Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / kinfocenter / ioslaveinfo / kcmioslaveinfo.cpp
blobb9fa63931af82e77ac99432688b1860bee35e99e
1 /*
2 * kcmioslaveinfo.cpp
4 * Copyright 2001 Alexander Neundorf <neundorf@kde.org>
5 * Copyright 2001 George Staikos <staikos@kde.org>
6 * Copyright 2008 Pino Toscano <pino@kde.org>
8 * Requires the Qt widget libraries, available at no cost at
9 * http://www.troll.no/
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include <QLabel>
27 #include <QLayout>
28 #include <QComboBox>
30 #include <kconfig.h>
31 #include <kdebug.h>
32 #include <kdialog.h>
33 #include <kglobal.h>
34 #include <kiconloader.h>
35 #include <klocale.h>
36 #include <kprotocolinfo.h>
37 #include <kstandarddirs.h>
38 #include <ktoolinvocation.h>
39 #include <kpluginfactory.h>
40 #include <kpluginloader.h>
41 #include <khtml_part.h>
42 #include <khtmlview.h>
43 #include <dom/dom_node.h>
44 #include <dom/html_element.h>
46 #include "kcmioslaveinfo.h"
48 K_PLUGIN_FACTORY(SlaveFactory, registerPlugin<KCMIOSlaveInfo>();)
49 K_EXPORT_PLUGIN( SlaveFactory("kcmioslaveinfo"))
51 KCMIOSlaveInfo::KCMIOSlaveInfo(QWidget *parent, const QVariantList &) :
52 KCModule(SlaveFactory::componentData(), parent) {
53 QVBoxLayout *layout=new QVBoxLayout(this);
54 layout->setMargin(0);
56 setQuickHelp(i18n("Overview of the installed ioslaves and supported protocols."));
57 setButtons(KCModule::Help);
59 QHBoxLayout* selectionLayout = new QHBoxLayout();
61 ioSlaves = new QComboBox(this);
62 QLabel* ioSlavesLabel = new QLabel(i18n("Select the protocol documentation to display:"));
63 ioSlavesLabel->setBuddy(ioSlaves);
65 connect(ioSlaves, SIGNAL(currentIndexChanged(const QString&) ), SLOT( showInfo(const QString&) ));
67 selectionLayout->addWidget(ioSlavesLabel);
68 selectionLayout->addWidget(ioSlaves);
70 layout->addLayout(selectionLayout);
73 m_info = new KHTMLPart(this, this);
74 m_info->setJScriptEnabled(false);
75 m_info->setJavaEnabled(false);
76 m_info->setMetaRefreshEnabled(false);
77 m_info->setPluginsEnabled(false);
79 connect(m_info, SIGNAL(completed()), this, SLOT(loadingCompleted()));
80 connect(m_info->browserExtension(), SIGNAL(openUrlRequestDelayed(const KUrl&, const KParts::OpenUrlArguments&, const KParts::BrowserArguments&)),
81 this, SLOT(openUrl(const KUrl&, const KParts::OpenUrlArguments&, const KParts::BrowserArguments&)));
83 layout->addWidget(m_info->view());
85 QStringList protocols=KProtocolInfo::protocols();
86 protocols.sort();
87 foreach(const QString &proto, protocols) {
88 //m_ioslavesLb->addItem(new QListWidgetItem ( SmallIcon( KProtocolInfo::icon( proto )), proto, m_ioslavesLb));
89 ioSlaves->addItem(SmallIcon( KProtocolInfo::icon( proto )), proto);
91 //m_ioslavesLb->sort();
92 //m_ioslavesLb->setSelected(0, true);
94 KAboutData *about = new KAboutData(I18N_NOOP("kcmioslaveinfo"), 0,
95 ki18n("KDE Panel System Information Control Module"),
96 0, KLocalizedString(), KAboutData::License_GPL,
97 ki18n("(c) 2001 - 2002 Alexander Neundorf"));
99 about->addAuthor(ki18n("Alexander Neundorf"), KLocalizedString(), "neundorf@kde.org");
100 about->addAuthor(ki18n("George Staikos"), KLocalizedString(), "staikos@kde.org");
101 setAboutData(about);
106 * Big Hack to only select content of the help documentation
107 * The HTML content is cut by removing the all DIV blocks but the class="article" one
109 void KCMIOSlaveInfo::selectHelpBody() {
110 DOM::Document document = m_info->document();
111 m_info->view()->setUpdatesEnabled(true);
112 if (document.isNull()) {
113 return;
115 const DOM::NodeList bodylist = document.getElementsByTagName("body");
116 if (bodylist.length() != 1) {
117 return;
119 DOM::Node body = bodylist.item(0);
120 const DOM::NodeList bodyChildren = body.childNodes();
121 for (unsigned long i = 0; i < bodyChildren.length(); ++i) {
122 const DOM::Node child = bodyChildren.item(i);
123 if ((child.nodeType() != DOM::Node::ELEMENT_NODE)
124 || (child.nodeName().lower() != DOM::DOMString("div"))) {
125 continue;
127 const DOM::HTMLElement el = child;
128 if (el.className() == DOM::DOMString("article")) {
129 continue;
131 --i;
132 body.removeChild(child);
136 void KCMIOSlaveInfo::showInfo(const QString& protocol) {
137 QString file = QString("kioslave/%1/index.docbook").arg(protocol);
138 file = KGlobal::locale()->langLookup(file);
140 if (!file.isEmpty()) {
141 m_info->view()->setUpdatesEnabled(false);
142 m_info->openUrl(KUrl(QString("help:/kioslave/%1/index.html").arg(protocol)));
143 return;
145 m_info->begin();
146 m_info->write(i18n("<html><body><p style='text-align:center'>No documentation available for the '%1:/' protocol.</p></body></html>", protocol));
147 m_info->end();
150 void KCMIOSlaveInfo::loadingCompleted() {
151 selectHelpBody();
154 void KCMIOSlaveInfo::openUrl(const KUrl& url, const KParts::OpenUrlArguments&, const KParts::BrowserArguments&) {
155 if (url.protocol() == QLatin1String("mailto")) {
156 KToolInvocation::invokeMailer(url);
157 } else {
158 KToolInvocation::invokeBrowser(url.url());
162 #include "kcmioslaveinfo.moc"