kpilot/kpilot

kpilotConfigDialog.cc

00001 /* KPilot
00002 **
00003 ** Copyright (C) 2001 by Dan Pilone
00004 ** Copyright (C) 2002-2004 by Adriaan de Groot
00005 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 **
00007 ** This file defines a specialization of KPilotDeviceLink
00008 ** that can actually handle some HotSync tasks, like backup
00009 ** and restore. It does NOT do conduit stuff.
00010 */
00011 
00012 /*
00013 ** This program is free software; you can redistribute it and/or modify
00014 ** it under the terms of the GNU General Public License as published by
00015 ** the Free Software Foundation; either version 2 of the License, or
00016 ** (at your option) any later version.
00017 **
00018 ** This program is distributed in the hope that it will be useful,
00019 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00021 ** GNU General Public License for more details.
00022 **
00023 ** You should have received a copy of the GNU General Public License
00024 ** along with this program in a file called COPYING; if not, write to
00025 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00026 ** MA 02110-1301, USA.
00027 */
00028 
00029 /*
00030 ** Bug reports and questions can be sent to kde-pim@kde.org
00031 */
00032 
00033 #include "options.h"
00034 
00035 #include <pi-version.h>
00036 
00037 #include <qcombobox.h>
00038 #include <qcheckbox.h>
00039 #include <qradiobutton.h>
00040 #include <qpushbutton.h>
00041 #include <qbuttongroup.h>
00042 #include <qlineedit.h>
00043 #include <qtabwidget.h>
00044 #include <qspinbox.h>
00045 #include <qfile.h>
00046 
00047 #include <kmessagebox.h>
00048 #include <kcharsets.h>
00049 #include <kstandarddirs.h>
00050 #include <kglobal.h>
00051 #include <kurl.h>
00052 #include <kio/netaccess.h>
00053 
00054 #include "kpilotConfig.h"
00055 #include "kpilotSettings.h"
00056 
00057 #include "kpilotConfigDialog_device.h"
00058 #include "kpilotConfigDialog_sync.h"
00059 #include "kpilotConfigDialog_startup.h"
00060 #include "kpilotConfigDialog_viewers.h"
00061 #include "kpilotConfigDialog_backup.h"
00062 #include "kpilotConfigDialog.moc"
00063 #include "syncAction.h"
00064 #include "dbSelectionDialog.h"
00065 
00066 /* virtual */ QString ConfigPage::maybeSaveText() const
00067 {
00068     return i18n("<qt>The settings for configuration page <i>%1</i> have been changed. Do you "
00069         "want to save the changes before continuing?</qt>").arg(this->conduitName());
00070 }
00071 
00072 DeviceConfigPage::DeviceConfigPage(QWidget * w, const char *n ) : ConfigPage( w, n )
00073 {
00074     FUNCTIONSETUP;
00075 
00076     fConfigWidget = new DeviceConfigWidget( w );
00077     // Fill the encodings list
00078     {
00079         QStringList l = KGlobal::charsets()->descriptiveEncodingNames();
00080         for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it )
00081         {
00082             fConfigWidget->fPilotEncoding->insertItem(*it);
00083         }
00084     }
00085 
00086     fConfigWidget->resize(fConfigWidget->size());
00087     fWidget = fConfigWidget;
00088 
00089 #if PILOT_LINK_NUMBER < PILOT_LINK_0_10_0
00090     fConfigWidget->fPilotDevice->setMaxLength(13);
00091 #endif
00092 
00093 
00094 #define CM(a,b) connect(fConfigWidget->a,b,this,SLOT(modified()));
00095     CM(fPilotDevice, SIGNAL(textChanged(const QString &)));
00096     CM(fPilotSpeed, SIGNAL(activated(int)));
00097     CM(fPilotEncoding, SIGNAL(textChanged(const QString &)));
00098     CM(fUserName, SIGNAL(textChanged(const QString &)));
00099     CM(fWorkaround, SIGNAL(activated(int)));
00100 #undef CM
00101 
00102     fConduitName = i18n("Device");
00103 }
00104 
00105 void DeviceConfigPage::load()
00106 {
00107     FUNCTIONSETUP;
00108     KPilotSettings::self()->readConfig();
00109 
00110     /* General tab in the setup dialog */
00111     fConfigWidget->fPilotDevice->setText(KPilotSettings::pilotDevice());
00112     fConfigWidget->fPilotSpeed->setCurrentItem(KPilotSettings::pilotSpeed());
00113     getEncoding();
00114     fConfigWidget->fUserName->setText(KPilotSettings::userName());
00115 
00116     switch(KPilotSettings::workarounds())
00117     {
00118     case KPilotSettings::eWorkaroundNone :
00119         fConfigWidget->fWorkaround->setCurrentItem(0);
00120         break;
00121     case KPilotSettings::eWorkaroundUSB :
00122         fConfigWidget->fWorkaround->setCurrentItem(1);
00123         break;
00124     default:
00125         kdWarning() << k_funcinfo
00126             << ": Unknown workaround number "
00127             << (int) KPilotSettings::workarounds()
00128             << endl;
00129         KPilotSettings::setWorkarounds(KPilotSettings::eWorkaroundNone);
00130         fConfigWidget->fWorkaround->setCurrentItem(0);
00131     }
00132     unmodified();
00133 }
00134 
00135 /* virtual */ bool DeviceConfigPage::validate()
00136 {
00137     int r = KMessageBox::Yes;
00138 
00139 #if PILOT_LINK_NUMBER < PILOT_LINK_0_10_0
00140     QString d = fConfigWidget->fPilotDevice->text();
00141 
00142     if (d.length() > 13)
00143     {
00144     r = KMessageBox::questionYesNo(
00145         fConfigWidget,
00146         i18n("<qt>The device name you entered (<i>%1</i>) "
00147             "is longer than 13 characters. This is "
00148             "probably unsupported and can cause problems. "
00149             "Are you sure you want to use this device name?</qt>")
00150             .arg(d),
00151         i18n("Device Name too Long"), i18n("Use"), i18n("Do Not Use")
00152         ) ;
00153     }
00154 #endif
00155 
00156     return KMessageBox::Yes == r;
00157 }
00158 
00159 /* virtual */ void DeviceConfigPage::commit()
00160 {
00161     FUNCTIONSETUP;
00162 
00163     // General page
00164     KPilotSettings::setPilotDevice(fConfigWidget->fPilotDevice->text());
00165     KPilotSettings::setPilotSpeed(fConfigWidget->fPilotSpeed->currentItem());
00166     setEncoding();
00167     KPilotSettings::setUserName(fConfigWidget->fUserName->text());
00168 
00169     switch(fConfigWidget->fWorkaround->currentItem())
00170     {
00171     case 0 : KPilotSettings::setWorkarounds(KPilotSettings::eWorkaroundNone); break;
00172     case 1 : KPilotSettings::setWorkarounds(KPilotSettings::eWorkaroundUSB); break;
00173     default :
00174         kdWarning() << k_funcinfo
00175             << ": Unknown workaround number "
00176             << fConfigWidget->fWorkaround->currentItem()
00177             << endl;
00178         KPilotSettings::setWorkarounds(KPilotSettings::eWorkaroundNone);
00179 
00180     }
00181     KPilotConfig::updateConfigVersion();
00182     KPilotSettings::self()->writeConfig();
00183     unmodified();
00184 }
00185 
00186 /* slot */ void DeviceConfigPage::changePortType(int i)
00187 {
00188     FUNCTIONSETUP;
00189 
00190     switch (i)
00191     {
00192     case 0:
00193         fConfigWidget->fPilotSpeed->setEnabled(true);
00194         break;
00195     case 1:
00196     case 2:
00197         fConfigWidget->fPilotSpeed->setEnabled(false);
00198         break;
00199     default:
00200         kdWarning() << k_funcinfo
00201             << ": Unknown port type " << i << endl;
00202     }
00203 }
00204 
00205 void DeviceConfigPage::getEncoding()
00206 {
00207     FUNCTIONSETUP;
00208     QString e = KPilotSettings::encoding();
00209     if (e.isEmpty())
00210         fConfigWidget->fPilotEncoding->setCurrentText(CSL1("ISO8859-15"));
00211     else
00212         fConfigWidget->fPilotEncoding->setCurrentText(e);
00213 }
00214 
00215 void DeviceConfigPage::setEncoding()
00216 {
00217     FUNCTIONSETUP;
00218 
00219     QString enc = fConfigWidget->fPilotEncoding->currentText();
00220     if (enc.isEmpty())
00221     {
00222         kdWarning() << k_funcinfo << "Empty encoding. Will ignore it"<<endl;
00223     }
00224     else
00225     {
00226         KPilotSettings::setEncoding(enc);
00227     }
00228 }
00229 
00230 SyncConfigPage::SyncConfigPage(QWidget * w, const char *n ) : ConfigPage( w, n )
00231 {
00232     FUNCTIONSETUP;
00233 
00234     fConfigWidget = new SyncConfigWidget( w );
00235     fConfigWidget->resize(fConfigWidget->size());
00236     fWidget = fConfigWidget;
00237 
00238 #define CM(a,b) connect(fConfigWidget->a,b,this,SLOT(modified()));
00239     CM(fSpecialSync, SIGNAL(activated(int)));
00240     CM(fFullSyncCheck, SIGNAL(toggled(bool)));
00241     CM(fScreenlockSecure, SIGNAL(toggled(bool)));
00242     CM(fConflictResolution, SIGNAL(activated(int)));
00243 #undef CM
00244 
00245     fConduitName = i18n("HotSync");
00246 }
00247 
00248 #define MENU_ITEM_COUNT (4)
00249 static SyncAction::SyncMode::Mode syncTypeMap[MENU_ITEM_COUNT] = {
00250     SyncAction::SyncMode::eHotSync,
00251     SyncAction::SyncMode::eFullSync,
00252     SyncAction::SyncMode::eCopyPCToHH,
00253     SyncAction::SyncMode::eCopyHHToPC
00254     } ;
00255 
00256 void SyncConfigPage::load()
00257 {
00258     FUNCTIONSETUP;
00259     KPilotSettings::self()->readConfig();
00260 
00261     /* Sync tab */
00262     int synctype=KPilotSettings::syncType();
00263     if (synctype<0) synctype=(int) SyncAction::SyncMode::eHotSync;
00264     for (unsigned int i=0; i<MENU_ITEM_COUNT; ++i)
00265     {
00266         if (syncTypeMap[i] == synctype)
00267         {
00268             fConfigWidget->fSpecialSync->setCurrentItem(i);
00269             synctype=-1;
00270             break;
00271         }
00272     }
00273     if (synctype != -1)
00274     {
00275         fConfigWidget->fSpecialSync->setCurrentItem(0); /* HotSync */
00276     }
00277 
00278     fConfigWidget->fFullSyncCheck->setChecked(KPilotSettings::fullSyncOnPCChange());
00279     fConfigWidget->fConflictResolution->setCurrentItem(KPilotSettings::conflictResolution());
00280     fConfigWidget->fScreenlockSecure->setChecked(KPilotSettings::screenlockSecure());
00281 
00282     unmodified();
00283 }
00284 
00285 /* virtual */ void SyncConfigPage::commit()
00286 {
00287     FUNCTIONSETUP;
00288 
00289     /* Sync tab */
00290     int synctype = -1;
00291     unsigned int selectedsync = fConfigWidget->fSpecialSync->currentItem();
00292     if (selectedsync < MENU_ITEM_COUNT)
00293     {
00294         synctype = syncTypeMap[selectedsync];
00295     }
00296     if (synctype < 0)
00297     {
00298         synctype = SyncAction::SyncMode::eHotSync;
00299     }
00300 
00301     KPilotSettings::setSyncType(synctype);
00302     KPilotSettings::setFullSyncOnPCChange(fConfigWidget->fFullSyncCheck->isChecked());
00303     KPilotSettings::setConflictResolution(fConfigWidget->fConflictResolution->currentItem());
00304     KPilotSettings::setScreenlockSecure(fConfigWidget->fScreenlockSecure->isChecked());
00305 
00306     KPilotConfig::updateConfigVersion();
00307     KPilotSettings::self()->writeConfig();
00308     unmodified();
00309 }
00310 
00311 
00312 BackupConfigPage::BackupConfigPage(QWidget * w, const char *n ) : ConfigPage( w, n )
00313 {
00314     FUNCTIONSETUP;
00315 
00316     fConfigWidget = new BackupConfigWidget( w );
00317     fConfigWidget->resize(fConfigWidget->size());
00318     fWidget = fConfigWidget;
00319 
00320     connect(fConfigWidget->fBackupOnlyChooser, SIGNAL( clicked() ),
00321         SLOT( slotSelectNoBackupDBs() ) );
00322     connect(fConfigWidget->fSkipDBChooser, SIGNAL(clicked()),
00323         SLOT(slotSelectNoRestoreDBs()));
00324 
00325 #define CM(a,b) connect(fConfigWidget->a,b,this,SLOT(modified()));
00326     CM(fBackupOnly, SIGNAL(textChanged(const QString &)));
00327     CM(fSkipDB, SIGNAL(textChanged(const QString &)));
00328     CM(fBackupFrequency, SIGNAL(activated(int)));
00329 #undef CM
00330 
00331     fConduitName = i18n("Backup");
00332 }
00333 
00334 void BackupConfigPage::load()
00335 {
00336     FUNCTIONSETUP;
00337     KPilotSettings::self()->readConfig();
00338 
00339     /* Backup tab */
00340     fConfigWidget->fBackupOnly->setText(KPilotSettings::skipBackupDB().join(CSL1(",")));
00341     fConfigWidget->fSkipDB->setText(KPilotSettings::skipRestoreDB().join(CSL1(",")));
00342     fConfigWidget->fRunConduitsWithBackup->setChecked(KPilotSettings::runConduitsWithBackup());
00343 
00344     int backupfreq=KPilotSettings::backupFrequency();
00345 
00346     fConfigWidget->fBackupFrequency->setCurrentItem(backupfreq);
00347 
00348     unmodified();
00349 }
00350 
00351 /* virtual */ void BackupConfigPage::commit()
00352 {
00353     FUNCTIONSETUP;
00354 
00355     /* Backup tab */
00356     KPilotSettings::setSkipBackupDB(
00357         QStringList::split(CSL1(","),fConfigWidget->fBackupOnly->text()));
00358     KPilotSettings::setSkipRestoreDB(
00359         QStringList::split(CSL1(","),fConfigWidget->fSkipDB->text()));
00360     KPilotSettings::setRunConduitsWithBackup(fConfigWidget->fRunConduitsWithBackup->isChecked());
00361     KPilotSettings::setBackupFrequency(fConfigWidget->fBackupFrequency->currentItem());
00362 
00363     KPilotConfig::updateConfigVersion();
00364     KPilotSettings::self()->writeConfig();
00365     unmodified();
00366 }
00367 
00368 void BackupConfigPage::slotSelectNoBackupDBs()
00369 {
00370     FUNCTIONSETUP;
00371 
00372     QStringList selectedDBs(QStringList::split(',', fConfigWidget->fBackupOnly->text() ));
00373 
00374     QStringList deviceDBs=KPilotSettings::deviceDBs();
00375     QStringList addedDBs=KPilotSettings::addedDBs();
00376     KPilotDBSelectionDialog*dlg=new KPilotDBSelectionDialog(selectedDBs, deviceDBs, addedDBs, 0, "NoBackupDBs");
00377     if (dlg && (dlg->exec()==QDialog::Accepted) )
00378     {
00379         fConfigWidget->fBackupOnly->setText(
00380             dlg->getSelectedDBs().join(CSL1(",")));
00381         KPilotSettings::setAddedDBs( dlg->getAddedDBs() );
00382     }
00383     KPILOT_DELETE(dlg);
00384 }
00385 
00386 void BackupConfigPage::slotSelectNoRestoreDBs()
00387 {
00388     FUNCTIONSETUP;
00389 
00390     QStringList selectedDBs(QStringList::split(',', fConfigWidget->fSkipDB->text() ));
00391 
00392     QStringList deviceDBs=KPilotSettings::deviceDBs();
00393     QStringList addedDBs=KPilotSettings::addedDBs();
00394     KPilotDBSelectionDialog*dlg=new KPilotDBSelectionDialog(selectedDBs, deviceDBs, addedDBs, 0, "NoRestoreDBs");
00395     if (dlg && (dlg->exec()==QDialog::Accepted) )
00396     {
00397         fConfigWidget->fSkipDB->setText(
00398             dlg->getSelectedDBs().join(CSL1(",")));
00399         KPilotSettings::setAddedDBs( dlg->getAddedDBs() );
00400     }
00401     KPILOT_DELETE(dlg);
00402 }
00403 
00404 
00405 
00406 ViewersConfigPage::ViewersConfigPage(QWidget * w, const char *n ) : ConfigPage( w, n )
00407 {
00408     FUNCTIONSETUP;
00409 
00410     fConfigWidget = new ViewersConfigWidget( w );
00411     fConfigWidget->resize(fConfigWidget->size());
00412     fWidget = fConfigWidget;
00413 
00414 #define CM(a,b) connect(fConfigWidget->a,b,this,SLOT(modified()));
00415     CM(fInternalEditors, SIGNAL(toggled(bool)));
00416     CM(fUseSecret, SIGNAL(toggled(bool)));
00417     CM(fAddressGroup, SIGNAL(clicked(int)));
00418     CM(fUseKeyField, SIGNAL(toggled(bool)));
00419 #undef CM
00420 
00421     fConduitName = i18n("Viewers");
00422 }
00423 
00424 void ViewersConfigPage::load()
00425 {
00426     FUNCTIONSETUP;
00427     KPilotSettings::self()->readConfig();
00428 
00429     fConfigWidget->fInternalEditors->setChecked( false /* KPilotSettings::internalEditors() */ );
00430     fConfigWidget->fUseSecret->setChecked(KPilotSettings::showSecrets());
00431     fConfigWidget->fAddressGroup->setButton(KPilotSettings::addressDisplayMode());
00432     fConfigWidget->fUseKeyField->setChecked(KPilotSettings::useKeyField());
00433     unmodified();
00434 }
00435 
00436 /* virtual */ void ViewersConfigPage::commit()
00437 {
00438     FUNCTIONSETUP;
00439 
00440     KPilotSettings::setInternalEditors( fConfigWidget->fInternalEditors->isChecked());
00441     KPilotSettings::setShowSecrets(fConfigWidget->fUseSecret->isChecked());
00442     KPilotSettings::setAddressDisplayMode(fConfigWidget->fAddressGroup->id(
00443         fConfigWidget->fAddressGroup->selected()));
00444     KPilotSettings::setUseKeyField(fConfigWidget->fUseKeyField->isChecked());
00445     KPilotConfig::updateConfigVersion();
00446     KPilotSettings::self()->writeConfig();
00447     unmodified();
00448 }
00449 
00450 
00451 
00452 
00453 
00454 
00455 
00456 
00457 
00458 StartExitConfigPage::StartExitConfigPage(QWidget * w, const char *n ) : ConfigPage( w, n )
00459 {
00460     FUNCTIONSETUP;
00461 
00462     fConfigWidget = new StartExitConfigWidget( w );
00463     fConfigWidget->resize(fConfigWidget->size());
00464     fWidget = fConfigWidget;
00465 
00466 #define CM(a,b) connect(fConfigWidget->a,b,this,SLOT(modified()));
00467     CM(fStartDaemonAtLogin, SIGNAL(toggled(bool)));
00468     CM(fKillDaemonOnExit, SIGNAL(toggled(bool)));
00469     CM(fDockDaemon, SIGNAL(toggled(bool)));
00470     CM(fQuitAfterSync, SIGNAL(toggled(bool)));
00471 #undef CM
00472 
00473     fConduitName = i18n("Startup and Exit");
00474 }
00475 
00476 void StartExitConfigPage::load()
00477 {
00478     FUNCTIONSETUP;
00479     KPilotSettings::self()->readConfig();
00480 
00481     fConfigWidget->fStartDaemonAtLogin->setChecked(KPilotSettings::startDaemonAtLogin());
00482     fConfigWidget->fDockDaemon->setChecked(KPilotSettings::dockDaemon());
00483     fConfigWidget->fKillDaemonOnExit->setChecked(KPilotSettings::killDaemonAtExit());
00484     fConfigWidget->fQuitAfterSync->setChecked(KPilotSettings::quitAfterSync());
00485     unmodified();
00486 }
00487 
00488 
00489 /* virtual */ void StartExitConfigPage::commit()
00490 {
00491     FUNCTIONSETUP;
00492 
00493     QString autostart = KGlobalSettings::autostartPath();
00494     QString desktopfile = CSL1("kpilotdaemon.desktop");
00495     QString desktopcategory = CSL1("kde/");
00496     QString location = KGlobal::dirs()->findResource("xdgdata-apps",desktopcategory + desktopfile);
00497     if (location.isEmpty()) // Fallback to KDE 3.0?
00498     {
00499         location = KGlobal::dirs()->findResource("apps",desktopfile);
00500     }
00501 
00502 #ifdef DEBUG
00503     DEBUGKPILOT << fname << ": Autostart=" << autostart << endl;
00504     DEBUGKPILOT << fname << ": desktop=" << desktopfile << endl;
00505     DEBUGKPILOT << fname << ": location=" << location << endl;
00506 #endif
00507 
00508     KPilotSettings::setStartDaemonAtLogin(fConfigWidget->fStartDaemonAtLogin->isChecked());
00509     if (KPilotSettings::startDaemonAtLogin())
00510     {
00511         if (!location.isEmpty())
00512         {
00513             KURL src;
00514             src.setPath(location);
00515             KURL dst;
00516             dst.setPath(autostart+desktopfile);
00517             KIO::NetAccess::file_copy(src,dst,-1 /* 0666? */,true /* overwrite */);
00518         }
00519     }
00520     else
00521     {
00522         QFile::remove(autostart+desktopfile);
00523     }
00524     KPilotSettings::setDockDaemon(fConfigWidget->fDockDaemon->isChecked());
00525     KPilotSettings::setKillDaemonAtExit(fConfigWidget->fKillDaemonOnExit->isChecked());
00526     KPilotSettings::setQuitAfterSync(fConfigWidget->fQuitAfterSync->isChecked());
00527     KPilotConfig::updateConfigVersion();
00528     KPilotSettings::self()->writeConfig();
00529     unmodified();
00530 }
00531 
KDE Home | KDE Accessibility Home | Description of Access Keys