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

kalarm

  • sources
  • kde-4.14
  • kdepim
  • kalarm
specialactions.cpp
Go to the documentation of this file.
1 /*
2  * specialactions.cpp - widget to specify special alarm actions
3  * Program: kalarm
4  * Copyright © 2004-2009,2012 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "kalarm.h"
22 #include "specialactions.h"
23 
24 #include "autoqpointer.h"
25 #include "checkbox.h"
26 #include "functions.h"
27 #include "shellprocess.h"
28 
29 #include <klineedit.h>
30 #include <khbox.h>
31 #include <kapplication.h>
32 #include <kaboutdata.h>
33 #include <klocale.h>
34 #include <kdebug.h>
35 
36 #include <QLabel>
37 #include <QGroupBox>
38 #include <QVBoxLayout>
39 #include <QResizeEvent>
40 
41 
42 /*=============================================================================
43 = Class SpecialActionsButton
44 = Button to display the Special Alarm Actions dialog.
45 =============================================================================*/
46 
47 SpecialActionsButton::SpecialActionsButton(bool enableCheckboxes, QWidget* parent)
48  : QPushButton(i18nc("@action:button", "Special Actions..."), parent),
49  mOptions(0),
50  mEnableCheckboxes(enableCheckboxes),
51  mReadOnly(false)
52 {
53  setCheckable(true);
54  setChecked(false);
55  connect(this, SIGNAL(clicked()), SLOT(slotButtonPressed()));
56  setWhatsThis(i18nc("@info:whatsthis", "Specify actions to execute before and after the alarm is displayed."));
57 }
58 
59 /******************************************************************************
60 * Set the pre- and post-alarm actions.
61 * The button's pressed state is set to reflect whether any actions are set.
62 */
63 void SpecialActionsButton::setActions(const QString& pre, const QString& post, KAEvent::ExtraActionOptions options)
64 {
65  mPreAction = pre;
66  mPostAction = post;
67  mOptions = options;
68  setChecked(!mPreAction.isEmpty() || !mPostAction.isEmpty());
69 }
70 
71 /******************************************************************************
72 * Called when the OK button is clicked.
73 * Display a font and colour selection dialog and get the selections.
74 */
75 void SpecialActionsButton::slotButtonPressed()
76 {
77  // Use AutoQPointer to guard against crash on application exit while
78  // the dialogue is still open. It prevents double deletion (both on
79  // deletion of SpecialActionsButton, and on return from this function).
80  AutoQPointer<SpecialActionsDlg> dlg = new SpecialActionsDlg(mPreAction, mPostAction, mOptions, mEnableCheckboxes, this);
81  dlg->setReadOnly(mReadOnly);
82  if (dlg->exec() == QDialog::Accepted)
83  {
84  mPreAction = dlg->preAction();
85  mPostAction = dlg->postAction();
86  mOptions = dlg->options();
87  emit selected();
88  }
89  if (dlg)
90  setChecked(!mPreAction.isEmpty() || !mPostAction.isEmpty());
91 }
92 
93 
94 /*=============================================================================
95 = Class SpecialActionsDlg
96 = Pre- and post-alarm actions dialog.
97 =============================================================================*/
98 
99 static const char SPEC_ACT_DIALOG_NAME[] = "SpecialActionsDialog";
100 
101 
102 SpecialActionsDlg::SpecialActionsDlg(const QString& preAction, const QString& postAction,
103  KAEvent::ExtraActionOptions options, bool enableCheckboxes,
104  QWidget* parent)
105  : KDialog(parent)
106 {
107  setCaption(i18nc("@title:window", "Special Alarm Actions"));
108  setButtons(Ok|Cancel);
109  setDefaultButton(Ok);
110  connect(this, SIGNAL(okClicked()), SLOT(slotOk()));
111 
112  QWidget* page = new QWidget(this);
113  setMainWidget(page);
114  QVBoxLayout* layout = new QVBoxLayout(page);
115  layout->setMargin(0);
116  layout->setSpacing(spacingHint());
117 
118  mActions = new SpecialActions(enableCheckboxes, page);
119  mActions->setActions(preAction, postAction, options);
120  layout->addWidget(mActions);
121  layout->addSpacing(spacingHint());
122 
123  QSize s;
124  if (KAlarm::readConfigWindowSize(SPEC_ACT_DIALOG_NAME, s))
125  resize(s);
126 }
127 
128 /******************************************************************************
129 * Called when the OK button is clicked.
130 */
131 void SpecialActionsDlg::slotOk()
132 {
133  if (mActions->isReadOnly())
134  reject();
135  accept();
136 }
137 
138 /******************************************************************************
139 * Called when the dialog's size has changed.
140 * Records the new size in the config file.
141 */
142 void SpecialActionsDlg::resizeEvent(QResizeEvent* re)
143 {
144  if (isVisible())
145  KAlarm::writeConfigWindowSize(SPEC_ACT_DIALOG_NAME, re->size());
146  KDialog::resizeEvent(re);
147 }
148 
149 
150 /*=============================================================================
151 = Class SpecialActions
152 = Pre- and post-alarm actions widget.
153 =============================================================================*/
154 
155 SpecialActions::SpecialActions(bool enableCheckboxes, QWidget* parent)
156  : QWidget(parent),
157  mEnableCheckboxes(enableCheckboxes),
158  mReadOnly(false)
159 {
160  QVBoxLayout* topLayout = new QVBoxLayout(this);
161  topLayout->setMargin(0);
162  topLayout->setSpacing(KDialog::spacingHint());
163 
164  // Pre-alarm action
165  QGroupBox* group = new QGroupBox(i18nc("@title:group", "Pre-Alarm Action"), this);
166  topLayout->addWidget(group);
167  QVBoxLayout* vlayout = new QVBoxLayout(group);
168  vlayout->setMargin(KDialog::marginHint());
169  vlayout->setSpacing(KDialog::spacingHint());
170 
171  KHBox* box = new KHBox(group); // this is to control the QWhatsThis text display area
172  box->setMargin(0);
173  box->setSpacing(KDialog::spacingHint());
174  vlayout->addWidget(box);
175  QLabel* label = new QLabel(i18nc("@label:textbox", "Command:"), box);
176  mPreAction = new KLineEdit(box);
177  label->setBuddy(mPreAction);
178  connect(mPreAction, SIGNAL(textChanged(QString)), SLOT(slotPreActionChanged(QString)));
179  box->setWhatsThis(i18nc("@info:whatsthis",
180  "<para>Enter a shell command to execute before the alarm is displayed.</para>"
181  "<para>Note that it is executed only when the alarm proper is displayed, not when a reminder or deferred alarm is displayed.</para>"
182  "<para><note>KAlarm will wait for the command to complete before displaying the alarm.</note></para>"));
183  box->setStretchFactor(mPreAction, 1);
184 
185  // Cancel if error in pre-alarm action
186  mExecOnDeferral = new CheckBox(i18nc("@option:check", "Execute for deferred alarms"), group);
187  mExecOnDeferral->setWhatsThis(i18nc("@info:whatsthis", "<para>If unchecked, the command is only executed before the alarm proper is displayed.</para>"
188  "<para>If checked, the pre-alarm command is also executed before a deferred alarm is displayed.</para>"));
189  vlayout->addWidget(mExecOnDeferral, 0, Qt::AlignLeft);
190 
191  mCancelOnError = new CheckBox(i18nc("@option:check", "Cancel alarm on error"), group);
192  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."));
193  vlayout->addWidget(mCancelOnError, 0, Qt::AlignLeft);
194 
195  mDontShowError = new CheckBox(i18nc("@option:check", "Do not notify errors"), group);
196  mDontShowError->setWhatsThis(i18nc("@info:whatsthis", "Do not show error status or error message if the pre-alarm command fails."));
197  vlayout->addWidget(mDontShowError, 0, Qt::AlignLeft);
198 
199  // Post-alarm action
200  group = new QGroupBox(i18nc("@title:group", "Post-Alarm Action"), this);
201  topLayout->addWidget(group);
202  vlayout = new QVBoxLayout(group);
203  vlayout->setMargin(KDialog::marginHint());
204  vlayout->setSpacing(KDialog::spacingHint());
205 
206  box = new KHBox(group); // this is to control the QWhatsThis text display area
207  box->setMargin(0);
208  box->setSpacing(KDialog::spacingHint());
209  vlayout->addWidget(box);
210  label = new QLabel(i18nc("@label:textbox", "Command:"), box);
211  mPostAction = new KLineEdit(box);
212  label->setBuddy(mPostAction);
213  box->setWhatsThis(i18nc("@info:whatsthis",
214  "<para>Enter a shell command to execute after the alarm window is closed.</para>"
215  "<para>Note that it is not executed after closing a reminder window. If you defer "
216  "the alarm, it is not executed until the alarm is finally acknowledged or closed.</para>"));
217  box->setStretchFactor(mPostAction, 1);
218 
219  mExecOnDeferral->setEnabled(enableCheckboxes);
220  mCancelOnError->setEnabled(enableCheckboxes);
221  mDontShowError->setEnabled(enableCheckboxes);
222 }
223 
224 void SpecialActions::setActions(const QString& pre, const QString& post, KAEvent::ExtraActionOptions options)
225 {
226  mPreAction->setText(pre);
227  mPostAction->setText(post);
228  mExecOnDeferral->setChecked(options & KAEvent::ExecPreActOnDeferral);
229  mCancelOnError->setChecked(options & KAEvent::CancelOnPreActError);
230  mDontShowError->setChecked(options & KAEvent::DontShowPreActError);
231 }
232 
233 QString SpecialActions::preAction() const
234 {
235  return mPreAction->text();
236 }
237 
238 QString SpecialActions::postAction() const
239 {
240  return mPostAction->text();
241 }
242 
243 KAEvent::ExtraActionOptions SpecialActions::options() const
244 {
245  KAEvent::ExtraActionOptions opts = 0;
246  if (mExecOnDeferral->isChecked()) opts |= KAEvent::ExecPreActOnDeferral;
247  if (mCancelOnError->isChecked()) opts |= KAEvent::CancelOnPreActError;
248  if (mDontShowError->isChecked()) opts |= KAEvent::DontShowPreActError;
249  return opts;
250 }
251 
252 void SpecialActions::setReadOnly(bool ro)
253 {
254  mReadOnly = ro;
255  mPreAction->setReadOnly(mReadOnly);
256  mPostAction->setReadOnly(mReadOnly);
257  mExecOnDeferral->setReadOnly(mReadOnly);
258  mCancelOnError->setReadOnly(mReadOnly);
259  mDontShowError->setReadOnly(mReadOnly);
260 }
261 
262 void SpecialActions::slotPreActionChanged(const QString& text)
263 {
264  if (!mEnableCheckboxes)
265  {
266  bool textValid = !text.isEmpty();
267  mExecOnDeferral->setEnabled(textValid);
268  mCancelOnError->setEnabled(textValid);
269  mDontShowError->setEnabled(textValid);
270  }
271 }
272 #include "moc_specialactions.cpp"
273 // vim: et sw=4:
CheckBox::setReadOnly
virtual void setReadOnly(bool readOnly)
SpecialActions
Definition: specialactions.h:65
SpecialActions::postAction
QString postAction() const
Definition: specialactions.cpp:238
QResizeEvent
QWidget
SpecialActions::setActions
void setActions(const QString &pre, const QString &post, KAEvent::ExtraActionOptions)
Definition: specialactions.cpp:224
text
virtual QByteArray text(quint32 serialNumber) const =0
specialactions.h
SpecialActionsButton::SpecialActionsButton
SpecialActionsButton(bool enableCheckboxes, QWidget *parent=0)
Definition: specialactions.cpp:47
SpecialActions::options
KAEvent::ExtraActionOptions options() const
Definition: specialactions.cpp:243
KDialog
QBoxLayout::addSpacing
void addSpacing(int size)
checkbox.h
SpecialActionsDlg::options
KAEvent::ExtraActionOptions options() const
Definition: specialactions.h:101
SpecialActions::isReadOnly
bool isReadOnly() const
Definition: specialactions.h:75
QLabel::setBuddy
void setBuddy(QWidget *buddy)
QWidget::setEnabled
void setEnabled(bool)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QGroupBox
SpecialActions::SpecialActions
SpecialActions(bool enableCheckboxes, QWidget *parent=0)
Definition: specialactions.cpp:155
CheckBox
SpecialActionsButton::selected
void selected()
Signal emitted whenever the widget has been changed.
autoqpointer.h
SpecialActionsDlg::preAction
QString preAction() const
Definition: specialactions.h:99
QString::isEmpty
bool isEmpty() const
QAbstractButton::clicked
void clicked(bool checked)
SPEC_ACT_DIALOG_NAME
static const char SPEC_ACT_DIALOG_NAME[]
Definition: specialactions.cpp:99
QVBoxLayout
SpecialActionsDlg::postAction
QString postAction() const
Definition: specialactions.h:100
QAbstractButton::setCheckable
void setCheckable(bool)
QString
SpecialActionsButton::options
KAEvent::ExtraActionOptions options() const
Definition: specialactions.h:44
QLayout::setMargin
void setMargin(int margin)
SpecialActionsDlg::SpecialActionsDlg
SpecialActionsDlg(const QString &preAction, const QString &postAction, KAEvent::ExtraActionOptions, bool enableCheckboxes, QWidget *parent=0)
Definition: specialactions.cpp:102
SpecialActions::setReadOnly
void setReadOnly(bool)
Definition: specialactions.cpp:252
SpecialActionsButton::slotButtonPressed
void slotButtonPressed()
Definition: specialactions.cpp:75
QResizeEvent::size
const QSize & size() const
QSize
SpecialActionsDlg::resizeEvent
virtual void resizeEvent(QResizeEvent *)
Definition: specialactions.cpp:142
AutoQPointer
SpecialActionsDlg::setReadOnly
void setReadOnly(bool ro)
Definition: specialactions.h:102
QAbstractButton::setChecked
void setChecked(bool)
KLineEdit
QWidget::setWhatsThis
void setWhatsThis(const QString &)
SpecialActionsDlg
Definition: specialactions.h:92
SpecialActionsButton::setActions
void setActions(const QString &pre, const QString &post, KAEvent::ExtraActionOptions)
Definition: specialactions.cpp:63
functions.h
miscellaneous functions
kalarm.h
QPushButton
KHBox
shellprocess.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
SpecialActions::preAction
QString preAction() const
Definition: specialactions.cpp:233
QBoxLayout::setSpacing
void setSpacing(int spacing)
SpecialActionsDlg::slotOk
virtual void slotOk()
Definition: specialactions.cpp:131
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal