-rw-r--r-- | kaddressbook/kabcore.cpp | 143 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 2 |
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 @@ -31,12 +31,16 @@ $Id$ #include "kabcore.h" #include <stdaddressbook.h> #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 #include <qclipboard.h> #include <qdir.h> #include <qfile.h> @@ -150,12 +154,56 @@ $Id$ #include <unistd.h> #endif // sync includes #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; #ifdef KAB_EMBEDDED KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), @@ -507,12 +555,13 @@ void KABCore::setContactSelected( const QString &uid ) //if (mActionBeam) //mActionBeam->setEnabled( selected ); if (mActionBeamVCard) mActionBeamVCard->setEnabled( selected ); + mActionExport2phone->setEnabled( selected ); mActionWhoAmI->setEnabled( selected ); mActionCategories->setEnabled( selected ); } void KABCore::sendMail() { @@ -606,12 +655,101 @@ void KABCore::beamMySelf() 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(); + +#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(); if ( !uids.isEmpty() ) beamVCard( uids ); } @@ -1601,12 +1739,16 @@ void KABCore::initActions() SLOT( newContact() ), actionCollection(), "file_new_contact" ); mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, 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; #ifndef DESKTOP_VERSION if ( Ir::supported() ) { mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, @@ -1901,12 +2043,13 @@ void KABCore::addActionsManually() //US topLayout->addWidget( mJumpButtonBar ); this->layout()->add( mJumpButtonBar ); */ #endif //KAB_EMBEDDED + mActionExport2phone->plug( ExportMenu ); connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); syncManager->fillSyncMenu(); } void KABCore::showLicence() { diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 941458d..e6f286b 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h @@ -171,12 +171,13 @@ class KABCore : public QWidget, public KSyncInterface /** Beams the "WhoAmI contact. */ void beamMySelf(); void beamVCard(); + void export2phone(); void beamVCard(const QStringList& uids); void beamDone( Ir *ir ); /** Starts the preferred web browser with the given URL as argument. @@ -394,12 +395,13 @@ class KABCore : public QWidget, public KSyncInterface bool mMultipleViewsAtOnce; //US file menu KAction *mActionMail; KAction *mActionBeam; + KAction *mActionExport2phone; KAction* mActionPrint; KAction* mActionNewContact; KAction *mActionSave; KAction *mActionEditAddressee; KAction *mActionMailVCard; KAction *mActionBeamVCard; |