00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include <qstring.h>
00013
#include <qvariant.h>
00014
#include <qheader.h>
00015
#include <qlabel.h>
00016
#include <qlayout.h>
00017
#include <qlistview.h>
00018
#include <qgroupbox.h>
00019
#include <qhbox.h>
00020
#include <qregexp.h>
00021
00022
#include <kconfig.h>
00023
#include <kdebug.h>
00024
#include <kglobal.h>
00025
#include <klocale.h>
00026
#include <kservice.h>
00027
#include <ktrader.h>
00028
#include <kurllabel.h>
00029
#include <kapplication.h>
00030
#include "domutil.h"
00031
00032
#include "partselectwidget.h"
00033
#include "plugincontroller.h"
00034
00035 class PluginItem :
public QCheckListItem
00036 {
00037
public:
00038
00039 PluginItem(
QListView * parent,
QString const & name,
QString const & label,
00040
QString const & info,
QString const url = QString::null )
00041 :
QCheckListItem( parent, label,
QCheckListItem::CheckBox),
00042
_name( name ),
_info( info ),
_url(
url )
00043 {}
00044
00045 QString info() {
return _info; }
00046 QString name() {
return _name; }
00047 QString url() {
return _url; }
00048
00049
private:
00050
00051 QString _name;
00052 QString _info;
00053 QString _url;
00054 };
00055
00056
00057 PartSelectWidget::PartSelectWidget(
QDomDocument &projectDom,
00058
QWidget *parent,
const char *name)
00059 :
QWidget(parent, name), m_projectDom(projectDom), _scope(Project)
00060 {
00061
init();
00062 }
00063
00064
00065 PartSelectWidget::PartSelectWidget(
QWidget *parent,
const char *name)
00066 :
QWidget(parent, name), m_projectDom(
QDomDocument()), _scope(Global)
00067 {
00068
init();
00069 }
00070
00071
00072 void PartSelectWidget::init()
00073 {
00074
QVBoxLayout *layout =
new QVBoxLayout(
this);
00075
00076
QString text = (
_scope==
Global)?
00077 i18n(
"Plugins to Load at Startup") :
00078 i18n(
"Plugins to Load for This Project");
00079
00080
QGroupBox * groupBox1 =
new QGroupBox(
text,
this );
00081 groupBox1->setColumnLayout(0, Qt::Vertical );
00082 groupBox1->layout()->setSpacing( 6 );
00083 groupBox1->layout()->setMargin( 11 );
00084
QHBoxLayout * groupBox1Layout =
new QHBoxLayout( groupBox1->layout() );
00085 groupBox1Layout->setAlignment( Qt::AlignTop );
00086
00087
_pluginList =
new QListView( groupBox1 );
00088
_pluginList->setResizeMode( QListView::LastColumn );
00089
_pluginList->addColumn(
"");
00090
_pluginList->header()->hide();
00091
00092 groupBox1Layout->addWidget(
_pluginList );
00093 layout->addWidget( groupBox1 );
00094
00095 QGroupBox * groupBox2 =
new QGroupBox( i18n(
"Description"),
this );
00096 groupBox2->setColumnLayout(0, Qt::Vertical );
00097 groupBox2->layout()->setSpacing( 6 );
00098 groupBox2->layout()->setMargin( 11 );
00099 QVBoxLayout * groupBox2Layout =
new QVBoxLayout( groupBox2->layout() );
00100 groupBox2Layout->setAlignment( Qt::AlignTop );
00101
00102
_pluginDescription =
new QLabel( groupBox2 );
00103
_pluginDescription->setAlignment(
int( QLabel::WordBreak | QLabel::AlignVCenter ) );
00104
00105
_urlLabel =
new KURLLabel( groupBox2 );
00106
00107 groupBox2Layout->addWidget(
_pluginDescription );
00108 groupBox2Layout->addWidget(
_urlLabel );
00109
00110 layout->addWidget( groupBox2 );
00111
00112 connect(
_pluginList, SIGNAL( selectionChanged(
QListViewItem * ) ),
this, SLOT(
itemSelected(
QListViewItem * ) ) );
00113 connect(
_urlLabel, SIGNAL( leftClickedURL(
const QString & ) ),
this, SLOT(
openURL(
const QString & ) ) );
00114
00115
if (_scope ==
Global)
00116
readGlobalConfig();
00117
else
00118
readProjectConfig();
00119 }
00120
00121
00122 PartSelectWidget::~PartSelectWidget()
00123 {}
00124
00125
00126 void PartSelectWidget::readGlobalConfig()
00127 {
00128 KTrader::OfferList globalOffers = PluginController::pluginServices(
"Global" );
00129
KConfig config( PluginController::getInstance()->currentProfilePath() );
00130 config.
setGroup(
"Plugins");
00131
00132
for (KTrader::OfferList::ConstIterator it = globalOffers.begin(); it != globalOffers.end(); ++it)
00133 {
00134
00135
QString Comment = (*it)->comment();
00136
QRegExp re(
"\\bhttp://[\\S]*");
00137 re.search( Comment );
00138 Comment.replace( re,
"" );
00139
00140
QString url;
00141
if ( re.pos() > -1 )
00142 {
00143 url = re.cap();
00144 }
00145
00146
PluginItem *item =
new PluginItem(
_pluginList, (*it)->name(), (*it)->genericName(), Comment, url );
00147 item->setOn(config.
readBoolEntry((*it)->name(),
true));
00148 }
00149
00150
QListViewItem *
first =
_pluginList->firstChild();
00151
if (
first )
00152 {
00153
_pluginList->setSelected(
first,
true );
00154 }
00155 }
00156
00157
00158 void PartSelectWidget::saveGlobalConfig()
00159 {
00160
KConfig config( PluginController::getInstance()->currentProfilePath() );
00161 config.
setGroup(
"Plugins");
00162
00163
QListViewItemIterator it(
_pluginList );
00164
while ( it.current() )
00165 {
00166
PluginItem * item = static_cast<PluginItem*>( it.current() );
00167 config.
writeEntry( item->
name(), item->isOn() );
00168 ++it;
00169 }
00170 }
00171
00172
00173 void PartSelectWidget::readProjectConfig()
00174 {
00175
QStringList ignoreparts = DomUtil::readListEntry(
m_projectDom,
"/general/ignoreparts",
"part");
00176
00177 KTrader::OfferList localOffers = PluginController::pluginServices(
"Project" );
00178
for (KTrader::OfferList::ConstIterator it = localOffers.begin(); it != localOffers.end(); ++it)
00179 {
00180
00181
QString Comment = (*it)->comment();
00182
QRegExp re(
"\\bhttp://[\\S]*");
00183 re.search( Comment );
00184 Comment.replace( re,
"" );
00185
00186
QString url;
00187
if ( re.pos() > -1 )
00188 {
00189 url = re.cap();
00190 }
00191
00192
PluginItem *item =
new PluginItem(
_pluginList, (*it)->name(), (*it)->genericName(), Comment, url );
00193 item->setOn(!ignoreparts.contains((*it)->name()));
00194 }
00195
00196
QListViewItem *
first =
_pluginList->firstChild();
00197
if (
first )
00198 {
00199
_pluginList->setSelected(
first,
true );
00200 }
00201 }
00202
00203 void PartSelectWidget::itemSelected(
QListViewItem * item )
00204 {
00205
if ( ! item )
return;
00206
00207
PluginItem * pitem = static_cast<PluginItem*>( item );
00208
_pluginDescription->setText( pitem->
info() );
00209
00210
if ( pitem->
url().isEmpty() )
00211 {
00212
_urlLabel->hide();
00213 }
00214
else
00215 {
00216
_urlLabel->show();
00217
_urlLabel->
setURL( pitem->
url() );
00218
_urlLabel->setText( pitem->
url() );
00219 }
00220 }
00221
00222 void PartSelectWidget::openURL(
const QString & url )
00223 {
00224 kapp->invokeBrowser( url );
00225 }
00226
00227 void PartSelectWidget::saveProjectConfig()
00228 {
00229
QStringList ignoreparts;
00230
00231
QListViewItemIterator it(
_pluginList );
00232
while ( it.current() )
00233 {
00234
PluginItem * item = static_cast<PluginItem*>( it.current() );
00235
if ( ! item->isOn() )
00236 {
00237 ignoreparts.append( item->
name() );
00238 }
00239 ++it;
00240 }
00241
00242 DomUtil::writeListEntry(
m_projectDom,
"/general/ignoreparts",
"part", ignoreparts);
00243
kdDebug(9000) <<
"xml:" <<
m_projectDom.toString() <<
endl;
00244 }
00245
00246
00247 void PartSelectWidget::accept()
00248 {
00249
if (
_scope ==
Global)
00250
saveGlobalConfig();
00251
else
00252
saveProjectConfig();
00253 emit
accepted();
00254 }
00255
00256
#include "partselectwidget.moc"