Fixed some clazy warning, gmail plugin now can mark msgs starred/read/unread.

This commit is contained in:
Martin Rotter 2017-10-27 20:38:01 +02:00
parent 1c364cb22a
commit d0154ca859
19 changed files with 103 additions and 144 deletions

View File

@ -19,7 +19,7 @@ FeedDownloader::FeedDownloader(QObject* parent)
m_results(FeedDownloadResults()), m_feedsUpdated(0),
m_feedsUpdating(0), m_feedsOriginalCount(0) {
qRegisterMetaType<FeedDownloadResults>("FeedDownloadResults");
m_threadPool->setMaxThreadCount(FEED_DOWNLOADER_MAX_THREADS);
m_threadPool->setMaxThreadCount(2);
}
FeedDownloader::~FeedDownloader() {

View File

@ -615,24 +615,24 @@ void FormMain::createConnections() {
connect(m_ui->m_actionSwitchStatusBar, &QAction::toggled, statusBar(), &StatusBar::setVisible);
// Menu "Tools" connections.
connect(m_ui->m_actionSettings, &QAction::triggered, [this]() {
connect(m_ui->m_actionSettings, &QAction::triggered, this, [this]() {
FormSettings(*this).exec();
});
connect(m_ui->m_actionDownloadManager, &QAction::triggered, m_ui->m_tabWidget, &TabWidget::showDownloadManager);
connect(m_ui->m_actionCleanupDatabase, &QAction::triggered, this, &FormMain::showDbCleanupAssistant);
// Menu "Help" connections.
connect(m_ui->m_actionAboutGuard, &QAction::triggered, [this]() {
connect(m_ui->m_actionAboutGuard, &QAction::triggered, this, [this]() {
FormAbout(this).exec();
});
connect(m_ui->m_actionCheckForUpdates, &QAction::triggered, [this]() {
connect(m_ui->m_actionCheckForUpdates, &QAction::triggered, this, [this]() {
FormUpdate(this).exec();
});
connect(m_ui->m_actionReportBug, &QAction::triggered, this, &FormMain::reportABug);
connect(m_ui->m_actionDonate, &QAction::triggered, this, &FormMain::donate);
connect(m_ui->m_actionDisplayWiki, &QAction::triggered, this, &FormMain::showWiki);
connect(m_ui->m_actionMessagePreviewEnabled, &QAction::toggled, [](bool enabled) {
connect(m_ui->m_actionMessagePreviewEnabled, &QAction::toggled, this, [](bool enabled) {
qApp->settings()->setValue(GROUP(Messages), Messages::EnableMessagePreview, enabled);
});

View File

@ -121,7 +121,7 @@ void FormSettings::addSettingsPanel(SettingsPanel* panel) {
m_panels.append(panel);
m_ui.m_stackedSettings->addWidget(panel);
panel->loadSettings();
connect(panel, &SettingsPanel::settingsChanged, [this]() {
connect(panel, &SettingsPanel::settingsChanged, this, [this]() {
m_btnApply->setEnabled(true);
});
}

View File

@ -54,7 +54,7 @@ bool FormUpdate::isSelfUpdateSupported() const {
}
void FormUpdate::checkForUpdates() {
connect(qApp->system(), &SystemFactory::updatesChecked, [this](QPair<QList<UpdateInfo>, QNetworkReply::NetworkError> update) {
connect(qApp->system(), &SystemFactory::updatesChecked, this, [this](QPair<QList<UpdateInfo>, QNetworkReply::NetworkError> update) {
m_ui.m_buttonBox->setEnabled(true);
disconnect(qApp->system(), &SystemFactory::updatesChecked, nullptr, nullptr);

View File

@ -45,7 +45,7 @@ MessagesView::MessagesView(QWidget* parent) : QTreeView(parent), m_contextMenu(n
setModel(m_proxyModel);
setupAppearance();
header()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(header(), &QHeaderView::customContextMenuRequested, [=](const QPoint& point) {
connect(header(), &QHeaderView::customContextMenuRequested, this, [=](const QPoint& point) {
TreeViewColumnsMenu mm(header());
mm.exec(header()->mapToGlobal(point));
});

View File

@ -15,13 +15,13 @@ SearchTextWidget::SearchTextWidget(QWidget* parent) : QWidget(parent) {
connect(m_ui.m_btnClear, &QToolButton::clicked, m_ui.m_txtSearch, &QLineEdit::clear);
connect(m_ui.m_txtSearch, &BaseLineEdit::textChanged, this, &SearchTextWidget::onTextChanged);
connect(m_ui.m_txtSearch, &BaseLineEdit::submitted, [this]() {
connect(m_ui.m_txtSearch, &BaseLineEdit::submitted, this, [this]() {
emit searchForText(m_ui.m_txtSearch->text(), false);
});
connect(m_ui.m_btnSearchForward, &QToolButton::clicked, [this]() {
connect(m_ui.m_btnSearchForward, &QToolButton::clicked, this, [this]() {
emit searchForText(m_ui.m_txtSearch->text(), false);
});
connect(m_ui.m_btnSearchBackward, &QToolButton::clicked, [this]() {
connect(m_ui.m_btnSearchBackward, &QToolButton::clicked, this, [this]() {
emit searchForText(m_ui.m_txtSearch->text(), true);
});
}

View File

@ -56,7 +56,7 @@ SettingsBrowserMail::SettingsBrowserMail(Settings* settings, QWidget* parent)
connect(m_ui->m_btnDeleteTool, &QPushButton::clicked, this, &SettingsBrowserMail::dirtifySettings);
connect(m_ui->m_btnAddTool, &QPushButton::clicked, this, &SettingsBrowserMail::addExternalTool);
connect(m_ui->m_btnDeleteTool, &QPushButton::clicked, this, &SettingsBrowserMail::deleteSelectedExternalTool);
connect(m_ui->m_listTools, &QTreeWidget::currentItemChanged, [this](QTreeWidgetItem* current, QTreeWidgetItem* previous) {
connect(m_ui->m_listTools, &QTreeWidget::currentItemChanged, this, [this](QTreeWidgetItem* current, QTreeWidgetItem* previous) {
Q_UNUSED(previous)
m_ui->m_btnDeleteTool->setEnabled(current != nullptr);

View File

@ -49,7 +49,7 @@ SystemTrayIcon::~SystemTrayIcon() {
hide();
}
void SystemTrayIcon::onActivated(const QSystemTrayIcon::ActivationReason& reason) {
void SystemTrayIcon::onActivated(QSystemTrayIcon::ActivationReason reason) {
switch (reason) {
case SystemTrayIcon::Trigger:
case SystemTrayIcon::DoubleClick:

View File

@ -38,9 +38,7 @@ class SystemTrayIcon : public QSystemTrayIcon {
public:
// Constructors and destructors.
explicit SystemTrayIcon(const QString& normal_icon,
const QString& plain_icon,
FormMain* parent = 0);
explicit SystemTrayIcon(const QString& normal_icon, const QString& plain_icon, FormMain* parent = nullptr);
virtual ~SystemTrayIcon();
// Sets the number to be visible in the tray icon, number <= 0 removes it.
@ -64,7 +62,7 @@ class SystemTrayIcon : public QSystemTrayIcon {
private slots:
void showPrivate();
void onActivated(const QSystemTrayIcon::ActivationReason& reason);
void onActivated(QSystemTrayIcon::ActivationReason reason);
signals:
void shown();

View File

@ -204,7 +204,7 @@ QString SystemFactory::loggedInUser() const {
void SystemFactory::checkForUpdates() const {
Downloader* downloader = new Downloader();
connect(downloader, &Downloader::completed, [this, downloader]() {
connect(downloader, &Downloader::completed, this, [this, downloader]() {
QPair<QList<UpdateInfo>, QNetworkReply::NetworkError> result;
result.second = downloader->lastOutputError();

View File

@ -596,6 +596,8 @@ void DownloadManager::setRemovePolicy(RemovePolicy policy) {
if (policy != m_removePolicy) {
m_removePolicy = policy;
m_autoSaver->changeOccurred();
emit removePolicyChanged();
}
}

View File

@ -82,7 +82,7 @@ class WebBrowser;
class DownloadManager : public TabContent {
Q_OBJECT
Q_PROPERTY(RemovePolicy removePolicy READ removePolicy WRITE setRemovePolicy)
Q_PROPERTY(RemovePolicy removePolicy READ removePolicy WRITE setRemovePolicy NOTIFY removePolicyChanged)
friend class DownloadModel;
@ -135,6 +135,7 @@ class DownloadManager : public TabContent {
void itemFinished();
signals:
void removePolicyChanged();
void downloadProgressed(int progress, const QString& description);
void downloadFinished();

View File

@ -150,12 +150,7 @@ void OAuth2Service::retrieveAccessToken(QString auth_code) {
"client_secret=%2&"
"code=%3&"
"redirect_uri=%5&"
"grant_type=%4")
.arg(m_clientId)
.arg(m_clientSecret)
.arg(auth_code)
.arg(m_tokenGrantType)
.arg(m_redirectUrl);
"grant_type=%4").arg(m_clientId, m_clientSecret, auth_code, m_tokenGrantType, m_redirectUrl);
m_networkManager.post(networkRequest, content.toUtf8());
}
@ -173,11 +168,7 @@ void OAuth2Service::refreshAccessToken(QString refresh_token) {
QString content = QString("client_id=%1&"
"client_secret=%2&"
"refresh_token=%3&"
"grant_type=%4")
.arg(m_clientId)
.arg(m_clientSecret)
.arg(refresh_token)
.arg("refresh_token");
"grant_type=%4").arg(m_clientId, m_clientSecret, refresh_token, QSL("refresh_token"));
qApp->showGuiMessage(tr("Logging in via OAuth 2.0..."),
tr("Refreshing login tokens for '%1'...").arg(m_tokenUrl.toString()),
@ -322,7 +313,7 @@ void OAuth2Service::retrieveAuthCode() {
OAuthLogin login_page(qApp->mainFormWidget());
connect(&login_page, &OAuthLogin::authGranted, this, &OAuth2Service::retrieveAccessToken);
connect(&login_page, &OAuthLogin::authRejected, [this]() {
connect(&login_page, &OAuthLogin::authRejected, this, [this]() {
logout();
emit authFailed();
});

View File

@ -7,10 +7,11 @@
#define GMAIL_OAUTH_TOKEN_URL "https://accounts.google.com/o/oauth2/token"
#define GMAIL_OAUTH_SCOPE "https://mail.google.com/"
#define GMAIL_API_GET_ATTACHMENT "https://www.googleapis.com/gmail/v1/users/me/messages/%20/attachments/"
#define GMAIL_API_LABELS_LIST "https://www.googleapis.com/gmail/v1/users/me/labels"
#define GMAIL_API_MSGS_LIST "https://www.googleapis.com/gmail/v1/users/me/messages"
#define GMAIL_API_BATCH "https://www.googleapis.com/batch"
#define GMAIL_API_BATCH_UPD_LABELS "https://www.googleapis.com/gmail/v1/users/me/messages/batchModify"
#define GMAIL_API_GET_ATTACHMENT "https://www.googleapis.com/gmail/v1/users/me/messages/%20/attachments/"
#define GMAIL_API_LABELS_LIST "https://www.googleapis.com/gmail/v1/users/me/labels"
#define GMAIL_API_MSGS_LIST "https://www.googleapis.com/gmail/v1/users/me/messages"
#define GMAIL_API_BATCH "https://www.googleapis.com/batch"
#define GMAIL_ATTACHMENT_SEP "####"
@ -27,5 +28,6 @@
#define GMAIL_SYSTEM_LABEL_TRASH "TRASH"
#define GMAIL_CONTENT_TYPE_HTTP "application/http"
#define GMAIL_CONTENT_TYPE_JSON "application/json"
#endif // GMAIL_DEFINITIONS_H

View File

@ -197,8 +197,7 @@ void GmailServiceRoot::saveAllCachedData(bool async) {
QStringList ids = i.value();
if (!ids.isEmpty()) {
// TODO: dodělat
//network()->markMessagesRead(key, ids, async);
network()->markMessagesRead(key, ids, async);
}
}
@ -218,8 +217,7 @@ void GmailServiceRoot::saveAllCachedData(bool async) {
custom_ids.append(msg.m_customId);
}
// TODO: dodělat
//network()->markMessagesStarred(key, custom_ids, async);
network()->markMessagesStarred(key, custom_ids, async);
}
}
}

View File

@ -18,7 +18,10 @@ FormDownloadAttachment::FormDownloadAttachment(const QString& target_file, Downl
GuiUtilities::applyDialogProperties(*this, qApp->icons()->fromTheme(QSL("mail-attachment")), tr("Downloading attachment..."));
connect(m_ui.m_btnBox->button(QDialogButtonBox::StandardButton::Abort), &QPushButton::clicked, downloader, &Downloader::cancel);
connect(downloader, &Downloader::completed, [this, downloader, target_file](QNetworkReply::NetworkError status, QByteArray contents) {
connect(downloader,
&Downloader::completed,
this,
[this, downloader, target_file](QNetworkReply::NetworkError status, QByteArray contents) {
if (status == QNetworkReply::NetworkError::NoError) {
QString data = QJsonDocument::fromJson(contents).object()["data"].toString();
@ -31,7 +34,7 @@ FormDownloadAttachment::FormDownloadAttachment(const QString& target_file, Downl
downloader->deleteLater();
close();
});
connect(downloader, &Downloader::progress, [this](qint64 bytes_received, qint64 bytes_total) {
connect(downloader, &Downloader::progress, this, [this](qint64 bytes_received, qint64 bytes_total) {
m_ui.m_lblInfo->setText(tr("Downloaded: %1 kB").arg(bytes_received / 1000.0));
if (m_ui.m_progressBar->maximum() == 0) {

View File

@ -54,7 +54,7 @@ void GmailNetworkFactory::setBatchSize(int batch_size) {
void GmailNetworkFactory::initializeOauth() {
connect(m_oauth2, &OAuth2Service::tokensRetrieveError, this, &GmailNetworkFactory::onTokensError);
connect(m_oauth2, &OAuth2Service::authFailed, this, &GmailNetworkFactory::onAuthFailed);
connect(m_oauth2, &OAuth2Service::tokensReceived, [this](QString access_token, QString refresh_token, int expires_in) {
connect(m_oauth2, &OAuth2Service::tokensReceived, this, [this](QString access_token, QString refresh_token, int expires_in) {
Q_UNUSED(expires_in)
if (m_service != nullptr && !access_token.isEmpty() && !refresh_token.isEmpty()) {
@ -186,18 +186,6 @@ QList<Message> GmailNetworkFactory::messages(const QString& stream_id, Feed::Sta
}
void GmailNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids, bool async) {
QString target_url;// TODO: dodělat
// = INOREADER_API_EDIT_TAG;
// TODO: dodělat
//
/*
if (status == RootItem::ReadStatus::Read) {
target_url += QString("?a=user/-/") + INOREADER_STATE_READ + "&";
}
else {
target_url += QString("?r=user/-/") + INOREADER_STATE_READ + "&";
}*/
QString bearer = m_oauth2->bearer().toLocal8Bit();
if (bearer.isEmpty()) {
@ -207,66 +195,49 @@ void GmailNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QS
QList<QPair<QByteArray, QByteArray>> headers;
headers.append(QPair<QByteArray, QByteArray>(QString(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(),
m_oauth2->bearer().toLocal8Bit()));
headers.append(QPair<QByteArray, QByteArray>(QString(HTTP_HEADERS_CONTENT_TYPE).toLocal8Bit(),
QString(GMAIL_CONTENT_TYPE_JSON).toLocal8Bit()));
QStringList trimmed_ids;
QRegularExpression regex_short_id(QSL("[0-9a-zA-Z]+$"));
int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
QJsonObject param_obj;
QJsonArray param_add, param_remove;
foreach (const QString& id, custom_ids) {
QString simplified_id = regex_short_id.match(id).captured();
trimmed_ids.append(QString("i=") + simplified_id);
if (status == RootItem::ReadStatus::Read) {
// We remove label UNREAD.
param_remove.append(GMAIL_SYSTEM_LABEL_UNREAD);
}
else {
// We add label UNREAD.
param_add.append(GMAIL_SYSTEM_LABEL_UNREAD);
}
QStringList working_subset;
int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
param_obj["addLabelIds"] = param_add;
param_obj["removeLabelIds"] = param_remove;
param_obj["ids"] = QJsonArray::fromStringList(custom_ids);
working_subset.reserve(trimmed_ids.size() > 200 ? 200 : trimmed_ids.size());
QJsonDocument param_doc(param_obj);
// Now, we perform messages update in batches (max 200 messages per batch).
while (!trimmed_ids.isEmpty()) {
// We take 200 IDs.
for (int i = 0; i < 200 && !trimmed_ids.isEmpty(); i++) {
working_subset.append(trimmed_ids.takeFirst());
}
// We send this batch.
if (async) {
NetworkFactory::performAsyncNetworkOperation(GMAIL_API_BATCH_UPD_LABELS,
timeout,
param_doc.toJson(QJsonDocument::JsonFormat::Compact),
QNetworkAccessManager::Operation::PostOperation,
headers);
}
else {
QByteArray output;
QString batch_final_url = target_url + working_subset.join(QL1C('&'));
// We send this batch.
if (async) {
NetworkFactory::performAsyncNetworkOperation(batch_final_url,
timeout,
QByteArray(),
QNetworkAccessManager::Operation::GetOperation,
headers);
}
else {
QByteArray output;
NetworkFactory::performNetworkOperation(batch_final_url,
timeout,
QByteArray(),
output,
QNetworkAccessManager::Operation::GetOperation,
headers);
}
// Cleanup for next batch.
working_subset.clear();
NetworkFactory::performNetworkOperation(GMAIL_API_BATCH_UPD_LABELS,
timeout,
param_doc.toJson(QJsonDocument::JsonFormat::Compact),
output,
QNetworkAccessManager::Operation::PostOperation,
headers);
}
}
void GmailNetworkFactory::markMessagesStarred(RootItem::Importance importance, const QStringList& custom_ids, bool async) {
QString target_url; // TODO: dodělat
//= INOREADER_API_EDIT_TAG;
/*
if (importance == RootItem::Importance::Important) {
target_url += QString("?a=user/-/") + INOREADER_STATE_IMPORTANT + "&";
}
else {
target_url += QString("?r=user/-/") + INOREADER_STATE_IMPORTANT + "&";
}*/
QString bearer = m_oauth2->bearer().toLocal8Bit();
if (bearer.isEmpty()) {
@ -276,52 +247,45 @@ void GmailNetworkFactory::markMessagesStarred(RootItem::Importance importance, c
QList<QPair<QByteArray, QByteArray>> headers;
headers.append(QPair<QByteArray, QByteArray>(QString(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(),
m_oauth2->bearer().toLocal8Bit()));
headers.append(QPair<QByteArray, QByteArray>(QString(HTTP_HEADERS_CONTENT_TYPE).toLocal8Bit(),
QString(GMAIL_CONTENT_TYPE_JSON).toLocal8Bit()));
QStringList trimmed_ids;
QRegularExpression regex_short_id(QSL("[0-9a-zA-Z]+$"));
int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
QJsonObject param_obj;
QJsonArray param_add, param_remove;
foreach (const QString& id, custom_ids) {
QString simplified_id = regex_short_id.match(id).captured();
trimmed_ids.append(QString("i=") + simplified_id);
if (importance == RootItem::Importance::Important) {
// We add label UNREAD.
param_add.append(GMAIL_SYSTEM_LABEL_STARRED);
}
else {
// We remove label UNREAD.
param_remove.append(GMAIL_SYSTEM_LABEL_STARRED);
}
QStringList working_subset;
int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
param_obj["addLabelIds"] = param_add;
param_obj["removeLabelIds"] = param_remove;
param_obj["ids"] = QJsonArray::fromStringList(custom_ids);
working_subset.reserve(trimmed_ids.size() > 200 ? 200 : trimmed_ids.size());
QJsonDocument param_doc(param_obj);
// Now, we perform messages update in batches (max 200 messages per batch).
while (!trimmed_ids.isEmpty()) {
// We take 200 IDs.
for (int i = 0; i < 200 && !trimmed_ids.isEmpty(); i++) {
working_subset.append(trimmed_ids.takeFirst());
}
// We send this batch.
if (async) {
NetworkFactory::performAsyncNetworkOperation(GMAIL_API_BATCH_UPD_LABELS,
timeout,
param_doc.toJson(QJsonDocument::JsonFormat::Compact),
QNetworkAccessManager::Operation::PostOperation,
headers);
}
else {
QByteArray output;
QString batch_final_url = target_url + working_subset.join(QL1C('&'));
// We send this batch.
if (async) {
NetworkFactory::performAsyncNetworkOperation(batch_final_url,
timeout,
QByteArray(),
QNetworkAccessManager::Operation::GetOperation,
headers);
}
else {
QByteArray output;
NetworkFactory::performNetworkOperation(batch_final_url,
timeout,
QByteArray(),
output,
QNetworkAccessManager::Operation::GetOperation,
headers);
}
// Cleanup for next batch.
working_subset.clear();
NetworkFactory::performNetworkOperation(GMAIL_API_BATCH_UPD_LABELS,
timeout,
param_doc.toJson(QJsonDocument::JsonFormat::Compact),
output,
QNetworkAccessManager::Operation::PostOperation,
headers);
}
}

View File

@ -52,7 +52,7 @@ void InoreaderNetworkFactory::setBatchSize(int batch_size) {
void InoreaderNetworkFactory::initializeOauth() {
connect(m_oauth2, &OAuth2Service::tokensRetrieveError, this, &InoreaderNetworkFactory::onTokensError);
connect(m_oauth2, &OAuth2Service::authFailed, this, &InoreaderNetworkFactory::onAuthFailed);
connect(m_oauth2, &OAuth2Service::tokensReceived, [this](QString access_token, QString refresh_token, int expires_in) {
connect(m_oauth2, &OAuth2Service::tokensReceived, this, [this](QString access_token, QString refresh_token, int expires_in) {
Q_UNUSED(expires_in)
if (m_service != nullptr && !access_token.isEmpty() && !refresh_token.isEmpty()) {

View File

@ -30,7 +30,7 @@ FormEditOwnCloudAccount::FormEditOwnCloudAccount(QWidget* parent)
tr("Limiting number of downloaded messages per feed makes updating of feeds faster but if your feed contains "
"bigger number of messages than specified limit, then some messages might not be downloaded during feed update."));
connect(m_ui->m_spinLimitMessages, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=](int value) {
connect(m_ui->m_spinLimitMessages, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, [=](int value) {
if (value <= 0) {
m_ui->m_spinLimitMessages->setSuffix(QSL(" ") + tr("= unlimited"));
}