diff options
Diffstat (limited to 'geyes/src/themes.c')
-rw-r--r-- | geyes/src/themes.c | 492 |
1 files changed, 252 insertions, 240 deletions
diff --git a/geyes/src/themes.c b/geyes/src/themes.c index 6eed8cc9..cb187ca4 100644 --- a/geyes/src/themes.c +++ b/geyes/src/themes.c @@ -14,7 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - * */ #include <config.h> @@ -27,325 +26,338 @@ #include "geyes.h" #define GET_WIDGET(x) (GTK_WIDGET (gtk_builder_get_object (builder, (x)))) - #define NUM_THEME_DIRECTORIES 2 static char *theme_directories[NUM_THEME_DIRECTORIES]; enum { - COL_THEME_DIR = 0, - COL_THEME_NAME, - TOTAL_COLS + COL_THEME_DIR = 0, + COL_THEME_NAME, + TOTAL_COLS }; -void theme_dirs_create (void) +void +theme_dirs_create (void) { - static gboolean themes_created = FALSE; + static gboolean themes_created = FALSE; - if (themes_created == TRUE) - return; + if (themes_created == TRUE) + return; - theme_directories[0] = g_build_filename(GEYES_THEMES_DIR, NULL); + theme_directories[0] = g_build_filename (GEYES_THEMES_DIR, NULL); - theme_directories[1] = g_build_filename(g_get_user_config_dir(), "mate", "geyes-themes", NULL); + theme_directories[1] = g_build_filename (g_get_user_config_dir (), "mate", + "geyes-themes", NULL); - themes_created = TRUE; + themes_created = TRUE; } static void -parse_theme_file (EyesApplet *eyes_applet, FILE *theme_file) +parse_theme_file (EyesApplet *eyes_applet, + FILE *theme_file) { - gchar line_buf [512]; /* prolly overkill */ - gchar *token; - - if (fgets (line_buf, 512, theme_file) == NULL) - printf("fgets error\n"); - - while (!feof (theme_file)) { - token = strtok (line_buf, "="); - if (strncmp (token, "wall-thickness", - strlen ("wall-thickness")) == 0) { - token += strlen ("wall-thickness"); - while (!isdigit (*token)) { - token++; - } - sscanf (token, "%d", &eyes_applet->wall_thickness); - } else if (strncmp (token, "num-eyes", strlen ("num-eyes")) == 0) { - token += strlen ("num-eyes"); - while (!isdigit (*token)) { - token++; - } - sscanf (token, "%d", &eyes_applet->num_eyes); - if (eyes_applet->num_eyes > MAX_EYES) - eyes_applet->num_eyes = MAX_EYES; - } else if (strncmp (token, "eye-pixmap", strlen ("eye-pixmap")) == 0) { - token = strtok (NULL, "\""); - token = strtok (NULL, "\""); - if (eyes_applet->eye_filename != NULL) - g_free (eyes_applet->eye_filename); - eyes_applet->eye_filename = g_strdup_printf ("%s%s", - eyes_applet->theme_dir, - token); - } else if (strncmp (token, "pupil-pixmap", strlen ("pupil-pixmap")) == 0) { - token = strtok (NULL, "\""); - token = strtok (NULL, "\""); + gchar line_buf[512]; /* prolly overkill */ + gchar *token; + + if (fgets (line_buf, 512, theme_file) == NULL) + printf ("fgets error\n"); + + while (!feof (theme_file)) { + token = strtok (line_buf, "="); + if (strncmp (token, "wall-thickness", strlen ("wall-thickness")) == 0) { + token += strlen ("wall-thickness"); + while (!isdigit (*token)) { + token++; + } + sscanf (token, "%d", &eyes_applet->wall_thickness); + } else if (strncmp (token, "num-eyes", strlen ("num-eyes")) == 0) { + token += strlen ("num-eyes"); + while (!isdigit (*token)) { + token++; + } + sscanf (token, "%d", &eyes_applet->num_eyes); + if (eyes_applet->num_eyes > MAX_EYES) + eyes_applet->num_eyes = MAX_EYES; + } else if (strncmp (token, "eye-pixmap", strlen ("eye-pixmap")) == 0) { + token = strtok (NULL, "\""); + token = strtok (NULL, "\""); + if (eyes_applet->eye_filename != NULL) + g_free (eyes_applet->eye_filename); + eyes_applet->eye_filename + = g_strdup_printf ("%s%s", eyes_applet->theme_dir, token); + } else if (strncmp (token, "pupil-pixmap", strlen ("pupil-pixmap")) == 0) { + token = strtok (NULL, "\""); + token = strtok (NULL, "\""); if (eyes_applet->pupil_filename != NULL) - g_free (eyes_applet->pupil_filename); + g_free (eyes_applet->pupil_filename); eyes_applet->pupil_filename - = g_strdup_printf ("%s%s", - eyes_applet->theme_dir, - token); - } - if (fgets (line_buf, 512, theme_file) == NULL) - printf("fgets error\n"); + = g_strdup_printf ("%s%s", eyes_applet->theme_dir, token); } + if (fgets (line_buf, 512, theme_file) == NULL) + printf ("fgets error\n"); + } } int -load_theme (EyesApplet *eyes_applet, const gchar *theme_dir) +load_theme (EyesApplet *eyes_applet, + const gchar *theme_dir) { - GtkWidget *dialog; + GtkWidget *dialog; + FILE *theme_file; + gchar *file_name; - FILE* theme_file; - gchar *file_name; + eyes_applet->theme_dir = g_strdup_printf ("%s/", theme_dir); - eyes_applet->theme_dir = g_strdup_printf ("%s/", theme_dir); + file_name = g_strdup_printf ("%s%s", theme_dir, "/config"); + theme_file = fopen (file_name, "r"); + g_free (file_name); - file_name = g_strdup_printf("%s%s",theme_dir,"/config"); - theme_file = fopen (file_name, "r"); - g_free (file_name); - if (theme_file == NULL) { - g_free (eyes_applet->theme_dir); - eyes_applet->theme_dir = g_strdup_printf (GEYES_THEMES_DIR "Default-tiny/"); - theme_file = fopen (GEYES_THEMES_DIR "Default-tiny/config", "r"); - } + if (theme_file == NULL) { + g_free (eyes_applet->theme_dir); - /* if it's still NULL we've got a major problem */ - if (theme_file == NULL) { - dialog = gtk_message_dialog_new_with_markup (NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - "<b>%s</b>\n\n%s", - _("Can not launch the eyes applet."), - _("There was a fatal error while trying to load the theme.")); + eyes_applet->theme_dir = g_strdup_printf (GEYES_THEMES_DIR "Default-tiny/"); + theme_file = fopen (GEYES_THEMES_DIR "Default-tiny/config", "r"); + } - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); + /* if it's still NULL we've got a major problem */ + if (theme_file == NULL) { + dialog = gtk_message_dialog_new_with_markup (NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, + "<b>%s</b>\n\n%s", + _("Can not launch the eyes applet."), + _("There was a fatal error while trying to load the theme.")); - gtk_widget_destroy (GTK_WIDGET (eyes_applet->applet)); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); - return FALSE; - } + gtk_widget_destroy (GTK_WIDGET (eyes_applet->applet)); - parse_theme_file (eyes_applet, theme_file); - fclose (theme_file); + return FALSE; + } - eyes_applet->theme_name = g_strdup (theme_dir); + parse_theme_file (eyes_applet, theme_file); + fclose (theme_file); - if (eyes_applet->eye_image) - g_object_unref (eyes_applet->eye_image); - eyes_applet->eye_image = gdk_pixbuf_new_from_file (eyes_applet->eye_filename, NULL); - if (eyes_applet->pupil_image) - g_object_unref (eyes_applet->pupil_image); - eyes_applet->pupil_image = gdk_pixbuf_new_from_file (eyes_applet->pupil_filename, NULL); + eyes_applet->theme_name = g_strdup (theme_dir); - eyes_applet->eye_height = gdk_pixbuf_get_height (eyes_applet->eye_image); - eyes_applet->eye_width = gdk_pixbuf_get_width (eyes_applet->eye_image); - eyes_applet->pupil_height = gdk_pixbuf_get_height (eyes_applet->pupil_image); - eyes_applet->pupil_width = gdk_pixbuf_get_width (eyes_applet->pupil_image); + if (eyes_applet->eye_image) + g_object_unref (eyes_applet->eye_image); - return TRUE; + eyes_applet->eye_image + = gdk_pixbuf_new_from_file (eyes_applet->eye_filename, + NULL); + + if (eyes_applet->pupil_image) + g_object_unref (eyes_applet->pupil_image); + + eyes_applet->pupil_image + = gdk_pixbuf_new_from_file (eyes_applet->pupil_filename, + NULL); + + eyes_applet->eye_height = gdk_pixbuf_get_height (eyes_applet->eye_image); + eyes_applet->eye_width = gdk_pixbuf_get_width (eyes_applet->eye_image); + eyes_applet->pupil_height = gdk_pixbuf_get_height (eyes_applet->pupil_image); + eyes_applet->pupil_width = gdk_pixbuf_get_width (eyes_applet->pupil_image); + + return TRUE; } static void destroy_theme (EyesApplet *eyes_applet) { - /* Dunno about this - to unref or not to unref? */ - if (eyes_applet->eye_image != NULL) { - g_object_unref (eyes_applet->eye_image); - eyes_applet->eye_image = NULL; - } - if (eyes_applet->pupil_image != NULL) { - g_object_unref (eyes_applet->pupil_image); - eyes_applet->pupil_image = NULL; - } - - g_free (eyes_applet->theme_dir); - g_free (eyes_applet->theme_name); + /* Dunno about this - to unref or not to unref? */ + if (eyes_applet->eye_image != NULL) { + g_object_unref (eyes_applet->eye_image); + eyes_applet->eye_image = NULL; + } + if (eyes_applet->pupil_image != NULL) { + g_object_unref (eyes_applet->pupil_image); + eyes_applet->pupil_image = NULL; + } + + g_free (eyes_applet->theme_dir); + g_free (eyes_applet->theme_name); } static void -theme_selected_cb (GtkTreeSelection *selection, gpointer data) +theme_selected_cb (GtkTreeSelection *selection, + gpointer data) { - EyesApplet *eyes_applet = data; - GtkTreeModel *model; - GtkTreeIter iter; - gchar *theme; - gchar *theme_dir; + EyesApplet *eyes_applet = data; + GtkTreeModel *model; + GtkTreeIter iter; + gchar *theme; + gchar *theme_dir; - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - return; + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) + return; - gtk_tree_model_get (model, &iter, COL_THEME_DIR, &theme, -1); + gtk_tree_model_get (model, &iter, COL_THEME_DIR, &theme, -1); - g_return_if_fail (theme); + g_return_if_fail (theme); - theme_dir = g_strdup_printf ("%s/", theme); - if (!g_ascii_strncasecmp (theme_dir, eyes_applet->theme_dir, strlen (theme_dir))) { - g_free (theme_dir); - return; - } - g_free (theme_dir); + theme_dir = g_strdup_printf ("%s/", theme); + if (!g_ascii_strncasecmp (theme_dir, eyes_applet->theme_dir, + strlen (theme_dir))) { + g_free (theme_dir); + return; + } + g_free (theme_dir); - destroy_eyes (eyes_applet); - destroy_theme (eyes_applet); - load_theme (eyes_applet, theme); - setup_eyes (eyes_applet); + destroy_eyes (eyes_applet); + destroy_theme (eyes_applet); + load_theme (eyes_applet, theme); + setup_eyes (eyes_applet); - g_settings_set_string ( - eyes_applet->settings, "theme-path", theme); + g_settings_set_string (eyes_applet->settings, "theme-path", theme); - g_free (theme); + g_free (theme); } static void phelp_cb (GtkDialog *dialog) { - GError *error = NULL; - - gtk_show_uri_on_window (GTK_WINDOW (dialog), - "help:mate-geyes/geyes-settings", - gtk_get_current_event_time (), - &error); - - if (error) { - GtkWidget *error_dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - _("There was an error displaying help: %s"), error->message); - g_signal_connect (G_OBJECT (error_dialog), "response", G_CALLBACK (gtk_widget_destroy) , NULL); - gtk_window_set_resizable (GTK_WINDOW (error_dialog), FALSE); - gtk_window_set_screen (GTK_WINDOW (error_dialog), gtk_widget_get_screen (GTK_WIDGET (dialog))); - gtk_widget_show (error_dialog); - g_error_free (error); - error = NULL; - } + GError *error = NULL; + + gtk_show_uri_on_window (GTK_WINDOW (dialog), "help:mate-geyes/geyes-settings", + gtk_get_current_event_time (), + &error); + + if (error) { + GtkWidget *error_dialog + = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + _("There was an error displaying help: %s"), + error->message); + g_signal_connect (G_OBJECT (error_dialog), "response", + G_CALLBACK (gtk_widget_destroy), + NULL); + gtk_window_set_resizable (GTK_WINDOW (error_dialog), FALSE); + gtk_window_set_screen (GTK_WINDOW (error_dialog), + gtk_widget_get_screen (GTK_WIDGET (dialog))); + gtk_widget_show (error_dialog); + g_error_free (error); + error = NULL; + } } static void -presponse_cb (GtkDialog *dialog, gint id, gpointer data) +presponse_cb (GtkDialog *dialog, + gint id, + gpointer data) { - EyesApplet *eyes_applet = data; - if(id == GTK_RESPONSE_HELP){ - phelp_cb (dialog); - return; - } - + EyesApplet *eyes_applet = data; + if (id == GTK_RESPONSE_HELP) { + phelp_cb (dialog); + return; + } - gtk_widget_destroy (GTK_WIDGET (dialog)); + gtk_widget_destroy (GTK_WIDGET (dialog)); - eyes_applet->prop_box.pbox = NULL; + eyes_applet->prop_box.pbox = NULL; } void properties_cb (GtkAction *action, - EyesApplet *eyes_applet) + EyesApplet *eyes_applet) { - GtkBuilder *builder; - GtkWidget *tree; - GtkWidget *label; - GtkListStore *model; - GtkTreeViewColumn *column; - GtkCellRenderer *cell; - GtkTreeIter iter; - DIR *dfd; - struct dirent *dp; - int i; + GtkBuilder *builder; + GtkWidget *tree; + GtkWidget *label; + GtkListStore *model; + GtkTreeViewColumn *column; + GtkCellRenderer *cell; + GtkTreeIter iter; + DIR *dfd; + struct dirent *dp; + int i; #ifdef PATH_MAX - gchar filename [PATH_MAX]; + gchar filename [PATH_MAX]; #else - gchar *filename; + gchar *filename; #endif - if (eyes_applet->prop_box.pbox) { - gtk_window_set_screen ( - GTK_WINDOW (eyes_applet->prop_box.pbox), - gtk_widget_get_screen (GTK_WIDGET (eyes_applet->applet))); - gtk_window_present (GTK_WINDOW (eyes_applet->prop_box.pbox)); - return; - } - - builder = gtk_builder_new_from_resource (GEYES_RESOURCE_PATH "themes.ui"); - - eyes_applet->prop_box.pbox = GET_WIDGET ("preferences_dialog"); - tree = GET_WIDGET ("themes_treeview"); - label = GET_WIDGET ("select_theme_label"); - - model = gtk_list_store_new (TOTAL_COLS, G_TYPE_STRING, G_TYPE_STRING); - gtk_tree_view_set_model (GTK_TREE_VIEW (tree), GTK_TREE_MODEL (model)); - cell = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("not used", cell, - "text", COL_THEME_NAME, NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column); - - if ( ! g_settings_is_writable (eyes_applet->settings, "theme-path")) { - gtk_widget_set_sensitive (tree, FALSE); - gtk_widget_set_sensitive (label, FALSE); - } - - for (i = 0; i < NUM_THEME_DIRECTORIES; i++) { - if ((dfd = opendir (theme_directories[i])) != NULL) { - while ((dp = readdir (dfd)) != NULL) { - if (dp->d_name[0] != '.') { - gchar *theme_dir; - gchar *theme_name; + if (eyes_applet->prop_box.pbox) { + gtk_window_set_screen (GTK_WINDOW (eyes_applet->prop_box.pbox), + gtk_widget_get_screen (GTK_WIDGET (eyes_applet->applet))); + + gtk_window_present (GTK_WINDOW (eyes_applet->prop_box.pbox)); + return; + } + + builder = gtk_builder_new_from_resource (GEYES_RESOURCE_PATH "themes.ui"); + + eyes_applet->prop_box.pbox = GET_WIDGET("preferences_dialog"); + tree = GET_WIDGET("themes_treeview"); + label = GET_WIDGET("select_theme_label"); + + model = gtk_list_store_new (TOTAL_COLS, G_TYPE_STRING, G_TYPE_STRING); + gtk_tree_view_set_model (GTK_TREE_VIEW (tree), GTK_TREE_MODEL (model)); + cell = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes ("not used", cell, "text", + COL_THEME_NAME, + NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column); + + if (!g_settings_is_writable (eyes_applet->settings, "theme-path")) { + gtk_widget_set_sensitive (tree, FALSE); + gtk_widget_set_sensitive (label, FALSE); + } + + for (i = 0; i < NUM_THEME_DIRECTORIES; i++) { + if ((dfd = opendir (theme_directories[i])) != NULL) { + while ((dp = readdir (dfd)) != NULL) { + if (dp->d_name[0] != '.') { + gchar *theme_dir; + gchar *theme_name; #ifdef PATH_MAX - strcpy (filename, - theme_directories[i]); - strcat (filename, dp->d_name); + strcpy (filename, theme_directories[i]); + strcat (filename, dp->d_name); #else - asprintf (&filename, theme_directories[i], dp->d_name); + asprintf (&filename, theme_directories[i], dp->d_name); #endif - theme_dir = g_strdup_printf ("%s/", filename); - theme_name = g_path_get_basename (filename); - - gtk_list_store_append (model, &iter); - gtk_list_store_set (model, &iter, - COL_THEME_DIR, &filename, - COL_THEME_NAME, theme_name, - -1); - - if (!g_ascii_strncasecmp (eyes_applet->theme_dir, theme_dir, strlen (theme_dir))) { - GtkTreePath *path; - path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), - &iter); - gtk_tree_view_set_cursor (GTK_TREE_VIEW (tree), - path, - NULL, - FALSE); - gtk_tree_path_free (path); - } - g_free (theme_name); - g_free (theme_dir); - } - } - closedir (dfd); + theme_dir = g_strdup_printf ("%s/", filename); + theme_name = g_path_get_basename (filename); + + gtk_list_store_append (model, &iter); + gtk_list_store_set (model, &iter, COL_THEME_DIR, &filename, + COL_THEME_NAME, + theme_name, -1); + + if (!g_ascii_strncasecmp (eyes_applet->theme_dir, theme_dir, + strlen (theme_dir))) { + GtkTreePath *path; + path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), + &iter); + gtk_tree_view_set_cursor (GTK_TREE_VIEW (tree), path, NULL, + FALSE); + gtk_tree_path_free (path); + } + g_free (theme_name); + g_free (theme_dir); } + } + closedir (dfd); } + } #ifndef PATH_MAX - g_free (filename); + g_free (filename); #endif - g_object_unref (model); + g_object_unref (model); - /* signals */ - gtk_builder_add_callback_symbols (builder, - "on_preferences_dialog_response", G_CALLBACK (presponse_cb), - "on_themes_treeselection_changed", G_CALLBACK (theme_selected_cb), - NULL); - gtk_builder_connect_signals (builder, eyes_applet); + /* signals */ + gtk_builder_add_callback_symbols (builder, "on_preferences_dialog_response", + G_CALLBACK (presponse_cb), + "on_themes_treeselection_changed", + G_CALLBACK (theme_selected_cb), + NULL); + gtk_builder_connect_signals (builder, eyes_applet); - g_object_unref (builder); + g_object_unref (builder); - gtk_widget_show_all (eyes_applet->prop_box.pbox); + gtk_widget_show_all (eyes_applet->prop_box.pbox); - return; + return; } |