summaryrefslogtreecommitdiff
path: root/migrationutility/googlesourceaccount.h
blob: 2085873dbcd56cbd8e9e2274aebaafd8eef9a778 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
 * Copyright (C) 2013  Christian Mollekopf <mollekopf@kolabsys.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef GOOGLESOURCEACCOUNT_H
#define GOOGLESOURCEACCOUNT_H

#include <libkgapi2/types.h>
#include <QStringList>

#include "sourceaccount.h"

namespace KGAPI2 {
class Job;
class FetchJob;
}

class GoogleSourceAccount: public SourceAccount
{
public:
    explicit GoogleSourceAccount(QObject* parent = 0);

    void setUser(const QString &username);
    virtual QPair<Kolab::FolderType, QString> translateFolder(const QString& folder);

    virtual KJob *login();
    virtual KJob *logout();

protected:
    KGAPI2::AccountPtr mAccount;
    QString mUser;
};

class GoogleContactsSourceAccount: public GoogleSourceAccount
{
public:
    explicit GoogleContactsSourceAccount(QObject* parent = 0);

    virtual QStringList lookupFolderList();
    virtual FetchObjectsJob *fetchObjects(const QString &folder);
};

class GoogleCalendarSourceAccount: public GoogleSourceAccount
{
    Q_OBJECT
public:
    explicit GoogleCalendarSourceAccount(QObject* parent = 0);

    virtual FetchFoldersJob *fetchFolderList();
    virtual FetchObjectsJob *fetchObjects(const QString &folder);
    virtual QPair<Kolab::FolderType, QString> translateFolder(const QString& folder);

private slots:
    void onFetchedCalendars(KJob *job);

private:
    QHash<QString, QString> mCalendarNames;
};

class GoogleTasksSourceAccount: public GoogleSourceAccount
{
    Q_OBJECT
public:
    explicit GoogleTasksSourceAccount(QObject* parent = 0);

    virtual FetchFoldersJob *fetchFolderList();
    virtual FetchObjectsJob *fetchObjects(const QString &folder);
    virtual QPair<Kolab::FolderType, QString> translateFolder(const QString& folder);

private slots:
    void onFetchedTasklists(KJob *job);

private:
    QHash<QString, QString> mTasklists;
};

class GoogleFetchObjectsJob : public FetchObjectsJob
{
    Q_OBJECT
public:
    explicit GoogleFetchObjectsJob(const QString &folder, const KGAPI2::AccountPtr &account, QObject* parent = 0);
    virtual void start();

protected:
    virtual Object getObject(const KGAPI2::ObjectPtr &) = 0;
    virtual KGAPI2::FetchJob *getFetchJob(const KGAPI2::AccountPtr &, const QString &folder) = 0;

private slots:
    void slotFetchJobFinished(KGAPI2::Job *job);

private:
    const KGAPI2::AccountPtr mAccount;
    const QString mCurrentFolder;
};

class FetchContactObjectsJob : public GoogleFetchObjectsJob
{
public:
    explicit FetchContactObjectsJob(const KGAPI2::AccountPtr &account, QObject* parent = 0);

protected:
    virtual KGAPI2::FetchJob* getFetchJob(const KGAPI2::AccountPtr &account, const QString& folder);
    virtual Object getObject(const KGAPI2::ObjectPtr &object);
};

class LoginJob : public KJob
{
    Q_OBJECT
public:
    explicit LoginJob(const KGAPI2::AccountPtr &account, QObject* parent = 0);
    virtual void start();

private slots:
    void slotAuthJobFinished(KGAPI2::Job *job);

private:
    KGAPI2::AccountPtr mAccount;
};

class FetchCalendarObjectsJob : public GoogleFetchObjectsJob
{
    Q_OBJECT
public:
    explicit FetchCalendarObjectsJob(const QString &mCalendarId, const KGAPI2::AccountPtr &account, QObject* parent = 0);

protected:
    virtual KGAPI2::FetchJob* getFetchJob(const KGAPI2::AccountPtr& , const QString& folder);
    virtual Object getObject(const KGAPI2::ObjectPtr& );
};

class FetchCalendarFoldersJob : public FetchFoldersJob
{
    Q_OBJECT
public:
    explicit FetchCalendarFoldersJob(const KGAPI2::AccountPtr &account, QObject* parent = 0);
    virtual void start();
    QHash<QString, QString> mNames;

private slots:
    void slotFetchJobFinished(KGAPI2::Job *job);

private:
    KGAPI2::AccountPtr mAccount;
};

class FetchTaskObjectsJob : public GoogleFetchObjectsJob
{
public:
    explicit FetchTaskObjectsJob(const QString &mTasklistId, const KGAPI2::AccountPtr &account, QObject* parent = 0);

protected:
    virtual KGAPI2::FetchJob* getFetchJob(const KGAPI2::AccountPtr& , const QString& folder);
    virtual Object getObject(const KGAPI2::ObjectPtr& );
};

class FetchTaskListsJob : public FetchFoldersJob
{
    Q_OBJECT
public:
    explicit FetchTaskListsJob(const KGAPI2::AccountPtr &account, QObject* parent = 0);
    virtual void start();
    QHash<QString, QString> mNames;

private slots:
    void slotFetchJobFinished(KGAPI2::Job *job);

private:
    KGAPI2::AccountPtr mAccount;
};

#endif