1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-10-02 23:37:08 +02: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<Settings>& settings);
Q_INVOKABLE QCoro::QmlTask removeAllWallpapers(bool saveToProfile = false);
Q_INVOKABLE bool removeAllWidgets(bool saveToProfile = false);
Q_INVOKABLE QCoro::QmlTask removeAllRunningWallpapers(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 ScreenPlayWallpaper* getWallpaperByAppID(const QString& appID);

View File

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

View File

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

View File

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

View File

@ -125,7 +125,7 @@ void App::init()
// m_monitorListModel.get(),
// &MonitorListModel::monitorConfigurationChanged,
// m_screenPlayManager.get(), [this]() {
// m_screenPlayManager->removeAllWallpapers(true);
// m_screenPlayManager->removeAllRunningWallpapers(true);
// });
}
@ -140,8 +140,8 @@ QString App::version() const
*/
void App::exit()
{
m_screenPlayManager->removeAllWallpapers(false);
m_screenPlayManager->removeAllWidgets(false);
m_screenPlayManager->removeAllRunningWallpapers(false);
m_screenPlayManager->removeAllRunningWidgets(false);
// Must be called inside a separate event loop otherwise we
// would kill the qml engine while it is calling this function.
// 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.
*/
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
const bool success = co_await m_screenPlayTimelineManager.removeAllWallpaperFromActiveTimlineSections();
qDebug() << "Task: removeAllWallpaperFromActiveTimlineSections" << success;
// emit requestSaveProfiles();
if (saveToProfile)
emit requestSaveProfiles();
co_return Result { success };
}());
}
@ -179,7 +180,7 @@ QCoro::QmlTask ScreenPlayManager::removeAllWallpapers(bool saveToProfile)
/*!
\brief Removes all widgets and resets the activeWidgetCounter to 0.
*/
bool ScreenPlayManager::removeAllWidgets(bool saveToProfile)
bool ScreenPlayManager::removeAllRunningWidgets(bool saveToProfile)
{
if (m_screenPlayWidgets.empty()) {
return false;
@ -229,6 +230,7 @@ bool ScreenPlayManager::requestProjectSettingsAtMonitorIndex(const int index)
if (!activeTimelineSection) {
return false;
}
// TODO CHANGE TO WP SECTION
for (const auto& wallpaper : std::as_const(activeTimelineSection->activeWallpaperList)) {
if (wallpaper->monitors()[0] == index) {
@ -328,7 +330,7 @@ QCoro::QmlTask ScreenPlayManager::removeAllTimlineSections()
const bool success = co_await m_screenPlayTimelineManager.removeAllTimlineSections();
qDebug() << "Task: removeAllTimlineSections" << success;
// emit requestSaveProfiles();
// removeAllWallpapers();
// removeAllRunningWallpapers();
co_return Result { success };
}());
}

View File

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