summaryrefslogtreecommitdiffstats
path: root/kresources/caldav/reader.cpp
blob: 892b490c6a6d03fbc88459a27a1bedbaadc61d22 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*=========================================================================
| KCalDAV
|--------------------------------------------------------------------------
| (c) 2010  Timothy Pearson
| (c) 2009  Kumaran Santhanam (initial KDE4 version)
|
| This project is released under the GNU General Public License.
| Please see the file COPYING for more details.
|--------------------------------------------------------------------------
| Remote calendar loading.
 ========================================================================*/

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

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

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

using namespace KCal;

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

void CalDavReader::cleanJob() {
    CalDavJob::cleanJob();
    mData = "";
}

void CalDavReader::cleanTasksJob() {
    CalDavJob::cleanJob();
    mTasksData = "";
}

void CalDavReader::cleanJournalsJob() {
    CalDavJob::cleanJob();
    mJournalsData = "";
}

int CalDavReader::runJob(runtime_info* RT) {
    kdDebug() << "reader::run, url: " << url();

    response* result = caldav_get_response();
    CALDAV_RESPONSE res = OK;

    if ((OK == res) && (url() != "")) {
      if (mGetAll) {
          kdDebug() << "getting all objects";
          res = caldav_getall_object(result, std::string(url().ascii()).c_str(), RT);
      } else {
          kdDebug() << "getting object from the specified time range";
          res = caldav_get_object(result, mTimeStart.toTime_t(), mTimeEnd.toTime_t(), std::string(url().ascii()).c_str(), RT);
      }

      if (OK == res) {
          kdDebug() << "success";
          if (result->msg) {
              mData = result->msg;
          } else {
              kdDebug() << "empty collection";
              // empty collection
              mData = "";
          }
      }
    }

    caldav_free_response(&result);

    return res;
}

int CalDavReader::runTasksJob(runtime_info* RT) {
    kdDebug() << "reader::run, tasksUrl: " << tasksUrl();

    response* result = caldav_get_response();
    CALDAV_RESPONSE tasksres = OK;

    if ((OK == tasksres) && (tasksUrl() != "")) {
      kdDebug() << "reader::run, url: " << tasksUrl();

      if (mGetAll) {
          kdDebug() << "getting all objects";
          tasksres = caldav_tasks_getall_object(result, std::string(tasksUrl().ascii()).c_str(), RT);
      } else {
          kdDebug() << "getting object from the specified time range";
          tasksres = caldav_tasks_get_object(result, mTimeStart.toTime_t(), mTimeEnd.toTime_t(), std::string(tasksUrl().ascii()).c_str(), RT);
      }

      if (OK == tasksres) {
          kdDebug() << "success";
          if (result->msg) {
              mTasksData = result->msg;
          } else {
              kdDebug() << "empty collection";
              // empty collection
              mTasksData = "";
          }
      }

      caldav_free_response(&result);
    }

    return tasksres;
}

int CalDavReader::runJournalsJob(runtime_info* RT) {
    kdDebug() << "reader::run, journalsUrl: " << journalsUrl();

    response* result = caldav_get_response();
    CALDAV_RESPONSE journalsres = OK;

    if ((OK == journalsres) && (journalsUrl() != "")) {
      kdDebug() << "reader::run, url: " << journalsUrl();

      if (mGetAll) {
          kdDebug() << "getting all objects";
          journalsres = caldav_tasks_getall_object(result, std::string(journalsUrl().ascii()).c_str(), RT);
      } else {
          kdDebug() << "getting object from the specified time range";
          journalsres = caldav_tasks_get_object(result, mTimeStart.toTime_t(), mTimeEnd.toTime_t(), std::string(journalsUrl().ascii()).c_str(), RT);
      }

      if (OK == journalsres) {
          kdDebug() << "success";
          if (result->msg) {
              mJournalsData = result->msg;
          } else {
              kdDebug() << "empty collection";
              // empty collection
              mJournalsData = "";
          }
      }

      caldav_free_response(&result);
    }

    return journalsres;
}

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