00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00043
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
00059
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
00071
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
00090
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
00126
00127 void SpecialActionsDlg::slotOk()
00128 {
00129 if (mActions->isReadOnly())
00130 reject();
00131 accept();
00132 }
00133
00134
00135
00136
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
00148
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
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);
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
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
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);
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 }