summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-06 16:02:56 (UTC)
committer zautrix <zautrix>2004-10-06 16:02:56 (UTC)
commita22de800110d8350a5200a994b041e47d51bf4c6 (patch) (side-by-side diff)
treea4de195003d1ceabc3fd9ca4e5cd0510570bcb97
parentef71411c2f248d1dc908aa2f119c9b281e0e8bb9 (diff)
downloadkdepimpi-a22de800110d8350a5200a994b041e47d51bf4c6.zip
kdepimpi-a22de800110d8350a5200a994b041e47d51bf4c6.tar.gz
kdepimpi-a22de800110d8350a5200a994b041e47d51bf4c6.tar.bz2
added phone export
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp143
-rw-r--r--kaddressbook/kabcore.h2
-rw-r--r--korganizer/koprefs.cpp4
-rw-r--r--korganizer/koprefs.h3
-rw-r--r--korganizer/mainwindow.cpp25
-rw-r--r--libkdepim/kpimglobalprefs.cpp7
-rw-r--r--libkdepim/kpimglobalprefs.h3
-rw-r--r--libkdepim/libkdepim.pro6
-rw-r--r--libkdepim/libkdepimE.pro6
-rw-r--r--libkdepim/phoneaccess.cpp153
-rw-r--r--libkdepim/phoneaccess.h42
11 files changed, 371 insertions, 23 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index f8359de..185cf46 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -34,6 +34,10 @@ $Id$
#include <klocale.h>
#include <kfiledialog.h>
#include <qtimer.h>
+#include <qlabel.h>
+#include <qlineedit.h>
+#include <qcheckbox.h>
+#include <qpushbutton.h>
#include <qprogressbar.h>
#ifndef KAB_EMBEDDED
@@ -153,6 +157,50 @@ $Id$
#include <libkdepim/ksyncprofile.h>
#include <libkdepim/ksyncprefsdialog.h>
+class KAex2phonePrefs : public QDialog
+{
+ public:
+ KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) :
+ QDialog( parent, name, true )
+ {
+ setCaption( i18n("Export to phone options") );
+ QVBoxLayout* lay = new QVBoxLayout( this );
+ lay->setSpacing( 3 );
+ lay->setMargin( 3 );
+ QLabel *lab;
+ lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) );
+ lab->setAlignment (AlignHCenter );
+ QHBox* temphb;
+ temphb = new QHBox( this );
+ new QLabel( i18n("I/O device: "), temphb );
+ mPhoneDevice = new QLineEdit( temphb);
+ lay->addWidget( temphb );
+ temphb = new QHBox( this );
+ new QLabel( i18n("Connection: "), temphb );
+ mPhoneConnection = new QLineEdit( temphb);
+ lay->addWidget( temphb );
+ temphb = new QHBox( this );
+ new QLabel( i18n("Model(opt.): "), temphb );
+ mPhoneModel = new QLineEdit( temphb);
+ lay->addWidget( temphb );
+ mWriteToSim= new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this );
+ lay->addWidget( mWriteToSim );
+ lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) );
+ lab->setAlignment (AlignHCenter );
+ QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this );
+ lay->addWidget( ok );
+ QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
+ lay->addWidget( cancel );
+ connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
+ connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
+ resize( 220, 240 );
+
+ }
+
+public:
+ QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel;
+ QCheckBox* mWriteToSim;
+};
bool pasteWithNewUid = true;
@@ -510,6 +558,7 @@ void KABCore::setContactSelected( const QString &uid )
if (mActionBeamVCard)
mActionBeamVCard->setEnabled( selected );
+ mActionExport2phone->setEnabled( selected );
mActionWhoAmI->setEnabled( selected );
mActionCategories->setEnabled( selected );
}
@@ -609,6 +658,95 @@ void KABCore::beamMySelf()
}
}
+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();
+
+#if 0
+ PhoneFormat::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice,
+ KPimGlobalPrefs::instance()->mEx2PhoneConnection,
+ KPimGlobalPrefs::instance()->mEx2PhoneModel );
+
+
+
+
+
+ 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;
+ 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() );
+ }
+#ifndef DESKTOP_VERSION
+ 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();
+ Ir *ir = new Ir( this );
+ connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) );
+ ir->send( fileName, description, "text/x-vCard" );
+ } else {
+ qDebug("Error open temp beam file ");
+ return;
+ }
+#endif
+
+
+
+
+ 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();
@@ -1604,6 +1742,10 @@ void KABCore::initActions()
this, SLOT( mailVCard() ),
actionCollection(), "file_mail_vcard");
+ mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this,
+ SLOT( export2phone() ), actionCollection(),
+ "kaddressbook_ex2phone" );
+
mActionBeamVCard = 0;
mActionBeam = 0;
@@ -1904,6 +2046,7 @@ void KABCore::addActionsManually()
#endif //KAB_EMBEDDED
+ mActionExport2phone->plug( ExportMenu );
connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) );
syncManager->fillSyncMenu();
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h
index 941458d..e6f286b 100644
--- a/kaddressbook/kabcore.h
+++ b/kaddressbook/kabcore.h
@@ -174,6 +174,7 @@ class KABCore : public QWidget, public KSyncInterface
void beamMySelf();
void beamVCard();
+ void export2phone();
void beamVCard(const QStringList& uids);
void beamDone( Ir *ir );
@@ -397,6 +398,7 @@ class KABCore : public QWidget, public KSyncInterface
//US file menu
KAction *mActionMail;
KAction *mActionBeam;
+ KAction *mActionExport2phone;
KAction* mActionPrint;
KAction* mActionNewContact;
KAction *mActionSave;
diff --git a/korganizer/koprefs.cpp b/korganizer/koprefs.cpp
index 716a125..84e3d00 100644
--- a/korganizer/koprefs.cpp
+++ b/korganizer/koprefs.cpp
@@ -79,10 +79,6 @@ KOPrefs::KOPrefs() :
KPrefs::setCurrentGroup("General");
- addItemString("Ex2PhoneDevice",&mEx2PhoneDevice,"/dev/ircomm");
- addItemString("Ex2PhoneConnection",&mEx2PhoneConnection,"irda");
- addItemString("Ex2PhoneModel",&mEx2PhoneModel,"6310i");
-
addItemBool("Enable Group Scheduling",&mEnableGroupScheduling,false);
addItemBool("ShowIconNewTodo",&mShowIconNewTodo,true);
diff --git a/korganizer/koprefs.h b/korganizer/koprefs.h
index a1ba8b3..d9ac851 100644
--- a/korganizer/koprefs.h
+++ b/korganizer/koprefs.h
@@ -210,9 +210,6 @@ class KOPrefs : public KPimPrefs
QString mPhoneDevice;
QString mPhoneConnection;
QString mPhoneModel;
- QString mEx2PhoneDevice;
- QString mEx2PhoneConnection;
- QString mEx2PhoneModel;
int mLastSyncTime;
int mSyncAlgoPrefs;
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index bd14fbf..2f286e0 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -103,7 +103,7 @@ class KOex2phonePrefs : public QDialog
mWriteBackFutureWeeks= new QSpinBox(1,104, 1, temphb);
mWriteBackFutureWeeks->setValue( 8 );
lay->addWidget( temphb );
- lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\n todo/calendar data on phone!"), this ) );
+ lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ntodo/calendar data on phone!"), this ) );
lab->setAlignment (AlignHCenter );
QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this );
lay->addWidget( ok );
@@ -1171,13 +1171,14 @@ void MainWindow::slotSyncMenu( int action )
}
void MainWindow::exportToPhone( int mode )
{
-
+
//ex2phone->insertItem(i18n("Complete calendar..."), 1 );
//ex2phone->insertItem(i18n("Filtered calendar..."), 2 );
- KOex2phonePrefs ex2phone;
- ex2phone.mPhoneConnection->setText( KOPrefs::instance()->mEx2PhoneConnection );
- ex2phone.mPhoneDevice->setText( KOPrefs::instance()->mEx2PhoneDevice );
- ex2phone.mPhoneModel->setText( KOPrefs::instance()->mEx2PhoneModel );
+ KOex2phonePrefs ex2phone;
+
+ ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection );
+ ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice );
+ ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel );
if ( mode == 1 )
ex2phone.setCaption(i18n("Export complete calendar"));
if ( mode == 2 )
@@ -1186,9 +1187,9 @@ void MainWindow::exportToPhone( int mode )
if ( !ex2phone.exec() ) {
return;
}
- KOPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text();
- KOPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text();
- KOPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text();
+ KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text();
+ KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text();
+ KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text();
int inFuture = 0;
if ( ex2phone.mWriteBackFuture->isChecked() )
@@ -1232,9 +1233,9 @@ void MainWindow::exportToPhone( int mode )
}
incidence = delSel.next();
}
- PhoneFormat::writeConfig( KOPrefs::instance()->mEx2PhoneDevice,
- KOPrefs::instance()->mEx2PhoneConnection,
- KOPrefs::instance()->mEx2PhoneModel );
+ PhoneFormat::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice,
+ KPimGlobalPrefs::instance()->mEx2PhoneConnection,
+ KPimGlobalPrefs::instance()->mEx2PhoneModel );
setCaption( i18n("Writing to phone..."));
if ( PhoneFormat::writeToPhone( cal ) )
diff --git a/libkdepim/kpimglobalprefs.cpp b/libkdepim/kpimglobalprefs.cpp
index b2b7663..b71e18d 100644
--- a/libkdepim/kpimglobalprefs.cpp
+++ b/libkdepim/kpimglobalprefs.cpp
@@ -99,6 +99,13 @@ KPimGlobalPrefs::KPimGlobalPrefs( const QString &name )
addItemString( "SIPChannelMessage", &mSipOtherMessage, "" );
addItemString( "SIPChannelParameters", &mSipOtherMessageParameters, "" );
+
+ KPrefs::setCurrentGroup( "PhoneAccess" );
+ addItemString("Ex2PhoneDevice",&mEx2PhoneDevice,"/dev/ircomm");
+ addItemString("Ex2PhoneConnection",&mEx2PhoneConnection,"irda");
+ addItemString("Ex2PhoneModel",&mEx2PhoneModel,"6310i");
+
+
}
void KPimGlobalPrefs::setGlobalConfig()
diff --git a/libkdepim/kpimglobalprefs.h b/libkdepim/kpimglobalprefs.h
index 84ba689..f6b6628 100644
--- a/libkdepim/kpimglobalprefs.h
+++ b/libkdepim/kpimglobalprefs.h
@@ -129,6 +129,9 @@ class KPimGlobalPrefs : public KPrefs
QString mSipOtherMessage;
QString mSipOtherMessageParameters;
+ QString mEx2PhoneDevice;
+ QString mEx2PhoneConnection;
+ QString mEx2PhoneModel;
};
diff --git a/libkdepim/libkdepim.pro b/libkdepim/libkdepim.pro
index eac19ea..84af7ad 100644
--- a/libkdepim/libkdepim.pro
+++ b/libkdepim/libkdepim.pro
@@ -35,7 +35,8 @@ HEADERS = \
ksyncprofile.h \
ksyncprefsdialog.h \
kcmconfigs/kcmkdepimconfig.h \
- kcmconfigs/kdepimconfigwidget.h
+ kcmconfigs/kdepimconfigwidget.h \
+ phoneaccess.h
SOURCES = \
categoryeditdialog.cpp \
@@ -54,6 +55,7 @@ SOURCES = \
ksyncprofile.cpp \
ksyncprefsdialog.cpp \
kcmconfigs/kcmkdepimconfig.cpp \
- kcmconfigs/kdepimconfigwidget.cpp
+ kcmconfigs/kdepimconfigwidget.cpp \
+ phoneaccess.cpp
diff --git a/libkdepim/libkdepimE.pro b/libkdepim/libkdepimE.pro
index 156e247..f3db68e 100644
--- a/libkdepim/libkdepimE.pro
+++ b/libkdepim/libkdepimE.pro
@@ -29,7 +29,8 @@ HEADERS = \
ksyncprofile.h \
ksyncprefsdialog.h \
kcmconfigs/kcmkdepimconfig.h \
- kcmconfigs/kdepimconfigwidget.h
+ kcmconfigs/kdepimconfigwidget.h \
+ phoneaccess.h
@@ -50,6 +51,7 @@ SOURCES = \
ksyncprofile.cpp \
ksyncprefsdialog.cpp \
kcmconfigs/kcmkdepimconfig.cpp \
- kcmconfigs/kdepimconfigwidget.cpp
+ kcmconfigs/kdepimconfigwidget.cpp \
+ phoneaccess.cpp
diff --git a/libkdepim/phoneaccess.cpp b/libkdepim/phoneaccess.cpp
new file mode 100644
index 0000000..c0bd6cc
--- a/dev/null
+++ b/libkdepim/phoneaccess.cpp
@@ -0,0 +1,153 @@
+/*
+ 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;
+ 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;
+}
diff --git a/libkdepim/phoneaccess.h b/libkdepim/phoneaccess.h
new file mode 100644
index 0000000..b7c4732
--- a/dev/null
+++ b/libkdepim/phoneaccess.h
@@ -0,0 +1,42 @@
+/*
+ This file is part of libkcal.
+
+ Copyright (c) 2003 Cornelius Schumacher <schumacher@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.
+*/
+#ifndef PHONEACCESS_H
+#define PHONEACCESS_H
+
+#include <qstring.h>
+
+
+
+/**
+ This class implements the calendar format used by Phone.
+*/
+
+class PhoneAccess : public QObject {
+ public:
+
+ static void writeConfig( QString device,QString connection, QString model );
+ static bool writeToPhone( QString fileName );
+
+};
+
+
+
+#endif