summaryrefslogtreecommitdiffabout
path: root/libkdepim/phoneaccess.cpp
authorzautrix <zautrix>2004-10-15 14:26:07 (UTC)
committer zautrix <zautrix>2004-10-15 14:26:07 (UTC)
commit4f276d80bd977401d656851515474cc00c661e5b (patch) (unidiff)
tree0d3a747bef0431ef791b69876f5bda554f9ca83f /libkdepim/phoneaccess.cpp
parentc2fb960297c4b08980921c818a4d347057732390 (diff)
downloadkdepimpi-4f276d80bd977401d656851515474cc00c661e5b.zip
kdepimpi-4f276d80bd977401d656851515474cc00c661e5b.tar.gz
kdepimpi-4f276d80bd977401d656851515474cc00c661e5b.tar.bz2
many phone and sync fixes
Diffstat (limited to 'libkdepim/phoneaccess.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/phoneaccess.cpp69
1 files changed, 56 insertions, 13 deletions
diff --git a/libkdepim/phoneaccess.cpp b/libkdepim/phoneaccess.cpp
index 8298aa6..e24ad9e 100644
--- a/libkdepim/phoneaccess.cpp
+++ b/libkdepim/phoneaccess.cpp
@@ -1,173 +1,216 @@
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 <qptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qfile.h> 27#include <qfile.h>
28#include <qlabel.h>
28#include <qtextstream.h> 29#include <qtextstream.h>
29#include <qtextcodec.h> 30#include <qtextcodec.h>
30#include <qdir.h> 31#include <qdir.h>
31#include <kmessagebox.h> 32#include <kmessagebox.h>
32#include <stdlib.h> 33#include <stdlib.h>
33#include "phoneaccess.h" 34#include "phoneaccess.h"
34 35
35void PhoneAccess::writeConfig( QString device, QString connection, QString model ) 36void PhoneAccess::writeConfig( QString device, QString connection, QString model )
36{ 37{
37#ifdef _WIN32_ 38#ifdef _WIN32_
38 QString fileName = qApp->applicationDirPath () +"\\gammurc"; 39 QString fileName = qApp->applicationDirPath () +"\\gammurc";
39#else 40#else
40 QString fileName = QDir::homeDirPath() +"/.gammurc"; 41 QString fileName = QDir::homeDirPath() +"/.gammurc";
41#endif 42#endif
42 //qDebug("save %d ", load ); 43 //qDebug("save %d ", load );
43 QString content = "[gammu]\n";; 44 QString content = "[gammu]\n";;
44 bool write = false; 45 bool write = false;
45 bool addPort = true, addConnection = true, addModel = true; 46 bool addPort = true, addConnection = true, addModel = true;
46 QFile file( fileName ); 47 QFile file( fileName );
47 if ( QFile::exists( fileName) ) { 48 if ( QFile::exists( fileName) ) {
48 if (!file.open( IO_ReadOnly ) ) { 49 if (!file.open( IO_ReadOnly ) ) {
49 qDebug("Error: cannot open %s ", fileName.latin1() ); 50 qDebug("Error: cannot open %s ", fileName.latin1() );
50 return; 51 return;
51 } 52 }
52 QString line; 53 QString line;
53 while ( file.readLine( line, 1024 ) > 0 ) { 54 while ( file.readLine( line, 1024 ) > 0 ) {
54 //qDebug("*%s* ", line.latin1() ); 55 //qDebug("*%s* ", line.latin1() );
55 if ( line.left(7 ) == "[gammu]" ) { 56 if ( line.left(7 ) == "[gammu]" ) {
56 ; 57 ;
57 } else 58 } else
58 if ( line.left(4 ) == "port" ) { 59 if ( line.left(4 ) == "port" ) {
59 if ( line == "port = " + device+"\n" ) { 60 if ( line == "port = " + device+"\n" ) {
60 content += line ; 61 content += line ;
61 addPort = false; 62 addPort = false;
62 //qDebug("port found" ); 63 //qDebug("port found" );
63 } 64 }
64 65
65 } else if ( line.left(5 ) == "model" ) { 66 } else if ( line.left(5 ) == "model" ) {
66 if ( line == "model = " + model +"\n") { 67 if ( line == "model = " + model +"\n") {
67 content += line ; 68 content += line ;
68 addModel = false; 69 addModel = false;
69 //qDebug("model found" ); 70 //qDebug("model found" );
70 } 71 }
71 72
72 } else if ( line.left( 10 ) == "connection" ) { 73 } else if ( line.left( 10 ) == "connection" ) {
73 if ( line == "connection = " + connection +"\n") { 74 if ( line == "connection = " + connection +"\n") {
74 addConnection = false; 75 addConnection = false;
75 content += line ; 76 content += line ;
76 //qDebug("con found" ); 77 //qDebug("con found" );
77 } 78 }
78 79
79 } else { 80 } else {
80 content += line ; 81 content += line ;
81 } 82 }
82 } 83 }
83 file.close(); 84 file.close();
84 } else { 85 } else {
85 if ( ! connection.isEmpty() ) { 86 if ( ! connection.isEmpty() ) {
86 addConnection = true; 87 addConnection = true;
87 } 88 }
88 if ( ! device.isEmpty() ) { 89 if ( ! device.isEmpty() ) {
89 addPort = true; 90 addPort = true;
90 91
91 } 92 }
92 if ( ! model.isEmpty() ) { 93 if ( ! model.isEmpty() ) {
93 addModel = true; 94 addModel = true;
94 } 95 }
95 } 96 }
96 97
97 if ( addConnection ) { 98 if ( addConnection ) {
98 write = true; 99 write = true;
99 content += "connection = "; 100 content += "connection = ";
100 content += connection; 101 content += connection;
101 content += "\n"; 102 content += "\n";
102 } 103 }
103 if ( addPort ) { 104 if ( addPort ) {
104 write = true; 105 write = true;
105 content += "port = "; 106 content += "port = ";
106 content += device; 107 content += device;
107 content += "\n"; 108 content += "\n";
108 109
109 } 110 }
110 if ( addModel ) { 111 if ( addModel ) {
111 write = true; 112 write = true;
112 content += "model = "; 113 content += "model = ";
113 content += model; 114 content += model;
114 content += "\n"; 115 content += "\n";
115 } 116 }
116 if ( write ) { 117 if ( write ) {
117 if (!file.open( IO_WriteOnly ) ) { 118 if (!file.open( IO_WriteOnly ) ) {
118 qDebug("Error: cannot write file %s ", fileName.latin1() ); 119 qDebug("Error: cannot write file %s ", fileName.latin1() );
119 return; 120 return;
120 } 121 }
121 qDebug("Writing file %s ", fileName.latin1() ); 122 qDebug("Writing file %s ", fileName.latin1() );
122 QTextStream ts( &file ); 123 QTextStream ts( &file );
123 ts << content ; 124 ts << content ;
124 file.close(); 125 file.close();
125 } 126 }
126 127
127} 128}
128 129
129 130
130bool PhoneAccess::writeToPhone( QString fileName) 131bool PhoneAccess::writeToPhone( QString fileName)
131{ 132{
132 133
133#ifdef DESKTOP_VERSION 134#ifdef DESKTOP_VERSION
134#ifdef _WIN32_ 135#ifdef _WIN32_
135 QString command ="kammu --restore " + fileName ; 136 QString command ="kammu --restore " + fileName ;
136#else 137#else
137 QString command ="./kammu --restore " + fileName ; 138 QString command ="./kammu --restore " + fileName ;
138#endif 139#endif
139#else 140#else
140 QString command ="kammu --restore " + fileName ; 141 QString command ="kammu --restore " + fileName ;
141#endif 142#endif
142 int ret; 143 int ret = 1;
143 while ( (ret = system ( command.latin1())) != 0 ) { 144 while ( ret != 0 ) {
144 qDebug("Error S::command returned %d.", ret); 145 QLabel* status = new QLabel( i18n(" This may take 1-3 minutes!"), 0 );
145 int retval = KMessageBox::warningContinueCancel(0, 146 int w = 235;
146 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel")); 147 int h = status->sizeHint().height()+20 ;
147 if ( retval != KMessageBox::Continue ) 148 int dw = QApplication::desktop()->width();
148 return false; 149 int dh = QApplication::desktop()->height();
150 if ( dw > 310 )
151 w = 310;
152 status->setCaption(i18n("Writing to phone...") );
153 status->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
154 status->show();
155 status->raise();
156 status->update();
157 qApp->processEvents();
158 status->update();
159 qApp->processEvents();
160 ret = system ( command.latin1());
161 delete status;
162 qApp->processEvents();
163 if ( ret ) {
164 qDebug("Error S::command returned %d.", ret);
165 int retval = KMessageBox::warningContinueCancel(0,
166 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel"));
167 if ( retval != KMessageBox::Continue )
168 return false;
169 }
149 } 170 }
150 return true; 171 return true;
151} 172}
152bool PhoneAccess::readFromPhone( QString fileName) 173bool PhoneAccess::readFromPhone( QString fileName)
153{ 174{
154 175
155#ifdef DESKTOP_VERSION 176#ifdef DESKTOP_VERSION
156#ifdef _WIN32_ 177#ifdef _WIN32_
157 QString command ="kammu --backup " + fileName + " -yes" ; 178 QString command ="kammu --backup " + fileName + " -yes" ;
158#else 179#else
159 QString command ="./kammu --backup " + fileName + " -yes" ; 180 QString command ="./kammu --backup " + fileName + " -yes" ;
160#endif 181#endif
161#else 182#else
162 QString command ="kammu --backup " + fileName + " -yes" ; 183 QString command ="kammu --backup " + fileName + " -yes" ;
163#endif 184#endif
164 int ret; 185 int ret;
165 while ( (ret = system ( command.latin1())) != 0 ) { 186 while ( ret != 0 ) {
166 qDebug("Error reading from phone:Command returned %d", ret); 187 QLabel* status = new QLabel( i18n(" This may take 1-3 minutes!"), 0 );
167 int retval = KMessageBox::warningContinueCancel(0, 188 int w = 235;
168 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel")); 189 int h = status->sizeHint().height()+20 ;
169 if ( retval != KMessageBox::Continue ) 190 int dw = QApplication::desktop()->width();
170 return false; 191 int dh = QApplication::desktop()->height();
192 if ( dw > 310 )
193 w = 310;
194 status->setCaption(i18n("Reading from phone...") );
195 status->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
196 status->show();
197 status->raise();
198 status->update();
199 qApp->processEvents();
200 status->update();
201 qApp->processEvents();
202 ret = system ( command.latin1() );
203 delete status;
204 qApp->processEvents();
205 if ( ret ) {
206 qDebug("Error reading from phone:Command returned %d", ret);
207 int retval = KMessageBox::warningContinueCancel(0,
208 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel"));
209 if ( retval != KMessageBox::Continue )
210 return false;
211
212 }
171 } 213 }
214 qApp->processEvents();
172 return true; 215 return true;
173} 216}