korganizer Library API Documentation

plugindialog.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of Qt, and distribute the resulting executable, 00022 without including the source code for Qt in the source distribution. 00023 */ 00024 00025 #include <qlayout.h> 00026 #include <qcheckbox.h> 00027 #include <qgroupbox.h> 00028 #include <qlabel.h> 00029 #include <qlineedit.h> 00030 #include <qlistview.h> 00031 00032 #include <klocale.h> 00033 #include <kmessagebox.h> 00034 #include <ktrader.h> 00035 00036 #include "kocore.h" 00037 #include "koprefs.h" 00038 00039 #include "plugindialog.h" 00040 00041 class PluginItem : public QCheckListItem { 00042 public: 00043 PluginItem( QListView *parent, KService::Ptr service ) : 00044 QCheckListItem( parent, service->name(), QCheckListItem::CheckBox ), mService( service ) 00045 { 00046 } 00047 00048 KService::Ptr service() { return mService; } 00049 00050 private: 00051 KService::Ptr mService; 00052 }; 00053 00054 00058 PluginDialog::PluginDialog( QWidget *parent ) 00059 : KDialogBase( Plain, i18n("Configure Plugins"), Ok | Cancel | User1, Ok, 00060 parent, 0, false, false, KGuiItem( i18n("Configure..."), "configure") ) 00061 { 00062 QFrame *topFrame = plainPage(); 00063 QVBoxLayout *topLayout = new QVBoxLayout( topFrame, 0, spacingHint() ); 00064 00065 mListView = new QListView( topFrame ); 00066 mListView->addColumn( i18n("Name") ); 00067 topLayout->addWidget( mListView ); 00068 00069 buildList(); 00070 00071 connect( mListView, SIGNAL( selectionChanged( QListViewItem* ) ), 00072 this, SLOT( selectionChanged( QListViewItem* ) ) ); 00073 00074 connect( this, SIGNAL( user1Clicked() ),SLOT( configure() ) ); 00075 00076 mMainView = dynamic_cast<CalendarView *>( parent ); 00077 00078 selectionChanged( 0 ); 00079 } 00080 00081 PluginDialog::~PluginDialog() 00082 { 00083 } 00084 00085 void PluginDialog::slotCancel() 00086 { 00087 buildList(); 00088 reject(); 00089 } 00090 00091 void PluginDialog::buildList() 00092 { 00093 mListView->clear(); 00094 KTrader::OfferList plugins = KOCore::self()->availablePlugins(); 00095 plugins += KOCore::self()->availableParts(); 00096 00097 QStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins; 00098 00099 KTrader::OfferList::ConstIterator it; 00100 for( it = plugins.begin(); it != plugins.end(); ++it ) { 00101 QCheckListItem *item = new PluginItem( mListView, *it ); 00102 if ( selectedPlugins.find( (*it)->desktopEntryName() ) != 00103 selectedPlugins.end() ) { 00104 item->setOn( true ); 00105 } 00106 } 00107 } 00108 00109 void PluginDialog::slotOk() 00110 { 00111 QStringList selectedPlugins; 00112 00113 PluginItem *item = static_cast<PluginItem *>( mListView->firstChild() ); 00114 while( item ) { 00115 if( item->isOn() ) { 00116 selectedPlugins.append( item->service()->desktopEntryName() ); 00117 } 00118 item = static_cast<PluginItem *>( item->nextSibling() ); 00119 } 00120 00121 KOPrefs::instance()->mSelectedPlugins = selectedPlugins; 00122 emit configChanged(); 00123 if ( mMainView ) mMainView->updateView(); 00124 00125 accept(); 00126 } 00127 00128 void PluginDialog::configure() 00129 { 00130 PluginItem *item = static_cast<PluginItem *>( mListView->selectedItem() ); 00131 if ( !item ) return; 00132 00133 KOrg::Plugin *plugin = KOCore::self()->loadPlugin( item->service() ); 00134 00135 if ( plugin ) { 00136 plugin->configure( this ); 00137 delete plugin; 00138 } else { 00139 KMessageBox::sorry( this, i18n( "Unable to configure this plugin" ) ); 00140 } 00141 } 00142 00143 void PluginDialog::selectionChanged( QListViewItem *i ) 00144 { 00145 PluginItem *item = dynamic_cast<PluginItem*>( i ); 00146 if ( !item ) { 00147 enableButton( User1, false ); 00148 return; 00149 } 00150 00151 QVariant variant = item->service()->property( "X-KDE-KOrganizer-HasSettings" ); 00152 00153 bool hasSettings = true; 00154 if ( variant.isValid() ) 00155 hasSettings = variant.toBool(); 00156 00157 enableButton( User1, hasSettings ); 00158 } 00159 00160 #include "plugindialog.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:14 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003