Add import and export dialogs

This commit is contained in:
Evgenii Alekseev 2016-09-30 10:22:10 +03:00
parent 31c129163b
commit 3ee1d4c30e
6 changed files with 148 additions and 85 deletions

View 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()
}
}

View 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()
}
}

View File

@ -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()
}
}

View File

@ -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

View File

@ -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<const QQmlPropertyMap *>(nativeConfig);

View File

@ -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,