00001 #ifdef HAVE_CONFIG_H
00002 # include <config.h>
00003 #endif
00004
00005 #include <gnome.h>
00006
00007 #include "callbacks.h"
00008 #include "interface.h"
00009 #include "support.h"
00010 #include "morse.h"
00011 #include "interface_il.h"
00012 #include "prop_interface.h"
00013 #include "morse_stats_i.h"
00014
00015 static void read_main_gui_user_preferences(void);
00016
00017 gboolean
00018 on_MainWindow_delete_event (GtkWidget *widget,
00019 GdkEvent *event,
00020 gpointer user_data)
00021 {
00022 g_idle_add((GSourceFunc)threads_stop, NULL);
00023 read_main_gui_user_preferences();
00024 gtk_main_quit ();
00025 return FALSE;
00026 }
00027
00028
00029 void
00030 on_exit1_activate (GtkMenuItem *menuitem,
00031 gpointer user_data)
00032 {
00033 g_idle_add((GSourceFunc)threads_stop, NULL);
00034 read_main_gui_user_preferences();
00035 gtk_main_quit();
00036 }
00037
00038
00039 void
00040 on_statistics_activate (GtkMenuItem *menuitem,
00041 gpointer user_data)
00042 {
00043 static gboolean show_gb;
00044
00045 if(NULL == morse_stats) {
00046 morse_stats = create_stats_window();
00047 }
00048
00049 if(FALSE == show_gb) {
00050 gtk_widget_show(morse_stats);
00051 show_gb = TRUE;
00052 }
00053 else {
00054 gtk_widget_hide(morse_stats);
00055 show_gb = FALSE;
00056 }
00057 }
00058
00059
00060 void
00061 on_preferences_activate (GtkMenuItem *menuitem,
00062 gpointer user_data)
00063 {
00064 main_gui.properties_v = create_morse2txt_properties ();
00065 gtk_widget_show (main_gui.properties_v);
00066 }
00067
00068 void
00069 on_filter_bw_activate (GtkMenuItem *menuitem,
00070 gpointer user_data)
00071 {
00072 int freq;
00074 char *tmp = ((char*)user_data);
00075
00076 switch(tmp[0]) {
00077 case 'a':
00078 freq = 25;
00079 break;
00080
00081 case 'b':
00082 freq = 50;
00083 break;
00084
00085 case 'c':
00086 freq = 100;
00087 break;
00088
00089 case 'd':
00090 freq = 150;
00091 break;
00092
00093 case 'e':
00094 freq = 200;
00095 break;
00096
00097 case 'f':
00098 freq = 250;
00099 break;
00100
00101 case 'g':
00102 freq = 500;
00103 break;
00104
00105 default:
00106 case 'h':
00107 freq = 1000;
00108 break;
00109 }
00110 morse_set_filter_bandwidth(freq);
00111 }
00112
00113 void
00114 on_icons_and_or_text_activate (GtkMenuItem *menuitem,
00115 gpointer user_data)
00116 {
00118 char *tmp = ((char*)user_data);
00119
00120 switch(tmp[0])
00121 {
00122 case 'a':
00123 if(main_gui.toolbar1_v) {
00124 gtk_toolbar_set_style (GTK_TOOLBAR(main_gui.toolbar1_v), GTK_TOOLBAR_ICONS);
00125 }
00126 main_gui.toolbar_style = GTK_TOOLBAR_ICONS;
00127 break;
00128
00129 case 'b':
00130 if(main_gui.toolbar1_v) {
00131 gtk_toolbar_set_style(GTK_TOOLBAR(main_gui.toolbar1_v), GTK_TOOLBAR_TEXT);
00132 }
00133 main_gui.toolbar_style = GTK_TOOLBAR_TEXT;
00134 break;
00135
00136 default:
00137 case 'c':
00138 if(main_gui.toolbar1_v) {
00139 gtk_toolbar_set_style (GTK_TOOLBAR(main_gui.toolbar1_v), GTK_TOOLBAR_BOTH);
00140 }
00141 main_gui.toolbar_style = GTK_TOOLBAR_BOTH;
00142 break;
00143 }
00144 }
00145
00146 void
00147 on_startbutton_clicked (GtkToolButton *toolbutton,
00148 gpointer user_data)
00149 {
00150 if(morse_get_thread_state() == THREADS_NOT_RUNNING) {
00151 if(
00152 (0 == plot_fft_data_array_create( get_tone_packet_size() ))
00153 && \
00154 (0 == morse_start_threads())
00155 )
00156 {
00157 preferences_enabled(FALSE);
00158 }
00159 else {
00160 preferences_enabled(TRUE);
00161 }
00162 }
00163 }
00164
00165 void
00166 on_stop_button_clicked (GtkToolButton *toolbutton,
00167 gpointer user_data)
00168 {
00169 g_idle_add((GSourceFunc)threads_stop, NULL);
00170 }
00171
00172 void
00173 on_clear_txt_button_clicked (GtkToolButton *toolbutton,
00174 gpointer user_data)
00175 {
00176 GtkTextIter start, end;
00177
00178 gtk_text_buffer_get_bounds(GTK_TEXT_VIEW(main_gui.decoded_text_v)->buffer, &start, &end);
00179 gtk_text_buffer_delete(GTK_TEXT_VIEW(main_gui.decoded_text_v)->buffer, &start, &end);
00180 }
00181
00182 void
00183 on_scope_fft_button_clicked (GtkToolButton *toolbutton,
00184 gpointer user_data)
00185 {
00186 switch(morse_get_plot_type()) {
00187 default:
00188 case PLOT_FFT:
00189 morse_set_plot_type(PLOT_SCOPE);
00190 gtk_widget_hide(main_gui.label1_v);
00191 gtk_widget_hide(main_gui.hscale1_v);
00192 gtk_curve_set_range(GTK_CURVE(main_gui.scope_v), 0.0, (gfloat)morse_get_fft_data_size(), -32000.0, 32000.0);
00193 break;
00194 case PLOT_SCOPE:
00195 morse_set_plot_type(PLOT_FFT);
00196 gtk_widget_show(main_gui.hscale1_v);
00197 gtk_widget_show(main_gui.label1_v);
00198 gtk_curve_set_range(GTK_CURVE(main_gui.scope_v), 0.0, (gfloat)morse_get_tone_packet_size(), 0.0, morse_get_fft_graph_top());
00199 break;
00200 }
00201 }
00202
00203 void
00204 on_agc_apply_btn_toggled (GtkToggleToolButton *toggletoolbutton,
00205 gpointer user_data)
00206 {
00207 te_morse_agc_enable tmp;
00208
00209 tmp = MORSE_DISABLE_AGC;
00210
00211 if(gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(toggletoolbutton)) == TRUE) {
00212 tmp = MORSE_ENABLE_AGC;
00213 }
00214 morse_set_agc_apply(tmp);
00215 }
00216
00217 void
00218 on_enable_fir_button_toggled (GtkToggleToolButton *toggletoolbutton,
00219 gpointer user_data)
00220 {
00221 te_morse_filter_enable tmp;
00222
00223 tmp = MORSE_DISABLE_FILTER;
00224
00225 if(gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(toggletoolbutton)) == TRUE) {
00226 tmp = MORSE_ENABLE_FILTER;
00227 }
00228 morse_set_filter_apply(tmp);
00229 }
00230
00231 void
00232 on_exit_button_clicked (GtkToolButton *toolbutton,
00233 gpointer user_data)
00234 {
00235 g_idle_add((GSourceFunc)threads_stop, NULL);
00236 read_main_gui_user_preferences();
00237 gtk_main_quit();
00238 }
00239
00240
00241 void
00242 on_adjustment_release_event (GtkAdjustment *widget,
00243 gpointer user_data)
00244 {
00245 morse_set_cw_frequency((int)gtk_adjustment_get_value(GTK_ADJUSTMENT(widget)));
00246 }
00247
00248 static void read_main_gui_user_preferences(void)
00249 {
00250 GtkWidget *widget;
00251 main_gui.x = GTK_WIDGET(main_gui.main_window_v)->allocation.x;
00252 main_gui.y = GTK_WIDGET(main_gui.main_window_v)->allocation.y;
00253 main_gui.width = GTK_WIDGET(main_gui.main_window_v)->allocation.width;
00254 main_gui.height = GTK_WIDGET(main_gui.main_window_v)->allocation.height;
00255 widget = lookup_widget(main_gui.main_window_v, "vpaned1");
00256 main_gui.pane_position = gtk_paned_get_position(GTK_PANED(widget));
00257 }