Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117880880
distributionlist.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None
distributionlist.cpp
View Options
/*
This file is part of Akonadi KolabProxy.
Copyright (c) 2009 Kevin Krammer <kevin.krammer@gmx.at>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#include
"distributionlist.h"
#include
<kabc/addressee.h>
#include
<kabc/contactgroup.h>
#include
<kdebug.h>
using
namespace
KolabV2
;
static
const
char
*
s_unhandledTagAppName
=
"KOLABUNHANDLED"
;
// no hyphens in appnames!
// saving (contactgroup->xml)
DistributionList
::
DistributionList
(
const
KABC
::
ContactGroup
*
contactGroup
)
{
setFields
(
contactGroup
);
}
// loading (xml->contactgroup)
DistributionList
::
DistributionList
(
const
QString
&
xml
)
{
load
(
xml
);
}
DistributionList
::~
DistributionList
()
{
}
void
DistributionList
::
setName
(
const
QString
&
name
)
{
mName
=
name
;
}
QString
DistributionList
::
name
()
const
{
return
mName
;
}
void
KolabV2
::
DistributionList
::
loadDistrListMember
(
const
QDomElement
&
element
)
{
Member
member
;
for
(
QDomNode
n
=
element
.
firstChild
();
!
n
.
isNull
();
n
=
n
.
nextSibling
()
)
{
if
(
n
.
isComment
()
)
continue
;
if
(
n
.
isElement
()
)
{
QDomElement
e
=
n
.
toElement
();
QString
tagName
=
e
.
tagName
();
if
(
tagName
==
"display-name"
)
member
.
displayName
=
e
.
text
();
else
if
(
tagName
==
"smtp-address"
)
member
.
email
=
e
.
text
();
}
}
mDistrListMembers
.
append
(
member
);
}
void
DistributionList
::
saveDistrListMembers
(
QDomElement
&
element
)
const
{
QList
<
Member
>::
ConstIterator
it
=
mDistrListMembers
.
constBegin
();
for
(
;
it
!=
mDistrListMembers
.
constEnd
();
++
it
)
{
QDomElement
e
=
element
.
ownerDocument
().
createElement
(
"member"
);
element
.
appendChild
(
e
);
const
Member
&
m
=
*
it
;
writeString
(
e
,
"display-name"
,
m
.
displayName
);
writeString
(
e
,
"smtp-address"
,
m
.
email
);
}
}
bool
DistributionList
::
loadAttribute
(
QDomElement
&
element
)
{
const
QString
tagName
=
element
.
tagName
();
switch
(
tagName
[
0
].
toLatin1
()
)
{
case
'd'
:
if
(
tagName
==
"display-name"
)
{
setName
(
element
.
text
()
);
return
true
;
}
break
;
case
'm'
:
if
(
tagName
==
"member"
)
{
loadDistrListMember
(
element
);
return
true
;
}
break
;
default
:
break
;
}
return
KolabBase
::
loadAttribute
(
element
);
}
bool
DistributionList
::
saveAttributes
(
QDomElement
&
element
)
const
{
// Save the base class elements
KolabBase
::
saveAttributes
(
element
);
writeString
(
element
,
"display-name"
,
name
()
);
saveDistrListMembers
(
element
);
return
true
;
}
bool
DistributionList
::
loadXML
(
const
QDomDocument
&
document
)
{
QDomElement
top
=
document
.
documentElement
();
if
(
top
.
tagName
()
!=
"distribution-list"
)
{
qWarning
(
"XML error: Top tag was %s instead of the expected distribution-list"
,
top
.
tagName
().
toAscii
().
data
()
);
return
false
;
}
for
(
QDomNode
n
=
top
.
firstChild
();
!
n
.
isNull
();
n
=
n
.
nextSibling
()
)
{
if
(
n
.
isComment
()
)
continue
;
if
(
n
.
isElement
()
)
{
QDomElement
e
=
n
.
toElement
();
if
(
!
loadAttribute
(
e
)
)
{
// Unhandled tag - save for later storage
//kDebug() <<"Saving unhandled tag" << e.tagName();
Custom
c
;
c
.
app
=
s_unhandledTagAppName
;
c
.
name
=
e
.
tagName
();
c
.
value
=
e
.
text
();
mCustomList
.
append
(
c
);
}
}
else
kDebug
()
<<
"Node is not a comment or an element???"
;
}
return
true
;
}
QString
DistributionList
::
saveXML
()
const
{
QDomDocument
document
=
domTree
();
QDomElement
element
=
document
.
createElement
(
"distribution-list"
);
element
.
setAttribute
(
"version"
,
"1.0"
);
saveAttributes
(
element
);
document
.
appendChild
(
element
);
return
document
.
toString
();
}
QString
DistributionList
::
productID
()
const
{
// TODO should we get name/version from desktop file?
return
QLatin1String
(
"Akonadi Kolab Proxy"
);
}
// The saving is contactgroup -> DistributionList -> xml, this is the first part
void
DistributionList
::
setFields
(
const
KABC
::
ContactGroup
*
contactGroup
)
{
KolabBase
::
setFields
(
contactGroup
);
setName
(
contactGroup
->
name
()
);
// explicit contact data
for
(
uint
index
=
0
;
index
<
contactGroup
->
dataCount
();
++
index
)
{
const
KABC
::
ContactGroup
::
Data
&
data
=
contactGroup
->
data
(
index
);
Member
m
;
m
.
displayName
=
data
.
name
();
m
.
email
=
data
.
email
();
mDistrListMembers
.
append
(
m
);
}
if
(
contactGroup
->
contactReferenceCount
()
>
0
)
{
kWarning
()
<<
"Tried to save contact references, which should have been resolved already"
;
}
if
(
contactGroup
->
contactGroupReferenceCount
()
>
0
)
{
kWarning
()
<<
"Tried to save contact group references, which should have been resolved already"
;
}
}
// The loading is: xml -> DistributionList -> contactgroup, this is the second part
void
DistributionList
::
saveTo
(
KABC
::
ContactGroup
*
contactGroup
)
{
KolabBase
::
saveTo
(
contactGroup
);
contactGroup
->
setName
(
name
()
);
QList
<
Member
>::
ConstIterator
mit
=
mDistrListMembers
.
constBegin
();
for
(
;
mit
!=
mDistrListMembers
.
constEnd
();
++
mit
)
{
const
KABC
::
ContactGroup
::
Data
data
(
(
*
mit
).
displayName
,
(
*
mit
).
email
);
contactGroup
->
append
(
data
);
}
}
// kate: space-indent on; indent-width 2; replace-tabs on;
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sun, Apr 5, 11:33 PM (1 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
bf/0f/819c909e4ad54db4e348590f422f
Default Alt Text
distributionlist.cpp (6 KB)
Attached To
Mode
rLK libkolab
Attached
Detach File
Event Timeline