1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-23 01:33:50 +03:00

Storage:update newView for views editor

--trying to support newView that works in all the
cases between inactive/active layouts
This commit is contained in:
Michail Vourlakos 2021-04-17 14:37:09 +03:00
parent dc56e61e64
commit 1fac17d6ba
8 changed files with 111 additions and 36 deletions

View File

@ -1164,8 +1164,8 @@ QStringList Corona::viewTemplatesData()
void Corona::addView(const uint &containmentId, const QString &templateId) void Corona::addView(const uint &containmentId, const QString &templateId)
{ {
auto view = m_layoutsManager->synchronizer()->viewForContainment((int)containmentId); auto view = m_layoutsManager->synchronizer()->viewForContainment((int)containmentId);
if (view && view->layout() && !templateId.isEmpty()) { if (view) {
view->layout()->newView(templateId); view->newView(templateId);
} }
} }

View File

@ -1550,21 +1550,14 @@ void GenericLayout::duplicateView(Plasma::Containment *containment)
emit viewEdgeChanged(); emit viewEdgeChanged();
} }
void GenericLayout::newView(const QString &templateFile) void GenericLayout::newView(const QString &templateFile, const Latte::Data::View &nextViewData)
{ {
//! Don't create LatteView when the containment is created because we must update its screen settings first if (nextViewData.state() == Data::View::IsInvalid) {
setBlockAutomaticLatteViewCreation(true); return;
Layouts::ViewDelayedCreationData result = Layouts::Storage::self()->newView(this, templateFile);
if (result.containment) {
addView(result.containment, result.forceOnPrimary, result.explicitScreen);
if (result.reactToScreenChange) {
result.containment->reactToScreenChange();
}
} }
setBlockAutomaticLatteViewCreation(false); Data::View result = Layouts::Storage::self()->newView(this, templateFile, nextViewData);
emit viewEdgeChanged(); emit viewEdgeChanged();
} }

View File

@ -125,8 +125,9 @@ public:
void recreateView(Plasma::Containment *containment, bool delayed = true); void recreateView(Plasma::Containment *containment, bool delayed = true);
bool latteViewExists(Plasma::Containment *containment); bool latteViewExists(Plasma::Containment *containment);
void updateView(const Latte::Data::View &viewData); void newView(const QString &templateFile, const Latte::Data::View &nextViewData);
void removeView(const Latte::Data::View &viewData); void removeView(const Latte::Data::View &viewData);
void updateView(const Latte::Data::View &viewData);
//! Available edges for specific view in that screen //! Available edges for specific view in that screen
virtual QList<Plasma::Types::Location> availableEdgesForView(QScreen *scr, Latte::View *forView) const; virtual QList<Plasma::Types::Location> availableEdgesForView(QScreen *scr, Latte::View *forView) const;
@ -147,7 +148,6 @@ public:
Latte::Data::ViewsTable viewsTable() const; Latte::Data::ViewsTable viewsTable() const;
public slots: public slots:
Q_INVOKABLE void newView(const QString &templateFile);
Q_INVOKABLE int viewsWithTasks() const; Q_INVOKABLE int viewsWithTasks() const;
virtual Q_INVOKABLE QList<int> qmlFreeEdges(int screen) const; //change <Plasma::Types::Location> to <int> types virtual Q_INVOKABLE QList<int> qmlFreeEdges(int screen) const; //change <Plasma::Types::Location> to <int> types

View File

