korganizer/korgac Library API Documentation

alarmdialog.cpp

00001 /*
00002     This file is part of the KOrganizer alarm daemon.
00003 
00004     Copyright (c) 2000,2003 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <qhbox.h>
00026 #include <qvbox.h>
00027 #include <qlabel.h>
00028 #include <qfile.h>
00029 #include <qspinbox.h>
00030 #include <qlayout.h>
00031 
00032 #include <klocale.h>
00033 #include <kprocess.h>
00034 #include <kaudioplayer.h>
00035 #include <kdebug.h>
00036 #include <knotifyclient.h>
00037 
00038 #include <libkcal/event.h>
00039 
00040 #include "koeventviewer.h"
00041 
00042 #include "alarmdialog.h"
00043 #include "alarmdialog.moc"
00044 
00045 AlarmDialog::AlarmDialog( QWidget *parent, const char *name )
00046   : KDialogBase( Plain, WType_TopLevel | WStyle_Customize | WStyle_StaysOnTop |
00047                  WStyle_DialogBorder,
00048                  parent, name, false, i18n("Alarm"), Ok | User1 | User2, User2,
00049                  false, i18n("Suspend") )
00050 {
00051   QWidget *topBox = plainPage();
00052   
00053   QBoxLayout *topLayout = new QVBoxLayout( topBox );
00054   topLayout->setSpacing( spacingHint() );
00055 
00056   QLabel *label = new QLabel( i18n("The following events triggered alarms:"),
00057                               topBox );
00058   topLayout->addWidget( label );
00059 
00060   mIncidences.setAutoDelete( true );
00061   
00062   mEventViewer = new KOEventViewer( topBox );
00063   topLayout->addWidget( mEventViewer );
00064 
00065   QHBox *suspendBox = new QHBox( topBox );
00066   suspendBox->setSpacing( spacingHint() );
00067   topLayout->addWidget( suspendBox );
00068 
00069   new QLabel( i18n("Suspend duration (minutes):"), suspendBox );
00070   mSuspendSpin = new QSpinBox( 1, 9999, 1, suspendBox );
00071   mSuspendSpin->setValue( 5 );  // default suspend duration
00072   
00073   showButton( User2, false );
00074   
00075   setMinimumSize( 300, 200 );
00076 }
00077 
00078 AlarmDialog::~AlarmDialog()
00079 {
00080 }
00081 
00082 void AlarmDialog::appendEvent(Event *event)
00083 {
00084   mEventViewer->appendEvent(event);
00085   mIncidences.append(event->clone());
00086 }
00087 
00088 void AlarmDialog::appendTodo(Todo *todo)
00089 {
00090   mEventViewer->appendTodo(todo);
00091   mIncidences.append(todo->clone());
00092 }
00093 
00094 void AlarmDialog::clearEvents()
00095 {
00096   mEventViewer->clearEvents();
00097 
00098   mIncidences.clear();
00099 }
00100 
00101 void AlarmDialog::slotOk()
00102 {
00103   clearEvents();
00104   accept();
00105 }
00106 
00107 void AlarmDialog::slotUser1()
00108 {
00109   emit suspendSignal(mSuspendSpin->value());
00110   accept();
00111 }
00112 
00113 void AlarmDialog::eventNotification()
00114 {
00115   bool beeped = false;
00116 
00117   Incidence *in;
00118   for (in = mIncidences.first(); in; in = mIncidences.next()) {
00119     Alarm::List alarms = in->alarms();
00120     Alarm::List::ConstIterator it;
00121     for ( it = alarms.begin(); it != alarms.end(); ++it ) {
00122       Alarm *alarm = *it;
00123 // TODO: Check whether this should be done for all multiple alarms
00124       if (alarm->type() == Alarm::Procedure) {
00125         kdDebug(5890) << "Starting program: '" << alarm->programFile() << "'" << endl;
00126         KProcess proc;
00127         proc << QFile::encodeName(alarm->programFile());
00128         proc.start(KProcess::DontCare);
00129       }
00130       else if (alarm->type() == Alarm::Audio) {
00131         beeped = true;
00132         KAudioPlayer::play(QFile::encodeName(alarm->audioFile()));
00133       }
00134     }
00135   }
00136   
00137   if ( !beeped ) {
00138     KNotifyClient::beep();
00139   }
00140 }
KDE Logo
This file is part of the documentation for korganizer/korgac Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:41 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003