static void brasero_track_image_cfg_get_info_thread (GSimpleAsyncResult *result, GObject *object, GCancellable *cancel) { BraseroTrackImageInfo *info; GError *error = NULL; info = g_simple_async_result_get_op_res_gpointer (result); if (info->format == BRASERO_IMAGE_FORMAT_NONE) { GFile *file; const gchar *mime; GFileInfo *file_info; /* check if we do have a URI */ file = g_file_new_for_commandline_arg (info->uri); file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, cancel, &error); g_object_unref (file); if (!file_info) { if (error && !g_cancellable_is_cancelled (cancel)) g_simple_async_result_set_from_error (result, error); if (error) g_error_free (error); return; } mime = g_file_info_get_content_type (file_info); if (mime && (!strcmp (mime, "application/x-toc") || !strcmp (mime, "application/x-cdrdao-toc") || !strcmp (mime, "application/x-cue"))) { info->format = brasero_image_format_identify_cuesheet (info->uri, cancel, &error); if (error) { if (!g_cancellable_is_cancelled (cancel)) g_simple_async_result_set_from_error (result, error); g_error_free (error); g_object_unref (file_info); return; } if (info->format == BRASERO_IMAGE_FORMAT_NONE && g_str_has_suffix (info->uri, ".toc")) info->format = BRASERO_IMAGE_FORMAT_CLONE; } else if (mime && !strcmp (mime, "application/octet-stream")) { /* that could be an image, so here is the deal: * if we can find the type through the extension, fine. * if not default to BIN */ if (g_str_has_suffix (info->uri, ".bin")) info->format = BRASERO_IMAGE_FORMAT_CDRDAO; else if (g_str_has_suffix (info->uri, ".raw")) info->format = BRASERO_IMAGE_FORMAT_CLONE; else info->format = BRASERO_IMAGE_FORMAT_BIN; } else if (mime && !strcmp (mime, "application/x-cd-image")) info->format = BRASERO_IMAGE_FORMAT_BIN; g_object_unref (file_info); } if (info->format == BRASERO_IMAGE_FORMAT_NONE) return; if (info->format == BRASERO_IMAGE_FORMAT_BIN) brasero_image_format_get_iso_size (info->uri, &info->blocks, NULL, cancel, &error); else if (info->format == BRASERO_IMAGE_FORMAT_CLONE) { gchar *complement; complement = brasero_image_format_get_complement (BRASERO_IMAGE_FORMAT_CLONE, info->uri); brasero_image_format_get_clone_size (complement, &info->blocks, NULL, cancel, &error); } else if (info->format == BRASERO_IMAGE_FORMAT_CDRDAO) brasero_image_format_get_cdrdao_size (info->uri, &info->blocks, NULL, cancel, &error); else if (info->format == BRASERO_IMAGE_FORMAT_CUE) brasero_image_format_get_cue_size (info->uri, &info->blocks, NULL, cancel, &error); if (error && !g_cancellable_is_cancelled (cancel)) g_simple_async_result_set_from_error (result, error); if (error) g_error_free (error); }
static gboolean exo_open_uri (const gchar *uri, GError **error) { GFile *file; gchar *scheme; GFileInfo *file_info; gboolean succeed = FALSE; gboolean retval = FALSE; GFileType file_type; const gchar *content_type; GAppInfo *app_info; gchar *path; const gchar *executable; GList fake_list; const gchar * const *schemes; GError *err = NULL; guint i; g_return_val_if_fail (uri != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); #ifndef NDEBUG schemes = g_vfs_get_supported_uri_schemes (g_vfs_get_default ()); scheme = g_strjoinv (", ", (gchar **) schemes); g_debug ("vfs supported schemes: %s", scheme); g_free (scheme); #endif file = g_file_new_for_uri (uri); scheme = g_file_get_uri_scheme (file); /* try to launch common schemes for know preferred applications */ if (scheme != NULL && exo_open_uri_known_category (uri, scheme, &retval)) { g_free (scheme); return retval; } /* handle the uri as a file, maybe we succeed... */ file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, &err); if (file_info != NULL) { file_type = g_file_info_get_file_type (file_info); if (file_type == G_FILE_TYPE_DIRECTORY) { #ifndef NDEBUG g_debug ("file is directory, use filemanager"); #endif /* directories should go fine with a file manager */ retval = exo_open_launch_category ("FileManager", uri); succeed = TRUE; } else { content_type = g_file_info_get_content_type (file_info); #ifndef NDEBUG g_debug ("content type=%s", content_type); #endif if (G_LIKELY (content_type)) { /* try to find a suitable application for this content type */ path = g_file_get_path (file); app_info = g_app_info_get_default_for_type (content_type, path == NULL); g_free (path); if (app_info != NULL) { /* make sure we don't loop somehow */ executable = g_app_info_get_executable (app_info); #ifndef NDEBUG g_debug ("default executable=%s", executable); #endif if (executable == NULL || strcmp (executable, "exo-open") != 0) { fake_list.data = (gpointer) uri; fake_list.prev = fake_list.next = NULL; /* launch it */ retval = g_app_info_launch_uris (app_info, &fake_list, NULL, &err); succeed = TRUE; } g_object_unref (G_OBJECT (app_info)); } } } g_object_unref (G_OBJECT (file_info)); } else if (err != NULL && scheme != NULL && err->code == G_IO_ERROR_NOT_MOUNTED) { /* check if the scheme is supported by gio */ schemes = g_vfs_get_supported_uri_schemes (g_vfs_get_default ()); if (G_LIKELY (schemes != NULL)) { for (i = 0; schemes[i] != NULL; i++) { /* found scheme, open in file manager */ if (strcmp (scheme, schemes[i]) == 0) { retval = succeed = exo_open_launch_category ("FileManager", uri); break; } } } } g_object_unref (G_OBJECT (file)); /* our last try... */ if (!succeed) { #ifndef NDEBUG g_debug ("nothing worked, try ftp(s) or gtk_show_uri()"); #endif /* try ftp uris if the file manager/gio failed to recognize it */ if (scheme != NULL && (strcmp (scheme, "ftp") == 0 || strcmp (scheme, "ftps") == 0)) retval = exo_open_launch_category ("WebBrowser", uri); else retval = gtk_show_uri (NULL, uri, 0, error); } g_free (scheme); if (!retval && error != NULL) *error = err; else if (err != NULL) g_error_free (err); return retval; }
static void add_face_info(GtkWidget *table, gint *row_p, const gchar *uri, FT_Face face) { gchar *s; GFile *file; GFileInfo *info; PS_FontInfoRec ps_info; add_row(table, row_p, _("Name:"), face->family_name, FALSE, FALSE); if (face->style_name) add_row(table, row_p, _("Style:"), face->style_name, FALSE, FALSE); file = g_file_new_for_uri (uri); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (file); if (info) { s = g_content_type_get_description (g_file_info_get_content_type (info)); add_row (table, row_p, _("Type:"), s, FALSE, FALSE); g_free (s); s = g_format_size (g_file_info_get_size (info)); add_row (table, row_p, _("Size:"), s, FALSE, FALSE); g_free (s); g_object_unref (info); } if (FT_IS_SFNT(face)) { gint i, len; gchar *version = NULL, *copyright = NULL, *description = NULL; len = FT_Get_Sfnt_Name_Count(face); for (i = 0; i < len; i++) { FT_SfntName sname; if (FT_Get_Sfnt_Name(face, i, &sname) != 0) continue; /* only handle the unicode names for US langid */ if (!(sname.platform_id == TT_PLATFORM_MICROSOFT && sname.encoding_id == TT_MS_ID_UNICODE_CS && sname.language_id == TT_MS_LANGID_ENGLISH_UNITED_STATES)) continue; switch (sname.name_id) { case TT_NAME_ID_COPYRIGHT: g_free(copyright); copyright = g_convert((gchar *)sname.string, sname.string_len, "UTF-8", "UTF-16BE", NULL, NULL, NULL); break; case TT_NAME_ID_VERSION_STRING: g_free(version); version = g_convert((gchar *)sname.string, sname.string_len, "UTF-8", "UTF-16BE", NULL, NULL, NULL); break; case TT_NAME_ID_DESCRIPTION: g_free(description); description = g_convert((gchar *)sname.string, sname.string_len, "UTF-8", "UTF-16BE", NULL, NULL, NULL); break; default: break; } } if (version) { add_row(table, row_p, _("Version:"), version, FALSE, FALSE); g_free(version); } if (copyright) { add_row(table, row_p, _("Copyright:"), copyright, TRUE, TRUE); g_free(copyright); } if (description) { add_row(table, row_p, _("Description:"), description, TRUE, TRUE); g_free(description); } } else if (FT_Get_PS_Font_Info(face, &ps_info) == 0) { if (ps_info.version && g_utf8_validate(ps_info.version, -1, NULL)) add_row(table, row_p, _("Version:"), ps_info.version, FALSE, FALSE); if (ps_info.notice && g_utf8_validate(ps_info.notice, -1, NULL)) add_row(table, row_p, _("Copyright:"), ps_info.notice, TRUE, FALSE); } }
static gboolean cheese_thumb_view_idle_append_item (gpointer data) { CheeseThumbViewIdleData *item = g_queue_peek_head (data); CheeseThumbView *thumb_view; CheeseThumbViewPrivate *priv; /* Disconnect the idle handler when the queue is empty. */ if (item == NULL) return FALSE; thumb_view = item->thumb_view; priv = cheese_thumb_view_get_instance_private (thumb_view); GnomeDesktopThumbnailFactory *factory = priv->factory; GFile *file = item->file; GtkTreeIter iter = item->iter; GdkPixbuf *pixbuf = NULL; GFileInfo *info; char *thumb_loc; GTimeVal mtime; char *mime_type; char *uri; char *filename; info = g_file_query_info (file, "standard::content-type,time::modified", 0, NULL, NULL); if (!info) { g_warning ("Invalid filename\n"); return TRUE; } g_file_info_get_modification_time (info, &mtime); mime_type = g_strdup (g_file_info_get_content_type (info)); uri = g_file_get_uri (file); filename = g_file_get_path (file); thumb_loc = gnome_desktop_thumbnail_factory_lookup (factory, uri, mtime.tv_sec); if (!thumb_loc) { pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (factory, uri, mime_type); if (!pixbuf) { g_warning ("could not generate thumbnail for %s (%s)\n", filename, mime_type); } else { gnome_desktop_thumbnail_factory_save_thumbnail (factory, pixbuf, uri, mtime.tv_sec); } } else { pixbuf = gdk_pixbuf_new_from_file (thumb_loc, NULL); if (!pixbuf) { g_warning ("could not load thumbnail %s (%s)\n", filename, mime_type); } } g_object_unref (info); g_free (thumb_loc); g_free (uri); if (!pixbuf) { gchar *escape = NULL; GError *error = NULL; escape = g_strrstr (mime_type, "/"); if (escape != NULL) *escape = '-'; pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), mime_type, 96, GTK_ICON_LOOKUP_GENERIC_FALLBACK, &error); if (error) { g_warning ("%s", error->message); return TRUE; } } else { cheese_thumbnail_add_frame (&pixbuf); } gtk_list_store_set (priv->store, &iter, THUMBNAIL_PIXBUF_COLUMN, pixbuf, -1); g_free (mime_type); g_free (filename); g_object_unref (pixbuf); g_object_unref (file); g_slice_free (CheeseThumbViewIdleData, item); g_queue_pop_head (data); return TRUE; }
static void update_chooser_preview (GtkFileChooser *chooser, CcBackgroundPanel *panel) { GnomeDesktopThumbnailFactory *thumb_factory; char *uri; thumb_factory = panel->priv->thumb_factory; uri = gtk_file_chooser_get_preview_uri (chooser); if (uri) { GdkPixbuf *pixbuf = NULL; const gchar *mime_type = NULL; GFile *file; GFileInfo *file_info; GtkWidget *preview; preview = gtk_file_chooser_get_preview_widget (chooser); file = g_file_new_for_uri (uri); file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (file); if (file_info != NULL) { mime_type = g_file_info_get_content_type (file_info); g_object_unref (file_info); } if (mime_type) { pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (thumb_factory, uri, mime_type); } gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT, (pixbuf != NULL)); if (pixbuf != NULL) { gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf); g_object_unref (pixbuf); } else { gtk_image_set_from_stock (GTK_IMAGE (preview), GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); } if (bg_pictures_source_is_known (panel->priv->pictures_source, uri)) gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT, FALSE); else gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT, TRUE); g_free (uri); } gtk_file_chooser_set_preview_widget_active (chooser, TRUE); }
static void file_monitor_changed_cb (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event, EogListStore *store) { const char *mimetype; GFileInfo *file_info; GtkTreeIter iter; EogImage *image; switch (event) { case G_FILE_MONITOR_EVENT_CHANGED: file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, NULL); if (file_info == NULL) { break; } mimetype = g_file_info_get_content_type (file_info); if (is_file_in_list_store_file (store, file, &iter)) { if (eog_image_is_supported_mime_type (mimetype)) { gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, EOG_LIST_STORE_EOG_IMAGE, &image, -1); eog_image_file_changed (image); g_object_unref (image); eog_list_store_thumbnail_refresh (store, &iter); } else { eog_list_store_remove (store, &iter); } } else { if (eog_image_is_supported_mime_type (mimetype)) { eog_list_store_append_image_from_file (store, file); } } g_object_unref (file_info); break; case G_FILE_MONITOR_EVENT_DELETED: if (is_file_in_list_store_file (store, file, &iter)) { EogImage *image; gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, EOG_LIST_STORE_EOG_IMAGE, &image, -1); eog_list_store_remove (store, &iter); } break; case G_FILE_MONITOR_EVENT_CREATED: if (!is_file_in_list_store_file (store, file, NULL)) { file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, NULL); if (file_info == NULL) { break; } mimetype = g_file_info_get_content_type (file_info); if (eog_image_is_supported_mime_type (mimetype)) { eog_list_store_append_image_from_file (store, file); } g_object_unref (file_info); } break; case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED: file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, NULL); if (file_info == NULL) { break; } mimetype = g_file_info_get_content_type (file_info); if (is_file_in_list_store_file (store, file, &iter) && eog_image_is_supported_mime_type (mimetype)) { eog_list_store_thumbnail_refresh (store, &iter); } g_object_unref (file_info); break; case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: case G_FILE_MONITOR_EVENT_PRE_UNMOUNT: case G_FILE_MONITOR_EVENT_UNMOUNTED: case G_FILE_MONITOR_EVENT_MOVED: break; } }
static void prepare_files_to_be_scanned (SymbolDBSystem *sdbs, GList *cflags, GPtrArray *OUT_files_to_scan_array, GPtrArray *OUT_languages_array) { SymbolDBSystemPriv *priv; GList *node; priv = sdbs->priv; node = cflags; do { GList *files_tmp_list = NULL; GFile *file; file = g_file_new_for_path ((gchar *)node->data); /* files_tmp_list needs to be freed */ sdb_system_files_visit_dir (&files_tmp_list, file); g_object_unref (file); if (files_tmp_list != NULL) { /* last loop here. With files_visit_dir we'll retrieve all files nodes * under the passed directory */ GList *tmp_node; tmp_node = files_tmp_list; do { GFileInfo *info; if ((info = g_file_query_info ((GFile *)tmp_node->data, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL))) { IAnjutaLanguageId lang_id; const char *lang; lang_id = ianjuta_language_get_from_mime_type (priv->lang_manager, g_file_info_get_content_type (info), NULL); g_object_unref (info); /* No supported language... */ if (!lang_id) { continue; } lang = ianjuta_language_get_name (priv->lang_manager, lang_id, NULL); g_ptr_array_add (OUT_languages_array, g_strdup (lang)); g_ptr_array_add (OUT_files_to_scan_array, g_file_get_path ((GFile *)tmp_node->data)); } } while ((tmp_node = tmp_node->next) != NULL); /* free the tmp files list */ g_list_foreach (files_tmp_list, (GFunc)g_object_unref, NULL); g_list_free (files_tmp_list); } } while ((node = node->next) != NULL); }
/* Function implementations */ static void fl_parser_start_node_cb (void *user_data, const char *node_name, const char **attr) { ParserData *data; GFileInfo *info; data = (ParserData *) user_data; data->depth++; d(g_print ("%d: %s\n", data->depth, node_name)); if (data->depth > 2) { g_set_error (data->error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Don't expect node '%s' as child of 'file', 'folder' or 'parent-folder'", node_name); return; } else if (data->depth == 1) { if (strcmp (node_name, "folder-listing") != 0) { g_set_error (data->error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Expected 'folder-listing', got '%s'", node_name); return; } return; } if (strcmp (node_name, "parent-folder") == 0) { /* Just ignore parent-folder items */ return; } info = g_file_info_new (); if (strcmp (node_name, "file") == 0) { g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); } else if (strcmp (node_name, "folder") == 0) { GIcon *icon; g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); g_file_info_set_content_type (info, "inode/directory"); icon = g_themed_icon_new ("folder"); g_file_info_set_icon (info, icon); g_object_unref (icon); icon = g_themed_icon_new ("folder-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); } else { g_set_error (data->error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, "Unknown element '%s'", node_name); return; } if (!fl_parser_fill_file_info (info, attr)) { d(g_print ("Failed to fill GnomeVFSFileInfo from node '%s'\n", node_name)); g_object_unref (info); return; } if (g_file_info_get_content_type (info) == NULL) { char *mime_type; mime_type = g_content_type_guess (g_file_info_get_name (info), NULL, 0, NULL); g_file_info_set_content_type (info, mime_type); g_free (mime_type); } if (g_file_info_get_content_type (info) == NULL) { g_file_info_set_content_type (info, "application/octet-stream"); } if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR) { GIcon *icon; const char *content_type; content_type = g_file_info_get_content_type (info); icon = g_content_type_get_icon (content_type); if (icon != NULL) { if (G_IS_THEMED_ICON (icon)) g_themed_icon_append_name (G_THEMED_ICON (icon), "text-x-generic"); g_file_info_set_icon (info, icon); g_object_unref (icon); } icon = g_content_type_get_symbolic_icon (content_type); if (icon != NULL) { if (G_IS_THEMED_ICON (icon)) g_themed_icon_append_name (G_THEMED_ICON (icon), "text-x-generic-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); } } /* Permissions on folders in OBEX has different semantics than POSIX. * In POSIX, if a folder is not writable, it means that it's content * can't be removed, whereas in OBEX, it just means that the folder * itself can't be removed. Therefore we must set all folders to RWD and * handle the error when it happens. */ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ, TRUE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, TRUE); } data->elements = g_list_prepend (data->elements, info); }
static void visit_directory (GFile *dir, SearchThreadData *data) { GFileEnumerator *enumerator; GFileInfo *info; GFile *child; const char *mime_type, *display_name; char *lower_name, *normalized; gboolean hit; int i; GList *l; const char *id; gboolean visited; enumerator = g_file_enumerate_children (dir, data->mime_types != NULL ? STD_ATTRIBUTES "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE : STD_ATTRIBUTES , 0, data->cancellable, NULL); if (enumerator == NULL) { return; } while ((info = g_file_enumerator_next_file (enumerator, data->cancellable, NULL)) != NULL) { if (g_file_info_get_is_hidden (info)) { goto next; } display_name = g_file_info_get_display_name (info); if (display_name == NULL) { goto next; } normalized = g_utf8_normalize (display_name, -1, G_NORMALIZE_NFD); lower_name = g_utf8_strdown (normalized, -1); g_free (normalized); hit = data->words_and; for (i = 0; data->words[i] != NULL; i++) { if (data->word_strstr[i]) { if ((strstr (lower_name, data->words[i]) != NULL)^data->words_and) { hit = !data->words_and; break; } } else if (strwildcardcmp (data->words[i], lower_name)^data->words_and) { hit = !data->words_and; break; } } g_free (lower_name); if (hit && data->mime_types) { mime_type = g_file_info_get_content_type (info); hit = FALSE; for (l = data->mime_types; mime_type != NULL && l != NULL; l = l->next) { if (g_content_type_equals (mime_type, l->data)) { hit = TRUE; break; } } } child = g_file_get_child (dir, g_file_info_get_name (info)); if (hit) { data->uri_hits = g_list_prepend (data->uri_hits, g_file_get_uri (child)); } data->n_processed_files++; if (data->n_processed_files > BATCH_SIZE) { send_batch (data); } if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILE); visited = FALSE; if (id) { if (g_hash_table_lookup_extended (data->visited, id, NULL, NULL)) { visited = TRUE; } else { g_hash_table_insert (data->visited, g_strdup (id), NULL); } } if (!visited) { g_queue_push_tail (data->directories, g_object_ref (child)); } } g_object_unref (child); next: g_object_unref (info); } g_object_unref (enumerator); }
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; }
static void pd_update_general_tab (XviewerPropertiesDialog *prop_dlg, XviewerImage *image) { gchar *bytes_str, *dir_str; gchar *width_str, *height_str; GFile *file, *parent_file; GFileInfo *file_info; const char *mime_str; char *type_str; gint width, height; goffset bytes; g_object_set (G_OBJECT (prop_dlg->priv->thumbnail_image), "pixbuf", xviewer_image_get_thumbnail (image), NULL); gtk_label_set_text (GTK_LABEL (prop_dlg->priv->name_label), xviewer_image_get_caption (image)); xviewer_image_get_size (image, &width, &height); width_str = g_strdup_printf ("%d %s", width, ngettext ("pixel", "pixels", width)); height_str = g_strdup_printf ("%d %s", height, ngettext ("pixel", "pixels", height)); gtk_label_set_text (GTK_LABEL (prop_dlg->priv->width_label), width_str); gtk_label_set_text (GTK_LABEL (prop_dlg->priv->height_label), height_str); g_free (height_str); g_free (width_str); file = xviewer_image_get_file (image); file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, NULL); if (file_info == NULL) { type_str = g_strdup (_("Unknown")); } else { mime_str = g_file_info_get_content_type (file_info); type_str = g_content_type_get_description (mime_str); g_object_unref (file_info); } gtk_label_set_text (GTK_LABEL (prop_dlg->priv->type_label), type_str); bytes = xviewer_image_get_bytes (image); bytes_str = g_format_size (bytes); gtk_label_set_text (GTK_LABEL (prop_dlg->priv->bytes_label), bytes_str); parent_file = g_file_get_parent (file); if (parent_file == NULL) { /* file is root directory itself */ parent_file = g_object_ref (file); } dir_str = g_file_get_basename (parent_file); gtk_button_set_label (GTK_BUTTON (prop_dlg->priv->folder_button), dir_str); g_free (prop_dlg->priv->folder_button_uri); prop_dlg->priv->folder_button_uri = g_file_get_uri (parent_file); g_object_unref (parent_file); g_free (type_str); g_free (bytes_str); g_free (dir_str); }
void Directory_list_task::exec() { QDir dir(path); if (!dir.exists()) { emit error(tr("Directory %1 does not exist.").arg(dir.absolutePath())); deleteLater(); return; } if (!dir.isReadable()) { emit error(tr("Directory %1 can not be read.").arg(dir.absolutePath())); deleteLater(); return; } QFileInfoList list = dir.entryInfoList(QStringList(), QDir::AllEntries | QDir::NoDotAndDotDot); GError* gerror = 0; File_info_list r; foreach (QFileInfo info, list) { File_info item; item.name = info.fileName(); item.full_path = info.absoluteFilePath(); item.is_file = info.isFile(); item.owner = info.owner(); item.group = info.group(); item.permissions = info.permissions(); item.name = info.baseName(); item.extension = info.suffix(); item.full_name = info.fileName(); item.parent_folder = info.dir().path(); item.date_accessed = info.lastRead(); item.date_modified = info.lastModified(); item.date_created = info.created(); item.is_executable = item.is_file && info.isExecutable(); //qDebug() << "path for GFile: " << info.absoluteFilePath(); GFile *file = g_file_new_for_path (info.absoluteFilePath().toLocal8Bit()); //qDebug() << "GFile* file = " << file; GFileInfo* gfileinfo = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, GFileQueryInfoFlags(), 0, &gerror); if (gerror) { emit error(QString::fromLocal8Bit(gerror->message)); g_error_free(gerror); gerror = 0; return; } if (gfileinfo) { //qDebug() << "GFileInfo* gfileinfo = " << gfileinfo; const char* content_type = g_file_info_get_content_type(gfileinfo); item.mime_type = QString::fromLocal8Bit(content_type); g_object_unref(gfileinfo); } g_object_unref(file); /* //todo: check for null pointers; add gerror for debug output GFileInfo *file_info = g_file_query_info (file, "standard::*", (GFileQueryInfoFlags) 0, 0, 0); GIcon *icon = g_file_info_get_icon (file_info); qDebug() << "is_loadable" << G_IS_LOADABLE_ICON(icon); qDebug() << "is_themed" << G_IS_THEMED_ICON(icon); qDebug() << "is_emblem" << G_IS_EMBLEM(icon); qDebug() << "is_emblemed_icon" << G_IS_EMBLEMED_ICON(icon); qDebug() << "is_file_icon" << G_IS_FILE_ICON(icon); GError* error = 0; GInputStream* icon_stream = g_loadable_icon_load( (GLoadableIcon*) icon, 16, 0, 0, &error); if (error) qDebug() << error->message; char buffer[ICON_BUFFER_SIZE]; gsize bytes_read; error = 0; gboolean b = g_input_stream_read_all(icon_stream, buffer, ICON_BUFFER_SIZE, &bytes_read, 0, &error); if (b) { //QString s = QString::fromAscii(buffer, bytes_read); qDebug() << "g_input_stream_read_all bytes read: " << bytes_read; } else { qDebug() << "g_input_stream_read_all failed"; } */ r << item; }
GList *vfs_backend_list_directory (const gchar *cBaseURI, CairoDockFMSortType iSortType, int iNewIconsType, gboolean bListHiddenFiles, gchar **cFullURI) { g_return_val_if_fail (cBaseURI != NULL, NULL); cd_message ("%s (%s)", __func__, cBaseURI); gchar *cURI; gboolean bAddHome = FALSE; if (strcmp (cBaseURI, CAIRO_DOCK_FM_VFS_ROOT) == 0) { cURI = g_strdup ("computer://"); bAddHome = TRUE; ///*cFullURI = cURI; ///return vfs_backend_list_volumes (); //vfs_backend_list_volumes (); } else if (strcmp (cBaseURI, CAIRO_DOCK_FM_NETWORK) == 0) cURI = g_strdup ("network://"); else cURI = (*cBaseURI == '/' ? g_strconcat ("file://", cBaseURI, NULL) : g_strdup (cBaseURI)); *cFullURI = cURI; GFile *pFile = g_file_new_for_uri (cURI); GError *erreur = NULL; const gchar *cAttributes = G_FILE_ATTRIBUTE_STANDARD_TYPE"," G_FILE_ATTRIBUTE_STANDARD_SIZE"," G_FILE_ATTRIBUTE_TIME_MODIFIED"," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE"," G_FILE_ATTRIBUTE_STANDARD_NAME"," G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN"," G_FILE_ATTRIBUTE_STANDARD_ICON"," G_FILE_ATTRIBUTE_STANDARD_TARGET_URI"," G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE; GFileEnumerator *pFileEnum = g_file_enumerate_children (pFile, cAttributes, G_FILE_QUERY_INFO_NONE, /// G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS NULL, &erreur); //g_object_unref (pFile); if (erreur != NULL) { cd_warning ("gnome_integration : %s", erreur->message); g_error_free (erreur); return NULL; } int iOrder = 0; GList *pIconList = NULL; Icon *icon; GFileInfo *pFileInfo; do { pFileInfo = g_file_enumerator_next_file (pFileEnum, NULL, &erreur); if (erreur != NULL) { cd_warning ("gnome_integration : %s", erreur->message); g_error_free (erreur); erreur = NULL; continue; } if (pFileInfo == NULL) break ; gboolean bIsHidden = g_file_info_get_is_hidden (pFileInfo); if (bListHiddenFiles || ! bIsHidden) { GFileType iFileType = g_file_info_get_file_type (pFileInfo); GIcon *pFileIcon = g_file_info_get_icon (pFileInfo); if (pFileIcon == NULL) { cd_message ("AUCUNE ICONE"); continue; } const gchar *cFileName = g_file_info_get_name (pFileInfo); const gchar *cMimeType = g_file_info_get_content_type (pFileInfo); gchar *cName = NULL; icon = g_new0 (Icon, 1); icon->iType = iNewIconsType; icon->cBaseURI = g_strconcat (*cFullURI, "/", cFileName, NULL); cd_message ("+ %s (mime:%s)", icon->cBaseURI, cMimeType); if (iFileType == G_FILE_TYPE_MOUNTABLE) { const gchar *cTargetURI = g_file_info_get_attribute_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI); cd_message (" c'est un point de montage correspondant a %s", cTargetURI); GMount *pMount = NULL; if (cTargetURI != NULL) { icon->acCommand = g_strdup (cTargetURI); GFile *file = g_file_new_for_uri (cTargetURI); pMount = g_file_find_enclosing_mount (file, NULL, NULL); //g_object_unref (file); } if (pMount != NULL) { cName = g_mount_get_name (pMount); cd_message ("un GMount existe (%s)", cName); GVolume *volume = g_mount_get_volume (pMount); if (volume) cd_message (" volume associe : %s", g_volume_get_name (volume)); GDrive *drive = g_mount_get_drive (pMount); if (drive) cd_message (" disque associe : %s", g_drive_get_name (drive)); ///pFileIcon = g_mount_get_icon (pMount); } else { cName = g_strdup (cFileName); gchar *str = strrchr (cName, '.'); // on vire l'extension ".volume" ou ".drive". if (str != NULL) { *str = '\0'; if (strcmp (str+1, "link") == 0) { if (strcmp (cName, "root") == 0) { g_free (cName); cName = g_strdup ("/"); } } else if (strcmp (str+1, "drive") == 0) // on cherche un nom plus parlant si possible. { gchar *cVolumeName = _cd_find_volume_name_from_drive_name (cName); if (cVolumeName != NULL) { g_free (cName); g_free (cVolumeName); continue; /// apparemment il n'est plus necessaire d'afficher les .drives qui ont 1 (ou plusieurs ?) volumes, car ces derniers sont dans la liste, donc ca fait redondant. /**if (strcmp (cVolumeName, "discard") == 0) continue; g_free (cName); cName = cVolumeName;*/ } } } } icon->iVolumeID = 1; cd_message ("le nom de ce volume est : %s", cName); } else cName = g_strdup (cFileName); if (icon->acCommand == NULL) icon->acCommand = g_strdup (icon->cBaseURI); icon->acName = cName; icon->acFileName = NULL; if (cMimeType != NULL && strncmp (cMimeType, "image", 5) == 0) { gchar *cHostname = NULL; gchar *cFilePath = g_filename_from_uri (icon->cBaseURI, &cHostname, &erreur); if (erreur != NULL) { g_error_free (erreur); erreur = NULL; } else if (cHostname == NULL || strcmp (cHostname, "localhost") == 0) // on ne recupere la vignette que sur les fichiers locaux. { icon->acFileName = g_strdup (cFilePath); cairo_dock_remove_html_spaces (icon->acFileName); } g_free (cHostname); g_free (cFilePath); } if (icon->acFileName == NULL) { icon->acFileName = _cd_get_icon_path (pFileIcon); cd_message ("icon->acFileName : %s", icon->acFileName); } if (iSortType == CAIRO_DOCK_FM_SORT_BY_SIZE) icon->fOrder = g_file_info_get_size (pFileInfo); else if (iSortType == CAIRO_DOCK_FM_SORT_BY_DATE) { GTimeVal t; g_file_info_get_modification_time (pFileInfo, &t); icon->fOrder = t.tv_sec; } else if (iSortType == CAIRO_DOCK_FM_SORT_BY_TYPE) icon->fOrder = (cMimeType != NULL ? *((int *) cMimeType) : 0); if (icon->fOrder == 0) // un peu moyen mais mieux que rien non ? icon->fOrder = iOrder; pIconList = g_list_insert_sorted (pIconList, icon, (GCompareFunc) cairo_dock_compare_icons_order); //g_list_prepend (pIconList, icon); iOrder ++; } } while (TRUE); // 'g_file_enumerator_close' est appelee lors du dernier 'g_file_enumerator_next_file'. if (bAddHome && pIconList != NULL) { icon = g_new0 (Icon, 1); icon->iType = iNewIconsType; icon->cBaseURI = g_strdup_printf ("file://%s", "/home"); icon->acCommand = g_strdup ("/home"); //icon->acCommand = g_strdup (icon->cBaseURI); icon->iVolumeID = 0; icon->acName = g_strdup ("home"); Icon *pRootIcon = cairo_dock_get_icon_with_name (pIconList, "/"); if (pRootIcon == NULL) { pRootIcon = cairo_dock_get_first_icon (pIconList); g_print ("domage ! (%s:%s)\n", pRootIcon->acCommand, pRootIcon->acName); } icon->acFileName = g_strdup (pRootIcon->acFileName); icon->fOrder = iOrder++; pIconList = g_list_insert_sorted (pIconList, icon, (GCompareFunc) cairo_dock_compare_icons_order); } if (iSortType == CAIRO_DOCK_FM_SORT_BY_NAME) pIconList = cairo_dock_sort_icons_by_name (pIconList); else pIconList = cairo_dock_sort_icons_by_order (pIconList); return pIconList; }
void vfs_backend_get_file_info (const gchar *cBaseURI, gchar **cName, gchar **cURI, gchar **cIconName, gboolean *bIsDirectory, int *iVolumeID, double *fOrder, CairoDockFMSortType iSortType) { g_return_if_fail (cBaseURI != NULL); GError *erreur = NULL; cd_message ("%s (%s)", __func__, cBaseURI); gchar *cFullURI; if (strncmp (cBaseURI, "x-nautilus-desktop://", 21) == 0) { gchar *cNautilusFile = g_strdup (cBaseURI+14); memcpy (cNautilusFile, "file", 4); if (g_str_has_suffix (cBaseURI, ".volume")) { cNautilusFile[strlen(cNautilusFile)-7] = '\0'; } else if (g_str_has_suffix (cBaseURI, ".drive")) { cNautilusFile[strlen(cNautilusFile)-6] = '\0'; } cFullURI = g_filename_from_uri (cNautilusFile, NULL, &erreur); if (erreur != NULL) { cd_warning ("gnome_integration : %s", erreur->message); g_error_free (erreur); return ; } gchar *cVolumeName = cFullURI + 1; // on saute le '/'. cd_message ("cVolumeName : %s", cVolumeName); GMount *pMount = NULL; _cd_find_mount_from_volume_name (cVolumeName, &pMount, cURI, cIconName); g_return_if_fail (pMount != NULL); *cName = g_strdup (cVolumeName); *bIsDirectory = TRUE; *iVolumeID = 1; *fOrder = 0; //g_object_unref (pMount); g_free (cFullURI); //g_free (cNautilusFile); return; } else { if (*cBaseURI == '/') cFullURI = g_filename_to_uri (cBaseURI, NULL, NULL); else cFullURI = g_strdup (cBaseURI); } cd_message (" -> cFullURI : %s", cFullURI); GFile *pFile = g_file_new_for_uri (cFullURI); const gchar *cQuery = G_FILE_ATTRIBUTE_STANDARD_TYPE"," G_FILE_ATTRIBUTE_STANDARD_SIZE"," G_FILE_ATTRIBUTE_TIME_MODIFIED"," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE"," G_FILE_ATTRIBUTE_STANDARD_NAME"," G_FILE_ATTRIBUTE_STANDARD_ICON"," G_FILE_ATTRIBUTE_STANDARD_TARGET_URI"," G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE; GFileInfo *pFileInfo = g_file_query_info (pFile, cQuery, G_FILE_QUERY_INFO_NONE, /// G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS NULL, &erreur); //g_object_unref (pFile); if (erreur != NULL) { cd_warning ("gnome_integration : %s", erreur->message); g_error_free (erreur); return ; } *cURI = cFullURI; const gchar *cFileName = g_file_info_get_name (pFileInfo); const gchar *cMimeType = g_file_info_get_content_type (pFileInfo); GFileType iFileType = g_file_info_get_file_type (pFileInfo); if (iSortType == CAIRO_DOCK_FM_SORT_BY_DATE) { GTimeVal t; g_file_info_get_modification_time (pFileInfo, &t); *fOrder = t.tv_sec; } else if (iSortType == CAIRO_DOCK_FM_SORT_BY_SIZE) *fOrder = g_file_info_get_size (pFileInfo); else if (iSortType == CAIRO_DOCK_FM_SORT_BY_TYPE) *fOrder = (cMimeType != NULL ? *((int *) cMimeType) : 0); else *fOrder = 0; *bIsDirectory = (iFileType == G_FILE_TYPE_DIRECTORY); cd_message (" => '%s' (mime:%s ; bIsDirectory:%d)", cFileName, cMimeType, *bIsDirectory); if (iFileType == G_FILE_TYPE_MOUNTABLE) { *cName = NULL; *iVolumeID = 1; const gchar *cTargetURI = g_file_info_get_attribute_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI); cd_message (" cTargetURI:%s", cTargetURI); GMount *pMount = NULL; if (cTargetURI != NULL) { GFile *file = g_file_new_for_uri (cTargetURI); pMount = g_file_find_enclosing_mount (file, NULL, NULL); //g_object_unref (file); } if (pMount != NULL) { *cName = g_mount_get_name (pMount); cd_message ("un GMount existe (%s)",* cName); } else { gchar *cMountName = g_strdup (cFileName); gchar *str = strrchr (cMountName, '.'); // on vire l'extension ".volume" ou ".drive". if (str != NULL) { *str = '\0'; if (strcmp (str+1, "link") == 0) // pour les liens, on prend le nom du lien. { if (strcmp (cMountName, "root") == 0) // on remplace 'root' par un nom plus parlant, sinon on prendra le nom du lien. { *cName = g_strdup ("/"); } } else if (strcmp (str+1, "drive") == 0) // on cherche un nom plus parlant si possible. { gchar *cVolumeName = _cd_find_volume_name_from_drive_name (cMountName); if (cVolumeName != NULL) { *cName = cVolumeName; } } } if (*cName == NULL) *cName = cMountName; //else //g_free (cMountName); } if (*cName == NULL) *cName = g_strdup (cFileName); } else { *iVolumeID = 0; *cName = g_strdup (cFileName); } *cIconName = NULL; if (cMimeType != NULL && strncmp (cMimeType, "image", 5) == 0) { gchar *cHostname = NULL; GError *erreur = NULL; gchar *cFilePath = g_filename_from_uri (cBaseURI, &cHostname, &erreur); if (erreur != NULL) { g_error_free (erreur); } else if (cHostname == NULL || strcmp (cHostname, "localhost") == 0) // on ne recupere la vignette que sur les fichiers locaux. { *cIconName = g_strdup (cFilePath); cairo_dock_remove_html_spaces (*cIconName); } //g_free (cHostname); } if (*cIconName == NULL) { GIcon *pSystemIcon = g_file_info_get_icon (pFileInfo); if (pSystemIcon != NULL) { *cIconName = _cd_get_icon_path (pSystemIcon); } } cd_message ("cIconName : %s", *cIconName); //*iVolumeID = g_file_info_get_attribute_uint32 (pFileInfo, G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE); //cd_message ("ID : %d\n", *iVolumeID); //g_object_unref (pFileInfo); }
static void ft_handler_gfile_ready_cb (GObject *source, GAsyncResult *res, CallbacksData *cb_data) { GFileInfo *info; GError *error = NULL; GTimeVal mtime; EmpathyFTHandlerPriv *priv = cb_data->handler->priv; (void)source; /* suppress unused-parameter warning */ DEBUG ("Got GFileInfo."); info = g_file_query_info_finish (priv->gfile, res, &error); if (error != NULL) goto out; if (g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR) { error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK, EMPATHY_FT_ERROR_INVALID_SOURCE_FILE, _("The selected file is not a regular file")); goto out; } priv->total_bytes = g_file_info_get_size (info); if (priv->total_bytes == 0) { error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK, EMPATHY_FT_ERROR_EMPTY_SOURCE_FILE, _("The selected file is empty")); goto out; } priv->content_type = g_strdup (g_file_info_get_content_type (info)); priv->filename = g_strdup (g_file_info_get_display_name (info)); g_file_info_get_modification_time (info, &mtime); priv->mtime = mtime.tv_sec; priv->transferred_bytes = 0; priv->description = NULL; g_object_unref (info); out: if (error != NULL) { if (!g_cancellable_is_cancelled (priv->cancellable)) g_cancellable_cancel (priv->cancellable); cb_data->callback (cb_data->handler, error, cb_data->user_data); g_error_free (error); callbacks_data_free (cb_data); } else { /* see if FT/hashing are allowed */ check_hashing (cb_data); } }
int main (int argc, char *argv[]) { RygelMediaServer *server; RygelSimpleContainer *root_container; char *path; GFile *source_dir; GFileEnumerator *enumerator; GFileInfo *info; int i; GMainLoop *loop; GError *error = NULL; // g_type_init (); rygel_media_engine_init (&error); if (error != NULL) { g_print ("Could not initialize media engine: %s\n", error->message); g_error_free (error); return EXIT_FAILURE; } g_set_application_name ("Standalone-Server"); root_container = rygel_simple_container_new_root ("Sample implementation"); if (argc >= 2) { path = g_strdup (argv[1]); } else { path = g_get_current_dir (); } source_dir = g_file_new_for_commandline_arg (path); g_free (path); enumerator = g_file_enumerate_children (source_dir, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); info = g_file_enumerator_next_file (enumerator, NULL, NULL); i = 0; while (info != NULL) { GFile *file; const char *display_name, *content_type; char *uri, *id; RygelMediaItem *item = NULL; GError *error = NULL; display_name = g_file_info_get_display_name (info); content_type = g_file_info_get_content_type (info); file = g_file_get_child_for_display_name (source_dir, display_name, &error); if (error != NULL) { g_critical ("Failed to get child: %s", error->message); return 127; } uri = g_file_get_uri (file); g_object_unref (file); id = g_strdup_printf ("%06d", i); if (g_str_has_prefix (content_type, "audio/")) { item = (RygelMediaItem*)rygel_audio_item_new (id, (RygelMediaContainer*)root_container, display_name, RYGEL_AUDIO_ITEM_UPNP_CLASS); } else if (g_str_has_prefix (content_type, "video/")) { item = (RygelMediaItem*)rygel_video_item_new (id, (RygelMediaContainer*)root_container, display_name, RYGEL_VIDEO_ITEM_UPNP_CLASS); } else if (g_str_has_prefix (content_type, "image/")) { item = (RygelMediaItem*)rygel_image_item_new (id, (RygelMediaContainer*)root_container, display_name, RYGEL_IMAGE_ITEM_UPNP_CLASS); } g_free (id); if (item != NULL) { RygelMediaObject *object; GeeArrayList* uris; rygel_media_item_set_mime_type (RYGEL_MEDIA_ITEM (item), content_type); object = RYGEL_MEDIA_OBJECT (item); gee_collection_add (GEE_COLLECTION (object->uris), uri); rygel_simple_container_add_child_item (root_container, item); } i++; info = g_file_enumerator_next_file (enumerator, NULL, NULL); } server = rygel_media_server_new ("Single purpose server", (RygelMediaContainer*)root_container, RYGEL_PLUGIN_CAPABILITIES_NONE); rygel_media_device_add_interface (RYGEL_MEDIA_DEVICE (server), "eth0"); rygel_media_device_add_interface (RYGEL_MEDIA_DEVICE (server), "wlan0"); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); }
GList * rut_infer_asset_tags (RutContext *ctx, GFileInfo *info, GFile *asset_file) { GFile *assets_dir = g_file_new_for_path (ctx->assets_location); GFile *dir = g_file_get_parent (asset_file); char *basename; const char *content_type = g_file_info_get_content_type (info); char *mime_type = g_content_type_get_mime_type (content_type); const char *ext; GList *inferred_tags = NULL; while (dir && !g_file_equal (assets_dir, dir)) { basename = g_file_get_basename (dir); inferred_tags = g_list_prepend (inferred_tags, (char *)g_intern_string (basename)); g_free (basename); dir = g_file_get_parent (dir); } if (mime_type) { if (strncmp (mime_type, "image/", 6) == 0) inferred_tags = g_list_prepend (inferred_tags, (char *)g_intern_string ("image")); inferred_tags = g_list_prepend (inferred_tags, (char *)g_intern_string ("img")); if (rut_util_find_tag (inferred_tags, "normal-maps")) { inferred_tags = g_list_prepend (inferred_tags, (char *)g_intern_string ("map")); inferred_tags = g_list_prepend (inferred_tags, (char *)g_intern_string ("normal-map")); inferred_tags = g_list_prepend (inferred_tags, (char *)g_intern_string ("bump-map")); } else if (rut_util_find_tag (inferred_tags, "alpha-masks")) { inferred_tags = g_list_prepend (inferred_tags, (char *)g_intern_string ("alpha-mask")); inferred_tags = g_list_prepend (inferred_tags, (char *)g_intern_string ("mask")); } } basename = g_file_get_basename (asset_file); ext = get_extension (basename); if (ext && strcmp (ext, "ply") == 0) { inferred_tags = g_list_prepend (inferred_tags, (char *)g_intern_string ("ply")); inferred_tags = g_list_prepend (inferred_tags, (char *)g_intern_string ("mesh")); inferred_tags = g_list_prepend (inferred_tags, (char *)g_intern_string ("model")); } g_free (basename); return inferred_tags; }
static void remote_query_info_ready_cb (GObject *obj, GAsyncResult *res, gpointer user_data) { PdfLoadJob *job = user_data; GError *error = NULL; GFile *pdf_file; GFileInfo *info; const gchar *content_type; gchar *tmp_name; gchar *tmp_path; info = g_file_query_info_finish (G_FILE (obj), res, &error); if (error != NULL) { pdf_load_job_complete_error (job, error); return; } job->original_file_mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED); tmp_name = g_strdup_printf ("gnome-documents-%u.pdf", g_str_hash (job->uri)); tmp_path = g_build_filename (g_get_user_cache_dir (), "gnome-documents", NULL); job->pdf_path = g_build_filename (tmp_path, tmp_name, NULL); g_mkdir_with_parents (tmp_path, 0700); content_type = g_file_info_get_content_type (info); if (!content_type_is_native (content_type)) { GFileIOStream *iostream; job->download_file = g_file_new_tmp (NULL, &iostream, &error); if (error != NULL) { pdf_load_job_complete_error (job, error); return; } /* We don't need the iostream. */ g_io_stream_close (G_IO_STREAM (iostream), NULL, NULL); } else { job->download_file = g_file_new_for_path (job->pdf_path); } pdf_file = g_file_new_for_path (job->pdf_path); g_file_query_info_async (pdf_file, G_FILE_ATTRIBUTE_TIME_MODIFIED, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, job->cancellable, remote_cache_query_info_ready_cb, job); g_free (tmp_name); g_free (tmp_path); g_object_unref (pdf_file); g_object_unref (info); }
/** * eog_list_store_add_files: * @store: An #EogListStore. * @file_list: (element-type GFile): A %NULL-terminated list of #GFile's. * * Adds a list of #GFile's to @store. The given list * must be %NULL-terminated. * * If any of the #GFile's in @file_list is a directory, all the images * in that directory will be added to @store. If the list of files contains * only one file and this is a regular file, then all the images in the same * directory will be added as well to @store. * **/ void eog_list_store_add_files (EogListStore *store, GList *file_list) { GList *it; GFileInfo *file_info; GFileType file_type; GFile *initial_file = NULL; GtkTreeIter iter; if (file_list == NULL) { return; } gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, GTK_SORT_ASCENDING); for (it = file_list; it != NULL; it = it->next) { GFile *file = (GFile *) it->data; file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE"," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, NULL); if (file_info == NULL) { continue; } file_type = g_file_info_get_file_type (file_info); /* Workaround for gvfs backends that don't set the GFileType. */ if (G_UNLIKELY (file_type == G_FILE_TYPE_UNKNOWN)) { const gchar *ctype; ctype = g_file_info_get_content_type (file_info); /* If the content type is supported adjust file_type */ if (eog_image_is_supported_mime_type (ctype)) file_type = G_FILE_TYPE_REGULAR; } g_object_unref (file_info); if (file_type == G_FILE_TYPE_DIRECTORY) { eog_list_store_append_directory (store, file, file_type); } else if (file_type == G_FILE_TYPE_REGULAR && g_list_length (file_list) == 1) { initial_file = g_file_dup (file); file = g_file_get_parent (file); file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, 0, NULL, NULL); /* If we can't get a file_info, file_type will stay as G_FILE_TYPE_REGULAR */ if (file_info != NULL) { file_type = g_file_info_get_file_type (file_info); g_object_unref (file_info); } if (file_type == G_FILE_TYPE_DIRECTORY) { eog_list_store_append_directory (store, file, file_type); if (!is_file_in_list_store_file (store, initial_file, &iter)) { eog_list_store_append_image_from_file (store, initial_file); } } else { eog_list_store_append_image_from_file (store, initial_file); } g_object_unref (file); } else if (file_type == G_FILE_TYPE_REGULAR && g_list_length (file_list) > 1) { eog_list_store_append_image_from_file (store, file); } } gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING); if (initial_file && is_file_in_list_store_file (store, initial_file, &iter)) { store->priv->initial_image = eog_list_store_get_pos_by_iter (store, &iter); g_object_unref (initial_file); } else { store->priv->initial_image = 0; } }
static gboolean log_load (GIOSchedulerJob *io_job, GCancellable *cancellable, gpointer user_data) { /* this runs in a separate i/o thread */ LoadJob *job = user_data; LogviewLog *log = job->log; GFile *f = log->priv->file; GFileInfo *info; GInputStream *is; const char *peeked_buffer; const char * parse_data[2]; GSList *days; const char *content_type; GFileType type; GError *err = NULL; GTimeVal timeval; gboolean is_archive, can_read; info = g_file_query_info (f, G_FILE_ATTRIBUTE_ACCESS_CAN_READ "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SIZE "," G_FILE_ATTRIBUTE_TIME_MODIFIED ",", 0, NULL, &err); if (err) { if (err->code == G_IO_ERROR_PERMISSION_DENIED) { /* TODO: PolicyKit integration */ } goto out; } can_read = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ); if (!can_read) { /* TODO: PolicyKit integration */ err = g_error_new_literal (LOGVIEW_ERROR_QUARK, LOGVIEW_ERROR_PERMISSION_DENIED, _("You don't have enough permissions to read the file.")); g_object_unref (info); goto out; } type = g_file_info_get_file_type (info); content_type = g_file_info_get_content_type (info); is_archive = g_content_type_equals (content_type, "application/x-gzip"); if (type != (G_FILE_TYPE_REGULAR || G_FILE_TYPE_SYMBOLIC_LINK) || (!g_content_type_is_a (content_type, "text/plain") && !is_archive)) { err = g_error_new_literal (LOGVIEW_ERROR_QUARK, LOGVIEW_ERROR_NOT_A_LOG, _("The file is not a regular file or is not a text file.")); g_object_unref (info); goto out; } log->priv->file_size = g_file_info_get_size (info); g_file_info_get_modification_time (info, &timeval); log->priv->file_time = timeval.tv_sec; log->priv->display_name = g_strdup (g_file_info_get_display_name (info)); g_object_unref (info); /* initialize the stream */ is = G_INPUT_STREAM (g_file_read (f, NULL, &err)); if (err) { if (err->code == G_IO_ERROR_PERMISSION_DENIED) { /* TODO: PolicyKit integration */ } goto out; } if (is_archive) { #ifdef HAVE_ZLIB GZHandle *gz; gboolean res; guchar * buffer; gsize bytes_read; GInputStream *real_is; time_t mtime; /* seconds */ /* this also skips the header from |is| */ res = read_gzip_header (is, &mtime); if (!res) { g_object_unref (is); err = create_zlib_error (); goto out; } log->priv->file_time = mtime; gz = gz_handle_new (f, is); res = gz_handle_init (gz); if (!res) { g_object_unref (is); gz_handle_free (gz); err = create_zlib_error (); goto out; } real_is = g_memory_input_stream_new (); do { buffer = g_malloc (1024); res = gz_handle_read (gz, buffer, 1024, &bytes_read); g_memory_input_stream_add_data (G_MEMORY_INPUT_STREAM (real_is), buffer, bytes_read, g_free); } while (res == TRUE && bytes_read > 0); if (!res) { gz_handle_free (gz); g_object_unref (real_is); g_object_unref (is); err = create_zlib_error (); goto out; } g_object_unref (is); is = real_is; gz_handle_free (gz); #else /* HAVE_ZLIB */ g_object_unref (is); err = g_error_new_literal (LOGVIEW_ERROR_QUARK, LOGVIEW_ERROR_NOT_SUPPORTED, _("This version of System Log does not support GZipped logs.")); goto out; #endif /* HAVE_ZLIB */ } log->priv->stream = g_data_input_stream_new (is); /* sniff into the stream for a timestamped line */ g_buffered_input_stream_fill (G_BUFFERED_INPUT_STREAM (log->priv->stream), (gssize) g_buffered_input_stream_get_buffer_size (G_BUFFERED_INPUT_STREAM (log->priv->stream)), NULL, &err); if (err == NULL) { peeked_buffer = g_buffered_input_stream_peek_buffer (G_BUFFERED_INPUT_STREAM (log->priv->stream), NULL); parse_data[0] = peeked_buffer; parse_data[1] = NULL; if ((days = log_read_dates (parse_data, time (NULL))) != NULL) { log->priv->has_days = TRUE; g_slist_foreach (days, (GFunc) logview_utils_day_free, NULL); g_slist_free (days); } else { log->priv->has_days = FALSE; } } else { log->priv->has_days = FALSE; g_clear_error (&err); } g_object_unref (is); out: if (err) { job->err = err; } g_io_scheduler_job_send_to_mainloop_async (io_job, log_load_done, job, NULL); return FALSE; }
static const gchar * xfdesktop_regular_file_icon_peek_tooltip(XfdesktopIcon *icon) { XfdesktopRegularFileIcon *regular_file_icon = XFDESKTOP_REGULAR_FILE_ICON(icon); if(!regular_file_icon->priv->tooltip) { GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon)); const gchar *content_type, *comment = NULL; gchar *description, *size_string, *time_string; guint64 size, mtime; gboolean is_desktop_file = FALSE; if(!info) return NULL; if(g_content_type_equals(g_file_info_get_content_type(info), "application/x-desktop")) { is_desktop_file = TRUE; } else { gchar *uri = g_file_get_uri(regular_file_icon->priv->file); if(g_str_has_suffix(uri, ".desktop")) is_desktop_file = TRUE; g_free(uri); } content_type = g_file_info_get_content_type(info); description = g_content_type_get_description(content_type); size = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_STANDARD_SIZE); size_string = g_format_size(size); mtime = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_TIME_MODIFIED); time_string = xfdesktop_file_utils_format_time_for_display(mtime); regular_file_icon->priv->tooltip = g_strdup_printf(_("Type: %s\nSize: %s\nLast modified: %s"), description, size_string, time_string); /* Extract the Comment entry from the .desktop file */ if(is_desktop_file) { gchar *path = g_file_get_path(regular_file_icon->priv->file); XfceRc *rcfile = xfce_rc_simple_open(path, TRUE); g_free(path); if(rcfile) { xfce_rc_set_group(rcfile, "Desktop Entry"); comment = xfce_rc_read_entry(rcfile, "Comment", NULL); } /* Prepend the comment to the tooltip */ if(comment != NULL && *comment != '\0') { gchar *tooltip = regular_file_icon->priv->tooltip; regular_file_icon->priv->tooltip = g_strdup_printf("%s\n%s", comment, tooltip); g_free(tooltip); } xfce_rc_close(rcfile); } g_free(time_string); g_free(size_string); g_free(description); } return regular_file_icon->priv->tooltip; }
static gboolean tracker_writeback_file_update_metadata (TrackerWriteback *writeback, GPtrArray *values, TrackerSparqlConnection *connection, GCancellable *cancellable, GError **error) { TrackerWritebackFileClass *writeback_file_class; gboolean retval; GFile *file, *tmp_file; GFileInfo *file_info; GStrv row; const gchar * const *content_types; const gchar *mime_type; guint n; GError *n_error = NULL; writeback_file_class = TRACKER_WRITEBACK_FILE_GET_CLASS (writeback); if (!writeback_file_class->update_file_metadata) { g_critical ("%s doesn't implement update_file_metadata()", G_OBJECT_TYPE_NAME (writeback)); g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s doesn't implement update_file_metadata()", G_OBJECT_TYPE_NAME (writeback)); return FALSE; } if (!writeback_file_class->content_types) { g_critical ("%s doesn't implement content_types()", G_OBJECT_TYPE_NAME (writeback)); g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s doesn't implement content_types()", G_OBJECT_TYPE_NAME (writeback)); return FALSE; } /* Get the file from the row */ row = g_ptr_array_index (values, 0); file = g_file_new_for_uri (row[0]); file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_UNIX_MODE "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); if (!file_info) { g_object_unref (file); g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s doesn't exist", row[0]); return FALSE; } if (!g_file_info_get_attribute_boolean (file_info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { g_object_unref (file_info); g_object_unref (file); g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s not writable", row[0]); return FALSE; } mime_type = g_file_info_get_content_type (file_info); content_types = (writeback_file_class->content_types) (TRACKER_WRITEBACK_FILE (writeback)); retval = FALSE; for (n = 0; content_types[n] != NULL; n++) { if (g_strcmp0 (mime_type, content_types[n]) == 0) { retval = TRUE; break; } } if (!retval) { /* module does not support writeback for this file */ g_object_unref (file_info); g_object_unref (file); g_set_error_literal (error, TRACKER_DBUS_ERROR, TRACKER_DBUS_ERROR_UNSUPPORTED, "Module does not support writeback for this file"); return FALSE; } /* Copy to a temporary file so we can perform an atomic write on move */ tmp_file = create_temporary_file (file, file_info, &n_error); if (!tmp_file) { g_object_unref (file); g_propagate_error (error, n_error); g_object_unref (file_info); return FALSE; } retval = (writeback_file_class->update_file_metadata) (TRACKER_WRITEBACK_FILE (writeback), tmp_file, values, connection, cancellable, &n_error); if (!retval) { /* Delete the temporary file and preserve original */ g_file_delete (tmp_file, NULL, NULL); } else { GError *m_error = NULL; /* Move back the modified file to the original location */ g_file_move (tmp_file, file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL); /* Set file attributes on tmp_file using file_info of original file */ g_file_set_attributes_from_info (tmp_file, file_info, 0, NULL, &m_error); if (m_error) { g_warning ("Can't restore permissions of original file for %s", row[0]); g_error_free (m_error); } } g_object_unref (file_info); g_object_unref (tmp_file); g_object_unref (file); if (n_error) { g_propagate_error (error, n_error); } return retval; }
/** * tmp_picasaweb_upload_async: * * Temporary solution to provide asynchronous uploading and stop * blocking the UI until gdata_picasaweb_service_upload_file_async() * becomes available (bgo #600262). This method does the synchronous * file upload, but is run asynchronously via * g_simple_async_result_run_in_thread(). * * This sets up a minimal #GDataPicasaWebFile entry, using the * basename of the filepath for the file's title (which is not the * caption, but might be something we would consider doing). The * image file and the minimal entry are then uploaded to PicasaWeb's * default album of "Drop Box". In the future, we might consider * adding an Album Chooser to the Preferences/login window, but only * if there's demand. **/ static void tmp_picasaweb_upload_async (GSimpleAsyncResult *result, GObject *source_object, GCancellable *cancellable) { GDataPicasaWebFile *new_file = NULL; XviewerPostasaPlugin *plugin = XVIEWER_POSTASA_PLUGIN (source_object); GDataPicasaWebService *service = plugin->priv->service; GDataPicasaWebFile *file_entry; PicasaWebUploadFileAsyncData *data; #ifdef HAVE_LIBGDATA_0_8 GDataUploadStream *upload_stream; GFileInputStream *in_stream; GFileInfo *file_info; #endif gchar *filename; GError *error = NULL; data = (PicasaWebUploadFileAsyncData*)g_async_result_get_user_data (G_ASYNC_RESULT (result)); /* get filename to set image title */ file_entry = gdata_picasaweb_file_new (NULL); filename = g_file_get_basename (data->imgfile); gdata_entry_set_title (GDATA_ENTRY (file_entry), filename); g_free (filename); #ifdef HAVE_LIBGDATA_0_8 file_info = g_file_query_info (data->imgfile, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, cancellable, &error); if (file_info == NULL) goto got_err; upload_stream = gdata_picasaweb_service_upload_file (service, NULL /* Upload to Dropbox */, file_entry, g_file_info_get_display_name (file_info), g_file_info_get_content_type (file_info), cancellable, &error); g_object_unref (file_info); if (upload_stream == NULL) goto got_err; in_stream = g_file_read (data->imgfile, cancellable, &error); if (in_stream == NULL) { g_object_unref (upload_stream); goto got_err; } if (g_output_stream_splice (G_OUTPUT_STREAM (upload_stream), G_INPUT_STREAM (in_stream), G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, cancellable, &error) == -1) { g_object_unref (upload_stream); g_object_unref (in_stream); goto got_err; } new_file = gdata_picasaweb_service_finish_file_upload (service, upload_stream, &error); g_object_unref (upload_stream); g_object_unref (in_stream); got_err: /* Jump here if any GIO/GData call doesn't return successfully. * Error handling happens below. */ #else /* libgdata-0.6 */ new_file = gdata_picasaweb_service_upload_file (service, NULL /* Uploading to Drop Box */, file_entry, data->imgfile, cancellable, &error); #endif g_object_unref (file_entry); if (new_file == NULL || error) { if (g_cancellable_is_cancelled (cancellable) == FALSE) { g_simple_async_result_set_from_error (result, error); } /* Clear errors always as cancelling creates errors too */ g_clear_error (&error); } else { g_simple_async_result_set_op_res_gboolean (result, TRUE); } if (new_file != NULL) g_object_unref (new_file); }
gboolean nautilus_customization_data_get_next_element_for_display (NautilusCustomizationData *data, char **emblem_name, GdkPixbuf **pixbuf_out, char **label_out) { GFileInfo *current_file_info; char *image_file_name; GdkPixbuf *pixbuf; GdkPixbuf *orig_pixbuf; gboolean is_reset_image; g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (emblem_name != NULL, FALSE); g_return_val_if_fail (pixbuf_out != NULL, FALSE); g_return_val_if_fail (label_out != NULL, FALSE); if (data->current_file_list == NULL) { if (data->reading_mode == READ_PUBLIC_CUSTOMIZATIONS) { if (data->private_file_list == NULL) { return FALSE; } data->reading_mode = READ_PRIVATE_CUSTOMIZATIONS; data->current_file_list = data->private_file_list; return nautilus_customization_data_get_next_element_for_display (data, emblem_name, pixbuf_out, label_out); } else { return FALSE; } } current_file_info = data->current_file_list->data; data->current_file_list = data->current_file_list->next; g_assert (current_file_info != NULL); if (!eel_istr_has_prefix (g_file_info_get_content_type (current_file_info), "image/") || eel_istr_has_prefix (g_file_info_get_name (current_file_info), ".")) { return nautilus_customization_data_get_next_element_for_display (data, emblem_name, pixbuf_out, label_out); } image_file_name = get_file_path_for_mode (data, g_file_info_get_name (current_file_info)); orig_pixbuf = gdk_pixbuf_new_from_file (image_file_name, NULL); if (orig_pixbuf == NULL) { orig_pixbuf = rsvg_pixbuf_from_file_at_max_size (image_file_name, data->maximum_icon_width, data->maximum_icon_height, NULL); } g_free (image_file_name); if (orig_pixbuf == NULL) { return nautilus_customization_data_get_next_element_for_display (data, emblem_name, pixbuf_out, label_out); } is_reset_image = eel_strcmp(g_file_info_get_name (current_file_info), RESET_IMAGE_NAME) == 0; *emblem_name = g_strdup (g_file_info_get_name (current_file_info)); if (strcmp (data->customization_name, "patterns") == 0 && data->pattern_frame != NULL) { pixbuf = nautilus_customization_make_pattern_chit (orig_pixbuf, data->pattern_frame, FALSE, is_reset_image); } else { pixbuf = eel_gdk_pixbuf_scale_down_to_fit (orig_pixbuf, data->maximum_icon_width, data->maximum_icon_height); } g_object_unref (orig_pixbuf); *pixbuf_out = pixbuf; *label_out = format_name_for_display (data, g_file_info_get_name (current_file_info)); if (data->reading_mode == READ_PRIVATE_CUSTOMIZATIONS) { data->private_data_was_displayed = TRUE; } return TRUE; }
static void enumerate_next_files_async_cb (GObject *source, GAsyncResult *res, gpointer user_data) { EnumerateJob *job = user_data; GList *enumerated_files, *l; GFileInfo *info; GSList *logs; const char *content_type, *name; char *parse_string, *container_path; GFileType type; GFile *container; enumerated_files = g_file_enumerator_next_files_finish (G_FILE_ENUMERATOR (source), res, NULL); if (!enumerated_files) { enumerate_job_finish (job); return; } logs = job->logs; container = g_file_enumerator_get_container (G_FILE_ENUMERATOR (source)); container_path = g_file_get_path (container); /* TODO: we don't support grouping rotated logs yet, skip gzipped files * and those which name contains a formatted date. */ for (l = enumerated_files; l; l = l->next) { info = l->data; type = g_file_info_get_file_type (info); content_type = g_file_info_get_content_type (info); name = g_file_info_get_name (info); if (!g_file_info_get_attribute_boolean (info, "access::can-read")) { g_object_unref (info); continue; } if (type != (G_FILE_TYPE_REGULAR || G_FILE_TYPE_SYMBOLIC_LINK) || !g_content_type_is_a (content_type, "text/plain")) { g_object_unref (info); continue; } if (g_content_type_is_a (content_type, "application/x-gzip")) { g_object_unref (info); continue; } if (g_regex_match_simple ("\\d{8}$", name, 0, 0)) { g_object_unref (info); continue; } parse_string = g_build_filename (container_path, name, NULL); if (g_slist_find_custom (logs, parse_string, (GCompareFunc) g_ascii_strcasecmp) == NULL) { logs = g_slist_append (logs, parse_string); } else { g_free (parse_string); } g_object_unref (info); parse_string = NULL; } g_list_free (enumerated_files); g_object_unref (container); g_free (container_path); job->logs = logs; enumerate_job_finish (job); }
static void queryInfoCallback(GObject* source, GAsyncResult* res, gpointer data) { ResourceHandle* handle = static_cast<ResourceHandle*>(data); ResourceHandleInternal* d = handle->getInternal(); ResourceHandleClient* client = handle->client(); if (d->m_cancelled) { cleanupGioOperation(handle); return; } ResourceResponse response; char* uri = g_file_get_uri(d->m_gfile); response.setUrl(KURL(uri)); g_free(uri); GError *error = NULL; GFileInfo* info = g_file_query_info_finish(d->m_gfile, res, &error); if (error) { // FIXME: to be able to handle ftp URIs properly, we must // check if the error is G_IO_ERROR_NOT_MOUNTED, and if so, // call g_file_mount_enclosing_volume() to mount the ftp // server (and then keep track of the fact that we mounted it, // and set a timeout to unmount it later after it's been idle // for a while). cleanupGioOperation(handle); if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_FOUND) response.setHTTPStatusCode(SOUP_STATUS_NOT_FOUND); else if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_PERMISSION_DENIED) response.setHTTPStatusCode(SOUP_STATUS_FORBIDDEN); else response.setHTTPStatusCode(SOUP_STATUS_BAD_REQUEST); // ? g_error_free(error); // FIXME: do we need to fake up a response body containing the // error message? client->didReceiveResponse(handle, response); client->didFinishLoading(handle); return; } if (g_file_info_get_file_type(info) != G_FILE_TYPE_REGULAR) { // FIXME: what if the URI points to a directory? Should we // generate a listing? How? What do other backends do here? cleanupGioOperation(handle); response.setHTTPStatusCode(SOUP_STATUS_FORBIDDEN); // ? client->didReceiveResponse(handle, response); client->didFinishLoading(handle); return; } response.setMimeType(g_file_info_get_content_type(info)); response.setExpectedContentLength(g_file_info_get_size(info)); response.setHTTPStatusCode(SOUP_STATUS_OK); GTimeVal tv; g_file_info_get_modification_time(info, &tv); response.setLastModifiedDate(tv.tv_sec); client->didReceiveResponse(handle, response); g_file_read_async(d->m_gfile, G_PRIORITY_DEFAULT, d->m_cancellable, openCallback, handle); }
gint play_iter(GtkTreeIter * playiter, gint restart_second) { gchar *subtitle = NULL; gchar *audiofile = NULL; GtkTreePath *path; gchar *uri = NULL; gint count; gint playlist; gchar *title = NULL; gchar *artist = NULL; gchar *album = NULL; gchar *audio_codec; gchar *video_codec = NULL; GtkAllocation alloc; gchar *demuxer = NULL; gboolean playable = TRUE; gint width; gint height; gfloat length_value; gint i; gpointer pixbuf; gchar *buffer = NULL; gchar *message = NULL; MetaData *metadata; #ifdef GTK2_12_ENABLED GtkRecentData *recent_data; #ifdef GIO_ENABLED GFile *file; GFileInfo *file_info; #endif #endif /* if (!(gmtk_media_player_get_state(GMTK_MEDIA_PLAYER(media)) == MEDIA_STATE_UNKNOWN || gmtk_media_player_get_state(GMTK_MEDIA_PLAYER(media)) == MEDIA_STATE_QUIT)) { while (gmtk_media_player_get_state(GMTK_MEDIA_PLAYER(media)) != MEDIA_STATE_UNKNOWN) { gtk_main_iteration(); } } */ if (gtk_list_store_iter_is_valid(playliststore, playiter)) { gtk_tree_model_get(GTK_TREE_MODEL(playliststore), playiter, ITEM_COLUMN, &uri, DESCRIPTION_COLUMN, &title, LENGTH_VALUE_COLUMN, &length_value, ARTIST_COLUMN, &artist, ALBUM_COLUMN, &album, AUDIO_CODEC_COLUMN, &audio_codec, VIDEO_CODEC_COLUMN, &video_codec, VIDEO_WIDTH_COLUMN, &width, VIDEO_HEIGHT_COLUMN, &height, DEMUXER_COLUMN, &demuxer, COVERART_COLUMN, &pixbuf, SUBTITLE_COLUMN, &subtitle, AUDIOFILE_COLUMN, &audiofile, COUNT_COLUMN, &count, PLAYLIST_COLUMN, &playlist, PLAYABLE_COLUMN, &playable, -1); if (GTK_IS_TREE_SELECTION(selection)) { path = gtk_tree_model_get_path(GTK_TREE_MODEL(playliststore), playiter); if (path) { gtk_tree_selection_select_path(selection, path); if (GTK_IS_WIDGET(list)) gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(list), path, NULL, FALSE, 0, 0); buffer = gtk_tree_path_to_string(path); g_free(buffer); gtk_tree_path_free(path); } } gtk_list_store_set(playliststore, playiter, COUNT_COLUMN, count + 1, -1); } else { if (verbose > 1) printf("iter is invalid, nothing to play\n"); return 0; } if (verbose) { printf("playing - %s\n", uri); printf("is playlist %i\n", playlist); } gmtk_get_allocation(GTK_WIDGET(media), &alloc); if (width == 0 || height == 0) { alloc.width = 16; alloc.height = 16; } else { alloc.width = width; alloc.height = height; } //printf("setting window size to %i x %i\n", alloc.width, alloc.height); gtk_widget_size_allocate(GTK_WIDGET(media), &alloc); while (gtk_events_pending()) gtk_main_iteration(); /* // wait for metadata to be available on this item if (!streaming_media(uri) && !device_name(uri)) { i = 0; if (playable) { while (demuxer == NULL && i < 50) { g_free(title); g_free(artist); g_free(album); g_free(audio_codec); g_free(video_codec); g_free(demuxer); g_free(subtitle); g_free(audiofile); if (gtk_list_store_iter_is_valid(playliststore, playiter)) { gtk_tree_model_get(GTK_TREE_MODEL(playliststore), playiter, LENGTH_VALUE_COLUMN, &length_value, DESCRIPTION_COLUMN, &title, ARTIST_COLUMN, &artist, ALBUM_COLUMN, &album, AUDIO_CODEC_COLUMN, &audio_codec, VIDEO_CODEC_COLUMN, &video_codec, VIDEO_WIDTH_COLUMN, &width, VIDEO_HEIGHT_COLUMN, &height, DEMUXER_COLUMN, &demuxer, COVERART_COLUMN, &pixbuf, SUBTITLE_COLUMN, &subtitle, AUDIOFILE_COLUMN, &audiofile, COUNT_COLUMN, &count, PLAYLIST_COLUMN, &playlist, PLAYABLE_COLUMN, &playable, -1); if (!playable) { if (verbose) printf("%s is not marked as playable (%i)\n", uri, i); play_next(); return 0; } } else { if (verbose) printf("Current iter is not valid\n"); return 1; // error condition } gtk_main_iteration(); i++; if (demuxer == NULL) g_usleep(10000); } } else { if (verbose) printf("%s is not marked as playable\n", uri); play_next(); return 0; } } */ // reset audio meter for (i = 0; i < METER_BARS; i++) { buckets[i] = 0; max_buckets[i] = 0; } gmtk_media_tracker_set_text(tracker, _("Playing")); gmtk_media_tracker_set_position(tracker, (gfloat) restart_second); gmtk_media_tracker_set_length(tracker, length_value); message = g_strdup_printf("<small>\n"); if (title == NULL) { title = g_filename_display_basename(uri); } buffer = g_markup_printf_escaped("\t<big><b>%s</b></big>\n", title); message = g_strconcat(message, buffer, NULL); g_free(buffer); if (artist != NULL) { buffer = g_markup_printf_escaped("\t<i>%s</i>\n", artist); message = g_strconcat(message, buffer, NULL); g_free(buffer); } if (album != NULL) { buffer = g_markup_printf_escaped("\t%s\n", album); message = g_strconcat(message, buffer, NULL); g_free(buffer); } //buffer = g_markup_printf_escaped("\n\t%s\n", uri); //message = g_strconcat(message, buffer, NULL); //g_free(buffer); message = g_strconcat(message, "</small>", NULL); // probably not much cover art for random video files if (pixbuf == NULL && video_codec == NULL && !streaming_media(uri) && control_id == 0 && !playlist) { metadata = (MetaData *) g_new0(MetaData, 1); metadata->uri = g_strdup(uri); if (title != NULL) metadata->title = g_strstrip(g_strdup(title)); if (artist != NULL) metadata->artist = g_strstrip(g_strdup(artist)); if (album != NULL) metadata->album = g_strstrip(g_strdup(album)); g_thread_create(get_cover_art, metadata, FALSE, NULL); } else { gtk_image_clear(GTK_IMAGE(cover_art)); } g_strlcpy(idledata->media_info, message, 1024); g_strlcpy(idledata->display_name, title, 1024); g_free(message); message = gm_tempname(NULL, "mplayer-af_exportXXXXXX"); g_strlcpy(idledata->af_export, message, 1024); g_free(message); message = g_strdup(""); if (title == NULL) { title = g_filename_display_basename(uri); } //buffer = g_markup_printf_escaped("\t<b>%s</b>\n", title); //message = g_strconcat(message, buffer, NULL); //g_free(buffer); if (artist != NULL) { buffer = g_markup_printf_escaped("\t<i>%s</i>\n", artist); message = g_strconcat(message, buffer, NULL); g_free(buffer); } if (album != NULL) { buffer = g_markup_printf_escaped("\t%s\n", album); message = g_strconcat(message, buffer, NULL); g_free(buffer); } g_strlcpy(idledata->media_notification, message, 1024); g_free(message); if (control_id == 0) { set_media_label(idledata); } else { gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem_view_info), FALSE); } if (subtitles) gtk_container_forall(GTK_CONTAINER(subtitles), remove_langs, NULL); gtk_widget_set_sensitive(GTK_WIDGET(menuitem_edit_select_sub_lang), FALSE); if (tracks) gtk_container_forall(GTK_CONTAINER(tracks), remove_langs, NULL); gtk_widget_set_sensitive(GTK_WIDGET(menuitem_edit_select_audio_lang), FALSE); lang_group = NULL; audio_group = NULL; if (subtitle != NULL) { gmtk_media_player_set_attribute_string(GMTK_MEDIA_PLAYER(media), ATTRIBUTE_SUBTITLE_FILE, subtitle); g_free(subtitle); subtitle = NULL; } if (audiofile != NULL) { gmtk_media_player_set_attribute_string(GMTK_MEDIA_PLAYER(media), ATTRIBUTE_AUDIO_TRACK_FILE, audiofile); g_free(audiofile); audiofile = NULL; } /* if (g_ascii_strcasecmp(thread_data->filename, "") != 0) { if (!device_name(thread_data->filename) && !streaming_media(thread_data->filename)) { if (!g_file_test(thread_data->filename, G_FILE_TEST_EXISTS)) { error_msg = g_strdup_printf("%s not found\n", thread_data->filename); dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", error_msg); gtk_window_set_title(GTK_WINDOW(dialog), "GNOME MPlayer Error"); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); return 1; } } } */ #ifdef GTK2_12_ENABLED #ifdef GIO_ENABLED // don't put it on the recent list, if it is running in plugin mode if (control_id == 0 && !streaming_media(uri)) { recent_data = (GtkRecentData *) g_new0(GtkRecentData, 1); if (artist != NULL && strlen(artist) > 0) { recent_data->display_name = g_strdup_printf("%s - %s", artist, title); } else { recent_data->display_name = g_strdup(title); } g_strlcpy(idledata->display_name, recent_data->display_name, 1024); file = g_file_new_for_uri(uri); file_info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (file_info) { recent_data->mime_type = g_strdup(g_file_info_get_content_type(file_info)); g_object_unref(file_info); } g_object_unref(file); recent_data->app_name = g_strdup("gnome-mplayer"); recent_data->app_exec = g_strdup("gnome-mplayer %u"); if (recent_data->mime_type != NULL) { gtk_recent_manager_add_full(recent_manager, uri, recent_data); g_free(recent_data->mime_type); } g_free(recent_data->app_name); g_free(recent_data->app_exec); g_free(recent_data); } #endif #endif g_free(title); g_free(artist); g_free(album); if (demuxer != NULL) { g_strlcpy(idledata->demuxer, demuxer, 64); g_free(demuxer); } else { g_strlcpy(idledata->demuxer, "", 64); } last_x = 0; last_y = 0; idledata->width = width; idledata->height = height; idledata->retry_on_full_cache = FALSE; idledata->cachepercent = -1.0; g_strlcpy(idledata->info, uri, 1024); set_media_info(idledata); streaming = 0; gm_store = gm_pref_store_new("gnome-mplayer"); forcecache = gm_pref_store_get_boolean(gm_store, FORCECACHE); gm_pref_store_free(gm_store); if (g_ascii_strcasecmp(uri, "dvdnav://") == 0) { gtk_widget_show(menu_event_box); } else { gtk_widget_hide(menu_event_box); } if (autostart) { g_idle_add(hide_buttons, idledata); js_state = STATE_PLAYING; if (g_str_has_prefix(uri, "mmshttp") || g_str_has_prefix(uri, "http") || g_str_has_prefix(uri, "mms")) { gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_NETWORK); } else if (g_str_has_prefix(uri, "dvd") || g_str_has_prefix(uri, "dvdnav")) { gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_DVD); } else if (g_str_has_prefix(uri, "cdda")) { gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_CD); } else if (g_str_has_prefix(uri, "cddb")) { gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_CD); } else if (g_str_has_prefix(uri, "vcd")) { gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_VCD); } else if (g_str_has_prefix(uri, "tv")) { gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_TV); } else if (g_str_has_prefix(uri, "dvb")) { gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_DVB); } else if (g_str_has_prefix(uri, "file")) { gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_FILE); } else { // if all else fails it must be a network type gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_NETWORK); } gmtk_media_player_set_attribute_boolean(GMTK_MEDIA_PLAYER(media), ATTRIBUTE_PLAYLIST, playlist); gmtk_media_player_set_uri(GMTK_MEDIA_PLAYER(media), uri); gmtk_media_player_set_state(GMTK_MEDIA_PLAYER(media), MEDIA_STATE_PLAY); } return 0; }
/** * eos_shard_writer_v2_add_blob: * @self: an #EosShardWriterV2 * @name: the name of the blob to store. * @file: a file of contents to write into the shard * @content_type: (allow-none): The MIME type of the blob. Pass %NULL to * autodetect using Gio. * @flags: flags about how the data should be stored in the file * * Adds the blob at the specified file path to the shard. * * Returns some opaque identifier for the blob, to be passed to * eos_shard_writer_v2_add_blob_to_record(). */ uint64_t eos_shard_writer_v2_add_blob (EosShardWriterV2 *self, char *name, GFile *file, char *content_type, EosShardBlobFlags flags) { struct eos_shard_writer_v2_blob_entry b = {}; g_autoptr(GFileInfo) info = NULL; b.name = g_strdup (name); if (content_type == NULL) { info = g_file_query_info (file, "standard::size,standard::content-type", 0, NULL, NULL); content_type = (char *) g_file_info_get_content_type (info); } else { info = g_file_query_info (file, "standard::size", 0, NULL, NULL); } g_return_val_if_fail (strlen (name) <= EOS_SHARD_V2_BLOB_MAX_NAME_SIZE, 0); g_return_val_if_fail (strlen (content_type) <= EOS_SHARD_V2_BLOB_MAX_CONTENT_TYPE_SIZE, 0); b.sblob.flags = flags; b.sblob.uncompressed_size = g_file_info_get_size (info); /* Lock around the cpool. */ g_mutex_lock (&self->lock); b.sblob.name_offs = constant_pool_add (&self->cpool, name); b.sblob.content_type_offs = constant_pool_add (&self->cpool, content_type); g_mutex_unlock (&self->lock); /* Now deal with blob contents. */ g_autoptr(GError) error = NULL; GFileInputStream *file_stream = g_file_read (file, NULL, &error); if (!file_stream) { g_error ("Could not read from %s: %s", g_file_get_path (file), error->message); return -1; } int blob_fd; if (b.sblob.flags & EOS_SHARD_BLOB_FLAG_COMPRESSED_ZLIB) { blob_fd = compress_blob_to_tmp (G_INPUT_STREAM (file_stream)); } else { blob_fd = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (file_stream)); } /* Find the size by seeking... */ uint64_t blob_size = lseek (blob_fd, 0, SEEK_END); g_assert (blob_size >= 0); g_assert (lseek (blob_fd, 0, SEEK_SET) >= 0); /* Checksum the blob. */ g_autoptr(GChecksum) checksum = g_checksum_new (G_CHECKSUM_SHA256); uint8_t buf[4096*4]; int size; while ((size = read (blob_fd, buf, sizeof (buf))) != 0) g_checksum_update (checksum, buf, size); size_t checksum_buf_len = sizeof (b.sblob.csum); g_checksum_get_digest (checksum, b.sblob.csum, &checksum_buf_len); g_assert (checksum_buf_len == sizeof (b.sblob.csum)); /* Add the blob entry to the file. */ g_mutex_lock (&self->lock); /* Look for a checksum in our table to return early if we have it... */ off_t data_start = GPOINTER_TO_UINT (g_hash_table_lookup (self->csum_to_data_start, &b.sblob.csum)); struct eos_shard_writer_v2_blob_entry *blob = g_memdup (&b, sizeof (b)); g_ptr_array_add (self->blobs, blob); uint64_t index = self->blobs->len - 1; /* If the blob data isn't already in the file, write it in. */ if (data_start == 0) { /* Position the blob in the file, and add it to the csum table. */ int shard_fd = self->ctx.fd; data_start = self->ctx.offset; self->ctx.offset = ALIGN (self->ctx.offset + blob_size); g_hash_table_insert (self->csum_to_data_start, &blob->sblob.csum, GUINT_TO_POINTER (data_start)); /* Unlock before writing data to the file. */ g_mutex_unlock (&self->lock); off_t offset = data_start; lseek (blob_fd, 0, SEEK_SET); while ((size = read (blob_fd, buf, sizeof (buf))) != 0) { g_assert (pwrite (shard_fd, buf, size, offset) >= 0); offset += size; } } else { g_mutex_unlock (&self->lock); } blob->sblob.data_start = data_start; blob->sblob.size = blob_size; g_assert (close (blob_fd) == 0 || errno == EINTR); return index; }
static void enumerate_dir (MpdStorageDevice *self) { MpdStorageDevicePrivate *priv = GET_PRIVATE (self); GFileEnumerator *enumerator; GFileInfo *info; GError *error = NULL; g_return_if_fail (priv->dir_stack); enumerator = G_FILE_ENUMERATOR (priv->dir_stack->data); g_return_if_fail (G_IS_FILE_ENUMERATOR (enumerator)); while (NULL != (info = g_file_enumerator_next_file (enumerator, NULL, &error))) { char const *content_type = g_file_info_get_content_type (info); char const *name = g_file_info_get_name (info); /* Debug */ char *indent = g_strnfill (g_slist_length (priv->dir_stack), ' '); g_debug ("%s%s %s", indent, name, content_type); g_free (indent); /* Do not recurse into "dot" directories, they are use for trash. */ if (0 == g_strcmp0 ("inode/directory", content_type) && name[0] != '.') { char const *path = g_object_get_data (G_OBJECT (enumerator), "path"); char *subpath = g_build_filename (path, name, NULL); GFile *subdir = file_new_for_path (subpath); /* Push and recurse. */ push_dir_async (self, subdir); file_destroy (subdir); g_free (subpath); break; } else if (g_str_has_prefix (content_type, "audio/") || g_str_has_prefix (content_type, "image/") || g_str_has_prefix (content_type, "video/")) { /* Media found. */ char const *path = g_object_get_data (G_OBJECT (enumerator), "path"); char *filename = g_build_filename (path, name, NULL); priv->media_files = g_slist_prepend (priv->media_files, filename); priv->media_files_size += g_file_info_get_size (info); } g_object_unref (info); } if (info) { /* Broke out of loop, not done yet. */ g_object_unref (info); } else { /* Directory finished, pop. */ g_object_unref (enumerator); priv->dir_stack = g_slist_delete_link (priv->dir_stack, priv->dir_stack); if (priv->dir_stack) { enumerate_dir (self); } else { /* Done iterating. */ g_signal_emit_by_name (self, "has-media", (bool) priv->media_files); } } if (error) { g_critical ("%s : %s", G_STRLOC, error->message); g_clear_error (&error); } }
static inline void process_item (ProcessUserguideData *data, GFileInfo *file_info, gboolean is_dir, GError **error) { TrackerSparqlBuilder *sparql; gchar *uri; const gchar *mime_type; const gchar *urn; const gchar *parent_urn; gboolean is_iri; guint64 time_; sparql = data->sparql; uri = g_file_get_uri (data->file); mime_type = g_file_info_get_content_type (file_info); urn = get_file_urn (data->miner, data->file, &is_iri); tracker_sparql_builder_insert_silent_open (sparql, NULL); tracker_sparql_builder_graph_open (sparql, TRACKER_MINER_FS_GRAPH_URN); if (is_iri) { tracker_sparql_builder_subject_iri (sparql, urn); } else { tracker_sparql_builder_subject (sparql, urn); } tracker_sparql_builder_predicate (sparql, "a"); tracker_sparql_builder_object (sparql, "nfo:FileDataObject"); tracker_sparql_builder_object (sparql, "nie:InformationElement"); if (is_dir) { tracker_sparql_builder_object (sparql, "nfo:Folder"); } else { tracker_sparql_builder_object (sparql, "nfo:HelpDocument"); } parent_urn = tracker_miner_fs_get_parent_urn (TRACKER_MINER_FS (data->miner), data->file); if (parent_urn) { tracker_sparql_builder_predicate (sparql, "nfo:belongsToContainer"); tracker_sparql_builder_object_iri (sparql, parent_urn); } tracker_sparql_builder_predicate (sparql, "nfo:fileName"); tracker_sparql_builder_object_string (sparql, g_file_info_get_display_name (file_info)); tracker_sparql_builder_predicate (sparql, "nfo:fileSize"); tracker_sparql_builder_object_int64 (sparql, g_file_info_get_size (file_info)); time_ = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED); tracker_sparql_builder_predicate (sparql, "nfo:fileLastModified"); tracker_sparql_builder_object_date (sparql, (time_t *) &time_); time_ = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_ACCESS); tracker_sparql_builder_predicate (sparql, "nfo:fileLastAccessed"); tracker_sparql_builder_object_date (sparql, (time_t *) &time_); /* Laying the link between the IE and the DO. We use IE = DO */ tracker_sparql_builder_predicate (sparql, "nie:isStoredAs"); if (is_iri) { tracker_sparql_builder_object_iri (sparql, urn); } else { tracker_sparql_builder_object (sparql, urn); } /* The URL of the DataObject (because IE = DO, this is correct) */ tracker_sparql_builder_predicate (sparql, "nie:url"); tracker_sparql_builder_object_string (sparql, uri); tracker_sparql_builder_predicate (sparql, "nie:mimeType"); tracker_sparql_builder_object_string (sparql, mime_type); /* FIXME: Add nie:dataSource for switching different userguides? */ tracker_sparql_builder_predicate (sparql, "tracker:available"); tracker_sparql_builder_object_boolean (sparql, TRUE); if (!is_dir) { gchar *content = NULL; gchar *title = NULL; /* Get content */ parser_get_file_content (uri, MAX_EXTRACT_SIZE, &content, &title); g_message ("Adding userguide:'%s', uri:'%s'", title, uri); if (title && title[0]) { tracker_sparql_builder_predicate (sparql, "nie:title"); tracker_sparql_builder_object_unvalidated (sparql, title); } if (content && content[0]) { tracker_sparql_builder_predicate (sparql, "nie:plainTextContent"); tracker_sparql_builder_object_unvalidated (sparql, content); } g_free (content); g_free (title); } else { g_message ("Adding userguide directory:'%s'", uri); } tracker_sparql_builder_graph_close (sparql); tracker_sparql_builder_insert_close (sparql); g_free (uri); }