Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / runtime / kcontrol / infocenter / ioslaveinfo / kcmioslaveinfo.cpp
blob750f19a9f32b8a55eeed335770dd064d7c69efca
1 /*
2 * kcmioslaveinfo.cpp
4 * Copyright 2001 Alexander Neundorf <neundorf@kde.org>
5 * Copyright 2001 George Staikos <staikos@kde.org>
7 * Requires the Qt widget libraries, available at no cost at
8 * http://www.troll.no/
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include <QFile>
26 #include <QLabel>
27 #include <QLayout>
28 #include <QSpinBox>
29 #include <QTabWidget>
30 #include <QTextCodec>
31 #include <QWhatsThis>
33 #include <kconfig.h>
34 #include <kdebug.h>
35 #include <kdialog.h>
36 #include <kglobal.h>
37 #include <kiconloader.h>
38 #include <kio/job.h>
39 #include <klocale.h>
40 #include <kprotocolinfo.h>
41 #include <kstandarddirs.h>
42 #include <kpluginfactory.h>
43 #include <kpluginloader.h>
46 #include "kcmioslaveinfo.h"
48 K_PLUGIN_FACTORY(SlaveFactory, registerPlugin<KCMIOSlaveInfo>();)
49 K_EXPORT_PLUGIN( SlaveFactory("kcmioslaveinfo"))
52 KCMIOSlaveInfo::KCMIOSlaveInfo(QWidget *parent, const QVariantList &)
53 :KCModule(SlaveFactory::componentData(), parent),m_ioslavesLb(0),m_tfj(0)
55 QVBoxLayout *layout=new QVBoxLayout(this);
56 layout->setMargin(0);
58 setQuickHelp( i18n("<h1>IO slaves</h1> Gives you an overview of the installed ioslaves."));
59 setButtons( KCModule::Help );
61 QLabel* label=new QLabel(i18n("Available IO slaves:"),this);
62 QWidget *hbox=new QWidget(this);
63 QHBoxLayout *hboxLayout1 = new QHBoxLayout(hbox);
64 hboxLayout1->setMargin(0);
65 m_ioslavesLb=new KListWidget(hbox);
66 m_ioslavesLb->setMinimumSize(fontMetrics().width("blahfaselwhatever----"),10);
67 hboxLayout1->addWidget( m_ioslavesLb );
68 connect( m_ioslavesLb, SIGNAL(itemSelectionChanged() ), SLOT( showInfo() ) );
69 //TODO make something useful after 2.1 is released
70 m_info=new KTextBrowser(hbox);
71 hboxLayout1->setSpacing(KDialog::spacingHint());
72 hboxLayout1->addWidget( m_info );
74 layout->addWidget(label);
75 layout->addWidget(hbox);
76 hboxLayout1->setStretchFactor(m_ioslavesLb,1);
77 hboxLayout1->setStretchFactor(m_info,5);
79 QStringList protocols=KProtocolInfo::protocols();
80 protocols.sort();
81 for (QStringList::Iterator it=protocols.begin(); it!=protocols.end(); ++it)
83 QString proto = *it;
84 m_ioslavesLb->addItem( new QListWidgetItem ( SmallIcon( KProtocolInfo::icon( proto )), proto, m_ioslavesLb));
86 //m_ioslavesLb->sort();
87 //m_ioslavesLb->setSelected(0, true);
89 setButtons(KCModule::Help);
91 KAboutData *about =
92 new KAboutData(I18N_NOOP("kcmioslaveinfo"), 0,
93 ki18n("KDE Panel System Information Control Module"),
94 0, KLocalizedString(), KAboutData::License_GPL,
95 ki18n("(c) 2001 - 2002 Alexander Neundorf"));
97 about->addAuthor(ki18n("Alexander Neundorf"), KLocalizedString(), "neundorf@kde.org");
98 about->addAuthor(ki18n("George Staikos"), KLocalizedString(), "staikos@kde.org");
99 setAboutData( about );
103 void KCMIOSlaveInfo::slaveHelp( KIO::Job *, const QByteArray &data)
105 if ( data.size() == 0 ) { // EOF
106 int index = helpData.indexOf( "<meta http-equiv=\"Content-Type\"" );
107 index = helpData.indexOf( "charset=", index ) + 8;
108 QString charset = helpData.mid( index, helpData.indexOf( '\"', index ) - index );
109 QString text = QTextCodec::codecForName(charset.toLatin1())->toUnicode( helpData );
110 index = text.indexOf( "<div class=\"titlepage\">" );
111 text = text.mid( index );
112 index = text.indexOf( "<table width=\"100%\" class=\"bottom-nav\"" );
113 text = text.left( index );
114 m_info->setHtml(text);
115 return;
117 helpData += data;
120 void KCMIOSlaveInfo::slotResult(KJob *)
122 m_tfj = 0;
125 void KCMIOSlaveInfo::showInfo(const QString& protocol)
127 QString file = QString("kioslave/%1.docbook").arg( protocol );
128 file = KGlobal::locale()->langLookup( file );
129 if (m_tfj)
131 m_tfj->kill();
132 m_tfj = 0;
135 if (!file.isEmpty())
137 helpData.clear();
138 m_tfj = KIO::get( KUrl( QString("help:/kioslave/%1.html").arg( protocol ) ), KIO::Reload, KIO::HideProgressInfo );
139 connect( m_tfj, SIGNAL( data( KIO::Job *, const QByteArray &) ), SLOT( slaveHelp( KIO::Job *, const QByteArray &) ) );
140 connect( m_tfj, SIGNAL( result( KJob * ) ), SLOT( slotResult( KJob * ) ) );
141 return;
143 m_info->setPlainText(i18n("Some info about protocol %1:/ ...", protocol));
146 void KCMIOSlaveInfo::showInfo()
148 QListWidgetItem *item = m_ioslavesLb->currentItem();
149 if (item==0)
150 return;
151 showInfo( item->text() );
154 #include "kcmioslaveinfo.moc"