Predefined folders for gmail.
This commit is contained in:
parent
1fbdfc796c
commit
5d51b8d28d
@ -69,6 +69,12 @@ QList<QAction*> ServiceRoot::serviceMenu() {
|
||||
return QList<QAction*>();
|
||||
}
|
||||
|
||||
void ServiceRoot::start(bool freshly_activated) {
|
||||
Q_UNUSED(freshly_activated)
|
||||
}
|
||||
|
||||
void ServiceRoot::stop() {}
|
||||
|
||||
void ServiceRoot::updateCounts(bool including_total_count) {
|
||||
QList<Feed*> feeds;
|
||||
|
||||
@ -187,6 +193,14 @@ QList<Message> ServiceRoot::undeletedMessages() const {
|
||||
return DatabaseQueries::getUndeletedMessagesForAccount(database, accountId());
|
||||
}
|
||||
|
||||
bool ServiceRoot::supportsFeedAdding() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServiceRoot::supportsCategoryAdding() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ServiceRoot::itemChanged(const QList<RootItem*>& items) {
|
||||
emit dataChanged(items);
|
||||
}
|
||||
@ -211,6 +225,12 @@ void ServiceRoot::requestItemRemoval(RootItem* item) {
|
||||
emit itemRemovalRequested(item);
|
||||
}
|
||||
|
||||
void ServiceRoot::addNewFeed(const QString& url) {
|
||||
Q_UNUSED(url)
|
||||
}
|
||||
|
||||
void ServiceRoot::addNewCategory() {}
|
||||
|
||||
QMap<QString, QVariant> ServiceRoot::storeCustomFeedsData() {
|
||||
QMap<QString, QVariant> custom_data;
|
||||
|
||||
|
@ -35,8 +35,8 @@ class ServiceRoot : public RootItem {
|
||||
virtual RecycleBin* recycleBin() const;
|
||||
|
||||
QList<Message> undeletedMessages() const;
|
||||
virtual bool supportsFeedAdding() const = 0;
|
||||
virtual bool supportsCategoryAdding() const = 0;
|
||||
virtual bool supportsFeedAdding() const;
|
||||
virtual bool supportsCategoryAdding() const;
|
||||
|
||||
// Returns list of specific actions for "Add new item" main window menu.
|
||||
// So typical list of returned actions could look like:
|
||||
@ -61,8 +61,8 @@ class ServiceRoot : public RootItem {
|
||||
//
|
||||
// Stop method is called just before application exits OR when
|
||||
// user explicitly deletes existing service instance.
|
||||
virtual void start(bool freshly_activated) = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void start(bool freshly_activated);
|
||||
virtual void stop();
|
||||
|
||||
// Account ID corresponds with DB attribute Accounts (id).
|
||||
int accountId() const;
|
||||
@ -145,8 +145,8 @@ class ServiceRoot : public RootItem {
|
||||
void requestItemRemoval(RootItem* item);
|
||||
|
||||
public slots:
|
||||
virtual void addNewFeed(const QString& url = QString()) = 0;
|
||||
virtual void addNewCategory() = 0;
|
||||
virtual void addNewFeed(const QString& url = QString());
|
||||
virtual void addNewCategory();
|
||||
virtual void syncIn();
|
||||
|
||||
protected:
|
||||
|
@ -9,6 +9,12 @@
|
||||
|
||||
GmailFeed::GmailFeed(RootItem* parent) : Feed(parent) {}
|
||||
|
||||
GmailFeed::GmailFeed(const QString& title, const QString& custom_id, const QIcon& icon, RootItem* parent) : GmailFeed(parent) {
|
||||
setTitle(title);
|
||||
setCustomId(custom_id);
|
||||
setIcon(icon);
|
||||
}
|
||||
|
||||
GmailFeed::GmailFeed(const QSqlRecord& record) : Feed(record) {}
|
||||
|
||||
GmailServiceRoot* GmailFeed::serviceRoot() const {
|
||||
|
@ -10,6 +10,7 @@ class GmailServiceRoot;
|
||||
class GmailFeed : public Feed {
|
||||
public:
|
||||
explicit GmailFeed(RootItem* parent = nullptr);
|
||||
explicit GmailFeed(const QString& title, const QString& custom_id, const QIcon& icon, RootItem* parent = nullptr);
|
||||
explicit GmailFeed(const QSqlRecord& record);
|
||||
|
||||
GmailServiceRoot* serviceRoot() const;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "network-web/oauth2service.h"
|
||||
#include "services/abstract/recyclebin.h"
|
||||
#include "services/gmail/gmailentrypoint.h"
|
||||
#include "services/gmail/gmailfeed.h"
|
||||
#include "services/gmail/network/gmailnetworkfactory.h"
|
||||
|
||||
GmailServiceRoot::GmailServiceRoot(GmailNetworkFactory* network, RootItem* parent) : ServiceRoot(parent),
|
||||
@ -47,13 +48,10 @@ void GmailServiceRoot::updateTitle() {
|
||||
}
|
||||
|
||||
void GmailServiceRoot::loadFromDatabase() {
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
Assignment categories = DatabaseQueries::getCategories(database, accountId());
|
||||
Assignment feeds = DatabaseQueries::getInoreaderFeeds(database, accountId());
|
||||
|
||||
// All data are now obtained, lets create the hierarchy.
|
||||
assembleCategories(categories);
|
||||
assembleFeeds(feeds);
|
||||
appendChild(new GmailFeed(tr("Inbox"), QSL("INBOX"), qApp->icons()->fromTheme(QSL("mail-inbox")), this));
|
||||
appendChild(new GmailFeed(tr("Sent"), QSL("SENT"), qApp->icons()->fromTheme(QSL("mail-sent")), this));
|
||||
appendChild(new GmailFeed(tr("Drafts"), QSL("DRAFT"), qApp->icons()->fromTheme(QSL("gtk-edit")), this));
|
||||
appendChild(new GmailFeed(tr("Spam"), QSL("SPAM"), qApp->icons()->fromTheme(QSL("mail-mark-junk")), this));
|
||||
|
||||
// As the last item, add recycle bin, which is needed.
|
||||
appendChild(recycleBin());
|
||||
@ -121,27 +119,12 @@ void GmailServiceRoot::start(bool freshly_activated) {
|
||||
loadCacheFromFile(accountId());
|
||||
|
||||
m_network->oauth()->login();
|
||||
|
||||
if (childCount() <= 1) {
|
||||
syncIn();
|
||||
}
|
||||
}
|
||||
|
||||
void GmailServiceRoot::stop() {
|
||||
saveCacheToFile(accountId());
|
||||
}
|
||||
|
||||
QList<QAction*> GmailServiceRoot::serviceMenu() {
|
||||
if (m_serviceMenu.isEmpty()) {
|
||||
QAction* act_sync_in = new QAction(qApp->icons()->fromTheme(QSL("view-refresh")), tr("Sync in"), this);
|
||||
|
||||
connect(act_sync_in, &QAction::triggered, this, &GmailServiceRoot::syncIn);
|
||||
m_serviceMenu.append(act_sync_in);
|
||||
}
|
||||
|
||||
return m_serviceMenu;
|
||||
}
|
||||
|
||||
QString GmailServiceRoot::code() const {
|
||||
return GmailEntryPoint().code();
|
||||
}
|
||||
@ -153,16 +136,6 @@ QString GmailServiceRoot::additionalTooltip() const {
|
||||
network()->oauth()->tokensExpireIn().toString() : QSL("-"));
|
||||
}
|
||||
|
||||
RootItem* GmailServiceRoot::obtainNewTreeForSyncIn() const {
|
||||
return m_network->feedsCategories();
|
||||
}
|
||||
|
||||
void GmailServiceRoot::addNewFeed(const QString& url) {
|
||||
Q_UNUSED(url)
|
||||
}
|
||||
|
||||
void GmailServiceRoot::addNewCategory() {}
|
||||
|
||||
void GmailServiceRoot::saveAllCachedData(bool async) {
|
||||
QPair<QMap<RootItem::ReadStatus, QStringList>, QMap<RootItem::Importance, QList<Message>>> msgCache = takeMessageCache();
|
||||
QMapIterator<RootItem::ReadStatus, QStringList> i(msgCache.first);
|
||||
|
@ -49,18 +49,13 @@ class GmailServiceRoot : public ServiceRoot, public CacheForServiceRoot {
|
||||
|
||||
QString additionalTooltip() const;
|
||||
|
||||
RootItem* obtainNewTreeForSyncIn() const;
|
||||
|
||||
void saveAllCachedData(bool async = true);
|
||||
|
||||
public slots:
|
||||
void addNewFeed(const QString& url);
|
||||
void addNewCategory();
|
||||
void updateTitle();
|
||||
|
||||
private:
|
||||
void loadFromDatabase();
|
||||
QList<QAction*> serviceMenu();
|
||||
|
||||
private:
|
||||
QList<QAction*> m_serviceMenu;
|
||||
|
@ -70,32 +70,33 @@ void GmailNetworkFactory::setUsername(const QString& username) {
|
||||
m_username = username;
|
||||
}
|
||||
|
||||
RootItem* GmailNetworkFactory::feedsCategories() {
|
||||
Downloader downloader;
|
||||
QEventLoop loop;
|
||||
QString bearer = m_oauth2->bearer().toLocal8Bit();
|
||||
/*
|
||||
RootItem* GmailNetworkFactory::feedsCategories() {
|
||||
Downloader downloader;
|
||||
QEventLoop loop;
|
||||
QString bearer = m_oauth2->bearer().toLocal8Bit();
|
||||
|
||||
if (bearer.isEmpty()) {
|
||||
if (bearer.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
downloader.appendRawHeader(QString(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(), bearer.toLocal8Bit());
|
||||
downloader.appendRawHeader(QString(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(), bearer.toLocal8Bit());
|
||||
|
||||
// We need to quit event loop when the download finishes.
|
||||
connect(&downloader, &Downloader::completed, &loop, &QEventLoop::quit);
|
||||
// We need to quit event loop when the download finishes.
|
||||
connect(&downloader, &Downloader::completed, &loop, &QEventLoop::quit);
|
||||
|
||||
// TODO: dodělat
|
||||
downloader.manipulateData(GMAIL_API_LABELS_LIST, QNetworkAccessManager::Operation::GetOperation);
|
||||
loop.exec();
|
||||
// TODO: dodělat
|
||||
downloader.manipulateData(GMAIL_API_LABELS_LIST, QNetworkAccessManager::Operation::GetOperation);
|
||||
loop.exec();
|
||||
|
||||
if (downloader.lastOutputError() != QNetworkReply::NetworkError::NoError) {
|
||||
if (downloader.lastOutputError() != QNetworkReply::NetworkError::NoError) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
QString category_data = downloader.lastOutputData();
|
||||
QString category_data = downloader.lastOutputData();
|
||||
|
||||
return decodeFeedCategoriesData(category_data);
|
||||
}
|
||||
return decodeFeedCategoriesData(category_data);
|
||||
}*/
|
||||
|
||||
QList<Message> GmailNetworkFactory::messages(const QString& stream_id, Feed::Status& error) {
|
||||
Downloader downloader;
|
||||
@ -356,14 +357,15 @@ QList<Message> GmailNetworkFactory::decodeMessages(const QString& messages_json_
|
||||
return messages;
|
||||
}
|
||||
|
||||
RootItem* GmailNetworkFactory::decodeFeedCategoriesData(const QString& categories) {
|
||||
RootItem* parent = new RootItem();
|
||||
QJsonArray json = QJsonDocument::fromJson(categories.toUtf8()).object()["labels"].toArray();
|
||||
/*
|
||||
RootItem* GmailNetworkFactory::decodeFeedCategoriesData(const QString& categories) {
|
||||
RootItem* parent = new RootItem();
|
||||
QJsonArray json = QJsonDocument::fromJson(categories.toUtf8()).object()["labels"].toArray();
|
||||
|
||||
QMap<QString, RootItem*> cats;
|
||||
cats.insert(QString(), parent);
|
||||
QMap<QString, RootItem*> cats;
|
||||
cats.insert(QString(), parent);
|
||||
|
||||
foreach (const QJsonValue& obj, json) {
|
||||
foreach (const QJsonValue& obj, json) {
|
||||
auto label = obj.toObject();
|
||||
QString label_id = label["id"].toString();
|
||||
QString label_name = label["name"].toString();
|
||||
@ -381,7 +383,7 @@ RootItem* GmailNetworkFactory::decodeFeedCategoriesData(const QString& categorie
|
||||
parent->appendChild(feed);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
if (label_id.contains(QSL("/label/"))) {
|
||||
// We have label (not "state").
|
||||
Category* category = new Category();
|
||||
@ -394,10 +396,9 @@ RootItem* GmailNetworkFactory::decodeFeedCategoriesData(const QString& categorie
|
||||
|
||||
// All categories in ownCloud are top-level.
|
||||
parent->appendChild(category);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
json = QJsonDocument::fromJson(feeds.toUtf8()).object()["subscriptions"].toArray();
|
||||
|
||||
foreach (const QJsonValue& obj, json) {
|
||||
@ -428,7 +429,8 @@ RootItem* GmailNetworkFactory::decodeFeedCategoriesData(const QString& categorie
|
||||
if (cats.contains(parent_label)) {
|
||||
cats[parent_label]->appendChild(feed);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
return parent;
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
*/
|
||||
|
@ -36,7 +36,7 @@ class GmailNetworkFactory : public QObject {
|
||||
// Returns tree of feeds/categories.
|
||||
// Top-level root of the tree is not needed here.
|
||||
// Returned items do not have primary IDs assigned.
|
||||
RootItem* feedsCategories();
|
||||
//RootItem* feedsCategories();
|
||||
|
||||
QList<Message> messages(const QString& stream_id, Feed::Status& error);
|
||||
void markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids, bool async = true);
|
||||
@ -48,7 +48,8 @@ class GmailNetworkFactory : public QObject {
|
||||
|
||||
private:
|
||||
QList<Message> decodeMessages(const QString& messages_json_data, const QString& stream_id);
|
||||
RootItem* decodeFeedCategoriesData(const QString& categories);
|
||||
|
||||
//RootItem* decodeFeedCategoriesData(const QString& categories);
|
||||
|
||||
void initializeOauth();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user