| [0] | 1 | #include "linphone.h" |
|---|
| 2 | |
|---|
| [229] | 3 | #include "lpconfig.h" |
|---|
| [0] | 4 | |
|---|
| 5 | static GList *pixmaps_directories = NULL; |
|---|
| 6 | |
|---|
| 7 | /* Use this function to set the directory containing installed pixmaps. */ |
|---|
| 8 | void |
|---|
| 9 | add_pixmap_directory (const gchar *directory) |
|---|
| 10 | { |
|---|
| 11 | pixmaps_directories = g_list_prepend (pixmaps_directories, |
|---|
| 12 | g_strdup (directory)); |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | /* This is an internally used function to find pixmap files. */ |
|---|
| 16 | static gchar* |
|---|
| 17 | find_pixmap_file (const gchar *filename) |
|---|
| 18 | { |
|---|
| 19 | GList *elem; |
|---|
| 20 | |
|---|
| 21 | /* We step through each of the pixmaps directory to find it. */ |
|---|
| 22 | elem = pixmaps_directories; |
|---|
| 23 | while (elem) |
|---|
| 24 | { |
|---|
| 25 | gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data, |
|---|
| 26 | G_DIR_SEPARATOR_S, filename); |
|---|
| 27 | if (g_file_test (pathname, G_FILE_TEST_EXISTS)) |
|---|
| 28 | return pathname; |
|---|
| 29 | g_free (pathname); |
|---|
| 30 | elem = elem->next; |
|---|
| 31 | } |
|---|
| 32 | return NULL; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | /* This is an internally used function to create pixmaps. */ |
|---|
| 36 | GtkWidget* |
|---|
| 37 | create_pixmap (GtkWidget *widget, |
|---|
| 38 | const gchar *filename) |
|---|
| 39 | { |
|---|
| 40 | gchar *pathname = NULL; |
|---|
| 41 | GtkWidget *pixmap; |
|---|
| 42 | |
|---|
| 43 | if (!filename || !filename[0]) |
|---|
| 44 | return gtk_image_new (); |
|---|
| 45 | |
|---|
| 46 | pathname = find_pixmap_file (filename); |
|---|
| 47 | |
|---|
| 48 | if (!pathname) |
|---|
| 49 | { |
|---|
| 50 | g_warning (_("Couldn't find pixmap file: %s"), filename); |
|---|
| 51 | return gtk_image_new (); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | pixmap = gtk_image_new_from_file (pathname); |
|---|
| 55 | g_free (pathname); |
|---|
| 56 | return pixmap; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | /* This is an internally used function to create pixmaps. */ |
|---|
| 60 | GdkPixbuf* |
|---|
| 61 | create_pixbuf (const gchar *filename) |
|---|
| 62 | { |
|---|
| 63 | gchar *pathname = NULL; |
|---|
| 64 | GdkPixbuf *pixbuf; |
|---|
| 65 | GError *error = NULL; |
|---|
| 66 | |
|---|
| 67 | if (!filename || !filename[0]) |
|---|
| 68 | return NULL; |
|---|
| 69 | |
|---|
| 70 | pathname = find_pixmap_file (filename); |
|---|
| 71 | |
|---|
| 72 | if (!pathname) |
|---|
| 73 | { |
|---|
| 74 | g_warning (_("Couldn't find pixmap file: %s"), filename); |
|---|
| 75 | return NULL; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | pixbuf = gdk_pixbuf_new_from_file (pathname, &error); |
|---|
| 79 | if (!pixbuf) |
|---|
| 80 | { |
|---|
| 81 | fprintf (stderr, "Failed to load pixbuf file: %s: %s\n", |
|---|
| 82 | pathname, error->message); |
|---|
| 83 | g_error_free (error); |
|---|
| 84 | } |
|---|
| 85 | g_free (pathname); |
|---|
| 86 | return pixbuf; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | /* This is used to set ATK action descriptions. */ |
|---|
| 90 | void |
|---|
| 91 | glade_set_atk_action_description (AtkAction *action, |
|---|
| 92 | const gchar *action_name, |
|---|
| 93 | const gchar *description) |
|---|
| 94 | { |
|---|
| 95 | gint n_actions, i; |
|---|
| 96 | |
|---|
| 97 | n_actions = atk_action_get_n_actions (action); |
|---|
| 98 | for (i = 0; i < n_actions; i++) |
|---|
| 99 | { |
|---|
| 100 | if (!strcmp (atk_action_get_name (action, i), action_name)) |
|---|
| 101 | atk_action_set_description (action, i, description); |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| [229] | 105 | |
|---|
| 106 | static char linphone_lang[256]={0}; |
|---|
| 107 | |
|---|
| 108 | /*lang has to be read before the config file is parsed...*/ |
|---|
| 109 | const char *linphone_gtk_get_lang(const char *config_file){ |
|---|
| 110 | FILE *f=fopen(config_file,"r"); |
|---|
| 111 | if (f){ |
|---|
| 112 | char tmp[256]; |
|---|
| 113 | while(fgets(tmp,sizeof(tmp),f)!=NULL){ |
|---|
| 114 | char *p; |
|---|
| 115 | if ((p=strstr(tmp,"lang="))!=NULL){ |
|---|
| 116 | p+=5; |
|---|
| 117 | sscanf(p,"%s",linphone_lang); |
|---|
| 118 | g_message("Found lang %s",linphone_lang); |
|---|
| 119 | break; |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| [342] | 122 | fclose(f); |
|---|
| [229] | 123 | } |
|---|
| 124 | return linphone_lang; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| [570] | 127 | void linphone_gtk_set_lang(const char *code){ |
|---|
| 128 | LpConfig *cfg=linphone_core_get_config(linphone_gtk_get_core()); |
|---|
| 129 | lp_config_set_string(cfg,"GtkUi","lang",code); |
|---|
| 130 | #ifdef WIN32 |
|---|
| 131 | char tmp[128]; |
|---|
| 132 | snprintf(tmp,sizeof(tmp),"LANG=%s",code); |
|---|
| 133 | _putenv(tmp); |
|---|
| 134 | #else |
|---|
| 135 | setenv("LANG",code,1); |
|---|
| 136 | #endif |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| [229] | 139 | const gchar *linphone_gtk_get_ui_config(const char *key, const char *def){ |
|---|
| 140 | LinphoneCore *lc=linphone_gtk_get_core(); |
|---|
| 141 | if (lc){ |
|---|
| 142 | LpConfig *cfg=linphone_core_get_config(linphone_gtk_get_core()); |
|---|
| 143 | return lp_config_get_string(cfg,"GtkUi",key,def); |
|---|
| 144 | }else{ |
|---|
| 145 | ms_warning ("Cannot read config, no core created yet."); |
|---|
| 146 | return NULL; |
|---|
| 147 | } |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | int linphone_gtk_get_ui_config_int(const char *key, int def){ |
|---|
| 151 | LpConfig *cfg=linphone_core_get_config(linphone_gtk_get_core()); |
|---|
| 152 | return lp_config_get_int(cfg,"GtkUi",key,def); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | |
|---|