From 798c682df9e9b1634fa7f92cbcfecf7413b07961 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Mon, 17 Oct 2022 10:15:22 -0500 Subject: [PATCH] adding a loading of last saved file for jumping right back in --- src/qml/presenter/MainWindow.qml | 8 +++++++- src/serviceitemmodel.cpp | 35 +++++++++++++++++++++++--------- src/serviceitemmodel.h | 1 + 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/qml/presenter/MainWindow.qml b/src/qml/presenter/MainWindow.qml index 43be3a3..b3673c3 100644 --- a/src/qml/presenter/MainWindow.qml +++ b/src/qml/presenter/MainWindow.qml @@ -45,7 +45,13 @@ Controls.Page { property var currentWindow: presentation - Component.onCompleted: {changeServiceItem(0); presentation.forceActiveFocus();} + Component.onCompleted: { + changeServiceItem(0); + presentation.forceActiveFocus(); + /* const loaded = serviceItemModel.loadLastSaved(); */ + /* if (!loaded) */ + /* showPassiveNotification("Failed loading last file"); */ + } Item { id: mainItem diff --git a/src/serviceitemmodel.cpp b/src/serviceitemmodel.cpp index d5749b4..c62dc2d 100644 --- a/src/serviceitemmodel.cpp +++ b/src/serviceitemmodel.cpp @@ -19,21 +19,24 @@ #include #include #include +#include ServiceItemModel::ServiceItemModel(QObject *parent) : QAbstractListModel(parent) { - addItem(new ServiceItem("10,000 Reasons", "song", - "file:/home/chris/nextcloud/tfc/openlp/CMG - Nature King 21.jpg", - "image", QStringList("Yip Yip"), - "file:/home/chris/nextcloud/tfc/openlp/music/Eden-Phil Wickham [lyrics].mp3")); - addItem(new ServiceItem("Marvelous Light", "song", - "file:/home/chris/nextcloud/tfc/openlp/Fire Embers_Loop.mp4", - "video", QStringList("Hallelujah!"))); - addItem(new ServiceItem("BP Text", "video", - "file:/home/chris/nextcloud/tfc/openlp/videos/test.mp4", - "video", QStringList())); + if (!loadLastSaved()) { + addItem(new ServiceItem("10,000 Reasons", "song", + "file:/home/chris/nextcloud/tfc/openlp/CMG - Nature King 21.jpg", + "image", QStringList("Yip Yip"), + "file:/home/chris/nextcloud/tfc/openlp/music/Eden-Phil Wickham [lyrics].mp3")); + addItem(new ServiceItem("Marvelous Light", "song", + "file:/home/chris/nextcloud/tfc/openlp/Fire Embers_Loop.mp4", + "video", QStringList("Hallelujah!"))); + addItem(new ServiceItem("BP Text", "video", + "file:/home/chris/nextcloud/tfc/openlp/videos/test.mp4", + "video", QStringList())); + } } int ServiceItemModel::rowCount(const QModelIndex &parent) const { @@ -546,6 +549,13 @@ bool ServiceItemModel::save(QUrl file) { //close the archive so that everything is done tar.close(); + + QSettings settings; + settings.setValue("lastSaveFile", file); + + settings.sync(); + + qDebug() << settings.value("lastSaveFile"); return true; } @@ -611,3 +621,8 @@ void ServiceItemModel::clearAll() { removeItem(i); } } + +bool ServiceItemModel::loadLastSaved() { + QSettings settings; + return load(settings.value("lastSaveFile").toUrl()); +} diff --git a/src/serviceitemmodel.h b/src/serviceitemmodel.h index 8fdeae1..06bbcc8 100644 --- a/src/serviceitemmodel.h +++ b/src/serviceitemmodel.h @@ -93,6 +93,7 @@ public: Q_INVOKABLE bool save(QUrl file); Q_INVOKABLE bool load(QUrl file); + Q_INVOKABLE bool loadLastSaved(); private: QList m_items;