From e4d4cfe8c33ad6825de9f10a5c15feb2f0a9cce2 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Tue, 4 Oct 2022 09:29:42 -0500 Subject: [PATCH] adding basic filemanager plumbing --- CMakeLists.txt | 2 +- default.nix | 2 ++ shell.nix | 2 ++ src/CMakeLists.txt | 2 ++ src/filemanager.cpp | 52 ++++++++++++++++++++++++++++++++ src/filemanager.h | 38 +++++++++++++++++++++++ src/main.cpp | 3 ++ src/qml/main.qml | 21 +++++++++++-- src/qml/presenter/MainWindow.qml | 2 ++ 9 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 src/filemanager.cpp create mode 100644 src/filemanager.h diff --git a/CMakeLists.txt b/CMakeLists.txt index af65f02..8d8fded 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ include(ECMPoQmTools) kde_enable_exceptions() find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Core Quick Test Gui QuickControls2 Widgets Sql X11Extras) -find_package(KF5 ${KF_MIN_VERSION} REQUIRED COMPONENTS Kirigami2 I18n CoreAddons) +find_package(KF5 ${KF_MIN_VERSION} REQUIRED COMPONENTS Kirigami2 I18n Archive CoreAddons) find_package(Libmpv) set_package_properties(Libmpv PROPERTIES TYPE REQUIRED) diff --git a/default.nix b/default.nix index 1285ef9..89f6c05 100644 --- a/default.nix +++ b/default.nix @@ -61,9 +61,11 @@ stdenv.mkDerivation rec { # breeze-icons # breeze-qt5 # qqc2-desktop-style + libsForQt5.karchive libsForQt5.ki18n libsForQt5.kcoreaddons # lightly-qt + podofo mpv # libsForQt5.kconfig # ffmpeg-full diff --git a/shell.nix b/shell.nix index 7f3a09d..63f315c 100644 --- a/shell.nix +++ b/shell.nix @@ -20,6 +20,7 @@ mkShell rec { buildInputs = [ clang-tools + # clang-format qt5.full qt5.qttools qt5.qtquickcontrols2 @@ -30,6 +31,7 @@ mkShell rec { libsForQt5.breeze-icons libsForQt5.breeze-qt5 libsForQt5.qqc2-desktop-style + libsForQt5.karchive # libsForQt5.kirigami-addons libsForQt5.ki18n libsForQt5.kcoreaddons diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cac1b65..aeedd2d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,6 +9,7 @@ target_sources(presenter slide.cpp slide.h videosqlmodel.cpp videosqlmodel.h imagesqlmodel.cpp imagesqlmodel.h + filemanager.cpp filemanager.h presentationsqlmodel.cpp presentationsqlmodel.h mpv/mpvobject.h mpv/mpvobject.cpp mpv/qthelper.hpp mpv/mpvhelpers.h @@ -24,6 +25,7 @@ target_link_libraries(presenter Qt5::X11Extras KF5::Kirigami2 KF5::I18n + KF5::Archive podofo mpv ) diff --git a/src/filemanager.cpp b/src/filemanager.cpp new file mode 100644 index 0000000..5e8f22a --- /dev/null +++ b/src/filemanager.cpp @@ -0,0 +1,52 @@ +#include "filemanager.h" +#include +#include + +File::File(QObject *parent) + : QObject{parent} +{ + qDebug() << "Initializing empty file"; +} + +File::File(const QString &name, const QString &filePath, QObject *parent) + : QObject(parent),m_name(name),m_filePath(filePath) +{ + qDebug() << "Initializing file with defaults"; +} + +QString File::name() const { + return m_name; +} + +QString File::filePath() const { + return m_filePath; +} + +void File::setName(QString name) +{ + if (m_name == name) + return; + + qDebug() << "####changing name to: " << name; + m_name = name; + emit nameChanged(m_name); +} + +void File::setFilePath(QString filePath) +{ + if (m_filePath == filePath) + return; + + qDebug() << "####changing filePath to: " << filePath; + m_filePath = filePath; + emit filePathChanged(m_filePath); +} + +bool File::save(QUrl file, QVariantList serviceList) { + qDebug() << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"; + qDebug() << "Saving..."; + qDebug() << "File path is: " << file; + qDebug() << "serviceList is: " << serviceList; + qDebug() << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"; + return true; +} diff --git a/src/filemanager.h b/src/filemanager.h new file mode 100644 index 0000000..dc6143c --- /dev/null +++ b/src/filemanager.h @@ -0,0 +1,38 @@ +#ifndef FILEMANAGER_H +#define FILEMANAGER_H + +#include +#include +#include +#include + +class File : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QString filePath READ filePath WRITE setFilePath NOTIFY filePathChanged) + // QML_ELEMENT + +public: + explicit File(QObject *parent = nullptr); + File(const QString &name, const QString &filePath, + QObject * parent = nullptr); + + QString name() const; + QString filePath() const; + + Q_INVOKABLE void setName(QString name); + Q_INVOKABLE void setFilePath(QString filePath); + + Q_INVOKABLE bool save(QUrl file, QVariantList serviceList); + +signals: + Q_INVOKABLE void nameChanged(QString name); + Q_INVOKABLE void filePathChanged(QString filePath); + +private: + QString m_name; + QString m_filePath; +}; + +#endif //FILEMANAGER_H diff --git a/src/main.cpp b/src/main.cpp index 68d4e6a..19136ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,6 +39,7 @@ #include "videosqlmodel.h" #include "imagesqlmodel.h" #include "presentationsqlmodel.h" +#include "filemanager.h" #include "slide.h" static void connectToDatabase() { @@ -96,6 +97,7 @@ int main(int argc, char *argv[]) //Need to instantiate our slide QScopedPointer slide(new Slide); + QScopedPointer filemanager(new File); // apparently mpv needs this class set // let's register mpv as well @@ -109,6 +111,7 @@ int main(int argc, char *argv[]) qmlRegisterType("org.presenter", 1, 0, "PresentationSqlModel"); qmlRegisterType("org.presenter", 1, 0, "ServiceItemModel"); qmlRegisterSingletonInstance("org.presenter", 1, 0, "SlideObject", slide.get()); + qmlRegisterSingletonInstance("org.presenter", 1, 0, "FileManager", filemanager.get()); connectToDatabase(); diff --git a/src/qml/main.qml b/src/qml/main.qml index 10a8174..5220e66 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -66,8 +66,16 @@ Kirigami.ApplicationWindow { title: qsTr("File") Labs.MenuItem { text: qsTr("New...") } Labs.MenuItem { text: qsTr("Open...") } - Labs.MenuItem { text: qsTr("Save") } - Labs.MenuItem { text: qsTr("Save As...") } + Labs.MenuItem { + text: qsTr("Save") + shortcut: "Ctrl+S" + onTriggered: save() + } + Labs.MenuItem { + text: qsTr("Save As...") + shortcut: "Ctrl+Shift+S" + onTriggered: saveAs() + } Labs.MenuSeparator { } Labs.MenuItem { text: qsTr("Quit") } } @@ -111,6 +119,15 @@ Kirigami.ApplicationWindow { settingsSheet.open() } + function save() { + const saved = FileManager.save("/home/chris/blah.pres", mainPage.serviceList); + saved ? showPassiveNotification("SAVED!") : showPassiveNotification("FAILED!"); + } + + function saveAs() { + + } + Component.onCompleted: { /* showPassiveNotification(Kirigami.Settings.style); */ /* Kirigami.Settings.style = "Plasma"; */ diff --git a/src/qml/presenter/MainWindow.qml b/src/qml/presenter/MainWindow.qml index 704f380..e870d4c 100644 --- a/src/qml/presenter/MainWindow.qml +++ b/src/qml/presenter/MainWindow.qml @@ -37,6 +37,8 @@ Controls.Page { property var song property var draggedLibraryItem + property var serviceList: ["testing", "data"] + property bool songDragged: false property string editType