finalized refactorings
This commit is contained in:
parent
234d0b13c6
commit
85760efb5d
@ -30,7 +30,7 @@
|
||||
<url type="donation">https://martinrotter.github.io/donate/</url>
|
||||
<content_rating type="oars-1.1" />
|
||||
<releases>
|
||||
<release version="3.9.0" date="2021-03-19"/>
|
||||
<release version="3.9.0" date="2021-03-22"/>
|
||||
</releases>
|
||||
<content_rating type="oars-1.0">
|
||||
<content_attribute id="violence-cartoon">none</content_attribute>
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 9c10723bfbaf6cb85107d6ee16e0324e9e487749
|
||||
Subproject commit 47f4125753452eff8800dbd6600c5a05540b15d9
|
@ -2002,7 +2002,7 @@ void DatabaseQueries::removeMessageFilterFromFeed(const QSqlDatabase& db, const
|
||||
}
|
||||
}
|
||||
|
||||
QStringList DatabaseQueries::getAllRecipients(const QSqlDatabase& db, int account_id) {
|
||||
QStringList DatabaseQueries::getAllGmailRecipients(const QSqlDatabase& db, int account_id) {
|
||||
QSqlQuery query(db);
|
||||
QStringList rec;
|
||||
|
||||
|
@ -139,7 +139,7 @@ class DatabaseQueries {
|
||||
int account_id, bool* ok = nullptr);
|
||||
|
||||
// Gmail account.
|
||||
static QStringList getAllRecipients(const QSqlDatabase& db, int account_id);
|
||||
static QStringList getAllGmailRecipients(const QSqlDatabase& db, int account_id);
|
||||
|
||||
private:
|
||||
static QString unnulifyString(const QString& str);
|
||||
|
@ -234,9 +234,9 @@ bool AccountCheckModel::setData(const QModelIndex& index, const QVariant& value,
|
||||
// Check children of this new parent item.
|
||||
bool all_checked = true;
|
||||
bool all_unchecked = true;
|
||||
auto chi = item->childItems();
|
||||
auto childr = item->childItems();
|
||||
|
||||
for (RootItem* child_of_parent : qAsConst(chi)) {
|
||||
for (RootItem* child_of_parent : qAsConst(childr)) {
|
||||
if (m_checkStates.contains(child_of_parent)) {
|
||||
all_checked &= m_checkStates[child_of_parent] == Qt::CheckState::Checked;
|
||||
all_unchecked &= m_checkStates[child_of_parent] == Qt::CheckState::Unchecked;
|
||||
|
@ -391,8 +391,9 @@ void GmailNetworkFactory::onAuthFailed() {
|
||||
|
||||
bool GmailNetworkFactory::fillFullMessage(Message& msg, const QJsonObject& json, const QString& feed_id) {
|
||||
QHash<QString, QString> headers;
|
||||
auto json_headers = json["payload"].toObject()["headers"].toArray();
|
||||
|
||||
for (const QJsonValue& header : json["payload"].toObject()["headers"].toArray()) {
|
||||
for (const QJsonValue& header : qAsConst(json_headers)) {
|
||||
headers.insert(header.toObject()["name"].toString(), header.toObject()["value"].toString());
|
||||
}
|
||||
|
||||
@ -400,7 +401,9 @@ bool GmailNetworkFactory::fillFullMessage(Message& msg, const QJsonObject& json,
|
||||
msg.m_rawContents = QJsonDocument(json).toJson(QJsonDocument::JsonFormat::Compact);
|
||||
|
||||
// Assign correct main labels/states.
|
||||
for (const QVariant& label : json["labelIds"].toArray().toVariantList()) {
|
||||
auto labelids = json["labelIds"].toArray().toVariantList();
|
||||
|
||||
for (const QVariant& label : qAsConst(labelids)) {
|
||||
QString lbl = label.toString();
|
||||
|
||||
if (lbl == QL1S(GMAIL_SYSTEM_LABEL_UNREAD)) {
|
||||
@ -569,8 +572,7 @@ bool GmailNetworkFactory::obtainAndDecodeFullMessages(QList<Message>& messages,
|
||||
|
||||
if (res.first == QNetworkReply::NetworkError::NoError) {
|
||||
// We parse each part of HTTP response (it contains HTTP headers and payload with msg full data).
|
||||
for (const HttpResponse& part : output) {
|
||||
auto xx = part.body();
|
||||
for (const HttpResponse& part : qAsConst(output)) {
|
||||
QJsonObject msg_doc = QJsonDocument::fromJson(part.body().toUtf8()).object();
|
||||
QString msg_id = msg_doc["id"].toString();
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
#include "services/gmail/gmailserviceroot.h"
|
||||
|
||||
#include "miscellaneous/application.h"
|
||||
#include "database/databasequeries.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "network-web/oauth2service.h"
|
||||
#include "services/abstract/importantnode.h"
|
||||
@ -171,7 +171,9 @@ void GmailServiceRoot::start(bool freshly_activated) {
|
||||
syncIn();
|
||||
}
|
||||
|
||||
for (RootItem* feed : childItems()) {
|
||||
auto chi = childItems();
|
||||
|
||||
for (RootItem* feed : qAsConst(chi)) {
|
||||
if (feed->customId() == QL1S("INBOX")) {
|
||||
feed->setKeepOnTop(true);
|
||||
}
|
||||
|
@ -3,11 +3,11 @@
|
||||
#include "services/gmail/gui/formaddeditemail.h"
|
||||
|
||||
#include "3rd-party/mimesis/mimesis.hpp"
|
||||
#include "database/databasequeries.h"
|
||||
#include "exceptions/applicationexception.h"
|
||||
#include "gui/guiutilities.h"
|
||||
#include "gui/messagebox.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "database/databasequeries.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "services/gmail/gmailnetworkfactory.h"
|
||||
#include "services/gmail/gmailserviceroot.h"
|
||||
@ -38,11 +38,12 @@ FormAddEditEmail::FormAddEditEmail(GmailServiceRoot* root, QWidget* parent)
|
||||
this,
|
||||
&FormAddEditEmail::onOkClicked);
|
||||
|
||||
QSqlDatabase db = qApp->database()->driver()->connection(metaObject()->className());
|
||||
QSqlDatabase db = qApp->database()->driver()->connection(QSL("FormAddEditEmail"));
|
||||
|
||||
m_possibleRecipients = DatabaseQueries::getAllRecipients(db, m_root->accountId());
|
||||
m_possibleRecipients = DatabaseQueries::getAllGmailRecipients(db, m_root->accountId());
|
||||
auto ctrls = recipientControls();
|
||||
|
||||
for (auto* rec: recipientControls()) {
|
||||
for (auto* rec: qAsConst(ctrls)) {
|
||||
rec->setPossibleRecipients(m_possibleRecipients);
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ QNetworkReply::NetworkError GreaderNetwork::editLabels(const QString& state,
|
||||
}
|
||||
|
||||
QStringList trimmed_ids;
|
||||
QRegularExpression regex_short_id(QSL("[0-9a-zA-Z]+$"));
|
||||
|
||||
for (const QString& id : msg_custom_ids) {
|
||||
trimmed_ids.append(QString("i=") + id);
|
||||
@ -202,10 +201,11 @@ RootItem* GreaderNetwork::decodeTagsSubscriptions(const QString& categories, con
|
||||
// We need to process subscription list first and extract categories.
|
||||
json = QJsonDocument::fromJson(feeds.toUtf8()).object()["subscriptions"].toArray();
|
||||
|
||||
for (const QJsonValue& feed : json) {
|
||||
for (const QJsonValue& feed : qAsConst(json)) {
|
||||
auto subscription = feed.toObject();
|
||||
auto json_cats = subscription["categories"].toArray();
|
||||
|
||||
for (const QJsonValue& cat : subscription["categories"].toArray()) {
|
||||
for (const QJsonValue& cat : qAsConst(json_cats)) {
|
||||
auto cat_obj = cat.toObject();
|
||||
auto cat_id = cat_obj["id"].toString();
|
||||
|
||||
@ -225,7 +225,7 @@ RootItem* GreaderNetwork::decodeTagsSubscriptions(const QString& categories, con
|
||||
json = QJsonDocument::fromJson(categories.toUtf8()).object()["tags"].toArray();
|
||||
cats.insert(QString(), parent);
|
||||
|
||||
for (const QJsonValue& obj : json) {
|
||||
for (const QJsonValue& obj : qAsConst(json)) {
|
||||
auto label = obj.toObject();
|
||||
QString label_id = label["id"].toString();
|
||||
|
||||
@ -266,7 +266,7 @@ RootItem* GreaderNetwork::decodeTagsSubscriptions(const QString& categories, con
|
||||
|
||||
json = QJsonDocument::fromJson(feeds.toUtf8()).object()["subscriptions"].toArray();
|
||||
|
||||
for (const QJsonValue& obj : json) {
|
||||
for (const QJsonValue& obj : qAsConst(json)) {
|
||||
auto subscription = obj.toObject();
|
||||
QString id = subscription["id"].toString();
|
||||
QString title = subscription["title"].toString();
|
||||
@ -278,7 +278,7 @@ RootItem* GreaderNetwork::decodeTagsSubscriptions(const QString& categories, con
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const QJsonValue& cat : assigned_categories) {
|
||||
for (const QJsonValue& cat : qAsConst(assigned_categories)) {
|
||||
QString potential_id = cat.toObject()["id"].toString();
|
||||
|
||||
if (potential_id.contains(QSL("/label/"))) {
|
||||
@ -301,8 +301,6 @@ RootItem* GreaderNetwork::decodeTagsSubscriptions(const QString& categories, con
|
||||
: subscription["htmlUrl"].toString();
|
||||
|
||||
if (!icon_url.isEmpty()) {
|
||||
QByteArray icon_data;
|
||||
|
||||
if (icon_url.startsWith(QSL("//"))) {
|
||||
icon_url = QUrl(baseUrl()).scheme() + QSL(":") + icon_url;
|
||||
}
|
||||
|
@ -144,8 +144,9 @@ QList<RootItem*> InoreaderNetworkFactory::getLabels() {
|
||||
{},
|
||||
m_service->networkProxy());
|
||||
QJsonDocument json_lbls = QJsonDocument::fromJson(output);
|
||||
auto json_tags = json_lbls.object()["tags"].toArray();
|
||||
|
||||
for (const QJsonValue& lbl_val : json_lbls.object()["tags"].toArray()) {
|
||||
for (const QJsonValue& lbl_val : qAsConst(json_tags)) {
|
||||
QJsonObject lbl_obj = lbl_val.toObject();
|
||||
|
||||
if (lbl_obj["type"] == QL1S("tag")) {
|
||||
@ -400,7 +401,7 @@ RootItem* InoreaderNetworkFactory::decodeFeedCategoriesData(const QString& categ
|
||||
|
||||
json = QJsonDocument::fromJson(feeds.toUtf8()).object()["subscriptions"].toArray();
|
||||
|
||||
for (const QJsonValue& obj : json) {
|
||||
for (const QJsonValue& obj : qAsConst(json)) {
|
||||
auto subscription = obj.toObject();
|
||||
QString id = subscription["id"].toString();
|
||||
QString title = subscription["title"].toString();
|
||||
|
@ -494,7 +494,9 @@ RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons)
|
||||
cats.insert(QSL("0"), parent);
|
||||
|
||||
// Process categories first, then process feeds.
|
||||
for (const QJsonValue& cat : QJsonDocument::fromJson(m_contentCategories.toUtf8()).object()["folders"].toArray()) {
|
||||
auto json_folders = QJsonDocument::fromJson(m_contentCategories.toUtf8()).object()["folders"].toArray();
|
||||
|
||||
for (const QJsonValue& cat : qAsConst(json_folders)) {
|
||||
QJsonObject item = cat.toObject();
|
||||
auto* category = new Category();
|
||||
|
||||
@ -507,7 +509,9 @@ RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons)
|
||||
}
|
||||
|
||||
// We have categories added, now add all feeds.
|
||||
for (const QJsonValue& fed : QJsonDocument::fromJson(m_contentFeeds.toUtf8()).object()["feeds"].toArray()) {
|
||||
auto json_feeds = QJsonDocument::fromJson(m_contentFeeds.toUtf8()).object()["feeds"].toArray();
|
||||
|
||||
for (const QJsonValue& fed : qAsConst(json_feeds)) {
|
||||
QJsonObject item = fed.toObject();
|
||||
auto* feed = new OwnCloudFeed();
|
||||
|
||||
@ -571,8 +575,9 @@ OwnCloudGetMessagesResponse::~OwnCloudGetMessagesResponse() = default;
|
||||
|
||||
QList<Message>OwnCloudGetMessagesResponse::messages() const {
|
||||
QList<Message>msgs;
|
||||
auto json_items = m_rawContent["items"].toArray();
|
||||
|
||||
for (const QJsonValue& message : m_rawContent["items"].toArray()) {
|
||||
for (const QJsonValue& message : qAsConst(json_items)) {
|
||||
QJsonObject message_map = message.toObject();
|
||||
Message msg;
|
||||
|
||||
|
@ -112,7 +112,7 @@ QStringList FeedParser::textsFromPath(const QDomElement& element, const QString&
|
||||
}
|
||||
|
||||
if (!current_elements.isEmpty()) {
|
||||
for (const QDomElement& elem : current_elements) {
|
||||
for (const QDomElement& elem : qAsConst(current_elements)) {
|
||||
result.append(elem.text());
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ class StandardFeedDetails : public QWidget {
|
||||
public:
|
||||
explicit StandardFeedDetails(QWidget* parent = nullptr);
|
||||
|
||||
StandardFeed::SourceType sourceType() const;
|
||||
|
||||
private slots:
|
||||
void guessIconOnly(StandardFeed::SourceType source_type,
|
||||
const QString& source,
|
||||
@ -43,8 +45,6 @@ class StandardFeedDetails : public QWidget {
|
||||
void onLoadIconFromFile();
|
||||
void onUseDefaultIcon();
|
||||
|
||||
StandardFeed::SourceType sourceType() const;
|
||||
|
||||
private:
|
||||
void prepareForNewFeed(RootItem* parent_to_select, const QString& url);
|
||||
void setExistingFeed(StandardFeed* feed);
|
||||
|
@ -19,7 +19,9 @@ QList<Message> JsonParser::messages() const {
|
||||
global_author = json.object()["authors"].toArray().at(0).toObject()["name"].toString();
|
||||
}
|
||||
|
||||
for (const QJsonValue& msg_val : json.object()["items"].toArray()) {
|
||||
auto json_items = json.object()["items"].toArray();
|
||||
|
||||
for (const QJsonValue& msg_val : qAsConst(json_items)) {
|
||||
QJsonObject msg_obj = msg_val.toObject();
|
||||
Message msg;
|
||||
|
||||
@ -50,9 +52,10 @@ QList<Message> JsonParser::messages() const {
|
||||
msg.m_author = global_author;
|
||||
}
|
||||
|
||||
for (const QJsonValue& att : msg_obj["attachments"].toArray()) {
|
||||
auto json_att = msg_obj["attachments"].toArray();
|
||||
|
||||
for (const QJsonValue& att : qAsConst(json_att)) {
|
||||
QJsonObject att_obj = att.toObject();
|
||||
auto xx = att_obj["url"].toString();
|
||||
|
||||
msg.m_enclosures.append(Enclosure(att_obj["url"].toString(), att_obj["mime_type"].toString()));
|
||||
}
|
||||
|
@ -80,7 +80,9 @@ bool StandardCategory::removeItself() {
|
||||
|
||||
// Remove all child items (feeds and categories)
|
||||
// from the database.
|
||||
for (RootItem* child : childItems()) {
|
||||
auto chi = childItems();
|
||||
|
||||
for (RootItem* child : qAsConst(chi)) {
|
||||
if (child->kind() == RootItem::Kind::Category) {
|
||||
children_removed &= dynamic_cast<StandardCategory*>(child)->removeItself();
|
||||
}
|
||||
|
@ -65,8 +65,9 @@ bool FeedsImportExportModel::exportToOMPL20(QByteArray& result) {
|
||||
while (!items_to_process.isEmpty()) {
|
||||
QDomElement active_element = elements_to_use.pop();
|
||||
RootItem* active_item = items_to_process.pop();
|
||||
auto chi = active_item->childItems();
|
||||
|
||||
for (RootItem* child_item : active_item->childItems()) {
|
||||
for (RootItem* child_item : qAsConst(chi)) {
|
||||
if (!sourceModel()->isItemChecked(child_item)) {
|
||||
continue;
|
||||
}
|
||||
@ -313,7 +314,9 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m
|
||||
}
|
||||
|
||||
bool FeedsImportExportModel::exportToTxtURLPerLine(QByteArray& result) {
|
||||
for (const Feed* const feed : sourceModel()->rootItem()->getSubTreeFeeds()) {
|
||||
auto stf = sourceModel()->rootItem()->getSubTreeFeeds();
|
||||
|
||||
for (const Feed* const feed : qAsConst(stf)) {
|
||||
result += feed->source() + QL1S("\n");
|
||||
}
|
||||
|
||||
|
@ -272,7 +272,9 @@ QList<Message> StandardServiceRoot::obtainNewMessages(const QList<Feed*>& feeds,
|
||||
}
|
||||
|
||||
void StandardServiceRoot::checkArgumentsForFeedAdding() {
|
||||
for (const QString& arg : qApp->arguments().mid(1)) {
|
||||
auto args = qApp->arguments().mid(1);
|
||||
|
||||
for (const QString& arg : qAsConst(args)) {
|
||||
checkArgumentForFeedAdding(arg);
|
||||
}
|
||||
}
|
||||
@ -333,8 +335,9 @@ bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel* model,
|
||||
while (!new_parents.isEmpty()) {
|
||||
RootItem* target_parent = original_parents.pop();
|
||||
RootItem* source_parent = new_parents.pop();
|
||||
auto sour_chi = source_parent->childItems();
|
||||
|
||||
for (RootItem* source_item : source_parent->childItems()) {
|
||||
for (RootItem* source_item : qAsConst(sour_chi)) {
|
||||
if (!model->sourceModel()->isItemChecked(source_item)) {
|
||||
// We can skip this item, because it is not checked and should not be imported.
|
||||
// NOTE: All descendants are thus skipped too.
|
||||
@ -366,8 +369,9 @@ bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel* model,
|
||||
// already exists. If such a category exists in current parent, then find it and
|
||||
// add descendants to it.
|
||||
RootItem* existing_category = nullptr;
|
||||
auto tar_chi = target_parent->childItems();
|
||||
|
||||
for (RootItem* child : target_parent->childItems()) {
|
||||
for (RootItem* child : qAsConst(tar_chi)) {
|
||||
if (child->kind() == RootItem::Kind::Category && child->title() == new_category_title) {
|
||||
existing_category = child;
|
||||
}
|
||||
|
@ -697,7 +697,9 @@ RootItem* TtRssGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons, QS
|
||||
if (item_id == 0) {
|
||||
// This is "Uncategorized" category, all its feeds belong to top-level root.
|
||||
if (item.contains("items")) {
|
||||
for (const QJsonValue& child_feed : item["items"].toArray()) {
|
||||
auto ite = item["items"].toArray();
|
||||
|
||||
for (const QJsonValue& child_feed : qAsConst(ite)) {
|
||||
pairs.append(QPair<RootItem*, QJsonValue>(parent, child_feed));
|
||||
}
|
||||
}
|
||||
@ -710,7 +712,9 @@ RootItem* TtRssGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons, QS
|
||||
act_parent->appendChild(category);
|
||||
|
||||
if (item.contains("items")) {
|
||||
for (const QJsonValue& child : item["items"].toArray()) {
|
||||
auto ite = item["items"].toArray();
|
||||
|
||||
for (const QJsonValue& child : qAsConst(ite)) {
|
||||
pairs.append(QPair<RootItem*, QJsonValue>(category, child));
|
||||
}
|
||||
}
|
||||
@ -758,8 +762,9 @@ TtRssGetHeadlinesResponse::~TtRssGetHeadlinesResponse() = default;
|
||||
QList<Message> TtRssGetHeadlinesResponse::messages(ServiceRoot* root) const {
|
||||
QList<Message> messages;
|
||||
auto active_labels = root->labelsNode() != nullptr ? root->labelsNode()->labels() : QList<Label*>();
|
||||
auto json_msgs = m_rawContent["content"].toArray();
|
||||
|
||||
for (const QJsonValue& item : m_rawContent["content"].toArray()) {
|
||||
for (const QJsonValue& item : qAsConst(json_msgs)) {
|
||||
QJsonObject mapped = item.toObject();
|
||||
Message message;
|
||||
|
||||
@ -769,7 +774,9 @@ QList<Message> TtRssGetHeadlinesResponse::messages(ServiceRoot* root) const {
|
||||
message.m_contents = mapped["content"].toString();
|
||||
message.m_rawContents = QJsonDocument(mapped).toJson(QJsonDocument::JsonFormat::Compact);
|
||||
|
||||
for (const QJsonValue& lbl_val : mapped["labels"].toArray()) {
|
||||
auto json_labels = mapped["labels"].toArray();
|
||||
|
||||
for (const QJsonValue& lbl_val : qAsConst(json_labels)) {
|
||||
QString lbl_custom_id = QString::number(lbl_val.toArray().at(0).toInt());
|
||||
Label* label = boolinq::from(active_labels.begin(), active_labels.end()).firstOrDefault([lbl_custom_id](Label* lbl) {
|
||||
return lbl->customId() == lbl_custom_id;
|
||||
@ -797,7 +804,9 @@ QList<Message> TtRssGetHeadlinesResponse::messages(ServiceRoot* root) const {
|
||||
|
||||
if (mapped.contains(QSL("attachments"))) {
|
||||
// Process enclosures.
|
||||
for (const QJsonValue& attachment : mapped["attachments"].toArray()) {
|
||||
auto json_att = mapped["attachments"].toArray();
|
||||
|
||||
for (const QJsonValue& attachment : qAsConst(json_att)) {
|
||||
QJsonObject mapped_attachemnt = attachment.toObject();
|
||||
Enclosure enclosure;
|
||||
|
||||
@ -869,8 +878,9 @@ TtRssGetLabelsResponse::TtRssGetLabelsResponse(const QString& raw_content) : TtR
|
||||
|
||||
QList<RootItem*> TtRssGetLabelsResponse::labels() const {
|
||||
QList<RootItem*> labels;
|
||||
auto json_labels = m_rawContent["content"].toArray();
|
||||
|
||||
for (const QJsonValue& lbl_val : m_rawContent["content"].toArray()) {
|
||||
for (const QJsonValue& lbl_val : qAsConst(json_labels)) {
|
||||
QJsonObject lbl_obj = lbl_val.toObject();
|
||||
Label* lbl = new Label(lbl_obj["caption"].toString(), QColor(lbl_obj["fg_color"].toString()));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user