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 static const char *kpilotconfigdialog_id =
00034     "$Id: kpilotConfigDialog.cc 438196 2005-07-24 15:42:44Z binner $";
00035 
00036 #include "options.h"
00037 
00038 #include <pi-version.h>
00039 
00040 #include <qcombobox.h>
00041 #include <qcheckbox.h>
00042 #include <qradiobutton.h>
00043 #include <qpushbutton.h>
00044 #include <qbuttongroup.h>
00045 #include <qlineedit.h>
00046 #include <qtabwidget.h>
00047 #include <qspinbox.h>
00048 #include <qfile.h>
00049 
00050 #include <kmessagebox.h>
00051 #include <kcharsets.h>
00052 #include <kstandarddirs.h>
00053 #include <kglobal.h>
00054 #include <kurl.h>
00055 #include <kio/netaccess.h>
00056 
00057 #include "kpilotConfig.h"
00058 #include "kpilotSettings.h"
00059 
00060 #include "kpilotConfigDialog_device.h"
00061 #include "kpilotConfigDialog_sync.h"
00062 #include "kpilotConfigDialog_startup.h"
00063 #include "kpilotConfigDialog_viewers.h"
00064 #include "kpilotConfigDialog_backup.h"
00065 #include "kpilotConfigDialog.moc"
00066 #include "syncAction.h"
00067 #include "dbSelectionDialog.h"
00068 
00069 /* virtual */ QString ConfigPage::maybeSaveText() const
00070 {
00071     return i18n("<qt>The settings for configuration page <i>%1</i> have been changed. Do you "
00072         "want to save the changes before continuing?</qt>").arg(this->conduitName());
00073 }
00074 
00075 DeviceConfigPage::DeviceConfigPage(QWidget * w, const char *n ) : ConfigPage( w, n )
00076 {
00077     FUNCTIONSETUP;
00078 
00079     fConfigWidget = new DeviceConfigWidget( w );
00080     // Fill the encodings list
00081     {
00082         QStringList l = KGlobal::charsets()->descriptiveEncodingNames();
00083         for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it )
00084         {
00085             fConfigWidget->fPilotEncoding->insertItem(*it);
00086         }
00087     }
00088 
00089     fConfigWidget->resize(fConfigWidget->size());
00090     fWidget = fConfigWidget;
00091 
00092 #if PILOT_LINK_NUMBER < PILOT_LINK_0_10_0
00093     fConfigWidget->fPilotDevice->setMaxLength(13);
00094 #endif
00095 
00096 
00097 #define CM(a,b) connect(fConfigWidget->a,b,this,SLOT(modified()));
00098     CM(fPilotDevice, SIGNAL(textChanged(const QString &)));
00099     CM(fPilotSpeed, SIGNAL(activated(int)));
00100     CM(fPilotEncoding, SIGNAL(textChanged(const QString &)));
00101     CM(fUserName, SIGNAL(textChanged(const QString &)));
00102     CM(fWorkaround, SIGNAL(activated(int)));
00103 #undef CM
00104 
00105     fConduitName = i18n("Device");
00106 
00107     (void) kpilotconfigdialog_id;
00108 }
00109 
00110 void DeviceConfigPage::load()
00111 {
00112     FUNCTIONSETUP;
00113     KPilotSettings::self()->readConfig();
00114 
00115     /* General tab in the setup dialog */
00116     fConfigWidget->fPilotDevice->setText(KPilotSettings::pilotDevice());
00117     fConfigWidget->fPilotSpeed->setCurrentItem(KPilotSettings::pilotSpeed());
00118     getEncoding();
00119     fConfigWidget->fUserName->setText(KPilotSettings::userName());
00120 
00121     switch(KPilotSettings::workarounds())
00122     {
00123     case KPilotSettings::eWorkaroundNone :
00124         fConfigWidget->fWorkaround->setCurrentItem(0);
00125         break;
00126     case KPilotSettings::eWorkaroundUSB :
00127         fConfigWidget->fWorkaround->setCurrentItem(1);
00128         break;
00129     default:
00130         kdWarning() << k_funcinfo
00131             << ": Unknown workaround number "
00132             << (int) KPilotSettings::workarounds()
00133             << endl;
00134         KPilotSettings::setWorkarounds(KPilotSettings::eWorkaroundNone);
00135         fConfigWidget->fWorkaround->setCurrentItem(0);
00136     }
00137     unmodified();
00138 }
00139 
00140 /* virtual */ bool DeviceConfigPage::validate()
00141 {
00142     int r = KMessageBox::Yes;
00143 
00144 #if PILOT_LINK_NUMBER < PILOT_LINK_0_10_0
00145     QString d = fConfigWidget->fPilotDevice->text();
00146 
00147     if (d.length() > 13)
00148     {
00149     r = KMessageBox::questionYesNo(
00150         fConfigWidget,
00151         i18n("<qt>The device name you entered (<i>%1</i>) "
00152             "is longer than 13 characters. This is "
00153             "probably unsupported and can cause problems. "
00154             "Are you sure you want to use this device name?</qt>")
00155             .arg(d),
00156         i18n("Device Name too Long"), i18n("Use"), i18n("Do Not Use")
00157         ) ;
00158     }
00159 #endif
00160 
00161     return KMessageBox::Yes == r;
00162 }
00163 
00164 /* virtual */ void DeviceConfigPage::commit()
00165 {
00166     FUNCTIONSETUP;
00167 
00168     // General page
00169     KPilotSettings::setPilotDevice(fConfigWidget->fPilotDevice->text());
00170     KPilotSettings::setPilotSpeed(fConfigWidget->fPilotSpeed->currentItem());
00171     setEncoding();
00172     KPilotSettings::setUserName(fConfigWidget->fUserName->text());
00173 
00174     switch(fConfigWidget->fWorkaround->currentItem())
00175     {
00176     case 0 : KPilotSettings::setWorkarounds(KPilotSettings::eWorkaroundNone); break;
00177     case 1 : KPilotSettings::setWorkarounds(KPilotSettings::eWorkaroundUSB); break;
00178     default :
00179         kdWarning() << k_funcinfo
00180             << ": Unknown workaround number "
00181             << fConfigWidget->fWorkaround->currentItem()
00182             << endl;
00183         KPilotSettings::setWorkarounds(KPilotSettings::eWorkaroundNone);
00184 
00185     }
00186     KPilotConfig::updateConfigVersion();
00187     KPilotSettings::self()->writeConfig();
00188     unmodified();
00189 }
00190 
00191 /* slot */ void DeviceConfigPage::changePortType(int i)
00192 {
00193     FUNCTIONSETUP;
00194 
00195     switch (i)
00196     {
00197     case 0:
00198         fConfigWidget->fPilotSpeed->setEnabled(true);
00199         break;
00200     case 1:
00201     case 2:
00202         fConfigWidget->fPilotSpeed->setEnabled(false);
00203         break;
00204     default:
00205         kdWarning() << k_funcinfo
00206             << ": Unknown port type " << i << endl;
00207     }
00208 }
00209 
00210 void DeviceConfigPage::getEncoding()
00211 {
00212     FUNCTIONSETUP;
00213     QString e = KPilotSettings::encoding();
00214     if (e.isEmpty())
00215         fConfigWidget->fPilotEncoding->setCurrentText(CSL1("ISO8859-15"));
00216     else
00217         fConfigWidget->fPilotEncoding->setCurrentText(e);
00218 }
00219 
00220 void DeviceConfigPage::setEncoding()
00221 {
00222     FUNCTIONSETUP;
00223 
00224     QString enc = fConfigWidget->fPilotEncoding->currentText();
00225     if (enc.isEmpty())
00226     {
00227         kdWarning() << k_funcinfo << "Empty encoding. Will ignore it"<<endl;
00228     }
00229     else
00230     {
00231         KPilotSettings::setEncoding(enc);
00232     }
00233 }
00234 
00235 SyncConfigPage::SyncConfigPage(QWidget * w, const char *n ) : ConfigPage( w, n )
00236 {
00237     FUNCTIONSETUP;
00238 
00239     fConfigWidget = new SyncConfigWidget( w );
00240     fConfigWidget->resize(fConfigWidget->size());
00241     fWidget = fConfigWidget;
00242 
00243 #define CM(a,b) connect(fConfigWidget->a,b,this,SLOT(modified()));
00244     CM(fSpecialSync, SIGNAL(activated(int)));
00245     CM(fFullBackupCheck, SIGNAL(toggled(bool)));
00246     CM(fScreenlockSecure, SIGNAL(toggled(bool)));
00247     CM(fConflictResolution, SIGNAL(activated(int)));
00248 #undef CM
00249 
00250     fConduitName = i18n("HotSync");
00251 }
00252 
00253 #define MENU_ITEM_COUNT (5)
00254 static SyncAction::SyncMode::Mode syncTypeMap[MENU_ITEM_COUNT] = {
00255     SyncAction::SyncMode::eHotSync,
00256     SyncAction::SyncMode::eFastSync,
00257     SyncAction::SyncMode::eFullSync,
00258     SyncAction::SyncMode::eCopyPCToHH,
00259     SyncAction::SyncMode::eCopyHHToPC
00260     } ;
00261 
00262 void SyncConfigPage::load()
00263 {
00264     FUNCTIONSETUP;
00265     KPilotSettings::self()->readConfig();
00266 
00267     /* Sync tab */
00268     int synctype=KPilotSettings::syncType();
00269     if (synctype<0) synctype=(int) SyncAction::SyncMode::eHotSync;
00270     for (unsigned int i=0; i<MENU_ITEM_COUNT; ++i)
00271     {
00272         if (syncTypeMap[i] == synctype)
00273         {
00274             fConfigWidget->fSpecialSync->setCurrentItem(i);
00275             synctype=-1;
00276             break;
00277         }
00278     }
00279     if (synctype != -1)
00280     {
00281         fConfigWidget->fSpecialSync->setCurrentItem(0); /* HotSync */
00282     }
00283 
00284     fConfigWidget->fFullBackupCheck->setChecked(KPilotSettings::fullSyncOnPCChange());
00285     fConfigWidget->fConflictResolution->setCurrentItem(KPilotSettings::conflictResolution());
00286     fConfigWidget->fScreenlockSecure->setChecked(KPilotSettings::screenlockSecure());
00287 
00288     unmodified();
00289 }
00290 
00291 /* virtual */ void SyncConfigPage::commit()
00292 {
00293     FUNCTIONSETUP;
00294 
00295     /* Sync tab */
00296     int synctype = -1;
00297     unsigned int selectedsync = fConfigWidget->fSpecialSync->currentItem();
00298     if (selectedsync < MENU_ITEM_COUNT)
00299     {
00300         synctype = syncTypeMap[selectedsync];
00301     }
00302     if (synctype < 0)
00303     {
00304         synctype = SyncAction::SyncMode::eHotSync;
00305     }
00306 
00307     KPilotSettings::setSyncType(synctype);
00308     KPilotSettings::setFullSyncOnPCChange(fConfigWidget->fFullBackupCheck->isChecked());
00309     KPilotSettings::setConflictResolution(fConfigWidget->fConflictResolution->currentItem());
00310     KPilotSettings::setScreenlockSecure(fConfigWidget->fScreenlockSecure->isChecked());
00311 
00312     KPilotConfig::updateConfigVersion();
00313     KPilotSettings::self()->writeConfig();
00314     unmodified();
00315 }
00316 
00317 
00318 
00319 BackupConfigPage::BackupConfigPage(QWidget * w, const char *n ) : ConfigPage( w, n )
00320 {
00321     FUNCTIONSETUP;
00322 
00323     fConfigWidget = new BackupConfigWidget( w );
00324     fConfigWidget->resize(fConfigWidget->size());
00325     fWidget = fConfigWidget;
00326 
00327     connect(fConfigWidget->fBackupOnlyChooser, SIGNAL( clicked() ),
00328         SLOT( slotSelectNoBackupDBs() ) );
00329     connect(fConfigWidget->fSkipDBChooser, SIGNAL(clicked()),
00330         SLOT(slotSelectNoRestoreDBs()));
00331 
00332 #define CM(a,b) connect(fConfigWidget->a,b,this,SLOT(modified()));
00333     CM(fBackupOnly, SIGNAL(textChanged(const QString &)));
00334     CM(fSkipDB, SIGNAL(textChanged(const QString &)));
00335 #undef CM
00336 
00337     fConduitName = i18n("Backup");
00338 }
00339 
00340 void BackupConfigPage::load()
00341 {
00342     FUNCTIONSETUP;
00343     KPilotSettings::self()->readConfig();
00344 
00345     /* Backup tab */
00346     fConfigWidget->fBackupOnly->setText(KPilotSettings::skipBackupDB().join(CSL1(",")));
00347     fConfigWidget->fSkipDB->setText(KPilotSettings::skipRestoreDB().join(CSL1(",")));
00348     fConfigWidget->fRunConduitsWithBackup->setChecked(KPilotSettings::runConduitsWithBackup());
00349     unmodified();
00350 }
00351 
00352 /* virtual */ void BackupConfigPage::commit()
00353 {
00354     FUNCTIONSETUP;
00355 
00356     /* Backup tab */
00357     KPilotSettings::setSkipBackupDB(
00358         QStringList::split(CSL1(","),fConfigWidget->fBackupOnly->text()));
00359     KPilotSettings::setSkipRestoreDB(
00360         QStringList::split(CSL1(","),fConfigWidget->fSkipDB->text()));
00361     KPilotSettings::setRunConduitsWithBackup(fConfigWidget->fRunConduitsWithBackup->isChecked());
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     DEBUGDAEMON << fname << ": Autostart=" << autostart << endl;
00504     DEBUGDAEMON << fname << ": desktop=" << desktopfile << endl;
00505     DEBUGDAEMON << 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