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 <qlabel.h>
00033 #include <qradiobutton.h>
00034 #include <qbuttongroup.h>
00035 #include <qvbox.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 QString& caption, QWidget *parent, const char *name )
00049     : KDialogBase( parent, name, true, caption, Ok|Cancel, Ok )
00050 {
00051     QVBox *page = makeVBoxMainWidget();
00052     QGroupBox *group = new QGroupBox( 3, Vertical, i18n("Scheduled Alarm"), page );
00053     m_buttons = new QButtonGroup( page );
00054     m_buttons->hide();
00055 
00056     QRadioButton *none = new QRadioButton( i18n("&No alarm"), group );
00057     m_buttons->insert( none );
00058 
00059     QHBox *at = new QHBox( group );
00060     QRadioButton *label_at = new QRadioButton( 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     QHBox *in = new QHBox( group );
00067     QRadioButton *label_in = new QRadioButton( i18n("Alarm &in:"), in );
00068     m_buttons->insert( label_in );
00069     m_inTime = new KTimeEdit( in );
00070     QLabel *in_min = new QLabel( i18n("hours/minutes"), in );
00071 
00072     label_in->setEnabled( false ); // TODO
00073 
00074     connect( m_buttons, SIGNAL(clicked( int )), SLOT(slotButtonChanged( int )) );
00075 }
00076 
00077 
00078 void KNoteAlarmDlg::setIncidence( KCal::Journal *journal )
00079 {
00080     m_journal = journal;
00081 
00082     if ( !m_journal->alarms().isEmpty() )
00083     {
00084         KCal::Alarm *alarm = m_journal->alarms().first();
00085         if ( alarm->hasTime() )
00086         {
00087             m_buttons->setButton( 1 );
00088             m_atDate->setDate( alarm->time().date() );
00089             m_atTime->setTime( alarm->time().time() );
00090         }
00091         else if ( alarm->hasStartOffset() )
00092             m_buttons->setButton( 2 );
00093         else
00094             m_buttons->setButton( 0 );
00095     }
00096     else
00097         m_buttons->setButton( 0 );
00098 
00099     slotButtonChanged( m_buttons->selectedId() );
00100 }
00101 
00102 void KNoteAlarmDlg::slotButtonChanged( int id )
00103 {
00104     switch ( id )
00105     {
00106     case 0:
00107         m_atDate->setEnabled( false );
00108         m_atTime->setEnabled( false );
00109         m_inTime->setEnabled( false );
00110         break;
00111     case 1:
00112         m_atDate->setEnabled( true );
00113         m_atTime->setEnabled( true );
00114         m_inTime->setEnabled( false );
00115         break;
00116     case 2:
00117         m_atDate->setEnabled( false );
00118         m_atTime->setEnabled( false );
00119         m_inTime->setEnabled( true );
00120     }
00121 }
00122 
00123 void KNoteAlarmDlg::slotOk()
00124 {
00125     if ( m_buttons->selectedId() == 0 )
00126     {
00127         m_journal->clearAlarms();
00128         KDialogBase::slotOk();
00129         return;
00130     }
00131 
00132     KCal::Alarm *alarm;
00133     if ( m_journal->alarms().isEmpty() )
00134     {
00135         alarm = m_journal->newAlarm();
00136         alarm->setEnabled( true );
00137         alarm->setType( KCal::Alarm::Display );
00138     }
00139     else
00140         alarm = m_journal->alarms().first();
00141 
00142     if ( m_buttons->selectedId() == 1 )
00143         alarm->setTime( QDateTime( m_atDate->date(), m_atTime->getTime() ) );
00144     else
00145     {
00146         // TODO
00147     }
00148 
00149     KDialogBase::slotOk();
00150 }
00151 
00152 #include "knotealarmdlg.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys