summary refs log tree commit diff stats
path: root/src/common/util.c
AgeCommit message (Collapse)Author
2013-11-02Fix invalid timestamps crashing on WindowsTingPing
2013-09-25Only show users country if its not unknownTingPing
2013-09-07Disable challangeauth without opensslTingPing
2013-09-07Implement BLOWFISh, AES, and EXTERNAL SASL mechanismsTingPing
Closes #657
2013-05-20Sample code docs for challengeauth_response()Berke Viktor
2013-05-19CosmeticsBerke Viktor
2013-05-19Simplify SASL auth string generation codeBerke Viktor
2013-05-17Add support for QuakeNet /CHALLENGEAUTH, remove legacy /AUTHBerke Viktor
2013-05-14Fix warningsBerke Viktor
2013-05-04Replace g_strdup_printf with g_build_filename where possibleBerke Viktor
2013-04-02Only include top level includes from GTK+, GLib and GDK-PixBufBerke Viktor
2013-04-02Remove most of HexTray and one instanceBerke Viktor
You can still build HexTray manually if you want to try fixing it
2013-03-25Disable tray when using UnityTingPing
2013-01-09Oops, fixed error in util.cRichardHitt
2013-01-09Make source cleah with cppcheck, except for mpc and saslRichardHitt
2012-12-23fix incorrect FSF addressDan Mashal
2012-11-11utf8-everywhere: Derp.Arnav Singh
2012-11-11utf8-everywhere: Fixed some remaining C file I/O API calls to use the glib API.Arnav Singh
2012-11-04Indentation cosmeticsBerke Viktor
2012-11-03Initial commit for utf8 everywhere.Arnavion
2012-10-30Nah, even more rebrandingBerke Viktor
2012-10-29Make HexTray filename consistent with the restBerke Viktor
2012-10-28Use Consolas as the default font where availableBerke Viktor
2012-10-28Even moar polishingBerke Viktor
2012-10-28More polishing for the About dialogBerke Viktor
2012-10-27Ignore generated config.h properly on UnixBerke Viktor
2012-10-25Eliminate compiler warning and update Windows Server nameBerke Viktor
2012-10-25Move SASL passphrase generation code to utilsBerke Viktor
2012-10-25Quickfix for plugin breakage after the DCC patchBerke Viktor
2012-10-24A lot more rebrandingBerke Viktor
2012-10-22Removed DCC::destfile_fs since it was now the same as DCC::destfile. Fixed ↵Arnav Singh
usage of g_stat to use GStatBuf instead of OS-native struct stat.
2012-10-19Remove L10n test stringBerke Viktor
2012-10-19Add L10n test stringBerke Viktor
2012-10-18Add function for listing subdirsBerke Viktor
2012-07-21Minor cosmetics for util.c tooBerke Viktor
2012-07-21Supposed fix for g_io_channel_read() deprecationBerke Viktor
2012-07-21Some aid for compiler warningsBerke Viktor
2012-07-13Rename X-Tray to HexTrayBerke Viktor
2012-07-11Improve URL recognition (sacarasc)Alfred Daw
2012-06-16Fix string handling for Turkish localeBerke Viktor
2012-06-10Migrate VS solution to VS2010+WDK7Berke Viktor
2012-06-03Initial Visual Studio solutionBerke Viktor
2012-01-08Merge branch 'master' into wdkBerke Viktor
2012-01-08update xchat to r1499Berke Viktor
2011-12-11some more multiplatform supportBerke Viktor
2011-12-11initial patches for linux compatibilityBerke Viktor
2011-11-29initial plugin config framework, can't save multiple entriesBerke Viktor
2011-11-23remove unused variableBerke Viktor
2011-06-17add support for Windows 8 in CTCP VERSION replyberkeviktor@aol.com
2011-05-30move cpu arch stuff to separate functionberkeviktor@aol.com
pan class="cpf">"../common/hexchat.h" #include "../common/cfgfiles.h" #include "../common/hexchatc.h" #include "../common/fe.h" #include "menu.h" #include "gtkutil.h" #include "maingui.h" #include "editlist.h" enum { NAME_COLUMN, CMD_COLUMN, N_COLUMNS }; static GtkWidget *editlist_win = NULL; static GSList *editlist_list = NULL; static GtkTreeModel * get_store (void) { return gtk_tree_view_get_model (g_object_get_data (G_OBJECT (editlist_win), "view")); } static void editlist_save (GtkWidget *igad, gchar *file) { GtkTreeModel *store = get_store (); GtkTreeIter iter; char buf[512]; char *name, *cmd; int fh; fh = hexchat_open_file (file, O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE); if (fh != -1) { if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) { do { name = NULL; cmd = NULL; gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, NAME_COLUMN, &name, CMD_COLUMN, &cmd, -1); g_snprintf (buf, sizeof (buf), "NAME %s\nCMD %s\n\n", name, cmd); write (fh, buf, strlen (buf)); g_free (name); g_free (cmd); } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter)); } close (fh); gtk_widget_destroy (editlist_win); if (editlist_list == replace_list) { list_free (&replace_list); list_loadconf (file, &replace_list, 0); } else if (editlist_list == popup_list) { list_free (&popup_list); list_loadconf (file, &popup_list, 0); } else if (editlist_list == button_list) { GSList *list = sess_list; struct session *sess; list_free (&button_list); list_loadconf (file, &button_list, 0); while (list) { sess = (struct session *) list->data; fe_buttons_update (sess); list = list->next; } } else if (editlist_list == dlgbutton_list) { GSList *list = sess_list; struct session *sess; list_free (&dlgbutton_list); list_loadconf (file, &dlgbutton_list, 0); while (list) { sess = (struct session *) list->data; fe_dlgbuttons_update (sess); list = list->next; } } else if (editlist_list == ctcp_list) { list_free (&ctcp_list); list_loadconf (file, &ctcp_list, 0); } else if (editlist_list == command_list) { list_free (&command_list); list_loadconf (file, &command_list, 0); } else if (editlist_list == usermenu_list) { list_free (&usermenu_list); list_loadconf (file, &usermenu_list, 0); usermenu_update (); } else { list_free (&urlhandler_list); list_loadconf (file, &urlhandler_list, 0); } } } static void editlist_load (GtkListStore *store, GSList *list) { struct popup *pop; gchar *name, *cmd; GtkTreeIter iter; while (list) { pop = (struct popup *) list->data; name = pop->name; cmd = pop->cmd; gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, NAME_COLUMN, name, CMD_COLUMN, cmd, -1); list = list->next; } } static void editlist_delete (GtkWidget *wid, gpointer userdata) { GtkTreeView *view = g_object_get_data (G_OBJECT (editlist_win), "view"); GtkListStore *store = GTK_LIST_STORE (gtk_tree_view_get_model (view)); GtkTreeIter iter; GtkTreePath *path; if (gtkutil_treeview_get_selected (view, &iter, -1)) { /* delete this row, select next one */ if (gtk_list_store_remove (store, &iter)) { path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter); gtk_tree_view_scroll_to_cell (view, path, NULL, TRUE, 1.0, 0.0); gtk_tree_view_set_cursor (view, path, NULL, FALSE); gtk_tree_path_free (path); } } } static void editlist_add (GtkWidget *wid, gpointer userdata) { GtkTreeView *view = g_object_get_data (G_OBJECT (editlist_win), "view"); GtkTreeViewColumn *col; GtkListStore *store = GTK_LIST_STORE (get_store ()); GtkTreeIter iter; GtkTreePath *path; gtk_list_store_append (store, &iter); /* make sure the new row is visible and selected */ path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter); col = gtk_tree_view_get_column (view, NAME_COLUMN); gtk_tree_view_scroll_to_cell (view, path, NULL, FALSE, 0.0, 0.0); gtk_tree_view_set_cursor (view, path, col, TRUE); gtk_tree_path_free (path); } static void editlist_close (GtkWidget *wid, gpointer userdata) { gtk_widget_destroy (editlist_win); editlist_win = NULL; } static void editlist_edited (GtkCellRendererText *render, gchar *pathstr, gchar *new_text, gpointer data) { GtkTreeModel *model = get_store (); GtkTreePath *path = gtk_tree_path_new_from_string (pathstr); GtkTreeIter iter; gint column = GPOINTER_TO_INT (data); gtk_tree_model_get_iter (model, &iter, path); gtk_list_store_set (GTK_LIST_STORE (model), &iter, column, new_text, -1); gtk_tree_path_free (path); } static gboolean editlist_keypress (GtkWidget *wid, GdkEventKey *evt, gpointer userdata) { GtkTreeView *view = g_object_get_data (G_OBJECT (editlist_win), "view"); GtkTreeModel *store; GtkTreeIter iter1, iter2; GtkTreeSelection *sel; GtkTreePath *path; gboolean handled = FALSE; int delta; if (evt->state & GDK_SHIFT_MASK) { if (evt->keyval == GDK_KEY_Up) { handled = TRUE; delta = -1; } else if (evt->keyval == GDK_KEY_Down) { handled = TRUE; delta = 1; } } if (handled) { sel = gtk_tree_view_get_selection (view); gtk_tree_selection_get_selected (sel, &store, &iter1); path = gtk_tree_model_get_path (store, &iter1); if (delta == 1) gtk_tree_path_next (path); else gtk_tree_path_prev (path); gtk_tree_model_get_iter (store, &iter2, path); gtk_tree_path_free (path); gtk_list_store_swap (GTK_LIST_STORE (store), &iter1, &iter2); } return handled; } static GtkWidget * editlist_treeview_new (GtkWidget *box, char *title1, char *title2) { GtkWidget *scroll; GtkListStore *store; GtkTreeViewColumn *col; GtkWidget *view; GtkCellRenderer *render; scroll = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN); store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); g_return_val_if_fail (store != NULL, NULL); view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)); gtk_tree_view_set_fixed_height_mode (GTK_TREE_VIEW (view), TRUE); gtk_tree_view_set_enable_search (GTK_TREE_VIEW (view), FALSE); g_signal_connect (G_OBJECT (view), "key_press_event", G_CALLBACK (editlist_keypress), NULL); gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE); render = gtk_cell_renderer_text_new (); g_object_set (render, "editable", TRUE, NULL); g_signal_connect (G_OBJECT (render), "edited", G_CALLBACK (editlist_edited), GINT_TO_POINTER(NAME_COLUMN)); gtk_tree_view_insert_column_with_attributes ( GTK_TREE_VIEW (view), NAME_COLUMN, title1, render, "text", NAME_COLUMN, NULL); render = gtk_cell_renderer_text_new (); g_object_set (render, "editable", TRUE, NULL); g_signal_connect (G_OBJECT (render), "edited", G_CALLBACK (editlist_edited), GINT_TO_POINTER(CMD_COLUMN)); gtk_tree_view_insert_column_with_attributes ( GTK_TREE_VIEW (view), CMD_COLUMN, title2, render, "text", CMD_COLUMN, NULL); col = gtk_tree_view_get_column (GTK_TREE_VIEW (view), NAME_COLUMN); gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_AUTOSIZE); gtk_tree_view_column_set_resizable (col, TRUE); gtk_tree_view_column_set_min_width (col, 100); gtk_container_add (GTK_CONTAINER (scroll), view); gtk_container_add (GTK_CONTAINER (box), scroll); gtk_widget_show_all (box); return view; } void editlist_gui_open (char *title1, char *title2, GSList *list, char *title, char *wmclass, char *file, char *help) { GtkWidget *vbox, *box; GtkWidget *view; GtkListStore *store; if (editlist_win) { mg_bring_tofront (editlist_win); return; } editlist_win = mg_create_generic_tab (wmclass, title, TRUE, FALSE, editlist_close, NULL, 450, 250, &vbox, 0); editlist_list = list; view = editlist_treeview_new (vbox, title1, title2); g_object_set_data (G_OBJECT (editlist_win), "view", view); if (help) gtk_widget_set_tooltip_text (view, help); box = gtk_hbutton_box_new (); gtk_button_box_set_layout (GTK_BUTTON_BOX (box), GTK_BUTTONBOX_SPREAD); gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, FALSE, 2); gtk_container_set_border_width (GTK_CONTAINER (box), 5); gtk_widget_show (box); gtkutil_button (box, GTK_STOCK_NEW, 0, editlist_add, NULL, _("Add")); gtkutil_button (box, GTK_STOCK_DELETE, 0, editlist_delete, NULL, _("Delete")); gtkutil_button (box, GTK_STOCK_CANCEL, 0, editlist_close, NULL, _("Cancel")); gtkutil_button (box, GTK_STOCK_SAVE, 0, editlist_save, file, _("Save")); store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (view))); editlist_load (store, list); gtk_widget_show (editlist_win); }