~guadalinex-members/gnome-system-tools/gnome-system-tools-2.22.2

« back to all changes in this revision

Viewing changes to src/shares/table.c

  • Committer: Juanje Ojeda Croissier
  • Date: 2009-04-06 15:47:26 UTC
  • Revision ID: jojeda@emergya.es-20090406154726-h29t5g1n1wwc4x2h
Tags: gnome-system-tools-2.22.2-0ubuntu3
Imported the g-s-t code directly from the source package gnome-system-tools-2.22.2-0ubuntu3 (jaunty)

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
/* table.c: this file is part of shares-admin, a gnome-system-tool frontend 
 
3
 * for shared folders administration.
 
4
 * 
 
5
 * Copyright (C) 2004 Carlos Garnacho
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as
 
9
 * published by the Free Software Foundation; either version 2 of the
 
10
 * License, or (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 
20
 *
 
21
 * Authors: Carlos Garnacho Parro <carlosg@gnome.org>.
 
22
 */
 
23
 
 
24
#include <glib/gi18n.h>
 
25
#include <gtk/gtk.h>
 
26
#include "gst-tool.h"
 
27
#include "gst.h"
 
28
#include "table.h"
 
29
#include "callbacks.h"
 
30
 
 
31
extern GstTool *tool;
 
32
 
 
33
static GtkTargetEntry drop_types[] = {
 
34
        { "text/uri-list", 0, SHARES_DND_URI_LIST },
 
35
};
 
36
 
 
37
GtkActionEntry popup_menu_items [] = {
 
38
        { "Add",        GTK_STOCK_ADD,        N_("_Add"),        NULL, NULL, G_CALLBACK (on_add_share_clicked) },
 
39
        { "Properties", GTK_STOCK_PROPERTIES, N_("_Properties"), NULL, NULL, G_CALLBACK (on_edit_share_clicked) },
 
40
        { "Delete",     GTK_STOCK_DELETE,     N_("_Delete"),     NULL, NULL, G_CALLBACK (on_delete_share_clicked) },
 
41
};
 
42
 
 
43
const gchar *ui_description =
 
44
        "<ui>"
 
45
        "  <popup name='MainMenu'>"
 
46
        "    <menuitem action='Add'/>"
 
47
        "    <separator/>"
 
48
        "    <menuitem action='Properties'/>"
 
49
        "    <menuitem action='Delete'/>"
 
50
        "  </popup>"
 
51
        "</ui>";
 
52
 
 
53
static GtkWidget*
 
54
popup_menu_create (GtkTreeView *treeview)
 
55
{
 
56
        GtkUIManager   *ui_manager;
 
57
        GtkActionGroup *action_group;
 
58
        GtkWidget      *popup;
 
59
 
 
60
        g_return_val_if_fail (treeview != NULL, NULL);
 
61
 
 
62
        action_group = gtk_action_group_new ("MenuActions");
 
63
        gtk_action_group_set_translation_domain (action_group, NULL);
 
64
        gtk_action_group_add_actions (action_group,
 
65
                                      popup_menu_items,
 
66
                                      G_N_ELEMENTS (popup_menu_items), treeview);
 
67
 
 
68
        ui_manager = gtk_ui_manager_new ();
 
69
        gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
 
70
 
 
71
        if (!gtk_ui_manager_add_ui_from_string (ui_manager, ui_description, -1, NULL))
 
72
                return NULL;
 
73
 
 
74
        popup = gtk_ui_manager_get_widget (ui_manager, "/MainMenu");
 
75
 
 
76
        return popup;
 
77
}
 
78
 
 
79
static GtkTreeModel*
 
80
create_table_model (void)
 
81
{
 
82
        GtkListStore *store;
 
83
 
 
84
        store = gtk_list_store_new (COL_LAST,
 
85
                                    GDK_TYPE_PIXBUF,
 
86
                                    G_TYPE_STRING,
 
87
                                    G_TYPE_OBJECT,
 
88
                                    OOBS_TYPE_LIST_ITER);
 
89
 
 
90
        return GTK_TREE_MODEL (store);
 
91
}
 
