diff --git a/src/author.cpp b/src/author.cpp index 6c0566dc..f8d48179 100644 --- a/src/author.cpp +++ b/src/author.cpp @@ -6,7 +6,7 @@ #include "author.h" -Author::Author(QString name, QString email, QString url, QObject *parent) +Author::Author(const QString &name, const QString &email, const QString &url, QObject *parent) : QObject(parent) , m_name(name) , m_email(email) diff --git a/src/author.h b/src/author.h index 81eeaa54..bca834f4 100644 --- a/src/author.h +++ b/src/author.h @@ -18,7 +18,7 @@ class Author : public QObject Q_PROPERTY(QString url READ url CONSTANT) public: - Author(QString name, QString email, QString url, QObject *parent = nullptr); + Author(const QString &name, const QString &email, const QString &url, QObject *parent = nullptr); ~Author(); QString name() const; diff --git a/src/database.cpp b/src/database.cpp index 0bf0d055..9dff87c2 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -54,7 +54,7 @@ bool Database::migrateTo1() return true; } -bool Database::execute(QString query) +bool Database::execute(const QString &query) { QSqlQuery q; q.prepare(query); @@ -118,7 +118,7 @@ void Database::cleanup() } } -bool Database::feedExists(QString url) +bool Database::feedExists(const QString &url) { QSqlQuery query; query.prepare(QStringLiteral("SELECT COUNT (url) FROM Feeds WHERE url=:url;")); @@ -128,7 +128,7 @@ bool Database::feedExists(QString url) return query.value(0).toInt() != 0; } -void Database::addFeed(QString url) +void Database::addFeed(const QString &url) { qDebug() << "Adding feed"; if (feedExists(url)) { @@ -157,7 +157,7 @@ void Database::addFeed(QString url) Fetcher::instance().fetch(urlFromInput.toString()); } -void Database::importFeeds(QString path) +void Database::importFeeds(const QString &path) { QUrl url(path); QFile file(url.isLocalFile() ? url.toLocalFile() : url.toString()); @@ -173,7 +173,7 @@ void Database::importFeeds(QString path) Fetcher::instance().fetchAll(); } -void Database::exportFeeds(QString path) +void Database::exportFeeds(const QString &path) { QUrl url(path); QFile file(url.isLocalFile() ? url.toLocalFile() : url.toString()); diff --git a/src/database.h b/src/database.h index 7c0cfd7b..216bbc8c 100644 --- a/src/database.h +++ b/src/database.h @@ -19,13 +19,13 @@ public: return _instance; } bool execute(QSqlQuery &query); - bool execute(QString query); - Q_INVOKABLE void addFeed(QString url); - Q_INVOKABLE void importFeeds(QString path); - Q_INVOKABLE void exportFeeds(QString path); + bool execute(const QString &query); + Q_INVOKABLE void addFeed(const QString &url); + Q_INVOKABLE void importFeeds(const QString &path); + Q_INVOKABLE void exportFeeds(const QString &path); Q_SIGNALS: - void feedAdded(QString url); + void feedAdded(const QString &url); private: Database(); @@ -34,5 +34,5 @@ private: bool migrate(); bool migrateTo1(); void cleanup(); - bool feedExists(QString url); + bool feedExists(const QString &url); }; diff --git a/src/entriesmodel.cpp b/src/entriesmodel.cpp index cb2673fc..352682b6 100644 --- a/src/entriesmodel.cpp +++ b/src/entriesmodel.cpp @@ -16,7 +16,7 @@ EntriesModel::EntriesModel(Feed *feed) : QAbstractListModel(feed) , m_feed(feed) { - connect(&Fetcher::instance(), &Fetcher::feedUpdated, this, [this](QString url) { + connect(&Fetcher::instance(), &Fetcher::feedUpdated, this, [this](const QString &url) { if (m_feed->url() == url) { beginResetModel(); for (auto &entry : m_entries) { diff --git a/src/feed.cpp b/src/feed.cpp index 08663d15..6788d3a9 100644 --- a/src/feed.cpp +++ b/src/feed.cpp @@ -46,12 +46,12 @@ Feed::Feed(int index) m_errorId = 0; m_errorString = QLatin1String(""); - connect(&Fetcher::instance(), &Fetcher::startedFetchingFeed, this, [this](QString url) { + connect(&Fetcher::instance(), &Fetcher::startedFetchingFeed, this, [this](const QString &url) { if (url == m_url) { setRefreshing(true); } }); - connect(&Fetcher::instance(), &Fetcher::feedUpdated, this, [this](QString url) { + connect(&Fetcher::instance(), &Fetcher::feedUpdated, this, [this](const QString &url) { if (url == m_url) { setRefreshing(false); Q_EMIT entryCountChanged(); @@ -60,14 +60,14 @@ Feed::Feed(int index) setErrorString(QLatin1String("")); } }); - connect(&Fetcher::instance(), &Fetcher::error, this, [this](QString url, int errorId, QString errorString) { + connect(&Fetcher::instance(), &Fetcher::error, this, [this](const QString &url, int errorId, const QString &errorString) { if(url == m_url) { setErrorId(errorId); setErrorString(errorString); setRefreshing(false); } }); - connect(&Fetcher::instance(), &Fetcher::imageDownloadFinished, this, [this](QString url) { + connect(&Fetcher::instance(), &Fetcher::imageDownloadFinished, this, [this](const QString &url) { if(url == m_image) Q_EMIT imageChanged(url); }); @@ -171,31 +171,31 @@ QString Feed::errorString() const return m_errorString; } -void Feed::setName(QString name) +void Feed::setName(const QString &name) { m_name = name; Q_EMIT nameChanged(m_name); } -void Feed::setImage(QString image) +void Feed::setImage(const QString &image) { m_image = image; Q_EMIT imageChanged(m_image); } -void Feed::setLink(QString link) +void Feed::setLink(const QString &link) { m_link = link; Q_EMIT linkChanged(m_link); } -void Feed::setDescription(QString description) +void Feed::setDescription(const QString &description) { m_description = description; Q_EMIT descriptionChanged(m_description); } -void Feed::setAuthors(QVector authors) +void Feed::setAuthors(const QVector &authors) { m_authors = authors; Q_EMIT authorsChanged(m_authors); @@ -213,7 +213,7 @@ void Feed::setDeleteAfterType(int type) Q_EMIT deleteAfterTypeChanged(m_deleteAfterType); } -void Feed::setLastUpdated(QDateTime lastUpdated) +void Feed::setLastUpdated(const QDateTime &lastUpdated) { m_lastUpdated = lastUpdated; Q_EMIT lastUpdatedChanged(m_lastUpdated); @@ -237,7 +237,7 @@ void Feed::setErrorId(int errorId) Q_EMIT errorIdChanged(m_errorId); } -void Feed::setErrorString(QString errorString) +void Feed::setErrorString(const QString &errorString) { m_errorString = errorString; Q_EMIT errorStringChanged(m_errorString); diff --git a/src/feed.h b/src/feed.h index ce14f8f4..9ee6269c 100644 --- a/src/feed.h +++ b/src/feed.h @@ -60,36 +60,36 @@ public: bool refreshing() const; - void setName(QString name); - void setImage(QString image); - void setLink(QString link); - void setDescription(QString description); - void setAuthors(QVector authors); + void setName(const QString &name); + void setImage(const QString &image); + void setLink(const QString &link); + void setDescription(const QString &description); + void setAuthors(const QVector &authors); void setDeleteAfterCount(int count); void setDeleteAfterType(int type); - void setLastUpdated(QDateTime lastUpdated); + void setLastUpdated(const QDateTime &lastUpdated); void setNotify(bool notify); void setRefreshing(bool refreshing); void setErrorId(int errorId); - void setErrorString(QString errorString); + void setErrorString(const QString &errorString); Q_INVOKABLE void refresh(); void remove(); Q_SIGNALS: - void nameChanged(QString &name); - void imageChanged(QString &image); - void linkChanged(QString &link); - void descriptionChanged(QString &description); - void authorsChanged(QVector &authors); + void nameChanged(const QString &name); + void imageChanged(const QString &image); + void linkChanged(const QString &link); + void descriptionChanged(const QString &description); + void authorsChanged(const QVector &authors); void deleteAfterCountChanged(int count); void deleteAfterTypeChanged(int type); - void lastUpdatedChanged(QDateTime lastUpdated); + void lastUpdatedChanged(const QDateTime &lastUpdated); void notifyChanged(bool notify); void entryCountChanged(); void unreadEntryCountChanged(); void errorIdChanged(int &errorId); - void errorStringChanged(QString &errorString); + void errorStringChanged(const QString &errorString); void refreshingChanged(bool refreshing); diff --git a/src/feedsmodel.cpp b/src/feedsmodel.cpp index 6b550ffe..01b19f06 100644 --- a/src/feedsmodel.cpp +++ b/src/feedsmodel.cpp @@ -21,7 +21,7 @@ FeedsModel::FeedsModel(QObject *parent) beginInsertRows(QModelIndex(), rowCount(QModelIndex()) - 1, rowCount(QModelIndex()) - 1); endInsertRows(); }); - connect(&Fetcher::instance(), &Fetcher::feedDetailsUpdated, this, [this](QString url, QString name, QString image, QString link, QString description, QDateTime lastUpdated) { + connect(&Fetcher::instance(), &Fetcher::feedDetailsUpdated, this, [this](const QString &url, const QString &name, const QString &image, const QString &link, const QString &description, const QDateTime &lastUpdated) { for (int i = 0; i < m_feeds.length(); i++) { if (m_feeds[i]->url() == url) { m_feeds[i]->setName(name); diff --git a/src/fetcher.cpp b/src/fetcher.cpp index 6fa2ef0b..0a078e2f 100644 --- a/src/fetcher.cpp +++ b/src/fetcher.cpp @@ -25,7 +25,7 @@ Fetcher::Fetcher() manager->enableStrictTransportSecurityStore(true); } -void Fetcher::fetch(QString url) +void Fetcher::fetch(const QString &url) { qDebug() << "Starting to fetch" << url; @@ -58,7 +58,7 @@ void Fetcher::fetchAll() } } -void Fetcher::processFeed(Syndication::FeedPtr feed, QString url) +void Fetcher::processFeed(Syndication::FeedPtr feed, const QString &url) { if (feed.isNull()) return; @@ -96,7 +96,7 @@ void Fetcher::processFeed(Syndication::FeedPtr feed, QString url) Q_EMIT feedUpdated(url); } -void Fetcher::processEntry(Syndication::ItemPtr entry, QString url) +void Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url) { qDebug() << "Processing" << entry->title(); QSqlQuery query; @@ -132,7 +132,7 @@ void Fetcher::processEntry(Syndication::ItemPtr entry, QString url) } } -void Fetcher::processAuthor(Syndication::PersonPtr author, QString entryId, QString url) +void Fetcher::processAuthor(Syndication::PersonPtr author, const QString &entryId, const QString &url) { QSqlQuery query; query.prepare(QStringLiteral("INSERT INTO Authors VALUES(:feed, :id, :name, :uri, :email);")); @@ -144,7 +144,7 @@ void Fetcher::processAuthor(Syndication::PersonPtr author, QString entryId, QStr Database::instance().execute(query); } -void Fetcher::processEnclosure(Syndication::EnclosurePtr enclosure, Syndication::ItemPtr entry, QString feedUrl) +void Fetcher::processEnclosure(Syndication::EnclosurePtr enclosure, Syndication::ItemPtr entry, const QString &feedUrl) { QSqlQuery query; query.prepare(QStringLiteral("INSERT INTO Enclosures VALUES (:feed, :id, :duration, :size, :title, :type, :url);")); @@ -158,7 +158,7 @@ void Fetcher::processEnclosure(Syndication::EnclosurePtr enclosure, Syndication: Database::instance().execute(query); } -QString Fetcher::image(QString url) +QString Fetcher::image(const QString &url) { QString path = filePath(url); if (QFileInfo::exists(path)) { @@ -170,7 +170,7 @@ QString Fetcher::image(QString url) return QLatin1String(""); } -void Fetcher::download(QString url) +void Fetcher::download(const QString &url) { QNetworkRequest request((QUrl(url))); QNetworkReply *reply = get(request); @@ -186,13 +186,13 @@ void Fetcher::download(QString url) }); } -void Fetcher::removeImage(QString url) +void Fetcher::removeImage(const QString &url) { qDebug() << filePath(url); QFile(filePath(url)).remove(); } -QString Fetcher::filePath(QString url) +QString Fetcher::filePath(const QString &url) { return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/") + QString::fromStdString(QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md5).toHex().toStdString()); } diff --git a/src/fetcher.h b/src/fetcher.h index fd0c2547..ea400e17 100644 --- a/src/fetcher.h +++ b/src/fetcher.h @@ -20,28 +20,28 @@ public: static Fetcher _instance; return _instance; } - Q_INVOKABLE void fetch(QString url); + Q_INVOKABLE void fetch(const QString &url); Q_INVOKABLE void fetchAll(); - Q_INVOKABLE QString image(QString); - void removeImage(QString); - Q_INVOKABLE void download(QString url); + Q_INVOKABLE QString image(const QString &url); + void removeImage(const QString &url); + Q_INVOKABLE void download(const QString &url); QNetworkReply *get(QNetworkRequest &request); private: Fetcher(); - QString filePath(QString); - void processFeed(Syndication::FeedPtr feed, QString url); - void processEntry(Syndication::ItemPtr entry, QString url); - void processAuthor(Syndication::PersonPtr author, QString entryId, QString url); - void processEnclosure(Syndication::EnclosurePtr enclosure, Syndication::ItemPtr entry, QString feedUrl); + QString filePath(const QString &url); + void processFeed(Syndication::FeedPtr feed, const QString &url); + void processEntry(Syndication::ItemPtr entry, const QString &url); + void processAuthor(Syndication::PersonPtr author, const QString &entryId, const QString &url); + void processEnclosure(Syndication::EnclosurePtr enclosure, Syndication::ItemPtr entry, const QString &feedUrl); QNetworkAccessManager *manager; Q_SIGNALS: - void startedFetchingFeed(QString url); - void feedUpdated(QString url); - void feedDetailsUpdated(QString url, QString name, QString image, QString link, QString description, QDateTime lastUpdated); - void error(QString url, int errorId, QString errorString); - void imageDownloadFinished(QString url); + void startedFetchingFeed(const QString &url); + void feedUpdated(const QString &url); + void feedDetailsUpdated(const QString &url, const QString &name, const QString &image, const QString &link, const QString &description, const QDateTime &lastUpdated); + void error(const QString &url, int errorId, const QString &errorString); + void imageDownloadFinished(const QString &url); };