From d23cd0ffd3d63e372bf05453f2b216340f0459e4 Mon Sep 17 00:00:00 2001 From: JeJo Date: Mon, 22 Apr 2019 21:58:25 +0200 Subject: [PATCH] ScreenPlay::removeWallpaperAt(int at) does remove walls now(not done) --- ScreenPlay/src/screenplay.cpp | 68 +++++++++++++++++++++------------ ScreenPlay/src/screenplay.h | 26 ++++++------- ScreenPlay/src/sdkconnector.cpp | 15 +++++--- 3 files changed, 67 insertions(+), 42 deletions(-) diff --git a/ScreenPlay/src/screenplay.cpp b/ScreenPlay/src/screenplay.cpp index 0d5f94f5..22aca27a 100644 --- a/ScreenPlay/src/screenplay.cpp +++ b/ScreenPlay/src/screenplay.cpp @@ -9,6 +9,15 @@ ScreenPlay::ScreenPlay(InstalledListModel* ilm, Settings* set, MonitorListModel* m_sdkc{sdkc} {} +ScreenPlay::~ScreenPlay() +{ + if(m_ilm) delete m_ilm; + if(m_settings) delete m_settings; + if(m_mlm) delete m_mlm; + if(m_qGuiApplication) delete m_qGuiApplication; + if(m_sdkc) delete m_sdkc; +} + const InstalledListModel* ScreenPlay::listModelInstalled() const noexcept { return m_ilm; } const Settings* ScreenPlay::settings() const noexcept { return m_settings; } const MonitorListModel* ScreenPlay::monitorListModel() const noexcept { return m_mlm; } @@ -19,8 +28,8 @@ const std::vector& ScreenPlay::spWidgetList() const noexcept { retu void ScreenPlay::createWallpaper( const int monitorIndex, QUrl absoluteStoragePath, - const QString &previewImage, const float volume, - const QString &fillMode, const QString &type) + const QString& previewImage, const float volume, + const QString& fillMode, const QString& type) { ProjectFile project{}; if (!m_ilm->getProjectByAbsoluteStoragePath(&absoluteStoragePath, &project)) { @@ -30,16 +39,18 @@ void ScreenPlay::createWallpaper( //this->removeAllWallpaper(); this->removeWallpaperAt(0); m_settings->increaseActiveWallpaperCounter(); + m_screenPlayWallpaperList.emplace_back( RefSPWall::create( - QVector{monitorIndex}, absoluteStoragePath.toLocalFile(), + std::vector{monitorIndex}, absoluteStoragePath.toLocalFile(), previewImage, volume, fillMode, type, this) ); + m_mlm->setWallpaperActiveMonitor(m_qGuiApplication->screens().at(monitorIndex), QString{absoluteStoragePath.toLocalFile() + "/" + previewImage}); } -void ScreenPlay::createWidget(QUrl absoluteStoragePath, const QString &previewImage) +void ScreenPlay::createWidget(QUrl absoluteStoragePath, const QString& previewImage) { ProjectFile project{}; if (!m_ilm->getProjectByAbsoluteStoragePath(&absoluteStoragePath, &project)) { @@ -66,7 +77,7 @@ void ScreenPlay::removeAllWallpaper() noexcept void ScreenPlay::requestProjectSettingsListModelAt(const int index) const noexcept { - for (const RefSPWall &refSPWallpaper: m_screenPlayWallpaperList) { + for (const RefSPWall& refSPWallpaper: m_screenPlayWallpaperList) { if (!refSPWallpaper.data()->screenNumber().empty() && refSPWallpaper.data()->screenNumber()[0] == index) { // ??? only at index == 0 emit projectSettingsListModelFound( @@ -78,10 +89,10 @@ void ScreenPlay::requestProjectSettingsListModelAt(const int index) const noexce emit projectSettingsListModelNotFound(); } -void ScreenPlay::setWallpaperValue(const int at, const QString &key, const QString &value) noexcept +void ScreenPlay::setWallpaperValue(const int at, const QString& key, const QString& value) noexcept { Q_ASSERT(static_cast(at) < m_screenPlayWallpaperList.size() && m_sdkc); - for (const RefSPWall &refSPWallpaper: m_screenPlayWallpaperList) { + for (const RefSPWall& refSPWallpaper: m_screenPlayWallpaperList) { if (!refSPWallpaper.data()->screenNumber().empty() && m_sdkc && refSPWallpaper.data()->screenNumber()[0] == at) { // ??? only at index == 0 m_sdkc->setWallpaperValue(refSPWallpaper.data()->appID(), key, value); @@ -90,39 +101,47 @@ void ScreenPlay::setWallpaperValue(const int at, const QString &key, const QStri } } -void ScreenPlay::setAllWallpaperValue(const QString &key, const QString &value) noexcept +void ScreenPlay::setAllWallpaperValue(const QString& key, const QString& value) noexcept { Q_ASSERT(m_sdkc); - for (const RefSPWall &refSPWallpaper: m_screenPlayWallpaperList) { + for (const RefSPWall& refSPWallpaper: m_screenPlayWallpaperList) { if(m_sdkc) m_sdkc->setWallpaperValue(refSPWallpaper.data()->appID(), key, value); } } -void ScreenPlay::removeWallpaperAt(int at) +void ScreenPlay::removeWallpaperAt(const int at) { - //Q_ASSERT(m_screenPlayWallpaperList.size() < at); + // Q_ASSERT(at < m_screenPlayWallpaperList.size() && m_sdkc); + qDebug() << "No of walls in list: " << m_screenPlayWallpaperList.size(); + if(m_screenPlayWallpaperList.empty()) return; // done here; - if (m_screenPlayWallpaperList.isEmpty()) - return; - - for (int i = 0; i < m_screenPlayWallpaperList.length(); ++i) { - - if (m_screenPlayWallpaperList.at(i).data()->screenNumber().at(0) == at) { - qDebug() << i << m_screenPlayWallpaperList.at(i).data()->screenNumber().at(0); - m_sdkc->closeWallpapersAt(at); - m_screenPlayWallpaperList.removeAt(i); + const auto toRemove = std::remove_if( + m_screenPlayWallpaperList.begin(), m_screenPlayWallpaperList.end(), + [&](const RefSPWall& refSPWallpaper) noexcept ->bool { + const std::vector& screenNumber = refSPWallpaper->screenNumber(); + qDebug() << "Screen No. :" << screenNumber.size(); + const bool isFound = !screenNumber.empty();// && screenNumber[0] == at; + if(isFound) { + // m_mlm + m_sdkc->closeWallpapersAt(at); // for waht ??? + m_settings->decreaseActiveWallpaperCounter(); + qDebug() << "current wall count... " << m_settings->activeWallpaperCounter(); } - } + return isFound; + }); + m_screenPlayWallpaperList.erase(toRemove, m_screenPlayWallpaperList.end()); + qDebug() << "After removing: No of walls in list: " << m_screenPlayWallpaperList.size(); + } -QVector ScreenPlay::getMonitorByAppID(const QString &appID) const +std::vector ScreenPlay::getMonitorByAppID(const QString& appID) const { - for (const RefSPWall &refSPWallpaper: m_screenPlayWallpaperList) { + for (const RefSPWall& refSPWallpaper: m_screenPlayWallpaperList) { if (refSPWallpaper.data()->appID() == appID) { return refSPWallpaper.data()->screenNumber(); } } - return QVector{}; + return std::vector{}; } QString ScreenPlay::generateID() const @@ -141,6 +160,7 @@ QString ScreenPlay::generateID() const return randomString; } + ScreenPlayWallpaper::ScreenPlayWallpaper(const std::vector& screenNumber, const QString& projectPath, const QString& previewImage, const float volume, const QString& fillMode, const QString& type, ScreenPlay *parent) diff --git a/ScreenPlay/src/screenplay.h b/ScreenPlay/src/screenplay.h index 9e418b75..a7ea0490 100644 --- a/ScreenPlay/src/screenplay.h +++ b/ScreenPlay/src/screenplay.h @@ -23,11 +23,11 @@ class ScreenPlayWallpaper; class ScreenPlayWidget; -// conveniences types +// convenience types using RefSPWall = QSharedPointer; using RefSPWidget = QSharedPointer; -class ScreenPlay : public QObject { +class ScreenPlay final: public QObject { Q_OBJECT private: InstalledListModel *const m_ilm{nullptr}; @@ -48,6 +48,9 @@ public: // copy and move disable(for now) : remember rule of 1/3/5 Q_DISABLE_COPY_MOVE(ScreenPlay) + // destructor + ~ScreenPlay(); + // getters const InstalledListModel* listModelInstalled() const noexcept; const Settings* settings() const noexcept; @@ -57,26 +60,23 @@ public: const std::vector& spWallList() const noexcept; const std::vector& spWidgetList() const noexcept; - - signals: void allWallpaperRemoved() const; - void projectSettingsListModelFound(ProjectSettingsListModel* li, const QString &type) const; + void projectSettingsListModelFound(ProjectSettingsListModel* li, const QString& type) const; void projectSettingsListModelNotFound() const; public slots: - void removeWallpaperAt(int at); void createWallpaper( const int monitorIndex, QUrl absoluteStoragePath, - const QString &previewImage, const float volume, - const QString &fillMode, const QString &type); - void createWidget(QUrl absoluteStoragePath, const QString &previewImage); + const QString& previewImage, const float volume, + const QString& fillMode, const QString& type); + void createWidget(QUrl absoluteStoragePath, const QString& previewImage); void removeAllWallpaper() noexcept; void requestProjectSettingsListModelAt(const int index) const noexcept; - void setWallpaperValue(const int at, const QString &key, const QString &value) noexcept; - void setAllWallpaperValue(const QString &key, const QString &value) noexcept; - void removeWallpaperAt(const int at); - QVector getMonitorByAppID(const QString &appID) const; + void setWallpaperValue(const int at, const QString& key, const QString& value) noexcept; + void setAllWallpaperValue(const QString& key, const QString& value) noexcept; + void removeWallpaperAt(const int at = 0); + std::vector getMonitorByAppID(const QString& appID) const; QString generateID() const; }; diff --git a/ScreenPlay/src/sdkconnector.cpp b/ScreenPlay/src/sdkconnector.cpp index 21b881e5..b2251dbf 100644 --- a/ScreenPlay/src/sdkconnector.cpp +++ b/ScreenPlay/src/sdkconnector.cpp @@ -34,13 +34,18 @@ void SDKConnector::closeAllWallpapers() void SDKConnector::closeWallpapersAt(int at) { - for (int i = 0; i < m_clients.size(); ++i) { - if (m_clients.at(i).data()->monitor().size() > 0) { - if (m_clients.at(i).data()->monitor().at(0) == at) { - m_clients.at(i).data()->close(); + for (const QSharedPointer& refSDKConnection : m_clients) { + refSDKConnection->close(); + if (!refSDKConnection->monitor().empty()) { + // problem here !! + if (refSDKConnection->monitor().at(0) == at) { + refSDKConnection->close(); + qDebug() << "Wall Closed...!"; + } else { + qDebug() << "COULD NOT CLOSE!"; } } else { - qDebug() << "no wp window"; + qDebug() << "no wp window "; } } }