/* * Copyright 2020 Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * Latte-Dock is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "templatesmanager.h" // local #include "../layout/abstractlayout.h" #include "../layout/centrallayout.h" #include "../layouts/importer.h" #include "../tools/commontools.h" // Qt #include // KDE #include namespace Latte { namespace Templates { Manager::Manager(Latte::Corona *corona) : QObject(corona), m_corona(corona) { } Manager::~Manager() { } void Manager::init() { //! Local Templates QDir localTemplatesDir(Latte::configPath() + "/latte/templates"); if (!localTemplatesDir.exists()) { QDir(Latte::configPath() + "/latte").mkdir("templates"); } initLayoutTemplates(m_corona->kPackage().filePath("templates")); initLayoutTemplates(Latte::configPath() + "/latte/templates"); initViewTemplates(m_corona->kPackage().filePath("templates")); initViewTemplates(Latte::configPath() + "/latte/templates"); } void Manager::initLayoutTemplates(const QString &path) { QDir templatesDir(path); QStringList filter; filter.append(QString("*.layout.latte")); QStringList templates = templatesDir.entryList(filter, QDir::Files | QDir::Hidden | QDir::NoSymLinks); for (int i=0; i Manager::viewTemplates() { return m_viewTemplates; } QString Manager::newLayout(QString layoutName, QString layoutTemplate) { if (!m_layoutTemplates.containsName(layoutTemplate)) { return QString(); } if (layoutName.isEmpty()) { layoutName = Layouts::Importer::uniqueLayoutName(layoutTemplate); } else { layoutName = Layouts::Importer::uniqueLayoutName(layoutName); } QString newLayoutPath = Layouts::Importer::layoutUserFilePath(layoutName); Data::Layout dlayout = layoutTemplateForName(layoutTemplate); QFile(dlayout.id).copy(newLayoutPath); qDebug() << "adding layout : " << layoutName << " based on layout template:" << layoutTemplate; emit newLayoutAdded(newLayoutPath); return newLayoutPath; } void Manager::importSystemLayouts() { for (int i=0; i 0) { name = name.left(pos_); } int i = 2; QString namePart = name; while (layoutTemplateExists(name)) { name = namePart + " - " + QString::number(i); i++; } return name; } QString Manager::uniqueViewTemplateName(QString name) const { int pos_ = name.lastIndexOf(QRegExp(QString(" - [0-9]+"))); if (viewTemplateExists(name) && pos_ > 0) { name = name.left(pos_); } int i = 2; QString namePart = name; while (viewTemplateExists(name)) { name = namePart + " - " + QString::number(i); i++; } return name; } //! it is used in order to provide translations for system templates void Manager::exposeTranslatedTemplateNames() { i18nc("default layout template name", "Default"); i18nc("empty layout template name", "Empty"); } } }