00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <libheraia.h>
00026
00027 static gboolean load_heraia_glade_xml(heraia_window_t *main_window);
00028 static void heraia_ui_connect_signals(heraia_window_t *main_window);
00029 static void record_and_hide_about_box(heraia_window_t *main_window);
00030 static void refresh_file_labels(heraia_window_t *main_window);
00031 static void close_heraia(heraia_window_t *main_window);
00032
00036 void on_quit_activate( GtkWidget *widget, gpointer data )
00037 {
00038 heraia_window_t *main_window = (heraia_window_t *) data;
00039
00040 close_heraia(main_window);
00041 gtk_main_quit();
00042 }
00043
00047 void on_new_activate(GtkWidget *widget, gpointer data)
00048 {
00049 heraia_window_t *main_window = (heraia_window_t *) data;
00050
00051 log_message(main_window, G_LOG_LEVEL_WARNING, "Not implemented Yet (Please contribute !)");
00052 }
00053
00058 void on_preferences_activate(GtkWidget *widget, gpointer data)
00059 {
00060 heraia_window_t *main_window = (heraia_window_t *) data;
00061 GtkWidget *pref_window = NULL;
00062
00063 pref_window = heraia_get_widget(main_window->xmls->main, "main_preferences_window");
00064
00065 if (pref_window != NULL)
00066 {
00067 move_and_show_dialog_box(pref_window, main_window->win_prop->main_pref_window);
00068 }
00069
00070 }
00071
00075 void a_propos_activate(GtkWidget *widget, gpointer data)
00076 {
00077 heraia_window_t *main_window = (heraia_window_t *) data;
00078 GtkWidget *about_dialog = NULL;
00079
00080 about_dialog = heraia_get_widget(main_window->xmls->main, "about_dialog");
00081
00082 if (about_dialog != NULL)
00083 {
00084 if (GTK_MINOR_VERSION >= 12)
00085 {
00086 gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(about_dialog), PACKAGE_NAME);
00087 }
00088 if (GTK_MINOR_VERSION >= 6)
00089 {
00090 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about_dialog), PACKAGE_VERSION);
00091 }
00092
00093 move_and_show_dialog_box(about_dialog, main_window->win_prop->about_box);
00094 }
00095 }
00096
00100 void move_and_show_dialog_box(GtkWidget *dialog_box, window_prop_t *dialog_prop)
00101 {
00102 if (dialog_prop->displayed == FALSE)
00103 {
00104 gtk_window_move(GTK_WINDOW(dialog_box), dialog_prop->x, dialog_prop->y);
00105
00106 gtk_widget_show_all(dialog_box);
00107 dialog_prop->displayed = TRUE;
00108 }
00109 }
00110
00114 void record_dialog_box_position(GtkWidget *dialog_box, window_prop_t *dialog_prop)
00115 {
00116 gint x = 0;
00117 gint y = 0;
00118
00119 if (dialog_prop != NULL && dialog_prop->displayed == TRUE)
00120 {
00121 if (dialog_box != NULL)
00122 {
00123 gtk_window_get_position(GTK_WINDOW(dialog_box), &x, &y);
00124 dialog_prop->x = x;
00125 dialog_prop->y = y;
00126 }
00127 }
00128 }
00129
00130
00134 void record_all_dialog_box_positions(heraia_window_t *main_window)
00135 {
00136 GtkWidget *dialog_box = NULL;
00137
00138 if (main_window != NULL &&
00139 main_window->xmls != NULL &&
00140 main_window->xmls->main != NULL &&
00141 main_window->win_prop != NULL &&
00142 main_window->current_DW != NULL)
00143 {
00144
00145 dialog_box = main_window->current_DW->diw;
00146 record_dialog_box_position(dialog_box, main_window->win_prop->data_interpretor);
00147
00148
00149 dialog_box = heraia_get_widget (main_window->xmls->main, "about_dialog");
00150 record_dialog_box_position(dialog_box, main_window->win_prop->about_box);
00151
00152
00153 dialog_box = heraia_get_widget (main_window->xmls->main, "log_window");
00154 record_dialog_box_position(dialog_box, main_window->win_prop->log_box);
00155
00156
00157 dialog_box = heraia_get_widget (main_window->xmls->main, "main_window");
00158 record_dialog_box_position(dialog_box, main_window->win_prop->main_dialog);
00159
00160
00161 dialog_box = heraia_get_widget (main_window->xmls->main, "plugin_list_window");
00162 record_dialog_box_position(dialog_box, main_window->win_prop->plugin_list);
00163
00164
00165 dialog_box = heraia_get_widget (main_window->xmls->main, "list_data_types_window");
00166 record_dialog_box_position(dialog_box, main_window->win_prop->ldt);
00167
00168
00169 dialog_box = heraia_get_widget (main_window->xmls->main, "main_preferences_window");
00170 record_dialog_box_position(dialog_box, main_window->win_prop->main_pref_window);
00171 }
00172 }
00173
00174
00178 void record_and_hide_dialog_box(GtkWidget *dialog_box, window_prop_t *dialog_prop)
00179 {
00180
00181 if (dialog_prop->displayed == TRUE)
00182 {
00183 record_dialog_box_position(dialog_box, dialog_prop);
00184
00185 gtk_widget_hide(dialog_box);
00186 dialog_prop->displayed = FALSE;
00187 }
00188 }
00189
00190
00194 static void record_and_hide_about_box(heraia_window_t *main_window)
00195 {
00196 GtkWidget *about_dialog = NULL;
00197
00198 about_dialog = heraia_get_widget(main_window->xmls->main, "about_dialog");
00199
00200 if (about_dialog != NULL)
00201 {
00202 record_and_hide_dialog_box(about_dialog, main_window->win_prop->about_box);
00203 }
00204 }
00205
00206
00210 static void a_propos_response(GtkWidget *widget, gint response, gpointer data)
00211 {
00212 heraia_window_t *main_window = (heraia_window_t *) data;
00213 record_and_hide_about_box(main_window);
00214 }
00215
00216 static void a_propos_close(GtkWidget *widget, gpointer data)
00217 {
00218 heraia_window_t *main_window = (heraia_window_t *) data;
00219 record_and_hide_about_box(main_window);
00220 }
00221
00222 static gboolean a_propos_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
00223 {
00224 heraia_window_t *main_window = (heraia_window_t *) data;
00225 record_and_hide_about_box(main_window);
00226
00227 return TRUE;
00228 }
00229
00230
00234 void on_delete_activate( GtkWidget *widget, gpointer data )
00235 {
00236 heraia_window_t *main_window = (heraia_window_t *) data;
00237
00238 log_message(main_window, G_LOG_LEVEL_WARNING, "Not implemented Yet (Please contribute !)");
00239 }
00240
00244 void on_cut_activate( GtkWidget *widget, gpointer data )
00245 {
00246 heraia_window_t *main_window = (heraia_window_t *) data;
00247
00248 log_message(main_window, G_LOG_LEVEL_WARNING, "Not implemented Yet (Please contribute !)");
00249 }
00250
00254 void on_copy_activate( GtkWidget *widget, gpointer data )
00255 {
00256 heraia_window_t *main_window = (heraia_window_t *) data;
00257
00258 log_message(main_window, G_LOG_LEVEL_WARNING, "Not implemented Yet (Please contribute !)");
00259 }
00260
00261
00265 void on_paste_activate( GtkWidget *widget, gpointer data )
00266 {
00267 heraia_window_t *main_window = (heraia_window_t *) data;
00268
00269 log_message(main_window, G_LOG_LEVEL_WARNING, "Not implemented Yet (Please contribute !)");
00270 }
00271
00272
00278 static void refresh_file_labels(heraia_window_t *main_window)
00279 {
00280 GtkWidget *label = NULL;
00281 guint64 position = 0;
00282 gchar *text = NULL;
00283
00284 if (main_window != NULL)
00285 {
00286 if (main_window->current_DW != NULL && main_window->current_DW->current_hexwidget != NULL)
00287 {
00288 label = heraia_get_widget(main_window->xmls->main, "file_position_label");
00289 position = ghex_get_cursor_position(main_window->current_DW);
00290
00291
00292
00293 text = g_strdup_printf("<small>%'lld</small>", position + 1);
00294 gtk_label_set_markup(GTK_LABEL(label), text);
00295 g_free(text);
00296 }
00297 else
00298 {
00299 label = heraia_get_widget(main_window->xmls->main, "file_position_label");
00300 gtk_label_set_text(GTK_LABEL(label), "");
00301 }
00302 }
00303 }
00304
00305
00310 void refresh_event_handler(GtkWidget *widget, gpointer data)
00311 {
00312 heraia_window_t *main_window = (heraia_window_t *) data;
00313
00314 if (main_window != NULL)
00315 {
00316
00317 if (main_window->event == HERAIA_REFRESH_NOTHING)
00318 {
00319 main_window->event = HERAIA_REFRESH_CURSOR_MOVE;
00320 }
00321
00322 refresh_data_interpretor_window(widget, main_window);
00323 refresh_all_plugins(main_window);
00324 refresh_file_labels(main_window);
00325
00326 main_window->event = HERAIA_REFRESH_NOTHING;
00327 }
00328 }
00329
00330
00334 void on_open_activate(GtkWidget *widget, gpointer data)
00335 {
00336 heraia_window_t *main_window = (heraia_window_t *) data;
00337
00338 if (select_file_to_load(main_window) == TRUE)
00339 {
00340 load_file_to_analyse(main_window, main_window->filename);
00341 }
00342
00343 main_window->event = HERAIA_REFRESH_NEW_FILE;
00344 refresh_event_handler(main_window->current_DW->current_hexwidget, main_window);
00345 }
00346
00347
00352 void on_save_activate(GtkWidget *widget, gpointer data)
00353 {
00354 heraia_window_t *main_window = (heraia_window_t *) data;
00355 HERAIA_ERROR erreur = HERAIA_NOERR;
00356 gchar *filename = NULL;
00357
00358 if (main_window != NULL && main_window->current_doc != NULL)
00359 {
00360 erreur = heraia_hex_document_save(main_window);
00361
00362 if (erreur != HERAIA_NOERR)
00363 {
00364 filename = heraia_hex_document_get_filename(main_window->current_doc);
00365 log_message(main_window, G_LOG_LEVEL_ERROR, "Error while saving file %s !", filename);
00366 }
00367 }
00368 }
00369
00373 void on_save_as_activate( GtkWidget *widget, gpointer data )
00374 {
00375 heraia_window_t *main_window = (heraia_window_t *) data;
00376 HERAIA_ERROR erreur = HERAIA_NOERR;
00377 gchar *filename = NULL;
00378
00379 if (main_window != NULL && main_window->current_doc != NULL)
00380 {
00381 filename = select_a_file_to_save(main_window);
00382
00383 if (filename != NULL)
00384 {
00385 erreur = heraia_hex_document_save_as(main_window, filename);
00386 }
00387 else
00388 {
00389 erreur = HERAIA_CANCELLED;
00390 }
00391
00392 if (erreur != HERAIA_NOERR)
00393 {
00394 if (erreur == HERAIA_CANCELLED)
00395 {
00396 log_message(main_window, G_LOG_LEVEL_DEBUG, "Saving file as... : operation cancelled.");
00397 }
00398 else
00399 {
00400 log_message(main_window, G_LOG_LEVEL_ERROR, "Error while saving file as %s", main_window->current_doc->file_name);
00401 }
00402 }
00403 else
00404 {
00405
00406 update_main_window_name(main_window);
00407 set_notebook_tab_name(main_window);
00408 log_message(main_window, G_LOG_LEVEL_DEBUG, "File %s saved and now edited.", main_window->current_doc->file_name);
00409 }
00410 }
00411 }
00412
00417 void on_DIMenu_activate(GtkWidget *widget, gpointer data)
00418 {
00419
00420 heraia_window_t *main_window = (heraia_window_t *) data;
00421 data_window_t *dw = NULL;
00422 GtkNotebook *notebook = NULL;
00423
00424 if (main_window != NULL)
00425 {
00426 dw = main_window->current_DW;
00427
00428 if (dw != NULL)
00429 {
00430 if (dw->diw == NULL)
00431 {
00432 dw->diw = heraia_get_widget(main_window->xmls->main, "data_interpretor_window");
00433 }
00434
00435 if (dw->diw != NULL)
00436 {
00437
00438 notebook = GTK_NOTEBOOK(heraia_get_widget(main_window->xmls->main, "diw_notebook"));
00439
00440 if (main_window->win_prop->data_interpretor->displayed == FALSE)
00441 {
00442
00443 gtk_notebook_set_current_page(notebook, dw->tab_displayed);
00444
00445
00446 move_and_show_dialog_box(dw->diw, main_window->win_prop->data_interpretor);
00447
00448 refresh_data_interpretor_window(widget, data);
00449 }
00450 else
00451 {
00452
00453 dw->tab_displayed = gtk_notebook_get_current_page(notebook);
00454 record_and_hide_dialog_box(dw->diw, main_window->win_prop->data_interpretor);
00455 }
00456 }
00457 }
00458 }
00459 }
00460
00464 gboolean delete_main_window_event(GtkWidget *widget, GdkEvent *event, gpointer data)
00465 {
00466 heraia_window_t *main_window = (heraia_window_t *) data;
00467
00468 close_heraia(main_window);
00469 gtk_widget_destroy(widget);
00470 return TRUE;
00471 }
00472
00473
00477 gboolean delete_dt_window_event(GtkWidget *widget, GdkEvent *event, gpointer data)
00478 {
00479 heraia_window_t *main_window = (heraia_window_t *) data;
00480
00481 g_signal_emit_by_name(heraia_get_widget(main_window->xmls->main, "DIMenu"), "activate");
00482
00483 return TRUE;
00484 }
00485
00486 void destroy_dt_window(GtkWidget *widget, GdkEvent *event, gpointer data)
00487 {
00488 heraia_window_t *main_window = (heraia_window_t *) data;
00489
00490 g_signal_emit_by_name(heraia_get_widget(main_window->xmls->main, "DIMenu"), "activate");
00491 }
00492
00493
00494
00500 static gchar *make_absolute_path(gchar *filename)
00501 {
00502 gchar *current_dir = NULL;
00503 gchar *new_dir = NULL;
00504
00505 if (g_path_is_absolute(filename) == TRUE)
00506 {
00507
00508 return g_path_get_dirname(filename);
00509 }
00510 else
00511 {
00512 current_dir = g_get_current_dir();
00513 new_dir = g_path_get_dirname(filename);
00514
00515 if (g_chdir(new_dir) == 0)
00516 {
00517 g_free(new_dir);
00518 new_dir = g_get_current_dir();
00519 g_chdir(current_dir);
00520 g_free(current_dir);
00521
00522 return new_dir;
00523 }
00524 else
00525 {
00526 g_free(current_dir);
00527
00528 return NULL;
00529 }
00530 }
00531 }
00532
00533
00539 static void set_the_working_directory(GtkFileChooser *file_chooser, gchar *filename)
00540 {
00541 gchar *dirname = NULL;
00542
00543 dirname = make_absolute_path(filename);
00544
00545 if (dirname != NULL)
00546 {
00547 gtk_file_chooser_set_current_folder(file_chooser, dirname);
00548 g_free(dirname);
00549 }
00550 }
00551
00552
00558 gboolean select_file_to_load(heraia_window_t *main_window)
00559 {
00560 GtkWidget *parent = NULL;
00561 GtkFileChooser *file_chooser = NULL;
00562 gboolean success = FALSE;
00563 gchar *filename = NULL;
00564
00565 parent = heraia_get_widget(main_window->xmls->main, "main_window");
00566
00567 file_chooser = GTK_FILE_CHOOSER(gtk_file_chooser_dialog_new("Select a file to analyse",
00568 GTK_WINDOW(parent),
00569 GTK_FILE_CHOOSER_ACTION_OPEN,
00570 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
00571 GTK_STOCK_OPEN, GTK_RESPONSE_OK,
00572 NULL));
00573
00578 gtk_window_set_modal(GTK_WINDOW(file_chooser), TRUE);
00579 gtk_file_chooser_set_select_multiple(file_chooser, FALSE);
00580
00585 if (main_window->filename != NULL)
00586 {
00587 set_the_working_directory(file_chooser, main_window->filename);
00588 }
00589
00590 switch (gtk_dialog_run(GTK_DIALOG(file_chooser)))
00591 {
00592 case GTK_RESPONSE_OK:
00593 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_chooser));
00594 log_message(main_window, G_LOG_LEVEL_DEBUG, "filename selected : %s", filename);
00595
00596
00597 if (main_window->filename != NULL)
00598 {
00599 g_free(main_window->filename);
00600 }
00601
00602 main_window->filename = g_strdup_printf("%s", filename);
00603 success = TRUE;
00604 break;
00605 case GTK_RESPONSE_CANCEL:
00606 default:
00607 success = FALSE;
00608 break;
00609 }
00610
00611 g_free(filename);
00612 gtk_widget_destroy(GTK_WIDGET(file_chooser));
00613
00614 return success;
00615 }
00616
00621 gchar *select_a_file_to_save(heraia_window_t *main_window)
00622 {
00623 GtkWidget *parent = NULL;
00624 GtkFileChooser *fcd = NULL;
00625 gchar *filename = NULL;
00626
00627 parent = heraia_get_widget(main_window->xmls->main, "main_window");
00628
00629
00630 fcd = GTK_FILE_CHOOSER(gtk_file_chooser_dialog_new("Save As...",
00631 GTK_WINDOW(parent),
00632 GTK_FILE_CHOOSER_ACTION_SAVE,
00633 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
00634 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
00635 NULL));
00636
00637
00638 gtk_window_set_modal(GTK_WINDOW(fcd), TRUE);
00639 gtk_file_chooser_set_select_multiple(fcd, FALSE);
00640 gtk_file_chooser_set_do_overwrite_confirmation(fcd, TRUE);
00641
00642
00643 if (main_window->filename != NULL)
00644 {
00645 set_the_working_directory(fcd, main_window->filename);
00646 }
00647
00648 switch(gtk_dialog_run(GTK_DIALOG(fcd)))
00649 {
00650 case GTK_RESPONSE_OK:
00651
00652 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fcd));
00653 break;
00654 default:
00655 filename = NULL;
00656 break;
00657 }
00658
00659 gtk_widget_destroy(GTK_WIDGET(fcd));
00660
00661 return filename;
00662 }
00663
00664
00668 void update_main_window_name(heraia_window_t *main_window)
00669 {
00670 GtkWidget *widget = NULL;
00671 gchar *filename = NULL;
00672
00673 if (main_window != NULL && main_window->current_doc != NULL)
00674 {
00675 widget = heraia_get_widget(main_window->xmls->main, "main_window");
00676 filename = g_filename_display_basename(main_window->current_doc->file_name);
00677
00678 gtk_window_set_title(GTK_WINDOW(widget), filename);
00679 }
00680 }
00681
00686 void set_notebook_tab_name(heraia_window_t *main_window)
00687 {
00688 GtkWidget *notebook = NULL;
00689 GtkWidget *page = NULL;
00690 GtkWidget *label = NULL;
00691 gchar *filename = NULL;
00692 gint current = 0;
00693
00694 if (main_window != NULL && main_window->current_doc != NULL)
00695 {
00696 notebook = heraia_get_widget(main_window->xmls->main, "file_notebook");
00697 current = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
00698 page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), current);
00699 label = gtk_notebook_get_tab_label(GTK_NOTEBOOK(notebook), page);
00700 filename = g_filename_display_basename(main_window->current_doc->file_name);
00701 gtk_label_set_text(GTK_LABEL(label), filename);
00702
00703
00704 if (GTK_MINOR_VERSION >= 12)
00705 {
00706 gtk_widget_set_tooltip_text(label, g_filename_display_name(main_window->current_doc->file_name));
00707 }
00708 }
00709 }
00710
00711
00718 void init_heraia_interface(heraia_window_t *main_window)
00719 {
00720 GtkWidget *notebook = NULL;
00721
00722 if (main_window != NULL)
00723 {
00724
00725 init_window_states(main_window);
00726
00727
00728 notebook = heraia_get_widget(main_window->xmls->main, "file_notebook");
00729 gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
00730
00731 if (main_window->current_doc != NULL)
00732 {
00733 gtk_widget_show(notebook);
00734 }
00735 else
00736 {
00737 gtk_widget_hide(notebook);
00738 }
00739
00740 refresh_file_labels(main_window);
00741 }
00742 }
00743
00744
00752 static gboolean load_heraia_glade_xml(heraia_window_t *main_window)
00753 {
00754 gchar *filename = NULL;
00755
00756 if (main_window != NULL && main_window->xmls != NULL)
00757 {
00758
00759 filename = g_strdup_printf("heraia.glade");
00760 main_window->xmls->main = load_glade_xml_file(main_window->location_list, filename);
00761 g_free(filename);
00762
00769 if (main_window->xmls->main == NULL)
00770 return FALSE;
00771 else
00772 return TRUE;
00773 }
00774 else
00775 return FALSE;
00776 }
00777
00782 void connect_cursor_moved_signal(heraia_window_t *main_window)
00783 {
00784 g_signal_connect(G_OBJECT(main_window->current_DW->current_hexwidget), "cursor_moved",
00785 G_CALLBACK(refresh_event_handler), main_window);
00786 }
00787
00788
00792 static void heraia_ui_connect_signals(heraia_window_t *main_window)
00793 {
00794
00795
00796 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "DIMenu")), "activate",
00797 G_CALLBACK (on_DIMenu_activate), main_window);
00798
00799
00800 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "quit")), "activate",
00801 G_CALLBACK (on_quit_activate), main_window);
00802
00803
00804 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "new")), "activate",
00805 G_CALLBACK (on_new_activate), main_window);
00806
00807
00808 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "open")), "activate",
00809 G_CALLBACK (on_open_activate), main_window);
00810
00811
00812 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "save")), "activate",
00813 G_CALLBACK (on_save_activate), main_window);
00814
00815
00816 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "save_as")), "activate",
00817 G_CALLBACK (on_save_as_activate), main_window);
00818
00819
00820 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "preferences")), "activate",
00821 G_CALLBACK (on_preferences_activate), main_window);
00822
00823
00824 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "cut")), "activate",
00825 G_CALLBACK (on_cut_activate), main_window);
00826
00827
00828 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "copy")), "activate",
00829 G_CALLBACK (on_copy_activate), main_window);
00830
00831
00832 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "paste")), "activate",
00833 G_CALLBACK (on_paste_activate), main_window);
00834
00835
00836 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "delete")), "activate",
00837 G_CALLBACK (on_delete_activate), main_window);
00838
00839
00840
00841 g_signal_connect (G_OBJECT(heraia_get_widget(main_window->xmls->main, "a_propos")), "activate",
00842 G_CALLBACK(a_propos_activate), main_window);
00843
00844 g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "about_dialog")), "close",
00845 G_CALLBACK(a_propos_close), main_window);
00846
00847 g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "about_dialog")), "response",
00848 G_CALLBACK(a_propos_response), main_window);
00849
00850 g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "about_dialog")), "delete-event",
00851 G_CALLBACK(a_propos_delete), main_window);
00852
00853
00854
00855 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "main_window")), "delete_event",
00856 G_CALLBACK (delete_main_window_event), NULL);
00857
00858 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "main_window")), "destroy",
00859 G_CALLBACK (on_quit_activate), NULL);
00860
00861 }
00862
00870 int load_heraia_ui(heraia_window_t *main_window)
00871 {
00872 gboolean success = FALSE;
00873
00874
00875 success = load_heraia_glade_xml(main_window);
00876
00877 if (success == TRUE)
00878 {
00879
00880 if (main_window->debug == TRUE)
00881 {
00882 fprintf(stdout, "Connecting heraia_ui signals ");
00883 }
00884
00885 heraia_ui_connect_signals(main_window);
00886
00887 if (main_window->debug == TRUE)
00888 {
00889 fprintf(stdout, " [Done]\n");
00890 }
00891
00892 fprintf(stdout, "Loading heraia preference file ");
00893
00894 if (load_preference_file(main_window) != TRUE)
00895 {
00896 fprintf(stdout, " [FAILED]\n");
00897 }
00898 else
00899 {
00900 fprintf(stdout, " [Done]\n");
00901 fprintf(stdout, "Setting up preferences ");
00902 setup_preferences(main_window);
00903 fprintf(stdout, " [Done]\n");
00904 }
00905
00906
00907 if (main_window->debug == TRUE)
00908 {
00909 fprintf(stdout, "log window init interface ");
00910 }
00911
00912 log_window_init_interface(main_window);
00913
00914 if (main_window->debug == TRUE)
00915 {
00916 fprintf(stdout, " [Done]\n");
00917 }
00918
00919
00920 if (main_window->debug == TRUE)
00921 {
00922 fprintf(stdout, "preferences window init interface");
00923 }
00924
00925 main_pref_window_init_interface(main_window);
00926
00927 if (main_window->debug == TRUE)
00928 {
00929 fprintf(stdout, " [Done]\n");
00930 }
00931
00932
00933
00934 if (main_window->debug == TRUE)
00935 {
00936 fprintf(stdout, "data interpretor init interface ");
00937 }
00938
00939 data_interpretor_init_interface(main_window);
00940
00941 if (main_window->debug == TRUE)
00942 {
00943 fprintf(stdout, " [Done]\n");
00944 }
00945
00946
00947
00948 if (main_window->debug == TRUE)
00949 {
00950 fprintf(stdout, "list data types init interface ");
00951 }
00952
00953 list_data_types_init_interface(main_window);
00954
00955 if (main_window->debug == TRUE)
00956 {
00957 fprintf(stdout, " [Done]\n");
00958 }
00959
00960
00961
00962 if (main_window->debug == TRUE)
00963 {
00964 fprintf(stdout, "data type init interface ");
00965 }
00966
00967 data_type_init_interface(main_window);
00968
00969 if (main_window->debug == TRUE)
00970 {
00971 fprintf(stdout, " [Done]\n");
00972 }
00973 }
00974
00975 return success;
00976 }
00977
00978
00982 void add_text_to_textview(GtkTextView *textview, const char *format, ...)
00983 {
00984 va_list args;
00985 GtkTextBuffer *tb = NULL;
00986 GtkTextIter iEnd;
00987 gchar *display = NULL;
00988 GError *err = NULL;
00989
00990 va_start(args, format);
00991 display = g_locale_to_utf8(g_strdup_vprintf(format, args), -1, NULL, NULL, &err);
00992 va_end(args);
00993
00994 tb = GTK_TEXT_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)));
00995 gtk_text_buffer_get_end_iter(tb, &iEnd);
00996 gtk_text_buffer_insert(tb, &iEnd, display, -1);
00997 g_free(display);
00998 }
00999
01000
01004 void kill_text_from_textview(GtkTextView *textview)
01005 {
01006 GtkTextBuffer *tb = NULL;
01007 GtkTextIter iStart;
01008 GtkTextIter iEnd;
01009
01010 tb = GTK_TEXT_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)));
01011 gtk_text_buffer_get_start_iter(tb, &iStart);
01012 gtk_text_buffer_get_end_iter(tb, &iEnd);
01013 gtk_text_buffer_delete (tb, &iStart, &iEnd);
01014 }
01015
01016
01022 GtkWidget *gtk_radio_button_get_active(GSList *group)
01023 {
01024 GSList *tmp_slist = group;
01025
01026 while (tmp_slist)
01027 {
01028 if (GTK_TOGGLE_BUTTON (tmp_slist->data)->active)
01029 {
01030 return GTK_WIDGET (tmp_slist->data);
01031 }
01032 tmp_slist = tmp_slist->next;
01033 }
01034
01035 return NULL;
01036 }
01037
01038
01046 GtkWidget *gtk_radio_button_get_active_from_widget(GtkRadioButton *radio_group_member)
01047 {
01048 if (radio_group_member)
01049 {
01050 return gtk_radio_button_get_active(radio_group_member->group);
01051 }
01052 else
01053 {
01054 return NULL;
01055 }
01056 }
01057
01058
01062 gboolean is_cmi_checked(GtkWidget *check_menu_item)
01063 {
01064 return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(check_menu_item));
01065 }
01066
01067
01074 GtkWidget *heraia_get_widget(GladeXML *xml, gchar *widget_name)
01075 {
01079 if (xml != NULL && widget_name != NULL)
01080 {
01081 return glade_xml_get_widget(xml, widget_name);
01082 }
01083 else
01084 {
01085 return NULL;
01086 }
01087 }
01088
01089
01093 void destroy_a_single_widget(GtkWidget *widget)
01094 {
01095 if (widget != NULL)
01096 {
01097 gtk_widget_destroy(widget);
01098 }
01099 }
01100
01104 static void close_heraia(heraia_window_t *main_window)
01105 {
01106
01107
01108 record_all_dialog_box_positions(main_window);
01109
01110
01111 save_main_preferences(main_window);
01112 }
01113
01114
01115 static void init_one_cmi_window_state(GtkWidget *dialog_box, GtkWidget *cmi, window_prop_t *dialog_prop)
01116 {
01117 gboolean activated = FALSE;
01118
01119 if (dialog_box != NULL && cmi != NULL && dialog_prop != NULL)
01120 {
01121 activated = dialog_prop->displayed;
01122 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(cmi), activated);
01123 if (activated == TRUE)
01124 {
01125
01126 gtk_window_move(GTK_WINDOW(dialog_box), dialog_prop->x, dialog_prop->y);
01127 gtk_widget_show_all(dialog_box);
01128 }
01129 }
01130 }
01131
01132
01136 void init_window_states(heraia_window_t *main_window)
01137 {
01138 GtkWidget *cmi = NULL;
01139 GtkWidget *dialog_box = NULL;
01140
01141 if (main_window != NULL && main_window->xmls != NULL && main_window->xmls->main != NULL)
01142 {
01143 if (main_window->win_prop)
01144 {
01145
01146 cmi = heraia_get_widget(main_window->xmls->main, "mw_cmi_show_logw");
01147 dialog_box = heraia_get_widget(main_window->xmls->main, "log_window");
01148 init_one_cmi_window_state(dialog_box, cmi, main_window->win_prop->log_box);
01149
01150
01151 cmi = heraia_get_widget(main_window->xmls->main, "DIMenu");
01152
01153 if (main_window->win_prop->data_interpretor->displayed == TRUE)
01154 {
01155 main_window->win_prop->data_interpretor->displayed = FALSE;
01156 g_signal_emit_by_name(heraia_get_widget(main_window->xmls->main, "DIMenu"), "activate");
01157 }
01158
01159
01160 cmi = heraia_get_widget(main_window->xmls->main, "ldt_menu");
01161 dialog_box = heraia_get_widget(main_window->xmls->main, "list_data_types_window");
01162 init_one_cmi_window_state(dialog_box, cmi, main_window->win_prop->ldt);
01163
01164
01165 cmi = heraia_get_widget(main_window->xmls->main, "mw_cmi_plugin_list");
01166 dialog_box = heraia_get_widget(main_window->xmls->main, "plugin_list_window");
01167 init_one_cmi_window_state(dialog_box, cmi, main_window->win_prop->plugin_list);
01168
01169
01170 dialog_box = heraia_get_widget(main_window->xmls->main, "main_preferences_window");
01171 if (main_window->win_prop->main_pref_window->displayed == TRUE)
01172 {
01173
01174 gtk_window_move(GTK_WINDOW(dialog_box), main_window->win_prop->main_pref_window->x, main_window->win_prop->main_pref_window->y);
01175 gtk_widget_show_all(dialog_box);
01176 }
01177
01178
01179 dialog_box = heraia_get_widget(main_window->xmls->main, "main_window");
01180 if (main_window->win_prop->main_dialog->displayed == TRUE)
01181 {
01182 gtk_window_move(GTK_WINDOW(dialog_box), main_window->win_prop->main_dialog->x, main_window->win_prop->main_dialog->y);
01183
01184 }
01185 }
01186 }
01187 }