Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / kinfocenter / aboutwidget.cpp
blobf9496c27e5c632b889a9ffe66b699ba2ea9141df
1 /*
2 Copyright (c) 2000,2001 Matthias Elter <elter@kde.org>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "aboutwidget.h"
20 #include "global.h"
21 #include "modules.h"
22 #include "moduletreeview.h"
24 #include <kstandarddirs.h>
25 #include <klocale.h>
26 #include <kdebug.h>
27 #include <kcursor.h>
28 #include <kglobalsettings.h>
29 #include <khtml_part.h>
30 #include <kapplication.h>
31 #include <kvbox.h>
33 #include <QFile>
34 #include <QTextStream>
36 #include "aboutwidget.moc"
38 static const char kcc_text[] = I18N_NOOP("KDE Control Center");
40 static const char title_text[] = I18N_NOOP("Configure your desktop environment.");
42 static const char intro_text[] = I18N_NOOP("Welcome to the \"KDE Control Center\", "
43 "a central place to configure your "
44 "desktop environment. "
45 "Select an item from the index on the left "
46 "to load a configuration module.");
48 static const char kcc_infotext[] = I18N_NOOP("KDE Info Center");
50 static const char title_infotext[] = I18N_NOOP("Get system and desktop environment information");
52 static const char intro_infotext[] = I18N_NOOP("Welcome to the \"KDE Info Center\", "
53 "a central place to find information about your "
54 "computer system.");
56 static const char use_text[] = I18N_NOOP("Click on the \"Help\" tab on the left to view help "
57 "for the active "
58 "control module. Use the \"Search\" tab if you are unsure "
59 "where to look for "
60 "a particular configuration option.");
62 static const char version_text[] = I18N_NOOP("KDE version:");
63 static const char user_text[] = I18N_NOOP("User:");
64 static const char host_text[] = I18N_NOOP("Hostname:");
65 static const char system_text[] = I18N_NOOP("System:");
66 static const char release_text[] = I18N_NOOP("Release:");
67 static const char machine_text[] = I18N_NOOP("Machine:");
69 AboutWidget::AboutWidget(QWidget *parent, Q3ListViewItem* category, const QString &caption)
70 : KHBox(parent),
71 _moduleList(false),
72 _category(category),
73 _caption(caption)
75 if (_category)
76 _moduleList = true;
78 setMinimumSize(400, 400);
80 // set qwhatsthis help
81 this->setWhatsThis( i18n(intro_text));
82 _viewer = new KHTMLPart( this );
83 _viewer->widget()->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
84 connect( _viewer->browserExtension(),
85 SIGNAL(openUrlRequest(const KUrl&, const KParts::OpenUrlArguments&, const KParts::BrowserArguments&)),
86 this, SLOT(slotModuleLinkClicked(const KUrl&)) );
87 updatePixmap();
90 void AboutWidget::setCategory( Q3ListViewItem* category, const QString &caption )
92 _caption = caption;
93 _category = category;
94 if ( _category )
95 _moduleList = true;
96 else
97 _moduleList = true;
99 // Update the pixmap to be shown:
100 updatePixmap();
103 void AboutWidget::updatePixmap()
105 QString file = KStandardDirs::locate( "data", "kinfocenter/about/main.html" );
106 QFile f( file );
107 f.open( QIODevice::ReadOnly );
108 QTextStream t( &f );
109 QString res = t.readAll();
111 res = res.arg( KStandardDirs::locate( "data", "kdeui/about/kde_infopage.css" ) );
112 if ( kapp->layoutDirection() == Qt::RightToLeft )
113 res = res.arg( "@import \"%1\";" ).arg( KStandardDirs::locate( "data", "kdeui/about/kde_infopage_rtl.css" ) );
114 else
115 res = res.arg( "" );
118 QString title, intro, caption;
119 if (KCGlobal::isInfoCenter())
121 res = res.arg(i18n(kcc_infotext))
122 .arg(i18n(title_infotext))
123 .arg(i18n(intro_infotext));
125 else
127 res = res.arg(i18n(kcc_text))
128 .arg(i18n(title_text))
129 .arg(i18n(intro_text));
132 QString content;
134 if (!_moduleList)
136 content += "<table class=\"kc_table\">\n";
137 #define KC_HTMLROW( a, b ) "<tr><td class=\"kc_leftcol\">" + i18n( a ) + "</td><td class=\"kc_rightcol\">" + b + "</tr>\n"
138 content += KC_HTMLROW( version_text, KCGlobal::kdeVersion() );
139 content += KC_HTMLROW( user_text, KCGlobal::userName() );
140 content += KC_HTMLROW( host_text, KCGlobal::hostName() );
141 content += KC_HTMLROW( system_text, KCGlobal::systemName() );
142 content += KC_HTMLROW( release_text, KCGlobal::systemRelease() );
143 content += KC_HTMLROW( machine_text, KCGlobal::systemMachine() );
144 #undef KC_HTMLROW
145 content += "</table>\n";
146 content += "<p class=\"kc_use_text\">" + i18n( use_text ) + "</p>\n";
148 else
150 content += "<div id=\"tableTitle\">" + _caption + "</div>";
152 content += "<table class=\"kc_table\">\n";
153 // traverse the list
154 Q3ListViewItem* pEntry = _category;
155 while (pEntry != NULL)
157 QString szName;
158 QString szComment;
159 ConfigModule *module = static_cast<ModuleTreeItem*>(pEntry)->module();
160 /* TODO: work out link */
161 content += "<tr><td class=\"kc_leftcol\">";
162 if (module)
164 szName = module->moduleName();
165 szComment = module->comment();
166 content += "<a href=\"%1\" class=\"kcm_link\">" + szName + "</a></td><td class=\"kc_rightcol\">" + szComment;
167 KUrl moduleURL(QString("kcm://%1").arg(QString().sprintf("%p",(void*)module)) );
168 QString linkURL( moduleURL.url() );
169 content = content.arg( linkURL );
170 _moduleMap.insert( linkURL, module );
172 else
174 szName = static_cast<ModuleTreeItem*>(pEntry)->caption();
175 content += szName + "</td><td class=\"kc_rightcol\">" + szName;
177 content += "</td></tr>\n";
178 pEntry = pEntry->nextSibling();
180 content += "</table>";
182 _viewer->begin(KUrl(file ));
183 _viewer->write( res.arg( content ) );
184 _viewer->end();
187 void AboutWidget::slotModuleLinkClicked( const KUrl& url )
189 ConfigModule* module;
190 module = _moduleMap[url.url()];
191 if ( module )
192 emit moduleSelected( module );