mirror of
https://github.com/KDE/latte-dock.git
synced 2025-01-12 01:17:55 +03:00
cmd:support "add-dock" through command line
-- "add-dock" option now works even when application is not running and the user is executing it through command line. BUG: 446526 FIXED-IN: 0.10.5
This commit is contained in:
parent
6f162479e0
commit
ac30a9eb4f
@ -81,9 +81,10 @@
|
||||
|
||||
namespace Latte {
|
||||
|
||||
Corona::Corona(bool defaultLayoutOnStartup, QString layoutNameOnStartUp, int userSetMemoryUsage, QObject *parent)
|
||||
Corona::Corona(bool defaultLayoutOnStartup, QString layoutNameOnStartUp, QString addViewTemplateName, int userSetMemoryUsage, QObject *parent)
|
||||
: Plasma::Corona(parent),
|
||||
m_defaultLayoutOnStartup(defaultLayoutOnStartup),
|
||||
m_startupAddViewTemplateName(addViewTemplateName),
|
||||
m_userSetMemoryUsage(userSetMemoryUsage),
|
||||
m_layoutNameOnStartUp(layoutNameOnStartUp),
|
||||
m_activitiesConsumer(new KActivities::Consumer(this)),
|
||||
@ -267,6 +268,15 @@ void Corona::load()
|
||||
addOutput(screen);
|
||||
}
|
||||
|
||||
connect(m_layoutsManager->synchronizer(), &Layouts::Synchronizer::initializationFinished, [this]() {
|
||||
if (!m_startupAddViewTemplateName.isEmpty()) {
|
||||
//! user requested through cmd startup to add view from specific view template and we can add it after the startup
|
||||
//! sequence has loaded all required layouts properly
|
||||
addView(0, m_startupAddViewTemplateName);
|
||||
m_startupAddViewTemplateName = "";
|
||||
}
|
||||
});
|
||||
|
||||
m_inStartup = false;
|
||||
|
||||
connect(qGuiApp, &QGuiApplication::screenAdded, this, &Corona::addOutput, Qt::UniqueConnection);
|
||||
|
@ -87,6 +87,7 @@ class Corona : public Plasma::Corona
|
||||
public:
|
||||
Corona(bool defaultLayoutOnStartup = false,
|
||||
QString layoutNameOnStartUp = QString(),
|
||||
QString addViewTemplateName = QString(),
|
||||
int userSetMemoryUsage = -1,
|
||||
QObject *parent = nullptr);
|
||||
virtual ~Corona();
|
||||
@ -222,6 +223,7 @@ private:
|
||||
int m_userSetMemoryUsage{ -1};
|
||||
|
||||
QString m_layoutNameOnStartUp;
|
||||
QString m_startupAddViewTemplateName;
|
||||
QString m_importFullConfigurationFile;
|
||||
|
||||
QList<KDeclarative::QmlObjectSharedEngine *> m_alternativesObjects;
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "../screenpool.h"
|
||||
#include "../layout/abstractlayout.h"
|
||||
#include "../settings/universalsettings.h"
|
||||
#include "../templates/templatesmanager.h"
|
||||
#include "../tools/commontools.h"
|
||||
|
||||
// Qt
|
||||
@ -583,6 +584,11 @@ void Importer::disableAutostart()
|
||||
}
|
||||
}
|
||||
|
||||
bool Importer::hasViewTemplate(const QString &name)
|
||||
{
|
||||
return availableViewTemplates().contains(name);
|
||||
}
|
||||
|
||||
QString Importer::importLayout(const QString &fileName, const QString &suggestedLayoutName)
|
||||
{
|
||||
QString newLayoutName = importLayoutHelper(fileName, suggestedLayoutName);
|
||||
@ -606,6 +612,13 @@ QString Importer::importLayoutHelper(const QString &fileName, const QString &sug
|
||||
newLayoutName = uniqueLayoutName(newLayoutName);
|
||||
|
||||
QString newPath = layoutUserFilePath(newLayoutName);
|
||||
|
||||
QDir localLayoutsDir(layoutUserDir());
|
||||
|
||||
if (!localLayoutsDir.exists()) {
|
||||
QDir(Latte::configPath()).mkdir("latte");
|
||||
}
|
||||
|
||||
QFile(fileName).copy(newPath);
|
||||
|
||||
QFileInfo newFileInfo(newPath);
|
||||
@ -633,6 +646,57 @@ QStringList Importer::availableLayouts()
|
||||
return layoutNames;
|
||||
}
|
||||
|
||||
QStringList Importer::availableViewTemplates()
|
||||
{
|
||||
QStringList templates;
|
||||
|
||||
QDir localDir(layoutUserDir() + "/templates");
|
||||
QStringList filter;
|
||||
filter.append(QString("*.view.latte"));
|
||||
QStringList files = localDir.entryList(filter, QDir::Files | QDir::NoSymLinks);
|
||||
|
||||
for(const auto &file : files) {
|
||||
templates.append(Templates::Manager::templateName(file));
|
||||
}
|
||||
|
||||
QDir systemDir(systemShellDataPath()+"/contents/templates");
|
||||
QStringList sfiles = systemDir.entryList(filter, QDir::Files | QDir::NoSymLinks);
|
||||
|
||||
for(const auto &file : sfiles) {
|
||||
QString name = Templates::Manager::templateName(file);
|
||||
if (!templates.contains(name)) {
|
||||
templates.append(name);
|
||||
}
|
||||
}
|
||||
|
||||
return templates;
|
||||
}
|
||||
|
||||
QStringList Importer::availableLayoutTemplates()
|
||||
{
|
||||
QStringList templates;
|
||||
|
||||
QDir localDir(layoutUserDir() + "/templates");
|
||||
QStringList filter;
|
||||
filter.append(QString("*.layout.latte"));
|
||||
QStringList files = localDir.entryList(filter, QDir::Files | QDir::NoSymLinks);
|
||||
|
||||
for(const auto &file : files) {
|
||||
templates.append(Templates::Manager::templateName(file));
|
||||
}
|
||||
|
||||
QDir systemDir(systemShellDataPath()+"/contents/templates");
|
||||
QStringList sfiles = systemDir.entryList(filter, QDir::Files | QDir::NoSymLinks);
|
||||
|
||||
for(const auto &file : sfiles) {
|
||||
QString name = Templates::Manager::templateName(file);
|
||||
if (!templates.contains(name)) {
|
||||
templates.append(name);
|
||||
}
|
||||
}
|
||||
|
||||
return templates;
|
||||
}
|
||||
|
||||
QString Importer::nameOfConfigFile(const QString &fileName)
|
||||
{
|
||||
@ -662,6 +726,18 @@ QString Importer::layoutUserFilePath(QString layoutName)
|
||||
return QString(layoutUserDir() + "/" + layoutName + ".layout.latte");
|
||||
}
|
||||
|
||||
QString Importer::systemShellDataPath()
|
||||
{
|
||||
QStringList paths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
|
||||
QString rootpath = paths.count() > 0 ? paths[paths.count()-1] : "/usr/share";
|
||||
return rootpath + "/plasma/shells/org.kde.latte.shell";
|
||||
}
|
||||
|
||||
QString Importer::layoutTemplateSystemFilePath(const QString &name)
|
||||
{
|
||||
return systemShellDataPath() + "/contents/templates/" + name + ".layout.latte";
|
||||
}
|
||||
|
||||
QString Importer::uniqueLayoutName(QString name)
|
||||
{
|
||||
int pos_ = name.lastIndexOf(QRegExp(QString(" - [0-9]+")));
|
||||
|
@ -89,11 +89,18 @@ public:
|
||||
static QString layoutUserFilePath(QString layoutName);
|
||||
//! returns the layouts user directory
|
||||
static QString layoutUserDir();
|
||||
//! returns the system path for latte shell data
|
||||
static QString systemShellDataPath();
|
||||
|
||||
static QString nameOfConfigFile(const QString &fileName);
|
||||
static QString uniqueLayoutName(QString name);
|
||||
|
||||
static bool hasViewTemplate(const QString &name);
|
||||
static QString layoutTemplateSystemFilePath(const QString &name);
|
||||
|
||||
static QStringList availableLayouts();
|
||||
static QStringList availableLayoutTemplates();
|
||||
static QStringList availableViewTemplates();
|
||||
//! it checks the linked file if there are Containments in it that belong
|
||||
//! to Original Layouts and moves them accordingly. This is used mainly on
|
||||
//! startup and if such state occurs, it basically means that the app didn't
|
||||
|
@ -653,6 +653,8 @@ bool Synchronizer::initSingleMode(QString layoutName)
|
||||
}
|
||||
|
||||
m_manager->corona()->universalSettings()->setSingleModeLayoutName(layoutName);
|
||||
|
||||
emit initializationFinished();
|
||||
});
|
||||
|
||||
return true;
|
||||
@ -685,6 +687,8 @@ bool Synchronizer::initMultipleMode(QString layoutName)
|
||||
}
|
||||
|
||||
syncMultipleLayoutsToActivities();
|
||||
|
||||
emit initializationFinished();
|
||||
});
|
||||
|
||||
return true;
|
||||
|
@ -119,6 +119,7 @@ signals:
|
||||
void centralLayoutsChanged();
|
||||
void layoutsChanged();
|
||||
void runningActicitiesChanged();
|
||||
void initializationFinished();
|
||||
|
||||
void currentLayoutIsSwitching(QString layoutName);
|
||||
|
||||
|
29
app/main.cpp
29
app/main.cpp
@ -10,6 +10,7 @@
|
||||
#include "apptypes.h"
|
||||
#include "lattecorona.h"
|
||||
#include "layouts/importer.h"
|
||||
#include "templates/templatesmanager.h"
|
||||
|
||||
// C++
|
||||
#include <memory>
|
||||
@ -214,6 +215,7 @@ int main(int argc, char **argv)
|
||||
bool defaultLayoutOnStartup = false;
|
||||
int memoryUsage = -1;
|
||||
QString layoutNameOnStartup = "";
|
||||
QString addViewTemplateNameOnStartup = "";
|
||||
|
||||
//! --default-layout option
|
||||
if (parser.isSet(QStringLiteral("default-layout"))) {
|
||||
@ -326,6 +328,31 @@ int main(int argc, char **argv)
|
||||
memoryUsage = (int)(Latte::MemoryUsage::SingleLayout);
|
||||
}
|
||||
|
||||
//! add-dock usage option
|
||||
if (parser.isSet(QStringLiteral("add-dock"))) {
|
||||
QString viewTemplateName = parser.value(QStringLiteral("add-dock"));
|
||||
QStringList viewTemplates = Latte::Layouts::Importer::availableViewTemplates();
|
||||
|
||||
if (viewTemplates.contains(viewTemplateName)) {
|
||||
if (layoutNameOnStartup.isEmpty()) {
|
||||
//! Clean layout template is applied and proper name is used
|
||||
QString emptytemplatepath = Latte::Layouts::Importer::layoutTemplateSystemFilePath(Latte::Templates::EMPTYLAYOUTTEMPLATENAME);
|
||||
QString suggestedname = parser.isSet(QStringLiteral("suggested-layout-name")) ? parser.value(QStringLiteral("suggested-layout-name")) : viewTemplateName;
|
||||
QString importedLayout = Latte::Layouts::Importer::importLayoutHelper(emptytemplatepath, suggestedname);
|
||||
|
||||
if (importedLayout.isEmpty()) {
|
||||
qInfo() << i18n("The layout cannot be imported");
|
||||
qGuiApp->exit();
|
||||
return 0;
|
||||
} else {
|
||||
layoutNameOnStartup = importedLayout;
|
||||
}
|
||||
}
|
||||
|
||||
addViewTemplateNameOnStartup = viewTemplateName;
|
||||
}
|
||||
}
|
||||
|
||||
//! text filter for debug messages
|
||||
if (parser.isSet(QStringLiteral("debug-text"))) {
|
||||
filterDebugMessageText = parser.value(QStringLiteral("debug-text"));
|
||||
@ -350,7 +377,7 @@ int main(int argc, char **argv)
|
||||
KCrash::setDrKonqiEnabled(true);
|
||||
KCrash::setFlags(KCrash::AutoRestart | KCrash::AlwaysDirectly);
|
||||
|
||||
Latte::Corona corona(defaultLayoutOnStartup, layoutNameOnStartup, memoryUsage);
|
||||
Latte::Corona corona(defaultLayoutOnStartup, layoutNameOnStartup, addViewTemplateNameOnStartup, memoryUsage);
|
||||
KDBusService service(KDBusService::Unique);
|
||||
|
||||
return app.exec();
|
||||
|
@ -311,6 +311,24 @@ QString Manager::uniqueViewTemplateName(QString name) const
|
||||
return name;
|
||||
}
|
||||
|
||||
QString Manager::templateName(const QString &filePath)
|
||||
{
|
||||
int lastSlash = filePath.lastIndexOf("/");
|
||||
QString tempFilePath = filePath;
|
||||
QString templatename = tempFilePath.remove(0, lastSlash + 1);
|
||||
|
||||
QString extension(".layout.latte");
|
||||
int ext = templatename.lastIndexOf(extension);
|
||||
if (ext>0) {
|
||||
templatename = templatename.remove(ext, extension.size());
|
||||
} else {
|
||||
extension = ".view.latte";
|
||||
ext = templatename.lastIndexOf(extension);
|
||||
templatename = templatename.remove(ext,extension.size());
|
||||
}
|
||||
|
||||
return templatename;
|
||||
}
|
||||
|
||||
//! it is used in order to provide translations for system templates
|
||||
void Manager::exposeTranslatedTemplateNames()
|
||||
|
@ -60,6 +60,8 @@ public:
|
||||
|
||||
QString viewTemplateFilePath(const QString templateName) const;
|
||||
|
||||
static QString templateName(const QString &filePath);
|
||||
|
||||
void importSystemLayouts();
|
||||
void installCustomLayoutTemplate(const QString &templateFilePath);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user