kontact Library API Documentation

kaddressbook_plugin.cpp

00001 /*
00002     This file is part of Kontact.
00003     Copyright (c) 2003 Kontact Developer
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #include <qwidget.h>
00025 #include <qdragobject.h>
00026 
00027 #include <kaction.h>
00028 #include <kapplication.h>
00029 #include <kdebug.h>
00030 #include <kgenericfactory.h>
00031 #include <kiconloader.h>
00032 #include <kmessagebox.h>
00033 #include <kparts/componentfactory.h>
00034 
00035 #include <kaddrbook.h>
00036 #include <kabc/addressbook.h>
00037 #include <kabc/stdaddressbook.h>
00038 
00039 #include <dcopclient.h>
00040 #include "kmailIface_stub.h"
00041 
00042 #include <libkdepim/maillistdrag.h>
00043 
00044 #include "core.h"
00045 #include "kabsummarywidget.h"
00046 #include "plugin.h"
00047 
00048 #include "kaddressbook_plugin.h"
00049 
00050 typedef KGenericFactory< KAddressbookPlugin, Kontact::Core > KAddressbookPluginFactory;
00051 K_EXPORT_COMPONENT_FACTORY( libkontact_kaddressbookplugin,
00052                             KAddressbookPluginFactory( "kontact_kaddressbookplugin" ) )
00053 
00054 KAddressbookPlugin::KAddressbookPlugin( Kontact::Core *core, const char *, const QStringList& )
00055   : Kontact::Plugin( core, core, "kaddressbook" ),
00056     mStub( 0 )
00057 {
00058   setInstance( KAddressbookPluginFactory::instance() );
00059 
00060   insertNewAction( new KAction( i18n( "New Contact..." ), "identity",
00061                          0, this, SLOT( slotNewContact() ), actionCollection(),
00062                    "new_contact" ) );
00063   mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
00064       new Kontact::UniqueAppHandlerFactory<KABUniqueAppHandler>(), this );
00065 }
00066 
00067 KAddressbookPlugin::~KAddressbookPlugin()
00068 {
00069 }
00070 
00071 KParts::Part* KAddressbookPlugin::createPart()
00072 {
00073   KParts::Part * part = loadPart();
00074   if ( !part ) return 0;
00075 
00076   // Create the stub that allows us to talk to the part
00077   mStub = new KAddressBookIface_stub( dcopClient(), "kaddressbook",
00078                                       "KAddressBookIface" );
00079   return part;
00080 }
00081 
00082 QStringList KAddressbookPlugin::configModules() const
00083 {
00084   QStringList modules;
00085   modules << "PIM/kabconfig.desktop" << "PIM/kabldapconfig.desktop";
00086   return modules;
00087 }
00088 
00089 QStringList KAddressbookPlugin::invisibleToolbarActions() const
00090 {
00091   return QStringList( "file_new_contact" );
00092 }
00093 
00094 KAddressBookIface_stub *KAddressbookPlugin::interface()
00095 {
00096   if ( !mStub ) {
00097     part();
00098   }
00099   Q_ASSERT( mStub );
00100   return mStub;
00101 }
00102 
00103 void KAddressbookPlugin::slotNewContact()
00104 {
00105   (void) part(); // ensure part is loaded
00106   Q_ASSERT( mStub );
00107   if ( mStub )
00108     mStub->newContact();
00109 }
00110 
00111 bool KAddressbookPlugin::createDCOPInterface( const QString& serviceType )
00112 {
00113   if ( serviceType == "DCOP/AddressBook" )  {
00114     Q_ASSERT( mStub );
00115     return true;
00116   }
00117 
00118   return false;
00119 }
00120 
00121 bool KAddressbookPlugin::isRunningStandalone()
00122 {
00123   return mUniqueAppWatcher->isRunningStandalone();
00124 }
00125 
00126 bool KAddressbookPlugin::canDecodeDrag( QMimeSource *mimeSource )
00127 {
00128   return QTextDrag::canDecode( mimeSource ) ||
00129     KPIM::MailListDrag::canDecode( mimeSource );
00130 }
00131 
00132 #include <dcopref.h>
00133 
00134 void KAddressbookPlugin::processDropEvent( QDropEvent *event )
00135 {
00136   KPIM::MailList mails;
00137   if ( KPIM::MailListDrag::decode( event, mails ) ) {
00138     if ( mails.count() != 1 ) {
00139       KMessageBox::sorry( core(),
00140                           i18n( "Drops of multiple mails are not supported." ) );
00141     } else {
00142       KPIM::MailSummary mail = mails.first();
00143 
00144       KMailIface_stub kmailIface( "kmail", "KMailIface" );
00145       QString sFrom = kmailIface.getFrom( mail.serialNumber() );
00146 
00147       if ( !sFrom.isEmpty() ) {
00148         KAddrBookExternal::addEmail( sFrom, core() );
00149       }
00150     }
00151     return;
00152   }
00153 
00154   KMessageBox::sorry( core(), i18n("Cannot handle drop events of type '%1'.")
00155                       .arg( event->format() ) );
00156 }
00157 
00158 Kontact::Summary *KAddressbookPlugin::createSummaryWidget( QWidget *parentWidget )
00159 {
00160   return new KABSummaryWidget( this, parentWidget );
00161 }
00162 
00164 
00165 #include "../../../kaddressbook/kaddressbook_options.h"
00166 
00167 void KABUniqueAppHandler::loadCommandLineOptions()
00168 {
00169     KCmdLineArgs::addCmdLineOptions( kaddressbook_options );
00170 }
00171 
00172 int KABUniqueAppHandler::newInstance()
00173 {
00174     kdDebug(5602) << k_funcinfo << endl;
00175     // Ensure part is loaded
00176     (void)plugin()->part();
00177     DCOPRef kAB( "kaddressbook", "KAddressBookIface" );
00178     DCOPReply reply = kAB.call( "handleCommandLine" );
00179     if ( reply.isValid() ) {
00180         bool handled = reply;
00181         kdDebug(5602) << k_funcinfo << "handled=" << handled << endl;
00182         if ( !handled ) // no args -> simply bring kaddressbook plugin to front
00183             return Kontact::UniqueAppHandler::newInstance();
00184     }
00185     return 0;
00186 }
00187 
00188 #include "kaddressbook_plugin.moc"
00189 
00190 // vim: sw=2 sts=2 tw=80 et
KDE Logo
This file is part of the documentation for kontact Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 23 18:22:46 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003