Esempio n. 1
0
int main(int argc, char *argv[])
{
    if(argc > 1)
    {
        if(strequ(argv[1], "--version"))
        {
            printf("Boggle Solver version 2.0\nBuild number %X\n", BUILDNUMBER);
            return 0;
        }
    }

    gdk_threads_init();

    // Load dictionary
    pthread_t dictThread;
    pthread_create(&dictThread, NULL, load_dict_threaded, NULL);
    pthread_detach(dictThread);

    GtkWidget *textbox_table, *solve_b, *clear_b, *list_scroll;

    gtk_init(&argc, &argv); //140

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_container_set_border_width(GTK_CONTAINER(window), 10);
    gtk_widget_set_size_request(window, 653, 485);
    gtk_window_set_title(GTK_WINDOW(window), "Boggle Solver");

    gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(delete_event), NULL);

    textbox_table = gtk_table_new(6, 5, FALSE);
    list = gtk_tree_view_new();

    list_scroll = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(list_scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);

    gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), FALSE);
    gtk_widget_set_size_request(list_scroll, 190, -1);
    gtk_container_add(GTK_CONTAINER(list_scroll), list);
    gtk_table_attach_defaults(GTK_TABLE(textbox_table), list_scroll, 4, 5, 0, 5);
    gtk_table_set_col_spacings(GTK_TABLE(textbox_table), 10);
    gtk_table_set_row_spacings(GTK_TABLE(textbox_table), 10);

    solve_b = gtk_button_new_with_label("Solve");
    clear_b = gtk_button_new_with_label("Clear");

    gtk_widget_set_size_request(solve_b, 100, 27);
    gtk_widget_set_size_request(clear_b, 100, 27);

    gtk_table_attach_defaults(GTK_TABLE(textbox_table), solve_b, 0, 1, 4, 5);
    gtk_table_attach_defaults(GTK_TABLE(textbox_table), clear_b, 3, 4, 4, 5);

    gtk_signal_connect(GTK_OBJECT(solve_b), "clicked", GTK_SIGNAL_FUNC(solve_clicked), NULL);
    gtk_signal_connect(GTK_OBJECT(clear_b), "clicked", GTK_SIGNAL_FUNC(clear_clicked), NULL);

    int x, y;
    for(x = 0; x < 4; x++)
    {
        for(y = 0; y < 4; y++)
        {
            textboxes[x][y] = gtk_entry_new();
            GtkWidget *tb = textboxes[x][y];
            int *idx = malloc(sizeof(int));
            *idx = y * 4 + x;
            gtk_entry_set_max_length(GTK_ENTRY(tb), 1);
            gtk_table_attach_defaults(GTK_TABLE(textbox_table), tb, x, x + 1, y, y + 1);
            gtk_entry_set_width_chars(GTK_ENTRY(tb), 5);
            gtk_entry_set_alignment(GTK_ENTRY(tb), 0.5);
            gtk_widget_set_size_request(tb, 100, 100);
            gtk_widget_modify_font(tb, pango_font_description_from_string("Ubuntu 55"));
            gtk_signal_connect(GTK_OBJECT(tb), "backspace", GTK_SIGNAL_FUNC(backspace_pressed), NULL);
            gtk_signal_connect(GTK_OBJECT(tb), "key-press-event", GTK_SIGNAL_FUNC(key_pressed), NULL);
            gtk_signal_connect(GTK_OBJECT(tb), "button-press-event", GTK_SIGNAL_FUNC(tb_focus), idx);
        }
    }

    gtk_container_add(GTK_CONTAINER(window), textbox_table);

    init_list(list);

    gtk_widget_show_all(window);

    gtk_main();

    dict_clean_up();

    gdk_threads_leave();

    return 0;
}
/**
 * @fn int main (int argc, char **argv)
 * @brief Main program & Gtk thread.
 *
 * Create window and all widgets, then set there parameters to be the <br>
 * ROS params.
 */
