~noskcaj/ubuntu/trusty/gthumb/3.2.5

« back to all changes in this revision

Viewing changes to extensions/flicker_utils/flickr-account-chooser-dialog.c

  • Committer: Package Import Robot
  • Author(s): David Paleino
  • Date: 2011-12-22 22:40:29 UTC
  • mfrom: (5.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20111222224029-l58g65u1nfa6ojtg
Tags: 3:2.14.1-1
* New upstream version (Closes: #652692)
* Patches refreshed
* Bump build-dependencies requirements
* Fix FTBFS, added missing #include
* debian/watch fixed to point to new location (.xz tarballs)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "flickr-account-chooser-dialog.h"
 
25
 
 
26
#define GET_WIDGET(x) (_gtk_builder_get_widget (self->priv->builder, (x)))
 
27
 
 
28
 
 
29
enum {
 
30
        ACCOUNT_DATA_COLUMN,
 
31
        ACCOUNT_NAME_COLUMN,
 
32
        ACCOUNT_SEPARATOR_COLUMN,
 
33
        ACCOUNT_ICON_COLUMN
 
34
};
 
35
 
 
36
 
 
37
static gpointer parent_class = NULL;
 
38
 
 
39
 
 
40
struct _FlickrAccountChooserDialogPrivate {
 
41
        GtkBuilder *builder;
 
42
};
 
43
 
 
44
 
 
45
static void
 
46
flickr_account_chooser_dialog_finalize (GObject *object)
 
47
{
 
48
        FlickrAccountChooserDialog *self;
 
49
 
 
50
        self = FLICKR_ACCOUNT_CHOOSER_DIALOG (object);
 
51
 
 
52
        _g_object_unref (self->priv->builder);
 
53
 
 
54
        G_OBJECT_CLASS (parent_class)->finalize (object);
 
55
}
 
56
 
 
57
 
 
58
static void
 
59
flickr_account_chooser_dialog_class_init (FlickrAccountChooserDialogClass *klass)
 
60
{
 
61
        GObjectClass *object_class;
 
62
 
 
63
        parent_class = g_type_class_peek_parent (klass);
 
64
        g_type_class_add_private (klass, sizeof (FlickrAccountChooserDialogPrivate));
 
65
 
 
66
        object_class = (GObjectClass*) klass;
 
67
        object_class->finalize = flickr_account_chooser_dialog_finalize;
 
68
}
 
69
 
 
70
 
 
71
static void
 
72
account_combobox_changed_cb (GtkComboBox *combobox,
 
73
                             gpointer     user_data)
 
74
{
 
75
        FlickrAccountChooserDialog *self = user_data;
 
76
        GtkTreeIter                 iter;
 
77
        FlickrAccount              *account;
 
78
 
 
79
        if (! gtk_combo_box_get_active_iter (combobox, &iter))
 
80
                return;
 
81
 
 
82
        gtk_tree_model_get (GTK_TREE_MODEL (GET_WIDGET ("account_liststore")), &iter,
 
83
                            ACCOUNT_DATA_COLUMN, &account,
 
84
                            -1);
 
85
 
 
86
        if (account == NULL)
 
87
                gtk_dialog_response (GTK_DIALOG (self), FLICKR_ACCOUNT_CHOOSER_RESPONSE_NEW);
 
88
 
 
89
        _g_object_unref (account);
 
90
}
 
91
 
 
92
 
 
93
static gboolean
 
94
row_separator_func (GtkTreeModel *model,
 
95
                    GtkTreeIter  *iter,
 
96
                    gpointer      user_data)
 
97
{
 
98
        FlickrAccountChooserDialog *self = user_data;
 
99
        gboolean                    is_separator;
 
100
 
 
101
        gtk_tree_model_get (GTK_TREE_MODEL (GET_WIDGET ("account_liststore")),
 
102
                            iter,
 
103
                            ACCOUNT_SEPARATOR_COLUMN, &is_separator,
 
104
                            -1);
 
105
 
 
106
        return is_separator;
 
107
}
 
108
 
 
109
 
 
110
static void
 
111
flickr_account_chooser_dialog_init (FlickrAccountChooserDialog *self)
 
112
{
 
113
        GtkWidget *content;
 
114
 
 
115
        self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, FLICKR_TYPE_ACCOUNT_CHOOSER_DIALOG, FlickrAccountChooserDialogPrivate);
 
116
        self->priv->builder = _gtk_builder_new_from_file ("flicker-account-chooser.ui", "flicker_utils");
 
117
 
 
118
        gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
 
119
        gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (self))), 5);
 
