23 #include "recurrenceactions.h"
25 #include "ui_recurrenceactionsscopewidget.h"
29 #include <KLocalizedString>
30 #include <KMessageBox>
35 #include <boost/shared_ptr.hpp>
37 using namespace KCalUtils;
38 using namespace KCalUtils::RecurrenceActions;
39 using namespace KCalCore;
41 class ScopeWidget :
public QWidget
44 ScopeWidget(
int availableChoices,
const KDateTime &dateTime, QWidget *parent )
45 : QWidget( parent ), mAvailableChoices( availableChoices )
49 if ( ( mAvailableChoices & PastOccurrences ) == 0 ) {
50 mUi.checkBoxPast->hide();
52 mUi.checkBoxPast->setText( i18nc(
"@option:check calendar items before a certain date",
56 if ( ( mAvailableChoices & SelectedOccurrence ) == 0 ) {
57 mUi.checkBoxSelected->hide();
59 mUi.checkBoxSelected->setText( i18nc(
"@option:check currently selected calendar item",
62 if ( ( mAvailableChoices & FutureOccurrences ) == 0 ) {
63 mUi.checkBoxFuture->hide();
65 mUi.checkBoxFuture->setText( i18nc(
"@option:check calendar items after a certain date",
71 void setMessage(
const QString &message );
72 void setIcon(
const QIcon &icon );
74 void setCheckedChoices(
int choices );
75 int checkedChoices()
const;
78 const int mAvailableChoices;
79 Ui_RecurrenceActionsScopeWidget mUi;
82 void ScopeWidget::setMessage(
const QString &message )
84 mUi.messageLabel->setText( message );
87 void ScopeWidget::setIcon(
const QIcon &icon )
90 option.initFrom(
this );
91 mUi.iconLabel->setPixmap(
92 icon.pixmap( style()->pixelMetric( QStyle::PM_MessageBoxIconSize, &option,
this ) ) );
95 void ScopeWidget::setCheckedChoices(
int choices )
98 choices &= mAvailableChoices;
100 mUi.checkBoxPast->setChecked( ( choices & PastOccurrences ) != 0 );
101 mUi.checkBoxSelected->setChecked( ( choices & SelectedOccurrence ) != 0 );
102 mUi.checkBoxFuture->setChecked( ( choices & FutureOccurrences ) != 0 );
105 int ScopeWidget::checkedChoices()
const
109 if ( mUi.checkBoxPast->isChecked() ) {
110 result |= PastOccurrences;
112 if ( mUi.checkBoxSelected->isChecked() ) {
113 result |= SelectedOccurrence;
115 if ( mUi.checkBoxFuture->isChecked() ) {
116 result |= FutureOccurrences;
123 const KDateTime &selectedOccurrence )
127 if ( incidence->recurrence()->recursOn( selectedOccurrence.date(),
128 selectedOccurrence.timeSpec() ) ) {
129 result |= SelectedOccurrence;
132 if ( incidence->recurrence()->getPreviousDateTime( selectedOccurrence ).isValid() ) {
133 result |= PastOccurrences;
136 if ( incidence->recurrence()->getNextDateTime( selectedOccurrence ).isValid() ) {
137 result |= FutureOccurrences;
144 const QString &message,
const QString &caption,
145 const KGuiItem &action,
int availableChoices,
146 int preselectedChoices, QWidget *parent )
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 );
154 ScopeWidget *widget =
new ScopeWidget( availableChoices, selectedOccurrence, dialog );
155 dialog->setMainWidget( widget );
157 widget->setMessage( message );
158 widget->setIcon( widget->style()->standardIcon( QStyle::SP_MessageBoxQuestion ) );
159 widget->setCheckedChoices( preselectedChoices );
161 const int result = dialog->exec();
163 dialog->deleteLater();
166 if ( result == QDialog::Rejected ) {
170 return widget->checkedChoices();
174 const KGuiItem &actionSelected,
175 const KGuiItem &actionAll, QWidget *parent )
177 KDialog *dialog =
new KDialog( parent );
178 dialog->setCaption( caption );
179 dialog->setButtons( KDialog::Yes | KDialog::Ok | KDialog::Cancel );
180 dialog->setObjectName(
"RecurrenceActions::questionSelectedAllCancel" );
181 dialog->setDefaultButton( KDialog::Yes );
182 dialog->setButtonGuiItem( KDialog::Yes, actionSelected );
183 dialog->setButtonGuiItem( KDialog::Ok, actionAll );
185 bool checkboxResult =
false;
186 int result = KMessageBox::createKMessageBox(
188 QMessageBox::Question,
193 KMessageBox::Notify );
197 return SelectedOccurrence;
198 case QDialog::Accepted:
209 const QString &caption,
210 const KGuiItem &actionSelected,
211 const KGuiItem &actionFuture,
212 const KGuiItem &actionAll,
215 KDialog *dialog =
new KDialog( parent );
216 dialog->setCaption( caption );
217 dialog->setButtons( KDialog::Yes | KDialog::No | KDialog::Ok | KDialog::Cancel );
218 dialog->setObjectName(
"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 );
224 bool checkboxResult =
false;
225 int result = KMessageBox::createKMessageBox(
227 QMessageBox::Question,
232 KMessageBox::Notify );
236 return SelectedOccurrence;
238 return FutureOccurrences;
239 case QDialog::Accepted:
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.
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.
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.
Scope does not apply to any occurrence.
Scope does include all occurrences (past, present and future)
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.
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.