diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 53ae06e..b77108c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,6 +20,7 @@ set(SRC qt_add_resources(RESOURCES qml/glacier-gallery.qrc) add_subdirectory(editorplugin) +add_subdirectory(plugin) add_executable(glacier-gallery ${SRC} ${RESOURCES}) @@ -34,7 +35,3 @@ install(TARGETS glacier-gallery RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) FindQtInstallQml() - -install(DIRECTORY qml/api/ - DESTINATION - ${QT_INSTALL_QML}/org/nemomobile/gallery) diff --git a/src/editorplugin/plugin.cpp b/src/editorplugin/plugin.cpp index e6e90f6..0f26e29 100644 --- a/src/editorplugin/plugin.cpp +++ b/src/editorplugin/plugin.cpp @@ -24,11 +24,11 @@ #include "editableimage.h" -class Q_DECL_EXPORT GlacierPackageManagerPlugin : public QQmlExtensionPlugin { +class Q_DECL_EXPORT GlacierImageEditorPlugin : public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "org.glacier.imageeditor") public: - virtual ~GlacierPackageManagerPlugin() { } + virtual ~GlacierImageEditorPlugin() { } void initializeEngine(QQmlEngine*, const char* uri) { diff --git a/src/plugin/CMakeLists.txt b/src/plugin/CMakeLists.txt new file mode 100644 index 0000000..824bf68 --- /dev/null +++ b/src/plugin/CMakeLists.txt @@ -0,0 +1,60 @@ +### Sets QT_INSTALL_QML to the directory where QML Plugins should be installed +function(FindQtInstallQml) + find_program(QMAKE NAMES qmake6 qmake) + if(NOT QMAKE) + message(FATAL_ERROR "qmake not found") + endif() + execute_process( + COMMAND ${QMAKE} -query QT_INSTALL_QML + OUTPUT_VARIABLE PROC_RESULT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + set(QT_INSTALL_QML ${PROC_RESULT} PARENT_SCOPE) +endfunction() + +set(SRC + plugin.cpp + gallerymodel.cpp) + +set(HEADERS + plugin.h + gallerymodel.h) + +set(QML + qml/GalleryDelegate.qml + qml/GalleryView.qml) + +add_library(glaciergalleryplugin SHARED ${SRC}) + +qt6_add_qml_module(glaciergalleryplugin + URI Glacier.Gallery + VERSION 1.0 + PLUGIN_TARGET glaciergalleryplugin + NO_GENERATE_PLUGIN_SOURCE + SOURCES + ${SOURCES} + ${HEADERS} + QML_FILES + ${QML} + OUTPUT_DIRECTORY + ${CMAKE_BINARY_DIR}/Glacier/Gallery + RESOURCES qml/qmldir + SOURCES gallerymodel.h gallerymodel.cpp +) + +target_link_libraries(glaciergalleryplugin PUBLIC + Qt6::Core + Qt6::Gui + Qt6::Qml + Qt6::Quick) + +FindQtInstallQml() + +install(TARGETS glaciergalleryplugin + RUNTIME DESTINATION "${QT_INSTALL_QML}/Glacier/Gallery" + BUNDLE DESTINATION "${QT_INSTALL_QML}/Glacier/Gallery" + LIBRARY DESTINATION "${QT_INSTALL_QML}/Glacier/Gallery" +) + +install(DIRECTORY qml/ + DESTINATION ${QT_INSTALL_QML}/Glacier/Gallery) diff --git a/src/plugin/gallerymodel.cpp b/src/plugin/gallerymodel.cpp new file mode 100644 index 0000000..120a799 --- /dev/null +++ b/src/plugin/gallerymodel.cpp @@ -0,0 +1,41 @@ +#include "gallerymodel.h" + +GalleryModel::GalleryModel(QObject *parent) + : QAbstractListModel{parent} + , m_loading(false) + , m_error(true) +{ +} + +int GalleryModel::rowCount(const QModelIndex &parent) const +{ + return -1; +} + +QVariant GalleryModel::data(const QModelIndex &index, int role) const +{ + return QVariant(); +} + +QStringList GalleryModel::sortProperties() const +{ + return m_sortProperties; +} + +void GalleryModel::setSortProperties(const QStringList &newSortProperties) +{ + if (m_sortProperties == newSortProperties) + return; + m_sortProperties = newSortProperties; + emit sortPropertiesChanged(); +} + +bool GalleryModel::loading() const +{ + return m_loading; +} + +bool GalleryModel::error() const +{ + return m_error; +} diff --git a/src/plugin/gallerymodel.h b/src/plugin/gallerymodel.h new file mode 100644 index 0000000..ee87a79 --- /dev/null +++ b/src/plugin/gallerymodel.h @@ -0,0 +1,40 @@ +#ifndef GALLERYMODEL_H +#define GALLERYMODEL_H + +#include + +class GalleryModel : public QAbstractListModel +{ + Q_OBJECT + Q_PROPERTY(QStringList sortProperties READ sortProperties WRITE setSortProperties NOTIFY sortPropertiesChanged FINAL) + Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged FINAL) + Q_PROPERTY(bool error READ error NOTIFY errorChanged FINAL) + +public: + explicit GalleryModel(QObject *parent = nullptr); + int rowCount(const QModelIndex& parent = QModelIndex()) const; + QVariant data(const QModelIndex& index, int role) const; + QHash roleNames() const { return m_hash; } + + QStringList sortProperties() const; + void setSortProperties(const QStringList &newSortProperties); + + bool loading() const; + + bool error() const; + +signals: + void sortPropertiesChanged(); + + void loadingChanged(); + + void errorChanged(); + +private: + QHash m_hash; + QStringList m_sortProperties; + bool m_loading; + bool m_error; +}; + +#endif // GALLERYMODEL_H diff --git a/src/plugin/glacier.gallery.json b/src/plugin/glacier.gallery.json new file mode 100644 index 0000000..e69de29 diff --git a/src/plugin/plugin.cpp b/src/plugin/plugin.cpp new file mode 100644 index 0000000..665c3a0 --- /dev/null +++ b/src/plugin/plugin.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2024 Chupligin Sergey + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "plugin.h" +#include "gallerymodel.h" +#include + +void QQuickNemoControlsExtensionPlugin::registerTypes(const char* uri) +{ + Q_ASSERT(uri == QLatin1String("Glacier.Gallery")); + qmlRegisterModule(uri, 1, 0); + //@uri Glacier.Gallery + qmlRegisterType(uri, 1, 0, "GalleryModel"); +} diff --git a/src/plugin/plugin.h b/src/plugin/plugin.h new file mode 100644 index 0000000..71fb081 --- /dev/null +++ b/src/plugin/plugin.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2024 Chupligin Sergey + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + + +#ifndef PLUGIN_H +#define PLUGIN_H + +#include + +class QQuickNemoControlsExtensionPlugin : public QQmlExtensionPlugin { +public: + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid FILE "glacier.gallery.json") +public: + void registerTypes(const char* uri); +}; + +#endif // PLUGIN_H diff --git a/src/qml/api/GalleryDelegate.qml b/src/plugin/qml/GalleryDelegate.qml similarity index 100% rename from src/qml/api/GalleryDelegate.qml rename to src/plugin/qml/GalleryDelegate.qml diff --git a/src/qml/api/GalleryView.qml b/src/plugin/qml/GalleryView.qml similarity index 100% rename from src/qml/api/GalleryView.qml rename to src/plugin/qml/GalleryView.qml diff --git a/src/qml/api/qmldir b/src/plugin/qml/qmldir similarity index 58% rename from src/qml/api/qmldir rename to src/plugin/qml/qmldir index 6f94f7b..d5d3a1a 100644 --- a/src/qml/api/qmldir +++ b/src/plugin/qml/qmldir @@ -1,3 +1,5 @@ +module Glacier.Gallery +plugin glaciergalleryplugin + GalleryDelegate 1.0 GalleryDelegate.qml -GalleryModel 1.0 GalleryModel.qml GalleryView 1.0 GalleryView.qml diff --git a/src/qml/api/GalleryModel.qml b/src/qml/api/GalleryModel.qml deleted file mode 100644 index 4595a67..0000000 --- a/src/qml/api/GalleryModel.qml +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2012 Andrea Bernabei - * Copyright (C) 2022-2023 Chupligin Sergey - * - * You may use this file under the terms of the BSD license as follows: - * - * "Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Nemo Mobile nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." - */ -import QtQuick -import QtQml.Models 2.15 -import QtDocGallery 5.0 - -ListModel { - id: mainModel; - - function sourceModelsChanged() { - copyReady = false; - var i, item; - mainModel.clear() - for (i = 0; i < pictureGallery.count; i++) { - item = pictureGallery.get(i) - item.url = (String)(item.url); - mainModel.append(item); - } - - for (i = 0; i < videoGallery.count; i++) { - item = videoGallery.get(i) - item.url = (String)(item.url); - mainModel.append(item); - } - copyReady = true; - } - - //destroying the old filter before the new one is assigned makes the gallery model misbehave! - function assignNewDestroyCurrent(newFilter) { - var old = gallery.filter - gallery.filter = newFilter - } - - //this is to create single filters dynamically - function createFilter(parentItem, name, filterType, keyToFilter, value){ - var myFilter = Qt.createQmlObject('import QtDocGallery 5.0;' + filterType + '{property: "' +keyToFilter + '"; value: "' + value + '" }', - parentItem, name); - return myFilter - } - - //this is to create group filters, such as union and intersection ones - function createFiltersArray(parentItem, name, filterType, filtersArray){ - var myFilter = Qt.createQmlObject('import QtDocGallery 5.0;' + filterType + '{ }', - parentItem, name); - myFilter.filters = filtersArray - return myFilter - } - - //this is to know if the item at index "index" is a video - function isVideo(index) { - //elements have index == -1 when the gallery model is being rebuilt (e.g. filters are changed) - //In that case, we must not access model data - //NOTE: this will still return a value, best thing would be to add a check in the other components - //every time before using this method! - if (index !== -1) - { - var mimeString = get(index).mimeType.toString() - return (mimeString.substring(0,5) === "video") - } - } - - - property variant sortProperties: [] - property variant filter; - property bool copyReady: true; - property bool loading: pictureGallery.status != DocumentGalleryModel.Finished || videoGallery.status != DocumentGalleryModel.Finished || !copyReady; - property bool error: pictureGallery.status == DocumentGalleryModel.Error - - property variant pictures: - DocumentGalleryModel { - id: pictureGallery; - properties: [ - "fileName", - "fileSize", - "lastModified", - "mimeType", - "url", - "orientation", - "latitude", - "longitude", - "altitude", - "dateTaken", - "created", - "exposureTime", - "fNumber", - "flashEnabled", - "focalLength", - "meteringMode", - "whiteBalance", - "cameraManufacturer", - "cameraModel", - ] - - autoUpdate: true - rootType: DocumentGallery.Image - onCountChanged: { - sourceModelsChanged(); - } - - } - - property variant videos: DocumentGalleryModel { - id: videoGallery; - properties: [ - "fileName", - "fileSize", - "lastModified", - "mimeType", - "url", - "duration", - "frameRate", - "created", - ] - autoUpdate: true - rootType: DocumentGallery.Video - onCountChanged: { - sourceModelsChanged(); - } - } - - - onSortPropertiesChanged: { - pictureGallery.sortProperties = sortProperties; - videoGallery.sortProperties = sortProperties; - } - - onFilterChanged: { - pictureGallery.filter = filter; - videoGallery.filter = filter; - } -} diff --git a/src/qml/components/DownListView.qml b/src/qml/components/DownListView.qml index 3e006f6..ed738bf 100644 --- a/src/qml/components/DownListView.qml +++ b/src/qml/components/DownListView.qml @@ -35,8 +35,6 @@ import QtQuick.Controls import Nemo import Nemo.Controls -import QtDocGallery 5.0 - Item{ id: downListView property alias model: littleImagesListView.model diff --git a/src/qml/components/ImageContainer.qml b/src/qml/components/ImageContainer.qml index 7f80831..d66d854 100644 --- a/src/qml/components/ImageContainer.qml +++ b/src/qml/components/ImageContainer.qml @@ -35,8 +35,6 @@ import QtQuick.Controls import Nemo import Nemo.Controls -import QtDocGallery 5.0 - Item { id: imgContainer property int index: -1 diff --git a/src/qml/pages/MainPage.qml b/src/qml/pages/MainPage.qml index e54c1fe..3e8dec3 100644 --- a/src/qml/pages/MainPage.qml +++ b/src/qml/pages/MainPage.qml @@ -37,14 +37,10 @@ import QtQuick.Layouts import Nemo import Nemo.Controls -import org.nemomobile.gallery 1.0 -import QtDocGallery 5.0 - +import Glacier.Gallery Page { id: mainPage - width: parent.width; - height: parent.height; headerTools: mainTools GalleryView {