120
        gtk_container_set_border_width (GTK_CONTAINER (self), 5);
 
121
 
 
122
        content = _gtk_builder_get_widget (self->priv->builder, "account_chooser");
 
123
        gtk_container_set_border_width (GTK_CONTAINER (content), 5);
 
124
        gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (self))), content, TRUE, TRUE, 0);
 
125
 
 
126
        {
 
127
                GtkCellLayout   *cell_layout;
 
128
                GtkCellRenderer *renderer;
 
129
 
 
130
                cell_layout = GTK_CELL_LAYOUT (GET_WIDGET ("account_combobox"));
 
131
 
 
132
                renderer = gtk_cell_renderer_pixbuf_new ();
 
133
                gtk_cell_layout_pack_start (cell_layout, renderer, FALSE);
 
134
                gtk_cell_layout_set_attributes (cell_layout, renderer,
 
135
                                                "icon-name", ACCOUNT_ICON_COLUMN,
 
136
                                                NULL);
 
137
 
 
138
                renderer = gtk_cell_renderer_text_new ();
 
139
                gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
 
140
                gtk_cell_layout_set_attributes (cell_layout, renderer,
 
141
                                                "text", ACCOUNT_NAME_COLUMN,
 
142
                                                NULL);
 
143
        }
 
144
        gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (GET_WIDGET ("account_combobox")),
 
145
                                              row_separator_func,
 
146
                                              self,
 
147
                                              NULL);
 
148
        g_signal_connect (GET_WIDGET ("account_combobox"),
 
149
                          "changed",
 
150
                          G_CALLBACK (account_combobox_changed_cb),
 
151
                          self);
 
152
 
 
153
        gtk_dialog_add_button (GTK_DIALOG (self),
 
154
                               GTK_STOCK_NEW,
 
155
                               FLICKR_ACCOUNT_CHOOSER_RESPONSE_NEW);
 
156
        gtk_dialog_add_button (GTK_DIALOG (self),
 
157
                               GTK_STOCK_CANCEL,
 
158
                               GTK_RESPONSE_CANCEL);
 
159
        gtk_dialog_add_button (GTK_DIALOG (self),
 
160
                               GTK_STOCK_OK,
 
161
                               GTK_RESPONSE_OK);
 
162
        gtk_dialog_set_default_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
 
163
}
 
164
 
 
165
 
 
166
GType
 
167
flickr_account_chooser_dialog_get_type (void)
 
168
{
 
169
        static GType type = 0;
 
170
 
 
171
        if (type == 0) {
 
172
                static const GTypeInfo g_define_type_info = {
 
173
                        sizeof (FlickrAccountChooserDialogClass),
 
174
                        (GBaseInitFunc) NULL,
 
175
                        (GBaseFinalizeFunc) NULL,
 
176
                        (GClassInitFunc) flickr_account_chooser_dialog_class_init,
 
177
                        (GClassFinalizeFunc) NULL,
 
178
                        NULL,
 
179
                        sizeof (FlickrAccountChooserDialog),
 
180
                        0,
 
181
                        (GInstanceInitFunc) flickr_account_chooser_dialog_init,
 
182
                        NULL
 
183
                };
 
184
                type = g_type_register_static (GTK_TYPE_DIALOG,
 
185
                                               "FlickrAccountChooserDialog",
 
186
                                               &g_define_type_info,
 
187
                                               0);
 
188
        }
 
189
 
 
190
        return type;
 
191
}
 
