Beispiel #1
0
static void
pragha_application_shutdown (GApplication *application)
{
	PraghaApplication *pragha = PRAGHA_APPLICATION (application);

	CDEBUG(DBG_INFO, "Pragha shutdown: Saving curret state.");

	if (pragha_preferences_get_restore_playlist (pragha->preferences))
		pragha_playlist_save_playlist_state (pragha->playlist);

	pragha_window_save_settings (pragha);

	pragha_playback_stop (pragha);

	/* Shutdown plugins can hide sidebar before save settings. */
	if (pragha->sidebar2_binding) {
		g_object_unref (pragha->sidebar2_binding);
		pragha->sidebar2_binding = NULL;
	}

#ifdef HAVE_LIBPEAS
	pragha_plugins_engine_shutdown (pragha->plugins_engine);
#endif

	gtk_widget_destroy (pragha->mainwindow);

	G_APPLICATION_CLASS (pragha_application_parent_class)->shutdown (application);
}
Beispiel #2
0
static void
pragha_application_activate (GApplication *application)
{
	PraghaApplication *pragha = PRAGHA_APPLICATION (application);

	gtk_window_present (GTK_WINDOW (pragha->mainwindow));
}
Beispiel #3
0
static void
pragha_application_dispose (GObject *object)
{
	PraghaApplication *pragha = PRAGHA_APPLICATION (object);

	CDEBUG(DBG_INFO, "Cleaning up");

#ifdef HAVE_LIBPEAS
	if (pragha->plugins_engine) {
		g_object_unref (pragha->plugins_engine);
		pragha->plugins_engine = NULL;
	}
#endif
	if (pragha->setting_dialog) {
		pragha_preferences_dialog_free (pragha->setting_dialog);
		pragha->setting_dialog = NULL;
	}
	if (pragha->backend) {
		g_object_unref (pragha->backend);
		pragha->backend = NULL;
	}
	if (pragha->art_cache) {
		g_object_unref (pragha->art_cache);
		pragha->art_cache = NULL;
	}
	if (pragha->enum_map) {
		g_object_unref (pragha->enum_map);
		pragha->enum_map = NULL;
	}
	if (pragha->scanner) {
		pragha_scanner_free (pragha->scanner);
		pragha->scanner = NULL;
	}
	if (pragha->menu_ui_manager) {
		g_object_unref (pragha->menu_ui_manager);
		pragha->menu_ui_manager = NULL;
	}
	if (pragha->menu_ui) {
		g_object_unref (pragha->menu_ui);
		pragha->menu_ui = NULL;
	}

	/* Save Preferences and database. */

	if (pragha->preferences) {
		g_object_unref (pragha->preferences);
		pragha->preferences = NULL;
	}
	if (pragha->provider) {
		g_object_unref (pragha->provider);
		pragha->provider = NULL;
	}
	if (pragha->cdbase) {
		g_object_unref (pragha->cdbase);
		pragha->cdbase = NULL;
	}

	G_OBJECT_CLASS (pragha_application_parent_class)->dispose (object);
}
Beispiel #4
0
//it's used for --help and --version
static gboolean
pragha_application_local_command_line (GApplication *application, gchar ***arguments, int *exit_status)
{
	PraghaApplication *pragha = PRAGHA_APPLICATION (application);

	gchar **argv = *arguments;
	gint argc = g_strv_length (argv);

	*exit_status = handle_command_line (pragha, NULL, argc, argv);

	return FALSE;
}
Beispiel #5
0
static void
pragha_application_open (GApplication *application, GFile **files, gint n_files, const gchar *hint)
{
	PraghaApplication *pragha = PRAGHA_APPLICATION (application);
	gint i;
	GList *mlist = NULL;

	for (i = 0; i < n_files; i++) {
		gchar *path = g_file_get_path (files[i]);
		mlist = append_mobj_list_from_unknown_filename (mlist, path);
		g_free (path);
	}

	if (mlist) {
		pragha_playlist_append_mobj_list (pragha->playlist, mlist);
		g_list_free (mlist);
	}

	gtk_window_present (GTK_WINDOW (pragha->mainwindow));
}
Beispiel #6
0
static int
pragha_application_command_line (GApplication *application, GApplicationCommandLine *command_line)
{
	PraghaApplication *pragha = PRAGHA_APPLICATION (application);
	int ret = 0;
	gint argc;

	gchar **argv = g_application_command_line_get_arguments (command_line, &argc);

	if (argc <= 1) {
		pragha_application_activate (application);
		goto exit;
	}

	ret = handle_command_line (pragha, command_line, argc, argv);

exit:
	g_strfreev (argv);

	return ret;
}
Beispiel #7
0
static void
pragha_application_startup (GApplication *application)
{
	PraghaToolbar *toolbar;
	PraghaPlaylist *playlist;
	const gchar *version = NULL;
	const gchar *desktop = NULL;
	gint playlist_id = 0;

	const GBindingFlags binding_flags =
		G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL;

	PraghaApplication *pragha = PRAGHA_APPLICATION (application);

	G_APPLICATION_CLASS (pragha_application_parent_class)->startup (application);

	/* Allocate memory for simple structures */

	pragha->preferences = pragha_preferences_get();

	pragha->cdbase = pragha_database_get();
	if (pragha_database_start_successfully(pragha->cdbase) == FALSE) {
		g_error("Unable to init music dbase");
	}

	version = pragha_preferences_get_installed_version (pragha->preferences);
	if (string_is_not_empty (version) && (g_ascii_strcasecmp (version, "1.3.90") < 0)) {
		pragha_database_compatibilize_version (pragha->cdbase);
	}
	playlist_id = pragha_database_find_playlist (pragha->cdbase, _("Favorites"));
	if (playlist_id == 0)
		pragha_database_add_new_playlist (pragha->cdbase, _("Favorites"));

	pragha->provider = pragha_database_provider_get ();
	g_signal_connect (pragha->provider, "want-upgrade",
	                  G_CALLBACK(pragha_application_provider_want_upgrade), pragha);
	g_signal_connect (pragha->provider, "want-update",
	                  G_CALLBACK(pragha_application_provider_want_update), pragha);

	pragha->enum_map = pragha_music_enum_get ();
	g_signal_connect (pragha->enum_map, "enum-removed",
	                  G_CALLBACK(pragha_enum_map_removed_handler), pragha);

#ifdef HAVE_LIBPEAS
	pragha->plugins_engine = pragha_plugins_engine_new (G_OBJECT(pragha));
#endif

	pragha->art_cache = pragha_art_cache_get ();
	g_signal_connect (pragha->art_cache, "cache-changed",
	                  G_CALLBACK(pragha_art_cache_changed_handler), pragha);

	pragha->backend = pragha_backend_new ();

	g_signal_connect (pragha->backend, "finished",
	                  G_CALLBACK(pragha_backend_finished_song), pragha);
	g_signal_connect (pragha->backend, "tags-changed",
	                  G_CALLBACK(pragha_backend_tags_changed), pragha);

	g_signal_connect (pragha->backend, "error",
	                 G_CALLBACK(gui_backend_error_show_dialog_cb), pragha);
	g_signal_connect (pragha->backend, "error",
	                  G_CALLBACK(gui_backend_error_update_current_playlist_cb), pragha);
	g_signal_connect (pragha->backend, "notify::state",
	                  G_CALLBACK (pragha_menubar_update_playback_state_cb), pragha);

	/*
	 * Collect widgets and construct the window.
	 */

	pragha_application_construct_window (pragha);

	/* Connect Signals and Bindings. */

	toolbar = pragha->toolbar;
	g_signal_connect_swapped (toolbar, "prev",
	                          G_CALLBACK(pragha_playback_prev_track), pragha);
	g_signal_connect_swapped (toolbar, "play",
	                          G_CALLBACK(pragha_playback_play_pause_resume), pragha);
	g_signal_connect_swapped (toolbar, "stop",
	                          G_CALLBACK(pragha_playback_stop), pragha);
	g_signal_connect_swapped (toolbar, "next",
	                          G_CALLBACK(pragha_playback_next_track), pragha);
	g_signal_connect (toolbar, "unfull-activated",
	                  G_CALLBACK(pragha_window_unfullscreen), pragha);
	g_signal_connect (toolbar, "album-art-activated",
	                  G_CALLBACK(pragha_playback_show_current_album_art), pragha);
	g_signal_connect_swapped (toolbar, "track-info-activated",
	                          G_CALLBACK(pragha_playback_edit_current_track), pragha);
	g_signal_connect (toolbar, "track-progress-activated",
	                  G_CALLBACK(pragha_playback_seek_fraction), pragha);
	g_signal_connect (toolbar, "favorite-toggle",
	                  G_CALLBACK(pragha_playback_toogle_favorite), pragha);

	playlist = pragha->playlist;
	g_signal_connect (playlist, "playlist-set-track",
	                  G_CALLBACK(pragha_playback_set_playlist_track), pragha);
	g_signal_connect (playlist, "playlist-change-tags",
	                  G_CALLBACK(pragha_playlist_update_change_tags), pragha);
	g_signal_connect (playlist, "playlist-changed",
	                  G_CALLBACK(pragha_playlist_update_statusbar_playtime), pragha);
	pragha_playlist_update_statusbar_playtime (playlist, pragha);

	g_signal_connect (pragha->library, "library-append-playlist",
	                  G_CALLBACK(pragha_library_pane_append_tracks), pragha);
	g_signal_connect (pragha->library, "library-replace-playlist",
	                  G_CALLBACK(pragha_library_pane_replace_tracks), pragha);
	g_signal_connect (pragha->library, "library-replace-playlist-and-play",
	                  G_CALLBACK(pragha_library_pane_replace_tracks_and_play), pragha);
	g_signal_connect (pragha->library, "library-addto-playlist-and-play",
	                  G_CALLBACK(pragha_library_pane_addto_playlist_and_play), pragha);
	                  
	g_signal_connect (G_OBJECT(pragha->mainwindow), "window-state-event",
	                  G_CALLBACK(pragha_toolbar_window_state_event), toolbar);
	g_signal_connect (G_OBJECT(toolbar), "notify::timer-remaining-mode",
	                  G_CALLBACK(pragha_toolbar_show_ramaning_time_cb), pragha->backend);

	g_signal_connect (pragha->backend, "notify::state",
	                  G_CALLBACK(pragha_toolbar_playback_state_cb), toolbar);
	g_signal_connect (pragha->backend, "tick",
	                 G_CALLBACK(pragha_toolbar_update_playback_progress), toolbar);
	g_signal_connect (pragha->backend, "buffering",
	                  G_CALLBACK(pragha_toolbar_update_buffering_cb), toolbar);

	g_signal_connect (pragha->backend, "notify::state",
	                  G_CALLBACK (update_current_playlist_view_playback_state_cb), pragha->playlist);

	g_object_bind_property (pragha->backend, "volume",
	                        toolbar, "volume",
	                        binding_flags);

	g_object_bind_property (pragha->preferences, "timer-remaining-mode",
	                        toolbar, "timer-remaining-mode",
	                        binding_flags);

	g_signal_connect (pragha->preferences, "LibraryChanged",
	                  G_CALLBACK (pragha_libary_list_changed_cb), pragha);
	g_signal_connect (pragha->preferences, "NeedRestart",
	                  G_CALLBACK (pragha_need_restart_cb), pragha);

	g_signal_connect (pragha->preferences, "notify::system-titlebar",
	                  G_CALLBACK (pragha_system_titlebar_changed_cb), pragha);

	pragha->sidebar2_binding =
		g_object_bind_property (pragha->preferences, "secondary-lateral-panel",
		                        pragha->sidebar2, "visible",
		                        binding_flags);

	pragha->setting_dialog = pragha_preferences_dialog_new (pragha->mainwindow);

	#ifdef HAVE_LIBPEAS
	gboolean sidebar2_visible = // FIXME: Hack to allow hide sidebar when init.
		pragha_preferences_get_secondary_lateral_panel(pragha->preferences);

	pragha_plugins_engine_startup (pragha->plugins_engine);

	pragha_preferences_set_secondary_lateral_panel(pragha->preferences,
	                                               sidebar2_visible);
	#endif

	/* If first run and the desktop is gnome adapts style. */

	if (pragha_application_is_first_run (pragha)) {
		desktop = g_getenv ("XDG_CURRENT_DESKTOP");
		if (desktop && (g_strcmp0(desktop, "GNOME") == 0) &&
			gdk_screen_is_composited (gdk_screen_get_default())) {
			pragha_preferences_set_system_titlebar (pragha->preferences, FALSE);
			pragha_preferences_set_toolbar_size (pragha->preferences, GTK_ICON_SIZE_SMALL_TOOLBAR);
			pragha_preferences_set_show_menubar (pragha->preferences, FALSE);
		}
	}

	/* Forse update menubar and toolbar playback actions */

	pragha_menubar_update_playback_state_cb (pragha->backend, NULL, pragha);
	pragha_toolbar_playback_state_cb (pragha->backend, NULL, pragha->toolbar);

	/* Finally fill the library and the playlist */

	pragha_init_gui_state (pragha);
}
Beispiel #8
0
static void
pragha_application_startup (GApplication *application)
{
	PraghaApplication *pragha = PRAGHA_APPLICATION (application);

	PraghaToolbar *toolbar;
	PraghaPlaylist *playlist;

	const GBindingFlags binding_flags =
		G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL;

	G_APPLICATION_CLASS (pragha_application_parent_class)->startup (application);

	/* Allocate memory for simple structures */

	pragha->preferences = pragha_preferences_get();

	pragha->cdbase = pragha_database_get();
	if (pragha_database_start_successfully(pragha->cdbase) == FALSE) {
		g_error("Unable to init music dbase");
	}

	pragha->enum_map = pragha_music_enum_get ();
	g_signal_connect (pragha->enum_map, "enum-removed",
	                  G_CALLBACK(pragha_enum_map_removed_handler), pragha);

#ifdef HAVE_LIBPEAS
	pragha->peas_engine = peas_engine_get_default ();

	peas_engine_add_search_path (pragha->peas_engine, LIBPLUGINDIR, USRPLUGINDIR);
	pragha->peas_exten_set = peas_extension_set_new (pragha->peas_engine,
	                                                 PEAS_TYPE_ACTIVATABLE,
	                                                 "object", pragha,
	                                                 NULL);

	peas_extension_set_foreach (pragha->peas_exten_set,
	                            (PeasExtensionSetForeachFunc) on_extension_added,
	                            NULL);

	g_signal_connect (pragha->peas_exten_set, "extension-added",
	                  G_CALLBACK (on_extension_added), NULL);
	g_signal_connect (pragha->peas_exten_set, "extension-removed",
	                  G_CALLBACK (on_extension_removed), NULL);
#endif

	pragha->art_cache = pragha_art_cache_get ();
	g_signal_connect (pragha->art_cache, "cache-changed",
	                  G_CALLBACK(pragha_art_cache_changed_handler), pragha);

	pragha->backend = pragha_backend_new ();

	g_signal_connect (pragha->backend, "finished",
	                  G_CALLBACK(pragha_backend_finished_song), pragha);
	g_signal_connect (pragha->backend, "tags-changed",
	                  G_CALLBACK(pragha_backend_tags_changed), pragha);

	g_signal_connect (pragha->backend, "error",
	                 G_CALLBACK(gui_backend_error_show_dialog_cb), pragha);
	g_signal_connect (pragha->backend, "error",
	                  G_CALLBACK(gui_backend_error_update_current_playlist_cb), pragha);
	g_signal_connect (pragha->backend, "notify::state",
	                  G_CALLBACK (pragha_menubar_update_playback_state_cb), pragha);

	/*
	 * Collect widgets and construct the window.
	 */

	pragha_application_construct_window (pragha);

	/* Connect Signals and Bindings. */

	toolbar = pragha->toolbar;
	g_signal_connect_swapped (toolbar, "prev",
	                          G_CALLBACK(pragha_playback_prev_track), pragha);
	g_signal_connect_swapped (toolbar, "play",
	                          G_CALLBACK(pragha_playback_play_pause_resume), pragha);
	g_signal_connect_swapped (toolbar, "stop",
	                          G_CALLBACK(pragha_playback_stop), pragha);
	g_signal_connect_swapped (toolbar, "next",
	                          G_CALLBACK(pragha_playback_next_track), pragha);
	g_signal_connect (toolbar, "unfull-activated",
	                  G_CALLBACK(pragha_window_unfullscreen), pragha);
	g_signal_connect (toolbar, "album-art-activated",
	                  G_CALLBACK(pragha_playback_show_current_album_art), pragha);
	g_signal_connect (toolbar, "track-info-activated",
	                  G_CALLBACK(pragha_playback_edit_current_track), pragha);
	g_signal_connect (toolbar, "track-progress-activated",
	                  G_CALLBACK(pragha_playback_seek_fraction), pragha);

	playlist = pragha->playlist;
	g_signal_connect (playlist, "playlist-set-track",
	                  G_CALLBACK(pragha_playback_set_playlist_track), pragha);
	g_signal_connect (playlist, "playlist-change-tags",
	                  G_CALLBACK(pragha_playlist_update_change_tags), pragha);
	g_signal_connect (playlist, "playlist-changed",
	                  G_CALLBACK(pragha_playlist_update_statusbar_playtime), pragha);
	pragha_playlist_update_statusbar_playtime (playlist, pragha);
		
	g_signal_connect (pragha->library, "library-append-playlist",
	                  G_CALLBACK(pragha_library_pane_append_tracks), pragha);
	g_signal_connect (pragha->library, "library-replace-playlist",
	                  G_CALLBACK(pragha_library_pane_replace_tracks), pragha);
	g_signal_connect (pragha->library, "library-replace-playlist-and-play",
	                  G_CALLBACK(pragha_library_pane_replace_tracks_and_play), pragha);

	g_signal_connect (G_OBJECT(pragha->mainwindow), "window-state-event",
	                  G_CALLBACK(pragha_toolbar_window_state_event), toolbar);
	g_signal_connect (G_OBJECT(toolbar), "notify::timer-remaining-mode",
	                  G_CALLBACK(pragha_toolbar_show_ramaning_time_cb), pragha->backend);

	g_signal_connect (pragha->backend, "notify::state",
	                  G_CALLBACK(pragha_toolbar_playback_state_cb), toolbar);
	g_signal_connect (pragha->backend, "tick",
	                 G_CALLBACK(pragha_toolbar_update_playback_progress), toolbar);
	g_signal_connect (pragha->backend, "buffering",
	                  G_CALLBACK(pragha_toolbar_update_buffering_cb), toolbar);

	g_signal_connect (pragha->backend, "notify::state",
	                  G_CALLBACK (update_current_playlist_view_playback_state_cb), pragha->playlist);

	g_object_bind_property (pragha->backend, "volume",
	                        toolbar, "volume",
	                        binding_flags);

	g_object_bind_property (pragha->preferences, "timer-remaining-mode",
	                        toolbar, "timer-remaining-mode",
	                        binding_flags);

	pragha->sidebar2_binding =
		g_object_bind_property (pragha->preferences, "secondary-lateral-panel",
		                        pragha->sidebar2, "visible",
		                        binding_flags);
	
	pragha->setting_dialog = pragha_preferences_dialog_new (pragha);

	#ifdef HAVE_LIBPEAS
	pragha_plugins_activate_saved (pragha);
	#endif

	/* Finally fill the library and the playlist */

	pragha_init_gui_state (pragha);
}
Beispiel #9
0
static void
pragha_application_dispose (GObject *object)
{
	PraghaApplication *pragha = PRAGHA_APPLICATION (object);

	CDEBUG(DBG_INFO, "Cleaning up");

	if (pragha->sidebar2_binding) {
		g_object_unref (pragha->sidebar2_binding);
		pragha->sidebar2_binding = NULL;
	}
#ifdef HAVE_LIBPEAS
	if (pragha->peas_engine) {
		pragha_plugins_save_activated (pragha);

		peas_engine_garbage_collect (pragha->peas_engine);

		g_object_unref (pragha->peas_engine);
		pragha->peas_engine = NULL;
	}
	if (pragha->peas_exten_set) {
		g_object_unref (pragha->peas_exten_set);
		pragha->peas_exten_set = NULL;
	}
#endif
	if (pragha->setting_dialog) {
		pragha_preferences_dialog_free (pragha->setting_dialog);
		pragha->setting_dialog = NULL;
	}
	if (pragha->backend) {
		pragha_playback_stop (pragha);
		g_object_unref (pragha->backend);
		pragha->backend = NULL;
	}
	if (pragha->art_cache) {
		g_object_unref (pragha->art_cache);
		pragha->art_cache = NULL;
	}
	if (pragha->enum_map) {
		g_object_unref (pragha->enum_map);
		pragha->enum_map = NULL;
	}
	if (pragha->mainwindow) {
		pragha_window_free (pragha);
		/* Explicit destroy mainwindow to finalize lifecycle of childrens */
		gtk_widget_destroy (pragha->mainwindow);
		pragha->mainwindow = NULL;
	}
	if (pragha->scanner) {
		pragha_scanner_free (pragha->scanner);
		pragha->scanner = NULL;
	}

	if (pragha->pixbuf_app) {
		g_object_unref (pragha->pixbuf_app);
		pragha->pixbuf_app = NULL;
	}

	if (pragha->menu_ui_manager) {
		g_object_unref (pragha->menu_ui_manager);
		pragha->menu_ui_manager = NULL;
	}

	/* Save Preferences and database. */

	if (pragha->preferences) {
		g_object_unref (pragha->preferences);
		pragha->preferences = NULL;
	}
	if (pragha->cdbase) {
		g_object_unref (pragha->cdbase);
		pragha->cdbase = NULL;
	}

	G_OBJECT_CLASS (pragha_application_parent_class)->dispose (object);
}