92
 
 
93
static void
 
94
add_table_columns (GtkTreeView *table)
 
95
{
 
96
        GtkCellRenderer   *renderer;
 
97
 
 
98
        renderer = gtk_cell_renderer_pixbuf_new ();
 
99
        gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (table), 1,
 
100
                                                     "Share",
 
101
                                                     renderer,
 
102
                                                     "pixbuf", 0,
 
103
                                                     NULL);
 
104
        
 
105
        renderer = gtk_cell_renderer_text_new ();
 
106
        gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (table), 1,
 
107
                                                     "Path",
 
108
                                                     renderer,
 
109
                                                     "text", 1,
 
110
                                                     NULL);
 
111
}
 
112
 
 
113
void
 
114
table_create (GstTool *tool)
 
115
{
 
116
        GtkWidget        *table = gst_dialog_get_widget (tool->main_dialog, "shares_table");
 
117
        GtkWidget        *popup;
 
118
        GtkTreeSelection *selection;
 
119
        GtkTreeModel     *model;
 
120
 
 
121
        model = create_table_model ();
 
122
        gtk_tree_view_set_model (GTK_TREE_VIEW (table), model);
 
123
        g_object_unref (G_OBJECT (model));
 
124
 
 
125
        add_table_columns (GTK_TREE_VIEW (table));
 
126
 
 
127
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (table));
 
128
        g_signal_connect (G_OBJECT (selection), "changed",
 
129
                          G_CALLBACK (on_shares_table_selection_changed), NULL);
 
130
 
 
131
        popup = popup_menu_create (GTK_TREE_VIEW (table));
 
132
        g_signal_connect (G_OBJECT (table), "button-press-event",
 
133
                          G_CALLBACK (on_shares_table_button_press), (gpointer) popup);
 
134
        g_signal_connect (G_OBJECT (table), "popup_menu",
 
135
                          G_CALLBACK (on_shares_table_popup_menu), (gpointer) popup);
 
136
 
 
137
        /* Drag and Drop stuff */
 
138
        gtk_drag_dest_unset (table);
 
139
        gtk_drag_dest_set (table, GTK_DEST_DEFAULT_ALL, drop_types,
 
140
                           sizeof (drop_types) / sizeof (drop_types[0]),
 
141
                           GDK_ACTION_COPY);
 
142
        g_signal_connect (G_OBJECT (table), "drag_data_received",
 
143
                          G_CALLBACK (on_shares_dragged_folder), NULL);
 
144
}
 
145
 
 
146
void
 
147
table_clear (void)
 
148
{
 
149
        GtkWidget *table = gst_dialog_get_widget (tool->main_dialog, "shares_table");
 
150
        GtkTreeModel *model;
 
151
 
 
152
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (table));
 
153
        gtk_list_store_clear (GTK_LIST_STORE (model));
 
154
}
 
155
 
 
156
static GdkPixbuf*
 
157
get_share_icon (OobsShare *share)
 
158
{
 
159
        GdkPixbuf *pixbuf = NULL;
 
160
 
 
161
        if (OOBS_IS_SHARE_SMB (share)) {
 
162
                pixbuf = gtk_icon_theme_load_icon (gst_tool_get_icon_theme (tool),
 
163
                                                   "gnome-fs-smb",
 
164
                                                   48, 0, NULL);
 
165
        } else if (OOBS_IS_SHARE_NFS (share)) {
 
166
                pixbuf = gtk_icon_theme_load_icon (gst_tool_get_icon_theme (tool),
 
167
                                                   "gnome-fs-nfs",
 
168
                                                   48, 0, NULL);
 
169
        }
 
170
 
 
171
        return pixbuf;
 
172
}
 
173
 
 
174
void
 
175
table_add_share (OobsShare *share, OobsListIter *list_iter)
 
