mirror of
https://github.com/KDE/latte-dock.git
synced 2024-12-23 01:33:50 +03:00
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
This commit is contained in:
parent
5ed3f111e3
commit
7c238589ba
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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()) {
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user