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

KCalUtils Library

  • 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 <KMessageBox>
30 
31 #include <QPointer>
32 
33 #include <boost/shared_ptr.hpp>
34 
35 using namespace KCalUtils;
36 using namespace KCalUtils::RecurrenceActions;
37 using namespace KCalCore;
38 
39 class ScopeWidget : public QWidget
40 {
41  public:
42  ScopeWidget( int availableChoices, const KDateTime &dateTime, QWidget *parent )
43  : QWidget( parent ), mAvailableChoices( availableChoices )
44  {
45  mUi.setupUi( this );
46 
47  if ( ( mAvailableChoices & PastOccurrences ) == 0 ) {
48  mUi.checkBoxPast->hide();
49  } else {
50  mUi.checkBoxPast->setText( i18nc( "@option:check calendar items before a certain date",
51  "Items before %1",
52  KGlobal::locale()->formatDateTime( dateTime ) ) );
53  }
54  if ( ( mAvailableChoices & SelectedOccurrence ) == 0 ) {
55  mUi.checkBoxSelected->hide();
56  } else {
57  mUi.checkBoxSelected->setText( i18nc( "@option:check currently selected calendar item",
58  "Selected item" ) );
59  }
60  if ( ( mAvailableChoices & FutureOccurrences ) == 0 ) {
61  mUi.checkBoxFuture->hide();
62  } else {
63  mUi.checkBoxFuture->setText( i18nc( "@option:check calendar items after a certain date",
64  "Items after %1",
65  KGlobal::locale()->formatDateTime( dateTime ) ) );
66  }
67  }
68 
69  void setMessage( const QString &message );
70  void setIcon( const QIcon &icon );
71 
72  void setCheckedChoices( int choices );
73  int checkedChoices() const;
74 
75  private:
76  const int mAvailableChoices;
77  Ui_RecurrenceActionsScopeWidget mUi;
78 };
79 
80 void ScopeWidget::setMessage( const QString &message )
81 {
82  mUi.messageLabel->setText( message );
83 }
84 
85 void ScopeWidget::setIcon( const QIcon &icon )
86 {
87  QStyleOption option;
88  option.initFrom( this );
89  mUi.iconLabel->setPixmap(
90  icon.pixmap( style()->pixelMetric( QStyle::PM_MessageBoxIconSize, &option, this ) ) );
91 }
92 
93 void ScopeWidget::setCheckedChoices( int choices )
94 {
95  // mask with available ones
96  choices &= mAvailableChoices;
97 
98  mUi.checkBoxPast->setChecked( ( choices & PastOccurrences ) != 0 );
99  mUi.checkBoxSelected->setChecked( ( choices & SelectedOccurrence ) != 0 );
100  mUi.checkBoxFuture->setChecked( ( choices & FutureOccurrences ) != 0 );
101 }
102 
103 int ScopeWidget::checkedChoices() const
104 {
105  int result = NoOccurrence;
106 
107  if ( mUi.checkBoxPast->isChecked() ) {
108  result |= PastOccurrences;
109  }
110  if ( mUi.checkBoxSelected->isChecked() ) {
111  result |= SelectedOccurrence;
112  }
113  if ( mUi.checkBoxFuture->isChecked() ) {
114  result |= FutureOccurrences;
115  }
116 
117  return result;
118 }
119 
120 int RecurrenceActions::availableOccurrences( const Incidence::Ptr &incidence,
121  const KDateTime &selectedOccurrence )
122 {
123  int result = NoOccurrence;
124 
125  if ( incidence->recurrence()->recursOn( selectedOccurrence.date(),
126  selectedOccurrence.timeSpec() ) ) {
127  result |= SelectedOccurrence;
128  }
129 
130  if ( incidence->recurrence()->getPreviousDateTime( selectedOccurrence ).isValid() ) {
131  result |= PastOccurrences;
132  }
133 
134  if ( incidence->recurrence()->getNextDateTime( selectedOccurrence ).isValid() ) {
135  result |= FutureOccurrences;
136  }
137 
138  return result;
139 }
140 
141 int RecurrenceActions::questionMultipleChoice( const KDateTime &selectedOccurrence,
142  const QString &message, const QString &caption,
143  const KGuiItem &action, int availableChoices,
144  int preselectedChoices, QWidget *parent )
145 {
146  QPointer<KDialog> dialog = new KDialog( parent );
147  dialog->setCaption( caption );
148  dialog->setButtons( KDialog::Ok | KDialog::Cancel );
149  dialog->setDefaultButton( KDialog::Ok );
150  dialog->setButtonGuiItem( KDialog::Ok, action );
151 
152  ScopeWidget *widget = new ScopeWidget( availableChoices, selectedOccurrence, dialog );
153  dialog->setMainWidget( widget );
154 
155  widget->setMessage( message );
156  widget->setIcon( widget->style()->standardIcon( QStyle::SP_MessageBoxQuestion ) );
157  widget->setCheckedChoices( preselectedChoices );
158 
159  const int result = dialog->exec();
160  if ( dialog ) {
161  dialog->deleteLater();
162  }
163 
164  if ( result == QDialog::Rejected ) {
165  return NoOccurrence;
166  }
167 
168  return widget->checkedChoices();
169 }
170 
171 int RecurrenceActions::questionSelectedAllCancel( const QString &message, const QString &caption,
172  const KGuiItem &actionSelected,
173  const KGuiItem &actionAll, QWidget *parent )
174 {
175  KDialog *dialog = new KDialog( parent );
176  dialog->setCaption( caption );
177  dialog->setButtons( KDialog::Yes | KDialog::Ok | KDialog::Cancel );
178  dialog->setObjectName( "RecurrenceActions::questionSelectedAllCancel" );
179  dialog->setDefaultButton( KDialog::Yes );
180  dialog->setButtonGuiItem( KDialog::Yes, actionSelected );
181  dialog->setButtonGuiItem( KDialog::Ok, actionAll );
182 
183  bool checkboxResult = false;
184  int result = KMessageBox::createKMessageBox(
185  dialog,
186  QMessageBox::Question,
187  message,
188  QStringList(),
189  QString(),
190  &checkboxResult,
191  KMessageBox::Notify );
192 
193  switch (result) {
194  case KDialog::Yes:
195  return SelectedOccurrence;
196  case QDialog::Accepted:
197  // See kdialog.h, 'Ok' doesn't return KDialog:Ok
198  return AllOccurrences;
199  default:
200  return NoOccurrence;
201  }
202 
203  return NoOccurrence;
204 }
205 
206 int RecurrenceActions::questionSelectedFutureAllCancel( const QString &message,
207  const QString &caption,
208  const KGuiItem &actionSelected,
209  const KGuiItem &actionFuture,
210  const KGuiItem &actionAll,
211  QWidget *parent )
212 {
213  KDialog *dialog = new KDialog( parent );
214  dialog->setCaption( caption );
215  dialog->setButtons( KDialog::Yes | KDialog::No | KDialog::Ok | KDialog::Cancel );
216  dialog->setObjectName( "RecurrenceActions::questionSelectedFutureAllCancel" );
217  dialog->setDefaultButton( KDialog::Yes );
218  dialog->setButtonGuiItem( KDialog::Yes, actionSelected );
219  dialog->setButtonGuiItem( KDialog::No, actionFuture );
220  dialog->setButtonGuiItem( KDialog::Ok, actionAll );
221 
222  bool checkboxResult = false;
223  int result = KMessageBox::createKMessageBox(
224  dialog,
225  QMessageBox::Question,
226  message,
227  QStringList(),
228  QString(),
229  &checkboxResult,
230  KMessageBox::Notify );
231 
232  switch (result) {
233  case KDialog::Yes:
234  return SelectedOccurrence;
235  case KDialog::No:
236  return FutureOccurrences;
237  case QDialog::Accepted:
238  return AllOccurrences;
239  default:
240  return NoOccurrence;
241  }
242 
243  return NoOccurrence;
244 }
245 
246 // kate: space-indent on; indent-width 2; replace-tabs on;
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:26:46 by doxygen 1.8.3.1 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-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 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
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