Пример #1
0
gboolean binreloc_init(gboolean try_hardcoded)
{
    GError *error = NULL;
    gchar *tmp;

    DEBUG("initializing binreloc (hardcoded = %d)", try_hardcoded);

    /* If the runtime data directories we previously found, don't even try
       to find them again. */
    if (params.path_data && params.path_lib) {
	DEBUG("data and lib path already found.");
	return TRUE;
    }

    if (try_hardcoded || !gbr_init(&error)) {
	/* We were asked to try hardcoded paths or BinReloc failed to initialize. */
	params.path_data = g_strdup(PREFIX);
	params.path_lib = g_strdup(LIBPREFIX);

	if (error) {
	    g_error_free(error);
	}

	DEBUG("%strying hardcoded paths.",
	      try_hardcoded ? "" : "binreloc init failed. ");
    } else {
	/* If we were able to initialize BinReloc, build the default data
	   and library paths. */
	DEBUG("done, trying to use binreloc paths.");

	tmp = gbr_find_data_dir(PREFIX);
	params.path_data = g_build_filename(tmp, "hardinfo", NULL);
	g_free(tmp);

	tmp = gbr_find_lib_dir(PREFIX);
	params.path_lib = g_build_filename(tmp, "hardinfo", NULL);
	g_free(tmp);
    }

    DEBUG("searching for runtime data on these locations:");
    DEBUG("  lib: %s", params.path_lib);
    DEBUG(" data: %s", params.path_data);

    /* Try to see if the uidefs.xml file isn't missing. This isn't the
       definitive test, but it should do okay for most situations. */
    tmp = g_build_filename(params.path_data, "benchmark.data", NULL);
    if (!g_file_test(tmp, G_FILE_TEST_EXISTS)) {
	DEBUG("runtime data not found");

	g_free(params.path_data);
	g_free(params.path_lib);
	g_free(tmp);

	params.path_data = params.path_lib = NULL;

	if (try_hardcoded) {
	    /* We tried the hardcoded paths, but still was unable to find the
	       runtime data. Give up. */
	    DEBUG("giving up");
	    return FALSE;
	} else {
	    /* Even though BinReloc worked OK, the runtime data was not found.
	       Try the hardcoded paths. */
	    DEBUG("trying to find elsewhere");
	    return binreloc_init(TRUE);
	}
    }
    g_free(tmp);

    DEBUG("runtime data found!");
    /* We found the runtime data; hope everything is fine */
    return TRUE;
}
Пример #2
0
int main( int   argc,
          char *argv[] )
{
    /* GtkWidget is the storage type for widgets */
    GtkWidget *window;
    GtkWidget *menubar;
    time_t     now;
    struct tm *tm;
    GThread   *gth = NULL;         /* thread id */
    gboolean   run_flag = TRUE;   /* used as exit flag for threads */
    int i;

    putenv("UBUNTU_MENUPROXY=");

    //init_trees();

    gdk_color_parse("#FFFF00", &color_yellow);
    gdk_color_parse("#FFFFFF", &color_white);
    gdk_color_parse("#404040", &color_grey);
    gdk_color_parse("#00FF00", &color_green);
    gdk_color_parse("#007700", &color_darkgreen);
    gdk_color_parse("#0000FF", &color_blue);
    gdk_color_parse("#FF0000", &color_red);
    gdk_color_parse("#770000", &color_darkred);
    gdk_color_parse("#000000", &color_black);

    font = pango_font_description_from_string("Sans bold 12");

#ifdef WIN32
    installation_dir = g_win32_get_package_installation_directory_of_module(NULL);
#else
    gbr_init(NULL);
    installation_dir = gbr_find_prefix(NULL);
#endif

    program_path = argv[0];

    current_directory[0] = 0;

    if (current_directory[0] == 0)
        strcpy(current_directory, ".");

    conffile = g_build_filename(g_get_user_data_dir(), "judoproxy.ini", NULL);

    /* create video download dir */
    video_dir = g_build_filename(g_get_home_dir(), "rpivideos", NULL);
    g_print("Video dir = %s\n", video_dir);
    g_mkdir_with_parents(video_dir, 0755);

    keyfile = g_key_file_new();
    g_key_file_load_from_file(keyfile, conffile, 0, NULL);

    now = time(NULL);
    tm = localtime(&now);
    current_year = tm->tm_year+1900;
    srand(now); //srandom(now);
    my_address = now + getpid()*10000;

    gtk_init (&argc, &argv);

    main_window = window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(main_window), "JudoProxy");
    gtk_widget_set_size_request(window, FRAME_WIDTH, FRAME_HEIGHT);

    gchar *iconfile = g_build_filename(installation_dir, "etc", "judoproxy.png", NULL);
    gtk_window_set_default_icon_from_file(iconfile, NULL);
    g_free(iconfile);

    g_signal_connect (G_OBJECT (window), "delete_event",
                      G_CALLBACK (delete_event), NULL);

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

    gtk_container_set_border_width (GTK_CONTAINER (window), 10);

    main_vbox = gtk_grid_new();
    gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 1);
    gtk_container_add (GTK_CONTAINER (window), main_vbox);
    gtk_widget_show(main_vbox);

    /* menubar */
    menubar = get_menubar_menu(window);
    gtk_widget_show(menubar);

    gtk_grid_attach(GTK_GRID(main_vbox), menubar, 0, 0, 1, 1);
    gtk_widget_set_hexpand(menubar, TRUE);

    /* judoka info */
    //name_box = gtk_label_new("?");
    //gtk_box_pack_start(GTK_BOX(main_vbox), name_box, FALSE, TRUE, 0);

    //GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
    //gtk_box_pack_start(GTK_BOX(main_vbox), hbox, FALSE, TRUE, 0);

    notebook = gtk_notebook_new();
    gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), TRUE);
    gtk_widget_set_hexpand(notebook, TRUE);
    //gtk_widget_set_vexpand(notebook, TRUE);
    gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);
    /*
    GtkWidget *camera_table = gtk_grid_new();
    gtk_grid_set_column_spacing(GTK_GRID(camera_table), 10);
    gtk_grid_set_row_spacing(GTK_GRID(camera_table), 10);
    */

    for (i = 0; i < NUM_TATAMIS; i++) {
        gchar buf[32];
        GtkWidget *data_table = gtk_grid_new();
        connections[i].scrolled_window = data_table;
        //connections[i].scrolled_window = gtk_scrolled_window_new(NULL, NULL);
        gtk_container_set_border_width(GTK_CONTAINER(connections[i].scrolled_window), 10);

        snprintf(buf, sizeof(buf), "T%d [--]", i+1);
        gtk_notebook_append_page(GTK_NOTEBOOK(notebook), connections[i].scrolled_window,
                                 gtk_label_new(buf));

        gtk_grid_attach(GTK_GRID(data_table), gtk_label_new(_("Camera")),    0, 0, 2, 1);
        gtk_grid_attach(GTK_GRID(data_table), gtk_label_new(_("JudoTimer")), 4, 0, 2, 1);

	GtkWidget *reload = gtk_button_new_with_label(_("Reload"));
        gtk_grid_attach(GTK_GRID(data_table), reload, 0, 1, 1, 1);

        connections[i].in_addr = gtk_entry_new();
        connections[i].out_addr = gtk_entry_new();
        gtk_entry_set_width_chars(GTK_ENTRY(connections[i].in_addr), 15);
        gtk_entry_set_width_chars(GTK_ENTRY(connections[i].out_addr), 15);
        gtk_grid_attach(GTK_GRID(data_table), connections[i].in_addr, 2, 0, 2, 1);
        gtk_grid_attach(GTK_GRID(data_table), connections[i].out_addr, 6, 0, 2, 1);
        gtk_grid_attach(GTK_GRID(data_table), gtk_label_new(" "), 0, 1, 1, 1);


        //gtk_container_add(GTK_CONTAINER(connections[i].scrolled_window), data_table);
        g_signal_connect (connections[i].out_addr, "activate",
                          G_CALLBACK(enter_callback),
                          gint_to_ptr(i));
        g_signal_connect (connections[i].in_addr, "activate",
                          G_CALLBACK(camera_ip_enter_callback),
                          gint_to_ptr(i));
#ifdef WEBKIT
        g_signal_connect (reload, "clicked",
                          G_CALLBACK(reload_web),
                          gint_to_ptr(i));
#else
        g_signal_connect (reload, "clicked",
                          G_CALLBACK(select_camera_video),
                          gint_to_ptr(i));
#endif
    }

    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
    gtk_grid_attach_next_to(GTK_GRID(main_vbox), notebook, NULL, GTK_POS_BOTTOM, 1, 1);

    progress_bar = gtk_progress_bar_new();
    gtk_grid_attach_next_to(GTK_GRID(main_vbox), progress_bar, NULL, GTK_POS_BOTTOM, 1, 1);

    GtkWidget *w = GTK_WIDGET(gtk_scrolled_window_new(NULL, NULL));
