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.h>
00024 #include <qlayout.h>
00025 #include <qwhatsthis.h>
00026
00027 #include <klineedit.h>
00028 #include <kapplication.h>
00029 #include <kaboutdata.h>
00030 #include <klocale.h>
00031 #include <kdebug.h>
00032
00033 #include "functions.h"
00034 #include "shellprocess.h"
00035 #include "specialactions.moc"
00036
00037
00038
00039
00040
00041
00042
00043 SpecialActionsButton::SpecialActionsButton(const QString& caption, QWidget* parent, const char* name)
00044 : QPushButton(caption, parent, name),
00045 mReadOnly(false)
00046 {
00047 connect(this, SIGNAL(clicked()), SLOT(slotButtonPressed()));
00048 QWhatsThis::add(this,
00049 i18n("Specify actions to execute before and after the alarm is displayed."));
00050 }
00051
00052
00053
00054
00055
00056 void SpecialActionsButton::setActions(const QString& pre, const QString& post)
00057 {
00058 mPreAction = pre;
00059 mPostAction = post;
00060 setDown(!mPreAction.isEmpty() || !mPostAction.isEmpty());
00061 }
00062
00063
00064
00065
00066
00067 void SpecialActionsButton::slotButtonPressed()
00068 {
00069 SpecialActionsDlg dlg(mPreAction, mPostAction,
00070 i18n("Special Alarm Actions"), this, "actionsDlg");
00071 dlg.setReadOnly(mReadOnly);
00072 if (dlg.exec() == QDialog::Accepted)
00073 {
00074 setActions(dlg.preAction(), dlg.postAction());
00075 emit selected();
00076 }
00077 }
00078
00079
00080
00081
00082
00083
00084
00085 static const char SPEC_ACT_DIALOG_NAME[] = "SpecialActionsDialog";
00086
00087
00088 SpecialActionsDlg::SpecialActionsDlg(const QString& preAction, const QString& postAction,
00089 const QString& caption, QWidget* parent, const char* name)
00090 : KDialogBase(parent, name, true, caption, Ok|Cancel, Ok, false)
00091 {
00092 QWidget* page = new QWidget(this);
00093 setMainWidget(page);
00094 QVBoxLayout* layout = new QVBoxLayout(page, 0, spacingHint());
00095
00096 mActions = new SpecialActions(page);
00097 mActions->setActions(preAction, postAction);
00098 layout->addWidget(mActions);
00099 layout->addSpacing(KDialog::spacingHint());
00100
00101 QSize s;
00102 if (KAlarm::readConfigWindowSize(SPEC_ACT_DIALOG_NAME, s))
00103 resize(s);
00104 }
00105
00106
00107
00108
00109 void SpecialActionsDlg::slotOk()
00110 {
00111 if (mActions->isReadOnly())
00112 reject();
00113 accept();
00114 }
00115
00116
00117
00118
00119
00120 void SpecialActionsDlg::resizeEvent(QResizeEvent* re)
00121 {
00122 if (isVisible())
00123 KAlarm::writeConfigWindowSize(SPEC_ACT_DIALOG_NAME, re->size());
00124 KDialog::resizeEvent(re);
00125 }
00126
00127
00128
00129
00130
00131
00132
00133 SpecialActions::SpecialActions(QWidget* parent, const char* name)
00134 : QGroupBox(parent, name)
00135 {
00136 setFrameStyle(QFrame::NoFrame);
00137 init(QString::null);
00138 }
00139
00140 SpecialActions::SpecialActions(const QString& frameLabel, QWidget* parent, const char* name)
00141 : QGroupBox(frameLabel, parent, name)
00142 {
00143 init(frameLabel);
00144 }
00145
00146 void SpecialActions::init(const QString& frameLabel)
00147 {
00148 mReadOnly = false;
00149
00150 QBoxLayout* topLayout = new QVBoxLayout(this, 0, KDialog::spacingHint());
00151 if (!frameLabel.isEmpty())
00152 {
00153 topLayout->setMargin(KDialog::marginHint());
00154 topLayout->addSpacing(fontMetrics().lineSpacing()/2);
00155 }
00156
00157
00158 QLabel* label = new QLabel(i18n("Pre-a&larm action:"), this);
00159 label->setFixedSize(label->sizeHint());
00160 topLayout->addWidget(label, 0, Qt::AlignAuto);
00161
00162 mPreAction = new KLineEdit(this);
00163 label->setBuddy(mPreAction);
00164 QWhatsThis::add(mPreAction,
00165 i18n("Enter a shell command to execute before the alarm is displayed. "
00166 "N.B. KAlarm will wait for the command to complete before displaying the alarm."));
00167 topLayout->addWidget(mPreAction);
00168 topLayout->addSpacing(KDialog::spacingHint());
00169
00170
00171 label = new QLabel(i18n("Post-alar&m action:"), this);
00172 label->setFixedSize(label->sizeHint());
00173 topLayout->addWidget(label, 0, Qt::AlignAuto);
00174
00175 mPostAction = new KLineEdit(this);
00176 label->setBuddy(mPostAction);
00177 QWhatsThis::add(mPostAction, i18n("Enter a shell command to execute after the alarm window is closed."));
00178 topLayout->addWidget(mPostAction);
00179 }
00180
00181 void SpecialActions::setActions(const QString& pre, const QString& post)
00182 {
00183 mPreAction->setText(pre);
00184 mPostAction->setText(post);
00185 }
00186
00187 QString SpecialActions::preAction() const
00188 {
00189 return mPreAction->text();
00190 }
00191
00192 QString SpecialActions::postAction() const
00193 {
00194 return mPostAction->text();
00195 }
00196
00197 void SpecialActions::setReadOnly(bool ro)
00198 {
00199 mReadOnly = ro;
00200 mPreAction->setReadOnly(mReadOnly);
00201 mPostAction->setReadOnly(mReadOnly);
00202 }