Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
fda46c7bca8e9b267a2a3c6756b43ff809c56ad7
[xestiacalendar/.git] / source / libraries / CalendarDataStorage / CalendarDataStorage.h
1 // CalendarDataStorage.h - CalendarDataStorage class header
2 //
3 // (c) 2016-2017 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
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.
10 //
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.
15 //
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__
22 #include <string>
23 #include <iostream>
24 #include <sstream>
25 #include <cctype>
26 #include <algorithm>
28 #include <sqlite3.h>
30 #include "../../objects/calendarevent/CalendarEvent.h"
31 #include "../../common/colour.h"
32 #include "../../common/random.h"
34 /*enum CDSAddEntryResult{
35         CDSADDENTRY_UNITTESTFAIL = -1,
36         CDSADDENTRY_OK
37 }*/
39 enum CDSAccountResult{
40         CDSACCOUNT_UNITTESTFAIL = -1,
41         CDSACCOUNT_OK,
42         CDSACCOUNT_FAILED,
43         CDSACCOUNT_NOACTION,
44         CDSACCOUNT_NOACCOUNT
45 };
47 enum CDSCalendarResult{
48         CDSCALENDAR_UNITTESTFAIL = -1,
49         CDSCALENDAR_OK,
50         CDSCALENDAR_FAILED,
51         CDSCALENDAR_NOACTION,
52         CDSCALENDAR_NOCALENDAR
53 };
55 enum CDSEntryResult{
56         CDSENTRY_UNITTESTFAIL = -1,
57         CDSENTRY_OK,
58         CDSENTRY_FAILED,
59         CDSENTRY_NOACTION,
60         CDSENTRY_NOACCOUNT,
61         CDSENTRY_NOCALENDAR,
62         CDSENTRY_NOENTRY,
63         CDSENTRY_MISSINGFILE,
64         CDSENTRY_CANNOTOPENFILE,
65         CDSENTRY_INVALIDFILE,
66 };
68 struct CDSGetAccountInfo{
69         int accountID = 0;
70         int accountPreferencesID = 0;
71         std::string accountName = "";
72         CDSAccountResult accountInfoResult = CDSACCOUNT_NOACTION;
73 };
75 struct CDSGetCalendarInfo{
76         int accountID = 0;
77         int calendarID = 0;
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;
85 };
87 struct CDSAddEntryResult{
88         int calendarEntryID = 0;
89         CDSEntryResult addEventResult = CDSENTRY_NOACTION;
90 };
92 struct CDSEditEntryResult{
93         int calendarEntryID = 0;
94         CDSEntryResult editEventResult = CDSENTRY_NOACTION;
95 };
97 struct CDSGetCalendarEntryInfo{
98         int accountID = 0;
99         int calendarID = 0;
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;
112         int entryEndDay = 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;
122 };
124 struct CDSEntryList{
125         std::vector <int> entryList;
126         CDSEntryResult getEventListResult = CDSENTRY_NOACTION;
127 };
129 struct CDSCalendarList{
130         std::vector <int> calendarList;
131         std::vector <std::string> calendarListTextID;
132         CDSCalendarResult getCalendarListResult = CDSCALENDAR_NOACTION;
133 };
135 struct CDSAccountList{
136         std::vector<CDSGetAccountInfo> accountList;
137         CDSAccountResult getAccountListResult = CDSACCOUNT_NOACTION;
138 };
140 enum CDSChecksumResult{
141         CDSCHECKSUM_UNITTESTFAIL = -1,
142         CDSCHECKSUM_OK,
143         CDSCHECKSUM_FAILED,
144         CDSCHECKSUM_NOHASH,
145         CDSCHECKSUM_CHECKSUMALREADYEXISTS,
146         CDSCHECKSUM_NORESULT
147 };
149 struct CDSGetChecksumResult{
150         CDSChecksumResult getChecksumResult = CDSCHECKSUM_NORESULT;
151         std::string checksumValue = "";
152 };
154 enum CDSCleanupResult{
155         CDSCLEANUP_UNITTESTFAIL = -1,
156         CDSCLEANUP_OK,
157         CDSCLEANUP_FAILED
158 };
160 class CalendarDataStorage{
162         private:
163                 sqlite3 *db = nullptr;
164                 void SetupTables();
165                 bool DataStorageInitOK = false;
166         public:
167                 CalendarDataStorage();
168                 ~CalendarDataStorage();
169                 bool DidInitOK();
170         
171                 // Account functions.
172         
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();
178         
179                 // Calendar functions.
180         
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);
187         
188                 // Entry functions
189         
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);
196                 
197                 // Checksum functions.
198                 
199                 CDSChecksumResult AddChecksum(std::string checksumName, std::string checksumValue);             
200                 CDSGetChecksumResult GetChecksum(std::string checksumName);
201                 CDSChecksumResult UpdateChecksum(std::string checksumName, std::string checksumValue);
202                 
203                 // Cleanup functions.
204                 
205                 CDSCleanupResult Clear();
206          
207 };
209 #endif
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy