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 <tqlabel.h>
00024 #include <tqlayout.h>
00025 #include <tqwhatsthis.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 TQString& caption, TQWidget* parent, const char* name)
00044 : TQPushButton(caption, parent, name),
00045 mReadOnly(false)
00046 {
00047 setToggleButton(true);
00048 setOn(false);
00049 connect(this, TQT_SIGNAL(clicked()), TQT_SLOT(slotButtonPressed()));
00050 TQWhatsThis::add(this,
00051 i18n("Specify actions to execute before and after the alarm is displayed."));
00052 }
00053
00054
00055
00056
00057
00058 void SpecialActionsButton::setActions(const TQString& pre, const TQString& post)
00059 {
00060 mPreAction = pre;
00061 mPostAction = post;
00062 setOn(!mPreAction.isEmpty() || !mPostAction.isEmpty());
00063 }
00064
00065
00066
00067
00068
00069 void SpecialActionsButton::slotButtonPressed()
00070 {
00071 SpecialActionsDlg dlg(mPreAction, mPostAction,
00072 i18n("Special Alarm Actions"), this, "actionsDlg");
00073 dlg.setReadOnly(mReadOnly);
00074 if (dlg.exec() == TQDialog::Accepted)
00075 {
00076 mPreAction = dlg.preAction();
00077 mPostAction = dlg.postAction();
00078 emit selected();
00079 }
00080 setOn(!mPreAction.isEmpty() || !mPostAction.isEmpty());
00081 }
00082
00083
00084
00085
00086
00087
00088
00089 static const char SPEC_ACT_DIALOG_NAME[] = "SpecialActionsDialog";
00090
00091
00092 SpecialActionsDlg::SpecialActionsDlg(const TQString& preAction, const TQString& postAction,
00093 const TQString& caption, TQWidget* parent, const char* name)
00094 : KDialogBase(parent, name, true, caption, Ok|Cancel, Ok, false)
00095 {
00096 TQWidget* page = new TQWidget(this);
00097 setMainWidget(page);
00098 TQVBoxLayout* layout = new TQVBoxLayout(page, 0, spacingHint());
00099
00100 mActions = new SpecialActions(page);
00101 mActions->setActions(preAction, postAction);
00102 layout->addWidget(mActions);
00103 layout->addSpacing(KDialog::spacingHint());
00104
00105 TQSize s;
00106 if (KAlarm::readConfigWindowSize(SPEC_ACT_DIALOG_NAME, s))
00107 resize(s);
00108 }
00109
00110
00111
00112
00113 void SpecialActionsDlg::slotOk()
00114 {
00115 if (mActions->isReadOnly())
00116 reject();
00117 accept();
00118 }
00119
00120
00121
00122
00123
00124 void SpecialActionsDlg::resizeEvent(TQResizeEvent* re)
00125 {
00126 if (isVisible())
00127 KAlarm::writeConfigWindowSize(SPEC_ACT_DIALOG_NAME, re->size());
00128 KDialog::resizeEvent(re);
00129 }
00130
00131
00132
00133
00134
00135
00136
00137 SpecialActions::SpecialActions(TQWidget* parent, const char* name)
00138 : TQWidget(parent, name),
00139 mReadOnly(false)
00140 {
00141 TQBoxLayout* topLayout = new TQVBoxLayout(this, 0, KDialog::spacingHint());
00142
00143
00144 TQLabel* label = new TQLabel(i18n("Pre-a&larm action:"), this);
00145 label->setFixedSize(label->sizeHint());
00146 topLayout->addWidget(label, 0, Qt::AlignAuto);
00147
00148 mPreAction = new KLineEdit(this);
00149 label->setBuddy(mPreAction);
00150 TQWhatsThis::add(mPreAction,
00151 i18n("Enter a shell command to execute before the alarm is displayed.\n"
00152 "Note that it is executed only when the alarm proper is displayed, not when a reminder or deferred alarm is displayed.\n"
00153 "N.B. KAlarm will wait for the command to complete before displaying the alarm."));
00154 topLayout->addWidget(mPreAction);
00155 topLayout->addSpacing(KDialog::spacingHint());
00156
00157
00158 label = new TQLabel(i18n("Post-alar&m action:"), this);
00159 label->setFixedSize(label->sizeHint());
00160 topLayout->addWidget(label, 0, Qt::AlignAuto);
00161
00162 mPostAction = new KLineEdit(this);
00163 label->setBuddy(mPostAction);
00164 TQWhatsThis::add(mPostAction,
00165 i18n("Enter a shell command to execute after the alarm window is closed.\n"
00166 "Note that it is not executed after closing a reminder window. If you defer "
00167 "the alarm, it is not executed until the alarm is finally acknowledged or closed."));
00168 topLayout->addWidget(mPostAction);
00169 }
00170
00171 void SpecialActions::setActions(const TQString& pre, const TQString& post)
00172 {
00173 mPreAction->setText(pre);
00174 mPostAction->setText(post);
00175 }
00176
00177 TQString SpecialActions::preAction() const
00178 {
00179 return mPreAction->text();
00180 }
00181
00182 TQString SpecialActions::postAction() const
00183 {
00184 return mPostAction->text();
00185 }
00186
00187 void SpecialActions::setReadOnly(bool ro)
00188 {
00189 mReadOnly = ro;
00190 mPreAction->setReadOnly(mReadOnly);
00191 mPostAction->setReadOnly(mReadOnly);
00192 }