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

akonadi

  • akonadi
  • contact
contactgroupviewer.cpp
1/*
2 This file is part of Akonadi Contact.
3
4 Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10
11 This library is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
20*/
21
22#include "contactgroupviewer.h"
23
24#include "contactgroupexpandjob.h"
25#include "standardcontactgroupformatter.h"
26#include "textbrowser_p.h"
27
28#include <akonadi/collectionfetchjob.h>
29#include <akonadi/entitydisplayattribute.h>
30#include <akonadi/item.h>
31#include <akonadi/itemfetchjob.h>
32#include <akonadi/itemfetchscope.h>
33#include <kabc/addressee.h>
34#include <kabc/contactgroup.h>
35#include <kcolorscheme.h>
36#include <kglobal.h>
37#include <kicon.h>
38#include <klocalizedstring.h>
39#include <kstringhandler.h>
40
41#include <QVBoxLayout>
42
43using namespace Akonadi;
44
45class ContactGroupViewer::Private
46{
47 public:
48 Private( ContactGroupViewer *parent )
49 : mParent( parent ), mExpandJob( 0 ), mParentCollectionFetchJob( 0 )
50 {
51 mBrowser = new TextBrowser;
52
53 static QPixmap groupPixmap = KIcon( QLatin1String( "x-mail-distribution-list" ) ).pixmap( QSize( 100, 100 ) );
54 mBrowser->document()->addResource( QTextDocument::ImageResource,
55 QUrl( QLatin1String( "group_photo" ) ),
56 groupPixmap );
57
58 mStandardContactGroupFormatter = new StandardContactGroupFormatter;
59 mContactGroupFormatter = mStandardContactGroupFormatter;
60 }
61
62 ~Private()
63 {
64 delete mStandardContactGroupFormatter;
65 }
66
67 void updateView()
68 {
69 mParent->setWindowTitle( i18n( "Contact Group %1", mCurrentGroupName ) );
70
71 KABC::ContactGroup group;
72 group.setName( mCurrentGroupName );
73 foreach ( const KABC::Addressee &contact, mCurrentContacts ) {
74 group.append( KABC::ContactGroup::Data( contact.realName(), contact.preferredEmail() ) );
75 }
76
77 mContactGroupFormatter->setContactGroup( group );
78
79 QList<QVariantMap> additionalFields;
80
81 if ( !mCurrentAddressBookName.isEmpty() ) {
82 QVariantMap addressBookName;
83 addressBookName.insert( QLatin1String( "title" ), i18n( "Address Book" ) );
84 addressBookName.insert( QLatin1String( "value" ), mCurrentAddressBookName );
85
86 additionalFields << addressBookName;
87 }
88
89 mContactGroupFormatter->setAdditionalFields( additionalFields );
90
91 mBrowser->setHtml( mContactGroupFormatter->toHtml() );
92 }
93
94 void slotMailClicked( const QString&, const QString &email )
95 {
96 QString name, address;
97
98 // remove the 'mailto:' and split into name and email address
99 KABC::Addressee::parseEmailAddress( email.mid( 7 ), name, address );
100
101 emit mParent->emailClicked( name, address );
102 }
103
104 void _k_expandResult( KJob *job )
105 {
106 mExpandJob = 0;
107
108 if ( !job->error() ) {
109 ContactGroupExpandJob *expandJob = qobject_cast<ContactGroupExpandJob*>( job );
110 mCurrentContacts = expandJob->contacts();
111 }
112
113 // stop any running fetch job
114 if ( mParentCollectionFetchJob ) {
115 mParent->disconnect( mParentCollectionFetchJob, SIGNAL(result(KJob*)), mParent, SLOT(slotParentCollectionFetched(KJob*)) );
116 delete mParentCollectionFetchJob;
117 mParentCollectionFetchJob = 0;
118 }
119
120 mParentCollectionFetchJob = new CollectionFetchJob( mCurrentItem.parentCollection(), CollectionFetchJob::Base, mParent );
121 mParent->connect( mParentCollectionFetchJob, SIGNAL(result(KJob*)), SLOT(slotParentCollectionFetched(KJob*)) );
122 }
123
124 void slotParentCollectionFetched( KJob *job )
125 {
126 mParentCollectionFetchJob = 0;
127 mCurrentAddressBookName.clear();
128
129 if ( !job->error() ) {
130 CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob*>( job );
131 if ( !fetchJob->collections().isEmpty() ) {
132 const Collection collection = fetchJob->collections().first();
133 mCurrentAddressBookName = collection.displayName();
134 }
135 }
136
137 updateView();
138 }
139
140 ContactGroupViewer *mParent;
141 TextBrowser *mBrowser;
142 QString mCurrentGroupName;
143 KABC::Addressee::List mCurrentContacts;
144 QString mCurrentAddressBookName;
145 Item mCurrentItem;
146 ContactGroupExpandJob *mExpandJob;
147 CollectionFetchJob *mParentCollectionFetchJob;
148 AbstractContactGroupFormatter *mStandardContactGroupFormatter;
149 AbstractContactGroupFormatter *mContactGroupFormatter;
150};
151
152ContactGroupViewer::ContactGroupViewer( QWidget *parent )
153 : QWidget( parent ), d( new Private( this ) )
154{
155 QVBoxLayout *layout = new QVBoxLayout( this );
156 layout->setMargin( 0 );
157
158 d->mBrowser->setNotifyClick( true );
159
160 connect( d->mBrowser, SIGNAL(mailClick(QString,QString)),
161 this, SLOT(slotMailClicked(QString,QString)) );
162
163 layout->addWidget( d->mBrowser );
164
165 // always fetch full payload for contact groups
166 fetchScope().fetchFullPayload();
167 fetchScope().setAncestorRetrieval( ItemFetchScope::Parent );
168}
169
170ContactGroupViewer::~ContactGroupViewer()
171{
172 delete d;
173}
174
175Akonadi::Item ContactGroupViewer::contactGroup() const
176{
177 return ItemMonitor::item();
178}
179
180void ContactGroupViewer::setContactGroup( const Akonadi::Item &group )
181{
182 ItemMonitor::setItem( group );
183}
184
185void ContactGroupViewer::setContactGroupFormatter( AbstractContactGroupFormatter *formatter )
186{
187 if ( formatter == 0 ) {
188 d->mContactGroupFormatter = d->mStandardContactGroupFormatter;
189 } else {
190 d->mContactGroupFormatter = formatter;
191 }
192}
193
194void ContactGroupViewer::itemChanged( const Item &item )
195{
196 if ( !item.hasPayload<KABC::ContactGroup>() ) {
197 return;
198 }
199
200 const KABC::ContactGroup group = item.payload<KABC::ContactGroup>();
201 d->mCurrentGroupName = group.name();
202 d->mCurrentItem = item;
203
204 if ( d->mExpandJob ) {
205 disconnect( d->mExpandJob, SIGNAL(result(KJob*)), this, SLOT(_k_expandResult(KJob*)) );
206 d->mExpandJob->kill();
207 }
208
209 d->mExpandJob = new ContactGroupExpandJob( group );
210 connect( d->mExpandJob, SIGNAL(result(KJob*)), SLOT(_k_expandResult(KJob*)) );
211 d->mExpandJob->start();
212}
213
214void ContactGroupViewer::itemRemoved()
215{
216 d->mBrowser->clear();
217}
218
219#include "moc_contactgroupviewer.cpp"
Akonadi::AbstractContactGroupFormatter
The interface for all contact group formatters.
Definition abstractcontactgroupformatter.h:47
Akonadi::AbstractContactGroupFormatter::setContactGroup
void setContactGroup(const KABC::ContactGroup &group)
Sets the contact group that will be formatted.
Definition abstractcontactgroupformatter.cpp:47
Akonadi::AbstractContactGroupFormatter::toHtml
virtual QString toHtml(HtmlForm form=SelfcontainedForm) const =0
This method must be reimplemented to return the contact group formatted as HTML according to the requ...
Akonadi::AbstractContactGroupFormatter::setAdditionalFields
void setAdditionalFields(const QList< QVariantMap > &fields)
Sets the additional fields that will be shown.
Definition abstractcontactgroupformatter.cpp:67
Akonadi::CollectionFetchJob
Job that fetches collections from the Akonadi storage.
Definition collectionfetchjob.h:54
Akonadi::CollectionFetchJob::Base
@ Base
Only fetch the base collection.
Definition collectionfetchjob.h:62
Akonadi::CollectionFetchJob::collections
Collection::List collections() const
Returns the list of fetched collection.
Definition collectionfetchjob.cpp:169
Akonadi::Collection
Represents a collection of PIM items.
Definition collection.h:76
Akonadi::ContactGroupExpandJob
Job that expands a ContactGroup to a list of contacts.
Definition contactgroupexpandjob.h:65
Akonadi::ContactGroupExpandJob::contacts
KABC::Addressee::List contacts() const
Returns the list of contacts.
Definition contactgroupexpandjob.cpp:162
Akonadi::ContactGroupViewer
A viewer component for contact groups in Akonadi.
Definition contactgroupviewer.h:58
Akonadi::ContactGroupViewer::~ContactGroupViewer
~ContactGroupViewer()
Destroys the contact group viewer.
Definition contactgroupviewer.cpp:170
Akonadi::ContactGroupViewer::emailClicked
void emailClicked(const QString &name, const QString &email)
This signal is emitted whenever the user has clicked on an email address in the viewer.
Akonadi::ContactGroupViewer::setContactGroup
void setContactGroup(const Akonadi::Item &group)
Sets the contact group that shall be displayed in the viewer.
Definition contactgroupviewer.cpp:180
Akonadi::ContactGroupViewer::setContactGroupFormatter
void setContactGroupFormatter(AbstractContactGroupFormatter *formatter)
Sets the contact group formatter that should be used for formatting the contact group.
Definition contactgroupviewer.cpp:185
Akonadi::ContactGroupViewer::contactGroup
Akonadi::Item contactGroup() const
Returns the contact group that is currently displayed.
Definition contactgroupviewer.cpp:175
Akonadi::ContactGroupViewer::ContactGroupViewer
ContactGroupViewer(QWidget *parent=0)
Creates a new contact group viewer.
Definition contactgroupviewer.cpp:152
Akonadi::ItemFetchScope::setAncestorRetrieval
void setAncestorRetrieval(AncestorRetrieval ancestorDepth)
Sets how many levels of ancestor collections should be included in the retrieval.
Definition itemfetchscope.cpp:132
Akonadi::ItemFetchScope::fetchFullPayload
void fetchFullPayload(bool fetch=true)
Sets whether the full payload shall be fetched.
Definition itemfetchscope.cpp:70
Akonadi::ItemFetchScope::Parent
@ Parent
Only retrieve the immediate parent collection.
Definition itemfetchscope.h:78
Akonadi::ItemMonitor::setItem
void setItem(const Item &item)
Sets the item that shall be monitored.
Definition itemmonitor.cpp:39
Akonadi::ItemMonitor::item
Item item() const
Returns the currently monitored item.
Definition itemmonitor.cpp:63
Akonadi::ItemMonitor::fetchScope
ItemFetchScope & fetchScope()
Returns the item fetch scope.
Definition itemmonitor.cpp:81
Akonadi::StandardContactGroupFormatter
A class that formats a contact group as HTML code.
Definition standardcontactgroupformatter.h:54
Akonadi::TextBrowser
A convenience class to remove the 'Copy Link Location' action from the context menu of KTextBrowser.
Definition textbrowser_p.h:35
Akonadi
FreeBusyManager::Singleton.
Definition actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 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
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 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
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