• 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
wakedlg.cpp
Go to the documentation of this file.
1 /*
2  * wakedlg.cpp - dialog to configure wake-from-suspend alarms
3  * Program: kalarm
4  * Copyright © 2011-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 "wakedlg.h"
23 #include "ui_wakedlg.h"
24 
25 #include "alarmcalendar.h"
26 #include "functions.h"
27 #include "kalarmapp.h"
28 #include "mainwindow.h"
29 #include "messagebox.h"
30 #include "preferences.h"
31 
32 #include <kalarmcal/kaevent.h>
33 
34 #include <kglobal.h>
35 #include <klocale.h>
36 #include <kconfiggroup.h>
37 #include <kdebug.h>
38 
39 #include <QTimer>
40 
41 using namespace KAlarmCal;
42 
43 WakeFromSuspendDlg* WakeFromSuspendDlg::mInstance = 0;
44 
45 WakeFromSuspendDlg* WakeFromSuspendDlg::create(QWidget* parent)
46 {
47  if (!mInstance)
48  mInstance = new WakeFromSuspendDlg(parent);
49  return mInstance;
50 }
51 
52 WakeFromSuspendDlg::WakeFromSuspendDlg(QWidget* parent)
53  : KDialog(parent)
54 {
55  setAttribute(Qt::WA_DeleteOnClose);
56  setCaption(i18nc("@title:window", "Wake From Suspend"));
57  setButtons(Close);
58  mUi = new Ui_WakeFromSuspendDlgWidget;
59  mUi->setupUi(mainWidget());
60  mUi->advanceWakeTime->setValue(Preferences::wakeFromSuspendAdvance());
61 
62  mMainWindow = qobject_cast<MainWindow*>(parent);
63  if (!mMainWindow)
64  mMainWindow = MainWindow::mainMainWindow();
65 
66  // Check if there is any alarm selected in the main window, and enable/disable
67  // the Show and Cancel buttons as necessary.
68  enableDisableUseButton();
69 
70  // Update the Show and Cancel button status every 5 seconds
71  mTimer = new QTimer(this);
72  connect(mTimer, SIGNAL(timeout()), SLOT(checkPendingAlarm()));
73  mTimer->start(5000);
74 
75  connect(mMainWindow, SIGNAL(selectionChanged()), SLOT(enableDisableUseButton()));
76  connect(mUi->showWakeButton, SIGNAL(clicked()), SLOT(showWakeClicked()));
77  connect(mUi->useWakeButton, SIGNAL(clicked()), SLOT(useWakeClicked()));
78  connect(mUi->cancelWakeButton, SIGNAL(clicked()), SLOT(cancelWakeClicked()));
79 
80  connect(theApp(), SIGNAL(alarmEnabledToggled(bool)), SLOT(enableDisableUseButton()));
81 }
82 
83 WakeFromSuspendDlg::~WakeFromSuspendDlg()
84 {
85  if (mInstance == this)
86  mInstance = 0;
87  delete mUi;
88 }
89 
90 /******************************************************************************
91 * Called when the alarm selection in the main window changes.
92 * Enable or disable the Use Highlighted Alarm button.
93 */
94 void WakeFromSuspendDlg::enableDisableUseButton()
95 {
96  bool enable = theApp()->alarmsEnabled();
97  if (enable)
98  {
99  QString wakeFromSuspendId = KAlarm::checkRtcWakeConfig().value(0);
100 #ifdef USE_AKONADI
101  const KAEvent event = mMainWindow->selectedEvent();
102  enable = event.isValid()
103  && event.category() == CalEvent::ACTIVE
104  && event.enabled()
105  && !event.mainDateTime().isDateOnly()
106  && event.id() != wakeFromSuspendId;
107 #else
108  const KAEvent* event = mMainWindow->selectedEvent();
109  enable = event && event->isValid()
110  && event->category() == CalEvent::ACTIVE
111  && event->enabled()
112  && !event->mainDateTime().isDateOnly()
113  && event->id() != wakeFromSuspendId;
114 #endif
115  }
116  mUi->useWakeButton->setEnabled(enable);
117  checkPendingAlarm();
118 }
119 
120 /******************************************************************************
121 * Update the Show and Cancel buttons if the pending alarm status has changed.
122 * Reply = true if an alarm is still pending.
123 */
124 bool WakeFromSuspendDlg::checkPendingAlarm()
125 {
126  if (KAlarm::checkRtcWakeConfig(true).isEmpty())
127  {
128  mUi->showWakeButton->setEnabled(false);
129  mUi->cancelWakeButton->setEnabled(false);
130  return false;
131  }
132  return true;
133 }
134 
135 /******************************************************************************
136 * Called when the user clicks the Show Current Alarm button.
137 * Highlight the currently scheduled wake-from-suspend alarm in the main window.
138 */
139 void WakeFromSuspendDlg::showWakeClicked()
140 {
141  if (checkPendingAlarm())
142  {
143  QStringList params = KAlarm::checkRtcWakeConfig();
144  if (!params.isEmpty())
145  {
146 #ifdef USE_AKONADI
147  KAEvent* event = AlarmCalendar::resources()->event(EventId(params[0].toLongLong(), params[1]));
148  if (event)
149  {
150  mMainWindow->selectEvent(event->itemId());
151  return;
152  }
153 #else
154  mMainWindow->selectEvent(params[0]);
155  return;
156 #endif
157  }
158  }
159  mMainWindow->clearSelection();
160 }
161 
162 /******************************************************************************
163 * Called when the user clicks the Use Highlighted Alarm button.
164 * Schedules system wakeup for that alarm.
165 */
166 void WakeFromSuspendDlg::useWakeClicked()
167 {
168 #ifdef USE_AKONADI
169  KAEvent event = mMainWindow->selectedEvent();
170  if (!event.isValid())
171  return;
172  KDateTime dt = event.mainDateTime().kDateTime();
173 #else
174  KAEvent* event = mMainWindow->selectedEvent();
175  if (!event)
176  return;
177  KDateTime dt = event->mainDateTime().kDateTime();
178 #endif
179  if (dt.isDateOnly())
180  {
181  KAMessageBox::sorry(this, i18nc("@info", "Cannot schedule wakeup time for a date-only alarm"));
182  return;
183  }
184  if (KAMessageBox::warningContinueCancel(this,
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)
192  return;
193  int advance = mUi->advanceWakeTime->value();
194  unsigned triggerTime = dt.addSecs(-advance * 60).toTime_t();
195  if (KAlarm::setRtcWakeTime(triggerTime, this))
196  {
197  QStringList param;
198 #ifdef USE_AKONADI
199  param << QString::number(event.collectionId()) << event.id() << QString::number(triggerTime);
200 #else
201  param << event->id() << QString::number(triggerTime);
202 #endif
203  KConfigGroup config(KGlobal::config(), "General");
204  config.writeEntry("RtcWake", param);
205  config.sync();
206  Preferences::setWakeFromSuspendAdvance(advance);
207  close();
208  }
209 }
210 
211 /******************************************************************************
212 * Called when the user clicks the Cancel Wake From Suspend button.
213 * Cancels any currently scheduled system wakeup.
214 */
215 void WakeFromSuspendDlg::cancelWakeClicked()
216 {
217  KAlarm::setRtcWakeTime(0, this);
218  KAlarm::deleteRtcWakeConfig();
219  mUi->showWakeButton->setEnabled(false);
220  mUi->cancelWakeButton->setEnabled(false);
221  enableDisableUseButton();
222 }
223 
224 // vim: et sw=4:
QWidget
KAlarmApp::alarmsEnabled
bool alarmsEnabled() const
Definition: kalarmapp.h:63
MainWindow::clearSelection
void clearSelection()
Definition: mainwindow.cpp:733
WakeFromSuspendDlg::create
static WakeFromSuspendDlg * create(QWidget *parent)
Definition: wakedlg.cpp:45
AlarmCalendar::resources
static AlarmCalendar * resources()
Definition: alarmcalendar.h:130
alarmcalendar.h
KDialog
QList::value
T value(int i) const
kalarmapp.h
the KAlarm application object
QString::number
QString number(int n, int base)
QTimer
QList::isEmpty
bool isEmpty() const
MainWindow::selectEvent
void selectEvent(const QString &eventID)
Definition: mainwindow.cpp:702
mainwindow.h
main application window
messagebox.h
QString
theApp
KAlarmApp * theApp()
Definition: kalarmapp.h:263
QStringList
preferences.h
EventId
Unique event identifier for Akonadi.
Definition: eventid.h:38
QLatin1String
functions.h
miscellaneous functions
KAMessageBox::sorry
static void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Options(Notify|WindowModal))
wakedlg.h
kalarm.h
KAMessageBox::warningContinueCancel
static int warningContinueCancel(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Options(Notify|WindowModal))
WakeFromSuspendDlg
Definition: wakedlg.h:30
QTimer::start
void start(int msec)
AlarmCalendar::event
KAEvent * event(const QString &uniqueId)
Definition: alarmcalendar.cpp:1817
MainWindow::mainMainWindow
static MainWindow * mainMainWindow()
Definition: mainwindow.cpp:286
WakeFromSuspendDlg::~WakeFromSuspendDlg
~WakeFromSuspendDlg()
Definition: wakedlg.cpp:83
MainWindow
Definition: mainwindow.h:70
MainWindow::selectedEvent
KAEvent * selectedEvent() const
Definition: mainwindow.cpp:724
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