int main (int argc, char **argv)
{
    GtkBuilder *builder;
    GdkColor black = { 0, 0, 0, 0 };
    GError *error = NULL;
    char glade_gui_file[FILENAME_MAX];
    int start_zoom = 15;
    char *mapcachedir;
    OsmGpsMapPoint ccny_coord = { 40.818551, -73.948674 };

    struct arg param;
    param.argc = argc;
    param.argv = argv;

    pthread_t rosThread;

    // **** init threads
    g_thread_init (NULL);
    gdk_threads_init ();
    gdk_threads_enter ();

    // **** init gtk
    gtk_init (&argc, &argv);

    // **** allocate data structure
    data = g_slice_new (AppData);

    // **** set the glade gui file & set icon directory
    std::string package_path = ros::package::getPath (ROS_PACKAGE_NAME);
    sprintf (glade_gui_file, "%s/gui/%s", package_path.c_str (), "gui.glade");
    sprintf (data->icon_directory, "%s/gui/icon", package_path.c_str ());

    std::string rosbag_path = ros::package::getPath("rosbag");
    sprintf (data->rosbag_rec_path, "%s/bin/record", rosbag_path.c_str ());

    data->current_page = 0;
    data->telemetry_opt_popup_state = false;
    data->gps_opt_popup_state = false;
    data->fullscreen = false;
    load_icon ();

    // **** Create new GtkBuilder object
    builder = gtk_builder_new ();
    // **** Load UI from file
    if (!gtk_builder_add_from_file (builder, glade_gui_file, &error))
    {
        g_warning ("%s", error->message);
        g_free (error);
        exit (-1);
    }

    // **** Get main window pointer from UI
    data->window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
    gtk_window_set_title (GTK_WINDOW (data->window), "CityFlyer Ground Station");
    gtk_window_set_position (GTK_WINDOW (data->window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size (GTK_WINDOW (data->window), 1024, 576);

    // **** create ROS thread
    pthread_create (&rosThread, NULL, startROS, &param);

    // **** wait ros finish read params
    while (!data->ros_param_read)
    {
        ROS_DEBUG ("Waiting ROS params");
    }

    // **** Get GtkNotebook objsect
    data->notebook = GTK_WIDGET (gtk_builder_get_object (builder, "notebook1"));

    // #####################################################################
    // #####################################################################
    // **** Tab 1: Telemetry

    // **** create altimeter widgets
    data->alt = gtk_altimeter_new ();
    g_object_set (GTK_ALTIMETER (data->alt),
                  "grayscale-color", data->grayscale_color,
                  "unit-is-feet", data->altimeter_unit_is_feet,
                  "unit-step-value", data->altimeter_step_value, "radial-color", data->radial_color, NULL);

    // **** create compass widgets
    data->comp = gtk_compass_new ();
    g_object_set (GTK_COMPASS (data->comp),
                  "grayscale-color", data->grayscale_color, "radial-color", data->radial_color, NULL);

    data->comp2 = gtk_compass_new ();
    g_object_set (GTK_COMPASS (data->comp2),
                  "grayscale-color", data->grayscale_color, "radial-color", data->radial_color, NULL);

    data->gauge1 = gtk_gauge_new ();
    g_object_set (GTK_GAUGE (data->gauge1), "name", data->gauge1_name_f, NULL);
    g_object_set (GTK_GAUGE (data->gauge1),
                  "grayscale-color", data->grayscale_color,
                  "radial-color", data->radial_color,
                  "start-value", data->gauge1_start_value,
                  "end-value", data->gauge1_end_value,
                  "initial-step", data->gauge1_initial_step,
                  "sub-step", (gdouble) data->gauge1_sub_step,
                  "drawing-step", data->gauge1_drawing_step,
                  "color-strip-order", data->gauge1_color_strip_order,
                  "green-strip-start", data->gauge1_green_strip_start,
                  "yellow-strip-start", data->gauge1_yellow_strip_start,
                  "red-strip-start", data->gauge1_red_strip_start, NULL);

    // **** create artificial horizon widgets
    data->arh = gtk_artificial_horizon_new ();
    g_object_set (GTK_ARTIFICIAL_HORIZON (data->arh),
                  "grayscale-color", data->grayscale_color, "radial-color", data->radial_color, NULL);

    // **** create variometer widgets
    data->vario = gtk_variometer_new ();
    g_object_set (GTK_VARIOMETER (data->vario),
                  "grayscale-color", data->grayscale_color,
                  "unit-is-feet", data->variometer_unit_is_feet,
                  "unit-step-value", data->variometer_step_value, "radial-color", data->radial_color, NULL);

    data->widget_table = GTK_WIDGET (gtk_builder_get_object (builder, "table_Widgets"));
    gtk_table_attach_defaults (GTK_TABLE (data->widget_table), data->alt, 0, 1, 0, 1);
    gtk_table_attach_defaults (GTK_TABLE (data->widget_table), data->arh, 1, 2, 0, 1);
    gtk_table_attach_defaults (GTK_TABLE (data->widget_table), data->comp, 2, 3, 0, 1);
    gtk_table_attach_defaults (GTK_TABLE (data->widget_table), data->vario, 0, 1, 1, 2);
    gtk_table_attach_defaults (GTK_TABLE (data->widget_table), data->comp2, 1, 2, 1, 2);
    gtk_table_attach_defaults (GTK_TABLE (data->widget_table), data->gauge1, 2, 3, 1, 2);

    gtk_widget_modify_bg (data->alt, GTK_STATE_NORMAL, &black);
    gtk_widget_modify_bg (data->comp, GTK_STATE_NORMAL, &black);
    gtk_widget_modify_bg (data->comp2, GTK_STATE_NORMAL, &black);
    gtk_widget_modify_bg (data->arh, GTK_STATE_NORMAL, &black);
    gtk_widget_modify_bg (data->gauge1, GTK_STATE_NORMAL, &black);
    gtk_widget_modify_bg (data->vario, GTK_STATE_NORMAL, &black);

    data->telemetry_option_popup = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_TelemetryOption"));
    data->btn_open_telemetry_option_popup =
        GTK_WIDGET (gtk_builder_get_object (builder, "button_OpenTelemetryOptionPopup"));
    data->btn_close_telemetry_option_popup =
        GTK_WIDGET (gtk_builder_get_object (builder, "button_CloseTelemetryOptionPopup"));
    gtk_button_set_image (GTK_BUTTON (data->btn_open_telemetry_option_popup),
                          gtk_image_new_from_pixbuf (gdk_pixbuf_scale_simple
                                  (data->leftarrow_icon_64, 24, 50, GDK_INTERP_HYPER)));
    gtk_button_set_image (GTK_BUTTON (data->btn_close_telemetry_option_popup),
                          gtk_image_new_from_pixbuf (gdk_pixbuf_scale_simple
                                  (data->rightarrow_icon_64, 24, 50, GDK_INTERP_HYPER)));

    // #####################################################################
    // #####################################################################
    // **** Tab 2: Gps

    // Some GpsdViewer initialisation
    data->draw_path = false;
    data->map_provider = OSM_GPS_MAP_SOURCE_OPENSTREETMAP;
    data->map_zoom_max = 18;
    data->map_current_zoom = start_zoom;
    data->repo_uri = osm_gps_map_source_get_repo_uri (data->map_provider);
    data->friendly_name = osm_gps_map_source_get_friendly_name (data->map_provider);
    data->uav_track = osm_gps_map_track_new ();
    mapcachedir = osm_gps_map_get_default_cache_directory ();
    data->cachedir = g_build_filename (mapcachedir, data->friendly_name, NULL);
    g_free (mapcachedir);

    // Create the OsmGpsMap object
    data->map = (OsmGpsMap *) g_object_new (OSM_TYPE_GPS_MAP,
                                            "map-source", data->map_provider,
                                            "tile-cache", data->cachedir, "proxy-uri", g_getenv ("http_proxy"), NULL);

    //Set the starting coordinates and zoom level for the map
    osm_gps_map_set_zoom (data->map, start_zoom);
    osm_gps_map_set_center (data->map, ccny_coord.rlat, ccny_coord.rlon);

    data->osd = gpsd_viewer_osd_new ();
    g_object_set (GPSD_VIEWER_OSD (data->osd),
                  "show-scale", true,
                  "show-coordinates", true,
                  "show-dpad", true,
                  "show-zoom", true, "show-gps-in-dpad", true, "show-gps-in-zoom", false, "dpad-radius", 30, NULL);
    osm_gps_map_layer_add (OSM_GPS_MAP (data->map), OSM_GPS_MAP_LAYER (data->osd));

    data->map_box = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_map_box"));
    data->map_container = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_map_container"));
    gtk_box_pack_start (GTK_BOX (data->map_box), GTK_WIDGET (data->map), TRUE, TRUE, 0);

    data->gpsd_option_popup = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_GpsdOptionPopup"));
    data->btn_open_gpsd_option_popup = GTK_WIDGET (gtk_builder_get_object (builder, "button_OpenGpsdOptionPopup"));
    data->btn_close_gpsd_option_popup = GTK_WIDGET (gtk_builder_get_object (builder, "button_CloseGpsdOptionPopup"));
    gtk_button_set_image (GTK_BUTTON (data->btn_open_gpsd_option_popup),
                          gtk_image_new_from_pixbuf (gdk_pixbuf_scale_simple
                                  (data->leftarrow_icon_64, 24, 50, GDK_INTERP_HYPER)));
    gtk_button_set_image (GTK_BUTTON (data->btn_close_gpsd_option_popup),
                          gtk_image_new_from_pixbuf (gdk_pixbuf_scale_simple
                                  (data->rightarrow_icon_64, 24, 50, GDK_INTERP_HYPER)));

    // #####################################################################
    // #####################################################################
    // **** Tab 3: Rec

    data->recording = 0;
    data->rosbag_record_cmd = "rosbag record";
    data->topicsList = GTK_LIST_STORE (gtk_builder_get_object (builder, "liststore_TopicList"));
    data->cmd_line_entry = GTK_WIDGET (gtk_builder_get_object (builder, "entry_CommandLine"));
    data->prefix_entry = GTK_WIDGET (gtk_builder_get_object (builder, "entry_Prefix"));
    data->info_textview = GTK_WIDGET (gtk_builder_get_object (builder, "textview_BagInfo"));
    data->update_btn = GTK_WIDGET (gtk_builder_get_object (builder, "button_UpdateTopicList"));
    data->box_MotorStatus = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_MotorStatus"));
    data->box_Flying = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_Flying"));
    data->box_Gps = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_Gps"));
    data->flightMode_label = GTK_WIDGET (gtk_builder_get_object (builder, "label_FlightModeValue"));
    data->upTime_label = GTK_WIDGET (gtk_builder_get_object (builder, "label_UpTimeValue"));
    data->cpuLoad_label = GTK_WIDGET (gtk_builder_get_object (builder, "label_CpuLoadValue"));
    data->box_RecordStatus = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_RecordStatus"));
    data->record_stop_btn = GTK_WIDGET (gtk_builder_get_object (builder, "button_RecordStop"));

    gtk_box_pack_end (GTK_BOX (data->box_MotorStatus), data->status_ok_icon_motor, TRUE, TRUE, 0);
    gtk_box_pack_end (GTK_BOX (data->box_MotorStatus), data->status_fail_icon_motor, TRUE, TRUE, 0);
    gtk_box_pack_end (GTK_BOX (data->box_Flying), data->status_ok_icon_flying, TRUE, TRUE, 0);
    gtk_box_pack_end (GTK_BOX (data->box_Flying), data->status_fail_icon_flying, TRUE, TRUE, 0);
    gtk_box_pack_end (GTK_BOX (data->box_Gps), data->status_ok_icon_gps, TRUE, TRUE, 0);
    gtk_box_pack_end (GTK_BOX (data->box_Gps), data->status_fail_icon_gps, TRUE, TRUE, 0);
    gtk_box_pack_end (GTK_BOX (data->box_RecordStatus), data->record_icon, TRUE, TRUE, 0);
    gtk_box_pack_end (GTK_BOX (data->box_RecordStatus), data->record_g_icon, TRUE, TRUE, 0);

    gtk_button_set_image (GTK_BUTTON (data->update_btn),
                          gtk_image_new_from_pixbuf (gdk_pixbuf_scale_simple
                                  (data->refresh_icon_64, 24, 24, GDK_INTERP_HYPER)));
    gtk_button_set_image (GTK_BUTTON (data->record_stop_btn),
                          gtk_image_new_from_pixbuf (gdk_pixbuf_scale_simple
                                  (data->record_icon_64, 40, 40, GDK_INTERP_HYPER)));

    // Connect signals
    gtk_builder_connect_signals (builder, data);

    // Destroy builder, since we don't need it anymore
    g_object_unref (G_OBJECT (builder));

    // Show window. All other widgets are automatically shown by GtkBuilder
    gtk_widget_show_all (data->window);
    gtk_widget_hide(data->record_icon);
    gtk_widget_hide(data->status_ok_icon_motor);
    gtk_widget_hide(data->status_ok_icon_flying);
    gtk_widget_hide(data->status_ok_icon_gps);
    gtk_widget_hide_all(data->telemetry_option_popup);
    gtk_widget_hide_all(data->gpsd_option_popup);

    // **** allow ROS spinning
    data->widget_created = true;

    // **** udpate all widgets
    g_timeout_add (data->telemetry_refresh_rate, widgets_update, NULL);

    gtk_main ();
    gdk_threads_leave ();
    return 0;
}
Esempio n. 3
0
/* build a simple gui w/:
 *   - a combo box to select the desired video device
 *   - the zbar widget to display video
 *   - a non-editable text box to display any results
 */
int main (int argc, char *argv[])
{
    g_thread_init(NULL);
    gdk_threads_init();
    gdk_threads_enter();

    gtk_init(&argc, &argv);
    const char *video_arg = NULL;
    if(argc > 1)
        video_arg = argv[1];

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    gtk_window_set_title(GTK_WINDOW(window), "test_gtk");
    gtk_container_set_border_width(GTK_CONTAINER(window), 8);

    g_signal_connect(G_OBJECT(window), "destroy",
                     G_CALLBACK(gtk_main_quit), NULL);

    GtkWidget *zbar = zbar_gtk_new();

    g_signal_connect(G_OBJECT(zbar), "decoded",
                     G_CALLBACK(decoded), NULL);

    /* video device list combo box */
    GtkWidget *video_list = gtk_combo_box_new_text();

    g_signal_connect(G_OBJECT(video_list), "changed",
                     G_CALLBACK(video_changed), zbar);

    /* enable/disable status button */
    GtkWidget *status_button = gtk_toggle_button_new();
    status_image = gtk_image_new_from_stock(GTK_STOCK_NO,
                                            GTK_ICON_SIZE_BUTTON);
    gtk_button_set_image(GTK_BUTTON(status_button), status_image);
    gtk_button_set_label(GTK_BUTTON(status_button), "closed");
    gtk_widget_set_sensitive(status_button, FALSE);

    /* bind status button state and video state */
    g_signal_connect(G_OBJECT(status_button), "toggled",
                     G_CALLBACK(status_button_toggled), zbar);
    g_signal_connect(G_OBJECT(zbar), "notify::video-enabled",
                     G_CALLBACK(video_enabled), status_button);
    g_signal_connect(G_OBJECT(zbar), "notify::video-opened",
                     G_CALLBACK(video_opened), status_button);

    /* open image file button */
    GtkWidget *open_button = gtk_button_new_from_stock(GTK_STOCK_OPEN);

    g_signal_connect(G_OBJECT(open_button), "clicked",
                     G_CALLBACK(open_button_clicked), zbar);

    gtk_combo_box_append_text(GTK_COMBO_BOX(video_list), "<none>");
    int active = scan_video(gtk_combo_box_append_text, video_list, video_arg);
    if(active >= 0)
        gtk_combo_box_set_active(GTK_COMBO_BOX(video_list), active);

    /* hbox for combo box and buttons */
    GtkWidget *hbox = gtk_hbox_new(FALSE, 8);

    gtk_box_pack_start(GTK_BOX(hbox), video_list, TRUE, TRUE, 0);
    gtk_box_pack_start(GTK_BOX(hbox), status_button, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(hbox), open_button, FALSE, FALSE, 0);

    /* text box for holding results */
    results = GTK_TEXT_VIEW(gtk_text_view_new());
    gtk_widget_set_size_request(GTK_WIDGET(results), 320, 64);
    gtk_text_view_set_editable(results, FALSE);
    gtk_text_view_set_cursor_visible(results, FALSE);
    gtk_text_view_set_left_margin(results, 4);

    /* vbox for hbox, zbar test widget and result text box */
    GtkWidget *vbox = gtk_vbox_new(FALSE, 8);
    gtk_container_add(GTK_CONTAINER(window), vbox);

    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(vbox), zbar, TRUE, TRUE, 0);
    gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(results), FALSE, FALSE, 0);

    GdkGeometry hints;
    hints.min_width = 320;
    hints.min_height = 240;
    gtk_window_set_geometry_hints(GTK_WINDOW(window), zbar, &hints,
                                  GDK_HINT_MIN_SIZE);

    gtk_widget_show_all(window);
    gtk_main();
    gdk_threads_leave();
    return(0);
}
Esempio n. 4
0
void remmina_public_threads_leave(void* data)
{
	gdk_threads_leave();
}
Esempio n. 5
0
static int
ui_gtk_query_ident_operation(ident_t *ident, const char *operation, 
			       const char* true_op, const char *false_op)
{
	const char *templ = 
		"<big>%s identity?</big>\n\nYour confirmation is required for %sing the identity <b>%s</b> %s:\n  Name: <i>%s</i>\n  Certified name: <i>%s</i>\n  Issued by: <i>%s</i>\n  Valid from: <i>%s</i>\n  Until: <i>%s</i>\n";
	char *str = 0;
	time_t start, end;
	GtkDialog *diag = 0;
	char startb[64], endb[64], *issuer = 0, *cname = 0, *op2 = 0, *tmp, *aor = 0, *uname = 0;
	int ret = 0;

	gdk_threads_enter();
		
	/* cert data */
	if (!(issuer = ident_data_x509_get_cn(X509_get_issuer_name(ident->cert)))) {
		ASSERT_TRUE(issuer = strdup("UNKNOWN ISSUER"), err);
	}

	if (!(cname = ident_data_x509_get_cn(X509_get_subject_name(ident->cert)))) {
		ASSERT_TRUE(cname = strdup("UNKNOWN SUBJECT"), err);
	}
	
	/* validity */
	ASSERT_ZERO(ident_data_x509_get_validity(ident->cert, &start, &end), err);
	ship_format_time_human(start, startb, sizeof(startb));
	ship_format_time_human(end, endb, sizeof(endb));
	
	ASSERT_TRUE(op2 = strdup(operation), err);
	ASSERT_TRUE(aor = ship_pangoify(ident->sip_aor), err);
	ASSERT_TRUE(uname = ship_pangoify(ident->username), err);
	ASSERT_TRUE(tmp = ship_pangoify(cname), err);
	freez(cname); cname = tmp;
	ASSERT_TRUE(tmp = ship_pangoify(issuer), err);
	freez(issuer); issuer = tmp;
	
	str = malloc(strlen(templ) + strlen(startb) + strlen(endb) + strlen(issuer) 
		     + strlen(cname) 
		     + strlen(aor) + strlen(uname)
		     + 1024);

	op2[0] = toupper(op2[0]);
	if (!strcmp(operation, "replace")) {
		sprintf(str, templ,
			"Replace", "replace", aor, "New identity", uname,
			cname, issuer, startb, endb);
	} else {
		sprintf(str, templ,
			op2, operation, aor, "Details", uname,
			cname, issuer, startb, endb);
	}
	
	ASSERT_TRUE(diag = (GtkDialog*)gtk_message_dialog_new_with_markup(NULL,
									  GTK_DIALOG_MODAL,
									  GTK_MESSAGE_QUESTION,
									  GTK_BUTTONS_NONE,
									  str,
									  NULL), err);
	gtk_dialog_add_buttons(diag, op2, 1, "Cancel", 0, NULL);
	
	ret = gtk_dialog_run(diag);
	gtk_widget_destroy((GtkWidget*)diag);
 err:
	gdk_threads_leave();

	freez(op2);
	freez(str);
	freez(issuer);
	freez(cname);
	freez(uname);
	freez(aor);
	return ret;
}
Esempio n. 6
0
int main(int argc, char *argv[])
{
// Check for big files

#ifdef     __USE_LARGEFILE
#ifdef   __USE_LARGEFILE64
printf("\n LARGE FILE AVAILABLE : %d offset\n",  __USE_FILE_OFFSET64	);
#endif
#endif

/*
	Initialize Gettext if available
*/
#ifdef HAVE_DCGETTEXT
  setlocale (LC_ALL, "");

//#define ALOCALES "/usr/local/share/locale"
  bindtextdomain ("avidemux", ADMLOCALE);
  textdomain ("avidemux");
  printf("Locales for %s appear to be in %s\n","avidemux", ADMLOCALE);
  printf("\nI18N : %s \n",dgettext("avidemux","_File"));
#endif



// thx smurf uk :)
     signal(11, sig_segfault_handler); // show stacktrace on default

	printf("\n*******************\n");
	printf("  Avidemux 2, v  " VERSION "\n");
	printf("*******************\n");
	printf(" http://fixounet.free.fr/avidemux\n");
	printf(" Code      : Mean & JSC \n");
	printf(" GFX       : Nestor Di , [email protected]\n");
	printf(" Testing   : Jakub Misak\n");
	printf(" FreeBSD   : Anish Mistry, [email protected]\n");


#if (defined( ARCH_X86)  || defined(ARCH_X86_64))
	printf("Arcc X86 X86_64 activated.\n"); 	
#endif
   

#ifdef USE_XX_XVID_CVS
	printf("Probing XvidCVS library....\n");
 	dloadXvidCVS(  );
#endif
   VPInitLibrary();
   register_Encoders( );
    atexit(onexit);

#ifndef CYG_MANGLING    
    g_thread_init(NULL);
    gdk_threads_init();
#endif
    gdk_threads_enter();
    gtk_set_locale();
    gtk_init(&argc, &argv);
    gdk_rgb_init();
#ifdef USE_XVID_4
	xvid4_init();
#endif
        initFileSelector();
	CpuCaps::init();
	ADM_InitMemcpy();
	
// Load .avidemuxrc
    quotaInit();
    prefs->load();

   if(!initGUI())
    	{
		printf("\n Fatal : could not init GUI\n");
		exit(-1);	
	}

    video_body = new ADM_Composer;
#ifdef HAVE_ENCODER
     registerVideoFilters(  );
#endif
     
#ifdef USE_FFMPEG
  
                		avcodec_init();
	                 	avcodec_register_all();
				mpegps_init();
	                  
#endif
#ifdef HAVE_AUDIO
    AVDM_audioInit();
#endif    
    buildDistMatrix();
    initScaleTab();

    loadEncoderConfig();
    COL_init();
    
   
    if (argc >= 2)
    {
			  global_argc=argc;
			  global_argv=argv;
			  gtk_timeout_add( 300, (GtkFunction )automation, NULL );
				//automation();				
		}
   #ifdef USE_SDL
   	printf("Global SDL init...\n");
   	SDL_Init(0); //SDL_INIT_AUDIO+SDL_INIT_VIDEO);
   #endif
    oplug_mpegInit();
	if(SpidermonkeyInit() == true)
		printf("Spidermonkey initialized.\n");
	gtk_main();
	gdk_threads_leave();

    return 0;
}
Esempio n. 7
0
static int
VGUI_init(void) {
 GtkWidget *box1;
 GtkWidget *menubar, *submenu, *menuitem;
 GtkWidget *topitem;
 GSList *colorgroup;

#ifdef USE_THREADING
 block_thread=g_cond_new();
#endif

 //printf("VGUI_init\n");
 gdk_threads_enter();

 Keyboard_Buffer_init();

 VGUI.window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 gtk_window_set_title (GTK_WINDOW (VGUI.window), "posplot");
 if (VGUI.width==0) {
  /* This means that we're executed for the first time */
  gtk_window_set_default_size(GTK_WINDOW(VGUI.window), FRAME_SIZE_X, FRAME_SIZE_Y);
 } else {
  gtk_window_set_default_size(GTK_WINDOW(VGUI.window), VGUI.width, VGUI.height);
 }
 g_signal_connect_object (G_OBJECT (VGUI.window), "delete_event", G_CALLBACK(window_destroy_event), G_OBJECT(VGUI.window), G_CONNECT_SWAPPED);
 g_signal_connect (G_OBJECT (VGUI.window), "configure_event", G_CALLBACK (window_configure_event), NULL);

 box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
 gtk_container_add (GTK_CONTAINER (VGUI.window), box1);
 gtk_widget_show (box1);

 menubar = gtk_menu_bar_new ();
 gtk_box_pack_start (GTK_BOX (box1), menubar, FALSE, TRUE, 0);
 gtk_widget_show (menubar);

 /* Dataset menu */
 submenu=gtk_menu_new();

 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("quit, accept epoch (q)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"q");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Quit, reject epoch (Q)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"Q");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Quit, reject epoch+stop iterated queue (V)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"V");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Stop (X)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"X");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 /* Separator: */
 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("About");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(posplot_about), NULL);
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 topitem= gtk_menu_item_new_with_label("Quitting");
 gtk_menu_item_set_submenu (GTK_MENU_ITEM (topitem), submenu);
 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), topitem);
 gtk_widget_show (topitem);
 /* Catch Keypress events also when the mouse points to the open menu: */
 g_signal_connect (G_OBJECT (submenu), "key_press_event", G_CALLBACK (key_press_event), NULL);

 /* Command menu */
 submenu=gtk_menu_new();

 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 /* Antialiasing doesn't look nice with lines */
 VGUI.antialias=CAIRO_ANTIALIAS_NONE;
 menuitem=gtk_check_menu_item_new_with_label("Antialias screen plot lines");
 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), VGUI.antialias==CAIRO_ANTIALIAS_DEFAULT);
 g_signal_connect (G_OBJECT (menuitem), "toggled", G_CALLBACK(toggle_antialias), NULL);
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 /* Separator: */
 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Start entering an argument (=)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"=");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 /* Separator: */
 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Insert trigger (N)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"N");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 /* Separator: */
 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Record interactions (r)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"r");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Replay interactions (R)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"R");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 /* Separator: */
 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Landscape postscript dump (o)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"o");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Portrait postscript dump (O)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"O");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_radio_menu_item_new_with_label(NULL, "Color postscript");
 colorgroup=gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(menuitem));
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(set_postscriptcolor), (gpointer)TRUE);
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_radio_menu_item_new_with_label(colorgroup, "B/W postscript");
 colorgroup=gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(menuitem));
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(set_postscriptcolor), (gpointer)FALSE);
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 { char * const post_dev=getenv(POSTSCRIPT_ENVNAME);
 /* posplot's default is color Postscript */
 if (post_dev!=NULL && strcmp(post_dev, POSTSCRIPT_BWDEV)==0) gtk_widget_activate(menuitem);
 }

 /* Separator: */
 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Dump current point as ARRAY_ASCII (y)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"y");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Dump current point full (Y)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"Y");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Write datasets (W)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"W");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 /* Separator: */
 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Grid channels (G)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"G");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Enter pos modify mode");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"=change\n_");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Leave/switch pos mode (_)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"_");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 /* Separator: */
 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Zero current point ($)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"$");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Detrend datasets (D)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"D");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Differentiate datasets (%)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"%");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Integrate datasets (&)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"&");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 topitem= gtk_menu_item_new_with_label("Commands");
 gtk_menu_item_set_submenu (GTK_MENU_ITEM (topitem), submenu);
 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), topitem);
 gtk_widget_show (topitem);
 /* Catch Keypress events also when the mouse points to the open menu: */
 g_signal_connect (G_OBJECT (submenu), "key_press_event", G_CALLBACK (key_press_event), NULL);

 /* Show menu */
 submenu=gtk_menu_new();

 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Plots (p)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"p");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Axes (x)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"x");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Names (n)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"n");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Marker (m)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"m");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Triggers (M)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"M");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Grayscale (d)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"d");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Info (?)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"?");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Triangulation (z)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"z");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 topitem= gtk_menu_item_new_with_label("Show");
 gtk_menu_item_set_submenu (GTK_MENU_ITEM (topitem), submenu);
 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), topitem);
 gtk_widget_show (topitem);
 /* Catch Keypress events also when the mouse points to the open menu: */
 g_signal_connect (G_OBJECT (submenu), "key_press_event", G_CALLBACK (key_press_event), NULL);

 /* Select menu */
 submenu=gtk_menu_new();

 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Point by argument (.)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)".");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Next point (i)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"i");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Previous point (I)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"I");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Left interval boundary ([)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"[");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Right interval boundary (])");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"]");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 /* Separator: */
 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Dataset by argument (,)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)",");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Toggle datasets (*)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"*");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Datasets up '('");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"(");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Datasets down ')'");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)")");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 /* Separator: */
 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Next item (})");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"}");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Previous item ({)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"{");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 /* Separator: */
 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("One channel (ENTER)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"\n");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Hide channel (BACKSPACE)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("All channels (C)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"C");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 topitem= gtk_menu_item_new_with_label("Select");
 gtk_menu_item_set_submenu (GTK_MENU_ITEM (topitem), submenu);
 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), topitem);
 gtk_widget_show (topitem);
 /* Catch Keypress events also when the mouse points to the open menu: */
 g_signal_connect (G_OBJECT (submenu), "key_press_event", G_CALLBACK (key_press_event), NULL);

 /* Transform menu */
 submenu=gtk_menu_new();

 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);


 menuitem=gtk_menu_item_new_with_label("Exponential (e)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"e");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Logarithm (E)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"E");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 /* Separator: */
 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Single item mode (')");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"'");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Absolute values (a)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"a");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Power values (P)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"P");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Phase values (A)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"A");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 topitem= gtk_menu_item_new_with_label("Transform");
 gtk_menu_item_set_submenu (GTK_MENU_ITEM (topitem), submenu);
 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), topitem);
 gtk_widget_show (topitem);
 /* Catch Keypress events also when the mouse points to the open menu: */
 g_signal_connect (G_OBJECT (submenu), "key_press_event", G_CALLBACK (key_press_event), NULL);

 /* View menu */
 submenu=gtk_menu_new();

 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Redraw (^L)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Vertical scale lock (v)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"v");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Set/Toggle subsampling (@)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"@");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Toggle black/white background (b)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"b");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Line style mode (u)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"u");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Set first line style (U)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"U");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Swap plus/minus (~)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"~");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Swap x-z (S)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"S");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 /* Separator: */
 menuitem=gtk_menu_item_new();
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Position mode (_)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"_");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Center channel (Z)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"Z");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Nearer (+)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"+");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Farther (-)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"-");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Turn l (h)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"h");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Turn r (l)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"l");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Turn u (k)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"k");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Turn d (j)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"j");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Twist l (t)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"t");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Twist r (T)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"T");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Enlarge FOV (/)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"/");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Decrease FOV (\\)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"\\");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Enlarge plots (>)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)">");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Shrink plots (<)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"<");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 menuitem=gtk_menu_item_new_with_label("Reset parameters (c)");
 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK(insert_key), (gpointer)"c");
 gtk_menu_shell_append (GTK_MENU_SHELL (submenu), menuitem);
 gtk_widget_show (menuitem);

 topitem= gtk_menu_item_new_with_label("View");
 gtk_menu_item_set_submenu (GTK_MENU_ITEM (topitem), submenu);
 gtk_menu_shell_append (GTK_MENU_SHELL (menubar), topitem);
 gtk_widget_show (topitem);
 /* Catch Keypress events also when the mouse points to the open menu: */
 g_signal_connect (G_OBJECT (submenu), "key_press_event", G_CALLBACK (key_press_event), NULL);

 VGUI.cr = NULL; /* Allocated by canvas_configure_event */
 VGUI.surface = NULL;
 VGUI.canvas = gtk_drawing_area_new ();
 gtk_widget_set_name (VGUI.canvas, "posplot");

 gtk_box_pack_start (GTK_BOX (box1), VGUI.canvas, TRUE, TRUE, 0);
 /* Otherwise, a DrawingArea cannot receive key presses: */
 gtk_widget_set_can_focus(VGUI.canvas, TRUE);
 gtk_widget_set_events(VGUI.canvas, GDK_EXPOSURE_MASK
		      | GDK_BUTTON_PRESS_MASK
		      | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK
		      | GDK_KEY_PRESS_MASK
		      | GDK_PROPERTY_CHANGE_MASK);
 g_signal_connect (G_OBJECT (VGUI.canvas), "configure_event", G_CALLBACK (canvas_configure_event), NULL);
#if GTK_MAJOR_VERSION==2
 g_signal_connect (G_OBJECT (VGUI.canvas), "expose_event", G_CALLBACK (canvas_expose_event), NULL);
#else
 g_signal_connect (G_OBJECT (VGUI.canvas), "draw", G_CALLBACK (canvas_draw_event), NULL);
