Commit ab2192b9 authored by Dimitris Kardarakos's avatar Dimitris Kardarakos

Move components defined in Main to separate files

parent 95b8e1fe
/*
* Copyright 2018 Dimitris Kardarakos <dimkard@posteon.net>
*
* 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 Library 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.
*/
/**
* Creates the list of actions of 'Calendars' action container
*/
function loadGlobalActions(calendars, calendarActions, calendarActionComp) {
var cfgCalendars = calendars.split(calendars.includes(";") ? ";" : null);
var currentChildren = calendarActions.children;
var newChildren = [];
//Preserve non-dynamic actions
for(var i=0; i <currentChildren.length; ++i)
{
if(!(currentChildren[i].hasOwnProperty("isCalendar")))
{
newChildren.push(currentChildren[i]);
}
}
//Add calendars from configuration
for (var i=0; i < cfgCalendars.length; ++i)
{
newChildren.push(calendarActionComp.createObject(calendarActions, { text: cfgCalendars[i] }));
}
calendarActions.children = newChildren;
}
/*
* Copyright 2019 Dimitris Kardarakos <dimkard@posteo.net>
*
* 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 Library 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.0
import org.kde.kirigami 2.4 as Kirigami
import org.kde.phone.calindori 0.1 as Calindori
Kirigami.Action {
property bool isCalendar: true
property var configuration
checked: (text == configuration.activeCalendar)
Kirigami.Action {
text: "Activate"
iconName: "dialog-ok"
onTriggered: {
configuration.activeCalendar = parent.text;
}
}
Kirigami.Action {
text: "Delete"
iconName: "delete"
onTriggered: {
if (configuration.activeCalendar == parent.text) {
showPassiveNotification("Active calendar cannot be deleted");
}
else {
var toRemoveCalendarComponent = Qt.createQmlObject("import org.kde.phone.calindori 0.1 as Calindori; Calindori.LocalCalendar { name: \"" + parent.text + "\"}",root);
toRemoveCalendarComponent.deleteCalendar();
configuration.removeCalendar(parent.text);
showPassiveNotification("Calendar " + parent.text + " has been deleted");
}
}
}
}
......@@ -21,6 +21,7 @@ import QtQuick 2.1
import QtQuick.Layouts 1.2
import org.kde.kirigami 2.0 as Kirigami
import org.kde.phone.calindori 0.1 as Calindori
import "Utils.js" as Utils
Kirigami.ApplicationWindow {
id: root
......@@ -30,34 +31,6 @@ Kirigami.ApplicationWindow {
*/
signal refreshNeeded;
/**
* Creates the list of actions of 'Calendars' action container
*/
function loadGlobalActions() {
var cfgCalendars = calindoriConfig.calendars.split(calindoriConfig.calendars.includes(";") ? ";" : null);
var currentChildren = calendarActions.children;
var newChildren = [];
//Preserve non-dynamic actions
for(var i=0; i <currentChildren.length; ++i)
{
if(!(currentChildren[i].hasOwnProperty("isCalendar")))
{
newChildren.push(currentChildren[i]);
}
}
//Add calendars from configuration
for (var i=0; i < cfgCalendars.length; ++i)
{
newChildren.push(calendarAction.createObject(calendarActions, { text: cfgCalendars[i] }));
}
calendarActions.children = newChildren;
}
onRefreshNeeded: todosView.refreshNeeded()
globalDrawer: Kirigami.GlobalDrawer {
......@@ -82,8 +55,7 @@ Kirigami.ApplicationWindow {
}
}
]
Component.onCompleted: root.loadGlobalActions()
Component.onCompleted: Utils.loadGlobalActions(calindoriConfig.calendars, calendarActions, calendarAction)
}
contextDrawer: Kirigami.ContextDrawer {
......@@ -96,8 +68,8 @@ Kirigami.ApplicationWindow {
Calindori.Config {
id: calindoriConfig
onActiveCalendarChanged: root.loadGlobalActions()
onCalendarsChanged: root.loadGlobalActions()
onActiveCalendarChanged: Utils.loadGlobalActions(calindoriConfig.calendars, calendarActions, calendarAction)
onCalendarsChanged: Utils.loadGlobalActions(calindoriConfig.calendars, calendarActions, calendarAction)
}
Calindori.LocalCalendar {
......@@ -108,41 +80,15 @@ Kirigami.ApplicationWindow {
onNameChanged: root.refreshNeeded()
}
/**
* Action that represents a calendar configuration entry
* It is added dynamically to the global drawer
*/
Component {
id: calendarAction
Kirigami.Action {
property bool isCalendar: true
checked: (text == calindoriConfig.activeCalendar)
Kirigami.Action {
text: "Activate"
iconName: "dialog-ok"
onTriggered: {
calindoriConfig.activeCalendar = parent.text;
}
}
Kirigami.Action {
text: "Delete"
iconName: "delete"
onTriggered: {
if (calindoriConfig.activeCalendar == parent.text) {
showPassiveNotification("Active calendar cannot be deleted");
}
else {
showPassiveNotification("Deleting calendar " + parent.text);
var toRemoveCalendarComponent = Qt.createQmlObject("import org.kde.phone.calindori 0.1 as Calindori; Calindori.LocalCalendar { name: \"" + parent.text + "\"}",root);
toRemoveCalendarComponent.deleteCalendar();
calindoriConfig.removeCalendar(parent.text);
}
}
}
CalendarAction {
configuration: calindoriConfig
}
}
......
......@@ -11,5 +11,7 @@
<file alias="TimePicker.qml">contents/ui/kirigami-playground/TimePicker.qml</file>
<file alias="ClockElement.qml">contents/ui/kirigami-playground/ClockElement.qml</file>
<file alias="CalendarInputPage.qml">contents/ui/CalendarInputPage.qml</file>
<file alias="Utils.js">contents/code/Utils.js</file>
<file alias="CalendarAction.qml">contents/ui/CalendarAction.qml</file>
</qresource>
</RCC>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment