1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-07-08 13:54:53 +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}
{}
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<RefSPWidget>& 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<int>{monitorIndex}, absoluteStoragePath.toLocalFile(),
std::vector<int>{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<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 &&
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<int>& 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<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) {
return refSPWallpaper.data()->screenNumber();
}
}
return QVector<int>{};
return std::vector<int>{};
}
QString ScreenPlay::generateID() const
@ -141,6 +160,7 @@ QString ScreenPlay::generateID() const
return randomString;
}
ScreenPlayWallpaper::ScreenPlayWallpaper(const std::vector<int>& screenNumber, const QString& projectPath,
const QString& previewImage, const float volume,
const QString& fillMode, const QString& type, ScreenPlay *parent)

View File

@ -23,11 +23,11 @@
class ScreenPlayWallpaper;
class ScreenPlayWidget;
// conveniences types
// convenience types
using RefSPWall = QSharedPointer<ScreenPlayWallpaper>;
using RefSPWidget = QSharedPointer<ScreenPlayWidget>;
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<RefSPWall>& spWallList() const noexcept;
const std::vector<RefSPWidget>& 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<int> 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<int> getMonitorByAppID(const QString& appID) const;
QString generateID() const;
};

View File

@ -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<SDKConnection>& 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 ";
}
}
}