1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/*
Controller.h
This file is part of Charm, a task-based time tracking application.
Copyright (C) 2007-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
Author: Mirko Boehm <mirko.boehm@kdab.com>
Author: Olivier JG <olivier.de.gaalon@kdab.com>
Author: Frank Osterfeld <frank.osterfeld@kdab.com>
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) 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 <http://www.gnu.org/licenses/>.
*/
#ifndef CONTROLLER_H
#define CONTROLLER_H
#include <QObject>
#include "Event.h"
#include "Task.h"
#include "State.h"
class CharmCommand;
class Configuration;
class SqlStorage;
class Controller : public QObject
{
Q_OBJECT
public:
explicit Controller(QObject *parent = nullptr);
~Controller();
// application:
// react on application state changes
void stateChanged(State previous, State next);
// persist meta data portions of Configuration
void persistMetaData(Configuration &);
// load meta data and store appropriate portions in configuration
void provideMetaData(Configuration &);
/** Create the backend. */
bool initializeBackEnd(const QString &name);
/** Connect to the backend (make it available). */
bool connectToBackend();
/** Disconnect from the backend (shut it down). */
bool disconnectFromBackend();
/** The currently used backend. */
SqlStorage *storage();
// FIXME add the add/modify/delete functions will not be slots anymore
/** Add an event.
Return a valid event if successful. */
Event makeEvent(const Task &);
/** Add an event, copying data from another event. */
Event cloneEvent(const Event &);
/** Modify an event. */
bool modifyEvent(const Event &);
/** Delete an event. */
bool deleteEvent(const Event &);
/** Add a task, and send the result to the view as a signal. */
bool addTask(const Task &parent);
/** Modify the task, the user has changed it in the view. */
bool modifyTask(const Task &);
/** Delete the task. Send a signal to the view confirming it. */
bool deleteTask(const Task &);
/** Set all tasks. Updates the view, after. */
bool setAllTasks(const TaskList &);
/** Export the database contents into a XML document. */
QDomDocument exportDatabasetoXml() const;
/** Import the content of the Xml document into the currently open database.
* This will modify the database.
* @return An empty string on no error, an human-readable error message otherwise.
*/
QString importDatabaseFromXml(const QDomDocument &);
void updateModelEventsAndTasks();
public Q_SLOTS:
/** Receive a command from the view. */
void executeCommand(CharmCommand *);
/** Receive an undo command from the view. */
void rollbackCommand(CharmCommand *);
Q_SIGNALS:
/** Added an event. */
void eventAdded(const Event &event);
/** Modified an event. */
void eventModified(const Event &event);
/** Deleted an event. */
void eventDeleted(const Event &event);
void allEvents(const EventList &);
/** This sends out the current task list. */
void definedTasks(const TaskList &);
/** Add a task. */
void taskAdded(const Task &);
/** Update a task in the view. */
void taskUpdated(const Task &);
/** Delete a task from the view completely. */
void taskDeleted(const Task &);
/** This tells the application that the controller is ready to quit.
When the user quits the application, the application will tell
the controller to end and commit all active events.
The controller will emit readyToQuit() when all data is
stored.
The controller will leave Disconnecting state when it receives
the signal. */
void readyToQuit();
void currentBackendStatus(const QString &text);
/** A command has been completed from the controller's point of view. */
void commandCompleted(CharmCommand *);
private:
void updateSubscriptionForTask(const Task &);
template<class T> void loadConfigValue(const QString &key, T &configValue) const;
SqlStorage *m_storage = nullptr;
};
#endif
|