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"
38 enum CDSAccountResult{
39 CDSACCOUNT_UNITTESTFAIL = -1,
47 enum CDSCalendarResult{
48 CDSCALENDAR_UNITTESTFAIL = -1,
52 CDSCALENDAR_NOACCOUNT,
53 CDSCALENDAR_NOCALENDAR
57 CDSENTRY_UNITTESTFAIL = -1,
65 CDSENTRY_CANNOTOPENFILE,
69 struct CDSGetAccountInfo{
71 int accountPreferencesID = 0;
72 std::string accountName = "";
73 CDSAccountResult accountInfoResult = CDSACCOUNT_NOACTION;
76 struct CDSGetCalendarInfo{
79 std::string accountName = "";
80 std::string calendarName = "";
81 std::string calendarTextID = "";
82 std::string calendarDescription = "";
83 Colour calendarColour;
84 CDSAccountResult accountInfoResult = CDSACCOUNT_NOACTION;
85 CDSCalendarResult calendarInfoResult = CDSCALENDAR_NOACTION;
88 struct CDSAddEntryResult{
89 int calendarEntryID = 0;
90 CDSEntryResult addEventResult = CDSENTRY_NOACTION;
93 struct CDSEditEntryResult{
94 int calendarEntryID = 0;
95 CDSEntryResult editEventResult = CDSENTRY_NOACTION;
98 struct CDSGetCalendarEntryInfo{
101 int calendarEntryID = 0;
102 std::string entryName = "";
103 std::string entryDescription = "";
104 std::string entryFilename = "";
105 int entryStartYear = 0;
106 int entryStartMonth = 0;
107 int entryStartDay = 0;
108 int entryStartHour = 0;
109 int entryStartMinute = 0;
110 int entryStartSecond = 0;
111 int entryEndYear = 0;
112 int entryEndMonth = 0;
114 int entryEndHour = 0;
115 int entryEndMinute = 0;
116 int entryEndSecond = 0;
117 int entryDurationWeeks = 0;
118 int entryDurationDays = 0;
119 int entryDurationHours = 0;
120 int entryDurationMinutes = 0;
121 int entryDurationSeconds = 0;
122 CDSEntryResult getEventResult = CDSENTRY_NOACTION;
126 std::vector <int> entryList;
127 CDSEntryResult getEventListResult = CDSENTRY_NOACTION;
130 struct CDSCalendarList{
131 std::vector <int> calendarList;
132 std::vector <std::string> calendarListTextID;
133 CDSCalendarResult getCalendarListResult = CDSCALENDAR_NOACTION;
136 struct CDSAccountList{
137 std::vector<CDSGetAccountInfo> accountList;
138 CDSAccountResult getAccountListResult = CDSACCOUNT_NOACTION;
141 enum CDSChecksumResult{
142 CDSCHECKSUM_UNITTESTFAIL = -1,
146 CDSCHECKSUM_CHECKSUMALREADYEXISTS,
150 struct CDSGetChecksumResult{
151 CDSChecksumResult getChecksumResult = CDSCHECKSUM_NORESULT;
152 std::string checksumValue = "";
155 enum CDSCleanupResult{
156 CDSCLEANUP_UNITTESTFAIL = -1,
161 class CalendarDataStorage{
164 sqlite3 *db = nullptr;
166 bool DataStorageInitOK = false;
168 CalendarDataStorage();
169 ~CalendarDataStorage();
172 // Account functions.
174 CDSAccountResult AddAccount(std::string accountName, int accountPreferencesID);
175 CDSGetAccountInfo GetAccount(std::string accountName);
176 CDSAccountResult UpdateAccount(int accountID, std::string accountName);
177 CDSAccountResult DeleteAccount(int accountID);
178 CDSAccountList GetAccountList();
180 // Calendar functions.
182 CDSCalendarResult AddCalendar(int accountID, std::string calendarName, std::string calendarID, Colour calendarColour, std::string calendarDescription);
183 CDSGetCalendarInfo GetCalendar(std::string accountName, std::string calendarTextID);
184 CDSGetCalendarInfo GetCalendar(int calendarID);
185 CDSCalendarList GetCalendarList(int accountID);
186 CDSCalendarResult UpdateCalendar(int calendarID, std::string calendarName, Colour calendarColour, std::string calendarDescription);
187 CDSCalendarResult DeleteCalendar(int calendarID);
191 CDSAddEntryResult AddEvent(int calendarID, std::string filename);
192 CDSGetCalendarEntryInfo GetEvent(int calendarEntryID);
193 CDSEntryList GetEventList(int calendarID);
194 CDSEntryList GetEventListByDate(int calendarYear, int calendarMonth, int calendarDay);
195 CDSEditEntryResult UpdateEvent(int eventID, std::string filename);
196 CDSEntryResult DeleteEvent(int calendarEntryID);
198 // Checksum functions.
200 CDSChecksumResult AddChecksum(std::string checksumName, std::string checksumValue);
201 CDSGetChecksumResult GetChecksum(std::string checksumName);
202 CDSChecksumResult UpdateChecksum(std::string checksumName, std::string checksumValue);
204 // Cleanup functions.
206 CDSCleanupResult Clear();