• 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
deferdlg.cpp
Go to the documentation of this file.
1 /*
2  * deferdlg.cpp - dialog to defer an alarm
3  * Program: kalarm
4  * Copyright © 2002-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 "deferdlg.h"
23 
24 #include "alarmcalendar.h"
25 #include "alarmtimewidget.h"
26 #include "functions.h"
27 #include "kalarmapp.h"
28 #include "messagebox.h"
29 
30 #include <kalarmcal/datetime.h>
31 #include <kalarmcal/kaevent.h>
32 
33 #include <kglobal.h>
34 #include <klocale.h>
35 #include <kdebug.h>
36 
37 #include <QVBoxLayout>
38 
39 
40 DeferAlarmDlg::DeferAlarmDlg(const DateTime& initialDT, bool anyTimeOption, bool cancelButton, QWidget* parent)
41  : KDialog(parent)
42 {
43  setWindowModality(Qt::WindowModal);
44  setCaption(i18nc("@title:window", "Defer Alarm"));
45  setButtons(Ok | Cancel | User1);
46  setButtonGuiItem(User1, KGuiItem(i18nc("@action:button", "Cancel Deferral")));
47  if (!cancelButton)
48  showButton(User1, false);
49  connect(this, SIGNAL(okClicked()), SLOT(slotOk()));
50  connect(this, SIGNAL(user1Clicked()), SLOT(slotCancelDeferral()));
51 
52  QWidget* page = new QWidget(this);
53  setMainWidget(page);
54  QVBoxLayout* layout = new QVBoxLayout(page);
55  layout->setMargin(0);
56  layout->setSpacing(spacingHint());
57 
58  mTimeWidget = new AlarmTimeWidget((anyTimeOption ? AlarmTimeWidget::DEFER_ANY_TIME : AlarmTimeWidget::DEFER_TIME), page);
59  mTimeWidget->setDateTime(initialDT);
60  mTimeWidget->setMinDateTimeIsCurrent();
61  connect(mTimeWidget, SIGNAL(pastMax()), SLOT(slotPastLimit()));
62  layout->addWidget(mTimeWidget);
63  layout->addSpacing(spacingHint());
64 
65  setButtonWhatsThis(Ok, i18nc("@info:whatsthis", "Defer the alarm until the specified time."));
66  setButtonWhatsThis(User1, i18nc("@info:whatsthis", "Cancel the deferred alarm. This does not affect future recurrences."));
67 }
68 
69 
70 /******************************************************************************
71 * Called when the OK button is clicked.
72 */
73 void DeferAlarmDlg::slotOk()
74 {
75  mAlarmDateTime = mTimeWidget->getDateTime(&mDeferMinutes);
76  if (!mAlarmDateTime.isValid())
77  return;
78  KAEvent::DeferLimitType limitType = KAEvent::LIMIT_NONE;
79  DateTime endTime;
80  if (!mLimitEventId.isEmpty())
81  {
82  // Get the event being deferred
83  const KAEvent* event = AlarmCalendar::getEvent(mLimitEventId);
84  if (event)
85  endTime = event->deferralLimit(&limitType);
86  }
87  else
88  {
89  endTime = mLimitDateTime;
90  limitType = mLimitDateTime.isValid() ? KAEvent::LIMIT_MAIN : KAEvent::LIMIT_NONE;
91  }
92  if (endTime.isValid() && mAlarmDateTime > endTime)
93  {
94  QString text;
95  switch (limitType)
96  {
97  case KAEvent::LIMIT_REPETITION:
98  text = i18nc("@info", "Cannot defer past the alarm's next sub-repetition (currently %1)",
99  endTime.formatLocale());
100  break;
101  case KAEvent::LIMIT_RECURRENCE:
102  text = i18nc("@info", "Cannot defer past the alarm's next recurrence (currently %1)",
103  endTime.formatLocale());
104  break;
105  case KAEvent::LIMIT_REMINDER:
106  text = i18nc("@info", "Cannot defer past the alarm's next reminder (currently %1)",
107  endTime.formatLocale());
108  break;
109  case KAEvent::LIMIT_MAIN:
110  text = i18nc("@info", "Cannot defer reminder past the main alarm time (%1)",
111  endTime.formatLocale());
112  break;
113  case KAEvent::LIMIT_NONE:
114  break; // can't happen with a valid endTime
115  }
116  KAMessageBox::sorry(this, text);
117  }
118  else
119  accept();
120 }
121 
122 /******************************************************************************
123 * Select the 'Time from now' radio button and preset its value.
124 */
125 void DeferAlarmDlg::setDeferMinutes(int minutes)
126 {
127  mTimeWidget->selectTimeFromNow(minutes);
128 }
129 
130 /******************************************************************************
131 * Called the maximum date/time for the date/time edit widget has been passed.
132 */
133 void DeferAlarmDlg::slotPastLimit()
134 {
135  enableButtonOk(false);
136 }
137 
138 /******************************************************************************
139 * Set the time limit for deferral based on the next occurrence of the alarm
140 * with the specified ID.
141 */
142 void DeferAlarmDlg::setLimit(const DateTime& limit)
143 {
144  mLimitEventId.clear();
145  mLimitDateTime = limit;
146  mTimeWidget->setMaxDateTime(mLimitDateTime);
147 }
148 
149 /******************************************************************************
150 * Set the time limit for deferral based on the next occurrence of the alarm
151 * with the specified ID.
152 */
153 DateTime DeferAlarmDlg::setLimit(const KAEvent& event)
154 {
155 #ifdef USE_AKONADI
156  Q_ASSERT(event.collectionId() >= 0);
157  mLimitEventId = EventId(event);
158 #else
159  mLimitEventId = event.id();
160 #endif
161  const KAEvent* evnt = AlarmCalendar::getEvent(mLimitEventId);
162  mLimitDateTime = evnt ? evnt->deferralLimit() : DateTime();
163  mTimeWidget->setMaxDateTime(mLimitDateTime);
164  return mLimitDateTime;
165 }
166 
167 /******************************************************************************
168 * Called when the Cancel Deferral button is clicked.
169 */
170 void DeferAlarmDlg::slotCancelDeferral()
171 {
172  mAlarmDateTime = DateTime();
173  accept();
174 }
175 #include "moc_deferdlg.cpp"
176 // vim: et sw=4:
DeferAlarmDlg::slotCancelDeferral
virtual void slotCancelDeferral()
Definition: deferdlg.cpp:170
QWidget
AlarmTimeWidget::setMinDateTimeIsCurrent
void setMinDateTimeIsCurrent()
Definition: alarmtimewidget.cpp:396
alarmtimewidget.h
text
virtual QByteArray text(quint32 serialNumber) const =0
deferdlg.h
alarmcalendar.h
AlarmTimeWidget
Definition: alarmtimewidget.h:41
KDialog
DeferAlarmDlg::setDeferMinutes
void setDeferMinutes(int mins)
Definition: deferdlg.cpp:125
QBoxLayout::addSpacing
void addSpacing(int size)
AlarmTimeWidget::setDateTime
void setDateTime(const DateTime &)
Definition: alarmtimewidget.cpp:358
AlarmTimeWidget::DEFER_ANY_TIME
Definition: alarmtimewidget.h:48
AlarmTimeWidget::DEFER_TIME
Definition: alarmtimewidget.h:47
QString::clear
void clear()
AlarmCalendar::getEvent
static KAEvent * getEvent(const QString &uniqueId)
Definition: alarmcalendar.cpp:150
kalarmapp.h
the KAlarm application object
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QString::isEmpty
bool isEmpty() const
QVBoxLayout
messagebox.h
QString
QLayout::setMargin
void setMargin(int margin)
DeferAlarmDlg::slotOk
virtual void slotOk()
Definition: deferdlg.cpp:73
AlarmTimeWidget::getDateTime
KDateTime getDateTime(int *minsFromNow=0, bool checkExpired=true, bool showErrorMessage=true, QWidget **errorWidget=0) const
Definition: alarmtimewidget.cpp:280
AlarmTimeWidget::setMaxDateTime
void setMaxDateTime(const DateTime &=DateTime())
Definition: alarmtimewidget.cpp:421
EventId
Unique event identifier for Akonadi.
Definition: eventid.h:38
functions.h
miscellaneous functions
KAMessageBox::sorry
static void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Options(Notify|WindowModal))
DeferAlarmDlg::setLimit
void setLimit(const DateTime &)
Definition: deferdlg.cpp:142
kalarm.h
DeferAlarmDlg::DeferAlarmDlg
DeferAlarmDlg(const DateTime &initialDT, bool anyTimeOption, bool cancelButton, QWidget *parent=0)
Definition: deferdlg.cpp:40
QBoxLayout::setSpacing
void setSpacing(int spacing)
AlarmTimeWidget::selectTimeFromNow
void selectTimeFromNow(int minutes=0)
Definition: alarmtimewidget.cpp:264
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