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,
43 enum CDSCalendarResult{
44 CDSCALENDAR_UNITTESTFAIL = -1,
48 CDSCALENDAR_NOACCOUNT,
49 CDSCALENDAR_NOCALENDAR
53 CDSENTRY_UNITTESTFAIL = -1,
61 CDSENTRY_CANNOTOPENFILE,
65 struct CDSGetAccountInfo{
67 int accountPreferencesID = 0;
68 std::string accountName = "";
69 CDSAccountResult accountInfoResult = CDSACCOUNT_NOACTION;
72 struct CDSGetCalendarInfo{
75 std::string accountName = "";
76 std::string calendarName = "";
77 std::string calendarTextID = "";
78 std::string calendarDescription = "";
79 Colour calendarColour;
80 CDSAccountResult accountInfoResult = CDSACCOUNT_NOACTION;
81 CDSCalendarResult calendarInfoResult = CDSCALENDAR_NOACTION;
84 struct CDSAddEntryResult{
85 int calendarEntryID = 0;
86 CDSEntryResult addEventResult = CDSENTRY_NOACTION;
89 struct CDSEditEntryResult{
90 int calendarEntryID = 0;
91 CDSEntryResult editEventResult = CDSENTRY_NOACTION;
94 struct CDSGetCalendarEntryInfo{
97 int calendarEntryID = 0;
98 std::string entryName = "";
99 std::string entryDescription = "";
100 std::string entryFilename = "";
101 int entryStartYear = 0;
102 int entryStartMonth = 0;
103 int entryStartDay = 0;
104 int entryStartHour = 0;
105 int entryStartMinute = 0;
106 int entryStartSecond = 0;
107 int entryEndYear = 0;
108 int entryEndMonth = 0;
110 int entryEndHour = 0;
111 int entryEndMinute = 0;
112 int entryEndSecond = 0;
113 int entryDurationWeeks = 0;
114 int entryDurationDays = 0;
115 int entryDurationHours = 0;
116 int entryDurationMinutes = 0;
117 int entryDurationSeconds = 0;
118 CDSEntryResult getEventResult = CDSENTRY_NOACTION;
122 std::vector <int> entryList;
123 CDSEntryResult getEventListResult = CDSENTRY_NOACTION;
126 struct CDSCalendarList{
127 std::vector <int> calendarList;
128 std::vector <std::string> calendarListTextID;
129 CDSCalendarResult getCalendarListResult = CDSCALENDAR_NOACTION;
132 struct CDSAccountList{
133 std::vector<CDSGetAccountInfo> accountList;
134 CDSAccountResult getAccountListResult = CDSACCOUNT_NOACTION;
137 enum CDSChecksumResult{
138 CDSCHECKSUM_UNITTESTFAIL = -1,
142 CDSCHECKSUM_CHECKSUMALREADYEXISTS,
146 struct CDSGetChecksumResult{
147 CDSChecksumResult getChecksumResult = CDSCHECKSUM_NORESULT;
148 std::string checksumValue = "";
151 enum CDSCleanupResult{
152 CDSCLEANUP_UNITTESTFAIL = -1,
157 class CalendarDataStorage{
160 sqlite3 *db = nullptr;
162 bool DataStorageInitOK = false;
164 CalendarDataStorage();
165 ~CalendarDataStorage();
168 // Account functions.
170 CDSAccountResult AddAccount(std::string accountName, int accountPreferencesID);
171 CDSGetAccountInfo GetAccount(std::string accountName);
172 CDSAccountResult UpdateAccount(int accountID, std::string accountName);
173 CDSAccountResult DeleteAccount(int accountID);
174 CDSAccountList GetAccountList();
176 // Calendar functions.
178 CDSCalendarResult AddCalendar(int accountID, std::string calendarName, std::string calendarID, Colour calendarColour, std::string calendarDescription);
179 CDSGetCalendarInfo GetCalendar(std::string accountName, std::string calendarTextID);
180 CDSGetCalendarInfo GetCalendar(int calendarID);
181 CDSCalendarList GetCalendarList(int accountID);
182 CDSCalendarResult UpdateCalendar(int calendarID, std::string calendarName, Colour calendarColour, std::string calendarDescription);
183 CDSCalendarResult DeleteCalendar(int calendarID);
187 CDSAddEntryResult AddEvent(int calendarID, std::string filename);
188 CDSGetCalendarEntryInfo GetEvent(int calendarEntryID);
189 CDSEntryList GetEventList(int calendarID);
190 CDSEntryList GetEventListByDate(int calendarYear, int calendarMonth, int calendarDay);
191 CDSEditEntryResult UpdateEvent(int eventID, std::string filename);
192 CDSEntryResult DeleteEvent(int calendarEntryID);
194 // Checksum functions.
196 CDSChecksumResult AddChecksum(std::string checksumName, std::string checksumValue);
197 CDSGetChecksumResult GetChecksum(std::string checksumName);
198 CDSChecksumResult UpdateChecksum(std::string checksumName, std::string checksumValue);
200 // Cleanup functions.
202 CDSCleanupResult Clear();