Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPI: Moving from gdocgallery #44

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.directory
.commit
*.o
*.so
*.qmlc
Expand Down
5 changes: 1 addition & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand All @@ -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)
4 changes: 2 additions & 2 deletions src/editorplugin/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
36 changes: 8 additions & 28 deletions src/gallery.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (C) 2012 John Brooks <[email protected]>
* Copyright (C) 2022 Chupligin Sergey (NeoChapay) <[email protected]>
* Copyright (C) 2022-2025 Chupligin Sergey (NeoChapay) <[email protected]>
* 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
Expand Down Expand Up @@ -46,10 +46,11 @@ Gallery::Gallery(QObject* parent)
{
if (QCoreApplication::arguments().length() > 1) {
QString cmd = QCoreApplication::arguments().at(1);
if (!cmd.isEmpty()) {
if (isVideo(cmd) != -1) {
m_fileToOpen = cmd;
}
QMimeDatabase db;
QFileInfo fileInfo(cmd);

if (fileInfo.exists() && fileInfo.isFile() && (db.mimeTypeForFile(fileInfo.absoluteFilePath()).name().startsWith("video/") || db.mimeTypeForFile(fileInfo.absoluteFilePath()).name().startsWith("image/"))) {
m_fileToOpen = cmd;
}
}
}
Expand All @@ -67,28 +68,7 @@ void Gallery::acquireVideoResources()
m_resources->update();
m_resources->acquire();
}

int Gallery::isVideo(QUrl fileUrl)
bool Gallery::isVideo(QString url)
{
if (fileUrl.isEmpty()) {
return -1;
}

// RETURN VALUES
//-1: ERROR, 0: IMAGE, 1: VIDEO
QString filePath = fileUrl.toLocalFile();

QFileInfo testFile(filePath);
if (testFile.exists()) {
QImageReader reader(filePath);
QByteArray format = reader.format();
if (format.isNull() && reader.error() == QImageReader::UnsupportedFormatError) {
// we assume it's a video
return 1;
} else {
return 0;
}
}
qDebug() << filePath << " exists" << testFile.exists();
return -1;
return false;
}
10 changes: 5 additions & 5 deletions src/gallery.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#ifndef GALLERY_H
#define GALLERY_H

/* Copyright (C) 2012 John Brooks <[email protected]>
* Copyright (C) 2022 Chupligin Sergey (NeoChapay) <[email protected]>
* Copyright (C) 2022-2025 Chupligin Sergey (NeoChapay) <[email protected]>
*
* You may use this file under the terms of the BSD license as follows:
*
Expand Down Expand Up @@ -32,6 +29,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef GALLERY_H
#define GALLERY_H

#include <QObject>
#include <policy/resource-set.h>

Expand All @@ -43,10 +43,10 @@ class Gallery : public QObject {

public:
explicit Gallery(QObject* parent = 0);
Q_INVOKABLE bool isVideo(QString url);

public slots:
void acquireVideoResources();
int isVideo(QUrl fileName);
QString fileToOpen() { return m_fileToOpen; }

private:
Expand Down
62 changes: 62 additions & 0 deletions src/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
### 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
filesystemworker.cpp)

set(HEADERS
plugin.h
gallerymodel.h
filesystemworker.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 ${SOURCES}
)

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)
98 changes: 98 additions & 0 deletions src/plugin/filesystemworker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (C) 2025 Chupligin Sergey <[email protected]>
*
* 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 "filesystemworker.h"

#include <QDir>
#include <QDirIterator>
#include <QImageReader>
#include <QMimeDatabase>

FileSystemWorker::FileSystemWorker(QObject* parent)
: QObject { parent }
, m_busy(false)
{
}

void FileSystemWorker::setDirs(const QStringList dirs)
{
stop();
m_dirs = dirs;
}

void FileSystemWorker::setSuffixes(const QStringList suff)
{
stop();
m_suffixes = suff;
}

void FileSystemWorker::start()
{
if (m_busy) {
qWarning() << "Stop before run again!";
return;
}

QMimeDatabase db;

m_busy = true;
emit busyChanged();
foreach (const QString& dirString, m_dirs) {
if (!m_busy) { //STOP
break;
}
QDirIterator it(dirString, m_suffixes, QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()) {
QString filePath = it.next();
QFileInfo fInfo(filePath);

MediaFile file;
file.path = filePath;
file.created = fInfo.birthTime();
file.modified = fInfo.lastModified();
file.mimeType = db.mimeTypeForFile(fInfo.absoluteFilePath());
file.size = fInfo.size();

if (file.mimeType.name().startsWith("image/")) {
QImageReader reader(file.path);
QSize size = reader.size();
if (size.isValid()) {
file.width = size.width();
file.height = size.height();
} else {
QImage image = reader.read();
file.width = image.width();
file.height = image.height();
}
} else {
qWarning() << "Unsuported mime " << file.mimeType.name();
}
file.isValid = file.height > 0 && file.width > 0;
emit foundFile(file);
}
}
m_busy = false;
emit busyChanged();
}

void FileSystemWorker::stop()
{
m_busy = false;
emit busyChanged();
}
60 changes: 60 additions & 0 deletions src/plugin/filesystemworker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2025 Chupligin Sergey <[email protected]>
*
* 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 FILESYSTEMWORKER_H
#define FILESYSTEMWORKER_H

#include <QDirIterator>
#include <QMimeType>
#include <QObject>

struct MediaFile {
QString path = "";
bool isValid = false;
QMimeType mimeType;
uint width = -1;
uint height = -1;
QDateTime modified;
QDateTime created;
uint size = -1;
};

class FileSystemWorker : public QObject {
Q_OBJECT
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged FINAL)
public:
explicit FileSystemWorker(QObject* parent = nullptr);
void setDirs(QStringList dirs);
void setSuffixes(QStringList suff);

bool busy() { return m_busy; }
void start();
void stop();

signals:
void foundFile(MediaFile file);
void busyChanged();

private:
QStringList m_dirs;
QStringList m_suffixes;
bool m_busy;
};

#endif // FILESYSTEMWORKER_H
Loading
Loading