176
{
 
177
        GtkWidget    *table = gst_dialog_get_widget (tool->main_dialog, "shares_table");
 
178
        GtkTreeModel *model;
 
179
        GtkTreeIter   iter;
 
180
 
 
181
        g_return_if_fail (share != NULL);
 
182
        g_return_if_fail (OOBS_IS_SHARE (share));
 
183
        
 
184
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (table));
 
185
        gtk_list_store_append (GTK_LIST_STORE (model), &iter);
 
186
 
 
187
        gtk_list_store_set (GTK_LIST_STORE (model),
 
188
                            &iter,
 
189
                            COL_PIXBUF, get_share_icon (share),
 
190
                            COL_PATH, oobs_share_get_path (share),
 
191
                            COL_SHARE, share,
 
192
                            COL_ITER, list_iter,
 
193
                            -1);
 
194
}
 
195
 
 
196
void
 
197
table_modify_share_at_iter (GtkTreeIter *iter, OobsShare *share, OobsListIter *list_iter)
 
198
{
 
199
        GtkWidget    *table = gst_dialog_get_widget (tool->main_dialog, "shares_table");
 
200
        GtkTreeModel *model;
 
201
        GdkPixbuf    *pixbuf = NULL;
 
202
 
 
203
        g_return_if_fail (share != NULL);
 
204
        g_return_if_fail (OOBS_IS_SHARE (share));
 
205
 
 
206
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (table));
 
207
        gtk_list_store_set (GTK_LIST_STORE (model),
 
208
                            iter,
 
209
                            COL_PIXBUF, get_share_icon (share),
 
210
                            COL_PATH, oobs_share_get_path (share),
 
211
                            COL_SHARE, share,
 
212
                            COL_ITER, list_iter,
 
213
                            -1);
 
214
}
 
215
 
 
216
OobsShare*
 
217
table_get_share_at_iter (GtkTreeIter *iter, OobsListIter **list_iter)
 
218
{
 
219
        GtkWidget    *table = gst_dialog_get_widget (tool->main_dialog, "shares_table");
 
220
        GtkTreeModel *model;
 
221
        OobsShare     *share;
 
222
 
 
223
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (table));
 
224
 
 
225
        gtk_tree_model_get (model, iter,
 
226
                            COL_SHARE, &share,
 
227
                            COL_ITER, list_iter,
 
228
                            -1);
 
229
        return share;
 
230
}
 
231
 
 
232
void
 
233
table_delete_share_at_iter (GtkTreeIter *iter)
 
234
{
 
235
        GtkWidget    *table = gst_dialog_get_widget (tool->main_dialog, "shares_table");
 
236
        GtkTreeModel *model;
 
237
 
 
238
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (table));
 
239
        gtk_list_store_remove (GTK_LIST_STORE (model), iter);
 
240
}
 
241
 
 
242
gboolean
 
243
table_get_iter_with_path (const gchar *path, GtkTreeIter *iter)
 
244
{
 
245
        GtkWidget    *table = gst_dialog_get_widget (tool->main_dialog, "shares_table");
 
246
        GtkTreeModel *model;
 
247
        gboolean      valid, found;
 
248
        gchar        *iter_path;
 
249
 
 
250
        if (!path)
 
251
                return FALSE;
 
252
 
 
253
        found = FALSE;
 
254
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (table));
 
255
        valid = gtk_tree_model_get_iter_first (model, iter);
 
256
 
 
257
        while (valid) {
 
258
                gtk_tree_model_get (model, iter,
 
259
                                    COL_PATH, &iter_path,
 
260
                                    -1);
 
261
 
 
262
                if (strcmp (iter_path, path) == 0) {
 
263
                        found = TRUE;
 
264
                        valid = FALSE;
 
265
                } else
 
266
                        valid = gtk_tree_model_iter_next (model, iter);
 
267
 
 
268
                g_free (iter_path);
 
269
        }
 
270
 
 
271
        return found;
 
272
}