• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kalarm

specialactions.cpp

Go to the documentation of this file.
00001 /*
00002  *  specialactions.cpp  -  widget to specify special alarm actions
00003  *  Program:  kalarm
00004  *  Copyright © 2004-2008 by David Jarvie <djarvie@kde.org>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "kalarm.h"
00022 
00023 #include <QLabel>
00024 #include <QGroupBox>
00025 #include <QVBoxLayout>
00026 #include <QResizeEvent>
00027 
00028 #include <klineedit.h>
00029 #include <khbox.h>
00030 #include <kapplication.h>
00031 #include <kaboutdata.h>
00032 #include <klocale.h>
00033 #include <kdebug.h>
00034 
00035 #include "checkbox.h"
00036 #include "functions.h"
00037 #include "shellprocess.h"
00038 #include "specialactions.moc"
00039 
00040 
00041 /*=============================================================================
00042 = Class SpecialActionsButton
00043 = Button to display the Special Alarm Actions dialog.
00044 =============================================================================*/
00045 
00046 SpecialActionsButton::SpecialActionsButton(bool enableCancelOnError, QWidget* parent)
00047     : QPushButton(i18nc("@action:button", "Special Actions..."), parent),
00048       mEnableCancel(enableCancelOnError),
00049       mReadOnly(false)
00050 {
00051     setCheckable(true);
00052     setChecked(false);
00053     connect(this, SIGNAL(clicked()), SLOT(slotButtonPressed()));
00054     setWhatsThis(i18nc("@info:whatsthis", "Specify actions to execute before and after the alarm is displayed."));
00055 }
00056 
00057 /******************************************************************************
00058 *  Set the pre- and post-alarm actions.
00059 *  The button's pressed state is set to reflect whether any actions are set.
00060 */
00061 void SpecialActionsButton::setActions(const QString& pre, const QString& post, bool cancelOnError)
00062 {
00063     mPreAction     = pre;
00064     mPostAction    = post;
00065     mCancelOnError = cancelOnError;
00066     setChecked(!mPreAction.isEmpty() || !mPostAction.isEmpty());
00067 }
00068 
00069 /******************************************************************************
00070 *  Called when the OK button is clicked.
00071 *  Display a font and colour selection dialog and get the selections.
00072 */
00073 void SpecialActionsButton::slotButtonPressed()
00074 {
00075     SpecialActionsDlg dlg(mPreAction, mPostAction, mCancelOnError, mEnableCancel, this);
00076     dlg.setReadOnly(mReadOnly);
00077     if (dlg.exec() == QDialog::Accepted)
00078     {
00079         mPreAction     = dlg.preAction();
00080         mPostAction    = dlg.postAction();
00081         mCancelOnError = dlg.cancelOnError();
00082         emit selected();
00083     }
00084     setChecked(!mPreAction.isEmpty() || !mPostAction.isEmpty());
00085 }
00086 
00087 
00088 /*=============================================================================
00089 = Class SpecialActionsDlg
00090 = Pre- and post-alarm actions dialog.
00091 =============================================================================*/
00092 
00093 static const char SPEC_ACT_DIALOG_NAME[] = "SpecialActionsDialog";
00094 
00095 
00096 SpecialActionsDlg::SpecialActionsDlg(const QString& preAction, const QString& postAction,
00097                                      bool cancelOnError, bool enableCancelOnError, QWidget* parent)
00098     : KDialog(parent)
00099 {
00100 #ifdef __GNUC__
00101 #warning Dialogue appears below edit dialogue when Edit button in alarm message window is clicked
00102 #endif
00103     setCaption(i18nc("@title:window", "Special Alarm Actions"));
00104     setButtons(Ok|Cancel);
00105     setDefaultButton(Ok);
00106     connect(this, SIGNAL(okClicked()), SLOT(slotOk()));
00107 
00108     QWidget* page = new QWidget(this);
00109     setMainWidget(page);
00110     QVBoxLayout* layout = new QVBoxLayout(page);
00111     layout->setMargin(0);
00112     layout->setSpacing(spacingHint());
00113 
00114     mActions = new SpecialActions(enableCancelOnError, page);
00115     mActions->setActions(preAction, postAction, cancelOnError);
00116     layout->addWidget(mActions);
00117     layout->addSpacing(spacingHint());
00118 
00119     QSize s;
00120     if (KAlarm::readConfigWindowSize(SPEC_ACT_DIALOG_NAME, s))
00121         resize(s);
00122 }
00123 
00124 /******************************************************************************
00125 *  Called when the OK button is clicked.
00126 */
00127 void SpecialActionsDlg::slotOk()
00128 {
00129     if (mActions->isReadOnly())
00130         reject();
00131     accept();
00132 }
00133 
00134 /******************************************************************************
00135 *  Called when the dialog's size has changed.
00136 *  Records the new size in the config file.
00137 */
00138 void SpecialActionsDlg::resizeEvent(QResizeEvent* re)
00139 {
00140     if (isVisible())
00141         KAlarm::writeConfigWindowSize(SPEC_ACT_DIALOG_NAME, re->size());
00142     KDialog::resizeEvent(re);
00143 }
00144 
00145 
00146 /*=============================================================================
00147 = Class SpecialActions
00148 = Pre- and post-alarm actions widget.
00149 =============================================================================*/
00150 
00151 SpecialActions::SpecialActions(bool enableCancelOnError, QWidget* parent)
00152     : QWidget(parent),
00153       mEnableCancel(enableCancelOnError),
00154       mReadOnly(false)
00155 {
00156     QVBoxLayout* topLayout = new QVBoxLayout(this);
00157     topLayout->setMargin(0);
00158     topLayout->setSpacing(KDialog::spacingHint());
00159 
00160     // Pre-alarm action
00161     QGroupBox* group = new QGroupBox(i18nc("@title:group", "Pre-Alarm Action"), this);
00162     topLayout->addWidget(group);
00163     QVBoxLayout* vlayout = new QVBoxLayout(group);
00164     vlayout->setMargin(KDialog::marginHint());
00165     vlayout->setSpacing(KDialog::spacingHint());
00166 
00167     KHBox* box = new KHBox(group);   // this is to control the QWhatsThis text display area
00168     box->setMargin(0);
00169     box->setSpacing(KDialog::spacingHint());
00170     vlayout->addWidget(box);
00171     QLabel* label = new QLabel(i18nc("@label:textbox", "Command:"), box);
00172     mPreAction = new KLineEdit(box);
00173     label->setBuddy(mPreAction);
00174     connect(mPreAction, SIGNAL(textChanged(const QString&)), SLOT(slotPreActionChanged(const QString&)));
00175     box->setWhatsThis(i18nc("@info:whatsthis",
00176                             "<para>Enter a shell command to execute before the alarm is displayed.</para>"
00177                             "<para>Note that it is executed only when the alarm proper is displayed, not when a reminder or deferred alarm is displayed.</para>"
00178                             "<para><note>KAlarm will wait for the command to complete before displaying the alarm.</note></para>"));
00179     box->setStretchFactor(mPreAction, 1);
00180 
00181     // Cancel if error in pre-alarm action
00182     mCancelOnError = new CheckBox(i18nc("@option:check", "Cancel alarm on error"), group);
00183     mCancelOnError->setWhatsThis(i18nc("@info:whatsthis", "Cancel the alarm if the pre-alarm command fails, i.e. do not display the alarm or execute any post-alarm action command."));
00184     vlayout->addWidget(mCancelOnError, 0, Qt::AlignLeft);
00185 
00186     // Post-alarm action
00187     group = new QGroupBox(i18nc("@title:group", "Post-Alarm Action"), this);
00188     topLayout->addWidget(group);
00189     vlayout = new QVBoxLayout(group);
00190     vlayout->setMargin(KDialog::marginHint());
00191     vlayout->setSpacing(KDialog::spacingHint());
00192 
00193     box = new KHBox(group);   // this is to control the QWhatsThis text display area
00194     box->setMargin(0);
00195     box->setSpacing(KDialog::spacingHint());
00196     vlayout->addWidget(box);
00197     label = new QLabel(i18nc("@label:textbox", "Command:"), box);
00198     mPostAction = new KLineEdit(box);
00199     label->setBuddy(mPostAction);
00200     box->setWhatsThis(i18nc("@info:whatsthis",
00201                             "<para>Enter a shell command to execute after the alarm window is closed.</para>"
00202                             "<para>Note that it is not executed after closing a reminder window. If you defer "
00203                             "the alarm, it is not executed until the alarm is finally acknowledged or closed.</para>"));
00204     box->setStretchFactor(mPostAction, 1);
00205 
00206     mCancelOnError->setEnabled(enableCancelOnError);
00207 }
00208 
00209 void SpecialActions::setActions(const QString& pre, const QString& post, bool cancelOnError)
00210 {
00211     mPreAction->setText(pre);
00212     mPostAction->setText(post);
00213     mCancelOnError->setChecked(cancelOnError);
00214 }
00215 
00216 QString SpecialActions::preAction() const
00217 {
00218     return mPreAction->text();
00219 }
00220 
00221 QString SpecialActions::postAction() const
00222 {
00223     return mPostAction->text();
00224 }
00225 
00226 bool SpecialActions::cancelOnError() const
00227 {
00228     return mCancelOnError->isChecked();
00229 }
00230 
00231 void SpecialActions::setReadOnly(bool ro)
00232 {
00233     mReadOnly = ro;
00234     mPreAction->setReadOnly(mReadOnly);
00235     mPostAction->setReadOnly(mReadOnly);
00236     mCancelOnError->setReadOnly(mReadOnly);
00237 }
00238 
00239 void SpecialActions::slotPreActionChanged(const QString& text)
00240 {
00241     if (!mEnableCancel)
00242         mCancelOnError->setEnabled(!text.isEmpty());
00243 }

kalarm

Skip menu "kalarm"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal