/* must be called once device information is available via source properties */ void rb_media_player_source_load (RBMediaPlayerSource *source) { RBMediaPlayerSourcePrivate *priv = MEDIA_PLAYER_SOURCE_GET_PRIVATE (source); char *device_id; char *sync_filename; char *sync_path; char *sync_dir; /* make sure the sync settings dir exists */ sync_dir = g_build_filename (rb_user_data_dir (), "sync", NULL); g_mkdir (sync_dir, 0700); /* construct path to sync settings file */ g_object_get (source, "serial", &device_id, NULL); if (device_id == NULL) { g_object_get (source, "name", &device_id, NULL); } sync_filename = g_strdup_printf ("device-%s.conf", device_id); sync_path = g_build_filename (sync_dir, sync_filename, NULL); g_free (sync_filename); g_free (device_id); g_free (sync_dir); priv->sync_settings = rb_sync_settings_new (sync_path); g_free (sync_path); }
GList * rb_get_plugin_paths (void) { GList *paths; char *path; paths = NULL; if (!eel_gconf_get_boolean (CONF_PLUGIN_DISABLE_USER)) { /* deprecated path, should be removed some time in the future */ path = g_build_filename (rb_dot_dir (), "plugins", NULL); paths = g_list_prepend (paths, path); path = g_build_filename (rb_user_data_dir (), "plugins", NULL); paths = g_list_prepend (paths, path); } #ifdef USE_UNINSTALLED_DIRS path = g_build_filename (UNINSTALLED_PLUGINS_LOCATION, NULL); paths = g_list_prepend (paths, path); path = g_build_filename ("..", UNINSTALLED_PLUGINS_LOCATION, NULL); paths = g_list_prepend (paths, path); #endif path = g_strdup (RB_PLUGIN_DIR); paths = g_list_prepend (paths, path); paths = g_list_reverse (paths); return paths; }
/** * rb_stock_icons_init: * * Initializes the stock icons, adding the necessary filesystem * locations to the GTK icon search path. Must be called on startup. */ void rb_stock_icons_init (void) { GtkIconTheme *theme = gtk_icon_theme_get_default (); int i; int icon_size; char *dot_icon_dir; /* add our icon search paths */ dot_icon_dir = g_build_filename (rb_user_data_dir (), "icons", NULL); gtk_icon_theme_append_search_path (theme, dot_icon_dir); g_free (dot_icon_dir); gtk_icon_theme_append_search_path (theme, SHARE_DIR G_DIR_SEPARATOR_S "icons"); #ifdef USE_UNINSTALLED_DIRS gtk_icon_theme_append_search_path (theme, SHARE_UNINSTALLED_DIR G_DIR_SEPARATOR_S "icons"); #endif /* add inline icons */ gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &icon_size, NULL); for (i = 0; i < (int) G_N_ELEMENTS (inline_icons); i++) { GdkPixbuf *pixbuf; pixbuf = gdk_pixbuf_new_from_inline (-1, inline_icons[i].data, FALSE, NULL); g_assert (pixbuf); gtk_icon_theme_add_builtin_icon (inline_icons[i].name, icon_size, pixbuf); } }
int main (int argc, char **argv) { RhythmDB *db; char *name; int i; if (argc < 2) { name = g_build_filename (rb_user_data_dir(), "rhythmdb.xml", NULL); g_print ("using %s\n", name); } else { name = g_strdup (argv[1]); } rb_profile_start ("load test"); g_thread_init (NULL); rb_threads_init (); gtk_set_locale (); gtk_init (&argc, &argv); rb_debug_init (FALSE); rb_refstring_system_init (); rb_file_helpers_init (TRUE); GDK_THREADS_ENTER (); db = rhythmdb_tree_new ("test"); g_object_set (G_OBJECT (db), "name", name, NULL); g_free (name); for (i = 1; i <= 10; i++) { int j; rb_profile_start ("10 rhythmdb loads"); for (j = 1; j <= 10; j++) { set_waiting_signal (G_OBJECT (db), "load-complete"); rhythmdb_load (db); wait_for_signal (); rhythmdb_entry_delete_by_type (db, RHYTHMDB_ENTRY_TYPE_SONG); rhythmdb_entry_delete_by_type (db, rhythmdb_entry_type_get_by_name (db, "iradio")); rhythmdb_entry_delete_by_type (db, RHYTHMDB_ENTRY_TYPE_PODCAST_FEED); rhythmdb_entry_delete_by_type (db, RHYTHMDB_ENTRY_TYPE_PODCAST_POST); } rb_profile_end ("10 rhythmdb loads"); g_print ("completed %d loads\n", i * 10); } rhythmdb_shutdown (db); g_object_unref (G_OBJECT (db)); db = NULL; rb_file_helpers_shutdown (); rb_refstring_system_shutdown (); rb_profile_end ("load test"); return 0; }
static void save_session_settings (RBAudioscrobblerAccount *account) { /* Save the current session */ const char *rb_data_dir; char *file_path; GKeyFile *key_file; char *service_name; char *data; gsize data_length; GFile *out_file; GError *error; rb_data_dir = rb_user_data_dir (); if (rb_data_dir == NULL) { rb_debug ("error saving session: could not find data dir"); return; } file_path = g_build_filename (rb_data_dir, "audioscrobbler", SESSION_SETTINGS_FILE, NULL); key_file = g_key_file_new (); /* load existing file contents. errors wont matter, just means file doesn't exist yet */ g_key_file_load_from_file (key_file, file_path, G_KEY_FILE_KEEP_COMMENTS, NULL); /* get the service name */ g_object_get (account->priv->service, "name", &service_name, NULL); /* set the new data */ if (account->priv->username != NULL && account->priv->session_key != NULL) { g_key_file_set_string (key_file, service_name, "username", account->priv->username); g_key_file_set_string (key_file, service_name, "session_key", account->priv->session_key); } else { g_key_file_remove_group (key_file, service_name, NULL); } g_free (service_name); data = g_key_file_to_data (key_file, &data_length, NULL); g_key_file_free (key_file); /* write data to the file */ out_file = g_file_new_for_path (file_path); g_free (file_path); error = NULL; g_file_replace_contents (out_file, data, data_length, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, &error); if (error != NULL) { rb_debug ("error saving session: %s", error->message); g_error_free (error); } else { rb_debug ("successfully saved session"); } g_free (data); g_object_unref (out_file); }
static void load_session_settings (RBAudioscrobblerAccount *account) { /* Attempt to load the saved session */ const char *rb_data_dir; char *file_path; GKeyFile *key_file; char *service_name; rb_data_dir = rb_user_data_dir (); if (rb_data_dir == NULL) { rb_debug ("error loading session: could not find data dir"); return; } file_path = g_build_filename (rb_data_dir, "audioscrobbler", SESSION_SETTINGS_FILE, NULL); key_file = g_key_file_new (); g_key_file_load_from_file (key_file, file_path, G_KEY_FILE_NONE, NULL); /* get the service name */ g_object_get (account->priv->service, "name", &service_name, NULL); account->priv->username = g_key_file_get_string (key_file, service_name, "username", NULL); account->priv->session_key = g_key_file_get_string (key_file, service_name, "session_key", NULL); g_free (file_path); g_key_file_free (key_file); g_free (service_name); if (account->priv->username != NULL && account->priv->session_key != NULL) { rb_debug ("loaded session: username=\"%s\", session key=\"%s\"", account->priv->username, account->priv->session_key); account->priv->login_status = RB_AUDIOSCROBBLER_ACCOUNT_LOGIN_STATUS_LOGGED_IN; g_signal_emit (account, rb_audioscrobbler_account_signals[LOGIN_STATUS_CHANGED], 0, account->priv->login_status); } else { rb_debug ("there is no session to load"); /* free both incase only one of them did not load */ g_free (account->priv->username); account->priv->username = NULL; g_free (account->priv->session_key); account->priv->session_key = NULL; account->priv->login_status = RB_AUDIOSCROBBLER_ACCOUNT_LOGIN_STATUS_LOGGED_OUT; g_signal_emit (account, rb_audioscrobbler_account_signals[LOGIN_STATUS_CHANGED], 0, account->priv->login_status); } }
/** * rb_find_user_data_file: * @name: name of file to find * @error: returns error information * * Determines the full path to use for user-specific files, such as rhythmdb.xml. * This first checks in the user data directory (see @rb_user_data_dir). * If the file does not exist in the user data directory, it then checks the * old .gnome2 directory, moving the file to the user data directory if found there. * If an error occurs while moving the file, this will be reported through @error * and the .gnome2 path will be returned. * * Returns: allocated string containing the location of the file to use, even if * an error occurred. */ char * rb_find_user_data_file (const char *name, GError **error) { return rb_find_user_file (rb_user_data_dir (), name, error); }