00001 #include <qmessagebox.h>
00002 #include <qpushbutton.h>
00003 #include <qtoolbutton.h>
00004 #include <qgroupbox.h>
00005 #include <qcheckbox.h>
00006 #include <qspinbox.h>
00007 #include <qheader.h>
00008 #include <qtimer.h>
00009 #include <qlabel.h>
00010
00011 #include <qpe/resource.h>
00012 #include <qpe/config.h>
00013
00014 #include "accounteditor.h"
00015 #include "configdiag.h"
00016 #include "defines.h"
00017
00018 AccountListItem::AccountListItem(QListView *parent, Account &account)
00019 : QListViewItem(parent), _account(account)
00020 {
00021 QString displayText;
00022 if (!_account.realName().isEmpty() && !_account.email().isEmpty())
00023 setText(0, _account.realName() + " <" + _account.email() + ">");
00024 else if (_account.realName().isEmpty() && !_account.email().isEmpty())
00025 setText(0, _account.email());
00026 else if (!_account.realName().isEmpty() && _account.email().isEmpty())
00027 setText(0, _account.realName());
00028 else
00029 setText(0, QObject::tr("(no name)"));
00030
00031 setPixmap(0, Resource::loadPixmap("mail/inbox"));
00032 }
00033
00034 ConfigDiag::ConfigDiag(QWidget *parent, const char *name, bool modal, WFlags fl)
00035 : ConfigDiagBase(parent, name, modal, fl)
00036 {
00037 _configBenD = new Config("mail");
00038 _configBenD->setGroup("Settings");
00039 disabled->setChecked(_configBenD->readBoolEntry("Disabled", false));
00040 playSound->setChecked(_configBenD->readBoolEntry("PlaySound", false));
00041 blinkLed->setChecked(_configBenD->readBoolEntry("BlinkLed", true));
00042 checkDelay->setValue(_configBenD->readNumEntry("CheckDelay", 5));
00043
00044 accountList->header()->hide();
00045 disclaimer->setText(disclaimer->text().arg(VERSION));
00046
00047 connect(accountNew, SIGNAL(clicked()), SLOT(slotNewAccount()));
00048 connect(accountEdit, SIGNAL(clicked()), SLOT(slotEditAccount()));
00049 connect(accountDelete, SIGNAL(clicked()), SLOT(slotDelAccount()));
00050
00051 slotFillLists();
00052 }
00053
00054 void ConfigDiag::accept()
00055 {
00056 _configBenD->setGroup("Settings");
00057 _configBenD->writeEntry("Disabled", disabled->isChecked());
00058 _configBenD->writeEntry("PlaySound", playSound->isChecked());
00059 _configBenD->writeEntry("BlinkLed", blinkLed->isChecked());
00060 _configBenD->writeEntry("CheckDelay", checkDelay->value());
00061 _configBenD->write();
00062
00063 QDialog::accept();
00064 }
00065
00066 void ConfigDiag::slotFillLists()
00067 {
00068 accountList->clear();
00069
00070 QValueList<Account> accounts = ConfigFile::getAccounts();
00071
00072 QValueList<Account>::Iterator it;
00073 for (it = accounts.begin(); it != accounts.end(); it++)
00074 (void) new AccountListItem(accountList, *it);
00075 }
00076
00077 void ConfigDiag::slotNewAccount()
00078 {
00079 Account account;
00080 AccountEditor editor(account, 0, 0, true);
00081 editor.showMaximized();
00082 editor.show();
00083
00084 if (QDialog::Accepted == editor.exec()) {
00085 ConfigFile::updateAccount(editor._account);
00086 slotFillLists();
00087 emit changed();
00088 }
00089 }
00090
00091 void ConfigDiag::slotEditAccount()
00092 {
00093 if (!accountList->currentItem()) {
00094 QMessageBox::information(this, tr("Error"), tr("<p>You have to select an account first.</p>"), tr("Ok"));
00095 return;
00096 }
00097 Account account = ((AccountListItem *)accountList->currentItem())->account();
00098
00099 AccountEditor editor(account, 0, 0, true);
00100 editor.showMaximized();
00101 editor.show();
00102
00103 if (QDialog::Accepted == editor.exec()) {
00104 ConfigFile::updateAccount(editor._account);
00105 slotFillLists();
00106 emit changed();
00107 }
00108 }
00109
00110 void ConfigDiag::slotDelAccount()
00111 {
00112 if (!accountList->currentItem()) {
00113 QMessageBox::information(this, tr("Error"), tr("<p>You have to select an account first.</p>"), tr("Ok"));
00114 return;
00115 }
00116 Account account = ((AccountListItem *)accountList->currentItem())->account();
00117
00118 int ret = QMessageBox::information(this, tr("Question"), tr("<p>Do you relly want to delete the selected account?</p>"), tr("Yes"), tr("No"));
00119 if (1 == ret) return;
00120
00121 ConfigFile::deleteAccount(account);
00122 slotFillLists();
00123 emit changed();
00124 }
00125