1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-10-06 09:17:07 +02:00

ScreenPlay::removeWallpaperAt(int at) does remove walls now(not done)

This commit is contained in:
JeJo 2019-04-22 21:58:25 +02:00
parent e5504e2c14
commit d23cd0ffd3
3 changed files with 67 additions and 42 deletions

View File

@ -9,6 +9,15 @@ ScreenPlay::ScreenPlay(InstalledListModel* ilm, Settings* set, MonitorListModel*
m_sdkc{sdkc} 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 InstalledListModel* ScreenPlay::listModelInstalled() const noexcept { return m_ilm; }
const Settings* ScreenPlay::settings() const noexcept { return m_settings; } const Settings* ScreenPlay::settings() const noexcept { return m_settings; }
const MonitorListModel* ScreenPlay::monitorListModel() const noexcept { return m_mlm; } const MonitorListModel* ScreenPlay::monitorListModel() const noexcept { return m_mlm; }
@ -19,8 +28,8 @@ const std::vector<RefSPWidget>& ScreenPlay::spWidgetList() const noexcept { retu
void ScreenPlay::createWallpaper( void ScreenPlay::createWallpaper(
const int monitorIndex, QUrl absoluteStoragePath, const int monitorIndex, QUrl absoluteStoragePath,
const QString &previewImage, const float volume, const QString& previewImage, const float volume,
const QString &fillMode, const QString &type) const QString& fillMode, const QString& type)
{ {
ProjectFile project{}; ProjectFile project{};
if (!m_ilm->getProjectByAbsoluteStoragePath(&absoluteStoragePath, &project)) { if (!m_ilm->getProjectByAbsoluteStoragePath(&absoluteStoragePath, &project)) {
@ -30,16 +39,18 @@ void ScreenPlay::createWallpaper(
//this->removeAllWallpaper(); //this->removeAllWallpaper();
this->removeWallpaperAt(0); this->removeWallpaperAt(0);
m_settings->increaseActiveWallpaperCounter(); m_settings->increaseActiveWallpaperCounter();
m_screenPlayWallpaperList.emplace_back( m_screenPlayWallpaperList.emplace_back(
RefSPWall::create( RefSPWall::create(
QVector<int>{monitorIndex}, absoluteStoragePath.toLocalFile(), std::vector<int>{monitorIndex}, absoluteStoragePath.toLocalFile(),
previewImage, volume, fillMode, type, this) previewImage, volume, fillMode, type, this)
); );
m_mlm->setWallpaperActiveMonitor(m_qGuiApplication->screens().at(monitorIndex), m_mlm->setWallpaperActiveMonitor(m_qGuiApplication->screens().at(monitorIndex),
QString{absoluteStoragePath.toLocalFile() + "/" + previewImage}); QString{absoluteStoragePath.toLocalFile() + "/" + previewImage});
} }
void ScreenPlay::createWidget(QUrl absoluteStoragePath, const QString &previewImage) void ScreenPlay::createWidget(QUrl absoluteStoragePath, const QString& previewImage)
{ {
ProjectFile project{}; ProjectFile project{};
if (!m_ilm->getProjectByAbsoluteStoragePath(&absoluteStoragePath, &project)) { if (!m_ilm->getProjectByAbsoluteStoragePath(&absoluteStoragePath, &project)) {
@ -66,7 +77,7 @@ void ScreenPlay::removeAllWallpaper() noexcept
void ScreenPlay::requestProjectSettingsListModelAt(const int index) const 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() && if (!refSPWallpaper.data()->screenNumber().empty() &&
refSPWallpaper.data()->screenNumber()[0] == index) { // ??? only at index == 0 refSPWallpaper.data()->screenNumber()[0] == index) { // ??? only at index == 0
emit projectSettingsListModelFound( emit projectSettingsListModelFound(
@ -78,10 +89,10 @@ void ScreenPlay::requestProjectSettingsListModelAt(const int index) const noexce
emit projectSettingsListModelNotFound(); 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<std::size_t>(at) < m_screenPlayWallpaperList.size() && m_sdkc); Q_ASSERT(static_cast<std::size_t>(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 && if (!refSPWallpaper.data()->screenNumber().empty() && m_sdkc &&
refSPWallpaper.data()->screenNumber()[0] == at) { // ??? only at index == 0 refSPWallpaper.data()->screenNumber()[0] == at) { // ??? only at index == 0
m_sdkc->setWallpaperValue(refSPWallpaper.data()->appID(), key, value); 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); 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); 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()) const auto toRemove = std::remove_if(
return; m_screenPlayWallpaperList.begin(), m_screenPlayWallpaperList.end(),
[&](const RefSPWall& refSPWallpaper) noexcept ->bool {
for (int i = 0; i < m_screenPlayWallpaperList.length(); ++i) { const std::vector<int>& screenNumber = refSPWallpaper->screenNumber();
qDebug() << "Screen No. :" << screenNumber.size();
if (m_screenPlayWallpaperList.at(i).data()->screenNumber().at(0) == at) { const bool isFound = !screenNumber.empty();// && screenNumber[0] == at;
qDebug() << i << m_screenPlayWallpaperList.at(i).data()->screenNumber().at(0); if(isFound) {
m_sdkc->closeWallpapersAt(at); // m_mlm
m_screenPlayWallpaperList.removeAt(i); 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<int> ScreenPlay::getMonitorByAppID(const QString &appID) const std::vector<int> ScreenPlay::getMonitorByAppID(const QString& appID) const
{ {
for (const RefSPWall &refSPWallpaper: m_screenPlayWallpaperList) { for (const RefSPWall& refSPWallpaper: m_screenPlayWallpaperList) {
if (refSPWallpaper.data()->appID() == appID) { if (refSPWallpaper.data()->appID() == appID) {
return refSPWallpaper.data()->screenNumber(); return refSPWallpaper.data()->screenNumber();
} }
} }
return QVector<int>{}; return std::vector<int>{};
} }
QString ScreenPlay::generateID() const QString ScreenPlay::generateID() const
@ -141,6 +160,7 @@ QString ScreenPlay::generateID() const
return randomString; return randomString;
} }
ScreenPlayWallpaper::ScreenPlayWallpaper(const std::vector<int>& screenNumber, const QString& projectPath, ScreenPlayWallpaper::ScreenPlayWallpaper(const std::vector<int>& screenNumber, const QString& projectPath,
const QString& previewImage, const float volume, const QString& previewImage, const float volume,
const QString& fillMode, const QString& type, ScreenPlay *parent) const QString& fillMode, const QString& type, ScreenPlay *parent)

View File

@ -23,11 +23,11 @@
class ScreenPlayWallpaper; class ScreenPlayWallpaper;
class ScreenPlayWidget; class ScreenPlayWidget;
// conveniences types // convenience types
using RefSPWall = QSharedPointer<ScreenPlayWallpaper>; using RefSPWall = QSharedPointer<ScreenPlayWallpaper>;
using RefSPWidget = QSharedPointer<ScreenPlayWidget>; using RefSPWidget = QSharedPointer<ScreenPlayWidget>;
class ScreenPlay : public QObject { class ScreenPlay final: public QObject {
Q_OBJECT Q_OBJECT
private: private:
InstalledListModel *const m_ilm{nullptr}; InstalledListModel *const m_ilm{nullptr};
@ -48,6 +48,9 @@ public:
// copy and move disable(for now) : remember rule of 1/3/5 // copy and move disable(for now) : remember rule of 1/3/5
Q_DISABLE_COPY_MOVE(ScreenPlay) Q_DISABLE_COPY_MOVE(ScreenPlay)
// destructor
~ScreenPlay();
// getters // getters
const InstalledListModel* listModelInstalled() const noexcept; const InstalledListModel* listModelInstalled() const noexcept;
const Settings* settings() const noexcept; const Settings* settings() const noexcept;
@ -57,26 +60,23 @@ public:
const std::vector<RefSPWall>& spWallList() const noexcept; const std::vector<RefSPWall>& spWallList() const noexcept;
const std::vector<RefSPWidget>& spWidgetList() const noexcept; const std::vector<RefSPWidget>& spWidgetList() const noexcept;
signals: signals:
void allWallpaperRemoved() const; void allWallpaperRemoved() const;
void projectSettingsListModelFound(ProjectSettingsListModel* li, const QString &type) const; void projectSettingsListModelFound(ProjectSettingsListModel* li, const QString& type) const;
void projectSettingsListModelNotFound() const; void projectSettingsListModelNotFound() const;
public slots: public slots:
void removeWallpaperAt(int at);
void createWallpaper( void createWallpaper(
const int monitorIndex, QUrl absoluteStoragePath, const int monitorIndex, QUrl absoluteStoragePath,
const QString &previewImage, const float volume, const QString& previewImage, const float volume,
const QString &fillMode, const QString &type); const QString& fillMode, const QString& type);
void createWidget(QUrl absoluteStoragePath, const QString &previewImage); void createWidget(QUrl absoluteStoragePath, const QString& previewImage);
void removeAllWallpaper() noexcept; void removeAllWallpaper() noexcept;
void requestProjectSettingsListModelAt(const int index) const noexcept; void requestProjectSettingsListModelAt(const int index) const noexcept;
void setWallpaperValue(const int at, const QString &key, const QString &value) noexcept; void setWallpaperValue(const int at, const QString& key, const QString& value) noexcept;
void setAllWallpaperValue(const QString &key, const QString &value) noexcept; void setAllWallpaperValue(const QString& key, const QString& value) noexcept;
void removeWallpaperAt(const int at); void removeWallpaperAt(const int at = 0);
QVector<int> getMonitorByAppID(const QString &appID) const; std::vector<int> getMonitorByAppID(const QString& appID) const;
QString generateID() const; QString generateID() const;
}; };

View File

@ -34,13 +34,18 @@ void SDKConnector::closeAllWallpapers()
void SDKConnector::closeWallpapersAt(int at) void SDKConnector::closeWallpapersAt(int at)
{ {
for (int i = 0; i < m_clients.size(); ++i) { for (const QSharedPointer<SDKConnection>& refSDKConnection : m_clients) {
if (m_clients.at(i).data()->monitor().size() > 0) { refSDKConnection->close();
if (m_clients.at(i).data()->monitor().at(0) == at) { if (!refSDKConnection->monitor().empty()) {
m_clients.at(i).data()->close(); // problem here !!
if (refSDKConnection->monitor().at(0) == at) {
refSDKConnection->close();
qDebug() << "Wall Closed...!";
} else {
qDebug() << "COULD NOT CLOSE!";
} }
} else { } else {
qDebug() << "no wp window"; qDebug() << "no wp window ";
} }
} }
} }