summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-12 20:24:05 (UTC)
committer zautrix <zautrix>2004-09-12 20:24:05 (UTC)
commit7fcde3393eb2150fd96f7899056ec11d0fd2931e (patch) (unidiff)
treed46619e939b655b33df280f16c30b5e675be7450
parent5b434dd78f71bcea5e6067fc8ae0faaaea313f9d (diff)
downloadkdepimpi-7fcde3393eb2150fd96f7899056ec11d0fd2931e.zip
kdepimpi-7fcde3393eb2150fd96f7899056ec11d0fd2931e.tar.gz
kdepimpi-7fcde3393eb2150fd96f7899056ec11d0fd2931e.tar.bz2
writing gammurc added
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp97
-rw-r--r--libkcal/phoneformat.h2
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
@@ -8,49 +8,49 @@
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
48using namespace KCal; 48using namespace KCal;
49class PhoneParser : public QObject 49class PhoneParser : public QObject
50{ 50{
51public: 51public:
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 )
@@ -63,51 +63,140 @@ public:
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
84PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) 84PhoneFormat::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
92PhoneFormat::~PhoneFormat() 181PhoneFormat::~PhoneFormat()
93{ 182{
94} 183}
95#if 0 184#if 0
96int PhoneFormat::initDevice(GSM_StateMachine *s) 185int 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() ) {
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h
index 8286098..2d1ff79 100644
--- a/libkcal/phoneformat.h
+++ b/libkcal/phoneformat.h
@@ -31,31 +31,31 @@
31namespace KCal { 31namespace 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;
38class PhoneFormat : public QObject { 38class 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