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

kontact

  • sources
  • kde-4.12
  • kdepim
  • kontact
  • plugins
  • kmail
kmail_plugin.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Kontact.
3 
4  Copyright (c) 2003-2013 Kontact Developer <kde-pim@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of Qt, and distribute the resulting executable,
22  without including the source code for Qt in the source distribution.
23 */
24 
25 #include "kmail_plugin.h"
26 #include "kmailinterface.h"
27 #include "summarywidget.h"
28 
29 #include <KABC/VCardDrag>
30 #include <KCalCore/MemoryCalendar>
31 #include <KCalCore/FileStorage>
32 #include <KCalUtils/ICalDrag>
33 #include <KCalUtils/VCalDrag>
34 
35 #include <KontactInterface/Core>
36 
37 #include <KAction>
38 #include <KActionCollection>
39 #include <KDebug>
40 #include <KIcon>
41 #include <KLocale>
42 #include <KStandardDirs>
43 #include <KTemporaryFile>
44 
45 #include <QDropEvent>
46 
47 using namespace KCalUtils;
48 using namespace KCalCore;
49 
50 EXPORT_KONTACT_PLUGIN( KMailPlugin, kmail )
51 
52 KMailPlugin::KMailPlugin( KontactInterface::Core *core, const QVariantList & )
53  : KontactInterface::Plugin( core, core, "kmail2" ), m_instance( 0 )
54 {
55  setComponentData( KontactPluginFactory::componentData() );
56 
57  KAction *action =
58  new KAction( KIcon( QLatin1String("mail-message-new") ),
59  i18nc( "@action:inmenu", "New Message..." ), this );
60  actionCollection()->addAction( QLatin1String("new_mail"), action );
61  action->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_M ) );
62  action->setHelpText(
63  i18nc( "@info:status", "Create a new mail message" ) );
64  action->setWhatsThis(
65  i18nc( "@info:whatsthis",
66  "You will be presented with a dialog where you can create "
67  "and send a new email message." ) );
68  connect( action, SIGNAL(triggered(bool)), SLOT(slotNewMail()) );
69  insertNewAction( action );
70 
71  KAction *syncAction =
72  new KAction( KIcon( QLatin1String("view-refresh") ),
73  i18nc( "@action:inmenu", "Sync Mail" ), this );
74  syncAction->setHelpText(
75  i18nc( "@info:status", "Synchronize groupware mail" ) );
76  syncAction->setWhatsThis(
77  i18nc( "@info:whatsthis",
78  "Choose this option to synchronize your groupware email." ) );
79  connect( syncAction, SIGNAL(triggered(bool)), SLOT(slotSyncFolders()) );
80  actionCollection()->addAction( QLatin1String("sync_mail"), syncAction );
81  insertSyncAction( syncAction );
82 
83  mUniqueAppWatcher = new KontactInterface::UniqueAppWatcher(
84  new KontactInterface::UniqueAppHandlerFactory<KMailUniqueAppHandler>(), this );
85 }
86 
87 bool KMailPlugin::canDecodeMimeData( const QMimeData *mimeData ) const
88 {
89  return
90  ICalDrag::canDecode( mimeData ) ||
91  VCalDrag::canDecode( mimeData ) ||
92  KABC::VCardDrag::canDecode( mimeData );
93 }
94 
95 void KMailPlugin::processDropEvent( QDropEvent *de )
96 {
97  MemoryCalendar::Ptr cal( new MemoryCalendar( QString::fromLatin1( "UTC" ) ) );
98  KABC::Addressee::List list;
99  const QMimeData *md = de->mimeData();
100 
101  if ( VCalDrag::fromMimeData( md, cal ) || ICalDrag::fromMimeData( md, cal ) ) {
102  KTemporaryFile tmp;
103  tmp.setPrefix( QLatin1String("incidences-") );
104  tmp.setSuffix( QLatin1String(".ics") );
105  tmp.setAutoRemove( false );
106  tmp.open();
107  FileStorage storage( cal, tmp.fileName() );
108  storage.save();
109  openComposer( KUrl( tmp.fileName() ) );
110  } else if ( KABC::VCardDrag::fromMimeData( md, list ) ) {
111  KABC::Addressee::List::ConstIterator it;
112  QStringList to;
113  KABC::Addressee::List::ConstIterator end(list.constEnd());
114  for ( it = list.constBegin(); it != end; ++it ) {
115  to.append( ( *it ).fullEmail() );
116  }
117  openComposer( to.join( QLatin1String(", ") ) );
118  }
119 
120  kWarning() << QString::fromLatin1( "Cannot handle drop events of type '%1'." ).arg( QLatin1String(de->format()) );
121 }
122 
123 void KMailPlugin::openComposer( const KUrl &attach )
124 {
125  (void) part(); // ensure part is loaded
126  Q_ASSERT( m_instance );
127  if ( m_instance ) {
128  if ( attach.isValid() ) {
129  m_instance->newMessage( QString(), QString(), QString(), false, true, QString(), attach.isLocalFile() ?
130  attach.toLocalFile() : attach.path() );
131  } else {
132  m_instance->newMessage( QString(), QString(), QString(), false, true, QString(), QString() );
133  }
134  }
135 }
136 
137 void KMailPlugin::openComposer( const QString &to )
138 {
139  (void) part(); // ensure part is loaded
140  Q_ASSERT( m_instance );
141  if ( m_instance ) {
142  m_instance->newMessage( to, QString(), QString(), false, true, QString(), QString() );
143  }
144 }
145 
146 void KMailPlugin::slotNewMail()
147 {
148  openComposer( QString::null ); //krazy:exclude=nullstrassign for old broken gcc
149 }
150 
151 void KMailPlugin::slotSyncFolders()
152 {
153  QDBusMessage message =
154  QDBusMessage::createMethodCall( QLatin1String("org.kde.kmail"), QLatin1String("/KMail"),
155  QLatin1String("org.kde.kmail.kmail"),
156  QLatin1String("checkMail" ));
157  QDBusConnection::sessionBus().send( message );
158 }
159 
160 KMailPlugin::~KMailPlugin()
161 {
162  delete m_instance;
163  m_instance = 0;
164 }
165 
166 bool KMailPlugin::createDBUSInterface( const QString &serviceType )
167 {
168  if ( serviceType == QLatin1String( "DBUS/Mailer" ) ) {
169  if ( part() ) {
170  return true;
171  }
172  }
173  return false;
174 }
175 
176 QString KMailPlugin::tipFile() const
177 {
178  const QString file = KStandardDirs::locate( "data", QLatin1String("kmail2/tips") );
179  return file;
180 }
181 
182 KParts::ReadOnlyPart *KMailPlugin::createPart()
183 {
184  KParts::ReadOnlyPart *part = loadPart();
185  if ( !part ) {
186  return 0;
187  }
188 
189  m_instance = new OrgKdeKmailKmailInterface(
190  QLatin1String("org.kde.kmail"), QLatin1String("/KMail"), QDBusConnection::sessionBus() );
191 
192  return part;
193 }
194 
195 QStringList KMailPlugin::invisibleToolbarActions() const
196 {
197  return QStringList()<<QLatin1String( "new_message" );
198 }
199 
200 bool KMailPlugin::isRunningStandalone() const
201 {
202  return mUniqueAppWatcher->isRunningStandalone();
203 }
204 
205 KontactInterface::Summary *KMailPlugin::createSummaryWidget( QWidget *parent )
206 {
207  return new SummaryWidget( this, parent );
208 }
209 
211 
212 #include "../../../kmail/kmail_options.h"
213 void KMailUniqueAppHandler::loadCommandLineOptions()
214 {
215  KCmdLineArgs::addCmdLineOptions( kmail_options() );
216 }
217 
218 int KMailUniqueAppHandler::newInstance()
219 {
220  // Ensure part is loaded
221  (void)plugin()->part();
222  org::kde::kmail::kmail kmail( QLatin1String("org.kde.kmail"), QLatin1String("/KMail"), QDBusConnection::sessionBus() );
223  QDBusReply<bool> reply = kmail.handleCommandLine( false );
224 
225  if ( reply.isValid() ) {
226  bool handled = reply;
227  if ( !handled ) { // no args -> simply bring kmail plugin to front
228  return KontactInterface::UniqueAppHandler::newInstance();
229  }
230  }
231  return 0;
232 }
233 
234 bool KMailPlugin::queryClose() const
235 {
236  org::kde::kmail::kmail kmail( QLatin1String("org.kde.kmail"), QLatin1String("/KMail"), QDBusConnection::sessionBus() );
237  QDBusReply<bool> canClose = kmail.canQueryClose();
238  return canClose;
239 }
240 
241 #include "kmail_plugin.moc"
kmail_plugin.h
KMailPlugin::queryClose
virtual bool queryClose() const
Definition: kmail_plugin.cpp:234
KMailPlugin::createPart
virtual KParts::ReadOnlyPart * createPart()
Definition: kmail_plugin.cpp:182
KMailPlugin::openComposer
void openComposer(const KUrl &attach=KUrl())
Definition: kmail_plugin.cpp:123
KMailUniqueAppHandler::loadCommandLineOptions
virtual void loadCommandLineOptions()
Definition: kmail_plugin.cpp:213
SummaryWidget
Definition: kmail/summarywidget.h:53
QWidget
summarywidget.h
KMailPlugin::slotSyncFolders
void slotSyncFolders()
Definition: kmail_plugin.cpp:151
fromMimeData
static MailList fromMimeData(const QMimeData *md)
KMailPlugin::isRunningStandalone
bool isRunningStandalone() const
Definition: kmail_plugin.cpp:200
KMailPlugin::processDropEvent
void processDropEvent(QDropEvent *)
Definition: kmail_plugin.cpp:95
KMailUniqueAppHandler::newInstance
virtual int newInstance()
Definition: kmail_plugin.cpp:218
to
QString to() const
QMimeData
canDecode
static bool canDecode(const QMimeData *md)
KMailPlugin::tipFile
QString tipFile() const
Definition: kmail_plugin.cpp:176
KMailPlugin::invisibleToolbarActions
QStringList invisibleToolbarActions() const
Definition: kmail_plugin.cpp:195
KMailPlugin::~KMailPlugin
~KMailPlugin()
Definition: kmail_plugin.cpp:160
KMailPlugin::createDBUSInterface
bool createDBUSInterface(const QString &serviceType)
Definition: kmail_plugin.cpp:166
KMailPlugin::slotNewMail
void slotNewMail()
Definition: kmail_plugin.cpp:146
KMailPlugin::canDecodeMimeData
bool canDecodeMimeData(const QMimeData *) const
Definition: kmail_plugin.cpp:87
KMailPlugin::createSummaryWidget
virtual KontactInterface::Summary * createSummaryWidget(QWidget *parent)
Definition: kmail_plugin.cpp:205
KMailPlugin
Definition: kmail_plugin.h:48
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:30 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kontact

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal