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

kontact

kmail_plugin.cpp

Go to the documentation of this file.
00001 /*
00002   This file is part of Kontact.
00003 
00004   Copyright (c) 2003 Kontact Developer <kde-pim@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 along
00017   with this program; if not, write to the Free Software Foundation, Inc.,
00018   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 "kmail_plugin.h"
00026 #include "summarywidget.h"
00027 #include "kmailinterface.h"
00028 
00029 #include <kmail/kmail_part.h>
00030 #include <kmail/kmkernel.h>
00031 
00032 #include <libkdepim/kvcarddrag.h>
00033 #include <kontactinterfaces/core.h>
00034 
00035 #include <kabc/addressee.h>
00036 #include <kcal/vcaldrag.h>
00037 #include <kcal/icaldrag.h>
00038 #include <kcal/calendarlocal.h>
00039 
00040 #include <kaction.h>
00041 #include <kactioncollection.h>
00042 #include <kdebug.h>
00043 #include <kgenericfactory.h>
00044 #include <kicon.h>
00045 #include <kiconloader.h>
00046 #include <kstandarddirs.h>
00047 #include <ktemporaryfile.h>
00048 #include <kparts/componentfactory.h>
00049 
00050 #include <QWidget>
00051 #include <QDropEvent>
00052 
00053 using namespace KCal;
00054 using namespace KPIM;
00055 
00056 EXPORT_KONTACT_PLUGIN( KMailPlugin, kmail )
00057 
00058 KMailPlugin::KMailPlugin( Kontact::Core *core, const QVariantList & )
00059   : Kontact::Plugin( core, core, "kmail" ), m_instance( 0 )
00060 {
00061   setComponentData( KontactPluginFactory::componentData() );
00062 
00063   KAction *action  = new KAction( KIcon( "mail-message-new" ), i18n( "New Message..." ), this );
00064   actionCollection()->addAction( "new_mail", action );
00065   action->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_M ) );
00066   connect( action, SIGNAL(triggered(bool)), SLOT(slotNewMail()) );
00067   insertNewAction( action );
00068 
00069   KAction *syncAction = new KAction( KIcon( "view-refresh" ), i18n( "Synchronize Mail" ), this );
00070   connect( syncAction, SIGNAL(triggered(bool)), SLOT(slotSyncFolders()) );
00071   actionCollection()->addAction( "sync_mail", syncAction );
00072   insertSyncAction( syncAction );
00073 
00074   mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
00075       new Kontact::UniqueAppHandlerFactory<KMailUniqueAppHandler>(), this );
00076 }
00077 
00078 bool KMailPlugin::canDecodeMimeData( const QMimeData *mimeData )
00079 {
00080   return ( ICalDrag::canDecode( mimeData ) ||
00081            VCalDrag::canDecode( mimeData ) ||
00082            KVCardDrag::canDecode( mimeData ) );
00083 }
00084 
00085 void KMailPlugin::processDropEvent( QDropEvent *de )
00086 {
00087   kDebug();
00088   CalendarLocal cal( QString::fromLatin1( "UTC" ) );
00089   KABC::Addressee::List list;
00090   const QMimeData *md = de->mimeData();
00091 
00092   if ( VCalDrag::fromMimeData( md, &cal ) || ICalDrag::fromMimeData( md, &cal ) ) {
00093     KTemporaryFile tmp;
00094     tmp.setPrefix( "incidences-" );
00095     tmp.setSuffix( ".ics" );
00096     tmp.setAutoRemove( false );
00097     tmp.open();
00098     cal.save( tmp.fileName() );
00099     openComposer( KUrl( tmp.fileName() ) );
00100   } else if ( KVCardDrag::fromMimeData( md, list ) ) {
00101     KABC::Addressee::List::Iterator it;
00102     QStringList to;
00103     for ( it = list.begin(); it != list.end(); ++it ) {
00104       to.append( ( *it ).fullEmail() );
00105     }
00106     openComposer( to.join( ", " ) );
00107   }
00108 
00109   kWarning() << QString( "Cannot handle drop events of type '%1'." ).arg( de->format() );
00110 }
00111 
00112 void KMailPlugin::openComposer( const KUrl &attach )
00113 {
00114   (void) part(); // ensure part is loaded
00115   Q_ASSERT( m_instance );
00116   if ( m_instance ) {
00117     if ( attach.isValid() ) {
00118       m_instance->newMessage( "", "", "", false, true, QString(), attach.path() );
00119     } else {
00120       m_instance->newMessage( "", "", "", false, true, QString(), QString() );
00121     }
00122   }
00123 }
00124 
00125 void KMailPlugin::openComposer( const QString &to )
00126 {
00127   (void) part(); // ensure part is loaded
00128   Q_ASSERT( m_instance );
00129   if ( m_instance ) {
00130     m_instance->newMessage( to, "", "", false, true, QString(), QString() );
00131   }
00132 }
00133 
00134 void KMailPlugin::slotNewMail()
00135 {
00136   openComposer( QString::null );    //krazy:exclude=nullstrassign for old broken gcc
00137 }
00138 
00139 void KMailPlugin::slotSyncFolders()
00140 {
00141   QDBusMessage message =
00142       QDBusMessage::createMethodCall( "org.kde.kmail", "/Groupware",
00143                                       "org.kde.kmail.groupware",
00144                                       "triggerSync" );
00145   message << QString( "Mail" );
00146   QDBusConnection::sessionBus().send( message );
00147 }
00148 
00149 KMailPlugin::~KMailPlugin()
00150 {
00151 }
00152 
00153 bool KMailPlugin::createDBUSInterface( const QString &serviceType )
00154 {
00155   if ( serviceType == "DBUS/ResourceBackend/IMAP" ) {
00156     if ( part() ) {
00157       return true;
00158     }
00159   }
00160   return false;
00161 }
00162 
00163 QString KMailPlugin::tipFile() const
00164 {
00165   QString file = KStandardDirs::locate( "data", "kmail/tips" );
00166   return file;
00167 }
00168 
00169 KParts::ReadOnlyPart *KMailPlugin::createPart()
00170 {
00171   KParts::ReadOnlyPart *part = loadPart();
00172   if ( !part ) {
00173     return 0;
00174   }
00175 
00176   m_instance = new OrgKdeKmailKmailInterface(
00177     "org.kde.kmail", "/KMail", QDBusConnection::sessionBus() );
00178 
00179   return part;
00180 }
00181 
00182 QStringList KMailPlugin::invisibleToolbarActions() const
00183 {
00184   return QStringList( "new_message" );
00185 }
00186 
00187 bool KMailPlugin::isRunningStandalone()
00188 {
00189   return mUniqueAppWatcher->isRunningStandalone();
00190 }
00191 
00192 Kontact::Summary *KMailPlugin::createSummaryWidget( QWidget *parent )
00193 {
00194   return new SummaryWidget( this, parent );
00195 }
00196 
00198 
00199 #include "../../../kmail/kmail_options.h"
00200 void KMailUniqueAppHandler::loadCommandLineOptions()
00201 {
00202     KCmdLineArgs::addCmdLineOptions( kmail_options() );
00203 }
00204 
00205 int KMailUniqueAppHandler::newInstance()
00206 {
00207     kDebug();
00208     // Ensure part is loaded
00209     (void)plugin()->part();
00210     org::kde::kmail::kmail kmail( "org.kde.kmail", "/KMail", QDBusConnection::sessionBus() );
00211     QDBusReply<bool> reply = kmail.handleCommandLine( false );
00212 
00213     if ( reply.isValid() ) {
00214       bool handled = reply;
00215       kDebug() << "handled=" << handled;
00216       if ( !handled ) { // no args -> simply bring kmail plugin to front
00217         return Kontact::UniqueAppHandler::newInstance();
00218       }
00219     }
00220     return 0;
00221 }
00222 
00223 bool KMailPlugin::queryClose() const
00224 {
00225   org::kde::kmail::kmail kmail( "org.kde.kmail", "/KMail", QDBusConnection::sessionBus() );
00226   QDBusReply<bool> canClose = kmail.canQueryClose();
00227   return canClose;
00228 }
00229 
00230 #include "kmail_plugin.moc"

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