From 7c238589bac0a2908aafd0e7e1e9c5ec60ed77c0 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Fri, 14 Aug 2020 09:33:39 +0300 Subject: [PATCH] improve name style and layouts path references --use Importer in order to reference layouts directory in user space and improve also naming for relevant Importer functions --- app/layout/genericlayout.cpp | 4 +-- app/layout/storage.cpp | 2 +- app/layouts/importer.cpp | 28 ++++++++++--------- app/layouts/importer.h | 7 +++-- app/layouts/manager.cpp | 8 +++--- app/layouts/synchronizer.cpp | 12 ++++---- .../controllers/layoutscontroller.cpp | 4 +-- app/templates/templatesmanager.cpp | 2 +- 8 files changed, 36 insertions(+), 31 deletions(-) diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index d1897df3f..8c48ab29a 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -764,8 +764,8 @@ void GenericLayout::renameLayout(QString newName) return; } - if (m_layoutFile != Layouts::Importer::layoutFilePath(newName)) { - setFile(Layouts::Importer::layoutFilePath(newName)); + if (m_layoutFile != Layouts::Importer::layoutUserFilePath(newName)) { + setFile(Layouts::Importer::layoutUserFilePath(newName)); } setName(newName); diff --git a/app/layout/storage.cpp b/app/layout/storage.cpp index 4b800ff92..855665c2a 100644 --- a/app/layout/storage.cpp +++ b/app/layout/storage.cpp @@ -716,7 +716,7 @@ bool Storage::layoutIsBroken(QStringList &errors) const qDebug() << " --- storaged file : " << m_layout->file(); } else { if (m_layout->corona()->layoutsManager()->memoryUsage() == MemoryUsage::MultipleLayouts) { - qDebug() << " --- in multiple layouts hidden file : " << Layouts::Importer::layoutFilePath(MULTIPLELAYOUTSHIDDENNAME); + qDebug() << " --- in multiple layouts hidden file : " << Layouts::Importer::layoutUserFilePath(MULTIPLELAYOUTSHIDDENNAME); } else { qDebug() << " --- in active layout file : " << m_layout->file(); } diff --git a/app/layouts/importer.cpp b/app/layouts/importer.cpp index 66e32d7e3..c879e30f9 100644 --- a/app/layouts/importer.cpp +++ b/app/layouts/importer.cpp @@ -265,7 +265,7 @@ QString Importer::layoutCanBeImported(QString oldAppletsPath, QString newName, Q return QString(); } - QDir layoutDir(exportDirectory.isNull() ? QDir::homePath() + "/.config/latte" : exportDirectory); + QDir layoutDir(exportDirectory.isNull() ? layoutUserDir() : exportDirectory); if (!layoutDir.exists() && exportDirectory.isNull()) { QDir(QDir::homePath() + "/.config").mkdir("latte"); @@ -400,11 +400,9 @@ bool Importer::exportFullConfiguration(QString file) archive.addLocalFile(QString(QDir::homePath() + "/.config/lattedockrc"), QStringLiteral("lattedockrc")); for(const auto &layoutName : availableLayouts()) { - archive.addLocalFile(layoutFilePath(layoutName), QString("latte/" + layoutName + ".layout.latte")); + archive.addLocalFile(layoutUserFilePath(layoutName), QString("latte/" + layoutName + ".layout.latte")); } - //archive.addLocalDirectory(QString(QDir::homePath() + "/.config/latte"), QStringLiteral("latte")); - archive.close(); return true; @@ -511,8 +509,7 @@ bool Importer::importHelper(QString fileName) return false; } - QString latteDirPath(QDir::homePath() + "/.config/latte"); - QDir latteDir(latteDirPath); + QDir latteDir(layoutUserDir()); if (latteDir.exists()) { latteDir.removeRecursively(); @@ -534,7 +531,7 @@ QString Importer::importLayoutHelper(QString fileName) QString newLayoutName = Layout::AbstractLayout::layoutName(fileName); newLayoutName = uniqueLayoutName(newLayoutName); - QString newPath = QDir::homePath() + "/.config/latte/" + newLayoutName + ".layout.latte"; + QString newPath = layoutUserFilePath(newLayoutName); QFile(fileName).copy(newPath); QFileInfo newFileInfo(newPath); @@ -549,7 +546,7 @@ QString Importer::importLayoutHelper(QString fileName) QStringList Importer::availableLayouts() { - QDir layoutDir(QDir::homePath() + "/.config/latte"); + QDir layoutDir(layoutUserDir()); QStringList filter; filter.append(QString("*.layout.latte")); QStringList files = layoutDir.entryList(filter, QDir::Files | QDir::NoSymLinks); @@ -578,13 +575,18 @@ QString Importer::nameOfConfigFile(const QString &fileName) bool Importer::layoutExists(QString layoutName) { - return QFile::exists(layoutFilePath(layoutName)); + return QFile::exists(layoutUserFilePath(layoutName)); } -QString Importer::layoutFilePath(QString layoutName) +QString Importer::layoutUserDir() { - return QString(QDir::homePath() + "/.config/latte/" + layoutName + ".layout.latte"); + return QString(QDir::homePath() + "/.config/latte"); +} + +QString Importer::layoutUserFilePath(QString layoutName) +{ + return QString(layoutUserDir() + "/" + layoutName + ".layout.latte"); } QString Importer::uniqueLayoutName(QString name) @@ -609,7 +611,7 @@ QString Importer::uniqueLayoutName(QString name) QStringList Importer::checkRepairMultipleLayoutsLinkedFile() { - QString linkedFilePath = QDir::homePath() + "/.config/latte/" + Layout::MULTIPLELAYOUTSHIDDENNAME + ".layout.latte"; + QString linkedFilePath = layoutUserFilePath(Layout::MULTIPLELAYOUTSHIDDENNAME); KSharedConfigPtr filePtr = KSharedConfig::openConfig(linkedFilePath); KConfigGroup linkedContainments = KConfigGroup(filePtr, "Containments"); @@ -631,7 +633,7 @@ QStringList Importer::checkRepairMultipleLayoutsLinkedFile() for(const auto &layoutName : linkedLayoutContainmentGroups.uniqueKeys()) { if (layoutName != Layout::MULTIPLELAYOUTSHIDDENNAME && layoutExists(layoutName)) { updatedLayouts << layoutName; - KSharedConfigPtr layoutFilePtr = KSharedConfig::openConfig(layoutFilePath(layoutName)); + KSharedConfigPtr layoutFilePtr = KSharedConfig::openConfig(layoutUserFilePath(layoutName)); KConfigGroup origLayoutContainments = KConfigGroup(layoutFilePtr, "Containments"); //Clear old containments diff --git a/app/layouts/importer.h b/app/layouts/importer.h index 2732af1a8..f7b079ccf 100644 --- a/app/layouts/importer.h +++ b/app/layouts/importer.h @@ -91,8 +91,11 @@ public: //! if the function didn't succeed return an empty string static QString importLayoutHelper(QString fileName); - //! return the file path of a layout either existing or not - static QString layoutFilePath(QString layoutName); + //! returns the file path of a layout either existing or not + static QString layoutUserFilePath(QString layoutName); + //! returns the layouts user directory + static QString layoutUserDir(); + static QString nameOfConfigFile(const QString &fileName); static QString uniqueLayoutName(QString name); diff --git a/app/layouts/manager.cpp b/app/layouts/manager.cpp index 1224fbcf0..3d7cb1fb6 100644 --- a/app/layouts/manager.cpp +++ b/app/layouts/manager.cpp @@ -81,7 +81,7 @@ Manager::~Manager() void Manager::load() { - QDir layoutsDir(QDir::homePath() + "/.config/latte"); + QDir layoutsDir(Layouts::Importer::layoutUserDir()); bool firstRun = !layoutsDir.exists(); int configVer = m_corona->universalSettings()->version(); @@ -111,7 +111,7 @@ void Manager::load() } //! Check if the multiple-layouts hidden file is present, add it if it isnt - if (!QFile(QDir::homePath() + "/.config/latte/" + Layout::MULTIPLELAYOUTSHIDDENNAME + ".layout.latte").exists()) { + if (!QFile(Layouts::Importer::layoutUserFilePath(Layout::MULTIPLELAYOUTSHIDDENNAME)).exists()) { importPreset(MultipleLayoutsPresetId, false); } @@ -326,9 +326,9 @@ void Manager::importPreset(int presetNo, bool newInstanceIfPresent) QString newLayoutFile = ""; if (newInstanceIfPresent) { - newLayoutFile = QDir::homePath() + "/.config/latte/" + m_importer->uniqueLayoutName(presetName) + ".layout.latte"; + newLayoutFile = Layouts::Importer::layoutUserFilePath(m_importer->uniqueLayoutName(presetName)); } else { - newLayoutFile = QDir::homePath() + "/.config/latte/" + presetName + ".layout.latte"; + newLayoutFile = Layouts::Importer::layoutUserFilePath(presetName); } if (!QFile(newLayoutFile).exists()) { diff --git a/app/layouts/synchronizer.cpp b/app/layouts/synchronizer.cpp index 67390ee6d..59a056de8 100644 --- a/app/layouts/synchronizer.cpp +++ b/app/layouts/synchronizer.cpp @@ -133,7 +133,7 @@ bool Synchronizer::registerAtSharedLayout(CentralLayout *central, QString id) } //! If SharedLayout was not found, we must create it - SharedLayout *top = new SharedLayout(central, this, Importer::layoutFilePath(id)); + SharedLayout *top = new SharedLayout(central, this, Importer::layoutUserFilePath(id)); m_sharedLayouts.append(top); top->importToCorona(); @@ -184,7 +184,7 @@ void Synchronizer::setCurrentLayoutNameInMultiEnvironment(const QString &name) QString Synchronizer::layoutPath(QString layoutName) { - QString path = QDir::homePath() + "/.config/latte/" + layoutName + ".layout.latte"; + QString path = Layouts::Importer::layoutUserFilePath(layoutName); if (!QFile(path).exists()) { path = ""; @@ -558,7 +558,7 @@ void Synchronizer::loadLayouts() m_assignedLayouts.clear(); m_sharedLayoutIds.clear(); - QDir layoutDir(QDir::homePath() + "/.config/latte"); + QDir layoutDir(Layouts::Importer::layoutUserDir()); QStringList filter; filter.append(QString("*.layout.latte")); QStringList files = layoutDir.entryList(filter, QDir::Files | QDir::NoSymLinks); @@ -760,7 +760,7 @@ bool Synchronizer::switchToLayout(QString layoutName, int previousMemoryUsage) //! a Layout that is assigned to specific activities but this //! layout isnt loaded (this means neither of its activities are running) //! is such case we just activate these Activities - CentralLayout layout(this, Importer::layoutFilePath(layoutName)); + CentralLayout layout(this, Importer::layoutUserFilePath(layoutName)); int i = 0; bool lastUsedActivityFound{false}; @@ -951,7 +951,7 @@ void Synchronizer::syncActiveShares(SharesMap &sharesMap, QStringList &deprecate CentralLayout *central = centralLayout(share); if (!central) { //! Central Layout is not loaded - CentralLayout centralInStorage(this, Importer::layoutFilePath(share)); + CentralLayout centralInStorage(this, Importer::layoutUserFilePath(share)); centralInStorage.setSharedLayoutName(QString()); } } @@ -992,7 +992,7 @@ void Synchronizer::syncActiveShares(SharesMap &sharesMap, QStringList &deprecate } } else { //! Central Layout is not loaded - CentralLayout centralInStorage(this, Importer::layoutFilePath(centralName)); + CentralLayout centralInStorage(this, Importer::layoutUserFilePath(centralName)); centralInStorage.setSharedLayoutName(i.key()); } } diff --git a/app/settings/controllers/layoutscontroller.cpp b/app/settings/controllers/layoutscontroller.cpp index 4bf6a939a..7026b7cb2 100644 --- a/app/settings/controllers/layoutscontroller.cpp +++ b/app/settings/controllers/layoutscontroller.cpp @@ -402,7 +402,7 @@ void Layouts::loadLayouts() for (const auto layout : m_handler->corona()->layoutsManager()->layouts()) { Latte::Data::Layout original; - original.id = QDir::homePath() + "/.config/latte/" + layout + ".layout.latte"; + original.id = Latte::Layouts::Importer::layoutUserFilePath(layout); CentralLayout *central = new CentralLayout(this, original.id); @@ -804,7 +804,7 @@ void Layouts::save() for (int i = 0; i < alteredIdsInfo.count(); ++i) { Data::UniqueIdInfo idInfo = alteredIdsInfo[i]; - QString newFile = QDir::homePath() + "/.config/latte/" + idInfo.newName + ".layout.latte"; + QString newFile = Latte::Layouts::Importer::layoutUserFilePath(idInfo.newName); QFile(idInfo.newId).rename(newFile); CentralLayout *nLayout = new CentralLayout(this, newFile); diff --git a/app/templates/templatesmanager.cpp b/app/templates/templatesmanager.cpp index e3dfcba60..b1871f465 100644 --- a/app/templates/templatesmanager.cpp +++ b/app/templates/templatesmanager.cpp @@ -110,7 +110,7 @@ QString Manager::newLayout(QString layoutName, QString layoutTemplate) layoutName = Layouts::Importer::uniqueLayoutName(layoutName); } - QString newLayoutPath = QDir::homePath() + "/.config/latte/" + layoutName + ".layout.latte"; + QString newLayoutPath = Layouts::Importer::layoutUserFilePath(layoutName); Data::Layout dlayout = layoutTemplateForName(layoutTemplate); QFile(dlayout.id).copy(newLayoutPath);