summaryrefslogtreecommitdiffabout
path: root/kaddressbook/kabcore.cpp
Side-by-side diff
Diffstat (limited to 'kaddressbook/kabcore.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp254
1 files changed, 143 insertions, 111 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index a7ca0ce..2a54900 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -21,7 +21,7 @@
without including the source code for Qt in the source distribution.
*/
-#include "kabcore.h"
+#include "kabcore.h"
#include <stdaddressbook.h>
#include <klocale.h>
@@ -78,8 +78,14 @@
#include <kcmkabconfig.h>
-//US#include <qpe/resource.h> // needed for Resource::loadPixmap
//#include <qlabel.h>
+
+
+#ifdef Q_WS_QWS
+#include <qtopia/services.h>
+#include <qtopia/qcopenvelope_qws.h>
+#endif
+
#endif // KAB_EMBEDDED
#include <kcmkabconfig.h>
@@ -91,11 +97,17 @@
#include <resource.h>
//US#include <qsplitter.h>
+#include <qmap.h>
+#include <qdir.h>
+#include <qfile.h>
#include <qvbox.h>
#include <qlayout.h>
#include <qclipboard.h>
+#include <qtextstream.h>
#include <libkdepim/categoryselectdialog.h>
+#include <kabc/vcardconverter.h>
+
#include "addresseeutil.h"
#include "undocmds.h"
@@ -129,10 +141,7 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const
mReadWrite( readWrite ), mModified( false )
#endif //KAB_EMBEDDED
{
-#ifdef KAB_EMBEDDED
- //US we define here our own global actioncollection.
- //mActionCollection = new KActionCollection(this);
-#endif //KAB_EMBEDDED
+
mExtensionBarSplitter = 0;
mIsPart = !parent->inherits( "KAddressBookMain" );
@@ -142,7 +151,7 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const
#ifndef KAB_EMBEDDED
mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
#endif //KAB_EMBEDDED
-
+
connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
SLOT( addressBookChanged() ) );
@@ -162,8 +171,8 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const
"X-IMAddress", "KADDRESSBOOK" );
mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
"X-Anniversary", "KADDRESSBOOK" );
-
- //US added this field to become compatible with Opie/qtopia addressbook
+
+ //US added this field to become compatible with Opie/qtopia addressbook
// values can be "female" or "male" or "". An empty field represents undefined.
mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal,
"X-Gender", "KADDRESSBOOK" );
@@ -195,13 +204,14 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const
SLOT( incrementalSearch( const QString& ) ) );
connect( mIncSearchWidget, SIGNAL( fieldChanged() ),
mJumpButtonBar, SLOT( recreateButtons() ) );
-
+
+ connect( mDetails, SIGNAL( sendEmail( const QString& ) ),
+ SLOT( sendMail( const QString& ) ) );
+
#ifndef KAB_EMBEDDED
connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ),
mXXPortManager, SLOT( importVCard( const KURL& ) ) );
- connect( mDetails, SIGNAL( sendEmail( const QString& ) ),
- SLOT( sendMail( const QString& ) ) );
connect( mDetails, SIGNAL( browse( const QString& ) ),
SLOT( browse( const QString& ) ) );
@@ -221,12 +231,6 @@ KABCore::~KABCore()
delete AddresseeConfig::instance();
mAddressBook = 0;
KABC::StdAddressBook::close();
-
-#ifdef KAB_EMBEDDED
- //US we define here our own global actioncollection.
- // delete mActionCollection;
-#endif //KAB_EMBEDDED
-
}
void KABCore::restoreSettings()
@@ -235,7 +239,7 @@ void KABCore::restoreSettings()
mActionJumpBar->setChecked( state );
setJumpButtonBarVisible( state );
-
+
state = KABPrefs::instance()->mDetailsPageVisible;
mActionDetails->setChecked( state );
@@ -294,9 +298,9 @@ void KABCore::saveSettings()
#endif //KAB_EMBEDDED
mExtensionManager->saveSettings();
mViewManager->saveSettings();
-
+
KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem();
-
+
}
KABC::AddressBook *KABCore::addressBook() const
@@ -378,9 +382,9 @@ void KABCore::createAboutData()
return about;
#endif //KAB_EMBEDDED
-
+
QString version;
-#include <../version>
+#include <../version>
QMessageBox::about( this, "About KAddressbook/Pi",
"KAddressbook/Platform-independent\n"
"(KA/Pi) " +version + " - " +
@@ -390,7 +394,7 @@ void KABCore::createAboutData()
"PDA-Edition\n"
"for: Zaurus 5500 / 7x0 / 8x0\n"
#endif
-
+
"(c) 2004 Ulf Schenk\n"
"(c) 1997-2003, The KDE PIM Team\n"
"Tobias Koenig Current maintainer tokoe@kde.org\n"
@@ -418,13 +422,13 @@ void KABCore::setContactSelected( const QString &uid )
KABC::Picture pic = addr.photo();
if ( pic.isIntern() ) {
//US emit contactSelected( pic.data() );
-//US instead use:
+//US instead use:
QPixmap px;
if (pic.data().isNull() != true)
{
px.convertFromImage(pic.data());
}
-
+
emit contactSelected( px );
}
}
@@ -451,38 +455,50 @@ void KABCore::setContactSelected( const QString &uid )
void KABCore::sendMail()
{
-#ifndef KAB_EMBEDDED
sendMail( mViewManager->selectedEmails().join( ", " ) );
-#else //KAB_EMBEDDED
- qDebug("KABCore::sendMail() ust be fixed");
-#endif //KAB_EMBEDDED
}
void KABCore::sendMail( const QString& email )
{
-#ifndef KAB_EMBEDDED
- kapp->invokeMailer( email, "" );
-#else //KAB_EMBEDDED
- qDebug("KABCore::sendMail(const QString& email) ust be fixed");
-#endif //KAB_EMBEDDED
+//US original kde implementation : kapp->invokeMailer( email, "" );
+
+/*US original qtopia implementation
+ PimContact c = abList->currentEntry();
+ QString name = c.fileAs();
+ QString email = c.defaultEmail();
+#ifndef QT_NO_COP
+ QCopEnvelope e(Service::channel("Email"), "writeMail(QString,QString)");
+ e << name << email;
+#else
+*/
+
+
+#ifndef QT_NO_COP
+ QCString channel = KABPrefs::instance()->mEmailChannel.latin1();
+ qDebug("Using QCopEnvelope e(\"" + channel + "\", \"writeMail(QMap(QString,QString))\")");
+
+ QCopEnvelope e(channel, "writeMail(QString,QString)");
+ //US we need no names in the To field. The emailadresses are enough
+ e << "" << email;
+#else
+ KMessageBox::sorry( this, i18n( "This version does not support sending emails." ) );
+#endif
}
void KABCore::mailVCard()
{
-#ifndef KAB_EMBEDDED
QStringList uids = mViewManager->selectedUids();
if ( !uids.isEmpty() )
mailVCard( uids );
-#else //KAB_EMBEDDED
- qDebug("KABCore::mailVCard() must be fixed");
-#endif //KAB_EMBEDDED
}
void KABCore::mailVCard( const QStringList& uids )
{
-#ifndef KAB_EMBEDDED
QStringList urls;
+ QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
+
+/*US
// Create a temp dir, so that we can put the files in it with proper names
KTempFile tempDir;
if ( tempDir.status() != 0 ) {
@@ -492,6 +508,11 @@ void KABCore::mailVCard( const QStringList& uids )
QString dirName = tempDir.name();
tempDir.unlink();
+*/
+ QString dirName = tmpdir + "/" + KApplication::randomString( 8 );
+
+
+
QDir().mkdir( dirName, true );
for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
@@ -520,15 +541,26 @@ void KABCore::mailVCard( const QStringList& uids )
urls.append( fileName );
}
}
-
+/*US
kapp->invokeMailer( QString::null, QString::null, QString::null,
QString::null, // subject
QString::null, // body
QString::null,
urls ); // attachments
-#else //KAB_EMBEDDED
- qDebug("KABCore::mailVCard( must be fixed");
-#endif //KAB_EMBEDDED
+*/
+#ifndef QT_NO_COP
+ QCString channel = KABPrefs::instance()->mEmailChannel.latin1();
+ qDebug("Using QCopEnvelope e(\"" + channel + "\", \"writeMail(QMap(QString,QString))\")");
+
+ QMap<QString, QString> parameterMap;
+ parameterMap.insert("ATTACHMENT<n>", urls.join(", "));
+
+ QCopEnvelope e(channel, "writeMail(QMap(QString,QString))");
+ e << parameterMap;
+#else
+ KMessageBox::sorry( this, i18n( "This version does not support sending emails." ) );
+#endif
+
}
@@ -752,7 +784,7 @@ void KABCore::setModified( bool modified )
mViewManager->refreshView();
mDetails->refreshView();
-
+
}
bool KABCore::modified() const
@@ -762,7 +794,7 @@ bool KABCore::modified() const
void KABCore::contactModified( const KABC::Addressee &addr )
{
-
+
Command *command = 0;
QString uid;
@@ -806,14 +838,14 @@ void KABCore::newContact()
KABC::Addressee addr;
addr.setResource( resource );
mEditorDialog->setAddressee( addr );
- KApplication::execDialog ( mEditorDialog );
-
+ KApplication::execDialog ( mEditorDialog );
+
} else
return;
-
+
// mEditorDict.insert( dialog->addressee().uid(), dialog );
-
+
}
void KABCore::addEmail( QString aStr )
@@ -888,7 +920,7 @@ void KABCore::importVCard( const QString &vCard, bool showPreview )
mXXPortManager->importVCard( vCard, showPreview );
}
-//US added a second method without defaultparameter
+//US added a second method without defaultparameter
void KABCore::editContact2() {
editContact( QString::null );
}
@@ -981,14 +1013,14 @@ void KABCore::setDetailsVisible( bool visible )
void KABCore::extensionModified( const KABC::Addressee::List &list )
{
-
+
if ( list.count() != 0 ) {
KABC::Addressee::List::ConstIterator it;
for ( it = list.begin(); it != list.end(); ++it )
mAddressBook->insertAddressee( *it );
if ( list.count() > 1 )
setModified();
- else
+ else
setModifiedWOrefresh();
}
if ( list.count() == 0 )
@@ -996,7 +1028,7 @@ void KABCore::extensionModified( const KABC::Addressee::List &list )
else
mViewManager->refreshView( list[ 0 ].uid() );
-
+
}
@@ -1028,7 +1060,7 @@ QString KABCore::getNameByPhone( const QString &phone )
qDebug("KABCore::getNameByPhone finsih method");
return "";
#endif //KAB_EMBEDDED
-
+
}
void KABCore::openConfigDialog()
@@ -1185,7 +1217,7 @@ void KABCore::initGUI()
mXXPortManager = new XXPortManager( this, this );
#else //KAB_EMBEDDED
- //US initialize viewMenu before settingup viewmanager.
+ //US initialize viewMenu before settingup viewmanager.
// Viewmanager needs this menu to plugin submenues.
viewMenu = new QPopupMenu( this );
settingsMenu = new QPopupMenu( this );
@@ -1202,17 +1234,17 @@ void KABCore::initGUI()
// = new QHBoxLayout( this );
// QBoxLayout *topLayout = (QBoxLayout*)layout();
-
+
// QWidget *mainBox = new QWidget( this );
// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox);
#ifdef DESKTOP_VERSION
topLayout = new QHBoxLayout( this );
-
+
mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
-
+
topLayout->addWidget(mMiniSplitter );
mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter );
@@ -1231,18 +1263,18 @@ void KABCore::initGUI()
mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this);
mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
}
-
+
topLayout->addWidget(mMiniSplitter );
mViewManager = new ViewManager( this, mMiniSplitter );
mDetails = new ViewContainer( mMiniSplitter );
-
-
+
+
mExtensionManager = new ExtensionManager( this, mMiniSplitter );
#endif
//eh->hide();
// topLayout->addWidget(mExtensionManager );
-
-
+
+
/*US
#ifndef KAB_NOSPLITTER
QHBoxLayout *topLayout = new QHBoxLayout( this );
@@ -1257,7 +1289,7 @@ void KABCore::initGUI()
viewSpace->setStretchFactor( mViewManager, 1 );
mDetails = new ViewContainer( mDetailsSplitter );
-
+
topLayout->addWidget( mDetailsSplitter );
topLayout->setStretchFactor( mDetailsSplitter, 100 );
#else //KAB_NOSPLITTER
@@ -1280,7 +1312,7 @@ void KABCore::initGUI()
#endif //KAB_NOSPLITTER
*/
-
+
#endif //KAB_EMBEDDED
initActions();
@@ -1298,26 +1330,26 @@ void KABCore::initGUI()
connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
SLOT( incrementalSearch( const QString& ) ) );
-
+
mJumpButtonBar = new JumpButtonBar( this, this );
topLayout->addWidget( mJumpButtonBar );
//US topLayout->setStretchFactor( mJumpButtonBar, 10 );
-
+
// mMainWindow->getIconToolBar()->raise();
#endif //KAB_EMBEDDED
-
+
}
void KABCore::initActions()
{
//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
-
+
#ifndef KAB_EMBEDDED
connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
SLOT( clipboardDataChanged() ) );
#endif //KAB_EMBEDDED
-
+
// file menu
if ( mIsPart ) {
mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this,
@@ -1330,13 +1362,13 @@ void KABCore::initActions()
mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() );
mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() );
}
-
+
mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this,
SLOT( save() ), actionCollection(), "file_sync" );
-
+
mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this,
SLOT( newContact() ), actionCollection(), "file_new_contact" );
-
+
mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0,
this, SLOT( mailVCard() ),
actionCollection(), "file_mail_vcard");
@@ -1351,7 +1383,7 @@ void KABCore::initActions()
mMainWindow, SLOT( exit() ),
actionCollection(), "quit" );
#endif //KAB_EMBEDDED
-
+
// edit menu
if ( mIsPart ) {
mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this,
@@ -1387,7 +1419,7 @@ void KABCore::initActions()
mActionUndo->setEnabled( false );
mActionRedo->setEnabled( false );
-
+
// settings menu
#ifdef KAB_EMBEDDED
//US special menuentry to configure the addressbook resources. On KDE
@@ -1396,12 +1428,12 @@ void KABCore::initActions()
SLOT( configureResources() ), actionCollection(),
"kaddressbook_configure_resources" );
#endif //KAB_EMBEDDED
-
+
if ( mIsPart ) {
mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this,
SLOT( openConfigDialog() ), actionCollection(),
"kaddressbook_configure" );
-
+
mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0,
this, SLOT( configureKeyBindings() ), actionCollection(),
"kaddressbook_configure_shortcuts" );
@@ -1409,33 +1441,33 @@ void KABCore::initActions()
mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() );
mActionConfigureToolbars->setEnabled( false );
#endif //KAB_EMBEDDED
-
+
} else {
mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() );
-
+
mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() );
}
-
+
mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0,
actionCollection(), "options_show_jump_bar" );
connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) );
-
+
mActionDetails = new KToggleAction( i18n( "Show Details" ), 0, 0,
actionCollection(), "options_show_details" );
connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) );
-
+
// misc
// only enable LDAP lookup if we can handle the protocol
-#ifndef KAB_EMBEDDED
+#ifndef KAB_EMBEDDED
if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) {
new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0,
this, SLOT( openLDAPDialog() ), actionCollection(),
"ldap_lookup" );
}
-#else //KAB_EMBEDDED
+#else //KAB_EMBEDDED
//qDebug("KABCore::initActions() LDAP has to be implemented");
-#endif //KAB_EMBEDDED
-
+#endif //KAB_EMBEDDED
+
mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this,
SLOT( setWhoAmI() ), actionCollection(),
@@ -1457,7 +1489,7 @@ void KABCore::initActions()
this, SLOT( createAboutData() ), actionCollection(),
"kaddressbook_about_data" );
#endif //KAB_EMBEDDED
-
+
clipboardDataChanged();
connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
@@ -1478,7 +1510,7 @@ void KABCore::addActionsManually()
#ifdef DESKTOP_VERSION
QMenuBar* mb = mMainWindow->menuBar();
-
+
//US setup menubar.
//Disable the following block if you do not want to have a menubar.
mb->insertItem( "&File", fileMenu );
@@ -1489,15 +1521,15 @@ void KABCore::addActionsManually()
mb->insertItem( "&Help", helpMenu );
mIncSearchWidget = new IncSearchWidget( tb );
// tb->insertWidget(-1, 0, mIncSearchWidget);
-
-#else
+
+#else
//US setup toolbar
QMenuBar *menuBarTB = new QMenuBar( tb );
QPopupMenu *popupBarTB = new QPopupMenu( this );
menuBarTB->insertItem( "ME", popupBarTB);
tb->insertWidget(-1, 0, menuBarTB);
mIncSearchWidget = new IncSearchWidget( tb );
-
+
tb->enableMoving(false);
popupBarTB->insertItem( "&File", fileMenu );
popupBarTB->insertItem( "&Edit", editMenu );
@@ -1518,10 +1550,10 @@ void KABCore::addActionsManually()
mActionPrint->plug( fileMenu );
mActionMail->plug( fileMenu );
fileMenu->insertSeparator();
-
+
mActionNewContact->plug( fileMenu );
mActionNewContact->plug( tb );
-
+
mActionEditAddressee->plug( fileMenu );
fileMenu->insertSeparator();
mActionSave->plug( fileMenu );
@@ -1533,7 +1565,7 @@ void KABCore::addActionsManually()
mActionQuit->plug( fileMenu );
#ifdef _WIN32_
mActionImportOL->plug( ImportMenu );
-#endif
+#endif
// edit menu
mActionUndo->plug( editMenu );
mActionRedo->plug( editMenu );
@@ -1544,7 +1576,7 @@ void KABCore::addActionsManually()
mActionDelete->plug( editMenu );
editMenu->insertSeparator();
mActionSelectAll->plug( editMenu );
-
+
mActionRemoveVoice->plug( changeMenu );
// settings menu
//US special menuentry to configure the addressbook resources. On KDE
@@ -1553,32 +1585,32 @@ void KABCore::addActionsManually()
settingsMenu->insertSeparator();
mActionConfigKAddressbook->plug( settingsMenu );
-
+
if ( mIsPart ) {
mActionConfigShortcuts->plug( settingsMenu );
mActionConfigureToolbars->plug( settingsMenu );
-
+
} else {
mActionKeyBindings->plug( settingsMenu );
}
-
+
settingsMenu->insertSeparator();
-
+
mActionJumpBar->plug( settingsMenu );
mActionDetails->plug( settingsMenu );
settingsMenu->insertSeparator();
mActionWhoAmI->plug( settingsMenu );
mActionCategories->plug( settingsMenu );
-
+
mActionAboutKAddressbook->plug( helpMenu );
-
+
if (QApplication::desktop()->width() > 320 ) {
mActionEditAddressee->plug( tb );
mActionSave->plug( tb );
- mViewManager->getFilterAction()->plug ( tb);
+ mViewManager->getFilterAction()->plug ( tb);
if (QApplication::desktop()->width() > 480 ) {
mActionUndo->plug( tb );
mActionDelete->plug( tb );
@@ -1587,22 +1619,22 @@ void KABCore::addActionsManually()
}
//mActionQuit->plug ( tb );
// tb->insertWidget(-1, 0, mIncSearchWidget, 6);
-
+
//US link the searchwidget first to this.
// The real linkage to the toolbar happens later.
//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE);
//US tb->insertItem( mIncSearchWidget );
-/*US
+/*US
mIncSearchWidget = new IncSearchWidget( tb );
connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
SLOT( incrementalSearch( const QString& ) ) );
-
+
mJumpButtonBar = new JumpButtonBar( this, this );
-
+
//US topLayout->addWidget( mJumpButtonBar );
this->layout()->add( mJumpButtonBar );
*/
-
+
#endif //KAB_EMBEDDED
}
void KABCore::removeVoice()
@@ -1623,7 +1655,7 @@ void KABCore::removeVoice()
found = true;
}
}
-
+
}
if ( found )
contactModified((*it) );
@@ -1634,7 +1666,7 @@ void KABCore::removeVoice()
void KABCore::clipboardDataChanged()
{
-
+
if ( mReadWrite )
mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
@@ -1673,7 +1705,7 @@ void KABCore::configureKeyBindings()
void KABCore::configureResources()
{
KRES::KCMKResources dlg( this, "" , 0 );
-
+
if ( !dlg.exec() )
return;
KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") );