tomboynotesresource.h 2.56 KB
Newer Older
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
/*
    Copyright (c) 2016 Stefan Stäglich <sstaeglich@kdemail.net>

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This library 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 Library General Public
    License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
*/

#ifndef TOMBOYNOTESRESOURCE_H
#define TOMBOYNOTESRESOURCE_H

#include <AkonadiAgentBase/ResourceBase>
#include <KIO/AccessManager>

Laurent Montel's avatar
Laurent Montel committed
26
class TomboyNotesResource : public Akonadi::ResourceBase, public Akonadi::AgentBase::Observer
27 28 29 30
{
    Q_OBJECT

public:
Laurent Montel's avatar
Laurent Montel committed
31 32
    explicit TomboyNotesResource(const QString &id);
    ~TomboyNotesResource() override;
33 34

public Q_SLOTS:
Laurent Montel's avatar
Laurent Montel committed
35
    void configure(WId windowId) override;
36

37 38 39
protected:
    using ResourceBase::retrieveItems; // Suppress -Woverload-virtual

40 41
protected Q_SLOTS:
    // Standard akonadi slots
Laurent Montel's avatar
Laurent Montel committed
42 43 44
    void retrieveCollections() override;
    void retrieveItems(const Akonadi::Collection &col) override;
    bool retrieveItem(const Akonadi::Item &item, const QSet<QByteArray> &parts) override;
45 46 47 48 49 50 51 52 53 54 55 56 57

    // Slots for Job result handling
    void onAuthorizationFinished(KJob *kjob);
    void onCollectionsRetrieved(KJob *kjob);
    void onItemChangeCommitted(KJob *kjob);
    void onItemRetrieved(KJob *kjob);
    void onItemsRetrieved(KJob *kjob);

private Q_SLOTS:
    // SSL error handling
    void onSslError(QNetworkReply *reply, const QList<QSslError> &errors);

protected:
Laurent Montel's avatar
Laurent Montel committed
58
    void aboutToQuit() override;
59 60

    // Standard akonadi
Laurent Montel's avatar
Laurent Montel committed
61 62 63
    void itemAdded(const Akonadi::Item &item, const Akonadi::Collection &collection) override;
    void itemChanged(const Akonadi::Item &item, const QSet<QByteArray> &parts) override;
    void itemRemoved(const Akonadi::Item &item) override;
64 65 66 67 68 69 70

private:
    bool configurationNotValid() const;

    void retryAfterFailure(const QString &errorMessage);
    // Status handling
    void showError(const QString &errorText);
Laurent Montel's avatar
Laurent Montel committed
71
    QTimer *mStatusMessageTimer = nullptr;
72 73 74 75

    // Only one UploadJob should run per time
    bool mUploadJobProcessRunning;

Laurent Montel's avatar
Laurent Montel committed
76
    KIO::AccessManager *mManager = nullptr;
77 78 79
};

#endif