diff --git a/src/controls/ApplicationWindow.qml b/src/controls/ApplicationWindow.qml index eab02f9..bd41913 100644 --- a/src/controls/ApplicationWindow.qml +++ b/src/controls/ApplicationWindow.qml @@ -1,585 +1,521 @@ /* * Copyright 2018 Camilo Higuita * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program 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 Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.9 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 import QtQuick.Window 2.3 import org.kde.kirigami 2.7 as Kirigami import org.kde.mauikit 1.0 as Maui import QtQuick.Controls.Material 2.1 import "private" Kirigami.AbstractApplicationWindow { - id: root - visible: true - width: Screen.width * (isMobile ? 1 : 0.4) - height: Screen.height * (isMobile ? 1 : 0.4) - -// contentItem.anchors.leftMargin: root.globalDrawer && (root.globalDrawer.modal === false) ? root.globalDrawer.contentItem.width * root.globalDrawer.position : 0 -// contentItem.anchors.left: contentItem.parent.left - // contentItem.anchors.right: contentItem.parent.right -// contentItem.anchors.rightMargin: 0 + id: root + visible: true + width: Screen.width * (isMobile ? 1 : 0.4) + height: Screen.height * (isMobile ? 1 : 0.4) property bool showAccounts : true - + /***************************************************/ - /******************** ALIASES *********************/ - /*************************************************/ - property alias headBar : _headBar - property alias footBar: _footBar - property alias dialog: dialogLoader.item - - property alias leftIcon : menuBtn - property alias rightIcon : searchBtn - - property alias mainMenu : mainMenu.contentData - property alias about : aboutDialog - property alias accounts: _accountsDialogLoader.item - property var currentAccount: ({}) - property alias notifyDialog: _notify - - - //redefines here as here we can know a pointer to PageRow - wideScreen: isWide - - - /***************************************************/ - /*********************** UI ***********************/ - /*************************************************/ - - property bool isWide : root.width >= Kirigami.Units.gridUnit * 30 - - property int radiusV : unit * 4 - property int iconSize : iconSizes.medium * (isMobile ? 0.95 : 1) - - readonly property int unit : Maui.Style.unit - readonly property int rowHeight: Maui.Style.rowHeight - readonly property int rowHeightAlt: Maui.Style.rowHeightAlt - - readonly property int toolBarHeight: Maui.Style.toolBarHeight - readonly property int toolBarHeightAlt: Maui.Style.toolBarHeightAlt - - readonly property int contentMargins: space.medium - readonly property var fontSizes: Maui.Style.fontSizes - readonly property var space : Maui.Style.space - readonly property var iconSizes : Maui.Style.iconSizes - - property string colorSchemeName : Qt.application.name - - /***************************************************/ - /********************* COLORS *********************/ - /*************************************************/ + /******************** ALIASES *********************/ + /*************************************************/ + property alias headBar : _headBar + property alias footBar: _footBar + property alias dialog: dialogLoader.item + + property alias leftIcon : menuBtn + property alias rightIcon : searchBtn + + property alias mainMenu : mainMenu.contentData + property alias about : aboutDialog + property alias accounts: _accountsDialogLoader.item + property var currentAccount: Maui.App.accounts.currentAccount + property alias notifyDialog: _notify + + //redefines here as here we can know a pointer to PageRow + wideScreen: isWide + + /***************************************************/ + /*********************** UI ***********************/ + /*************************************************/ + + property bool isWide : root.width >= Kirigami.Units.gridUnit * 30 + + property int radiusV : unit * 4 + property int iconSize : iconSizes.medium * (isMobile ? 0.95 : 1) + + readonly property int unit : Maui.Style.unit + readonly property int rowHeight: Maui.Style.rowHeight + readonly property int rowHeightAlt: Maui.Style.rowHeightAlt + + readonly property int toolBarHeight: Maui.Style.toolBarHeight + readonly property int toolBarHeightAlt: Maui.Style.toolBarHeightAlt + + readonly property int contentMargins: space.medium + readonly property var fontSizes: Maui.Style.fontSizes + readonly property var space : Maui.Style.space + readonly property var iconSizes : Maui.Style.iconSizes + + property string colorSchemeName : Qt.application.name + + /***************************************************/ + /********************* COLORS *********************/ + /*************************************************/ readonly property var colorScheme: ({ Default : 1, Light : 2, Dark: 3, Custom: 4 }) - -// property color borderColor: Qt.tint(textColor, Qt.rgba(backgroundColor.r, backgroundColor.g, -// backgroundColor.b, 0.7)) -// property color backgroundColor: Maui.Style.backgroundColor -// property color textColor: Maui.Style.textColor -// property color highlightColor: Maui.Style.highlightColor -// property color highlightedTextColor: Maui.Style.highlightedTextColor -// property color buttonBackgroundColor: Maui.Style.buttonBackgroundColor -// property color viewBackgroundColor: Maui.Style.viewBackgroundColor -// property color altColor: Maui.Style.altColor -// property color altColorText: Maui.Style.altColorText -// property color accentColor : buttonBackgroundColor -// -// property color bgColor: Kirigami.Theme.viewBackgroundColor - property color headBarBGColor: Kirigami.Theme.backgroundColor - property color headBarFGColor: Kirigami.Theme.textColor - -// readonly property string darkBorderColor: Qt.darker(darkBackgroundColor, 1.5) -// readonly property string darkBackgroundColor: "#303030" -// readonly property string darkTextColor: "#FAFAFA" -// readonly property string darkHighlightColor: "#29B6F6" -// readonly property string darkHighlightedTextColor: darkTextColor -// readonly property string darkViewBackgroundColor: "#212121" -// readonly property string darkDarkColor: "#191919" -// readonly property string darkButtonBackgroundColor : "#191919" -// readonly property color darkAltColor: "#333" -// readonly property color darkAltColorText: darkTextColor -// readonly property color darkAccentColor : darkButtonBackgroundColor -// readonly property color darkBgColor: darkBackgroundColor - - - property color warningColor : Maui.Style.warningColor - property color dangerColor : Maui.Style.dangerColor - property color infoColor : Maui.Style.infoColor - property color suggestedColor : Maui.Style.suggestedColor - - /* ANDROID THEMING*/ - -// Material.theme: Material.Light -// Material.accent: Kirigami.Theme.highlightColor -// Material.background: headBarBGColor -// Material.primary: headBarBGColor -// Material.foreground: Kirigami.Theme.textColor - - /***************************************************/ - /**************** READONLY PROPS ******************/ - /*************************************************/ - - readonly property bool isMobile : Kirigami.Settings.isMobile - readonly property bool isAndroid: Qt.platform.os == "android" - - readonly property real screenWidth : Screen.width - readonly property real screenHeight : Screen.height - - /***************************************************/ - /********************* PROPS **********************/ - /*************************************************/ - - property alias searchButton : searchBtn - property alias menuButton : menuBtn - - /***************************************************/ - /******************** SIGNALS *********************/ - /*************************************************/ - signal menuButtonClicked(); - signal searchButtonClicked(); + + property color headBarBGColor: Kirigami.Theme.backgroundColor + property color headBarFGColor: Kirigami.Theme.textColor + property color warningColor : Maui.Style.warningColor + property color dangerColor : Maui.Style.dangerColor + property color infoColor : Maui.Style.infoColor + property color suggestedColor : Maui.Style.suggestedColor + + /* ANDROID THEMING*/ + + // Material.theme: Material.Light + // Material.accent: Kirigami.Theme.highlightColor + // Material.background: headBarBGColor + // Material.primary: headBarBGColor + // Material.foreground: Kirigami.Theme.textColor + + /***************************************************/ + /**************** READONLY PROPS ******************/ + /*************************************************/ + + readonly property bool isMobile : Kirigami.Settings.isMobile + readonly property bool isAndroid: Qt.platform.os == "android" + + readonly property real screenWidth : Screen.width + readonly property real screenHeight : Screen.height + + /***************************************************/ + /********************* PROPS **********************/ + /*************************************************/ + + property alias searchButton : searchBtn + property alias menuButton : menuBtn + + /***************************************************/ + /******************** SIGNALS *********************/ + /*************************************************/ + signal menuButtonClicked(); + signal searchButtonClicked(); signal goBackTriggered(); signal goFowardTriggered(); - // overlay.modal: Rectangle - // { - // color: Color.transparent(altColor, 0.5) - // } - - - // overlay.modeless: Rectangle { - // color: "transparent" - // } + // overlay.modal: Rectangle + // { + // color: Color.transparent(altColor, 0.5) + // } + + + // overlay.modeless: Rectangle { + // color: "transparent" + // } + - onClosing: { if(!isMobile) { var height = root.height var width = root.width var x = root.x var y = root.y Maui.FM.saveSettings("GEOMETRY", Qt.rect(x, y, width, height), "WINDOW") } } property bool isPortrait: Screen.primaryOrientation === Qt.PortraitOrientation || Screen.primaryOrientation === Qt.InvertedPortraitOrientation onIsPortraitChanged: { if(isPortrait) { - console.log("PORTARIT MODE CHANGED") - width: Screen.width - height: Screen.height + console.log("PORTARIT MODE CHANGED") + width: Screen.width + height: Screen.height } } -// onHeadBarBGColorChanged: -// { -// if(!isMobile && colorSchemeName.length > 0) -// Maui.KDE.setColorScheme(colorSchemeName, headBarBGColor, headBarFGColor) -// else if(isAndroid && headBar.position === ToolBar.Header) -// Maui.Android.statusbarColor(headBarBGColor, false) -// else if(isAndroid && headBar.position === ToolBar.Footer) -// Maui.Android.statusbarColor(Kirigami.Theme.viewBackgroundColor, true) -// -// } -// -// onHeadBarFGColorChanged: -// { -// if(!isAndroid && !isMobile && colorSchemeName.length > 0 && headBar.position === ToolBar.Header) -// Maui.KDE.setColorScheme(colorSchemeName, headBarBGColor, headBarFGColor) -// else if(isAndroid && headBar.position === ToolBar.Header) -// Maui.Android.statusbarColor(headBarBGColor, false) -// else if(isAndroid && headBar.position === ToolBar.Footer) -// Maui.Android.statusbarColor(Kirigami.Theme.viewBackgroundColor, true) -// } - /* - background: Rectangle - { - color: bgColor - } - */ - -// globalDrawer.height: root.height - headBar.height -// globalDrawer.y: headBar.height - + // onHeadBarBGColorChanged: + // { + // if(!isMobile && colorSchemeName.length > 0) + // Maui.KDE.setColorScheme(colorSchemeName, headBarBGColor, headBarFGColor) + // else if(isAndroid && headBar.position === ToolBar.Header) + // Maui.Android.statusbarColor(headBarBGColor, false) + // else if(isAndroid && headBar.position === ToolBar.Footer) + // Maui.Android.statusbarColor(Kirigami.Theme.viewBackgroundColor, true) + // + // } + // + // onHeadBarFGColorChanged: + // { + // if(!isAndroid && !isMobile && colorSchemeName.length > 0 && headBar.position === ToolBar.Header) + // Maui.KDE.setColorScheme(colorSchemeName, headBarBGColor, headBarFGColor) + // else if(isAndroid && headBar.position === ToolBar.Header) + // Maui.Android.statusbarColor(headBarBGColor, false) + // else if(isAndroid && headBar.position === ToolBar.Footer) + // Maui.Android.statusbarColor(Kirigami.Theme.viewBackgroundColor, true) + // } + /* + * background: Rectangle + * { + * color: bgColor +} +*/ - property QtObject mheadBar : Maui.ToolBar { id: _headBar visible: count > 1 position: ToolBar.Header width: root.width -// Kirigami.Theme.backgroundColor: headBarBGColor -// Kirigami.Theme.textColor: headBarFGColor -// Kirigami.Theme.inherit: true + // Kirigami.Theme.backgroundColor: headBarBGColor + // Kirigami.Theme.textColor: headBarFGColor + // Kirigami.Theme.inherit: true leftContent: [ ToolButton { id: menuBtn icon.name: "application-menu" icon.color: headBarFGColor icon.width: iconSizes.medium icon.height: iconSizes.medium checked: mainMenu.visible onClicked: { - + menuButtonClicked() mainMenu.visible ? mainMenu.close() : mainMenu.popup(parent, parent.x , parent.height+ space.medium) } Menu { id: mainMenu modal: true z: 999 width: unit * 200 Item { height: _accountCombobox.visible ? _accountCombobox.implicitHeight + space.big: 0 anchors { left: parent.left right: parent.right top: parent.top margins: space.medium } ComboBox { id: _accountCombobox anchors.centerIn: parent // parent: mainMenu popup.z: 999 width: parent.width -// visible: (count > 1) && showAccounts + // visible: (count > 1) && showAccounts textRole: "user" flat: true model: Maui.BaseModel { list: Maui.App.accounts } - onActivated: + onActivated: Maui.App.accounts.currentAccountIndex = index; + + Component.onCompleted: { - var account = accounts.list.get(index) - root.currentAccount = account - console.log(currentAccount.user, currentAccount.password, currentAccount.server) + if(_accountCombobox.count > 0) + { + _accountCombobox.currentIndex = 0 + Maui.App.accounts.currentAccountIndex = _accountCombobox.currentIndex + } } - // icon.name: "user-identity" - // iconButton.isMask: false } } MenuItem { text: qsTr("Accounts") visible: root.showAccounts icon.name: "list-add-user" onTriggered: { if(root.accounts) accounts.open() } } MenuSeparator { visible: _accountCombobox.visible } MenuItem { text: qsTr("About") icon.name: "documentinfo" onTriggered: aboutDialog.open() } } }, Kirigami.Separator { visible: menuBtn.visible Layout.preferredHeight: 16 opacity: 0.5 width: visible ? 2 : 0 } ] rightContent: ToolButton { id: searchBtn icon.name: "edit-find" icon.color: headBarFGColor onClicked: searchButtonClicked() } } property QtObject mfootBar : Maui.ToolBar { id: _footBar visible: count position: ToolBar.Footer width: root.width -// Kirigami.Theme.backgroundColor: Kirigami.Theme.backgroundColor + // Kirigami.Theme.backgroundColor: Kirigami.Theme.backgroundColor } header: headBar.count && headBar.position === ToolBar.Header ? headBar : undefined footer: Column { id: _footer visible : children > 0 children: { if(headBar.position === ToolBar.Footer && headBar.count && footBar.count) return [footBar , headBar] else if(headBar.position === ToolBar.Footer && headBar.count) return [headBar] else if(footBar.count) return [footBar] else return [] } } - - Maui.AboutDialog - { - id: aboutDialog - } - - Loader - { + + Maui.AboutDialog + { + id: aboutDialog + } + + Loader + { id: _accountsDialogLoader sourceComponent: root.showAccounts ? _accountsDialogComponent : undefined } Component { id: _accountsDialogComponent AccountsHelper {} } Maui.Dialog { id: _notify property var cb : ({}) verticalAlignment: Qt.AlignTop - defaultButtons: false -// colorScheme.backgroundColor: altColor -// colorScheme.textColor: altColorText - - maxHeight: Math.max(unit * 120, (_notifyLayout.implicitHeight)) - maxWidth: isMobile ? parent.width * 0.9 : unit * 500 - - Timer - { - id: _notifyTimer - onTriggered: _notify.close() - } - - onClosed: _notifyTimer.stop() - - MouseArea - { - anchors.fill: parent - onClicked: + defaultButtons: false + + maxHeight: Math.max(unit * 120, (_notifyLayout.implicitHeight)) + maxWidth: isMobile ? parent.width * 0.9 : unit * 500 + + Timer { - if(_notify.cb) - _notify.cb() - - _notify.close() + id: _notifyTimer + onTriggered: _notify.close() } - } - - GridLayout - { - anchors.fill: parent - columns: 2 - rows: 1 + onClosed: _notifyTimer.stop() - Item + MouseArea { - Layout.fillHeight: true - Layout.preferredWidth: iconSizes.huge + space.big - Layout.row: 1 - Layout.column: 1 - - ToolButton + anchors.fill: parent + onClicked: { - id: _notifyIcon - icon.width: iconSizes.large - - anchors.centerIn: parent -// isMask: false - } + if(_notify.cb) + _notify.cb() + + _notify.close() + } } - Item + GridLayout { - Layout.fillHeight: true - Layout.fillWidth: true - Layout.row: 1 - Layout.column: 2 + anchors.fill: parent + + columns: 2 + rows: 1 - ColumnLayout + Item { - anchors.fill: parent - id: _notifyLayout + Layout.fillHeight: true + Layout.preferredWidth: iconSizes.huge + space.big + Layout.row: 1 + Layout.column: 1 - Label + ToolButton { - id: _notifyTitle - Layout.fillHeight: true - Layout.fillWidth: true - font.weight: Font.Bold - font.bold: true - font.pointSize: fontSizes.big -// color: _notify.colorScheme.textColor - elide: Qt.ElideRight - wrapMode: Text.Wrap - } + id: _notifyIcon + icon.width: iconSizes.large + anchors.centerIn: parent + } + } + + Item + { + Layout.fillHeight: true + Layout.fillWidth: true + Layout.row: 1 + Layout.column: 2 - Label + ColumnLayout { - id: _notifyBody - Layout.fillHeight: true - Layout.fillWidth: true - font.pointSize: fontSizes.default -// color: _notify.colorScheme.textColor - elide: Qt.ElideRight - wrapMode: Text.Wrap + anchors.fill: parent + id: _notifyLayout + + Label + { + id: _notifyTitle + Layout.fillHeight: true + Layout.fillWidth: true + font.weight: Font.Bold + font.bold: true + font.pointSize: fontSizes.big + // color: _notify.colorScheme.textColor + elide: Qt.ElideRight + wrapMode: Text.Wrap + } + + Label + { + id: _notifyBody + Layout.fillHeight: true + Layout.fillWidth: true + font.pointSize: fontSizes.default + // color: _notify.colorScheme.textColor + elide: Qt.ElideRight + wrapMode: Text.Wrap + } } } } - } - - function show(callback) - { - _notify.cb = callback - _notifyTimer.start() - - _notify.open() - } + + function show(callback) + { + _notify.cb = callback + _notifyTimer.start() + + _notify.open() + } } Loader { id: dialogLoader } - - Component.onCompleted: - { - if(isAndroid && headBar.position === ToolBar.Footer) - Maui.Android.statusbarColor(Kirigami.Theme.backgroundColor, true) - - if(!isMobile) - { - var rect = Maui.FM.loadSettings("GEOMETRY", "WINDOW", Qt.rect(root.x, root.y, root.width, root.height)) - root.x = rect.x - root.y = rect.y - root.width = rect.width - root.height = rect.height - - } - - } - -// Connections -// { -// target: Maui.FM -// -// onNewItem: notify("dialog-information", qsTr("File uploaded"), "Your file has been uploaded to your account /n"+path) -// onWarningMessage: notify("dialog-information", "Oops!", message) -// } - - function switchColorScheme(variant) - { -// switch(variant) -// { -// case colorScheme.Default: -// -// backgroundColor = Maui.Style.backgroundColor -// textColor = Maui.Style.textColor -// highlightColor = Maui.Style.highlightColor -// highlightedTextColor = Maui.Style.highlightedTextColor -// buttonBackgroundColor = Maui.Style.buttonBackgroundColor -// viewBackgroundColor = Maui.Style.viewBackgroundColor -// altColor = Maui.Style.altColor -// borderColor = Maui.Style.borderColor -// if(isAndroid) Maui.Android.statusbarColor(backgroundColor, true) -// break -// -// case colorScheme.Dark: -// borderColor = darkBorderColor -// backgroundColor = darkBackgroundColor -// textColor = darkTextColor -// highlightColor = darkHighlightColor -// highlightedTextColor = darkHighlightedTextColor -// buttonBackgroundColor = darkButtonBackgroundColor -// viewBackgroundColor = darkViewBackgroundColor -// altColor = darkDarkColor -// altColorText = darkAltColorText -// bgColor =darkBgColor -// -// if(isAndroid) Maui.Android.statusbarColor(backgroundColor, false) -// break -// } - } - - function notify(icon, title, body, callback, timeout) + + Component.onCompleted: + { + if(isAndroid && headBar.position === ToolBar.Footer) + Maui.Android.statusbarColor(Kirigami.Theme.backgroundColor, true) + + if(!isMobile) + { + var rect = Maui.FM.loadSettings("GEOMETRY", "WINDOW", Qt.rect(root.x, root.y, root.width, root.height)) + root.x = rect.x + root.y = rect.y + root.width = rect.width + root.height = rect.height + + } + + } + + function switchColorScheme(variant) { - _notifyIcon.icon.name = icon + // switch(variant) + // { + // case colorScheme.Default: + // + // backgroundColor = Maui.Style.backgroundColor + // textColor = Maui.Style.textColor + // highlightColor = Maui.Style.highlightColor + // highlightedTextColor = Maui.Style.highlightedTextColor + // buttonBackgroundColor = Maui.Style.buttonBackgroundColor + // viewBackgroundColor = Maui.Style.viewBackgroundColor + // altColor = Maui.Style.altColor + // borderColor = Maui.Style.borderColor + // if(isAndroid) Maui.Android.statusbarColor(backgroundColor, true) + // break + // + // case colorScheme.Dark: + // borderColor = darkBorderColor + // backgroundColor = darkBackgroundColor + // textColor = darkTextColor + // highlightColor = darkHighlightColor + // highlightedTextColor = darkHighlightedTextColor + // buttonBackgroundColor = darkButtonBackgroundColor + // viewBackgroundColor = darkViewBackgroundColor + // altColor = darkDarkColor + // altColorText = darkAltColorText + // bgColor =darkBgColor + // + // if(isAndroid) Maui.Android.statusbarColor(backgroundColor, false) + // break + // } + } + + function notify(icon, title, body, callback, timeout) + { + _notifyIcon.icon.name = icon _notifyTitle.text = title _notifyBody.text = body _notifyTimer.interval = timeout ? timeout : 2500 _notify.show(callback) } - - /** FUNCTIONS **/ - // function riseContent() - // { - // if(allowRiseContent) - // flickable.flick(0, flickable.contentHeight* -2) - // } - - // function dropContent() - // { - // if(allowRiseContent) - // flickable.flick(0, flickable.contentHeight* 2) - - // } } diff --git a/src/utils/mauiaccounts.cpp b/src/utils/mauiaccounts.cpp index dc19e5f..798c82d 100644 --- a/src/utils/mauiaccounts.cpp +++ b/src/utils/mauiaccounts.cpp @@ -1,108 +1,108 @@ /* * * Copyright (C) 2019 camilo * * This program 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. * * This program 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 this program. If not, see . */ #include "utils/mauiaccounts.h" #include "fm.h" MauiAccounts::MauiAccounts(QObject *parent) : MauiList(parent), fm(new FM(this)) { this->setAccounts(); } MauiAccounts::~MauiAccounts() { } FMH::MODEL_LIST MauiAccounts::items() const { return this->m_data; } void MauiAccounts::setAccounts() { emit this->preListChanged(); this->m_data = this->fm->getCloudAccounts(); qDebug()<< "ACCOUNTS LIST"<< this->m_data; this->m_count = this->m_data.count(); emit this->countChanged(this->m_count); emit this->postListChanged(); } int MauiAccounts::getCurrentAccountIndex() const { return this->m_currentAccountIndex; } -ACCOUNT MauiAccounts::getCurrentAccount() const +QVariantMap MauiAccounts::getCurrentAccount() const { return this->m_currentAccount; } -void MauiAccounts::registerAccount(const ACCOUNT& account) +void MauiAccounts::registerAccount(const QVariantMap& account) { // register the account to the backend needed auto model = FMH::toModel(account); if(this->fm->addCloudAccount(model[FMH::MODEL_KEY::SERVER], model[FMH::MODEL_KEY::USER], model[FMH::MODEL_KEY::PASSWORD])) { this->setAccounts(); } } void MauiAccounts::setCurrentAccountIndex(const int& index) { if(index >= this->m_data.size() || index < 0) return; //make sure the account exists this->m_currentAccountIndex = index; this->m_currentAccount = FMH::toMap(this->m_data.at(m_currentAccountIndex)); emit this->currentAccountChanged(this->m_currentAccount); emit this->currentAccountIndexChanged(this->m_currentAccountIndex); } QVariantMap MauiAccounts::get(const int& index) const { if(index >= this->m_data.size() || index < 0) return QVariantMap(); return FMH::toMap(this->m_data.at(index)); } uint MauiAccounts::getCount() const { return this->m_count; } void MauiAccounts::refresh() { this->setAccounts(); } void MauiAccounts::removeAccount(const int& index) { //todo } void MauiAccounts::removeAccountAndFiles(const int& index) { //todo } diff --git a/src/utils/mauiaccounts.h b/src/utils/mauiaccounts.h index 0d75283..ef3357e 100644 --- a/src/utils/mauiaccounts.h +++ b/src/utils/mauiaccounts.h @@ -1,93 +1,93 @@ /* * * Copyright (C) 2019 camilo * * This program 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. * * This program 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 this program. If not, see . */ #ifndef MAUIACCOUNTS_H #define MAUIACCOUNTS_H #include /** * MauiAccounts * provides an interface to access the system registered accounts, * the current active account and a bridge to add account data to the host system backend solution. * This properties and functions are exposed to * all the Maui Applications that might want to use the accounts */ typedef QVariantMap ACCOUNT; class FM; class MauiAccounts : public MauiList { Q_OBJECT Q_PROPERTY(int currentAccountIndex READ getCurrentAccountIndex WRITE setCurrentAccountIndex NOTIFY currentAccountIndexChanged) - Q_PROPERTY(ACCOUNT currentAccount READ getCurrentAccount NOTIFY currentAccountChanged) + Q_PROPERTY(QVariantMap currentAccount READ getCurrentAccount NOTIFY currentAccountChanged) Q_PROPERTY(uint count READ getCount NOTIFY countChanged) public: /** * Default constructor */ MauiAccounts(QObject *parent = nullptr); /** * Destructor */ ~MauiAccounts(); /** * @todo write docs * * @return TODO */ FMH::MODEL_LIST items() const final override; void setCurrentAccountIndex(const int &index); int getCurrentAccountIndex() const; - ACCOUNT getCurrentAccount() const; + QVariantMap getCurrentAccount() const; uint getCount() const; public slots: QVariantMap get(const int &index) const; - void registerAccount(const ACCOUNT &account); + void registerAccount(const QVariantMap &account); void removeAccount(const int &index); void removeAccountAndFiles(const int &index); void refresh(); private: FM *fm; FMH::MODEL_LIST m_data; - ACCOUNT m_currentAccount; + QVariantMap m_currentAccount; int m_currentAccountIndex = 1; uint m_count = 0; void setAccounts(); signals: - void currentAccountChanged(ACCOUNT account); + void currentAccountChanged(QVariantMap account); void currentAccountIndexChanged(int index); void countChanged(uint count); }; #endif // MAUIACCOUNTS_H