You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
295 lines
6.3 KiB
295 lines
6.3 KiB
/* This file has been automatically generated by geneet.py */ |
|
/* DO NOT MODIFY */ |
|
|
|
#include <limits.h> |
|
#include <stdio.h> |
|
#include <sys/stat.h> |
|
#include <sys/types.h> |
|
#include <unistd.h> |
|
|
|
#include "favorite.h" |
|
|
|
struct _Fav_Item { |
|
const char * url; |
|
const char * title; |
|
unsigned int visit_count; |
|
}; |
|
|
|
struct _Fav { |
|
int version; |
|
Eina_Hash * items; |
|
const char *__eet_filename; |
|
}; |
|
|
|
static const char FAV_ITEM_ENTRY[] = "fav_item"; |
|
static const char FAV_ENTRY[] = "fav"; |
|
|
|
static Eet_Data_Descriptor *_fav_item_descriptor = NULL; |
|
static Eet_Data_Descriptor *_fav_descriptor = NULL; |
|
|
|
static inline void |
|
_fav_item_init(void) |
|
{ |
|
Eet_Data_Descriptor_Class eddc; |
|
|
|
if (_fav_item_descriptor) return; |
|
|
|
EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Fav_Item); |
|
_fav_item_descriptor = eet_data_descriptor_stream_new(&eddc); |
|
|
|
EET_DATA_DESCRIPTOR_ADD_BASIC(_fav_item_descriptor, Fav_Item, "url", url, EET_T_STRING); |
|
EET_DATA_DESCRIPTOR_ADD_BASIC(_fav_item_descriptor, Fav_Item, "title", title, EET_T_STRING); |
|
EET_DATA_DESCRIPTOR_ADD_BASIC(_fav_item_descriptor, Fav_Item, "visit_count", visit_count, EET_T_UINT); |
|
} |
|
|
|
static inline void |
|
_fav_item_shutdown(void) |
|
{ |
|
if (!_fav_item_descriptor) return; |
|
eet_data_descriptor_free(_fav_item_descriptor); |
|
_fav_item_descriptor = NULL; |
|
} |
|
|
|
Fav_Item * |
|
fav_item_new(const char * url, const char * title, unsigned int visit_count) |
|
{ |
|
Fav_Item *fav_item = calloc(1, sizeof(Fav_Item)); |
|
|
|
if (!fav_item) |
|
{ |
|
fprintf(stderr, "ERROR: could not calloc Fav_Item\n"); |
|
return NULL; |
|
} |
|
|
|
fav_item->url = eina_stringshare_add(url ? url : "about:blank"); |
|
fav_item->title = eina_stringshare_add(title ? title : "Untitled"); |
|
fav_item->visit_count = visit_count; |
|
|
|
return fav_item; |
|
} |
|
|
|
void |
|
fav_item_free(Fav_Item *fav_item) |
|
{ |
|
eina_stringshare_del(fav_item->url); |
|
eina_stringshare_del(fav_item->title); |
|
free(fav_item); |
|
} |
|
|
|
inline const char * |
|
fav_item_url_get(const Fav_Item *fav_item) |
|
{ |
|
return fav_item->url; |
|
} |
|
|
|
inline void |
|
fav_item_url_set(Fav_Item *fav_item, const char *url) |
|
{ |
|
EINA_SAFETY_ON_NULL_RETURN(fav_item); |
|
eina_stringshare_del(fav_item->url); |
|
fav_item->url = eina_stringshare_add(url); |
|
} |
|
|
|
inline const char * |
|
fav_item_title_get(const Fav_Item *fav_item) |
|
{ |
|
return fav_item->title; |
|
} |
|
|
|
inline void |
|
fav_item_title_set(Fav_Item *fav_item, const char *title) |
|
{ |
|
EINA_SAFETY_ON_NULL_RETURN(fav_item); |
|
eina_stringshare_del(fav_item->title); |
|
fav_item->title = eina_stringshare_add(title); |
|
} |
|
|
|
inline unsigned int |
|
fav_item_visit_count_get(const Fav_Item *fav_item) |
|
{ |
|
return fav_item->visit_count; |
|
} |
|
|
|
inline void |
|
fav_item_visit_count_set(Fav_Item *fav_item, unsigned int visit_count) |
|
{ |
|
EINA_SAFETY_ON_NULL_RETURN(fav_item); |
|
fav_item->visit_count = visit_count; |
|
} |
|
|
|
|
|
static inline void |
|
_fav_init(void) |
|
{ |
|
Eet_Data_Descriptor_Class eddc; |
|
|
|
if (_fav_descriptor) return; |
|
|
|
EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Fav); |
|
_fav_descriptor = eet_data_descriptor_stream_new(&eddc); |
|
|
|
EET_DATA_DESCRIPTOR_ADD_BASIC(_fav_descriptor, Fav, "version", version, EET_T_INT); |
|
EET_DATA_DESCRIPTOR_ADD_HASH(_fav_descriptor, Fav, "items", items, _fav_item_descriptor); |
|
} |
|
|
|
static inline void |
|
_fav_shutdown(void) |
|
{ |
|
if (!_fav_descriptor) return; |
|
eet_data_descriptor_free(_fav_descriptor); |
|
_fav_descriptor = NULL; |
|
} |
|
|
|
Fav * |
|
fav_new(int version) |
|
{ |
|
Fav *fav = calloc(1, sizeof(Fav)); |
|
|
|
if (!fav) |
|
{ |
|
fprintf(stderr, "ERROR: could not calloc Fav\n"); |
|
return NULL; |
|
} |
|
|
|
fav->version = version; |
|
fav->items = eina_hash_stringshared_new(EINA_FREE_CB(fav_item_free)); |
|
|
|
return fav; |
|
} |
|
|
|
void |
|
fav_free(Fav *fav) |
|
{ |
|
eina_hash_free(fav->items); |
|
free(fav); |
|
} |
|
|
|
inline int |
|
fav_version_get(const Fav *fav) |
|
{ |
|
return fav->version; |
|
} |
|
|
|
inline void |
|
fav_version_set(Fav *fav, int version) |
|
{ |
|
EINA_SAFETY_ON_NULL_RETURN(fav); |
|
fav->version = version; |
|
} |
|
|
|
void |
|
fav_items_add(Fav *fav, const char * url, Fav_Item *fav_item) |
|
{ |
|
EINA_SAFETY_ON_NULL_RETURN(fav); |
|
eina_hash_add(fav->items, url, fav_item); |
|
} |
|
|
|
void |
|
fav_items_del(Fav *fav, const char * url) |
|
{ |
|
EINA_SAFETY_ON_NULL_RETURN(fav); |
|
eina_hash_del(fav->items, url, NULL); |
|
} |
|
|
|
inline Fav_Item * |
|
fav_items_get(const Fav *fav, const char * url) |
|
{ |
|
EINA_SAFETY_ON_NULL_RETURN_VAL(fav, NULL); |
|
return eina_hash_find(fav->items, url); |
|
} |
|
|
|
inline Eina_Hash * |
|
fav_items_hash_get(const Fav *fav) |
|
{ |
|
EINA_SAFETY_ON_NULL_RETURN_VAL(fav, NULL); |
|
return fav->items; |
|
} |
|
|
|
void |
|
fav_items_modify(Fav *fav, const char * key, void *value) |
|
{ |
|
EINA_SAFETY_ON_NULL_RETURN(fav); |
|
eina_hash_modify(fav->items, key, value); |
|
} |
|
|
|
Fav * |
|
fav_load(const char *filename) |
|
{ |
|
Fav *fav; |
|
Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); |
|
if (!ef) |
|
{ |
|
fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); |
|
return NULL; |
|
} |
|
|
|
fav = eet_data_read(ef, _fav_descriptor, FAV_ENTRY); |
|
fav->__eet_filename = eina_stringshare_add(filename); |
|
|
|
if (!fav->items) fav->items = eina_hash_stringshared_new(EINA_FREE_CB(fav_item_free)); |
|
|
|
eet_close(ef); |
|
return fav; |
|
} |
|
|
|
Eina_Bool |
|
fav_save(Fav *fav, const char *filename) |
|
{ |
|
char tmp[PATH_MAX]; |
|
Eet_File *ef; |
|
Eina_Bool ret; |
|
unsigned int i, len; |
|
struct stat st; |
|
|
|
if (filename) fav->__eet_filename = eina_stringshare_add(filename); |
|
else if (fav->__eet_filename) filename = fav->__eet_filename; |
|
else return EINA_FALSE; |
|
|
|
len = eina_strlcpy(tmp, filename, sizeof(tmp)); |
|
if (len + 12 >= (int)sizeof(tmp)) |
|
{ |
|
fprintf(stderr, "ERROR: filename is too big: %s\n", filename); |
|
return EINA_FALSE; |
|
} |
|
|
|
i = 0; |
|
do |
|
{ |
|
snprintf(tmp + len, 12, ".%u", i); |
|
i++; |
|
} |
|
while(stat(tmp, &st) == 0); |
|
|
|
ef = eet_open(tmp, EET_FILE_MODE_WRITE); |
|
if (!ef) |
|
{ |
|
fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp); |
|
return EINA_FALSE; |
|
} |
|
|
|
ret = !!eet_data_write(ef, _fav_descriptor, FAV_ENTRY, fav, EINA_TRUE); |
|
eet_close(ef); |
|
|
|
if (ret) |
|
{ |
|
unlink(filename); |
|
rename(tmp, filename); |
|
} |
|
|
|
return ret; |
|
} |
|
|
|
void |
|
favorite_init(void) |
|
{ |
|
_fav_item_init(); |
|
_fav_init(); |
|
} |
|
|
|
void |
|
favorite_shutdown(void) |
|
{ |
|
_fav_item_shutdown(); |
|
_fav_shutdown(); |
|
} |
|
|
|
|