plugindialog.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <qlayout.h>
00027 #include <qcheckbox.h>
00028 #include <qgroupbox.h>
00029 #include <qlabel.h>
00030 #include <qlineedit.h>
00031 #include <qlistview.h>
00032
00033 #include <klocale.h>
00034 #include <kmessagebox.h>
00035 #include <ktrader.h>
00036
00037 #include "kocore.h"
00038 #include "koprefs.h"
00039
00040 #include "plugindialog.h"
00041 #include "plugindialog.moc"
00042
00043 class PluginItem : public QCheckListItem {
00044 public:
00045 PluginItem( QListView *parent, KService::Ptr service ) :
00046 QCheckListItem( parent, service->name(), QCheckListItem::CheckBox ), mService( service )
00047 {
00048 }
00049
00050 KService::Ptr service() { return mService; }
00051
00052 private:
00053 KService::Ptr mService;
00054 };
00055
00056
00057 PluginDialog::PluginDialog(QWidget *parent)
00058 : KDialogBase(Plain,i18n("Configure Plugins"),Ok|Cancel|User1,Ok,parent,0,false,false,
00059 i18n("Configure..."))
00060 {
00061 QFrame *topFrame = plainPage();
00062 QVBoxLayout *topLayout = new QVBoxLayout(topFrame,0,spacingHint());
00063
00064 mListView = new QListView(topFrame);
00065 mListView->addColumn(i18n("Name"));
00066 topLayout->addWidget(mListView);
00067 connect(mListView,SIGNAL(selectionChanged()),SLOT(checkSelection()));
00068
00069 KTrader::OfferList plugins = KOCore::self()->availablePlugins("Calendar/Plugin");
00070 plugins += KOCore::self()->availablePlugins("KOrganizer/Part");
00071
00072 QStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins;
00073
00074 KTrader::OfferList::ConstIterator it;
00075 for(it = plugins.begin(); it != plugins.end(); ++it) {
00076 QCheckListItem *item = new PluginItem(mListView,*it);
00077 if ( selectedPlugins.find((*it)->desktopEntryName()) != selectedPlugins.end() ) {
00078 item->setOn(true);
00079 }
00080 }
00081
00082 checkSelection();
00083
00084 connect(this,SIGNAL(user1Clicked()),SLOT(configure()));
00085 mMainView = dynamic_cast<CalendarView *>(parent);
00086 }
00087
00088 PluginDialog::~PluginDialog()
00089 {
00090 }
00091
00092 void PluginDialog::slotOk()
00093 {
00094 QStringList selectedPlugins;
00095
00096 PluginItem *item = (PluginItem *)mListView->firstChild();
00097 while(item) {
00098 if(item->isOn()) {
00099 selectedPlugins.append(item->service()->desktopEntryName());
00100 }
00101 item = (PluginItem *)item->nextSibling();
00102 }
00103
00104 KOPrefs::instance()->mSelectedPlugins = selectedPlugins;
00105 emit configChanged();
00106 if ( mMainView ) mMainView->updateView();
00107
00108 accept();
00109
00110 }
00111
00112 void PluginDialog::configure()
00113 {
00114 PluginItem *item = (PluginItem *)mListView->selectedItem();
00115 if ( !item ) return;
00116
00117 KOrg::Plugin *plugin = KOCore::self()->loadPlugin( item->service() );
00118
00119 if ( plugin ) {
00120 plugin->configure( this );
00121 delete plugin;
00122 } else {
00123 KMessageBox::sorry( this, i18n( "Unable to configure this plugin" ) );
00124 }
00125
00126 }
00127
00128 void PluginDialog::checkSelection()
00129 {
00130 if (mListView->selectedItem()) {
00131 enableButton(User1,true);
00132 } else {
00133 enableButton(User1,false);
00134 }
00135 }
This file is part of the documentation for kdelibs Version 3.1.5.