finch/finchui.c

changeset 42435
ecf0fdfc8363
parent 41958
76d1633b8ec0
child 42574
ef32e25a3b78
equal deleted inserted replaced
42434:622b4989d073 42435:ecf0fdfc8363
49 }; 49 };
50 50
51 G_DEFINE_TYPE(FinchUi, finch_ui, PURPLE_TYPE_UI) 51 G_DEFINE_TYPE(FinchUi, finch_ui, PURPLE_TYPE_UI)
52 52
53 /****************************************************************************** 53 /******************************************************************************
54 * Helpers
55 *****************************************************************************/
56 static gboolean
57 finch_history_init(GError **error) {
58 PurpleHistoryManager *manager = NULL;
59 PurpleHistoryAdapter *adapter = NULL;
60 gchar *filename = NULL;
61 const gchar *id = NULL;
62
63 manager = purple_history_manager_get_default();
64
65 /* Attempt to create the config directory. */
66 g_mkdir_with_parents(purple_config_dir(), 0700);
67
68 filename = g_build_filename(purple_config_dir(), "history.db", NULL);
69 adapter = purple_sqlite_history_adapter_new(filename);
70 g_free(filename);
71
72 id = purple_history_adapter_get_id(adapter);
73 if(!purple_history_manager_register(manager, adapter, error)) {
74 g_clear_object(&adapter);
75
76 return FALSE;
77 }
78
79 /* The manager adds a ref to the adapter on registration, so we can remove
80 * our reference.
81 */
82 g_clear_object(&adapter);
83
84 return purple_history_manager_set_active(manager, id, error);
85 }
86
87 /******************************************************************************
88 * PurpleUi Implementation 54 * PurpleUi Implementation
89 *****************************************************************************/ 55 *****************************************************************************/
90 static void 56 static void
91 finch_ui_prefs_init(G_GNUC_UNUSED PurpleUi *ui) { 57 finch_ui_prefs_init(G_GNUC_UNUSED PurpleUi *ui) {
92 finch_prefs_init(); 58 finch_prefs_init();
93 } 59 }
94 60
95 static gboolean 61 static gboolean
96 finch_ui_start(G_GNUC_UNUSED PurpleUi *ui, GError **error) { 62 finch_ui_start(G_GNUC_UNUSED PurpleUi *ui, G_GNUC_UNUSED GError **error) {
97 finch_debug_init(); 63 finch_debug_init();
98 64
99 #ifdef STANDALONE 65 #ifdef STANDALONE
100 #ifdef _WIN32 /* TODO: don't change it when using FHS under win32 */ 66 #ifdef _WIN32 /* TODO: don't change it when using FHS under win32 */
101 gnt_set_config_dir(purple_config_dir()); 67 gnt_set_config_dir(purple_config_dir());
102 #endif /* _WIN32 */ 68 #endif /* _WIN32 */
103 69
104 gnt_init(); 70 gnt_init();
105 #endif /* STANDALONE */ 71 #endif /* STANDALONE */
106
107 if(!finch_history_init(error)) {
108 const char *error_message = "unknown";
109
110 if(error != NULL && *error != NULL) {
111 error_message = (*error)->message;
112 }
113
114 g_critical("failed to initialize the history api: %s", error_message);
115
116 return FALSE;
117 }
118 72
119 purple_prefs_add_none("/purple/gnt"); 73 purple_prefs_add_none("/purple/gnt");
120 74
121 /* Accounts */ 75 /* Accounts */
122 finch_accounts_init(); 76 finch_accounts_init();
215 g_free(config); 169 g_free(config);
216 170
217 return backend; 171 return backend;
218 } 172 }
219 173
174 static PurpleHistoryAdapter *
175 finch_ui_get_history_adapter(G_GNUC_UNUSED PurpleUi *ui) {
176 PurpleHistoryAdapter *adapter = NULL;
177 char *filename = NULL;
178
179 g_mkdir_with_parents(purple_config_dir(), 0700);
180
181 filename = g_build_filename(purple_config_dir(), "history.db", NULL);
182 adapter = purple_sqlite_history_adapter_new(filename);
183 g_free(filename);
184
185 return adapter;
186 }
187
220 /****************************************************************************** 188 /******************************************************************************
221 * GObject Implementation 189 * GObject Implementation
222 *****************************************************************************/ 190 *****************************************************************************/
223 static void 191 static void
224 finch_ui_init(G_GNUC_UNUSED FinchUi *ui) { 192 finch_ui_init(G_GNUC_UNUSED FinchUi *ui) {
230 198
231 ui_class->prefs_init = finch_ui_prefs_init; 199 ui_class->prefs_init = finch_ui_prefs_init;
232 ui_class->start = finch_ui_start; 200 ui_class->start = finch_ui_start;
233 ui_class->stop = finch_ui_stop; 201 ui_class->stop = finch_ui_stop;
234 ui_class->get_settings_backend = finch_ui_get_settings_backend; 202 ui_class->get_settings_backend = finch_ui_get_settings_backend;
203 ui_class->get_history_adapter = finch_ui_get_history_adapter;
235 } 204 }
236 205
237 /****************************************************************************** 206 /******************************************************************************
238 * Public API 207 * Public API
239 *****************************************************************************/ 208 *****************************************************************************/

mercurial