Complete source rewrite/improvement of KInfocenter :

- Complete port to KDE/Qt 4, no more use of QT3 Support
- Simplify interface (remove multiple left tabs, add quick help in the top of the layout, use a KListWidgetSearchLine to filter by keywords and name)
- Fix General Page (modules were not displayed), and allow user to select it from the left panel
- Clean code and indentation structure
- Remove big margins and useless layout/widgets to integrate KCMModule (request from Aaron Siego)
- Memory module is now in a separate folder
- Memory module has been rewritten, and the chart generation is now simpler.
- Use color gradient and color scheme of System Monitor app (request from John Tapsell)
- Use a default icon when the requested icon does not exist (request from David Jarvie)
- Integrate patch from Konrad Rzepecki about improve PCI module by using libpci API. Add an optional dependency in CMake for this library
FEATURE:88625
- The porting to KDE4 of all architecture may add some compilation errors (sorry, I have no AIX, HPUX, Solaris, SGI, FreeBSD, OpenBSD systems to test those source). However, some existing codes already did not compile.
- Simplify source code by removing some part corresponding to the moment where KInfocenter and KControl were the same (it seems to).
- Name and comments of each modules are now normalized. (even IOSlaves Info and Samba Status)
CCMAIL:kde-core-devel@kde.org
- Allow the future move of inner modules of kcm_info to a dedicated module (examples: Sound, X-Server, Partitions,...)
TODO : - Improve Loading page layout
- Port Partitions, Sound and Network Interfaces modules to Solid
- Set my email as current maintainer

svn path=/trunk/KDE/kdebase/apps/; revision=795596
This commit is contained in:
Nicolas Ternisien 2008-04-10 23:08:34 +00:00
parent d3fd6ab778
commit a410c025ea
114 changed files with 8578 additions and 9019 deletions

View file

@ -11,8 +11,6 @@ include (KDE4Defaults)
include (MacroLibrary)
include(MacroOptionalAddSubdirectory)
macro_optional_find_package(OpenGL)
include(ConfigureChecks.cmake)
configure_file (config-apps.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-apps.h )
include_directories (${CMAKE_CURRENT_BINARY_DIR})

View file

@ -0,0 +1,20 @@
# - Try to find the pciutils directory library
# Once done this will define
#
# PCIUTILS_FOUND - system has PCIUtils
# PCIUTILS_INCLUDE_DIR - the PCIUTILS include directory
# PCIUTILS_LIBRARIES - The libraries needed to use FAM
if(PCIUTILS_INCLUDE_DIR AND PCIUTILS_LIBRARIES)
set(PCIUTILS_FIND_QUIETLY TRUE)
endif(PCIUTILS_INCLUDE_DIR AND PCIUTILS_LIBRARIES)
FIND_PATH(PCIUTILS_INCLUDE_DIR pci/pci.h)
FIND_LIBRARY(PCIUTILS_LIBRARIES NAMES pci )
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCIUTILS DEFAULT_MSG PCIUTILS_LIBRARIES PCIUTILS_INCLUDE_DIR)
MARK_AS_ADVANCED(PCIUTILS_INCLUDE_DIR PCIUTILS_LIBRARIES)

View file

@ -1,12 +1,32 @@
add_definitions( -DKDE_DEFAULT_DEBUG_AREA=1208 )
add_subdirectory( about )
add_definitions (-DQT3_SUPPORT -DQT3_SUPPORT_WARNINGS)
add_subdirectory( solidproc )
add_subdirectory( info )
add_subdirectory( nics )
add_subdirectory( usbview )
add_subdirectory( opengl )
add_subdirectory( memory )
macro_optional_find_package(OpenGL)
macro_log_feature(OPENGL_FOUND "OpenGL" "API for developing portable, interactive 2D and 3D graphics applications" "http://mesa3d.sourceforge.net" FALSE "" "View OpenGL details in kinfocenter.")
if(OPENGL_FOUND AND OPENGL_GLU_FOUND)
add_subdirectory( opengl )
else(OPENGL_FOUND AND OPENGL_GLU_FOUND)
MESSAGE(STATUS "OpenGL information module has been disabled.")
endif(OPENGL_FOUND AND OPENGL_GLU_FOUND)
macro_optional_find_package(PCIUTILS)
macro_log_feature(PCIUTILS_FOUND "PCIUTILS" "PciUtils is a library for direct access to PCI slots" "http://atrey.karlin.mff.cuni.cz/~mj/pciutils.shtml" FALSE "" "View PCI details in kinfocenter.")
if(NOT APPLE)
add_subdirectory( pci )
endif(NOT APPLE)
macro_optional_find_package(RAW1394)
macro_log_feature(RAW1394_FOUND "RAW1394" "library for direct access to IEEE 1394 bus" "http://www.linux1394.org/" FALSE "" "View FireWire devices in kinfocenter.")
@ -19,25 +39,13 @@ set(kinfocenter_SRCS
main.cpp
toplevel.cpp
indexwidget.cpp
helpwidget.cpp
dockcontainer.cpp
aboutwidget.cpp
quickhelp.cpp
moduletreeview.cpp
moduleiconview.cpp
moduleIface.cpp
global.cpp
modules.cpp
proxywidget.cpp
kcrootonly.cpp
searchwidget.cpp )
set(kinfocenter_adaptor ${KDEBASE_APPS_SOURCE_DIR}/kinfocenter/moduleIface.h)
set(kinfocenter_xml ${CMAKE_CURRENT_BINARY_DIR}/org.kde.Kinfocenter.xml)
ADD_CUSTOM_COMMAND(OUTPUT ${kinfocenter_xml}
COMMAND ${QT_DBUSCPP2XML_EXECUTABLE} ${kinfocenter_adaptor} > ${kinfocenter_xml}
DEPENDS ${kinfocenter_adaptor})
QT4_ADD_DBUS_INTERFACE( kinfocenter_SRCS ${kinfocenter_xml} kinfocenter_interface )
)
set(kinfocenter_KDEINIT_SRCS ${kinfocenter_SRCS})

View file

@ -44,9 +44,3 @@
font-size: xx-small;
}
.kcm_link {
color: #000;
}
/* vim:set sw=2 et nocindent smartindent: */

View file

@ -4,13 +4,10 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 1st August 2004), see www.w3.org" />
<style type="text/css">
/*<![CDATA[*/
@import "%1"; /* kde_infopage.css */
%1 /* maybe @import "kde_infopage_rtl.css"; */
%2 /* maybe @import "kde_infopage_rtl.css"; */
@import "kinfocenter.css";
/*body {font-size: px;}*/
/*]]>*/
@ -23,11 +20,11 @@
<div id="headerR"/>
<div id="title">
%2 <!-- Title -->
%3 <!-- Title -->
</div>
<div id="tagline">
%3 <!-- Catchphrase -->
%4 <!-- Catchphrase -->
</div>
</div>
@ -37,7 +34,7 @@
<div id="barL">
<div id="barR">
<div id="barCenter" class="bar_text">
%4<!-- Summary -->
%5<!-- Summary -->
</div>
</div>
</div>
@ -51,7 +48,7 @@
<div id="boxR">
<div id="boxCenter">
<!--Content-->
%5
%6
</div>
</div>
</div>
@ -61,4 +58,3 @@
<div id="footer"><div id="footerL"/><div id="footerR"/></div>
</body>
</html>
<!-- vim:set sw=2 et nocindent smartindent: -->

View file

@ -1,20 +1,20 @@
/*
Copyright (c) 2000,2001 Matthias Elter <elter@kde.org>
Copyright (c) 2000,2001 Matthias Elter <elter@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "aboutwidget.h"
#include "global.h"
@ -35,160 +35,107 @@
#include "aboutwidget.moc"
static const char kcc_text[] = I18N_NOOP("KDE Control Center");
static const char kcc_infotext[]= I18N_NOOP("KDE Info Center");
static const char title_text[] = I18N_NOOP("Configure your desktop environment");
static const char title_infotext[]= I18N_NOOP("Get system and desktop environment information");
static const char intro_text[] = I18N_NOOP("Welcome to the \"KDE Control Center\", "
"a central place to configure your "
"desktop environment. "
"Select an item from the index on the left "
"to load a configuration module.");
static const char intro_infotext[]= I18N_NOOP("Welcome to the \"KDE Info Center\", "
"a central place to find information about your "
"computer system.");
static const char kcc_infotext[] = I18N_NOOP("KDE Info Center");
static const char use_text[]= I18N_NOOP("Click on the \"Help\" tab on the left to view help "
"for the active "
"control module. Use the \"Search\" tab if you are unsure "
"where to look for "
"a particular configuration option.");
static const char title_infotext[] = I18N_NOOP("Get system and desktop environment information");
static const char version_text[]= I18N_NOOP("KDE version:");
static const char user_text[]= I18N_NOOP("User:");
static const char host_text[]= I18N_NOOP("Hostname:");
static const char system_text[]= I18N_NOOP("System:");
static const char release_text[]= I18N_NOOP("Release:");
static const char machine_text[]= I18N_NOOP("Machine:");
static const char intro_infotext[] = I18N_NOOP("Welcome to the \"KDE Info Center\", "
"a central place to find information about your "
"computer system.");
AboutWidget::AboutWidget(QWidget *parent, ConfigModuleList* configModules, const QString &caption) :
KHBox(parent), _configModules(configModules), _caption(caption) {
static const char use_text[] = I18N_NOOP("Click on the \"Help\" tab on the left to view help "
"for the active "
"control module. Use the \"Search\" tab if you are unsure "
"where to look for "
"a particular configuration option.");
setMinimumSize(400, 400);
static const char version_text[] = I18N_NOOP("KDE version:");
static const char user_text[] = I18N_NOOP("User:");
static const char host_text[] = I18N_NOOP("Hostname:");
static const char system_text[] = I18N_NOOP("System:");
static const char release_text[] = I18N_NOOP("Release:");
static const char machine_text[] = I18N_NOOP("Machine:");
AboutWidget::AboutWidget(QWidget *parent, Q3ListViewItem* category, const QString &caption)
: KHBox(parent),
_moduleList(false),
_category(category),
_caption(caption)
{
if (_category)
_moduleList = true;
setMinimumSize(400, 400);
// set qwhatsthis help
this->setWhatsThis( i18n(intro_text));
_viewer = new KHTMLPart( this );
_viewer->widget()->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
connect( _viewer->browserExtension(),
SIGNAL(openUrlRequest(const KUrl&, const KParts::OpenUrlArguments&, const KParts::BrowserArguments&)),
this, SLOT(slotModuleLinkClicked(const KUrl&)) );
updatePixmap();
// set qwhatsthis help
this->setWhatsThis(i18n(intro_infotext));
_viewer = new KHTMLPart( this );
_viewer->widget()->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
connect(_viewer->browserExtension(),
SIGNAL(openUrlRequest(const KUrl&, const KParts::OpenUrlArguments&, const KParts::BrowserArguments&)), this, SLOT(slotModuleLinkClicked(const KUrl&)));
updatePixmap();
}
void AboutWidget::setCategory( Q3ListViewItem* category, const QString &caption )
{
_caption = caption;
_category = category;
if ( _category )
_moduleList = true;
else
_moduleList = true;
void AboutWidget::updatePixmap() {
QString file = KStandardDirs::locate("data", "kinfocenter/about/main.html");
QFile f(file);
f.open(QIODevice::ReadOnly);
QTextStream t( &f);
QString res = t.readAll();
// Update the pixmap to be shown:
updatePixmap();
}
res = res.arg(KStandardDirs::locate("data", "kdeui/about/kde_infopage.css") );
if ( kapp->layoutDirection() == Qt::RightToLeft)
res = res.arg( "@import \"%1\";" ).arg(KStandardDirs::locate("data", "kdeui/about/kde_infopage_rtl.css") );
else
res = res.arg("");
void AboutWidget::updatePixmap()
{
QString file = KStandardDirs::locate( "data", "kinfocenter/about/main.html" );
QFile f( file );
f.open( QIODevice::ReadOnly );
QTextStream t( &f );
QString res = t.readAll();
QString title, intro, caption;
res = res.arg(i18n(kcc_infotext));
res = res.arg(i18n(title_infotext));
res = res.arg(i18n(intro_infotext));
res = res.arg( KStandardDirs::locate( "data", "kdeui/about/kde_infopage.css" ) );
if ( kapp->layoutDirection() == Qt::RightToLeft )
res = res.arg( "@import \"%1\";" ).arg( KStandardDirs::locate( "data", "kdeui/about/kde_infopage_rtl.css" ) );
else
res = res.arg( "" );
QString content;
QString title, intro, caption;
if (KCGlobal::isInfoCenter())
{
res = res.arg(i18n(kcc_infotext))
.arg(i18n(title_infotext))
.arg(i18n(intro_infotext));
}
else
{
res = res.arg(i18n(kcc_text))
.arg(i18n(title_text))
.arg(i18n(intro_text));
}
QString content;
if (!_moduleList)
{
content += "<table class=\"kc_table\">\n";
if (_configModules == NULL) {
content += "<table class=\"kc_table\">\n";
#define KC_HTMLROW( a, b ) "<tr><td class=\"kc_leftcol\">" + i18n( a ) + "</td><td class=\"kc_rightcol\">" + b + "</tr>\n"
content += KC_HTMLROW( version_text, KCGlobal::kdeVersion() );
content += KC_HTMLROW( user_text, KCGlobal::userName() );
content += KC_HTMLROW( host_text, KCGlobal::hostName() );
content += KC_HTMLROW( system_text, KCGlobal::systemName() );
content += KC_HTMLROW( release_text, KCGlobal::systemRelease() );
content += KC_HTMLROW( machine_text, KCGlobal::systemMachine() );
content += KC_HTMLROW( version_text, KCGlobal::kdeVersion() );
content += KC_HTMLROW( user_text, KCGlobal::userName() );
content += KC_HTMLROW( host_text, KCGlobal::hostName() );
content += KC_HTMLROW( system_text, KCGlobal::systemName() );
content += KC_HTMLROW( release_text, KCGlobal::systemRelease() );
content += KC_HTMLROW( machine_text, KCGlobal::systemMachine() );
#undef KC_HTMLROW
content += "</table>\n";
content += "<p class=\"kc_use_text\">" + i18n( use_text ) + "</p>\n";
}
else
{
content += "<div id=\"tableTitle\">" + _caption + "</div>";
content += "</table>\n";
content += "<p class=\"kc_use_text\">" + i18n(use_text) + "</p>\n";
} else {
content += "<div id=\"tableTitle\">" + _caption + "</div>";
content += "<table class=\"kc_table\">\n";
// traverse the list
Q3ListViewItem* pEntry = _category;
while (pEntry != NULL)
{
QString szName;
QString szComment;
ConfigModule *module = static_cast<ModuleTreeItem*>(pEntry)->module();
/* TODO: work out link */
content += "<tr><td class=\"kc_leftcol\">";
if (module)
{
szName = module->moduleName();
szComment = module->comment();
content += "<a href=\"%1\" class=\"kcm_link\">" + szName + "</a></td><td class=\"kc_rightcol\">" + szComment;
KUrl moduleURL(QString("kcm://%1").arg(QString().sprintf("%p",(void*)module)) );
QString linkURL( moduleURL.url() );
content = content.arg( linkURL );
_moduleMap.insert( linkURL, module );
}
else
{
szName = static_cast<ModuleTreeItem*>(pEntry)->caption();
content += szName + "</td><td class=\"kc_rightcol\">" + szName;
}
content += "</td></tr>\n";
pEntry = pEntry->nextSibling();
}
content += "</table>";
}
_viewer->begin(KUrl(file ));
_viewer->write( res.arg( content ) );
_viewer->end();
content += "<table class=\"kc_table\">\n";
// traverse the list
foreach(ConfigModule* configModule, *_configModules) {
QString szName;
QString szComment;
content += "<tr><td class=\"kc_leftcol\">";
szName = configModule->moduleName();
szComment = configModule->comment();
content += "<a href=\"%1\">" + szName + "</a></td><td class=\"kc_rightcol\">" + szComment;
KUrl moduleURL(QString("kcm://%1").arg(QString().sprintf("%p", (void*)configModule)) );
QString linkURL(moduleURL.url() );
content = content.arg(linkURL);
_moduleMap.insert(linkURL, configModule);
content += "</td></tr>\n";
}
content += "</table>";
}
_viewer->begin(KUrl(file));
_viewer->write(res.arg(content) );
_viewer->end();
}
void AboutWidget::slotModuleLinkClicked( const KUrl& url )
{
ConfigModule* module;
module = _moduleMap[url.url()];
if ( module )
emit moduleSelected( module );
void AboutWidget::slotModuleLinkClicked(const KUrl& url) {
ConfigModule* module = _moduleMap[url.url()];
if (module) {
emit moduleSelected(module);
}
}

View file

@ -20,7 +20,7 @@
#define __aboutwidget_h__
#include <QWidget>
#include <Qt3Support/Q3CheckListItem>
#include <QListWidgetItem>
#include <QMap>
#include <QPixmap>
#include <kvbox.h>
@ -29,21 +29,16 @@ class QPixmap;
class ConfigModule;
class KHTMLPart;
class KUrl;
class ConfigModuleList;
class AboutWidget : public KHBox
{
Q_OBJECT
public:
explicit AboutWidget(QWidget *parent, Q3ListViewItem* category=0, const QString &caption=QString());
explicit AboutWidget(QWidget *parent, ConfigModuleList* modules = NULL, const QString &caption=QString());
/**
* Set a new category without creating a new AboutWidget if there is
* one visible already (reduces flicker)
*/
void setCategory( Q3ListViewItem* category, const QString& caption);
Q_SIGNALS:
signals:
void moduleSelected(ConfigModule *);
private Q_SLOTS:
@ -56,8 +51,7 @@ private:
*/
void updatePixmap();
bool _moduleList;
Q3ListViewItem* _category;
ConfigModuleList * _configModules;
QString _caption;
KHTMLPart *_viewer;
QMap<QString,ConfigModule*> _moduleMap;

View file

@ -0,0 +1,13 @@
# TODO: HAVE_COREAUDIO (for OSX)
# TODO: HAVE_LIBDEVINFO_H (for Solaris 7 and later)
# to be set if both -ldevinfo and libdevinfo.h exist
check_include_files(devinfo.h HAVE_DEVINFO_H) # info_fbsd.cpp
check_include_files(fstab.h HAVE_FSTAB_H) # info_linux.cpp
check_include_files(linux/raw.h HAVE_LINUX_RAW_H) # info_linux.cpp
check_include_files(mntent.h HAVE_MNTENT_H) # info_linux.cpp
check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H) # info_linux.cpp
check_include_files(sys/raw.h HAVE_SYS_RAW_H) # info_linux.cpp
check_include_files(Alib.h HAVE_ALIB_H) # info_hpux.cpp
configure_file (../base/config-infocenter.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config-infocenter.h )

View file

@ -0,0 +1,345 @@
/*
* info_aix.cpp
*
* Reza Arbab <arbab@austin.ibm.com>
*
* GetInfo_Partitions() and its helpers (get_fs_usage, fs_adjust_blocks)
* taken from info_hpux.cpp.
*
*/
#include <cf.h>
#define class _class
#include <odmi.h>
#include <sys/cfgodm.h>
#include <sys/cfgdb.h>
#undef class
#include <nl_types.h>
#include <string.h>
#include <kdebug.h>
#include <stdlib.h>
#include <sys/statfs.h>
#include <sys/statvfs.h>
#include <sys/types.h>
#include <unistd.h>
#include <fstab.h>
#include <errno.h>
#include <sys/utsname.h>
char * device_description(struct CuDv *cudv) {
char *desc= NULL;
struct PdDv *pddv = cudv->PdDvLn; /* link to Predefined Devices database */
nl_catd cat;
cat = catopen("/usr/lib/methods/devices.cat", NL_CAT_LOCALE);
if ((int)cat == -1)
return NULL;
desc = strdup(catgets(cat, pddv->setno, pddv->msgno, "N/A") );
catclose(cat);
return desc;
}
bool list_devices(QListView *lBox, char *criteria) {
struct CuDv *cudv; /* Customized Devices */
struct listinfo info;
int i;
char *cudv_desc;
QString cudv_status;
QListViewItem *lastitem= NULL;
lBox->addColumn(i18n("Name"));
lBox->addColumn(i18n("Status"));
lBox->addColumn(i18n("Location"));
lBox->addColumn(i18n("Description"));
if (odm_initialize() == -1) {
kError(0) << "odm_initialize() failed: odmerrno = " << odmerrno << endl;
return (false);
}
cudv = (struct CuDv *) odm_get_list(CuDv_CLASS, criteria, &info, 100, 2);
if ((int)cudv == -1) {
odm_terminate();
kError(0) << "odm_get_list() failed: odmerrno = " << odmerrno << endl;
return (false);
} else if (!cudv) /* empty list */
{
odm_terminate();
return (true);
}
for (i=0; i<info.num; i++) {
switch (cudv[i].status) {
case DEFINED:
cudv_status = QString("Defined");
break;
case AVAILABLE:
cudv_status = QString("Available");
break;
case STOPPED:
cudv_status = QString("Stopped");
break;
default:
cudv_status = QString("Unknown");
}
cudv_desc = device_description(&cudv[i]);
lastitem = new QListViewItem(lBox, lastitem,
QString(cudv[i].name),
cudv_status,
QString(cudv[i].location),
QString(cudv_desc ? cudv_desc : "N/A") );
if (cudv_desc)
free(cudv_desc);
}
if (odm_free_list(cudv, &info) == -1) {
odm_terminate();
kError(0) << "odm_free_list() failed: odmerrno = " << odmerrno << endl;
return (false);
}
odm_terminate();
return true;
}
enum CHIP
{
P2SC, Power, Power2, Power3, Power3_II, PowerPC,
PowerPC_604e, PowerPersonal, RD64_II, RS_III, RS64, RS64_II,
RS64_III, RS64_IV, RSC, ThinkPad, unknown,
NUM_CHIPS
};
static const char chip_name[NUM_CHIPS][16] = { "P2SC", "Power", "Power2", "Power3", "Power3-II", "PowerPC", "PowerPC 604e", "PowerPersonal", "RD64-II", "RS-III", "RS64", "RS64-II", "RS64-III", "RS64-IV", "RSC", "ThinkPad", "unknown" };
struct model {
char model_ID[21];
char machine_type[21];
char processor_speed[21];
unsigned short architecture; /* enum CHIP */
};
struct model _models[] = { { "02", "7015-930", "25", Power }, { "10", "7013-530", "25", Power }, { "10", "7016-730", "25", Power }, { "11", "7013-540", "30", Power }, { "14", "7013-540", "30", Power }, { "18", "7013-53H", "33", Power }, { "1C", "7013-550", "41.6", Power }, { "20", "7015-930", "25",
Power }, { "2E", "7015-950", "41", Power }, { "30", "7013-520", "20", Power }, { "31", "7012-320", "20", Power }, { "34", "7013-52H", "25", Power }, { "35", "7012-32H", "25", Power }, { "37", "7012-340", "33", Power }, { "38", "7012-350", "41", Power }, { "41", "7011-20", "33", PowerPC }, {
"45", "7011-220", "33", PowerPC }, { "42", "7006-41T/41W", "80", PowerPC }, { "43", "7008-M20", "33", Power }, { "43", "7008-M2A", "33", Power }, { "46", "7011-250", "66", PowerPC }, { "47", "7011-230", "45", RSC }, { "48", "7009-C10", "80", PowerPC },
/* 4C models use a different table -- see below */
{ "4C", "70XX", "(unknown)", unknown }, { "57", "7012-390", "67", Power2 }, { "57", "7030-3BT", "67", Power2 }, { "57", "9076-SP2 Thin", "67", Power2 }, { "58", "7012-380", "59", Power2 }, { "58", "7030-3AT", "59", Power2 }, { "59", "7012-39H", "67", Power2 }, { "59", "9076-SP2 Thin w/L2", "67",
Power2 }, { "5C", "7013-560", "50", Power }, { "63", "7015-970", "50", Power }, { "63", "7015-97B", "50", Power }, { "64", "7015-980", "62.5", Power }, { "64", "7015-98B", "62.5", Power }, { "66", "7013-580", "62.5", Power }, { "67", "7013-570", "50", Power }, { "67", "7015-R10", "50",
Power }, { "70", "7013-590", "66", Power2 }, { "70", "9076-SP2 Wide", "66", Power2 }, { "71", "7013-58H", "55", Power2 }, { "72", "7013-59H", "66", Power2 }, { "72", "7015-R20", "66", Power2 }, { "72", "9076-SP2 Wide", "66", Power2 }, { "75", "7012-370", "62", Power }, { "75", "7012-375",
"62", Power }, { "75", "9076-SP1 Thin", "62", Power }, { "76", "7012-360", "50", Power }, { "76", "7012-365", "50", Power }, { "77", "7012-350", "41", Power }, { "77", "7012-355", "41", Power }, { "77", "7013-55L", "41.6", Power }, { "79", "7013-591", "77", Power2 }, { "79",
"9076-SP2 Wide", "77", Power2 }, { "80", "7015-990", "71.5", Power2 }, { "81", "7015-R24", "71.5", P2SC }, { "89", "7013-595", "135", P2SC }, { "89", "9076-SP2 Wide", "135", P2SC }, { "90", "7009-C20", "120", PowerPC }, { "91", "7006-42W/42T", "120", PowerPC }, { "94", "7012-397", "160",
P2SC }, { "94", "9076-SP2 Thin", "160", P2SC }, { "A0", "7013-J30", "75", PowerPC }, { "A1", "7013-J40", "112", PowerPC }, { "A3", "7015-R30", "(unknown)", PowerPC }, { "A4", "7015-R40", "(unknown)", PowerPC }, { "A4", "7015-R50", "(unknown)", PowerPC }, { "A4", "9076-SP2 High",
"(unknown)", PowerPC }, { "A6", "7012-G30", "(unknown)", PowerPC }, { "A7", "7012-G40", "(unknown)", PowerPC }, { "C0", "7024-E20", "(unknown)", PowerPC }, { "C0", "7024-E30", "(unknown)", PowerPC }, { "C4", "7025-F30", "(unknown)", PowerPC }, { "F0", "7007-N40", "50", ThinkPad }, { "", "",
"0", 0 } };
struct model _4C_models[] = { { "IBM,7017-S70", "7017-S70", "125", RS64 }, { "IBM,7017-S7A", "7017-S7A", "262", RD64_II }, { "IBM,7017-S80", "7017-S80", "450", RS_III }, { "IBM,7017-S85", "pSeries 680", "600", RS64_IV }, { "IBM,7025-F40", "7025-F40", "166/233", PowerPC_604e }, { "IBM,7025-F50",
"7025-F50", "(unknown)", PowerPC_604e }, { "IBM,7025-F80", "7025-F80", "(unknown)", RS64_III }, { "IBM,7026-H10", "7025-H10", "166/233", PowerPC_604e }, { "IBM,7026-H50", "7025-H50", "(unknown)", PowerPC_604e }, { "IBM,7026-H80", "7025-H80", "(unknown)", RS64_III }, { "IBM,7026-M80",
"7026-M80", "500", RS64_III }, { "IBM,7025-F40", "7025-F40", "166/233", PowerPC }, { "IBM,7025-F50", "7025-F50", "(unknown)", PowerPC }, { "IBM,7025-F80", "7025-F80", "450", PowerPC }, { "IBM,7026-B80", "pSeries 640", "375", Power3_II }, { "IBM,7026-H10", "7026-H10", "166/233", PowerPC }, {
"IBM,7026-H50", "7026-H50", "(unknown)", PowerPC }, { "IBM,7026-H70", "7026-H70", "340", RS64_II }, { "IBM,7026-H80", "7026-H80", "450", PowerPC }, { "IBM,7026-M80", "7026-M80", "500", PowerPC }, { "IBM,7042-140", "7043-140", "166/200/233/332", PowerPC }, { "IBM,7042-150", "7043-150",
"375", PowerPC }, { "IBM,7042-240", "7043-240", "166/233", PowerPC }, { "IBM,7043-140", "7043-140", "166/200/233/332", PowerPC }, { "IBM,7043-150", "7043-150", "375", PowerPC }, { "IBM,7043-240", "7043-240", "166/233", PowerPC }, { "IBM,7043-260", "7043-260", "200", Power3 }, { "IBM,7248",
"7248-100", "100", PowerPersonal }, { "IBM,7248", "7248-120", "120", PowerPersonal }, { "IBM,7248", "7248-132", "132", PowerPersonal }, { "IBM,9076-270", "9076-SP Silver Node", "(unknown)", PowerPC }, { "", "", "", 0 },
};
/* all GetInfo_ functions should return true, when the Information
was filled into the lBox-Widget.
returning false indicates, that information was not available.
*/
bool GetInfo_XServer_and_Video(QListView *lBox) {
return GetInfo_XServer_Generic(lBox);
}
/*
* Written using information from:
*
* http://service.software.ibm.com/cgi-bin/support/rs6000.support/techbrowse/tbgaus?gaus_mode=8&documents=B93576892313352&database=task
*
* Not fully implemented. In particular there are ways to resolve the
* "(unknown)" clock speeds of many of these models. See page for details.
*
*/
bool GetInfo_CPU(QListView *lBox) {
struct utsname info;
struct model *table = _models; /* table of model information */
char model_ID[21] = ""; /* information for table lookup */
char cpu_ID[7] = ""; /* unique CPU ID */
int i;
QListViewItem *lastitem= NULL;
lBox->addColumn(i18n("Information"));
lBox->addColumn(i18n("Value"));
if (uname(&info) == -1) {
kError(0) << "uname() failed: errno = " << errno << endl;
return false;
}
strncat(model_ID, info.machine+8, 2); /* we want the ninth and tenth digits */
strncat(cpu_ID, info.machine+2, 6);
if (strcmp(model_ID, "4C") == 0) /* need to use a different model_ID and model table */
{
if (odm_initialize() == -1)
kError(0) << "odm_initialize() failed: odmerrno = " << odmerrno << endl;
else {
struct CuAt cuat; /* Customized Device attribute */
/* equivalent to uname -M */
if (odm_get_first(CuAt_CLASS, (char *)"name='sys0' and attribute='modelname'", &cuat) ) {
strcpy(model_ID, cuat.value);
table = _4C_models;
}
odm_terminate();
}
}
lastitem = new QListViewItem(lBox, lastitem, QString("CPU ID"), QString(cpu_ID));
lastitem = new QListViewItem(lBox, lastitem, QString("Node"), QString(info.nodename));
lastitem = new QListViewItem(lBox, lastitem, QString("OS"), QString(info.sysname) +
QString(" ") + QString(info.version) + QString(".") + QString(info.release));
for (i=0; *(table[i].model_ID); i++)
if (strcmp(model_ID, table[i].model_ID) == 0) {
lastitem = new QListViewItem(lBox, lastitem, QString("Machine Type"), QString(table[i].machine_type));
lastitem = new QListViewItem(lBox, lastitem, QString("Architecture"), QString(chip_name[table[i].architecture]));
lastitem = new QListViewItem(lBox, lastitem, QString("Speed"), QString(table[i].processor_speed) + QString(" Mhz"));
break;
}
return (true);
}
bool GetInfo_IRQ(QListView *) {
return false;
}
bool GetInfo_DMA(QListView *) {
return false;
}
bool GetInfo_PCI(QTreeWidget* tree) {
return list_devices(tree, (char *)"PdDvLn like '*/pci/*'");
}
bool GetInfo_IO_Ports(QListView *) {
return false;
}
bool GetInfo_Sound(QListView *) {
return false;
}
bool GetInfo_Devices(QListView *lBox) {
return list_devices(lBox, (char *)"PdDvLn like '*'");
}
bool GetInfo_SCSI(QListView *lBox) {
return list_devices(lBox, (char *)"PdDvLn like '*/scsi/*'");
}
/* Parts taken from fsusage.c from the Midnight Commander (mc)
Copyright (C) 1991, 1992 Free Software Foundation, In
Return the number of TOSIZE-byte blocks used by
BLOCKS FROMSIZE-byte blocks, rounding away from zero.
TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */
static long fs_adjust_blocks(long blocks, int fromsize, int tosize) {
if (tosize <= 0)
abort();
if (fromsize <= 0)
return -1;
if (fromsize == tosize) /* E.g., from 512 to 512. */
return blocks;
else if (fromsize > tosize) /* E.g., from 2048 to 512. */
return blocks * (fromsize / tosize);
else
/* E.g., from 256 to 512. */
return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize);
}
/* Fill in the fields of FSP with information about space usage for
the filesystem on which PATH resides.
Return 0 if successful, -1 if not. */
#define CONVERT_BLOCKS(b) fs_adjust_blocks ((b), fsd.f_bsize, 512)
static int get_fs_usage(char *path, long *l_total, long *l_avail) {
struct statfs fsd; /* 4.3BSD, SunOS 4, HP-UX, AIX. */
unsigned long fsu_blocks, fsu_bfree, fsu_bavail;
*l_total = *l_avail = 0;
if (statfs(path, &fsd) < 0)
return -1;
fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks);
fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree);
fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail);
*l_avail = getuid() ? fsu_bavail/2 : fsu_bfree/2;
*l_total = fsu_blocks/2;
return 0;
}
// Some Ideas taken from garbazo from his source in info_fbsd.cpp
bool GetInfo_Partitions(QListView *lbox) {
#define NUMCOLS 5
QString Title[NUMCOLS];
int n;
struct fstab *fstab_ent;
struct statvfs svfs;
long total, avail;
QString str;
QString MB(i18n("MB")+ " "); // International Text for MB=Mega-Byte
if (setfsent() != 1) // Try to open fstab
return false;
Title[0] = i18n("Device");
Title[1] = i18n("Mount Point");
Title[2] = i18n("FS Type");
Title[3] = i18n("Total Size");
Title[4] = i18n("Free Size");
for (n=0; n<NUMCOLS; ++n) {
lbox->addColumn(Title[n]);
}
while ((fstab_ent=getfsent())!=NULL) {
/* fstab_ent->fs_type holds only "rw","xx","ro"... */
memset(&svfs, 0, sizeof(svfs));
statvfs(fstab_ent->fs_file, &svfs);
get_fs_usage(fstab_ent->fs_file, &total, &avail);
if (!strcmp(fstab_ent->fs_type, FSTAB_XX)) // valid drive ?
svfs.f_basetype[0] = 0;
if (svfs.f_basetype[0]) {
new QListViewItem(lbox, QString(fstab_ent->fs_spec),
QString(fstab_ent->fs_file) + QString(" "),
(svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a")),
Value((total+512)/1024,6) + MB,
Value((avail+512)/1024,6) + MB);
} else {
new QListViewItem(lbox, QString(fstab_ent->fs_spec),
QString(fstab_ent->fs_file) + QString(" "),
(svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a")));
}
}
endfsent();
return true;
}

View file

@ -8,47 +8,37 @@
* during the creation of info_fbsd.cpp. Thanks Mike.
*/
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_PCI_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
/*
* all following functions should return true, when the Information
* was filled into the lBox-Widget. Returning false indicates that
* was filled into the QTreeWidget. Returning false indicates that
* information was not available.
*/
#include "config-infocenter.h" // HAVE_DEVINFO_H
#include "config-infocenter.h" // HAVE_DEVINFO_H
#include <sys/types.h>
#include <sys/sysctl.h>
#ifdef HAVE_DEVINFO_H
extern "C" {
#include <devinfo.h>
}
extern "C" {
#include <devinfo.h>
}
#endif
#include <errno.h>
#include <fstab.h>
#include <string.h>
#include <Qt3Support/Q3Dict>
#include <QMap>
#include <QFile>
#include <QTextStream>
class Device {
public:
Device (QString n=QString(), QString d=QString())
{name=n; description=d;}
Device(QString n=QString(), QString d=QString()) {
name=n;
description=d;
}
QString name, description;
};
@ -65,8 +55,7 @@ extern "C" {
}
#endif
bool GetInfo_CPU (Q3ListView *lBox)
{
bool GetInfo_CPU(QTreeWidget* tree) {
// Modified 13 July 2000 for SMP by Brad Hughes - bhughes@trolltech.com
int ncpu;
@ -95,7 +84,9 @@ bool GetInfo_CPU (Q3ListView *lBox)
}
/* Put everything in the listbox */
new Q3ListViewItem(lBox, cpustring);
QStringList list;
list << cpustring;
new QTreeWidgetItem(tree, list);
/* Clean up after ourselves, this time I mean it ;-) */
delete buf;
@ -104,64 +95,64 @@ bool GetInfo_CPU (Q3ListView *lBox)
return true;
}
bool GetInfo_IRQ (Q3ListView *lbox)
{
bool GetInfo_IRQ(QTreeWidget* tree) {
#ifdef HAVE_DEVINFO_H
/* systat lists the interrupts assigned to devices as well as how many were
generated. Parsing its output however is about as fun as a sandpaper
enema. The best idea would probably be to rip out the guts of systat.
Too bad it's not very well commented */
generated. Parsing its output however is about as fun as a sandpaper
enema. The best idea would probably be to rip out the guts of systat.
Too bad it's not very well commented */
/* Oh neat, current now has a neat little utility called devinfo */
if (devinfo_init())
return false;
devinfo_foreach_rman(print_irq, lbox);
return false;
devinfo_foreach_rman(print_irq, tree);
return true;
#else
return false;
#endif
}
bool GetInfo_DMA (Q3ListView *lbox)
{
bool GetInfo_DMA(QTreeWidget* tree) {
#ifdef HAVE_DEVINFO_H
/* Oh neat, current now has a neat little utility called devinfo */
if (devinfo_init())
return false;
devinfo_foreach_rman(print_dma, lbox);
return false;
devinfo_foreach_rman(print_dma, tree);
return true;
#else
return false;
#endif
}
bool GetInfo_IO_Ports (Q3ListView *lbox)
{
bool GetInfo_IO_Ports(QTreeWidget* tree) {
#ifdef HAVE_DEVINFO_H
/* Oh neat, current now has a neat little utility called devinfo */
if (devinfo_init())
return false;
devinfo_foreach_rman(print_ioports, lbox);
return false;
devinfo_foreach_rman(print_ioports, tree);
return true;
#else
return false;
#endif
}
bool GetInfo_Sound (Q3ListView *lbox)
{
bool GetInfo_Sound(QTreeWidget* tree) {
QFile *sndstat = new QFile("/dev/sndstat");
QTextStream *t;
QString s;
Q3ListViewItem *olditem = 0;
if (!sndstat->exists() || !sndstat->open(QIODevice::ReadOnly)) {
s = i18n("Your sound system could not be queried. /dev/sndstat does not exist or is not readable.");
olditem = new Q3ListViewItem(lbox, olditem, s);
QStringList list;
list << s;
new QTreeWidgetItem(tree, list);
} else {
t = new QTextStream(sndstat);
while (!(s=t->readLine()).isNull()) {
olditem = new Q3ListViewItem(lbox, olditem, s);
QStringList list;
list << s;
new QTreeWidgetItem(tree, list);
}
delete t;
@ -172,32 +163,36 @@ bool GetInfo_Sound (Q3ListView *lbox)
return true;
}
bool GetInfo_SCSI (Q3ListView *lbox)
{
bool GetInfo_SCSI(QTreeWidget* tree) {
FILE *pipe;
QFile *camcontrol = new QFile("/sbin/camcontrol");
QTextStream *t;
QString s;
Q3ListViewItem *olditem = 0;
if (!camcontrol->exists()) {
s = i18n ("SCSI subsystem could not be queried: /sbin/camcontrol could not be found");
olditem = new Q3ListViewItem(lbox, olditem, s);
s = i18n("SCSI subsystem could not be queried: /sbin/camcontrol could not be found");
QStringList list;
list << s;
new QTreeWidgetItem(tree, list);
} else if ((pipe = popen("/sbin/camcontrol devlist 2>&1", "r")) == NULL) {
s = i18n ("SCSI subsystem could not be queried: /sbin/camcontrol could not be executed");
olditem = new Q3ListViewItem(lbox, olditem, s);
s = i18n("SCSI subsystem could not be queried: /sbin/camcontrol could not be executed");
QStringList list;
list << s;
new QTreeWidgetItem(tree, list);
} else {
/* This prints out a list of all the scsi devies, perhaps eventually we could
parse it as opposed to schlepping it into a listbox */
parse it as opposed to schlepping it into a listbox */
t = new QTextStream(pipe, QIODevice::ReadOnly);
while (true) {
s = t->readLine();
if ( s.isEmpty() )
if (s.isEmpty() )
break;
olditem = new Q3ListViewItem(lbox, olditem, s);
QStringList list;
list << s;
new QTreeWidgetItem(tree, list);
}
delete t;
@ -206,18 +201,17 @@ bool GetInfo_SCSI (Q3ListView *lbox)
delete camcontrol;
if (!lbox->childCount())
if (!tree->topLevelItemCount())
return false;
return true;
}
bool GetInfo_PCI (Q3ListView *lbox)
{
bool GetInfo_PCI(QTreeWidget* tree) {
FILE *pipe;
QFile *pcicontrol;
QString s, cmd;
Q3ListViewItem *olditem = 0;
QTreeWidgetItem *olditem= NULL;
pcicontrol = new QFile("/usr/sbin/pciconf");
@ -228,9 +222,9 @@ bool GetInfo_PCI (Q3ListView *lbox)
delete pcicontrol;
pcicontrol = new QFile("/usr/X11R6/bin/pcitweak");
if (!pcicontrol->exists()) {
QString s;
s = i18n("Could not find any programs with which to query your system's PCI information");
(void) new Q3ListViewItem(lbox, 0, s);
QStringList list;
list << i18n("Could not find any programs with which to query your system's PCI information");
new QTreeWidgetItem(tree, list);
delete pcicontrol;
return true;
} else {
@ -245,72 +239,71 @@ bool GetInfo_PCI (Q3ListView *lbox)
delete pcicontrol;
if ((pipe = popen(cmd.toLatin1(), "r")) == NULL) {
s = i18n ("PCI subsystem could not be queried: %1 could not be executed", cmd);
olditem = new Q3ListViewItem(lbox, olditem, s);
QStringList list;
list << i18n("PCI subsystem could not be queried: %1 could not be executed", cmd);
olditem = new QTreeWidgetItem(olditem, list);
} else {
/* This prints out a list of all the pci devies, perhaps eventually we could
parse it as opposed to schlepping it into a listbox */
parse it as opposed to schlepping it into a listbox */
pclose(pipe);
GetInfo_ReadfromPipe(lbox, cmd.toLatin1(), true);
GetInfo_ReadfromPipe(tree, cmd.toLatin1(), true);
}
if (!lbox->childCount()) {
s = i18n("The PCI subsystem could not be queried, this may need root privileges.");
olditem = new Q3ListViewItem(lbox, olditem, s);
if (!tree->topLevelItemCount()) {
QStringList list;
list << i18n("The PCI subsystem could not be queried, this may need root privileges.");
olditem = new QTreeWidgetItem(tree, olditem, list);
return true;
}
return true;
}
bool GetInfo_Partitions (Q3ListView *lbox)
{
bool GetInfo_Partitions(QTreeWidget* tree) {
struct fstab *fstab_ent;
if (setfsent() != 1) /* Try to open fstab */ {
int s_err = errno;
if (setfsent() != 1) /* Try to open fstab */{
int s_err= errno;
QString s;
s = i18n("Could not check filesystem info: ");
s += strerror(s_err);
(void)new Q3ListViewItem(lbox, 0, s);
QStringList list;
list << s;
new QTreeWidgetItem(tree, list);
} else {
lbox->addColumn(i18n("Device"));
lbox->addColumn(i18n("Mount Point"));
lbox->addColumn(i18n("FS Type"));
lbox->addColumn(i18n("Mount Options"));
QStringList headers;
headers << i18n("Device") << i18n("Mount Point") << i18n("FS Type") << i18n("Mount Options");
while ((fstab_ent=getfsent())!=NULL) {
new Q3ListViewItem(lbox, fstab_ent->fs_spec,
fstab_ent->fs_file, fstab_ent->fs_vfstype,
fstab_ent->fs_mntops);
QString list;
list << fstab_ent->fs_spec << fstab_ent->fs_file << fstab_ent->fs_vfstype << fstab_ent->fs_mntops;
new QTreeWidgetItem(tree, list);
}
lbox->setSorting(0);
lbox->header()->setClickEnabled(true);
tree->sortItems(0, Qt::AscendingOrder);
endfsent(); /* Close fstab */
}
return true;
}
bool GetInfo_XServer_and_Video (Q3ListView *lBox)
{
return GetInfo_XServer_Generic( lBox );
bool GetInfo_XServer_and_Video(QTreeWidget* tree) {
return GetInfo_XServer_Generic(tree);
}
bool GetInfo_Devices (Q3ListView *lbox)
{
bool GetInfo_Devices(QTreeWidget* tree) {
QFile *f = new QFile("/var/run/dmesg.boot");
if (f->open(QIODevice::ReadOnly)) {
QTextStream qts(f);
Q3Dict<Q3ListViewItem> lv_items;
QMap<QString, QTreeWidgetItem*> lv_items;
Device *dev;
QString line, controller;
lbox->setRootIsDecorated(true);
lbox->addColumn("Device");
lbox->addColumn("Description");
tree->setRootIsDecorated(true);
QStringList headers;
headers << i18n("Device") << i18n("Description");
tree->setHeaderLabels(headers);
while ( !(line=qts.readLine()).isNull() ) {
controller = GetController(line);
if (controller.isNull())
@ -320,13 +313,18 @@ bool GetInfo_Devices (Q3ListView *lbox)
continue;
// Ewww assuing motherboard is the only toplevel controller is rather gross
if (controller == "motherboard") {
if (!lv_items[dev->name]) {
lv_items.insert(dev->name, new Q3ListViewItem(lbox, dev->name, dev->description) );
if (lv_items.contains(QString(dev->name))==false) {
QStringList list;
list << dev->name << dev->description;
lv_items.insert(QString(dev->name), new QTreeWidgetItem(tree, list));
}
} else {
Q3ListViewItem *parent=lv_items[controller];
if (parent && !lv_items[dev->name]) {
lv_items.insert(dev->name, new Q3ListViewItem(parent, dev->name, dev->description) );
QTreeWidgetItem* parent=lv_items[controller];
if (parent && lv_items.contains(dev->name)==false) {
QStringList list;
list << dev->name << dev->description;
lv_items.insert(QString(dev->name), new QTreeWidgetItem(parent, list));
}
}
}
@ -335,33 +333,31 @@ bool GetInfo_Devices (Q3ListView *lbox)
return false;
}
QString GetController(const QString &line)
{
if ( ( (line.startsWith("ad")) || (line.startsWith("afd")) || (line.startsWith("acd")) ) && (line.find(":") < 6) ) {
QString controller = line;
controller.remove(0, controller.find(" at ")+4);
if (controller.find("-slave") != -1) {
controller.remove(controller.find("-slave"), controller.length());
} else if (controller.find("-master") != -1) {
controller.remove(controller.find("-master"), controller.length());
} else
controller=QString();
if (!controller.isNull())
return controller;
}
if (line.find(" on ") != -1) {
QString controller;
controller = line;
controller.remove(0, controller.find(" on ")+4);
if (controller.find(" ") != -1)
controller.remove(controller.find(" "), controller.length());
QString GetController(const QString &line) {
if ( ( (line.startsWith("ad")) || (line.startsWith("afd")) || (line.startsWith("acd")) ) && (line.find(":") < 6)) {
QString controller = line;
controller.remove(0, controller.find(" at ")+4);
if (controller.find("-slave") != -1) {
controller.remove(controller.find("-slave"), controller.length());
} else if (controller.find("-master") != -1) {
controller.remove(controller.find("-master"), controller.length());
} else
controller=QString();
if (!controller.isNull())
return controller;
}
return QString();
}
if (line.find(" on ") != -1) {
QString controller;
controller = line;
controller.remove(0, controller.find(" on ")+4);
if (controller.find(" ") != -1)
controller.remove(controller.find(" "), controller.length());
return controller;
}
return QString();
}
Device *GetDevice(const QString &line)
{
Device *GetDevice(const QString &line) {
Device *dev;
int colon = line.find(":");
if (colon == -1)
@ -375,73 +371,84 @@ Device *GetDevice(const QString &line)
#ifdef HAVE_DEVINFO_H
int print_irq(struct devinfo_rman *rman, void *arg)
{
Q3ListView *lbox = (Q3ListView *)arg;
if (strcmp(rman->dm_desc, "Interrupt request lines")==0) {
(void)new Q3ListViewItem(lbox, 0, rman->dm_desc);
int print_irq(struct devinfo_rman *rman, void *arg) {
QTreeWidget* tree = (QTreeWidget *)arg;
if (strcmp(rman->dm_desc, "Interrupt request lines")==0) {
QStringList list;
list << rman->dm_desc;
new QTreeWidgetItem(tree, list);
devinfo_foreach_rman_resource(rman, print_resource, arg);
}
return(0);
}
return 0;
}
int print_dma(struct devinfo_rman *rman, void *arg)
{
Q3ListView *lbox = (Q3ListView *)arg;
if (strcmp(rman->dm_desc, "DMA request lines")==0) {
(void)new Q3ListViewItem(lbox, lbox->lastItem(), rman->dm_desc);
QTreeWidget* tree = (QTreeWidget *)arg;
if (strcmp(rman->dm_desc, "DMA request lines")==0) {
QStringList list;
list << rman->dm_desc;
new QTreeWidgetItem(tree, list);
devinfo_foreach_rman_resource(rman, print_resource, arg);
}
return(0);
}
return(0);
}
int print_ioports(struct devinfo_rman *rman, void *arg)
{
Q3ListView *lbox = (Q3ListView *)arg;
QTreeWidget* tree = (QTreeWidget*) arg;
if (strcmp(rman->dm_desc, "I/O ports")==0) {
(void)new Q3ListViewItem(lbox, lbox->lastItem(), rman->dm_desc);
devinfo_foreach_rman_resource(rman, print_resource, arg);
}
else if (strcmp(rman->dm_desc, "I/O memory addresses")==0) {
(void)new Q3ListViewItem(lbox, lbox->lastItem(), rman->dm_desc);
QStringList list;
list << rman->dm_desc;
new QTreeWidgetItem(tree, list);
devinfo_foreach_rman_resource(rman, print_resource, arg);
}
return(0);
else if (strcmp(rman->dm_desc, "I/O memory addresses")==0) {
QStringList list;
list << rman->dm_desc;
new QTreeWidgetItem(tree, list);
devinfo_foreach_rman_resource(rman, print_resource, arg);
}
return 0;
}
int print_resource(struct devinfo_res *res, void *arg)
{
struct devinfo_dev *dev;
struct devinfo_rman *rman;
int hexmode;
struct devinfo_dev *dev;
struct devinfo_rman *rman;
int hexmode;
Q3ListView *lbox;
lbox = (Q3ListView *)arg;
QTreeWidget* tree = (QTreeWidget*) arg;
QString s, tmp;
rman = devinfo_handle_to_rman(res->dr_rman);
hexmode = (rman->dm_size > 100) || (rman->dm_size == 0);
tmp.sprintf(hexmode ? "0x%lx" : "%lu", res->dr_start);
rman = devinfo_handle_to_rman(res->dr_rman);
hexmode = (rman->dm_size > 100) || (rman->dm_size == 0);
tmp.sprintf(hexmode ? "0x%lx" : "%lu", res->dr_start);
s += tmp;
if (res->dr_size > 1) {
tmp.sprintf(hexmode ? "-0x%lx" : "-%lu",
res->dr_start + res->dr_size - 1);
if (res->dr_size > 1) {
tmp.sprintf(hexmode ? "-0x%lx" : "-%lu",
res->dr_start + res->dr_size - 1);
s += tmp;
}
dev = devinfo_handle_to_device(res->dr_device);
if ((dev != NULL) && (dev->dd_name[0] != 0)) {
tmp.sprintf(" (%s)", dev->dd_name);
} else {
tmp.sprintf(" ----");
}
dev = devinfo_handle_to_device(res->dr_device);
if ((dev != NULL) && (dev->dd_name[0] != 0)) {
tmp.sprintf(" (%s)", dev->dd_name);
} else {
tmp.sprintf(" ----");
}
s += tmp;
(void)new Q3ListViewItem(lbox, lbox->lastItem(), s);
return(0);
QStringList list;
list << s;
new QTreeWidgetItem(tree, list);
return 0;
}
#endif

View file

@ -0,0 +1,55 @@
/*
1998 by Helge Deller (deller@gmx.de)
free source under GPL
!!!!! this file will be included by info.cpp !!!!!
*/
// Default for unsupportet systems
/* all following functions should return true, when the Information
was filled into the lBox-Widget.
returning false indicates, that information was not available.
*/
bool GetInfo_CPU(QTreeWidget*) {
return false;
}
bool GetInfo_IRQ(QTreeWidget*) {
return false;
}
bool GetInfo_DMA(QTreeWidget*) {
return false;
}
bool GetInfo_PCI(QTreeWidget*) {
return false;
}
bool GetInfo_IO_Ports(QTreeWidget*) {
return false;
}
bool GetInfo_Sound(QTreeWidget*) {
return false;
}
bool GetInfo_Devices(QTreeWidget*) {
return false;
}
bool GetInfo_SCSI(QTreeWidget*) {
return false;
}
bool GetInfo_Partitions(QTreeWidget*) {
return false;
}
bool GetInfo_XServer_and_Video(QTreeWidget* tree) {
return GetInfo_XServer_Generic(tree);
}

View file

@ -0,0 +1,560 @@
/*
!!!!! this file will be included by info.cpp !!!!!
Mostly written 1998-1999 by Helge Deller (deller@gmx.de),
with some pieces of code from Aubert Pierre.
Last modified: done:
1999-06-21 added more models to the lookup-table (deller)
1999-06-18 added support for 64-Bit HP-UX in CPU-detection(deller)
1999-05-04 added audio(alib)-support (deller)
1999-04-27 [tested with HP-UX 10.20 (HP9000/715/64-EISA)]
added support for nearly all categories
(means: not finished!)
1998-11-01 first, nearly empty version (deller)
with a little source for CPU from Aubert Pierre
*/
#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/pstat.h>
#include <sys/utsname.h>
#include <sys/statvfs.h>
#include <sys/vfs.h>
#include <fstab.h>
#include <stdlib.h>
#include <QFile>
#include <QFontMetrics>
#include <QTextStream>
# define INFO_CPU_MODEL "/bin/model" // as pipe !!
# define INFO_PCI "" // Please, who know it ????
# define INFO_PCI_EISA "/etc/eisa/system.sci" // File !
# define INFO_IOPORTS_1 "/etc/dmesg" // as pipe !
# define INFO_IOPORTS_2 "/usr/sbin/dmesg" // as pipe !
# define INFO_DEVICES "/etc/ioscan" // as pipe !!
# define INFO_PARTITIONS_1 FSTAB // = "/etc/fstab" (in fstab.h)
# define INFO_PARTITIONS_2 "/etc/checklist"
/* The following table is from an HP-UX 10.20 System
build out of the files
"/usr/lib/sched.models"
or
"/opt/langtools/lib/sched.models"
If you have more entries, then please add them or send them to me!
*/
// entries for PA_REVISION[]
enum V_ENTRIES
{ V_1x0,
V_1x1, V_1x1a, V_1x1b, V_1x1c, V_1x1d, V_1x1e,
V_2x0,
V_LAST};
static const char PA_REVISION[V_LAST][7] = { "1.0", "1.1", "1.1a", "1.1b", "1.1c", "1.1d", "1.1e", "2.0" };
// entries for PA_NAME[]
enum PA_ENTRIES
{ PA7000,
PA7100, PA7100LC, PA7200, PA7300,
PA8000, PA8200, PA8500,
PARISC_PA_LAST};
static const char PA_NAME[PARISC_PA_LAST][11] = { "PA7000", "PA7100", "PA7100LC", "PA7200", "PA7300", "PA8000", "PA8200", "PA8500" };
struct _type_LOOKUPTABLE {
char Name[8];
unsigned short parisc_rev; // = enum V_ENTRIES
unsigned short parisc_name; // = enum PA_ENTRIES
};
static const struct _type_LOOKUPTABLE PA_LOOKUPTABLE[] = {
/* VERSION A.00.07
(there seems to exist several different files with same version-number !)*/
{ "600", V_1x0, PA7000 }, { "635", V_1x0, PA7000 }, { "645", V_1x0, PA7000 }, { "700", V_1x1, PA7000 }, { "705", V_1x1a, PA7000 }, { "710", V_1x1a, PA7000 }, { "712", V_1x1c, PA7100LC }, { "715", V_1x1c, PA7100LC }, { "720", V_1x1a, PA7000 }, { "722", V_1x1c, PA7100LC },
{ "725", V_1x1c, PA7100LC }, { "728", V_1x1d, PA7200 }, { "730", V_1x1a, PA7000 }, { "735", V_1x1b, PA7100 },
{ "742", V_1x1b, PA7100 },
{ "743", V_1x1b, PA7100 }, // or a 1.1c,PA7100LC !!
{ "744", V_1x1e, PA7300 }, { "745", V_1x1b, PA7100 }, { "747", V_1x1b, PA7100 }, { "750", V_1x1a, PA7000 }, { "755", V_1x1b, PA7100 }, { "770", V_1x1d, PA7200 }, { "777", V_1x1d, PA7200 }, { "778", V_1x1e, PA7300 }, { "779", V_1x1e, PA7300 }, { "780", V_2x0, PA8000 },
{ "781", V_2x0, PA8000 }, { "782", V_2x0, PA8200 }, { "783", V_2x0, PA8500 }, { "785", V_2x0, PA8500 },
{ "800", V_1x0, PA7000 }, // and one with: 2.0 / PA8000
{ "801", V_1x1c, PA7100LC }, { "802", V_2x0, PA8000 }, { "803", V_1x1e, PA7300 }, { "804", V_2x0, PA8000 }, { "806", V_1x1c, PA7100LC }, { "807", V_1x1a, PA7000 }, { "808", V_1x0, PA7000 }, { "809", V_1x1d, PA7200 }, { "810", V_2x0, PA8000 }, { "811", V_1x1c, PA7100LC }, { "813", V_1x1e,
PA7300 }, { "815", V_1x0, PA7000 }, { "816", V_1x1c, PA7100LC }, { "817", V_1x1a, PA7000 }, { "819", V_1x1d, PA7200 }, { "820", V_2x0, PA8000 }, { "821", V_1x1d, PA7200 }, { "822", V_1x0, PA7000 }, { "825", V_1x0, PA7000 }, { "826", V_1x1c, PA7100LC }, { "827", V_1x1a, PA7000 }, {
"829", V_1x1d, PA7200 }, { "831", V_1x1d, PA7200 }, { "832", V_1x0, PA7000 }, { "834", V_1x0, PA7000 }, { "835", V_1x0, PA7000 }, { "837", V_1x1a, PA7000 }, { "839", V_1x1d, PA7200 }, { "840", V_1x0, PA7000 }, { "841", V_1x1d, PA7200 }, { "842", V_1x0, PA7000 }, { "845", V_1x0,
PA7000 }, { "847", V_1x1a, PA7000 }, { "849", V_1x1d, PA7200 }, { "850", V_1x0, PA7000 }, { "851", V_1x1d, PA7200 }, { "852", V_1x0, PA7000 }, { "855", V_1x0, PA7000 }, { "856", V_1x1c, PA7100LC }, { "857", V_1x1a, PA7000 }, { "859", V_1x1d, PA7200 }, { "860", V_1x0, PA7000 }, {
"861", V_2x0, PA8000 }, { "865", V_1x0, PA7000 }, { "869", V_1x1d, PA7200 }, { "870", V_1x0, PA7000 }, { "871", V_2x0, PA8000 }, { "877", V_1x1a, PA7000 }, { "879", V_2x0, PA8000 }, { "887", V_1x1b, PA7100 }, { "889", V_2x0, PA8000 }, { "890", V_1x0, PA7000 }, { "891", V_1x1b,
PA7100 }, { "892", V_1x1b, PA7100 }, { "893", V_2x0, PA8000 }, { "895", V_2x0, PA8000 }, { "896", V_2x0, PA8000 }, { "897", V_1x1b, PA7100 }, { "898", V_2x0, PA8200 }, { "899", V_2x0, PA8200 }, { "900", V_1x0, PA7000 }, { "B115", V_1x1e, PA7300 }, { "B120", V_1x1e, PA7300 }, {
"B132L", V_1x1e, PA7300 }, { "B160L", V_1x1e, PA7300 }, { "B180L", V_1x1e, PA7300 }, { "C100", V_1x1d, PA7200 }, { "C110", V_1x1d, PA7200 }, { "C115", V_1x1e, PA7300 }, { "C120", V_1x1e, PA7300 }, { "C130", V_2x0, PA8000 }, { "C140", V_2x0, PA8000 }, { "C160L", V_1x1e, PA7300 }, {
"C160", V_2x0, PA8000 }, { "C180L", V_1x1e, PA7300 }, { "C180-XP", V_2x0, PA8000 }, { "C180", V_2x0, PA8000 }, { "C200+", V_2x0, PA8200 }, { "C230+", V_2x0, PA8200 }, { "C240+", V_2x0, PA8200 }, { "CB260", V_2x0, PA8200 },
{ "D200", V_1x1d, PA7200 }, // or: 1.1c, PA7100LC
{ "D210", V_1x1d, PA7200 }, // or: 1.1c, PA7100LC
{ "D220", V_1x1e, PA7300 }, { "D230", V_1x1e, PA7300 }, { "D250", V_1x1d, PA7200 }, { "D260", V_1x1d, PA7200 }, { "D270", V_2x0, PA8000 }, { "D280", V_2x0, PA8000 }, { "D310", V_1x1c, PA7100LC }, { "D320", V_1x1e, PA7300 }, { "D330", V_1x1e, PA7300 }, { "D350", V_1x1d, PA7200 }, { "D360",
V_1x1d, PA7200 }, { "D370", V_2x0, PA8000 }, { "D380", V_2x0, PA8000 }, { "D400", V_1x1d, PA7200 }, { "D410", V_1x1d, PA7200 }, { "D650", V_2x0, PA8000 }, { "DX0", V_1x1c, PA7100LC }, { "DX5", V_1x1c, PA7100LC }, { "DXO", V_1x1c, PA7100LC }, { "E25", V_1x1c, PA7100LC }, { "E35",
V_1x1c, PA7100LC }, { "E45", V_1x1c, PA7100LC }, { "E55", V_1x1c, PA7100LC }, { "F10", V_1x1a, PA7000 }, { "F20", V_1x1a, PA7000 }, { "F30", V_1x1a, PA7000 }, { "G30", V_1x1a, PA7000 }, { "G40", V_1x1a, PA7000 }, { "G50", V_1x1b, PA7100 }, { "G60", V_1x1b, PA7100 }, { "G70", V_1x1b,
PA7100 }, { "H20", V_1x1a, PA7000 }, { "H30", V_1x1a, PA7000 }, { "H40", V_1x1a, PA7000 }, { "H50", V_1x1b, PA7100 }, { "H60", V_1x1b, PA7100 }, { "H70", V_1x1b, PA7100 }, { "I30", V_1x1a, PA7000 }, { "I40", V_1x1a, PA7000 }, { "I50", V_1x1b, PA7100 }, { "I60", V_1x1b, PA7100 }, {
"I70", V_1x1b, PA7100 }, { "J200", V_1x1d, PA7200 }, { "J210XC", V_1x1d, PA7200 }, { "J210", V_1x1d, PA7200 }, { "J220", V_2x0, PA8000 }, { "J2240", V_2x0, PA8200 }, { "J280", V_2x0, PA8000 }, { "J282", V_2x0, PA8000 }, { "J400", V_2x0, PA8000 }, { "J410", V_2x0, PA8000 }, { "K100",
V_1x1d, PA7200 }, { "K200", V_1x1d, PA7200 }, { "K210", V_1x1d, PA7200 }, { "K230", V_1x1d, PA7200 }, { "K250", V_2x0, PA8000 }, { "K260", V_2x0, PA8000 }, { "K370", V_2x0, PA8200 }, { "K380", V_2x0, PA8200 }, { "K400", V_1x1d, PA7200 }, { "K410", V_1x1d, PA7200 }, { "K420", V_1x1d,
PA7200 }, { "K430", V_1x1d, PA7200 }, { "K450", V_2x0, PA8000 }, { "K460", V_2x0, PA8000 }, { "K470", V_2x0, PA8200 }, { "K570", V_2x0, PA8200 }, { "K580", V_2x0, PA8200 }, { "S700i", V_1x1e, PA7300 }, { "S715", V_1x1e, PA7300 }, { "S744", V_1x1e, PA7300 },
{ "S760", V_1x1e, PA7300 }, { "T500", V_1x1c, PA7100LC }, // or: 1.1b, PA7100
{ "T520", V_1x1b, PA7100 }, { "T540", V_2x0, PA8000 }, { "T600", V_2x0, PA8000 }, { "V2000", V_2x0, PA8000 }, { "V2200", V_2x0, PA8200 }, { "V2250", V_2x0, PA8200 }, { "V2500", V_2x0, PA8500 },
{ "", 0, 0 } /* Last Entry has to be empty. */
};
/* Helper-Functions */
// Value() is defined in info.cpp !!!
static bool Find_in_LOOKUPTABLE(QListView *lBox, char *machine) {
char *Machine;
int len;
const struct _type_LOOKUPTABLE *Entry = PA_LOOKUPTABLE;
QString str;
QListViewItem* olditem = 0;
Machine = machine; // machine is like: "9000/715/D"
while ((*Machine) && (*Machine!='/'))
++Machine;
if (*Machine)
++Machine;
else
Machine=machine;
len = strlen(Machine);
while (Entry->Name[0]) {
if (strncmp(Entry->Name, Machine, len)==0) {
olditem = new QListViewItem(lBox, olditem, i18n("PA-RISC Processor"),
QString(PA_NAME[Entry->parisc_name]));
olditem = new QListViewItem(lBox, olditem, i18n("PA-RISC Revision"),
QString("PA-RISC ") + QString(PA_REVISION[Entry->parisc_rev]));
return true;
} else
++Entry; // next Entry !
}
return false;
}
/* all following functions should return true, when the Information
was filled into the lBox-Widget.
returning false indicates, that information was not available.
*/
bool GetInfo_CPU(QListView *lBox) {
FILE *pipe;
QFile *model;
struct pst_dynamic psd;
struct pst_static pst;
struct pst_processor pro;
struct utsname info;
QString str, str2;
QListViewItem* olditem = 0;
int maxwidth, i;
if ((pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1) || (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0)== -1)) {
return false;
}
maxwidth = 0;
lBox->addColumn(i18n("Information") );
lBox->addColumn(i18n("Value") );
uname(&info);
olditem = new QListViewItem(lBox, olditem, i18n("Machine"), info.machine);
model = new QFile(INFO_CPU_MODEL);
if (model->exists()) {
if ((pipe = popen(INFO_CPU_MODEL, "r"))) {
QTextStream *t = new QTextStream(pipe, QIODevice::ReadOnly);
str = t->readLine();
olditem = new QListViewItem(lBox, olditem, i18n("Model"), str);
delete t;
}
delete pipe;
}
delete model;
olditem = new QListViewItem(lBox, olditem, i18n("Machine Identification Number"),
strlen(info.__idnumber) ? QString(info.__idnumber) : i18n("(none)") );
if (psd.psd_proc_cnt<=0)
psd.psd_proc_cnt=1; // Minimum one CPU !
olditem = new QListViewItem(lBox, olditem, i18n("Number of Active Processors"),
Value(psd.psd_proc_cnt));
pstat_getprocessor( &pro, sizeof(pro), 1, 0);
olditem = new QListViewItem(lBox, olditem, i18n("CPU Clock"),
Value(pro.psp_iticksperclktick/10000) + ' ' + i18n("MHz"));
switch (sysconf(_SC_CPU_VERSION)) {
case CPU_HP_MC68020:
str2 = "Motorola 68020";
break;
case CPU_HP_MC68030:
str2 = "Motorola 68030";
break;
case CPU_HP_MC68040:
str2 = "Motorola 68040";
break;
case CPU_PA_RISC1_0:
str2 = "PA-RISC 1.0";
break;
case CPU_PA_RISC1_1:
str2 = "PA-RISC 1.1";
break;
case CPU_PA_RISC1_2:
str2 = "PA-RISC 1.2";
break;
case CPU_PA_RISC2_0:
#if defined(_SC_KERNEL_BITS)
switch (sysconf(_SC_KERNEL_BITS)) {
case 64: str2 = "PA-RISC 2.0w (64 bit)"; break;
case 32: str2 = "PA-RISC 2.0n (32 bit)"; break;
default: str2 = "PA-RISC 2.0"; break;
}; break;
#else /* !defined(_SC_KERNEL_BITS) */
str2 = "PA-RISC 2.0";
break;
#endif
default:
str2 = i18n("(unknown)");
break;
}
olditem = new QListViewItem(lBox, olditem, i18n("CPU Architecture"), str2);
Find_in_LOOKUPTABLE(lBox, info.machine);// try to get extended Information.
for (i=PS_PA83_FPU; i<=PS_PA89_FPU; ++i) {
if ((1<<(i-1)) & pro.psp_coprocessor.psc_present) {
str = QString( (i==PS_PA83_FPU) ? "PS_PA83_FPU" : "PS_PA89_FPU") + QString(" (") + QString(((1<<(i-1))&pro.psp_coprocessor.psc_enabled) ? i18n("enabled") : i18n("disabled") ) + QString(")");
olditem = new QListViewItem(lBox, olditem, i18n("Numerical Coprocessor (FPU)"), str);
}
}// for(coprocessor..)
str = Value(((pst.physical_memory*pst.page_size)/1024/1024)) + QString(" ") + i18n("MB"); // Mega-Byte
olditem = new QListViewItem(lBox, olditem, i18n("Total Physical Memory"), str);
str = Value(pst.page_size) + QString(" ") + i18n("Bytes");
olditem = new QListViewItem(lBox, olditem, i18n("Size of One Page"), str);
return true;
}
bool GetInfo_ReadfromFile(QListView *lBox, const char *Name) {
char buf[2048];
QFile *file = new QFile(Name);
QListViewItem* olditem = 0;
if (!file->open(QIODevice::ReadOnly)) {
delete file;
return false;
}
while (file->readLine(buf, sizeof(buf)-1) >= 0) {
if (strlen(buf))
olditem = new QListViewItem(lBox, olditem, QString::fromLocal8Bit(buf));
}
file->close();
delete file;
return (lBox->childCount());
}
bool GetInfo_IRQ(QListView *) {
return false;
}
bool GetInfo_DMA(QListView *) {
return false;
}
bool GetInfo_PCI(QTreeWidget* tree) {
return (GetInfo_ReadfromFile(tree, INFO_PCI) + GetInfo_ReadfromFile(tree, INFO_PCI_EISA) );
}
bool GetInfo_IO_Ports(QListView *lBox) {
if (GetInfo_ReadfromPipe(lBox, INFO_IOPORTS_1, false))
return true;
else
return GetInfo_ReadfromPipe(lBox, INFO_IOPORTS_2, false);
}
bool GetInfo_Devices(QListView *lBox) {
return GetInfo_ReadfromPipe(lBox, INFO_DEVICES, false);
}
bool GetInfo_SCSI(QListView *lBox) {
return GetInfo_Devices(lBox);
}
/* Parts taken from fsusage.c from the Midnight Commander (mc)
Copyright (C) 1991, 1992 Free Software Foundation, In
Return the number of TOSIZE-byte blocks used by
BLOCKS FROMSIZE-byte blocks, rounding away from zero.
TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */
static long fs_adjust_blocks(long blocks, int fromsize, int tosize) {
if (tosize <= 0)
abort();
if (fromsize <= 0)
return -1;
if (fromsize == tosize) /* E.g., from 512 to 512. */
return blocks;
else if (fromsize > tosize) /* E.g., from 2048 to 512. */
return blocks * (fromsize / tosize);
else
/* E.g., from 256 to 512. */
return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize);
}
/* Fill in the fields of FSP with information about space usage for
the filesystem on which PATH resides.
Return 0 if successful, -1 if not. */
#define CONVERT_BLOCKS(b) fs_adjust_blocks ((b), fsd.f_bsize, 512)
static int get_fs_usage(char *path, long *l_total, long *l_avail) {
struct statfs fsd; /* 4.3BSD, SunOS 4, HP-UX, AIX. */
unsigned long fsu_blocks, fsu_bfree, fsu_bavail;
*l_total = *l_avail = 0;
if (statfs(path, &fsd) < 0)
return -1;
fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks);
fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree);
fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail);
*l_avail = getuid() ? fsu_bavail/2 : fsu_bfree/2;
*l_total = fsu_blocks/2;
return 0;
}
// Some Ideas taken from garbazo from his source in info_fbsd.cpp
bool GetInfo_Partitions(QListView *lbox) {
#define NUMCOLS 5
QString Title[NUMCOLS];
int n;
struct fstab *fstab_ent;
struct statvfs svfs;
long total, avail;
QString str;
QString MB(i18n("MB")+ " "); // International Text for MB=Mega-Byte
if (setfsent() != 1) // Try to open fstab
return false;
Title[0] = i18n("Device");
Title[1] = i18n("Mount Point");
Title[2] = i18n("FS Type");
Title[3] = i18n("Total Size");
Title[4] = i18n("Free Size");
for (n=0; n<NUMCOLS; ++n) {
lbox->addColumn(Title[n]);
}
while ((fstab_ent=getfsent())!=NULL) {
/* fstab_ent->fs_type holds only "rw","xx","ro"... */
memset(&svfs, 0, sizeof(svfs));
statvfs(fstab_ent->fs_file, &svfs);
get_fs_usage(fstab_ent->fs_file, &total, &avail);
if (!strcmp(fstab_ent->fs_type, FSTAB_XX)) // valid drive ?
svfs.f_basetype[0] = 0;
if (svfs.f_basetype[0]) {
new QListViewItem(lbox, QString(fstab_ent->fs_spec),
QString(fstab_ent->fs_file) + QString(" "),
(svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a")),
Value((total+512)/1024,6) + MB,
Value((avail+512)/1024,6) + MB);
} else {
new QListViewItem(lbox, QString(fstab_ent->fs_spec),
QString(fstab_ent->fs_file) + QString(" "),
(svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a")));
}
}
endfsent();
return true;
}
bool GetInfo_XServer_and_Video(QListView *lBox) {
lBox = lBox;
return GetInfo_XServer_Generic(lBox);
}
#ifndef HAVE_ALIB_H
bool GetInfo_Sound(QListView * /*lBox*/) {
return false;
}
#else // defined(HAVE_ALIB_H)
#include "Alib.h"
static const char formatNames[6][15] = {
"ADFUnknown", "ADFMuLaw", "ADFALaw",
"ADFLin16", "ADFLin8", "ADFLin8Offset"};
/* handle typo in 1st release of Alib.h */
#ifndef ARightOutputChMask
#define ARightOutputChMask ARighOutputChMask
#endif
bool GetInfo_Sound( QListView *lBox )
{
Audio *audio;
long status;
char server[80];
int i;
QString str,str2;
QListViewItem* olditem = 0;
// server = Hostname....
server[0] = 0;
audio = AOpenAudio( server, &status );
if( status ) {
return false;
}
lBox->addColumn(i18n("Information") );
lBox->addColumn(i18n("Value") );
olditem = new QListViewItem(lBox, olditem, i18n("Audio Name"), QString(audio->audio_name));
olditem = new QListViewItem(lBox, olditem, i18n("Vendor"), QString(audio->vendor));
olditem = new QListViewItem(lBox, olditem, i18n("Alib Version"),
Value(audio->alib_major_version) + QString(".") +
Value(audio->alib_minor_version));
olditem = new QListViewItem(lBox, olditem, i18n("Protocol Revision"),
Value(audio->proto_major_version) + QString(".") +
Value(audio->proto_minor_version));
olditem = new QListViewItem(lBox, olditem, i18n("Vendor Number"),
Value(audio->vnumber));
olditem = new QListViewItem(lBox, olditem, i18n("Release"),
Value(audio->release));
olditem = new QListViewItem(lBox, olditem, i18n("Byte Order"),
QString((audio->byte_order==ALSBFirst)? i18n("ALSBFirst (LSB)"):
((audio->byte_order==AMSBFirst)? i18n("AMSBFirst (MSB)"):
i18n("Invalid Byteorder.")) ));
olditem = new QListViewItem(lBox, olditem, i18n("Bit Order"),
QString((audio->sound_bit_order==ALeastSignificant)?
i18n("ALeastSignificant (LSB)") :
((audio->sound_bit_order==AMostSignificant) ?
i18n("AMostSignificant (MSB)"):i18n("Invalid Bitorder.")) ));
olditem = new QListViewItem(lBox, olditem, i18n("Data Formats"));
for ( i = 0; i < audio->n_data_format; i++ ) {
if (audio->data_format_list[i] <= ADFLin8Offset)
new QListViewItem(olditem, QString(formatNames[audio->data_format_list[i]]));
}
olditem->setExpanded(true);
olditem = new QListViewItem(lBox, olditem, i18n("Sampling Rates"));
for ( i = 0; i < audio->n_sampling_rate; i++ ) {
new QListViewItem(olditem, Value(audio->sampling_rate_list[i]));
}
olditem->setExpanded(true);
olditem = new QListViewItem(lBox, olditem, i18n("Input Sources"));
if ( audio->input_sources & AMonoMicrophoneMask )
new QListViewItem(olditem, i18n("Mono-Microphone"));
if ( audio->input_sources & AMonoAuxiliaryMask )
new QListViewItem(olditem, i18n("Mono-Auxiliary"));
if ( audio->input_sources & ALeftMicrophoneMask )
new QListViewItem(olditem, i18n("Left-Microphone"));
if ( audio->input_sources & ARightMicrophoneMask )
new QListViewItem(olditem, i18n("Right-Microphone"));
if ( audio->input_sources & ALeftAuxiliaryMask )
new QListViewItem(olditem, i18n("Left-Auxiliary"));
if ( audio->input_sources & ARightAuxiliaryMask )
new QListViewItem(olditem, i18n("Right-Auxiliary"));
olditem->setExpanded(true);
olditem = new QListViewItem(lBox, olditem,i18n("Input Channels"));
if ( audio->input_channels & AMonoInputChMask )
new QListViewItem(olditem, i18n("Mono-Channel"));
if ( audio->input_channels & ALeftInputChMask )
new QListViewItem(olditem, i18n("Left-Channel"));
if ( audio->input_channels & ARightInputChMask )
new QListViewItem(olditem, i18n("Right-Channel"));
olditem->setExpanded(true);
olditem = new QListViewItem(lBox, olditem, i18n("Output Destinations"));
if ( audio->output_destinations & AMonoIntSpeakerMask )
new QListViewItem(olditem, i18n("Mono-InternalSpeaker"));
if ( audio->output_destinations & AMonoJackMask )
new QListViewItem(olditem, i18n("Mono-Jack"));
if ( audio->output_destinations & ALeftIntSpeakerMask )
new QListViewItem(olditem, i18n("Left-InternalSpeaker"));
if ( audio->output_destinations & ARightIntSpeakerMask )
new QListViewItem(olditem, i18n("Right-InternalSpeaker"));
if ( audio->output_destinations & ALeftJackMask )
new QListViewItem(olditem, i18n("Left-Jack"));
if ( audio->output_destinations & ARightJackMask )
new QListViewItem(olditem, i18n("Right-Jack"));
olditem->setExpanded(true);
olditem = new QListViewItem(lBox, olditem, i18n("Output Channels"));
if ( audio->output_channels & AMonoOutputChMask )
new QListViewItem(olditem, i18n("Mono-Channel"));
if ( audio->output_channels & ALeftOutputChMask )
new QListViewItem(olditem, i18n("Left-Channel"));
if ( audio->output_channels & ARightOutputChMask )
new QListViewItem(olditem, i18n("Right-Channel"));
olditem->setExpanded(true);
olditem = new QListViewItem(lBox, olditem, i18n("Gain"));
new QListViewItem(olditem, i18n("Input Gain Limits"),
Value(audio->max_input_gain));
new QListViewItem(olditem,i18n("Output Gain Limits"),
Value(audio->min_output_gain) + QString(" ")
+ Value(audio->max_output_gain));
new QListViewItem(olditem, i18n("Monitor Gain Limits"),
Value(audio->min_monitor_gain) + QString(" ")
+ Value(audio->max_monitor_gain));
new QListViewItem(olditem, i18n("Gain Restricted"),
Value(audio->gm_gain_restricted));
olditem->setExpanded(true);
olditem = new QListViewItem(lBox, olditem,i18n("Lock"),
Value(audio->lock));
olditem = new QListViewItem(lBox, olditem, i18n("Queue Length"),
Value(audio->qlen));
olditem = new QListViewItem(lBox, olditem, i18n("Block Size"),
Value(audio->block_size));
olditem = new QListViewItem(lBox, olditem, i18n("Stream Port (decimal)"),
Value(audio->stream_port));
olditem = new QListViewItem(lBox, olditem, i18n("Ev Buffer Size"),
Value(audio->ev_buf_size));
olditem = new QListViewItem(lBox, olditem, i18n("Ext Number"),
Value(audio->ext_number));
ACloseAudio( audio, &status );
return true;
}
#endif // defined(HAVE_ALIB_H)

View file

@ -0,0 +1,531 @@
/*
Linux-specific Information about the Hardware.
(C) Copyright 1998-2001 by Helge Deller <deller@gmx.de>
To do (maybe?):
- include Information about XFree86 and/or Accelerated X
(needs to change configure-script, to see, if Header-files are available !)
- maybe also include information about the video-framebuffer devices
- rewrite detection-routines (maybe not to use the /proc-fs)
- more & better sound-information
/dev/sndstat support added: 1998-12-08 Duncan Haldane (f.d.m.haldane@cwix.com)
*/
#include <unistd.h>
#include <syscall.h>
#include <stdio.h>
#include <sys/stat.h>
#include <linux/kernel.h>
#include <ctype.h>
#include "config-infocenter.h"
#ifdef HAVE_FSTAB_H /* some Linux-versions don't have fstab.h */
# include <fstab.h>
# include <sys/statfs.h>
# define INFO_PARTITIONS_FULL_INFO /* show complete info */
#elif defined HAVE_MNTENT_H /* but maybe they have mntent.h ? */
# include <mntent.h>
# include <sys/vfs.h>
# define INFO_PARTITIONS_FULL_INFO /* show complete info */
#else
# undef INFO_PARTITIONS_FULL_INFO /* no partitions-info */
#endif
#ifdef HAVE_PCIUTILS
#include "pci.h"
#endif //HAVE_PCIUTILS
#include <QRegExp>
#include <QFile>
#include <QHeaderView>
#include <klocale.h>
#include <kiconloader.h>
#include <kglobalsettings.h>
#include <kdebug.h>
#define INFO_CPU "/proc/cpuinfo"
#define INFO_IRQ "/proc/interrupts"
#define INFO_DMA "/proc/dma"
#define INFO_PCI "/proc/pci"
#define INFO_IOPORTS "/proc/ioports"
#define INFO_DEV_SNDSTAT "/dev/sndstat"
#define INFO_SOUND "/proc/sound"
#define INFO_ASOUND "/proc/asound/oss/sndstat"
#define INFO_ASOUND09 "/proc/asound/sndstat"
#define INFO_DEVICES "/proc/devices"
#define INFO_MISC "/proc/misc"
#define INFO_SCSI "/proc/scsi/scsi"
#define INFO_PARTITIONS "/proc/partitions"
#define INFO_MOUNTED_PARTITIONS "/etc/mtab" /* on Linux... */
#define MAXCOLUMNWIDTH 600
bool GetInfo_ReadfromFile(QTreeWidget* tree, const char *FileName, const QChar& splitChar) {
bool added = false;
QFile file(FileName);
if (!file.exists()) {
return false;
}
if (!file.open(QIODevice::ReadOnly)) {
return false;
}
QTextStream stream(&file);
QString line = stream.readLine();
while (!line.isNull()) {
QString s1, s2;
if (!line.isEmpty()) {
if (!splitChar.isNull()) {
int pos = line.indexOf(splitChar);
s1 = line.left(pos-1).trimmed();
s2 = line.mid(pos+1).trimmed();
} else
s1 = line;
}
QStringList list;
list << s1 << s2;
new QTreeWidgetItem(tree, list);
added = true;
line = stream.readLine();
}
file.close();
return added;
}
bool GetInfo_CPU(QTreeWidget* tree) {
QStringList headers;
headers << i18n("Information") << i18n("Value");
tree->setHeaderLabels(headers);
return GetInfo_ReadfromFile(tree, INFO_CPU, ':');
}
bool GetInfo_IRQ(QTreeWidget* tree) {
tree->setFont(KGlobalSettings::fixedFont());
return GetInfo_ReadfromFile(tree, INFO_IRQ, 0);
}
bool GetInfo_DMA(QTreeWidget* tree) {
QFile file(INFO_DMA);
QStringList headers;
headers << i18n("DMA-Channel") << i18n("Used By");
tree->setHeaderLabels(headers);
if (file.exists() && file.open(QIODevice::ReadOnly)) {
QTextStream stream(&file);
QString line;
line = stream.readLine();
while (!line.isNull()) {
if (!line.isEmpty()) {
QRegExp rx("^\\s*(\\S+)\\s*:\\s*(\\S+)");
if (-1 != rx.indexIn(line)) {
QStringList list;
list << rx.cap(1) << rx.cap(2);
new QTreeWidgetItem(tree, list);
}
}
line = stream.readLine();
}
file.close();
} else {
return false;
}
return true;
}
bool GetInfo_PCI(QTreeWidget* tree) {
int num;
#ifdef HAVE_PCIUTILS
if ( (num = GetInfo_PCIUtils(tree))) {
return num;
}
#endif //HAVE_PCIUTILS
tree->header()->setVisible(false);
tree->setSortingEnabled(false);
/* try to get the output of the lspci package first */
if ((num = GetInfo_ReadfromPipe(tree, "lspci -v", true)) || (num = GetInfo_ReadfromPipe(tree, "/sbin/lspci -v", true)) || (num = GetInfo_ReadfromPipe(tree, "/usr/sbin/lspci -v", true)) || (num = GetInfo_ReadfromPipe(tree, "/usr/local/sbin/lspci -v", true)) || (num = GetInfo_ReadfromPipe(tree,
"/usr/bin/lspci -v", true)))
return num;
/* if lspci failed, read the contents of /proc/pci */
return GetInfo_ReadfromFile(tree, INFO_PCI, 0);
}
bool GetInfo_IO_Ports(QTreeWidget* tree) {
QStringList headers;
headers << i18n("I/O-Range") << i18n("Used By");
tree->setHeaderLabels(headers);
return GetInfo_ReadfromFile(tree, INFO_IOPORTS, ':');
}
bool GetInfo_Sound(QTreeWidget* tree) {
tree->setSortingEnabled(false);
if (GetInfo_ReadfromFile(tree, INFO_DEV_SNDSTAT, 0))
return true;
else if (GetInfo_ReadfromFile(tree, INFO_SOUND, 0))
return true;
else if (GetInfo_ReadfromFile(tree, INFO_ASOUND, 0))
return true;
else
return GetInfo_ReadfromFile(tree, INFO_ASOUND09, 0);
}
bool GetInfo_Devices(QTreeWidget* tree) {
kDebug() << "Linux Info Devices" << endl;
QFile file;
QTreeWidgetItem *misc=NULL;
tree->setRootIsDecorated(true);
QStringList headers;
headers << i18n("Devices") << i18n("Major Number") << i18n("Minor Number");
tree->setHeaderLabels(headers);
file.setFileName(INFO_DEVICES);
if (file.exists() && file.open(QIODevice::ReadOnly)) {
QTextStream stream(&file);
QTreeWidgetItem *parent=0L, *child=0L;
QString line = stream.readLine();
while (!line.isNull()) {
if (!line.isEmpty()) {
if (-1 != line.indexOf("character device", 0, Qt::CaseInsensitive)) {
QStringList list;
list << i18n("Character Devices");
parent = new QTreeWidgetItem(tree, list);
parent->setIcon(0, SmallIcon("chardevice"));
parent->setExpanded(true);
} else if (-1 != line.indexOf("block device", 0, Qt::CaseInsensitive)) {
QStringList list;
list << i18n("Block Devices");
parent = new QTreeWidgetItem(tree, list);
parent->setIcon(0, SmallIcon("blockdevice"));
parent->setExpanded(true);
} else {
QRegExp rx("^\\s*(\\S+)\\s+(\\S+)");
if (-1 != rx.indexIn(line)) {
if (parent) {
QStringList list;
list << rx.cap(2) << rx.cap(1);
child = new QTreeWidgetItem(parent, list);
} else {
QStringList list;
list << rx.cap(2) << rx.cap(1);
child = new QTreeWidgetItem(tree, list);
}
if (rx.cap(2)=="misc") {
misc=child;
}
}
}
}
line = stream.readLine();
}
file.close();
} else {
return false;
}
file.setFileName(INFO_MISC);
if (misc && file.exists() && file.open(QIODevice::ReadOnly)) {
QTextStream stream(&file);
misc->setText(0, i18n("Miscellaneous Devices"));
misc->setIcon(0, SmallIcon("memory"));
misc->setExpanded(true);
QString line = stream.readLine();
while (!line.isNull()) {
if (!line.isEmpty()) {
QRegExp rx("^\\s*(\\S+)\\s+(\\S+)");
if (-1 != rx.indexIn(line)) {
QStringList list;
list << rx.cap(2) << "10" << rx.cap(1);
new QTreeWidgetItem(misc, list);
}
}
line = stream.readLine();
}
file.close();
}
return true;
}
bool GetInfo_SCSI(QTreeWidget* tree) {
return GetInfo_ReadfromFile(tree, INFO_SCSI, 0);
}
static void cleanPassword(QString & str) {
int index = 0;
QString passwd("password=");
while (index >= 0) {
index = str.indexOf(passwd, index, Qt::CaseInsensitive);
if (index >= 0) {
index += passwd.length();
while (index < (int) str.length() && str[index] != ' ' && str[index] != ',')
str[index++] = '*';
}
}
}
#ifndef INFO_PARTITIONS_FULL_INFO
bool GetInfo_Partitions(QTreeWidget* tree)
{
return GetInfo_ReadfromFile(tree, INFO_PARTITIONS, 0);
}
#else /* INFO_PARTITIONS_FULL_INFO */
// Some Ideas taken from garbazo from his source in info_fbsd.cpp
#if ( defined(HAVE_LINUX_RAW_H) || defined(HAVE_SYS_RAW_H) ) && defined(HAVE_SYS_IOCTL_H) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
#include <sys/ioctl.h>
#include <fcntl.h>
#if defined(HAVE_SYS_RAW_H)
#include <sys/raw.h>
#elif defined(HAVE_LINUX_RAW_H)
#include <linux/raw.h>
#endif
/*
* get raw device bindings and information
*/
void Get_LinuxRawDevices(QTreeWidget* tree)
{
int f, i, err;
int new_raw_devs = 1;
struct raw_config_request rq;
QString devname;
QString MB(i18n("MB")); /* "MB" = "Mega-Byte" */
/* try to open the raw device control file */
f = open("/dev/rawctl", O_RDWR);
if (f == -1) {
f = open("/dev/raw", O_RDWR);
new_raw_devs = 0;
}
if (f == -1)
return;
for (i=1; i<256; i++) {
rq.raw_minor = i;
if (ioctl(f, RAW_GETBIND, &rq))
continue;
if (!rq.block_major) /* unbound ? */
continue;
unsigned int minor = rq.block_minor;
char first_letter;
switch ((int)rq.block_major) {
/* IDE drives */
case 3: first_letter = 'a';
set_ide_name:
devname = QString("/dev/hd%1%2")
.arg(QChar(first_letter + minor/64))
.arg(minor&63);
break;
case 22:first_letter = 'c'; goto set_ide_name;
case 33:first_letter = 'e'; goto set_ide_name;
case 34:first_letter = 'g'; goto set_ide_name;
case 56:first_letter = 'i'; goto set_ide_name;
case 57:first_letter = 'k'; goto set_ide_name;
case 88:first_letter = 'm'; goto set_ide_name;
case 89:first_letter = 'o'; goto set_ide_name;
case 90:first_letter = 'q'; goto set_ide_name;
case 91:first_letter = 's'; goto set_ide_name;
/* SCSI drives */
case 8: first_letter = 'a';
set_scsi_name:
devname = QString("/dev/sd%1%2")
.arg(QChar(first_letter + minor/16))
.arg(minor&15);
break;
case 65:first_letter = 'q'; goto set_scsi_name;
/* Compaq /dev/cciss devices */
case 104: case 105: case 106:
case 107: case 108: case 109:
devname = QString("/dev/cciss/c%1d%2")
.arg((int)rq.block_major-104)
.arg(minor&15);
break;
/* Compaq Intelligent Drive Array (ida) */
case 72: case 73: case 74: case 75:
case 76: case 77: case 78: case 79:
devname = QString("/dev/ida/c%1d%2")
.arg((int)rq.block_major-72)
.arg(minor&15);
break;
default: devname = QString("%1/%2")
.arg((int)rq.block_major)
.arg(minor);
}
/* TODO: get device size */
QString size = "";
QStringList list;
list << devname;
if (new_raw_devs)
list << QString("/dev/raw/raw%1").arg(i);
else
list << QString("/dev/raw%1").arg(i);
list << "raw" << size << " " << "";
new QTreeWidgetItem(tree, list);
}
close(f);
}
#else
#define Get_LinuxRawDevices(x) /* nothing */
#endif
bool GetInfo_Partitions(QTreeWidget* tree) {
QStringList Mounted_Partitions;
bool found_in_List;
int n;
#ifdef HAVE_FSTAB_H
struct fstab *fstab_ent;
# define FS_NAME fstab_ent->fs_spec // device-name
# define FS_FILE fstab_ent->fs_file // mount-point
# define FS_TYPE fstab_ent->fs_vfstype // fs-type
# define FS_MNTOPS fstab_ent->fs_mntops // mount-options
#else
struct mntent *mnt_ent;
FILE *fp;
# define FS_NAME mnt_ent->mnt_fsname // device-name
# define FS_FILE mnt_ent->mnt_dir // mount-point
# define FS_TYPE mnt_ent->mnt_type // fs-type
# define FS_MNTOPS mnt_ent->mnt_opts // mount-options
#endif
struct statfs sfs;
quint64 total, avail;
QString str, mountopts;
QString MB(i18n("MB")); /* "MB" = "Mega-Byte" */
#ifdef HAVE_FSTAB_H
if (setfsent() == 0) /* Try to open fstab */
return false;
#else
if (!(fp = setmntent("/etc/fstab", "r")))
return false;
#endif
/* read the list of already mounted file-systems.. */
QFile *file = new QFile(INFO_MOUNTED_PARTITIONS);
if (file->open(QIODevice::ReadOnly)) {
char buf[1024];
while (file->readLine(buf, sizeof(buf )) > 0) {
str = QString::fromLocal8Bit(buf);
if (str.length()) {
int p = str.indexOf(' '); /* find first space. */
if (p)
str.remove(p, 1024); /* erase all chars including space. */
Mounted_Partitions.append(str);
}
}
file->close();
}
delete file;
/* create the header-tables */
MB = QString(" ") + MB;
QStringList headers;
headers << i18n("Device") << i18n("Mount Point") << i18n("FS Type") << i18n("Total Size") << i18n("Free Size") << i18n("Mount Options");
tree->setHeaderLabels(headers);
for (n = 0; n < 6; ++n)
/* loop through all partitions... */
#ifdef HAVE_FSTAB_H
while ((fstab_ent = getfsent()) != NULL)
#else
while ((mnt_ent = getmntent(fp)) != NULL)
#endif
{
total = avail = 0; /* initialize size.. */
found_in_List = (Mounted_Partitions.contains(FS_NAME) > 0);
if (found_in_List && statfs(FS_FILE, &sfs) == 0) {
total = ((quint64) sfs.f_blocks) * sfs.f_bsize;
avail = (getuid() ? sfs.f_bavail : sfs.f_bfree) * ((quint64) sfs.f_bsize);
};
/*
if (stat(fstab_ent->fs_file,&st)!=0)
total = 0;
if (!S_ISDIR(st.st_mode))
total = 0;
*/
mountopts = FS_MNTOPS;
cleanPassword(mountopts);
if (total) {
QStringList list;
list << QString(FS_NAME) + " " << QString(FS_FILE) + " " << QString(FS_TYPE) + " " << Value((int) (((total / 1024) + 512) / 1024), 6) + MB << Value((int) (((avail / 1024) + 512) / 1024), 6) + MB << mountopts;
new QTreeWidgetItem(tree, list);
} else {
QStringList list;
list << QString(FS_NAME) + " " << QString(FS_FILE) + " " << QString(FS_TYPE) + " " << " " << " " << mountopts;
new QTreeWidgetItem(tree, list);
}
}
#ifdef HAVE_FSTAB_H
endfsent(); /* close fstab.. */
#else
endmntent(fp); /* close fstab.. */
#endif
/* get raw device entires if available... */
Get_LinuxRawDevices(tree);
tree->sortItems(1, Qt::AscendingOrder);
return true;
}
#endif /* INFO_PARTITIONS_FULL_INFO */
bool GetInfo_XServer_and_Video(QTreeWidget* tree) {
return GetInfo_XServer_Generic(tree);
}

View file

@ -11,21 +11,9 @@
* The code is placed into public domain. Do whatever you want with it.
*/
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_PCI_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
/*
* all following functions should return true, when the Information
* was filled into the lBox-Widget. Returning false indicates that
* was filled into the Tree Widget. Returning false indicates that
* information was not available.
*/
@ -39,73 +27,65 @@
#include <QFile>
#include <QFontMetrics>
#include <Q3StrList>
#include <QStringList>
#include <QTextStream>
#include <QTreeWidgetItemIterator>
#include <kdebug.h>
#include <kio/global.h> /* for KIO::convertSize() */
typedef struct
{
int string;
int name;
const char *title;
} hw_info_mib_list_t;
typedef struct {
int string;
int name;
const char *title;
} hw_info_mib_list_t;
bool GetInfo_CPU(Q3ListView *lBox)
{
static hw_info_mib_list_t hw_info_mib_list[]= {
{ 1, HW_MODEL, "Model" },
{ 1, HW_MACHINE, "Machine" },
{ 1, HW_MACHINE_ARCH, "Architecture" },
{ 0, HW_NCPU, "Number of CPUs" },
{ 0, HW_PAGESIZE, "Pagesize" },
{ 0,0,0 }
};
hw_info_mib_list_t *hw_info_mib;
bool GetInfo_CPU(QTreeWidget* tree) {
static hw_info_mib_list_t hw_info_mib_list[]= { { 1, HW_MODEL, "Model" }, { 1, HW_MACHINE, "Machine" }, { 1, HW_MACHINE_ARCH, "Architecture" }, { 0, HW_NCPU, "Number of CPUs" }, { 0, HW_PAGESIZE, "Pagesize" }, { 0, 0, 0 } };
hw_info_mib_list_t *hw_info_mib;
int mib[2], num;
char *buf;
size_t len;
QString value;
int mib[2], num;
char *buf;
size_t len;
QString value;
lBox->addColumn(i18n("Information"));
lBox->addColumn(i18n("Value"));
QStringList list;
list << i18n("Information") << i18n("Value");
tree->setHeaderLabels(list);
for ( hw_info_mib = hw_info_mib_list ; hw_info_mib->title ; ++hw_info_mib )
{
mib[0] = CTL_HW;
mib[1] = hw_info_mib->name;
if ( hw_info_mib->string ) {
sysctl(mib,2,NULL,&len,NULL,0);
if ( (buf = (char*)malloc(len)) ) {
sysctl(mib,2,buf,&len,NULL,0);
value = QString::fromLocal8Bit(buf);
free(buf);
for (hw_info_mib = hw_info_mib_list; hw_info_mib->title; ++hw_info_mib) {
mib[0] = CTL_HW;
mib[1] = hw_info_mib->name;
if (hw_info_mib->string) {
sysctl(mib, 2, NULL, &len, NULL, 0);
if ( (buf = (char*)malloc(len))) {
sysctl(mib, 2, buf, &len, NULL, 0);
value = QString::fromLocal8Bit(buf);
free(buf);
} else {
value = QString("Unknown");
}
} else {
len = sizeof(num);
sysctl(mib, 2, &num, &len, NULL, 0);
value = QString::number(num);
}
else {
value = QString("Unknown");
}
}
else {
len = sizeof(num);
sysctl(mib,2,&num,&len,NULL,0);
value = QString::number(num);
}
new Q3ListViewItem(lBox, hw_info_mib->title, value);
}
return true;
QStringList list;
list << hw_info_mib->title << value;
new QTreeWidgetItem(tree, list);
}
return true;
}
// this is used to find out which devices are currently
// on system
static bool GetDmesgInfo(Q3ListView *lBox, const char *filter,
void func(Q3ListView *, QString s))
{
QFile *dmesg = new QFile("/var/run/dmesg.boot");
static bool GetDmesgInfo(QTreeWidget* tree, const char *filter, void func(QTreeWidget* tree, QString s)) {
QFile *dmesg = new QFile("/var/run/dmesg.boot");
bool usepipe = false;
FILE *pipe = NULL;
FILE *pipe= NULL;
QTextStream *t;
bool seencpu = false;
QString s;
@ -113,31 +93,33 @@ static bool GetDmesgInfo(Q3ListView *lBox, const char *filter,
if (dmesg->exists() && dmesg->open(QIODevice::ReadOnly)) {
t = new QTextStream(dmesg);
}
else {
} else {
delete dmesg;
pipe = popen("/sbin/dmesg", "r");
if (!pipe) return false;
if (!pipe)
return false;
usepipe = true;
t = new QTextStream(pipe, QIODevice::ReadOnly);
}
Q3ListViewItem *olditem = NULL;
while(!(s = t->readLine().toLocal8Bit()).isNull()) {
while (!(s = t->readLine().toLocal8Bit()).isNull()) {
if (!seencpu) {
if (s.contains("cpu"))
seencpu = true;
else
continue;
}
if (s.contains("boot device") ||
s.contains("WARNING: old BSD partition ID!"))
if (s.contains("boot device") || s.contains("WARNING: old BSD partition ID!"))
break;
if (!filter || s.contains(QRegExp(filter))) {
if (func)
func(lBox, s);
else
olditem = new Q3ListViewItem(lBox, olditem, s);
func(tree, s);
else {
QStringList list;
list << s;
new QTreeWidgetItem(tree, list);
}
found = true;
}
}
@ -153,10 +135,7 @@ static bool GetDmesgInfo(Q3ListView *lBox, const char *filter,
return found;
}
void
AddIRQLine(Q3ListView *lBox, QString s)
{
void AddIRQLine(QTreeWidget* tree, QString s) {
int irqnum;
QString s2;
char numstr[3];
@ -171,95 +150,111 @@ AddIRQLine(Q3ListView *lBox, QString s)
strcpy(numstr, "??");
}
new Q3ListViewItem(lBox, numstr, s);
QStringList list;
list << numstr << s;
new QTreeWidgetItem(tree, list);
}
bool GetInfo_IRQ (Q3ListView *lBox)
{
lBox->addColumn(i18n("IRQ"));
lBox->addColumn(i18n("Device"));
lBox->setSorting(0);
lBox->setShowSortIndicator(false);
(void) GetDmesgInfo(lBox, "[ (]irq ", AddIRQLine);
bool GetInfo_IRQ(QTreeWidget* tree) {
QStringList headers;
headers << i18n("IRQ") << i18n("Device");
tree->setHeaderLabels(headers);
tree->sortItems(0, Qt::AscendingOrder);
tree->setSortingEnabled(false);
(void) GetDmesgInfo(tree, "[ (]irq ", AddIRQLine);
return true;
}
bool GetInfo_DMA (Q3ListView *)
{
bool GetInfo_DMA(QTreeWidget*) {
return false;
}
bool GetInfo_PCI (Q3ListView *lbox)
{
if (!GetDmesgInfo(lbox, "at pci", NULL))
new Q3ListViewItem(lbox, i18n("No PCI devices found."));
bool GetInfo_PCI(QTreeWidget* tree) {
if (!GetDmesgInfo(tree, "at pci", NULL)) {
QStringList list;
list << i18n("No PCI devices found.");
new QTreeWidgetItem(tree, list);
}
return true;
}
bool GetInfo_IO_Ports (Q3ListView *lbox)
{
if (!GetDmesgInfo(lbox, "port 0x", NULL))
new Q3ListViewItem(lbox, i18n("No I/O port devices found."));
bool GetInfo_IO_Ports(QTreeWidget* tree) {
if (!GetDmesgInfo(tree, "port 0x", NULL)) {
QStringList list;
list << i18n("No I/O port devices found.");
new QTreeWidgetItem(tree, list);
}
return true;
}
bool GetInfo_Sound (Q3ListView *lbox)
{
lbox->setSorting(false);
bool GetInfo_Sound(QTreeWidget* tree) {
tree->setSortingEnabled(false);
if (!GetDmesgInfo(lbox, "audio", NULL))
new Q3ListViewItem(lbox, i18n("No audio devices found."));
if (!GetDmesgInfo(tree, "audio", NULL)) {
QStringList list;
list << i18n("No audio devices found.");
new QTreeWidgetItem(tree, list);
}
// append information for each audio devices found
Q3ListViewItem *lvitem = lbox->firstChild();
for(; lvitem; lvitem = lvitem->nextSibling()) {
QTreeWidgetItemIterator it(tree, QTreeWidgetItemIterator::All);
while ( *it != NULL) {
QString s, s2;
int pos;
char *dev;
s = lvitem->text(0);
s = (*it)->text(0);
// The autoconf message is in form 'audio0 at auvia0: ...'
if (s.find("audio") == 0 && (pos = s.find(" at ")) > 0) {
s2 = s.mid(pos+4); // skip " at "
s2.remove(QRegExp("[:\n\t ].*"));
dev = strdup(s2.toAscii().data());
GetDmesgInfo(lbox, dev, NULL);
GetDmesgInfo(tree, dev, NULL);
free(dev);
}
++it;
}
return true;
}
bool GetInfo_Devices (Q3ListView *lBox)
{
(void) GetDmesgInfo(lBox, NULL, NULL);
bool GetInfo_Devices(QTreeWidget* tree) {
(void) GetDmesgInfo(tree, NULL, NULL);
return true;
}
bool GetInfo_SCSI (Q3ListView *lbox)
{
if (!GetDmesgInfo(lbox, "scsibus", NULL))
new Q3ListViewItem(lbox, i18n("No SCSI devices found."));
bool GetInfo_SCSI(QTreeWidget* tree) {
if (!GetDmesgInfo(tree, "scsibus", NULL)) {
QStringList list;
list << i18n("No SCSI devices found.");
new QTreeWidgetItem(tree, list);
}
// remove the 'waiting %d seconds for devices to settle' message
Q3ListViewItem *lvitem = lbox->firstChild();
for(; lvitem; lvitem = lvitem->nextSibling()) {
QString s = lvitem->text(0);
QTreeWidgetItemIterator it(tree, QTreeWidgetItemIterator::All);
while ( *it != NULL) {
QString s = (*it)->text(0);
if (s.contains("seconds for devices to settle")) {
lbox->removeItem(lvitem);
delete tree->takeItem( tree->indexOfTopLevelItem(*it) );
break;
}
++it;
}
return true;
}
bool GetInfo_Partitions (Q3ListView *lbox)
{
bool GetInfo_Partitions(QTreeWidget* tree) {
int num; // number of mounts
#ifdef HAVE_STATVFS
struct statvfs *mnt; // mount data pointer
@ -274,17 +269,12 @@ bool GetInfo_Partitions (Q3ListView *lbox)
}
// table headers
lbox->addColumn(i18n("Device"));
lbox->addColumn(i18n("Mount Point"));
lbox->addColumn(i18n("FS Type"));
lbox->addColumn(i18n("Total Size"));
lbox->addColumn(i18n("Free Size"));
lbox->addColumn(i18n("Total Nodes"));
lbox->addColumn(i18n("Free Nodes"));
lbox->addColumn(i18n("Flags"));
QStringList headers;
headers << i18n("Device") << i18n("Mount Point") << i18n("FS Type") << i18n("Total Size") << i18n("Free Size") << i18n("Total Nodes") << i18n("Free Nodes") << i18n("Flags");
tree->setHeaderLabels(headers);
// mnt points into a static array (no need to free it)
for(; num--; ++mnt) {
for (; num--; ++mnt) {
unsigned long long big[2];
QString vv[5];
@ -299,13 +289,13 @@ bool GetInfo_Partitions (Q3ListView *lbox)
// convert to strings
vv[0] = KIO::convertSize(big[0]);
vv[1] = QString("%1 (%2%)")
.arg(KIO::convertSize(big[1]))
.arg(mnt->f_blocks ? mnt->f_bavail*100/mnt->f_blocks : 0);
.arg(KIO::convertSize(big[1]))
.arg(mnt->f_blocks ? mnt->f_bavail*100/mnt->f_blocks : 0);
vv[2] = QString("%L1").arg(mnt->f_files);
vv[3] = QString("%L1 (%2%) ")
.arg(mnt->f_ffree)
.arg(mnt->f_files ? mnt->f_ffree*100/mnt->f_files : 0);
.arg(mnt->f_ffree)
.arg(mnt->f_files ? mnt->f_ffree*100/mnt->f_files : 0);
vv[4].clear();
#ifdef HAVE_STATVFS
@ -341,20 +331,18 @@ bool GetInfo_Partitions (Q3ListView *lbox)
#undef MNTF
// put it in the table
QStringList list;
// FIXME: there're more data but we have limited args (this is wrong! just add!)
new Q3ListViewItem(lbox,
// FIXME: names need pad space
mnt->f_mntfromname,
mnt->f_mntonname,
mnt->f_fstypename,
vv[0], vv[1], vv[2], vv[3], vv[4]);
// FIXME: names need pad space
list << mnt->f_mntfromname << mnt->f_mntonname << mnt->f_fstypename << vv[0] << vv[1] << vv[2] << vv[3] << vv[4];
new QTreeWidgetItem(tree, list);
}
// job well done
return true;
}
bool GetInfo_XServer_and_Video (Q3ListView *lBox)
{
return GetInfo_XServer_Generic( lBox );
bool GetInfo_XServer_and_Video(QTreeWidget* tree) {
return GetInfo_XServer_Generic(tree);
}

View file

@ -0,0 +1,297 @@
/*
* info_netbsd.cpp is part of the KDE program kcminfo. This displays
* various information about the OpenBSD system it's running on.
*
* Originally written by Jaromir Dolecek <dolecek@ics.muni.cz>. CPU info
* code has been imported from implementation of processor.cpp for KDE 1.0
* by David Brownlee <abs@NetBSD.org> as found in NetBSD packages collection.
* Hubert Feyer <hubertf@NetBSD.org> enhanced the sound information printing
* quite a lot, too.
*
* The code is placed into public domain. Do whatever you want with it.
*/
/*
* all following functions should return true, when the Information
* was filled into the QTreeWidget. Returning false indicates that
* information was not available.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <stdio.h> /* for NULL */
#include <stdlib.h> /* for malloc(3) */
#include <QFile>
#include <QFontMetrics>
#include <QTextStream>
#include <QTreeWidgetItemIterator>
#include <kdebug.h>
typedef struct {
int string;
int name;
const char *title;
} hw_info_mib_list_t;
bool GetInfo_CPU(QTreeWidget* tree) {
static hw_info_mib_list_t hw_info_mib_list[]= { { 1, HW_MODEL, "Model" }, { 1, HW_MACHINE, "Machine" }, { 0, HW_NCPU, "Number of CPUs" }, { 0, HW_PAGESIZE, "Pagesize" }, { 0, 0, 0 } };
hw_info_mib_list_t *hw_info_mib;
int mib[2], num;
char *buf;
size_t len;
QString value;
QStringList headers;
headers << i18n("Information") << i18n("Value");
tree->setHeaderLabels(headers);
for (hw_info_mib = hw_info_mib_list; hw_info_mib->title; ++hw_info_mib) {
mib[0] = CTL_HW;
mib[1] = hw_info_mib->name;
if (hw_info_mib->string) {
sysctl(mib, 2, NULL, &len, NULL, 0);
if ( (buf = (char*)malloc(len))) {
sysctl(mib, 2, buf, &len, NULL, 0);
value = QString::fromLocal8Bit(buf);
free(buf);
} else {
value = QString("Unknown");
}
} else {
len = sizeof(num);
sysctl(mib, 2, &num, &len, NULL, 0);
value.sprintf("%d", num);
}
QStringList list;
list << hw_info_mib->title << value;
new QTreeWidgetItem(tree, list);
}
return true;
}
// this is used to find out which devices are currently
// on system
static bool GetDmesgInfo(QTreeWidget* tree, const char *filter, void func(QTreeWidget *, QString s, void **, bool)) {
QFile *dmesg = new QFile("/var/run/dmesg.boot");
bool usepipe=false;
FILE *pipe=NULL;
QTextStream *t;
bool seencpu=false;
void *opaque=NULL;
QString s;
bool found=false;
if (dmesg->exists() && dmesg->open(QIODevice::ReadOnly)) {
t = new QTextStream(dmesg);
} else {
delete dmesg;
pipe = popen("/sbin/dmesg", "r");
if (!pipe)
return false;
usepipe = true;
t = new QTextStream(pipe, QIODevice::ReadOnly);
}
while (!(s = t->readLine()).isNull()) {
if (!seencpu) {
if (s.contains("cpu"))
seencpu = true;
else
continue;
}
if (s.contains("boot device") || s.contains("WARNING: old BSD partition ID!"))
break;
if (!filter || s.contains(filter)) {
if (func) {
func(tree, s, &opaque, false);
} else {
QStringList list;
list << s;
new QTreeWidgetItem(tree, list);
}
found = true;
}
}
if (func) {
func(tree, s, &opaque, true);
}
//tree->triggerUpdate();
delete t;
if (pipe) {
pclose(pipe);
} else {
dmesg->close();
delete dmesg;
}
return found;
}
void AddIRQLine(QTreeWidget* tree, QString s, void **opaque, bool ending) {
QStringList *strlist = (QStringList *) *opaque;
QString str;
int pos, irqnum=0;
const char *p;
p = s.toLatin1();
if (!strlist) {
strlist = new QStringList();
*opaque = (void *) strlist;
}
if (ending) {
foreach(QString temp, *strlist) {
QStringList tempList;
tempList << temp;
new QTreeWidgetItem(tree, tempList);
}
delete strlist;
return;
}
pos = s.find(" irq ");
irqnum = (pos < 0) ? 0 : atoi(&p[pos+5]);
if (irqnum) {
s.sprintf("%02d%s", irqnum, p);
} else {
s.sprintf("??%s", p);
}
strlist->append(s);
strlist->sort();
}
bool GetInfo_IRQ(QTreeWidget* tree) {
QStringList headers;
headers << i18n("IRQ") << i18n("Device");
tree->setHeaderLabels(headers);
(void) GetDmesgInfo(tree, " irq ", AddIRQLine);
return true;
}
bool GetInfo_DMA(QTreeWidget *) {
return false;
}
bool GetInfo_PCI(QTreeWidget* tree) {
if (!GetDmesgInfo(tree, "at pci", NULL)) {
QStringList list;
list << i18n("No PCI devices found.");
new QTreeWidgetItem(tree, list);
}
return true;
}
bool GetInfo_IO_Ports(QTreeWidget* tree) {
if (!GetDmesgInfo(tree, "port 0x", NULL)) {
QStringList list;
list << i18n("No I/O port devices found.");
new QTreeWidgetItem(tree, list);
}
return true;
}
bool GetInfo_Sound(QTreeWidget* tree) {
if (!GetDmesgInfo(tree, "audio", NULL)) {
QStringList list;
list << i18n("No audio devices found.");
new QTreeWidgetItem(tree, list);
}
// append information on any audio devices found
QTreeWidgetItemIterator it(tree, QTreeWidgetItemIterator::All);
while ( *it != NULL ) {
QTreeWidgetItem* lvitem = *it;
QString s;
int pos, len;
const char *start, *end;
char *dev;
s = lvitem->text(0);
if ((pos = s.find("at ")) >= 0) {
pos += 3; // skip "at "
start = end = s.toAscii();
for (; *end && (*end!=':') && (*end!='\n'); end++)
;
len = end - start;
dev = (char *) malloc(len + 1);
strncpy(dev, start, len);
dev[len] = '\0';
GetDmesgInfo(tree, dev, NULL);
free(dev);
}
++it;
}
return true;
}
bool GetInfo_Devices(QTreeWidget* tree) {
(void) GetDmesgInfo(tree, NULL, NULL);
return true;
}
bool GetInfo_SCSI(QTreeWidget* tree) {
if (!GetDmesgInfo(tree, "scsibus", NULL)) {
QStringList list;
list << i18n("No SCSI devices found.");
new QTreeWidgetItem(tree, list);
}
return true;
}
bool GetInfo_Partitions(QTreeWidget* tree) {
QString s;
char *line, *orig_line;
const char *device, *mountpoint, *type, *flags;
FILE *pipe = popen("/sbin/mount", "r");
QTextStream *t;
if (!pipe) {
kError(0) << i18n("Unable to run /sbin/mount.") << endl;
return false;
}
t = new QTextStream(pipe, QIODevice::ReadOnly);
QStringList headers;
headers << i18n("Device") << i18n("Mount Point") << i18n("FS Type") << i18n("Mount Options");
tree->setHeaderLabels(headers);
while (!(s = t->readLine()).isNull()) {
orig_line = line = strdup(s.toLatin1());
device = strsep(&line, " ");
(void) strsep(&line, " "); // consume word "on"
mountpoint = strsep(&line, " ");
(void) strsep(&line, " "); // consume word "type"
type = strsep(&line, " ");
flags = line;
QStringList mountList;
mountList << device << mountpoint << type << flags;
new QTreeWidgetItem(tree, mountList);
free(orig_line);
}
delete t;
pclose(pipe);
return true;
}
bool GetInfo_XServer_and_Video(QTreeWidget* tree) {
return GetInfo_XServer_Generic(tree);
}

View file

@ -19,17 +19,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#define INFO_CPU_AVAILABLE
//#define INFO_IRQ_AVAILABLE
//#define INFO_DMA_AVAILABLE
//#define INFO_PCI_AVAILABLE
//#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
/*
* all following functions should return true, when the Information
* was filled into the lBox-Widget. Returning false indicates that
@ -48,7 +37,6 @@
#include <qdict.h>
#include <QFile>
#include <QFontMetrics>
#include <Q3PtrList>
#include <QTextStream>
@ -63,24 +51,22 @@
#include <machine/limits.h>
bool GetInfo_CPU (QListView *lBox)
{
bool GetInfo_CPU(QListView *lBox) {
QString cpustring;
kern_return_t ret;
struct host_basic_info basic_info;
unsigned int count=HOST_BASIC_INFO_COUNT;
kern_return_t ret;
struct host_basic_info basic_info;
unsigned int count=HOST_BASIC_INFO_COUNT;
ret=host_info(mach_host_self(), HOST_BASIC_INFO,
(host_info_t)&basic_info, &count);
if (ret != KERN_SUCCESS) {
ret=host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&basic_info, &count);
if (ret != KERN_SUCCESS) {
kDebug() << "unable to get host information from mach";
return false;
} else {
} else {
kDebug() << "got Host Info: (" << basic_info.avail_cpus << ") CPUs available";
const NXArchInfo *archinfo;
archinfo=NXGetArchInfoFromCpuType(basic_info.cpu_type, basic_info.cpu_subtype);
const NXArchInfo *archinfo;
archinfo=NXGetArchInfoFromCpuType(basic_info.cpu_type, basic_info.cpu_subtype);
new QListViewItem(lBox, i18n("Kernel is configured for %1 CPUs", basic_info.max_cpus));
for (int i = 1; i <= basic_info.avail_cpus; i++) {
cpustring = i18n("CPU %1: %2", i, archinfo->description);
@ -91,28 +77,23 @@ bool GetInfo_CPU (QListView *lBox)
return false;
}
bool GetInfo_IRQ (QListView *)
{
bool GetInfo_IRQ(QListView *) {
return false;
}
bool GetInfo_DMA (QListView *)
{
bool GetInfo_DMA(QListView *) {
return false;
}
bool GetInfo_PCI (QListView *)
{
bool GetInfo_PCI(QTreeWidget*) {
return false;
}
bool GetInfo_IO_Ports (QListView *)
{
bool GetInfo_IO_Ports(QListView *) {
return false;
}
bool GetInfo_Sound (QListView *lBox)
{
bool GetInfo_Sound(QListView *lBox) {
#ifdef HAVE_COREAUDIO
#define qMaxStringSize 1024
OSStatus status;
@ -155,22 +136,18 @@ bool GetInfo_Sound (QListView *lBox)
#endif
}
bool GetInfo_SCSI (QListView *lbox)
{
bool GetInfo_SCSI(QListView *lbox) {
return false;
}
bool GetInfo_Partitions (QListView *lbox)
{
bool GetInfo_Partitions(QListView *lbox) {
return false;
}
bool GetInfo_XServer_and_Video (QListView *lBox)
{
return GetInfo_XServer_Generic( lBox );
bool GetInfo_XServer_and_Video(QListView *lBox) {
return GetInfo_XServer_Generic(lBox);
}
bool GetInfo_Devices (QListView *lbox)
{
bool GetInfo_Devices(QListView *lbox) {
return false;
}

View file

@ -0,0 +1,58 @@
/* info_sgi.cpp
!!!!! this file will be included by info.cpp !!!!!
*/
/* all following functions should return true, when the Information
was filled into the lBox-Widget.
returning false indicates, that information was not available.
*/
#include <sys/systeminfo.h>
bool GetInfo_CPU(QListView *lBox) {
QString str;
char buf[256];
sysinfo(SI_ARCHITECTURE, buf, sizeof(buf));
str = QString::fromLocal8Bit(buf);
new QListViewItem(lBox, str);
return true;
}
bool GetInfo_IRQ(QListView *) {
return false;
}
bool GetInfo_DMA(QListView *) {
return false;
}
bool GetInfo_PCI(QTreeWidget*) {
return false;
}
bool GetInfo_IO_Ports(QListView *) {
return false;
}
bool GetInfo_Sound(QListView *) {
return false;
}
bool GetInfo_Devices(QListView *) {
return false;
}
bool GetInfo_SCSI(QListView *) {
return false;
}
bool GetInfo_Partitions(QListView *) {
return false;
}
bool GetInfo_XServer_and_Video(QListView *lBox) {
return GetInfo_XServer_Generic(lBox);
}

View file

@ -0,0 +1,718 @@
/*
* info_solaris.cpp
*
* Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
*/
#include "config-infocenter.h"
#include <QTreeWidgetItemIterator>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mnttab.h>
#include <kstat.h>
#include <sys/types.h>
#include <sys/statvfs.h>
#include <time.h>
#ifdef HAVE_LIBDEVINFO_H
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <sys/mkdev.h>
#include <sys/stat.h>
#include <devid.h>
#include <libdevinfo.h>
#endif /* HAVE_LIBDEVINFO_H */
bool GetInfo_CPU(QTreeWidget* tree) {
kstat_ctl_t *kctl;
kstat_t *ksp;
kstat_named_t *kdata;
char cputype[16], fputype[16];
char *timetxt;
char *ptr;
uint32_t i, ncpus;
unsigned long state_begin;
QString state;
QString mhz;
QString inst;
/*
* get a kstat handle first and update the user's kstat chain
*/
if ( (kctl = kstat_open()) == NULL) {
return false;
}
while (kstat_chain_update(kctl) != 0)
;
/*
* get the # of CPUs
*/
if ( (ksp = kstat_lookup(kctl, "unix", 0, "system_misc")) == NULL) {
return false;
}
if (kstat_read(kctl, ksp, NULL) == -1) {
return false;
}
kdata = (kstat_named_t *) kstat_data_lookup(ksp, "ncpus");
if (kdata != NULL) {
ncpus = kdata->value.ui32;
} else {
ncpus = 0;
}
QStringList headers;
headers << i18n("Instance") << i18n("CPU Type") << i18n("FPU Type") << i18n("MHz") << i18n("State");
tree->setHeaderLabels(headers);
/*
* get the per-processor info
*/
for (i = 0; i < ncpus; i++) {
if ( (ksp = kstat_lookup(kctl, "cpu_info", i, NULL)) == NULL) {
return false;
}
if (kstat_read(kctl, ksp, NULL) == -1) {
return false;
}
inst.setNum(i);
kdata = (kstat_named_t *) kstat_data_lookup(ksp, "cpu_type");
if (kdata != NULL) {
strcpy(cputype, kdata->value.c);
} else {
sprintf(cputype, "???");
}
kdata = (kstat_named_t *) kstat_data_lookup(ksp, "fpu_type");
if (kdata != NULL) {
strcpy(fputype, kdata->value.c);
} else {
sprintf(fputype, "???");
}
kdata = (kstat_named_t *) kstat_data_lookup(ksp, "clock_MHz");
if (kdata != NULL) {
mhz.setNum(kdata->value.ul);
} else {
mhz.setNum( 0);
}
kdata = (kstat_named_t *) kstat_data_lookup(ksp, "state");
if (kdata != NULL) {
state = QString(kdata->value.c);
} else {
state = "???";
}
kdata = (kstat_named_t *) kstat_data_lookup(ksp, "state_begin");
if (kdata != NULL) {
state_begin = kdata->value.i32;
if ( (timetxt = ctime( (time_t *) &state_begin )) != NULL) {
ptr = strrchr(timetxt, '\n');
*ptr = '\0';
state += " since " + QString(timetxt);
}
}
QStringList list;
list << inst << cputype << fputype << mhz << state;
new QTreeWidgetItem(tree, list);
}
tree->sortItems(0, Qt::AscendingOrder);
return true;
}
bool GetInfo_IRQ(QTreeWidget*) {
return false;
}
bool GetInfo_DMA(QTreeWidget*) {
return false;
}
bool GetInfo_PCI(QTreeWidget*) {
return false;
}
bool GetInfo_IO_Ports(QTreeWidget*) {
return false;
}
bool GetInfo_Sound(QTreeWidget*) {
return false;
}
bool GetInfo_SCSI(QTreeWidget*) {
return false;
}
bool GetInfo_Partitions(QTreeWidget* tree) {
FILE *mnttab;
struct mnttab mnt;
struct statvfs statbuf;
fsblkcnt_t tmp;
QString total;
QString avail;
time_t mnttime;
char *timetxt;
char *ptr;
if ( (mnttab = fopen(MNTTAB, "r")) == NULL) {
return false;
}
/*
* set up column headers
*/
QStringList headers;
headers << i18n("Device") << i18n("Mount Point") << i18n("FS Type") << i18n("Total Size") << i18n("Free Size") << i18n("Mount Time") << i18n("Mount Options");
tree->setHeaderLabels(headers);
// XXX: FIXME: how do I set column alignment correctly?
//tree->setColumnAlignment( 3, 2 );
// XXX: FIXME: how do I set column alignment correctly?
//tree->setColumnAlignment( 4, 2 );
/*
* get info about mounted file systems
*/
rewind(mnttab);
while (getmntent(mnttab, &mnt) == 0) {
/*
* skip fstype "nfs" and "autofs" for two reasons:
* o if the mountpoint is visible, the fs is not
* necessarily available (autofs option "-nobrowse")
* and we don't want to mount every remote fs just
* to get its size, do we?
* o the name "Partitions" for this statistics implies
* "local file systems only"
*/
if ( (strcmp(mnt.mnt_fstype, "nfs") == 0) || (strcmp(mnt.mnt_fstype, "autofs") == 0))
continue;
if (statvfs(mnt.mnt_mountp, &statbuf) == 0) {
if (statbuf.f_blocks > 0) {
/*
* produce output in KB, MB, or GB for
* readability -- unfortunately, this
* breaks sorting for these columns...
*/
tmp = statbuf.f_blocks * (statbuf.f_frsize / 1024);
if (tmp > 9999) {
tmp /= 1024;
if (tmp > 9999) {
tmp /= 1024;
total.setNum(tmp);
total += " G";
} else {
total.setNum(tmp);
total += " M";
}
} else {
total.setNum(tmp);
total += " K";
}
// avail.setNum( statbuf.f_bavail );
// avail += " K";
tmp = statbuf.f_bavail * (statbuf.f_frsize / 1024);
if (tmp > 9999) {
tmp /= 1024;
if (tmp > 9999) {
tmp /= 1024;
avail.setNum(tmp);
avail += " G";
} else {
avail.setNum(tmp);
avail += " M";
}
} else {
avail.setNum(tmp);
avail += " K";
}
} else {
total = "-";
avail = "-";
}
} else {
total = "???";
avail = "???";
}
/*
* ctime() adds a '\n' which we have to remove
* so that we get a one-line output for the QTreeWidgetItem
*/
mnttime = (time_t) atol(mnt.mnt_time);
if ( (timetxt = ctime( &mnttime)) != NULL) {
ptr = strrchr(timetxt, '\n');
*ptr = '\0';
}
QStringList list;
list << mnt.mnt_special << mnt.mnt_mountp << mnt.mnt_fstype << total << avail << QString(timetxt) << mnt.mnt_mntopts;
new QTreeWidgetItem(tree, list);
}
fclose(mnttab);
tree->sortItems(0, Qt::AscendingOrder);
return true;
}
bool GetInfo_XServer_and_Video(QTreeWidget* tree) {
return GetInfo_XServer_Generic(tree);
}
#ifdef HAVE_LIBDEVINFO_H
/*
* get Solaris' device configuration data through libdevinfo(3)
* and display it in a prtconf(1M) style tree
*
* NOTE: though the devinfo library seems to be present on earlier
* Solaris releases, this interface is documented to be available
* since Solaris 7 (libdevinfo.h is missing on pre-Solaris 7 systems)
*
* documentation for libdevinfo(3) including code samples on which
* this implementation is based on is available at
* http://soldc.sun.com/developer/support/driver/wps/libdevinfo/
*/
/*
* we start with various helper routines for GetInfo_Devices()
*/
/*
* mktree() -- break up the device path and place its components
* into the tree widget
*/
QTreeWidgetItem* mktree( QTreeWidgetItem* top, const char* path ) {
QTreeWidgetItem* parent;
QTreeWidgetItem* previous;
QTreeWidgetItem* result;
char* str = strdup( path );
char* token;
/*
* start at "/"
*/
parent = top;
result = top->child(0);
previous = top->child(0);
token = strtok( str, "/" );
while( token != NULL ) {
/*
* find insert pos:
* try to match the node at the current level
*
* NOTE: this implementation assumes that there are
* no two nodes with identical names at the
* same level of the device tree
*/
QTreeWidgetItemIterator it(top, QTreeWidgetItemIterator::All);
while ( *it != NULL ) {
if( strcmp( token, (*it)->text( 0 ).toLatin1()) == 0 )
break;
previous = *it;
++it;
result = *it;
}
if( result == NULL ) {
QStringList list;
list << token;
/*
* we haven't found the node, create a new one
*/
result = new QTreeWidgetItem(parent, previous, list);
}
else {
/*
* we've found the node
*/
parent = result;
previous = NULL;
if( result->child(0) == NULL ) {
/*
* create new node during next iteration
*/
result->setExpanded(false);
} else {
/*
* follow the child path
*/
result = result->child(0);
}
}
token = strtok( NULL, "/" );
}
free( str );
return result;
}
/*
* prop_type_str() -- return the property type as a string
*/
char *prop_type_str( di_prop_t prop ) {
switch( di_prop_type( prop )) {
case DI_PROP_TYPE_UNDEF_IT:
return( "undefined" );
case DI_PROP_TYPE_BOOLEAN:
return( "BOOL" );
case DI_PROP_TYPE_INT:
return( "INT" );
case DI_PROP_TYPE_STRING:
return( "STRING" );
case DI_PROP_TYPE_BYTE:
return( "BYTE" );
default:
return( "unknown" );
}
}
/*
* prop_type_guess() -- guess the property type
*/
int prop_type_guess( uchar_t *data, int len ) {
int slen;
int guess;
int i, c;
if( len < 0 )
return( -1 );
else if( len == 0 )
return( DI_PROP_TYPE_BOOLEAN );
slen = 0;
guess = DI_PROP_TYPE_STRING;
for( i = 0; i < len; i++ ) {
c = (int) data[i];
switch( c ) {
case 0:
if( i == (len - 1 ))
break;
if( slen == 0 )
guess = DI_PROP_TYPE_BYTE;
else
guess = slen = 0;
break;
default:
if( ! isprint( c ))
guess = DI_PROP_TYPE_BYTE;
else
slen++;
}
if( guess != DI_PROP_TYPE_STRING )
break;
}
// if( (guess == DI_PROP_TYPE_BYTE) && (len % sizeof( int ) == 0 ))
// guess = DI_PROP_TYPE_INT;
return( guess );
}
/*
* dump_minor_node() -- examine a device minor node
* this routine gets passed to di_walk_node()
*/
int dump_minor_node( di_node_t node, di_minor_t minor, void *arg ) {
QString majmin;
char *type;
dev_t dev;
QStringList list;
list << di_minor_name( minor );
QTreeWidgetItem* item = new QTreeWidgetItem( (QTreeWidgetItem *) arg, list);
item->setExpanded(false);
QString specResult;
if (di_minor_spectype( minor ) == S_IFCHR)
specResult = i18n( "character special" );
else
specResult = i18n( "block special" );
QStringList spec;
spec << i18n( "Spectype:" ) << specResult;
new QTreeWidgetItem(item, spec);
type = di_minor_nodetype( minor );
QString nodeResult;
if (type == NULL)
nodeResult = "NULL";
else
nodeResult = type;
QStringList node;
node << i18n( "Nodetype:" ) << nodeResult;
new QTreeWidgetItem(item, node);
if( (dev = di_minor_devt( minor )) != DDI_DEV_T_NONE ) {
majmin.sprintf( "%ld/%ld", major( dev ), minor( dev ));
QStringList mn;
mn << i18n( "Major/Minor:" ) << majmin;
new QTreeWidgetItem(item, mn);
}
if( di_minor_next( node, minor ) == DI_MINOR_NIL )
return DI_WALK_TERMINATE;
else
return DI_WALK_CONTINUE;
}
/*
* propvalue() -- return the property value
*/
QString propvalue( di_prop_t prop ) {
int type;
int i, n;
char *strp;
int *intp;
uchar_t *bytep;
QString result;
/*
* Since a lot of printable strings seem to be tagged as 'byte',
* we're going to guess, if the property is not STRING or INT
* The actual type is shown in the info tree, though.
*/
type = di_prop_type( prop );
if( (type != DI_PROP_TYPE_STRING) && (type != DI_PROP_TYPE_INT) ) {
n = di_prop_bytes( prop, &bytep );
type = prop_type_guess( bytep, n );
}
result = "";
switch( type ) {
case DI_PROP_TYPE_STRING:
if( (n = di_prop_strings( prop, &strp )) < 0 ) {
result = "(error)";
} else {
for( i = 0; i < n; i++ ) {
result += "\"";
result += strp;
result += "\" ";
strp += strlen( strp ) + 1;
}
}
break;
case DI_PROP_TYPE_INT:
if( (n = di_prop_ints( prop, &intp )) < 0 ) {
result = "(error)";
} else {
for( i = 0; i < n; i++ ) {
QString tmp;
tmp.setNum( intp[i] );
result += tmp;
result += ' ';
}
}
break;
case DI_PROP_TYPE_BOOLEAN:
/*
* hmm, Sun's sample code handles the existence
* of a boolean property as "true", whereas
* prtconf(1M) obviously does not (Sol8, at least)
* -- we're doing the same and handle "bool" as "byte"
*/
case DI_PROP_TYPE_BYTE:
if( (n = di_prop_bytes( prop, &bytep )) < 0 ) {
result = "(error)";
} else {
if( n == 0 ) {
result = i18n( "(no value)" );
break;
}
result = "0x";
for( i = 0; i < n; i++ ) {
QString tmp;
unsigned byte = (unsigned) bytep[i];
tmp.sprintf( "%2.2x", byte );
result += tmp;
}
}
break;
default:
result = "???";
}
return( result );
}
/*
* dump_node() -- examine a device node and its children
* this routine gets passed to di_walk_node()
*/
int dump_node( di_node_t node, void *arg ) {
QTreeWidgetItem *top = (QTreeWidgetItem *) arg;
QTreeWidgetItem *parent;
char *path;
char *drivername;
char *names;
QString compatnames;
int i, n;
di_prop_t prop;
path = di_devfs_path( node );
/*
* if this is the root node ("/"), initialize the tree
*/
if( strlen( path ) == 1 ) {
top->setText( 0, QString( di_binding_name( node )));
top->setIcon( 0, SmallIcon( "kcmdevices" ));
top->setExpanded( true );
}
/*
* place the node in the tree
*/
parent = mktree( top, path );
/*
* we have to handle the root node differently...
*/
if( strlen( path ) > 1 ) {
parent->setExpanded(false);
} else {
parent = top;
}
/*
* node name and physical device path
*/
drivername = di_driver_name( node );
QStringList driverList;
driverList << i18n( "Driver Name:" );
if (drivername==NULL)
driverList << i18n( "(driver not attached)" );
else
driverList << drivername;
new QTreeWidgetItem(parent, driverList);
QStringList bindingList;
bindingList << i18n( "Binding Name:" ) << di_binding_name( node );
new QTreeWidgetItem(parent, bindingList);
n = di_compatible_names( node, &names );
if( n < 1 ) {
compatnames = i18n( "(none)" );
} else {
for( i = 0; i < n; i++ ) {
compatnames += names;
compatnames += ' ';
names += strlen( names ) + 1;
}
}
QStringList compatibleList;
compatibleList << i18n( "Compatible Names:" ) << compatnames;
new QTreeWidgetItem(parent, compatibleList);
QStringList physicalList;
physicalList << i18n( "Physical Path:" ) << QString( path );
new QTreeWidgetItem(parent, physicalList);
/*
* dump the node's property list (if any)
*/
if( (prop = di_prop_next( node, DI_PROP_NIL )) != DI_PROP_NIL ) {
QTreeWidgetItem *previous;
QStringList propertiesList;
propertiesList << i18n( "Properties" );
previous = new QTreeWidgetItem(parent, propertiesList);
previous->setExpanded( false );
do {
/*
* property type & value
*/
QStringList propList;
propList << di_prop_name( prop );
QTreeWidgetItem* tmp = new QTreeWidgetItem(previous, propList);
tmp->setExpanded( false );
QStringList typeList;
typeList << i18n( "Type:" ) << prop_type_str( prop );
new QTreeWidgetItem( tmp, typeList);
QStringList valueList;
valueList << i18n( "Value:" ) << propvalue( prop );
new QTreeWidgetItem( tmp, valueList);
}while( (prop = di_prop_next( node, prop )) != DI_PROP_NIL );
}
/*
* if there are minor nodes, expand the tree appropriately
*/
if( di_minor_next( node, DI_MINOR_NIL ) != DI_MINOR_NIL ) {
QStringList minorList;
minorList << i18n( "Minor Nodes" );
QTreeWidgetItem* previous = new QTreeWidgetItem(parent, minorList);
previous->setExpanded(false);
di_walk_minor( node, NULL, 0, previous, dump_minor_node );
}
return DI_WALK_CONTINUE;
}
bool GetInfo_Devices( QTreeWidget* tree ) {
di_node_t root_node;
/*
* create a snapshot of the device tree
*/
if( (root_node = di_init( "/", DINFOCPYALL )) == DI_NODE_NIL ) {
return( false );
}
// XXX: might try to di_prom_init() here as well (if we're setgid sys)
/*
* prepare the tree widget
*/
QStringList headers;
headers << i18n( "Device Information" ) << i18n( "Value" );
tree->setHeaderLabels(headers);
QTreeWidgetItem* top = new QTreeWidgetItem( tree );
/*
* traverse the device tree
*/
di_walk_node( root_node, DI_WALK_CLDFIRST, top, dump_node );
di_fini( root_node );
tree->setSortingEnabled(false);
return true;
}
#else /* ! HAVE_LIBDEVINFO_H */
bool GetInfo_Devices(QTreeWidget*) {
return false;
}
#endif /* ! HAVE_LIBDEVINFO_H */

View file

@ -0,0 +1,112 @@
/*
info_svr4.cpp
UNIX System V Release 4 specific Information about the Hardware.
Appropriate for SCO OpenServer and UnixWare.
Written 20-Feb-99 by Ronald Joe Record (rr@sco.com)
Initially based on info_sgi.cpp
*/
#define INFO_DEV_SNDSTAT "/dev/sndstat"
#include <sys/systeminfo.h>
/* all following functions should return true, when the Information
was filled into the lBox-Widget.
returning false indicates, that information was not available.
*/
bool GetInfo_ReadfromFile(QListView *lBox, char *Name, char splitchar) {
QString str;
char buf[512];
QFile *file = new QFile(Name);
QListViewItem* olditem = 0;
if (!file->open(QIODevice::ReadOnly)) {
delete file;
return false;
}
while (file->readLine(buf, sizeof(buf)-1) > 0) {
if (strlen(buf)) {
char *p=buf;
if (splitchar!=0) /* remove leading spaces between ':' and the following text */
while (*p) {
if (*p==splitchar) {
*p++ = ' ';
while (*p==' ')
++p;
*(--p) = splitchar;
++p;
} else
++p;
}
QString s1 = QString::fromLocal8Bit(buf);
QString s2 = s1.mid(s1.find(splitchar)+1);
s1.truncate(s1.find(splitchar));
if (!(s1.isEmpty() || s2.isEmpty()))
olditem = new QListViewItem(lBox, olditem, s1, s2);
}
}
file->close();
delete file;
return true;
}
bool GetInfo_CPU(QListView *lBox) {
char buf[256];
sysinfo(SI_ARCHITECTURE, buf, sizeof(buf));
new QListViewItem(lBox, QString::fromLocal8Bit(buf));
return true;
}
bool GetInfo_IRQ(QListView *) {
return false;
}
bool GetInfo_DMA(QListView *) {
return false;
}
bool GetInfo_PCI(QTreeWidget* tree) {
char buf[256];
sysinfo(SI_BUSTYPES, buf, sizeof(buf));
QStringList list;
list << QString::fromLocal8Bit(buf);
new QTreeWidgetItem(tree, list);
return true;
}
bool GetInfo_IO_Ports(QListView *) {
return false;
}
bool GetInfo_Sound(QListView *lBox) {
if (GetInfo_ReadfromFile(lBox, INFO_DEV_SNDSTAT, 0))
return true;
else
return false;
}
bool GetInfo_Devices(QListView *) {
return false;
}
bool GetInfo_SCSI(QListView *) {
return false;
}
bool GetInfo_Partitions(QListView *) {
return false;
}
bool GetInfo_XServer_and_Video(QListView *lBox) {
return GetInfo_XServer_Generic(lBox);
}

331
kinfocenter/base/os_base.h Normal file
View file

@ -0,0 +1,331 @@
#ifndef OS_BASE_H_
#define OS_BASE_H_
#include <QString>
#include <QStringList>
#include <QProcess>
#include <QTextStream>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <kiconloader.h>
#include <kglobal.h>
#include <klocale.h>
#include <X11/Xlib.h>
#include "config-infocenter.h"
static const QString Value(int val, int numbers=1) {
return KGlobal::locale()->formatNumber(val, 0).rightJustified(numbers);
}
static const QString HexStr(unsigned long val, int digits) {
QString hexstr;
int i;
hexstr = QString::fromLatin1("0x%1").arg(val, digits, 16/*=HEX*/);
for (i=hexstr.length()-1; i>0; --i)
if (hexstr[i]==' ')
hexstr[i] = '0';
return hexstr;
}
static const QString Order(int order) {
if (order==LSBFirst)
return i18n("LSBFirst");
else if (order==MSBFirst)
return i18n("MSBFirst");
else
return i18n("Unknown Order %1", order);
}
static const QString BitString(unsigned long n) {
return i18np("1 Bit", "%1 Bits", n); // singular & plural form of "%d Bit"
}
static const QString ByteString(unsigned long n) {
/* explanation in BR #52640 (http://bugs.kde.org/show_bug.cgi?id=52640) */
if (n == 1)
return i18nc("singular form: '1 Byte' (yes, it is '1', not '%1'!)", "1 Byte");
return i18nc("plural form: '%1 Bytes'", "%1 Bytes", KGlobal::locale()->formatNumber(n, 0));
}
static struct _event_table {
const char *name;
long value;
} event_table[] = { { "KeyPressMask", KeyPressMask }, { "KeyReleaseMask", KeyReleaseMask }, { "ButtonPressMask", ButtonPressMask }, { "ButtonReleaseMask", ButtonReleaseMask }, { "EnterWindowMask", EnterWindowMask }, { "LeaveWindowMask", LeaveWindowMask }, { "PointerMotionMask", PointerMotionMask },
{ "PointerMotionHintMask", PointerMotionHintMask }, { "Button1MotionMask", Button1MotionMask }, { "Button2MotionMask", Button2MotionMask }, { "Button3MotionMask", Button3MotionMask }, { "Button4MotionMask", Button4MotionMask }, { "Button5MotionMask", Button5MotionMask }, {
"ButtonMotionMask", ButtonMotionMask }, { "KeymapStateMask", KeymapStateMask }, { "ExposureMask", ExposureMask }, { "VisibilityChangeMask", VisibilityChangeMask }, { "StructureNotifyMask", StructureNotifyMask }, { "ResizeRedirectMask", ResizeRedirectMask }, {
"SubstructureNotifyMask", SubstructureNotifyMask }, { "SubstructureRedirectMask", SubstructureRedirectMask }, { "FocusChangeMask", FocusChangeMask }, { "PropertyChangeMask", PropertyChangeMask }, { "ColormapChangeMask", ColormapChangeMask }, { "OwnerGrabButtonMask",
OwnerGrabButtonMask }, { 0L, 0 } };
/* easier to read with such a define ! */
#define I18N_MAX(txt,in,fm,maxw) \
{ int n = fm.width(txt=in); if (n>maxw) maxw=n; }
#define PIXEL_ADD 20 // add x Pixel to multicolumns..
#define HEXDIGITS (sizeof(int)*8/4) /* 4 Bytes = 32 Bits = 8 Hex-Digits */
static QTreeWidgetItem* XServer_fill_screen_info(QTreeWidgetItem *lBox, QTreeWidgetItem *last, Display *dpy, int scr, int default_scr) {
unsigned width, height;
double xres, yres;
int i, ndepths, *depths;
Screen *s= ScreenOfDisplay(dpy,scr); /* opaque structure */
QTreeWidgetItem *item;
/*
* there are 2.54 centimeters to an inch; so there are 25.4 millimeters.
*
* dpi = N pixels / (M millimeters / (25.4 millimeters / 1 inch))
* = N pixels / (M inch / 25.4)
* = N * 25.4 pixels / M inch
*/
xres = ((double)(DisplayWidth(dpy,scr) *25.4)/DisplayWidthMM(dpy,scr) );
yres = ((double)(DisplayHeight(dpy,scr)*25.4)/DisplayHeightMM(dpy,scr));
QStringList screenList;
screenList << ki18n("Screen # %1").subs((int)scr,-1).toString();
if (scr==default_scr)
screenList << i18n("(Default Screen)");
else
screenList << QString();
item = new QTreeWidgetItem(lBox, screenList);
if (scr==default_scr)
item->setExpanded(true);
QStringList dimensionList;
dimensionList << i18n("Dimensions") << i18n("%1 x %2 Pixel (%3 x %4 mm)", (int)DisplayWidth(dpy,scr) , (int)DisplayHeight(dpy,scr) , (int)DisplayWidthMM(dpy,scr) , (int)DisplayHeightMM (dpy,scr) );
last = new QTreeWidgetItem(item, dimensionList);
QStringList resolutionList;
resolutionList << i18n("Resolution") << i18n("%1 x %2 dpi", (int)(xres+0.5) , (int)(yres+0.5) );
last = new QTreeWidgetItem(item, resolutionList);
ndepths = 0;
depths = 0;
depths = XListDepths(dpy, scr, &ndepths);
if (depths) {
QString txt;
for (i = 0; i < ndepths; i++) {
txt = txt + Value(depths[i]);
if (i < ndepths - 1)
txt = txt + QLatin1String(", ");
}
QStringList depthList;
depthList << ki18n("Depths (%1)").subs(ndepths,-1).toString() << txt;
last = new QTreeWidgetItem(item, depthList);
XFree((char *) depths);
}
QStringList rootList;
rootList << i18n("Root Window ID") << HexStr((unsigned long)RootWindow(dpy,scr), HEXDIGITS);
last = new QTreeWidgetItem(item, rootList);
QStringList depthRootList;
depthRootList << i18n("Depth of Root Window") << i18np("%1 plane", "%1 planes", DisplayPlanes(dpy,scr));
last = new QTreeWidgetItem(item, depthRootList);
QStringList colormapList;
colormapList << i18n("Number of Colormaps") << i18n("minimum %1, maximum %2", (int)MinCmapsOfScreen(s), (int)MaxCmapsOfScreen(s));
last = new QTreeWidgetItem(item, colormapList);
QStringList defaultColormap;
defaultColormap << i18n("Default Colormap"), Value((int)DefaultColormap(dpy,scr));
last = new QTreeWidgetItem(item, defaultColormap);
QStringList colormapCellList;
colormapCellList << i18n("Default Number of Colormap Cells") << Value((int)DisplayCells(dpy, scr));
last = new QTreeWidgetItem(item, colormapCellList);
QStringList preallocatedList;
preallocatedList << i18n("Preallocated Pixels") << i18n("Black %1, White %2", KGlobal::locale()->formatNumber(BlackPixel(dpy,scr), 0), KGlobal::locale()->formatNumber(WhitePixel(dpy,scr), 0));
last = new QTreeWidgetItem(item, preallocatedList);
QString YES(i18n("Yes"));
QString NO(i18n("No"));
QStringList optionList;
optionList << i18n("Options") << i18n("backing-store: %1, save-unders: %2", (DoesBackingStore(s) == NotUseful) ? NO : ((DoesBackingStore(s) == Always) ? YES : i18n("When mapped")),
DoesSaveUnders(s) ? YES : NO);
last = new QTreeWidgetItem(item, optionList);
XQueryBestSize(dpy, CursorShape, RootWindow(dpy,scr), 65535, 65535, &width, &height);
QStringList largestList;
largestList << i18n("Largest Cursor");
if (width == 65535 && height == 65535)
largestList << i18n("unlimited");
else
largestList << QString::fromLatin1("%1 x %2").arg(width).arg(height);
last = new QTreeWidgetItem(item, largestList);
QStringList currentInput;
currentInput << i18n("Current Input Event Mask") << HexStr((unsigned long)EventMaskOfScreen(s), HEXDIGITS);
last = new QTreeWidgetItem(item, currentInput);
struct _event_table *etp;
for (etp=event_table; etp->name; etp++) {
if (EventMaskOfScreen(s) & etp->value) {
QStringList eventList;
eventList << i18n("Event = %1", HexStr(etp->value, HEXDIGITS)) << etp->name;
new QTreeWidgetItem(last, eventList);
}
}
if (last->childCount()==0)
return last;
else
return last->child(last->childCount()-1);
}
static bool GetInfo_XServer_Generic(QTreeWidget *lBox) {
/* Many parts of this source are taken from the X11-program "xdpyinfo" */
int i, n;
long req_size;
Display *dpy;
XPixmapFormatValues *pmf;
QString str, txt;
QTreeWidgetItem *last, *item, *next;
dpy = XOpenDisplay(0);
if (!dpy)
return false;
QStringList headers;
headers << i18n("Information") << i18n("Value");
lBox->setHeaderLabels(headers);
lBox->setSortingEnabled(false);
QStringList serverInfo;
serverInfo << i18n("Server Information");
next = new QTreeWidgetItem(lBox, serverInfo);
next->setIcon(0, SmallIcon("xorg"));
next->setExpanded(true);
QStringList displayNameList;
displayNameList << i18n("Name of the Display") << DisplayString(dpy);
last = new QTreeWidgetItem(next, displayNameList);
QStringList vendorList;
vendorList << i18n("Vendor String") << QLatin1String(ServerVendor(dpy));
last = new QTreeWidgetItem(next, vendorList);
QStringList vendorReleaseList;
vendorReleaseList << i18n("Vendor Release Number") << Value((int)VendorRelease(dpy));
last = new QTreeWidgetItem(next, vendorReleaseList);
QStringList versionList;
versionList << i18n("Version Number") << QString::fromLatin1("%1.%2").arg((int)ProtocolVersion(dpy)).arg((int)ProtocolRevision(dpy));
last = new QTreeWidgetItem(next, versionList);
QStringList screenList;
screenList << i18n("Available Screens");
last = item = new QTreeWidgetItem(next, screenList);
last->setExpanded(true);
for (i=0; i<ScreenCount(dpy); i++) {
item = XServer_fill_screen_info(last, item, dpy, i, (int)DefaultScreen(dpy));
if (i==0)
item->setExpanded(true);
}
QStringList extensionList;
extensionList << i18n("Supported Extensions");
last = new QTreeWidgetItem(next, extensionList );
item = last;
int extCount;
char **extensions = XListExtensions(dpy, &extCount);
for (i = 0; i < extCount; i++) {
QStringList extensionInfoList;
extensionInfoList << QLatin1String(extensions[i]);
item = new QTreeWidgetItem( last, extensionInfoList );
}
XFreeExtensionList(extensions);
pmf = XListPixmapFormats(dpy, &n);
QStringList pixmapFormatList;
pixmapFormatList << i18n("Supported Pixmap Formats");
last = item = new QTreeWidgetItem(next, pixmapFormatList);
if (pmf) {
for (i=0; i<n; i++) {
QStringList pixmapList;
pixmapList << i18n("Pixmap Format #%1", i+1) << i18n("%1 BPP, Depth: %2, Scanline padding: %3", pmf[i].bits_per_pixel, BitString(pmf[i].depth), BitString(pmf[i].scanline_pad));
item = new QTreeWidgetItem(last, pixmapList);
}
XFree((char *)pmf);
}
req_size = XExtendedMaxRequestSize(dpy);
if (!req_size)
req_size = XMaxRequestSize(dpy);
QStringList requestSizeList;
requestSizeList << i18n("Maximum Request Size") << ByteString(req_size*4);
last = new QTreeWidgetItem(next, requestSizeList);
QStringList motionList;
motionList << i18n("Motion Buffer Size") << ByteString(XDisplayMotionBufferSize(dpy));
last = new QTreeWidgetItem(next, motionList);
QStringList bitmapList;
bitmapList << i18n("Bitmap");
last = item = new QTreeWidgetItem(next, bitmapList);
QStringList unitList;
unitList << i18n("Unit") << Value(BitmapUnit(dpy));
item = new QTreeWidgetItem(last, unitList);
QStringList orderList;
orderList << i18n("Order") << Order(BitmapBitOrder(dpy));
item = new QTreeWidgetItem(last, orderList);
QStringList paddingList;
paddingList << i18n("Padding") << Value(BitmapPad(dpy));
item = new QTreeWidgetItem(last, paddingList);
QStringList imageByteList;
imageByteList << i18n("Image Byte Order") << Order(ImageByteOrder(dpy));
last = new QTreeWidgetItem(next, imageByteList);
XCloseDisplay(dpy);
return true;
}
/* Helper-function to read output from an external program */
static int GetInfo_ReadfromPipe(QTreeWidget* tree, const char *FileName, bool WithEmptyLines = true) {
QProcess proc;
QTreeWidgetItem* olditem= NULL;
QString s;
proc.start(FileName, QIODevice::ReadOnly);
if (!proc.waitForFinished()) {
// Process hanged or did not start
return 0;
}
QTextStream t(&proc);
while (!t.atEnd()) {
s = t.readLine();
if (!WithEmptyLines && s.length()==0)
continue;
QStringList list;
list << s;
olditem = new QTreeWidgetItem(tree, list);
}
return tree->topLevelItemCount();
}
#endif /*OS_BASE_H_*/

View file

@ -0,0 +1,28 @@
#include "os_current.h"
#include "os_base.h"
#ifdef __linux__
#include "info_linux.cpp"
#elif defined(sgi) && sgi
#include "info_sgi.cpp"
#elif defined(__FreeBSD__) || defined(__DragonFly__)
#include "info_fbsd.cpp"
#elif __hpux
#include "info_hpux.cpp"
#elif __NetBSD__
#include "info_netbsd.cpp"
#elif __OpenBSD__
#include "info_openbsd.cpp"
#elif defined(__svr4__) && defined(sun)
#include "info_solaris.cpp"
#elif __svr4__
#include "info_svr4.cpp"
#elif _AIX
#include "info_aix.cpp"
#elif defined(__APPLE__)
#include "info_osx.cpp"
#else
#include "info_generic.cpp" /* Default for unsupported systems.... */
#endif

View file

@ -0,0 +1,185 @@
#ifndef OS_CURRENT_H_
#define OS_CURRENT_H_
class QTreeWidget;
class QTreeWidgetItem;
class QString;
/* function call-back-prototypes... */
bool GetInfo_CPU(QTreeWidget* tree);
bool GetInfo_IRQ(QTreeWidget* tree);
bool GetInfo_DMA(QTreeWidget* tree);
bool GetInfo_PCI(QTreeWidget* tree);
bool GetInfo_IO_Ports(QTreeWidget* tree);
bool GetInfo_Sound(QTreeWidget* tree);
bool GetInfo_Devices(QTreeWidget* tree);
bool GetInfo_SCSI(QTreeWidget* tree);
bool GetInfo_Partitions(QTreeWidget* tree);
bool GetInfo_XServer_and_Video(QTreeWidget* tree);
#ifdef __linux__
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
/* i18n("Maybe the proc-filesystem is not enabled in Linux-Kernel.") */
#define DEFAULT_ERRORSTRING QString()
#elif defined(sgi) && sgi
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
#define DEFAULT_ERRORSTRING i18n("This system may not be completely supported yet.")
#elif defined(__FreeBSD__) || defined(__DragonFly__)
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
#define DEFAULT_ERRORSTRING i18n("This system may not be completely supported yet.")
#elif __hpux
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
#define DEFAULT_ERRORSTRING QString()
#elif __NetBSD__
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
#define DEFAULT_ERRORSTRING i18n("This system may not be completely supported yet.")
#elif __OpenBSD__
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
#define DEFAULT_ERRORSTRING i18n("This system may not be completely supported yet.")
#elif defined(__svr4__) && defined(sun)
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
#define DEFAULT_ERRORSTRING i18n("This system may not be completely supported yet.")
#elif __svr4__
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
#define DEFAULT_ERRORSTRING i18n("This system may not be completely supported yet.")
#elif _AIX
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_XSERVER_AVAILABLE
#define DEFAULT_ERRORSTRING i18n("This system may not be completely supported yet.")
#elif defined(__APPLE__)
#define INFO_CPU_AVAILABLE
//#define INFO_IRQ_AVAILABLE
//#define INFO_DMA_AVAILABLE
//#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
#define DEFAULT_ERRORSTRING i18n("This system may not be completely supported yet.")
#else
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
#define DEFAULT_ERRORSTRING i18n("This system may not be completely supported yet.")
#endif
#endif /*OS_CURRENT_H_*/

View file

@ -1,25 +1,22 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 2000 Matthias Elter <elter@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "dockcontainer.h"
#include "global.h"
#include "modules.h"
#include "proxywidget.h"
#include <kapplication.h>
#include <kmessagebox.h>
@ -34,224 +31,158 @@
#include <QFont>
#include <QApplication>
#include "global.h"
#include "modules.h"
#include "proxywidget.h"
#include "aboutwidget.h"
#include "dockcontainer.moc"
class ModuleTitle : public KHBox
{
public:
ModuleTitle( QWidget *parent );
~ModuleTitle() {}
ModuleTitle::ModuleTitle(QWidget *parent) :
KTitleWidget(parent) {
void showTitleFor( ConfigModule *module );
void clear();
protected:
QLabel *m_icon;
QLabel *m_name;
};
ModuleTitle::ModuleTitle( QWidget *parent )
: KHBox( parent )
{
QWidget *spacer = new QWidget( this );
spacer->setFixedWidth( KDialog::marginHint()-KDialog::spacingHint() );
m_icon = new QLabel( this );
m_name = new QLabel( this );
QFont font = m_name->font();
font.setPointSize( font.pointSize()+1 );
font.setBold( true );
m_name->setFont( font );
setSpacing( KDialog::spacingHint() );
if ( QApplication::isRightToLeft() )
{
spacer = new QWidget( this );
setStretchFactor( spacer, 10 );
}
else
setStretchFactor( m_name, 10 );
}
void ModuleTitle::showTitleFor( ConfigModule *config )
{
if ( !config )
return;
ModuleTitle::~ModuleTitle() {
this->setWhatsThis( config->comment() );
KIconLoader *loader = KIconLoader::global();
QPixmap icon = loader->loadIcon( config->icon(), KIconLoader::NoGroup, 22 );
m_icon->setPixmap( icon );
m_name->setText( config->moduleName() );
show();
}
void ModuleTitle::clear()
{
m_icon->setPixmap( QPixmap() );
m_name->setText( QString() );
kapp->processEvents();
void ModuleTitle::showTitleFor(ConfigModule* config) {
kDebug() << "Show title for" << endl;
if ( !config)
return;
setWhatsThis(config->comment() );
setCommentText(config->docPath(), config->comment(), config->module()->quickHelp());
setPixmap(config->realIcon(KIconLoader::SizeLarge));
setText(config->moduleName());
kDebug() << "Show title for done" << endl;
}
class ModuleWidget : public QWidget
{
public:
ModuleWidget( QWidget *parent, const char *name );
~ModuleWidget() {}
ProxyWidget* load( ConfigModule *module );
protected:
QVBoxLayout *m_layout;
ModuleTitle *m_title;
};
ModuleWidget::ModuleWidget( QWidget *parent, const char * )
: QWidget( parent )
, m_layout (new QVBoxLayout (this))
, m_title (new ModuleTitle (this))
{
m_layout->addWidget (m_title);
void ModuleTitle::setCommentText(const QString& docPath, const QString& text, const QString& quickHelp) {
if (text.isEmpty() && docPath.isEmpty())
setCommentBaseText();
else if (docPath.isEmpty())
setComment(text);
else {
setComment(quickHelp + i18n("<p>Click here to consult the full <a href=\"%1\">Manual</a>.</p>", "help:/" + docPath));
}
}
ProxyWidget *ModuleWidget::load( ConfigModule *module )
{
m_title->clear();
ProxyWidget *proxy = module->module();
if ( proxy )
{
proxy->setParent(this);
m_layout->addWidget (proxy);
proxy->show();
proxy->setSizePolicy (QSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding));
m_title->showTitleFor( module );
}
return proxy;
void ModuleTitle::setCommentBaseText() {
setComment(i18n("<h1>KDE Info Center</h1>"
"There is no quick help available for the active info module."
"<br /><br />"
"Click <a href = \"kinfocenter/index.html\">here</a> to read the general Info Center manual.") );
}
DockContainer::DockContainer(QWidget *parent)
: QStackedWidget(parent)
, _basew(0L)
, _module(0L)
{
_busyw = new QLabel(i18n("<big><b>Loading...</b></big>"), this);
_busyw->setAlignment(Qt::AlignCenter);
_busyw->setTextFormat(Qt::RichText);
_busyw->setGeometry(0,0, width(), height());
addWidget( _busyw );
DockContainer::DockContainer(AboutWidget* aboutWidget, QWidget *parent) :
QWidget(parent) {
_modulew = new ModuleWidget( this, "_modulew" );
addWidget( _modulew );
QVBoxLayout* mainLayout = new QVBoxLayout(this);
_moduleTitle = new ModuleTitle(this);
mainLayout->addWidget(_moduleTitle);
_moduleWidgets = new QStackedWidget(this);
mainLayout->addWidget(_moduleWidgets);
_busyWidget = new QLabel(i18n("<big><b>Loading...</b></big>"), this);
_busyWidget->setAlignment(Qt::AlignCenter);
_busyWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
_moduleWidgets->addWidget(_busyWidget);
_generalWidget = aboutWidget;
_moduleWidgets->addWidget(_generalWidget);
showAboutWidget();
}
DockContainer::~DockContainer()
{
deleteModule();
DockContainer::~DockContainer() {
}
void DockContainer::setBaseWidget(QWidget *widget)
{
removeWidget( _basew );
delete _basew;
_basew = 0;
if (!widget) return;
_basew = widget;
ProxyWidget* DockContainer::initializeModule(ConfigModule * module) {
showBusyWidget();
addWidget( _basew );
setCurrentWidget( _basew );
QApplication::setOverrideCursor(Qt::WaitCursor);
emit newModule(widget->windowTitle(), "", "");
ProxyWidget* proxy = module->module();
if (proxy!=NULL) {
//If this module was not in the stack, add it.
if ( _moduleWidgets->indexOf(proxy) == -1) {
_moduleWidgets->addWidget(proxy);
}
}
QApplication::restoreOverrideCursor();
return proxy;
}
ProxyWidget* DockContainer::loadModule( ConfigModule *module )
{
QApplication::setOverrideCursor( Qt::WaitCursor );
bool DockContainer::dockModule(ConfigModule *module) {
ProxyWidget *widget = _modulew->load( module );
ProxyWidget* widget = initializeModule(module);
if (widget)
{
_module = module;
connect(_module, SIGNAL(childClosed()), SLOT(removeModule()));
connect(_module, SIGNAL(changed(ConfigModule *)),
SIGNAL(changedModule(ConfigModule *)));
connect(widget, SIGNAL(quickHelpChanged()), SLOT(quickHelpChanged()));
if (widget==NULL) {
kDebug() << "Failed to display module" << module->moduleName() << endl;
showAboutWidget();
setCurrentWidget( _modulew );
emit newModule(widget->windowTitle(), module->docPath(), widget->quickHelp());
}
else
{
setCurrentWidget( _basew );
emit newModule(_basew->windowTitle(), "", "");
}
return false;
QApplication::restoreOverrideCursor();
}
return widget;
if (widget == _moduleWidgets->currentWidget()) {
kDebug() << "Module already displayed" << endl;
return true;
}
if (widget->isChanged()) {
int res = KMessageBox::warningYesNoCancel(this, module ? i18n("There are unsaved changes in the active module.\n"
"Do you want to apply the changes before running "
"the new module or discard the changes?") : i18n("There are unsaved changes in the active module.\n"
"Do you want to apply the changes before exiting "
"the Control Center or discard the changes?"), i18n("Unsaved Changes"), KStandardGuiItem::apply(), KStandardGuiItem::discard());
if (res == KMessageBox::Cancel)
return false;
}
kDebug() << "Docking module..." << endl;
showConfigWidget(module);
return true;
}
bool DockContainer::dockModule(ConfigModule *module)
{
if (module == _module) return true;
void DockContainer::showAboutWidget() {
kDebug() << "Show About Widget" << endl;
_moduleWidgets->setCurrentWidget(_generalWidget);
if (_module && _module->isChanged())
{
_moduleTitle->hide();
int res = KMessageBox::warningYesNoCancel(this,
module ?
i18n("There are unsaved changes in the active module.\n"
"Do you want to apply the changes before running "
"the new module or discard the changes?") :
i18n("There are unsaved changes in the active module.\n"
"Do you want to apply the changes before exiting "
"the Control Center or discard the changes?"),
i18n("Unsaved Changes"),
KStandardGuiItem::apply(),
KStandardGuiItem::discard());
if (res == KMessageBox::Yes)
_module->module()->applyClicked();
if (res == KMessageBox::Cancel)
return false;
}
setCurrentWidget( _busyw );
kapp->processEvents();
deleteModule();
if (!module) return true;
ProxyWidget *widget = loadModule( module );
KCGlobal::repairAccels( window() );
return ( widget!=0 );
}
void DockContainer::removeModule()
{
setCurrentWidget( _basew );
deleteModule();
void DockContainer::showBusyWidget() {
kDebug() << "Show Busy Widget" << endl;
_moduleWidgets->setCurrentWidget(_busyWidget);
_moduleTitle->hide();
kapp->processEvents();
if (_basew)
emit newModule(_basew->windowTitle(), "", "");
else
emit newModule("", "", "");
}
void DockContainer::deleteModule()
{
if(_module) {
_module->deleteClient();
_module = 0;
}
}
void DockContainer::showConfigWidget(ConfigModule* module) {
kDebug() << "Show Config Widget" << endl;
void DockContainer::quickHelpChanged()
{
if (_module && _module->module())
emit newModule(_module->module()->windowTitle(), _module->docPath(), _module->module()->quickHelp());
_moduleTitle->showTitleFor(module);
_moduleTitle->show();
_moduleWidgets->setCurrentWidget(module->module());
}

View file

@ -1,67 +1,76 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 2000 Matthias Elter <elter@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
*/
#ifndef __dockcontainer_h__
#define __dockcontainer_h__
#include <QStackedWidget>
#include <QLabel>
#include <kvbox.h>
#include <QVBoxLayout>
#include <kvbox.h>
#include <ktitlewidget.h>
class AboutWidget;
class ConfigModule;
class ModuleWidget;
class ProxyWidget;
class DockContainer : public QStackedWidget
{
Q_OBJECT
class ModuleTitle : public KTitleWidget {
public:
DockContainer(QWidget *parent=0);
virtual ~DockContainer();
ModuleTitle(QWidget *parent);
~ModuleTitle();
void setBaseWidget(QWidget *widget);
QWidget *baseWidget() { return _basew; }
bool dockModule(ConfigModule *module);
ConfigModule *module() { return _module; }
public Q_SLOTS:
void removeModule();
protected Q_SLOTS:
void quickHelpChanged();
protected:
void deleteModule();
ProxyWidget* loadModule( ConfigModule *module );
Q_SIGNALS:
void newModule(const QString &name, const QString& docPath, const QString &quickhelp);
void changedModule(ConfigModule *module);
void showTitleFor(ConfigModule *module);
private:
QWidget *_basew;
QLabel *_busyw;
ModuleWidget *_modulew;
ConfigModule *_module;
void setCommentText(const QString& docPath, const QString& text, const QString& quickHelp);
void setCommentBaseText();
};
class DockContainer : public QWidget {
Q_OBJECT
public:
DockContainer(AboutWidget* aboutWidget, QWidget *parent=NULL);
virtual ~DockContainer();
bool dockModule(ConfigModule *module);
public slots:
void showAboutWidget();
signals:
void newModule(const QString& name);
private:
void showBusyWidget();
void showConfigWidget(ConfigModule* module);
ProxyWidget* initializeModule(ConfigModule* module);
QLabel *_busyWidget;
ModuleTitle* _moduleTitle;
QStackedWidget* _moduleWidgets;
AboutWidget* _generalWidget;
};
#endif

View file

@ -1,21 +1,21 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 2000 Matthias Elter <elter@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
*/
#include "global.h"
@ -25,7 +25,6 @@
#include <kuser.h>
#include <QObject>
#include <Qt3Support/Q3Accel>
#include <QByteArray>
#include <QWidget>
@ -35,7 +34,6 @@
#include <sys/utsname.h>
bool KCGlobal::_root = false;
bool KCGlobal::_infocenter = false;
QStringList KCGlobal::_types;
QString KCGlobal::_uname = "";
QString KCGlobal::_hname = "";
@ -44,76 +42,48 @@ QString KCGlobal::_isystem = "";
QString KCGlobal::_irelease = "";
QString KCGlobal::_iversion = "";
QString KCGlobal::_imachine = "";
IndexViewMode KCGlobal::_viewmode = Icon;
KIconLoader::StdSizes KCGlobal::_iconsize = KIconLoader::SizeMedium;
QString KCGlobal::_baseGroup = "";
void KCGlobal::init()
{
char buf[256];
buf[0] = '\0';
if (!gethostname(buf, sizeof(buf)))
buf[sizeof(buf)-1] ='\0';
QString hostname(buf);
void KCGlobal::init() {
char buf[256];
buf[0] = '\0';
if (!gethostname(buf, sizeof(buf)))
buf[sizeof(buf)-1] ='\0';
QString hostname(buf);
setHostName(hostname);
setUserName(KUser().loginName());
setRoot(getuid() == 0);
setHostName(hostname);
setUserName(KUser().loginName());
setRoot(getuid() == 0);
setKDEVersion(KDE::versionString());
setKDEVersion(KDE::versionString());
struct utsname info;
uname(&info);
struct utsname info;
uname(&info);
setSystemName(info.sysname);
setSystemRelease(info.release);
setSystemVersion(info.version);
setSystemMachine(info.machine);
setSystemName(info.sysname);
setSystemRelease(info.release);
setSystemVersion(info.version);
setSystemMachine(info.machine);
}
void KCGlobal::setType(const QByteArray& s)
{
QString string = s.toLower();
_types = string.split( ',');
void KCGlobal::setType(const QByteArray& s) {
QString string = s.toLower();
_types = string.split( ',');
}
QString KCGlobal::baseGroup()
{
if ( _baseGroup.isEmpty() )
{
KServiceGroup::Ptr group = KServiceGroup::baseGroup( _infocenter ? "info" : "settings" );
if (group)
{
_baseGroup = group->relPath();
kDebug(1208) << "Found basegroup = " << _baseGroup;
return _baseGroup;
}
// Compatibility with old behaviour, in case of missing .directory files.
if (_baseGroup.isEmpty())
{
if (_infocenter)
{
kWarning() << "No K menu group with X-KDE-BaseGroup=info found ! Defaulting to Settings/Information/" ;
_baseGroup = QLatin1String("Settings/Information/");
}
else
{
kWarning() << "No K menu group with X-KDE-BaseGroup=settings found ! Defaulting to Settings/" ;
_baseGroup = QLatin1String("Settings/");
}
}
}
return _baseGroup;
}
void KCGlobal::repairAccels( QWidget * tw )
{
const QList<QObject*> &l = tw->children();
for (QList<QObject*>::const_iterator it( l.begin() ); it != l.end(); ++it)
{
QObject *obj = *it;
if (qobject_cast<Q3Accel*>(obj))
qobject_cast<Q3Accel*>(obj)->repairEventFilter();
}
QString KCGlobal::baseGroup() {
if (_baseGroup.isEmpty() ) {
KServiceGroup::Ptr group = KServiceGroup::baseGroup("info");
if (group) {
_baseGroup = group->relPath();
kDebug() << "Found basegroup = " << _baseGroup;
return _baseGroup;
}
// Compatibility with old behaviour, in case of missing .directory files.
if (_baseGroup.isEmpty()) {
kWarning() << "No K menu group with X-KDE-BaseGroup=info found ! Defaulting to Settings/Information/";
_baseGroup = QLatin1String("Settings/Information/");
}
}
return _baseGroup;
}

View file

@ -1,74 +1,95 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 2000 Matthias Elter <elter@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
*/
#ifndef __global_h__
#define __global_h__
#ifndef _GLOBAL_H_
#define _GLOBAL_H_
#include <kicontheme.h>
#define KINFOCENTER_ICON_NAME "hwinfo"
#include <QString>
#include <QStringList>
enum IndexViewMode {Icon, Tree};
class KCGlobal
{
class KCGlobal {
public:
static void init();
static void init();
static bool isInfoCenter() { return _infocenter; }
static bool root() { return _root; }
static QStringList types() { return _types; }
static QString userName() { return _uname; }
static QString hostName() { return _hname; }
static QString kdeVersion() { return _kdeversion; }
static QString systemName() { return _isystem; }
static QString systemRelease() { return _irelease; }
static QString systemVersion() { return _iversion; }
static QString systemMachine() { return _imachine; }
static IndexViewMode viewMode() { return _viewmode; }
static KIconLoader::StdSizes iconSize() { return _iconsize; }
static QString baseGroup();
static bool root() {
return _root;
}
static QStringList types() {
return _types;
}
static QString userName() {
return _uname;
}
static QString hostName() {
return _hname;
}
static QString kdeVersion() {
return _kdeversion;
}
static QString systemName() {
return _isystem;
}
static QString systemRelease() {
return _irelease;
}
static QString systemVersion() {
return _iversion;
}
static QString systemMachine() {
return _imachine;
}
static QString baseGroup();
static void setIsInfoCenter(bool b) { _infocenter = b; }
static void setRoot(bool r) { _root = r; }
static void setType(const QByteArray& s);
static void setUserName(const QString& n){ _uname = n; }
static void setHostName(const QString& n){ _hname = n; }
static void setKDEVersion(const QString& n){ _kdeversion = n; }
static void setSystemName(const QString& n){ _isystem = n; }
static void setSystemRelease(const QString& n){ _irelease = n; }
static void setSystemVersion(const QString& n){ _iversion = n; }
static void setSystemMachine(const QString& n){ _imachine = n; }
static void setViewMode(IndexViewMode m) { _viewmode = m; }
static void setIconSize(KIconLoader::StdSizes s) { _iconsize = s; }
static void repairAccels( QWidget * tw );
static void setRoot(bool r) {
_root = r;
}
static void setType(const QByteArray& s);
static void setUserName(const QString& n) {
_uname = n;
}
static void setHostName(const QString& n) {
_hname = n;
}
static void setKDEVersion(const QString& n) {
_kdeversion = n;
}
static void setSystemName(const QString& n) {
_isystem = n;
}
static void setSystemRelease(const QString& n) {
_irelease = n;
}
static void setSystemVersion(const QString& n) {
_iversion = n;
}
static void setSystemMachine(const QString& n) {
_imachine = n;
}
private:
static bool _root;
static bool _infocenter;
static QStringList _types;
static QString _uname, _hname, _isystem, _irelease, _iversion, _imachine, _kdeversion;
static IndexViewMode _viewmode;
static KIconLoader::StdSizes _iconsize;
static QString _baseGroup;
static bool _root;
static QStringList _types;
static QString _uname, _hname, _isystem, _irelease, _iversion, _imachine, _kdeversion;
static QString _baseGroup;
};
#endif

View file

@ -1,89 +0,0 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "helpwidget.h"
#include "global.h"
#include "quickhelp.h"
#include <klocale.h>
#include <kdebug.h>
#include <kprocess.h>
#include <kapplication.h>
#include <krun.h>
#include <ktoolinvocation.h>
#include <QVBoxLayout>
#include "helpwidget.moc"
HelpWidget::HelpWidget(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *l = new QVBoxLayout(this);
_browser = new QuickHelp(this);
connect(_browser, SIGNAL(urlClick(const QString &)),
SLOT(urlClicked(const QString &)));
connect(_browser, SIGNAL(mailClick(const QString &,const QString &)),
SLOT(mailClicked(const QString &,const QString &)));
l->addWidget(_browser);
setBaseText();
}
void HelpWidget::setText( const QString& docPath, const QString& text)
{
docpath = docPath;
if (text.isEmpty() && docPath.isEmpty())
setBaseText();
else if (docPath.isEmpty())
_browser->setText(text);
else
{
QByteArray a = docPath.toLocal8Bit();
QString path = QString::fromLocal8Bit (a.data(), a.size());
_browser->setText(text + i18n("<p>Use the \"Whats This\" (Shift+F1) to get help on specific options.</p><p>To read the full manual click <a href=\"%1\">here</a>.</p>",
path));
}
}
void HelpWidget::setBaseText()
{
_browser->setText(i18n("<h1>KDE Info Center</h1>"
"There is no quick help available for the active info module."
"<br /><br />"
"Click <a href = \"kinfocenter/index.html\">here</a> to read the general Info Center manual.") );
}
void HelpWidget::urlClicked(const QString & _url)
{
KUrl url(KUrl("help:/"), _url);
if (url.protocol() == "help" || url.protocol() == "man" || url.protocol() == "info") {
KProcess::startDetached("khelpcenter", QStringList() << url.url());
} else {
new KRun(url, this);
}
}
void HelpWidget::mailClicked(const QString &,const QString & addr)
{
KToolInvocation::invokeMailer(addr, QString());
}

View file

@ -1,46 +0,0 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __helpwidget_h__
#define __helpwidget_h__
#include <QWidget>
class QuickHelp;
class HelpWidget : public QWidget
{
Q_OBJECT
public:
HelpWidget(QWidget *parent);
void setText( const QString& docPath, const QString& text);
void setBaseText();
protected Q_SLOTS:
void urlClicked(const QString &);
void mailClicked(const QString &,const QString &);
private:
QuickHelp *_browser;
QString docpath;
};
#endif

View file

@ -1,137 +1,102 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 2003 Frauke Oster <frauke.oster@t-online.de>
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 2003 Frauke Oster <frauke.oster@t-online.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "indexwidget.h"
#include "moduletreeview.h"
#include "moduleiconview.h"
#include <Qt3Support/Q3CheckListItem>
#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include "moduletreeview.h"
#include <kdebug.h>
#include <klocale.h>
#include "indexwidget.moc"
IndexWidget::IndexWidget(ConfigModuleList *modules, QWidget *parent ,const char *)
: QStackedWidget(parent)
, _tree(0L)
, _icon(0L)
, _modules(modules)
, viewMode(Icon)
{
activateView(Icon);
IndexWidget::IndexWidget(ConfigModuleList *modules, QWidget *parent) :
QWidget(parent) {
QVBoxLayout* mainLayout = new QVBoxLayout();
setLayout(mainLayout);
_tree=new ModuleTreeView(modules, this);
QHBoxLayout* searchLayout = new QHBoxLayout();
searchLayout->setMargin(0);
QLabel* searchLabel = new QLabel(i18n("Filter:"), this);
_searchLine = new ModuleWidgetSearchLine(this, _tree);
searchLabel->setBuddy(_searchLine);
searchLayout->addWidget(searchLabel);
searchLayout->addWidget(_searchLine);
_tree->fill();
connectTree();
mainLayout->addLayout(searchLayout);
mainLayout->addWidget(_tree);
kDebug() << "Index Widget initialized" << endl;
}
IndexWidget::~IndexWidget() {}
void IndexWidget::reload()
{
if (_icon)
_icon->fill();
IndexWidget::~IndexWidget() {
}
Q3ListViewItem *IndexWidget::firstTreeViewItem()
{
if (_tree)
return _tree->firstChild();
else
return 0L;
void IndexWidget::reload() {
}
void IndexWidget::moduleSelected(ConfigModule *m)
{
const QObject *obj = sender();
if(!m) return;
void IndexWidget::selectModule(ConfigModule *module) {
kDebug() << "Selecting module..." << endl;
emit moduleActivated(m);
ModuleTreeItem* moduleTreeItem = _tree->findMatchingItem(module);
if (obj->inherits("ModuleIconView") && _tree)
{
_tree->makeVisible(m);
disconnectTree();
_tree->disconnect(SIGNAL(moduleSelected(ConfigModule*)));
_tree->makeSelected(m);
connect(_tree, SIGNAL(moduleSelected(ConfigModule*)),
this, SLOT(moduleSelected(ConfigModule*)));
}
else if (obj->inherits("ModuleTreeView") && _icon)
{
_icon->makeVisible(m);
_tree->scrollToItem(moduleTreeItem);
moduleTreeItem->setSelected(true);
_icon->disconnect(SIGNAL(moduleSelected(ConfigModule*)));
_icon->makeSelected(m);
connect(_icon, SIGNAL(moduleSelected(ConfigModule*)),
this, SLOT(moduleSelected(ConfigModule*)));
}
connectTree();
emit moduleActivated(module);
}
void IndexWidget::makeSelected(ConfigModule *module)
{
if (_icon)
{
_icon->disconnect(SIGNAL(moduleSelected(ConfigModule*)));
_icon->makeSelected(module);
connect(_icon, SIGNAL(moduleSelected(ConfigModule*)),
this, SLOT(moduleSelected(ConfigModule*)));
}
if (_tree)
{
_tree->disconnect(SIGNAL(moduleSelected(ConfigModule*)));
_tree->makeSelected(module);
connect(_tree, SIGNAL(moduleSelected(ConfigModule*)),
this, SLOT(moduleSelected(ConfigModule*)));
}
void IndexWidget::selectGeneral() {
_tree->scrollToItem(_tree->generalItem());
disconnectTree();
_tree->generalItem()->setSelected(true);
connectTree();
emit generalActivated();
}
void IndexWidget::makeVisible(ConfigModule *module)
{
if (_icon)
_icon->makeVisible(module);
if (_tree)
_tree->makeVisible(module);
void IndexWidget::connectTree() {
connect(_tree, SIGNAL(moduleSelected(ConfigModule*)), this, SLOT(selectModule(ConfigModule*)));
connect(_tree, SIGNAL(generalSelected()), this, SLOT(selectGeneral()));
}
void IndexWidget::activateView(IndexViewMode mode)
{
viewMode = mode;
if (mode == Icon)
{
if (!_icon)
{
_icon=new ModuleIconView(_modules, this);
addWidget (_icon);
_icon->fill();
connect(_icon, SIGNAL(moduleSelected(ConfigModule*)),
this, SLOT(moduleSelected(ConfigModule*)));
}
setCurrentWidget( _icon );
}
else
{
if (!_tree)
{
_tree=new ModuleTreeView(_modules, this);
addWidget (_tree);
_tree->fill();
connect(_tree, SIGNAL(moduleSelected(ConfigModule*)),
this, SLOT(moduleSelected(ConfigModule*)));
connect(_tree, SIGNAL(categorySelected(Q3ListViewItem*)),
this, SIGNAL(categorySelected(Q3ListViewItem*)));
}
setCurrentWidget( _tree );
}
void IndexWidget::disconnectTree() {
_tree->disconnect(SIGNAL(generalSelected()));
_tree->disconnect(SIGNAL(moduleSelected(ConfigModule*)));
}

View file

@ -1,60 +1,61 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 2000 Matthias Elter <elter@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __indexwidget_h__
#define __indexwidget_h__
#include "global.h"
#include <QStackedWidget>
#include <QWidget>
class QListWidgetItem;
class ConfigModuleList;
class ConfigModule;
class ModuleTreeView;
class ModuleIconView;
class Q3ListViewItem;
class IndexWidget : public QStackedWidget
{
Q_OBJECT
class ModuleTreeItem;
class ModuleWidgetSearchLine;
class IndexWidget : public QWidget {
Q_OBJECT
public:
IndexWidget(ConfigModuleList *list, QWidget *parent, const char *name=0);
virtual ~IndexWidget();
IndexWidget(ConfigModuleList *list, QWidget *parent);
virtual ~IndexWidget();
Q3ListViewItem *firstTreeViewItem();
public Q_SLOTS:
void makeVisible(ConfigModule *module);
void makeSelected(ConfigModule *module);
void activateView(IndexViewMode);
void reload();
public slots:
void reload();
protected Q_SLOTS:
void moduleSelected(ConfigModule *);
void selectGeneral();
void selectModule(ConfigModule *);
Q_SIGNALS:
void moduleActivated(ConfigModule *module);
void categorySelected(Q3ListViewItem *);
signals:
void generalActivated();
void moduleActivated(ConfigModule *module);
private:
ModuleTreeView *_tree;
ModuleIconView *_icon;
ConfigModuleList *_modules;
IndexViewMode viewMode;
void connectTree();
void disconnectTree();
ModuleTreeView *_tree;
ModuleWidgetSearchLine* _searchLine;
};
#endif

View file

@ -1,33 +1,35 @@
# TODO: HAVE_COREAUDIO (for OSX)
# TODO: HAVE_LIBDEVINFO_H (for Solaris 7 and later)
# to be set if both -ldevinfo and libdevinfo.h exist
check_include_files(devinfo.h HAVE_DEVINFO_H) # info_fbsd.cpp
check_include_files(fstab.h HAVE_FSTAB_H) # info_linux.cpp
check_include_files(linux/raw.h HAVE_LINUX_RAW_H) # info_linux.cpp
check_include_files(mntent.h HAVE_MNTENT_H) # info_linux.cpp
check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H) # info_linux.cpp
check_include_files(sys/raw.h HAVE_SYS_RAW_H) # info_linux.cpp
check_include_files(Alib.h HAVE_ALIB_H) # info_hpux.cpp
# OS Base includes
include(../base/CMakeLists.txt)
configure_file (config-infocenter.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-infocenter.h )
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../base
)
########### next target ###############
set(kcm_info_PART_SRCS main.cpp memory.cpp )
set(kcm_info_PART_SRCS main.cpp info.cpp ../base/os_current.cpp )
kde4_add_plugin(kcm_info ${kcm_info_PART_SRCS})
target_link_libraries(kcm_info ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY} ${X11_X11_LIB})
target_link_libraries(kcm_info ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QT3SUPPORT_LIBRARY} ${X11_X11_LIB})
install(TARGETS kcm_info DESTINATION ${PLUGIN_INSTALL_DIR} )
########### install files ###############
install(FILES memory.desktop
# processor.desktop # currently broken
dma.desktop interrupts.desktop ioports.desktop pci.desktop sound.desktop devices.desktop scsi.desktop partitions.desktop xserver.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
install(
FILES
dma.desktop
interrupts.desktop
ioports.desktop
sound.desktop
devices.desktop
scsi.desktop
partitions.desktop
xserver.desktop
DESTINATION ${SERVICES_INSTALL_DIR}
)

View file

@ -1,501 +1,104 @@
/*
Main Widget for showing system-dependent information.
(But all functions in THIS FILE should be system independent !)
Main Widget for showing system-dependent information.
(But all functions in THIS FILE should be system independent !)
(C) 1998-2003 by Helge Deller <deller@kde.org>
(C) 1998-2003 by Helge Deller <deller@kde.org>
** main.cpp includes this file ! **
*/
This source-file includes another system-dependet sourcefile called
info_<systemname>.cpp
which should define one or more of the following defines to
indicate, that this information is really available.
#include "info.h"
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_PCI_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
right now, there is the problem, that also the .desktop-files should
depend on the systemname, so that only available .desktop-files will
be copied to kde/applnk/Settings/Information !!
*/
#include <Qt3Support/Q3Header>
#include <klocale.h>
#include <QLayout>
#include <QProcess>
//Added by qt3to4:
#include <QLabel>
#include <QHBoxLayout>
#include <QTextStream>
#include <QHeaderView>
#include <kglobalsettings.h>
#include <kiconloader.h>
#include <kdialog.h>
#include <klocale.h>
#include <kdebug.h>
#include "info.h" /* include the forward declares... */
KInfoListWidget::KInfoListWidget(const KComponentData &inst, const QString &_title, QWidget *parent, bool _getlistbox(QTreeWidget *tree) ) :
KCModule(inst, parent), title(_title) {
KAboutData *about = new KAboutData(I18N_NOOP("kcminfo"), 0,
ki18n("KDE Panel System Information Control Module"),
0, KLocalizedString(), KAboutData::License_GPL,
ki18n( "(c) 2008 Nicolas Ternisien\n"
"(c) 1998 - 2002 Helge Deller"));
#include <X11/Xlib.h>
about->addAuthor(ki18n("Nicolas Ternisien"), KLocalizedString(), "nicolas.ternisien@gmail.com");
about->addAuthor(ki18n("Helge Deller"), KLocalizedString(), "deller@kde.org");
setAboutData(about);
/* All Functions GetInfo_xyz() can set GetInfo_ErrorString, when a special
error-message should be shown to the user....
If GetInfo_ErrorString is not modified in the function, the default string
DEFAULT_ERRORSTRING will be used...
*/
kDebug() << "Constructing a KInfoListWidget..." << endl;
static QString *GetInfo_ErrorString; /* should always point to:
KInfoListWidget::ErrorString */
static bool sorting_allowed; /* is sorting allowed by user ? */
//setButtons(KCModule::Help);
getlistbox = _getlistbox;
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setSpacing(KDialog::spacingHint());
layout->setMargin(0);
widgetStack = new QStackedWidget(this);
layout->addWidget(widgetStack);
tree = new QTreeWidget(widgetStack);
widgetStack->addWidget(tree);
tree->setMinimumSize(200, 120);
tree->setFont(KGlobalSettings::generalFont()); /* default font */
tree->setSortingEnabled(true);
tree->setRootIsDecorated(false);
tree->header()->setSortIndicatorShown(true);
tree->setWhatsThis(i18n("This list displays system information on the selected category.") );
noInfoText = new QLabel(widgetStack);
widgetStack->addWidget(noInfoText);
noInfoText->setAlignment(Qt::AlignCenter);
noInfoText->setWordWrap( true);
widgetStack->setCurrentWidget(noInfoText);
#if defined(__linux__)
# define DEFAULT_ERRORSTRING QString() /* i18n("Maybe the proc-filesystem is not enabled in Linux-Kernel.") */
#elif defined(__hpux)
# define DEFAULT_ERRORSTRING QString()
#else
#define DEFAULT_ERRORSTRING i18n("This system may not be completely supported yet.")
#endif
/* easier to read with such a define ! */
#define I18N_MAX(txt,in,fm,maxw) \
{ int n = fm.width(txt=in); if (n>maxw) maxw=n; }
#define PIXEL_ADD 20 // add x Pixel to multicolumns..
#define HEXDIGITS (sizeof(int)*8/4) /* 4 Bytes = 32 Bits = 8 Hex-Digits */
static const QString Value( int val, int numbers=1 )
{
return KGlobal::locale()->formatNumber(val, 0).rightJustified(numbers);
}
static const QString HexStr(unsigned long val, int digits )
{
QString hexstr;
int i;
hexstr = QString::fromLatin1("0x%1").arg(val, digits, 16/*=HEX*/);
for (i=hexstr.length()-1; i>0; --i)
if (hexstr[i]==' ')
hexstr[i] = '0';
return hexstr;
}
void KInfoListWidget::load() {
kDebug() << "Loading KInfoListWidget..." << endl;
static struct _event_table {
const char *name;
long value;
} event_table[] = {
{ "KeyPressMask", KeyPressMask },
{ "KeyReleaseMask", KeyReleaseMask },
{ "ButtonPressMask", ButtonPressMask },
{ "ButtonReleaseMask", ButtonReleaseMask },
{ "EnterWindowMask", EnterWindowMask },
{ "LeaveWindowMask", LeaveWindowMask },
{ "PointerMotionMask", PointerMotionMask },
{ "PointerMotionHintMask", PointerMotionHintMask },
{ "Button1MotionMask", Button1MotionMask },
{ "Button2MotionMask", Button2MotionMask },
{ "Button3MotionMask", Button3MotionMask },
{ "Button4MotionMask", Button4MotionMask },
{ "Button5MotionMask", Button5MotionMask },
{ "ButtonMotionMask", ButtonMotionMask },
{ "KeymapStateMask", KeymapStateMask },
{ "ExposureMask", ExposureMask },
{ "VisibilityChangeMask", VisibilityChangeMask },
{ "StructureNotifyMask", StructureNotifyMask },
{ "ResizeRedirectMask", ResizeRedirectMask },
{ "SubstructureNotifyMask", SubstructureNotifyMask },
{ "SubstructureRedirectMask",SubstructureRedirectMask },
{ "FocusChangeMask", FocusChangeMask },
{ "PropertyChangeMask", PropertyChangeMask },
{ "ColormapChangeMask", ColormapChangeMask },
{ "OwnerGrabButtonMask", OwnerGrabButtonMask },
{ 0L, 0 }};
//TODO Remove tree content before clear it
tree->clear();
errorString = i18n("No information available about %1.", title) + QLatin1String("\n\n") + DEFAULT_ERRORSTRING;
static Q3ListViewItem* XServer_fill_screen_info( Q3ListViewItem *lBox, Q3ListViewItem *last,
Display *dpy, int scr, int default_scr)
{
unsigned width, height;
double xres, yres;
int i,
ndepths,
*depths;
Screen *s = ScreenOfDisplay(dpy,scr); /* opaque structure */
Q3ListViewItem *item;
/* No Sorting per default */
tree->setSortingEnabled(false);
/*
* there are 2.54 centimeters to an inch; so there are 25.4 millimeters.
*
* dpi = N pixels / (M millimeters / (25.4 millimeters / 1 inch))
* = N pixels / (M inch / 25.4)
* = N * 25.4 pixels / M inch
*/
xres = ((double)(DisplayWidth(dpy,scr) *25.4)/DisplayWidthMM(dpy,scr) );
yres = ((double)(DisplayHeight(dpy,scr)*25.4)/DisplayHeightMM(dpy,scr));
item = new Q3ListViewItem(lBox,last, ki18n("Screen # %1").subs((int)scr,-1).toString(),
(scr==default_scr) ? i18n("(Default Screen)") : QString() );
item->setExpandable(true);
if (scr==default_scr)
item->setOpen(true);
last = new Q3ListViewItem(item, i18n("Dimensions"),
i18n("%1 x %2 Pixel (%3 x %4 mm)",
(int)DisplayWidth(dpy,scr) ,
(int)DisplayHeight(dpy,scr) ,
(int)DisplayWidthMM(dpy,scr) ,
(int)DisplayHeightMM (dpy,scr) ));
last = new Q3ListViewItem(item, last, i18n("Resolution"),
i18n("%1 x %2 dpi",
(int)(xres+0.5) ,
(int)(yres+0.5) ));
ndepths = 0;
depths = 0;
depths = XListDepths (dpy, scr, &ndepths);
if (depths) {
QString txt;
for (i = 0; i < ndepths; i++) {
txt = txt + Value(depths[i]);
if (i < ndepths - 1)
txt = txt + QLatin1String(", ");
}
last = new Q3ListViewItem(item, last, ki18n("Depths (%1)").subs(ndepths,-1).toString(), txt);
XFree((char *) depths);
}
last = new Q3ListViewItem(item, last, i18n("Root Window ID"),
HexStr((unsigned long)RootWindow(dpy,scr),HEXDIGITS));
last = new Q3ListViewItem(item, last, i18n("Depth of Root Window"),
(DisplayPlanes (dpy, scr) == 1)
? i18n("%1 plane", DisplayPlanes(dpy,scr)) /*singular*/
: i18n("%1 planes", DisplayPlanes(dpy,scr)));/*plural*/
last = new Q3ListViewItem(item, last, i18n("Number of Colormaps"),
i18n("minimum %1, maximum %2",
(int)MinCmapsOfScreen(s), (int)MaxCmapsOfScreen(s)));
last = new Q3ListViewItem(item, last, i18n("Default Colormap"),
Value((int)DefaultColormap(dpy,scr)));
last = new Q3ListViewItem(item, last, i18n("Default Number of Colormap Cells"),
Value((int)DisplayCells(dpy, scr)));
last = new Q3ListViewItem(item, last, i18n("Preallocated Pixels"),
i18n("Black %1, White %2",
KGlobal::locale()->formatNumber(BlackPixel(dpy,scr), 0),
KGlobal::locale()->formatNumber(WhitePixel(dpy,scr), 0)));
QString YES(i18n("Yes"));
QString NO(i18n("No"));
last = new Q3ListViewItem(item, last, i18n("Options"),
i18n("backing-store: %1, save-unders: %2",
(DoesBackingStore(s) == NotUseful) ? NO :
((DoesBackingStore(s) == Always) ? YES : i18n("When mapped")) ,
DoesSaveUnders(s) ? YES : NO ));
XQueryBestSize (dpy, CursorShape, RootWindow(dpy,scr), 65535, 65535,
&width, &height);
last = new Q3ListViewItem(item, last, i18n("Largest Cursor"),
(width == 65535 && height == 65535)
? i18n("unlimited") : QString::fromLatin1("%1 x %2").arg(width).arg(height));
last = new Q3ListViewItem(item, last, i18n("Current Input Event Mask"),
HexStr((unsigned long)EventMaskOfScreen(s),HEXDIGITS));
item = last;
struct _event_table *etp;
for (etp=event_table; etp->name; etp++) {
if (EventMaskOfScreen(s) & etp->value)
item = new Q3ListViewItem(last, item,
i18n("Event = %1", HexStr(etp->value,HEXDIGITS)),
etp->name );
}
return item;
}
static const QString Order( int order )
{
if (order==LSBFirst) return i18n("LSBFirst"); else
if (order==MSBFirst) return i18n("MSBFirst"); else
return i18n("Unknown Order %1", order);
}
static const QString BitString( unsigned long n )
{
return i18np("1 Bit", "%1 Bits", n); // singular & plural form of "%d Bit"
}
static const QString ByteString( unsigned long n )
{
/* explanation in BR #52640 (http://bugs.kde.org/show_bug.cgi?id=52640) */
if (n == 1)
return i18n("1 Byte"); // singular form: "1 Byte" (yes, it is "1", not "%1"!)
return i18n("%1 Bytes", // plural form: "%1 Bytes"
KGlobal::locale()->formatNumber(n,0));
}
static bool GetInfo_XServer_Generic( Q3ListView *lBox )
{
/* Many parts of this source are taken from the X11-program "xdpyinfo" */
int i,n;
long req_size;
Display *dpy;
XPixmapFormatValues *pmf;
QString str,txt;
Q3ListViewItem *last, *item, *next;
dpy = XOpenDisplay(0);
if (!dpy)
return false;
lBox->addColumn(i18n("Information") );
lBox->addColumn(i18n("Value") );
sorting_allowed = false;
next = new Q3ListViewItem(lBox, i18n("Server Information"));
next->setPixmap(0, SmallIcon("xorg"));
next->setOpen(true);
next->setSelectable(false);
next->setExpandable(false);
last = new Q3ListViewItem(next, i18n("Name of the Display"),
DisplayString(dpy));
last = new Q3ListViewItem(next, last, i18n("Vendor String"), QLatin1String(ServerVendor(dpy)));
last = new Q3ListViewItem(next, last, i18n("Vendor Release Number"),
Value((int)VendorRelease(dpy)));
last = new Q3ListViewItem(next, last, i18n("Version Number"),
QString::fromLatin1("%1.%2").arg((int)ProtocolVersion(dpy))
.arg((int)ProtocolRevision(dpy)));
last = item = new Q3ListViewItem(next, last, i18n("Available Screens"));
last->setOpen(true);
last->setExpandable(true);
for (i=0; i<ScreenCount(dpy); i++) {
item = XServer_fill_screen_info(last, item, dpy, i, (int)DefaultScreen(dpy));
if (i==0) item->setOpen(true);
}
last = new Q3ListViewItem( next, last, i18n("Supported Extensions") );
item = last;
int extCount;
char **extensions = XListExtensions( dpy, &extCount );
for ( i = 0; i < extCount; i++ ) {
item = new Q3ListViewItem( last, item, QLatin1String( extensions[i] ) );
}
XFreeExtensionList( extensions );
pmf = XListPixmapFormats(dpy, &n);
last = item = new Q3ListViewItem(next, last, i18n("Supported Pixmap Formats"));
if (pmf) {
last->setExpandable(true);
for (i=0; i<n; i++) {
item = new Q3ListViewItem(last, item,
i18n("Pixmap Format #%1", i+1),
i18n("%1 BPP, Depth: %2, Scanline padding: %3",
pmf[i].bits_per_pixel,
BitString(pmf[i].depth),
BitString(pmf[i].scanline_pad)));
bool ok = false;
/* retrieve the information */
if (getlistbox) {
ok = (*getlistbox)(tree);
}
XFree ((char *)pmf);
}
req_size = XExtendedMaxRequestSize(dpy);
if (!req_size) req_size = XMaxRequestSize(dpy);
last = new Q3ListViewItem(next, last, i18n("Maximum Request Size"),
ByteString(req_size*4));
last = new Q3ListViewItem(next, last, i18n("Motion Buffer Size"),
ByteString(XDisplayMotionBufferSize(dpy)));
/* set default title */
if (tree->headerItem()->columnCount()<=1) {
QStringList headers;
headers << title;
tree->setHeaderLabels(headers);
}
last = item = new Q3ListViewItem(next, last, i18n("Bitmap"));
last->setExpandable(true);
item = new Q3ListViewItem(last, item, i18n("Unit"),
Value(BitmapUnit(dpy)) );
item = new Q3ListViewItem(last, item, i18n("Order"),
Order(BitmapBitOrder(dpy)));
item = new Q3ListViewItem(last, item, i18n("Padding"),
Value(BitmapPad(dpy)));
if (ok) {
widgetStack->setCurrentWidget(tree);
} else {
noInfoText->setText(errorString);
widgetStack->setCurrentWidget(noInfoText);
}
last = new Q3ListViewItem(next, last, i18n("Image Byte Order"),
Order(ImageByteOrder(dpy)));
tree->resizeColumnToContents(0);
XCloseDisplay (dpy);
return true;
emit changed(false);
}
QString KInfoListWidget::quickHelp() const {
return i18n("All the information modules return information about a certain"
" aspect of your computer hardware or your operating system.");
}
/*
***************************************************************************
***************************************************************************
***************************************************************************
*/
void KInfoListWidget::load()
{
bool ok = false;
lBox->clear();
/* Delete the user-visible ErrorString, before calling the
retrieve-function. If the function wants the widget to show
another string, then it change *GetInfo_ErrorString ! */
ErrorString = i18n("No information available about %1.", title)
+ QLatin1String("\n\n") + DEFAULT_ERRORSTRING;
GetInfo_ErrorString = &ErrorString; /* save the address of ErrorString */
sorting_allowed = true; /* the functions may set that */
lBox->setSorting(-1); /* No Sorting per default */
if (getlistbox)
ok = (*getlistbox)(lBox); /* retrieve the information */
if (lBox->header()->count()<=1)
lBox->addColumn(title); /* set default title */
/* is the user allowed to use sorting ? */
lBox->header()->setClickEnabled(sorting_allowed);
lBox->header()->setFont(KGlobalSettings::generalFont());
lBox->setShowSortIndicator(sorting_allowed);
if (ok)
{
widgetStack->setCurrentWidget(lBox);
}
else
{
NoInfoText->setText(ErrorString);
widgetStack->setCurrentWidget(NoInfoText);
}
emit changed(false);
}
QString KInfoListWidget::quickHelp() const
{
return i18n("<h1>System Information</h1>"
" All the information modules return information about a certain"
" aspect of your computer hardware or your operating system."
" Not all modules are available on all hardware architectures"
" and/or operating systems." );
}
KInfoListWidget::KInfoListWidget(const KComponentData &inst,const QString &_title, QWidget *parent,
bool _getlistbox(Q3ListView *lbox))
: KCModule(inst,parent),
title(_title)
{
KAboutData *about =
new KAboutData(I18N_NOOP("kcminfo"), 0,
ki18n("KDE Panel System Information Control Module"),
0, KLocalizedString(), KAboutData::License_GPL,
ki18n("(c) 1998 - 2002 Helge Deller"));
about->addAuthor(ki18n("Helge Deller"), KLocalizedString(), "deller@kde.org");
setAboutData( about );
setButtons(KCModule::Help);
getlistbox = _getlistbox;
GetInfo_ErrorString = 0;
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setSpacing(KDialog::spacingHint());
layout->setMargin(0);
widgetStack = new QStackedWidget(this);
layout->addWidget(widgetStack);
lBox = new Q3ListView(widgetStack);
widgetStack->insertWidget(0,lBox);
lBox->setMinimumSize(200,120);
lBox->setFont(KGlobalSettings::generalFont()); /* default font */
lBox->setAllColumnsShowFocus(true);
lBox->setWhatsThis( i18n( "This list displays system information on the selected category." ) );
NoInfoText = new QLabel(widgetStack);
widgetStack->insertWidget(1,NoInfoText);
NoInfoText->setAlignment( Qt::AlignCenter );
NoInfoText->setWordWrap( true );
widgetStack->setCurrentWidget(NoInfoText);
load();
}
/* Helper-function to read output from an external program */
static int GetInfo_ReadfromPipe( Q3ListView *lBox, const char *FileName, bool WithEmptyLines = true )
{
QProcess proc;
Q3ListViewItem* olditem = 0L;
QString s;
proc.start(FileName, QIODevice::ReadOnly);
if (!proc.waitForFinished()) {
// Process hanged or did not start
return 0;
}
QTextStream t(&proc);
while (!t.atEnd()) {
s = t.readLine();
if (!WithEmptyLines && s.length()==0)
continue;
olditem = new Q3ListViewItem(lBox, olditem, s);
}
return (lBox->childCount());
}
/*
***************************************************************************
** Include system-specific code **
***************************************************************************
*/
#ifdef __linux__
#include "info_linux.cpp"
#elif defined(sgi) && sgi
#include "info_sgi.cpp"
#elif defined(__FreeBSD__) || defined(__DragonFly__)
#include "info_fbsd.cpp"
#elif __hpux
#include "info_hpux.cpp"
#elif __NetBSD__
#include "info_netbsd.cpp"
#elif __OpenBSD__
#include "info_openbsd.cpp"
#elif defined(__svr4__) && defined(sun)
#include "info_solaris.cpp"
#elif __svr4__
#include "info_svr4.cpp"
#elif _AIX
#include "info_aix.cpp"
#elif defined(__APPLE__)
#include "info_osx.cpp"
#else
#include "info_generic.cpp" /* Default for unsupported systems.... */
#endif
/*
***************************************************************************
** End of: Include system-specific code **
***************************************************************************
*/

View file

@ -6,43 +6,30 @@
#include <QLabel>
#include <QPushButton>
#include <QTimer>
#include <Qt3Support/Q3CheckListItem>
#include <QTreeWidget>
#include <QFile>
#include <QEvent>
#include <kcmodule.h>
#include <kaboutdata.h>
#include "config-infocenter.h"
/* function call-back-prototypes... */
bool GetInfo_CPU( Q3ListView *lBox );
bool GetInfo_IRQ( Q3ListView *lBox );
bool GetInfo_DMA( Q3ListView *lBox );
bool GetInfo_PCI( Q3ListView *lBox );
bool GetInfo_IO_Ports( Q3ListView *lBox );
bool GetInfo_Sound( Q3ListView *lBox );
bool GetInfo_Devices( Q3ListView *lBox );
bool GetInfo_SCSI( Q3ListView *lBox );
bool GetInfo_Partitions( Q3ListView *lBox );
bool GetInfo_XServer_and_Video( Q3ListView *lBox );
#include "os_current.h"
class KInfoListWidget : public KCModule
{
public:
KInfoListWidget(const KComponentData &inst,const QString &_title, QWidget *parent, bool _getlistbox (Q3ListView *)=0);
KInfoListWidget(const KComponentData &inst,const QString &_title, QWidget *parent, bool _getlistbox (QTreeWidget*) = NULL);
virtual void load();
virtual QString quickHelp() const;
private:
Q3ListView *lBox;
bool (*getlistbox) (Q3ListView *);
QTreeWidget* tree;
bool (*getlistbox) (QTreeWidget*);
QString title;
QLabel *NoInfoText;
QString ErrorString;
QLabel *noInfoText;
QString errorString;
QStackedWidget *widgetStack;
};

View file

@ -1,486 +0,0 @@
/*
* info_aix.cpp
*
* Reza Arbab <arbab@austin.ibm.com>
*
* GetInfo_Partitions() and its helpers (get_fs_usage, fs_adjust_blocks)
* taken from info_hpux.cpp.
*
*/
#include <cf.h>
#define class _class
#include <odmi.h>
#include <sys/cfgodm.h>
#include <sys/cfgdb.h>
#undef class
#include <nl_types.h>
#include <string.h>
#include <kdebug.h>
#include <stdlib.h>
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PCI_AVAILABLE
#include <sys/statfs.h>
#include <sys/statvfs.h>
#include <sys/types.h>
#include <unistd.h>
#include <fstab.h>
#define INFO_PARTITIONS_AVAILABLE
#include <errno.h>
#include <sys/utsname.h>
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_XSERVER_AVAILABLE
char *
device_description(struct CuDv *cudv)
{
char *desc = NULL;
struct PdDv *pddv = cudv->PdDvLn; /* link to Predefined Devices database */
nl_catd cat;
cat = catopen("/usr/lib/methods/devices.cat", NL_CAT_LOCALE);
if ((int)cat == -1)
return NULL;
desc = strdup( catgets(cat, pddv->setno, pddv->msgno, "N/A") );
catclose(cat);
return desc;
}
bool
list_devices(QListView *lBox, char *criteria)
{
struct CuDv *cudv; /* Customized Devices */
struct listinfo info;
int i;
char *cudv_desc;
QString cudv_status;
QListViewItem *lastitem = NULL;
lBox->addColumn(i18n("Name"));
lBox->addColumn(i18n("Status"));
lBox->addColumn(i18n("Location"));
lBox->addColumn(i18n("Description"));
if (odm_initialize() == -1)
{
kError(0) << "odm_initialize() failed: odmerrno = " << odmerrno << endl;
return(false);
}
cudv = (struct CuDv *) odm_get_list(CuDv_CLASS, criteria, &info, 100, 2);
if ((int)cudv == -1)
{
odm_terminate();
kError(0) << "odm_get_list() failed: odmerrno = " << odmerrno << endl;
return(false);
}
else if (!cudv) /* empty list */
{
odm_terminate();
return(true);
}
for (i=0; i<info.num; i++)
{
switch(cudv[i].status)
{
case DEFINED: cudv_status = QString("Defined"); break;
case AVAILABLE: cudv_status = QString("Available"); break;
case STOPPED: cudv_status = QString("Stopped"); break;
default: cudv_status = QString("Unknown");
}
cudv_desc = device_description(&cudv[i]);
lastitem = new QListViewItem(lBox, lastitem,
QString(cudv[i].name),
cudv_status,
QString(cudv[i].location),
QString(cudv_desc ? cudv_desc : "N/A") );
if (cudv_desc) free(cudv_desc);
}
if (odm_free_list(cudv, &info) == -1)
{
odm_terminate();
kError(0) << "odm_free_list() failed: odmerrno = " << odmerrno << endl;
return(false);
}
odm_terminate();
return true;
}
enum CHIP
{
P2SC, Power, Power2, Power3, Power3_II, PowerPC,
PowerPC_604e, PowerPersonal, RD64_II, RS_III, RS64, RS64_II,
RS64_III, RS64_IV, RSC, ThinkPad, unknown,
NUM_CHIPS
};
static const char chip_name[NUM_CHIPS][16] =
{
"P2SC", "Power", "Power2", "Power3", "Power3-II", "PowerPC",
"PowerPC 604e", "PowerPersonal", "RD64-II", "RS-III", "RS64", "RS64-II",
"RS64-III", "RS64-IV", "RSC", "ThinkPad", "unknown"
};
struct model
{
char model_ID[21];
char machine_type[21];
char processor_speed[21];
unsigned short architecture; /* enum CHIP */
};
struct model _models[] =
{
{ "02", "7015-930", "25", Power },
{ "10", "7013-530", "25", Power },
{ "10", "7016-730", "25", Power },
{ "11", "7013-540", "30", Power },
{ "14", "7013-540", "30", Power },
{ "18", "7013-53H", "33", Power },
{ "1C", "7013-550", "41.6", Power },
{ "20", "7015-930", "25", Power },
{ "2E", "7015-950", "41", Power },
{ "30", "7013-520", "20", Power },
{ "31", "7012-320", "20", Power },
{ "34", "7013-52H", "25", Power },
{ "35", "7012-32H", "25", Power },
{ "37", "7012-340", "33", Power },
{ "38", "7012-350", "41", Power },
{ "41", "7011-20", "33", PowerPC },
{ "45", "7011-220", "33", PowerPC },
{ "42", "7006-41T/41W", "80", PowerPC },
{ "43", "7008-M20", "33", Power },
{ "43", "7008-M2A", "33", Power },
{ "46", "7011-250", "66", PowerPC },
{ "47", "7011-230", "45", RSC },
{ "48", "7009-C10", "80", PowerPC },
/* 4C models use a different table -- see below */
{ "4C", "70XX", "(unknown)", unknown },
{ "57", "7012-390", "67", Power2 },
{ "57", "7030-3BT", "67", Power2 },
{ "57", "9076-SP2 Thin", "67", Power2 },
{ "58", "7012-380", "59", Power2 },
{ "58", "7030-3AT", "59", Power2 },
{ "59", "7012-39H", "67", Power2 },
{ "59", "9076-SP2 Thin w/L2", "67", Power2 },
{ "5C", "7013-560", "50", Power },
{ "63", "7015-970", "50", Power },
{ "63", "7015-97B", "50", Power },
{ "64", "7015-980", "62.5", Power },
{ "64", "7015-98B", "62.5", Power },
{ "66", "7013-580", "62.5", Power },
{ "67", "7013-570", "50", Power },
{ "67", "7015-R10", "50", Power },
{ "70", "7013-590", "66", Power2 },
{ "70", "9076-SP2 Wide", "66", Power2 },
{ "71", "7013-58H", "55", Power2 },
{ "72", "7013-59H", "66", Power2 },
{ "72", "7015-R20", "66", Power2 },
{ "72", "9076-SP2 Wide", "66", Power2 },
{ "75", "7012-370", "62", Power },
{ "75", "7012-375", "62", Power },
{ "75", "9076-SP1 Thin", "62", Power },
{ "76", "7012-360", "50", Power },
{ "76", "7012-365", "50", Power },
{ "77", "7012-350", "41", Power },
{ "77", "7012-355", "41", Power },
{ "77", "7013-55L", "41.6", Power },
{ "79", "7013-591", "77", Power2 },
{ "79", "9076-SP2 Wide", "77", Power2 },
{ "80", "7015-990", "71.5", Power2 },
{ "81", "7015-R24", "71.5", P2SC },
{ "89", "7013-595", "135", P2SC },
{ "89", "9076-SP2 Wide", "135", P2SC },
{ "90", "7009-C20", "120", PowerPC },
{ "91", "7006-42W/42T", "120", PowerPC },
{ "94", "7012-397", "160", P2SC },
{ "94", "9076-SP2 Thin", "160", P2SC },
{ "A0", "7013-J30", "75", PowerPC },
{ "A1", "7013-J40", "112", PowerPC },
{ "A3", "7015-R30", "(unknown)", PowerPC },
{ "A4", "7015-R40", "(unknown)", PowerPC },
{ "A4", "7015-R50", "(unknown)", PowerPC },
{ "A4", "9076-SP2 High", "(unknown)", PowerPC },
{ "A6", "7012-G30", "(unknown)", PowerPC },
{ "A7", "7012-G40", "(unknown)", PowerPC },
{ "C0", "7024-E20", "(unknown)", PowerPC },
{ "C0", "7024-E30", "(unknown)", PowerPC },
{ "C4", "7025-F30", "(unknown)", PowerPC },
{ "F0", "7007-N40", "50", ThinkPad },
{ "", "", "0", 0 }
};
struct model _4C_models[] =
{
{ "IBM,7017-S70", "7017-S70", "125", RS64 },
{ "IBM,7017-S7A", "7017-S7A", "262", RD64_II },
{ "IBM,7017-S80", "7017-S80", "450", RS_III },
{ "IBM,7017-S85", "pSeries 680", "600", RS64_IV },
{ "IBM,7025-F40", "7025-F40", "166/233", PowerPC_604e },
{ "IBM,7025-F50", "7025-F50", "(unknown)", PowerPC_604e },
{ "IBM,7025-F80", "7025-F80", "(unknown)", RS64_III },
{ "IBM,7026-H10", "7025-H10", "166/233", PowerPC_604e },
{ "IBM,7026-H50", "7025-H50", "(unknown)", PowerPC_604e },
{ "IBM,7026-H80", "7025-H80", "(unknown)", RS64_III },
{ "IBM,7026-M80", "7026-M80", "500", RS64_III },
{ "IBM,7025-F40", "7025-F40", "166/233", PowerPC },
{ "IBM,7025-F50", "7025-F50", "(unknown)", PowerPC },
{ "IBM,7025-F80", "7025-F80", "450", PowerPC },
{ "IBM,7026-B80", "pSeries 640", "375", Power3_II },
{ "IBM,7026-H10", "7026-H10", "166/233", PowerPC },
{ "IBM,7026-H50", "7026-H50", "(unknown)", PowerPC },
{ "IBM,7026-H70", "7026-H70", "340", RS64_II },
{ "IBM,7026-H80", "7026-H80", "450", PowerPC },
{ "IBM,7026-M80", "7026-M80", "500", PowerPC },
{ "IBM,7042-140", "7043-140", "166/200/233/332", PowerPC },
{ "IBM,7042-150", "7043-150", "375", PowerPC },
{ "IBM,7042-240", "7043-240", "166/233", PowerPC },
{ "IBM,7043-140", "7043-140", "166/200/233/332", PowerPC },
{ "IBM,7043-150", "7043-150", "375", PowerPC },
{ "IBM,7043-240", "7043-240", "166/233", PowerPC },
{ "IBM,7043-260", "7043-260", "200", Power3 },
{ "IBM,7248", "7248-100", "100", PowerPersonal },
{ "IBM,7248", "7248-120", "120", PowerPersonal },
{ "IBM,7248", "7248-132", "132", PowerPersonal },
{ "IBM,9076-270", "9076-SP Silver Node", "(unknown)", PowerPC },
{ "", "", "", 0 },
};
/* all GetInfo_ functions should return true, when the Information
was filled into the lBox-Widget.
returning false indicates, that information was not available.
*/
bool
GetInfo_XServer_and_Video( QListView *lBox )
{
return GetInfo_XServer_Generic( lBox );
}
/*
* Written using information from:
*
* http://service.software.ibm.com/cgi-bin/support/rs6000.support/techbrowse/tbgaus?gaus_mode=8&documents=B93576892313352&database=task
*
* Not fully implemented. In particular there are ways to resolve the
* "(unknown)" clock speeds of many of these models. See page for details.
*
*/
bool
GetInfo_CPU( QListView *lBox )
{
struct utsname info;
struct model *table = _models; /* table of model information */
char model_ID[21] = ""; /* information for table lookup */
char cpu_ID[7] = ""; /* unique CPU ID */
int i;
QListViewItem *lastitem = NULL;
lBox->addColumn(i18n("Information"));
lBox->addColumn(i18n("Value"));
if (uname(&info) == -1)
{
kError(0) << "uname() failed: errno = " << errno << endl;
return false;
}
strncat(model_ID, info.machine+8, 2); /* we want the ninth and tenth digits */
strncat(cpu_ID, info.machine+2, 6);
if (strcmp(model_ID, "4C") == 0) /* need to use a different model_ID and model table */
{
if (odm_initialize() == -1)
kError(0) << "odm_initialize() failed: odmerrno = " << odmerrno << endl;
else
{
struct CuAt cuat; /* Customized Device attribute */
/* equivalent to uname -M */
if ( odm_get_first(CuAt_CLASS, (char *)"name='sys0' and attribute='modelname'", &cuat) )
{
strcpy(model_ID, cuat.value);
table = _4C_models;
}
odm_terminate();
}
}
lastitem = new QListViewItem(lBox, lastitem, QString("CPU ID"), QString(cpu_ID));
lastitem = new QListViewItem(lBox, lastitem, QString("Node"), QString(info.nodename));
lastitem = new QListViewItem(lBox, lastitem, QString("OS"), QString(info.sysname) +
QString(" ") + QString(info.version) + QString(".") + QString(info.release));
for (i=0; *(table[i].model_ID); i++)
if (strcmp(model_ID, table[i].model_ID) == 0)
{
lastitem = new QListViewItem(lBox, lastitem, QString("Machine Type"), QString(table[i].machine_type));
lastitem = new QListViewItem(lBox, lastitem, QString("Architecture"), QString(chip_name[table[i].architecture]));
lastitem = new QListViewItem(lBox, lastitem, QString("Speed"), QString(table[i].processor_speed) + QString(" Mhz"));
break;
}
return(true);
}
bool GetInfo_IRQ( QListView * )
{
return false;
}
bool GetInfo_DMA( QListView * )
{
return false;
}
bool
GetInfo_PCI( QListView *lBox )
{
return list_devices(lBox, (char *)"PdDvLn like '*/pci/*'");
}
bool GetInfo_IO_Ports( QListView * )
{
return false;
}
bool GetInfo_Sound( QListView * )
{
return false;
}
bool
GetInfo_Devices( QListView *lBox )
{
return list_devices(lBox, (char *)"PdDvLn like '*'");
}
bool
GetInfo_SCSI( QListView *lBox )
{
return list_devices(lBox, (char *)"PdDvLn like '*/scsi/*'");
}
/* Parts taken from fsusage.c from the Midnight Commander (mc)
Copyright (C) 1991, 1992 Free Software Foundation, In
Return the number of TOSIZE-byte blocks used by
BLOCKS FROMSIZE-byte blocks, rounding away from zero.
TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */
static long fs_adjust_blocks(long blocks, int fromsize, int tosize)
{
if (tosize <= 0)
abort ();
if (fromsize <= 0)
return -1;
if (fromsize == tosize) /* E.g., from 512 to 512. */
return blocks;
else if (fromsize > tosize) /* E.g., from 2048 to 512. */
return blocks * (fromsize / tosize);
else /* E.g., from 256 to 512. */
return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize);
}
/* Fill in the fields of FSP with information about space usage for
the filesystem on which PATH resides.
Return 0 if successful, -1 if not. */
#define CONVERT_BLOCKS(b) fs_adjust_blocks ((b), fsd.f_bsize, 512)
static int get_fs_usage (char *path, long *l_total, long *l_avail)
{ struct statfs fsd; /* 4.3BSD, SunOS 4, HP-UX, AIX. */
unsigned long fsu_blocks,fsu_bfree,fsu_bavail;
*l_total = *l_avail = 0;
if (statfs (path, &fsd) < 0)
return -1;
fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks);
fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree);
fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail);
*l_avail = getuid () ? fsu_bavail/2 : fsu_bfree/2;
*l_total = fsu_blocks/2;
return 0;
}
// Some Ideas taken from garbazo from his source in info_fbsd.cpp
bool
GetInfo_Partitions ( QListView *lbox )
{
#define NUMCOLS 5
QString Title[NUMCOLS];
int n;
struct fstab *fstab_ent;
struct statvfs svfs;
long total,avail;
QString str;
QString MB(i18n("MB")+ " "); // International Text for MB=Mega-Byte
if (setfsent() != 1) // Try to open fstab
return false;
Title[0] = i18n("Device");
Title[1] = i18n("Mount Point");
Title[2] = i18n("FS Type");
Title[3] = i18n("Total Size");
Title[4] = i18n("Free Size");
for (n=0; n<NUMCOLS; ++n) {
lbox->addColumn(Title[n] );
}
while ((fstab_ent=getfsent())!=NULL) {
/* fstab_ent->fs_type holds only "rw","xx","ro"... */
memset(&svfs,0,sizeof(svfs));
statvfs(fstab_ent->fs_file,&svfs);
get_fs_usage(fstab_ent->fs_file, &total, &avail);
if (!strcmp(fstab_ent->fs_type,FSTAB_XX)) // valid drive ?
svfs.f_basetype[0] = 0;
if(svfs.f_basetype[0]) {
new QListViewItem(lbox, QString(fstab_ent->fs_spec),
QString(fstab_ent->fs_file) + QString(" "),
(svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a")),
Value((total+512)/1024,6) + MB,
Value((avail+512)/1024,6) + MB);
}
else {
new QListViewItem(lbox, QString(fstab_ent->fs_spec),
QString(fstab_ent->fs_file) + QString(" "),
(svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a")));
}
}
endfsent();
return true;
}

View file

@ -1,81 +0,0 @@
/*
1998 by Helge Deller (deller@gmx.de)
free source under GPL
!!!!! this file will be included by info.cpp !!!!!
*/
// Default for unsupportet systems
// the following defines are not really ok here, but maybe we should show, what
// Information could be displayed here....
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_PCI_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
/* all following functions should return true, when the Information
was filled into the lBox-Widget.
returning false indicates, that information was not available.
*/
bool GetInfo_CPU( Q3ListView * )
{
return false;
}
bool GetInfo_IRQ( Q3ListView * )
{
return false;
}
bool GetInfo_DMA( Q3ListView * )
{
return false;
}
bool GetInfo_PCI( Q3ListView * )
{
return false;
}
bool GetInfo_IO_Ports( Q3ListView * )
{
return false;
}
bool GetInfo_Sound( Q3ListView * )
{
return false;
}
bool GetInfo_Devices( Q3ListView * )
{
return false;
}
bool GetInfo_SCSI( Q3ListView * )
{
return false;
}
bool GetInfo_Partitions( Q3ListView * )
{
return false;
}
bool GetInfo_XServer_and_Video( Q3ListView *lBox )
{
return GetInfo_XServer_Generic( lBox );
}

View file

@ -1,785 +0,0 @@
/*
!!!!! this file will be included by info.cpp !!!!!
Mostly written 1998-1999 by Helge Deller (deller@gmx.de),
with some pieces of code from Aubert Pierre.
Last modified: done:
1999-06-21 added more models to the lookup-table (deller)
1999-06-18 added support for 64-Bit HP-UX in CPU-detection(deller)
1999-05-04 added audio(alib)-support (deller)
1999-04-27 [tested with HP-UX 10.20 (HP9000/715/64-EISA)]
added support for nearly all categories
(means: not finished!)
1998-11-01 first, nearly empty version (deller)
with a little source for CPU from Aubert Pierre
*/
#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/pstat.h>
#include <sys/utsname.h>
#include <sys/statvfs.h>
#include <sys/vfs.h>
#include <fstab.h>
#include <stdlib.h>
#include <QFile>
#include <QFontMetrics>
#include <QTextStream>
#define INFO_CPU_AVAILABLE
# define INFO_CPU_MODEL "/bin/model" // as pipe !!
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_PCI_AVAILABLE
# define INFO_PCI "" // Please, who know it ????
# define INFO_PCI_EISA "/etc/eisa/system.sci" // File !
#define INFO_IOPORTS_AVAILABLE
# define INFO_IOPORTS_1 "/etc/dmesg" // as pipe !
# define INFO_IOPORTS_2 "/usr/sbin/dmesg" // as pipe !
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
# define INFO_DEVICES "/etc/ioscan" // as pipe !!
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
# define INFO_PARTITIONS_1 FSTAB // = "/etc/fstab" (in fstab.h)
# define INFO_PARTITIONS_2 "/etc/checklist"
#define INFO_XSERVER_AVAILABLE
/* The following table is from an HP-UX 10.20 System
build out of the files
"/usr/lib/sched.models"
or
"/opt/langtools/lib/sched.models"
If you have more entries, then please add them or send them to me!
*/
// entries for PA_REVISION[]
enum V_ENTRIES
{ V_1x0,
V_1x1, V_1x1a, V_1x1b, V_1x1c, V_1x1d, V_1x1e,
V_2x0,
V_LAST };
static const char PA_REVISION[V_LAST][7]
= { "1.0",
"1.1", "1.1a", "1.1b", "1.1c", "1.1d", "1.1e",
"2.0" };
// entries for PA_NAME[]
enum PA_ENTRIES
{ PA7000,
PA7100, PA7100LC, PA7200, PA7300,
PA8000, PA8200, PA8500,
PARISC_PA_LAST };
static const char PA_NAME[PARISC_PA_LAST][11]
= { "PA7000",
"PA7100", "PA7100LC", "PA7200", "PA7300",
"PA8000", "PA8200", "PA8500" };
struct _type_LOOKUPTABLE {
char Name[8];
unsigned short parisc_rev; // = enum V_ENTRIES
unsigned short parisc_name; // = enum PA_ENTRIES
};
static const struct _type_LOOKUPTABLE PA_LOOKUPTABLE[] = {
/* VERSION A.00.07
(there seems to exist several different files with same version-number !)*/
{ "600" ,V_1x0 ,PA7000 },
{ "635" ,V_1x0 ,PA7000 },
{ "645" ,V_1x0 ,PA7000 },
{ "700" ,V_1x1 ,PA7000 },
{ "705" ,V_1x1a ,PA7000 },
{ "710" ,V_1x1a ,PA7000 },
{ "712" ,V_1x1c ,PA7100LC },
{ "715" ,V_1x1c ,PA7100LC },
{ "720" ,V_1x1a ,PA7000 },
{ "722" ,V_1x1c ,PA7100LC },
{ "725" ,V_1x1c ,PA7100LC },
{ "728" ,V_1x1d ,PA7200 },
{ "730" ,V_1x1a ,PA7000 },
{ "735" ,V_1x1b ,PA7100 },
{ "742" ,V_1x1b ,PA7100 },
{ "743" ,V_1x1b ,PA7100 }, // or a 1.1c,PA7100LC !!
{ "744" ,V_1x1e ,PA7300 },
{ "745" ,V_1x1b ,PA7100 },
{ "747" ,V_1x1b ,PA7100 },
{ "750" ,V_1x1a ,PA7000 },
{ "755" ,V_1x1b ,PA7100 },
{ "770" ,V_1x1d ,PA7200 },
{ "777" ,V_1x1d ,PA7200 },
{ "778" ,V_1x1e ,PA7300 },
{ "779" ,V_1x1e ,PA7300 },
{ "780" ,V_2x0 ,PA8000 },
{ "781" ,V_2x0 ,PA8000 },
{ "782" ,V_2x0 ,PA8200 },
{ "783" ,V_2x0 ,PA8500 },
{ "785" ,V_2x0 ,PA8500 },
{ "800" ,V_1x0 ,PA7000 }, // and one with: 2.0 / PA8000
{ "801" ,V_1x1c ,PA7100LC },
{ "802" ,V_2x0 ,PA8000 },
{ "803" ,V_1x1e ,PA7300 },
{ "804" ,V_2x0 ,PA8000 },
{ "806" ,V_1x1c ,PA7100LC },
{ "807" ,V_1x1a ,PA7000 },
{ "808" ,V_1x0 ,PA7000 },
{ "809" ,V_1x1d ,PA7200 },
{ "810" ,V_2x0 ,PA8000 },
{ "811" ,V_1x1c ,PA7100LC },
{ "813" ,V_1x1e ,PA7300 },
{ "815" ,V_1x0 ,PA7000 },
{ "816" ,V_1x1c ,PA7100LC },
{ "817" ,V_1x1a ,PA7000 },
{ "819" ,V_1x1d ,PA7200 },
{ "820" ,V_2x0 ,PA8000 },
{ "821" ,V_1x1d ,PA7200 },
{ "822" ,V_1x0 ,PA7000 },
{ "825" ,V_1x0 ,PA7000 },
{ "826" ,V_1x1c ,PA7100LC },
{ "827" ,V_1x1a ,PA7000 },
{ "829" ,V_1x1d ,PA7200 },
{ "831" ,V_1x1d ,PA7200 },
{ "832" ,V_1x0 ,PA7000 },
{ "834" ,V_1x0 ,PA7000 },
{ "835" ,V_1x0 ,PA7000 },
{ "837" ,V_1x1a ,PA7000 },
{ "839" ,V_1x1d ,PA7200 },
{ "840" ,V_1x0 ,PA7000 },
{ "841" ,V_1x1d ,PA7200 },
{ "842" ,V_1x0 ,PA7000 },
{ "845" ,V_1x0 ,PA7000 },
{ "847" ,V_1x1a ,PA7000 },
{ "849" ,V_1x1d ,PA7200 },
{ "850" ,V_1x0 ,PA7000 },
{ "851" ,V_1x1d ,PA7200 },
{ "852" ,V_1x0 ,PA7000 },
{ "855" ,V_1x0 ,PA7000 },
{ "856" ,V_1x1c ,PA7100LC },
{ "857" ,V_1x1a ,PA7000 },
{ "859" ,V_1x1d ,PA7200 },
{ "860" ,V_1x0 ,PA7000 },
{ "861" ,V_2x0 ,PA8000 },
{ "865" ,V_1x0 ,PA7000 },
{ "869" ,V_1x1d ,PA7200 },
{ "870" ,V_1x0 ,PA7000 },
{ "871" ,V_2x0 ,PA8000 },
{ "877" ,V_1x1a ,PA7000 },
{ "879" ,V_2x0 ,PA8000 },
{ "887" ,V_1x1b ,PA7100 },
{ "889" ,V_2x0 ,PA8000 },
{ "890" ,V_1x0 ,PA7000 },
{ "891" ,V_1x1b ,PA7100 },
{ "892" ,V_1x1b ,PA7100 },
{ "893" ,V_2x0 ,PA8000 },
{ "895" ,V_2x0 ,PA8000 },
{ "896" ,V_2x0 ,PA8000 },
{ "897" ,V_1x1b ,PA7100 },
{ "898" ,V_2x0 ,PA8200 },
{ "899" ,V_2x0 ,PA8200 },
{ "900" ,V_1x0 ,PA7000 },
{ "B115" ,V_1x1e ,PA7300 },
{ "B120" ,V_1x1e ,PA7300 },
{ "B132L" ,V_1x1e ,PA7300 },
{ "B160L" ,V_1x1e ,PA7300 },
{ "B180L" ,V_1x1e ,PA7300 },
{ "C100" ,V_1x1d ,PA7200 },
{ "C110" ,V_1x1d ,PA7200 },
{ "C115" ,V_1x1e ,PA7300 },
{ "C120" ,V_1x1e ,PA7300 },
{ "C130" ,V_2x0 ,PA8000 },
{ "C140" ,V_2x0 ,PA8000 },
{ "C160L" ,V_1x1e ,PA7300 },
{ "C160" ,V_2x0 ,PA8000 },
{ "C180L" ,V_1x1e ,PA7300 },
{ "C180-XP" ,V_2x0 ,PA8000 },
{ "C180" ,V_2x0 ,PA8000 },
{ "C200+" ,V_2x0 ,PA8200 },
{ "C230+" ,V_2x0 ,PA8200 },
{ "C240+" ,V_2x0 ,PA8200 },
{ "CB260" ,V_2x0 ,PA8200 },
{ "D200" ,V_1x1d ,PA7200 }, // or: 1.1c, PA7100LC
{ "D210" ,V_1x1d ,PA7200 }, // or: 1.1c, PA7100LC
{ "D220" ,V_1x1e ,PA7300 },
{ "D230" ,V_1x1e ,PA7300 },
{ "D250" ,V_1x1d ,PA7200 },
{ "D260" ,V_1x1d ,PA7200 },
{ "D270" ,V_2x0 ,PA8000 },
{ "D280" ,V_2x0 ,PA8000 },
{ "D310" ,V_1x1c ,PA7100LC },
{ "D320" ,V_1x1e ,PA7300 },
{ "D330" ,V_1x1e ,PA7300 },
{ "D350" ,V_1x1d ,PA7200 },
{ "D360" ,V_1x1d ,PA7200 },
{ "D370" ,V_2x0 ,PA8000 },
{ "D380" ,V_2x0 ,PA8000 },
{ "D400" ,V_1x1d ,PA7200 },
{ "D410" ,V_1x1d ,PA7200 },
{ "D650" ,V_2x0 ,PA8000 },
{ "DX0" ,V_1x1c ,PA7100LC },
{ "DX5" ,V_1x1c ,PA7100LC },
{ "DXO" ,V_1x1c ,PA7100LC },
{ "E25" ,V_1x1c ,PA7100LC },
{ "E35" ,V_1x1c ,PA7100LC },
{ "E45" ,V_1x1c ,PA7100LC },
{ "E55" ,V_1x1c ,PA7100LC },
{ "F10" ,V_1x1a ,PA7000 },
{ "F20" ,V_1x1a ,PA7000 },
{ "F30" ,V_1x1a ,PA7000 },
{ "G30" ,V_1x1a ,PA7000 },
{ "G40" ,V_1x1a ,PA7000 },
{ "G50" ,V_1x1b ,PA7100 },
{ "G60" ,V_1x1b ,PA7100 },
{ "G70" ,V_1x1b ,PA7100 },
{ "H20" ,V_1x1a ,PA7000 },
{ "H30" ,V_1x1a ,PA7000 },
{ "H40" ,V_1x1a ,PA7000 },
{ "H50" ,V_1x1b ,PA7100 },
{ "H60" ,V_1x1b ,PA7100 },
{ "H70" ,V_1x1b ,PA7100 },
{ "I30" ,V_1x1a ,PA7000 },
{ "I40" ,V_1x1a ,PA7000 },
{ "I50" ,V_1x1b ,PA7100 },
{ "I60" ,V_1x1b ,PA7100 },
{ "I70" ,V_1x1b ,PA7100 },
{ "J200" ,V_1x1d ,PA7200 },
{ "J210XC" ,V_1x1d ,PA7200 },
{ "J210" ,V_1x1d ,PA7200 },
{ "J220" ,V_2x0 ,PA8000 },
{ "J2240" ,V_2x0 ,PA8200 },
{ "J280" ,V_2x0 ,PA8000 },
{ "J282" ,V_2x0 ,PA8000 },
{ "J400" ,V_2x0 ,PA8000 },
{ "J410" ,V_2x0 ,PA8000 },
{ "K100" ,V_1x1d ,PA7200 },
{ "K200" ,V_1x1d ,PA7200 },
{ "K210" ,V_1x1d ,PA7200 },
{ "K230" ,V_1x1d ,PA7200 },
{ "K250" ,V_2x0 ,PA8000 },
{ "K260" ,V_2x0 ,PA8000 },
{ "K370" ,V_2x0 ,PA8200 },
{ "K380" ,V_2x0 ,PA8200 },
{ "K400" ,V_1x1d ,PA7200 },
{ "K410" ,V_1x1d ,PA7200 },
{ "K420" ,V_1x1d ,PA7200 },
{ "K430" ,V_1x1d ,PA7200 },
{ "K450" ,V_2x0 ,PA8000 },
{ "K460" ,V_2x0 ,PA8000 },
{ "K470" ,V_2x0 ,PA8200 },
{ "K570" ,V_2x0 ,PA8200 },
{ "K580" ,V_2x0 ,PA8200 },
{ "S700i" ,V_1x1e ,PA7300 },
{ "S715" ,V_1x1e ,PA7300 },
{ "S744" ,V_1x1e ,PA7300 },
{ "S760" ,V_1x1e ,PA7300 },
{ "T500" ,V_1x1c ,PA7100LC }, // or: 1.1b, PA7100
{ "T520" ,V_1x1b ,PA7100 },
{ "T540" ,V_2x0 ,PA8000 },
{ "T600" ,V_2x0 ,PA8000 },
{ "V2000" ,V_2x0 ,PA8000 },
{ "V2200" ,V_2x0 ,PA8200 },
{ "V2250" ,V_2x0 ,PA8200 },
{ "V2500" ,V_2x0 ,PA8500 },
{ "" ,0 ,0 } /* Last Entry has to be empty. */
};
/* Helper-Functions */
// Value() is defined in info.cpp !!!
static bool Find_in_LOOKUPTABLE( QListView *lBox, char *machine )
{ char *Machine;
int len;
const struct _type_LOOKUPTABLE *Entry = PA_LOOKUPTABLE;
QString str;
QListViewItem* olditem = 0;
Machine = machine; // machine is like: "9000/715/D"
while ((*Machine) && (*Machine!='/'))
++Machine;
if (*Machine)
++Machine;
else
Machine=machine;
len = strlen(Machine);
while (Entry->Name[0])
{ if (strncmp(Entry->Name,Machine,len)==0)
{
olditem = new QListViewItem(lBox, olditem, i18n("PA-RISC Processor"),
QString(PA_NAME[Entry->parisc_name]));
olditem = new QListViewItem(lBox, olditem, i18n("PA-RISC Revision"),
QString("PA-RISC ") + QString(PA_REVISION[Entry->parisc_rev]));
return true;
}
else
++Entry; // next Entry !
}
return false;
}
/* all following functions should return true, when the Information
was filled into the lBox-Widget.
returning false indicates, that information was not available.
*/
bool GetInfo_CPU( QListView *lBox )
{
FILE *pipe;
QFile *model;
struct pst_dynamic psd;
struct pst_static pst;
struct pst_processor pro;
struct utsname info;
QString str,str2;
QListViewItem* olditem = 0;
int maxwidth,i;
if((pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1) ||
(pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0)== -1)) {
*GetInfo_ErrorString = i18n("Could not get Information."); /* Error */
return false;
}
maxwidth = 0;
lBox->addColumn(i18n("Information") );
lBox->addColumn(i18n("Value") );
uname(&info);
olditem = new QListViewItem(lBox, olditem, i18n("Machine"), info.machine);
model = new QFile(INFO_CPU_MODEL);
if (model->exists())
{ if ((pipe = popen(INFO_CPU_MODEL, "r")))
{ QTextStream *t = new QTextStream(pipe, QIODevice::ReadOnly);
str = t->readLine();
olditem = new QListViewItem(lBox, olditem, i18n("Model"), str);
delete t;
}
delete pipe;
}
delete model;
olditem = new QListViewItem(lBox, olditem, i18n("Machine Identification Number"),
strlen(info.__idnumber) ? QString(info.__idnumber) : i18n("(none)") );
if (psd.psd_proc_cnt<=0)
psd.psd_proc_cnt=1; // Minimum one CPU !
olditem = new QListViewItem(lBox, olditem, i18n("Number of Active Processors"),
Value(psd.psd_proc_cnt));
pstat_getprocessor( &pro, sizeof(pro), 1, 0 );
olditem = new QListViewItem(lBox, olditem, i18n("CPU Clock"),
Value(pro.psp_iticksperclktick/10000) + ' ' + i18n("MHz"));
switch(sysconf(_SC_CPU_VERSION))
{ case CPU_HP_MC68020: str2 = "Motorola 68020"; break;
case CPU_HP_MC68030: str2 = "Motorola 68030"; break;
case CPU_HP_MC68040: str2 = "Motorola 68040"; break;
case CPU_PA_RISC1_0: str2 = "PA-RISC 1.0"; break;
case CPU_PA_RISC1_1: str2 = "PA-RISC 1.1"; break;
case CPU_PA_RISC1_2: str2 = "PA-RISC 1.2"; break;
case CPU_PA_RISC2_0:
#if defined(_SC_KERNEL_BITS)
switch (sysconf(_SC_KERNEL_BITS)) {
case 64: str2 = "PA-RISC 2.0w (64 bit)"; break;
case 32: str2 = "PA-RISC 2.0n (32 bit)"; break;
default: str2 = "PA-RISC 2.0"; break;
}; break;
#else /* !defined(_SC_KERNEL_BITS) */
str2 = "PA-RISC 2.0"; break;
#endif
default: str2 = i18n("(unknown)"); break;
}
olditem = new QListViewItem(lBox, olditem, i18n("CPU Architecture"), str2);
Find_in_LOOKUPTABLE( lBox, info.machine );// try to get extended Information.
for (i=PS_PA83_FPU; i<=PS_PA89_FPU; ++i) {
if ((1<<(i-1)) & pro.psp_coprocessor.psc_present) {
str = QString( (i==PS_PA83_FPU) ? "PS_PA83_FPU":"PS_PA89_FPU" )
+ QString(" (")
+ QString(((1<<(i-1))&pro.psp_coprocessor.psc_enabled) ?
i18n("enabled") : i18n("disabled") )
+ QString(")");
olditem = new QListViewItem(lBox, olditem, i18n("Numerical Coprocessor (FPU)"), str);
}
}// for(coprocessor..)
str = Value(((pst.physical_memory*pst.page_size)/1024/1024))
+ QString(" ")
+ i18n("MB"); // Mega-Byte
olditem = new QListViewItem(lBox, olditem, i18n("Total Physical Memory"), str);
str = Value(pst.page_size) + QString(" ") + i18n("Bytes");
olditem = new QListViewItem(lBox, olditem, i18n("Size of One Page"), str);
return true;
}
bool GetInfo_ReadfromFile( QListView *lBox, const char *Name )
{
char buf[2048];
QFile *file = new QFile(Name);
QListViewItem* olditem = 0;
if(!file->open(QIODevice::ReadOnly)) {
delete file;
return false;
}
while (file->readLine(buf,sizeof(buf)-1) >= 0)
{ if (strlen(buf))
olditem = new QListViewItem(lBox, olditem, QString::fromLocal8Bit(buf));
}
file->close();
delete file;
return (lBox->childCount());
}
bool GetInfo_IRQ( QListView * )
{
return false;
}
bool GetInfo_DMA( QListView * )
{
return false;
}
bool GetInfo_PCI( QListView *lBox )
{
return( GetInfo_ReadfromFile(lBox,INFO_PCI) +
GetInfo_ReadfromFile(lBox,INFO_PCI_EISA) );
}
bool GetInfo_IO_Ports( QListView *lBox )
{
if (GetInfo_ReadfromPipe( lBox, INFO_IOPORTS_1, false ))
return true;
else
return GetInfo_ReadfromPipe( lBox, INFO_IOPORTS_2, false );
}
bool GetInfo_Devices( QListView *lBox )
{
return GetInfo_ReadfromPipe( lBox, INFO_DEVICES, false );
}
bool GetInfo_SCSI( QListView *lBox )
{
return GetInfo_Devices( lBox );
}
/* Parts taken from fsusage.c from the Midnight Commander (mc)
Copyright (C) 1991, 1992 Free Software Foundation, In
Return the number of TOSIZE-byte blocks used by
BLOCKS FROMSIZE-byte blocks, rounding away from zero.
TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */
static long fs_adjust_blocks(long blocks, int fromsize, int tosize)
{
if (tosize <= 0)
abort ();
if (fromsize <= 0)
return -1;
if (fromsize == tosize) /* E.g., from 512 to 512. */
return blocks;
else if (fromsize > tosize) /* E.g., from 2048 to 512. */
return blocks * (fromsize / tosize);
else /* E.g., from 256 to 512. */
return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize);
}
/* Fill in the fields of FSP with information about space usage for
the filesystem on which PATH resides.
Return 0 if successful, -1 if not. */
#define CONVERT_BLOCKS(b) fs_adjust_blocks ((b), fsd.f_bsize, 512)
static int get_fs_usage (char *path, long *l_total, long *l_avail)
{ struct statfs fsd; /* 4.3BSD, SunOS 4, HP-UX, AIX. */
unsigned long fsu_blocks,fsu_bfree,fsu_bavail;
*l_total = *l_avail = 0;
if (statfs (path, &fsd) < 0)
return -1;
fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks);
fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree);
fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail);
*l_avail = getuid () ? fsu_bavail/2 : fsu_bfree/2;
*l_total = fsu_blocks/2;
return 0;
}
// Some Ideas taken from garbazo from his source in info_fbsd.cpp
bool GetInfo_Partitions (QListView *lbox)
{
#define NUMCOLS 5
QString Title[NUMCOLS];
int n;
struct fstab *fstab_ent;
struct statvfs svfs;
long total,avail;
QString str;
QString MB(i18n("MB")+ " "); // International Text for MB=Mega-Byte
if (setfsent() != 1) // Try to open fstab
return false;
Title[0] = i18n("Device");
Title[1] = i18n("Mount Point");
Title[2] = i18n("FS Type");
Title[3] = i18n("Total Size");
Title[4] = i18n("Free Size");
for (n=0; n<NUMCOLS; ++n) {
lbox->addColumn(Title[n] );
}
while ((fstab_ent=getfsent())!=NULL) {
/* fstab_ent->fs_type holds only "rw","xx","ro"... */
memset(&svfs,0,sizeof(svfs));
statvfs(fstab_ent->fs_file,&svfs);
get_fs_usage(fstab_ent->fs_file, &total, &avail);
if (!strcmp(fstab_ent->fs_type,FSTAB_XX)) // valid drive ?
svfs.f_basetype[0] = 0;
if(svfs.f_basetype[0]) {
new QListViewItem(lbox, QString(fstab_ent->fs_spec),
QString(fstab_ent->fs_file) + QString(" "),
(svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a")),
Value((total+512)/1024,6) + MB,
Value((avail+512)/1024,6) + MB);
}
else {
new QListViewItem(lbox, QString(fstab_ent->fs_spec),
QString(fstab_ent->fs_file) + QString(" "),
(svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a")));
}
}
endfsent();
return true;
}
bool GetInfo_XServer_and_Video( QListView *lBox )
{
lBox = lBox;
return GetInfo_XServer_Generic( lBox );
}
#ifndef HAVE_ALIB_H
bool GetInfo_Sound( QListView *lBox )
{ lBox = lBox;
*GetInfo_ErrorString = i18n("Audio-Support (Alib) was disabled during configuration and compile-time.");
return false;
}
#else // defined(HAVE_ALIB_H)
#include "Alib.h"
static const char formatNames[6][15] = {
"ADFUnknown", "ADFMuLaw", "ADFALaw",
"ADFLin16", "ADFLin8", "ADFLin8Offset" };
/* handle typo in 1st release of Alib.h */
#ifndef ARightOutputChMask
#define ARightOutputChMask ARighOutputChMask
#endif
bool GetInfo_Sound( QListView *lBox )
{
Audio *audio;
long status;
char server[80];
int i;
QString str,str2;
QListViewItem* olditem = 0;
// server = Hostname....
server[0] = 0;
audio = AOpenAudio( server, &status );
if( status ) {
*GetInfo_ErrorString = i18n("Unable to open Audio-Server (Alib).");
return false;
}
lBox->addColumn(i18n("Information") );
lBox->addColumn(i18n("Value") );
olditem = new QListViewItem(lBox, olditem, i18n("Audio Name"), QString(audio->audio_name));
olditem = new QListViewItem(lBox, olditem, i18n("Vendor"), QString(audio->vendor));
olditem = new QListViewItem(lBox, olditem, i18n("Alib Version"),
Value(audio->alib_major_version) + QString(".") +
Value(audio->alib_minor_version));
olditem = new QListViewItem(lBox, olditem, i18n("Protocol Revision"),
Value(audio->proto_major_version) + QString(".") +
Value(audio->proto_minor_version));
olditem = new QListViewItem(lBox, olditem, i18n("Vendor Number"),
Value(audio->vnumber));
olditem = new QListViewItem(lBox, olditem, i18n("Release"),
Value(audio->release));
olditem = new QListViewItem(lBox, olditem, i18n("Byte Order"),
QString((audio->byte_order==ALSBFirst)? i18n("ALSBFirst (LSB)"):
((audio->byte_order==AMSBFirst)? i18n("AMSBFirst (MSB)"):
i18n("Invalid Byteorder.")) ));
olditem = new QListViewItem(lBox, olditem, i18n("Bit Order"),
QString((audio->sound_bit_order==ALeastSignificant)?
i18n("ALeastSignificant (LSB)") :
((audio->sound_bit_order==AMostSignificant) ?
i18n("AMostSignificant (MSB)"):i18n("Invalid Bitorder.")) ));
olditem = new QListViewItem(lBox, olditem, i18n("Data Formats"));
for ( i = 0; i < audio->n_data_format; i++ ) {
if (audio->data_format_list[i] <= ADFLin8Offset)
new QListViewItem(olditem, QString(formatNames[audio->data_format_list[i]]));
}
olditem->setOpen(true);
olditem = new QListViewItem(lBox, olditem, i18n("Sampling Rates"));
for ( i = 0; i < audio->n_sampling_rate; i++ ) {
new QListViewItem(olditem, Value(audio->sampling_rate_list[i]));
}
olditem->setOpen(true);
olditem = new QListViewItem(lBox, olditem, i18n("Input Sources"));
if ( audio->input_sources & AMonoMicrophoneMask )
new QListViewItem(olditem, i18n("Mono-Microphone"));
if ( audio->input_sources & AMonoAuxiliaryMask )
new QListViewItem(olditem, i18n("Mono-Auxiliary"));
if ( audio->input_sources & ALeftMicrophoneMask )
new QListViewItem(olditem, i18n("Left-Microphone"));
if ( audio->input_sources & ARightMicrophoneMask )
new QListViewItem(olditem, i18n("Right-Microphone"));
if ( audio->input_sources & ALeftAuxiliaryMask )
new QListViewItem(olditem, i18n("Left-Auxiliary"));
if ( audio->input_sources & ARightAuxiliaryMask )
new QListViewItem(olditem, i18n("Right-Auxiliary"));
olditem->setOpen(true);
olditem = new QListViewItem(lBox, olditem,i18n("Input Channels"));
if ( audio->input_channels & AMonoInputChMask )
new QListViewItem(olditem, i18n("Mono-Channel"));
if ( audio->input_channels & ALeftInputChMask )
new QListViewItem(olditem, i18n("Left-Channel"));
if ( audio->input_channels & ARightInputChMask )
new QListViewItem(olditem, i18n("Right-Channel"));
olditem->setOpen(true);
olditem = new QListViewItem(lBox, olditem, i18n("Output Destinations"));
if ( audio->output_destinations & AMonoIntSpeakerMask )
new QListViewItem(olditem, i18n("Mono-InternalSpeaker"));
if ( audio->output_destinations & AMonoJackMask )
new QListViewItem(olditem, i18n("Mono-Jack"));
if ( audio->output_destinations & ALeftIntSpeakerMask )
new QListViewItem(olditem, i18n("Left-InternalSpeaker"));
if ( audio->output_destinations & ARightIntSpeakerMask )
new QListViewItem(olditem, i18n("Right-InternalSpeaker"));
if ( audio->output_destinations & ALeftJackMask )
new QListViewItem(olditem, i18n("Left-Jack"));
if ( audio->output_destinations & ARightJackMask )
new QListViewItem(olditem, i18n("Right-Jack"));
olditem->setOpen(true);
olditem = new QListViewItem(lBox, olditem, i18n("Output Channels"));
if ( audio->output_channels & AMonoOutputChMask )
new QListViewItem(olditem, i18n("Mono-Channel"));
if ( audio->output_channels & ALeftOutputChMask )
new QListViewItem(olditem, i18n("Left-Channel"));
if ( audio->output_channels & ARightOutputChMask )
new QListViewItem(olditem, i18n("Right-Channel"));
olditem->setOpen(true);
olditem = new QListViewItem(lBox, olditem, i18n("Gain"));
new QListViewItem(olditem, i18n("Input Gain Limits"),
Value(audio->max_input_gain));
new QListViewItem(olditem,i18n("Output Gain Limits"),
Value(audio->min_output_gain) + QString(" ")
+ Value(audio->max_output_gain));
new QListViewItem(olditem, i18n("Monitor Gain Limits"),
Value(audio->min_monitor_gain) + QString(" ")
+ Value(audio->max_monitor_gain));
new QListViewItem(olditem, i18n("Gain Restricted"),
Value(audio->gm_gain_restricted));
olditem->setOpen(true);
olditem = new QListViewItem(lBox, olditem,i18n("Lock"),
Value(audio->lock));
olditem = new QListViewItem(lBox, olditem, i18n("Queue Length"),
Value(audio->qlen));
olditem = new QListViewItem(lBox, olditem, i18n("Block Size"),
Value(audio->block_size));
olditem = new QListViewItem(lBox, olditem, i18n("Stream Port (decimal)"),
Value(audio->stream_port));
olditem = new QListViewItem(lBox, olditem, i18n("Ev Buffer Size"),
Value(audio->ev_buf_size));
olditem = new QListViewItem(lBox, olditem, i18n("Ext Number"),
Value(audio->ext_number));
ACloseAudio( audio, &status );
return true;
}
#endif // defined(HAVE_ALIB_H)

View file

@ -1,541 +0,0 @@
/*
Linux-specific Information about the Hardware.
(C) Copyright 1998-2001 by Helge Deller <deller@gmx.de>
To do (maybe?):
- include Information about XFree86 and/or Accelerated X
(needs to change configure-script, to see, if Header-files are available !)
- maybe also include information about the video-framebuffer devices
- rewrite detection-routines (maybe not to use the /proc-fs)
- more & better sound-information
/dev/sndstat support added: 1998-12-08 Duncan Haldane (f.d.m.haldane@cwix.com)
*/
#include <unistd.h>
#include <syscall.h>
#include <stdio.h>
#include <sys/stat.h>
#include <linux/kernel.h>
#include <ctype.h>
#include "config-infocenter.h"
#ifdef HAVE_FSTAB_H /* some Linux-versions don't have fstab.h */
# include <fstab.h>
# include <sys/statfs.h>
# define INFO_PARTITIONS_FULL_INFO /* show complete info */
#elif defined HAVE_MNTENT_H /* but maybe they have mntent.h ? */
# include <mntent.h>
# include <sys/vfs.h>
# define INFO_PARTITIONS_FULL_INFO /* show complete info */
#else
# undef INFO_PARTITIONS_FULL_INFO /* no partitions-info */
#endif
#include <QRegExp>
#include <kiconloader.h>
#define INFO_CPU_AVAILABLE
#define INFO_CPU "/proc/cpuinfo"
#define INFO_IRQ_AVAILABLE
#define INFO_IRQ "/proc/interrupts"
#define INFO_DMA_AVAILABLE
#define INFO_DMA "/proc/dma"
#define INFO_PCI_AVAILABLE
#define INFO_PCI "/proc/pci"
#define INFO_IOPORTS_AVAILABLE
#define INFO_IOPORTS "/proc/ioports"
#define INFO_SOUND_AVAILABLE
#define INFO_DEV_SNDSTAT "/dev/sndstat"
#define INFO_SOUND "/proc/sound"
#define INFO_ASOUND "/proc/asound/oss/sndstat"
#define INFO_ASOUND09 "/proc/asound/sndstat"
#define INFO_DEVICES_AVAILABLE
#define INFO_DEVICES "/proc/devices"
#define INFO_MISC "/proc/misc"
#define INFO_SCSI_AVAILABLE
#define INFO_SCSI "/proc/scsi/scsi"
#define INFO_PARTITIONS_AVAILABLE
#define INFO_PARTITIONS "/proc/partitions"
#define INFO_MOUNTED_PARTITIONS "/etc/mtab" /* on Linux... */
#define INFO_XSERVER_AVAILABLE
#define MAXCOLUMNWIDTH 600
bool GetInfo_ReadfromFile(Q3ListView * lbox, const char *FileName,
const QChar& splitChar,
Q3ListViewItem * lastitem = 0,
Q3ListViewItem ** newlastitem = 0)
{
bool added = false;
QFile file(FileName);
if (!file.exists()) {
return false;
}
if (!file.open(QIODevice::ReadOnly)) {
/* *GetInfo_ErrorString =
i18n("You do not have read-access to the file %1.\nPlease ask your system administrator for advice.")
.arg(FileName);
*/
return false;
}
QTextStream stream(&file);
QString line = stream.readLine();
while (!line.isNull()) {
QString s1, s2;
if (!line.isEmpty()) {
if (!splitChar.isNull()) {
int pos = line.indexOf(splitChar);
s1 = line.left(pos-1).trimmed();
s2 = line.mid(pos+1).trimmed();
}
else
s1 = line;
}
lastitem = new Q3ListViewItem(lbox, lastitem, s1, s2);
added = true;
line = stream.readLine();
}
file.close();
if (newlastitem)
*newlastitem = lastitem;
return added;
}
bool GetInfo_CPU(Q3ListView * lBox)
{
lBox->addColumn(i18n("Information"));
lBox->addColumn(i18n("Value"));
return GetInfo_ReadfromFile(lBox, INFO_CPU, ':');
}
bool GetInfo_IRQ(Q3ListView * lBox)
{
lBox->setFont(KGlobalSettings::fixedFont());
return GetInfo_ReadfromFile(lBox, INFO_IRQ, 0);
}
bool GetInfo_DMA(Q3ListView * lBox)
{
QFile file(INFO_DMA);
lBox->addColumn(i18n("DMA-Channel"));
lBox->addColumn(i18n("Used By"));
if (file.exists() && file.open(QIODevice::ReadOnly)) {
QTextStream stream(&file);
QString line;
Q3ListViewItem *child=0L;
line = stream.readLine();
while (!line.isNull()) {
if (!line.isEmpty()) {
QRegExp rx("^\\s*(\\S+)\\s*:\\s*(\\S+)");
if (-1 != rx.indexIn(line)) {
child = new Q3ListViewItem(lBox,child,rx.cap(1),rx.cap(2));
}
}
line = stream.readLine();
}
file.close();
} else {
return false;
}
return true;
}
bool GetInfo_PCI(Q3ListView * lBox)
{
int num;
sorting_allowed = false; /* no sorting by user */
/* ry to get the output of the lspci package first */
if ((num = GetInfo_ReadfromPipe(lBox, "lspci -v", true)) ||
(num = GetInfo_ReadfromPipe(lBox, "/sbin/lspci -v", true)) ||
(num = GetInfo_ReadfromPipe(lBox, "/usr/sbin/lspci -v", true)) ||
(num = GetInfo_ReadfromPipe(lBox, "/usr/local/sbin/lspci -v", true)) ||
(num = GetInfo_ReadfromPipe(lBox, "/usr/bin/lspci -v", true)))
return num;
/* if lspci failed, read the contents of /proc/pci */
return GetInfo_ReadfromFile(lBox, INFO_PCI, 0);
}
bool GetInfo_IO_Ports(Q3ListView * lBox)
{
lBox->addColumn(i18n("I/O-Range"));
lBox->addColumn(i18n("Used By"));
return GetInfo_ReadfromFile(lBox, INFO_IOPORTS, ':');
}
bool GetInfo_Sound(Q3ListView * lBox)
{
sorting_allowed = false; /* no sorting by user */
if (GetInfo_ReadfromFile(lBox, INFO_DEV_SNDSTAT, 0))
return true;
else if (GetInfo_ReadfromFile(lBox, INFO_SOUND, 0))
return true;
else if (GetInfo_ReadfromFile(lBox, INFO_ASOUND, 0))
return true;
else
return GetInfo_ReadfromFile(lBox, INFO_ASOUND09, 0);
}
bool GetInfo_Devices(Q3ListView * lBox)
{
QFile file;
Q3ListViewItem *misc=0L;
lBox->setRootIsDecorated(true);
lBox->addColumn(i18n("Devices"));
lBox->addColumn(i18n("Major Number"));
lBox->addColumn(i18n("Minor Number"));
file.setFileName(INFO_DEVICES);
if (file.exists() && file.open(QIODevice::ReadOnly)) {
QTextStream stream(&file);
Q3ListViewItem *parent=0L, *child=0L;
QString line = stream.readLine();
while (!line.isNull()) {
if (!line.isEmpty()) {
if (-1 != line.indexOf("character device",0,Qt::CaseInsensitive)) {
parent = new Q3ListViewItem(lBox,parent,i18n("Character Devices"));
parent->setPixmap(0,SmallIcon("chardevice"));
parent->setOpen(true);
} else if (-1 != line.indexOf("block device",0,Qt::CaseInsensitive)) {
parent = new Q3ListViewItem(lBox,parent,i18n("Block Devices"));
parent->setPixmap(0,SmallIcon("blockdevice"));
parent->setOpen(true);
} else {
QRegExp rx("^\\s*(\\S+)\\s+(\\S+)");
if (-1 != rx.indexIn(line)) {
if (parent) {
child = new Q3ListViewItem(parent,child,rx.cap(2),rx.cap(1));
} else {
child = new Q3ListViewItem(lBox,parent,rx.cap(2),rx.cap(1));
}
if (rx.cap(2)=="misc") {
misc=child;
}
}
}
}
line = stream.readLine();
}
file.close();
} else {
return false;
}
file.setFileName(INFO_MISC);
if (misc && file.exists() && file.open(QIODevice::ReadOnly)) {
QTextStream stream(&file);
Q3ListViewItem *child=0L;
misc->setText(0,i18n("Miscellaneous Devices"));
misc->setPixmap(0,SmallIcon("memory"));
misc->setOpen(true);
QString line = stream.readLine();
while (!line.isNull()) {
if (!line.isEmpty()) {
QRegExp rx("^\\s*(\\S+)\\s+(\\S+)");
if (-1 != rx.indexIn(line)) {
child = new Q3ListViewItem(misc,child,rx.cap(2),"10",rx.cap(1));
}
}
line = stream.readLine();
}
file.close();
}
return true;
}
bool GetInfo_SCSI(Q3ListView * lBox)
{
return GetInfo_ReadfromFile(lBox, INFO_SCSI, 0);
}
static void cleanPassword(QString & str)
{
int index = 0;
QString passwd("password=");
while (index >= 0)
{
index = str.indexOf(passwd, index, Qt::CaseInsensitive);
if (index >= 0) {
index += passwd.length();
while (index < (int) str.length() &&
str[index] != ' ' && str[index] != ',')
str[index++] = '*';
}
}
}
#ifndef INFO_PARTITIONS_FULL_INFO
bool GetInfo_Partitions(Q3ListView * lBox)
{
return GetInfo_ReadfromFile(lBox, INFO_PARTITIONS, 0);
}
#else /* INFO_PARTITIONS_FULL_INFO */
// Some Ideas taken from garbazo from his source in info_fbsd.cpp
#if ( defined(HAVE_LINUX_RAW_H) || defined(HAVE_SYS_RAW_H) ) && defined(HAVE_SYS_IOCTL_H) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
#include <sys/ioctl.h>
#include <fcntl.h>
#if defined(HAVE_SYS_RAW_H)
#include <sys/raw.h>
#elif defined(HAVE_LINUX_RAW_H)
#include <linux/raw.h>
#endif
/*
* get raw device bindings and information
*/
void Get_LinuxRawDevices(Q3ListView *lbox)
{
int f, i, err;
int new_raw_devs = 1;
struct raw_config_request rq;
QString devname;
QString MB(i18n("MB")); /* "MB" = "Mega-Byte" */
/* try to open the raw device control file */
f = open("/dev/rawctl", O_RDWR);
if (f == -1) {
f = open("/dev/raw", O_RDWR);
new_raw_devs = 0;
}
if (f == -1)
return;
for (i=1; i<256; i++) {
rq.raw_minor = i;
if (ioctl(f, RAW_GETBIND, &rq))
continue;
if (!rq.block_major) /* unbound ? */
continue;
unsigned int minor = rq.block_minor;
char first_letter;
switch ((int)rq.block_major) {
/* IDE drives */
case 3: first_letter = 'a';
set_ide_name:
devname = QString("/dev/hd%1%2")
.arg(QChar(first_letter + minor/64))
.arg(minor&63);
break;
case 22:first_letter = 'c'; goto set_ide_name;
case 33:first_letter = 'e'; goto set_ide_name;
case 34:first_letter = 'g'; goto set_ide_name;
case 56:first_letter = 'i'; goto set_ide_name;
case 57:first_letter = 'k'; goto set_ide_name;
case 88:first_letter = 'm'; goto set_ide_name;
case 89:first_letter = 'o'; goto set_ide_name;
case 90:first_letter = 'q'; goto set_ide_name;
case 91:first_letter = 's'; goto set_ide_name;
/* SCSI drives */
case 8: first_letter = 'a';
set_scsi_name:
devname = QString("/dev/sd%1%2")
.arg(QChar(first_letter + minor/16))
.arg(minor&15);
break;
case 65:first_letter = 'q'; goto set_scsi_name;
/* Compaq /dev/cciss devices */
case 104: case 105: case 106:
case 107: case 108: case 109:
devname = QString("/dev/cciss/c%1d%2")
.arg((int)rq.block_major-104)
.arg(minor&15);
break;
/* Compaq Intelligent Drive Array (ida) */
case 72: case 73: case 74: case 75:
case 76: case 77: case 78: case 79:
devname = QString("/dev/ida/c%1d%2")
.arg((int)rq.block_major-72)
.arg(minor&15);
break;
default: devname = QString("%1/%2")
.arg((int)rq.block_major)
.arg(minor);
}
/* TODO: get device size */
QString size = "";
new Q3ListViewItem(lbox, devname,
QString(new_raw_devs ? "/dev/raw/raw%1" : "/dev/raw%1").arg(i),
"raw", size, " ", "");
}
close(f);
}
#else
#define Get_LinuxRawDevices(x) /* nothing */
#endif
bool GetInfo_Partitions(Q3ListView * lbox)
{
#define NUMCOLS 6
QString Title[NUMCOLS];
QStringList Mounted_Partitions;
bool found_in_List;
int n;
#ifdef HAVE_FSTAB_H
struct fstab *fstab_ent;
# define FS_NAME fstab_ent->fs_spec // device-name
# define FS_FILE fstab_ent->fs_file // mount-point
# define FS_TYPE fstab_ent->fs_vfstype // fs-type
# define FS_MNTOPS fstab_ent->fs_mntops // mount-options
#else
struct mntent *mnt_ent;
FILE *fp;
# define FS_NAME mnt_ent->mnt_fsname // device-name
# define FS_FILE mnt_ent->mnt_dir // mount-point
# define FS_TYPE mnt_ent->mnt_type // fs-type
# define FS_MNTOPS mnt_ent->mnt_opts // mount-options
#endif
struct statfs sfs;
quint64 total, avail;
QString str, mountopts;
QString MB(i18n("MB")); /* "MB" = "Mega-Byte" */
#ifdef HAVE_FSTAB_H
if (setfsent() == 0) /* Try to open fstab */
return false;
#else
if (!(fp = setmntent("/etc/fstab", "r")))
return false;
#endif
/* read the list of already mounted file-systems.. */
QFile *file = new QFile(INFO_MOUNTED_PARTITIONS);
if (file->open(QIODevice::ReadOnly)) {
char buf[1024];
while (file->readLine(buf, sizeof( buf )) > 0) {
str = QString::fromLocal8Bit(buf);
if (str.length()) {
int p = str.indexOf(' '); /* find first space. */
if (p)
str.remove(p, 1024); /* erase all chars including space. */
Mounted_Partitions.append(str);
}
}
file->close();
}
delete file;
/* create the header-tables */
MB = QString(" ") + MB;
Title[0] = i18n("Device");
Title[1] = i18n("Mount Point");
Title[2] = i18n("FS Type");
Title[3] = i18n("Total Size");
Title[4] = i18n("Free Size");
Title[5] = i18n("Mount Options");
for (n = 0; n < NUMCOLS; ++n)
lbox->addColumn(Title[n]);
/* loop through all partitions... */
#ifdef HAVE_FSTAB_H
while ((fstab_ent = getfsent()) != NULL)
#else
while ((mnt_ent = getmntent(fp)) != NULL)
#endif
{
total = avail = 0; /* initialize size.. */
found_in_List = (Mounted_Partitions.contains(FS_NAME) > 0);
if (found_in_List && statfs(FS_FILE, &sfs) == 0) {
total = ((quint64) sfs.f_blocks) * sfs.f_bsize;
avail = (getuid()? sfs.f_bavail : sfs.f_bfree)
* ((quint64) sfs.f_bsize);
};
/*
if (stat(fstab_ent->fs_file,&st)!=0)
total = 0;
if (!S_ISDIR(st.st_mode))
total = 0;
*/
mountopts = FS_MNTOPS;
cleanPassword(mountopts);
if (total)
new Q3ListViewItem(lbox, QString(FS_NAME) + " ",
QString(FS_FILE) + " ",
QString(FS_TYPE) + " ",
Value((int) (((total / 1024) + 512) / 1024),
6) + MB,
Value((int) (((avail / 1024) + 512) / 1024),
6) + MB, mountopts);
else
new Q3ListViewItem(lbox, QString(FS_NAME), QString(FS_FILE),
QString(FS_TYPE), " ", " ", mountopts);
}
#ifdef HAVE_FSTAB_H
endfsent(); /* close fstab.. */
#else
endmntent(fp); /* close fstab.. */
#endif
/* get raw device entires if available... */
Get_LinuxRawDevices(lbox);
sorting_allowed = true; /* sorting by user allowed ! */
lbox->setSorting(1);
return true;
}
#endif /* INFO_PARTITIONS_FULL_INFO */
bool GetInfo_XServer_and_Video(Q3ListView * lBox)
{
return GetInfo_XServer_Generic(lBox);
}

View file

@ -1,313 +0,0 @@
/*
* info_netbsd.cpp is part of the KDE program kcminfo. This displays
* various information about the OpenBSD system it's running on.
*
* Originally written by Jaromir Dolecek <dolecek@ics.muni.cz>. CPU info
* code has been imported from implementation of processor.cpp for KDE 1.0
* by David Brownlee <abs@NetBSD.org> as found in NetBSD packages collection.
* Hubert Feyer <hubertf@NetBSD.org> enhanced the sound information printing
* quite a lot, too.
*
* The code is placed into public domain. Do whatever you want with it.
*/
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_PCI_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
/*
* all following functions should return true, when the Information
* was filled into the lBox-Widget. Returning false indicates that
* information was not available.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <stdio.h> /* for NULL */
#include <stdlib.h> /* for malloc(3) */
#include <QFile>
#include <QFontMetrics>
#include <Q3StrList>
#include <QTextStream>
#include <kdebug.h>
typedef struct
{
int string;
int name;
const char *title;
} hw_info_mib_list_t;
bool GetInfo_CPU(Q3ListView *lBox)
{
static hw_info_mib_list_t hw_info_mib_list[]= {
{ 1, HW_MODEL, "Model" },
{ 1, HW_MACHINE, "Machine" },
{ 0, HW_NCPU, "Number of CPUs" },
{ 0, HW_PAGESIZE, "Pagesize" },
{ 0,0,0 }
};
hw_info_mib_list_t *hw_info_mib;
int mib[2], num;
char *buf;
size_t len;
QString value;
lBox->addColumn(i18n("Information"));
lBox->addColumn(i18n("Value"));
for ( hw_info_mib = hw_info_mib_list ; hw_info_mib->title ; ++hw_info_mib )
{
mib[0] = CTL_HW;
mib[1] = hw_info_mib->name;
if ( hw_info_mib->string ) {
sysctl(mib,2,NULL,&len,NULL,0);
if ( (buf = (char*)malloc(len)) ) {
sysctl(mib,2,buf,&len,NULL,0);
value = QString::fromLocal8Bit(buf);
free(buf);
}
else {
value = QString("Unknown");
}
}
else {
len = sizeof(num);
sysctl(mib,2,&num,&len,NULL,0);
value.sprintf("%d", num);
}
new Q3ListViewItem(lBox, hw_info_mib->title, value);
}
return true;
}
// this is used to find out which devices are currently
// on system
static bool GetDmesgInfo(Q3ListView *lBox, const char *filter,
void func(Q3ListView *, QString s, void **, bool))
{
QFile *dmesg = new QFile("/var/run/dmesg.boot");
bool usepipe=false;
FILE *pipe=NULL;
QTextStream *t;
bool seencpu=false;
void *opaque=NULL;
QString s;
bool found=false;
if (dmesg->exists() && dmesg->open(QIODevice::ReadOnly)) {
t = new QTextStream(dmesg);
}
else {
delete dmesg;
pipe = popen("/sbin/dmesg", "r");
if (!pipe) return false;
usepipe = true;
t = new QTextStream(pipe, QIODevice::ReadOnly);
}
Q3ListViewItem *olditem = NULL;
while(!(s = t->readLine()).isNull()) {
if (!seencpu) {
if (s.contains("cpu"))
seencpu = true;
else
continue;
}
if (s.contains("boot device") ||
s.contains("WARNING: old BSD partition ID!"))
break;
if (!filter || s.contains(filter)) {
if (func) {
func(lBox, s, &opaque, false);
}
else {
olditem = new Q3ListViewItem(lBox, olditem, s);
}
found = true;
}
}
if (func) {
func(lBox, s, &opaque, true);
}
//lBox->triggerUpdate();
delete t;
if (pipe) {
pclose(pipe);
}
else {
dmesg->close();
delete dmesg;
}
return found;
}
void AddIRQLine(Q3ListView *lBox, QString s, void **opaque, bool ending)
{
Q3StrList *strlist = (Q3StrList *) *opaque;
const char *str;
int pos, irqnum=0;
const char *p;
p = s.toLatin1();
if (!strlist) {
strlist = new Q3StrList();
*opaque = (void *) strlist;
}
if (ending) {
str = strlist->first();
for(;str; str = strlist->next()) {
new Q3ListViewItem(lBox, str);
}
delete strlist;
return;
}
pos = s.find(" irq ");
irqnum = (pos < 0) ? 0 : atoi(&p[pos+5]);
if (irqnum) {
s.sprintf("%02d%s", irqnum, p);
}
else {
s.sprintf("??%s", p);
}
strlist->inSort(s.toLatin1());
}
bool GetInfo_IRQ (Q3ListView *lBox)
{
lBox->addColumn(i18n("IRQ"));
lBox->addColumn(i18n("Device"));
(void) GetDmesgInfo(lBox, " irq ", AddIRQLine);
return true;
}
bool GetInfo_DMA (Q3ListView *)
{
return false;
}
bool GetInfo_PCI (Q3ListView *lbox)
{
if (!GetDmesgInfo(lbox, "at pci", NULL))
new Q3ListViewItem(lbox, i18n("No PCI devices found."));
return true;
}
bool GetInfo_IO_Ports (Q3ListView *lbox)
{
if (!GetDmesgInfo(lbox, "port 0x", NULL))
new Q3ListViewItem(lbox, i18n("No I/O port devices found."));
return true;
}
bool GetInfo_Sound (Q3ListView *lbox)
{
if (!GetDmesgInfo(lbox, "audio", NULL))
new Q3ListViewItem(lbox, i18n("No audio devices found."));
// append information on any audio devices found
Q3ListViewItem *lvitem = lbox->firstChild();
for(; lvitem; lvitem = lvitem->nextSibling()) {
QString s;
int pos, len;
const char *start, *end;
char *dev;
s = lvitem->text(0);
if ((pos = s.find("at ")) >= 0) {
pos += 3; // skip "at "
start = end = s.toAscii();
for(; *end && (*end!=':') && (*end!='\n'); end++);
len = end - start;
dev = (char *) malloc(len + 1);
strncpy(dev, start, len);
dev[len] = '\0';
GetDmesgInfo(lbox, dev, NULL);
free(dev);
}
}
return true;
}
bool GetInfo_Devices (Q3ListView *lBox)
{
(void) GetDmesgInfo(lBox, NULL, NULL);
return true;
}
bool GetInfo_SCSI (Q3ListView *lbox)
{
if (!GetDmesgInfo(lbox, "scsibus", NULL))
new Q3ListViewItem(lbox, i18n("No SCSI devices found."));
return true;
}
bool GetInfo_Partitions (Q3ListView *lbox)
{
QString s;
char *line, *orig_line;
const char *device, *mountpoint, *type, *flags;
FILE *pipe = popen("/sbin/mount", "r");
QTextStream *t;
if (!pipe) {
kError(0) << i18n("Unable to run /sbin/mount.") << endl;
return false;
}
t = new QTextStream(pipe, QIODevice::ReadOnly);
lbox->addColumn(i18n("Device"));
lbox->addColumn(i18n("Mount Point"));
lbox->addColumn(i18n("FS Type"));
lbox->addColumn(i18n("Mount Options"));
Q3ListViewItem *olditem = 0;
while (!(s = t->readLine()).isNull()) {
orig_line = line = strdup(s.toLatin1());
device = strsep(&line, " ");
(void) strsep(&line, " "); // consume word "on"
mountpoint = strsep(&line, " ");
(void) strsep(&line, " "); // consume word "type"
type = strsep(&line, " ");
flags = line;
olditem = new Q3ListViewItem(lbox, olditem, device, mountpoint,
type, flags);
free(orig_line);
}
delete t;
pclose(pipe);
return true;
}
bool GetInfo_XServer_and_Video (Q3ListView *lBox)
{
return GetInfo_XServer_Generic( lBox );
}

View file

@ -1,82 +0,0 @@
/* info_sgi.cpp
!!!!! this file will be included by info.cpp !!!!!
*/
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_PCI_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
/* all following functions should return true, when the Information
was filled into the lBox-Widget.
returning false indicates, that information was not available.
*/
#include <sys/systeminfo.h>
bool GetInfo_CPU( QListView *lBox )
{
QString str;
char buf[256];
sysinfo(SI_ARCHITECTURE, buf, sizeof(buf));
str = QString::fromLocal8Bit(buf);
new QListViewItem(lBox, str);
return true;
}
bool GetInfo_IRQ( QListView * )
{
return false;
}
bool GetInfo_DMA( QListView * )
{
return false;
}
bool GetInfo_PCI( QListView * )
{
return false;
}
bool GetInfo_IO_Ports( QListView * )
{
return false;
}
bool GetInfo_Sound( QListView * )
{
return false;
}
bool GetInfo_Devices( QListView * )
{
return false;
}
bool GetInfo_SCSI( QListView * )
{
return false;
}
bool GetInfo_Partitions( QListView * )
{
return false;
}
bool GetInfo_XServer_and_Video( QListView *lBox )
{
return GetInfo_XServer_Generic( lBox );
}

View file

@ -1,707 +0,0 @@
/*
* info_solaris.cpp
*
* Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
*/
#include "config-infocenter.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/mnttab.h>
#include <kstat.h>
#include <sys/types.h>
#include <sys/statvfs.h>
#include <time.h>
#ifdef HAVE_LIBDEVINFO_H
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <sys/mkdev.h>
#include <sys/stat.h>
#include <devid.h>
#include <libdevinfo.h>
#endif /* HAVE_LIBDEVINFO_H */
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_PCI_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
bool GetInfo_CPU( Q3ListView *lBox ) {
kstat_ctl_t *kctl;
kstat_t *ksp;
kstat_named_t *kdata;
char cputype[16],
fputype[16];
char *timetxt;
char *ptr;
uint32_t i, ncpus;
unsigned long state_begin;
QString state;
QString mhz;
QString inst;
/*
* get a kstat handle first and update the user's kstat chain
*/
if( (kctl = kstat_open()) == NULL ) {
return false;
}
while( kstat_chain_update( kctl ) != 0 )
;
/*
* get the # of CPUs
*/
if( (ksp = kstat_lookup( kctl, "unix", 0, "system_misc" )) == NULL ) {
return false;
}
if( kstat_read( kctl, ksp, NULL ) == -1 ) {
return false;
}
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "ncpus" );
if( kdata != NULL ) {
ncpus = kdata->value.ui32;
} else {
ncpus = 0;
}
lBox->addColumn( i18n( "Instance" ));
lBox->addColumn( i18n( "CPU Type" ));
lBox->addColumn( i18n( "FPU Type" ));
lBox->addColumn( i18n( "MHz" ));
lBox->addColumn( i18n( "State" ));
/*
* get the per-processor info
*/
for( i = 0; i < ncpus; i++ ) {
if( (ksp = kstat_lookup( kctl, "cpu_info", i, NULL )) == NULL ){
return false;
}
if( kstat_read( kctl, ksp, NULL ) == -1 ) {
return false;
}
inst.setNum( i );
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "cpu_type" );
if( kdata != NULL ) {
strcpy( cputype, kdata->value.c );
} else {
sprintf( cputype, "???" );
}
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "fpu_type" );
if( kdata != NULL ) {
strcpy( fputype, kdata->value.c );
} else {
sprintf( fputype, "???" );
}
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "clock_MHz" );
if( kdata != NULL ) {
mhz.setNum( kdata->value.ul );
} else {
mhz.setNum( 0 );
}
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "state" );
if( kdata != NULL ) {
state = QString( kdata->value.c );
} else {
state = "???";
}
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "state_begin" );
if( kdata != NULL ) {
state_begin = kdata->value.i32;
if( (timetxt = ctime( (time_t *) &state_begin )) != NULL ) {
ptr = strrchr( timetxt, '\n' );
*ptr = '\0';
state += " since " + QString( timetxt );
}
}
new Q3ListViewItem( lBox, inst, cputype, fputype, mhz, state );
}
// sorting_allowed = true;
lBox->setSorting( 0 );
return true;
}
bool GetInfo_IRQ( Q3ListView * ) {
return false;
}
bool GetInfo_DMA( Q3ListView * ) {
return false;
}
bool GetInfo_PCI( Q3ListView * ) {
return false;
}
bool GetInfo_IO_Ports( Q3ListView * ) {
return false;
}
bool GetInfo_Sound( Q3ListView * ) {
return false;
}
bool GetInfo_SCSI( Q3ListView * ) {
return false;
}
bool GetInfo_Partitions( Q3ListView *lBox ) {
FILE *mnttab;
struct mnttab mnt;
struct statvfs statbuf;
fsblkcnt_t tmp;
QString total;
QString avail;
time_t mnttime;
char *timetxt;
char *ptr;
if( (mnttab = fopen( MNTTAB, "r" )) == NULL ) {
return false;
}
/*
* set up column headers
*/
lBox->addColumn( i18n( "Device" ));
lBox->addColumn( i18n( "Mount Point" ));
lBox->addColumn( i18n( "FS Type" ));
lBox->addColumn( i18n( "Total Size" ));
// XXX: FIXME: how do I set column alignment correctly?
lBox->setColumnAlignment( 3, 2 );
lBox->addColumn( i18n( "Free Size" ));
// XXX: FIXME: how do I set column alignment correctly?
lBox->setColumnAlignment( 4, 2 );
lBox->addColumn( i18n( "Mount Time" ));
lBox->addColumn( i18n( "Mount Options" ));
/*
* get info about mounted file systems
*/
rewind( mnttab );
while( getmntent( mnttab, &mnt ) == 0 ) {
/*
* skip fstype "nfs" and "autofs" for two reasons:
* o if the mountpoint is visible, the fs is not
* necessarily available (autofs option "-nobrowse")
* and we don't want to mount every remote fs just
* to get its size, do we?
* o the name "Partitions" for this statistics implies
* "local file systems only"
*/
if( (strcmp( mnt.mnt_fstype, "nfs" ) == 0)
|| (strcmp( mnt.mnt_fstype, "autofs" ) == 0) )
continue;
if( statvfs( mnt.mnt_mountp, &statbuf ) == 0 ) {
if( statbuf.f_blocks > 0 ) {
/*
* produce output in KB, MB, or GB for
* readability -- unfortunately, this
* breaks sorting for these columns...
*/
tmp = statbuf.f_blocks
* (statbuf.f_frsize / 1024);
if( tmp > 9999 ) {
tmp /= 1024;
if( tmp > 9999 ) {
tmp /= 1024;
total.setNum( tmp );
total += " G";
} else {
total.setNum( tmp );
total += " M";
}
} else {
total.setNum( tmp );
total += " K";
}
// avail.setNum( statbuf.f_bavail );
// avail += " K";
tmp = statbuf.f_bavail
* (statbuf.f_frsize / 1024);
if( tmp > 9999 ) {
tmp /= 1024;
if( tmp > 9999 ) {
tmp /= 1024;
avail.setNum( tmp );
avail += " G";
} else {
avail.setNum( tmp );
avail += " M";
}
} else {
avail.setNum( tmp );
avail += " K";
}
} else {
total = "-";
avail = "-";
}
} else {
total = "???";
avail = "???";
}
/*
* ctime() adds a '\n' which we have to remove
* so that we get a one-line output for the Q3ListViewItem
*/
mnttime = (time_t) atol( mnt.mnt_time );
if( (timetxt = ctime( &mnttime )) != NULL ) {
ptr = strrchr( timetxt, '\n' );
*ptr = '\0';
}
new Q3ListViewItem(
lBox,
mnt.mnt_special,
mnt.mnt_mountp,
mnt.mnt_fstype,
total,
avail,
QString( timetxt ),
mnt.mnt_mntopts
);
}
fclose( mnttab );
lBox->setSorting( 0 );
// sorting_allowed = true;
return true;
}
bool GetInfo_XServer_and_Video( Q3ListView *lBox ) {
return GetInfo_XServer_Generic( lBox );
}
#ifdef HAVE_LIBDEVINFO_H
/*
* get Solaris' device configuration data through libdevinfo(3)
* and display it in a prtconf(1M) style tree
*
* NOTE: though the devinfo library seems to be present on earlier
* Solaris releases, this interface is documented to be available
* since Solaris 7 (libdevinfo.h is missing on pre-Solaris 7 systems)
*
* documentation for libdevinfo(3) including code samples on which
* this implementation is based on is available at
* http://soldc.sun.com/developer/support/driver/wps/libdevinfo/
*/
/*
* we start with various helper routines for GetInfo_Devices()
*/
/*
* mktree() -- break up the device path and place its components
* into the tree widget
*/
Q3ListViewItem *mktree( Q3ListViewItem *top, const char *path ) {
Q3ListViewItem *parent,
*previous,
*result;
char *str = strdup( path ),
*token;
/*
* start at "/"
*/
parent = top;
result = (*top).firstChild();
previous = (*top).firstChild();
token = strtok( str, "/" );
while( token != NULL ) {
/*
* find insert pos:
* try to match the node at the current level
*
* NOTE: this implementation assumes that there are
* no two nodes with identical names at the
* same level of the device tree
*/
while( result != NULL ) {
if( strcmp( token, (*result).text( 0 ).toLatin1()) == 0 )
break;
previous = result;
result = (*result).nextSibling();
}
if( result == NULL ) {
/*
* we haven't found the node, create a new one
*/
result = new Q3ListViewItem( parent,
previous,
token );
} else {
/*
* we've found the node
*/
parent = result;
previous = NULL;
if( (*result).firstChild() == NULL ) {
/*
* create new node during next iteration
*/
result->setExpandable( true );
result->setOpen( false );
} else {
/*
* follow the child path
*/
result = (*result).firstChild();
}
}
token = strtok( NULL, "/" );
}
free( str );
return( result );
}
/*
* prop_type_str() -- return the property type as a string
*/
char *prop_type_str( di_prop_t prop ) {
switch( di_prop_type( prop )) {
case DI_PROP_TYPE_UNDEF_IT:
return( "undefined" );
case DI_PROP_TYPE_BOOLEAN:
return( "BOOL" );
case DI_PROP_TYPE_INT:
return( "INT" );
case DI_PROP_TYPE_STRING:
return( "STRING" );
case DI_PROP_TYPE_BYTE:
return( "BYTE" );
default:
return( "unknown" );
}
}
/*
* prop_type_guess() -- guess the property type
*/
int prop_type_guess( uchar_t *data, int len ) {
int slen;
int guess;
int i, c;
if( len < 0 )
return( -1 );
else if( len == 0 )
return( DI_PROP_TYPE_BOOLEAN );
slen = 0;
guess = DI_PROP_TYPE_STRING;
for( i = 0; i < len; i++ ) {
c = (int) data[i];
switch( c ) {
case 0:
if( i == (len - 1 ))
break;
if( slen == 0 )
guess = DI_PROP_TYPE_BYTE;
else
guess = slen = 0;
break;
default:
if( ! isprint( c ))
guess = DI_PROP_TYPE_BYTE;
else
slen++;
}
if( guess != DI_PROP_TYPE_STRING )
break;
}
// if( (guess == DI_PROP_TYPE_BYTE) && (len % sizeof( int ) == 0 ))
// guess = DI_PROP_TYPE_INT;
return( guess );
}
/*
* dump_minor_node() -- examine a device minor node
* this routine gets passed to di_walk_node()
*/
int dump_minor_node( di_node_t node, di_minor_t minor, void *arg ) {
Q3ListViewItem *item;
QString majmin;
char *type;
dev_t dev;
item = new Q3ListViewItem( (Q3ListViewItem *) arg,
di_minor_name( minor ));
item->setExpandable( true );
item->setOpen( false );
new Q3ListViewItem( item, i18n( "Spectype:" ),
(di_minor_spectype( minor ) == S_IFCHR)
? i18n( "character special" )
: i18n( "block special" ));
type = di_minor_nodetype( minor );
new Q3ListViewItem( item, i18n( "Nodetype:" ),
(type == NULL) ? "NULL" : type );
if( (dev = di_minor_devt( minor )) != DDI_DEV_T_NONE ) {
majmin.sprintf( "%ld/%ld", major( dev ), minor( dev ));
new Q3ListViewItem( item, i18n( "Major/Minor:" ), majmin );
}
if( di_minor_next( node, minor ) == DI_MINOR_NIL )
return( DI_WALK_TERMINATE );
else
return( DI_WALK_CONTINUE );
}
/*
* propvalue() -- return the property value
*/
QString propvalue( di_prop_t prop ) {
int type;
int i, n;
char *strp;
int *intp;
uchar_t *bytep;
QString result;
/*
* Since a lot of printable strings seem to be tagged as 'byte',
* we're going to guess, if the property is not STRING or INT
* The actual type is shown in the info tree, though.
*/
type = di_prop_type( prop );
if( (type != DI_PROP_TYPE_STRING) && (type != DI_PROP_TYPE_INT) ) {
n = di_prop_bytes( prop, &bytep );
type = prop_type_guess( bytep, n );
}
result = "";
switch( type ) {
case DI_PROP_TYPE_STRING:
if( (n = di_prop_strings( prop, &strp )) < 0 ) {
result = "(error)";
} else {
for( i = 0; i < n; i++ ) {
result += "\"";
result += strp;
result += "\" ";
strp += strlen( strp ) + 1;
}
}
break;
case DI_PROP_TYPE_INT:
if( (n = di_prop_ints( prop, &intp )) < 0 ) {
result = "(error)";
} else {
for( i = 0; i < n; i++ ) {
QString tmp;
tmp.setNum( intp[i] );
result += tmp;
result += ' ';
}
}
break;
case DI_PROP_TYPE_BOOLEAN:
/*
* hmm, Sun's sample code handles the existence
* of a boolean property as "true", whereas
* prtconf(1M) obviously does not (Sol8, at least)
* -- we're doing the same and handle "bool" as "byte"
*/
case DI_PROP_TYPE_BYTE:
if( (n = di_prop_bytes( prop, &bytep )) < 0 ) {
result = "(error)";
} else {
if( n == 0 ) {
result = i18n( "(no value)" );
break;
}
result = "0x";
for( i = 0; i < n; i++ ) {
QString tmp;
unsigned byte = (unsigned) bytep[i];
tmp.sprintf( "%2.2x", byte );
result += tmp;
}
}
break;
default:
result = "???";
}
return( result );
}
/*
* dump_node() -- examine a device node and its children
* this routine gets passed to di_walk_node()
*/
int dump_node( di_node_t node, void *arg ) {
Q3ListViewItem *top = (Q3ListViewItem *) arg,
*parent,
*previous;
char *path;
char *drivername;
char *names;
QString compatnames;
int i, n;
di_prop_t prop;
path = di_devfs_path( node );
/*
* if this is the root node ("/"), initialize the tree
*/
if( strlen( path ) == 1 ) {
top->setText( 0, QString( di_binding_name( node )));
top->setPixmap( 0, SmallIcon( "kcmdevices" ));
top->setOpen( true );
top->setSelectable( false );
top->setExpandable( false );
}
/*
* place the node in the tree
*/
parent = mktree( top, path );
/*
* we have to handle the root node differently...
*/
if( strlen( path ) > 1 ) {
parent->setExpandable( true );
parent->setOpen( false );
} else {
previous = parent;
parent = top;
}
/*
* node name and physical device path
*/
drivername = di_driver_name( node );
previous = new Q3ListViewItem( parent,
i18n( "Driver Name:" ),
(drivername == NULL)
? i18n( "(driver not attached)" )
: drivername );
previous = new Q3ListViewItem( parent, previous,
i18n( "Binding Name:" ), di_binding_name( node ));
n = di_compatible_names( node, &names );
if( n < 1 ) {
compatnames = i18n( "(none)" );
} else {
for( i = 0; i < n; i++ ) {
compatnames += names;
compatnames += ' ';
names += strlen( names ) + 1;
}
}
previous = new Q3ListViewItem( parent, previous,
i18n( "Compatible Names:" ), compatnames );
previous = new Q3ListViewItem( parent, previous,
i18n( "Physical Path:" ), QString( path ));
/*
* dump the node's property list (if any)
*/
if( (prop = di_prop_next( node, DI_PROP_NIL )) != DI_PROP_NIL ) {
previous = new Q3ListViewItem( parent, previous, i18n( "Properties" ));
previous->setExpandable( true );
previous->setOpen( false );
do {
/*
* property type & value
*/
Q3ListViewItem *tmp,
*prev;
tmp = new Q3ListViewItem( previous, di_prop_name( prop ));
tmp->setExpandable( true );
tmp->setOpen( false );
prev = new Q3ListViewItem( tmp, i18n( "Type:" ),
prop_type_str( prop ));
new Q3ListViewItem( tmp, prev, i18n( "Value:" ),
propvalue( prop ));
} while( (prop = di_prop_next( node, prop )) != DI_PROP_NIL );
}
/*
* if there are minor nodes, expand the tree appropriately
*/
if( di_minor_next( node, DI_MINOR_NIL ) != DI_MINOR_NIL ) {
previous = new Q3ListViewItem( parent, previous, i18n( "Minor Nodes" ));
previous->setExpandable( true );
previous->setOpen( false );
di_walk_minor( node, NULL, 0, previous, dump_minor_node );
}
return( DI_WALK_CONTINUE );
}
bool GetInfo_Devices( Q3ListView *lBox ) {
Q3ListViewItem *top;
di_node_t root_node;
/*
* create a snapshot of the device tree
*/
if( (root_node = di_init( "/", DINFOCPYALL )) == DI_NODE_NIL ) {
return( false );
}
// XXX: might try to di_prom_init() here as well (if we're setgid sys)
/*
* prepare the tree widget
*/
lBox->addColumn( i18n( "Device Information" ));
lBox->addColumn( i18n( "Value" ));
top = new Q3ListViewItem( lBox );
/*
* traverse the device tree
*/
di_walk_node( root_node, DI_WALK_CLDFIRST, top, dump_node );
di_fini( root_node );
sorting_allowed = false;
return true;
}
#else /* ! HAVE_LIBDEVINFO_H */
bool GetInfo_Devices( Q3ListView * ) {
return false;
}
#endif /* ! HAVE_LIBDEVINFO_H */

View file

@ -1,132 +0,0 @@
/*
info_svr4.cpp
UNIX System V Release 4 specific Information about the Hardware.
Appropriate for SCO OpenServer and UnixWare.
Written 20-Feb-99 by Ronald Joe Record (rr@sco.com)
Initially based on info_sgi.cpp
*/
#define INFO_CPU_AVAILABLE
#define INFO_IRQ_AVAILABLE
#define INFO_DMA_AVAILABLE
#define INFO_PCI_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
#define INFO_SOUND_AVAILABLE
#define INFO_DEVICES_AVAILABLE
#define INFO_SCSI_AVAILABLE
#define INFO_PARTITIONS_AVAILABLE
#define INFO_XSERVER_AVAILABLE
#define INFO_DEV_SNDSTAT "/dev/sndstat"
#include <sys/systeminfo.h>
/* all following functions should return true, when the Information
was filled into the lBox-Widget.
returning false indicates, that information was not available.
*/
bool GetInfo_ReadfromFile( QListView *lBox, char *Name, char splitchar )
{
QString str;
char buf[512];
QFile *file = new QFile(Name);
QListViewItem* olditem = 0;
if(!file->open(QIODevice::ReadOnly)) {
delete file;
return false;
}
while (file->readLine(buf,sizeof(buf)-1) > 0) {
if (strlen(buf)) {
char *p=buf;
if (splitchar!=0) /* remove leading spaces between ':' and the following text */
while (*p) {
if (*p==splitchar) {
*p++ = ' ';
while (*p==' ') ++p;
*(--p) = splitchar;
++p;
}
else ++p;
}
QString s1 = QString::fromLocal8Bit(buf);
QString s2 = s1.mid(s1.find(splitchar)+1);
s1.truncate(s1.find(splitchar));
if(!(s1.isEmpty() || s2.isEmpty()))
olditem = new QListViewItem(lBox, olditem, s1, s2);
}
}
file->close();
delete file;
return true;
}
bool GetInfo_CPU( QListView *lBox )
{
char buf[256];
sysinfo(SI_ARCHITECTURE, buf, sizeof(buf));
new QListViewItem(lBox, QString::fromLocal8Bit(buf));
return true;
}
bool GetInfo_IRQ( QListView * )
{
return false;
}
bool GetInfo_DMA( QListView * )
{
return false;
}
bool GetInfo_PCI( QListView *lBox )
{
char buf[256];
sysinfo(SI_BUSTYPES, buf, sizeof(buf));
new QListViewItem(lBox, QString::fromLocal8Bit(buf));
return true;
}
bool GetInfo_IO_Ports( QListView * )
{
return false;
}
bool GetInfo_Sound( QListView *lBox )
{
if ( GetInfo_ReadfromFile( lBox, INFO_DEV_SNDSTAT, 0 ))
return true;
else
return false;
}
bool GetInfo_Devices( QListView * )
{
return false;
}
bool GetInfo_SCSI( QListView * )
{
return false;
}
bool GetInfo_Partitions( QListView * )
{
return false;
}
bool GetInfo_XServer_and_Video( QListView *lBox )
{
return GetInfo_XServer_Generic( lBox );
}

View file

@ -21,16 +21,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "memory.h"
#include <kcomponentdata.h>
#include <KPluginFactory>
#include <KPluginLoader>
/* we have to include the info.cpp-file, to get the DEFINES about possible properties.
example: we need the "define INFO_CPU_AVAILABLE" */
#include "info.cpp"
#include "info.h"
#include "os_current.h"
class KInfoModulesFactory : public KPluginFactory
{
@ -60,12 +59,6 @@ CREATE_FACTORY(CPU, i18n("Processor(s)"))
#ifdef INFO_IRQ_AVAILABLE
CREATE_FACTORY(IRQ, i18n("Interrupt"))
#endif
#ifdef INFO_PCI_AVAILABLE
CREATE_FACTORY(PCI, i18n("PCI"))
#endif
#ifdef INFO_DMA_AVAILABLE
CREATE_FACTORY(DMA, i18n("DMA-Channel"))
#endif
#ifdef INFO_IOPORTS_AVAILABLE
CREATE_FACTORY(IO_Ports, i18n("I/O-Port"))
#endif
@ -75,6 +68,9 @@ CREATE_FACTORY(Sound, i18n("Soundcard"))
#ifdef INFO_SCSI_AVAILABLE
CREATE_FACTORY(SCSI, i18n("SCSI"))
#endif
#ifdef INFO_DMA_AVAILABLE
CREATE_FACTORY(DMA, i18n("DMA-Channel"))
#endif
#ifdef INFO_DEVICES_AVAILABLE
CREATE_FACTORY(Devices, i18n("Devices"))
#endif
@ -89,19 +85,13 @@ KInfoModulesFactory::KInfoModulesFactory(const char *componentName)
: KPluginFactory(componentName)
{
s_instance = this;
registerPlugin<KMemoryWidget>("memory");
#ifdef INFO_CPU_AVAILABLE
registerPlugin<KCPUInfoWidget>("cpu");
#endif
#ifdef INFO_IRQ_AVAILABLE
registerPlugin<KIRQInfoWidget>("irq");
#endif
#ifdef INFO_PCI_AVAILABLE
registerPlugin<KPCIInfoWidget>("pci");
#endif
#ifdef INFO_DMA_AVAILABLE
registerPlugin<KDMAInfoWidget>("dma");
#endif
#ifdef INFO_IOPORTS_AVAILABLE
registerPlugin<KIO_PortsInfoWidget>("ioports");
#endif
@ -111,6 +101,9 @@ KInfoModulesFactory::KInfoModulesFactory(const char *componentName)
#ifdef INFO_SCSI_AVAILABLE
registerPlugin<KSCSIInfoWidget>("scsi");
#endif
#ifdef INFO_DMA_AVAILABLE
registerPlugin<KDMAInfoWidget>("dma");
#endif
#ifdef INFO_DEVICES_AVAILABLE
registerPlugin<KDevicesInfoWidget>("devices");
#endif

View file

@ -1,493 +0,0 @@
/*
* memory.cpp
*
* prints memory-information and shows a graphical display.
*
* Copyright (c) 1999-2002 Helge Deller <deller@gmx.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*
*/
#include <sys/param.h> /* for BSD */
#include <QLayout>
#include <QPainter>
#include <QtGui/qdrawutil.h>
//Added by qt3to4:
#include <QPixmap>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <klocale.h>
#include <kglobal.h>
#include <kdialog.h>
#include <kseparator.h>
#include <KPluginFactory>
#include "memory.h"
enum { /* entries for Memory_Info[] */
TOTAL_MEM = 0, /* total physical memory (without swaps) */
FREE_MEM, /* total free physical memory (without swaps) */
#if !defined(__svr4__) || !defined(sun)
#if !defined(__NetBSD__) && !defined(__OpenBSD__)
SHARED_MEM, /* shared memory size */
BUFFER_MEM, /* buffered memory size */
#else
ACTIVE_MEM,
INACTIVE_MEM,
#endif
#endif
CACHED_MEM, /* cache memory size (located in ram) */
SWAP_MEM, /* total size of all swap-partitions */
FREESWAP_MEM, /* free memory in swap-partitions */
MEM_LAST_ENTRY
};
/*
all fetchValues()-functions should put either
their results _OR_ the value NO_MEMORY_INFO into Memory_Info[]
*/
static t_memsize Memory_Info[MEM_LAST_ENTRY];
#define MEMORY(x) ((t_memsize) (x)) /* it's easier... */
#define NO_MEMORY_INFO MEMORY(-1) /* DO NOT CHANGE */
#define ZERO_IF_NO_INFO(value) ((value) != NO_MEMORY_INFO ? (value) : 0)
/******************/
/* Implementation */
/******************/
static QLabel *MemSizeLabel[MEM_LAST_ENTRY][2];
enum { MEM_RAM_AND_HDD, MEM_RAM, MEM_HDD, MEM_LAST };
static QLabel *Graph[MEM_LAST];
static QLabel *GraphLabel[MEM_LAST];
#define SPACING 16
static QString formatted_unit(t_memsize value)
{
if (value > (1024 * 1024))
if (value > (1024 * 1024 * 1024))
return i18n("%1 GiB", KGlobal::locale()->formatNumber(value / (1024 * 1024 * 1024.0), 2));
else
return i18n("%1 MiB", KGlobal::locale()->formatNumber(value / (1024 * 1024.0), 2));
else
return i18n("%1 KiB", KGlobal::locale()->formatNumber(value / 1024.0, 2));
}
K_PLUGIN_FACTORY_DECLARATION(KInfoModulesFactory)
KMemoryWidget::KMemoryWidget(QWidget *parent, const QVariantList &)
: KCModule(KInfoModulesFactory::componentData(),parent)
{
KAboutData *about =
new KAboutData(I18N_NOOP("kcminfo"), 0,
ki18n("KDE Panel Memory Information Control Module"),
0, KLocalizedString(), KAboutData::License_GPL,
ki18n("(c) 1998 - 2002 Helge Deller"));
about->addAuthor(ki18n("Helge Deller"), KLocalizedString(), "deller@gmx.de");
setAboutData( about );
QString title, initial_str;
QLabel *Widget = 0;
int i, j;
ram_colors_initialized =
swap_colors_initialized =
all_colors_initialized = false;
setButtons(Help);
/* default string for no Information... */
Not_Available_Text = i18n("Not available.");
QVBoxLayout *top = new QVBoxLayout(this);
top->setMargin(0);
top->setSpacing(KDialog::spacingHint());
QHBoxLayout *hbox = new QHBoxLayout();
top->addLayout(hbox);
/* stretch the left side */
hbox->addStretch();
/* first create the Informationtext-Widget */
QVBoxLayout *vbox = new QVBoxLayout();
hbox->addItem( vbox );
vbox->setSpacing(0);
for (i = TOTAL_MEM; i < MEM_LAST_ENTRY; ++i) {
switch (i) {
case TOTAL_MEM:
title = i18n("Total physical memory:");
break;
case FREE_MEM:
title = i18n("Free physical memory:");
break;
#if !defined(__svr4__) || !defined(sun)
#if !defined(__NetBSD__) && !defined(__OpenBSD__)
case SHARED_MEM:
title = i18n("Shared memory:");
break;
case BUFFER_MEM:
title = i18n("Disk buffers:");
break;
#else
case ACTIVE_MEM:
title = i18n("Active memory:");
break;
case INACTIVE_MEM:
title = i18n("Inactive memory:");
break;
#endif
#endif
case CACHED_MEM:
title = i18n("Disk cache:");
break;
case SWAP_MEM:
vbox->addSpacing(SPACING);
title = i18n("Total swap memory:");
break;
case FREESWAP_MEM:
title = i18n("Free swap memory:");
break;
default:
title = "";
break;
};
Widget = new QLabel(title, this);
Widget->setAlignment( Qt::AlignLeft );
vbox->addWidget(Widget, 1);
}
/* then the memory-content-widgets */
for (j = 0; j < 2; j++) {
vbox = new QVBoxLayout();
hbox->addItem( vbox );
vbox->setSpacing(0);
for (i = TOTAL_MEM; i < MEM_LAST_ENTRY; ++i) {
if (i == SWAP_MEM)
vbox->addSpacing(SPACING);
Widget = new QLabel(this);
Widget->setAlignment( Qt::AlignRight );
MemSizeLabel[i][j] = Widget;
vbox->addWidget(Widget, 1);
}
}
/* stretch the right side */
hbox->addStretch();
KSeparator *line = new KSeparator(Qt::Horizontal, this);
top->addWidget(line);
/* now the Graphics */
QString hint;
hbox = new QHBoxLayout();
top->addItem(hbox);
hbox->setSpacing(1);
for (i = MEM_RAM_AND_HDD; i < MEM_LAST; i++) {
hbox->addSpacing(SPACING);
vbox = new QVBoxLayout();
hbox->addItem( vbox );
switch (i) {
case MEM_RAM_AND_HDD:
title = i18n("Total Memory");
hint = i18n("This graph gives you an overview of the "
"<b>total sum of physical and virtual memory</b> "
"in your system.");
break;
case MEM_RAM:
title = i18n("Physical Memory");
hint = i18n("This graph gives you an overview of "
"the <b>usage of physical memory</b> in your system."
"<p>Most operating systems (including Linux) "
"will use as much of the available physical "
"memory as possible as disk cache, "
"to speed up the system performance.</p>"
"<p>This means that if you have a small amount "
"of <b>Free Physical Memory</b> and a large amount of "
"<b>Disk Cache Memory</b>, your system is well "
"configured.</p>");
break;
case MEM_HDD:
title = i18n("Swap Space");
hint = i18n("The swap space is the <b>virtual memory</b> "
"available to the system. "
"<p>It will be used on demand and is provided "
"through one or more swap partitions and/or swap files.</p>");
break;
default:
hint = title = QString();
break;
};
if (hint.length())
hint = "<qt>" + hint + "</qt>";
Widget = new QLabel("<b>" + title + "</b>", this);
Widget->setAlignment( Qt::AlignCenter );
Widget->setToolTip( hint);
vbox->addWidget(Widget);
vbox->addSpacing(SPACING / 2);
QLabel *g = new QLabel(this);
g->setMinimumWidth(2 * SPACING);
g->setMinimumHeight(3 * SPACING);
g->setAttribute(Qt::WA_NoSystemBackground, true);
g->setToolTip( hint); // add the tooltip
Graph[i] = g;
vbox->addWidget(g, 2);
vbox->addSpacing(SPACING / 2);
Widget = new QLabel(this); /* xx MB used. */
Widget->setAlignment( Qt::AlignCenter );
Widget->setToolTip( hint);
GraphLabel[i] = Widget;
vbox->addWidget(Widget);
}
hbox->addSpacing(SPACING);
timer = new QTimer(this);
timer->start(100);
QObject::connect(timer, SIGNAL(timeout()), this,
SLOT(update()));
fetchValues();
}
KMemoryWidget::~KMemoryWidget()
{
/* stop the timer */
timer->stop();
}
QString KMemoryWidget::quickHelp() const
{
return i18n("<h1>Memory Information</h1>"
" This display shows you the current memory usage of your system."
" The values are updated on a regular basis and give you an"
" overview of the physical and virtual used memory." );
}
/* Graphical Memory Display */
bool KMemoryWidget::Display_Graph(int widgetindex,
int count,
t_memsize total,
t_memsize * used,
QColor * color,
QString *text)
{
QLabel *graph = Graph[widgetindex];
int width = graph->width();
int height = graph->height();
QPixmap pm(width, height);
QPainter paint;
paint.begin(&pm, this);
QPen pen(QColor(0, 0, 0));
if (! ZERO_IF_NO_INFO(total)) {
paint.fillRect(1, 1, width - 2, height - 2,
QBrush(QColor(128, 128, 128)));
paint.setPen(pen);
paint.drawRect(graph->rect());
GraphLabel[widgetindex]->setText(Not_Available_Text);
paint.end();
bitBlt(graph, 0, 0, &pm);
return false;
}
int startline = height-2;
int percent, localheight;
t_memsize last_used = 0;
while (count--) {
last_used = *used;
percent = (((qint64)last_used) * 100) / total;
if (count)
localheight = ((height-2) * percent) / 100;
else
localheight = startline;
if (localheight>0) {
paint.fillRect(1, startline, width-2, -localheight, *color);
if (localheight >= SPACING) {
paint.drawText(0, startline-localheight, width, localheight,
Qt::AlignCenter | Qt::TextWordWrap,
QString("%1 %2%").arg(*text).arg(percent));
}
}
startline -= localheight;
++used;
++color;
++text;
}
/* draw surrounding box */
paint.setPen(pen);
QRect r = graph->rect();
qDrawShadePanel(&paint, r.x(), r.y(), r.width(), r.height(), palette().active(), true, 1);
paint.end();
graph->setPixmap(pm);
//bitBlt(graph, 0, 0, &pm);
GraphLabel[widgetindex]->setText(i18n("%1 free", formatted_unit(last_used)));
return true;
}
/* update_Values() is the main-loop for updating the Memory-Information */
void KMemoryWidget::paintEvent(QPaintEvent *)
{
int i;
bool ok1;
QLabel *label;
t_memsize used[5];
fetchValues(); /* get the Information from memory_linux, memory_fbsd */
/* update the byte-strings */
for (i = TOTAL_MEM; i < MEM_LAST_ENTRY; i++) {
label = MemSizeLabel[i][0];
if (Memory_Info[i] == NO_MEMORY_INFO)
label->clear();
else
label->setText(i18n("%1 bytes =",
KGlobal::locale()->
formatNumber(Memory_Info[i], 0)));
}
/* update the MB-strings */
for (i = TOTAL_MEM; i < MEM_LAST_ENTRY; i++) {
label = MemSizeLabel[i][1];
label->setText((Memory_Info[i] != NO_MEMORY_INFO)
? formatted_unit(Memory_Info[i])
: Not_Available_Text);
}
/* display graphical output (ram, hdd, at last: HDD+RAM) */
/* be careful ! Maybe we have not all info available ! */
/* RAM usage: */
/* don't rely on the SHARED_MEM value since it may refer to
* the size of the System V sharedmem in 2.4.x. Calculate instead! */
used[1] = 0;
#if !defined(__svr4__) || !defined(sun)
#if !defined(__NetBSD__) && !defined(__OpenBSD__)
used[1] = ZERO_IF_NO_INFO(Memory_Info[BUFFER_MEM]);
#endif
#endif
used[2] = ZERO_IF_NO_INFO(Memory_Info[CACHED_MEM]);
used[3] = ZERO_IF_NO_INFO(Memory_Info[FREE_MEM]);
used[0] = ZERO_IF_NO_INFO(Memory_Info[TOTAL_MEM]) - used[1] - used[2] - used[3];
if (!ram_colors_initialized) {
ram_colors_initialized = true;
ram_text[0] = i18n("Application Data");
ram_colors[0] = COLOR_USED_MEMORY; /* used+shared */
ram_text[1] = i18n("Disk Buffers");
ram_colors[1] = QColor(24,131,5); /* buffer */
ram_text[2] = i18n("Disk Cache");
ram_colors[2] = QColor(33,180,7); /* cached */
ram_text[3] = i18n("Free Physical Memory");
ram_colors[3] = COLOR_FREE_MEMORY; /* free */
}
ok1 = Display_Graph(MEM_RAM, 4, Memory_Info[TOTAL_MEM],
used, ram_colors, ram_text);
/* SWAP usage: */
used[1] = ZERO_IF_NO_INFO(Memory_Info[FREESWAP_MEM]);
used[0] = ZERO_IF_NO_INFO(Memory_Info[SWAP_MEM]) - used[1];
if (!swap_colors_initialized) {
swap_colors_initialized = true;
swap_text[0] = i18n("Used Swap");
swap_colors[0] = COLOR_USED_SWAP; /* used */
swap_text[1] = i18n("Free Swap");
swap_colors[1] = COLOR_FREE_MEMORY; /* free */
}
Display_Graph(MEM_HDD, 2, Memory_Info[SWAP_MEM],
used, swap_colors, swap_text);
/* RAM + SWAP usage: */
if (Memory_Info[SWAP_MEM] == NO_MEMORY_INFO ||
Memory_Info[FREESWAP_MEM] == NO_MEMORY_INFO)
Memory_Info[SWAP_MEM] = Memory_Info[FREESWAP_MEM] = 0;
used[1] = Memory_Info[SWAP_MEM] - Memory_Info[FREESWAP_MEM];
used[2] = Memory_Info[FREE_MEM] + Memory_Info[FREESWAP_MEM];
used[0] = (Memory_Info[TOTAL_MEM]+Memory_Info[SWAP_MEM])-used[1]-used[2];
if (!all_colors_initialized) {
all_colors_initialized = true;
all_text[0] = i18n("Used Physical Memory");
all_colors[0] = COLOR_USED_MEMORY; /* used ram */
all_text[1] = i18n("Used Swap");
all_colors[1] = COLOR_USED_SWAP; /* used swap */
all_text[2] = i18n("Total Free Memory");
all_colors[2] = COLOR_FREE_MEMORY; /* free ram+swap*/
}
Display_Graph(MEM_RAM_AND_HDD, 3,
ok1 ? Memory_Info[TOTAL_MEM] + Memory_Info[SWAP_MEM]
: NO_MEMORY_INFO,
used, all_colors, all_text);
}
/* Include system-specific code */
#ifdef __linux__
#include "memory_linux.cpp"
#elif defined(__APPLE__)
#include "memory_osx.cpp"
#elif defined(sgi) && sgi
#include "memory_sgi.cpp"
#elif defined(__svr4__) && defined(sun)
#include "memory_solaris.cpp"
#elif defined(__FreeBSD__) || defined(__DragonFly__)
#include "memory_fbsd.cpp"
#elif defined(__hpux)
#include "memory_hpux.cpp"
#elif defined(__NetBSD__) || defined(__OpenBSD__)
#include "memory_netbsd.cpp"
#elif __osf__
#include "memory_tru64.cpp"
#else
/* Default for unsupported systems */
void KMemoryWidget::fetchValues()
{
int i;
for (i = TOTAL_MEM; i < MEM_LAST_ENTRY; ++i)
Memory_Info[i] = NO_MEMORY_INFO;
}
#endif
#include "memory.moc"

View file

@ -1,61 +0,0 @@
#ifndef _MEMORY_H_KDEINFO_INCLUDED_
#define _MEMORY_H_KDEINFO_INCLUDED_
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QTimer>
#include <kcmodule.h>
#include <kaboutdata.h>
class QStringList;
/* better to use quint64, because some 32bit-machines have more total
memory (with swap) than just the 4GB which fits into a 32bit-long */
typedef quint64 t_memsize;
#define COLOR_USED_MEMORY QColor(255,0,0)
#define COLOR_USED_SWAP QColor(255,134,64)
#define COLOR_FREE_MEMORY QColor(127,255,212)
class KMemoryWidget:public KCModule {
Q_OBJECT
public:
KMemoryWidget(QWidget *parent, const QVariantList &);
~KMemoryWidget();
QString quickHelp() const;
private:
QString Not_Available_Text;
QTimer *timer;
bool ram_colors_initialized,
swap_colors_initialized,
all_colors_initialized;
QColor ram_colors[4];
QString ram_text[4];
QColor swap_colors[2];
QString swap_text[2];
QColor all_colors[3];
QString all_text[3];
void fetchValues();
bool Display_Graph(int widgetindex,
int count,
t_memsize total,
t_memsize *used,
QColor *color,
QString *text);
void paintEvent(QPaintEvent *);
};
#endif // _MEMORY_H_KDEINFO_INCLUDED_

View file

@ -1,37 +0,0 @@
/*
Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kcrootonly.h"
#include <klocale.h>
#include <QLabel>
#include <QVBoxLayout>
KCRootOnly::KCRootOnly(const KComponentData &componentData, QWidget *parent)
: KCModule( componentData, parent )
{
QVBoxLayout *layout=new QVBoxLayout(this);
QLabel *label = new QLabel(i18n("<big>You need super user privileges to run this control module.</big><br />"
"Click on the \"Administrator Mode\" button below."), this);
layout->addWidget(label);
label->setAlignment(Qt::AlignCenter);
label->setTextFormat(Qt::RichText);
label->setMinimumSize(label->sizeHint());
}

View file

@ -1,30 +0,0 @@
/*
Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _kinfocenter_kcrootonly_
#define _kinfocenter_kcrootonly_
#include <kcmodule.h>
class KComponentData;
class KCRootOnly: public KCModule {
public:
KCRootOnly(const KComponentData &inst, QWidget *parent);
};
#endif

View file

@ -1,18 +1,6 @@
<!DOCTYPE kpartgui>
<kpartgui name="kinfocenter" version="2">
<MenuBar>
<Menu name="view"><text>&amp;View</text>
<Menu name="view_mode"><text>&amp;Mode</text>
<Action name="activate_iconview"/>
<Action name="activate_treeview"/>
</Menu>
<Menu name="view_iconsize"><text>Icon &amp;Size</text>
<Action name="activate_smallicons"/>
<Action name="activate_mediumicons"/>
<Action name="activate_largeicons"/>
<Action name="activate_hugeicons"/>
</Menu>
</Menu>
<Menu name="help">
<Action name="help_about_module" append="about_merge"/>
</Menu>

View file

@ -1,22 +1,21 @@
/*
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
Copyright (c) 2000 Matthias Elter <elter@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* Howto debug:
@ -33,10 +32,8 @@
*/
#include "main.h"
#include "version.h"
#include "toplevel.h"
#include "global.h"
#include "moduleIface.h"
#include <kcmdlineargs.h>
#include <kaboutdata.h>
@ -46,89 +43,76 @@
#include <kdebug.h>
#include <kglobal.h>
#include <klocale.h>
#include <kapplication.h>
#include <QByteArray>
#include <QDesktopWidget>
#include "main.moc"
KInfoCenterApp::KInfoCenterApp()
: KUniqueApplication()
, toplevel(0)
{
toplevel = new TopLevel();
KInfoCenterApp::KInfoCenterApp() :
KUniqueApplication() {
// hmm? KApplication registers its KComponentData as the main and active component. Why is this
// needed?
//KGlobal::setActiveComponent(this);
toplevel = new TopLevel();
// KUniqueApplication does dcop regitration for us
ModuleIface *modIface = new ModuleIface(toplevel, "moduleIface");
QRect desk = KGlobalSettings::desktopGeometry(toplevel);
KConfigGroup config(KGlobal::config(), "General");
// Initial size is:
// never bigger than workspace as reported by desk
// 940x700 on 96 dpi, 12 pt font
// 800x600 on 72 dpi, 12 pt font
// --> 368 + 6 x dpiX, 312 + 4 x dpiY
// Adjusted for font size
int fontSize = toplevel->fontInfo().pointSize();
if (fontSize == 0)
fontSize = (toplevel->fontInfo().pixelSize() * 72) / toplevel->logicalDpiX();
int x = config.readEntry(QString::fromLatin1("InitialWidth %1").arg(desk.width()), qMin(desk.width(), 368 + (6*toplevel->logicalDpiX()*fontSize)/12) );
int y = config.readEntry(QString::fromLatin1("InitialHeight %1").arg(desk.height()), qMin(desk.height(), 312 + (4*toplevel->logicalDpiX()*fontSize)/12) );
connect (modIface, SIGNAL(helpClicked()), toplevel, SLOT(slotHelpRequest()));
toplevel->resize(x, y);
QRect desk = KGlobalSettings::desktopGeometry(toplevel);
KConfigGroup config(KGlobal::config(), "General");
// Initial size is:
// never bigger than workspace as reported by desk
// 940x700 on 96 dpi, 12 pt font
// 800x600 on 72 dpi, 12 pt font
// --> 368 + 6 x dpiX, 312 + 4 x dpiY
// Adjusted for font size
int fontSize = toplevel->fontInfo().pointSize();
if (fontSize == 0)
fontSize = (toplevel->fontInfo().pixelSize() * 72) / toplevel->logicalDpiX();
int x = config.readEntry(QString::fromLatin1("InitialWidth %1").arg(desk.width()),
qMin( desk.width(), 368 + (6*toplevel->logicalDpiX()*fontSize)/12 ) );
int y = config.readEntry(QString::fromLatin1("InitialHeight %1").arg(desk.height()),
qMin( desk.height(), 312 + (4*toplevel->logicalDpiX()*fontSize)/12 ) );
toplevel->resize(x,y);
toplevel->show();
toplevel->show();
}
KInfoCenterApp::~KInfoCenterApp()
{
if (toplevel)
{
KConfigGroup config(KGlobal::config(), "General");
QDesktopWidget *desk = QApplication::desktop();
config.writeEntry(QString::fromLatin1("InitialWidth %1").arg(desk->width()), toplevel->width());
config.writeEntry(QString::fromLatin1("InitialHeight %1").arg(desk->height()), toplevel->height());
config.sync();
}
KInfoCenterApp::~KInfoCenterApp() {
if (toplevel!=NULL) {
KConfigGroup config(KGlobal::config(), "General");
QDesktopWidget *desk = QApplication::desktop();
config.writeEntry(QString::fromLatin1("InitialWidth %1").arg(desk->width()), toplevel->width());
config.writeEntry(QString::fromLatin1("InitialHeight %1").arg(desk->height()), toplevel->height());
config.sync();
}
}
extern "C" KDE_EXPORT int kdemain(int argc, char *argv[])
extern "C"KDE_EXPORT int kdemain(int argc, char *argv[])
{
KLocale::setMainCatalog("kinfocenter");
KLocale::setMainCatalog("kinfocenter");
KAboutData aboutKInfoCenter( "kinfocenter", 0, ki18n("KDE Info Center"),
KINFOCENTER_VERSION, ki18n("The KDE Info Center"), KAboutData::License_GPL,
ki18n("(c) 1998-2004, The KDE Control Center Developers"));
KAboutData aboutKInfoCenter( "kinfocenter", 0, ki18n("KDE Info Center"),
KDE_VERSION_STRING, ki18n("The KDE Info Center"), KAboutData::License_GPL,
ki18n("(c) 1998-2004, The KDE Control Center Developers"));
QByteArray argv_0 = argv[0];
KAboutData *aboutData;
aboutData = &aboutKInfoCenter;
KCGlobal::setIsInfoCenter(true);
kDebug(1208) << "Running as KInfoCenter!\n";
QByteArray argv_0 = argv[0];
KAboutData *aboutData = &aboutKInfoCenter;
aboutData->addAuthor(ki18n("Helge Deller"), ki18n("Current Maintainer"), "deller@kde.org");
aboutData->addAuthor(ki18n("Matthias Hoelzer-Kluepfel"),KLocalizedString(), "hoelzer@kde.org");
aboutData->addAuthor(ki18n("Matthias Elter"),KLocalizedString(), "elter@kde.org");
aboutData->addAuthor(ki18n("Matthias Ettrich"),KLocalizedString(), "ettrich@kde.org");
aboutData->addAuthor(ki18n("Waldo Bastian"),KLocalizedString(), "bastian@kde.org");
aboutData->addAuthor(ki18n("Nicolas Ternisien"), ki18n("Current Maintainer"), "nicolas.ternisien@gmail.com");
aboutData->addAuthor(ki18n("Helge Deller"), ki18n("Previous Maintainer"), "deller@kde.org");
aboutData->addAuthor(ki18n("Matthias Hoelzer-Kluepfel"),KLocalizedString(), "hoelzer@kde.org");
aboutData->addAuthor(ki18n("Matthias Elter"),KLocalizedString(), "elter@kde.org");
aboutData->addAuthor(ki18n("Matthias Ettrich"),KLocalizedString(), "ettrich@kde.org");
aboutData->addAuthor(ki18n("Waldo Bastian"),KLocalizedString(), "bastian@kde.org");
KCmdLineArgs::init( argc, argv, aboutData );
KUniqueApplication::addCmdLineOptions();
KCmdLineArgs::init( argc, argv, aboutData );
KUniqueApplication::addCmdLineOptions();
KCGlobal::init();
KCGlobal::init();
if (!KInfoCenterApp::start()) {
kDebug(1208) << "kinfocenter is already running!\n";
return (0);
}
if (!KInfoCenterApp::start()) {
kDebug() << "kinfocenter is already running!\n";
return 0;
}
KInfoCenterApp app;
KInfoCenterApp app;
return app.exec();
return app.exec();
}

View file

@ -1,22 +1,22 @@
/*
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
Copyright (c) 2000 Matthias Elter <elter@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
*/
#ifndef __main_h__
#define __main_h__
@ -25,17 +25,16 @@
class TopLevel;
class KInfoCenterApp : public KUniqueApplication
{
Q_OBJECT
class KInfoCenterApp : public KUniqueApplication {
Q_OBJECT
public:
KInfoCenterApp();
virtual ~KInfoCenterApp();
KInfoCenterApp();
virtual ~KInfoCenterApp();
private:
TopLevel *toplevel;
TopLevel *toplevel;
};

View file

@ -0,0 +1,14 @@
########### next target ###############
set(KCM_MEMORY_PART_SRCS memory.cpp chartWidget.cpp totalMemoryChart.cpp physicalMemoryChart.cpp swapMemoryChart.cpp )
kde4_add_plugin(kcm_memory ${KCM_MEMORY_PART_SRCS})
target_link_libraries(kcm_memory ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY})
install(TARGETS kcm_memory DESTINATION ${PLUGIN_INSTALL_DIR})
########### install files ###############
install( FILES kcm_memory.desktop DESTINATION ${SERVICES_INSTALL_DIR})

View file

@ -0,0 +1,2 @@
#! /usr/bin/env bash
$XGETTEXT *.cpp -o $podir/kcm_memory.pot

48
kinfocenter/memory/base.h Normal file
View file

@ -0,0 +1,48 @@
#ifndef SETTINGS_H_
#define SETTINGS_H_
#include <QColor>
#define COLOR_USED_MEMORY QColor(0x83,0xDD, 0xF5)
//start : 0x00, 0x71, 0xBC
//end : 0x83,0xDD, 0xF5
//#define COLOR_USED_MEMORY QColor(236,91,47)
#define COLOR_USED_SWAP QColor(255,134,64)
//#define COLOR_FREE_MEMORY QColor(0x00, 0x71, 0xBC)
#define COLOR_FREE_MEMORY QColor(216, 231, 227)
/* better to use quint64, because some 32bit-machines have more total
memory (with swap) than just the 4GB which fits into a 32bit-long */
typedef quint64 t_memsize;
enum { /* entries for memoryInfos[] */
TOTAL_MEM = 0, /* total physical memory (without swaps) */
FREE_MEM, /* total free physical memory (without swaps) */
#if !defined(__svr4__) || !defined(sun)
#if !defined(__NetBSD__) && !defined(__OpenBSD__)
SHARED_MEM, /* shared memory size */
BUFFER_MEM, /* buffered memory size */
#else
ACTIVE_MEM,
INACTIVE_MEM,
#endif
#endif
CACHED_MEM, /* cache memory size (located in ram) */
SWAP_MEM, /* total size of all swap-partitions */
FREESWAP_MEM, /* free memory in swap-partitions */
MEM_LAST_ENTRY
};
#define MEMORY(x) ((t_memsize) (x)) /* it's easier... */
#define NO_MEMORY_INFO MEMORY(-1) /* DO NOT CHANGE */
#define ZERO_IF_NO_INFO(value) ((value) != NO_MEMORY_INFO ? (value) : 0)
#define SPACING 16
#endif /*SETTINGS_H_*/

View file

@ -0,0 +1,152 @@
/***************************************************************************
* KT list view item task implementation. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "chartWidget.h"
#include <QVBoxLayout>
#include <QLinearGradient>
#include <QLabel>
#include <QPainter>
#include <QPen>
#include <QColor>
#include <klocale.h>
#include <kdebug.h>
#include <kglobal.h>
Chart::Chart(QWidget* parent) :
QWidget(parent) {
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
memoryInfos = NULL;
freeMemoryLabel = NULL;
}
void Chart::setMemoryInfos(t_memsize* memoryInfos) {
this->memoryInfos = memoryInfos;
}
void Chart::setFreeMemoryLabel(QLabel* freeMemoryLabel) {
this->freeMemoryLabel = freeMemoryLabel;
}
/* Graphical Memory Display */
bool Chart::drawChart(t_memsize total, const QList<t_memsize>& used, const QList<QColor>& colors, const QList<QString>& texts) {
QPainter paint(this);
QPen pen(QColor(0, 0, 0));
if (total == NO_MEMORY_INFO) {
paint.fillRect(1, 1, width() - 2, height() - 2, QBrush(QColor(128, 128, 128)));
paint.setPen(pen);
paint.drawRect(rect());
freeMemoryLabel->setText(i18n("Not available."));
return false;
}
int startline = height()-2;
int percent, localheight;
t_memsize last_used = 0;
for (int count = used.size()-1; count >=0; --count) {
last_used = used.at(count);
QColor color = colors.at(count);
QString text = texts.at(count);
percent = (((qint64)last_used) * 100) / total;
if (count)
localheight = ((height()-2) * percent) / 100;
else
localheight = startline;
//kDebug() << "Count : " << count << " Percent : " << percent << "%" << " Localheight:" << localheight << endl;
if (localheight>0) {
QLinearGradient gradient(QPointF(1, startline), QPointF(width()-2, -localheight));
QColor endProgressColor(0xFF, 0xFF, 0xFF, 100);
gradient.setColorAt(0, color);
gradient.setColorAt(1, endProgressColor);
paint.fillRect(1, startline, width()-2, -localheight, gradient);
//paint.fillRect(1, startline, width()-2, -localheight, color);
if (localheight >= SPACING) {
paint.drawText(0, startline-localheight, width(), localheight, Qt::AlignCenter | Qt::TextWordWrap, QString("%1 %2%").arg(text).arg(percent));
}
}
startline -= localheight;
}
// draw surrounding box
paint.setPen(pen);
QRect r = rect();
qDrawShadePanel(&paint, r.x(), r.y(), r.width(), r.height(), palette(), true, 1);
freeMemoryLabel->setText(i18n("%1 free", formattedUnit(last_used)));
return true;
}
QString Chart::formattedUnit(t_memsize value) {
if (value > (1024 * 1024))
if (value > (1024 * 1024 * 1024))
return i18n("%1 GiB", KGlobal::locale()->formatNumber(value / (1024 * 1024 * 1024.0), 2));
else
return i18n("%1 MiB", KGlobal::locale()->formatNumber(value / (1024 * 1024.0), 2));
else
return i18n("%1 KiB", KGlobal::locale()->formatNumber(value / 1024.0, 2));
}
ChartWidget::ChartWidget(const QString& title, const QString& hint, Chart* chartImplementation, QWidget* parent) :
QWidget(parent) {
QVBoxLayout* mainLayout = new QVBoxLayout(this);
titleLabel = new QLabel("<strong>" + title + "</strong>", this);
titleLabel->setAlignment(Qt::AlignHCenter);
titleLabel->setToolTip(hint);
mainLayout->addWidget(titleLabel);
chart = chartImplementation;
chart->setToolTip(hint);
mainLayout->addWidget(chart);
freeMemoryLabel = new QLabel("", this);
freeMemoryLabel->setAlignment(Qt::AlignHCenter);
freeMemoryLabel->setToolTip(hint);
mainLayout->addWidget(freeMemoryLabel);
chart->setFreeMemoryLabel(freeMemoryLabel);
}
void ChartWidget::setMemoryInfos(t_memsize* memoryInfos) {
chart->setMemoryInfos(memoryInfos);
}
void ChartWidget::refresh() {
//The update() method will launch paintEvent() automatically
chart->update();
}

View file

@ -0,0 +1,65 @@
/***************************************************************************
* -------------------------------------------------------------------- *
* Copyright (C) 2008, Nicolas Ternisien <nicolas.ternisien@gmail.com> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef CHART_WIDGET_H
#define CHART_WIDGET_H
#include <QWidget>
#include <QFrame>
#include <QString>
#include <QColor>
#include <QList>
class QLabel;
class QWidget;
#include "base.h"
class Chart : public QWidget {
public:
Chart(QWidget* parent = NULL);
void setMemoryInfos(t_memsize* memoryInfos);
void setFreeMemoryLabel(QLabel* freeMemoryLabel);
static QString formattedUnit(t_memsize value);
protected:
bool drawChart(t_memsize total, const QList<t_memsize>& used, const QList<QColor>& colors, const QList<QString>& texts);
t_memsize* memoryInfos;
QLabel* freeMemoryLabel;
};
class ChartWidget : public QWidget {
public:
/**
* Initialize the list view item and task.
*/
ChartWidget(const QString& title, const QString& hint, Chart* chartImplementation, QWidget* parent = NULL);
void setMemoryInfos(t_memsize* memoryInfos);
void refresh();
private:
QLabel* titleLabel;
Chart* chart;
QLabel* freeMemoryLabel;
};
#endif // CHART_WIDGET_H

View file

@ -1,13 +1,12 @@
[Desktop Entry]
Exec=kcmshell4 memory
Icon=kcmmemory
Exec=kcmshell4 kcm_memory
Icon=memory
Type=Service
X-KDE-ServiceTypes=KCModule
X-DocPath=kinfocenter/memory/index.html
X-KDE-Library=kcm_info
X-KDE-PluginKeyword=memory
X-KDE-Library=kcm_memory
X-KDE-ParentApp=kinfocenter
Name=Memory

View file

@ -0,0 +1,326 @@
/*
* memory.cpp
*
* Copyright (C) 2008 Ivo Anjo <knuckles@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "memory.h"
#include <QtGui>
#include <QStringList>
#include <QLayout>
#include <QPainter>
#include <QPixmap>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLinearGradient>
#include <kaboutdata.h>
#include <kdialog.h>
#include <kdebug.h>
#include <sys/param.h> /* for BSD */
#include <klocale.h>
#include <kglobal.h>
#include <kdialog.h>
#include <KPluginFactory>
#include <KPluginLoader>
#include "chartWidget.h"
#include "physicalMemoryChart.h"
#include "totalMemoryChart.h"
#include "swapMemoryChart.h"
/*
all fetchValues()-functions should put either
their results _OR_ the value NO_MEMORY_INFO into memoryInfos[]
*/
static t_memsize memoryInfos[MEM_LAST_ENTRY];
/******************/
/* Implementation */
/******************/
static QLabel *memorySizeLabels[MEM_LAST_ENTRY][2];
K_PLUGIN_FACTORY(KCMMemoryFactory,
registerPlugin<KCMMemory>();
)
K_EXPORT_PLUGIN(KCMMemoryFactory("kcm_memory"))
KCMMemory::KCMMemory(QWidget *parent, const QVariantList &) :
KCModule(KCMMemoryFactory::componentData(), parent) {
KAboutData *about = new KAboutData(I18N_NOOP("kcm_memory"), 0,
ki18n("KDE Panel Memory Information Control Module"),
0, KLocalizedString(), KAboutData::License_GPL,
ki18n("(c) 1998 - 2002 Helge Deller"));
about->addAuthor(ki18n("Helge Deller"), KLocalizedString(), "deller@gmx.de");
setAboutData(about);
QString title, initial_str;
setButtons(Help);
QVBoxLayout *top = new QVBoxLayout(this);
top->setMargin(0);
top->setSpacing(1);
QGroupBox* informationGroup = initializeText();
top->addWidget(informationGroup, 1);
// Now the Graphics
QGroupBox* graphicsGroup = initializeCharts();
top->addWidget(graphicsGroup, 2);
timer = new QTimer(this);
timer->start(100);
connect(timer, SIGNAL(timeout()), this, SLOT(updateDatas()));
updateDatas();
}
KCMMemory::~KCMMemory() {
/* stop the timer */
timer->stop();
}
QString KCMMemory::quickHelp() const {
return i18n(" This display shows you the current memory usage of your system."
" The values are updated on a regular basis and give you an"
" overview of the physical and virtual used memory.");
}
QGroupBox* KCMMemory::initializeText() {
QGroupBox* informationGroup = new QGroupBox("Memory");
QHBoxLayout *hbox = new QHBoxLayout(informationGroup);
/* stretch the left side */
hbox->addStretch();
QString title;
//TODO Use the more smart QGridLayout !!!
/* first create the Informationtext-Widget */
QVBoxLayout *vbox = new QVBoxLayout();
hbox->addLayout(vbox);
vbox->setSpacing(0);
for (int i = TOTAL_MEM; i < MEM_LAST_ENTRY; ++i) {
switch (i) {
case TOTAL_MEM:
title = i18n("Total physical memory:");
break;
case FREE_MEM:
title = i18n("Free physical memory:");
break;
#if !defined(__svr4__) || !defined(sun)
#if !defined(__NetBSD__) && !defined(__OpenBSD__)
case SHARED_MEM:
title = i18n("Shared memory:");
break;
case BUFFER_MEM:
title = i18n("Disk buffers:");
break;
#else
case ACTIVE_MEM:
title = i18n("Active memory:");
break;
case INACTIVE_MEM:
title = i18n("Inactive memory:");
break;
#endif
#endif
case CACHED_MEM:
title = i18n("Disk cache:");
break;
case SWAP_MEM:
vbox->addSpacing(SPACING);
title = i18n("Total swap memory:");
break;
case FREESWAP_MEM:
title = i18n("Free swap memory:");
break;
default:
title = "";
break;
};
QLabel* labelWidget = new QLabel(title, this);
labelWidget->setAlignment(Qt::AlignLeft);
vbox->addWidget(labelWidget);
}
vbox->addStretch();
/* then the memory-content-widgets */
for (int j = 0; j < 2; j++) {
vbox = new QVBoxLayout();
hbox->addLayout(vbox);
vbox->setSpacing(0);
for (int i = TOTAL_MEM; i < MEM_LAST_ENTRY; ++i) {
if (i == SWAP_MEM)
vbox->addSpacing(SPACING);
QLabel* labelWidget = new QLabel(this);
labelWidget->setAlignment(Qt::AlignRight);
memorySizeLabels[i][j] = labelWidget;
vbox->addWidget(labelWidget);
}
vbox->addStretch();
}
/* stretch the right side */
hbox->addStretch();
return informationGroup;
}
QGroupBox* KCMMemory::initializeCharts() {
QGroupBox* chartsGroup = new QGroupBox("Charts");
QHBoxLayout* chartsLayout = new QHBoxLayout(chartsGroup);
chartsLayout->setSpacing(1);
chartsLayout->setMargin(1);
//chartsLayout->addStretch(1);
totalMemory = new ChartWidget(i18n("Total Memory"),
i18n("This graph gives you an overview of the "
"<b>total sum of physical and virtual memory</b> "
"in your system."),
new TotalMemoryChart(this), this);
chartsLayout->addWidget(totalMemory);
chartsLayout->addSpacing(SPACING);
physicalMemory = new ChartWidget(i18n("Physical Memory"),
i18n("This graph gives you an overview of "
"the <b>usage of physical memory</b> in your system."
"<p>Most operating systems (including Linux) "
"will use as much of the available physical "
"memory as possible as disk cache, "
"to speed up the system performance.</p>"
"<p>This means that if you have a small amount "
"of <b>Free Physical Memory</b> and a large amount of "
"<b>Disk Cache Memory</b>, your system is well "
"configured.</p>"),
new PhysicalMemoryChart(this), this);
chartsLayout->addWidget(physicalMemory);
chartsLayout->addSpacing(SPACING);
swapMemory = new ChartWidget(i18n("Swap Space"),
i18n("<p>The swap space is the <b>virtual memory</b> "
"available to the system.</p> "
"<p>It will be used on demand and is provided "
"through one or more swap partitions and/or swap files.</p>"),
new SwapMemoryChart(this), this);
chartsLayout->addWidget(swapMemory);
//chartsLayout->addStretch(1);
return chartsGroup;
}
void KCMMemory::updateDatas() {
/* get the Information from memory_linux, memory_fbsd */
fetchValues();
updateMemoryText();
updateMemoryGraphics();
}
void KCMMemory::updateMemoryText() {
/* update the byte-strings */
for (int i = TOTAL_MEM; i < MEM_LAST_ENTRY; i++) {
QLabel* label = memorySizeLabels[i][0];
if (memoryInfos[i] == NO_MEMORY_INFO)
label->clear();
else
label->setText(i18n("%1 bytes =", KGlobal::locale()->
formatNumber(memoryInfos[i], 0)));
}
/* update the MB-strings */
for (int i = TOTAL_MEM; i < MEM_LAST_ENTRY; i++) {
QLabel* label = memorySizeLabels[i][1];
label->setText((memoryInfos[i] != NO_MEMORY_INFO) ? Chart::formattedUnit(memoryInfos[i]) : i18n("Not available."));
}
}
void KCMMemory::updateMemoryGraphics() {
totalMemory->setMemoryInfos(memoryInfos);
totalMemory->refresh();
physicalMemory->setMemoryInfos(memoryInfos);
physicalMemory->refresh();
swapMemory->setMemoryInfos(memoryInfos);
swapMemory->refresh();
}
/* Include system-specific code */
#ifdef __linux__
#include "memory_linux.cpp"
#elif defined(__APPLE__)
#include "memory_osx.cpp"
#elif defined(sgi) && sgi
#include "memory_sgi.cpp"
#elif defined(__svr4__) && defined(sun)
#include "memory_solaris.cpp"
#elif defined(__FreeBSD__) || defined(__DragonFly__)
#include "memory_fbsd.cpp"
#elif defined(__hpux)
#include "memory_hpux.cpp"
#elif defined(__NetBSD__) || defined(__OpenBSD__)
#include "memory_netbsd.cpp"
#elif __osf__
#include "memory_tru64.cpp"
#else
/* Default for unsupported systems */
void KCMMemory::fetchValues() {
int i;
for (i = TOTAL_MEM; i < MEM_LAST_ENTRY; ++i) {
memoryInfos[i] = NO_MEMORY_INFO;
}
}
#endif
#include "memory.moc"

View file

@ -0,0 +1,71 @@
/*
* memory.h
*
* Copyright (C) 2008 Nicolas Ternisien <nicolas.ternisien@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KCONTROL_MEMORY_H
#define KCONTROL_MEMORY_H
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QTimer>
#include <kcmodule.h>
#include <kaboutdata.h>
#include "base.h"
class QGroupBox;
class QStringList;
class QPushButton;
class QTreeWidget;
class ChartWidget;
class KCMMemory : public KCModule {
Q_OBJECT
public:
explicit KCMMemory(QWidget *parent = NULL, const QVariantList &list = QVariantList());
~KCMMemory();
QString quickHelp() const;
private slots:
void updateMemoryText();
void updateMemoryGraphics();
void updateDatas();
private:
QGroupBox* initializeText();
QGroupBox* initializeCharts();
QTimer *timer;
ChartWidget* totalMemory;
ChartWidget* physicalMemory;
ChartWidget* swapMemory;
void fetchValues();
};
#endif

View file

@ -9,7 +9,7 @@
#include <stdio.h>
#include <unistd.h>
void KMemoryWidget::fetchValues()
void KCMMemory::fetchValues()
{
char blah[10], buf[80], *used_str, *total_str;
/* Stuff for sysctl */
@ -26,14 +26,14 @@ void KMemoryWidget::fetchValues()
// Numerical values
// total physical memory (without swap space)
Memory_Info[TOTAL_MEM] = MEMORY(memory);
memoryInfos[TOTAL_MEM] = MEMORY(memory);
// added by Brad Hughes bhughes@trolltech.com
struct vmtotal vmem;
#ifdef __GNUC__
#warning "FIXME: Memory_Info[CACHED_MEM]"
#warning "FIXME: memoryInfos[CACHED_MEM]"
#endif
Memory_Info[CACHED_MEM] = NO_MEMORY_INFO;
memoryInfos[CACHED_MEM] = NO_MEMORY_INFO;
// The sysctls don't work in a nice manner under FreeBSD v2.2.x
// so we assume that if sysctlbyname doesn't return what we
@ -43,24 +43,24 @@ void KMemoryWidget::fetchValues()
len = sizeof(vmem);
if (sysctlbyname("vm.vmmeter", &vmem, &len, NULL, 0) == 0)
Memory_Info[SHARED_MEM] = MEMORY(vmem.t_armshr) * PAGE_SIZE;
memoryInfos[SHARED_MEM] = MEMORY(vmem.t_armshr) * PAGE_SIZE;
else
Memory_Info[SHARED_MEM] = NO_MEMORY_INFO;
memoryInfos[SHARED_MEM] = NO_MEMORY_INFO;
int buffers;
len = sizeof (buffers);
if ((sysctlbyname("vfs.bufspace", &buffers, &len, NULL, 0) == -1) || !len)
Memory_Info[BUFFER_MEM] = NO_MEMORY_INFO;
memoryInfos[BUFFER_MEM] = NO_MEMORY_INFO;
else
Memory_Info[BUFFER_MEM] = MEMORY(buffers);
memoryInfos[BUFFER_MEM] = MEMORY(buffers);
// total free physical memory (without swap space)
int free;
len = sizeof (buffers);
if ((sysctlbyname("vm.stats.vm.v_free_count", &free, &len, NULL, 0) == -1) || !len)
Memory_Info[FREE_MEM] = NO_MEMORY_INFO;
memoryInfos[FREE_MEM] = NO_MEMORY_INFO;
else
Memory_Info[FREE_MEM] = MEMORY(free) * getpagesize();
memoryInfos[FREE_MEM] = MEMORY(free) * getpagesize();
// Q&D hack for swap display. Borrowed from xsysinfo-1.4
if ((pipe = popen("/usr/sbin/pstat -ks", "r")) == NULL) {
@ -83,8 +83,8 @@ void KMemoryWidget::fetchValues()
_free=total-used;
// total size of all swap-partitions
Memory_Info[SWAP_MEM] = MEMORY(total) * 1024;
memoryInfos[SWAP_MEM] = MEMORY(total) * 1024;
// free memory in swap-partitions
Memory_Info[FREESWAP_MEM] = MEMORY(_free) * 1024;
memoryInfos[FREESWAP_MEM] = MEMORY(_free) * 1024;
}

View file

@ -24,7 +24,7 @@
#define MAX_SWAP_AREAS 16
void KMemoryWidget::fetchValues()
void KCMMemory::fetchValues()
{
int page_size,i;
unsigned long total_mem, total_free,
@ -79,14 +79,14 @@ void KMemoryWidget::fetchValues()
total_mem = total_physical; // + total_swap;
total_free = (total_physical - used_physical);// + free_swap;
Memory_Info[TOTAL_MEM] = MEMORY(total_mem); // total physical memory (without swaps)
Memory_Info[FREE_MEM] = MEMORY(total_free);// total free physical memory (without swaps)
Memory_Info[SHARED_MEM] = NO_MEMORY_INFO; /* FIXME ?? */
Memory_Info[BUFFER_MEM] = MEMORY(fields_[2])*page_size; /* FIXME ?? */
Memory_Info[SWAP_MEM] = MEMORY(total_swap); // total size of all swap-partitions
Memory_Info[FREESWAP_MEM] = MEMORY(free_swap); // free memory in swap-partitions
memoryInfos[TOTAL_MEM] = MEMORY(total_mem); // total physical memory (without swaps)
memoryInfos[FREE_MEM] = MEMORY(total_free);// total free physical memory (without swaps)
memoryInfos[SHARED_MEM] = NO_MEMORY_INFO; /* FIXME ?? */
memoryInfos[BUFFER_MEM] = MEMORY(fields_[2])*page_size; /* FIXME ?? */
memoryInfos[SWAP_MEM] = MEMORY(total_swap); // total size of all swap-partitions
memoryInfos[FREESWAP_MEM] = MEMORY(free_swap); // free memory in swap-partitions
#ifdef __GNUC__
#warning "FIXME: Memory_Info[CACHED_MEM]"
#warning "FIXME: memoryInfos[CACHED_MEM]"
#endif
Memory_Info[CACHED_MEM] = NO_MEMORY_INFO; // cached memory in ram
memoryInfos[CACHED_MEM] = NO_MEMORY_INFO; // cached memory in ram
}

View file

@ -3,7 +3,7 @@
#include <stdlib.h>
#include <QFile>
void KMemoryWidget::fetchValues()
void KCMMemory::fetchValues()
{
struct sysinfo info;
@ -16,12 +16,12 @@ void KMemoryWidget::fetchValues()
const int mem_unit = info.mem_unit;
Memory_Info[TOTAL_MEM] = MEMORY(info.totalram) * mem_unit; // total physical memory (without swaps)
Memory_Info[FREE_MEM] = MEMORY(info.freeram) * mem_unit; // total free physical memory (without swaps)
Memory_Info[SHARED_MEM] = MEMORY(info.sharedram) * mem_unit;
Memory_Info[BUFFER_MEM] = MEMORY(info.bufferram) * mem_unit;
Memory_Info[SWAP_MEM] = MEMORY(info.totalswap) * mem_unit; // total size of all swap-partitions
Memory_Info[FREESWAP_MEM] = MEMORY(info.freeswap) * mem_unit; // free memory in swap-partitions
memoryInfos[TOTAL_MEM] = MEMORY(info.totalram) * mem_unit; // total physical memory (without swaps)
memoryInfos[FREE_MEM] = MEMORY(info.freeram) * mem_unit; // total free physical memory (without swaps)
memoryInfos[SHARED_MEM] = MEMORY(info.sharedram) * mem_unit;
memoryInfos[BUFFER_MEM] = MEMORY(info.bufferram) * mem_unit;
memoryInfos[SWAP_MEM] = MEMORY(info.totalswap) * mem_unit; // total size of all swap-partitions
memoryInfos[FREESWAP_MEM] = MEMORY(info.freeswap) * mem_unit; // free memory in swap-partitions
QFile file("/proc/meminfo");
if (file.open(QIODevice::ReadOnly)) {
@ -30,7 +30,7 @@ void KMemoryWidget::fetchValues()
if (strncmp(buf,"Cached:",7)==0) {
unsigned long v;
v = strtoul(&buf[7],NULL,10);
Memory_Info[CACHED_MEM] = MEMORY(v) * 1024; // Cached memory in RAM
memoryInfos[CACHED_MEM] = MEMORY(v) * 1024; // Cached memory in RAM
break;
}
}

View file

@ -17,7 +17,7 @@
#include <vm/vm_swap.h>
#endif
void KMemoryWidget::fetchValues()
void KCMMemory::fetchValues()
{
int mib[2];
size_t len;
@ -47,9 +47,9 @@ void KMemoryWidget::fetchValues()
#endif
len = sizeof(memory);
if( sysctl(mib,2,&memory,&len,NULL,0)< 0 )
Memory_Info[TOTAL_MEM] = NO_MEMORY_INFO;
memoryInfos[TOTAL_MEM] = NO_MEMORY_INFO;
else
Memory_Info[TOTAL_MEM] = memory;
memoryInfos[TOTAL_MEM] = memory;
#ifdef UVM
mib[0] = CTL_VM;
@ -60,29 +60,29 @@ void KMemoryWidget::fetchValues()
#endif
len = sizeof(uvmexp);
if ( sysctl(mib, 2, &uvmexp, &len, NULL, 0) < 0 ) {
Memory_Info[FREE_MEM] = NO_MEMORY_INFO;
Memory_Info[ACTIVE_MEM] = NO_MEMORY_INFO;
Memory_Info[INACTIVE_MEM] = NO_MEMORY_INFO;
Memory_Info[SWAP_MEM] = NO_MEMORY_INFO;
Memory_Info[FREESWAP_MEM] = NO_MEMORY_INFO;
Memory_Info[CACHED_MEM] = NO_MEMORY_INFO;
memoryInfos[FREE_MEM] = NO_MEMORY_INFO;
memoryInfos[ACTIVE_MEM] = NO_MEMORY_INFO;
memoryInfos[INACTIVE_MEM] = NO_MEMORY_INFO;
memoryInfos[SWAP_MEM] = NO_MEMORY_INFO;
memoryInfos[FREESWAP_MEM] = NO_MEMORY_INFO;
memoryInfos[CACHED_MEM] = NO_MEMORY_INFO;
} else {
t_memsize pgsz = MEMORY(uvmexp.pagesize);
Memory_Info[FREE_MEM] = pgsz * uvmexp.free;
Memory_Info[ACTIVE_MEM] = pgsz * uvmexp.active;
Memory_Info[INACTIVE_MEM] = pgsz * uvmexp.inactive;
Memory_Info[SWAP_MEM] = pgsz * uvmexp.swpages;
Memory_Info[FREESWAP_MEM] = pgsz * (uvmexp.swpages - uvmexp.swpginuse);
memoryInfos[FREE_MEM] = pgsz * uvmexp.free;
memoryInfos[ACTIVE_MEM] = pgsz * uvmexp.active;
memoryInfos[INACTIVE_MEM] = pgsz * uvmexp.inactive;
memoryInfos[SWAP_MEM] = pgsz * uvmexp.swpages;
memoryInfos[FREESWAP_MEM] = pgsz * (uvmexp.swpages - uvmexp.swpginuse);
#if __NetBSD_Version__ > 106000000
Memory_Info[CACHED_MEM] = pgsz * (uvmexp.filepages + uvmexp.execpages);
memoryInfos[CACHED_MEM] = pgsz * (uvmexp.filepages + uvmexp.execpages);
#else
Memory_Info[CACHED_MEM] = NO_MEMORY_INFO;
memoryInfos[CACHED_MEM] = NO_MEMORY_INFO;
#endif
}
#else
Memory_Info[FREE_MEM] = NO_MEMORY_INFO;
Memory_Info[ACTIVE_MEM] = NO_MEMORY_INFO;
Memory_Info[INACTIVE_MEM] = NO_MEMORY_INFO;
memoryInfos[FREE_MEM] = NO_MEMORY_INFO;
memoryInfos[ACTIVE_MEM] = NO_MEMORY_INFO;
memoryInfos[INACTIVE_MEM] = NO_MEMORY_INFO;
/* swap */
totalswap = freeswap = usedswap = 0;
@ -103,11 +103,11 @@ void KMemoryWidget::fetchValues()
totalswap = freeswap = -1; /* Error */
if ( totalswap == -1 ) {
Memory_Info[SWAP_MEM] = NO_MEMORY_INFO;
Memory_Info[FREESWAP_MEM] = NO_MEMORY_INFO;
memoryInfos[SWAP_MEM] = NO_MEMORY_INFO;
memoryInfos[FREESWAP_MEM] = NO_MEMORY_INFO;
} else {
Memory_Info[SWAP_MEM] = MEMORY(totalswap);
Memory_Info[FREESWAP_MEM] = MEMORY(freeswap);
memoryInfos[SWAP_MEM] = MEMORY(totalswap);
memoryInfos[FREESWAP_MEM] = MEMORY(freeswap);
}
}
#endif

View file

@ -29,7 +29,7 @@
#include <dirent.h>
#include <kdebug.h>
void KMemoryWidget::fetchValues()
void KCMMemory::fetchValues()
{
vm_statistics_data_t vm_info;
@ -44,12 +44,12 @@ void KMemoryWidget::fetchValues()
return;
}
Memory_Info[TOTAL_MEM] = MEMORY(vm_info.active_count + vm_info.inactive_count +
memoryInfos[TOTAL_MEM] = MEMORY(vm_info.active_count + vm_info.inactive_count +
vm_info.free_count + vm_info.wire_count) * vm_page_size;
Memory_Info[FREE_MEM] = MEMORY(vm_info.free_count) * vm_page_size;
Memory_Info[SHARED_MEM] = NO_MEMORY_INFO;
Memory_Info[BUFFER_MEM] = NO_MEMORY_INFO;
Memory_Info[CACHED_MEM] = NO_MEMORY_INFO;
memoryInfos[FREE_MEM] = MEMORY(vm_info.free_count) * vm_page_size;
memoryInfos[SHARED_MEM] = NO_MEMORY_INFO;
memoryInfos[BUFFER_MEM] = NO_MEMORY_INFO;
memoryInfos[CACHED_MEM] = NO_MEMORY_INFO;
dirp = opendir("/private/var/vm");
if (!dirp) {
@ -81,9 +81,9 @@ void KMemoryWidget::fetchValues()
kDebug() << "unable to get VM info";
}
Memory_Info[SWAP_MEM] = total;
memoryInfos[SWAP_MEM] = total;
// off_t used = (vm_info.pageouts - vm_info.pageins) * vm_page_size;
Memory_Info[FREESWAP_MEM] = NO_MEMORY_INFO;
memoryInfos[FREESWAP_MEM] = NO_MEMORY_INFO;
/* free = MEMORY(vm_info.free_count) * vm_page_size;
used = MEMORY(vm_info.active_count) * vm_page_size;

View file

@ -16,35 +16,35 @@
#endif
void KMemoryWidget::fetchValues()
void KCMMemory::fetchValues()
{
int pagesize = getpagesize();
struct rminfo rmi;
if( sysmp(MP_SAGET, MPSA_RMINFO, &rmi, sizeof(rmi)) == -1 )
return;
Memory_Info[TOTAL_MEM] = MEMORY(rmi.physmem) * pagesize; // total physical memory (without swaps)
Memory_Info[FREE_MEM] = MEMORY(rmi.freemem) * pagesize; // total free physical memory (without swaps)
Memory_Info[BUFFER_MEM] = MEMORY(rmi.bufmem) * pagesize;
memoryInfos[TOTAL_MEM] = MEMORY(rmi.physmem) * pagesize; // total physical memory (without swaps)
memoryInfos[FREE_MEM] = MEMORY(rmi.freemem) * pagesize; // total free physical memory (without swaps)
memoryInfos[BUFFER_MEM] = MEMORY(rmi.bufmem) * pagesize;
//FIXME: Memory_Info[CACHED_MEM]"
Memory_Info[CACHED_MEM] = NO_MEMORY_INFO; // cached memory in ram
//FIXME: memoryInfos[CACHED_MEM]"
memoryInfos[CACHED_MEM] = NO_MEMORY_INFO; // cached memory in ram
long val;
swapctl(SC_GETSWAPTOT, &val);
Memory_Info[SWAP_MEM] = MEMORY(val) * UBSIZE; // total size of all swap-partitions
memoryInfos[SWAP_MEM] = MEMORY(val) * UBSIZE; // total size of all swap-partitions
swapctl(SC_GETFREESWAP, &val);
Memory_Info[FREESWAP_MEM] = MEMORY(val) * UBSIZE; // free memory in swap-partitions
memoryInfos[FREESWAP_MEM] = MEMORY(val) * UBSIZE; // free memory in swap-partitions
#ifndef MPKA_SHMINFO
/* Irix 6.5 (also 6.4?) */
Memory_Info[SHARED_MEM] = NO_MEMORY_INFO;
memoryInfos[SHARED_MEM] = NO_MEMORY_INFO;
#else
FILE *kmem = fopen("/dev/kmem", "r");
if( kmem == 0 ) {
Memory_Info[SHARED_MEM] = NO_MEMORY_INFO;
memoryInfos[SHARED_MEM] = NO_MEMORY_INFO;
return;
}
@ -68,7 +68,7 @@ void KMemoryWidget::fetchValues()
val += shmid.shm_segsz;
}
}
Memory_Info[SHARED_MEM] = MEMORY(val);
memoryInfos[SHARED_MEM] = MEMORY(val);
fclose(kmem);
#endif

View file

@ -21,7 +21,7 @@
#define PAGETOK(a) (( (t_memsize) sysconf( _SC_PAGESIZE )) * (t_memsize) a)
void KMemoryWidget::fetchValues() {
void KCMMemory::fetchValues() {
kstat_ctl_t *kctl;
kstat_t *ksp;
@ -50,18 +50,18 @@ void KMemoryWidget::fetchValues() {
#if 0
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "physmem" );
if( kdata != NULL ) {
Memory_Info[TOTAL_MEM] = PAGETOK(kdata->value.ui32);
memoryInfos[TOTAL_MEM] = PAGETOK(kdata->value.ui32);
}
#endif
Memory_Info[TOTAL_MEM] = PAGETOK(sysconf(_SC_PHYS_PAGES));
memoryInfos[TOTAL_MEM] = PAGETOK(sysconf(_SC_PHYS_PAGES));
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "freemem" );
if( kdata != NULL )
Memory_Info[FREE_MEM] = PAGETOK(kdata->value.ui32);
memoryInfos[FREE_MEM] = PAGETOK(kdata->value.ui32);
#ifdef __GNUC__
#warning "FIXME: Memory_Info[CACHED_MEM]"
#warning "FIXME: memoryInfos[CACHED_MEM]"
#endif
Memory_Info[CACHED_MEM] = NO_MEMORY_INFO; // cached memory in ram
memoryInfos[CACHED_MEM] = NO_MEMORY_INFO; // cached memory in ram
kstat_close( kctl );
@ -90,6 +90,6 @@ void KMemoryWidget::fetchValues() {
swapused = am_swap.ani_resv;
swapfree = swaptotal - swapused;
Memory_Info[SWAP_MEM] = PAGETOK(swaptotal);
Memory_Info[FREESWAP_MEM] = PAGETOK(swapfree);
memoryInfos[SWAP_MEM] = PAGETOK(swaptotal);
memoryInfos[FREESWAP_MEM] = PAGETOK(swapfree);
}

View file

@ -27,7 +27,7 @@ extern "C" {
extern "C" void vm_statistics(task_t, vm_statistics_data_t*);
void KMemoryWidget::fetchValues()
void KCMMemory::fetchValues()
{
int pageshift; /* log base 2 of the pagesize */
register int pagesize;
@ -67,17 +67,17 @@ void KMemoryWidget::fetchValues()
swap_free += swbuf.free;
i++;
}
Memory_Info[TOTAL_MEM] = pagetob((vmstats.free_count +
memoryInfos[TOTAL_MEM] = pagetob((vmstats.free_count +
vmstats.active_count +
vmstats.inactive_count +
vmstats.wire_count));
Memory_Info[FREE_MEM] = pagetob(vmstats.free_count);
Memory_Info[SHARED_MEM] = NO_MEMORY_INFO; /* FIXME ?? */
Memory_Info[BUFFER_MEM] = NO_MEMORY_INFO; /* FIXME ?? */
memoryInfos[FREE_MEM] = pagetob(vmstats.free_count);
memoryInfos[SHARED_MEM] = NO_MEMORY_INFO; /* FIXME ?? */
memoryInfos[BUFFER_MEM] = NO_MEMORY_INFO; /* FIXME ?? */
#ifdef __GNUC__
#warning "FIXME: Memory_Info[CACHED_MEM]"
#warning "FIXME: memoryInfos[CACHED_MEM]"
#endif
Memory_Info[CACHED_MEM] = NO_MEMORY_INFO; /* cached memory in ram */
Memory_Info[SWAP_MEM] = pagetob(swap_pages);
Memory_Info[FREESWAP_MEM] = pagetob(swap_free);
memoryInfos[CACHED_MEM] = NO_MEMORY_INFO; /* cached memory in ram */
memoryInfos[SWAP_MEM] = pagetob(swap_pages);
memoryInfos[FREESWAP_MEM] = pagetob(swap_free);
}

View file

@ -0,0 +1,63 @@
/***************************************************************************
* KT list view item task implementation. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "physicalMemoryChart.h"
#include <klocale.h>
#include <kdebug.h>
#include "base.h"
PhysicalMemoryChart::PhysicalMemoryChart(QWidget* parent) :
Chart(parent) {
colorsInitialized = false;
}
void PhysicalMemoryChart::paintEvent(QPaintEvent* /*event*/) {
/* RAM usage: */
/* don't rely on the SHARED_MEM value since it may refer to
* the size of the System V sharedmem in 2.4.x. Calculate instead! */
t_memsize bufferMemory;
bufferMemory = 0;
#if !defined(__svr4__) || !defined(sun)
#if !defined(__NetBSD__) && !defined(__OpenBSD__)
bufferMemory = ZERO_IF_NO_INFO(memoryInfos[BUFFER_MEM]);
#endif
#endif
t_memsize cachedMemory = ZERO_IF_NO_INFO(memoryInfos[CACHED_MEM]);
t_memsize freeMemory = ZERO_IF_NO_INFO(memoryInfos[FREE_MEM]);
t_memsize totalMemory = ZERO_IF_NO_INFO(memoryInfos[TOTAL_MEM]) - bufferMemory - cachedMemory - freeMemory;
QList<t_memsize> used;
used.append(freeMemory);
used.append(cachedMemory);
used.append(bufferMemory);
used.append(totalMemory);
if (!colorsInitialized) {
colorsInitialized = true;
texts.append(i18n("Free Physical Memory"));
colors.append(COLOR_FREE_MEMORY); // free
texts.append(i18n("Disk Cache"));
colors.append(QColor(88, 176, 36)); // cached
texts.append(i18n("Disk Buffers"));
colors.append(QColor(118, 237, 49)); // buffer
texts.append(i18n("Application Data"));
colors.append(COLOR_USED_MEMORY); // used+shared
}
drawChart(memoryInfos[TOTAL_MEM], used, colors, texts);
}

View file

@ -0,0 +1,42 @@
/***************************************************************************
* -------------------------------------------------------------------- *
* Copyright (C) 2008, Nicolas Ternisien <nicolas.ternisien@gmail.com> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef PHYSICAL_MEMORY_CHART_H
#define PHYSICAL_MEMORY_CHART_H
#include <QFrame>
#include <QList>
#include "chartWidget.h"
class QWidget;
class QPaintEvent;
class PhysicalMemoryChart : public Chart {
public:
/**
* Initialize the list view item and task.
*/
PhysicalMemoryChart(QWidget* parent = NULL);
protected:
virtual void paintEvent(QPaintEvent* event);
private:
bool colorsInitialized;
QList<QColor> colors;
QList<QString> texts;
};
#endif // PHYSICAL_MEMORY_CHART_H

View file

@ -0,0 +1,51 @@
/***************************************************************************
* KT list view item task implementation. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "swapMemoryChart.h"
#include <klocale.h>
#include <kdebug.h>
#include "base.h"
SwapMemoryChart::SwapMemoryChart(QWidget* parent) :
Chart(parent) {
colorsInitialized = false;
}
void SwapMemoryChart::paintEvent(QPaintEvent* /*event*/) {
/* display graphical output (ram, hdd, at last: HDD+RAM) */
/* be careful ! Maybe we have not all info available ! */
// SWAP usage:
t_memsize freeSwap = ZERO_IF_NO_INFO(memoryInfos[FREESWAP_MEM]);
t_memsize swap = ZERO_IF_NO_INFO(memoryInfos[SWAP_MEM]) - freeSwap;
QList<t_memsize> used;
used.append(freeSwap);
used.append(swap);
if (!colorsInitialized) {
colorsInitialized = true;
texts.append(i18n("Free Swap"));
colors.append(COLOR_FREE_MEMORY); // free
texts.append(i18n("Used Swap"));
colors.append(COLOR_USED_SWAP); // used swap
}
drawChart(memoryInfos[SWAP_MEM], used, colors, texts);
}

View file

@ -0,0 +1,42 @@
/***************************************************************************
* -------------------------------------------------------------------- *
* Copyright (C) 2008, Nicolas Ternisien <nicolas.ternisien@gmail.com> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef SWAP_MEMORY_CHART_H
#define SWAP_MEMORY_CHART_H
#include <QFrame>
#include <QList>
#include "chartWidget.h"
class QWidget;
class QPaintEvent;
class SwapMemoryChart : public Chart {
public:
/**
* Initialize the list view item and task.
*/
SwapMemoryChart(QWidget* parent = NULL);
protected:
virtual void paintEvent(QPaintEvent* event);
private:
bool colorsInitialized;
QList<QColor> colors;
QList<QString> texts;
};
#endif // SWAP_MEMORY_CHART_H

View file

@ -0,0 +1,53 @@
/***************************************************************************
* KT list view item task implementation. *
* -------------------------------------------------------------------- *
* Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "totalMemoryChart.h"
#include <klocale.h>
#include <kdebug.h>
#include "base.h"
TotalMemoryChart::TotalMemoryChart(QWidget* parent) :
Chart(parent) {
colorsInitialized = false;
}
void TotalMemoryChart::paintEvent(QPaintEvent* /*event*/) {
// RAM + SWAP usage:
if (memoryInfos[SWAP_MEM] == NO_MEMORY_INFO || memoryInfos[FREESWAP_MEM] == NO_MEMORY_INFO)
memoryInfos[SWAP_MEM] = memoryInfos[FREESWAP_MEM] = 0;
t_memsize usedSwap = memoryInfos[SWAP_MEM] - memoryInfos[FREESWAP_MEM];
t_memsize totalFree = memoryInfos[FREE_MEM] + memoryInfos[FREESWAP_MEM];
t_memsize usedPhysical = (memoryInfos[TOTAL_MEM]+memoryInfos[SWAP_MEM])-usedSwap-totalFree;
QList<t_memsize> used;
used.append(totalFree);
used.append(usedSwap);
used.append(usedPhysical);
if (!colorsInitialized) {
colorsInitialized = true;
texts.append(i18n("Total Free Memory"));
colors.append(COLOR_FREE_MEMORY); // free ram+swap
texts.append(i18n("Used Swap"));
colors.append(COLOR_USED_SWAP); // used swap
texts.append(i18n("Used Physical Memory"));
colors.append(COLOR_USED_MEMORY); // used ram
}
drawChart(memoryInfos[TOTAL_MEM] + memoryInfos[SWAP_MEM], used, colors, texts);
}

View file

@ -0,0 +1,42 @@
/***************************************************************************
* -------------------------------------------------------------------- *
* Copyright (C) 2008, Nicolas Ternisien <nicolas.ternisien@gmail.com> *
* -------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef TOTAL_MEMORY_CHART_H
#define TOTAL_MEMORY_CHART_H
#include <QFrame>
#include <QList>
#include "chartWidget.h"
class QWidget;
class QPaintEvent;
class TotalMemoryChart : public Chart {
public:
/**
* Initialize the list view item and task.
*/
TotalMemoryChart(QWidget* parent = NULL);
protected:
virtual void paintEvent(QPaintEvent* event);
private:
bool colorsInitialized;
QList<QColor> colors;
QList<QString> texts;
};
#endif // TOTAL_MEMORY_CHART_H

View file

@ -1,58 +0,0 @@
/*
Copyright (c) 2001 Daniel Molkentin <molkentin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "moduleIface.h"
#include "moduleIface.moc"
#include <QtDBus/qdbusconnection.h>
#include <kdebug.h>
#include <kconfig.h>
#include <kconfiggroup.h>
ModuleIface::ModuleIface(QObject *parent, const char *name)
: QObject(parent) {
QDBusConnection::sessionBus().registerObject('/'+QString(name), this, QDBusConnection::ExportScriptableSlots);
setObjectName( name );
_parent = static_cast<QWidget *>(parent);
}
ModuleIface::~ModuleIface() {
}
#ifdef __GNUC__
#warning "kde4: DBUS port "
#endif
#if 0
QFont ModuleIface::getFont() {
return _parent->font();
}
QPalette ModuleIface::getPalette(){
kDebug(1208) << "Returned Palette";
return _parent->palette();
}
#endif
QString ModuleIface::getStyle() const {
KConfig _config( "kdeglobals" );
KConfigGroup config(&_config, "General" );
return config.readEntry("widgetStyle");
}
void ModuleIface::invokeHelp() {
emit helpClicked();
}

View file

@ -1,53 +0,0 @@
/*
Copyright (c) 2001 Daniel Molkentin <molkentin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __moduleIface_h__
#define __moduleIface_h__
#include <QFont>
#include <QPalette>
#include <QWidget>
class ModuleIface : public QObject {
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kinfocenter")
public:
ModuleIface(QObject *parent, const char *name);
~ModuleIface();
public Q_SLOTS:
#if 0
Q_SCRIPTABLE QFont getFont();
Q_SCRIPTABLE QPalette getPalette();
#endif
Q_SCRIPTABLE QString getStyle() const;
Q_SCRIPTABLE void invokeHelp();
signals:
void helpClicked();
private:
QWidget *_parent;
};
#endif

View file

@ -1,171 +0,0 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 2003 Daniel Molkentin <molkentin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "moduleiconview.h"
#include "modules.h"
#include "global.h"
#include <Qt3Support/Q3Header>
#include <QPixmap>
#include <QKeyEvent>
#include <Q3PtrList>
#include <QApplication>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kservicegroup.h>
#include <kiconloader.h>
#include <kdebug.h>
#include "moduleiconview.moc"
ModuleIconView::ModuleIconView(ConfigModuleList *list, QWidget * parent)
: K3ListView(parent)
, _path(KCGlobal::baseGroup())
, _modules(list)
{
setSorting(1, true);
addColumn(QString());
// Needed to enforce a cut of the items label rather than
// showing a horizontal scrollbar
setResizeMode(LastColumn);
header()->hide();
// This is intentionally _not_ connected with executed(), since
// honoring doubleclick doesn't make any sense here (changed by
// large user demand)
connect(this, SIGNAL(clicked(Q3ListViewItem*)),
this, SLOT(slotItemSelected(Q3ListViewItem*)));
}
void ModuleIconView::makeSelected(ConfigModule *m)
{
if (!m) return;
for (Q3ListViewItem *i = firstChild(); i; i = i->nextSibling())
{
if(static_cast<ModuleIconItem*>(i)->module() == m)
{
setSelected(i, true);
break;
}
}
}
void ModuleIconView::makeVisible(ConfigModule *m)
{
if (!m) return;
QString tmp = _modules->findModule(m);
if (tmp.isEmpty())
return;
_path = tmp;
fill();
}
void ModuleIconView::fill()
{
clear();
QPixmap icon;
// add our "up" icon if we aren't top level
if (_path != KCGlobal::baseGroup())
{
icon = loadIcon( "go-previous" );
// go-back node
ModuleIconItem *i = new ModuleIconItem(this, i18nc("go back", "Back"), icon);
i->setOrderNo(0);
int last_slash = _path.lastIndexOf('/', -2);
if (last_slash == -1)
i->setTag(QString());
else
i->setTag(_path.left(last_slash+1));
}
int c = 0;
QStringList submenus = _modules->submenus(_path);
for (QStringList::Iterator it = submenus.begin(); it != submenus.end(); ++it )
{
QString path = (*it);
KServiceGroup::Ptr group = KServiceGroup::group(path);
if (!group || !group->isValid())
continue;
icon = loadIcon( group->icon() );
ModuleIconItem *i = new ModuleIconItem(this, group->caption(), icon);
i->setTag(path);
i->setOrderNo(++c);
}
c = 0;
Q3PtrList<ConfigModule> moduleList = _modules->modules(_path);
for (ConfigModule *module=moduleList.first(); module != 0; module=moduleList.next())
{
icon = loadIcon( module->icon() );
ModuleIconItem *i = new ModuleIconItem(this, module->moduleName(), icon, module);
i->setOrderNo(++c);
}
}
void ModuleIconView::slotItemSelected(Q3ListViewItem* item)
{
QApplication::restoreOverrideCursor();
if (!item) return;
if (static_cast<ModuleIconItem*>(item)->module())
{
emit moduleSelected(static_cast<ModuleIconItem*>(item)->module());
}
else
{
_path = static_cast<ModuleIconItem*>(item)->tag();
fill();
setCurrentItem(firstChild());
}
}
void ModuleIconView::keyPressEvent(QKeyEvent *e)
{
if( e->key() == Qt::Key_Return
|| e->key() == Qt::Key_Enter
|| e->key() == Qt::Key_Space)
{
if (currentItem())
slotItemSelected(currentItem());
}
else
{
K3ListView::keyPressEvent(e);
}
}
QPixmap ModuleIconView::loadIcon( const QString &name )
{
QPixmap icon = DesktopIcon( name, KCGlobal::iconSize() );
if(icon.isNull())
icon = DesktopIcon( "folder", KCGlobal::iconSize() );
return icon;
}

View file

@ -1,89 +0,0 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __moduleiconview_h__
#define __moduleiconview_h__
#include <k3listview.h>
//Added by qt3to4:
#include <QPixmap>
#include <QKeyEvent>
class ConfigModule;
class ConfigModuleList;
class ModuleIconItem : public K3ListViewItem
{
public:
ModuleIconItem(Q3ListView *parent, const QString& text, const QPixmap& pm, ConfigModule *m = 0)
: K3ListViewItem(parent, text)
, _tag(QString())
, _module(m)
{
setPixmap(0, pm);
}
void setConfigModule(ConfigModule* m) { _module = m; }
void setTag(const QString& t) { _tag = t; }
void setOrderNo(int order)
{
QString s;
setText(1, s.sprintf( "%02d", order ) );
}
ConfigModule* module() { return _module; }
QString tag() { return _tag; }
private:
QString _tag;
ConfigModule *_module;
};
class ModuleIconView : public K3ListView
{
Q_OBJECT
public:
explicit ModuleIconView(ConfigModuleList *list, QWidget * parent = 0);
void makeSelected(ConfigModule* module);
void makeVisible(ConfigModule *module);
void fill();
Q_SIGNALS:
void moduleSelected(ConfigModule*);
protected Q_SLOTS:
void slotItemSelected(Q3ListViewItem*);
protected:
void keyPressEvent(QKeyEvent *);
QPixmap loadIcon( const QString &name );
private:
QString _path;
ConfigModuleList *_modules;
};
#endif

View file

@ -1,25 +1,24 @@
/*
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "modules.h"
#include "global.h"
#include "proxywidget.h"
#include "kcrootonly.h"
#include <kapplication.h>
#include <kdebug.h>
@ -35,7 +34,6 @@
#include <QLabel>
#include <QVBoxLayout>
#include <QFrame>
#include <Q3PtrList>
#ifdef Q_WS_X11
#include <X11/Xlib.h>
@ -47,291 +45,95 @@
#include "modules.moc"
template class Q3PtrList<ConfigModule>;
ConfigModule::ConfigModule(const KService::Ptr &s)
: KCModuleInfo(s), _changed(false), _module(0), _embedWidget(0),
_rootProcess(0), _embedLayout(0), _embedFrame(0)
{
ConfigModule::ConfigModule(const KService::Ptr &s) :
KCModuleInfo(s), _module(0) {
}
ConfigModule::~ConfigModule()
{
deleteClient();
ConfigModule::~ConfigModule() {
deleteClient();
}
ProxyWidget *ConfigModule::module()
{
if (_module)
return _module;
#ifdef __GNUC__
#warning I expect KControl in its current form to disappear, if not a real port is needed
#endif
// root KCMs are gone, clean up all of the related code
bool run_as_root = false; //needsRootPrivileges() && (getuid() != 0);
ProxyWidget *ConfigModule::module() {
if (_module)
return _module;
KCModule *modWidget = 0;
kDebug() << "Finding proxy..." << endl;
modWidget = KCModuleLoader::loadModule(*this,/*KCModuleLoader::None*/(KCModuleLoader::ErrorReporting)0);
KCModule *modWidget = 0;
if (modWidget)
{
modWidget = KCModuleLoader::loadModule(*this,/*KCModuleLoader::None*/(KCModuleLoader::ErrorReporting)NULL);
_module = new ProxyWidget(modWidget, moduleName(), run_as_root);
connect(_module, SIGNAL(changed(bool)), this, SLOT(clientChanged(bool)));
connect(_module, SIGNAL(closed()), this, SLOT(clientClosed()));
connect(_module, SIGNAL(helpRequest()), this, SIGNAL(helpRequest()));
connect(_module, SIGNAL(runAsRoot()), this, SLOT(runAsRoot()));
if (modWidget==NULL) {
return _module;
}
kWarning() << "Unable to load KCM Module" << endl;
return NULL;
}
return 0;
_module = new ProxyWidget(modWidget);
return _module;
}
void ConfigModule::deleteClient()
{
#ifdef Q_WS_X11
if (_embedWidget)
XKillClient(QX11Info::display(), _embedWidget->containerWinId());
#endif
delete _rootProcess;
_rootProcess = 0;
QPixmap ConfigModule::realIcon(KIconLoader::StdSizes size) {
//The next line is identical as SmallIcon(module->icon()), but is able to return a isNull() QPixmap
QPixmap providedIcon = KIconLoader::global()->loadIcon(icon(), KIconLoader::Small, size, KIconLoader::DefaultState, QStringList(), 0L, true);
if (providedIcon.isNull()) {
kDebug() << "Icon is null" << icon() << endl;
return SmallIcon("computer", size);
delete _embedWidget;
_embedWidget = 0;
delete _embedFrame;
_embedFrame = 0;
kapp->syncX();
}
return providedIcon;
if(_module)
_module->close();
_module = 0;
delete _embedLayout;
_embedLayout = 0;
_changed = false;
}
void ConfigModule::clientClosed()
{
deleteClient();
void ConfigModule::deleteClient() {
kapp->syncX();
if (_module)
_module->close();
_module = NULL;
emit changed(this);
emit childClosed();
}
void ConfigModule::clientChanged(bool state)
{
setChanged(state);
emit changed(this);
const KAboutData *ConfigModule::aboutData() const {
if (!_module)
return 0;
return _module->aboutData();
}
ConfigModuleList::ConfigModuleList() {
foreach(ConfigModule* configModule, *this) {
delete configModule;
}
void ConfigModule::runAsRoot()
{
if (!_module)
return;
delete _rootProcess;
delete _embedWidget;
delete _embedLayout;
// create an embed widget that will embed the
// kcmshell4 running as root
_embedLayout = new QVBoxLayout(_module->parentWidget());
_embedFrame = new KVBox( _module->parentWidget() );
#ifdef __GNUC__
#warning "KDE4 porting ";
#endif
//_embedFrame->setFrameStyle( QFrame::Box | QFrame::Raised );
QPalette pal( Qt::red );
pal.setColor( QPalette::Background,
_module->parentWidget()->palette().color( QPalette::Background ) );
#ifdef __GNUC__
#warning "KDE4 porting"
#endif
//_embedFrame->setPalette( pal );
//_embedFrame->setLineWidth( 2 );
//_embedFrame->setMidLineWidth( 2 );
_embedLayout->addWidget(_embedFrame,1);
_embedWidget = new QX11EmbedWidget(_embedFrame );
_module->hide();
_embedFrame->show();
QLabel *_busy = new QLabel(i18n("<big>Loading...</big>"), _embedWidget);
_busy->setAlignment(Qt::AlignCenter);
_busy->setTextFormat(Qt::RichText);
_busy->setGeometry(0,0, _module->width(), _module->height());
_busy->show();
// prepare the process to run the kcmshell4
QString cmd = service()->exec().trimmed();
bool kdeshell = false;
if (cmd.left(5) == "kdesu")
{
cmd = cmd.remove(0,5).trimmed();
// remove all kdesu switches
while( cmd.length() > 1 && cmd[ 0 ] == '-' )
{
int pos = cmd.indexOf( ' ' );
cmd = cmd.remove( 0, pos ).trimmed();
}
}
if (cmd.left(8) == "kcmshell4")
{
cmd = cmd.remove(0,8).trimmed();
kdeshell = true;
}
// run the process
QString kdesu = KStandardDirs::findExe("kdesu");
if (!kdesu.isEmpty())
{
_rootProcess = new K3Process;
*_rootProcess << kdesu;
#ifdef __GNUC__
#warning "--nonewdcop doesn't exist now";
#endif
//*_rootProcess << "--nonewdcop";
// We have to disable the keep-password feature because
// in that case the modules is started through kdesud and kdesu
// returns before the module is running and that doesn't work.
// We also don't have a way to close the module in that case.
*_rootProcess << "--n"; // Don't keep password.
if (kdeshell) {
*_rootProcess << QString("kcmshell4 %1 --embed %2 --lang %3").arg(cmd).arg(_embedWidget->winId()).arg(KGlobal::locale()->language());
}
else {
*_rootProcess << QString("%1 --embed %2 --lang %3").arg(cmd).arg(_embedWidget->winId()).arg( KGlobal::locale()->language() );
}
connect(_rootProcess, SIGNAL(processExited(K3Process*)), this, SLOT(rootExited(K3Process*)));
if ( !_rootProcess->start(K3Process::NotifyOnExit) )
{
delete _rootProcess;
_rootProcess = 0L;
}
return;
}
// clean up in case of failure
delete _embedFrame;
_embedWidget = 0;
delete _embedLayout;
_embedLayout = 0;
_module->show();
this->clear();
}
bool ConfigModuleList::readDesktopEntries() {
KService::List list = KServiceTypeTrader::self()->query("KCModule", "[X-KDE-ParentApp] == 'kinfocenter'");
void ConfigModule::rootExited(K3Process *)
{
if (list.isEmpty()) {
return false;
}
if (_embedWidget->containerWinId())
XDestroyWindow(QX11Info::display(), _embedWidget->containerWinId());
foreach(const KService::Ptr &s, list) {
if (s->isType(KST_KService) == false) {
continue;
}
delete _embedWidget;
_embedWidget = 0;
if (!KAuthorized::authorizeControlModule(s->menuId())) {
continue;
}
delete _rootProcess;
_rootProcess = 0;
ConfigModule *module = new ConfigModule(s);
if (module->library().isEmpty()) {
delete module;
continue;
}
delete _embedLayout;
_embedLayout = 0;
append(module);
delete _module;
_module=0;
}
_changed = false;
emit changed(this);
emit childClosed();
}
const KAboutData *ConfigModule::aboutData() const
{
if (!_module) return 0;
return _module->aboutData();
}
ConfigModuleList::ConfigModuleList()
{
setAutoDelete(true);
subMenus.setAutoDelete(true);
}
void ConfigModuleList::readDesktopEntries()
{
readDesktopEntriesRecursive( KCGlobal::baseGroup() );
}
bool ConfigModuleList::readDesktopEntriesRecursive(const QString &path)
{
KService::List list = KServiceTypeTrader::self()->query( "KCModule", "[X-KDE-ParentApp] == 'kinfocenter'" );
if( list.isEmpty() )
return false;
Menu *menu = new Menu;
subMenus.insert(path, menu);
foreach(const KService::Ptr &s, list)
{
if (s->isType(KST_KService))
{
if (!KAuthorized::authorizeControlModule(s->menuId()))
continue;
ConfigModule *module = new ConfigModule(s);
if (module->library().isEmpty())
{
delete module;
continue;
}
append(module);
menu->modules.append(module);
}
else if (s->isType(KST_KServiceGroup) &&
readDesktopEntriesRecursive(s->entryPath()) )
menu->submenus.append(s->entryPath());
}
return true;
}
Q3PtrList<ConfigModule> ConfigModuleList::modules(const QString &path)
{
Menu *menu = subMenus.find(path);
if (menu)
return menu->modules;
return Q3PtrList<ConfigModule>();
}
QStringList ConfigModuleList::submenus(const QString &path)
{
Menu *menu = subMenus.find(path);
if (menu)
return menu->submenus;
return QStringList();
}
QString ConfigModuleList::findModule(ConfigModule *module)
{
Q3DictIterator<Menu> it(subMenus);
Menu *menu;
for(;(menu = it.current());++it)
{
if (menu->modules.containsRef(module))
return it.currentKey();
}
return QString();
return true;
}

View file

@ -1,125 +1,74 @@
/*
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
*/
#ifndef MODULES_H
#define MODULES_H
#include <kcmoduleinfo.h>
#include <QObject>
#include <Qt3Support/Q3Dict>
//Added by qt3to4:
#include <QVBoxLayout>
#include <Q3PtrList>
#include <kvbox.h>
template<class ConfigModule> class Q3PtrList;
#include <kcmoduleinfo.h>
#include <kiconloader.h>
class QStringList;
class KAboutData;
class KCModule;
class ProxyWidget;
class K3Process;
class QX11EmbedWidget;
class QVBoxLayout;
class KVBox;
class ConfigModule : public QObject, public KCModuleInfo
{
Q_OBJECT
class ConfigModule : public QObject, public KCModuleInfo {
Q_OBJECT
public:
ConfigModule(const KService::Ptr &s);
~ConfigModule();
ConfigModule(const KService::Ptr &s);
~ConfigModule();
bool isChanged() { return _changed; }
void setChanged(bool changed) { _changed = changed; }
bool isActive() {
return _module != 0;
}
ProxyWidget *module();
const KAboutData *aboutData() const;
bool isActive() { return _module != 0; }
ProxyWidget *module();
const KAboutData *aboutData() const;
QPixmap realIcon(KIconLoader::StdSizes size);
public slots:
public Q_SLOTS:
void deleteClient();
private Q_SLOTS:
void clientClosed();
void clientChanged(bool state);
void runAsRoot();
void rootExited(K3Process *proc);
Q_SIGNALS:
void changed(ConfigModule *module);
void childClosed();
void helpRequest();
void deleteClient();
private:
bool _changed;
ProxyWidget *_module;
QX11EmbedWidget *_embedWidget;
K3Process *_rootProcess;
QVBoxLayout *_embedLayout;
KVBox *_embedFrame;
ProxyWidget *_module;
QVBoxLayout *_embedLayout;
KVBox *_embedFrame;
};
class ConfigModuleList : public Q3PtrList<ConfigModule>
{
class ConfigModuleList : public QList<ConfigModule*> {
public:
ConfigModuleList();
ConfigModuleList();
void readDesktopEntries();
bool readDesktopEntriesRecursive(const QString &path);
bool readDesktopEntries();
/**
* Returns all submenus of the submenu identified by path
*/
Q3PtrList<ConfigModule> modules(const QString &path);
/**
* Returns all modules of the submenu identified by path
*/
QStringList submenus(const QString &path);
/**
* Returns the path of the submenu the module is in
*/
QString findModule(ConfigModule *module);
protected:
class Menu
{
public:
Q3PtrList<ConfigModule> modules;
QStringList submenus;
};
Q3Dict<Menu> subMenus;
};
#endif

View file

@ -1,21 +1,21 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "moduletreeview.h"
#include "global.h"
@ -25,353 +25,120 @@
#include <kiconloader.h>
#include <kservicegroup.h>
#include <kdebug.h>
#include <kicon.h>
#include <Qt3Support/Q3Header>
#include <Qt3Support/Q3WhatsThis>
#include <QImage>
#include <QPainter>
#include <QBitmap>
#include <QPixmap>
#include <Q3PtrList>
#include <QKeyEvent>
#include "moduletreeview.moc"
static QPixmap appIcon(const QString &iconName)
{
QString path;
QPixmap normal = KIconLoader::global()->loadIcon(iconName, KIconLoader::Small, 0, KIconLoader::DefaultState, QStringList(), &path, true);
// make sure they are not larger than KIconLoader::SizeSmall
if (normal.width() > KIconLoader::SizeSmall || normal.height() > KIconLoader::SizeSmall)
{
QImage tmp = normal.toImage();
tmp = tmp.scaled(KIconLoader::SizeSmall, KIconLoader::SizeSmall, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
normal = QPixmap::fromImage(tmp);
}
return normal;
ModuleTreeView::ModuleTreeView(ConfigModuleList *modules, QWidget * parent) :
QListWidget(parent), _modules(modules) {
connect(this, SIGNAL(itemSelectionChanged()), this, SLOT(selectItem()));
setSortingEnabled(false);
_generalItem = NULL;
}
class ModuleTreeWhatsThis : public Q3WhatsThis
{
public:
ModuleTreeWhatsThis( ModuleTreeView* tree)
: Q3WhatsThis( tree ), treeView( tree ) {}
~ModuleTreeWhatsThis(){}
void ModuleTreeView::fill() {
_generalItem = new QListWidgetItem(KIcon(KINFOCENTER_ICON_NAME), i18n("General Information"), this);
QString text( const QPoint & p) {
ModuleTreeItem* i = (ModuleTreeItem*) treeView->itemAt( p );
if ( i && i->module() ) {
return i->module()->comment();
} else if ( i ) {
return i18n("The %1 configuration group. Click to open it.", i->text(0) );
}
return i18n("This treeview displays all available control modules. Click on one of the modules to receive more detailed information.");
}
private:
ModuleTreeView* treeView;
};
ModuleTreeView::ModuleTreeView(ConfigModuleList *list, QWidget * parent)
: K3ListView(parent)
, _modules(list)
{
addColumn(QString());
setColumnWidthMode (0, Q3ListView::Maximum);
setAllColumnsShowFocus(true);
setResizeMode(Q3ListView::AllColumns);
setRootIsDecorated(true);
setHScrollBarMode(AlwaysOff);
header()->hide();
new ModuleTreeWhatsThis( this );
connect(this, SIGNAL(clicked(Q3ListViewItem*)),
this, SLOT(slotItemSelected(Q3ListViewItem*)));
foreach(ConfigModule* configModule, *_modules) {
new ModuleTreeItem(this, configModule);
}
}
void ModuleTreeView::fill()
{
clear();
void ModuleTreeView::selectItem() {
QListWidgetItem* item = this->currentItem();
if (item==NULL)
return;
QStringList subMenus = _modules->submenus(KCGlobal::baseGroup());
for(QStringList::ConstIterator it = subMenus.begin();
it != subMenus.end(); ++it)
{
QString path = *it;
ModuleTreeItem* menu = new ModuleTreeItem(this);
menu->setGroup(path);
fill(menu, path);
}
if (isGeneralItem(item)) {
kDebug() << "General Selected" << endl;
emit generalSelected();
return;
}
ConfigModule *module;
Q3PtrList<ConfigModule> moduleList = _modules->modules(KCGlobal::baseGroup());
for (module=moduleList.first(); module != 0; module=moduleList.next())
{
new ModuleTreeItem(this, module);
}
}
kDebug() << "Select item" << endl;
ModuleTreeItem* moduleItem = static_cast<ModuleTreeItem*>(item);
void ModuleTreeView::fill(ModuleTreeItem *parent, const QString &parentPath)
{
QStringList subMenus = _modules->submenus(parentPath);
for(QStringList::ConstIterator it = subMenus.begin();
it != subMenus.end(); ++it)
{
QString path = *it;
ModuleTreeItem* menu = new ModuleTreeItem(parent);
menu->setGroup(path);
fill(menu, path);
}
ConfigModule *module;
Q3PtrList<ConfigModule> moduleList = _modules->modules(parentPath);
for (module=moduleList.first(); module != 0; module=moduleList.next())
{
new ModuleTreeItem(parent, module);
}
emit moduleSelected(moduleItem->module());
kDebug() << "Select item end" << endl;
}
bool ModuleTreeView::isGeneralItem(const QListWidgetItem* item) const {
if (item == _generalItem)
return true;
QSize ModuleTreeView::sizeHint() const
{
return Q3ListView::sizeHint().boundedTo(
QSize( fontMetrics().maxWidth()*35, QWIDGETSIZE_MAX) );
return false;
}
void ModuleTreeView::makeSelected(ConfigModule *module)
{
ModuleTreeItem *item = static_cast<ModuleTreeItem*>(firstChild());
updateItem(item, module);
QListWidgetItem* ModuleTreeView::generalItem() const {
return _generalItem;
}
void ModuleTreeView::updateItem(ModuleTreeItem *item, ConfigModule *module)
{
while (item)
{
if (item->childCount() != 0)
updateItem(static_cast<ModuleTreeItem*>(item->firstChild()), module);
if (item->module() == module)
{
setSelected(item, true);
break;
}
item = static_cast<ModuleTreeItem*>(item->nextSibling());
}
}
ModuleTreeItem* ModuleTreeView::findMatchingItem(ConfigModule* configModule) const {
for (int i = 0; i < count() ; ++i) {
QListWidgetItem* tempItem = item(i);
if (isGeneralItem(tempItem)) {
continue;
}
/*
void ModuleTreeView::expandItem(QListViewItem *item, QPtrList<QListViewItem> *parentList)
{
while (item)
{
setOpen(item, parentList->contains(item));
ModuleTreeItem* moduleItem = static_cast<ModuleTreeItem*>(tempItem);
if (moduleItem->module()==configModule)
return moduleItem;
if (item->childCount() != 0)
expandItem(item->firstChild(), parentList);
item = item->nextSibling();
}
}
*/
void ModuleTreeView::makeVisible(ConfigModule *module)
{
QString path = _modules->findModule(module);
if (path.startsWith(KCGlobal::baseGroup()))
path = path.mid(KCGlobal::baseGroup().length());
}
QStringList groups = path.split( '/');
ModuleTreeItem *item = 0;
QStringList::ConstIterator it;
for (it=groups.begin(); it != groups.end(); ++it)
{
if (item)
item = static_cast<ModuleTreeItem*>(item->firstChild());
else
item = static_cast<ModuleTreeItem*>(firstChild());
while (item)
{
if (item->tag() == *it)
{
setOpen(item, true);
break;
}
item = static_cast<ModuleTreeItem*>(item->nextSibling());
}
if (!item)
break; // Not found (?)
}
// make the item visible
if (item)
ensureItemVisible(item);
}
void ModuleTreeView::slotItemSelected(Q3ListViewItem* item)
{
if (!item) return;
if (static_cast<ModuleTreeItem*>(item)->module())
{
emit moduleSelected(static_cast<ModuleTreeItem*>(item)->module());
return;
}
else
{
emit categorySelected(item);
}
setOpen(item, !item->isOpen());
/*
else
{
QPtrList<QListViewItem> parents;
QListViewItem* i = item;
while(i)
{
parents.append(i);
i = i->parent();
}
//int oy1 = item->itemPos();
//int oy2 = mapFromGlobal(QCursor::pos()).y();
//int offset = oy2 - oy1;
expandItem(firstChild(), &parents);
//int x =mapFromGlobal(QCursor::pos()).x();
//int y = item->itemPos() + offset;
//QCursor::setPos(mapToGlobal(QPoint(x, y)));
}
*/
}
void ModuleTreeView::keyPressEvent(QKeyEvent *e)
{
if (!currentItem()) return;
if(e->key() == Qt::Key_Return
|| e->key() == Qt::Key_Enter
|| e->key() == Qt::Key_Space)
{
//QCursor::setPos(mapToGlobal(QPoint(10, currentItem()->itemPos()+5)));
slotItemSelected(currentItem());
}
else
K3ListView::keyPressEvent(e);
kDebug() << "Unable to find the matching item" << endl;
return NULL;
}
ModuleTreeItem::ModuleTreeItem(Q3ListViewItem *parent, ConfigModule *module)
: Q3ListViewItem(parent)
, _module(module)
, _tag(QString())
, _maxChildIconWidth(0)
{
if (_module)
{
setText(0, ' ' + module->moduleName());
setPixmap(0, appIcon(module->icon()));
}
ModuleTreeItem::ModuleTreeItem(QListWidget *parent, ConfigModule *module) :
QListWidgetItem(parent), _module(module) {
setText(module->moduleName());
setIcon(module->realIcon(KIconLoader::SizeSmall));
}
ModuleTreeItem::ModuleTreeItem(Q3ListView *parent, ConfigModule *module)
: Q3ListViewItem(parent)
, _module(module)
, _tag(QString())
, _maxChildIconWidth(0)
{
if (_module)
{
setText(0, ' ' + module->moduleName());
setPixmap(0, appIcon(module->icon()));
}
}
ModuleTreeItem::ModuleTreeItem(Q3ListViewItem *parent, const QString& text)
: Q3ListViewItem(parent, ' ' + text)
, _module(0)
, _tag(QString())
, _maxChildIconWidth(0)
{}
ModuleTreeItem::ModuleTreeItem(Q3ListView *parent, const QString& text)
: Q3ListViewItem(parent, ' ' + text)
, _module(0)
, _tag(QString())
, _maxChildIconWidth(0)
{}
void ModuleTreeItem::setPixmap(int column, const QPixmap& pm)
{
if (!pm.isNull())
{
ModuleTreeItem* p = dynamic_cast<ModuleTreeItem*>(parent());
if (p)
p->regChildIconWidth(pm.width());
}
Q3ListViewItem::setPixmap(column, pm);
}
void ModuleTreeItem::regChildIconWidth(int width)
{
if (width > _maxChildIconWidth)
_maxChildIconWidth = width;
}
void ModuleTreeItem::paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int align )
{
if (!pixmap(0))
{
int offset = 0;
ModuleTreeItem* parentItem = dynamic_cast<ModuleTreeItem*>(parent());
if (parentItem)
{
offset = parentItem->maxChildIconWidth();
}
if (offset > 0)
{
QPixmap pixmap(offset, offset);
pixmap.fill(Qt::color0);
pixmap.setMask(pixmap.createHeuristicMask());
QBitmap mask( pixmap.size() );
mask.clear();
pixmap.setMask( mask );
Q3ListViewItem::setPixmap(0, pixmap);
}
}
Q3ListViewItem::paintCell( p, cg, column, width, align );
ConfigModule* ModuleTreeItem::module() const {
return _module;
}
void ModuleTreeItem::setGroup(const QString &path)
{
KServiceGroup::Ptr group = KServiceGroup::group(path);
QString defName = path.left(path.length()-1);
int pos = defName.lastIndexOf('/');
if (pos >= 0)
defName = defName.mid(pos+1);
if (group && group->isValid())
{
setPixmap(0, appIcon(group->icon()));
setText(0, ' ' + group->caption());
setTag(defName);
setCaption(group->caption());
}
else
{
// Should not happen: Installation problem
// Let's try to fail softly.
setText(0, ' ' + defName);
setTag(defName);
}
ModuleWidgetSearchLine::ModuleWidgetSearchLine(QWidget* parent, ModuleTreeView* listWidget) :
KListWidgetSearchLine(parent, listWidget) {
}
bool ModuleWidgetSearchLine::itemMatches(const QListWidgetItem* item, const QString& search) const {
const ModuleTreeView* moduleTree = static_cast<const ModuleTreeView*>(listWidget());
if (moduleTree->isGeneralItem(item)) {
return true;
}
const ModuleTreeItem* moduleItem = static_cast<const ModuleTreeItem*>(item);
QStringList itemMatches;
itemMatches << moduleItem->module()->moduleName();
//kDebug() << "Module name " << moduleItem->module()->moduleName() << endl;
QStringList keywords = moduleItem->module()->keywords();
foreach(QString keyword, keywords) {
//kDebug() << "Key word " << keyword << endl;
itemMatches.append(keyword);
}
foreach(QString itemMatch, itemMatches) {
if (itemMatch.contains(search, Qt::CaseInsensitive)) {
return true;
}
}
return false;
}

View file

@ -1,95 +1,79 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 2000 Matthias Elter <elter@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
*/
#ifndef __moduletreeview_h__
#define __moduletreeview_h__
#include <Qt3Support/Q3PtrList>
#include <Qt3Support/Q3CheckListItem>
//Added by qt3to4:
#include <QListWidget>
#include <QPixmap>
#include <QKeyEvent>
#include <k3listview.h>
#include <Qt3Support/Q3Dict>
#include <klistwidgetsearchline.h>
class ConfigModule;
class ConfigModuleList;
class QPainter;
class ModuleTreeItem : public Q3ListViewItem
{
class ModuleTreeItem : public QListWidgetItem {
public:
explicit ModuleTreeItem(Q3ListViewItem *parent, ConfigModule *module = 0);
ModuleTreeItem(Q3ListViewItem *parent, const QString& text);
explicit ModuleTreeItem(Q3ListView *parent, ConfigModule *module = 0);
ModuleTreeItem(Q3ListView *parent, const QString& text);
explicit ModuleTreeItem(QListWidget* parent, ConfigModule* module = NULL);
void setTag(const QString& tag) { _tag = tag; }
void setCaption(const QString& caption) { _caption = caption; }
void setModule(ConfigModule *m) { _module = m; }
QString tag() const { return _tag; }
QString caption() const { return _caption; }
ConfigModule *module() { return _module; }
void regChildIconWidth(int width);
int maxChildIconWidth() { return _maxChildIconWidth; }
void setPixmap(int column, const QPixmap& pm);
void setGroup(const QString &path);
protected:
void paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int align );
ConfigModule* module() const;
private:
ConfigModule *_module;
QString _tag;
QString _caption;
int _maxChildIconWidth;
ConfigModule *_module;
};
class ModuleTreeView : public K3ListView
{
Q_OBJECT
class ModuleTreeView : public QListWidget {
Q_OBJECT
public:
explicit ModuleTreeView(ConfigModuleList *list, QWidget * parent = 0);
explicit ModuleTreeView(ConfigModuleList* configModules, QWidget* parent = NULL);
void makeSelected(ConfigModule* module);
void makeVisible(ConfigModule *module);
void fill();
QSize sizeHint() const;
void fill();
Q_SIGNALS:
void moduleSelected(ConfigModule*);
void categorySelected(Q3ListViewItem*);
bool isGeneralItem(const QListWidgetItem* item) const;
protected Q_SLOTS:
void slotItemSelected(Q3ListViewItem*);
QListWidgetItem* generalItem() const;
protected:
void updateItem(ModuleTreeItem *item, ConfigModule* module);
void keyPressEvent(QKeyEvent *);
void fill(ModuleTreeItem *parent, const QString &parentPath);
ModuleTreeItem* findMatchingItem(ConfigModule* configModule) const;
signals:
void moduleSelected(ConfigModule* configModule);
void generalSelected();
private slots:
void selectItem();
private:
ConfigModuleList *_modules;
QListWidgetItem* _generalItem;
ConfigModuleList* _modules;
};
class ModuleWidgetSearchLine : public KListWidgetSearchLine {
public:
ModuleWidgetSearchLine(QWidget* parent, ModuleTreeView* listWidget);
protected:
virtual bool itemMatches(const QListWidgetItem* item, const QString& search) const;
};
#endif

View file

@ -18,7 +18,7 @@ set(kcm_nic_PART_SRCS nic.cpp )
kde4_add_plugin(kcm_nic ${kcm_nic_PART_SRCS})
target_link_libraries(kcm_nic ${KDE4_KIO_LIBS} ${QT_QT3SUPPORT_LIBRARY} )
target_link_libraries(kcm_nic ${KDE4_KIO_LIBS} )
install(TARGETS kcm_nic DESTINATION ${PLUGIN_INSTALL_DIR} )

View file

@ -41,14 +41,13 @@
#include <QTimer>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <Q3PtrList>
#include <QTreeWidget>
#include "nic.h"
#ifdef USE_SOLARIS
/* net/if.h is incompatible with STL on Solaris 2.6 - 2.8, redefine
map in the header file because we don't need it. -- Simon Josefsson */
map in the header file because we don't need it. -- Simon Josefsson */
#define map junkmap
#endif
# include <net/if.h>
@ -61,273 +60,259 @@
#include <KPluginLoader>
#ifndef HAVE_STRUCT_SOCKADDR_SA_LEN
#undef HAVE_GETNAMEINFO
#undef HAVE_GETIFADDRS
#undef HAVE_GETNAMEINFO
#undef HAVE_GETIFADDRS
#endif
#if defined(HAVE_GETNAMEINFO) && defined(HAVE_GETIFADDRS)
#include <ifaddrs.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <netdb.h>
QString flags_tos (unsigned int flags);
QString flags_tos (unsigned int flags);
#endif
K_PLUGIN_FACTORY(KCMNicFactory,
registerPlugin<KCMNic>();
registerPlugin<KCMNic>();
)
K_EXPORT_PLUGIN(KCMNicFactory("kcmnic"))
struct MyNIC
{
QString name;
QString addr;
QString netmask;
QString state;
QString type;
QString HWaddr;
struct MyNIC {
QString name;
QString addr;
QString netmask;
QString state;
QString type;
QString HWaddr;
};
typedef Q3PtrList<MyNIC> NICList;
QList<MyNIC*> findNICs();
NICList* findNICs();
KCMNic::KCMNic(QWidget *parent, const QVariantList &) :
KCModule(KCMNicFactory::componentData(), parent) {
QVBoxLayout *box=new QVBoxLayout(this);
box->setMargin(0);
box->setSpacing(KDialog::spacingHint());
m_list=new QTreeWidget(this);
m_list->setRootIsDecorated(false);
box->addWidget(m_list);
QStringList columns;
columns<<i18n("Name")<<i18n("IP Address")<<i18n("Network Mask")<<i18n("Type")<<i18n("State")<<i18n("HWAddr");
m_list->setHeaderLabels(columns);
QHBoxLayout *hbox=new QHBoxLayout();
box->addItem(hbox);
m_updateButton=new QPushButton(i18n("&Update"),this);
hbox->addWidget(m_updateButton);
hbox->addStretch(1);
QTimer* timer=new QTimer(this);
timer->start(60000);
connect(m_updateButton, SIGNAL(clicked()), this, SLOT(update()));
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
update();
KAboutData *about = new KAboutData(I18N_NOOP("kcminfo"), 0,
ki18n("KDE Panel System Information Control Module"),
0, KLocalizedString(), KAboutData::License_GPL,
ki18n("(c) 2001 - 2002 Alexander Neundorf"));
KCMNic::KCMNic(QWidget *parent, const QVariantList &)
:KCModule(KCMNicFactory::componentData(), parent)
{
QVBoxLayout *box=new QVBoxLayout(this);
box->setMargin(0);
box->setSpacing(KDialog::spacingHint());
m_list=new QTreeWidget(this);
m_list->setRootIsDecorated(false);
box->addWidget(m_list);
QStringList columns;
columns<<i18n("Name")<<i18n("IP Address")<<i18n("Network Mask")<<i18n("Type")<<i18n("State")<<i18n("HWAddr");
m_list->setHeaderLabels(columns);
QHBoxLayout *hbox=new QHBoxLayout();
box->addItem(hbox);
m_updateButton=new QPushButton(i18n("&Update"),this);
hbox->addWidget(m_updateButton);
hbox->addStretch(1);
QTimer* timer=new QTimer(this);
timer->start(60000);
connect(m_updateButton,SIGNAL(clicked()),this,SLOT(update()));
connect(timer,SIGNAL(timeout()),this,SLOT(update()));
update();
KAboutData *about =
new KAboutData(I18N_NOOP("kcminfo"), 0,
ki18n("KDE Panel System Information Control Module"),
0, KLocalizedString(), KAboutData::License_GPL,
ki18n("(c) 2001 - 2002 Alexander Neundorf"));
about->addAuthor(ki18n("Alexander Neundorf"), KLocalizedString(), "neundorf@kde.org");
setAboutData( about );
about->addAuthor(ki18n("Alexander Neundorf"), KLocalizedString(), "neundorf@kde.org");
setAboutData(about);
}
void KCMNic::update()
{
m_list->clear();
NICList *nics=findNICs();
nics->setAutoDelete(true);
for (MyNIC* tmp=nics->first(); tmp!=0; tmp=nics->next()) {
QStringList lst;
lst << tmp->name<<tmp->addr<<tmp->netmask<<tmp->type<<tmp->state<<tmp->HWaddr;
new QTreeWidgetItem(m_list,lst);
}
delete nics;
void KCMNic::update() {
m_list->clear();
QList<MyNIC*> nics=findNICs();
foreach(MyNIC* tmp, nics) {
QStringList lst;
lst << tmp->name<<tmp->addr<<tmp->netmask<<tmp->type<<tmp->state<<tmp->HWaddr;
new QTreeWidgetItem(m_list,lst);
delete tmp;
}
nics.clear();
}
static QString HWaddr2String(const char *hwaddr )
{
QString ret;
for (int i=0; i<6; i++, hwaddr++)
{
int v = (*hwaddr & 0xff);
QString num = QString("%1").arg(v,0,16);
if (num.length() < 2)
num.prepend("0");
if (i>0)
ret.append(":");
ret.append(num);
}
return ret;
static QString HWaddr2String(const char *hwaddr) {
QString ret;
for (int i=0; i<6; i++, hwaddr++) {
int v = (*hwaddr & 0xff);
QString num = QString("%1").arg(v, 0, 16);
if (num.length() < 2)
num.prepend("0");
if (i>0)
ret.append(":");
ret.append(num);
}
return ret;
}
NICList* findNICs()
{
QString upMessage( i18nc("State of network card is connected", "Up") );
QString downMessage( i18nc("State of network card is disconnected", "Down") );
QList<MyNIC*> findNICs() {
QString upMessage(i18nc("State of network card is connected", "Up") );
QString downMessage(i18nc("State of network card is disconnected", "Down") );
NICList* nl=new NICList;
nl->setAutoDelete(true);
QList<MyNIC*> nl;
#if !defined(HAVE_GETIFADDRS) || !defined(HAVE_GETNAMEINFO)
int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
char buf[8*1024];
struct ifconf ifc;
ifc.ifc_len = sizeof(buf);
ifc.ifc_req = (struct ifreq *) buf;
int result=ioctl(sockfd, SIOCGIFCONF, &ifc);
char buf[8*1024];
struct ifconf ifc;
ifc.ifc_len = sizeof(buf);
ifc.ifc_req = (struct ifreq *) buf;
int result=ioctl(sockfd, SIOCGIFCONF, &ifc);
for (char* ptr = buf; ptr < buf + ifc.ifc_len; )
{
struct ifreq *ifr =(struct ifreq *) ptr;
for (char* ptr = buf; ptr < buf + ifc.ifc_len;) {
struct ifreq *ifr =(struct ifreq *) ptr;
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
int len = sizeof(struct sockaddr);
if (ifr->ifr_addr.sa_len > len)
len = ifr->ifr_addr.sa_len; /* length > 16 */
ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */
int len = sizeof(struct sockaddr);
if (ifr->ifr_addr.sa_len > len)
len = ifr->ifr_addr.sa_len; /* length > 16 */
ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */
#else
ptr += sizeof(*ifr); /* for next one in buffer */
ptr += sizeof(*ifr); /* for next one in buffer */
#endif
int flags;
struct sockaddr_in *sinptr;
MyNIC *tmp=0;
switch (ifr->ifr_addr.sa_family)
{
case AF_INET:
sinptr = (struct sockaddr_in *) &ifr->ifr_addr;
flags=0;
int flags;
struct sockaddr_in *sinptr;
MyNIC *tmp=0;
switch (ifr->ifr_addr.sa_family) {
case AF_INET:
sinptr = (struct sockaddr_in *) &ifr->ifr_addr;
flags=0;
struct ifreq ifcopy;
ifcopy=*ifr;
result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy);
flags=ifcopy.ifr_flags;
struct ifreq ifcopy;
ifcopy=*ifr;
result=ioctl(sockfd, SIOCGIFFLAGS, &ifcopy);
flags=ifcopy.ifr_flags;
tmp=new MyNIC;
tmp->name=ifr->ifr_name;
tmp->state= ((flags & IFF_UP) == IFF_UP) ? upMessage : downMessage;
tmp=new MyNIC;
tmp->name=ifr->ifr_name;
tmp->state= ((flags & IFF_UP) == IFF_UP) ? upMessage : downMessage;
if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
tmp->type=i18nc("@item:intext Mode of network card", "Broadcast");
else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
tmp->type=i18nc("@item:intext Mode of network card", "Point to Point");
if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
tmp->type=i18nc("@item:intext Mode of network card", "Broadcast");
else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
tmp->type=i18nc("@item:intext Mode of network card", "Point to Point");
#ifndef _AIX
else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
tmp->type=i18nc("@item:intext Mode of network card", "Multicast");
else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
tmp->type=i18nc("@item:intext Mode of network card", "Multicast");
#endif
else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
tmp->type=i18nc("@item:intext Mode of network card", "Loopback");
else
tmp->type=i18nc("@item:intext Mode of network card", "Unknown");
else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
tmp->type=i18nc("@item:intext Mode of network card", "Loopback");
else
tmp->type=i18nc("@item:intext Mode of network card", "Unknown");
tmp->addr=inet_ntoa(sinptr->sin_addr);
tmp->addr=inet_ntoa(sinptr->sin_addr);
ifcopy=*ifr;
result=ioctl(sockfd,SIOCGIFNETMASK,&ifcopy);
if (result==0)
{
sinptr = (struct sockaddr_in *) &ifcopy.ifr_addr;
tmp->netmask=inet_ntoa(sinptr->sin_addr);
}
else
tmp->netmask=i18nc("Unknown network mask", "Unknown");
ifcopy=*ifr;
result=ioctl(sockfd, SIOCGIFNETMASK, &ifcopy);
if (result==0) {
sinptr = (struct sockaddr_in *) &ifcopy.ifr_addr;
tmp->netmask=inet_ntoa(sinptr->sin_addr);
} else
tmp->netmask=i18nc("Unknown network mask", "Unknown");
ifcopy=*ifr;
result=-1; // if none of the two #ifs below matches, ensure that result!=0 so that "Unknown" is returned as result
ifcopy=*ifr;
result=-1; // if none of the two #ifs below matches, ensure that result!=0 so that "Unknown" is returned as result
#ifdef SIOCGIFHWADDR
result=ioctl(sockfd,SIOCGIFHWADDR,&ifcopy);
if (result==0)
{
char *n = &ifcopy.ifr_ifru.ifru_hwaddr.sa_data[0];
tmp->HWaddr = HWaddr2String(n);
}
result=ioctl(sockfd, SIOCGIFHWADDR, &ifcopy);
if (result==0) {
char *n = &ifcopy.ifr_ifru.ifru_hwaddr.sa_data[0];
tmp->HWaddr = HWaddr2String(n);
}
#elif defined SIOCGENADDR
result=ioctl(sockfd,SIOCGENADDR,&ifcopy);
if (result==0)
{
char *n = &ifcopy.ifr_ifru.ifru_enaddr[0];
tmp->HWaddr = HWaddr2String(n);
}
result=ioctl(sockfd,SIOCGENADDR,&ifcopy);
if (result==0)
{
char *n = &ifcopy.ifr_ifru.ifru_enaddr[0];
tmp->HWaddr = HWaddr2String(n);
}
#endif
if (result!=0)
{
tmp->HWaddr = i18nc("Unknown HWaddr", "Unknown");
}
if (result!=0) {
tmp->HWaddr = i18nc("Unknown HWaddr", "Unknown");
}
nl->append(tmp);
break;
nl.append(tmp);
break;
default:
break;
}
}
default:
break;
}
}
#else
struct ifaddrs *ifap, *ifa;
if (getifaddrs(&ifap) != 0) {
return nl;
}
struct ifaddrs *ifap, *ifa;
if (getifaddrs(&ifap) != 0) {
return nl;
}
MyNIC *tmp=0;
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
switch (ifa->ifa_addr->sa_family) {
case AF_INET6:
case AF_INET: {
tmp = new MyNIC;
tmp->name = ifa->ifa_name;
MyNIC *tmp=0;
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
switch (ifa->ifa_addr->sa_family) {
case AF_INET6:
case AF_INET: {
tmp = new MyNIC;
tmp->name = ifa->ifa_name;
char buf[128];
char buf[128];
bzero(buf, 128);
getnameinfo(ifa->ifa_addr, ifa->ifa_addr->sa_len, buf, 127, 0, 0, NI_NUMERICHOST);
tmp->addr = buf;
bzero(buf, 128);
getnameinfo(ifa->ifa_addr, ifa->ifa_addr->sa_len, buf, 127, 0, 0, NI_NUMERICHOST);
tmp->addr = buf;
if (ifa->ifa_netmask != NULL) {
bzero(buf, 128);
getnameinfo(ifa->ifa_netmask, ifa->ifa_netmask->sa_len, buf, 127, 0, 0, NI_NUMERICHOST);
tmp->netmask = buf;
}
if (ifa->ifa_netmask != NULL) {
bzero(buf, 128);
getnameinfo(ifa->ifa_netmask, ifa->ifa_netmask->sa_len, buf, 127, 0, 0, NI_NUMERICHOST);
tmp->netmask = buf;
}
tmp->state= (ifa->ifa_flags & IFF_UP) ? upMessage : downMessage;
tmp->type = flags_tos(ifa->ifa_flags);
tmp->state= (ifa->ifa_flags & IFF_UP) ? upMessage : downMessage;
tmp->type = flags_tos(ifa->ifa_flags);
nl->append(tmp);
break;
}
default:
break;
}
}
nl.append(tmp);
break;
}
default:
break;
}
}
freeifaddrs(ifap);
freeifaddrs(ifap);
#endif
return nl;
return nl;
}
#if defined(HAVE_GETNAMEINFO) && defined(HAVE_GETIFADDRS)
QString flags_tos (unsigned int flags)
{
QString tmp;
if (flags & IFF_POINTOPOINT) {
tmp += i18n("Point to Point");
}
QString tmp;
if (flags & IFF_POINTOPOINT) {
tmp += i18n("Point to Point");
}
if (flags & IFF_BROADCAST) {
if (tmp.length()) {
tmp += QLatin1String(", ");
}
tmp += i18n("Broadcast");
}
if (flags & IFF_BROADCAST) {
if (tmp.length()) {
tmp += QLatin1String(", ");
}
tmp += i18n("Broadcast");
}
if (flags & IFF_MULTICAST) {
if (tmp.length()) {
tmp += QLatin1String(", ");
}
tmp += i18n("Multicast");
}
if (flags & IFF_MULTICAST) {
if (tmp.length()) {
tmp += QLatin1String(", ");
}
tmp += i18n("Multicast");
}
if (flags & IFF_LOOPBACK) {
if (tmp.length()) {
tmp += QLatin1String(", ");
}
tmp += i18n("Loopback");
}
return tmp;
if (flags & IFF_LOOPBACK) {
if (tmp.length()) {
tmp += QLatin1String(", ");
}
tmp += i18n("Loopback");
}
return tmp;
}
#endif

View file

@ -1,24 +1,19 @@
if(OPENGL_FOUND AND OPENGL_GLU_FOUND)
ADD_DEFINITIONS(-DINFO_OPENGL_AVAILABLE ) # added manually
include_directories( ${OPENGL_INCLUDE_DIR} ${OPENGL_GLU_INCLUDE_DIR} )
include_directories( ${OPENGL_INCLUDE_DIR} ${OPENGL_GLU_INCLUDE_DIR} )
########### next target ###############
########### next target ###############
set(KCM_OPENGL_PART_SRCS opengl.cpp )
set(KCM_OPENGL_PART_UIS opengl.ui )
set(KCM_OPENGL_PART_SRCS opengl.cpp )
set(KCM_OPENGL_PART_UIS opengl.ui )
qt4_wrap_ui(KCM_OPENGL_PART_UIS_H ${KCM_OPENGL_PART_UIS})
qt4_wrap_ui(KCM_OPENGL_PART_UIS_H ${KCM_OPENGL_PART_UIS})
kde4_add_plugin(kcm_opengl ${KCM_OPENGL_PART_SRCS} ${KCM_OPENGL_PART_UIS_H})
kde4_add_plugin(kcm_opengl ${KCM_OPENGL_PART_SRCS} ${KCM_OPENGL_PART_UIS_H})
target_link_libraries(kcm_opengl ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY} ${X11_X11_LIB} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY})
target_link_libraries(kcm_opengl ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY} ${X11_X11_LIB} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY})
install(TARGETS kcm_opengl DESTINATION ${PLUGIN_INSTALL_DIR})
install(TARGETS kcm_opengl DESTINATION ${PLUGIN_INSTALL_DIR})
########### install files ###############
########### install files ###############
install(FILES opengl.desktop DESTINATION ${SERVICES_INSTALL_DIR})
else(OPENGL_FOUND AND OPENGL_GLU_FOUND)
MESSAGE(STATUS "OpenGL information module has been disabled.")
endif(OPENGL_FOUND AND OPENGL_GLU_FOUND)
install(FILES opengl.desktop DESTINATION ${SERVICES_INSTALL_DIR})

View file

@ -1,12 +1,11 @@
[Desktop Entry]
Exec=kcmshell4 kcmopengl
Exec=kcmshell4 opengl
Type=Service
X-KDE-ServiceTypes=KCModule
X-DocPath=kinfocenter/opengl/index.html
Icon=kcmopengl
X-KDE-Library=kcm_opengl
X-KDE-PluginKeyword=opengl
X-KDE-ParentApp=kinfocenter
Name=OpenGL

View file

@ -0,0 +1,37 @@
# OS Base includes
include(../base/CMakeLists.txt)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../base
)
########### next target ###############
if(PCIUTILS_FOUND)
MESSAGE(STATUS "Enabling PCI module based on pciutils library")
add_definitions( -DHAVE_PCIUTILS )
set(KCM_PCI_PART_SRCS kcm_pci.cpp ../base/os_current.cpp pci.cpp )
kde4_add_plugin(kcm_pci ${KCM_PCI_PART_SRCS})
target_link_libraries(kcm_pci ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY} ${PCIUTILS_LIBRARIES})
else(PCIUTILS_FOUND)
set(KCM_PCI_PART_SRCS kcm_pci.cpp ../base/os_current.cpp )
kde4_add_plugin(kcm_pci ${KCM_PCI_PART_SRCS})
target_link_libraries(kcm_pci ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY} )
endif(PCIUTILS_FOUND)
install(TARGETS kcm_pci DESTINATION ${PLUGIN_INSTALL_DIR})
########### install files ###############
install( FILES kcm_pci.desktop DESTINATION ${SERVICES_INSTALL_DIR})

View file

@ -0,0 +1,2 @@
#! /usr/bin/env bash
$XGETTEXT *.cpp -o $podir/kcm_pci.pot

View file

@ -0,0 +1,90 @@
/*
* Copyright (C) 2008 Nicolas Ternisien <nicolas.ternisien@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kcm_pci.h"
#include <QtGui>
#include <QStringList>
#include <KPluginFactory>
#include <KPluginLoader>
#include <kaboutdata.h>
#include <kdialog.h>
#include <kdebug.h>
#include <QLayout>
#include <QPainter>
#include <QPixmap>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <klocale.h>
#include <kglobal.h>
#include <kdialog.h>
#include <kseparator.h>
K_PLUGIN_FACTORY(KCMPciFactory,
registerPlugin<KCMPci>();
)
K_EXPORT_PLUGIN(KCMPciFactory("kcm_pci"))
KCMPci::KCMPci(QWidget *parent, const QVariantList &) :
KCModule(KCMPciFactory::componentData(), parent) {
KAboutData *about = new KAboutData(I18N_NOOP("kcm_pci"), 0,
ki18n("KDE PCI Information Control Module"),
0, KLocalizedString(), KAboutData::License_GPL,
ki18n( "(c) 2008 Nicolas Ternisien"
"(c) 1998 - 2002 Helge Deller"));
about->addAuthor(ki18n("Nicolas Ternisien"), KLocalizedString(), "nicolas.ternisien@gmail.com");
about->addAuthor(ki18n("Helge Deller"), KLocalizedString(), "deller@gmx.de");
setAboutData(about);
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->setMargin(0);
tree = new QTreeWidget(this);
layout->addWidget(tree);
tree->setSelectionMode(QAbstractItemView::ExtendedSelection);
tree->setAllColumnsShowFocus(true);
tree->setRootIsDecorated(false);
tree->setWhatsThis(i18n("This list displays PCI information.") );
}
KCMPci::~KCMPci() {
}
void KCMPci::load() {
kDebug() << "Loading PCI information..." << endl;
GetInfo_PCI(tree);
}
QString KCMPci::quickHelp() const {
return i18n("This display shows information about PCI slots of your computer and the related connected devices.");
}
#include "kcm_pci.moc"

View file

@ -1,13 +1,11 @@
[Desktop Entry]
Exec=kcmshell4 pci
Icon=kcmpci
Exec=kcmshell4 kcm_pci
Icon=memory
Type=Service
X-KDE-ServiceTypes=KCModule
X-DocPath=kinfocenter/pci/index.html
X-KDE-Library=kcm_info
X-KDE-PluginKeyword=pci
X-KDE-Library=kcm_pci
X-KDE-ParentApp=kinfocenter
Name=PCI

53
kinfocenter/pci/kcm_pci.h Normal file
View file

@ -0,0 +1,53 @@
/*
* memory.h
*
* Copyright (C) 2008 Nicolas Ternisien <nicolas.ternisien@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KCONTROL_PCI_H
#define KCONTROL_PCI_H
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <kcmodule.h>
#include <kaboutdata.h>
#include "os_current.h"
class QStringList;
class QPushButton;
class QTreeWidget;
class KCMPci : public KCModule {
Q_OBJECT
public:
explicit KCMPci(QWidget *parent = NULL, const QVariantList &list = QVariantList());
~KCMPci();
virtual void load();
virtual QString quickHelp() const;
private:
QTreeWidget* tree;
};
#endif

808
kinfocenter/pci/pci.cpp Normal file
View file

@ -0,0 +1,808 @@
/* Retreive information about PCI subsystem trough libpci library from
pciutils package. This should be possible on Linux, BSD and AIX.
This code is based on example.c, lspci.c and pci.ids from pciutils.
Device classes, subclasses and programing interfaces are hardcoded
here, since there are only few of them, and they are important and
should their names be translated.
Author: Konrad Rzepecki <hannibal@megapolis.pl>
*/
#include "pci_private.h"
//extern "C" is needed to proper linking with libpci
extern "C" {
#include <pci/pci.h>
}
#include <unistd.h>
#include <sys/types.h> //getuid
#include <ctype.h> //isxdigit
#include <string.h> //memcpy
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QFile>
static const QString& getNameById(const id2name *const table, int id) {
for (int i=0;; i++) {
if ((table[i].id==id)||(table[i].id==-1)) {
return table[i].name;
}//if
}//while
}//getNameById
static const QString& getNameBy2Id(const id3name *const table, int id, int id2) {
for (int i=0;; i++) {
if (((table[i].id==id)&&(table[i].id2==id2))|| ((table[i].id==id)&&(table[i].id2==-1))|| (table[i].id==-1)) {
return table[i].name;
}//if
}//while
}//getNameBy2Id
static const QString& getNameBy3Id(const id4name *const table, int id, int id2, int id3) {
for (int i=0;; i++) {
if (((table[i].id==id)&&(table[i].id2==id2)&&(table[i].id3==id3))|| ((table[i].id==id)&&(table[i].id2==id2)&&(table[i].id3==-1))|| ((table[i].id==id)&&(table[i].id2==-1))|| (table[i].id==-1)) {
return table[i].name;
}//if
}//while
}//getNameBy3Id
static QTreeWidgetItem* create(QTreeWidgetItem* parent, const QString& title, const QString& value) {
QStringList list;
list << title << value;
return new QTreeWidgetItem(parent, list);
}
static QTreeWidgetItem* createTitle(QTreeWidgetItem* parent, const QString& title) {
QStringList list;
list << title;
return new QTreeWidgetItem(parent, list);
}
static QTreeWidgetItem* addDeviceClass(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info) {
QString value;
QTreeWidgetItem *localAfter=NULL;
after=create(parent, i18n("Device Class"), getNameById(devClass, info->devClass)+value.sprintf(" (0x%02X)", info->devClass));
after=create(parent, i18n("Device Subclass"), getNameBy2Id(devSubclass, info->devClass, info->devSubClass)+value.sprintf(" (0x%02X)", info->devSubClass));
after=create(parent, i18n("Device Programming Interface"), getNameBy3Id(devInterface, info->devClass, info->devSubClass, info->devProgIface)+value.sprintf(" (0x%02X)", info->devProgIface));
if ((info->devClass==0x01)&&(info->devSubClass==0x01)) { //programming interface for IDE
localAfter=create(after, i18n("Master IDE Device"), (info->progIdeMaster ? i18n(strYes) : i18n(strNo)));
localAfter=create(after, i18n("Secondary programmable indicator"), (info->progSecProgInd ? i18n(strYes) : i18n(strNo)));
localAfter=create(after, i18n("Secondary operating mode"), (info->progSecOperMode ? i18n(strYes) : i18n(strNo)));
localAfter=create(after, i18n("Primary programmable indicator"), (info->progPriProgInd ? i18n(strYes) : i18n(strNo)));
localAfter=create(after, i18n("Primary operating mode"), (info->progPriOperMode ? i18n(strYes) : i18n(strNo)));
}//if
return after;
}//addDeviceClass
static QTreeWidgetItem* addVendor(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info, pci_access *PCIAccess) {
char nameBuffer[NAME_BUFFER_SIZE];
QString line, value, topname;
short int subvendor=0, subdevice=0;
bool isVendor=false, isDevice=false, isSub=false;
memset((void*)nameBuffer, 0, NAME_BUFFER_SIZE);
if (info->headerType==PCI_HEADER_TYPE_CARDBUS) {
subvendor=info->cbSubVendor;
subdevice=info->cbSubDevice;
}//if
else {
subvendor=info->subVendor;
subdevice=info->subDevice;
}//else
//WARNING all pci_lookup_name calls should have 4 extra args for compatibility with older pcilib !
if (pci_lookup_name(PCIAccess, nameBuffer, NAME_BUFFER_SIZE, PCI_LOOKUP_VENDOR, info->vendor, 0, 0, 0)!=NULL) {
// line.setAscii(nameBuffer); //not work, workaround below
line = QString::fromAscii(pci_lookup_name(PCIAccess, nameBuffer, NAME_BUFFER_SIZE, PCI_LOOKUP_VENDOR, info->vendor, 0, 0, 0));
if (line.contains("Unknown")==0) {
isVendor=true;
topname=line;
after=create(parent, i18n("Vendor"), line+value.sprintf(" (0x%04X)", info->vendor));
if (pci_lookup_name(PCIAccess, nameBuffer, NAME_BUFFER_SIZE, PCI_LOOKUP_DEVICE, info->vendor, info->device, 0, 0)!=NULL) {
// line.setAscii(nameBuffer); //not work, workaround below
line = QString::fromAscii(pci_lookup_name(PCIAccess, nameBuffer, NAME_BUFFER_SIZE, PCI_LOOKUP_DEVICE, info->vendor, info->device, 0, 0));
if (line.contains("Unknown")==0) {
isDevice=true;
topname+=QString(" ")+line;
after=create(parent, i18n("Device"), line+value.sprintf(" (0x%04X)", info->device));
if (info->headerType==PCI_HEADER_TYPE_BRIDGE) {
isSub=true;
}//if
else if (pci_lookup_name(PCIAccess, nameBuffer, NAME_BUFFER_SIZE, PCI_LOOKUP_VENDOR|PCI_LOOKUP_DEVICE|PCI_LOOKUP_SUBSYSTEM, info->vendor, info->device, subvendor, subdevice)!=NULL) {
// line.setAscii(nameBuffer); //not work, workaround below
line = QString::fromAscii(pci_lookup_name(PCIAccess, nameBuffer, NAME_BUFFER_SIZE, PCI_LOOKUP_VENDOR|PCI_LOOKUP_DEVICE|PCI_LOOKUP_SUBSYSTEM, info->vendor, info->device, subvendor, subdevice));
if (line.contains("Unknown")==0) {
isSub=true;
after=create(parent, i18n("Subsystem"), line+value.sprintf(" (0x%04X:0x%04X)", subvendor, subdevice));
}//if
}//eliif
}//if
}//iif
}//if
}//if
if (!isVendor) {
after=create(parent, i18n("Vendor"), i18n(strUnknown)+value.sprintf(" (0x%04X)", info->vendor));
if (!isDevice) {
after=create(parent, i18n("Device"), i18n(strUnknown)+value.sprintf(" (0x%04X)", info->device));
}//if
topname=i18n(strUnknown);
}//if
if ((!isSub)&&(info->headerType!=PCI_HEADER_TYPE_BRIDGE)) { //if entire subsytem was not found, search at least for subvendor
if (pci_lookup_name(PCIAccess, nameBuffer, NAME_BUFFER_SIZE, PCI_LOOKUP_VENDOR, subvendor, 0, 0, 0)!=NULL) {
// line.setAscii(nameBuffer); //not work, workaround below
line = QString::fromAscii(pci_lookup_name(PCIAccess, nameBuffer, NAME_BUFFER_SIZE, PCI_LOOKUP_VENDOR, subvendor, 0, 0, 0));
if (line.contains("Unknown")==0) {
after=create(parent, i18n("Subsystem"), line+i18n(" - device:")+value.sprintf(" 0x%04X (0x%04X:0x%04X)", subdevice, subvendor, subdevice));
}//if
else {
after=create(parent, i18n("Subsystem"), i18n(strUnknown)+value.sprintf(" (0x%04X:0x%04X)", subvendor, subdevice));
}//else
}//if
else {
after=create(parent, i18n("Subsystem"), i18n(strUnknown)+value.sprintf(" (0x%04X:0x%04X)", subvendor, subdevice));
}//else
}//if
parent->setText(1, topname);
return after;
}//addVendor
static QTreeWidgetItem* addInterrupt(QTreeWidgetItem *parent, QTreeWidgetItem *after, int irq, int pin) {
QTreeWidgetItem *localAfter=NULL;
QString value;
if ((irq!=0)||(pin!=0)) {
after=createTitle(parent, i18n("Interrupt"));
localAfter=create(after, i18n("IRQ"), value.sprintf("%i", irq));
localAfter=create(after, i18n("Pin"), value.sprintf("%c", (pin==0 ? '?' : 'A'-1+pin)));
}//if
return after;
}//addInterrupt
static QTreeWidgetItem* addControl(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info) {
QTreeWidgetItem *localAfter=NULL;
QString value;
after=create(parent, i18n("Control"), value.sprintf("0x%04X", info->command));
localAfter=create(after, i18n("Response in I/O space"), (info->comIo ? i18n(strEnabled) : i18n(strDisabled)));
localAfter=create(after, i18n("Response in memory space"), (info->comMemory ? i18n(strEnabled) : i18n(strDisabled)));
localAfter=create(after, i18n("Bus mastering"), (info->comMaster ? i18n(strEnabled) : i18n(strDisabled)));
localAfter=create(after, i18n("Response to special cycles"), (info->comSpecial ? i18n(strEnabled) : i18n(strDisabled)));
localAfter=create(after, i18n("Memory write and invalidate"), (info->comInvalidate ? i18n(strEnabled) : i18n(strDisabled)));
localAfter=create(after, i18n("Palette snooping"), (info->comVgaPalette ? i18n(strEnabled) : i18n(strDisabled)));
localAfter=create(after, i18n("Parity checking"), (info->comParity ? i18n(strEnabled) : i18n(strDisabled)));
localAfter=create(after, i18n("Address/data stepping"), (info->comWait ? i18n(strEnabled) : i18n(strDisabled)));
localAfter=create(after, i18n("System error"), (info->comSerr ? i18n(strEnabled) : i18n(strDisabled)));
localAfter=create(after, i18n("Back-to-back writes"), (info->comFastBack ? i18n(strEnabled) : i18n(strDisabled)));
localAfter=create(after, i18n("Interrupt"), (info->comInterrupt ? i18n(strDisabled) : i18n(strEnabled))); //reverse order is intentional
return after;
}//addControl
static QTreeWidgetItem* addStatus(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info) {
QTreeWidgetItem *localAfter=NULL;
QString value;
after=create(parent, i18n("Status"), value.sprintf("0x%04X", info->status));
localAfter=create(after, i18n("Interrupt status"), (info->statCapList ? i18n(strEnabled) : i18n(strDisabled)));
localAfter=create(after, i18n("Capability list"), (info->statCapList ? i18n(strYes) : i18n(strNo)));
localAfter=create(after, i18n("66 MHz PCI 2.1 bus"), (info->stat66MHz ? i18n(strYes) : i18n(strNo)));
localAfter=create(after, i18n("User definable features"), (info->statUdf ? i18n(strYes) : i18n(strNo)));
localAfter=create(after, i18n("Accept fast-back to back"), (info->statFastBack ? i18n(strYes) : i18n(strNo)));
localAfter=create(after, i18n("Data parity error"), (info->statParity ? i18n(strYes) : i18n(strNo)));
localAfter=create(after, i18n("Device selection timing"), getNameById(devSel, info->statDevsel));
localAfter=create(after, i18n("Signaled target abort"), (info->statSigTargetAbort ? i18n(strYes) : i18n(strNo)));
localAfter=create(after, i18n("Received target abort"), (info->statRecTargetAbort ? i18n(strYes) : i18n(strNo)));
localAfter=create(after, i18n("Received master abort"), (info->statRecMasterAbort ? i18n(strYes) : i18n(strNo)));
localAfter=create(after, i18n("Signaled system error"), (info->statSigSystemError ? i18n(strYes) : i18n(strNo)));
localAfter=create(after, i18n("Parity error"), (info->statDetectedParity ? i18n(strYes) : i18n(strNo)));
return after;
}//addStatus
static QTreeWidgetItem* addLatency(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info) {
QTreeWidgetItem *localAfter=NULL;
QString value;
after=create(parent, i18n("Latency"), value.sprintf("%u", info->latencyTimer));
if (info->headerType==PCI_HEADER_TYPE_NORMAL) {
if (info->minGnt==0) {
localAfter=create(after, i18n("MIN_GNT"), i18n("No major requirements (0x00)"));
}//if
else {
localAfter=create(after, i18n("MIN_GNT"), value.sprintf("%u ns (0x%02X)", info->minGnt*250, info->minGnt));
}//else
if (info->maxLat==0) {
localAfter=create(after, i18n("MAX_LAT"), i18n("No major requirements (0x00)"));
}//if
else {
localAfter=create(after, i18n("MAX_LAT"), value.sprintf("%u ns (0x%02X)", info->maxLat*250, info->maxLat));
}//else
}//if
return after;
}//addLatency
static QTreeWidgetItem* addHeaderType(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info) {
QTreeWidgetItem *localAfter=NULL;
QString value;
after=create(parent, i18n("Header"),value.sprintf("0x%02X",info->headerTypeFull));
localAfter=create(after, i18n("Type"),getNameById(headerType,info->headerType)+value.sprintf(" (0x%02X)",info->headerType));
localAfter=create(after, i18n("Multifunctional"),(info->multifunctional?i18n(strYes):i18n(strNo)));
return after;
}//addHeaderType
static QTreeWidgetItem* addBist(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info) {
QTreeWidgetItem *localAfter=NULL;
QString value;
after=create(parent, i18n("Build-in self test"), value.sprintf("0x%02X", info->bist));
localAfter=create(after, i18n("BIST Capable"), (info->bistCapable ? i18n(strYes) : i18n(strNo)));
if (info->bistCapable==1) {
localAfter=create(after, i18n("BIST Start"), (info->bistStart ? i18n(strYes) : i18n(strNo)));
localAfter=create(after, i18n("Completion code"), value.sprintf("0x%01X", info->bistCode));
}//if
return after;
}//addBist
static QTreeWidgetItem* addSize(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciaddr_t size) {
if (size<0x400) {
after=create(parent, i18n("Size"), QString::QString("%1 B").arg(static_cast<unsigned long>(size)));
}//if
else if (size<0x100000) {
after=create(parent, i18n("Size"), QString::QString("%1 kiB").arg(static_cast<unsigned long>(size/0x400)));
}//elif
else if (size<0x40000000) {
after=create(parent, i18n("Size"), QString::QString("%1 MiB").arg(static_cast<unsigned long>(size/0x100000)));
}//elif
#ifdef HAVE_PCIADDR_T64
else if (size<0x10000000000LL) {
after=create(parent, i18n("Size"),QString::QString("%1 GiB").arg(static_cast<unsigned long>(size/0x40000000)));
}//elif
else if (size<0x4000000000000LL) {
after=create(parent, i18n("Size"),QString::QString("%1 PiB").arg(static_cast<unsigned long>(size/0x10000000000LL)));
}//elif
else if (size<0x1000000000000000LL) {
after=create(parent, i18n("Size"),QString::QString("%1 EiB").arg(static_cast<unsigned long>(size/0x4000000000000LL)));
}//elif
#else //HAVE_PCIADDR_T64
else {
after=create(parent, i18n("Size"), QString::QString("%1 GiB").arg(static_cast<unsigned long>(size/0x40000000)));
}//else
#endif //HAVE_PCIADDR_T64
return after;
}//addSize
static QTreeWidgetItem* addMapping(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info, pci_dev* PCIDevice) {
QTreeWidgetItem *localAfter=NULL;
QTreeWidgetItem *topLocalAfter=NULL;
QString value;
bool is64b=false;
after=createTitle(parent, i18n("Address mappings"));
for (int i=0; i<6; i++) {
if (((info->headerType==PCI_HEADER_TYPE_BRIDGE)&&(i>1))||((info->headerType==PCI_HEADER_TYPE_CARDBUS)&&(i>0))) {
break;
}//if
if (is64b) { //skip one range
continue;
}//if
topLocalAfter=createTitle(after, i18n("Mapping %1").arg(i));
localAfter=create(topLocalAfter, i18n("Space"), (info->mapping[i].baseAddressMap ? i18n("I/O") : i18n("Memory")));
if (info->mapping[i].baseAddressMap==0) { //memory only
localAfter=create(topLocalAfter, i18n("Type"), getNameById(mappingType, info->mapping[i].baseAddressType));
localAfter=create(topLocalAfter, i18n("Prefetchable"), (info->mapping[i].baseAddressPref ? i18n(strYes) : i18n(strNo)));
}//if
if (is64b) { //there is no long long support in Qt so we need compose value
topLocalAfter->setText(1, value.sprintf("0x%08X%08X", info->mapping[i+1].baseAddress, info->mapping[i].baseAddress));
if (info->mapping[i+1].baseAddress==0) { //no top 4 bytes
if ((info->mapping[i].baseAddress&(~(info->mapping[i].baseAddressMap ? 0x3 : 0xF)))==0) { //no address at all
localAfter=create(topLocalAfter, i18n("Address"), i18n("Unassigned"));
localAfter=create(topLocalAfter, i18n("Size"), i18n("Unassigned"));
}//if
else {
localAfter=create(topLocalAfter, i18n("Address"), value.sprintf("0x%X", (info->mapping[i].baseAddress&(~(info->mapping[i].baseAddressMap ? 0x3 : 0xF)))));
localAfter=addSize(topLocalAfter, localAfter, PCIDevice->size[i]);
}//else
}//if
else {
localAfter=create(topLocalAfter, i18n("Address"), value.sprintf("0x%X%08X", info->mapping[i+1].baseAddress, (~(info->mapping[i].baseAddress&(info->mapping[i].baseAddressMap ? 0x3 : 0xF)))));
localAfter=addSize(topLocalAfter, localAfter, PCIDevice->size[i]);
}//else
}//if
else {
topLocalAfter->setText(1, value.sprintf("0x%08X", info->mapping[i].baseAddress));
if ((info->mapping[i].baseAddress&(~(info->mapping[i].baseAddressMap ? 0x3 : 0xF)))==0) { //no address at all
localAfter=create(topLocalAfter, i18n("Address"), i18n("Unassigned"));
localAfter=create(topLocalAfter, i18n("Size"), i18n("Unassigned"));
}//if
else {
localAfter=create(topLocalAfter, i18n("Address"), value.sprintf("0x%X", (info->mapping[i].baseAddress&(~(info->mapping[i].baseAddressMap ? 0x3 : 0xF)))));
localAfter=addSize(topLocalAfter, localAfter, PCIDevice->size[i]);
}//else
}//else
}//for
return after;
}//addMapping
static QTreeWidgetItem* addBus(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info) {
QTreeWidgetItem *localAfter=NULL;
QString value;
if (info->headerType==PCI_HEADER_TYPE_BRIDGE) {
after=createTitle(parent, i18n("Bus"));
localAfter=create(after, i18n("Primary bus number"), value.sprintf("0x%02X", info->primaryBus));
localAfter=create(after, i18n("Secondary bus number"), value.sprintf("0x%02X", info->secondaryBus));
localAfter=create(after, i18n("Subordinate bus number"), value.sprintf("0x%02X", info->subordinateBus));
localAfter=create(after, i18n("Secondary latency timer"), value.sprintf("0x%02X", info->secLatencyTimer));
}//if
else if (info->headerType==PCI_HEADER_TYPE_CARDBUS) { //should be checked
after=createTitle(parent, i18n("Bus"));
localAfter=create(after, i18n("Primary bus number"), value.sprintf("0x%02X", info->cbPrimaryBus));
localAfter=create(after, i18n("CardBus number"), value.sprintf("0x%02X", info->cbCardBus));
localAfter=create(after, i18n("Subordinate bus number"), value.sprintf("0x%02X", info->cbSubordinateBus));
localAfter=create(after, i18n("CardBus latency timer"), value.sprintf("0x%02X", info->cbLatencyTimer));
}//elif
return after;
}//addBus
static QTreeWidgetItem* addSecStatus(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info) {
QTreeWidgetItem *localAfter=NULL;
QString value;
if (info->headerType==PCI_HEADER_TYPE_BRIDGE) {
after=create(parent, i18n("Secondary status"), value.sprintf("0x%04X", info->secStatus));
localAfter=create(after, i18n("Interrupt status"),(info->secStatCapList?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Capability list"),(info->secStatCapList?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("66 MHz PCI 2.1 bus"),(info->secStat66MHz?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("User definable features"),(info->secStatUdf?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Accept fast-back to back"),(info->secStatFastBack?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Data parity error"),(info->secStatParity?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Device selection timing"),getNameById(devSel,info->secStatDevsel));
localAfter=create(after, i18n("Signaled target abort"),(info->secStatSigTargetAbort?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Received target abort"),(info->secStatRecTargetAbort?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Received master abort"),(info->secStatRecMasterAbort?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Signaled system error"),(info->secStatSigSystemError?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Parity error"),(info->secStatDetectedParity?i18n(strYes):i18n(strNo)));
}//if
else if (info->headerType==PCI_HEADER_TYPE_CARDBUS) { //should be checked
after=create(parent,i18n("Secondary status"),value.sprintf("0x%04X",info->cbSecStatus));
localAfter=create(after, i18n("Interrupt status"),(info->cbSecStatCapList?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Capability list"),(info->cbSecStatCapList?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("66 MHz PCI 2.1 bus"),(info->cbSecStat66MHz?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("User definable features"),(info->cbSecStatUdf?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Accept fast-back to back"),(info->cbSecStatFastBack?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Data parity error"),(info->cbSecStatParity?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Device selection timing"),getNameById(devSel,info->cbSecStatDevsel));
localAfter=create(after, i18n("Signaled target abort"),(info->cbSecStatSigTargetAbort?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Received target abort"),(info->cbSecStatRecTargetAbort?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Received master abort"),(info->cbSecStatRecMasterAbort?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Signaled system error"),(info->cbSecStatSigSystemError?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Parity error"),(info->cbSecStatDetectedParity?i18n(strYes):i18n(strNo)));
}//elif
return after;
}//addSecStatus
static QTreeWidgetItem* addBridgeBehind(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info) {
QTreeWidgetItem *localAfter=NULL;
QString value;
if (info->headerType==PCI_HEADER_TYPE_BRIDGE) {
after=createTitle(parent, i18n("I/O behind bridge"));
localAfter=create(after, i18n("32 bit"),(info->ioBaseType?i18n(strYes):i18n(strNo)));
if (info->ioBaseType==0) {
localAfter=create(after, i18n("Base"),value.sprintf("0x%04X",info->ioBase&0xFFF0));
localAfter=create(after, i18n("Limit"),value.sprintf("0x%04X",info->ioLimit|0x0F));
}//if
else {
localAfter=create(after, i18n("Base"),value.sprintf("0x%04X%04X",info->ioBaseUpper16,info->ioBase&0xFFF0));
localAfter=create(after, i18n("Limit"),value.sprintf("0x%04X%04X",info->ioLimitUpper16,info->ioLimit|0x0F));
}//else
after=createTitle(parent, i18n("Memory behind bridge"));
localAfter=create(after, i18n("Base"),value.sprintf("0x%08X",(info->memoryBase<<16)&0xFFFFFFF0));
localAfter=create(after, i18n("Limit"),value.sprintf("0x%08X",(info->memoryLimit<<16)|0x0FFFFF));
after=createTitle(parent, i18n("Prefetchable memory behind bridge"));
localAfter=create(after, i18n("64 bit"),(info->ioBaseType?i18n(strYes):i18n(strNo)));
if (info->ioBaseType==0) {
localAfter=create(after, i18n("Base"),value.sprintf("0x%08X",(info->prefMemoryBase<<16)&0xFFFFFFF0));
localAfter=create(after, i18n("Limit"),value.sprintf("0x%08X",(info->prefMemoryLimit<<16)|0x0FFFFF));
}//if
else {
localAfter=create(after, i18n("Base"),value.sprintf("0x%08X%08X",info->prefBaseUpper32,(info->prefMemoryBase<<16)&0xFFFFFFF0));
localAfter=create(after, i18n("Limit"),value.sprintf("0x%0x8X%08X",info->prefLimitUpper32,(info->prefMemoryLimit<<16)|0x0FFFFF));
}//else
}//if
return after;
}//addBridgeBechind
static QTreeWidgetItem* addBridgeControl(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info) {
QTreeWidgetItem *localAfter=NULL;
QString value;
if (info->headerType==PCI_HEADER_TYPE_BRIDGE) {
after=create(parent, i18n("Bridge control"),value.sprintf("0x%04X",info->bridgeControl));
localAfter=create(after, i18n("Secondary parity checking"),(info->bridgeControlParity?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Secondary system error"),(info->bridgeControlSerr?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("ISA ports forwarding"),(info->bridgeControlIsa?i18n(strDisabled):i18n(strEnabled))); //reverse order is intentional
localAfter=create(after, i18n("VGA forwarding"),(info->bridgeControlVga?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Master abort"),(info->bridgeControlMasterAbort?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Secondary bus reset"),(info->bridgeControlBusReset?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Secondary back-to-back writes"),(info->bridgeControlFastBack?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Primary discard timer counts"),(info->bridgeControlPriDisTim?i18n("2e10 PCI clocks"):i18n("2e15 PCI clocks")));
localAfter=create(after, i18n("Secondary discard timer counts"),(info->bridgeControlSecDisTim?i18n("2e10 PCI clocks"):i18n("2e15 PCI clocks")));
localAfter=create(after, i18n("Discard timer error"),(info->bridgeControlDisTimStat?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Discard timer system error"),(info->bridgeControlDisTimeSerr?i18n(strEnabled):i18n(strDisabled)));
}//if
return after;
}//addBridgeControl
static QTreeWidgetItem* addRom(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info, pci_dev* PCIDevice) {
QTreeWidgetItem *localAfter=NULL;
QString value;
if ((info->headerType==PCI_HEADER_TYPE_NORMAL)||(info->headerType==PCI_HEADER_TYPE_BRIDGE)) {
after=createTitle(parent, i18n("Expansion ROM"));
localAfter=create(after, i18n("Status"),(info->romEnabled?i18n(strEnabled):i18n(strDisabled)));
if (PCIDevice->rom_base_addr==0) { //no address at all
localAfter=create(after, i18n("Address"),i18n("Unassigned"));
localAfter=create(after, i18n("Size"),i18n("Unassigned"));
}//if
else {
localAfter=create(after, i18n("Address"),value.sprintf("0x%X",static_cast<unsigned>(PCIDevice->rom_base_addr)));
localAfter=addSize(after, localAfter, PCIDevice->rom_size);
}//else
}//if
return after;
}//addRom
static QTreeWidgetItem* addCardbusResource(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info) {
QTreeWidgetItem *localAfter=NULL;
QTreeWidgetItem *topLocalAfter=NULL;
QString value;
int pref=0;
if (info->headerType==PCI_HEADER_TYPE_CARDBUS) {
after=createTitle(parent, i18n("Memory windows"));
for (int i=0; i<2; i++) {
pref=(i ? info->cbControlPref1 : info->cbControlPref0);
topLocalAfter=createTitle(after, i18n("Window %1").arg(i));
localAfter=create(topLocalAfter, i18n("Prefetchable"),(pref?i18n(strYes):i18n(strNo)));
localAfter=create(topLocalAfter, i18n("Base"),value.sprintf("0x%08X",info->cbMemory[i].cbMemoryBase));
localAfter=create(topLocalAfter, i18n("Limit"),value.sprintf("0x%08X",info->cbMemory[i].cbMemoryLimit));
}//for
after=createTitle(parent, i18n("I/O windows"));
for (int i=0; i<2; i++) {
topLocalAfter=createTitle(after, i18n("Window %1").arg(i));
localAfter=create(topLocalAfter, i18n("Type"),(info->cbIo[i].cbIoBaseType?i18n("32 bit"):i18n("16 bit")));
if (info->cbIo[i].cbIoBaseType==1) {
localAfter=create(topLocalAfter, i18n("Base"),value.sprintf("0x%08X",info->cbIo[i].cbIoBase&0xFFFFFFFC));
localAfter=create(topLocalAfter, i18n("Limit"),value.sprintf("0x%08X",info->cbIo[i].cbIoLimit|0x03));
}//if
else {
localAfter=create(topLocalAfter, i18n("Base"),value.sprintf("0x%04X",info->cbIo[i].cbIoBase&0xFFFC));
localAfter=create(topLocalAfter, i18n("Limit"),value.sprintf("0x%04X",(info->cbIo[i].cbIoLimit&0xFFFF)|0x03));
}//else
}//for
after=create(parent, i18n("16-bit legacy interface ports"),value.sprintf("0x%04X",info->cbLegacyModeBase));
}//if
return after;
}//addCardbusResource
static QTreeWidgetItem* addCardbusControl(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info) {
QTreeWidgetItem *localAfter=NULL;
QString value;
if (info->headerType==PCI_HEADER_TYPE_CARDBUS) {
after=create(parent, i18n("CardBus control"),value.sprintf("0x%04X",info->cbControl));
localAfter=create(after, i18n("Secondary parity checking"),(info->cbControlParity?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Secondary system error"),(info->cbControlSerr?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("ISA ports forwarding"),(info->cbControlIsa?i18n(strDisabled):i18n(strEnabled))); //reverse order is intentional
localAfter=create(after, i18n("VGA forwarding"),(info->cbControlVga?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Master abort"),(info->cbControlMasterAbort?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Interrupts for 16 bit cards"),(info->cbControl16Int?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Window 0 prefetchable memory"),(info->cbControlPref0?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Window 1 prefetchable memory"),(info->cbControlPref1?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Post writes"),(info->cbControlPostWrites?i18n(strEnabled):i18n(strDisabled)));
}//if
return after;
}//addCardbusControl
static QTreeWidgetItem* addRaw(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info) {
QTreeWidgetItem *localAfter=NULL;
QString value, temp;
after=createTitle(parent, i18n("Raw PCI config space"));
for (int i=0; i<(getuid()==0 ? 16 : 4); i++) {
for (int j=0; j<16; j++) {
if (j!=0) {
value+=temp.sprintf(" %02X", info->raw[i*16+j]);
}//if
else {
value.sprintf("%02X", info->raw[i*16+j]);
}//if
}//for
localAfter=create(after, temp.sprintf("0x%02X:",i*16),value);
}//for
return after;
}//addRaw
static QTreeWidgetItem* addCapsPm(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info, int offset) {
QTreeWidgetItem *localAfter=NULL;
QTreeWidgetItem *subLocalAfter=NULL;
QString value;
pmInfo infoPm;
if ((offset+2+sizeof(pmInfo))<256) {
memcpy(reinterpret_cast<void*>(&infoPm.raw[0]), reinterpret_cast<void*>(&info->raw[offset+2]), sizeof(pmInfo));
after=create(parent, i18n("Capabilities"),value.sprintf("0x%04X",infoPm.caps));
localAfter=create(after, i18n("Version"),QString::number(infoPm.capsVer));
localAfter=create(after, i18n("Clock required for PME generation"),(infoPm.capsClock?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Device specific initialization required"),(infoPm.capsDsi?i18n(strYes):i18n(strNo)));
localAfter=create(after, i18n("Maximum auxiliary current required in D3 cold"),getNameById(auxCur,infoPm.capsAuxCur));
localAfter=create(after, i18n("D1 support"),(infoPm.capsD1Supp?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("D2 support"),(infoPm.capsD2Supp?i18n(strEnabled):i18n(strDisabled)));
localAfter=createTitle(after, i18n("Power management events"));
subLocalAfter=create(localAfter, i18n("D0"),(infoPm.capsPmeD0?i18n(strEnabled):i18n(strDisabled)));
subLocalAfter=create(localAfter, i18n("D1"),(infoPm.capsPmeD1?i18n(strEnabled):i18n(strDisabled)));
subLocalAfter=create(localAfter, i18n("D2"),(infoPm.capsPmeD2?i18n(strEnabled):i18n(strDisabled)));
subLocalAfter=create(localAfter, i18n("D3 hot"),(infoPm.capsPmeD3hot?i18n(strEnabled):i18n(strDisabled)));
subLocalAfter=create(localAfter, i18n("D3 cold"),(infoPm.capsPmeD3cold?i18n(strEnabled):i18n(strDisabled)));
localAfter=NULL;
after=create(parent, i18n("Status"),value.sprintf("0x%04X",infoPm.status));
localAfter=create(after, i18n("Power state"),getNameById(powerState,infoPm.statPower));
localAfter=create(after, i18n("Power management"),(infoPm.statPme?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Data select"),QString::number(infoPm.statDataSelect));
localAfter=create(after, i18n("Data scale"),QString::number(infoPm.statDataScale));
localAfter=create(after, i18n("Power management status"),(infoPm.statPmeStat?i18n(strEnabled):i18n(strDisabled)));
if ((info->devClass==0x06)&&(info->devSubClass==0x04)) { //PCI bridge
subLocalAfter=NULL;
localAfter=create(after, i18n("Bridge status"),value.sprintf("0x%02X",infoPm.statusBridge));
subLocalAfter=create(localAfter, i18n("Secondary bus state in D3 hot"),(infoPm.statBridgeBx?i18n("B2"):i18n("B3")));
subLocalAfter=create(localAfter, i18n("Secondary bus power & clock control"),(infoPm.statBridgeClock?i18n(strEnabled):i18n(strDisabled)));
}//if
}//if
after=create(parent, i18n("Data"),value.sprintf("0x%02X",infoPm.data));
return after;
}//addCapsPm
static QTreeWidgetItem* addCapsAgp(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info, int offset) {
QTreeWidgetItem *localAfter=NULL;
QString value;
agpInfo infoAgp;
int i, cycleSize;
if ((offset+2+sizeof(agpInfo))<256) {
memcpy(reinterpret_cast<void*>(&infoAgp.raw[0]), reinterpret_cast<void*>(&info->raw[offset+2]), sizeof(agpInfo));
// after=create(parent, i18n("Revision"),value.sprintf("%i.%i",infoAgp.revMaior,infoAgp.revMinor));
after=create(parent, i18n("Revision"),QString::QString("%1.%2").arg(infoAgp.revMaior).arg(infoAgp.revMinor));
after=create(parent, i18n("Status"),value.sprintf("0x%08X",infoAgp.status));
localAfter=create(after, i18n("Rate"),getNameById(agpRate,infoAgp.statusEnhRate));
localAfter=create(after, i18n("AGP 3.0 mode"),(infoAgp.statusMode?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Fast Writes"),(infoAgp.statusFastWrite?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Address over 4 GiB"),(infoAgp.statusOver4gb?i18n(strEnabled):i18n(strDisabled)));
if (infoAgp.statusMode==1) {
localAfter=create(after, i18n("Translation of host processor access"),(infoAgp.statusHtrans?i18n(strDisabled):i18n(strEnabled))); //reverse order is intentional
localAfter=create(after, i18n("64 bit GART"),(infoAgp.statusGart64b?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Cache Coherency"),(infoAgp.statusItaCoh?i18n(strEnabled):i18n(strDisabled)));
}//if
localAfter=create(after, i18n("Side band addressing"),(infoAgp.statusSba?i18n(strEnabled):i18n(strDisabled)));
if (infoAgp.statusMode==1) {
localAfter=create(after, i18n("Calibrating cycle"),getNameById(calCycle,infoAgp.statusCalCycle));
for (i=0, cycleSize=1; i<(infoAgp.statusOptReqSize+4); i++) {
cycleSize*=2;
}//for
localAfter=create(after, i18n("Optimum asynchronous request size"),value.sprintf("%i (0x%02X)",cycleSize,infoAgp.statusOptReqSize));
localAfter=create(after, i18n("Isochronous transactions"),(infoAgp.statusIsochSupp?i18n(strEnabled):i18n(strDisabled)));
}//if
localAfter=create(after, i18n("Maximum number of AGP command"),value.sprintf("%i (0x%02X)",infoAgp.statusReq+1,infoAgp.statusReq));
localAfter=NULL;
after=create(parent, i18n("Configuration"),value.sprintf("0x%08X",infoAgp.config));
localAfter=create(after, i18n("Rate"),getNameById(agpRate,infoAgp.configEnhRate));
localAfter=create(after, i18n("Fast Writes"),(infoAgp.configFastWrite?i18n(strEnabled):i18n(strDisabled)));
if (infoAgp.statusMode==1) {
localAfter=create(after, i18n("Address over 4 GiB"),(infoAgp.configOver4gb?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("64 bit GART"),(infoAgp.configGart64b?i18n(strEnabled):i18n(strDisabled)));
}//if
localAfter=create(after, i18n("AGP"),(infoAgp.configAgp?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Side band addressing"),(infoAgp.configSba?i18n(strEnabled):i18n(strDisabled)));
if (infoAgp.statusMode==1) {
localAfter=create(after, i18n("Calibrating cycle"),getNameById(calCycle,infoAgp.configCalCycle));
for (i=0, cycleSize=1; i<(infoAgp.configOptReqSize+4); i++) {
cycleSize*=2;
}//for
localAfter=create(after, i18n("Optimum asynchronous request size"),value.sprintf("%i (0x%02X)",cycleSize,infoAgp.configOptReqSize));
}//if
localAfter=create(after, i18n("Maximum number of AGP command"),value.sprintf("%i (0x%02X)",infoAgp.configReq+1,infoAgp.configReq));
}//if
return after;
}//addCapsAgp
static QTreeWidgetItem* addCapsVpd(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info, int offset) {
QString value;
vpdInfo infoVpd;
if ((offset+2+sizeof(vpdInfo))<256) {
memcpy(reinterpret_cast<void*>(&infoVpd.raw[0]), reinterpret_cast<void*>(&info->raw[offset+2]), sizeof(vpdInfo));
after=create(parent, i18n("Data address"),value.sprintf("0x%04X",infoVpd.vpdAddress));
after=create(parent, i18n("Transfer completed"),(infoVpd.vpdTransfer?i18n(strYes):i18n(strNo)));
after=create(parent, i18n("Data"),value.sprintf("0x%08X",infoVpd.vpdData));
}//if
return after;
}//addCapsVpd
static QTreeWidgetItem* addCapsMsi(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info, int offset) {
QTreeWidgetItem *localAfter=NULL;
QString value;
msiInfo infoMsi;
int size=10;
if ((offset+4)<256) { //copy control only (for now)
memcpy(reinterpret_cast<void*>(&infoMsi.raw[0]), reinterpret_cast<void*>(&info->raw[offset+2]), 2);
after=create(parent, i18n("Message control"),value.sprintf("0x%04X",infoMsi.msiControl));
localAfter=create(after, i18n("Message signaled interrupts"),(infoMsi.msiEnable?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Multiple message capable"),getNameById(multipleMessage,infoMsi.msiMmCapable));
localAfter=create(after, i18n("Multiple message enable"),getNameById(multipleMessage,infoMsi.msiMmEnable));
localAfter=create(after, i18n("64 bit address"),(infoMsi.msi64bit?i18n(strEnabled):i18n(strDisabled)));
localAfter=create(after, i18n("Per vector masking"),(infoMsi.msiPerVector?i18n(strEnabled):i18n(strDisabled)));
size+=(infoMsi.msi64bit ? 4 : 0)+(infoMsi.msiPerVector ? 8 : 0);
if ((offset+size)<256) { //copy all MSI data
memcpy(reinterpret_cast<void*>(&infoMsi.raw[0]), reinterpret_cast<void*>(&info->raw[offset+size]), 2);
if (infoMsi.msi64bit==1) {
after=create(parent, i18n("Address"),value.sprintf("0x%08X%08X",infoMsi.msiUpperAddress,infoMsi.msiAddress));
after=create(parent, i18n("Data"),value.sprintf("0x%04X",infoMsi.msiData64));
if (infoMsi.msiPerVector==1) {
after=create(parent, i18n("Mask"),value.sprintf("0x%08X",infoMsi.msiMask64));
after=create(parent, i18n("Pending"),value.sprintf("0x%08X",infoMsi.msiPending64));
}//if
}//if
else {
after=create(parent, i18n("Address"),value.sprintf("0x%08X",infoMsi.msiAddress));
after=create(parent, i18n("Data"),value.sprintf("0x%04X",infoMsi.msiData));
if (infoMsi.msiPerVector==1) {
after=create(parent, i18n("Mask"),value.sprintf("0x%08X",infoMsi.msiMask));
after=create(parent, i18n("Pending"),value.sprintf("0x%08X",infoMsi.msiPending));
}//if
}//else
}//if
}//if
return after;
}//addCapsMsi
static QTreeWidgetItem* addCapsVendor(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info, int offset) {
QString value, temp;
after=create(parent, i18n("Length"),value.sprintf("0x%02X",info->raw[offset+2]));
if ((offset+3)<256) { //check partial size
if (info->raw[offset+2]<=2) {
after=create(parent, i18n("Data"),i18n("None"));
}//if
else {
if ((offset+info->raw[offset+2])<256) { //check full size
for (int i=3; i<(info->raw[offset+2]); i++) {
if (i!=3) {
value+=temp.sprintf(" 0x%02X", info->raw[offset+i]);
}//if
else {
value.sprintf("0x%02X", info->raw[offset+i]);
}//if
}//for
after=create(parent, i18n("Data"),value);
}//if
}//else
}//if
return after;
}//addCapsVendor
static QTreeWidgetItem* addCaps(QTreeWidgetItem *parent, QTreeWidgetItem *after, pciInfo *info) {
QTreeWidgetItem *localAfter=NULL;
QTreeWidgetItem *topLocalAfter=NULL;
QString value;
unsigned char offset;
if ((info->headerType==PCI_HEADER_TYPE_NORMAL)||(info->headerType==PCI_HEADER_TYPE_BRIDGE)) {
if ((info->capabilityList!=0)&&(info->statCapList!=0)) {
after=create(parent, i18n("Capabilities"),value.sprintf("0x%02X",info->capabilityList));
if (getuid()==0) {
for (offset=info->capabilityList; offset!=0; offset=info->raw[offset+1]) {
topLocalAfter=create(after, getNameById(capNames,info->raw[offset]),value.sprintf("0x%02X",info->raw[offset]));
localAfter=create(topLocalAfter, i18n("Next"),(info->raw[offset+1]==0?i18n("0x00 (None)"):value.sprintf("0x%02X",info->raw[offset+1])));
switch (info->raw[offset]) {
case 0x01: //Power Managemet
addCapsPm(topLocalAfter, localAfter, info, offset);
break;
case 0x02: //AGP
addCapsAgp(topLocalAfter, localAfter, info, offset);
break;
case 0x03: //VPD
addCapsVpd(topLocalAfter, localAfter, info, offset);
break;
case 0x05: //MSI
addCapsMsi(topLocalAfter, localAfter, info, offset);
break;
case 0x09: //vendor specific
addCapsVendor(topLocalAfter, localAfter, info, offset);
break;
default:
break;
}//switch
}//for
}//if
else {
topLocalAfter=createTitle(after, i18n("Root only"));
}//else
}//if
else {
after=create(parent, i18n("Capabilities"),i18n("0x00 (None)"));
}//else
}//if
return after;
}//addCaps
bool GetInfo_PCIUtils(QTreeWidget* tree) {
QStringList headers;
headers << i18n("Information") << i18n("Value");
tree->setHeaderLabels(headers);
tree->setRootIsDecorated(true);
pci_access *PCIAccess=NULL;
pci_dev *PCIDevice=NULL;
//init libpci
PCIAccess=pci_alloc();
if (PCIAccess==NULL) {
return false;
}//if
pci_init(PCIAccess);
pci_scan_bus(PCIAccess);
QTreeWidgetItem *DeviceName=NULL, *after=NULL;
QString value;
pciInfo info;
//proces all devices
for (PCIDevice=PCIAccess->devices; PCIDevice; PCIDevice=PCIDevice->next) {
//get PCI data
pci_fill_info(PCIDevice, PCI_FILL_IDENT|PCI_FILL_IRQ|PCI_FILL_BASES|PCI_FILL_ROM_BASE|PCI_FILL_SIZES);
if (getuid()==0) {
pci_read_block(PCIDevice, 0, info.raw, 256);
}//if
else {
pci_read_block(PCIDevice, 0, info.raw, 64);
}//else
QStringList deviceList;
deviceList << value.sprintf("%02X:%02X.%d", PCIDevice->bus, PCIDevice->dev, PCIDevice->func);
//create device tree
DeviceName=new QTreeWidgetItem(tree, deviceList);
//adding class, subclass and programing intrface info
after=addDeviceClass(DeviceName, NULL, &info);
//adding revision
after=create(DeviceName, i18n("Revision"), value.sprintf("0x%02X", info.revision));
//adding vendor, device, and subvendor/sudevice info
after=addVendor(DeviceName, after, &info, PCIAccess);
//adding control
after=addControl(DeviceName, after, &info);
//adding status
after=addStatus(DeviceName, after, &info);
//adding cache line size
after=create(DeviceName, i18n("Cache line size"), value.sprintf("0x%02X", info.cacheLineSize));
//adding latency
after=addLatency(DeviceName, after, &info);
//adding header type
after=addHeaderType(DeviceName, after, &info);
//adding BIST
after=addBist(DeviceName, after, &info);
//adding address mapping
after=addMapping(DeviceName, after, &info, PCIDevice);
//adding bus info
after=addBus(DeviceName, after, &info);
//adding secondary status
after=addSecStatus(DeviceName, after, &info);
//adding resourece behind bridge
after=addBridgeBehind(DeviceName, after, &info);
//adding bridge control
after=addBridgeControl(DeviceName, after, &info);
//adding cardbus resource
after=addCardbusResource(DeviceName, after, &info);
//adding cardbus control
after=addCardbusControl(DeviceName, after, &info);
//adding ROM
after=addRom(DeviceName, after, &info, PCIDevice);
//adding capabilites
after=addCaps(DeviceName, after, &info);
//adding interrupt info (IRQ, pin)
after=addInterrupt(DeviceName, after, PCIDevice->irq, info.interruptPin); //PCI data have wrong IRQ ?!?
//add raw PCI config data
after=addRaw(DeviceName, after, &info);
}//for
pci_cleanup(PCIAccess);
return true;
} //GetInfo_PCIUtils

14
kinfocenter/pci/pci.h Normal file
View file

@ -0,0 +1,14 @@
/* Retrieve information about PCI subsystem trough libpci library from
pciutils package. This should be possible on Linux, BSD and AIX.
Author: Konrad Rzepecki <hannibal@megapolis.pl>
*/
#ifndef _PCI_H_
#define _PCI_H_
#include <QTreeWidget>
bool GetInfo_PCIUtils(QTreeWidget* tree);
#endif //_PCI_H_

View file

@ -0,0 +1,783 @@
/* Retrive information about PCI subsystem trough libpci library from
pciutils package. This should be possible on Linux, BSD and AIX.
Device classes, subclasses and programing interfaces are hardcoded
here, since there are only few of them, and they are important and
should their names be translated.
pci.cpp private header, don't include in other files.
Author: Konrad Rzepecki <hannibal@megapolis.pl>
*/
#ifndef _PCI_PRIVATE_H_
#define _PCI_PRIVATE_H_
#include "pci.h"
#include <QString>
#include <klocale.h>
//pci lookup buffer size
#define NAME_BUFFER_SIZE 256
//common used strings
static const char* strEnabled=I18N_NOOP("Enabled");
static const char* strDisabled=I18N_NOOP("Disabled");
static const char* strYes=I18N_NOOP("Yes");
static const char* strNo=I18N_NOOP("No");
static const char* strUnknown=I18N_NOOP("Unknown");
struct id2name {
int id;
QString name;
};
struct id3name {
int id,id2;
QString name;
};
struct id4name {
int id,id2,id3;
QString name;
};
union pciInfo{
unsigned char raw[256];
struct {
unsigned short vendor;
unsigned short device;
union {
unsigned short command;
struct {
unsigned comIo:1;
unsigned comMemory:1;
unsigned comMaster:1;
unsigned comSpecial:1;
unsigned comInvalidate:1;
unsigned comVgaPalette:1;
unsigned comParity:1;
unsigned comWait:1;
unsigned comSerr:1;
unsigned comFastBack:1;
unsigned comInterrupt:1;
unsigned comUnk:5;
} KDE_PACKED;
} KDE_PACKED;
union {
unsigned short status;
struct {
unsigned statUnk:3;
unsigned statInterrupt:1;
unsigned statCapList:1;
unsigned stat66MHz:1;
unsigned statUdf:1;
unsigned statFastBack:1;
unsigned statParity:1;
unsigned statDevsel:2;
unsigned statSigTargetAbort:1;
unsigned statRecTargetAbort:1;
unsigned statRecMasterAbort:1;
unsigned statSigSystemError:1;
unsigned statDetectedParity:1;
} KDE_PACKED;
} KDE_PACKED;
unsigned char revision;
union {
unsigned char devProgIface;
struct {
unsigned progPriOperMode:1;
unsigned progPriProgInd:1;
unsigned progSecOperMode:1;
unsigned progSecProgInd:1;
unsigned progUnk:3;
unsigned progIdeMaster:1;
} KDE_PACKED;
} KDE_PACKED;
unsigned char devSubClass;
unsigned char devClass;
unsigned char cacheLineSize;
unsigned char latencyTimer;
union {
unsigned char headerTypeFull:1;
struct {
unsigned headerType:7;
unsigned multifunctional:1;
} KDE_PACKED;
} KDE_PACKED;
union {
unsigned char bist;
struct {
unsigned bistCode:4;
unsigned bistUnk:2;
unsigned bistStart:1;
unsigned bistCapable:1;
} KDE_PACKED;
} KDE_PACKED;
union {
struct { //header0
union {
unsigned baseAddress;
struct {
unsigned baseAddressMap:1;
unsigned baseAddressType:2;
unsigned baseAddressPref:1;
unsigned baseAddressAddr:28;
} KDE_PACKED;
} KDE_PACKED mapping[6];
unsigned cardbusCis;
unsigned short subVendor;
unsigned short subDevice;
union {
unsigned romAddress;
struct {
unsigned romEnabled:1;
unsigned romUnk:10;
unsigned romAddr:21;
} KDE_PACKED;
} KDE_PACKED;
unsigned char capabilityList;
unsigned char reserved1[7];
unsigned char interruptLine;
unsigned char interruptPin;
unsigned char minGnt;
unsigned char maxLat;
} KDE_PACKED;
struct{ //header1
unsigned baseAddress0_2;
unsigned baseAddress1_2;
unsigned char primaryBus;
unsigned char secondaryBus;
unsigned char subordinateBus;
unsigned char secLatencyTimer;
union {
unsigned char ioBase;
struct {
unsigned ioBaseType:1;
unsigned ioBaseUnk:3;
unsigned ioBaseAddr:4;
} KDE_PACKED;
} KDE_PACKED;
unsigned char ioLimit;
union {
unsigned short secStatus;
struct {
unsigned secStatUnk:3;
unsigned secStatInterrupt:1;
unsigned secStatCapList:1;
unsigned secStat66MHz:1;
unsigned secStatUdf:1;
unsigned secStatFastBack:1;
unsigned secStatParity:1;
unsigned secStatDevsel:2;
unsigned secStatSigTargetAbort:1;
unsigned secStatRecTargetAbort:1;
unsigned secStatRecMasterAbort:1;
unsigned secStatSigSystemError:1;
unsigned secStatDetectedParity:1;
} KDE_PACKED;
} KDE_PACKED;
union {
unsigned short memoryBase;
struct {
unsigned memoryType:1;
unsigned memoryUnk:3;
unsigned memoryAddr:4;
} KDE_PACKED;
} KDE_PACKED;
unsigned short memoryLimit;
union {
unsigned short prefMemoryBase;
struct {
unsigned prefMemoryType:1;
unsigned prefMemoryUnk:3;
unsigned prefMemoryAddr:4;
} KDE_PACKED;
} KDE_PACKED;
unsigned short prefMemoryLimit;
unsigned prefBaseUpper32;
unsigned prefLimitUpper32;
unsigned short ioBaseUpper16;
unsigned short ioLimitUpper16;
unsigned char capabilityList_2;
unsigned char reserved2[3];
unsigned romAddress1;
unsigned char interruptLine_2;
unsigned char interruptPin_2;
union {
unsigned short bridgeControl;
struct {
unsigned bridgeControlParity:1;
unsigned bridgeControlSerr:1;
unsigned bridgeControlIsa:1;
unsigned bridgeControlVga:1;
unsigned bridgeControlUnk:1;
unsigned bridgeControlMasterAbort:1;
unsigned bridgeControlBusReset:1;
unsigned bridgeControlFastBack:1;
unsigned bridgeControlPriDisTim:1;
unsigned bridgeControlSecDisTim:1;
unsigned bridgeControlDisTimStat:1;
unsigned bridgeControlDisTimeSerr:1;
unsigned bridgeControlUnk2:4;
} KDE_PACKED;
} KDE_PACKED;
} KDE_PACKED;
struct{ //header2
unsigned baseAddress0_3;
union {
unsigned short cbSecStatus;
struct {
unsigned cbSecStatUnk:3;
unsigned cbSecStatInterrupt:1;
unsigned cbSecStatCapList:1;
unsigned cbSecStat66MHz:1;
unsigned cbSecStatUdf:1;
unsigned cbSecStatFastBack:1;
unsigned cbSecStatParity:1;
unsigned cbSecStatDevsel:2;
unsigned cbSecStatSigTargetAbort:1;
unsigned cbSecStatRecTargetAbort:1;
unsigned cbSecStatRecMasterAbort:1;
unsigned cbSecStatSigSystemError:1;
unsigned cbSecStatDetectedParity:1;
} KDE_PACKED;
} KDE_PACKED;
unsigned char cbPrimaryBus;
unsigned char cbCardBus;
unsigned char cbSubordinateBus;
unsigned char cbLatencyTimer;
struct {
unsigned cbMemoryBase;
unsigned cbMemoryLimit;
} KDE_PACKED cbMemory[2];
struct {
union {
unsigned cbIoBase;
struct {
unsigned cbIoBaseType:1;
unsigned coIoBaseUnk:1;
unsigned cbIoBaseAddr:30;
} KDE_PACKED;
} KDE_PACKED;
unsigned cbIoLimit;
} KDE_PACKED cbIo[2];
unsigned char interruptLine_3;
unsigned char interruptPin_3;
union {
unsigned short cbControl;
struct {
unsigned cbControlParity:1;
unsigned cbControlSerr:1;
unsigned cbControlIsa:1;
unsigned cbControlVga:1;
unsigned cbControlUnk:1;
unsigned cbControlMasterAbort:1;
unsigned cbControlBusReset:1;
unsigned cbControl16Int:1;
unsigned cbControlPref0:1;
unsigned cbControlPref1:1;
unsigned cbControlPostWrites:1;
unsigned cbControlUnk2:5;
} KDE_PACKED;
} KDE_PACKED;
unsigned short cbSubVendor;
unsigned short cbSubDevice;
unsigned short cbLegacyModeBase;
} KDE_PACKED;
} KDE_PACKED;
} KDE_PACKED;
} KDE_PACKED;
union agpInfo{
unsigned char raw[10];
struct {
struct {
unsigned revMinor:4;
unsigned revMaior:4;
unsigned char unk;
} KDE_PACKED;
union {
unsigned status;
struct {
unsigned statusEnhRate:4;
unsigned statusUnk:28;
} KDE_PACKED;
struct {
unsigned statusRate:3;
unsigned statusMode:1;
unsigned statusFastWrite:1;
unsigned statusOver4gb:1;
unsigned statusHtrans:1;
unsigned statusGart64b:1;
unsigned statusItaCoh:1;
unsigned statusSba:1;
unsigned statusCalCycle:3;
unsigned statusOptReqSize:3;
unsigned statusUnk1:1;
unsigned statusIsochSupp:1;
unsigned statusUnk2:6;
unsigned statusReq:8;
} KDE_PACKED;
} KDE_PACKED;
union {
unsigned config;
struct {
unsigned configEnhRate:4;
unsigned configUnk:28;
} KDE_PACKED;
struct {
unsigned configRate:3;
unsigned configUnk1:1;
unsigned configFastWrite:1;
unsigned configOver4gb:1;
unsigned configUnk2:1;
unsigned configGart64b:1;
unsigned configAgp:1;
unsigned configSba:1;
unsigned configCalCycle:3;
unsigned configOptReqSize:3;
unsigned configUnk3:8;
unsigned configReq:8;
} KDE_PACKED;
} KDE_PACKED;
} KDE_PACKED;
} KDE_PACKED;
union pmInfo {
unsigned char raw[6];
struct {
union {
unsigned short caps;
struct {
unsigned capsVer:3;
unsigned capsClock:1;
unsigned capsUnk:1;
unsigned capsDsi:1;
unsigned capsAuxCur:3;
unsigned capsD1Supp:1;
unsigned capsD2Supp:1;
unsigned capsPmeD0:1;
unsigned capsPmeD1:1;
unsigned capsPmeD2:1;
unsigned capsPmeD3hot:1;
unsigned capsPmeD3cold:1;
} KDE_PACKED;
} KDE_PACKED;
union {
unsigned short status;
struct {
unsigned statPower:2;
unsigned statUnk:6;
unsigned statPme:1;
unsigned statDataSelect:4;
unsigned statDataScale:2;
unsigned statPmeStat:1;
} KDE_PACKED;
} KDE_PACKED;
union {
unsigned char statusBridge;
struct {
unsigned statBridgeUnk:6;
unsigned statBridgeBx:1;
unsigned statBridgeClock:1;
} KDE_PACKED;
} KDE_PACKED;
unsigned char data;
} KDE_PACKED;
} KDE_PACKED;
union vpdInfo {
unsigned char raw[6];
struct {
unsigned vpdAddress:15;
unsigned vpdTransfer:1;
unsigned vpdData;
} KDE_PACKED;
} KDE_PACKED;
union msiInfo {
unsigned char raw[22];
struct {
union {
unsigned short msiControl;
struct {
unsigned msiEnable:1;
unsigned msiMmCapable:3;
unsigned msiMmEnable:3;
unsigned msi64bit:1;
unsigned msiPerVector:1;
unsigned msiUnk0:7;
} KDE_PACKED;
} KDE_PACKED;
unsigned msiAddress;
union {
struct {
unsigned msiUpperAddress;
unsigned short msiData64;
unsigned short msiUnk64;
unsigned msiMask64;
unsigned msiPending64;
} KDE_PACKED;
struct {
unsigned short msiData;
unsigned short msiUnk;
unsigned msiMask;
unsigned msiPending;
} KDE_PACKED;
} KDE_PACKED;
} KDE_PACKED;
} KDE_PACKED;
//In following arrays -1 mean default value
//keep -1 in last position
//device classes list
static const id2name devClass[]={{ 0x00, i18n("Unclassified device")},
{ 0x01, i18n("Mass storage controller")},
{ 0x02, i18n("Network controller")},
{ 0x03, i18n("Display controller")},
{ 0x04, i18n("Multimedia controller")},
{ 0x05, i18n("Memory controller")},
{ 0x06, i18n("Bridge")},
{ 0x07, i18n("Communication controller")},
{ 0x08, i18n("Generic system peripheral")},
{ 0x09, i18n("Input device controller")},
{ 0x0A, i18n("Docking station")},
{ 0x0B, i18n("Processor")},
{ 0x0C, i18n("Serial bus controller")},
{ 0x0D, i18n("Wireless controller")},
{ 0x0E, i18n("Intelligent controller")},
{ 0x0F, i18n("Satellite communications controller")},
{ 0x10, i18n("Encryption controller")},
{ 0x11, i18n("Signal processing controller")},
{ -1, i18n("Unknown device class")}
};
//keep -1 in last position in "id"
//and in last position in "id2" with certain "id"
//subdevice classes list
static const id3name devSubclass[]={ { 0x00, 0x00, i18n("Non-VGA unclassified device")},
{ 0x00, 0x01, i18n("VGA unclassified device")},
{ 0x00, -1, i18n("Unknown unclassified device")},
{ 0x01, 0x00, i18n("SCSI storage controller")},
{ 0x01, 0x01, i18n("IDE controller")},
{ 0x01, 0x02, i18n("Floppy disk controller")},
{ 0x01, 0x03, i18n("IPI bus controller")},
{ 0x01, 0x04, i18n("RAID bus controller")},
{ 0x01, 0x05, i18n("ATA controller")},
{ 0x01, 0x06, i18n("Serial ATA direct port access")},
{ 0x01, 0x80, i18n("Mass storage controller")},
{ 0x01, -1, i18n("Unknown storage controller")},
{ 0x02, 0x00, i18n("Ethernet controller")},
{ 0x02, 0x01, i18n("Token ring network controller")},
{ 0x02, 0x02, i18n("FDDI network controller")},
{ 0x02, 0x03, i18n("ATM network controller")},
{ 0x02, 0x04, i18n("ISDN controller")},
{ 0x02, 0x05, i18n("WorldFip controller")},
{ 0x02, 0x06, i18n("PICMG 2.14 multi computing")},
{ 0x02, 0x80, i18n("Network controller")},
{ 0x02, -1, i18n("Unknown network controller")},
{ 0x03, 0x00, i18n("VGA compatible controller")},
{ 0x03, 0x01, i18n("XGA compatible controller")},
{ 0x03, 0x02, i18n("3D controller")},
{ 0x03, 0x80, i18n("Display controller")},
{ 0x03, -1, i18n("Unknown display controller")},
{ 0x04, 0x00, i18n("Multimedia video controller")},
{ 0x04, 0x01, i18n("Multimedia audio controller")},
{ 0x04, 0x02, i18n("Computer telephony device")},
{ 0x04, 0x80, i18n("Multimedia controller")},
{ 0x04, -1, i18n("Unknown multimedia controller")},
{ 0x05, 0x00, i18n("RAM memory")},
{ 0x05, 0x01, i18n("FLASH memory")},
{ 0x05, 0x80, i18n("Memory controller")},
{ 0x05, -1, i18n("Unknown memory controller")},
{ 0x06, 0x00, i18n("Host bridge")},
{ 0x06, 0x01, i18n("ISA bridge")},
{ 0x06, 0x02, i18n("EISA bridge")},
{ 0x06, 0x03, i18n("MicroChannel bridge")},
{ 0x06, 0x04, i18n("PCI bridge")},
{ 0x06, 0x05, i18n("PCMCIA bridge")},
{ 0x06, 0x06, i18n("NuBus bridge")},
{ 0x06, 0x07, i18n("CardBus bridge")},
{ 0x06, 0x08, i18n("RACEway bridge")},
{ 0x06, 0x09, i18n("Semi-transparent PCI-to-PCI bridge")},
{ 0x06, 0x0A, i18n("InfiniBand to PCI host bridge")},
{ 0x06, 0x80, i18n("Bridge")},
{ 0x06, -1, i18n("Unknown bridge")},
{ 0x07, 0x00, i18n("Serial controller")},
{ 0x07, 0x01, i18n("Parallel controller")},
{ 0x07, 0x02, i18n("Multiport serial controller")},
{ 0x07, 0x03, i18n("Modem")},
{ 0x07, 0x04, i18n("GPIB (IEEE 488.1/2) controller")},
{ 0x07, 0x05, i18n("Smart card")},
{ 0x07, 0x80, i18n("Communication controller")},
{ 0x07, -1, i18n("Unknown communication controller")},
{ 0x08, 0x00, i18n("PIC")},
{ 0x08, 0x01, i18n("DMA controller")},
{ 0x08, 0x02, i18n("Timer")},
{ 0x08, 0x03, i18n("RTC")},
{ 0x08, 0x04, i18n("PCI Hot-plug controller")},
{ 0x08, 0x80, i18n("System peripheral")},
{ 0x08, -1, i18n("Unknown system peripheral")},
{ 0x09, 0x00, i18n("Keyboard controller")},
{ 0x09, 0x01, i18n("Digitizer Pen")},
{ 0x09, 0x02, i18n("Mouse controller")},
{ 0x09, 0x03, i18n("Scanner controller")},
{ 0x09, 0x04, i18n("Gameport controller")},
{ 0x09, 0x80, i18n("Input device controller")},
{ 0x09, -1, i18n("Unknown input device controller")},
{ 0x0A, 0x00, i18n("Generic docking station")},
{ 0x0A, 0x80, i18n("Docking station")},
{ 0x0A, -1, i18n("Unknown docking station")},
{ 0x0B, 0x00, i18n("386")},
{ 0x0B, 0x01, i18n("486")},
{ 0x0B, 0x02, i18n("Pentium")},
{ 0x0B, 0x10, i18n("Alpha")},
{ 0x0B, 0x20, i18n("Power PC")},
{ 0x0B, 0x30, i18n("MIPS")},
{ 0x0B, 0x40, i18n("Co-processor")},
{ 0x0B, -1, i18n("Unknown processor")},
{ 0x0C, 0x00, i18n("FireWire (IEEE 1394)")},
{ 0x0C, 0x01, i18n("ACCESS bus")},
{ 0x0C, 0x02, i18n("SSA")},
{ 0x0C, 0x03, i18n("USB controller")},
{ 0x0C, 0x04, i18n("Fibre channel")},
{ 0x0C, 0x05, i18n("SMBus")},
{ 0x0C, 0x06, i18n("InfiniBand")},
{ 0x0C, 0x07, i18n("IPMI interface")},
{ 0x0C, 0x08, i18n("SERCOS interface")},
{ 0x0C, 0x09, i18n("CANbus")},
{ 0x0C, -1, i18n("Unknown serial bus controller")},
{ 0x0D, 0x00, i18n("IRDA controller")},
{ 0x0D, 0x01, i18n("Consumer IR controller")},
{ 0x0D, 0x10, i18n("RF controller")},
{ 0x0D, 0x11, i18n("Bluetooth")},
{ 0x0D, 0x12, i18n("Broadband")},
{ 0x0D, 0x20, i18n("Ethernet (802.11a - 5 GHz)")},
{ 0x0D, 0x21, i18n("Ethernet (802.11b - 2.4 GHz)")},
{ 0x0D, 0x80, i18n("Wireless controller")},
{ 0x0D, -1, i18n("Unknown wireless controller")},
{ 0x0E, 0x00, i18n("I2O")},
{ 0x0E, -1, i18n("Unknown intelligent controller")},
{ 0x0F, 0x01, i18n("Satellite TV controller")},
{ 0x0F, 0x02, i18n("Satellite audio communication controller")},
{ 0x0F, 0x03, i18n("Satellite voice communication controller")},
{ 0x0F, 0x04, i18n("Satellite data communication controller")},
{ 0x0F, -1, i18n("Unknown satellite communications controller")},
{ 0x10, 0x00, i18n("Network and computing encryption device")},
{ 0x10, 0x10, i18n("Entertainment encryption device")},
{ 0x10, 0x80, i18n("Encryption controller")},
{ 0x10, -1, i18n("Unknown encryption controller")},
{ 0x11, 0x00, i18n("DPIO module")},
{ 0x11, 0x01, i18n("Performance counters")},
{ 0x11, 0x10, i18n("Communication synchronizer")},
{ 0x11, 0x20, i18n("Management card")},
{ 0x11, 0x80, i18n("Signal processing controller")},
{ 0x11, -1, i18n("Unknown signal processing controller")},
{ -1, -1, i18n("Unknown subdevice class")}
};
//keep -1 in last position in "id",
//in last position in "id2" with certain "id",
//and in last position in "id3" with certain "id2"
//device programming interface list
static const id4name devInterface[]={ { 0x01, 0x05, 0x20, i18n("single DMA")},
{ 0x01, 0x05, 0x30, i18n("chained DMA")},
{ 0x03, 0x00, 0x00, i18n("VGA compatible")},
{ 0x03, 0x00, 0x01, i18n("8514 compatible")},
{ 0x06, 0x04, 0x00, i18n("Normal decode")},
{ 0x06, 0x04, 0x01, i18n("Subtractive decode")},
{ 0x06, 0x08, 0x00, i18n("Transparent mode")},
{ 0x06, 0x08, 0x01, i18n("Endpoint mode")},
{ 0x06, 0x09, 0x40, i18n("Primary bus towards host CPU")},
{ 0x06, 0x09, 0x40, i18n("Secondary bus towards host CPU")},
{ 0x07, 0x00, 0x00, i18n("8250")},
{ 0x07, 0x00, 0x01, i18n("16450")},
{ 0x07, 0x00, 0x02, i18n("16550")},
{ 0x07, 0x00, 0x03, i18n("16650")},
{ 0x07, 0x00, 0x04, i18n("16750")},
{ 0x07, 0x00, 0x05, i18n("16850")},
{ 0x07, 0x00, 0x06, i18n("16950")},
{ 0x07, 0x01, 0x00, i18n("SPP")},
{ 0x07, 0x01, 0x01, i18n("BiDir")},
{ 0x07, 0x01, 0x02, i18n("ECP")},
{ 0x07, 0x01, 0x03, i18n("IEEE1284")},
{ 0x07, 0x01, 0xFE, i18n("IEEE1284 Target")},
{ 0x07, 0x03, 0x00, i18n("Generic")},
{ 0x07, 0x03, 0x01, i18n("Hayes/16450")},
{ 0x07, 0x03, 0x02, i18n("Hayes/16550")},
{ 0x07, 0x03, 0x03, i18n("Hayes/16650")},
{ 0x07, 0x03, 0x04, i18n("Hayes/16750")},
{ 0x08, 0x00, 0x00, i18n("8259")},
{ 0x08, 0x00, 0x01, i18n("ISA PIC")},
{ 0x08, 0x00, 0x02, i18n("EISA PIC")},
{ 0x08, 0x00, 0x03, i18n("IO-APIC")},
{ 0x08, 0x00, 0x04, i18n("IO(X)-APIC")},
{ 0x08, 0x01, 0x00, i18n("8237")},
{ 0x08, 0x01, 0x01, i18n("ISA DMA")},
{ 0x08, 0x01, 0x01, i18n("EISA DMA")},
{ 0x08, 0x02, 0x00, i18n("8254")},
{ 0x08, 0x02, 0x01, i18n("ISA timer")},
{ 0x08, 0x02, 0x01, i18n("EISA timers")},
{ 0x08, 0x03, 0x00, i18n("Generic")},
{ 0x08, 0x03, 0x01, i18n("ISA RTC")},
{ 0x09, 0x04, 0x00, i18n("Generic")},
{ 0x09, 0x04, 0x01, i18n("Extended")},
{ 0x0C, 0x00, 0x00, i18n("Generic")},
{ 0x0C, 0x00, 0x01, i18n("OHCI")},
{ 0x0C, 0x03, 0x00, i18n("UHCI")},
{ 0x0C, 0x03, 0x10, i18n("OHCI")},
{ 0x0C, 0x03, 0x20, i18n("EHCI")},
{ 0x0C, 0x03, 0x80, i18n("Unspecified")},
{ 0x0C, 0x03, 0xFE, i18n("USB Device")},
{ 0x0C, 0x07, 0x00, i18n("SMIC")},
{ 0x0C, 0x07, 0x01, i18n("Keyboard controller style")},
{ 0x0C, 0x07, 0x02, i18n("Block transfer")},
{ -1, -1, -1, i18n(strUnknown)}
};
//keep -1 in last position
//capabilities list
static const id2name capNames[]={{ 0x01, i18n("Power management")},
{ 0x02, i18n("AGP")},
{ 0x03, i18n("Vital product data")},
{ 0x04, i18n("Slot identification")},
{ 0x05, i18n("Message signaled interrupts")},
{ 0x06, i18n("CompactPCI hot swap")},
{ 0x07, i18n("PCI-X")},
{ 0x08, i18n("HyperTransport")},
{ 0x09, i18n("Vendor specific")},
{ 0x0A, i18n("Debug port")},
{ 0x0B, i18n("CompactPCI central resource control")},
{ 0x0C, i18n("PCI hot-plug")},
{ 0x0E, i18n("AGP x8")},
{ 0x0F, i18n("Secure device")},
{ 0x10, i18n("PCI express")},
{ 0x11, i18n("MSI-X")},
{ -1, i18n(strUnknown)}
};
//keep -1 in last position
//device selection timing
static const id2name devSel[]={ { 0x00, i18n("Fast")},
{ 0x01, i18n("Medium")},
{ 0x02, i18n("Slow")},
{ -1, i18n(strUnknown)}
};
//keep -1 in last position
//mapping type
static const id2name mappingType[]={{ 0x00, i18n("32 bit")},
{ 0x01, i18n("Below 1M")},
{ 0x02, i18n("64 bit")},
{ -1, i18n(strUnknown)}
};
//keep -1 in last position
//header type
static const id2name headerType[]={ { 0x00, i18n("Standard")},
{ 0x01, i18n("Bridge")},
{ 0x02, i18n("CardBus")},
{ -1, i18n(strUnknown)}
};
//keep -1 in last position
//AGP rate
static const id2name agpRate[]={{ 0x01, i18n("1X")},
{ 0x02, i18n("2X")},
{ 0x03, i18n("1X & 2X")},
{ 0x04, i18n("4X")},
{ 0x05, i18n("1X & 4X")},
{ 0x06, i18n("2X & 4X")},
{ 0x07, i18n("1X & 2X & 4X")},
{ 0x09, i18n("4X")},
{ 0x0A, i18n("8X")},
{ 0x0B, i18n("4X & 8X")},
{ -1, i18n(strUnknown)}
};
//keep -1 in last position
//AGP calibrating cycle
static const id2name calCycle[]={ { 0x00, i18n("4 ms")},
{ 0x01, i18n("16 ms")},
{ 0x02, i18n("64 ms")},
{ 0x03, i18n("256 ms")},
{ 0x07, i18n("Not needed")},
{ -1, i18n(strUnknown)}
};
//keep -1 in last position
//PM auxiliary current
static const id2name auxCur[]={ { 0x00, i18n("0 (self powered)")},
{ 0x01, i18n("55 mA")},
{ 0x02, i18n("100 mA")},
{ 0x03, i18n("160 mA")},
{ 0x04, i18n("220 mA")},
{ 0x05, i18n("270 mA")},
{ 0x06, i18n("320 mA")},
{ 0x07, i18n("375 mA")},
{ -1, i18n(strUnknown)}
};
//keep -1 in last position
//PM power state
static const id2name powerState[]={ { 0x00, i18n("D0")},
{ 0x01, i18n("D1")},
{ 0x02, i18n("D2")},
{ 0x03, i18n("D3 hot")},
{ -1, i18n(strUnknown)}
};
//keep -1 in last position
//MSI multiple message
static const id2name multipleMessage[]={{ 0x00, i18n("1 vector")},
{ 0x01, i18n("2 vectors")},
{ 0x02, i18n("4 vectors")},
{ 0x03, i18n("8 vectors")},
{ 0x04, i18n("16 vectors")},
{ 0x05, i18n("32 vectors")},
{ -1, i18n(strUnknown)}
};
static const QString& getNameById(const id2name *const table,int id);
static const QString& getNameBy2Id(const id3name *const table,int id,int id2);
static const QString& getNameBy3Id(const id4name *const table,int id,int id2, int id3);
#endif //_PCI_PRIVATE_H_

View file

@ -1,36 +1,33 @@
/*
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "proxywidget.h"
#include "global.h"
#include "kinfocenter_interface.h"
#include <kpushbutton.h>
#include <QByteArray>
#include <QFrame>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QResizeEvent>
#include <Q3ScrollView>
#include <QScrollArea>
#include <QLabel>
#include <QtDBus/QtDBus>
#include <Q3WhatsThis>
#include <kpushbutton.h>
#include <klocale.h>
#include <kapplication.h>
#include <kcmodule.h>
@ -40,282 +37,38 @@
#include <kdebug.h>
#include <unistd.h> // for getuid()
#include "proxywidget.moc"
class WhatsThis : public Q3WhatsThis
{
public:
WhatsThis( ProxyWidget* parent )
: Q3WhatsThis( parent ), proxy( parent ) {}
~WhatsThis(){}
ProxyWidget::ProxyWidget(KCModule *client) :
QWidget(), _changed(false), _client(client) {
QString text( const QPoint & ) {
if ( !proxy->quickHelp().isEmpty() )
return proxy->quickHelp();
else
return i18n("The currently loaded configuration module.");
}
kDebug() << "Creating Proxy Widget..." << endl;
private:
ProxyWidget* proxy;
};
if (_client->quickHelp().isEmpty() == false )
setWhatsThis(_client->quickHelp());
else
setWhatsThis(i18n("The currently loaded configuration module."));
////////////////////////////////////////////////////////////////////////////////////////////////////////
QVBoxLayout *top = new QVBoxLayout(this);
top->setMargin(0);
top->setSpacing(0);
top->addWidget(_client);
class RootInfoWidget : public QLabel
{
public:
RootInfoWidget(QWidget *parent, const char *name);
void setRootMessage(const QString& s) { setText(s); }
};
RootInfoWidget::RootInfoWidget(QWidget *parent, const char *name = 0)
: QLabel(parent)
{
setObjectName( name );
setFrameShape(QFrame::Box);
setFrameShadow(QFrame::Raised);
setText(i18n("<b>Changes in this module require root access.</b><br />"
"Click the \"Administrator Mode\" button to "
"allow modifications in this module."));
this->setWhatsThis( i18n("This module requires special permissions, probably "
"for system-wide modifications; therefore, it is "
"required that you provide the root password to be "
"able to change the module's properties. If you "
"do not provide the password, the module will be "
"disabled."));
kDebug() << "Proxy Widget created" << endl;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
class ProxyView : public Q3ScrollView
{
public:
ProxyView(KCModule *client, const QString& title, QWidget *parent, bool run_as_root, const char *name);
private:
virtual void resizeEvent(QResizeEvent *);
QWidget *contentWidget;
KCModule *client;
bool scroll;
};
class ProxyContentWidget : public QWidget
{
public:
ProxyContentWidget( QWidget* parent ) : QWidget( parent ) {}
~ProxyContentWidget(){}
// this should be really done by qscrollview in AutoOneFit mode!
QSize sizeHint() const { return minimumSizeHint(); }
};
ProxyView::ProxyView(KCModule *_client, const QString&, QWidget *parent, bool run_as_root, const char *name)
: Q3ScrollView(parent, name), client(_client)
{
setResizePolicy(Q3ScrollView::AutoOneFit);
setFrameStyle( NoFrame );
contentWidget = new ProxyContentWidget( viewport() );
QVBoxLayout* vbox = new QVBoxLayout( contentWidget );
vbox->setMargin(0);
if (run_as_root && _client->useRootOnlyMessage()) // notify the user
{
RootInfoWidget *infoBox = new RootInfoWidget(contentWidget);
vbox->addWidget( infoBox );
QString msg = _client->rootOnlyMessage();
if (!msg.isEmpty())
infoBox->setRootMessage(msg);
vbox->setSpacing(KDialog::spacingHint());
}
client->setParent(contentWidget);
client->move(0,0);
client->show();
vbox->addWidget( client );
vbox->activate(); // make sure we have a proper minimumSizeHint
addChild(contentWidget);
ProxyWidget::~ProxyWidget() {
delete _client;
}
void ProxyView::resizeEvent(QResizeEvent *e)
{
Q3ScrollView::resizeEvent(e);
QString ProxyWidget::quickHelp() const {
if (_client)
return _client->quickHelp();
else
return "";
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
ProxyWidget::ProxyWidget(KCModule *client, const QString &title,
bool run_as_root)
: QWidget(0)
, _client(client)
{
setWindowTitle(title);
#ifdef __GNUC__
#warning "kde4: DBUS port"
#endif
#if 0
if (getuid()==0 ) {
// Make root modules look as similar as possible...
DCOPCString replyType;
QByteArray replyData;
if (kapp->dcopClient()->call("kcontrol", "moduleIface", "getPalette()", QByteArray(),
replyType, replyData))
if ( replyType == "QPalette") {
QDataStream reply( replyData );
QPalette pal;
reply >> pal;
setPalette(pal);
}
/* // Doesn't work ...
if (kapp->dcopClient()->call("kcontrol", "moduleIface", "getStyle()", QByteArray(),
replyType, replyData))
if ( replyType == "QString") {
QDataStream reply( replyData, QIODevice::ReadOnly );
QString style;
reply >> style;
setStyle(style);
}
*/
if (kapp->dcopClient()->call("kcontrol", "moduleIface", "getFont()", QByteArray(),
replyType, replyData))
if ( replyType == "QFont") {
QDataStream reply( replyData );
QFont font;
reply >> font;
setFont(font);
}
}
#endif
view = new ProxyView(client, title, this, run_as_root, "proxyview");
(void) new WhatsThis( this );
connect(_client, SIGNAL(changed(bool)), SLOT(clientChanged(bool)));
connect(_client, SIGNAL(quickHelpChanged()), SIGNAL(quickHelpChanged()));
_sep = new KSeparator(Qt::Horizontal, this);
_help = new KPushButton( KStandardGuiItem::help(), this );
_default = new KPushButton( KStandardGuiItem::defaults(), this );
_apply = new KPushButton( KStandardGuiItem::apply(), this );
_reset = new KPushButton( KStandardGuiItem::reset(), this );
_root = new KPushButton( KGuiItem(i18n( "&Administrator Mode" )), this );
bool mayModify = (!run_as_root || !_client->useRootOnlyMessage()) && !KCGlobal::isInfoCenter();
// only enable the requested buttons
int b = _client->buttons();
_help->setVisible(false & (b & KCModule::Help));
_default->setVisible(mayModify && (b & KCModule::Default));
_apply->setVisible(mayModify && (b & KCModule::Apply));
_reset->setVisible(mayModify && (b & KCModule::Apply));
_root->setVisible(run_as_root);
// disable initial buttons
_apply->setEnabled( false );
_reset->setEnabled( false );
connect(_help, SIGNAL(clicked()), SLOT(helpClicked()));
connect(_default, SIGNAL(clicked()), SLOT(defaultClicked()));
connect(_apply, SIGNAL(clicked()), SLOT(applyClicked()));
connect(_reset, SIGNAL(clicked()), SLOT(resetClicked()));
connect(_root, SIGNAL(clicked()), SLOT(rootClicked()));
QVBoxLayout *top = new QVBoxLayout(this);
top->setMargin(KDialog::marginHint());
top->setSpacing(KDialog::spacingHint());
top->addWidget(view);
top->addWidget(_sep);
QHBoxLayout *buttons = new QHBoxLayout();
top->addItem(buttons);
buttons->setSpacing(4);
buttons->addWidget(_help);
buttons->addWidget(_default);
if (run_as_root)
{
buttons->addWidget(_root);
}
buttons->addStretch(1);
if (mayModify)
{
buttons->addWidget(_apply);
buttons->addWidget(_reset);
}
top->activate();
const KAboutData *ProxyWidget::aboutData() const {
return _client->aboutData();
}
ProxyWidget::~ProxyWidget()
{
delete _client;
}
QString ProxyWidget::quickHelp() const
{
if (_client)
return _client->quickHelp();
else
return "";
}
void ProxyWidget::helpClicked()
{
if (getuid()!=0)
emit helpRequest();
else
{
OrgKdeKinfocenterInterface kinfocenter("org.kde.kinfocenter", "/moduleIface", QDBusConnection::sessionBus());
kinfocenter.invokeHelp();
}
}
void ProxyWidget::defaultClicked()
{
clientChanged(true);
_client->defaults();
}
void ProxyWidget::applyClicked()
{
_client->save();
clientChanged(false);
}
void ProxyWidget::resetClicked()
{
_client->load();
clientChanged(false);
}
void ProxyWidget::rootClicked()
{
emit runAsRoot();
}
void ProxyWidget::clientChanged(bool state)
{
_apply->setEnabled(state);
_reset->setEnabled(state);
// forward the signal
emit changed(state);
}
const KAboutData *ProxyWidget::aboutData() const
{
return _client->aboutData();
}
// vim: sw=2 sts=2 et

View file

@ -1,21 +1,21 @@
/*
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __PROXYWIDGET_H__
#define __PROXYWIDGET_H__
@ -30,49 +30,33 @@ class KAboutData;
#include <QPointer>
class ProxyView;
class ProxyWidget : public QWidget
{
Q_OBJECT
class ProxyWidget : public QWidget {
Q_OBJECT
public:
ProxyWidget(KCModule *client, const QString &title, bool run_as_root = false);
~ProxyWidget();
ProxyWidget(KCModule *client);
~ProxyWidget();
QString quickHelp() const;
const KAboutData *aboutData() const;
QString quickHelp() const;
const KAboutData *aboutData() const;
public Q_SLOTS:
bool isChanged() {
return _changed;
}
void setChanged(bool changed) {
_changed = changed;
}
void helpClicked();
void defaultClicked();
void applyClicked();
void resetClicked();
void rootClicked();
void clientChanged(bool state);
Q_SIGNALS:
void closed();
void helpRequest();
void changed(bool state);
void runAsRoot();
void quickHelpChanged();
private:
QPushButton *_help, *_default, *_apply, *_reset, *_root;
KSeparator *_sep;
bool _changed;
// Just in case the module was deleted from outside (i.e. by unloading the module)
QPointer<KCModule> _client;
// Just in case the module was deleted from outside (i.e. by unloading the module)
QPointer<KCModule> _client;
ProxyView *view;
};
#endif

View file

@ -1,43 +0,0 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "quickhelp.h"
#include "quickhelp.moc"
#include <QFrame>
QuickHelp::QuickHelp(QWidget *parent)
: KTextBrowser( parent )
{
setFrameStyle( QFrame::Panel | QFrame::Sunken );
setFocusPolicy( Qt::ClickFocus );
setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
setNotifyClick(true);
}
void QuickHelp::setText(const QString &text)
{
QString s(text);
//lukas: no need to change the font -- it breaks for
//those not having it in the right encoding!
//s.replace(QRegExp("<[Hh]1>"),"<font face=utopia><h1>");
//s.replace(QRegExp("</[Hh]1>"),"</h1></font>");
KTextBrowser::setHtml(s);
}

View file

@ -1,35 +0,0 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __quickhelp_h__
#define __quickhelp_h__
#include <ktextbrowser.h>
class QuickHelp : public KTextBrowser
{
Q_OBJECT
public:
QuickHelp(QWidget *parent);
virtual void setText(const QString &text);
};
#endif

View file

@ -1,222 +0,0 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 2004 Daniel Molkentin <molkentin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "searchwidget.h"
#include <Q3PtrList>
#include <QLabel>
#include <QListWidgetItem>
#include <QRegExp>
#include <QVBoxLayout>
#include <klineedit.h>
#include <kiconloader.h>
#include <klocale.h>
#include <klistwidget.h>
#include "searchwidget.moc"
/**
* Helper class for sorting icon modules by name without losing the fileName ID
*/
class ModuleItem : public QListWidgetItem
{
public:
ModuleItem(ConfigModule *module, QListWidget * listbox = 0) :
QListWidgetItem(listbox)
, m_module(module)
{
setText( module->moduleName() );
setIcon( KIconLoader::global()->loadIcon(module->icon(), KIconLoader::Desktop, KIconLoader::SizeSmall) );
}
ConfigModule *module() const { return m_module; }
protected:
ConfigModule *m_module;
};
KeywordListEntry::KeywordListEntry(const QString& name, ConfigModule* module)
: _name(name)
{
if(module)
_modules.append(module);
}
void KeywordListEntry::addModule(ConfigModule* module)
{
if(module)
_modules.append(module);
}
SearchWidget::SearchWidget(QWidget *parent)
: QWidget(parent)
{
_keywords.setAutoDelete(true);
QVBoxLayout * l = new QVBoxLayout(this);
l->setMargin(0);
l->setSpacing(2);
// input
_input = new KLineEdit(this);
_input->setFocus();
QLabel *inputl = new QLabel(i18n("Se&arch:"), this);
inputl->setBuddy(_input);
l->addWidget(inputl);
l->addWidget(_input);
// keyword list
_keyList = new KListWidget(this);
QLabel *keyl = new QLabel(i18n("&Keywords:"), this);
keyl->setBuddy(_keyList);
l->addWidget(keyl);
l->addWidget(_keyList);
// result list
_resultList = new KListWidget(this);
QLabel *resultl = new QLabel(i18n("&Results:"), this);
resultl->setBuddy(_resultList);
l->addWidget(resultl);
l->addWidget(_resultList);
// set stretch factors
l->setStretchFactor(_resultList, 1);
l->setStretchFactor(_keyList, 2);
connect(_input, SIGNAL(textChanged(const QString&)),
this, SLOT(slotSearchTextChanged(const QString&)));
connect(_keyList, SIGNAL(currentTextChanged(const QString&)),
this, SLOT(slotKeywordSelected(const QString&)));
connect(_resultList, SIGNAL(itemChanged (QListWidgetItem*)),
this, SLOT(slotModuleSelected(QListWidgetItem *)));
connect(_resultList, SIGNAL(executed(QListWidgetItem *)),
this, SLOT(slotModuleClicked(QListWidgetItem *)));
}
void SearchWidget::populateKeywordList(ConfigModuleList *list)
{
ConfigModule *module;
// loop through all control modules
for (module=list->first(); module != 0; module=list->next())
{
if (module->library().isEmpty())
continue;
// get the modules keyword list
QStringList kw = module->keywords();
// loop through the keyword list to populate _keywords
for(QStringList::ConstIterator it = kw.begin(); it != kw.end(); ++it)
{
QString name = (*it).toLower();
bool found = false;
// look if _keywords already has an entry for this keyword
for(KeywordListEntry *k = _keywords.first(); k != 0; k = _keywords.next())
{
// if there is an entry for this keyword, add the module to the entries module list
if (k->moduleName() == name)
{
k->addModule(module);
found = true;
break;
}
}
// if there is entry for this keyword, create a new one
if (!found)
{
KeywordListEntry *k = new KeywordListEntry(name, module);
_keywords.append(k);
}
}
}
populateKeyListBox("*");
}
void SearchWidget::populateKeyListBox(const QString& s)
{
_keyList->clear();
QStringList matches;
for(KeywordListEntry *k = _keywords.first(); k != 0; k = _keywords.next())
{
if ( QRegExp(s, Qt::CaseInsensitive, QRegExp::Wildcard).indexIn(k->moduleName()) >= 0)
matches.append(k->moduleName().trimmed());
}
for(QStringList::ConstIterator it = matches.begin(); it != matches.end(); ++it)
_keyList->addItem(*it);
_keyList->model()->sort(0);
}
void SearchWidget::populateResultListBox(const QString& s)
{
_resultList->clear();
Q3PtrList<ModuleItem> results;
for(KeywordListEntry *k = _keywords.first(); k != 0; k = _keywords.next())
{
if (k->moduleName() == s)
{
Q3PtrList<ConfigModule> modules = k->modules();
for(ConfigModule *m = modules.first(); m != 0; m = modules.next())
new ModuleItem(m, _resultList);
}
}
_resultList->model()->sort(0);
}
void SearchWidget::slotSearchTextChanged(const QString & s)
{
QString regexp = s;
regexp += '*';
populateKeyListBox(regexp);
}
void SearchWidget::slotKeywordSelected(const QString & s)
{
populateResultListBox(s);
}
void SearchWidget::slotModuleSelected(QListWidgetItem *item)
{
if (item)
emit moduleSelected( static_cast<ModuleItem*>(item)->module() );
}
void SearchWidget::slotModuleClicked(QListWidgetItem *item)
{
if (item)
emit moduleSelected( static_cast<ModuleItem*>(item)->module() );
}

View file

@ -1,76 +0,0 @@
/*
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 2004 Daniel Molkentin <molkentin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
along with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __searchwidget_h__
#define __searchwidget_h__
#include <QWidget>
#include <Qt3Support/Q3PtrList>
#include "modules.h"
class KListWidget;
class KLineEdit;
class QListWidgetItem;
class KeywordListEntry
{
public:
KeywordListEntry(const QString& name, ConfigModule* module);
void addModule(ConfigModule* module);
QString moduleName() { return _name; }
Q3PtrList<ConfigModule> modules() { return _modules; }
private:
QString _name;
Q3PtrList<ConfigModule> _modules;
};
class SearchWidget : public QWidget
{
Q_OBJECT
public:
SearchWidget(QWidget *parent);
void populateKeywordList(ConfigModuleList *list);
Q_SIGNALS:
void moduleSelected(ConfigModule *);
protected:
void populateKeyListBox(const QString& regexp);
void populateResultListBox(const QString& keyword);
protected Q_SLOTS:
void slotSearchTextChanged(const QString &);
void slotKeywordSelected(const QString &);
void slotModuleSelected(QListWidgetItem *item);
void slotModuleClicked(QListWidgetItem *item);
private:
KListWidget *_keyList, *_resultList;
KLineEdit *_input;
Q3PtrList<KeywordListEntry> _keywords;
};
#endif

View file

@ -25,4 +25,6 @@ Name[x-test]=xxProcessor Informationxx
Name[zh_CN]=
Name[zh_TW]=
Comment=Processor Information
Categories=Qt;KDE;X-KDE-information;

View file

@ -1,30 +1,29 @@
/*
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
Copyright (c) 2000 Matthias Elter <elter@kde.org>
Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
Copyright (c) 2000 Matthias Elter <elter@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
#include "toplevel.h"
#include "indexwidget.h"
#include "searchwidget.h"
#include "helpwidget.h"
#include "aboutwidget.h"
#include "proxywidget.h"
#include "moduletreeview.h"
#include "modules.h"
#include <kaboutapplicationdialog.h>
#include <kactioncollection.h>
@ -42,6 +41,8 @@
#include <kwindowsystem.h>
#include <kxmlguifactory.h>
#include <kdebug.h>
#include <QTabWidget>
#include <QSplitter>
@ -49,438 +50,176 @@
#include "toplevel.moc"
TopLevel::TopLevel()
: KXmlGuiWindow( 0, Qt::WindowContextHelpButtonHint )
, _active(0), dummyAbout(0)
{
setCaption(QString());
TopLevel::TopLevel() :
KXmlGuiWindow( 0, Qt::WindowContextHelpButtonHint), _active(NULL), dummyAbout(NULL) {
setCaption(QString());
report_bug = 0;
report_bug = NULL;
// read settings
KConfigGroup config(KGlobal::config(), "Index");
QString viewmode = config.readEntry("ViewMode", "Tree");
// initialize the entries
_modules = new ConfigModuleList();
_modules->readDesktopEntries();
if (viewmode == "Tree")
KCGlobal::setViewMode(Tree);
else
KCGlobal::setViewMode(Icon);
// create the layout box
_splitter = new QSplitter( Qt::Horizontal, this );
_splitter->setContentsMargins(0, 0, 0, 0);
QString size = config.readEntry("IconSize", "Medium");
if (size == "Small")
KCGlobal::setIconSize(KIconLoader::SizeSmall);
else if (size == "Large")
KCGlobal::setIconSize(KIconLoader::SizeLarge);
else if (size == "Huge")
KCGlobal::setIconSize(KIconLoader::SizeHuge);
else
KCGlobal::setIconSize(KIconLoader::SizeMedium);
// index tab
_indextab = new IndexWidget(_modules, this);
connect(_indextab, SIGNAL(moduleActivated(ConfigModule*)), this, SLOT(activateModule(ConfigModule*)));
connect(_indextab, SIGNAL(generalActivated()), this, SLOT(activateGeneral()));
_splitter->addWidget(_indextab);
// initialize the entries
_modules = new ConfigModuleList();
_modules->readDesktopEntries();
_indextab->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred) );
for ( ConfigModule* m = _modules->first(); m; m = _modules->next() )
connect( m, SIGNAL( helpRequest() ), this, SLOT( slotHelpRequest() ) );
// Restore sizes
KConfigGroup config = KConfigGroup(KGlobal::config(), "General");
QList<int> sizes = config.readEntry("SplitterSizes", QList<int>() );
if (!sizes.isEmpty())
_splitter->setSizes(sizes);
// create the layout box
_splitter = new QSplitter( Qt::Horizontal, this );
AboutWidget* aboutWidget = new AboutWidget( this, _modules);
connect(aboutWidget, SIGNAL( moduleSelected( ConfigModule * ) ), _indextab, SLOT(selectModule(ConfigModule*)));
// create the left hand side (the tab view)
_tab = new QTabWidget( _splitter );
// set up the right hand side (the docking area)
_dock = new DockContainer(aboutWidget, _splitter);
_tab->setWhatsThis( i18n("Choose between Index, Search and Quick Help") );
// That one does the trick ...
_splitter->setStretchFactor(_splitter->indexOf(_indextab), 0);
_splitter->setStretchFactor(_splitter->indexOf(_dock), 1);
// index tab
_indextab = new IndexWidget(_modules, 0L);
connect(_indextab, SIGNAL(moduleActivated(ConfigModule*)),
this, SLOT(activateModule(ConfigModule*)));
_tab->addTab(_indextab, KIcon("kinfocenter"), i18n("&Index"));
connect(_indextab, SIGNAL(generalActivated()), _dock, SLOT(showAboutWidget()));
connect(_indextab, SIGNAL(categorySelected(Q3ListViewItem*)),
this, SLOT(categorySelected(Q3ListViewItem*)));
// set the main view
setCentralWidget(_splitter);
// search tab
_searchtab = new SearchWidget(0L);
_searchtab->populateKeywordList(_modules);
connect(_searchtab, SIGNAL(moduleSelected(ConfigModule *)),
this, SLOT(activateModule(ConfigModule *)));
// initialize the GUI actions
setupActions();
_tab->addTab(_searchtab, KIcon("edit-find"), i18n("Sear&ch"));
KWindowSystem::setIcons(winId(), KIconLoader::global()->loadIcon(KINFOCENTER_ICON_NAME, KIconLoader::NoGroup, 32), KIconLoader::global()->loadIcon("hwinfo", KIconLoader::NoGroup, 16) );
// help tab
_helptab = new HelpWidget(0L);
_tab->addTab(_helptab, KIcon("help-contents"), i18n("Hel&p"));
_tab->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) );
// Restore sizes
config = KConfigGroup(KGlobal::config(),"General");
QList<int> sizes = config.readEntry( "SplitterSizes",QList<int>() );
if (!sizes.isEmpty())
_splitter->setSizes(sizes);
// set up the right hand side (the docking area)
_dock = new DockContainer( _splitter );
// That one does the trick ...
_splitter->setStretchFactor( _splitter->indexOf( _tab ), 0 );
_splitter->setStretchFactor( _splitter->indexOf( _dock ), 1);
connect(_dock, SIGNAL(newModule(const QString&, const QString&, const QString&)),
this, SLOT(newModule(const QString&, const QString&, const QString&)));
connect(_dock, SIGNAL(changedModule(ConfigModule*)),
SLOT(changedModule(ConfigModule*)));
// set the main view
setCentralWidget( _splitter );
// initialize the GUI actions
setupActions();
// activate defaults
if (KCGlobal::viewMode() == Tree) {
activateTreeView();
tree_view->setChecked(true);
}
else {
activateIconView();
icon_view->setChecked(true);
}
// insert the about widget
if (KCGlobal::isInfoCenter())
{
AboutWidget *aw = new AboutWidget( this, _indextab->firstTreeViewItem());
connect( aw, SIGNAL( moduleSelected( ConfigModule * ) ),
SLOT( activateModule( ConfigModule * ) ) );
_dock->setBaseWidget( aw );
KWindowSystem::setIcons( winId(),
KIconLoader::global()->loadIcon("hwinfo", KIconLoader::NoGroup, 32 ),
KIconLoader::global()->loadIcon("hwinfo", KIconLoader::NoGroup, 16 ) );
}
else
{
AboutWidget *aw = new AboutWidget(this);
connect( aw, SIGNAL( moduleSelected( ConfigModule * ) ),
SLOT( activateModule( ConfigModule * ) ) );
_dock->setBaseWidget(aw);
}
_indextab->selectGeneral();
}
TopLevel::~TopLevel()
{
KConfigGroup config(KGlobal::config(), "Index");
if (KCGlobal::viewMode() == Tree)
config.writeEntry("ViewMode", "Tree");
else
config.writeEntry("ViewMode", "Icon");
TopLevel::~TopLevel() {
switch (KCGlobal::iconSize())
{
case KIconLoader::SizeSmall:
config.writeEntry("IconSize", "Small");
break;
case KIconLoader::SizeLarge:
config.writeEntry("IconSize", "Large");
break;
case KIconLoader::SizeHuge:
config.writeEntry("IconSize", "Huge");
break;
default:
config.writeEntry("IconSize", "Medium");
break;
}
KConfigGroup config = KConfigGroup(KGlobal::config(), "General");
config.writeEntry("SplitterSizes", _splitter->sizes());
config = KConfigGroup(KGlobal::config(),"General");
config.writeEntry("SplitterSizes", _splitter->sizes());
config.sync();
config.sync();
delete _modules;
delete _modules;
}
bool TopLevel::queryClose()
{
return _dock->dockModule(0);
void TopLevel::setupActions() {
KStandardAction::quit(this, SLOT(close()), actionCollection());
KStandardAction::keyBindings(guiFactory(), SLOT(configureShortcuts()), actionCollection());
about_module = actionCollection()->addAction("help_about_module");
about_module->setText(i18n("About Current Module"));
about_module->setVisible(false);
connect(about_module, SIGNAL(triggered(bool) ), SLOT(aboutModule()));
createGUI("kinfocenterui.rc");
report_bug = actionCollection()->action("help_report_bug");
report_bug->setText(i18n("&Report Bug..."));
report_bug->disconnect();
connect(report_bug, SIGNAL(activated()), SLOT(reportBug()));
}
void TopLevel::setupActions()
{
KStandardAction::quit(this, SLOT(close()), actionCollection());
KStandardAction::keyBindings(guiFactory(), SLOT(configureShortcuts()),
actionCollection());
void TopLevel::activateModule(ConfigModule *configModule) {
kDebug() << "Activating module..." << endl;
QActionGroup* viewModeGroup = new QActionGroup(this);
_active=configModule;
icon_view = new KToggleAction(i18n("&Icon View"), this);
actionCollection()->addAction("activate_iconview", icon_view);
connect(icon_view, SIGNAL(triggered(bool) ), SLOT(activateIconView()));
icon_view->setActionGroup(viewModeGroup);
// dock it
if (!_dock->dockModule(configModule)) {
kDebug() << "Activating module by docking it." << endl;
tree_view = new KToggleAction(i18n("&Tree View"), this);
actionCollection()->addAction("activate_treeview", tree_view);
connect(tree_view, SIGNAL(triggered(bool) ), SLOT(activateTreeView()));
tree_view->setActionGroup(viewModeGroup);
return;
}
QActionGroup* iconSizeGroup = new QActionGroup(this);
kDebug() << "Modifying About Module." << endl;
icon_small = new KToggleAction(i18nc("@option activate small size icons", "&Small"), this);
actionCollection()->addAction("activate_smallicons", icon_small);
connect(icon_small, SIGNAL(triggered(bool) ), SLOT(activateSmallIcons()));
icon_small->setActionGroup(iconSizeGroup);
if (configModule->aboutData()) {
about_module->setText(i18nc("Help menu->about <modulename>", "About %1", handleAmpersand(configModule->moduleName())));
about_module->setIcon(configModule->realIcon(KIconLoader::SizeSmall));
about_module->setVisible(true);
} else {
about_module->setText(i18n("About Current Module"));
about_module->setIcon(KIcon());
about_module->setVisible(false);
}
icon_medium = new KToggleAction(i18nc("@option activate medium size icons", "&Medium"), this);
actionCollection()->addAction("activate_mediumicons", icon_medium);
connect(icon_medium, SIGNAL(triggered(bool) ), SLOT(activateMediumIcons()));
icon_medium->setActionGroup(iconSizeGroup);
setCaption(configModule->moduleName(), false);
icon_large = new KToggleAction(i18nc("@option activate large size icons", "&Large"), this);
actionCollection()->addAction("activate_largeicons", icon_large);
connect(icon_large, SIGNAL(triggered(bool) ), SLOT(activateLargeIcons()));
icon_large->setActionGroup(iconSizeGroup);
if (configModule->moduleName().isEmpty())
report_bug->setText(i18n("&Report Bug..."));
else
report_bug->setText(i18n("Report Bug on Module %1...", handleAmpersand(configModule->moduleName())));
icon_huge = new KToggleAction(i18nc("@option activate huge size icons", "&Huge"), this);
actionCollection()->addAction("activate_hugeicons", icon_huge);
connect(icon_huge, SIGNAL(triggered(bool) ), SLOT(activateHugeIcons()));
icon_huge->setActionGroup(iconSizeGroup);
about_module = actionCollection()->addAction("help_about_module");
about_module->setText(i18n("About Current Module"));
connect(about_module, SIGNAL(triggered(bool) ), SLOT(aboutModule()));
about_module->setEnabled(false);
createGUI("kinfocenterui.rc");
report_bug = actionCollection()->action("help_report_bug");
report_bug->setText(i18n("&Report Bug..."));
report_bug->disconnect();
connect(report_bug, SIGNAL(activated()), SLOT(reportBug()));
kDebug() << "Activating module done." << endl;
}
void TopLevel::activateIconView()
{
KCGlobal::setViewMode(Icon);
_indextab->activateView(Icon);
icon_small->setEnabled(true);
icon_medium->setEnabled(true);
icon_large->setEnabled(true);
icon_huge->setEnabled(true);
switch(KCGlobal::iconSize())
{
case KIconLoader::SizeSmall:
icon_small->setChecked(true);
break;
case KIconLoader::SizeLarge:
icon_large->setChecked(true);
break;
case KIconLoader::SizeHuge:
icon_huge->setChecked(true);
break;
default:
icon_medium->setChecked(true);
break;
}
void TopLevel::deleteDummyAbout() {
delete dummyAbout;
dummyAbout = 0;
}
void TopLevel::activateTreeView()
{
KCGlobal::setViewMode(Tree);
_indextab->activateView(Tree);
void TopLevel::reportBug() {
dummyAbout = NULL;
bool deleteit = false;
icon_small->setEnabled(false);
icon_medium->setEnabled(false);
icon_large->setEnabled(false);
icon_huge->setEnabled(false);
if (!_active) // report against kinfocenter
dummyAbout = const_cast<KAboutData*>(KGlobal::mainComponent().aboutData());
else {
if (_active->aboutData())
dummyAbout = const_cast<KAboutData*>(_active->aboutData());
else {
QString kcmLibrary = "kcm" + _active->library();
dummyAbout = new KAboutData(kcmLibrary.toLatin1(), 0, ki18n(_active->moduleName().toUtf8()), "2.0");
deleteit = true;
}
}
KBugReport *br = new KBugReport(this, false, dummyAbout);
if (deleteit)
connect(br, SIGNAL(finished()), SLOT(deleteDummyAbout()));
else
dummyAbout = NULL;
br->show();
}
void TopLevel::activateSmallIcons()
{
KCGlobal::setIconSize(KIconLoader::SizeSmall);
_indextab->reload();
void TopLevel::aboutModule() {
kDebug() << "About " << _active->moduleName() << endl;
KAboutApplicationDialog dlg(_active->aboutData());
dlg.exec();
}
void TopLevel::activateMediumIcons()
{
KCGlobal::setIconSize(KIconLoader::SizeMedium);
_indextab->reload();
QString TopLevel::handleAmpersand(const QString& modName) const {
QString modulename = modName;
// double it
if (modulename.contains( '&')) {
for (int i = modulename.length(); i >= 0; --i)
if (modulename[ i ] == '&')
modulename.insert(i, "&");
}
return modulename;
}
void TopLevel::activateLargeIcons()
{
KCGlobal::setIconSize(KIconLoader::SizeLarge);
_indextab->reload();
}
void TopLevel::activateHugeIcons()
{
KCGlobal::setIconSize(KIconLoader::SizeHuge);
_indextab->reload();
}
void TopLevel::newModule(const QString &name, const QString& docPath, const QString &quickhelp)
{
setCaption(name, false);
_helptab->setText( docPath, quickhelp );
if (!report_bug) return;
if(name.isEmpty())
report_bug->setText(i18n("&Report Bug..."));
else
report_bug->setText(i18n("Report Bug on Module %1...", handleAmpersand( name)));
}
void TopLevel::changedModule(ConfigModule *changed)
{
if (!changed)
return;
setCaption(changed->moduleName(), changed->isChanged() );
}
void TopLevel::categorySelected(Q3ListViewItem *category)
{
if (_active)
{
if (_active->isChanged())
{
int res = KMessageBox::warningYesNoCancel(this, _active ?
i18n("There are unsaved changes in the active module.\n"
"Do you want to apply the changes before running "
"the new module or discard the changes?") :
i18n("There are unsaved changes in the active module.\n"
"Do you want to apply the changes before exiting "
"the Control Center or discard the changes?"),
i18n("Unsaved Changes"),
KStandardGuiItem::apply(),
KStandardGuiItem::discard());
if (res == KMessageBox::Yes)
_active->module()->applyClicked();
else if (res == KMessageBox::Cancel)
return;
}
}
_dock->removeModule();
about_module->setText( i18n( "About Current Module" ) );
about_module->setIcon( KIcon() );
about_module->setEnabled( false );
// insert the about widget
Q3ListViewItem *firstItem = category->firstChild();
QString caption = static_cast<ModuleTreeItem*>(category)->caption();
if( qstrcmp(_dock->baseWidget()->metaObject()->className(), "AboutWidget" ) == 0)
{
static_cast<AboutWidget *>( _dock->baseWidget() )->setCategory( firstItem, caption);
}
else
{
AboutWidget *aw = new AboutWidget( this, firstItem, caption );
connect( aw, SIGNAL( moduleSelected( ConfigModule * ) ),
SLOT( activateModule( ConfigModule * ) ) );
_dock->setBaseWidget( aw );
}
}
void TopLevel::activateModule(ConfigModule *mod)
{
if ( _dock->module() == mod )
return;
// tell the index to display the module
_indextab->makeVisible(mod);
// tell the index to mark this module as loaded
_indextab->makeSelected(mod);
// dock it
if (!_dock->dockModule(mod))
{
if ( _dock->module() )
{
_indextab->makeVisible(_active);
_indextab->makeSelected(_active);
}
return;
}
_active=mod;
if (mod->aboutData())
{
about_module->setText(i18nc("Help menu->about <modulename>", "About %1",
handleAmpersand( mod->moduleName())));
about_module->setIcon(KIcon(mod->icon()));
about_module->setEnabled(true);
}
else
{
about_module->setText(i18n("About Current Module"));
about_module->setIcon(KIcon());
about_module->setEnabled(false);
}
}
void TopLevel::deleteDummyAbout()
{
delete dummyAbout;
dummyAbout = 0;
}
void TopLevel::slotHelpRequest()
{
_tab->setCurrentIndex( _tab->indexOf( _helptab ) );
}
void TopLevel::reportBug()
{
// this assumes the user only opens one bug report at a time
static char buffer[128];
dummyAbout = 0;
bool deleteit = false;
if (!_active) // report against kinfocenter
dummyAbout = const_cast<KAboutData*>(KGlobal::mainComponent().aboutData());
else
{
if (_active->aboutData())
dummyAbout = const_cast<KAboutData*>(_active->aboutData());
else
{
snprintf(buffer, sizeof(buffer), "kcm%s", _active->library().toLatin1().constData());
dummyAbout = new KAboutData(buffer, 0, ki18n(_active->moduleName().toUtf8()), "2.0");
deleteit = true;
}
}
KBugReport *br = new KBugReport(this, false, dummyAbout);
if (deleteit)
connect(br, SIGNAL(finished()), SLOT(deleteDummyAbout()));
else
dummyAbout = 0;
br->show();
}
void TopLevel::aboutModule()
{
KAboutApplicationDialog dlg(_active->aboutData());
dlg.exec();
}
QString TopLevel::handleAmpersand( const QString &modName ) const
{
QString modulename = modName;
if( modulename.contains( '&' )) // double it
{
for( int i = modulename.length();
i >= 0;
--i )
if( modulename[ i ] == '&' )
modulename.insert( i, "&" );
}
return modulename;
void TopLevel::activateGeneral() {
kDebug() << "Activating General..." << endl;
about_module->setText(i18n("About Current Module"));
about_module->setIcon(KIcon());
about_module->setVisible(false);
setCaption(i18n("General Information"), false);
report_bug->setText(i18n("&Report Bug..."));
}

Some files were not shown because too many files have changed in this diff Show more