1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-20 01:34:04 +01:00

Fix remove all call

We need to first stop all currently running wallpaper,
before we remove the timelines
This commit is contained in:
Elias Steurer 2024-07-29 10:45:02 +02:00
parent 2f481e0846
commit d32b093651
7 changed files with 42 additions and 23 deletions

View File

@ -35,8 +35,8 @@ public:
const std::shared_ptr<MonitorListModel>& mlm, const std::shared_ptr<MonitorListModel>& mlm,
const std::shared_ptr<Settings>& settings); const std::shared_ptr<Settings>& settings);
Q_INVOKABLE QCoro::QmlTask removeAllWallpapers(bool saveToProfile = false); Q_INVOKABLE QCoro::QmlTask removeAllRunningWallpapers(bool saveToProfile = false);
Q_INVOKABLE bool removeAllWidgets(bool saveToProfile = false); Q_INVOKABLE bool removeAllRunningWidgets(bool saveToProfile = false);
Q_INVOKABLE QCoro::QmlTask removeWallpaperAt(const int timelineIndex, const QString timelineIdentifier, const int monitorIndex); Q_INVOKABLE QCoro::QmlTask removeWallpaperAt(const int timelineIndex, const QString timelineIdentifier, const int monitorIndex);
Q_INVOKABLE ScreenPlayWallpaper* getWallpaperByAppID(const QString& appID); Q_INVOKABLE ScreenPlayWallpaper* getWallpaperByAppID(const QString& appID);

View File

@ -470,23 +470,37 @@ Control {
} }
ToolButton { ToolButton {
text: "❌ Reset" //qsTr("Remove all timeline ranges") id: btnReset
text: resetting ? qsTr("Reseting...") : qsTr("❌ Reset")
property bool resetting: false
enabled: !resetting
z: 99 z: 99
anchors { anchors {
right: parent.right right: parent.right
top: parent.top top: parent.top
} }
onClicked: { onClicked: {
timeline.removeAll(); console.log("resetting", btnReset.resetting);
btnReset.resetting = true;
App.screenPlayManager.removeAllRunningWallpapers().then(result => {
if (!result.success) {
console.error("removeAllTimlineSections failed");
btnReset.resetting = false;
return;
}
App.screenPlayManager.removeAllTimlineSections().then(result => { App.screenPlayManager.removeAllTimlineSections().then(result => {
if (!result.success) { if (!result.success) {
console.error("removeAllTimlineSections failed"); console.error("removeAllTimlineSections failed");
btnReset.resetting = false;
return; return;
} }
timeline.removeAll();
const position = 1.0; const position = 1.0;
const identifier = App.util.generateRandomString(4); const identifier = App.util.generateRandomString(4);
const sectionObject = timeline.addSection(identifier, position); const sectionObject = timeline.addSection(identifier, position);
App.screenPlayManager.addTimelineAt(sectionObject.index, sectionObject.relativeLinePosition, sectionObject.identifier); App.screenPlayManager.addTimelineAt(sectionObject.index, sectionObject.relativeLinePosition, sectionObject.identifier);
btnReset.resetting = false;
});
}); });
} }
anchors { anchors {

View File

@ -189,7 +189,7 @@ Util.Popup {
font.family: App.settings.font font.family: App.settings.font
enabled: App.screenPlayManager.activeWallpaperCounter > 0 enabled: App.screenPlayManager.activeWallpaperCounter > 0
onClicked: { onClicked: {
if (!App.screenPlayManager.removeAllWallpapers(true)) if (!App.screenPlayManager.removeAllRunningWallpapers(true))
print("Unable to close all wallpaper!"); print("Unable to close all wallpaper!");
} }
} }
@ -204,7 +204,7 @@ Util.Popup {
font.family: App.settings.font font.family: App.settings.font
enabled: App.screenPlayManager.activeWidgetsCounter > 0 enabled: App.screenPlayManager.activeWidgetsCounter > 0
onClicked: { onClicked: {
if (!App.screenPlayManager.removeAllWidgets()) if (!App.screenPlayManager.removeAllRunningWidgets())
print("Unable to close all widgets!"); print("Unable to close all widgets!");
} }
} }

View File

@ -285,14 +285,15 @@ Rectangle {
icon.width: root.iconWidth icon.width: root.iconWidth
icon.height: root.iconHeight icon.height: root.iconHeight
onClicked: { onClicked: {
App.screenPlayManager.removeAllWallpapers(true); App.screenPlayManager.removeAllRunningWidgets(false);
App.screenPlayManager.removeAllWidgets(true); // Saves profiles.json
App.screenPlayManager.removeAllRunningWallpapers(true);
miStopAll.isPlaying = true; miStopAll.isPlaying = true;
miMuteAll.soundEnabled = true; miMuteAll.soundEnabled = true;
} }
hoverEnabled: true hoverEnabled: true
ToolTip.text: qsTr("Close All Content") ToolTip.text: qsTr("Stop All Running Content")
ToolTip.visible: hovered ToolTip.visible: hovered
} }
} }

