kpilot

kpilotConfigWizard.cc

Go to the documentation of this file.
00001 /* KPilot
00002 **
00003 ** Copyright (C) 2004 by Reinhold Kainhofer
00004 **
00005 ** A simple configuration wizard.
00006 */
00007 
00008 /*
00009 ** This program is free software; you can redistribute it and/or modify
00010 ** it under the terms of the GNU General Public License as published by
00011 ** the Free Software Foundation; either version 2 of the License, or
00012 ** (at your option) any later version.
00013 **
00014 ** This program is distributed in the hope that it will be useful,
00015 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017 ** GNU General Public License for more details.
00018 **
00019 ** You should have received a copy of the GNU General Public License
00020 ** along with this program in a file called COPYING; if not, write to
00021 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00022 ** MA 02110-1301, USA.
00023 */
00024 
00025 /*
00026 ** Bug reports and questions can be sent to kde-pim@kde.org
00027 */
00028 
00029 //#include "options.h"
00030 
00031 #include <qpushbutton.h>
00032 #include <qbuttongroup.h>
00033 #include <qcheckbox.h>
00034 #include <qlineedit.h>
00035 
00036 #include <kmessagebox.h>
00037 #include <kglobal.h>
00038 #include <klocale.h>
00039 #include <kconfigskeleton.h>
00040 
00041 #include "kpilotConfig.h"
00042 #include "options.h"
00043 
00044 #include "kpilotConfigWizard_app.h"
00045 #include "kpilotConfigWizard_user.h"
00046 #include "kpilotConfigWizard_address.h"
00047 #include "kpilotConfigWizard_notes.h"
00048 #include "kpilotConfigWizard_vcal.h"
00049 
00050 
00051 #include "kpilotConfigWizard.moc"
00052 #include "kpilotProbeDialog.h"
00053 
00054 
00055 ConfigWizard::ConfigWizard(QWidget *parent, const char *n, int m) :
00056     KWizard(parent, n),
00057     fMode((Mode)m)
00058 {
00059 //  page1=new ConfigWizard_base1(this);
00060 //  addPage( page1, i18n("Select Connection Type") );
00061     page2=new ConfigWizard_base2(this);
00062     addPage( page2, i18n("Pilot Info") );
00063     page3=new ConfigWizard_base3(this);
00064     addPage( page3, i18n("Application to Sync With") );
00065     setFinishEnabled( page3, true );
00066     
00067     setHelpEnabled( page2, false );
00068     setHelpEnabled( page3, false );
00069 
00070     connect( page2->fProbeButton, SIGNAL( pressed() ),
00071         this, SLOT( probeHandheld() ) );
00072 
00073     KPilotSettings::self()->readConfig();
00074     page2->fUserName->setText( KPilotSettings::userName() );
00075     page2->fDeviceName->setText( KPilotSettings::pilotDevice() );
00076     page2->fPilotRunningPermanently->setChecked( KPilotSettings::startDaemonAtLogin() );
00077 
00078 }
00079 
00080 ConfigWizard::~ConfigWizard()
00081 {
00082 }
00083 
00084 void ConfigWizard::accept()
00085 {
00086     FUNCTIONSETUP;
00087     QString username( page2->fUserName->text() );
00088     QString devicename( page2->fDeviceName->text() );
00089 //  int devicetype( page1->fConnectionType->selectedId() );
00090     enum eSyncApp {
00091         eAppKDE=0,
00092         //eAppKontact,
00093         eAppEvolution,
00094         eAppNone
00095     } app;
00096     app=(eSyncApp)( page3->fAppType->selectedId() );
00097     bool keepPermanently( page2->fPilotRunningPermanently->isChecked() );
00098 #ifdef DEBUG
00099     DEBUGKPILOT<<fname<<"Keep permanently: "<<keepPermanently<<endl;
00100 #endif
00101 
00102     KPilotSettings::setPilotDevice( devicename );
00103     KPilotSettings::setUserName(username);
00104 //  KPilotSettings::setEncoding("iso 8859-15");
00105     KPilotSettings::setDockDaemon( true );
00106     KPilotSettings::setKillDaemonAtExit( !keepPermanently);
00107     KPilotSettings::setQuitAfterSync( !keepPermanently );
00108     KPilotSettings::setStartDaemonAtLogin( keepPermanently );
00109     KPilotSettings::setSyncType(0);
00110     KPilotSettings::setFullSyncOnPCChange( true );
00111     KPilotSettings::setConflictResolution(0);
00112     if ( !mDBs.isEmpty() ) 
00113         KPilotSettings::setDeviceDBs( mDBs );
00114 
00115     KPilotWizard_vcalConfig*calendarConfig = new KPilotWizard_vcalConfig("Calendar");
00116     KPilotWizard_vcalConfig*todoConfig = new KPilotWizard_vcalConfig("ToDo");
00117     KPilotWizard_addressConfig*addressConfig = new KPilotWizard_addressConfig();
00118     KPilotWizard_notesConfig*notesConfig = new KPilotWizard_notesConfig();
00119     addressConfig->readConfig();
00120     notesConfig->readConfig();
00121     todoConfig->readConfig();
00122     calendarConfig->readConfig();
00123 
00124     QStringList conduits = KPilotSettings::installedConduits();
00125     int version(0);
00126 #define APPEND_CONDUIT(a) if (!conduits.contains(a)) conduits.append(a)
00127     QString applicationName(i18n("general KDE-PIM"));
00128     APPEND_CONDUIT("internal_fileinstall");
00129     APPEND_CONDUIT("todo-conduit");
00130     APPEND_CONDUIT("vcal-conduit");
00131     switch (app) {
00132         case eAppEvolution:
00133             applicationName=i18n("Gnome's PIM suite", "Evolution");
00134 
00135             // TODO: Once the Evolution abook resource is finished, enable it...
00136             conduits.remove("abbrowser_conduit");
00137             // addressConfig->setDefaults();
00138             // addressConfig->setAddressbookType( KPilotWizard_addressConfig::eAbookResource );
00141 
00142             // nothing to do for knotes conduit yet (evolution doesn't have notes)
00143             conduits.remove("knotes-conduit");
00144 
00145             // the vcalconduits use the same config file, so set the correct groups
00146             version = calendarConfig->conduitVersion();
00147             calendarConfig->setDefaults();
00148             calendarConfig->setCalendarType( KPilotWizard_vcalConfig::eCalendarLocal );
00149             calendarConfig->setCalendarFile( "$HOME/evolution/local/Calendar/calendar.ics" );
00150             calendarConfig->setConduitVersion( version );
00151             version = todoConfig->conduitVersion();
00152             todoConfig->setDefaults();
00153             todoConfig->setCalendarType( KPilotWizard_vcalConfig::eCalendarLocal );
00154             todoConfig->setCalendarFile( "$HOME/evolution/local/Tasks/tasks.ics" );
00155             todoConfig->setConduitVersion( version );
00156 
00157             KMessageBox::information(this, i18n("KPilot cannot yet synchronize the addressbook with Evolution, so the addressbook conduit was disabled.\nWhen syncing the calendar or to-do list using KPilot please quit Evolution before the sync, otherwise you will lose data."), i18n("Restrictions with Evolution"));
00158             break;
00159         case eAppNone:
00160             conduits.clear();
00161             APPEND_CONDUIT("internal_fileinstall");
00162             applicationName=i18n("Kpilot will sync with nothing","nothing (it will backup only)");
00163             break;
00164 //      case eAppKontact:
00165         case eAppKDE:
00166             applicationName=i18n("KDE's PIM suite", "Kontact");
00167         default:
00168             APPEND_CONDUIT("knotes-conduit");
00169             APPEND_CONDUIT("abbrowser_conduit");
00170             // Set to the stdaddressbook, reset others to defaults
00171             addressConfig->setAddressbookType( KPilotWizard_addressConfig::eAbookResource );
00172             addressConfig->setArchiveDeleted( true );
00173             addressConfig->setConflictResolution( -1 );
00174             // nothing to do for knotes conduit yet
00175             // notesConfig->set...
00176             // the vcalconduits use the same config file, so set the correct groups
00177             int version = calendarConfig->conduitVersion();
00178             calendarConfig->setDefaults();
00179             calendarConfig->setCalendarType( KPilotWizard_vcalConfig::eCalendarResource );
00180             calendarConfig->setConduitVersion( version );
00181             version = todoConfig->conduitVersion();
00182             todoConfig->setDefaults();
00183             todoConfig->setCalendarType( KPilotWizard_vcalConfig::eCalendarResource );
00184             todoConfig->setConduitVersion( version );
00185             break;
00186     }
00187     addressConfig->writeConfig();
00188     notesConfig->writeConfig();
00189     todoConfig->writeConfig();
00190     calendarConfig->writeConfig();
00191 
00192     KPILOT_DELETE(addressConfig);
00193     KPILOT_DELETE(notesConfig);
00194     KPILOT_DELETE(todoConfig);
00195     KPILOT_DELETE(calendarConfig);
00196 
00197     KPilotSettings::setInstalledConduits( conduits );
00198 #undef APPEND_CONDUIT
00199 
00200     QString finishMessage = i18n("KPilot is now configured to sync with %1.").arg(applicationName);
00201     if (fMode == InDialog)
00202     {
00203         finishMessage.append(CSL1("\n"));
00204         finishMessage.append(i18n(
00205             "The remaining options in the config dialog are advanced options and can "
00206             "be used to fine-tune KPilot."));
00207     }
00208 
00209     KMessageBox::information(this, finishMessage,
00210         i18n("Automatic Configuration Finished"));
00211     KPilotSettings::self()->writeConfig();
00212     QDialog::accept();
00213 }
00214 
00215 void ConfigWizard::probeHandheld()
00216 {
00217     if ( KMessageBox::warningContinueCancel( this, i18n("Please put the handheld "
00218             "in the cradle, press the hotsync button and click on \"Continue\".\n\nSome "
00219             "kernel versions (Linux 2.6.x) have problems with the visor kernel module "
00220             "(for Sony Clie devices). Running an autodetection in that case might block "
00221             "the computer from doing hotsyncs until it is rebooted. In that case it might "
00222             "be advisable not to continue."), 
00223             i18n("Handheld Detection") ) == KMessageBox::Continue ) {
00224         ProbeDialog *probeDialog = new ProbeDialog( this );
00225         if ( probeDialog->exec() && probeDialog->detected() ) {
00226             page2->fUserName->setText( probeDialog->userName() );
00227             page2->fDeviceName->setText( probeDialog->device() );
00228             mDBs = probeDialog->dbs();
00229         }
00230         KPILOT_DELETE(probeDialog);
00231     }
00232 }
00233