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

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • akonadi
changenotificationdependenciesfactory.cpp
1 /*
2  Copyright (c) 2011 Stephen Kelly <steveire@gmail.com>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "changenotificationdependenciesfactory_p.h"
21 #include "dbusconnectionpool.h"
22 #include "notificationsource_p.h"
23 #include "notificationsourceinterface.h"
24 #include "notificationmanagerinterface.h"
25 #include "changemediator_p.h"
26 #include "servermanager.h"
27 
28 #include <KComponentData>
29 #include <KGlobal>
30 #include <KRandom>
31 #include <qdbusextratypes.h>
32 
33 using namespace Akonadi;
34 
35 NotificationSource *ChangeNotificationDependenciesFactory::createNotificationSource(QObject *parent)
36 {
37  if (!Akonadi::ServerManager::self()->isRunning()) {
38  return 0;
39  }
40 
41  org::freedesktop::Akonadi::NotificationManager *manager =
42  new org::freedesktop::Akonadi::NotificationManager(
43  ServerManager::serviceName(Akonadi::ServerManager::Server),
44  QLatin1String("/notifications"),
45  DBusConnectionPool::threadConnection());
46 
47  if (!manager) {
48  // :TODO: error handling
49  return 0;
50  }
51 
52  const QString name =
53  QString::fromLatin1("%1_%2_%3").arg(
54  KGlobal::mainComponent().componentName(),
55  QString::number(QCoreApplication::applicationPid()),
56  KRandom::randomString(6));
57  QDBusObjectPath p = manager->subscribeV2(name, true);
58  const bool validError = manager->lastError().isValid();
59  if (validError) {
60  kWarning() << manager->lastError().name() << manager->lastError().message();
61  // :TODO: What to do?
62  delete manager;
63  return 0;
64  }
65  delete manager;
66  org::freedesktop::Akonadi::NotificationSource *notificationSource =
67  new org::freedesktop::Akonadi::NotificationSource(
68  ServerManager::serviceName(Akonadi::ServerManager::Server),
69  p.path(),
70  DBusConnectionPool::threadConnection(), parent);
71 
72  if (!notificationSource) {
73  // :TODO: error handling
74  return 0;
75  }
76  return new NotificationSource(notificationSource);
77 }
78 
79 QObject *ChangeNotificationDependenciesFactory::createChangeMediator(QObject *parent)
80 {
81  Q_UNUSED(parent);
82  return ChangeMediator::instance();
83 }
84 
85 CollectionCache *ChangeNotificationDependenciesFactory::createCollectionCache(int maxCapacity, Session *session)
86 {
87  return new CollectionCache(maxCapacity, session);
88 }
89 
90 ItemCache *ChangeNotificationDependenciesFactory::createItemCache(int maxCapacity, Session *session)
91 {
92  return new ItemCache(maxCapacity, session);
93 }
94 
95 ItemListCache *ChangeNotificationDependenciesFactory::createItemListCache(int maxCapacity, Session *session)
96 {
97  return new ItemListCache(maxCapacity, session);
98 }
99 
100 TagListCache *ChangeNotificationDependenciesFactory::createTagListCache(int maxCapacity, Session *session)
101 {
102  return new TagListCache(maxCapacity, session);
103 }
Akonadi::ServerManager::self
static ServerManager * self()
Returns the singleton instance of this class, for connecting to its signals.
Definition: servermanager.cpp:161
Akonadi::ServerManager::serviceName
static QString serviceName(ServiceType serviceType)
Returns the namespaced D-Bus service name for serviceType.
Definition: servermanager.cpp:307
QDBusObjectPath
QString::number
QString number(int n, int base)
QObject
Akonadi::Session
A communication session with the Akonadi storage.
Definition: session.h:59
QCoreApplication::applicationPid
qint64 applicationPid()
QString
Akonadi::EntityCache
Definition: entitycache_p.h:97
QLatin1String
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QDBusObjectPath::path
QString path() const
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

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