korganizer 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 #include <qpushbutton.h> 00032 #include <qcstring.h> 00033 #include <qdatastream.h> 00034 00035 #include <kapplication.h> 00036 #include <dcopclient.h> 00037 #include <klocale.h> 00038 #include <kprocess.h> 00039 #include <kaudioplayer.h> 00040 #include <kdebug.h> 00041 #include <kmessagebox.h> 00042 #include <knotifyclient.h> 00043 #include <kcombobox.h> 00044 #include <kwin.h> 00045 00046 #include <libkcal/event.h> 00047 00048 #include "koeventviewer.h" 00049 00050 #include "alarmdialog.h" 00051 #include "alarmdialog.moc" 00052 00053 AlarmDialog::AlarmDialog( QWidget *parent, const char *name ) 00054 : KDialogBase( Plain, WType_TopLevel | WStyle_Customize | WStyle_StaysOnTop | 00055 WStyle_DialogBorder, 00056 parent, name, false, i18n("Alarm"), Ok | User1 | User2/* | User3*/, Ok/*3*/, 00057 false, i18n("Suspend"), i18n("Edit...") ) 00058 { 00059 QWidget *topBox = plainPage(); 00060 00061 QBoxLayout *topLayout = new QVBoxLayout( topBox ); 00062 topLayout->setSpacing( spacingHint() ); 00063 00064 QLabel *label = new QLabel( i18n("The following events triggered alarms:"), 00065 topBox ); 00066 topLayout->addWidget( label ); 00067 00068 mIncidences.setAutoDelete( true ); 00069 00070 mEventViewer = new KOEventViewer( topBox ); 00071 topLayout->addWidget( mEventViewer ); 00072 00073 QHBox *suspendBox = new QHBox( topBox ); 00074 suspendBox->setSpacing( spacingHint() ); 00075 topLayout->addWidget( suspendBox ); 00076 00077 new QLabel( i18n("Suspend duration:"), suspendBox ); 00078 mSuspendSpin = new QSpinBox( 1, 9999, 1, suspendBox ); 00079 mSuspendSpin->setValue( 5 ); // default suspend duration 00080 00081 mSuspendUnit = new KComboBox( suspendBox ); 00082 mSuspendUnit->insertItem( i18n("minute(s)") ); 00083 mSuspendUnit->insertItem( i18n("hour(s)") ); 00084 mSuspendUnit->insertItem( i18n("day(s)") ); 00085 mSuspendUnit->insertItem( i18n("week(s)") ); 00086 00087 connect( mSuspendSpin, SIGNAL( valueChanged(int) ), actionButton(User1), SLOT( setFocus() ) ); 00088 connect( mSuspendUnit, SIGNAL( activated(int) ), actionButton(User1), SLOT( setFocus() ) ); 00089 connect( mSuspendUnit, SIGNAL( activated(int) ), actionButton(User2), SLOT( setFocus() ) ); 00090 00091 // showButton( User2/*3*/, false ); 00092 00093 setMinimumSize( 300, 200 ); 00094 } 00095 00096 AlarmDialog::~AlarmDialog() 00097 { 00098 } 00099 00100 void AlarmDialog::appendEvent(Event *event) 00101 { 00102 mEventViewer->appendEvent(event); 00103 mIncidences.append(event->clone()); 00104 } 00105 00106 void AlarmDialog::appendTodo(Todo *todo) 00107 { 00108 mEventViewer->appendTodo(todo); 00109 mIncidences.append(todo->clone()); 00110 } 00111 00112 void AlarmDialog::clearEvents() 00113 { 00114 mEventViewer->clearEvents(); 00115 00116 mIncidences.clear(); 00117 } 00118 00119 void AlarmDialog::slotOk() 00120 { 00121 clearEvents(); 00122 accept(); 00123 } 00124 00125 void AlarmDialog::slotUser1() 00126 { 00127 int unit=1; 00128 switch (mSuspendUnit->currentItem()) { 00129 case 3: // weeks 00130 unit *= 7; 00131 case 2: // days 00132 unit *= 24; 00133 case 1: // hours 00134 unit *= 60; 00135 case 0: // minutes 00136 unit *= 60; 00137 default: 00138 break; 00139 } 00140 00141 emit suspendSignal( unit * mSuspendSpin->value() ); 00142 accept(); 00143 } 00144 00145 void AlarmDialog::slotUser2() 00146 { 00147 if ( !kapp->dcopClient()->isApplicationRegistered( "korganizer" ) ) { 00148 if ( kapp->startServiceByDesktopName( "korganizer", QString::null ) ) 00149 KMessageBox::error( 0, i18n("Could not start KOrganizer.") ); 00150 } 00151 00152 kapp->dcopClient()->send( "korganizer", "KOrganizerIface", 00153 "editIncidence(QString)", 00154 mIncidences.first()->uid() ); 00155 00156 // get desktop # where korganizer (or kontact) runs 00157 QByteArray replyData; 00158 QCString object, replyType; 00159 object = kapp->dcopClient()->isApplicationRegistered( "kontact" ) ? 00160 "kontact-mainwindow#1" : "KOrganizer MainWindow"; 00161 if (!kapp->dcopClient()->call( "korganizer", object, 00162 "getWinID()", 0, replyType, replyData, true, -1 ) ) { 00163 } 00164 00165 if ( replyType == "int" ) { 00166 int desktop, window; 00167 QDataStream ds( replyData, IO_ReadOnly ); 00168 ds >> window; 00169 desktop = KWin::windowInfo( window ).desktop(); 00170 00171 if ( KWin::currentDesktop() == desktop ) { 00172 KWin::iconifyWindow( winId(), false ); 00173 } 00174 else 00175 KWin::setCurrentDesktop( desktop ); 00176 00177 KWin::activateWindow( KWin::transientFor( window ) ); 00178 } 00179 00180 } 00181 00182 void AlarmDialog::eventNotification() 00183 { 00184 bool beeped = false; 00185 00186 Incidence *in; 00187 for (in = mIncidences.first(); in; in = mIncidences.next()) { 00188 Alarm::List alarms = in->alarms(); 00189 Alarm::List::ConstIterator it; 00190 for ( it = alarms.begin(); it != alarms.end(); ++it ) { 00191 Alarm *alarm = *it; 00192 // TODO: Check whether this should be done for all multiple alarms 00193 if (alarm->type() == Alarm::Procedure) { 00194 kdDebug(5890) << "Starting program: '" << alarm->programFile() << "'" << endl; 00195 KProcess proc; 00196 proc << QFile::encodeName(alarm->programFile()); 00197 proc.start(KProcess::DontCare); 00198 } 00199 else if (alarm->type() == Alarm::Audio) { 00200 beeped = true; 00201 KAudioPlayer::play(QFile::encodeName(alarm->audioFile())); 00202 } 00203 } 00204 } 00205 00206 if ( !beeped ) { 00207 KNotifyClient::beep(); 00208 } 00209 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:55 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003