diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-07-24 15:57:00 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-07-24 15:57:00 -0500 |
commit | b888c7edb54e483ec0e3c2e2ce0eafd73acdcc65 (patch) | |
tree | 7ca76d42f66fb21ea08142de9a8d3bf16e597404 /kshowmail/kcmconfigs | |
download | kshowmail-b888c7edb54e483ec0e3c2e2ce0eafd73acdcc65.tar.gz kshowmail-b888c7edb54e483ec0e3c2e2ce0eafd73acdcc65.zip |
Initial import from kshowmail 3.3.1 sources
Diffstat (limited to 'kshowmail/kcmconfigs')
42 files changed, 7055 insertions, 0 deletions
diff --git a/kshowmail/kcmconfigs/Makefile.am b/kshowmail/kcmconfigs/Makefile.am new file mode 100644 index 0000000..94cd555 --- /dev/null +++ b/kshowmail/kcmconfigs/Makefile.am @@ -0,0 +1,36 @@ +INCLUDES = $(all_includes) +METASOURCES = AUTO +kde_module_LTLIBRARIES = kcm_kshowmailconfigaccounts.la \ + kcm_kshowmailconfigactions.la kcm_kshowmailconfigdisplay.la kcm_kshowmailconfigfilter.la \ + kcm_kshowmailconfiggeneral.la kcm_kshowmailconfiglog.la kcm_kshowmailconfigspamcheck.la +kcm_kshowmailconfigactions_la_LDFLAGS = -avoid-version -module $(all_libraries) +noinst_HEADERS = accountsetupdialog.h accountsetupitem.h configaccounts.h \ + configactions.h configdisplay.h configfilter.h configgeneral.h configlog.h \ + configspamcheck.h encryption.h filtercriteriawidget.h filtersetupdialog.h \ + filtersetupitem.h kwalletaccess.h mailboxwizard.h mailboxwizardlistitem.h \ + senderlistdialog.h +kcm_kshowmailconfigactions_la_SOURCES = configactions.cpp +kde_services_DATA = kshowmailconfigaccounts.desktop \ + kshowmailconfigactions.desktop kshowmailconfigdisplay.desktop kshowmailconfigfilter.desktop \ + kshowmailconfiggeneral.desktop kshowmailconfiglog.desktop kshowmailconfigspamcheck.desktop +kcm_kshowmailconfiggeneral_la_LDFLAGS = -avoid-version -module\ + $(all_libraries) +kcm_kshowmailconfiggeneral_la_SOURCES = configgeneral.cpp +kcm_kshowmailconfigdisplay_la_LDFLAGS = -avoid-version -module\ + $(all_libraries) +kcm_kshowmailconfigdisplay_la_SOURCES = configdisplay.cpp +kcm_kshowmailconfigaccounts_la_LDFLAGS = -avoid-version -module\ + $(all_libraries) +kcm_kshowmailconfigaccounts_la_SOURCES = configaccounts.cpp \ + accountsetupitem.cpp accountsetupdialog.cpp encryption.cpp kwalletaccess.cpp +kcm_kshowmailconfigfilter_la_LDFLAGS = -avoid-version -module\ + $(all_libraries) +kcm_kshowmailconfigfilter_la_SOURCES = configfilter.cpp senderlistdialog.cpp \ + filtersetupitem.cpp filtersetupdialog.cpp filtercriteriawidget.cpp mailboxwizard.cpp \ + mailboxwizardlistitem.cpp +kcm_kshowmailconfiglog_la_LDFLAGS = $(all_libraries) -avoid-version -module +kcm_kshowmailconfiglog_la_SOURCES = configlog.cpp +kcm_kshowmailconfigspamcheck_la_LDFLAGS = $(all_libraries) -avoid-version \ + -module +kcm_kshowmailconfigspamcheck_la_SOURCES = configspamcheck.cpp mailboxwizard.cpp \ + mailboxwizardlistitem.cpp diff --git a/kshowmail/kcmconfigs/accountsetupdialog.cpp b/kshowmail/kcmconfigs/accountsetupdialog.cpp new file mode 100644 index 0000000..6c6fe22 --- /dev/null +++ b/kshowmail/kcmconfigs/accountsetupdialog.cpp @@ -0,0 +1,362 @@ +// +// C++ Implementation: accountsetupdialog +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "accountsetupdialog.h" + +AccountSetupDialog::AccountSetupDialog( QWidget* parent, KListView* view, AccountSetupItem* item ) + : KDialogBase( parent, "AccountSetupDialog", true, QString::null, Ok|Cancel, Ok, true ) +{ + //save pointer to account and view + account = item; + ListView = view; + + //tab widget + KTabWidget* tabs = new KTabWidget( this, "tabs" ); + tabs->setMargin( 10 ); + + //pages + QWidget* pgGeneral = new QWidget( this ); + QWidget* pgSecurity = new QWidget( this ); + setMainWidget( tabs ); + + //layouts of general page + QVBoxLayout* layGeneral = new QVBoxLayout( pgGeneral, 0, spacingHint() ); + QGridLayout* layTop = new QGridLayout( layGeneral, 5, 2 ); + + //layouts of security page + QVBoxLayout* laySecurity = new QVBoxLayout( pgSecurity, 0, spacingHint() ); + laySecurity->setAlignment( Qt::AlignTop ); + + //upper items + QLabel* lblAccount = new QLabel( i18n( "Account:" ), pgGeneral, "lblAccount" ); + txtAccount = new KLineEdit( pgGeneral, "txtAccount" ); + txtAccount->setFocus(); + QToolTip::add( lblAccount, i18n( "Unique Account Name" ) ); + QToolTip::add( txtAccount, i18n( "Unique Account Name" ) ); + layTop->addWidget( lblAccount, 0, 0 ); + layTop->addWidget( txtAccount, 0, 1 ); + + QLabel* lblServer = new QLabel( i18n( "Server:" ), pgGeneral, "lblServer" ); + txtServer = new KLineEdit( pgGeneral, "txtServer" ); + QToolTip::add( lblServer, i18n( "Server Name" ) ); + QToolTip::add( txtServer, i18n( "Server Name" ) ); + layTop->addWidget( lblServer, 1, 0 ); + layTop->addWidget( txtServer, 1, 1 ); + + QLabel* lblProtocol = new QLabel( i18n( "Protocol:" ), pgGeneral, "lblProtocol" ); + cboProtocol = new KComboBox( pgGeneral, "cboProtocol" ); + cboProtocol->insertItem( "POP3" ); //currently KShowmail just supports POP3 + QToolTip::add( lblProtocol, i18n( "Protocol, which shall be used to get the mails from the server. Currently KShowmail just supports POP3.") ); + QToolTip::add( cboProtocol, i18n( "Protocol, which shall be used to get the mails from the server. Currently KShowmail just supports POP3.") ); + layTop->addWidget( lblProtocol, 2, 0 ); + layTop->addWidget( cboProtocol, 2, 1 ); + + QLabel* lblPort = new QLabel( i18n( "Port:" ), pgGeneral, "lblPort" ); + spbPort = new QSpinBox( 0, 65535, 1, pgGeneral, "spbPort" ); + spbPort->setValue( DEFAULT_ACCOUNT_PORT_POP3 ); + QToolTip::add( lblPort, i18n( "Port Number. Normally POP3 uses port 110." ) ); + QToolTip::add( spbPort, i18n( "Port Number. Normally POP3 uses port 110." ) ); + layTop->addWidget( lblPort, 3, 0 ); + layTop->addWidget( spbPort, 3, 1 ); + + QLabel* lblUser = new QLabel( i18n( "User:" ), pgGeneral, "lblUser" ); + txtUser = new KLineEdit( pgGeneral, "txtUser" ); + QToolTip::add( lblUser, i18n( "To authenticate to the mail server you need an user name." ) ); + QToolTip::add( txtUser, i18n( "To authenticate to the mail server you need an user name." ) ); + layTop->addWidget( lblUser, 4, 0 ); + layTop->addWidget( txtUser, 4, 1 ); + + //password groupbox and layouts + QGroupBox* gboxPassword = new QGroupBox( 0, Qt::Horizontal, i18n( "Password" ), pgGeneral, "gboxPassword" ); + layGeneral->addWidget( gboxPassword ); + + QVBoxLayout* layPassword = new QVBoxLayout( gboxPassword->layout(), spacingHint() ); + QGridLayout* layPasswordStorage = new QGridLayout( layPassword, 2, 2, spacingHint() ); + + + //radio buttons to set storage of the password + grpPasswordStorage = new QButtonGroup( NULL, "grpPasswordStorage" ); + connect( grpPasswordStorage, SIGNAL( clicked( int ) ), this, SLOT( slotPasswordStorageChanged( int ) ) ); + + QRadioButton* btnPasswordDontSave = new QRadioButton( i18n( "Don't save" ), gboxPassword, "btnPasswordDontSave" ); + QRadioButton* btnPasswordSaveFile = new QRadioButton( i18n( "Save password"), gboxPassword, "btnPasswordSaveFile" ); + QRadioButton* btnPasswordSaveKWallet = new QRadioButton( i18n( "Use KWallet" ), gboxPassword, "btnPasswordSaveKWallet" ); + grpPasswordStorage->insert( btnPasswordDontSave, ID_BUTTON_PASSWORD_DONT_SAVE ); + grpPasswordStorage->insert( btnPasswordSaveFile, ID_BUTTON_PASSWORD_SAVE_FILE ); + grpPasswordStorage->insert( btnPasswordSaveKWallet, ID_BUTTON_PASSWORD_SAVE_KWALLET ); + QToolTip::add( btnPasswordDontSave, i18n( "Don't save password. KShowmail will ask you for it at first server connect." ) ); + QToolTip::add( btnPasswordSaveFile, i18n( "Save password in the configuration file. Not recommended, because the password is just lightly encrypted" ) ); + QToolTip::add( btnPasswordSaveKWallet, i18n( "Use KWallet to save the password. Maybe you have to type in the KWallet master password at first server connect." ) ); + layPasswordStorage->addWidget( btnPasswordDontSave, 0, 0 ); + layPasswordStorage->addWidget( btnPasswordSaveFile, 0, 1 ); + layPasswordStorage->addWidget( btnPasswordSaveKWallet, 1, 0 ); + + //password edit line + txtPassword = new KPasswordEdit( gboxPassword, "txtUser" ); + layPassword->addWidget( txtPassword ); + + //set password defaults + grpPasswordStorage->setButton( DEFAULT_ACCOUNT_PASSWORD_STORAGE ); + slotPasswordStorageChanged( DEFAULT_ACCOUNT_PASSWORD_STORAGE ); + + //active check box + QGridLayout* layActive = new QGridLayout( layGeneral, 1, 1 ); + layActive->setAlignment( Qt::AlignCenter ); + chkActive = new QCheckBox( i18n( "Active"), pgGeneral, "chkActive" ); + QToolTip::add( chkActive, i18n( "Select it to activate this account." ) ); + layActive->addWidget( chkActive, 0, 0 ); + chkActive->setChecked( DEFAULT_ACCOUNT_ACTIVE ); + + //secure transfer groupbox and layouts + QGroupBox* gboxSecureTransfer = new QGroupBox( 0, Qt::Horizontal, i18n( "Encryption" ), pgSecurity, "gboxSecureTransfer" ); + gboxSecureTransfer->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum ) ); + laySecurity->addWidget( gboxSecureTransfer ); + + QHBoxLayout* laySecureTransfer = new QHBoxLayout( gboxSecureTransfer->layout(), spacingHint() ); + + //radio buttons to set secure transfer + grpSecureTransfer = new QButtonGroup( NULL, "grpSecureTransfer" ); + connect( grpSecureTransfer, SIGNAL( clicked( int ) ), this, SLOT( slotSecureTransferChanged ( int ) ) ); + + QRadioButton* btnSecureTransferNone = new QRadioButton( i18n( "None" ), gboxSecureTransfer, "btnSecureTransferNone" ); + QRadioButton* btnSecureTransferSSL = new QRadioButton( i18n( "SSL"), gboxSecureTransfer, "btnSecureTransferSSL" ); + QRadioButton* btnSecureTransferTLS = new QRadioButton( i18n( "TLS" ), gboxSecureTransfer, "btnSecureTransferTLS" ); + grpSecureTransfer->insert( btnSecureTransferNone, ID_BUTTON_SECTRANSFER_NONE ); + grpSecureTransfer->insert( btnSecureTransferSSL, ID_BUTTON_SECTRANSFER_SSL ); + grpSecureTransfer->insert( btnSecureTransferTLS, ID_BUTTON_SECTRANSFER_TLS ); + QToolTip::add( btnSecureTransferNone, i18n( "The download of the mail header and body will not be encrypted. Use this, if your provider doesn't make a secure transfer available." ) ); + QToolTip::add( btnSecureTransferSSL, i18n( "Secure Sockets Layer (SSL), is a cryptographic protocol that provides secure communications on the Internet." ) ); + QToolTip::add( btnSecureTransferTLS, i18n( "Transport Layer Security (TLS) is a cryptographic protocol that provides secure communications on the Internet. It is the successor of SSL." ) ); + laySecureTransfer->addWidget( btnSecureTransferNone ); + laySecureTransfer->addWidget( btnSecureTransferSSL ); + laySecureTransfer->addWidget( btnSecureTransferTLS ); + + grpSecureTransfer->setButton( DEFAULT_ACCOUNT_SECTRANSFER ); + + //set pages to tab widget + tabs->addTab( pgGeneral, i18n( "General" ) ); + tabs->addTab( pgSecurity, i18n( "Security" ) ); + + //set caption + if( item == NULL ) + setCaption( i18n( "New account" ) ); + else + setCaption( i18n( "Edit account" ) ); + + //write values of the given account into the dialog items + if( account != NULL ) + fillDialog(); + + +} + + +AccountSetupDialog::~AccountSetupDialog() +{ +} + +void AccountSetupDialog::slotPasswordStorageChanged( int id ) +{ + if( id == ID_BUTTON_PASSWORD_DONT_SAVE ) + { + txtPassword->setEnabled( false ); + txtPassword->clear(); + } + else + txtPassword->setEnabled( true ); +} + +void AccountSetupDialog::slotOk( ) +{ + //check for necessary values + if( txtAccount->text() == "" ) + { + KMessageBox::error( this, i18n( "Please enter an account name." ) ); + return; + } + if( txtServer->text() == "" ) + { + KMessageBox::error( this, i18n( "Please enter an server." ) ); + return; + } + + if( txtUser->text() == "" ) + { + KMessageBox::error( this, i18n( "Please enter an user name." ) ); + return; + } + + //test for unique account name + //we will only test if the account is new or if the + //name in the dialog is different from the name of the account object + bool test = false; + if( account == NULL ) + test = true; + else if( account != NULL && account->getAccountName() != txtAccount->text() ) + test = true; + else + test = false; + + if( test ) + { + //OK, we want to test + AccountSetupItem* item = NULL; + int index = 0; + bool equality = false; + + do + { + item = (AccountSetupItem*)( ListView->itemAtIndex( index ) ); + if( item != NULL ) + { + index++; + equality = item->getAccountName() == txtAccount->text(); + } + } while( item != NULL && !equality ); + + //exit method if we have found an account with the same name + if( equality ) + { + KMessageBox::error( this, i18n( "There is already an account named %1. Please choose another name." ).arg( txtAccount->text() ) ); + return; + } + + } + + + //create a new account item if necessary + if( account == NULL ) + account = new AccountSetupItem( ListView ); + + //show a warning if the account name was changend + if( account->getAccountName() != DEFAULT_ACCOUNT_NAME && account->getAccountName() != txtAccount->text() ) + KMessageBox::information( this, i18n( "You have changed the account name. The account will lose all downloaded mail headers. Please perform a refresh." ) ); + + //set column text + account->setText( 0, txtAccount->text() ); + + //write values into account item + account->setAccountName( txtAccount->text() ); + account->setServer( txtServer->text() ); + account->setProtocol( cboProtocol->currentText() ); + account->setPort( spbPort->value() ); + account->setUser( txtUser->text() ); + + //get the password + //the class KPasswordEdit doesn't have a method to set the password + //therefore we use setText(). But if we use this method, KPasswordEdit::password() + //will return an empty string. If the user has typed in a new password, KPasswordEdit::password() + //will return the correct password + QString pass; + if( txtPassword->password() == "" || txtPassword->password() == QString::null ) + pass = txtPassword->text(); + else + pass = txtPassword->password(); + + switch( grpPasswordStorage->selectedId() ) + { + case ID_BUTTON_PASSWORD_DONT_SAVE : account->setPasswordStorageType( CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE ); + account->setPassword( QString::null ); + break; + case ID_BUTTON_PASSWORD_SAVE_FILE : account->setPasswordStorageType( CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE ); + account->setPassword( pass ); + break; + case ID_BUTTON_PASSWORD_SAVE_KWALLET : account->setPasswordStorageType( CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET ); + account->setPassword( pass ); + break; + default : account->setPasswordStorageType( -1 ); + account->setPassword( QString::null ); + } + + account->setActive( chkActive->isChecked() ); + + switch( grpSecureTransfer->selectedId() ) + { + case ID_BUTTON_SECTRANSFER_NONE : account->setTransferSecurity( CONFIG_VALUE_ACCOUNT_SECTRANSFER_NONE ); break; + case ID_BUTTON_SECTRANSFER_SSL : account->setTransferSecurity( CONFIG_VALUE_ACCOUNT_SECTRANSFER_SSL ); break; + case ID_BUTTON_SECTRANSFER_TLS : account->setTransferSecurity( CONFIG_VALUE_ACCOUNT_SECTRANSFER_TLS ); break; + default : account->setTransferSecurity( DEFAULT_ACCOUNT_SECTRANSFER ); break; + } + + //call slot of super class to close the dialog + KDialogBase::slotOk(); +} + +void AccountSetupDialog::fillDialog( ) +{ + //check for valid account pointer + if( account == NULL ) + { + kdError() << "AccountSetupDialog::fillDialog: invalid pointer to account item." << endl; + return; + } + + txtAccount->setText( account->getAccountName() ); + txtServer->setText( account->getServer() ); + cboProtocol->setCurrentText( account->getProtocol().upper() ); + + if( account->getPort() >= 0 && account->getPort() <= 65535 ) + spbPort->setValue( account->getPort() ); + else + spbPort->setValue( DEFAULT_ACCOUNT_PORT_POP3 ); + + txtUser->setText( account->getUser() ); + + int type = account->getPasswordStorageType(); + if( type != CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE && type != CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE && type != CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET ) + type = DEFAULT_ACCOUNT_PASSWORD_STORAGE; + + switch( type ) + { + case CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE : grpPasswordStorage->setButton( ID_BUTTON_PASSWORD_DONT_SAVE ); + txtPassword->setEnabled( false ); + txtPassword->clear(); + break; + case CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE : grpPasswordStorage->setButton( ID_BUTTON_PASSWORD_SAVE_FILE ); + txtPassword->setEnabled( true ); + txtPassword->setText( account->getPassword() ); + break; + case CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET : grpPasswordStorage->setButton( ID_BUTTON_PASSWORD_SAVE_KWALLET ); + txtPassword->setEnabled( true ); + txtPassword->setText( account->getPassword() ); + break; + default : grpPasswordStorage->setButton( 1 ); + txtPassword->clear(); + } + + chkActive->setChecked( account->getActive() ); + + int transferSecurity = account->getTransferSecurity(); + if( transferSecurity != CONFIG_VALUE_ACCOUNT_SECTRANSFER_NONE && transferSecurity != CONFIG_VALUE_ACCOUNT_SECTRANSFER_SSL && transferSecurity != CONFIG_VALUE_ACCOUNT_SECTRANSFER_TLS ) + transferSecurity = DEFAULT_ACCOUNT_SECTRANSFER; + + switch( transferSecurity ) + { + case CONFIG_VALUE_ACCOUNT_SECTRANSFER_NONE : grpSecureTransfer->setButton( ID_BUTTON_SECTRANSFER_NONE ); break; + case CONFIG_VALUE_ACCOUNT_SECTRANSFER_SSL : grpSecureTransfer->setButton( ID_BUTTON_SECTRANSFER_SSL ); break; + case CONFIG_VALUE_ACCOUNT_SECTRANSFER_TLS : grpSecureTransfer->setButton( ID_BUTTON_SECTRANSFER_TLS ); break; + default : grpSecureTransfer->setButton( ID_BUTTON_SECTRANSFER_NONE ); break; + } +} + +void AccountSetupDialog::slotSecureTransferChanged( int id ) +{ + switch( id ) + { + case ID_BUTTON_SECTRANSFER_NONE : spbPort->setValue( DEFAULT_ACCOUNT_PORT_POP3 ); break; + case ID_BUTTON_SECTRANSFER_SSL : spbPort->setValue( DEFAULT_ACCOUNT_PORT_POP3SSL ); break; + case ID_BUTTON_SECTRANSFER_TLS : spbPort->setValue( DEFAULT_ACCOUNT_PORT_POP3 ); break; + } +} + + + +#include "accountsetupdialog.moc" diff --git a/kshowmail/kcmconfigs/accountsetupdialog.h b/kshowmail/kcmconfigs/accountsetupdialog.h new file mode 100644 index 0000000..756f51e --- /dev/null +++ b/kshowmail/kcmconfigs/accountsetupdialog.h @@ -0,0 +1,165 @@ +// +// C++ Interface: accountsetupdialog +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef ACCOUNTSETUPDIALOG_H +#define ACCOUNTSETUPDIALOG_H + +//Qt headers +#include <qlayout.h> +#include <qlabel.h> +#include <qtooltip.h> +#include <qspinbox.h> +#include <qgroupbox.h> +#include <qbuttongroup.h> +#include <qradiobutton.h> +#include <qcheckbox.h> + +//KDE headers +#include <kdialogbase.h> +#include <klocale.h> +#include <klineedit.h> +#include <kcombobox.h> +#include <kdebug.h> +#include <kmessagebox.h> +#include <kpassdlg.h> +#include <ktabwidget.h> + +//KShowmail headers +#include "accountsetupitem.h" +#include "../constants.h" + +//radio button IDs +#define ID_BUTTON_PASSWORD_DONT_SAVE 1 +#define ID_BUTTON_PASSWORD_SAVE_FILE 2 +#define ID_BUTTON_PASSWORD_SAVE_KWALLET 3 +#define ID_BUTTON_SECLOGIN_NONE 1 +#define ID_BUTTON_SECLOGIN_APOP 2 +#define ID_BUTTON_SECLOGIN_SASL 3 +#define ID_BUTTON_SECTRANSFER_NONE 1 +#define ID_BUTTON_SECTRANSFER_SSL 2 +#define ID_BUTTON_SECTRANSFER_TLS 3 + +/** + * @brief Dialog to setup an account. + * + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +class AccountSetupDialog : public KDialogBase +{ +Q_OBJECT + + public: + + /** + * General constructor + * @param parent parent of the dialog + * @param view view which shows the items + * @param item account to setup; if NULL, a new item will be created + */ + AccountSetupDialog( QWidget* parent, KListView* view, AccountSetupItem* item = NULL ); + + /** + * Destructor + */ + ~AccountSetupDialog(); + + private: + + /** + * account to setup + */ + AccountSetupItem* account; + + /** + * View which shows the account items. + */ + KListView* ListView; + + /** + * Edit line which contains the unique account name. + */ + KLineEdit* txtAccount; + + /** + * Edit line which contains the server name. + */ + KLineEdit* txtServer; + + /** + * Combo box to choose the protocol. + */ + KComboBox* cboProtocol; + + /** + * Spinbox to choose the tcp port. + */ + QSpinBox* spbPort; + + /** + * Edit line which contains the user name. + */ + KLineEdit* txtUser; + + /** + * Edit line which contains the password. + */ + KPasswordEdit* txtPassword; + + /** + * Check box to select whether the account is active or not. + */ + QCheckBox* chkActive; + + /** + * Combines the radio buttons of password storage. + */ + QButtonGroup* grpPasswordStorage; + + /** + * Combines the radio buttons of secure transfer. + */ + QButtonGroup* grpSecureTransfer; + + protected slots: + + /** + * Connected with the password button group. + * Enabled or disabled the password edit line. + * @param id button identifier + */ + void slotPasswordStorageChanged( int id ); + + /** + * Connected with the secure transfer button group. + * Changes the port number. + * @param id button identifier + */ + void slotSecureTransferChanged( int id ); + + /** + * Overwritten method of KDialogBase. + * Called if OK was clicked. + * Stores the entered values into the given account item. + * If no item was given it creates a new one. + * After then it invokes slotOk() of KDialogBase. + */ + void slotOk(); + + protected: + + /** + * Writes the values of the account into the dialog items. + */ + void fillDialog(); + +}; + +#endif diff --git a/kshowmail/kcmconfigs/accountsetupitem.cpp b/kshowmail/kcmconfigs/accountsetupitem.cpp new file mode 100644 index 0000000..f9f8431 --- /dev/null +++ b/kshowmail/kcmconfigs/accountsetupitem.cpp @@ -0,0 +1,207 @@ +// +// C++ Implementation: accountsetupitem +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "accountsetupitem.h" + +AccountSetupItem::AccountSetupItem( KListView* parent ) + : KListViewItem( parent ) +{ + init(); + +} + +AccountSetupItem::AccountSetupItem( KListView * parent, QString & name ) + : KListViewItem( parent ) +{ + init(); + + //save account name + _account = name; + + //set column text + setText( 0, getAccountName() ); +} + +AccountSetupItem::~AccountSetupItem() +{ +} + +void AccountSetupItem::init( ) +{ + //set default values + _account = DEFAULT_ACCOUNT_NAME; + _server = DEFAULT_ACCOUNT_SERVER; + _protocol = DEFAULT_ACCOUNT_PROTOCOL; + _port = DEFAULT_ACCOUNT_PORT_POP3; + _user = DEFAULT_ACCOUNT_USER; + _password = DEFAULT_ACCOUNT_PASSWORD; + _passwordStorage = DEFAULT_ACCOUNT_PASSWORD_STORAGE; + _active = DEFAULT_ACCOUNT_ACTIVE; + _transferSecurity = DEFAULT_ACCOUNT_SECTRANSFER; + + //get application config object (kshowmailrc) + config = KApplication::kApplication()->config(); +} + +void AccountSetupItem::setAccountName( const QString & name ) +{ + _account = name; +} + +QString AccountSetupItem::getAccountName( ) const +{ + return _account; +} + +void AccountSetupItem::setServer( const QString & server ) +{ + _server = server; +} + +QString AccountSetupItem::getServer( ) const +{ + return _server; +} + +void AccountSetupItem::setProtocol( const QString & protocol ) +{ + _protocol = protocol; +} + +QString AccountSetupItem::getProtocol( ) const +{ + return _protocol; +} + +void AccountSetupItem::setPort( int port ) +{ + if( port >= 0 && port <= 65535 ) + _port = port; + else + _port = DEFAULT_ACCOUNT_PORT_POP3; +} + +int AccountSetupItem::getPort( ) const +{ + return _port; +} + +void AccountSetupItem::setUser( const QString & user ) +{ + _user = user; +} + +QString AccountSetupItem::getUser( ) const +{ + return _user; +} + +void AccountSetupItem::setPassword( const QString & password ) +{ + _password = password; +} + +QString AccountSetupItem::getPassword( ) const +{ + return _password; +} + +void AccountSetupItem::setPasswordStorageType( int type ) +{ + if( type == CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE || type == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE || type == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET ) + _passwordStorage = type; + else + _passwordStorage = DEFAULT_ACCOUNT_PASSWORD_STORAGE; +} + +int AccountSetupItem::getPasswordStorageType( ) const +{ + return _passwordStorage; +} + +void AccountSetupItem::setActive( bool active ) +{ + _active = active; +} + +bool AccountSetupItem::getActive( ) const +{ + return _active; +} + +void AccountSetupItem::save() const +{ + config->setGroup( getAccountName() ); + + config->writeEntry( CONFIG_ENTRY_ACCOUNT_NAME, getAccountName() ); + config->writeEntry( CONFIG_ENTRY_ACCOUNT_SERVER, getServer() ); + config->writeEntry( CONFIG_ENTRY_ACCOUNT_PROTOCOL, getProtocol().upper() ); + config->writeEntry( CONFIG_ENTRY_ACCOUNT_PORT, getPort() ); + config->writeEntry( CONFIG_ENTRY_ACCOUNT_USER, getUser() ); + config->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, getPasswordStorageType() ); + + //save crypted password + KURL url; + url.setUser( getUser() ); + url.setHost( getServer() ); + url.setPass( getPassword() ); + + if( getPasswordStorageType() == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE ) + config->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, crypt( url ) ); + else + config->writeEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, QString::null ); + + //save password in KWallet if desired + if( getPasswordStorageType() == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET ) + KWalletAccess::savePassword( getAccountName(), getPassword() ); + + config->writeEntry( CONFIG_ENTRY_ACCOUNT_ACTIVE, getActive() ); + config->writeEntry( CONFIG_ENTRY_ACCOUNT_SECTRANSFER, getTransferSecurity() ); + +} + +void AccountSetupItem::load( ) +{ + config->setGroup( getAccountName() ); + + _server = config->readEntry( CONFIG_ENTRY_ACCOUNT_SERVER, DEFAULT_ACCOUNT_SERVER ); + _protocol = config->readEntry( CONFIG_ENTRY_ACCOUNT_PROTOCOL, DEFAULT_ACCOUNT_PROTOCOL ); + _port = config->readNumEntry( CONFIG_ENTRY_ACCOUNT_PORT, DEFAULT_ACCOUNT_PORT_POP3 ); + _user = config->readEntry( CONFIG_ENTRY_ACCOUNT_USER, DEFAULT_ACCOUNT_USER ); + _passwordStorage = config->readNumEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD_STORAGE, DEFAULT_ACCOUNT_PASSWORD_STORAGE ); + + if( _passwordStorage == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE ) + _password = decrypt( config->readEntry( CONFIG_ENTRY_ACCOUNT_PASSWORD, DEFAULT_ACCOUNT_PASSWORD ) ); + else if( _passwordStorage == CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET ) + _password = KWalletAccess::getPassword( getAccountName() ); + else + _password = QString::null; + + _active = config->readBoolEntry( CONFIG_ENTRY_ACCOUNT_ACTIVE, DEFAULT_ACCOUNT_ACTIVE ); + _transferSecurity = config->readNumEntry( CONFIG_ENTRY_ACCOUNT_SECTRANSFER, DEFAULT_ACCOUNT_SECTRANSFER ); +} + +void AccountSetupItem::setTransferSecurity( int type ) +{ + if( type == CONFIG_VALUE_ACCOUNT_SECTRANSFER_NONE || type == CONFIG_VALUE_ACCOUNT_SECTRANSFER_SSL || type == CONFIG_VALUE_ACCOUNT_SECTRANSFER_TLS ) + _transferSecurity = type; + else + _transferSecurity = DEFAULT_ACCOUNT_SECTRANSFER; +} + +int AccountSetupItem::getTransferSecurity( ) const +{ + return _transferSecurity; +} + + + + diff --git a/kshowmail/kcmconfigs/accountsetupitem.h b/kshowmail/kcmconfigs/accountsetupitem.h new file mode 100644 index 0000000..fe85eee --- /dev/null +++ b/kshowmail/kcmconfigs/accountsetupitem.h @@ -0,0 +1,242 @@ +// +// C++ Interface: accountsetupitem +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef ACCOUNTSETUPITEM_H +#define ACCOUNTSETUPITEM_H + +//KDE headers +#include <klistview.h> +#include <kconfig.h> +#include <kurl.h> +#include <kapplication.h> + +//KShowmail headers +#include "../constants.h" +#include "encryption.h" +#include "kwalletaccess.h" + +using namespace Encryption; + +/** + * @brief This class is used in ConfigAccounts to show the available accounts in the list view and to store an account setup. + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +class AccountSetupItem : public KListViewItem +{ + public: + + /** + * General Constructor + * @param parent the list view + */ + AccountSetupItem( KListView* parent ); + + /** + * Constructor + * @param parent the list view + * @param name account name + */ + AccountSetupItem( KListView* parent, QString& name ); + + /** + * Destructor + */ + ~AccountSetupItem(); + + /** + * Sets account name + * @param name account name + */ + void setAccountName( const QString& name ); + + /** + * Returns the account name. + * @return account name + */ + QString getAccountName() const; + + /** + * Sets the server. + * @param server server + */ + void setServer( const QString& server ); + + /** + * Returns the server. + * @return server + */ + QString getServer() const; + + /** + * Sets the protocol. + * @param protocol protocol + */ + void setProtocol( const QString& protocol ); + + /** + * Returns the protocol. + * @return protocol + */ + QString getProtocol() const; + + /** + * Sets the port number. + * @param port port number + */ + void setPort( int port ); + + /** + * Returns the port number. + * @return port number (0..65535) + */ + int getPort() const; + + /** + * Sets the user name. + * @param user user name + */ + void setUser( const QString& user ); + + /** + * Returns the user name. + * @return user name + */ + QString getUser() const; + + /** + * Sets the password. + * @param password password + */ + void setPassword( const QString& password ); + + /** + * Returns the password. + * @return password + */ + QString getPassword() const; + + /** + * Sets the password storage type. + * See constants.h for valid values + * @param type password storage type (CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE, CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE or CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_KWALLET) + */ + void setPasswordStorageType( int type ); + + /** + * Returns the password storage type. + * See constants.h for valid values (CONFIG_VALUE_ACCOUNT_PASSWORD_...) + * @return storage type + */ + int getPasswordStorageType() const; + + /** + * Sets whether the account is active. + * @param active TRUE - account is active; FALSE - account is not active + */ + void setActive( bool active ); + + /** + * Returns whether the account is active. + * @return TRUE - account is active + * @return FALSE - account is not active + */ + bool getActive() const; + + /** + * Sets the transfer security. + * See constants.h for valid values. + * @param type transfer security type (CONFIG_VALUE_ACCOUNT_SECTRANSFER_NONE, CONFIG_VALUE_ACCOUNT_SECTRANSFER_SSL, CONFIG_VALUE_ACCOUNT_SECTRANSFER_TLS) + */ + void setTransferSecurity( int type ); + + /** + * Returns the transfer security. + * seee constants.h for valid values (CONFIG_VALUE_ACCOUNT_SECTRANSFER_...) + * @return transfer security + */ + int getTransferSecurity() const; + + /** + * Saves this account into applications config. + * All values are placed in a group called like the account name. + */ + void save() const; + + /** + * Loads the options of this account from the application config. + */ + void load(); + + + private: + + /** + * Connector to the configuration file + */ + KConfig* config; + + /** + * Account name + */ + QString _account; + + /** + * Server + */ + QString _server; + + /** + * Protocol + */ + QString _protocol; + + /** + * Port + */ + int _port; + + /** + * User Name + */ + QString _user; + + /** + * Password + */ + QString _password; + + /** + * TRUE - account is active + */ + bool _active; + + /** + * password storage type + * Values are defined in constants.h (CONFIG_VALUE_ACCOUNT_PASSWORD_...) + */ + int _passwordStorage; + + /** + * transfer security + * Values are defined in constants.h (CONFIG_VALUE_ACCOUNT_SECTRANSFER_...) + */ + int _transferSecurity; + + protected: + + /** + * Initializes the object. + */ + void init(); + +}; + +#endif diff --git a/kshowmail/kcmconfigs/configaccounts.cpp b/kshowmail/kcmconfigs/configaccounts.cpp new file mode 100644 index 0000000..3cb6d6c --- /dev/null +++ b/kshowmail/kcmconfigs/configaccounts.cpp @@ -0,0 +1,203 @@ +// +// C++ Implementation: configaccounts +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "configaccounts.h" + +typedef KGenericFactory<ConfigAccounts, QWidget> ConfigAccountsFactory; + +K_EXPORT_COMPONENT_FACTORY( kcm_kshowmailconfigaccounts, ConfigAccountsFactory( + "kcm_kshowmailconfigaccounts" ) ); + +ConfigAccounts::ConfigAccounts( QWidget * parent, const char * name, const QStringList & args ) + : KCModule( ConfigAccountsFactory::instance(), parent, args ) +{ + //set the module name + if ( !name ) + setName( "configaccounts" ); + + //build GUI + //--------- + + //main layout + QHBoxLayout* layMain = new QHBoxLayout( this, 0, 10 ); + + //account list view + AccountListView = new KListView( this, "AccountListView" ); + AccountListView->addColumn( i18n( "Name" ) ); + AccountListView->setColumnWidthMode( 0, QListView::Maximum ); + AccountListView->setResizeMode( QListView::LastColumn ); + + layMain->addWidget( AccountListView ); + + //button layout + QVBoxLayout* layButtons = new QVBoxLayout( layMain ); + + //Buttons + btnAdd = new KPushButton( KStdGuiItem::add(), this, "btnAdd" ); + layButtons->addWidget( btnAdd ); + btnAdd->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ); + connect( btnAdd, SIGNAL( clicked() ), this, SLOT( slotAdd() ) ); + + btnEdit = new KPushButton( KStdGuiItem::configure(), this, "btnEdit" ); + layButtons->addWidget( btnEdit ); + btnEdit->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ); + connect( btnEdit, SIGNAL( clicked() ), this, SLOT( slotEdit() ) ); + + btnRemove = new KPushButton( KStdGuiItem::remove(), this, "btnRemove" ); + layButtons->addWidget( btnRemove ); + btnRemove->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ); + connect( btnRemove, SIGNAL( clicked() ), this, SLOT( slotRemove() ) ); + + layButtons->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ) ); + + + //get application config object (kshowmailrc) + config = KApplication::kApplication()->config(); + + //load configured values + load(); + +} + +ConfigAccounts::~ConfigAccounts() +{ +} + +void ConfigAccounts::load() +{ + //get list of account names + config->setGroup( CONFIG_GROUP_ACCOUNTS ); + QStringList accounts = config->readListEntry( CONFIG_ENTRY_ACCOUNTS_LIST, QStringList() ); + + //create list view items and order accounts to load their config + for( QStringList::Iterator it = accounts.begin(); it != accounts.end(); ++it ) + { + //create item + AccountSetupItem* item = new AccountSetupItem( AccountListView, *it ); + + //load item config + item->load(); + + } +} + +void ConfigAccounts::save() +{ + config->setGroup( CONFIG_GROUP_ACCOUNTS ); + + //get old account list from config file to remove old account entries + QStringList oldList = config->readListEntry( CONFIG_ENTRY_ACCOUNTS_LIST, QStringList() ); + + //remove all account entries + for( QStringList::Iterator it = oldList.begin(); it != oldList.end(); ++it ) + { + config->deleteGroup( *it ); + } + + + //write a list with all account names into the config + QStringList accounts; //list of all account names + AccountSetupItem* item = NULL; + int index = 0; + + do //get all account names + { + item = (AccountSetupItem*)( AccountListView->itemAtIndex( index ) ); + if( item != NULL ) + { + index++; + accounts.append( item->getAccountName() ); + } + } while( item != NULL ); + + config->writeEntry( CONFIG_ENTRY_ACCOUNTS_LIST, accounts ); //write list of account names + + //order the items to save their configuration + index = 0; + item = NULL; + do + { + item = (AccountSetupItem*)( AccountListView->itemAtIndex( index ) ); + if( item != NULL ) + { + index++; + item->save(); + } + } while( item != NULL ); + + //write configuration to disk + config->sync(); +} + +void ConfigAccounts::defaults() +{ +} + +void ConfigAccounts::slotChanged( ) +{ + KCModule::changed(); +} + +void ConfigAccounts::slotAdd( ) +{ + //open setup dialog + AccountSetupDialog* dlg = new AccountSetupDialog( this, AccountListView, NULL ); + int res = dlg->exec(); + + //inform application setup dialog about changes + if( res == KDialogBase::Accepted ) + slotChanged(); + + //delete dialog + delete dlg; +} + +void ConfigAccounts::slotEdit( ) +{ + //get selected item + AccountSetupItem* account = (AccountSetupItem*)( AccountListView->selectedItem() ); + + //test item + if( account == NULL ) + return; + + //open dialog + AccountSetupDialog* dlg = new AccountSetupDialog( this, AccountListView, account ); + int res = dlg->exec(); + + //inform application setup dialog about changes + if( res == KDialogBase::Accepted ) + slotChanged(); + + //delete dialog + delete dlg; +} + +void ConfigAccounts::slotRemove( ) +{ + //get selected item + AccountSetupItem* account = (AccountSetupItem*)( AccountListView->selectedItem() ); + + //test item + if( account == NULL ) + return; + + //remove item + int result = KMessageBox::questionYesNo( this, i18n( "Do you really want to remove account %1?").arg( account->getAccountName() ) ); + if( result == KMessageBox::Yes ) + { + delete account; + slotChanged(); + } +} + + +#include "configaccounts.moc" diff --git a/kshowmail/kcmconfigs/configaccounts.h b/kshowmail/kcmconfigs/configaccounts.h new file mode 100644 index 0000000..e2f4e53 --- /dev/null +++ b/kshowmail/kcmconfigs/configaccounts.h @@ -0,0 +1,131 @@ +// +// C++ Interface: configaccounts +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef CONFIGACCOUNTS_H +#define CONFIGACCOUNTS_H + +//Qt headers +#include <qlayout.h> + +//KDE headers +#include <kcmodule.h> +#include <kgenericfactory.h> +#include <kapplication.h> +#include <kconfig.h> +#include <klistview.h> +#include <kpushbutton.h> +#include <kstdguiitem.h> +#include <kmessagebox.h> + +//kshowmail headers +#include "../constants.h" +#include "accountsetupdialog.h" +#include "accountsetupitem.h" + +/** + * @brief Part of the setup dialog (KShowMailApp::SetupDialog) to configure the accounts. + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +class ConfigAccounts : public KCModule +{ +Q_OBJECT + + public: + + /** + * Generic Constructor + */ + ConfigAccounts( QWidget *parent = 0, const char *name = 0, const QStringList &args = QStringList() ); + + /** + * Destructor + */ + ~ConfigAccounts(); + + /** + * Overloaded method of KCModule. + * Sets the user interface elements to reflect the current settings stored in the + * config file. + */ + virtual void load(); + + /** + * Overloaded method of KCModule. + * Sets the user interface elements to default values. + * This method is called when the user clicks the "Default" button. + */ + virtual void defaults(); + + /** + * Overloaded method of KCModule. + * Stores the config information as shown in the user interface in the + * config file. + * Is called when the user clicks "Apply" or "Ok". + */ + virtual void save(); + + private: + + /** + * Connector to the configuration file + */ + KConfig* config; + + /** + * Account List View + */ + KListView* AccountListView; + + /** + * Button to add a new account + */ + KPushButton* btnAdd; + + /** + * Button to edit an account + */ + KPushButton* btnEdit; + + /** + * Button to remove an account + */ + KPushButton* btnRemove; + + private slots: + + /** + * Connected with the configuration items. + * Calls the slot changed() of KCModule to notify the dialog about the change. + */ + void slotChanged(); + + /** + * Connected with button btnAdd. + * Opens the account setup dialog with an account item pointer of NULL. + * If the user has clicked OK, the dialog will create a new account item with + * the entered values and adds it to the list view. + */ + void slotAdd(); + + /** + * Connected with button btnEdit. + * Opens the account setup with the selected account item. + */ + void slotEdit(); + + /** + * Connected with button btnRemove. + * Removes the selected item. + */ + void slotRemove(); +}; + +#endif diff --git a/kshowmail/kcmconfigs/configactions.cpp b/kshowmail/kcmconfigs/configactions.cpp new file mode 100644 index 0000000..583d767 --- /dev/null +++ b/kshowmail/kcmconfigs/configactions.cpp @@ -0,0 +1,267 @@ +// +// C++ Implementation: configactions +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "configactions.h" + +typedef KGenericFactory<ConfigActions, QWidget> ConfigActionsFactory; + +K_EXPORT_COMPONENT_FACTORY( kcm_kshowmailconfigactions, ConfigActionsFactory( + "kcm_kshowmailconfigactions" ) ); + +ConfigActions::ConfigActions( QWidget * parent, const char * name, const QStringList & args ) + : KCModule( ConfigActionsFactory::instance(), parent, args ) +{ + //set the module name + if ( !name ) + setName( "configactions" ); + + //build GUI + //--------- + + //main layout + QVBoxLayout* layMain = new QVBoxLayout( this, 0, 10 ); + + //two boxes to seperate the action if new mail or if no new mail + QGroupBox* gboxNewMails = new QGroupBox( 0, Qt::Horizontal, i18n( "Action if new &mail" ), this, "gboxNewMails" ); + QGroupBox* gboxNoNewMails = new QGroupBox( 2, Qt::Vertical, i18n( "Action if &no mail" ), this, "gboxNoNewMails" ); + gboxNoNewMails->layout()->setSpacing( 20 ); + layMain->addWidget( gboxNewMails ); + layMain->addWidget( gboxNoNewMails ); + + //layouts for the upper group box + QVBoxLayout* layMainNewMails = new QVBoxLayout( gboxNewMails->layout(), 10 ); + QGridLayout* layMainNewMailsTop = new QGridLayout( layMainNewMails, 2, 2, 10 ); + QGridLayout* layMainNewMailsDown = new QGridLayout( layMainNewMails, 2, 4, 10 ); + + //items for the upper group box + chkNewMailsAlertWindow = new QCheckBox( i18n( "Show message box" ), gboxNewMails, "chkNewMailsAlertWindow" ); + QToolTip::add( chkNewMailsAlertWindow, i18n( "Show message if new mail arrives" ) ); + layMainNewMailsTop->addWidget( chkNewMailsAlertWindow, 0, 0 ); + + chkNewMailsMainWindow = new QCheckBox( i18n( "Show main window" ), gboxNewMails, "chkNewMailsMainWindow" ); + QToolTip::add( chkNewMailsMainWindow, i18n( "Show main window if new mail arrives" ) ); + layMainNewMailsTop->addWidget( chkNewMailsMainWindow, 0, 1 ); + + chkNewMailsBeep = new QCheckBox( i18n( "&Beep" ), gboxNewMails, "chkNewMailsBeep" ); + QToolTip::add( chkNewMailsBeep, i18n( "Beeps the internal speaker if new mail" ) ); + layMainNewMailsTop->addWidget( chkNewMailsBeep, 1, 0 ); + + chkNewMailsSound = new QCheckBox( i18n( "Sound:" ), gboxNewMails, "chkNewMailsSound" ); + QToolTip::add( chkNewMailsSound, i18n( "Plays sound if new mail" ) ); + layMainNewMailsDown->addWidget( chkNewMailsSound, 0, 0 ); + + btnNewMailsPlaySound = new KPushButton( KGuiItem( QString(), QString( "player_play" ), i18n( "Play the selected sound file" ), i18n( "Play the selected sound file" ) ), gboxNewMails, "btnNewMailsPlaySound" ); + layMainNewMailsDown->addWidget( btnNewMailsPlaySound, 0, 1 ); + + txtNewMailsSound = new KLineEdit( gboxNewMails, "txtNewMailsSound" ); + layMainNewMailsDown->addWidget( txtNewMailsSound, 0, 2 ); + + btnNewMailsChooseSound = new KPushButton( KGuiItem( QString(), QString( "folder" ), i18n( "Press to select sound file" ), i18n( "Press to select sound file" ) ), gboxNewMails, "btnNewMailsChooseSound" ); + layMainNewMailsDown->addWidget( btnNewMailsChooseSound, 0, 3 ); + + chkNewMailsCommand = new QCheckBox( i18n( "Command:" ), gboxNewMails, "chkNewMailsCommand" ); + QToolTip::add( chkNewMailsCommand, i18n( "Starts external program if new mail" ) ); + layMainNewMailsDown->addWidget( chkNewMailsCommand, 1, 0 ); + + btnNewMailsExecCommand = new KPushButton( KGuiItem( QString(), QString( "exec" ), i18n( "Start the selected program" ), i18n( "Start the selected program" ) ), gboxNewMails, "btnNewMailsExecCommand" ); + layMainNewMailsDown->addWidget( btnNewMailsExecCommand, 1, 1 ); + + txtNewMailsCommand = new KLineEdit( gboxNewMails, "txtNewMailsCommand" ); + layMainNewMailsDown->addWidget( txtNewMailsCommand, 1, 2 ); + + btnNewMailsChooseCommand = new KPushButton( KGuiItem( QString(), QString( "folder" ), i18n( "Select external command" ), i18n( "Select external command" ) ), gboxNewMails, "btnNewMailsChooseCommand" ); + layMainNewMailsDown->addWidget( btnNewMailsChooseCommand, 1, 3 ); + + //items for the lower group box + chkNoNewMailsMinimize = new QCheckBox( i18n( "Minimi&ze" ), gboxNoNewMails, "chkNoNewMailsMinimize" ); + QToolTip::add( chkNoNewMailsMinimize, i18n( "Minimize window if no new mail" ) ); + + chkNoNewMailsTerminate = new QCheckBox( i18n( "Terminate" ), gboxNoNewMails, "chkNoNewMailsTerminate" ); + QToolTip::add( chkNoNewMailsTerminate, i18n( "Terminate kshowmail if no new mail" ) ); + + //connect file choose buttons + connect( btnNewMailsChooseSound, SIGNAL( clicked() ), this, SLOT( slotChooseSound() ) ); + connect( btnNewMailsChooseCommand, SIGNAL( clicked() ), this, SLOT( slotChooseCommand() ) ); + + //connect test buttons + connect( btnNewMailsPlaySound, SIGNAL( clicked() ), this, SLOT( slotPlaySound() ) ); + connect( btnNewMailsExecCommand, SIGNAL( clicked() ), this, SLOT( slotExecuteCommand() ) ); + + //connect sound and command check boxes to enable or disable the configuration items + connect( chkNewMailsSound, SIGNAL( toggled( bool ) ), this, SLOT( slotSoundToggled( bool ) ) ); + connect( chkNewMailsCommand, SIGNAL( toggled( bool ) ), this, SLOT( slotCommandToggled( bool ) ) ); + + //connect all configuration items with slot changed() to notify the dialog about changes + connect( chkNewMailsAlertWindow, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkNewMailsMainWindow, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkNewMailsBeep, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkNewMailsSound, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkNewMailsCommand, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( txtNewMailsSound, SIGNAL( textChanged( const QString& ) ), this, SLOT( slotChanged() ) ); + connect( txtNewMailsCommand, SIGNAL( textChanged( const QString& ) ), this, SLOT( slotChanged() ) ); + connect( chkNoNewMailsMinimize, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkNoNewMailsTerminate, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + + + + //get application config object (kshowmailrc) + config = KApplication::kApplication()->config(); + + //load configured values + load(); + +} + + +ConfigActions::~ConfigActions() +{ +} + +void ConfigActions::load( ) +{ + config->setGroup( CONFIG_GROUP_ACTIONS ); + + chkNewMailsAlertWindow->setChecked( config->readBoolEntry( CONFIG_ENTRY_NEW_MAIL_ALERTWINDOW, DEFAULT_ACTION_NEW_MAIL_ALERTWINDOW ) ); + chkNewMailsMainWindow->setChecked( config->readBoolEntry( CONFIG_ENTRY_NEW_MAIL_MAINWINDOW, DEFAULT_ACTION_NEW_MAIL_MAINWINDOW ) ); + chkNewMailsBeep->setChecked( config->readBoolEntry( CONFIG_ENTRY_NEW_MAIL_BEEP, DEFAULT_ACTION_NEW_MAIL_BEEP ) ); + chkNewMailsSound->setChecked( config->readBoolEntry( CONFIG_ENTRY_NEW_MAIL_SOUND, DEFAULT_ACTION_NEW_MAIL_SOUND ) ); + chkNewMailsCommand->setChecked( config->readBoolEntry( CONFIG_ENTRY_NEW_MAIL_COMMAND, DEFAULT_ACTION_NEW_MAIL_COMMAND ) ); + chkNoNewMailsTerminate->setChecked( config->readBoolEntry( CONFIG_ENTRY_NO_NEW_MAIL_TERMINATE, DEFAULT_ACTION_NO_NEW_MAIL_TERMINATE ) ); + chkNoNewMailsMinimize->setChecked( config->readBoolEntry( CONFIG_ENTRY_NO_NEW_MAIL_MINIMIZE, DEFAULT_ACTION_NO_NEW_MAIL_MINIMIZE ) ); + + txtNewMailsSound->setText( config->readEntry( CONFIG_ENTRY_NEW_MAIL_SOUNDPATH ) ); + txtNewMailsCommand->setText( config->readEntry( CONFIG_ENTRY_NEW_MAIL_COMMANDPATH ) ); + + //enable or disable configuration items of sound and command + slotSoundToggled( chkNewMailsSound->isChecked() ); + slotCommandToggled( chkNewMailsCommand->isChecked() ); +} + +void ConfigActions::defaults( ) +{ + chkNewMailsAlertWindow->setChecked( DEFAULT_ACTION_NEW_MAIL_ALERTWINDOW ); + chkNewMailsMainWindow->setChecked( DEFAULT_ACTION_NEW_MAIL_MAINWINDOW ); + chkNewMailsBeep->setChecked( DEFAULT_ACTION_NEW_MAIL_BEEP ); + chkNewMailsSound->setChecked( DEFAULT_ACTION_NEW_MAIL_SOUND ); + chkNewMailsCommand->setChecked( DEFAULT_ACTION_NEW_MAIL_COMMAND ); + chkNoNewMailsTerminate->setChecked( DEFAULT_ACTION_NO_NEW_MAIL_TERMINATE ); + chkNoNewMailsMinimize->setChecked( DEFAULT_ACTION_NO_NEW_MAIL_MINIMIZE ); + + //enable or disable configuration items of sound and command + slotSoundToggled( chkNewMailsSound->isChecked() ); + slotCommandToggled( chkNewMailsCommand->isChecked() ); +} + +void ConfigActions::save( ) +{ + config->setGroup( CONFIG_GROUP_ACTIONS ); + config->writeEntry( CONFIG_ENTRY_NEW_MAIL_ALERTWINDOW, chkNewMailsAlertWindow->isChecked() ); + config->writeEntry( CONFIG_ENTRY_NEW_MAIL_MAINWINDOW, chkNewMailsMainWindow->isChecked() ); + config->writeEntry( CONFIG_ENTRY_NEW_MAIL_BEEP, chkNewMailsBeep->isChecked() ); + config->writeEntry( CONFIG_ENTRY_NEW_MAIL_SOUND, chkNewMailsSound->isChecked() ); + config->writeEntry( CONFIG_ENTRY_NEW_MAIL_SOUNDPATH, txtNewMailsSound->text() ); + config->writeEntry( CONFIG_ENTRY_NEW_MAIL_COMMAND, chkNewMailsCommand->isChecked() ); + config->writeEntry( CONFIG_ENTRY_NEW_MAIL_COMMANDPATH, txtNewMailsCommand->text() ); + config->writeEntry( CONFIG_ENTRY_NO_NEW_MAIL_TERMINATE, chkNoNewMailsTerminate->isChecked() ); + config->writeEntry( CONFIG_ENTRY_NO_NEW_MAIL_MINIMIZE, chkNoNewMailsMinimize->isChecked() ); + + //write configuration to disk + config->sync(); +} + +void ConfigActions::slotChooseSound( ) +{ + QString startPath; //start path of the file dialog + + //get sounds directory of kshowmail + KStandardDirs stdDirs; + QString soundPath = stdDirs.findResource( "data", "kshowmail/sounds/" ); + + //get start path of the file dialog + if( txtNewMailsSound->text() != "" ) + { + startPath = txtNewMailsSound->text(); + } + else if( soundPath != QString::null ) + { + startPath = soundPath; + } + else + { + startPath = QString::null; + } + + //open file dialog + QString path = KFileDialog::getOpenFileName( startPath, "*.wav *.ogg|" + i18n( "Sound files (*.wav, *.ogg)" ) + "\n*.*|" + i18n( "All files (*)" ), this, i18n("Select Sound File") ); + + //write selected path into the edit line + if( path != QString::null ) + txtNewMailsSound->setText( path ); +} + +void ConfigActions::slotChooseCommand( ) +{ + //open file dialog + QString path = KFileDialog::getOpenFileName( QString::null, "", this, i18n("Select external command") ); + + //write selected path into the edit line + if( path != QString::null ) + txtNewMailsCommand->setText( path ); +} + +void ConfigActions::slotPlaySound( ) +{ + QString path = txtNewMailsSound->text(); + + if( path != QString::null ) + KAudioPlayer::play( path ); +} + +void ConfigActions::slotExecuteCommand( ) +{ + QString path = txtNewMailsCommand->text(); + + if( path != QString::null ) + { + KShellProcess proc; //process handler to execute the binary + + proc << path; + + proc.start( KShellProcess::DontCare ); + } +} + +void ConfigActions::slotSoundToggled( bool on ) +{ + btnNewMailsPlaySound->setEnabled( on ); + txtNewMailsSound->setEnabled( on ); + btnNewMailsChooseSound->setEnabled( on ); +} + +void ConfigActions::slotCommandToggled( bool on ) +{ + btnNewMailsExecCommand->setEnabled( on ); + txtNewMailsCommand->setEnabled( on ); + btnNewMailsChooseCommand->setEnabled( on ); +} + +void ConfigActions::slotChanged( ) +{ + KCModule::changed(); +} + + +#include "configactions.moc" + + + + + diff --git a/kshowmail/kcmconfigs/configactions.h b/kshowmail/kcmconfigs/configactions.h new file mode 100644 index 0000000..901984f --- /dev/null +++ b/kshowmail/kcmconfigs/configactions.h @@ -0,0 +1,202 @@ +// +// C++ Interface: configactions +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef CONFIGACTIONS_H +#define CONFIGACTIONS_H + +#include <string.h> + +//QT headers +#include <qlayout.h> +#include <qgroupbox.h> +#include <qcheckbox.h> +#include <qtooltip.h> + +//KDE headers +#include <kcmodule.h> +#include <kgenericfactory.h> +#include <kpushbutton.h> +#include <klineedit.h> +#include <kdebug.h> +#include <kapplication.h> +#include <kfiledialog.h> +#include <kaudioplayer.h> +#include <kprocess.h> +#include <kmessagebox.h> +#include <kstandarddirs.h> + +//kshowmail headers +#include "../constants.h" + +/** + * @brief Part of the setup dialog (KShowMailApp::SetupDialog) to configure the actions. + * + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +class ConfigActions : public KCModule +{ +Q_OBJECT + + public: + /** + * Generic Constructor + */ + ConfigActions( QWidget *parent = 0, const char *name = 0, const QStringList &args = QStringList() ); + + /** + * Destructor + */ + ~ConfigActions(); + + /** + * Overloaded method of KCModule. + * Sets the user interface elements to reflect the current settings stored in the + * config file. + */ + virtual void load(); + + /** + * Overloaded method of KCModule. + * Sets the user interface elements to default values. + * This method is called when the user clicks the "Default" button. + */ + virtual void defaults(); + + /** + * Overloaded method of KCModule. + * Stores the config information as shown in the user interface in the + * config file. + * Is called when the user clicks "Apply" or "Ok". + */ + virtual void save(); + + private: + + /** + * Connector to the configuration file + */ + KConfig* config; + + /** + * Check box to select whether an alert message will be shown if a new mail is arrived. + */ + QCheckBox* chkNewMailsAlertWindow; + + /** + * Check box to select whether the main window will be shown if a new mail is arrived. + */ + QCheckBox* chkNewMailsMainWindow; + + /** + * Check box to select whether the system beep will be played if a new mail is arrived. + */ + QCheckBox* chkNewMailsBeep; + + /** + * Check box to select whether a sound will be played if a new mail is arrived. + */ + QCheckBox* chkNewMailsSound; + + /** + * Check box to select whether a command will be executed if a new mail is arrived. + */ + QCheckBox* chkNewMailsCommand; + + /** + * Button to test the sound which will be played if a new mail is arrived. + */ + KPushButton* btnNewMailsPlaySound; + + /** + * Button to test the command which will be executed if a new mail is arrived. + */ + KPushButton* btnNewMailsExecCommand; + + /** + * Edit line which contains the path to the sound file which will be played if a new mail is arrived. + */ + KLineEdit* txtNewMailsSound; + + /** + * Edit line which contains the path to the command which will be executed if a new mail is arrived. + */ + KLineEdit* txtNewMailsCommand; + + /** + * Button to open a file dialog to choose the sound file which will be played if a new is arrived. + */ + KPushButton* btnNewMailsChooseSound; + + /** + * Button to open a file dialog to choose the command which will be executed if a new mail is arrived. + */ + KPushButton* btnNewMailsChooseCommand; + + /** + * Check box to select whether the main window will be minimized if no new mail is arrived. + */ + QCheckBox* chkNoNewMailsMinimize; + + /** + * Check box to select whether the application will be terminated if no new mail is arrived. + */ + QCheckBox* chkNoNewMailsTerminate; + + private slots: + + /** + * Connected with button btnNewMailsChooseSound. + * Opens a file dialog to choose the sound file which will be played. + * Writes the chosen path into the edit line txtNewMailsSound. + */ + void slotChooseSound(); + + /** + * Connected with button btnNewMailsChooseCommand. + * Opens a file dialog to choose the command which shall be executed. + * Writes the chosen path into the edit line txtNewMailsCommand. + */ + void slotChooseCommand(); + + /** + * Connected with button btnNewMailsPlaySound. + * Plays the sound. + */ + void slotPlaySound(); + + /** + * Connected with button btnNewMailsExecCommand. + * Executes the coommand. + */ + void slotExecuteCommand(); + + /** + * Connected with check box chkNewMailsSound. + * Enable or disable the sound configuration items. + * @param on TRUE - box is checked; FALSE - box is not checked + */ + void slotSoundToggled( bool on ); + + /** + * Connected with check box chkNewMailsCommand. + * Enable or disable the command configuration items. + * @param on TRUE - box is checked; FALSE - box is not checked + */ + void slotCommandToggled( bool on ); + + /** + * Connected with the configuration items. + * Calls the slot changed() of KCModule to notify the dialog about the change. + */ + void slotChanged(); +}; + +#endif diff --git a/kshowmail/kcmconfigs/configdisplay.cpp b/kshowmail/kcmconfigs/configdisplay.cpp new file mode 100644 index 0000000..e93027c --- /dev/null +++ b/kshowmail/kcmconfigs/configdisplay.cpp @@ -0,0 +1,221 @@ +// +// C++ Implementation: configdisplay +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "configdisplay.h" + +typedef KGenericFactory<ConfigDisplay, QWidget> ConfigDisplayFactory; + +K_EXPORT_COMPONENT_FACTORY( kcm_kshowmailconfigdisplay, ConfigDisplayFactory( + "kcm_kshowmailconfigdisplay" ) ); + +ConfigDisplay::ConfigDisplay( QWidget * parent, const char * name, const QStringList & args ) + : KCModule( ConfigDisplayFactory::instance(), parent, args ) +{ + //set the module name + if ( !name ) + setName( "configdisplay" ); + + //build GUI + //--------- + + //main layout + QVBoxLayout* layMain = new QVBoxLayout( this, 0, 10 ); + + //group boxes + QGroupBox* gboxAccountlist = new QGroupBox( 0, Qt::Horizontal, i18n( "Account list" ), this, "gboxAccountlist" ); + layMain->addWidget( gboxAccountlist ); + QGroupBox* gboxMessagelist = new QGroupBox( 0, Qt::Horizontal, i18n( "Mail list" ), this, "gboxMessagelist" ); + layMain->addWidget( gboxMessagelist ); + QGroupBox* gboxMessageContent = new QGroupBox( 0, Qt::Horizontal, i18n( "Mail content" ), this, "gboxMessageContent" ); + layMain->addWidget( gboxMessageContent ); + + //group box layouts + QGridLayout* layAccountlist = new QGridLayout( gboxAccountlist->layout(), 3, 2, 10 ); + QGridLayout* layMessagelist = new QGridLayout( gboxMessagelist->layout(), 5, 2, 10 ); + QGridLayout* layMessageContent = new QGridLayout( gboxMessageContent->layout(), 1, 1, 10 ); + + //create items + chkAccountlistActive = new QCheckBox( i18n( "Active" ), gboxAccountlist, "chkAccountlistActive" ); + QToolTip::add( chkAccountlistActive, i18n( "To switch on/off the 'Active' column in the account list" ) ); + layAccountlist->addWidget( chkAccountlistActive, 0, 0 ); + + chkAccountlistAccount = new QCheckBox( i18n( "Account" ), gboxAccountlist, "chkAccountlistAccount" ); + QToolTip::add( chkAccountlistAccount, i18n( "To switch on/off the 'Account' column in the account list" ) ); + layAccountlist->addWidget( chkAccountlistAccount, 0, 1 ); + + chkAccountlistServer = new QCheckBox( i18n( "Server" ), gboxAccountlist, "chkAccountlistServer" ); + QToolTip::add( chkAccountlistServer, i18n( "To switch on/off the 'Server' column in the account list" ) ); + layAccountlist->addWidget( chkAccountlistServer, 1, 0 ); + + chkAccountlistUser = new QCheckBox( i18n( "User" ), gboxAccountlist, "chkAccountlistUser" ); + QToolTip::add( chkAccountlistUser, i18n( "To switch on/off the 'User' column in the account list" ) ); + layAccountlist->addWidget( chkAccountlistUser, 1, 1 ); + + chkAccountlistMessages = new QCheckBox( i18n( "Messages" ), gboxAccountlist, "chkAccountlistMessages" ); + QToolTip::add( chkAccountlistMessages, i18n( "To switch on/off the 'Messages' column in the account list" ) ); + layAccountlist->addWidget( chkAccountlistMessages, 2, 0 ); + + chkAccountlistSize = new QCheckBox( i18n( "Si&ze" ), gboxAccountlist, "chkAccountlistSize" ); + QToolTip::add( chkAccountlistSize, i18n( "To switch on/off the 'Size' column in the account list" ) ); + layAccountlist->addWidget( chkAccountlistSize, 2, 1 ); + + chkMessagelistNumber = new QCheckBox( i18n( "Number" ), gboxMessagelist, "chkMessagelistNumber" ); + QToolTip::add( chkMessagelistNumber, i18n( "To switch on/off the 'Number' column in the message list" ) ); + layMessagelist->addWidget( chkMessagelistNumber, 0, 0 ); + + chkMessagelistAccount = new QCheckBox( i18n( "Account" ), gboxMessagelist, "chkMessagelistAccount" ); + QToolTip::add( chkMessagelistAccount, i18n( "To switch on/off the 'Account' column in the message list" ) ); + layMessagelist->addWidget( chkMessagelistAccount, 0, 1 ); + + chkMessagelistFrom = new QCheckBox( i18n( "From" ), gboxMessagelist, "chkMessagelistFrom" ); + QToolTip::add( chkMessagelistFrom, i18n( "To switch on/off the 'From' column in the message list" ) ); + layMessagelist->addWidget( chkMessagelistFrom, 1, 0 ); + + chkMessagelistTo = new QCheckBox( i18n( "To" ), gboxMessagelist, "chkMessagelistTo" ); + QToolTip::add( chkMessagelistTo, i18n( "To switch on/off the 'To' column in the message list" ) ); + layMessagelist->addWidget( chkMessagelistTo, 1, 1 ); + + chkMessagelistSubject = new QCheckBox( i18n( "Su&bject" ), gboxMessagelist, "chkMessagelistSubject" ); + QToolTip::add( chkMessagelistSubject, i18n( "To switch on/off the 'Subject' column in the message list" ) ); + layMessagelist->addWidget( chkMessagelistSubject, 2, 0 ); + + chkMessagelistDate = new QCheckBox( i18n( "Date" ), gboxMessagelist, "chkMessagelistDate" ); + QToolTip::add( chkMessagelistDate, i18n( "To switch on/off the 'Date' column in the message list" ) ); + layMessagelist->addWidget( chkMessagelistDate, 2, 1 ); + + chkMessagelistSize = new QCheckBox( i18n( "Size" ), gboxMessagelist, "chkMessagelistSize" ); + QToolTip::add( chkMessagelistSize, i18n( "To switch on/off the 'Size' column in the message list" ) ); + layMessagelist->addWidget( chkMessagelistSize, 3, 0 ); + + chkMessagelistContent = new QCheckBox( i18n( "Content" ), gboxMessagelist, "chkMessagelistContent" ); + QToolTip::add( chkMessagelistContent, i18n( "To switch on/off the 'Content' column in the message list" ) ); + layMessagelist->addWidget( chkMessagelistContent, 3, 1 ); + + chkMessagelistState = new QCheckBox( i18n( "State" ), gboxMessagelist, "chkMessagelistState" ); + QToolTip::add( chkMessagelistState, i18n( "To switch on/off the 'State' column in the message list" ) ); + layMessagelist->addWidget( chkMessagelistState, 4, 0 ); + + chkAllowHTML = new QCheckBox( i18n( "Allow HTML" ), gboxMessageContent, "chkAllowHTML" ); + QToolTip::add( chkAllowHTML, i18n( "To switch on/off HTML in the message view") ); + layMessageContent->addWidget( chkAllowHTML, 0, 0 ); + + //connect all configuration itmes with slot changed() to notify the dialog about changes + connect( chkAccountlistActive, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkAccountlistAccount, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkAccountlistServer, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkAccountlistUser, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkAccountlistMessages, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkAccountlistSize, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkMessagelistNumber, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkMessagelistAccount, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkMessagelistFrom, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkMessagelistTo, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkMessagelistSubject, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkMessagelistDate, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkMessagelistSize, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkMessagelistContent, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkMessagelistState, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkAllowHTML, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + + + //get application config object (kshowmailrc) + config = KApplication::kApplication()->config(); + + //load configurated values + load(); +} + +ConfigDisplay::~ConfigDisplay() +{ +} + +void ConfigDisplay::slotChanged( ) +{ + KCModule::changed(); +} + +void ConfigDisplay::load( ) +{ + config->setGroup( CONFIG_GROUP_ACCOUNT_LIST ); + chkAccountlistActive->setChecked( config->readBoolEntry( CONFIG_ENTRY_DISPLAY_ACCOUNT_ACTIVE, DEFAULT_DISPLAY_ACCOUNT_ACTIVE ) ); + chkAccountlistAccount->setChecked( config->readBoolEntry( CONFIG_ENTRY_DISPLAY_ACCOUNT_ACCOUNT, DEFAULT_DISPLAY_ACCOUNT_ACCOUNT ) ); + chkAccountlistServer->setChecked( config->readBoolEntry( CONFIG_ENTRY_DISPLAY_ACCOUNT_SERVER, DEFAULT_DISPLAY_ACCOUNT_SERVER ) ); + chkAccountlistUser->setChecked( config->readBoolEntry( CONFIG_ENTRY_DISPLAY_ACCOUNT_USER, DEFAULT_DISPLAY_ACCOUNT_USER ) ); + chkAccountlistMessages->setChecked( config->readBoolEntry( CONFIG_ENTRY_DISPLAY_ACCOUNT_MESSAGES, DEFAULT_DISPLAY_ACCOUNT_MESSAGES ) ); + chkAccountlistSize->setChecked( config->readBoolEntry( CONFIG_ENTRY_DISPLAY_ACCOUNT_SIZE, DEFAULT_DISPLAY_ACCOUNT_SIZE ) ); + + config->setGroup( CONFIG_GROUP_MESSAGE_LIST ); + chkMessagelistNumber->setChecked( config->readBoolEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_NUMBER, DEFAULT_DISPLAY_MESSAGE_NUMBER ) ); + chkMessagelistAccount->setChecked( config->readBoolEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_ACCOUNT, DEFAULT_DISPLAY_MESSAGE_ACCOUNT ) ); + chkMessagelistFrom->setChecked( config->readBoolEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_FROM, DEFAULT_DISPLAY_MESSAGE_FROM ) ); + chkMessagelistTo->setChecked( config->readBoolEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_TO, DEFAULT_DISPLAY_MESSAGE_TO ) ); + chkMessagelistSubject->setChecked( config->readBoolEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_SUBJECT, DEFAULT_DISPLAY_MESSAGE_SUBJECT ) ); + chkMessagelistDate->setChecked( config->readBoolEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_DATE, DEFAULT_DISPLAY_MESSAGE_DATE ) ); + chkMessagelistSize->setChecked( config->readBoolEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_SIZE, DEFAULT_DISPLAY_MESSAGE_SIZE ) ); + chkMessagelistContent->setChecked( config->readBoolEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_CONTENT, DEFAULT_DISPLAY_MESSAGE_CONTENT ) ); + chkMessagelistState->setChecked( config->readBoolEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_STATE, DEFAULT_DISPLAY_MESSAGE_STATE ) ); + + config->setGroup( CONFIG_GROUP_VIEW ); + chkAllowHTML->setChecked( config->readBoolEntry( CONFIG_ENTRY_VIEW_USE_HTML, DEFAULT_VIEW_USE_HTML ) ); + +} + +void ConfigDisplay::save() +{ + config->setGroup( CONFIG_GROUP_ACCOUNT_LIST ); + config->writeEntry( CONFIG_ENTRY_DISPLAY_ACCOUNT_ACTIVE, chkAccountlistActive->isChecked() ); + config->writeEntry( CONFIG_ENTRY_DISPLAY_ACCOUNT_ACCOUNT, chkAccountlistAccount->isChecked() ); + config->writeEntry( CONFIG_ENTRY_DISPLAY_ACCOUNT_SERVER, chkAccountlistServer->isChecked() ); + config->writeEntry( CONFIG_ENTRY_DISPLAY_ACCOUNT_USER, chkAccountlistUser->isChecked() ); + config->writeEntry( CONFIG_ENTRY_DISPLAY_ACCOUNT_MESSAGES, chkAccountlistMessages->isChecked() ); + config->writeEntry( CONFIG_ENTRY_DISPLAY_ACCOUNT_SIZE, chkAccountlistSize->isChecked() ); + + config->setGroup( CONFIG_GROUP_MESSAGE_LIST ); + config->writeEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_NUMBER, chkMessagelistNumber->isChecked() ); + config->writeEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_ACCOUNT, chkMessagelistAccount->isChecked() ); + config->writeEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_FROM, chkMessagelistFrom->isChecked() ); + config->writeEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_TO, chkMessagelistTo->isChecked() ); + config->writeEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_SUBJECT, chkMessagelistSubject->isChecked() ); + config->writeEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_DATE, chkMessagelistDate->isChecked() ); + config->writeEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_SIZE, chkMessagelistSize->isChecked() ); + config->writeEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_CONTENT, chkMessagelistContent->isChecked() ); + config->writeEntry( CONFIG_ENTRY_DISPLAY_MESSAGE_STATE, chkMessagelistState->isChecked() ); + + config->setGroup( CONFIG_GROUP_VIEW ); + config->writeEntry( CONFIG_ENTRY_VIEW_USE_HTML, chkAllowHTML->isChecked() ); + + //write configuration to disk + config->sync(); +} + +void ConfigDisplay::defaults() +{ + chkAccountlistActive->setChecked( DEFAULT_DISPLAY_ACCOUNT_ACTIVE ); + chkAccountlistAccount->setChecked( DEFAULT_DISPLAY_ACCOUNT_ACCOUNT ); + chkAccountlistServer->setChecked( DEFAULT_DISPLAY_ACCOUNT_SERVER ); + chkAccountlistUser->setChecked( DEFAULT_DISPLAY_ACCOUNT_USER ); + chkAccountlistMessages->setChecked( DEFAULT_DISPLAY_ACCOUNT_MESSAGES ); + chkAccountlistSize->setChecked( DEFAULT_DISPLAY_ACCOUNT_SIZE ); + + chkMessagelistNumber->setChecked( DEFAULT_DISPLAY_MESSAGE_NUMBER ); + chkMessagelistAccount->setChecked( DEFAULT_DISPLAY_MESSAGE_ACCOUNT ); + chkMessagelistFrom->setChecked( DEFAULT_DISPLAY_MESSAGE_FROM ); + chkMessagelistTo->setChecked( DEFAULT_DISPLAY_MESSAGE_TO ); + chkMessagelistSubject->setChecked( DEFAULT_DISPLAY_MESSAGE_SUBJECT ); + chkMessagelistDate->setChecked( DEFAULT_DISPLAY_MESSAGE_DATE ); + chkMessagelistSize->setChecked( DEFAULT_DISPLAY_MESSAGE_SIZE ); + chkMessagelistContent->setChecked( DEFAULT_DISPLAY_MESSAGE_CONTENT ); + chkMessagelistState->setChecked( DEFAULT_DISPLAY_MESSAGE_STATE ); + + chkAllowHTML->setChecked( DEFAULT_VIEW_USE_HTML ); + +} +#include "configdisplay.moc" diff --git a/kshowmail/kcmconfigs/configdisplay.h b/kshowmail/kcmconfigs/configdisplay.h new file mode 100644 index 0000000..847b20b --- /dev/null +++ b/kshowmail/kcmconfigs/configdisplay.h @@ -0,0 +1,169 @@ +// +// C++ Interface: configdisplay +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef CONFIGDISPLAY_H +#define CONFIGDISPLAY_H + +//Qt headers +#include <qlayout.h> +#include <qgroupbox.h> +#include <qcheckbox.h> +#include <qlabel.h> +#include <qtooltip.h> + +//KDE headers +#include <kcmodule.h> +#include <kconfig.h> +#include <kgenericfactory.h> +#include <kapplication.h> + +//KShowmail headers +#include <../constants.h> + + +/** + * @brief Part of the setup dialog (KShowMailApp::SetupDialog) to configure the display. + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +class ConfigDisplay : public KCModule +{ +Q_OBJECT + + public: + /** + * Generic Constructor + */ + ConfigDisplay( QWidget *parent = 0, const char *name = 0, const QStringList &args = QStringList() ); + + /** + * Destructor + */ + ~ConfigDisplay(); + + /** + * Overloaded method of KCModule. + * Sets the user interface elements to reflect the current settings stored in the + * config file. + */ + virtual void load(); + + /** + * Overloaded method of KCModule. + * Sets the user interface elements to default values. + * This method is called when the user clicks the "Default" button. + */ + virtual void defaults(); + + /** + * Overloaded method of KCModule. + * Stores the config information as shown in the user interface in the + * config file. + * Is called when the user clicks "Apply" or "Ok". + */ + virtual void save(); + + private: + + /** + * Connector to the configuration file + */ + KConfig* config; + + /** + * Check box to switch on/off the "Active" column in the account list. + */ + QCheckBox* chkAccountlistActive; + + /** + * Check box to switch on/off the "Account" column in the account list. + */ + QCheckBox* chkAccountlistAccount; + + /** + * Check box to switch on/off the "Server" column in the account list. + */ + QCheckBox* chkAccountlistServer; + + /** + * Check box to switch on/off the "User" column in the account list. + */ + QCheckBox* chkAccountlistUser; + + /** + * Check box to switch on/off the "Messages" column in the account list. + */ + QCheckBox* chkAccountlistMessages; + + /** + * Check box to switch on/off the "Size" column in the account list. + */ + QCheckBox* chkAccountlistSize; + + /** + * Check box to switch on/off the "Number" column in the message list. + */ + QCheckBox* chkMessagelistNumber; + + /** + * Check box to switch on/off the "Account" column in the message list. + */ + QCheckBox* chkMessagelistAccount; + + /** + * Check box to switch on/off the "From" column in the message list. + */ + QCheckBox* chkMessagelistFrom; + + /** + * Check box to switch on/off the "To" column in the message list. + */ + QCheckBox* chkMessagelistTo; + + /** + * Check box to switch on/off the "Subject" column in the message list. + */ + QCheckBox* chkMessagelistSubject; + + /** + * Check box to switch on/off the "Date" column in the message list. + */ + QCheckBox* chkMessagelistDate; + + /** + * Check box to switch on/off the "Size" column in the message list. + */ + QCheckBox* chkMessagelistSize; + + /** + * Check box to switch on/off the "Content" column in the message list. + */ + QCheckBox* chkMessagelistContent; + + /** + * Check box to switch on/off the "State" column in the message list. + */ + QCheckBox* chkMessagelistState; + + /** + * Check box to switch on/off HTML in the message view. + */ + QCheckBox* chkAllowHTML; + + public slots: + + /** + * Connected with the configuration items. + * Calls the slot changed() of KCModule to notify the dialog about the change. + */ + void slotChanged(); +}; + +#endif diff --git a/kshowmail/kcmconfigs/configfilter.cpp b/kshowmail/kcmconfigs/configfilter.cpp new file mode 100644 index 0000000..c999361 --- /dev/null +++ b/kshowmail/kcmconfigs/configfilter.cpp @@ -0,0 +1,613 @@ +// +// C++ Implementation: configfilter +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "configfilter.h" + +typedef KGenericFactory<ConfigFilter, QWidget> ConfigFilterFactory; + +K_EXPORT_COMPONENT_FACTORY( kcm_kshowmailconfigfilter, ConfigFilterFactory( + "kcm_kshowmailconfigfilter" ) ); + +ConfigFilter::ConfigFilter( QWidget * parent, const char * name, const QStringList & args ) + : KCModule( ConfigFilterFactory::instance(), parent, args ) +{ + //set the module name + if ( !name ) + setName( "configfilter" ); + + //build GUI + //--------- + + //main layout + QVBoxLayout* layMain = new QVBoxLayout( this, 0, 10 ); + + //check box to activate the filter + chkActivateFilter = new QCheckBox( i18n( "Activate Filter" ), this, "chkActivateFilter" ); + layMain->addWidget( chkActivateFilter ); + QToolTip::add( chkActivateFilter, i18n( "Check to activate the header filter." ) ); + connect( chkActivateFilter, SIGNAL( toggled( bool ) ), this, SLOT( slotFilterActiveToggled( bool ) ) ); + connect( chkActivateFilter, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + + //GUI of sender lists + //------------------- + gboxSenderLists = new QGroupBox( 0, Qt::Horizontal, i18n( "First Check: Sender Lists" ), this, "gboxSenderLists" ); + QHBoxLayout* laySender = new QHBoxLayout( gboxSenderLists->layout(), 10 ); + layMain->addWidget( gboxSenderLists ); + + btnOpenWhitelist = new KPushButton( KGuiItem( QString( i18n( "Whitelist") ), QString( "mail_forward" ) ), gboxSenderLists, "btnOpenWhitelist" ); + QToolTip::add( btnOpenWhitelist, i18n( "Click here to edit the list of senders whose mails shall pass the filter." ) ); + laySender->addWidget( btnOpenWhitelist ); + laySender->setStretchFactor( btnOpenWhitelist, 3 ); + btnOpenWhitelist->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); + connect( btnOpenWhitelist, SIGNAL( clicked() ), this, SLOT( slotOpenWhitelist() ) ); + + btnOpenBlacklist = new KPushButton( KGuiItem( QString( i18n( "Blacklist" ) ), QString( "mail_delete" ) ), gboxSenderLists, "btnOpenBlacklist" ); + QToolTip::add( btnOpenBlacklist, i18n( "Click here to edit the list of senders whose mails shall be deleted or marked." ) ); + laySender->addWidget( btnOpenBlacklist ); + laySender->setStretchFactor( btnOpenBlacklist, 3 ); + btnOpenBlacklist->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); + connect( btnOpenBlacklist, SIGNAL( clicked() ), this, SLOT( slotOpenBlacklist() ) ); + + laySender->insertStretch( 0, 2 ); + laySender->insertStretch( 2, 2 ); + laySender->insertStretch( 4, 2 ); + + //GUI of filters + //-------------- + gboxFilters = new QGroupBox( 0, Qt::Horizontal, i18n( "Second Check: Filters" ), this, "gboxFilters" ); + QHBoxLayout* layFilters = new QHBoxLayout( gboxFilters->layout(), 10 ); + layMain->addWidget( gboxFilters ); + + listFilters = new KListView( gboxFilters, "listFilters" ); + listFilters->addColumn( i18n( "No." ) ); + listFilters->addColumn( i18n( "Name" ) ); + listFilters->addColumn( i18n( "Action" ) ); + layFilters->addWidget( listFilters ); + listFilters->setColumnWidthMode( 0, QListView::Maximum ); + listFilters->setColumnWidthMode( 1, QListView::Maximum ); + listFilters->setColumnWidthMode( 2, QListView::Maximum ); + listFilters->setResizeMode( QListView::LastColumn ); + listFilters->setColumnAlignment( 0, Qt::AlignHCenter ); + listFilters->setSorting( 0 ); //the list is sorted by filter number + listFilters->setAllColumnsShowFocus( true ); + + QVBoxLayout* layFiltersButtons = new QVBoxLayout( layFilters, 10 ); + btnAdd = new KPushButton( KStdGuiItem::add(), gboxFilters, "btnAdd" ); + btnEdit = new KPushButton( KStdGuiItem::configure(), gboxFilters, "btnEdit" ); + btnRemove = new KPushButton( KStdGuiItem::remove(), gboxFilters, "btnRemove" ); + btnMoveTop = new KPushButton( KGuiItem( "", "top", i18n( "Moves the selected filter at the top" ) ), gboxFilters, "btnMoveTop" ); + btnMoveUp = new KPushButton( KGuiItem( "", "up", i18n( "Moves the selected filter up" ) ), gboxFilters, "btnMoveUp" ); + btnMoveDown = new KPushButton( KGuiItem( "", "down", i18n( "Moves the selected filter down" ) ), gboxFilters, "btnMoveDown" ); + btnMoveBottom = new KPushButton( KGuiItem( "", "bottom", i18n( "Moves the selected filter at the bottm" ) ), gboxFilters, "btnMoveBottom" ); + btnAdd->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ); + btnEdit->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ); + btnRemove->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ); + btnMoveTop->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ); + btnMoveUp->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ); + btnMoveDown->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ); + btnMoveBottom->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ); + layFiltersButtons->addWidget( btnAdd ); + layFiltersButtons->addWidget( btnEdit ); + layFiltersButtons->addWidget( btnRemove ); + layFiltersButtons->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ) ); + layFiltersButtons->addWidget( btnMoveTop ); + layFiltersButtons->addWidget( btnMoveUp ); + layFiltersButtons->addWidget( btnMoveDown ); + layFiltersButtons->addWidget( btnMoveBottom ); + connect( btnAdd, SIGNAL( clicked() ), this, SLOT( slotAdd() ) ); + connect( btnEdit, SIGNAL( clicked() ), this, SLOT( slotEdit() ) ); + connect( btnRemove, SIGNAL( clicked() ), this, SLOT( slotRemove() ) ); + connect( btnMoveTop, SIGNAL( clicked() ), this, SLOT( slotMoveTop() ) ); + connect( btnMoveBottom, SIGNAL( clicked() ), this, SLOT( slotMoveBottom() ) ); + connect( btnMoveUp, SIGNAL( clicked() ), this, SLOT( slotMoveUp() ) ); + connect( btnMoveDown, SIGNAL( clicked() ), this, SLOT( slotMoveDown() ) ); + + + //GUI of Others + //------------- + gboxOthers = new QGroupBox( 0, Qt::Horizontal, i18n( "Third Check: Action for all others" ), this, "gboxOthers" ); + QHBoxLayout* layOthers = new QHBoxLayout( gboxOthers->layout(), 10 ); + layMain->addWidget( gboxOthers ); + + //create combobox to select action + cmbActionOthers = new KComboBox( gboxOthers, "cmbActionOthers" ); + layOthers->addWidget( cmbActionOthers ); + QToolTip::add( cmbActionOthers, i18n( "Choose the action for all mails which are not filtered by the steps before." ) ); + connect( cmbActionOthers, SIGNAL( activated( int ) ), this, SLOT( slotOtherActionChanged( int ) ) ); + connect( cmbActionOthers, SIGNAL( activated( int ) ), this, SLOT( slotChanged() ) ); + + //insert items + cmbActionOthers->insertItem( i18n( "Show" ), ID_COMBO_FILTER_OTHERS_ACTION_PASS ); + cmbActionOthers->insertItem( i18n( "Delete" ), ID_COMBO_FILTER_OTHERS_ACTION_DELETE ); + cmbActionOthers->insertItem( i18n( "Mark" ), ID_COMBO_FILTER_OTHERS_ACTION_MARK ); + cmbActionOthers->insertItem( i18n( "Move" ), ID_COMBO_FILTER_OTHERS_ACTION_MOVE ); + cmbActionOthers->insertItem( i18n( "Spamcheck" ), ID_COMBO_FILTER_OTHERS_ACTION_SPAMCHECK ); + cmbActionOthers->insertItem( i18n( "Ignore" ), ID_COMBO_FILTER_OTHERS_ACTION_IGNORE ); + + //create edit line to defined the mailbox for move + txtMailbox = new KLineEdit( gboxOthers ); + layOthers->addWidget( txtMailbox ); + connect( txtMailbox, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotChanged() ) ); + + //create wizard button to configure mailbox + btnMailboxWizard= new KPushButton( KGuiItem( QString::null, "wizard" ), gboxOthers ); + layOthers->addWidget( btnMailboxWizard ); + QToolTip::add( btnMailboxWizard, i18n( "Choose the mailbox" ) ); + connect( btnMailboxWizard, SIGNAL( clicked() ), this, SLOT( slotOpenMailBoxWizard() ) ); + + //set defaults + switch( DEFAULT_FILTER_OTHERS_ACTION ) + { + case CONFIG_VALUE_FILTER_OTHERS_ACTION_PASS : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_PASS ); break; + case CONFIG_VALUE_FILTER_OTHERS_ACTION_DELETE : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_DELETE ); break; + case CONFIG_VALUE_FILTER_OTHERS_ACTION_MARK : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_MARK ); break; + case CONFIG_VALUE_FILTER_OTHERS_ACTION_MOVE : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_MOVE ); break; + case CONFIG_VALUE_FILTER_OTHERS_ACTION_IGNORE : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_IGNORE ); break; + case CONFIG_VALUE_FILTER_OTHERS_ACTION_SPAMCHECK : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_SPAMCHECK ); break; + } + chkActivateFilter->setChecked( DEFAULT_FILTER_ACTIVE ); + + //enable or disable widgets + slotOtherActionChanged( cmbActionOthers->currentItem() ); + slotFilterActiveToggled( DEFAULT_FILTER_ACTIVE ); + + //get application config object (kshowmailrc) + config = KApplication::kApplication()->config(); + + //init counter for filter item numbering. This variable contains the last assigned number of a filter setup item. + //Because it is initialized with zero, the first filter number is 1. + lastFilterNumber = 0; + + //load configured values + load(); +} + + +ConfigFilter::~ConfigFilter() +{ +} + +void ConfigFilter::load( ) +{ + config->setGroup( CONFIG_GROUP_FILTER ); + + //load filter active state + chkActivateFilter->setChecked( config->readBoolEntry( CONFIG_ENTRY_FILTER_ACTIVE, DEFAULT_FILTER_ACTIVE ) ); + slotFilterActiveToggled( chkActivateFilter->isOn() ); + + //load other action + switch( config->readNumEntry( CONFIG_ENTRY_FILTER_OTHERS_ACTION, DEFAULT_FILTER_OTHERS_ACTION ) ) + { + case CONFIG_VALUE_FILTER_OTHERS_ACTION_PASS : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_PASS ); break; + case CONFIG_VALUE_FILTER_OTHERS_ACTION_DELETE : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_DELETE ); break; + case CONFIG_VALUE_FILTER_OTHERS_ACTION_MARK : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_MARK ); break; + case CONFIG_VALUE_FILTER_OTHERS_ACTION_MOVE : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_MOVE ); break; + case CONFIG_VALUE_FILTER_OTHERS_ACTION_IGNORE : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_IGNORE ); break; + case CONFIG_VALUE_FILTER_OTHERS_ACTION_SPAMCHECK : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_SPAMCHECK ); break; + } + + //get mailbox name + if( config->readNumEntry( CONFIG_ENTRY_FILTER_OTHERS_ACTION, DEFAULT_FILTER_OTHERS_ACTION ) == CONFIG_VALUE_FILTER_OTHERS_ACTION_MOVE ) + txtMailbox->setText( config->readEntry( CONFIG_ENTRY_FILTER_OTHERS_MAILBOX, DEFAULT_FILTER_ACTION_MOVE_MAILBOX ) ); + else + txtMailbox->clear(); + + //enable or disable widgets for other action + slotOtherActionChanged( cmbActionOthers->currentItem() ); + + //get number of filters + uint numFilters = config->readNumEntry( CONFIG_ENTRY_FILTER_NUMBER_OF_FILTERS, 0 ); + + //create filter setup items and load theirs settings + for( uint ctr = 1; ctr <= numFilters; ctr++ ) + { + //create filter item + FilterSetupItem* item = new FilterSetupItem( listFilters, ctr ); + + //load settings + item->load(); + } + + //set filter index counter + lastFilterNumber = numFilters; +} + +void ConfigFilter::defaults( ) +{ + switch( DEFAULT_FILTER_OTHERS_ACTION ) + { + case CONFIG_VALUE_FILTER_OTHERS_ACTION_PASS : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_PASS ); break; + case CONFIG_VALUE_FILTER_OTHERS_ACTION_DELETE : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_DELETE ); break; + case CONFIG_VALUE_FILTER_OTHERS_ACTION_MARK : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_MARK ); break; + case CONFIG_VALUE_FILTER_OTHERS_ACTION_MOVE : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_MOVE ); break; + case CONFIG_VALUE_FILTER_OTHERS_ACTION_IGNORE : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_IGNORE ); break; + case CONFIG_VALUE_FILTER_OTHERS_ACTION_SPAMCHECK : cmbActionOthers->setCurrentItem( ID_COMBO_FILTER_OTHERS_ACTION_SPAMCHECK ); break; + } + + if( DEFAULT_FILTER_OTHERS_ACTION == CONFIG_VALUE_FILTER_OTHERS_ACTION_MOVE ) + txtMailbox->setText( QString( DEFAULT_FILTER_ACTION_MOVE_MAILBOX ) ); + else + txtMailbox->clear(); + + //enable or disable widgets for other action + slotOtherActionChanged( cmbActionOthers->currentItem() ); + + slotChanged(); +} + +void ConfigFilter::save( ) +{ + config->setGroup( CONFIG_GROUP_FILTER ); + + //save filter active state + config->writeEntry( CONFIG_ENTRY_FILTER_ACTIVE, chkActivateFilter->isOn() ); + + //save other action + switch( cmbActionOthers->currentItem() ) + { + case ID_COMBO_FILTER_OTHERS_ACTION_PASS : config->writeEntry( CONFIG_ENTRY_FILTER_OTHERS_ACTION, CONFIG_VALUE_FILTER_OTHERS_ACTION_PASS ); break; + case ID_COMBO_FILTER_OTHERS_ACTION_DELETE : config->writeEntry( CONFIG_ENTRY_FILTER_OTHERS_ACTION, CONFIG_VALUE_FILTER_OTHERS_ACTION_DELETE ); break; + case ID_COMBO_FILTER_OTHERS_ACTION_MARK : config->writeEntry( CONFIG_ENTRY_FILTER_OTHERS_ACTION, CONFIG_VALUE_FILTER_OTHERS_ACTION_MARK ); break; + case ID_COMBO_FILTER_OTHERS_ACTION_MOVE : config->writeEntry( CONFIG_ENTRY_FILTER_OTHERS_ACTION, CONFIG_VALUE_FILTER_OTHERS_ACTION_MOVE ); break; + case ID_COMBO_FILTER_OTHERS_ACTION_IGNORE : config->writeEntry( CONFIG_ENTRY_FILTER_OTHERS_ACTION, CONFIG_VALUE_FILTER_OTHERS_ACTION_IGNORE ); break; + case ID_COMBO_FILTER_OTHERS_ACTION_SPAMCHECK : config->writeEntry( CONFIG_ENTRY_FILTER_OTHERS_ACTION, CONFIG_VALUE_FILTER_OTHERS_ACTION_SPAMCHECK ); break; + default : config->writeEntry( CONFIG_ENTRY_FILTER_OTHERS_ACTION, DEFAULT_FILTER_OTHERS_ACTION ); break; + } + + //save mailbox name + if( cmbActionOthers->currentItem() == ID_COMBO_FILTER_OTHERS_ACTION_MOVE ) + { + config->writeEntry( CONFIG_ENTRY_FILTER_OTHERS_MAILBOX, txtMailbox->text() ); + } + else + { + config->deleteEntry( CONFIG_ENTRY_FILTER_OTHERS_MAILBOX ); + } + + //get old number of filters + uint oldNumFilter = config->readNumEntry( CONFIG_ENTRY_FILTER_NUMBER_OF_FILTERS, 0 ); + + //save current number of filters + config->writeEntry( CONFIG_ENTRY_FILTER_NUMBER_OF_FILTERS, lastFilterNumber ); + + //delete surplus filter configurations + if( oldNumFilter > lastFilterNumber ) + { + for( uint ctr = lastFilterNumber + 1; ctr <= oldNumFilter; ctr++ ) + { + config->deleteGroup( QString( "%1%2" ).arg( CONFIG_GROUP_FILTER ).arg( ctr ) ); + } + } + + //save the filters + QListViewItemIterator it( listFilters ); + + while( it.current() ) + { + ( (FilterSetupItem*)it.current() )->save(); + + //get next item + ++it; + } + + + config->sync(); +} + +void ConfigFilter::slotChanged( ) +{ + KCModule::changed(); +} + +void ConfigFilter::slotOpenWhitelist( ) +{ + //open list dialog + SenderListDialog* dlg = new SenderListDialog( this, SenderListDialog::White, "dlgWhiteList" ); + dlg->exec(); + + //delete dialog + delete dlg; +} + +void ConfigFilter::slotOpenBlacklist( ) +{ + //open list dialog + SenderListDialog* dlg = new SenderListDialog( this, SenderListDialog::Black, "dlgBlackList" ); + dlg->exec(); + + //delete dialog + delete dlg; +} + +void ConfigFilter::slotAdd( ) +{ + //create a new filter setup item + FilterSetupItem* item = new FilterSetupItem( listFilters , lastFilterNumber + 1 ); + + //open setup dialog + FilterSetupDialog* dlg = new FilterSetupDialog( this, item ); + int res = dlg->exec(); + + if( res == KDialogBase::Accepted ) + { + //inform application setup dialog about changes + slotChanged(); + + //increase variable for the last assigned filter number + lastFilterNumber++; + } + else + //delete new item because the user don't want it + delete item; + + //delete dialog + delete dlg; +} + +void ConfigFilter::slotEdit( ) +{ + //get selected item + FilterSetupItem* item = (FilterSetupItem*)listFilters->selectedItem(); + + //return if no item selected + if( item == NULL ) return; + + //open setup dialog + FilterSetupDialog* dlg = new FilterSetupDialog( this, item ); + int res = dlg->exec(); + + //inform application setup dialog about changes + if( res == KDialogBase::Accepted ) + slotChanged(); + + //delete dialog + delete dlg; + +} + +void ConfigFilter::slotRemove( ) +{ + //get selected item + FilterSetupItem* item = (FilterSetupItem*)listFilters->selectedItem(); + + if( item != NULL ) + { + //get number of the item + uint num = item->getNumber(); + + //delete item + delete item; + + //decrease the number of all filter items after the removed one + decreaseNumbers( num + 1 ); + + //decrease last assigned number + lastFilterNumber--; + + //inform application setup dialog about changes + slotChanged(); + } +} + +void ConfigFilter::slotOtherActionChanged( int index ) +{ + switch( index ) + { + case ID_COMBO_FILTER_OTHERS_ACTION_MOVE : txtMailbox->setEnabled( true ); + if( txtMailbox->text() == "" ) txtMailbox->setText( DEFAULT_FILTER_ACTION_MOVE_MAILBOX ); + btnMailboxWizard->setHidden( false ); + break; + default : txtMailbox->setEnabled( false ); + btnMailboxWizard->setHidden( true ); + break; + } +} + +void ConfigFilter::decreaseNumbers( uint number ) +{ + //get an iterator of the list view + QListViewItemIterator it( listFilters ); + + //iterate over the filter list + while( it.current() ) + { + //get number of current filter item + uint curNumber = ( (FilterSetupItem*)it.current() )->getNumber(); + + //decrease current number, if the given number is lesser or equals + if( curNumber >= number && curNumber > 0 ) + ( (FilterSetupItem*)it.current() )->setNumber( curNumber - 1 ); + + //get next item + ++it; + } +} + +void ConfigFilter::slotMoveTop( ) +{ + //get selected item + FilterSetupItem* item = (FilterSetupItem*)listFilters->selectedItem(); + + if( item != NULL ) + { + //get number of the item + uint num = item->getNumber(); + + if( num > 1 ) + { + //set number of the selected to zero, this will move it at the top + item->setNumber( 0 ); + + //now we move all items after the old position one step up + decreaseNumbers( num + 1 ); + + //at last we add one to all numbers + QListViewItemIterator it( listFilters ); + + while( it.current() ) + { + uint curNumber = ( (FilterSetupItem*)it.current() )->getNumber(); + ( (FilterSetupItem*)it.current() )->setNumber( curNumber + 1 ); + + ++it; + } + + //refresh list view + listFilters->sort(); + + //inform application setup dialog about changes + slotChanged(); + + } + } + + +} + +void ConfigFilter::slotMoveBottom( ) +{ + //get selected item + FilterSetupItem* item = (FilterSetupItem*)listFilters->selectedItem(); + + if( item != NULL ) + { + //get number of the item + uint num = item->getNumber(); + + if( num < lastFilterNumber ) + { + //move the selected item at the bottom + item->setNumber( lastFilterNumber + 1 ); + + //move all items after the old position one step up (decrease number) + decreaseNumbers( num + 1 ); + + //refresh list view + listFilters->sort(); + + //inform application setup dialog about changes + slotChanged(); + } + + } +} + +void ConfigFilter::slotMoveUp( ) +{ + //get selected item + FilterSetupItem* item = (FilterSetupItem*)listFilters->selectedItem(); + + if( item != NULL ) + { + //get number of the item + uint num = item->getNumber(); + + if( num > 1 ) + { + //get item before the selected one + FilterSetupItem* itemBefore = getFilterItem( num - 1 ); + + if( itemBefore != NULL ) + { + //swap numbers + item->setNumber( num - 1 ); + itemBefore->setNumber( num ); + + //inform application setup dialog about changes + slotChanged(); + + } + } + //refresh list view + listFilters->sort(); + } +} + +void ConfigFilter::slotMoveDown( ) +{ + //get selected item + FilterSetupItem* item = (FilterSetupItem*)listFilters->selectedItem(); + + if( item != NULL ) + { + //get number of the item + uint num = item->getNumber(); + + if( num < lastFilterNumber ) + { + //get item behind the selected one + FilterSetupItem* itemBehind = getFilterItem( num + 1 ); + + if( itemBehind != NULL ) + { + //swap numbers + item->setNumber( num + 1 ); + itemBehind->setNumber( num ); + + //inform application setup dialog about changes + slotChanged(); + + } + } + //refresh list view + listFilters->sort(); + } +} + +FilterSetupItem* ConfigFilter::getFilterItem( uint num ) +{ + FilterSetupItem* foundItem = NULL; + bool found = false; + + //get Iterator + QListViewItemIterator it( listFilters ); + + //iterate over th elist to look for the item + while( it.current() && !found ) + { + //get current number + uint curNumber = ( (FilterSetupItem*)it.current() )->getNumber(); + + //have we found it? + if( curNumber == num ) + { + foundItem = (FilterSetupItem*)it.current(); + + found = true; + } + + ++it; + } + + return foundItem; +} + +void ConfigFilter::slotFilterActiveToggled( bool filterOn ) +{ + gboxSenderLists->setEnabled( filterOn ); + gboxFilters->setEnabled( filterOn ); + gboxOthers->setEnabled( filterOn ); +} + +void ConfigFilter::slotOpenMailBoxWizard( ) +{ + MailBoxWizard wizard( this, "malboxwizard" ); + wizard.setCaption( i18n( "Mailbox Select" ) ); + int res = wizard.exec(); + + if( res == QDialog::Accepted ) + txtMailbox->setText( wizard.getPath() ); + +} + + + +#include "configfilter.moc" diff --git a/kshowmail/kcmconfigs/configfilter.h b/kshowmail/kcmconfigs/configfilter.h new file mode 100644 index 0000000..9d37c82 --- /dev/null +++ b/kshowmail/kcmconfigs/configfilter.h @@ -0,0 +1,288 @@ +// +// C++ Interface: configfilter +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef CONFIGFILTER_H +#define CONFIGFILTER_H + +//QT headers +#include <qlayout.h> +#include <qgroupbox.h> +#include <qtooltip.h> +#include <qcheckbox.h> + +//KDE headers +#include <kcmodule.h> +#include <kconfig.h> +#include <kgenericfactory.h> +#include <kapplication.h> +#include <klistview.h> +#include <kpushbutton.h> +#include <kcombobox.h> +#include <klineedit.h> + +//Kshowmail headers +#include "../constants.h" +#include "senderlistdialog.h" +#include "filtersetupdialog.h" +#include "mailboxwizard.h" + +//radio button IDs +#define ID_COMBO_FILTER_OTHERS_ACTION_PASS 0 +#define ID_COMBO_FILTER_OTHERS_ACTION_DELETE 1 +#define ID_COMBO_FILTER_OTHERS_ACTION_MARK 2 +#define ID_COMBO_FILTER_OTHERS_ACTION_MOVE 3 +#define ID_COMBO_FILTER_OTHERS_ACTION_SPAMCHECK 4 +#define ID_COMBO_FILTER_OTHERS_ACTION_IGNORE 5 + + +/** + * @brief Part of the setup dialog (KShowMailApp::SetupDialog) to configure the filter. + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +class ConfigFilter : public KCModule +{ +Q_OBJECT + + public: + + /** + * Generic constructor + */ + ConfigFilter( QWidget* parent = 0, const char* name = 0, const QStringList &args = QStringList() ); + + /** + * Destructor + */ + ~ConfigFilter(); + + /** + * Overloaded method of KCModule. + * Sets the user interface elements to reflect the current settings stored in the + * config file. + */ + virtual void load(); + + /** + * Overloaded method of KCModule. + * Sets the user interface elements to default values. + * This method is called when the user clicks the "Default" button. + */ + virtual void defaults(); + + /** + * Overloaded method of KCModule. + * Stores the config information as shown in the user interface in the + * config file. + * Is called when the user clicks "Apply" or "Ok". + */ + virtual void save(); + + private: + + /** + * Connector to the configuration file + */ + KConfig* config; + + /** + * Check box to activate the filter + */ + QCheckBox* chkActivateFilter; + + /** + * Group box for sender lists. + */ + QGroupBox* gboxSenderLists; + + /** + * Group box for filter items. + */ + QGroupBox* gboxFilters; + + /** + * Group box for other action. + */ + QGroupBox* gboxOthers; + + /** + * Button to open the Blacklist. + */ + KPushButton* btnOpenBlacklist; + + /** + * Button to open the Whitelist. + */ + KPushButton* btnOpenWhitelist; + + /** + * List of filters + */ + KListView* listFilters; + + /** + * Button to move a filter at top. + */ + KPushButton* btnMoveTop; + + /** + * Button to move a filter at bottom. + */ + KPushButton* btnMoveBottom; + + /** + * Button to move a filter up. + */ + KPushButton* btnMoveUp; + + /** + * Button to move a filter down. + */ + KPushButton* btnMoveDown; + + /** + * Button to add a new filter. + */ + KPushButton* btnAdd; + + /** + * Button to edit a filter. + */ + KPushButton* btnEdit; + + /** + * Button to remove a filter. + */ + KPushButton* btnRemove; + + /** + * Combobox to select the action for the rest of mails. + */ + KComboBox* cmbActionOthers; + + /** + * If selected, the other mails will be moved to the mailbox which is written in this edit line. + */ + KLineEdit* txtMailbox; + + /** + * This button opens a wizard which will help to get the right mailbox + */ + KPushButton* btnMailboxWizard; + + /** + * The last assigned number of a filter setup item. + * It is set to zero by the constructor. Therefore the first filter number is 1. + */ + uint lastFilterNumber; + + private slots: + + /** + * Connected with the configuration items. + * Calls the slot changed() of KCModule to notify the dialog about the change. + */ + void slotChanged(); + + /** + * Connected with the button btnOpenWhitelist. + * Creates and opens a dialog to edit the whitelist. + */ + void slotOpenWhitelist(); + + /** + * Connected with the button btnOpenBlacklist. + * Creates and opens a dialog to edit the blacklist. + */ + void slotOpenBlacklist(); + + /** + * Connected with button btnAdd. + * Opens the account setup dialog with an account item pointer of NULL. + * If the user has clicked OK, the dialog will create a new account item with + * the entered values and adds it to the list view. + */ + void slotAdd(); + + /** + * Connected with button btnEdit. + * Opens the account setup with the selected account item. + */ + void slotEdit(); + + /** + * Connected with button btnRemove. + * Removes the selected item. + */ + void slotRemove(); + + /** + * Connected with combobox cmbActionOthers. + * Enables or disables additional widgets for action configuration. + * @param index position (index) of the selected action + */ + void slotOtherActionChanged( int index ); + + /** + * Connected with button btnMoveTop. + * Moves the selected filter item at the top of the list, i.e. the number of this item will be the least one. + */ + void slotMoveTop(); + + /** + * Connected with button btnMoveBottom. + * Moves the selected filter item at the bottom of the list, i.e. the number of this item will be the greatest one. + */ + void slotMoveBottom(); + + /** + * Connected with button btnMoveUp. + * Moves the selected filter item up, i.e. the number of this item will be decreased. + */ + void slotMoveUp(); + + /** + * Connected with button btnMoveDown. + * Moves the selected filter item down, i.e. the number of this item will be increased. + */ + void slotMoveDown(); + + /** + * Connected with chkActivateFilter, signal toggled(). + * Enabled or disabled the other widget of this GUI. + * @param filterOn TRUE - filter is active; FALSE - filter is not active + */ + void slotFilterActiveToggled( bool filterOn ); + + /** + * Connected with button btnMailboxWizard. + * Opens a wizard to configure the mailbox + */ + void slotOpenMailBoxWizard(); + + + protected: + + /** + * Decrease the numbers of these filter setup items whose number is greater than or equals num. + * @param number start number of renumbering + */ + void decreaseNumbers( uint number ); + + /** + * Returns the pointer to the filter setup item with number num. Returns 0 if no item found. + * @param num number of the searched filter item + * @return pointer to the found item + */ + FilterSetupItem* getFilterItem( uint num ); + +}; + +#endif diff --git a/kshowmail/kcmconfigs/configgeneral.cpp b/kshowmail/kcmconfigs/configgeneral.cpp new file mode 100644 index 0000000..0bffeca --- /dev/null +++ b/kshowmail/kcmconfigs/configgeneral.cpp @@ -0,0 +1,181 @@ +// +// C++ Implementation: configgeneral +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "configgeneral.h" + +typedef KGenericFactory<ConfigGeneral, QWidget> ConfigGeneralFactory; + +K_EXPORT_COMPONENT_FACTORY( kcm_kshowmailconfiggeneral, ConfigGeneralFactory( + "kcm_kshowmailconfiggeneral" ) ); + +ConfigGeneral::ConfigGeneral( QWidget * parent, const char * name, const QStringList & args ) + : KCModule( ConfigGeneralFactory::instance(), parent, args ) +{ + //set the module name + if ( !name ) + setName( "configgeneral" ); + + //build GUI + //--------- + + //main layout + QVBoxLayout* layMain = new QVBoxLayout( this, 0, 10 ); + + //layout for check buttons (upper half) + QGridLayout* layMainTop = new QGridLayout( layMain, 4, 2, 15 ); + layMainTop->setMargin( 20 ); + + //group box for timers + QGroupBox* gboxTimers = new QGroupBox( 0, Qt::Horizontal, i18n( "&Timers" ), this, "gboxTimers" ); + layMain->addWidget( gboxTimers ); + + //layouts for timers + QGridLayout* layTimers = new QGridLayout( gboxTimers->layout(),3, 3, 20 ); + + //create items + chkConfirmClose = new QCheckBox( i18n( "Confirm Close" ), this, "chkConfirmClose" ); + QToolTip::add( chkConfirmClose, i18n( "If checked, window close must be confirmed" ) ); + layMainTop->addWidget( chkConfirmClose, 0, 0 ); + + chkConfirmDelete = new QCheckBox( i18n( "Confirm delete" ), this, "chkConfirmDelete" ); + QToolTip::add( chkConfirmDelete, i18n( "If checked, message delete must be confirmed" ) ); + layMainTop->addWidget( chkConfirmDelete, 0, 1 ); + + chkStartMinimized = new QCheckBox( i18n( "Start Minimi&zed" ), this, "chkStartMinimized" ); + QToolTip::add( chkStartMinimized, i18n( "Application is started as icon" ) ); + layMainTop->addWidget( chkStartMinimized, 1, 0 ); + + chkCloseToTray = new QCheckBox( i18n( "Close to tray" ), this, "chkCloseToTray" ); + QToolTip::add( chkCloseToTray, i18n( "Close button leaves the application running in tray" ) ); + layMainTop->addWidget( chkCloseToTray, 1, 1 ); + + chkMinimizeToTray = new QCheckBox( i18n( "Minimize to tray" ), this, "chkMinimizeToTray" ); + QToolTip::add( chkMinimizeToTray, i18n( "Minimizes to the tray rather than to the taskbar" ) ); + layMainTop->addWidget( chkMinimizeToTray, 2, 0 ); + + chkShowConnectionErrors = new QCheckBox( i18n( "Show Connection Errors during refresh" ), this, "chkShowConnectionErrors" ); + QToolTip::add( chkShowConnectionErrors, i18n( "If a connection error occurs during refresh (e.g. unknown server), an error message will be shown. During other actions, this error always will be shown" ) ); + layMainTop->addWidget( chkShowConnectionErrors, 2, 1 ); + + chkKeepNew = new QCheckBox( i18n( "&Keep mail as new" ), this, "chkKeepNew" ); + QToolTip::add( chkKeepNew, i18n( "Keep mail as new until termination" ) ); + layMainTop->addWidget( chkKeepNew, 3, 0 ); + + QLabel* lblTimerInitial = new QLabel( i18n( "Initial Timer:" ), gboxTimers, "lblTimerInitial" ); + QLabel* lblInitialUnit = new QLabel( i18n( "[Seconds]" ), gboxTimers, "lblInitialUnit" ); + spbInitial = new QSpinBox( 0, 99999, 1, gboxTimers, "spbInitial" ); + QToolTip::add( spbInitial, i18n( "Seconds until first automatic logon (0 = no automatic)" ) ); + QToolTip::add( lblTimerInitial, i18n( "Seconds until first automatic logon (0 = no automatic)" ) ); + layTimers->addWidget( lblTimerInitial, 0, 0 ); + layTimers->addWidget( spbInitial, 0, 1 ); + layTimers->addWidget( lblInitialUnit, 0, 2 ); + + QLabel* lblTimerInterval = new QLabel( i18n( "Interval Timer:" ), gboxTimers, "lblTimerInterval" ); + QLabel* lblIntervalUnit = new QLabel( i18n( "[Minutes]" ), gboxTimers, "lblIntervalUnit" ); + spbInterval = new QSpinBox( 0, 99999, 1, gboxTimers, "spbInterval" ); + QToolTip::add( spbInterval, i18n( "Minutes between automatic logon (0 = no automatic)" ) ); + QToolTip::add( lblTimerInterval, i18n( "Minutes between automatic logon (0 = no automatic)" ) ); + layTimers->addWidget( lblTimerInterval, 1, 0 ); + layTimers->addWidget( spbInterval, 1, 1 ); + layTimers->addWidget( lblIntervalUnit, 1, 2 ); + + QLabel* lblTimerTimeout = new QLabel( i18n( "Timeout:" ), gboxTimers, "lblTimerTimeout" ); + QLabel* lblTimeoutUnit = new QLabel( i18n( "[Seconds]" ), gboxTimers, "lblTimeoutUnit" ); + spbTimeout = new QSpinBox( MINIMUM_TIMEOUT_TIME, 99999, 1, gboxTimers, "spbTimeout" ); + QToolTip::add( spbTimeout, i18n( "Seconds until a server connect will be canceled" ) ); + QToolTip::add( lblTimerTimeout, i18n( "Seconds until a server connect will be canceled" ) ); + layTimers->addWidget( lblTimerTimeout, 2, 0 ); + layTimers->addWidget( spbTimeout, 2, 1 ); + layTimers->addWidget( lblTimeoutUnit, 2, 2 ); + + + //connect all configuration itmes with slot changed() to notify the dialog about changes + connect( chkConfirmClose, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkConfirmDelete, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkStartMinimized, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkCloseToTray, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkMinimizeToTray, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkShowConnectionErrors, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkKeepNew, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( spbInitial, SIGNAL( valueChanged( int ) ), this, SLOT( slotChanged() ) ); + connect( spbInterval, SIGNAL( valueChanged( int ) ), this, SLOT( slotChanged() ) ); + connect( spbTimeout, SIGNAL( valueChanged( int ) ), this, SLOT( slotChanged() ) ); + + + //get application config object (kshowmailrc) + config = KApplication::kApplication()->config(); + + //load configurated values + load(); + +} + +ConfigGeneral::~ConfigGeneral() +{ +} + +void ConfigGeneral::load( ) +{ + config->setGroup( CONFIG_GROUP_GENERAL ); + + chkConfirmClose->setChecked( config->readBoolEntry( CONFIG_ENTRY_CONFIRM_CLOSE, DEFAULT_CONFIRM_CLOSE ) ); + chkConfirmDelete->setChecked( config->readBoolEntry( CONFIG_ENTRY_CONFIRM_DELETE, DEFAULT_CONFIRM_DELETE ) ); + chkStartMinimized->setChecked( config->readBoolEntry( CONFIG_ENTRY_START_MINIMIZED, DEFAULT_START_MINIMIZED ) ); + chkCloseToTray->setChecked( config->readBoolEntry( CONFIG_ENTRY_CLOSE_TO_TRAY, DEFAULT_CLOSE_TO_TRAY ) ); + chkMinimizeToTray->setChecked( config->readBoolEntry( CONFIG_ENTRY_MINIMIZE_TO_TRAY, DEFAULT_MINIMIZE_TO_TRAY ) ); + chkShowConnectionErrors->setChecked( config->readBoolEntry( CONFIG_ENTRY_SHOW_CONNECTION_ERRORS, DEFAULT_SHOW_CONNECTION_ERRORS ) ); + chkKeepNew->setChecked( config->readBoolEntry( CONFIG_ENTRY_KEEP_NEW, DEFAULT_KEEP_NEW ) ); + + spbInitial->setValue( config->readNumEntry( CONFIG_ENTRY_INITIAL_TIME, DEFAULT_INITIAL_TIME ) ); + spbInterval->setValue( config->readNumEntry( CONFIG_ENTRY_INTERVAL_TIME, DEFAULT_INTERVAL_TIME) ); + spbTimeout->setValue( config->readNumEntry( CONFIG_ENTRY_TIMEOUT_TIME, DEFAULT_TIMEOUT_TIME) ); +} + +void ConfigGeneral::defaults( ) +{ + chkConfirmClose->setChecked( DEFAULT_CONFIRM_CLOSE ); + chkConfirmDelete->setChecked( DEFAULT_CONFIRM_DELETE ); + chkStartMinimized->setChecked( DEFAULT_START_MINIMIZED ); + chkCloseToTray->setChecked( DEFAULT_CLOSE_TO_TRAY ); + chkMinimizeToTray->setChecked( DEFAULT_MINIMIZE_TO_TRAY ); + chkShowConnectionErrors->setChecked( DEFAULT_SHOW_CONNECTION_ERRORS ); + chkKeepNew->setChecked( DEFAULT_KEEP_NEW ); + + spbInitial->setValue( DEFAULT_INITIAL_TIME ); + spbInterval->setValue( DEFAULT_INTERVAL_TIME ); + spbTimeout->setValue( DEFAULT_TIMEOUT_TIME ); +} + +void ConfigGeneral::save( ) +{ + config->setGroup( CONFIG_GROUP_GENERAL ); + + config->writeEntry( CONFIG_ENTRY_CONFIRM_CLOSE, chkConfirmClose->isChecked() ); + config->writeEntry( CONFIG_ENTRY_CONFIRM_DELETE, chkConfirmDelete->isChecked() ); + config->writeEntry( CONFIG_ENTRY_START_MINIMIZED, chkStartMinimized->isChecked() ); + config->writeEntry( CONFIG_ENTRY_CLOSE_TO_TRAY, chkCloseToTray->isChecked() ); + config->writeEntry( CONFIG_ENTRY_MINIMIZE_TO_TRAY, chkMinimizeToTray->isChecked() ); + config->writeEntry( CONFIG_ENTRY_SHOW_CONNECTION_ERRORS, chkShowConnectionErrors->isChecked() ); + config->writeEntry( CONFIG_ENTRY_KEEP_NEW, chkKeepNew->isChecked() ); + config->writeEntry( CONFIG_ENTRY_INITIAL_TIME, spbInitial->value() ); + config->writeEntry( CONFIG_ENTRY_INTERVAL_TIME, spbInterval->value() ); + config->writeEntry( CONFIG_ENTRY_TIMEOUT_TIME, spbTimeout->value() ); + + //write configuration to disk + config->sync(); +} + +void ConfigGeneral::slotChanged( ) +{ + KCModule::changed(); +} + +#include "configgeneral.moc" diff --git a/kshowmail/kcmconfigs/configgeneral.h b/kshowmail/kcmconfigs/configgeneral.h new file mode 100644 index 0000000..c61ef67 --- /dev/null +++ b/kshowmail/kcmconfigs/configgeneral.h @@ -0,0 +1,141 @@ +// +// C++ Interface: configgeneral +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef CONFIGGENERAL_H +#define CONFIGGENERAL_H + +//Qt headers +#include <qlayout.h> +#include <qgroupbox.h> +#include <qcheckbox.h> +#include <qspinbox.h> +#include <qtooltip.h> +#include <qlabel.h> + +//KDE headers +#include <kcmodule.h> +#include <kconfig.h> +#include <kgenericfactory.h> +#include <kapplication.h> + +//KShowmail headers +#include <../constants.h> + +/** + * @brief Part of the setup dialog (KShowMailApp::SetupDialog) to configure general things. + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +class ConfigGeneral : public KCModule +{ +Q_OBJECT + + public: + + /** + * Generic Constructor + */ + ConfigGeneral( QWidget *parent = 0, const char *name = 0, const QStringList &args = QStringList() ); + + /** + * Destructor + */ + ~ConfigGeneral(); + + /** + * Overloaded method of KCModule. + * Sets the user interface elements to reflect the current settings stored in the + * config file. + */ + virtual void load(); + + /** + * Overloaded method of KCModule. + * Sets the user interface elements to default values. + * This method is called when the user clicks the "Default" button. + */ + virtual void defaults(); + + /** + * Overloaded method of KCModule. + * Stores the config information as shown in the user interface in the + * config file. + * Is called when the user clicks "Apply" or "Ok". + */ + virtual void save(); + + private: + + /** + * Connector to the configuration file + */ + KConfig* config; + + /** + * Check box to select whether window closing must be confirmed. + */ + QCheckBox* chkConfirmClose; + + /** + * Check box to select whether deleting must be confirmed. + */ + QCheckBox* chkConfirmDelete; + + /** + * Check box to select whether the main window will be minimized at start. + */ + QCheckBox* chkStartMinimized; + + /** + * Check box to select whether the close button leave the application running in tray. + */ + QCheckBox* chkCloseToTray; + + /** + * Check box to select whether minimizes to the tray rather than to the taskbar. + */ + QCheckBox* chkMinimizeToTray; + + /** + * Check box to select whether connection errors will be shown. + */ + QCheckBox* chkShowConnectionErrors; + + /** + * Check box to select whether mails will be kept as new until termination. + */ + QCheckBox* chkKeepNew; + + /** + * Spin box to set the initial timer. + */ + QSpinBox* spbInitial; + + /** + * Spin box to set the interval timer. + */ + QSpinBox* spbInterval; + + /** + * Spin box to set the time out timer. + */ + QSpinBox* spbTimeout; + + public slots: + + /** + * Connected with the configuration items. + * Calls the slot changed() of KCModule to notify the dialog about the change. + */ + void slotChanged(); + +}; + +#endif diff --git a/kshowmail/kcmconfigs/configlog.cpp b/kshowmail/kcmconfigs/configlog.cpp new file mode 100644 index 0000000..e7eb51d --- /dev/null +++ b/kshowmail/kcmconfigs/configlog.cpp @@ -0,0 +1,255 @@ +// +// C++ Implementation: configlog +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "configlog.h" + +typedef KGenericFactory<ConfigLog, QWidget> ConfigLogFactory; + +K_EXPORT_COMPONENT_FACTORY( kcm_kshowmailconfiglog, ConfigLogFactory( + "kcm_kshowmailconfiglog" ) ); + +ConfigLog::ConfigLog( QWidget * parent, const char * name, const QStringList & args ) + : KCModule( ConfigLogFactory::instance(), parent, args ) +{ + //set the module name + if ( !name ) + setName( "configlog" ); + + //build GUI + //--------- + //main layout + QVBoxLayout* layMain = new QVBoxLayout( this, 0, 10 ); + + //widgets for deleted mails log + QVBoxLayout* layDelMails = new QVBoxLayout( layMain, 10, "layDelMails" ); + + chkLogDeletedMails = new QCheckBox( i18n( "Log mails deleted by filter" ), this, "chkLogDeletedMails" ); + layDelMails->addWidget( chkLogDeletedMails ); + QToolTip::add( chkLogDeletedMails, i18n( "Check to activate the log of mails deleted by filter." ) ); + connect( chkLogDeletedMails, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkLogDeletedMails, SIGNAL( toggled( bool ) ), this, SLOT( slotChangeItems() ) ); + + QVBoxLayout* layDelMailsConfig = new QVBoxLayout( layDelMails, 10, "layDelMailsConfig" ); + layDelMailsConfig->setMargin( 10 ); + + grpDelMailsRemove = new QButtonGroup( NULL, "grpDelMailsRemove" ); + connect( grpDelMailsRemove, SIGNAL( clicked( int ) ), this, SLOT( slotChanged() ) ); + connect( grpDelMailsRemove, SIGNAL( clicked( int ) ), this, SLOT( slotChangeItems() ) ); + btnDelMailsRemoveExit = new QRadioButton( i18n( "Remove log entries at exit" ), this, "btnDelMailsRemoveExit" ); + grpDelMailsRemove->insert( btnDelMailsRemoveExit, ID_BUTTON_REMOVE_AT_EXIT ); + layDelMailsConfig->addWidget( btnDelMailsRemoveExit ); + + QHBoxLayout* layDelMailsConfigDays = new QHBoxLayout( layDelMailsConfig, 0, "layDelMailsConfigDays" ); + layDelMailsConfigDays->setAlignment( Qt::AlignLeft ); + btnDelMailsRemoveDays = new QRadioButton( i18n( "Remove log entries after" ), this, "btnDelMailsRemoveDays" ); + grpDelMailsRemove->insert( btnDelMailsRemoveDays, ID_BUTTON_REMOVE_AFTER_DAYS ); + layDelMailsConfigDays->addWidget( btnDelMailsRemoveDays ); + spbDelDays = new QSpinBox( 1, 999999, 1, this, "spbDelDays" ); + connect( spbDelDays, SIGNAL( valueChanged( int ) ), this, SLOT( slotChanged() ) ); + connect( spbDelDays, SIGNAL( valueChanged( int ) ), this, SLOT( slotChangeItems() ) ); + spbDelDays->setSuffix( i18n( " Days" ) ); + spbDelDays->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Minimum ); + layDelMailsConfigDays->addWidget( spbDelDays ); + + + //widgets for moved mails log + QVBoxLayout* layMovMails = new QVBoxLayout( layMain, 10, "layMovMails" ); + + chkLogMovedMails = new QCheckBox( i18n( "Log mails moved by filter" ), this, "chkLogMovedMails" ); + layMovMails->addWidget( chkLogMovedMails ); + QToolTip::add( chkLogMovedMails, i18n( "Check to activate the log of mails moved by filter." ) ); + connect( chkLogMovedMails, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) ); + connect( chkLogMovedMails, SIGNAL( toggled( bool ) ), this, SLOT( slotChangeItems() ) ); + + QVBoxLayout* layMovMailsConfig = new QVBoxLayout( layMovMails, 10, "layMovMailsConfig" ); + layMovMailsConfig->setMargin( 10 ); + + grpMovMailsRemove = new QButtonGroup( NULL, "grpMovMailsRemove" ); + connect( grpMovMailsRemove, SIGNAL( clicked( int ) ), this, SLOT( slotChanged() ) ); + connect( grpMovMailsRemove, SIGNAL( clicked( int ) ), this, SLOT( slotChangeItems() ) ); + btnMovMailsRemoveExit = new QRadioButton( i18n( "Remove log entries at exit" ), this, "btnMovMailsRemoveExit" ); + grpMovMailsRemove->insert( btnMovMailsRemoveExit, ID_BUTTON_REMOVE_AT_EXIT ); + layMovMailsConfig->addWidget( btnMovMailsRemoveExit ); + + QHBoxLayout* layMovMailsConfigDays = new QHBoxLayout( layMovMailsConfig, 0, "layMovMailsConfigDays" ); + layMovMailsConfigDays->setAlignment( Qt::AlignLeft ); + btnMovMailsRemoveDays = new QRadioButton( i18n( "Remove log entries after" ), this, "btnMovMailsRemoveDays" ); + grpMovMailsRemove->insert( btnMovMailsRemoveDays, ID_BUTTON_REMOVE_AFTER_DAYS ); + layMovMailsConfigDays->addWidget( btnMovMailsRemoveDays ); + spbMovDays = new QSpinBox( 1, 999999, 1, this, "spbMovDays" ); + connect( spbMovDays, SIGNAL( valueChanged( int ) ), this, SLOT( slotChanged() ) ); + connect( spbMovDays, SIGNAL( valueChanged( int ) ), this, SLOT( slotChangeItems() ) ); + spbMovDays->setSuffix( i18n( " Days" ) ); + spbMovDays->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Minimum ); + layMovMailsConfigDays->addWidget( spbMovDays ); + + //the log of moved mails is not saved yet, maybe later... + btnMovMailsRemoveExit->setHidden( true ); + btnMovMailsRemoveDays->setHidden( true ); + spbMovDays->setHidden( true ); + + //get application config object (kshowmailrc) + config = KApplication::kApplication()->config(); + + //load configured values + load(); +} + +ConfigLog::~ConfigLog() +{ +} + +void ConfigLog::load() +{ + //set group + config->setGroup( CONFIG_GROUP_LOG ); + + //load settings + chkLogDeletedMails->setChecked( config->readBoolEntry( CONFIG_ENTRY_LOG_LOG_DELETED_MAILS, DEFAULT_LOG_LOG_DELETED_MAILS ) ); + chkLogMovedMails->setChecked( config->readBoolEntry( CONFIG_ENTRY_LOG_LOG_MOVED_MAILS, DEFAULT_LOG_LOG_MOVED_MAILS ) ); + + if( config->readEntry( CONFIG_ENTRY_LOG_REMOVE_DELETED_MAILS, DEFAULT_LOG_REMOVE_DELETED_MAILS ) == CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT ) + grpDelMailsRemove->setButton( ID_BUTTON_REMOVE_AT_EXIT ); + else if( config->readEntry( CONFIG_ENTRY_LOG_REMOVE_DELETED_MAILS, DEFAULT_LOG_REMOVE_DELETED_MAILS ) == CONFIG_VALUE_LOG_REMOVE_MAILS_AFTER_DAYS ) + grpDelMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS ); + else + if( DEFAULT_LOG_REMOVE_DELETED_MAILS == CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT ) + grpDelMailsRemove->setButton( ID_BUTTON_REMOVE_AT_EXIT ); + else + grpDelMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS ); + + if( config->readEntry( CONFIG_ENTRY_LOG_REMOVE_MOVED_MAILS, DEFAULT_LOG_REMOVE_MOVED_MAILS ) == CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT ) + grpMovMailsRemove->setButton( ID_BUTTON_REMOVE_AT_EXIT ); + else if( config->readEntry( CONFIG_ENTRY_LOG_REMOVE_MOVED_MAILS, DEFAULT_LOG_REMOVE_MOVED_MAILS ) == CONFIG_VALUE_LOG_REMOVE_MAILS_AFTER_DAYS ) + grpMovMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS ); + else + if( DEFAULT_LOG_REMOVE_MOVED_MAILS == CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT ) + grpMovMailsRemove->setButton( ID_BUTTON_REMOVE_AT_EXIT ); + else + grpMovMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS ); + + spbDelDays->setValue( config->readNumEntry( CONFIG_ENTRY_LOG_HOLDDAYS_DELETED_MAILS, DEFAULT_LOG_HOLDDAYS_DELETED_MAILS ) ); + spbMovDays->setValue( config->readNumEntry( CONFIG_ENTRY_LOG_HOLDDAYS_MOVED_MAILS, DEFAULT_LOG_HOLDDAYS_MOVED_MAILS ) ); + + //enable or disable Items + slotChangeItems(); +} + +void ConfigLog::defaults() +{ + if( DEFAULT_LOG_LOG_DELETED_MAILS ) + chkLogDeletedMails->setChecked( true ); + else + chkLogMovedMails->setChecked( false ); + + if( DEFAULT_LOG_LOG_MOVED_MAILS ) + chkLogMovedMails->setChecked( true ); + else + chkLogMovedMails->setChecked( false ); + + if( DEFAULT_LOG_REMOVE_DELETED_MAILS == CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT ) + grpDelMailsRemove->setButton( ID_BUTTON_REMOVE_AT_EXIT ); + else if( DEFAULT_LOG_REMOVE_DELETED_MAILS == CONFIG_VALUE_LOG_REMOVE_MAILS_AFTER_DAYS ) + grpDelMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS ); + else + grpDelMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS ); + + if( DEFAULT_LOG_REMOVE_MOVED_MAILS == CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT ) + grpMovMailsRemove->setButton( ID_BUTTON_REMOVE_AT_EXIT ); + else if( DEFAULT_LOG_REMOVE_MOVED_MAILS == CONFIG_VALUE_LOG_REMOVE_MAILS_AFTER_DAYS ) + grpMovMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS ); + else + grpMovMailsRemove->setButton( ID_BUTTON_REMOVE_AFTER_DAYS ); + + spbDelDays->setValue( DEFAULT_LOG_HOLDDAYS_DELETED_MAILS ); + spbMovDays->setValue( DEFAULT_LOG_HOLDDAYS_MOVED_MAILS ); + + //enable or disable Items + slotChangeItems(); + + slotChanged(); +} + +void ConfigLog::save() +{ + //set group + config->setGroup( CONFIG_GROUP_LOG ); + + //write settings + config->writeEntry( CONFIG_ENTRY_LOG_LOG_DELETED_MAILS, chkLogDeletedMails->isOn() ); + config->writeEntry( CONFIG_ENTRY_LOG_LOG_MOVED_MAILS, chkLogMovedMails->isOn() ); + + switch( grpDelMailsRemove->selectedId() ) + { + case ID_BUTTON_REMOVE_AT_EXIT : config->writeEntry( CONFIG_ENTRY_LOG_REMOVE_DELETED_MAILS, CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT ); break; + case ID_BUTTON_REMOVE_AFTER_DAYS : config->writeEntry( CONFIG_ENTRY_LOG_REMOVE_DELETED_MAILS, CONFIG_VALUE_LOG_REMOVE_MAILS_AFTER_DAYS ); break; + default : config->writeEntry( CONFIG_ENTRY_LOG_REMOVE_DELETED_MAILS, CONFIG_VALUE_LOG_REMOVE_MAILS_AFTER_DAYS ); break; + } + + switch( grpMovMailsRemove->selectedId() ) + { + case ID_BUTTON_REMOVE_AT_EXIT : config->writeEntry( CONFIG_ENTRY_LOG_REMOVE_MOVED_MAILS, CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT ); break; + case ID_BUTTON_REMOVE_AFTER_DAYS : config->writeEntry( CONFIG_ENTRY_LOG_REMOVE_MOVED_MAILS, CONFIG_VALUE_LOG_REMOVE_MAILS_AFTER_DAYS ); break; + default : config->writeEntry( CONFIG_ENTRY_LOG_REMOVE_MOVED_MAILS, CONFIG_VALUE_LOG_REMOVE_MAILS_AT_EXIT ); break; + } + + config->writeEntry( CONFIG_ENTRY_LOG_HOLDDAYS_DELETED_MAILS, spbDelDays->value() ); + config->writeEntry( CONFIG_ENTRY_LOG_HOLDDAYS_MOVED_MAILS, spbMovDays->value() ); +} + +void ConfigLog::slotChanged() +{ + KCModule::changed(); +} + +void ConfigLog::slotChangeItems() +{ + if( chkLogDeletedMails->isChecked() ) + { + btnDelMailsRemoveExit->setEnabled( true ); + btnDelMailsRemoveDays->setEnabled( true ); + spbDelDays->setEnabled( true ); + switch( grpDelMailsRemove->selectedId() ) + { + case ID_BUTTON_REMOVE_AFTER_DAYS : spbDelDays->setEnabled( true ); break; + case ID_BUTTON_REMOVE_AT_EXIT : spbDelDays->setEnabled( false ); break; + default : spbDelDays->setEnabled( true ); break; + } + } + else + { + btnDelMailsRemoveExit->setEnabled( false ); + btnDelMailsRemoveDays->setEnabled( false ); + spbDelDays->setEnabled( false ); + } + + if( chkLogMovedMails->isChecked() ) + { + btnMovMailsRemoveExit->setEnabled( true ); + btnMovMailsRemoveDays->setEnabled( true ); + spbMovDays->setEnabled( true ); + switch( grpMovMailsRemove->selectedId() ) + { + case ID_BUTTON_REMOVE_AFTER_DAYS : spbMovDays->setEnabled( true ); break; + case ID_BUTTON_REMOVE_AT_EXIT : spbMovDays->setEnabled( false ); break; + default : spbMovDays->setEnabled( true ); break; + } + } + else + { + btnMovMailsRemoveExit->setEnabled( false ); + btnMovMailsRemoveDays->setEnabled( false ); + spbMovDays->setEnabled( false ); + } +} + + +#include "configlog.moc" diff --git a/kshowmail/kcmconfigs/configlog.h b/kshowmail/kcmconfigs/configlog.h new file mode 100644 index 0000000..84e6fd4 --- /dev/null +++ b/kshowmail/kcmconfigs/configlog.h @@ -0,0 +1,152 @@ +// +// C++ Interface: configlog +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef CONFIGLOG_H +#define CONFIGLOG_H + +//button IDs +#define ID_BUTTON_REMOVE_AT_EXIT 1 +#define ID_BUTTON_REMOVE_AFTER_DAYS 2 + +//qt headers +#include <qlayout.h> +#include <qgroupbox.h> +#include <qtooltip.h> +#include <qcheckbox.h> +#include <qradiobutton.h> +#include <qbuttongroup.h> +#include <qspinbox.h> + +//KDE headers +#include <kcmodule.h> +#include <kconfig.h> +#include <kgenericfactory.h> +#include <kapplication.h> + +//Kshowmail headers +#include "../constants.h" + + +/** + * @brief Part of the setup dialog (KShowMailApp::SetupDialog) to configure the log. + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +class ConfigLog : public KCModule +{ +Q_OBJECT + + public: + + /** + * Generic constructor + */ + ConfigLog( QWidget* parent = 0, const char* name = 0, const QStringList &args = QStringList() ); + + /** + * Destructor + */ + ~ConfigLog(); + + /** + * Overloaded method of KCModule. + * Sets the user interface elements to reflect the current settings stored in the + * config file. + */ + virtual void load(); + + /** + * Overloaded method of KCModule. + * Sets the user interface elements to default values. + * This method is called when the user clicks the "Default" button. + */ + virtual void defaults(); + + /** + * Overloaded method of KCModule. + * Stores the config information as shown in the user interface in the + * config file. + * Is called when the user clicks "Apply" or "Ok". + */ + virtual void save(); + + private: + + /** + * Connector to the configuration file + */ + KConfig* config; + + /** + * Checkbox to activate log of deleted mails + */ + QCheckBox* chkLogDeletedMails; + + /** + * Checkbox to activate log of moved mails + */ + QCheckBox* chkLogMovedMails; + + /** + * Combines the radio buttons to select the kind of removing log entries of deleted mails + */ + QButtonGroup* grpDelMailsRemove; + + /** + * Combines the radio buttons to select the kind of removing log entries of moved mails + */ + QButtonGroup* grpMovMailsRemove; + + /** + * Spinbox to select the number of days to remove. + */ + QSpinBox* spbDelDays; + + /** + * Spinbox to select the number of days to remove. + */ + QSpinBox* spbMovDays; + + /** + * Radio button to select the removing of entries about deleted mails at application exit. + */ + QRadioButton* btnDelMailsRemoveExit; + + /** + * Radio button to select the removing of entries about deleted mails after some days. + */ + QRadioButton* btnDelMailsRemoveDays; + + /** + * Radio button to select the removing of entries about moved mails at application exit. + */ + QRadioButton* btnMovMailsRemoveExit; + + /** + * Radio button to select the removing of entries about moved mails after some days. + */ + QRadioButton* btnMovMailsRemoveDays; + + private slots: + + /** + * Connected with the configuration items. + * Calls the slot changed() of KCModule to notify the dialog about the change. + */ + void slotChanged(); + + /** + * Connected with the checkboxes and radiobuttons. + * Enables or disables the dialog items. + */ + void slotChangeItems(); +}; + +#endif diff --git a/kshowmail/kcmconfigs/configspamcheck.cpp b/kshowmail/kcmconfigs/configspamcheck.cpp new file mode 100644 index 0000000..44f7ef7 --- /dev/null +++ b/kshowmail/kcmconfigs/configspamcheck.cpp @@ -0,0 +1,236 @@ +// +// C++ Implementation: configspamcheck +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2008 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "configspamcheck.h" + + +typedef KGenericFactory<ConfigSpamcheck, QWidget> ConfigSpamcheckFactory; + +K_EXPORT_COMPONENT_FACTORY( kcm_kshowmailconfigspamcheck, ConfigSpamcheckFactory( + "kcm_kshowmailconfigspamcheck" ) ); + + +ConfigSpamcheck::ConfigSpamcheck(QWidget * parent, const char * name, const QStringList & args) + : KCModule( ConfigSpamcheckFactory::instance(), parent, args ) +{ + //set the module name + if ( !name ) + setName( "configfilter" ); + + //build GUI + //--------- + + //main layout + QVBoxLayout* layMain = new QVBoxLayout( this, 0, 10 ); + + //description + QLabel* lblDescription = new QLabel( this, "lblDescription" ); + lblDescription->setAlignment( Qt::WordBreak ); + lblDescription->setText( QString( "<i>%1</i>" ).arg( i18n( "KShowmail uses SpamAssassin to check the mails for spam. You have to install, configure and start the SpamAssassin daemon, before you can use this service." ) ) ); + lblDescription->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum ); + layMain->addWidget( lblDescription ); + + //Test button + btnTest = new KPushButton( KStdGuiItem::test(), this, "btnTest" ); + btnTest->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ); + layMain->addWidget( btnTest ); + connect( btnTest, SIGNAL( clicked() ), this, SLOT( slotTestSpamAssassin() ) ); + + //action + gboxAction = new QGroupBox( 0, Qt::Horizontal, i18n( "Action for Spam" ), this, "gboxAction" ); + QHBoxLayout* layAction = new QHBoxLayout( gboxAction->layout(), 10 ); + layMain->addWidget( gboxAction ); + + cmbAction = new KComboBox( gboxAction, "cmbAction" ); + layAction->addWidget( cmbAction ); + QToolTip::add( cmbAction, i18n( "Choose the action for spam mails." ) ); + connect( cmbAction, SIGNAL( activated( int ) ), this, SLOT( slotActionChanged( int ) ) ); + connect( cmbAction, SIGNAL( activated( int ) ), this, SLOT( slotChanged() ) ); + + //insert items + cmbAction->insertItem( i18n( "Delete" ), ID_SPAM_ACTION_BUTTONS_DELETE ); + cmbAction->insertItem( i18n( "Mark" ), ID_SPAM_ACTION_BUTTONS_MARK ); + cmbAction->insertItem( i18n( "Move" ), ID_SPAM_ACTION_BUTTONS_MOVE ); + + //create edit line to defined the mailbox for move + txtMailbox = new KLineEdit( gboxAction ); + layAction->addWidget( txtMailbox ); + connect( txtMailbox, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotChanged() ) ); + + //create wizard button to configure mailbox + btnMailboxWizard= new KPushButton( KGuiItem( QString::null, "wizard" ), gboxAction ); + layAction->addWidget( btnMailboxWizard ); + QToolTip::add( btnMailboxWizard, i18n( "Choose the mailbox" ) ); + connect( btnMailboxWizard, SIGNAL( clicked() ), this, SLOT( slotOpenMailBoxWizard() ) ); + + //set defaults + switch( DEFAULT_SPAMCHECK_ACTION ) + { + case CONFIG_VALUE_SPAMCHECK_ACTION_DELETE : cmbAction->setCurrentItem( ID_SPAM_ACTION_BUTTONS_DELETE ); break; + case CONFIG_VALUE_SPAMCHECK_ACTION_MARK : cmbAction->setCurrentItem( ID_SPAM_ACTION_BUTTONS_MARK ); break; + case CONFIG_VALUE_SPAMCHECK_ACTION_MOVE : cmbAction->setCurrentItem( ID_SPAM_ACTION_BUTTONS_MOVE ); break; + } + + txtMailbox->setText( DEFAULT_SPAMCHECK_ACTION_MOVE_MAILBOX ); + + //enable or disable widgets + slotActionChanged( cmbAction->currentItem() ); + gboxAction->setEnabled( isSpamAssassinRunning() ); + + //get application config object (kshowmailrc) + config = KApplication::kApplication()->config(); + + //load configured values + load(); +} + +ConfigSpamcheck::~ConfigSpamcheck() +{ +} + +void ConfigSpamcheck::load() +{ + config->setGroup( CONFIG_GROUP_SPAMCHECK ); + + //load action + switch( config->readNumEntry( CONFIG_ENTRY_SPAMCHECK_ACTION, DEFAULT_SPAMCHECK_ACTION ) ) + { + case CONFIG_VALUE_SPAMCHECK_ACTION_DELETE : cmbAction->setCurrentItem( ID_SPAM_ACTION_BUTTONS_DELETE ); break; + case CONFIG_VALUE_SPAMCHECK_ACTION_MARK : cmbAction->setCurrentItem( ID_SPAM_ACTION_BUTTONS_MARK ); break; + case CONFIG_VALUE_SPAMCHECK_ACTION_MOVE : cmbAction->setCurrentItem( ID_SPAM_ACTION_BUTTONS_MOVE ); break; + } + + //get mailbox name + if( config->readNumEntry( CONFIG_ENTRY_SPAMCHECK_ACTION, DEFAULT_SPAMCHECK_ACTION ) == CONFIG_VALUE_SPAMCHECK_ACTION_MOVE ) + txtMailbox->setText( config->readEntry( CONFIG_ENTRY_SPAMCHECK_MOVE_MAILBOX, DEFAULT_SPAMCHECK_ACTION_MOVE_MAILBOX ) ); + else + txtMailbox->clear(); + + //enable or disable widgets for other action + slotActionChanged( cmbAction->currentItem() ); +} + +void ConfigSpamcheck::defaults() +{ + switch( DEFAULT_SPAMCHECK_ACTION ) + { + case CONFIG_VALUE_SPAMCHECK_ACTION_DELETE : cmbAction->setCurrentItem( ID_SPAM_ACTION_BUTTONS_DELETE ); break; + case CONFIG_VALUE_SPAMCHECK_ACTION_MARK : cmbAction->setCurrentItem( ID_SPAM_ACTION_BUTTONS_MARK ); break; + case CONFIG_VALUE_SPAMCHECK_ACTION_MOVE : cmbAction->setCurrentItem( ID_SPAM_ACTION_BUTTONS_MOVE ); break; + } + + if( DEFAULT_SPAMCHECK_ACTION == CONFIG_VALUE_SPAMCHECK_ACTION_MOVE ) + txtMailbox->setText( QString( DEFAULT_SPAMCHECK_ACTION_MOVE_MAILBOX ) ); + else + txtMailbox->clear(); + + //enable or disable widgets for other action + slotActionChanged( cmbAction->currentItem() ); + + slotChanged(); +} + +void ConfigSpamcheck::save() +{ + config->setGroup( CONFIG_GROUP_SPAMCHECK ); + + //save action + switch( cmbAction->currentItem() ) + { + case ID_SPAM_ACTION_BUTTONS_DELETE : config->writeEntry( CONFIG_ENTRY_SPAMCHECK_ACTION, CONFIG_VALUE_SPAMCHECK_ACTION_DELETE ); break; + case ID_SPAM_ACTION_BUTTONS_MARK : config->writeEntry( CONFIG_ENTRY_SPAMCHECK_ACTION, CONFIG_VALUE_SPAMCHECK_ACTION_MARK ); break; + case ID_SPAM_ACTION_BUTTONS_MOVE : config->writeEntry( CONFIG_ENTRY_SPAMCHECK_ACTION, CONFIG_VALUE_SPAMCHECK_ACTION_MOVE ); break; + default : config->writeEntry( CONFIG_ENTRY_SPAMCHECK_ACTION, DEFAULT_SPAMCHECK_ACTION ); break; + } + + //save mailbox name + if( cmbAction->currentItem() == ID_SPAM_ACTION_BUTTONS_MOVE ) + { + config->writeEntry( CONFIG_ENTRY_SPAMCHECK_MOVE_MAILBOX, txtMailbox->text() ); + } + else + { + config->deleteEntry( CONFIG_ENTRY_SPAMCHECK_MOVE_MAILBOX ); + } + + config->sync(); +} + +void ConfigSpamcheck::slotChanged() +{ + KCModule::changed(); +} + +void ConfigSpamcheck::slotActionChanged( int index ) +{ + switch( index ) + { + case ID_SPAM_ACTION_BUTTONS_MOVE : txtMailbox->setEnabled( true ); + if( txtMailbox->text() == "" ) + txtMailbox->setText( DEFAULT_FILTER_ACTION_MOVE_MAILBOX ); + btnMailboxWizard->setHidden( false ); + break; + default : txtMailbox->setEnabled( false ); + btnMailboxWizard->setHidden( true ); + break; + } +} + +void ConfigSpamcheck::slotOpenMailBoxWizard( ) +{ + MailBoxWizard wizard( this, "malboxwizard" ); + wizard.setCaption( i18n( "Mailbox Select" ) ); + int res = wizard.exec(); + + if( res == QDialog::Accepted ) + txtMailbox->setText( wizard.getPath() ); +} + +bool ConfigSpamcheck::isSpamAssassinRunning( ) const +{ + FILE *read_fp; + char buffer[ BUFSIZ + 1 ]; + int chars_read; + bool found = false; + + memset( buffer, '\0', sizeof( buffer ) ); + read_fp = popen( "ps -eo comm", "r" ); + if( read_fp != NULL ) + { + chars_read = fread( buffer, sizeof( char ), BUFSIZ, read_fp ); + while( chars_read > 0 ) + { + buffer[ chars_read - 1 ] = '\0'; + QString output( buffer ); + found = output.contains( NAME_SPAMASSASSIN_DAEMON ) > 0; + chars_read = fread( buffer, sizeof( char ), BUFSIZ, read_fp ); + } + pclose( read_fp ); + } + + return found; +} + +void ConfigSpamcheck::slotTestSpamAssassin( ) +{ + if( isSpamAssassinRunning() ) + { + KMessageBox::information( this, i18n( "SpamAssassin is running." ), i18n( "Check for SpamAssassin" ) ); + gboxAction->setEnabled( true ); + } + else + { + KMessageBox::information( this, i18n( "SpamAssassin is not running." ), i18n( "Check for SpamAssassin" ) ); + gboxAction->setEnabled( false ); + } +} + +#include "configspamcheck.moc" diff --git a/kshowmail/kcmconfigs/configspamcheck.h b/kshowmail/kcmconfigs/configspamcheck.h new file mode 100644 index 0000000..d2af35c --- /dev/null +++ b/kshowmail/kcmconfigs/configspamcheck.h @@ -0,0 +1,161 @@ +// +// C++ Interface: configspamcheck +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2008 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef CONFIGSPAMCHECK_H +#define CONFIGSPAMCHECK_H + +//C-headers +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +//Qt headers +#include <qlayout.h> +#include <qlabel.h> +#include <qgroupbox.h> +#include <qtooltip.h> + +//KDE headers +#include <kcmodule.h> +#include <kconfig.h> +#include <kgenericfactory.h> +#include <kapplication.h> +#include <kpushbutton.h> +#include <kstdguiitem.h> +#include <kcombobox.h> +#include <klineedit.h> +#include <kmessagebox.h> + +//Kshowmail headers +#include "../constants.h" +#include "mailboxwizard.h" + +//radio button IDs +#define ID_SPAM_ACTION_BUTTONS_DELETE 0 +#define ID_SPAM_ACTION_BUTTONS_MARK 1 +#define ID_SPAM_ACTION_BUTTONS_MOVE 2 + + +/** + * @brief Part of the setup dialog (KShowMailApp::SetupDialog) to configure the spam check. + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +class ConfigSpamcheck : public KCModule +{ + +Q_OBJECT + + + public: + /** + * Generic constructor + */ + ConfigSpamcheck( QWidget* parent = 0, const char* name = 0, const QStringList &args = QStringList() ); + + /** + * Destructor + */ + ~ConfigSpamcheck(); + + /** + * Overloaded method of KCModule. + * Sets the user interface elements to reflect the current settings stored in the + * config file. + */ + virtual void load(); + + /** + * Overloaded method of KCModule. + * Sets the user interface elements to default values. + * This method is called when the user clicks the "Default" button. + */ + virtual void defaults(); + + /** + * Overloaded method of KCModule. + * Stores the config information as shown in the user interface in the + * config file. + * Is called when the user clicks "Apply" or "Ok". + */ + virtual void save(); + + private: + + /** + * Connector to the configuration file + */ + KConfig* config; + + /** + * Button to test for a running SpamAssassin + */ + KPushButton* btnTest; + + /** + * Combobox to select the action for spam. + */ + KComboBox* cmbAction; + + /** + * If selected, the spam mails will be moved to the mailbox which is written in this edit line. + */ + KLineEdit* txtMailbox; + + /** + * This button opens a wizard which will help to get the right mailbox + */ + KPushButton* btnMailboxWizard; + + /** + * Contains the widgets of action configuration. + */ + QGroupBox* gboxAction; + + private slots: + + /** + * Connected with the configuration items. + * Calls the slot changed() of KCModule to notify the dialog about the change. + */ + void slotChanged(); + + /** + * Connected with combobox cmbAction. + * Enables or disables additional widgets for action configuration. + * @param index position (index) of the selected action + */ + void slotActionChanged( int index ); + + /** + * Connected with button btnMailboxWizard. + * Opens a wizard to configure the mailbox + */ + void slotOpenMailBoxWizard(); + + /** + * Connected with btnTest. + * Tests whether SpamAssassin is running and shows a message box containing the result. + * Enables or disables the action widgets. + */ + void slotTestSpamAssassin(); + + protected: + + /** + * Looks for a running spamd daemon of SpamAssassin. + * @return TRUE - SpamAssassin is running + */ + bool isSpamAssassinRunning() const; + +}; + +#endif diff --git a/kshowmail/kcmconfigs/encryption.cpp b/kshowmail/kcmconfigs/encryption.cpp new file mode 100644 index 0000000..dd3bcec --- /dev/null +++ b/kshowmail/kcmconfigs/encryption.cpp @@ -0,0 +1,85 @@ +// +// C++ Implementation: encryption +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "encryption.h" + +//used in crypt() and decrypt() +static const char scramble1 [50] = "C6FDC7A1EDFBB6FEE3DBF5BEBAEFDDF7ABC6FDC7A1EDFBB6"; +static const char hexstr [17] = "0123456789ABCDEF"; + +int Encryption::hexbyt( const char c ) +{ + if( c >= '0' && c <= '9' ) + return c - '0'; + else + return c - 'A' + 10; +} + +const QString Encryption::crypt( const KURL& url ) +{ + char result[50]; + char scramble2[50]; + QString hexresult; + + memset (result, 0, 50); + memset (scramble2, 0, 50); + int pos = url.pass().length () + 1; + unsigned int free = 50 - pos; + + if( url.user().length() <= free ) + { + strcpy( &scramble2[pos], url.user() ); + pos += url.user().length(); + free -= url.user().length(); + } + else + { + memcpy( &scramble2[pos], url.user().latin1(), free ); + free = 0; + } + + if( url.host().length() <= free ) + { + strcpy( &scramble2[pos], url.host() ); + pos += url.host().length(); + free -= url.host().length(); + } + else + { + memcpy( &scramble2[pos], url.host().latin1(), free ); + free = 0; + } + + memcpy( result, url.pass().latin1(), url.pass().length() ); + for (int i = 0; i <= 31; i++) + { + result[i] = (char)( result[i] ^ ( scramble1[i] ^ scramble2[i] ) ); + hexresult += hexstr[ result[i] / 16 ]; + hexresult += hexstr[ result[i] % 16 ]; + } + + return hexresult; +} + +const QString Encryption::decrypt( const QString& pass ) +{ + char result[50]; + + memset( result, 0, 50 ); + int i; + for( i = 0; i <= 31; i++ ) + { + result[i] = (char)hexbyt( pass[ i * 2 ] ) * 16 + hexbyt( pass[ i * 2 + 1 ] ); + result[i] = (char)( result[i] ^ scramble1[i] ); + } + + return result; +} diff --git a/kshowmail/kcmconfigs/encryption.h b/kshowmail/kcmconfigs/encryption.h new file mode 100644 index 0000000..376cc26 --- /dev/null +++ b/kshowmail/kcmconfigs/encryption.h @@ -0,0 +1,46 @@ +// +// C++ Interface: encryption +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +//Qt headers +#include <qstring.h> + +//KDE headers +#include <kurl.h> + +/** + * @brief Provides functions to crypt and decrypt a password. + */ +namespace Encryption +{ + /** + * Transforms the given hex numeric character to integer. + * For example: a given '2' will transformed to 2; 'B' to 12. + * @param c character to transform [0..9, 'A'..'F']; no lower case letters + * @return integer value of the given character + */ + int hexbyt( const char c ); + + /** + * Encrypts the the password in the given url and returns it. + * The encryption algorithm uses host and user name to crypt the password. + * @param url the url with password, host and user name + * @return encrypted password + */ + const QString crypt( const KURL& url ); + + /** + * Decrypts the given encrypted password. + * @param pass encrypted password + * @return decrypted password + */ + const QString decrypt( const QString& pass ); +} diff --git a/kshowmail/kcmconfigs/filtercriteriawidget.cpp b/kshowmail/kcmconfigs/filtercriteriawidget.cpp new file mode 100644 index 0000000..c7ea8c5 --- /dev/null +++ b/kshowmail/kcmconfigs/filtercriteriawidget.cpp @@ -0,0 +1,338 @@ +// +// C++ Implementation: filtercriteriawidget +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "filtercriteriawidget.h" + +FilterCriteriaWidget::FilterCriteriaWidget( QWidget *parent, const char *name ) + : QWidget( parent, name ) +{ + //this is the main layout + QVBoxLayout* layMain = new QVBoxLayout( this, 0, KDialog::spacingHint(), "layMain" ); + + //and now the layouts of the first and second line + QHBoxLayout* layLine1 = new QHBoxLayout( layMain, KDialog::spacingHint(), "layLine1" ); + QHBoxLayout* layLine2 = new QHBoxLayout( layMain, KDialog::spacingHint(), "layLine2" ); + + //Source Select + cmbSource = new KComboBox( this, "cmbSource" ); + cmbSource->insertItem( i18n( "From" ), ID_COMBO_SOURCE_FROM ); + cmbSource->insertItem( i18n( "To" ), ID_COMBO_SOURCE_TO ); + cmbSource->insertItem( i18n( "Size (Bytes)" ), ID_COMBO_SOURCE_SIZE ); + cmbSource->insertItem( i18n( "Subject" ), ID_COMBO_SOURCE_SUBJECT ); + cmbSource->insertItem( i18n( "Header" ), ID_COMBO_SOURCE_HEADER ); + cmbSource->insertItem( i18n( "Account" ), ID_COMBO_SOURCE_ACCOUNT ); + layLine1->addWidget( cmbSource ); + connect( cmbSource, SIGNAL( activated( int ) ), this, SLOT( slotSetWidgets() ) ); + + switch( DEFAULT_FILTER_CRITERIA_SOURCE ) + { + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_FROM : cmbSource->setCurrentItem( ID_COMBO_SOURCE_FROM ); break; + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_TO : cmbSource->setCurrentItem( ID_COMBO_SOURCE_TO ); break; + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SIZE : cmbSource->setCurrentItem( ID_COMBO_SOURCE_SIZE ); break; + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SUBJECT : cmbSource->setCurrentItem( ID_COMBO_SOURCE_SUBJECT ); break; + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_HEADER : cmbSource->setCurrentItem( ID_COMBO_SOURCE_HEADER ); break; + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_ACCOUNT : cmbSource->setCurrentItem( ID_COMBO_SOURCE_ACCOUNT ); break; + default : cmbSource->setCurrentItem( ID_COMBO_SOURCE_FROM ); break; + } + + //Comboboxes to select the condition between source and value + cmbConditionText = new KComboBox( this, "cmbConditionText" ); + cmbConditionText->insertItem( i18n( "contains" ), ID_COMBO_COND_TEXT_CONTAINS ); + cmbConditionText->insertItem( i18n( "does not contain" ), ID_COMBO_COND_TEXT_NOT_CONTAINS ); + cmbConditionText->insertItem( i18n( "equals" ), ID_COMBO_COND_TEXT_EQUALS ); + cmbConditionText->insertItem( i18n( "does not equal" ), ID_COMBO_COND_TEXT_NOT_EQUALS ); + cmbConditionText->insertItem( i18n( "matches regular expression" ), ID_COMBO_COND_TEXT_REGEXPR ); + cmbConditionText->insertItem( i18n( "does not match reg. expr." ), ID_COMBO_COND_TEXT_NOT_REGEXPR ); + layLine1->addWidget( cmbConditionText ); + connect( cmbConditionText, SIGNAL( activated( int ) ), this, SLOT( slotSetWidgets() ) ); + + switch( DEFAULT_FILTER_CRITERIA_COND_TEXT ) + { + case CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_CONTAINS : cmbConditionText->setCurrentItem( ID_COMBO_COND_TEXT_CONTAINS );break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_NOT_CONTAINS : cmbConditionText->setCurrentItem( ID_COMBO_COND_TEXT_NOT_CONTAINS );break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_EQUALS : cmbConditionText->setCurrentItem( ID_COMBO_COND_TEXT_EQUALS );break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_NOT_EQUALS : cmbConditionText->setCurrentItem( ID_COMBO_COND_TEXT_NOT_EQUALS );break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_REGEXPR : cmbConditionText->setCurrentItem( ID_COMBO_COND_TEXT_REGEXPR );break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_NOT_REGEXPR : cmbConditionText->setCurrentItem( ID_COMBO_COND_TEXT_NOT_REGEXPR );break; + default : cmbConditionText->setCurrentItem( ID_COMBO_COND_TEXT_CONTAINS ); break; + } + + cmbConditionNum = new KComboBox( this, "cmbConditionNum" ); + cmbConditionNum->insertItem( i18n( "is equal to" ), ID_COMBO_COND_NUM_EQUAL ); + cmbConditionNum->insertItem( i18n( "is not equal to" ), ID_COMBO_COND_NUM_NOT_EQUAL ); + cmbConditionNum->insertItem( i18n( "is greater than" ), ID_COMBO_COND_NUM_GREATER ); + cmbConditionNum->insertItem( i18n( "is greater than or equal to" ), ID_COMBO_COND_NUM_GREATER_EQUAL ); + cmbConditionNum->insertItem( i18n( "is less than" ), ID_COMBO_COND_NUM_LESS ); + cmbConditionNum->insertItem( i18n( "is less than or equal to" ), ID_COMBO_COND_NUM_LESS_EQUAL ); + layLine1->addWidget( cmbConditionNum ); + + switch( DEFAULT_FILTER_CRITERIA_COND_NUM ) + { + case CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_EQUAL : cmbConditionNum->setCurrentItem( ID_COMBO_COND_NUM_EQUAL ); break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_NOT_EQUAL : cmbConditionNum->setCurrentItem( ID_COMBO_COND_NUM_NOT_EQUAL ); break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_GREATER : cmbConditionNum->setCurrentItem( ID_COMBO_COND_NUM_GREATER ); break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_GREATER_EQUAL : cmbConditionNum->setCurrentItem( ID_COMBO_COND_NUM_GREATER_EQUAL ); break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_LESS : cmbConditionNum->setCurrentItem( ID_COMBO_COND_NUM_LESS ); break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_LESS_EQUAL : cmbConditionNum->setCurrentItem( ID_COMBO_COND_NUM_LESS_EQUAL ); break; + default : cmbConditionNum->setCurrentItem( ID_COMBO_COND_NUM_EQUAL ); break; + } + + //edit line and spin box which hold the comparation values + txtCompValueText = new KLineEdit( this, "txtCompValueText" ); + txtCompValueText->setMinimumWidth( WIDTH_FILTER_TEXT_VALUE_LINE ); + layLine1->addWidget( txtCompValueText ); + + spbCompValueNum = new KIntNumInput( DEFAULT_FILTER_CRITERIA_SIZE, this, 10, "spbCompValueNum" ); + spbCompValueNum->setMinValue( 0 ); + spbCompValueNum->setSuffix( " Bytes" ); + layLine1->addWidget( spbCompValueNum ); + + //Button to open the regular expression editor + btnOpenRegExpEditor = new KPushButton( KGuiItem( "", "edit", "Edit Regualar Expression" ), this, "btnOpenRegExpEditor" ); + layLine1->addWidget( btnOpenRegExpEditor ); + connect( btnOpenRegExpEditor, SIGNAL( clicked() ), this, SLOT( slotOpenRegExpEditor() ) ); + + //check whether the KRegExpEditor is available + kRegExpEditorAvailable = !KTrader::self()->query( "KRegExpEditor/KRegExpEditor" ).isEmpty(); + + //checkbox to select case sensitve + chkCaseSensitive = new QCheckBox( i18n( "Case sensitive" ), this, "chkCaseSensitive" ); + chkCaseSensitive->setChecked( DEFAULT_FILTER_CRITERIA_CASE_SENSITIVE ); //set default + layLine2->addWidget( chkCaseSensitive ); + + //separator to the next criteria widget + layMain->addWidget( new KSeparator( this ) ); + + //set widgets dependent on criteria source + slotSetWidgets(); +} + + +FilterCriteriaWidget::~FilterCriteriaWidget() +{ +} + +void FilterCriteriaWidget::slotSetWidgets( ) +{ + switch( cmbSource->currentItem() ) + { + case ID_COMBO_SOURCE_FROM : cmbConditionNum->setHidden( true ); + spbCompValueNum->setHidden( true ); + cmbConditionText->setHidden( false ); + txtCompValueText->setHidden( false ); + chkCaseSensitive->setHidden( false ); + break; + case ID_COMBO_SOURCE_TO : cmbConditionNum->setHidden( true ); + spbCompValueNum->setHidden( true ); + cmbConditionText->setHidden( false ); + txtCompValueText->setHidden( false ); + chkCaseSensitive->setHidden( false ); + break; + case ID_COMBO_SOURCE_SIZE : cmbConditionNum->setHidden( false ); + spbCompValueNum->setHidden( false ); + cmbConditionText->setHidden( true ); + txtCompValueText->setHidden( true ); + chkCaseSensitive->setHidden( true ); + break; + case ID_COMBO_SOURCE_SUBJECT : cmbConditionNum->setHidden( true ); + spbCompValueNum->setHidden( true ); + cmbConditionText->setHidden( false ); + txtCompValueText->setHidden( false ); + chkCaseSensitive->setHidden( false ); + break; + case ID_COMBO_SOURCE_HEADER : cmbConditionNum->setHidden( true ); + spbCompValueNum->setHidden( true ); + cmbConditionText->setHidden( false ); + txtCompValueText->setHidden( false ); + chkCaseSensitive->setHidden( false ); + break; + case ID_COMBO_SOURCE_ACCOUNT : cmbConditionNum->setHidden( true ); + spbCompValueNum->setHidden( true ); + cmbConditionText->setHidden( false ); + txtCompValueText->setHidden( false ); + chkCaseSensitive->setHidden( false ); + break; + default: cmbConditionNum->setHidden( true ); + spbCompValueNum->setHidden( true ); + cmbConditionText->setHidden( false ); + txtCompValueText->setHidden( false ); + chkCaseSensitive->setHidden( false ); + break; + } + + //show or hide widgets of regular expressions + if( !cmbConditionText->isHidden() && ( cmbConditionText->currentItem() == ID_COMBO_COND_TEXT_REGEXPR || cmbConditionText->currentItem() == ID_COMBO_COND_TEXT_NOT_REGEXPR ) ) + { + if( kRegExpEditorAvailable ) + btnOpenRegExpEditor->setHidden( false ); + + //we don't need case sensitve for regular expressions + chkCaseSensitive->setHidden( true ); + } + else + { + btnOpenRegExpEditor->setHidden( true ); + } +} + +void FilterCriteriaWidget::slotOpenRegExpEditor( ) +{ + QDialog* editorDialog = KParts::ComponentFactory::createInstanceFromQuery<QDialog>( "KRegExpEditor/KRegExpEditor" ); + + if( editorDialog != NULL ) + { + //kdeutils was installed, so the dialog was found fetch the editor interface + KRegExpEditorInterface* editor = static_cast<KRegExpEditorInterface*>( editorDialog->qt_cast( "KRegExpEditorInterface" ) ); + if( editor == NULL ) + { + KMessageBox::error( this, i18n( "The Regular Expression Editor could not be initilized." ) ); + return; + } + + //use the editor. + editor->setRegExp( txtCompValueText->text() ); + + //exec the dialog + if( editorDialog->exec() == QDialog::Accepted ) + txtCompValueText->setText( editor->regExp() ); + + //delete dialog + delete editorDialog; + } + else + KMessageBox::error( this, i18n( "The Regular Expression Editor is not available." ) ); + +} + +void FilterCriteriaWidget::setNumCriteria( int source, int condition, uint value ) +{ + //set source + switch( source ) + { + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SIZE : cmbSource->setCurrentItem( ID_COMBO_SOURCE_SIZE ); break; + default : kdError() << "FilterCriteriaWidget::setNumCriteria: invalid source parameter." << endl; + return; + } + + //show or hide widgets + slotSetWidgets(); + + //set condition + switch( condition ) + { + case CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_EQUAL : cmbConditionNum->setCurrentItem( ID_COMBO_COND_NUM_EQUAL ); break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_NOT_EQUAL : cmbConditionNum->setCurrentItem( ID_COMBO_COND_NUM_NOT_EQUAL ); break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_GREATER : cmbConditionNum->setCurrentItem( ID_COMBO_COND_NUM_GREATER ); break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_GREATER_EQUAL : cmbConditionNum->setCurrentItem( ID_COMBO_COND_NUM_GREATER_EQUAL ); break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_LESS : cmbConditionNum->setCurrentItem( ID_COMBO_COND_NUM_LESS ); break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_LESS_EQUAL : cmbConditionNum->setCurrentItem( ID_COMBO_COND_NUM_LESS_EQUAL ); break; + default : cmbConditionNum->setCurrentItem( ID_COMBO_COND_NUM_EQUAL ); break; + } + + //set comparison value + spbCompValueNum->setValue( value ); + + //show or hide widgets + slotSetWidgets(); +} + +void FilterCriteriaWidget::setTextCriteria( int source, int condition, QString value, bool cs ) +{ + //set source + switch( source ) + { + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_FROM : cmbSource->setCurrentItem( ID_COMBO_SOURCE_FROM ); break; + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_TO : cmbSource->setCurrentItem( ID_COMBO_SOURCE_TO ); break; + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SUBJECT : cmbSource->setCurrentItem( ID_COMBO_SOURCE_SUBJECT ); break; + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_HEADER : cmbSource->setCurrentItem( ID_COMBO_SOURCE_HEADER ); break; + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_ACCOUNT : cmbSource->setCurrentItem( ID_COMBO_SOURCE_ACCOUNT ); break; + default : kdError() << "FilterCriteriaWidget::setTextCriteria: invalid source parameter." << endl; + return; + } + + //set condition + switch( condition ) + { + case CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_CONTAINS : cmbConditionText->setCurrentItem( ID_COMBO_COND_TEXT_CONTAINS );break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_NOT_CONTAINS : cmbConditionText->setCurrentItem( ID_COMBO_COND_TEXT_NOT_CONTAINS );break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_EQUALS : cmbConditionText->setCurrentItem( ID_COMBO_COND_TEXT_EQUALS );break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_NOT_EQUALS : cmbConditionText->setCurrentItem( ID_COMBO_COND_TEXT_NOT_EQUALS );break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_REGEXPR : cmbConditionText->setCurrentItem( ID_COMBO_COND_TEXT_REGEXPR );break; + case CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_NOT_REGEXPR : cmbConditionText->setCurrentItem( ID_COMBO_COND_TEXT_NOT_REGEXPR );break; + default : cmbConditionText->setCurrentItem( ID_COMBO_COND_TEXT_CONTAINS ); break; + } + + //set value + txtCompValueText->setText( value ); + + //set case sensitve + chkCaseSensitive->setChecked( cs ); + + //show or hide widgets + slotSetWidgets(); + +} + +FilterCriteria_Type FilterCriteriaWidget::getValues() +{ + FilterCriteria_Type crit; //return value + + switch( cmbSource->currentItem() ) + { + case ID_COMBO_SOURCE_FROM : crit.source = CONFIG_VALUE_FILTER_CRITERIA_SOURCE_FROM; break; + case ID_COMBO_SOURCE_TO : crit.source = CONFIG_VALUE_FILTER_CRITERIA_SOURCE_TO; break; + case ID_COMBO_SOURCE_SIZE : crit.source = CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SIZE; break; + case ID_COMBO_SOURCE_SUBJECT : crit.source = CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SUBJECT; break; + case ID_COMBO_SOURCE_HEADER : crit.source = CONFIG_VALUE_FILTER_CRITERIA_SOURCE_HEADER; break; + case ID_COMBO_SOURCE_ACCOUNT : crit.source = CONFIG_VALUE_FILTER_CRITERIA_SOURCE_ACCOUNT; break; + default : crit.source = 99; break; + } + + if( crit.source == CONFIG_VALUE_FILTER_CRITERIA_SOURCE_FROM || + crit.source == CONFIG_VALUE_FILTER_CRITERIA_SOURCE_TO || + crit.source == CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SUBJECT || + crit.source == CONFIG_VALUE_FILTER_CRITERIA_SOURCE_HEADER || + crit.source == CONFIG_VALUE_FILTER_CRITERIA_SOURCE_ACCOUNT ) + { + switch( cmbConditionText->currentItem() ) + { + case ID_COMBO_COND_TEXT_CONTAINS : crit.condition = CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_CONTAINS; break; + case ID_COMBO_COND_TEXT_NOT_CONTAINS : crit.condition = CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_NOT_CONTAINS; break; + case ID_COMBO_COND_TEXT_EQUALS : crit.condition = CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_EQUALS; break; + case ID_COMBO_COND_TEXT_NOT_EQUALS : crit.condition = CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_NOT_EQUALS; break; + case ID_COMBO_COND_TEXT_REGEXPR : crit.condition = CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_REGEXPR; break; + case ID_COMBO_COND_TEXT_NOT_REGEXPR : crit.condition = CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_NOT_REGEXPR; break; + default : crit.condition = 99; break; + } + } else if ( crit.source == CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SIZE ) + { + switch( cmbConditionNum->currentItem() ) + { + case ID_COMBO_COND_NUM_EQUAL : crit.condition = CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_EQUAL; break; + case ID_COMBO_COND_NUM_NOT_EQUAL : crit.condition = CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_NOT_EQUAL; break; + case ID_COMBO_COND_NUM_GREATER : crit.condition = CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_GREATER; break; + case ID_COMBO_COND_NUM_GREATER_EQUAL : crit.condition = CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_GREATER_EQUAL; break; + case ID_COMBO_COND_NUM_LESS : crit.condition = CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_LESS; break; + case ID_COMBO_COND_NUM_LESS_EQUAL : crit.condition = CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_LESS_EQUAL; break; + default : crit.condition = 99; + } + } else + crit.condition = 99; + + crit.txtValue = txtCompValueText->text(); + crit.numValue = spbCompValueNum->value(); + crit.cs = chkCaseSensitive->isChecked(); + + return crit; +} + + +#include "filtercriteriawidget.moc" diff --git a/kshowmail/kcmconfigs/filtercriteriawidget.h b/kshowmail/kcmconfigs/filtercriteriawidget.h new file mode 100644 index 0000000..14721c2 --- /dev/null +++ b/kshowmail/kcmconfigs/filtercriteriawidget.h @@ -0,0 +1,163 @@ +// +// C++ Interface: filtercriteriawidget +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef FILTERCRITERIAWIDGET_H +#define FILTERCRITERIAWIDGET_H + +//Qt headers +#include <qwidget.h> +#include <qlayout.h> +#include <qcheckbox.h> + +//KDE headers +#include <klineedit.h> +#include <kseparator.h> +#include <kdialog.h> +#include <kcombobox.h> +#include <klocale.h> +#include <knuminput.h> +#include <kpushbutton.h> +#include <kregexpeditorinterface.h> +#include <ktrader.h> +#include <kdebug.h> +#include <kmessagebox.h> +#include <kparts/componentfactory.h> + +//KShowmail headers +#include <../constants.h> +#include <../types.h> + +//ComboBox IDs +#define ID_COMBO_SOURCE_FROM 0 +#define ID_COMBO_SOURCE_TO 1 +#define ID_COMBO_SOURCE_SIZE 2 +#define ID_COMBO_SOURCE_SUBJECT 3 +#define ID_COMBO_SOURCE_HEADER 4 +#define ID_COMBO_SOURCE_ACCOUNT 5 + +#define ID_COMBO_COND_TEXT_CONTAINS 0 +#define ID_COMBO_COND_TEXT_NOT_CONTAINS 1 +#define ID_COMBO_COND_TEXT_EQUALS 2 +#define ID_COMBO_COND_TEXT_NOT_EQUALS 3 +#define ID_COMBO_COND_TEXT_REGEXPR 4 +#define ID_COMBO_COND_TEXT_NOT_REGEXPR 5 + +#define ID_COMBO_COND_NUM_EQUAL 0 +#define ID_COMBO_COND_NUM_NOT_EQUAL 1 +#define ID_COMBO_COND_NUM_GREATER 2 +#define ID_COMBO_COND_NUM_GREATER_EQUAL 3 +#define ID_COMBO_COND_NUM_LESS 4 +#define ID_COMBO_COND_NUM_LESS_EQUAL 5 + +using namespace Types; + +/** + * @brief Part of the filter setup dialog (class FilterSetupDialog) to show a criteria of the selected filter. + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +class FilterCriteriaWidget : public QWidget +{ + +Q_OBJECT + + public: + + /** + * Constructor + */ + FilterCriteriaWidget( QWidget *parent = 0, const char *name = 0 ); + + /** + * Destructor + */ + ~FilterCriteriaWidget(); + + /** + * Sets the values of a numeric criteria. + * @param source Object of Comparison (see constants.h for valid values) + * @param condition Condition of the comparison (see constants.h for valid values) + * @param value comparison value + */ + void setNumCriteria( int source, int condition, uint value ); + + /** + * Sets the values of a text criteria. + * @param source Object of Comparison (see constants.h for valid values) + * @param condition Condition of the comparison (see constants.h for valid values) + * @param value comparison string + * @param cs TRUE - comparison is case sensitive; FALSE - comparison is not case sensitive + */ + void setTextCriteria( int source, int condition, QString value, bool cs ); + + /** + * Returns the values of the criteria. + * @return criteria values + */ + FilterCriteria_Type getValues(); + + private: + + /** + * Combobox to select the source of the criteria. + */ + KComboBox* cmbSource; + + /** + * Combobox to select the condition of a text source (From, To, ...) + */ + KComboBox* cmbConditionText; + + /** + * Combobox to select the condition of a numeric source (Size, ...) + */ + KComboBox* cmbConditionNum; + + /** + * Line for a text comparative value. + */ + KLineEdit* txtCompValueText; + + /** + * Spin Box for a numeric comparative value. + */ + KIntNumInput* spbCompValueNum; + + /** + * Checkbox to select case sensitive. + */ + QCheckBox* chkCaseSensitive; + + /** + * Button to open the regular expression editor. + */ + KPushButton* btnOpenRegExpEditor; + + /** + * TRUE - KRegExpEditor is installed and available. + */ + bool kRegExpEditorAvailable; + + + private slots: + + /** + * Connected with combobox cmbSource. + * Hides or shows the widgets dependent on the criteria source (text or numeric). + */ + void slotSetWidgets(); + + /** + * Opens the editor for regular expressions. + */ + void slotOpenRegExpEditor(); +}; + +#endif diff --git a/kshowmail/kcmconfigs/filtersetupdialog.cpp b/kshowmail/kcmconfigs/filtersetupdialog.cpp new file mode 100644 index 0000000..58e390b --- /dev/null +++ b/kshowmail/kcmconfigs/filtersetupdialog.cpp @@ -0,0 +1,451 @@ +// +// C++ Implementation: filtersetupdialog +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "filtersetupdialog.h" + +FilterSetupDialog::FilterSetupDialog( QWidget* parent, FilterSetupItem* item ) + : KDialogBase( parent, "FilterSetupDialog", true, QString::null, Ok|Cancel, Ok, true ) +{ + //save pointer to account and view + filter = item; + + //set caption + if( item != NULL ) + if( item->getName() == DEFAULT_FILTER_NAME ) + setCaption( i18n( "New filter" ) ); + else + setCaption( i18n( "Edit filter" ) ); + + //create main widget and layout + QWidget* pgMain = new QWidget( this ); + setMainWidget( pgMain ); + QVBoxLayout* layMain = new QVBoxLayout( pgMain, 0, spacingHint() ); + + //create filter name widgets + QHBoxLayout* layName = new QHBoxLayout( layMain, spacingHint() ); + QLabel* lblName = new QLabel( i18n( "Name:" ), pgMain, "lblName" ); + layName->addWidget( lblName ); + txtName = new KLineEdit( pgMain, "txtName" ); + layName->addWidget( txtName ); + + //create group boxes and layouts for rules and action + QGroupBox* gboxCriteria = new QGroupBox( 0, Qt::Horizontal, i18n( "Filter Criterias" ), pgMain, "gboxCriteria" ); + QVBoxLayout* layCriteria = new QVBoxLayout( gboxCriteria->layout(), spacingHint() ); + layMain->addWidget( gboxCriteria ); + + QGroupBox* gboxAction = new QGroupBox( 0, Qt::Horizontal, i18n( "Filter Action" ), pgMain, "gboxAction" ); + QHBoxLayout* layAction = new QHBoxLayout( gboxAction->layout(), spacingHint() ); + layMain->addWidget( gboxAction ); + + //radio buttons to select the kind of linkage between filter criterias + QHBoxLayout* layLinkage = new QHBoxLayout( layCriteria, spacingHint(), "layLinkage" ); + grpLinkage = new QButtonGroup( NULL, "grpLinkage" ); + + QRadioButton* btnMatchAll = new QRadioButton( i18n( "Match all of the following" ), gboxCriteria, "btnMatchAll" ); + QRadioButton* btnMatchAny = new QRadioButton( i18n( "Match any of the following" ), gboxCriteria, "btnMatchAny" ); + grpLinkage->insert( btnMatchAll, ID_BUTTON_LINKAGE_MATCH_ALL ); + grpLinkage->insert( btnMatchAny, ID_BUTTON_LINKAGE_MATCH_ANY ); + layLinkage->addWidget( btnMatchAll ); + layLinkage->addWidget( btnMatchAny ); + + switch( DEFAULT_FILTER_CRITERIA_LINKAGE ) + { + case CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ALL : grpLinkage->setButton( ID_BUTTON_LINKAGE_MATCH_ALL ); break; + case CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ANY : grpLinkage->setButton( ID_BUTTON_LINKAGE_MATCH_ANY ); break; + default : grpLinkage->setButton( ID_BUTTON_LINKAGE_MATCH_ALL ); break; + } + + //this widget holds one or more criterias (class FilterCriteriaWidget) + wdgCriteriasHolding = new QWidget( gboxCriteria, "gboxCriteria" ); + layCriteriasHolding = new QVBoxLayout( wdgCriteriasHolding, 0, spacingHint(), "layCriteriasHolding" ); + layCriteria->addWidget( wdgCriteriasHolding ); + + //buttons to add or remove criterias + QHBoxLayout* layButtons = new QHBoxLayout( layCriteria, spacingHint(), "layButtons" ); + btnAddCriteria = new KPushButton( KGuiItem( i18n( "More" ), "button_more", i18n( "Add a further criteria." ) ), gboxCriteria, "btnAddCriteria" ); + btnRemoveCriteria = new KPushButton( KGuiItem( i18n( "Fewer" ), "button_fewer", i18n( "Remove the last criteria." ) ), gboxCriteria, "btnRemoveCriteria" ); + btnAddCriteria->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed ); + btnRemoveCriteria->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed ); + layButtons->addWidget( btnAddCriteria ); + layButtons->addWidget( btnRemoveCriteria ); + layButtons->addStretch(); + connect( btnAddCriteria, SIGNAL( clicked() ), this, SLOT( slotAddCriteriaWidget() ) ); + connect( btnRemoveCriteria, SIGNAL( clicked() ), this, SLOT( slotRemoveCriteriaWidget() ) ); + + //create combobox to select action + cmbAction = new KComboBox( gboxAction, "cmbAction" ); + layAction->addWidget( cmbAction ); + QToolTip::add( cmbAction, i18n( "Choose the action for all mails which are filtered by this filter." ) ); + connect( cmbAction, SIGNAL( activated( int ) ), this, SLOT( slotActionChanged( int ) ) ); + + //insert items + cmbAction->insertItem( i18n( "Show" ), ID_COMBO_FILTER_ACTION_PASS ); + cmbAction->insertItem( i18n( "Delete" ), ID_COMBO_FILTER_ACTION_DELETE ); + cmbAction->insertItem( i18n( "Mark" ), ID_COMBO_FILTER_ACTION_MARK ); + cmbAction->insertItem( i18n( "Move" ), ID_COMBO_FILTER_ACTION_MOVE ); + cmbAction->insertItem( i18n( "Spamcheck" ), ID_COMBO_FILTER_ACTION_SPAMCHECK ); + cmbAction->insertItem( i18n( "Ignore" ), ID_COMBO_FILTER_ACTION_IGNORE ); + + //create edit line to defined the mailbox for move + txtMailbox = new KLineEdit( gboxAction ); + layAction->addWidget( txtMailbox ); + + //create wizard button to configure mailbox + btnMailboxWizard= new KPushButton( KGuiItem( QString::null, "wizard" ), gboxAction ); + layAction->addWidget( btnMailboxWizard ); + QToolTip::add( btnMailboxWizard, i18n( "Choose the mailbox" ) ); + connect( btnMailboxWizard, SIGNAL( clicked() ), this, SLOT( slotOpenMailBoxWizard() ) ); + + //set default action + switch( DEFAULT_FILTER_ACTION ) + { + case CONFIG_VALUE_FILTER_ACTION_PASS : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_PASS ); break; + case CONFIG_VALUE_FILTER_ACTION_DELETE : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_DELETE ); break; + case CONFIG_VALUE_FILTER_ACTION_MARK : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_MARK ); break; + case CONFIG_VALUE_FILTER_ACTION_MOVE : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_MOVE ); break; + case CONFIG_VALUE_FILTER_ACTION_SPAMCHECK : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_SPAMCHECK ); break; + case CONFIG_VALUE_FILTER_ACTION_IGNORE : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_IGNORE ); break; + } + + //enable or disable action widgets + slotActionChanged( cmbAction->currentItem() ); + + //this adds a first empty criteria widget at the dialog if the given setup item pointer is null + //(this means we want to create a new filter) + if( item == NULL ) + { + slotAddCriteriaWidget(); + } + + //write values of the given filter into the dialog items + if( filter != NULL ) + fillDialog(); +} + + +FilterSetupDialog::~FilterSetupDialog() +{ +} + +void FilterSetupDialog::fillDialog( ) +{ + //check for valid pointer to the setup item + if( filter == NULL ) + { + kdError() << "FilterSetupDialog::fillDialog: The given pointer to the filter setup item is NULL." << endl; + return; + } + + //set filter name + txtName->setText( filter->getName() ); + + //set linkage + switch( filter->getCriteriaLinkage() ) + { + case CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ALL : grpLinkage->setButton( ID_BUTTON_LINKAGE_MATCH_ALL ); break; + case CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ANY : grpLinkage->setButton( ID_BUTTON_LINKAGE_MATCH_ANY ); break; + default : kdError() << "FilterSetupDialog::fillDialog: The Filter Setup Item of filter " << filter->getName() << " has returned an invalid linkage value. Set default value." << endl; + switch( DEFAULT_FILTER_CRITERIA_LINKAGE ) + { + case CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ALL : grpLinkage->setButton( ID_BUTTON_LINKAGE_MATCH_ALL ); break; + case CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ANY : grpLinkage->setButton( ID_BUTTON_LINKAGE_MATCH_ANY ); break; + default: kdError() << "FilterSetupDialog::fillDialog: The default value DEFAULT_FILTER_CRITERIA_LINKAGE in constants.h is also invalid. Set linkage to ALL." << endl; + grpLinkage->setButton( ID_BUTTON_LINKAGE_MATCH_ALL ); + break; + } + break; + } + + //set criterias + FilterCriteriaList_Type criteriaList = filter->getCriteriaList(); + + if( !criteriaList.empty() ) + { + FilterCriteriaList_Type::iterator it; + for( it = criteriaList.begin(); it != criteriaList.end(); ++it ) + { + //get source and condition + int source = (*it).source; + int condition = (*it).condition; + + //depend on the source we add a numeric or text criteria + switch( source ) + { + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_FROM : + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_TO : + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SUBJECT : + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_HEADER : + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_ACCOUNT : addCriteriaWidget( source, condition, (*it).txtValue, (*it).cs ); break; + + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SIZE : addCriteriaWidget( source, condition, (*it).numValue ); break; + default : kdError() << "FilterSetupDialog::fillDialog: The Filter Setup Item of filter " << filter->getName() << " has returned an invalid criteria. Add an empty criteria." << endl; + break; + } + } + } + else + //just add a empty criteria widget + slotAddCriteriaWidget(); + + + //set action + switch( filter->getAction() ) + { + case CONFIG_VALUE_FILTER_ACTION_PASS : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_PASS ); break; + case CONFIG_VALUE_FILTER_ACTION_DELETE : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_DELETE ); break; + case CONFIG_VALUE_FILTER_ACTION_MARK : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_MARK ); break; + case CONFIG_VALUE_FILTER_ACTION_MOVE : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_MOVE ); break; + case CONFIG_VALUE_FILTER_ACTION_IGNORE : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_IGNORE ); break; + case CONFIG_VALUE_FILTER_ACTION_SPAMCHECK : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_SPAMCHECK ); break; + default : kdError() << "FilterSetupDialog:: fillDialog: The Filter Setup Item of filter " << filter->getName() << " has returned an invalid action value. Set default value." << endl; + switch( DEFAULT_FILTER_ACTION ) + { + case CONFIG_VALUE_FILTER_ACTION_PASS : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_PASS ); break; + case CONFIG_VALUE_FILTER_ACTION_DELETE : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_DELETE ); break; + case CONFIG_VALUE_FILTER_ACTION_MARK : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_MARK ); break; + case CONFIG_VALUE_FILTER_ACTION_MOVE : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_MOVE ); break; + case CONFIG_VALUE_FILTER_ACTION_IGNORE : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_IGNORE ); break; + case CONFIG_VALUE_FILTER_ACTION_SPAMCHECK : cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_SPAMCHECK ); break; + default: kdError() << "FilterSetupDialog::fillDialog: The default value DEFAULT_FILTER_ACTION in constants.h is also invalid. Set action to PASS." << endl; + cmbAction->setCurrentItem( ID_COMBO_FILTER_ACTION_PASS ); + break; + } + } + + //set mailbox name if action is MOVE + if( filter->getAction() == CONFIG_VALUE_FILTER_ACTION_MOVE ) + txtMailbox->setText( filter->getMailBox() ); + + //enable or disable action widgets + slotActionChanged( cmbAction->currentItem() ); + +} + +FilterCriteriaWidget* FilterSetupDialog::slotAddCriteriaWidget( ) +{ + //create a new widget + FilterCriteriaWidget* crit = new FilterCriteriaWidget( wdgCriteriasHolding ); + crit->setHidden( false ); //the new widgets are hidden by default + + //insert it into the layout + layCriteriasHolding->addWidget( crit ); + + //hide remove button if necessary + const QObjectList* critList = wdgCriteriasHolding->children(); + + if( critList != NULL ) + { + if( critList->count() <= 2 ) + btnRemoveCriteria->setEnabled( false ); + else + btnRemoveCriteria->setEnabled( true ); + } + + + + return crit; +} + +void FilterSetupDialog::slotRemoveCriteriaWidget( ) +{ + //get a list of all criteria widgets + const QObjectList* critList = wdgCriteriasHolding->children(); + + //return, if the pointer to the list is invalid + if( critList == NULL ) + { + kdError() << "FilterSetupDialog::slotRemoveCriteriaWidget: No object found in the criteria widget holding." << endl;; + return; + } + + //return, if the holding widget doesn't contain a criteria widget + //the count of children has to be greater than 2, because the layout is the first child + //and one criteria must always be present. + if( critList->count() <= 2 ) return; + + //get iterator + QObjectListIterator it( *critList ); + + //get last child + QObject* obj = it.toLast(); + + //remove last child + if( obj->isA( "FilterCriteriaWidget" ) ) + { + ((QWidget*)obj)->setHidden( true ); + layCriteriasHolding->remove( (QWidget*)obj ); + wdgCriteriasHolding->removeChild( obj ); + } + else + kdError() << "FilterSetupDialog::slotRemoveCriteriaWidget: the last object of the criteria widget holding is not a criteria widget." << endl; + + //hide remove button if necessary + if( critList->count() <= 2 ) + btnRemoveCriteria->setEnabled( false ); + else + btnRemoveCriteria->setEnabled( true ); + +} + +void FilterSetupDialog::addCriteriaWidget( int source, int condition, uint value ) +{ + //check source and condition + if( source != CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SIZE ) + { + kdError() << "FilterSetupDialog::addCriteriaWidget: invalid source parameter." << endl; + return; + } + + if( condition != CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_EQUAL && + condition != CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_NOT_EQUAL && + condition != CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_GREATER && + condition != CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_GREATER_EQUAL && + condition != CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_LESS && + condition != CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_LESS_EQUAL ) + { + kdError() << "FilterSetupDialog::addCriteriaWidget: invalid condition parameter." << endl; + return; + } + + //create widget + FilterCriteriaWidget* crit = slotAddCriteriaWidget(); + + //set values + crit->setNumCriteria( source, condition, value ); +} + +void FilterSetupDialog::addCriteriaWidget( int source, int condition, QString value, bool cs ) +{ + //check source and condition + if( source != CONFIG_VALUE_FILTER_CRITERIA_SOURCE_FROM && + source != CONFIG_VALUE_FILTER_CRITERIA_SOURCE_TO && + source != CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SUBJECT && + source != CONFIG_VALUE_FILTER_CRITERIA_SOURCE_HEADER && + source != CONFIG_VALUE_FILTER_CRITERIA_SOURCE_ACCOUNT ) + { + kdError() << "FilterSetupDialog::addCriteriaWidget: invalid source parameter." << endl; + return; + } + + if( condition != CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_CONTAINS && + condition != CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_NOT_CONTAINS && + condition != CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_EQUALS && + condition != CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_NOT_EQUALS && + condition != CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_REGEXPR && + condition != CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_NOT_REGEXPR ) + { + kdError() << "FilterSetupDialog::addCriteriaWidget: invalid condition parameter." << endl; + return; + } + + //create widget + FilterCriteriaWidget* crit = slotAddCriteriaWidget(); + + //set values + crit->setTextCriteria( source, condition, value, cs ); + +} + +void FilterSetupDialog::slotOk() +{ + + //here we write the settings back to the filter setup item + + //filter name + filter->setName( txtName->text() ); + + //linkage + switch( grpLinkage->selectedId() ) + { + case ID_BUTTON_LINKAGE_MATCH_ALL : filter->setCriteriaLinkage( CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ALL ); break; + case ID_BUTTON_LINKAGE_MATCH_ANY : filter->setCriteriaLinkage( CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ANY ); break; + default : kdDebug() << "FilterSetupDialog::slotOk: Invalid linkage value. Set default value." << endl; + filter->setCriteriaLinkage( DEFAULT_FILTER_CRITERIA_LINKAGE ); break; + } + + //action + switch( cmbAction->currentItem() ) + { + case ID_COMBO_FILTER_ACTION_PASS : filter->setAction( CONFIG_VALUE_FILTER_ACTION_PASS ); break; + case ID_COMBO_FILTER_ACTION_DELETE : filter->setAction( CONFIG_VALUE_FILTER_ACTION_DELETE ); break; + case ID_COMBO_FILTER_ACTION_MARK : filter->setAction( CONFIG_VALUE_FILTER_ACTION_MARK ); break; + case ID_COMBO_FILTER_ACTION_MOVE : filter->setAction( CONFIG_VALUE_FILTER_ACTION_MOVE ); break; + case ID_COMBO_FILTER_ACTION_IGNORE : filter->setAction( CONFIG_VALUE_FILTER_ACTION_IGNORE ); break; + case ID_COMBO_FILTER_ACTION_SPAMCHECK : filter->setAction( CONFIG_VALUE_FILTER_ACTION_SPAMCHECK ); break; + default : kdDebug() << "FilterSetupDialog::slotOk: Invalid action value. Set default value." << endl; + filter->setAction( DEFAULT_FILTER_ACTION ); break; + } + + //mailbox name if action is MOVE + if( cmbAction->currentItem() == ID_COMBO_FILTER_ACTION_MOVE ) + filter->setMailBox( txtMailbox->text() ); + + //criteria widgets + + //get list of all children of the criterias holding widget + const QObjectList* children = wdgCriteriasHolding->children(); + + //get iterator of the list + QObjectListIterator it( *children ); + + QObject* obj; //current child object + FilterCriteriaList_Type critList; //list of criterias; will be give to the filter setup item + + //iterate over the children list + while ( ( obj = it.current() ) != NULL ) + { + //get next child + ++it; + + if( obj->isA( "FilterCriteriaWidget" ) ) //check for criteria object + { + //get the values of the criteria + FilterCriteria_Type crit = ( (FilterCriteriaWidget*)obj )->getValues(); + + //append the new criteria at the end of the criteria list + critList.push_back( crit ); + } + } + + //pass criteria list to filter setup item + filter->setCriteriaList( critList ); + + //call slot of super class to close the dialog + KDialogBase::slotOk(); +} + +void FilterSetupDialog::slotActionChanged( int index ) +{ + switch( index ) + { + case ID_COMBO_FILTER_ACTION_MOVE : txtMailbox->setEnabled( true ); + if( txtMailbox->text() == "" ) txtMailbox->setText( DEFAULT_FILTER_ACTION_MOVE_MAILBOX ); + btnMailboxWizard->setHidden( false ); + break; + default : txtMailbox->setEnabled( false ); + btnMailboxWizard->setHidden( true ); + break; + } +} + +void FilterSetupDialog::slotOpenMailBoxWizard( ) +{ + MailBoxWizard wizard( this, "malboxwizard" ); + wizard.setCaption( i18n( "Mailbox Select" ) ); + int res = wizard.exec(); + + if( res == QDialog::Accepted ) + txtMailbox->setText( wizard.getPath() ); + +} + + +#include "filtersetupdialog.moc" diff --git a/kshowmail/kcmconfigs/filtersetupdialog.h b/kshowmail/kcmconfigs/filtersetupdialog.h new file mode 100644 index 0000000..a9fd761 --- /dev/null +++ b/kshowmail/kcmconfigs/filtersetupdialog.h @@ -0,0 +1,191 @@ +// +// C++ Interface: filtersetupdialog +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef FILTERSETUPDIALOG_H +#define FILTERSETUPDIALOG_H + +//button IDs +#define ID_BUTTON_LINKAGE_MATCH_ALL 1 +#define ID_BUTTON_LINKAGE_MATCH_ANY 2 + +//Qt headers +#include <qlayout.h> +#include <qgroupbox.h> +#include <qbuttongroup.h> +#include <qradiobutton.h> +#include <qvbox.h> +#include <qobjectlist.h> +#include <qtooltip.h> +#include <qlabel.h> + +//KDE headers +#include <kdialogbase.h> +#include <klocale.h> +#include <kpushbutton.h> +#include <kcombobox.h> +#include <klineedit.h> + +//KShowmail headers +#include "filtersetupitem.h" +#include "filtercriteriawidget.h" +#include "../constants.h" +#include "mailboxwizard.h" + +//IDs of the action combo box +#define ID_COMBO_FILTER_ACTION_PASS 0 +#define ID_COMBO_FILTER_ACTION_DELETE 1 +#define ID_COMBO_FILTER_ACTION_MARK 2 +#define ID_COMBO_FILTER_ACTION_MOVE 3 +#define ID_COMBO_FILTER_ACTION_SPAMCHECK 4 +#define ID_COMBO_FILTER_ACTION_IGNORE 5 + +/** + * @brief Dialog to setup a filter. + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +class FilterSetupDialog : public KDialogBase +{ + + Q_OBJECT + + public: + /** + * General constructor + * @param parent parent of the dialog + * @param item filter to setup; + */ + FilterSetupDialog( QWidget* parent, FilterSetupItem* item = NULL ); + + /** + * Destructor + */ + ~FilterSetupDialog(); + + private: + + /** + * filter to setup + */ + FilterSetupItem* filter; + + /** + * View which shows the filter items. + */ + KListView* ListView; + + /** + * Contains the filter name. + */ + KLineEdit* txtName; + + /** + * Combines the radio buttons to select the kind of linkage between the criterias. + */ + QButtonGroup* grpLinkage; + + /** + * This widget holds one ore more filter criteria dialogs (class FilterCriteriaWidget). + */ + QWidget* wdgCriteriasHolding; + + /** + * Layout for wdgCriterias. + */ + QVBoxLayout* layCriteriasHolding; + + /** + * Button to add a criteria dialog. + */ + KPushButton* btnAddCriteria; + + /** + * Button to remove the last criteria. + */ + KPushButton* btnRemoveCriteria; + + /** + * Combobox to select the action. + */ + KComboBox* cmbAction; + + /** + * If selected, the mails will be moved to the mailbox which is written in this edit line. + */ + KLineEdit* txtMailbox; + + /** + * This button opens a wizard which will help to get the right mailbox + */ + KPushButton* btnMailboxWizard; + + + protected: + + /** + * Writes the values of the given filter into the dialog items. + */ + void fillDialog(); + + /** + * Adds a criteria widget dialog with values for numeric comparison. + * @param source Object of Comparison. It accepts only numeric objects (e.g. Size) (see constants.h for valid values) + * @param condition Condition of the comparison (see constants.h for valid values) + * @param value comparison value + */ + void addCriteriaWidget( int source, int condition, uint value ); + + /** + * Adds a criteria widget dialog with values for text comparison. + * @param source Object of Comparison. It accepts only text objects (e.g. Subject) (see constants.h for valid values) + * @param condition Condition of the comparison (see constants.h for valid values) + * @param value comparison string + * @param cs TRUE - comparison is case sensitive; FALSE - comparison is not case sensitive + */ + void addCriteriaWidget( int source, int condition, QString value, bool cs ); + + + protected slots: + + /** + * Overwritten method of KDialogBase. + * Called if OK was clicked. + * Stores the entered values into the given account item. + * If no item was given it creates a new one. + * After then it invokes slotOk() of KDialogBase. + */ + void slotOk(); + + /** + * Connected with combobox cmbAction. + * Enables or disables additional widgets for action configuration. + * @param index position (index) of the selected action + */ + void slotActionChanged( int index ); + + /** + * Adds a empty critera dialog widget. + * @return Pointer to the new widget + */ + FilterCriteriaWidget* slotAddCriteriaWidget(); + + /** + * Removes the last criteria dialog widget. + */ + void slotRemoveCriteriaWidget(); + + /** + * Connected with button btnMailboxWizard. + * Opens a wizard to configure the mailbox + */ + void slotOpenMailBoxWizard(); +}; + +#endif diff --git a/kshowmail/kcmconfigs/filtersetupitem.cpp b/kshowmail/kcmconfigs/filtersetupitem.cpp new file mode 100644 index 0000000..ef16a53 --- /dev/null +++ b/kshowmail/kcmconfigs/filtersetupitem.cpp @@ -0,0 +1,347 @@ +// +// C++ Implementation: filtersetupitem +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "filtersetupitem.h" + +FilterSetupItem::FilterSetupItem( KListView* parent ) + : KListViewItem( parent ) +{ + //set default number + number = 0; + + init(); +} + +FilterSetupItem::FilterSetupItem( KListView* parent, uint num ) + : KListViewItem( parent ) +{ + //store the given filter number + number = num; + + init(); +} + +FilterSetupItem::~FilterSetupItem() +{ +} + +void FilterSetupItem::init( ) +{ + //get application config object (kshowmailrc) + config = KApplication::kApplication()->config(); + + //set default values + setName( i18n( DEFAULT_FILTER_NAME ) ); + setCriteriaLinkage( DEFAULT_FILTER_CRITERIA_LINKAGE ); + setAction( DEFAULT_FILTER_ACTION ); + + //show number in column + setText( ColNumber, QString("%1").arg( number ) ); +} + +void FilterSetupItem::setName( QString name ) +{ + this->name = name; + + //show name in the list view + setText( ColName, name ); +} + +QString FilterSetupItem::getName( ) const +{ + return name; +} + +void FilterSetupItem::setNumber( uint number ) +{ + this->number = number; + + //show number in column + setText( ColNumber, QString("%1").arg( number ) ); +} + +void FilterSetupItem::setAction( int action ) +{ + if( action == CONFIG_VALUE_FILTER_ACTION_PASS || + action == CONFIG_VALUE_FILTER_ACTION_DELETE || + action == CONFIG_VALUE_FILTER_ACTION_MARK || + action == CONFIG_VALUE_FILTER_ACTION_MOVE || + action == CONFIG_VALUE_FILTER_ACTION_IGNORE || + action == CONFIG_VALUE_FILTER_ACTION_SPAMCHECK ) + { + this->action = action; + } + else + { + kdError() << "FilterSetupItem::setAction: Invalid parameter for action given. Parameter: " << action << endl; + this->action = DEFAULT_FILTER_ACTION; + return; + } + + //update the text of the rule column + updateActionColumn(); +} + +void FilterSetupItem::save( ) +{ + //build group name + QString group; + group = QString( "%1%2" ).arg( CONFIG_GROUP_FILTER ).arg( number ); + + //first delete the group to clear it of old criteria entries + config->deleteGroup( group ); + + //set group + config->setGroup( group ); + + //write entries + config->writeEntry( CONFIG_ENTRY_FILTER_NAME, name ); + + if( linkage == CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ALL || + linkage == CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ANY ) + { + config->writeEntry( CONFIG_ENTRY_FILTER_CRITERIA_LINKAGE, linkage ); + } + else + { + config->writeEntry( CONFIG_ENTRY_FILTER_CRITERIA_LINKAGE, DEFAULT_FILTER_CRITERIA_LINKAGE ); + } + + if( action == CONFIG_VALUE_FILTER_ACTION_PASS || + action == CONFIG_VALUE_FILTER_ACTION_DELETE || + action == CONFIG_VALUE_FILTER_ACTION_MARK || + action == CONFIG_VALUE_FILTER_ACTION_MOVE || + action == CONFIG_VALUE_FILTER_ACTION_IGNORE || + action == CONFIG_VALUE_FILTER_ACTION_SPAMCHECK ) + { + config->writeEntry( CONFIG_ENTRY_FILTER_ACTION, action ); + } + else + { + config->writeEntry( CONFIG_ENTRY_FILTER_ACTION, DEFAULT_FILTER_ACTION ); + } + + //write action parameter + switch( action ) + { + case CONFIG_VALUE_FILTER_ACTION_MOVE : + config->writeEntry( CONFIG_ENTRY_FILTER_MOVE_MAILBOX, mailbox ); + break; + + default: break; + } + + //write criteria list and number of criterias + if( !criteriaList.empty() ) + { + config->writeEntry( CONFIG_ENTRY_FILTER_CRITERIA_NUMBER, criteriaList.size() ); + + int ctr = 0; //number of the current criteria + FilterCriteriaList_Type::iterator it; + for( it = criteriaList.begin(); it != criteriaList.end(); ++it ) + { + ctr++; + + config->writeEntry( QString( "%1%2" ).arg( CONFIG_ENTRY_FILTER_CRITERIA_SOURCE ).arg( ctr ), (*it).source ); + config->writeEntry( QString( "%1%2" ).arg( CONFIG_ENTRY_FILTER_CRITERIA_CONDITION ).arg( ctr ), (*it).condition ); + + switch( (*it).source ) + { + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_FROM : + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_TO : + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SUBJECT : + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_HEADER : + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_ACCOUNT : config->writeEntry( QString( "%1%2" ).arg( CONFIG_ENTRY_FILTER_CRITERIA_VALUE ).arg( ctr ), (*it).txtValue ); + config->writeEntry( QString( "%1%2" ).arg( CONFIG_ENTRY_FILTER_CRITERIA_CASESENSITIVE ).arg( ctr ), (*it).cs ); + break; + + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SIZE : config->writeEntry( QString( "%1%2" ).arg( CONFIG_ENTRY_FILTER_CRITERIA_VALUE ).arg( ctr ), (*it).numValue ); + break; + } + } + } + else + { + config->writeEntry( CONFIG_ENTRY_FILTER_CRITERIA_NUMBER, 0 ); + } + +} + +void FilterSetupItem::setCriteriaLinkage( int linkage ) +{ + if( linkage == CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ALL || + linkage == CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ANY ) + { + this->linkage = linkage; + } + else + { + kdError() << "FilterSetupItem::setCriteriaLinkage: Invalid parameter for criteria linkage given. Parameter: " << linkage << endl; + this->linkage = DEFAULT_FILTER_CRITERIA_LINKAGE; + return; + } + +} + +void FilterSetupItem::setCriteriaList( FilterCriteriaList_Type list ) +{ + criteriaList = list; +} + +void FilterSetupItem::setMailBox( QString mailbox ) +{ + this->mailbox = mailbox; + + //update the text of the rule column + updateActionColumn(); +} + +int FilterSetupItem::getCriteriaLinkage( ) const +{ + return linkage; +} + +int FilterSetupItem::getAction( ) const +{ + return action; +} + +QString FilterSetupItem::getMailBox( ) const +{ + if( action == CONFIG_VALUE_FILTER_ACTION_MOVE ) + return mailbox; + else + return QString( "" ); +} + +FilterCriteriaList_Type FilterSetupItem::getCriteriaList( ) const +{ + return criteriaList; +} + +uint FilterSetupItem::getNumber( ) const +{ + return number; +} + +int FilterSetupItem::compare( QListViewItem * i, int col, bool ascending ) const +{ + if( col == ColNumber ) + { + return text( ColNumber ).toInt() - i->text( ColNumber ).toInt(); + } + else + return key( col, ascending ).compare( i->key( col, ascending) ); + +} + +void FilterSetupItem::updateActionColumn( ) +{ + QString strAction; //filter action + + //build action + switch( action ) + { + case CONFIG_VALUE_FILTER_ACTION_PASS : strAction = i18n( "Show" ); break; + case CONFIG_VALUE_FILTER_ACTION_DELETE : strAction = i18n( "Delete" ); break; + case CONFIG_VALUE_FILTER_ACTION_MARK : strAction = i18n( "Mark" ); break; + case CONFIG_VALUE_FILTER_ACTION_MOVE : strAction = i18n( "Move to %1").arg( mailbox ); break; + case CONFIG_VALUE_FILTER_ACTION_IGNORE : strAction = i18n( "Ignore"); break; + case CONFIG_VALUE_FILTER_ACTION_SPAMCHECK : strAction = i18n( "Check for spam" ); break; + default : strAction = i18n( "Unknown action" ); break; + } + + //set text + setText( ColAction, QString( " %1" ).arg( strAction ) ); +} + +void FilterSetupItem::load( ) +{ + //set group + config->setGroup( QString( "%1%2" ).arg( CONFIG_GROUP_FILTER ).arg( number ) ); + + //get name + setName( config->readEntry( CONFIG_ENTRY_FILTER_NAME, DEFAULT_FILTER_NAME ) ); + + //get linkage + setCriteriaLinkage( config->readNumEntry( CONFIG_ENTRY_FILTER_CRITERIA_LINKAGE, DEFAULT_FILTER_CRITERIA_LINKAGE ) ); + if( linkage != CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ALL && linkage != CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ANY ) + setCriteriaLinkage( DEFAULT_FILTER_CRITERIA_LINKAGE ); + + //get action + setAction( config->readNumEntry( CONFIG_ENTRY_FILTER_ACTION, DEFAULT_FILTER_ACTION ) ); + if( action != CONFIG_VALUE_FILTER_ACTION_PASS && + action != CONFIG_VALUE_FILTER_ACTION_DELETE && + action != CONFIG_VALUE_FILTER_ACTION_MARK && + action != CONFIG_VALUE_FILTER_ACTION_MOVE && + action != CONFIG_VALUE_FILTER_ACTION_IGNORE && + action != CONFIG_VALUE_FILTER_ACTION_SPAMCHECK ) + setAction( DEFAULT_FILTER_ACTION ); + + //get action parameter + switch( action ) + { + case CONFIG_VALUE_FILTER_ACTION_MOVE : setMailBox( config->readEntry( CONFIG_ENTRY_FILTER_MOVE_MAILBOX, DEFAULT_FILTER_ACTION_MOVE_MAILBOX ) ); break; + default : setMailBox( QString::null ); + } + + //get number of criterias + uint numCrit = config->readNumEntry( CONFIG_ENTRY_FILTER_CRITERIA_NUMBER, 0 ); + + //get criterias + for( uint ctr = 1; ctr <= numCrit; ctr++ ) + { + struct FilterCriteria_Type crit; + + crit.source = config->readNumEntry( QString( "%1%2" ).arg( CONFIG_ENTRY_FILTER_CRITERIA_SOURCE ).arg( ctr ), DEFAULT_FILTER_CRITERIA_SOURCE ); + if( crit.source != CONFIG_VALUE_FILTER_CRITERIA_SOURCE_FROM && + crit.source != CONFIG_VALUE_FILTER_CRITERIA_SOURCE_TO && + crit.source != CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SUBJECT && + crit.source != CONFIG_VALUE_FILTER_CRITERIA_SOURCE_HEADER && + crit.source != CONFIG_VALUE_FILTER_CRITERIA_SOURCE_ACCOUNT && + crit.source != CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SIZE ) + crit.source = DEFAULT_FILTER_CRITERIA_SOURCE; + + switch( crit.source ) + { + case CONFIG_VALUE_FILTER_CRITERIA_SOURCE_SIZE : crit.condition = config->readNumEntry( QString( "%1%2" ).arg( CONFIG_ENTRY_FILTER_CRITERIA_CONDITION ).arg( ctr ), DEFAULT_FILTER_CRITERIA_COND_NUM ); + if( crit.condition != CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_EQUAL && + crit.condition != CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_NOT_EQUAL && + crit.condition != CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_GREATER && + crit.condition != CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_GREATER_EQUAL && + crit.condition != CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_LESS && + crit.condition != CONFIG_VALUE_FILTER_CRITERIA_COND_NUM_LESS_EQUAL ) + crit.condition = DEFAULT_FILTER_CRITERIA_COND_NUM; + crit.numValue = config->readNumEntry( QString( "%1%2" ).arg( CONFIG_ENTRY_FILTER_CRITERIA_VALUE ).arg( ctr ), DEFAULT_FILTER_CRITERIA_SIZE ); + break; + + default : crit.condition = config->readNumEntry( QString( "%1%2" ).arg( CONFIG_ENTRY_FILTER_CRITERIA_CONDITION ).arg( ctr ), DEFAULT_FILTER_CRITERIA_COND_TEXT ); + if( crit.condition != CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_CONTAINS && + crit.condition != CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_NOT_CONTAINS && + crit.condition != CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_EQUALS && + crit.condition != CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_NOT_EQUALS && + crit.condition != CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_REGEXPR && + crit.condition != CONFIG_VALUE_FILTER_CRITERIA_COND_TEXT_NOT_REGEXPR ) + crit.condition = DEFAULT_FILTER_CRITERIA_COND_TEXT; + crit.txtValue = config->readEntry( QString( "%1%2" ).arg( CONFIG_ENTRY_FILTER_CRITERIA_VALUE ).arg( ctr ) ); + crit.cs = config->readBoolEntry( QString( "%1%2" ).arg( CONFIG_ENTRY_FILTER_CRITERIA_CASESENSITIVE ).arg( ctr ), DEFAULT_FILTER_CRITERIA_CASE_SENSITIVE ); + break; + } + + criteriaList.push_back( crit ); + + } + + +} + + + diff --git a/kshowmail/kcmconfigs/filtersetupitem.h b/kshowmail/kcmconfigs/filtersetupitem.h new file mode 100644 index 0000000..1d1bf02 --- /dev/null +++ b/kshowmail/kcmconfigs/filtersetupitem.h @@ -0,0 +1,240 @@ +// +// C++ Interface: filtersetupitem +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef FILTERSETUPITEM_H +#define FILTERSETUPITEM_H + +//KDE headers +#include <klistview.h> +#include <kapplication.h> +#include <kconfig.h> +#include <kdebug.h> +#include <klocale.h> + +//KShowmail headers +#include "../constants.h" +#include "../types.h" + +using namespace Types; + +/** + * @brief This class is used in ConfigFilter to show the available filters in the list view and to store a filter setup. + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +class FilterSetupItem : public KListViewItem +{ + + public: + + /** + * Column Numbers. + */ + enum Column{ ColNumber = 0, ColName = 1, ColAction = 2 }; + + /** + * General Constructor + * @param parent the list view + */ + FilterSetupItem( KListView* parent ); + + /** + * Constructor + * @param parent the list view + * @param num filter number + */ + FilterSetupItem( KListView* parent, uint num ); + + /** + * Destructor + */ + ~FilterSetupItem(); + + /** + * Sets the filter name. + * @param name filter name + * @see name + * @see getName + */ + void setName( QString name ); + + /** + * Returns the name of this filter. + * @return filter name + * @see name + * @see setName + */ + QString getName() const; + + /** + * Sets the filter number. + * @param number filter number. + * @see number + * @see getNumber + */ + void setNumber( uint number ); + + /** + * Returns the filter number. + * @return filter number + * @see number + * @see setNumber + */ + uint getNumber() const; + + /** + * Sets the action. See constants.h for valid values (CONFIG_VALUE_FILTER_ACTION...). + * @param action + * @see getAction + * @see action + */ + void setAction( int action ); + + /** + * Returns the action of this filter. + * See constants.h for possible values (CONFIG_VALUE_FILTER_ACTION...). + * @return action code + * @see setAction + * @see action + */ + int getAction() const; + + /** + * Sets the mailbox of a move action. + * @param mailbox name of the mailbox + * @see setMailBox + * @see mailbox + */ + void setMailBox( QString mailbox ); + + /** + * Returns the mailbox name of a move action if this action is selected. Otherwise it returns an empty string. + * @return mailbox name + * @see setMailBox + * @see mailbox + */ + QString getMailBox() const; + + /** + * Sets the criteria linkage. + * Valid values are CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ALL (all criterias have to satisy) or CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ANY (at least one criteria has to satisy ). + * @param linkage criteria linkage + * @see linkage + */ + void setCriteriaLinkage( int linkage ); + + /** + * Returns the criteria linkage. + * Possible values are CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ALL (all criterias have to satisy) or CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ANY (at least one criteria has to satisy ). + * @return criteria linkage + * @see setCriteriaLinkage + * @see linkage + */ + int getCriteriaLinkage() const; + + /** + * Sets the criteria list. + * @param list criteria list + * @see criteriaList + * @see getCriteriaList + * @see Types::FilterCriteriaList_Type + */ + void setCriteriaList( FilterCriteriaList_Type list ); + + /** + * Returns the criteria list. + * @return criteria list + * @see criteriaList + * @see setCriteriaList + * @see Types::FilterCriteriaList_Type + */ + FilterCriteriaList_Type getCriteriaList() const; + + /** + * Saves the settings to the configuration file. + * The group is named CONFIG_GROUP_FILTER + filter number, e.g. Filter12. + */ + void save(); + + /** + * Reimplemantation of QListViewItem::compare. + * Compares this list view item to i using the column col in ascending order. Reutrns <0 if this item is less than i, + * 0 if they are equal and >0 if this item is greater than i. The parameter ascneding will be ignored. + * @param i pointer to the second view item + * @param col number of the sorted column + * @param ascending ignored + */ + virtual int compare( QListViewItem* i, int col, bool ascending ) const; + + /** + * Reads the settings from the config file. + * The group is named CONFIG_GROUP_FILTER + filter number, e.g. Filter12. + */ + void load(); + + + private: + + /** + * filter name + */ + QString name; + + /** + * Connector to the configuration file + */ + KConfig* config; + + /** + * List of filter criterias. + */ + FilterCriteriaList_Type criteriaList; + + /** + * Filter Action + * See constants.h for valid values (CONFIG_VALUE_FILTER_ACTION...). + */ + int action; + + /** + * Contains the mailbox name if the move action is selected. + */ + QString mailbox; + + /** + * Filter Number. + * The filters will be showed and run through in ascending order. The first number is "0". + */ + uint number; + + /** + * Criteria Linkage. + * Valid values are CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ALL (all criterias have to satisy) or CONFIG_VALUE_FILTER_CRITERIA_LINKAGE_MATCH_ANY (at least one criteria has to satisy ). + */ + int linkage; + + protected: + + /** + * Initializes the object. + */ + void init(); + + /** + * Updates the text of the rule column. + */ + void updateActionColumn(); + + + + +}; + +#endif diff --git a/kshowmail/kcmconfigs/kshowmailconfigaccounts.desktop b/kshowmail/kcmconfigs/kshowmailconfigaccounts.desktop new file mode 100644 index 0000000..e8da1f9 --- /dev/null +++ b/kshowmail/kcmconfigs/kshowmailconfigaccounts.desktop @@ -0,0 +1,20 @@ +[Desktop Entry] +Encoding=UTF-8 +Type=Service +Name=Accounts +Name[de]=Konten +Name[es]=Cuentas +Comment=Accounts +Comment[de]=Konten +Comment[es]=Cuentas +Icon=network +ServiceTypes=KCModule + +X-KDE-ModuleType=Library +X-KDE-Library=kshowmailconfigaccounts +X-KDE-CfgDlgHierarchy= +X-KDE-FactoryName=kshowmailconfigaccounts +X-KDE-IsHiddenByDefault= +X-KDE-RootOnly= +X-KDE-Weight=5 +X-KDE-ParentApp=kshowmail diff --git a/kshowmail/kcmconfigs/kshowmailconfigactions.desktop b/kshowmail/kcmconfigs/kshowmailconfigactions.desktop new file mode 100644 index 0000000..a925df8 --- /dev/null +++ b/kshowmail/kcmconfigs/kshowmailconfigactions.desktop @@ -0,0 +1,20 @@ +[Desktop Entry] +Encoding=UTF-8 +Type=Service +Name=Actions +Name[de]=Aktionen +Name[es]=Acciones +Comment=actions +Comment[de]=Aktionen +Comment[es]=Acciones +Icon=launch +ServiceTypes=KCModule + +X-KDE-ModuleType=Library +X-KDE-Library=kshowmailconfigactions +X-KDE-CfgDlgHierarchy= +X-KDE-FactoryName=kshowmailconfigactions +X-KDE-IsHiddenByDefault= +X-KDE-RootOnly= +X-KDE-Weight=2 +X-KDE-ParentApp=kshowmail diff --git a/kshowmail/kcmconfigs/kshowmailconfigdisplay.desktop b/kshowmail/kcmconfigs/kshowmailconfigdisplay.desktop new file mode 100644 index 0000000..ac5e02b --- /dev/null +++ b/kshowmail/kcmconfigs/kshowmailconfigdisplay.desktop @@ -0,0 +1,19 @@ +[Desktop Entry] +Encoding=UTF-8 +Type=Service +Name=Display +Name[de]=Erscheinungsbild +Name[es]=Visualización +Comment=Display Options +Comment[de]=Erscheinungsbild +Comment[es]=Opciones de visualización +Icon=looknfeel +ServiceTypes=KCModule +X-KDE-ModuleType=Library +X-KDE-Library=kshowmailconfigdisplay +X-KDE-CfgDlgHierarchy= +X-KDE-FactoryName=kshowmailconfigdisplay +X-KDE-IsHiddenByDefault= +X-KDE-RootOnly= +X-KDE-Weight=3 +X-KDE-ParentApp=kshowmail
\ No newline at end of file diff --git a/kshowmail/kcmconfigs/kshowmailconfigfilter.desktop b/kshowmail/kcmconfigs/kshowmailconfigfilter.desktop new file mode 100644 index 0000000..cd6b801 --- /dev/null +++ b/kshowmail/kcmconfigs/kshowmailconfigfilter.desktop @@ -0,0 +1,19 @@ +[Desktop Entry] +Type=Service +Name=Filter +Name[de]=Filter +Name[es]=Filtro +Comment=Filter +Comment[de]=Filter +Comment[es]=Filtro +Icon=filter +ServiceTypes=KCModule + +X-KDE-ModuleType=Library +X-KDE-Library=kshowmailconfigfilter +X-KDE-CfgDlgHierarchy= +X-KDE-FactoryName=kshowmailconfigfilter +X-KDE-IsHiddenByDefault= +X-KDE-RootOnly= +X-KDE-Weight=6 +X-KDE-ParentApp=kshowmail diff --git a/kshowmail/kcmconfigs/kshowmailconfiggeneral.desktop b/kshowmail/kcmconfigs/kshowmailconfiggeneral.desktop new file mode 100644 index 0000000..1f4db6d --- /dev/null +++ b/kshowmail/kcmconfigs/kshowmailconfiggeneral.desktop @@ -0,0 +1,19 @@ +[Desktop Entry] +Encoding=UTF-8 +Type=Service +Name=General +Name[de]=Allgemeines +Name[es]=General +Comment=General Options +Comment[de]=Allgemeine Einstellungen +Comment[es]=Opciones generales +Icon=exec +ServiceTypes=KCModule +X-KDE-ModuleType=Library +X-KDE-Library=kshowmailconfiggeneral +X-KDE-CfgDlgHierarchy= +X-KDE-FactoryName=kshowmailconfiggeneral +X-KDE-IsHiddenByDefault= +X-KDE-RootOnly= +X-KDE-Weight=4 +X-KDE-ParentApp=kshowmail
\ No newline at end of file diff --git a/kshowmail/kcmconfigs/kshowmailconfiglog.desktop b/kshowmail/kcmconfigs/kshowmailconfiglog.desktop new file mode 100644 index 0000000..4a5dc5f --- /dev/null +++ b/kshowmail/kcmconfigs/kshowmailconfiglog.desktop @@ -0,0 +1,16 @@ +[Desktop Entry] +Encoding=UTF-8 +Type=Service +Name=Log +Name[de]=Log +Name[es]=Registro +Comment=Log +Comment[de]=Log +Comment[es]=Registro +Icon=kedit +ServiceTypes=KCModule +X-KDE-ModuleType=Library +X-KDE-Library=kshowmailconfiglog +X-KDE-FactoryName=kshowmailconfiglog +X-KDE-Weight=7 +X-KDE-ParentApp=kshowmail diff --git a/kshowmail/kcmconfigs/kshowmailconfigspamcheck.desktop b/kshowmail/kcmconfigs/kshowmailconfigspamcheck.desktop new file mode 100644 index 0000000..5f6cb3b --- /dev/null +++ b/kshowmail/kcmconfigs/kshowmailconfigspamcheck.desktop @@ -0,0 +1,20 @@ +[Desktop Entry] +Type=Service +Name=Spam Checking +Name[de]=Spam-Prüfung +Name[es]=Análisis de spam +Comment=Checking for Spam +Comment[de]=Prüfung auf Spam +Comment[es]=Analizar el spam +Icon=kfind +ServiceTypes=KCModule + +X-KDE-ModuleType=Library +X-KDE-Library=kshowmailconfigspamcheck +X-KDE-CfgDlgHierarchy= +X-KDE-FactoryName=kshowmailconfigspamcheck +X-KDE-IsHiddenByDefault= +X-KDE-RootOnly= +X-KDE-Weight=6 +X-KDE-ParentApp=kshowmail + diff --git a/kshowmail/kcmconfigs/kwalletaccess.cpp b/kshowmail/kcmconfigs/kwalletaccess.cpp new file mode 100644 index 0000000..20dccc6 --- /dev/null +++ b/kshowmail/kcmconfigs/kwalletaccess.cpp @@ -0,0 +1,137 @@ +// +// C++ Implementation: kwalletaccess +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "kwalletaccess.h" + + +bool KWalletAccess::savePassword( const QString & account, const QString & password ) +{ + //check for enabled KWallet + if( !KWallet::Wallet::isEnabled() ) + { + KMessageBox::error( NULL, i18n( "KWallet is not available." ) ); + return false; + } + + //get wallet name for network data + QString name = KWallet::Wallet::NetworkWallet(); + if( name == "" || name == QString::null ) + { + KMessageBox::error( NULL, i18n( "Could not get wallet name for network datas from KWallet." ) ); + return false; + } + + //open wallet + //we want to create a connection object just at first call of this function + static KWallet::Wallet* wallet; + + if( wallet == NULL ) + { + wallet = KWallet::Wallet::openWallet( name ); + } + else if( !wallet->isOpen() ) + { + delete wallet; + wallet = KWallet::Wallet::openWallet( name ); + } + + if( wallet == NULL ) + { + KMessageBox::error( NULL, i18n( "Could not open KWallet." ) ); + return false; + } + + //create kshowmail folder if it does not exist + if( !wallet->hasFolder( "KShowmail" ) ) + { + bool createFolderSuccess = wallet->createFolder( "KShowmail" ); + + if( !createFolderSuccess ) + { + KMessageBox::error( NULL, i18n( "Could not create folder for KShowmail in KWallet." ) ); + return false; + } + } + + //set folder + bool setFolderSuccess = wallet->setFolder( "KShowmail" ); + if( !setFolderSuccess ) + { + KMessageBox::error( NULL, i18n( "Could not open folder for KShowmail in KWallet." ) ); + return false; + } + + //write password + int writePasswordSuccess = wallet->writePassword( account, password ); + if( writePasswordSuccess != 0 ) + { + KMessageBox::error( NULL, i18n( "Could not save password in KWallet." ) ); + return false; + } + + + return true; +} + +QString KWalletAccess::getPassword( const QString & account ) +{ + //check for enabled KWallet + if( !KWallet::Wallet::isEnabled() ) + { + KMessageBox::error( NULL, i18n( "KWallet is not available." ) ); + return QString::null; + } + + //get wallet name for network data + QString name = KWallet::Wallet::NetworkWallet(); + if( name == "" || name == QString::null ) + { + KMessageBox::error( NULL, i18n( "Could not get wallet name for network datas from KWallet." ) ); + return QString::null; + } + + //open wallet + //we want to create a connection object just at first call of this function + static KWallet::Wallet* wallet; + + if( wallet == NULL ) + { + wallet = KWallet::Wallet::openWallet( name ); + } + else if( !wallet->isOpen() ) + { + delete wallet; + wallet = KWallet::Wallet::openWallet( name ); + } + + if( wallet == NULL ) + { + KMessageBox::error( NULL, i18n( "Could not open KWallet." ) ); + return QString::null; + } + + //set folder + bool setFolderSuccess = wallet->setFolder( "KShowmail" ); + if( !setFolderSuccess ) + { + KMessageBox::error( NULL, i18n( "Could not open folder for KShowmail in KWallet." ) ); + return QString::null; + } + + //read password + QString password; + + int readPasswordSuccess = wallet->readPassword( account, password ); + if( readPasswordSuccess != 0 ) + { + KMessageBox::error( NULL, i18n( "Could not get password of account %1 from KWallet." ).arg( account) ); + return QString::null; + } + + return password; +} diff --git a/kshowmail/kcmconfigs/kwalletaccess.h b/kshowmail/kcmconfigs/kwalletaccess.h new file mode 100644 index 0000000..8e9c537 --- /dev/null +++ b/kshowmail/kcmconfigs/kwalletaccess.h @@ -0,0 +1,45 @@ +// +// C++ Interface: kwalletaccess +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef KWALLETACCESS_H +#define KWALLETACCESS_H + +//Qt headers +#include <qstring.h> + +//KDE headers +#include <kwallet.h> +#include <kmessagebox.h> +#include <kdebug.h> +#include <klocale.h> + +/** + * @brief Provides routines to save and read passwords using KWallet. + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +namespace KWalletAccess +{ + + /** + * Saves the given password into KWallet. + * @param account account name + * @param password the password + * @return TRUE - password successfully saved + * @return FALSE - password could not be saved + */ + bool savePassword( const QString& account, const QString& password ); + + /** + * Returns the password of the given account. + * @param account account name + * @return the password or QString::null, if the sought password is not stored in KWallet. + */ + QString getPassword( const QString& account ); +} + +#endif diff --git a/kshowmail/kcmconfigs/mailboxwizard.cpp b/kshowmail/kcmconfigs/mailboxwizard.cpp new file mode 100644 index 0000000..d6ab904 --- /dev/null +++ b/kshowmail/kcmconfigs/mailboxwizard.cpp @@ -0,0 +1,164 @@ +// +// C++ Implementation: mailboxwizard +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2008 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "mailboxwizard.h" + +MailBoxWizard::MailBoxWizard( QWidget* parent, const char* name ) + : QWizard( parent, name, true ) +{ + + //this is page one + //in this the user can chosse his mail directory + //---------------------------------------------- + QWidget* page1 = new QWidget( this, "page1" ); + QHBoxLayout* layMain1 = new QHBoxLayout( page1, 0, 10 ); + + txtMailDir = new KLineEdit( page1, "txtMailDir" ); + layMain1->addWidget( txtMailDir ); + + btnMailDir = new KPushButton( KGuiItem( QString(), QString( "folder" ), i18n( "Press to choose the mail directory" ), i18n( "Press to choose the mail directory" ) ), page1, "btnMailDir" ); + btnMailDir->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); + layMain1->addWidget( btnMailDir ); + connect( btnMailDir, SIGNAL( clicked() ), this, SLOT( slotOpenDirDialog() ) ); + + title1 = i18n( "Please choose the path to the mailboxes.\nKShowmail supports only MailDir boxes." ); + addPage( page1, title1 ); + + + //this is page two + //in this the user can choose the mailbox + //--------------------------------------- + QWidget* page2 = new QWidget( this, "page2" ); + QHBoxLayout* layMain2 = new QHBoxLayout( page2, 0, 10 ); + + lstMailboxes = new KListView( page2, "lstMailboxes" ); + lstMailboxes->addColumn( "Mailbox" ); + lstMailboxes->setRootIsDecorated( true ); + layMain2->addWidget( lstMailboxes ); + + title2 = i18n( "Please choose the mailbox" ); + addPage( page2, title2 ); + setFinishEnabled( page2, true ); + + connect( this, SIGNAL( selected( const QString& ) ), this, SLOT( slotPageChanged( const QString& ) ) ); +} + + +MailBoxWizard::~MailBoxWizard() +{ +} + +void MailBoxWizard::slotOpenDirDialog( ) +{ + //save old path + QString oldPath = txtMailDir->text(); + + //get new path + QString path = KFileDialog::getExistingDirectory( oldPath, this, i18n( "Choose the mailbox directory") ); + + //put new or old path in the edit line + if( path == QString::null ) + txtMailDir->setText( oldPath ); + else + txtMailDir->setText( path ); +} + +void MailBoxWizard::slotPageChanged( const QString& pageTitle ) +{ + //just we looking for mailboxes if the page 2 was opened + if( pageTitle == title2 ) + { + //clear all entries + lstMailboxes->clear(); + + //create an directory object to browse the given directory + QDir mailDir( txtMailDir->text() ); + if( mailDir.isReadable() ) //is the dir readable? + { + //get a list of all entries in this directory + const QStringList entries = mailDir.entryList( QDir::Dirs | QDir::Readable | QDir::Writable | QDir::Hidden, QDir::Name | QDir::IgnoreCase | QDir::LocaleAware ); + + for( QStringList::const_iterator it = entries.begin(); it != entries.end(); ++it ) + { + //add an entry to the mailbox list + QDir newMailDir( mailDir ); + newMailDir.cd( (*it) ); + if( (*it) != ".." && (*it) != "." && isMailDir( newMailDir ) ) + addMailBoxListItem( *it, mailDir ); + } + } + } + +} + +bool MailBoxWizard::isMailDir( const QDir & path ) +{ + //get a list of all subdirectories in this directory + const QStringList entries = path.entryList( QDir::Dirs | QDir::Readable | QDir::Writable | QDir::Hidden, QDir::Name | QDir::IgnoreCase | QDir::LocaleAware ); + + //a maildir folder must contains the folders "cur", "new" and "tmp" + bool curFound = false; + bool newFound = false; + bool tmpFound = false; + + //iterate over all directories and look for the three necessary dirs + QStringList::const_iterator it = entries.begin(); + while( it != entries.end() && !( curFound && newFound && tmpFound ) ) + { + if( *it == "tmp" ) + tmpFound = true; + else if( *it == "cur" ) + curFound = true; + else if( *it == "new" ) + newFound = true; + + ++it; + } + + return curFound && newFound && tmpFound; +} + +void MailBoxWizard::addMailBoxListItem( QString boxname, QDir path ) +{ + //translate some default mailboxes + QString boxnameTrans; + if( boxname.lower() == "inbox" ) + boxnameTrans = i18n( "Inbox" ); + else if( boxname.lower() == "outbox" ) + boxnameTrans = i18n( "Outbox" ); + else if( boxname.lower() == "drafts" ) + boxnameTrans = i18n( "Drafts" ); + else if( boxname.lower() == "sent-mail" ) + boxnameTrans = i18n( "sent-mail" ); + else if( boxname.lower() == "trash" ) + boxnameTrans = i18n( "Trash" ); + else + boxnameTrans = boxname; + + //create item + MailBoxWizardListItem* newItem; + newItem = new MailBoxWizardListItem( lstMailboxes, boxnameTrans, path.absPath() + "/" + boxname + "/" ); + + +} + +QString MailBoxWizard::getPath( ) +{ + MailBoxWizardListItem* item = (MailBoxWizardListItem*)lstMailboxes->selectedItem(); + + QString path = QString::null; + if( item != NULL ) + path = item->getPath(); + + return path; +} + +#include "mailboxwizard.moc" diff --git a/kshowmail/kcmconfigs/mailboxwizard.h b/kshowmail/kcmconfigs/mailboxwizard.h new file mode 100644 index 0000000..2c32b7a --- /dev/null +++ b/kshowmail/kcmconfigs/mailboxwizard.h @@ -0,0 +1,131 @@ +// +// C++ Interface: mailboxwizard +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2008 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef MAILBOXWIZARD_H +#define MAILBOXWIZARD_H + +//C-headers +#include <stdlib.h> + +//Qt headers +#include <qwizard.h> +#include <qwidget.h> +#include <qlayout.h> +#include <qdir.h> +#include <qregexp.h> +#include <qfileinfo.h> +#include <qmap.h> + +//KDE headers +#include <klocale.h> +#include <klineedit.h> +#include <kpushbutton.h> +#include <kfiledialog.h> +#include <klistview.h> +#include <kstandarddirs.h> +#include <kconfig.h> +#include <kdebug.h> + +//Kshowmail headers +#include "../constants.h" +#include "mailboxwizardlistitem.h" + +/** + * Wizard to configure the mailbox to which a filteres mail shall be moved. + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +class MailBoxWizard : public QWizard +{ + + Q_OBJECT + + public: + + /** + * Constructor + */ + MailBoxWizard( QWidget* parent = 0, const char* name = 0 ); + + /** + * Destructor + */ + ~MailBoxWizard(); + + /** + * Returns the absolute path of the selected mailbox. + * @return the path + */ + QString getPath(); + + private: + + /** + * This contains the path to the mail directory + */ + KLineEdit* txtMailDir; + + /** + * This button opens a file dialog to slecht the mail directory + */ + KPushButton* btnMailDir; + + /** + * This view shows the available mailboxes in the selected directory + */ + KListView* lstMailboxes; + + /** + * Title of page 1. + * Set by constructor + */ + QString title1; + + /** + * Title of page 2. + * Set by Constructor. + */ + QString title2; + + /** + * Returns whether the given directory is a maildir directory + * @param path the directory for test + * @return TRUE - directory is a maildir directory + */ + bool isMailDir( const QDir& path ); + + /** + * Adds a new mailbox list view item to the mailbox list or to a given parent item. + * @param boxname name of the mailbox + * @param path path to the directory of this mailbox + */ + void addMailBoxListItem( QString boxname, QDir path ); + + + + private slots: + + /** + * Connected with btnMailDir. + * Opens a file dialog to choose the mail directory. + */ + void slotOpenDirDialog(); + + /** + * Connected with the signal selected of this wizard. + * Searchs for mailboxes inside the path typed in page1. + * @param pageTitle title of the selected page + */ + void slotPageChanged( const QString& pageTitle ); + + +}; + +#endif diff --git a/kshowmail/kcmconfigs/mailboxwizardlistitem.cpp b/kshowmail/kcmconfigs/mailboxwizardlistitem.cpp new file mode 100644 index 0000000..4afdc2a --- /dev/null +++ b/kshowmail/kcmconfigs/mailboxwizardlistitem.cpp @@ -0,0 +1,28 @@ +// +// C++ Implementation: mailboxwizardlistitem +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2008 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "mailboxwizardlistitem.h" + +MailBoxWizardListItem::~MailBoxWizardListItem() +{ +} + +MailBoxWizardListItem::MailBoxWizardListItem( QListView* parent, QString label, QString path ) + : KListViewItem( parent, label ) +{ + this->path = path; +} + +QString MailBoxWizardListItem::getPath( ) +{ + return path; +} + diff --git a/kshowmail/kcmconfigs/mailboxwizardlistitem.h b/kshowmail/kcmconfigs/mailboxwizardlistitem.h new file mode 100644 index 0000000..603a9c8 --- /dev/null +++ b/kshowmail/kcmconfigs/mailboxwizardlistitem.h @@ -0,0 +1,61 @@ +// +// C++ Interface: mailboxwizardlistitem +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2008 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef MAILBOXWIZARDLISTITEM_H +#define MAILBOXWIZARDLISTITEM_H + +//Qt-Headers +#include <qlistview.h> + +//KDE-Headers +#include <klistview.h> + +/** + * This is a list item in the mailbox list of the mailbox wizard + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +class MailBoxWizardListItem : public KListViewItem +{ + + public: + + /** + * Constructor + * Constructs a new top-level entry in the mailbox list. + * @param parent pointer to mailbox list. + * @param label column content + * @param path the absolute path to this mailbox + */ + MailBoxWizardListItem( QListView* parent, QString label, QString path ); + + /** + * Destructor + */ + ~MailBoxWizardListItem(); + + /** + * Returns the path to this mailbox. + * @return path to this mailbox + */ + QString getPath(); + + private: + + /** + * The path to this mailbox + */ + QString path; + + + +}; + +#endif diff --git a/kshowmail/kcmconfigs/senderlistdialog.cpp b/kshowmail/kcmconfigs/senderlistdialog.cpp new file mode 100644 index 0000000..c30804c --- /dev/null +++ b/kshowmail/kcmconfigs/senderlistdialog.cpp @@ -0,0 +1,151 @@ +// +// C++ Implementation: senderlistdialog +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "senderlistdialog.h" + +SenderListDialog::SenderListDialog(QWidget *parent, ListType list, const char *name) + : KDialogBase( parent, name, true, QString::null, Ok|Cancel, Ok, true ) +{ + //save list type + this->list = list; + + //get application config object (kshowmailrc) + config = KApplication::kApplication()->config(); + + //set caption + if( list == White ) + setCaption( "Whitelist" ); + else + setCaption( "Blacklist" ); + + //build GUI + //--------- + + //main widget and layout + QWidget* wdgMain = new QWidget( this ); + setMainWidget( wdgMain ); + QVBoxLayout* layMain = new QVBoxLayout( wdgMain, 0, spacingHint() ); + + //edit frame + editFrame = new KEditListBox( wdgMain, "editFrame", true, KEditListBox::Add | KEditListBox::Remove ); + editFrame->setTitle( i18n( "List" ) ); + if( list == White ) + QToolTip::add( editFrame->listBox(), i18n( "A mail whose sender is listed here will pass the filter.\nA mail will be accepted, if its From line incloses a list entry.\nE.g. a line of\n\"Ulrich Weigelt\" <ulrich.weigelt@gmx.de> is accepted by the entries\nUlrich Weigelt\nulrich.weigelt@gmx.de\n\"Ulrich Weigelt\" <ulrich.weigelt@gmx.de>" ) ); + else + QToolTip::add( editFrame->listBox(), i18n( "A mail whose sender is listed here will be hold up by the filter.\nA mail will be stopped, if its From line incloses a list entry.\nE.g. a line of\n\"Ulrich Weigelt\" <ulrich.weigelt@gmx.de> is filtered by the entries\nUlrich Weigelt\nulrich.weigelt@gmx.de\n\"Ulrich Weigelt\" <ulrich.weigelt@gmx.de>" ) ); + + layMain->addWidget( editFrame ); + + connect( editFrame->addButton(), SIGNAL( clicked() ), this, SLOT( slotSort() ) ); + connect( editFrame->lineEdit(), SIGNAL( returnPressed( const QString & ) ), this, SLOT( slotSort() ) ); + + //this radio buttons we just need in the blacklist + if( list == Black ) + { + QGroupBox* gboxAction = new QGroupBox( 0, Qt::Horizontal, i18n( "Action" ), wdgMain, "gboxAction" ); + QHBoxLayout* layAction = new QHBoxLayout( gboxAction->layout(), 10 ); + layMain->addWidget( gboxAction ); + + grpAction = new QButtonGroup( NULL, "grpAction" ); + QRadioButton* btnDelete = new QRadioButton( i18n( "Delete"), gboxAction, "btnDelete" ); + QRadioButton* btnMark = new QRadioButton( i18n( "Mark" ), gboxAction, "btnMark" ); + + grpAction->insert( btnDelete, ID_BUTTON_FILTER_SENDERLIST_DELETE ); + grpAction->insert( btnMark, ID_BUTTON_FILTER_SENDERLIST_MARK ); + + QToolTip::add( btnDelete, i18n( "The mails will be deleted." ) ); + QToolTip::add( btnMark, i18n( "The mails will be marked." ) ); + + layAction->addWidget( btnDelete ); + layAction->addWidget( btnMark ); + + //set default + switch( DEFAULT_FILTER_BLACKLIST_ACTION ) + { + case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_DELETE : grpAction->setButton( ID_BUTTON_FILTER_SENDERLIST_DELETE ); break; + case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_MARK : grpAction->setButton( ID_BUTTON_FILTER_SENDERLIST_MARK ); break; + default : grpAction->setButton( ID_BUTTON_FILTER_SENDERLIST_DELETE ); break; + } + } + //set size + setGeometry( 50, 50, (int)( this->width() / 2 ), this->height() ); + + //get values + fillDialog(); +} + + +SenderListDialog::~SenderListDialog() +{ +} + +void SenderListDialog::slotSort( ) +{ + editFrame->listBox()->sort(); +} + +void SenderListDialog::slotOk( ) +{ + //set config group + config->setGroup( CONFIG_GROUP_FILTER ); + + //save the list of senders + if( list == Black ) + config->writeEntry( CONFIG_ENTRY_FILTER_BLACKLIST, editFrame->items() ); + else + config->writeEntry( CONFIG_ENTRY_FILTER_WHITELIST, editFrame->items() ); + + //save blacklist action + if( list == Black ) + { + int action = grpAction->selectedId(); + if( action != ID_BUTTON_FILTER_SENDERLIST_DELETE && action != ID_BUTTON_FILTER_SENDERLIST_MARK ) + action = DEFAULT_FILTER_BLACKLIST_ACTION; + + switch( action ) + { + case ID_BUTTON_FILTER_SENDERLIST_DELETE : config->writeEntry( CONFIG_ENTRY_FILTER_BLACKLIST_ACTION, CONFIG_VALUE_FILTER_BLACKLIST_ACTION_DELETE ); break; + case ID_BUTTON_FILTER_SENDERLIST_MARK : config->writeEntry( CONFIG_ENTRY_FILTER_BLACKLIST_ACTION, CONFIG_VALUE_FILTER_BLACKLIST_ACTION_MARK ); break; + default : config->writeEntry( CONFIG_ENTRY_FILTER_BLACKLIST_ACTION, CONFIG_VALUE_FILTER_BLACKLIST_ACTION_DELETE ); break; + } + } + + config->sync(); + + //call slot of super class to close the dialog + KDialogBase::slotOk(); +} + +void SenderListDialog::fillDialog( ) +{ + //set config group + config->setGroup( CONFIG_GROUP_FILTER ); + + //get list of senders + if( list == Black ) + editFrame->setItems( config->readListEntry( CONFIG_ENTRY_FILTER_BLACKLIST ) ); + else + editFrame->setItems( config->readListEntry( CONFIG_ENTRY_FILTER_WHITELIST ) ); + + //get blacklist action + if( list == Black ) + { + switch( config->readNumEntry( CONFIG_ENTRY_FILTER_BLACKLIST_ACTION, DEFAULT_FILTER_BLACKLIST_ACTION ) ) + { + case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_DELETE : grpAction->setButton( ID_BUTTON_FILTER_SENDERLIST_DELETE ); break; + case CONFIG_VALUE_FILTER_BLACKLIST_ACTION_MARK : grpAction->setButton( ID_BUTTON_FILTER_SENDERLIST_MARK ); break; + default : grpAction->setButton( ID_BUTTON_FILTER_SENDERLIST_DELETE ); break; + } + } +} + + +#include "senderlistdialog.moc" diff --git a/kshowmail/kcmconfigs/senderlistdialog.h b/kshowmail/kcmconfigs/senderlistdialog.h new file mode 100644 index 0000000..eeb0661 --- /dev/null +++ b/kshowmail/kcmconfigs/senderlistdialog.h @@ -0,0 +1,112 @@ +// +// C++ Interface: senderlistdialog +// +// Description: +// +// +// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef SENDERLISTDIALOG_H +#define SENDERLISTDIALOG_H + +//Qt headers +#include <qlayout.h> +#include <qtooltip.h> +#include <qradiobutton.h> +#include <qbuttongroup.h> +#include <qpushbutton.h> + +//KDE headers +#include <kdialogbase.h> +#include <kapplication.h> +#include <keditlistbox.h> +#include <klocale.h> +#include <klineedit.h> +#include <kconfig.h> + +//KShowmail headers +#include "../constants.h" + +//Button IDs +#define ID_BUTTON_FILTER_SENDERLIST_DELETE 1 +#define ID_BUTTON_FILTER_SENDERLIST_MARK 2 + +/** + * @brief This is a dialog to edit the blacklist and whitelist. It is used by the class ConfigFilter. + * @author Ulrich Weigelt <ulrich.weigelt@gmx.de> + */ +class SenderListDialog : public KDialogBase +{ + + Q_OBJECT + + public: + + /** + * Type of list. + */ + enum ListType { Black, White }; + + /** + * Constructor + * @param parent parent widget + * @param list list which shall be opened + * @param name widget name + */ + SenderListDialog( QWidget *parent = 0, ListType list = Black, const char *name = 0 ); + + /** + * Destructor + */ + ~SenderListDialog(); + + private: + + /** + * list which shall be opened + */ + ListType list; + + /** + * Application Config Object + */ + KConfig* config; + + /** + * Edit Frame + */ + KEditListBox* editFrame; + + /** + * Combines the action radio buttons for the blacklist. + */ + QButtonGroup* grpAction; + + /** + * Reads the entries for the dialog from the config file fill them in it. + */ + void fillDialog(); + + private slots: + + /** + * Connected with add button of the edit frame. + * Sorts the content of the list box. + */ + void slotSort(); + + /** + * Overwritten method of KDialogBase. + * Called if OK was clicked. + * Stores the entered values. + * After then it invokes slotOk() of KDialogBase. + */ + void slotOk(); + + +}; + +#endif |