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.cpp1571
1 files changed, 1571 insertions, 0 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
new file mode 100644
index 0000000..3e578bc
--- a/dev/null
+++ b/kaddressbook/kabcore.cpp
@@ -0,0 +1,1571 @@
+/*
+ This file is part of KAddressbook.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#include "kabcore.h"
+
+#include <stdaddressbook.h>
+#include <klocale.h>
+
+#ifndef KAB_EMBEDDED
+#include <qclipboard.h>
+#include <qdir.h>
+#include <qfile.h>
+#include <qapplicaton.h>
+#include <qlayout.h>
+#include <qregexp.h>
+#include <qvbox.h>
+#include <kabc/addresseelist.h>
+#include <kabc/errorhandler.h>
+#include <kabc/resource.h>
+#include <kabc/vcardconverter.h>
+#include <kapplication.h>
+#include <kactionclasses.h>
+#include <kcmultidialog.h>
+#include <kdebug.h>
+#include <kdeversion.h>
+#include <kkeydialog.h>
+#include <kmessagebox.h>
+#include <kprinter.h>
+#include <kprotocolinfo.h>
+#include <kresources/selectdialog.h>
+#include <kstandarddirs.h>
+#include <ktempfile.h>
+#include <kxmlguiclient.h>
+#include <kaboutdata.h>
+#include <libkdepim/categoryselectdialog.h>
+
+#include "addresseeutil.h"
+#include "addresseeeditordialog.h"
+#include "extensionmanager.h"
+#include "kstdaction.h"
+#include "kaddressbookservice.h"
+#include "ldapsearchdialog.h"
+#include "printing/printingwizard.h"
+#else // KAB_EMBEDDED
+
+#include "KDGanttMinimizeSplitter.h"
+#include "kaddressbookmain.h"
+#include "kactioncollection.h"
+#include <qapp.h>
+#include <qmenubar.h>
+//#include <qtoolbar.h>
+#include <qmessagebox.h>
+#include <kdebug.h>
+#include <kiconloader.h> // needed for SmallIcon
+#include <kresources/kcmkresources.h>
+#include <ktoolbar.h>
+
+#include <kcmkabconfig.h>
+
+//US#include <qpe/resource.h> // needed for Resource::loadPixmap
+//#include <qlabel.h>
+#endif // KAB_EMBEDDED
+#include <kcmkabconfig.h>
+
+
+#include <kresources/selectdialog.h>
+#include <kmessagebox.h>
+
+#include <picture.h>
+#include <resource.h>
+
+//US#include <qsplitter.h>
+#include <qvbox.h>
+#include <qlayout.h>
+#include <qclipboard.h>
+
+#include <libkdepim/categoryselectdialog.h>
+
+#include "addresseeutil.h"
+#include "undocmds.h"
+#include "addresseeeditordialog.h"
+#include "viewmanager.h"
+#include "details/detailsviewcontainer.h"
+#include "kabprefs.h"
+#include "xxportmanager.h"
+#include "incsearchwidget.h"
+#include "jumpbuttonbar.h"
+#include "extensionmanager.h"
+#include "addresseeconfig.h"
+#include <kcmultidialog.h>
+
+
+#ifdef KAB_EMBEDDED
+KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
+ : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
+ mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
+ mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
+#else //KAB_EMBEDDED
+KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
+ : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
+ mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
+ 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
+
+ mIsPart = !parent->inherits( "KAddressBookMain" );
+
+ mAddressBook = KABC::StdAddressBook::self();
+ KABC::StdAddressBook::setAutomaticSave( true );
+
+#ifndef KAB_EMBEDDED
+ mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
+#endif //KAB_EMBEDDED
+
+ connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
+ SLOT( addressBookChanged() ) );
+
+ mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization,
+ "X-Department", "KADDRESSBOOK" );
+ mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization,
+ "X-Profession", "KADDRESSBOOK" );
+ mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
+ "X-AssistantsName", "KADDRESSBOOK" );
+ mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
+ "X-ManagersName", "KADDRESSBOOK" );
+ mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
+ "X-SpousesName", "KADDRESSBOOK" );
+ mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal,
+ "X-Office", "KADDRESSBOOK" );
+ mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
+ "X-IMAddress", "KADDRESSBOOK" );
+ mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
+ "X-Anniversary", "KADDRESSBOOK" );
+
+ initGUI();
+
+ mIncSearchWidget->setFocus();
+
+
+ connect( mViewManager, SIGNAL( selected( const QString& ) ),
+ SLOT( setContactSelected( const QString& ) ) );
+ connect( mViewManager, SIGNAL( executed( const QString& ) ),
+ SLOT( editContact( const QString& ) ) );
+ connect( mViewManager, SIGNAL( deleteRequest( ) ),
+ SLOT( deleteContacts( ) ) );
+ connect( mViewManager, SIGNAL( modified() ),
+ SLOT( setModified() ) );
+
+ connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) );
+
+ connect( mXXPortManager, SIGNAL( modified() ),
+ SLOT( setModified() ) );
+
+ connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ),
+ SLOT( incrementalSearch( const QString& ) ) );
+ connect( mIncSearchWidget, SIGNAL( fieldChanged() ),
+ mJumpButtonBar, SLOT( recreateButtons() ) );
+
+#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& ) ) );
+
+ mAddressBookService = new KAddressBookService( this );
+
+#endif //KAB_EMBEDDED
+
+ setModified( false );
+}
+
+KABCore::~KABCore()
+{
+ // save();
+ //saveSettings();
+ //KABPrefs::instance()->writeConfig();
+ 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()
+{
+ bool state = KABPrefs::instance()->mJumpButtonBarVisible;
+
+ mActionJumpBar->setChecked( state );
+ setJumpButtonBarVisible( state );
+
+ state = KABPrefs::instance()->mDetailsPageVisible;
+
+ mActionDetails->setChecked( state );
+ setDetailsVisible( state );
+ QValueList<int> splitterSize = KABPrefs::instance()->mExtensionsSplitter;
+ if ( splitterSize.count() == 0 ) {
+ splitterSize.append( width() / 2 );
+ splitterSize.append( width() / 2 );
+ }
+ mMiniSplitter->setSizes( splitterSize );
+#ifndef KAB_EMBEDDED
+ QValueList<int> splitterSize = KABPrefs::instance()->mExtensionsSplitter;
+ if ( splitterSize.count() == 0 ) {
+ splitterSize.append( width() / 2 );
+ splitterSize.append( width() / 2 );
+ }
+ mExtensionBarSplitter->setSizes( splitterSize );
+
+ splitterSize = KABPrefs::instance()->mDetailsSplitter;
+ if ( splitterSize.count() == 0 ) {
+ splitterSize.append( height() / 2 );
+ splitterSize.append( height() / 2 );
+ }
+ mDetailsSplitter->setSizes( splitterSize );
+
+ mExtensionManager->restoreSettings();
+
+#endif //KAB_EMBEDDED
+
+ mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField );
+
+ mViewManager->restoreSettings();
+ mExtensionManager->restoreSettings();
+}
+
+void KABCore::saveSettings()
+{
+ KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked();
+ KABPrefs::instance()->mExtensionsSplitter = mMiniSplitter->sizes();
+ KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked();
+
+#ifndef KAB_EMBEDDED
+
+ KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
+ KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes();
+#endif //KAB_EMBEDDED
+ mExtensionManager->saveSettings();
+ mViewManager->saveSettings();
+
+ KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem();
+
+}
+
+KABC::AddressBook *KABCore::addressBook() const
+{
+ return mAddressBook;
+}
+
+KConfig *KABCore::config()
+{
+#ifndef KAB_EMBEDDED
+ return KABPrefs::instance()->config();
+#else //KAB_EMBEDDED
+ return KABPrefs::instance()->getConfig();
+#endif //KAB_EMBEDDED
+}
+
+KActionCollection *KABCore::actionCollection() const
+{
+ return mGUIClient->actionCollection();
+}
+
+KABC::Field *KABCore::currentSearchField() const
+{
+ if (mIncSearchWidget)
+ return mIncSearchWidget->currentField();
+ else
+ return 0;
+}
+
+QStringList KABCore::selectedUIDs() const
+{
+ return mViewManager->selectedUids();
+}
+
+KABC::Resource *KABCore::requestResource( QWidget *parent )
+{
+ QPtrList<KABC::Resource> kabcResources = addressBook()->resources();
+
+ QPtrList<KRES::Resource> kresResources;
+ QPtrListIterator<KABC::Resource> resIt( kabcResources );
+ KABC::Resource *resource;
+ while ( ( resource = resIt.current() ) != 0 ) {
+ ++resIt;
+ if ( !resource->readOnly() ) {
+ KRES::Resource *res = static_cast<KRES::Resource*>( resource );
+ if ( res )
+ kresResources.append( res );
+ }
+ }
+
+ KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent );
+ return static_cast<KABC::Resource*>( res );
+}
+
+#ifndef KAB_EMBEDDED
+KAboutData *KABCore::createAboutData()
+#else //KAB_EMBEDDED
+void KABCore::createAboutData()
+#endif //KAB_EMBEDDED
+{
+#ifndef KAB_EMBEDDED
+ KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ),
+ "3.1", I18N_NOOP( "The KDE Address Book" ),
+ KAboutData::License_GPL_V2,
+ I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) );
+ about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" );
+ about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) );
+ about->addAuthor( "Cornelius Schumacher",
+ I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ),
+ "schumacher@kde.org" );
+ about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ),
+ "mpilone@slac.com" );
+ about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) );
+ about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) );
+ about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ),
+ "michel@klaralvdalens-datakonsult.se" );
+ about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ),
+ "hansen@kde.org" );
+
+ return about;
+#endif //KAB_EMBEDDED
+
+ QString version;
+#include <../version>
+ QMessageBox::about( this, "About KAddressbook/Pi",
+ "KAddressbook/Platform-independent\n"
+ "(KA/Pi) " +version + " - " +
+#ifdef DESKTOP_VERSION
+ "Desktop Edition\n"
+#else
+ "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"
+ "Don Sanders Original author\n"
+ "Cornelius Schumacher Co-maintainer schumacher@kde.org\n"
+ "Mike Pilone GUI and framework redesign mpilone@slac.com\n"
+ "Greg Stern DCOP interface\n"
+ "Mark Westcot Contact pinning\n"
+ "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n"
+ "Steffen Hansen LDAP Lookup hansen@kde.org\n" );
+}
+
+void KABCore::setContactSelected( const QString &uid )
+{
+ KABC::Addressee addr = mAddressBook->findByUid( uid );
+ if ( !mDetails->isHidden() )
+ mDetails->setAddressee( addr );
+
+ if ( !addr.isEmpty() ) {
+ emit contactSelected( addr.formattedName() );
+ KABC::Picture pic = addr.photo();
+ if ( pic.isIntern() ) {
+//US emit contactSelected( pic.data() );
+//US instead use:
+ QPixmap px;
+ if (pic.data().isNull() != true)
+ {
+ px.convertFromImage(pic.data());
+ }
+
+ emit contactSelected( px );
+ }
+ }
+
+
+ mExtensionManager->setSelectionChanged();
+
+ // update the actions
+ bool selected = !uid.isEmpty();
+
+ if ( mReadWrite ) {
+ mActionCut->setEnabled( selected );
+ mActionPaste->setEnabled( selected );
+ }
+
+ mActionCopy->setEnabled( selected );
+ mActionDelete->setEnabled( selected );
+ mActionEditAddressee->setEnabled( selected );
+ mActionMail->setEnabled( selected );
+ mActionMailVCard->setEnabled( selected );
+ mActionWhoAmI->setEnabled( selected );
+ mActionCategories->setEnabled( selected );
+}
+
+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
+}
+
+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;
+
+ // Create a temp dir, so that we can put the files in it with proper names
+ KTempFile tempDir;
+ if ( tempDir.status() != 0 ) {
+ kdWarning() << strerror( tempDir.status() ) << endl;
+ return;
+ }
+
+ QString dirName = tempDir.name();
+ tempDir.unlink();
+ QDir().mkdir( dirName, true );
+
+ for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
+ KABC::Addressee a = mAddressBook->findByUid( *it );
+
+ if ( a.isEmpty() )
+ continue;
+
+ QString name = a.givenName() + "_" + a.familyName() + ".vcf";
+
+ QString fileName = dirName + "/" + name;
+
+ QFile outFile(fileName);
+ if ( outFile.open(IO_WriteOnly) ) { // file opened successfully
+ KABC::VCardConverter converter;
+ QString vcard;
+
+ converter.addresseeToVCard( a, vcard );
+
+ QTextStream t( &outFile ); // use a text stream
+ t.setEncoding( QTextStream::UnicodeUTF8 );
+ t << vcard;
+
+ outFile.close();
+
+ urls.append( fileName );
+ }
+ }
+
+ 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
+
+}
+
+void KABCore::browse( const QString& url )
+{
+#ifndef KAB_EMBEDDED
+ kapp->invokeBrowser( url );
+#else //KAB_EMBEDDED
+ qDebug("KABCore::browse must be fixed");
+#endif //KAB_EMBEDDED
+}
+
+void KABCore::selectAllContacts()
+{
+ mViewManager->setSelected( QString::null, true );
+}
+
+void KABCore::deleteContacts()
+{
+ QStringList uidList = mViewManager->selectedUids();
+ deleteContacts( uidList );
+}
+
+void KABCore::deleteContacts( const QStringList &uids )
+{
+ if ( uids.count() > 0 ) {
+ PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids );
+ UndoStack::instance()->push( command );
+ RedoStack::instance()->clear();
+
+ // now if we deleted anything, refresh
+ setContactSelected( QString::null );
+ setModified( true );
+ }
+}
+
+void KABCore::copyContacts()
+{
+ KABC::Addressee::List addrList = mViewManager->selectedAddressees();
+
+ QString clipText = AddresseeUtil::addresseesToClipboard( addrList );
+
+ kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl;
+
+ QClipboard *cb = QApplication::clipboard();
+ cb->setText( clipText );
+}
+
+void KABCore::cutContacts()
+{
+ QStringList uidList = mViewManager->selectedUids();
+
+//US if ( uidList.size() > 0 ) {
+ if ( uidList.count() > 0 ) {
+ PwCutCommand *command = new PwCutCommand( mAddressBook, uidList );
+ UndoStack::instance()->push( command );
+ RedoStack::instance()->clear();
+
+ setModified( true );
+ }
+}
+
+void KABCore::pasteContacts()
+{
+ QClipboard *cb = QApplication::clipboard();
+
+ KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() );
+
+ pasteContacts( list );
+}
+
+void KABCore::pasteContacts( KABC::Addressee::List &list )
+{
+ KABC::Resource *resource = requestResource( this );
+ KABC::Addressee::List::Iterator it;
+ for ( it = list.begin(); it != list.end(); ++it )
+ (*it).setResource( resource );
+
+ PwPasteCommand *command = new PwPasteCommand( this, list );
+ UndoStack::instance()->push( command );
+ RedoStack::instance()->clear();
+
+ setModified( true );
+}
+
+void KABCore::setWhoAmI()
+{
+ KABC::Addressee::List addrList = mViewManager->selectedAddressees();
+
+ if ( addrList.count() > 1 ) {
+ KMessageBox::sorry( this, i18n( "Please select only one contact." ) );
+ return;
+ }
+
+ QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) );
+ if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes )
+ static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] );
+}
+
+void KABCore::setCategories()
+{
+ KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true );
+ if ( !dlg.exec() )
+ return;
+
+ bool merge = false;
+ QString msg = i18n( "Merge with existing categories?" );
+ if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes )
+ merge = true;
+
+ QStringList categories = dlg.selectedCategories();
+
+ QStringList uids = mViewManager->selectedUids();
+ QStringList::Iterator it;
+ for ( it = uids.begin(); it != uids.end(); ++it ) {
+ KABC::Addressee addr = mAddressBook->findByUid( *it );
+ if ( !addr.isEmpty() ) {
+ if ( !merge )
+ addr.setCategories( categories );
+ else {
+ QStringList addrCategories = addr.categories();
+ QStringList::Iterator catIt;
+ for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
+ if ( !addrCategories.contains( *catIt ) )
+ addrCategories.append( *catIt );
+ }
+ addr.setCategories( addrCategories );
+ }
+
+ mAddressBook->insertAddressee( addr );
+ }
+ }
+
+ if ( uids.count() > 0 )
+ setModified( true );
+}
+
+void KABCore::setSearchFields( const KABC::Field::List &fields )
+{
+ mIncSearchWidget->setFields( fields );
+}
+
+void KABCore::incrementalSearch( const QString& text )
+{
+ mViewManager->setSelected( QString::null, false );
+
+ if ( !text.isEmpty() ) {
+ KABC::Field *field = mIncSearchWidget->currentField();
+
+ QString pattern = text.lower();
+
+#if KDE_VERSION >= 319
+ KABC::AddresseeList list( mAddressBook->allAddressees() );
+ if ( field ) {
+ list.sortByField( field );
+ KABC::AddresseeList::Iterator it;
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ if ( field->value( *it ).lower().startsWith( pattern ) ) {
+ mViewManager->setSelected( (*it).uid(), true );
+ return;
+ }
+ }
+ } else {
+ KABC::AddresseeList::Iterator it;
+ for ( it = list.begin(); it != list.end(); ++it ) {
+ KABC::Field::List fieldList = mIncSearchWidget->fields();
+ KABC::Field::List::ConstIterator fieldIt;
+ for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
+ if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) {
+ mViewManager->setSelected( (*it).uid(), true );
+ return;
+ }
+ }
+ }
+ }
+#else
+ KABC::AddressBook::Iterator it;
+ for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
+ if ( field ) {
+ if ( field->value( *it ).lower().startsWith( pattern ) ) {
+ mViewManager->setSelected( (*it).uid(), true );
+ return;
+ }
+ } else {
+ KABC::Field::List fieldList = mIncSearchWidget->fields();
+ KABC::Field::List::ConstIterator fieldIt;
+ for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
+ if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) {
+ mViewManager->setSelected( (*it).uid(), true );
+ return;
+ }
+ }
+ }
+ }
+#endif
+ }
+}
+
+void KABCore::setModified()
+{
+ setModified( true );
+}
+
+void KABCore::setModifiedWOrefresh()
+{
+ // qDebug("KABCore::setModifiedWOrefresh() ");
+ mModified = true;
+ mActionSave->setEnabled( mModified );
+#ifdef DESKTOP_VERSION
+ mDetails->refreshView();
+#endif
+
+}
+void KABCore::setModified( bool modified )
+{
+ mModified = modified;
+ mActionSave->setEnabled( mModified );
+
+ if ( modified )
+ mJumpButtonBar->recreateButtons();
+
+ mViewManager->refreshView();
+ mDetails->refreshView();
+
+}
+
+bool KABCore::modified() const
+{
+ return mModified;
+}
+
+void KABCore::contactModified( const KABC::Addressee &addr )
+{
+
+ Command *command = 0;
+ QString uid;
+
+ // check if it exists already
+ KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() );
+ if ( origAddr.isEmpty() )
+ command = new PwNewCommand( mAddressBook, addr );
+ else {
+ command = new PwEditCommand( mAddressBook, origAddr, addr );
+ uid = addr.uid();
+ }
+
+ UndoStack::instance()->push( command );
+ RedoStack::instance()->clear();
+
+ setModified( true );
+}
+
+void KABCore::newContact()
+{
+ AddresseeEditorDialog *dialog = 0;
+
+ QPtrList<KABC::Resource> kabcResources = mAddressBook->resources();
+
+ QPtrList<KRES::Resource> kresResources;
+ QPtrListIterator<KABC::Resource> it( kabcResources );
+ KABC::Resource *resource;
+ while ( ( resource = it.current() ) != 0 ) {
+ ++it;
+ if ( !resource->readOnly() ) {
+ KRES::Resource *res = static_cast<KRES::Resource*>( resource );
+ if ( res )
+ kresResources.append( res );
+ }
+ }
+
+ KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this );
+ resource = static_cast<KABC::Resource*>( res );
+
+ if ( resource ) {
+ KABC::Addressee addr;
+ addr.setResource( resource );
+ dialog = createAddresseeEditorDialog( this );
+ dialog->setAddressee( addr );
+
+ } else
+ return;
+
+ mEditorDict.insert( dialog->addressee().uid(), dialog );
+
+ dialog->show();
+
+}
+
+void KABCore::addEmail( QString aStr )
+{
+#ifndef KAB_EMBEDDED
+ QString fullName, email;
+
+ KABC::Addressee::parseEmailAddress( aStr, fullName, email );
+
+ // Try to lookup the addressee matching the email address
+ bool found = false;
+ QStringList emailList;
+ KABC::AddressBook::Iterator it;
+ for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) {
+ emailList = (*it).emails();
+ if ( emailList.contains( email ) > 0 ) {
+ found = true;
+ (*it).setNameFromString( fullName );
+ editContact( (*it).uid() );
+ }
+ }
+
+ if ( !found ) {
+ KABC::Addressee addr;
+ addr.setNameFromString( fullName );
+ addr.insertEmail( email, true );
+
+ mAddressBook->insertAddressee( addr );
+ mViewManager->refreshView( addr.uid() );
+ editContact( addr.uid() );
+ }
+#else //KAB_EMBEDDED
+ qDebug("KABCore::addEmail finsih method");
+#endif //KAB_EMBEDDED
+}
+
+void KABCore::importVCard( const KURL &url, bool showPreview )
+{
+ mXXPortManager->importVCard( url, showPreview );
+}
+
+void KABCore::importVCard( const QString &vCard, bool showPreview )
+{
+ mXXPortManager->importVCard( vCard, showPreview );
+}
+
+//US added a second method without defaultparameter
+void KABCore::editContact2() {
+ editContact( QString::null );
+}
+
+void KABCore::editContact( const QString &uid )
+{
+
+ if ( mExtensionManager->isQuickEditVisible() )
+ return;
+
+ // First, locate the contact entry
+ QString localUID = uid;
+ if ( localUID.isNull() ) {
+ QStringList uidList = mViewManager->selectedUids();
+ if ( uidList.count() > 0 )
+ localUID = *( uidList.at( 0 ) );
+ }
+
+ KABC::Addressee addr = mAddressBook->findByUid( localUID );
+ if ( !addr.isEmpty() ) {
+ AddresseeEditorDialog *dialog = mEditorDict.find( addr.uid() );
+ if ( !dialog ) {
+ dialog = createAddresseeEditorDialog( this );
+
+ mEditorDict.insert( addr.uid(), dialog );
+
+ dialog->setAddressee( addr );
+ }
+
+ dialog->raise();
+ dialog->show();
+ }
+}
+
+void KABCore::save()
+{
+ if ( !mModified )
+ return;
+ QString text = i18n( "There was an error while attempting to save\n the "
+ "address book. Please check that some \nother application is "
+ "not using it. " );
+ statusMessage(i18n("Saving addressbook ... "));
+#ifndef KAB_EMBEDDED
+ KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
+ if ( !b || !b->save() ) {
+ KMessageBox::error( this, text, i18n( "Unable to Save" ) );
+ }
+#else //KAB_EMBEDDED
+ KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
+ if ( !b || !b->save() ) {
+ QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
+ }
+#endif //KAB_EMBEDDED
+
+ statusMessage(i18n("Addressbook saved!"));
+ setModified( false );
+}
+
+void KABCore::statusMessage(QString mess , int time )
+{
+ //topLevelWidget()->setCaption( mess );
+ // pending setting timer to revome message
+}
+void KABCore::undo()
+{
+ UndoStack::instance()->undo();
+
+ // Refresh the view
+ mViewManager->refreshView();
+}
+
+void KABCore::redo()
+{
+ RedoStack::instance()->redo();
+
+ // Refresh the view
+ mViewManager->refreshView();
+}
+
+void KABCore::setJumpButtonBarVisible( bool visible )
+{
+ if ( visible )
+ mJumpButtonBar->show();
+ else
+ mJumpButtonBar->hide();
+}
+void KABCore::setDetailsToState()
+{
+ setDetailsVisible( mActionDetails->isChecked() );
+}
+
+void KABCore::setDetailsVisible( bool visible )
+{
+ if ( visible )
+ mDetails->show();
+ else
+ mDetails->hide();
+}
+
+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
+ setModifiedWOrefresh();
+ }
+ if ( list.count() == 0 )
+ mViewManager->refreshView();
+ else
+ mViewManager->refreshView( list[ 0 ].uid() );
+
+
+
+}
+
+QString KABCore::getNameByPhone( const QString &phone )
+{
+#ifndef KAB_EMBEDDED
+ QRegExp r( "[/*/-/ ]" );
+ QString localPhone( phone );
+
+ bool found = false;
+ QString ownerName = "";
+ KABC::AddressBook::Iterator iter;
+ KABC::PhoneNumber::List::Iterator phoneIter;
+ KABC::PhoneNumber::List phoneList;
+ for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) {
+ phoneList = (*iter).phoneNumbers();
+ for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() );
+ ++phoneIter) {
+ // Get rid of separator chars so just the numbers are compared.
+ if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) {
+ ownerName = (*iter).formattedName();
+ found = true;
+ }
+ }
+ }
+
+ return ownerName;
+#else //KAB_EMBEDDED
+ qDebug("KABCore::getNameByPhone finsih method");
+ return "";
+#endif //KAB_EMBEDDED
+
+}
+
+void KABCore::openConfigDialog()
+{
+ KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true );
+ KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" );
+ ConfigureDialog->addModule(kabcfg );
+ connect( ConfigureDialog, SIGNAL( applyClicked() ),
+ this, SLOT( configurationChanged() ) );
+ connect( ConfigureDialog, SIGNAL( okClicked() ),
+ this, SLOT( configurationChanged() ) );
+ saveSettings();
+ ConfigureDialog->exec();
+ delete ConfigureDialog;
+}
+
+void KABCore::openLDAPDialog()
+{
+#ifndef KAB_EMBEDDED
+ if ( !mLdapSearchDialog ) {
+ mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this );
+ connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager,
+ SLOT( refreshView() ) );
+ connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this,
+ SLOT( setModified() ) );
+ } else
+ mLdapSearchDialog->restoreSettings();
+
+ if ( mLdapSearchDialog->isOK() )
+ mLdapSearchDialog->exec();
+#else //KAB_EMBEDDED
+ qDebug("KABCore::openLDAPDialog() finsih method");
+#endif //KAB_EMBEDDED
+}
+
+void KABCore::print()
+{
+#ifndef KAB_EMBEDDED
+ KPrinter printer;
+ if ( !printer.setup( this ) )
+ return;
+
+ KABPrinting::PrintingWizard wizard( &printer, mAddressBook,
+ mViewManager->selectedUids(), this );
+
+ wizard.exec();
+#else //KAB_EMBEDDED
+ qDebug("KABCore::print() finsih method");
+#endif //KAB_EMBEDDED
+
+}
+
+
+void KABCore::addGUIClient( KXMLGUIClient *client )
+{
+ if ( mGUIClient )
+ mGUIClient->insertChildClient( client );
+ else
+ KMessageBox::error( this, "no KXMLGUICLient");
+}
+
+
+void KABCore::configurationChanged()
+{
+ mExtensionManager->reconfigure();
+}
+
+void KABCore::addressBookChanged()
+{
+#ifndef KAB_EMBEDDED
+ QDictIterator<AddresseeEditorDialog> it( mEditorDict );
+ while ( it.current() ) {
+ if ( it.current()->dirty() ) {
+ QString text = i18n( "Data has been changed externally. Unsaved "
+ "changes will be lost." );
+ KMessageBox::information( this, text );
+ }
+ it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) );
+ ++it;
+ }
+
+ mViewManager->refreshView();
+#else //KAB_EMBEDDED
+ qDebug("KABCore::addressBookChanged() finsih method");
+#endif //KAB_EMBEDDED
+}
+
+AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent,
+ const char *name )
+{
+ AddresseeEditorDialog *dialog = new AddresseeEditorDialog( this, parent,
+ name ? name : "editorDialog" );
+
+//US
+ dialog->setMaximumSize( 640, 480 );
+ dialog->showMaximized();
+
+ connect( dialog, SIGNAL( contactModified( const KABC::Addressee& ) ),
+ SLOT( contactModified( const KABC::Addressee& ) ) );
+ connect( dialog, SIGNAL( editorDestroyed( const QString& ) ),
+ SLOT( slotEditorDestroyed( const QString& ) ) );
+
+ return dialog;
+}
+
+void KABCore::slotEditorDestroyed( const QString &uid )
+{
+ mEditorDict.remove( uid );
+}
+
+void KABCore::initGUI()
+{
+#ifndef KAB_EMBEDDED
+ QHBoxLayout *topLayout = new QHBoxLayout( this );
+ topLayout->setSpacing( KDialogBase::spacingHint() );
+
+ mExtensionBarSplitter = new QSplitter( this );
+ mExtensionBarSplitter->setOrientation( Qt::Vertical );
+
+ mDetailsSplitter = new QSplitter( mExtensionBarSplitter );
+
+ QVBox *viewSpace = new QVBox( mDetailsSplitter );
+ mIncSearchWidget = new IncSearchWidget( viewSpace );
+ connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
+ SLOT( incrementalSearch( const QString& ) ) );
+
+ mViewManager = new ViewManager( this, viewSpace );
+ viewSpace->setStretchFactor( mViewManager, 1 );
+
+ mDetails = new ViewContainer( mDetailsSplitter );
+
+ mJumpButtonBar = new JumpButtonBar( this, this );
+
+ mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
+
+ topLayout->addWidget( mExtensionBarSplitter );
+ topLayout->setStretchFactor( mExtensionBarSplitter, 100 );
+ topLayout->addWidget( mJumpButtonBar );
+ topLayout->setStretchFactor( mJumpButtonBar, 1 );
+
+ mXXPortManager = new XXPortManager( this, this );
+
+#else //KAB_EMBEDDED
+ //US initialize viewMenu before settingup viewmanager.
+ // Viewmanager needs this menu to plugin submenues.
+ viewMenu = new QPopupMenu( this );
+ settingsMenu = new QPopupMenu( this );
+ //filterMenu = new QPopupMenu( this );
+ ImportMenu = new QPopupMenu( this );
+ ExportMenu = new QPopupMenu( this );
+
+
+//US since we have no splitter for the embedded system, setup
+// a layout with two frames. One left and one right.
+
+ QBoxLayout *topLayout;
+
+ // = new QHBoxLayout( this );
+// QBoxLayout *topLayout = (QBoxLayout*)layout();
+
+// QWidget *mainBox = new QWidget( this );
+// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox);
+
+
+ if ( QApplication::desktop()->width() > 480 ) {
+ topLayout = new QHBoxLayout( this );
+ mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
+ mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
+ } else {
+
+ topLayout = new QVBoxLayout( this );
+ 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 );
+
+ //eh->hide();
+ // topLayout->addWidget(mExtensionManager );
+
+
+/*US
+#ifndef KAB_NOSPLITTER
+ QHBoxLayout *topLayout = new QHBoxLayout( this );
+//US topLayout->setSpacing( KDialogBase::spacingHint() );
+ topLayout->setSpacing( 10 );
+
+ mDetailsSplitter = new QSplitter( this );
+
+ QVBox *viewSpace = new QVBox( mDetailsSplitter );
+
+ mViewManager = new ViewManager( this, viewSpace );
+ viewSpace->setStretchFactor( mViewManager, 1 );
+
+ mDetails = new ViewContainer( mDetailsSplitter );
+
+ topLayout->addWidget( mDetailsSplitter );
+ topLayout->setStretchFactor( mDetailsSplitter, 100 );
+#else //KAB_NOSPLITTER
+ QHBoxLayout *topLayout = new QHBoxLayout( this );
+//US topLayout->setSpacing( KDialogBase::spacingHint() );
+ topLayout->setSpacing( 10 );
+
+// mDetailsSplitter = new QSplitter( this );
+
+ QVBox *viewSpace = new QVBox( this );
+
+ mViewManager = new ViewManager( this, viewSpace );
+ viewSpace->setStretchFactor( mViewManager, 1 );
+
+ mDetails = new ViewContainer( this );
+
+ topLayout->addWidget( viewSpace );
+// topLayout->setStretchFactor( mDetailsSplitter, 100 );
+ topLayout->addWidget( mDetails );
+#endif //KAB_NOSPLITTER
+*/
+
+
+#endif //KAB_EMBEDDED
+ initActions();
+
+#ifdef KAB_EMBEDDED
+ addActionsManually();
+ //US make sure the export and import menues are initialized before creating the xxPortManager.
+ mXXPortManager = new XXPortManager( this, this );
+
+ // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() );
+ //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget);
+ // mActionQuit->plug ( mMainWindow->toolBar());
+ //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() );
+ //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget);
+ // mIncSearchWidget->hide();
+ 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,
+ SLOT( sendMail() ), actionCollection(),
+ "kaddressbook_mail" );
+ mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this,
+ SLOT( print() ), actionCollection(), "kaddressbook_print" );
+
+ } else {
+ 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");
+
+ mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0,
+ this, SLOT( editContact2() ),
+ actionCollection(), "file_properties" );
+
+#ifdef KAB_EMBEDDED
+ // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() );
+ mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0,
+ mMainWindow, SLOT( exit() ),
+ actionCollection(), "quit" );
+#endif //KAB_EMBEDDED
+
+ // edit menu
+ if ( mIsPart ) {
+ mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this,
+ SLOT( copyContacts() ), actionCollection(),
+ "kaddressbook_copy" );
+ mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this,
+ SLOT( cutContacts() ), actionCollection(),
+ "kaddressbook_cut" );
+ mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this,
+ SLOT( pasteContacts() ), actionCollection(),
+ "kaddressbook_paste" );
+ mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this,
+ SLOT( selectAllContacts() ), actionCollection(),
+ "kaddressbook_select_all" );
+ mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this,
+ SLOT( undo() ), actionCollection(),
+ "kaddressbook_undo" );
+ mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z,
+ this, SLOT( redo() ), actionCollection(),
+ "kaddressbook_redo" );
+ } else {
+ mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() );
+ mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() );
+ mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() );
+ mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() );
+ mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() );
+ mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() );
+ }
+
+ mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete",
+ Key_Delete, this, SLOT( deleteContacts() ),
+ actionCollection(), "edit_delete" );
+
+ mActionUndo->setEnabled( false );
+ mActionRedo->setEnabled( false );
+
+ // settings menu
+#ifdef KAB_EMBEDDED
+//US special menuentry to configure the addressbook resources. On KDE
+// you do that through the control center !!!
+ mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this,
+ 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" );
+#ifdef KAB_EMBEDDED
+ mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() );
+#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
+ if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) {
+ new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0,
+ this, SLOT( openLDAPDialog() ), actionCollection(),
+ "ldap_lookup" );
+ }
+#else //KAB_EMBEDDED
+ //qDebug("KABCore::initActions() LDAP has to be implemented");
+#endif //KAB_EMBEDDED
+
+
+ mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this,
+ SLOT( setWhoAmI() ), actionCollection(),
+ "set_personal" );
+
+ mActionCategories = new KAction( i18n( "Set Categories" ), 0, this,
+ SLOT( setCategories() ), actionCollection(),
+ "edit_set_categories" );
+
+#ifdef KAB_EMBEDDED
+
+ mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0,
+ 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() ) );
+}
+
+//US we need this function, to plug all actions into the correct menues.
+// KDE uses a XML format to plug the actions, but we work her without this overhead.
+void KABCore::addActionsManually()
+{
+//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
+
+#ifdef KAB_EMBEDDED
+ QPopupMenu *fileMenu = new QPopupMenu( this );
+ QPopupMenu *editMenu = new QPopupMenu( this );
+ QPopupMenu *helpMenu = new QPopupMenu( this );
+
+ KToolBar* tb = mMainWindow->toolBar();
+
+#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 );
+ mb->insertItem( "&Edit", editMenu );
+ mb->insertItem( "&View", viewMenu );
+ mb->insertItem( "&Settings", settingsMenu );
+ mb->insertItem( "&Help", helpMenu );
+ mIncSearchWidget = new IncSearchWidget( tb );
+ // tb->insertWidget(-1, 0, mIncSearchWidget);
+
+#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 );
+ popupBarTB->insertItem( "&View", viewMenu );
+ popupBarTB->insertItem( "&Settings", settingsMenu );
+ mViewManager->getFilterAction()->plug ( popupBarTB);
+ popupBarTB->insertItem( "&Help", helpMenu );
+ if (QApplication::desktop()->width() > 320 ) {
+ // mViewManager->getFilterAction()->plug ( tb);
+ }
+#endif
+ // mActionQuit->plug ( mMainWindow->toolBar());
+
+
+
+ //US Now connect the actions with the menue entries.
+ mActionPrint->plug( fileMenu );
+ mActionMail->plug( fileMenu );
+ fileMenu->insertSeparator();
+
+ mActionNewContact->plug( fileMenu );
+ mActionNewContact->plug( tb );
+
+ mActionEditAddressee->plug( fileMenu );
+ fileMenu->insertSeparator();
+ mActionSave->plug( fileMenu );
+ fileMenu->insertItem( "&Import", ImportMenu );
+ fileMenu->insertItem( "&Emport", ExportMenu );
+ fileMenu->insertSeparator();
+ mActionMailVCard->plug( fileMenu );
+ fileMenu->insertSeparator();
+ mActionQuit->plug( fileMenu );
+
+
+ // edit menu
+ mActionUndo->plug( editMenu );
+ mActionRedo->plug( editMenu );
+ editMenu->insertSeparator();
+ mActionCut->plug( editMenu );
+ mActionCopy->plug( editMenu );
+ mActionPaste->plug( editMenu );
+ mActionDelete->plug( editMenu );
+ editMenu->insertSeparator();
+ mActionSelectAll->plug( editMenu );
+
+
+ // settings menu
+//US special menuentry to configure the addressbook resources. On KDE
+// you do that through the control center !!!
+ mActionConfigResources->plug( settingsMenu );
+ 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);
+ if (QApplication::desktop()->width() > 480 )
+ mActionDelete->plug( tb );
+ }
+ 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
+ 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::clipboardDataChanged()
+{
+
+ if ( mReadWrite )
+ mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
+
+}
+
+void KABCore::updateActionMenu()
+{
+ UndoStack *undo = UndoStack::instance();
+ RedoStack *redo = RedoStack::instance();
+
+ if ( undo->isEmpty() )
+ mActionUndo->setText( i18n( "Undo" ) );
+ else
+ mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) );
+
+ mActionUndo->setEnabled( !undo->isEmpty() );
+
+ if ( !redo->top() )
+ mActionRedo->setText( i18n( "Redo" ) );
+ else
+ mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) );
+
+ mActionRedo->setEnabled( !redo->isEmpty() );
+}
+
+void KABCore::configureKeyBindings()
+{
+#ifndef KAB_EMBEDDED
+ KKeyDialog::configure( actionCollection(), true );
+#else //KAB_EMBEDDED
+ qDebug("KABCore::configureKeyBindings() not implemented");
+#endif //KAB_EMBEDDED
+}
+
+#ifdef KAB_EMBEDDED
+void KABCore::configureResources()
+{
+ KRES::KCMKResources dlg( this, "" , 0 );
+
+ if ( !dlg.exec() )
+ return;
+}
+#endif //KAB_EMBEDDED
+
+
+
+#ifndef KAB_EMBEDDED
+#include "kabcore.moc"
+#endif //KAB_EMBEDDED