Changeset View
Changeset View
Standalone View
Standalone View
src/imagefoldermodel.cpp
Show All 22 Lines | |||||
23 | #include "roles.h" | 23 | #include "roles.h" | ||
24 | 24 | | |||
25 | #include <QImage> | 25 | #include <QImage> | ||
26 | #include <QPixmap> | 26 | #include <QPixmap> | ||
27 | #include <QProcess> | 27 | #include <QProcess> | ||
28 | #include <QDebug> | 28 | #include <QDebug> | ||
29 | #include <QMimeDatabase> | 29 | #include <QMimeDatabase> | ||
30 | #include <QStandardPaths> | 30 | #include <QStandardPaths> | ||
31 | #include <QFileInfo> | 31 | #include <QDir> | ||
32 | 32 | | |||
33 | #include <kdirlister.h> | 33 | #include <kdirlister.h> | ||
34 | #include <KIO/EmptyTrashJob> | 34 | #include <KIO/EmptyTrashJob> | ||
35 | 35 | | |||
36 | ImageFolderModel::ImageFolderModel(QObject *parent) | 36 | ImageFolderModel::ImageFolderModel(QObject *parent) | ||
37 | : KDirModel(parent) | 37 | : KDirModel(parent) | ||
38 | { | 38 | { | ||
39 | QMimeDatabase db; | 39 | QMimeDatabase db; | ||
Show All 9 Lines | |||||
49 | dirLister()->setMimeFilter(m_mimeTypes); | 49 | dirLister()->setMimeFilter(m_mimeTypes); | ||
50 | 50 | | |||
51 | connect(this, &QAbstractItemModel::rowsInserted, | 51 | connect(this, &QAbstractItemModel::rowsInserted, | ||
52 | this, &ImageFolderModel::countChanged); | 52 | this, &ImageFolderModel::countChanged); | ||
53 | connect(this, &QAbstractItemModel::rowsRemoved, | 53 | connect(this, &QAbstractItemModel::rowsRemoved, | ||
54 | this, &ImageFolderModel::countChanged); | 54 | this, &ImageFolderModel::countChanged); | ||
55 | connect(this, &QAbstractItemModel::modelReset, | 55 | connect(this, &QAbstractItemModel::modelReset, | ||
56 | this, &ImageFolderModel::countChanged); | 56 | this, &ImageFolderModel::countChanged); | ||
57 | | ||||
58 | connect(this, &ImageFolderModel::showImageViewer, | | |||
59 | this, [this] (const QString path) {qDebug() << "will show image " << path;}); | | |||
60 | } | 57 | } | ||
61 | 58 | | |||
62 | ImageFolderModel::~ImageFolderModel() | 59 | ImageFolderModel::~ImageFolderModel() | ||
63 | { | 60 | { | ||
64 | } | 61 | } | ||
65 | 62 | | |||
66 | QHash<int, QByteArray> ImageFolderModel::roleNames() const | 63 | QHash<int, QByteArray> ImageFolderModel::roleNames() const | ||
67 | { | 64 | { | ||
68 | return { | 65 | return { | ||
69 | { Qt::DisplayRole, "display" }, | 66 | { Qt::DisplayRole, "display" }, | ||
70 | { Qt::DecorationRole, "decoration" }, | 67 | { Qt::DecorationRole, "decoration" }, | ||
71 | { Roles::ImageUrlRole, "imageurl" }, | 68 | { Roles::ImageUrlRole, "imageurl" }, | ||
72 | { Roles::MimeTypeRole, "mimeType" }, | 69 | { Roles::MimeTypeRole, "mimeType" }, | ||
73 | { Roles::ItemTypeRole, "itemType"} | 70 | { Roles::ItemTypeRole, "itemType"} | ||
74 | }; | 71 | }; | ||
75 | } | 72 | } | ||
76 | 73 | | |||
77 | QString ImageFolderModel::url() const | 74 | QString ImageFolderModel::url() const | ||
78 | { | 75 | { | ||
79 | return dirLister()->url().toString(); | 76 | return dirLister()->url().toString(); | ||
80 | } | 77 | } | ||
81 | 78 | | |||
82 | void ImageFolderModel::setUrl(const QString& url) | 79 | void ImageFolderModel::setUrl(QString& url) | ||
83 | { | 80 | { | ||
84 | if (url.isEmpty()) { | 81 | if (url.isEmpty()) { | ||
85 | return; | 82 | return; | ||
86 | } | 83 | } | ||
87 | 84 | | |||
85 | Q_ASSERT( QUrl(url).isLocalFile()); | ||||
86 | url = QUrl(url).path(); | ||||
mart: construct a QUrl immediately, then use it to check isLocalFile() | |||||
87 | | ||||
mart: QUrl::path() | |||||
88 | QString directoryUrl; | 88 | QString directoryUrl; | ||
drop that if then else and simply do: Q_ASSERT(QUrl(url).isLocalFile()) also, if you are asserting here, you need to check beforehand that url is local mart: drop that if then else and simply do:
Q_ASSERT(QUrl(url).isLocalFile())
url = QUrl(url).path()… | |||||
89 | 89 | | |||
90 | if( !QFileInfo(url).isDir()) { | 90 | if( QDir(url).exists()) { | ||
91 | m_imagePath = url; | 91 | directoryUrl = QUrl::fromLocalFile(url).toString(); | ||
92 | directoryUrl = url.left(url.lastIndexOf('/')); | | |||
93 | emit showImageViewer( m_imagePath); | | |||
94 | } else { | 92 | } else { | ||
95 | directoryUrl = "file://" + url; | 93 | m_imagePath = url; | ||
mart: you can prettyfy those as well:
QUrl::fromLocalFile(url) | |||||
94 | directoryUrl = QUrl::fromLocalFile(url.left(url.lastIndexOf('/'))).toString(); | ||||
95 | emit showImageViewer( indexForUrl(m_imagePath)); | ||||
96 | } | 96 | } | ||
mart: here too | |||||
97 | 97 | | |||
98 | if (dirLister()->url().path() == directoryUrl) { | 98 | if (dirLister()->url().path() == directoryUrl) { | ||
99 | dirLister()->updateDirectory(QUrl(directoryUrl)); | 99 | dirLister()->updateDirectory(QUrl(directoryUrl)); | ||
100 | return; | 100 | return; | ||
101 | } | 101 | } | ||
102 | 102 | | |||
103 | beginResetModel(); | 103 | beginResetModel(); | ||
104 | dirLister()->openUrl(QUrl(directoryUrl)); | 104 | dirLister()->openUrl(QUrl(directoryUrl)); | ||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |
construct a QUrl immediately, then use it to check isLocalFile()