#endif
 g_signal_connect (G_OBJECT (VGUI.canvas), "key_press_event", G_CALLBACK (key_press_event), NULL);
 g_signal_connect (G_OBJECT (VGUI.canvas), "button_press_event", G_CALLBACK (button_press_event), NULL);
 g_signal_connect (G_OBJECT (VGUI.canvas), "motion_notify_event", G_CALLBACK (motion_notify_event), NULL);

 gtk_widget_show (VGUI.canvas);
 gtk_widget_grab_focus(VGUI.canvas);

 gtk_widget_show (VGUI.window);

 VGUI.lastbutton=0;
 VGUI.in_frontbuffer=FALSE;

 gdk_threads_leave();

 /* Set the colors */
 VGUI.fg = BLACK;
 set_palette_entry(BLACK, 0.0, 0.0, 0.0);
 set_palette_entry(RED, 1.0, 0.0, 0.0);
 set_palette_entry(GREEN, 0.0, 1.0, 0.0);
 set_palette_entry(YELLOW, 1.0, 1.0, 0.0);
 set_palette_entry(BLUE, 0.0, 0.0, 1.0);
 set_palette_entry(MAGENTA, 1.0, 0.0, 1.0);
 set_palette_entry(CYAN, 0.0, 1.0, 1.0);
 set_palette_entry(WHITE, 1.0, 1.0, 1.0);

 //printf("VGUI_init end\n");

 return (1);
}
Esempio n. 8
0
int main(int argc, char **argv)
{
	GtkWidget *menubar = NULL;
	GtkWidget *table = NULL;
	GtkWidget *combo = NULL;
	GtkBin *bin = NULL;
	GtkViewport *view = NULL;
	int i=0;
	log_options_t lopts = LOG_OPTS_STDERR_ONLY;

	if (!getenv("SLURM_BITSTR_LEN"))
		setenv("SLURM_BITSTR_LEN", "128", 1);	/* More array info */
	slurm_conf_init(NULL);
	log_init(argv[0], lopts, SYSLOG_FACILITY_USER, NULL);
	load_defaults();
	cluster_flags = slurmdb_setup_cluster_flags();
	cluster_dims = slurmdb_setup_cluster_dims();

	_init_pages();
	sview_thread_init(NULL);
	gdk_threads_init();
	gdk_threads_enter();
	/* Initialize GTK */
	gtk_init (&argc, &argv);
	sview_mutex_new(&sview_mutex);
	sview_mutex_new(&grid_mutex);
	sview_cond_new(&grid_cond);
	/* make sure the system is up */
	grid_window = GTK_WIDGET(create_scrolled_window());
	bin = GTK_BIN(&GTK_SCROLLED_WINDOW(grid_window)->container);
	view = GTK_VIEWPORT(bin->child);
	bin = GTK_BIN(&view->bin);
	main_grid_table = GTK_TABLE(bin->child);
	gtk_table_set_homogeneous(main_grid_table, true);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(grid_window),
				       GTK_POLICY_NEVER,
				       GTK_POLICY_AUTOMATIC);

	/* fill in all static info for pages */
	/* Make a window */
	main_window = gtk_dialog_new();
	g_signal_connect(G_OBJECT(main_window), "delete_event",
			 G_CALLBACK(_delete), NULL);

	gtk_window_set_title(GTK_WINDOW(main_window), "Sview");
	gtk_window_set_default_size(GTK_WINDOW(main_window),
				    working_sview_config.main_width,
				    working_sview_config.main_height);
	gtk_container_set_border_width(
		GTK_CONTAINER(GTK_DIALOG(main_window)->vbox), 1);
	/* Create the main notebook, place the position of the tabs */
	main_notebook = gtk_notebook_new();
	g_signal_connect(G_OBJECT(main_notebook), "switch_page",
			 G_CALLBACK(_page_switched),
			 NULL);
	table = gtk_table_new(1, 3, false);
	gtk_table_set_homogeneous(GTK_TABLE(table), false);
	gtk_container_set_border_width(GTK_CONTAINER(table), 1);
	/* Create a menu */
	menubar = _get_menubar_menu(main_window, main_notebook);
	gtk_table_attach_defaults(GTK_TABLE(table), menubar, 0, 1, 0, 1);

	if ((combo = _create_cluster_combo())) {
		GtkWidget *label = gtk_label_new("Cluster ");
		gtk_table_attach(GTK_TABLE(table), label, 1, 2, 0, 1,
				 GTK_FILL, GTK_SHRINK, 0, 0);
		gtk_table_attach(GTK_TABLE(table), combo, 2, 3, 0, 1,
				 GTK_FILL, GTK_SHRINK, 0, 0);
	}
	gtk_notebook_popup_enable(GTK_NOTEBOOK(main_notebook));
	gtk_notebook_set_scrollable(GTK_NOTEBOOK(main_notebook), true);
	gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_notebook),
				 working_sview_config.tab_pos);

	main_statusbar = gtk_statusbar_new();
	gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(main_statusbar),
					  false);
	/* Pack it all together */
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(main_window)->vbox),
			   table, false, false, 0);
	table = gtk_table_new(1, 2, false);

	gtk_table_attach(GTK_TABLE(table), grid_window, 0, 1, 0, 1,
			 GTK_SHRINK, GTK_EXPAND | GTK_FILL,
			 0, 0);
	gtk_table_attach_defaults(GTK_TABLE(table), main_notebook, 1, 2, 0, 1);

	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(main_window)->vbox),
			   table, true, true, 0);
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(main_window)->vbox),
			   main_statusbar, false, false, 0);

	in_process_cursor = gdk_cursor_new(GDK_WATCH);

	for(i=0; i<PAGE_CNT; i++) {
		if (main_display_data[i].id == -1)
			break;

		create_page(GTK_NOTEBOOK(main_notebook),
			    &main_display_data[i]);
	}

	/* tell signal we are done adding */

	popup_list = list_create(destroy_popup_info);
	signal_params_list = list_create(destroy_signal_params);

	gtk_widget_show_all(main_window);

	adding = 0;
	/* apply default settings */
	if (!working_sview_config.show_grid)
		gtk_widget_hide(grid_window);

	for(i=0; i<PAGE_CNT; i++) {
		GtkWidget *visible_tab = NULL;

		if (main_display_data[i].id == -1)
			break;

		visible_tab = gtk_notebook_get_nth_page(
			GTK_NOTEBOOK(main_notebook), i);
		if (working_sview_config.page_visible[i]
		    || (i == working_sview_config.default_page)
		    || (i == TAB_PAGE))
			gtk_widget_show(visible_tab);
		else
			gtk_widget_hide(visible_tab);
	}
	/* Set the default page.  This has to be done after the
	 * gtk_widget_show_all since it, for some reason always sets
	 * 0 to be the default page and will just overwrite this. */
	/* Also if we already are set at the current page we need to
	   start up the page thread, so just call the _page_switched
	   function.  If we aren't already there, then set the current
	   page which will inturn call the _page_switched.  If the
	   pages is already this the signal doesn't happen so handle
	   it here.
	*/
	if (gtk_notebook_get_current_page(GTK_NOTEBOOK(main_notebook))
	    == working_sview_config.default_page)
		_page_switched(GTK_NOTEBOOK(main_notebook), NULL,
			       working_sview_config.default_page, NULL);
	else
		gtk_notebook_set_current_page(GTK_NOTEBOOK(main_notebook),
					      working_sview_config.
					      default_page);

	/* Finished! */
	gtk_main ();
	gdk_threads_leave();
	return 0;
}
Esempio n. 9
0
void *_page_thr(void *arg)
{
	page_thr_t *page = (page_thr_t *)arg;
	int num = page->page_num;
	GtkTable *table = page->table;
	display_data_t *display_data = &main_display_data[num];
	static int thread_count = 0;
	bool reset_highlight = true;

	xfree(page);
	if (!grid_init) {
		/* we need to signal any threads that are waiting */
		g_mutex_lock(grid_mutex);
		g_cond_signal(grid_cond);
		g_mutex_unlock(grid_mutex);

		/* wait for the grid to be inited */
		g_mutex_lock(grid_mutex);
		g_cond_wait(grid_cond, grid_mutex);
		g_mutex_unlock(grid_mutex);

		/* if the grid isn't there just return */
		if (!grid_init)
			return NULL;
	}

	g_mutex_lock(sview_mutex);
	thread_count++;
	g_mutex_unlock(sview_mutex);
	while (page_running == num) {
#if _DEBUG
		DEF_TIMERS;
		START_TIMER;
#endif
//		g_mutex_lock(sview_mutex);
		gdk_threads_enter();
		sview_init_grid(reset_highlight);
		reset_highlight=false;
		(display_data->get_info)(table, display_data);
		//gdk_flush();
		gdk_threads_leave();
//		g_mutex_unlock(sview_mutex);
#if _DEBUG
		END_TIMER;
		g_print("got for iteration: %s\n", TIME_STR);
#endif
		sleep(working_sview_config.refresh_delay);
		g_mutex_lock(sview_mutex);
		if (thread_count > 1) {
			g_mutex_unlock(sview_mutex);
			break;
		}
		g_mutex_unlock(sview_mutex);
	}
	g_mutex_lock(sview_mutex);
	//g_print("now here\n");
	thread_count--;
	//g_print("done decrementing\n");
	g_mutex_unlock(sview_mutex);
	//g_print("done\n");
	return NULL;
}
Esempio n. 10
0
int main( int argc, char *argv[] )
{
  VikWindow *first_window;
  GdkPixbuf *main_icon;
  gboolean dashdash_already = FALSE;
  int i = 0;
  GError *error = NULL;
  gboolean gui_initialized;
	
  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);  
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

#if ! GLIB_CHECK_VERSION (2, 32, 0)
  g_thread_init ( NULL );
#endif
  gdk_threads_init ();

  gui_initialized = gtk_init_with_args (&argc, &argv, "files+", entries, NULL, &error);
  if (!gui_initialized)
  {
    /* check if we have an error message */
    if (error == NULL)
    {
      /* no error message, the GUI initialization failed */
      const gchar *display_name = gdk_get_display_arg_name ();
      (void)g_fprintf (stderr, "Failed to open display: %s\n", (display_name != NULL) ? display_name : " ");
    }
    else
    {
      /* yep, there's an error, so print it */
      (void)g_fprintf (stderr, "Parsing command line options failed: %s\n", error->message);
      g_error_free (error);
      (void)g_fprintf (stderr, "Run \"%s --help\" to see the list of recognized options.\n",argv[0]);
    }
    return EXIT_FAILURE;
  }
   
  if (vik_version)
  {
    (void)g_printf ("%s %s\nCopyright (c) 2003-2008 Evan Battaglia\nCopyright (c) 2008-"THEYEAR" Viking's contributors\n", PACKAGE_NAME, PACKAGE_VERSION);
    return EXIT_SUCCESS;
  }

#if GLIB_CHECK_VERSION (2, 32, 0)
  if (vik_debug)
    g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, log_debug, NULL);
#else
  if (!vik_debug)
    g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, mute_log, NULL);
#endif

#if HAVE_X11_XLIB_H
  XSetErrorHandler(myXErrorHandler);
#endif

  // Discover if this is the very first run
  a_vik_very_first_run ();

  a_settings_init ();
  a_preferences_init ();

 /*
  * First stage initialization
  *
  * Should not use a_preferences_get() yet
  *
  * Since the first time a_preferences_get() is called it loads any preferences values from disk,
  *  but of course for preferences not registered yet it can't actually understand them
  *  so subsequent initial attempts to get those preferences return the default value, until the values have changed
  */
  a_vik_preferences_init ();

  a_layer_defaults_init ();

  a_download_init();
  curl_download_init();

  a_babel_init ();

  /* Init modules/plugins */
  modules_init();

  vik_georef_layer_init ();
  maps_layer_init ();
  a_mapcache_init ();
  a_background_init ();

  a_toolbar_init();
  vik_routing_prefs_init();

  /*
   * Second stage initialization
   *
   * Can now use a_preferences_get()
   */
  a_background_post_init ();
  a_babel_post_init ();
  modules_post_init ();

  // May need to initialize the Positonal TimeZone lookup
  if ( a_vik_get_time_ref_frame() == VIK_TIME_REF_WORLD )
    vu_setup_lat_lon_tz_lookup();

  /* Set the icon */
  main_icon = gdk_pixbuf_from_pixdata(&viking_pixbuf, FALSE, NULL);
  gtk_window_set_default_icon(main_icon);

  gdk_threads_enter ();

  // Ask for confirmation of default settings on first run
  vu_set_auto_features_on_first_run ();

  /* Create the first window */
  first_window = vik_window_new_window();

  vu_check_latest_version ( GTK_WINDOW(first_window) );

  // Load startup file first so that subsequent files are loaded on top
  // Especially so that new tracks+waypoints will be above any maps in a startup file
  if ( a_vik_get_startup_method () == VIK_STARTUP_METHOD_SPECIFIED_FILE ) {
    gboolean load_startup_file = TRUE;
    // When a viking file is to be loaded via the command line
    //  then we'll skip loading any startup file
    int jj = 0;
    while ( ++jj < argc ) {
      if ( check_file_magic_vik(argv[jj]) )
        load_startup_file = FALSE;
    }
    if ( load_startup_file )
      vik_window_open_file ( first_window, a_vik_get_startup_file(), TRUE );
  }

  while ( ++i < argc ) {
    if ( strcmp(argv[i],"--") == 0 && !dashdash_already )
      dashdash_already = TRUE; /* hack to open '-' */
    else {
      VikWindow *newvw = first_window;
      gboolean change_filename = (i == 1);

      // Open any subsequent .vik files in their own window
      if ( i > 1 && check_file_magic_vik ( argv[i] ) ) {
        newvw = vik_window_new_window ();
        change_filename = TRUE;
      }

      vik_window_open_file ( newvw, argv[i], change_filename );
    }
  }

  vik_window_new_window_finish ( first_window );

  vu_command_line ( first_window, latitude, longitude, zoom_level_osm, map_id );

  gtk_main ();
  gdk_threads_leave ();

  a_babel_uninit ();
  a_toolbar_uninit ();
  a_background_uninit ();
  a_mapcache_uninit ();
  a_dems_uninit ();
  a_layer_defaults_uninit ();
  a_preferences_uninit ();
  a_settings_uninit ();

  modules_uninit();

  curl_download_uninit();

  vu_finalize_lat_lon_tz_lookup ();

  // Clean up any temporary files
  util_remove_all_in_deletion_list ();

  return 0;
}
Esempio n. 11
0
static void update_view(vx_gtk_buffer_manager_t * gtk)
{
    // This order of these two mutex locks should prevent deadloc
    // even if a user sends op codes while the user holds the GDK mutex
    gdk_threads_enter();
    pthread_mutex_lock(&gtk->mutex);

    // Clear XXX Double buffered?
    GList * children = gtk_container_get_children(GTK_CONTAINER(gtk->window));
    for(GList * iter = children; iter != NULL; iter = g_list_next(iter))
        gtk_widget_destroy(GTK_WIDGET(iter->data));
    g_list_free(children);

    // Rebuild from scratch
    GtkWidget * box = gtk_vbox_new(0, 10);
    GtkWidget * widget = NULL;

    zarray_t *layers = zhash_values(gtk->layers); // contents: layer_info_t*
    zarray_sort(layers, layer_info_compare);

    for (int lidx = 0; lidx < zarray_size(layers); lidx++) {

        layer_info_t *linfo = NULL;
        zarray_get(layers, lidx, &linfo);

        // Draw the layer name:
        widget = gtk_label_new("");
        char * text = sprintf_alloc("<b>Layer %d</b>", linfo->layer_id);
        gtk_label_set_markup(GTK_LABEL(widget), text);
        free(text);
        //gtk_container_add(GTK_CONTAINER(box), widget);
        gtk_box_pack_start(GTK_BOX(box), widget, FALSE, FALSE, 0);

        // Make a checkbox for each buffer
        zarray_t *buffers = zhash_values(linfo->buffers); // contents: buffer_info_t*
        zarray_sort(buffers, buffer_info_compare);

        for (int i = 0; i < zarray_size(buffers); i++) {

            buffer_info_t * buffer = NULL;
            zarray_get(buffers, i, &buffer);
            assert(buffer != NULL);

            widget = gtk_check_button_new_with_label(buffer->name);
            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), buffer->enabled);
            g_signal_connect (G_OBJECT(widget), "toggled",
                              G_CALLBACK (buffer_checkbox_changed), buffer);
            //gtk_container_add(GTK_CONTAINER(box), widget);
            gtk_box_pack_start(GTK_BOX(box), widget, FALSE, FALSE, 0);
        }

        zarray_destroy(buffers);
    }
    gtk_container_add(GTK_CONTAINER(gtk->window), box);
    gtk_widget_show_all(box);

    zarray_destroy(layers);

    pthread_mutex_unlock(&gtk->mutex);
    gdk_threads_leave();
}
Esempio n. 12
0
int main(int argc, char *argv[])
{
	/***************************************************************************
	 * initialization **********************************************************
	 ***************************************************************************/
	g_thread_init(NULL);
	gdk_threads_init();
	gtk_init(&argc, &argv);

	/***************************************************************************
	 * window setup ************************************************************
	 ***************************************************************************/
	GtkWidget * main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(main_window), "vexterm");
	gtk_window_set_default_size(GTK_WINDOW(main_window), 400, 300);
	gtk_window_set_position(GTK_WINDOW(main_window), GTK_WIN_POS_CENTER);
	g_signal_connect(G_OBJECT(main_window), "hide", G_CALLBACK(exit), NULL);

	/***************************************************************************
	 * window content **********************************************************
	 ***************************************************************************/
	GtkWidget * a = gtk_button_new_with_label("asdf");
	GtkWidget * b = gtk_button_new_with_label("foo");
	GtkWidget * c = gtk_button_new_with_label("bar");

//	GtkWidget * split1 = gtk_splittable_new_with_child(a);
//	GtkWidget * split2 = gtk_splittable_new_with_child(c);
//	//gtk_splittable_split(VEX_GTK_SPLITTABLE(split1), b, GTK_SPLIT_LEFT);
//	gtk_splittable_split(VEX_GTK_SPLITTABLE(split1), split2, GTK_SPLIT_LEFT);
//	gtk_splittable_split(VEX_GTK_SPLITTABLE(split2), b, GTK_SPLIT_BOTTOM);

	GtkWidget * v1 = vex_single_new("/home/z/", NULL);
	GtkWidget * v2 = vex_single_new("/home/z/", NULL);
	GtkWidget * v3 = vex_single_new("/home/z/", NULL);

//	GtkWidget * split1 = gtk_splittable_new_with_child(v1);
//	GtkWidget * split2 = gtk_splittable_new_with_child(v2);
//	GtkWidget * split3 = gtk_splittable_new_with_child(v3);

	GtkWidget * split1 = gtk_splittable_new_with_child(v1);
	GtkWidget * split2 = gtk_splittable_new_with_child(b);
	//gtk_splittable_split(VEX_GTK_SPLITTABLE(split1), v2, GTK_SPLIT_LEFT);
	gtk_splittable_split(VEX_GTK_SPLITTABLE(split1), split2, GTK_SPLIT_LEFT);
	gtk_splittable_split(VEX_GTK_SPLITTABLE(split2), v2, GTK_SPLIT_BOTTOM);

	GtkWidget * box_h = gtk_hbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(main_window), box_h);
	gtk_box_pack_start(GTK_BOX(box_h), GTK_WIDGET(split1), TRUE, TRUE, 0);

	gtk_widget_show_all(main_window);

	// testing sth.
	foo(split1);

	/***************************************************************************
	 * main loop ***************************************************************
	 ***************************************************************************/
	gdk_threads_enter();	
	gtk_main();
	gdk_threads_leave();

	return 0;
}
Esempio n. 13
0
/*
 * Class:     sun_awt_X11_GtkFileDialogPeer
 * Method:    run
 * Signature: (Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/io/FilenameFilter;ZII)V
 */
