-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
213 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Anton Kharuzhy <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
import QtQuick | ||
import QtCore | ||
import QtQuick.Dialogs | ||
|
||
Loader { | ||
id: settingsLoader | ||
|
||
active: false | ||
|
||
property string name | ||
property date dateCreated | ||
property string settingsJson | ||
property url location | ||
property bool writeMode: true | ||
|
||
signal configSaved(url fileUrl) | ||
signal configLoaded(url fileUrl, var settings) | ||
|
||
property var configExportFileDialog: FileDialog { | ||
nameFilters: ["Configuration (*.cfg)"] | ||
defaultSuffix: "cfg" | ||
fileMode: FileDialog.SaveFile | ||
onAccepted: savePlasmoidConfig(selectedFile) | ||
} | ||
|
||
property var configImportFileDialog: FileDialog { | ||
nameFilters: ["Configuration (*.cfg)"] | ||
defaultSuffix: "cfg" | ||
fileMode: FileDialog.OpenFile | ||
onAccepted: loadPlasmoidConfig(selectedFile) | ||
} | ||
|
||
sourceComponent: Settings { | ||
location: settingsLoader.location | ||
property int version: 0 | ||
property string name | ||
property date dateCreated | ||
property string settingsJson | ||
} | ||
|
||
onLoaded: function () { | ||
if (writeMode) { | ||
item.name = name; | ||
item.dateCreated = new Date(); | ||
item.settingsJson = settingsJson; | ||
configSaved(item.location); | ||
} else { | ||
name = item.value("name", ""); | ||
dateCreated = item.value("dateCreated", new Date()); | ||
settingsJson = item.value("settingsJson", "{}"); | ||
configLoaded(item.location, JSON.parse(settingsJson)); | ||
} | ||
active = false; | ||
} | ||
|
||
function showConfigExportFileDialog() { | ||
configExportFileDialog.open(); | ||
} | ||
|
||
function showConfigImportFileDialog() { | ||
configImportFileDialog.open(); | ||
} | ||
|
||
function saveSettings(name, settings, fileUrl) { | ||
name = name; | ||
settingsJson = JSON.stringify(settings); | ||
location = fileUrl; | ||
writeMode = true; | ||
active = true; | ||
} | ||
|
||
function loadSettings(fileUrl) { | ||
location = fileUrl; | ||
writeMode = false; | ||
active = true; | ||
} | ||
|
||
function getPlasmoidConfig() { | ||
let configMap = {}; | ||
const config = plasmoid.configuration; | ||
const propertyNames = config.keys(); | ||
for (let index = 0; index < propertyNames.length; index++) { | ||
const propertyName = propertyNames[index]; | ||
const propertyValue = config[propertyName]; | ||
configMap[propertyName] = propertyValue; | ||
} | ||
return configMap; | ||
} | ||
|
||
function savePlasmoidConfig(fileUrl) { | ||
const config = getPlasmoidConfig(); | ||
saveSettings("Application Title Bar Configuration", config, fileUrl); | ||
} | ||
|
||
function loadPlasmoidConfig(fileUrl) { | ||
const loadedConfig = loadSettings(fileUrl); | ||
} | ||
|
||
function updatePlasmoidConfig(loadedConfig) { | ||
let plasmoidConfig = plasmoid.configuration; | ||
for (const propertyName in loadedConfig) { | ||
let loadedValue = loadedConfig[propertyName]; | ||
let loadedValueString = JSON.stringify(loadedValue); | ||
let plasmoidValue = plasmoidConfig[propertyName]; | ||
let plasmoidValueString = JSON.stringify(plasmoidValue); | ||
if (loadedValueString !== plasmoidValueString && !plasmoidConfig.isImmutable(propertyName)) { | ||
//console.log("Diff in " + propertyName + " : '" + plasmoidConfig[propertyName] + "' !== '" + loadedValue + "'"); | ||
plasmoidConfig[propertyName] = loadedValue; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Anton Kharuzhy <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
import QtQuick | ||
import QtCore | ||
import QtQuick.Dialogs | ||
import QtQuick.Controls | ||
import org.kde.plasma.core as PlasmaCore | ||
import org.kde.plasma.plasmoid | ||
|
||
QtObject { | ||
property Item configManager: ConfigManager { | ||
onConfigLoaded: function (fileUrl, loadedConfig) { | ||
updatePlasmoidConfig(loadedConfig); | ||
} | ||
} | ||
|
||
Plasmoid.contextualActions: [ | ||
PlasmaCore.Action { | ||
text: i18n("Ma&ximize") | ||
enabled: tasksModel.activeWindow.maximizable | ||
checked: tasksModel.activeWindow.maximized | ||
icon.name: "window-maximize" | ||
checkable: true | ||
onTriggered: tasksModel.activeWindow.actionCall(ActiveWindow.Action.Maximize) | ||
}, | ||
PlasmaCore.Action { | ||
text: i18n("Mi&nimize") | ||
enabled: tasksModel.activeWindow.minimizable | ||
icon.name: "window-minimize" | ||
checkable: false | ||
onTriggered: tasksModel.activeWindow.actionCall(ActiveWindow.Action.Minimize) | ||
}, | ||
PlasmaCore.Action { | ||
text: i18n("Keep &Above Others") | ||
checked: tasksModel.activeWindow.keepAbove | ||
icon.name: "window-keep-above" | ||
checkable: true | ||
onTriggered: tasksModel.activeWindow.actionCall(ActiveWindow.Action.KeepAbove) | ||
}, | ||
PlasmaCore.Action { | ||
text: i18n("Keep &Below Others") | ||
checked: tasksModel.activeWindow.keepBelow | ||
icon.name: "window-keep-below" | ||
checkable: true | ||
onTriggered: tasksModel.activeWindow.actionCall(ActiveWindow.Action.KeepBelow) | ||
}, | ||
PlasmaCore.Action { | ||
text: i18n("&Fullscreen") | ||
enabled: tasksModel.activeWindow.fullScreenable | ||
checked: tasksModel.activeWindow.fullScreen | ||
icon.name: "view-fullscreen" | ||
checkable: true | ||
onTriggered: tasksModel.activeWindow.actionCall(ActiveWindow.Action.FullScreen) | ||
}, | ||
PlasmaCore.Action { | ||
text: i18n("&Move") | ||
icon.name: "transform-move" | ||
enabled: tasksModel.activeTask.movable | ||
checkable: false | ||
onTriggered: tasksModel.activeWindow.actionCall(ActiveWindow.Action.Move) | ||
}, | ||
PlasmaCore.Action { | ||
text: i18n("&Resize") | ||
icon.name: "image-resize-symbolic" | ||
enabled: tasksModel.activeTask.resizable | ||
checkable: false | ||
onTriggered: tasksModel.activeWindow.actionCall(ActiveWindow.Action.Resize) | ||
}, | ||
PlasmaCore.Action { | ||
text: i18n("&Close") | ||
icon.name: "window-close" | ||
enabled: tasksModel.activeTask.closable | ||
checkable: false | ||
onTriggered: tasksModel.activeWindow.actionCall(ActiveWindow.Action.Close) | ||
}, | ||
PlasmaCore.Action { | ||
text: i18n("&Export configuration...") | ||
icon.name: "document-export" | ||
checkable: false | ||
onTriggered: configManager.showConfigExportFileDialog() | ||
}, | ||
PlasmaCore.Action { | ||
text: i18n("&Import configuration...") | ||
icon.name: "document-import" | ||
checkable: false | ||
onTriggered: configManager.showConfigImportFileDialog() | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters