Commit ba66159b authored by Dimitris Kardarakos's avatar Dimitris Kardarakos

Offer calendar deletion functionality and simplify actions' dynamic creation

parent c14f532e
......@@ -30,32 +30,34 @@ 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 = [];
for (var i=0; i < cfgCalendars.length; ++i)
//Preserve non-dynamic actions
for(var i=0; i <currentChildren.length; ++i)
{
var isActive = (cfgCalendars[i] == calindoriConfig.activeCalendar);
if(!calendarActionExists(cfgCalendars[i]))
if(!(currentChildren[i].hasOwnProperty("isCalendar")))
{
calendarActions.children.push(calendarAction.createObject(calendarActions, { text: cfgCalendars[i] }));
newChildren.push(currentChildren[i]);
}
}
}
function calendarActionExists(name)
{
for(var i=0; i < calendarActions.children.length; ++i)
//Add calendars from configuration
for (var i=0; i < cfgCalendars.length; ++i)
{
if(calendarActions.children[i].hasOwnProperty("type") && calendarActions.children[i].type == "calendar" && calendarActions.children[i].text == name)
{
return true;
}
newChildren.push(calendarAction.createObject(calendarActions, { text: cfgCalendars[i] }));
}
return false;
calendarActions.children = newChildren;
}
onRefreshNeeded: todosView.refreshNeeded()
globalDrawer: Kirigami.GlobalDrawer {
......@@ -110,7 +112,7 @@ Kirigami.ApplicationWindow {
Kirigami.Action {
property string type: "calendar"
property bool isCalendar: true
checked: (text == calindoriConfig.activeCalendar)
......
......@@ -99,9 +99,13 @@ QString CalindoriConfig::addCalendar(const QString & calendar)
void CalindoriConfig::removeCalendar(const QString& calendar)
{
//TODO: IMPLEMENT
qDebug() << "Removing calendar " << calendar;
emit calendarsChanged();
QStringList calendarsList = d->config.group("general").readEntry("calendars", QString()).split(";");
if(calendarsList.contains(calendar))
{
qDebug() << "Removing calendar " << calendar;
calendarsList.removeAll(calendar);
d->config.group("general").writeEntry("calendars", calendarsList.join(";"));
d->config.sync();
emit calendarsChanged();
}
}
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