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
00026
00027
00028
00029
00030
00031 #include <libheraia.h>
00032
00033 static void set_a_propos_properties(GtkWidget *about_dialog);
00034 static gboolean load_heraia_glade_xml(heraia_window_t *main_window);
00035 static void heraia_ui_connect_signals(heraia_window_t *main_window);
00036 static void record_and_hide_about_box(heraia_window_t *main_window);
00037 static void close_heraia(heraia_window_t *main_window);
00038
00039
00040
00041
00042
00043
00044
00045 void on_quit_activate(GtkWidget *widget, gpointer data)
00046 {
00047 heraia_window_t *main_window = (heraia_window_t *) data;
00048
00049 close_heraia(main_window);
00050 gtk_main_quit();
00051 }
00052
00053
00054
00055
00056
00057
00058
00059 void on_new_activate(GtkWidget *widget, gpointer data)
00060 {
00061 heraia_window_t *main_window = (heraia_window_t *) data;
00062
00063 log_message(main_window, G_LOG_LEVEL_WARNING, "Not implemented Yet (Please contribute !)");
00064 }
00065
00066
00067
00068
00069
00070
00071
00072
00073 void on_preferences_activate(GtkWidget *widget, gpointer data)
00074 {
00075 heraia_window_t *main_window = (heraia_window_t *) data;
00076 GtkWidget *pref_window = NULL;
00077
00078 pref_window = heraia_get_widget(main_window->xmls->main, "main_preferences_window");
00079
00080 if (pref_window != NULL)
00081 {
00082 move_and_show_dialog_box(pref_window, main_window->win_prop->main_pref_window);
00083 }
00084
00085 }
00086
00087
00088
00089
00090
00091
00092 static void set_a_propos_properties(GtkWidget *about_dialog)
00093 {
00094
00095 if (about_dialog != NULL)
00096 {
00097 if (GTK_MINOR_VERSION >= 12)
00098 {
00099 gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(about_dialog), PACKAGE_NAME);
00100 }
00101 if (GTK_MINOR_VERSION >= 6)
00102 {
00103 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about_dialog), PACKAGE_VERSION);
00104 }
00105 }
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115 void a_propos_activate(GtkWidget *widget, gpointer data)
00116 {
00117 heraia_window_t *main_window = (heraia_window_t *) data;
00118 GtkWidget *about_dialog = NULL;
00119
00120 about_dialog = heraia_get_widget(main_window->xmls->main, "about_dialog");
00121
00122 if (about_dialog != NULL)
00123 {
00124 set_a_propos_properties(about_dialog);
00125
00126 move_and_show_dialog_box(about_dialog, main_window->win_prop->about_box);
00127 }
00128 }
00129
00130
00131
00132
00133
00134
00135
00136 void move_and_show_dialog_box(GtkWidget *dialog_box, window_prop_t *dialog_prop)
00137 {
00138 if (dialog_prop->displayed == FALSE)
00139 {
00140 gtk_window_move(GTK_WINDOW(dialog_box), dialog_prop->x, dialog_prop->y);
00141 gtk_window_resize(GTK_WINDOW(dialog_box), dialog_prop->width, dialog_prop->height);
00142 gtk_widget_show_all(dialog_box);
00143 dialog_prop->displayed = TRUE;
00144 }
00145 }
00146
00147
00148
00149
00150
00151
00152
00153 void record_dialog_box_position(GtkWidget *dialog_box, window_prop_t *dialog_prop)
00154 {
00155 gint x = 0;
00156 gint y = 0;
00157 gint width = WPT_DEFAULT_WIDTH;
00158 gint height = WPT_DEFAULT_HEIGHT;
00159
00160 if (dialog_prop != NULL && dialog_prop->displayed == TRUE)
00161 {
00162 if (dialog_box != NULL)
00163 {
00164 gtk_window_get_position(GTK_WINDOW(dialog_box), &x, &y);
00165 gtk_window_get_size(GTK_WINDOW(dialog_box), &width, &height);
00166 dialog_prop->x = x;
00167 dialog_prop->y = y;
00168 dialog_prop->width = width;
00169 dialog_prop->height = height;
00170 }
00171 }
00172 }
00173
00174
00175
00176
00177
00178
00179
00180 void record_all_dialog_box_positions(heraia_window_t *main_window)
00181 {
00182 GtkWidget *dialog_box = NULL;
00183
00184 if (main_window != NULL &&
00185 main_window->xmls != NULL &&
00186 main_window->xmls->main != NULL &&
00187 main_window->win_prop != NULL &&
00188 main_window->current_DW != NULL)
00189 {
00190
00191 dialog_box = main_window->current_DW->diw;
00192 record_dialog_box_position(dialog_box, main_window->win_prop->data_interpretor);
00193
00194
00195 dialog_box = heraia_get_widget (main_window->xmls->main, "about_dialog");
00196 record_dialog_box_position(dialog_box, main_window->win_prop->about_box);
00197
00198
00199 dialog_box = heraia_get_widget (main_window->xmls->main, "log_window");
00200 record_dialog_box_position(dialog_box, main_window->win_prop->log_box);
00201
00202
00203 dialog_box = heraia_get_widget (main_window->xmls->main, "main_window");
00204 record_dialog_box_position(dialog_box, main_window->win_prop->main_dialog);
00205
00206
00207 dialog_box = heraia_get_widget (main_window->xmls->main, "plugin_list_window");
00208 record_dialog_box_position(dialog_box, main_window->win_prop->plugin_list);
00209
00210
00211 dialog_box = heraia_get_widget (main_window->xmls->main, "list_data_types_window");
00212 record_dialog_box_position(dialog_box, main_window->win_prop->ldt);
00213
00214
00215 dialog_box = heraia_get_widget (main_window->xmls->main, "main_preferences_window");
00216 record_dialog_box_position(dialog_box, main_window->win_prop->main_pref_window);
00217 }
00218 }
00219
00220
00221
00222
00223
00224
00225
00226
00227 void record_and_hide_dialog_box(GtkWidget *dialog_box, window_prop_t *dialog_prop)
00228 {
00229
00230 if (dialog_prop->displayed == TRUE)
00231 {
00232 record_dialog_box_position(dialog_box, dialog_prop);
00233
00234 gtk_widget_hide(dialog_box);
00235 dialog_prop->displayed = FALSE;
00236 }
00237 }
00238
00239
00240
00241
00242
00243
00244
00245 static void record_and_hide_about_box(heraia_window_t *main_window)
00246 {
00247 GtkWidget *about_dialog = NULL;
00248
00249 about_dialog = heraia_get_widget(main_window->xmls->main, "about_dialog");
00250
00251 if (about_dialog != NULL)
00252 {
00253 record_and_hide_dialog_box(about_dialog, main_window->win_prop->about_box);
00254 }
00255 }
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 static void a_propos_response(GtkWidget *widget, gint response, gpointer data)
00266 {
00267 heraia_window_t *main_window = (heraia_window_t *) data;
00268 record_and_hide_about_box(main_window);
00269 }
00270
00271
00272
00273
00274
00275
00276
00277 static void a_propos_close(GtkWidget *widget, gpointer data)
00278 {
00279 heraia_window_t *main_window = (heraia_window_t *) data;
00280 record_and_hide_about_box(main_window);
00281 }
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 static gboolean a_propos_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
00294 {
00295 heraia_window_t *main_window = (heraia_window_t *) data;
00296 record_and_hide_about_box(main_window);
00297
00298 return TRUE;
00299 }
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 void on_delete_activate(GtkWidget *widget, gpointer data)
00311 {
00312 heraia_window_t *main_window = (heraia_window_t *) data;
00313
00314 log_message(main_window, G_LOG_LEVEL_WARNING, "Not implemented Yet (Please contribute !)");
00315 }
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325 void on_cut_activate(GtkWidget *widget, gpointer data)
00326 {
00327 heraia_window_t *main_window = (heraia_window_t *) data;
00328
00329 log_message(main_window, G_LOG_LEVEL_WARNING, "Not implemented Yet (Please contribute !)");
00330 }
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 void on_copy_activate(GtkWidget *widget, gpointer data)
00341 {
00342 heraia_window_t *main_window = (heraia_window_t *) data;
00343
00344 log_message(main_window, G_LOG_LEVEL_WARNING, "Not implemented Yet (Please contribute !)");
00345 }
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356 void on_paste_activate(GtkWidget *widget, gpointer data)
00357 {
00358 heraia_window_t *main_window = (heraia_window_t *) data;
00359
00360 log_message(main_window, G_LOG_LEVEL_WARNING, "Not implemented Yet (Please contribute !)");
00361 }
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 void refresh_file_labels(heraia_window_t *main_window)
00372 {
00373 GtkWidget *label = NULL;
00374 guint64 position = 0;
00375 gchar *text = NULL;
00376
00377 if (main_window != NULL)
00378 {
00379 if (main_window->current_DW != NULL && main_window->current_DW->current_hexwidget != NULL)
00380 {
00381 label = heraia_get_widget(main_window->xmls->main, "file_position_label");
00382 position = ghex_get_cursor_position(main_window->current_DW);
00383
00384
00385
00386
00387 if (is_toggle_button_activated(main_window->xmls->main, "mp_thousand_bt") == TRUE)
00388 {
00389 text = g_strdup_printf("<small>%'lld</small>", position + 1);
00390 }
00391 else
00392 {
00393 text = g_strdup_printf("<small>%lld</small>", position + 1);
00394 }
00395 gtk_label_set_markup(GTK_LABEL(label), text);
00396 g_free(text);
00397 }
00398 else
00399 {
00400 label = heraia_get_widget(main_window->xmls->main, "file_position_label");
00401 gtk_label_set_text(GTK_LABEL(label), "");
00402 }
00403 }
00404 }
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417 void refresh_event_handler(GtkWidget *widget, gpointer data)
00418 {
00419 heraia_window_t *main_window = (heraia_window_t *) data;
00420
00421 if (main_window != NULL)
00422 {
00423
00424 if (main_window->event == HERAIA_REFRESH_NOTHING)
00425 {
00426 main_window->event = HERAIA_REFRESH_CURSOR_MOVE;
00427 }
00428
00429 refresh_data_interpretor_window(widget, main_window);
00430 refresh_all_plugins(main_window);
00431 refresh_file_labels(main_window);
00432
00433 main_window->event = HERAIA_REFRESH_NOTHING;
00434 }
00435 }
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447 void on_open_activate(GtkWidget *widget, gpointer data)
00448 {
00449 heraia_window_t *main_window = (heraia_window_t *) data;
00450
00451 if (select_file_to_load(main_window) == TRUE)
00452 {
00453 load_file_to_analyse(main_window, main_window->filename);
00454
00455
00456 main_window->event = HERAIA_REFRESH_NEW_FILE;
00457 refresh_event_handler(main_window->current_DW->current_hexwidget, main_window);
00458 }
00459 }
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470 void on_save_activate(GtkWidget *widget, gpointer data)
00471 {
00472 heraia_window_t *main_window = (heraia_window_t *) data;
00473 HERAIA_ERROR erreur = HERAIA_NOERR;
00474 gchar *filename = NULL;
00475
00476 if (main_window != NULL && main_window->current_doc != NULL)
00477 {
00478 erreur = heraia_hex_document_save(main_window);
00479
00480 if (erreur != HERAIA_NOERR)
00481 {
00482 filename = heraia_hex_document_get_filename(main_window->current_doc);
00483 log_message(main_window, G_LOG_LEVEL_ERROR, "Error while saving file %s !", filename);
00484 }
00485 }
00486 }
00487
00488
00489
00490
00491
00492
00493
00494 void on_save_as_activate(GtkWidget *widget, gpointer data)
00495 {
00496 heraia_window_t *main_window = (heraia_window_t *) data;
00497 HERAIA_ERROR erreur = HERAIA_NOERR;
00498 gchar *filename = NULL;
00499
00500 if (main_window != NULL && main_window->current_doc != NULL)
00501 {
00502 filename = select_a_file_to_save(main_window);
00503
00504 if (filename != NULL)
00505 {
00506 erreur = heraia_hex_document_save_as(main_window, filename);
00507 }
00508 else
00509 {
00510 erreur = HERAIA_CANCELLED;
00511 }
00512
00513 if (erreur != HERAIA_NOERR)
00514 {
00515 if (erreur == HERAIA_CANCELLED)
00516 {
00517 log_message(main_window, G_LOG_LEVEL_DEBUG, "Saving file as... : operation cancelled.");
00518 }
00519 else
00520 {
00521 log_message(main_window, G_LOG_LEVEL_ERROR, "Error while saving file as %s", main_window->current_doc->file_name);
00522 }
00523 }
00524 else
00525 {
00526
00527 update_main_window_name(main_window);
00528 set_notebook_tab_name(main_window);
00529 log_message(main_window, G_LOG_LEVEL_DEBUG, "File %s saved and now edited.", main_window->current_doc->file_name);
00530 }
00531 }
00532 }
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542 void on_DIMenu_activate(GtkWidget *widget, gpointer data)
00543 {
00544
00545 heraia_window_t *main_window = (heraia_window_t *) data;
00546 data_window_t *dw = NULL;
00547 GtkNotebook *notebook = NULL;
00548
00549 if (main_window != NULL)
00550 {
00551 dw = main_window->current_DW;
00552
00553 if (dw != NULL)
00554 {
00555 if (dw->diw == NULL)
00556 {
00557 dw->diw = heraia_get_widget(main_window->xmls->main, "data_interpretor_window");
00558 }
00559
00560 if (dw->diw != NULL)
00561 {
00562
00563 notebook = GTK_NOTEBOOK(heraia_get_widget(main_window->xmls->main, "diw_notebook"));
00564
00565 if (main_window->win_prop->data_interpretor->displayed == FALSE)
00566 {
00567
00568 gtk_notebook_set_current_page(notebook, dw->tab_displayed);
00569
00570
00571 move_and_show_dialog_box(dw->diw, main_window->win_prop->data_interpretor);
00572
00573 refresh_data_interpretor_window(widget, data);
00574 }
00575 else
00576 {
00577
00578 dw->tab_displayed = gtk_notebook_get_current_page(notebook);
00579 record_and_hide_dialog_box(dw->diw, main_window->win_prop->data_interpretor);
00580 }
00581 }
00582 }
00583 }
00584 }
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594 gboolean delete_main_window_event(GtkWidget *widget, GdkEvent *event, gpointer data)
00595 {
00596
00597 on_quit_activate(widget, data);
00598
00599 return FALSE;
00600 }
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610 gboolean delete_dt_window_event(GtkWidget *widget, GdkEvent *event, gpointer data)
00611 {
00612 heraia_window_t *main_window = (heraia_window_t *) data;
00613
00614 g_signal_emit_by_name(heraia_get_widget(main_window->xmls->main, "DIMenu"), "activate");
00615
00616 return TRUE;
00617 }
00618
00619
00620
00621
00622
00623
00624
00625
00626 void destroy_dt_window(GtkWidget *widget, GdkEvent *event, gpointer data)
00627 {
00628 heraia_window_t *main_window = (heraia_window_t *) data;
00629
00630 g_signal_emit_by_name(heraia_get_widget(main_window->xmls->main, "DIMenu"), "activate");
00631 }
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646 static gchar *make_absolute_path(gchar *filename)
00647 {
00648 gchar *current_dir = NULL;
00649 gchar *new_dir = NULL;
00650
00651 if (g_path_is_absolute(filename) == TRUE)
00652 {
00653
00654 return g_path_get_dirname(filename);
00655 }
00656 else
00657 {
00658 current_dir = g_get_current_dir();
00659 new_dir = g_path_get_dirname(filename);
00660
00661 if (g_chdir(new_dir) == 0)
00662 {
00663 g_free(new_dir);
00664 new_dir = g_get_current_dir();
00665 g_chdir(current_dir);
00666 g_free(current_dir);
00667
00668 return new_dir;
00669 }
00670 else
00671 {
00672 g_free(current_dir);
00673
00674 return NULL;
00675 }
00676 }
00677 }
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687 static void set_the_working_directory(GtkFileChooser *file_chooser, gchar *filename)
00688 {
00689 gchar *dirname = NULL;
00690
00691 dirname = make_absolute_path(filename);
00692
00693 if (dirname != NULL)
00694 {
00695 gtk_file_chooser_set_current_folder(file_chooser, dirname);
00696 g_free(dirname);
00697 }
00698 }
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709 gboolean select_file_to_load(heraia_window_t *main_window)
00710 {
00711 GtkWidget *parent = NULL;
00712 GtkFileChooser *file_chooser = NULL;
00713 gboolean success = FALSE;
00714 gchar *filename = NULL;
00715
00716 parent = heraia_get_widget(main_window->xmls->main, "main_window");
00717
00718 file_chooser = GTK_FILE_CHOOSER(gtk_file_chooser_dialog_new("Select a file to analyse",
00719 GTK_WINDOW(parent),
00720 GTK_FILE_CHOOSER_ACTION_OPEN,
00721 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
00722 GTK_STOCK_OPEN, GTK_RESPONSE_OK,
00723 NULL));
00724
00725
00726
00727
00728
00729 gtk_window_set_modal(GTK_WINDOW(file_chooser), TRUE);
00730 gtk_file_chooser_set_select_multiple(file_chooser, FALSE);
00731
00732
00733
00734
00735
00736 if (main_window->filename != NULL)
00737 {
00738 set_the_working_directory(file_chooser, main_window->filename);
00739 }
00740
00741 switch (gtk_dialog_run(GTK_DIALOG(file_chooser)))
00742 {
00743 case GTK_RESPONSE_OK:
00744 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_chooser));
00745 log_message(main_window, G_LOG_LEVEL_DEBUG, "filename selected : %s", filename);
00746
00747
00748 if (main_window->filename != NULL)
00749 {
00750 g_free(main_window->filename);
00751 }
00752
00753 main_window->filename = g_strdup_printf("%s", filename);
00754 success = TRUE;
00755 break;
00756 case GTK_RESPONSE_CANCEL:
00757 default:
00758 success = FALSE;
00759 break;
00760 }
00761
00762 g_free(filename);
00763 gtk_widget_destroy(GTK_WIDGET(file_chooser));
00764
00765 return success;
00766 }
00767
00768
00769
00770
00771
00772
00773
00774
00775 gchar *select_a_file_to_save(heraia_window_t *main_window)
00776 {
00777 GtkWidget *parent = NULL;
00778 GtkFileChooser *fcd = NULL;
00779 gchar *filename = NULL;
00780
00781 parent = heraia_get_widget(main_window->xmls->main, "main_window");
00782
00783
00784 fcd = GTK_FILE_CHOOSER(gtk_file_chooser_dialog_new("Save As...",
00785 GTK_WINDOW(parent),
00786 GTK_FILE_CHOOSER_ACTION_SAVE,
00787 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
00788 GTK_STOCK_SAVE, GTK_RESPONSE_OK,
00789 NULL));
00790
00791
00792 gtk_window_set_modal(GTK_WINDOW(fcd), TRUE);
00793 gtk_file_chooser_set_select_multiple(fcd, FALSE);
00794 gtk_file_chooser_set_do_overwrite_confirmation(fcd, TRUE);
00795
00796
00797 if (main_window->filename != NULL)
00798 {
00799 set_the_working_directory(fcd, main_window->filename);
00800 }
00801
00802 switch(gtk_dialog_run(GTK_DIALOG(fcd)))
00803 {
00804 case GTK_RESPONSE_OK:
00805
00806 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fcd));
00807 break;
00808 default:
00809 filename = NULL;
00810 break;
00811 }
00812
00813 gtk_widget_destroy(GTK_WIDGET(fcd));
00814
00815 return filename;
00816 }
00817
00818
00819
00820
00821
00822
00823
00824 void update_main_window_name(heraia_window_t *main_window)
00825 {
00826 GtkWidget *widget = NULL;
00827 gchar *filename = NULL;
00828
00829 if (main_window != NULL && main_window->current_doc != NULL)
00830 {
00831 widget = heraia_get_widget(main_window->xmls->main, "main_window");
00832 filename = g_filename_display_basename(main_window->current_doc->file_name);
00833
00834 gtk_window_set_title(GTK_WINDOW(widget), filename);
00835 }
00836 }
00837
00838
00839
00840
00841
00842
00843
00844 void set_notebook_tab_name(heraia_window_t *main_window)
00845 {
00846 GtkWidget *notebook = NULL;
00847 GtkWidget *page = NULL;
00848 GtkWidget *label = NULL;
00849 gchar *filename = NULL;
00850 gint current = 0;
00851
00852 if (main_window != NULL && main_window->current_doc != NULL)
00853 {
00854 notebook = heraia_get_widget(main_window->xmls->main, "file_notebook");
00855 current = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
00856 page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), current);
00857 label = gtk_notebook_get_tab_label(GTK_NOTEBOOK(notebook), page);
00858 filename = g_filename_display_basename(main_window->current_doc->file_name);
00859 gtk_label_set_text(GTK_LABEL(label), filename);
00860
00861
00862 if (GTK_MINOR_VERSION >= 12)
00863 {
00864 gtk_widget_set_tooltip_text(label, g_filename_display_name(main_window->current_doc->file_name));
00865 }
00866 }
00867 }
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878 void init_heraia_interface(heraia_window_t *main_window)
00879 {
00880 GtkWidget *notebook = NULL;
00881
00882 if (main_window != NULL)
00883 {
00884
00885 init_window_states(main_window);
00886
00887
00888 notebook = heraia_get_widget(main_window->xmls->main, "file_notebook");
00889 gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
00890
00891 if (main_window->current_doc != NULL)
00892 {
00893 gtk_widget_show(notebook);
00894 }
00895 else
00896 {
00897
00898 gtk_widget_set_sensitive(heraia_get_widget(main_window->xmls->main, "save"), FALSE);
00899 gtk_widget_set_sensitive(heraia_get_widget(main_window->xmls->main, "save_as"), FALSE);
00900 gtk_widget_hide(notebook);
00901 }
00902
00903 refresh_file_labels(main_window);
00904 }
00905 }
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918 static gboolean load_heraia_glade_xml(heraia_window_t *main_window)
00919 {
00920 gchar *filename = NULL;
00921
00922 if (main_window != NULL && main_window->xmls != NULL)
00923 {
00924 filename = g_strdup_printf("heraia.glade");
00925 main_window->xmls->main = load_glade_xml_file(main_window->location_list, filename);
00926 g_free(filename);
00927
00928 if (main_window->xmls->main == NULL)
00929 {
00930 return FALSE;
00931 }
00932 else
00933 {
00934 return TRUE;
00935 }
00936 }
00937 else
00938 {
00939 return FALSE;
00940 }
00941 }
00942
00943
00944
00945
00946
00947
00948
00949 void connect_cursor_moved_signal(heraia_window_t *main_window)
00950 {
00951 g_signal_connect(G_OBJECT(main_window->current_DW->current_hexwidget), "cursor_moved",
00952 G_CALLBACK(refresh_event_handler), main_window);
00953 }
00954
00955
00956
00957
00958
00959
00960
00961 static void heraia_ui_connect_signals(heraia_window_t *main_window)
00962 {
00963
00964
00965 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "DIMenu")), "activate",
00966 G_CALLBACK (on_DIMenu_activate), main_window);
00967
00968
00969 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "quit")), "activate",
00970 G_CALLBACK (on_quit_activate), main_window);
00971
00972
00973 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "new")), "activate",
00974 G_CALLBACK (on_new_activate), main_window);
00975
00976
00977 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "open")), "activate",
00978 G_CALLBACK (on_open_activate), main_window);
00979
00980
00981 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "save")), "activate",
00982 G_CALLBACK (on_save_activate), main_window);
00983
00984
00985 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "save_as")), "activate",
00986 G_CALLBACK (on_save_as_activate), main_window);
00987
00988
00989 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "preferences")), "activate",
00990 G_CALLBACK (on_preferences_activate), main_window);
00991
00992
00993 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "cut")), "activate",
00994 G_CALLBACK (on_cut_activate), main_window);
00995
00996
00997 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "copy")), "activate",
00998 G_CALLBACK (on_copy_activate), main_window);
00999
01000
01001 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "paste")), "activate",
01002 G_CALLBACK (on_paste_activate), main_window);
01003
01004
01005 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "delete")), "activate",
01006 G_CALLBACK (on_delete_activate), main_window);
01007
01008
01009
01010 g_signal_connect (G_OBJECT(heraia_get_widget(main_window->xmls->main, "a_propos")), "activate",
01011 G_CALLBACK(a_propos_activate), main_window);
01012
01013 g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "about_dialog")), "close",
01014 G_CALLBACK(a_propos_close), main_window);
01015
01016 g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "about_dialog")), "response",
01017 G_CALLBACK(a_propos_response), main_window);
01018
01019 g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "about_dialog")), "delete-event",
01020 G_CALLBACK(a_propos_delete), main_window);
01021
01022
01023
01024 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "main_window")), "delete-event",
01025 G_CALLBACK (delete_main_window_event), main_window);
01026
01027 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "main_window")), "response",
01028 G_CALLBACK (delete_main_window_event), main_window);
01029
01030 g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "main_window")), "close",
01031 G_CALLBACK (on_quit_activate), main_window);
01032 }
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045 int load_heraia_ui(heraia_window_t *main_window)
01046 {
01047 gboolean success = FALSE;
01048
01049
01050 success = load_heraia_glade_xml(main_window);
01051
01052 if (success == TRUE)
01053 {
01054
01055 if (main_window->debug == TRUE)
01056 {
01057 fprintf(stdout, "Connecting heraia_ui signals ");
01058 }
01059
01060 heraia_ui_connect_signals(main_window);
01061
01062 if (main_window->debug == TRUE)
01063 {
01064 fprintf(stdout, " [Done]\n");
01065 }
01066
01067
01068 if (main_window->debug == TRUE)
01069 {
01070 fprintf(stdout, "log window init interface ");
01071 }
01072
01073 log_window_init_interface(main_window);
01074
01075 if (main_window->debug == TRUE)
01076 {
01077 fprintf(stdout, " [Done]\n");
01078 }
01079
01080
01081 if (main_window->debug == TRUE)
01082 {
01083 fprintf(stdout, "preferences window init interface");
01084 }
01085
01086 main_pref_window_init_interface(main_window);
01087
01088 if (main_window->debug == TRUE)
01089 {
01090 fprintf(stdout, " [Done]\n");
01091 }
01092
01093
01094
01095 if (main_window->debug == TRUE)
01096 {
01097 fprintf(stdout, "data interpretor init interface ");
01098 }
01099
01100 data_interpretor_init_interface(main_window);
01101
01102 if (main_window->debug == TRUE)
01103 {
01104 fprintf(stdout, " [Done]\n");
01105 }
01106
01107
01108
01109 if (main_window->debug == TRUE)
01110 {
01111 fprintf(stdout, "list data types init interface ");
01112 }
01113
01114 list_data_types_init_interface(main_window);
01115
01116 if (main_window->debug == TRUE)
01117 {
01118 fprintf(stdout, " [Done]\n");
01119 }
01120
01121
01122
01123 if (main_window->debug == TRUE)
01124 {
01125 fprintf(stdout, "data type init interface ");
01126 }
01127
01128 data_type_init_interface(main_window);
01129
01130 if (main_window->debug == TRUE)
01131 {
01132 fprintf(stdout, " [Done]\n");
01133 }
01134
01135 fprintf(stdout, "Loading heraia preference file ");
01136
01137 if (load_preference_file(main_window) != TRUE)
01138 {
01139 fprintf(stdout, " [FAILED]\n");
01140 }
01141 else
01142 {
01143 fprintf(stdout, " [Done]\n");
01144 fprintf(stdout, "Setting up preferences ");
01145 load_preferences(main_window);
01146 fprintf(stdout, " [Done]\n");
01147 }
01148 }
01149 return success;
01150 }
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160 void add_text_to_textview(GtkTextView *textview, const char *format, ...)
01161 {
01162 va_list args;
01163 GtkTextBuffer *tb = NULL;
01164 GtkTextIter iEnd;
01165 gchar *display = NULL;
01166 GError *err = NULL;
01167
01168 va_start(args, format);
01169 display = g_locale_to_utf8(g_strdup_vprintf(format, args), -1, NULL, NULL, &err);
01170 va_end(args);
01171
01172 tb = GTK_TEXT_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)));
01173 gtk_text_buffer_get_end_iter(tb, &iEnd);
01174 gtk_text_buffer_insert(tb, &iEnd, display, -1);
01175 g_free(display);
01176 }
01177
01178
01179
01180
01181
01182
01183
01184 void kill_text_from_textview(GtkTextView *textview)
01185 {
01186 GtkTextBuffer *tb = NULL;
01187 GtkTextIter iStart;
01188 GtkTextIter iEnd;
01189
01190 tb = GTK_TEXT_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)));
01191 gtk_text_buffer_get_start_iter(tb, &iStart);
01192 gtk_text_buffer_get_end_iter(tb, &iEnd);
01193 gtk_text_buffer_delete (tb, &iStart, &iEnd);
01194 }
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205 GtkWidget *gtk_radio_button_get_active(GSList *group)
01206 {
01207 GSList *tmp_slist = group;
01208
01209 while (tmp_slist)
01210 {
01211 if (GTK_TOGGLE_BUTTON (tmp_slist->data)->active)
01212 {
01213 return GTK_WIDGET (tmp_slist->data);
01214 }
01215 tmp_slist = tmp_slist->next;
01216 }
01217
01218 return NULL;
01219 }
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229 GtkWidget *gtk_radio_button_get_active_from_widget(GtkRadioButton *radio_group_member)
01230 {
01231 if (radio_group_member)
01232 {
01233 return gtk_radio_button_get_active(radio_group_member->group);
01234 }
01235 else
01236 {
01237 return NULL;
01238 }
01239 }
01240
01241
01242
01243
01244
01245
01246
01247
01248 gboolean is_cmi_checked(GtkWidget *check_menu_item)
01249 {
01250 return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(check_menu_item));
01251 }
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263 gboolean is_toggle_button_activated(GladeXML *main_xml, gchar *check_button)
01264 {
01265 gboolean activated = FALSE;
01266
01267 if (main_xml != NULL)
01268 {
01269 activated = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(heraia_get_widget(main_xml, check_button)));
01270 }
01271
01272 return activated;
01273 }
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287 GtkWidget *heraia_get_widget(GladeXML *xml, gchar *widget_name)
01288 {
01289
01290
01291
01292
01293
01294 if (xml != NULL && widget_name != NULL)
01295 {
01296 return glade_xml_get_widget(xml, widget_name);
01297 }
01298 else
01299 {
01300 return NULL;
01301 }
01302 }
01303
01304
01305
01306
01307
01308
01309
01310 void destroy_a_single_widget(GtkWidget *widget)
01311 {
01312 if (widget != NULL)
01313 {
01314 gtk_widget_destroy(widget);
01315 }
01316 }
01317
01318
01319
01320
01321
01322
01323 static void close_heraia(heraia_window_t *main_window)
01324 {
01325
01326
01327 record_all_dialog_box_positions(main_window);
01328
01329
01330 save_preferences(main_window);
01331 }
01332
01333
01334
01335
01336
01337
01338
01339
01340 static void init_one_cmi_window_state(GtkWidget *dialog_box, GtkWidget *cmi, window_prop_t *dialog_prop)
01341 {
01342 gboolean activated = FALSE;
01343
01344 if (dialog_box != NULL && cmi != NULL && dialog_prop != NULL)
01345 {
01346 activated = dialog_prop->displayed;
01347 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(cmi), activated);
01348 if (activated == TRUE)
01349 {
01350 gtk_window_move(GTK_WINDOW(dialog_box), dialog_prop->x, dialog_prop->y);
01351 gtk_window_resize(GTK_WINDOW(dialog_box), dialog_prop->width, dialog_prop->height);
01352 gtk_widget_show_all(dialog_box);
01353 }
01354 }
01355 }
01356
01357
01358
01359
01360
01361
01362
01363 void init_window_states(heraia_window_t *main_window)
01364 {
01365 GtkWidget *cmi = NULL;
01366 GtkWidget *dialog_box = NULL;
01367
01368 if (main_window != NULL && main_window->xmls != NULL && main_window->xmls->main != NULL)
01369 {
01370 if (main_window->win_prop)
01371 {
01372
01373 dialog_box = heraia_get_widget(main_window->xmls->main, "main_window");
01374 if (main_window->win_prop->main_dialog->displayed == TRUE)
01375 {
01376 gtk_window_move(GTK_WINDOW(dialog_box), main_window->win_prop->main_dialog->x, main_window->win_prop->main_dialog->y);
01377 gtk_window_resize(GTK_WINDOW(dialog_box), main_window->win_prop->main_dialog->width, main_window->win_prop->main_dialog->height);
01378 gtk_widget_show(dialog_box);
01379 }
01380
01381
01382 cmi = heraia_get_widget(main_window->xmls->main, "mw_cmi_show_logw");
01383 dialog_box = heraia_get_widget(main_window->xmls->main, "log_window");
01384 init_one_cmi_window_state(dialog_box, cmi, main_window->win_prop->log_box);
01385
01386
01387 cmi = heraia_get_widget(main_window->xmls->main, "DIMenu");
01388
01389 if (main_window->win_prop->data_interpretor->displayed == TRUE)
01390 {
01391 main_window->win_prop->data_interpretor->displayed = FALSE;
01392 g_signal_emit_by_name(heraia_get_widget(main_window->xmls->main, "DIMenu"), "activate");
01393 }
01394
01395
01396 cmi = heraia_get_widget(main_window->xmls->main, "ldt_menu");
01397 dialog_box = heraia_get_widget(main_window->xmls->main, "list_data_types_window");
01398 init_one_cmi_window_state(dialog_box, cmi, main_window->win_prop->ldt);
01399
01400
01401 cmi = heraia_get_widget(main_window->xmls->main, "mw_cmi_plugin_list");
01402 dialog_box = heraia_get_widget(main_window->xmls->main, "plugin_list_window");
01403 init_one_cmi_window_state(dialog_box, cmi, main_window->win_prop->plugin_list);
01404
01405
01406 dialog_box = heraia_get_widget(main_window->xmls->main, "main_preferences_window");
01407 if (main_window->win_prop->main_pref_window->displayed == TRUE)
01408 {
01409
01410 gtk_window_move(GTK_WINDOW(dialog_box), main_window->win_prop->main_pref_window->x, main_window->win_prop->main_pref_window->y);
01411 gtk_window_resize(GTK_WINDOW(dialog_box), main_window->win_prop->main_pref_window->width, main_window->win_prop->main_pref_window->height);
01412 gtk_widget_show_all(dialog_box);
01413 }
01414
01415
01416 dialog_box = heraia_get_widget(main_window->xmls->main, "about_dialog");
01417 if (main_window->win_prop->about_box->displayed == TRUE)
01418 {
01419
01420 gtk_window_move(GTK_WINDOW(dialog_box), main_window->win_prop->about_box->x, main_window->win_prop->about_box->y);
01421 gtk_window_resize(GTK_WINDOW(dialog_box), main_window->win_prop->about_box->width, main_window->win_prop->about_box->height);
01422 set_a_propos_properties(dialog_box);
01423 gtk_widget_show_all(dialog_box);
01424 }
01425 }
01426 }
01427 }