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