knotes

knotealarmdlg.cpp

00001 /*******************************************************************
00002  KNotes -- Notes for the KDE project
00003 
00004  Copyright (c) 2005, Michael Brade <brade@kde.org>
00005 
00006  This program is free software; you can redistribute it and/or
00007  modify it under the terms of the GNU General Public License
00008  as published by the Free Software Foundation; either version 2
00009  of the License, or (at your option) any later version.
00010 
00011  This program is distributed in the hope that it will be useful,
00012  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  GNU General Public License for more details.
00015 
00016  You should have received a copy of the GNU General Public License
00017  along with this program; if not, write to the Free Software
00018  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020  In addition, as a special exception, the copyright holders give
00021  permission to link the code of this program with any edition of
00022  the Qt library by Trolltech AS, Norway (or with modified versions
00023  of Qt that use the same license as Qt), and distribute linked
00024  combinations including the two.  You must obey the GNU General
00025  Public License in all respects for all of the code used other than
00026  Qt.  If you modify this file, you may extend this exception to
00027  your version of the file, but you are not obligated to do so.  If
00028  you do not wish to do so, delete this exception statement from
00029  your version.
00030 *******************************************************************/
00031 
00032 #include <tqlabel.h>
00033 #include <tqradiobutton.h>
00034 #include <tqbuttongroup.h>
00035 #include <tqvbox.h>
00036 
00037 #include <klocale.h>
00038 
00039 #include <libkdepim/kdateedit.h>
00040 #include <libkdepim/ktimeedit.h>
00041 
00042 #include <libkcal/journal.h>
00043 #include <libkcal/alarm.h>
00044 
00045 #include "knotealarmdlg.h"
00046 
00047 
00048 KNoteAlarmDlg::KNoteAlarmDlg( const TQString& caption, TQWidget *parent, const char *name )
00049     : KDialogBase( parent, name, true, caption, Ok|Cancel, Ok )
00050 {
00051     TQVBox *page = makeVBoxMainWidget();
00052     TQGroupBox *group = new TQGroupBox( 3, Vertical, i18n("Scheduled Alarm"), page );
00053     m_buttons = new TQButtonGroup( page );
00054     m_buttons->hide();
00055 
00056     TQRadioButton *none = new TQRadioButton( i18n("&No alarm"), group );
00057     m_buttons->insert( none );
00058 
00059     TQHBox *at = new TQHBox( group );
00060     TQRadioButton *label_at = new TQRadioButton( i18n("Alarm &at:"), at );
00061     m_buttons->insert( label_at );
00062     m_atDate = new KDateEdit( at );
00063     m_atTime = new KTimeEdit( at );
00064     at->setStretchFactor( m_atDate, 1 );
00065 
00066     TQHBox *in = new TQHBox( group );
00067     TQRadioButton *label_in = new TQRadioButton( i18n("Alarm &in:"), in );
00068     m_buttons->insert( label_in );
00069     m_inTime = new KTimeEdit( in );
00070     TQLabel *in_min = new TQLabel( i18n("hours/minutes"), in );
00071 
00072     label_in->setEnabled( false ); // TODO
00073     in->hide(); //show it and enable it when feature will implement
00074  
00075     connect( m_buttons, TQT_SIGNAL(clicked( int )), TQT_SLOT(slotButtonChanged( int )) );
00076 }
00077 
00078 
00079 void KNoteAlarmDlg::setIncidence( KCal::Journal *journal )
00080 {
00081     m_journal = journal;
00082 
00083     if ( !m_journal->alarms().isEmpty() )
00084     {
00085         KCal::Alarm *alarm = m_journal->alarms().first();
00086         if ( alarm->hasTime() )
00087         {
00088             m_buttons->setButton( 1 );
00089             m_atDate->setDate( alarm->time().date() );
00090             m_atTime->setTime( alarm->time().time() );
00091         }
00092         else if ( alarm->hasStartOffset() )
00093             m_buttons->setButton( 2 );
00094         else
00095             m_buttons->setButton( 0 );
00096     }
00097     else
00098         m_buttons->setButton( 0 );
00099 
00100     slotButtonChanged( m_buttons->selectedId() );
00101 }
00102 
00103 void KNoteAlarmDlg::slotButtonChanged( int id )
00104 {
00105     switch ( id )
00106     {
00107     case 0:
00108         m_atDate->setEnabled( false );
00109         m_atTime->setEnabled( false );
00110         m_inTime->setEnabled( false );
00111         break;
00112     case 1:
00113         m_atDate->setEnabled( true );
00114         m_atTime->setEnabled( true );
00115         m_inTime->setEnabled( false );
00116         break;
00117     case 2:
00118         m_atDate->setEnabled( false );
00119         m_atTime->setEnabled( false );
00120         m_inTime->setEnabled( true );
00121     }
00122 }
00123 
00124 void KNoteAlarmDlg::slotOk()
00125 {
00126     if ( m_buttons->selectedId() == 0 )
00127     {
00128         m_journal->clearAlarms();
00129         KDialogBase::slotOk();
00130         return;
00131     }
00132 
00133     KCal::Alarm *alarm;
00134     if ( m_journal->alarms().isEmpty() )
00135     {
00136         alarm = m_journal->newAlarm();
00137         alarm->setEnabled( true );
00138         alarm->setType( KCal::Alarm::Display );
00139     }
00140     else
00141         alarm = m_journal->alarms().first();
00142 
00143     if ( m_buttons->selectedId() == 1 )
00144         alarm->setTime( TQDateTime( m_atDate->date(), m_atTime->getTime() ) );
00145     else
00146     {
00147         // TODO
00148     }
00149 
00150     KDialogBase::slotOk();
00151 }
00152 
00153 #include "knotealarmdlg.moc"