kalarmd Library API Documentation

alarmdialog.cpp

00001 /*
00002     This file is part of the KDE alarm daemon.
00003     Copyright (c) 2000 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 // $Id: alarmdialog.cpp,v 1.12 2002/10/22 15:02:09 schwann Exp $
00025 
00026 #include <qhbox.h>
00027 #include <qvbox.h>
00028 #include <qlabel.h>
00029 #include <qfile.h>
00030 #include <qspinbox.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(parent,name,false,i18n("Alarm"),Ok|User1|User2,User2,false,
00047                 i18n("Suspend"))
00048 {
00049   QVBox *topBox = new QVBox(this);
00050   topBox->setSpacing(spacingHint());
00051   setMainWidget(topBox);
00052 
00053   (void)new QLabel(i18n("The following events triggered alarms:"),topBox);
00054 
00055   mIncidences.setAutoDelete(true);
00056   
00057   mEventViewer = new KOEventViewer(topBox);
00058 
00059   QHBox *suspendBox = new QHBox(topBox);
00060   suspendBox->setSpacing(spacingHint());
00061 
00062   (void)new QLabel(i18n("Suspend duration (minutes):"),suspendBox);
00063   mSuspendSpin = new QSpinBox(1,60,1,suspendBox);
00064   mSuspendSpin->setValue(5);  // default suspend duration
00065   
00066   showButton(User2, false);
00067   
00068   setMinimumSize(300,200);
00069 }
00070 
00071 AlarmDialog::~AlarmDialog()
00072 {
00073 }
00074 
00075 void AlarmDialog::appendEvent(Event *event)
00076 {
00077   mEventViewer->appendEvent(event);
00078   mIncidences.append(event->clone());
00079 }
00080 
00081 void AlarmDialog::appendTodo(Todo *todo)
00082 {
00083   mEventViewer->appendTodo(todo);
00084   mIncidences.append(todo->clone());
00085 }
00086 
00087 void AlarmDialog::clearEvents()
00088 {
00089   mEventViewer->clearEvents();
00090 
00091   mIncidences.clear();
00092 }
00093 
00094 void AlarmDialog::slotOk()
00095 {
00096   clearEvents();
00097   accept();
00098 }
00099 
00100 void AlarmDialog::slotUser1()
00101 {
00102   emit suspendSignal(mSuspendSpin->value());
00103   accept();
00104 }
00105 
00106 void AlarmDialog::eventNotification()
00107 {
00108   bool beeped = false;
00109 
00110   Incidence *in;
00111   for (in = mIncidences.first(); in; in = mIncidences.next()) {
00112     QPtrList<Alarm> alarms = in->alarms();
00113     const Alarm* alarm;
00114     for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
00115 // TODO: Check whether this should be done for all multiple alarms
00116       QString program = alarm->programFile();
00117       if (!program.isEmpty()) {
00118         kdDebug() << "Starting program: '" << program << "'" << endl;
00119         KProcess proc;
00120         proc << QFile::encodeName(alarm->programFile());
00121         proc.start(KProcess::DontCare);
00122       }
00123 
00124       if (!alarm->audioFile().isEmpty()) {
00125         beeped = true;
00126         KAudioPlayer::play(QFile::encodeName(alarm->audioFile()));
00127       }
00128     }
00129   }
00130   
00131   if ( !beeped ) {
00132     KNotifyClient::beep();
00133   }
00134 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:55 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001