• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kontact

kaddressbook_plugin.cpp

Go to the documentation of this file.
00001 /*
00002   This file is part of Kontact.
00003 
00004   Copyright (c) 2001 Matthias Hoelzer-Kluepfel <mhk@kde.org>
00005 
00006   This program is free software; you can redistribute it and/or modify
00007   it under the terms of the GNU General Public License as published by
00008   the Free Software Foundation; either version 2 of the License, or
00009   (at your option) any later version.
00010 
00011   This program is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014   GNU General Public License for more details.
00015 
00016   You should have received a copy of the GNU General Public License
00017   along with this program; if not, write to the Free Software
00018   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020   As a special exception, permission is given to link this program
00021   with any edition of Qt, and distribute the resulting executable,
00022   without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include "kaddressbook_plugin.h"
00026 #include "coreinterface.h"
00027 #include "kmailinterface.h"
00028 
00029 #include <kaddrbookexternal.h>
00030 
00031 #include <kontactinterfaces/core.h>
00032 #include <kontactinterfaces/plugin.h>
00033 #include <libkdepim/maillistdrag.h>
00034 
00035 #include <kabc/addressbook.h>
00036 #include <kabc/stdaddressbook.h>
00037 
00038 #include <kaction.h>
00039 #include <kactioncollection.h>
00040 #include <kdebug.h>
00041 #include <kgenericfactory.h>
00042 #include <kicon.h>
00043 #include <kiconloader.h>
00044 #include <kmessagebox.h>
00045 #include <kparts/componentfactory.h>
00046 
00047 #include <QDropEvent>
00048 
00049 EXPORT_KONTACT_PLUGIN( KAddressbookPlugin, kaddressbook )
00050 
00051 KAddressbookPlugin::KAddressbookPlugin( Kontact::Core *core, const QVariantList & )
00052   : Kontact::Plugin( core, core, "kaddressbook" ),
00053     m_interface( 0 )
00054 {
00055   setComponentData( KontactPluginFactory::componentData() );
00056 
00057   KAction *action  = new KAction( KIcon( "contact-new" ),
00058                                   i18n( "New Contact..." ), this );
00059   actionCollection()->addAction( "new_contact", action );
00060   connect( action, SIGNAL(triggered(bool)), SLOT(slotNewContact()) );
00061   action->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_C ) );
00062   insertNewAction( action );
00063 
00064   action = new KAction( KIcon( "view-pim-contacts" ),
00065                         i18n( "New Distribution List..." ), this );
00066   actionCollection()->addAction( "new_distributionlist", action );
00067   connect( action, SIGNAL(triggered(bool)), SLOT(slotNewDistributionList()) );
00068   insertNewAction( action );
00069 
00070   KAction *syncAction = new KAction( KIcon( "view-refresh" ),
00071                                      i18n( "Synchronize Contacts" ), this );
00072   actionCollection()->addAction( "kaddressbook_sync", syncAction );
00073   connect( action, SIGNAL(triggered(bool)), SLOT(slotSyncContacts()) );
00074 
00075   mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
00076     new Kontact::UniqueAppHandlerFactory<KABUniqueAppHandler>(), this );
00077 }
00078 
00079 KAddressbookPlugin::~KAddressbookPlugin()
00080 {
00081 }
00082 
00083 QString KAddressbookPlugin::tipFile() const
00084 {
00085   // TODO: tips file
00086   //QString file = KStandardDirs::locate("data", "kaddressbook/tips");
00087   QString file;
00088   return file;
00089 }
00090 
00091 KParts::ReadOnlyPart *KAddressbookPlugin::createPart()
00092 {
00093   KParts::ReadOnlyPart *part = loadPart();
00094   if ( !part ) {
00095     return 0;
00096   }
00097 
00098   // Create the stub that allows us to talk to the part
00099   m_interface = new OrgKdeKAddressbookCoreInterface(
00100     "org.kde.kaddressbook", "/KAddressBook", QDBusConnection::sessionBus() );
00101   return part;
00102 }
00103 
00104 QStringList KAddressbookPlugin::configModules() const
00105 {
00106   QStringList modules;
00107   modules << "PIM/kabconfig.desktop" << "PIM/kabldapconfig.desktop";
00108   return modules;
00109 }
00110 
00111 QStringList KAddressbookPlugin::invisibleToolbarActions() const
00112 {
00113   return QStringList( "file_new_contact" );
00114 }
00115 
00116 OrgKdeKAddressbookCoreInterface *KAddressbookPlugin::interface()
00117 {
00118   if ( !m_interface ) {
00119     part();
00120   }
00121   Q_ASSERT( m_interface );
00122   return m_interface;
00123 }
00124 
00125 void KAddressbookPlugin::slotNewContact()
00126 {
00127   interface()->newContact();
00128 }
00129 
00130 void KAddressbookPlugin::slotNewDistributionList()
00131 {
00132   interface()->newDistributionList();
00133 }
00134 
00135 void KAddressbookPlugin::slotSyncContacts()
00136 {
00137   QDBusMessage message =
00138       QDBusMessage::createMethodCall( "org.kde.kmail", "/Groupware",
00139                                       "org.kde.kmail.groupware",
00140                                       "triggerSync" );
00141   message << QString( "Contact" );
00142   QDBusConnection::sessionBus().send( message );
00143 }
00144 
00145 bool KAddressbookPlugin::createDBUSInterface( const QString &serviceType )
00146 {
00147   if ( serviceType == "DBUS/AddressBook" )  {
00148     Q_ASSERT( m_interface );
00149     return true;
00150   }
00151   return false;
00152 }
00153 
00154 void KAddressbookPlugin::configUpdated()
00155 {
00156 }
00157 
00158 bool KAddressbookPlugin::isRunningStandalone()
00159 {
00160   return mUniqueAppWatcher->isRunningStandalone();
00161 }
00162 
00163 bool KAddressbookPlugin::canDecodeMimeData( const QMimeData * mimeData )
00164 {
00165   return KPIM::MailList::canDecode( mimeData );
00166 }
00167 
00168 void KAddressbookPlugin::processDropEvent( QDropEvent *event )
00169 {
00170   const QMimeData *md = event->mimeData();
00171   if ( KPIM::MailList::canDecode( md ) ) {
00172     event->accept();
00173     KPIM::MailList mails = KPIM::MailList::fromMimeData( md );
00174     if ( mails.count() != 1 ) {
00175       KMessageBox::sorry( core(),
00176                           i18n( "Dropping multiple mails is not supported." ) );
00177     } else {
00178       KPIM::MailSummary mail = mails.first();
00179       org::kde::kmail::kmail kmail(
00180         "org.kde.kmail", "/KMail", QDBusConnection::sessionBus() );
00181       QString sFrom = kmail.getFrom( mail.serialNumber() );
00182       if ( !sFrom.isEmpty() ) {
00183         KPIM::KAddrBookExternal::addEmail( sFrom, core() );
00184       }
00185     }
00186     return;
00187   }
00188 
00189   kWarning() << QString( "Cannot handle drop events of type '%1'." ).arg( event->format() );
00190 }
00191 
00193 
00194 #include "../../../kaddressbook/kaddressbook_options.h"
00195 
00196 void KABUniqueAppHandler::loadCommandLineOptions()
00197 {
00198     KCmdLineArgs::addCmdLineOptions( kaddressbook_options() );
00199 }
00200 
00201 int KABUniqueAppHandler::newInstance()
00202 {
00203     kDebug() ;
00204     // Ensure part is loaded
00205     (void)plugin()->part();
00206 
00207     org::kde::KAddressbook::Core kaddressbook(
00208       "org.kde.kaddressbook", "/KAddressBook", QDBusConnection::sessionBus() );
00209     QDBusReply<bool> reply = kaddressbook.handleCommandLine();
00210     if ( reply.isValid() ) {
00211         bool handled = reply;
00212         kDebug() << "handled=" << handled;
00213         if ( !handled ) { // no args -> simply bring kaddressbook plugin to front
00214           return Kontact::UniqueAppHandler::newInstance();
00215         }
00216     }
00217 
00218     return 0;
00219 }
00220 
00221 #include "kaddressbook_plugin.moc"
00222 
00223 // vim: sw=2 sts=2 tw=80 et

kontact

Skip menu "kontact"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal