kpilot Library API Documentation

JPilotProxy-setup.cc

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