/* X-Chat * Copyright (C) 1998 Peter Zelezny. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #include #include #include #include "fe-gtk.h" #include #include "../common/hexchat.h" #include "../common/util.h" #include "../common/userlist.h" #include "../common/modes.h" #include "../common/text.h" #include "../common/notify.h" #include "../common/hexchatc.h" #include "../common/fe.h" #include "gtkutil.h" #include "palette.h" #include "maingui.h" #include "menu.h" #include "pixmaps.h" #include "userlistgui.h" #include "fkeys.h" enum { COL_PIX=0, // GdkPixbuf * COL_NICK=1, // char * COL_HOST=2, // char * COL_USER=3, // struct User * COL_GDKCOLOR=4 // GdkColor * }; GdkPixbuf * get_user_icon (server *serv, struct User *user) { char *pre; int level; if (!user) return NULL; /* these ones are hardcoded */ switch (user->prefix[0]) { case 0: return NULL; case '+': return pix_ulist_voice; case '%': return pix_ulist_halfop; case '@': return pix_ulist_op; } /* find out how many levels above Op this user is */ pre = strchr (serv->nick_prefixes, '@'); if (pre && pre != serv->nick_prefixes) { pre--; level = 0; while (1) { if (pre[0] == user->prefix[0]) { switch (level) { case 0: return pix_ulist_owner; /* 1 level above op */ case 1: return pix_ulist_founder; /* 2 levels above op */ case 2: return pix_ulist_netop; /* 3 levels above op */ } break; /* 4+, no icons */ } level++; if (pre == serv->nick_prefixes) break; pre--; } } return NULL; } void fe_userlist_numbers (session *sess) { char tbuf[256]; if (sess == current_tab || !sess->gui->is_tab) { if (sess->total) { snprintf (tbuf, sizeof (tbuf), _("%d ops, %d total"), sess->ops, sess->total); tbuf[sizeof (tbuf) - 1] = 0; gtk_label_set_text (GTK_LABEL (sess->gui->namelistinfo), tbuf); } else { gtk_label_set_text (GTK_LABEL (sess->gui->namelistinfo), NULL); } if (sess->type == SESS_CHANNEL && prefs.hex_gui_win_ucount) fe_set_title (sess); } } static void scroll_to_iter (GtkTreeIter *iter, GtkTreeView *treeview, GtkTreeModel *model) { GtkTreePath *path = gtk_tree_model_get_path (model, iter); if (path) { gtk_tree_view_scroll_to_cell (treeview, path, NULL, TRUE, 0.5, 0.5); gtk_tree_path_free (path); } } /* select a row in the userlist by nick-name */ void userlist_select (session *sess, char *name) { GtkTreeIter iter; GtkTreeView *treeview = GTK_TREE_VIEW (sess->gui->user_tree); GtkTreeModel *model = gtk_tree_view_get_model (treeview); GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview); struct User *row_user; if (gtk_tree_model_get_iter_first (model, &iter)) { do { gtk_tree_model_get (model, &iter, COL_USER, &row_user, -1); if (sess->server->p_cmp (row_user->nick, name) == 0) { if (gtk_tree_selection_iter_is_selected (selection, &iter)) gtk_tree_selection_unselect_iter (selection, &iter); else gtk_tree_selection_select_iter (selection, &iter); /* and make sure it's visible */ scroll_to_iter (&iter, treeview, model); return; } } while (gtk_tree_model_iter_next (model, &iter)); } } char ** userlist_selection_list (GtkWidget *widget, int *num_ret) { GtkTreeIter iter; GtkTreeView *treeview = (GtkTreeView *) widget; GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview); GtkTreeModel *model = gtk_tree_view_get_model (treeview); struct User *user; int i, num_sel; char **nicks; *num_ret = 0; /* first, count the number of selections */ num_sel = 0; if (gtk_tree_model_get_iter_first (model, &iter)) { do { if (gtk_tree_selection_iter_is_selected (selection, &iter)) num_sel++; } while (gtk_tree_model_iter_next (model, &iter)); } if (num_sel < 1) return NULL; nicks = malloc (sizeof (char *) * (num_sel + 1)); i = 0; gtk_tree_model_get_iter_first (model, &iter); do { if (gtk_tree_selection_iter_is_selected (selection, &iter)) { gtk_tree_model_get (model, &iter, COL_USER, &user, -1); nicks[i] = g_strdup (user->nick); i++; nicks[i] = NULL; } } while (gtk_tree_model_iter_next (model, &iter)); *num_ret = i; return nicks; } void fe_userlist_set_selected (struct session *sess) { GtkListStore *store = sess->res->user_model; GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (sess->gui->user_tree)); GtkTreeIter iter; struct User *user; /* if it's not front-most tab it doesn't own the GtkTreeView! */ if (store != (GtkListStore*) gtk_tree_view_get_model (GTK_TREE_VIEW (sess->gui->user_tree))) return; if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) { do { gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, COL_USER, &user, -1); if (gtk_tree_selection_iter_is_selected (selection, &iter)) user->selected = 1; else user->selected = 0; } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter)); } } static GtkTreeIter * find_row (GtkTreeView *treeview, GtkTreeModel *model, struct User *user, int *selected) { static GtkTreeIter iter; struct User *row_user; *selected = FALSE; if (gtk_tree_model_get_iter_first (model, &iter)) { do { gtk_tree_model_get (model, &iter, COL_USER, &row_user, -1); if (row_user == user) { if (gtk_tree_view_get_model (treeview) == model) { if (gtk_tree_selection_iter_is_selected (gtk_tree_view_get_selection (treeview), &iter)) *selected = TRUE; } return &iter; } } while (gtk_tree_model_iter_next (model, &iter)); } return NULL; } void userlist_set_value (GtkWidget *treeview, gfloat val) { gtk_adjustment_set_value ( gtk_tree_view_get_vadjustment (GTK_TREE_VIEW (treeview)), val); } gfloat userlist_get_value (GtkWidget *treeview) { return gtk_tree_view_get_vadjustment (GTK_TREE_VIEW (treeview))->value; } int fe_userlist_remove (session *sess, struct User *user) { GtkTreeIter *iter; /* GtkAdjustment *adj; gfloat val, end;*/ int sel; iter = find_row (GTK_TREE_VIEW (sess->gui->user_tree), sess->res->user_model, user, &sel); if (!iter) return 0; /* adj = gtk_tree_view_get_vadjustment (GTK_TREE_VIEW (sess->gui->user_tree)); val = adj->value;*/ gtk_list_store_remove (sess->res->user_model, iter); /* is it the front-most tab? */ /* if (gtk_tree_view_get_model (GTK_TREE_VIEW (sess->gui->user_tree)) == sess->res->user_model) { end = adj->upper - adj->lower - adj->page_size; if (val > end) val = end; gtk_adjustment_set_value (adj, val); }*/ return sel; } void fe_userlist_rehash (session *sess, struct User *user) { GtkTreeIter *iter; int sel; int nick_color = 0; iter = find_row (GTK_TREE_VIEW (sess->gui->user_tree), sess->res->user_model, user, &sel); if (!iter) return; if (prefs.hex_away_track && prefs.hex_away_size_max && user->away) nick_color = COL_AWAY; else if (prefs.hex_gui_ulist_color) nick_color = text_color_of(user->nick); gtk_list_store_set (GTK_LIST_STORE (sess->res->user_model), iter, COL_HOST, user->hostname, COL_GDKCOLOR, nick_color ? &colors[nick_color] : NULL, -1); } void fe_userlist_insert (session *sess, struct User *newuser, int row, int sel) { GtkTreeModel *model = sess->res->user_model; GdkPixbuf *pix = get_user_icon (sess->server, newuser); GtkTreeIter iter; char *nick; int nick_color = 0; if (prefs.hex_away_track && prefs.hex_away_size_max && newuser->away) nick_color = COL_AWAY; else if (prefs.hex_gui_ulist_color) nick_color = text_color_of(newuser->nick); nick = newuser->nick; if (!prefs.hex_gui_ulist_icons) { nick = malloc (strlen (newuser->nick) + 2); nick[0] = newuser->prefix[0]; if (!nick[0] || nick[0] == ' ') strcpy (nick, newuser->nick); else strcpy (nick + 1, newuser->nick); pix = NULL;
/* libsexy
 * Copyright (C) 2005-2006 Christian Hammond.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <glib-object.h>


#ifdef G_ENABLE_DEBUG
#define g_marshal_value_peek_boolean(v)  g_value_get_boolean (v)
#define g_marshal_value_peek_char(v)     g_value_get_char (v)
#define g_marshal_value_peek_uchar(v)    g_value_get_uchar (v)
#define g_marshal_value_peek_int(v)      g_value_get_int (v)
#define g_marshal_value_peek_uint(v)     g_value_get_uint (v)
#define g_marshal_value_peek_long(v)     g_value_get_long (v)
#define g_marshal_value_peek_ulong(v)    g_value_get_ulong (v)
#define g_marshal_value_peek_int64(v)    g_value_get_int64 (v)
#define g_marshal_value_peek_uint64(v)   g_value_get_uint64 (v)
#define g_marshal_value_peek_enum(v)     g_value_get_enum (v)
#define g_marshal_value_peek_flags(v)    g_value_get_flags (v)
#define g_marshal_value_peek_float(v)    g_value_get_float (v)
#define g_marshal_value_peek_double(v)   g_value_get_double (v)
#define g_marshal_value_peek_string(v)   (char*) g_value_get_string (v)
#define g_marshal_value_peek_param(v)    g_value_get_param (v)
#define g_marshal_value_peek_boxed(v)    g_value_get_boxed (v)
#define g_marshal_value_peek_pointer(v)  g_value_get_pointer (v)
#define g_marshal_value_peek_object(v)   g_value_get_object (v)
#else /* !G_ENABLE_DEBUG */
/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
 *          Do not access GValues directly in your code. Instead, use the
 *          g_value_get_*() functions
 */
#define g_marshal_value_peek_boolean(v)  (v)->data[0].v_int
#define g_marshal_value_peek_char(v)     (v)->data[0].v_int
#define g_marshal_value_peek_uchar(v)    (v)->data[0].v_uint
#define g_marshal_value_peek_int(v)      (v)->data[0].v_int
#define g_marshal_value_peek_uint(v)     (v)->data[0].v_uint
#define g_marshal_value_peek_long(v)     (v)->data[0].v_long
#define g_marshal_value_peek_ulong(v)    (v)->data[0].v_ulong