22 #include "wakedlg.moc"
23 #include "ui_wakedlg.h"
32 #include <kalarmcal/kaevent.h>
36 #include <kconfiggroup.h>
41 using namespace KAlarmCal;
52 WakeFromSuspendDlg::WakeFromSuspendDlg(
QWidget* parent)
55 setAttribute(Qt::WA_DeleteOnClose);
56 setCaption(i18nc(
"@title:window",
"Wake From Suspend"));
58 mUi =
new Ui_WakeFromSuspendDlgWidget;
59 mUi->setupUi(mainWidget());
60 KConfigGroup config(KGlobal::config(),
"General");
63 mMainWindow = qobject_cast<
MainWindow*>(parent);
69 enableDisableUseButton();
72 mTimer =
new QTimer(
this);
73 connect(mTimer, SIGNAL(timeout()), SLOT(checkPendingAlarm()));
76 connect(mMainWindow, SIGNAL(selectionChanged()), SLOT(enableDisableUseButton()));
77 connect(mUi->showWakeButton, SIGNAL(clicked()), SLOT(showWakeClicked()));
78 connect(mUi->useWakeButton, SIGNAL(clicked()), SLOT(useWakeClicked()));
79 connect(mUi->cancelWakeButton, SIGNAL(clicked()), SLOT(cancelWakeClicked()));
81 connect(
theApp(), SIGNAL(alarmEnabledToggled(
bool)), SLOT(enableDisableUseButton()));
86 if (mInstance ==
this)
94 void WakeFromSuspendDlg::enableDisableUseButton()
99 QString wakeFromSuspendId = KAlarm::checkRtcWakeConfig().value(0);
102 enable =
event.isValid()
103 &&
event.category() == CalEvent::ACTIVE
105 && !
event.mainDateTime().isDateOnly()
106 &&
event.id() != wakeFromSuspendId;
109 enable =
event &&
event->isValid()
110 &&
event->category() == CalEvent::ACTIVE
112 && !
event->mainDateTime().isDateOnly()
113 &&
event->id() != wakeFromSuspendId;
116 mUi->useWakeButton->setEnabled(enable);
124 bool WakeFromSuspendDlg::checkPendingAlarm()
126 if (KAlarm::checkRtcWakeConfig(
true).isEmpty())
128 mUi->showWakeButton->setEnabled(
false);
129 mUi->cancelWakeButton->setEnabled(
false);
139 void WakeFromSuspendDlg::showWakeClicked()
141 if (checkPendingAlarm())
143 QStringList params = KAlarm::checkRtcWakeConfig();
144 if (!params.isEmpty())
166 void WakeFromSuspendDlg::useWakeClicked()
170 if (!event.isValid())
172 KDateTime dt =
event.mainDateTime().kDateTime();
177 KDateTime dt =
event->mainDateTime().kDateTime();
181 KAMessageBox::sorry(
this, i18nc(
"@info",
"Cannot schedule wakeup time for a date-only alarm"));
185 i18nc(
"@info",
"<para>This wakeup will cancel any existing wakeup which has been set by KAlarm "
186 "or any other application, because your computer can only schedule a single wakeup time.</para>"
187 "<para><b>Note:</b> Wake From Suspend is not supported at all on some computers, especially older ones, "
188 "and some computers only support setting a wakeup time up to 24 hours ahead. "
189 "You may wish to set up a test alarm to check your system's capability.</para>"),
190 QString(), KStandardGuiItem::cont(), KStandardGuiItem::cancel(), QLatin1String(
"wakeupWarning"))
191 != KMessageBox::Continue)
193 int advance = mUi->advanceWakeTime->value();
194 unsigned triggerTime = dt.addSecs(-advance * 60).toTime_t();
195 if (KAlarm::setRtcWakeTime(triggerTime,
this))
199 param << QString::number(event.collectionId()) << event.id() << QString::number(triggerTime);
201 param <<
event->id() << QString::number(triggerTime);
203 KConfigGroup config(KGlobal::config(),
"General");
204 config.writeEntry(
"RtcWake", param);
215 void WakeFromSuspendDlg::cancelWakeClicked()
217 KAlarm::setRtcWakeTime(0,
this);
218 KAlarm::deleteRtcWakeConfig();
219 mUi->showWakeButton->setEnabled(
false);
220 mUi->cancelWakeButton->setEnabled(
false);
221 enableDisableUseButton();
bool alarmsEnabled() const
static void setWakeFromSuspendAdvance(int v)
Set Number of minutes before alarm to wake from suspend.
static WakeFromSuspendDlg * create(QWidget *parent)
static AlarmCalendar * resources()
the KAlarm application object
void selectEvent(const QString &eventID)
Unique event identifier for Akonadi.
static int warningContinueCancel(QWidget *parent, ButtonCode defaultButton, const QString &text, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const QString &dontAskAgainName=QString())
static void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Options(Notify|WindowModal))
static int wakeFromSuspendAdvance()
Get Number of minutes before alarm to wake from suspend.
KAEvent * event(const QString &uniqueId)
static MainWindow * mainMainWindow()
KAEvent * selectedEvent() const