##// END OF EJS Templates
Check unsaved data on close
trabillard -
r1239:af6db233f5d0
parent child
Show More
@@ -1,65 +1,66
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SciQLop Software
2 -- This file is a part of the SciQLop Software
3 -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #ifndef SCIQLOP_MAINWINDOW_H
22 #ifndef SCIQLOP_MAINWINDOW_H
23 #define SCIQLOP_MAINWINDOW_H
23 #define SCIQLOP_MAINWINDOW_H
24
24
25 #include <QListWidgetItem>
25 #include <QListWidgetItem>
26 #include <QLoggingCategory>
26 #include <QLoggingCategory>
27 #include <QMainWindow>
27 #include <QMainWindow>
28 #include <QProgressBar>
28 #include <QProgressBar>
29 #include <QProgressDialog>
29 #include <QProgressDialog>
30 #include <QThread>
30 #include <QThread>
31 #include <QVBoxLayout>
31 #include <QVBoxLayout>
32 #include <QWidget>
32 #include <QWidget>
33
33
34 #include <Common/spimpl.h>
34 #include <Common/spimpl.h>
35
35
36 #include <memory>
36 #include <memory>
37
37
38 Q_DECLARE_LOGGING_CATEGORY(LOG_MainWindow)
38 Q_DECLARE_LOGGING_CATEGORY(LOG_MainWindow)
39
39
40 namespace Ui {
40 namespace Ui {
41 class MainWindow;
41 class MainWindow;
42 } // namespace Ui
42 } // namespace Ui
43
43
44
44
45 class MainWindow : public QMainWindow {
45 class MainWindow : public QMainWindow {
46 Q_OBJECT
46 Q_OBJECT
47
47
48 public:
48 public:
49 explicit MainWindow(QWidget *parent = 0);
49 explicit MainWindow(QWidget *parent = 0);
50 virtual ~MainWindow();
50 virtual ~MainWindow();
51 public slots:
51 public slots:
52
52
53 protected:
53 protected:
54 void changeEvent(QEvent *e);
54 void changeEvent(QEvent *e);
55 void closeEvent(QCloseEvent *event);
55
56
56 private:
57 private:
57 std::unique_ptr<Ui::MainWindow> m_Ui;
58 std::unique_ptr<Ui::MainWindow> m_Ui;
58 // QWidget *m_progressWidget;
59 // QWidget *m_progressWidget;
59 // QVBoxLayout *m_progressLayout;
60 // QVBoxLayout *m_progressLayout;
60 // QList<QLopService*> m_qlopServices;
61 // QList<QLopService*> m_qlopServices;
61 class MainWindowPrivate;
62 class MainWindowPrivate;
62 spimpl::unique_impl_ptr<MainWindowPrivate> impl;
63 spimpl::unique_impl_ptr<MainWindowPrivate> impl;
63 };
64 };
64
65
65 #endif // SCIQLOP_MAINWINDOW_H
66 #endif // SCIQLOP_MAINWINDOW_H
@@ -1,366 +1,405
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SciQLop Software
2 -- This file is a part of the SciQLop Software
3 -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "MainWindow.h"
22 #include "MainWindow.h"
23 #include "ui_MainWindow.h"
23 #include "ui_MainWindow.h"
24
24
25 #include <Catalogue/CatalogueController.h>
25 #include <Catalogue/CatalogueExplorer.h>
26 #include <Catalogue/CatalogueExplorer.h>
26 #include <DataSource/DataSourceController.h>
27 #include <DataSource/DataSourceController.h>
27 #include <DataSource/DataSourceWidget.h>
28 #include <DataSource/DataSourceWidget.h>
28 #include <Settings/SqpSettingsDialog.h>
29 #include <Settings/SqpSettingsDialog.h>
29 #include <Settings/SqpSettingsGeneralWidget.h>
30 #include <Settings/SqpSettingsGeneralWidget.h>
30 #include <SidePane/SqpSidePane.h>
31 #include <SidePane/SqpSidePane.h>
31 #include <SqpApplication.h>
32 #include <SqpApplication.h>
32 #include <Time/TimeController.h>
33 #include <Time/TimeController.h>
33 #include <TimeWidget/TimeWidget.h>
34 #include <TimeWidget/TimeWidget.h>
34 #include <Variable/Variable.h>
35 #include <Variable/Variable.h>
35 #include <Variable/VariableController.h>
36 #include <Variable/VariableController.h>
36 #include <Visualization/VisualizationController.h>
37 #include <Visualization/VisualizationController.h>
37
38
38 #include <QAction>
39 #include <QAction>
40 #include <QCloseEvent>
39 #include <QDate>
41 #include <QDate>
40 #include <QDir>
42 #include <QDir>
41 #include <QFileDialog>
43 #include <QFileDialog>
44 #include <QMessageBox>
42 #include <QToolBar>
45 #include <QToolBar>
43 #include <QToolButton>
46 #include <QToolButton>
44 #include <memory.h>
47 #include <memory.h>
45
48
46 #include "iostream"
49 #include "iostream"
47
50
48 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
51 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
49
52
50 namespace {
53 namespace {
51 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
54 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
52 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
55 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
53 const auto VIEWPLITTERINDEX = 2;
56 const auto VIEWPLITTERINDEX = 2;
54 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
57 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
55 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
58 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
56 }
59 }
57
60
58 class MainWindow::MainWindowPrivate {
61 class MainWindow::MainWindowPrivate {
59 public:
62 public:
60 explicit MainWindowPrivate(MainWindow *mainWindow)
63 explicit MainWindowPrivate(MainWindow *mainWindow)
61 : m_LastOpenLeftInspectorSize{},
64 : m_LastOpenLeftInspectorSize{},
62 m_LastOpenRightInspectorSize{},
65 m_LastOpenRightInspectorSize{},
63 m_GeneralSettingsWidget{new SqpSettingsGeneralWidget{mainWindow}},
66 m_GeneralSettingsWidget{new SqpSettingsGeneralWidget{mainWindow}},
64 m_SettingsDialog{new SqpSettingsDialog{mainWindow}},
67 m_SettingsDialog{new SqpSettingsDialog{mainWindow}},
65 m_CatalogExplorer{new CatalogueExplorer{mainWindow}}
68 m_CatalogExplorer{new CatalogueExplorer{mainWindow}}
66 {
69 {
67 }
70 }
68
71
69 QSize m_LastOpenLeftInspectorSize;
72 QSize m_LastOpenLeftInspectorSize;
70 QSize m_LastOpenRightInspectorSize;
73 QSize m_LastOpenRightInspectorSize;
71 /// General settings widget. MainWindow has the ownership
74 /// General settings widget. MainWindow has the ownership
72 SqpSettingsGeneralWidget *m_GeneralSettingsWidget;
75 SqpSettingsGeneralWidget *m_GeneralSettingsWidget;
73 /// Settings dialog. MainWindow has the ownership
76 /// Settings dialog. MainWindow has the ownership
74 SqpSettingsDialog *m_SettingsDialog;
77 SqpSettingsDialog *m_SettingsDialog;
75 /// Catalogue dialog. MainWindow has the ownership
78 /// Catalogue dialog. MainWindow has the ownership
76 CatalogueExplorer *m_CatalogExplorer;
79 CatalogueExplorer *m_CatalogExplorer;
80
81 bool checkDataToSave(QWidget *parentWidget);
77 };
82 };
78
83
79 MainWindow::MainWindow(QWidget *parent)
84 MainWindow::MainWindow(QWidget *parent)
80 : QMainWindow{parent},
85 : QMainWindow{parent},
81 m_Ui{new Ui::MainWindow},
86 m_Ui{new Ui::MainWindow},
82 impl{spimpl::make_unique_impl<MainWindowPrivate>(this)}
87 impl{spimpl::make_unique_impl<MainWindowPrivate>(this)}
83 {
88 {
84 m_Ui->setupUi(this);
89 m_Ui->setupUi(this);
85
90
86 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
91 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
87 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
92 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
88
93
89 impl->m_CatalogExplorer->setVisualizationWidget(m_Ui->view);
94 impl->m_CatalogExplorer->setVisualizationWidget(m_Ui->view);
90
95
91
96
92 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
97 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
93 auto openLeftInspectorAction = new QAction{QIcon{
98 auto openLeftInspectorAction = new QAction{QIcon{
94 ":/icones/previous.png",
99 ":/icones/previous.png",
95 },
100 },
96 tr("Show/hide the left inspector"), this};
101 tr("Show/hide the left inspector"), this};
97
102
98
103
99 auto spacerLeftTop = new QWidget{};
104 auto spacerLeftTop = new QWidget{};
100 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
105 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
101
106
102 auto spacerLeftBottom = new QWidget{};
107 auto spacerLeftBottom = new QWidget{};
103 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
108 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
104
109
105 leftSidePane->addWidget(spacerLeftTop);
110 leftSidePane->addWidget(spacerLeftTop);
106 leftSidePane->addAction(openLeftInspectorAction);
111 leftSidePane->addAction(openLeftInspectorAction);
107 leftSidePane->addWidget(spacerLeftBottom);
112 leftSidePane->addWidget(spacerLeftBottom);
108
113
109
114
110 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
115 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
111 auto openRightInspectorAction = new QAction{QIcon{
116 auto openRightInspectorAction = new QAction{QIcon{
112 ":/icones/next.png",
117 ":/icones/next.png",
113 },
118 },
114 tr("Show/hide the right inspector"), this};
119 tr("Show/hide the right inspector"), this};
115
120
116 auto spacerRightTop = new QWidget{};
121 auto spacerRightTop = new QWidget{};
117 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
122 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
118
123
119 auto spacerRightBottom = new QWidget{};
124 auto spacerRightBottom = new QWidget{};
120 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
125 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
121
126
122 rightSidePane->addWidget(spacerRightTop);
127 rightSidePane->addWidget(spacerRightTop);
123 rightSidePane->addAction(openRightInspectorAction);
128 rightSidePane->addAction(openRightInspectorAction);
124 rightSidePane->addWidget(spacerRightBottom);
129 rightSidePane->addWidget(spacerRightBottom);
125
130
126 openLeftInspectorAction->setCheckable(true);
131 openLeftInspectorAction->setCheckable(true);
127 openRightInspectorAction->setCheckable(true);
132 openRightInspectorAction->setCheckable(true);
128
133
129 auto openInspector = [this](bool checked, bool right, auto action) {
134 auto openInspector = [this](bool checked, bool right, auto action) {
130
135
131 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
136 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
132
137
133 auto &lastInspectorSize
138 auto &lastInspectorSize
134 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
139 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
135
140
136 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
141 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
137 : m_Ui->leftMainInspectorWidget->size();
142 : m_Ui->leftMainInspectorWidget->size();
138
143
139 // Update of the last opened geometry
144 // Update of the last opened geometry
140 if (checked) {
145 if (checked) {
141 lastInspectorSize = nextInspectorSize;
146 lastInspectorSize = nextInspectorSize;
142 }
147 }
143
148
144 auto startSize = lastInspectorSize;
149 auto startSize = lastInspectorSize;
145 auto endSize = startSize;
150 auto endSize = startSize;
146 endSize.setWidth(0);
151 endSize.setWidth(0);
147
152
148 auto splitterInspectorIndex
153 auto splitterInspectorIndex
149 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
154 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
150
155
151 auto currentSizes = m_Ui->splitter->sizes();
156 auto currentSizes = m_Ui->splitter->sizes();
152 if (checked) {
157 if (checked) {
153 // adjust sizes individually here, e.g.
158 // adjust sizes individually here, e.g.
154 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
159 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
155 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
160 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
156 m_Ui->splitter->setSizes(currentSizes);
161 m_Ui->splitter->setSizes(currentSizes);
157 }
162 }
158 else {
163 else {
159 // adjust sizes individually here, e.g.
164 // adjust sizes individually here, e.g.
160 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
165 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
161 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
166 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
162 m_Ui->splitter->setSizes(currentSizes);
167 m_Ui->splitter->setSizes(currentSizes);
163 }
168 }
164
169
165 };
170 };
166
171
167
172
168 connect(openLeftInspectorAction, &QAction::triggered,
173 connect(openLeftInspectorAction, &QAction::triggered,
169 [openInspector, openLeftInspectorAction](bool checked) {
174 [openInspector, openLeftInspectorAction](bool checked) {
170 openInspector(checked, false, openLeftInspectorAction);
175 openInspector(checked, false, openLeftInspectorAction);
171 });
176 });
172 connect(openRightInspectorAction, &QAction::triggered,
177 connect(openRightInspectorAction, &QAction::triggered,
173 [openInspector, openRightInspectorAction](bool checked) {
178 [openInspector, openRightInspectorAction](bool checked) {
174 openInspector(checked, true, openRightInspectorAction);
179 openInspector(checked, true, openRightInspectorAction);
175 });
180 });
176
181
177 // //////////////// //
182 // //////////////// //
178 // Menu and Toolbar //
183 // Menu and Toolbar //
179 // //////////////// //
184 // //////////////// //
180 this->menuBar()->addAction(tr("File"));
185 this->menuBar()->addAction(tr("File"));
181 auto toolsMenu = this->menuBar()->addMenu(tr("Tools"));
186 auto toolsMenu = this->menuBar()->addMenu(tr("Tools"));
182 toolsMenu->addAction(tr("Settings..."), [this]() {
187 toolsMenu->addAction(tr("Settings..."), [this]() {
183 // Loads settings
188 // Loads settings
184 impl->m_SettingsDialog->loadSettings();
189 impl->m_SettingsDialog->loadSettings();
185
190
186 // Open settings dialog and save settings if the dialog is accepted
191 // Open settings dialog and save settings if the dialog is accepted
187 if (impl->m_SettingsDialog->exec() == QDialog::Accepted) {
192 if (impl->m_SettingsDialog->exec() == QDialog::Accepted) {
188 impl->m_SettingsDialog->saveSettings();
193 impl->m_SettingsDialog->saveSettings();
189 }
194 }
190
195
191 });
196 });
192
197
193 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
198 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
194
199
195 auto timeWidget = new TimeWidget{};
200 auto timeWidget = new TimeWidget{};
196 mainToolBar->addWidget(timeWidget);
201 mainToolBar->addWidget(timeWidget);
197
202
198 // Interaction modes
203 // Interaction modes
199 auto actionPointerMode = new QAction{QIcon(":/icones/pointer.png"), "Move", this};
204 auto actionPointerMode = new QAction{QIcon(":/icones/pointer.png"), "Move", this};
200 actionPointerMode->setCheckable(true);
205 actionPointerMode->setCheckable(true);
201 actionPointerMode->setChecked(sqpApp->plotsInteractionMode()
206 actionPointerMode->setChecked(sqpApp->plotsInteractionMode()
202 == SqpApplication::PlotsInteractionMode::None);
207 == SqpApplication::PlotsInteractionMode::None);
203 connect(actionPointerMode, &QAction::triggered,
208 connect(actionPointerMode, &QAction::triggered,
204 []() { sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::None); });
209 []() { sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::None); });
205
210
206 auto actionZoomMode = new QAction{QIcon(":/icones/zoom.png"), "Zoom", this};
211 auto actionZoomMode = new QAction{QIcon(":/icones/zoom.png"), "Zoom", this};
207 actionZoomMode->setCheckable(true);
212 actionZoomMode->setCheckable(true);
208 actionZoomMode->setChecked(sqpApp->plotsInteractionMode()
213 actionZoomMode->setChecked(sqpApp->plotsInteractionMode()
209 == SqpApplication::PlotsInteractionMode::ZoomBox);
214 == SqpApplication::PlotsInteractionMode::ZoomBox);
210 connect(actionZoomMode, &QAction::triggered, []() {
215 connect(actionZoomMode, &QAction::triggered, []() {
211 sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::ZoomBox);
216 sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::ZoomBox);
212 });
217 });
213
218
214 auto actionOrganisationMode = new QAction{QIcon(":/icones/drag.png"), "Organize", this};
219 auto actionOrganisationMode = new QAction{QIcon(":/icones/drag.png"), "Organize", this};
215 actionOrganisationMode->setCheckable(true);
220 actionOrganisationMode->setCheckable(true);
216 actionOrganisationMode->setChecked(sqpApp->plotsInteractionMode()
221 actionOrganisationMode->setChecked(sqpApp->plotsInteractionMode()
217 == SqpApplication::PlotsInteractionMode::DragAndDrop);
222 == SqpApplication::PlotsInteractionMode::DragAndDrop);
218 connect(actionOrganisationMode, &QAction::triggered, []() {
223 connect(actionOrganisationMode, &QAction::triggered, []() {
219 sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::DragAndDrop);
224 sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::DragAndDrop);
220 });
225 });
221
226
222 auto actionZonesMode = new QAction{QIcon(":/icones/rectangle.png"), "Zones", this};
227 auto actionZonesMode = new QAction{QIcon(":/icones/rectangle.png"), "Zones", this};
223 actionZonesMode->setCheckable(true);
228 actionZonesMode->setCheckable(true);
224 actionZonesMode->setChecked(sqpApp->plotsInteractionMode()
229 actionZonesMode->setChecked(sqpApp->plotsInteractionMode()
225 == SqpApplication::PlotsInteractionMode::SelectionZones);
230 == SqpApplication::PlotsInteractionMode::SelectionZones);
226 connect(actionZonesMode, &QAction::triggered, []() {
231 connect(actionZonesMode, &QAction::triggered, []() {
227 sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::SelectionZones);
232 sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::SelectionZones);
228 });
233 });
229
234
230 auto modeActionGroup = new QActionGroup{this};
235 auto modeActionGroup = new QActionGroup{this};
231 modeActionGroup->addAction(actionZoomMode);
236 modeActionGroup->addAction(actionZoomMode);
232 modeActionGroup->addAction(actionZonesMode);
237 modeActionGroup->addAction(actionZonesMode);
233 modeActionGroup->addAction(actionOrganisationMode);
238 modeActionGroup->addAction(actionOrganisationMode);
234 modeActionGroup->addAction(actionPointerMode);
239 modeActionGroup->addAction(actionPointerMode);
235 modeActionGroup->setExclusive(true);
240 modeActionGroup->setExclusive(true);
236
241
237 mainToolBar->addSeparator();
242 mainToolBar->addSeparator();
238 mainToolBar->addAction(actionPointerMode);
243 mainToolBar->addAction(actionPointerMode);
239 mainToolBar->addAction(actionZoomMode);
244 mainToolBar->addAction(actionZoomMode);
240 mainToolBar->addAction(actionOrganisationMode);
245 mainToolBar->addAction(actionOrganisationMode);
241 mainToolBar->addAction(actionZonesMode);
246 mainToolBar->addAction(actionZonesMode);
242 mainToolBar->addSeparator();
247 mainToolBar->addSeparator();
243
248
244 // Cursors
249 // Cursors
245 auto btnCursor = new QToolButton{this};
250 auto btnCursor = new QToolButton{this};
246 btnCursor->setIcon(QIcon(":/icones/cursor.png"));
251 btnCursor->setIcon(QIcon(":/icones/cursor.png"));
247 btnCursor->setText("Cursor");
252 btnCursor->setText("Cursor");
248 btnCursor->setToolTip("Cursor");
253 btnCursor->setToolTip("Cursor");
249 btnCursor->setPopupMode(QToolButton::InstantPopup);
254 btnCursor->setPopupMode(QToolButton::InstantPopup);
250 auto cursorMenu = new QMenu("CursorMenu", this);
255 auto cursorMenu = new QMenu("CursorMenu", this);
251 btnCursor->setMenu(cursorMenu);
256 btnCursor->setMenu(cursorMenu);
252
257
253 auto noCursorAction = cursorMenu->addAction("No Cursor");
258 auto noCursorAction = cursorMenu->addAction("No Cursor");
254 noCursorAction->setCheckable(true);
259 noCursorAction->setCheckable(true);
255 noCursorAction->setChecked(sqpApp->plotsCursorMode()
260 noCursorAction->setChecked(sqpApp->plotsCursorMode()
256 == SqpApplication::PlotsCursorMode::NoCursor);
261 == SqpApplication::PlotsCursorMode::NoCursor);
257 connect(noCursorAction, &QAction::triggered,
262 connect(noCursorAction, &QAction::triggered,
258 []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::NoCursor); });
263 []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::NoCursor); });
259
264
260 cursorMenu->addSeparator();
265 cursorMenu->addSeparator();
261 auto verticalCursorAction = cursorMenu->addAction("Vertical Cursor");
266 auto verticalCursorAction = cursorMenu->addAction("Vertical Cursor");
262 verticalCursorAction->setCheckable(true);
267 verticalCursorAction->setCheckable(true);
263 verticalCursorAction->setChecked(sqpApp->plotsCursorMode()
268 verticalCursorAction->setChecked(sqpApp->plotsCursorMode()
264 == SqpApplication::PlotsCursorMode::Vertical);
269 == SqpApplication::PlotsCursorMode::Vertical);
265 connect(verticalCursorAction, &QAction::triggered,
270 connect(verticalCursorAction, &QAction::triggered,
266 []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Vertical); });
271 []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Vertical); });
267
272
268 auto temporalCursorAction = cursorMenu->addAction("Temporal Cursor");
273 auto temporalCursorAction = cursorMenu->addAction("Temporal Cursor");
269 temporalCursorAction->setCheckable(true);
274 temporalCursorAction->setCheckable(true);
270 temporalCursorAction->setChecked(sqpApp->plotsCursorMode()
275 temporalCursorAction->setChecked(sqpApp->plotsCursorMode()
271 == SqpApplication::PlotsCursorMode::Temporal);
276 == SqpApplication::PlotsCursorMode::Temporal);
272 connect(temporalCursorAction, &QAction::triggered,
277 connect(temporalCursorAction, &QAction::triggered,
273 []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Temporal); });
278 []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Temporal); });
274
279
275 auto horizontalCursorAction = cursorMenu->addAction("Horizontal Cursor");
280 auto horizontalCursorAction = cursorMenu->addAction("Horizontal Cursor");
276 horizontalCursorAction->setCheckable(true);
281 horizontalCursorAction->setCheckable(true);
277 horizontalCursorAction->setChecked(sqpApp->plotsCursorMode()
282 horizontalCursorAction->setChecked(sqpApp->plotsCursorMode()
278 == SqpApplication::PlotsCursorMode::Horizontal);
283 == SqpApplication::PlotsCursorMode::Horizontal);
279 connect(horizontalCursorAction, &QAction::triggered,
284 connect(horizontalCursorAction, &QAction::triggered,
280 []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Horizontal); });
285 []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Horizontal); });
281
286
282 auto crossCursorAction = cursorMenu->addAction("Cross Cursor");
287 auto crossCursorAction = cursorMenu->addAction("Cross Cursor");
283 crossCursorAction->setCheckable(true);
288 crossCursorAction->setCheckable(true);
284 crossCursorAction->setChecked(sqpApp->plotsCursorMode()
289 crossCursorAction->setChecked(sqpApp->plotsCursorMode()
285 == SqpApplication::PlotsCursorMode::Cross);
290 == SqpApplication::PlotsCursorMode::Cross);
286 connect(crossCursorAction, &QAction::triggered,
291 connect(crossCursorAction, &QAction::triggered,
287 []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Cross); });
292 []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Cross); });
288
293
289 mainToolBar->addWidget(btnCursor);
294 mainToolBar->addWidget(btnCursor);
290
295
291 auto cursorModeActionGroup = new QActionGroup{this};
296 auto cursorModeActionGroup = new QActionGroup{this};
292 cursorModeActionGroup->setExclusive(true);
297 cursorModeActionGroup->setExclusive(true);
293 cursorModeActionGroup->addAction(noCursorAction);
298 cursorModeActionGroup->addAction(noCursorAction);
294 cursorModeActionGroup->addAction(verticalCursorAction);
299 cursorModeActionGroup->addAction(verticalCursorAction);
295 cursorModeActionGroup->addAction(temporalCursorAction);
300 cursorModeActionGroup->addAction(temporalCursorAction);
296 cursorModeActionGroup->addAction(horizontalCursorAction);
301 cursorModeActionGroup->addAction(horizontalCursorAction);
297 cursorModeActionGroup->addAction(crossCursorAction);
302 cursorModeActionGroup->addAction(crossCursorAction);
298
303
299 // Catalog
304 // Catalog
300 mainToolBar->addSeparator();
305 mainToolBar->addSeparator();
301 mainToolBar->addAction(QIcon(":/icones/catalogue.png"), "Catalogues",
306 mainToolBar->addAction(QIcon(":/icones/catalogue.png"), "Catalogues",
302 [this]() { impl->m_CatalogExplorer->show(); });
307 [this]() { impl->m_CatalogExplorer->show(); });
303
308
304 // //////// //
309 // //////// //
305 // Settings //
310 // Settings //
306 // //////// //
311 // //////// //
307
312
308 // Registers "general settings" widget to the settings dialog
313 // Registers "general settings" widget to the settings dialog
309 impl->m_SettingsDialog->registerWidget(QStringLiteral("General"),
314 impl->m_SettingsDialog->registerWidget(QStringLiteral("General"),
310 impl->m_GeneralSettingsWidget);
315 impl->m_GeneralSettingsWidget);
311
316
312 // /////////// //
317 // /////////// //
313 // Connections //
318 // Connections //
314 // /////////// //
319 // /////////// //
315
320
316 // Controllers / controllers connections
321 // Controllers / controllers connections
317 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpRange)), &sqpApp->variableController(),
322 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpRange)), &sqpApp->variableController(),
318 SLOT(onDateTimeOnSelection(SqpRange)));
323 SLOT(onDateTimeOnSelection(SqpRange)));
319
324
320 // Widgets / controllers connections
325 // Widgets / controllers connections
321
326
322 // DataSource
327 // DataSource
323 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
328 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
324 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
329 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
325
330
326 // Time
331 // Time
327 connect(timeWidget, SIGNAL(timeUpdated(SqpRange)), &sqpApp->timeController(),
332 connect(timeWidget, SIGNAL(timeUpdated(SqpRange)), &sqpApp->timeController(),
328 SLOT(onTimeToUpdate(SqpRange)));
333 SLOT(onTimeToUpdate(SqpRange)));
329
334
330 // Visualization
335 // Visualization
331 connect(&sqpApp->visualizationController(),
336 connect(&sqpApp->visualizationController(),
332 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view,
337 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view,
333 SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>)));
338 SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>)));
334
339
335 connect(&sqpApp->visualizationController(),
340 connect(&sqpApp->visualizationController(),
336 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)), m_Ui->view,
341 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)), m_Ui->view,
337 SLOT(onRangeChanged(std::shared_ptr<Variable>, const SqpRange &)));
342 SLOT(onRangeChanged(std::shared_ptr<Variable>, const SqpRange &)));
338
343
339 // Widgets / widgets connections
344 // Widgets / widgets connections
340
345
341 // For the following connections, we use DirectConnection to allow each widget that can
346 // For the following connections, we use DirectConnection to allow each widget that can
342 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
347 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
343 // The order of connections is also important, since it determines the order in which each
348 // The order of connections is also important, since it determines the order in which each
344 // widget will attach its menu
349 // widget will attach its menu
345 connect(
350 connect(
346 m_Ui->variableInspectorWidget,
351 m_Ui->variableInspectorWidget,
347 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
352 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
348 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
353 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
349 Qt::DirectConnection);
354 Qt::DirectConnection);
350 }
355 }
351
356
352 MainWindow::~MainWindow()
357 MainWindow::~MainWindow()
353 {
358 {
354 }
359 }
355
360
356 void MainWindow::changeEvent(QEvent *e)
361 void MainWindow::changeEvent(QEvent *e)
357 {
362 {
358 QMainWindow::changeEvent(e);
363 QMainWindow::changeEvent(e);
359 switch (e->type()) {
364 switch (e->type()) {
360 case QEvent::LanguageChange:
365 case QEvent::LanguageChange:
361 m_Ui->retranslateUi(this);
366 m_Ui->retranslateUi(this);
362 break;
367 break;
363 default:
368 default:
364 break;
369 break;
365 }
370 }
366 }
371 }
372
373 void MainWindow::closeEvent(QCloseEvent *event)
374 {
375 if (!impl->checkDataToSave(this)) {
376 event->ignore();
377 }
378 else {
379 event->accept();
380 }
381 }
382
383 bool MainWindow::MainWindowPrivate::checkDataToSave(QWidget *parentWidget)
384 {
385 auto hasChanges = sqpApp->catalogueController().hasChanges();
386 if (hasChanges) {
387 // There are some unsaved changes
388 switch (QMessageBox::question(
389 parentWidget, "Save changes",
390 tr("The catalogue controller unsaved changes.\nDo you want to save them ?"),
391 QMessageBox::SaveAll | QMessageBox::Discard | QMessageBox::Cancel,
392 QMessageBox::SaveAll)) {
393 case QMessageBox::SaveAll:
394 sqpApp->catalogueController().saveAll();
395 break;
396 case QMessageBox::Discard:
397 break;
398 case QMessageBox::Cancel:
399 default:
400 return false;
401 }
402 }
403
404 return true;
405 }
@@ -1,81 +1,82
1 #ifndef SCIQLOP_CATALOGUECONTROLLER_H
1 #ifndef SCIQLOP_CATALOGUECONTROLLER_H
2 #define SCIQLOP_CATALOGUECONTROLLER_H
2 #define SCIQLOP_CATALOGUECONTROLLER_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <Data/SqpRange.h>
6 #include <Data/SqpRange.h>
7
7
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9 #include <QObject>
9 #include <QObject>
10 #include <QUuid>
10 #include <QUuid>
11
11
12 #include <Common/spimpl.h>
12 #include <Common/spimpl.h>
13
13
14 #include <memory>
14 #include <memory>
15
15
16 class DBCatalogue;
16 class DBCatalogue;
17 class DBEvent;
17 class DBEvent;
18 class DBEventProduct;
18 class DBEventProduct;
19
19
20 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
20 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
21
21
22 class DataSourceItem;
22 class DataSourceItem;
23 class Variable;
23 class Variable;
24
24
25 /**
25 /**
26 * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI
26 * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI
27 * library.
27 * library.
28 */
28 */
29 class SCIQLOP_CORE_EXPORT CatalogueController : public QObject {
29 class SCIQLOP_CORE_EXPORT CatalogueController : public QObject {
30 Q_OBJECT
30 Q_OBJECT
31 public:
31 public:
32 explicit CatalogueController(QObject *parent = 0);
32 explicit CatalogueController(QObject *parent = 0);
33 virtual ~CatalogueController();
33 virtual ~CatalogueController();
34
34
35 // DB
35 // DB
36 QStringList getRepositories() const;
36 QStringList getRepositories() const;
37 void addDB(const QString &dbPath);
37 void addDB(const QString &dbPath);
38 void saveDB(const QString &destinationPath, const QString &repository);
38 void saveDB(const QString &destinationPath, const QString &repository);
39
39
40 // Event
40 // Event
41 /// retrieveEvents with empty repository retrieve them from the default repository
41 /// retrieveEvents with empty repository retrieve them from the default repository
42 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
42 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
43 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
43 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
44 std::list<std::shared_ptr<DBEvent> >
44 std::list<std::shared_ptr<DBEvent> >
45 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
45 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
46 void addEvent(std::shared_ptr<DBEvent> event);
46 void addEvent(std::shared_ptr<DBEvent> event);
47 void updateEvent(std::shared_ptr<DBEvent> event);
47 void updateEvent(std::shared_ptr<DBEvent> event);
48 void updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct);
48 void updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct);
49 void removeEvent(std::shared_ptr<DBEvent> event);
49 void removeEvent(std::shared_ptr<DBEvent> event);
50 // void trashEvent(std::shared_ptr<DBEvent> event);
50 // void trashEvent(std::shared_ptr<DBEvent> event);
51 // void restore(QUuid eventId);
51 // void restore(QUuid eventId);
52 void saveEvent(std::shared_ptr<DBEvent> event);
52 void saveEvent(std::shared_ptr<DBEvent> event);
53 bool eventHasChanges(std::shared_ptr<DBEvent> event) const;
53 bool eventHasChanges(std::shared_ptr<DBEvent> event) const;
54
54
55 // Catalogue
55 // Catalogue
56 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
56 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
57 /// retrieveEvents with empty repository retrieve them from the default repository
57 /// retrieveEvents with empty repository retrieve them from the default repository
58 std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository
58 std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository
59 = QString()) const;
59 = QString()) const;
60 void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue);
60 void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue);
61 void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue);
61 void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue);
62 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
62 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
63
63
64 void saveAll();
64 void saveAll();
65 bool hasChanges() const;
65
66
66 /// Returns the MIME data associated to a list of variables
67 /// Returns the MIME data associated to a list of variables
67 QByteArray mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const;
68 QByteArray mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const;
68
69
69 /// Returns the list of variables contained in a MIME data
70 /// Returns the list of variables contained in a MIME data
70 QVector<std::shared_ptr<DBEvent> > eventsForMimeData(const QByteArray &mimeData) const;
71 QVector<std::shared_ptr<DBEvent> > eventsForMimeData(const QByteArray &mimeData) const;
71
72
72 public slots:
73 public slots:
73 /// Manage init/end of the controller
74 /// Manage init/end of the controller
74 void initialize();
75 void initialize();
75
76
76 private:
77 private:
77 class CatalogueControllerPrivate;
78 class CatalogueControllerPrivate;
78 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
79 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
79 };
80 };
80
81
81 #endif // SCIQLOP_CATALOGUECONTROLLER_H
82 #endif // SCIQLOP_CATALOGUECONTROLLER_H
@@ -1,388 +1,393
1 #include <Catalogue/CatalogueController.h>
1 #include <Catalogue/CatalogueController.h>
2
2
3 #include <Variable/Variable.h>
3 #include <Variable/Variable.h>
4
4
5 #include <CatalogueDao.h>
5 #include <CatalogueDao.h>
6
6
7 #include <ComparaisonPredicate.h>
7 #include <ComparaisonPredicate.h>
8 #include <CompoundPredicate.h>
8 #include <CompoundPredicate.h>
9 #include <DBCatalogue.h>
9 #include <DBCatalogue.h>
10 #include <DBEvent.h>
10 #include <DBEvent.h>
11 #include <DBEventProduct.h>
11 #include <DBEventProduct.h>
12 #include <DBTag.h>
12 #include <DBTag.h>
13 #include <IRequestPredicate.h>
13 #include <IRequestPredicate.h>
14
14
15 #include <QDataStream>
15 #include <QDataStream>
16 #include <QMutex>
16 #include <QMutex>
17 #include <QThread>
17 #include <QThread>
18
18
19 #include <QDir>
19 #include <QDir>
20 #include <QStandardPaths>
20 #include <QStandardPaths>
21
21
22 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
22 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
23
23
24 namespace {
24 namespace {
25
25
26 static QString REPOSITORY_WORK_SUFFIX = QString{"_work"};
26 static QString REPOSITORY_WORK_SUFFIX = QString{"_work"};
27 static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"};
27 static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"};
28 }
28 }
29
29
30 class CatalogueController::CatalogueControllerPrivate {
30 class CatalogueController::CatalogueControllerPrivate {
31
31
32 public:
32 public:
33 explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {}
33 explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {}
34
34
35 CatalogueDao m_CatalogueDao;
35 CatalogueDao m_CatalogueDao;
36
36
37 QStringList m_RepositoryList;
37 QStringList m_RepositoryList;
38 CatalogueController *m_Q;
38 CatalogueController *m_Q;
39
39
40 QSet<QString> m_EventKeysWithChanges;
40 QSet<QString> m_EventKeysWithChanges;
41
41
42 QString eventUniqueKey(const std::shared_ptr<DBEvent> &event) const;
42 QString eventUniqueKey(const std::shared_ptr<DBEvent> &event) const;
43
43
44 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
44 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
45 QString toWorkRepository(QString repository);
45 QString toWorkRepository(QString repository);
46 QString toSyncRepository(QString repository);
46 QString toSyncRepository(QString repository);
47 void savAllDB();
47 void savAllDB();
48
48
49 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
49 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
50 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
50 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
51 };
51 };
52
52
53 CatalogueController::CatalogueController(QObject *parent)
53 CatalogueController::CatalogueController(QObject *parent)
54 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)}
54 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)}
55 {
55 {
56 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
56 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
57 << QThread::currentThread();
57 << QThread::currentThread();
58 }
58 }
59
59
60 CatalogueController::~CatalogueController()
60 CatalogueController::~CatalogueController()
61 {
61 {
62 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
62 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
63 << QThread::currentThread();
63 << QThread::currentThread();
64 }
64 }
65
65
66 QStringList CatalogueController::getRepositories() const
66 QStringList CatalogueController::getRepositories() const
67 {
67 {
68 return impl->m_RepositoryList;
68 return impl->m_RepositoryList;
69 }
69 }
70
70
71 void CatalogueController::addDB(const QString &dbPath)
71 void CatalogueController::addDB(const QString &dbPath)
72 {
72 {
73 QDir dbDir(dbPath);
73 QDir dbDir(dbPath);
74 if (dbDir.exists()) {
74 if (dbDir.exists()) {
75 auto dirName = dbDir.dirName();
75 auto dirName = dbDir.dirName();
76
76
77 if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName)
77 if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName)
78 != impl->m_RepositoryList.cend()) {
78 != impl->m_RepositoryList.cend()) {
79 qCCritical(LOG_CatalogueController())
79 qCCritical(LOG_CatalogueController())
80 << tr("Impossible to addDB that is already loaded");
80 << tr("Impossible to addDB that is already loaded");
81 }
81 }
82
82
83 if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) {
83 if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) {
84 qCCritical(LOG_CatalogueController())
84 qCCritical(LOG_CatalogueController())
85 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
85 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
86 }
86 }
87 else {
87 else {
88 impl->m_RepositoryList << dirName;
88 impl->m_RepositoryList << dirName;
89 impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName));
89 impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName));
90 }
90 }
91 }
91 }
92 else {
92 else {
93 qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ")
93 qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ")
94 << dbPath;
94 << dbPath;
95 }
95 }
96 }
96 }
97
97
98 void CatalogueController::saveDB(const QString &destinationPath, const QString &repository)
98 void CatalogueController::saveDB(const QString &destinationPath, const QString &repository)
99 {
99 {
100 if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) {
100 if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) {
101 qCCritical(LOG_CatalogueController())
101 qCCritical(LOG_CatalogueController())
102 << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath);
102 << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath);
103 }
103 }
104 }
104 }
105
105
106 std::list<std::shared_ptr<DBEvent> >
106 std::list<std::shared_ptr<DBEvent> >
107 CatalogueController::retrieveEvents(const QString &repository) const
107 CatalogueController::retrieveEvents(const QString &repository) const
108 {
108 {
109 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
109 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
110
110
111 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
111 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
112 auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName));
112 auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName));
113 for (auto event : events) {
113 for (auto event : events) {
114 eventsShared.push_back(std::make_shared<DBEvent>(event));
114 eventsShared.push_back(std::make_shared<DBEvent>(event));
115 }
115 }
116 return eventsShared;
116 return eventsShared;
117 }
117 }
118
118
119 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const
119 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const
120 {
120 {
121 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
121 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
122 for (auto repository : impl->m_RepositoryList) {
122 for (auto repository : impl->m_RepositoryList) {
123 eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
123 eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
124 }
124 }
125
125
126 return eventsShared;
126 return eventsShared;
127 }
127 }
128
128
129 std::list<std::shared_ptr<DBEvent> >
129 std::list<std::shared_ptr<DBEvent> >
130 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const
130 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const
131 {
131 {
132 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
132 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
133 auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue);
133 auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue);
134 for (auto event : events) {
134 for (auto event : events) {
135 eventsShared.push_back(std::make_shared<DBEvent>(event));
135 eventsShared.push_back(std::make_shared<DBEvent>(event));
136 }
136 }
137 return eventsShared;
137 return eventsShared;
138 }
138 }
139
139
140 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
140 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
141 {
141 {
142 event->setRepository(impl->toWorkRepository(event->getRepository()));
142 event->setRepository(impl->toWorkRepository(event->getRepository()));
143
143
144 auto uniqueId = impl->eventUniqueKey(event);
144 auto uniqueId = impl->eventUniqueKey(event);
145 impl->m_EventKeysWithChanges.insert(uniqueId);
145 impl->m_EventKeysWithChanges.insert(uniqueId);
146
146
147 impl->m_CatalogueDao.updateEvent(*event);
147 impl->m_CatalogueDao.updateEvent(*event);
148 }
148 }
149
149
150 void CatalogueController::updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct)
150 void CatalogueController::updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct)
151 {
151 {
152 impl->m_CatalogueDao.updateEventProduct(*eventProduct);
152 impl->m_CatalogueDao.updateEventProduct(*eventProduct);
153 }
153 }
154
154
155 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
155 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
156 {
156 {
157 // Remove it from both repository and repository_work
157 // Remove it from both repository and repository_work
158 event->setRepository(impl->toWorkRepository(event->getRepository()));
158 event->setRepository(impl->toWorkRepository(event->getRepository()));
159 impl->m_CatalogueDao.removeEvent(*event);
159 impl->m_CatalogueDao.removeEvent(*event);
160 event->setRepository(impl->toSyncRepository(event->getRepository()));
160 event->setRepository(impl->toSyncRepository(event->getRepository()));
161 impl->m_CatalogueDao.removeEvent(*event);
161 impl->m_CatalogueDao.removeEvent(*event);
162 }
162 }
163
163
164 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
164 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
165 {
165 {
166 event->setRepository(impl->toWorkRepository(event->getRepository()));
166 event->setRepository(impl->toWorkRepository(event->getRepository()));
167
167
168 auto eventTemp = *event;
168 auto eventTemp = *event;
169 impl->m_CatalogueDao.addEvent(eventTemp);
169 impl->m_CatalogueDao.addEvent(eventTemp);
170
170
171 // Call update is necessary at the creation of add Event if it has some tags or some event
171 // Call update is necessary at the creation of add Event if it has some tags or some event
172 // products
172 // products
173 if (!event->getEventProducts().empty() || !event->getTags().empty()) {
173 if (!event->getEventProducts().empty() || !event->getTags().empty()) {
174
174
175 auto eventProductsTemp = eventTemp.getEventProducts();
175 auto eventProductsTemp = eventTemp.getEventProducts();
176 auto eventProductTempUpdated = std::list<DBEventProduct>{};
176 auto eventProductTempUpdated = std::list<DBEventProduct>{};
177 for (auto eventProductTemp : eventProductsTemp) {
177 for (auto eventProductTemp : eventProductsTemp) {
178 eventProductTemp.setEvent(eventTemp);
178 eventProductTemp.setEvent(eventTemp);
179 eventProductTempUpdated.push_back(eventProductTemp);
179 eventProductTempUpdated.push_back(eventProductTemp);
180 }
180 }
181 eventTemp.setEventProducts(eventProductTempUpdated);
181 eventTemp.setEventProducts(eventProductTempUpdated);
182
182
183 impl->m_CatalogueDao.updateEvent(eventTemp);
183 impl->m_CatalogueDao.updateEvent(eventTemp);
184 }
184 }
185 }
185 }
186
186
187 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
187 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
188 {
188 {
189 impl->saveEvent(event, true);
189 impl->saveEvent(event, true);
190 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
190 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
191 }
191 }
192
192
193 bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const
193 bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const
194 {
194 {
195 return impl->m_EventKeysWithChanges.contains(impl->eventUniqueKey(event));
195 return impl->m_EventKeysWithChanges.contains(impl->eventUniqueKey(event));
196 }
196 }
197
197
198 std::list<std::shared_ptr<DBCatalogue> >
198 std::list<std::shared_ptr<DBCatalogue> >
199 CatalogueController::retrieveCatalogues(const QString &repository) const
199 CatalogueController::retrieveCatalogues(const QString &repository) const
200 {
200 {
201 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
201 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
202
202
203 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
203 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
204 auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName));
204 auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName));
205 for (auto catalogue : catalogues) {
205 for (auto catalogue : catalogues) {
206 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
206 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
207 }
207 }
208 return cataloguesShared;
208 return cataloguesShared;
209 }
209 }
210
210
211 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
211 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
212 {
212 {
213 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
213 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
214
214
215 impl->m_CatalogueDao.updateCatalogue(*catalogue);
215 impl->m_CatalogueDao.updateCatalogue(*catalogue);
216 }
216 }
217
217
218 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue)
218 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue)
219 {
219 {
220 // Remove it from both repository and repository_work
220 // Remove it from both repository and repository_work
221 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
221 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
222 impl->m_CatalogueDao.removeCatalogue(*catalogue);
222 impl->m_CatalogueDao.removeCatalogue(*catalogue);
223 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
223 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
224 impl->m_CatalogueDao.removeCatalogue(*catalogue);
224 impl->m_CatalogueDao.removeCatalogue(*catalogue);
225 }
225 }
226
226
227 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
227 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
228 {
228 {
229 impl->saveCatalogue(catalogue, true);
229 impl->saveCatalogue(catalogue, true);
230 }
230 }
231
231
232 void CatalogueController::saveAll()
232 void CatalogueController::saveAll()
233 {
233 {
234 for (auto repository : impl->m_RepositoryList) {
234 for (auto repository : impl->m_RepositoryList) {
235 // Save Event
235 // Save Event
236 auto events = this->retrieveEvents(repository);
236 auto events = this->retrieveEvents(repository);
237 for (auto event : events) {
237 for (auto event : events) {
238 impl->saveEvent(event, false);
238 impl->saveEvent(event, false);
239 }
239 }
240
240
241 // Save Catalogue
241 // Save Catalogue
242 auto catalogues = this->retrieveCatalogues(repository);
242 auto catalogues = this->retrieveCatalogues(repository);
243 for (auto catalogue : catalogues) {
243 for (auto catalogue : catalogues) {
244 impl->saveCatalogue(catalogue, false);
244 impl->saveCatalogue(catalogue, false);
245 }
245 }
246 }
246 }
247
247
248 impl->savAllDB();
248 impl->savAllDB();
249 impl->m_EventKeysWithChanges.clear();
249 impl->m_EventKeysWithChanges.clear();
250 }
250 }
251
251
252 bool CatalogueController::hasChanges() const
253 {
254 return !impl->m_EventKeysWithChanges.isEmpty(); // TODO: catalogues
255 }
256
252 QByteArray
257 QByteArray
253 CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const
258 CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const
254 {
259 {
255 auto encodedData = QByteArray{};
260 auto encodedData = QByteArray{};
256
261
257 QMap<QString, QVariantList> idsPerRepository;
262 QMap<QString, QVariantList> idsPerRepository;
258 for (auto event : events) {
263 for (auto event : events) {
259 idsPerRepository[event->getRepository()] << event->getUniqId();
264 idsPerRepository[event->getRepository()] << event->getUniqId();
260 }
265 }
261
266
262 QDataStream stream{&encodedData, QIODevice::WriteOnly};
267 QDataStream stream{&encodedData, QIODevice::WriteOnly};
263 stream << idsPerRepository;
268 stream << idsPerRepository;
264
269
265 return encodedData;
270 return encodedData;
266 }
271 }
267
272
268 QVector<std::shared_ptr<DBEvent> >
273 QVector<std::shared_ptr<DBEvent> >
269 CatalogueController::eventsForMimeData(const QByteArray &mimeData) const
274 CatalogueController::eventsForMimeData(const QByteArray &mimeData) const
270 {
275 {
271 auto events = QVector<std::shared_ptr<DBEvent> >{};
276 auto events = QVector<std::shared_ptr<DBEvent> >{};
272 QDataStream stream{mimeData};
277 QDataStream stream{mimeData};
273
278
274 QMap<QString, QVariantList> idsPerRepository;
279 QMap<QString, QVariantList> idsPerRepository;
275 stream >> idsPerRepository;
280 stream >> idsPerRepository;
276
281
277 for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) {
282 for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) {
278 auto repository = it.key();
283 auto repository = it.key();
279 auto allRepositoryEvent = retrieveEvents(repository);
284 auto allRepositoryEvent = retrieveEvents(repository);
280 for (auto uuid : it.value()) {
285 for (auto uuid : it.value()) {
281 for (auto repositoryEvent : allRepositoryEvent) {
286 for (auto repositoryEvent : allRepositoryEvent) {
282 if (uuid.toUuid() == repositoryEvent->getUniqId()) {
287 if (uuid.toUuid() == repositoryEvent->getUniqId()) {
283 events << repositoryEvent;
288 events << repositoryEvent;
284 }
289 }
285 }
290 }
286 }
291 }
287 }
292 }
288
293
289 return events;
294 return events;
290 }
295 }
291
296
292 void CatalogueController::initialize()
297 void CatalogueController::initialize()
293 {
298 {
294 <<<<<<< HEAD
299 <<<<<<< HEAD
295 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
300 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
296 << QThread::currentThread();
301 << QThread::currentThread();
297 impl->m_WorkingMutex.lock();
302 impl->m_WorkingMutex.lock();
298 =======
303 =======
299 qCDebug(LOG_CatalogueController())
304 qCDebug(LOG_CatalogueController())
300 << tr("CatalogueController init") << QThread::currentThread();
305 << tr("CatalogueController init") << QThread::currentThread();
301 >>>>>>> 286decc... unthread the catalogue controller
306 >>>>>>> 286decc... unthread the catalogue controller
302 impl->m_CatalogueDao.initialize();
307 impl->m_CatalogueDao.initialize();
303 auto defaultRepositoryLocation
308 auto defaultRepositoryLocation
304 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
309 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
305
310
306 QDir defaultRepositoryLocationDir;
311 QDir defaultRepositoryLocationDir;
307 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
312 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
308 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
313 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
309 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
314 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
310 qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ")
315 qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ")
311 << defaultRepository;
316 << defaultRepository;
312 this->addDB(defaultRepository);
317 this->addDB(defaultRepository);
313 }
318 }
314 else {
319 else {
315 qCWarning(LOG_CatalogueController())
320 qCWarning(LOG_CatalogueController())
316 << tr("Cannot load the persistent default repository from ")
321 << tr("Cannot load the persistent default repository from ")
317 << defaultRepositoryLocation;
322 << defaultRepositoryLocation;
318 }
323 }
319
324
320 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
325 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
321 }
326 }
322
327
323 QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey(
328 QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey(
324 const std::shared_ptr<DBEvent> &event) const
329 const std::shared_ptr<DBEvent> &event) const
325 {
330 {
326 return event->getUniqId().toString().append(event->getRepository());
331 return event->getUniqId().toString().append(event->getRepository());
327 }
332 }
328
333
329 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
334 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
330 const QString &dbTo)
335 const QString &dbTo)
331 {
336 {
332 // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
337 // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
333 auto catalogues = m_CatalogueDao.getCatalogues(dbFrom);
338 auto catalogues = m_CatalogueDao.getCatalogues(dbFrom);
334 auto events = m_CatalogueDao.getEvents(dbFrom);
339 auto events = m_CatalogueDao.getEvents(dbFrom);
335 for (auto catalogue : catalogues) {
340 for (auto catalogue : catalogues) {
336 m_CatalogueDao.copyCatalogue(catalogue, dbTo, true);
341 m_CatalogueDao.copyCatalogue(catalogue, dbTo, true);
337 }
342 }
338
343
339 for (auto event : events) {
344 for (auto event : events) {
340 m_CatalogueDao.copyEvent(event, dbTo, true);
345 m_CatalogueDao.copyEvent(event, dbTo, true);
341 }
346 }
342 }
347 }
343
348
344 QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository)
349 QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository)
345 {
350 {
346 auto syncRepository = toSyncRepository(repository);
351 auto syncRepository = toSyncRepository(repository);
347
352
348 return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX);
353 return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX);
349 }
354 }
350
355
351 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository)
356 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository)
352 {
357 {
353 auto syncRepository = repository;
358 auto syncRepository = repository;
354 if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) {
359 if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) {
355 syncRepository.remove(REPOSITORY_WORK_SUFFIX);
360 syncRepository.remove(REPOSITORY_WORK_SUFFIX);
356 }
361 }
357 else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) {
362 else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) {
358 syncRepository.remove(REPOSITORY_TRASH_SUFFIX);
363 syncRepository.remove(REPOSITORY_TRASH_SUFFIX);
359 }
364 }
360 return syncRepository;
365 return syncRepository;
361 }
366 }
362
367
363 void CatalogueController::CatalogueControllerPrivate::savAllDB()
368 void CatalogueController::CatalogueControllerPrivate::savAllDB()
364 {
369 {
365 for (auto repository : m_RepositoryList) {
370 for (auto repository : m_RepositoryList) {
366 auto defaultRepositoryLocation
371 auto defaultRepositoryLocation
367 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
372 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
368 m_CatalogueDao.saveDB(defaultRepositoryLocation, repository);
373 m_CatalogueDao.saveDB(defaultRepositoryLocation, repository);
369 }
374 }
370 }
375 }
371
376
372 void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event,
377 void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event,
373 bool persist)
378 bool persist)
374 {
379 {
375 m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), true);
380 m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), true);
376 if (persist) {
381 if (persist) {
377 savAllDB();
382 savAllDB();
378 }
383 }
379 }
384 }
380
385
381 void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
386 void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
382 std::shared_ptr<DBCatalogue> catalogue, bool persist)
387 std::shared_ptr<DBCatalogue> catalogue, bool persist)
383 {
388 {
384 m_CatalogueDao.copyCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true);
389 m_CatalogueDao.copyCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true);
385 if (persist) {
390 if (persist) {
386 savAllDB();
391 savAllDB();
387 }
392 }
388 }
393 }
General Comments 0
You need to be logged in to leave comments. Login now