From 6d54d24b5e0f9138eac117eb350b818f0d2b0533 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Mon, 2 Sep 2019 13:40:48 +0300 Subject: [PATCH 1/2] thunarx: expose a new function thunarx_file_info_is_archive Signed-off-by: Sergey Ponomarev --- docs/reference/thunarx/thunarx-sections.txt | 1 + thunar/thunar-file.c | 29 +++++++++++++++++++++ thunar/thunar-file.h | 1 + thunarx/thunarx-file-info.c | 15 +++++++++++ thunarx/thunarx-file-info.h | 3 +++ thunarx/thunarx-menu-provider.c | 9 ++++--- thunarx/thunarx.symbols | 1 + 7 files changed, 55 insertions(+), 4 deletions(-) diff --git a/docs/reference/thunarx/thunarx-sections.txt b/docs/reference/thunarx/thunarx-sections.txt index d057ceb6..7271a0d2 100644 --- a/docs/reference/thunarx/thunarx-sections.txt +++ b/docs/reference/thunarx/thunarx-sections.txt @@ -12,6 +12,7 @@ thunarx_file_info_get_uri_scheme thunarx_file_info_get_mime_type thunarx_file_info_has_mime_type thunarx_file_info_is_directory +thunarx_file_info_is_archive thunarx_file_info_get_file_info thunarx_file_info_get_filesystem_info thunarx_file_info_get_location diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 1ac9a1e4..90026dc7 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -96,6 +96,7 @@ static gchar *thunar_file_info_get_mime_type (ThunarxFileInfo static gboolean thunar_file_info_has_mime_type (ThunarxFileInfo *file_info, const gchar *mime_type); static gboolean thunar_file_info_is_directory (ThunarxFileInfo *file_info); +static gboolean thunar_file_info_is_archive (ThunarxFileInfo *file_info); static GFileInfo *thunar_file_info_get_file_info (ThunarxFileInfo *file_info); static GFileInfo *thunar_file_info_get_filesystem_info (ThunarxFileInfo *file_info); static GFile *thunar_file_info_get_location (ThunarxFileInfo *file_info); @@ -394,6 +395,7 @@ thunar_file_info_init (ThunarxFileInfoIface *iface) iface->get_mime_type = thunar_file_info_get_mime_type; iface->has_mime_type = thunar_file_info_has_mime_type; iface->is_directory = thunar_file_info_is_directory; + iface->is_archive = thunar_file_info_is_archive; iface->get_file_info = thunar_file_info_get_file_info; iface->get_filesystem_info = thunar_file_info_get_filesystem_info; iface->get_location = thunar_file_info_get_location; @@ -542,6 +544,14 @@ thunar_file_info_is_directory (ThunarxFileInfo *file_info) +static gboolean +thunar_file_info_is_archive (ThunarxFileInfo *file_info) +{ + return thunar_file_is_archive (THUNAR_FILE (file_info)); +} + + + static GFileInfo * thunar_file_info_get_file_info (ThunarxFileInfo *file_info) { @@ -2763,6 +2773,25 @@ thunar_file_is_directory (const ThunarFile *file) +/** + * thunar_file_is_archive: + * @file : a #ThunarFile instance. + * + * Checks whether @file refers to an archive e.g. tar, zip, gz etc. + * + * Return value: %TRUE if @file is an archive. + **/ +gboolean +thunar_file_is_archive (const ThunarFile *file) +{ + if (thunar_file_is_directory (file)) + return FALSE; + /* TODO */ + return FALSE; +} + + + /** * thunar_file_is_shortcut: * @file : a #ThunarFile instance. diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h index 2c744391..07ca5f60 100644 --- a/thunar/thunar-file.h +++ b/thunar/thunar-file.h @@ -193,6 +193,7 @@ ThunarFileMode thunar_file_get_mode (const ThunarFile gboolean thunar_file_is_mounted (const ThunarFile *file); gboolean thunar_file_exists (const ThunarFile *file); gboolean thunar_file_is_directory (const ThunarFile *file) G_GNUC_PURE; +gboolean thunar_file_is_archive (const ThunarFile *file) G_GNUC_PURE; gboolean thunar_file_is_shortcut (const ThunarFile *file) G_GNUC_PURE; gboolean thunar_file_is_mountable (const ThunarFile *file) G_GNUC_PURE; gboolean thunar_file_is_local (const ThunarFile *file); diff --git a/thunarx/thunarx-file-info.c b/thunarx/thunarx-file-info.c index ad832062..cf86f5fb 100644 --- a/thunarx/thunarx-file-info.c +++ b/thunarx/thunarx-file-info.c @@ -291,6 +291,21 @@ thunarx_file_info_is_directory (ThunarxFileInfo *file_info) return (*THUNARX_FILE_INFO_GET_IFACE (file_info)->is_directory) (file_info); } +/** + * thunarx_file_info_is_archive: + * @file_info : a #ThunarxFileInfo. + * + * Checks whether @file_info refers to an archive e.g. tar, zip, gz etc. + * + * Return value: %TRUE if @file_info is an archive. + **/ +gboolean +thunarx_file_info_is_archive (ThunarxFileInfo *file_info) +{ + g_return_val_if_fail (THUNARX_IS_FILE_INFO (file_info), FALSE); + return (*THUNARX_FILE_INFO_GET_IFACE (file_info)->is_archive) (file_info); +} + /** diff --git a/thunarx/thunarx-file-info.h b/thunarx/thunarx-file-info.h index 4f1f9116..174c894f 100644 --- a/thunarx/thunarx-file-info.h +++ b/thunarx/thunarx-file-info.h @@ -75,6 +75,7 @@ typedef struct _ThunarxFileInfo ThunarxFileInfo; * @get_mime_type: See thunarx_file_info_get_mime_type(). * @has_mime_type: See thunarx_file_info_has_mime_type(). * @is_directory: See thunarx_file_info_is_directory(). + * @is_archive: See thunarx_file_info_is_archive(). * @get_file_info: See thunarx_file_info_get_file_info(). * @get_filesystem_info: See thunarx_filesystem_info_get_filesystem_info(). * @get_location: See thunarx_location_get_location(). @@ -104,6 +105,7 @@ struct _ThunarxFileInfoIface const gchar *mime_type); gboolean (*is_directory) (ThunarxFileInfo *file_info); + gboolean (*is_archive) (ThunarxFileInfo *file_info); GFileInfo *(*get_file_info) (ThunarxFileInfo *file_info); GFileInfo *(*get_filesystem_info) (ThunarxFileInfo *file_info); @@ -142,6 +144,7 @@ gboolean thunarx_file_info_has_mime_type (ThunarxFileInfo *file_info, const gchar *mime_type); gboolean thunarx_file_info_is_directory (ThunarxFileInfo *file_info); +gboolean thunarx_file_info_is_archive (ThunarxFileInfo *file_info); GFileInfo *thunarx_file_info_get_file_info (ThunarxFileInfo *file_info); GFileInfo *thunarx_file_info_get_filesystem_info (ThunarxFileInfo *file_info); diff --git a/thunarx/thunarx-menu-provider.c b/thunarx/thunarx-menu-provider.c index 583e0f93..e5060c3e 100644 --- a/thunarx/thunarx-menu-provider.c +++ b/thunarx/thunarx-menu-provider.c @@ -40,10 +40,11 @@ * fast as possible to method invokations by the file manager. That said, when * the file manager calls the thunarx_menu_provider_get_file_menu_items() or the * thunarx_menu_provider_get_folder_menu_items() method, the implementation in the - * extension should use only the thunarx_file_info_has_mime_type() and - * thunarx_file_info_is_directory() methods to determine the menu items that should - * be added to the file manager's context menu. Don't perform any complicated I/O - * to determine the menu items list, as that would block the whole file manager process. + * extension should use only the thunarx_file_info_has_mime_type(), + * thunarx_file_info_is_archive and thunarx_file_info_is_directory() methods + * to determine the menu items that should be added to the file manager's context menu. + * Don't perform any complicated I/O to determine the menu items list, + * as that would block the whole file manager process. * * The name of ThunarxMenuItems returned from the * thunarx_menu_provider_get_file_menu_items() and thunarx_menu_provider_get_folder_menu_items() diff --git a/thunarx/thunarx.symbols b/thunarx/thunarx.symbols index 750d55fe..5651ce4e 100644 --- a/thunarx/thunarx.symbols +++ b/thunarx/thunarx.symbols @@ -37,6 +37,7 @@ thunarx_file_info_get_uri_scheme thunarx_file_info_get_mime_type thunarx_file_info_has_mime_type thunarx_file_info_is_directory +thunarx_file_info_is_archive thunarx_file_info_get_file_info thunarx_file_info_get_filesystem_info thunarx_file_info_get_location -- 2.20.1