summaryrefslogtreecommitdiffabout
path: root/kaddressbook
Side-by-side diff
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp143
-rw-r--r--kaddressbook/kabcore.h2
2 files changed, 145 insertions, 0 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;