JNIEXPORT void JNICALL
Java_sun_awt_X11_GtkFileDialogPeer_run(JNIEnv * env, jobject jpeer,
        jstring jtitle, jint mode, jstring jdir, jstring jfile,
        jobject jfilter, jboolean multiple, int x, int y)
{
    GtkWidget *dialog = NULL;
    GtkFileFilter *filter;

    if (jvm == NULL) {
        (*env)->GetJavaVM(env, &jvm);
    }

    gdk_threads_enter();

    const char *title = jtitle == NULL? "": (*env)->GetStringUTFChars(env, jtitle, 0);

    if (mode == java_awt_FileDialog_SAVE) {
        /* Save action */
        dialog = gtk_file_chooser_dialog_new(title, NULL,
                GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL,
                GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
    }
    else {
        /* Default action OPEN */
        dialog = gtk_file_chooser_dialog_new(title, NULL,
                GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL,
                GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);

        /* Set multiple selection mode, that is allowed only in OPEN action */
        if (multiple) {
            gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog),
                    multiple);
        }
    }

    if (jtitle != NULL) {
      (*env)->ReleaseStringUTFChars(env, jtitle, title);
    }

    /* Set the directory */
    if (jdir != NULL) {
        const char *dir = (*env)->GetStringUTFChars(env, jdir, 0);
        gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), dir);
        (*env)->ReleaseStringUTFChars(env, jdir, dir);
    }

    /* Set the filename */
    if (jfile != NULL) {
        const char *filename = (*env)->GetStringUTFChars(env, jfile, 0);
        if (mode == java_awt_FileDialog_SAVE) {
            gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
        } else {
            gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), filename);
        }
        (*env)->ReleaseStringUTFChars(env, jfile, filename);
    }

    /* Set the file filter */
    if (jfilter != NULL) {
        filter = gtk_file_filter_new();
        gtk_file_filter_add_custom(filter, GTK_FILE_FILTER_FILENAME,
                filenameFilterCallback, jpeer, NULL);
        gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
    }

    /* Other Properties */
    if (gtk_check_version(2, 8, 0) == NULL) {
        gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(
                dialog), TRUE);
    }

    /* Set the initial location */
    if (x >= 0 && y >= 0) {
        gtk_window_move((GtkWindow*)dialog, (gint)x, (gint)y);

        // NOTE: it doesn't set the initial size for the file chooser
        // as it seems like the file chooser overrides the size internally
    }

    g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(
            handle_response), jpeer);

    (*env)->SetLongField(env, jpeer, widgetFieldID, ptr_to_jlong(dialog));

    gtk_widget_show(dialog);

    gtk_main();
    gdk_threads_leave();
}
Esempio n. 14
0
static gpointer move_thread (gpointer user_data)
{
  struct thread_args *args = user_data;
  svn_error_t *err;
  apr_array_header_t *paths;
  svn_client_ctx_t *ctx = args->ctx;
  apr_pool_t *subpool, *pool = args->pool;
  TshNotifyDialog *dialog = args->dialog;
  gchar *from = args->from;
  gchar *to = args->to;
  gchar *error_str;
#if CHECK_SVN_VERSION_S(1,6)
  svn_commit_info_t *commit_info;
  gchar *message;
  gchar buffer[256];
#endif

  g_free (args);

  subpool = svn_pool_create (pool);

  paths = apr_array_make (subpool, 1, sizeof (const char *));

  APR_ARRAY_PUSH (paths, const char *) = from;

#if CHECK_SVN_VERSION_G(1,8)
  if ((err = svn_client_move7(paths, to, FALSE, FALSE, TRUE, FALSE, NULL,
                              tsh_commit_func2, dialog, ctx, subpool)))
#elif CHECK_SVN_VERSION_G(1,7)
  if ((err = svn_client_move6(paths, to, FALSE, FALSE, NULL, tsh_commit_func2,
                              dialog, ctx, subpool)))
#else
  if ((err = svn_client_move5(&commit_info, paths, to, FALSE, FALSE, FALSE,
                              NULL, ctx, subpool)))
#endif
  {
    svn_pool_destroy (subpool);

    error_str = tsh_strerror(err);

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
    gdk_threads_enter();
    tsh_notify_dialog_add(dialog, _("Failed"), error_str, NULL);
    tsh_notify_dialog_done (dialog);
    gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS

    g_free(error_str);

    svn_error_clear(err);
    tsh_reset_cancel();
    return GINT_TO_POINTER (FALSE);
  }

#if CHECK_SVN_VERSION_S(1,6)
  if(SVN_IS_VALID_REVNUM(commit_info->revision))
  {
    g_snprintf(buffer, 256, _("At revision: %ld"), commit_info->revision);
    message = buffer;
  }
  else
  {
    message = _("Local move");
  }
#endif

  svn_pool_destroy (subpool);

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  gdk_threads_enter();
#if CHECK_SVN_VERSION_S(1,6)
  tsh_notify_dialog_add(dialog, _("Completed"), message, NULL);
#endif
  tsh_notify_dialog_done (dialog);
  gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS

  tsh_reset_cancel();
  return GINT_TO_POINTER (TRUE);
}
Esempio n. 15
0
void wxGUIAppTraits::MutexGuiLeave()
{
    gdk_threads_leave();
}
Esempio n. 16
0
/**
  * Navdata handling callback
  * This callback is registered to ARDroneTool in the BEGIN_NAVDATA_HANDLER_TABLE in navdata_client.c
  * @param pnd Pointer to the ready-to-use navdata structure
  * @return Always returns C_OK.
  */
C_RESULT navdata_ihm_process( const navdata_unpacked_t* const pnd )
{
  //char text_buffer[1024];
  const navdata_vision_detect_t* pndvision = &pnd->navdata_vision_detect;

  gdk_threads_enter();

  // States' display update for IHM
  vp_os_memset( label_mykonos_state_value, '\0', sizeof(label_mykonos_state_value) );
  sprintf(label_mykonos_state_value, "%08x", pnd->ardrone_state);

  strcpy(label_ctrl_state_value, ctrl_state_str( pnd->navdata_demo.ctrl_state ));
  set_control_state(pnd->navdata_demo.ctrl_state);

  ihm_val_idx--;
  if (ihm_val_idx < 0) ihm_val_idx = KIHM_N_PT2PLOT-1;

  // Angular rates received and displayed in deg/s

  ihm_CA[KIHM_CURVE_GYRO].tval[0][ihm_val_idx] = ((double) pnd->navdata_phys_measures.phys_gyros[GYRO_X]);
  ihm_CA[KIHM_CURVE_GYRO].tval[1][ihm_val_idx] = ((double) pnd->navdata_phys_measures.phys_gyros[GYRO_Y]);
  ihm_CA[KIHM_CURVE_GYRO].tval[2][ihm_val_idx] = ((double) pnd->navdata_phys_measures.phys_gyros[GYRO_Z]);

  // Accelerations are received in mg
  // They are displayed in g: conversion gain is 1/1000
  ihm_CA[KIHM_CURVE_ACC].tval[0][ihm_val_idx] = ((double) pnd->navdata_phys_measures.phys_accs[ACC_X]) / KIHM_MIL_F;
  ihm_CA[KIHM_CURVE_ACC].tval[1][ihm_val_idx] = ((double) pnd->navdata_phys_measures.phys_accs[ACC_Y]) / KIHM_MIL_F;
  ihm_CA[KIHM_CURVE_ACC].tval[2][ihm_val_idx] = ((double) pnd->navdata_phys_measures.phys_accs[ACC_Z]) / KIHM_MIL_F;

  // Filtered  temperature is drawn in the Vbat window
  ihm_CA[KIHM_CURVE_VBAT].tval[0][ihm_val_idx] = ((double) (pnd->navdata_phys_measures.accs_temp));   // Filtered temperature

  ihm_CA[KIHM_CURVE_VBAT].tval[1][ihm_val_idx] = ((double) (pnd->navdata_demo.vbat_flying_percentage)) ; // Filtered vbat in %

  ihm_CA[KIHM_CURVE_THETA].tval[2][ihm_val_idx] = ((double) pnd->navdata_euler_angles.theta_a) / KIHM_MIL_F; // theta accelerometer value
  ihm_CA[KIHM_CURVE_PHI  ].tval[2][ihm_val_idx] = ((double) pnd->navdata_euler_angles.phi_a) / KIHM_MIL_F; // phi accelerometer value

  ihm_CA[KIHM_CURVE_THETA].tval[0][ihm_val_idx] = ((double) pnd->navdata_demo.theta) / KIHM_MIL_F; // theta fused value
  ihm_CA[KIHM_CURVE_PHI  ].tval[0][ihm_val_idx] = ((double) pnd->navdata_demo.phi) / KIHM_MIL_F; // phi fused value
  ihm_psi                                       = ((double) pnd->navdata_demo.psi) / KIHM_MIL_F;

  earef.theta = pnd->navdata_references.ref_theta;
  ihm_CA[KIHM_CURVE_THETA].tval[1][ihm_val_idx] = ((double) earef.theta) / KIHM_MIL_F; // theta reference value

  earef.phi = pnd->navdata_references.ref_phi;
  ihm_CA[KIHM_CURVE_PHI  ].tval[1][ihm_val_idx] = ((double) earef.phi) / KIHM_MIL_F; // phi reference value

  earef.psi = pnd->navdata_references.ref_psi;

  wref.p = pnd->navdata_references.ref_roll;
  wref.q = pnd->navdata_references.ref_pitch;
  wref.r = pnd->navdata_references.ref_yaw;

  rc_ref_gaz = pnd->navdata_rc_references.rc_ref_gaz;

  ihm_CA[KIHM_CURVE_ALTITUDE].tval[0][ihm_val_idx] = ((double) pnd->navdata_demo.altitude);

  ihm_CA[KIHM_CURVE_ALTITUDE].tval[1][ihm_val_idx] = ((double) pnd->navdata_altitude.altitude_vision);
  ihm_CA[KIHM_CURVE_ALTITUDE].tval[2][ihm_val_idx] = ((double) pnd->navdata_altitude.altitude_ref);
  ihm_CA[KIHM_CURVE_ALTITUDE].tval[3][ihm_val_idx] = ((double) pnd->navdata_altitude.altitude_raw);

  ihm_CA[KIHM_CURVE_VZ].tval[1][ihm_val_idx] = (double) (pnd->navdata_altitude.altitude_vz);      // Fusion Vz

  tab_trims[0] = (double)pnd->navdata_trims.euler_angles_trim_theta;
  tab_trims[1] = (double)pnd->navdata_trims.euler_angles_trim_phi;
  tab_trims[2] = (double)pnd->navdata_trims.angular_rates_trim_r;

  ihm_CA[KIHM_CURVE_PWM].tval[0][ihm_val_idx] = (double) (pnd->navdata_pwm.motor1); // PWM motor 1
  ihm_CA[KIHM_CURVE_PWM].tval[1][ihm_val_idx] = (double) (pnd->navdata_pwm.motor2); // PWM motor 2
  ihm_CA[KIHM_CURVE_PWM].tval[2][ihm_val_idx] = (double) (pnd->navdata_pwm.motor3); // PWM motor 3
  ihm_CA[KIHM_CURVE_PWM].tval[3][ihm_val_idx] = (double) (pnd->navdata_pwm.motor4); // PWM motor 4
  ihm_CA[KIHM_CURVE_CURRENT].tval[0][ihm_val_idx] = (double) (pnd->navdata_pwm.current_motor1); // current motor 1
  ihm_CA[KIHM_CURVE_CURRENT].tval[1][ihm_val_idx] = (double) (pnd->navdata_pwm.current_motor2); // current motor 2
  ihm_CA[KIHM_CURVE_CURRENT].tval[2][ihm_val_idx] = (double) (pnd->navdata_pwm.current_motor3); // current motor 3
  ihm_CA[KIHM_CURVE_CURRENT].tval[3][ihm_val_idx] = (double) (pnd->navdata_pwm.current_motor4); // current motor 4

  ihm_CA[KIHM_CURVE_VZ].tval[3][ihm_val_idx] = (double) (pnd->navdata_pwm.vz_ref);  // VZ reference

  ihm_CA[KIHM_CURVE_VX].tval[0][ihm_val_idx] = (double) (pnd->navdata_vision_raw.vision_tx_raw);      // VISION trans. en x
  ihm_CA[KIHM_CURVE_VY].tval[0][ihm_val_idx] = (double) (pnd->navdata_vision_raw.vision_ty_raw);      // VISION trans. en y
  ihm_CA[KIHM_CURVE_VZ].tval[0][ihm_val_idx] = (double) (pnd->navdata_vision_raw.vision_tz_raw);      // VISION trans. en z


  if( pnd->vision_defined )
  {
    if( fabsf(pnd->navdata_vision_raw.vision_tx_raw) <= 10.0f && fabsf(pnd->navdata_vision_raw.vision_ty_raw) <= 10.0f )
    {
      ihm_dir = HOVER_VAL;
    }
    else
    {
      ihm_dir = (double) atan2f(pnd->navdata_vision_raw.vision_ty_raw, pnd->navdata_vision_raw.vision_tx_raw);
    }
  }
  else
  {
    ihm_dir = NOT_DEF_VAL;
  }

  //Vision States' display update for IHM
  vp_os_memset( label_vision_state_value, '\0', sizeof(label_vision_state_value) );
  sprintf(label_vision_state_value, "%08x", pnd->navdata_vision.vision_state);

  ihm_CA[KIHM_CURVE_VX].tval[1][ihm_val_idx] = (double) (pnd->navdata_demo.vx);      // Fusion Vx
  ihm_CA[KIHM_CURVE_VY].tval[1][ihm_val_idx] = (double) (pnd->navdata_demo.vy);      // Fusion Vy

#ifdef PC_USE_VISION
  draw_trackers_cfg.num_points = NUM_MAX_SCREEN_POINTS;
  vp_os_memset(&draw_trackers_cfg.locked[0], 0, NUM_MAX_SCREEN_POINTS * sizeof(uint32_t));
  vp_os_memcpy(&draw_trackers_cfg.locked[0], pnd->navdata_trackers_send.locked, NUM_MAX_SCREEN_POINTS * sizeof(uint32_t));
  vp_os_memset(&draw_trackers_cfg.points[0], 0, NUM_MAX_SCREEN_POINTS * sizeof(screen_point_t));
  vp_os_memcpy(&draw_trackers_cfg.points[0], pnd->navdata_trackers_send.point, NUM_MAX_SCREEN_POINTS * sizeof(screen_point_t));

  int i;
  draw_trackers_cfg.detected = pnd->navdata_vision_detect.nb_detected;
  for(i = 0 ; i < pnd->navdata_vision_detect.nb_detected ; i++)
  {
    draw_trackers_cfg.type[i]           = pnd->navdata_vision_detect.type[i];
    draw_trackers_cfg.patch_center[i].x = pnd->navdata_vision_detect.xc[i];
    draw_trackers_cfg.patch_center[i].y = pnd->navdata_vision_detect.yc[i];
    draw_trackers_cfg.width[i]          = pnd->navdata_vision_detect.width[i];
    draw_trackers_cfg.height[i]         = pnd->navdata_vision_detect.height[i];
  }
  set_draw_trackers_config(&draw_trackers_cfg);
#endif

  /*Stephane*/

	  extern char label_detection_state_value[32];
	  switch(pnd->navdata_demo.detection_camera_type)
	  {
		  case CAD_TYPE_NONE:  snprintf(label_detection_state_value,sizeof(label_detection_state_value),"Detection disabled"); break;
		  case CAD_TYPE_VISION:   snprintf(label_detection_state_value,sizeof(label_detection_state_value),"Searching 2D tags"); break;
		  case CAD_TYPE_COCARDE:  snprintf(label_detection_state_value,sizeof(label_detection_state_value),"Searching roundels"); break;
		  case CAD_TYPE_ORIENTED_COCARDE:  snprintf(label_detection_state_value,sizeof(label_detection_state_value),"Searching roundels"); break;
		  case CAD_TYPE_H_COCARDE:  snprintf(label_detection_state_value,sizeof(label_detection_state_value),"Searching H roundels"); break;
		  case CAD_TYPE_H_ORIENTED_COCARDE:  snprintf(label_detection_state_value,sizeof(label_detection_state_value),"Searching H roundels"); break;
		  case CAD_TYPE_STRIPE:  snprintf(label_detection_state_value,sizeof(label_detection_state_value),"Searching ground stripe (15Hz)"); break;
		  case CAD_TYPE_STRIPE_V:  snprintf(label_detection_state_value,sizeof(label_detection_state_value),"Searching ground stripe (60Hz)"); break;
		  default : snprintf(label_detection_state_value,sizeof(label_detection_state_value),"Navdata error");
	  }

	  char nbDetectedTags_label_buffer[1024];

	  if (pndvision->nb_detected==1 && ( pnd->navdata_demo.detection_camera_type==CAD_TYPE_ORIENTED_COCARDE ||  pnd->navdata_demo.detection_camera_type==CAD_TYPE_H_ORIENTED_COCARDE ) )
	  {  snprintf(nbDetectedTags_label_buffer,sizeof(nbDetectedTags_label_buffer),"Found : %i (%4.2f deg)",pndvision->nb_detected,pndvision->orientation_angle[0]); }
	  else if (pndvision->nb_detected==1 && (pnd->navdata_demo.detection_camera_type==CAD_TYPE_STRIPE || pnd->navdata_demo.detection_camera_type==CAD_TYPE_STRIPE_V))
	  {  snprintf(nbDetectedTags_label_buffer,sizeof(nbDetectedTags_label_buffer),"Found : %i (%4.2f deg - w: %i)",
			  pndvision->nb_detected,
			  pndvision->orientation_angle[0],
			  pndvision->width[0]);
	  }
	  else
	  {  snprintf(nbDetectedTags_label_buffer,sizeof(nbDetectedTags_label_buffer),"Found : %i",pndvision->nb_detected);	  }

	  if(nbDetectedTags_label!=NULL)
		  gtk_label_set_text((GtkLabel*)nbDetectedTags_label,(const gchar*)nbDetectedTags_label_buffer);





  gdk_threads_leave();

  return C_OK;
}
Esempio n. 17
0
static int MicrocodeDialog()
{
	GtkWidget *infoLabel;
	GtkWidget *infoFrame, *infoTable;
	GtkWidget *crcInfoLabel, *crcDataInfoLabel, *textInfoLabel;
	GtkWidget *crcLabel = NULL, *crcDataLabel = NULL, *textLabel = NULL;
	GtkWidget *selectUcodeLabel;
	//GtkWidget *microcodeLabel;
	GtkWidget *okButton, *stopButton;
	GList *ucodeList = 0;
	char buf[1024];

	if (!g_thread_supported())
		g_thread_init( NULL );
	gdk_threads_enter();

	// create dialog
	if (microcodeWindow == 0)
	{
		microcodeWindow = gtk_dialog_new();
		gtk_signal_connect( GTK_OBJECT(microcodeWindow), "delete_event",
		                    GTK_SIGNAL_FUNC(delete_question_event), (gpointer)NULL );
		sprintf( buf, "%s - unknown microcode", pluginName );
		gtk_window_set_title( GTK_WINDOW(microcodeWindow), buf );
		gtk_container_set_border_width( GTK_CONTAINER(GTK_DIALOG(microcodeWindow)->vbox), 11 );

		// ok button
		okButton = gtk_button_new_with_label( "Ok" );
		gtk_signal_connect_object( GTK_OBJECT(okButton), "clicked",
                               GTK_SIGNAL_FUNC(okButton_clicked), NULL );
		gtk_container_add( GTK_CONTAINER(GTK_DIALOG(microcodeWindow)->action_area), okButton );

		// stop button
		stopButton = gtk_button_new_with_label( "Stop" );
		gtk_signal_connect_object( GTK_OBJECT(stopButton), "clicked",
                               GTK_SIGNAL_FUNC(stopButton_clicked), NULL );
		gtk_container_add( GTK_CONTAINER(GTK_DIALOG(microcodeWindow)->action_area), stopButton );

		// info label
		infoLabel = gtk_label_new( "Unknown microcode. Please notify Orkin, including the following information:" );
		gtk_box_pack_start_defaults( GTK_BOX(GTK_DIALOG(microcodeWindow)->vbox), infoLabel );

		// info frame
		infoFrame = gtk_frame_new( "Microcode info" );
		gtk_container_set_border_width( GTK_CONTAINER(infoFrame), 7 );
		gtk_box_pack_start_defaults( GTK_BOX(GTK_DIALOG(microcodeWindow)->vbox), infoFrame );

		infoTable = gtk_table_new( 3, 2, FALSE );
		gtk_container_set_border_width( GTK_CONTAINER(infoTable), 7 );
		gtk_table_set_col_spacings( GTK_TABLE(infoTable), 3 );
		gtk_table_set_row_spacings( GTK_TABLE(infoTable), 3 );
		gtk_container_add( GTK_CONTAINER(infoFrame), infoTable );

		crcInfoLabel = gtk_label_new( "Microcode CRC:" );
		crcDataInfoLabel = gtk_label_new( "Microcode Data CRC:" );
		textInfoLabel = gtk_label_new( "Microcode Text:" );

		crcLabel = gtk_label_new( "" );
		crcDataLabel = gtk_label_new( "" );
		textLabel = gtk_label_new( "" );

		gtk_table_attach_defaults( GTK_TABLE(infoTable), crcInfoLabel, 0, 1, 0, 1 );
		gtk_table_attach_defaults( GTK_TABLE(infoTable), crcLabel, 1, 2, 0, 1 );
		gtk_table_attach_defaults( GTK_TABLE(infoTable), crcDataInfoLabel, 0, 1, 1, 2 );
		gtk_table_attach_defaults( GTK_TABLE(infoTable), crcDataLabel, 1, 2, 1, 2 );
		gtk_table_attach_defaults( GTK_TABLE(infoTable), textInfoLabel, 0, 1, 2, 3 );
		gtk_table_attach_defaults( GTK_TABLE(infoTable), textLabel, 1, 2, 2, 3 );

		selectUcodeLabel = gtk_label_new( "You can manually select the closest matching microcode." );
		for (int i = 0; i < numMicrocodeTypes; i++)
			ucodeList = g_list_append( ucodeList, gtk_list_item_new_with_label( MicrocodeTypes[i] ) );
		microcodeList = gtk_list_new();
		gtk_list_set_selection_mode( GTK_LIST(microcodeList), GTK_SELECTION_SINGLE );
		gtk_list_append_items( GTK_LIST(microcodeList), ucodeList );

		gtk_box_pack_start_defaults( GTK_BOX(GTK_DIALOG(microcodeWindow)->vbox), selectUcodeLabel );
		gtk_box_pack_start_defaults( GTK_BOX(GTK_DIALOG(microcodeWindow)->vbox), microcodeList );
	}

	snprintf( buf, 1024, "0x%8.8X", (unsigned int)uc_crc );
        if(crcLabel) gtk_label_set_text( GTK_LABEL(crcLabel), buf );
	snprintf( buf, 1024, "0x%8.8X", (unsigned int)uc_dcrc );
	if(crcDataLabel) gtk_label_set_text( GTK_LABEL(crcDataLabel), buf );
	if(textLabel) gtk_label_set_text( GTK_LABEL(textLabel), uc_str );

	selectedMicrocode = -1;
	gtk_widget_show_all( microcodeWindow );

	while (selectedMicrocode == -1)
	{
//		if( gtk_main_iteration() )
//			break;
		usleep( 10000 );
	}
	gdk_threads_leave();
	return selectedMicrocode;
}
void
classpath_jawt_unlock ()
{
  gdk_threads_leave ();
}
Esempio n. 19
0
/*
 * vim: softtabstop=4 shiftwidth=4 cindent foldmethod=marker expandtab
 *
 * $LastChangedDate$
 * $Revision$
 * $LastChangedBy$
 * $URL$
 *
 * Copyright 2009-2011 Eric Connell
 *
 * This file is part of Mangler.
 *
 * Mangler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Mangler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Mangler.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "mangler.h"
#include "manglerrecorder.h"
#include "mangleraudio.h"
#include "manglercharset.h"

#include <unistd.h>
#include <sys/stat.h>
#include <dirent.h>

ManglerRecorder::ManglerRecorder(Glib::RefPtr<Gtk::Builder> builder) {/*{{{*/
    this->builder = builder;

    builder->get_widget("recWindow", recWindow);
    builder->get_widget("recHide", menuitem);
    menuitem->signal_activate().connect(sigc::mem_fun(this, &ManglerRecorder::hide_activate_cb));

    builder->get_widget("recOpen", menuitem);
    menuitem->signal_activate().connect(sigc::mem_fun(this, &ManglerRecorder::open_activate_cb));
    builder->get_widget("recClose", menuitem);
    menuitem->signal_activate().connect(sigc::mem_fun(this, &ManglerRecorder::close_activate_cb));
    builder->get_widget("recSaveAs", menuitem);
    menuitem->signal_activate().connect(sigc::mem_fun(this, &ManglerRecorder::saveas_activate_cb));
    builder->get_widget("recDelete", menuitem);
    menuitem->signal_activate().connect(sigc::mem_fun(this, &ManglerRecorder::delete_activate_cb));

    builder->get_widget("recPlayPause", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerRecorder::playpause_clicked_cb));
    builder->get_widget("recStop", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerRecorder::stop_clicked_cb));
    builder->get_widget("recRecord", recordbutton);
    recordbutton->signal_toggled().connect(sigc::mem_fun(this, &ManglerRecorder::record_toggled_cb));
    builder->get_widget("recInfo", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerRecorder::info_clicked_cb));

    builder->get_widget("recOpenEntry", fileentry);
    builder->get_widget("recOpenButton", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerRecorder::open_activate_cb));

    filedialog = new Gtk::FileChooserDialog("Open Recording", Gtk::FILE_CHOOSER_ACTION_OPEN);
    filedialog->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    filedialog->add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
    Gtk::FileFilter vrf_filter;
    vrf_filter.set_name("Ventrilo Recording File (*.vrf)");
    vrf_filter.add_pattern("*.vrf");
    filedialog->add_filter(vrf_filter);
    Gtk::FileFilter all_filter;
    all_filter.set_name("All Files");
    all_filter.add_pattern("*");
    filedialog->add_filter(all_filter);

    builder->get_widget("recScrolledWindow", recScrolledWindow);
    recListModel = Gtk::ListStore::create(recRecord);
    builder->get_widget("recListTree", recListTree);
    recListTree->set_model(recListModel);
    recListTree->append_column("Time", recRecord.time);
    recListTree->append_column("Duration", recRecord.duration);
    recListTree->append_column("Status", recRecord.status);
    recListTree->append_column("Username", recRecord.username);
    recListTree->append_column("", recRecord.text);
    recListTree->signal_cursor_changed().connect(sigc::mem_fun(this, &ManglerRecorder::recListTree_cursor_changed_cb));
    recListTree->signal_row_activated().connect(sigc::mem_fun(this, &ManglerRecorder::recListTree_row_activated_cb));

    builder->get_widget("recInfoDialog", recInfoDialog);
    builder->get_widget("recInfoCancel", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerRecorder::recInfoDialog_cancel_clicked_cb));
    builder->get_widget("recInfoSave", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerRecorder::recInfoDialog_save_clicked_cb));

    recdir = ManglerConfig::confdir() + "/recordings";
    DIR *testdir;
    if ((testdir = opendir(recdir.c_str()))) {
        closedir(testdir);
    } else {
        mkdir(recdir.c_str(), 0700);
    }
    filedialog->set_current_folder(recdir);

    isPlaying   = false;
    isRecording = false;

    vrfh = NULL;
    player = NULL;
}/*}}}*/
ManglerRecorder::~ManglerRecorder() {/*{{{*/
    reset(true);
    delete filedialog;
}/*}}}*/

