gchar* sourceview_io_get_mime_type (SourceviewIO* sio) { GFileInfo* file_info; if (!sio->file) return NULL; file_info = g_file_query_info (sio->file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (file_info) { gchar* mime_type = g_strdup (g_file_info_get_content_type (file_info)); g_object_unref (file_info); return mime_type; } else return NULL; }
gboolean can_trash_file (GFile *file) { GFileInfo *info; gboolean can_trash = FALSE; info = g_file_query_info (file, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info) { if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH)) { can_trash = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH); } g_object_unref (info); } return can_trash; }
/** * ctpl_input_stream_new_for_gfile: * @file: A #GFile to read * @error: Return location for errors, or %NULL to ignore them * * Creates a new #CtplInputStream for a #GFile. This is a wrapper around * g_file_read() that also sets the name of the stream to the file's name. * The errors this function can throw are those from the %G_IO_ERROR domain. * See ctpl_input_stream_new(). * * Returns: A new #CtplInputStream on success, %NULL on error. * * Since: 0.2 */ CtplInputStream * ctpl_input_stream_new_for_gfile (GFile *file, GError **error) { GFileInputStream *gfstream; CtplInputStream *stream = NULL; gfstream = g_file_read (file, NULL, error); if (gfstream) { GFileInfo *finfo; finfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, G_FILE_QUERY_INFO_NONE, NULL, error); if (finfo) { stream = ctpl_input_stream_new (G_INPUT_STREAM (gfstream), g_file_info_get_display_name (finfo)); g_object_unref (finfo); } g_object_unref (gfstream); } return stream; }
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; }
static gboolean get_uri_perm (const char *uri, const char *perm_attribute) { GFile *f; GFileInfo *info; GError *error = NULL; gboolean result; f = g_file_new_for_uri (uri); info = g_file_query_info (f, perm_attribute, 0, NULL, &error); if (error != NULL) { result = FALSE; g_error_free (error); } else { result = g_file_info_get_attribute_boolean (info, perm_attribute); } if (info != NULL) { g_object_unref (info); } g_object_unref (f); return result; }
void vfs_backend_get_file_properties (const gchar *cURI, guint64 *iSize, time_t *iLastModificationTime, gchar **cMimeType, int *iUID, int *iGID, int *iPermissionsMask) { g_return_if_fail (cURI != NULL); GFile *pFile = (*cURI == '/' ? g_file_new_for_path (cURI) : g_file_new_for_uri (cURI)); GError *erreur = NULL; const gchar *cQuery = G_FILE_ATTRIBUTE_STANDARD_SIZE"," G_FILE_ATTRIBUTE_TIME_MODIFIED"," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE"," G_FILE_ATTRIBUTE_UNIX_UID"," G_FILE_ATTRIBUTE_UNIX_GID"," G_FILE_ATTRIBUTE_ACCESS_CAN_READ"," G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE"," G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE; GFileInfo *pFileInfo = g_file_query_info (pFile, cQuery, G_FILE_QUERY_INFO_NONE, /// G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS NULL, &erreur); if (erreur != NULL) { cd_warning ("Attention : couldn't get file properties for '%s' [%s]", cURI, erreur->message); g_error_free (erreur); } *iSize = g_file_info_get_attribute_uint64 (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_SIZE); *iLastModificationTime = (time_t) g_file_info_get_attribute_uint64 (pFileInfo, G_FILE_ATTRIBUTE_TIME_MODIFIED); *cMimeType = g_file_info_get_attribute_as_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); *iUID = g_file_info_get_attribute_uint32 (pFileInfo, G_FILE_ATTRIBUTE_UNIX_UID); *iGID = g_file_info_get_attribute_uint32 (pFileInfo, G_FILE_ATTRIBUTE_UNIX_GID); int r = g_file_info_get_attribute_uint32 (pFileInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_READ); int w = g_file_info_get_attribute_uint32 (pFileInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE); int x = g_file_info_get_attribute_uint32 (pFileInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE); *iPermissionsMask = r * 8 * 8 + w * 8 + x; g_object_unref (pFileInfo); g_object_unref (pFile); }
static gboolean info_dir_is_writable( GFile *file, const gchar *path_or_uri ) { static const gchar *thisfn = "na_core_utils_info_dir_is_writable"; GError *error = NULL; GFileInfo *info; GFileType type; gboolean writable; info = g_file_query_info( file, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE "," G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, &error ); if( error ){ if( error->code != G_IO_ERROR_NOT_FOUND ){ g_warning( "%s: g_file_query_info error: %s", thisfn, error->message ); } g_error_free( error ); return( FALSE ); } type = g_file_info_get_file_type( info ); if( type != G_FILE_TYPE_DIRECTORY ){ g_debug( "%s: %s is not a directory", thisfn, path_or_uri ); g_object_unref( info ); return( FALSE ); } writable = g_file_info_get_attribute_boolean( info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE ); if( !writable ){ g_debug( "%s: %s is not writable", thisfn, path_or_uri ); } g_object_unref( info ); return( writable ); }
static gchar * gnac_profiles_mgr_get_file_name(GFile *file, guint target_type) { GError *error = NULL; GFileInfo *file_info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, &error); if (error) { libgnac_warning("%s", error->message); g_clear_error(&error); return NULL; } gchar *name = NULL; switch (target_type) { case DND_TARGET_URI: if (g_file_info_get_file_type(file_info) == G_FILE_TYPE_REGULAR) { name = g_strdup(g_file_info_get_name(file_info)); } break; case DND_TARGET_PLAIN: if (g_file_info_get_file_type(file_info) == G_FILE_TYPE_UNKNOWN) { name = g_file_get_basename(file); } break; } g_object_unref(file_info); return name; }
static gboolean recent_backend_enumerate (GVfsBackend *vfs_backend, GVfsJobEnumerate *job, const char *filename, GFileAttributeMatcher *attribute_matcher, GFileQueryInfoFlags flags) { GVfsBackendRecent *backend = G_VFS_BACKEND_RECENT (vfs_backend); GHashTableIter iter; gpointer key, value; g_assert (filename[0] == '/'); g_vfs_job_succeeded (G_VFS_JOB (job)); g_hash_table_iter_init (&iter, backend->items); while (g_hash_table_iter_next (&iter, &key, &value)) { RecentItem *item = value; GFileInfo *info; info = g_file_query_info (item->file, job->attributes, flags, G_VFS_JOB (job)->cancellable, NULL); if (info) { g_file_info_set_attribute_mask (info, attribute_matcher); recent_backend_add_info (item, info); g_vfs_job_enumerate_add_info (job, info); } } g_vfs_job_enumerate_done (job); return TRUE; }
XfdesktopVolumeIcon * xfdesktop_volume_icon_new(GVolume *volume, GdkScreen *screen) { XfdesktopVolumeIcon *volume_icon; GMount *mount; g_return_val_if_fail(G_IS_VOLUME(volume), NULL); volume_icon = g_object_new(XFDESKTOP_TYPE_VOLUME_ICON, NULL); volume_icon->priv->volume = g_object_ref(G_OBJECT(volume)); volume_icon->priv->gscreen = screen; mount = g_volume_get_mount(volume); if(mount) { volume_icon->priv->file = g_mount_get_root(mount); volume_icon->priv->file_info = g_file_query_info(volume_icon->priv->file, XFDESKTOP_FILE_INFO_NAMESPACE, G_FILE_QUERY_INFO_NONE, NULL, NULL); volume_icon->priv->filesystem_info = g_file_query_filesystem_info(volume_icon->priv->file, XFDESKTOP_FILESYSTEM_INFO_NAMESPACE, NULL, NULL); g_object_unref(mount); } g_signal_connect_swapped(G_OBJECT(gtk_icon_theme_get_for_screen(screen)), "changed", G_CALLBACK(xfdesktop_icon_invalidate_pixbuf), volume_icon); g_signal_connect(volume, "changed", G_CALLBACK(xfdesktop_volume_icon_changed), volume_icon); return volume_icon; }
/** * gtk_css_section_print: * @section: a section * @string: a #GString to print to * * Prints the @section into @string in a human-readable form. This * is a form like `gtk.css:32:1-23` to denote line 32, characters * 1 to 23 in the file gtk.css. **/ void gtk_css_section_print (const GtkCssSection *section, GString *string) { if (section->file) { GFileInfo *info; info = g_file_query_info (section->file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, NULL); if (info) { g_string_append (string, g_file_info_get_display_name (info)); g_object_unref (info); } else { g_string_append (string, "<broken file>"); } } else { g_string_append (string, "<data>"); } g_string_append_printf (string, ":%zu:%zu", section->start_location.lines + 1, section->start_location.line_chars + 1); if (section->start_location.lines != section->end_location.lines || section->start_location.line_chars != section->end_location.line_chars) { g_string_append (string, "-"); if (section->start_location.lines != section->end_location.lines) g_string_append_printf (string, "%zu:", section->end_location.lines + 1); g_string_append_printf (string, "%zu", section->end_location.line_chars + 1); } }
static GdkDragAction xfdesktop_regular_file_icon_get_allowed_drag_actions(XfdesktopIcon *icon) { GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon)); GFile *file = xfdesktop_file_icon_peek_file(XFDESKTOP_FILE_ICON(icon)); GdkDragAction actions = GDK_ACTION_LINK; /* we can always link */ if(!info) return 0; if(g_file_info_get_attribute_boolean(info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ)) { GFileInfo *parent_info; GFile *parent_file; actions |= GDK_ACTION_COPY; /* we can only move if the parent is writable */ parent_file = g_file_get_parent(file); parent_info = g_file_query_info(parent_file, XFDESKTOP_FILE_INFO_NAMESPACE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if(parent_info) { if(g_file_info_get_attribute_boolean(parent_info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { actions |= GDK_ACTION_MOVE; } g_object_unref(parent_info); } g_object_unref(parent_file); } return actions; }
static int64_t gio_fsize (VFSFile * file) { FileData * data = vfs_get_handle (file); GError * error = 0; /* Audacious core expects one of two cases: * 1) File size is known and file is seekable. * 2) File size is unknown and file is not seekable. * Therefore, we return -1 for size if file is not seekable. */ if (! g_seekable_can_seek (data->seekable)) return -1; GFileInfo * info = g_file_query_info (data->file, G_FILE_ATTRIBUTE_STANDARD_SIZE, 0, 0, & error); CHECK_ERROR ("get size of", vfs_get_filename (file)); int64_t size = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_SIZE); g_object_unref (info); return size; FAILED: return -1; }
static gboolean get_file_mtime (const char *file_uri, time_t* mtime) { GFile *file; GFileInfo *info; gboolean ret; ret = FALSE; *mtime = INVALID_MTIME; file = g_file_new_for_uri (file_uri); info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, 0, NULL, NULL); if (info) { if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) { *mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED); ret = TRUE; } g_object_unref (info); } g_object_unref (file); return ret; }
static void g_keyfile_settings_backend_keyfile_writable (GKeyfileSettingsBackend *kfsb) { GFileInfo *fileinfo; gboolean writable; fileinfo = g_file_query_info (kfsb->dir, "access::*", 0, NULL, NULL); if (fileinfo) { writable = g_file_info_get_attribute_boolean (fileinfo, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE) && g_file_info_get_attribute_boolean (fileinfo, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE); g_object_unref (fileinfo); } else writable = FALSE; if (writable != kfsb->writable) { kfsb->writable = writable; g_settings_backend_path_writable_changed (&kfsb->parent_instance, "/"); } }
static void _check_gfile_display_names(FmPath *path, GFile *child) { GFile *gf; GFileInfo *inf; if (path == NULL || _fm_path_get_display_name(path) != NULL) return; /* all done */ gf = g_file_get_parent(child); if (gf == NULL) /* file systems such as search:// don't support this */ return; inf = g_file_query_info(gf, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME"," G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); if (inf != NULL) { const char *dname = g_file_info_get_edit_name(inf); if (!dname) dname = g_file_info_get_display_name(inf); _fm_path_set_display_name(path, dname); g_object_unref(inf); } _check_gfile_display_names(fm_path_get_parent(path), gf); /* recursion */ g_object_unref(gf); }
static gboolean selection_is_image_file (GList *selection_list) { const char *mime_type; NemoDragSelectionItem *selected_item; gboolean result; GFile *location; GFileInfo *info; /* Make sure only one item is selected */ if (selection_list == NULL || selection_list->next != NULL) { return FALSE; } selected_item = selection_list->data; mime_type = NULL; location = g_file_new_for_uri (selected_item->uri); info = g_file_query_info (location, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, NULL); if (info) { mime_type = g_file_info_get_content_type (info); } result = eel_istr_has_prefix (mime_type, "image/"); if (info) { g_object_unref (info); } g_object_unref (location); return result; }
void copy_async_lcb(GObject *source_object,GAsyncResult *res,gpointer user_data) { Tcopyfile *cf = user_data; gboolean done; GError *error=NULL; /* fill in the blanks */ done = g_file_copy_finish(cf->curfile,res,&error); if (!done) { if (error->code == G_IO_ERROR_EXISTS) { gint retval; gchar *tmpstr, *dispname; GFileInfo *info =g_file_query_info (cf->curfile,"standard::display-name", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,NULL,NULL); dispname = (gchar *)g_file_info_get_display_name (info); tmpstr = g_strdup_printf(_("%s cannot be copied, it already exists, overwrite?"),dispname); retval = yes_no_dialog (_("Overwrite file?"), tmpstr); g_free(tmpstr); g_free(dispname); if (retval != -8) { g_file_copy_async(cf->curfile,cf->curdest,G_FILE_COPY_OVERWRITE, G_PRIORITY_LOW,NULL, NULL,NULL, copy_async_lcb,cf); return; } }else { g_print("ERROR copying file::%s\n",error->message); g_error_free (error); } } g_object_unref(cf->curfile); g_object_unref(cf->curdest); if (!copy_uris_process_queue(cf)) { filebrowser_backend_refresh_folder (cf->fbback); g_object_unref(cf->destdir); g_slice_free(Tcopyfile,cf); } }
static time_t theme_get_mtime(const char* name) { MateThemeMetaInfo* theme; time_t mtime = -1; theme = mate_theme_meta_info_find(name); if (theme != NULL) { GFile* file; GFileInfo* file_info; file = g_file_new_for_path(theme->path); file_info = g_file_query_info(file, G_FILE_ATTRIBUTE_TIME_MODIFIED, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref(file); if (file_info != NULL) { mtime = g_file_info_get_attribute_uint64(file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED); g_object_unref(file_info); } } return mtime; }
static GdkPixbuf * create_preview_pixbuf (const gchar *filename) { GdkPixbuf *pixbuf = NULL; MateThumbnailFactory *thumbs; const char *mime_type = NULL; GFile *gfile; GFileInfo *file_info; if (filename == NULL) return NULL; gfile = g_file_new_for_uri (filename); file_info = g_file_query_info (gfile, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, NULL); if (file_info != NULL) mime_type = g_file_info_get_content_type (file_info); g_object_unref (gfile); if (mime_type != NULL) { thumbs = mate_thumbnail_factory_new (MATE_THUMBNAIL_SIZE_NORMAL); pixbuf = mate_thumbnail_factory_generate_thumbnail (thumbs, filename, mime_type); g_object_unref (thumbs); } if (file_info != NULL) g_object_unref (file_info); return pixbuf; }
void nautilus_update_thumbnail_file_copied (const char *source_file_uri, const char *destination_file_uri) { char *old_thumbnail_path; GdkPixbuf *pixbuf; GFileInfo *file_info; GnomeThumbnailFactory *factory; GFile *destination_file; old_thumbnail_path = gnome_thumbnail_path_for_uri (source_file_uri, GNOME_THUMBNAIL_SIZE_NORMAL); if (old_thumbnail_path != NULL && g_file_test (old_thumbnail_path, G_FILE_TEST_EXISTS)) { destination_file = g_file_new_for_uri (destination_file_uri); file_info = g_file_query_info (destination_file, G_FILE_ATTRIBUTE_TIME_MODIFIED, 0, NULL, NULL); g_object_unref (destination_file); if (file_info != NULL) { pixbuf = gdk_pixbuf_new_from_file (old_thumbnail_path, NULL); if (pixbuf && gnome_thumbnail_has_uri (pixbuf, source_file_uri)) { factory = get_thumbnail_factory (); gnome_thumbnail_factory_save_thumbnail (factory, pixbuf, destination_file_uri, g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED)); } if (pixbuf) { g_object_unref (pixbuf); } g_object_unref (file_info); } } g_free (old_thumbnail_path); }
JS_EXPORT_API gboolean dentry_should_move(Entry* e) { GFile* file = e; if (G_IS_APP_INFO(e)) { file = _get_gfile_from_gapp(e); } if (!g_file_is_native(file)) { if (file != e) g_object_unref(file); return FALSE; } GFileInfo* info = g_file_query_info (file, "access::can-delete", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); if (file != e) g_object_unref(file); gboolean can_delete = g_file_info_get_attribute_boolean(info, "access::can-delete"); g_object_unref(info); return can_delete; }
GFile * nautilus_find_existing_uri_in_hierarchy (GFile *location) { GFileInfo *info; GFile *tmp; g_assert (location != NULL); location = g_object_ref (location); while (location != NULL) { info = g_file_query_info (location, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, NULL); g_object_unref (info); if (info != NULL) { return location; } tmp = location; location = g_file_get_parent (location); g_object_unref (tmp); } return location; }
/** * shell_util_get_icon_for_uri: * @text_uri: A URI * * Look up the icon that should be associated with a given URI. Handles * various special GNOME-internal cases like x-nautilus-search, etc. * * Return Value: (transfer none): A new #GIcon */ GIcon * shell_util_get_icon_for_uri (const char *text_uri) { const char *name; GFile *file; GFileInfo *info; GIcon *retval; /* Here's what we do: * + check for known file: URI * + x-nautilus-search: URI * + override burn: URI icon * + check if the URI is a mount * + override trash: URI icon for subfolders * + check for application/x-gnome-saved-search mime type and override * icon of the GFile * + use icon of the GFile */ /* this only checks file: URI */ name = shell_util_get_icon_for_uri_known_folders (text_uri); if (name) return g_themed_icon_new (name); if (g_str_has_prefix (text_uri, "x-nautilus-search:")) return g_themed_icon_new ("folder-saved-search"); /* gvfs doesn't give us a nice icon, so overriding */ if (g_str_has_prefix (text_uri, "burn:")) return g_themed_icon_new ("nautilus-cd-burner"); file = g_file_new_for_uri (text_uri); retval = shell_util_get_file_icon_if_mount (file); if (retval) return retval; /* gvfs doesn't give us a nice icon for subfolders of the trash, so * overriding */ if (g_str_has_prefix (text_uri, "trash:")) { GFile *root; root = shell_util_get_gfile_root (file); g_object_unref (file); file = root; } info = g_file_query_info (file, "standard::icon", G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (file); if (!info) return g_themed_icon_new ("gtk-file"); retval = g_file_info_get_icon (info); if (retval) g_object_ref (retval); g_object_unref (info); if (retval) return retval; return g_themed_icon_new ("gtk-file"); }
static gboolean drop_urilist (PanelWidget *panel, int pos, char *urilist) { char **uris; gboolean success; int i; uris = g_uri_list_extract_uris (urilist); success = TRUE; for (i = 0; uris[i]; i++) { GFile *file; GFileInfo *info; const char *uri; uri = uris[i]; if (g_ascii_strncasecmp (uri, "http:", strlen ("http:")) == 0 || g_ascii_strncasecmp (uri, "https:", strlen ("https:")) == 0 || g_ascii_strncasecmp (uri, "ftp:", strlen ("ftp:")) == 0 || g_ascii_strncasecmp (uri, "gopher:", strlen ("gopher:")) == 0 || g_ascii_strncasecmp (uri, "ghelp:", strlen ("ghelp:")) == 0 || g_ascii_strncasecmp (uri, "man:", strlen ("man:")) == 0 || g_ascii_strncasecmp (uri, "info:", strlen ("info:")) == 0) { /* FIXME: probably do this only on link, * in fact, on link always set up a link, * on copy do all the other stuff. Or something. */ if ( ! drop_url (panel, pos, uri)) success = FALSE; continue; } if (g_ascii_strncasecmp (uri, "x-caja-desktop:", strlen ("x-caja-desktop:")) == 0) { success = drop_caja_desktop_uri (panel, pos, uri); continue; } file = g_file_new_for_uri (uri); info = g_file_query_info (file, "standard::type," "standard::content-type," "access::can-execute", G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info) { const char *mime; GFileType type; gboolean can_exec; mime = g_file_info_get_content_type (info); type = g_file_info_get_file_type (info); can_exec = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE); if (mime && g_str_has_prefix (mime, "image")) { if (!set_background_image_from_uri (panel->toplevel, uri)) success = FALSE; } else if (mime && (!strcmp (mime, "application/x-mate-app-info") || !strcmp (mime, "application/x-desktop") || !strcmp (mime, "application/x-kde-app-info"))) { if (panel_profile_id_lists_are_writable ()) panel_launcher_create (panel->toplevel, pos, uri); else success = FALSE; } else if (type != G_FILE_TYPE_DIRECTORY && can_exec) { char *filename; filename = g_file_get_path (file); if (panel_profile_id_lists_are_writable ()) /* executable and local, so add a * launcher with it */ ask_about_launcher (filename, panel, pos, TRUE); else success = FALSE; g_free (filename); } else { if (!drop_uri (panel, pos, uri, PANEL_ICON_UNKNOWN)) success = FALSE; } } else { if (!drop_uri (panel, pos, uri, PANEL_ICON_UNKNOWN)) success = FALSE; } g_object_unref (info); g_object_unref (file); } g_strfreev (uris); return success; }
/** * Start file open operation, mount volume when needed and according to file type * create file output stream or read directory content. * @return NS_OK when file or directory opened successfully, error code otherwise */ nsresult nsGIOInputStream::DoOpen() { nsresult rv; GError *error = nullptr; NS_ASSERTION(mHandle == nullptr, "already open"); mHandle = g_file_new_for_uri( mSpec.get() ); GFileInfo *info = g_file_query_info(mHandle, "standard::*", G_FILE_QUERY_INFO_NONE, nullptr, &error); if (error) { if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_MOUNTED) { // location is not yet mounted, try to mount g_error_free(error); if (NS_IsMainThread()) return NS_ERROR_NOT_CONNECTED; error = nullptr; rv = MountVolume(); if (rv != NS_OK) { return rv; } // get info again info = g_file_query_info(mHandle, "standard::*", G_FILE_QUERY_INFO_NONE, nullptr, &error); // second try to get file info from remote files after media mount if (!info) { g_warning("Unable to get file info: %s", error->message); rv = MapGIOResult(error); g_error_free(error); return rv; } } else { g_warning("Unable to get file info: %s", error->message); rv = MapGIOResult(error); g_error_free(error); return rv; } } // Get file type to handle directories and file differently GFileType f_type = g_file_info_get_file_type(info); if (f_type == G_FILE_TYPE_DIRECTORY) { // directory rv = DoOpenDirectory(); } else if (f_type != G_FILE_TYPE_UNKNOWN) { // file rv = DoOpenFile(info); } else { g_warning("Unable to get file type."); rv = NS_ERROR_FILE_NOT_FOUND; } if (info) g_object_unref(info); return rv; }
nsresult nsIconChannel::InitWithGIO(nsIMozIconURI *aIconURI) { GIcon *icon = NULL; nsCOMPtr<nsIURL> fileURI; // Read icon content aIconURI->GetIconURL(getter_AddRefs(fileURI)); // Get icon for file specified by URI if (fileURI) { bool isFile; nsAutoCString spec; fileURI->GetAsciiSpec(spec); if (NS_SUCCEEDED(fileURI->SchemeIs("file", &isFile)) && isFile) { GFile *file = g_file_new_for_uri(spec.get()); GFileInfo *fileInfo = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_ICON, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref(file); if (fileInfo) { // icon from g_content_type_get_icon doesn't need unref icon = g_file_info_get_icon(fileInfo); if (icon) g_object_ref(icon); g_object_unref(fileInfo); } } } // Try to get icon by using MIME type if (!icon) { nsAutoCString type; aIconURI->GetContentType(type); // Try to get MIME type from file extension by using nsIMIMEService if (type.IsEmpty()) { nsCOMPtr<nsIMIMEService> ms(do_GetService("@mozilla.org/mime;1")); if (ms) { nsAutoCString fileExt; aIconURI->GetFileExtension(fileExt); ms->GetTypeFromExtension(fileExt, type); } } char *ctype = NULL; // character representation of content type if (!type.IsEmpty()) { ctype = g_content_type_from_mime_type(type.get()); } if (ctype) { icon = g_content_type_get_icon(ctype); g_free(ctype); } } // Get default icon theme GtkIconTheme *iconTheme = gtk_icon_theme_get_default(); GtkIconInfo *iconInfo = NULL; // Get icon size int32_t iconSize = GetIconSize(aIconURI); if (icon) { // Use icon and theme to get GtkIconInfo iconInfo = gtk_icon_theme_lookup_by_gicon(iconTheme, icon, iconSize, (GtkIconLookupFlags)0); g_object_unref(icon); } if (!iconInfo) { // Mozilla's mimetype lookup failed. Try the "unknown" icon. iconInfo = gtk_icon_theme_lookup_icon(iconTheme, "unknown", iconSize, (GtkIconLookupFlags)0); if (!iconInfo) { return NS_ERROR_NOT_AVAILABLE; } } // Create a GdkPixbuf buffer containing icon and scale it GdkPixbuf* buf = gtk_icon_info_load_icon(iconInfo, NULL); gtk_icon_info_free(iconInfo); if (!buf) { return NS_ERROR_UNEXPECTED; } nsresult rv = ScaleIconBuf(&buf, iconSize); NS_ENSURE_SUCCESS(rv, rv); rv = moz_gdk_pixbuf_to_channel(buf, aIconURI, getter_AddRefs(mRealChannel)); g_object_unref(buf); return rv; }
int main (int argc, char *argv[]) { gboolean kill_shell; gboolean no_default_window; gboolean browser_window; gboolean no_desktop; gboolean version; gboolean autostart_mode; const char *autostart_id; gchar *geometry; gchar **remaining; gboolean perform_self_check; CajaApplication *application; GOptionContext *context; GFile *file = NULL; GFileInfo *fileinfo = NULL; GAppInfo *appinfo = NULL; char *uri = NULL; char **uris = NULL; GPtrArray *uris_array; GError *error; int i; const GOptionEntry options[] = { #ifndef CAJA_OMIT_SELF_CHECK { "check", 'c', 0, G_OPTION_ARG_NONE, &perform_self_check, N_("Perform a quick set of self-check tests."), NULL }, #endif { "version", '\0', 0, G_OPTION_ARG_NONE, &version, N_("Show the version of the program."), NULL }, { "geometry", 'g', 0, G_OPTION_ARG_STRING, &geometry, N_("Create the initial window with the given geometry."), N_("GEOMETRY") }, { "no-default-window", 'n', 0, G_OPTION_ARG_NONE, &no_default_window, N_("Only create windows for explicitly specified URIs."), NULL }, { "no-desktop", '\0', 0, G_OPTION_ARG_NONE, &no_desktop, N_("Do not manage the desktop (ignore the preference set in the preferences dialog)."), NULL }, { "browser", '\0', 0, G_OPTION_ARG_NONE, &browser_window, N_("open a browser window."), NULL }, { "quit", 'q', 0, G_OPTION_ARG_NONE, &kill_shell, N_("Quit Caja."), NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining, NULL, N_("[URI...]") }, { NULL } }; #if defined (HAVE_MALLOPT) && defined(M_MMAP_THRESHOLD) /* Caja uses lots and lots of small and medium size allocations, * and then a few large ones for the desktop background. By default * glibc uses a dynamic treshold for how large allocations should * be mmaped. Unfortunately this triggers quickly for caja when * it does the desktop background allocations, raising the limit * such that a lot of temporary large allocations end up on the * heap and are thus not returned to the OS. To fix this we set * a hardcoded limit. I don't know what a good value is, but 128K * was the old glibc static limit, lets use that. */ mallopt (M_MMAP_THRESHOLD, 128 *1024); #endif g_thread_init (NULL); /* This will be done by gtk+ later, but for now, force it to MATE */ g_desktop_app_info_set_desktop_env ("MATE"); if (g_getenv ("CAJA_DEBUG") != NULL) { eel_make_warnings_and_criticals_stop_in_debugger (); } /* Initialize gettext support */ bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); autostart_mode = FALSE; autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID"); if (autostart_id != NULL && *autostart_id != '\0') { autostart_mode = TRUE; } /* Get parameters. */ remaining = NULL; geometry = NULL; version = FALSE; kill_shell = FALSE; no_default_window = FALSE; no_desktop = FALSE; perform_self_check = FALSE; browser_window = FALSE; g_set_prgname ("caja"); if (g_file_test (DATADIR "/applications/caja.desktop", G_FILE_TEST_EXISTS)) { egg_set_desktop_file (DATADIR "/applications/caja.desktop"); } context = g_option_context_new (_("\n\nBrowse the file system with the file manager")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_add_group (context, egg_sm_client_get_option_group ()); error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("Could not parse arguments: %s\n", error->message); g_error_free (error); return 1; } g_option_context_free (context); if (version) { g_print ("MATE caja " PACKAGE_VERSION "\n"); return 0; } #ifdef HAVE_EXEMPI xmp_init(); #endif setup_debug_log (); /* If in autostart mode (aka started by mate-session), we need to ensure * caja starts with the correct options. */ if (autostart_mode) { no_default_window = TRUE; no_desktop = FALSE; } if (perform_self_check && remaining != NULL) { /* translators: %s is an option (e.g. --check) */ fprintf (stderr, _("caja: %s cannot be used with URIs.\n"), "--check"); return EXIT_FAILURE; } if (perform_self_check && kill_shell) { fprintf (stderr, _("caja: --check cannot be used with other options.\n")); return EXIT_FAILURE; } if (kill_shell && remaining != NULL) { fprintf (stderr, _("caja: %s cannot be used with URIs.\n"), "--quit"); return EXIT_FAILURE; } if (geometry != NULL && remaining != NULL && remaining[0] != NULL && remaining[1] != NULL) { fprintf (stderr, _("caja: --geometry cannot be used with more than one URI.\n")); return EXIT_FAILURE; } /* Initialize the services that we use. */ LIBXML_TEST_VERSION /* Initialize preferences. This is needed so that proper * defaults are available before any preference peeking * happens. */ caja_global_preferences_init (); /* exit_with_last_window being FALSE, caja can run without window. */ exit_with_last_window = g_settings_get_boolean (caja_preferences, CAJA_PREFERENCES_EXIT_WITH_LAST_WINDOW); application = NULL; /* Do either the self-check or the real work. */ if (perform_self_check) { #ifndef CAJA_OMIT_SELF_CHECK /* Run the checks (each twice) for caja and libcaja-private. */ caja_run_self_checks (); caja_run_lib_self_checks (); eel_exit_if_self_checks_failed (); caja_run_self_checks (); caja_run_lib_self_checks (); eel_exit_if_self_checks_failed (); #endif } else { /* Convert args to URIs */ if (remaining != NULL) { uris_array = g_ptr_array_new (); for (i = 0; remaining[i] != NULL; i++) { file = g_file_new_for_commandline_arg (remaining[i]); if (file != NULL) { uri = g_file_get_uri (file); if (uri) { fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (fileinfo && g_file_info_get_file_type(fileinfo) == G_FILE_TYPE_DIRECTORY) { g_ptr_array_add (uris_array, uri); } else { if (fileinfo) g_object_unref (fileinfo); fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (fileinfo) { appinfo = g_app_info_get_default_for_type (g_file_info_get_content_type (fileinfo), TRUE); if (appinfo) { if (g_strcmp0 (g_app_info_get_executable (appinfo), "caja") != 0) { g_app_info_launch_default_for_uri (uri, NULL, NULL); } else { fprintf (stderr, _("caja: set erroneously as default application for '%s' content type.\n"), g_file_info_get_content_type (fileinfo)); } g_object_unref (appinfo); } g_free (uri); } else { g_ptr_array_add (uris_array, uri); } } if (fileinfo) g_object_unref (fileinfo); } if (file) g_object_unref (file); } } if (uris_array->len == 0) { /* Caja is being used only to open files (not directories), so closing */ g_strfreev (remaining); return EXIT_SUCCESS; } g_ptr_array_add (uris_array, NULL); uris = (char**) g_ptr_array_free (uris_array, FALSE); g_strfreev (remaining); } /* Run the caja application. */ application = caja_application_new (); if (egg_sm_client_is_resumed (application->smclient)) { no_default_window = TRUE; } caja_application_startup (application, kill_shell, no_default_window, no_desktop, browser_window, geometry, uris); g_strfreev (uris); if (unique_app_is_running (application->unique_app) || kill_shell) { exit_with_last_window = TRUE; } if (is_event_loop_needed ()) { gtk_main (); } } caja_icon_info_clear_caches (); if (application != NULL) { g_object_unref (application); } eel_debug_shut_down (); caja_application_save_accel_map (NULL); return EXIT_SUCCESS; }
static gboolean try_check_file (GIOSchedulerJob *io_job, GCancellable *cancellable, gpointer data) { AsyncExistenceJob *job = data; GFile *file; GFileInfo *info; GError *error; char *uri; retry: error = NULL; uri = build_uri (job); file = g_file_new_for_uri (uri); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, cancellable, &error); if (info != NULL) { /* file already exists, iterate again */ g_object_unref (info); g_object_unref (file); g_free (uri); (job->iteration)++; goto retry; } else { /* see the error to check whether the location is not accessible * or the file does not exist. */ if (error->code == G_IO_ERROR_NOT_FOUND) { GFile *parent; /* if the parent directory doesn't exist as well, forget the saved * directory and treat this as a generic error. */ parent = g_file_get_parent (file); if (!g_file_query_exists (parent, NULL)) { (job->type)++; job->iteration = 0; g_object_unref (file); g_object_unref (parent); goto retry; } else { job->retval = uri; g_object_unref (parent); goto out; } } else { /* another kind of error, assume this location is not * accessible. */ g_free (uri); if (job->type == TEST_TMP) { job->retval = NULL; goto out; } else { (job->type)++; job->iteration = 0; g_error_free (error); g_object_unref (file); goto retry; } } } out: g_error_free (error); g_object_unref (file); g_io_scheduler_job_send_to_mainloop_async (io_job, check_file_done, job, NULL); return FALSE; }
},"desktop_run_in_terminal"); #if 0 extern gboolean activate_file (GFile* file, const char* content_type, gboolean is_executable, GFile* _file_arg); Test({ g_message("activate_file start"); GFile* f = g_file_new_for_uri("file:///tmp/test_files/skype.desktop"); ArrayContainer fs; fs.data=&f; fs.num = 1; // g_message("file is GFile"); #if 1 gboolean launch_res = TRUE; GFileInfo* info = g_file_query_info(f, "standard::content-type,access::can-execute", G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info != NULL) { const char* content_type = g_file_info_get_attribute_string(info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); gboolean is_executable = g_file_info_get_attribute_boolean(info, "access::can-execute"); //ugly hack here. we just read the first GFile*. GFile* _file_arg = NULL; ArrayContainer _fs; GFile** files = NULL; if (fs.num != 0) { _fs = _normalize_array_container(fs); GFile** files = _fs.data; _file_arg = files[0]; } launch_res = activate_file (f, content_type, is_executable, _file_arg);