[gthumb] show the emblems in the window title when in viewer mode



commit bdccfcdcc5c3b3b4226988ad86d632e9c0b3d505
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Apr 13 16:47:32 2014 +0200

    show the emblems in the window title when in viewer mode

 gthumb/Makefile.am        |    2 +
 gthumb/gth-browser.c      |   33 +++++++++++--
 gthumb/gth-icon-cache.c   |    2 +-
 gthumb/gth-window-title.c |  114 +++++++++++++++++++++++++++++++++++++++++++++
 gthumb/gth-window-title.h |   60 +++++++++++++++++++++++
 gthumb/gth-window.c       |   25 ++++------
 gthumb/gth-window.h       |    2 +-
 7 files changed, 217 insertions(+), 21 deletions(-)
---
diff --git a/gthumb/Makefile.am b/gthumb/Makefile.am
index df0251f..ce882b9 100644
--- a/gthumb/Makefile.am
+++ b/gthumb/Makefile.am
@@ -134,6 +134,7 @@ PRIVATE_HEADER_FILES =                                      \
        dlg-preferences.h                               \
        dlg-sort-order.h                                \
        main-migrate.h                                  \
+       gth-window-title.h                              \
        $(NULL)
 
 RESOURCES =                                            \
@@ -251,6 +252,7 @@ gthumb_SOURCES =                                    \
        gth-user-dir.c                                  \
        gth-viewer-page.c                               \
        gth-window.c                                    \
+       gth-window-title.c                              \
        gtk-utils.c                                     \
        gvaluehash.c                                    \
        main.c                                          \
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 3862cd9..16bb371 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -319,9 +319,9 @@ _gth_browser_update_current_file_position (GthBrowser *browser)
 void
 gth_browser_update_title (GthBrowser *browser)
 {
-       GString      *title;
-       const char   *name = NULL;
-
+       GString    *title;
+       const char *name = NULL;
+       GList      *emblems = NULL;
 
        title = g_string_new (NULL);
 
@@ -343,15 +343,26 @@ gth_browser_update_title (GthBrowser *browser)
                        g_string_append (title, " ");
                        g_string_append (title, _("[modified]"));
                }
+
+               if (browser->priv->current_file != NULL) {
+                       GthStringList *string_list;
+
+                       string_list = GTH_STRING_LIST (g_file_info_get_attribute_object 
(browser->priv->current_file->info, GTH_FILE_ATTRIBUTE_EMBLEMS));
+                       if (string_list != NULL)
+                               emblems = _g_string_list_dup (gth_string_list_get_list (string_list));
+               }
                break;
        }
 
        if (title->len == 0)
                g_string_append (title, _("gThumb"));
 
-       gth_window_set_title (GTH_WINDOW (browser), title->str, NULL);
+       gth_window_set_title (GTH_WINDOW (browser),
+                             title->str,
+                             emblems);
 
        g_string_free (title, TRUE);
+       _g_string_list_free (emblems);
 }
 
 
@@ -3215,6 +3226,20 @@ emblems_attributes_ready_cb (GthFileSource *file_source,
 
                gth_file_list_update_emblems (GTH_FILE_LIST (browser->priv->file_list), files);
                gth_file_list_update_emblems (GTH_FILE_LIST (browser->priv->thumbnail_list), files);
+
+               if (browser->priv->current_file != NULL) {
+                       GList *link;
+
+                       link = gth_file_data_list_find_file (files, browser->priv->current_file->file);
+                       if (link != NULL) {
+                               GthFileData *current_file_data = link->data;
+                               GObject     *emblems;
+
+                               emblems = g_file_info_get_attribute_object (current_file_data->info, 
GTH_FILE_ATTRIBUTE_EMBLEMS);
+                               g_file_info_set_attribute_object (browser->priv->current_file->info, 
GTH_FILE_ATTRIBUTE_EMBLEMS, emblems);
+                               gth_browser_update_title (browser);
+                       }
+               }
        }
 
        emblems_data_free (data);
diff --git a/gthumb/gth-icon-cache.c b/gthumb/gth-icon-cache.c
index 1806e87..18357b2 100644
--- a/gthumb/gth-icon-cache.c
+++ b/gthumb/gth-icon-cache.c
@@ -151,7 +151,7 @@ gth_icon_cache_get_surface (GthIconCache *icon_cache,
        if ((icon != NULL) && (surface != NULL))
                g_hash_table_insert (icon_cache->surface_cache, g_object_ref (icon), cairo_surface_reference 
(surface));
 
-       g_object_unref (pixbuf);
+       _g_object_unref (pixbuf);
 
        return surface;
 }
