knotes

knotealarmdlg.cpp
1 /*******************************************************************
2  KNotes -- Notes for the KDE project
3 
4  Copyright (c) 2005, Michael Brade <brade@kde.org>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  In addition, as a special exception, the copyright holders give
21  permission to link the code of this program with any edition of
22  the TQt library by Trolltech AS, Norway (or with modified versions
23  of TQt that use the same license as TQt), and distribute linked
24  combinations including the two. You must obey the GNU General
25  Public License in all respects for all of the code used other than
26  TQt. If you modify this file, you may extend this exception to
27  your version of the file, but you are not obligated to do so. If
28  you do not wish to do so, delete this exception statement from
29  your version.
30 *******************************************************************/
31 
32 #include <tqlabel.h>
33 #include <tqradiobutton.h>
34 #include <tqbuttongroup.h>
35 #include <tqvbox.h>
36 
37 #include <tdelocale.h>
38 
39 #include <libtdepim/kdateedit.h>
40 #include <libtdepim/ktimeedit.h>
41 
42 #include <libkcal/journal.h>
43 #include <libkcal/alarm.h>
44 
45 #include "knotealarmdlg.h"
46 
47 
48 KNoteAlarmDlg::KNoteAlarmDlg( const TQString& caption, TQWidget *parent, const char *name )
49  : KDialogBase( parent, name, true, caption, Ok|Cancel, Ok )
50 {
51  TQVBox *page = makeVBoxMainWidget();
52  TQGroupBox *group = new TQGroupBox( 3, TQt::Vertical, i18n("Scheduled Alarm"), page );
53  m_buttons = new TQButtonGroup( page );
54  m_buttons->hide();
55 
56  TQRadioButton *none = new TQRadioButton( i18n("&No alarm"), group );
57  m_buttons->insert( none );
58 
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 );
65 
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 );
71 
72  label_in->setEnabled( false ); // TODO
73  in->hide(); //show it and enable it when feature will implement
74 
75  connect( m_buttons, TQ_SIGNAL(clicked( int )), TQ_SLOT(slotButtonChanged( int )) );
76 }
77 
78 
79 void KNoteAlarmDlg::setIncidence( KCal::Journal *journal )
80 {
81  m_journal = journal;
82 
83  if ( !m_journal->alarms().isEmpty() )
84  {
85  KCal::Alarm *alarm = m_journal->alarms().first();
86  if ( alarm->hasTime() )
87  {
88  m_buttons->setButton( 1 );
89  m_atDate->setDate( alarm->time().date() );
90  m_atTime->setTime( alarm->time().time() );
91  }
92  else if ( alarm->hasStartOffset() )
93  m_buttons->setButton( 2 );
94  else
95  m_buttons->setButton( 0 );
96  }
97  else
98  m_buttons->setButton( 0 );
99 
100  slotButtonChanged( m_buttons->selectedId() );
101 }
102 
103 void KNoteAlarmDlg::slotButtonChanged( int id )
104 {
105  switch ( id )
106  {
107  case 0:
108  m_atDate->setEnabled( false );
109  m_atTime->setEnabled( false );
110  m_inTime->setEnabled( false );
111  break;
112  case 1:
113  m_atDate->setEnabled( true );
114  m_atTime->setEnabled( true );
115  m_inTime->setEnabled( false );
116  break;
117  case 2:
118  m_atDate->setEnabled( false );
119  m_atTime->setEnabled( false );
120  m_inTime->setEnabled( true );
121  }
122 }
123 
124 void KNoteAlarmDlg::slotOk()
125 {
126  if ( m_buttons->selectedId() == 0 )
127  {
128  m_journal->clearAlarms();
129  KDialogBase::slotOk();
130  return;
131  }
132 
133  KCal::Alarm *alarm;
134  if ( m_journal->alarms().isEmpty() )
135  {
136  alarm = m_journal->newAlarm();
137  alarm->setEnabled( true );
138  alarm->setType( KCal::Alarm::Display );
139  }
140  else
141  alarm = m_journal->alarms().first();
142 
143  if ( m_buttons->selectedId() == 1 )
144  alarm->setTime( TQDateTime( m_atDate->date(), m_atTime->getTime() ) );
145  else
146  {
147  // TODO
148  }
149 
150  KDialogBase::slotOk();
151 }
152 
153 #include "knotealarmdlg.moc"