kmail Library API Documentation

startupwizard.cpp

00001 /* 00002 This file is part of KMail. 00003 00004 Copyright (c) 2003 - 2004 Bo Thorsen <bo@klaralvdalens-datakonsult.se> 00005 Copyright (c) 2003 Steffen Hansen <steffen@klaralvdalens-datakonsult.se> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00020 Boston, MA 02111-1307, USA. 00021 00022 In addition, as a special exception, the copyright holders give 00023 permission to link the code of this program with any edition of 00024 the Qt library by Trolltech AS, Norway (or with modified versions 00025 of Qt that use the same license as Qt), and distribute linked 00026 combinations including the two. You must obey the GNU General 00027 Public License in all respects for all of the code used other than 00028 Qt. If you modify this file, you may extend this exception to 00029 your version of the file, but you are not obligated to do so. If 00030 you do not wish to do so, delete this exception statement from 00031 your version. 00032 */ 00033 00034 #ifdef HAVE_CONFIG_H 00035 #include <config.h> 00036 #endif 00037 00038 #include "startupwizard.h" 00039 00040 #include "kmfoldercombobox.h" 00041 #include "configuredialog_p.h" 00042 #include "kmacctmgr.h" 00043 #include "kmcomposewin.h" 00044 #include "kmfoldermgr.h" 00045 #include "kmacctcachedimap.h" 00046 #include "kmfoldercachedimap.h" 00047 #include <libkpimidentities/identity.h> 00048 #include <libkpimidentities/identitymanager.h> 00049 #include "kmtransport.h" 00050 #include "kmsender.h" 00051 #include "kmgroupware.h" 00052 #include "kmkernel.h" 00053 #include "kmailicalifaceimpl.h" 00054 #include "globalsettings.h" 00055 00056 #include <kdebug.h> 00057 #include <klocale.h> 00058 #include <knuminput.h> 00059 #include <kapplication.h> 00060 #include <kconfig.h> 00061 00062 #include <qvbox.h> 00063 #include <qvbuttongroup.h> 00064 #include <qtextbrowser.h> 00065 #include <qwhatsthis.h> 00066 #include <qvalidator.h> 00067 00068 WizardIdentityPage::WizardIdentityPage( QWidget * parent, const char * name ) 00069 : QWidget( parent, name ) 00070 { 00071 // First either get the default identity or make a new one 00072 KPIM::IdentityManager *im = kmkernel->identityManager(); 00073 if( im->identities().count() > 0 ) 00074 mIdentity = im->defaultIdentity().uoid(); 00075 else { 00076 mIdentity = im->newFromScratch( "Kolab Identity" ).uoid(); 00077 im->setAsDefault( mIdentity ); 00078 } 00079 00080 KPIM::Identity & ident = im->identityForUoid( mIdentity ); 00081 00082 QGridLayout *grid = new QGridLayout( this, 3, 2, KDialog::marginHint(), 00083 KDialog::spacingHint() ); 00084 grid->addColSpacing( 1, fontMetrics().maxWidth()*15 ); 00085 grid->setRowStretch( 15, 10 ); 00086 grid->setColStretch( 1, 10 ); 00087 00088 QLabel *label = new QLabel( i18n("&Your name:"), this ); 00089 QWhatsThis::add( label, i18n("Write your name here.") ); 00090 grid->addWidget( label, 0, 0 ); 00091 nameEdit = new QLineEdit( ident.fullName(), this ); 00092 nameEdit->setFocus(); 00093 label->setBuddy( nameEdit ); 00094 grid->addWidget( nameEdit, 0, 1 ); 00095 00096 label = new QLabel( i18n("Organi&zation:"), this ); 00097 QWhatsThis::add( label, i18n("You can write the company or organization you work for.") ); 00098 grid->addWidget( label, 1, 0 ); 00099 orgEdit = new QLineEdit( ident.organization(), this ); 00100 label->setBuddy( orgEdit ); 00101 grid->addWidget( orgEdit, 1, 1 ); 00102 00103 label = new QLabel( i18n("&Email address:"), this ); 00104 grid->addWidget( label, 2, 0 ); 00105 emailEdit = new QLineEdit( ident.emailAddr(), this ); 00106 label->setBuddy( emailEdit ); 00107 grid->addWidget( emailEdit, 2, 1 ); 00108 } 00109 00110 void WizardIdentityPage::apply() const { 00111 // Save the identity settings 00112 KPIM::Identity & ident = identity(); 00113 ident.setFullName( nameEdit->text().stripWhiteSpace() ); 00114 ident.setOrganization( orgEdit->text().stripWhiteSpace() ); 00115 ident.setEmailAddr( emailEdit->text().stripWhiteSpace() ); 00116 kmkernel->identityManager()->sort(); 00117 kmkernel->identityManager()->commit(); 00118 } 00119 00120 KPIM::Identity & WizardIdentityPage::identity() const { 00121 return kmkernel->identityManager()->identityForUoid( mIdentity ); 00122 } 00123 00124 WizardKolabPage::WizardKolabPage( QWidget * parent, const char * name ) 00125 : QWidget( parent, name ), mFolder(0), mAccount(0), mTransport( 0 ) 00126 { 00127 QGridLayout *grid = new QGridLayout( this, 7, 2, KDialog::marginHint(), 00128 KDialog::spacingHint() ); 00129 grid->addColSpacing( 1, fontMetrics().maxWidth()*15 ); 00130 grid->setRowStretch( 15, 10 ); 00131 grid->setColStretch( 1, 10 ); 00132 00133 QLabel *label = new QLabel( i18n("&Login:"), this ); 00134 QWhatsThis::add( label, i18n("Your Internet Service Provider gave you a <em>user name</em> which is used to authenticate you with their servers. It usually is the first part of your email address (the part before <em>@</em>).") ); 00135 grid->addWidget( label, 0, 0 ); 00136 loginEdit = new QLineEdit( this ); 00137 label->setBuddy( loginEdit ); 00138 grid->addWidget( loginEdit, 0, 1 ); 00139 00140 label = new QLabel( i18n("P&assword:"), this ); 00141 grid->addWidget( label, 1, 0 ); 00142 passwordEdit = new QLineEdit( this ); 00143 passwordEdit->setEchoMode( QLineEdit::Password ); 00144 label->setBuddy( passwordEdit ); 00145 grid->addWidget( passwordEdit, 1, 1 ); 00146 00147 label = new QLabel( i18n("Ho&st:"), this ); 00148 grid->addWidget( label, 2, 0 ); 00149 hostEdit = new QLineEdit( this ); 00150 // only letters, digits, '-', '.', ':' (IPv6) and '_' (for Windows 00151 // compatibility) are allowed 00152 hostEdit->setValidator(new QRegExpValidator( QRegExp( "[A-Za-z0-9-_:.]*" ), 0 ) ); 00153 label->setBuddy( hostEdit ); 00154 grid->addWidget( hostEdit, 2, 1 ); 00155 00156 storePasswordCheck = 00157 new QCheckBox( i18n("Sto&re IMAP password in configuration file"), this ); 00158 storePasswordCheck->setChecked( true ); 00159 grid->addMultiCellWidget( storePasswordCheck, 3, 3, 0, 1 ); 00160 00161 excludeCheck = new QCheckBox( i18n("E&xclude from \"Check Mail\""), this ); 00162 grid->addMultiCellWidget( excludeCheck, 4, 4, 0, 1 ); 00163 00164 intervalCheck = new QCheckBox( i18n("Enable &interval mail checking"), this ); 00165 intervalCheck->setChecked( true ); 00166 grid->addMultiCellWidget( intervalCheck, 5, 5, 0, 2 ); 00167 intervalLabel = new QLabel( i18n("Check inter&val:"), this ); 00168 grid->addWidget( intervalLabel, 6, 0 ); 00169 intervalSpin = new KIntNumInput( this ); 00170 intervalSpin->setRange( 1, 60, 1, FALSE ); 00171 intervalSpin->setValue( 1 ); 00172 intervalSpin->setSuffix( i18n( " min" ) ); 00173 intervalLabel->setBuddy( intervalSpin ); 00174 connect( intervalCheck, SIGNAL(toggled(bool)), intervalSpin, SLOT(setEnabled(bool)) ); 00175 grid->addWidget( intervalSpin, 6, 1 ); 00176 } 00177 00178 void WizardKolabPage::init( const QString &email ) 00179 { 00180 static bool first = true; 00181 if( !first ) return; 00182 first = false; 00183 00184 // Workaround since Qt can't have default focus on more than one page 00185 loginEdit->setFocus(); 00186 00187 int at = email.find('@'); 00188 if( at > 1 && email.length() > (uint)at ) { 00189 // Set reasonable login and host defaults 00190 loginEdit->setText( email ); 00191 hostEdit->setText( email.mid( at + 1 ) ); 00192 } 00193 } 00194 00195 void WizardKolabPage::apply() 00196 { 00197 // Handle the account 00198 if( mAccount == 0 ) { 00199 // Create the account 00200 mAccount = static_cast<KMAcctCachedImap*> 00201 ( kmkernel->acctMgr()->create( QString("cachedimap"), "Kolab" ) ); 00202 mAccount->init(); // fill the account fields with good default values 00203 kmkernel->acctMgr()->add(mAccount); 00204 00205 // Set all default settings 00206 // TODO: read these from a system wide settings file 00207 mAccount->setAuth( "PLAIN" ); 00208 mAccount->setPrefix( "/" ); 00209 mAccount->setUseSSL( false ); 00210 mAccount->setUseTLS( true ); 00211 mAccount->setSieveConfig( KMail::SieveConfig( true ) ); 00212 kmkernel->cleanupImapFolders(); 00213 assert( mAccount->folder() ); 00214 00215 // This Must Be False!! 00216 mAccount->setAutoExpunge( false ); 00217 } 00218 00219 mAccount->setLogin( loginEdit->text().stripWhiteSpace() ); 00220 mAccount->setPasswd( passwordEdit->text() ); 00221 mAccount->setHost( hostEdit->text().stripWhiteSpace() ); 00222 mAccount->setStorePasswd( storePasswordCheck->isChecked() ); 00223 mAccount->setCheckExclude( excludeCheck->isChecked() ); 00224 00225 kmkernel->acctMgr()->writeConfig( false ); 00226 00227 // Sync new IMAP account ASAP 00228 kdDebug(5006) << mAccount->folder()->name() << endl; 00229 00230 if( mFolder == 0 ) { 00231 KMFolderDir *child = mAccount->folder()->child(); 00232 if( child == 0 ) 00233 child = mAccount->folder()->createChildFolder(); 00234 00235 mFolder = kmkernel->dimapFolderMgr()-> 00236 createFolder( "INBOX", false, KMFolderTypeCachedImap, child ); 00237 static_cast<KMFolderCachedImap*>(mFolder)->setSilentUpload( true ); 00238 } 00239 if ( !mAccount->checkingMail() ) { 00240 mAccount->setCheckingMail( true ); 00241 mAccount->processNewMail( false ); 00242 } 00243 00244 // Handle SMTP transport 00245 if( mTransport == 0 ) { 00246 mTransport = new KMTransportInfo(); 00247 mTransport->type = "smtp"; 00248 mTransport->name = "Kolab"; 00249 mTransport->port = "25"; 00250 mTransport->encryption = "TLS"; 00251 mTransport->authType = "PLAIN"; 00252 mTransport->auth = true; 00253 mTransport->precommand = ""; 00254 } 00255 00256 mTransport->host = hostEdit->text().stripWhiteSpace(); 00257 mTransport->user = loginEdit->text().stripWhiteSpace(); 00258 mTransport->pass = passwordEdit->text(); 00259 mTransport->storePass = storePasswordCheck->isChecked(); 00260 00261 // Save transports: 00262 KConfigGroup general( KMKernel::config(), "General" ); 00263 KConfigGroup composer( KMKernel::config(), "Composer" ); 00264 // TODO: Set more transports 00265 general.writeEntry( "transports", 1/*mTransportInfoList.count()*/ ); 00266 // QPtrListIterator<KMTransportInfo> it( mTransportInfoList ); 00267 // for ( int i = 1 ; it.current() ; ++it, ++i ) 00268 // (*it)->writeConfig(i); 00269 mTransport->writeConfig(1); 00270 00271 // Save common options: 00272 general.writeEntry( "sendOnCheck", false ); 00273 kmkernel->msgSender()->setSendImmediate( true ); 00274 } 00275 00276 00277 StartupWizard::StartupWizard( QWidget* parent, const char* name, bool modal ) 00278 : QWizard( parent, name, modal ), mGroupwareEnabled(true) 00279 { 00280 addPage( mIntroPage = createIntroPage(), i18n("Groupware Functionality for KMail") ); 00281 addPage( mIdentityPage = createIdentityPage(), i18n("Your Identity") ); 00282 addPage( mKolabPage = createKolabPage(), i18n("Kolab Groupware Settings") ); 00283 addPage( mAccountPage = createAccountPage(), i18n("Accounts") ); 00284 addPage( mFolderSelectionPage = createFolderSelectionPage(), i18n("Folder Selection") ); 00285 addPage( mLanguagePage = createLanguagePage(), i18n("Folder Language") ); 00286 addPage( mFolderCreationPage = createFolderCreationPage(), i18n("Folder Creation") ); 00287 addPage( mOutroPage = createOutroPage(), i18n("Done") ); 00288 } 00289 00290 int StartupWizard::language() const 00291 { 00292 return mLanguageCombo->currentItem(); 00293 } 00294 00295 KMFolder* StartupWizard::folder() const 00296 { 00297 if( groupwareEnabled() && useDefaultKolabSettings() ) 00298 return mKolabWidget->folder(); 00299 else 00300 return mFolderCombo->getFolder(); 00301 } 00302 00303 void StartupWizard::setAppropriatePages() 00304 { 00305 setAppropriate( mKolabPage, groupwareEnabled() && useDefaultKolabSettings() ); 00306 setAppropriate( mAccountPage, !groupwareEnabled() || !useDefaultKolabSettings() ); 00307 setAppropriate( mLanguagePage, groupwareEnabled() ); 00308 setAppropriate( mFolderSelectionPage, groupwareEnabled() && !useDefaultKolabSettings() ); 00309 setAppropriate( mFolderCreationPage, groupwareEnabled() ); 00310 setAppropriate( mOutroPage, !groupwareEnabled() ); 00311 setNextEnabled( mOutroPage, false); 00312 setFinishEnabled( mOutroPage, true ); 00313 setFinishEnabled( mFolderCreationPage, true ); 00314 } 00315 00316 void StartupWizard::slotGroupwareEnabled( int i ) 00317 { 00318 mGroupwareEnabled = (i == 0); 00319 serverSettings->setEnabled( mGroupwareEnabled ); 00320 } 00321 00322 void StartupWizard::slotServerSettings( int i ) 00323 { 00324 mUseDefaultKolabSettings = (i == 0); 00325 } 00326 00327 QWidget* StartupWizard::createIntroPage() 00328 { 00329 QWidget* page = new QWidget(this, "intro_page"); 00330 QBoxLayout* top = new QHBoxLayout( page ); 00331 QTextBrowser* text = new QTextBrowser( page ); 00332 text->setText( i18n("<b>You do not seem to have any groupware folders " 00333 "configured in KMail.</b><br>" 00334 "This is probably because you are running KMail for the first time, or " 00335 "because you have enabled the groupware functionality for the first time.<br>" 00336 "You now have the choice between disabling the groupware functionality, " 00337 "or leaving it enabled and going through this wizard.<br>" 00338 "If you disable the groupware functionality for now, you can always enable it again from " 00339 "the KMail configure dialog.")); 00340 top->addWidget( text ); 00341 00342 QVBox* rightSide = new QVBox( page ); 00343 top->addWidget( rightSide, 1 ); 00344 00345 QButtonGroup* bg = new QVButtonGroup( i18n("Groupware Functions"), rightSide ); 00346 00347 (new QRadioButton( i18n("Enable groupware functions"), bg ))->setChecked( TRUE ); 00348 (void)new QRadioButton( i18n("Disable groupware functions"), bg ); 00349 connect( bg, SIGNAL( clicked(int) ), this, SLOT( slotGroupwareEnabled(int) ) ); 00350 00351 bg = serverSettings = new QVButtonGroup( i18n("Groupware Server Setup"), rightSide ); 00352 (new QRadioButton( i18n("Use standard groupware server settings"), bg ))->setChecked(TRUE); 00353 (void)new QRadioButton( i18n("Advanced server setup"), bg ); 00354 connect( bg, SIGNAL( clicked(int) ), this, SLOT(slotServerSettings(int) ) ); 00355 00356 // Set the groupware setup to the right settings 00357 slotGroupwareEnabled( 0 ); 00358 slotServerSettings( 0 ); 00359 setHelpEnabled( page, false ); 00360 setBackEnabled( page, false ); 00361 return page; 00362 } 00363 00364 QWidget* StartupWizard::createIdentityPage() 00365 { 00366 QWidget* page = new QWidget( this, "identity_page" ); 00367 QBoxLayout* top = new QHBoxLayout( page ); 00368 QTextBrowser* text = new QTextBrowser( page ); 00369 text->setText( i18n("Please set at least your name and email address.") ); 00370 top->addWidget( text ); 00371 00372 mIdentityWidget = new WizardIdentityPage( page, "identity_page" ); 00373 top->addWidget( mIdentityWidget, 1 ); 00374 setHelpEnabled( page, false ); 00375 return page; 00376 } 00377 00378 QWidget* StartupWizard::createKolabPage() 00379 { 00380 QWidget* page = new QWidget( this, "kolabserver_page" ); 00381 QBoxLayout* top = new QHBoxLayout( page ); 00382 QTextBrowser* text = new QTextBrowser( page ); 00383 text->setText( i18n("If the groupware server is a kolab server with default" 00384 " settings, you only need to set these settings.") ); 00385 top->addWidget( text ); 00386 00387 mKolabWidget = new WizardKolabPage( page, "kolabserver_page" ); 00388 top->addWidget( mKolabWidget, 1 ); 00389 setHelpEnabled( page, false ); 00390 return page; 00391 } 00392 00393 QWidget* StartupWizard::createAccountPage() 00394 { 00395 QWidget* page = new QWidget( this, "account_page"); 00396 QBoxLayout* top = new QHBoxLayout( page ); 00397 QTextBrowser* text = new QTextBrowser( page ); 00398 text->setText(i18n("If you want, you can create new accounts before going on with" 00399 " groupware configuration.")); 00400 top->addWidget( text ); 00401 00402 mAccountWidget = new NetworkPage( page, "account_page" ); 00403 mAccountWidget->setup(); 00404 top->addWidget( mAccountWidget, 1 ); 00405 setHelpEnabled( page, false ); 00406 return page; 00407 } 00408 00409 QWidget* StartupWizard::createLanguagePage() 00410 { 00411 QWidget* page = new QWidget(this, "language_page"); 00412 QBoxLayout* top = new QHBoxLayout( page ); 00413 QTextBrowser* text = new QTextBrowser( page ); 00414 text->setText( i18n("If you want to make your groupware folders work with other " 00415 "applications, you might want to select a different language " 00416 "than English.<br>" 00417 "If this is not an issue, leave the language as is.")); 00418 top->addWidget( text ); 00419 00420 QVBox* rightSide = new QVBox( page ); 00421 top->addWidget( rightSide, 1 ); 00422 00423 mLanguageLabel = new QLabel( rightSide ); 00424 00425 mLanguageCombo = new QComboBox( false, rightSide ); 00426 00427 QStringList lst; 00428 lst << i18n("English") << i18n("German") << i18n("French") << i18n("Dutch"); 00429 mLanguageCombo->insertStringList( lst ); 00430 00431 setLanguage( 0, false ); 00432 setHelpEnabled( page, false ); 00433 return page; 00434 } 00435 00436 QWidget* StartupWizard::createFolderSelectionPage() 00437 { 00438 QWidget* page = new QWidget(this, "foldersel_page"); 00439 QBoxLayout* top = new QHBoxLayout( page ); 00440 QTextBrowser* text = new QTextBrowser( page ); 00441 text->setText(i18n("The groupware functionality needs some special folders to store " 00442 "the contents of the calendar, contacts, tasks etc.<br>" 00443 "Please select the folder that the groupware folders should " 00444 "be subfolders of.")); 00445 top->addWidget( text ); 00446 mFolderCombo = new KMFolderComboBox( page ); 00447 top->addWidget( mFolderCombo, 1 ); 00448 connect( mFolderCombo, SIGNAL( activated(int) ), 00449 this, SLOT( slotUpdateParentFolderName() ) ); 00450 setHelpEnabled( page, false ); 00451 return page; 00452 } 00453 00454 void StartupWizard::slotUpdateParentFolderName() 00455 { 00456 KMFolder* folder = mFolderCombo->getFolder(); 00457 QString fldrName = i18n("<unnamed>"); 00458 if( folder ) fldrName = folder->name(); 00459 mFolderCreationText 00460 ->setText( i18n("You have chosen the folder <b>%1</b> as parent of the " 00461 "groupware folders. When pressing the Finish button, " 00462 "those folders will be created if " 00463 "they do not already exist").arg( fldrName )); 00464 } 00465 00466 void StartupWizard::setLanguage( int language, bool guessed ) 00467 { 00468 mLanguageCombo->setCurrentItem( language ); 00469 if( guessed ) { 00470 mLanguageLabel->setText( i18n("The folders present indicates that you want to use the selected folder language")); 00471 } else { 00472 mLanguageLabel->setText( i18n("The folder language cannot be guessed, please select a language:")); 00473 } 00474 } 00475 00476 QWidget* StartupWizard::createFolderCreationPage() 00477 { 00478 QHBox* page = new QHBox(this, "foldercre_page"); 00479 mFolderCreationText = new QTextBrowser( page ); 00480 slotUpdateParentFolderName(); 00481 setFinishEnabled( page, true ); 00482 setNextEnabled( page, false); 00483 setHelpEnabled( page, false ); 00484 return page; 00485 } 00486 00487 QWidget* StartupWizard::createOutroPage() 00488 { 00489 QHBox* page = new QHBox(this, "outtro_page"); 00490 QTextBrowser* text = new QTextBrowser( page ); 00491 text->setText( i18n("The groupware functionality has been disabled.") ); 00492 setFinishEnabled( page, true ); 00493 setNextEnabled( page, false); 00494 setHelpEnabled( page, false ); 00495 return page; 00496 } 00497 00498 void StartupWizard::back() 00499 { 00500 QWizard::back(); 00501 } 00502 00503 void StartupWizard::next() 00504 { 00505 if( currentPage() == mAccountPage ) { 00506 kdDebug(5006) << "AccountPage appropriate: " << appropriate(mAccountPage) << endl; 00507 mAccountWidget->apply(); 00508 } else if( currentPage() == mFolderSelectionPage ) { 00509 /* Find the list of folders and guess the language */ 00510 guessExistingFolderLanguage(); 00511 } else if( currentPage() == mKolabPage ) { 00512 // Apply all settings to the account 00513 mKolabWidget->apply(); 00514 /* Find the list of folders and guess the language */ 00515 // TODO: guessExistingFolderLanguage(); 00516 00517 // Finally, just set the message at the end of the wizard 00518 mFolderCreationText->setText( i18n("You have chosen to use standard kolab settings.\nPress Finish to proceed.") ); 00519 00520 } else if( currentPage() == mIdentityPage ) { 00521 mIdentityWidget->apply(); 00522 mKolabWidget->init( userIdentity().emailAddr() ); 00523 } 00524 00525 // Set which ones apply, given the present state of answers 00526 setAppropriatePages(); 00527 00528 QWizard::next(); 00529 } 00530 00531 static bool checkSubfolders( KMFolderDir* dir, int language ) 00532 { 00533 KMailICalIfaceImpl& ical = kmkernel->iCalIface(); 00534 return dir->hasNamedFolder( ical.folderName( KFolderTreeItem::Inbox, language ) ) && 00535 dir->hasNamedFolder( ical.folderName( KFolderTreeItem::Calendar, language ) ) && 00536 dir->hasNamedFolder( ical.folderName( KFolderTreeItem::Contacts, language ) ) && 00537 dir->hasNamedFolder( ical.folderName( KFolderTreeItem::Notes, language ) ) && 00538 dir->hasNamedFolder( ical.folderName( KFolderTreeItem::Tasks, language ) ); 00539 } 00540 00541 void StartupWizard::guessExistingFolderLanguage() 00542 { 00543 KMFolderDir* dir = folder()->child(); 00544 00545 if( checkSubfolders( dir, 0 ) ) { 00546 // Check English 00547 setLanguage( 0, true ); 00548 } else if( checkSubfolders( dir, 1 ) ) { 00549 // Check German 00550 setLanguage( 1, true ); 00551 } else { 00552 setLanguage( 0, false ); 00553 } 00554 } 00555 00556 KPIM::Identity &StartupWizard::userIdentity() 00557 { 00558 return mIdentityWidget->identity(); 00559 } 00560 00561 const KPIM::Identity &StartupWizard::userIdentity() const 00562 { 00563 return mIdentityWidget->identity(); 00564 } 00565 00566 QString StartupWizard::name() const 00567 { 00568 return userIdentity().fullName(); 00569 } 00570 00571 QString StartupWizard::login() const 00572 { 00573 return mKolabWidget->loginEdit->text().stripWhiteSpace(); 00574 } 00575 00576 QString StartupWizard::host() const 00577 { 00578 return mKolabWidget->hostEdit->text().stripWhiteSpace(); 00579 } 00580 00581 QString StartupWizard::email() const 00582 { 00583 return userIdentity().emailAddr(); 00584 } 00585 00586 QString StartupWizard::passwd() const 00587 { 00588 return KMAccount::encryptStr( mKolabWidget->passwordEdit->text() ); 00589 } 00590 00591 bool StartupWizard::storePasswd() const 00592 { 00593 return mKolabWidget->storePasswordCheck->isChecked(); 00594 } 00595 00596 00597 void StartupWizard::run() 00598 { 00599 /* 00600 * 00601 * FIXME the below is no longer up to date. If you, dear reader are here 00602 * because you want to fix it, know this: 00603 * 00604 * 1 ) I applaud your efforts : ) 00605 * 2 ) please look in kmail.kcfg and use KConfigXT 00606 * 00607 */ 00608 KConfigGroup options( KMKernel::config(), "Groupware" ); 00609 00610 // Check if this wizard was previously run 00611 if( options.readEntry( "Enabled", "notset" ) != "notset" ) 00612 return; 00613 00614 StartupWizard wiz(0, "groupware wizard", TRUE ); 00615 int rc = wiz.exec(); 00616 00617 options.writeEntry( "Enabled", rc == QDialog::Accepted && wiz.groupwareEnabled() ); 00618 if( rc == QDialog::Accepted ) { 00619 options.writeEntry( "FolderLanguage", wiz.language() ); 00620 options.writeEntry( "GroupwareFolder", wiz.folder()->idString() ); 00621 00622 kmkernel->groupware().readConfig(); 00623 00624 if( wiz.groupwareEnabled() && wiz.useDefaultKolabSettings() ) { 00625 // Write the apps configs 00626 writeKOrganizerConfig( wiz ); 00627 writeKAbcConfig(); 00628 writeKAddressbookConfig( wiz ); 00629 } 00630 } 00631 } 00632 00633 00634 // Write the KOrganizer settings 00635 void StartupWizard::writeKOrganizerConfig( const StartupWizard& wiz ) { 00636 KConfig config( "korganizerrc" ); 00637 00638 KConfigGroup optionsKOrgGeneral( &config, "Personal Settings" ); 00639 optionsKOrgGeneral.writeEntry( "user_name", wiz.name() ); 00640 optionsKOrgGeneral.writeEntry( "user_email", wiz.email() ); 00641 00642 KConfigGroup optionsKOrgGroupware( &config, "Groupware" ); 00643 optionsKOrgGroupware.writeEntry( "Publish FreeBusy lists", true ); 00644 optionsKOrgGroupware.writeEntry( "Publish FreeBusy days", 60 ); 00645 optionsKOrgGroupware.writeEntry( "Publish to Kolab server", true ); 00646 optionsKOrgGroupware.writeEntry( "Publish to Kolab server name", wiz.host() ); 00647 optionsKOrgGroupware.writeEntry( "Publish user name", wiz.login() ); 00648 optionsKOrgGroupware.writeEntry( "Remember publish password", wiz.storePasswd() ); 00649 if( wiz.storePasswd() ) { 00650 optionsKOrgGroupware.writeEntry( "Publish Server Password", wiz.passwd() ); 00651 optionsKOrgGroupware.writeEntry( "Retrieve Server Password", wiz.passwd() ); 00652 } 00653 optionsKOrgGroupware.writeEntry( "Retrieve FreeBusy lists", true ); 00654 optionsKOrgGroupware.writeEntry( "Retrieve from Kolab server", true ); 00655 optionsKOrgGroupware.writeEntry( "Retrieve from Kolab server name", wiz.host() ); 00656 optionsKOrgGroupware.writeEntry( "Retrieve user name", wiz.login() ); 00657 optionsKOrgGroupware.writeEntry( "Remember retrieve password", wiz.storePasswd() ); 00658 00659 config.sync(); 00660 } 00661 00662 00663 // Write the KABC settings 00664 void StartupWizard::writeKAbcConfig() { 00665 KConfig config( "kabcrc" ); 00666 KConfigGroup optionsKAbcGeneral( &config, "General" ); 00667 QString standardKey = optionsKAbcGeneral.readEntry( "Standard" ); 00668 QString newStandardKey; 00669 00670 QStringList activeKeys = optionsKAbcGeneral.readListEntry( "ResourceKeys" ); 00671 QStringList passiveKeys = optionsKAbcGeneral.readListEntry( "PassiveResourceKeys" ); 00672 QStringList keys = activeKeys + passiveKeys; 00673 for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) { 00674 KConfigGroup entry( &config, "Resource_" + (*it) ); 00675 if( entry.readEntry( "ResourceType" ) == "imap" && newStandardKey.isNull() ) { 00676 // This is the IMAP resource that must now be the standard 00677 newStandardKey = *it; 00678 00679 // We want to be able to write to this 00680 entry.writeEntry( "ResourceIsReadOnly", false ); 00681 } else 00682 // Not an IMAP resource, so don't write to it anymore 00683 entry.writeEntry( "ResourceIsReadOnly", true ); 00684 } 00685 00686 if( newStandardKey.isNull() ) { 00687 // No IMAP resource was found, make one 00688 newStandardKey = KApplication::randomString( 10 ); 00689 KConfigGroup entry( &config, "Resource_" + newStandardKey ); 00690 entry.writeEntry( "ResourceName", "imap-resource" ); 00691 entry.writeEntry( "ResourceType", "imap" ); 00692 entry.writeEntry( "ResourceIsReadOnly", false ); 00693 entry.writeEntry( "ResourceIsFast", true ); 00694 activeKeys += newStandardKey; 00695 } else if( passiveKeys.remove( newStandardKey ) > 0 ) 00696 // This used to be passive. Make it active 00697 activeKeys += newStandardKey; 00698 00699 // Set the keys 00700 optionsKAbcGeneral.writeEntry( "ResourceKeys", activeKeys ); 00701 optionsKAbcGeneral.writeEntry( "PassiveResourceKeys", passiveKeys ); 00702 optionsKAbcGeneral.writeEntry( "Standard", newStandardKey ); 00703 00704 config.sync(); 00705 } 00706 00707 00708 // Write the KAddressbook settings 00709 void StartupWizard::writeKAddressbookConfig( const StartupWizard& wiz ) { 00710 KConfig config( "kaddressbookrc" ); 00711 KConfigGroup options( &config, "LDAP" ); 00712 00713 QString hostBase = QString( "dc=" ) + wiz.host(); 00714 hostBase.replace( '.', ",dc=" ); 00715 00716 // Read all servers and try finding one that matches us 00717 uint count = options.readUnsignedNumEntry( "NumSelectedHosts"); 00718 for ( uint i = 0; i < count; ++i ) { 00719 QString host = options.readEntry( QString( "SelectedHost%1").arg( i ) ); 00720 int port = options.readUnsignedNumEntry( QString( "SelectedPort%1" ).arg( i ) ); 00721 QString base = options.readEntry( QString( "SelectedBase%1" ).arg( i ) ); 00722 00723 if( host == wiz.host() && port == 389 && base == hostBase ) 00724 // We found a match, and it's selected 00725 return; 00726 } 00727 00728 // No match among the selected ones, try the unselected 00729 count = options.readUnsignedNumEntry( "NumHosts" ); 00730 for ( uint i = 0; i < count; ++i ) { 00731 QString host = options.readEntry( QString( "SelectedHost%1").arg( i ) ); 00732 int port = options.readUnsignedNumEntry( QString( "SelectedPort%1" ).arg( i ) ); 00733 QString base = options.readEntry( QString( "SelectedBase%1" ).arg( i ) ); 00734 00735 if( host == wiz.host() && port == 389 && base == hostBase ) { 00736 // We found a match. Remove it from this list 00737 for( ++i; i < count; ++i ) { 00738 host = options.readEntry( QString( "Host%1" ).arg( i ) ); 00739 port = options.readUnsignedNumEntry( QString( "Port%1" ).arg( i ) ); 00740 base = options.readEntry( QString( "Base%1" ).arg( i ) ); 00741 options.writeEntry( QString( "Host%1" ).arg( i-1 ), host ); 00742 options.writeEntry( QString( "Port%1" ).arg( i-1 ), port ); 00743 options.writeEntry( QString( "Base%1" ).arg( i-1 ), base ); 00744 } 00745 00746 // Now all the previous ones were overwritten, so remove the last one 00747 --count; 00748 options.deleteEntry( QString( "Host%1" ).arg( count ) ); 00749 options.deleteEntry( QString( "Port%1" ).arg( count ) ); 00750 options.deleteEntry( QString( "Base%1" ).arg( count ) ); 00751 options.writeEntry( "NumHosts", count ); 00752 break; 00753 } 00754 } 00755 00756 // Now write the selected ldap server 00757 count = options.readUnsignedNumEntry( "NumSelectedHosts"); 00758 options.writeEntry( QString( "SelectedHost%1" ).arg( count ), wiz.host() ); 00759 options.writeEntry( QString( "SelectedPort%1" ).arg( count ), 389 ); 00760 options.writeEntry( QString( "SelectedBase%1" ).arg( count ), hostBase ); 00761 options.writeEntry( "NumSelectedHosts", count+1 ); 00762 } 00763 00764 00765 #include "startupwizard.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:52:53 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003