24 #include <tqgroupbox.h>
27 #include <tqlineedit.h>
28 #include <tqwhatsthis.h>
30 #include <tdelocale.h>
31 #include <tdeglobal.h>
32 #include <tdeconfig.h>
33 #include <tdemessagebox.h>
35 #include <tdeabc/addressbook.h>
36 #include <tdeabc/stdaddressbook.h>
39 #include "alarmcalendar.h"
41 #include "colourcombo.h"
43 #include "fontcolourbutton.h"
45 #include "latecancel.h"
46 #include "preferences.h"
48 #include "repetition.h"
49 #include "shellprocess.h"
50 #include "soundpicker.h"
51 #include "specialactions.h"
52 #include "birthdaydlg.moc"
57 class AddresseeItem :
public TQListViewItem
60 enum columns { NAME = 0, BIRTHDAY = 1 };
61 AddresseeItem(TQListView* parent,
const TQString& name,
const TQDate& birthday);
62 TQDate birthday()
const {
return mBirthday; }
63 virtual TQString key(
int column,
bool ascending)
const;
66 TQString mBirthdayOrder;
70 const TDEABC::AddressBook* BirthdayDlg::mAddressBook = 0;
73 BirthdayDlg::BirthdayDlg(TQWidget* parent)
74 : KDialogBase(KDialogBase::Plain, i18n(
"Import Birthdays From KAddressBook"), Ok|Cancel, Ok, parent,
"BirthdayDlg"),
75 mSpecialActionsButton(0)
77 TQWidget* topWidget = plainPage();
78 TQBoxLayout* topLayout =
new TQVBoxLayout(topWidget);
79 topLayout->setSpacing(spacingHint());
83 TDEConfig* config = kapp->config();
84 config->setGroup(TQString::fromLatin1(
"General"));
85 mPrefixText = config->readEntry(TQString::fromLatin1(
"BirthdayPrefix"), i18n(
"Birthday: "));
86 mSuffixText = config->readEntry(TQString::fromLatin1(
"BirthdaySuffix"));
88 TQGroupBox* textGroup =
new TQGroupBox(2, TQt::Horizontal, i18n(
"Alarm Text"), topWidget);
89 topLayout->addWidget(textGroup);
90 TQLabel* label =
new TQLabel(i18n(
"Pre&fix:"), textGroup);
91 mPrefix =
new BLineEdit(mPrefixText, textGroup);
92 mPrefix->setMinimumSize(mPrefix->sizeHint());
93 label->setBuddy(mPrefix);
94 connect(mPrefix, TQ_SIGNAL(focusLost()), TQ_SLOT(slotTextLostFocus()));
95 TQWhatsThis::add(mPrefix,
96 i18n(
"Enter text to appear before the person's name in the alarm message, "
97 "including any necessary trailing spaces."));
99 label =
new TQLabel(i18n(
"S&uffix:"), textGroup);
100 mSuffix =
new BLineEdit(mSuffixText, textGroup);
101 mSuffix->setMinimumSize(mSuffix->sizeHint());
102 label->setBuddy(mSuffix);
103 connect(mSuffix, TQ_SIGNAL(focusLost()), TQ_SLOT(slotTextLostFocus()));
104 TQWhatsThis::add(mSuffix,
105 i18n(
"Enter text to appear after the person's name in the alarm message, "
106 "including any necessary leading spaces."));
108 TQGroupBox* group =
new TQGroupBox(1, TQt::Horizontal, i18n(
"Select Birthdays"), topWidget);
109 topLayout->addWidget(group);
110 mAddresseeList =
new BListView(group);
111 mAddresseeList->setMultiSelection(
true);
112 mAddresseeList->setSelectionMode(TQListView::Extended);
113 mAddresseeList->setAllColumnsShowFocus(
true);
114 mAddresseeList->setFullWidth(
true);
115 mAddresseeList->addColumn(i18n(
"Name"));
116 mAddresseeList->addColumn(i18n(
"Birthday"));
117 connect(mAddresseeList, TQ_SIGNAL(selectionChanged()), TQ_SLOT(slotSelectionChanged()));
118 TQWhatsThis::add(mAddresseeList,
119 i18n(
"Select birthdays to set alarms for.\n"
120 "This list shows all birthdays in KAddressBook except those for which alarms already exist.\n\n"
121 "You can select multiple birthdays at one time by dragging the mouse over the list, "
122 "or by clicking the mouse while pressing Ctrl or Shift."));
124 group =
new TQGroupBox(i18n(
"Alarm Configuration"), topWidget);
125 topLayout->addWidget(group);
126 TQBoxLayout* groupLayout =
new TQVBoxLayout(group, marginHint(), spacingHint());
127 groupLayout->addSpacing(fontMetrics().lineSpacing()/2);
130 mFontColourButton =
new FontColourButton(group);
131 mFontColourButton->setMaximumHeight(mFontColourButton->sizeHint().height() * 3/2);
132 groupLayout->addWidget(mFontColourButton);
135 mSoundPicker =
new SoundPicker(group);
136 mSoundPicker->setFixedSize(mSoundPicker->sizeHint());
137 groupLayout->addWidget(mSoundPicker, 0, TQt::AlignAuto);
140 mReminder =
new Reminder(i18n(
"&Reminder"),
141 i18n(
"Check to display a reminder in advance of the birthday."),
142 i18n(
"Enter the number of days before each birthday to display a reminder. "
143 "This is in addition to the alarm which is displayed on the birthday."),
144 false,
false, group);
145 mReminder->setFixedSize(mReminder->sizeHint());
146 mReminder->setMaximum(0, 364);
147 mReminder->setMinutes(0,
true);
148 groupLayout->addWidget(mReminder, 0, TQt::AlignAuto);
151 TQHBoxLayout* layout =
new TQHBoxLayout(groupLayout, 2*spacingHint());
152 mConfirmAck = EditAlarmDlg::createConfirmAckCheckbox(group);
153 layout->addWidget(mConfirmAck);
154 layout->addSpacing(2*spacingHint());
155 layout->addStretch();
157 if (ShellProcess::authorised())
160 mSpecialActionsButton =
new SpecialActionsButton(i18n(
"Special Actions..."), group);
161 layout->addWidget(mSpecialActionsButton);
165 layout =
new TQHBoxLayout(groupLayout, 2*spacingHint());
166 mLateCancel =
new LateCancelSelector(
false, group);
167 layout->addWidget(mLateCancel);
168 layout->addStretch();
171 mSubRepetition =
new RepetitionButton(i18n(
"Sub-Repetition"),
false, group);
172 mSubRepetition->set(0, 0,
true, 364*24*60);
173 TQWhatsThis::add(mSubRepetition, i18n(
"Set up an additional alarm repetition"));
174 layout->addWidget(mSubRepetition);
177 mFontColourButton->setDefaultFont();
178 mFontColourButton->setBgColour(Preferences::defaultBgColour());
179 mFontColourButton->setFgColour(Preferences::defaultFgColour());
180 mLateCancel->setMinutes(Preferences::defaultLateCancel(),
true, TimePeriod::DAYS);
181 mConfirmAck->setChecked(Preferences::defaultConfirmAck());
182 mSoundPicker->set(Preferences::defaultSoundType(), Preferences::defaultSoundFile(),
183 Preferences::defaultSoundVolume(), -1, 0, Preferences::defaultSoundRepeat());
184 if (mSpecialActionsButton)
185 mSpecialActionsButton->setActions(Preferences::defaultPreAction(), Preferences::defaultPostAction());
194 void BirthdayDlg::loadAddressBook()
198 #if KDE_IS_VERSION(3,1,90)
199 mAddressBook = TDEABC::StdAddressBook::self(
true);
201 connect(mAddressBook, TQ_SIGNAL(addressBookChanged(AddressBook*)), TQ_SLOT(updateSelectionList()));
203 mAddressBook = TDEABC::StdAddressBook::self();
205 updateSelectionList();
209 updateSelectionList();
211 KMessageBox::error(
this, i18n(
"Error reading address book"));
217 void BirthdayDlg::close()
221 TDEABC::StdAddressBook::close();
230 void BirthdayDlg::updateSelectionList()
233 TQStringList messageList;
235 Event::List events = AlarmCalendar::activeCalendar()->events();
236 for (Event::List::ConstIterator it = events.begin(); it != events.end(); ++it)
238 Event* kcalEvent = *it;
239 event.set(*kcalEvent);
240 if (event.action() == KAEvent::MESSAGE
241 && event.recurType() == KARecurrence::ANNUAL_DATE
242 && (mPrefixText.isEmpty() || event.message().startsWith(mPrefixText)))
243 messageList.append(event.message());
247 for (TDEABC::AddressBook::ConstIterator abit = mAddressBook->begin(); abit != mAddressBook->end(); ++abit)
249 const TDEABC::Addressee& addressee = *abit;
250 if (addressee.birthday().isValid())
253 TQDate birthday = addressee.birthday().date();
254 TQString name = addressee.nickName();
256 name = addressee.realName();
258 TQString text = mPrefixText + name + mSuffixText;
259 bool alarmExists = (messageList.find(text) != messageList.end());
261 bool inSelectionList =
false;
262 AddresseeItem* item = 0;
263 for (TQListViewItem* qitem = mAddresseeList->firstChild(); qitem; qitem = qitem->nextSibling())
265 item =
dynamic_cast<AddresseeItem*
>(qitem);
266 if (item && item->text(AddresseeItem::NAME) == name && item->birthday() == birthday)
268 inSelectionList =
true;
273 if (alarmExists && inSelectionList)
275 else if (!alarmExists && !inSelectionList)
276 new AddresseeItem(mAddresseeList, name, birthday);
282 bool selection =
false;
283 for (TQListViewItem* item = mAddresseeList->firstChild(); item; item = item->nextSibling())
284 if (mAddresseeList->isSelected(item))
289 enableButtonOK(selection);
295 TQValueList<KAEvent> BirthdayDlg::events()
const
297 TQValueList<KAEvent> list;
298 TQDate today = TQDate::currentDate();
299 TQDateTime todayNoon(today, TQTime(12, 0, 0));
300 int thisYear = today.year();
301 int reminder = mReminder->minutes();
303 for (TQListViewItem* item = mAddresseeList->firstChild(); item; item = item->nextSibling())
305 if (mAddresseeList->isSelected(item))
307 AddresseeItem* aItem =
dynamic_cast<AddresseeItem*
>(item);
310 TQDate date = aItem->birthday();
311 date.setYMD(thisYear, date.month(), date.day());
313 date.setYMD(thisYear + 1, date.month(), date.day());
315 mPrefix->text() + aItem->text(AddresseeItem::NAME) + mSuffix->text(),
316 mFontColourButton->bgColour(), mFontColourButton->fgColour(),
317 mFontColourButton->font(), KAEvent::MESSAGE, mLateCancel->minutes(),
321 float volume = mSoundPicker->volume(fadeVolume, fadeSecs);
322 event.setAudioFile(mSoundPicker->file(), volume, fadeVolume, fadeSecs);
323 TQValueList<int> months;
324 months.append(date.month());
325 event.setRecurAnnualByDate(1, months, 0, Preferences::defaultFeb29Type(), -1, TQDate());
326 event.setRepetition(mSubRepetition->interval(), mSubRepetition->count());
327 event.setNextOccurrence(todayNoon);
329 event.setReminder(reminder,
false);
330 if (mSpecialActionsButton)
331 event.setActions(mSpecialActionsButton->preAction(),
332 mSpecialActionsButton->postAction());
343 void BirthdayDlg::slotOk()
346 TDEConfig* config = kapp->config();
347 config->setGroup(TQString::fromLatin1(
"General"));
348 config->writeEntry(TQString::fromLatin1(
"BirthdayPrefix"), mPrefix->text());
349 config->writeEntry(TQString::fromLatin1(
"BirthdaySuffix"), mSuffix->text());
352 mFlags = (mSoundPicker->sound() == SoundPicker::BEEP ? KAEvent::BEEP : 0)
353 | (mSoundPicker->repeat() ? KAEvent::REPEAT_SOUND : 0)
354 | (mConfirmAck->isChecked() ? KAEvent::CONFIRM_ACK : 0)
355 | (mFontColourButton->defaultFont() ? KAEvent::DEFAULT_FONT : 0)
357 KDialogBase::slotOk();
364 void BirthdayDlg::slotSelectionChanged()
366 for (TQListViewItem* item = mAddresseeList->firstChild(); item; item = item->nextSibling())
367 if (mAddresseeList->isSelected(item))
369 enableButtonOK(
true);
372 enableButtonOK(
false);
381 void BirthdayDlg::slotTextLostFocus()
383 TQString prefix = mPrefix->text();
384 TQString suffix = mSuffix->text();
385 if (prefix != mPrefixText || suffix != mSuffixText)
388 mPrefixText = prefix;
389 mSuffixText = suffix;
399 AddresseeItem::AddresseeItem(TQListView* parent,
const TQString& name,
const TQDate& birthday)
400 : TQListViewItem(parent),
404 setText(BIRTHDAY, TDEGlobal::locale()->formatDate(mBirthday,
true));
405 mBirthdayOrder.sprintf(
"%04d%03d", mBirthday.year(), mBirthday.dayOfYear());
408 TQString AddresseeItem::key(
int column,
bool)
const
410 if (column == BIRTHDAY)
411 return mBirthdayOrder;
412 return text(column).lower();
420 BListView::BListView(TQWidget* parent,
const char* name)
421 : TDEListView(parent, name)
423 TDEAccel* accel =
new TDEAccel(
this);
424 accel->insert(TDEStdAccel::SelectAll,
this, TQ_SLOT(slotSelectAll()));
425 accel->insert(TDEStdAccel::Deselect,
this, TQ_SLOT(slotDeselect()));
426 accel->readSettings();
KAEvent corresponds to a KCal::Event instance.
the KAlarm application object