Reduce includes of gtkfilesystem.h

Move a few non-filesystem helpers to gtkfileutils.h,
and drop the include in all the places where it isn't needed.
This commit is contained in:
Matthias Clasen 2020-07-11 18:11:32 -04:00
parent 053223bf65
commit 0210850e86
14 changed files with 84 additions and 96 deletions

View File

@ -26,7 +26,6 @@
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooserembed.h"
#include "gtkfilesystem.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"
#include "gtkintl.h"

View File

@ -25,7 +25,7 @@
#include "gtkcelllayout.h"
#include "gtkcellrenderertext.h"
#include "gtkentryprivate.h"
#include "gtkfilesystemmodel.h"
#include "gtkfilechooserutils.h"
#include "gtklabel.h"
#include "gtkmain.h"
#include "gtksizerequest.h"

View File

@ -19,7 +19,6 @@
#ifndef __GTK_FILE_CHOOSER_ENTRY_H__
#define __GTK_FILE_CHOOSER_ENTRY_H__
#include "gtkfilesystem.h"
#include "gtkfilechooser.h"
G_BEGIN_DECLS

View File

@ -29,7 +29,6 @@
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooserembed.h"
#include "gtkfilesystem.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"
#include "gtkintl.h"

View File

@ -29,7 +29,6 @@
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooserembed.h"
#include "gtkfilesystem.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"
#include "gtkintl.h"

View File

@ -29,7 +29,6 @@
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooserembed.h"
#include "gtkfilesystem.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"
#include "gtkintl.h"

View File

@ -35,7 +35,6 @@
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooserembed.h"
#include "gtkfilesystem.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"
#include "gtkintl.h"

View File

@ -411,3 +411,76 @@ delegate_get_choice (GtkFileChooser *chooser,
{
return gtk_file_chooser_get_choice (get_delegate (chooser), id);
}
gboolean
_gtk_file_info_consider_as_directory (GFileInfo *info)
{
GFileType type = g_file_info_get_file_type (info);
return (type == G_FILE_TYPE_DIRECTORY ||
type == G_FILE_TYPE_MOUNTABLE ||
type == G_FILE_TYPE_SHORTCUT);
}
gboolean
_gtk_file_has_native_path (GFile *file)
{
char *local_file_path;
gboolean has_native_path;
/* Don't use g_file_is_native(), as we want to support FUSE paths if available */
local_file_path = g_file_get_path (file);
has_native_path = (local_file_path != NULL);
g_free (local_file_path);
return has_native_path;
}
gboolean
_gtk_file_consider_as_remote (GFile *file)
{
GFileInfo *info;
gboolean is_remote;
info = g_file_query_filesystem_info (file, G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE, NULL, NULL);
if (info)
{
is_remote = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE);
g_object_unref (info);
}
else
is_remote = FALSE;
return is_remote;
}
GIcon *
_gtk_file_info_get_icon (GFileInfo *info,
int icon_size,
int scale)
{
GIcon *icon;
GdkPixbuf *pixbuf;
const gchar *thumbnail_path;
thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
if (thumbnail_path)
{
pixbuf = gdk_pixbuf_new_from_file_at_size (thumbnail_path,
icon_size*scale, icon_size*scale,
NULL);
if (pixbuf != NULL)
return G_ICON (pixbuf);
}
icon = g_file_info_get_icon (info);
if (icon)
return g_object_ref (icon);
/* Use general fallback for all files without icon */
icon = g_themed_icon_new ("text-x-generic");
return icon;
}

View File

@ -49,6 +49,13 @@ GSettings *_gtk_file_chooser_get_settings_for_widget (GtkWidget *widget);
gchar * _gtk_file_chooser_label_for_file (GFile *file);
gboolean _gtk_file_info_consider_as_directory (GFileInfo *info);
gboolean _gtk_file_has_native_path (GFile *file);
gboolean _gtk_file_consider_as_remote (GFile *file);
GIcon * _gtk_file_info_get_icon (GFileInfo *info,
int icon_size,
int scale);
G_END_DECLS
#endif /* __GTK_FILE_CHOOSER_UTILS_H__ */

View File

@ -747,77 +747,3 @@ _gtk_file_system_volume_unref (GtkFileSystemVolume *volume)
G_IS_DRIVE (volume))
g_object_unref (volume);
}
/* GFileInfo helper functions */
GIcon *
_gtk_file_info_get_icon (GFileInfo *info,
int icon_size,
int scale)
{
GIcon *icon;
GdkPixbuf *pixbuf;
const gchar *thumbnail_path;
thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
if (thumbnail_path)
{
pixbuf = gdk_pixbuf_new_from_file_at_size (thumbnail_path,
icon_size*scale, icon_size*scale,
NULL);
if (pixbuf != NULL)
return G_ICON (pixbuf);
}
icon = g_file_info_get_icon (info);
if (icon)
return g_object_ref (icon);
/* Use general fallback for all files without icon */
icon = g_themed_icon_new ("text-x-generic");
return icon;
}
gboolean
_gtk_file_info_consider_as_directory (GFileInfo *info)
{
GFileType type = g_file_info_get_file_type (info);
return (type == G_FILE_TYPE_DIRECTORY ||
type == G_FILE_TYPE_MOUNTABLE ||
type == G_FILE_TYPE_SHORTCUT);
}
gboolean
_gtk_file_has_native_path (GFile *file)
{
char *local_file_path;
gboolean has_native_path;
/* Don't use g_file_is_native(), as we want to support FUSE paths if available */
local_file_path = g_file_get_path (file);
has_native_path = (local_file_path != NULL);
g_free (local_file_path);
return has_native_path;
}
gboolean
_gtk_file_consider_as_remote (GFile *file)
{
GFileInfo *info;
gboolean is_remote;
info = g_file_query_filesystem_info (file, G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE, NULL, NULL);
if (info)
{
is_remote = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE);
g_object_unref (info);
}
else
is_remote = FALSE;
return is_remote;
}

View File

@ -99,18 +99,7 @@ GIcon * _gtk_file_system_volume_get_icon (GtkFileSystemVo
GtkFileSystemVolume *_gtk_file_system_volume_ref (GtkFileSystemVolume *volume);
void _gtk_file_system_volume_unref (GtkFileSystemVolume *volume);
/* GFileInfo helper functions */
GIcon * _gtk_file_info_get_icon (GFileInfo *info,
int icon_size,
int scale);
gboolean _gtk_file_info_consider_as_directory (GFileInfo *info);
/* GFile helper functions */
gboolean _gtk_file_has_native_path (GFile *file);
gboolean _gtk_file_consider_as_remote (GFile *file);
G_END_DECLS
#endif /* __GTK_FILE_SYSTEM_H__ */

View File

@ -23,7 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include "gtkfilesystem.h"
#include "gtkfilechooserutils.h"
#include "gtkintl.h"
#include "gtkmarshalers.h"
#include "gtktreedatalist.h"

View File

@ -28,7 +28,6 @@
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooserembed.h"
#include "gtkfilesystem.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"
#include "gtkintl.h"

View File

@ -33,7 +33,7 @@
#include "gdk/gdkkeysyms.h"
#include "gtkbookmarksmanagerprivate.h"
#include "gtkcelllayout.h"
#include "gtkfilesystem.h"
#include "gtkfilechooserutils.h"
#include "gtkicontheme.h"
#include "gtkintl.h"
#include "gtkmain.h"