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
00124
00125 config = KGlobal::config();
00126
00127
00128 load();
00129
00130 }
00131
00132
00133 ConfigActions::~ConfigActions()
00134 {
00135 }
00136
00137 void ConfigActions::load( )
00138 {
00139 KConfigGroup* configAct = new KConfigGroup( config, CONFIG_GROUP_ACTIONS );
00140
00141
00142 chkNewMailsAlertWindow->setChecked( configAct->readEntry( CONFIG_ENTRY_NEW_MAIL_ALERTWINDOW, DEFAULT_ACTION_NEW_MAIL_ALERTWINDOW ) );
00143 chkNewMailsMainWindow->setChecked( configAct->readEntry( CONFIG_ENTRY_NEW_MAIL_MAINWINDOW, DEFAULT_ACTION_NEW_MAIL_MAINWINDOW ) );
00144 chkNewMailsBeep->setChecked( configAct->readEntry( CONFIG_ENTRY_NEW_MAIL_BEEP, DEFAULT_ACTION_NEW_MAIL_BEEP ) );
00145 chkNewMailsSound->setChecked( configAct->readEntry( CONFIG_ENTRY_NEW_MAIL_SOUND, DEFAULT_ACTION_NEW_MAIL_SOUND ) );
00146 chkNewMailsCommand->setChecked( configAct->readEntry( CONFIG_ENTRY_NEW_MAIL_COMMAND, DEFAULT_ACTION_NEW_MAIL_COMMAND ) );
00147 chkNoNewMailsTerminate->setChecked( configAct->readEntry( CONFIG_ENTRY_NO_NEW_MAIL_TERMINATE, DEFAULT_ACTION_NO_NEW_MAIL_TERMINATE ) );
00148 chkNoNewMailsMinimize->setChecked( configAct->readEntry( CONFIG_ENTRY_NO_NEW_MAIL_MINIMIZE, DEFAULT_ACTION_NO_NEW_MAIL_MINIMIZE ) );
00149
00150 txtNewMailsSound->setText( configAct->readEntry( CONFIG_ENTRY_NEW_MAIL_SOUNDPATH ) );
00151 txtNewMailsCommand->setText( configAct->readEntry( CONFIG_ENTRY_NEW_MAIL_COMMANDPATH ) );
00152
00153
00154 slotSoundToggled( chkNewMailsSound->isChecked() );
00155 slotCommandToggled( chkNewMailsCommand->isChecked() );
00156 }
00157
00158 void ConfigActions::defaults( )
00159 {
00160 chkNewMailsAlertWindow->setChecked( DEFAULT_ACTION_NEW_MAIL_ALERTWINDOW );
00161 chkNewMailsMainWindow->setChecked( DEFAULT_ACTION_NEW_MAIL_MAINWINDOW );
00162 chkNewMailsBeep->setChecked( DEFAULT_ACTION_NEW_MAIL_BEEP );
00163 chkNewMailsSound->setChecked( DEFAULT_ACTION_NEW_MAIL_SOUND );
00164 chkNewMailsCommand->setChecked( DEFAULT_ACTION_NEW_MAIL_COMMAND );
00165 chkNoNewMailsTerminate->setChecked( DEFAULT_ACTION_NO_NEW_MAIL_TERMINATE );
00166 chkNoNewMailsMinimize->setChecked( DEFAULT_ACTION_NO_NEW_MAIL_MINIMIZE );
00167
00168
00169 slotSoundToggled( chkNewMailsSound->isChecked() );
00170 slotCommandToggled( chkNewMailsCommand->isChecked() );
00171 }
00172
00173 void ConfigActions::save( )
00174 {
00175 KConfigGroup* configAct = new KConfigGroup( config, CONFIG_GROUP_ACTIONS );
00176
00177 configAct->writeEntry( CONFIG_ENTRY_NEW_MAIL_ALERTWINDOW, chkNewMailsAlertWindow->isChecked() );
00178 configAct->writeEntry( CONFIG_ENTRY_NEW_MAIL_MAINWINDOW, chkNewMailsMainWindow->isChecked() );
00179 configAct->writeEntry( CONFIG_ENTRY_NEW_MAIL_BEEP, chkNewMailsBeep->isChecked() );
00180 configAct->writeEntry( CONFIG_ENTRY_NEW_MAIL_SOUND, chkNewMailsSound->isChecked() );
00181 configAct->writeEntry( CONFIG_ENTRY_NEW_MAIL_SOUNDPATH, txtNewMailsSound->text() );
00182 configAct->writeEntry( CONFIG_ENTRY_NEW_MAIL_COMMAND, chkNewMailsCommand->isChecked() );
00183 configAct->writeEntry( CONFIG_ENTRY_NEW_MAIL_COMMANDPATH, txtNewMailsCommand->text() );
00184 configAct->writeEntry( CONFIG_ENTRY_NO_NEW_MAIL_TERMINATE, chkNoNewMailsTerminate->isChecked() );
00185 configAct->writeEntry( CONFIG_ENTRY_NO_NEW_MAIL_MINIMIZE, chkNoNewMailsMinimize->isChecked() );
00186
00187
00188 config->sync();
00189 }
00190
00191 void ConfigActions::slotChooseSound( )
00192 {
00193 QString startPath;
00194
00195
00196 KStandardDirs stdDirs;
00197 QString soundPath = stdDirs.findResource( "data", "kshowmail/sounds/" );
00198
00199
00200 if( !txtNewMailsSound->text().isEmpty() )
00201 {
00202 startPath = txtNewMailsSound->text();
00203 }
00204 else if( !soundPath.isEmpty() )
00205 {
00206 startPath = soundPath;
00207 }
00208 else
00209 {
00210 startPath.clear();
00211 }
00212
00213
00214 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") );
00215
00216
00217 if( !path.isEmpty() )
00218 txtNewMailsSound->setText( path );
00219 }
00220
00221 void ConfigActions::slotChooseCommand( )
00222 {
00223
00224 QString path = KFileDialog::getOpenFileName( KUrl(), "", this, i18nc( "@title:window", "Select external command") );
00225
00226
00227 if( !path.isEmpty() )
00228 txtNewMailsCommand->setText( path );
00229 }
00230
00231 void ConfigActions::slotPlaySound( )
00232 {
00233 QString path = txtNewMailsSound->text();
00234
00235 if( !path.isEmpty() )
00236 {
00237 Phonon::MediaObject *mediaObject = new Phonon::MediaObject( this );
00238 mediaObject->setCurrentSource( Phonon::MediaSource( path ) );
00239 Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput( Phonon::MusicCategory, this );
00240 Phonon::createPath( mediaObject, audioOutput );
00241 mediaObject->play();
00242
00243 }
00244 }
00245
00246 void ConfigActions::slotExecuteCommand( )
00247 {
00248
00249 QString path = txtNewMailsCommand->text();
00250
00251
00252 QStringList parts = path.split( ' ', QString::SkipEmptyParts );
00253
00254 if( !path.isEmpty() )
00255 {
00256 KProcess::execute( parts );
00257 }
00258 }
00259
00260 void ConfigActions::slotSoundToggled( bool on )
00261 {
00262 btnNewMailsPlaySound->setEnabled( on );
00263 txtNewMailsSound->setEnabled( on );
00264 btnNewMailsChooseSound->setEnabled( on );
00265 }
00266
00267 void ConfigActions::slotCommandToggled( bool on )
00268 {
00269 btnNewMailsExecCommand->setEnabled( on );
00270 txtNewMailsCommand->setEnabled( on );
00271 btnNewMailsChooseCommand->setEnabled( on );
00272 }
00273
00274 void ConfigActions::slotChanged( )
00275 {
00276 KCModule::changed();
00277 }
00278
00279
00280 #include "configactions.moc"
00281
00282
00283
00284
00285