summaryrefslogtreecommitdiffabout
path: root/libkdepim/phoneaccess.cpp
Unidiff
Diffstat (limited to 'libkdepim/phoneaccess.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libkdepim/phoneaccess.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/libkdepim/phoneaccess.cpp b/libkdepim/phoneaccess.cpp
index 89db22b..0ea73f5 100644
--- a/libkdepim/phoneaccess.cpp
+++ b/libkdepim/phoneaccess.cpp
@@ -1,78 +1,81 @@
1/* 1/*
2 This file is part of libkdepim. 2 This file is part of libkdepim.
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 22
23#include <qstring.h> 23#include <qstring.h>
24#include <qapplication.h> 24#include <qapplication.h>
25#include <qptrlist.h> 25#include <QDesktopWidget>
26#include <q3ptrlist.h>
26#include <qregexp.h> 27#include <qregexp.h>
27#include <qfile.h> 28#include <qfile.h>
28#include <qlabel.h> 29#include <qlabel.h>
29#include <qtextstream.h> 30#include <q3textstream.h>
30#include <qtextcodec.h> 31#include <qtextcodec.h>
31#include <qdir.h> 32#include <qdir.h>
32#include <kmessagebox.h> 33#include <kmessagebox.h>
33#include <stdlib.h> 34#include <stdlib.h>
34#include "phoneaccess.h" 35#include "phoneaccess.h"
35 36
36void PhoneAccess::writeConfig( QString device, QString connection, QString model ) 37void PhoneAccess::writeConfig( QString device, QString connection, QString model )
37{ 38{
38#ifdef _WIN32_ 39#ifdef _WIN32_
39 QString fileName = qApp->applicationDirPath () +"\\gammurc"; 40 QString fileName = qApp->applicationDirPath () +"\\gammurc";
40#else 41#else
41 QString fileName = QDir::homeDirPath() +"/.gammurc"; 42 QString fileName = QDir::homeDirPath() +"/.gammurc";
42#endif 43#endif
43 //qDebug("save %d ", load ); 44 //qDebug("save %d ", load );
44 QString content = "[gammu]\n";; 45 QString content = "[gammu]\n";;
45 bool write = false; 46 bool write = false;
46 bool addPort = true, addConnection = true, addModel = true; 47 bool addPort = true, addConnection = true, addModel = true;
47 QFile file( fileName ); 48 QFile file( fileName );
48 if ( QFile::exists( fileName) ) { 49 if ( QFile::exists( fileName) ) {
49 if (!file.open( IO_ReadOnly ) ) { 50 if (!file.open( QIODevice::ReadOnly ) ) {
50 qDebug("Error: cannot open %s ", fileName.latin1() ); 51 qDebug("Error: cannot open %s ", fileName.latin1() );
51 return; 52 return;
52 } 53 }
53 QString line; 54 QString line;
54 while ( file.readLine( line, 1024 ) > 0 ) { 55 char tmp[1024];
56 while ( file.readLine( tmp, 1024 ) > 0 ) {
57 line = tmp;
55 //qDebug("*%s* ", line.latin1() ); 58 //qDebug("*%s* ", line.latin1() );
56 if ( line.left(7 ) == "[gammu]" ) { 59 if ( line.left(7 ) == "[gammu]" ) {
57 ; 60 ;
58 } else 61 } else
59 if ( line.left(4 ) == "port" ) { 62 if ( line.left(4 ) == "port" ) {
60 if ( line == "port = " + device+"\n" ) { 63 if ( line == "port = " + device+"\n" ) {
61 content += line ; 64 content += line ;
62 addPort = false; 65 addPort = false;
63 //qDebug("port found" ); 66 //qDebug("port found" );
64 } 67 }
65 68
66 } else if ( line.left(5 ) == "model" ) { 69 } else if ( line.left(5 ) == "model" ) {
67 if ( line == "model = " + model +"\n") { 70 if ( line == "model = " + model +"\n") {
68 content += line ; 71 content += line ;
69 addModel = false; 72 addModel = false;
70 //qDebug("model found" ); 73 //qDebug("model found" );
71 } 74 }
72 75
73 } else if ( line.left( 10 ) == "connection" ) { 76 } else if ( line.left( 10 ) == "connection" ) {
74 if ( line == "connection = " + connection +"\n") { 77 if ( line == "connection = " + connection +"\n") {
75 addConnection = false; 78 addConnection = false;
76 content += line ; 79 content += line ;
77 //qDebug("con found" ); 80 //qDebug("con found" );
78 } 81 }
@@ -94,54 +97,54 @@ void PhoneAccess::writeConfig( QString device, QString connection, QString model
94 addModel = true; 97 addModel = true;
95 } 98 }
96 } 99 }
97 100
98 if ( addConnection ) { 101 if ( addConnection ) {
99 write = true; 102 write = true;
100 content += "connection = "; 103 content += "connection = ";
101 content += connection; 104 content += connection;
102 content += "\n"; 105 content += "\n";
103 } 106 }
104 if ( addPort ) { 107 if ( addPort ) {
105 write = true; 108 write = true;
106 content += "port = "; 109 content += "port = ";
107 content += device; 110 content += device;
108 content += "\n"; 111 content += "\n";
109 112
110 } 113 }
111 if ( addModel ) { 114 if ( addModel ) {
112 write = true; 115 write = true;
113 content += "model = "; 116 content += "model = ";
114 content += model; 117 content += model;
115 content += "\n"; 118 content += "\n";
116 } 119 }
117 if ( write ) { 120 if ( write ) {
118 if (!file.open( IO_WriteOnly ) ) { 121 if (!file.open( QIODevice::WriteOnly ) ) {
119 qDebug("Error: cannot write file %s ", fileName.latin1() ); 122 qDebug("Error: cannot write file %s ", fileName.latin1() );
120 return; 123 return;
121 } 124 }
122 qDebug("Writing file %s ", fileName.latin1() ); 125 qDebug("Writing file %s ", fileName.latin1() );
123 QTextStream ts( &file ); 126 Q3TextStream ts( &file );
124 ts << content ; 127 ts << content ;
125 file.close(); 128 file.close();
126 } 129 }
127 130
128} 131}
129 132
130 133
131bool PhoneAccess::writeToPhone( QString fileName) 134bool PhoneAccess::writeToPhone( QString fileName)
132{ 135{
133 136
134#ifdef DESKTOP_VERSION 137#ifdef DESKTOP_VERSION
135#ifdef _WIN32_ 138#ifdef _WIN32_
136 QString command ="kammu --restore " + fileName ; 139 QString command ="kammu --restore " + fileName ;
137#else 140#else
138 QString command ="./kammu --restore " + fileName ; 141 QString command ="./kammu --restore " + fileName ;
139#endif 142#endif
140#else 143#else
141 QString command ="kammu --restore " + fileName ; 144 QString command ="kammu --restore " + fileName ;
142#endif 145#endif
143 int ret = 1; 146 int ret = 1;
144 while ( ret != 0 ) { 147 while ( ret != 0 ) {
145 QLabel* status = new QLabel( i18n(" This may take 1-3 minutes!"), 0 ); 148 QLabel* status = new QLabel( i18n(" This may take 1-3 minutes!"), 0 );
146 int w = 235; 149 int w = 235;
147 int h = status->sizeHint().height()+20 ; 150 int h = status->sizeHint().height()+20 ;