void
ManglerRecorder::show(void) {/*{{{*/
    recWindow->present();
}/*}}}*/
void
ManglerRecorder::hide_activate_cb(void) {/*{{{*/
    recWindow->hide();
}/*}}}*/
void
ManglerRecorder::open_activate_cb(void) {/*{{{*/
    int result = filedialog->run();
    filedialog->hide();
    if (result == Gtk::RESPONSE_OK) {
        path = filedialog->get_current_folder();
        filename = filedialog->get_filename();
        set(false);
    }
}/*}}}*/
void
ManglerRecorder::close_activate_cb(void) {/*{{{*/
    reset();
}/*}}}*/
void
ManglerRecorder::saveas_activate_cb(void) {/*{{{*/
}/*}}}*/
void
ManglerRecorder::delete_activate_cb(void) {/*{{{*/
    if (!vrfh || filename.empty()) {
        return;
    }
    Gtk::MessageDialog confirm("<b>Are you sure you want to delete \"" + fileentry->get_text() + "\"?</b>",
            true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO, true);
    if (confirm.run() == Gtk::RESPONSE_YES) {
        reset();
        unlink(filename.c_str());
    }
}/*}}}*/
void
ManglerRecorder::playpause_clicked_cb(void) {/*{{{*/
    if (!vrfh) {
        return;
    }
    isPlaying = true;
    player = Glib::Thread::create(sigc::mem_fun(*this, &ManglerRecorder::play), false);
}/*}}}*/
void
ManglerRecorder::stop_clicked_cb(void) {/*{{{*/
    player = NULL;
}/*}}}*/
void
ManglerRecorder::record_toggled_cb(void) {/*{{{*/
    if (recordbutton->get_active()) {
        path = recdir;
        filename = path + "/" + timestamp() + ".vrf";
        set(true);
    } else {
        set(false);
    }
}/*}}}*/
void
ManglerRecorder::info_clicked_cb(void) {/*{{{*/
    if (!vrfh) {
        return;
    }
    v3_vrf_data vrfd;
    if (v3_vrf_get_info(vrfh, &vrfd) != V3_OK) {
        mangler->errorDialog(c_to_ustring(_v3_error(NULL)));
        return;
    }
    builder->get_widget("recInfoByEntry", entry);
    entry->set_text(c_to_ustring(vrfd.username));
    builder->get_widget("recInfoComment", textview);
    textview->get_buffer()->set_text(c_to_ustring(vrfd.comment));
    builder->get_widget("recInfoURL", textview);
    textview->get_buffer()->set_text(c_to_ustring(vrfd.url));
    builder->get_widget("recInfoCopyright", textview);
    textview->get_buffer()->set_text(c_to_ustring(vrfd.copyright));
    recInfoDialog->set_icon(mangler->icons["tray_icon"]);
    recInfoDialog->present();
}/*}}}*/
void
ManglerRecorder::recListTree_cursor_changed_cb(void) {/*{{{*/
    if (!vrfh) {
        return;
    }
    builder->get_widget("recPlayPause", widget);
    widget->set_sensitive(recListTree->get_selection()->get_selected());
}/*}}}*/
void
ManglerRecorder::recListTree_row_activated_cb(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column) {/*{{{*/
    if (!vrfh) {
        return;
    }
    isPlaying = false;
    player = Glib::Thread::create(sigc::mem_fun(*this, &ManglerRecorder::play), false);
}/*}}}*/
void
ManglerRecorder::set(bool isRecording) {/*{{{*/
    reset();
    if (isRecording) {
        if (v3_vrf_record_start(filename.c_str()) != V3_OK) {
            mangler->errorDialog(c_to_ustring(_v3_error(NULL)));
            recordbutton->set_active(false);
            return;
        }
        this->isRecording = true;
    } else {
        this->isRecording = false;
        if (!(vrfh = v3_vrf_init(filename.c_str()))) {
            mangler->errorDialog(c_to_ustring(_v3_error(NULL)));
            return;
        }
        v3_vrf_data vrfd;
        if (v3_vrf_get_info(vrfh, &vrfd) != V3_OK) {
            reset();
            mangler->errorDialog(c_to_ustring(_v3_error(NULL)));
            return;
        }
        builder->get_widget("recSize", label);
        label->set_text(bytes_to_readable(vrfd.size));
        builder->get_widget("recCount", label);
        label->set_text(float_to_ustring(v3_vrf_get_count(vrfh), 0));
        builder->get_widget("recPlatform", label);
        label->set_text(c_to_ustring(vrfd.platform));
        builder->get_widget("recVersion", label);
        label->set_text(c_to_ustring(vrfd.version));
        builder->get_widget("recCodec", label);
        label->set_text(c_to_ustring(v3_get_codec(vrfd.codec, vrfd.codecformat)->name));
        totalduration = 0;
        for (uint32_t ctr = 0, cnt = v3_vrf_get_count(vrfh); ctr < cnt; ctr++) {
            if (v3_vrf_get_segment(vrfh, ctr, &vrfd) != V3_OK) {
                reset();
                mangler->errorDialog(c_to_ustring(_v3_error(NULL)));
                return;
            }
            Gtk::TreeModel::Row row = *(recListModel->append());
            row[recRecord.id]           = ctr;
            row[recRecord.time_val]     = vrfd.time;
            row[recRecord.duration_val] = vrfd.duration;
            row[recRecord.time]         = msec_to_timestamp(vrfd.time);
            row[recRecord.duration]     = float_to_ustring(vrfd.duration / 1000.0, 2);
            row[recRecord.status]       = "";
            row[recRecord.username]     = c_to_ustring(vrfd.username);
            row[recRecord.text]         = "";
            totalduration += vrfd.duration;
        }
        builder->get_widget("recDuration", label);
        label->set_text(float_to_ustring(totalduration / 60000.0, 1) + " min");
        builder->get_widget("recInfo", widget);
        widget->set_sensitive(true);
    }
    fileentry->set_text(filename.substr(path.length() + 1));
    builder->get_widget("recType", label);
    label->set_text("VRF");
    recListTree->set_sensitive(true);
    builder->get_widget("recClose", widget);
    widget->set_sensitive(true);
    builder->get_widget("recDelete", widget);
    widget->set_sensitive(true);
    builder->get_widget("recInfos", widget);
    widget->set_sensitive(true);
    recScrolledWindow->get_vadjustment()->set_value(0);
    if (recListModel->children().size()) {
        recListTree->set_cursor(recListModel->get_path(recListModel->children().begin()));
        builder->get_widget("recPlayPause", widget);
        widget->grab_focus();
    }
}/*}}}*/
void
ManglerRecorder::reset(bool destroying) {/*{{{*/
    player = (Glib::Thread*)destroying;
    isPlaying = false;
    if (isRecording) {
        v3_vrf_record_stop();
        recordbutton->set_active(false);
    }
    isRecording = false;
    if (vrfh) {
        v3_vrf_destroy(vrfh);
        vrfh = NULL;
    }
    recListModel->clear();
    if (destroying) {
        return;
    }
    for (int ctr = 0, cnt = recListTree->get_columns().size(); ctr < cnt; ctr++) {
        recListTree->get_column(ctr)->queue_resize();
    }
    recListTree->set_sensitive(false);
    fileentry->set_text("");
    builder->get_widget("recType", label);
    label->set_text("N/A");
    builder->get_widget("recSize", label);
    label->set_text("N/A");
    builder->get_widget("recCount", label);
    label->set_text("N/A");
    builder->get_widget("recDuration", label);
    label->set_text("N/A");
    builder->get_widget("recPlatform", label);
    label->set_text("N/A");
    builder->get_widget("recVersion", label);
    label->set_text("N/A");
    builder->get_widget("recCodec", label);
    label->set_text("N/A");
    builder->get_widget("recClose", widget);
    widget->set_sensitive(false);
    builder->get_widget("recDelete", widget);
    widget->set_sensitive(false);
    builder->get_widget("recInfos", widget);
    widget->set_sensitive(false);
    builder->get_widget("recPlayPause", widget);
    widget->set_sensitive(false);
    builder->get_widget("recInfo", widget);
    widget->set_sensitive(false);
    builder->get_widget("recInfoByEntry", entry);
    entry->set_text("");
    builder->get_widget("recInfoComment", textview);
    textview->get_buffer()->set_text("");
    builder->get_widget("recInfoURL", textview);
    textview->get_buffer()->set_text("");
    builder->get_widget("recInfoCopyright", textview);
    textview->get_buffer()->set_text("");
    recInfoDialog->hide();
}/*}}}*/
void
ManglerRecorder::can_record(bool isConnected) {/*{{{*/
    if (!isConnected && isRecording) {
        set(false);
    }
    recordbutton->set_sensitive(isConnected);
}/*}}}*/
void
ManglerRecorder::record(Glib::ustring username, Glib::ustring text, uint32_t index, uint32_t time, bool stopped, bool flushed) {/*{{{*/
    if (!isRecording) {
        return;
    }
    Gtk::TreeModel::Children children = recListModel->children();
    Gtk::TreeModel::Row row;
    if (!flushed && !children[index]) {
        row = *(recListModel->append());
        row[recRecord.id]           = index;
        row[recRecord.time_val]     = time;
        row[recRecord.duration_val] = 0;
        row[recRecord.diff_val]     = 0;
        row[recRecord.time]         = msec_to_timestamp(time);
        row[recRecord.duration]     = float_to_ustring(0, 2);
        row[recRecord.status]       = "Rec";
        row[recRecord.username]     = username;
        row[recRecord.text]         = (text.length()) ? text : "";
        builder->get_widget("recCount", label);
        label->set_text(float_to_ustring(children.size(), 0));
        recListTree->set_cursor(recListModel->get_path(row));
    }
    if (flushed) {
        for (Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); iter++) {
            (*iter)[recRecord.status] = "*";
        }
        return;
    }
    row = children[index];
    if (stopped) {
        row[recRecord.status] = "*";
    } else {
        row[recRecord.duration_val] = time - row[recRecord.time_val];
    }
    if (stopped || row[recRecord.diff_val] + 100 < row[recRecord.duration_val]) {
        row[recRecord.diff_val] = time - row[recRecord.time_val];
        row[recRecord.duration] = float_to_ustring(row[recRecord.duration_val] / 1000.0, 2);
    }
}/*}}}*/
void
ManglerRecorder::play(void) {/*{{{*/
    Glib::Thread *self = Glib::Thread::self();
    Gtk::TreeModel::iterator iter = recListTree->get_selection()->get_selected();
    Gtk::TreeModel::Children children = recListModel->children();
    if (!vrfh || !iter || children.empty() || player != self) {
        if (player == self) {
            player = NULL;
        }
        return;
    } else {
        gdk_threads_enter();
        builder->get_widget("recStop", widget);
        widget->set_sensitive(true);
        gdk_threads_leave();
    }
    std::map<uint32_t, ManglerRecorderData *> recData;
    std::map<uint32_t, ManglerRecorderData *>::iterator recIter;
    v3_vrf_data *next = NULL;
    double elapsed;
    struct timeval start, now, diff;
    elapsed = (*iter)[recRecord.time_val];
    gettimeofday(&start, NULL);
    for (;;) {
        if (!next && iter != children.end()) {
            next = (v3_vrf_data *)malloc(sizeof(v3_vrf_data));
            v3_vrf_data_init(next);
            if (v3_vrf_get_segment(vrfh, (*iter)[recRecord.id], next) != V3_OK) {
                free(next);
                next = NULL;
                iter++;
            } else if (isPlaying && children.size()) {
                gdk_threads_enter();
                Gtk::Adjustment *vadjustment = recScrolledWindow->get_vadjustment();
                float adj = vadjustment->get_upper() * ((*iter)[recRecord.id] / (float)children.size()) - vadjustment->get_page_size() / 2.0;
                if (adj < 0) {
                    adj = 0;
                } else if (adj > vadjustment->get_upper() - vadjustment->get_page_size()) {
                    adj = vadjustment->get_upper() - vadjustment->get_page_size();
                }
                vadjustment->set_value(adj);
                recListTree->set_cursor(recListModel->get_path(iter));
                gdk_threads_leave();
            }
            if (!isPlaying) {
                iter = children.end();
            }
        }
        gettimeofday(&now, NULL);
        timeval_subtract(&diff, &now, &start);
        gettimeofday(&start, NULL);
        elapsed += diff.tv_sec * 1000.0 + diff.tv_usec / 1000.0;
        if ((player != self || (iter == children.end() && !next)) && recData.empty()) {
            if (next) {
                v3_vrf_data_destroy(next);
                free(next);
            }
            break;
        }
        if (next && next->time <= elapsed) {
            recData[next->id] = new ManglerRecorderData(next);
            next = NULL;
            if (isPlaying) {
                iter++;
            }
        }
        double duration = 0;
        for (recIter = recData.begin(); recIter != recData.end() && recData.size();) {
            ManglerRecorderData *recd = recIter->second;
            if (player == self && recd->next > elapsed) {
                recIter++;
                continue;
            }
            v3_vrf_data *vrfd = recd->vrfd;
            if (player == self) {
                v3_vrf_get_audio(vrfh, vrfd->id, vrfd);
            }
            switch ((player == self) ? vrfd->type : V3_VRF_DATA_NULL) {
              case V3_VRF_DATA_AUDIO:
                if (!recd->outputAudio) {
                    recd->outputAudio = new ManglerAudio(AUDIO_OUTPUT, vrfd->rate, vrfd->channels, 0, 0, false);
                }
                if (vrfd->length) {
                    recd->outputAudio->queue(vrfd->length, (uint8_t *)vrfd->data);
                }
                if (!recd->next) {
                    recd->next = vrfd->time;
                    gdk_threads_enter();
                    children[recIter->first][recRecord.status] = "Play";
                    builder->get_widget("recCodec", label);
                    label->set_text(c_to_ustring(v3_get_codec(vrfd->codec, vrfd->codecformat)->name));
                    gdk_threads_leave();
                }
                duration += (vrfd->length / (float)(vrfd->rate * sizeof(int16_t) * vrfd->channels)) * 1000.0;
                if (duration < 10) {
                    continue;
                }
                recd->next += duration;
                recIter++;
                break;
              case V3_VRF_DATA_TEXT:
                gdk_threads_enter();
                children[recIter->first][recRecord.text] = c_to_ustring(vrfd->text);
                children[recIter->first][recRecord.status] = "*";
                gdk_threads_leave();
                recIter++;
                break;
              case V3_VRF_DATA_NULL:
              default:
                if (recd->outputAudio) {
                    recd->outputAudio->finish();
                }
                v3_vrf_data_destroy(vrfd);
                free(vrfd);
                delete recd;
                gdk_threads_enter();
                if (vrfh && children[recIter->first] && children[recIter->first][recRecord.status] == "Play") {
                    children[recIter->first][recRecord.status] = "*";
                }
                gdk_threads_leave();
                recData.erase(recIter);
                recIter = recData.begin();
                break;
            }
            duration = 0;
        }
        usleep(10000);
    }
    if (!player || player == self) {
        gdk_threads_enter();
        builder->get_widget("recStop", widget);
        widget->set_sensitive(false);
        gdk_threads_leave();
    }
}/*}}}*/
Esempio n. 20
0
 void sync_helper_update_note(GObject * helper, gpointer existing_note, gpointer note_update)
 {
   gdk_threads_enter();
   g_signal_emit_by_name(helper, "update-note", existing_note, note_update);
   gdk_threads_leave();
 }
