mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-09-18 08:22:33 +02:00
Fix closing of wallpaper in MonitorSelection
We did not remove wallpaperData, but only the running wallpaper resulting in a reenabling of the wallpaper
This commit is contained in:
parent
74fb1f2b29
commit
ca7908d844
@ -55,7 +55,7 @@ signals:
|
||||
void activeWallpaperCountChanged(const int count);
|
||||
|
||||
private:
|
||||
std::optional<std::shared_ptr<WallpaperTimelineSection>> activeWallpaperSection(const int timelineIndex, const QString timelineIdentifier);
|
||||
std::optional<std::shared_ptr<WallpaperTimelineSection>> wallpaperSection(const int timelineIndex, const QString timelineIdentifier);
|
||||
|
||||
private:
|
||||
QVector<std::shared_ptr<WallpaperTimelineSection>> m_wallpaperTimelineSectionsList;
|
||||
|
@ -12,8 +12,8 @@ Rectangle {
|
||||
property alias text: text.text
|
||||
property alias wallpaperPreviewImage: imgWallpaper.source
|
||||
|
||||
signal remove(var index)
|
||||
signal lineSelected(var index)
|
||||
signal remove(int index)
|
||||
signal lineSelected(int index)
|
||||
|
||||
Text {
|
||||
id: text
|
||||
|
@ -193,7 +193,7 @@ Util.Popup {
|
||||
}
|
||||
|
||||
Button {
|
||||
id: btnRemoveAllWallpape
|
||||
id: btnRemoveAllWallpaper
|
||||
|
||||
text: qsTr("Remove all ") + App.screenPlayManager.activeWallpaperCounter + " " + qsTr("Wallpapers")
|
||||
Material.background: Material.accent
|
||||
|
@ -32,9 +32,8 @@ Rectangle {
|
||||
signal requestProjectSettings(int index, var installedType, string appID)
|
||||
signal requestRemoveWallpaper(int index)
|
||||
|
||||
|
||||
function getActiveMonitors(){
|
||||
return root.activeMonitors
|
||||
function getActiveMonitors() {
|
||||
return root.activeMonitors;
|
||||
}
|
||||
|
||||
function selectOnly(index) {
|
||||
|
@ -139,9 +139,12 @@ Drawer {
|
||||
return;
|
||||
}
|
||||
monitorSelection.enabled = false;
|
||||
App.screenPlayManager.removeWallpaperAt(selectedTimeline.index, selectedTimeline.identifier,monitorIndex ).then(result => {
|
||||
App.screenPlayManager.removeWallpaperAt(selectedTimeline.index, selectedTimeline.identifier, monitorIndex).then(result => {
|
||||
monitorSelection.enabled = true;
|
||||
if (!result.success) {} else {}
|
||||
if (result.success) {
|
||||
// Reset to update the wallpaper preview image
|
||||
timeline.reset();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,7 @@ QCoro::QmlTask ScreenPlayManager::removeWallpaperAt(int timelineIndex, QString t
|
||||
// call with coro
|
||||
const bool success = co_await m_screenPlayTimelineManager.removeWallpaperAt(timelineIndex, timelineIdentifier, monitorIndex);
|
||||
qDebug() << "Task: removeAllWallpaperFromActiveTimlineSections" << success;
|
||||
// crash? mit requestSaveProfiles();
|
||||
emit requestSaveProfiles();
|
||||
co_return Result { success };
|
||||
}());
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ void ScreenPlayTimelineManager::checkActiveWallpaperTimeline()
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<WallpaperTimelineSection>> ScreenPlayTimelineManager::activeWallpaperSection(const int timelineIndex, const QString timelineIdentifier)
|
||||
std::optional<std::shared_ptr<WallpaperTimelineSection>> ScreenPlayTimelineManager::wallpaperSection(const int timelineIndex, const QString timelineIdentifier)
|
||||
{
|
||||
for (const auto& section : m_wallpaperTimelineSectionsList) {
|
||||
const bool indexMatches = section->index == timelineIndex;
|
||||
@ -226,33 +226,33 @@ void ScreenPlayTimelineManager::updateMonitorListModelData(const int selectedTim
|
||||
// Clear current list model. This is needed to make sure
|
||||
// that we do not show any old active wallpaper
|
||||
|
||||
if (!selectedTimeline.empty()) {
|
||||
std::shared_ptr<WallpaperTimelineSection>& timeline = selectedTimeline.front();
|
||||
if (selectedTimeline.empty()) {
|
||||
qCritical() << "No selectedTimelineIndex found" << selectedTimelineIndex;
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<WallpaperTimelineSection>& timeline = selectedTimeline.front();
|
||||
|
||||
m_monitorListModel->reset();
|
||||
m_monitorListModel->reset();
|
||||
|
||||
for (int i = 0; i < m_monitorListModel->rowCount(); ++i) {
|
||||
// One wallpaper can span across multiple monitors
|
||||
bool ok;
|
||||
const int monitorIndex = m_monitorListModel->data(m_monitorListModel->index(i), (int)MonitorListModel::MonitorRole::Index).toInt(&ok);
|
||||
if (!ok) {
|
||||
qCritical() << "Invalid monitor index at: " << i;
|
||||
return;
|
||||
}
|
||||
for (const auto& wallpaper : timeline->activeWallpaperList) {
|
||||
if (wallpaper->monitors().contains(monitorIndex)) {
|
||||
const auto previewImg = wallpaper->absolutePath() + "/" + wallpaper->previewImage();
|
||||
const auto mondelIndex = m_monitorListModel->index(0, monitorIndex);
|
||||
m_monitorListModel->setData(mondelIndex, previewImg, (int)MonitorListModel::MonitorRole::PreviewImage);
|
||||
m_monitorListModel->setData(mondelIndex, wallpaper->appID(), (int)MonitorListModel::MonitorRole::AppID);
|
||||
m_monitorListModel->setData(mondelIndex, (int)wallpaper->type(), (int)MonitorListModel::MonitorRole::InstalledType);
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < m_monitorListModel->rowCount(); ++i) {
|
||||
// One wallpaper can span across multiple monitors
|
||||
bool ok;
|
||||
const int monitorIndex = m_monitorListModel->data(m_monitorListModel->index(i), (int)MonitorListModel::MonitorRole::Index).toInt(&ok);
|
||||
if (!ok) {
|
||||
qCritical() << "Invalid monitor index at: " << i;
|
||||
return;
|
||||
}
|
||||
for (const auto& wallpaper : timeline->wallpaperDataList) {
|
||||
if (wallpaper.monitors.contains(monitorIndex)) {
|
||||
const auto previewImg = wallpaper.absolutePath + "/" + wallpaper.previewImage;
|
||||
const auto mondelIndex = m_monitorListModel->index(0, monitorIndex);
|
||||
m_monitorListModel->setData(mondelIndex, previewImg, (int)MonitorListModel::MonitorRole::PreviewImage);
|
||||
// TODO
|
||||
m_monitorListModel->setData(mondelIndex, "dummy", (int)MonitorListModel::MonitorRole::AppID);
|
||||
m_monitorListModel->setData(mondelIndex, (int)wallpaper.type, (int)MonitorListModel::MonitorRole::InstalledType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
qCritical() << "No selectedTimelineIndex found" << selectedTimelineIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@ -416,9 +416,11 @@ QCoro::Task<bool> ScreenPlayTimelineManager::removeAllWallpaperFromActiveTimline
|
||||
QCoro::Task<bool> ScreenPlayTimelineManager::removeWallpaperAt(const int timelineIndex, const QString timelineIdentifier, const int monitorIndex)
|
||||
{
|
||||
m_contentTimer.stop();
|
||||
auto updateTimer = qScopeGuard([this] { m_contentTimer.start(); });
|
||||
auto updateTimer = qScopeGuard([this] {
|
||||
m_contentTimer.start();
|
||||
});
|
||||
|
||||
std::optional<std::shared_ptr<WallpaperTimelineSection>> sectionOpt = activeWallpaperSection(timelineIndex, timelineIdentifier);
|
||||
std::optional<std::shared_ptr<WallpaperTimelineSection>> sectionOpt = wallpaperSection(timelineIndex, timelineIdentifier);
|
||||
if (!sectionOpt)
|
||||
co_return false;
|
||||
|
||||
|
@ -145,22 +145,45 @@ QCoro::Task<bool> WallpaperTimelineSection::deactivateTimeline()
|
||||
co_return false;
|
||||
}
|
||||
|
||||
// Remove the running wallpaper and the corresponding
|
||||
// WallpaperData!
|
||||
QCoro::Task<bool> WallpaperTimelineSection::removeWallpaper(const int monitorIndex)
|
||||
{
|
||||
auto wallpaperOpt = wallpaperByMonitorIndex(monitorIndex);
|
||||
if (!wallpaperOpt.has_value()) {
|
||||
qCritical() << "No wallpaper found for monitor index:" << monitorIndex;
|
||||
|
||||
size_t removedCount = std::erase_if(wallpaperDataList, [monitorIndex](const auto& wallpaperData) {
|
||||
return wallpaperData.monitors.contains(monitorIndex);
|
||||
});
|
||||
|
||||
if (removedCount == 0) {
|
||||
qCritical() << "No wallpaper data found for monitor index:" << monitorIndex;
|
||||
co_return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<ScreenPlayWallpaper> runningScreenPlayWallpaper;
|
||||
bool found = false;
|
||||
for (const auto& screenPlayWallpaper : activeWallpaperList) {
|
||||
if (screenPlayWallpaper->monitors().contains(monitorIndex)) {
|
||||
runningScreenPlayWallpaper = screenPlayWallpaper;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// The user always can select a not running timeline section
|
||||
// and remove the wallpaper there. This means that it is
|
||||
// fine to just return here.
|
||||
if (!found) {
|
||||
qDebug() << "No running wallpaper found for monitor index:" << monitorIndex;
|
||||
co_return true;
|
||||
}
|
||||
|
||||
QTimer timer;
|
||||
timer.start(250);
|
||||
const int maxRetries = 30;
|
||||
wallpaperOpt.value()->close();
|
||||
runningScreenPlayWallpaper->close();
|
||||
for (int i = 1; i <= maxRetries; ++i) {
|
||||
// Wait for the timer to tick
|
||||
co_await timer;
|
||||
if (!wallpaperOpt.value()->isConnected()) {
|
||||
if (!runningScreenPlayWallpaper->isConnected()) {
|
||||
co_return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user