summaryrefslogtreecommitdiffabout
path: root/korganizer/simplealarmclient.cpp
Unidiff
Diffstat (limited to 'korganizer/simplealarmclient.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/simplealarmclient.cpp111
1 files changed, 111 insertions, 0 deletions
diff --git a/korganizer/simplealarmclient.cpp b/korganizer/simplealarmclient.cpp
new file mode 100644
index 0000000..4882a27
--- a/dev/null
+++ b/korganizer/simplealarmclient.cpp
@@ -0,0 +1,111 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2002,2003 Cornelius Schumacher <schumacher@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24#include "simplealarmclient.h"
25
26#include <kprocess.h>
27#include <kdebug.h>
28#include <kstandarddirs.h>
29
30#include <qfile.h>
31#include <qtextstream.h>
32
33SimpleAlarmClient::SimpleAlarmClient()
34 : mProcess( 0 )
35{
36 //mCalendarsFile = locateLocal( "data", "simplealarmdaemon/calendars" );
37
38
39}
40
41SimpleAlarmClient::~SimpleAlarmClient()
42{
43 delete mProcess;
44}
45
46void SimpleAlarmClient::startDaemon()
47{
48
49 qDebug("SimpleAlarmClient::startDaemon() ");
50 if ( !mProcess ) {
51 mProcess = new KProcess;
52 *mProcess << "simplealarmdaemon";
53 if ( !mProcess->start() ) {
54 kdDebug() << "Failed to start process." << endl;
55 }
56 }
57}
58
59bool SimpleAlarmClient::setCalendars( const QStringList &calendars )
60{
61
62
63 QFile f( mCalendarsFile );
64 if ( !f.open( IO_WriteOnly ) ) {
65 kdDebug() << "Unable to open file '" << mCalendarsFile << "'" << endl;
66 return false;
67 }
68 QTextStream ts( &f );
69 QStringList::ConstIterator it;
70 for ( it = calendars.begin(); it != calendars.end(); ++it ) {
71 kdDebug() << "CAL: " << *it << endl;
72 ts << *it << "\n";
73 }
74 f.close();
75
76 return true;
77}
78
79bool SimpleAlarmClient::addCalendar( const QString &calendar )
80{
81 QFile f( mCalendarsFile );
82 if ( !f.open( IO_WriteOnly | IO_Append ) ) return false;
83 QTextStream ts( &f );
84 ts << calendar << "\n";
85 f.close();
86
87 return true;
88}
89
90bool SimpleAlarmClient::removeCalendar( const QString &calendar )
91{
92 QStringList calendars;
93
94 QFile f( mCalendarsFile );
95 if ( !f.open( IO_ReadOnly ) ) return false;
96 QTextStream ts( &f );
97 bool found = false;
98 QString line;
99 while ( !( line = ts.readLine() ).isNull() ) {
100 if ( line != calendar ) calendars.append( line );
101 else found = true;
102 }
103
104 if ( found ) return setCalendars( calendars );
105 else return true;
106}
107
108bool SimpleAlarmClient::reloadCalendar( const QString & )
109{
110 return true;
111}