void ss__gth_catalog_read_metadata (GthCatalog *catalog, GthFileData *file_data) { if (g_file_info_get_attribute_status (file_data->info, "slideshow::personalize") == G_FILE_ATTRIBUTE_STATUS_SET) g_value_hash_set_boolean (catalog->attributes, "slideshow::personalize", g_file_info_get_attribute_boolean (file_data->info, "slideshow::personalize")); if (g_file_info_get_attribute_status (file_data->info, "slideshow::automatic") == G_FILE_ATTRIBUTE_STATUS_SET) g_value_hash_set_boolean (catalog->attributes, "slideshow::automatic", g_file_info_get_attribute_boolean (file_data->info, "slideshow::automatic")); if (g_file_info_get_attribute_status (file_data->info, "slideshow::wrap-around") == G_FILE_ATTRIBUTE_STATUS_SET) g_value_hash_set_boolean (catalog->attributes, "slideshow::wrap-around", g_file_info_get_attribute_boolean (file_data->info, "slideshow::wrap-around")); if (g_file_info_get_attribute_status (file_data->info, "slideshow::random-order") == G_FILE_ATTRIBUTE_STATUS_SET) g_value_hash_set_boolean (catalog->attributes, "slideshow::random-order", g_file_info_get_attribute_boolean (file_data->info, "slideshow::random-order")); if (g_file_info_get_attribute_status (file_data->info, "slideshow::delay") == G_FILE_ATTRIBUTE_STATUS_SET) g_value_hash_set_int (catalog->attributes, "slideshow::delay", g_file_info_get_attribute_int32 (file_data->info, "slideshow::delay")); if (g_file_info_get_attribute_status (file_data->info, "slideshow::transition") == G_FILE_ATTRIBUTE_STATUS_SET) g_value_hash_set_string (catalog->attributes, "slideshow::transition", g_file_info_get_attribute_string (file_data->info, "slideshow::transition")); if (g_file_info_get_attribute_status (file_data->info, "slideshow::playlist") == G_FILE_ATTRIBUTE_STATUS_SET) g_value_hash_set_stringv (catalog->attributes, "slideshow::playlist", g_file_info_get_attribute_stringv (file_data->info, "slideshow::playlist")); }
void totem_try_restore_position (Totem *totem, const char *mrl) { GFile *file; GFileInfo *file_info; const char *seek_str; if (totem->remember_position == FALSE) return; if (mrl == NULL) return; file = g_file_new_for_uri (mrl); g_debug ("trying to restore position of: %s", mrl); /* Get the file attribute containing the position */ file_info = g_file_query_info (file, SAVE_POSITION_FILE_ATTRIBUTE, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (file); if (file_info == NULL) return; seek_str = g_file_info_get_attribute_string (file_info, SAVE_POSITION_FILE_ATTRIBUTE); g_debug ("seek time: %s", seek_str); if (seek_str != NULL) totem->seek_to = g_ascii_strtoull (seek_str, NULL, 0); g_object_unref (file_info); }
static char * get_target_filename (GFile *file) { GFileInfo *info; const char *target; GFile *new_file; char *ret; info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info == NULL) return NULL; target = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI); if (target == NULL) { g_object_unref (info); return NULL; } new_file = g_file_new_for_uri (target); g_object_unref (info); ret = g_file_get_path (new_file); g_object_unref (new_file); return ret; }
static gpointer search_thread_func (gpointer user_data) { SearchThreadData *data; GFile *dir; GFileInfo *info; const char *id; data = user_data; /* Insert id for toplevel directory into visited */ dir = g_queue_peek_head (data->directories); info = g_file_query_info (dir, G_FILE_ATTRIBUTE_ID_FILE, 0, data->cancellable, NULL); if (info) { id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILE); if (id) { g_hash_table_insert (data->visited, g_strdup (id), NULL); } g_object_unref (info); } while (!g_cancellable_is_cancelled (data->cancellable) && (dir = g_queue_pop_head (data->directories)) != NULL) { visit_directory (dir, data); g_object_unref (dir); } send_batch (data); g_idle_add (search_thread_done_idle, data); return NULL; }
static void append_file_to_cmd(GFile* gf, GString* cmd) { char* file = g_file_get_path(gf); char* quote; if(file == NULL) /* trash:// gvfs is incomplete in resolving it */ { /* we can retrieve real path from GVFS >= 1.13.3 */ if(g_file_has_uri_scheme(gf, "trash")) { GFileInfo *inf; const char *orig_path; inf = g_file_query_info(gf, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI, G_FILE_QUERY_INFO_NONE, NULL, NULL); if(inf == NULL) /* failed */ return; orig_path = g_file_info_get_attribute_string(inf, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI); if(orig_path != NULL) /* success */ file = g_filename_from_uri(orig_path, NULL, NULL); g_object_unref(inf); } if(file == NULL) return; } quote = g_shell_quote(file); g_string_append(cmd, quote); g_string_append_c(cmd, ' '); g_free(quote); g_free(file); }
static void nautilus_sendto_init (NautilusSendto *nst) { int i; /* Clean up the URIs passed, and collect whether we have directories */ for (i = 0; filenames != NULL && filenames[i] != NULL; i++) { GFile *file; char *filename, *escaped, *uri; GFileInfo *info; const char *mimetype; /* We need a filename */ file = g_file_new_for_commandline_arg (filenames[i]); filename = g_file_get_path (file); if (filename == NULL) { filename = get_target_filename (file); if (filename == NULL) { g_object_unref (file); continue; } } /* Get the mime-type, and whether the file is readable */ info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE","G_FILE_ATTRIBUTE_ACCESS_CAN_READ, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (file); if (info == NULL) continue; if (g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ) == FALSE) { g_debug ("'%s' is not readable", filenames[i]); g_object_unref (info); continue; } mimetype = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE); if (g_str_equal (mimetype, "inode/directory")) nst->num_dirs++; g_object_unref (info); uri = g_filename_to_uri (filename, NULL, NULL); g_free (filename); escaped = escape_ampersands_and_commas (uri); if (escaped == NULL) { nst->file_list = g_list_prepend (nst->file_list, uri); } else { nst->file_list = g_list_prepend (nst->file_list, escaped); g_free (uri); } } nst->file_list = g_list_reverse (nst->file_list); }
static void saved_query_info_cb (GFile *location, GAsyncResult *result, GeditDocument *doc) { GFileInfo *info; const gchar *content_type = NULL; GError *error = NULL; info = g_file_query_info_finish (location, result, &error); if (error != NULL) { g_warning ("Document saving: query info error: %s", error->message); g_error_free (error); error = NULL; } doc->priv->mtime_set = FALSE; if (info != NULL) { if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) { content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); } if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) { g_file_info_get_modification_time (info, &doc->priv->mtime); doc->priv->mtime_set = TRUE; } } gedit_document_set_content_type (doc, content_type); if (info != NULL) { /* content_type (owned by info) is no longer needed. */ g_object_unref (info); } g_get_current_time (&doc->priv->time_of_last_save_or_load); doc->priv->externally_modified = FALSE; doc->priv->deleted = FALSE; doc->priv->create = FALSE; set_readonly (doc, FALSE); gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), FALSE); save_encoding_metadata (doc); /* Async operation finished. */ g_object_unref (doc); }
static void loaded_query_info_cb (GFile *location, GAsyncResult *result, GeditDocument *doc) { GFileInfo *info; GError *error = NULL; info = g_file_query_info_finish (location, result, &error); if (error != NULL) { /* Ignore not found error as it can happen when opening a * non-existent file from the command line. */ if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_NOT_FOUND) { g_warning ("Document loading: query info error: %s", error->message); } g_error_free (error); error = NULL; } if (info != NULL) { if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) { const gchar *content_type; content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); gedit_document_set_content_type (doc, content_type); } if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { gboolean read_only; read_only = !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); set_readonly (doc, read_only); } if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) { g_file_info_get_modification_time (info, &doc->priv->mtime); doc->priv->mtime_set = TRUE; } g_object_unref (info); } /* Async operation finished. */ g_object_unref (doc); }
static gint64 get_place_for_test (GthTest *test, GthFileData *file, gconstpointer *data, GDestroyNotify *data_destroy_func) { *data = g_file_info_get_attribute_string (file->info, "comment::place"); return 0; }
static const gchar * xfdesktop_special_file_icon_peek_tooltip(XfdesktopIcon *icon) { XfdesktopSpecialFileIcon *special_file_icon = XFDESKTOP_SPECIAL_FILE_ICON(icon); if(!special_file_icon->priv->tooltip) { GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon)); if(!info) return NULL; if(XFDESKTOP_SPECIAL_FILE_ICON_TRASH == special_file_icon->priv->type) { if(special_file_icon->priv->trash_item_count == 0) { special_file_icon->priv->tooltip = g_strdup(_("Trash is empty")); } else { special_file_icon->priv->tooltip = g_strdup_printf(g_dngettext(GETTEXT_PACKAGE, _("Trash contains one item"), _("Trash contains %d items"), special_file_icon->priv->trash_item_count), special_file_icon->priv->trash_item_count); } } else { const gchar *description; gchar *size_string, *time_string; guint64 size, mtime; if(special_file_icon->priv->type == XFDESKTOP_SPECIAL_FILE_ICON_FILESYSTEM) description = _("File System"); else if(special_file_icon->priv->type == XFDESKTOP_SPECIAL_FILE_ICON_HOME) description = _("Home"); else { description = g_file_info_get_attribute_string(info, G_FILE_ATTRIBUTE_STANDARD_DESCRIPTION); } 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); special_file_icon->priv->tooltip = g_strdup_printf(_("%s\nSize: %s\nLast modified: %s"), description, size_string, time_string); g_free(size_string); g_free(time_string); } } return special_file_icon->priv->tooltip; }
static gboolean check_same_fs (GFile *file1, GFile *file2) { GFileInfo *info1, *info2; const char *id1, *id2; gboolean res; info1 = g_file_query_info (file1, G_FILE_ATTRIBUTE_ID_FILESYSTEM, 0, NULL, NULL); if (info1 == NULL) { return FALSE; } id1 = g_file_info_get_attribute_string (info1, G_FILE_ATTRIBUTE_ID_FILESYSTEM); if (id1 == NULL) { g_object_unref (info1); return FALSE; } info2 = g_file_query_info (file2, G_FILE_ATTRIBUTE_ID_FILESYSTEM, 0, NULL, NULL); if (info2 == NULL) { g_object_unref (info1); return FALSE; } id2 = g_file_info_get_attribute_string (info2, G_FILE_ATTRIBUTE_ID_FILESYSTEM); if (id2 == NULL) { g_object_unref (info1); g_object_unref (info2); return FALSE; } res = strcmp (id1, id2) == 0; g_object_unref (info1); g_object_unref (info2); return res; }
int recurseDirs(const char *path, ThreadManager *threadman) { GValue message = {0,}; g_value_init(&message,G_TYPE_STRING); g_value_set_string(&message,"busy"); g_object_set_property(G_OBJECT(threadman),"status", &message); g_value_unset(&message); if(path==NULL) { return 1; } sleep(1); GFile *dir = g_file_new_for_path(path); GFileEnumerator *fileEnumerator; GError *errorHandler=NULL; fileEnumerator = g_file_enumerate_children(dir,"standard::*",G_FILE_QUERY_INFO_NONE,NULL,&errorHandler); if(errorHandler!=NULL) { fprintf(stderr,"ERROR: %s\n",errorHandler->message); g_error_free(errorHandler); return 1; } if(fileEnumerator!=NULL) { GFileInfo *finfo = g_file_enumerator_next_file(fileEnumerator,NULL,NULL); while(finfo!=NULL) { if(!g_file_info_get_is_hidden(finfo)) { const gchar *name; char *fullPath; name = g_file_info_get_name(finfo); fullPath = strdup(path); fullPath = realloc(fullPath,strlen(path)+3+strlen(name)); strcat(fullPath,"/"); strcat(fullPath,name); if(g_file_info_get_file_type(finfo)==G_FILE_TYPE_DIRECTORY) { int res = recurseDirs(fullPath,threadman); if(res!=0) { fprintf(stderr,"Error with %s\n",fullPath); } } else { const gchar *type = g_file_info_get_attribute_string(finfo,G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); if(strcmp(type,"audio/mpeg")==0) { addToIndex(name,fullPath,type); } } free(fullPath); } finfo = g_file_enumerator_next_file(fileEnumerator,NULL,NULL); } g_object_unref(fileEnumerator); } return 0; }
static void rename_torrent_and_unref_file (GFile * file) { GFileInfo * info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME, 0, NULL, NULL); const char * old_name = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME); char * new_name = g_strdup_printf ("%s.added", old_name); GFile * new_file = g_file_set_display_name (file, new_name, NULL, NULL); g_object_unref (G_OBJECT (new_file)); g_free (new_name); g_object_unref (G_OBJECT (info)); g_object_unref (G_OBJECT (file)); }
/** * gedit_document_get_metadata: * @doc: a #GeditDocument * @key: name of the key * * Gets the metadata assigned to @key. * * Returns: the value assigned to @key. Free with g_free(). */ gchar * gedit_document_get_metadata (GeditDocument *doc, const gchar *key) { g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL); g_return_val_if_fail (key != NULL, NULL); if (doc->priv->metadata_info != NULL && g_file_info_has_attribute (doc->priv->metadata_info, key)) { return g_strdup (g_file_info_get_attribute_string (doc->priv->metadata_info, key)); } return NULL; }
/** * mcm_utils_is_icc_profile: **/ gboolean mcm_utils_is_icc_profile (GFile *file) { GFileInfo *info; const gchar *type; GError *error = NULL; gboolean ret = FALSE; gchar *filename = NULL; /* get content type for file */ filename = g_file_get_uri (file); if (filename == NULL) filename = g_file_get_path (file); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, &error); if (info != NULL) { type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); if (g_strcmp0 (type, "application/vnd.iccprofile") == 0) { ret = TRUE; goto out; } } else { egg_warning ("failed to get content type of %s: %s", filename, error->message); g_error_free (error); } /* fall back if we have not got a new enought s-m-i */ if (g_str_has_suffix (filename, ".icc")) { ret = TRUE; goto out; } if (g_str_has_suffix (filename, ".icm")) { ret = TRUE; goto out; } if (g_str_has_suffix (filename, ".ICC")) { ret = TRUE; goto out; } if (g_str_has_suffix (filename, ".ICM")) { ret = TRUE; goto out; } out: if (info != NULL) g_object_unref (info); g_free (filename); return ret; }
static gchar * get_metadata_from_gvfs (GeditDocument *doc, const gchar *key) { GeditDocumentPrivate *priv; priv = gedit_document_get_instance_private (doc); if (priv->metadata_info != NULL && g_file_info_has_attribute (priv->metadata_info, key)) { return g_strdup (g_file_info_get_attribute_string (priv->metadata_info, key)); } return NULL; }
static char * gs_file_get_target_path (GFile *file) { GFileInfo *info; const char *target; char *path; info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info == NULL) return NULL; target = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI); path = g_filename_from_uri (target, NULL, NULL); g_object_unref (info); return path; }
static int get_file_owner (const gchar * filepath) { int owner; GFile *fhandle = g_file_new_for_path(filepath); GFileInfo * finfo = g_file_query_info(fhandle, G_FILE_ATTRIBUTE_OWNER_USER, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (finfo == NULL) { owner = g_access(filepath, W_OK); } else { owner = g_strcmp0(g_file_info_get_attribute_string(finfo, G_FILE_ATTRIBUTE_OWNER_USER), g_get_user_name()); g_object_unref(finfo); } g_object_unref(fhandle); return owner; }
static gchar *_cd_find_target_uri (const gchar *cBaseURI) { GError *erreur = NULL; GFile *pFile = g_file_new_for_uri (cBaseURI); GFileInfo *pFileInfo = g_file_query_info (pFile, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &erreur); g_object_unref (pFile); if (erreur != NULL) { cd_warning ("Attention : %s", erreur->message); g_error_free (erreur); return NULL; } gchar *cTargetURI = g_strdup (g_file_info_get_attribute_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI)); g_object_unref (pFileInfo); return cTargetURI; }
static char * shell_util_get_file_description (GFile *file) { GFileInfo *info; char *ret; ret = NULL; info = g_file_query_info (file, "standard::description", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); if (info) { ret = g_strdup (g_file_info_get_attribute_string(info, G_FILE_ATTRIBUTE_STANDARD_DESCRIPTION)); g_object_unref (info); } return ret; }
static gchar* ldsm_get_fs_id_for_path (const gchar *path) { GFile *file; GFileInfo *fileinfo; gchar *attr_id_fs; file = g_file_new_for_path (path); fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_ID_FILESYSTEM, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); if (fileinfo) { attr_id_fs = g_strdup (g_file_info_get_attribute_string (fileinfo, G_FILE_ATTRIBUTE_ID_FILESYSTEM)); g_object_unref (fileinfo); } else { attr_id_fs = NULL; } g_object_unref (file); return attr_id_fs; }
static void search_results_populate (IdolTrackerWidget *widget, const gchar *uri) { GFile *file; GFileInfo *info; GError *error = NULL; file = g_file_new_for_uri (uri); info = g_file_query_info (file, "standard::display-name,thumbnail::path", G_FILE_QUERY_INFO_NONE, NULL, &error); if (error == NULL) { GtkTreeIter iter; GdkPixbuf *thumbnail = NULL; const gchar *thumbnail_path; gtk_list_store_append (GTK_LIST_STORE (widget->priv->result_store), &iter); /* Acquire an iterator */ thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); if (thumbnail_path != NULL) thumbnail = gdk_pixbuf_new_from_file (thumbnail_path, NULL); gtk_list_store_set (GTK_LIST_STORE (widget->priv->result_store), &iter, IMAGE_COLUMN, thumbnail, FILE_COLUMN, uri, NAME_COLUMN, g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME), -1); if (thumbnail != NULL) g_object_unref (thumbnail); } else { /* Display an error */ gchar *message = g_strdup_printf (_("Could not get name and thumbnail for %s: %s"), uri, error->message); idol_interface_error_blocking (_("File Error"), message, NULL); g_free (message); g_error_free (error); } g_object_unref (info); g_object_unref (file); }
/** * gs_utils_get_content_type: * @file: A GFile * @cancellable: A #GCancellable, or %NULL * @error: A #GError, or %NULL * * Gets the standard content type for a file. * * Returns: the content type, or %NULL, e.g. "text/plain" */ gchar * gs_utils_get_content_type (GFile *file, GCancellable *cancellable, GError **error) { const gchar *tmp; g_autoptr(GFileInfo) info = NULL; /* get content type */ info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, cancellable, error); if (info == NULL) return NULL; tmp = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); if (tmp == NULL) return NULL; return g_strdup (tmp); }
static void loaded_query_info_cb (GFile *location, GAsyncResult *result, GeditDocument *doc) { GFileInfo *info; GError *error = NULL; info = g_file_query_info_finish (location, result, &error); if (error != NULL) { /* Ignore not found error as it can happen when opening a * non-existent file from the command line. */ if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_NOT_FOUND) { g_warning ("Document loading: query info error: %s", error->message); } g_error_free (error); error = NULL; } if (info != NULL && g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) { const gchar *content_type; content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); set_content_type (doc, content_type); } g_clear_object (&info); /* Async operation finished. */ g_object_unref (doc); }
/* FIXME: This should probably be an inline */ static gboolean file_info_is_image (GFileInfo *info) { gboolean is_image; const char *content_type; g_return_val_if_fail (info != NULL, FALSE); if (! g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) { return FALSE; } content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); if (content_type == NULL) { return FALSE; } is_image = (strcmp (content_type, "application/x-cd-image") == 0); return is_image; }
/** * gs_plugin_packagekit_refresh_content_type_matches: */ static gboolean gs_plugin_packagekit_refresh_content_type_matches (const gchar *filename, gboolean *matches, GCancellable *cancellable, GError **error) { const gchar *tmp; guint i; g_autoptr(GFile) file = NULL; g_autoptr(GFileInfo) info = NULL; const gchar *mimetypes[] = { "application/x-app-package", "application/x-deb", "application/x-redhat-package-manager", "application/x-rpm", NULL }; /* get content type */ file = g_file_new_for_path (filename); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, cancellable, error); if (info == NULL) return FALSE; tmp = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); /* match any */ *matches = FALSE; for (i = 0; mimetypes[i] != NULL; i++) { if (g_strcmp0 (tmp, mimetypes[i]) == 0) { *matches = TRUE; break; } } return TRUE; }
static gboolean get_etag_xattr(const char *fn, CurlDownloadOptions *cdo) { gboolean result = FALSE; GFileInfo *fileinfo; GFile *file; file = g_file_new_for_path(fn); fileinfo = g_file_query_info(file, VIKING_ETAG_XATTR, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (fileinfo) { const char *etag = g_file_info_get_attribute_string(fileinfo, VIKING_ETAG_XATTR); if (etag) { cdo->etag = g_strdup(etag); result = !!cdo->etag; } g_object_unref(fileinfo); } g_object_unref(file); if (result) g_debug("%s: Get etag (xattr) from %s: %s", __FUNCTION__, fn, cdo->etag); return result; }
void GioLister::DeviceInfo::ReadMountInfo(GMount* mount) { // Get basic information this->mount.reset_without_add(mount); if (!mount) return; mount_name = ConvertAndFree(g_mount_get_name(mount)); // Get the icon name(s) mount_icon_names.clear(); GIcon* icon = g_mount_get_icon(mount); if (G_IS_THEMED_ICON(icon)) { const char* const * icons = g_themed_icon_get_names(G_THEMED_ICON(icon)); for (const char* const * p = icons ; *p ; ++p) { mount_icon_names << QString::fromUtf8(*p); } } g_object_unref(icon); GFile* root = g_mount_get_root(mount); // Get the mount path mount_path = ConvertAndFree(g_file_get_path(root)); mount_uri = ConvertAndFree(g_file_get_uri(root)); // Do a sanity check to make sure the root is actually this mount - when a // device is unmounted GIO sends a changed signal before the removed signal, // and we end up reading information about the / filesystem by mistake. GError* error = NULL; GMount* actual_mount = g_file_find_enclosing_mount(root, NULL, &error); if (error || !actual_mount) { g_error_free(error); invalid_enclosing_mount = true; } else if (actual_mount) { g_object_unref(actual_mount); } // Query the filesystem info for size, free space, and type error = NULL; GFileInfo* info = g_file_query_filesystem_info(root, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE "," G_FILE_ATTRIBUTE_FILESYSTEM_FREE "," G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, NULL, &error); if (error) { qLog(Warning) << error->message; g_error_free(error); } else { filesystem_size = g_file_info_get_attribute_uint64( info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); filesystem_free = g_file_info_get_attribute_uint64( info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE); filesystem_type = QString::fromUtf8(g_file_info_get_attribute_string( info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE)); g_object_unref(info); } // Query the file's info for a filesystem ID // Only afc devices (that I know of) give reliably unique IDs if (filesystem_type == "afc") { error = NULL; info = g_file_query_info(root, G_FILE_ATTRIBUTE_ID_FILESYSTEM, G_FILE_QUERY_INFO_NONE, NULL, &error); if (error) { qLog(Warning) << error->message; g_error_free(error); } else { mount_uuid = QString::fromUtf8(g_file_info_get_attribute_string( info, G_FILE_ATTRIBUTE_ID_FILESYSTEM)); g_object_unref(info); } } g_object_unref(root); }
void dlg_sort_order (GthBrowser *browser) { DialogData *data; GtkListStore *selection_model; GtkCellRenderer *renderer; GthFileData *file_data; GList *sort_types; GList *scan; GthFileDataSort *current_sort_type; gboolean sort_inverse; int i, i_active; if (gth_browser_get_dialog (browser, "sort-order") != NULL) { gtk_window_present (GTK_WINDOW (gth_browser_get_dialog (browser, "sort-order"))); return; } data = g_new0 (DialogData, 1); data->browser = browser; data->builder = _gtk_builder_new_from_file ("sort-order.ui", NULL); /* Get the widgets. */ data->dialog = _gtk_builder_get_widget (data->builder, "sort_order_dialog"); gth_browser_set_dialog (browser, "sort-order", data->dialog); g_object_set_data (G_OBJECT (data->dialog), "dialog_data", data); /* Set widgets data. */ selection_model = gtk_list_store_new (2, G_TYPE_POINTER, G_TYPE_STRING); data->sort_by_combobox = gtk_combo_box_new_with_model (GTK_TREE_MODEL (selection_model)); g_object_unref (selection_model); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (data->sort_by_combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (data->sort_by_combobox), renderer, "text", SELECTION_COLUMN_NAME, NULL); file_data = gth_browser_get_location_data (data->browser); if (file_data != NULL) { current_sort_type = gth_main_get_sort_type (g_file_info_get_attribute_string (file_data->info, "sort::type")); sort_inverse = g_file_info_get_attribute_boolean (file_data->info, "sort::inverse"); } else gth_browser_get_sort_order (data->browser, ¤t_sort_type, &sort_inverse); sort_types = gth_main_get_all_sort_types (); for (i = 0, i_active = 0, scan = sort_types; scan; scan = scan->next, i++) { GthFileDataSort *sort_type = scan->data; GtkTreeIter iter; if (strcmp (sort_type->name, current_sort_type->name) == 0) i_active = i; gtk_list_store_append (selection_model, &iter); gtk_list_store_set (selection_model, &iter, SELECTION_COLUMN_DATA, sort_type, SELECTION_COLUMN_NAME, _(sort_type->display_name), -1); } g_list_free (sort_types); gtk_combo_box_set_active (GTK_COMBO_BOX (data->sort_by_combobox), i_active); gtk_widget_show (data->sort_by_combobox); gtk_container_add (GTK_CONTAINER (GET_WIDGET ("sort_by_hbox")), data->sort_by_combobox); gtk_label_set_use_underline (GTK_LABEL (GET_WIDGET ("sort_by_label")), TRUE); gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("sort_by_label")), data->sort_by_combobox); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("inverse_checkbutton")), sort_inverse); /* Set the signals handlers. */ g_signal_connect (G_OBJECT (data->dialog), "destroy", G_CALLBACK (destroy_cb), data); g_signal_connect_swapped (GET_WIDGET ("close_button"), "clicked", G_CALLBACK (gtk_widget_destroy), G_OBJECT (data->dialog)); g_signal_connect (GET_WIDGET ("inverse_checkbutton"), "toggled", G_CALLBACK (apply_sort_order), data); g_signal_connect (data->sort_by_combobox, "changed", G_CALLBACK (apply_sort_order), data); /* run dialog. */ gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (browser)); gtk_window_set_modal (GTK_WINDOW (data->dialog), FALSE); gtk_widget_show (data->dialog); }
void dlg_sort_order (GthBrowser *browser) { DialogData *data; GtkWidget *first_button; GthFileData *file_data; GList *scan; gboolean sort_inverse; if (gth_browser_get_dialog (browser, "sort-order") != NULL) { gtk_window_present (GTK_WINDOW (gth_browser_get_dialog (browser, "sort-order"))); return; } data = g_new0 (DialogData, 1); data->browser = browser; data->builder = _gtk_builder_new_from_file ("sort-order.ui", NULL); /* Get the widgets. */ data->dialog = g_object_new (GTK_TYPE_DIALOG, "title", _("Sort By"), "transient-for", GTK_WINDOW (browser), "modal", FALSE, "destroy-with-parent", FALSE, "use-header-bar", _gtk_settings_get_dialogs_use_header (), NULL); gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (data->dialog))), _gtk_builder_get_widget (data->builder, "dialog_content")); gtk_dialog_add_buttons (GTK_DIALOG (data->dialog), _GTK_LABEL_OK, GTK_RESPONSE_CLOSE, NULL); gth_browser_set_dialog (browser, "sort-order", data->dialog); g_object_set_data (G_OBJECT (data->dialog), "dialog_data", data); /* Set widgets data. */ file_data = gth_browser_get_location_data (data->browser); if (file_data != NULL) { data->current_sort_type = gth_main_get_sort_type (g_file_info_get_attribute_string (file_data->info, "sort::type")); sort_inverse = g_file_info_get_attribute_boolean (file_data->info, "sort::inverse"); } else gth_browser_get_sort_order (data->browser, &data->current_sort_type, &sort_inverse); first_button = NULL; data->sort_types = gth_main_get_all_sort_types (); for (scan = data->sort_types; scan; scan = scan->next) { GthFileDataSort *sort_type = scan->data; GtkWidget *button; ButtonData *button_data; button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (first_button), _(sort_type->display_name)); if (scan == data->sort_types) first_button = button; gtk_widget_show (button); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("sort_order_box")), button, FALSE, FALSE, 0); if (strcmp (sort_type->name, data->current_sort_type->name) == 0) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); button_data = g_new0 (ButtonData, 1); button_data->data = data; button_data->sort_type = sort_type; g_signal_connect_data (button, "toggled", G_CALLBACK (order_button_toggled_cb), button_data, (GClosureNotify) button_data_free, 0); } gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("inverse_checkbutton")), sort_inverse); /* Set the signals handlers. */ g_signal_connect (G_OBJECT (data->dialog), "destroy", G_CALLBACK (destroy_cb), data); g_signal_connect_swapped (gtk_dialog_get_widget_for_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_CLOSE), "clicked", G_CALLBACK (gtk_widget_destroy), G_OBJECT (data->dialog)); g_signal_connect (GET_WIDGET ("inverse_checkbutton"), "toggled", G_CALLBACK (apply_sort_order), data); /* run dialog. */ gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (browser)); gtk_window_set_modal (GTK_WINDOW (data->dialog), FALSE); gtk_widget_show (data->dialog); }