26 #include "koeditoralarms_base.h"
27 #include "koeditoralarms.h"
30 #include <libkcal/duration.h>
33 #include <tqlistview.h>
34 #include <tqpushbutton.h>
35 #include <tqspinbox.h>
36 #include <tqcombobox.h>
37 #include <tqcheckbox.h>
38 #include <tqbuttongroup.h>
39 #include <tqtextedit.h>
40 #include <tqwidgetstack.h>
41 #include <tqradiobutton.h>
42 #include <tqtooltip.h>
43 #include <tqwhatsthis.h>
45 #include <kurlrequester.h>
46 #include <tdelocale.h>
49 #include <libkcal/alarm.h>
50 #include <libkcal/incidence.h>
52 #include <libemailfunctions/email.h>
54 class AlarmListViewItem :
public TQListViewItem
57 AlarmListViewItem( TQListView *parent,
KCal::Alarm *alarm,
const TQCString &inctype );
58 virtual ~AlarmListViewItem();
61 enum AlarmViewColumns { ColAlarmType=0, ColAlarmOffset, ColAlarmRepeat };
70 AlarmListViewItem::AlarmListViewItem( TQListView *parent,
KCal::Alarm *alarm,
71 const TQCString &inctype )
72 : TQListViewItem( parent ), mIncType( inctype )
78 mAlarm->setType( KCal::Alarm::Display );
80 switch( KOPrefs::instance()->mReminderTimeUnits ) {
83 duration = KOPrefs::instance()->mReminderTime * 60;
86 duration = KOPrefs::instance()->mReminderTime * 60 * 60;
89 duration = KOPrefs::instance()->mReminderTime * 60 * 60 * 24;
92 if ( mIncType ==
"Event" ) {
101 AlarmListViewItem::~AlarmListViewItem()
106 void AlarmListViewItem::construct()
111 switch ( mAlarm->type() ) {
112 case KCal::Alarm::Display:
113 type = i18n(
"Reminder Dialog");
115 case KCal::Alarm::Procedure:
116 type = i18n(
"Program");
118 case KCal::Alarm::Email:
119 type = i18n(
"Email");
121 case KCal::Alarm::Audio:
122 type = i18n(
"Audio");
125 type = i18n(
"Unknown");
128 setText( ColAlarmType, type );
133 if ( mAlarm->hasStartOffset() ) {
134 offset = mAlarm->startOffset().asSeconds();
136 offsetstr = i18n(
"N days/hours/minutes before/after the start/end",
137 "%1 before the start" );
140 offsetstr = i18n(
"N days/hours/minutes before/after the start/end",
141 "%1 after the start" );
143 }
else if ( mAlarm->hasEndOffset() ) {
144 offset = mAlarm->endOffset().asSeconds();
146 if ( mIncType ==
"Todo" ) {
147 offsetstr = i18n(
"N days/hours/minutes before/after the due date",
148 "%1 before the to-do is due" );
150 offsetstr = i18n(
"N days/hours/minutes before/after the start/end",
151 "%1 before the end" );
155 if ( mIncType ==
"Todo" ) {
156 offsetstr = i18n(
"N days/hours/minutes before/after the due date",
157 "%1 after the to-do is due" );
159 offsetstr = i18n(
"N days/hours/minutes before/after the start/end",
160 "%1 after the end" );
165 offset = offset / 60;
166 int useoffset = offset;
168 if ( offset % (24*60) == 0 && offset>0 ) {
169 useoffset = offset / (24*60);
170 offsetstr = offsetstr.arg( i18n(
"1 day",
"%n days", useoffset ) );
171 }
else if (offset % 60 == 0 && offset>0 ) {
172 useoffset = offset / 60;
173 offsetstr = offsetstr.arg( i18n(
"1 hour",
"%n hours", useoffset ) );
176 offsetstr = offsetstr.arg( i18n(
"1 minute",
"%n minutes", useoffset ) );
178 setText( ColAlarmOffset, offsetstr );
181 if ( mAlarm->repeatCount()>0 ) {
182 setText( ColAlarmRepeat, i18n(
"Yes") );
184 setText( ColAlarmRepeat, i18n(
"No") );
190 KOEditorAlarms::KOEditorAlarms(
const TQCString &type,
191 KCal::Alarm::List *alarms, TQWidget *parent,
193 : KDialogBase( parent, name, true, i18n(
"Advanced Reminders"), Ok | Cancel ),
194 mType( type ), mAlarms( alarms ),mCurrentItem( 0 )
196 if ( mType !=
"Todo" ) {
200 setMainWidget( mWidget =
new KOEditorAlarms_base(
this ) );
204 mWidget->mAddButton->setText( i18n(
"Add a new alarm to the alarm list.",
"&Add" ) );
206 mWidget->mAlarmList->setResizeMode( TQListView::LastColumn );
207 mWidget->mAlarmList->setColumnWidthMode( 0, TQListView::Maximum );
208 mWidget->mAlarmList->setColumnWidthMode( 1, TQListView::Maximum );
209 connect( mWidget->mAlarmList, TQ_SIGNAL( selectionChanged( TQListViewItem * ) ),
210 TQ_SLOT( selectionChanged( TQListViewItem * ) ) );
211 connect( mWidget->mAddButton, TQ_SIGNAL( clicked() ), TQ_SLOT( slotAdd() ) );
212 connect( mWidget->mRemoveButton, TQ_SIGNAL( clicked() ), TQ_SLOT( slotRemove() ) );
213 connect( mWidget->mDuplicateButton, TQ_SIGNAL( clicked() ), TQ_SLOT( slotDuplicate() ) );
215 connect( mWidget->mAlarmOffset, TQ_SIGNAL( valueChanged(
int ) ), TQ_SLOT( changed() ) );
216 connect( mWidget->mOffsetUnit, TQ_SIGNAL( activated(
int ) ), TQ_SLOT( changed() ) );
217 connect( mWidget->mBeforeAfter, TQ_SIGNAL( activated(
int ) ), TQ_SLOT( changed() ) );
218 connect( mWidget->mRepeats, TQ_SIGNAL( toggled(
bool ) ), TQ_SLOT( changed() ) );
219 connect( mWidget->mRepeatCount, TQ_SIGNAL( valueChanged(
int ) ), TQ_SLOT( changed() ) );
220 connect( mWidget->mRepeatInterval, TQ_SIGNAL( valueChanged(
int ) ), TQ_SLOT( changed() ) );
221 connect( mWidget->mAlarmType, TQ_SIGNAL(clicked(
int)), TQ_SLOT( changed() ) );
222 connect( mWidget->mDisplayText, TQ_SIGNAL( textChanged() ), TQ_SLOT( changed() ) );
223 connect( mWidget->mSoundFile, TQ_SIGNAL( textChanged(
const TQString & ) ), TQ_SLOT( changed() ) );
224 connect( mWidget->mApplication, TQ_SIGNAL( textChanged(
const TQString & ) ), TQ_SLOT( changed() ) );
225 connect( mWidget->mAppArguments, TQ_SIGNAL( textChanged(
const TQString & ) ), TQ_SLOT( changed() ) );
226 connect( mWidget->mEmailAddress, TQ_SIGNAL( textChanged(
const TQString & ) ), TQ_SLOT( changed() ) );
227 connect( mWidget->mEmailText, TQ_SIGNAL( textChanged() ), TQ_SLOT( changed() ) );
232 mWidget->mTypeEmailRadio->hide();
234 mWidget->setMinimumSize( 500, 500 );
237 KOEditorAlarms::~KOEditorAlarms()
241 void KOEditorAlarms::changed()
243 if ( !mInitializing && mCurrentItem ) {
248 KOPrefs::instance()->defaultAudioFileReminders() ) {
249 alarm->
setAudioFile( KOPrefs::instance()->audioFilePath() );
250 mWidget->mSoundFile->setURL( KOPrefs::instance()->audioFilePath() );
254 mCurrentItem->construct();
258 void KOEditorAlarms::readAlarm(
KCal::Alarm *alarm )
260 if ( !alarm )
return;
262 mInitializing =
true;
266 int beforeafterpos = 0;
267 if ( mType ==
"Todo" ) {
285 mWidget->mBeforeAfter->setCurrentItem( beforeafterpos );
287 offset = offset / 60;
288 int useoffset = offset;
290 if ( offset % (24*60) == 0 && offset>0 ) {
291 useoffset = offset / (24*60);
292 mWidget->mOffsetUnit->setCurrentItem( 2 );
293 }
else if (offset % 60 == 0 && offset>0 ) {
294 useoffset = offset / 60;
295 mWidget->mOffsetUnit->setCurrentItem( 1 );
298 mWidget->mOffsetUnit->setCurrentItem( 0 );
300 mWidget->mAlarmOffset->setValue( useoffset );
304 mWidget->mRepeats->setChecked( alarm->
repeatCount()>0 );
306 mWidget->mRepeatCount->setValue( alarm->
repeatCount() );
310 switch ( alarm->
type() ) {
311 case KCal::Alarm::Audio:
312 mWidget->mAlarmType->setButton( 1 );
313 mWidget->mSoundFile->setURL( alarm->
audioFile() );
315 case KCal::Alarm::Procedure:
316 mWidget->mAlarmType->setButton( 2 );
317 mWidget->mApplication->setURL( alarm->
programFile() );
320 case KCal::Alarm::Email: {
321 mWidget->mAlarmType->setButton( 3 );
322 TQValueList<KCal::Person> addresses = alarm->
mailAddresses();
324 for ( TQValueList<KCal::Person>::ConstIterator it = addresses.begin();
325 it != addresses.end(); ++it ) {
326 add << (*it).fullName();
328 mWidget->mEmailAddress->setText( add.join(
", ") );
329 mWidget->mEmailText->setText( alarm->
mailText() );
331 case KCal::Alarm::Display:
332 case KCal::Alarm::Invalid:
334 mWidget->mAlarmType->setButton( 0 );
335 mWidget->mDisplayText->setText( alarm->
text() );
339 mWidget->mTypeStack->raiseWidget( mWidget->mAlarmType->selectedId() );
341 mInitializing =
false;
344 void KOEditorAlarms::writeAlarm(
KCal::Alarm *alarm )
347 int offset = mWidget->mAlarmOffset->value()*60;
348 int offsetunit = mWidget->mOffsetUnit->currentItem();
349 if ( offsetunit >= 1 ) offset *= 60;
350 if ( offsetunit >= 2 ) offset *= 24;
351 if ( offsetunit >= 3 ) offset *= 7;
353 int beforeafterpos = mWidget->mBeforeAfter->currentItem();
354 if ( beforeafterpos % 2 == 0 ) {
359 if ( beforeafterpos / 2 == 0 ) {
366 if ( mWidget->mRepeats->isChecked() ) {
373 switch ( mWidget->mAlarmType->selectedId() ) {
378 alarm->
setProcedureAlarm( mWidget->mApplication->url(), mWidget->mAppArguments->text() );
381 TQStringList addresses = KPIM::splitEmailAddrList( mWidget->mEmailAddress->text() );
382 TQValueList<KCal::Person> add;
383 for ( TQStringList::Iterator it = addresses.begin(); it != addresses.end();
388 alarm->
setEmailAlarm( TQString(), mWidget->mEmailText->text(),
398 void KOEditorAlarms::selectionChanged( TQListViewItem *listviewitem )
400 AlarmListViewItem *item =
dynamic_cast<AlarmListViewItem*
>(listviewitem);
402 mWidget->mTimeGroup->setEnabled( item );
403 mWidget->mTypeGroup->setEnabled( item );
405 readAlarm( item->alarm() );
409 void KOEditorAlarms::slotOk()
417 TQListViewItemIterator it( mWidget->mAlarmList );
418 while ( it.current() ) {
419 AlarmListViewItem *item =
dynamic_cast<AlarmListViewItem*
>(*it);
421 mAlarms->append(
new KCal::Alarm( *(item->alarm()) ) );
429 void KOEditorAlarms::slotAdd()
431 mCurrentItem =
new AlarmListViewItem( mWidget->mAlarmList, 0, mType );
432 mWidget->mAlarmList->setCurrentItem( mCurrentItem );
435 void KOEditorAlarms::slotDuplicate()
437 if ( mCurrentItem ) {
438 mCurrentItem =
new AlarmListViewItem( mWidget->mAlarmList, mCurrentItem->alarm(), mType );
439 mWidget->mAlarmList->setCurrentItem( mCurrentItem );
443 void KOEditorAlarms::slotRemove()
445 if ( mCurrentItem ) {
447 mCurrentItem =
dynamic_cast<AlarmListViewItem*
>( mWidget->mAlarmList->currentItem() );
448 mWidget->mAlarmList->setSelected( mCurrentItem,
true );
452 void KOEditorAlarms::init()
454 mInitializing =
true;
457 if ( mType ==
"Todo" ) {
459 mWidget->mBeforeAfter->clear();
460 mWidget->mBeforeAfter->insertItem( i18n(
"before the to-do starts" ), 0 );
461 mWidget->mBeforeAfter->insertItem( i18n(
"after the to-do starts" ), 1 );
462 mWidget->mBeforeAfter->insertItem( i18n(
"before the to-do is due" ), 2 );
463 mWidget->mBeforeAfter->insertItem( i18n(
"after the to-do is due" ), 3 );
465 mWidget->mBeforeAfter,
466 i18n(
"Select the reminder trigger relative to the start or due time" ) );
468 mWidget->mBeforeAfter,
469 i18n(
"Use this combobox to specify if you want the reminder to "
470 "trigger before or after the start or due time." ) );
472 mWidget->mBeforeAfter->setCurrentItem( 2 );
476 KCal::Alarm::List::ConstIterator it;
477 for ( it = mAlarms->begin(); it != mAlarms->end(); ++it ) {
478 new AlarmListViewItem( mWidget->mAlarmList, *it, mType );
480 mWidget->mAlarmList->setSelected( mWidget->mAlarmList->firstChild(),
true );
481 mInitializing =
false;
484 #include "koeditoralarms.moc"
void setAudioAlarm(const TQString &audioFile=TQString())
bool hasStartOffset() const
TQString audioFile() const
Duration snoozeTime() const
TQString programFile() const
void setRepeatCount(int alarmRepeatCount)
Duration endOffset() const
bool hasEndOffset() const
void setDisplayAlarm(const TQString &text=TQString())
Duration startOffset() const
void setSnoozeTime(const Duration &alarmSnoozeTime)
TQString programArguments() const
void setEndOffset(const Duration &)
void setEmailAlarm(const TQString &subject, const TQString &text, const TQValueList< Person > &addressees, const TQStringList &attachments=TQStringList())
TQString mailText() const
void setStartOffset(const Duration &)
TQValueList< Person > mailAddresses() const
void setAudioFile(const TQString &audioFile)
void setProcedureAlarm(const TQString &programFile, const TQString &arguments=TQString())