kpilot

kpilotConfigDialog.cc

Go to the documentation of this file.
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         WARNINGKPILOT << "Unknown workaround number "
00126             << (int) KPilotSettings::workarounds()
00127             << endl;
00128         KPilotSettings::setWorkarounds(KPilotSettings::eWorkaroundNone);
00129         fConfigWidget->fWorkaround->setCurrentItem(0);
00130     }
00131     unmodified();
00132 }
00133 
00134 /* virtual */ bool DeviceConfigPage::validate()
00135 {
00136     int r = KMessageBox::Yes;
00137 
00138 #if PILOT_LINK_NUMBER < PILOT_LINK_0_10_0
00139     QString d = fConfigWidget->fPilotDevice->text();
00140 
00141     if (d.length() > 13)
00142     {
00143     r = KMessageBox::questionYesNo(
00144         fConfigWidget,
00145         i18n("<qt>The device name you entered (<i>%1</i>) "
00146             "is longer than 13 characters. This is "
00147             "probably unsupported and can cause problems. "
00148             "Are you sure you want to use this device name?</qt>")
00149             .arg(d),
00150         i18n("Device Name too Long"), i18n("Use"), i18n("Do Not Use")
00151         ) ;
00152     }
00153 #endif
00154 
00155     return KMessageBox::Yes == r;
00156 }
00157 
00158 /* virtual */ void DeviceConfigPage::commit()
00159 {
00160     FUNCTIONSETUP;
00161 
00162     // General page
00163     KPilotSettings::setPilotDevice(fConfigWidget->fPilotDevice->text());
00164     KPilotSettings::setPilotSpeed(fConfigWidget->fPilotSpeed->currentItem());
00165     setEncoding();
00166     KPilotSettings::setUserName(fConfigWidget->fUserName->text());
00167 
00168     switch(fConfigWidget->fWorkaround->currentItem())
00169     {
00170     case 0 : KPilotSettings::setWorkarounds(KPilotSettings::eWorkaroundNone); break;
00171     case 1 : KPilotSettings::setWorkarounds(KPilotSettings::eWorkaroundUSB); break;
00172     default :
00173         WARNINGKPILOT << "Unknown workaround number "
00174             << fConfigWidget->fWorkaround->currentItem()
00175             << endl;
00176         KPilotSettings::setWorkarounds(KPilotSettings::eWorkaroundNone);
00177 
00178     }
00179     KPilotConfig::updateConfigVersion();
00180     KPilotSettings::self()->writeConfig();
00181     unmodified();
00182 }
00183 
00184 /* slot */ void DeviceConfigPage::changePortType(int i)
00185 {
00186     FUNCTIONSETUP;
00187 
00188     switch (i)
00189     {
00190     case 0:
00191         fConfigWidget->fPilotSpeed->setEnabled(true);
00192         break;
00193     case 1:
00194     case 2:
00195         fConfigWidget->fPilotSpeed->setEnabled(false);
00196         break;
00197     default:
00198         WARNINGKPILOT << "Unknown port type " << i << endl;
00199     }
00200 }
00201 
00202 void DeviceConfigPage::getEncoding()
00203 {
00204     FUNCTIONSETUP;
00205     QString e = KPilotSettings::encoding();
00206     if (e.isEmpty())
00207         fConfigWidget->fPilotEncoding->setCurrentText(CSL1("ISO8859-15"));
00208     else
00209         fConfigWidget->fPilotEncoding->setCurrentText(e);
00210 }
00211 
00212 void DeviceConfigPage::setEncoding()
00213 {
00214     FUNCTIONSETUP;
00215 
00216     QString enc = fConfigWidget->fPilotEncoding->currentText();
00217     if (enc.isEmpty())
00218     {
00219         WARNINGKPILOT << "Empty encoding. Will ignore it." << endl;
00220     }
00221     else
00222     {
00223         KPilotSettings::setEncoding(enc);
00224     }
00225 }
00226 
00227 SyncConfigPage::SyncConfigPage(QWidget * w, const char *n ) : ConfigPage( w, n )
00228 {
00229     FUNCTIONSETUP;
00230 
00231     fConfigWidget = new SyncConfigWidget( w );
00232     fConfigWidget->resize(fConfigWidget->size());
00233     fWidget = fConfigWidget;
00234 
00235 #define CM(a,b) connect(fConfigWidget->a,b,this,SLOT(modified()));
00236     CM(fSpecialSync, SIGNAL(activated(int)));
00237     CM(fFullSyncCheck, SIGNAL(toggled(bool)));
00238     CM(fScreenlockSecure, SIGNAL(toggled(bool)));
00239     CM(fConflictResolution, SIGNAL(activated(int)));
00240 #undef CM
00241 
00242     fConduitName = i18n("HotSync");
00243 }
00244 
00245 #define MENU_ITEM_COUNT (4)
00246 static SyncAction::SyncMode::Mode syncTypeMap[MENU_ITEM_COUNT] = {
00247     SyncAction::SyncMode::eHotSync,
00248     SyncAction::SyncMode::eFullSync,
00249     SyncAction::SyncMode::eCopyPCToHH,
00250     SyncAction::SyncMode::eCopyHHToPC
00251     } ;
00252 
00253 void SyncConfigPage::load()
00254 {
00255     FUNCTIONSETUP;
00256     KPilotSettings::self()->readConfig();
00257 
00258     /* Sync tab */
00259     int synctype=KPilotSettings::syncType();
00260     if (synctype<0) synctype=(int) SyncAction::SyncMode::eHotSync;
00261     for (unsigned int i=0; i<MENU_ITEM_COUNT; ++i)
00262     {
00263         if (syncTypeMap[i] == synctype)
00264         {
00265             fConfigWidget->fSpecialSync->setCurrentItem(i);
00266             synctype=-1;
00267             break;
00268         }
00269     }
00270     if (synctype != -1)
00271     {
00272         fConfigWidget->fSpecialSync->setCurrentItem(0); /* HotSync */
00273     }
00274 
00275     fConfigWidget->fFullSyncCheck->setChecked(KPilotSettings::fullSyncOnPCChange());
00276     fConfigWidget->fConflictResolution->setCurrentItem(KPilotSettings::conflictResolution());
00277     fConfigWidget->fScreenlockSecure->setChecked(KPilotSettings::screenlockSecure());
00278 
00279     unmodified();
00280 }
00281 
00282 /* virtual */ void SyncConfigPage::commit()
00283 {
00284     FUNCTIONSETUP;
00285 
00286     /* Sync tab */
00287     int synctype = -1;
00288     unsigned int selectedsync = fConfigWidget->fSpecialSync->currentItem();
00289     if (selectedsync < MENU_ITEM_COUNT)
00290     {
00291         synctype = syncTypeMap[selectedsync];
00292     }
00293     if (synctype < 0)
00294     {
00295         synctype = SyncAction::SyncMode::eHotSync;
00296     }
00297 
00298     KPilotSettings::setSyncType(synctype);
00299     KPilotSettings::setFullSyncOnPCChange(fConfigWidget->fFullSyncCheck->isChecked());
00300     KPilotSettings::setConflictResolution(fConfigWidget->fConflictResolution->currentItem());
00301     KPilotSettings::setScreenlockSecure(fConfigWidget->fScreenlockSecure->isChecked());
00302 
00303     KPilotConfig::updateConfigVersion();
00304     KPilotSettings::self()->writeConfig();
00305     unmodified();
00306 }
00307 
00308 
00309 BackupConfigPage::BackupConfigPage(QWidget * w, const char *n ) : ConfigPage( w, n )
00310 {
00311     FUNCTIONSETUP;
00312 
00313     fConfigWidget = new BackupConfigWidget( w );
00314     fConfigWidget->resize(fConfigWidget->size());
00315     fWidget = fConfigWidget;
00316 
00317     connect(fConfigWidget->fBackupOnlyChooser, SIGNAL( clicked() ),
00318         SLOT( slotSelectNoBackupDBs() ) );
00319     connect(fConfigWidget->fSkipDBChooser, SIGNAL(clicked()),
00320         SLOT(slotSelectNoRestoreDBs()));
00321 
00322 #define CM(a,b) connect(fConfigWidget->a,b,this,SLOT(modified()));
00323     CM(fBackupOnly, SIGNAL(textChanged(const QString &)));
00324     CM(fSkipDB, SIGNAL(textChanged(const QString &)));
00325     CM(fBackupFrequency, SIGNAL(activated(int)));
00326 #undef CM
00327 
00328     fConduitName = i18n("Backup");
00329 }
00330 
00331 void BackupConfigPage::load()
00332 {
00333     FUNCTIONSETUP;
00334     KPilotSettings::self()->readConfig();
00335 
00336     /* Backup tab */
00337     fConfigWidget->fBackupOnly->setText(KPilotSettings::skipBackupDB().join(CSL1(",")));
00338     fConfigWidget->fSkipDB->setText(KPilotSettings::skipRestoreDB().join(CSL1(",")));
00339     fConfigWidget->fRunConduitsWithBackup->setChecked(KPilotSettings::runConduitsWithBackup());
00340 
00341     int backupfreq=KPilotSettings::backupFrequency();
00342 
00343     fConfigWidget->fBackupFrequency->setCurrentItem(backupfreq);
00344 
00345     unmodified();
00346 }
00347 
00348 /* virtual */ void BackupConfigPage::commit()
00349 {
00350     FUNCTIONSETUP;
00351 
00352     /* Backup tab */
00353     KPilotSettings::setSkipBackupDB(
00354         QStringList::split(CSL1(","),fConfigWidget->fBackupOnly->text()));
00355     KPilotSettings::setSkipRestoreDB(
00356         QStringList::split(CSL1(","),fConfigWidget->fSkipDB->text()));
00357     KPilotSettings::setRunConduitsWithBackup(fConfigWidget->fRunConduitsWithBackup->isChecked());
00358     KPilotSettings::setBackupFrequency(fConfigWidget->fBackupFrequency->currentItem());
00359 
00360     KPilotConfig::updateConfigVersion();
00361     KPilotSettings::self()->writeConfig();
00362     unmodified();
00363 }
00364 
00365 void BackupConfigPage::slotSelectNoBackupDBs()
00366 {
00367     FUNCTIONSETUP;
00368 
00369     QStringList selectedDBs(QStringList::split(',', fConfigWidget->fBackupOnly->text() ));
00370 
00371     QStringList deviceDBs=KPilotSettings::deviceDBs();
00372     QStringList addedDBs=KPilotSettings::addedDBs();
00373     KPilotDBSelectionDialog*dlg=new KPilotDBSelectionDialog(selectedDBs, deviceDBs, addedDBs, 0, "NoBackupDBs");
00374     if (dlg && (dlg->exec()==QDialog::Accepted) )
00375     {
00376         fConfigWidget->fBackupOnly->setText(
00377             dlg->getSelectedDBs().join(CSL1(",")));
00378         KPilotSettings::setAddedDBs( dlg->getAddedDBs() );
00379     }
00380     KPILOT_DELETE(dlg);
00381 }
00382 
00383 void BackupConfigPage::slotSelectNoRestoreDBs()
00384 {
00385     FUNCTIONSETUP;
00386 
00387     QStringList selectedDBs(QStringList::split(',', fConfigWidget->fSkipDB->text() ));
00388 
00389     QStringList deviceDBs=KPilotSettings::deviceDBs();
00390     QStringList addedDBs=KPilotSettings::addedDBs();
00391     KPilotDBSelectionDialog*dlg=new KPilotDBSelectionDialog(selectedDBs, deviceDBs, addedDBs, 0, "NoRestoreDBs");
00392     if (dlg && (dlg->exec()==QDialog::Accepted) )
00393     {
00394         fConfigWidget->fSkipDB->setText(
00395             dlg->getSelectedDBs().join(CSL1(",")));
00396         KPilotSettings::setAddedDBs( dlg->getAddedDBs() );
00397     }
00398     KPILOT_DELETE(dlg);
00399 }
00400 
00401 
00402 
00403 ViewersConfigPage::ViewersConfigPage(QWidget * w, const char *n ) : ConfigPage( w, n )
00404 {
00405     FUNCTIONSETUP;
00406 
00407     fConfigWidget = new ViewersConfigWidget( w );
00408     fConfigWidget->resize(fConfigWidget->size());
00409     fWidget = fConfigWidget;
00410 
00411 #define CM(a,b) connect(fConfigWidget->a,b,this,SLOT(modified()));
00412     CM(fInternalEditors, SIGNAL(toggled(bool)));
00413     CM(fUseSecret, SIGNAL(toggled(bool)));
00414     CM(fAddressGroup, SIGNAL(clicked(int)));
00415     CM(fUseKeyField, SIGNAL(toggled(bool)));
00416 #undef CM
00417 
00418     fConduitName = i18n("Viewers");
00419 }
00420 
00421 void ViewersConfigPage::load()
00422 {
00423     FUNCTIONSETUP;
00424     KPilotSettings::self()->readConfig();
00425 
00426     fConfigWidget->fInternalEditors->setChecked( false /* KPilotSettings::internalEditors() */ );
00427     fConfigWidget->fUseSecret->setChecked(KPilotSettings::showSecrets());
00428     fConfigWidget->fAddressGroup->setButton(KPilotSettings::addressDisplayMode());
00429     fConfigWidget->fUseKeyField->setChecked(KPilotSettings::useKeyField());
00430     unmodified();
00431 }
00432 
00433 /* virtual */ void ViewersConfigPage::commit()
00434 {
00435     FUNCTIONSETUP;
00436 
00437     KPilotSettings::setInternalEditors( fConfigWidget->fInternalEditors->isChecked());
00438     KPilotSettings::setShowSecrets(fConfigWidget->fUseSecret->isChecked());
00439     KPilotSettings::setAddressDisplayMode(fConfigWidget->fAddressGroup->id(
00440         fConfigWidget->fAddressGroup->selected()));
00441     KPilotSettings::setUseKeyField(fConfigWidget->fUseKeyField->isChecked());
00442     KPilotConfig::updateConfigVersion();
00443     KPilotSettings::self()->writeConfig();
00444     unmodified();
00445 }
00446 
00447 
00448 
00449 
00450 
00451 
00452 
00453 
00454 
00455 StartExitConfigPage::StartExitConfigPage(QWidget * w, const char *n ) : ConfigPage( w, n )
00456 {
00457     FUNCTIONSETUP;
00458 
00459     fConfigWidget = new StartExitConfigWidget( w );
00460     fConfigWidget->resize(fConfigWidget->size());
00461     fWidget = fConfigWidget;
00462 
00463 #define CM(a,b) connect(fConfigWidget->a,b,this,SLOT(modified()));
00464     CM(fStartDaemonAtLogin, SIGNAL(toggled(bool)));
00465     CM(fKillDaemonOnExit, SIGNAL(toggled(bool)));
00466     CM(fDockDaemon, SIGNAL(toggled(bool)));
00467     CM(fQuitAfterSync, SIGNAL(toggled(bool)));
00468 #undef CM
00469 
00470     fConduitName = i18n("Startup and Exit");
00471 }
00472 
00473 void StartExitConfigPage::load()
00474 {
00475     FUNCTIONSETUP;
00476     KPilotSettings::self()->readConfig();
00477 
00478     fConfigWidget->fStartDaemonAtLogin->setChecked(KPilotSettings::startDaemonAtLogin());
00479     fConfigWidget->fDockDaemon->setChecked(KPilotSettings::dockDaemon());
00480     fConfigWidget->fKillDaemonOnExit->setChecked(KPilotSettings::killDaemonAtExit());
00481     fConfigWidget->fQuitAfterSync->setChecked(KPilotSettings::quitAfterSync());
00482     unmodified();
00483 }
00484 
00485 
00486 /* virtual */ void StartExitConfigPage::commit()
00487 {
00488     FUNCTIONSETUP;
00489 
00490     QString autostart = KGlobalSettings::autostartPath();
00491     QString desktopfile = CSL1("kpilotdaemon.desktop");
00492     QString desktopcategory = CSL1("kde/");
00493     QString location = KGlobal::dirs()->findResource("xdgdata-apps",desktopcategory + desktopfile);
00494     if (location.isEmpty()) // Fallback to KDE 3.0?
00495     {
00496         location = KGlobal::dirs()->findResource("apps",desktopfile);
00497     }
00498 
00499 #ifdef DEBUG
00500     DEBUGKPILOT << fname << ": Autostart=" << autostart << endl;
00501     DEBUGKPILOT << fname << ": desktop=" << desktopfile << endl;
00502     DEBUGKPILOT << fname << ": location=" << location << endl;
00503 #endif
00504 
00505     KPilotSettings::setStartDaemonAtLogin(fConfigWidget->fStartDaemonAtLogin->isChecked());
00506     if (KPilotSettings::startDaemonAtLogin())
00507     {
00508         if (!location.isEmpty())
00509         {
00510             KURL src;
00511             src.setPath(location);
00512             KURL dst;
00513             dst.setPath(autostart+desktopfile);
00514             KIO::NetAccess::file_copy(src,dst,-1 /* 0666? */,true /* overwrite */);
00515         }
00516     }
00517     else
00518     {
00519         QFile::remove(autostart+desktopfile);
00520     }
00521     KPilotSettings::setDockDaemon(fConfigWidget->fDockDaemon->isChecked());
00522     KPilotSettings::setKillDaemonAtExit(fConfigWidget->fKillDaemonOnExit->isChecked());
00523     KPilotSettings::setQuitAfterSync(fConfigWidget->fQuitAfterSync->isChecked());
00524     KPilotConfig::updateConfigVersion();
00525     KPilotSettings::self()->writeConfig();
00526     unmodified();
00527 }
00528