summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-06 19:41:10 (UTC)
committer zautrix <zautrix>2004-10-06 19:41:10 (UTC)
commitbe3a5ea82c9a160eeeaad187a357c9a085fdb20a (patch) (side-by-side diff)
tree933c685c84430f5c19a0657239b5c8b50a88de05
parent656636acfb8c607901c97c4f55129e29e1df9913 (diff)
downloadkdepimpi-be3a5ea82c9a160eeeaad187a357c9a085fdb20a.zip
kdepimpi-be3a5ea82c9a160eeeaad187a357c9a085fdb20a.tar.gz
kdepimpi-be3a5ea82c9a160eeeaad187a357c9a085fdb20a.tar.bz2
bugfixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--gammu/emb/common/gsmstate.h2
-rw-r--r--kaddressbook/kabcore.cpp6
-rw-r--r--libkdepim/phoneaccess.cpp12
3 files changed, 10 insertions, 10 deletions
diff --git a/gammu/emb/common/gsmstate.h b/gammu/emb/common/gsmstate.h
index 2b4806c..f15a6a7 100644
--- a/gammu/emb/common/gsmstate.h
+++ b/gammu/emb/common/gsmstate.h
@@ -68,193 +68,192 @@ typedef struct _GSM_Reply_Function GSM_Reply_Function;
#ifndef GSM_USED_FBUS2IRDA
# undef GSM_ENABLE_FBUS2IRDA
#endif
#ifndef GSM_USED_PHONETBLUE
# undef GSM_ENABLE_PHONETBLUE
#endif
#ifndef GSM_USED_AT
# undef GSM_ENABLE_AT
#endif
#ifndef GSM_USED_IRDAOBEX
# undef GSM_ENABLE_IRDAOBEX
#endif
#ifndef GSM_USED_BLUEOBEX
# undef GSM_ENABLE_BLUEOBEX
#endif
#ifndef GSM_USED_ALCABUS
# undef GSM_ENABLE_ALCABUS
#endif
#ifndef GSM_USED_IRDAPHONET
# undef GSM_ENABLE_IRDAPHONET
#endif
#ifndef GSM_USED_BLUEFBUS2
# undef GSM_ENABLE_BLUEFBUS2
#endif
#ifndef GSM_USED_BLUEPHONET
# undef GSM_ENABLE_BLUEPHONET
#endif
#ifndef GSM_USED_BLUEAT
# undef GSM_ENABLE_BLUEAT
#endif
#ifndef GSM_USED_IRDAAT
# undef GSM_ENABLE_IRDAAT
#endif
#ifndef GSM_USED_MROUTERBLUE
# undef GSM_ENABLE_MROUTERBLUE
#endif
#if defined(GSM_ENABLE_NOKIA3320) || defined(GSM_ENABLE_NOKIA650) || defined(GSM_ENABLE_NOKIA6110) || defined(GSM_ENABLE_NOKIA7110) || defined(GSM_ENABLE_NOKIA9210)
# define GSM_ENABLE_NOKIA_DCT3
#endif
#if defined(GSM_ENABLE_NOKIA3650) || defined(GSM_ENABLE_NOKIA6510)
# define GSM_ENABLE_NOKIA_DCT4
#endif
#include "protocol/protocol.h"
#if defined(GSM_ENABLE_FBUS2) || defined(GSM_ENABLE_FBUS2IRDA) || defined(GSM_ENABLE_FBUS2DLR3) || defined(GSM_ENABLE_FBUS2BLUE) || defined(GSM_ENABLE_BLUEFBUS2) || defined(GSM_ENABLE_FBUS2DKU5) || defined(GSM_ENABLE_FBUS2PL2303)
# include "protocol/nokia/fbus2.h"
#endif
#ifdef GSM_ENABLE_MBUS2
# include "protocol/nokia/mbus2.h"
#endif
#if defined(GSM_ENABLE_PHONETBLUE) || defined(GSM_ENABLE_IRDAPHONET) || defined(GSM_ENABLE_BLUEPHONET)
# include "protocol/nokia/phonet.h"
#endif
#if defined(GSM_ENABLE_AT) || defined(GSM_ENABLE_BLUEAT) || defined(GSM_ENABLE_IRDAAT)
# include "protocol/at/at.h"
#endif
#ifdef GSM_ENABLE_ALCABUS
# include "protocol/alcatel/alcabus.h"
#endif
#if defined(GSM_ENABLE_IRDAOBEX) || defined(GSM_ENABLE_BLUEOBEX)
# include "protocol/obex/obex.h"
#endif
#if defined(GSM_ENABLE_MROUTERBLUE)
# include "protocol/symbian/mrouter.h"
#endif
#define GSM_ENABLE_SERIALDEVICE
#ifndef GSM_USED_SERIALDEVICE
# undef GSM_ENABLE_SERIALDEVICE
#endif
#define GSM_ENABLE_IRDADEVICE
#ifndef GSM_USED_IRDADEVICE
# undef GSM_ENABLE_IRDADEVICE
#endif
#define GSM_ENABLE_BLUETOOTHDEVICE
#ifndef GSM_USED_BLUETOOTHDEVICE
# undef GSM_ENABLE_BLUETOOTHDEVICE
#endif
#ifdef DJGPP
# undef GSM_ENABLE_IRDADEVICE
# undef GSM_ENABLE_IRDAPHONET
# undef GSM_ENABLE_IRDAOBEX
# undef GSM_ENABLE_IRDAAT
# undef GSM_ENABLE_FBUS2IRDA
# undef GSM_ENABLE_BLUETOOTHDEVICE
# undef GSM_ENABLE_BLUEPHONET
# undef GSM_ENABLE_BLUEOBEX
# undef GSM_ENABLE_BLUEAT
# undef GSM_ENABLE_BLUEFBUS2
# undef GSM_ENABLE_PHONETBLUE
# undef GSM_ENABLE_FBUS2BLUE
# undef GSM_ENABLE_MROUTERBLUE
#endif
-
#ifndef WIN32
# ifdef ENABLE_LGPL
# undef GSM_ENABLE_IRDADEVICE
# undef GSM_ENABLE_IRDAPHONET
# undef GSM_ENABLE_IRDAOBEX
# undef GSM_ENABLE_IRDAAT
# undef GSM_ENABLE_FBUS2IRDA
# undef GSM_ENABLE_BLUETOOTHDEVICE
# undef GSM_ENABLE_BLUEPHONET
# undef GSM_ENABLE_BLUEOBEX
# undef GSM_ENABLE_BLUEAT
# undef GSM_ENABLE_BLUEFBUS2
# undef GSM_ENABLE_PHONETBLUE
# undef GSM_ENABLE_FBUS2BLUE
# undef GSM_ENABLE_MROUTERBLUE
# endif
#endif
#ifdef GSM_ENABLE_SERIALDEVICE
# include "device/serial/ser_w32.h"
# include "device/serial/ser_unx.h"
# include "device/serial/ser_djg.h"
#endif
#ifdef GSM_ENABLE_IRDADEVICE
# include "device/irda/irda.h"
#endif
#ifdef GSM_ENABLE_BLUETOOTHDEVICE
# include "device/bluetoth/bluetoth.h"
#endif
#include "service/gsmpbk.h"
#include "service/gsmnet.h"
#include "service/gsmring.h"
#include "service/gsmcal.h"
#include "service/gsmdata.h"
#include "service/gsmlogo.h"
#include "service/gsmmisc.h"
#include "service/gsmprof.h"
#include "service/gsmcall.h"
#include "service/sms/gsmsms.h"
#include "service/sms/gsmems.h"
#include "service/sms/gsmmulti.h"
#include "service/backup/gsmback.h"
/* ------------------------- Device layer ---------------------------------- */
/**
* Device functions, each device has to provide these.
*/
typedef struct {
/**
* Opens device.
*/
GSM_Error (*OpenDevice) (GSM_StateMachine *s);
/**
* Closes device.
*/
GSM_Error (*CloseDevice) (GSM_StateMachine *s);
/**
* Sets parity for device.
*/
GSM_Error (*DeviceSetParity) (GSM_StateMachine *s, bool parity);
/**
* Sets dtr (data to read) and rts (ready to send) flags.
*/
GSM_Error (*DeviceSetDtrRts) (GSM_StateMachine *s, bool dtr, bool rts);
/**
* Sets device speed.
*/
GSM_Error (*DeviceSetSpeed) (GSM_StateMachine *s, int speed);
/**
* Attempts to read nbytes from device.
*/
int (*ReadDevice) (GSM_StateMachine *s, void *buf, size_t nbytes);
/**
* Attempts to read nbytes from device.
*/
int (*WriteDevice) (GSM_StateMachine *s, void *buf, size_t nbytes);
} GSM_Device_Functions;
#ifdef GSM_ENABLE_SERIALDEVICE
extern GSM_Device_Functions SerialDevice;
#endif
#ifdef GSM_ENABLE_IRDADEVICE
extern GSM_Device_Functions IrdaDevice;
#endif
#ifdef GSM_ENABLE_BLUETOOTHDEVICE
extern GSM_Device_Functions BlueToothDevice;
#endif
/**
* Structure containing device specific data and pointer to device functions -
* @ref GSM_Device_Functions. The data are in a union, so you can use only
* one device at one time.
@@ -1484,96 +1483,97 @@ GSM_Error GSM_WaitFor (GSM_StateMachine *s, unsigned char *buffer,
GSM_Error GSM_DispatchMessage (GSM_StateMachine *s);
INI_Section *GSM_FindGammuRC(void);
bool GSM_ReadConfig (INI_Section *cfg_info, GSM_Config *cfg, int num);
void GSM_DumpMessageLevel2 (GSM_StateMachine *s, unsigned char *message, int messagesize, int type);
void GSM_DumpMessageLevel3 (GSM_StateMachine *s, unsigned char *message, int messagesize, int type);
/* ---------------------- Phone features ----------------------------------- */
typedef enum {
/* n6110.c */
F_CAL33 = 1, /* Calendar,3310 style - 10 reminders, Unicode, 3 coding types */
F_CAL52, /* Calendar,5210 style - full Unicode, etc. */
F_CAL82, /* Calendar,8250 style - "normal", but with Unicode */
F_RING_SM, /* Ringtones returned in SM format - 33xx */
F_NORING, /* No ringtones */
F_NOPBKUNICODE, /* No phonebook in Unicode */
F_NOWAP, /* No WAP */
F_NOCALLER, /* No caller groups */
F_NOPICTURE, /* No Picture Images */
F_NOPICTUREUNI, /* No Picture Images text in Unicode */
F_NOSTARTUP, /* No startup logo */
F_NOCALENDAR, /* No calendar */
F_NOSTARTANI, /* Startup logo is not animated */
F_POWER_BATT, /* Network and battery level get from netmonitor */
F_PROFILES33, /* Phone profiles in 3310 style */
F_PROFILES51, /* Phone profiles in 5110 style */
F_MAGICBYTES, /* Phone can make authentication with magic bytes */
F_NODTMF, /* Phone can't send DTMF */
F_DISPSTATUS, /* Phone return display status */
F_NOCALLINFO,
/* n3320.c */
F_DAYMONTH, /* Day and month reversed in pbk, when compare to GSM models */
/* n6510.c */
F_PBK35, /* Phonebook in 3510 style with ringtones ID */
F_PBKIMG, /* Phonebook in 7250 style with picture ID */
F_PBKTONEGAL, /* Phonebook with selecting ringtones from gallery */
F_PBKSMSLIST, /* Phonebook with SMS list */
F_PBKUSER, /* Phonebook with user ID */
F_RADIO, /* Phone with FM radio */
F_TODO63, /* ToDo in 6310 style - 0x55 msg type */
F_TODO66, /* ToDo in 6610 style - like calendar, with date and other */
F_NOMIDI, /* No ringtones in MIDI */
F_BLUETOOTH, /* Bluetooth support */
F_NOFILESYSTEM, /* No images, ringtones, java saved in special filesystem */
F_NOMMS, /* No MMS sets in phone */
F_NOGPRSPOINT, /* GPRS point are not useable */
F_CAL35, /* Calendar,3510 style - Reminder,Call,Birthday */
F_CAL65, /* Calendar,6510 style - CBMM, method 3 */
F_WAPMMSPROXY, /* WAP & MMS settings contains first & second proxy */
/* n6510.c && n7110.c */
F_VOICETAGS, /* Voice tags available */
F_CAL62, /* Calendar,6210 style - Call,Birthday,Memo,Meeting */
F_NOTES,
/* AT modules */
F_SMSONLYSENT, /* Phone supports only sent/unsent messages */
F_BROKENCPBS, /* CPBS on some memories can hang phone */
F_M20SMS, /* Siemens M20 like SMS handling */
F_SLOWWRITE, /* Use slower writing which some phone need */
F_SMSME900, /* SMS in ME start from location 900 - case of Sagem */
F_ALCATEL /* Phone supports Alcatel protocol */
} Feature;
/* For models table */
struct _OnePhoneModel {
char *model;
char *number;
char *irdamodel;
Feature features[12];
};
bool IsPhoneFeatureAvailable (OnePhoneModel *model, Feature feature);
OnePhoneModel *GetModelData (char *model, char *number, char *irdamodel);
#ifdef __GNUC__
__attribute__((format(printf, 2, 3)))
#endif
int smprintf(GSM_StateMachine *s, const char *format, ...);
void GSM_OSErrorInfo(GSM_StateMachine *s, char *description);
#ifdef GSM_ENABLE_BACKUP
void GSM_GetPhoneFeaturesForBackup(GSM_StateMachine *s, GSM_Backup_Info *info);
#endif
#endif
/* How should editor hadle tabs in this file? Add editor commands here.
* vim: noexpandtab sw=8 ts=8 sts=8:
*/
+
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 7bec90a..b014cba 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1,133 +1,134 @@
/*
This file is part of KAddressbook.
Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, permission is given to link this program
with any edition of Qt, and distribute the resulting executable,
without including the source code for Qt in the source distribution.
*/
/*s
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk
$Id$
*/
#include "kabcore.h"
#include <stdaddressbook.h>
#include <klocale.h>
#include <kfiledialog.h>
#include <qtimer.h>
#include <qlabel.h>
+#include <qregexp.h>
#include <qlineedit.h>
#include <qcheckbox.h>
#include <qpushbutton.h>
#include <qprogressbar.h>
#include <libkdepim/phoneaccess.h>
#ifndef KAB_EMBEDDED
#include <qclipboard.h>
#include <qdir.h>
#include <qfile.h>
#include <qapplicaton.h>
#include <qprogressbar.h>
#include <qlayout.h>
#include <qregexp.h>
#include <qvbox.h>
#include <kabc/addresseelist.h>
#include <kabc/errorhandler.h>
#include <kabc/resource.h>
#include <kabc/vcardconverter.h>
#include <kapplication.h>
#include <kactionclasses.h>
#include <kcmultidialog.h>
#include <kdebug.h>
#include <kdeversion.h>
#include <kkeydialog.h>
#include <kmessagebox.h>
#include <kprinter.h>
#include <kprotocolinfo.h>
#include <kresources/selectdialog.h>
#include <kstandarddirs.h>
#include <ktempfile.h>
#include <kxmlguiclient.h>
#include <kaboutdata.h>
#include <libkdepim/categoryselectdialog.h>
#include "addresseeutil.h"
#include "addresseeeditordialog.h"
#include "extensionmanager.h"
#include "kstdaction.h"
#include "kaddressbookservice.h"
#include "ldapsearchdialog.h"
#include "printing/printingwizard.h"
#else // KAB_EMBEDDED
#include <kapplication.h>
#include "KDGanttMinimizeSplitter.h"
#include "kaddressbookmain.h"
#include "kactioncollection.h"
#include "addresseedialog.h"
//US
#include <addresseeview.h>
#include <qapp.h>
#include <qmenubar.h>
//#include <qtoolbar.h>
#include <qmessagebox.h>
#include <kdebug.h>
#include <kiconloader.h> // needed for SmallIcon
#include <kresources/kcmkresources.h>
#include <ktoolbar.h>
//#include <qlabel.h>
#ifndef DESKTOP_VERSION
#include <qpe/ir.h>
#include <qpe/qpemenubar.h>
#include <qtopia/qcopenvelope_qws.h>
#else
#include <qmenubar.h>
#endif
#endif // KAB_EMBEDDED
#include "kcmconfigs/kcmkabconfig.h"
#include "kcmconfigs/kcmkdepimconfig.h"
#include "kpimglobalprefs.h"
#include "externalapphandler.h"
#include <kresources/selectdialog.h>
#include <kmessagebox.h>
#include <picture.h>
#include <resource.h>
//US#include <qsplitter.h>
#include <qmap.h>
#include <qdir.h>
#include <qfile.h>
#include <qvbox.h>
#include <qlayout.h>
#include <qclipboard.h>
#include <qtextstream.h>
@@ -633,192 +634,197 @@ void KABCore::mailVCard( const QStringList& uids )
/*US
kapp->invokeMailer( QString::null, QString::null, QString::null,
QString::null, // subject
QString::null, // body
QString::null,
urls ); // attachments
*/
}
/**
Beams the "WhoAmI contact.
*/
void KABCore::beamMySelf()
{
KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI();
if (!a.isEmpty())
{
QStringList uids;
uids << a.uid();
beamVCard(uids);
} else {
KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) );
}
}
void KABCore::export2phone()
{
KAex2phonePrefs ex2phone;
ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection );
ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice );
ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel );
if ( !ex2phone.exec() ) {
return;
}
KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text();
KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text();
KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text();
PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice,
KPimGlobalPrefs::instance()->mEx2PhoneConnection,
KPimGlobalPrefs::instance()->mEx2PhoneModel );
QStringList uids = mViewManager->selectedUids();
if ( uids.isEmpty() )
return;
#ifdef _WIN32_
QString fileName = locateLocal("tmp", "tempfile.vcf");
#else
QString fileName = "/tmp/kdepimtemp.vcf";
#endif
KABC::VCardConverter converter;
QString description;
QString datastream;
for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
KABC::Addressee a = mAddressBook->findByUid( *it );
if ( a.isEmpty() )
continue;
if (description.isEmpty())
description = a.formattedName();
QString vcard;
converter.addresseeToVCard( a, vcard );
int start = 0;
int next;
while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
int semi = vcard.find(";", next);
int dopp = vcard.find(":", next);
int sep;
if ( semi < dopp && semi >= 0 )
sep = semi ;
else
sep = dopp;
datastream +=vcard.mid( start, next - start);
datastream +=vcard.mid( next+5,sep -next -5 ).upper();
start = sep;
}
datastream += vcard.mid( start,vcard.length() );
}
QFile outFile(fileName);
if ( outFile.open(IO_WriteOnly) ) {
datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
QTextStream t( &outFile ); // use a text stream
t.setEncoding( QTextStream::UnicodeUTF8 );
t <<datastream;
outFile.close();
+ if ( PhoneAccess::writeToPhone( fileName ) )
+ qDebug("Export okay ");
+ else
+ qDebug("Error export contacts ");
+
} else {
qDebug("Error open temp file ");
return;
}
#if 0
setCaption( i18n("Writing to phone..."));
if ( PhoneFormat::writeToPhone( cal ) )
setCaption( i18n("Export to phone successful!"));
else
setCaption( i18n("Error exporting to phone!"));
#endif
}
void KABCore::beamVCard()
{
QStringList uids = mViewManager->selectedUids();
if ( !uids.isEmpty() )
beamVCard( uids );
}
void KABCore::beamVCard(const QStringList& uids)
{
/*US
QString beamFilename;
Opie::OPimContact c;
if ( actionPersonal->isOn() ) {
beamFilename = addressbookPersonalVCardName();
if ( !QFile::exists( beamFilename ) )
return; // can't beam a non-existent file
Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
beamFilename );
Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
Opie::OPimContactAccess::List allList = access->allRecords();
Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first
c = *it;
delete access;
} else {
unlink( beamfile ); // delete if exists
mkdir("/tmp/obex/", 0755);
c = m_abView -> currentEntry();
Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
beamfile );
Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
access->add( c );
access->save();
delete access;
beamFilename = beamfile;
}
owarn << "Beaming: " << beamFilename << oendl;
*/
#if 0
QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
QString dirName = tmpdir + "/" + KApplication::randomString( 8 );
QString name = "contact.vcf";
QString fileName = dirName + "/" + name;
#endif
// LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory
//
QString fileName = "/tmp/kapibeamfile.vcf";
//QDir().mkdir( dirName, true );
KABC::VCardConverter converter;
QString description;
QString datastream;
for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
KABC::Addressee a = mAddressBook->findByUid( *it );
if ( a.isEmpty() )
continue;
if (description.isEmpty())
description = a.formattedName();
QString vcard;
converter.addresseeToVCard( a, vcard );
int start = 0;
int next;
while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
int semi = vcard.find(";", next);
int dopp = vcard.find(":", next);
int sep;
diff --git a/libkdepim/phoneaccess.cpp b/libkdepim/phoneaccess.cpp
index c0bd6cc..357cd39 100644
--- a/libkdepim/phoneaccess.cpp
+++ b/libkdepim/phoneaccess.cpp
@@ -1,153 +1,147 @@
/*
This file is part of libkdepim.
Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <qstring.h>
#include <qapplication.h>
#include <qptrlist.h>
#include <qregexp.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qtextcodec.h>
#include <qdir.h>
#include <kmessagebox.h>
#include <stdlib.h>
#include "phoneaccess.h"
void PhoneAccess::writeConfig( QString device, QString connection, QString model )
{
#ifdef _WIN32_
QString fileName = qApp->applicationDirPath () +"\\gammurc";
#else
QString fileName = QDir::homeDirPath() +"/.gammurc";
#endif
//qDebug("save %d ", load );
- QString content;
+ QString content = "[gammu]\n";;
bool write = false;
bool addPort = true, addConnection = true, addModel = true;
QFile file( fileName );
if ( QFile::exists( fileName) ) {
if (!file.open( IO_ReadOnly ) ) {
qDebug("Error: cannot open %s ", fileName.latin1() );
return;
}
QString line;
while ( file.readLine( line, 1024 ) > 0 ) {
//qDebug("*%s* ", line.latin1() );
if ( line.left(7 ) == "[gammu]" ) {
- ;
+ ;
} else
if ( line.left(4 ) == "port" ) {
if ( line == "port = " + device+"\n" ) {
content += line ;
addPort = false;
//qDebug("port found" );
}
} else if ( line.left(5 ) == "model" ) {
if ( line == "model = " + model +"\n") {
content += line ;
addModel = false;
//qDebug("model found" );
}
} else if ( line.left( 10 ) == "connection" ) {
if ( line == "connection = " + connection +"\n") {
addConnection = false;
content += line ;
//qDebug("con found" );
}
} else {
content += line ;
}
}
file.close();
} else {
if ( ! connection.isEmpty() ) {
addConnection = true;
}
if ( ! device.isEmpty() ) {
addPort = true;
}
if ( ! model.isEmpty() ) {
addModel = true;
}
}
-
+
if ( addConnection ) {
- if ( ! write )
- content += "[gammu]\n";
write = true;
content += "connection = ";
content += connection;
content += "\n";
}
if ( addPort ) {
- if ( ! write )
- content += "[gammu]\n";
write = true;
content += "port = ";
content += device;
content += "\n";
}
if ( addModel ) {
- if ( ! write )
- content += "[gammu]\n";
write = true;
content += "model = ";
content += model;
content += "\n";
}
if ( write ) {
if (!file.open( IO_WriteOnly ) ) {
qDebug("Error: cannot write file %s ", fileName.latin1() );
return;
}
qDebug("Writing file %s ", fileName.latin1() );
QTextStream ts( &file );
ts << content ;
file.close();
}
}
bool PhoneAccess::writeToPhone( QString fileName)
{
#ifdef DESKTOP_VERSION
QString command ="./kammu --restore " + fileName ;
#else
QString command ="kammu --restore " + fileName ;
#endif
int ret;
while ( (ret = system ( command.latin1())) != 0 ) {
qDebug("Error S::command returned %d. asking users", ret);
int retval = KMessageBox::warningContinueCancel(0,
i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone access"),i18n("Retry"),i18n("Cancel"));
if ( retval != KMessageBox::Continue )
return false;
}
return true;
}