No issues found
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2012 Red Hat, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 */
20
21 #include "config.h"
22
23 #include <glib/gi18n.h>
24 #include <gtk/gtk.h>
25 #include <string.h>
26
27 #include "nautilus-special-location-bar.h"
28 #include "nautilus-enum-types.h"
29
30 #define NAUTILUS_SPECIAL_LOCATION_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_SPECIAL_LOCATION_BAR, NautilusSpecialLocationBarPrivate))
31
32 struct NautilusSpecialLocationBarPrivate
33 {
34 GtkWidget *label;
35 NautilusSpecialLocation special_location;
36 };
37
38 enum {
39 PROP_0,
40 PROP_SPECIAL_LOCATION,
41 };
42
43 G_DEFINE_TYPE (NautilusSpecialLocationBar, nautilus_special_location_bar, GTK_TYPE_INFO_BAR)
44
45 static char *
46 get_message_for_special_location (NautilusSpecialLocation location)
47 {
48 char *message;
49
50 switch (location) {
51 case NAUTILUS_SPECIAL_LOCATION_TEMPLATES:
52 message = g_strdup (_("Files in this folder will appear in the Create Document menu."));
53 break;
54 case NAUTILUS_SPECIAL_LOCATION_SCRIPTS:
55 message = g_strdup (_("Executable files in this folder will appear in the Scripts menu."));
56 break;
57 default:
58 g_assert_not_reached ();
59 }
60
61 return message;
62 }
63
64 static void
65 set_special_location (NautilusSpecialLocationBar *bar,
66 NautilusSpecialLocation location)
67 {
68 char *message;
69
70 message = get_message_for_special_location (location);
71
72 gtk_label_set_text (GTK_LABEL (bar->priv->label), message);
73 g_free (message);
74
75 gtk_widget_show (bar->priv->label);
76 }
77
78 static void
79 nautilus_special_location_bar_set_property (GObject *object,
80 guint prop_id,
81 const GValue *value,
82 GParamSpec *pspec)
83 {
84 NautilusSpecialLocationBar *bar;
85
86 bar = NAUTILUS_SPECIAL_LOCATION_BAR (object);
87
88 switch (prop_id) {
89 case PROP_SPECIAL_LOCATION:
90 set_special_location (bar, g_value_get_enum (value));
91 break;
92 default:
93 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
94 break;
95 }
96 }
97
98 static void
99 nautilus_special_location_bar_get_property (GObject *object,
100 guint prop_id,
101 GValue *value,
102 GParamSpec *pspec)
103 {
104 NautilusSpecialLocationBar *bar;
105
106 bar = NAUTILUS_SPECIAL_LOCATION_BAR (object);
107
108 switch (prop_id) {
109 case PROP_SPECIAL_LOCATION:
110 g_value_set_enum (value, bar->priv->special_location);
111 break;
112 default:
113 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
114 break;
115 }
116 }
117
118 static void
119 nautilus_special_location_bar_class_init (NautilusSpecialLocationBarClass *klass)
120 {
121 GObjectClass *object_class;
122
123 object_class = G_OBJECT_CLASS (klass);
124 object_class->get_property = nautilus_special_location_bar_get_property;
125 object_class->set_property = nautilus_special_location_bar_set_property;
126
127 g_type_class_add_private (klass, sizeof (NautilusSpecialLocationBarPrivate));
128
129 g_object_class_install_property (object_class,
130 PROP_SPECIAL_LOCATION,
131 g_param_spec_enum ("special-location",
132 "special-location",
133 "special-location",
134 NAUTILUS_TYPE_SPECIAL_LOCATION,
135 NAUTILUS_SPECIAL_LOCATION_TEMPLATES,
136 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
137 }
138
139 static void
140 nautilus_special_location_bar_init (NautilusSpecialLocationBar *bar)
141 {
142 GtkWidget *location_area;
143 GtkWidget *action_area;
144 PangoAttrList *attrs;
145
146 bar->priv = NAUTILUS_SPECIAL_LOCATION_BAR_GET_PRIVATE (bar);
147 location_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
148 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
149
150 gtk_orientable_set_orientation (GTK_ORIENTABLE (action_area), GTK_ORIENTATION_HORIZONTAL);
151
152 attrs = pango_attr_list_new ();
153 pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
154 bar->priv->label = gtk_label_new (NULL);
155 gtk_label_set_attributes (GTK_LABEL (bar->priv->label), attrs);
156 pango_attr_list_unref (attrs);
157
158 gtk_label_set_ellipsize (GTK_LABEL (bar->priv->label), PANGO_ELLIPSIZE_END);
159 gtk_container_add (GTK_CONTAINER (location_area), bar->priv->label);
160 }
161
162 GtkWidget *
163 nautilus_special_location_bar_new (NautilusSpecialLocation location)
164 {
165 return g_object_new (NAUTILUS_TYPE_SPECIAL_LOCATION_BAR,
166 "message-type", GTK_MESSAGE_QUESTION,
167 "special-location", location,
168 NULL);
169 }