home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / LINUX / gopchop-1.1.7.tar.tar / gopchop-1.1.7.tar / gopchop-1.1.7 / src / callbacks.cpp < prev    next >
C/C++ Source or Header  |  2005-05-01  |  31KB  |  1,052 lines

  1. /* vi:set ai ts=4 sw=4 expandtab: */
  2. /*
  3. #
  4. # C++-ized callbacks.c file produced by Glade for GTK event callbacks
  5. #
  6. # $Id: callbacks.cpp,v 1.33 2005/05/01 17:59:23 keescook Exp $
  7. #
  8. # Copyright (C) 2001-2003 Kees Cook
  9. # kees@outflux.net, http://outflux.net/
  10. # This program is free software; you can redistribute it and/or
  11. # modify it under the terms of the GNU General Public License
  12. # as published by the Free Software Foundation; either version 2
  13. # of the License, or (at your option) any later version.
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. # GNU General Public License for more details.
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21. # http://www.gnu.org/copyleft/gpl.html
  22. #
  23. */
  24.  
  25. #include "GOPchop.h"
  26.  
  27. #include <gtk/gtk.h>
  28. #include <gdk/gdkkeysyms.h>
  29.  
  30. #include <stdio.h>
  31.  
  32. extern "C"
  33. {
  34. #include "callbacks.h"
  35. #include "interface.h"
  36. #include "support.h"
  37. #include "video_out.h"
  38. }
  39.  
  40. #include "main.h"
  41. #include "widgets.h"
  42. #include "gettext.h"
  43.  
  44. #include "Picture.h"
  45. #include "sessions.h"
  46.  
  47. #include "display.h"
  48.  
  49. extern struct display_engine_t * engine;
  50. extern int desired_output;
  51. extern char * opt_videoout;
  52. extern int opt_show_states;
  53. extern char * opt_pipe;
  54.  
  55. static void
  56. slider_updated_actions(uint32_t GOP)
  57. {
  58.     // only do something if we have output, and auto refreshing
  59.     if (options.auto_refresh)
  60.         show_GOP(engine,GOP);
  61.  
  62.     if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button_run))) {
  63.         display_flush(engine);
  64.     }
  65.  
  66.     // make sure the parser is loaded
  67.     if (mpeg2parser->getParsingState()==PARSER_STATE_FINISHED)
  68.         update_GOP_info(GOP);
  69.  
  70.     // handle start/end button availability
  71.     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button_start_mark))) {
  72.         gtk_widget_set_sensitive(button_end_mark, (GOP >= mark_start));
  73.     }
  74. }
  75.  
  76. void file_is_loaded()
  77. {
  78.     List *GOPs;
  79.     List *pictures;
  80.     gchar buf[128];
  81.     char *pathname;
  82.     int picture_count = 0;
  83.  
  84.     // toggle our file options
  85.     gtk_widget_set_sensitive(menu_load_mpeg2, FALSE);
  86.     gtk_widget_set_sensitive(menu_load_clip_list, FALSE);
  87.     gtk_widget_set_sensitive(menu_save_clip_list, TRUE);
  88.     gtk_widget_set_sensitive(menu_export_mpeg2, TRUE);
  89.     gtk_widget_set_sensitive(menu_close, TRUE);
  90.  
  91.     gtk_widget_set_sensitive(menu_delete, TRUE);
  92.     gtk_widget_set_sensitive(menu_clear, TRUE);
  93.  
  94.     gtk_widget_set_sensitive(menu_video_window, TRUE);
  95.  
  96.     gtk_widget_set_sensitive(button_run, TRUE);
  97.     gtk_widget_set_sensitive(button_prev, TRUE);
  98.     gtk_widget_set_sensitive(button_next, TRUE);
  99.     gtk_widget_set_sensitive(button_refresh, TRUE);
  100.     gtk_widget_set_sensitive(button_start_mark, TRUE);
  101.     gtk_widget_set_sensitive(button_end_mark, FALSE);
  102.  
  103.     // adjust the slider scales
  104.     gtk_range_set_range(GTK_RANGE(GOP_selector), 0.0, (gdouble) (mpeg2parser->numGOPs()));
  105.     gtk_spin_button_set_range(GTK_SPIN_BUTTON(GOP_selector_spinbutton), 0.0, (gdouble) (mpeg2parser->numGOPs()-1));
  106.  
  107.     // start decode window
  108.     display_close(engine);
  109.     engine = display_open(desired_output,opt_pipe,opt_videoout,opt_show_states);
  110.     set_GOP_selected(0);
  111.     flush();
  112.     slider_updated_actions(0);
  113.  
  114.     pathname = mpeg2parser->getFilename();
  115.     if (!pathname)
  116.         pathname = "unknown";
  117.     gtk_label_set_text(GTK_LABEL(GOP_label_filename), pathname);
  118. }
  119.  
  120. void file_is_unloaded()
  121. {
  122.     // stop decode window
  123.     display_close(engine);
  124.     engine = NULL;
  125.     set_GOP_selected(0);
  126.  
  127.     // toggle our file options
  128.     gtk_widget_set_sensitive(menu_load_mpeg2, TRUE);
  129.     gtk_widget_set_sensitive(menu_load_clip_list, TRUE);
  130.     gtk_widget_set_sensitive(menu_save_clip_list, FALSE);
  131.     gtk_widget_set_sensitive(menu_export_mpeg2, FALSE);
  132.     gtk_widget_set_sensitive(menu_close, FALSE);
  133.  
  134.     gtk_widget_set_sensitive(menu_delete, FALSE);
  135.     gtk_widget_set_sensitive(menu_clear, FALSE);
  136.  
  137.     gtk_widget_set_sensitive(menu_video_window, FALSE);
  138.  
  139.     gtk_widget_set_sensitive(button_run, FALSE);
  140.     gtk_widget_set_sensitive(button_prev, FALSE);
  141.     gtk_widget_set_sensitive(button_next, FALSE);
  142.     gtk_widget_set_sensitive(button_refresh, FALSE);
  143.     gtk_widget_set_sensitive(button_start_mark, FALSE);
  144.     gtk_widget_set_sensitive(button_end_mark, FALSE);
  145.  
  146.     // adjust the slider scales
  147.     gtk_range_set_range(GTK_RANGE(GOP_selector), 0.0, 0.1);
  148.     gtk_spin_button_set_range(GTK_SPIN_BUTTON(GOP_selector_spinbutton), 0.0, 0.1);
  149.  
  150.     // wipe out GOP info window
  151.     clear_GOP_info();
  152.  
  153.     // wipe out clip window
  154.     clear_GOP_slices();
  155.  
  156.     // reset parser
  157.     mpeg2parser->reset();
  158.  
  159.     if (error_dialog)
  160.     {
  161.         // hide the errors (no errors now!)
  162.         gtk_widget_hide(error_dialog);
  163.     }
  164. }
  165.  
  166.  
  167. /*
  168.  * #############################################################################
  169.  * ######################## Start Menu Related Functions #######################
  170.  * #############################################################################
  171.  */
  172.  
  173. /* +-----------------------------------+
  174.  * | File Menu Related Functions       |
  175.  * +-----------------------------------+ */
  176. void
  177. on_menu_load_mpeg2_activate            (GtkMenuItem    *menuitem,
  178.                                         gpointer        user_data)
  179. {
  180.     if( !new_file_window ) {
  181.         new_file_window = create_new_file_window();
  182.     }
  183.     gtk_widget_show( new_file_window );
  184. }
  185.  
  186.  
  187. void
  188. on_menu_load_clip_list_activate        (GtkMenuItem    *menuitem,
  189.                                         gpointer        user_data)
  190. {
  191.     if (!open_file_window)
  192.     {
  193.         open_file_window = create_open_file_window();
  194.     }
  195.     gtk_widget_show(open_file_window);
  196. }
  197.  
  198.  
  199. void
  200. on_menu_save_clip_list_activate        (GtkMenuItem    *menuitem,
  201.                                         gpointer        user_data)
  202. {
  203.     if (!save_file_window)
  204.     {
  205.         save_file_window = create_save_file_window();
  206.     }
  207.     gtk_widget_show(save_file_window);
  208. }
  209.  
  210.  
  211. void
  212. on_menu_export_mpeg2_activate          (GtkMenuItem    *menuitem,
  213.                                         gpointer        user_data)
  214. {
  215.     if (!export_file_window)
  216.     {
  217.         export_file_window = create_export_file_window();
  218.     }
  219.     gtk_widget_show(export_file_window);
  220. }
  221.  
  222.  
  223. void
  224. on_menu_file_close_activate            (GtkMenuItem    *menuitem,
  225.                                         gpointer        user_data)
  226. {
  227.     file_is_unloaded();
  228. }
  229.  
  230.  
  231. void
  232. on_menu_file_quit_activate             (GtkMenuItem    *menuitem,
  233.                                         gpointer        user_data)
  234. {
  235.     mpeg2parser->reset();
  236.     gtk_main_quit();
  237. }
  238.  
  239.  
  240. /* +-----------------------------------+
  241.  * | Edit Menu Related Functions       |
  242.  * +-----------------------------------+ */
  243. void
  244. on_menu_delete_activate                (GtkMenuItem    *menuitem,
  245.                                         gpointer        user_data)
  246. {
  247.     GtkTreeSelection *selection;
  248.     GtkTreeIter       iter;
  249.  
  250.     selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(main_clist));
  251.     if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) {
  252.         return; /* nothing selected: skip */
  253.     }
  254.  
  255.     remove_GOP_slice(&iter);
  256. }
  257.  
  258.  
  259. void
  260. on_menu_file_clear_activate            (GtkMenuItem    *menuitem,
  261.                                         gpointer        user_data)
  262. {
  263.     clear_GOP_slices();
  264. }
  265.  
  266. static char *
  267. string_merge(char * one, char * two)
  268. {
  269.     char * result=NULL;
  270.  
  271.     if (!(result=(char*)malloc(strlen(one)+strlen(two)+1))) {
  272.         perror("malloc");
  273.         exit(1);
  274.     }
  275.     sprintf(result,"%s%s",one,two);
  276.     return result;
  277. }
  278.  
  279.  
  280. // are we _displaying_ preferences or saving them?
  281. static void
  282. handle_simple_preferences(gboolean display)
  283. {
  284.     rc_parse_item * parse_item;
  285.  
  286.     for (parse_item = parsable_items;
  287.          parse_item->option;
  288.          parse_item++) {
  289.  
  290. //        printf("%s '%s' ...\n",display ? "Populating" : "Storing", parse_item->option);
  291.  
  292.         // skip missing variables
  293.         if (!parse_item->variable) continue;
  294.  
  295.         switch (parse_item->vartype) {
  296.             case RC_TYPE_BOOLEAN:
  297.             {
  298.                 gboolean * value = (gboolean*)parse_item->variable;
  299.                 GtkWidget * button;
  300.                 char *name = string_merge(parse_item->option,"_checkbutton");
  301.  
  302.                 button = lookup_widget( GTK_WIDGET(preferences_window), name );
  303.                 if (display) {
  304.                     gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(button),
  305.                                                   (*value == false) ?
  306.                                                     FALSE : TRUE );
  307.                 }
  308.                 else {
  309.                     *value = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(button) );
  310.                 }
  311.  
  312.                 if (name) free(name);
  313.                 break;
  314.             }
  315.             case RC_TYPE_INTEGER:
  316.             {
  317.                 int * value = (int*)parse_item->variable;
  318.                 GtkWidget *spinner, *range;
  319.                 char *spin_name  = string_merge(parse_item->option,"_spinner");
  320.                 char *slide_name = string_merge(parse_item->option,"_slider");
  321.  
  322.                 spinner = lookup_widget(GTK_WIDGET(preferences_window),
  323.                                         spin_name );
  324.                 range = lookup_widget(GTK_WIDGET(preferences_window),
  325.                                       slide_name);
  326.                 if (display) {
  327.                     gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinner),
  328.                                               (gdouble)*value);
  329.                     gtk_range_set_value(GTK_RANGE(range),
  330.                                         (gdouble)*value);
  331.                 }
  332.                 else {
  333.                     *value = (int) gtk_range_get_value(GTK_RANGE(range));
  334.                 }
  335.  
  336.  
  337.                 if (spin_name) free(spin_name);
  338.                 if (slide_name) free(slide_name);
  339.                 break;
  340.             }
  341.             case RC_TYPE_STRING:
  342.             {
  343.                 // string combo boxes are not simple...
  344.                 break;
  345.             }
  346.             default:
  347.             {
  348.                 printf("Unknown parseable vartype: %s:%d\n",
  349.                        parse_item->option,parse_item->vartype);
  350.                 break;
  351.             }
  352.         }
  353.     }
  354. }
  355.  
  356.  
  357. void
  358. on_menu_options_preferences_activate   (GtkMenuItem    *menuitem,
  359.                                         gpointer        user_data)
  360. {
  361.     GtkToggleButton *button;
  362.     GtkCombo        *combo;
  363.     GtkRange        *range;
  364.     GtkSpinButton   *spinner;
  365.     GList           *items;
  366.     int i;
  367.     vo_driver_t const *drivers;
  368.     
  369.     items = NULL;
  370.  
  371.     if( !preferences_window ) {
  372.         preferences_window = create_preferences_window();
  373.     }
  374.  
  375.         /* set the combo box up with the correct values. */
  376.         combo = GTK_COMBO(lookup_widget(GTK_WIDGET(preferences_window), "video_output_driver_combo" ));
  377.         gchar * vidpref = NULL;
  378.         drivers = vo_drivers();
  379.         for( i = 0; drivers[i].name; i++ ) {
  380.             items = g_list_append(items, drivers[i].name);
  381.  
  382.             // while looking through the list of available video drivers,
  383.             // the prefered driver is xv2, followed by xv, and finally x11.
  384.             // If the user hasn't selected one, this one will be used.
  385.             if ( !strcmp(drivers[i].name,"xv2") ||
  386.                  (!vidpref && !strcmp(drivers[i].name,"xv"))) {
  387.                 if (vidpref) free(vidpref);
  388.                 vidpref=g_strdup(drivers[i].name);
  389.             }
  390.         }
  391.         if (!vidpref) vidpref=g_strdup("x11");
  392.  
  393.         gtk_combo_set_popdown_strings(combo, items);
  394.  
  395.         if( !options.video_driver_ptr ) options.video_driver_ptr = vidpref;
  396.         else                            if (vidpref) free(vidpref);
  397.  
  398.         gtk_entry_set_text(GTK_ENTRY(combo->entry),
  399.                            (const gchar*)options.video_driver_ptr);
  400.  
  401.     handle_simple_preferences(true);
  402.  
  403.     gtk_widget_show(preferences_window);
  404. }
  405.  
  406.  
  407. /* +-----------------------------------+
  408.  * | View Menu Related Functions       |
  409.  * +-----------------------------------+ */
  410. void
  411. on_menu_info_window_activate           (GtkMenuItem    *menuitem,
  412.                                         gpointer        user_data)
  413. {
  414.     if( TRUE == gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem)) ) {
  415.         if( NULL == GOP_window ) {
  416.             GOP_window = GTK_WIDGET(create_GOP_window());
  417.         }
  418.  
  419.         gtk_widget_show(GOP_window);
  420.     } else {
  421.         gtk_widget_hide(GOP_window);
  422.     }
  423. }
  424.  
  425.  
  426. void
  427. on_menu_video_window_activate          (GtkMenuItem    *menuitem,
  428.                                         gpointer        user_data)
  429. {
  430.  
  431. }
  432.  
  433. /* +-----------------------------------+
  434.  * | Help Menu Related Functions       |
  435.  * +-----------------------------------+ */
  436. void
  437. on_menu_help_about_activate            (GtkMenuItem    *menuitem,
  438.                                         gpointer        user_data)
  439. {
  440.     static char buf[1024];
  441.     GtkWidget *label;
  442.  
  443.     if (!about_window)
  444.     {
  445.         about_window = create_about_window();
  446.  
  447.         // set version in window
  448.         snprintf(buf, 1023, _("GOPchop %s (%s)"), VERSION, __DATE__);
  449.         label = GTK_WIDGET(lookup_widget(GTK_WIDGET(about_window),
  450.                                          "about_label_version"));
  451.         gtk_label_set_text(GTK_LABEL(label), buf);
  452.  
  453.         label = GTK_WIDGET(lookup_widget(GTK_WIDGET(about_window),
  454.                                          "about_label_cvsid"));
  455.         gtk_label_set_text(GTK_LABEL(label), GOPchop_cvsid);
  456.     }
  457.  
  458.     gtk_widget_show(about_window);
  459. }
  460. /*
  461.  * #############################################################################
  462.  * ######################## End Menu Related Functions #########################
  463.  * #############################################################################
  464.  */
  465.  
  466.  
  467. /*
  468.  * #############################################################################
  469.  * ######################## Start FileSelection Related Functions ##############
  470.  * #############################################################################
  471.  */
  472.  
  473. /* +-----------------------------------+
  474.  * | Preferences Related Functions     |
  475.  * +-----------------------------------+ */
  476. void
  477. on_preferences_okbutton_clicked        (GtkButton       *button,
  478.                                         gpointer         user_data)
  479. {
  480.     const gchar     *string;
  481.     GtkCombo        *combo;
  482.  
  483.     // handle video mode selection
  484.     combo = GTK_COMBO(lookup_widget(GTK_WIDGET(preferences_window), "video_output_driver_combo" ));
  485.     string = gtk_entry_get_text(GTK_ENTRY(combo->entry));
  486.     options.video_driver_ptr = options.video_driver;
  487.     g_snprintf(options.video_driver_ptr, 24, "%s", string);
  488.     opt_videoout = options.video_driver_ptr;
  489.  
  490.     // load simple prefs from window
  491.     handle_simple_preferences(false);
  492.     
  493.     gtk_widget_hide(preferences_window);
  494.  
  495.     // preference setting side-effects
  496.     options.run_speed = options.default_run_speed;
  497.     gtk_range_set_value(GTK_RANGE(slider_run_speed), options.run_speed);
  498.     mpeg2parser->set_ignore_endcode(options.ignore_endcode);
  499.  
  500.     rc_save(PACKAGE,parsable_items);
  501. }
  502.  
  503. void
  504. on_preferences_cancelbutton_clicked    (GtkButton       *button,
  505.                                         gpointer         user_data)
  506. {
  507.     gtk_widget_hide(preferences_window);
  508. }
  509.  
  510. gboolean
  511. on_preferences_window_delete_event     (GtkWidget       *widget,
  512.                                         GdkEvent        *event,
  513.                                         gpointer         user_data)
  514. {
  515.     gtk_widget_hide(preferences_window);
  516.     return TRUE;
  517. }
  518.  
  519. void
  520. on_preferences_run_speed_slider_value_changed
  521.                                         (GtkRange        *range,
  522.                                         gpointer         user_data)
  523. {
  524.     gdouble value;
  525.     GtkSpinButton *spinner;
  526.     
  527.     value = gtk_range_get_value(range);
  528.     spinner = GTK_SPIN_BUTTON(lookup_widget(GTK_WIDGET(preferences_window), "default_run_speed_spinner" ));
  529.     gtk_spin_button_set_value(spinner, value);
  530. }
  531.  
  532. void
  533. on_preferences_run_speed_spinner_value_changed
  534.                                         (GtkSpinButton   *spinbutton,
  535.                                         gpointer         user_data)
  536. {
  537.     gdouble value;
  538.     GtkRange *range;
  539.  
  540.     value = gtk_spin_button_get_value(spinbutton);
  541.     range = GTK_RANGE(lookup_widget(GTK_WIDGET(preferences_window), "default_run_speed_slider"));
  542.     gtk_range_set_value( range, value );
  543. }
  544.  
  545.  
  546. /* +-----------------------------------+
  547.  * | New Related Functions             |
  548.  * +-----------------------------------+ */
  549. void
  550. on_new_file_okbutton_clicked           (GtkButton       *button,
  551.                                         gpointer         user_data)
  552. {
  553.     char *filename;
  554.  
  555.     gtk_widget_hide(new_file_window);
  556.     flush();
  557.  
  558.     filename = (char*)
  559.         gtk_file_selection_get_filename(GTK_FILE_SELECTION
  560.                                         (new_file_window));
  561.  
  562.     open_file(filename);
  563. }
  564.  
  565. void
  566. on_new_file_cancelbutton_clicked       (GtkButton       *button,
  567.                                         gpointer         user_data)
  568. {
  569.     gtk_widget_hide(new_file_window);
  570. }
  571.  
  572. void
  573. on_new_file_window_destroy             (GtkObject       *object,
  574.                                         gpointer         user_data)
  575. {
  576.     new_file_window = NULL;
  577. }
  578.  
  579. gboolean
  580. on_new_file_window_delete_event        (GtkWidget       *widget,
  581.                                         GdkEvent        *event,
  582.                                         gpointer         user_data)
  583. {
  584.     gtk_widget_hide(new_file_window);
  585.     return TRUE;
  586. }
  587.  
  588.  
  589. /* +-----------------------------------+
  590.  * | Open Related Functions            |
  591.  * +-----------------------------------+ */
  592. void
  593. on_open_file_okbutton_clicked          (GtkButton       *button,
  594.                                         gpointer         user_data)
  595. {
  596.     char *filename;
  597.     int   load_status;
  598.  
  599.     gtk_widget_hide(open_file_window);
  600.     flush();
  601.  
  602.     filename = (char*)
  603.         gtk_file_selection_get_filename(GTK_FILE_SELECTION
  604.                                         (open_file_window));
  605.  
  606.     load_status = load_session(filename);
  607.     if( SESSION_LOADED_OK == load_status ) {
  608.     } else {
  609.         show_error( error_to_string(load_status) );
  610.     }
  611. }
  612.  
  613. void
  614. on_open_file_cancelbutton_clicked      (GtkButton       *button,
  615.                                         gpointer         user_data)
  616. {
  617.     gtk_widget_hide(open_file_window);
  618. }
  619.  
  620. void
  621. on_open_file_window_destroy            (GtkObject       *object,
  622.                                         gpointer         user_data)
  623. {
  624.     open_file_window = NULL;
  625. }
  626.  
  627. gboolean
  628. on_open_file_window_delete_event       (GtkWidget       *widget,
  629.                                         GdkEvent        *event,
  630.                                         gpointer         user_data)
  631. {
  632.     gtk_widget_hide(open_file_window);
  633.     return TRUE;
  634. }
  635.  
  636.  
  637. /* +-----------------------------------+
  638.  * | Save Related Functions            |
  639.  * +-----------------------------------+ */
  640. void
  641. on_save_file_okbutton_clicked          (GtkButton       *button,
  642.                                         gpointer         user_data)
  643. {
  644.     gchar     *filename;
  645.     GtkWidget *dialog;
  646.  
  647.     gint result = GTK_RESPONSE_OK;
  648.  
  649.     filename = (char*)
  650.         gtk_file_selection_get_filename(GTK_FILE_SELECTION
  651.                                         (save_file_window));
  652.     if( !access(filename, F_OK) ) {
  653.         dialog = gtk_message_dialog_new(GTK_WINDOW(save_file_window),
  654.                                         GTK_DIALOG_DESTROY_WITH_PARENT,
  655.                                         GTK_MESSAGE_QUESTION,
  656.                                         GTK_BUTTONS_OK_CANCEL,
  657.                                         "File '%s' exists.  Overwrite?",
  658.                                         filename);
  659.         result = gtk_dialog_run( GTK_DIALOG(dialog) );
  660.         gtk_widget_destroy( dialog );
  661.     }
  662.  
  663.     gtk_widget_hide(save_file_window);
  664.     flush();
  665.  
  666.     if( GTK_RESPONSE_OK == result ) {
  667.         save_session( filename );
  668.     }
  669. }
  670.  
  671. void
  672. on_save_file_cancelbutton_clicked      (GtkButton       *button,
  673.                                         gpointer         user_data)
  674. {
  675.     gtk_widget_hide(save_file_window);
  676. }
  677.  
  678. gboolean
  679. on_save_file_window_delete_event       (GtkWidget       *widget,
  680.                                         GdkEvent        *event,
  681.                                         gpointer         user_data)
  682. {
  683.     gtk_widget_hide(save_file_window);
  684.     return TRUE;
  685. }
  686.  
  687.  
  688. /* +-----------------------------------+
  689.  * | Export Related Functions          |
  690.  * +-----------------------------------+ */
  691. void
  692. on_export_file_okbutton_clicked        (GtkButton       *button,
  693.                                         gpointer         user_data)
  694. {
  695.     gchar *filename;
  696.     GtkWidget *dialog;
  697.  
  698.     gint result = GTK_RESPONSE_OK;
  699.  
  700.     filename = (char*)
  701.         gtk_file_selection_get_filename(GTK_FILE_SELECTION
  702.                                         (export_file_window));
  703.  
  704.     if( !access(filename, F_OK) ) {
  705.         dialog = gtk_message_dialog_new(GTK_WINDOW(save_file_window),
  706.                                         GTK_DIALOG_DESTROY_WITH_PARENT,
  707.                                         GTK_MESSAGE_QUESTION,
  708.                                         GTK_BUTTONS_OK_CANCEL,
  709.                                         "File '%s' exists.  Overwrite?",
  710.                                         filename);
  711.         result = gtk_dialog_run( GTK_DIALOG(dialog) );
  712.         gtk_widget_destroy( dialog );
  713.     }
  714.  
  715.     gtk_widget_hide(export_file_window);
  716.     flush();
  717.  
  718.     if( GTK_RESPONSE_OK == result ) {
  719.         save_file(filename);
  720.     }
  721.  
  722. }
  723.  
  724.  
  725. void
  726. on_export_file_cancelbutton_clicked    (GtkButton       *button,
  727.                                         gpointer         user_data)
  728. {
  729.     gtk_widget_hide(export_file_window);
  730. }
  731.  
  732. void
  733. on_export_file_window_destroy          (GtkObject       *object,
  734.                                         gpointer         user_data)
  735. {
  736.     export_file_window = NULL;
  737. }
  738.  
  739. gboolean
  740. on_export_file_window_delete_event     (GtkWidget       *widget,
  741.                                         GdkEvent        *event,
  742.                                         gpointer         user_data)
  743. {
  744.     gtk_widget_hide(export_file_window);
  745.     return TRUE;
  746. }
  747. /*
  748.  * #############################################################################
  749.  * ######################## End FileSelection Related Functions ################
  750.  * #############################################################################
  751.  */
  752.  
  753. /*
  754.  * #############################################################################
  755.  * ######################## Start Main Window Related Functions ################
  756.  * #############################################################################
  757.  */
  758. void
  759. on_GOP_selector_value_changed          (GtkRange        *range,
  760.                                         gpointer         user_data)
  761. {
  762.     uint32_t GOP;
  763.  
  764.     GOP = (uint32_t) gtk_range_get_value(range);
  765.     gtk_spin_button_set_value(GTK_SPIN_BUTTON(GOP_selector_spinbutton), (gdouble)GOP);
  766.  
  767.     slider_updated_actions(GOP);
  768. }
  769.  
  770. void
  771. on_GOP_selector_spinbutton_value_changed
  772.                                         (GtkSpinButton   *spinbutton,
  773.                                         gpointer         user_data)
  774. {
  775.     uint32_t GOP;
  776.  
  777.     GOP = (uint32_t) gtk_spin_button_get_value(spinbutton);
  778.     gtk_range_set_value(GTK_RANGE(GOP_selector), (gdouble)GOP);
  779.  
  780.     slider_updated_actions(GOP);
  781. }
  782.  
  783. void
  784. on_slider_run_speed_value_changed      (GtkRange        *range,
  785.                                         gpointer         user_data)
  786. {
  787.     options.run_speed = (int) gtk_range_get_value(range);
  788. }
  789. /*
  790.  * #############################################################################
  791.  * ######################## End Main Window Related Functions ##################
  792.  * #############################################################################
  793.  */
  794.  
  795.  
  796. static gboolean run_saved_refresh = true;
  797. void on_button_run_toggled(GtkToggleButton * togglebutton, gpointer user_data)
  798. {
  799.     uint32_t GOPs, i;
  800.  
  801.     GOPs = mpeg2parser->numGOPs();
  802.     i = get_GOP_selected();
  803.  
  804.     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(togglebutton))) {
  805.         // if you clicked "Run", you want to see it...
  806.         run_saved_refresh = options.auto_refresh;
  807.         options.auto_refresh = true;
  808.     }
  809.  
  810.     while (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(togglebutton)))
  811.     {
  812.         set_GOP_selected(i);
  813.         flush();
  814.         i = get_GOP_selected();
  815.         i+=options.run_speed;
  816.         if (i >= GOPs)
  817.         {
  818.             if (options.run_loop)
  819.                 i = 0;
  820.             else
  821.             {
  822.                 // flip back off now
  823.                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togglebutton),
  824.                                              FALSE);
  825.                 flush();
  826.             }
  827.         }
  828.     }
  829.     flush();
  830.     display_flush(engine);
  831.  
  832.     options.auto_refresh = run_saved_refresh;
  833. }
  834.  
  835.  
  836. void on_about_window_destroy(GtkObject * object, gpointer user_data)
  837. {
  838.     about_window = NULL;
  839. }
  840.  
  841.  
  842. void on_about_button_cool_clicked(GtkButton * button, gpointer user_data)
  843. {
  844.     gtk_widget_hide(about_window);
  845.     gtk_widget_destroy(about_window);
  846. }
  847.  
  848.  
  849. void on_error_button_annoying_clicked(GtkButton * button, gpointer user_data)
  850. {
  851.     gtk_widget_hide(error_dialog);
  852. }
  853.  
  854. void
  855. on_button_start_mark_toggled           (GtkToggleButton *togglebutton,
  856.                                         gpointer         user_data)
  857. {
  858.     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(togglebutton))) {
  859.         /* start mark */
  860.         char buf[128];
  861.         mark_start = get_GOP_selected();
  862.  
  863.         gtk_widget_set_sensitive(button_end_mark, TRUE);
  864.  
  865.         sprintf(buf, "%d", mark_start);
  866.         gtk_label_set_text(GTK_LABEL(main_label_mark), buf);
  867.     }
  868.     else {
  869.         /* undo start mark */
  870.         gtk_widget_set_sensitive(button_end_mark, FALSE);
  871.         gtk_label_set_text(GTK_LABEL(main_label_mark), "no mark set");
  872.     }
  873. }
  874.  
  875. void on_button_end_mark_clicked(GtkButton * button, gpointer user_data)
  876. {
  877.     mark_end = get_GOP_selected();
  878.  
  879.     if (mark_end >= mark_start)
  880.     {
  881.         gtk_widget_set_sensitive(button_end_mark, FALSE);
  882.         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_start_mark),
  883.                                      FALSE);
  884.  
  885.         gtk_label_set_text(GTK_LABEL(main_label_mark), "no mark set");
  886.  
  887.         add_GOP_slice(mark_start, mark_end);
  888.     }
  889.     else
  890.     {
  891.         // FIXME: do something to "flash" the startmark label
  892.     }
  893. }
  894.  
  895.  
  896. void on_button_refresh_clicked(GtkButton * button, gpointer user_data)
  897. {
  898.     show_GOP(engine,get_GOP_selected());
  899.     display_redraw(engine);
  900. }
  901.  
  902.  
  903. gboolean
  904. on_main_clist_key_press_event(GtkWidget * widget,
  905.                               GdkEventKey * event, gpointer user_data)
  906. {
  907.     GtkTreeSelection *selection;
  908.     GtkTreeIter       iter;
  909.  
  910.     selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
  911.     if (!gtk_tree_selection_get_selected(selection, NULL, &iter)) {
  912.         return FALSE; /* nothing selected: skip */
  913.     }
  914.  
  915.     switch (event->keyval)
  916.     {
  917.     case GDK_Delete:
  918.     case GDK_KP_Delete:
  919.     case GDK_BackSpace:
  920.         remove_GOP_slice(&iter);
  921.         return TRUE;
  922.     }
  923.     return FALSE;
  924. }
  925.  
  926.  
  927. gboolean
  928. on_main_clist_button_press_event(GtkWidget * widget,
  929.                                  GdkEventButton * event, gpointer user_data)
  930. {
  931.  
  932. #if 0
  933.     if (event->button == 3)     // right-click
  934.     {
  935.         main_popup_info.x = event->x;
  936.         main_popup_info.y = event->y;
  937.         gtk_menu_popup(GTK_MENU(main_popup), NULL, NULL, NULL,
  938.                        &main_popup_info, event->button, event->time);
  939.         return TRUE;
  940.     }
  941. #endif
  942.  
  943.     return FALSE;
  944. }
  945.  
  946.  
  947. void on_main_popup_delete_activate(GtkMenuItem * menuitem, gpointer user_data)
  948. {
  949.     gint row, col;
  950.     popup_info_t *info;
  951.  
  952.     fprintf( stderr, "on_main_popup_delete_activate\n" );
  953.  
  954.     if (info = (popup_info_t *) user_data)
  955.     {
  956.         gtk_clist_get_selection_info(GTK_CLIST(main_clist),
  957.                                      info->x, info->y, &row, &col);
  958.  
  959.         //printf("bloa! (x %d y %d is row %d col %d)\n");
  960.     }
  961.     else
  962.         printf("%s",
  963.                _("Oops.  NULL info in on_main_popup_delete_activate\n"));
  964.  
  965. }
  966.  
  967.  
  968. void on_save_file_window_destroy(GtkObject * object, gpointer user_data)
  969. {
  970.     save_file_window = NULL;
  971. }
  972.  
  973.  
  974. void on_button_next_clicked(GtkButton * button, gpointer user_data)
  975. {
  976.     set_GOP_selected(get_GOP_selected() + 1);
  977. }
  978.  
  979.  
  980. void on_button_prev_clicked(GtkButton * button, gpointer user_data)
  981. {
  982.     uint32_t gop;
  983.  
  984.     // don't wrap to the end
  985.     gop=get_GOP_selected();
  986.     if (gop>0) {
  987.         gop--;
  988.     }
  989.     set_GOP_selected(gop);
  990. }
  991.  
  992.  
  993. #if 0
  994. void
  995. on_menu_options_ignore_errors_activate(GtkMenuItem * menuitem,
  996.                                        gpointer user_data)
  997. {
  998.     options.ignore_errors=GTK_CHECK_MENU_ITEM(menuitem)->active;
  999.     rc_save(PACKAGE,parsable_items);
  1000. }
  1001.  
  1002.  
  1003. void
  1004. on_menu_options_drop_orphaned_frames_activate
  1005.                                         (GtkMenuItem     *menuitem,
  1006.                                         gpointer         user_data)
  1007. {
  1008.     options.drop_orphaned_frames=GTK_CHECK_MENU_ITEM(menuitem)->active;
  1009.     rc_save(PACKAGE,parsable_items);
  1010. }
  1011.  
  1012.  
  1013.  
  1014. void
  1015. on_menu_options_adjust_timestamps_activate
  1016.                                         (GtkMenuItem     *menuitem,
  1017.                                         gpointer         user_data)
  1018. {
  1019.     options.adjust_timestamps=GTK_CHECK_MENU_ITEM(menuitem)->active;
  1020.     rc_save(PACKAGE,parsable_items);
  1021. }
  1022. #endif
  1023.  
  1024. gboolean
  1025. on_main_window_delete_event            (GtkWidget       *widget,
  1026.                                         GdkEvent        *event,
  1027.                                         gpointer         user_data)
  1028. {
  1029.     mpeg2parser->reset();
  1030.     gtk_main_quit();
  1031.  
  1032.     return FALSE;
  1033. }
  1034.  
  1035.  
  1036. gboolean
  1037. on_GOP_window_delete_event             (GtkWidget       *widget,
  1038.                                         GdkEvent        *event,
  1039.                                         gpointer         user_data)
  1040. {
  1041.     GtkWidget *menuitem;
  1042.  
  1043.     menuitem = GTK_WIDGET(lookup_widget(GTK_WIDGET(main_window), "menu_info_window"));
  1044.     gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(menuitem), FALSE );
  1045.     gtk_widget_hide(GOP_window);
  1046.     return TRUE;
  1047. }
  1048. /******************************************************************************/
  1049.