/** * rb_builder_load: * @file: filename, either absolute or relative to the data directory * @user_data: user data to pass to autoconnected signal handlers * * Locates and reads a GtkBuilder file, automatically connecting * signal handlers where possible. The caller can specify a path * relative to the shared data directory, or its 'ui' or 'art' * subdirectories. * * Return value: #GtkBuilder object built from the file */ GtkBuilder * rb_builder_load (const char *file, gpointer user_data) { GtkBuilder *builder; const char *name; GError *error = NULL; g_return_val_if_fail (file != NULL, NULL); /* if the first character is /, it's an absolute path, otherwise locate it */ if (file[0] == G_DIR_SEPARATOR) name = file; else name = rb_file (file); builder = gtk_builder_new (); gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE); if (gtk_builder_add_from_file (builder, name, &error) == 0) { g_warning ("Error loading GtkBuilder file %s: %s", name, error->message); g_error_free (error); } gtk_builder_connect_signals (builder, user_data); return builder; }
int main (int argc, char **argv) { GtkWidget *main_window; GtkTreeModel *main_model; GtkTreeIter iter; RBEntryView *view; RhythmDB *db; RhythmDBEntry *entry; gtk_init (&argc, &argv); gdk_threads_init (); rb_thread_helpers_init (); rb_file_helpers_init (TRUE); rb_stock_icons_init (); rb_debug_init (TRUE); GDK_THREADS_ENTER (); db = rhythmdb_tree_new ("test"); rhythmdb_write_lock (db); entry = create_entry (db, "file:///sin.mp3", "Sin", "Pretty Hate Machine", "Nine Inch Nails", "Rock"); rhythmdb_write_unlock (db); rhythmdb_read_lock (db); main_model = GTK_TREE_MODEL (rhythmdb_query_model_new_empty (db)); rhythmdb_do_full_query (db, main_model, RHYTHMDB_QUERY_PROP_EQUALS, RHYTHMDB_PROP_TYPE, RHYTHMDB_ENTRY_TYPE_IGNORE, RHYTHMDB_QUERY_END); wait_for_model_completion (RHYTHMDB_QUERY_MODEL (main_model)); g_assert (gtk_tree_model_get_iter_first (main_model, &iter)); main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); view = rb_entry_view_new (db, rb_file ("rb-entry-view-library.xml")); rb_entry_view_set_query_model (view, RHYTHMDB_QUERY_MODEL (main_model)); gtk_container_add (GTK_CONTAINER (main_window), GTK_WIDGET (view)); g_signal_connect (G_OBJECT (main_window), "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_show_all (GTK_WIDGET (main_window)); gtk_main (); rhythmdb_shutdown (db); g_object_unref (G_OBJECT (db)); GDK_THREADS_LEAVE (); exit (0); }
static char * get_encoding_target_file () { char *target_file; target_file = rb_find_user_data_file (ENCODING_TARGET_FILE); if (g_file_test (target_file, G_FILE_TEST_EXISTS) == FALSE) { g_free (target_file); target_file = g_strdup (rb_file (ENCODING_TARGET_FILE)); } return target_file; }
static VALUE exportr_read ( void ) { VALUE data; VALUE config = exportr_config_file(); VALUE hash = Qnil; if ( TYPE(config) != T_NIL ) { data = rb_funcall(rb_file(), rb_intern("read"), 1, config); hash = rb_funcall(rb_yaml(), rb_intern("load"), 1, data); return hash; } return Qnil; }
char * rb_plugin_find_file (RBPlugin *plugin, const char *file) { RBPluginPrivate *priv = RB_PLUGIN_GET_PRIVATE (plugin); GList *paths; GList *l; char *ret = NULL; paths = rb_get_plugin_paths (); for (l = paths; l != NULL; l = l->next) { if (ret == NULL && priv->name) { char *tmp; tmp = g_build_filename (l->data, priv->name, file, NULL); if (g_file_test (tmp, G_FILE_TEST_EXISTS)) { ret = tmp; break; } g_free (tmp); } } g_list_foreach (paths, (GFunc)g_free, NULL); g_list_free (paths); /* global data files */ if (ret == NULL) { const char *f; f = rb_file (file); if (f) ret = g_strdup (f); } rb_debug ("found '%s' when searching for file '%s' for plugin '%s'", ret, file, priv->name); /* ensure it's an absolute path, so doesn't confuse rb_builder_load et al */ if (ret != NULL && ret[0] != '/') { char *pwd = g_get_current_dir (); char *path = g_strconcat (pwd, G_DIR_SEPARATOR_S, ret, NULL); g_free (ret); g_free (pwd); ret = path; } return ret; }
static VALUE exportr_config_file ( void ) { VALUE filepath, frag; VALUE exists = Qfalse; int i; for ( i=0; 1; i++ ) { if ( d_scan[i] == 0 ) break; frag = rb_str_new2(d_scan[i]); if ( strlen(d_scan[i]) > 0 ) rb_str_cat2(frag, "/"); rb_str_cat2(frag, FILE); filepath = rb_funcall(rb_file(), rb_intern("expand_path"), 1, frag); exists = rb_funcall(rb_file(), rb_intern("exists?"), 1, filepath); if ( TYPE(exists) == T_TRUE ) break; filepath = Qnil; } return filepath; }
/** * rb_find_plugin_data_file: * @plugin: the plugin object * @name: name of the file to find * * Locates a file under the plugin's data directory. * * Returns: allocated string containing the location of the file */ char * rb_find_plugin_data_file (GObject *object, const char *name) { PeasPluginInfo *info; char *ret = NULL; const char *plugin_name = "<unknown>"; g_object_get (object, "plugin-info", &info, NULL); if (info != NULL) { char *tmp; tmp = g_build_filename (peas_plugin_info_get_data_dir (info), name, NULL); if (g_file_test (tmp, G_FILE_TEST_EXISTS)) { ret = tmp; } else { g_free (tmp); } plugin_name = peas_plugin_info_get_name (info); } if (ret == NULL) { const char *f; f = rb_file (name); if (f != NULL) { ret = g_strdup (f); } } rb_debug ("found '%s' when searching for file '%s' for plugin '%s'", ret, name, plugin_name); /* ensure it's an absolute path */ if (ret != NULL && ret[0] != '/') { char *pwd = g_get_current_dir (); char *path = g_strconcat (pwd, G_DIR_SEPARATOR_S, ret, NULL); g_free (ret); g_free (pwd); ret = path; } return ret; }
/** * rb_glade_xml_new: * @file: filename, either absolute or relative to the data directory * @root: the widget node in the file to start building from (or NULL) * @user_data: user data to pass to autoconnected signal handlers * * Locates and reads a glade xml file, automatically connecting * signal handlers where possible. The caller can specify a path * relative to the shared data directory, or its 'glade' or 'art' * subdirectories. * * Return value: #GladeXML object built from the file */ GladeXML * rb_glade_xml_new (const char *file, const char *root, gpointer user_data) { GladeXML *xml; const char *name; g_return_val_if_fail (file != NULL, NULL); /* if the first character is /, it's an absolute path, otherwise locate it */ if (file[0] == G_DIR_SEPARATOR) name = file; else name = rb_file (file); xml = glade_xml_new (name, root, NULL); glade_xml_signal_autoconnect_full (xml, (GladeXMLConnectFunc) glade_signal_connect_func, user_data); return xml; }
static void display_sync_settings_dialog (RBMediaPlayerSource *source) { RBMediaPlayerSourcePrivate *priv = MEDIA_PLAYER_SOURCE_GET_PRIVATE (source); GtkWidget *content; GtkWidget *widget; GtkBuilder *builder; const char *ui_file; char *name; char *title; g_object_get (source, "name", &name, NULL); title = g_strdup_printf (_("%s Sync Settings"), name); priv->sync_dialog = gtk_dialog_new_with_buttons (title, NULL, 0, _("Sync with the device"), GTK_RESPONSE_YES, _("Don't sync"), GTK_RESPONSE_CANCEL, NULL); g_free (title); priv->sync_dialog_update_id = g_signal_connect_object (priv->sync_state, "updated", G_CALLBACK (sync_dialog_state_update), source, 0); g_signal_connect_object (priv->sync_dialog, "response", G_CALLBACK (sync_confirm_dialog_cb), source, 0); /* display the sync settings, the sync state, and some helpful text indicating why * we're not syncing already */ content = gtk_dialog_get_content_area (GTK_DIALOG (priv->sync_dialog)); ui_file = rb_file ("sync-dialog.ui"); if (ui_file == NULL) { g_warning ("Couldn't find sync-state.ui"); gtk_widget_show_all (priv->sync_dialog); return; } builder = rb_builder_load (ui_file, NULL); if (builder == NULL) { g_warning ("Couldn't load sync-state.ui"); gtk_widget_show_all (priv->sync_dialog); return; } priv->sync_dialog_label = GTK_WIDGET (gtk_builder_get_object (builder, "sync-dialog-reason")); priv->sync_dialog_error_box = GTK_WIDGET (gtk_builder_get_object (builder, "sync-dialog-message")); widget = GTK_WIDGET (gtk_builder_get_object (builder, "sync-settings-ui-container")); gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (widget), rb_sync_settings_ui_new (source, priv->sync_settings)); widget = GTK_WIDGET (gtk_builder_get_object (builder, "sync-state-ui-container")); gtk_box_pack_start (GTK_BOX (widget), rb_sync_state_ui_new (priv->sync_state), TRUE, TRUE, 0); widget = GTK_WIDGET (gtk_builder_get_object (builder, "sync-dialog")); gtk_box_pack_start (GTK_BOX (content), widget, TRUE, TRUE, 0); gtk_widget_show_all (priv->sync_dialog); update_sync_settings_dialog (source); g_object_unref (builder); }
void rb_media_player_source_show_properties (RBMediaPlayerSource *source) { RBMediaPlayerSourcePrivate *priv = MEDIA_PLAYER_SOURCE_GET_PRIVATE (source); RBMediaPlayerSourceClass *klass = RB_MEDIA_PLAYER_SOURCE_GET_CLASS (source); GtkBuilder *builder; GtkContainer *container; const char *ui_file; char *name; char *text; if (priv->properties_dialog != NULL) { gtk_window_present (GTK_WINDOW (priv->properties_dialog)); return; } /* load dialog UI */ ui_file = rb_file ("media-player-properties.ui"); if (ui_file == NULL) { g_warning ("Couldn't find media-player-properties.ui"); return; } builder = rb_builder_load (ui_file, NULL); if (builder == NULL) { g_warning ("Couldn't load media-player-properties.ui"); return; } priv->properties_dialog = GTK_DIALOG (gtk_builder_get_object (builder, "media-player-properties")); g_object_ref (priv->properties_dialog); g_signal_connect_object (priv->properties_dialog, "response", G_CALLBACK (properties_dialog_response_cb), source, 0); g_object_get (source, "name", &name, NULL); text = g_strdup_printf (_("%s Properties"), name); gtk_window_set_title (GTK_WINDOW (priv->properties_dialog), text); g_free (text); g_free (name); /* ensure device usage information is available and up to date */ update_sync (source); /* * fill in some common details: * - volume usage (need to hook up signals etc. to update this live) */ rb_sync_state_ui_create_bar (&priv->volume_usage, rb_media_player_source_get_capacity (source), NULL); rb_sync_state_ui_update_volume_usage (&priv->volume_usage, priv->sync_state); gtk_widget_show_all (priv->volume_usage.widget); container = GTK_CONTAINER (gtk_builder_get_object (builder, "device-usage-container")); gtk_container_add (container, priv->volume_usage.widget); /* let the subclass fill in device type specific details (model names, device names, * .. battery levels?) and add more tabs to the notebook to display 'advanced' stuff. */ if (klass->show_properties) { klass->show_properties (source, GTK_WIDGET (gtk_builder_get_object (builder, "device-info-box")), GTK_WIDGET (gtk_builder_get_object (builder, "media-player-notebook"))); } /* create sync UI */ container = GTK_CONTAINER (gtk_builder_get_object (builder, "sync-settings-ui-container")); gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (container), rb_sync_settings_ui_new (source, priv->sync_settings)); container = GTK_CONTAINER (gtk_builder_get_object (builder, "sync-state-ui-container")); gtk_box_pack_start (GTK_BOX (container), rb_sync_state_ui_new (priv->sync_state), TRUE, TRUE, 0); gtk_widget_show_all (GTK_WIDGET (container)); /* create encoding settings UI */ if (priv->encoding_settings) { container = GTK_CONTAINER (gtk_builder_get_object (builder, "encoding-settings-container")); gtk_container_add (container, rb_encoding_settings_new (priv->encoding_settings, priv->encoding_target, TRUE)); gtk_widget_show_all (GTK_WIDGET (container)); } else { container = GTK_CONTAINER (gtk_builder_get_object (builder, "encoding-settings-frame")); gtk_widget_hide (GTK_WIDGET (container)); gtk_widget_set_no_show_all (GTK_WIDGET (container), TRUE); } gtk_widget_show (GTK_WIDGET (priv->properties_dialog)); g_object_unref (builder); }