diff --git a/gthumb/gth-window-title.c b/gthumb/gth-window-title.c
new file mode 100644
index 0000000..94ceae4
--- /dev/null
+++ b/gthumb/gth-window-title.c
@@ -0,0 +1,114 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2014 Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY 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 <config.h>
+#include <string.h>
+#include <glib/gi18n.h>
+#include <glib.h>
+#include <gtk/gtk.h>
+#include "gth-window-title.h"
+#include "gtk-utils.h"
+
+
+struct _GthWindowTitlePrivate {
+       GtkWidget     *title;
+       GtkWidget     *emblems;
+};
+
+
+G_DEFINE_TYPE (GthWindowTitle,
+              gth_window_title,
+              GTK_TYPE_BOX)
+
+
+static void
+gth_window_title_finalize (GObject *object)
+{
+       GthWindowTitle *self;
+
+       self = GTH_WINDOW_TITLE (object);
+
+       G_OBJECT_CLASS (gth_window_title_parent_class)->finalize (object);
+}
+
+static void
+gth_window_title_class_init (GthWindowTitleClass *klass)
+{
+       GObjectClass *object_class;
+
+       g_type_class_add_private (klass, sizeof (GthWindowTitlePrivate));
+
+       object_class = (GObjectClass*) klass;
+       object_class->finalize = gth_window_title_finalize;
+}
+
+
+static void
+gth_window_title_init (GthWindowTitle *self)
+{
+       self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_WINDOW_TITLE, GthWindowTitlePrivate);
+
+       gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL);
+       gtk_box_set_spacing (GTK_BOX (self), 10);
+
+       self->priv->title = gtk_label_new ("");
+       gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->title), "title");
+       gtk_box_pack_start (GTK_BOX (self), self->priv->title, FALSE, FALSE, 0);
+
+       self->priv->emblems = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
+       gtk_box_pack_start (GTK_BOX (self), self->priv->emblems, FALSE, FALSE, 0);
+}
+
+
+GtkWidget *
+gth_window_title_new (void)
+{
+       return (GtkWidget *) g_object_new (GTH_TYPE_WINDOW_TITLE, NULL);
+}
+
+
+void
+gth_window_title_set_title (GthWindowTitle     *self,
+                           const char          *title)
+{
+       gtk_label_set_text (GTK_LABEL (self->priv->title), (title != NULL) ? title : "");
+       gtk_widget_set_visible (self->priv->title, title != NULL);
+}
+
+
+void
+gth_window_title_set_emblems (GthWindowTitle   *self,
+                             GList             *emblems)
+{
+       GList *scan;
+
+       _gtk_container_remove_children (GTK_CONTAINER (self->priv->emblems), NULL, NULL);
+       for (scan = emblems; scan; scan = scan->next) {
+               char      *emblem = scan->data;
+               GtkWidget *icon;
+
+               icon = gtk_image_new_from_icon_name (emblem, GTK_ICON_SIZE_MENU);
+               gtk_widget_show (icon);
+               gtk_box_pack_start (GTK_BOX (self->priv->emblems), icon, FALSE, FALSE, 0);
+       }
+
+       gtk_widget_set_visible (self->priv->emblems, emblems != NULL);
+}
diff --git a/gthumb/gth-window-title.h b/gthumb/gth-window-title.h
new file mode 100644
index 0000000..51a337c
--- /dev/null
+++ b/gthumb/gth-window-title.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2014 Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY 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/>.
+ */
+
+#ifndef GTH_WINDOW_TITLE_H
+#define GTH_WINDOW_TITLE_H
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GTH_TYPE_WINDOW_TITLE            (gth_window_title_get_type ())
+#define GTH_WINDOW_TITLE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTH_TYPE_WINDOW_TITLE, 
GthWindowTitle))
+#define GTH_WINDOW_TITLE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTH_TYPE_WINDOW_TITLE, 
GthWindowTitleClass))
+#define GTH_IS_WINDOW_TITLE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTH_TYPE_WINDOW_TITLE))
+#define GTH_IS_WINDOW_TITLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTH_TYPE_WINDOW_TITLE))
+#define GTH_WINDOW_TITLE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTH_TYPE_WINDOW_TITLE, 
GthWindowTitleClass))
+
+typedef struct _GthWindowTitle GthWindowTitle;
+typedef struct _GthWindowTitleClass GthWindowTitleClass;
+typedef struct _GthWindowTitlePrivate GthWindowTitlePrivate;
+
+struct _GthWindowTitle {
+       GtkBox parent_instance;
+       GthWindowTitlePrivate *priv;
+};
+
+struct _GthWindowTitleClass {
+       GtkBoxClass parent_class;
+};
+
+GType            gth_window_title_get_type     (void);
+GtkWidget *      gth_window_title_new          (void);
+void             gth_window_title_set_title    (GthWindowTitle *window_title,
+                                                const char     *title);
+void             gth_window_title_set_emblems  (GthWindowTitle *window_title,
+                                                GList          *emblems);
+
+G_END_DECLS
+
+#endif /* GTH_WINDOW_TITLE_H */
diff --git a/gthumb/gth-window.c b/gthumb/gth-window.c
index f09208f..76e59af 100644
--- a/gthumb/gth-window.c
+++ b/gthumb/gth-window.c
@@ -22,6 +22,7 @@
 #include <config.h>
 #include <gtk/gtk.h>
 #include "gth-window.h"
