37 #include "messages_window.h"
40 static const char *get_current_system_time()
42 time_t cur_time = time(NULL);
43 const struct tm *tm = localtime(&cur_time);
45 static char time_str[128] = {
'\0' };
46 strftime(time_str,
sizeof(time_str),
"(%H:%M:%S) ", tm);
59 GtkTextTag *gray_tag = gtk_text_tag_table_lookup(gui->mess_hist_tag_table,
"gray_bold");
62 gtk_text_buffer_get_end_iter(ui->gui->mess_hist_buffer, &iter);
63 const char *current_system_time = get_current_system_time();
64 gtk_text_buffer_insert_with_tags(ui->gui->mess_hist_buffer,
65 &iter, current_system_time, -1, gray_tag, NULL);
67 gtk_text_buffer_insert(ui->gui->mess_hist_buffer, &iter, message, -1);
68 gtk_text_buffer_insert(ui->gui->mess_hist_buffer, &iter,
"\n", -1);
70 gtk_text_iter_set_line_offset(&iter, 0);
72 GtkTextMark *mark = gtk_text_buffer_get_mark(ui->gui->mess_hist_buffer,
"end");
73 gtk_text_buffer_move_mark(ui->gui->mess_hist_buffer, mark, &iter);
74 gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(ui->gui->mess_hist_view), mark);
79 static void debug_check_event(GtkToggleButton *debug_toggle,
ui_state *ui)
81 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(debug_toggle)))
83 ui->infos->debug_is_active = TRUE;
87 ui->infos->debug_is_active = FALSE;
91 static void clear_messages_event(GtkWidget *widget,
ui_state *ui)
93 GtkTextIter start_iter;
94 gtk_text_buffer_get_start_iter(ui->gui->mess_hist_buffer, &start_iter);
96 gtk_text_buffer_get_end_iter(ui->gui->mess_hist_buffer, &end_iter);
97 gtk_text_buffer_delete(ui->gui->mess_hist_buffer, &start_iter, &end_iter);
101 static void add_mess_hist_tags(GtkTextTagTable *mess_hist_tag_table)
103 GtkTextTag *tag = gtk_text_tag_new(
"gray_bold");
105 GValue fg_val = { 0 };
106 g_value_init(&fg_val, G_TYPE_STRING);
107 g_value_set_static_string(&fg_val,
"gray");
108 g_object_set_property(G_OBJECT(tag),
"foreground", &fg_val);
110 gtk_text_tag_table_add(mess_hist_tag_table, tag);
114 static GtkWidget *create_text_component(
ui_state *ui)
116 GtkWidget *vbox = wh_vbox_new();
117 gtk_container_set_border_width(GTK_CONTAINER(vbox), 3);
120 GtkTextTagTable *mess_hist_tag_table = gtk_text_tag_table_new();
121 ui->gui->mess_hist_tag_table = mess_hist_tag_table;
122 add_mess_hist_tags(mess_hist_tag_table);
124 GtkTextBuffer *mess_hist_buffer = gtk_text_buffer_new(mess_hist_tag_table);
125 ui->gui->mess_hist_buffer = mess_hist_buffer;
128 gtk_text_buffer_get_end_iter(ui->gui->mess_hist_buffer, &iter);
129 gtk_text_buffer_create_mark(ui->gui->mess_hist_buffer,
"end", &iter, TRUE);
130 GtkWidget *mess_hist_view = gtk_text_view_new_with_buffer(ui->gui->mess_hist_buffer);
131 ui->gui->mess_hist_view = mess_hist_view;
133 gtk_text_view_set_editable(GTK_TEXT_VIEW(mess_hist_view), FALSE);
134 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(mess_hist_view), FALSE);
135 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(mess_hist_view), 5);
137 GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
138 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_NONE);
139 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
140 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
142 gtk_container_add(GTK_CONTAINER(scrolled_window), mess_hist_view);
144 GtkWidget *hbox = wh_hbox_new();
147 GtkWidget *debug_check_button =
148 gtk_check_button_new_with_mnemonic(_(
"Enable _debug messages"));
149 g_signal_connect(G_OBJECT(debug_check_button),
"toggled", G_CALLBACK(debug_check_event), ui);
150 gtk_box_pack_start(GTK_BOX(hbox), debug_check_button, FALSE, FALSE, 0);
154 g_signal_connect(G_OBJECT(clear_button),
"clicked", G_CALLBACK(clear_messages_event), ui);
155 gtk_box_pack_end(GTK_BOX(hbox), clear_button, FALSE, FALSE, 0);
157 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
158 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 3);
166 GtkWidget *text_component = create_text_component(ui);
167 ui->gui->mess_history_window =
168 wh_create_window_with_close_button(_(
"Messages history"), 550, 300,
169 GTK_WIN_POS_CENTER, GTK_WINDOW(ui->gui->window),
170 text_component, NULL);