~renatofilho/buteo-syncfw/more-verbose

« back to all changes in this revision

Viewing changes to libsyncprofile/SyncResults.cpp

  • Committer: Sergey Gerasimenko
  • Date: 2010-06-29 12:51:21 UTC
  • Revision ID: git-v1:cd8dab07b102ac96752ece4f3cde5fc62697d717
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of buteo-syncfw package
 
3
 *
 
4
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 
5
 *
 
6
 * Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
 
7
 *
 
8
 * This library is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public License
 
10
 * version 2.1 as published by the Free Software Foundation.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
15
 * Lesser General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with this library; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
20
 * 02110-1301 USA
 
21
 *
 
22
 */
 
23
 
 
24
 
 
25
#include "SyncResults.h"
 
26
#include "LogMacros.h"
 
27
#include <QDomDocument>
 
28
 
 
29
#include "ProfileEngineDefs.h"
 
30
 
 
31
 
 
32
namespace Buteo {
 
33
    
 
34
// Private implementation class for SyncResults.
 
35
class SyncResultsPrivate
 
36
{
 
37
public:
 
38
    SyncResultsPrivate();
 
39
 
 
40
    SyncResultsPrivate(const SyncResultsPrivate &aSource);
 
41
 
 
42
    // List of target results.
 
43
    QList<TargetResults> iTargetResults;
 
44
 
 
45
    // Sync time.
 
46
    QDateTime iTime;
 
47
 
 
48
    // Sync result code.
 
49
    int iResultCode;
 
50
 
 
51
    //Sync target id
 
52
    QString iTargetId;
 
53
 
 
54
    bool iScheduled;
 
55
};
 
56
 
 
57
}
 
58
 
 
59
using namespace Buteo;
 
60
 
 
61
SyncResultsPrivate::SyncResultsPrivate()
 
62
:   iTime(QDateTime::currentDateTime()),
 
63
    iResultCode(0),
 
64
    iScheduled(false)
 
65
{
 
66
}
 
67
 
 
68
SyncResultsPrivate::SyncResultsPrivate(const SyncResultsPrivate &aSource)
 
69
:   iTargetResults(aSource.iTargetResults),
 
70
    iTime(aSource.iTime),
 
71
    iResultCode(aSource.iResultCode),
 
72
    iScheduled(aSource.iScheduled),
 
73
    iTargetId(aSource.iTargetId)
 
74
{
 
75
}
 
76
 
 
77
SyncResults::SyncResults()
 
78
:   d_ptr(new SyncResultsPrivate())
 
79
{
 
80
}
 
81
 
 
82
SyncResults::SyncResults(const SyncResults &aSource)
 
83
:   d_ptr(new SyncResultsPrivate(*aSource.d_ptr))
 
84
{
 
85
}
 
86
 
 
87
SyncResults::SyncResults(QDateTime aTime, int aResultCode)
 
88
:   d_ptr(new SyncResultsPrivate())
 
89
{
 
90
    d_ptr->iTime = aTime;
 
91
    d_ptr->iResultCode = aResultCode;
 
92
}
 
93
 
 
94
SyncResults::SyncResults(const QDomElement &aRoot)
 
95
:   d_ptr(new SyncResultsPrivate())
 
96
{
 
97
    d_ptr->iTime = QDateTime::fromString(aRoot.attribute(ATTR_TIME), Qt::ISODate);
 
98
    d_ptr->iResultCode = aRoot.attribute(ATTR_RESULT_CODE).toInt();
 
99
    d_ptr->iScheduled = (aRoot.attribute(KEY_SYNC_SCHEDULED) == BOOLEAN_TRUE);
 
100
 
 
101
    QDomElement target = aRoot.firstChildElement(TAG_TARGET_RESULTS);
 
102
    for (; !target.isNull();
 
103
         target = target.nextSiblingElement(TAG_TARGET_RESULTS))
 
104
    {
 
105
        d_ptr->iTargetResults.append(TargetResults(target));
 
106
    }
 
107
}
 
108
 
 
109
SyncResults::~SyncResults()
 
110
{
 
111
    delete d_ptr;
 
112
    d_ptr = 0;
 
113
}
 
114
 
 
115
SyncResults& SyncResults::operator=(const SyncResults &aRhs)
 
116
{
 
117
    if (&aRhs != this)
 
118
    {
 
119
        delete d_ptr;
 
120
        d_ptr = new SyncResultsPrivate(*aRhs.d_ptr);
 
121
    }
 
122
 
 
123
    return *this;
 
124
}
 
125
 
 
126
QDomElement SyncResults::toXml(QDomDocument &aDoc) const
 
127
{
 
128
    QDomElement root = aDoc.createElement(TAG_SYNC_RESULTS);
 
129
    root.setAttribute(ATTR_TIME, d_ptr->iTime.toString(Qt::ISODate));
 
130
    root.setAttribute(ATTR_RESULT_CODE, QString::number(d_ptr->iResultCode));
 
131
    root.setAttribute(KEY_SYNC_SCHEDULED, d_ptr->iScheduled ? BOOLEAN_TRUE :
 
132
        BOOLEAN_FALSE);
 
133
 
 
134
    foreach (TargetResults tr, d_ptr->iTargetResults)
 
135
    {
 
136
        root.appendChild(tr.toXml(aDoc));
 
137
    }
 
138
 
 
139
    return root;
 
140
}
 
141
 
 
142
QList<TargetResults> SyncResults::targetResults() const
 
143
{
 
144
    return d_ptr->iTargetResults;
 
145
}
 
146
 
 
147
void SyncResults::addTargetResults(const TargetResults &aResults)
 
148
{
 
149
    d_ptr->iTargetResults.append(aResults);
 
150
}
 
151
 
 
152
QDateTime SyncResults::syncTime() const
 
153
{
 
154
    return d_ptr->iTime;
 
155
}
 
156
 
 
157
int SyncResults::resultCode() const
 
158
{
 
159
    return d_ptr->iResultCode;
 
160
}
 
161
 
 
162
void SyncResults::setResultCode(int aResultCode)
 
163
{
 
164
  FUNCTION_CALL_TRACE;
 
165
    d_ptr->iResultCode = aResultCode;
 
166
}
 
167
 
 
168
void SyncResults::setTargetId(const QString& aTargetId) 
 
169
{
 
170
    d_ptr->iTargetId = aTargetId;
 
171
}
 
172
 
 
173
QString SyncResults::getTargetId() const
 
174
{
 
175
    return d_ptr->iTargetId;
 
176
}
 
177
 
 
178
bool SyncResults::operator<(const SyncResults &aOther) const
 
179
{
 
180
    return (d_ptr->iTime < aOther.d_ptr->iTime);
 
181
}
 
182
 
 
183
void SyncResults::setScheduled(bool aScheduled)
 
184
{
 
185
    d_ptr->iScheduled = aScheduled;
 
186
}
 
187
 
 
188
bool SyncResults::isScheduled() const
 
189
{
 
190
    return d_ptr->iScheduled;
 
191
}