View File

@ -125,7 +125,7 @@ void App::init()
// m_monitorListModel.get(), // m_monitorListModel.get(),
// &MonitorListModel::monitorConfigurationChanged, // &MonitorListModel::monitorConfigurationChanged,
// m_screenPlayManager.get(), [this]() { // m_screenPlayManager.get(), [this]() {
// m_screenPlayManager->removeAllWallpapers(true); // m_screenPlayManager->removeAllRunningWallpapers(true);
// }); // });
} }
@ -140,8 +140,8 @@ QString App::version() const
*/ */
void App::exit() void App::exit()
{ {
m_screenPlayManager->removeAllWallpapers(false); m_screenPlayManager->removeAllRunningWallpapers(false);
m_screenPlayManager->removeAllWidgets(false); m_screenPlayManager->removeAllRunningWidgets(false);
// Must be called inside a separate event loop otherwise we // Must be called inside a separate event loop otherwise we
// would kill the qml engine while it is calling this function. // would kill the qml engine while it is calling this function.
// A single shot timer is a handy woraround for this. // A single shot timer is a handy woraround for this.

View File

@ -165,13 +165,14 @@ void ScreenPlayManager::setSelectedTimelineIndex(const int selectedTimelineIndex
/*! /*!
\brief Removes all wallpaper entries in the profiles.json. \brief Removes all wallpaper entries in the profiles.json.
*/ */
QCoro::QmlTask ScreenPlayManager::removeAllWallpapers(bool saveToProfile) QCoro::QmlTask ScreenPlayManager::removeAllRunningWallpapers(bool saveToProfile)
{ {
return QCoro::QmlTask([this]() -> QCoro::Task<Result> { return QCoro::QmlTask([this, saveToProfile]() -> QCoro::Task<Result> {
// call with coro // call with coro
const bool success = co_await m_screenPlayTimelineManager.removeAllWallpaperFromActiveTimlineSections(); const bool success = co_await m_screenPlayTimelineManager.removeAllWallpaperFromActiveTimlineSections();
qDebug() << "Task: removeAllWallpaperFromActiveTimlineSections" << success; qDebug() << "Task: removeAllWallpaperFromActiveTimlineSections" << success;
// emit requestSaveProfiles(); if (saveToProfile)
emit requestSaveProfiles();
co_return Result { success }; co_return Result { success };
}()); }());
} }
@ -179,7 +180,7 @@ QCoro::QmlTask ScreenPlayManager::removeAllWallpapers(bool saveToProfile)
/*! /*!
\brief Removes all widgets and resets the activeWidgetCounter to 0. \brief Removes all widgets and resets the activeWidgetCounter to 0.
*/ */
bool ScreenPlayManager::removeAllWidgets(bool saveToProfile) bool ScreenPlayManager::removeAllRunningWidgets(bool saveToProfile)
{ {
if (m_screenPlayWidgets.empty()) { if (m_screenPlayWidgets.empty()) {
return false; return false;
@ -229,6 +230,7 @@ bool ScreenPlayManager::requestProjectSettingsAtMonitorIndex(const int index)
if (!activeTimelineSection) { if (!activeTimelineSection) {
return false; return false;
} }
// TODO CHANGE TO WP SECTION // TODO CHANGE TO WP SECTION
for (const auto& wallpaper : std::as_const(activeTimelineSection->activeWallpaperList)) { for (const auto& wallpaper : std::as_const(activeTimelineSection->activeWallpaperList)) {
if (wallpaper->monitors()[0] == index) { if (wallpaper->monitors()[0] == index) {
@ -328,7 +330,7 @@ QCoro::QmlTask ScreenPlayManager::removeAllTimlineSections()
const bool success = co_await m_screenPlayTimelineManager.removeAllTimlineSections(); const bool success = co_await m_screenPlayTimelineManager.removeAllTimlineSections();
qDebug() << "Task: removeAllTimlineSections" << success; qDebug() << "Task: removeAllTimlineSections" << success;
// emit requestSaveProfiles(); // emit requestSaveProfiles();
// removeAllWallpapers(); // removeAllRunningWallpapers();
co_return Result { success }; co_return Result { success };
}()); }());
} }

View File

@ -100,7 +100,9 @@ bool WallpaperTimelineSection::activateTimeline()
QCoro::Task<bool> WallpaperTimelineSection::deactivateTimeline() QCoro::Task<bool> WallpaperTimelineSection::deactivateTimeline()
{ {
if (activeWallpaperList.empty()) {
co_return true;
}
status = Status::Closing; status = Status::Closing;
for (auto& activeWallpaper : activeWallpaperList) { for (auto& activeWallpaper : activeWallpaperList) {
activeWallpaper->close(); activeWallpaper->close();