1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 
3 /*
4  *  GThumb
5  *
6  *  Copyright (C) 2010 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 <glib/gi18n.h>
24 #include "facebook-album-properties-dialog.h"
25 
26 
27 #define GET_WIDGET(x) (_gtk_builder_get_widget (self->priv->builder, (x)))
28 
29 
30 struct _FacebookAlbumPropertiesDialogPrivate {
31 	GtkBuilder *builder;
32 };
33 
34 
G_DEFINE_TYPE_WITH_CODE(FacebookAlbumPropertiesDialog,facebook_album_properties_dialog,GTK_TYPE_DIALOG,G_ADD_PRIVATE (FacebookAlbumPropertiesDialog))35 G_DEFINE_TYPE_WITH_CODE (FacebookAlbumPropertiesDialog,
36 			 facebook_album_properties_dialog,
37 			 GTK_TYPE_DIALOG,
38 			 G_ADD_PRIVATE (FacebookAlbumPropertiesDialog))
39 
40 
41 static void
42 facebook_album_properties_dialog_finalize (GObject *object)
43 {
44 	FacebookAlbumPropertiesDialog *self;
45 
46 	self = FACEBOOK_ALBUM_PROPERTIES_DIALOG (object);
47 	_g_object_unref (self->priv->builder);
48 
49 	G_OBJECT_CLASS (facebook_album_properties_dialog_parent_class)->finalize (object);
50 }
51 
52 
53 static void
facebook_album_properties_dialog_class_init(FacebookAlbumPropertiesDialogClass * klass)54 facebook_album_properties_dialog_class_init (FacebookAlbumPropertiesDialogClass *klass)
55 {
56 	GObjectClass *object_class;
57 
58 	object_class = (GObjectClass*) klass;
59 	object_class->finalize = facebook_album_properties_dialog_finalize;
60 }
61 
62 
63 static void
facebook_album_properties_dialog_init(FacebookAlbumPropertiesDialog * self)64 facebook_album_properties_dialog_init (FacebookAlbumPropertiesDialog *self)
65 {
66 	GtkWidget *content;
67 
68 	self->priv = facebook_album_properties_dialog_get_instance_private(self);
69 	self->priv->builder = _gtk_builder_new_from_file ("facebook-album-properties.ui", "facebook");
70 
71 	content = _gtk_builder_get_widget (self->priv->builder, "album_properties");
72   	gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (self))), content, TRUE, TRUE, 0);
73 
74 	gtk_dialog_add_buttons (GTK_DIALOG (self),
75 				_GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL,
76 				_GTK_LABEL_SAVE, GTK_RESPONSE_OK,
77 				NULL);
78 	gtk_dialog_set_default_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
79 	_gtk_dialog_add_class_to_response (GTK_DIALOG (self), GTK_RESPONSE_OK, GTK_STYLE_CLASS_SUGGESTED_ACTION);
80 }
81 
82 
83 static void
facebook_album_properties_dialog_construct(FacebookAlbumPropertiesDialog * self,const char * name,const char * description,FacebookVisibility visibility)84 facebook_album_properties_dialog_construct (FacebookAlbumPropertiesDialog *self,
85 				            const char                    *name,
86 				            const char                    *description,
87 				            FacebookVisibility             visibility)
88 {
89 	int idx;
90 
91 	if (name != NULL)
92 		gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("name_entry")), name);
93 	if (description != NULL)
94 		gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("description_entry")), description);
95 
96 	switch (visibility) {
97 	case FACEBOOK_VISIBILITY_EVERYONE:
98 		idx = 0;
99 		break;
100 	case FACEBOOK_VISIBILITY_ALL_FRIENDS:
101 		idx = 1;
102 		break;
103 	case FACEBOOK_VISIBILITY_SELF:
104 		idx = 2;
105 		break;
106 	default:
107 		idx = 0;
108 		break;
109 	}
110 	gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("visibility_combobox")), idx);
111 }
112 
113 
114 GtkWidget *
facebook_album_properties_dialog_new(const char * name,const char * description,FacebookVisibility visibility)115 facebook_album_properties_dialog_new (const char         *name,
116 				      const char         *description,
117 				      FacebookVisibility  visibility)
118 {
119 	FacebookAlbumPropertiesDialog *self;
120 
121 	self = g_object_new (FACEBOOK_TYPE_ALBUM_PROPERTIES_DIALOG,
122 			     "modal", FALSE,
123 			     "resizable", FALSE,
124 			     "use-header-bar", _gtk_settings_get_dialogs_use_header (),
125 			     NULL);
126 	facebook_album_properties_dialog_construct (self, name, description, visibility);
127 
128 	return (GtkWidget *) self;
129 }
130 
131 
132 const char *
facebook_album_properties_dialog_get_name(FacebookAlbumPropertiesDialog * self)133 facebook_album_properties_dialog_get_name (FacebookAlbumPropertiesDialog *self)
134 {
135 	return gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("name_entry")));
136 }
137 
138 
139 const char *
facebook_album_properties_dialog_get_description(FacebookAlbumPropertiesDialog * self)140 facebook_album_properties_dialog_get_description (FacebookAlbumPropertiesDialog *self)
141 {
142 	return gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("description_entry")));
143 }
144 
145 
146 static const char *
get_privacy_from_visibility(FacebookVisibility visibility)147 get_privacy_from_visibility (FacebookVisibility visibility)
148 {
149 	char *value = NULL;
150 
151 	switch (visibility) {
152 	case FACEBOOK_VISIBILITY_EVERYONE:
153 		value = "{ 'value': 'EVERYONE' }";
154 		break;
155 
156 	case FACEBOOK_VISIBILITY_ALL_FRIENDS:
157 		value = "{ 'value': 'ALL_FRIENDS' }";
158 		break;
159 
160 	case FACEBOOK_VISIBILITY_SELF:
161 		value = "{ 'value': 'SELF' }";
162 		break;
163 
164 	default:
165 		break;
166 	}
167 
168 	return value;
169 }
170 
171 
172 const char *
facebook_album_properties_dialog_get_visibility(FacebookAlbumPropertiesDialog * self)173 facebook_album_properties_dialog_get_visibility (FacebookAlbumPropertiesDialog *self)
174 {
175 	GtkTreeIter        iter;
176 	FacebookVisibility value;
177 
178 	if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (GET_WIDGET ("visibility_combobox")), &iter))
179 		gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (GET_WIDGET ("visibility_combobox"))),
180 				    &iter,
181 				    1, &value,
182 				    -1);
183 	else
184 		value = FACEBOOK_VISIBILITY_SELF;
185 
186 	return get_privacy_from_visibility (value);
187 }
188