Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
tests: Added more tests for CalendarDataStorage
[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 CDSAccountResult{
35         CDSACCOUNT_UNITTESTFAIL = -1,
36         CDSACCOUNT_OK,
37         CDSACCOUNT_FAILED,
38         CDSACCOUNT_NOACTION,
39         CDSACCOUNT_NOACCOUNT,
40         CDSACCOUNT_NONAME
41 };
43 enum CDSCalendarResult{
44         CDSCALENDAR_UNITTESTFAIL = -1,
45         CDSCALENDAR_OK,
46         CDSCALENDAR_FAILED,
47         CDSCALENDAR_NOACTION,
48         CDSCALENDAR_NOACCOUNT,
49         CDSCALENDAR_NOCALENDAR
50 };
52 enum CDSEntryResult{
53         CDSENTRY_UNITTESTFAIL = -1,
54         CDSENTRY_OK,
55         CDSENTRY_FAILED,
56         CDSENTRY_NOACTION,
57         CDSENTRY_NOACCOUNT,
58         CDSENTRY_NOCALENDAR,
59         CDSENTRY_NOENTRY,
60         CDSENTRY_MISSINGFILE,
61         CDSENTRY_CANNOTOPENFILE,
62         CDSENTRY_INVALIDFILE,
63 };
65 struct CDSGetAccountInfo{
66         int accountID = 0;
67         int accountPreferencesID = 0;
68         std::string accountName = "";
69         CDSAccountResult accountInfoResult = CDSACCOUNT_NOACTION;
70 };
72 struct CDSGetCalendarInfo{
73         int accountID = 0;
74         int calendarID = 0;
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;
82 };
84 struct CDSAddEntryResult{
85         int calendarEntryID = 0;
86         CDSEntryResult addEventResult = CDSENTRY_NOACTION;
87 };
89 struct CDSEditEntryResult{
90         int calendarEntryID = 0;
91         CDSEntryResult editEventResult = CDSENTRY_NOACTION;
92 };
94 struct CDSGetCalendarEntryInfo{
95         int accountID = 0;
96         int calendarID = 0;
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;
109         int entryEndDay = 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;
119 };
121 struct CDSEntryList{
122         std::vector <int> entryList;
123         CDSEntryResult getEventListResult = CDSENTRY_NOACTION;
124 };
126 struct CDSCalendarList{
127         std::vector <int> calendarList;
128         std::vector <std::string> calendarListTextID;
129         CDSCalendarResult getCalendarListResult = CDSCALENDAR_NOACTION;
130 };
132 struct CDSAccountList{
133         std::vector<CDSGetAccountInfo> accountList;
134         CDSAccountResult getAccountListResult = CDSACCOUNT_NOACTION;
135 };
137 enum CDSChecksumResult{
138         CDSCHECKSUM_UNITTESTFAIL = -1,
139         CDSCHECKSUM_OK,
140         CDSCHECKSUM_FAILED,
141         CDSCHECKSUM_NOHASH,
142         CDSCHECKSUM_CHECKSUMALREADYEXISTS,
143         CDSCHECKSUM_NORESULT
144 };
146 struct CDSGetChecksumResult{
147         CDSChecksumResult getChecksumResult = CDSCHECKSUM_NORESULT;
148         std::string checksumValue = "";
149 };
151 enum CDSCleanupResult{
152         CDSCLEANUP_UNITTESTFAIL = -1,
153         CDSCLEANUP_OK,
154         CDSCLEANUP_FAILED
155 };
157 class CalendarDataStorage{
159         private:
160                 sqlite3 *db = nullptr;
161                 void SetupTables();
162                 bool DataStorageInitOK = false;
163         public:
164                 CalendarDataStorage();
165                 ~CalendarDataStorage();
166                 bool DidInitOK();
167         
168                 // Account functions.
169         
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();
175         
176                 // Calendar functions.
177         
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);
184         
185                 // Entry functions
186         
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);
193                 
194                 // Checksum functions.
195                 
196                 CDSChecksumResult AddChecksum(std::string checksumName, std::string checksumValue);             
197                 CDSGetChecksumResult GetChecksum(std::string checksumName);
198                 CDSChecksumResult UpdateChecksum(std::string checksumName, std::string checksumValue);
199                 
200                 // Cleanup functions.
201                 
202                 CDSCleanupResult Clear();
203          
204 };
206 #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