File indexing completed on 2024-06-16 05:00:54

0001 /*
0002  *   Copyright (C) 2015 Christian Mollekopf <chrigi_1@fastmail.fm>
0003  *
0004  *   This program is free software; you can redistribute it and/or modify
0005  *   it under the terms of the GNU General Public License as published by
0006  *   the Free Software Foundation; either version 2 of the License, or
0007  *   (at your option) any later version.
0008  *
0009  *   This program is distributed in the hope that it will be useful,
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *   GNU General Public License for more details.
0013  *
0014  *   You should have received a copy of the GNU General Public License
0015  *   along with this program; if not, write to the
0016  *   Free Software Foundation, Inc.,
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
0018  */
0019 #include "typeimplementations.h"
0020 
0021 #include <QVector>
0022 #include <QByteArray>
0023 #include <QString>
0024 
0025 #include "../propertymapper.h"
0026 #include "../typeindex.h"
0027 #include "entitybuffer.h"
0028 #include "entity_generated.h"
0029 #include "mail/threadindexer.h"
0030 #include "mail/fulltextindexer.h"
0031 #include "domainadaptor.h"
0032 #include "typeimplementations_p.h"
0033 
0034 using namespace Sink;
0035 using namespace Sink::ApplicationDomain;
0036 
0037 #define SINK_REGISTER_SERIALIZER(MAPPER, ENTITYTYPE, PROPERTY, LOWERCASEPROPERTY) \
0038     MAPPER.addMapping<ENTITYTYPE::PROPERTY, Sink::ApplicationDomain::Buffer::ENTITYTYPE, Sink::ApplicationDomain::Buffer::ENTITYTYPE##Builder>(&Sink::ApplicationDomain::Buffer::ENTITYTYPE::LOWERCASEPROPERTY, &Sink::ApplicationDomain::Buffer::ENTITYTYPE##Builder::add_##LOWERCASEPROPERTY);
0039 
0040 typedef IndexConfig<Mail,
0041         SortedIndex<Mail::Date>,
0042         ValueIndex<Mail::Folder>,
0043         ValueIndex<Mail::ParentMessageIds>,
0044         ValueIndex<Mail::MessageId>,
0045         ValueIndex<Mail::Draft>,
0046         SortedIndex<Mail::Folder, Mail::Date>,
0047         SecondaryIndex<Mail::MessageId, Mail::ThreadId>,
0048         SecondaryIndex<Mail::ThreadId, Mail::MessageId>,
0049         CustomSecondaryIndex<Mail::MessageId, Mail::ThreadId, ThreadIndexer>,
0050         CustomSecondaryIndex<Mail::Subject, Mail::Subject, FulltextIndexer>
0051     > MailIndexConfig;
0052 
0053 typedef IndexConfig<Folder,
0054         ValueIndex<Folder::Name>,
0055         ValueIndex<Folder::Parent>
0056     > FolderIndexConfig;
0057 
0058 typedef IndexConfig<Contact,
0059         ValueIndex<Contact::Uid>,
0060         ValueIndex<Contact::Addressbook>
0061     > ContactIndexConfig;
0062 
0063 typedef IndexConfig<Addressbook,
0064         ValueIndex<Addressbook::Parent>
0065     > AddressbookIndexConfig;
0066 
0067 typedef IndexConfig<Event,
0068         ValueIndex<Event::Uid>,
0069         ValueIndex<Event::Calendar>,
0070         ValueIndex<Event::AllDay>,
0071         ValueIndex<Event::Recurring>,
0072         SortedIndex<Event::StartTime>,
0073         SampledPeriodIndex<Event::StartTime, Event::EndTime>
0074     > EventIndexConfig;
0075 
0076 typedef IndexConfig<Todo,
0077         ValueIndex<Todo::Uid>,
0078         ValueIndex<Todo::ParentUid>,
0079         ValueIndex<Todo::Calendar>
0080     > TodoIndexConfig;
0081 
0082 typedef IndexConfig<Calendar,
0083         ValueIndex<Calendar::Name>
0084     > CalendarIndexConfig;
0085 
0086 template <typename EntityType, typename EntityIndexConfig>
0087 QMap<QByteArray, int> defaultTypeDatabases()
0088 {
0089     return merge(QMap<QByteArray, int>{{QByteArray{EntityType::name} + ".main", Storage::IntegerKeys}}, EntityIndexConfig::databases());
0090 }
0091 
0092 void TypeImplementation<Mail>::configure(TypeIndex &index)
0093 {
0094     MailIndexConfig::configure(index);
0095 }
0096 
0097 QMap<QByteArray, int> TypeImplementation<Mail>::typeDatabases()
0098 {
0099     return defaultTypeDatabases<Mail, MailIndexConfig>();
0100 }
0101 
0102 void TypeImplementation<Mail>::configure(IndexPropertyMapper &indexPropertyMapper)
0103 {
0104     indexPropertyMapper.addIndexLookupProperty<Mail::ThreadId>([](TypeIndex &index, const ApplicationDomain::BufferAdaptor &entity) {
0105             auto messageId = entity.getProperty(Mail::MessageId::name);
0106             auto thread = index.secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId);
0107             if (!thread.isEmpty()) {
0108                 return thread.first();
0109             }
0110             return QByteArray{};
0111         });
0112 }
0113 
0114 void TypeImplementation<Mail>::configure(PropertyMapper &propertyMapper)
0115 {
0116     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Sender, sender);
0117     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, To, to);
0118     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Cc, cc);
0119     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Bcc, bcc);
0120     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Subject, subject);
0121     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Date, date);
0122     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Unread, unread);
0123     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Important, important);
0124     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Folder, folder);
0125     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, MimeMessage, mimeMessage);
0126     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, FullPayloadAvailable, fullPayloadAvailable);
0127     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Draft, draft);
0128     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Trash, trash);
0129     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Sent, sent);
0130     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, MessageId, messageId);
0131     SINK_REGISTER_SERIALIZER(propertyMapper, Mail, ParentMessageIds, parentMessageIds);
0132 }
0133 
0134 
0135 void TypeImplementation<Folder>::configure(TypeIndex &index)
0136 {
0137     FolderIndexConfig::configure(index);
0138 }
0139 
0140 QMap<QByteArray, int> TypeImplementation<Folder>::typeDatabases()
0141 {
0142     return defaultTypeDatabases<Folder, FolderIndexConfig>();
0143 }
0144 
0145 void TypeImplementation<Folder>::configure(PropertyMapper &propertyMapper)
0146 {
0147     SINK_REGISTER_SERIALIZER(propertyMapper, Folder, Parent, parent);
0148     SINK_REGISTER_SERIALIZER(propertyMapper, Folder, Name, name);
0149     SINK_REGISTER_SERIALIZER(propertyMapper, Folder, Icon, icon);
0150     SINK_REGISTER_SERIALIZER(propertyMapper, Folder, SpecialPurpose, specialpurpose);
0151     SINK_REGISTER_SERIALIZER(propertyMapper, Folder, Enabled, enabled);
0152 }
0153 
0154 void TypeImplementation<Folder>::configure(IndexPropertyMapper &)
0155 {
0156 
0157 }
0158 
0159 
0160 void TypeImplementation<Contact>::configure(TypeIndex &index)
0161 {
0162     ContactIndexConfig::configure(index);
0163 }
0164 
0165 QMap<QByteArray, int> TypeImplementation<Contact>::typeDatabases()
0166 {
0167     return defaultTypeDatabases<Contact, ContactIndexConfig>();
0168 }
0169 
0170 void TypeImplementation<Contact>::configure(PropertyMapper &propertyMapper)
0171 {
0172     SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Uid, uid);
0173     SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Fn, fn);
0174     SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Emails, emails);
0175     SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Vcard, vcard);
0176     SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Addressbook, addressbook);
0177     SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Firstname, firstname);
0178     SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Lastname, lastname);
0179     SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Photo, photo);
0180 }
0181 
0182 void TypeImplementation<Contact>::configure(IndexPropertyMapper &)
0183 {
0184 
0185 }
0186 
0187 
0188 void TypeImplementation<Addressbook>::configure(TypeIndex &index)
0189 {
0190     AddressbookIndexConfig::configure(index);
0191 }
0192 
0193 QMap<QByteArray, int> TypeImplementation<Addressbook>::typeDatabases()
0194 {
0195     return defaultTypeDatabases<Addressbook, AddressbookIndexConfig>();
0196 }
0197 
0198 void TypeImplementation<Addressbook>::configure(PropertyMapper &propertyMapper)
0199 {
0200     SINK_REGISTER_SERIALIZER(propertyMapper, Addressbook, Parent, parent);
0201     SINK_REGISTER_SERIALIZER(propertyMapper, Addressbook, Name, name);
0202     SINK_REGISTER_SERIALIZER(propertyMapper, Addressbook, Enabled, enabled);
0203 }
0204 
0205 void TypeImplementation<Addressbook>::configure(IndexPropertyMapper &)
0206 {
0207 
0208 }
0209 
0210 
0211 void TypeImplementation<Event>::configure(TypeIndex &index)
0212 {
0213     EventIndexConfig::configure(index);
0214 }
0215 
0216 QMap<QByteArray, int> TypeImplementation<Event>::typeDatabases()
0217 {
0218     return defaultTypeDatabases<Event, EventIndexConfig>();
0219 }
0220 
0221 void TypeImplementation<Event>::configure(PropertyMapper &propertyMapper)
0222 {
0223     SINK_REGISTER_SERIALIZER(propertyMapper, Event, Summary, summary);
0224     SINK_REGISTER_SERIALIZER(propertyMapper, Event, Description, description);
0225     SINK_REGISTER_SERIALIZER(propertyMapper, Event, Uid, uid);
0226     SINK_REGISTER_SERIALIZER(propertyMapper, Event, StartTime, startTime);
0227     SINK_REGISTER_SERIALIZER(propertyMapper, Event, EndTime, endTime);
0228     SINK_REGISTER_SERIALIZER(propertyMapper, Event, AllDay, allDay);
0229     SINK_REGISTER_SERIALIZER(propertyMapper, Event, Recurring, recurring);
0230     SINK_REGISTER_SERIALIZER(propertyMapper, Event, Ical, ical);
0231     SINK_REGISTER_SERIALIZER(propertyMapper, Event, Calendar, calendar);
0232 }
0233 
0234 void TypeImplementation<Event>::configure(IndexPropertyMapper &)
0235 {
0236 
0237 }
0238 
0239 
0240 void TypeImplementation<Todo>::configure(TypeIndex &index)
0241 {
0242     TodoIndexConfig::configure(index);
0243 }
0244 
0245 QMap<QByteArray, int> TypeImplementation<Todo>::typeDatabases()
0246 {
0247     return defaultTypeDatabases<Todo, TodoIndexConfig>();
0248 }
0249 
0250 void TypeImplementation<Todo>::configure(PropertyMapper &propertyMapper)
0251 {
0252     SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Uid, uid);
0253     SINK_REGISTER_SERIALIZER(propertyMapper, Todo, ParentUid, parentUid);
0254     SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Summary, summary);
0255     SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Description, description);
0256     SINK_REGISTER_SERIALIZER(propertyMapper, Todo, CompletedDate, completedDate);
0257     SINK_REGISTER_SERIALIZER(propertyMapper, Todo, DueDate, dueDate);
0258     SINK_REGISTER_SERIALIZER(propertyMapper, Todo, StartDate, startDate);
0259     SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Status, status);
0260     SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Priority, priority);
0261     SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Categories, categories);
0262     SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Ical, ical);
0263     SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Calendar, calendar);
0264 }
0265 
0266 void TypeImplementation<Todo>::configure(IndexPropertyMapper &)
0267 {
0268 
0269 }
0270 
0271 
0272 void TypeImplementation<Calendar>::configure(TypeIndex &index)
0273 {
0274     CalendarIndexConfig::configure(index);
0275 }
0276 
0277 QMap<QByteArray, int> TypeImplementation<Calendar>::typeDatabases()
0278 {
0279     return defaultTypeDatabases<Calendar, CalendarIndexConfig>();
0280 }
0281 
0282 void TypeImplementation<Calendar>::configure(PropertyMapper &propertyMapper)
0283 {
0284     SINK_REGISTER_SERIALIZER(propertyMapper, Calendar, Name, name);
0285     SINK_REGISTER_SERIALIZER(propertyMapper, Calendar, Color, color);
0286     SINK_REGISTER_SERIALIZER(propertyMapper, Calendar, Enabled, enabled);
0287     SINK_REGISTER_SERIALIZER(propertyMapper, Calendar, ContentTypes, contentTypes);
0288 }
0289 
0290 void TypeImplementation<Calendar>::configure(IndexPropertyMapper &) {}