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

kontact

  • sources
  • kde-4.14
  • kdepim
  • kontact
  • plugins
  • kaddressbook
kaddressbook_plugin.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KAddressBook Kontact Plugin.
3 
4  Copyright (c) 2009-2015 Laurent Montel <montel@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 
21 #include "kaddressbook_plugin.h"
22 #include "kaddressbook_options.h"
23 #include "kaddressbookinterface.h"
24 
25 #include <KontactInterface/Core>
26 
27 #include <KAction>
28 #include <KActionCollection>
29 #include <KCmdLineArgs>
30 #include <KDebug>
31 #include <KLocalizedString>
32 
33 #include <QDBusConnection>
34 #include <QDBusMessage>
35 #include <QDBusReply>
36 
37 EXPORT_KONTACT_PLUGIN( KAddressBookPlugin, kaddressbook )
38 
39 KAddressBookPlugin::KAddressBookPlugin( KontactInterface::Core *core, const QVariantList & )
40  : KontactInterface::Plugin( core, core, "kaddressbook" )
41 {
42  setComponentData( KontactPluginFactory::componentData() );
43 
44  KGlobal::locale()->insertCatalog( QLatin1String("libkdepim") );
45  KGlobal::locale()->insertCatalog( QLatin1String("kabc") );
46  KGlobal::locale()->insertCatalog( QLatin1String("libakonadi") );
47  KGlobal::locale()->insertCatalog( QLatin1String("kabcakonadi" ));
48 
49  KAction *action =
50  new KAction( KIcon( QLatin1String("contact-new") ),
51  i18nc( "@action:inmenu", "New Contact..." ), this );
52  actionCollection()->addAction( QLatin1String("new_contact"), action );
53  connect( action, SIGNAL(triggered(bool)), SLOT(slotNewContact()) );
54  action->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_C ) );
55  action->setHelpText(
56  i18nc( "@info:status", "Create a new contact" ) );
57  action->setWhatsThis(
58  i18nc( "@info:whatsthis",
59  "You will be presented with a dialog where you can create a new contact." ) );
60  insertNewAction( action );
61 
62  action =
63  new KAction( KIcon( QLatin1String("user-group-new") ),
64  i18nc( "@action:inmenu", "New Contact Group..." ), this );
65  actionCollection()->addAction( QLatin1String("new_contactgroup"), action );
66  connect( action, SIGNAL(triggered(bool)), SLOT(slotNewContactGroup()) );
67  action->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_G ) );
68  action->setHelpText(
69  i18nc( "@info:status", "Create a new contact group" ) );
70  action->setWhatsThis(
71  i18nc( "@info:whatsthis",
72  "You will be presented with a dialog where you can create a new contact group." ) );
73  insertNewAction( action );
74 
75  KAction *syncAction =
76  new KAction( KIcon( QLatin1String("view-refresh") ),
77  i18nc( "@action:inmenu", "Sync Contacts" ), this );
78  actionCollection()->addAction( QLatin1String("kaddressbook_sync"), syncAction );
79  connect( syncAction, SIGNAL(triggered(bool)), SLOT(slotSyncContacts()) );
80  syncAction->setHelpText(
81  i18nc( "@info:status", "Synchronize groupware contacts" ) );
82  syncAction->setWhatsThis(
83  i18nc( "@info:whatsthis",
84  "Choose this option to synchronize your groupware contacts." ) );
85  insertSyncAction( syncAction );
86 
87  mUniqueAppWatcher = new KontactInterface::UniqueAppWatcher(
88  new KontactInterface::UniqueAppHandlerFactory<KAddressBookUniqueAppHandler>(), this );
89 }
90 
91 KAddressBookPlugin::~KAddressBookPlugin()
92 {
93 }
94 
95 void KAddressBookPlugin::slotNewContact()
96 {
97  KParts::ReadOnlyPart *part = createPart();
98  if ( !part ) {
99  return;
100  }
101 
102  if ( part->metaObject()->indexOfMethod( "newContact()" ) == -1 ) {
103  kWarning() << "KAddressBook part is missing slot newContact()";
104  return;
105  }
106 
107  QMetaObject::invokeMethod( part, "newContact" );
108 }
109 
110 void KAddressBookPlugin::slotNewContactGroup()
111 {
112  KParts::ReadOnlyPart *part = createPart();
113  if ( !part ) {
114  return;
115  }
116 
117  if ( part->metaObject()->indexOfMethod( "newGroup()" ) == -1 ) {
118  kWarning() << "KAddressBook part is missing slot newGroup()";
119  return;
120  }
121 
122  QMetaObject::invokeMethod( part, "newGroup" );
123 }
124 
125 QString KAddressBookPlugin::tipFile() const
126 {
127  // TODO: tips file
128  //QString file = KStandardDirs::locate("data", "kaddressbook/tips");
129  QString file;
130  return file;
131 }
132 
133 KParts::ReadOnlyPart *KAddressBookPlugin::createPart()
134 {
135  KParts::ReadOnlyPart *part = loadPart();
136  if ( !part ) {
137  return 0;
138  }
139 
140  // disable the Ctrl+N shortcut, as it is used by Kontact already
141  if ( part->action( "akonadi_contact_create" ) ) {
142  KAction *newAction = qobject_cast<KAction*>( part->action( "akonadi_contact_create" ) );
143  if ( newAction ) {
144  newAction->setShortcut( QKeySequence() );
145  }
146  }
147 
148  return part;
149 }
150 
151 bool KAddressBookPlugin::isRunningStandalone() const
152 {
153  return mUniqueAppWatcher->isRunningStandalone();
154 }
155 
156 QStringList KAddressBookPlugin::invisibleToolbarActions() const
157 {
158  QStringList actions;
159  actions << QLatin1String("akonadi_contact_create") << QLatin1String("akonadi_contact_group_create");
160  return actions;
161 }
162 
163 void KAddressBookPlugin::shortcutChanged()
164 {
165  KParts::ReadOnlyPart *localPart = part();
166  if ( localPart ) {
167  if ( localPart->metaObject()->indexOfMethod( "updateQuickSearchText()" ) == -1 ) {
168  kWarning() << "KAddressBook part is missing slot updateQuickSearchText()";
169  return;
170  }
171  QMetaObject::invokeMethod( localPart, "updateQuickSearchText" );
172  }
173 }
174 
175 void KAddressBookPlugin::slotSyncContacts()
176 {
177 #if 0
178  QDBusMessage message =
179  QDBusMessage::createMethodCall( "org.kde.kmail", "/Groupware",
180  "org.kde.kmail.groupware",
181  "triggerSync" );
182  message << QString( "Contact" );
183  QDBusConnection::sessionBus().send( message );
184 #else
185  kWarning() << QLatin1String(" Need to port to AKONADI: KAddressBookPlugin::slotSyncNotes");
186 #endif
187 }
188 
189 void KAddressBookUniqueAppHandler::loadCommandLineOptions()
190 {
191  KCmdLineArgs::addCmdLineOptions( kaddressbook_options() );
192 }
193 
194 int KAddressBookUniqueAppHandler::newInstance()
195 {
196  kDebug() ;
197  // Ensure part is loaded
198  (void)plugin()->part();
199  org::kde::kaddressbook kaddressbook( QLatin1String("org.kde.kaddressbook"), QLatin1String("/KAddressBook"), QDBusConnection::sessionBus() );
200  QDBusReply<bool> reply = kaddressbook.handleCommandLine();
201  return KontactInterface::UniqueAppHandler::newInstance();
202 }
203 
204 
KAddressBookPlugin::createPart
KParts::ReadOnlyPart * createPart()
Definition: kaddressbook_plugin.cpp:133
QDBusReply
KAddressBookUniqueAppHandler::loadCommandLineOptions
virtual void loadCommandLineOptions()
Definition: kaddressbook_plugin.cpp:189
KAddressBookPlugin::tipFile
QString tipFile() const
Definition: kaddressbook_plugin.cpp:125
QDBusConnection::sessionBus
QDBusConnection sessionBus()
KAddressBookPlugin::isRunningStandalone
bool isRunningStandalone() const
Definition: kaddressbook_plugin.cpp:151
KAddressBookPlugin::invisibleToolbarActions
QStringList invisibleToolbarActions() const
Definition: kaddressbook_plugin.cpp:156
KAddressBookPlugin::~KAddressBookPlugin
~KAddressBookPlugin()
Definition: kaddressbook_plugin.cpp:91
QDBusConnection::send
bool send(const QDBusMessage &message) const
QString
QStringList
KAddressBookPlugin
Definition: kaddressbook_plugin.h:39
QMetaObject::invokeMethod
bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericReturnArgument ret, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9)
kaddressbook_plugin.h
KAddressBookPlugin::shortcutChanged
void shortcutChanged()
Definition: kaddressbook_plugin.cpp:163
QDBusMessage
QLatin1String
QKeySequence
QDBusMessage::createMethodCall
QDBusMessage createMethodCall(const QString &service, const QString &path, const QString &interface, const QString &method)
KAddressBookUniqueAppHandler::newInstance
virtual int newInstance()
Definition: kaddressbook_plugin.cpp:194
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:11 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
  • pimprint

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