This commit is contained in:
Martin Rotter 2021-04-01 07:22:33 +02:00
parent bbdf4eec7c
commit 0db772361d
6 changed files with 38 additions and 5 deletions

@ -1 +1 @@
Subproject commit 9c10723bfbaf6cb85107d6ee16e0324e9e487749 Subproject commit 47f4125753452eff8800dbd6600c5a05540b15d9

View file

@ -26,6 +26,7 @@
GmailNetworkFactory::GmailNetworkFactory(QObject* parent) : QObject(parent), GmailNetworkFactory::GmailNetworkFactory(QObject* parent) : QObject(parent),
m_service(nullptr), m_username(QString()), m_batchSize(GMAIL_DEFAULT_BATCH_SIZE), m_service(nullptr), m_username(QString()), m_batchSize(GMAIL_DEFAULT_BATCH_SIZE),
m_downloadOnlyUnreadMessages(false),
m_oauth2(new OAuth2Service(GMAIL_OAUTH_AUTH_URL, GMAIL_OAUTH_TOKEN_URL, m_oauth2(new OAuth2Service(GMAIL_OAUTH_AUTH_URL, GMAIL_OAUTH_TOKEN_URL,
{}, {}, GMAIL_OAUTH_SCOPE, this)) { {}, {}, GMAIL_OAUTH_SCOPE, this)) {
initializeOauth(); initializeOauth();
@ -140,6 +141,14 @@ void GmailNetworkFactory::initializeOauth() {
}); });
} }
bool GmailNetworkFactory::downloadOnlyUnreadMessages() const {
return m_downloadOnlyUnreadMessages;
}
void GmailNetworkFactory::setDownloadOnlyUnreadMessages(bool download_only_unread_messages) {
m_downloadOnlyUnreadMessages = download_only_unread_messages;
}
void GmailNetworkFactory::setOauth(OAuth2Service* oauth) { void GmailNetworkFactory::setOauth(OAuth2Service* oauth) {
m_oauth2 = oauth; m_oauth2 = oauth;
} }
@ -191,6 +200,10 @@ QList<Message> GmailNetworkFactory::messages(const QString& stream_id,
target_url = GMAIL_API_MSGS_LIST; target_url = GMAIL_API_MSGS_LIST;
target_url += QString("?labelIds=%1").arg(stream_id); target_url += QString("?labelIds=%1").arg(stream_id);
if (downloadOnlyUnreadMessages()) {
target_url += QString("?labelIds=%1").arg(GMAIL_SYSTEM_LABEL_UNREAD);
}
if (batchSize() > 0) { if (batchSize() > 0) {
target_url += QString("&maxResults=%1").arg(batchSize()); target_url += QString("&maxResults=%1").arg(batchSize());
} }

View file

@ -32,10 +32,12 @@ class GmailNetworkFactory : public QObject {
QString username() const; QString username() const;
void setUsername(const QString& username); void setUsername(const QString& username);
// Gets/sets the amount of messages to obtain during single feed update.
int batchSize() const; int batchSize() const;
void setBatchSize(int batch_size); void setBatchSize(int batch_size);
bool downloadOnlyUnreadMessages() const;
void setDownloadOnlyUnreadMessages(bool download_only_unread_messages);
// API methods. // API methods.
QString sendEmail(Mimesis::Message msg, const QNetworkProxy& custom_proxy, Message* reply_to_message = nullptr); QString sendEmail(Mimesis::Message msg, const QNetworkProxy& custom_proxy, Message* reply_to_message = nullptr);
Downloader* downloadAttachment(const QString& msg_id, const QString& attachment_id, const QNetworkProxy& custom_proxy); Downloader* downloadAttachment(const QString& msg_id, const QString& attachment_id, const QNetworkProxy& custom_proxy);
@ -67,6 +69,7 @@ class GmailNetworkFactory : public QObject {
GmailServiceRoot* m_service; GmailServiceRoot* m_service;
QString m_username; QString m_username;
int m_batchSize; int m_batchSize;
bool m_downloadOnlyUnreadMessages;
OAuth2Service* m_oauth2; OAuth2Service* m_oauth2;
}; };

View file

@ -54,6 +54,7 @@ QVariantHash GmailServiceRoot::customDatabaseData() const {
data["username"] = m_network->username(); data["username"] = m_network->username();
data["batch_size"] = m_network->batchSize(); data["batch_size"] = m_network->batchSize();
data["download_only_unread"] = m_network->downloadOnlyUnreadMessages();
data["client_id"] = m_network->oauth()->clientId(); data["client_id"] = m_network->oauth()->clientId();
data["client_secret"] = m_network->oauth()->clientSecret(); data["client_secret"] = m_network->oauth()->clientSecret();
data["refresh_token"] = m_network->oauth()->refreshToken(); data["refresh_token"] = m_network->oauth()->refreshToken();
@ -65,6 +66,7 @@ QVariantHash GmailServiceRoot::customDatabaseData() const {
void GmailServiceRoot::setCustomDatabaseData(const QVariantHash& data) { void GmailServiceRoot::setCustomDatabaseData(const QVariantHash& data) {
m_network->setUsername(data["username"].toString()); m_network->setUsername(data["username"].toString());
m_network->setBatchSize(data["batch_size"].toInt()); m_network->setBatchSize(data["batch_size"].toInt());
m_network->setDownloadOnlyUnreadMessages(data["download_only_unread"].toBool());
m_network->oauth()->setClientId(data["client_id"].toString()); m_network->oauth()->setClientId(data["client_id"].toString());
m_network->oauth()->setClientSecret(data["client_secret"].toString()); m_network->oauth()->setClientSecret(data["client_secret"].toString());
m_network->oauth()->setRefreshToken(data["refresh_token"].toString()); m_network->oauth()->setRefreshToken(data["refresh_token"].toString());

View file

@ -30,6 +30,7 @@ void FormEditGmailAccount::apply() {
account<GmailServiceRoot>()->network()->setUsername(m_details->m_ui.m_txtUsername->lineEdit()->text()); account<GmailServiceRoot>()->network()->setUsername(m_details->m_ui.m_txtUsername->lineEdit()->text());
account<GmailServiceRoot>()->network()->setBatchSize(m_details->m_ui.m_spinLimitMessages->value()); account<GmailServiceRoot>()->network()->setBatchSize(m_details->m_ui.m_spinLimitMessages->value());
account<GmailServiceRoot>()->network()->setDownloadOnlyUnreadMessages(m_details->m_ui.m_cbDownloadOnlyUnreadMessages->isChecked());
account<GmailServiceRoot>()->saveAccountDataToDatabase(); account<GmailServiceRoot>()->saveAccountDataToDatabase();
accept(); accept();
@ -53,4 +54,5 @@ void FormEditGmailAccount::loadAccountData() {
m_details->m_ui.m_txtUsername->lineEdit()->setText(account<GmailServiceRoot>()->network()->username()); m_details->m_ui.m_txtUsername->lineEdit()->setText(account<GmailServiceRoot>()->network()->username());
m_details->m_ui.m_spinLimitMessages->setValue(account<GmailServiceRoot>()->network()->batchSize()); m_details->m_ui.m_spinLimitMessages->setValue(account<GmailServiceRoot>()->network()->batchSize());
m_details->m_ui.m_cbDownloadOnlyUnreadMessages->setChecked(account<GmailServiceRoot>()->network()->downloadOnlyUnreadMessages());
} }

View file

@ -115,7 +115,7 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="2" column="0" colspan="2"> <item row="3" column="0" colspan="2">
<layout class="QFormLayout" name="formLayout_3"> <layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
@ -142,7 +142,7 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="3" column="0" colspan="2"> <item row="4" column="0" colspan="2">
<layout class="QFormLayout" name="formLayout_2"> <layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QPushButton" name="m_btnTestSetup"> <widget class="QPushButton" name="m_btnTestSetup">
@ -160,7 +160,7 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="4" column="0" colspan="2"> <item row="5" column="0" colspan="2">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -173,6 +173,13 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="m_cbDownloadOnlyUnreadMessages">
<property name="text">
<string>Download only unread messages</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
@ -189,6 +196,12 @@
<container>1</container> <container>1</container>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops>
<tabstop>m_btnRegisterApi</tabstop>
<tabstop>m_cbDownloadOnlyUnreadMessages</tabstop>
<tabstop>m_spinLimitMessages</tabstop>
<tabstop>m_btnTestSetup</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>