• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

KCalUtils Library

  • sources
  • kde-4.14
  • kdepimlibs
  • kcalutils
recurrenceactions.cpp
1 /*
2  This file is part of the kcal library.
3 
4  Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
5  Author: Kevin Krammer, krake@kdab.com
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "recurrenceactions.h"
24 
25 #include "ui_recurrenceactionsscopewidget.h"
26 
27 #include <KDialog>
28 #include <KLocale>
29 #include <KLocalizedString>
30 #include <KMessageBox>
31 #include <KGlobal>
32 
33 #include <QPointer>
34 
35 #include <boost/shared_ptr.hpp>
36 
37 using namespace KCalUtils;
38 using namespace KCalUtils::RecurrenceActions;
39 using namespace KCalCore;
40 
41 class ScopeWidget : public QWidget
42 {
43 public:
44  ScopeWidget(int availableChoices, const KDateTime &dateTime, QWidget *parent)
45  : QWidget(parent), mAvailableChoices(availableChoices)
46  {
47  mUi.setupUi(this);
48 
49  if ((mAvailableChoices & PastOccurrences) == 0) {
50  mUi.checkBoxPast->hide();
51  } else {
52  mUi.checkBoxPast->setText(i18nc("@option:check calendar items before a certain date",
53  "Items before %1",
54  KGlobal::locale()->formatDateTime(dateTime)));
55  }
56  if ((mAvailableChoices & SelectedOccurrence) == 0) {
57  mUi.checkBoxSelected->hide();
58  } else {
59  mUi.checkBoxSelected->setText(i18nc("@option:check currently selected calendar item",
60  "Selected item"));
61  }
62  if ((mAvailableChoices & FutureOccurrences) == 0) {
63  mUi.checkBoxFuture->hide();
64  } else {
65  mUi.checkBoxFuture->setText(i18nc("@option:check calendar items after a certain date",
66  "Items after %1",
67  KGlobal::locale()->formatDateTime(dateTime)));
68  }
69  }
70 
71  void setMessage(const QString &message);
72  void setIcon(const QIcon &icon);
73 
74  void setCheckedChoices(int choices);
75  int checkedChoices() const;
76 
77 private:
78  const int mAvailableChoices;
79  Ui_RecurrenceActionsScopeWidget mUi;
80 };
81 
82 void ScopeWidget::setMessage(const QString &message)
83 {
84  mUi.messageLabel->setText(message);
85 }
86 
87 void ScopeWidget::setIcon(const QIcon &icon)
88 {
89  QStyleOption option;
90  option.initFrom(this);
91  mUi.iconLabel->setPixmap(
92  icon.pixmap(style()->pixelMetric(QStyle::PM_MessageBoxIconSize, &option, this)));
93 }
94 
95 void ScopeWidget::setCheckedChoices(int choices)
96 {
97  // mask with available ones
98  choices &= mAvailableChoices;
99 
100  mUi.checkBoxPast->setChecked((choices & PastOccurrences) != 0);
101  mUi.checkBoxSelected->setChecked((choices & SelectedOccurrence) != 0);
102  mUi.checkBoxFuture->setChecked((choices & FutureOccurrences) != 0);
103 }
104 
105 int ScopeWidget::checkedChoices() const
106 {
107  int result = NoOccurrence;
108 
109  if (mUi.checkBoxPast->isChecked()) {
110  result |= PastOccurrences;
111  }
112  if (mUi.checkBoxSelected->isChecked()) {
113  result |= SelectedOccurrence;
114  }
115  if (mUi.checkBoxFuture->isChecked()) {
116  result |= FutureOccurrences;
117  }
118 
119  return result;
120 }
121 
122 int RecurrenceActions::availableOccurrences(const Incidence::Ptr &incidence,
123  const KDateTime &selectedOccurrence)
124 {
125  int result = NoOccurrence;
126 
127  if (incidence->recurrence()->recursOn(selectedOccurrence.date(),
128  selectedOccurrence.timeSpec())) {
129  result |= SelectedOccurrence;
130  }
131 
132  if (incidence->recurrence()->getPreviousDateTime(selectedOccurrence).isValid()) {
133  result |= PastOccurrences;
134  }
135 
136  if (incidence->recurrence()->getNextDateTime(selectedOccurrence).isValid()) {
137  result |= FutureOccurrences;
138  }
139 
140  return result;
141 }
142 
143 int RecurrenceActions::questionMultipleChoice(const KDateTime &selectedOccurrence,
144  const QString &message, const QString &caption,
145  const KGuiItem &action, int availableChoices,
146  int preselectedChoices, QWidget *parent)
147 {
148  QPointer<KDialog> dialog = new KDialog(parent);
149  dialog->setCaption(caption);
150  dialog->setButtons(KDialog::Ok | KDialog::Cancel);
151  dialog->setDefaultButton(KDialog::Ok);
152  dialog->setButtonGuiItem(KDialog::Ok, action);
153 
154  ScopeWidget *widget = new ScopeWidget(availableChoices, selectedOccurrence, dialog);
155  dialog->setMainWidget(widget);
156 
157  widget->setMessage(message);
158  widget->setIcon(widget->style()->standardIcon(QStyle::SP_MessageBoxQuestion));
159  widget->setCheckedChoices(preselectedChoices);
160 
161  const int result = dialog->exec();
162  if (dialog) {
163  dialog->deleteLater();
164  }
165 
166  if (result == QDialog::Rejected) {
167  return NoOccurrence;
168  }
169 
170  return widget->checkedChoices();
171 }
172 
173 int RecurrenceActions::questionSelectedAllCancel(const QString &message, const QString &caption,
174  const KGuiItem &actionSelected,
175  const KGuiItem &actionAll, QWidget *parent)
176 {
177  KDialog *dialog = new KDialog(parent);
178  dialog->setCaption(caption);
179  dialog->setButtons(KDialog::Yes | KDialog::Ok | KDialog::Cancel);
180  dialog->setObjectName(QLatin1String("RecurrenceActions::questionSelectedAllCancel"));
181  dialog->setDefaultButton(KDialog::Yes);
182  dialog->setButtonGuiItem(KDialog::Yes, actionSelected);
183  dialog->setButtonGuiItem(KDialog::Ok, actionAll);
184 
185  bool checkboxResult = false;
186  int result = KMessageBox::createKMessageBox(
187  dialog,
188  QMessageBox::Question,
189  message,
190  QStringList(),
191  QString(),
192  &checkboxResult,
193  KMessageBox::Notify);
194 
195  switch (result) {
196  case KDialog::Yes:
197  return SelectedOccurrence;
198  case QDialog::Accepted:
199  // See kdialog.h, 'Ok' doesn't return KDialog:Ok
200  return AllOccurrences;
201  default:
202  return NoOccurrence;
203  }
204 
205  return NoOccurrence;
206 }
207 
208 int RecurrenceActions::questionSelectedFutureAllCancel(const QString &message,
209  const QString &caption,
210  const KGuiItem &actionSelected,
211  const KGuiItem &actionFuture,
212  const KGuiItem &actionAll,
213  QWidget *parent)
214 {
215  KDialog *dialog = new KDialog(parent);
216  dialog->setCaption(caption);
217  dialog->setButtons(KDialog::Yes | KDialog::No | KDialog::Ok | KDialog::Cancel);
218  dialog->setObjectName(QLatin1String("RecurrenceActions::questionSelectedFutureAllCancel"));
219  dialog->setDefaultButton(KDialog::Yes);
220  dialog->setButtonGuiItem(KDialog::Yes, actionSelected);
221  dialog->setButtonGuiItem(KDialog::No, actionFuture);
222  dialog->setButtonGuiItem(KDialog::Ok, actionAll);
223 
224  bool checkboxResult = false;
225  int result = KMessageBox::createKMessageBox(
226  dialog,
227  QMessageBox::Question,
228  message,
229  QStringList(),
230  QString(),
231  &checkboxResult,
232  KMessageBox::Notify);
233 
234  switch (result) {
235  case KDialog::Yes:
236  return SelectedOccurrence;
237  case KDialog::No:
238  return FutureOccurrences;
239  case QDialog::Accepted:
240  return AllOccurrences;
241  default:
242  return NoOccurrence;
243  }
244 
245  return NoOccurrence;
246 }
247 
248 // kate: space-indent on; indent-width 2; replace-tabs on;
QWidget
QWidget::setupUi
void setupUi(QWidget *widget)
QWidget::setIcon
void setIcon(const QPixmap &i)
KCalUtils::RecurrenceActions::PastOccurrences
Scope does include occurrences before the given/selected occurrence.
Definition: recurrenceactions.h:66
KCalUtils::RecurrenceActions::availableOccurrences
KCALUTILS_EXPORT int availableOccurrences(const KCalCore::Incidence::Ptr &incidence, const KDateTime &selectedOccurrence)
Checks what scope an action could be applied on for a given incidence.
QPointer
KCalUtils::RecurrenceActions::questionMultipleChoice
KCALUTILS_EXPORT int questionMultipleChoice(const KDateTime &selectedOccurrence, const QString &message, const QString &caption, const KGuiItem &action, int availableChoices, int preselectedChoices, QWidget *parent)
Presents a multiple choice scope selection dialog to the user.
Definition: recurrenceactions.cpp:143
KCalUtils::Stringify::formatDateTime
KCALUTILS_EXPORT QString formatDateTime(const KDateTime &dt, bool dateOnly=false, bool shortfmt=true, const KDateTime::Spec &spec=KDateTime::Spec())
Build a QString date/time representation of a KDateTime object.
Definition: stringify.cpp:242
QIcon::pixmap
QPixmap pixmap(const QSize &size, Mode mode, State state) const
QStyleOption::initFrom
void initFrom(const QWidget *widget)
QStyleOption
KCalUtils::RecurrenceActions::NoOccurrence
Scope does not apply to any occurrence.
Definition: recurrenceactions.h:56
QString
KCalUtils::RecurrenceActions::AllOccurrences
Scope does include all occurrences (past, present and future)
Definition: recurrenceactions.h:76
QStringList
KCalUtils::RecurrenceActions::SelectedOccurrence
Scope does include the given/selected occurrence.
Definition: recurrenceactions.h:61
KCalUtils::RecurrenceActions::FutureOccurrences
Scope does include occurrences after the given/selected occurrence.
Definition: recurrenceactions.h:71
QLatin1String
KCalUtils::RecurrenceActions::questionSelectedAllCancel
KCALUTILS_EXPORT int questionSelectedAllCancel(const QString &message, const QString &caption, const KGuiItem &actionSelected, const KGuiItem &actionAll, QWidget *parent)
Presents a message box with two action choices and cancel to the user.
Definition: recurrenceactions.cpp:173
KCalUtils::RecurrenceActions::questionSelectedFutureAllCancel
KCALUTILS_EXPORT int questionSelectedFutureAllCancel(const QString &message, const QString &caption, const KGuiItem &actionSelected, const KGuiItem &actionFuture, const KGuiItem &actionAll, QWidget *parent)
Presents a message box with three action choices and cancel to the user.
Definition: recurrenceactions.cpp:208
QIcon
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:46 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCalUtils Library

Skip menu "KCalUtils Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

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