Early out parsing if we're only processing incoming OR outgoing.
[qwerkisync] / AttachmentCollection.cpp
1 /*
2  * Copyright (C) 2011, Jamie Thompson
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public
6  * License as published by the Free Software Foundation; either
7  * version 3 of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this program; If not, see
16  * <http://www.gnu.org/licenses/>.
17  */
18
19 #include <rtcom-eventlogger/eventlogger-attach-iter.h>
20 #include <rtcom-eventlogger/event.h>
21
22 #include "AttachmentCollection.h"
23
24 #include <QHash>
25
26 #include "Attachment.h"
27
28 const uint AttachmentCollection::HashCode() const
29 {
30         uint hashCode = qHash(size());
31
32         if(size() > 0)
33         {
34                 foreach(QSharedPointer<Attachment> attachment, *this)
35                 {
36                         qDebug() << attachment->Description();
37                         qDebug() << attachment->Path();
38                         hashCode ^= attachment->HashCode();
39                 }
40         }
41         return hashCode;
42 }
43
44 GList * AttachmentCollection::toRTComAttachments() const
45 {
46         GList *rattachments(NULL);
47
48         foreach(QSharedPointer<Attachment> attachment, *this)
49                 rattachments = g_list_prepend(rattachments, attachment->toRTComAttachment());
50
51         return rattachments;
52 }
53
54 void AttachmentCollection::freeRTComContents(GList &attachments)
55 {
56         for (GList *attachment(&attachments); NULL != attachment; attachment = attachment->next)
57         {
58                 Attachment::freeRTComContents(*(RTComElAttachment*)attachment->data);
59                 rtcom_el_free_attachment((RTComElAttachment*)attachment->data);
60         }
61
62         g_list_free (&attachments);
63 }