33 #include <tqradiobutton.h>
34 #include <tqbuttongroup.h>
37 #include <tdelocale.h>
39 #include <libtdepim/kdateedit.h>
40 #include <libtdepim/ktimeedit.h>
42 #include <libkcal/journal.h>
43 #include <libkcal/alarm.h>
45 #include "knotealarmdlg.h"
48 KNoteAlarmDlg::KNoteAlarmDlg(
const TQString& caption, TQWidget *parent,
const char *name )
49 : KDialogBase( parent, name, true, caption, Ok|Cancel, Ok )
51 TQVBox *page = makeVBoxMainWidget();
52 TQGroupBox *group =
new TQGroupBox( 3, TQt::Vertical, i18n(
"Scheduled Alarm"), page );
53 m_buttons =
new TQButtonGroup( page );
56 TQRadioButton *none =
new TQRadioButton( i18n(
"&No alarm"), group );
57 m_buttons->insert( none );
59 TQHBox *at =
new TQHBox( group );
60 TQRadioButton *label_at =
new TQRadioButton( i18n(
"Alarm &at:"), at );
61 m_buttons->insert( label_at );
62 m_atDate =
new KDateEdit( at );
63 m_atTime =
new KTimeEdit( at );
64 at->setStretchFactor( m_atDate, 1 );
66 TQHBox *in =
new TQHBox( group );
67 TQRadioButton *label_in =
new TQRadioButton( i18n(
"Alarm &in:"), in );
68 m_buttons->insert( label_in );
69 m_inTime =
new KTimeEdit( in );
70 TQLabel *in_min =
new TQLabel( i18n(
"hours/minutes"), in );
72 label_in->setEnabled(
false );
75 connect( m_buttons, TQ_SIGNAL(clicked(
int )), TQ_SLOT(slotButtonChanged(
int )) );
79 void KNoteAlarmDlg::setIncidence( KCal::Journal *journal )
83 if ( !m_journal->alarms().isEmpty() )
85 KCal::Alarm *alarm = m_journal->alarms().first();
86 if ( alarm->hasTime() )
88 m_buttons->setButton( 1 );
89 m_atDate->setDate( alarm->time().date() );
90 m_atTime->setTime( alarm->time().time() );
92 else if ( alarm->hasStartOffset() )
93 m_buttons->setButton( 2 );
95 m_buttons->setButton( 0 );
98 m_buttons->setButton( 0 );
100 slotButtonChanged( m_buttons->selectedId() );
103 void KNoteAlarmDlg::slotButtonChanged(
int id )
108 m_atDate->setEnabled(
false );
109 m_atTime->setEnabled(
false );
110 m_inTime->setEnabled(
false );
113 m_atDate->setEnabled(
true );
114 m_atTime->setEnabled(
true );
115 m_inTime->setEnabled(
false );
118 m_atDate->setEnabled(
false );
119 m_atTime->setEnabled(
false );
120 m_inTime->setEnabled(
true );
124 void KNoteAlarmDlg::slotOk()
126 if ( m_buttons->selectedId() == 0 )
128 m_journal->clearAlarms();
129 KDialogBase::slotOk();
134 if ( m_journal->alarms().isEmpty() )
136 alarm = m_journal->newAlarm();
137 alarm->setEnabled(
true );
138 alarm->setType( KCal::Alarm::Display );
141 alarm = m_journal->alarms().first();
143 if ( m_buttons->selectedId() == 1 )
144 alarm->setTime( TQDateTime( m_atDate->date(), m_atTime->getTime() ) );
150 KDialogBase::slotOk();
153 #include "knotealarmdlg.moc"