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 00037 #include "kocore.h" 00038 #include "koprefs.h" 00039 #include "calendarview.h" 00040 00041 #include "plugindialog.h" 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 00060 PluginDialog::PluginDialog( QWidget *parent ) 00061 : KDialogBase( Plain, i18n("Configure Plugins"), Ok | Cancel | User1, Ok, 00062 parent, 0, false, false, KGuiItem( i18n("Configure..."), "configure") ) 00063 { 00064 QFrame *topFrame = plainPage(); 00065 QVBoxLayout *topLayout = new QVBoxLayout( topFrame, 0, spacingHint() ); 00066 00067 mListView = new QListView( topFrame ); 00068 mListView->addColumn( i18n("Name") ); 00069 topLayout->addWidget( mListView ); 00070 00071 buildList(); 00072 00073 connect( mListView, SIGNAL( selectionChanged( QListViewItem* ) ), 00074 this, SLOT( selectionChanged( QListViewItem* ) ) ); 00075 00076 connect( this, SIGNAL( user1Clicked() ),SLOT( configure() ) ); 00077 00078 mMainView = dynamic_cast<CalendarView *>( parent ); 00079 00080 selectionChanged( 0 ); 00081 } 00082 00083 PluginDialog::~PluginDialog() 00084 { 00085 } 00086 00087 void PluginDialog::slotCancel() 00088 { 00089 buildList(); 00090 reject(); 00091 } 00092 00093 void PluginDialog::buildList() 00094 { 00095 mListView->clear(); 00096 KTrader::OfferList plugins = KOCore::self()->availablePlugins(); 00097 plugins += KOCore::self()->availableParts(); 00098 00099 QStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins; 00100 00101 KTrader::OfferList::ConstIterator it; 00102 for( it = plugins.begin(); it != plugins.end(); ++it ) { 00103 QCheckListItem *item = new PluginItem( mListView, *it ); 00104 if ( selectedPlugins.find( (*it)->desktopEntryName() ) != 00105 selectedPlugins.end() ) { 00106 item->setOn( true ); 00107 } 00108 } 00109 } 00110 00111 void PluginDialog::slotOk() 00112 { 00113 QStringList selectedPlugins; 00114 00115 PluginItem *item = static_cast<PluginItem *>( mListView->firstChild() ); 00116 while( item ) { 00117 if( item->isOn() ) { 00118 selectedPlugins.append( item->service()->desktopEntryName() ); 00119 } 00120 item = static_cast<PluginItem *>( item->nextSibling() ); 00121 } 00122 00123 KOPrefs::instance()->mSelectedPlugins = selectedPlugins; 00124 emit configChanged(); 00125 if ( mMainView ) mMainView->updateView(); 00126 00127 accept(); 00128 } 00129 00130 void PluginDialog::configure() 00131 { 00132 PluginItem *item = static_cast<PluginItem *>( mListView->selectedItem() ); 00133 if ( !item ) return; 00134 00135 KOrg::Plugin *plugin = KOCore::self()->loadPlugin( item->service() ); 00136 00137 if ( plugin ) { 00138 plugin->configure( this ); 00139 delete plugin; 00140 } else { 00141 KMessageBox::sorry( this, i18n( "Unable to configure this plugin" ) ); 00142 } 00143 } 00144 00145 void PluginDialog::selectionChanged( QListViewItem *i ) 00146 { 00147 PluginItem *item = dynamic_cast<PluginItem*>( i ); 00148 if ( !item ) { 00149 enableButton( User1, false ); 00150 return; 00151 } 00152 00153 QVariant variant = item->service()->property( "X-KDE-KOrganizer-HasSettings" ); 00154 00155 bool hasSettings = true; 00156 if ( variant.isValid() ) 00157 hasSettings = variant.toBool(); 00158 00159 enableButton( User1, hasSettings ); 00160 } 00161 00162 #include "plugindialog.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:53:27 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003