#ifdef WEBKIT
    web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
    webkit_web_view_set_transparent(web_view, TRUE);

    gtk_container_add(GTK_CONTAINER(w), GTK_WIDGET(web_view));
    gtk_widget_set_vexpand(GTK_WIDGET(web_view), TRUE);

    WebKitWebSettings *web_settings = webkit_web_settings_new();
    //g_object_set(G_OBJECT(web_settings), "enable-java-applet", FALSE, NULL);
    //g_object_set(G_OBJECT(web_settings), "enable-plugins", FALSE, NULL);
    webkit_web_view_set_settings(web_view, web_settings);

    gtk_grid_attach_next_to(GTK_GRID(main_vbox), GTK_WIDGET(w), NULL, GTK_POS_BOTTOM, 1, 1);
    gtk_widget_grab_focus(GTK_WIDGET(web_view));

    //webkit_web_view_load_uri(web_view, "http://www.hs.fi");
    webkit_web_view_load_uri(web_view, "http://www.quirksmode.org/html5/tests/video.html");

    g_signal_connect(web_view, "download-requested", G_CALLBACK(download_req), NULL);
    //g_signal_connect(web_view, "load-changed", G_CALLBACK(load_changed), NULL);
#else
    /* HTML page */
    html_page = create_html_page();
    gtk_grid_attach_next_to(GTK_GRID(main_vbox), GTK_WIDGET(html_page), NULL, GTK_POS_BOTTOM, 1, 1);

    /* Video display */
    camera_image = gtk_image_new();
    gtk_widget_set_size_request(GTK_WIDGET(camera_image), 640, 360);

    GtkWidget *event_box = gtk_event_box_new();
    gtk_container_add(GTK_CONTAINER(event_box), camera_image);

    gtk_widget_set_events(event_box, gtk_widget_get_events(event_box) |
                          GDK_BUTTON_PRESS_MASK |
                          GDK_BUTTON_RELEASE_MASK |
                          /*GDK_POINTER_MOTION_MASK |*/
                          GDK_POINTER_MOTION_HINT_MASK |
                          GDK_BUTTON_MOTION_MASK);

    g_signal_connect(G_OBJECT(event_box),
		     "button_press_event",
		     G_CALLBACK(button_press_callback),
		     camera_image);
    g_signal_connect(G_OBJECT(event_box),
		     "button_release_event",
		     G_CALLBACK(button_release_callback),
		     camera_image);
    g_signal_connect(G_OBJECT(event_box),
		     "motion-notify-event",
		     G_CALLBACK(button_notify_callback),
		     camera_image);

    gtk_widget_show(camera_image);
    gtk_container_add(GTK_CONTAINER(w), GTK_WIDGET(event_box));
    gtk_widget_set_vexpand(GTK_WIDGET(event_box), TRUE);
    gtk_widget_set_hexpand(GTK_WIDGET(event_box), TRUE);
    gtk_widget_set_vexpand(GTK_WIDGET(camera_image), TRUE);
    gtk_widget_set_hexpand(GTK_WIDGET(camera_image), TRUE);
    gtk_grid_attach_next_to(GTK_GRID(main_vbox), GTK_WIDGET(w), NULL, GTK_POS_BOTTOM, 1, 1);

