mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
Add import and export dialogs
This commit is contained in:
parent
31c129163b
commit
3ee1d4c30e
59
sources/awesome-widget/package/contents/ui/ExportDialog.qml
Normal file
59
sources/awesome-widget/package/contents/ui/ExportDialog.qml
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* This file is part of awesome-widgets *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is free software: you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
|
* License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
import QtQuick 2.0
|
||||||
|
import QtQuick.Dialogs 1.2 as QtDialogs
|
||||||
|
|
||||||
|
import org.kde.plasma.private.awesomewidget 1.0
|
||||||
|
|
||||||
|
|
||||||
|
Item {
|
||||||
|
property var configuration
|
||||||
|
|
||||||
|
AWConfigHelper {
|
||||||
|
id: awConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
QtDialogs.MessageDialog {
|
||||||
|
id: messageDialog
|
||||||
|
standardButtons: QtDialogs.StandardButton.Ok
|
||||||
|
}
|
||||||
|
|
||||||
|
QtDialogs.FileDialog {
|
||||||
|
id: fileDialog
|
||||||
|
selectExisting: false
|
||||||
|
title: i18n("Export")
|
||||||
|
folder: awConfig.configurationDirectory()
|
||||||
|
onAccepted: {
|
||||||
|
var status = awConfig.exportConfiguration(
|
||||||
|
configuration,
|
||||||
|
fileDialog.fileUrl.toString().replace("file://", ""))
|
||||||
|
if (status) {
|
||||||
|
messageDialog.title = i18n("Success")
|
||||||
|
messageDialog.text = i18n("Please note that binary files were not copied")
|
||||||
|
} else {
|
||||||
|
messageDialog.title = i18n("Ooops...")
|
||||||
|
messageDialog.text = i18n("Could not save configuration file")
|
||||||
|
}
|
||||||
|
messageDialog.open()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function open() {
|
||||||
|
return fileDialog.open()
|
||||||
|
}
|
||||||
|
}
|
71
sources/awesome-widget/package/contents/ui/ImportDialog.qml
Normal file
71
sources/awesome-widget/package/contents/ui/ImportDialog.qml
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* This file is part of awesome-widgets *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is free software: you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
|
* License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
import QtQuick 2.0
|
||||||
|
import QtQuick.Controls 1.3 as QtControls
|
||||||
|
import QtQuick.Dialogs 1.2 as QtDialogs
|
||||||
|
|
||||||
|
import org.kde.plasma.private.awesomewidget 1.0
|
||||||
|
|
||||||
|
|
||||||
|
Item {
|
||||||
|
AWConfigHelper {
|
||||||
|
id: awConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
signal configurationReceived(var configuration)
|
||||||
|
|
||||||
|
QtDialogs.FileDialog {
|
||||||
|
id: fileDialog
|
||||||
|
title: i18n("Import")
|
||||||
|
folder: awConfig.configurationDirectory()
|
||||||
|
onAccepted: importSelection.open()
|
||||||
|
}
|
||||||
|
|
||||||
|
QtDialogs.Dialog {
|
||||||
|
id: importSelection
|
||||||
|
|
||||||
|
Column {
|
||||||
|
QtControls.CheckBox {
|
||||||
|
id: importPlasmoid
|
||||||
|
text: i18n("Import plasmoid settings")
|
||||||
|
}
|
||||||
|
|
||||||
|
QtControls.CheckBox {
|
||||||
|
id: importExtensions
|
||||||
|
text: i18n("Import extensions")
|
||||||
|
}
|
||||||
|
|
||||||
|
QtControls.CheckBox {
|
||||||
|
id: importAdds
|
||||||
|
text: i18n("Import additional files")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onAccepted: {
|
||||||
|
var importConfig = awConfig.importConfiguration(
|
||||||
|
fileDialog.fileUrl.toString().replace("file://", ""),
|
||||||
|
importPlasmoid.checked, importExtensions.checked,
|
||||||
|
importAdds.checked)
|
||||||
|
configurationReceived(importConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function open() {
|
||||||
|
return fileDialog.open()
|
||||||
|
}
|
||||||
|
}
|
@ -198,95 +198,27 @@ Item {
|
|||||||
onButtonActivated: awActions.dropCache()
|
onButtonActivated: awActions.dropCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
Row {
|
ButtonSelector {
|
||||||
height: implicitHeight
|
ExportDialog {
|
||||||
width: parent.width
|
|
||||||
QtControls.Label {
|
|
||||||
height: parent.height
|
|
||||||
width: parent.width * 2 / 5
|
|
||||||
}
|
|
||||||
QtControls.Button {
|
|
||||||
width: parent.width * 3 / 5
|
|
||||||
text: i18n("Export configuration")
|
|
||||||
onClicked: saveConfigAs.open()
|
|
||||||
}
|
|
||||||
|
|
||||||
QtDialogs.FileDialog {
|
|
||||||
id: saveConfigAs
|
id: saveConfigAs
|
||||||
selectExisting: false
|
configuration: plasmoid.configuration
|
||||||
title: i18n("Export")
|
|
||||||
folder: awConfig.configurationDirectory()
|
|
||||||
onAccepted: {
|
|
||||||
var status = awConfig.exportConfiguration(
|
|
||||||
plasmoid.configuration,
|
|
||||||
saveConfigAs.fileUrl.toString().replace("file://", ""))
|
|
||||||
if (status) {
|
|
||||||
messageDialog.title = i18n("Success")
|
|
||||||
messageDialog.text = i18n("Please note that binary files were not copied")
|
|
||||||
} else {
|
|
||||||
messageDialog.title = i18n("Ooops...")
|
|
||||||
messageDialog.text = i18n("Could not save configuration file")
|
|
||||||
}
|
|
||||||
messageDialog.open()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QtDialogs.MessageDialog {
|
value: i18n("Export configuration")
|
||||||
id: messageDialog
|
onButtonActivated: saveConfigAs.open()
|
||||||
standardButtons: QtDialogs.StandardButton.Ok
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Row {
|
ButtonSelector {
|
||||||
height: implicitHeight
|
ImportDialog {
|
||||||
width: parent.width
|
id: loadConfigFrom
|
||||||
QtControls.Label {
|
onConfigurationReceived: {
|
||||||
height: parent.height
|
for (var key in configuration)
|
||||||
width: parent.width * 2 / 5
|
plasmoid.configuration[key] = configuration[key]
|
||||||
}
|
|
||||||
QtControls.Button {
|
|
||||||
width: parent.width * 3 / 5
|
|
||||||
text: i18n("Import configuration")
|
|
||||||
onClicked: openConfig.open()
|
|
||||||
}
|
|
||||||
|
|
||||||
QtDialogs.FileDialog {
|
|
||||||
id: openConfig
|
|
||||||
title: i18n("Import")
|
|
||||||
folder: awConfig.configurationDirectory()
|
|
||||||
onAccepted: importSelection.open()
|
|
||||||
}
|
|
||||||
|
|
||||||
QtDialogs.Dialog {
|
|
||||||
id: importSelection
|
|
||||||
|
|
||||||
Column {
|
|
||||||
QtControls.CheckBox {
|
|
||||||
id: importPlasmoid
|
|
||||||
text: i18n("Import plasmoid settings")
|
|
||||||
}
|
|
||||||
|
|
||||||
QtControls.CheckBox {
|
|
||||||
id: importExtensions
|
|
||||||
text: i18n("Import extensions")
|
|
||||||
}
|
|
||||||
|
|
||||||
QtControls.CheckBox {
|
|
||||||
id: importAdds
|
|
||||||
text: i18n("Import additional files")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onAccepted: {
|
|
||||||
if (debug) console.debug()
|
|
||||||
var importConfig = awConfig.importConfiguration(
|
|
||||||
openConfig.fileUrl.toString().replace("file://", ""),
|
|
||||||
importPlasmoid.checked, importExtensions.checked,
|
|
||||||
importAdds.checked)
|
|
||||||
for (var key in importConfig)
|
|
||||||
plasmoid.configuration[key] = importConfig[key]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value: i18n("Import configuration")
|
||||||
|
onButtonActivated: loadConfigFrom.open()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,5 +4,7 @@ ButtonSelector ./ButtonSelector.qml
|
|||||||
CheckBoxSelector ./CheckBoxSelector.qml
|
CheckBoxSelector ./CheckBoxSelector.qml
|
||||||
ColorSelector ./ColorSelector.qml
|
ColorSelector ./ColorSelector.qml
|
||||||
ComboBoxSelector ./ComboBoxSelector.qml
|
ComboBoxSelector ./ComboBoxSelector.qml
|
||||||
|
ExportDialog ./ExportDialog.qml
|
||||||
|
ImportDialog ./ImportDialog.qml
|
||||||
IntegerSelector ./IntegerSelector.qml
|
IntegerSelector ./IntegerSelector.qml
|
||||||
LineSelector ./LineSelector.qml
|
LineSelector ./LineSelector.qml
|
||||||
|
@ -69,13 +69,12 @@ bool AWConfigHelper::dropCache() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool AWConfigHelper::exportConfiguration(const QObject *nativeConfig,
|
bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
|
||||||
const QString fileName) const
|
const QString fileName) const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Selected filename" << fileName;
|
qCDebug(LOG_AW) << "Selected filename" << fileName;
|
||||||
|
|
||||||
QSettings settings(fileName, QSettings::IniFormat);
|
QSettings settings(fileName, QSettings::IniFormat);
|
||||||
|
|
||||||
// plasmoid configuration
|
// plasmoid configuration
|
||||||
const QQmlPropertyMap *configuration
|
const QQmlPropertyMap *configuration
|
||||||
= static_cast<const QQmlPropertyMap *>(nativeConfig);
|
= static_cast<const QQmlPropertyMap *>(nativeConfig);
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
virtual ~AWConfigHelper();
|
virtual ~AWConfigHelper();
|
||||||
Q_INVOKABLE QString configurationDirectory() const;
|
Q_INVOKABLE QString configurationDirectory() const;
|
||||||
Q_INVOKABLE bool dropCache() const;
|
Q_INVOKABLE bool dropCache() const;
|
||||||
Q_INVOKABLE bool exportConfiguration(const QObject *nativeConfig,
|
Q_INVOKABLE bool exportConfiguration(QObject *nativeConfig,
|
||||||
const QString fileName) const;
|
const QString fileName) const;
|
||||||
Q_INVOKABLE QVariantMap importConfiguration(const QString fileName,
|
Q_INVOKABLE QVariantMap importConfiguration(const QString fileName,
|
||||||
const bool importPlasmoid,
|
const bool importPlasmoid,
|
||||||
|
Loading…
Reference in New Issue
Block a user