4
* Project: GGZ GTK Client
6
* $Id: tablelist.c,v 1.1 2006/10/14 10:27:32 andreasr Exp $
8
* List of tables in the current room
10
* Copyright (C) 2000-2002 Justin Zaun.
12
* This program is free software; you can redistribute it and/or modify
13
* it under the terms of the GNU General Public License as published by
14
* the Free Software Foundation; either version 2 of the License, or
15
* (at your option) any later version.
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
40
#include "tablelist.h"
51
static GtkWidget *table_list;
53
static gboolean table_list_event(GtkWidget *widget, GdkEvent *event,
56
/* Check to see if the event was a mouse button press */
57
if (event->type == GDK_2BUTTON_PRESS)
58
client_start_table_join();
64
static GtkWidget *create_mnu_table(void)
72
mnu_table = gtk_menu_new();
74
join = gtk_menu_item_new_with_label(_("Join"));
75
gtk_container_add(GTK_CONTAINER(mnu_table), join);
77
leave = gtk_menu_item_new_with_label(_("Leave"));
78
gtk_container_add(GTK_CONTAINER(mnu_table), leave);
80
menuitem3 = gtk_menu_item_new();
81
gtk_container_add(GTK_CONTAINER(mnu_table), menuitem3);
82
gtk_widget_set_sensitive(menuitem3, FALSE);
84
info = gtk_menu_item_new_with_label(_("Info"));
85
gtk_container_add(GTK_CONTAINER(mnu_table), info);
87
#if 0 /* not implemented */
88
g_signal_connect(GTK_OBJECT(join), "activate",
89
GTK_SIGNAL_FUNC(client_join_table_activate),
90
GINT_TO_POINTER(table_num));
91
g_signal_connect(GTK_OBJECT(leave), "activate",
92
GTK_SIGNAL_FUNC(client_leave_activate), NULL);
93
g_signal_connect(GTK_OBJECT(info), "activate",
94
GTK_SIGNAL_FUNC(client_table_info_activate),
95
GINT_TO_POINTER(table_num));
102
GGZTable *get_selected_table(void)
104
GtkWidget *tree = table_list;
105
GtkTreeSelection *select
106
= gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
107
GGZRoom *room = ggzcore_server_get_cur_room(server);
112
if (!gtk_tree_selection_get_selected(select, &model, &iter)) {
116
gtk_tree_model_get(model, &iter, TABLE_COLUMN_ID, &id, -1);
118
return ggzcore_room_get_table_by_id(room, id);
122
void clear_table_list(void)
124
GtkWidget *store = ggz_lookup_widget(table_list, "table_list_store");
126
gtk_list_store_clear(GTK_LIST_STORE(store));
129
void sensitize_table_list(gboolean sensitive)
131
gtk_widget_set_sensitive(table_list, sensitive);
134
void update_table_list(void)
137
GGZRoom *room = ggzcore_server_get_cur_room(server);
139
const int num = ggzcore_room_get_num_tables(room);
141
/* Retrieve the player list widget. */
142
store = GTK_LIST_STORE(ggz_lookup_widget(table_list, "table_list_store"));
144
gtk_list_store_clear(store);
146
for (i = 0; i < num; i++) {
151
GGZTable *t = ggzcore_room_get_nth_table(room, i);
152
int id = ggzcore_table_get_id(t);
154
avail = (ggzcore_table_get_seat_count(t, GGZ_SEAT_OPEN)
155
+ ggzcore_table_get_seat_count(t, GGZ_SEAT_RESERVED));
156
total = ggzcore_table_get_num_seats(t);
157
snprintf(seats, sizeof(seats), "%d/%d", avail, total);
159
desc = ggzcore_table_get_desc(t);
161
desc = _("No description available.");
164
gtk_list_store_append(store, &iter);
165
gtk_list_store_set(store, &iter,
167
TABLE_COLUMN_SEATS, seats,
168
TABLE_COLUMN_DESC, desc,
174
GtkWidget *create_table_list(GtkWidget * window)
178
GtkCellRenderer *renderer;
179
GtkTreeViewColumn *column;
180
GtkTreeSelection *select;
182
assert(TABLE_COLUMNS == 3);
183
store = gtk_list_store_new(TABLE_COLUMNS,
187
tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
188
g_object_unref(store);
190
renderer = gtk_cell_renderer_text_new();
191
column = gtk_tree_view_column_new_with_attributes(_("T#"), renderer,
192
"text", TABLE_COLUMN_ID, NULL);
193
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
195
renderer = gtk_cell_renderer_text_new();
196
column = gtk_tree_view_column_new_with_attributes(_("Seats"), renderer,
197
"text", TABLE_COLUMN_SEATS, NULL);
198
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
200
renderer = gtk_cell_renderer_text_new();
201
column = gtk_tree_view_column_new_with_attributes(_("Description"),
203
"text", TABLE_COLUMN_DESC, NULL);
204
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
206
g_object_set_data(G_OBJECT(window), "table_list_store", store);
207
g_object_set_data(G_OBJECT(tree), "table_list_store", store);
208
gtk_widget_set_sensitive(tree, FALSE);
209
GTK_WIDGET_UNSET_FLAGS(tree, GTK_CAN_FOCUS);
211
select = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
212
gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE);
214
g_signal_connect(tree, "button-press-event",
215
GTK_SIGNAL_FUNC(table_list_event), NULL);