192
 
 
193
 
 
194
static void
 
195
flickr_account_chooser_dialog_construct (FlickrAccountChooserDialog *self,
 
196
                                         GList                      *accounts,
 
197
                                         FlickrAccount              *default_account)
 
198
{
 
199
        GtkTreeIter  iter;
 
200
        GList       *scan;
 
201
        int          active = 0;
 
202
        int          idx;
 
203
 
 
204
        gtk_list_store_clear (GTK_LIST_STORE (GET_WIDGET ("account_liststore")));
 
205
 
 
206
        for (scan = accounts, idx = 0; scan; scan = scan->next, idx++) {
 
207
                FlickrAccount *account = scan->data;
 
208
 
 
209
                if ((default_account != NULL) && (g_strcmp0 (account->username, default_account->username) == 0))
 
210
                        active = idx;
 
211
 
 
212
                gtk_list_store_append (GTK_LIST_STORE (GET_WIDGET ("account_liststore")), &iter);
 
213
                gtk_list_store_set (GTK_LIST_STORE (GET_WIDGET ("account_liststore")), &iter,
 
214
                                    ACCOUNT_DATA_COLUMN, account,
 
215
                                    ACCOUNT_NAME_COLUMN, account->username,
 
216
                                    ACCOUNT_SEPARATOR_COLUMN, FALSE,
 
217
                                    ACCOUNT_ICON_COLUMN, "dialog-password",
 
218
                                    -1);
 
219
        }
 
220
 
 
221
        gtk_list_store_append (GTK_LIST_STORE (GET_WIDGET ("account_liststore")), &iter);
 
222
        gtk_list_store_set (GTK_LIST_STORE (GET_WIDGET ("account_liststore")), &iter,
 
223
                            ACCOUNT_SEPARATOR_COLUMN, TRUE,
 
224
                            -1);
 
225
 
 
226
        gtk_list_store_append (GTK_LIST_STORE (GET_WIDGET ("account_liststore")), &iter);
 
227
        gtk_list_store_set (GTK_LIST_STORE (GET_WIDGET ("account_liststore")), &iter,
 
228
                            ACCOUNT_DATA_COLUMN, NULL,
 
229
                            ACCOUNT_NAME_COLUMN, _("New authentication..."),
 
230
                            ACCOUNT_SEPARATOR_COLUMN, FALSE,
 
231
                            ACCOUNT_ICON_COLUMN, GTK_STOCK_NEW,
 
232
                            -1);
 
233
 
 
234
        gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("account_combobox")), active);
 
235
}
 
236
 
 
237
 
 
238
GtkWidget *
 
239
flickr_account_chooser_dialog_new (GList         *accounts,
 
240
                                   FlickrAccount *default_account)
 
241
{
 
242
        FlickrAccountChooserDialog *self;
 
243
 
 
244
        self = g_object_new (FLICKR_TYPE_ACCOUNT_CHOOSER_DIALOG, NULL);
 
245
        flickr_account_chooser_dialog_construct (self, accounts, default_account);
 
246
 
 
247
        return (GtkWidget *) self;
 
248
}
 
249
 
 
250
 
 
251
FlickrAccount *
 
252
flickr_account_chooser_dialog_get_active (FlickrAccountChooserDialog *self)
 
253
{
 
254
        GtkTreeIter    iter;
 
255
        FlickrAccount *account;
 
256
 
 
257
        if (! gtk_combo_box_get_active_iter (GTK_COMBO_BOX (GET_WIDGET ("account_combobox")), &iter))
 
258
                return NULL;
 
259
 
 
260
        gtk_tree_model_get (GTK_TREE_MODEL (GET_WIDGET ("account_liststore")), &iter,
 
261
                            ACCOUNT_DATA_COLUMN, &account,
 
262
                            -1);
 
263
 
 
264
        return account;
 
265
}