Commit 69f5d6a3 authored by Dimitris Kardarakos's avatar Dimitris Kardarakos

Set default start date and duration for events

When the user creates a new event, the start time is set to the next
hour; e.g. if the current time is 13.30, the start time of the event is set to
14.00. The event duration is set to 60 minutes; thus, the end date time of
the event will be set to 15.00. The user may change the default event duration
in application settings.
parent 77e107cf
Pipeline #19299 passed with stage
in 11 minutes and 47 seconds
/* /*
* Copyright (C) 2019 Dimitris Kardarakos * Copyright (C) 2019-2020 Dimitris Kardarakos
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
...@@ -67,7 +67,7 @@ void CalindoriConfig::setActiveCalendar(const QString & calendar) ...@@ -67,7 +67,7 @@ void CalindoriConfig::setActiveCalendar(const QString & calendar)
{ {
d->config.group("general").writeEntry("activeCalendar", calendar); d->config.group("general").writeEntry("activeCalendar", calendar);
d->config.sync(); d->config.sync();
emit activeCalendarChanged(); Q_EMIT activeCalendarChanged();
} }
QVariantMap CalindoriConfig::canAddCalendar(const QString& calendar) QVariantMap CalindoriConfig::canAddCalendar(const QString& calendar)
...@@ -129,7 +129,7 @@ QVariantMap CalindoriConfig::addCalendar(const QString & calendar) ...@@ -129,7 +129,7 @@ QVariantMap CalindoriConfig::addCalendar(const QString & calendar)
d->config.group("general").writeEntry("calendars", calendarsList.join(";")); d->config.group("general").writeEntry("calendars", calendarsList.join(";"));
d->config.sync(); d->config.sync();
emit calendarsChanged(); Q_EMIT calendarsChanged();
return result; return result;
} }
...@@ -147,7 +147,7 @@ void CalindoriConfig::removeCalendar(const QString& calendar) ...@@ -147,7 +147,7 @@ void CalindoriConfig::removeCalendar(const QString& calendar)
d->config.group("general").writeEntry("calendars", calendarsList.join(";")); d->config.group("general").writeEntry("calendars", calendarsList.join(";"));
d->config.sync(); d->config.sync();
emit calendarsChanged(); Q_EMIT calendarsChanged();
} }
} }
...@@ -171,3 +171,16 @@ QString CalindoriConfig::filenameToPath(const QString& calendarName) ...@@ -171,3 +171,16 @@ QString CalindoriConfig::filenameToPath(const QString& calendarName)
return basePath + "/calindori_" + calendarName + ".ics"; return basePath + "/calindori_" + calendarName + ".ics";
} }
int CalindoriConfig::eventsDuration() const
{
return d->config.group("events").readEntry("duration", 60);
}
void CalindoriConfig::setEventsDuration(int duration)
{
d->config.group("events").writeEntry("duration", duration);
d->config.sync();
Q_EMIT eventsDurationChanged();
}
/* /*
* Copyright (C) 2019 Dimitris Kardarakos * Copyright (C) 2019-2020 Dimitris Kardarakos
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
...@@ -27,6 +27,8 @@ class CalindoriConfig : public QObject ...@@ -27,6 +27,8 @@ class CalindoriConfig : public QObject
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString calendars READ calendars NOTIFY calendarsChanged) Q_PROPERTY(QString calendars READ calendars NOTIFY calendarsChanged)
Q_PROPERTY(QString activeCalendar READ activeCalendar WRITE setActiveCalendar NOTIFY activeCalendarChanged) Q_PROPERTY(QString activeCalendar READ activeCalendar WRITE setActiveCalendar NOTIFY activeCalendarChanged)
Q_PROPERTY(int eventsDuration READ eventsDuration WRITE setEventsDuration NOTIFY eventsDurationChanged)
public: public:
explicit CalindoriConfig(QObject* parent = nullptr); explicit CalindoriConfig(QObject* parent = nullptr);
...@@ -40,6 +42,10 @@ public: ...@@ -40,6 +42,10 @@ public:
void setActiveCalendar(const QString& calendar); void setActiveCalendar(const QString& calendar);
Q_SIGNAL void activeCalendarChanged(); Q_SIGNAL void activeCalendarChanged();
int eventsDuration() const;
void setEventsDuration(int duration);
Q_SIGNAL void eventsDurationChanged();
public Q_SLOTS: public Q_SLOTS:
QVariantMap canAddCalendar(const QString& calendar); QVariantMap canAddCalendar(const QString& calendar);
QVariantMap addCalendar(const QString& calendar); QVariantMap addCalendar(const QString& calendar);
......
...@@ -51,12 +51,12 @@ Controls2.SwipeView { ...@@ -51,12 +51,12 @@ Controls2.SwipeView {
onNextMonth: { onNextMonth: {
mm.goNextMonth(); mm.goNextMonth();
root.selectedDate = new Date(mm.year, mm.month-1, 1); root.selectedDate = new Date(mm.year, mm.month-1, 1, root.selectedDate.getHours(), root.selectedDate.getMinutes());
} }
onPreviousMonth: { onPreviousMonth: {
mm.goPreviousMonth(); mm.goPreviousMonth();
root.selectedDate = new Date(mm.year, mm.month-1, 1); root.selectedDate = new Date(mm.year, mm.month-1, 1, root.selectedDate.getHours(), root.selectedDate.getMinutes());
} }
onGoToday: { onGoToday: {
......
...@@ -104,6 +104,13 @@ Kirigami.GlobalDrawer { ...@@ -104,6 +104,13 @@ Kirigami.GlobalDrawer {
}, },
Kirigami.Action {
text: i18n("Settings")
iconName: "settings-configure"
onTriggered: pageStack.push(settingsPage)
},
Kirigami.Action { Kirigami.Action {
id: aboutAction id: aboutAction
...@@ -189,6 +196,12 @@ Kirigami.GlobalDrawer { ...@@ -189,6 +196,12 @@ Kirigami.GlobalDrawer {
} }
} }
Component {
id: settingsPage
SettingsPage {}
}
Component { Component {
id: aboutInfoPage id: aboutInfoPage
......
...@@ -52,10 +52,22 @@ ListView { ...@@ -52,10 +52,22 @@ ListView {
currentIndex = selectedDate.getHours(); currentIndex = selectedDate.getHours();
} }
onAddEvent: pageStack.push(eventEditor, { startDt: selectedDate, startHour: currentIndex % 12, endHour: currentIndex % 12, startPm: currentIndex > 12, endPm: currentIndex > 12 } ) onAddEvent: {
var eventDt = selectedDate;
eventDt.setHours(currentIndex);
eventDt.setMinutes(0);
pageStack.push(eventEditor, { startDt: eventDt });
}
onAddTodo: pageStack.push(todoEditor, { startDt: selectedDate, startHour: currentIndex % 12, startPm: currentIndex > 12 } ) onAddTodo: pageStack.push(todoEditor, { startDt: selectedDate, startHour: currentIndex % 12, startPm: currentIndex > 12 } )
onCurrentIndexChanged: {
if (pageStack.depth > 1) {
pageStack.pop(null);
}
}
model: 24 model: 24
currentIndex: selectedDate.getHours() currentIndex: selectedDate.getHours()
......
...@@ -113,9 +113,9 @@ Kirigami.Page { ...@@ -113,9 +113,9 @@ Kirigami.Page {
id: startTimeSelector id: startTimeSelector
selectorDate: root.startDt selectorDate: root.startDt
selectorHour: root.incidenceData ? root.incidenceData.dtstart.toLocaleTimeString(Qt.locale(), "hh") % 12 : 0 selectorHour: (root.incidenceData ? root.incidenceData.dtstart.getHours() : root.startDt.getHours() ) % 12
selectorMinutes: root.incidenceData ? root.incidenceData.dtstart.toLocaleTimeString(Qt.locale(), "mm") : 0 selectorMinutes: root.incidenceData ? root.incidenceData.dtstart.getMinutes() : root.startDt.getMinutes()
selectorPm: (root.incidenceData && root.incidenceData.dtstart.toLocaleTimeString(Qt.locale("en_US"), "AP") == "PM") ? true : false selectorPm: root.incidenceData ? (root.incidenceData.dtstart.getHours() >=12) : (root.startDt.getHours() >=12)
enabled: !allDaySelector.checked enabled: !allDaySelector.checked
} }
} }
...@@ -129,16 +129,16 @@ Kirigami.Page { ...@@ -129,16 +129,16 @@ Kirigami.Page {
enabled: !allDaySelector.checked enabled: !allDaySelector.checked
Component.onCompleted: selectorDate = root.incidenceData ? root.incidenceData.dtend : root.startDt // Do not bind, just initialize Component.onCompleted: selectorDate = root.incidenceData ? root.incidenceData.dtend : new Date(root.startDt.getTime() + _calindoriConfig.eventsDuration*60000);// Do not bind, just initialize
} }
TimeSelectorButton { TimeSelectorButton {
id: endTimeSelector id: endTimeSelector
selectorDate: root.endDt selectorDate: root.endDt
selectorHour: root.incidenceData ? root.incidenceData.dtend.toLocaleTimeString(Qt.locale(), "hh") % 12 : 0 selectorHour: root.endDt.getHours() % 12
selectorMinutes: root.incidenceData ? root.incidenceData.dtend.toLocaleTimeString(Qt.locale(), "mm") : 0 selectorMinutes: root.endDt.getMinutes()
selectorPm: (root.incidenceData && root.incidenceData.dtend.toLocaleTimeString(Qt.locale("en_US"), "AP") == "PM") ? true : false selectorPm: (root.endDt.getHours() >=12)
enabled: !allDaySelector.checked && (root.endDt != undefined && !isNaN(root.endDt)) enabled: !allDaySelector.checked && (root.endDt != undefined && !isNaN(root.endDt))
} }
} }
......
...@@ -37,7 +37,7 @@ Kirigami.Page { ...@@ -37,7 +37,7 @@ Kirigami.Page {
actions.main: Kirigami.Action { actions.main: Kirigami.Action {
icon.name: "resource-calendar-insert" icon.name: "resource-calendar-insert"
text: i18n("Add event") text: i18n("Add event")
onTriggered: pageStack.push(eventEditor, {startDt: (eventStartDt && !isNaN(eventStartDt)) ? eventStartDt : new Date() }) onTriggered: pageStack.push(eventEditor, {startDt: (eventStartDt && !isNaN(eventStartDt)) ? new Date(root.eventStartDt.getTime() - root.eventStartDt.getMinutes()*60000 + 3600000) : new Date() })
} }
Component { Component {
......
...@@ -23,7 +23,7 @@ import QtQuick.Layouts 1.11 ...@@ -23,7 +23,7 @@ import QtQuick.Layouts 1.11
import org.kde.kirigami 2.10 as Kirigami import org.kde.kirigami 2.10 as Kirigami
import org.kde.phone.calindori 0.1 as Calindori import org.kde.phone.calindori 0.1 as Calindori
Kirigami.Page { Kirigami.ScrollablePage {
id: root id: root
property date incidenceStartDt property date incidenceStartDt
...@@ -39,7 +39,8 @@ Kirigami.Page { ...@@ -39,7 +39,8 @@ Kirigami.Page {
icon.name: "resource-calendar-insert" icon.name: "resource-calendar-insert"
text: i18n("Add") text: i18n("Add")
onTriggered: { onTriggered: {
var lStartDt = (incidenceType == 0 && (incidenceStartDt == null || isNaN(incidenceStartDt))) ? new Date() : incidenceStartDt; var currentDt = new Date();
var lStartDt = (incidenceType == 0 && (incidenceStartDt == null || isNaN(incidenceStartDt))) ? new Date(currentDt.getTime() - currentDt.getMinutes()*60000 + 3600000) : incidenceStartDt;
pageStack.push(incidenceType == 0 ? eventEditor : todoEditor, { startDt: lStartDt } ); pageStack.push(incidenceType == 0 ? eventEditor : todoEditor, { startDt: lStartDt } );
} }
} }
...@@ -65,7 +66,7 @@ Kirigami.Page { ...@@ -65,7 +66,7 @@ Kirigami.Page {
property: "displayDate" property: "displayDate"
criteria: ViewSection.FullString criteria: ViewSection.FullString
delegate: Kirigami.ListSectionHeader { delegate: Kirigami.ListSectionHeader {
label: section label: section || i18n("No start date")
} }
} }
......
/*
Copyright (C) 2020 Dimitris Kardarakos <dimkard@posteo.net>
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 <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as Controls
import org.kde.kirigami 2.4 as Kirigami
Kirigami.ScrollablePage {
id: root
title: i18n("Settings")
Kirigami.FormLayout {
width: root.width
Item {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: i18n("Events")
}
RowLayout {
Kirigami.FormData.label: i18n("Initial duration (minutes)")
Controls.SpinBox {
from: 0
value: _calindoriConfig.eventsDuration
onValueModified: _calindoriConfig.eventsDuration = value
}
}
}
}
...@@ -26,8 +26,9 @@ import org.kde.phone.calindori 0.1 ...@@ -26,8 +26,9 @@ import org.kde.phone.calindori 0.1
ListView { ListView {
id: root id: root
property int fstDayOfWeek: Qt.locale().firstDayOfWeek
property date startDate property date startDate
property date selectedWeekDate: new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() - startDate.getDay() + Qt.locale().firstDayOfWeek) property date selectedWeekDate: new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() - startDate.getDay() + (startDate.getDay() >= fstDayOfWeek ? fstDayOfWeek : fstDayOfWeek-7), startDate.getHours(), 0)
property date selectedDate: startDate property date selectedDate: startDate
property var cal property var cal
...@@ -58,17 +59,23 @@ ListView { ...@@ -58,17 +59,23 @@ ListView {
} }
onGoCurrentWeek: { onGoCurrentWeek: {
selectedWeekDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() - startDate.getDay() + Qt.locale().firstDayOfWeek); selectedWeekDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() - startDate.getDay() + (startDate.getDay() >= fstDayOfWeek ? fstDayOfWeek : fstDayOfWeek - 7), startDate.getHours(), 0);
selectedDate = startDate; selectedDate = startDate;
currentIndex = startDate.getDay() - Qt.locale().firstDayOfWeek; currentIndex = selectedDate.getDay() >= fstDayOfWeek ? selectedDate.getDay() - fstDayOfWeek : 7 - (selectedDate.getDay() + fstDayOfWeek)
} }
onAddEvent: pageStack.push(eventEditor, { startDt: selectedDate }) onAddEvent: pageStack.push(eventEditor, { startDt: new Date(root.selectedDate.getTime() - root.selectedDate.getMinutes()*60000 + 3600000) })
onAddTodo: pageStack.push(todoEditor, { startDt: selectedDate }) onAddTodo: pageStack.push(todoEditor, { startDt: selectedDate })
onCurrentIndexChanged: {
if (pageStack.depth > 1) {
pageStack.pop(null);
}
}
model: 7 model: 7
currentIndex: selectedDate.getDay() - Qt.locale().firstDayOfWeek currentIndex: selectedDate.getDay() >= fstDayOfWeek ? selectedDate.getDay() - fstDayOfWeek : 7 - (selectedDate.getDay() + fstDayOfWeek)
delegate: Kirigami.AbstractListItem { delegate: Kirigami.AbstractListItem {
id: dayListItem id: dayListItem
...@@ -80,7 +87,7 @@ ListView { ...@@ -80,7 +87,7 @@ ListView {
Controls2.Label { Controls2.Label {
font.pointSize: Kirigami.Units.fontMetrics.font.pointSize * 1.5 font.pointSize: Kirigami.Units.fontMetrics.font.pointSize * 1.5
text: Qt.locale().dayName(model.index + Qt.locale().firstDayOfWeek, Locale.NarrowFormat) text: Qt.locale().dayName(model.index + fstDayOfWeek, Locale.NarrowFormat)
Layout.minimumWidth: Kirigami.Units.gridUnit * 3 Layout.minimumWidth: Kirigami.Units.gridUnit * 3
} }
......
...@@ -136,7 +136,7 @@ Item { ...@@ -136,7 +136,7 @@ Item {
delegateWidth: root.dayRectWidth delegateWidth: root.dayRectWidth
selectedDate: root.selectedDate selectedDate: root.selectedDate
onDayClicked: root.selectedDate = new Date(model.yearNumber, model.monthNumber -1, model.dayNumber) onDayClicked: root.selectedDate = new Date(model.yearNumber, model.monthNumber -1, model.dayNumber, root.selectedDate.getHours(), root.selectedDate.getMinutes(), 0)
} }
} }
} }
......
...@@ -96,15 +96,22 @@ ColumnLayout { ...@@ -96,15 +96,22 @@ ColumnLayout {
font.pointSize: Kirigami.Units.fontMetrics.font.pointSize * 1.5 font.pointSize: Kirigami.Units.fontMetrics.font.pointSize * 1.5
} }
Controls2.ToolButton { Controls2.TabBar {
id: pm id: pmTabBar
checked: root.pm
checkable: true
text: checked ? i18n("PM") : i18n("AM")
font.pointSize: Kirigami.Units.fontMetrics.font.pointSize * 1.5 font.pointSize: Kirigami.Units.fontMetrics.font.pointSize * 1.5
onClicked: root.pm = checked Controls2.TabButton {
text: i18n("AM")
checked: !root.pm
onClicked: root.pm = !checked
}
Controls2.TabButton {
text: i18n("PM")
checked: root.pm
onClicked: root.pm = checked
}
} }
} }
......
...@@ -289,7 +289,7 @@ Incidence::List IncidenceModel::hourEvents() const ...@@ -289,7 +289,7 @@ Incidence::List IncidenceModel::hourEvents() const
auto endHour = e->allDay() ? 23 : e->dtEnd().time().hour(); auto endHour = e->allDay() ? 23 : e->dtEnd().time().hour();
//If the event starts and ends in the same day, we just check the hours; that way recurring events are fetched as well //If the event starts and ends in the same day, we just check the hours; that way recurring events are fetched as well
if( (e->dtStart().date() == e->dtEnd().date()) && (startHour <= m_filter_hour) && (endHour >= m_filter_hour) ) if( (e->dtStart().date() == e->dtEnd().date()) && (startHour <= m_filter_hour) && (endHour > m_filter_hour) )
{ {
incidences.append(e); incidences.append(e);
} }
......
...@@ -34,5 +34,6 @@ ...@@ -34,5 +34,6 @@
<file alias="DayPage.qml">contents/ui/DayPage.qml</file> <file alias="DayPage.qml">contents/ui/DayPage.qml</file>
<file alias="WeekPage.qml">contents/ui/WeekPage.qml</file> <file alias="WeekPage.qml">contents/ui/WeekPage.qml</file>
<file alias="CalindoriGlobalDrawer.qml">contents/ui/CalindoriGlobalDrawer.qml</file> <file alias="CalindoriGlobalDrawer.qml">contents/ui/CalindoriGlobalDrawer.qml</file>
<file alias="SettingsPage.qml">contents/ui/SettingsPage.qml</file>
</qresource> </qresource>
</RCC> </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