summaryrefslogtreecommitdiffabout
path: root/libkcal/phoneformat.cpp
Unidiff
Diffstat (limited to 'libkcal/phoneformat.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp97
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
@@ -29,7 +29,7 @@
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>
@@ -84,9 +84,98 @@ public:
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()