1 // CalendarDataStorage.h - CalendarDataStorage class header
3 // (c) 2016-2017 Xestia Software Development.
5 // This file is part of Xestia Calendar.
7 // Xestia Calendar is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Calendar is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
19 #ifndef __LIBRARIES_CALENDARDATASTORAGE_H__
20 #define __LIBRARIES_CALENDARDATASTORAGE_H__
30 #include "../../objects/calendarevent/CalendarEvent.h"
31 #include "../../common/colour.h"
32 #include "../../common/random.h"
34 enum CDSAccountResult{
35 CDSACCOUNT_UNITTESTFAIL = -1,
42 enum CDSCalendarResult{
43 CDSCALENDAR_UNITTESTFAIL = -1,
47 CDSCALENDAR_NOCALENDAR
51 CDSENTRY_UNITTESTFAIL = -1,
59 CDSENTRY_CANNOTOPENFILE,
63 struct CDSGetAccountInfo{
65 int accountPreferencesID = 0;
66 std::string accountName = "";
67 CDSAccountResult accountInfoResult = CDSACCOUNT_NOACTION;
70 struct CDSGetCalendarInfo{
73 std::string accountName = "";
74 std::string calendarName = "";
75 std::string calendarTextID = "";
76 std::string calendarDescription = "";
77 Colour calendarColour;
78 CDSAccountResult accountInfoResult = CDSACCOUNT_NOACTION;
79 CDSCalendarResult calendarInfoResult = CDSCALENDAR_NOACTION;
82 struct CDSAddEntryResult{
83 int calendarEntryID = 0;
84 CDSEntryResult addEventResult = CDSENTRY_NOACTION;
87 struct CDSEditEntryResult{
88 int calendarEntryID = 0;
89 CDSEntryResult editEventResult = CDSENTRY_NOACTION;
92 struct CDSGetCalendarEntryInfo{
95 int calendarEntryID = 0;
96 std::string entryName = "";
97 std::string entryDescription = "";
98 std::string entryFilename = "";
99 int entryStartYear = 0;
100 int entryStartMonth = 0;
101 int entryStartDay = 0;
102 int entryStartHour = 0;
103 int entryStartMinute = 0;
104 int entryStartSecond = 0;
105 int entryEndYear = 0;
106 int entryEndMonth = 0;
108 int entryEndHour = 0;
109 int entryEndMinute = 0;
110 int entryEndSecond = 0;
111 int entryDurationWeeks = 0;
112 int entryDurationDays = 0;
113 int entryDurationHours = 0;
114 int entryDurationMinutes = 0;
115 int entryDurationSeconds = 0;
116 CDSEntryResult getEventResult = CDSENTRY_NOACTION;
120 std::vector <int> entryList;
121 CDSEntryResult getEventListResult = CDSENTRY_NOACTION;
124 struct CDSCalendarList{
125 std::vector <int> calendarList;
126 std::vector <std::string> calendarListTextID;
127 CDSCalendarResult getCalendarListResult = CDSCALENDAR_NOACTION;
130 struct CDSAccountList{
131 std::vector<CDSGetAccountInfo> accountList;
132 CDSAccountResult getAccountListResult = CDSACCOUNT_NOACTION;
135 enum CDSChecksumResult{
136 CDSCHECKSUM_UNITTESTFAIL = -1,
140 CDSCHECKSUM_CHECKSUMALREADYEXISTS,
144 struct CDSGetChecksumResult{
145 CDSChecksumResult getChecksumResult = CDSCHECKSUM_NORESULT;
146 std::string checksumValue = "";
149 enum CDSCleanupResult{
150 CDSCLEANUP_UNITTESTFAIL = -1,
155 class CalendarDataStorage{
158 sqlite3 *db = nullptr;
160 bool DataStorageInitOK = false;
162 CalendarDataStorage();
163 ~CalendarDataStorage();
166 // Account functions.
168 CDSAccountResult AddAccount(std::string accountName, int accountPreferencesID);
169 CDSGetAccountInfo GetAccount(std::string accountName);
170 CDSAccountResult UpdateAccount(int accountID, std::string accountName);
171 CDSAccountResult DeleteAccount(int accountID);
172 CDSAccountList GetAccountList();
174 // Calendar functions.
176 CDSCalendarResult AddCalendar(int accountID, std::string calendarName, std::string calendarID, Colour calendarColour, std::string calendarDescription);
177 CDSGetCalendarInfo GetCalendar(std::string accountName, std::string calendarTextID);
178 CDSGetCalendarInfo GetCalendar(int calendarID);
179 CDSCalendarList GetCalendarList(int accountID);
180 CDSCalendarResult UpdateCalendar(int calendarID, std::string calendarName, Colour calendarColour, std::string calendarDescription);
181 CDSCalendarResult DeleteCalendar(int calendarID);
185 CDSAddEntryResult AddEvent(int calendarID, std::string filename);
186 CDSGetCalendarEntryInfo GetEvent(int calendarEntryID);
187 CDSEntryList GetEventList(int calendarID);
188 CDSEntryList GetEventListByDate(int calendarYear, int calendarMonth, int calendarDay);
189 CDSEditEntryResult UpdateEvent(int eventID, std::string filename);
190 CDSEntryResult DeleteEvent(int calendarEntryID);
192 // Checksum functions.
194 CDSChecksumResult AddChecksum(std::string checksumName, std::string checksumValue);
195 CDSGetChecksumResult GetChecksum(std::string checksumName);
196 CDSChecksumResult UpdateChecksum(std::string checksumName, std::string checksumValue);
198 // Cleanup functions.
200 CDSCleanupResult Clear();