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

kabc

  • sources
  • kde-4.12
  • kdepimlibs
  • kabc
distributionlist.cpp
1 /*
2  This file is part of libkabc.
3  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "distributionlist.h"
22 #include "resource.h"
23 
24 #include <kconfig.h>
25 #include <krandom.h>
26 #include <kstandarddirs.h>
27 #include <kdebug.h>
28 
29 #include <QApplication>
30 #include <QtCore/QPair>
31 #include <QtCore/QPointer>
32 
33 using namespace KABC;
34 
35 class DistributionList::Entry::Private
36 {
37  public:
38  Private() {}
39  Private( Addressee _addressee, const QString &_email )
40  : addressee( _addressee ), email( _email ) {}
41 
42  Addressee addressee;
43  QString email;
44 };
45 
46 DistributionList::Entry::Entry()
47  : d( new Private() )
48 {
49 }
50 
51 DistributionList::Entry::Entry( const DistributionList::Entry &entry )
52  : d( new Private( entry.d->addressee, entry.d->email ) )
53 {
54 }
55 
56 DistributionList::Entry::Entry( const Addressee &_addressee, const QString &_email )
57  : d( new Private( _addressee, _email ) )
58 {
59 }
60 
61 DistributionList::Entry::~Entry()
62 {
63  delete d;
64 }
65 
66 DistributionList::Entry &DistributionList::Entry::operator=( const DistributionList::Entry &entry )
67 {
68  d->addressee = entry.d->addressee;
69  d->email = entry.d->email;
70 
71  return *this;
72 }
73 
74 Addressee DistributionList::Entry::addressee() const
75 {
76  return d->addressee;
77 }
78 
79 QString DistributionList::Entry::email() const
80 {
81  return d->email;
82 }
83 
84 class DistributionList::Private
85 {
86  public:
87  Private( Resource *resource, const QString &identifier,
88  const QString &name )
89  : mResource( resource ), mIdentifier( identifier ), mName( name )
90  {
91  }
92 
93  QPointer<Resource> mResource;
94  QString mIdentifier;
95  QString mName;
96  Entry::List mEntries;
97 };
98 
99 DistributionList::DistributionList( Resource *resource, const QString &name )
100  : d( new Private( resource, KRandom::randomString(10), name ) )
101 {
102  d->mResource->insertDistributionList( this );
103 }
104 
105 DistributionList::DistributionList( Resource *resource,
106  const QString &identifier, const QString &name )
107  : d( new Private( resource, identifier, name ) )
108 {
109  d->mResource->insertDistributionList( this );
110 }
111 
112 DistributionList::~DistributionList()
113 {
114  if ( d->mResource ) {
115  d->mResource->removeDistributionList( this );
116  }
117 
118  delete d;
119 }
120 
121 void DistributionList::setIdentifier( const QString &identifier )
122 {
123  d->mIdentifier = identifier;
124 }
125 
126 QString DistributionList::identifier() const
127 {
128  return d->mIdentifier;
129 }
130 
131 void DistributionList::setName( const QString &name )
132 {
133  d->mName = name;
134 }
135 
136 QString DistributionList::name() const
137 {
138  return d->mName;
139 }
140 
141 void DistributionList::insertEntry( const Addressee &a, const QString &email )
142 {
143  Entry e( a, email );
144 
145  QList<Entry>::Iterator it;
146  for ( it = d->mEntries.begin(); it != d->mEntries.end(); ++it ) {
147  if ( ( *it ).addressee().uid() == a.uid() ) {
152  if ( ( ( *it ).email().isNull() && email.isEmpty() ) ||
153  ( ( *it ).email().isEmpty() && email.isNull() ) ||
154  ( ( *it ).email() == email ) ) {
155  *it = e;
156  return;
157  }
158  }
159  }
160  d->mEntries.append( e );
161 }
162 
163 void DistributionList::removeEntry( const Addressee &a, const QString &email )
164 {
165  QList<Entry>::Iterator it;
166  for ( it = d->mEntries.begin(); it != d->mEntries.end(); ++it ) {
167  if ( ( *it ).addressee().uid() == a.uid() && ( *it ).email() == email ) {
168  d->mEntries.erase( it );
169  return;
170  }
171  }
172 }
173 
174 QStringList DistributionList::emails() const
175 {
176  QStringList emails;
177 
178  Entry::List::ConstIterator it;
179  for ( it = d->mEntries.constBegin(); it != d->mEntries.constEnd(); ++it ) {
180  const Addressee a = ( *it ).addressee();
181  QString email = ( *it ).email().isEmpty() ? a.fullEmail() :
182  a.fullEmail( ( *it ).email() );
183 
184  if ( !email.isEmpty() ) {
185  emails.append( email );
186  }
187  }
188 
189  return emails;
190 }
191 
192 DistributionList::Entry::List DistributionList::entries() const
193 {
194  return d->mEntries;
195 }
196 
197 Resource *DistributionList::resource() const
198 {
199  return d->mResource;
200 }
201 
202 typedef QList< QPair<QString, QString> > MissingEntryList;
KABC::DistributionList::entries
Entry::List entries() const
Return list of entries belonging to this distribution list.
Definition: distributionlist.cpp:192
KABC::DistributionList::removeEntry
void removeEntry(const Addressee &, const QString &email=QString())
Remove an entry from this distribution list.
Definition: distributionlist.cpp:163
KABC::DistributionList::~DistributionList
~DistributionList()
Destructor.
Definition: distributionlist.cpp:112
KABC::DistributionList::emails
QStringList emails() const
Return list of email addresses, which belong to this distributon list.
Definition: distributionlist.cpp:174
KABC::DistributionList::Entry::Entry
Entry()
Creates an empty Entry instance.
Definition: distributionlist.cpp:46
KABC::DistributionList::insertEntry
void insertEntry(const Addressee &, const QString &email=QString())
Insert an entry into this distribution list.
Definition: distributionlist.cpp:141
KABC::Addressee::fullEmail
QString fullEmail(const QString &email=QString()) const
Return email address including real name.
Definition: addressee.cpp:1205
KABC::DistributionList::Entry::operator=
Entry & operator=(const Entry &other)
Assignment operator.
Definition: distributionlist.cpp:66
KABC::DistributionList::Entry::List
QList< Entry > List
A list of Entry instances.
Definition: distributionlist.h:61
KABC::DistributionList::Entry
Distribution List Entry.
Definition: distributionlist.h:55
KABC::DistributionList::Entry::email
QString email() const
Returns the email address of the list entry.
Definition: distributionlist.cpp:79
KABC::DistributionList::Entry::addressee
Addressee addressee() const
Returns the addressee of the list entry.
Definition: distributionlist.cpp:74
KABC::DistributionList::name
QString name() const
Get name of this list.
Definition: distributionlist.cpp:136
KABC::DistributionList::identifier
QString identifier() const
Returns the distribution list's identifier.
Definition: distributionlist.cpp:126
KABC::DistributionList::setIdentifier
void setIdentifier(const QString &identifier)
Sets the identifier of this list which is used as key by resources.
Definition: distributionlist.cpp:121
KABC::Addressee::isEmpty
bool isEmpty() const
Return, if the address book entry is empty.
Definition: addressee.cpp:363
KABC::Addressee
address book entry
Definition: addressee.h:74
KABC::DistributionList::Entry::~Entry
~Entry()
Destroys the Entry instance.
Definition: distributionlist.cpp:61
KABC::Resource
Definition: resource.h:64
KABC::DistributionList::DistributionList
DistributionList(Resource *resource, const QString &name)
Create distribution list object.
Definition: distributionlist.cpp:99
KABC::Addressee::uid
QString uid() const
Return unique identifier.
Definition: addressee.cpp:377
KABC::DistributionList::setName
void setName(const QString &)
Set name of this list.
Definition: distributionlist.cpp:131
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:01:05 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kabc

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

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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