kpilot Library API Documentation

kpilotConfigDialog.cc

00001 /* kpilotConfigDialog.cc                KPilot
00002 **
00003 ** Copyright (C) 2001 by Dan Pilone
00004 **
00005 ** This file defines a specialization of KPilotDeviceLink
00006 ** that can actually handle some HotSync tasks, like backup
00007 ** and restore. It does NOT do conduit stuff.
00008 */
00009 
00010 /*
00011 ** This program is free software; you can redistribute it and/or modify
00012 ** it under the terms of the GNU General Public License as published by
00013 ** the Free Software Foundation; either version 2 of the License, or
00014 ** (at your option) any later version.
00015 **
00016 ** This program is distributed in the hope that it will be useful,
00017 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 ** GNU General Public License for more details.
00020 **
00021 ** You should have received a copy of the GNU General Public License
00022 ** along with this program in a file called COPYING; if not, write to
00023 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024 ** MA 02111-1307, USA.
00025 */
00026 
00027 /*
00028 ** Bug reports and questions can be sent to kde-pim@kde.org
00029 */
00030 
00031 static const char *kpilotconfigdialog_id =
00032     "$Id: kpilotConfigDialog.cc,v 1.19 2003/07/26 15:50:04 kainhofe Exp $";
00033 
00034 #include "options.h"
00035 
00036 #include <pi-version.h>
00037 
00038 #include <qcombobox.h>
00039 #include <qcheckbox.h>
00040 #include <qradiobutton.h>
00041 #include <qpushbutton.h>
00042 #include <qbuttongroup.h>
00043 #include <qlineedit.h>
00044 #include <qtabwidget.h>
00045 
00046 #include <kmessagebox.h>
00047 #include <kcharsets.h>
00048 
00049 #include "kpilotConfig.h"
00050 
00051 #include "kpilotConfigDialog_base.h"
00052 #include "kpilotConfigDialog.moc"
00053 #include "syncAction.h"
00054 #include "dbSelectionDialog.h"
00055 
00056 KPilotConfigDialog::KPilotConfigDialog(QWidget * w, const char *n,
00057     bool m) : UIDialog(w, n, m)
00058 {
00059     FUNCTIONSETUP;
00060 
00061     fConfigWidget = new KPilotConfigWidget(widget());
00062     // Fill the encodings list
00063     {
00064         QStringList l = KGlobal::charsets()->descriptiveEncodingNames();
00065         for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it )
00066         {
00067             fConfigWidget->fPilotEncoding->insertItem(*it);
00068         }
00069     }
00070 
00071     fConfigWidget->tabWidget->adjustSize();
00072     fConfigWidget->resize(fConfigWidget->tabWidget->size());
00073     setTabWidget(fConfigWidget->tabWidget);
00074 
00075 #if defined(PILOT_LINK_VERSION) && defined(PILOT_LINK_MAJOR) && defined(PILOT_LINK_MINOR)
00076 #if (PILOT_LINK_VERSION * 100 + PILOT_LINK_MAJOR * 10 + PILOT_LINK_MINOR) < 100
00077     fConfigWidget->fPilotDevice->setMaxLength(13);
00078 #endif
00079 #endif
00080 
00081     disableUnusedOptions();
00082     readConfig();
00083 
00084 
00085     addAboutPage(false);
00086 //  connect( fSyncFile, SIGNAL( toggled(bool) ), fAbookFile, SLOT( setEnabled(bool) ) );
00087     connect(fConfigWidget->fBackupOnlyChooser, SIGNAL( clicked() ),
00088         SLOT( slotSelectNoBackupDBs() ) );
00089     connect(fConfigWidget->fSkipDBChooser, SIGNAL(clicked()),
00090         SLOT(slotSelectNoRestoreDBs()));
00091 
00092     (void) kpilotconfigdialog_id;
00093 }
00094 
00095 KPilotConfigDialog::~KPilotConfigDialog()
00096 {
00097     FUNCTIONSETUP;
00098 }
00099 
00100 void KPilotConfigDialog::disableUnusedOptions()
00101 {
00102     FUNCTIONSETUP;
00103 }
00104 
00105 void KPilotConfigDialog::readConfig()
00106 {
00107     FUNCTIONSETUP;
00108 
00109     KPilotConfigSettings & c = KPilotConfig::getConfig();
00110     c.resetGroup();
00111 
00112     /* General tab in the setup dialog */
00113     fConfigWidget->fPilotDevice->setText(c.getPilotDevice());
00114     fConfigWidget->fPilotSpeed->setCurrentItem(c.getPilotSpeed());
00115     getEncoding(c);
00116     fConfigWidget->fUserName->setText(c.getUser());
00117     fConfigWidget->fStartDaemonAtLogin->setChecked(c.getStartDaemonAtLogin());
00118     fConfigWidget->fDockDaemon->setChecked(c.getDockDaemon());
00119     fConfigWidget->fKillDaemonOnExit->setChecked(c.getKillDaemonOnExit());
00120     fConfigWidget->fQuitAfterSync->setChecked(c.getQuitAfterSync());
00121 
00122     /* Sync tab */
00123     int synctype=c.getSyncType();
00124     if (synctype < SyncAction::eSyncModeLastRadiobutton)
00125         fConfigWidget->fSyncMode->setButton(synctype);
00126     else
00127     {
00128         fConfigWidget->fSyncMode->setButton(SyncAction::eSyncModeLastRadiobutton);
00129         fConfigWidget->fSpecialSync->setCurrentItem(synctype-SyncAction::eSyncModeLastRadiobutton);
00130     }
00131 
00132     fConfigWidget->fFullBackupCheck->setChecked(c.getFullSyncOnPCChange());
00133     fConfigWidget->fConflictResolution->setCurrentItem(c.getConflictResolution());
00134     // fConfigWidget->fSyncFiles->setChecked(c.getSyncFiles());
00135     // fConfigWidget->fSyncWithKMail->setChecked(c.getSyncWithKMail());
00136 
00137     /* Viewers tab */
00138     fConfigWidget->fInternalEditors->setChecked(c.getInternalEditors());
00139     fConfigWidget->fUseSecret->setChecked(c.getShowSecrets());
00140     c.setAddressGroup();
00141     fConfigWidget->fAddressGroup->setButton(c.getAddressDisplayMode());
00142     fConfigWidget->fUseKeyField->setChecked(c.getUseKeyField());
00143     c.resetGroup();
00144 
00145     /* Backup tab */
00146     fConfigWidget->fBackupOnly->setText(c.getBackupOnly());
00147     fConfigWidget->fSkipDB->setText(c.getSkip());
00148 }
00149 
00150 /* virtual */ bool KPilotConfigDialog::validate()
00151 {
00152     int r = KMessageBox::Yes;
00153 
00154 #if defined(PILOT_LINK_VERSION) && defined(PILOT_LINK_MAJOR) && defined(PILOT_LINK_MINOR)
00155 #if (PILOT_LINK_VERSION * 100 + PILOT_LINK_MAJOR * 10 + PILOT_LINK_MINOR) < 100
00156     QString d = fConfigWidget->fPilotDevice->text();
00157 
00158     if (d.length() > 13)
00159     {
00160     r = KMessageBox::questionYesNo(
00161         this,
00162         i18n("<qt>The device name you entered (<i>%1</i>) "
00163             "is longer than 13 characters. This is "
00164             "probably unsupported and can cause problems. "
00165             "Are you sure you want to use this device name?</qt>")
00166             .arg(d),
00167         i18n("Device Name too Long")
00168         ) ;
00169     }
00170 #endif
00171 #endif
00172 
00173     return KMessageBox::Yes == r;
00174 }
00175 
00176 /* virtual */ void KPilotConfigDialog::commitChanges()
00177 {
00178     FUNCTIONSETUP;
00179 
00180     KPilotConfigSettings & c = KPilotConfig::getConfig();
00181     c.resetGroup();
00182 
00183     // General page
00184     c.setPilotDevice(fConfigWidget->fPilotDevice->text());
00185     c.setPilotSpeed(fConfigWidget->fPilotSpeed->currentItem());
00186     setEncoding(c);
00187     c.setUser(fConfigWidget->fUserName->text());
00188     c.setStartDaemonAtLogin(fConfigWidget->fStartDaemonAtLogin->isChecked());
00189     c.setDockDaemon(fConfigWidget->fDockDaemon->isChecked());
00190     c.setKillDaemonOnExit(fConfigWidget->fKillDaemonOnExit->isChecked());
00191     c.setQuitAfterSync(fConfigWidget->fQuitAfterSync->isChecked());
00192 
00193     /* Sync tab */
00194     int syncmode=fConfigWidget->fSyncMode->id(fConfigWidget->fSyncMode->selected());
00195     if (syncmode==SyncAction::eSyncModeLastRadiobutton)
00196         syncmode+=fConfigWidget->fSpecialSync->currentItem();
00197     c.setSyncType(syncmode);
00198     c.setFullSyncOnPCChange(fConfigWidget->fFullBackupCheck->isChecked());
00199     c.setConflictResolution(fConfigWidget->fConflictResolution->currentItem());
00200 
00201     // c.setSyncFiles(fConfigWidget->fSyncFiles->isChecked());
00202     // c.setSyncWithKMail(fConfigWidget->fSyncWithKMail->isChecked());
00203 
00204     /* Viewers tab */
00205     c.setInternalEditors( fConfigWidget->fInternalEditors->isChecked());
00206     c.setShowSecrets(fConfigWidget->fUseSecret->isChecked());
00207     c.setAddressGroup();
00208     c.setAddressDisplayMode(fConfigWidget->fAddressGroup->id(
00209         fConfigWidget->fAddressGroup->selected()));
00210     c.setUseKeyField(fConfigWidget->fUseKeyField->isChecked());
00211     c.resetGroup();
00212 
00213     /* Backup tab */
00214     c.setBackupOnly(fConfigWidget->fBackupOnly->text());
00215     c.setSkip(fConfigWidget->fSkipDB->text());
00216 
00217     KPilotConfig::updateConfigVersion();
00218     c.sync();
00219 }
00220 
00221 /* slot */ void KPilotConfigDialog::changePortType(int i)
00222 {
00223     FUNCTIONSETUP;
00224 
00225     switch (i)
00226     {
00227     case 0:
00228         fConfigWidget->fPilotSpeed->setEnabled(true);
00229         break;
00230     case 1:
00231     case 2:
00232         fConfigWidget->fPilotSpeed->setEnabled(false);
00233         break;
00234     default:
00235         kdWarning() << k_funcinfo
00236             << ": Unknown port type " << i << endl;
00237     }
00238 }
00239 
00240 void KPilotConfigDialog::getEncoding(const KPilotConfigSettings &c)
00241 {
00242     FUNCTIONSETUP;
00243     QString e = c.getEncoding();
00244     if (e.isEmpty())
00245         fConfigWidget->fPilotEncoding->setCurrentItem(0);
00246     else
00247         fConfigWidget->fPilotEncoding->setCurrentText(e);
00248 }
00249 
00250 void KPilotConfigDialog::setEncoding(KPilotConfigSettings &c)
00251 {
00252     FUNCTIONSETUP;
00253 
00254     QString enc = fConfigWidget->fPilotEncoding->currentText();
00255     if (enc.isEmpty())
00256     {
00257         kdWarning() << k_funcinfo << "Empty encoding. Will ignore it"<<endl;
00258     }
00259     else
00260     {
00261         c.setEncoding(enc);
00262     }
00263 }
00264 
00265 void KPilotConfigDialog::slotSelectNoBackupDBs()
00266 {
00267     FUNCTIONSETUP;
00268     KPilotConfigSettings & c = KPilotConfig::getConfig();
00269 
00270     QStringList selectedDBs(QStringList::split(',', fConfigWidget->fBackupOnly->text() ));
00271     QStringList deviceDBs(c.readListEntry("DeviceDBs"));
00272     QStringList addedDBs(c.readListEntry("AddedDBsNoBackup"));
00273 
00274     KPilotDBSelectionDialog*dlg=new KPilotDBSelectionDialog(selectedDBs, deviceDBs, addedDBs, this, "NoBackupDBs");
00275     if (dlg && (dlg->exec()==QDialog::Accepted) )
00276     {
00277         fConfigWidget->fBackupOnly->setText(
00278             dlg->getSelectedDBs().join(","));
00279         c.writeEntry("AddedDBsNoBackup", dlg->getAddedDBs());
00280     }
00281     KPILOT_DELETE(dlg);
00282 }
00283 
00284 void KPilotConfigDialog::slotSelectNoRestoreDBs()
00285 {
00286     FUNCTIONSETUP;
00287     KPilotConfigSettings & c = KPilotConfig::getConfig();
00288 
00289     QStringList selectedDBs(QStringList::split(',', fConfigWidget->fSkipDB->text() ));
00290     QStringList deviceDBs(c.readListEntry("DeviceDBs"));
00291     QStringList addedDBs(c.readListEntry("AddedDBsNoRestore"));
00292 
00293     KPilotDBSelectionDialog*dlg=new KPilotDBSelectionDialog(selectedDBs, deviceDBs, addedDBs, this, "NoRestoreDBs");
00294     if (dlg && (dlg->exec()==QDialog::Accepted) )
00295     {
00296         fConfigWidget->fSkipDB->setText(
00297             dlg->getSelectedDBs().join(","));
00298         c.writeEntry("AddedDBsNoRestore", dlg->getAddedDBs());
00299     }
00300     KPILOT_DELETE(dlg);
00301 }
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