#endif

    /* timers */

    timer = g_timer_new();

    gtk_widget_show_all(window);

    set_preferences();
    change_language(NULL, NULL, gint_to_ptr(language));

    open_comm_socket();
    scan_interfaces();

    /* Create a bg thread using glib */
    gpointer proxy_ssdp_thread(gpointer args);
    g_snprintf(ssdp_id, sizeof(ssdp_id), "JudoProxy");

    static gint run[NUM_CONNECTIONS];
    for (i = 0; i < NUM_CONNECTIONS; i++) {
	char tname[16];
	run[i] = i;
	sprintf(tname, "Connection%d", i);
	gth = g_thread_new(tname,
			   (GThreadFunc)connection_thread,
			   &run[i]);
    }

    gth = g_thread_new("SSDP",
                       (GThreadFunc)proxy_ssdp_thread,
                       (gpointer)&run_flag);

    gth = g_thread_new("CameraVideo",
		       camera_video,
		       (gpointer)&run_flag);
    gth = gth; // make compiler happy

    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);

    cursor = gdk_cursor_new(GDK_HAND2);
    //gdk_window_set_cursor(GTK_WIDGET(main_window)->window, cursor);

    //g_timeout_add(100, timeout_ask_for_data, NULL);
    g_timeout_add(1000, check_table, NULL);
    g_timeout_add(100, show_camera_video, NULL);
    //g_idle_add(show_camera_video, NULL);

    /* All GTK applications must have a gtk_main(). Control ends here
     * and waits for an event to occur (like a key press or
     * mouse event). */
    gtk_main();

    for (i = 0; i < NUM_CONNECTIONS; i++)
	run[i] = -1;
    run_flag = FALSE;     /* flag threads to stop and exit */
    //g_thread_join(gth);   /* wait for thread to exit */

    return 0;
}