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:
parent
dc56e61e64
commit
1fac17d6ba
@ -1164,8 +1164,8 @@ QStringList Corona::viewTemplatesData()
|
||||
void Corona::addView(const uint &containmentId, const QString &templateId)
|
||||
{
|
||||
auto view = m_layoutsManager->synchronizer()->viewForContainment((int)containmentId);
|
||||
if (view && view->layout() && !templateId.isEmpty()) {
|
||||
view->layout()->newView(templateId);
|
||||
if (view) {
|
||||
view->newView(templateId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1550,21 +1550,14 @@ void GenericLayout::duplicateView(Plasma::Containment *containment)
|
||||
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
|
||||
setBlockAutomaticLatteViewCreation(true);
|
||||
|
||||
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();
|
||||
}
|
||||
if (nextViewData.state() == Data::View::IsInvalid) {
|
||||
return;
|
||||
}
|
||||
|
||||
setBlockAutomaticLatteViewCreation(false);
|
||||
Data::View result = Layouts::Storage::self()->newView(this, templateFile, nextViewData);
|
||||
|
||||
emit viewEdgeChanged();
|
||||
}
|
||||
|
||||
|
@ -125,8 +125,9 @@ public:
|
||||
void recreateView(Plasma::Containment *containment, bool delayed = true);
|
||||
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 updateView(const Latte::Data::View &viewData);
|
||||
|
||||
//! Available edges for specific view in that screen
|
||||
virtual QList<Plasma::Types::Location> availableEdgesForView(QScreen *scr, Latte::View *forView) const;
|
||||
@ -147,7 +148,6 @@ public:
|
||||
Latte::Data::ViewsTable viewsTable() const;
|
||||
|
||||
public slots:
|
||||
Q_INVOKABLE void newView(const QString &templateFile);
|
||||
Q_INVOKABLE int viewsWithTasks() const;
|
||||
virtual Q_INVOKABLE QList<int> qmlFreeEdges(int screen) const; //change <Plasma::Types::Location> to <int> types
|
||||
|
||||
|
@ -573,27 +573,50 @@ QList<Plasma::Containment *> Storage::importLayoutFile(const Layout::GenericLayo
|
||||
|
||||
qDebug() << " imported containments ::: " << newContainments.length();
|
||||
|
||||
QList<Plasma::Containment *> importedDocks;
|
||||
QList<Plasma::Containment *> importedViews;
|
||||
|
||||
for (const auto containment : newContainments) {
|
||||
if (isLatteContainment(containment)) {
|
||||
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()) {
|
||||
return ViewDelayedCreationData();
|
||||
if (originFile.isEmpty() || destinationFile.isEmpty()) {
|
||||
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";
|
||||
//! 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
|
||||
QString templateTmpAbsolutePath = m_storageTmpDir.path() + "/" + QFileInfo(templateFile).fileName() + ".newids";
|
||||
@ -605,18 +628,46 @@ ViewDelayedCreationData Storage::newView(const Layout::GenericLayout *destinatio
|
||||
QFile(templateFile).copy(templateTmpAbsolutePath);
|
||||
|
||||
//! update ids to unique ones
|
||||
QString temp2File = newUniqueIdsFile(templateTmpAbsolutePath, destination);
|
||||
QString temp2File = newUniqueIdsFile(templateTmpAbsolutePath, destinationLayout);
|
||||
|
||||
//! Finally import the configuration
|
||||
QList<Plasma::Containment *> importedViews = importLayoutFile(destination, temp2File);
|
||||
//! update view containment data in case next data are provided
|
||||
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()) {
|
||||
qWarning() << "the requested containment plugin can not be located or loaded from:" << templateFile;
|
||||
return ViewDelayedCreationData();
|
||||
for (const auto cId : containments.groupList()) {
|
||||
if (Layouts::Storage::self()->isLatteContainment(containments.group(cId))) {
|
||||
//! 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();
|
||||
int primaryScrId = destination->corona()->screenPool()->primaryScreenId();
|
||||
|
||||
@ -644,7 +695,7 @@ ViewDelayedCreationData Storage::newView(const Layout::GenericLayout *destinatio
|
||||
result.explicitScreen = primaryScrId;
|
||||
result.reactToScreenChange = false;
|
||||
|
||||
return result;
|
||||
return result;*/
|
||||
}
|
||||
|
||||
void Storage::clearExportedLayoutSettings(KConfigGroup &layoutSettingsGroup)
|
||||
|
@ -86,7 +86,7 @@ public:
|
||||
void importToCorona(const Layout::GenericLayout *layout);
|
||||
void syncToLayoutFile(const Layout::GenericLayout *layout, bool removeLayoutId);
|
||||
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(KConfigGroup viewGroup, const Data::View &viewData);
|
||||
@ -120,6 +120,7 @@ private:
|
||||
Storage();
|
||||
|
||||
void clearExportedLayoutSettings(KConfigGroup &layoutSettingsGroup);
|
||||
void importContainments(const QString &originFile, const QString &destinationFile);
|
||||
|
||||
bool isSubContainment(const KConfigGroup &appletGroup) const;
|
||||
int subIdentityIndex(const KConfigGroup &appletGroup) const;
|
||||
|
@ -32,10 +32,12 @@
|
||||
#include "../apptypes.h"
|
||||
#include "../lattecorona.h"
|
||||
#include "../data/layoutdata.h"
|
||||
#include "../data/viewstable.h"
|
||||
#include "../declarativeimports/interfaces.h"
|
||||
#include "../indicator/factory.h"
|
||||
#include "../layout/genericlayout.h"
|
||||
#include "../layouts/manager.h"
|
||||
#include "../layouts/storage.h"
|
||||
#include "../plasma/extended/theme.h"
|
||||
#include "../screenpool.h"
|
||||
#include "../settings/universalsettings.h"
|
||||
@ -322,7 +324,7 @@ void View::init(Plasma::Containment *plasma_containment)
|
||||
|
||||
connect(m_effects, &ViewPart::Effects::innerShadowChanged, this, [&]() {
|
||||
emit availableScreenRectChangedFrom(this);
|
||||
});
|
||||
});
|
||||
connect(m_positioner, &ViewPart::Positioner::onHideWindowsForSlidingOut, this, &View::hideWindowsForSlidingOut);
|
||||
connect(m_positioner, &ViewPart::Positioner::screenGeometryChanged, this, &View::screenGeometryChanged);
|
||||
connect(m_positioner, &ViewPart::Positioner::windowSizeChanged, this, [&]() {
|
||||
@ -472,6 +474,32 @@ void View::exportTemplate()
|
||||
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()
|
||||
{
|
||||
if (m_layout) {
|
||||
|
@ -276,9 +276,11 @@ public:
|
||||
void releaseConfigView();
|
||||
|
||||
public slots:
|
||||
Q_INVOKABLE void newView(const QString &templateFile);
|
||||
Q_INVOKABLE void removeView();
|
||||
Q_INVOKABLE void duplicateView();
|
||||
Q_INVOKABLE void exportTemplate();
|
||||
Q_INVOKABLE void removeView();
|
||||
|
||||
|
||||
Q_INVOKABLE void moveToLayout(QString layoutName);
|
||||
|
||||
|
@ -541,7 +541,7 @@ Loader {
|
||||
var item = actionsModel.get(index);
|
||||
|
||||
if (item && item.actionId === "add:") {
|
||||
latteView.layout.newView(item.templateId);
|
||||
latteView.newView(item.templateId);
|
||||
} else if (item && item.actionId === "duplicate:") {
|
||||
latteView.duplicateView();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user