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 | 32 | | |||
32 | #include <kdirlister.h> | 33 | #include <kdirlister.h> | ||
33 | #include <KIO/EmptyTrashJob> | 34 | #include <KIO/EmptyTrashJob> | ||
34 | 35 | | |||
35 | ImageFolderModel::ImageFolderModel(QObject *parent) | 36 | ImageFolderModel::ImageFolderModel(QObject *parent) | ||
36 | : KDirModel(parent) | 37 | : KDirModel(parent) | ||
37 | { | 38 | { | ||
38 | QMimeDatabase db; | 39 | QMimeDatabase db; | ||
Show All 10 Lines | |||||
49 | 50 | | |||
50 | connect(this, &QAbstractItemModel::rowsInserted, | 51 | connect(this, &QAbstractItemModel::rowsInserted, | ||
51 | this, &ImageFolderModel::countChanged); | 52 | this, &ImageFolderModel::countChanged); | ||
52 | connect(this, &QAbstractItemModel::rowsRemoved, | 53 | connect(this, &QAbstractItemModel::rowsRemoved, | ||
53 | this, &ImageFolderModel::countChanged); | 54 | this, &ImageFolderModel::countChanged); | ||
54 | connect(this, &QAbstractItemModel::modelReset, | 55 | connect(this, &QAbstractItemModel::modelReset, | ||
55 | this, &ImageFolderModel::countChanged); | 56 | this, &ImageFolderModel::countChanged); | ||
56 | 57 | | |||
57 | //TODO: don't hardcode this | 58 | connect(this, &ImageFolderModel::showImageViewer, | ||
58 | QStringList locations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); | 59 | this, [this] (const QString path) {qDebug() << "will show image " << path;}); | ||
59 | Q_ASSERT(locations.size() >= 1); | | |||
60 | qDebug() << locations; | | |||
61 | | ||||
62 | setUrl("file://"+locations.first()); | | |||
63 | } | 60 | } | ||
64 | 61 | | |||
65 | ImageFolderModel::~ImageFolderModel() | 62 | ImageFolderModel::~ImageFolderModel() | ||
66 | { | 63 | { | ||
67 | } | 64 | } | ||
68 | 65 | | |||
69 | QHash<int, QByteArray> ImageFolderModel::roleNames() const | 66 | QHash<int, QByteArray> ImageFolderModel::roleNames() const | ||
70 | { | 67 | { | ||
71 | return { | 68 | return { | ||
72 | { Qt::DisplayRole, "display" }, | 69 | { Qt::DisplayRole, "display" }, | ||
73 | { Qt::DecorationRole, "decoration" }, | 70 | { Qt::DecorationRole, "decoration" }, | ||
74 | { Roles::ImageUrlRole, "imageurl" }, | 71 | { Roles::ImageUrlRole, "imageurl" }, | ||
75 | { Roles::MimeTypeRole, "mimeType" }, | 72 | { Roles::MimeTypeRole, "mimeType" }, | ||
76 | { Roles::ItemTypeRole, "itemType"} | 73 | { Roles::ItemTypeRole, "itemType"} | ||
77 | }; | 74 | }; | ||
78 | } | 75 | } | ||
79 | 76 | | |||
80 | QString ImageFolderModel::url() const | 77 | QString ImageFolderModel::url() const | ||
81 | { | 78 | { | ||
82 | return dirLister()->url().toString(); | 79 | return dirLister()->url().toString(); | ||
83 | } | 80 | } | ||
84 | 81 | | |||
85 | void ImageFolderModel::setUrl(const QString& url) | 82 | void ImageFolderModel::setUrl(const QString& url) | ||
mart: i think this method and setUrl are redundant, they can be merged into a single method | |||||
86 | { | 83 | { | ||
87 | if (url.isEmpty()) { | 84 | if (url.isEmpty()) { | ||
88 | return; | 85 | return; | ||
89 | } | 86 | } | ||
90 | if (dirLister()->url().path() == url) { | 87 | | ||
91 | dirLister()->updateDirectory(QUrl(url)); | 88 | QString directoryUrl; | ||
89 | | ||||
90 | if( !QFileInfo(url).isDir()) { | ||||
91 | m_imagePath = url; | ||||
92 | directoryUrl = url.left(url.lastIndexOf('/')); | ||||
93 | emit showImageViewer( m_imagePath); | ||||
94 | } else { | ||||
95 | directoryUrl = "file://" + url; | ||||
96 | } | ||||
97 | | ||||
98 | if (dirLister()->url().path() == directoryUrl) { | ||||
99 | dirLister()->updateDirectory(QUrl(directoryUrl)); | ||||
92 | return; | 100 | return; | ||
93 | } | 101 | } | ||
94 | 102 | | |||
95 | beginResetModel(); | 103 | beginResetModel(); | ||
96 | dirLister()->openUrl(QUrl(url)); | 104 | dirLister()->openUrl(QUrl(directoryUrl)); | ||
97 | endResetModel(); | 105 | endResetModel(); | ||
98 | emit urlChanged(); | 106 | emit urlChanged(); | ||
99 | } | 107 | } | ||
100 | 108 | | |||
101 | int ImageFolderModel::indexForUrl(const QString &url) const | 109 | int ImageFolderModel::indexForUrl(const QString &url) const | ||
102 | { | 110 | { | ||
103 | QModelIndex index = KDirModel::indexForUrl(QUrl(url)); | 111 | QModelIndex index = KDirModel::indexForUrl(QUrl(url)); | ||
104 | return index.row(); | 112 | return index.row(); | ||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |
i think this method and setUrl are redundant, they can be merged into a single method