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
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.
37 #include <kiconloader.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);
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();
81 for (QStringList::Iterator it
=protocols
.begin(); it
!=protocols
.end(); ++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
);
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
);
120 void KCMIOSlaveInfo::slotResult(KJob
*)
125 void KCMIOSlaveInfo::showInfo(const QString
& protocol
)
127 QString file
= QString("kioslave/%1.docbook").arg( protocol
);
128 file
= KGlobal::locale()->langLookup( file
);
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
* ) ) );
143 m_info
->setPlainText(i18n("Some info about protocol %1:/ ...", protocol
));
146 void KCMIOSlaveInfo::showInfo()
148 QListWidgetItem
*item
= m_ioslavesLb
->currentItem();
151 showInfo( item
->text() );
154 #include "kcmioslaveinfo.moc"