Delete image when deleting feed
This commit is contained in:
parent
cfb18072fc
commit
14d8819fb5
@ -35,9 +35,7 @@ FeedListModel::FeedListModel(QObject *parent)
|
|||||||
setEditStrategy(OnFieldChange);
|
setEditStrategy(OnFieldChange);
|
||||||
select();
|
select();
|
||||||
|
|
||||||
connect(&Fetcher::instance(), &Fetcher::updated, this, [this]() {
|
connect(&Fetcher::instance(), &Fetcher::updated, this, [this]() { select(); });
|
||||||
select();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> FeedListModel::roleNames() const
|
QHash<int, QByteArray> FeedListModel::roleNames() const
|
||||||
@ -85,6 +83,7 @@ bool FeedListModel::feedExists(QString url)
|
|||||||
|
|
||||||
void FeedListModel::removeFeed(int index)
|
void FeedListModel::removeFeed(int index)
|
||||||
{
|
{
|
||||||
|
Fetcher::instance().removeImage(data(createIndex(index, 0), Image).toString());
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
query.prepare(QStringLiteral("DELETE FROM Authors WHERE feed=:feed;"));
|
query.prepare(QStringLiteral("DELETE FROM Authors WHERE feed=:feed;"));
|
||||||
query.bindValue(QStringLiteral(":feed"), data(createIndex(index, 0), 1).toString());
|
query.bindValue(QStringLiteral(":feed"), data(createIndex(index, 0), 1).toString());
|
||||||
|
@ -18,11 +18,11 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QFileInfo>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QFile>
|
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QFileInfo>
|
|
||||||
|
|
||||||
#include <Syndication/Syndication>
|
#include <Syndication/Syndication>
|
||||||
|
|
||||||
@ -101,8 +101,7 @@ void Fetcher::fetch(QUrl url)
|
|||||||
|
|
||||||
QString Fetcher::image(QString url)
|
QString Fetcher::image(QString url)
|
||||||
{
|
{
|
||||||
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/") + QString::fromStdString(QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md5).toHex().toStdString());
|
QString path = imagePath(url);
|
||||||
|
|
||||||
if (QFileInfo(path).exists()) {
|
if (QFileInfo(path).exists()) {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
@ -122,3 +121,14 @@ QString Fetcher::image(QString url)
|
|||||||
|
|
||||||
return QStringLiteral("");
|
return QStringLiteral("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Fetcher::removeImage(QString url)
|
||||||
|
{
|
||||||
|
qDebug() << imagePath(url);
|
||||||
|
QFile(imagePath(url)).remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Fetcher::imagePath(QString url)
|
||||||
|
{
|
||||||
|
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/") + QString::fromStdString(QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md5).toHex().toStdString());
|
||||||
|
}
|
||||||
|
@ -20,9 +20,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
|
|
||||||
class Fetcher : public QObject
|
class Fetcher : public QObject
|
||||||
{
|
{
|
||||||
@ -35,11 +35,14 @@ public:
|
|||||||
}
|
}
|
||||||
void fetch(QUrl);
|
void fetch(QUrl);
|
||||||
QString image(QString);
|
QString image(QString);
|
||||||
|
void removeImage(QString);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Fetcher();
|
Fetcher();
|
||||||
Fetcher(const Fetcher &);
|
Fetcher(const Fetcher &);
|
||||||
|
|
||||||
|
QString imagePath(QString);
|
||||||
|
|
||||||
QNetworkAccessManager *manager;
|
QNetworkAccessManager *manager;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user