summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp134
-rw-r--r--kaddressbook/kabcore.h42
2 files changed, 162 insertions, 14 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 2a54900..d891b07 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -85,6 +85,7 @@
#include <qtopia/services.h>
#include <qtopia/qcopenvelope_qws.h>
#endif
+#include <qpe/ir.h>
#endif // KAB_EMBEDDED
#include <kcmkabconfig.h>
@@ -449,6 +450,12 @@ void KABCore::setContactSelected( const QString &uid )
mActionEditAddressee->setEnabled( selected );
mActionMail->setEnabled( selected );
mActionMailVCard->setEnabled( selected );
+ if (mActionBeam)
+ mActionBeam->setEnabled( selected );
+
+ if (mActionBeam)
+ mActionBeamVCard->setEnabled( selected );
+
mActionWhoAmI->setEnabled( selected );
mActionCategories->setEnabled( selected );
}
@@ -485,6 +492,8 @@ void KABCore::sendMail( const QString& email )
#endif
}
+
+
void KABCore::mailVCard()
{
QStringList uids = mViewManager->selectedUids();
@@ -564,6 +573,112 @@ void KABCore::mailVCard( const QStringList& uids )
}
+/**
+ Beams the "WhoAmI contact.
+*/
+void KABCore::beamMySelf()
+{
+ KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI();
+ if (!a.isEmpty())
+ {
+ QStringList uids;
+ uids << a.uid();
+
+ beamVCard(uids);
+ }
+}
+
+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;
+*/
+ QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
+
+ QString dirName = tmpdir + "/" + KApplication::randomString( 8 );
+
+ QString name = "contact.vcf";
+
+ QString fileName = dirName + "/" + name;
+
+
+ QDir().mkdir( dirName, true );
+
+ QFile outFile(fileName);
+ KABC::VCardConverter converter;
+ QString description;
+
+ if ( outFile.open(IO_WriteOnly) ) { // file opened successfully
+
+ QTextStream t( &outFile ); // use a text stream
+ t.setEncoding( QTextStream::UnicodeUTF8 );
+
+ 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 );
+ t << vcard;
+
+ }
+ }
+
+ outFile.close();
+
+ Ir *ir = new Ir( this );
+ connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) );
+ ir->send( fileName, description, "text/x-vCard" );
+
+}
+
+void KABCore::beamDone( Ir *ir )
+{
+ delete ir;
+}
+
+
void KABCore::browse( const QString& url )
{
#ifndef KAB_EMBEDDED
@@ -1363,6 +1478,7 @@ void KABCore::initActions()
mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() );
}
+
mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this,
SLOT( save() ), actionCollection(), "file_sync" );
@@ -1373,6 +1489,14 @@ void KABCore::initActions()
this, SLOT( mailVCard() ),
actionCollection(), "file_mail_vcard");
+ mActionBeamVCard = 0;
+ if ( Ir::supported() ) {
+ mActionBeamVCard = new KAction( i18n( "Beam v&Card" ), "beam", 0, this,
+ SLOT( beamVCard() ), actionCollection(),
+ "kaddressbook_beam_vcard" );
+ }
+
+
mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0,
this, SLOT( editContact2() ),
actionCollection(), "file_properties" );
@@ -1473,6 +1597,14 @@ void KABCore::initActions()
SLOT( setWhoAmI() ), actionCollection(),
"set_personal" );
+ mActionBeam = 0;
+ if ( Ir::supported() ) {
+ mActionBeam = new KAction( i18n( "&Beam Who Am I" ), "beam", 0, this,
+ SLOT( beamMySelf() ), actionCollection(),
+ "kaddressbook_beam_myself" );
+ }
+
+
mActionCategories = new KAction( i18n( "Set Categories" ), 0, this,
SLOT( setCategories() ), actionCollection(),
"edit_set_categories" );
@@ -1561,6 +1693,7 @@ void KABCore::addActionsManually()
fileMenu->insertItem( "&Emport", ExportMenu );
fileMenu->insertSeparator();
mActionMailVCard->plug( fileMenu );
+ if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu );
fileMenu->insertSeparator();
mActionQuit->plug( fileMenu );
#ifdef _WIN32_
@@ -1601,6 +1734,7 @@ void KABCore::addActionsManually()
settingsMenu->insertSeparator();
mActionWhoAmI->plug( settingsMenu );
+ if ( Ir::supported() ) mActionBeam->plug( settingsMenu );
mActionCategories->plug( settingsMenu );
mActionAboutKAddressbook->plug( helpMenu );
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h
index 6446974..be39148 100644
--- a/kaddressbook/kabcore.h
+++ b/kaddressbook/kabcore.h
@@ -64,6 +64,7 @@ class QSplitter;
class ViewContainer;
class ViewManager;
class AddresseeEditorDialog;
+class Ir;
class KABCore : public QWidget
{
@@ -71,8 +72,8 @@ class KABCore : public QWidget
public:
KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name = 0 );
-
-
+
+
~KABCore();
@@ -139,7 +140,7 @@ class KABCore : public QWidget
#ifdef KAB_EMBEDDED
void createAboutData();
#endif //KAB_EMBEDDED
-
+
void statusMessage(QString, int time = 0 );
/**
Is called whenever a contact is selected in the view.
@@ -163,6 +164,16 @@ class KABCore : public QWidget
void mailVCard(const QStringList& uids);
/**
+ Beams the "WhoAmI contact.
+ */
+ void beamMySelf();
+
+ void beamVCard();
+ void beamVCard(const QStringList& uids);
+ void beamDone( Ir *ir );
+
+
+ /**
Starts the preferred web browser with the given URL as argument.
*/
void browse( const QString& url );
@@ -286,9 +297,9 @@ class KABCore : public QWidget
the method will try to find a selected addressee in the view.
*/
void editContact( const QString &uid /*US = QString::null*/ );
-//US added a second method without defaultparameter
+//US added a second method without defaultparameter
void editContact2();
-
+
/**
Launches the configuration dialog.
*/
@@ -335,12 +346,12 @@ class KABCore : public QWidget
private:
void initGUI();
void initActions();
-
+
AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent,
const char *name = 0 );
KXMLGUIClient *mGUIClient;
-
+
KABC::AddressBook *mAddressBook;
ViewManager *mViewManager;
@@ -366,13 +377,16 @@ class KABCore : public QWidget
//US file menu
KAction *mActionMail;
+ KAction *mActionBeam;
KAction* mActionPrint;
KAction* mActionNewContact;
KAction *mActionSave;
KAction *mActionEditAddressee;
KAction *mActionMailVCard;
+ KAction *mActionBeamVCard;
+
KAction *mActionQuit;
-
+
//US edit menu
KAction *mActionCopy;
KAction *mActionCut;
@@ -381,7 +395,7 @@ class KABCore : public QWidget
KAction *mActionUndo;
KAction *mActionRedo;
KAction *mActionDelete;
-
+
//US settings menu
KAction *mActionConfigResources;
KAction *mActionConfigKAddressbook;
@@ -393,21 +407,21 @@ class KABCore : public QWidget
KAction *mActionWhoAmI;
KAction *mActionCategories;
KAction *mActionAboutKAddressbook;
-
+
KAction *mActionDeleteView;
-
+
QPopupMenu *viewMenu;
QPopupMenu *filterMenu;
QPopupMenu *settingsMenu;
QPopupMenu *changeMenu;
-
+
//US QAction *mActionSave;
QPopupMenu *ImportMenu;
QPopupMenu *ExportMenu;
//LR additional methods
KAction *mActionRemoveVoice;
KAction * mActionImportOL;
-
+
#ifndef KAB_EMBEDDED
KAddressBookService *mAddressBookService;
#endif //KAB_EMBEDDED
@@ -418,7 +432,7 @@ class KABCore : public QWidget
#ifdef KAB_EMBEDDED
KAddressBookMain *mMainWindow; // should be the same like mGUIClient
#endif //KAB_EMBEDDED
-
+
};
#endif