add --default-layout option for command line

--this option enables the user to load the default
layout from start.
pull/2/head
Michail Vourlakos 7 years ago
parent 3679c1c0cf
commit 0615dcf084

@ -57,8 +57,9 @@
namespace Latte {
DockCorona::DockCorona(QObject *parent)
DockCorona::DockCorona(bool defaultLayoutOnStartup, QObject *parent)
: Plasma::Corona(parent),
m_defaultLayoutOnStartup(defaultLayoutOnStartup),
m_activityConsumer(new KActivities::Consumer(this)),
m_screenPool(new ScreenPool(KSharedConfig::openConfig(), this)),
m_globalShortcuts(new GlobalShortcuts(this)),
@ -150,20 +151,20 @@ void DockCorona::load()
QString loadLayoutName = "";
if (!assignedLayout.isEmpty() && assignedLayout != m_universalSettings->currentLayoutName()) {
loadLayoutName = assignedLayout;
} else {
loadLayoutName = m_universalSettings->currentLayoutName();
}
if (!m_layoutManager->layoutExists(loadLayoutName)) {
QString defaultLayoutName = m_layoutManager->defaultLayoutName();
if (!m_layoutManager->layoutExists(defaultLayoutName)) {
m_layoutManager->importDefaultLayout();
if (!m_defaultLayoutOnStartup) {
if (!assignedLayout.isEmpty() && assignedLayout != m_universalSettings->currentLayoutName()) {
loadLayoutName = assignedLayout;
} else {
loadLayoutName = m_universalSettings->currentLayoutName();
}
loadLayoutName = defaultLayoutName;
if (!m_layoutManager->layoutExists(loadLayoutName)) {
loadLayoutName = m_layoutManager->defaultLayoutName();
m_layoutManager->importDefaultLayout(false);
}
} else {
loadLayoutName = m_layoutManager->importer()->uniqueLayoutName(m_layoutManager->defaultLayoutName());
m_layoutManager->importDefaultLayout(true);
}
m_layoutManager->switchToLayout(loadLayoutName);

@ -62,7 +62,7 @@ class DockCorona : public Plasma::Corona {
Q_CLASSINFO("D-Bus Interface", "org.kde.LatteDock")
public:
DockCorona(QObject *parent = nullptr);
DockCorona(bool defaultLayoutOnStartup = false, QObject *parent = nullptr);
virtual ~DockCorona();
int numScreens() const override;
@ -136,6 +136,8 @@ private:
QStringList appletsIds();
bool m_activitiesStarting{true};
//! this is used to enforce loading the default layout on startup
bool m_defaultLayoutOnStartup{false};
//! this is used to check if a dock with tasks in it will be loaded on startup
bool m_tasksWillBeLoaded{false};
//! this is used to record the first dock having tasks in it. It is used

@ -463,4 +463,29 @@ QString Importer::nameOfConfigFile(const QString &fileName)
return layoutName;
}
bool Importer::layoutExists(QString layoutName)
{
return QFile::exists(QDir::homePath() + "/.config/latte/" + layoutName + ".layout.latte");
}
QString Importer::uniqueLayoutName(QString name)
{
int pos_ = name.lastIndexOf(QRegExp(QString("[-][0-9]+")));
if (layoutExists(name) && pos_ > 0) {
name = name.left(pos_);
}
int i = 2;
QString namePart = name;
while (layoutExists(name)) {
name = namePart + "-" + QString::number(i);
i++;
}
return name;
}
}

@ -65,9 +65,15 @@ public:
bool exportFullConfiguration(QString file);
static Importer::LatteFileVersion fileVersion(QString file);
static QString nameOfConfigFile(const QString &fileName);
static bool importHelper(QString fileName);
static QString nameOfConfigFile(const QString &fileName);
static QString uniqueLayoutName(QString name);
private:
//! check if this layout exists already in the latte directory
static bool layoutExists(QString layoutName);
//! checks if this old layout can be imported. If it can it returns
//! the new layout path and an empty string if it cant
QString layoutCanBeImported(QString oldAppletsPath, QString newName, QString exportDirectory = QString());

@ -357,9 +357,9 @@ QString LayoutManager::newLayout(QString layoutName, QString preset)
return newLayoutPath;
}
void LayoutManager::importDefaultLayout()
void LayoutManager::importDefaultLayout(bool newInstanceIfPresent)
{
importPreset(1);
importPreset(1, newInstanceIfPresent);
}
void LayoutManager::importPresets(bool includeDefault)
@ -371,11 +371,11 @@ void LayoutManager::importPresets(bool includeDefault)
}
for (int i = start; i <= 4; ++i) {
importPreset(i);
importPreset(i, false);
}
}
void LayoutManager::importPreset(int presetNo)
void LayoutManager::importPreset(int presetNo, bool newInstanceIfPresent)
{
QByteArray presetNameOrig = QString("preset" + QString::number(presetNo)).toUtf8();
QString presetPath = m_corona->kPackage().filePath(presetNameOrig);
@ -383,7 +383,13 @@ void LayoutManager::importPreset(int presetNo)
QByteArray presetNameChars = presetName.toUtf8();
presetName = i18n(presetNameChars);
QString newLayoutFile = QDir::homePath() + "/.config/latte/" + presetName + ".layout.latte";
QString newLayoutFile = "";
if (newInstanceIfPresent) {
newLayoutFile = QDir::homePath() + "/.config/latte/" + m_importer->uniqueLayoutName(presetName) + ".layout.latte";
} else {
newLayoutFile = QDir::homePath() + "/.config/latte/" + presetName + ".layout.latte";
}
if (!QFile(newLayoutFile).exists()) {
QFile(presetPath).copy(newLayoutFile);

@ -81,7 +81,7 @@ public:
QStringList activities();
void importDefaultLayout();
void importDefaultLayout(bool newInstanceIfPresent = false);
void importPresets(bool includeDefault = false);
public slots:
@ -110,7 +110,7 @@ private:
void confirmDynamicSwitch();
void setMenuLayouts(QStringList layouts);
void showInfoWindow(QString info, int duration);
void importPreset(int presetNo);
void importPreset(int presetNo, bool newInstanceIfPresent = false);
QString layoutPath(QString layoutName);

@ -83,6 +83,7 @@ int main(int argc, char **argv)
, {{"d", "debug"}, i18nc("command line", "Show the debugging messages on stdout.")}
, {"graphics", i18nc("command line", "Draw boxes around of the applets.")}
, {"with-window", i18nc("command line", "Open a window with much debug information.")}
, {"default-layout", i18nc("command line", "Import and load default layout.")}
, {"import", i18nc("command line", "Import configuration."), i18nc("command line: import", "file_name")}
, {"mask", i18nc("command line" , "Show messages of debugging for the mask (Only useful to devs).")}
, {"timers", i18nc("command line", "Show messages for debugging the timers (Only useful to devs).")}
@ -146,7 +147,13 @@ int main(int argc, char **argv)
KCrash::setDrKonqiEnabled(true);
KCrash::setFlags(KCrash::AutoRestart | KCrash::AlwaysDirectly);
Latte::DockCorona corona;
bool defaultLayoutOnStartup = false;
if (parser.isSet(QStringLiteral("default-layout"))) {
defaultLayoutOnStartup = true;
}
Latte::DockCorona corona(defaultLayoutOnStartup);
KDBusService service(KDBusService::Unique);
return app.exec();

Loading…
Cancel
Save