author | zautrix <zautrix> | 2004-09-12 20:24:05 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-12 20:24:05 (UTC) |
commit | 7fcde3393eb2150fd96f7899056ec11d0fd2931e (patch) (unidiff) | |
tree | d46619e939b655b33df280f16c30b5e675be7450 | |
parent | 5b434dd78f71bcea5e6067fc8ae0faaaea313f9d (diff) | |
download | kdepimpi-7fcde3393eb2150fd96f7899056ec11d0fd2931e.zip kdepimpi-7fcde3393eb2150fd96f7899056ec11d0fd2931e.tar.gz kdepimpi-7fcde3393eb2150fd96f7899056ec11d0fd2931e.tar.bz2 |
writing gammurc added
-rw-r--r-- | libkcal/phoneformat.cpp | 97 | ||||
-rw-r--r-- | libkcal/phoneformat.h | 2 |
2 files changed, 94 insertions, 5 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 178a63e..99d6a06 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -1,153 +1,242 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> | 4 | Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <qdatetime.h> | 22 | #include <qdatetime.h> |
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qapplication.h> | 24 | #include <qapplication.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | #include <qregexp.h> | 26 | #include <qregexp.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | #include <qclipboard.h> | 28 | #include <qclipboard.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | #include <qtextcodec.h> | 31 | #include <qtextcodec.h> |
32 | #include <qxml.h> | 32 | #include <qdir.h> |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | 34 | ||
35 | #include <kdebug.h> | 35 | #include <kdebug.h> |
36 | #include <klocale.h> | 36 | #include <klocale.h> |
37 | #include <kglobal.h> | 37 | #include <kglobal.h> |
38 | #include <kmessagebox.h> | 38 | #include <kmessagebox.h> |
39 | 39 | ||
40 | #include "calendar.h" | 40 | #include "calendar.h" |
41 | #include "alarm.h" | 41 | #include "alarm.h" |
42 | #include "recurrence.h" | 42 | #include "recurrence.h" |
43 | #include "calendarlocal.h" | 43 | #include "calendarlocal.h" |
44 | 44 | ||
45 | #include "phoneformat.h" | 45 | #include "phoneformat.h" |
46 | #include "syncdefines.h" | 46 | #include "syncdefines.h" |
47 | 47 | ||
48 | using namespace KCal; | 48 | using namespace KCal; |
49 | class PhoneParser : public QObject | 49 | class PhoneParser : public QObject |
50 | { | 50 | { |
51 | public: | 51 | public: |
52 | PhoneParser( ) { | 52 | PhoneParser( ) { |
53 | ; | 53 | ; |
54 | } | 54 | } |
55 | 55 | ||
56 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) | 56 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) |
57 | { | 57 | { |
58 | QString datestr; | 58 | QString datestr; |
59 | QString timestr; | 59 | QString timestr; |
60 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 60 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
61 | QDateTime dt; | 61 | QDateTime dt; |
62 | if (useTZ) | 62 | if (useTZ) |
63 | dt = dti.addSecs ( -(offset*60)); | 63 | dt = dti.addSecs ( -(offset*60)); |
64 | else | 64 | else |
65 | dt = dti; | 65 | dt = dti; |
66 | if(dt.date().isValid()){ | 66 | if(dt.date().isValid()){ |
67 | const QDate& date = dt.date(); | 67 | const QDate& date = dt.date(); |
68 | datestr.sprintf("%04d%02d%02d", | 68 | datestr.sprintf("%04d%02d%02d", |
69 | date.year(), date.month(), date.day()); | 69 | date.year(), date.month(), date.day()); |
70 | } | 70 | } |
71 | if(dt.time().isValid()){ | 71 | if(dt.time().isValid()){ |
72 | const QTime& time = dt.time(); | 72 | const QTime& time = dt.time(); |
73 | timestr.sprintf("T%02d%02d%02d", | 73 | timestr.sprintf("T%02d%02d%02d", |
74 | time.hour(), time.minute(), time.second()); | 74 | time.hour(), time.minute(), time.second()); |
75 | } | 75 | } |
76 | return datestr + timestr; | 76 | return datestr + timestr; |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
80 | }; | 80 | }; |
81 | 81 | ||
82 | 82 | ||
83 | 83 | ||
84 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) | 84 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) |
85 | { | 85 | { |
86 | mProfileName = profileName; | 86 | mProfileName = profileName; |
87 | mDevice = device; | 87 | |
88 | mConnection = connection; | 88 | QString fileName = QDir::homeDirPath() +"/.gammurc"; |
89 | mModel = model; | 89 | //qDebug("save %d ", load ); |
90 | QString content; | ||
91 | bool write = false; | ||
92 | bool addPort = true, addConnection = true, addModel = true; | ||
93 | QFile file( fileName ); | ||
94 | if ( QFile::exists( fileName) ) { | ||
95 | if (!file.open( IO_ReadOnly ) ) { | ||
96 | qDebug("Error: cannot open %s ", fileName.latin1() ); | ||
97 | return; | ||
98 | } | ||
99 | QString line; | ||
100 | while ( file.readLine( line, 1024 ) > 0 ) { | ||
101 | //qDebug("*%s* ", line.latin1() ); | ||
102 | if ( line.left(7 ) == "[gammu]" ) { | ||
103 | ; | ||
104 | } else | ||
105 | if ( line.left(4 ) == "port" ) { | ||
106 | if ( line == "port = " + device+"\n" ) { | ||
107 | content += line ; | ||
108 | addPort = false; | ||
109 | //qDebug("port found" ); | ||
110 | } | ||
111 | |||
112 | } else if ( line.left(5 ) == "model" ) { | ||
113 | if ( line == "model = " + model +"\n") { | ||
114 | content += line ; | ||
115 | addModel = false; | ||
116 | //qDebug("model found" ); | ||
117 | } | ||
118 | |||
119 | } else if ( line.left( 10 ) == "connection" ) { | ||
120 | if ( line == "connection = " + connection +"\n") { | ||
121 | addConnection = false; | ||
122 | content += line ; | ||
123 | //qDebug("con found" ); | ||
124 | } | ||
125 | |||
126 | } else { | ||
127 | content += line ; | ||
128 | } | ||
129 | } | ||
130 | file.close(); | ||
131 | } else { | ||
132 | if ( ! connection.isEmpty() ) { | ||
133 | addConnection = true; | ||
134 | } | ||
135 | if ( ! device.isEmpty() ) { | ||
136 | addPort = true; | ||
137 | |||
138 | } | ||
139 | if ( ! model.isEmpty() ) { | ||
140 | addModel = true; | ||
141 | } | ||
142 | } | ||
143 | |||
144 | if ( addConnection ) { | ||
145 | if ( ! write ) | ||
146 | content += "[gammu]\n"; | ||
147 | write = true; | ||
148 | content += "connection = "; | ||
149 | content += connection; | ||
150 | content += "\n"; | ||
151 | } | ||
152 | if ( addPort ) { | ||
153 | if ( ! write ) | ||
154 | content += "[gammu]\n"; | ||
155 | write = true; | ||
156 | content += "port = "; | ||
157 | content += device; | ||
158 | content += "\n"; | ||
159 | |||
160 | } | ||
161 | if ( addModel ) { | ||
162 | if ( ! write ) | ||
163 | content += "[gammu]\n"; | ||
164 | write = true; | ||
165 | content += "model = "; | ||
166 | content += model; | ||
167 | content += "\n"; | ||
168 | } | ||
169 | if ( write ) { | ||
170 | if (!file.open( IO_WriteOnly ) ) { | ||
171 | qDebug("Error: cannot write file %s ", fileName.latin1() ); | ||
172 | return; | ||
173 | } | ||
174 | qDebug("Writing file %s ", fileName.latin1() ); | ||
175 | QTextStream ts( &file ); | ||
176 | ts << content ; | ||
177 | file.close(); | ||
178 | } | ||
90 | } | 179 | } |
91 | 180 | ||
92 | PhoneFormat::~PhoneFormat() | 181 | PhoneFormat::~PhoneFormat() |
93 | { | 182 | { |
94 | } | 183 | } |
95 | #if 0 | 184 | #if 0 |
96 | int PhoneFormat::initDevice(GSM_StateMachine *s) | 185 | int PhoneFormat::initDevice(GSM_StateMachine *s) |
97 | { | 186 | { |
98 | GSM_ReadConfig(NULL, &s->Config[0], 0); | 187 | GSM_ReadConfig(NULL, &s->Config[0], 0); |
99 | s->ConfigNum = 1; | 188 | s->ConfigNum = 1; |
100 | GSM_Config *cfg = &s->Config[0]; | 189 | GSM_Config *cfg = &s->Config[0]; |
101 | if ( ! mConnection.isEmpty() ) { | 190 | if ( ! mConnection.isEmpty() ) { |
102 | cfg->Connection = strdup(mConnection.latin1()); | 191 | cfg->Connection = strdup(mConnection.latin1()); |
103 | cfg->DefaultConnection = false; | 192 | cfg->DefaultConnection = false; |
104 | qDebug("Connection set %s ", cfg->Connection ); | 193 | qDebug("Connection set %s ", cfg->Connection ); |
105 | 194 | ||
106 | } | 195 | } |
107 | if ( ! mDevice.isEmpty() ) { | 196 | if ( ! mDevice.isEmpty() ) { |
108 | cfg->Device = strdup(mDevice.latin1()); | 197 | cfg->Device = strdup(mDevice.latin1()); |
109 | cfg->DefaultDevice = false; | 198 | cfg->DefaultDevice = false; |
110 | qDebug("Device set %s ", cfg->Device); | 199 | qDebug("Device set %s ", cfg->Device); |
111 | 200 | ||
112 | } | 201 | } |
113 | if ( ! mModel.isEmpty() ) { | 202 | if ( ! mModel.isEmpty() ) { |
114 | strcpy(cfg->Model,mModel.latin1() ); | 203 | strcpy(cfg->Model,mModel.latin1() ); |
115 | cfg->DefaultModel = false; | 204 | cfg->DefaultModel = false; |
116 | qDebug("Model set %s ",cfg->Model ); | 205 | qDebug("Model set %s ",cfg->Model ); |
117 | } | 206 | } |
118 | int error=GSM_InitConnection(s,3); | 207 | int error=GSM_InitConnection(s,3); |
119 | return error; | 208 | return error; |
120 | } | 209 | } |
121 | #endif | 210 | #endif |
122 | ulong PhoneFormat::getCsumTodo( Todo* todo ) | 211 | ulong PhoneFormat::getCsumTodo( Todo* todo ) |
123 | { | 212 | { |
124 | QStringList attList; | 213 | QStringList attList; |
125 | if ( todo->hasDueDate() ) | 214 | if ( todo->hasDueDate() ) |
126 | attList << PhoneParser::dtToString ( todo->dtDue() ); | 215 | attList << PhoneParser::dtToString ( todo->dtDue() ); |
127 | attList << todo->summary(); | 216 | attList << todo->summary(); |
128 | QString completedString = "no"; | 217 | QString completedString = "no"; |
129 | if ( todo->isCompleted() ) | 218 | if ( todo->isCompleted() ) |
130 | completedString = "yes"; | 219 | completedString = "yes"; |
131 | attList << completedString; | 220 | attList << completedString; |
132 | int prio = todo->priority(); | 221 | int prio = todo->priority(); |
133 | if( prio == 2 ) prio = 1; | 222 | if( prio == 2 ) prio = 1; |
134 | if (prio == 4 ) prio = 5 ; | 223 | if (prio == 4 ) prio = 5 ; |
135 | attList << QString::number( prio ); | 224 | attList << QString::number( prio ); |
136 | QString alarmString = "na"; | 225 | QString alarmString = "na"; |
137 | Alarm *alarm; | 226 | Alarm *alarm; |
138 | if ( todo->alarms().count() > 0 ) { | 227 | if ( todo->alarms().count() > 0 ) { |
139 | alarm = todo->alarms().first(); | 228 | alarm = todo->alarms().first(); |
140 | if ( alarm->enabled() ) { | 229 | if ( alarm->enabled() ) { |
141 | alarmString = QString::number(alarm->offset() ); | 230 | alarmString = QString::number(alarm->offset() ); |
142 | } | 231 | } |
143 | } | 232 | } |
144 | attList << alarmString; | 233 | attList << alarmString; |
145 | attList << todo->categoriesStr(); | 234 | attList << todo->categoriesStr(); |
146 | attList << todo->secrecyStr(); | 235 | attList << todo->secrecyStr(); |
147 | return PhoneFormat::getCsum(attList ); | 236 | return PhoneFormat::getCsum(attList ); |
148 | 237 | ||
149 | } | 238 | } |
150 | ulong PhoneFormat::getCsumEvent( Event* event ) | 239 | ulong PhoneFormat::getCsumEvent( Event* event ) |
151 | { | 240 | { |
152 | QStringList attList; | 241 | QStringList attList; |
153 | attList << PhoneParser::dtToString ( event->dtStart() ); | 242 | attList << PhoneParser::dtToString ( event->dtStart() ); |
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h index 8286098..2d1ff79 100644 --- a/libkcal/phoneformat.h +++ b/libkcal/phoneformat.h | |||
@@ -1,61 +1,61 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | #ifndef PHONEFORMAT_H | 21 | #ifndef PHONEFORMAT_H |
22 | #define PHONEFORMAT_H | 22 | #define PHONEFORMAT_H |
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | 25 | ||
26 | #include "scheduler.h" | 26 | #include "scheduler.h" |
27 | 27 | ||
28 | #include "vcalformat.h" | 28 | #include "vcalformat.h" |
29 | #include "calformat.h" | 29 | #include "calformat.h" |
30 | 30 | ||
31 | namespace KCal { | 31 | namespace KCal { |
32 | 32 | ||
33 | /** | 33 | /** |
34 | This class implements the calendar format used by Phone. | 34 | This class implements the calendar format used by Phone. |
35 | */ | 35 | */ |
36 | class Event; | 36 | class Event; |
37 | class Todo; | 37 | class Todo; |
38 | class PhoneFormat : public QObject { | 38 | class PhoneFormat : public QObject { |
39 | public: | 39 | public: |
40 | /** Create new iCalendar format. */ | 40 | /** Create new iCalendar format. */ |
41 | PhoneFormat(QString profileName, QString device,QString connection, QString model); | 41 | PhoneFormat(QString profileName, QString device,QString connection, QString model); |
42 | virtual ~PhoneFormat(); | 42 | virtual ~PhoneFormat(); |
43 | 43 | ||
44 | bool load( Calendar * ,Calendar * ); | 44 | bool load( Calendar * ,Calendar * ); |
45 | bool save( Calendar * ); | 45 | bool save( Calendar * ); |
46 | bool fromString( Calendar *, const QString & ); | 46 | bool fromString( Calendar *, const QString & ); |
47 | QString toString( Calendar * ); | 47 | QString toString( Calendar * ); |
48 | static ulong getCsum( const QStringList & ); | 48 | static ulong getCsum( const QStringList & ); |
49 | static ulong getCsumTodo( Todo* to ); | 49 | static ulong getCsumTodo( Todo* to ); |
50 | static ulong getCsumEvent( Event* ev ); | 50 | static ulong getCsumEvent( Event* ev ); |
51 | private: | 51 | private: |
52 | void copyEvent( Event* to, Event* from ); | 52 | void copyEvent( Event* to, Event* from ); |
53 | void copyTodo( Todo* to, Todo* from ); | 53 | void copyTodo( Todo* to, Todo* from ); |
54 | //int initDevice(GSM_StateMachine *s); | 54 | //int initDevice(GSM_StateMachine *s); |
55 | QString mProfileName, mDevice, mConnection, mModel; | 55 | QString mProfileName; |
56 | void afterSave( Incidence* ); | 56 | void afterSave( Incidence* ); |
57 | }; | 57 | }; |
58 | 58 | ||
59 | } | 59 | } |
60 | 60 | ||
61 | #endif | 61 | #endif |