Beispiel #1
0
int main(int argc, char **argv)
{
	ClutterActor *stage;
	ClutterColor stage_clr = { 0x00, 0x00, 0x00, 0xff };
	const gchar *stage_title = { "potassium music player" };
	struct sigaction action;

	g_set_application_name("potassium music player");

	clutter_init(&argc, &argv);
	
	stage = clutter_stage_get_default();
	clutter_actor_set_size(stage, 512, 128);
	clutter_stage_set_color(CLUTTER_STAGE(stage), &stage_clr);
	clutter_stage_set_title(CLUTTER_STAGE(stage), stage_title);
	clutter_actor_set_name(stage, "stage");
	clutter_actor_show(stage);

	/* Setup signal handler for USR1 to dump player state */
	memset(&action, 0, sizeof(&action));
	sigemptyset(&action.sa_mask);
	action.sa_handler = dump_data;
	action.sa_flags = SA_RESTART;
	sigaction(SIGUSR1, &action, NULL);

	/* Handle keyboard/mouse events */
	g_signal_connect(stage, "event", G_CALLBACK(input_events_cb), NULL);

	mozart_init(argc, argv);
	
	if (argc == 2) {
		/*
		 * strdup() argv[1] here, as it seems to get mangled by
		 * generate_playlist()
		 */
		generate_playlist(strdup(argv[1]), strdup(argv[1]));
		mozart_switch_playlist(argv[1]);
	} else {
		read_checkpoint_data();
	}

	init_icons(stage);

	g_timeout_add(500, (GSourceFunc)update_display, stage);
	g_timeout_add_seconds(1, (GSourceFunc)write_checkpoint_data, NULL);
	g_signal_connect(mozart_bus, "message::state-changed",
					G_CALLBACK(set_status_icons), stage);
	
	clutter_main();

	mozart_destroy();
	exit(0);
}
Beispiel #2
0
gboolean
init_ui (gint   *argc,
         gchar **argv[])
{
        GtkWidget *about_dialog;
        GdkPixbuf *icon_pixbuf;
        GtkWidget *hpaned;
        GtkWidget *vpaned;
        gint       window_width, window_height;
        gint       position;
        GError    *error = NULL;
        double     w,h;

        gtk_init (argc, argv);

        builder = gtk_builder_new ();
        g_assert (builder != NULL);
        gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);

        if (!gtk_builder_add_from_file (builder, UI_FILE, &error)) {
                g_critical ("Unable to load the GUI file %s: %s",
                            UI_FILE,
                            error->message);

                g_error_free (error);
                return FALSE;
        }

        main_window = GTK_WIDGET (gtk_builder_get_object (builder,
                                                          "main-window"));
        about_dialog = GTK_WIDGET (gtk_builder_get_object (builder,
                                                           "about-dialog"));
        hpaned = GTK_WIDGET (gtk_builder_get_object (builder,
                                                     "main-window-hpaned"));
        vpaned = GTK_WIDGET (gtk_builder_get_object (builder,
                                                     "main-window-vpaned"));

        g_assert (main_window != NULL);
        g_assert (about_dialog != NULL);
        g_assert (hpaned != NULL);
        g_assert (vpaned != NULL);

        /* 80% of the screen but don't get bigger than 1000x800 */
        /* FIXME: Replace with proper functions */
        G_GNUC_BEGIN_IGNORE_DEPRECATIONS
        w = gdk_screen_width () * 0.8;
        h = gdk_screen_height () * 0.8;
        G_GNUC_END_IGNORE_DEPRECATIONS

        /* Keep 5/4 aspect */
        if (w/h > 1.25) {
                h = w / 1.25;
        } else {
                w = h * 1.25;
        }

        window_width = CLAMP ((int) w, 10, 1000);
        window_height = CLAMP ((int) h, 10, 800);

        gtk_window_set_default_size (GTK_WINDOW (main_window),
                                     window_width,
                                     window_height);

        gtk_window_resize (GTK_WINDOW (main_window),
                                     window_width,
                                     window_height);


        icon_pixbuf = load_pixbuf_file (ICON_FILE);
        if (icon_pixbuf == NULL) {
                return FALSE;
        }

        gtk_window_set_icon (GTK_WINDOW (main_window), icon_pixbuf);
        gtk_window_set_icon (GTK_WINDOW (about_dialog), icon_pixbuf);
        gtk_about_dialog_set_logo (GTK_ABOUT_DIALOG (about_dialog),
                                   icon_pixbuf);
        gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (about_dialog),
                                      VERSION);

        g_object_unref (icon_pixbuf);

        gtk_builder_connect_signals (builder, NULL);

        init_icons ();
        setup_treeviews ();
        init_action_dialog (builder);

        gtk_widget_show_all (main_window);

        /* Give device treeview 40% of the main window */
        g_object_get (hpaned, "max-position", &position, NULL);
        position = position * 40 / 100;
        g_object_set (hpaned, "position", position, NULL);

        /* Give details treeview 60% of 60% of the main window */
        g_object_get (vpaned, "max-position", &position, NULL);
        position = position * 60 / 100;
        g_object_set (vpaned, "position", position, NULL);

        return TRUE;
}