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

move newLayout from layoutsmanager to templates

This commit is contained in:
Michail Vourlakos 2020-08-13 20:42:38 +03:00
parent 0393e0ff35
commit 15dc6f5eac
5 changed files with 25 additions and 34 deletions

View File

@ -32,6 +32,7 @@
#include "../layout/centrallayout.h"
#include "../settings/dialogs/settingsdialog.h"
#include "../settings/universalsettings.h"
#include "../templates/templatesmanager.h"
// Qt
#include <QDir>
@ -95,7 +96,7 @@ void Manager::load()
QDir(QDir::homePath() + "/.config").mkdir("latte");
}
newLayout(i18n("My Layout"));
m_corona->templatesManager()->newLayout(i18n("My Layout"), i18n(Templates::DEFAULTLAYOUTTEMPLATENAME));
importPresets(false);
} else if (configVer < 2 && !firstRun) {
m_corona->universalSettings()->setVersion(2);
@ -293,33 +294,6 @@ void Manager::clearUnloadedContainmentsFromLinkedFile(QStringList containmentsId
}
}
QString Manager::newLayout(QString layoutName, QString layoutTemplate)
{
QDir layoutDir(QDir::homePath() + "/.config/latte");
QStringList filter;
filter.append(QString(layoutName + "*.layout.latte"));
QStringList files = layoutDir.entryList(filter, QDir::Files | QDir::NoSymLinks);
//! if the newLayout already exists provide a newName that doesn't
if (files.count() >= 1) {
int newCounter = files.count() + 1;
layoutName = layoutName + "-" + QString::number(newCounter);
}
QString newLayoutPath = layoutDir.absolutePath() + "/" + layoutName + ".layout.latte";
qDebug() << "adding layout : " << layoutName << " based on layout template:" << layoutTemplate;
if (layoutTemplate == i18n(Templates::DEFAULTLAYOUTTEMPLATENAME) && !QFile(newLayoutPath).exists()) {
qDebug() << "adding layout : succeed";
Data::Layout dlayout = m_corona->templatesManager()->layoutTemplateForName(i18n(Templates::DEFAULTLAYOUTTEMPLATENAME));
QFile(dlayout.id).copy(newLayoutPath);
}
return newLayoutPath;
}
void Manager::importDefaultLayout(bool newInstanceIfPresent)
{
importPreset(1, newInstanceIfPresent);

View File

@ -25,7 +25,6 @@
#include "launcherssignals.h"
#include "synchronizer.h"
#include "../apptypes.h"
#include "../templates/templatesmanager.h"
#include "../settings/dialogs/settingsdialog.h"
// Qt
@ -116,9 +115,6 @@ public slots:
//! switch to specified layout, default previousMemoryUsage means that it didn't change
Q_INVOKABLE bool switchToLayout(QString layoutName, int previousMemoryUsage = -1);
//! creates a new layout with layoutName based on specific layout template
Q_INVOKABLE QString newLayout(QString layoutName, QString layoutTemplate = i18n(Templates::DEFAULTLAYOUTTEMPLATENAME));
Q_INVOKABLE QStringList centralLayoutsNames();
Q_INVOKABLE QStringList sharedLayoutsNames();

View File

@ -28,6 +28,7 @@
#include "../layout/genericlayout.h"
#include "../layout/sharedlayout.h"
#include "../settings/universalsettings.h"
#include "../templates/templatesmanager.h"
#include "../view/view.h"
// Qt
@ -675,8 +676,8 @@ bool Synchronizer::switchToLayout(QString layoutName, int previousMemoryUsage)
QString lPath = layoutPath(layoutName);
if (lPath.isEmpty() && layoutName == i18n("Alternative")) {
lPath = m_manager->newLayout(i18n("Alternative"), i18n("Default"));
if (lPath.isEmpty() && layoutName == i18nc("alternative layout", "Alternative")) {
lPath = m_manager->corona()->templatesManager()->newLayout(i18nc("alternative layout", "Alternative"), i18n(Templates::DEFAULTLAYOUTTEMPLATENAME));
}
if (!lPath.isEmpty()) {

View File

@ -21,6 +21,7 @@
// local
#include "../layout/centrallayout.h"
#include "../layouts/importer.h"
// Qt
#include <QDir>
@ -96,6 +97,19 @@ Data::LayoutsTable Manager::systemLayoutTemplates()
return templates;
}
QString Manager::newLayout(QString layoutName, QString layoutTemplate)
{
layoutName = Layouts::Importer::uniqueLayoutName(layoutName);
QString newLayoutPath = QDir::homePath() + "/.config/latte/" + layoutName + ".layout.latte";
Data::Layout dlayout = layoutTemplateForName(layoutTemplate);
QFile(dlayout.id).copy(newLayoutPath);
qDebug() << "adding layout : " << layoutName << " based on layout template:" << layoutTemplate;
return newLayoutPath;
}
//! it is used just in order to provide translations for the presets
void Manager::exposeTranslatedTemplateNames()
{

View File

@ -28,6 +28,9 @@
// Qt
#include <QObject>
// KDE
#include <KLocalizedString>
namespace Latte {
class Corona;
}
@ -54,6 +57,9 @@ public:
Data::LayoutsTable systemLayoutTemplates();
//! creates a new layout with layoutName based on specific layout template and returns the new layout absolute path
QString newLayout(QString layoutName, QString layoutTemplate = i18n(DEFAULTLAYOUTTEMPLATENAME));
private:
void exposeTranslatedTemplateNames();