Esempio n. 21
0
/*
 * Dispaly the up-to-date status of the software. If a new release is available
 * display information about it.
 */
static gboolean version_info_show(gpointer data)
{
    Dialogs *_dialogs = (data) ? (Dialogs *)data : &dialogs;
    GtkBuilder *builder = _dialogs->builder;
    GtkWidget *r_name, *r_link, *r_dld_link;
    GtkWidget *internal_vbox;
    gchar *buf;

    /* don't bother showing the dialog if version check failed (applies only at startup) */
    if (!release && !data)
        return false;

    gdk_threads_enter();
    internal_vbox = GTK_WIDGET(gtk_builder_get_object(builder,
                               "msg_dialog_vbox"));

    if (!release) {
        g_object_set(G_OBJECT(_dialogs->latest_version), "text",
                     "Failed to get the latest version."
                     "Make sure you have an internet connection.",
                     NULL);
        gtk_widget_hide(internal_vbox);
    } else if (strncmp(GIT_VERSION, release->commit, 7)) {

        if (date_compare_against_build_date(release->build_date) > 0) {
            g_object_set(G_OBJECT(_dialogs->latest_version), "text",
                         "A new version is available", NULL);
        } else {
            /* No data means that a silent version checking has been
               requested. The progress bar has already been hidden
               and so should the message dialog be. */
            if (!data)
                goto end;
            g_object_set(G_OBJECT(_dialogs->latest_version), "text",
                         "This software is newer than the latest release",
                         NULL);
        }

        r_name = GTK_WIDGET(gtk_builder_get_object(builder,
                            "latest_version_name"));
        r_link = GTK_WIDGET(gtk_builder_get_object(builder,
                            "latest_version_link"));
        r_dld_link = GTK_WIDGET(gtk_builder_get_object(builder,
                                "latest_version_donwnload_link"));

        buf = g_strdup_printf("<b>%s</b>", release->name);
        gtk_label_set_markup(GTK_LABEL(r_name), buf);
        g_free(buf);
        gtk_link_button_set_uri(GTK_LINK_BUTTON(r_link), release->url);
        gtk_link_button_set_uri(GTK_LINK_BUTTON(r_dld_link),
                                release->windows_dld_url);
#ifndef __MINGW32__
        gtk_widget_hide(r_dld_link);
#endif

        gtk_widget_show(internal_vbox);
    } else {
        /* No data means that a silent version checking has been
           requested. The progress bar has already been hidden and so
           should the message dialog be. */
        if (!data)
            goto end;
        g_object_set(G_OBJECT(_dialogs->latest_version), "text",
                     "This software is up to date", NULL);
        gtk_widget_hide(internal_vbox);
    }

    release_dispose(release);
    release = NULL;


    gtk_widget_set_visible(GTK_WIDGET(gtk_builder_get_object(builder,
                                      "version_check_dont_show_again")), !data);

    gtk_dialog_run(GTK_DIALOG(_dialogs->latest_version));
    gtk_widget_hide(_dialogs->latest_version);

end:
    gdk_threads_leave();

    return false;
}
Esempio n. 22
0
/* entry point */
int
main (int argc, char **argv)
{
  GtkWidget *mainwin;
  gint n_burners;
  GError *error = NULL;
#ifdef HAVE_GUDEV
  gchar *error_msg;
#endif
  XfburnTranscoder *transcoder;
  XfburnDeviceList *devlist;

#if DEBUG > 0
  /* I have to disable this until GtkTreeView gets fixed,
   * and doesn't complain anymore when a DnD doesn't add any
   * rows
  g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
   */
#endif
  
  g_set_application_name (_("Xfburn"));

  gdk_threads_init ();
  gdk_threads_enter ();

  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");

  if (!gtk_init_with_args (&argc, &argv, "", optionentries, GETTEXT_PACKAGE, &error)) {
    if (error != NULL) {
      g_print (_("%s: %s\nTry %s --help to see a full list of available command line options.\n"), PACKAGE, error->message, PACKAGE_NAME);
      g_error_free (error);
      return EXIT_FAILURE;
    }
  }

  if (!burn_initialize ()) {
    g_critical ("Unable to initialize libburn");
    xfce_dialog_show_error (NULL, NULL, _("Unable to initialize the burning backend."));
    gdk_threads_leave ();
    return EXIT_FAILURE;
  }

#ifdef HAVE_GST
  if (!gst_init_check (&argc, &argv, &error)) {
    g_critical ("Failed to initialize gstreamer!");
    /* I'm assuming this pretty much never happens. If it does, we should make this a soft failure and fall back to basic */
    gdk_threads_leave ();
    burn_finish ();
    return EXIT_FAILURE;
  }
#endif

  if (show_version) {
#ifdef HAVE_GST
    const char *nano_str;
    guint gst_major, gst_minor, gst_micro, gst_nano;
#endif

    g_print ("%s version %s for Xfce %s\n", PACKAGE, VERSION, xfce_version_string ());
    g_print ("\tbuilt with GTK+-%d.%d.%d, ", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
    g_print ("linked with GTK+-%d.%d.%d.\n", gtk_major_version, gtk_minor_version, gtk_micro_version);

#ifdef HAVE_GST
    gst_version (&gst_major, &gst_minor, &gst_micro, &gst_nano);

    if (gst_nano == 1)
      nano_str = " (CVS)";
    else if (gst_nano == 2)
      nano_str = " (Prerelease)";
    else
      nano_str = "";

    g_print ("\tGStreamer support (built with %d.%d.%d, linked against %d.%d.%d%s)\n",
             GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO,
             gst_major, gst_minor, gst_micro, nano_str);
             
#endif
    exit (EXIT_SUCCESS);
  }

  if (transcoder_selection && strcmp (transcoder_selection, "list") == 0) {
    print_available_transcoders();
    gdk_threads_leave ();
    burn_finish ();
    return EXIT_SUCCESS;
  }

  DBG ("%s version %s for Xfce %s\n", PACKAGE, VERSION, xfce_version_string ());

  xfburn_settings_init ();
  
#ifdef HAVE_GUDEV
  error_msg = xfburn_udev_manager_create_global ();
  if (error_msg) {
    xfce_dialog_show_error (NULL, NULL, "%s", error_msg);
    gdk_threads_leave ();
    burn_finish ();
    return EXIT_FAILURE;
  } else {
    g_message ("Using UDEV");
  }
#endif

  xfburn_stock_init ();
  devlist = xfburn_device_list_new ();
  g_object_get (devlist, "num-burners", &n_burners, NULL);

  if (n_burners < 1) {
    GtkMessageDialog *dialog = (GtkMessageDialog *) gtk_message_dialog_new (NULL,
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
                                    GTK_MESSAGE_WARNING,
                                    GTK_BUTTONS_CLOSE,
                                    ((const gchar *) _("No burners are currently available")));
    gtk_message_dialog_format_secondary_text (dialog,
                                    _("Possibly the disc(s) are in use, and cannot get accessed.\n\n"
                                      "Please unmount and restart the application.\n\n"
                                      "If no disc is in the drive, check that you have read and write access to the drive with the current user."));
    gtk_dialog_run (GTK_DIALOG (dialog));
    gtk_widget_destroy (GTK_WIDGET (dialog));
  }


  /*----------Transcoder--------------------------------------------------*/

  if (!transcoder_selection) {
    /* select the best available */
#ifdef HAVE_GST
    transcoder = XFBURN_TRANSCODER (xfburn_transcoder_gst_new ());
#else
    transcoder = XFBURN_TRANSCODER (xfburn_transcoder_basic_new ());
#endif
#ifdef HAVE_GST
  } else if (strcmp (transcoder_selection, "gst") == 0) {
    transcoder = XFBURN_TRANSCODER (xfburn_transcoder_gst_new ());
#endif
  } else if (strcmp (transcoder_selection, "basic") == 0) {
    transcoder = XFBURN_TRANSCODER (xfburn_transcoder_basic_new ());
  } else {
    g_print ("'%s' is an invalid transcoder selection.\n",
             transcoder_selection);
    g_print ("\n");
    print_available_transcoders();
    gdk_threads_leave ();
    burn_finish ();
    return EXIT_FAILURE;
  }

  if (!xfburn_transcoder_is_initialized (transcoder, &error)) {
    xfce_dialog_show_warning(NULL, NULL, _("Failed to initialize %s transcoder: %s\n\t(falling back to basic implementation)"), xfburn_transcoder_get_name (transcoder), error->message);
    g_error_free (error);
    g_object_unref (transcoder);
    transcoder = XFBURN_TRANSCODER (xfburn_transcoder_basic_new ());
  } else {
    g_message ("Using %s transcoder.", xfburn_transcoder_get_name (transcoder));
  }
  xfburn_transcoder_set_global (transcoder);


  /*----------evaluate parsed command line action options-------------------------*/

  /* heuristic for file names on the commandline */
  if (argc == 2 && !add_data_composition && !add_audio_composition) {
    /* exactly one filename, assume it is an image */
      image_filename = argv[1];
  } else if (argc > 2) {
    /* several file names, for now just open up a data composition */
    /* TODO: auto-detect music files for audio compositions */
    add_data_composition = TRUE;
  }


  if (show_main) {
    xfburn_main_enter_main_window ();
  }

  if (image_filename != NULL) {
    GtkWidget *dialog = xfburn_burn_image_dialog_new ();
    other_action = TRUE;

    DBG ("image_filename = '%s'\n", image_filename);

    if (*image_filename != '\0') {
      gchar *image_fullname;

      if (!g_path_is_absolute (image_filename))
	image_fullname  = g_build_filename (g_get_current_dir (), image_filename, NULL);
      else
	image_fullname = image_filename;

      if (g_file_test (image_fullname, G_FILE_TEST_EXISTS))
	xfburn_burn_image_dialog_set_filechooser_name (dialog, image_fullname);
      else
        xfce_dialog_show_error (NULL, NULL, _("Image file '%s' does not exist."), image_fullname);
    }

    gtk_dialog_run (GTK_DIALOG (dialog));
    gtk_widget_destroy (dialog);
  } else if (blank) {
    GtkWidget *dialog = xfburn_blank_dialog_new ();

    other_action = TRUE;
    gtk_dialog_run (GTK_DIALOG (dialog));
    gtk_widget_destroy (dialog);
  }


  /*----------main window--------------------------------------------------*/

  if (!other_action || show_main) {
    xfburn_main_enter_main_window ();
    mainwin = xfburn_main_window_new ();

    gtk_widget_show (mainwin);
  
    if (add_data_composition)
      xfburn_main_window_add_data_composition_with_files (XFBURN_MAIN_WINDOW (mainwin), argc-1, argv+1);

    if (add_audio_composition)
      xfburn_main_window_add_audio_composition_with_files (XFBURN_MAIN_WINDOW (mainwin), argc-1, argv+1);
  }


  gtk_main ();


  /*----------shutdown--------------------------------------------------*/

  g_object_unref (devlist);
  g_object_unref (transcoder);

#ifdef HAVE_GUDEV
  xfburn_udev_manager_shutdown ();
#endif

  xfburn_settings_flush ();
  xfburn_settings_free ();
  
  burn_finish ();

  gdk_threads_leave ();

  return EXIT_SUCCESS;
}
static void calibrate (gpointer button)
{
	GtkProgressBar *calib_progress = NULL;
	double rx_phase_lpc, rx_phase_hpc, tx_phase_hpc;
	struct iio_channel *in0, *in0_slave;
	long long cal_tone, cal_freq;
	int ret, samples;

	in0 = iio_device_find_channel(dev, "voltage0", false);
	in0_slave = iio_device_find_channel(dev_slave, "voltage0", false);
	if (!in0 || !in0_slave) {
		printf("could not find channels\n");
		ret = -ENODEV;
		goto calibrate_fail;
	}

	if (!cf_ad9361_lpc || !cf_ad9361_hpc) {
		printf("could not find capture cores\n");
		ret = -ENODEV;
		goto calibrate_fail;
	}

	if (!dev_dds_master || !dev_dds_slave) {
		printf("could not find dds cores\n");
		ret = -ENODEV;
		goto calibrate_fail;
	}

	calib_progress = GTK_PROGRESS_BAR(gtk_builder_get_object(builder, "progress_calibration"));
	set_calibration_progress(calib_progress, 0.00);

	mcs_cb(NULL, NULL);

	/*
	 * set some logical defaults / assumptions
	 */

	ret = default_dds(get_cal_tone(), CAL_SCALE);
	if (ret < 0) {
		printf("could not set dds cores\n");
		goto calibrate_fail;
	}

	iio_channel_attr_read_longlong(dds_out[0][0], "frequency", &cal_tone);
	iio_channel_attr_read_longlong(dds_out[0][0], "sampling_frequency", &cal_freq);

	samples = get_cal_samples(cal_tone, cal_freq);

	DBG("cal_tone %lld cal_freq %lld samples %d", cal_tone, cal_freq, samples);

	gdk_threads_enter();
	osc_plot_set_sample_count(plot_xcorr_4ch, samples);
	osc_plot_draw_start(plot_xcorr_4ch);
	gdk_threads_leave();

	/* Turn off quadrature tracking while the sync is going on */
	iio_channel_attr_write(in0, "quadrature_tracking_en", "0");
	iio_channel_attr_write(in0_slave, "quadrature_tracking_en", "0");

	/* reset any Tx rotation to zero */
	trx_phase_rotation(cf_ad9361_lpc, 0.0);
	trx_phase_rotation(cf_ad9361_hpc, 0.0);
	set_calibration_progress(calib_progress, 0.16);

	/*
	 * Calibrate RX:
	 * 1 TX1B_B (HPC) -> RX1C_B (HPC) : BIST_LOOPBACK on A
	 */
	osc_plot_xcorr_revert(plot_xcorr_4ch, true);
	__cal_switch_ports_enable_cb(1);
	rx_phase_hpc = tune_trx_phase_offset(cf_ad9361_hpc, &ret, cal_freq, cal_tone, 1.0, 0.01, trx_phase_rotation);
	if (ret < 0) {
		printf("Failed to tune phase : %s:%i\n", __func__, __LINE__);
		goto calibrate_fail;
	}
	set_calibration_progress(calib_progress, 0.40);
	DBG("rx_phase_hpc %f", rx_phase_hpc);

	/*
	 * Calibrate RX:
	 * 3 TX1B_B (HPC) -> RX1C_A (LPC) : BIST_LOOPBACK on B
	 */

	osc_plot_xcorr_revert(plot_xcorr_4ch, false);
	trx_phase_rotation(cf_ad9361_hpc, 0.0);
	__cal_switch_ports_enable_cb(3);
	rx_phase_lpc = tune_trx_phase_offset(cf_ad9361_lpc, &ret, cal_freq, cal_tone, 1.0, 0.01, trx_phase_rotation);
	if (ret < 0) {
		printf("Failed to tune phase : %s:%i\n", __func__, __LINE__);
		goto calibrate_fail;
	}
	set_calibration_progress(calib_progress, 0.64);

	(void) rx_phase_lpc; /* Avoid compiler warnings */
	DBG("rx_phase_lpc %f", rx_phase_lpc);

	/*
	 * Calibrate TX:
	 * 4 TX1B_A (LPC) -> RX1C_A (LPC) : BIST_LOOPBACK on B
	 */

	osc_plot_xcorr_revert(plot_xcorr_4ch, false);
	trx_phase_rotation(cf_ad9361_hpc, 0.0);
	__cal_switch_ports_enable_cb(4);
	tx_phase_hpc = tune_trx_phase_offset(dev_dds_slave, &ret, cal_freq, cal_tone, -1.0 , 0.001, trx_phase_rotation);
	if (ret < 0) {
		printf("Failed to tune phase : %s:%i\n", __func__, __LINE__);
		goto calibrate_fail;
	}
	set_calibration_progress(calib_progress, 0.88);
	DBG("tx_phase_hpc %f", tx_phase_hpc);

	trx_phase_rotation(cf_ad9361_hpc, rx_phase_hpc);

	gtk_range_set_value(GTK_RANGE(GTK_WIDGET(gtk_builder_get_object(builder,
			"tx_phase"))), scale_phase_0_360(tx_phase_hpc));

	ret = 0;
	set_calibration_progress(calib_progress, 1.0);

calibrate_fail:

	osc_plot_xcorr_revert(plot_xcorr_4ch, false);
	__cal_switch_ports_enable_cb(0);

	if (in0 && in0_slave) {
		iio_channel_attr_write(in0, "quadrature_tracking_en", "1");
		iio_channel_attr_write(in0_slave, "quadrature_tracking_en", "1");
	}

	gdk_threads_enter();
	reload_settings();

	if (ret) {
		create_blocking_popup(GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
			"FMCOMMS5", "Calibration failed");
		auto_calibrate = -1;
	} else {
		/* set completed flag for testing */
		auto_calibrate = 1;
	}

	osc_plot_destroy(plot_xcorr_4ch);
	if (button)
		gtk_widget_show(GTK_WIDGET(button));
	gdk_threads_leave();

	/* reset progress bar */
	gtk_progress_bar_set_fraction(calib_progress, 0.0);
	gtk_progress_bar_set_text(calib_progress, "Calibration Progress");

	/* Disable the channels that were enabled at the beginning of the calibration */
	struct iio_device *iio_dev;
	iio_dev = iio_context_find_device(get_context_from_osc(), CAP_DEVICE_ALT);
	if (iio_dev && cap_device_channels_enabled) {
		iio_channels_change_shadow_of_enabled(iio_dev, false);
		cap_device_channels_enabled = false;
	}

	g_thread_exit(NULL);
}
Esempio n. 24
0
File: main.c Progetto: nanley/glawn
int main (int argc, char *argv[])
{
	/* GUI widgets */
	GtkWidget *window;
	GtkWidget *align;
	GtkWidget *expander;
	GtkWidget *label;
	GtkWidget *radio1, *radio2;
	GtkWidget *check;
	GtkWidget *button;
	GtkWidget *entry;
	GtkTooltips *tooltip;

	/* Packing boxes */
	GtkWidget *vbMain;			/* main vertical box */
	GtkWidget *hbox1, *vbox1, *vbox2;	/* username/password */
	GtkWidget *hbox2, *vbox3, *hbMac;	/* login options */
	GtkWidget *hbox3;			/* cancel/login buttons */
	GtkWidget *hbox9;			/* show pwd & gtl */

	/* Initialize multihreading and gtk functions */
	g_thread_init (NULL);
	gdk_threads_init ();
	gdk_threads_enter ();
	gtk_init (&argc, &argv);

	/* Create main window */
	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW(window), "Glawn");
	gtk_window_set_resizable (GTK_WINDOW(window), FALSE);
	gtk_container_set_border_width (GTK_CONTAINER (window), 10);
	g_signal_connect (window, "destroy", G_CALLBACK(quit_glawn), NULL);
	GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file ("./icons/glawn-icon.png", NULL);
  	gtk_window_set_icon (GTK_WINDOW(window), pixbuf);

	/* Create pack boxes */
	vbMain= gtk_vbox_new (FALSE, 3);
	vbox1 = gtk_vbox_new (FALSE, 0);
	vbox2 = gtk_vbox_new (FALSE, 3);
	vbox3 = gtk_vbox_new (FALSE, 0);
	hbox1 = gtk_hbox_new (FALSE, 0);
	hbox2 = gtk_hbox_new (FALSE, 0);
	hbox3 = gtk_hbox_new (FALSE, 0);
	hbMac = gtk_hbox_new (FALSE, 0);
	hbox9 = gtk_hbox_new (FALSE, 0);
	gtk_container_add (GTK_CONTAINER (window), vbMain);

	/* Username entry label */
	label = gtk_label_new ("GT Account : ");
	gtk_misc_set_alignment ((GtkMisc *)label, 0, 0);
	gtk_box_pack_start (GTK_BOX(vbox1), label, TRUE, FALSE, 0);

	/* Password entry label */
	label = gtk_label_new ("Password : "******"");
	gtk_box_pack_start (GTK_BOX(vbox1),label,FALSE, FALSE, 2);

	/* Username entry field */
	data.nameEntry = entry = gtk_entry_new_with_max_length (50);
	gtk_entry_set_width_chars (GTK_ENTRY(entry), 25);
	g_signal_connect (entry, "activate", G_CALLBACK(login), NULL);
	gtk_box_pack_start (GTK_BOX(vbox2), entry, FALSE, FALSE, 0);

	/* Password entry field */
	data.pwdEntry = entry = gtk_entry_new_with_max_length(50);
	gtk_entry_set_visibility (GTK_ENTRY(entry), FALSE);
	g_signal_connect (entry, "activate", G_CALLBACK(login), NULL);
	gtk_box_pack_start (GTK_BOX(vbox2), entry, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX(hbox1), vbox2, TRUE, TRUE, 0);
	gtk_box_pack_start (GTK_BOX(vbMain), hbox1, FALSE, FALSE, 0);

	/* Show password checkbox */
	data.pwdCBox = check = gtk_check_button_new_with_mnemonic ("_Show password");
	g_signal_connect (check, "toggled", G_CALLBACK(show_pass), GTK_ENTRY(entry));
	gtk_box_pack_start (GTK_BOX(hbox9), check, FALSE, FALSE, 0);

	/* Location checkbox */
	data.locCBox = check = gtk_check_button_new_with_mnemonic ("_GTL");
	tooltip = gtk_tooltips_new ();
	gtk_tooltips_set_tip (tooltip, check, "Enable Georgia Tech-Lorraine support", NULL);
	gtk_box_pack_start (GTK_BOX(hbox9), check, FALSE, FALSE, 9);
	gtk_box_pack_start (GTK_BOX(vbox2), hbox9, FALSE, FALSE, 0);

	/* Options expander */
	expander = gtk_expander_new_with_mnemonic ("_Options");
	gtk_box_pack_start (GTK_BOX(vbMain), expander, FALSE, FALSE, 0);
	gtk_container_add (GTK_CONTAINER(expander), hbox2);

	/* Left indent alignment for expander */
	align = gtk_alignment_new (0, 0, 1 , 1);
	gtk_widget_set_size_request (align, 17, 0);
	gtk_box_pack_start (GTK_BOX(hbox2), align, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX(hbox2), vbox3, FALSE, FALSE, 0);

	/* ISS checkbox */
	data.issCBox = check = gtk_check_button_new_with_mnemonic
				("_Enable Inbound Service Security");
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(check), TRUE);
	gtk_box_pack_start (GTK_BOX(vbox3), check, FALSE, FALSE, 0);
	tooltip = gtk_tooltips_new ();
	gtk_tooltips_set_tip (tooltip, check, "When turned on,"
	" devices outside of the LAWN network are blocked from "
	"connecting to services running on your device.", NULL);

	/* Login this device radio */
	data.radio_this = radio1 = gtk_radio_button_new_with_mnemonic_from_widget
					(NULL, "Lo_gin this device");
	g_signal_connect (radio1, "toggled", G_CALLBACK(mac_switch), (gpointer) FALSE);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(radio1), TRUE);
	gtk_box_pack_start (GTK_BOX(vbox3), radio1, FALSE, FALSE, 0);

	/* Login other device radio */
	data.radio_other = radio2 = gtk_radio_button_new_with_mnemonic_from_widget
		(GTK_RADIO_BUTTON(radio1), "Login a _different device");
	g_signal_connect (radio2, "toggled", G_CALLBACK(mac_switch), (gpointer) TRUE);
	gtk_box_pack_start (GTK_BOX(vbox3), radio2, FALSE, FALSE, 0);
	gtk_tooltips_set_tip (tooltip, radio2, "You can authenticate other"
	" devices currently on LAWN. The login will last as long as the"
	" device maintains a valid DHCP lease. You accept responsibility"
	" for all usage associated with this device.", NULL);

	/* MAC address label and entry */
	label = gtk_label_new ("        MAC Address : "); // more elegance
	data.macEntry = entry = gtk_entry_new_with_max_length (12);
	gtk_entry_set_width_chars (GTK_ENTRY(entry), 18);
	gtk_widget_set_sensitive (entry, FALSE);
	gtk_box_pack_start (GTK_BOX(hbMac), label, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX(hbMac), entry, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX(vbox3), hbMac, FALSE, FALSE, 0);

	/* Login button */
	data.login = button = gtk_button_new_with_mnemonic (" _Login ");
	gtk_widget_set_sensitive (button, FALSE);
	g_signal_connect (button, "clicked", G_CALLBACK(login), NULL);
	gtk_box_pack_end (GTK_BOX(hbox3), button, FALSE, FALSE, 5);

	/* Logout button */
	data.logout = button = gtk_button_new_with_mnemonic ("Logou_t");
        gtk_widget_set_sensitive (button, FALSE);
	g_signal_connect (button, "clicked", G_CALLBACK(logout), NULL);
	gtk_box_pack_end (GTK_BOX(hbox3), button, FALSE, FALSE, 0);

	/* Spinner */
	data.spinner = gtk_spinner_new ();
	gtk_box_pack_start (GTK_BOX(hbox3), data.spinner, FALSE, FALSE, 2);

	/* Statusbar */
	data.status = label = gtk_label_new ("");
	gtk_box_pack_start (GTK_BOX(hbox3), label, FALSE, FALSE, 2);
	gtk_box_pack_start (GTK_BOX(vbMain), hbox3, FALSE, FALSE, 0);

	/* Display window */
	gtk_widget_show_all (window);

	/* Ascii art */
	g_printf ("\n===========================\n"
		  "     Welcome to Glawn!\n"
		  "===========================\n\n");

	/*Load_settings */
	init_mutex();
	load_settings();
	update_gui (LOAD_INI_START);
	
	// send curl request for status
	update_gui (CHECK_STAT_START);
	g_thread_create((GThreadFunc)check_status, NULL, FALSE, NULL);
	g_timeout_add_seconds_full(G_PRIORITY_LOW, 1, init_check_status, NULL, NULL);
	
   	/* Start main loop */
	gtk_main ();
	gdk_threads_leave ();

	return 0;
}
JNIEXPORT void JNICALL 
Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getGlyphs
  (JNIEnv *env, jobject obj, jintArray codepoints, jintArray glyphs,
   jlongArray fonts)
{
  PangoFcFont *default_font, *current_font;
  PangoFontset *pfs;
  jint *cpvals;
  jint length;
  int i;

  /* Set up default font and fontset */
  default_font = getFont(env, obj);
  current_font = default_font;
  pfs = getFontSet(env, obj);

  /* Retrieve string information */
  length = (*env)->GetArrayLength (env, codepoints);
  cpvals = (*env)->GetIntArrayElements (env, codepoints, NULL);
  
  jint *glyphArray = (*env)->GetIntArrayElements (env, glyphs, NULL);
  jlong *fontArray = (*env)->GetLongArrayElements (env, fonts, NULL);

  /* A design goal of Pango is to be threadsafe, but it's admitted that it is
   * not actually threadsafe at the moment.  Using gdk locking here to be safe,
   * but I don't know if if actually helps at all... */ 
  gdk_threads_enter();

  for( i = 0; i < length; i++ )
  {
  	/* Ensure the current font has the requested character; if it doesn't,
  	 * try the default font before pulling a new font out of the fontset.
  	 * Once chosen, a font will be used until a character not in the font is
  	 * encountered. */ 
  	if (!pango_fc_font_has_char(current_font, cpvals[i]))
  	  {
  	    if (pango_fc_font_has_char(default_font, cpvals[i]))
  	      {
  	        current_font = default_font;
            g_object_ref(current_font);
  	      }
  	    else
  	      {
  	        current_font = (PangoFcFont*)pango_fontset_get_font(pfs, cpvals[i]);
  	      }
  	  }
  	else
      {
        g_object_ref(current_font);
      }
  	
  	/* Get glyph, and store both glyph and pointer to font */
    glyphArray[i] = (int)pango_fc_font_get_glyph(current_font,
                                                 (gunichar)cpvals[i]);
    fontArray[i] = PTR_TO_JLONG(current_font);
  }
  
  gdk_threads_leave();

  (*env)->ReleaseIntArrayElements (env, glyphs, glyphArray, 0);
  (*env)->ReleaseIntArrayElements (env, codepoints, cpvals, 0);
  (*env)->ReleaseLongArrayElements (env, fonts, fontArray, 0);
}
Esempio n. 26
0
static void calibrate (gpointer button)
{
	GtkProgressBar *calib_progress;
	double rx_phase_lpc, rx_phase_hpc, tx_phase_hpc;
	struct iio_channel *in0 = NULL, *in0_slave = NULL;
	long long cal_tone, cal_freq;
	int ret, samples;

	in0 = iio_device_find_channel(dev, "voltage0", false);
	in0_slave = iio_device_find_channel(dev_slave, "voltage0", false);
	if (!in0 || !in0_slave) {
		printf("could not find channels\n");
		ret = -ENODEV;
		auto_calibrate = -1;
		goto calibrate_fail;
	}

	if (!cf_ad9361_lpc || !cf_ad9361_hpc) {
		printf("could not find capture cores\n");
		ret = -ENODEV;
		auto_calibrate = -1;
		goto calibrate_fail;
	}

	if (!dev_dds_master || !dev_dds_slave) {
		printf("could not find dds cores\n");
		ret = -ENODEV;
		auto_calibrate = -1;
		goto calibrate_fail;
	}



	calib_progress = GTK_PROGRESS_BAR(gtk_builder_get_object(builder, "progress_calibration"));
	set_calibration_progress(calib_progress, 0.00);

	mcs_cb(NULL, NULL);

	/*
	 * set some logical defaults / assumptions
	 */

	ret = default_dds(get_cal_tone(), CAL_SCALE);
	if (ret < 0) {
		printf("could not set dds cores\n");
		auto_calibrate = -1;
		goto calibrate_fail;
	}

	iio_channel_attr_read_longlong(dds_out[0][0], "frequency", &cal_tone);
	iio_channel_attr_read_longlong(dds_out[0][0], "sampling_frequency", &cal_freq);

	samples = get_cal_samples(cal_tone, cal_freq);

	DBG("cal_tone %u cal_freq %u samples %d", cal_tone, cal_freq, samples);

	gdk_threads_enter();
	osc_plot_set_sample_count(plot_xcorr_4ch, samples);
	osc_plot_draw_start(plot_xcorr_4ch);
	gdk_threads_leave();


	iio_channel_attr_write(in0, "in_voltage_quadrature_tracking_en", "0");
	iio_channel_attr_write(in0_slave, "in_voltage_quadrature_tracking_en", "0");

	trx_phase_rotation(cf_ad9361_lpc, 0.0);
	trx_phase_rotation(cf_ad9361_hpc, 0.0);
	set_calibration_progress(calib_progress, 0.16);

	/*
	 * Calibrate RX:
	 * 1 TX1B_B (HPC) -> RX1C_B (HPC) : BIST_LOOPBACK on A
	 */
	osc_plot_xcorr_revert(plot_xcorr_4ch, true);
	__cal_switch_ports_enable_cb(1);
	rx_phase_hpc = tune_trx_phase_offset(cf_ad9361_hpc, &ret, cal_freq, cal_tone, 1.0, 0.01, trx_phase_rotation);
	if (ret < 0) {
		printf("Failed to tune phase\n");
		auto_calibrate = -1;
		goto calibrate_fail;
	}
	set_calibration_progress(calib_progress, 0.40);
	DBG("rx_phase_hpc %f", rx_phase_hpc);

	/*
	 * Calibrate RX:
	 * 3 TX1B_B (HPC) -> RX1C_A (LPC) : BIST_LOOPBACK on B
	 */

	osc_plot_xcorr_revert(plot_xcorr_4ch, false);
	trx_phase_rotation(cf_ad9361_hpc, 0.0);
	__cal_switch_ports_enable_cb(3);
	rx_phase_lpc = tune_trx_phase_offset(cf_ad9361_lpc, &ret, cal_freq, cal_tone, 1.0, 0.01, trx_phase_rotation);
	if (ret < 0) {
		printf("Failed to tune phase\n");
		auto_calibrate = -1;
		goto calibrate_fail;
	}
	set_calibration_progress(calib_progress, 0.64);

	(void) rx_phase_lpc; /* Avoid compiler warnings */
	DBG("rx_phase_lpc %f", rx_phase_lpc);

	/*
	 * Calibrate TX:
	 * 4 TX1B_A (LPC) -> RX1C_A (LPC) : BIST_LOOPBACK on B
	 */

	osc_plot_xcorr_revert(plot_xcorr_4ch, false);
	trx_phase_rotation(cf_ad9361_hpc, 0.0);
	__cal_switch_ports_enable_cb(4);
	tx_phase_hpc = tune_trx_phase_offset(dev_dds_slave, &ret, cal_freq, cal_tone, -1.0 , 0.001, trx_phase_rotation);
	if (ret < 0) {
		printf("Failed to tune phase\n");
		auto_calibrate = -1;
		goto calibrate_fail;
	}
	set_calibration_progress(calib_progress, 0.88);
	DBG("tx_phase_hpc %f", tx_phase_hpc);

	trx_phase_rotation(cf_ad9361_hpc, rx_phase_hpc);

	gtk_range_set_value(GTK_RANGE(GTK_WIDGET(gtk_builder_get_object(builder,
			"tx_phase"))), scale_phase_0_360(tx_phase_hpc));

	ret = 0;
	set_calibration_progress(calib_progress, 1.0);

calibrate_fail:

	osc_plot_xcorr_revert(plot_xcorr_4ch, false);
	__cal_switch_ports_enable_cb(0);

	if (in0 && in0_slave) {
		iio_channel_attr_write(in0, "in_voltage_quadrature_tracking_en", "1");
		iio_channel_attr_write(in0_slave, "in_voltage_quadrature_tracking_en", "1");
	}

	gdk_threads_enter();
	reload_settings();

	create_blocking_popup(GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
			"FMCOMMS5", "Calibration finished %s",
			ret ? "with Error" : "Successfully");
	auto_calibrate = 1;

	osc_plot_destroy(plot_xcorr_4ch);
	if (button)
		gtk_widget_show(GTK_WIDGET(button));
	gdk_threads_leave();

	g_thread_exit(NULL);
}
Esempio n. 27
0
gint
remmina_ssh_auth_gui (RemminaSSH *ssh, RemminaInitDialog *dialog, gboolean threaded)
{
	gchar *tips;
	gchar *keyname;
	gint ret;
	size_t len;
	guchar *pubkey;
	ssh_key server_pubkey;

	/* Check if the server's public key is known */
	ret = ssh_is_server_known (ssh->session);
	switch (ret)
	{
		case SSH_SERVER_KNOWN_OK:
			break;

		case SSH_SERVER_NOT_KNOWN:
		case SSH_SERVER_FILE_NOT_FOUND:
		case SSH_SERVER_KNOWN_CHANGED:
		case SSH_SERVER_FOUND_OTHER:
			if ( ssh_get_publickey(ssh->session, &server_pubkey) != SSH_OK )
			{
				remmina_ssh_set_error(ssh, "ssh_get_publickey() has failed: %s");
				return 0;
			}
			if ( ssh_get_publickey_hash(server_pubkey, SSH_PUBLICKEY_HASH_MD5, &pubkey, &len) != 0 ) {
				ssh_key_free(server_pubkey);
				remmina_ssh_set_error(ssh, "ssh_get_publickey_hash() has failed: %s");
				return 0;
			}
			ssh_key_free(server_pubkey);
			keyname = ssh_get_hexa (pubkey, len);

			if (threaded) gdk_threads_enter();
			if (ret == SSH_SERVER_NOT_KNOWN || ret == SSH_SERVER_FILE_NOT_FOUND)
			{
				ret = remmina_init_dialog_serverkey_unknown (dialog, keyname);
			}
			else
			{
				ret = remmina_init_dialog_serverkey_changed (dialog, keyname);
			}
			if (threaded)
			{	gdk_flush();gdk_threads_leave();}

			ssh_string_free_char(keyname);
			ssh_clean_pubkey_hash (&pubkey);
			if (ret != GTK_RESPONSE_OK) return -1;
			ssh_write_knownhost (ssh->session);
			break;
		case SSH_SERVER_ERROR:
		default:
			remmina_ssh_set_error (ssh, "SSH known host checking failed: %s");
		return 0;
	}

	/* Try empty password or existing password first */
	ret = remmina_ssh_auth (ssh, NULL);
	if (ret > 0) return 1;

	/* Requested for a non-empty password */
	if (ret < 0)
	{
		if (!dialog) return -1;

		switch (ssh->auth)
		{
			case SSH_AUTH_PASSWORD:
			tips = _("Authenticating %s's password to SSH server %s...");
			keyname = _("SSH password");
			break;
			case SSH_AUTH_PUBLICKEY:
			tips = _("Authenticating %s's identity to SSH server %s...");
			keyname = _("SSH private key passphrase");
			break;
			default:
			return FALSE;
		}

		if (ssh->auth != SSH_AUTH_AUTO_PUBLICKEY)
		{
			if (threaded) gdk_threads_enter();
			remmina_init_dialog_set_status (dialog, tips, ssh->user, ssh->server);

			ret = remmina_init_dialog_authpwd (dialog, keyname, FALSE);
			if (threaded)
			{	gdk_flush();gdk_threads_leave();}

			if (ret != GTK_RESPONSE_OK) return -1;
		}
		ret = remmina_ssh_auth (ssh, dialog->password);
	}

	if (ret <= 0)
	{
		return 0;
	}

	return 1;
}
gboolean
pre_event_handler (GtkWidget *widget, GdkEvent *event, jobject peer)
{
  GtkWidget *event_widget;
  static guint32 button_click_time = 0;
  static GdkWindow *button_window = NULL;
  static guint button_number = -1;
  static jint click_count = 1;

  /* If it is not a focus change event, the widget must be realized already.
     If not, ignore the event (Gtk+ will do the same). */
  if (!(event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget)))
    return FALSE;
    
  /* Do not handle propagated events.  AWT has its own propagation rules */
  gdk_window_get_user_data (event->any.window, (void **) &event_widget);
  if (event_widget != widget)
    return FALSE;

  /* We only care about input events */    
  if (!(event->type == GDK_BUTTON_PRESS
       || event->type == GDK_BUTTON_RELEASE
       || event->type == GDK_ENTER_NOTIFY
       || event->type == GDK_LEAVE_NOTIFY
       || event->type == GDK_CONFIGURE
       || event->type == GDK_EXPOSE
       || event->type == GDK_KEY_PRESS
       || event->type == GDK_KEY_RELEASE
       || event->type == GDK_FOCUS_CHANGE
       || event->type == GDK_MOTION_NOTIFY))
    {
      return FALSE;
    }
  /* g_print("event %u widget %s peer %p\n",
            event->type, gtk_widget_get_name (widget), peer); */

  /* If it has no jobject associated we can send no AWT event */
  if (!peer)
    return FALSE;

  /* for all input events, which have a window with a jobject attached,
     send the AWT input event corresponding to the Gtk event off to Java  */

  /* keep track of clickCount ourselves, since the AWT allows more
     than a triple click to occur */
  if (event->type == GDK_BUTTON_PRESS)
    {
      if ((event->button.time < (button_click_time + MULTI_CLICK_TIME))
	  && (event->button.window == button_window)
	  && (event->button.button == button_number))
	click_count++;
      else
	click_count = 1;
      
      button_click_time = event->button.time;
      button_window = event->button.window;
      button_number = event->button.button;
    }

  switch (event->type)
    {
    case GDK_BUTTON_PRESS:
      (*gdk_env)->CallVoidMethod (gdk_env, peer,
                                  postMouseEventID,
				  AWT_MOUSE_PRESSED, 
				  (jlong)event->button.time,
				  state_to_awt_mods (event->button.state) |
				  button_to_awt_mods (event->button.button), 
				  (jint)event->button.x,
				  (jint)event->button.y, 
				  click_count, 
				  (event->button.button == 3) ? JNI_TRUE :
				                                JNI_FALSE);
      break;
    case GDK_BUTTON_RELEASE:
      {
	int width, height;

	(*gdk_env)->CallVoidMethod (gdk_env, peer,
				    postMouseEventID,
				    AWT_MOUSE_RELEASED, 
				    (jlong)event->button.time,
				    state_to_awt_mods (event->button.state) |
				    button_to_awt_mods (event->button.button), 
				    (jint)event->button.x,
				    (jint)event->button.y, 
				    click_count,
				    JNI_FALSE);

	/* check to see if the release occured in the window it was pressed
	   in, and if so, generate an AWT click event */
	gdk_window_get_size (event->any.window, &width, &height);
	if (event->button.x >= 0
            && event->button.y >= 0
	    && event->button.x <= width 
	    && event->button.y <= height)
          {
	    (*gdk_env)->CallVoidMethod (gdk_env, peer,
				        postMouseEventID,
				        AWT_MOUSE_CLICKED, 
				        (jlong)event->button.time,
				        state_to_awt_mods (event->button.state) |
				        button_to_awt_mods (event->button.button), 
				        (jint)event->button.x,
				        (jint)event->button.y, 
				        click_count,
				        JNI_FALSE);
          }
      }
      break;
    case GDK_MOTION_NOTIFY:
      (*gdk_env)->CallVoidMethod (gdk_env, peer, postMouseEventID,
				  AWT_MOUSE_MOVED,
				  (jlong)event->motion.time,
				  state_to_awt_mods (event->motion.state),
				  (jint)event->motion.x,
				  (jint)event->motion.y,
				  0,
				  JNI_FALSE);

      if (event->motion.state & (GDK_BUTTON1_MASK
				 | GDK_BUTTON2_MASK
				 | GDK_BUTTON3_MASK
				 | GDK_BUTTON4_MASK
				 | GDK_BUTTON5_MASK))
	{
	  (*gdk_env)->CallVoidMethod (gdk_env, peer,
			              postMouseEventID,
				      AWT_MOUSE_DRAGGED,
				      (jlong)event->motion.time,
				      state_to_awt_mods (event->motion.state),
				      (jint)event->motion.x,
				      (jint)event->motion.y,
				      0,
				      JNI_FALSE);
	}
      break;
    case GDK_ENTER_NOTIFY:
      (*gdk_env)->CallVoidMethod (gdk_env, peer, postMouseEventID,
				  AWT_MOUSE_ENTERED, 
				  (jlong)event->crossing.time,
				  state_to_awt_mods (event->crossing.state), 
				  (jint)event->crossing.x,
				  (jint)event->crossing.y, 
				  0,
				  JNI_FALSE);
      break;
    case GDK_LEAVE_NOTIFY:
      if (event->crossing.mode == GDK_CROSSING_NORMAL)
	(*gdk_env)->CallVoidMethod (gdk_env, peer,
				    postMouseEventID,
				    AWT_MOUSE_EXITED, 
				    (jlong)event->crossing.time,
				    state_to_awt_mods (event->crossing.state),
				    (jint)event->crossing.x,
				    (jint)event->crossing.y, 
				    0,
				    JNI_FALSE);
      break;
    case GDK_CONFIGURE:
      {
	/* GtkWidget *widget;

	gdk_window_get_user_data (event->any.window, (void **) &widget); */
	    
	if (widget && GTK_WIDGET_TOPLEVEL (widget))
	  {
	    /* Configure events are not posted to the AWT event
	       queue, and as such, the gdk/gtk peer functions will
	       be called back before postConfigureEvent
	       returns. */
	    gdk_threads_leave ();

 	    (*gdk_env)->CallVoidMethod (gdk_env, peer,
					postConfigureEventID,
					(jint) event->configure.x,
					(jint) event->configure.y,
					(jint) event->configure.width,
					(jint) event->configure.height);
	    gdk_threads_enter ();
	  }
      }
      break;
    case GDK_EXPOSE:
      {
	(*gdk_env)->CallVoidMethod (gdk_env, peer,
				    postExposeEventID,
				    (jint)event->expose.area.x,
				    (jint)event->expose.area.y,
				    (jint)event->expose.area.width,
				    (jint)event->expose.area.height);
      }
      break;
    case GDK_FOCUS_CHANGE:
      (*gdk_env)->CallVoidMethod (gdk_env, peer,
				  postFocusEventID,
				  (jint) (event->focus_change.in) ? 
				  AWT_FOCUS_GAINED : AWT_FOCUS_LOST,
				  JNI_FALSE);
      break;
    case GDK_KEY_PRESS:
    case GDK_KEY_RELEASE:
      {
        GdkWindow *obj_window;
        jobject *focus_obj_ptr = NULL;
	int generates_key_typed = 0;

        /* A widget with a grab will get key events */
	if (!GTK_IS_WINDOW (widget))
	  focus_obj_ptr = &peer;
	else
	  {
            GtkWindow *window;

            /* Check if we have an enabled focused widget in this window.
	       If not don't handle the event. */
	    window = GTK_WINDOW (widget);
	    if (!window->focus_widget
	        || !GTK_WIDGET_IS_SENSITIVE (window->focus_widget)
	        || !window->focus_widget->window)
	      return FALSE;
	
            /* TextArea peers are attached to the scrolled window
               that contains the GtkTextView, not to the text view
               itself.  Same for List. */
            if (GTK_IS_TEXT_VIEW (window->focus_widget)
                || GTK_IS_CLIST (window->focus_widget))
              {
                obj_window = gtk_widget_get_parent (window->focus_widget)->window;
              }
            else if (GTK_IS_BUTTON (window->focus_widget))
	      /* GtkButton events go to the "event_window" and this is what
	         we registered when the button was created. */
              obj_window = GTK_BUTTON (window->focus_widget)->event_window;
            else
              obj_window = window->focus_widget->window;

            gdk_property_get (obj_window,
                              gdk_atom_intern ("_GNU_GTKAWT_ADDR", FALSE),
                              gdk_atom_intern ("CARDINAL", FALSE),
                              0,
                              sizeof (jobject),
                              FALSE,
                              NULL,
                              NULL,
                              NULL,
                              (guchar **)&focus_obj_ptr);

            /* If the window has no jobject attached we can't send anything */
	    if (!focus_obj_ptr)
	      return FALSE;
	      
	    /* Should we generate an AWT_KEY_TYPED event? */
	    generates_key_typed = generates_key_typed_event (event, window->focus_widget);
	  }	

	if (event->type == GDK_KEY_PRESS)	
	  {
            (*gdk_env)->CallVoidMethod (gdk_env, *focus_obj_ptr,
				        postKeyEventID,
				        (jint) AWT_KEY_PRESSED,
				        (jlong) event->key.time,
                                        keyevent_state_to_awt_mods (event),
                                        keysym_to_awt_keycode (event),
                                        keyevent_to_awt_keychar (event),
                                        keysym_to_awt_keylocation (event));

            if (generates_key_typed)
              {
                (*gdk_env)->CallVoidMethod (gdk_env, *focus_obj_ptr,
                                            postKeyEventID,
                                            (jint) AWT_KEY_TYPED,
                                            (jlong) event->key.time,
                                            state_to_awt_mods (event->key.state),
                                            VK_UNDEFINED,
                                            keyevent_to_awt_keychar (event),
                                            AWT_KEY_LOCATION_UNKNOWN);
              }
          }
	else /* GDK_KEY_RELEASE */
          {
	    (*gdk_env)->CallVoidMethod (gdk_env, *focus_obj_ptr,
				        postKeyEventID,
				        (jint) AWT_KEY_RELEASED,
				        (jlong) event->key.time,
			                keyevent_state_to_awt_mods (event),
			                keysym_to_awt_keycode (event),
                                        keyevent_to_awt_keychar (event),
                                        keysym_to_awt_keylocation (event));
	  }
      }
      break;
    default:
      break;
    }
  
  return FALSE;
}
Esempio n. 29
0
File: dnd.c Progetto: ayyi/samplecat
gint
drag_received (GtkWidget* widget, GdkDragContext* drag_context, gint x, gint y, GtkSelectionData* data, guint info, guint time, gpointer user_data)
{
	// this receives drops for the whole window.

	if(!data || data->length < 0){ perr("no data!\n"); return -1; }

	dbg(1, "%s", data->data);

	if(g_str_has_prefix((char*)data->data, "colour:")){

		char* colour_string = (char*)data->data + 7;
		unsigned colour_index = atoi(colour_string) ? atoi(colour_string) - 1 : 0;

		// which row are we on?
		GtkTreePath* path;
		GtkTreeIter iter;
		gint tx, treeview_top;
		gdk_window_get_position(app->libraryview->widget->window, &tx, &treeview_top);
		dbg(2, "treeview_top=%i", y);

#ifdef HAVE_GTK_2_12
		gint bx, by;
		gtk_tree_view_convert_widget_to_bin_window_coords(GTK_TREE_VIEW(app->libraryview->widget), x, y - treeview_top, &bx, &by);
		dbg(2, "coords: %dx%d => %dx%d", x, y, bx, by);

#else
		gint by = y - treeview_top - 20;
#endif

#ifdef USE_GDL
		GdkWindow* top_window = gdk_window_get_toplevel(gtk_widget_get_toplevel(app->libraryview->widget)->window);
		GdkWindow* window = app->libraryview->widget->window;
		while((window = gdk_window_get_parent(window)) != top_window){
			gint x0, y0;
			gdk_window_get_position(window, &x0, &y0);
			by -= y0;
		}
#endif

    if(gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(app->libraryview->widget), x, by, &path, NULL, NULL, NULL)){

      gtk_tree_model_get_iter(GTK_TREE_MODEL(samplecat.store), &iter, path);
      gchar* path_str = gtk_tree_model_get_string_from_iter(GTK_TREE_MODEL(samplecat.store), &iter);
      dbg(2, "path=%s y=%i final_y=%i", path_str, y, y - treeview_top);

      listview_item_set_colour(path, colour_index);

      gtk_tree_path_free(path);
    }
    else dbg(0, "path not found.");

    return FALSE;
  }

  if(info == GPOINTER_TO_INT(GDK_SELECTION_TYPE_STRING)) printf(" type=string.\n");

  if(info == GPOINTER_TO_INT(TARGET_URI_LIST)){
    dbg(1, "type=uri_list. len=%i", data->length);
    GList* list = uri_list_to_glist((char*)data->data);
    if(g_list_length(list) < 1) pwarn("drag drop: uri list parsing found no uri's.\n");
    int i = 0;
    ScanResults result = {0,};
    GList* l = list;
#ifdef __APPLE__
    gdk_threads_enter();
#endif
    for(;l;l=l->next){
      char* u = l->data;

      gchar* method_string;
      vfs_get_method_string(u, &method_string);
      dbg(2, "%i: %s method=%s", i, u, method_string);

      if(!strcmp(method_string, "file")){
        //we could probably better use g_filename_from_uri() here
        //http://10.0.0.151/man/glib-2.0/glib-Character-Set-Conversion.html#g-filename-from-uri
        //-or perhaps get_local_path() from rox/src/support.c

        char* uri_unescaped = vfs_unescape_string(u + strlen(method_string) + 1, NULL);

        char* uri = (strstr(uri_unescaped, "///") == uri_unescaped) ? uri_unescaped + 2 : uri_unescaped;

        if(do_progress(0,0)) break;
        if(is_dir(uri)) application_add_dir(uri, &result);
        else application_add_file(uri, &result);

        g_free(uri_unescaped);
      }
      else pwarn("drag drop: unknown format: '%s'. Ignoring.\n", u);
      i++;
    }
    hide_progress();
#ifdef __APPLE__
    gdk_threads_leave();
#endif

    statusbar_print(1, "import complete. %i files added", result.n_added);

    uri_list_free(list);
  }

  return FALSE;
}
Esempio n. 30
0
void wxApp::CleanUp()
{
    gdk_threads_leave();

    wxAppBase::CleanUp();
}