+#include "gth-window-title.h"
 #include "gtk-utils.h"
 #include "main.h"
 
@@ -43,6 +44,7 @@ struct _GthWindowPrivate {
        GtkWidget       *grid;
        GtkWidget       *stack;
        GtkWidget       *headerbar;
+       GtkWidget       *title;
        GtkWidget       *menubar;
        GtkWidget       *toolbar;
        GtkWidget       *infobar;
@@ -113,6 +115,9 @@ _gth_window_add_header_bar (GthWindow *self)
        self->priv->headerbar = gtk_header_bar_new ();
        gtk_widget_show (self->priv->headerbar);
        gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (self->priv->headerbar), TRUE);
+       self->priv->title = gth_window_title_new ();
+       gtk_widget_show (self->priv->title);
+       gtk_header_bar_set_custom_title (GTK_HEADER_BAR (self->priv->headerbar), self->priv->title);
        gtk_window_set_titlebar (GTK_WINDOW (self), self->priv->headerbar);
 }
 
@@ -560,24 +565,14 @@ gth_window_get_page_size (GthWindow *window,
 void
 gth_window_set_title (GthWindow  *window,
                      const char *title,
-                     const char *subtitle)
+                     GList      *emblems)
 {
        if (window->priv->use_header_bar) {
-               gtk_header_bar_set_title (GTK_HEADER_BAR (window->priv->headerbar), title);
-               gtk_header_bar_set_subtitle (GTK_HEADER_BAR (window->priv->headerbar), subtitle);
-       }
-       else {
-               GString *complete_title;
-
-               complete_title = g_string_new (title);
-               if (subtitle != NULL) {
-                       g_string_append (complete_title, " - ");
-                       g_string_append (complete_title, subtitle);
-               }
-               gtk_window_set_title (GTK_WINDOW (window), complete_title->str);
-
-               g_string_free (complete_title, TRUE);
+               gth_window_title_set_title (GTH_WINDOW_TITLE (window->priv->title), title);
+               gth_window_title_set_emblems (GTH_WINDOW_TITLE (window->priv->title), emblems);
        }
+       else
+               gtk_window_set_title (GTK_WINDOW (window), title);
 }
 
 
diff --git a/gthumb/gth-window.h b/gthumb/gth-window.h
index 182bddc..5988457 100644
--- a/gthumb/gth-window.h
+++ b/gthumb/gth-window.h
@@ -103,7 +103,7 @@ void           gth_window_clear_saved_size   (GthWindow     *window,
                                              int            page);
 void           gth_window_set_title          (GthWindow     *window,
                                              const char    *title,
-                                             const char    *subtitle);
+                                             GList         *emblems);
 GtkAccelGroup *gth_window_get_accel_group      (GthWindow              *window);
 void           gth_window_add_accelerators     (GthWindow              *window,
                                                 const GthAccelerator   *accelerators,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]