24#include <tqgroupbox.h>
27#include <tqlineedit.h>
28#include <tqwhatsthis.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"
57class 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;
70const TDEABC::AddressBook* BirthdayDlg::mAddressBook = 0;
73BirthdayDlg::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 = tdeApp->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());
194void BirthdayDlg::loadAddressBook()
198 mAddressBook = TDEABC::StdAddressBook::self(
true);
200 connect(mAddressBook, TQ_SIGNAL(addressBookChanged(AddressBook*)), TQ_SLOT(updateSelectionList()));
203 updateSelectionList();
205 KMessageBox::error(
this, i18n(
"Error reading address book"));
211void BirthdayDlg::close()
215 TDEABC::StdAddressBook::close();
224void BirthdayDlg::updateSelectionList()
227 TQStringList messageList;
229 Event::List events = AlarmCalendar::activeCalendar()->events();
230 for (Event::List::ConstIterator it = events.begin(); it != events.end(); ++it)
232 Event* kcalEvent = *it;
233 event.set(*kcalEvent);
234 if (event.action() == KAEvent::MESSAGE
235 && event.recurType() == KARecurrence::ANNUAL_DATE
236 && (mPrefixText.isEmpty() || event.message().startsWith(mPrefixText)))
237 messageList.append(event.message());
241 for (TDEABC::AddressBook::ConstIterator abit = mAddressBook->begin(); abit != mAddressBook->end(); ++abit)
243 const TDEABC::Addressee& addressee = *abit;
244 if (addressee.birthday().isValid())
247 TQDate birthday = addressee.birthday().date();
248 TQString name = addressee.nickName();
250 name = addressee.realName();
252 TQString text = mPrefixText + name + mSuffixText;
253 bool alarmExists = (messageList.find(text) != messageList.end());
255 bool inSelectionList =
false;
256 AddresseeItem* item = 0;
257 for (TQListViewItem* qitem = mAddresseeList->firstChild(); qitem; qitem = qitem->nextSibling())
259 item =
dynamic_cast<AddresseeItem*
>(qitem);
260 if (item && item->text(AddresseeItem::NAME) == name && item->birthday() == birthday)
262 inSelectionList =
true;
267 if (alarmExists && inSelectionList)
269 else if (!alarmExists && !inSelectionList)
270 new AddresseeItem(mAddresseeList, name, birthday);
276 bool selection =
false;
277 for (TQListViewItem* item = mAddresseeList->firstChild(); item; item = item->nextSibling())
278 if (mAddresseeList->isSelected(item))
283 enableButtonOK(selection);
289TQValueList<KAEvent> BirthdayDlg::events()
const
291 TQValueList<KAEvent> list;
292 TQDate today = TQDate::currentDate();
293 TQDateTime todayNoon(today, TQTime(12, 0, 0));
294 int thisYear = today.year();
295 int reminder = mReminder->minutes();
297 for (TQListViewItem* item = mAddresseeList->firstChild(); item; item = item->nextSibling())
299 if (mAddresseeList->isSelected(item))
301 AddresseeItem* aItem =
dynamic_cast<AddresseeItem*
>(item);
304 TQDate date = aItem->birthday();
305 date.setYMD(thisYear, date.month(), date.day());
307 date.setYMD(thisYear + 1, date.month(), date.day());
309 mPrefix->text() + aItem->text(AddresseeItem::NAME) + mSuffix->text(),
310 mFontColourButton->bgColour(), mFontColourButton->fgColour(),
311 mFontColourButton->font(), KAEvent::MESSAGE, mLateCancel->minutes(),
315 float volume = mSoundPicker->volume(fadeVolume, fadeSecs);
316 event.setAudioFile(mSoundPicker->file(), volume, fadeVolume, fadeSecs);
317 TQValueList<int> months;
318 months.append(date.month());
319 event.setRecurAnnualByDate(1, months, 0, Preferences::defaultFeb29Type(), -1, TQDate());
320 event.setRepetition(mSubRepetition->interval(), mSubRepetition->count());
321 event.setNextOccurrence(todayNoon);
323 event.setReminder(reminder,
false);
324 if (mSpecialActionsButton)
325 event.setActions(mSpecialActionsButton->preAction(),
326 mSpecialActionsButton->postAction());
337void BirthdayDlg::slotOk()
340 TDEConfig* config = tdeApp->config();
341 config->setGroup(TQString::fromLatin1(
"General"));
342 config->writeEntry(TQString::fromLatin1(
"BirthdayPrefix"), mPrefix->text());
343 config->writeEntry(TQString::fromLatin1(
"BirthdaySuffix"), mSuffix->text());
346 mFlags = (mSoundPicker->sound() == SoundPicker::BEEP ? KAEvent::BEEP : 0)
347 | (mSoundPicker->repeat() ? KAEvent::REPEAT_SOUND : 0)
348 | (mConfirmAck->isChecked() ? KAEvent::CONFIRM_ACK : 0)
349 | (mFontColourButton->defaultFont() ? KAEvent::DEFAULT_FONT : 0)
351 KDialogBase::slotOk();
358void BirthdayDlg::slotSelectionChanged()
360 for (TQListViewItem* item = mAddresseeList->firstChild(); item; item = item->nextSibling())
361 if (mAddresseeList->isSelected(item))
363 enableButtonOK(
true);
366 enableButtonOK(
false);
375void BirthdayDlg::slotTextLostFocus()
377 TQString prefix = mPrefix->text();
378 TQString suffix = mSuffix->text();
379 if (prefix != mPrefixText || suffix != mSuffixText)
382 mPrefixText = prefix;
383 mSuffixText = suffix;
393AddresseeItem::AddresseeItem(TQListView* parent,
const TQString& name,
const TQDate& birthday)
394 : TQListViewItem(parent),
398 setText(BIRTHDAY, TDEGlobal::locale()->formatDate(mBirthday,
true));
399 mBirthdayOrder.sprintf(
"%04d%03d", mBirthday.year(), mBirthday.dayOfYear());
402TQString AddresseeItem::key(
int column,
bool)
const
404 if (column == BIRTHDAY)
405 return mBirthdayOrder;
406 return text(column).lower();
414BListView::BListView(TQWidget* parent,
const char* name)
415 : TDEListView(parent, name)
417 TDEAccel* accel =
new TDEAccel(
this);
418 accel->insert(TDEStdAccel::SelectAll,
this, TQ_SLOT(slotSelectAll()));
419 accel->insert(TDEStdAccel::Deselect,
this, TQ_SLOT(slotDeselect()));
420 accel->readSettings();
KAEvent corresponds to a KCal::Event instance.
the KAlarm application object