summaryrefslogtreecommitdiffabout
path: root/libkdepim/phoneaccess.cpp
Unidiff
Diffstat (limited to 'libkdepim/phoneaccess.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/phoneaccess.cpp12
1 files changed, 3 insertions, 9 deletions
diff --git a/libkdepim/phoneaccess.cpp b/libkdepim/phoneaccess.cpp
index c0bd6cc..357cd39 100644
--- a/libkdepim/phoneaccess.cpp
+++ b/libkdepim/phoneaccess.cpp
@@ -19,122 +19,116 @@
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22 22
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 <qfile.h> 27#include <qfile.h>
28#include <qtextstream.h> 28#include <qtextstream.h>
29#include <qtextcodec.h> 29#include <qtextcodec.h>
30#include <qdir.h> 30#include <qdir.h>
31#include <kmessagebox.h> 31#include <kmessagebox.h>
32#include <stdlib.h> 32#include <stdlib.h>
33#include "phoneaccess.h" 33#include "phoneaccess.h"
34 34
35void PhoneAccess::writeConfig( QString device, QString connection, QString model ) 35void PhoneAccess::writeConfig( QString device, QString connection, QString model )
36{ 36{
37#ifdef _WIN32_ 37#ifdef _WIN32_
38 QString fileName = qApp->applicationDirPath () +"\\gammurc"; 38 QString fileName = qApp->applicationDirPath () +"\\gammurc";
39#else 39#else
40 QString fileName = QDir::homeDirPath() +"/.gammurc"; 40 QString fileName = QDir::homeDirPath() +"/.gammurc";
41#endif 41#endif
42 //qDebug("save %d ", load ); 42 //qDebug("save %d ", load );
43 QString content; 43 QString content = "[gammu]\n";;
44 bool write = false; 44 bool write = false;
45 bool addPort = true, addConnection = true, addModel = true; 45 bool addPort = true, addConnection = true, addModel = true;
46 QFile file( fileName ); 46 QFile file( fileName );
47 if ( QFile::exists( fileName) ) { 47 if ( QFile::exists( fileName) ) {
48 if (!file.open( IO_ReadOnly ) ) { 48 if (!file.open( IO_ReadOnly ) ) {
49 qDebug("Error: cannot open %s ", fileName.latin1() ); 49 qDebug("Error: cannot open %s ", fileName.latin1() );
50 return; 50 return;
51 } 51 }
52 QString line; 52 QString line;
53 while ( file.readLine( line, 1024 ) > 0 ) { 53 while ( file.readLine( line, 1024 ) > 0 ) {
54 //qDebug("*%s* ", line.latin1() ); 54 //qDebug("*%s* ", line.latin1() );
55 if ( line.left(7 ) == "[gammu]" ) { 55 if ( line.left(7 ) == "[gammu]" ) {
56 ; 56 ;
57 } else 57 } else
58 if ( line.left(4 ) == "port" ) { 58 if ( line.left(4 ) == "port" ) {
59 if ( line == "port = " + device+"\n" ) { 59 if ( line == "port = " + device+"\n" ) {
60 content += line ; 60 content += line ;
61 addPort = false; 61 addPort = false;
62 //qDebug("port found" ); 62 //qDebug("port found" );
63 } 63 }
64 64
65 } else if ( line.left(5 ) == "model" ) { 65 } else if ( line.left(5 ) == "model" ) {
66 if ( line == "model = " + model +"\n") { 66 if ( line == "model = " + model +"\n") {
67 content += line ; 67 content += line ;
68 addModel = false; 68 addModel = false;
69 //qDebug("model found" ); 69 //qDebug("model found" );
70 } 70 }
71 71
72 } else if ( line.left( 10 ) == "connection" ) { 72 } else if ( line.left( 10 ) == "connection" ) {
73 if ( line == "connection = " + connection +"\n") { 73 if ( line == "connection = " + connection +"\n") {
74 addConnection = false; 74 addConnection = false;
75 content += line ; 75 content += line ;
76 //qDebug("con found" ); 76 //qDebug("con found" );
77 } 77 }
78 78
79 } else { 79 } else {
80 content += line ; 80 content += line ;
81 } 81 }
82 } 82 }
83 file.close(); 83 file.close();
84 } else { 84 } else {
85 if ( ! connection.isEmpty() ) { 85 if ( ! connection.isEmpty() ) {
86 addConnection = true; 86 addConnection = true;
87 } 87 }
88 if ( ! device.isEmpty() ) { 88 if ( ! device.isEmpty() ) {
89 addPort = true; 89 addPort = true;
90 90
91 } 91 }
92 if ( ! model.isEmpty() ) { 92 if ( ! model.isEmpty() ) {
93 addModel = true; 93 addModel = true;
94 } 94 }
95 } 95 }
96 96
97 if ( addConnection ) { 97 if ( addConnection ) {
98 if ( ! write )
99 content += "[gammu]\n";
100 write = true; 98 write = true;
101 content += "connection = "; 99 content += "connection = ";
102 content += connection; 100 content += connection;
103 content += "\n"; 101 content += "\n";
104 } 102 }
105 if ( addPort ) { 103 if ( addPort ) {
106 if ( ! write )
107 content += "[gammu]\n";
108 write = true; 104 write = true;
109 content += "port = "; 105 content += "port = ";
110 content += device; 106 content += device;
111 content += "\n"; 107 content += "\n";
112 108
113 } 109 }
114 if ( addModel ) { 110 if ( addModel ) {
115 if ( ! write )
116 content += "[gammu]\n";
117 write = true; 111 write = true;
118 content += "model = "; 112 content += "model = ";
119 content += model; 113 content += model;
120 content += "\n"; 114 content += "\n";
121 } 115 }
122 if ( write ) { 116 if ( write ) {
123 if (!file.open( IO_WriteOnly ) ) { 117 if (!file.open( IO_WriteOnly ) ) {
124 qDebug("Error: cannot write file %s ", fileName.latin1() ); 118 qDebug("Error: cannot write file %s ", fileName.latin1() );
125 return; 119 return;
126 } 120 }
127 qDebug("Writing file %s ", fileName.latin1() ); 121 qDebug("Writing file %s ", fileName.latin1() );
128 QTextStream ts( &file ); 122 QTextStream ts( &file );
129 ts << content ; 123 ts << content ;
130 file.close(); 124 file.close();
131 } 125 }
132 126
133} 127}
134 128
135 129
136bool PhoneAccess::writeToPhone( QString fileName) 130bool PhoneAccess::writeToPhone( QString fileName)
137{ 131{
138 132
139#ifdef DESKTOP_VERSION 133#ifdef DESKTOP_VERSION
140 QString command ="./kammu --restore " + fileName ; 134 QString command ="./kammu --restore " + fileName ;