gboolean ostree_builtin_trivial_httpd (int argc, char **argv, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; GOptionContext *context; const char *dirpath; OtTrivialHttpd appstruct = { 0, }; OtTrivialHttpd *app = &appstruct; glnx_unref_object SoupServer *server = NULL; g_autoptr(GFileMonitor) dirmon = NULL; context = g_option_context_new ("[DIR] - Simple webserver"); if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NO_REPO, NULL, cancellable, error)) goto out; if (argc > 1) dirpath = argv[1]; else dirpath = "."; app->root = g_file_new_for_path (dirpath); if (!(opt_random_500s_percentage >= 0 && opt_random_500s_percentage <= 99)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid --random-500s=%u", opt_random_500s_percentage); goto out; } if (opt_log) { GOutputStream *stream = NULL; if (g_strcmp0 (opt_log, "-") == 0) { if (opt_daemonize) { ot_util_usage_error (context, "Cannot use --log-file=- and --daemonize at the same time", error); goto out; } stream = G_OUTPUT_STREAM (g_unix_output_stream_new (STDOUT_FILENO, FALSE)); } else { g_autoptr(GFile) log_file; GFileOutputStream* log_stream; log_file = g_file_new_for_path (opt_log); log_stream = g_file_create (log_file, G_FILE_CREATE_PRIVATE, cancellable, error); if (!log_stream) goto out; stream = G_OUTPUT_STREAM (log_stream); } app->log = stream; } #if SOUP_CHECK_VERSION(2, 48, 0) server = soup_server_new (SOUP_SERVER_SERVER_HEADER, "ostree-httpd ", NULL); if (!soup_server_listen_all (server, opt_port, 0, error)) goto out; #else server = soup_server_new (SOUP_SERVER_PORT, opt_port, SOUP_SERVER_SERVER_HEADER, "ostree-httpd ", NULL); #endif soup_server_add_handler (server, NULL, httpd_callback, app, NULL); if (opt_port_file) { g_autofree char *portstr = NULL; #if SOUP_CHECK_VERSION(2, 48, 0) GSList *listeners = soup_server_get_listeners (server); g_autoptr(GSocket) listener = NULL; g_autoptr(GSocketAddress) addr = NULL; g_assert (listeners); listener = g_object_ref (listeners->data); g_slist_free (listeners); listeners = NULL; addr = g_socket_get_local_address (listener, error); if (!addr) goto out; g_assert (G_IS_INET_SOCKET_ADDRESS (addr)); portstr = g_strdup_printf ("%u\n", g_inet_socket_address_get_port ((GInetSocketAddress*)addr)); #else portstr = g_strdup_printf ("%u\n", soup_server_get_port (server)); #endif if (g_strcmp0 ("-", opt_port_file) == 0) { fputs (portstr, stdout); // not g_print - this must go to stdout, not a handler fflush (stdout); } else if (!g_file_set_contents (opt_port_file, portstr, strlen (portstr), error)) goto out; } #if !SOUP_CHECK_VERSION(2, 48, 0) soup_server_run_async (server); #endif if (opt_daemonize) { pid_t pid = fork(); if (pid == -1) { int errsv = errno; g_set_error_literal (error, G_IO_ERROR, g_io_error_from_errno (errsv), g_strerror (errsv)); goto out; } else if (pid > 0) { /* Parent */ _exit (0); } /* Child, continue */ /* Daemonising: close stdout/stderr so $() et al work on us */ fclose (stdout); fclose (stdin); } else { /* Since we're used for testing purposes, let's just do this by * default. This ensures we exit when our parent does. */ if (prctl (PR_SET_PDEATHSIG, SIGTERM) != 0) { if (errno != ENOSYS) { glnx_set_error_from_errno (error); goto out; } } } app->running = TRUE; if (opt_autoexit) { gboolean is_symlink = FALSE; g_autoptr(GFileInfo) info = NULL; info = g_file_query_info (app->root, G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!info) goto out; is_symlink = g_file_info_get_is_symlink (info); if (is_symlink) dirmon = g_file_monitor_file (app->root, 0, cancellable, error); else dirmon = g_file_monitor_directory (app->root, 0, cancellable, error); if (!dirmon) goto out; g_signal_connect (dirmon, "changed", G_CALLBACK (on_dir_changed), app); } { g_autofree gchar *path = g_file_get_path (app->root); httpd_log (app, "serving at root %s\n", path); } while (app->running) g_main_context_iteration (NULL, TRUE); ret = TRUE; out: g_clear_object (&app->root); g_clear_object (&app->log); if (context) g_option_context_free (context); return ret; }
static void pdf_load_job_openoffice_refresh_cache (PdfLoadJob *job) { gchar *doc_path, *cmd, *quoted_path, *unoconv_path; GFile *file; gint argc; GPid pid; gchar **argv = NULL; GError *error = NULL; unoconv_path = g_find_program_in_path ("unoconv"); if (unoconv_path == NULL) { pdf_load_job_openoffice_missing_unoconv (job); return; } g_free (unoconv_path); /* build the temporary PDF file path */ file = g_file_new_for_uri (job->uri); doc_path = g_file_get_path (file); quoted_path = g_shell_quote (doc_path); g_object_unref (file); g_free (doc_path); /* call into the unoconv executable to convert the OpenOffice document * to the temporary PDF. */ cmd = g_strdup_printf ("unoconv -f pdf -o %s %s", job->pdf_path, quoted_path); g_shell_parse_argv (cmd, &argc, &argv, &error); g_free (cmd); g_free (quoted_path); if (error != NULL) { pdf_load_job_complete_error (job, error); return; } g_spawn_async (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, &error); g_strfreev (argv); if (error != NULL) { pdf_load_job_complete_error (job, error); return; } /* now watch when the unoconv child process dies */ g_child_watch_add (pid, unoconv_child_watch_cb, job); job->unoconv_pid = pid; if (job->cancellable != NULL) job->cancelled_id = g_cancellable_connect (job->cancellable, G_CALLBACK (unoconv_cancelled_cb), job, NULL); }
gboolean Read_Directory (const gchar *path_real) { GFile *dir; GFileEnumerator *dir_enumerator; GError *error = NULL; gchar *msg; gchar progress_bar_text[30]; guint nbrfile = 0; double fraction; GList *FileList = NULL; GList *l; gint progress_bar_index = 0; GAction *action; EtApplicationWindow *window; g_return_val_if_fail (path_real != NULL, FALSE); ReadingDirectory = TRUE; /* A flag to avoid to start another reading */ /* Initialize file list */ ET_Core_Free (); ET_Core_Create (); et_application_window_update_actions (ET_APPLICATION_WINDOW (MainWindow)); window = ET_APPLICATION_WINDOW (MainWindow); /* Initialize browser list */ et_application_window_browser_clear (window); /* Clear entry boxes */ et_application_window_file_area_clear (window); et_application_window_tag_area_clear (window); // Set to unsensitive the Browser Area, to avoid to select another file while loading the first one et_application_window_browser_set_sensitive (window, FALSE); /* Placed only here, to empty the previous list of files */ dir = g_file_new_for_path (path_real); dir_enumerator = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN, G_FILE_QUERY_INFO_NONE, NULL, &error); if (!dir_enumerator) { // Message if the directory doesn't exist... GtkWidget *msgdialog; gchar *display_path = g_filename_display_name (path_real); msgdialog = gtk_message_dialog_new(GTK_WINDOW(MainWindow), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Cannot read directory ‘%s’"), display_path); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msgdialog), "%s", error->message); gtk_window_set_title(GTK_WINDOW(msgdialog),_("Directory Read Error")); gtk_dialog_run(GTK_DIALOG(msgdialog)); gtk_widget_destroy(msgdialog); g_free (display_path); ReadingDirectory = FALSE; //Allow a new reading et_application_window_browser_set_sensitive (window, TRUE); g_object_unref (dir); g_error_free (error); return FALSE; } /* Open the window to quit recursion (since 27/04/2007 : not only into recursion mode) */ et_application_window_set_busy_cursor (window); action = g_action_map_lookup_action (G_ACTION_MAP (MainWindow), "stop"); g_settings_bind (MainSettings, "browse-subdir", G_SIMPLE_ACTION (action), "enabled", G_SETTINGS_BIND_GET); Open_Quit_Recursion_Function_Window(); /* Read the directory recursively */ msg = g_strdup_printf(_("Search in progress…")); et_application_window_status_bar_message (window, msg, FALSE); g_free (msg); /* Search the supported files. */ FileList = read_directory_recursively (FileList, dir_enumerator, g_settings_get_boolean (MainSettings, "browse-subdir")); g_file_enumerator_close (dir_enumerator, NULL, &error); g_object_unref (dir_enumerator); g_object_unref (dir); nbrfile = g_list_length(FileList); et_application_window_progress_set_fraction (window, 0.0); g_snprintf (progress_bar_text, 30, "%d/%u", 0, nbrfile); et_application_window_progress_set_text (window, progress_bar_text); // Load the supported files (Extension recognized) for (l = FileList; l != NULL && !Main_Stop_Button_Pressed; l = g_list_next (l)) { GFile *file = l->data; gchar *filename_real = g_file_get_path (file); gchar *display_path = g_filename_display_name (filename_real); msg = g_strdup_printf (_("File: ‘%s’"), display_path); et_application_window_status_bar_message (window, msg, FALSE); g_free(msg); g_free (filename_real); g_free (display_path); ETCore->ETFileList = et_file_list_add (ETCore->ETFileList, file); /* Update the progress bar. */ fraction = (++progress_bar_index) / (double) nbrfile; et_application_window_progress_set_fraction (window, fraction); g_snprintf (progress_bar_text, 30, "%d/%u", progress_bar_index, nbrfile); et_application_window_progress_set_text (window, progress_bar_text); while (gtk_events_pending()) gtk_main_iteration(); } g_list_free_full (FileList, g_object_unref); et_application_window_progress_set_text (window, ""); /* Close window to quit recursion */ Destroy_Quit_Recursion_Function_Window(); Main_Stop_Button_Pressed = FALSE; action = g_action_map_lookup_action (G_ACTION_MAP (MainWindow), "stop"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE); //ET_Debug_Print_File_List(ETCore->ETFileList,__FILE__,__LINE__,__FUNCTION__); if (ETCore->ETFileList) { //GList *etfilelist; /* Load the list of file into the browser list widget */ et_application_window_browser_toggle_display_mode (window); /* Display the first file */ //No need to select first item, because Browser_Display_Tree_Or_Artist_Album_List() does this //etfilelist = ET_Displayed_File_List_First(); //if (etfilelist) //{ // ET_Display_File_Data_To_UI((ET_File *)etfilelist->data); // Browser_List_Select_File_By_Etfile((ET_File *)etfilelist->data,FALSE); //} /* Prepare message for the status bar */ if (g_settings_get_boolean (MainSettings, "browse-subdir")) { msg = g_strdup_printf (ngettext ("Found one file in this directory and subdirectories", "Found %u files in this directory and subdirectories", ETCore->ETFileDisplayedList_Length), ETCore->ETFileDisplayedList_Length); } else { msg = g_strdup_printf (ngettext ("Found one file in this directory", "Found %u files in this directory", ETCore->ETFileDisplayedList_Length), ETCore->ETFileDisplayedList_Length); } }else { /* Clear entry boxes */ et_application_window_file_area_clear (ET_APPLICATION_WINDOW (MainWindow)); et_application_window_tag_area_clear (ET_APPLICATION_WINDOW (MainWindow)); /* Translators: No files, as in "0 files". */ et_application_window_browser_label_set_text (ET_APPLICATION_WINDOW (MainWindow), _("No files")); /* See in ET_Display_Filename_To_UI */ /* Prepare message for the status bar */ if (g_settings_get_boolean (MainSettings, "browse-subdir")) msg = g_strdup(_("No file found in this directory and subdirectories")); else msg = g_strdup(_("No file found in this directory")); } /* Update sensitivity of buttons and menus */ et_application_window_update_actions (window); et_application_window_browser_set_sensitive (window, TRUE); et_application_window_progress_set_fraction (window, 0.0); et_application_window_status_bar_message (window, msg, FALSE); g_free (msg); et_application_window_set_normal_cursor (window); ReadingDirectory = FALSE; return TRUE; }
/** * gimp_icons_init: * * Initializes the GIMP stock icon factory. * * You don't need to call this function as gimp_ui_init() already does * this for you. */ void gimp_icons_init (void) { static gboolean initialized = FALSE; GtkSettings *settings; GdkPixbuf *pixbuf; GError *error = NULL; gchar *icons_dir; gchar *system_icon_theme; gchar *gimp_icon_theme; gint i; if (initialized) return; gimp_stock_factory = gtk_icon_factory_new (); for (i = 0; i < G_N_ELEMENTS (gimp_stock_items); i++) { register_stock_icon (gimp_stock_factory, gimp_stock_items[i].stock_id, gimp_stock_items[i].stock_id); } register_bidi_stock_icon (gimp_stock_factory, GIMP_STOCK_MENU_LEFT, GIMP_STOCK_MENU_LEFT, GIMP_STOCK_MENU_RIGHT); register_bidi_stock_icon (gimp_stock_factory, GIMP_STOCK_MENU_RIGHT, GIMP_STOCK_MENU_RIGHT, GIMP_STOCK_MENU_LEFT); register_stock_icon (gimp_stock_factory, "gimp-indexed-palette", GIMP_STOCK_COLORMAP); register_stock_icon (gimp_stock_factory, "gimp-qmask-off", GIMP_STOCK_QUICK_MASK_OFF); register_stock_icon (gimp_stock_factory, "gimp-qmask-on", GIMP_STOCK_QUICK_MASK_ON); gtk_icon_factory_add_default (gimp_stock_factory); gtk_stock_add_static (gimp_stock_items, G_N_ELEMENTS (gimp_stock_items)); gtk_stock_add_static (gimp_compat_stock_items, G_N_ELEMENTS (gimp_compat_stock_items)); /* always prepend the default icon theme, it's never removed from * the path again and acts as fallback for missing icons in other * themes. */ if (! default_search_path) default_search_path = gimp_data_directory_file ("icons", NULL); icons_dir = g_file_get_path (default_search_path); gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (), icons_dir); g_free (icons_dir); /* if an icon theme was chosen before init(), change to it */ if (icon_theme_path) { GFile *search_path = g_file_get_parent (icon_theme_path); if (!g_file_equal (search_path, default_search_path)) { gchar *icon_dir = g_file_get_path (search_path); gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (), icon_dir); g_free (icon_dir); } g_object_unref (search_path); gimp_icon_theme = g_file_get_basename (icon_theme_path); } else { gimp_icon_theme = g_strdup (GIMP_DEFAULT_ICON_THEME); } settings = gtk_settings_get_for_screen (gdk_screen_get_default ()); g_object_get (settings, "gtk-icon-theme-name", &system_icon_theme, NULL); g_object_set (settings, "gtk-fallback-icon-theme", system_icon_theme, "gtk-icon-theme-name", gimp_icon_theme, NULL); g_free (gimp_icon_theme); g_free (system_icon_theme); g_signal_connect (settings, "notify::gtk-icon-theme-name", G_CALLBACK (gimp_icons_notify_system_icon_theme), NULL); pixbuf = gdk_pixbuf_new_from_resource ("/org/gimp/icons/64/gimp-wilber-eek.png", &error); if (pixbuf) { gtk_icon_theme_add_builtin_icon (GIMP_STOCK_WILBER_EEK, 64, pixbuf); g_object_unref (pixbuf); } else { g_critical ("Failed to create icon image: %s", error->message); g_clear_error (&error); } initialized = TRUE; }
static GList* get_source_directories (AnjutaPlugin *plugin) { gchar *cwd; GList *node, *search_dirs = NULL; GList *slibs_dirs = NULL; GList *libs_dirs = NULL; GValue value = {0,}; GFile *file; return NULL; cwd = anjuta_util_get_current_dir(); file = g_file_new_for_path (cwd); search_dirs = g_list_prepend (search_dirs, g_file_get_uri (file)); g_object_unref (file); g_free (cwd); /* Check if a project is already open */ anjuta_shell_get_value (plugin->shell, IANJUTA_PROJECT_MANAGER_PROJECT_ROOT_URI, &value, NULL); /* Set source file search directories */ if (g_value_get_string (&value) != NULL) { IAnjutaProjectManager *pm; pm = anjuta_shell_get_interface (plugin->shell, IAnjutaProjectManager, NULL); if (pm) { slibs_dirs = ianjuta_project_manager_get_targets (pm, ANJUTA_PROJECT_TARGET | ANJUTA_PROJECT_SHAREDLIB, NULL); libs_dirs = ianjuta_project_manager_get_targets (pm, ANJUTA_PROJECT_TARGET | ANJUTA_PROJECT_STATICLIB, NULL); } } slibs_dirs = g_list_reverse (slibs_dirs); libs_dirs = g_list_reverse (libs_dirs); node = slibs_dirs; while (node) { gchar *path; GFile *parent = g_file_get_parent (node->data); path = g_file_get_uri (parent); g_object_unref (parent); search_dirs = g_list_prepend (search_dirs, path); node = g_list_next (node); } node = libs_dirs; while (node) { gchar *path; path = g_file_get_path (node->data); search_dirs = g_list_prepend (search_dirs, path); node = g_list_next (node); } g_list_foreach (slibs_dirs, (GFunc)g_free, NULL); g_list_free (slibs_dirs); g_list_foreach (libs_dirs, (GFunc)g_free, NULL); g_list_free (libs_dirs); return g_list_reverse (search_dirs); }
gboolean rejilla_project_open_project_xml (const gchar *uri, RejillaBurnSession *session, gboolean warn_user) { xmlNodePtr track_node = NULL; gchar *label = NULL; gchar *cover = NULL; xmlDocPtr project; xmlNodePtr item; gboolean retval; GFile *file; gchar *path; file = g_file_new_for_commandline_arg (uri); path = g_file_get_path (file); g_object_unref (file); if (!path) return FALSE; /* start parsing xml doc */ project = xmlParseFile (path); g_free (path); if (!project) { if (warn_user) rejilla_project_invalid_project_dialog (_("The project could not be opened")); return FALSE; } /* parses the "header" */ item = xmlDocGetRootElement (project); if (!item) { if (warn_user) rejilla_project_invalid_project_dialog (_("The file is empty")); xmlFreeDoc (project); return FALSE; } if (xmlStrcmp (item->name, (const xmlChar *) "rejillaproject") || item->next) goto error; item = item->children; while (item) { if (!xmlStrcmp (item->name, (const xmlChar *) "version")) { /* simply ignore it */ } else if (!xmlStrcmp (item->name, (const xmlChar *) "label")) { label = (gchar *) xmlNodeListGetString (project, item->xmlChildrenNode, 1); if (!(label)) goto error; } else if (!xmlStrcmp (item->name, (const xmlChar *) "cover")) { xmlChar *escaped; escaped = xmlNodeListGetString (project, item->xmlChildrenNode, 1); if (!escaped) goto error; cover = g_uri_unescape_string ((char *) escaped, NULL); g_free (escaped); } else if (!xmlStrcmp (item->name, (const xmlChar *) "track")) { if (track_node) goto error; track_node = item; } else if (item->type == XML_ELEMENT_NODE) goto error; item = item->next; } retval = _get_tracks (project, track_node, session); if (!retval) goto error; xmlFreeDoc (project); rejilla_burn_session_set_label (session, label); g_free (label); if (cover) { GValue *value; value = g_new0 (GValue, 1); g_value_init (value, G_TYPE_STRING); g_value_set_string (value, cover); rejilla_burn_session_tag_add (session, REJILLA_COVER_URI, value); g_free (cover); } return retval; error: if (cover) g_free (cover); if (label) g_free (label); xmlFreeDoc (project); if (warn_user) rejilla_project_invalid_project_dialog (_("It does not seem to be a valid Rejilla project")); return FALSE; }
IAnjutaDocument * anjuta_docman_get_document_for_file (AnjutaDocman *docman, GFile* file) { IAnjutaDocument *file_doc = NULL; GList *node; g_return_val_if_fail (file != NULL, NULL); for (node = docman->priv->pages; node != NULL; node = g_list_next (node)) { AnjutaDocmanPage *page; GFile* doc_file; page = (AnjutaDocmanPage *) node->data; if (page && page->widget && IANJUTA_IS_DOCUMENT (page->doc)) { IAnjutaDocument *doc; doc = page->doc; doc_file = ianjuta_file_get_file (IANJUTA_FILE (doc), NULL); if (doc_file) { gchar *path; gchar *local_real_path = NULL; /* Try exact match first */ if (g_file_equal (file, doc_file)) { g_object_unref (doc_file); file_doc = doc; break; } /* Try a local file alias */ path = g_file_get_path (file); if (path) { local_real_path = anjuta_util_get_real_path (path); if (local_real_path) { g_free (path); } else { local_real_path = path; } } else { continue; } if ((file_doc == NULL) && (local_real_path)) { gchar *doc_path = g_file_get_path (doc_file); if (doc_path) { gchar *doc_real_path = anjuta_util_get_real_path (doc_path); if (doc_real_path) { g_free (doc_path); } else { doc_real_path = doc_path; } if ((strcmp (doc_real_path, local_real_path) == 0)) { file_doc = doc; } g_free (doc_real_path); } } g_free (local_real_path); g_object_unref (doc_file); } } } return file_doc; }
static void rb_removable_media_manager_add_mount (RBRemovableMediaManager *mgr, GMount *mount) { RBRemovableMediaManagerPrivate *priv = GET_PRIVATE (mgr); RBRemovableMediaSource *source = NULL; GVolume *volume; GFile *mount_root; char *mountpoint; MPIDDevice *device_info; g_assert (mount != NULL); if (g_hash_table_lookup (priv->mount_mapping, mount) != NULL) { return; } #if GLIB_CHECK_VERSION(2, 20, 0) if (g_mount_is_shadowed (mount) != FALSE) { return; } #endif volume = g_mount_get_volume (mount); if (volume == NULL) { rb_debug ("Unhandled media, no volume for mount"); return; } /* if we've already created a source for the volume, * don't do anything with the mount. */ if (g_hash_table_lookup (priv->volume_mapping, volume) != NULL) { rb_debug ("already created a source for the volume, so ignoring the mount"); g_object_unref (volume); return; } dump_volume_identifiers (volume); g_object_unref (volume); /* look the device up in the device info database */ mount_root = g_mount_get_root (mount); if (mount_root == NULL) { rb_debug ("unable to get mount root, can't create a source for this mount"); return; } mountpoint = g_file_get_path (mount_root); g_object_unref (mount_root); device_info = mpid_device_new (mountpoint); g_free (mountpoint); g_signal_emit (G_OBJECT (mgr), rb_removable_media_manager_signals[CREATE_SOURCE_MOUNT], 0, mount, device_info, &source); if (source) { g_hash_table_insert (priv->mount_mapping, mount, source); rb_removable_media_manager_append_media_source (mgr, RB_SOURCE (source)); } else { rb_debug ("Unhandled media"); } g_object_unref (device_info); }
static GthImage * dcraw_pixbuf_animation_new_from_file (GInputStream *istream, GthFileData *file_data, int requested_size, int *original_width, int *original_height, gpointer user_data, GCancellable *cancellable, GError **error) { GthImage *image = NULL; GdkPixbuf *pixbuf; gboolean is_thumbnail; gboolean is_raw; gboolean is_hdr; char *local_file; char *local_file_md5; char *cache_file; char *cache_file_esc; char *local_file_esc; char *command = NULL; if (file_data == NULL) { if (error != NULL) *error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME, "Could not load file"); return NULL; } is_thumbnail = requested_size > 0; is_raw = _g_mime_type_is_raw (gth_file_data_get_mime_type (file_data)); is_hdr = _g_mime_type_is_hdr (gth_file_data_get_mime_type (file_data)); /* The output filename, and its persistence, depend on the input file * type, and whether or not a thumbnail has been requested. */ local_file = g_file_get_path (file_data->file); local_file_md5 = gnome_desktop_thumbnail_md5 (local_file); if (is_raw && !is_thumbnail) /* Full-sized converted RAW file */ cache_file = get_cache_full_path (local_file_md5, "conv.pnm"); else if (is_raw && is_thumbnail) /* RAW: thumbnails generated in pnm format. The converted file is later removed. */ cache_file = get_cache_full_path (local_file_md5, "conv-thumb.pnm"); else if (is_hdr && is_thumbnail) /* HDR: thumbnails generated in tiff format. The converted file is later removed. */ cache_file = get_cache_full_path (local_file_md5, "conv-thumb.tiff"); else /* Full-sized converted HDR files */ cache_file = get_cache_full_path (local_file_md5, "conv.tiff"); g_free (local_file_md5); if (cache_file == NULL) { g_free (local_file); return NULL; } local_file_esc = g_shell_quote (local_file); cache_file_esc = g_shell_quote (cache_file); /* Do nothing if an up-to-date converted file is already in the cache */ if (! g_file_test (cache_file, G_FILE_TEST_EXISTS) || (gth_file_data_get_mtime (file_data) > get_file_mtime (cache_file))) { if (is_raw) { if (is_thumbnail) { char *first_part; char *jpg_thumbnail; char *tiff_thumbnail; char *ppm_thumbnail; char *thumb_command; thumb_command = g_strdup_printf ("dcraw -e %s", local_file_esc); g_spawn_command_line_sync (thumb_command, NULL, NULL, NULL, NULL); g_free (thumb_command); first_part = _g_uri_remove_extension (local_file); jpg_thumbnail = g_strdup_printf ("%s.thumb.jpg", first_part); tiff_thumbnail = g_strdup_printf ("%s.thumb.tiff", first_part); ppm_thumbnail = g_strdup_printf ("%s.thumb.ppm", first_part); if (g_file_test (jpg_thumbnail, G_FILE_TEST_EXISTS)) { g_free (cache_file); cache_file = g_strdup (jpg_thumbnail); } else if (g_file_test (tiff_thumbnail, G_FILE_TEST_EXISTS)) { g_free (cache_file); cache_file = g_strdup (tiff_thumbnail); } else if (g_file_test (ppm_thumbnail, G_FILE_TEST_EXISTS)) { g_free (cache_file); cache_file = g_strdup (ppm_thumbnail); } else { /* No embedded thumbnail. Read the whole file. */ /* Add -h option to speed up thumbnail generation. */ command = g_strdup_printf ("dcraw -w -c -h %s > %s", local_file_esc, cache_file_esc); } g_free (first_part); g_free (jpg_thumbnail); g_free (tiff_thumbnail); g_free (ppm_thumbnail); } else { /* -w option = camera-specified white balance */ command = g_strdup_printf ("dcraw -w -c %s > %s", local_file_esc, cache_file_esc); } } if (is_hdr) { /* HDR files. We can use the pfssize tool to speed up thumbnail generation considerably, so we treat thumbnailing as a special case. */ char *resize_command; if (is_thumbnail) resize_command = g_strdup_printf (" | pfssize --maxx %d --maxy %d", requested_size, requested_size); else resize_command = g_strdup_printf (" "); command = g_strconcat ( "pfsin ", local_file_esc, resize_command, " | pfsclamp --rgb | pfstmo_drago03 | pfsout ", cache_file_esc, NULL ); g_free (resize_command); } if (command != NULL) { if (system (command) == -1) { g_free (command); g_free (cache_file_esc); g_free (local_file_esc); g_free (cache_file); g_free (local_file); return NULL; } g_free (command); } } pixbuf = gdk_pixbuf_new_from_file (cache_file, NULL); /* Thumbnail files are already cached, so delete the conversion cache copies */ if (is_thumbnail) { GFile *file; file = g_file_new_for_path (cache_file); g_file_delete (file, NULL, NULL); g_object_unref (file); } if (pixbuf != NULL) { image = gth_image_new_for_pixbuf (pixbuf); g_object_unref (pixbuf); } g_free (cache_file_esc); g_free (local_file_esc); g_free (cache_file); g_free (local_file); return image; }
static gboolean tvm_block_device_autorun (TvmContext *context, GMount *mount, GError **error) { struct stat statb_mount_point; struct stat statb_autoopen; gboolean autoopen; gboolean autoplay; gboolean autorun; gboolean result = FALSE; GError *err = NULL; GFile *mount_point; gchar **argv; gchar *autoplay_command; gchar *message; gchar *mount_path; gchar *path_autoopen; gchar *wine; gchar line[1024]; guint n; FILE *fp; gint response; g_return_val_if_fail (context != NULL, FALSE); g_return_val_if_fail (G_IS_MOUNT (mount), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); /* check if autoplaying video CDs and DVDs is enabled */ autoplay = xfconf_channel_get_bool (context->channel, "/autoplay-video-cds/enabled", FALSE); if (autoplay) { /* check if we have a video CD or video DVD here */ if (tvm_file_test (mount, "vcd", G_FILE_TEST_IS_DIR) || tvm_file_test (mount, "video_ts", G_FILE_TEST_IS_DIR)) { /* determine the autoplay command for video CDs/DVDs */ autoplay_command = xfconf_channel_get_string (context->channel, "/autoplay-video-cds/command", "parole"); /* try to spawn the preferred video CD/DVD player */ result = tvm_run_command (context, mount, autoplay_command, &err); /* free the command string */ g_free (autoplay_command); /* forward errors to the caller */ if (err != NULL) g_propagate_error (error, err); /* return success/failure to the caller */ return result; } } /* check if autorun is enabled */ autorun = xfconf_channel_get_bool (context->channel, "/autorun/enabled", FALSE); if (autorun) { /* Autostart files according to the Desktop Application Autostart * Specification */ static const gchar *autorun_files[] = { ".autorun", "autorun", "autorun.sh" }; for (n = 0; n < G_N_ELEMENTS (autorun_files); ++n) { /* check if one of the autorun files is present and executable */ if (tvm_file_test (mount, autorun_files[n], G_FILE_TEST_IS_EXECUTABLE) && tvm_file_test (mount, autorun_files[n], G_FILE_TEST_IS_REGULAR)) { /* prompt the user to execute the file */ message = g_strdup_printf (_("Would you like to allow \"%s\" to run?"), autorun_files[n]); response = tvm_prompt (context, "gnome-fs-executable", _("Auto-Run Confirmation"), _("Auto-Run capability detected"), message, _("Ig_nore"), GTK_RESPONSE_CANCEL, _("_Allow Auto-Run"), TVM_RESPONSE_AUTORUN, NULL); g_free (message); /* check if we should autorun */ if (response == TVM_RESPONSE_AUTORUN) { /* determine the mount point as a string */ mount_point = g_mount_get_root (mount); mount_path = g_file_get_path (mount_point); g_object_unref (mount_point); /* prepare argv to launch the autorun file */ argv = g_new0 (gchar *, 2); argv[0] = g_build_filename (mount_path, autorun_files[n], NULL); argv[1] = NULL; /* try to launch the autorun file */ result = g_spawn_async (mount_path, argv, NULL, 0, NULL, NULL, NULL, &err); /* free strings */ g_strfreev (argv); g_free (mount_path); if (err != NULL) g_propagate_error (error, err); return result; } } }
static void gb_terminal_respawn (GbTerminalView *self, VteTerminal *terminal) { g_autoptr(GPtrArray) args = NULL; g_autoptr(IdeSubprocess) subprocess = NULL; g_autoptr(IdeSubprocessLauncher) launcher = NULL; g_autofree gchar *workpath = NULL; g_autofree gchar *shell = NULL; GtkWidget *toplevel; GError *error = NULL; IdeContext *context; IdeVcs *vcs; VtePty *pty = NULL; GFile *workdir; gint64 now; int tty_fd = -1; gint stdout_fd = -1; gint stderr_fd = -1; IDE_ENTRY; g_assert (GB_IS_TERMINAL_VIEW (self)); vte_terminal_reset (terminal, TRUE, TRUE); toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self)); if (!IDE_IS_WORKBENCH (toplevel)) IDE_EXIT; /* Prevent flapping */ now = g_get_monotonic_time (); if ((now - self->last_respawn) < (G_USEC_PER_SEC / 10)) IDE_EXIT; self->last_respawn = now; context = ide_workbench_get_context (IDE_WORKBENCH (toplevel)); vcs = ide_context_get_vcs (context); workdir = ide_vcs_get_working_directory (vcs); workpath = g_file_get_path (workdir); shell = gb_terminal_view_discover_shell (NULL, &error); if (shell == NULL) { g_warning ("Failed to discover user shell: %s", error->message); /* We prefer bash in flatpak over sh */ if (ide_is_flatpak ()) shell = g_strdup ("/bin/bash"); else shell = vte_get_user_shell (); g_clear_error (&error); } args = g_ptr_array_new (); g_ptr_array_add (args, (gchar *)shell); g_ptr_array_add (args, NULL); pty = vte_terminal_pty_new_sync (terminal, VTE_PTY_DEFAULT | VTE_PTY_NO_LASTLOG | VTE_PTY_NO_UTMP | VTE_PTY_NO_WTMP, NULL, &error); if (pty == NULL) IDE_GOTO (failure); vte_terminal_set_pty (terminal, pty); if (-1 == (tty_fd = gb_vte_pty_create_slave (pty))) IDE_GOTO (failure); /* dup() is safe as it will inherit O_CLOEXEC */ if (-1 == (stdout_fd = dup (tty_fd)) || -1 == (stderr_fd = dup (tty_fd))) IDE_GOTO (failure); /* XXX: It would be nice to allow using the runtimes launcher */ launcher = ide_subprocess_launcher_new (0); ide_subprocess_launcher_set_run_on_host (launcher, TRUE); ide_subprocess_launcher_set_clear_env (launcher, FALSE); ide_subprocess_launcher_set_cwd (launcher, workpath); ide_subprocess_launcher_push_args (launcher, (const gchar * const *)args->pdata); ide_subprocess_launcher_take_stdin_fd (launcher, tty_fd); ide_subprocess_launcher_take_stdout_fd (launcher, stdout_fd); ide_subprocess_launcher_take_stderr_fd (launcher, stderr_fd); ide_subprocess_launcher_setenv (launcher, "TERM", "xterm-256color", TRUE); ide_subprocess_launcher_setenv (launcher, "INSIDE_GNOME_BUILDER", PACKAGE_VERSION, TRUE); ide_subprocess_launcher_setenv (launcher, "SHELL", shell, TRUE); tty_fd = -1; stdout_fd = -1; stderr_fd = -1; if (NULL == (subprocess = ide_subprocess_launcher_spawn (launcher, NULL, &error))) IDE_GOTO (failure); ide_subprocess_wait_async (subprocess, NULL, gb_terminal_view_wait_cb, g_object_ref (terminal)); failure: if (tty_fd != -1) close (tty_fd); if (stdout_fd != -1) close (stdout_fd); g_clear_object (&pty); if (error != NULL) { g_warning ("%s", error->message); g_clear_error (&error); } IDE_EXIT; }
static gboolean tvm_block_device_autoipod (TvmContext *context, GMount *mount, GError **error) { gboolean autoipod; gboolean is_audio_player = FALSE; gboolean is_ipod = FALSE; gboolean result = FALSE; GFile *mount_point; gchar *autoipod_command; gchar *autophoto_command; gchar *mount_path; gchar *path_dcim = NULL; gint response = TVM_RESPONSE_NONE; g_return_val_if_fail (context != NULL, FALSE); g_return_val_if_fail (G_IS_MOUNT (mount), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); autoipod = xfconf_channel_get_bool (context->channel, "/autoipod/enabled", FALSE); if (autoipod) { /* check if we have a portable audio player here */ is_audio_player = g_udev_device_has_property (context->device, "ID_MEDIA_PLAYER"); /* check if we have an iPod */ is_ipod = g_str_has_prefix (g_udev_device_get_property (context->device, "ID_MODEL"), "iPod"); if (is_ipod) { /* determine the mount point path */ mount_point = g_mount_get_root (mount); mount_path = g_file_get_path (mount_point); g_object_unref (mount_point); /* build dcim path */ path_dcim = g_build_filename (mount_path, "dcim", NULL); g_free (mount_path); /* check if the iPod has photos */ if (!g_file_test (path_dcim, G_FILE_TEST_IS_DIR)) { /* no photos */ g_free (path_dcim); path_dcim = NULL; } } autoipod_command = xfconf_channel_get_string (context->channel, "/autoipod/command", NULL); autophoto_command = xfconf_channel_get_string (context->channel, "/autophoto/command", NULL); /* check if autophoto command is specified, otherwise we cannot handle the photos * on the iPod anyway */ if (autophoto_command == NULL || *autophoto_command == '\0') { g_free (path_dcim); path_dcim = NULL; } /* iPods can carry music and photos... */ if (path_dcim != NULL) { /* ...so we need to prompt what to do */ response = tvm_prompt (context, "multimedia-player", _("Photos and Music"), _("Photos were found on your portable music player"), _("Would you like to import the photos or manage the " "music?"), _("Ig_nore"), GTK_RESPONSE_CANCEL, _("Import _Photos"), TVM_RESPONSE_PHOTOS, _("Manage _Music"), TVM_RESPONSE_MUSIC, NULL); } else if (is_audio_player || is_ipod) { response = TVM_RESPONSE_MUSIC; } /* check what to do */ if (response == TVM_RESPONSE_MUSIC) { /* run the preferred application to manage music players */ result = tvm_run_command (context, mount, autoipod_command, error); } else if (response == TVM_RESPONSE_PHOTOS) { /* run the preferred application to manage photos */ result = tvm_run_command (context, mount, autophoto_command, error); } else if (path_dcim != NULL) { /* when the user has decided to ignore photos/music, we don't want * to ask him again in autophoto and we don't want to mount the * device either... I guess? */ result = TRUE; } g_free (autophoto_command); g_free (autoipod_command); g_free (path_dcim); } return result; }
static void backup_job (GTask *task, gpointer source_object, gpointer task_data, GCancellable *cancellable) { BackupInfo *info = task_data; const gchar *src_path; GFile *parent_file, *temp_file; gchar *temp_path; sqlite3 *src_db = NULL; sqlite3 *temp_db = NULL; sqlite3_backup *backup = NULL; src_path = tracker_db_manager_get_file (TRACKER_DB_METADATA); parent_file = g_file_get_parent (info->destination); temp_file = g_file_get_child (parent_file, TRACKER_DB_BACKUP_META_FILENAME_T); g_file_delete (temp_file, NULL, NULL); temp_path = g_file_get_path (temp_file); if (sqlite3_open_v2 (src_path, &src_db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) { g_set_error (&info->error, TRACKER_DB_BACKUP_ERROR, TRACKER_DB_BACKUP_ERROR_UNKNOWN, "Could not open sqlite3 database:'%s'", src_path); } if (!info->error && sqlite3_open (temp_path, &temp_db) != SQLITE_OK) { g_set_error (&info->error, TRACKER_DB_BACKUP_ERROR, TRACKER_DB_BACKUP_ERROR_UNKNOWN, "Could not open sqlite3 database:'%s'", temp_path); } if (!info->error) { backup = sqlite3_backup_init (temp_db, "main", src_db, "main"); if (!backup) { g_set_error (&info->error, TRACKER_DB_BACKUP_ERROR, TRACKER_DB_BACKUP_ERROR_UNKNOWN, "Unable to initialize sqlite3 backup from '%s' to '%s'", src_path, temp_path); } } if (!info->error && sqlite3_backup_step (backup, -1) != SQLITE_DONE) { g_set_error (&info->error, TRACKER_DB_BACKUP_ERROR, TRACKER_DB_BACKUP_ERROR_UNKNOWN, "Unable to complete sqlite3 backup"); } if (backup) { if (sqlite3_backup_finish (backup) != SQLITE_OK) { if (info->error) { /* sqlite3_backup_finish can provide more detailed error message */ g_clear_error (&info->error); } g_set_error (&info->error, TRACKER_DB_BACKUP_ERROR, TRACKER_DB_BACKUP_ERROR_UNKNOWN, "Unable to finish sqlite3 backup: %s", sqlite3_errmsg (temp_db)); } backup = NULL; } if (temp_db) { sqlite3_close (temp_db); temp_db = NULL; } if (src_db) { sqlite3_close (src_db); src_db = NULL; } if (!info->error) { g_file_move (temp_file, info->destination, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &info->error); } g_free (temp_path); g_object_unref (temp_file); g_object_unref (parent_file); g_idle_add_full (G_PRIORITY_DEFAULT, perform_callback, info, backup_info_free); }
static void _really_move_to_trash (CheeseWindow *cheese_window, GList *files) { GError *error = NULL; GList *l = NULL; GList *d = NULL; gchar *primary, *secondary; GtkWidget *question_dialog; gint response; gint list_length = g_list_length (files); g_print ("received %d items to delete\n", list_length); for (l = files; l != NULL; l = l->next) { if (!g_file_test (g_file_get_path (l->data), G_FILE_TEST_EXISTS)) { g_object_unref (l->data); break; } if (!g_file_trash (l->data, NULL, &error)) { primary = g_strdup (_("Cannot move file to trash, do you want to delete immediately?")); secondary = g_strdup_printf (_("The file \"%s\" cannot be moved to the trash. Details: %s"), g_file_get_basename (l->data), error->message); question_dialog = gtk_message_dialog_new (GTK_WINDOW (cheese_window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", primary); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (question_dialog), "%s", secondary); gtk_dialog_add_button (GTK_DIALOG (question_dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); if (list_length > 1) { /* no need for all those buttons we have a single file to delete */ gtk_dialog_add_button (GTK_DIALOG (question_dialog), CHEESE_BUTTON_SKIP, CHEESE_RESPONSE_SKIP); gtk_dialog_add_button (GTK_DIALOG (question_dialog), CHEESE_BUTTON_SKIP_ALL, CHEESE_RESPONSE_SKIP_ALL); gtk_dialog_add_button (GTK_DIALOG (question_dialog), CHEESE_BUTTON_DELETE_ALL, CHEESE_RESPONSE_DELETE_ALL); } gtk_dialog_add_button (GTK_DIALOG (question_dialog), GTK_STOCK_DELETE, GTK_RESPONSE_ACCEPT); response = gtk_dialog_run (GTK_DIALOG (question_dialog)); gtk_widget_destroy (question_dialog); g_free (primary); g_free (secondary); g_error_free (error); error = NULL; switch (response) { case CHEESE_RESPONSE_DELETE_ALL: /* forward the list to cmd_delete */ _really_delete (cheese_window, l, TRUE); return; case GTK_RESPONSE_ACCEPT: /* create a single file list for cmd_delete */ d = g_list_append (d, g_object_ref (l->data)); _really_delete (cheese_window, d, TRUE); g_list_free (d); break; case CHEESE_RESPONSE_SKIP: /* do nothing, skip to the next item */ break; case CHEESE_RESPONSE_SKIP_ALL: case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_DELETE_EVENT: default: /* cancel the whole delete operation */ return; } } else { cheese_thumb_view_remove_item (cheese_window_get_thumbview (cheese_window), l->data); } g_object_unref (l->data); } }
/* * Write a playlist * - 'playlist_name' in file system encoding (not UTF-8) */ static gboolean write_playlist (EtPlaylistDialog *self, GFile *file, GError **error) { EtPlaylistDialogPrivate *priv; GFile *parent; GFileOutputStream *ostream; GString *to_write; GList *l; GList *etfilelist = NULL; gchar *basedir; gchar *temp; EtPlaylistContent playlist_content; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); priv = et_playlist_dialog_get_instance_private (self); ostream = g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, error); if (!ostream) { g_assert (error == NULL || *error != NULL); return FALSE; } /* 'base directory' where is located the playlist. Used also to write file with a * relative path for file located in this directory and sub-directories */ parent = g_file_get_parent (file); basedir = g_file_get_path (parent); g_object_unref (parent); playlist_content = g_settings_get_enum (MainSettings, "playlist-content"); /* 1) First line of the file (if playlist content is not set to "write only * list of files") */ if (playlist_content != ET_PLAYLIST_CONTENT_FILENAMES) { gsize bytes_written; to_write = g_string_new ("#EXTM3U\r\n"); if (!g_output_stream_write_all (G_OUTPUT_STREAM (ostream), to_write->str, to_write->len, &bytes_written, NULL, error)) { g_debug ("Only %" G_GSIZE_FORMAT " bytes out of %" G_GSIZE_FORMAT "bytes of data were written", bytes_written, to_write->len); g_assert (error == NULL || *error != NULL); g_string_free (to_write, TRUE); g_object_unref (ostream); return FALSE; } g_string_free (to_write, TRUE); } if (g_settings_get_boolean (MainSettings, "playlist-selected-only")) { etfilelist = et_application_window_browser_get_selected_files (ET_APPLICATION_WINDOW (MainWindow)); } else { etfilelist = ETCore->ETFileList; } for (l = etfilelist; l != NULL; l = g_list_next (l)) { const ET_File *etfile; const gchar *filename; gint duration; etfile = (ET_File *)l->data; filename = ((File_Name *)etfile->FileNameCur->data)->value; duration = ((ET_File_Info *)etfile->ETFileInfo)->duration; if (g_settings_get_boolean (MainSettings, "playlist-relative")) { // Keep only files in this directory and sub-dirs if ( strncmp(filename,basedir,strlen(basedir))==0 ) { gsize bytes_written; /* 2) Write the header. */ switch (playlist_content) { case ET_PLAYLIST_CONTENT_FILENAMES: /* No header written. */ break; case ET_PLAYLIST_CONTENT_EXTENDED: /* Header has extended information. */ temp = g_path_get_basename (filename); to_write = g_string_new ("#EXTINF:"); /* Must be written in system encoding (not UTF-8). */ g_string_append_printf (to_write, "%d,%s\r\n", duration, temp); if (!g_output_stream_write_all (G_OUTPUT_STREAM (ostream), to_write->str, to_write->len, &bytes_written, NULL, error)) { g_debug ("Only %" G_GSIZE_FORMAT " bytes out of %" G_GSIZE_FORMAT "bytes of data were written", bytes_written, to_write->len); g_assert (error == NULL || *error != NULL); g_string_free (to_write, TRUE); g_object_unref (ostream); return FALSE; } g_string_free (to_write, TRUE); g_free (temp); break; case ET_PLAYLIST_CONTENT_EXTENDED_MASK: { /* Header uses information generated from a mask. */ gchar *mask = filename_from_display (gtk_entry_get_text (GTK_ENTRY (priv->content_mask_entry))); /* Special case: do not replace illegal characters and * do not check if there is a directory separator in * the mask. */ gchar *filename_generated_utf8 = et_scan_generate_new_filename_from_mask (etfile, mask, TRUE); gchar *filename_generated = filename_from_display (filename_generated_utf8); to_write = g_string_new ("#EXTINF:"); /* Must be written in system encoding (not UTF-8). */ g_string_append_printf (to_write, "%d,%s\r\n", duration, filename_generated); if (!g_output_stream_write_all (G_OUTPUT_STREAM (ostream), to_write->str, to_write->len, &bytes_written, NULL, error)) { g_debug ("Only %" G_GSIZE_FORMAT " bytes out of %" G_GSIZE_FORMAT "bytes of data were written", bytes_written, to_write->len); g_assert (error == NULL || *error != NULL); g_string_free (to_write, TRUE); g_object_unref (ostream); return FALSE; } g_string_free (to_write, TRUE); g_free (mask); g_free (filename_generated_utf8); break; } default: g_assert_not_reached (); break; } /* 3) Write the file path. */ if (g_settings_get_boolean (MainSettings, "playlist-dos-separator")) { gchar *filename_conv = g_strdup(filename+strlen(basedir)+1); convert_forwardslash_to_backslash (filename_conv); to_write = g_string_new (filename_conv); /* Must be written in system encoding (not UTF-8)*/ to_write = g_string_append (to_write, "\r\n"); if (!g_output_stream_write_all (G_OUTPUT_STREAM (ostream), to_write->str, to_write->len, &bytes_written, NULL, error)) { g_debug ("Only %" G_GSIZE_FORMAT " bytes out of %" G_GSIZE_FORMAT "bytes of data were written", bytes_written, to_write->len); g_assert (error == NULL || *error != NULL); g_string_free (to_write, TRUE); g_object_unref (ostream); return FALSE; } g_string_free (to_write, TRUE); g_free(filename_conv); }else { to_write = g_string_new (filename+strlen(basedir)+1); /* Must be written in system encoding (not UTF-8)*/ to_write = g_string_append (to_write, "\r\n"); if (!g_output_stream_write_all (G_OUTPUT_STREAM (ostream), to_write->str, to_write->len, &bytes_written, NULL, error)) { g_debug ("Only %" G_GSIZE_FORMAT " bytes out of %" G_GSIZE_FORMAT "bytes of data were written", bytes_written, to_write->len); g_assert (error == NULL || *error != NULL); g_string_free (to_write, TRUE); g_object_unref (ostream); return FALSE; } g_string_free (to_write, TRUE); } } } else /* !ETSettings:playlist-relative */ { gsize bytes_written; /* 2) Write the header. */ switch (playlist_content) { case ET_PLAYLIST_CONTENT_FILENAMES: /* No header written. */ break; case ET_PLAYLIST_CONTENT_EXTENDED: /* Header has extended information. */ temp = g_path_get_basename (filename); to_write = g_string_new ("#EXTINF:"); /* Must be written in system encoding (not UTF-8). */ g_string_append_printf (to_write, "%d,%s\r\n", duration, temp); g_free (temp); if (!g_output_stream_write_all (G_OUTPUT_STREAM (ostream), to_write->str, to_write->len, &bytes_written, NULL, error)) { g_debug ("Only %" G_GSIZE_FORMAT " bytes out of %" G_GSIZE_FORMAT" bytes of data were written", bytes_written, to_write->len); g_assert (error == NULL || *error != NULL); g_string_free (to_write, TRUE); g_object_unref (ostream); return FALSE; } g_string_free (to_write, TRUE); break; case ET_PLAYLIST_CONTENT_EXTENDED_MASK: { /* Header uses information generated from a mask. */ gchar *mask = filename_from_display (gtk_entry_get_text (GTK_ENTRY (priv->content_mask_entry))); /* Special case: do not replace illegal characters and * do not check if there is a directory separator in * the mask. */ gchar *filename_generated_utf8 = et_scan_generate_new_filename_from_mask (etfile, mask, TRUE); gchar *filename_generated = filename_from_display (filename_generated_utf8); to_write = g_string_new ("#EXTINF:"); /* Must be written in system encoding (not UTF-8). */ g_string_append_printf (to_write, "%d,%s\r\n", duration, filename_generated); g_free (filename_generated); if (!g_output_stream_write_all (G_OUTPUT_STREAM (ostream), to_write->str, to_write->len, &bytes_written, NULL, error)) { g_debug ("Only %" G_GSIZE_FORMAT " bytes out of %" G_GSIZE_FORMAT" bytes of data were written", bytes_written, to_write->len); g_assert (error == NULL || *error != NULL); g_string_free (to_write, TRUE); g_object_unref (ostream); return FALSE; } g_string_free (to_write, TRUE); g_free (mask); g_free (filename_generated_utf8); } break; default: g_assert_not_reached (); break; } /* 3) Write the file path. */ if (g_settings_get_boolean (MainSettings, "playlist-dos-separator")) { gchar *filename_conv = g_strdup(filename); convert_forwardslash_to_backslash(filename_conv); to_write = g_string_new (filename_conv); /* Must be written in system encoding (not UTF-8)*/ to_write = g_string_append (to_write, "\r\n"); if (!g_output_stream_write_all (G_OUTPUT_STREAM (ostream), to_write->str, to_write->len, &bytes_written, NULL, error)) { g_debug ("Only %" G_GSIZE_FORMAT " bytes out of %" G_GSIZE_FORMAT" bytes of data were written", bytes_written, to_write->len); g_assert (error == NULL || *error != NULL); g_string_free (to_write, TRUE); g_object_unref (ostream); return FALSE; } g_string_free (to_write, TRUE); g_free(filename_conv); }else { to_write = g_string_new (filename); /* Must be written in system encoding (not UTF-8)*/ to_write = g_string_append (to_write, "\r\n"); if (!g_output_stream_write_all (G_OUTPUT_STREAM (ostream), to_write->str, to_write->len, &bytes_written, NULL, error)) { g_debug ("Only %" G_GSIZE_FORMAT " bytes out of %" G_GSIZE_FORMAT" bytes of data were written", bytes_written, to_write->len); g_assert (error == NULL || *error != NULL); g_string_free (to_write, TRUE); g_object_unref (ostream); return FALSE; } g_string_free (to_write, TRUE); } } } if (g_settings_get_boolean (MainSettings, "playlist-selected-only")) { g_list_free (etfilelist); } g_assert (error == NULL || *error == NULL); g_object_unref (ostream); g_free(basedir); return TRUE; }
static gboolean _copy_files_async (GFile* src, gpointer data) { gboolean retval = TRUE; TDData* _data = (TDData*) data; GError* error = NULL; /*GCancellable* _copy_cancellable = NULL;*/ GFile* dest = NULL; _copy_cancellable = _data->cancellable; dest = _data->dest_file; //because @dest doesn't exist, we should check @src instead. GFileType type = g_file_query_file_type (src, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL); if (type == G_FILE_TYPE_DIRECTORY) { //TODO: change permissions g_file_make_directory (dest, NULL, &error); #if 1 char* dest_uri = g_file_get_uri (dest); g_debug ("_copy_files_async: mkdir : %s", dest_uri); g_free (dest_uri); #endif } else { if (!_cmp_files (src, dest)) //src==dest { //rename destination name char* tmp = g_file_get_uri (dest); char* ext_name = strrchr (tmp, '.'); if (ext_name != NULL) { *ext_name = '\0'; ext_name ++; } char* stem_name = tmp; char* tmp_dest = g_strconcat (stem_name, " (", _("Copy"), ")", ".", ext_name, NULL); g_free (tmp); g_object_unref (dest); dest = g_file_new_for_uri (tmp_dest); g_free (tmp_dest); _data->dest_file = dest; } gboolean ASYNC = TRUE; if (ASYNC) { // g_debug("check the g_file_copy_async error first!"); char* dest_path = g_file_get_path (dest); gboolean is_exist = g_file_test(dest_path,G_FILE_TEST_EXISTS); g_free (dest_path); if (is_exist) { error = g_error_new(G_FILE_TEST_EXISTS,G_IO_ERROR_EXISTS,"file already exist!"); // g_cancellable_cancel (_copy_cancellable); g_warning ("_copy_files_async: %s, code = %d", error->message, error->code); //TEST: FileOpsResponse* response = NULL; if (g_copy_response != NULL && g_copy_response->apply_to_all) { response = fileops_response_dup (g_copy_response); //FIXME:reduce dup calls } else { response = fileops_move_copy_error_show_dialog (_("copy"), error, src, dest, NULL); if (response->apply_to_all) g_copy_response = fileops_response_dup (response); } if(response != NULL) { switch (response->response_id) { case GTK_RESPONSE_CANCEL: //cancel all operations g_debug ("response : Cancel"); retval = FALSE; break; case CONFLICT_RESPONSE_SKIP: //skip, imediately return. g_debug ("response : Skip"); retval = TRUE; break; case CONFLICT_RESPONSE_RENAME: //rename, redo operations g_debug ("response : Rename to %s", response->file_name); GFile* dest_parent = g_file_get_parent (dest); GFile* new_dest = g_file_get_child (dest_parent, response->file_name); g_object_unref (dest_parent); g_object_unref (dest); _data->dest_file = new_dest; // retval = _copy_files_async (src, _data); _copy_files_async_true(src,_data); retval = COPY_ASYNC_FINISH; break; case CONFLICT_RESPONSE_REPLACE: if (type == G_FILE_TYPE_DIRECTORY) { //Merge: g_debug("Merge"); retval = TRUE; } else { //replace retval = _delete_files_async (dest, _data); if (retval == TRUE) { // retval = _copy_files_async (src, _data); _copy_files_async_true(src,_data); } } g_debug ("response : Replace"); break; default: retval = FALSE; break; } fileops_response_free (response); } g_error_free (error); } else { g_debug("file not exist in dest"); _copy_files_async_true(src,_data); retval == TRUE; } } } COPY_ASYNC_FINISH = retval; return COPY_ASYNC_FINISH; }
G_MODULE_EXPORT gboolean tracker_extract_get_metadata (TrackerExtractInfo *info) { struct jpeg_decompress_struct cinfo; struct tej_error_mgr tejerr; struct jpeg_marker_struct *marker; TrackerSparqlBuilder *preupdate, *metadata; TrackerXmpData *xd = NULL; TrackerExifData *ed = NULL; TrackerIptcData *id = NULL; MergeData md = { 0 }; GFile *file; FILE *f; goffset size; gchar *filename, *uri; gchar *comment = NULL; const gchar *dlna_profile, *dlna_mimetype, *graph; GPtrArray *keywords; gboolean success = TRUE; GString *where; guint i; metadata = tracker_extract_info_get_metadata_builder (info); preupdate = tracker_extract_info_get_preupdate_builder (info); graph = tracker_extract_info_get_graph (info); file = tracker_extract_info_get_file (info); filename = g_file_get_path (file); size = tracker_file_get_size (filename); if (size < 18) { g_free (filename); return FALSE; } f = tracker_file_open (filename); g_free (filename); if (!f) { return FALSE; } uri = g_file_get_uri (file); tracker_sparql_builder_predicate (metadata, "a"); tracker_sparql_builder_object (metadata, "nfo:Image"); tracker_sparql_builder_predicate (metadata, "a"); tracker_sparql_builder_object (metadata, "nmm:Photo"); cinfo.err = jpeg_std_error (&tejerr.jpeg); tejerr.jpeg.error_exit = extract_jpeg_error_exit; if (setjmp (tejerr.setjmp_buffer)) { success = FALSE; goto fail; } jpeg_create_decompress (&cinfo); jpeg_save_markers (&cinfo, JPEG_COM, 0xFFFF); jpeg_save_markers (&cinfo, JPEG_APP0 + 1, 0xFFFF); jpeg_save_markers (&cinfo, JPEG_APP0 + 13, 0xFFFF); jpeg_stdio_src (&cinfo, f); jpeg_read_header (&cinfo, TRUE); /* FIXME? It is possible that there are markers after SOS, * but there shouldn't be. Should we decompress the whole file? * * jpeg_start_decompress(&cinfo); * jpeg_finish_decompress(&cinfo); * * jpeg_calc_output_dimensions(&cinfo); */ marker = (struct jpeg_marker_struct *) &cinfo.marker_list; while (marker) { gchar *str; gsize len; #ifdef HAVE_LIBIPTCDATA gsize offset; guint sublen; #endif /* HAVE_LIBIPTCDATA */ switch (marker->marker) { case JPEG_COM: g_free (comment); comment = g_strndup ((gchar*) marker->data, marker->data_length); break; case JPEG_APP0 + 1: str = (gchar*) marker->data; len = marker->data_length; #ifdef HAVE_LIBEXIF if (strncmp (EXIF_NAMESPACE, str, EXIF_NAMESPACE_LENGTH) == 0) { ed = tracker_exif_new ((guchar *) marker->data, len, uri); } #endif /* HAVE_LIBEXIF */ #ifdef HAVE_EXEMPI if (strncmp (XMP_NAMESPACE, str, XMP_NAMESPACE_LENGTH) == 0) { xd = tracker_xmp_new (str + XMP_NAMESPACE_LENGTH, len - XMP_NAMESPACE_LENGTH, uri); } #endif /* HAVE_EXEMPI */ break; case JPEG_APP0 + 13: str = (gchar*) marker->data; len = marker->data_length; #ifdef HAVE_LIBIPTCDATA if (len > 0 && strncmp (PS3_NAMESPACE, str, PS3_NAMESPACE_LENGTH) == 0) { offset = iptc_jpeg_ps3_find_iptc (str, len, &sublen); if (offset > 0 && sublen > 0) { id = tracker_iptc_new (str + offset, sublen, uri); } } #endif /* HAVE_LIBIPTCDATA */ break; default: marker = marker->next; continue; } marker = marker->next; } if (!ed) { ed = g_new0 (TrackerExifData, 1); } if (!xd) { xd = g_new0 (TrackerXmpData, 1); } if (!id) { id = g_new0 (TrackerIptcData, 1); } md.title = tracker_coalesce_strip (4, xd->title, ed->document_name, xd->title2, xd->pdf_title); md.orientation = tracker_coalesce_strip (3, xd->orientation, ed->orientation, id->image_orientation); md.copyright = tracker_coalesce_strip (4, xd->copyright, xd->rights, ed->copyright, id->copyright_notice); md.white_balance = tracker_coalesce_strip (2, xd->white_balance, ed->white_balance); md.fnumber = tracker_coalesce_strip (2, xd->fnumber, ed->fnumber); md.flash = tracker_coalesce_strip (2, xd->flash, ed->flash); md.focal_length = tracker_coalesce_strip (2, xd->focal_length, ed->focal_length); md.artist = tracker_coalesce_strip (3, xd->artist, ed->artist, xd->contributor); md.exposure_time = tracker_coalesce_strip (2, xd->exposure_time, ed->exposure_time); md.iso_speed_ratings = tracker_coalesce_strip (2, xd->iso_speed_ratings, ed->iso_speed_ratings); md.date = tracker_coalesce_strip (5, xd->date, xd->time_original, ed->time, id->date_created, ed->time_original); md.description = tracker_coalesce_strip (2, xd->description, ed->description); md.metering_mode = tracker_coalesce_strip (2, xd->metering_mode, ed->metering_mode); md.city = tracker_coalesce_strip (2, xd->city, id->city); md.state = tracker_coalesce_strip (2, xd->state, id->state); md.address = tracker_coalesce_strip (2, xd->address, id->sublocation); md.country = tracker_coalesce_strip (2, xd->country, id->country_name); /* FIXME We are not handling the altitude ref here for xmp */ md.gps_altitude = tracker_coalesce_strip (2, xd->gps_altitude, ed->gps_altitude); md.gps_latitude = tracker_coalesce_strip (2, xd->gps_latitude, ed->gps_latitude); md.gps_longitude = tracker_coalesce_strip (2, xd->gps_longitude, ed->gps_longitude); md.gps_direction = tracker_coalesce_strip (2, xd->gps_direction, ed->gps_direction); md.creator = tracker_coalesce_strip (3, xd->creator, id->byline, id->credit); md.comment = tracker_coalesce_strip (2, comment, ed->user_comment); md.make = tracker_coalesce_strip (2, xd->make, ed->make); md.model = tracker_coalesce_strip (2, xd->model, ed->model); /* Prioritize on native dimention in all cases */ tracker_sparql_builder_predicate (metadata, "nfo:width"); tracker_sparql_builder_object_int64 (metadata, cinfo.image_width); /* TODO: add ontology and store ed->software */ tracker_sparql_builder_predicate (metadata, "nfo:height"); tracker_sparql_builder_object_int64 (metadata, cinfo.image_height); if (guess_dlna_profile (cinfo.image_width, cinfo.image_height, &dlna_profile, &dlna_mimetype)) { tracker_sparql_builder_predicate (metadata, "nmm:dlnaProfile"); tracker_sparql_builder_object_string (metadata, dlna_profile); tracker_sparql_builder_predicate (metadata, "nmm:dlnaMime"); tracker_sparql_builder_object_string (metadata, dlna_mimetype); } if (id->contact) { gchar *uri = tracker_sparql_escape_uri_printf ("urn:contact:%s", id->contact); tracker_sparql_builder_insert_open (preupdate, NULL); if (graph) { tracker_sparql_builder_graph_open (preupdate, graph); } tracker_sparql_builder_subject_iri (preupdate, uri); tracker_sparql_builder_predicate (preupdate, "a"); tracker_sparql_builder_object (preupdate, "nco:Contact"); tracker_sparql_builder_predicate (preupdate, "nco:fullname"); tracker_sparql_builder_object_unvalidated (preupdate, id->contact); if (graph) { tracker_sparql_builder_graph_close (preupdate); } tracker_sparql_builder_insert_close (preupdate); tracker_sparql_builder_predicate (metadata, "nco:representative"); tracker_sparql_builder_object_iri (metadata, uri); g_free (uri); } keywords = g_ptr_array_new (); if (xd->keywords) { tracker_keywords_parse (keywords, xd->keywords); } if (xd->pdf_keywords) { tracker_keywords_parse (keywords, xd->pdf_keywords); } if (xd->subject) { tracker_keywords_parse (keywords, xd->subject); } if (xd->publisher) { gchar *uri = tracker_sparql_escape_uri_printf ("urn:contact:%s", xd->publisher); tracker_sparql_builder_insert_open (preupdate, NULL); if (graph) { tracker_sparql_builder_graph_open (preupdate, graph); } tracker_sparql_builder_subject_iri (preupdate, uri); tracker_sparql_builder_predicate (preupdate, "a"); tracker_sparql_builder_object (preupdate, "nco:Contact"); tracker_sparql_builder_predicate (preupdate, "nco:fullname"); tracker_sparql_builder_object_unvalidated (preupdate, xd->publisher); if (graph) { tracker_sparql_builder_graph_close (preupdate); } tracker_sparql_builder_insert_close (preupdate); tracker_sparql_builder_predicate (metadata, "nco:publisher"); tracker_sparql_builder_object_iri (metadata, uri); g_free (uri); } if (xd->type) { tracker_sparql_builder_predicate (metadata, "dc:type"); tracker_sparql_builder_object_unvalidated (metadata, xd->type); } if (xd->rating) { tracker_sparql_builder_predicate (metadata, "nao:numericRating"); tracker_sparql_builder_object_unvalidated (metadata, xd->rating); } if (xd->format) { tracker_sparql_builder_predicate (metadata, "dc:format"); tracker_sparql_builder_object_unvalidated (metadata, xd->format); } if (xd->identifier) { tracker_sparql_builder_predicate (metadata, "dc:indentifier"); tracker_sparql_builder_object_unvalidated (metadata, xd->identifier); } if (xd->source) { tracker_sparql_builder_predicate (metadata, "dc:source"); tracker_sparql_builder_object_unvalidated (metadata, xd->source); } if (xd->language) { tracker_sparql_builder_predicate (metadata, "dc:language"); tracker_sparql_builder_object_unvalidated (metadata, xd->language); } if (xd->relation) { tracker_sparql_builder_predicate (metadata, "dc:relation"); tracker_sparql_builder_object_unvalidated (metadata, xd->relation); } if (xd->coverage) { tracker_sparql_builder_predicate (metadata, "dc:coverage"); tracker_sparql_builder_object_unvalidated (metadata, xd->coverage); } if (xd->license) { tracker_sparql_builder_predicate (metadata, "nie:license"); tracker_sparql_builder_object_unvalidated (metadata, xd->license); } if (xd->regions) { tracker_xmp_apply_regions (preupdate, metadata, graph, xd); } if (id->keywords) { tracker_keywords_parse (keywords, id->keywords); } where = g_string_new (""); for (i = 0; i < keywords->len; i++) { gchar *p, *escaped, *var; p = g_ptr_array_index (keywords, i); escaped = tracker_sparql_escape_string (p); var = g_strdup_printf ("tag%d", i + 1); /* ensure tag with specified label exists */ tracker_sparql_builder_append (preupdate, "INSERT { "); if (graph) { tracker_sparql_builder_append (preupdate, "GRAPH <"); tracker_sparql_builder_append (preupdate, graph); tracker_sparql_builder_append (preupdate, "> { "); } tracker_sparql_builder_append (preupdate, "_:tag a nao:Tag ; nao:prefLabel \""); tracker_sparql_builder_append (preupdate, escaped); tracker_sparql_builder_append (preupdate, "\""); if (graph) { tracker_sparql_builder_append (preupdate, " } "); } tracker_sparql_builder_append (preupdate, " }\n"); tracker_sparql_builder_append (preupdate, "WHERE { FILTER (NOT EXISTS { " "?tag a nao:Tag ; nao:prefLabel \""); tracker_sparql_builder_append (preupdate, escaped); tracker_sparql_builder_append (preupdate, "\" }) }\n"); /* associate file with tag */ tracker_sparql_builder_predicate (metadata, "nao:hasTag"); tracker_sparql_builder_object_variable (metadata, var); g_string_append_printf (where, "?%s a nao:Tag ; nao:prefLabel \"%s\" .\n", var, escaped); g_free (var); g_free (escaped); g_free (p); } g_ptr_array_free (keywords, TRUE); tracker_extract_info_set_where_clause (info, where->str); g_string_free (where, TRUE); if (md.make || md.model) { gchar *equip_uri; equip_uri = tracker_sparql_escape_uri_printf ("urn:equipment:%s:%s:", md.make ? md.make : "", md.model ? md.model : ""); tracker_sparql_builder_insert_open (preupdate, NULL); if (graph) { tracker_sparql_builder_graph_open (preupdate, graph); } tracker_sparql_builder_subject_iri (preupdate, equip_uri); tracker_sparql_builder_predicate (preupdate, "a"); tracker_sparql_builder_object (preupdate, "nfo:Equipment"); if (md.make) { tracker_sparql_builder_predicate (preupdate, "nfo:manufacturer"); tracker_sparql_builder_object_unvalidated (preupdate, md.make); } if (md.model) { tracker_sparql_builder_predicate (preupdate, "nfo:model"); tracker_sparql_builder_object_unvalidated (preupdate, md.model); } if (graph) { tracker_sparql_builder_graph_close (preupdate); } tracker_sparql_builder_insert_close (preupdate); tracker_sparql_builder_predicate (metadata, "nfo:equipment"); tracker_sparql_builder_object_iri (metadata, equip_uri); g_free (equip_uri); } tracker_guarantee_title_from_file (metadata, "nie:title", md.title, uri, NULL); if (md.orientation) { tracker_sparql_builder_predicate (metadata, "nfo:orientation"); tracker_sparql_builder_object (metadata, md.orientation); } if (md.copyright) { tracker_sparql_builder_predicate (metadata, "nie:copyright"); tracker_sparql_builder_object_unvalidated (metadata, md.copyright); } if (md.white_balance) { tracker_sparql_builder_predicate (metadata, "nmm:whiteBalance"); tracker_sparql_builder_object (metadata, md.white_balance); } if (md.fnumber) { gdouble value; value = g_strtod (md.fnumber, NULL); tracker_sparql_builder_predicate (metadata, "nmm:fnumber"); tracker_sparql_builder_object_double (metadata, value); } if (md.flash) { tracker_sparql_builder_predicate (metadata, "nmm:flash"); tracker_sparql_builder_object (metadata, md.flash); } if (md.focal_length) { gdouble value; value = g_strtod (md.focal_length, NULL); tracker_sparql_builder_predicate (metadata, "nmm:focalLength"); tracker_sparql_builder_object_double (metadata, value); } if (md.artist) { gchar *uri = tracker_sparql_escape_uri_printf ("urn:contact:%s", md.artist); tracker_sparql_builder_insert_open (preupdate, NULL); if (graph) { tracker_sparql_builder_graph_open (preupdate, graph); } tracker_sparql_builder_subject_iri (preupdate, uri); tracker_sparql_builder_predicate (preupdate, "a"); tracker_sparql_builder_object (preupdate, "nco:Contact"); tracker_sparql_builder_predicate (preupdate, "nco:fullname"); tracker_sparql_builder_object_unvalidated (preupdate, md.artist); if (graph) { tracker_sparql_builder_graph_close (preupdate); } tracker_sparql_builder_insert_close (preupdate); tracker_sparql_builder_predicate (metadata, "nco:contributor"); tracker_sparql_builder_object_iri (metadata, uri); g_free (uri); } if (md.exposure_time) { gdouble value; value = g_strtod (md.exposure_time, NULL); tracker_sparql_builder_predicate (metadata, "nmm:exposureTime"); tracker_sparql_builder_object_double (metadata, value); } if (md.iso_speed_ratings) { gdouble value; value = g_strtod (md.iso_speed_ratings, NULL); tracker_sparql_builder_predicate (metadata, "nmm:isoSpeed"); tracker_sparql_builder_object_double (metadata, value); } tracker_guarantee_date_from_file_mtime (metadata, "nie:contentCreated", md.date, uri); if (md.description) { tracker_sparql_builder_predicate (metadata, "nie:description"); tracker_sparql_builder_object_unvalidated (metadata, md.description); } if (md.metering_mode) { tracker_sparql_builder_predicate (metadata, "nmm:meteringMode"); tracker_sparql_builder_object (metadata, md.metering_mode); } if (md.creator) { gchar *uri = tracker_sparql_escape_uri_printf ("urn:contact:%s", md.creator); tracker_sparql_builder_insert_open (preupdate, NULL); if (graph) { tracker_sparql_builder_graph_open (preupdate, graph); } tracker_sparql_builder_subject_iri (preupdate, uri); tracker_sparql_builder_predicate (preupdate, "a"); tracker_sparql_builder_object (preupdate, "nco:Contact"); tracker_sparql_builder_predicate (preupdate, "nco:fullname"); tracker_sparql_builder_object_unvalidated (preupdate, md.creator); if (graph) { tracker_sparql_builder_graph_close (preupdate); } tracker_sparql_builder_insert_close (preupdate); /* NOTE: We only have affiliation with * nco:PersonContact and we are using * nco:Contact here. */ /* if (id->byline_title) { */ /* tracker_sparql_builder_insert_open (preupdate, NULL); */ /* tracker_sparql_builder_subject (preupdate, "_:affiliation_by_line"); */ /* tracker_sparql_builder_predicate (preupdate, "a"); */ /* tracker_sparql_builder_object (preupdate, "nco:Affiliation"); */ /* tracker_sparql_builder_predicate (preupdate, "nco:title"); */ /* tracker_sparql_builder_object_unvalidated (preupdate, id->byline_title); */ /* tracker_sparql_builder_insert_close (preupdate); */ /* tracker_sparql_builder_predicate (preupdate, "a"); */ /* tracker_sparql_builder_object (preupdate, "nco:Contact"); */ /* tracker_sparql_builder_predicate (preupdate, "nco:hasAffiliation"); */ /* tracker_sparql_builder_object (preupdate, "_:affiliation_by_line"); */ /* } */ tracker_sparql_builder_predicate (metadata, "nco:creator"); tracker_sparql_builder_object_iri (metadata, uri); g_free (uri); } if (md.comment) { tracker_sparql_builder_predicate (metadata, "nie:comment"); tracker_sparql_builder_object_unvalidated (metadata, md.comment); } if (md.address || md.state || md.country || md.city || md.gps_altitude || md.gps_latitude || md.gps_longitude) { tracker_sparql_builder_predicate (metadata, "slo:location"); tracker_sparql_builder_object_blank_open (metadata); /* GeoPoint */ tracker_sparql_builder_predicate (metadata, "a"); tracker_sparql_builder_object (metadata, "slo:GeoLocation"); if (md.address || md.state || md.country || md.city) { gchar *addruri; addruri = tracker_sparql_get_uuid_urn (); tracker_sparql_builder_predicate (metadata, "slo:postalAddress"); tracker_sparql_builder_object_iri (metadata, addruri); tracker_sparql_builder_insert_open (preupdate, NULL); if (graph) { tracker_sparql_builder_graph_open (preupdate, graph); } tracker_sparql_builder_subject_iri (preupdate, addruri); g_free (addruri); tracker_sparql_builder_predicate (preupdate, "a"); tracker_sparql_builder_object (preupdate, "nco:PostalAddress"); if (md.address) { tracker_sparql_builder_predicate (preupdate, "nco:streetAddress"); tracker_sparql_builder_object_unvalidated (preupdate, md.address); } if (md.state) { tracker_sparql_builder_predicate (preupdate, "nco:region"); tracker_sparql_builder_object_unvalidated (preupdate, md.state); } if (md.city) { tracker_sparql_builder_predicate (preupdate, "nco:locality"); tracker_sparql_builder_object_unvalidated (preupdate, md.city); } if (md.country) { tracker_sparql_builder_predicate (preupdate, "nco:country"); tracker_sparql_builder_object_unvalidated (preupdate, md.country); } if (graph) { tracker_sparql_builder_graph_close (preupdate); } tracker_sparql_builder_insert_close (preupdate); } if (md.gps_altitude) { tracker_sparql_builder_predicate (metadata, "slo:altitude"); tracker_sparql_builder_object_unvalidated (metadata, md.gps_altitude); } if (md.gps_latitude) { tracker_sparql_builder_predicate (metadata, "slo:latitude"); tracker_sparql_builder_object_unvalidated (metadata, md.gps_latitude); } if (md.gps_longitude) { tracker_sparql_builder_predicate (metadata, "slo:longitude"); tracker_sparql_builder_object_unvalidated (metadata, md.gps_longitude); } tracker_sparql_builder_object_blank_close (metadata); /* GeoLocation */ } if (md.gps_direction) { tracker_sparql_builder_predicate (metadata, "nfo:heading"); tracker_sparql_builder_object_unvalidated (metadata, md.gps_direction); } if (cinfo.density_unit != 0 || ed->x_resolution) { gdouble value; if (cinfo.density_unit == 0) { if (ed->resolution_unit != 3) value = g_strtod (ed->x_resolution, NULL); else value = g_strtod (ed->x_resolution, NULL) * CM_TO_INCH; } else { if (cinfo.density_unit == 1) value = cinfo.X_density; else value = cinfo.X_density * CM_TO_INCH; } tracker_sparql_builder_predicate (metadata, "nfo:horizontalResolution"); tracker_sparql_builder_object_double (metadata, value); } if (cinfo.density_unit != 0 || ed->y_resolution) { gdouble value; if (cinfo.density_unit == 0) { if (ed->resolution_unit != 3) value = g_strtod (ed->y_resolution, NULL); else value = g_strtod (ed->y_resolution, NULL) * CM_TO_INCH; } else { if (cinfo.density_unit == 1) value = cinfo.Y_density; else value = cinfo.Y_density * CM_TO_INCH; } tracker_sparql_builder_predicate (metadata, "nfo:verticalResolution"); tracker_sparql_builder_object_double (metadata, value); } jpeg_destroy_decompress (&cinfo); tracker_exif_free (ed); tracker_xmp_free (xd); tracker_iptc_free (id); g_free (comment); fail: tracker_file_close (f, FALSE); g_free (uri); return success; }
void amp_group_node_update_preset_variable (AmpGroupNode *group) { gchar *path; AnjutaToken *value; AmpVariable *var; GFile *root; GFile *file; AnjutaProjectNode *node; if (group->preset_token != NULL) anjuta_token_free (group->preset_token); group->preset_token = anjuta_token_new_static (ANJUTA_TOKEN_FILE, NULL); /* Get project root */ for (node = ANJUTA_PROJECT_NODE (group); anjuta_project_node_parent (node) != NULL; node = anjuta_project_node_parent (node)); root = anjuta_project_node_get_file (node); /* Set source directory variables */ file = anjuta_project_node_get_file (group); value = anjuta_token_insert_token_list (FALSE, NULL, ANJUTA_TOKEN_LIST, NULL, ANJUTA_TOKEN_ARGUMENT, NULL, ANJUTA_TOKEN_CONTENT, ".", NULL); anjuta_token_append_child (group->preset_token, value); var = amp_variable_new ("srcdir", 0, value); g_hash_table_insert (group->variables, var->name, var); var = amp_variable_new ("builddir", 0, value); g_hash_table_insert (group->variables, var->name, var); path = g_file_get_path (file); value = anjuta_token_insert_token_list (FALSE, NULL, ANJUTA_TOKEN_LIST, NULL, ANJUTA_TOKEN_ARGUMENT, NULL, ANJUTA_TOKEN_CONTENT, path, NULL); g_free (path); anjuta_token_append_child (group->preset_token, value); var = amp_variable_new ("abs_srcdir", 0, value); g_hash_table_insert (group->variables, var->name, var); var = amp_variable_new ("abs_builddir", 0, value); g_hash_table_insert (group->variables, var->name, var); path = get_relative_path (file, root); value = anjuta_token_insert_token_list (FALSE, NULL, ANJUTA_TOKEN_LIST, NULL, ANJUTA_TOKEN_ARGUMENT, NULL, ANJUTA_TOKEN_CONTENT, path, NULL); g_free (path); anjuta_token_append_child (group->preset_token, value); var = amp_variable_new ("top_srcdir", 0, value); g_hash_table_insert (group->variables, var->name, var); var = amp_variable_new ("top_builddir", 0, value); g_hash_table_insert (group->variables, var->name, var); path = g_file_get_path (root); value = anjuta_token_insert_token_list (FALSE, NULL, ANJUTA_TOKEN_LIST, NULL, ANJUTA_TOKEN_ARGUMENT, NULL, ANJUTA_TOKEN_CONTENT, path, NULL); g_free (path); anjuta_token_append_child (group->preset_token, value); var = amp_variable_new ("abs_top_srcdir", 0, value); g_hash_table_insert (group->variables, var->name, var); var = amp_variable_new ("abs_top_builddir", 0, value); g_hash_table_insert (group->variables, var->name, var); }
static void terminal_nautilus_menu_item_activate (NautilusMenuItem *item) { TerminalNautilusMenuItem *menu_item = TERMINAL_NAUTILUS_MENU_ITEM (item); TerminalNautilus *nautilus = menu_item->nautilus; char *uri, *path; TerminalFileInfo info; ExecData *data; uri = nautilus_file_info_get_activation_uri (menu_item->file_info); if (uri == NULL) return; path = NULL; info = get_terminal_file_info_from_uri (uri); switch (info) { case FILE_INFO_LOCAL: path = g_filename_from_uri (uri, NULL, NULL); break; case FILE_INFO_DESKTOP: if (desktop_is_home_dir (nautilus) || desktop_opens_home_dir (nautilus)) { path = g_strdup (g_get_home_dir ()); } else { path = g_strdup (g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP)); } break; case FILE_INFO_SFTP: if (menu_item->remote_terminal) break; /* fall through */ case FILE_INFO_OTHER: { GFile *file; /* map back remote URI to local path */ file = g_file_new_for_uri (uri); path = g_file_get_path (file); g_object_unref (file); break; } default: g_assert_not_reached (); } if (path == NULL && (info != FILE_INFO_SFTP || !menu_item->remote_terminal)) { g_free (uri); return; } data = g_new (ExecData, 1); data->nautilus = g_object_ref (nautilus); data->timestamp = gtk_get_current_event_time (); data->path = path; data->uri = uri; data->display = gdk_screen_make_display_name (menu_item->screen); data->info = info; data->remote = menu_item->remote_terminal; data->run_in_mc = menu_item->run_in_mc; create_terminal (data); }
/** * seahorse_util_uris_package * @package: Package uri * @uris: null-terminated array of uris to package * * Package uris into an archive. The uris must be local. * * Returns: Success or failure */ gboolean seahorse_util_uris_package (const gchar* package, const char** uris) { GError* err = NULL; gchar *out = NULL; gint status; gboolean r; GString *str; gchar *cmd; gchar *t; gchar *x; GFile *file, *fpackage; fpackage = g_file_new_for_uri (package); t = g_file_get_path (fpackage); x = g_shell_quote (t); g_free (t); /* create execution */ str = g_string_new (""); g_string_printf (str, "file-roller --add-to=%s", x); g_free(x); while(*uris) { x = g_uri_parse_scheme (*uris); if (x) file = g_file_new_for_uri (*uris); else file = g_file_new_for_path (*uris); g_free (x); t = g_file_get_path (file); g_object_unref (file); g_return_val_if_fail (t != NULL, FALSE); x = g_shell_quote(t); g_free(t); g_string_append_printf (str, " %s", x); g_free(x); uris++; } /* Execute the command */ cmd = g_string_free (str, FALSE); r = g_spawn_command_line_sync (cmd, &out, NULL, &status, &err); g_free (cmd); if (out) { g_print (out, NULL); g_free (out); } if (!r) { seahorse_util_handle_error (err, _("Couldn't run file-roller")); return FALSE; } if(!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) { seahorse_util_show_error(NULL, _("Couldn't package files"), _("The file-roller process did not complete successfully")); return FALSE; } t = g_file_get_path (fpackage); if (t != NULL) { g_chmod (t, S_IRUSR | S_IWUSR); g_free (t); } return TRUE; }
static void gimp_icons_change_icon_theme (GFile *new_search_path) { GFile *old_search_path = g_file_get_parent (icon_theme_path); if (! default_search_path) default_search_path = gimp_data_directory_file ("icons", NULL); if (! g_file_equal (new_search_path, old_search_path)) { GtkIconTheme *icon_theme = gtk_icon_theme_get_default (); if (g_file_equal (old_search_path, default_search_path)) { /* if the old icon theme is in the default search path, * simply prepend the new theme's path */ gchar *path_str = g_file_get_path (new_search_path); gtk_icon_theme_prepend_search_path (icon_theme, path_str); g_free (path_str); } else { /* if the old theme is not in the default search path, * we need to deal with the search path's first element */ gchar **paths; gint n_paths; gtk_icon_theme_get_search_path (icon_theme, &paths, &n_paths); if (g_file_equal (new_search_path, default_search_path)) { /* when switching to a theme in the default path, remove * the first search path element, the default search path * is still in the search path */ gtk_icon_theme_set_search_path (icon_theme, (const gchar **) paths + 1, n_paths - 1); } else { /* when switching between two non-default search paths, replace * the first element of the search path with the new * theme's path */ g_free (paths[0]); paths[0] = g_file_get_path (new_search_path); gtk_icon_theme_set_search_path (icon_theme, (const gchar **) paths, n_paths); } g_strfreev (paths); } } g_object_unref (old_search_path); }
bool PluginPackage::load() { if (m_isLoaded) { m_loadCount++; return true; } GOwnPtr<gchar> finalPath(g_strdup(m_path.utf8().data())); while (g_file_test(finalPath.get(), G_FILE_TEST_IS_SYMLINK)) { GOwnPtr<GFile> file(g_file_new_for_path(finalPath.get())); GOwnPtr<GFile> dir(g_file_get_parent(file.get())); GOwnPtr<gchar> linkPath(g_file_read_link(finalPath.get(), 0)); GOwnPtr<GFile> resolvedFile(g_file_resolve_relative_path(dir.get(), linkPath.get())); finalPath.set(g_file_get_path(resolvedFile.get())); } // No joke. If there is a netscape component in the path, go back // to the symlink, as flash breaks otherwise. // See http://src.chromium.org/viewvc/chrome/trunk/src/webkit/glue/plugins/plugin_list_posix.cc GOwnPtr<gchar> baseName(g_path_get_basename(finalPath.get())); if (!g_strcmp0(baseName.get(), "libflashplayer.so") && g_strstr_len(finalPath.get(), -1, "/netscape/")) finalPath.set(g_strdup(m_path.utf8().data())); m_module = g_module_open(finalPath.get(), G_MODULE_BIND_LOCAL); if (!m_module) { LOG(Plugins,"Module Load Failed :%s, Error:%s\n", (m_path.utf8()).data(), g_module_error()); return false; } m_isLoaded = true; NP_InitializeFuncPtr NP_Initialize = 0; m_NPP_Shutdown = 0; NPError npErr; g_module_symbol(m_module, "NP_Initialize", (void**)&NP_Initialize); g_module_symbol(m_module, "NP_Shutdown", (void**)&m_NPP_Shutdown); if (!NP_Initialize || !m_NPP_Shutdown) goto abort; memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs)); m_pluginFuncs.size = sizeof(m_pluginFuncs); initializeBrowserFuncs(); #if defined(XP_UNIX) npErr = NP_Initialize(&m_browserFuncs, &m_pluginFuncs); #else npErr = NP_Initialize(&m_browserFuncs); #endif if (npErr != NPERR_NO_ERROR) goto abort; m_loadCount++; return true; abort: unloadWithoutShutdown(); return false; }
int main (int argc, char **argv) { GarconMenuParser *parser; GarconMenuMerger *merger; const gchar *prefix; GError *error = NULL; GFile *file = NULL; gchar *filename; gchar *relative_filename; gint result = EXIT_SUCCESS; #if !GLIB_CHECK_VERSION (2, 36, 0) /* Initialize the type system */ g_type_init (); #endif #if !GLIB_CHECK_VERSION(2,32,0) if (!g_thread_supported ()) g_thread_init (NULL); #endif garcon_set_environment ("XFCE"); if (argc > 1) file = g_file_new_for_path (argv[1]); else { prefix = g_getenv ("XDG_MENU_PREFIX"); relative_filename = g_strconcat ("menus", G_DIR_SEPARATOR_S, prefix != NULL ? prefix : "", "applications.menu", NULL); /* Search for the menu file */ filename = garcon_config_lookup (relative_filename); if (G_UNLIKELY (filename != NULL)) { /* Try to load the root menu from this file */ file = g_file_new_for_path (filename); g_free (filename); if (!g_file_query_exists (file, NULL)) { g_object_unref (file); file = NULL; } } g_free (relative_filename); } filename = g_file_get_path (file); g_print ("\nread menu from \"%s\"\n", filename); g_free (filename); parser = garcon_menu_parser_new (file); g_object_unref (file); if (G_LIKELY (garcon_menu_parser_run (parser, NULL, &error))) { g_print("\n\nafter parsing:\n\n"); print_tree (GARCON_MENU_TREE_PROVIDER (parser)); merger = garcon_menu_merger_new (GARCON_MENU_TREE_PROVIDER (parser)); if (G_LIKELY (garcon_menu_merger_run (merger, NULL, NULL, NULL, &error))) { g_print ("\n\nafter merging:\n\n"); print_tree (GARCON_MENU_TREE_PROVIDER (merger)); } else { if (error != NULL) { g_error ("Could not merge menus in %s: %s", argc > 1 ? argv[1] : FILENAME, error->message); g_error_free (error); } result = EXIT_FAILURE; } g_object_unref (merger); } else { if (error != NULL) { g_error ("Could not parse %s: %s", argc > 1 ? argv[1] : FILENAME, error->message); g_error_free (error); } result = EXIT_FAILURE; } g_object_unref (parser); return result; }
/** * rb_device_source_want_uri: * @source: a #RBDeviceSource * @uri: a URI to consider * * Checks whether @uri identifies a path underneath the * device's mount point. Should be used to implement * the #RBSource want_uri method. * * Return value: URI match strength */ guint rb_device_source_want_uri (RBSource *source, const char *uri) { GMount *mount = NULL; GVolume *volume = NULL; GFile *file; char *device_path, *uri_path; int retval; int len; retval = 0; file = g_file_new_for_uri (uri); /* Deal with the mount root being passed, eg. file:///media/IPODNAME */ if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "mount")) { g_object_get (source, "mount", &mount, NULL); } if (mount != NULL) { GFile *root; root = g_mount_get_root (mount); retval = g_file_equal (root, file) ? 100 : 0; g_object_unref (root); if (retval) { g_object_unref (file); g_object_unref (mount); return retval; } volume = g_mount_get_volume (mount); g_object_unref (mount); } else { if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "volume")) { g_object_get (source, "volume", &volume, NULL); } } /* ignore anything that isn't a local file or doesn't have a volume */ if (g_file_has_uri_scheme (file, "file") == FALSE || volume == NULL) { g_object_unref (file); return 0; } /* Deal with the path to the device node being passed */ device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); g_object_unref (volume); if (device_path == NULL) { g_object_unref (file); return 0; } uri_path = g_file_get_path (file); g_object_unref (file); if (uri_path == NULL) return 0; len = strlen (uri_path); if (uri_path[len - 1] == '/') { if (strncmp (uri_path, device_path, len - 1) == 0) { retval = 100; } } else if (strcmp (uri_path, device_path) == 0) { retval = 100; } g_free (device_path); g_free (uri_path); return retval; }
static void trash_item_get_trashinfo (GFile *path, GFile **original, char **date) { GFile *files, *trashdir; GKeyFile *keyfile; char *trashpath; char *trashinfo; char *basename; files = g_file_get_parent (path); trashdir = g_file_get_parent (files); trashpath = g_file_get_path (trashdir); g_object_unref (files); basename = g_file_get_basename (path); trashinfo = g_strdup_printf ("%s/info/%s.trashinfo", trashpath, basename); g_free (trashpath); g_free (basename); keyfile = g_key_file_new (); *original = NULL; *date = NULL; if (g_key_file_load_from_file (keyfile, trashinfo, 0, NULL)) { char *orig, *decoded; decoded = NULL; orig = g_key_file_get_string (keyfile, "Trash Info", "Path", NULL); if (orig == NULL) *original = NULL; else { decoded = g_uri_unescape_string (orig, NULL); if (g_path_is_absolute (decoded)) *original = g_file_new_for_path (decoded); else { GFile *rootdir; rootdir = g_file_get_parent (trashdir); *original = g_file_get_child (rootdir, decoded); g_object_unref (rootdir); } g_free (decoded); } g_free (orig); *date = g_key_file_get_string (keyfile, "Trash Info", "DeletionDate", NULL); } g_object_unref (trashdir); g_key_file_free (keyfile); g_free (trashinfo); }
static void set_background (CcBackgroundPanel *panel, CcBackgroundItem *item) { CcBackgroundPanelPrivate *priv = panel->priv; GDesktopBackgroundStyle style; gboolean save_settings = TRUE; const char *uri; CcBackgroundItemFlags flags; char *filename; if (item == NULL) return; uri = cc_background_item_get_uri (item); flags = cc_background_item_get_flags (item); if ((flags & CC_BACKGROUND_ITEM_HAS_URI) && uri == NULL) { g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, G_DESKTOP_BACKGROUND_STYLE_NONE); g_settings_set_string (priv->settings, WP_URI_KEY, ""); } else if (cc_background_item_get_source_url (item) != NULL && cc_background_item_get_needs_download (item)) { GFile *source, *dest; char *cache_path, *basename, *dest_path, *display_name, *dest_uri; GdkPixbuf *pixbuf; cache_path = bg_pictures_source_get_cache_path (); if (g_mkdir_with_parents (cache_path, 0755) < 0) { g_warning ("Failed to create directory '%s'", cache_path); g_free (cache_path); return; } g_free (cache_path); dest_path = bg_pictures_source_get_unique_path (cc_background_item_get_source_url (item)); dest = g_file_new_for_path (dest_path); g_free (dest_path); source = g_file_new_for_uri (cc_background_item_get_source_url (item)); basename = g_file_get_basename (source); display_name = g_filename_display_name (basename); dest_path = g_file_get_path (dest); g_free (basename); /* create a blank image to use until the source image is ready */ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1); gdk_pixbuf_fill (pixbuf, 0x00000000); gdk_pixbuf_save (pixbuf, dest_path, "png", NULL, NULL); g_object_unref (pixbuf); g_free (dest_path); if (priv->copy_cancellable) { g_cancellable_cancel (priv->copy_cancellable); g_cancellable_reset (priv->copy_cancellable); } if (priv->spinner) { gtk_widget_destroy (GTK_WIDGET (priv->spinner)); priv->spinner = NULL; } /* create a spinner while the file downloads */ priv->spinner = gtk_spinner_new (); gtk_spinner_start (GTK_SPINNER (priv->spinner)); gtk_box_pack_start (GTK_BOX (WID ("bottom-hbox")), priv->spinner, FALSE, FALSE, 6); gtk_widget_show (priv->spinner); /* reference the panel in case it is removed before the copy is * finished */ g_object_ref (panel); g_object_set_data_full (G_OBJECT (source), "item", g_object_ref (item), g_object_unref); g_file_copy_async (source, dest, G_FILE_COPY_OVERWRITE, G_PRIORITY_DEFAULT, priv->copy_cancellable, NULL, NULL, copy_finished_cb, panel); g_object_unref (source); dest_uri = g_file_get_uri (dest); g_object_unref (dest); g_settings_set_string (priv->settings, WP_URI_KEY, dest_uri); g_object_set (G_OBJECT (item), "uri", dest_uri, "needs-download", FALSE, "name", display_name, NULL); g_free (display_name); g_free (dest_uri); /* delay the updated drawing of the preview until the copy finishes */ save_settings = FALSE; } else { g_settings_set_string (priv->settings, WP_URI_KEY, uri); } /* Also set the placement if we have a URI and the previous value was none */ if (flags & CC_BACKGROUND_ITEM_HAS_PLACEMENT) { g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, cc_background_item_get_placement (item)); } else if (uri != NULL) { style = g_settings_get_enum (priv->settings, WP_OPTIONS_KEY); if (style == G_DESKTOP_BACKGROUND_STYLE_NONE) g_settings_set_enum (priv->settings, WP_OPTIONS_KEY, cc_background_item_get_placement (item)); } if (flags & CC_BACKGROUND_ITEM_HAS_SHADING) g_settings_set_enum (priv->settings, WP_SHADING_KEY, cc_background_item_get_shading (item)); g_settings_set_string (priv->settings, WP_PCOLOR_KEY, cc_background_item_get_pcolor (item)); g_settings_set_string (priv->settings, WP_SCOLOR_KEY, cc_background_item_get_scolor (item)); /* update the preview information */ if (save_settings != FALSE) { /* Apply all changes */ g_settings_apply (priv->settings); /* Save the source XML if there is one */ filename = get_save_path (); if (create_save_dir ()) cc_background_xml_save (priv->current_background, filename); } }
/* * Recurse the path to create a list of files. Return a GList of the files found. */ static GList * read_directory_recursively (GList *file_list, GFileEnumerator *dir_enumerator, gboolean recurse) { GError *error = NULL; GFileInfo *info; const char *file_name; gboolean is_hidden; GFileType type; g_return_val_if_fail (dir_enumerator != NULL, file_list); while ((info = g_file_enumerator_next_file (dir_enumerator, NULL, &error)) != NULL) { if (Main_Stop_Button_Pressed) { g_object_unref (info); return file_list; } file_name = g_file_info_get_name (info); is_hidden = g_file_info_get_is_hidden (info); type = g_file_info_get_file_type (info); /* Hidden directory like '.mydir' will also be browsed if allowed. */ if (!is_hidden || (g_settings_get_boolean (MainSettings, "browse-show-hidden") && is_hidden)) { if (type == G_FILE_TYPE_DIRECTORY) { if (recurse) { /* Searching for files recursively. */ GFile *child_dir = g_file_enumerator_get_child (dir_enumerator, info); GFileEnumerator *childdir_enumerator; GError *child_error = NULL; childdir_enumerator = g_file_enumerate_children (child_dir, G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN, G_FILE_QUERY_INFO_NONE, NULL, &child_error); if (!childdir_enumerator) { gchar *child_path; gchar *display_path; child_path = g_file_get_path (child_dir); display_path = g_filename_display_name (child_path); Log_Print (LOG_ERROR, _("Error opening directory ‘%s’: %s"), display_path, child_error->message); g_free (display_path); g_free (child_path); g_error_free (child_error); g_object_unref (child_dir); g_object_unref (info); continue; } file_list = read_directory_recursively (file_list, childdir_enumerator, recurse); g_object_unref (child_dir); g_file_enumerator_close (childdir_enumerator, NULL, &error); g_object_unref (childdir_enumerator); } } else if (type == G_FILE_TYPE_REGULAR && et_file_is_supported (file_name)) { GFile *file = g_file_enumerator_get_child (dir_enumerator, info); file_list = g_list_append (file_list, file); } // Just to not block X events while (gtk_events_pending()) gtk_main_iteration(); } g_object_unref (info); } if (error) { Log_Print (LOG_ERROR, _("Cannot read directory ‘%s’"), error->message); g_error_free (error); } return file_list; }
static void write_button_clicked (EtPlaylistDialog *self) { EtPlaylistDialogPrivate *priv; gchar *playlist_name = NULL; gchar *playlist_path_utf8; // Path gchar *playlist_basename_utf8; // Filename gchar *playlist_name_utf8; // Path + filename gchar *temp; GtkWidget *msgdialog; priv = et_playlist_dialog_get_instance_private (self); /* Check if playlist name was filled. */ if (g_settings_get_boolean (MainSettings, "playlist-use-mask") && *(gtk_entry_get_text (GTK_ENTRY (priv->name_mask_entry))) == '\0') { /* TODO: Can this happen? */ g_settings_set_boolean (MainSettings, "playlist-use-mask", FALSE); } // Path of the playlist file (may be truncated later if PLAYLIST_CREATE_IN_PARENT_DIR is TRUE) temp = g_file_get_path (et_application_window_get_current_path (ET_APPLICATION_WINDOW (MainWindow))); playlist_path_utf8 = g_filename_display_name (temp); g_free (temp); /* Build the playlist filename. */ if (g_settings_get_boolean (MainSettings, "playlist-use-mask")) { EtConvertSpaces convert_mode; if (!ETCore->ETFileList) return; playlist_name = g_settings_get_string (MainSettings, "playlist-filename-mask"); /* Generate filename from tag of the current selected file (FIXME). */ temp = filename_from_display (playlist_name); g_free (playlist_name); playlist_basename_utf8 = et_scan_generate_new_filename_from_mask (ETCore->ETFileDisplayed, temp, FALSE); g_free (temp); /* Replace Characters (with scanner). */ convert_mode = g_settings_get_enum (MainSettings, "rename-convert-spaces"); switch (convert_mode) { case ET_CONVERT_SPACES_SPACES: Scan_Convert_Underscore_Into_Space (playlist_basename_utf8); Scan_Convert_P20_Into_Space (playlist_basename_utf8); break; case ET_CONVERT_SPACES_UNDERSCORES: Scan_Convert_Space_Into_Underscore (playlist_basename_utf8); break; case ET_CONVERT_SPACES_REMOVE: Scan_Remove_Spaces (playlist_basename_utf8); break; /* FIXME: Check that this is intended. */ case ET_CONVERT_SPACES_NO_CHANGE: default: g_assert_not_reached (); break; } }else // PLAYLIST_USE_DIR_NAME { if ( strcmp(playlist_path_utf8,G_DIR_SEPARATOR_S)==0 ) { playlist_basename_utf8 = g_strdup("playlist"); }else { gchar *tmp_string = g_strdup(playlist_path_utf8); // Remove last '/' if (tmp_string[strlen(tmp_string)-1]==G_DIR_SEPARATOR) tmp_string[strlen(tmp_string)-1] = '\0'; // Get directory name temp = g_path_get_basename(tmp_string); playlist_basename_utf8 = g_strdup(temp); g_free(tmp_string); g_free(temp); } } /* Must be placed after "Build the playlist filename", as we can truncate * the path! */ if (g_settings_get_boolean (MainSettings, "playlist-parent-directory")) { if ( (strcmp(playlist_path_utf8,G_DIR_SEPARATOR_S) != 0) ) { gchar *tmp; // Remove last '/' if (playlist_path_utf8[strlen(playlist_path_utf8)-1]==G_DIR_SEPARATOR) playlist_path_utf8[strlen(playlist_path_utf8)-1] = '\0'; // Get parent directory if ( (tmp=strrchr(playlist_path_utf8,G_DIR_SEPARATOR)) != NULL ) *(tmp + 1) = '\0'; } } // Generate path + filename of playlist if (playlist_path_utf8[strlen(playlist_path_utf8)-1]==G_DIR_SEPARATOR) playlist_name_utf8 = g_strconcat(playlist_path_utf8,playlist_basename_utf8,".m3u",NULL); else playlist_name_utf8 = g_strconcat(playlist_path_utf8,G_DIR_SEPARATOR_S,playlist_basename_utf8,".m3u",NULL); g_free(playlist_path_utf8); g_free(playlist_basename_utf8); playlist_name = filename_from_display(playlist_name_utf8); { GFile *file = g_file_new_for_path (playlist_name); GError *error = NULL; if (!write_playlist (self, file, &error)) { // Writing fails... msgdialog = gtk_message_dialog_new (GTK_WINDOW (self), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Cannot write playlist file ‘%s’"), playlist_name_utf8); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msgdialog), "%s", error->message); gtk_window_set_title(GTK_WINDOW(msgdialog),_("Playlist File Error")); gtk_dialog_run(GTK_DIALOG(msgdialog)); gtk_widget_destroy(msgdialog); g_error_free (error); }else { gchar *msg; msg = g_strdup_printf (_("Wrote playlist file ‘%s’"), playlist_name_utf8); et_application_window_status_bar_message (ET_APPLICATION_WINDOW (MainWindow), msg, TRUE); g_free (msg); } g_object_unref (file); } g_free(playlist_name_utf8); g_free(playlist_name); }
/* * info_mac_read: * @file: file from which to read a header * @stream_info: stream information to fill * @error: a #GError, or NULL * * Read the header information from a Monkey's Audio file. * * Returns: %TRUE on success, or %FALSE and with @error set on failure */ gboolean info_mac_read (GFile *file, StreamInfoMac *stream_info, GError **error) { GFileInfo *info; GFileInputStream *istream; guint8 header_buffer[MAC_FORMAT_HEADER_LENGTH]; gsize bytes_read; gsize size_id3; struct macHeader *header; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, error); if (!info) { return FALSE; } stream_info->FileSize = g_file_info_get_size (info); g_object_unref (info); istream = g_file_read (file, NULL, error); if (!istream) { return FALSE; } /* FIXME: is_id3v2() should accept an istream or a GFile. */ { gchar *path; FILE *fp; path = g_file_get_path (file); fp = g_fopen (path, "rb"); if (!fp) { /* TODO: Add specific error domain and message. */ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, "%s", g_strerror (EINVAL)); g_free (path); return FALSE; } size_id3 = is_id3v2 (fp); fclose (fp); g_free (path); } if (!g_seekable_seek (G_SEEKABLE (istream), size_id3, G_SEEK_SET, NULL, error)) { return FALSE; } if (!g_input_stream_read_all (G_INPUT_STREAM (istream), header_buffer, MAC_FORMAT_HEADER_LENGTH, &bytes_read, NULL, error)) { g_debug ("Only %" G_GSIZE_FORMAT " bytes out of 16 bytes of data were " "read", bytes_read); return FALSE; } if (memcmp (header_buffer, "MAC", 3) != 0) { /* TODO: Add specific error domain and message. */ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, "%s", g_strerror (EINVAL)); return FALSE; // no monkeyAudio file } header = (struct macHeader *) header_buffer; stream_info->Version = stream_info->EncoderVersion = header->ver; stream_info->Channels = header->channels; stream_info->SampleFreq = header->sampleRate; stream_info->Flags = header->formatFlags; stream_info->SamplesPerFrame = monkey_samples_per_frame(header->ver, header->compLevel); stream_info->BitsPerSample = (header->formatFlags & MAC_FORMAT_FLAG_8_BIT) ? 8 : ((header->formatFlags & MAC_FORMAT_FLAG_24_BIT) ? 24 : 16); stream_info->PeakLevel = header->peakLevel; // Info->PeakRatio = Info->PakLevel / pow(2, Info->bitsPerSample - 1); stream_info->Frames = header->totalFrames; stream_info->Samples = (stream_info->Frames - 1) * stream_info->SamplesPerFrame + header->finalFrameBlocks; stream_info->Duration = stream_info -> SampleFreq > 0 ? ((float)stream_info->Samples / stream_info->SampleFreq) * 1000 : 0; stream_info->Compresion = header->compLevel; stream_info->CompresionName = monkey_stringify (stream_info->Compresion); stream_info->UncompresedSize = stream_info->Samples * stream_info->Channels * (stream_info->BitsPerSample / 8); stream_info->CompresionRatio = (stream_info->UncompresedSize + header->headerBytesWAV) > 0 ? stream_info->FileSize / (float) (stream_info->UncompresedSize + header->headerBytesWAV) : 0.; stream_info->Bitrate = stream_info->Duration > 0 ? (((stream_info->Samples * stream_info->Channels * stream_info->BitsPerSample) / (float) stream_info->Duration) * stream_info->CompresionRatio) * 1000 : 0; stream_info->PeakRatio = stream_info->ByteLength = 0; return TRUE; }
static void gb_view_source_set_file_attribs (GbViewSource *source, GFile *file) { GtkSourceLanguageManager *lm; GbViewSourcePrivate *priv; GtkSourceLanguage *lang; const gchar *icon_name; GFileInfo *info; gchar *path; ENTRY; g_return_if_fail(GB_IS_VIEW_SOURCE(source)); g_return_if_fail(G_IS_FILE(file)); priv = source->priv; if (!(path = g_file_get_path(file))) { path = g_file_get_uri(file); } if ((icon_name = gb_path_get_icon_name(path))) { gb_view_set_icon_name(GB_VIEW(source), icon_name); } info = g_file_query_info(file, "standard::*", 0, NULL, NULL); /* * Get the relative path to the file from the project. */ { const gchar *directory; GtkWidget *window; GbProject *project; gb_view_set_name(GB_VIEW(source), path); window = gtk_widget_get_toplevel(GTK_WIDGET(source)); if (GB_IS_WINDOW(window)) { project = gb_window_get_project(GB_WINDOW(window)); directory = gb_project_get_directory(project); if (g_str_has_prefix(path, directory)) { gb_view_set_name(GB_VIEW(source), path + strlen(directory)); } } } lm = gtk_source_language_manager_get_default(); lang = gtk_source_language_manager_guess_language( lm, path, g_file_info_get_content_type(info)); if (lang) { gb_menu_button_set_label(GB_MENU_BUTTON(priv->lang_combo), gtk_source_language_get_name(lang)); } else { gb_menu_button_set_label(GB_MENU_BUTTON(priv->lang_combo), ""); } gtk_source_buffer_set_language(priv->buffer, lang); g_object_unref(info); g_free(path); EXIT; }