Example #1
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;
}
Example #2
0
void
playback_properties_change (GtkAction * action, DenemoScriptParam* param)
{
    DenemoProject *gui = Denemo.project;
    GtkWidget *dialog;
    GtkWidget *label;
    GtkWidget *hbox;
    GtkWidget *main_vbox;
    GtkWidget *notebook;


    static struct callbackdata cbdata;

    dialog = gtk_dialog_new_with_buttons (_("Playback properties"), NULL, (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), _("_OK"), GTK_RESPONSE_ACCEPT, _("_Cancel"), GTK_RESPONSE_REJECT, NULL);

    //gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
    notebook = gtk_notebook_new ();
    GtkWidget *content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
    gtk_container_add (GTK_CONTAINER (content_area), notebook);

#define NEWPAGE(thelabel) \
  main_vbox = gtk_vbox_new (FALSE, 1);\
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), main_vbox, NULL);\
  gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (notebook), main_vbox,\
                                                           _(thelabel));

#define BOOLEANENTRY(thelabel, field) \
  GtkWidget *field =\
    gtk_check_button_new_with_label (thelabel); \
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (field),\
		            (gboolean)Denemo.prefs.field);\
  gtk_box_pack_start (GTK_BOX (main_vbox), field, FALSE, TRUE, 0);\
  cbdata.field = field;

#define TEXTENTRY(thelabel, field) \
  hbox = gtk_hbox_new (FALSE, 8);\
  gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, TRUE, 0);\
  label = gtk_label_new (_(thelabel));\
  gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);\
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);\
  GtkWidget *field = gtk_entry_new ();\
  gtk_entry_set_text (GTK_ENTRY (field), Denemo.prefs.field->str);\
  gtk_box_pack_start (GTK_BOX (hbox), field, TRUE, TRUE, 0);\
  cbdata.field = field;

#define INTENTRY_LIMITS(thelabel, field, min, max) \
  hbox = gtk_hbox_new (FALSE, 8);\
  gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, TRUE, 0);\
  label = gtk_label_new (thelabel);\
  gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);\
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);\
  GtkWidget *field = gtk_spin_button_new_with_range (min, max, 1.0);\
  gtk_spin_button_set_value (GTK_SPIN_BUTTON (field), gui->movement->field);\
  gtk_box_pack_start (GTK_BOX (hbox), field, FALSE, FALSE, 0);\
  cbdata.field = field;

    NEWPAGE ("Playback") INTENTRY_LIMITS ("Tempo", tempo, 10, 250);

    gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);

    gtk_widget_show_all (dialog);
    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
    {
        set_preferences (&cbdata);
    }
    gtk_widget_destroy (dialog);
}