1 /* font-manager-database.h 2 * 3 * Copyright (C) 2009 - 2021 Jerry Casiano 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. 17 * 18 * If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>. 19 */ 20 21 #ifndef __FONT_MANAGER_DATABASE_H__ 22 #define __FONT_MANAGER_DATABASE_H__ 23 24 #include <glib.h> 25 #include <glib/gstdio.h> 26 #include <gmodule.h> 27 #include <glib-object.h> 28 #include <json-glib/json-glib.h> 29 #include <sqlite3.h> 30 31 #include "font-manager-orthography.h" 32 #include "font-manager-fontconfig.h" 33 #include "font-manager-freetype.h" 34 #include "font-manager-json.h" 35 #include "font-manager-font.h" 36 #include "font-manager-family.h" 37 #include "font-manager-font-info.h" 38 #include "font-manager-progress-data.h" 39 #include "font-manager-string-set.h" 40 #include "font-manager-utils.h" 41 42 G_BEGIN_DECLS 43 44 #define FONT_MANAGER_CURRENT_DATABASE_VERSION 11 45 46 #define FONT_MANAGER_TYPE_DATABASE (font_manager_database_get_type ()) 47 G_DECLARE_FINAL_TYPE(FontManagerDatabase, font_manager_database, FONT_MANAGER, DATABASE, GObject) 48 49 #define FONT_MANAGER_TYPE_DATABASE_ITERATOR (font_manager_database_iterator_get_type()) 50 G_DECLARE_FINAL_TYPE(FontManagerDatabaseIterator, font_manager_database_iterator, FONT_MANAGER, DATABASE_ITERATOR, GObject) 51 52 GQuark font_manager_database_error_quark (); 53 #define FONT_MANAGER_DATABASE_ERROR (font_manager_database_error_quark ()) 54 55 /** 56 * FontManagerDatabaseError: 57 * @FONT_MANAGER_DATABASE_ERROR_OK: SQLITE_OK 58 * @FONT_MANAGER_DATABASE_ERROR_ERROR: SQLITE_ERROR 59 * @FONT_MANAGER_DATABASE_ERROR_INTERNAL: SQLITE_INTERNAL 60 * @FONT_MANAGER_DATABASE_ERROR_PERM: SQLITE_PERM 61 * @FONT_MANAGER_DATABASE_ERROR_ABORT: SQLITE_ABORT 62 * @FONT_MANAGER_DATABASE_ERROR_BUSY: SQLITE_BUSY 63 * @FONT_MANAGER_DATABASE_ERROR_LOCKED: SQLITE_LOCKED 64 * @FONT_MANAGER_DATABASE_ERROR_NOMEM: SQLITE_NOMEM 65 * @FONT_MANAGER_DATABASE_ERROR_READONLY: SQLITE_READONLY 66 * @FONT_MANAGER_DATABASE_ERROR_INTERRUPT: SQLITE_INTERRUPT 67 * @FONT_MANAGER_DATABASE_ERROR_IOERR: SQLITE_IOERR 68 * @FONT_MANAGER_DATABASE_ERROR_CORRUPT: SQLITE_CORRUPT 69 * @FONT_MANAGER_DATABASE_ERROR_NOTFOUND: SQLITE_NOTFOUND 70 * @FONT_MANAGER_DATABASE_ERROR_FULL: SQLITE_FULL 71 * @FONT_MANAGER_DATABASE_ERROR_CANTOPEN: SQLITE_CANTOPEN 72 * @FONT_MANAGER_DATABASE_ERROR_PROTOCOL: SQLITE_PROTOCOL 73 * @FONT_MANAGER_DATABASE_ERROR_EMPTY: SQLITE_EMPTY 74 * @FONT_MANAGER_DATABASE_ERROR_SCHEMA: SQLITE_SCHEMA 75 * @FONT_MANAGER_DATABASE_ERROR_TOOBIG: SQLITE_TOOBIG 76 * @FONT_MANAGER_DATABASE_ERROR_CONSTRAINT: SQLITE_CONSTRAINT 77 * @FONT_MANAGER_DATABASE_ERROR_MISMATCH: SQLITE_MISMATCH 78 * @FONT_MANAGER_DATABASE_ERROR_MISUSE: SQLITE_MISUSE 79 * @FONT_MANAGER_DATABASE_ERROR_NOLFS: SQLITE_NOLFS 80 * @FONT_MANAGER_DATABASE_ERROR_AUTH: SQLITE_AUTH 81 * @FONT_MANAGER_DATABASE_ERROR_FORMAT: SQLITE_FORMAT 82 * @FONT_MANAGER_DATABASE_ERROR_RANGE: SQLITE_RANGE 83 * @FONT_MANAGER_DATABASE_ERROR_NOTADB: SQLITE_NOTADB 84 * @FONT_MANAGER_DATABASE_ERROR_NOTICE: SQLITE_NOTICE 85 * @FONT_MANAGER_DATABASE_ERROR_WARNING: SQLITE_WARNING 86 * @FONT_MANAGER_DATABASE_ERROR_ROW: SQLITE_ROW 87 * @FONT_MANAGER_DATABASE_ERROR_DONE: SQLITE_DONE 88 * 89 * These errors map directly to SQLite error codes. 90 * See https://sqlite.org/rescode.html for more detailed information. 91 */ 92 typedef enum 93 { 94 FONT_MANAGER_DATABASE_ERROR_OK, 95 FONT_MANAGER_DATABASE_ERROR_ERROR, 96 FONT_MANAGER_DATABASE_ERROR_INTERNAL, 97 FONT_MANAGER_DATABASE_ERROR_PERM, 98 FONT_MANAGER_DATABASE_ERROR_ABORT, 99 FONT_MANAGER_DATABASE_ERROR_BUSY, 100 FONT_MANAGER_DATABASE_ERROR_LOCKED, 101 FONT_MANAGER_DATABASE_ERROR_NOMEM, 102 FONT_MANAGER_DATABASE_ERROR_READONLY, 103 FONT_MANAGER_DATABASE_ERROR_INTERRUPT, 104 FONT_MANAGER_DATABASE_ERROR_IOERR, 105 FONT_MANAGER_DATABASE_ERROR_CORRUPT, 106 FONT_MANAGER_DATABASE_ERROR_NOTFOUND, 107 FONT_MANAGER_DATABASE_ERROR_FULL, 108 FONT_MANAGER_DATABASE_ERROR_CANTOPEN, 109 FONT_MANAGER_DATABASE_ERROR_PROTOCOL, 110 FONT_MANAGER_DATABASE_ERROR_EMPTY, 111 FONT_MANAGER_DATABASE_ERROR_SCHEMA, 112 FONT_MANAGER_DATABASE_ERROR_TOOBIG, 113 FONT_MANAGER_DATABASE_ERROR_CONSTRAINT, 114 FONT_MANAGER_DATABASE_ERROR_MISMATCH, 115 FONT_MANAGER_DATABASE_ERROR_MISUSE, 116 FONT_MANAGER_DATABASE_ERROR_NOLFS, 117 FONT_MANAGER_DATABASE_ERROR_AUTH, 118 FONT_MANAGER_DATABASE_ERROR_FORMAT, 119 FONT_MANAGER_DATABASE_ERROR_RANGE, 120 FONT_MANAGER_DATABASE_ERROR_NOTADB, 121 FONT_MANAGER_DATABASE_ERROR_NOTICE, 122 FONT_MANAGER_DATABASE_ERROR_WARNING, 123 FONT_MANAGER_DATABASE_ERROR_ROW = 100, 124 FONT_MANAGER_DATABASE_ERROR_DONE = 101 125 } 126 FontManagerDatabaseError; 127 128 GType font_manager_database_error_get_type (void); 129 #define FONT_MANAGER_TYPE_DATABASE_ERROR (font_manager_database_error_get_type ()) 130 131 struct _FontManagerDatabase 132 { 133 GObjectClass parent_class; 134 135 sqlite3 *db; 136 sqlite3_stmt *stmt; 137 }; 138 139 /** 140 * FontManagerDatabaseType: 141 * @FONT_MANAGER_DATABASE_TYPE_BASE: Base database file 142 * @FONT_MANAGER_DATABASE_TYPE_FONT: Font style information 143 * @FONT_MANAGER_DATABASE_TYPE_METADATA: Font metadata 144 * @FONT_MANAGER_DATABASE_TYPE_ORTHOGRAPHY: Orthography data 145 */ 146 typedef enum 147 { 148 FONT_MANAGER_DATABASE_TYPE_BASE, 149 FONT_MANAGER_DATABASE_TYPE_FONT, 150 FONT_MANAGER_DATABASE_TYPE_METADATA, 151 FONT_MANAGER_DATABASE_TYPE_ORTHOGRAPHY 152 } 153 FontManagerDatabaseType; 154 155 GType font_manager_database_type_get_type (void); 156 #define FONT_MANAGER_TYPE_DATABASE_TYPE (font_manager_database_type_get_type ()) 157 158 const gchar * font_manager_database_get_type_name (FontManagerDatabaseType type); 159 gchar * font_manager_database_get_file (FontManagerDatabaseType type); 160 161 FontManagerDatabase * font_manager_database_new (void); 162 void font_manager_database_open (FontManagerDatabase *self, GError **error); 163 void font_manager_database_begin_transaction (FontManagerDatabase *self, GError **error); 164 void font_manager_database_commit_transaction (FontManagerDatabase *self, GError **error); 165 void font_manager_database_execute_query (FontManagerDatabase *self, const gchar *sql, GError **error); 166 gint font_manager_database_get_version (FontManagerDatabase *self, GError **error); 167 void font_manager_database_set_version (FontManagerDatabase *self, int version, GError **error); 168 void font_manager_database_vacuum (FontManagerDatabase *self, GError **error); 169 void font_manager_database_initialize (FontManagerDatabase *self, FontManagerDatabaseType type, GError **error); 170 void font_manager_database_attach (FontManagerDatabase *self, FontManagerDatabaseType type, GError **error); 171 void font_manager_database_detach (FontManagerDatabase *self, FontManagerDatabaseType type, GError **error); 172 JsonObject * font_manager_database_get_object (FontManagerDatabase *self, const gchar *sql, GError **error); 173 FontManagerDatabaseIterator * font_manager_database_iterator (FontManagerDatabase *self); 174 175 /* Standard Iterator protocol */ 176 FontManagerDatabaseIterator * font_manager_database_iterator_new (FontManagerDatabase *db); 177 gboolean font_manager_database_iterator_next (FontManagerDatabaseIterator *self); 178 sqlite3_stmt * font_manager_database_iterator_get (FontManagerDatabaseIterator *self); 179 180 /* Related functions */ 181 182 FontManagerDatabase * font_manager_get_database (FontManagerDatabaseType type, GError **error); 183 184 gboolean font_manager_update_database_sync (FontManagerDatabase *db, 185 FontManagerDatabaseType type, 186 JsonObject *available_fonts, 187 FontManagerStringSet *available_files, 188 FontManagerProgressCallback progress, 189 GCancellable *cancellable, 190 GError **error); 191 192 void font_manager_update_database (FontManagerDatabase *db, 193 FontManagerDatabaseType type, 194 JsonObject *available_fonts, 195 FontManagerStringSet *available_files, 196 FontManagerProgressCallback progress, 197 GCancellable *cancellable, 198 GAsyncReadyCallback callback, 199 gpointer user_data); 200 201 gboolean font_manager_update_database_finish (GAsyncResult *result, GError **error); 202 203 void font_manager_get_matching_families_and_fonts (FontManagerDatabase *db, 204 FontManagerStringSet *families, 205 FontManagerStringSet *fonts, 206 const gchar *sql, 207 GError **error); 208 209 G_END_DECLS 210 211 #endif /* __FONT_MANAGER_DATABASE_H__ */ 212