korganizer Library API Documentation

plugindialog.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 // Dialog for selecting and configuring KOrganizer plugins
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 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:41:10 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001