mp3splt-gtk 0.9.3.1519
Loading...
Searching...
No Matches
messages_window.c
Go to the documentation of this file.
1/**********************************************************
2 *
3 * mp3splt-gtk -- utility based on mp3splt,
4 * for mp3/ogg splitting without decoding
5 *
6 * Copyright: (C) 2005-2014 Alexandru Munteanu
7 * Contact: m@ioalex.net
8 *
9 * http://mp3splt.sourceforge.net/
10 *
11 *********************************************************/
12
13/**********************************************************
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 * USA.
29 *
30 *********************************************************/
31
32/*!********************************************************
33 * \file
34 * The messages history dialog
35 *********************************************************/
36
37#include "messages_window.h"
38
40static const char *get_current_system_time()
41{
42 time_t cur_time = time(NULL);
43 const struct tm *tm = localtime(&cur_time);
44
45 static char time_str[128] = { '\0' };
46 strftime(time_str, sizeof(time_str), "(%H:%M:%S) ", tm);
47
48 return time_str;
49}
50
52void put_message_in_history(const gchar *message, splt_message_type mess_type, ui_state *ui)
53{
54 gui_state *gui = ui->gui;
55
56 if (mess_type == SPLT_MESSAGE_INFO || mess_type == SPLT_MESSAGE_WARNING ||
57 (mess_type == SPLT_MESSAGE_DEBUG && ui->infos->debug_is_active))
58 {
59 GtkTextTag *gray_tag = gtk_text_tag_table_lookup(gui->mess_hist_tag_table, "gray_bold");
60
61 GtkTextIter iter;
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);
66
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);
69
70 gtk_text_iter_set_line_offset(&iter, 0);
71
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);
75 }
76}
77
79static void debug_check_event(GtkToggleButton *debug_toggle, ui_state *ui)
80{
81 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(debug_toggle)))
82 {
83 ui->infos->debug_is_active = TRUE;
84 return;
85 }
86
87 ui->infos->debug_is_active = FALSE;
88}
89
91static void clear_messages_event(GtkWidget *widget, ui_state *ui)
92{
93 GtkTextIter start_iter;
94 gtk_text_buffer_get_start_iter(ui->gui->mess_hist_buffer, &start_iter);
95 GtkTextIter end_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);
98}
99
101static void add_mess_hist_tags(GtkTextTagTable *mess_hist_tag_table)
102{
103 GtkTextTag *tag = gtk_text_tag_new("gray_bold");
104
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);
109
110 gtk_text_tag_table_add(mess_hist_tag_table, tag);
111}
112
114static GtkWidget *create_text_component(ui_state *ui)
115{
116 GtkWidget *vbox = wh_vbox_new();
117 gtk_container_set_border_width(GTK_CONTAINER(vbox), 3);
118
119 //text view
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);
123
124 GtkTextBuffer *mess_hist_buffer = gtk_text_buffer_new(mess_hist_tag_table);
125 ui->gui->mess_hist_buffer = mess_hist_buffer;
126
127 GtkTextIter iter;
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;
132
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);
136
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);
141
142 gtk_container_add(GTK_CONTAINER(scrolled_window), mess_hist_view);
143
144 GtkWidget *hbox = wh_hbox_new();
145
146 //debug option
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);
151
152 //clear button
153 GtkWidget *clear_button = wh_create_cool_button("edit-clear", _("C_lear"), FALSE);
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);
156
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);
159
160 return vbox;
161}
162
165{
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);
171}
172
void create_mess_history_window(ui_state *ui)
Create the message history dialog.
void put_message_in_history(const gchar *message, splt_message_type mess_type, ui_state *ui)
Record this message in the message history.