File indexing completed on 2024-11-24 04:43:41
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Shashwat Jolly <shashwat.jolly@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QString> 0010 #include <etebase.h> 0011 #include <memory> 0012 #include <vector> 0013 0014 #define charArrFromQString(str) ((str).isNull() ? nullptr : qUtf8Printable((str))) 0015 0016 #define ETEBASE_COLLECTION_TYPE_CALENDAR QStringLiteral("etebase.vevent") 0017 #define ETEBASE_COLLECTION_TYPE_ADDRESS_BOOK QStringLiteral("etebase.vcard") 0018 #define ETEBASE_COLLECTION_TYPE_TASKS QStringLiteral("etebase.vtodo") 0019 0020 #define ETESYNC_DEFAULT_COLLECTION_COLOR QStringLiteral("#8BC34A") 0021 0022 static const char *ETESYNC_COLLECTION_TYPES[] = {"etebase.vevent", "etebase.vcard", "etebase.vtodo"}; 0023 static const int ETESYNC_COLLECTION_TYPES_SIZE = ETEBASE_UTILS_C_ARRAY_LEN(ETESYNC_COLLECTION_TYPES); 0024 0025 struct EtebaseDeleter { 0026 void operator()(EtebaseClient *ptr) 0027 { 0028 etebase_client_destroy(ptr); 0029 } 0030 0031 void operator()(EtebaseAccount *ptr) 0032 { 0033 etebase_account_destroy(ptr); 0034 } 0035 0036 void operator()(EtebaseFetchOptions *ptr) 0037 { 0038 etebase_fetch_options_destroy(ptr); 0039 } 0040 0041 void operator()(EtebaseCollectionListResponse *ptr) 0042 { 0043 etebase_collection_list_response_destroy(ptr); 0044 } 0045 0046 void operator()(EtebaseCollectionManager *ptr) 0047 { 0048 etebase_collection_manager_destroy(ptr); 0049 } 0050 0051 void operator()(EtebaseCollection *ptr) 0052 { 0053 etebase_collection_destroy(ptr); 0054 } 0055 0056 void operator()(EtebaseItemManager *ptr) 0057 { 0058 etebase_item_manager_destroy(ptr); 0059 } 0060 0061 void operator()(EtebaseItemListResponse *ptr) 0062 { 0063 etebase_item_list_response_destroy(ptr); 0064 } 0065 0066 void operator()(EtebaseItemMetadata *ptr) 0067 { 0068 etebase_item_metadata_destroy(ptr); 0069 } 0070 0071 void operator()(EtebaseItem *ptr) 0072 { 0073 etebase_item_destroy(ptr); 0074 } 0075 0076 void operator()(EtebaseFileSystemCache *ptr) 0077 { 0078 etebase_fs_cache_destroy(ptr); 0079 } 0080 }; 0081 0082 struct VoidDeleter { 0083 void operator()(void *ptr) 0084 { 0085 std::free(ptr); 0086 } 0087 }; 0088 0089 using EtebaseClientPtr = std::unique_ptr<EtebaseClient, EtebaseDeleter>; 0090 using EtebaseAccountPtr = std::unique_ptr<EtebaseAccount, EtebaseDeleter>; 0091 using EtebaseFetchOptionsPtr = std::unique_ptr<EtebaseFetchOptions, EtebaseDeleter>; 0092 using EtebaseCollectionListResponsePtr = std::unique_ptr<EtebaseCollectionListResponse, EtebaseDeleter>; 0093 using EtebaseCollectionManagerPtr = std::unique_ptr<EtebaseCollectionManager, EtebaseDeleter>; 0094 using EtebaseCollectionPtr = std::unique_ptr<EtebaseCollection, EtebaseDeleter>; 0095 using EtebaseItemManagerPtr = std::unique_ptr<EtebaseItemManager, EtebaseDeleter>; 0096 using EtebaseItemListResponsePtr = std::unique_ptr<EtebaseItemListResponse, EtebaseDeleter>; 0097 using EtebaseItemMetadataPtr = std::unique_ptr<EtebaseItemMetadata, EtebaseDeleter>; 0098 using EtebaseItemPtr = std::unique_ptr<EtebaseItem, EtebaseDeleter>; 0099 using EtebaseFileSystemCachePtr = std::unique_ptr<EtebaseFileSystemCache, EtebaseDeleter>; 0100 using EtebaseCachePtr = std::unique_ptr<void, VoidDeleter>; 0101 using CharPtr = std::unique_ptr<char, VoidDeleter>; 0102 0103 QString QStringFromCharPtr(const CharPtr &str); 0104 0105 EtebaseClientPtr etebase_client_new(const QString &client_name, const QString &server_url); 0106 0107 EtebaseAccountPtr etebase_account_login(const EtebaseClient *client, const QString &username, const QString &password); 0108 0109 void etebase_fetch_options_set_stoken(EtebaseFetchOptions *fetch_options, const QString &stoken); 0110 0111 void etebase_item_metadata_set_color(EtebaseItemMetadata *meta_data, const QString &color); 0112 0113 void etebase_item_metadata_set_name(EtebaseItemMetadata *meta_data, const QString &name); 0114 0115 EtebaseCollectionPtr etebase_collection_manager_create(const EtebaseCollectionManager *col_mgr, 0116 const QString &collection_type, 0117 const EtebaseItemMetadata *meta, 0118 const void *content, 0119 uintptr_t content_size); 0120 0121 EtebaseFileSystemCachePtr etebase_fs_cache_new(const QString &path, const QString &username); 0122 0123 int32_t etebase_fs_cache_item_set(const EtebaseFileSystemCache *fs_cache, const EtebaseItemManager *item_mgr, const QString &col_uid, const EtebaseItem *item); 0124 0125 EtebaseCollectionPtr etebase_fs_cache_collection_get(const EtebaseFileSystemCache *fs_cache, const EtebaseCollectionManager *col_mgr, const QString &col_uid); 0126 0127 EtebaseItemPtr 0128 etebase_fs_cache_item_get(const EtebaseFileSystemCache *fs_cache, const EtebaseItemManager *item_mgr, const QString &col_uid, const QString &item_uid); 0129 0130 int32_t etebase_fs_cache_collection_unset(const EtebaseFileSystemCache *fs_cache, const EtebaseCollectionManager *col_mgr, const QString &col_uid); 0131 0132 int32_t 0133 etebase_fs_cache_item_unset(const EtebaseFileSystemCache *fs_cache, const EtebaseItemManager *item_mgr, const QString &col_uid, const QString &item_uid);