00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 static const char *setupDialog_id=
00037 "$Id: setupDialog.cc,v 1.31.4.6 2003/03/12 23:31:12 adridg Exp $";
00038
00039 #include "options.h"
00040
00041
00042 #include <sys/types.h>
00043 #include <sys/stat.h>
00044 #include <stdlib.h>
00045
00046 #include <qwhatsthis.h>
00047 #include <qlabel.h>
00048 #include <qcheckbox.h>
00049 #include <qlineedit.h>
00050 #include <qdir.h>
00051 #include <qbuttongroup.h>
00052 #include <qpushbutton.h>
00053 #include <qradiobutton.h>
00054 #include <qlayout.h>
00055 #include <qvbuttongroup.h>
00056
00057 #include <kconfig.h>
00058 #include <kapplication.h>
00059 #include <klocale.h>
00060 #include <kstddirs.h>
00061 #include <kdebug.h>
00062 #include <kfiledialog.h>
00063
00064 #include "popmail-factory.h"
00065 #include "setupDialog.moc"
00066
00067
00068 PopMailSendPage::PopMailSendPage(QWidget *parent) :
00069 QWidget(parent,"SendMail")
00070 {
00071 FUNCTIONSETUP;
00072 QGridLayout *grid=new QGridLayout(this,6,3,SPACING);
00073 QLabel *currentLabel;
00074
00075 sendGroup=new QVButtonGroup(i18n("Send Method"),
00076 this,"sb");
00077
00078 fNoSend=new QRadioButton(i18n("&Do not send mail"),sendGroup);
00079 fSendmail=new QRadioButton(i18n("Use &Sendmail"),sendGroup);
00080 fSMTP=new QRadioButton(i18n("Use S&MTP"),sendGroup);
00081 fKMail=new QRadioButton(i18n("Use &KMail"),sendGroup);
00082
00083 connect(fNoSend,SIGNAL(clicked()),
00084 this,SLOT(toggleMode()));
00085 connect(fSMTP,SIGNAL(clicked()),
00086 this,SLOT(toggleMode()));
00087 connect(fSendmail,SIGNAL(clicked()),
00088 this,SLOT(toggleMode()));
00089 connect(fKMail,SIGNAL(clicked()),
00090 this,SLOT(toggleMode()));
00091
00092 sendGroup->adjustSize();
00093
00094 grid->addMultiCellWidget(sendGroup,0,0,0,2);
00095
00096
00097
00098
00099
00100
00101 currentLabel = new QLabel(i18n("Email address: "),
00102 this);
00103
00104 fEmailFrom = new QLineEdit(this);
00105 fEmailFrom->resize(200, fEmailFrom->height());
00106
00107 grid->addWidget(currentLabel,1,0);
00108 grid->addWidget(fEmailFrom,1,1);
00109
00110 currentLabel = new QLabel(i18n("Signature file: "),
00111 this);
00112 currentLabel->adjustSize();
00113
00114 fSignature = new QLineEdit(this);
00115 fSignature->resize(200, fSignature->height());
00116
00117 fSignatureBrowse=new QPushButton(i18n("Browse..."),this);
00118 fSignatureBrowse->adjustSize();
00119
00120 connect(fSignatureBrowse,SIGNAL(clicked()),
00121 this,SLOT(browseSignature()));
00122
00123 grid->addWidget(currentLabel,2,0);
00124 grid->addWidget(fSignature,2,1);
00125 grid->addWidget(fSignatureBrowse,2,2);
00126
00127 currentLabel = new QLabel(i18n("Sendmail command:"), this);
00128 currentLabel->adjustSize();
00129
00130 fSendmailCmd = new QLineEdit(this);
00131 fSendmailCmd->resize(300, fSendmailCmd->height());
00132
00133 grid->addWidget(currentLabel,4,0);
00134 grid->addWidget(fSendmailCmd,4,1);
00135
00136 currentLabel = new QLabel(i18n("SMTP server:"), this);
00137 currentLabel->adjustSize();
00138
00139 fSMTPServer = new QLineEdit(this);
00140 fSMTPServer->resize(200, fSendmailCmd->height());
00141
00142 grid->addWidget(currentLabel,6,0);
00143 grid->addWidget(fSMTPServer,6,1);
00144
00145 currentLabel = new QLabel(i18n("SMTP port:"), this);
00146 currentLabel->adjustSize();
00147
00148 fSMTPPort = new QLineEdit(this);
00149 fSMTPPort->resize(200, fSendmailCmd->height());
00150
00151 grid->addWidget(currentLabel,7,0);
00152 grid->addWidget(fSMTPPort,7,1);
00153
00154 currentLabel = new QLabel(i18n("Firewall:"), this);
00155 currentLabel->adjustSize();
00156
00157 fFirewallFQDN = new QLineEdit(this);
00158 fFirewallFQDN->resize(200, fSendmailCmd->height());
00159
00160 grid->addWidget(currentLabel,9,0);
00161 grid->addWidget(fFirewallFQDN,9,1);
00162
00163 fKMailSendImmediate = new QCheckBox(
00164 i18n("Send mail through KMail immediately"),
00165 this);
00166 grid->addRowSpacing(10,SPACING);
00167 grid->addWidget(fKMailSendImmediate,11,1);
00168 QWhatsThis::add(fKMailSendImmediate,
00169 i18n("<qt>Check this box if you want the conduit "
00170 "to send all items in the outbox as soon "
00171 "as it is done, as if you clicked KMail's "
00172 "File->Send Queued menu item.</qt>"));
00173
00174
00175
00176 (void) setupDialog_id;
00177 }
00178
00179 void PopMailSendPage::readSettings(KConfig &config)
00180 {
00181 fEmailFrom->setText(config.readEntry("EmailAddress", CSL1("$USER")));
00182 fSignature->setText(config.readEntry("Signature", QString::null));
00183 fSendmailCmd->setText(config.readEntry("SendmailCmd",
00184 CSL1("/usr/lib/sendmail -t -i")));
00185 fSMTPServer->setText(config.readEntry("SMTPServer", CSL1("mail")));
00186 fSMTPPort->setText(QString::number(config.readNumEntry("SMTPPort", 25)));
00187 fFirewallFQDN->setText(config.readEntry("explicitDomainName", CSL1("$MAILDOMAIN")));
00188 fKMailSendImmediate->setChecked(config.readBoolEntry("SendImmediate",
00189 true));
00190 setMode(SendMode(config.readNumEntry(PopmailConduitFactory::syncOutgoing,SEND_NONE)));
00191 }
00192
00193 int PopMailSendPage::commitChanges(KConfig& config)
00194 {
00195 FUNCTIONSETUP;
00196
00197 #if 0
00198 if (parentSetup->queryFile(i18n("Signature File %1 is missing."),
00199 fSignature->text())!=KMessageBox::No)
00200 #endif
00201
00202 {
00203 config.writeEntry("Signature", fSignature->text());
00204 }
00205
00206 config.writeEntry("EmailAddress", fEmailFrom->text());
00207
00208
00209 config.writeEntry("SendmailCmd", fSendmailCmd->text());
00210 config.writeEntry("SMTPServer", fSMTPServer->text());
00211 config.writeEntry("SMTPPort", fSMTPPort->text());
00212 config.writeEntry("explicitDomainName", fFirewallFQDN->text());
00213
00214 config.writeEntry(PopmailConduitFactory::syncOutgoing, (int)getMode());
00215
00216 config.writeEntry("SendImmediate", fKMailSendImmediate->isChecked());
00217 return 0;
00218 }
00219
00220
00221 void PopMailSendPage::toggleMode()
00222 {
00223 if (fNoSend->isChecked()) setMode(SEND_NONE);
00224 if (fSendmail->isChecked()) setMode(SEND_SENDMAIL);
00225 if (fSMTP->isChecked()) setMode(SEND_SMTP);
00226 if (fKMail->isChecked()) setMode(SEND_KMAIL);
00227 }
00228
00229 void PopMailSendPage::setMode(SendMode m)
00230 {
00231 FUNCTIONSETUP;
00232
00233 switch(m)
00234 {
00235 case SEND_SENDMAIL :
00236 fSendmailCmd->setEnabled(true);
00237 fSMTPServer->setEnabled(false);
00238 fSMTPPort->setEnabled(false);
00239 fKMailSendImmediate->setEnabled(false);
00240 fSendmail->setChecked(true);
00241 break;
00242 case SEND_SMTP :
00243 fSendmailCmd->setEnabled(false);
00244 fSMTPServer->setEnabled(true);
00245 fSMTPPort->setEnabled(true);
00246 fKMailSendImmediate->setEnabled(false);
00247 fSMTP->setChecked(true);
00248 break;
00249 case SEND_KMAIL :
00250 fSendmailCmd->setEnabled(false);
00251 fSMTPServer->setEnabled(false);
00252 fSMTPPort->setEnabled(false);
00253 fKMailSendImmediate->setEnabled(true);
00254 fKMail->setChecked(true);
00255 break;
00256 case SEND_NONE :
00257 fSendmailCmd->setEnabled(false);
00258 fSMTPServer->setEnabled(false);
00259 fSMTPPort->setEnabled(false);
00260 fKMailSendImmediate->setEnabled(false);
00261 fNoSend->setChecked(true);
00262 break;
00263 default :
00264 kdWarning() << k_funcinfo
00265 << ": Unknown mode "
00266 << (int) m
00267 << endl;
00268 return;
00269 }
00270
00271 fMode=m;
00272 }
00273
00274
00275
00276
00277 void PopMailSendPage::browseSignature()
00278 {
00279 FUNCTIONSETUP;
00280
00281 QString filename=fSignature->text();
00282
00283 #ifdef DEBUG
00284 {
00285 DEBUGCONDUIT << fname << ": Signature currently "
00286 << fSignature->text() << endl;
00287 }
00288 #endif
00289
00290 if (filename.isEmpty())
00291 {
00292 filename=QDir::currentDirPath();
00293 }
00294 else
00295 {
00296 filename=QFileInfo( filename ).dirPath();
00297 }
00298
00299 filename = KFileDialog::getOpenFileName(filename,CSL1("*"));
00300
00301 #ifdef DEBUG
00302 {
00303 DEBUGCONDUIT << fname << ": Signature selected "
00304 << filename << endl;
00305 }
00306 #endif
00307
00308 if (!filename.isEmpty())
00309 {
00310 fSignature->setText(filename);
00311 }
00312 }
00313
00314
00315
00316 PopMailReceivePage::PopMailReceivePage(QWidget *parent) :
00317 QWidget(parent,"RecvMail")
00318 {
00319 FUNCTIONSETUP;
00320 QLabel *currentLabel;
00321 QGridLayout *grid=new QGridLayout(this,8,3,SPACING);
00322
00323 methodGroup=new QVButtonGroup(i18n("Retrieve Method"),
00324 this,"bg");
00325
00326 fNoReceive=new QRadioButton(i18n("Do ¬ receive mail"),
00327 methodGroup);
00328 fReceivePOP=new QRadioButton(i18n("Use &POP3 server"),
00329 methodGroup);
00330 fReceiveUNIX=new QRadioButton(i18n("Use &UNIX Mailbox"),
00331 methodGroup);
00332
00333 connect(fNoReceive,SIGNAL(clicked()),
00334 this,SLOT(toggleMode()));
00335 connect(fReceivePOP,SIGNAL(clicked()),
00336 this,SLOT(toggleMode()));
00337 connect(fReceiveUNIX,SIGNAL(clicked()),
00338 this,SLOT(toggleMode()));
00339 methodGroup->adjustSize();
00340
00341
00342 grid->addMultiCellWidget(methodGroup,0,0,0,2);
00343
00344 currentLabel = new QLabel(i18n("UNIX mailbox:"),this);
00345 currentLabel->adjustSize();
00346
00347 fMailbox=new QLineEdit(this);
00348 fMailbox->resize(200,fMailbox->height());
00349
00350 fMailboxBrowse=new QPushButton(i18n("Browse..."),this);
00351 fMailboxBrowse->adjustSize();
00352
00353 connect(fMailboxBrowse,SIGNAL(clicked()),
00354 this,SLOT(browseMailbox()));
00355
00356 grid->addWidget(currentLabel,1,0);
00357 grid->addWidget(fMailbox,1,1);
00358 grid->addWidget(fMailboxBrowse,1,2);
00359
00360
00361
00362
00363
00364
00365 currentLabel = new QLabel(i18n("POP server:"), this);
00366 currentLabel->adjustSize();
00367
00368 fPopServer = new QLineEdit(this);
00369 fPopServer->resize(200, fPopServer->height());
00370
00371 grid->addWidget(currentLabel,3,0);
00372 grid->addWidget(fPopServer,3,1);
00373
00374 currentLabel = new QLabel(i18n("POP port:"), this);
00375 currentLabel->adjustSize();
00376
00377 fPopPort = new QLineEdit(this);
00378 fPopPort->resize(200, fPopPort->height());
00379
00380 grid->addWidget(currentLabel,4,0);
00381 grid->addWidget(fPopPort,4,1);
00382
00383 currentLabel = new QLabel(i18n("POP username:"), this);
00384 currentLabel->adjustSize();
00385
00386 fPopUser = new QLineEdit(this);
00387 fPopUser->resize(200, fPopUser->height());
00388
00389 grid->addWidget(currentLabel,5,0);
00390 grid->addWidget(fPopUser,5,1);
00391
00392 fLeaveMail = new QCheckBox(i18n("&Leave mail on server"), this);
00393 fLeaveMail->adjustSize();
00394
00395 grid->addWidget(fLeaveMail,6,1);
00396
00397 currentLabel = new QLabel(i18n("POP password:"), this);
00398 currentLabel->adjustSize();
00399
00400 fPopPass = new QLineEdit(this);
00401 fPopPass->setEchoMode(QLineEdit::Password);
00402 fPopPass->resize(200, fPopPass->height());
00403
00404
00405 grid->addWidget(currentLabel,7,0);
00406 grid->addWidget(fPopPass,7,1);
00407
00408
00409 fStorePass = new QCheckBox(i18n("Save &POP password"), this);
00410 connect(fStorePass, SIGNAL(clicked()), this, SLOT(togglePopPass()));
00411 fStorePass->adjustSize();
00412 togglePopPass();
00413
00414 grid->addWidget(fStorePass,8,1);
00415
00416 }
00417
00418 void PopMailReceivePage::readSettings(KConfig &config)
00419 {
00420 FUNCTIONSETUP;
00421
00422 QString defaultMailbox;
00423 char *u=getenv("USER");
00424 if (u==0L)
00425 {
00426 u=getenv("HOME");
00427 if (u==0L)
00428 {
00429 defaultMailbox=CSL1("mbox");
00430 }
00431 else
00432 {
00433 defaultMailbox=QString::fromLocal8Bit(u)+CSL1("mbox");
00434 }
00435 }
00436 else
00437 {
00438 defaultMailbox=CSL1("/var/spool/mail/")+QString::fromLocal8Bit(u);
00439 }
00440
00441 fMailbox->setText(config.readEntry("UNIX Mailbox",defaultMailbox));
00442 fPopServer->setText(config.readEntry("PopServer", CSL1("pop")));
00443 fPopPort->setText(config.readEntry("PopPort", CSL1("110")));
00444 fPopUser->setText(config.readEntry("PopUser", CSL1("$USER")));
00445 fLeaveMail->setChecked(config.readNumEntry("LeaveMail", 1));
00446 fPopPass->setText(config.readEntry("PopPass", QString::null));
00447 fPopPass->setEnabled(config.readNumEntry("StorePass", 0));
00448 fStorePass->setChecked(config.readNumEntry("StorePass", 0));
00449 setMode(RetrievalMode(
00450 config.readNumEntry(PopmailConduitFactory::syncIncoming,RECV_NONE)));
00451 }
00452
00453 int PopMailReceivePage::commitChanges(KConfig& config)
00454 {
00455 FUNCTIONSETUP;
00456 config.writeEntry("UNIX Mailbox", fMailbox->text());
00457
00458 config.writeEntry("PopServer", fPopServer->text().latin1());
00459 config.writeEntry("PopPort", atoi(fPopPort->text().latin1()));
00460 config.writeEntry("PopUser", fPopUser->text().latin1());
00461 config.writeEntry("LeaveMail", (int)fLeaveMail->isChecked());
00462 config.writeEntry("StorePass", (int)fStorePass->isChecked());
00463 config.sync();
00464
00465
00466
00467 if(fStorePass->isChecked())
00468 {
00469 chmod(KGlobal::dirs()->findResource("config", CSL1("kpilotrc"))
00470 .latin1(), 0600);
00471 config.writeEntry("PopPass", fPopPass->text());
00472 }
00473 else
00474 {
00475 config.writeEntry("PopPass",QString::null);
00476 }
00477
00478 config.writeEntry(PopmailConduitFactory::syncIncoming, (int)getMode());
00479 config.sync();
00480
00481 return 0;
00482 }
00483
00484 void PopMailReceivePage::toggleMode()
00485 {
00486 if (fNoReceive->isChecked()) setMode(RECV_NONE);
00487 if (fReceivePOP->isChecked()) setMode(RECV_POP);
00488 if (fReceiveUNIX->isChecked()) setMode(RECV_UNIX);
00489 }
00490
00491 void PopMailReceivePage::setMode(RetrievalMode m)
00492 {
00493 FUNCTIONSETUP;
00494
00495 switch(m)
00496 {
00497 case RECV_NONE :
00498 fMailbox->setEnabled(false);
00499 fPopServer->setEnabled(false);
00500 fPopPort->setEnabled(false);
00501 fPopUser->setEnabled(false);
00502 fLeaveMail->setEnabled(false);
00503 fStorePass->setEnabled(false);
00504 fPopPass->setEnabled(false);
00505 fNoReceive->setChecked(true);
00506 break;
00507 case RECV_POP :
00508 fMailbox->setEnabled(false);
00509 fPopServer->setEnabled(true);
00510 fPopPort->setEnabled(true);
00511 fPopUser->setEnabled(true);
00512 fLeaveMail->setEnabled(true);
00513 fStorePass->setEnabled(true);
00514 togglePopPass();
00515 fReceivePOP->setChecked(true);
00516 break;
00517 case RECV_UNIX :
00518 fMailbox->setEnabled(true);
00519 fPopServer->setEnabled(false);
00520 fPopPort->setEnabled(false);
00521 fPopUser->setEnabled(false);
00522 fLeaveMail->setEnabled(false);
00523 fStorePass->setEnabled(false);
00524 fPopPass->setEnabled(false);
00525 fReceiveUNIX->setChecked(true);
00526 break;
00527 default :
00528 kdWarning() << k_funcinfo
00529 << ": Unknown mode " << (int) m
00530 << endl;
00531 return;
00532 }
00533
00534 fMode=m;
00535 }
00536
00537 void PopMailReceivePage::browseMailbox()
00538 {
00539 FUNCTIONSETUP;
00540
00541 QString filename=fMailbox->text();
00542
00543 #ifdef DEBUG
00544 {
00545 DEBUGCONDUIT << fname << ": Mailbox currently "
00546 << fMailbox->text() << endl;
00547 }
00548 #endif
00549
00550 if (filename.isEmpty())
00551 {
00552 filename=QDir::currentDirPath();
00553 }
00554 else
00555 {
00556 filename=QFileInfo( filename ).dirPath();
00557 }
00558
00559 filename = KFileDialog::getOpenFileName(filename,CSL1("*"));
00560
00561 #ifdef DEBUG
00562 {
00563 DEBUGCONDUIT << fname << ": Mailbox selected "
00564 << filename << endl;
00565 }
00566 #endif
00567
00568 if (!filename.isEmpty())
00569 {
00570 fMailbox->setText(filename);
00571 }
00572 }
00573
00574 void PopMailReceivePage::togglePopPass()
00575 {
00576 FUNCTIONSETUP;
00577
00578 if(fStorePass->isChecked())
00579 {
00580 fPopPass->setEnabled(true);
00581 }
00582 else
00583 {
00584 fPopPass->setEnabled(false);
00585 }
00586 }
00587
00588
00589 #if 0
00590 const QString PopMailOptions::PopGroup("popmailOptions");
00591
00592 PopMailOptions::PopMailOptions(QWidget *parent) :
00593 setupDialog(parent, PopGroup,
00594 PopMailConduit::version())
00595 {
00596 FUNCTIONSETUP;
00597 setupWidget();
00598 setupDialog::setupWidget();
00599 }
00600
00601 PopMailOptions::~PopMailOptions()
00602 {
00603 FUNCTIONSETUP;
00604
00605 }
00606
00607
00608
00609
00610
00611
00612
00613 void
00614 PopMailOptions::setupWidget()
00615 {
00616 FUNCTIONSETUP;
00617
00618 KConfig& config = KPilotConfig::getConfig();
00619 config.setGroup(PopGroup);
00620
00621
00622 addPage(new PopMailSendPage(this,config));
00623 addPage(new PopMailReceivePage(this,config));
00624 addPage(new setupInfoPage(this));
00625 }
00626 #endif
00627
00628