mirror of
https://github.com/KDE/kasts.git
synced 2025-01-11 08:03:43 +01:00
Make more things const &
This commit is contained in:
parent
70393521f3
commit
7d75c6cf9b
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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) {
|
||||
|
22
src/feed.cpp
22
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<Author *> authors)
|
||||
void Feed::setAuthors(const QVector<Author *> &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);
|
||||
|
28
src/feed.h
28
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<Author *> 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<Author *> &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<Author *> &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<Author *> &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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user