1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
|
/* familiar-players-db.c generated by valac, the Vala compiler
* generated from familiar-players-db.vala, do not modify */
/*
Copyright 2010 Canonical Ltd.
Authors:
Conor Curran <conor.curran@canonical.com>
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License version 3, as published
by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranties of
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <glib.h>
#include <glib-object.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gstdio.h>
#define TYPE_FAMILIAR_PLAYERS_DB (familiar_players_db_get_type ())
#define FAMILIAR_PLAYERS_DB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FAMILIAR_PLAYERS_DB, FamiliarPlayersDB))
#define FAMILIAR_PLAYERS_DB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FAMILIAR_PLAYERS_DB, FamiliarPlayersDBClass))
#define IS_FAMILIAR_PLAYERS_DB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FAMILIAR_PLAYERS_DB))
#define IS_FAMILIAR_PLAYERS_DB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FAMILIAR_PLAYERS_DB))
#define FAMILIAR_PLAYERS_DB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FAMILIAR_PLAYERS_DB, FamiliarPlayersDBClass))
typedef struct _FamiliarPlayersDB FamiliarPlayersDB;
typedef struct _FamiliarPlayersDBClass FamiliarPlayersDBClass;
typedef struct _FamiliarPlayersDBPrivate FamiliarPlayersDBPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_key_file_free0(var) ((var == NULL) ? NULL : (var = (g_key_file_free (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
struct _FamiliarPlayersDB {
GObject parent_instance;
FamiliarPlayersDBPrivate * priv;
};
struct _FamiliarPlayersDBClass {
GObjectClass parent_class;
};
struct _FamiliarPlayersDBPrivate {
GeeHashMap* players_DB;
char* file_name;
char* dir_name;
GKeyFile* key_file;
guint write_id;
};
static gpointer familiar_players_db_parent_class = NULL;
GType familiar_players_db_get_type (void);
#define FAMILIAR_PLAYERS_DB_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_FAMILIAR_PLAYERS_DB, FamiliarPlayersDBPrivate))
enum {
FAMILIAR_PLAYERS_DB_DUMMY_PROPERTY
};
#define FAMILIAR_PLAYERS_DB_GROUP_NAME "Seen Database"
#define FAMILIAR_PLAYERS_DB_KEY_NAME "DesktopFiles"
static gboolean familiar_players_db_create_key_file (FamiliarPlayersDB* self);
static gboolean familiar_players_db_check_for_keys (FamiliarPlayersDB* self);
static gboolean familiar_players_db_load_data_from_key_file (FamiliarPlayersDB* self);
FamiliarPlayersDB* familiar_players_db_new (void);
FamiliarPlayersDB* familiar_players_db_construct (GType object_type);
static void _vala_array_add1 (char*** array, int* length, int* size, char* value);
static gboolean familiar_players_db_write_db (FamiliarPlayersDB* self);
gboolean familiar_players_db_already_familiar (FamiliarPlayersDB* self, const char* desktop);
static gboolean _familiar_players_db_write_db_gsource_func (gpointer self);
void familiar_players_db_insert (FamiliarPlayersDB* self, const char* desktop);
GeeSet* familiar_players_db_records (FamiliarPlayersDB* self);
static void familiar_players_db_finalize (GObject* obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
FamiliarPlayersDB* familiar_players_db_construct (GType object_type) {
FamiliarPlayersDB * self;
GeeHashMap* _tmp0_;
char* _tmp1_;
char* _tmp2_;
gboolean _tmp3_ = FALSE;
gboolean _tmp4_ = FALSE;
self = (FamiliarPlayersDB*) g_object_new (object_type, NULL);
self->priv->write_id = (guint) 0;
self->priv->players_DB = (_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, G_TYPE_BOOLEAN, NULL, NULL, NULL, NULL, NULL), _g_object_unref0 (self->priv->players_DB), _tmp0_);
self->priv->dir_name = (_tmp1_ = g_build_filename (g_get_user_cache_dir (), "indicators", "sound", NULL), _g_free0 (self->priv->dir_name), _tmp1_);
self->priv->file_name = (_tmp2_ = g_build_filename (self->priv->dir_name, "familiar-players-db.keyfile", NULL), _g_free0 (self->priv->file_name), _tmp2_);
if (familiar_players_db_create_key_file (self)) {
_tmp4_ = familiar_players_db_check_for_keys (self);
} else {
_tmp4_ = FALSE;
}
if (_tmp4_) {
_tmp3_ = familiar_players_db_load_data_from_key_file (self);
} else {
_tmp3_ = FALSE;
}
if (_tmp3_) {
g_debug ("familiar-players-db.vala:45: keyfiles in place and ready for action");
} else {
GKeyFile* _tmp5_;
self->priv->key_file = (_tmp5_ = NULL, _g_key_file_free0 (self->priv->key_file), _tmp5_);
g_warning ("familiar-players-db.vala:49: FamiliarPlayersDB:: problems loading key " \
"file - can't go any further");
}
return self;
}
FamiliarPlayersDB* familiar_players_db_new (void) {
return familiar_players_db_construct (TYPE_FAMILIAR_PLAYERS_DB);
}
static gboolean familiar_players_db_create_key_file (FamiliarPlayersDB* self) {
gboolean result = FALSE;
GError * _inner_error_;
g_return_val_if_fail (self != NULL, FALSE);
_inner_error_ = NULL;
if (g_file_test (self->priv->file_name, G_FILE_TEST_EXISTS)) {
GKeyFile* _tmp0_;
self->priv->key_file = (_tmp0_ = g_key_file_new (), _g_key_file_free0 (self->priv->key_file), _tmp0_);
{
gboolean _tmp1_;
_tmp1_ = g_key_file_load_from_file (self->priv->key_file, self->priv->file_name, G_KEY_FILE_NONE, &_inner_error_);
if (_inner_error_ != NULL) {
if (_inner_error_->domain == G_FILE_ERROR) {
goto __catch2_g_file_error;
}
goto __finally2;
}
if (_tmp1_ == TRUE) {
result = TRUE;
return result;
}
}
goto __finally2;
__catch2_g_file_error:
{
GError * e;
e = _inner_error_;
_inner_error_ = NULL;
{
g_warning ("familiar-players-db.vala:62: FamiliarPlayersDB - error trying to load " \
"KeyFile");
_g_error_free0 (e);
}
}
__finally2:
if (_inner_error_ != NULL) {
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
g_clear_error (&_inner_error_);
return FALSE;
}
}
result = FALSE;
return result;
}
static gboolean familiar_players_db_check_for_keys (FamiliarPlayersDB* self) {
gboolean result = FALSE;
GError * _inner_error_;
g_return_val_if_fail (self != NULL, FALSE);
_inner_error_ = NULL;
{
gboolean _tmp0_;
_tmp0_ = g_key_file_has_key (self->priv->key_file, FAMILIAR_PLAYERS_DB_GROUP_NAME, FAMILIAR_PLAYERS_DB_KEY_NAME, &_inner_error_);
if (_inner_error_ != NULL) {
if (_inner_error_->domain == G_KEY_FILE_ERROR) {
goto __catch3_g_key_file_error;
}
g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
g_clear_error (&_inner_error_);
return FALSE;
}
if (_tmp0_ == TRUE) {
result = TRUE;
return result;
}
}
goto __finally3;
__catch3_g_key_file_error:
{
GError * e;
e = _inner_error_;
_inner_error_ = NULL;
{
result = FALSE;
_g_error_free0 (e);
return result;
}
}
__finally3:
if (_inner_error_ != NULL) {
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
g_clear_error (&_inner_error_);
return FALSE;
}
g_warning ("familiar-players-db.vala:77: Seen DB '%s' does not have key '%s' in gr" \
"oup '%s'", self->priv->file_name, FAMILIAR_PLAYERS_DB_KEY_NAME, FAMILIAR_PLAYERS_DB_GROUP_NAME);
result = FALSE;
return result;
}
static gboolean familiar_players_db_load_data_from_key_file (FamiliarPlayersDB* self) {
gboolean result = FALSE;
GError * _inner_error_;
g_return_val_if_fail (self != NULL, FALSE);
_inner_error_ = NULL;
{
char** _tmp1_;
gint _desktops_size_;
gint desktops_length1;
gsize _tmp0_;
char** desktops;
desktops = (_tmp1_ = g_key_file_get_string_list (self->priv->key_file, FAMILIAR_PLAYERS_DB_GROUP_NAME, FAMILIAR_PLAYERS_DB_KEY_NAME, &_tmp0_, &_inner_error_), desktops_length1 = _tmp0_, _desktops_size_ = desktops_length1, _tmp1_);
if (_inner_error_ != NULL) {
if (_inner_error_->domain == G_FILE_ERROR) {
goto __catch4_g_file_error;
}
goto __finally4;
}
{
char** s_collection;
int s_collection_length1;
int s_it;
s_collection = desktops;
s_collection_length1 = desktops_length1;
for (s_it = 0; s_it < desktops_length1; s_it = s_it + 1) {
char* s;
s = g_strdup (s_collection[s_it]);
{
gee_abstract_map_set ((GeeAbstractMap*) self->priv->players_DB, s, GINT_TO_POINTER (TRUE));
_g_free0 (s);
}
}
}
result = TRUE;
desktops = (_vala_array_free (desktops, desktops_length1, (GDestroyNotify) g_free), NULL);
return result;
}
goto __finally4;
__catch4_g_file_error:
{
GError * _error_;
_error_ = _inner_error_;
_inner_error_ = NULL;
{
g_warning ("familiar-players-db.vala:91: Error loading the Desktop string list");
result = FALSE;
_g_error_free0 (_error_);
return result;
}
}
__finally4:
{
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
g_clear_error (&_inner_error_);
return FALSE;
}
}
static void _vala_array_add1 (char*** array, int* length, int* size, char* value) {
if ((*length) == (*size)) {
*size = (*size) ? (2 * (*size)) : 4;
*array = g_renew (char*, *array, (*size) + 1);
}
(*array)[(*length)++] = value;
(*array)[*length] = NULL;
}
static gboolean familiar_players_db_write_db (FamiliarPlayersDB* self) {
gboolean result = FALSE;
GError * _inner_error_;
GKeyFile* keyfile;
char** _tmp1_;
gint _desktops_size_;
gint desktops_length1;
char** _tmp0_ = NULL;
char** desktops;
gsize data_length = 0UL;
char* data;
g_return_val_if_fail (self != NULL, FALSE);
_inner_error_ = NULL;
keyfile = g_key_file_new ();
desktops = (_tmp1_ = (_tmp0_ = g_new0 (char*, 0 + 1), _tmp0_), desktops_length1 = 0, _desktops_size_ = desktops_length1, _tmp1_);
{
GeeSet* _tmp2_;
GeeIterator* _tmp3_;
GeeIterator* _key_it;
_key_it = (_tmp3_ = gee_iterable_iterator ((GeeIterable*) (_tmp2_ = gee_map_get_keys ((GeeMap*) self->priv->players_DB))), _g_object_unref0 (_tmp2_), _tmp3_);
while (TRUE) {
char* key;
if (!gee_iterator_next (_key_it)) {
break;
}
key = (char*) gee_iterator_get (_key_it);
_vala_array_add1 (&desktops, &desktops_length1, &_desktops_size_, g_strdup (key));
_g_free0 (key);
}
_g_object_unref0 (_key_it);
}
g_key_file_set_string_list (keyfile, FAMILIAR_PLAYERS_DB_GROUP_NAME, FAMILIAR_PLAYERS_DB_KEY_NAME, (const gchar* const*) desktops, desktops_length1);
data = NULL;
{
char* _tmp4_;
data = (_tmp4_ = g_key_file_to_data (keyfile, &data_length, NULL), _g_free0 (data), _tmp4_);
}
goto __finally5;
__catch5_g_error:
{
GError * e;
e = _inner_error_;
_inner_error_ = NULL;
{
g_warning ("familiar-players-db.vala:112: Problems dumping keyfile to a string");
result = FALSE;
_g_error_free0 (e);
_g_key_file_free0 (keyfile);
desktops = (_vala_array_free (desktops, desktops_length1, (GDestroyNotify) g_free), NULL);
_g_free0 (data);
return result;
}
}
__finally5:
if (_inner_error_ != NULL) {
_g_key_file_free0 (keyfile);
desktops = (_vala_array_free (desktops, desktops_length1, (GDestroyNotify) g_free), NULL);
_g_free0 (data);
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
g_clear_error (&_inner_error_);
return FALSE;
}
if (g_mkdir_with_parents (self->priv->dir_name, 0700) != 0) {
g_warning ("familiar-players-db.vala:117: Unable to make directory: %s", self->priv->dir_name);
result = FALSE;
_g_key_file_free0 (keyfile);
desktops = (_vala_array_free (desktops, desktops_length1, (GDestroyNotify) g_free), NULL);
_g_free0 (data);
return result;
}
{
gboolean _tmp5_;
_tmp5_ = g_file_set_contents (self->priv->file_name, data, (gssize) data_length, &_inner_error_);
if (_inner_error_ != NULL) {
if (_inner_error_->domain == G_FILE_ERROR) {
goto __catch6_g_file_error;
}
_g_key_file_free0 (keyfile);
desktops = (_vala_array_free (desktops, desktops_length1, (GDestroyNotify) g_free), NULL);
_g_free0 (data);
g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
g_clear_error (&_inner_error_);
return FALSE;
}
if (_tmp5_ == FALSE) {
g_warning ("familiar-players-db.vala:123: Unable to write out file '%s'", self->priv->file_name);
}
}
goto __finally6;
__catch6_g_file_error:
{
GError * err;
err = _inner_error_;
_inner_error_ = NULL;
{
g_warning ("familiar-players-db.vala:127: Unable to write out file '%s'", self->priv->file_name);
_g_error_free0 (err);
}
}
__finally6:
if (_inner_error_ != NULL) {
_g_key_file_free0 (keyfile);
desktops = (_vala_array_free (desktops, desktops_length1, (GDestroyNotify) g_free), NULL);
_g_free0 (data);
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
g_clear_error (&_inner_error_);
return FALSE;
}
result = TRUE;
_g_key_file_free0 (keyfile);
desktops = (_vala_array_free (desktops, desktops_length1, (GDestroyNotify) g_free), NULL);
_g_free0 (data);
return result;
}
static gboolean _familiar_players_db_write_db_gsource_func (gpointer self) {
gboolean result;
result = familiar_players_db_write_db (self);
return result;
}
void familiar_players_db_insert (FamiliarPlayersDB* self, const char* desktop) {
g_return_if_fail (self != NULL);
g_return_if_fail (desktop != NULL);
if (familiar_players_db_already_familiar (self, desktop) == FALSE) {
char* _tmp0_;
if (self->priv->write_id != 0) {
g_source_remove (self->priv->write_id);
self->priv->write_id = (guint) 0;
}
self->priv->write_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 60, _familiar_players_db_write_db_gsource_func, g_object_ref (self), g_object_unref);
gee_abstract_map_set ((GeeAbstractMap*) self->priv->players_DB, _tmp0_ = g_strdup (desktop), GINT_TO_POINTER (TRUE));
_g_free0 (_tmp0_);
}
}
gboolean familiar_players_db_already_familiar (FamiliarPlayersDB* self, const char* desktop) {
gboolean result = FALSE;
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (desktop != NULL, FALSE);
result = GPOINTER_TO_INT (gee_abstract_map_get ((GeeAbstractMap*) self->priv->players_DB, desktop));
return result;
}
GeeSet* familiar_players_db_records (FamiliarPlayersDB* self) {
GeeSet* result = NULL;
g_return_val_if_fail (self != NULL, NULL);
result = gee_map_get_keys ((GeeMap*) self->priv->players_DB);
return result;
}
static void familiar_players_db_class_init (FamiliarPlayersDBClass * klass) {
familiar_players_db_parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (klass, sizeof (FamiliarPlayersDBPrivate));
G_OBJECT_CLASS (klass)->finalize = familiar_players_db_finalize;
}
static void familiar_players_db_instance_init (FamiliarPlayersDB * self) {
self->priv = FAMILIAR_PLAYERS_DB_GET_PRIVATE (self);
}
static void familiar_players_db_finalize (GObject* obj) {
FamiliarPlayersDB * self;
self = FAMILIAR_PLAYERS_DB (obj);
_g_object_unref0 (self->priv->players_DB);
_g_free0 (self->priv->file_name);
_g_free0 (self->priv->dir_name);
_g_key_file_free0 (self->priv->key_file);
G_OBJECT_CLASS (familiar_players_db_parent_class)->finalize (obj);
}
GType familiar_players_db_get_type (void) {
static volatile gsize familiar_players_db_type_id__volatile = 0;
if (g_once_init_enter (&familiar_players_db_type_id__volatile)) {
static const GTypeInfo g_define_type_info = { sizeof (FamiliarPlayersDBClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) familiar_players_db_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FamiliarPlayersDB), 0, (GInstanceInitFunc) familiar_players_db_instance_init, NULL };
GType familiar_players_db_type_id;
familiar_players_db_type_id = g_type_register_static (G_TYPE_OBJECT, "FamiliarPlayersDB", &g_define_type_info, 0);
g_once_init_leave (&familiar_players_db_type_id__volatile, familiar_players_db_type_id);
}
return familiar_players_db_type_id__volatile;
}
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
if ((array != NULL) && (destroy_func != NULL)) {
int i;
for (i = 0; i < array_length; i = i + 1) {
if (((gpointer*) array)[i] != NULL) {
destroy_func (((gpointer*) array)[i]);
}
}
}
}
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
_vala_array_destroy (array, array_length, destroy_func);
g_free (array);
}
|