summaryrefslogtreecommitdiffstats
path: root/tderesources/carddav/reader.cpp
blob: eb5625060d1862d3660a4bdce2604d7e2cdf8a65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*=========================================================================
| KABCDAV
|--------------------------------------------------------------------------
| (c) 2010  Timothy Pearson
|
| This project is released under the GNU General Public License.
| Please see the file COPYING for more details.
|--------------------------------------------------------------------------
| Remote address book loading.
 ========================================================================*/

/*=========================================================================
| INCLUDES
 ========================================================================*/

#include "reader.h"
#include <kdebug.h>
#include <kcharsets.h>
#include <string>

/*=========================================================================
| NAMESPACE
 ========================================================================*/

using namespace TDEABC;

/*=========================================================================
| METHODS
 ========================================================================*/

void CardDavReader::cleanJob() {
    CardDavJob::cleanJob();
    mData = "";
}

int CardDavReader::runJob(runtime_info* RT) {
    kdDebug() << "reader::run, url: " << url() << '\n';

    response* result = carddav_get_response();
    CARDDAV_RESPONSE res = OK;

    kdDebug() << "getting all objects" << '\n';
    if (getUseURI() == false)
        res = carddav_getall_object(result, std::string(url().ascii()).c_str(), RT);
    else
        res = carddav_getall_object_by_uri(result, std::string(url().ascii()).c_str(), RT);

    if (OK == res) {
        kdDebug() << "success" << '\n';
        if (result->msg) {
            mData = KCharsets::resolveEntities(TQString::fromUtf8(result->msg));
        } else {
            kdDebug() << "empty collection" << '\n';
            // empty collection
            mData = "";
        }
    }

    carddav_free_response(&result);

    return res;
}

// EOF ========================================================================