Commit c1f11402 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Prepared gtk application for friends' database storage

parent 56db674e
......@@ -1047,7 +1047,7 @@ void linphone_core_remove_friend_from_db(LinphoneCore *lc, LinphoneFriend *lf) {
}
}
MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc) {
const MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc) {
char *buf;
uint64_t begin,end;
MSList *result = NULL;
......@@ -1079,7 +1079,7 @@ void linphone_core_store_friend_in_db(LinphoneCore *lc, LinphoneFriend *lf) {
void linphone_core_remove_friend_from_db(LinphoneCore *lc, LinphoneFriend *lf) {
}
MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc) {
const MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc) {
return NULL;
}
......
......@@ -1366,7 +1366,7 @@ static void ui_config_read(LinphoneCore *lc)
{
LinphoneFriend *lf = NULL;
#ifdef FRIENDS_SQL_STORAGE_ENABLED
MSList *friends = linphone_core_fetch_friends_from_db(lc);
const MSList *friends = linphone_core_fetch_friends_from_db(lc);
while (friends && friends->data) {
lf = friends->data;
friends = ms_list_next(friends);
......
......@@ -399,7 +399,7 @@ void linphone_core_friends_storage_init(LinphoneCore *lc);
void linphone_core_friends_storage_close(LinphoneCore *lc);
void linphone_core_store_friend_in_db(LinphoneCore *lc, LinphoneFriend *lf);
void linphone_core_remove_friend_from_db(LinphoneCore *lc, LinphoneFriend *lf);
MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc);
const MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc);
int parse_hostname_to_addr(const char *server, struct sockaddr_storage *ss, socklen_t *socklen, int default_port);
......
......@@ -991,3 +991,30 @@ gboolean linphone_gtk_friend_list_motion_event_handler(GtkTreeView *friendlist,
return FALSE;
}
#define CONFIG_FILE ".linphone-friends.db"
char *linphone_gtk_friends_storage_get_db_file(const char *filename){
const int path_max=1024;
char *db_file=NULL;
db_file=(char *)g_malloc(path_max*sizeof(char));
if (filename==NULL) filename=CONFIG_FILE;
/*try accessing a local file first if exists*/
if (access(CONFIG_FILE,F_OK)==0){
snprintf(db_file,path_max,"%s",filename);
}else{
#ifdef WIN32
const char *appdata=getenv("APPDATA");
if (appdata){
snprintf(db_file,path_max,"%s\\%s",appdata,LINPHONE_CONFIG_DIR);
CreateDirectory(db_file,NULL);
snprintf(db_file,path_max,"%s\\%s\\%s",appdata,LINPHONE_CONFIG_DIR,filename);
}
#else
const char *home=getenv("HOME");
if (home==NULL) home=".";
snprintf(db_file,path_max,"%s/%s",home,filename);
#endif
}
return db_file;
}
\ No newline at end of file
......@@ -116,6 +116,7 @@ LINPHONE_PUBLIC GtkWidget *linphone_gtk_make_tab_header(const gchar *label, cons
char *linphone_gtk_message_storage_get_db_file(const char *filename);
char *linphone_gtk_call_logs_storage_get_db_file(const char *filename);
char *linphone_gtk_friends_storage_get_db_file(const char* filename);
LINPHONE_PUBLIC void linphone_gtk_close_assistant(void);
LINPHONE_PUBLIC LinphoneCore *linphone_gtk_get_core(void);
......
......@@ -252,7 +252,8 @@ gboolean linphone_gtk_get_audio_assistant_option(void){
}
static void linphone_gtk_init_liblinphone(const char *config_file,
const char *factory_config_file, const char *chat_messages_db_file, const char *call_logs_db_file) {
const char *factory_config_file, const char *chat_messages_db_file,
const char *call_logs_db_file, const char *friends_db_file) {
LinphoneCoreVTable vtable={0};
gchar *secrets_file=linphone_gtk_get_config_file(SECRETS_FILE);
gchar *user_certificates_dir=linphone_gtk_get_config_file(CERTIFICATES_PATH);
......@@ -299,6 +300,7 @@ static void linphone_gtk_init_liblinphone(const char *config_file,
}
if (chat_messages_db_file) linphone_core_set_chat_database_path(the_core,chat_messages_db_file);
if (call_logs_db_file) linphone_core_set_call_logs_database_path(the_core, call_logs_db_file);
if (friends_db_file) linphone_core_set_friends_database_path(the_core, friends_db_file);
}
LinphoneCore *linphone_gtk_get_core(void){
......@@ -2074,7 +2076,7 @@ int main(int argc, char *argv[]){
const char *icon_name=LINPHONE_ICON_NAME;
const char *app_name="Linphone";
LpConfig *factory;
char *chat_messages_db_file, *call_logs_db_file;
char *chat_messages_db_file, *call_logs_db_file, *friends_db_file;
GError *error=NULL;
const char *tmp;
......@@ -2212,9 +2214,11 @@ core_start:
chat_messages_db_file=linphone_gtk_message_storage_get_db_file(NULL);
call_logs_db_file = linphone_gtk_call_logs_storage_get_db_file(NULL);
linphone_gtk_init_liblinphone(config_file, factory_config_file, chat_messages_db_file, call_logs_db_file);
friends_db_file = linphone_gtk_friends_storage_get_db_file(NULL);
linphone_gtk_init_liblinphone(config_file, factory_config_file, chat_messages_db_file, call_logs_db_file, friends_db_file);
g_free(chat_messages_db_file);
g_free(call_logs_db_file);
g_free(friends_db_file);
#ifdef CALL_LOGS_STORAGE_ENABLED
linphone_gtk_call_log_update(the_ui);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment