1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /*
4 * GThumb
5 *
6 * Copyright (C) 2014 Free Software Foundation, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include <config.h>
23 #include <string.h>
24 #include <glib/gi18n.h>
25 #include <glib.h>
26 #include <gtk/gtk.h>
27 #include "gth-window-title.h"
28 #include "gtk-utils.h"
29
30
31 struct _GthWindowTitlePrivate {
32 GtkWidget *title;
33 GtkWidget *emblems;
34 };
35
36
G_DEFINE_TYPE_WITH_CODE(GthWindowTitle,gth_window_title,GTK_TYPE_BOX,G_ADD_PRIVATE (GthWindowTitle))37 G_DEFINE_TYPE_WITH_CODE (GthWindowTitle,
38 gth_window_title,
39 GTK_TYPE_BOX,
40 G_ADD_PRIVATE (GthWindowTitle))
41
42
43 static void
44 gth_window_title_class_init (GthWindowTitleClass *klass)
45 {
46 /* void */
47 }
48
49
50 static void
gth_window_title_init(GthWindowTitle * self)51 gth_window_title_init (GthWindowTitle *self)
52 {
53 self->priv = gth_window_title_get_instance_private (self);
54
55 gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL);
56 gtk_box_set_spacing (GTK_BOX (self), 10);
57
58 self->priv->title = gtk_label_new ("");
59 gtk_label_set_line_wrap (GTK_LABEL (self->priv->title), FALSE);
60 gtk_label_set_single_line_mode (GTK_LABEL (self->priv->title), TRUE);
61 gtk_label_set_ellipsize (GTK_LABEL (self->priv->title), PANGO_ELLIPSIZE_END);
62 gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->title), "title");
63 gtk_box_pack_start (GTK_BOX (self), self->priv->title, FALSE, FALSE, 0);
64
65 self->priv->emblems = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
66 gtk_box_pack_start (GTK_BOX (self), self->priv->emblems, FALSE, FALSE, 0);
67 }
68
69
70 GtkWidget *
gth_window_title_new(void)71 gth_window_title_new (void)
72 {
73 return (GtkWidget *) g_object_new (GTH_TYPE_WINDOW_TITLE, NULL);
74 }
75
76
77 void
gth_window_title_set_title(GthWindowTitle * self,const char * title)78 gth_window_title_set_title (GthWindowTitle *self,
79 const char *title)
80 {
81 gtk_label_set_text (GTK_LABEL (self->priv->title), (title != NULL) ? title : "");
82 gtk_widget_set_visible (self->priv->title, title != NULL);
83 }
84
85
86 void
gth_window_title_set_emblems(GthWindowTitle * self,GList * emblems)87 gth_window_title_set_emblems (GthWindowTitle *self,
88 GList *emblems)
89 {
90 GList *scan;
91
92 _gtk_container_remove_children (GTK_CONTAINER (self->priv->emblems), NULL, NULL);
93 for (scan = emblems; scan; scan = scan->next) {
94 char *emblem = scan->data;
95 GtkWidget *icon;
96
97 icon = gtk_image_new_from_icon_name (emblem, GTK_ICON_SIZE_MENU);
98 gtk_widget_show (icon);
99 gtk_box_pack_start (GTK_BOX (self->priv->emblems), icon, FALSE, FALSE, 0);
100 }
101
102 gtk_widget_set_visible (self->priv->emblems, emblems != NULL);
103 }
104