1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
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, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: William Jon McCann <mccann@jhu.edu>
19 *
20 */
21
22 #include "config.h"
23
24 #include <glib/gi18n-lib.h>
25 #include <gtk/gtk.h>
26
27 #include "nautilus-share-bar.h"
28
29 #define NAUTILUS_SHARE_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_SHARE_BAR, NautilusShareBarPrivate))
30
31 struct NautilusShareBarPrivate
32 {
33 GtkWidget *label;
34 };
35
36 enum {
37 PROP_0,
38 PROP_LABEL
39 };
40
G_DEFINE_TYPE(NautilusShareBar,nautilus_share_bar,GTK_TYPE_INFO_BAR)41 G_DEFINE_TYPE (NautilusShareBar, nautilus_share_bar, GTK_TYPE_INFO_BAR)
42
43 static void
44 nautilus_share_bar_set_property (GObject *object,
45 guint prop_id,
46 const GValue *value,
47 GParamSpec *pspec)
48 {
49 NautilusShareBar *self;
50
51 self = NAUTILUS_SHARE_BAR (object);
52
53 switch (prop_id) {
54 case PROP_LABEL: {
55 gtk_label_set_text (GTK_LABEL (self->priv->label), g_value_get_string (value));
56 break;
57 }
58 default:
59 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
60 break;
61 }
62 }
63
64 static void
nautilus_share_bar_class_init(NautilusShareBarClass * klass)65 nautilus_share_bar_class_init (NautilusShareBarClass *klass)
66 {
67 GObjectClass *object_class = G_OBJECT_CLASS (klass);
68
69 object_class->set_property = nautilus_share_bar_set_property;
70
71 g_type_class_add_private (klass, sizeof (NautilusShareBarPrivate));
72
73 g_object_class_install_property (G_OBJECT_CLASS(klass), PROP_LABEL,
74 g_param_spec_string ("label", "label",
75 "The widget's main label",
76 NULL,
77 G_PARAM_WRITABLE));
78 }
79
80 static void
nautilus_share_bar_init(NautilusShareBar * bar)81 nautilus_share_bar_init (NautilusShareBar *bar)
82 {
83 GtkWidget *content_area;
84 GtkWidget *action_area;
85 GtkWidget *label;
86 GtkWidget *vbox;
87 GtkWidget *button;
88 PangoAttrList *attrs;
89
90 bar->priv = NAUTILUS_SHARE_BAR_GET_PRIVATE (bar);
91
92 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
93 action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
94 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_CENTER);
95
96 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
97 gtk_container_add (GTK_CONTAINER (content_area), vbox);
98
99 attrs = pango_attr_list_new ();
100 pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
101 /* translators: This is the label for the "Sharing" panel in the Settings */
102 label = gtk_label_new (_("Sharing"));
103 gtk_label_set_attributes (GTK_LABEL (label), attrs);
104 pango_attr_list_unref (attrs);
105
106 gtk_widget_set_halign (label, GTK_ALIGN_START);
107 gtk_widget_show (label);
108 gtk_container_add (GTK_CONTAINER (vbox), label);
109
110 bar->priv->label = gtk_label_new (NULL);
111 gtk_widget_set_halign (bar->priv->label, GTK_ALIGN_START);
112 gtk_widget_show (bar->priv->label);
113 gtk_container_add (GTK_CONTAINER (vbox), bar->priv->label);
114
115 button = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
116 _("Preferences"),
117 NAUTILUS_SHARE_BAR_RESPONSE_PREFERENCES);
118
119 /* translators: This is the tooltip for the "Sharing" panel in the Settings */
120 gtk_widget_set_tooltip_text (button, _("Sharing Settings"));
121
122 gtk_widget_show_all (vbox);
123 }
124
125 GtkWidget *
nautilus_share_bar_new(const char * label)126 nautilus_share_bar_new (const char *label)
127 {
128 return g_object_new (NAUTILUS_TYPE_SHARE_BAR,
129 "message-type", GTK_MESSAGE_QUESTION,
130 "label", label,
131 NULL);
132 }
133