File indexing completed on 2024-12-01 11:10:35
0001 /* 0002 SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "templateskeeper.h" 0007 0008 // local 0009 #include "layoutscontroller.h" 0010 #include "../../lattecorona.h" 0011 #include "../../layout/centrallayout.h" 0012 #include "../../layouts/manager.h" 0013 #include "../../layouts/synchronizer.h" 0014 0015 namespace Latte { 0016 namespace Settings { 0017 namespace Part { 0018 0019 TemplatesKeeper::TemplatesKeeper(Settings::Controller::Layouts *parent, Latte::Corona *corona) 0020 : QObject(parent), 0021 m_corona(corona), 0022 m_layoutsController(parent) 0023 { 0024 } 0025 0026 TemplatesKeeper::~TemplatesKeeper() 0027 { 0028 clear(); 0029 } 0030 0031 bool TemplatesKeeper::hasClipboardContents() const 0032 { 0033 return (m_clipboardViews.rowCount() > 0); 0034 } 0035 0036 Latte::Data::ViewsTable TemplatesKeeper::clipboardContents() const 0037 { 0038 return m_clipboardViews; 0039 } 0040 0041 void TemplatesKeeper::setClipboardContents(const Latte::Data::ViewsTable &views) 0042 { 0043 if (m_clipboardViews == views) { 0044 return; 0045 } 0046 0047 m_clipboardViews.clear(); 0048 m_clipboardViews = views; 0049 0050 emit clipboardContentsChanged(); 0051 } 0052 0053 void TemplatesKeeper::clear() 0054 { 0055 qDeleteAll(m_garbageLayouts); 0056 0057 m_garbageLayouts.clear(); 0058 m_storedViews.clear(); 0059 m_clipboardViews.clear(); 0060 } 0061 0062 QString TemplatesKeeper::viewKeeperId(const QString &layoutCurrentId, const QString &viewId) 0063 { 0064 return QString(layoutCurrentId + "#" + viewId); 0065 0066 } 0067 0068 QString TemplatesKeeper::storedView(const QString &layoutCurrentId, const QString &viewId) 0069 { 0070 QString keeperid = viewKeeperId(layoutCurrentId, viewId); 0071 0072 if (m_storedViews.containsId(keeperid)) { 0073 return m_storedViews[keeperid].originFile(); 0074 } 0075 0076 Latte::Data::Layout originallayout = m_layoutsController->originalData(layoutCurrentId); 0077 Latte::Data::Layout currentlayout = m_layoutsController->currentData(layoutCurrentId); 0078 Latte::CentralLayout *centralActive = m_layoutsController->isLayoutOriginal(layoutCurrentId) ? m_corona->layoutsManager()->synchronizer()->centralLayout(originallayout.name) : nullptr; 0079 Latte::CentralLayout *central = centralActive ? centralActive : new Latte::CentralLayout(this, layoutCurrentId); 0080 0081 if (!centralActive) { 0082 m_garbageLayouts << central; 0083 } 0084 0085 if (!central->containsView(viewId.toInt())) { 0086 return QString(); 0087 } 0088 0089 QString storedviewpath = central->storedView(viewId.toInt()); 0090 0091 Latte::Data::View storedview; 0092 storedview.id = keeperid; 0093 storedview.isActive = false; 0094 storedview.setState(Data::View::OriginFromViewTemplate, storedviewpath, layoutCurrentId, viewId); 0095 m_storedViews << storedview; 0096 0097 return storedviewpath; 0098 } 0099 0100 0101 } 0102 } 0103 }