summary refs log blame commit diff stats
path: root/src/common/servlist.c
blob: 1a262a54a1595bc225c7c652c89d1fdc8573c882 (plain) (tree)
1ecc6b31 generated by cgit-pink 1.4.1 (git 2.36.1) at 2024-12-27 11:46:33 +0000
b; } static void open_data_cb (GtkWidget *button, gpointer data) { fe_open_url (get_xdir ()); } static GtkWidget * setup_create_page (const setting *set) { int i, row, do_disable; GtkWidget *tab, *box, *left; GtkWidget *wid = NULL, *parentwid = NULL; box = gtk_vbox_new (FALSE, 1); gtk_container_set_border_width (GTK_CONTAINER (box), 6); tab = setup_create_frame (&left, box); i = row = do_disable = 0; while (set[i].type != ST_END) { switch (set[i].type) { case ST_HEADER: setup_create_header (tab, row, set[i].label); break; case ST_EFONT: case ST_ENTRY: case ST_EFILE: case ST_EFOLDER: wid = setup_create_entry (tab, row, &set[i]); break; case ST_TOGGLR: row--; setup_create_toggleR (tab, row, &set[i]); break; case ST_TOGGLE: wid = setup_create_toggleL (tab, row, &set[i]); if (set[i].extra) do_disable = set[i].extra; break; case ST_3OGGLE: setup_create_3oggle (tab, row, &set[i]); break; case ST_MENU: setup_create_menu (tab, row, &set[i]); break; case ST_RADIO: row += setup_create_radio (tab, row, &set[i]); break; case ST_NUMBER: wid = setup_create_spin (tab, row, &set[i]); break; case ST_HSCALE: setup_create_hscale (tab, row, &set[i]); break; case ST_LABEL: setup_create_label (tab, row, &set[i]); break; case ST_ALERTHEAD: setup_create_alert_header (tab, row, &set[i]); } if (do_disable) { if (GTK_IS_WIDGET (parentwid)) { g_signal_connect (G_OBJECT (parentwid), "toggled", G_CALLBACK(setup_toggle_sensitive_cb), wid); gtk_widget_set_sensitive (wid, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (parentwid))); do_disable--; if (!do_disable) parentwid = NULL; } else parentwid = wid; } i++; row++; } #if 0 if (set == general_settings) { setup_create_id_menu (tab, _("Mark identified users with:"), row, setup_prefs.hex_irc_id_ytext); setup_create_id_menu (tab, _("Mark not-identified users with:"), row + 1, setup_prefs.hex_irc_id_ntext); } #endif if (set == logging_settings) { GtkWidget *but = gtk_button_new_with_label (_("Open Data Folder")); gtk_box_pack_start (GTK_BOX (left), but, 0, 0, 0); g_signal_connect (G_OBJECT (but), "clicked", G_CALLBACK (open_data_cb), 0); } return box; } static void setup_color_ok_cb (GtkWidget *button, GtkWidget *dialog) { GtkColorSelectionDialog *cdialog = GTK_COLOR_SELECTION_DIALOG (dialog); GdkColor *col; GdkColor old_color; GtkStyle *style; col = g_object_get_data (G_OBJECT (button), "c"); old_color = *col; button = g_object_get_data (G_OBJECT (button), "b"); if (!GTK_IS_WIDGET (button)) { gtk_widget_destroy (dialog); return; } color_change = TRUE; gtk_color_selection_get_current_color (GTK_COLOR_SELECTION (cdialog->colorsel), col); gdk_colormap_alloc_color (gtk_widget_get_colormap (button), col, TRUE, TRUE); style = gtk_style_new (); style->bg[0] = *col; gtk_widget_set_style (button, style); g_object_unref (style); /* is this line correct?? */ gdk_colormap_free_colors (gtk_widget_get_colormap (button), &old_color, 1); gtk_widget_destroy (dialog); } static void setup_color_cb (GtkWidget *button, gpointer userdata) { GtkWidget *dialog; GtkColorSelectionDialog *cdialog; GdkColor *color; color = &colors[GPOINTER_TO_INT (userdata)]; dialog = gtk_color_selection_dialog_new (_("Select color")); cdialog = GTK_COLOR_SELECTION_DIALOG (dialog); gtk_widget_hide (cdialog->help_button); g_signal_connect (G_OBJECT (cdialog->ok_button), "clicked", G_CALLBACK (setup_color_ok_cb), dialog); g_signal_connect (G_OBJECT (cdialog->cancel_button), "clicked", G_CALLBACK (gtkutil_destroy), dialog); g_object_set_data (G_OBJECT (cdialog->ok_button), "c", color); g_object_set_data (G_OBJECT (cdialog->ok_button), "b", button); gtk_widget_set_sensitive (cdialog->help_button, FALSE); gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (cdialog->colorsel), color); gtk_widget_show (dialog); } static void setup_create_color_button (GtkWidget *table, int num, int row, int col) { GtkWidget *but; GtkStyle *style; char buf[64]; if (num > 31) strcpy (buf, "<span size=\"x-small\"> </span>"); else /* 12345678901 23456789 01 23456789 */ sprintf (buf, "<span size=\"x-small\">%d</span>", num); but = gtk_button_new_with_label (" "); gtk_label_set_markup (GTK_LABEL (GTK_BIN (but)->child), buf); /* win32 build uses this to turn off themeing */ g_object_set_data (G_OBJECT (but), "hexchat-color", (gpointer)1); gtk_table_attach (GTK_TABLE (table), but, col, col+1, row, row+1, GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0); g_signal_connect (G_OBJECT (but), "clicked", G_CALLBACK (setup_color_cb), GINT_TO_POINTER (num)); style = gtk_style_new (); style->bg[GTK_STATE_NORMAL] = colors[num]; gtk_widget_set_style (but, style); g_object_unref (style); } static void setup_create_other_colorR (char *text, int num, int row, GtkWidget *tab) { GtkWidget *label; label = gtk_label_new (text); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_table_attach (GTK_TABLE (tab), label, 5, 9, row, row + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, LABEL_INDENT, 0); setup_create_color_button (tab, num, row, 9); } static void setup_create_other_color (char *text, int num, int row, GtkWidget *tab) { GtkWidget *label; label = gtk_label_new (text); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_table_attach (GTK_TABLE (tab), label, 2, 3, row, row + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, LABEL_INDENT, 0); setup_create_color_button (tab, num, row, 3); } static GtkWidget * setup_create_color_page (void) { GtkWidget *tab, *box, *label; int i; box = gtk_vbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER (box), 6); tab = gtk_table_new (9, 2, FALSE); gtk_container_set_border_width (GTK_CONTAINER (tab), 6); gtk_table_set_row_spacings (GTK_TABLE (tab), 2); gtk_table_set_col_spacings (GTK_TABLE (tab), 3); gtk_container_add (GTK_CONTAINER (box), tab); setup_create_header (tab, 0, N_("Text Colors")); label = gtk_label_new (_("mIRC colors:")); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_table_attach (GTK_TABLE (tab), label, 2, 3, 1, 2, GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, LABEL_INDENT, 0); for (i = 0; i < 16; i++) setup_create_color_button (tab, i, 1, i+3); label = gtk_label_new (_("Local colors:")); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_table_attach (GTK_TABLE (tab), label, 2, 3, 2, 3, GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, LABEL_INDENT, 0); for (i = 16; i < 32; i++) setup_create_color_button (tab, i, 2, (i+3) - 16); setup_create_other_color (_("Foreground:"), COL_FG, 3, tab); setup_create_other_colorR (_("Background:"), COL_BG, 3, tab); setup_create_header (tab, 5, N_("Selected Text")); setup_create_other_color (_("Foreground:"), COL_MARK_FG, 6, tab); setup_create_other_colorR (_("Background:"), COL_MARK_BG, 6, tab); setup_create_header (tab, 8, N_("Interface Colors")); setup_create_other_color (_("New data:"), COL_NEW_DATA, 9, tab); setup_create_other_colorR (_("Marker line:"), COL_MARKER, 9, tab); setup_create_other_color (_("New message:"), COL_NEW_MSG, 10, tab); setup_create_other_colorR (_("Away user:"), COL_AWAY, 10, tab); setup_create_other_color (_("Highlight:"), COL_HILIGHT, 11, tab); #ifdef HAVE_ISO_CODES /* Defined with static spelling */ setup_create_other_colorR (_("Spell checker:"), COL_SPELL, 11, tab); #endif setup_create_header (tab, 15, N_("Color Stripping")); /* label = gtk_label_new (_("Strip colors from:")); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_table_attach (GTK_TABLE (tab), label, 2, 3, 16, 17, GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, LABEL_INDENT, 0); */ for (i = 0; i < 3; i++) { setup_create_toggleL (tab, i + 16, &color_settings[i]); } return box; } /* === GLOBALS for sound GUI === */ static GtkWidget *sndfile_entry; static int ignore_changed = FALSE; extern struct text_event te[]; /* text.c */ extern char *sound_files[]; static void setup_snd_populate (GtkTreeView * treeview) { GtkListStore *store; GtkTreeIter iter; GtkTreeSelection *sel; GtkTreePath *path; int i; sel = gtk_tree_view_get_selection (treeview); store = (GtkListStore *)gtk_tree_view_get_model (treeview); for (i = NUM_XP-1; i >= 0; i--) { gtk_list_store_prepend (store, &iter); if (sound_files[i]) gtk_list_store_set (store, &iter, 0, te[i].name, 1, sound_files[i], 2, i, -1); else gtk_list_store_set (store, &iter, 0, te[i].name, 1, "", 2, i, -1); if (i == last_selected_row) { gtk_tree_selection_select_iter (sel, &iter); path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter); if (path) { gtk_tree_view_scroll_to_cell (treeview, path, NULL, TRUE, 0.5, 0.5); gtk_tree_view_set_cursor (treeview, path, NULL, FALSE); gtk_tree_path_free (path); } } } } static int setup_snd_get_selected (GtkTreeSelection *sel, GtkTreeIter *iter) { int n; GtkTreeModel *model; if (!gtk_tree_selection_get_selected (sel, &model, iter)) return -1; gtk_tree_model_get (model, iter, 2, &n, -1); return n; } static void setup_snd_row_cb (GtkTreeSelection *sel, gpointer user_data) { int n; GtkTreeIter iter; n = setup_snd_get_selected (sel, &iter); if (n == -1) return; last_selected_row = n; ignore_changed = TRUE; if (sound_files[n]) gtk_entry_set_text (GTK_ENTRY (sndfile_entry), sound_files[n]); else gtk_entry_set_text (GTK_ENTRY (sndfile_entry), ""); ignore_changed = FALSE; } static void setup_snd_add_columns (GtkTreeView * treeview) { GtkCellRenderer *renderer; GtkTreeModel *model; /* event column */ renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, _("Event"), renderer, "text", 0, NULL); /* file column */ renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, _("Sound file"), renderer, "text", 1, NULL); model = GTK_TREE_MODEL (gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT)); gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), model); g_object_unref (model); } static void setup_snd_filereq_cb (GtkWidget *entry, char *file) { if (file) { if (file[0]) { /* Use just the filename if the given sound file is in the default <config>/sounds directory. * We're comparing absolute paths so this won't work in portable mode which uses a relative path. */ if (!strcmp (g_path_get_dirname (file), g_build_filename (get_xdir (), HEXCHAT_SOUND_DIR, NULL))) { gtk_entry_set_text (GTK_ENTRY (entry), g_path_get_basename (file)); } else { gtk_entry_set_text (GTK_ENTRY (entry), file); } } } } static void setup_snd_browse_cb (GtkWidget *button, GtkEntry *entry) { char *sounds_dir = g_build_filename (get_xdir (), HEXCHAT_SOUND_DIR, NULL); gtkutil_file_req (_("Select a sound file"), setup_snd_filereq_cb, entry, sounds_dir, NULL, FRF_FILTERISINITIAL); g_free (sounds_dir); } static void setup_snd_play_cb (GtkWidget *button, GtkEntry *entry) { sound_play (entry->text, FALSE); } static void setup_snd_changed_cb (GtkEntry *ent, GtkTreeView *tree) { int n; GtkTreeIter iter; GtkListStore *store; GtkTreeSelection *sel; if (ignore_changed) return; sel = gtk_tree_view_get_selection (tree); n = setup_snd_get_selected (sel, &iter); if (n == -1) return; /* get the new sound file */ if (sound_files[n]) free (sound_files[n]); sound_files[n] = strdup (GTK_ENTRY (ent)->text); /* update the TreeView list */ store = (GtkListStore *)gtk_tree_view_get_model (tree); gtk_list_store_set (store, &iter, 1, sound_files[n], -1); gtk_widget_set_sensitive (cancel_button, FALSE); } static GtkWidget * setup_create_sound_page (void) { GtkWidget *vbox1; GtkWidget *vbox2; GtkWidget *scrolledwindow1; GtkWidget *sound_tree; GtkWidget *table1; GtkWidget *sound_label; GtkWidget *sound_browse; GtkWidget *sound_play; GtkTreeSelection *sel; vbox1 = gtk_vbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER (vbox1), 6); gtk_widget_show (vbox1); vbox2 = gtk_vbox_new (FALSE, 0); gtk_widget_show (vbox2); gtk_container_add (GTK_CONTAINER (vbox1), vbox2); scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (scrolledwindow1); gtk_container_add (GTK_CONTAINER (vbox2), scrolledwindow1); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_SHADOW_IN); sound_tree = gtk_tree_view_new (); sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (sound_tree)); gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE); setup_snd_add_columns (GTK_TREE_VIEW (sound_tree)); setup_snd_populate (GTK_TREE_VIEW (sound_tree)); g_signal_connect (G_OBJECT (sel), "changed", G_CALLBACK (setup_snd_row_cb), NULL); gtk_widget_show (sound_tree); gtk_container_add (GTK_CONTAINER (scrolledwindow1), sound_tree); gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (sound_tree), TRUE); table1 = gtk_table_new (2, 3, FALSE); gtk_widget_show (table1); gtk_box_pack_start (GTK_BOX (vbox2), table1, FALSE, TRUE, 8); gtk_table_set_row_spacings (GTK_TABLE (table1), 2); gtk_table_set_col_spacings (GTK_TABLE (table1), 4); sound_label = gtk_label_new_with_mnemonic (_("Sound file:")); gtk_widget_show (sound_label); gtk_table_attach (GTK_TABLE (table1), sound_label, 0, 1, 0, 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (sound_label), 0, 0.5); sndfile_entry = gtk_entry_new (); g_signal_connect (G_OBJECT (sndfile_entry), "changed", G_CALLBACK (setup_snd_changed_cb), sound_tree); gtk_widget_show (sndfile_entry); gtk_table_attach (GTK_TABLE (table1), sndfile_entry, 0, 1, 1, 2, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0); sound_browse = gtk_button_new_with_mnemonic (_("_Browse...")); g_signal_connect (G_OBJECT (sound_browse), "clicked", G_CALLBACK (setup_snd_browse_cb), sndfile_entry); gtk_widget_show (sound_browse); gtk_table_attach (GTK_TABLE (table1), sound_browse, 1, 2, 1, 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); #ifdef GTK_STOCK_MEDIA_PLAY sound_play = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY); #else sound_play = gtk_button_new_with_mnemonic (_("_Play")); #endif g_signal_connect (G_OBJECT (sound_play), "clicked", G_CALLBACK (setup_snd_play_cb), sndfile_entry); gtk_widget_show (sound_play); gtk_table_attach (GTK_TABLE (table1), sound_play, 2, 3, 1, 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); setup_snd_row_cb (sel, NULL); return vbox1; } static void setup_add_page (const char *title, GtkWidget *book, GtkWidget *tab) { GtkWidget *oframe, *frame, *label, *vvbox; char buf[128]; /* frame for whole page */ oframe = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (oframe), GTK_SHADOW_IN); vvbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (oframe), vvbox); /* border for the label */ frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT); gtk_box_pack_start (GTK_BOX (vvbox), frame, FALSE, TRUE, 0); /* label */ label = gtk_label_new (NULL); snprintf (buf, sizeof (buf), "<b><big>%s</big></b>", _(title)); gtk_label_set_markup (GTK_LABEL (label), buf); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_misc_set_padding (GTK_MISC (label), 2, 1); gtk_container_add (GTK_CONTAINER (frame), label); gtk_container_add (GTK_CONTAINER (vvbox), tab); gtk_notebook_append_page (GTK_NOTEBOOK (book), oframe, NULL); } static const char *const cata[] = { N_("Interface"), N_("Appearance"), N_("Input box"), N_("User list"), N_("Channel switcher"), N_("Colors"), NULL, N_("Chatting"), N_("General"), N_("Alerts"), N_("Sounds"), N_("Logging"), N_("Advanced"), NULL, N_("Network"), N_("Network setup"), N_("File transfers"), NULL, NULL }; static GtkWidget * setup_create_pages (GtkWidget *box) { GtkWidget *book; book = gtk_notebook_new (); setup_add_page (cata[1], book, setup_create_page (appearance_settings)); setup_add_page (cata[2], book, setup_create_page (inputbox_settings)); setup_add_page (cata[3], book, setup_create_page (userlist_settings)); setup_add_page (cata[4], book, setup_create_page (tabs_settings)); setup_add_page (cata[5], book, setup_create_color_page ()); setup_add_page (cata[8], book, setup_create_page (general_settings)); if (unity_mode ()) { setup_add_page (cata[9], book, setup_create_page (alert_settings_unity)); } else { setup_add_page (cata[9], book, setup_create_page (alert_settings)); } setup_add_page (cata[10], book, setup_create_sound_page ()); setup_add_page (cata[11], book, setup_create_page (logging_settings)); setup_add_page (cata[12], book, setup_create_page (advanced_settings)); setup_add_page (cata[14], book, setup_create_page (network_settings)); setup_add_page (cata[15], book, setup_create_page (filexfer_settings)); gtk_notebook_set_show_tabs (GTK_NOTEBOOK (book), FALSE); gtk_notebook_set_show_border (GTK_NOTEBOOK (book), FALSE); gtk_container_add (GTK_CONTAINER (box), book); return book; } static void setup_tree_cb (GtkTreeView *treeview, GtkWidget *book) { GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview); GtkTreeIter iter; GtkTreeModel *model; int page; if (gtk_tree_selection_get_selected (selection, &model, &iter)) { gtk_tree_model_get (model, &iter, 1, &page, -1); if (page != -1) { gtk_notebook_set_current_page (GTK_NOTEBOOK (book), page); last_selected_page = page; } } } static gboolean setup_tree_select_filter (GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean path_selected, gpointer data) { if (gtk_tree_path_get_depth (path) > 1) return TRUE; return FALSE; } static void setup_create_tree (GtkWidget *box, GtkWidget *book) { GtkWidget *tree; GtkWidget *frame; GtkTreeStore *model; GtkTreeIter iter; GtkTreeIter child_iter; GtkTreeIter *sel_iter = NULL; GtkCellRenderer *renderer; GtkTreeSelection *sel; int i, page; model = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_INT); i = 0; page = 0; do { gtk_tree_store_append (model, &iter, NULL); gtk_tree_store_set (model, &iter, 0, _(cata[i]), 1, -1, -1); i++; do { gtk_tree_store_append (model, &child_iter, &iter); gtk_tree_store_set (model, &child_iter, 0, _(cata[i]), 1, page, -1); if (page == last_selected_page) sel_iter = gtk_tree_iter_copy (&child_iter); page++; i++; } while (cata[i]); i++; } while (cata[i]); tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model)); g_object_unref (G_OBJECT (model)); sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree)); gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE); gtk_tree_selection_set_select_function (sel, setup_tree_select_filter, NULL, NULL); g_signal_connect (G_OBJECT (tree), "cursor_changed", G_CALLBACK (setup_tree_cb), book); renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1, _("Categories"), renderer, "text", 0, NULL); gtk_tree_view_expand_all (GTK_TREE_VIEW (tree)); frame = gtk_frame_new (NULL); gtk_container_add (GTK_CONTAINER (frame), tree); gtk_box_pack_start (GTK_BOX (box), frame, 0, 0, 0); gtk_box_reorder_child (GTK_BOX (box), frame, 0); if (sel_iter) { gtk_tree_selection_select_iter (sel, sel_iter); gtk_tree_iter_free (sel_iter); } } static void setup_apply_entry_style (GtkWidget *entry) { gtk_widget_modify_base (entry, GTK_STATE_NORMAL, &colors[COL_BG]); gtk_widget_modify_text (entry, GTK_STATE_NORMAL, &colors[COL_FG]); gtk_widget_modify_font (entry, input_style->font_desc); } static void setup_apply_to_sess (session_gui *gui) { #ifdef USE_GTKSPELL GtkSpell *spell; #endif mg_update_xtext (gui->xtext); if (prefs.hex_gui_ulist_style) gtk_widget_set_style (gui->user_tree, input_style); if (prefs.hex_gui_input_style) { extern char cursor_color_rc[]; char buf[256]; sprintf (buf, cursor_color_rc, (colors[COL_FG].red >> 8), (colors[COL_FG].green >> 8), (colors[COL_FG].blue >> 8)); gtk_rc_parse_string (buf); setup_apply_entry_style (gui->input_box); setup_apply_entry_style (gui->limit_entry); setup_apply_entry_style (gui->key_entry); setup_apply_entry_style (gui->topic_entry); } if (prefs.hex_gui_ulist_buttons) gtk_widget_show (gui->button_box); else gtk_widget_hide (gui->button_box); #ifdef USE_GTKSPELL spell = gtkspell_get_from_text_view (GTK_TEXT_VIEW (gui->input_box)); if (prefs.hex_gui_input_spell) { if (!spell) gtkspell_new_attach (GTK_TEXT_VIEW (gui->input_box), NULL, NULL); } else { if (spell) gtkspell_detach (spell); } #endif #ifdef USE_LIBSEXY sexy_spell_entry_set_checked ((SexySpellEntry *)gui->input_box, prefs.hex_gui_input_spell); #endif } static void unslash (char *dir) { if (dir[0]) { int len = strlen (dir) - 1; #ifdef WIN32 if (dir[len] == '/' || dir[len] == '\\') #else if (dir[len] == '/') #endif dir[len] = 0; } } void setup_apply_real (int new_pix, int do_ulist, int do_layout) { GSList *list; session *sess; int done_main = FALSE; /* remove trailing slashes */ unslash (prefs.hex_dcc_dir); unslash (prefs.hex_dcc_completed_dir); g_mkdir (prefs.hex_dcc_dir, 0700); g_mkdir (prefs.hex_dcc_completed_dir, 0700); if (new_pix) { if (channelwin_pix) g_object_unref (channelwin_pix); channelwin_pix = pixmap_load_from_file (prefs.hex_text_background); } input_style = create_input_style (input_style); list = sess_list; while (list) { sess = list->data; if (sess->gui->is_tab) { /* only apply to main tabwindow once */ if (!done_main) { done_main = TRUE; setup_apply_to_sess (sess->gui); } } else { setup_apply_to_sess (sess->gui); } log_open_or_close (sess); if (do_ulist) userlist_rehash (sess); list = list->next; } mg_apply_setup (); tray_apply_setup (); if (do_layout) menu_change_layout (); } static void setup_apply (struct hexchatprefs *pr) { #ifdef WIN32 PangoFontDescription *old_desc; PangoFontDescription *new_desc; char buffer[4 * FONTNAMELEN + 1]; time_t rawtime; #endif int new_pix = FALSE; int noapply = FALSE; int do_ulist = FALSE; int do_layout = FALSE; if (strcmp (pr->hex_text_background, prefs.hex_text_background) != 0) new_pix = TRUE; #define DIFF(a) (pr->a != prefs.a) #ifdef WIN32 if (DIFF (hex_gui_lang)) noapply = TRUE; #endif if (DIFF (hex_gui_compact)) noapply = TRUE; if (DIFF (hex_gui_input_icon)) noapply = TRUE; if (DIFF (hex_gui_input_nick)) noapply = TRUE; if (DIFF (hex_gui_lagometer)) noapply = TRUE; if (DIFF (hex_gui_tab_icons)) noapply = TRUE; if (DIFF (hex_gui_tab_server)) noapply = TRUE; if (DIFF (hex_gui_tab_small)) noapply = TRUE; if (DIFF (hex_gui_tab_sort)) noapply = TRUE; if (DIFF (hex_gui_tab_trunc)) noapply = TRUE; if (DIFF (hex_gui_throttlemeter)) noapply = TRUE; if (DIFF (hex_gui_ulist_count)) noapply = TRUE; if (DIFF (hex_gui_ulist_icons)) noapply = TRUE; if (DIFF (hex_gui_ulist_resizable)) noapply = TRUE; if (DIFF (hex_gui_ulist_show_hosts)) noapply = TRUE; if (DIFF (hex_gui_ulist_style)) noapply = TRUE; if (DIFF (hex_gui_tab_dots)) do_layout = TRUE; if (DIFF (hex_gui_tab_layout)) do_layout = TRUE; if (color_change || (DIFF (hex_gui_ulist_color)) || (DIFF (hex_away_size_max)) || (DIFF (hex_away_track))) do_ulist = TRUE; if ((pr->hex_gui_tab_pos == 5 || pr->hex_gui_tab_pos == 6) && pr->hex_gui_tab_layout == 2 && pr->hex_gui_tab_pos != prefs.hex_gui_tab_pos) fe_message (_("You cannot place the tree on the top or bottom!\n" "Please change to the <b>Tabs</b> layout in the <b>View</b>" " menu first."), FE_MSG_WARN | FE_MSG_MARKUP); memcpy (&prefs, pr, sizeof (prefs)); #ifdef WIN32 /* merge hex_font_main and hex_font_alternative into hex_font_normal */ old_desc = pango_font_description_from_string (prefs.hex_text_font_main); sprintf (buffer, "%s,%s", pango_font_description_get_family (old_desc), prefs.hex_text_font_alternative); new_desc = pango_font_description_from_string (buffer); pango_font_description_set_weight (new_desc, pango_font_description_get_weight (old_desc)); pango_font_description_set_style (new_desc, pango_font_description_get_style (old_desc)); pango_font_description_set_size (new_desc, pango_font_description_get_size (old_desc)); sprintf (prefs.hex_text_font, "%s", pango_font_description_to_string (new_desc)); /* FIXME this is not required after pango_font_description_from_string() g_free (old_desc); g_free (new_desc); */ /* workaround for strftime differences between POSIX and MSVC */ time (&rawtime); if (!strftime (buffer, sizeof (buffer), prefs.hex_stamp_text_format, localtime (&rawtime)) || !strftime (buffer, sizeof (buffer), prefs.hex_stamp_log_format, localtime (&rawtime))) { fe_message (_("Invalid time stamp format! See the strftime MSDN article for details."), FE_MSG_ERROR); } #endif if (prefs.hex_irc_real_name[0] == 0) { fe_message (_("The Real name option cannot be left blank. Falling back to \"realname\"."), FE_MSG_WARN); strcpy (prefs.hex_irc_real_name, "realname"); } setup_apply_real (new_pix, do_ulist, do_layout); if (noapply) fe_message (_("Some settings were changed that require a" " restart to take full effect."), FE_MSG_WARN); #ifndef WIN32 if (prefs.hex_dcc_auto_recv) { if (!strcmp ((char *)g_get_home_dir (), prefs.hex_dcc_dir)) { fe_message (_("*WARNING*\n" "Auto accepting DCC to your home directory\n" "can be dangerous and is exploitable. Eg:\n" "Someone could send you a .bash_profile"), FE_MSG_WARN); } } #endif } #if 0 static void setup_apply_cb (GtkWidget *but, GtkWidget *win) { /* setup_prefs -> hexchat */ setup_apply (&setup_prefs); } #endif static void setup_ok_cb (GtkWidget *but, GtkWidget *win) { gtk_widget_destroy (win); setup_apply (&setup_prefs); save_config (); palette_save (); } static GtkWidget * setup_window_open (void) { GtkWidget *wid, *win, *vbox, *hbox, *hbbox; win = gtkutil_window_new (_(DISPLAY_NAME": Preferences"), "prefs", 0, 0, 3); vbox = gtk_vbox_new (FALSE, 5); gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); gtk_container_add (GTK_CONTAINER (win), vbox); hbox = gtk_hbox_new (FALSE, 4); gtk_container_add (GTK_CONTAINER (vbox), hbox); setup_create_tree (hbox, setup_create_pages (hbox)); hbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); /* prepare the button box */ hbbox = gtk_hbutton_box_new (); gtk_box_set_spacing (GTK_BOX (hbbox), 4); gtk_box_pack_end (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0); /* standard buttons */ /* GNOME doesn't like apply */ #if 0 wid = gtk_button_new_from_stock (GTK_STOCK_APPLY); g_signal_connect (G_OBJECT (wid), "clicked", G_CALLBACK (setup_apply_cb), win); gtk_box_pack_start (GTK_BOX (hbbox), wid, FALSE, FALSE, 0); #endif cancel_button = wid = gtk_button_new_from_stock (GTK_STOCK_CANCEL); g_signal_connect (G_OBJECT (wid), "clicked", G_CALLBACK (gtkutil_destroy), win); gtk_box_pack_start (GTK_BOX (hbbox), wid, FALSE, FALSE, 0); wid = gtk_button_new_from_stock (GTK_STOCK_OK); g_signal_connect (G_OBJECT (wid), "clicked", G_CALLBACK (setup_ok_cb), win); gtk_box_pack_start (GTK_BOX (hbbox), wid, FALSE, FALSE, 0); wid = gtk_hseparator_new (); gtk_box_pack_end (GTK_BOX (vbox), wid, FALSE, FALSE, 0); gtk_widget_show_all (win); return win; } static void setup_close_cb (GtkWidget *win, GtkWidget **swin) { *swin = NULL; if (font_dialog) { gtk_widget_destroy (font_dialog); font_dialog = NULL; } } void setup_open (void) { static GtkWidget *setup_window = NULL; if (setup_window) { gtk_window_present (GTK_WINDOW (setup_window)); return; } memcpy (&setup_prefs, &prefs, sizeof (prefs)); color_change = FALSE; setup_window = setup_window_open (); g_signal_connect (G_OBJECT (setup_window), "destroy", G_CALLBACK (setup_close_cb), &setup_window); }