Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Akonadi Contacts
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PIM
Akonadi Contacts
Commits
4dd3676b
Commit
4dd3676b
authored
May 15, 2010
by
Tobias Koenig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed the design of AbstractContactFormatter
svn path=/trunk/KDE/kdepimlibs/; revision=1127126
parent
cc874f54
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
138 additions
and
64 deletions
+138
-64
akonadi/contact/abstractcontactformatter.cpp
akonadi/contact/abstractcontactformatter.cpp
+47
-0
akonadi/contact/abstractcontactformatter.h
akonadi/contact/abstractcontactformatter.h
+58
-10
akonadi/contact/contactviewer.cpp
akonadi/contact/contactviewer.cpp
+3
-1
akonadi/contact/standardcontactformatter.cpp
akonadi/contact/standardcontactformatter.cpp
+30
-41
akonadi/contact/standardcontactformatter.h
akonadi/contact/standardcontactformatter.h
+0
-12
No files found.
akonadi/contact/abstractcontactformatter.cpp
View file @
4dd3676b
...
...
@@ -21,8 +21,55 @@
#include "abstractcontactformatter.h"
#include <akonadi/item.h>
#include <kabc/addressee.h>
using
namespace
Akonadi
;
class
AbstractContactFormatter
::
Private
{
public:
KABC
::
Addressee
mContact
;
Akonadi
::
Item
mItem
;
QList
<
QVariantMap
>
mCustomFieldDescriptions
;
};
AbstractContactFormatter
::
AbstractContactFormatter
()
:
d
(
new
Private
)
{
}
AbstractContactFormatter
::~
AbstractContactFormatter
()
{
delete
d
;
}
void
AbstractContactFormatter
::
setContact
(
const
KABC
::
Addressee
&
contact
)
{
d
->
mContact
=
contact
;
}
KABC
::
Addressee
AbstractContactFormatter
::
contact
()
const
{
return
d
->
mContact
;
}
void
AbstractContactFormatter
::
setItem
(
const
Akonadi
::
Item
&
item
)
{
d
->
mItem
=
item
;
}
Akonadi
::
Item
AbstractContactFormatter
::
item
()
const
{
return
d
->
mItem
;
}
void
AbstractContactFormatter
::
setCustomFieldDescriptions
(
const
QList
<
QVariantMap
>
&
descriptions
)
{
d
->
mCustomFieldDescriptions
=
descriptions
;
}
QList
<
QVariantMap
>
AbstractContactFormatter
::
customFieldDescriptions
()
const
{
return
d
->
mCustomFieldDescriptions
;
}
akonadi/contact/abstractcontactformatter.h
View file @
4dd3676b
...
...
@@ -31,14 +31,18 @@ class Addressee;
}
namespace
Akonadi
{
class
Item
;
/**
* @short The interface for all contact formatters.
*
* This is the interface that can be used to format an Akonadi
* item with a contact payload or a contact itself as HTML.
*
* @see StandardContactFormatter
* @author Tobias Koenig <tokoe@kde.org>
* @since 4.5
*/
//AK_REVIEW: extend api docs (usage), move class to libkabc
class
AKONADI_CONTACT_EXPORT
AbstractContactFormatter
{
public:
...
...
@@ -52,30 +56,74 @@ class AKONADI_CONTACT_EXPORT AbstractContactFormatter
UserForm
=
SelfcontainedForm
+
42
///< Point for extension
};
/**
* Creates a new abstract contact formatter.
*/
AbstractContactFormatter
();
/**
* Destroys the abstract contact formatter.
*/
virtual
~
AbstractContactFormatter
();
/**
* Sets the @p contact that
sha
ll be formatted.
* Sets the @p contact that
wi
ll be formatted.
*/
//AK_REVIEW: add getter and make it non-abstract
virtual
void
setContact
(
const
KABC
::
Addressee
&
contact
)
=
0
;
void
setContact
(
const
KABC
::
Addressee
&
contact
);
//AK_REVIEW: add method setItem( const Akonadi::Item ) and getter
/**
* Returns the contact that will be formatted.
*/
KABC
::
Addressee
contact
()
const
;
/**
* Sets the @p item who's payload will be formatted.
*
* @note The payload must be a valid KABC::Addressee object.
*/
void
setItem
(
const
Akonadi
::
Item
&
item
);
/**
*
Sets the custom field @p descriptions that shall be us
ed.
*
Returns the item who's payload will be formatt
ed.
*/
//AK_REVIEW: change QVariantList to QList<QMap<QString, QVariant>>
//AK_REVIEW: add getter and make it non-abstract
virtual
void
setCustomFieldDescriptions
(
const
QVariantList
&
descriptions
)
=
0
;
Akonadi
::
Item
item
()
const
;
/**
* Returns the contact formatted as HTML
* Sets the custom field @p descriptions that will be used.
*
* The description list contains a QVariantMap for each custom field
* with the following keys:
* - key (string) The identifier of the field
* - title (string) The i18n'ed title of the field
* - type (string) The type description of the field
* Possible values for type description are
* - text
* - numeric
* - boolean
* - date
* - time
* - datetime
*/
void
setCustomFieldDescriptions
(
const
QList
<
QVariantMap
>
&
descriptions
);
/**
* Returns the custom field descriptions that will be used.
*/
QList
<
QVariantMap
>
customFieldDescriptions
()
const
;
/**
* This method must be reimplemented to return the contact formatted as HTML
* according to the requested @p form.
*/
virtual
QString
toHtml
(
HtmlForm
form
=
SelfcontainedForm
)
const
=
0
;
private:
//@cond PRIVATE
Q_DISABLE_COPY
(
AbstractContactFormatter
)
class
Private
;
Private
*
const
d
;
//@endcond
};
}
...
...
akonadi/contact/contactviewer.cpp
View file @
4dd3676b
...
...
@@ -74,7 +74,9 @@ class ContactViewer::Private
}
// merge local and global custom field descriptions
QVariantList
customFieldDescriptions
(
localCustomFieldDescriptions
);
QList
<
QVariantMap
>
customFieldDescriptions
;
foreach
(
const
QVariant
&
entry
,
localCustomFieldDescriptions
)
customFieldDescriptions
<<
entry
.
toMap
();
const
CustomField
::
List
globalCustomFields
=
CustomFieldManager
::
globalCustomFieldDescriptions
();
foreach
(
const
CustomField
&
field
,
globalCustomFields
)
{
...
...
akonadi/contact/standardcontactformatter.cpp
View file @
4dd3676b
...
...
@@ -21,6 +21,7 @@
#include "standardcontactformatter.h"
#include <akonadi/item.h>
#include <kabc/addressee.h>
#include <kcolorscheme.h>
#include <kglobal.h>
...
...
@@ -31,36 +32,25 @@
using
namespace
Akonadi
;
class
StandardContactFormatter
::
Private
{
public:
KABC
::
Addressee
mContact
;
QVariantList
mCustomFieldDescriptions
;
};
StandardContactFormatter
::
StandardContactFormatter
()
:
d
(
new
Private
)
:
d
(
0
)
{
}
StandardContactFormatter
::~
StandardContactFormatter
()
{
delete
d
;
}
void
StandardContactFormatter
::
setContact
(
const
KABC
::
Addressee
&
contact
)
{
d
->
mContact
=
contact
;
}
void
StandardContactFormatter
::
setCustomFieldDescriptions
(
const
QVariantList
&
descriptions
)
{
d
->
mCustomFieldDescriptions
=
descriptions
;
}
QString
StandardContactFormatter
::
toHtml
(
HtmlForm
form
)
const
{
if
(
d
->
mContact
.
isEmpty
()
)
KABC
::
Addressee
rawContact
;
const
Akonadi
::
Item
localItem
=
item
();
if
(
localItem
.
isValid
()
&&
localItem
.
hasPayload
<
KABC
::
Addressee
>
()
)
rawContact
=
localItem
.
payload
<
KABC
::
Addressee
>
();
else
rawContact
=
contact
();
if
(
rawContact
.
isEmpty
()
)
return
QString
();
// We'll be building a table to display the vCard in.
...
...
@@ -77,7 +67,7 @@ QString StandardContactFormatter::toHtml( HtmlForm form ) const
QString
dynamicPart
;
// Birthday
const
QDate
date
=
d
->
m
Contact
.
birthday
().
date
();
const
QDate
date
=
raw
Contact
.
birthday
().
date
();
const
int
years
=
(
date
.
daysTo
(
QDate
::
currentDate
()
)
/
365
);
if
(
date
.
isValid
()
)
...
...
@@ -88,7 +78,7 @@ QString StandardContactFormatter::toHtml( HtmlForm form ) const
// Phone Numbers
int
counter
=
0
;
foreach
(
const
KABC
::
PhoneNumber
&
number
,
d
->
m
Contact
.
phoneNumbers
()
)
{
foreach
(
const
KABC
::
PhoneNumber
&
number
,
raw
Contact
.
phoneNumbers
()
)
{
const
QString
url
=
QString
::
fromLatin1
(
"<a href=
\"
phone:?index=%1
\"
>%2</a>"
).
arg
(
counter
).
arg
(
number
.
number
()
);
counter
++
;
...
...
@@ -98,10 +88,10 @@ QString StandardContactFormatter::toHtml( HtmlForm form ) const
}
// EMails
foreach
(
const
QString
&
email
,
d
->
m
Contact
.
emails
()
)
{
foreach
(
const
QString
&
email
,
raw
Contact
.
emails
()
)
{
QString
type
=
i18nc
(
"a contact's email address"
,
"Email"
);
const
QString
fullEmail
=
QString
::
fromLatin1
(
KUrl
::
toPercentEncoding
(
d
->
m
Contact
.
fullEmail
(
email
)
)
);
const
QString
fullEmail
=
QString
::
fromLatin1
(
KUrl
::
toPercentEncoding
(
raw
Contact
.
fullEmail
(
email
)
)
);
dynamicPart
+=
rowFmtStr
.
arg
(
type
)
.
arg
(
QString
::
fromLatin1
(
"<a href=
\"
mailto:%1
\"
>%2</a>"
)
...
...
@@ -109,8 +99,8 @@ QString StandardContactFormatter::toHtml( HtmlForm form ) const
}
// Homepage
if
(
d
->
m
Contact
.
url
().
isValid
()
)
{
QString
url
=
d
->
m
Contact
.
url
().
url
();
if
(
raw
Contact
.
url
().
isValid
()
)
{
QString
url
=
raw
Contact
.
url
().
url
();
if
(
!
url
.
startsWith
(
QLatin1String
(
"http://"
)
)
&&
!
url
.
startsWith
(
QLatin1String
(
"https://"
)
)
)
url
=
QLatin1String
(
"http://"
)
+
url
;
...
...
@@ -119,13 +109,13 @@ QString StandardContactFormatter::toHtml( HtmlForm form ) const
}
// Blog Feed
const
QString
blog
=
d
->
m
Contact
.
custom
(
QLatin1String
(
"KADDRESSBOOK"
),
QLatin1String
(
"BlogFeed"
)
);
const
QString
blog
=
raw
Contact
.
custom
(
QLatin1String
(
"KADDRESSBOOK"
),
QLatin1String
(
"BlogFeed"
)
);
if
(
!
blog
.
isEmpty
()
)
dynamicPart
+=
rowFmtStr
.
arg
(
i18n
(
"Blog Feed"
)
).
arg
(
KStringHandler
::
tagUrls
(
blog
)
);
// Addresses
counter
=
0
;
foreach
(
const
KABC
::
Address
&
address
,
d
->
m
Contact
.
addresses
()
)
{
foreach
(
const
KABC
::
Address
&
address
,
raw
Contact
.
addresses
()
)
{
QString
formattedAddress
;
if
(
address
.
label
().
isEmpty
()
)
{
...
...
@@ -146,8 +136,8 @@ QString StandardContactFormatter::toHtml( HtmlForm form ) const
// Note
QString
notes
;
if
(
!
d
->
m
Contact
.
note
().
isEmpty
()
)
notes
=
rowFmtStr
.
arg
(
i18n
(
"Notes"
)
).
arg
(
d
->
m
Contact
.
note
().
replace
(
QLatin1Char
(
'\n'
),
QLatin1String
(
"<br>"
)
)
)
;
if
(
!
raw
Contact
.
note
().
isEmpty
()
)
notes
=
rowFmtStr
.
arg
(
i18n
(
"Notes"
)
).
arg
(
raw
Contact
.
note
().
replace
(
QLatin1Char
(
'\n'
),
QLatin1String
(
"<br>"
)
)
)
;
// Custom Data
QString
customData
;
...
...
@@ -173,8 +163,8 @@ QString StandardContactFormatter::toHtml( HtmlForm form ) const
blacklistedKeys
.
insert
(
QLatin1String
(
"CRYPTOENCRYPTPREF"
)
);
}
if
(
!
d
->
m
Contact
.
customs
().
empty
()
)
{
const
QStringList
customs
=
d
->
m
Contact
.
customs
();
if
(
!
raw
Contact
.
customs
().
empty
()
)
{
const
QStringList
customs
=
raw
Contact
.
customs
();
foreach
(
QString
custom
,
customs
)
{
//krazy:exclude=foreach
if
(
custom
.
startsWith
(
QLatin1String
(
"KADDRESSBOOK-"
)
)
)
{
custom
.
remove
(
QLatin1String
(
"KADDRESSBOOK-X-"
)
);
...
...
@@ -203,10 +193,9 @@ QString StandardContactFormatter::toHtml( HtmlForm form ) const
key
=
keyIt
.
value
();
}
else
{
// check whether it is a custom local field
foreach
(
const
QVariant
&
description
,
d
->
mCustomFieldDescriptions
)
{
const
QVariantMap
field
=
description
.
toMap
();
if
(
field
.
value
(
QLatin1String
(
"key"
)
).
toString
()
==
key
)
{
key
=
field
.
value
(
QLatin1String
(
"title"
)
).
toString
();
foreach
(
const
QVariantMap
&
description
,
customFieldDescriptions
()
)
{
if
(
description
.
value
(
QLatin1String
(
"key"
)
).
toString
()
==
key
)
{
key
=
description
.
value
(
QLatin1String
(
"title"
)
).
toString
();
break
;
}
}
...
...
@@ -218,11 +207,11 @@ QString StandardContactFormatter::toHtml( HtmlForm form ) const
}
// Assemble all parts
QString
role
=
d
->
m
Contact
.
title
();
QString
role
=
raw
Contact
.
title
();
if
(
role
.
isEmpty
()
)
role
=
d
->
m
Contact
.
role
();
role
=
raw
Contact
.
role
();
if
(
role
.
isEmpty
()
)
role
=
d
->
m
Contact
.
custom
(
QLatin1String
(
"KADDRESSBOOK"
),
QLatin1String
(
"X-Profession"
)
);
role
=
raw
Contact
.
custom
(
QLatin1String
(
"KADDRESSBOOK"
),
QLatin1String
(
"X-Profession"
)
);
QString
strAddr
=
QString
::
fromLatin1
(
"<div align=
\"
center
\"
>"
...
...
@@ -240,9 +229,9 @@ QString StandardContactFormatter::toHtml( HtmlForm form ) const
"<td align=
\"
left
\"
width=
\"
70%
\"
>%4</td>"
// organization
"</tr>"
)
.
arg
(
QLatin1String
(
"contact_photo"
)
)
.
arg
(
d
->
m
Contact
.
realName
()
)
.
arg
(
raw
Contact
.
realName
()
)
.
arg
(
role
)
.
arg
(
d
->
m
Contact
.
organization
()
);
.
arg
(
raw
Contact
.
organization
()
);
strAddr
.
append
(
dynamicPart
);
strAddr
.
append
(
notes
);
...
...
akonadi/contact/standardcontactformatter.h
View file @
4dd3676b
...
...
@@ -63,16 +63,6 @@ class AKONADI_CONTACT_EXPORT StandardContactFormatter : public AbstractContactFo
*/
virtual
~
StandardContactFormatter
();
/**
* Sets the @p contact that shall be formatted.
*/
virtual
void
setContact
(
const
KABC
::
Addressee
&
contact
);
/**
* Sets the custom field @p descriptions that shall be used.
*/
virtual
void
setCustomFieldDescriptions
(
const
QVariantList
&
descriptions
);
/**
* Returns the contact formatted as HTML
*/
...
...
@@ -82,8 +72,6 @@ class AKONADI_CONTACT_EXPORT StandardContactFormatter : public AbstractContactFo
//@cond PRIVATE
class
Private
;
Private
*
const
d
;
Q_DISABLE_COPY
(
StandardContactFormatter
)
//@endcond
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment