00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00059 QObject::connect(fConfigWidget->PushAddPlugin,SIGNAL(clicked()), this, SLOT(slotAddConduit()));
00060 QObject::connect(fConfigWidget->PushConfigure,SIGNAL(clicked()), this, SLOT(slotConfigureConduit()));
00061
00062
00063
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
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
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);
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
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 void JPilotProxyWidgetSetup::commitChanges() {
00186 FUNCTIONSETUP;
00187
00188 if (!fConfig) return;
00189 KConfigGroupSaver s(fConfig, getSettingsGroup());
00190
00191
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
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 void JPilotProxyWidgetSetup::readSettings() {
00210 FUNCTIONSETUP;
00211
00212 if (!fConfig) {
00213 DEBUGCONDUIT << fname << ": !fConfig..." << endl;
00214 return;
00215 }
00216
00217
00218
00219 KConfigGroupSaver s(fConfig, getSettingsGroup());
00220 QStringList plugpathes=fConfig->readListEntry(JPilotProxyConduitFactory::PluginPathes);
00221 fConfigWidget->ListPluginPathes->insertStringList(plugpathes);
00222
00223
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