mirror of
https://github.com/KDE/latte-dock.git
synced 2024-12-25 09:33:51 +03:00
get ready for Plasma LookNFeel packages
--introduce enable/disableAutostart from command line --accept import-layout from command line when latte is already running --introduce --suggested-layout-name to be used with import-layout in order to provide a preferred layout name e.g. latte-dock --import-layout /blah/blah/mywhat.layout.latte --suggested-layout-name MyAwesomeLayout --dbus:introduce "setAutostart" function --dbus:introduce "importLayoutFile" function BUG:446249 FIXED-IN:0.10.5
This commit is contained in:
parent
2560828067
commit
0e63e7dd0b
@ -5,6 +5,9 @@
|
||||
</method>
|
||||
<method name="quitApplication">
|
||||
</method>
|
||||
<method name="setAutostart">
|
||||
<arg name="enabled" type="b" direction="in"/>
|
||||
</method>
|
||||
<method name="updateDockItemBadge">
|
||||
<arg name="identifier" type="s" direction="in"/>
|
||||
<arg name="value" type="s" direction="in"/>
|
||||
@ -15,6 +18,10 @@
|
||||
<method name="switchToLayout">
|
||||
<arg name="layout" type="s" direction="in"/>
|
||||
</method>
|
||||
<method name="importLayoutFile">
|
||||
<arg name="filepath" type="s" direction="in"/>
|
||||
<arg name="suggestedLayoutName" type="s" direction="in"/>
|
||||
</method>
|
||||
<method name="exportViewTemplate">
|
||||
<arg name="containmentId" type="u" direction="in"/>
|
||||
</method>
|
||||
|
@ -1082,41 +1082,57 @@ void Corona::updateDockItemBadge(QString identifier, QString value)
|
||||
m_globalShortcuts->updateViewItemBadge(identifier, value);
|
||||
}
|
||||
|
||||
void Corona::setAutostart(const bool &enabled)
|
||||
{
|
||||
m_universalSettings->setAutostart(enabled);
|
||||
}
|
||||
|
||||
void Corona::switchToLayout(QString layout)
|
||||
{
|
||||
if ((layout.startsWith("file:/") || layout.startsWith("/")) && layout.endsWith(".layout.latte")) {
|
||||
//! Import and load runtime a layout through dbus interface
|
||||
//! It can be used from external programs that want to update runtime
|
||||
//! the Latte shown layout
|
||||
QString layoutPath = layout;
|
||||
|
||||
//! cleanup layout path
|
||||
if (layoutPath.startsWith("file:///")) {
|
||||
layoutPath = layout.remove("file://");
|
||||
} else if (layoutPath.startsWith("file://")) {
|
||||
layoutPath = layout.remove("file:/");
|
||||
}
|
||||
|
||||
//! check out layoutpath existence
|
||||
if (QFileInfo(layoutPath).exists()) {
|
||||
qDebug() << " Layout is going to be imported and loaded from file :: " << layoutPath;
|
||||
|
||||
QString importedLayout = m_layoutsManager->importer()->importLayout(layoutPath);
|
||||
|
||||
if (importedLayout.isEmpty()) {
|
||||
qDebug() << i18n("The layout cannot be imported from file :: ") << layoutPath;
|
||||
} else {
|
||||
m_layoutsManager->switchToLayout(importedLayout);
|
||||
}
|
||||
} else {
|
||||
qDebug() << " Layout from missing file can not be imported and loaded :: " << layoutPath;
|
||||
}
|
||||
importLayoutFile(layout);
|
||||
} else {
|
||||
m_layoutsManager->switchToLayout(layout);
|
||||
}
|
||||
}
|
||||
|
||||
void Corona::importLayoutFile(const QString &filepath, const QString &suggestedLayoutName)
|
||||
{
|
||||
bool isFilepathValid = (filepath.startsWith("file:/") || filepath.startsWith("/")) && filepath.endsWith(".layout.latte");
|
||||
|
||||
if (!isFilepathValid) {
|
||||
qDebug() << i18n("The layout cannot be imported from file :: ") << filepath;
|
||||
return;
|
||||
}
|
||||
|
||||
//! Import and load runtime a layout through dbus interface
|
||||
//! It can be used from external programs that want to update runtime
|
||||
//! the Latte shown layout
|
||||
QString layoutPath = filepath;
|
||||
|
||||
//! cleanup layout path
|
||||
if (layoutPath.startsWith("file:///")) {
|
||||
layoutPath = layoutPath.remove("file://");
|
||||
} else if (layoutPath.startsWith("file://")) {
|
||||
layoutPath = layoutPath.remove("file:/");
|
||||
}
|
||||
|
||||
//! check out layoutpath existence
|
||||
if (QFileInfo(layoutPath).exists()) {
|
||||
qDebug() << " Layout is going to be imported and loaded from file :: " << layoutPath << " with suggested name :: " << suggestedLayoutName;
|
||||
|
||||
QString importedLayout = m_layoutsManager->importer()->importLayout(layoutPath, suggestedLayoutName);
|
||||
|
||||
if (importedLayout.isEmpty()) {
|
||||
qDebug() << i18n("The layout cannot be imported from file :: ") << layoutPath;
|
||||
} else {
|
||||
m_layoutsManager->switchToLayout(importedLayout, MemoryUsage::SingleLayout);
|
||||
}
|
||||
} else {
|
||||
qDebug() << " Layout from missing file can not be imported and loaded :: " << layoutPath;
|
||||
}
|
||||
}
|
||||
|
||||
void Corona::showSettingsWindow(int page)
|
||||
{
|
||||
if (m_inStartup) {
|
||||
|
@ -144,6 +144,7 @@ public:
|
||||
//! these functions are used from context menu through containmentactions
|
||||
void quitApplication();
|
||||
void switchToLayout(QString layout);
|
||||
void importLayoutFile(const QString &filepath, const QString &suggestedLayoutName = QString());
|
||||
void showSettingsWindow(int page);
|
||||
|
||||
QStringList contextMenuData(const uint &containmentId);
|
||||
@ -154,6 +155,8 @@ public slots:
|
||||
void activateLauncherMenu();
|
||||
void loadDefaultLayout() override;
|
||||
|
||||
void setAutostart(const bool &enabled);
|
||||
|
||||
void addView(const uint &containmentId, const QString &templateId);
|
||||
void duplicateView(const uint &containmentId);
|
||||
void exportViewTemplate(const uint &containmentId);
|
||||
|
@ -358,7 +358,7 @@ bool Importer::importOldConfiguration(QString oldConfigPath, QString newName)
|
||||
}
|
||||
|
||||
//! the old configuration contains also screen values, these must be updated also
|
||||
/*
|
||||
/*
|
||||
* do not use any deprecated screen ids
|
||||
* KSharedConfigPtr oldScreensConfig = KSharedConfig::openConfig(screensPath);
|
||||
KConfigGroup m_screensGroup = KConfigGroup(oldScreensConfig, "ScreenConnectors");
|
||||
@ -531,9 +531,56 @@ bool Importer::importHelper(QString fileName)
|
||||
return true;
|
||||
}
|
||||
|
||||
QString Importer::importLayout(QString fileName)
|
||||
bool Importer::isAutostartEnabled()
|
||||
{
|
||||
QString newLayoutName = importLayoutHelper(fileName);
|
||||
QFile autostartFile(Latte::configPath() + "/autostart/org.kde.latte-dock.desktop");
|
||||
return autostartFile.exists();
|
||||
}
|
||||
|
||||
void Importer::enableAutostart()
|
||||
{
|
||||
//! deprecated old file
|
||||
QFile oldAutostartFile(Latte::configPath() + "/autostart/latte-dock.desktop");
|
||||
|
||||
if (oldAutostartFile.exists()) {
|
||||
//! remove deprecated file
|
||||
oldAutostartFile.remove();
|
||||
}
|
||||
|
||||
QFile autostartFile(Latte::configPath() + "/autostart/org.kde.latte-dock.desktop");
|
||||
QFile metaFile(standardPath("applications/org.kde.latte-dock.desktop", false));
|
||||
|
||||
if (metaFile.exists()) {
|
||||
//! check if autostart folder exists and create otherwise
|
||||
QDir autostartDir(Latte::configPath() + "/autostart");
|
||||
if (!autostartDir.exists()) {
|
||||
QDir configDir(Latte::configPath());
|
||||
configDir.mkdir("autostart");
|
||||
}
|
||||
|
||||
metaFile.copy(autostartFile.fileName());
|
||||
}
|
||||
}
|
||||
|
||||
void Importer::disableAutostart()
|
||||
{
|
||||
QFile oldAutostartFile(Latte::configPath() + "/autostart/latte-dock.desktop");
|
||||
|
||||
if (oldAutostartFile.exists()) {
|
||||
//! remove deprecated file
|
||||
oldAutostartFile.remove();
|
||||
}
|
||||
|
||||
QFile autostartFile(Latte::configPath() + "/autostart/org.kde.latte-dock.desktop");
|
||||
|
||||
if (autostartFile.exists()) {
|
||||
autostartFile.remove();
|
||||
}
|
||||
}
|
||||
|
||||
QString Importer::importLayout(const QString &fileName, const QString &suggestedLayoutName)
|
||||
{
|
||||
QString newLayoutName = importLayoutHelper(fileName, suggestedLayoutName);
|
||||
|
||||
if (!newLayoutName.isEmpty()) {
|
||||
emit newLayoutAdded(layoutUserFilePath(newLayoutName));
|
||||
@ -542,7 +589,7 @@ QString Importer::importLayout(QString fileName)
|
||||
return newLayoutName;
|
||||
}
|
||||
|
||||
QString Importer::importLayoutHelper(QString fileName)
|
||||
QString Importer::importLayoutHelper(const QString &fileName, const QString &suggestedLayoutName)
|
||||
{
|
||||
LatteFileVersion version = fileVersion(fileName);
|
||||
|
||||
@ -550,7 +597,7 @@ QString Importer::importLayoutHelper(QString fileName)
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString newLayoutName = Layout::AbstractLayout::layoutName(fileName);
|
||||
QString newLayoutName = !suggestedLayoutName.isEmpty() ? suggestedLayoutName : Layout::AbstractLayout::layoutName(fileName);
|
||||
newLayoutName = uniqueLayoutName(newLayoutName);
|
||||
|
||||
QString newPath = layoutUserFilePath(newLayoutName);
|
||||
@ -560,7 +607,7 @@ QString Importer::importLayoutHelper(QString fileName)
|
||||
|
||||
if (newFileInfo.exists() && !newFileInfo.isWritable()) {
|
||||
QFile(newPath).setPermissions(QFileDevice::ReadUser | QFileDevice::WriteUser | QFileDevice::ReadGroup | QFileDevice::ReadOther);
|
||||
}
|
||||
}
|
||||
|
||||
return newLayoutName;
|
||||
}
|
||||
|
@ -61,8 +61,11 @@ public:
|
||||
QString storageTmpDir() const;
|
||||
//! imports the specific layout and return the new layout name.
|
||||
//! if the function didn't succeed returns an empty string
|
||||
QString importLayout(QString fileName);
|
||||
QString importLayout(const QString &fileName, const QString &suggestedName = QString());
|
||||
|
||||
static void enableAutostart();
|
||||
static void disableAutostart();
|
||||
static bool isAutostartEnabled();
|
||||
|
||||
static Importer::LatteFileVersion fileVersion(QString file);
|
||||
|
||||
@ -80,7 +83,7 @@ public:
|
||||
static bool layoutExists(QString layoutName);
|
||||
//! imports the specific layout and return the new layout name.
|
||||
//! if the function didn't succeed returns an empty string
|
||||
static QString importLayoutHelper(QString fileName);
|
||||
static QString importLayoutHelper(const QString &fileName, const QString &suggestedName = QString());
|
||||
|
||||
//! returns the file path of a layout either existing or not
|
||||
static QString layoutUserFilePath(QString layoutName);
|
||||
|
35
app/main.cpp
35
app/main.cpp
@ -94,10 +94,13 @@ int main(int argc, char **argv)
|
||||
{{"r", "replace"}, i18nc("command line", "Replace the current Latte instance.")}
|
||||
, {{"d", "debug"}, i18nc("command line", "Show the debugging messages on stdout.")}
|
||||
, {{"cc", "clear-cache"}, i18nc("command line", "Clear qml cache. It can be useful after system upgrades.")}
|
||||
, {"enable-autostart", i18nc("command line", "Enable autostart for this application")}
|
||||
, {"disable-autostart", i18nc("command line", "Disable autostart for this application")}
|
||||
, {"default-layout", i18nc("command line", "Import and load default layout on startup.")}
|
||||
, {"available-layouts", i18nc("command line", "Print available layouts")}
|
||||
, {"layout", i18nc("command line", "Load specific layout on startup."), i18nc("command line: load", "layout_name")}
|
||||
, {"import-layout", i18nc("command line", "Import and load a layout."), i18nc("command line: import", "file_name")}
|
||||
, {"import-layout", i18nc("command line", "Import and load a layout."), i18nc("command line: import", "absolute_filepath")}
|
||||
, {"suggested-layout-name", i18nc("command line", "Suggested layout name when importing a layout file"), i18nc("command line: import", "suggested_name")}
|
||||
, {"import-full", i18nc("command line", "Import full configuration."), i18nc("command line: import", "file_name")}
|
||||
, {"add-dock", i18nc("command line", "Add Dock/Panel"), i18nc("command line: add", "template_name")}
|
||||
, {"single", i18nc("command line", "Single layout memory mode. Only one layout is active at any case.")}
|
||||
@ -169,6 +172,14 @@ int main(int argc, char **argv)
|
||||
|
||||
parser.process(app);
|
||||
|
||||
if (parser.isSet(QStringLiteral("enable-autostart"))) {
|
||||
Latte::Layouts::Importer::enableAutostart();
|
||||
}
|
||||
|
||||
if (parser.isSet(QStringLiteral("disable-autostart"))) {
|
||||
Latte::Layouts::Importer::disableAutostart();
|
||||
}
|
||||
|
||||
//! print available-layouts
|
||||
if (parser.isSet(QStringLiteral("available-layouts"))) {
|
||||
QStringList layouts = Latte::Layouts::Importer::availableLayouts();
|
||||
@ -239,19 +250,36 @@ int main(int argc, char **argv)
|
||||
if (!lockFile.tryLock(timeout)) {
|
||||
QDBusInterface iface("org.kde.lattedock", "/Latte", "", QDBusConnection::sessionBus());
|
||||
bool addview{parser.isSet(QStringLiteral("add-dock"))};
|
||||
bool importlayout{parser.isSet(QStringLiteral("import-layout"))};
|
||||
bool enableautostart{parser.isSet(QStringLiteral("enable-autostart"))};
|
||||
bool disableautostart{parser.isSet(QStringLiteral("disable-autostart"))};
|
||||
|
||||
bool validaction{false};
|
||||
|
||||
if (iface.isValid()) {
|
||||
if (addview) {
|
||||
validaction = true;
|
||||
iface.call("addView", (uint)0, parser.value(QStringLiteral("add-dock")));
|
||||
qGuiApp->exit();
|
||||
return 0;
|
||||
} else if (importlayout) {
|
||||
validaction = true;
|
||||
QString suggestedname = parser.isSet(QStringLiteral("suggested-layout-name")) ? parser.value(QStringLiteral("suggested-layout-name")) : QString();
|
||||
iface.call("importLayoutFile", parser.value(QStringLiteral("import-layout")), suggestedname);
|
||||
qGuiApp->exit();
|
||||
return 0;
|
||||
} else if (enableautostart || disableautostart){
|
||||
validaction = true;
|
||||
} else {
|
||||
// LayoutPage = 0
|
||||
iface.call("showSettingsWindow", 0);
|
||||
}
|
||||
}
|
||||
|
||||
qInfo() << i18n("An instance is already running!, use --replace to restart Latte");
|
||||
if (!validaction) {
|
||||
qInfo() << i18n("An instance is already running!, use --replace to restart Latte");
|
||||
}
|
||||
|
||||
qGuiApp->exit();
|
||||
return 0;
|
||||
}
|
||||
@ -279,7 +307,8 @@ int main(int argc, char **argv)
|
||||
|
||||
//! import-layout option
|
||||
if (parser.isSet(QStringLiteral("import-layout"))) {
|
||||
QString importedLayout = Latte::Layouts::Importer::importLayoutHelper(parser.value(QStringLiteral("import-layout")));
|
||||
QString suggestedname = parser.isSet(QStringLiteral("suggested-layout-name")) ? parser.value(QStringLiteral("suggested-layout-name")) : QString();
|
||||
QString importedLayout = Latte::Layouts::Importer::importLayoutHelper(parser.value(QStringLiteral("import-layout")), suggestedname);
|
||||
|
||||
if (importedLayout.isEmpty()) {
|
||||
qInfo() << i18n("The layout cannot be imported");
|
||||
|
@ -78,7 +78,11 @@ void UniversalSettings::load()
|
||||
bool autostartUserSet = m_universalGroup.readEntry("userConfiguredAutostart", false);
|
||||
|
||||
if (!autostartUserSet && !autostart()) {
|
||||
//! the first time the application is running and autostart is not set, autostart is enabled
|
||||
//! and from now own it will not be recreated in the beginning
|
||||
|
||||
setAutostart(true);
|
||||
m_universalGroup.writeEntry("userConfiguredAutostart", true);
|
||||
}
|
||||
|
||||
//! init screen scales
|
||||
@ -237,47 +241,22 @@ void UniversalSettings::setLaunchers(QStringList launcherList)
|
||||
|
||||
bool UniversalSettings::autostart() const
|
||||
{
|
||||
QFile autostartFile(Latte::configPath() + "/autostart/org.kde.latte-dock.desktop");
|
||||
return autostartFile.exists();
|
||||
return Layouts::Importer::isAutostartEnabled();
|
||||
}
|
||||
|
||||
void UniversalSettings::setAutostart(bool state)
|
||||
{
|
||||
//! remove old autostart file
|
||||
QFile oldAutostartFile(Latte::configPath() + "/autostart/latte-dock.desktop");
|
||||
|
||||
if (oldAutostartFile.exists()) {
|
||||
oldAutostartFile.remove();
|
||||
if (autostart() == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
//! end of removal of old autostart file
|
||||
|
||||
QFile autostartFile(Latte::configPath() + "/autostart/org.kde.latte-dock.desktop");
|
||||
QFile metaFile(Layouts::Importer::standardPath("applications/org.kde.latte-dock.desktop", false));
|
||||
|
||||
if (!state && autostartFile.exists()) {
|
||||
//! the first time that the user disables the autostart, this is recorded
|
||||
//! and from now own it will not be recreated it in the beginning
|
||||
if (!m_universalGroup.readEntry("userConfiguredAutostart", false)) {
|
||||
m_universalGroup.writeEntry("userConfiguredAutostart", true);
|
||||
}
|
||||
|
||||
autostartFile.remove();
|
||||
emit autostartChanged();
|
||||
} else if (state && metaFile.exists()) {
|
||||
//! check if autostart folder exists and create otherwise
|
||||
QDir autostartDir(Latte::configPath() + "/autostart");
|
||||
if (!autostartDir.exists()) {
|
||||
QDir configDir(Latte::configPath());
|
||||
configDir.mkdir("autostart");
|
||||
}
|
||||
|
||||
metaFile.copy(autostartFile.fileName());
|
||||
//! I haven't added the flag "OnlyShowIn=KDE;" into the autostart file
|
||||
//! because I fall onto a Plasma 5.8 case that this flag
|
||||
//! didn't let the plasma desktop to start
|
||||
emit autostartChanged();
|
||||
if (state) {
|
||||
Layouts::Importer::enableAutostart();
|
||||
} else {
|
||||
Layouts::Importer::disableAutostart();
|
||||
}
|
||||
|
||||
emit autostartChanged();
|
||||
}
|
||||
|
||||
bool UniversalSettings::badges3DStyle() const
|
||||
|
Loading…
Reference in New Issue
Block a user