kpilot/kpilot

kpilotConfigWizard.cc

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 static const char *conduitconfigwizard_id =
00030     "$Id: kpilotConfigWizard.cc 437980 2005-07-23 19:53:57Z kainhofe $";
00031 
00032 //#include "options.h"
00033 
00034 #include <qpushbutton.h>
00035 #include <qbuttongroup.h>
00036 #include <qcheckbox.h>
00037 #include <qlineedit.h>
00038 
00039 #include <kmessagebox.h>
00040 #include <kglobal.h>
00041 #include <klocale.h>
00042 #include <kconfigskeleton.h>
00043 
00044 #include "kpilotConfig.h"
00045 #include "options.h"
00046 
00047 #include "kpilotConfigWizard_app.h"
00048 #include "kpilotConfigWizard_user.h"
00049 #include "kpilotConfigWizard_address.h"
00050 #include "kpilotConfigWizard_notes.h"
00051 #include "kpilotConfigWizard_vcal.h"
00052 
00053 
00054 #include "kpilotConfigWizard.moc"
00055 #include "kpilotProbeDialog.h"
00056 
00057 
00058 ConfigWizard::ConfigWizard(QWidget *parent, const char *n, int m) :
00059     KWizard(parent, n),
00060     fMode((Mode)m)
00061 {
00062 //  page1=new ConfigWizard_base1(this);
00063 //  addPage( page1, i18n("Select Connection Type") );
00064     page2=new ConfigWizard_base2(this);
00065     addPage( page2, i18n("Pilot Info") );
00066     page3=new ConfigWizard_base3(this);
00067     addPage( page3, i18n("Application to Sync With") );
00068     setFinishEnabled( page3, true );
00069     
00070     setHelpEnabled( page2, false );
00071     setHelpEnabled( page3, false );
00072 
00073     connect( page2->fProbeButton, SIGNAL( pressed() ),
00074         this, SLOT( probeHandheld() ) );
00075 
00076     KPilotSettings::self()->readConfig();
00077     page2->fUserName->setText( KPilotSettings::userName() );
00078     page2->fDeviceName->setText( KPilotSettings::pilotDevice() );
00079     page2->fPilotRunningPermanently->setChecked( KPilotSettings::startDaemonAtLogin() );
00080 
00081     (void) conduitconfigwizard_id;
00082 }
00083 
00084 ConfigWizard::~ConfigWizard()
00085 {
00086 }
00087 
00088 void ConfigWizard::accept()
00089 {
00090     FUNCTIONSETUP;
00091     QString username( page2->fUserName->text() );
00092     QString devicename( page2->fDeviceName->text() );
00093 //  int devicetype( page1->fConnectionType->selectedId() );
00094     enum eSyncApp {
00095         eAppKDE=0,
00096         //eAppKontact,
00097         eAppEvolution,
00098         eAppNone
00099     } app;
00100     app=(eSyncApp)( page3->fAppType->selectedId() );
00101     bool keepPermanently( page2->fPilotRunningPermanently->isChecked() );
00102 #ifdef DEBUG
00103     DEBUGCONDUIT<<fname<<"Keep permanently: "<<keepPermanently<<endl;
00104 #endif
00105 
00106     KPilotSettings::setPilotDevice( devicename );
00107     KPilotSettings::setUserName(username);
00108 //  KPilotSettings::setEncoding("iso 8859-15");
00109     KPilotSettings::setDockDaemon( true );
00110     KPilotSettings::setKillDaemonAtExit( !keepPermanently);
00111     KPilotSettings::setQuitAfterSync( !keepPermanently );
00112     KPilotSettings::setStartDaemonAtLogin( keepPermanently );
00113     KPilotSettings::setSyncType(0);
00114     KPilotSettings::setFullSyncOnPCChange( true );
00115     KPilotSettings::setConflictResolution(0);
00116     if ( !mDBs.isEmpty() ) 
00117         KPilotSettings::setDeviceDBs( mDBs );
00118 
00119     KPilotWizard_vcalConfig*calendarConfig = new KPilotWizard_vcalConfig("Calendar");
00120     KPilotWizard_vcalConfig*todoConfig = new KPilotWizard_vcalConfig("ToDo");
00121     KPilotWizard_addressConfig*addressConfig = new KPilotWizard_addressConfig();
00122     KPilotWizard_notesConfig*notesConfig = new KPilotWizard_notesConfig();
00123     addressConfig->readConfig();
00124     notesConfig->readConfig();
00125     todoConfig->readConfig();
00126     calendarConfig->readConfig();
00127 
00128     QStringList conduits = KPilotSettings::installedConduits();
00129     int version(0);
00130 #define APPEND_CONDUIT(a) if (!conduits.contains(a)) conduits.append(a)
00131     QString applicationName(i18n("general KDE-PIM"));
00132     APPEND_CONDUIT("internal_fileinstall");
00133     APPEND_CONDUIT("todo-conduit");
00134     APPEND_CONDUIT("vcal-conduit");
00135     switch (app) {
00136         case eAppEvolution:
00137             applicationName=i18n("Gnome's PIM suite", "Evolution");
00138 
00139             // TODO: Once the Evolution abook resource is finished, enable it...
00140             conduits.remove("abbrowser_conduit");
00141             // addressConfig->setDefaults();
00142             // addressConfig->setAddressbookType( KPilotWizard_addressConfig::eAbookResource );
00145 
00146             // nothing to do for knotes conduit yet (evolution doesn't have notes)
00147             conduits.remove("knotes-conduit");
00148 
00149             // the vcalconduits use the same config file, so set the correct groups
00150             version = calendarConfig->conduitVersion();
00151             calendarConfig->setDefaults();
00152             calendarConfig->setCalendarType( KPilotWizard_vcalConfig::eCalendarLocal );
00153             calendarConfig->setCalendarFile( "$HOME/evolution/local/Calendar/calendar.ics" );
00154             calendarConfig->setConduitVersion( version );
00155             version = todoConfig->conduitVersion();
00156             todoConfig->setDefaults();
00157             todoConfig->setCalendarType( KPilotWizard_vcalConfig::eCalendarLocal );
00158             todoConfig->setCalendarFile( "$HOME/evolution/local/Tasks/tasks.ics" );
00159             todoConfig->setConduitVersion( version );
00160 
00161             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"));
00162             break;
00163         case eAppNone:
00164             conduits.clear();
00165             APPEND_CONDUIT("internal_fileinstall");
00166             applicationName=i18n("Kpilot will sync with nothing","nothing (it will backup only)");
00167             break;
00168 //      case eAppKontact:
00169         case eAppKDE:
00170             applicationName=i18n("KDE's PIM suite", "Kontact");
00171         default:
00172             APPEND_CONDUIT("knotes-conduit");
00173             APPEND_CONDUIT("abbrowser_conduit");
00174             // Set to the stdaddressbook, reset others to defaults
00175             addressConfig->setAddressbookType( KPilotWizard_addressConfig::eAbookResource );
00176             addressConfig->setArchiveDeleted( true );
00177             addressConfig->setConflictResolution( -1 );
00178             // nothing to do for knotes conduit yet
00179             // notesConfig->set...
00180             // the vcalconduits use the same config file, so set the correct groups
00181             int version = calendarConfig->conduitVersion();
00182             calendarConfig->setDefaults();
00183             calendarConfig->setCalendarType( KPilotWizard_vcalConfig::eCalendarResource );
00184             calendarConfig->setConduitVersion( version );
00185             version = todoConfig->conduitVersion();
00186             todoConfig->setDefaults();
00187             todoConfig->setCalendarType( KPilotWizard_vcalConfig::eCalendarResource );
00188             todoConfig->setConduitVersion( version );
00189             break;
00190     }
00191     addressConfig->writeConfig();
00192     notesConfig->writeConfig();
00193     todoConfig->writeConfig();
00194     calendarConfig->writeConfig();
00195 
00196     KPILOT_DELETE(addressConfig);
00197     KPILOT_DELETE(notesConfig);
00198     KPILOT_DELETE(todoConfig);
00199     KPILOT_DELETE(calendarConfig);
00200 
00201     KPilotSettings::setInstalledConduits( conduits );
00202 #undef APPEND_CONDUIT
00203 
00204     QString finishMessage = i18n("KPilot is now configured to sync with %1.").arg(applicationName);
00205     if (fMode == InDialog)
00206     {
00207         finishMessage.append(CSL1("\n"));
00208         finishMessage.append(i18n(
00209             "The remaining options in the config dialog are advanced options and can "
00210             "be used to fine-tune KPilot."));
00211     }
00212 
00213     KMessageBox::information(this, finishMessage,
00214         i18n("Automatic Configuration Finished"));
00215     KPilotSettings::self()->writeConfig();
00216     QDialog::accept();
00217 }
00218 
00219 void ConfigWizard::probeHandheld()
00220 {
00221     if ( KMessageBox::warningContinueCancel( this, i18n("Please put the handheld "
00222             "in the cradle, press the hotsync button and click on \"Continue\".\n\nSome "
00223             "kernel versions (Linux 2.6.x) have problems with the visor kernel module "
00224             "(for Sony Clie devices). Running an autodetection in that case might block "
00225             "the computer from doing hotsyncs until it is rebooted. In that case it might "
00226             "be advisable not to continue."), 
00227             i18n("Handheld Detection") ) == KMessageBox::Continue ) {
00228         ProbeDialog *probeDialog = new ProbeDialog( this );
00229         if ( probeDialog->exec() && probeDialog->detected() ) {
00230             page2->fUserName->setText( probeDialog->userName() );
00231             page2->fDeviceName->setText( probeDialog->device() );
00232             mDBs = probeDialog->dbs();
00233         }
00234         KPILOT_DELETE(probeDialog);
00235     }
00236 }
00237 
KDE Home | KDE Accessibility Home | Description of Access Keys