1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
6
* Copyright (C) 2010 Free Software Foundation, Inc.
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.
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.
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/>.
23
#include <glib/gi18n.h>
24
#include "flickr-account-chooser-dialog.h"
26
#define GET_WIDGET(x) (_gtk_builder_get_widget (self->priv->builder, (x)))
32
ACCOUNT_SEPARATOR_COLUMN,
37
static gpointer parent_class = NULL;
40
struct _FlickrAccountChooserDialogPrivate {
46
flickr_account_chooser_dialog_finalize (GObject *object)
48
FlickrAccountChooserDialog *self;
50
self = FLICKR_ACCOUNT_CHOOSER_DIALOG (object);
52
_g_object_unref (self->priv->builder);
54
G_OBJECT_CLASS (parent_class)->finalize (object);
59
flickr_account_chooser_dialog_class_init (FlickrAccountChooserDialogClass *klass)
61
GObjectClass *object_class;
63
parent_class = g_type_class_peek_parent (klass);
64
g_type_class_add_private (klass, sizeof (FlickrAccountChooserDialogPrivate));
66
object_class = (GObjectClass*) klass;
67
object_class->finalize = flickr_account_chooser_dialog_finalize;
72
account_combobox_changed_cb (GtkComboBox *combobox,
75
FlickrAccountChooserDialog *self = user_data;
77
FlickrAccount *account;
79
if (! gtk_combo_box_get_active_iter (combobox, &iter))
82
gtk_tree_model_get (GTK_TREE_MODEL (GET_WIDGET ("account_liststore")), &iter,
83
ACCOUNT_DATA_COLUMN, &account,
87
gtk_dialog_response (GTK_DIALOG (self), FLICKR_ACCOUNT_CHOOSER_RESPONSE_NEW);
89
_g_object_unref (account);
94
row_separator_func (GtkTreeModel *model,
98
FlickrAccountChooserDialog *self = user_data;
99
gboolean is_separator;
101
gtk_tree_model_get (GTK_TREE_MODEL (GET_WIDGET ("account_liststore")),
103
ACCOUNT_SEPARATOR_COLUMN, &is_separator,
111
flickr_account_chooser_dialog_init (FlickrAccountChooserDialog *self)
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");
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);
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);
127
GtkCellLayout *cell_layout;
128
GtkCellRenderer *renderer;
130
cell_layout = GTK_CELL_LAYOUT (GET_WIDGET ("account_combobox"));
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,
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,
144
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (GET_WIDGET ("account_combobox")),
148
g_signal_connect (GET_WIDGET ("account_combobox"),
150
G_CALLBACK (account_combobox_changed_cb),
153
gtk_dialog_add_button (GTK_DIALOG (self),
155
FLICKR_ACCOUNT_CHOOSER_RESPONSE_NEW);
156
gtk_dialog_add_button (GTK_DIALOG (self),
158
GTK_RESPONSE_CANCEL);
159
gtk_dialog_add_button (GTK_DIALOG (self),
162
gtk_dialog_set_default_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
167
flickr_account_chooser_dialog_get_type (void)
169
static GType 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,
179
sizeof (FlickrAccountChooserDialog),
181
(GInstanceInitFunc) flickr_account_chooser_dialog_init,
184
type = g_type_register_static (GTK_TYPE_DIALOG,
185
"FlickrAccountChooserDialog",
195
flickr_account_chooser_dialog_construct (FlickrAccountChooserDialog *self,
197
FlickrAccount *default_account)
204
gtk_list_store_clear (GTK_LIST_STORE (GET_WIDGET ("account_liststore")));
206
for (scan = accounts, idx = 0; scan; scan = scan->next, idx++) {
207
FlickrAccount *account = scan->data;
209
if ((default_account != NULL) && (g_strcmp0 (account->username, default_account->username) == 0))
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",
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,
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,
234
gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("account_combobox")), active);
239
flickr_account_chooser_dialog_new (GList *accounts,
240
FlickrAccount *default_account)
242
FlickrAccountChooserDialog *self;
244
self = g_object_new (FLICKR_TYPE_ACCOUNT_CHOOSER_DIALOG, NULL);
245
flickr_account_chooser_dialog_construct (self, accounts, default_account);
247
return (GtkWidget *) self;
252
flickr_account_chooser_dialog_get_active (FlickrAccountChooserDialog *self)
255
FlickrAccount *account;
257
if (! gtk_combo_box_get_active_iter (GTK_COMBO_BOX (GET_WIDGET ("account_combobox")), &iter))
260
gtk_tree_model_get (GTK_TREE_MODEL (GET_WIDGET ("account_liststore")), &iter,
261
ACCOUNT_DATA_COLUMN, &account,