~ubuntu-branches/ubuntu/gutsy/gnome-games/gutsy-updates

« back to all changes in this revision

Viewing changes to dependencies/ggz-gtk/tablelist.c

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2006-11-08 15:56:11 UTC
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20061108155611-wv3ofq76d2dnddt3
Tags: upstream-2.17.2
ImportĀ upstreamĀ versionĀ 2.17.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * File: tablelist.c
 
3
 * Author: GGZ Dev Team
 
4
 * Project: GGZ GTK Client
 
5
 * Date: 11/03/2002
 
6
 * $Id: tablelist.c,v 1.1 2006/10/14 10:27:32 andreasr Exp $
 
7
 * 
 
8
 * List of tables in the current room
 
9
 * 
 
10
 * Copyright (C) 2000-2002 Justin Zaun.
 
11
 * 
 
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.
 
16
 * 
 
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.
 
21
 *
 
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
 
25
 */
 
26
 
 
27
#ifdef HAVE_CONFIG_H
 
28
#  include <config.h>
 
29
#endif
 
30
 
 
31
#include <assert.h>
 
32
#include <stdio.h>
 
33
#include <stdlib.h>
 
34
#include <strings.h>
 
35
 
 
36
#include <gtk/gtk.h>
 
37
#include <ggzcore.h>
 
38
 
 
39
#include "client.h"
 
40
#include "tablelist.h"
 
41
#include "server.h"
 
42
#include "support.h"
 
43
 
 
44
enum {
 
45
        TABLE_COLUMN_ID,
 
46
        TABLE_COLUMN_SEATS,
 
47
        TABLE_COLUMN_DESC,
 
48
        TABLE_COLUMNS
 
49
};
 
50
 
 
51
static GtkWidget *table_list;
 
52
 
 
53
static gboolean table_list_event(GtkWidget *widget, GdkEvent *event,
 
54
                                 gpointer data)
 
55
{
 
56
        /* Check to see if the event was a mouse button press */
 
57
        if (event->type == GDK_2BUTTON_PRESS)
 
58
                client_start_table_join();
 
59
        return FALSE;
 
60
}
 
61
 
 
62
 
 
63
#if 0
 
64
static GtkWidget *create_mnu_table(void)
 
65
{
 
66
        GtkWidget *mnu_table;
 
67
        GtkWidget *join;
 
68
        GtkWidget *leave;
 
69
        GtkWidget *menuitem3;
 
70
        GtkWidget *info;
 
71
 
 
72
        mnu_table = gtk_menu_new();
 
73
 
 
74
        join = gtk_menu_item_new_with_label(_("Join"));
 
75
        gtk_container_add(GTK_CONTAINER(mnu_table), join);
 
76
 
 
77
        leave = gtk_menu_item_new_with_label(_("Leave"));
 
78
        gtk_container_add(GTK_CONTAINER(mnu_table), leave);
 
79
 
 
80
        menuitem3 = gtk_menu_item_new();
 
81
        gtk_container_add(GTK_CONTAINER(mnu_table), menuitem3);
 
82
        gtk_widget_set_sensitive(menuitem3, FALSE);
 
83
 
 
84
        info = gtk_menu_item_new_with_label(_("Info"));
 
85
        gtk_container_add(GTK_CONTAINER(mnu_table), info);
 
86
 
 
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));
 
96
#endif
 
97
 
 
98
        return mnu_table;
 
99
}
 
100
#endif
 
101
 
 
102
GGZTable *get_selected_table(void)
 
103
{
 
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);
 
108
        GtkTreeModel *model;
 
109
        GtkTreeIter iter;
 
110
        gint id;
 
111
 
 
112
        if (!gtk_tree_selection_get_selected(select, &model, &iter)) {
 
113
                return NULL;
 
114
        }
 
115
 
 
116
        gtk_tree_model_get(model, &iter, TABLE_COLUMN_ID, &id, -1);
 
117
 
 
118
        return ggzcore_room_get_table_by_id(room, id);
 
119
}
 
120
 
 
121
 
 
122
void clear_table_list(void)
 
123
{
 
124
        GtkWidget *store = ggz_lookup_widget(table_list, "table_list_store");
 
125
 
 
126
        gtk_list_store_clear(GTK_LIST_STORE(store));
 
127
}
 
128
 
 
129
void sensitize_table_list(gboolean sensitive)
 
130
{
 
131
        gtk_widget_set_sensitive(table_list, sensitive);
 
132
}
 
133
 
 
134
void update_table_list(void)
 
135
{
 
136
        GtkListStore *store;
 
137
        GGZRoom *room = ggzcore_server_get_cur_room(server);
 
138
        int i;
 
139
        const int num = ggzcore_room_get_num_tables(room);
 
140
 
 
141
        /* Retrieve the player list widget. */
 
142
        store = GTK_LIST_STORE(ggz_lookup_widget(table_list, "table_list_store"));
 
143
 
 
144
        gtk_list_store_clear(store);
 
145
 
 
146
        for (i = 0; i < num; i++) {
 
147
                GtkTreeIter iter;
 
148
                gchar seats[128];
 
149
                int avail, total;
 
150
                const gchar *desc;
 
151
                GGZTable *t = ggzcore_room_get_nth_table(room, i);
 
152
                int id = ggzcore_table_get_id(t);
 
153
 
 
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);
 
158
 
 
159
                desc = ggzcore_table_get_desc(t);
 
160
                if (!desc) {
 
161
                        desc = _("No description available.");
 
162
                }
 
163
 
 
164
                gtk_list_store_append(store, &iter);
 
165
                gtk_list_store_set(store, &iter,
 
166
                                   TABLE_COLUMN_ID, id,
 
167
                                   TABLE_COLUMN_SEATS, seats,
 
168
                                   TABLE_COLUMN_DESC, desc,
 
169
                                   -1);
 
170
 
 
171
        }
 
172
}
 
173
 
 
174
GtkWidget *create_table_list(GtkWidget * window)
 
175
{
 
176
        GtkListStore *store;
 
177
        GtkWidget *tree;
 
178
        GtkCellRenderer *renderer;
 
179
        GtkTreeViewColumn *column;
 
180
        GtkTreeSelection *select;
 
181
 
 
182
        assert(TABLE_COLUMNS == 3);
 
183
        store = gtk_list_store_new(TABLE_COLUMNS,
 
184
                                   G_TYPE_INT,
 
185
                                   G_TYPE_STRING,
 
186
                                   G_TYPE_STRING);
 
187
        tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
 
188
        g_object_unref(store);
 
189
 
 
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);
 
194
 
 
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);
 
199
 
 
200
        renderer = gtk_cell_renderer_text_new();
 
201
        column = gtk_tree_view_column_new_with_attributes(_("Description"),
 
202
                                                          renderer,
 
203
                                "text", TABLE_COLUMN_DESC, NULL);
 
204
        gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
 
205
 
 
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);
 
210
 
 
211
        select = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
 
212
        gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE);
 
213
 
 
214
        g_signal_connect(tree, "button-press-event",
 
215
                         GTK_SIGNAL_FUNC(table_list_event), NULL);
 
216
 
 
217
        table_list = tree;
 
218
 
 
219
        return tree;
 
220
}