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
Akonadi
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
4
Merge Requests
4
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
Commits
5b5505ef
Commit
5b5505ef
authored
Sep 07, 2009
by
Volker Krause
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor itemSetToByteArray() to be usable for collections as well.
svn path=/trunk/KDE/kdepimlibs/; revision=1020872
parent
5b708d9f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
47 deletions
+47
-47
itemdeletejob.cpp
itemdeletejob.cpp
+1
-1
itemmovejob.cpp
itemmovejob.cpp
+1
-1
protocolhelper.cpp
protocolhelper.cpp
+0
-43
protocolhelper_p.h
protocolhelper_p.h
+44
-1
tests/protocolhelpertest.cpp
tests/protocolhelpertest.cpp
+1
-1
No files found.
itemdeletejob.cpp
View file @
5b5505ef
...
...
@@ -91,7 +91,7 @@ void ItemDeleteJob::doStart()
if
(
!
d
->
mItems
.
isEmpty
()
)
{
QByteArray
command
=
d
->
newTag
();
try
{
command
+=
ProtocolHelper
::
item
SetToByteArray
(
d
->
mItems
,
AKONADI_CMD_ITEMDELETE
);
command
+=
ProtocolHelper
::
entity
SetToByteArray
(
d
->
mItems
,
AKONADI_CMD_ITEMDELETE
);
}
catch
(
const
std
::
exception
&
e
)
{
setError
(
Unknown
);
setErrorText
(
QString
::
fromUtf8
(
e
.
what
()
)
);
...
...
itemmovejob.cpp
View file @
5b5505ef
...
...
@@ -77,7 +77,7 @@ void ItemMoveJob::doStart()
QByteArray
command
=
d
->
newTag
();
try
{
command
+=
ProtocolHelper
::
item
SetToByteArray
(
d
->
mItems
,
"MOVE"
);
command
+=
ProtocolHelper
::
entity
SetToByteArray
(
d
->
mItems
,
"MOVE"
);
}
catch
(
const
std
::
exception
&
e
)
{
setError
(
Unknown
);
setErrorText
(
QString
::
fromUtf8
(
e
.
what
()
)
);
...
...
protocolhelper.cpp
View file @
5b5505ef
...
...
@@ -25,8 +25,6 @@
#include "exception.h"
#include "itemserializer_p.h"
#include "itemserializerplugin.h"
#include <akonadi/private/imapparser_p.h>
#include <akonadi/private/protocol_p.h>
#include <QtCore/QDateTime>
#include <QtCore/QFile>
...
...
@@ -35,9 +33,6 @@
#include <kdebug.h>
#include <klocale.h>
#include <boost/bind.hpp>
#include <algorithm>
using
namespace
Akonadi
;
int
ProtocolHelper
::
parseCachePolicy
(
const
QByteArray
&
data
,
CachePolicy
&
policy
,
int
start
)
...
...
@@ -219,44 +214,6 @@ QByteArray ProtocolHelper::decodePartIdentifier( const QByteArray &data, PartNam
}
}
QByteArray
ProtocolHelper
::
itemSetToByteArray
(
const
Item
::
List
&
_items
,
const
QByteArray
&
command
)
{
if
(
_items
.
isEmpty
()
)
throw
Exception
(
"No items specified"
);
Item
::
List
items
(
_items
);
QByteArray
rv
;
std
::
sort
(
items
.
begin
(),
items
.
end
(),
boost
::
bind
(
&
Item
::
id
,
_1
)
<
boost
::
bind
(
&
Item
::
id
,
_2
)
);
if
(
items
.
first
().
isValid
()
)
{
// all items have a uid set
rv
+=
" "
AKONADI_CMD_UID
" "
;
rv
+=
command
;
rv
+=
' '
;
QList
<
Item
::
Id
>
uids
;
foreach
(
const
Item
&
item
,
items
)
uids
<<
item
.
id
();
ImapSet
set
;
set
.
add
(
uids
);
rv
+=
set
.
toImapSequenceSet
();
}
else
{
// check if all items have a remote id
QList
<
QByteArray
>
rids
;
foreach
(
const
Item
&
item
,
items
)
{
if
(
item
.
remoteId
().
isEmpty
()
)
throw
Exception
(
i18n
(
"No remote identifier specified"
)
);
rids
<<
ImapParser
::
quote
(
item
.
remoteId
().
toUtf8
()
);
}
rv
+=
" "
AKONADI_CMD_RID
" "
;
rv
+=
command
;
rv
+=
" ("
;
rv
+=
ImapParser
::
join
(
rids
,
" "
);
rv
+=
')'
;
}
return
rv
;
}
QByteArray
ProtocolHelper
::
hierarchicalRidToByteArray
(
const
Collection
&
col
)
{
if
(
col
==
Collection
::
root
()
)
...
...
protocolhelper_p.h
View file @
5b5505ef
...
...
@@ -25,6 +25,12 @@
#include <akonadi/item.h>
#include <akonadi/itemfetchscope.h>
#include <akonadi/private/imapparser_p.h>
#include <akonadi/private/protocol_p.h>
#include <boost/bind.hpp>
#include <algorithm>
namespace
Akonadi
{
/**
...
...
@@ -92,7 +98,44 @@ class ProtocolHelper
Converts the given set of items into a protocol representation.
@throws A Akonadi::Exception if the item set contains items with missing/invalid identifiers.
*/
static
QByteArray
itemSetToByteArray
(
const
Item
::
List
&
items
,
const
QByteArray
&
command
);
template
<
typename
T
>
static
QByteArray
entitySetToByteArray
(
const
QList
<
T
>
&
_objects
,
const
QByteArray
&
command
)
{
if
(
_objects
.
isEmpty
()
)
throw
Exception
(
"No objects specified"
);
typename
T
::
List
objects
(
_objects
);
QByteArray
rv
;
std
::
sort
(
objects
.
begin
(),
objects
.
end
(),
boost
::
bind
(
&
T
::
id
,
_1
)
<
boost
::
bind
(
&
T
::
id
,
_2
)
);
if
(
objects
.
first
().
isValid
()
)
{
// all items have a uid set
rv
+=
" "
AKONADI_CMD_UID
" "
;
rv
+=
command
;
rv
+=
' '
;
QList
<
typename
T
::
Id
>
uids
;
foreach
(
const
T
&
object
,
objects
)
uids
<<
object
.
id
();
ImapSet
set
;
set
.
add
(
uids
);
rv
+=
set
.
toImapSequenceSet
();
}
else
{
// check if all items have a remote id
QList
<
QByteArray
>
rids
;
foreach
(
const
T
&
object
,
objects
)
{
if
(
object
.
remoteId
().
isEmpty
()
)
throw
Exception
(
"No remote identifier specified"
);
rids
<<
ImapParser
::
quote
(
object
.
remoteId
().
toUtf8
()
);
}
rv
+=
" "
AKONADI_CMD_RID
" "
;
rv
+=
command
;
rv
+=
" ("
;
rv
+=
ImapParser
::
join
(
rids
,
" "
);
rv
+=
')'
;
}
return
rv
;
}
/**
Converts the given collection's hierarchical RID into a protocol representation.
...
...
tests/protocolhelpertest.cpp
View file @
5b5505ef
...
...
@@ -56,7 +56,7 @@ class ProtocolHelperTest : public QObject
bool
didThrow
=
false
;
try
{
const
QByteArray
r
=
ProtocolHelper
::
item
SetToByteArray
(
items
,
"CMD"
);
const
QByteArray
r
=
ProtocolHelper
::
entity
SetToByteArray
(
items
,
"CMD"
);
QCOMPARE
(
r
,
result
);
}
catch
(
const
std
::
exception
&
e
)
{
qDebug
()
<<
e
.
what
();
...
...
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