diff --git a/sources/awesome-widget/package/contents/ui/ExportDialog.qml b/sources/awesome-widget/package/contents/ui/ExportDialog.qml new file mode 100644 index 0000000..db136d5 --- /dev/null +++ b/sources/awesome-widget/package/contents/ui/ExportDialog.qml @@ -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() + } +} diff --git a/sources/awesome-widget/package/contents/ui/ImportDialog.qml b/sources/awesome-widget/package/contents/ui/ImportDialog.qml new file mode 100644 index 0000000..0ebdaad --- /dev/null +++ b/sources/awesome-widget/package/contents/ui/ImportDialog.qml @@ -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() + } +} diff --git a/sources/awesome-widget/package/contents/ui/advanced.qml b/sources/awesome-widget/package/contents/ui/advanced.qml index 41f3707..bbe344c 100644 --- a/sources/awesome-widget/package/contents/ui/advanced.qml +++ b/sources/awesome-widget/package/contents/ui/advanced.qml @@ -198,95 +198,27 @@ Item { onButtonActivated: awActions.dropCache() } - Row { - height: implicitHeight - 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 { + ButtonSelector { + ExportDialog { id: saveConfigAs - selectExisting: false - 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() - } + configuration: plasmoid.configuration } - QtDialogs.MessageDialog { - id: messageDialog - standardButtons: QtDialogs.StandardButton.Ok - } + value: i18n("Export configuration") + onButtonActivated: saveConfigAs.open() } - Row { - height: implicitHeight - width: parent.width - QtControls.Label { - height: parent.height - width: parent.width * 2 / 5 - } - 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] + ButtonSelector { + ImportDialog { + id: loadConfigFrom + onConfigurationReceived: { + for (var key in configuration) + plasmoid.configuration[key] = configuration[key] } } + + value: i18n("Import configuration") + onButtonActivated: loadConfigFrom.open() } } diff --git a/sources/awesome-widget/package/contents/ui/qmldir b/sources/awesome-widget/package/contents/ui/qmldir index 47d9e93..3cc294b 100644 --- a/sources/awesome-widget/package/contents/ui/qmldir +++ b/sources/awesome-widget/package/contents/ui/qmldir @@ -4,5 +4,7 @@ ButtonSelector ./ButtonSelector.qml CheckBoxSelector ./CheckBoxSelector.qml ColorSelector ./ColorSelector.qml ComboBoxSelector ./ComboBoxSelector.qml +ExportDialog ./ExportDialog.qml +ImportDialog ./ImportDialog.qml IntegerSelector ./IntegerSelector.qml LineSelector ./LineSelector.qml diff --git a/sources/awesome-widget/plugin/awconfighelper.cpp b/sources/awesome-widget/plugin/awconfighelper.cpp index edcb201..91b37f7 100644 --- a/sources/awesome-widget/plugin/awconfighelper.cpp +++ b/sources/awesome-widget/plugin/awconfighelper.cpp @@ -69,13 +69,12 @@ bool AWConfigHelper::dropCache() const } -bool AWConfigHelper::exportConfiguration(const QObject *nativeConfig, +bool AWConfigHelper::exportConfiguration(QObject *nativeConfig, const QString fileName) const { qCDebug(LOG_AW) << "Selected filename" << fileName; QSettings settings(fileName, QSettings::IniFormat); - // plasmoid configuration const QQmlPropertyMap *configuration = static_cast(nativeConfig); diff --git a/sources/awesome-widget/plugin/awconfighelper.h b/sources/awesome-widget/plugin/awconfighelper.h index 4a71956..6747155 100644 --- a/sources/awesome-widget/plugin/awconfighelper.h +++ b/sources/awesome-widget/plugin/awconfighelper.h @@ -35,7 +35,7 @@ public: virtual ~AWConfigHelper(); Q_INVOKABLE QString configurationDirectory() const; Q_INVOKABLE bool dropCache() const; - Q_INVOKABLE bool exportConfiguration(const QObject *nativeConfig, + Q_INVOKABLE bool exportConfiguration(QObject *nativeConfig, const QString fileName) const; Q_INVOKABLE QVariantMap importConfiguration(const QString fileName, const bool importPlasmoid,