void menu_create (GtkWidget *menu, GSList *list, char *target, int check_path) { struct popup *pop; GtkWidget *tempmenu = menu, *subitem = NULL; int childcount = 0; submenu_list = g_slist_prepend (0, menu); while (list) { pop = (struct popup *) list->data; if (!g_ascii_strncasecmp (pop->name, "SUB", 3)) { childcount = 0; tempmenu = menu_quick_sub (pop->cmd, tempmenu, &subitem, XCMENU_DOLIST, -1); } else if (!g_ascii_strncasecmp (pop->name, "TOGGLE", 6)) { childcount++; menu_toggle_item (pop->name + 7, tempmenu, toggle_cb, pop->cmd, cfg_get_bool (pop->cmd)); } else if (!g_ascii_strncasecmp (pop->name, "ENDSUB", 6)) { /* empty sub menu due to no programs in PATH? */ if (check_path && childcount < 1) gtk_widget_destroy (subitem); subitem = NULL; if (tempmenu != menu) tempmenu = menu_quick_endsub (); /* If we get here and tempmenu equals menu that means we havent got any submenus to exit from */ } else if (!g_ascii_strncasecmp (pop->name, "SEP", 3)) { menu_quick_item (0, 0, tempmenu, XCMENU_SHADED, 0, 0); } else { if (!check_path || pop->cmd[0] != '!') { menu_quick_item (pop->cmd, pop->name, tempmenu, 0, target, 0); /* check if the program is in path, if not, leave it out! */ } else if (is_in_path (pop->cmd)) { childcount++; menu_quick_item (pop->cmd, pop->name, tempmenu, 0, target, 0); } } list = list->next; } /* Let's clean up the linked list from mem */ while (submenu_list) submenu_list = g_slist_remove (submenu_list, submenu_list->data); }
void menu_nickmenu(window_t *sess, GdkEventButton * event, char *nick, int num_sel) { char buf[512]; GtkWidget *menu = gtk_menu_new(); userlist_t *user; if (str_copy) free(str_copy); str_copy = xstrdup(nick); submenu_list = NULL; /* first time through, might not be 0 */ /* [XXX, how does this work? memleak? */ /* more than 1 nick selected? */ if (num_sel > 1) { snprintf(buf, sizeof(buf), "%d nicks selected.", num_sel); menu_quick_item(0, buf, menu, 0, 0, 0); menu_quick_item(0, 0, menu, XCMENU_SHADED, 0, 0); } else { user = userlist_find(sess->session, nick); /* XXX, * jesli nadal nie ma uzytkownika, to szukaj go w konferencjach */ if (user) { GtkWidget *submenu = menu_quick_sub(nick, menu, NULL, XCMENU_DOLIST, -1); char *fmt = "<tt><b>%-11s</b></tt> %s"; /* XXX, gettext? (let the translators tweak this if need be) */ char *real; /* UID */ real = g_markup_escape_text(user->uid, -1); snprintf(buf, sizeof(buf), fmt, "UID:", real); g_free(real); menu_quick_item(0, buf, submenu, XCMENU_MARKUP, 0, 0); /* <separator> ? */ /* XXX, get more data using USERLIST_PRIVHANDLE (?) */ /* the same like above */ menu_quick_endsub(); menu_quick_item(0, 0, menu, XCMENU_SHADED, 0, 0); } } #if 0 if (num_sel > 1) menu_create(menu, popup_list, NULL, FALSE); else menu_create(menu, popup_list, str_copy, FALSE); if (num_sel == 0) /* xtext click */ menu_add_plugin_items(menu, "\x5$NICK", str_copy); else /* userlist treeview click */ menu_add_plugin_items(menu, "\x5$NICK", NULL); #endif menu_popup(menu, event, NULL); }
static GtkWidget *menu_add_sub(GtkWidget *menu, menu_entry *me) { GtkWidget *item = NULL; char *path = me->path + me->root_offset; int pos; if (path[0] != 0) menu = menu_find_path(menu, path); if (menu) { pos = me->pos; if (pos < 0) /* position offset from end/bottom */ pos = g_list_length(GTK_MENU_SHELL(menu)->children) + pos; menu_quick_sub(me->label, menu, &item, me->markup ? XCMENU_MARKUP | XCMENU_MNEMONIC : XCMENU_MNEMONIC, pos); } return item; }
void menu_nickmenu (session *sess, GdkEventButton *event, char *nick, int num_sel) { char buf[512]; char *real, *fmt; struct User *user; struct away_msg *away; GtkWidget *submenu, *menu = gtk_menu_new (); if (str_copy) free (str_copy); str_copy = strdup (nick); submenu_list = 0; /* first time through, might not be 0 */ /* more than 1 nick selected? */ if (num_sel > 1) { snprintf (buf, sizeof (buf), "%d nicks selected.", num_sel); menu_quick_item (0, buf, menu, 0, 0, 0); menu_quick_item (0, 0, menu, XCMENU_SHADED, 0, 0); } else { user = userlist_find (sess, nick); /* lasttalk is channel specific */ if (!user) user = userlist_find_global (current_sess->server, nick); if (user) { submenu = menu_quick_sub (nick, menu, NULL, XCMENU_DOLIST, -1); /* let the translators tweak this if need be */ fmt = _("<tt><b>%-11s</b></tt> %s"); if (user->realname) { real = g_markup_escape_text (user->realname, -1); snprintf (buf, sizeof (buf), fmt, _("Real Name:"), real); g_free (real); } else { snprintf (buf, sizeof (buf), fmt, _("Real Name:"), _("Unknown")); } menu_quick_item (0, buf, submenu, XCMENU_MARKUP, 0, 0); snprintf (buf, sizeof (buf), fmt, _("User:"******"Unknown")); menu_quick_item (0, buf, submenu, XCMENU_MARKUP, 0, 0); snprintf (buf, sizeof (buf), fmt, _("Server:"), user->servername ? user->servername : _("Unknown")); menu_quick_item (0, buf, submenu, XCMENU_MARKUP, 0, 0); if (user->away) { away = server_away_find_message (current_sess->server, nick); if (away) { char *msg = strip_color (away->message ? away->message : _("Unknown"), -1, STRIP_ALL); real = g_markup_escape_text (msg, -1); free (msg); snprintf (buf, sizeof (buf), fmt, _("Away Msg:"), real); g_free (real); menu_quick_item (0, buf, submenu, XCMENU_MARKUP, 0, 0); } } if (user->lasttalk) { char min[96]; snprintf (min, sizeof (min), _("%u minutes ago"), (unsigned int) ((time (0) - user->lasttalk) / 60)); snprintf (buf, sizeof (buf), fmt, _("Last Msg:"), min); } else { snprintf (buf, sizeof (buf), fmt, _("Last Msg:"), _("Unknown")); } menu_quick_item (0, buf, submenu, XCMENU_MARKUP, 0, 0); menu_quick_endsub (); menu_quick_item (0, 0, menu, XCMENU_SHADED, 0, 0); } } if (num_sel > 1) menu_create (menu, popup_list, NULL, FALSE); else menu_create (menu, popup_list, str_copy, FALSE); if (num_sel == 0) /* xtext click */ menu_add_plugin_items (menu, "\x5$NICK", str_copy); else /* userlist treeview click */ menu_add_plugin_items (menu, "\x5$NICK", NULL); menu_popup (menu, event, NULL); }