kpilot Library API Documentation

JPilotProxy-setup.cc

00001 /* JPilotProxy-setup.cc                        KPilot
00002 **
00003 ** Copyright (C) 2001 by Dan Pilone
00004 ** Copyright (C) 2002 by Reinhold Kainhofer
00005 **
00006 ** This file defines the factory for the JPilotProxy-conduit plugin.
00007 */
00008 
00009 /*
00010 ** This program is free software; you can redistribute it and/or modify
00011 ** it under the terms of the GNU General Public License as published by
00012 ** the Free Software Foundation; either version 2 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 ** GNU General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU General Public License
00021 ** along with this program in a file called COPYING; if not, write to
00022 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 ** MA 02111-1307, USA.
00024 */
00025 
00026 /*
00027 ** Bug reports and questions can be sent to kde-pim@kde.org
00028 */
00029 
00030 #include "options.h"
00031 
00032 #include <qbuttongroup.h>
00033 #include <qlineedit.h>
00034 #include <qlistview.h>
00035 #include <qpushbutton.h>
00036 
00037 #include <kconfig.h>
00038 #include <klistview.h>
00039 #include <kfiledialog.h>
00040 #include <kmessagebox.h>
00041 
00042 #include "JPilotProxy-conduit.h"
00043 #include "JPilotProxy-factory.h"
00044 #include "JPilotProxy-setup.moc"
00045 
00046 
00047 
00048 JPilotProxyWidgetSetup::JPilotProxyWidgetSetup(QWidget *w, const char *n,
00049         const QStringList & a) : ConduitConfig(w,n,a) {
00050         FUNCTIONSETUP;
00051 
00052         fConfigWidget = new JPilotProxyWidget(widget());
00053         setTabWidget(fConfigWidget->tabWidget);
00054         addAboutPage(false, JPilotProxyConduitFactory::fAbout);
00055         
00056 
00057         QObject::connect(fConfigWidget->ListPlugins, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(slotConfigureConduit(QListViewItem*)));
00058 //      QObject::connect(fConfigWidget->ListPlugins, SIGNAL(doubleClicked()), this, SLOT(slotConfigureConduit()));
00059         QObject::connect(fConfigWidget->PushAddPlugin,SIGNAL(clicked()), this, SLOT(slotAddConduit()));
00060         QObject::connect(fConfigWidget->PushConfigure,SIGNAL(clicked()), this, SLOT(slotConfigureConduit()));
00061         
00062 //      QObject::connect(fConfigWidget->ListPluginPathes, SIGNAL(selected(QListBoxItem*)), this, SLOT(slotBrowse(QListBoxItem*)));
00063 //      QObject::connect(fConfigWidget->ListPluginPathes, SIGNAL(selectionChanged(QListBoxItem*)), this, SLOT(slotSelectPluginPath(QListBoxItem*)));
00064         QObject::connect(fConfigWidget->ListPluginPathes, SIGNAL(selectionChanged()), this, SLOT(slotSelectPluginPath()));
00065         QObject::connect(fConfigWidget->DirEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotUpdatePluginPath(const QString&)));
00066         QObject::connect(fConfigWidget->BrowseButton, SIGNAL(clicked()), this, SLOT(slotBrowse()));
00067         
00068         QObject::connect(fConfigWidget->AddButton, SIGNAL(clicked()), this, SLOT(slotAddPluginPath()));
00069         QObject::connect(fConfigWidget->RemoveButton, SIGNAL(clicked()), this, SLOT(slotRemovePluginPath()));
00070         fConfigWidget->SearchPluginsButton->setEnabled(false);
00071 //      QObject::connect(fConfigWidget->SearchPluginsButton, SIGNAL(clicked()), this, SLOT(slotScanPluginPathes()));
00072         updatePluginPathSel=true;
00073 }
00074 
00075 JPilotProxyWidgetSetup::~JPilotProxyWidgetSetup() {
00076         FUNCTIONSETUP;
00077 }
00078 
00079 void JPilotProxyWidgetSetup::slotOk() {
00080         FUNCTIONSETUP;
00081         commitChanges();
00082         ConduitConfig::slotOk();
00083 }
00084 
00085 void JPilotProxyWidgetSetup::slotApply() {
00086         FUNCTIONSETUP;
00087         commitChanges();
00088         ConduitConfig::slotApply();
00089 }
00090 
00091 void JPilotProxyWidgetSetup::slotAddConduit() {
00092         FUNCTIONSETUP;
00093         QString fn=KFileDialog::getOpenFileName(0, i18n("*.so|JPilot plugins\n*.*|All files"), this);
00094         if(fn.isNull()) return;
00095         // TODO: check of the plugin has already been loaded...
00096         if (    addConduit(fn, false)) {
00097                 KMessageBox::sorry(this, i18n("Loading the JPilot plugin failed"));
00098         }
00099 }
00100 
00101 bool JPilotProxyWidgetSetup::addConduit(QString file, bool on) {
00102         JPlugin*newplug=JPilotProxyConduitFactory::addPlugin(file, on);
00103         if (!newplug) return false;
00104         QCheckListItem*plugitem=(QCheckListItem*)new QCheckListItem(fConfigWidget->ListPlugins,
00105                 newplug->info.name, QCheckListItem::CheckBox);
00106         if (newplug->lib) plugitem->setText(1, newplug->info.fullpath);
00107         jp_startup_info si;
00108         si.base_dir="/usr/local/";
00109         newplug->startup(&si);
00110         if (on) plugitem->setOn(on);
00111 }
00112 void JPilotProxyWidgetSetup::slotConfigureConduit() {
00113         FUNCTIONSETUP;
00114         QListViewItem*item=fConfigWidget->ListPlugins->selectedItem();
00115         slotConfigureConduit(item);
00116 }
00117 
00118 JPlugin*JPilotProxyWidgetSetup::findPlugin(QString fn) {
00119         PluginIterator_t it(*JPilotProxyConduitFactory::plugins); // iterator for plugin list
00120         for ( ; it.current(); ++it ) {
00121                 if (it.current()->info.fullpath==fn) return it.current();
00122         }
00123         return NULL;
00124 }
00125 
00126 void JPilotProxyWidgetSetup::slotConfigureConduit(QListViewItem*item) {
00127         FUNCTIONSETUP;
00128         if (!item) return;
00129         
00130         #ifdef DEBUG
00131         DEBUGCONDUIT<<"Configuring conduit "<<item->text(0)<<endl;
00132         #endif
00133         JPlugin*plg=findPlugin(item->text(1));
00134         if (!plg) {
00135                 KMessageBox::sorry(this, i18n("Error finding the plugin in memory."));
00136                 return;
00137         }
00138         if (plg->hasGui()) {
00139                 // TODO: configure the plugin
00140                 KMessageBox::sorry(this, i18n("Configuring JPilot plugins has not yet been implemented. "
00141                         "This would mean embedding a GtkWidget inside a KDE dialog box, so that the whole message "
00142                         "loop of the modal dialog box needs to be rewritten (see QGtkApplication)"));
00143         } else {
00144                 KMessageBox::sorry(this, i18n("This JPilot plugin does not have a configuration dialog"));
00145         }
00146 }
00147 
00148 void JPilotProxyWidgetSetup::slotBrowse() {
00149         FUNCTIONSETUP;
00150         QString oldname=fConfigWidget->DirEdit->text();
00151         QString fn=KFileDialog::getExistingDirectory(oldname, this, i18n("Change Plugin Directory"));
00152         if(fn.isNull()) return;
00153         fConfigWidget->DirEdit->setText(fn);
00154 }
00155 
00156 void JPilotProxyWidgetSetup::slotSelectPluginPath() {
00157         FUNCTIONSETUP;
00158         QString path=fConfigWidget->ListPluginPathes->currentText();
00159         if (! path.isNull()) {
00160                 updatePluginPathSel=false;
00161                 fConfigWidget->DirEdit->setText(path);
00162         }
00163 }
00164 
00165 void JPilotProxyWidgetSetup::slotAddPluginPath() {
00166         FUNCTIONSETUP;
00167         QString fn=KFileDialog::getExistingDirectory(QString::null, this, i18n("Add Plugin Directory"));
00168         if (!fn.isNull()) {
00169                 fConfigWidget->ListPluginPathes->insertItem(fn);
00170                 fConfigWidget->ListPluginPathes->setCurrentItem(-1);
00171         }
00172 }
00173 void JPilotProxyWidgetSetup::slotRemovePluginPath(){ 
00174         FUNCTIONSETUP;
00175         fConfigWidget->ListPluginPathes->removeItem(fConfigWidget->ListPluginPathes->currentItem());
00176 }
00177 
00178 void JPilotProxyWidgetSetup::slotUpdatePluginPath(const QString &newpath) {
00179         FUNCTIONSETUP;
00180         if (updatePluginPathSel) 
00181                 fConfigWidget->ListPluginPathes->changeItem(newpath, fConfigWidget->ListPluginPathes->currentItem());
00182         updatePluginPathSel=true;
00183 }
00184 
00185 /* virtual */ void JPilotProxyWidgetSetup::commitChanges() {
00186         FUNCTIONSETUP;
00187 
00188         if (!fConfig) return;
00189         KConfigGroupSaver s(fConfig, getSettingsGroup());
00190         
00191         // First save the list of plugin pathes
00192         QStringList plugpathes;
00193         for (int i=0; i<fConfigWidget->ListPluginPathes->count(); i++) {
00194                 plugpathes<<fConfigWidget->ListPluginPathes->text(i);
00195         }
00196         fConfig->writeEntry(JPilotProxyConduitFactory::PluginPathes, plugpathes);
00197 
00198         // now save the list of all loaded/found plugins
00199         QStringList pluginfiles;
00200         QListViewItem *item=fConfigWidget->ListPlugins->firstChild();
00201         while (item) {
00202                 pluginfiles << item->text(1);
00203                 fConfig->writeEntry(item->text(1), (dynamic_cast<QCheckListItem*>(item))->isOn());
00204                 item=item->nextSibling();
00205         }
00206         fConfig->writeEntry(JPilotProxyConduitFactory::LoadedPlugins, pluginfiles);
00207 }
00208 
00209 /* virtual */ void JPilotProxyWidgetSetup::readSettings() {
00210         FUNCTIONSETUP;
00211 
00212         if (!fConfig) {
00213                 DEBUGCONDUIT << fname << ": !fConfig..." << endl;
00214                 return;
00215         }
00216 //TODO: Activate:
00217 //      JPilotProxyConduitFactory::loadPlugins(fConfig);
00218 
00219         KConfigGroupSaver s(fConfig, getSettingsGroup());
00220         QStringList plugpathes=fConfig->readListEntry(JPilotProxyConduitFactory::PluginPathes);
00221         fConfigWidget->ListPluginPathes->insertStringList(plugpathes);
00222         
00223         // TODO: Use the plugin list? or use the list stored in the config?
00224         QStringList pluginfiles=fConfig->readListEntry(JPilotProxyConduitFactory::LoadedPlugins);
00225         for (QStringList::Iterator it = pluginfiles.begin(); it != pluginfiles.end(); ++it ) {
00226                 addConduit(*it, fConfig->readBoolEntry(*it));
00227         }
00228 }
00229 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:14 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001