21 #include "birthdaydlg.moc"
38 #include <akonadi/control.h>
39 #include <akonadi/entitymimetypefiltermodel.h>
43 #include <kconfiggroup.h>
44 #include <kmessagebox.h>
45 #include <kstandardaction.h>
46 #include <kactioncollection.h>
47 #include <kdescendantsproxymodel.h>
55 #include <QHeaderView>
56 #include <QHBoxLayout>
57 #include <QVBoxLayout>
64 mSpecialActionsButton(0)
66 setObjectName(QLatin1String(
"BirthdayDlg"));
67 setCaption(i18nc(
"@title:window",
"Import Birthdays From KAddressBook"));
68 setButtons(Ok | Cancel);
71 connect(
this, SIGNAL(okClicked()), SLOT(
slotOk()));
74 setMainWidget(topWidget);
75 QVBoxLayout* topLayout =
new QVBoxLayout(topWidget);
76 topLayout->setMargin(0);
77 topLayout->setSpacing(spacingHint());
81 KConfigGroup config(KGlobal::config(),
"General");
82 mPrefixText = config.readEntry(
"BirthdayPrefix", i18nc(
"@info/plain",
"Birthday: "));
83 mSuffixText = config.readEntry(
"BirthdaySuffix");
86 topLayout->addWidget(textGroup);
87 QGridLayout* grid =
new QGridLayout(textGroup);
88 grid->setMargin(marginHint());
89 grid->setSpacing(spacingHint());
90 QLabel* label =
new QLabel(i18nc(
"@label:textbox",
"Prefix:"), textGroup);
91 label->setFixedSize(label->sizeHint());
92 grid->addWidget(label, 0, 0);
93 mPrefix =
new BLineEdit(mPrefixText, textGroup);
94 mPrefix->setMinimumSize(mPrefix->sizeHint());
95 label->setBuddy(mPrefix);
96 connect(mPrefix, SIGNAL(focusLost()), SLOT(slotTextLostFocus()));
97 mPrefix->setWhatsThis(i18nc(
"@info:whatsthis",
98 "Enter text to appear before the person's name in the alarm message, "
99 "including any necessary trailing spaces."));
100 grid->addWidget(mPrefix, 0, 1);
102 label =
new QLabel(i18nc(
"@label:textbox",
"Suffix:"), textGroup);
103 label->setFixedSize(label->sizeHint());
104 grid->addWidget(label, 1, 0);
105 mSuffix =
new BLineEdit(mSuffixText, textGroup);
106 mSuffix->setMinimumSize(mSuffix->sizeHint());
107 label->setBuddy(mSuffix);
108 connect(mSuffix, SIGNAL(focusLost()), SLOT(slotTextLostFocus()));
109 mSuffix->setWhatsThis(i18nc(
"@info:whatsthis",
110 "Enter text to appear after the person's name in the alarm message, "
111 "including any necessary leading spaces."));
112 grid->addWidget(mSuffix, 1, 1);
114 QGroupBox* group =
new QGroupBox(i18nc(
"@title:group",
"Select Birthdays"), topWidget);
115 topLayout->addWidget(group);
116 QVBoxLayout* layout =
new QVBoxLayout(group);
117 layout->setMargin(0);
120 Akonadi::Control::start();
123 connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(resizeViewColumns()));
126 descendantsModel->setSourceModel(model);
128 Akonadi::EntityMimeTypeFilterModel* mimeTypeFilter =
new Akonadi::EntityMimeTypeFilterModel(
this);
129 mimeTypeFilter->setSourceModel(descendantsModel);
130 mimeTypeFilter->addMimeTypeExclusionFilter(Akonadi::Collection::mimeType());
131 mimeTypeFilter->setHeaderGroup(Akonadi::EntityTreeModel::ItemListHeaders);
134 mBirthdaySortModel->setSourceModel(mimeTypeFilter);
135 mBirthdaySortModel->setSortCaseSensitivity(Qt::CaseInsensitive);
138 mListView->setEditTriggers(QAbstractItemView::NoEditTriggers);
139 mListView->setModel(mBirthdaySortModel);
140 mListView->setRootIsDecorated(
false);
141 mListView->setSortingEnabled(
true);
143 mListView->setAllColumnsShowFocus(
true);
144 mListView->setSelectionMode(QAbstractItemView::ExtendedSelection);
145 mListView->setSelectionBehavior(QAbstractItemView::SelectRows);
146 mListView->setTextElideMode(Qt::ElideRight);
149 connect(mListView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(slotSelectionChanged()));
150 mListView->setWhatsThis(i18nc(
"@info:whatsthis",
151 "<para>Select birthdays to set alarms for.<nl/>"
152 "This list shows all birthdays in <application>KAddressBook</application> except those for which alarms already exist.</para>"
153 "<para>You can select multiple birthdays at one time by dragging the mouse over the list, "
154 "or by clicking the mouse while pressing Ctrl or Shift.</para>"));
155 layout->addWidget(mListView);
157 group =
new QGroupBox(i18nc(
"@title:group",
"Alarm Configuration"), topWidget);
158 topLayout->addWidget(group);
159 QVBoxLayout* groupLayout =
new QVBoxLayout(group);
160 groupLayout->setMargin(marginHint());
161 groupLayout->setSpacing(spacingHint());
164 QHBoxLayout* hlayout =
new QHBoxLayout();
165 hlayout->setMargin(0);
166 groupLayout->addLayout(hlayout);
168 mSoundPicker->setFixedSize(mSoundPicker->sizeHint());
169 hlayout->addWidget(mSoundPicker);
170 hlayout->addSpacing(2*spacingHint());
171 hlayout->addStretch();
175 mFontColourButton->setMaximumHeight(mFontColourButton->sizeHint().height() * 3/2);
176 hlayout->addWidget(mFontColourButton);
177 connect(mFontColourButton, SIGNAL(selected(QColor,QColor)), SLOT(setColours(QColor,QColor)));
180 mReminder =
new Reminder(i18nc(
"@info:whatsthis",
"Check to display a reminder in advance of or after the birthday."),
181 i18nc(
"@info:whatsthis",
"Enter the number of days before or after each birthday to display a reminder. "
182 "This is in addition to the alarm which is displayed on the birthday."),
183 i18nc(
"@info:whatsthis",
"Select whether the reminder should be triggered before or after the birthday."),
184 false,
false, group);
185 mReminder->setFixedSize(mReminder->sizeHint());
188 groupLayout->addWidget(mReminder, 0, Qt::AlignLeft);
191 hlayout =
new QHBoxLayout();
192 hlayout->setMargin(0);
193 hlayout->setSpacing(2*spacingHint());
194 groupLayout->addLayout(hlayout);
196 mConfirmAck->setFixedSize(mConfirmAck->sizeHint());
197 hlayout->addWidget(mConfirmAck);
198 hlayout->addSpacing(2*spacingHint());
199 hlayout->addStretch();
205 mSpecialActionsButton->setFixedSize(mSpecialActionsButton->sizeHint());
206 hlayout->addWidget(mSpecialActionsButton);
210 hlayout =
new QHBoxLayout();
211 hlayout->setMargin(0);
212 hlayout->setSpacing(2*spacingHint());
213 groupLayout->addLayout(hlayout);
215 mLateCancel->setFixedSize(mLateCancel->sizeHint());
216 hlayout->addWidget(mLateCancel);
217 hlayout->addStretch();
220 mSubRepetition =
new RepetitionButton(i18nc(
"@action:button",
"Sub-Repetition"),
false, group);
221 mSubRepetition->setFixedSize(mSubRepetition->sizeHint());
222 mSubRepetition->
set(Repetition(),
true, 364*24*60);
223 mSubRepetition->setWhatsThis(i18nc(
"@info:whatsthis",
"Set up an additional alarm repetition"));
224 hlayout->addWidget(mSubRepetition);
235 if (mSpecialActionsButton)
237 KAEvent::ExtraActionOptions opts(0);
239 opts |= KAEvent::ExecPreActOnDeferral;
241 opts |= KAEvent::CancelOnPreActError;
243 opts |= KAEvent::DontShowPreActError;
247 KActionCollection* actions =
new KActionCollection(
this);
248 KStandardAction::selectAll(mListView, SLOT(selectAll()), actions);
249 KStandardAction::deselect(mListView, SLOT(clearSelection()), actions);
250 actions->addAssociatedWidget(mListView);
251 foreach (QAction* action, actions->actions())
252 action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
254 enableButtonOk(
false);
262 QVector<KAEvent> list;
263 QModelIndexList
indexes = mListView->selectionModel()->selectedRows();
264 int count = indexes.count();
267 QDate today = KDateTime::currentLocalDate();
268 KDateTime todayStart(today, KDateTime::ClockTime);
269 int thisYear = today.year();
270 int reminder = mReminder->
minutes();
271 for (
int i = 0; i < count; ++i)
273 const QModelIndex nameIndex = indexes.at(i).model()->index(indexes.at(i).row(), 0);
274 const QModelIndex birthdayIndex = indexes.at(i).model()->index(indexes.at(i).row(), 1);
275 const QString name = nameIndex.data(Qt::DisplayRole).toString();
276 QDate
date = birthdayIndex.data(BirthdayModel::DateRole).toDate();
277 date.setYMD(thisYear, date.month(), date.day());
279 date.setYMD(thisYear + 1, date.month(), date.day());
280 KAEvent event(KDateTime(date, KDateTime::ClockTime),
281 mPrefix->text() + name + mSuffix->text(),
283 mFontColourButton->
font(), KAEvent::MESSAGE, mLateCancel->
minutes(),
287 float volume = mSoundPicker->
volume(fadeVolume, fadeSecs);
289 event.setAudioFile(mSoundPicker->
file().prettyUrl(), volume, fadeVolume, fadeSecs, repeatPause);
290 QVector<int> months(1, date.month());
291 event.setRecurAnnualByDate(1, months, 0, KARecurrence::defaultFeb29Type(), -1, QDate());
292 event.setRepetition(mSubRepetition->
repetition());
293 event.setNextOccurrence(todayStart);
295 event.setReminder(reminder,
false);
296 if (mSpecialActionsButton)
297 event.setActions(mSpecialActionsButton->
preAction(),
299 mSpecialActionsButton->
options());
312 KConfigGroup config(KGlobal::config(),
"General");
313 config.writeEntry(
"BirthdayPrefix", mPrefix->text());
314 config.writeEntry(
"BirthdaySuffix", mSuffix->text());
317 mFlags = KAEvent::ANY_TIME;
319 if (mSoundPicker->
repeatPause() >= 0) mFlags |= KAEvent::REPEAT_SOUND;
320 if (mConfirmAck->isChecked()) mFlags |= KAEvent::CONFIRM_ACK;
321 if (mFontColourButton->
defaultFont()) mFlags |= KAEvent::DEFAULT_FONT;
329 void BirthdayDlg::slotSelectionChanged()
331 enableButtonOk(mListView->selectionModel()->hasSelection());
338 void BirthdayDlg::setColours(
const QColor& fgColour,
const QColor& bgColour)
340 QPalette pal = mPrefix->palette();
341 pal.setColor(mPrefix->backgroundRole(), bgColour);
342 pal.setColor(mPrefix->foregroundRole(), fgColour);
343 mPrefix->setPalette(pal);
344 mSuffix->setPalette(pal);
351 void BirthdayDlg::resizeViewColumns()
361 void BirthdayDlg::slotTextLostFocus()
363 QString prefix = mPrefix->text();
364 QString suffix = mSuffix->text();
365 if (prefix != mPrefixText || suffix != mSuffixText)
368 mPrefixText = prefix;
369 mSuffixText = suffix;
Preferences::SoundType sound() const
Returns the selected option.
KUrl file() const
If the 'file' option is selected, returns the URL of the chosen file.
void setPrefixSuffix(const QString &prefix, const QString &suffix)
static QColor defaultBgColour()
Get Background color.
float volume(float &fadeVolume, int &fadeSeconds) const
Returns the volume and fade characteristics for playing a sound file.
static QString defaultPreAction()
Get Pre-alarm action.
Provides the global model for all contacts.
static bool defaultSoundRepeat()
Get Repeat sound file.
static SoundType defaultSoundType()
Get Sound.
static BirthdayModel * instance()
Returns the global contact model instance.
the KAlarm application object
static QString defaultPostAction()
Get Post-alarm action.
void setMinutes(int minutes, bool dateOnly)
static CheckBox * createConfirmAckCheckbox(QWidget *parent)
void set(Preferences::SoundType type, const QString &filename, float volume, float fadeVolume, int fadeSeconds, int repeatPause)
Initialises the widget's state.
BirthdayDlg(QWidget *parent=0)
static bool defaultExecPreActionOnDeferral()
Get Execute pre-alarm action for deferred alarms.
static bool defaultDontShowPreActionError()
Get Do not notify pre-alarm action errors.
int repeatPause() const
Returns pause in seconds between repetitions of the sound file, or -1 if no repeat or 'file' option i...
static int defaultLateCancel()
Get Cancel if late (minutes)
QVector< KAEvent > events() const
static bool defaultConfirmAck()
Get Confirm acknowledgement.
static bool defaultCancelOnPreActionError()
Get Cancel alarm on pre-alarm action error.
static QColor defaultFgColour()
Get Foreground color.
static QString defaultSoundFile()
Get Sound file.
void setMaximum(int hourmin, int days)
static QMap< Preferences::SoundType, int > indexes
void setMinutes(int Minutes, bool dateOnly, TimePeriod::Units defaultUnits)
static float defaultSoundVolume()