00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "configactions.h"
00019
00020 K_PLUGIN_FACTORY( ConfigActionsFactory, registerPlugin<ConfigActions>(); )
00021 K_EXPORT_PLUGIN( ConfigActionsFactory( "kcm_kshowmailconfigactions" ) )
00022
00023 ConfigActions::ConfigActions( QWidget * parent, const QVariantList & args )
00024 : KCModule( ConfigActionsFactory::componentData(), parent, args )
00025 {
00026
00027
00028
00029
00030 QVBoxLayout* layMain = new QVBoxLayout( this );
00031
00032
00033 QGroupBox* gboxNewMails = new QGroupBox( i18nc( "@title:group", "Action if new &mail" ), this );
00034 QGroupBox* gboxNoNewMails = new QGroupBox( i18nc( "@title:group", "Action if &no mail" ), this );
00035 layMain->addWidget( gboxNewMails );
00036 layMain->addWidget( gboxNoNewMails );
00037
00038
00039 QVBoxLayout* layMainNewMails = new QVBoxLayout();
00040 QGridLayout* layMainNewMailsTop = new QGridLayout();
00041 QGridLayout* layMainNewMailsDown = new QGridLayout();
00042 layMainNewMails->addLayout( layMainNewMailsTop );
00043 layMainNewMails->addLayout( layMainNewMailsDown );
00044 gboxNewMails->setLayout( layMainNewMails );
00045
00046
00047 QVBoxLayout* layMainNoNewMails = new QVBoxLayout();
00048 gboxNoNewMails->setLayout( layMainNoNewMails );
00049
00050
00051
00052 chkNewMailsAlertWindow = new QCheckBox( i18nc( "@option:check show message box if new mail", "Show message box" ), gboxNewMails );
00053 chkNewMailsAlertWindow->setToolTip( i18nc( "@info:tooltip", "Show message if new mail arrives" ) );
00054 layMainNewMailsTop->addWidget( chkNewMailsAlertWindow, 0, 0 );
00055
00056 chkNewMailsMainWindow = new QCheckBox( i18nc( "@option:check show main window if new mail", "Show main window" ), gboxNewMails );
00057 chkNewMailsMainWindow->setToolTip( i18nc( "@info:tooltip", "Show main window if new mail arrives" ) );
00058 layMainNewMailsTop->addWidget( chkNewMailsMainWindow, 0, 1 );
00059
00060 chkNewMailsBeep = new QCheckBox( i18nc( "@option:check beep if new mail", "Beep" ), gboxNewMails );
00061 chkNewMailsBeep->setToolTip( i18nc( "@info:tooltip", "Beeps the internal speaker if new mail" ) );
00062 layMainNewMailsTop->addWidget( chkNewMailsBeep, 1, 0 );
00063
00064 chkNewMailsSound = new QCheckBox( i18nc( "@option:check play sound if new mail", "Sound:" ), gboxNewMails );
00065 chkNewMailsSound->setToolTip( i18nc( "@info:tooltip", "Play sound if new mail" ) );
00066 layMainNewMailsDown->addWidget( chkNewMailsSound, 0, 0 );
00067
00068 btnNewMailsPlaySound = new KPushButton( KGuiItem( QString(), QString( "media-playback-start" ), i18nc( "@info:tooltip", "Play the selected sound file" ), i18nc( "@info:whatsthis", """Play the selected sound file" ) ), gboxNewMails );
00069 layMainNewMailsDown->addWidget( btnNewMailsPlaySound, 0, 1 );
00070
00071 txtNewMailsSound = new KLineEdit( gboxNewMails );
00072 layMainNewMailsDown->addWidget( txtNewMailsSound, 0, 2 );
00073
00074 btnNewMailsChooseSound = new KPushButton( KGuiItem( QString(), QString( "folder" ), i18nc( "@info:tooltip", "Press to select sound file" ), i18nc( "@info:whatsthis", "Press to select sound file" ) ), gboxNewMails );
00075 layMainNewMailsDown->addWidget( btnNewMailsChooseSound, 0, 3 );
00076
00077 chkNewMailsCommand = new QCheckBox( i18nc( "@option:check execute this command if new mail", "Command:" ), gboxNewMails );
00078 chkNewMailsCommand->setToolTip( i18nc( "@info:tooltip", "Starts external program if new mail" ) );
00079 layMainNewMailsDown->addWidget( chkNewMailsCommand, 1, 0 );
00080
00081 btnNewMailsExecCommand = new KPushButton( KGuiItem( QString(), QString( "system-run" ), i18nc( "@info:tooltip", "Start the selected program" ), i18nc( "@info:whatsthis", "Start the selected program" ) ), gboxNewMails );
00082 layMainNewMailsDown->addWidget( btnNewMailsExecCommand, 1, 1 );
00083
00084 txtNewMailsCommand = new KLineEdit( gboxNewMails );
00085 layMainNewMailsDown->addWidget( txtNewMailsCommand, 1, 2 );
00086
00087 btnNewMailsChooseCommand = new KPushButton( KGuiItem( QString(), QString( "folder" ), i18nc( "@info:tooltip", "Select external command" ), i18nc( "@info:whatsthis", "Select external command" ) ), gboxNewMails );
00088 layMainNewMailsDown->addWidget( btnNewMailsChooseCommand, 1, 3 );
00089
00090
00091 chkNoNewMailsMinimize = new QCheckBox( i18nc( "@option:check minimize the main window if no new mails", "Minimi&ze" ), gboxNoNewMails );
00092 chkNoNewMailsMinimize->setToolTip( i18nc( "@info:tooltip", "Minimize window if no new mail" ) );
00093 layMainNoNewMails->addWidget( chkNoNewMailsMinimize );
00094
00095 chkNoNewMailsTerminate = new QCheckBox( i18nc( "@option:check exit the application if no new mails", "Terminate" ), gboxNoNewMails );
00096 chkNoNewMailsTerminate->setToolTip( i18nc( "@info:tooltip", "Terminate kshowmail if no new mail" ) );
00097 layMainNoNewMails->addWidget( chkNoNewMailsTerminate );
00098
00099
00100 connect( btnNewMailsChooseSound, SIGNAL( clicked() ), this, SLOT( slotChooseSound() ) );
00101 connect( btnNewMailsChooseCommand, SIGNAL( clicked() ), this, SLOT( slotChooseCommand() ) );
00102
00103
00104 connect( btnNewMailsPlaySound, SIGNAL( clicked() ), this, SLOT( slotPlaySound() ) );
00105 connect( btnNewMailsExecCommand, SIGNAL( clicked() ), this, SLOT( slotExecuteCommand() ) );
00106
00107
00108 connect( chkNewMailsSound, SIGNAL( toggled( bool ) ), this, SLOT( slotSoundToggled( bool ) ) );
00109 connect( chkNewMailsCommand, SIGNAL( toggled( bool ) ), this, SLOT( slotCommandToggled( bool ) ) );
00110
00111
00112 connect( chkNewMailsAlertWindow, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00113 connect( chkNewMailsMainWindow, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00114 connect( chkNewMailsBeep, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00115 connect( chkNewMailsSound, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00116 connect( chkNewMailsCommand, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00117 connect( txtNewMailsSound, SIGNAL( textChanged( const QString& ) ), this, SLOT( slotChanged() ) );
00118 connect( txtNewMailsCommand, SIGNAL( textChanged( const QString& ) ), this, SLOT( slotChanged() ) );
00119 connect( chkNoNewMailsMinimize, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00120 connect( chkNoNewMailsTerminate, SIGNAL( toggled( bool ) ), this, SLOT( slotChanged() ) );
00121
00122
00123 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
00124
00125
00126 config = KGlobal::config();
00127
00128
00129 load();
00130
00131 }
00132
00133
00134 ConfigActions::~ConfigActions()
00135 {
00136 }
00137
00138 void ConfigActions::load( )
00139 {
00140 KConfigGroup* configAct = new KConfigGroup( config, CONFIG_GROUP_ACTIONS );
00141
00142
00143 chkNewMailsAlertWindow->setChecked( configAct->readEntry( CONFIG_ENTRY_NEW_MAIL_ALERTWINDOW, DEFAULT_ACTION_NEW_MAIL_ALERTWINDOW ) );
00144 chkNewMailsMainWindow->setChecked( configAct->readEntry( CONFIG_ENTRY_NEW_MAIL_MAINWINDOW, DEFAULT_ACTION_NEW_MAIL_MAINWINDOW ) );
00145 chkNewMailsBeep->setChecked( configAct->readEntry( CONFIG_ENTRY_NEW_MAIL_BEEP, DEFAULT_ACTION_NEW_MAIL_BEEP ) );
00146 chkNewMailsSound->setChecked( configAct->readEntry( CONFIG_ENTRY_NEW_MAIL_SOUND, DEFAULT_ACTION_NEW_MAIL_SOUND ) );
00147 chkNewMailsCommand->setChecked( configAct->readEntry( CONFIG_ENTRY_NEW_MAIL_COMMAND, DEFAULT_ACTION_NEW_MAIL_COMMAND ) );
00148 chkNoNewMailsTerminate->setChecked( configAct->readEntry( CONFIG_ENTRY_NO_NEW_MAIL_TERMINATE, DEFAULT_ACTION_NO_NEW_MAIL_TERMINATE ) );
00149 chkNoNewMailsMinimize->setChecked( configAct->readEntry( CONFIG_ENTRY_NO_NEW_MAIL_MINIMIZE, DEFAULT_ACTION_NO_NEW_MAIL_MINIMIZE ) );
00150
00151 txtNewMailsSound->setText( configAct->readEntry( CONFIG_ENTRY_NEW_MAIL_SOUNDPATH ) );
00152 txtNewMailsCommand->setText( configAct->readEntry( CONFIG_ENTRY_NEW_MAIL_COMMANDPATH ) );
00153
00154
00155 slotSoundToggled( chkNewMailsSound->isChecked() );
00156 slotCommandToggled( chkNewMailsCommand->isChecked() );
00157 }
00158
00159 void ConfigActions::defaults( )
00160 {
00161 chkNewMailsAlertWindow->setChecked( DEFAULT_ACTION_NEW_MAIL_ALERTWINDOW );
00162 chkNewMailsMainWindow->setChecked( DEFAULT_ACTION_NEW_MAIL_MAINWINDOW );
00163 chkNewMailsBeep->setChecked( DEFAULT_ACTION_NEW_MAIL_BEEP );
00164 chkNewMailsSound->setChecked( DEFAULT_ACTION_NEW_MAIL_SOUND );
00165 chkNewMailsCommand->setChecked( DEFAULT_ACTION_NEW_MAIL_COMMAND );
00166 chkNoNewMailsTerminate->setChecked( DEFAULT_ACTION_NO_NEW_MAIL_TERMINATE );
00167 chkNoNewMailsMinimize->setChecked( DEFAULT_ACTION_NO_NEW_MAIL_MINIMIZE );
00168
00169
00170 slotSoundToggled( chkNewMailsSound->isChecked() );
00171 slotCommandToggled( chkNewMailsCommand->isChecked() );
00172 }
00173
00174 void ConfigActions::save( )
00175 {
00176 KConfigGroup* configAct = new KConfigGroup( config, CONFIG_GROUP_ACTIONS );
00177
00178 configAct->writeEntry( CONFIG_ENTRY_NEW_MAIL_ALERTWINDOW, chkNewMailsAlertWindow->isChecked() );
00179 configAct->writeEntry( CONFIG_ENTRY_NEW_MAIL_MAINWINDOW, chkNewMailsMainWindow->isChecked() );
00180 configAct->writeEntry( CONFIG_ENTRY_NEW_MAIL_BEEP, chkNewMailsBeep->isChecked() );
00181 configAct->writeEntry( CONFIG_ENTRY_NEW_MAIL_SOUND, chkNewMailsSound->isChecked() );
00182 configAct->writeEntry( CONFIG_ENTRY_NEW_MAIL_SOUNDPATH, txtNewMailsSound->text() );
00183 configAct->writeEntry( CONFIG_ENTRY_NEW_MAIL_COMMAND, chkNewMailsCommand->isChecked() );
00184 configAct->writeEntry( CONFIG_ENTRY_NEW_MAIL_COMMANDPATH, txtNewMailsCommand->text() );
00185 configAct->writeEntry( CONFIG_ENTRY_NO_NEW_MAIL_TERMINATE, chkNoNewMailsTerminate->isChecked() );
00186 configAct->writeEntry( CONFIG_ENTRY_NO_NEW_MAIL_MINIMIZE, chkNoNewMailsMinimize->isChecked() );
00187
00188
00189 config->sync();
00190 }
00191
00192 void ConfigActions::slotChooseSound( )
00193 {
00194 QString startPath;
00195
00196
00197 KStandardDirs stdDirs;
00198 QString soundPath = stdDirs.findResource( "data", "kshowmail/sounds/" );
00199
00200
00201 if( !txtNewMailsSound->text().isEmpty() )
00202 {
00203 startPath = txtNewMailsSound->text();
00204 }
00205 else if( !soundPath.isEmpty() )
00206 {
00207 startPath = soundPath;
00208 }
00209 else
00210 {
00211 startPath.clear();
00212 }
00213
00214
00215 QString path = KFileDialog::getOpenFileName( startPath, "*.wav *.ogg|" + i18nc( "@item:inlistbox file types showed by file dialog", "Sound files (*.wav, *.ogg)" ) + "\n*.*|" + i18nc( "@item:inlistbox file types showed by file dialog", "All files (*)" ), this, i18nc( "@title:window", "Select Sound File") );
00216
00217
00218 if( !path.isEmpty() )
00219 txtNewMailsSound->setText( path );
00220 }
00221
00222 void ConfigActions::slotChooseCommand( )
00223 {
00224
00225 QString path = KFileDialog::getOpenFileName( KUrl(), "", this, i18nc( "@title:window", "Select external command") );
00226
00227
00228 if( !path.isEmpty() )
00229 txtNewMailsCommand->setText( path );
00230 }
00231
00232 void ConfigActions::slotPlaySound( )
00233 {
00234 QString path = txtNewMailsSound->text();
00235
00236 if( !path.isEmpty() )
00237 {
00238 Phonon::MediaObject *mediaObject = new Phonon::MediaObject( this );
00239 mediaObject->setCurrentSource( Phonon::MediaSource( path ) );
00240 Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput( Phonon::MusicCategory, this );
00241 Phonon::createPath( mediaObject, audioOutput );
00242 mediaObject->play();
00243
00244 }
00245 }
00246
00247 void ConfigActions::slotExecuteCommand( )
00248 {
00249
00250 QString path = txtNewMailsCommand->text();
00251
00252
00253 QStringList parts = path.split( ' ', QString::SkipEmptyParts );
00254
00255 if( !path.isEmpty() )
00256 {
00257 KProcess::execute( parts );
00258 }
00259 }
00260
00261 void ConfigActions::slotSoundToggled( bool on )
00262 {
00263 btnNewMailsPlaySound->setEnabled( on );
00264 txtNewMailsSound->setEnabled( on );
00265 btnNewMailsChooseSound->setEnabled( on );
00266 }
00267
00268 void ConfigActions::slotCommandToggled( bool on )
00269 {
00270 btnNewMailsExecCommand->setEnabled( on );
00271 txtNewMailsCommand->setEnabled( on );
00272 btnNewMailsChooseCommand->setEnabled( on );
00273 }
00274
00275 void ConfigActions::slotChanged( )
00276 {
00277 KCModule::changed();
00278 }
00279
00280
00281 #include "configactions.moc"
00282
00283
00284
00285
00286