diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ find_package(KdepimLibs REQUIRED) find_package(Boost REQUIRED) find_package(Baloo REQUIRED) +find_package(Grantlee REQUIRED) macro_log_feature(KDEPIMLIBS_FOUND "kdepimlibs" "KDE PIM libraries" "The KDE PIM libs are required to build Zanshin" "http://www.kde.org") include(KDE4Defaults) diff --git a/src/domain/task.h b/src/domain/task.h --- a/src/domain/task.h +++ b/src/domain/task.h @@ -197,6 +197,7 @@ Q_OBJECT Q_PROPERTY(QDateTime startDate READ startDate WRITE setStartDate NOTIFY startDateChanged) Q_PROPERTY(QDateTime dueDate READ dueDate WRITE setDueDate NOTIFY dueDateChanged) + Q_PROPERTY(bool done READ isDone) Q_PROPERTY(Domain::Task::Delegate delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) Q_PROPERTY(Domain::Recurrence::Ptr recurrence READ recurrence WRITE setRecurrence NOTIFY recurrenceChanged) Q_PROPERTY(Domain::Alarm::List alarms READ alarms WRITE setAlarms NOTIFY alarmsChanged) diff --git a/src/presentation/tasklistmodel.h b/src/presentation/tasklistmodel.h --- a/src/presentation/tasklistmodel.h +++ b/src/presentation/tasklistmodel.h @@ -54,8 +54,8 @@ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); -private: Domain::Task::Ptr taskForIndex(const QModelIndex &index) const; +private: bool isModelIndexValid(const QModelIndex &index) const; TaskList::Ptr m_taskList; diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -14,6 +14,7 @@ newpagedialog.cpp newpagedialoginterface.cpp pageview.cpp + printwidget.cpp ) qt4_wrap_ui(widgets_SRCS @@ -22,5 +23,12 @@ newpagedialog.ui ) +include_directories( + ${Grantlee_INCLUDE_DIRS} + ${CMAKE_CURRENT_BINARY_DIR} +) + +configure_file(grantlee_paths.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/grantlee_paths.h) + kde4_add_library(widgets STATIC ${widgets_SRCS}) -target_link_libraries(widgets ${QT4_QTGUI_LIBRARY} presentation ${KDEPIM_STATIC_LIBS}) +target_link_libraries(widgets ${QT4_QTGUI_LIBRARY} presentation ${KDEPIM_STATIC_LIBS} ${Grantlee_CORE_LIBRARIES}) diff --git a/src/widgets/grantlee_paths.h.cmake b/src/widgets/grantlee_paths.h.cmake new file mode 100644 --- /dev/null +++ b/src/widgets/grantlee_paths.h.cmake @@ -0,0 +1,2 @@ +#define GRANTLEE_TEMPLATE_PATH "@PROJECT_SOURCE_DIR@/src/widgets/templates" + diff --git a/src/widgets/pageview.h b/src/widgets/pageview.h --- a/src/widgets/pageview.h +++ b/src/widgets/pageview.h @@ -43,6 +43,7 @@ namespace Widgets { class FilterWidget; +class PrintWidget; class PageView : public QWidget { @@ -76,6 +77,7 @@ FilterWidget *m_filterWidget; QTreeView *m_centralView; QLineEdit *m_quickAddEdit; + PrintWidget *m_printWidget; MessageBoxInterface::Ptr m_messageBoxInterface; ApplicationMode m_mode; }; diff --git a/src/widgets/pageview.cpp b/src/widgets/pageview.cpp --- a/src/widgets/pageview.cpp +++ b/src/widgets/pageview.cpp @@ -23,6 +23,7 @@ #include "pageview.h" +#include "printwidget.h" #include #include @@ -87,7 +88,8 @@ m_filterWidget(new FilterWidget(this)), m_centralView(new PageTreeView(this)), m_quickAddEdit(new QLineEdit(this)), - m_mode(mode) + m_mode(mode), + m_printWidget(new PrintWidget(parent)) { m_filterWidget->setObjectName("filterWidget"); @@ -121,6 +123,7 @@ auto layout = new QVBoxLayout; layout->addWidget(m_filterWidget); layout->addWidget(m_centralView); + layout->addWidget(m_printWidget); layout->addLayout(hLayout); setLayout(layout); @@ -134,6 +137,8 @@ addAction(removeItemAction); m_messageBoxInterface = MessageBox::Ptr::create(); + + m_printWidget->setModel(m_filterWidget->proxyModel()); } QObject *PageView::model() const diff --git a/src/widgets/pageview.h b/src/widgets/printwidget.h copy from src/widgets/pageview.h copy to src/widgets/printwidget.h --- a/src/widgets/pageview.h +++ b/src/widgets/printwidget.h @@ -1,6 +1,6 @@ /* This file is part of Zanshin - Copyright 2014 Kevin Ottens + Copyright 2015 Sandro Knauß This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -21,9 +21,8 @@ USA. */ - -#ifndef WIDGETS_PAGEVIEW_H -#define WIDGETS_PAGEVIEW_H +#ifndef WIDGETS_PRINTWIDGET_H +#define WIDGETS_PRINTWIDGET_H #include @@ -32,19 +31,29 @@ #include #include "domain/artifact.h" -#include "messageboxinterface.h" +#include "domain/task.h" class QLineEdit; class QModelIndex; class QTreeView; class QMessageBox; class QMenu; +class QTextDocument; +class QTextEdit; +class QTimer; -namespace Widgets { +namespace Akonadi { + class TaskRepository; + class TaskQueries; +} -class FilterWidget; +namespace Grantlee { + class Engine; +} + +namespace Widgets { -class PageView : public QWidget +class PrintWidget : public QWidget { Q_OBJECT public: @@ -53,33 +62,31 @@ NotesOnly, TasksAndNotes }; - explicit PageView(QWidget *parent = 0, ApplicationMode mode = TasksAndNotes); + explicit PrintWidget(QWidget *parent = 0, ApplicationMode mode = TasksAndNotes); QObject *model() const; - MessageBoxInterface::Ptr messageBoxInterface() const; public slots: void setModel(QObject *model); - void setMessageBoxInterface(const MessageBoxInterface::Ptr &interface); - void configurePopupMenu(QMenu *menu, const Domain::Artifact::Ptr &artifact); -signals: - void currentArtifactChanged(const Domain::Artifact::Ptr &artifact); +private: + QObject *m_model; + QTextDocument *m_document; + QTextEdit *m_edit; + QTimer *m_timer; + ApplicationMode m_mode; + Akonadi::TaskRepository *m_repository; + Akonadi::TaskQueries *m_queries; + Grantlee::Engine *m_engine; private slots: - void onEditingFinished(); - void onRemoveItemRequested(); - void onCurrentChanged(const QModelIndex ¤t); + void render(); + void delayedInit(); private: - QObject *m_model; - FilterWidget *m_filterWidget; - QTreeView *m_centralView; - QLineEdit *m_quickAddEdit; - MessageBoxInterface::Ptr m_messageBoxInterface; - ApplicationMode m_mode; + QString renderItem(const Domain::Task::Ptr &task); }; } -#endif // WIDGETS_PAGEVIEW_H +#endif // WIDGETS_PRINTWIDGET_H diff --git a/src/widgets/printwidget.cpp b/src/widgets/printwidget.cpp new file mode 100644 --- /dev/null +++ b/src/widgets/printwidget.cpp @@ -0,0 +1,130 @@ +/* This file is part of Zanshin + + Copyright 2015 Sandro Knauß + + 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 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + 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, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include "printwidget.h" + +#include +#include +#include +#include + +#include + +#include "presentation/artifactfilterproxymodel.h" +#include "presentation/metatypes.h" + +#include "akonadi/akonaditaskqueries.h" +#include "akonadi/akonaditaskrepository.h" +#include "presentation/tasklistmodel.h" +#include + +#include "grantlee_paths.h" +#include "grantlee_core.h" + +using namespace Widgets; + +PrintWidget::PrintWidget(QWidget *parent, ApplicationMode mode) + : QWidget(parent), + m_model(0), + m_mode(mode), + m_document(new QTextDocument(this)), + m_edit(new QTextEdit()), + m_timer(new QTimer()), + m_repository(new Akonadi::TaskRepository), + m_queries(new Akonadi::TaskQueries), + m_engine(0) +{ + m_edit->setDocument(m_document); + + connect(m_timer, SIGNAL(timeout()), SLOT(render())); + m_timer->setInterval(2000); + + auto layout = new QVBoxLayout; + layout->addWidget(m_edit); + setLayout(layout); + + QTimer::singleShot(0, this, SLOT(delayedInit())); +} + +void PrintWidget::delayedInit() +{ + m_engine = new Grantlee::Engine(this); + m_engine->addDefaultLibrary( "grantlee_i18n" ); + m_engine->addDefaultLibrary( "grantlee_scriptabletags" ); + + Grantlee::FileSystemTemplateLoader::Ptr loader = Grantlee::FileSystemTemplateLoader::Ptr(new Grantlee::FileSystemTemplateLoader()); + loader->setTemplateDirs(QStringList() << GRANTLEE_TEMPLATE_PATH); + m_engine->addTemplateLoader(loader); +} + +QObject *PrintWidget::model() const +{ + return m_model; +} + +void PrintWidget::setModel(QObject *model) +{ + if (model == m_model) + return; + + m_model = model; + + if (!m_model) { + m_timer->stop(); + return; + } + m_timer->start(); +} + +void PrintWidget::render() +{ + if (!m_model) { + return; + } + + auto model = static_cast(m_model); + + QString html; + + QVariantList artifacts; + + for(int i=0; irowCount(); i++) { + auto index = model->index(i,0); + auto data = index.data(Presentation::QueryTreeModelBase::ObjectRole); + if (!data.isValid()) + continue; + + auto artifact = data.value(); + if (!artifact) + continue; + artifacts << QVariant::fromValue(static_cast(artifact.data())); + } + + Grantlee::Template t = m_engine->loadByName("main.html"); + Grantlee::Context c; + c.insert("anz", artifacts.count()); + c.insert("tasks", artifacts); + + html += t->render(&c); + m_document->setHtml(html); +} diff --git a/src/widgets/templates/CMakeLists.txt b/src/widgets/templates/CMakeLists.txt new file mode 100644 diff --git a/src/widgets/templates/main.html b/src/widgets/templates/main.html new file mode 100644 --- /dev/null +++ b/src/widgets/templates/main.html @@ -0,0 +1,16 @@ + +

You have {{ anz }} Tasks

+ +{% for task in tasks %} +
+

{{ task.title }} {% if task.done %}---done---{% endif %}

+{% if task.dueDate %} +due to: {{ task.dueDate|date }} +{% endif %} +{% if task.text %} +

{{ task.text|safe }}

+{% endif %} +
+{% endfor %} + +