@ -573,27 +573,50 @@ QList<Plasma::Containment *> Storage::importLayoutFile(const Layout::GenericLayo
qDebug() << " imported containments ::: " << newContainments.length(); qDebug() << " imported containments ::: " << newContainments.length();
QList<Plasma::Containment *> importedDocks; QList<Plasma::Containment *> importedViews;
for (const auto containment : newContainments) { for (const auto containment : newContainments) {
if (isLatteContainment(containment)) { if (isLatteContainment(containment)) {
qDebug() << "new latte containment id: " << containment->id(); qDebug() << "new latte containment id: " << containment->id();
importedDocks << containment; importedViews << containment;
} }
} }
return importedDocks; return importedViews;
} }
ViewDelayedCreationData Storage::newView(const Layout::GenericLayout *destination, const QString &templateFile) void Storage::importContainments(const QString &originFile, const QString &destinationFile)
{ {
if (!destination || !destination->corona()) { if (originFile.isEmpty() || destinationFile.isEmpty()) {
return ViewDelayedCreationData(); return;
}
KSharedConfigPtr originPtr = KSharedConfig::openConfig(originFile);
KSharedConfigPtr destinationPtr = KSharedConfig::openConfig(destinationFile);
KConfigGroup originContainments = KConfigGroup(originPtr, "Containments");
KConfigGroup destinationContainments = KConfigGroup(destinationPtr, "Containments");
for (const auto originContId : originContainments.groupList()) {
KConfigGroup destinationContainment(&destinationContainments, originContId);
originContainments.group(originContId).copyTo(&destinationContainment);
}
destinationContainments.sync();
}
Data::View Storage::newView(const Layout::GenericLayout *destinationLayout, const QString &templateFile, const Data::View &nextViewData)
{
if (!destinationLayout) {
return Data::View();
} }
qDebug() << "new view for layout"; qDebug() << "new view for layout";
//! Setting mutable for create a containment
destination->corona()->setImmutability(Plasma::Types::Mutable); if (destinationLayout->isActive()) {
//! Setting mutable for create a containment
destinationLayout->corona()->setImmutability(Plasma::Types::Mutable);
}
//! copy view template path in temp file //! copy view template path in temp file
QString templateTmpAbsolutePath = m_storageTmpDir.path() + "/" + QFileInfo(templateFile).fileName() + ".newids"; QString templateTmpAbsolutePath = m_storageTmpDir.path() + "/" + QFileInfo(templateFile).fileName() + ".newids";
@ -605,18 +628,46 @@ ViewDelayedCreationData Storage::newView(const Layout::GenericLayout *destinatio
QFile(templateFile).copy(templateTmpAbsolutePath); QFile(templateFile).copy(templateTmpAbsolutePath);
//! update ids to unique ones //! update ids to unique ones
QString temp2File = newUniqueIdsFile(templateTmpAbsolutePath, destination); QString temp2File = newUniqueIdsFile(templateTmpAbsolutePath, destinationLayout);
//! Finally import the configuration //! update view containment data in case next data are provided
QList<Plasma::Containment *> importedViews = importLayoutFile(destination, temp2File); if (nextViewData.state() != Data::View::IsInvalid) {
Plasma::Containment *newContainment = (importedViews.size() == 1 ? importedViews[0] : nullptr); KSharedConfigPtr lFile = KSharedConfig::openConfig(temp2File);
KConfigGroup containments = KConfigGroup(lFile, "Containments");
if (!newContainment || !newContainment->kPackage().isValid()) { for (const auto cId : containments.groupList()) {
qWarning() << "the requested containment plugin can not be located or loaded from:" << templateFile; if (Layouts::Storage::self()->isLatteContainment(containments.group(cId))) {
return ViewDelayedCreationData(); //! first view we will find, we update its value
updateView(containments.group(cId), nextViewData);
break;
}
}
} }
Data::ViewsTable updatedNextViews = views(temp2File);
if (updatedNextViews.rowCount() <= 0) {
return Data::View();
}
if (destinationLayout->isActive()) {
//! import views for active layout
QList<Plasma::Containment *> importedViews = importLayoutFile(destinationLayout, temp2File);
Plasma::Containment *newContainment = (importedViews.size() == 1 ? importedViews[0] : nullptr);
if (!newContainment || !newContainment->kPackage().isValid()) {
qWarning() << "the requested containment plugin can not be located or loaded from:" << templateFile;
return Data::View();
}
} else {
//! import views for inactive layout
importContainments(temp2File, destinationLayout->file());
}
return updatedNextViews[0];
/*
auto config = newContainment->config(); auto config = newContainment->config();
int primaryScrId = destination->corona()->screenPool()->primaryScreenId(); int primaryScrId = destination->corona()->screenPool()->primaryScreenId();
@ -644,7 +695,7 @@ ViewDelayedCreationData Storage::newView(const Layout::GenericLayout *destinatio
result.explicitScreen = primaryScrId; result.explicitScreen = primaryScrId;
result.reactToScreenChange = false; result.reactToScreenChange = false;
return result; return result;*/
} }
void Storage::clearExportedLayoutSettings(KConfigGroup &layoutSettingsGroup) void Storage::clearExportedLayoutSettings(KConfigGroup &layoutSettingsGroup)

View File

@ -86,7 +86,7 @@ public:
void importToCorona(const Layout::GenericLayout *layout); void importToCorona(const Layout::GenericLayout *layout);
void syncToLayoutFile(const Layout::GenericLayout *layout, bool removeLayoutId); void syncToLayoutFile(const Layout::GenericLayout *layout, bool removeLayoutId);
ViewDelayedCreationData copyView(const Layout::GenericLayout *layout, Plasma::Containment *containment); ViewDelayedCreationData copyView(const Layout::GenericLayout *layout, Plasma::Containment *containment);
ViewDelayedCreationData newView(const Layout::GenericLayout *destination, const QString &templateFile); Data::View newView(const Layout::GenericLayout *destination, const QString &templateFile, const Data::View &nextViewData);
void updateView(const Layout::GenericLayout *layout, const Data::View &viewData); void updateView(const Layout::GenericLayout *layout, const Data::View &viewData);
void updateView(KConfigGroup viewGroup, const Data::View &viewData); void updateView(KConfigGroup viewGroup, const Data::View &viewData);
@ -120,6 +120,7 @@ private:
Storage(); Storage();
void clearExportedLayoutSettings(KConfigGroup &layoutSettingsGroup); void clearExportedLayoutSettings(KConfigGroup &layoutSettingsGroup);
void importContainments(const QString &originFile, const QString &destinationFile);
bool isSubContainment(const KConfigGroup &appletGroup) const; bool isSubContainment(const KConfigGroup &appletGroup) const;
int subIdentityIndex(const KConfigGroup &appletGroup) const; int subIdentityIndex(const KConfigGroup &appletGroup) const;

View File

@ -32,10 +32,12 @@
#include "../apptypes.h" #include "../apptypes.h"
#include "../lattecorona.h" #include "../lattecorona.h"
#include "../data/layoutdata.h" #include "../data/layoutdata.h"
#include "../data/viewstable.h"
#include "../declarativeimports/interfaces.h" #include "../declarativeimports/interfaces.h"
#include "../indicator/factory.h" #include "../indicator/factory.h"
#include "../layout/genericlayout.h" #include "../layout/genericlayout.h"
#include "../layouts/manager.h" #include "../layouts/manager.h"
#include "../layouts/storage.h"
#include "../plasma/extended/theme.h" #include "../plasma/extended/theme.h"
#include "../screenpool.h" #include "../screenpool.h"
#include "../settings/universalsettings.h" #include "../settings/universalsettings.h"
@ -322,7 +324,7 @@ void View::init(Plasma::Containment *plasma_containment)
connect(m_effects, &ViewPart::Effects::innerShadowChanged, this, [&]() { connect(m_effects, &ViewPart::Effects::innerShadowChanged, this, [&]() {
emit availableScreenRectChangedFrom(this); emit availableScreenRectChangedFrom(this);
}); });
connect(m_positioner, &ViewPart::Positioner::onHideWindowsForSlidingOut, this, &View::hideWindowsForSlidingOut); connect(m_positioner, &ViewPart::Positioner::onHideWindowsForSlidingOut, this, &View::hideWindowsForSlidingOut);
connect(m_positioner, &ViewPart::Positioner::screenGeometryChanged, this, &View::screenGeometryChanged); connect(m_positioner, &ViewPart::Positioner::screenGeometryChanged, this, &View::screenGeometryChanged);
connect(m_positioner, &ViewPart::Positioner::windowSizeChanged, this, [&]() { connect(m_positioner, &ViewPart::Positioner::windowSizeChanged, this, [&]() {
@ -472,6 +474,32 @@ void View::exportTemplate()
exportDlg->show(); exportDlg->show();
} }
void View::newView(const QString &templateFile)
{
if (templateFile.isEmpty() || !m_layout) {
return;
}
Data::ViewsTable templateviews = Layouts::Storage::self()->views(templateFile);
if (templateviews.rowCount() <= 0) {
return;
}
Data::View nextdata = templateviews[0];
int scrId = onPrimary() ? m_corona->screenPool()->primaryScreenId() : m_positioner->currentScreenId();
QList<Plasma::Types::Location> freeedges = m_layout->freeEdges(scrId);
if (!freeedges.contains(nextdata.edge)) {
nextdata.edge = (freeedges.count() > 0 ? freeedges[0] : Plasma::Types::BottomEdge);
}
nextdata.setState(Data::View::OriginFromViewTemplate, templateFile);
m_layout->newView(templateFile, nextdata);
}
void View::removeView() void View::removeView()
{ {
if (m_layout) { if (m_layout) {

View File

@ -276,9 +276,11 @@ public:
void releaseConfigView(); void releaseConfigView();
public slots: public slots:
Q_INVOKABLE void newView(const QString &templateFile);
Q_INVOKABLE void removeView();
Q_INVOKABLE void duplicateView(); Q_INVOKABLE void duplicateView();
Q_INVOKABLE void exportTemplate(); Q_INVOKABLE void exportTemplate();
Q_INVOKABLE void removeView();
Q_INVOKABLE void moveToLayout(QString layoutName); Q_INVOKABLE void moveToLayout(QString layoutName);

View File

@ -541,7 +541,7 @@ Loader {
var item = actionsModel.get(index); var item = actionsModel.get(index);
if (item && item.actionId === "add:") { if (item && item.actionId === "add:") {
latteView.layout.newView(item.templateId); latteView.newView(item.templateId);
} else if (item && item.actionId === "duplicate:") { } else if (item && item.actionId === "duplicate:") {
latteView.duplicateView(); latteView.duplicateView();
} }