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.
5
* Copyright (C) 2004 Carlos Garnacho
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.
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.
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.
21
* Authors: Carlos Garnacho Parro <carlosg@gnome.org>.
24
#include <glib/gi18n.h>
29
#include "callbacks.h"
33
static GtkTargetEntry drop_types[] = {
34
{ "text/uri-list", 0, SHARES_DND_URI_LIST },
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) },
43
const gchar *ui_description =
45
" <popup name='MainMenu'>"
46
" <menuitem action='Add'/>"
48
" <menuitem action='Properties'/>"
49
" <menuitem action='Delete'/>"
54
popup_menu_create (GtkTreeView *treeview)
56
GtkUIManager *ui_manager;
57
GtkActionGroup *action_group;
60
g_return_val_if_fail (treeview != NULL, NULL);
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,
66
G_N_ELEMENTS (popup_menu_items), treeview);
68
ui_manager = gtk_ui_manager_new ();
69
gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
71
if (!gtk_ui_manager_add_ui_from_string (ui_manager, ui_description, -1, NULL))
74
popup = gtk_ui_manager_get_widget (ui_manager, "/MainMenu");
80
create_table_model (void)
84
store = gtk_list_store_new (COL_LAST,
90
return GTK_TREE_MODEL (store);
94
add_table_columns (GtkTreeView *table)
96
GtkCellRenderer *renderer;
98
renderer = gtk_cell_renderer_pixbuf_new ();
99
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (table), 1,
105
renderer = gtk_cell_renderer_text_new ();
106
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (table), 1,
114
table_create (GstTool *tool)
116
GtkWidget *table = gst_dialog_get_widget (tool->main_dialog, "shares_table");
118
GtkTreeSelection *selection;
121
model = create_table_model ();
122
gtk_tree_view_set_model (GTK_TREE_VIEW (table), model);
123
g_object_unref (G_OBJECT (model));
125
add_table_columns (GTK_TREE_VIEW (table));
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);
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);
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]),
142
g_signal_connect (G_OBJECT (table), "drag_data_received",
143
G_CALLBACK (on_shares_dragged_folder), NULL);
149
GtkWidget *table = gst_dialog_get_widget (tool->main_dialog, "shares_table");
152
model = gtk_tree_view_get_model (GTK_TREE_VIEW (table));
153
gtk_list_store_clear (GTK_LIST_STORE (model));
157
get_share_icon (OobsShare *share)
159
GdkPixbuf *pixbuf = NULL;
161
if (OOBS_IS_SHARE_SMB (share)) {
162
pixbuf = gtk_icon_theme_load_icon (gst_tool_get_icon_theme (tool),
165
} else if (OOBS_IS_SHARE_NFS (share)) {
166
pixbuf = gtk_icon_theme_load_icon (gst_tool_get_icon_theme (tool),
175
table_add_share (OobsShare *share, OobsListIter *list_iter)
177
GtkWidget *table = gst_dialog_get_widget (tool->main_dialog, "shares_table");
181
g_return_if_fail (share != NULL);
182
g_return_if_fail (OOBS_IS_SHARE (share));
184
model = gtk_tree_view_get_model (GTK_TREE_VIEW (table));
185
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
187
gtk_list_store_set (GTK_LIST_STORE (model),
189
COL_PIXBUF, get_share_icon (share),
190
COL_PATH, oobs_share_get_path (share),
197
table_modify_share_at_iter (GtkTreeIter *iter, OobsShare *share, OobsListIter *list_iter)
199
GtkWidget *table = gst_dialog_get_widget (tool->main_dialog, "shares_table");
201
GdkPixbuf *pixbuf = NULL;
203
g_return_if_fail (share != NULL);
204
g_return_if_fail (OOBS_IS_SHARE (share));
206
model = gtk_tree_view_get_model (GTK_TREE_VIEW (table));
207
gtk_list_store_set (GTK_LIST_STORE (model),
209
COL_PIXBUF, get_share_icon (share),
210
COL_PATH, oobs_share_get_path (share),
217
table_get_share_at_iter (GtkTreeIter *iter, OobsListIter **list_iter)
219
GtkWidget *table = gst_dialog_get_widget (tool->main_dialog, "shares_table");
223
model = gtk_tree_view_get_model (GTK_TREE_VIEW (table));
225
gtk_tree_model_get (model, iter,
233
table_delete_share_at_iter (GtkTreeIter *iter)
235
GtkWidget *table = gst_dialog_get_widget (tool->main_dialog, "shares_table");
238
model = gtk_tree_view_get_model (GTK_TREE_VIEW (table));
239
gtk_list_store_remove (GTK_LIST_STORE (model), iter);
243
table_get_iter_with_path (const gchar *path, GtkTreeIter *iter)
245
GtkWidget *table = gst_dialog_get_widget (tool->main_dialog, "shares_table");
247
gboolean valid, found;
254
model = gtk_tree_view_get_model (GTK_TREE_VIEW (table));
255
valid = gtk_tree_model_get_iter_first (model, iter);
258
gtk_tree_model_get (model, iter,
259
COL_PATH, &iter_path,
262
if (strcmp (iter_path, path) == 0) {
266
valid = gtk_tree_model_iter_next (model, iter);