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 CDSAddEntryResult{
35 CDSADDENTRY_UNITTESTFAIL = -1,
39 enum CDSAccountResult{
40 CDSACCOUNT_UNITTESTFAIL = -1,
47 enum CDSCalendarResult{
48 CDSCALENDAR_UNITTESTFAIL = -1,
52 CDSCALENDAR_NOCALENDAR
56 CDSENTRY_UNITTESTFAIL = -1,
64 CDSENTRY_CANNOTOPENFILE,
68 struct CDSGetAccountInfo{
70 int accountPreferencesID = 0;
71 std::string accountName = "";
72 CDSAccountResult accountInfoResult = CDSACCOUNT_NOACTION;
75 struct CDSGetCalendarInfo{
78 std::string accountName = "";
79 std::string calendarName = "";
80 std::string calendarTextID = "";
81 std::string calendarDescription = "";
82 Colour calendarColour;
83 CDSAccountResult accountInfoResult = CDSACCOUNT_NOACTION;
84 CDSCalendarResult calendarInfoResult = CDSCALENDAR_NOACTION;
87 struct CDSAddEntryResult{
88 int calendarEntryID = 0;
89 CDSEntryResult addEventResult = CDSENTRY_NOACTION;
92 struct CDSEditEntryResult{
93 int calendarEntryID = 0;
94 CDSEntryResult editEventResult = CDSENTRY_NOACTION;
97 struct CDSGetCalendarEntryInfo{
100 int calendarEntryID = 0;
101 std::string entryName = "";
102 std::string entryDescription = "";
103 std::string entryFilename = "";
104 int entryStartYear = 0;
105 int entryStartMonth = 0;
106 int entryStartDay = 0;
107 int entryStartHour = 0;
108 int entryStartMinute = 0;
109 int entryStartSecond = 0;
110 int entryEndYear = 0;
111 int entryEndMonth = 0;
113 int entryEndHour = 0;
114 int entryEndMinute = 0;
115 int entryEndSecond = 0;
116 int entryDurationWeeks = 0;
117 int entryDurationDays = 0;
118 int entryDurationHours = 0;
119 int entryDurationMinutes = 0;
120 int entryDurationSeconds = 0;
121 CDSEntryResult getEventResult = CDSENTRY_NOACTION;
125 std::vector <int> entryList;
126 CDSEntryResult getEventListResult = CDSENTRY_NOACTION;
129 struct CDSCalendarList{
130 std::vector <int> calendarList;
131 std::vector <std::string> calendarListTextID;
132 CDSCalendarResult getCalendarListResult = CDSCALENDAR_NOACTION;
135 struct CDSAccountList{
136 std::vector<CDSGetAccountInfo> accountList;
137 CDSAccountResult getAccountListResult = CDSACCOUNT_NOACTION;
140 enum CDSChecksumResult{
141 CDSCHECKSUM_UNITTESTFAIL = -1,
145 CDSCHECKSUM_CHECKSUMALREADYEXISTS,
149 struct CDSGetChecksumResult{
150 CDSChecksumResult getChecksumResult = CDSCHECKSUM_NORESULT;
151 std::string checksumValue = "";
154 enum CDSCleanupResult{
155 CDSCLEANUP_UNITTESTFAIL = -1,
160 class CalendarDataStorage{
163 sqlite3 *db = nullptr;
165 bool DataStorageInitOK = false;
167 CalendarDataStorage();
168 ~CalendarDataStorage();
171 // Account functions.
173 CDSAccountResult AddAccount(std::string accountName, int accountPreferencesID);
174 CDSGetAccountInfo GetAccount(std::string accountName);
175 CDSAccountResult UpdateAccount(int accountID, std::string accountName);
176 CDSAccountResult DeleteAccount(int accountID);
177 CDSAccountList GetAccountList();
179 // Calendar functions.
181 CDSCalendarResult AddCalendar(int accountID, std::string calendarName, std::string calendarID, Colour calendarColour, std::string calendarDescription);
182 CDSGetCalendarInfo GetCalendar(std::string accountName, std::string calendarTextID);
183 CDSGetCalendarInfo GetCalendar(int calendarID);
184 CDSCalendarList GetCalendarList(int accountID);
185 CDSCalendarResult UpdateCalendar(int calendarID, std::string calendarName, Colour calendarColour, std::string calendarDescription);
186 CDSCalendarResult DeleteCalendar(int calendarID);
190 CDSAddEntryResult AddEvent(int calendarID, std::string filename);
191 CDSGetCalendarEntryInfo GetEvent(int calendarEntryID);
192 CDSEntryList GetEventList(int calendarID);
193 CDSEntryList GetEventListByDate(int calendarYear, int calendarMonth, int calendarDay);
194 CDSEditEntryResult UpdateEvent(int eventID, std::string filename);
195 CDSEntryResult DeleteEvent(int calendarEntryID);
197 // Checksum functions.
199 CDSChecksumResult AddChecksum(std::string checksumName, std::string checksumValue);
200 CDSGetChecksumResult GetChecksum(std::string checksumName);
201 CDSChecksumResult UpdateChecksum(std::string checksumName, std::string checksumValue);
203 // Cleanup functions.
205 CDSCleanupResult Clear();