Changeset 3313 for trunk/jons-gtk2-gui
- Timestamp:
- 02/26/03 11:14:31 (6 years ago)
- Files:
-
- 1 modified
-
trunk/jons-gtk2-gui/src/log_window.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/jons-gtk2-gui/src/log_window.cpp
r3164 r3313 20 20 21 21 #include "licq_gtk.h" 22 #include "utilities.h" 22 23 23 24 #include "licq_icqd.h" … … 26 27 27 28 #include <gtk/gtk.h> 29 #include <iostream> 28 30 29 31 using namespace std; // for ofstream 30 32 31 struct network_window *nw ;33 struct network_window *nw = NULL; 32 34 gboolean nw_shown = FALSE; 33 35 gboolean hidden = FALSE; 34 36 35 void new_log_window()36 { 37 if(nw_shown) 38 {37 void 38 new_log_window() 39 { 40 if (nw_shown) 39 41 return; 40 } 41 42 if(hidden) 43 { 42 43 if (hidden) { 44 44 gtk_widget_show_all(nw->window); 45 45 hidden = FALSE; … … 84 84 85 85 gtk_table_attach(GTK_TABLE(table), box_text, 0, 2, 0, 2, 86 GtkAttachOptions(GTK_FILL | GTK_EXPAND),87 GtkAttachOptions(GTK_FILL | GTK_EXPAND),88 3, 3);86 GtkAttachOptions(GTK_FILL | GTK_EXPAND), 87 GtkAttachOptions(GTK_FILL | GTK_EXPAND), 88 3, 3); 89 89 90 90 /* The "OK" button */ … … 114 114 } 115 115 116 void log_window_show(GtkWidget *widget, gpointer data)117 { 118 if(nw == 0) 119 {116 void 117 log_window_show(GtkWidget *widget, gpointer data) 118 { 119 if (nw == NULL) { 120 120 new_log_window(); 121 121 log_window_show(0, 0); 122 122 } 123 else if(!nw_shown) 124 { 123 else if (!nw_shown) { 125 124 gtk_widget_show_all(nw->window); 126 125 GtkTextBuffer *tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(nw->text)); … … 132 131 hidden = FALSE; 133 132 } 134 135 } 136 137 voidlog_pipe_callback(gpointer data, gint pipe, GdkInputCondition condition)138 { 139 /* If the window doesn't exist, wait for it to exist */140 if (nw == 0)133 } 134 135 void 136 log_pipe_callback(gpointer data, gint pipe, GdkInputCondition condition) 137 { 138 /* If the window doesn't exist, create it */ 139 if (nw == NULL) 141 140 new_log_window(); 142 141 143 142 gchar buf[4]; 144 gchar *for_user; /* The text for the window */145 146 143 read(pipe, buf, 1); 147 144 148 145 /* Get the message */ 149 for_user = logg->NextLogMsg(); 150 151 /* Insert the message */ 152 GtkTextBuffer *tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(nw->text)); 153 GtkTextIter iter; 154 gtk_text_buffer_get_end_iter(tb, &iter); 155 gtk_text_buffer_insert(tb, &iter, for_user, -1); 156 157 /* Scroll down to the new bottom if not hidden */ 158 if (hidden == FALSE) 159 { 146 gchar *for_user = convert_to_utf8(logg->NextLogMsg()); 147 if (for_user != NULL) { 160 148 GtkTextBuffer *tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(nw->text)); 161 GtkTextIter end; 149 GtkTextIter iter, end; 150 151 // when we're over 510 lines, we'll cut off the first 500 162 152 gtk_text_buffer_get_end_iter(tb, &end); 163 GtkTextMark *tm = gtk_text_buffer_create_mark(tb, NULL, &end, TRUE); 164 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(nw->text), tm, 0, FALSE, 0, 0); 165 } 166 153 if (gtk_text_iter_get_line(&end) > 510) { 154 gtk_text_buffer_get_start_iter(tb, &iter); 155 gtk_text_buffer_get_iter_at_line(tb, &end, 500); 156 gtk_text_buffer_delete(tb, &iter, &end); 157 } 158 159 /* Insert the message */ 160 gtk_text_buffer_get_end_iter(tb, &iter); 161 gtk_text_buffer_insert(tb, &iter, for_user, -1); 162 163 /* Scroll down to the new bottom if not hidden */ 164 if (!hidden) { 165 gtk_text_buffer_get_end_iter(tb, &end); 166 GtkTextMark *tm = gtk_text_buffer_create_mark(tb, NULL, &end, TRUE); 167 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(nw->text), tm, 0, FALSE, 0, 0); 168 } 169 170 g_free(for_user); 171 } 172 167 173 /* Get rid of this message */ 168 174 logg->ClearLog(); … … 189 195 GtkWidget *fileSelect = (GtkWidget *)_fs; 190 196 191 const gchar *szFileName = gtk_file_selection_get_filename(GTK_FILE_SELECTION( 192 fileSelect)); 193 194 ofstream strmFileOut(szFileName, ios::out); 195 196 if (!strmFileOut.fail()) 197 { 198 strmFileOut << gtk_editable_get_chars(GTK_EDITABLE(nw->text), 0, -1); 199 } 197 const gchar *filename = 198 gtk_file_selection_get_filename(GTK_FILE_SELECTION(fileSelect)); 199 200 ofstream strmFileOut(filename, ios::out); 201 if (strmFileOut) { 202 GtkTextBuffer *tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(nw->text)); 203 GtkTextIter start, end; 204 gtk_text_buffer_get_start_iter(tb, &start); 205 gtk_text_buffer_get_end_iter(tb, &end); 206 strmFileOut << gtk_text_buffer_get_text(tb, &start, &end, FALSE); 207 } 208 else { 209 GtkWidget *dialog = 210 gtk_message_dialog_new(GTK_WINDOW(nw->window), 211 GTK_DIALOG_DESTROY_WITH_PARENT, 212 GTK_MESSAGE_ERROR, 213 GTK_BUTTONS_CLOSE, 214 "Couldn't save log to file: %s", 215 filename); 216 gtk_dialog_run(GTK_DIALOG(dialog)); 217 gtk_widget_destroy(dialog); 218 } 200 219 201 220 strmFileOut.close();
