author | zautrix <zautrix> | 2004-10-06 16:02:56 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-06 16:02:56 (UTC) |
commit | a22de800110d8350a5200a994b041e47d51bf4c6 (patch) (unidiff) | |
tree | a4de195003d1ceabc3fd9ca4e5cd0510570bcb97 /kaddressbook | |
parent | ef71411c2f248d1dc908aa2f119c9b281e0e8bb9 (diff) | |
download | kdepimpi-a22de800110d8350a5200a994b041e47d51bf4c6.zip kdepimpi-a22de800110d8350a5200a994b041e47d51bf4c6.tar.gz kdepimpi-a22de800110d8350a5200a994b041e47d51bf4c6.tar.bz2 |
added phone export
-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$ | |||
31 | #include "kabcore.h" | 31 | #include "kabcore.h" |
32 | 32 | ||
33 | #include <stdaddressbook.h> | 33 | #include <stdaddressbook.h> |
34 | #include <klocale.h> | 34 | #include <klocale.h> |
35 | #include <kfiledialog.h> | 35 | #include <kfiledialog.h> |
36 | #include <qtimer.h> | 36 | #include <qtimer.h> |
37 | #include <qlabel.h> | ||
38 | #include <qlineedit.h> | ||
39 | #include <qcheckbox.h> | ||
40 | #include <qpushbutton.h> | ||
37 | #include <qprogressbar.h> | 41 | #include <qprogressbar.h> |
38 | 42 | ||
39 | #ifndef KAB_EMBEDDED | 43 | #ifndef KAB_EMBEDDED |
40 | #include <qclipboard.h> | 44 | #include <qclipboard.h> |
41 | #include <qdir.h> | 45 | #include <qdir.h> |
42 | #include <qfile.h> | 46 | #include <qfile.h> |
@@ -150,12 +154,56 @@ $Id$ | |||
150 | #include <unistd.h> | 154 | #include <unistd.h> |
151 | #endif | 155 | #endif |
152 | // sync includes | 156 | // sync includes |
153 | #include <libkdepim/ksyncprofile.h> | 157 | #include <libkdepim/ksyncprofile.h> |
154 | #include <libkdepim/ksyncprefsdialog.h> | 158 | #include <libkdepim/ksyncprefsdialog.h> |
155 | 159 | ||
160 | class KAex2phonePrefs : public QDialog | ||
161 | { | ||
162 | public: | ||
163 | KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : | ||
164 | QDialog( parent, name, true ) | ||
165 | { | ||
166 | setCaption( i18n("Export to phone options") ); | ||
167 | QVBoxLayout* lay = new QVBoxLayout( this ); | ||
168 | lay->setSpacing( 3 ); | ||
169 | lay->setMargin( 3 ); | ||
170 | QLabel *lab; | ||
171 | lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); | ||
172 | lab->setAlignment (AlignHCenter ); | ||
173 | QHBox* temphb; | ||
174 | temphb = new QHBox( this ); | ||
175 | new QLabel( i18n("I/O device: "), temphb ); | ||
176 | mPhoneDevice = new QLineEdit( temphb); | ||
177 | lay->addWidget( temphb ); | ||
178 | temphb = new QHBox( this ); | ||
179 | new QLabel( i18n("Connection: "), temphb ); | ||
180 | mPhoneConnection = new QLineEdit( temphb); | ||
181 | lay->addWidget( temphb ); | ||
182 | temphb = new QHBox( this ); | ||
183 | new QLabel( i18n("Model(opt.): "), temphb ); | ||
184 | mPhoneModel = new QLineEdit( temphb); | ||
185 | lay->addWidget( temphb ); | ||
186 | mWriteToSim= new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); | ||
187 | lay->addWidget( mWriteToSim ); | ||
188 | lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) ); | ||
189 | lab->setAlignment (AlignHCenter ); | ||
190 | QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); | ||
191 | lay->addWidget( ok ); | ||
192 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); | ||
193 | lay->addWidget( cancel ); | ||
194 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); | ||
195 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); | ||
196 | resize( 220, 240 ); | ||
197 | |||
198 | } | ||
199 | |||
200 | public: | ||
201 | QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; | ||
202 | QCheckBox* mWriteToSim; | ||
203 | }; | ||
156 | 204 | ||
157 | bool pasteWithNewUid = true; | 205 | bool pasteWithNewUid = true; |
158 | 206 | ||
159 | #ifdef KAB_EMBEDDED | 207 | #ifdef KAB_EMBEDDED |
160 | KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) | 208 | KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) |
161 | : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), | 209 | : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), |
@@ -507,12 +555,13 @@ void KABCore::setContactSelected( const QString &uid ) | |||
507 | //if (mActionBeam) | 555 | //if (mActionBeam) |
508 | //mActionBeam->setEnabled( selected ); | 556 | //mActionBeam->setEnabled( selected ); |
509 | 557 | ||
510 | if (mActionBeamVCard) | 558 | if (mActionBeamVCard) |
511 | mActionBeamVCard->setEnabled( selected ); | 559 | mActionBeamVCard->setEnabled( selected ); |
512 | 560 | ||
561 | mActionExport2phone->setEnabled( selected ); | ||
513 | mActionWhoAmI->setEnabled( selected ); | 562 | mActionWhoAmI->setEnabled( selected ); |
514 | mActionCategories->setEnabled( selected ); | 563 | mActionCategories->setEnabled( selected ); |
515 | } | 564 | } |
516 | 565 | ||
517 | void KABCore::sendMail() | 566 | void KABCore::sendMail() |
518 | { | 567 | { |
@@ -606,12 +655,101 @@ void KABCore::beamMySelf() | |||
606 | KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); | 655 | KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); |
607 | 656 | ||
608 | 657 | ||
609 | } | 658 | } |
610 | } | 659 | } |
611 | 660 | ||
661 | void KABCore::export2phone() | ||
662 | { | ||
663 | |||
664 | KAex2phonePrefs ex2phone; | ||
665 | ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); | ||
666 | ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); | ||
667 | ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); | ||
668 | |||
669 | if ( !ex2phone.exec() ) { | ||
670 | return; | ||
671 | } | ||
672 | KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); | ||
673 | KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); | ||
674 | KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); | ||
675 | |||
676 | #if 0 | ||
677 | PhoneFormat::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, | ||
678 | KPimGlobalPrefs::instance()->mEx2PhoneConnection, | ||
679 | KPimGlobalPrefs::instance()->mEx2PhoneModel ); | ||
680 | |||
681 | |||
682 | |||
683 | |||
684 | |||
685 | QString fileName = "/tmp/kapibeamfile.vcf"; | ||
686 | |||
687 | |||
688 | //QDir().mkdir( dirName, true ); | ||
689 | |||
690 | |||
691 | KABC::VCardConverter converter; | ||
692 | QString description; | ||
693 | QString datastream; | ||
694 | for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | ||
695 | KABC::Addressee a = mAddressBook->findByUid( *it ); | ||
696 | |||
697 | if ( a.isEmpty() ) | ||
698 | continue; | ||
699 | |||
700 | if (description.isEmpty()) | ||
701 | description = a.formattedName(); | ||
702 | |||
703 | QString vcard; | ||
704 | converter.addresseeToVCard( a, vcard ); | ||
705 | int start = 0; | ||
706 | int next; | ||
707 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { | ||
708 | int semi = vcard.find(";", next); | ||
709 | int dopp = vcard.find(":", next); | ||
710 | int sep; | ||
711 | if ( semi < dopp && semi >= 0 ) | ||
712 | sep = semi ; | ||
713 | else | ||
714 | sep = dopp; | ||
715 | datastream +=vcard.mid( start, next - start); | ||
716 | datastream +=vcard.mid( next+5,sep -next -5 ).upper(); | ||
717 | start = sep; | ||
718 | } | ||
719 | datastream += vcard.mid( start,vcard.length() ); | ||
720 | } | ||
721 | #ifndef DESKTOP_VERSION | ||
722 | QFile outFile(fileName); | ||
723 | if ( outFile.open(IO_WriteOnly) ) { | ||
724 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); | ||
725 | QTextStream t( &outFile ); // use a text stream | ||
726 | t.setEncoding( QTextStream::UnicodeUTF8 ); | ||
727 | t <<datastream; | ||
728 | outFile.close(); | ||
729 | Ir *ir = new Ir( this ); | ||
730 | connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); | ||
731 | ir->send( fileName, description, "text/x-vCard" ); | ||
732 | } else { | ||
733 | qDebug("Error open temp beam file "); | ||
734 | return; | ||
735 | } | ||
736 | #endif | ||
737 | |||
738 | |||
739 | |||
740 | |||
741 | setCaption( i18n("Writing to phone...")); | ||
742 | if ( PhoneFormat::writeToPhone( cal ) ) | ||
743 | setCaption( i18n("Export to phone successful!")); | ||
744 | else | ||
745 | setCaption( i18n("Error exporting to phone!")); | ||
746 | #endif | ||
747 | |||
748 | |||
749 | } | ||
612 | void KABCore::beamVCard() | 750 | void KABCore::beamVCard() |
613 | { | 751 | { |
614 | QStringList uids = mViewManager->selectedUids(); | 752 | QStringList uids = mViewManager->selectedUids(); |
615 | if ( !uids.isEmpty() ) | 753 | if ( !uids.isEmpty() ) |
616 | beamVCard( uids ); | 754 | beamVCard( uids ); |
617 | } | 755 | } |
@@ -1601,12 +1739,16 @@ void KABCore::initActions() | |||
1601 | SLOT( newContact() ), actionCollection(), "file_new_contact" ); | 1739 | SLOT( newContact() ), actionCollection(), "file_new_contact" ); |
1602 | 1740 | ||
1603 | mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, | 1741 | mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, |
1604 | this, SLOT( mailVCard() ), | 1742 | this, SLOT( mailVCard() ), |
1605 | actionCollection(), "file_mail_vcard"); | 1743 | actionCollection(), "file_mail_vcard"); |
1606 | 1744 | ||
1745 | mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this, | ||
1746 | SLOT( export2phone() ), actionCollection(), | ||
1747 | "kaddressbook_ex2phone" ); | ||
1748 | |||
1607 | mActionBeamVCard = 0; | 1749 | mActionBeamVCard = 0; |
1608 | mActionBeam = 0; | 1750 | mActionBeam = 0; |
1609 | 1751 | ||
1610 | #ifndef DESKTOP_VERSION | 1752 | #ifndef DESKTOP_VERSION |
1611 | if ( Ir::supported() ) { | 1753 | if ( Ir::supported() ) { |
1612 | mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, | 1754 | mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, |
@@ -1901,12 +2043,13 @@ void KABCore::addActionsManually() | |||
1901 | //US topLayout->addWidget( mJumpButtonBar ); | 2043 | //US topLayout->addWidget( mJumpButtonBar ); |
1902 | this->layout()->add( mJumpButtonBar ); | 2044 | this->layout()->add( mJumpButtonBar ); |
1903 | */ | 2045 | */ |
1904 | 2046 | ||
1905 | #endif //KAB_EMBEDDED | 2047 | #endif //KAB_EMBEDDED |
1906 | 2048 | ||
2049 | mActionExport2phone->plug( ExportMenu ); | ||
1907 | connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); | 2050 | connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); |
1908 | syncManager->fillSyncMenu(); | 2051 | syncManager->fillSyncMenu(); |
1909 | 2052 | ||
1910 | } | 2053 | } |
1911 | void KABCore::showLicence() | 2054 | void KABCore::showLicence() |
1912 | { | 2055 | { |
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 | |||
171 | /** | 171 | /** |
172 | Beams the "WhoAmI contact. | 172 | Beams the "WhoAmI contact. |
173 | */ | 173 | */ |
174 | void beamMySelf(); | 174 | void beamMySelf(); |
175 | 175 | ||
176 | void beamVCard(); | 176 | void beamVCard(); |
177 | void export2phone(); | ||
177 | void beamVCard(const QStringList& uids); | 178 | void beamVCard(const QStringList& uids); |
178 | void beamDone( Ir *ir ); | 179 | void beamDone( Ir *ir ); |
179 | 180 | ||
180 | 181 | ||
181 | /** | 182 | /** |
182 | Starts the preferred web browser with the given URL as argument. | 183 | Starts the preferred web browser with the given URL as argument. |
@@ -394,12 +395,13 @@ class KABCore : public QWidget, public KSyncInterface | |||
394 | bool mMultipleViewsAtOnce; | 395 | bool mMultipleViewsAtOnce; |
395 | 396 | ||
396 | 397 | ||
397 | //US file menu | 398 | //US file menu |
398 | KAction *mActionMail; | 399 | KAction *mActionMail; |
399 | KAction *mActionBeam; | 400 | KAction *mActionBeam; |
401 | KAction *mActionExport2phone; | ||
400 | KAction* mActionPrint; | 402 | KAction* mActionPrint; |
401 | KAction* mActionNewContact; | 403 | KAction* mActionNewContact; |
402 | KAction *mActionSave; | 404 | KAction *mActionSave; |
403 | KAction *mActionEditAddressee; | 405 | KAction *mActionEditAddressee; |
404 | KAction *mActionMailVCard; | 406 | KAction *mActionMailVCard; |
405 | KAction *mActionBeamVCard; | 407 | KAction *mActionBeamVCard; |