-rw-r--r-- | libkcal/phoneformat.cpp | 97 |
1 files changed, 93 insertions, 4 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 178a63e..99d6a06 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -1,137 +1,226 @@ | |||
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; |