Commit 2a9e623f authored by Dimitris Kardarakos's avatar Dimitris Kardarakos
Browse files

Calendar is created automatically. Functionality to add tasks added.

parent f2cf28a2
......@@ -102,23 +102,31 @@ Kirigami.ApplicationWindow {
TodosView {
id: todosView
calendar: localCalendar
}
Component {
id: todoPage
TodoPage {
calendar: localCalendar
onTaskeditcompleted: {
console.log("Closing todo page");
root.pageStack.pop(todoPage);
todosView.todosmodel.reloadTasks();
root.pageStack.pop(todoPage);
}
}
}
MobileCalendar.LocalCalendar {
id: localCalendar
name: "personal"
}
MobileCalendar.Config {
id: mobileCalendarConfig;
}
}
}
/*
* Copyright 2018 Dimitris Kardarakos <dimkard@gmail.com>
*
* 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 QtQuick.Controls 2.4 as Controls2
import QtQuick.Layouts 1.11
import org.kde.kirigami 2.4 as Kirigami
import org.kde.phone.mobilecalendar 0.1 as MobileCalendar
Kirigami.Page {
id: root
property date startdt
property var calendar
signal taskeditcompleted
title: qsTr("Task")
Kirigami.AbstractCard {
id: todoCard
anchors.fill: parent
// header: Kirigami.Heading {
// text: "New Task"
// }
//
contentItem: ColumnLayout {
Controls2.Label {
text: startdt.toLocaleDateString(Qt.locale())
}
Controls2.TextField {
id: summary
placeholderText: qsTr("Summary")
}
Controls2.TextArea {
id:description
placeholderText: qsTr("Description")
}
RowLayout {
Controls2.Button {
id: saveBtn
text: "Save"
onClicked: {
if(summary.text) {
console.log("Saving task");
root.calendar.addTask(summary.text, description.text, root.startdt);
taskeditcompleted();
}
else {
showPassiveNotification("Summary should not be empty");
}
}
}
Controls2.Button {
id: cancelBtn
text: "Cancel"
onClicked: {
taskeditcompleted();
}
}
}
}
}
}
......@@ -22,18 +22,16 @@ import QtQuick.Controls 2.4 as Controls2
import QtQuick.Layouts 1.11
import org.kde.kirigami 2.4 as Kirigami
import org.kde.phone.mobilecalendar 0.1 as MobileCalendar
import Qt.labs.platform 1.0
Kirigami.ScrollablePage {
id: root
property date todoDt
property alias calendar: todosModel.calendar
property var calendar
property alias todosmodel: cardsListview.model
title: qsTr("Tasks")
Kirigami.CardsListView {
id: cardsListview
......@@ -42,7 +40,7 @@ Kirigami.ScrollablePage {
id: todosModel
filterdt: todoDt
calendar: Qt.resolvedUrl( StandardPaths.standardLocations(StandardPaths.DataLocation)[0] + "/localcalendar")
memorycalendar: root.calendar.memorycalendar
}
delegate: Kirigami.AbstractCard {
......
/*
* Copyright (C) 2018 Dimitris Kardarakos
*
* This library 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 library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "localcalendar.h"
#include <QDebug>
#include <KCalCore/Todo>
#include <QFile>
#include <QStandardPaths>
using namespace KCalCore;
LocalCalendar::LocalCalendar(QObject* parent)
: QObject(parent)
{}
LocalCalendar::~LocalCalendar() = default;
MemoryCalendar::Ptr LocalCalendar::memorycalendar() const
{
return m_calendar;
}
FileStorage::Ptr LocalCalendar::calendarstorage() const
{
return m_cal_storage;
}
QString LocalCalendar::name() const
{
return m_name;
}
void LocalCalendar::setName(QString calendarName)
{
if (m_name != calendarName) {
MemoryCalendar::Ptr calendar(new MemoryCalendar(QTimeZone::systemTimeZone()));
FileStorage::Ptr storage(new FileStorage(calendar));
QString fullPathName = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/" + calendarName; //TODO: Consider changing to GenericDataLocation if calendar should be shared with other apps
QFile calendarFile(fullPathName);
storage->setFileName(fullPathName);
if (!calendarFile.exists()) {
qDebug() << "Creating file" << storage->save();
}
if(storage->load()) {
m_name = calendarName;
m_calendar = calendar;
m_cal_storage = storage;
}
}
}
void LocalCalendar::setMemorycalendar(MemoryCalendar::Ptr memoryCalendar)
{
if(m_calendar != memoryCalendar) {
m_calendar = memoryCalendar;
qDebug() << "Calendar succesfully set";
}
else {
qDebug() << "Cannot set calendar ";
}
}
void LocalCalendar::setCalendarstorage(FileStorage::Ptr calendarStorage)
{
if(m_cal_storage != calendarStorage) {
m_cal_storage = calendarStorage;
qDebug() << "Storage succesfully set";
}
else {
qDebug() << "Cannot set storage ";
}
}
void LocalCalendar::addTask(QString summary, QString description, QDate startDate)
{
qDebug() << "Creating todo" << "summary:" << summary << ", description:" << description << ", startDate:" << startDate.toString();
QDateTime now = QDateTime::currentDateTime();
Todo::Ptr todo(new Todo());
todo->setUid(summary.left(1) + now.toString("yyyyMMddhhmmsszzz"));
todo->setDtStart(QDateTime(startDate));
todo->setDescription(description);
todo->setSummary(summary);
m_calendar->addTodo(todo);
bool success = m_cal_storage->save();
qDebug() << "Storage save: " << success;
emit todoAdded();
qDebug() << "New todo has been saved";
}
/*
* Copyright (C) 2018 Dimitris Kardarakos
*
* This library 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 library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef LOCALCALENDAR_H
#define LOCALCALENDAR_H
#include <QSharedPointer>
#include <KCalCore/MemoryCalendar>
#include <KCalCore/FileStorage>
using namespace KCalCore;
class LocalCalendar : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QSharedPointer<MemoryCalendar> memorycalendar READ memorycalendar WRITE setMemorycalendar NOTIFY memorycalendarChanged)
Q_PROPERTY(QSharedPointer<FileStorage> calendarstorage READ calendarstorage WRITE setCalendarstorage NOTIFY calendarstorageChanged)
public:
explicit LocalCalendar(QObject* parent = nullptr);
~LocalCalendar() override;
MemoryCalendar::Ptr memorycalendar() const;
FileStorage::Ptr calendarstorage() const;
QString name() const;
void setMemorycalendar(MemoryCalendar::Ptr memoryCalendar);
void setCalendarstorage(FileStorage::Ptr calendarStorage);
void setName(QString calendarName);
public Q_SLOTS:
void addTask(QString summary, QString description, QDate startDate);
Q_SIGNALS:
void memorycalendarChanged();
void calendarstorageChanged();
void nameChanged();
void todoAdded();
private:
MemoryCalendar::Ptr m_calendar;
FileStorage::Ptr m_cal_storage;
QString m_name;
};
#endif // LOCALCALENDAR_H
......@@ -20,12 +20,9 @@
#include <QDebug>
TodosModel::TodosModel(QObject* parent)
: QAbstractListModel(parent),
m_todos(Todo::List()),
m_cal_url(QUrl()),
m_calendar(nullptr),
m_cal_storage(nullptr),
m_filterdt(QDate())
m_filterdt(QDate()),
m_todos(Todo::List())
{}
TodosModel::~TodosModel() = default;
......@@ -80,50 +77,15 @@ QVariant TodosModel::data(const QModelIndex& index, int role) const
return QVariant();
}
int TodosModel::rowCount(const QModelIndex& parent) const
{
if(parent.isValid())
return 0;
return m_todos.count();
}
void TodosModel::addTodos(const Todo::List& todos)
{
qDebug() << "Add Todos (not implemented yet)";
// if(!todos.isEmpty()) {
// beginInsertRows(QModelIndex(), rowCount(), rowCount()+todos.size()-1);
// m_todos += todos;
//
// //TODO: add todos to calendar
// //TODO: save storage
// endInsertRows();
// emit rowsChanged();
// }
}
void TodosModel::deleteTodo(int row)
{
qDebug() << "Delete Todo (not implemented yet)";
// Todo::Ptr = m_todos[row].data();
}
QUrl TodosModel::calendar() const
{
return m_cal_url;
}
MemoryCalendar::Ptr TodosModel::memorycalendar() const
{
return m_calendar;
}
FileStorage::Ptr TodosModel::calendarstorage() const
void TodosModel::setMemorycalendar(MemoryCalendar::Ptr calendarPtr)
{
return m_cal_storage;
m_calendar = calendarPtr;
}
QDate TodosModel::filterdt() const
......@@ -137,8 +99,16 @@ void TodosModel::setFilterdt(QDate filterDate)
m_filterdt = filterDate;
if(m_calendar != nullptr) {
loadTasks(m_filterdt);
}
}
}
int TodosModel::rowCount(const QModelIndex& parent) const
{
if(parent.isValid())
return 0;
return m_todos.count();
}
......@@ -149,33 +119,15 @@ void TodosModel::loadTasks(QDate taskDt)
qDebug() << "Show tasks of " + taskDt.toString();
m_todos = m_calendar->rawTodos(taskDt,taskDt);
endResetModel();
emit rowsChanged();
emit calendarChanged();
}
void TodosModel::setCalendar(QUrl calendarUrl)
void TodosModel::reloadTasks()
{
if(m_cal_url != calendarUrl) {
MemoryCalendar::Ptr calendar(new MemoryCalendar(QTimeZone::systemTimeZone()));
FileStorage::Ptr storage(new FileStorage(calendar));
storage->setFileName(calendarUrl.path());
if(storage->load()) {
m_cal_url = calendarUrl; //TODO: create a calendar-url-storage type ?
m_calendar = calendar;
m_cal_storage = storage;
loadTasks(m_filterdt);
// beginResetModel();
// m_todos.clear();
// m_todos = m_calendar->rawTodos();
// endResetModel();
// emit rowsChanged();
// emit calendarChanged();
}
else {
qDebug() << "Cannot open calendar file " << calendarUrl.toDisplayString() ;
}
}
loadTasks(m_filterdt);
}
......@@ -23,16 +23,16 @@
#include <QSharedPointer>
#include <KCalCore/MemoryCalendar>
#include <KCalCore/FileStorage>
#include "localcalendar.h"
using namespace KCalCore;
class TodosModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(QUrl calendar READ calendar WRITE setCalendar NOTIFY calendarChanged)
Q_PROPERTY(QDate filterdt READ filterdt WRITE setFilterdt NOTIFY filterdtChanged)
Q_PROPERTY(QSharedPointer<MemoryCalendar> memorycalendar READ memorycalendar NOTIFY memorycalendarChanged )
Q_PROPERTY(QSharedPointer<FileStorage> calendarstorage READ calendarstorage NOTIFY calendarstorageChanged)
Q_PROPERTY(QSharedPointer<MemoryCalendar> memorycalendar READ memorycalendar WRITE setMemorycalendar NOTIFY memorycalendarChanged )
Q_PROPERTY(int count READ rowCount NOTIFY rowsChanged)
public:
enum Roles {
......@@ -54,33 +54,26 @@ public:
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
void setCalendar(QUrl canledarUrl);
void setFilterdt(QDate filterDate);
QUrl calendar() const;
MemoryCalendar::Ptr memorycalendar() const;
FileStorage::Ptr calendarstorage() const;
void setMemorycalendar(MemoryCalendar::Ptr calendarPtr);
QDate filterdt() const;
void setFilterdt(QDate filterDate);
QHash<int, QByteArray> roleNames() const override;
public Q_SLOTS:
void deleteTodo(int row);
private Q_SLOTS:
void addTodos(const Todo::List& todos);
void reloadTasks();
Q_SIGNALS:
void rowsChanged();
void calendarChanged();
void memorycalendarChanged();
void calendarstorageChanged();
void filterdtChanged();
private:
Todo::List m_todos;
MemoryCalendar::Ptr m_calendar;
FileStorage::Ptr m_cal_storage;
QUrl m_cal_url;
QDate m_filterdt;
void loadTasks(QDate taskDt);
};
......
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