[file-roller] file-utils: added a prefix to the functions
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [file-roller] file-utils: added a prefix to the functions
- Date: Wed, 20 Jun 2012 20:12:14 +0000 (UTC)
commit 592ba559a3aed08b438e333c643b518daff9741a
Author: Paolo Bacchilega <paobac src gnome org>
Date: Wed Jun 20 20:37:28 2012 +0200
file-utils: added a prefix to the functions
src/actions.c | 6 +-
src/dlg-add-files.c | 3 +-
src/dlg-add-folder.c | 25 +-
src/dlg-batch-add.c | 24 +-
src/dlg-extract.c | 8 +-
src/dlg-new.c | 5 +-
src/dlg-prop.c | 6 +-
src/dlg-update.c | 6 +-
src/file-utils.c | 975 ++++++++++++----------------------------------
src/file-utils.h | 163 +++-----
src/fr-archive.c | 102 +++---
src/fr-command-7z.c | 54 ++--
src/fr-command-ace.c | 6 +-
src/fr-command-alz.c | 8 +-
src/fr-command-ar.c | 27 +-
src/fr-command-arj.c | 6 +-
src/fr-command-cfile.c | 124 +++---
src/fr-command-cpio.c | 8 +-
src/fr-command-dpkg.c | 8 +-
src/fr-command-iso.c | 12 +-
src/fr-command-jar.c | 24 +-
src/fr-command-lha.c | 8 +-
src/fr-command-lrzip.c | 6 +-
src/fr-command-rar.c | 14 +-
src/fr-command-rpm.c | 8 +-
src/fr-command-tar.c | 198 +++++-----
src/fr-command-unstuff.c | 11 +-
src/fr-command-zip.c | 10 +-
src/fr-command-zoo.c | 6 +-
src/fr-init.c | 8 +-
src/fr-window.c | 98 +++---
src/gio-utils.c | 8 +-
src/glib-utils.c | 489 +++++++++++++++++++++++-
src/glib-utils.h | 173 ++++++---
src/main.c | 3 +-
src/open-file.c | 4 +-
src/rar-utils.c | 3 +-
37 files changed, 1342 insertions(+), 1305 deletions(-)
---
diff --git a/src/actions.c b/src/actions.c
index ee4c82e..b407f4e 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -92,7 +92,7 @@ is_supported_extension (GtkWidget *file_sel,
{
int i;
for (i = 0; file_type[i] != -1; i++)
- if (file_extension_is (filename, mime_type_desc[file_type[i]].default_ext))
+ if (_g_filename_has_extension (filename, mime_type_desc[file_type[i]].default_ext))
return TRUE;
return FALSE;
}
@@ -111,7 +111,7 @@ get_full_uri (DlgNewData *data)
if ((uri == NULL) || (*uri == 0))
return NULL;
- filename = file_name_from_path (uri);
+ filename = _g_path_get_file_name (uri);
if ((filename == NULL) || (*filename == 0)) {
g_free (uri);
return NULL;
@@ -221,7 +221,7 @@ get_archive_filename_from_selector (DlgNewData *data)
debug (DEBUG_INFO, "create/save %s\n", uri);
- if (uri_exists (uri)) {
+ if (_g_uri_query_exists (uri)) {
GtkWidget *dialog;
if (! is_supported_extension (data->dialog, uri, data->supported_types)) {
diff --git a/src/dlg-add-files.c b/src/dlg-add-files.c
index 063a799..998617e 100644
--- a/src/dlg-add-files.c
+++ b/src/dlg-add-files.c
@@ -27,6 +27,7 @@
#include "file-utils.h"
#include "fr-stock.h"
#include "fr-window.h"
+#include "glib-utils.h"
#include "gtk-utils.h"
#include "preferences.h"
@@ -87,7 +88,7 @@ file_sel_response_cb (GtkWidget *widget,
/* check folder permissions. */
- if (uri_is_dir (current_folder) && ! check_permissions (current_folder, R_OK)) {
+ if (_g_uri_query_is_dir (current_folder) && ! _g_uri_check_permissions (current_folder, R_OK)) {
GtkWidget *d;
char *utf8_path;
diff --git a/src/dlg-add-folder.c b/src/dlg-add-folder.c
index fa60b13..8647f19 100644
--- a/src/dlg-add-folder.c
+++ b/src/dlg-add-folder.c
@@ -22,7 +22,6 @@
#include <config.h>
#include <string.h>
#include <unistd.h>
-
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
@@ -30,9 +29,11 @@
#include "file-utils.h"
#include "fr-stock.h"
#include "fr-window.h"
+#include "glib-utils.h"
#include "gtk-utils.h"
#include "preferences.h"
+
typedef struct {
FrWindow *window;
GSettings *settings;
@@ -117,7 +118,7 @@ file_sel_response_cb (GtkWidget *widget,
/* check folder permissions. */
- if (! check_permissions (selected_folder, R_OK)) {
+ if (! _g_uri_check_permissions (selected_folder, R_OK)) {
GtkWidget *d;
char *utf8_path;
@@ -155,8 +156,8 @@ file_sel_response_cb (GtkWidget *widget,
exclude_folders = NULL;
local_filename = g_filename_from_uri (selected_folder, NULL, NULL);
- dest_dir = build_uri (fr_window_get_current_location (window),
- file_name_from_path (local_filename),
+ dest_dir = _g_uri_build (fr_window_get_current_location (window),
+ _g_path_get_file_name (local_filename),
NULL);
fr_window_archive_add_with_wildcard (window,
@@ -374,7 +375,7 @@ dlg_add_folder_save_last_used_options (DialogData *data,
const char *options_path)
{
g_free (data->last_options);
- data->last_options = g_strdup (file_name_from_path (options_path));
+ data->last_options = g_strdup (_g_path_get_file_name (options_path));
}
@@ -443,7 +444,7 @@ dlg_add_folder_load_options (DialogData *data,
gboolean recursive;
gboolean no_symlinks;
- options_dir = get_user_config_subdirectory (ADD_FOLDER_OPTIONS_DIR, TRUE);
+ options_dir = _g_file_new_user_config_subdir (ADD_FOLDER_OPTIONS_DIR, TRUE);
options_file = g_file_get_child (options_dir, name);
file_path = g_file_get_path (options_file);
key_file = g_key_file_new ();
@@ -598,7 +599,7 @@ dlg_add_folder_save_current_options (DialogData *data,
g_key_file_set_boolean (key_file, "Options", "recursive", recursive);
g_key_file_set_boolean (key_file, "Options", "no_symlinks", no_symlinks);
- g_key_file_save (key_file, options_file);
+ _g_key_file_save (key_file, options_file);
g_key_file_free (key_file);
g_free (base_dir);
@@ -704,8 +705,8 @@ aod_update_option_list (LoadOptionsDialogData *aod_data)
gtk_list_store_clear (list_store);
- options_dir = get_user_config_subdirectory (ADD_FOLDER_OPTIONS_DIR, TRUE);
- make_directory_tree (options_dir, 0700, NULL);
+ options_dir = _g_file_new_user_config_subdir (ADD_FOLDER_OPTIONS_DIR, TRUE);
+ _g_file_make_directory_tree (options_dir, 0700, NULL);
file_enum = g_file_enumerate_children (options_dir, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &err);
if (err != NULL) {
@@ -766,7 +767,7 @@ aod_remove_cb (GtkWidget *widget,
gtk_tree_model_get (aod_data->aod_model, &iter, 1, &filename, -1);
gtk_list_store_remove (GTK_LIST_STORE (aod_data->aod_model), &iter);
- options_dir = get_user_config_subdirectory (ADD_FOLDER_OPTIONS_DIR, TRUE);
+ options_dir = _g_file_new_user_config_subdir (ADD_FOLDER_OPTIONS_DIR, TRUE);
options_file = g_file_get_child (options_dir, filename);
if (! g_file_delete (options_file, NULL, &error)) {
g_warning ("could not delete the options: %s", error->message);
@@ -873,8 +874,8 @@ save_options_cb (GtkWidget *w,
GFile *options_file;
char *opt_filename;
- options_dir = get_user_config_subdirectory (ADD_FOLDER_OPTIONS_DIR, TRUE);
- make_directory_tree (options_dir, 0700, NULL);
+ options_dir = _g_file_new_user_config_subdir (ADD_FOLDER_OPTIONS_DIR, TRUE);
+ _g_file_make_directory_tree (options_dir, 0700, NULL);
opt_filename = _gtk_request_dialog_run (
GTK_WINDOW (data->dialog),
diff --git a/src/dlg-batch-add.c b/src/dlg-batch-add.c
index c577d64..49fd578 100644
--- a/src/dlg-batch-add.c
+++ b/src/dlg-batch-add.c
@@ -185,7 +185,7 @@ add_clicked_cb (GtkWidget *widget,
return;
}
- if (! check_permissions (archive_dir, R_OK|W_OK|X_OK)) {
+ if (! _g_uri_check_permissions (archive_dir, R_OK|W_OK|X_OK)) {
GtkWidget *d;
d = _gtk_error_dialog_new (GTK_WINDOW (window),
@@ -202,7 +202,7 @@ add_clicked_cb (GtkWidget *widget,
return;
}
- if (! uri_is_dir (archive_dir)) {
+ if (! _g_uri_query_is_dir (archive_dir)) {
GtkWidget *d;
int r;
char *folder_name;
@@ -230,7 +230,7 @@ add_clicked_cb (GtkWidget *widget,
do_not_add = (r != GTK_RESPONSE_YES);
}
- if (! do_not_add && ! ensure_dir_exists (archive_dir, 0755, &error)) {
+ if (! do_not_add && ! _g_uri_ensure_dir_exists (archive_dir, 0755, &error)) {
GtkWidget *d;
d = _gtk_error_dialog_new (GTK_WINDOW (window),
@@ -276,7 +276,7 @@ add_clicked_cb (GtkWidget *widget,
g_free (tmp);
archive_file = g_strconcat (archive_dir, "/", archive_name, NULL);
- if (uri_is_dir (archive_file)) {
+ if (_g_uri_query_is_dir (archive_file)) {
GtkWidget *d;
d = _gtk_error_dialog_new (GTK_WINDOW (window),
@@ -295,7 +295,7 @@ add_clicked_cb (GtkWidget *widget,
return;
}
- if (uri_exists (archive_file)) {
+ if (_g_uri_query_exists (archive_file)) {
GtkWidget *d;
int r;
@@ -481,7 +481,7 @@ dlg_batch_add_files (FrWindow *window,
data->window = window;
data->file_list = file_list;
- data->single_file = ((file_list->next == NULL) && uri_is_file ((char*) file_list->data));
+ data->single_file = ((file_list->next == NULL) && _g_uri_query_is_file ((char*) file_list->data));
data->add_clicked = FALSE;
/* Set widgets data. */
@@ -498,25 +498,25 @@ dlg_batch_add_files (FrWindow *window,
gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("a_volume_spinbutton")), (double) g_settings_get_int (data->settings, PREF_BATCH_ADD_VOLUME_SIZE) / MEGABYTE);
first_filename = (char*) file_list->data;
- parent = remove_level_from_path (first_filename);
+ parent = _g_path_remove_level (first_filename);
if (file_list->next == NULL)
- automatic_name = g_uri_unescape_string (file_name_from_path ((char*) file_list->data), NULL);
+ automatic_name = g_uri_unescape_string (_g_path_get_file_name ((char*) file_list->data), NULL);
else {
- automatic_name = g_uri_unescape_string (file_name_from_path (parent), NULL);
+ automatic_name = g_uri_unescape_string (_g_path_get_file_name (parent), NULL);
if ((automatic_name == NULL) || (automatic_name[0] == '\0')) {
g_free (automatic_name);
- automatic_name = g_uri_unescape_string (file_name_from_path (first_filename), NULL);
+ automatic_name = g_uri_unescape_string (_g_path_get_file_name (first_filename), NULL);
}
}
_gtk_entry_set_filename_text (GTK_ENTRY (GET_WIDGET ("a_add_to_entry")), automatic_name);
g_free (automatic_name);
- if (check_permissions (parent, R_OK | W_OK))
+ if (_g_uri_check_permissions (parent, R_OK | W_OK))
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (GET_WIDGET ("a_location_filechooserbutton")), parent);
else
- gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (GET_WIDGET ("a_location_filechooserbutton")), get_home_uri ());
+ gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (GET_WIDGET ("a_location_filechooserbutton")), _g_uri_get_home ());
g_free (parent);
/* archive type combobox */
diff --git a/src/dlg-extract.c b/src/dlg-extract.c
index f7aa106..6f83ec8 100644
--- a/src/dlg-extract.c
+++ b/src/dlg-extract.c
@@ -92,7 +92,7 @@ extract_cb (GtkWidget *w,
/* check directory existence. */
- if (! uri_is_dir (extract_to_dir)) {
+ if (! _g_uri_query_is_dir (extract_to_dir)) {
if (! ForceDirectoryCreation) {
GtkWidget *d;
int r;
@@ -122,7 +122,7 @@ extract_cb (GtkWidget *w,
do_not_extract = TRUE;
}
- if (! do_not_extract && ! ensure_dir_exists (extract_to_dir, 0755, &error)) {
+ if (! do_not_extract && ! _g_uri_ensure_dir_exists (extract_to_dir, 0755, &error)) {
GtkWidget *d;
d = _gtk_error_dialog_new (GTK_WINDOW (window),
@@ -162,8 +162,8 @@ extract_cb (GtkWidget *w,
/* check extraction directory permissions. */
- if (uri_is_dir (extract_to_dir)
- && ! check_permissions (extract_to_dir, R_OK | W_OK))
+ if (_g_uri_query_is_dir (extract_to_dir)
+ && ! _g_uri_check_permissions (extract_to_dir, R_OK | W_OK))
{
GtkWidget *d;
char *utf8_path;
diff --git a/src/dlg-new.c b/src/dlg-new.c
index cbbdff4..d64fae6 100644
--- a/src/dlg-new.c
+++ b/src/dlg-new.c
@@ -27,6 +27,7 @@
#include "dlg-new.h"
#include "file-utils.h"
#include "fr-stock.h"
+#include "glib-utils.h"
#include "gtk-utils.h"
#include "fr-init.h"
#include "preferences.h"
@@ -150,7 +151,7 @@ archive_type_combo_box_changed_cb (GtkComboBox *combo_box,
char *new_basename_uft8;
new_ext = mime_type_desc[data->supported_types[idx]].default_ext;
- basename = file_name_from_path (uri);
+ basename = _g_path_get_file_name (uri);
if (g_str_has_suffix (basename, ext))
basename_noext = g_strndup (basename, strlen (basename) - strlen (ext));
else
@@ -212,7 +213,7 @@ format_chooser_selection_changed_cb (EggFileFormatChooser *format_chooser,
char *new_basename_uft8;
new_ext = mime_type_desc[data->supported_types[n_format - 1]].default_ext;
- basename = file_name_from_path (uri);
+ basename = _g_path_get_file_name (uri);
if (g_str_has_suffix (basename, ext))
basename_noext = g_strndup (basename, strlen (basename) - strlen (ext));
else
diff --git a/src/dlg-prop.c b/src/dlg-prop.c
index 1a717d8..26d39a0 100644
--- a/src/dlg-prop.c
+++ b/src/dlg-prop.c
@@ -72,7 +72,7 @@ dlg_prop (FrWindow *window)
/* Set widgets data. */
label = _gtk_builder_get_widget (data->builder, "p_path_label");
- s = remove_level_from_path (fr_window_get_archive_uri (window));
+ s = _g_path_remove_level (fr_window_get_archive_uri (window));
utf8_name = g_filename_display_name (s);
gtk_label_set_text (GTK_LABEL (label), utf8_name);
g_free (utf8_name);
@@ -93,14 +93,14 @@ dlg_prop (FrWindow *window)
/**/
label = _gtk_builder_get_widget (data->builder, "p_date_label");
- s = _g_time_to_string (get_file_mtime (fr_window_get_archive_uri (window)));
+ s = _g_time_to_string (_g_uri_get_file_mtime (fr_window_get_archive_uri (window)));
gtk_label_set_text (GTK_LABEL (label), s);
g_free (s);
/**/
label = _gtk_builder_get_widget (data->builder, "p_size_label");
- size = get_file_size (fr_window_get_archive_uri (window));
+ size = _g_uri_get_file_size (fr_window_get_archive_uri (window));
s = g_format_size (size);
gtk_label_set_text (GTK_LABEL (label), s);
g_free (s);
diff --git a/src/dlg-update.c b/src/dlg-update.c
index fc999fc..a1b2c8c 100644
--- a/src/dlg-update.c
+++ b/src/dlg-update.c
@@ -135,7 +135,7 @@ update_file_list (DialogData *data)
gtk_list_store_append (GTK_LIST_STORE (data->list_model),
&iter);
- utf8_name = g_filename_display_name (file_name_from_path (file->path));
+ utf8_name = g_filename_display_name (_g_path_get_file_name (file->path));
gtk_list_store_set (GTK_LIST_STORE (data->list_model),
&iter,
IS_SELECTED_COLUMN, TRUE,
@@ -157,7 +157,7 @@ update_file_list (DialogData *data)
/* primary text */
- file_name = g_filename_display_name (file_name_from_path (file->path));
+ file_name = g_filename_display_name (_g_path_get_file_name (file->path));
unescaped = g_uri_unescape_string (fr_window_get_archive_uri (data->window), NULL);
archive_name = g_path_get_basename (unescaped);
label = g_markup_printf_escaped (_("Update the file \"%s\" in the archive \"%s\"?"), file_name, archive_name);
@@ -393,7 +393,7 @@ dlg_update_add_file (gpointer dialog,
for (scan = data->file_list; scan; scan = scan->next) {
OpenFile *test = scan->data;
- if (uricmp (test->extracted_uri, file->extracted_uri) == 0)
+ if (_g_uri_cmp (test->extracted_uri, file->extracted_uri) == 0)
return;
}
diff --git a/src/file-utils.c b/src/file-utils.c
index eb0ffdf..8d18143 100644
--- a/src/file-utils.c
+++ b/src/file-utils.c
@@ -50,7 +50,7 @@
gboolean
-uri_exists (const char *uri)
+_g_uri_query_exists (const char *uri)
{
GFile *file;
gboolean exists;
@@ -67,8 +67,8 @@ uri_exists (const char *uri)
static gboolean
-uri_is_filetype (const char *uri,
- GFileType file_type)
+_g_uri_is_filetype (const char *uri,
+ GFileType file_type)
{
gboolean result = FALSE;
GFile *file;
@@ -99,41 +99,56 @@ uri_is_filetype (const char *uri,
gboolean
-uri_is_file (const char *uri)
+_g_uri_query_is_file (const char *uri)
{
- return uri_is_filetype (uri, G_FILE_TYPE_REGULAR);
+ return _g_uri_is_filetype (uri, G_FILE_TYPE_REGULAR);
}
gboolean
-uri_is_dir (const char *uri)
+_g_uri_query_is_dir (const char *uri)
{
- return uri_is_filetype (uri, G_FILE_TYPE_DIRECTORY);
+ return _g_uri_is_filetype (uri, G_FILE_TYPE_DIRECTORY);
}
-gboolean
-path_is_dir (const char *path)
+char *
+_g_uri_create_alternative (const char *folder,
+ const char *name)
{
- char *uri;
- gboolean result;
+ char *new_uri = NULL;
+ int n = 1;
- uri = g_filename_to_uri (path, NULL, NULL);
- result = uri_is_dir (uri);
- g_free (uri);
+ do {
+ g_free (new_uri);
+ if (n == 1)
+ new_uri = g_strconcat (folder, "/", name, NULL);
+ else
+ new_uri = g_strdup_printf ("%s/%s%%20(%d)", folder, name, n);
+ n++;
+ }
+ while (_g_uri_query_exists (new_uri));
- return result;
+ return new_uri;
}
-gboolean
-uri_is_local (const char *uri)
+
+char *
+_g_uri_create_alternative_for_uri (const char *uri)
{
- return strncmp (uri, "file://", 7) == 0;
+ char *base_uri;
+ char *new_uri;
+
+ base_uri = _g_path_remove_level (uri);
+ new_uri = _g_uri_create_alternative (base_uri, _g_path_get_file_name (uri));
+ g_free (base_uri);
+
+ return new_uri;
}
gboolean
-dir_is_empty (const char *uri)
+_g_uri_query_dir_is_empty (const char *uri)
{
GFile *file;
GFileEnumerator *file_enum;
@@ -175,7 +190,7 @@ dir_is_empty (const char *uri)
gboolean
-dir_contains_one_object (const char *uri)
+_g_uri_dir_contains_one_object (const char *uri)
{
GFile *file;
GFileEnumerator *file_enum;
@@ -229,7 +244,7 @@ dir_contains_one_object (const char *uri)
char *
-get_dir_content_if_unique (const char *uri)
+_g_uri_get_dir_content_if_unique (const char *uri)
{
GFile *file;
GFileEnumerator *file_enum;
@@ -274,7 +289,7 @@ get_dir_content_if_unique (const char *uri)
break;
}
- content_uri = build_uri (uri, name, NULL);
+ content_uri = _g_uri_build (uri, name, NULL);
g_object_unref (info);
}
@@ -290,40 +305,8 @@ get_dir_content_if_unique (const char *uri)
}
-/* Check whether the dirname is contained in filename */
-gboolean
-path_in_path (const char *dirname,
- const char *filename)
-{
- int dirname_l, filename_l, separator_position;
-
- if ((dirname == NULL) || (filename == NULL))
- return FALSE;
-
- dirname_l = strlen (dirname);
- filename_l = strlen (filename);
-
- if ((dirname_l == filename_l + 1)
- && (dirname[dirname_l - 1] == '/'))
- return FALSE;
-
- if ((filename_l == dirname_l + 1)
- && (filename[filename_l - 1] == '/'))
- return FALSE;
-
- if (dirname[dirname_l - 1] == '/')
- separator_position = dirname_l - 1;
- else
- separator_position = dirname_l;
-
- return ((filename_l > dirname_l)
- && (strncmp (dirname, filename, dirname_l) == 0)
- && (filename[separator_position] == '/'));
-}
-
-
goffset
-get_file_size (const char *uri)
+_g_uri_get_file_size (const char *uri)
{
goffset size = 0;
GFile *file;
@@ -350,23 +333,9 @@ get_file_size (const char *uri)
}
-goffset
-get_file_size_for_path (const char *path)
-{
- char *uri;
- goffset result;
-
- uri = g_filename_to_uri (path, NULL, NULL);
- result = get_file_size (uri);
- g_free (uri);
-
- return result;
-}
-
-
static time_t
-get_file_time_type (const char *uri,
- const char *type)
+_g_uri_get_file_time_type (const char *uri,
+ const char *type)
{
time_t result = 0;
GFile *file;
@@ -395,223 +364,23 @@ get_file_time_type (const char *uri,
time_t
-get_file_mtime (const char *uri)
-{
- return get_file_time_type (uri, G_FILE_ATTRIBUTE_TIME_MODIFIED);
-}
-
-
-time_t
-get_file_mtime_for_path (const char *path)
+_g_uri_get_file_mtime (const char *uri)
{
- char *uri;
- time_t result;
-
- uri = g_filename_to_uri (path, NULL, NULL);
- result = get_file_mtime (uri);
- g_free (uri);
-
- return result;
+ return _g_uri_get_file_time_type (uri, G_FILE_ATTRIBUTE_TIME_MODIFIED);
}
time_t
-get_file_ctime (const char *uri)
-{
- return get_file_time_type (uri, G_FILE_ATTRIBUTE_TIME_CREATED);
-}
-
-
-gboolean
-file_is_hidden (const gchar *name)
-{
- if (name[0] != '.') return FALSE;
- if (name[1] == '\0') return FALSE;
- if ((name[1] == '.') && (name[2] == '\0')) return FALSE;
-
- return TRUE;
-}
-
-
-/* like g_path_get_basename but does not warn about NULL and does not
- * alloc a new string. */
-const gchar *
-file_name_from_path (const gchar *file_name)
-{
- register char *base;
- register gssize last_char;
-
- if (file_name == NULL)
- return NULL;
-
- if (file_name[0] == '\0')
- return "";
-
- last_char = strlen (file_name) - 1;
-
- if (file_name [last_char] == G_DIR_SEPARATOR)
- return "";
-
- base = g_utf8_strrchr (file_name, -1, G_DIR_SEPARATOR);
- if (! base)
- return file_name;
-
- return base + 1;
-}
-
-
-char *
-dir_name_from_path (const gchar *path)
-{
- register gssize base;
- register gssize last_char;
-
- if (path == NULL)
- return NULL;
-
- if (path[0] == '\0')
- return g_strdup ("");
-
- last_char = strlen (path) - 1;
- if (path[last_char] == G_DIR_SEPARATOR)
- last_char--;
-
- base = last_char;
- while ((base >= 0) && (path[base] != G_DIR_SEPARATOR))
- base--;
-
- return g_strndup (path + base + 1, last_char - base);
-}
-
-
-gchar *
-remove_level_from_path (const gchar *path)
-{
- int p;
- const char *ptr = path;
- char *new_path;
-
- if (path == NULL)
- return NULL;
-
- p = strlen (path) - 1;
- if (p < 0)
- return NULL;
-
- while ((p > 0) && (ptr[p] != '/'))
- p--;
- if ((p == 0) && (ptr[p] == '/'))
- p++;
- new_path = g_strndup (path, (guint)p);
-
- return new_path;
-}
-
-
-char *
-remove_ending_separator (const char *path)
-{
- gint len, copy_len;
-
- if (path == NULL)
- return NULL;
-
- copy_len = len = strlen (path);
- if ((len > 1) && (path[len - 1] == '/'))
- copy_len--;
-
- return g_strndup (path, copy_len);
-}
-
-
-char *
-build_uri (const char *base, ...)
-{
- va_list args;
- const char *child;
- GString *uri;
-
- uri = g_string_new (base);
-
- va_start (args, base);
- while ((child = va_arg (args, const char *)) != NULL) {
- if (! g_str_has_suffix (uri->str, "/") && ! g_str_has_prefix (child, "/"))
- g_string_append (uri, "/");
- g_string_append (uri, child);
- }
- va_end (args);
-
- return g_string_free (uri, FALSE);
-}
-
-
-gchar *
-remove_extension_from_path (const gchar *path)
-{
- int len;
- int p;
- const char *ptr = path;
- char *new_path;
-
- if (! path)
- return NULL;
-
- len = strlen (path);
- if (len == 1)
- return g_strdup (path);
-
- p = len - 1;
- while ((p > 0) && (ptr[p] != '.'))
- p--;
- if (p == 0)
- p = len;
- new_path = g_strndup (path, (guint) p);
-
- return new_path;
-}
-
-
-gboolean
-make_directory_tree (GFile *dir,
- mode_t mode,
- GError **error)
+_g_uri_get_file_ctime (const char *uri)
{
- gboolean success = TRUE;
- GFile *parent;
-
- if ((dir == NULL) || g_file_query_exists (dir, NULL))
- return TRUE;
-
- parent = g_file_get_parent (dir);
- if (parent != NULL) {
- success = make_directory_tree (parent, mode, error);
- g_object_unref (parent);
- if (! success)
- return FALSE;
- }
-
- success = g_file_make_directory (dir, NULL, error);
- if ((error != NULL) && (*error != NULL) && g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
- g_clear_error (error);
- success = TRUE;
- }
-
- if (success)
- g_file_set_attribute_uint32 (dir,
- G_FILE_ATTRIBUTE_UNIX_MODE,
- mode,
- 0,
- NULL,
- NULL);
-
- return success;
+ return _g_uri_get_file_time_type (uri, G_FILE_ATTRIBUTE_TIME_CREATED);
}
gboolean
-ensure_dir_exists (const char *uri,
- mode_t mode,
- GError **error)
+_g_uri_ensure_dir_exists (const char *uri,
+ mode_t mode,
+ GError **error)
{
GFile *dir;
GError *priv_error = NULL;
@@ -623,7 +392,7 @@ ensure_dir_exists (const char *uri,
error = &priv_error;
dir = g_file_new_for_uri (uri);
- if (! make_directory_tree (dir, mode, error)) {
+ if (! _g_file_make_directory_tree (dir, mode, error)) {
g_warning ("could create directory %s: %s", uri, (*error)->message);
if (priv_error != NULL)
g_clear_error (&priv_error);
@@ -634,79 +403,9 @@ ensure_dir_exists (const char *uri,
}
-gboolean
-make_directory_tree_from_path (const char *path,
- mode_t mode,
- GError **error)
-{
- char *uri;
- gboolean result;
-
- uri = g_filename_to_uri (path, NULL, NULL);
- result = ensure_dir_exists (uri, mode, error);
- g_free (uri);
-
- return result;
-}
-
-
const char *
-get_file_extension (const char *filename)
-{
- const char *ptr = filename;
- int len;
- int p;
- const char *ext;
-
- if (filename == NULL)
- return NULL;
-
- len = strlen (filename);
- if (len <= 1)
- return NULL;
-
- p = len - 1;
- while ((p >= 0) && (ptr[p] != '.'))
- p--;
- if (p < 0)
- return NULL;
-
- ext = filename + p;
- if (ext - 4 > filename) {
- const char *test = ext - 4;
- if (strncmp (test, ".tar", 4) == 0)
- ext = ext - 4;
- }
- return ext;
-}
-
-
-gboolean
-file_extension_is (const char *filename,
- const char *ext)
-{
- int filename_l, ext_l;
-
- filename_l = strlen (filename);
- ext_l = strlen (ext);
-
- if (filename_l < ext_l)
- return FALSE;
- return strcasecmp (filename + filename_l - ext_l, ext) == 0;
-}
-
-
-gboolean
-is_mime_type (const char *mime_type,
- const char *pattern)
-{
- return (strcasecmp (mime_type, pattern) == 0);
-}
-
-
-const char*
-get_file_mime_type (const char *uri,
- gboolean fast_file_type)
+_g_uri_get_mime_type (const char *uri,
+ gboolean fast_file_type)
{
GFile *file;
GFileInfo *info;
@@ -734,43 +433,7 @@ get_file_mime_type (const char *uri,
}
-const char*
-get_file_mime_type_for_path (const char *filename,
- gboolean fast_file_type)
-{
- char *uri;
- const char *mime_type;
-
- uri = g_filename_to_uri (filename, NULL, NULL);
- mime_type = get_file_mime_type (uri, fast_file_type);
- g_free (uri);
-
- return mime_type;
-}
-
-
-guint64
-get_dest_free_space (const char *path)
-{
- guint64 freespace = 0;
- GFile *file;
- GFileInfo *info;
- GError *err = NULL;
-
- file = g_file_new_for_path (path);
- info = g_file_query_filesystem_info (file, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, NULL, &err);
- if (info != NULL) {
- freespace = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
- g_object_unref (info);
- }
- else {
- g_warning ("Could not get filesystem free space on volume that contains %s: %s", path, err->message);
- g_error_free (err);
- }
- g_object_unref (file);
-
- return freespace;
-}
+/* -- _g_uri_remove_directory -- */
static gboolean
@@ -795,7 +458,7 @@ delete_directory_recursive (GFile *dir,
char *child_uri;
GFile *child;
- child_uri = build_uri (uri, g_file_info_get_name (info), NULL);
+ child_uri = _g_uri_build (uri, g_file_info_get_name (info), NULL);
child = g_file_new_for_uri (child_uri);
switch (g_file_info_get_file_type (info)) {
@@ -825,7 +488,7 @@ delete_directory_recursive (GFile *dir,
gboolean
-remove_directory (const char *uri)
+_g_uri_remove_directory (const char *uri)
{
GFile *dir;
gboolean result;
@@ -844,32 +507,148 @@ remove_directory (const char *uri)
gboolean
-remove_local_directory (const char *path)
+_g_uri_check_permissions (const char *uri,
+ int mode)
{
- char *uri;
+ GFile *file;
gboolean result;
- if (path == NULL)
- return TRUE;
+ file = g_file_new_for_uri (uri);
+ result = _g_file_check_permissions (file, mode);
- uri = g_filename_to_uri (path, NULL, NULL);
- result = remove_directory (uri);
- g_free (uri);
+ g_object_unref (file);
return result;
}
-static const char *try_folder[] = { "cache", "~", "tmp", NULL };
+/* path */
-static char *
-ith_temp_folder_to_try (int n)
+gboolean
+_g_path_query_is_dir (const char *path)
{
- const char *folder;
+ char *uri;
+ gboolean result;
- folder = try_folder[n];
- if (strcmp (folder, "cache") == 0)
+ uri = g_filename_to_uri (path, NULL, NULL);
+ result = _g_uri_query_is_dir (uri);
+ g_free (uri);
+
+ return result;
+}
+
+
+goffset
+_g_path_get_file_size (const char *path)
+{
+ char *uri;
+ goffset result;
+
+ uri = g_filename_to_uri (path, NULL, NULL);
+ result = _g_uri_get_file_size (uri);
+ g_free (uri);
+
+ return result;
+}
+
+
+time_t
+_g_path_get_file_mtime (const char *path)
+{
+ char *uri;
+ time_t result;
+
+ uri = g_filename_to_uri (path, NULL, NULL);
+ result = _g_uri_get_file_mtime (uri);
+ g_free (uri);
+
+ return result;
+}
+
+
+gboolean
+_g_path_make_directory_tree (const char *path,
+ mode_t mode,
+ GError **error)
+{
+ char *uri;
+ gboolean result;
+
+ uri = g_filename_to_uri (path, NULL, NULL);
+ result = _g_uri_ensure_dir_exists (uri, mode, error);
+ g_free (uri);
+
+ return result;
+}
+
+
+const char*
+_g_path_get_mime_type (const char *filename,
+ gboolean fast_file_type)
+{
+ char *uri;
+ const char *mime_type;
+
+ uri = g_filename_to_uri (filename, NULL, NULL);
+ mime_type = _g_uri_get_mime_type (uri, fast_file_type);
+ g_free (uri);
+
+ return mime_type;
+}
+
+
+guint64
+_g_path_get_free_space (const char *path)
+{
+ guint64 freespace = 0;
+ GFile *file;
+ GFileInfo *info;
+ GError *err = NULL;
+
+ file = g_file_new_for_path (path);
+ info = g_file_query_filesystem_info (file, G_FILE_ATTRIBUTE_FILESYSTEM_FREE, NULL, &err);
+ if (info != NULL) {
+ freespace = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+ g_object_unref (info);
+ }
+ else {
+ g_warning ("Could not get filesystem free space on volume that contains %s: %s", path, err->message);
+ g_error_free (err);
+ }
+ g_object_unref (file);
+
+ return freespace;
+}
+
+
+gboolean
+_g_path_remove_directory (const char *path)
+{
+ char *uri;
+ gboolean result;
+
+ if (path == NULL)
+ return TRUE;
+
+ uri = g_filename_to_uri (path, NULL, NULL);
+ result = _g_uri_remove_directory (uri);
+ g_free (uri);
+
+ return result;
+}
+
+
+static const char *try_folder[] = { "cache", "~", "tmp", NULL };
+
+
+static char *
+ith_temp_folder_to_try (int n)
+{
+ const char *folder;
+
+ folder = try_folder[n];
+ if (strcmp (folder, "cache") == 0)
folder = g_get_user_cache_dir ();
else if (strcmp (folder, "~") == 0)
folder = g_get_home_dir ();
@@ -881,7 +660,7 @@ ith_temp_folder_to_try (int n)
char *
-get_temp_work_dir (const char *parent_folder)
+_g_path_get_temp_work_dir (const char *parent_folder)
{
guint64 max_size = 0;
char *best_folder = NULL;
@@ -897,7 +676,7 @@ get_temp_work_dir (const char *parent_folder)
guint64 size;
folder = ith_temp_folder_to_try (i);
- size = get_dest_free_space (folder);
+ size = _g_path_get_free_space (folder);
if (max_size < size) {
max_size = size;
g_free (best_folder);
@@ -926,21 +705,21 @@ get_temp_work_dir (const char *parent_folder)
gboolean
-is_temp_work_dir (const char *dir)
+_g_path_is_temp_work_dir (const char *path)
{
int i;
- if (strncmp (dir, "file://", 7) == 0)
- dir = dir + 7;
- else if (dir[0] != '/')
+ if (strncmp (path, "file://", 7) == 0)
+ path = path + 7;
+ else if (path[0] != '/')
return FALSE;
for (i = 0; try_folder[i] != NULL; i++) {
char *folder;
folder = ith_temp_folder_to_try (i);
- if (strncmp (dir, folder, strlen (folder)) == 0) {
- if (strncmp (dir + strlen (folder), "/.fr-", 5) == 0) {
+ if (strncmp (path, folder, strlen (folder)) == 0) {
+ if (strncmp (path + strlen (folder), "/.fr-", 5) == 0) {
g_free (folder);
return TRUE;
}
@@ -954,154 +733,25 @@ is_temp_work_dir (const char *dir)
gboolean
-is_temp_dir (const char *dir)
+_g_path_is_temp_dir (const char *path)
{
- if (strncmp (dir, "file://", 7) == 0)
- dir = dir + 7;
- if (strcmp (g_get_tmp_dir (), dir) == 0)
+ if (strncmp (path, "file://", 7) == 0)
+ path = path + 7;
+ if (strcmp (g_get_tmp_dir (), path) == 0)
return TRUE;
- if (path_in_path (g_get_tmp_dir (), dir))
+ if (_g_path_is_parent_of (g_get_tmp_dir (), path))
return TRUE;
else
- return is_temp_work_dir (dir);
-}
-
-
-/* file list utils */
-
-
-gboolean
-file_list__match_pattern (const char *line,
- const char *pattern)
-{
- const char *l = line, *p = pattern;
-
- for (; (*p != 0) && (*l != 0); p++, l++) {
- if (*p != '%') {
- if (*p != *l)
- return FALSE;
- }
- else {
- p++;
- switch (*p) {
- case 'a':
- break;
- case 'n':
- if (!isdigit (*l))
- return FALSE;
- break;
- case 'c':
- if (!isalpha (*l))
- return FALSE;
- break;
- default:
- return FALSE;
- }
- }
- }
-
- return (*p == 0);
+ return _g_path_is_temp_work_dir (path);
}
-int
-file_list__get_index_from_pattern (const char *line,
- const char *pattern)
-{
- int line_l, pattern_l;
- const char *l;
-
- line_l = strlen (line);
- pattern_l = strlen (pattern);
-
- if ((pattern_l == 0) || (line_l == 0))
- return -1;
-
- for (l = line; *l != 0; l++)
- if (file_list__match_pattern (l, pattern))
- return (l - line);
-
- return -1;
-}
-
-
-char*
-file_list__get_next_field (const char *line,
- int start_from,
- int field_n)
-{
- const char *f_start, *f_end;
-
- line = line + start_from;
-
- f_start = line;
- while ((*f_start == ' ') && (*f_start != *line))
- f_start++;
- f_end = f_start;
-
- while ((field_n > 0) && (*f_end != 0)) {
- if (*f_end == ' ') {
- field_n--;
- if (field_n != 0) {
- while ((*f_end == ' ') && (*f_end != *line))
- f_end++;
- f_start = f_end;
- }
- } else
- f_end++;
- }
-
- return g_strndup (f_start, f_end - f_start);
-}
-
-
-char*
-file_list__get_prev_field (const char *line,
- int start_from,
- int field_n)
-{
- const char *f_start, *f_end;
-
- f_start = line + start_from - 1;
- while ((*f_start == ' ') && (*f_start != *line))
- f_start--;
- f_end = f_start;
-
- while ((field_n > 0) && (*f_start != *line)) {
- if (*f_start == ' ') {
- field_n--;
- if (field_n != 0) {
- while ((*f_start == ' ') && (*f_start != *line))
- f_start--;
- f_end = f_start;
- }
- } else
- f_start--;
- }
-
- return g_strndup (f_start + 1, f_end - f_start);
-}
+/* GFile */
gboolean
-check_permissions (const char *uri,
- int mode)
-{
- GFile *file;
- gboolean result;
-
- file = g_file_new_for_uri (uri);
- result = check_file_permissions (file, mode);
-
- g_object_unref (file);
-
- return result;
-}
-
-
-gboolean
-check_file_permissions (GFile *file,
- int mode)
+_g_file_check_permissions (GFile *file,
+ int mode)
{
gboolean result = TRUE;
GFileInfo *info;
@@ -1143,77 +793,45 @@ check_file_permissions (GFile *file,
gboolean
-is_program_in_path (const char *filename)
+_g_file_make_directory_tree (GFile *dir,
+ mode_t mode,
+ GError **error)
{
- char *str;
- char *value;
- int result = FALSE;
+ gboolean success = TRUE;
+ GFile *parent;
- value = g_hash_table_lookup (ProgramsCache, filename);
- if (value != NULL) {
- result = (strcmp (value, "1") == 0);
- return result;
- }
+ if ((dir == NULL) || g_file_query_exists (dir, NULL))
+ return TRUE;
- str = g_find_program_in_path (filename);
- if (str != NULL) {
- g_free (str);
- result = TRUE;
+ parent = g_file_get_parent (dir);
+ if (parent != NULL) {
+ success = _g_file_make_directory_tree (parent, mode, error);
+ g_object_unref (parent);
+ if (! success)
+ return FALSE;
}
- g_hash_table_insert (ProgramsCache,
- g_strdup (filename),
- result ? "1" : "0");
-
- return result;
-}
-
-
-gboolean
-is_program_available (const char *filename,
- gboolean check)
-{
- return ! check || is_program_in_path (filename);
-}
-
-
-const char *
-get_home_uri (void)
-{
- static char *home_uri = NULL;
- if (home_uri == NULL)
- home_uri = g_filename_to_uri (g_get_home_dir (), NULL, NULL);
- return home_uri;
-}
-
-
-char *
-get_home_relative_uri (const char *partial_uri)
-{
- return g_strconcat (get_home_uri (),
- "/",
- partial_uri,
- NULL);
-}
-
-
-GFile *
-get_home_relative_file (const char *partial_uri)
-{
- GFile *file;
- char *uri;
+ success = g_file_make_directory (dir, NULL, error);
+ if ((error != NULL) && (*error != NULL) && g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
+ g_clear_error (error);
+ success = TRUE;
+ }
- uri = g_strconcat (get_home_uri (), "/", partial_uri, NULL);
- file = g_file_new_for_uri (uri);
- g_free (uri);
+ if (success)
+ g_file_set_attribute_uint32 (dir,
+ G_FILE_ATTRIBUTE_UNIX_MODE,
+ mode,
+ 0,
+ NULL,
+ NULL);
- return file;
+ return success;
}
GFile *
-get_user_config_subdirectory (const char *child_name,
- gboolean create_child)
+_g_file_new_user_config_subdir (const char *child_name,
+ gboolean create_child)
{
char *full_path;
GFile *file;
@@ -1223,7 +841,7 @@ get_user_config_subdirectory (const char *child_name,
file = g_file_new_for_path (full_path);
g_free (full_path);
- if (create_child && ! make_directory_tree (file, 0700, &error)) {
+ if (create_child && ! _g_file_make_directory_tree (file, 0700, &error)) {
g_warning ("%s", error->message);
g_error_free (error);
g_object_unref (file);
@@ -1234,133 +852,50 @@ get_user_config_subdirectory (const char *child_name,
}
-const char *
-remove_host_from_uri (const char *uri)
-{
- const char *idx, *sep;
-
- if (uri == NULL)
- return NULL;
-
- idx = strstr (uri, "://");
- if (idx == NULL)
- return uri;
- idx += 3;
- if (*idx == '\0')
- return "/";
- sep = strstr (idx, "/");
- if (sep == NULL)
- return idx;
- return sep;
-}
-
-
-char *
-get_uri_host (const char *uri)
-{
- const char *idx;
-
- idx = strstr (uri, "://");
- if (idx == NULL)
- return NULL;
- idx = strstr (idx + 3, "/");
- if (idx == NULL)
- return NULL;
- return g_strndup (uri, (idx - uri));
-}
-
-
-char *
-get_uri_root (const char *uri)
-{
- char *host;
- char *root;
-
- host = get_uri_host (uri);
- if (host == NULL)
- return NULL;
- root = g_strconcat (host, "/", NULL);
- g_free (host);
-
- return root;
-}
-
-
-int
-uricmp (const char *uri1,
- const char *uri2)
-{
- return _g_strcmp_null_tolerant (uri1, uri2);
-}
-
-
-char *
-get_alternative_uri (const char *folder,
- const char *name)
-{
- char *new_uri = NULL;
- int n = 1;
-
- do {
- g_free (new_uri);
- if (n == 1)
- new_uri = g_strconcat (folder, "/", name, NULL);
- else
- new_uri = g_strdup_printf ("%s/%s%%20(%d)", folder, name, n);
- n++;
- } while (uri_exists (new_uri));
-
- return new_uri;
-}
+/* program */
-char *
-get_alternative_uri_for_uri (const char *uri)
+gboolean
+_g_program_is_in_path (const char *filename)
{
- char *base_uri;
- char *new_uri;
+ char *str;
+ char *value;
+ int result = FALSE;
- base_uri = remove_level_from_path (uri);
- new_uri = get_alternative_uri (base_uri, file_name_from_path (uri));
- g_free (base_uri);
+ value = g_hash_table_lookup (ProgramsCache, filename);
+ if (value != NULL) {
+ result = (strcmp (value, "1") == 0);
+ return result;
+ }
- return new_uri;
-}
+ str = g_find_program_in_path (filename);
+ if (str != NULL) {
+ g_free (str);
+ result = TRUE;
+ }
+ g_hash_table_insert (ProgramsCache,
+ g_strdup (filename),
+ result ? "1" : "0");
-GList *
-_g_file_list_dup (GList *l)
-{
- GList *r = NULL, *scan;
- for (scan = l; scan; scan = scan->next)
- r = g_list_prepend (r, g_file_dup ((GFile*)scan->data));
- return g_list_reverse (r);
+ return result;
}
-void
-_g_file_list_free (GList *l)
+gboolean
+_g_program_is_available (const char *filename,
+ gboolean check)
{
- GList *scan;
- for (scan = l; scan; scan = scan->next)
- g_object_unref (scan->data);
- g_list_free (l);
+ return ! check || _g_program_is_in_path (filename);
}
-GList *
-_g_file_list_new_from_uri_list (GList *uris)
-{
- GList *r = NULL, *scan;
- for (scan = uris; scan; scan = scan->next)
- r = g_list_prepend (r, g_file_new_for_uri ((char*)scan->data));
- return g_list_reverse (r);
-}
+/* GKeyFile */
void
-g_key_file_save (GKeyFile *key_file,
- GFile *file)
+_g_key_file_save (GKeyFile *key_file,
+ GFile *file)
{
char *file_data;
gsize size;
diff --git a/src/file-utils.h b/src/file-utils.h
index 94b6474..54b6882 100644
--- a/src/file-utils.h
+++ b/src/file-utils.h
@@ -27,107 +27,66 @@
#include <unistd.h>
#include <gio/gio.h>
-#define MIME_TYPE_DIRECTORY "folder"
-#define MIME_TYPE_ARCHIVE "application/x-archive"
-
-#define get_home_relative_path(x) \
- g_strconcat (g_get_home_dir (), \
- "/", \
- (x), \
- NULL)
-
-gboolean uri_exists (const char *uri);
-gboolean uri_is_file (const char *uri);
-gboolean uri_is_dir (const char *uri);
-gboolean path_is_dir (const char *path);
-gboolean uri_is_local (const char *uri);
-gboolean dir_is_empty (const char *uri);
-gboolean dir_contains_one_object (const char *uri);
-char * get_dir_content_if_unique (const char *uri);
-gboolean path_in_path (const char *path_src,
- const char *path_dest);
-goffset get_file_size (const char *uri);
-goffset get_file_size_for_path (const char *path);
-time_t get_file_mtime (const char *uri);
-time_t get_file_mtime_for_path (const char *path);
-time_t get_file_ctime (const char *uri);
-gboolean make_directory_tree (GFile *dir,
- mode_t mode,
- GError **error);
-gboolean ensure_dir_exists (const char *uri,
- mode_t mode,
- GError **error);
-gboolean make_directory_tree_from_path (const char *path,
- mode_t mode,
- GError **error);
-gboolean file_is_hidden (const char *name);
-const char * file_name_from_path (const char *path);
-char * dir_name_from_path (const char *path);
-char * remove_level_from_path (const char *path);
-char * remove_ending_separator (const char *path);
-char * build_uri (const char *base, ...);
-char * remove_extension_from_path (const char *path);
-const char * get_file_extension (const char *filename);
-gboolean file_extension_is (const char *filename,
- const char *ext);
-gboolean is_mime_type (const char *type,
- const char *pattern);
-const char* get_file_mime_type (const char *uri,
- gboolean fast_file_type);
-const char* get_file_mime_type_for_path (const char *filename,
- gboolean fast_file_type);
-guint64 get_dest_free_space (const char *path);
-gboolean remove_directory (const char *uri);
-gboolean remove_local_directory (const char *directory);
-char * get_temp_work_dir (const char *parent_folder);
-gboolean is_temp_work_dir (const char *dir);
-gboolean is_temp_dir (const char *dir);
-
-/* misc functions used to parse a command output lines. */
-
-gboolean file_list__match_pattern (const char *line,
- const char *pattern);
-int file_list__get_index_from_pattern (const char *line,
- const char *pattern);
-char* file_list__get_next_field (const char *line,
- int start_from,
- int field_n);
-char* file_list__get_prev_field (const char *line,
- int start_from,
- int field_n);
-gboolean check_permissions (const char *path,
- int mode);
-gboolean check_file_permissions (GFile *file,
- int mode);
-gboolean is_program_in_path (const char *filename);
-gboolean is_program_available (const char *filename,
- gboolean check);
-
-/* URI utils */
-
-const char * get_home_uri (void);
-char * get_home_relative_uri (const char *partial_uri);
-GFile * get_home_relative_file (const char *partial_uri);
-GFile * get_user_config_subdirectory (const char *child_name,
- gboolean create_);
-const char * remove_host_from_uri (const char *uri);
-char * get_uri_host (const char *uri);
-char * get_uri_root (const char *uri);
-int uricmp (const char *uri1,
- const char *uri2);
-char * get_alternative_uri (const char *folder,
- const char *name);
-char * get_alternative_uri_for_uri (const char *uri);
-
-/* GFile utils */
-
-GList * _g_file_list_dup (GList *l);
-void _g_file_list_free (GList *l);
-GList * _g_file_list_new_from_uri_list (GList *uris);
-
-/* GKeyFile utils */
-
-void g_key_file_save (GKeyFile *key_file,
- GFile *file);
+/* uri */
+
+gboolean _g_uri_query_exists (const char *uri);
+gboolean _g_uri_query_is_file (const char *uri);
+gboolean _g_uri_query_is_dir (const char *uri);
+char * _g_uri_create_alternative (const char *folder,
+ const char *name);
+char * _g_uri_create_alternative_for_uri (const char *uri);
+gboolean _g_uri_query_dir_is_empty (const char *uri);
+gboolean _g_uri_dir_contains_one_object (const char *uri);
+char * _g_uri_get_dir_content_if_unique (const char *uri);
+goffset _g_uri_get_file_size (const char *uri);
+
+time_t _g_uri_get_file_mtime (const char *uri);
+
+time_t _g_uri_get_file_ctime (const char *uri);
+gboolean _g_uri_ensure_dir_exists (const char *uri,
+ mode_t mode,
+ GError **error);
+const char* _g_uri_get_mime_type (const char *uri,
+ gboolean fast_file_type);
+gboolean _g_uri_remove_directory (const char *uri);
+gboolean _g_uri_check_permissions (const char *uri,
+ int mode);
+
+/* path */
+
+gboolean _g_path_query_is_dir (const char *path);
+goffset _g_path_get_file_size (const char *path);
+time_t _g_path_get_file_mtime (const char *path);
+gboolean _g_path_make_directory_tree (const char *path,
+ mode_t mode,
+ GError **error);
+const char* _g_path_get_mime_type (const char *filename,
+ gboolean fast_file_type);
+guint64 _g_path_get_free_space (const char *path);
+gboolean _g_path_remove_directory (const char *path);
+char * _g_path_get_temp_work_dir (const char *parent_folder);
+gboolean _g_path_is_temp_work_dir (const char *path);
+gboolean _g_path_is_temp_dir (const char *path);
+
+/* GFile */
+
+gboolean _g_file_check_permissions (GFile *file,
+ int mode);
+gboolean _g_file_make_directory_tree (GFile *dir,
+ mode_t mode,
+ GError **error);
+GFile * _g_file_new_user_config_subdir (const char *child_name,
+ gboolean create_);
+
+/* program */
+
+gboolean _g_program_is_in_path (const char *filename);
+gboolean _g_program_is_available (const char *filename,
+ gboolean check);
+
+/* GKeyFile */
+
+void _g_key_file_save (GKeyFile *key_file,
+ GFile *file);
#endif /* FILE_UTILS_H */
diff --git a/src/fr-archive.c b/src/fr-archive.c
index 1728627..5486d58 100644
--- a/src/fr-archive.c
+++ b/src/fr-archive.c
@@ -383,7 +383,7 @@ get_local_copy_for_file (GFile *remote_file)
char *temp_dir;
GFile *local_copy = NULL;
- temp_dir = get_temp_work_dir (NULL);
+ temp_dir = _g_path_get_temp_work_dir (NULL);
if (temp_dir != NULL) {
char *archive_name;
char *local_path;
@@ -452,7 +452,7 @@ fr_archive_remove_temp_work_dir (FrArchive *archive)
{
if (archive->priv->temp_dir == NULL)
return;
- remove_local_directory (archive->priv->temp_dir);
+ _g_path_remove_directory (archive->priv->temp_dir);
g_free (archive->priv->temp_dir);
archive->priv->temp_dir = NULL;
}
@@ -595,7 +595,7 @@ get_mime_type_from_filename (GFile *file)
return NULL;
filename = g_file_get_path (file);
- mime_type = get_mime_type_from_extension (get_file_extension (filename));
+ mime_type = get_mime_type_from_extension (_g_filename_get_extension (filename));
g_free (filename);
return mime_type;
@@ -778,16 +778,16 @@ move_here (FrArchive *archive)
GFile *source, *destination, *parent_file;
GError *error = NULL;
- content_uri = get_dir_content_if_unique (archive->priv->extraction_destination);
+ content_uri = _g_uri_get_dir_content_if_unique (archive->priv->extraction_destination);
if (content_uri == NULL)
return;
- parent = remove_level_from_path (content_uri);
+ parent = _g_path_remove_level (content_uri);
- if (uricmp (parent, archive->priv->extraction_destination) == 0) {
+ if (_g_uri_cmp (parent, archive->priv->extraction_destination) == 0) {
char *new_uri;
- new_uri = get_alternative_uri_for_uri (archive->priv->extraction_destination);
+ new_uri = _g_uri_create_alternative_for_uri (archive->priv->extraction_destination);
source = g_file_new_for_uri (archive->priv->extraction_destination);
destination = g_file_new_for_uri (new_uri);
@@ -803,15 +803,15 @@ move_here (FrArchive *archive)
g_free (parent);
- content_uri = get_dir_content_if_unique (archive->priv->extraction_destination);
+ content_uri = _g_uri_get_dir_content_if_unique (archive->priv->extraction_destination);
if (content_uri == NULL)
return;
- parent = remove_level_from_path (content_uri);
+ parent = _g_path_remove_level (content_uri);
}
- parent_parent = remove_level_from_path (parent);
- new_content_uri = get_alternative_uri (parent_parent, file_name_from_path (content_uri));
+ parent_parent = _g_path_remove_level (parent);
+ new_content_uri = _g_uri_create_alternative (parent_parent, _g_path_get_file_name (content_uri));
source = g_file_new_for_uri (content_uri);
destination = g_file_new_for_uri (new_content_uri);
@@ -842,7 +842,7 @@ copy_extracted_files_done (GError *error,
{
FrArchive *archive = user_data;
- remove_local_directory (archive->priv->temp_extraction_dir);
+ _g_path_remove_directory (archive->priv->temp_extraction_dir);
g_free (archive->priv->temp_extraction_dir);
archive->priv->temp_extraction_dir = NULL;
@@ -901,7 +901,7 @@ fr_archive_change_name (FrArchive *archive,
const char *name;
GFile *parent;
- name = file_name_from_path (filename);
+ name = _g_path_get_file_name (filename);
parent = g_file_get_parent (archive->file);
g_object_unref (archive->file);
@@ -972,13 +972,13 @@ action_performed (FrCommand *command,
g_print ("action_performed: ERROR!\n");
if ((archive->priv->remote_extraction) && (archive->priv->temp_extraction_dir != NULL)) {
- remove_local_directory (archive->priv->temp_extraction_dir);
+ _g_path_remove_directory (archive->priv->temp_extraction_dir);
g_free (archive->priv->temp_extraction_dir);
archive->priv->temp_extraction_dir = NULL;
}
if (archive->priv->extract_here)
- remove_directory (archive->priv->extraction_destination);
+ _g_uri_remove_directory (archive->priv->extraction_destination);
}
break;
@@ -1140,7 +1140,7 @@ load_local_archive (FrArchive *archive,
return;
}
- archive->have_permissions = check_file_permissions (archive->file, W_OK);
+ archive->have_permissions = _g_file_check_permissions (archive->file, W_OK);
archive->read_only = ! archive->have_permissions;
old_command = archive->command;
@@ -1355,13 +1355,13 @@ create_tmp_base_dir (const char *base_dir,
debug (DEBUG_INFO, "base_dir: %s\n", base_dir);
debug (DEBUG_INFO, "dest_dir: %s\n", dest_dir);
- temp_dir = get_temp_work_dir (NULL);
- tmp = remove_level_from_path (dest_dir);
+ temp_dir = _g_path_get_temp_work_dir (NULL);
+ tmp = _g_path_remove_level (dest_dir);
parent_dir = g_build_filename (temp_dir, tmp, NULL);
g_free (tmp);
debug (DEBUG_INFO, "mkdir %s\n", parent_dir);
- make_directory_tree_from_path (parent_dir, 0700, NULL);
+ _g_path_make_directory_tree (parent_dir, 0700, NULL);
g_free (parent_dir);
dir = g_build_filename (temp_dir, "/", dest_dir, NULL);
@@ -1420,7 +1420,7 @@ newer_files_only (FrArchive *archive,
fullpath = g_strconcat (base_dir, "/", filename, NULL);
uri = g_filename_to_uri (fullpath, NULL, NULL);
- if (fdata->modified >= get_file_mtime (uri)) {
+ if (fdata->modified >= _g_uri_get_file_mtime (uri)) {
g_free (fullpath);
g_free (uri);
continue;
@@ -1447,7 +1447,7 @@ save_list_to_temp_file (GList *file_list,
if (error != NULL)
*error = NULL;
- *list_dir = get_temp_work_dir (NULL);
+ *list_dir = _g_path_get_temp_work_dir (NULL);
*list_filename = g_build_filename (*list_dir, "file-list", NULL);
list_file = g_file_new_for_path (*list_filename);
ostream = g_file_create (list_file, G_FILE_CREATE_PRIVATE, NULL, error);
@@ -1478,7 +1478,7 @@ save_list_to_temp_file (GList *file_list,
error_occurred = TRUE;
if (error_occurred) {
- remove_local_directory (*list_dir);
+ _g_path_remove_directory (*list_dir);
g_free (*list_dir);
g_free (*list_filename);
*list_dir = NULL;
@@ -1599,7 +1599,7 @@ fr_archive_add (FrArchive *archive,
debug (DEBUG_INFO, "nothing to update.\n");
if (base_dir_created)
- remove_local_directory (tmp_base_dir);
+ _g_path_remove_directory (tmp_base_dir);
g_free (tmp_base_dir);
archive->process->error.type = FR_PROC_ERROR_NONE;
@@ -1625,9 +1625,9 @@ fr_archive_add (FrArchive *archive,
local_copy_parent = g_file_get_parent (archive->local_copy);
archive_dir = g_file_get_path (local_copy_parent);
- tmp_archive_dir = get_temp_work_dir (archive_dir);
+ tmp_archive_dir = _g_path_get_temp_work_dir (archive_dir);
archive_filename = g_file_get_path (archive->local_copy);
- tmp_archive_filename = g_build_filename (tmp_archive_dir, file_name_from_path (archive_filename), NULL);
+ tmp_archive_filename = g_build_filename (tmp_archive_dir, _g_path_get_file_name (archive_filename), NULL);
tmp_file = g_file_new_for_path (tmp_archive_filename);
g_object_set (archive->command, "file", tmp_file, NULL);
@@ -1872,10 +1872,10 @@ copy_remote_files (FrArchive *archive,
char *remote_uri;
local_uri = g_strconcat ("file://", tmp_dir, "/", partial_filename, NULL);
- local_folder_uri = remove_level_from_path (local_uri);
+ local_folder_uri = _g_path_remove_level (local_uri);
if (g_hash_table_lookup (created_folders, local_folder_uri) == NULL) {
GError *error = NULL;
- if (! ensure_dir_exists (local_folder_uri, 0755, &error)) {
+ if (! _g_uri_ensure_dir_exists (local_folder_uri, 0755, &error)) {
g_free (local_folder_uri);
g_free (local_uri);
_g_file_list_free (sources);
@@ -1941,7 +1941,7 @@ static char *
fr_archive_get_temp_work_dir (FrArchive *archive)
{
fr_archive_remove_temp_work_dir (archive);
- archive->priv->temp_dir = get_temp_work_dir (NULL);
+ archive->priv->temp_dir = _g_path_get_temp_work_dir (NULL);
return archive->priv->temp_dir;
}
@@ -1957,7 +1957,7 @@ fr_archive_add_files (FrArchive *archive,
FrCompression compression,
guint volume_size)
{
- if (uri_is_local (base_dir)) {
+ if (_g_uri_is_local (base_dir)) {
char *local_dir = g_filename_from_uri (base_dir, NULL, NULL);
fr_archive_add_local_files (archive,
file_list,
@@ -2258,7 +2258,7 @@ all_files_in_same_dir (GList *list)
if (list == NULL)
return FALSE;
- first_basedir = remove_level_from_path (list->data);
+ first_basedir = _g_path_remove_level (list->data);
if (first_basedir == NULL)
return TRUE;
@@ -2266,7 +2266,7 @@ all_files_in_same_dir (GList *list)
char *path = scan->data;
char *basedir;
- basedir = remove_level_from_path (path);
+ basedir = _g_path_remove_level (path);
if (basedir == NULL) {
same_dir = FALSE;
break;
@@ -2307,7 +2307,7 @@ add_dropped_items (DroppedItemsData *data)
if (all_files_in_same_dir (list)) {
char *first_base_dir;
- first_base_dir = remove_level_from_path (list->data);
+ first_base_dir = _g_path_remove_level (list->data);
fr_archive_add_items (data->archive,
list,
first_base_dir,
@@ -2331,16 +2331,16 @@ add_dropped_items (DroppedItemsData *data)
char *path = scan->data;
char *base_dir;
- if (! uri_is_dir (path))
+ if (! _g_uri_query_is_dir (path))
continue;
data->item_list = g_list_remove_link (list, scan);
if (data->item_list != NULL)
archive->priv->continue_adding_dropped_items = TRUE;
- base_dir = remove_level_from_path (path);
+ base_dir = _g_path_remove_level (path);
fr_archive_add_directory (archive,
- file_name_from_path (path),
+ _g_path_get_file_name (path),
base_dir,
data->dest_dir,
data->update,
@@ -2361,12 +2361,12 @@ add_dropped_items (DroppedItemsData *data)
char *first_basedir;
GList *only_names_list = NULL;
- first_basedir = remove_level_from_path (list->data);
+ first_basedir = _g_path_remove_level (list->data);
for (scan = list; scan; scan = scan->next) {
char *name;
- name = g_uri_unescape_string (file_name_from_path (scan->data), NULL);
+ name = g_uri_unescape_string (_g_path_get_file_name (scan->data), NULL);
only_names_list = g_list_prepend (only_names_list, name);
}
@@ -2405,8 +2405,8 @@ add_dropped_items (DroppedItemsData *data)
char *basedir;
GList *singleton;
- basedir = remove_level_from_path (fullpath);
- singleton = g_list_prepend (NULL, (char*)file_name_from_path (fullpath));
+ basedir = _g_path_remove_level (fullpath);
+ singleton = g_list_prepend (NULL, (char*)_g_path_get_file_name (fullpath));
fr_command_add (archive->command,
NULL,
singleton,
@@ -2449,7 +2449,7 @@ fr_archive_add_dropped_items (FrArchive *archive,
/* FIXME: make this check for all the add actions */
archive_uri = g_file_get_uri (archive->file);
for (scan = item_list; scan; scan = scan->next) {
- if (uricmp (scan->data, archive_uri) == 0) {
+ if (_g_uri_cmp (scan->data, archive_uri) == 0) {
g_free (archive_uri);
fr_archive_action_completed (archive,
FR_ACTION_ADDING_FILES,
@@ -2491,7 +2491,7 @@ file_is_in_subfolder_of (const char *filename,
for (scan = folder_list; scan; scan = scan->next) {
char *folder_in_list = (char*) scan->data;
- if (path_in_path (folder_in_list, filename))
+ if (_g_path_is_parent_of (folder_in_list, filename))
return TRUE;
}
@@ -2645,9 +2645,9 @@ fr_archive_remove (FrArchive *archive,
local_copy_parent = g_file_get_parent (archive->local_copy);
archive_dir = g_file_get_path (local_copy_parent);
- tmp_archive_dir = get_temp_work_dir (archive_dir);
+ tmp_archive_dir = _g_path_get_temp_work_dir (archive_dir);
archive_filename = g_file_get_path (archive->local_copy);
- tmp_archive_filename = g_build_filename (tmp_archive_dir, file_name_from_path (archive_filename), NULL);
+ tmp_archive_filename = g_build_filename (tmp_archive_dir, _g_path_get_file_name (archive_filename), NULL);
tmp_file = g_file_new_for_path (tmp_archive_filename);
g_object_set (archive->command, "file", tmp_file, NULL);
@@ -2903,7 +2903,7 @@ compute_base_path (const char *base_dir,
if (junk_paths) {
if (can_junk_paths)
- new_path = g_strdup (file_name_from_path (path));
+ new_path = g_strdup (_g_path_get_file_name (path));
else
new_path = g_strdup (path);
@@ -2998,7 +2998,7 @@ file_list_contains_files_in_this_dir (GList *file_list,
for (scan = file_list; scan; scan = scan->next) {
char *filename = scan->data;
- if (path_in_path (dirname, filename))
+ if (_g_path_is_parent_of (dirname, filename))
return TRUE;
}
@@ -3020,7 +3020,7 @@ remove_files_contained_in_this_dir (GList *file_list,
if (strncmp (dirname, filename, dirname_l) != 0)
break;
- if (path_in_path (dirname, filename)) {
+ if (_g_path_is_parent_of (dirname, filename)) {
GList *next = scan->next;
file_list = g_list_remove_link (file_list, scan);
@@ -3159,7 +3159,7 @@ fr_archive_extract_to_local (FrArchive *archive,
if (! junk_paths)
filename = archive_list_filename;
else
- filename = file_name_from_path (archive_list_filename);
+ filename = _g_path_get_file_name (archive_list_filename);
if ((destination[strlen (destination) - 1] == '/')
|| (filename[0] == '/'))
@@ -3174,7 +3174,7 @@ fr_archive_extract_to_local (FrArchive *archive,
if (! archive->command->propExtractCanSkipOlder
&& skip_older
&& g_file_test (dest_filename, G_FILE_TEST_EXISTS)
- && (fdata->modified < get_file_mtime_for_path (dest_filename)))
+ && (fdata->modified < _g_path_get_file_mtime (dest_filename)))
continue;
if (! archive->command->propExtractCanAvoidOverwrite
@@ -3197,7 +3197,7 @@ fr_archive_extract_to_local (FrArchive *archive,
if (move_to_dest_dir) {
char *temp_dir;
- temp_dir = get_temp_work_dir (destination);
+ temp_dir = _g_path_get_temp_work_dir (destination);
extract_from_archive (archive,
filtered,
temp_dir,
@@ -3259,9 +3259,9 @@ fr_archive_extract (FrArchive *archive,
g_free (archive->priv->temp_extraction_dir);
archive->priv->temp_extraction_dir = NULL;
- archive->priv->remote_extraction = ! uri_is_local (destination);
+ archive->priv->remote_extraction = ! _g_uri_is_local (destination);
if (archive->priv->remote_extraction) {
- archive->priv->temp_extraction_dir = get_temp_work_dir (NULL);
+ archive->priv->temp_extraction_dir = _g_path_get_temp_work_dir (NULL);
fr_archive_extract_to_local (archive,
file_list,
archive->priv->temp_extraction_dir,
diff --git a/src/fr-command-7z.c b/src/fr-command-7z.c
index d655b36..61db0ef 100644
--- a/src/fr-command-7z.c
+++ b/src/fr-command-7z.c
@@ -131,10 +131,10 @@ list__process_line (char *line,
else {
fdata = p7z_comm->fdata;
if (fdata->dir)
- fdata->name = dir_name_from_path (fdata->full_path);
+ fdata->name = _g_path_get_dir_name (fdata->full_path);
else
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
+ fdata->path = _g_path_remove_level (fdata->full_path);
fr_command_add_file (comm, fdata);
p7z_comm->fdata = NULL;
}
@@ -195,11 +195,11 @@ list__process_line (char *line,
static void
fr_command_7z_begin_command (FrCommand *comm)
{
- if (is_program_in_path ("7z"))
+ if (_g_program_is_in_path ("7z"))
fr_process_begin_command (comm->process, "7z");
- else if (is_program_in_path ("7za"))
+ else if (_g_program_is_in_path ("7za"))
fr_process_begin_command (comm->process, "7za");
- else if (is_program_in_path ("7zr"))
+ else if (_g_program_is_in_path ("7zr"))
fr_process_begin_command (comm->process, "7zr");
}
@@ -331,8 +331,8 @@ fr_command_7z_add (FrCommand *comm,
fr_process_add_arg_concat (comm->process, "-w", base_dir, NULL);
}
- if (is_mime_type (comm->mime_type, "application/zip")
- || is_mime_type (comm->mime_type, "application/x-cbz"))
+ if (_g_mime_type_matches (comm->mime_type, "application/zip")
+ || _g_mime_type_matches (comm->mime_type, "application/x-cbz"))
{
fr_process_add_arg (comm->process, "-tzip");
fr_process_add_arg (comm->process, "-mem=AES128");
@@ -368,7 +368,7 @@ fr_command_7z_add (FrCommand *comm,
break;
}
- if (is_mime_type (comm->mime_type, "application/x-ms-dos-executable"))
+ if (_g_mime_type_matches (comm->mime_type, "application/x-ms-dos-executable"))
fr_process_add_arg (comm->process, "-sfx");
if (comm->volume_size > 0)
@@ -398,7 +398,7 @@ fr_command_7z_delete (FrCommand *comm,
fr_process_add_arg (comm->process, "d");
fr_process_add_arg (comm->process, "-bd");
fr_process_add_arg (comm->process, "-y");
- if (is_mime_type (comm->mime_type, "application/x-ms-dos-executable"))
+ if (_g_mime_type_matches (comm->mime_type, "application/x-ms-dos-executable"))
fr_process_add_arg (comm->process, "-sfx");
if (from_file != NULL)
@@ -559,22 +559,22 @@ fr_command_7z_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (! is_program_available ("7za", check_command) && ! is_program_available ("7zr", check_command) && ! is_program_available ("7z", check_command))
+ if (! _g_program_is_available ("7za", check_command) && ! _g_program_is_available ("7zr", check_command) && ! _g_program_is_available ("7z", check_command))
return capabilities;
- if (is_mime_type (mime_type, "application/x-7z-compressed")) {
+ if (_g_mime_type_matches (mime_type, "application/x-7z-compressed")) {
capabilities |= FR_COMMAND_CAN_READ_WRITE | FR_COMMAND_CAN_CREATE_VOLUMES;
- if (is_program_available ("7z", check_command))
+ if (_g_program_is_available ("7z", check_command))
capabilities |= FR_COMMAND_CAN_ENCRYPT | FR_COMMAND_CAN_ENCRYPT_HEADER;
}
- else if (is_mime_type (mime_type, "application/x-7z-compressed-tar")) {
+ else if (_g_mime_type_matches (mime_type, "application/x-7z-compressed-tar")) {
capabilities |= FR_COMMAND_CAN_READ_WRITE;
- if (is_program_available ("7z", check_command))
+ if (_g_program_is_available ("7z", check_command))
capabilities |= FR_COMMAND_CAN_ENCRYPT | FR_COMMAND_CAN_ENCRYPT_HEADER;
}
- else if (is_program_available ("7z", check_command)) {
- if (is_mime_type (mime_type, "application/x-rar")
- || is_mime_type (mime_type, "application/x-cbr"))
+ else if (_g_program_is_available ("7z", check_command)) {
+ if (_g_mime_type_matches (mime_type, "application/x-rar")
+ || _g_mime_type_matches (mime_type, "application/x-cbr"))
{
if (! check_command || g_file_test ("/usr/lib/p7zip/Codecs/Rar29.so", G_FILE_TEST_EXISTS))
capabilities |= FR_COMMAND_CAN_READ;
@@ -582,21 +582,21 @@ fr_command_7z_get_capabilities (FrCommand *comm,
else
capabilities |= FR_COMMAND_CAN_READ;
- if (is_mime_type (mime_type, "application/x-cbz")
- || is_mime_type (mime_type, "application/x-ms-dos-executable")
- || is_mime_type (mime_type, "application/zip"))
+ if (_g_mime_type_matches (mime_type, "application/x-cbz")
+ || _g_mime_type_matches (mime_type, "application/x-ms-dos-executable")
+ || _g_mime_type_matches (mime_type, "application/zip"))
{
capabilities |= FR_COMMAND_CAN_WRITE | FR_COMMAND_CAN_ENCRYPT;
}
}
- else if (is_program_available ("7za", check_command)) {
- if (is_mime_type (mime_type, "application/vnd.ms-cab-compressed")
- || is_mime_type (mime_type, "application/zip"))
+ else if (_g_program_is_available ("7za", check_command)) {
+ if (_g_mime_type_matches (mime_type, "application/vnd.ms-cab-compressed")
+ || _g_mime_type_matches (mime_type, "application/zip"))
{
capabilities |= FR_COMMAND_CAN_READ;
}
- if (is_mime_type (mime_type, "application/zip"))
+ if (_g_mime_type_matches (mime_type, "application/zip"))
capabilities |= FR_COMMAND_CAN_WRITE;
}
@@ -612,9 +612,9 @@ static const char *
fr_command_7z_get_packages (FrCommand *comm,
const char *mime_type)
{
- if (is_mime_type (mime_type, "application/x-rar"))
+ if (_g_mime_type_matches (mime_type, "application/x-rar"))
return PACKAGES ("p7zip,p7zip-rar");
- else if (is_mime_type (mime_type, "application/zip") || is_mime_type (mime_type, "application/vnd.ms-cab-compressed"))
+ else if (_g_mime_type_matches (mime_type, "application/zip") || _g_mime_type_matches (mime_type, "application/vnd.ms-cab-compressed"))
return PACKAGES ("p7zip,p7zip-full");
else
return PACKAGES ("p7zip");
diff --git a/src/fr-command-ace.c b/src/fr-command-ace.c
index 8c250f1..a604b4a 100644
--- a/src/fr-command-ace.c
+++ b/src/fr-command-ace.c
@@ -150,8 +150,8 @@ process_line (char *line,
g_strfreev (fields);
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
+ fdata->path = _g_path_remove_level (fdata->full_path);
if (*fdata->name == 0)
file_data_free (fdata);
@@ -252,7 +252,7 @@ fr_command_ace_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_available ("unace", check_command))
+ if (_g_program_is_available ("unace", check_command))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/fr-command-alz.c b/src/fr-command-alz.c
index dc54160..72902bd 100644
--- a/src/fr-command-alz.c
+++ b/src/fr-command-alz.c
@@ -138,13 +138,13 @@ process_line (char *line,
if (*s == '\\') *s = '/';
for (s = fdata->original_path; *s != '\0'; ++s)
if (*s == '\\') *s = '/';
- fdata->name = dir_name_from_path (fdata->full_path);
+ fdata->name = _g_path_get_dir_name (fdata->full_path);
}
else {
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
}
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->path = _g_path_remove_level (fdata->full_path);
if (*fdata->name == 0)
file_data_free (fdata);
@@ -315,7 +315,7 @@ fr_command_alz_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_available ("unalz", check_command))
+ if (_g_program_is_available ("unalz", check_command))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/fr-command-ar.c b/src/fr-command-ar.c
index e8041c2..c4d6def 100644
--- a/src/fr-command-ar.c
+++ b/src/fr-command-ar.c
@@ -22,13 +22,12 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
-
#include <glib.h>
-
#include "file-data.h"
#include "file-utils.h"
#include "fr-command.h"
#include "fr-command-ar.h"
+#include "glib-utils.h"
static void fr_command_ar_class_init (FrCommandArClass *class);
static void fr_command_ar_init (FrCommand *afile);
@@ -129,16 +128,16 @@ process_line (char *line,
fdata = file_data_new ();
- date_idx = file_list__get_index_from_pattern (line, "%c%c%c %a%n %n%n:%n%n %n%n%n%n");
+ date_idx = _g_line_get_index_from_pattern (line, "%c%c%c %a%n %n%n:%n%n %n%n%n%n");
- field_size = file_list__get_prev_field (line, date_idx, 1);
+ field_size = _g_line_get_prev_field (line, date_idx, 1);
fdata->size = g_ascii_strtoull (field_size, NULL, 10);
g_free (field_size);
- field_month = file_list__get_next_field (line, date_idx, 1);
- field_day = file_list__get_next_field (line, date_idx, 2);
- field_time = file_list__get_next_field (line, date_idx, 3);
- field_year = file_list__get_next_field (line, date_idx, 4);
+ field_month = _g_line_get_next_field (line, date_idx, 1);
+ field_day = _g_line_get_next_field (line, date_idx, 2);
+ field_time = _g_line_get_next_field (line, date_idx, 3);
+ field_year = _g_line_get_next_field (line, date_idx, 4);
fdata->modified = mktime_from_string (field_time, field_day, field_month, field_year);
g_free (field_day);
g_free (field_month);
@@ -176,8 +175,8 @@ process_line (char *line,
g_strfreev (fields);
g_free (field_name);
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
+ fdata->path = _g_path_remove_level (fdata->full_path);
if (*fdata->name == 0)
file_data_free (fdata);
@@ -276,7 +275,7 @@ fr_command_ar_handle_error (FrCommand *comm,
}
-const char *ar_mime_type[] = { "application/x-ar",
+const char *ar_mime_type[] = { "application/x-ar",
"application/x-deb",
NULL };
@@ -296,10 +295,10 @@ fr_command_ar_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_available ("ar", check_command)) {
- if (is_mime_type (mime_type, "application/x-deb"))
+ if (_g_program_is_available ("ar", check_command)) {
+ if (_g_mime_type_matches (mime_type, "application/x-deb"))
capabilities |= FR_COMMAND_CAN_READ;
- else if (is_mime_type (mime_type, "application/x-ar"))
+ else if (_g_mime_type_matches (mime_type, "application/x-ar"))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
diff --git a/src/fr-command-arj.c b/src/fr-command-arj.c
index e296670..e3de7aa 100644
--- a/src/fr-command-arj.c
+++ b/src/fr-command-arj.c
@@ -127,8 +127,8 @@ list__process_line (char *line,
fdata->link = NULL;
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
+ fdata->path = _g_path_remove_level (fdata->full_path);
}
else if (arj_comm->line_no == 2) { /* Read file size and date. */
FileData *fdata;
@@ -333,7 +333,7 @@ fr_command_arj_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES | FR_COMMAND_CAN_ENCRYPT;
- if (is_program_available ("arj", check_command))
+ if (_g_program_is_available ("arj", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
return capabilities;
diff --git a/src/fr-command-cfile.c b/src/fr-command-cfile.c
index cb23cad..6221b70 100644
--- a/src/fr-command-cfile.c
+++ b/src/fr-command-cfile.c
@@ -48,7 +48,7 @@ get_uncompressed_name_from_archive (FrCommand *comm,
GInputStream *stream;
char *filename = NULL;
- if (! is_mime_type (comm->mime_type, "application/x-gzip"))
+ if (! _g_mime_type_matches (comm->mime_type, "application/x-gzip"))
return NULL;
file = g_file_new_for_path (archive);
@@ -74,7 +74,7 @@ get_uncompressed_name_from_archive (FrCommand *comm,
str = g_string_new ("");
while (g_input_stream_read (stream, buffer, 1, NULL, NULL) > 0) {
if (buffer[0] == '\0') {
- filename = g_strdup (file_name_from_path (str->str));
+ filename = g_strdup (_g_path_get_file_name (str->str));
#ifdef DEBUG
g_message ("filename is: %s", filename);
#endif
@@ -109,23 +109,23 @@ list__process_line (char *line,
g_strfreev (fields);
if (fdata->size == 0)
- fdata->size = get_file_size (comm->filename);
+ fdata->size = _g_uri_get_file_size (comm->filename);
filename = get_uncompressed_name_from_archive (comm, comm->filename);
if (filename == NULL)
- filename = remove_extension_from_path (comm->filename);
+ filename = _g_path_remove_extension (comm->filename);
fdata->full_path = g_strconcat ("/",
- file_name_from_path (filename),
+ _g_path_get_file_name (filename),
NULL);
g_free (filename);
fdata->original_path = fdata->full_path + 1;
fdata->link = NULL;
- fdata->modified = get_file_mtime_for_path (comm->filename);
+ fdata->modified = _g_path_get_file_mtime (comm->filename);
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
+ fdata->path = _g_path_remove_level (fdata->full_path);
if (*fdata->name == 0)
file_data_free (fdata);
@@ -139,7 +139,7 @@ fr_command_cfile_list (FrCommand *comm)
{
FrCommandCFile *comm_cfile = FR_COMMAND_CFILE (comm);
- if (is_mime_type (comm->mime_type, "application/x-gzip")) {
+ if (_g_mime_type_matches (comm->mime_type, "application/x-gzip")) {
/* gzip let us known the uncompressed size */
fr_process_set_out_line_func (FR_COMMAND (comm)->process,
@@ -163,19 +163,19 @@ fr_command_cfile_list (FrCommand *comm)
fdata = file_data_new ();
- filename = remove_extension_from_path (comm->filename);
+ filename = _g_path_remove_extension (comm->filename);
fdata->full_path = g_strconcat ("/",
- file_name_from_path (filename),
+ _g_path_get_file_name (filename),
NULL);
g_free (filename);
fdata->original_path = fdata->full_path + 1;
fdata->link = NULL;
- fdata->size = get_file_size_for_path (comm->filename);
- fdata->modified = get_file_mtime_for_path (comm->filename);
+ fdata->size = _g_path_get_file_size (comm->filename);
+ fdata->modified = _g_path_get_file_mtime (comm->filename);
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
+ fdata->path = _g_path_remove_level (fdata->full_path);
if (*fdata->name == 0)
file_data_free (fdata);
@@ -210,7 +210,7 @@ fr_command_cfile_add (FrCommand *comm,
/* copy file to the temp dir */
- temp_dir = get_temp_work_dir (NULL);
+ temp_dir = _g_path_get_temp_work_dir (NULL);
filename = file_list->data;
temp_file = g_strconcat (temp_dir, "/", filename, NULL);
@@ -224,7 +224,7 @@ fr_command_cfile_add (FrCommand *comm,
/**/
- if (is_mime_type (comm->mime_type, "application/x-gzip")) {
+ if (_g_mime_type_matches (comm->mime_type, "application/x-gzip")) {
fr_process_begin_command (comm->process, "gzip");
fr_process_set_working_dir (comm->process, temp_dir);
fr_process_add_arg (comm->process, "--");
@@ -232,7 +232,7 @@ fr_command_cfile_add (FrCommand *comm,
fr_process_end_command (comm->process);
compressed_filename = g_strconcat (filename, ".gz", NULL);
}
- else if (is_mime_type (comm->mime_type, "application/x-bzip")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-bzip")) {
fr_process_begin_command (comm->process, "bzip2");
fr_process_set_working_dir (comm->process, temp_dir);
fr_process_add_arg (comm->process, "--");
@@ -240,7 +240,7 @@ fr_command_cfile_add (FrCommand *comm,
fr_process_end_command (comm->process);
compressed_filename = g_strconcat (filename, ".bz2", NULL);
}
- else if (is_mime_type (comm->mime_type, "application/x-compress")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-compress")) {
fr_process_begin_command (comm->process, "compress");
fr_process_set_working_dir (comm->process, temp_dir);
fr_process_add_arg (comm->process, "-f");
@@ -248,7 +248,7 @@ fr_command_cfile_add (FrCommand *comm,
fr_process_end_command (comm->process);
compressed_filename = g_strconcat (filename, ".Z", NULL);
}
- else if (is_mime_type (comm->mime_type, "application/x-lzip")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzip")) {
fr_process_begin_command (comm->process, "lzip");
fr_process_set_working_dir (comm->process, temp_dir);
fr_process_add_arg (comm->process, "--");
@@ -256,7 +256,7 @@ fr_command_cfile_add (FrCommand *comm,
fr_process_end_command (comm->process);
compressed_filename = g_strconcat (filename, ".lz", NULL);
}
- else if (is_mime_type (comm->mime_type, "application/x-lzma")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzma")) {
fr_process_begin_command (comm->process, "lzma");
fr_process_set_working_dir (comm->process, temp_dir);
fr_process_add_arg (comm->process, "--");
@@ -264,7 +264,7 @@ fr_command_cfile_add (FrCommand *comm,
fr_process_end_command (comm->process);
compressed_filename = g_strconcat (filename, ".lzma", NULL);
}
- else if (is_mime_type (comm->mime_type, "application/x-xz")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-xz")) {
fr_process_begin_command (comm->process, "xz");
fr_process_set_working_dir (comm->process, temp_dir);
fr_process_add_arg (comm->process, "--");
@@ -272,7 +272,7 @@ fr_command_cfile_add (FrCommand *comm,
fr_process_end_command (comm->process);
compressed_filename = g_strconcat (filename, ".xz", NULL);
}
- else if (is_mime_type (comm->mime_type, "application/x-lzop")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzop")) {
fr_process_begin_command (comm->process, "lzop");
fr_process_set_working_dir (comm->process, temp_dir);
fr_process_add_arg (comm->process, "-fU");
@@ -282,7 +282,7 @@ fr_command_cfile_add (FrCommand *comm,
fr_process_end_command (comm->process);
compressed_filename = g_strconcat (filename, ".lzo", NULL);
}
- else if (is_mime_type (comm->mime_type, "application/x-rzip")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-rzip")) {
fr_process_begin_command (comm->process, "rzip");
fr_process_set_working_dir (comm->process, temp_dir);
fr_process_add_arg (comm->process, filename);
@@ -341,10 +341,10 @@ fr_command_cfile_extract (FrCommand *comm,
/* copy file to the temp dir, remove the already existing file first */
- temp_dir = get_temp_work_dir (NULL);
+ temp_dir = _g_path_get_temp_work_dir (NULL);
temp_file = g_strconcat (temp_dir,
"/",
- file_name_from_path (comm->filename),
+ _g_path_get_file_name (comm->filename),
NULL);
fr_process_begin_command (comm->process, "cp");
@@ -355,7 +355,7 @@ fr_command_cfile_extract (FrCommand *comm,
/* uncompress the file */
- if (is_mime_type (comm->mime_type, "application/x-gzip")) {
+ if (_g_mime_type_matches (comm->mime_type, "application/x-gzip")) {
fr_process_begin_command (comm->process, "gzip");
fr_process_add_arg (comm->process, "-f");
fr_process_add_arg (comm->process, "-d");
@@ -363,15 +363,15 @@ fr_command_cfile_extract (FrCommand *comm,
fr_process_add_arg (comm->process, temp_file);
fr_process_end_command (comm->process);
}
- else if (is_mime_type (comm->mime_type, "application/x-bzip")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-bzip")) {
fr_process_begin_command (comm->process, "bzip2");
fr_process_add_arg (comm->process, "-f");
fr_process_add_arg (comm->process, "-d");
fr_process_add_arg (comm->process, temp_file);
fr_process_end_command (comm->process);
}
- else if (is_mime_type (comm->mime_type, "application/x-compress")) {
- if (is_program_in_path ("gzip")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-compress")) {
+ if (_g_program_is_in_path ("gzip")) {
fr_process_begin_command (comm->process, "gzip");
fr_process_add_arg (comm->process, "-d");
fr_process_add_arg (comm->process, "-n");
@@ -382,28 +382,28 @@ fr_command_cfile_extract (FrCommand *comm,
fr_process_add_arg (comm->process, temp_file);
fr_process_end_command (comm->process);
}
- else if (is_mime_type (comm->mime_type, "application/x-lzip")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzip")) {
fr_process_begin_command (comm->process, "lzip");
fr_process_add_arg (comm->process, "-f");
fr_process_add_arg (comm->process, "-d");
fr_process_add_arg (comm->process, temp_file);
fr_process_end_command (comm->process);
}
- else if (is_mime_type (comm->mime_type, "application/x-lzma")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzma")) {
fr_process_begin_command (comm->process, "lzma");
fr_process_add_arg (comm->process, "-f");
fr_process_add_arg (comm->process, "-d");
fr_process_add_arg (comm->process, temp_file);
fr_process_end_command (comm->process);
}
- else if (is_mime_type (comm->mime_type, "application/x-xz")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-xz")) {
fr_process_begin_command (comm->process, "xz");
fr_process_add_arg (comm->process, "-f");
fr_process_add_arg (comm->process, "-d");
fr_process_add_arg (comm->process, temp_file);
fr_process_end_command (comm->process);
}
- else if (is_mime_type (comm->mime_type, "application/x-lzop")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzop")) {
fr_process_begin_command (comm->process, "lzop");
fr_process_set_working_dir (comm->process, temp_dir);
fr_process_add_arg (comm->process, "-d");
@@ -412,7 +412,7 @@ fr_command_cfile_extract (FrCommand *comm,
fr_process_add_arg (comm->process, temp_file);
fr_process_end_command (comm->process);
}
- else if (is_mime_type (comm->mime_type, "application/x-rzip")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-rzip")) {
fr_process_begin_command (comm->process, "rzip");
fr_process_add_arg (comm->process, "-f");
fr_process_add_arg (comm->process, "-d");
@@ -422,11 +422,11 @@ fr_command_cfile_extract (FrCommand *comm,
/* copy uncompress file to the dest dir */
- uncompr_file = remove_extension_from_path (temp_file);
+ uncompr_file = _g_path_remove_extension (temp_file);
compr_file = get_uncompressed_name_from_archive (comm, comm->filename);
if (compr_file == NULL)
- compr_file = remove_extension_from_path (file_name_from_path (comm->filename));
+ compr_file = _g_path_remove_extension (_g_path_get_file_name (comm->filename));
dest_file = g_strconcat (dest_dir,
"/",
compr_file,
@@ -480,38 +480,38 @@ fr_command_cfile_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_DO_NOTHING;
- if (is_mime_type (mime_type, "application/x-gzip")) {
- if (is_program_available ("gzip", check_command))
+ if (_g_mime_type_matches (mime_type, "application/x-gzip")) {
+ if (_g_program_is_available ("gzip", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
- else if (is_mime_type (mime_type, "application/x-bzip")) {
- if (is_program_available ("bzip2", check_command))
+ else if (_g_mime_type_matches (mime_type, "application/x-bzip")) {
+ if (_g_program_is_available ("bzip2", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
- else if (is_mime_type (mime_type, "application/x-compress")) {
- if (is_program_available ("compress", check_command))
+ else if (_g_mime_type_matches (mime_type, "application/x-compress")) {
+ if (_g_program_is_available ("compress", check_command))
capabilities |= FR_COMMAND_CAN_WRITE;
- if (is_program_available ("uncompress", check_command) || is_program_available ("gzip", check_command))
+ if (_g_program_is_available ("uncompress", check_command) || _g_program_is_available ("gzip", check_command))
capabilities |= FR_COMMAND_CAN_READ;
}
- else if (is_mime_type (mime_type, "application/x-lzip")) {
- if (is_program_available ("lzip", check_command))
+ else if (_g_mime_type_matches (mime_type, "application/x-lzip")) {
+ if (_g_program_is_available ("lzip", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
- else if (is_mime_type (mime_type, "application/x-lzma")) {
- if (is_program_available ("lzma", check_command))
+ else if (_g_mime_type_matches (mime_type, "application/x-lzma")) {
+ if (_g_program_is_available ("lzma", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
- else if (is_mime_type (mime_type, "application/x-xz")) {
- if (is_program_available ("xz", check_command))
+ else if (_g_mime_type_matches (mime_type, "application/x-xz")) {
+ if (_g_program_is_available ("xz", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
- else if (is_mime_type (mime_type, "application/x-lzop")) {
- if (is_program_available ("lzop", check_command))
+ else if (_g_mime_type_matches (mime_type, "application/x-lzop")) {
+ if (_g_program_is_available ("lzop", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
- else if (is_mime_type (mime_type, "application/x-rzip")) {
- if (is_program_available ("rzip", check_command))
+ else if (_g_mime_type_matches (mime_type, "application/x-rzip")) {
+ if (_g_program_is_available ("rzip", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
@@ -535,21 +535,21 @@ static const char *
fr_command_cfile_get_packages (FrCommand *comm,
const char *mime_type)
{
- if (is_mime_type (mime_type, "application/x-gzip"))
+ if (_g_mime_type_matches (mime_type, "application/x-gzip"))
return PACKAGES ("gzip");
- else if (is_mime_type (mime_type, "application/x-bzip"))
+ else if (_g_mime_type_matches (mime_type, "application/x-bzip"))
return PACKAGES ("bzip2");
- else if (is_mime_type (mime_type, "application/x-compress"))
+ else if (_g_mime_type_matches (mime_type, "application/x-compress"))
return PACKAGES ("ncompress");
- else if (is_mime_type (mime_type, "application/x-lzip"))
+ else if (_g_mime_type_matches (mime_type, "application/x-lzip"))
return PACKAGES ("lzip");
- else if (is_mime_type (mime_type, "application/x-lzma"))
+ else if (_g_mime_type_matches (mime_type, "application/x-lzma"))
return PACKAGES ("lzma");
- else if (is_mime_type (mime_type, "application/x-xz"))
+ else if (_g_mime_type_matches (mime_type, "application/x-xz"))
return PACKAGES ("xz");
- else if (is_mime_type (mime_type, "application/x-lzop"))
+ else if (_g_mime_type_matches (mime_type, "application/x-lzop"))
return PACKAGES ("lzop");
- else if (is_mime_type (mime_type, "application/x-rzip"))
+ else if (_g_mime_type_matches (mime_type, "application/x-rzip"))
return PACKAGES ("rzip");
return NULL;
diff --git a/src/fr-command-cpio.c b/src/fr-command-cpio.c
index 907bbe1..7700ac2 100644
--- a/src/fr-command-cpio.c
+++ b/src/fr-command-cpio.c
@@ -156,10 +156,10 @@ list__process_line (char *line,
g_strfreev (fields);
if (fdata->dir)
- fdata->name = dir_name_from_path (fdata->full_path);
+ fdata->name = _g_path_get_dir_name (fdata->full_path);
else
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
+ fdata->path = _g_path_remove_level (fdata->full_path);
if (*fdata->name == 0)
file_data_free (fdata);
@@ -239,7 +239,7 @@ fr_command_cpio_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_available ("cpio", check_command))
+ if (_g_program_is_available ("cpio", check_command))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/fr-command-dpkg.c b/src/fr-command-dpkg.c
index 9191a58..4cd1739 100644
--- a/src/fr-command-dpkg.c
+++ b/src/fr-command-dpkg.c
@@ -144,10 +144,10 @@ process_data_line (char *line,
g_strfreev (fields);
if (fdata->dir)
- fdata->name = dir_name_from_path (fdata->full_path);
+ fdata->name = _g_path_get_dir_name (fdata->full_path);
else
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
+ fdata->path = _g_path_remove_level (fdata->full_path);
if (*fdata->name == 0)
file_data_free (fdata);
@@ -224,7 +224,7 @@ fr_command_dpkg_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_available ("dpkg-deb", check_command))
+ if (_g_program_is_available ("dpkg-deb", check_command))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/fr-command-iso.c b/src/fr-command-iso.c
index 4d505d7..3cced06 100644
--- a/src/fr-command-iso.c
+++ b/src/fr-command-iso.c
@@ -118,8 +118,8 @@ list__process_line (char *line,
else
fdata->full_path = g_strstrip (g_strconcat (comm_iso->cur_path, name_field, NULL));
fdata->original_path = fdata->full_path;
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
+ fdata->path = _g_path_remove_level (fdata->full_path);
fr_command_add_file (comm, fdata);
}
@@ -170,8 +170,8 @@ fr_command_iso_extract (FrCommand *comm,
char *file_dir;
char *temp_dest_dir = NULL;
- filename = file_name_from_path (path);
- file_dir = remove_level_from_path (path);
+ filename = _g_path_get_file_name (path);
+ file_dir = _g_path_remove_level (path);
if ((file_dir != NULL) && (strcmp (file_dir, "/") != 0))
temp_dest_dir = g_build_filename (dest_dir, file_dir, NULL);
else
@@ -181,7 +181,7 @@ fr_command_iso_extract (FrCommand *comm,
if (temp_dest_dir == NULL)
continue;
- make_directory_tree_from_path (temp_dest_dir, 0700, NULL);
+ _g_path_make_directory_tree (temp_dest_dir, 0700, NULL);
fr_process_begin_command (comm->process, "sh");
fr_process_set_working_dir (comm->process, temp_dest_dir);
@@ -216,7 +216,7 @@ fr_command_iso_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_available ("isoinfo", check_command))
+ if (_g_program_is_available ("isoinfo", check_command))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/fr-command-jar.c b/src/fr-command-jar.c
index fc7701c..147306b 100644
--- a/src/fr-command-jar.c
+++ b/src/fr-command-jar.c
@@ -63,12 +63,12 @@ fr_command_jar_add (FrCommand *comm,
for (scan = file_list; scan; scan = scan->next) {
char *filename = scan->data;
- char *path = build_uri (base_dir, filename, NULL);
+ char *path = _g_uri_build (base_dir, filename, NULL);
char *package = NULL;
- if (file_extension_is (filename, ".java"))
+ if (_g_filename_has_extension (filename, ".java"))
package = get_package_name_from_java_file (path);
- else if (file_extension_is (filename, ".class"))
+ else if (_g_filename_has_extension (filename, ".class"))
package = get_package_name_from_class_file (path);
if ((package == NULL) || (strlen (package) == 0))
@@ -76,10 +76,10 @@ fr_command_jar_add (FrCommand *comm,
else {
JarData *newdata = g_new0 (JarData, 1);
- newdata->package_minus_one_level = remove_level_from_path (package);
- newdata->link_name = g_strdup (file_name_from_path (package));
- newdata->rel_path = remove_level_from_path (filename);
- newdata->filename = g_strdup (file_name_from_path (filename));
+ newdata->package_minus_one_level = _g_path_remove_level (package);
+ newdata->link_name = g_strdup (_g_path_get_file_name (package));
+ newdata->rel_path = _g_path_remove_level (filename);
+ newdata->filename = g_strdup (_g_path_get_file_name (filename));
jardata_list = g_list_append (jardata_list, newdata);
}
@@ -87,7 +87,7 @@ fr_command_jar_add (FrCommand *comm,
g_free (path);
}
- tmp_dir = get_temp_work_dir (NULL);
+ tmp_dir = _g_path_get_temp_work_dir (NULL);
for (scan = jardata_list; scan ; scan = scan->next) {
JarData *jdata = scan->data;
char *pack_path;
@@ -95,13 +95,13 @@ fr_command_jar_add (FrCommand *comm,
char *link_name;
int retval;
- pack_path = build_uri (tmp_dir, jdata->package_minus_one_level, NULL);
- if (! make_directory_tree_from_path (pack_path, 0755, NULL)) {
+ pack_path = _g_uri_build (tmp_dir, jdata->package_minus_one_level, NULL);
+ if (! _g_path_make_directory_tree (pack_path, 0755, NULL)) {
g_free (pack_path);
continue;
}
- old_link = build_uri (base_dir, jdata->rel_path, NULL);
+ old_link = _g_uri_build (base_dir, jdata->rel_path, NULL);
link_name = g_build_filename (pack_path, jdata->link_name, NULL);
retval = symlink (old_link, link_name);
@@ -165,7 +165,7 @@ fr_command_jar_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_available ("zip", check_command))
+ if (_g_program_is_available ("zip", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
return capabilities;
diff --git a/src/fr-command-lha.c b/src/fr-command-lha.c
index d7c1bd0..5dd13f1 100644
--- a/src/fr-command-lha.c
+++ b/src/fr-command-lha.c
@@ -195,11 +195,11 @@ process_line (char *line,
fdata->dir = line[0] == 'd';
if (fdata->dir)
- fdata->name = dir_name_from_path (fdata->full_path);
+ fdata->name = _g_path_get_dir_name (fdata->full_path);
else
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->path = _g_path_remove_level (fdata->full_path);
if (*fdata->name == 0)
file_data_free (fdata);
@@ -318,7 +318,7 @@ fr_command_lha_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_available ("lha", check_command))
+ if (_g_program_is_available ("lha", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
return capabilities;
diff --git a/src/fr-command-lrzip.c b/src/fr-command-lrzip.c
index ddbd397..a54e2dc 100644
--- a/src/fr-command-lrzip.c
+++ b/src/fr-command-lrzip.c
@@ -58,7 +58,7 @@ list__process_line (char *line,
fdata->encrypted = FALSE;
- char *new_fname = g_strdup (file_name_from_path (comm->filename));
+ char *new_fname = g_strdup (_g_path_get_file_name (comm->filename));
if (g_str_has_suffix (new_fname, ".lrz"))
new_fname[strlen (new_fname) - 4] = '\0';
@@ -70,7 +70,7 @@ list__process_line (char *line,
fdata->full_path = g_strconcat ("/", new_fname, NULL);
fdata->original_path = fdata->full_path + 1;
}
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->path = _g_path_remove_level (fdata->full_path);
fdata->name = new_fname;
fdata->dir = FALSE;
fdata->link = NULL;
@@ -181,7 +181,7 @@ fr_command_lrzip_get_capabilities (FrCommand *comm,
{
FrCommandCap capabilities = FR_COMMAND_CAN_DO_NOTHING;
- if (is_program_available ("lrzip", check_command))
+ if (_g_program_is_available ("lrzip", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
return capabilities;
diff --git a/src/fr-command-rar.c b/src/fr-command-rar.c
index 721b857..53ac186 100644
--- a/src/fr-command-rar.c
+++ b/src/fr-command-rar.c
@@ -48,7 +48,7 @@ static FrCommandClass *parent_class = NULL;
static gboolean
have_rar (void)
{
- return is_program_in_path ("rar");
+ return _g_program_is_in_path ("rar");
}
@@ -156,11 +156,11 @@ process_line (char *line,
g_free (tmp);
- fdata->name = dir_name_from_path (fdata->full_path);
+ fdata->name = _g_path_get_dir_name (fdata->full_path);
fdata->dir = TRUE;
}
else
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
fr_command_add_file (comm, fdata);
rar_comm->fdata = NULL;
@@ -191,7 +191,7 @@ process_line (char *line,
}
fdata->link = NULL;
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->path = _g_path_remove_level (fdata->full_path);
}
else {
@@ -286,7 +286,7 @@ parse_progress_line (FrCommand *comm,
if ((len > 5) && (strncmp (filename + len - 5, " OK ", 5) == 0))
filename[len - 5] = 0;
- msg = g_strdup_printf (message_format, file_name_from_path (filename), NULL);
+ msg = g_strdup_printf (message_format, _g_path_get_file_name (filename), NULL);
fr_command_message (comm, msg);
g_free (msg);
@@ -615,9 +615,9 @@ fr_command_rar_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES | FR_COMMAND_CAN_ENCRYPT | FR_COMMAND_CAN_ENCRYPT_HEADER;
- if (is_program_available ("rar", check_command))
+ if (_g_program_is_available ("rar", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE | FR_COMMAND_CAN_CREATE_VOLUMES;
- else if (is_program_available ("unrar", check_command))
+ else if (_g_program_is_available ("unrar", check_command))
capabilities |= FR_COMMAND_CAN_READ;
/* multi-volumes are read-only */
diff --git a/src/fr-command-rpm.c b/src/fr-command-rpm.c
index 739399d..ebf0cdb 100644
--- a/src/fr-command-rpm.c
+++ b/src/fr-command-rpm.c
@@ -164,10 +164,10 @@ list__process_line (char *line,
g_strfreev (fields);
if (fdata->dir)
- fdata->name = dir_name_from_path (fdata->full_path);
+ fdata->name = _g_path_get_dir_name (fdata->full_path);
else
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
+ fdata->path = _g_path_remove_level (fdata->full_path);
if (*fdata->name == 0)
file_data_free (fdata);
@@ -240,7 +240,7 @@ fr_command_rpm_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_available ("cpio", check_command))
+ if (_g_program_is_available ("cpio", check_command))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/fr-command-tar.c b/src/fr-command-tar.c
index 84f8067..5928014 100644
--- a/src/fr-command-tar.c
+++ b/src/fr-command-tar.c
@@ -132,18 +132,18 @@ process_line (char *line,
g_return_if_fail (line != NULL);
- date_idx = file_list__get_index_from_pattern (line, "%n%n%n%n-%n%n-%n%n %n%n:%n%n");
+ date_idx = _g_line_get_index_from_pattern (line, "%n%n%n%n-%n%n-%n%n %n%n:%n%n");
if (date_idx < 0)
return;
fdata = file_data_new ();
- field_size = file_list__get_prev_field (line, date_idx, 1);
+ field_size = _g_line_get_prev_field (line, date_idx, 1);
fdata->size = g_ascii_strtoull (field_size, NULL, 10);
g_free (field_size);
- field_date = file_list__get_next_field (line, date_idx, 1);
- field_time = file_list__get_next_field (line, date_idx, 2);
+ field_date = _g_line_get_next_field (line, date_idx, 1);
+ field_time = _g_line_get_next_field (line, date_idx, 2);
fdata->modified = mktime_from_string (field_date, field_time);
g_free (field_date);
g_free (field_time);
@@ -178,10 +178,10 @@ process_line (char *line,
fdata->dir = line[0] == 'd';
if (fdata->dir)
- fdata->name = dir_name_from_path (fdata->full_path);
+ fdata->name = _g_path_get_dir_name (fdata->full_path);
else
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
+ fdata->path = _g_path_remove_level (fdata->full_path);
if (*fdata->name == 0)
file_data_free (fdata);
@@ -193,34 +193,34 @@ process_line (char *line,
static void
add_compress_arg (FrCommand *comm)
{
- if (is_mime_type (comm->mime_type, "application/x-compressed-tar"))
+ if (_g_mime_type_matches (comm->mime_type, "application/x-compressed-tar"))
fr_process_add_arg (comm->process, "-z");
- else if (is_mime_type (comm->mime_type, "application/x-bzip-compressed-tar"))
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-bzip-compressed-tar"))
fr_process_add_arg (comm->process, "--use-compress-program=bzip2");
- else if (is_mime_type (comm->mime_type, "application/x-tarz")) {
- if (is_program_in_path ("gzip"))
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-tarz")) {
+ if (_g_program_is_in_path ("gzip"))
fr_process_add_arg (comm->process, "-z");
else
fr_process_add_arg (comm->process, "-Z");
}
- else if (is_mime_type (comm->mime_type, "application/x-lrzip-compressed-tar"))
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lrzip-compressed-tar"))
fr_process_add_arg (comm->process, "--use-compress-program=lrzip");
- else if (is_mime_type (comm->mime_type, "application/x-lzip-compressed-tar"))
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzip-compressed-tar"))
fr_process_add_arg (comm->process, "--use-compress-program=lzip");
- else if (is_mime_type (comm->mime_type, "application/x-lzma-compressed-tar"))
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzma-compressed-tar"))
fr_process_add_arg (comm->process, "--use-compress-program=lzma");
- else if (is_mime_type (comm->mime_type, "application/x-xz-compressed-tar"))
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-xz-compressed-tar"))
fr_process_add_arg (comm->process, "--use-compress-program=xz");
- else if (is_mime_type (comm->mime_type, "application/x-lzop-compressed-tar"))
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzop-compressed-tar"))
fr_process_add_arg (comm->process, "--use-compress-program=lzop");
- else if (is_mime_type (comm->mime_type, "application/x-7z-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-7z-compressed-tar")) {
FrCommandTar *comm_tar = (FrCommandTar*) comm;
char *option;
@@ -270,7 +270,7 @@ fr_command_tar_list (FrCommand *comm)
static gboolean
can_create_a_compressed_archive (FrCommand *comm)
{
- return comm->creating_archive && ! is_mime_type (comm->mime_type, "application/x-7z-compressed-tar");
+ return comm->creating_archive && ! _g_mime_type_matches (comm->mime_type, "application/x-7z-compressed-tar");
}
@@ -292,7 +292,7 @@ process_line__generic (char *line,
fr_command_progress (comm, fraction);
}
else {
- char *msg = g_strdup_printf (message_format, file_name_from_path (line), NULL);
+ char *msg = g_strdup_printf (message_format, _g_path_get_file_name (line), NULL);
fr_command_message (comm, msg);
g_free (msg);
}
@@ -512,7 +512,7 @@ fr_command_tar_recompress (FrCommand *comm)
if (can_create_a_compressed_archive (comm))
return;
- if (is_mime_type (comm->mime_type, "application/x-compressed-tar")) {
+ if (_g_mime_type_matches (comm->mime_type, "application/x-compressed-tar")) {
fr_process_begin_command (comm->process, "gzip");
fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
fr_process_set_continue_func (comm->process, gzip_continue_func, comm);
@@ -532,7 +532,7 @@ fr_command_tar_recompress (FrCommand *comm)
new_name = g_strconcat (c_tar->uncomp_filename, ".gz", NULL);
}
- else if (is_mime_type (comm->mime_type, "application/x-bzip-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-bzip-compressed-tar")) {
fr_process_begin_command (comm->process, "bzip2");
fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
switch (comm->compression) {
@@ -551,7 +551,7 @@ fr_command_tar_recompress (FrCommand *comm)
new_name = g_strconcat (c_tar->uncomp_filename, ".bz2", NULL);
}
- else if (is_mime_type (comm->mime_type, "application/x-tarz")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-tarz")) {
fr_process_begin_command (comm->process, "compress");
fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
fr_process_add_arg (comm->process, "-f");
@@ -560,7 +560,7 @@ fr_command_tar_recompress (FrCommand *comm)
new_name = g_strconcat (c_tar->uncomp_filename, ".Z", NULL);
}
- else if (is_mime_type (comm->mime_type, "application/x-lrzip-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lrzip-compressed-tar")) {
fr_process_begin_command (comm->process, "lrzip");
fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
switch (comm->compression) {
@@ -579,7 +579,7 @@ fr_command_tar_recompress (FrCommand *comm)
new_name = g_strconcat (c_tar->uncomp_filename, ".lrz", NULL);
}
- else if (is_mime_type (comm->mime_type, "application/x-lzip-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzip-compressed-tar")) {
fr_process_begin_command (comm->process, "lzip");
fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
switch (comm->compression) {
@@ -598,7 +598,7 @@ fr_command_tar_recompress (FrCommand *comm)
new_name = g_strconcat (c_tar->uncomp_filename, ".lz", NULL);
}
- else if (is_mime_type (comm->mime_type, "application/x-lzma-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzma-compressed-tar")) {
fr_process_begin_command (comm->process, "lzma");
fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
switch (comm->compression) {
@@ -617,7 +617,7 @@ fr_command_tar_recompress (FrCommand *comm)
new_name = g_strconcat (c_tar->uncomp_filename, ".lzma", NULL);
}
- else if (is_mime_type (comm->mime_type, "application/x-xz-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-xz-compressed-tar")) {
fr_process_begin_command (comm->process, "xz");
fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
switch (comm->compression) {
@@ -636,7 +636,7 @@ fr_command_tar_recompress (FrCommand *comm)
new_name = g_strconcat (c_tar->uncomp_filename, ".xz", NULL);
}
- else if (is_mime_type (comm->mime_type, "application/x-lzop-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzop-compressed-tar")) {
fr_process_begin_command (comm->process, "lzop");
fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
switch (comm->compression) {
@@ -656,7 +656,7 @@ fr_command_tar_recompress (FrCommand *comm)
new_name = g_strconcat (c_tar->uncomp_filename, ".lzo", NULL);
}
- else if (is_mime_type (comm->mime_type, "application/x-7z-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-7z-compressed-tar")) {
FrCommandTar *comm_tar = (FrCommandTar*) comm;
fr_process_begin_command (comm->process, comm_tar->compress_command);
@@ -701,7 +701,7 @@ fr_command_tar_recompress (FrCommand *comm)
fr_process_add_arg (comm->process, comm->filename);
fr_process_end_command (comm->process);
- tmp_dir = remove_level_from_path (new_name);
+ tmp_dir = _g_path_remove_level (new_name);
fr_process_begin_command (comm->process, "rm");
fr_process_set_sticky (comm->process, TRUE);
@@ -735,81 +735,81 @@ get_uncompressed_name (FrCommandTar *c_tar,
char *new_name = g_strdup (e_filename);
int l = strlen (new_name);
- if (is_mime_type (comm->mime_type, "application/x-compressed-tar")) {
+ if (_g_mime_type_matches (comm->mime_type, "application/x-compressed-tar")) {
/* X.tgz --> X.tar
* X.tar.gz --> X.tar */
- if (file_extension_is (e_filename, ".tgz")) {
+ if (_g_filename_has_extension (e_filename, ".tgz")) {
new_name[l - 2] = 'a';
new_name[l - 1] = 'r';
}
- else if (file_extension_is (e_filename, ".tar.gz"))
+ else if (_g_filename_has_extension (e_filename, ".tar.gz"))
new_name[l - 3] = 0;
}
- else if (is_mime_type (comm->mime_type, "application/x-bzip-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-bzip-compressed-tar")) {
/* X.tbz2 --> X.tar
* X.tar.bz2 --> X.tar */
- if (file_extension_is (e_filename, ".tbz2")) {
+ if (_g_filename_has_extension (e_filename, ".tbz2")) {
new_name[l - 3] = 'a';
new_name[l - 2] = 'r';
new_name[l - 1] = 0;
}
- else if (file_extension_is (e_filename, ".tar.bz2"))
+ else if (_g_filename_has_extension (e_filename, ".tar.bz2"))
new_name[l - 4] = 0;
}
- else if (is_mime_type (comm->mime_type, "application/x-tarz")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-tarz")) {
/* X.taz --> X.tar
* X.tar.Z --> X.tar */
- if (file_extension_is (e_filename, ".taz"))
+ if (_g_filename_has_extension (e_filename, ".taz"))
new_name[l - 1] = 'r';
- else if (file_extension_is (e_filename, ".tar.Z"))
+ else if (_g_filename_has_extension (e_filename, ".tar.Z"))
new_name[l - 2] = 0;
}
- else if (is_mime_type (comm->mime_type, "application/x-lrzip-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lrzip-compressed-tar")) {
/* X.tlrz --> X.tar
* X.tar.lrz --> X.tar */
- if (file_extension_is (e_filename, ".tlrz")) {
+ if (_g_filename_has_extension (e_filename, ".tlrz")) {
new_name[l - 3] = 'a';
new_name[l - 2] = 'r';
new_name[l - 1] = 0;
}
- else if (file_extension_is (e_filename, ".tar.lrz"))
+ else if (_g_filename_has_extension (e_filename, ".tar.lrz"))
new_name[l - 4] = 0;
}
- else if (is_mime_type (comm->mime_type, "application/x-lzip-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzip-compressed-tar")) {
/* X.tlz --> X.tar
* X.tar.lz --> X.tar */
- if (file_extension_is (e_filename, ".tlz")) {
+ if (_g_filename_has_extension (e_filename, ".tlz")) {
new_name[l - 2] = 'a';
new_name[l - 1] = 'r';
}
- else if (file_extension_is (e_filename, ".tar.lz"))
+ else if (_g_filename_has_extension (e_filename, ".tar.lz"))
new_name[l - 3] = 0;
}
- else if (is_mime_type (comm->mime_type, "application/x-lzma-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzma-compressed-tar")) {
/* X.tar.lzma --> X.tar
* (There doesn't seem to be a shorthand suffix) */
- if (file_extension_is (e_filename, ".tar.lzma"))
+ if (_g_filename_has_extension (e_filename, ".tar.lzma"))
new_name[l - 5] = 0;
}
- else if (is_mime_type (comm->mime_type, "application/x-xz-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-xz-compressed-tar")) {
/* X.tar.xz --> X.tar
* (There doesn't seem to be a shorthand suffix) */
- if (file_extension_is (e_filename, ".tar.xz"))
+ if (_g_filename_has_extension (e_filename, ".tar.xz"))
new_name[l - 3] = 0;
}
- else if (is_mime_type (comm->mime_type, "application/x-lzop-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzop-compressed-tar")) {
/* X.tzo --> X.tar
* X.tar.lzo --> X.tar */
- if (file_extension_is (e_filename, ".tzo")) {
+ if (_g_filename_has_extension (e_filename, ".tzo")) {
new_name[l - 2] = 'a';
new_name[l - 1] = 'r';
}
- else if (file_extension_is (e_filename, ".tar.lzo"))
+ else if (_g_filename_has_extension (e_filename, ".tar.lzo"))
new_name[l - 4] = 0;
}
- else if (is_mime_type (comm->mime_type, "application/x-7z-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-7z-compressed-tar")) {
/* X.tar.7z --> X.tar */
- if (file_extension_is (e_filename, ".tar.7z"))
+ if (_g_filename_has_extension (e_filename, ".tar.7z"))
new_name[l - 3] = 0;
}
@@ -824,14 +824,14 @@ static char *
get_temp_name (FrCommandTar *c_tar,
const char *filepath)
{
- char *dirname = remove_level_from_path (filepath);
+ char *dirname = _g_path_remove_level (filepath);
char *template;
char *result = NULL;
char *temp_name = NULL;
template = g_strconcat (dirname, "/.fr-XXXXXX", NULL);
result = mkdtemp (template);
- temp_name = g_build_filename (result, file_name_from_path (filepath), NULL);
+ temp_name = g_build_filename (result, _g_path_get_file_name (filepath), NULL);
g_free (template);
return temp_name;
@@ -855,7 +855,7 @@ fr_command_tar_uncompress (FrCommand *comm)
archive_exists = ! comm->creating_archive;
- c_tar->name_modified = ! is_mime_type (comm->mime_type, "application/x-tar");
+ c_tar->name_modified = ! _g_mime_type_matches (comm->mime_type, "application/x-tar");
if (c_tar->name_modified) {
tmp_name = get_temp_name (c_tar, comm->filename);
if (archive_exists) {
@@ -870,7 +870,7 @@ fr_command_tar_uncompress (FrCommand *comm)
tmp_name = g_strdup (comm->filename);
if (archive_exists) {
- if (is_mime_type (comm->mime_type, "application/x-compressed-tar")) {
+ if (_g_mime_type_matches (comm->mime_type, "application/x-compressed-tar")) {
fr_process_begin_command (comm->process, "gzip");
fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
fr_process_set_continue_func (comm->process, gzip_continue_func, comm);
@@ -879,7 +879,7 @@ fr_command_tar_uncompress (FrCommand *comm)
fr_process_add_arg (comm->process, tmp_name);
fr_process_end_command (comm->process);
}
- else if (is_mime_type (comm->mime_type, "application/x-bzip-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-bzip-compressed-tar")) {
fr_process_begin_command (comm->process, "bzip2");
fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
fr_process_add_arg (comm->process, "-f");
@@ -887,8 +887,8 @@ fr_command_tar_uncompress (FrCommand *comm)
fr_process_add_arg (comm->process, tmp_name);
fr_process_end_command (comm->process);
}
- else if (is_mime_type (comm->mime_type, "application/x-tarz")) {
- if (is_program_in_path ("gzip")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-tarz")) {
+ if (_g_program_is_in_path ("gzip")) {
fr_process_begin_command (comm->process, "gzip");
fr_process_set_continue_func (comm->process, gzip_continue_func, comm);
}
@@ -899,7 +899,7 @@ fr_command_tar_uncompress (FrCommand *comm)
fr_process_add_arg (comm->process, tmp_name);
fr_process_end_command (comm->process);
}
- else if (is_mime_type (comm->mime_type, "application/x-lrzip-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lrzip-compressed-tar")) {
fr_process_begin_command (comm->process, "lrzip");
fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
fr_process_add_arg (comm->process, "-f");
@@ -907,7 +907,7 @@ fr_command_tar_uncompress (FrCommand *comm)
fr_process_add_arg (comm->process, tmp_name);
fr_process_end_command (comm->process);
}
- else if (is_mime_type (comm->mime_type, "application/x-lzip-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzip-compressed-tar")) {
fr_process_begin_command (comm->process, "lzip");
fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
fr_process_add_arg (comm->process, "-f");
@@ -915,7 +915,7 @@ fr_command_tar_uncompress (FrCommand *comm)
fr_process_add_arg (comm->process, tmp_name);
fr_process_end_command (comm->process);
}
- else if (is_mime_type (comm->mime_type, "application/x-lzma-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzma-compressed-tar")) {
fr_process_begin_command (comm->process, "lzma");
fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
fr_process_add_arg (comm->process, "-f");
@@ -923,7 +923,7 @@ fr_command_tar_uncompress (FrCommand *comm)
fr_process_add_arg (comm->process, tmp_name);
fr_process_end_command (comm->process);
}
- else if (is_mime_type (comm->mime_type, "application/x-xz-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-xz-compressed-tar")) {
fr_process_begin_command (comm->process, "xz");
fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
fr_process_add_arg (comm->process, "-f");
@@ -931,7 +931,7 @@ fr_command_tar_uncompress (FrCommand *comm)
fr_process_add_arg (comm->process, tmp_name);
fr_process_end_command (comm->process);
}
- else if (is_mime_type (comm->mime_type, "application/x-lzop-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-lzop-compressed-tar")) {
fr_process_begin_command (comm->process, "lzop");
fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
fr_process_add_arg (comm->process, "-dfU");
@@ -939,7 +939,7 @@ fr_command_tar_uncompress (FrCommand *comm)
fr_process_add_arg (comm->process, tmp_name);
fr_process_end_command (comm->process);
}
- else if (is_mime_type (comm->mime_type, "application/x-7z-compressed-tar")) {
+ else if (_g_mime_type_matches (comm->mime_type, "application/x-7z-compressed-tar")) {
FrCommandTar *comm_tar = (FrCommandTar*) comm;
fr_process_begin_command (comm->process, comm_tar->compress_command);
@@ -1005,52 +1005,52 @@ fr_command_tar_get_capabilities (FrCommand *comm,
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
/* In solaris gtar is present under /usr/sfw/bin */
- if (! is_program_available ("tar", check_command) && ! is_program_available ("/usr/sfw/bin/gtar", check_command))
+ if (! _g_program_is_available ("tar", check_command) && ! _g_program_is_available ("/usr/sfw/bin/gtar", check_command))
return capabilities;
- if (is_mime_type (mime_type, "application/x-tar")) {
+ if (_g_mime_type_matches (mime_type, "application/x-tar")) {
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
- else if (is_mime_type (mime_type, "application/x-compressed-tar")) {
- if (is_program_available ("gzip", check_command))
+ else if (_g_mime_type_matches (mime_type, "application/x-compressed-tar")) {
+ if (_g_program_is_available ("gzip", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
- else if (is_mime_type (mime_type, "application/x-bzip-compressed-tar")) {
- if (is_program_available ("bzip2", check_command))
+ else if (_g_mime_type_matches (mime_type, "application/x-bzip-compressed-tar")) {
+ if (_g_program_is_available ("bzip2", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
- else if (is_mime_type (mime_type, "application/x-tarz")) {
- if (is_program_available ("compress", check_command) && is_program_available ("uncompress", check_command))
+ else if (_g_mime_type_matches (mime_type, "application/x-tarz")) {
+ if (_g_program_is_available ("compress", check_command) && _g_program_is_available ("uncompress", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
- else if (is_program_available ("gzip", check_command))
+ else if (_g_program_is_available ("gzip", check_command))
capabilities |= FR_COMMAND_CAN_READ;
}
- else if (is_mime_type (mime_type, "application/x-lrzip-compressed-tar")) {
- if (is_program_available ("lrzip", check_command))
+ else if (_g_mime_type_matches (mime_type, "application/x-lrzip-compressed-tar")) {
+ if (_g_program_is_available ("lrzip", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
- else if (is_mime_type (mime_type, "application/x-lzip-compressed-tar")) {
- if (is_program_available ("lzip", check_command))
+ else if (_g_mime_type_matches (mime_type, "application/x-lzip-compressed-tar")) {
+ if (_g_program_is_available ("lzip", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
- else if (is_mime_type (mime_type, "application/x-lzma-compressed-tar")) {
- if (is_program_available ("lzma", check_command))
+ else if (_g_mime_type_matches (mime_type, "application/x-lzma-compressed-tar")) {
+ if (_g_program_is_available ("lzma", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
- else if (is_mime_type (mime_type, "application/x-xz-compressed-tar")) {
- if (is_program_available ("xz", check_command))
+ else if (_g_mime_type_matches (mime_type, "application/x-xz-compressed-tar")) {
+ if (_g_program_is_available ("xz", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
- else if (is_mime_type (mime_type, "application/x-lzop-compressed-tar")) {
- if (is_program_available ("lzop", check_command))
+ else if (_g_mime_type_matches (mime_type, "application/x-lzop-compressed-tar")) {
+ if (_g_program_is_available ("lzop", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
- else if (is_mime_type (mime_type, "application/x-7z-compressed-tar")) {
+ else if (_g_mime_type_matches (mime_type, "application/x-7z-compressed-tar")) {
char *try_command[3] = { "7za", "7zr", "7z" };
int i;
for (i = 0; i < G_N_ELEMENTS (try_command); i++) {
- if (is_program_available (try_command[i], check_command)) {
+ if (_g_program_is_available (try_command[i], check_command)) {
capabilities |= FR_COMMAND_CAN_WRITE;
break;
}
@@ -1069,12 +1069,12 @@ fr_command_tar_set_mime_type (FrCommand *comm,
FR_COMMAND_CLASS (parent_class)->set_mime_type (comm, mime_type);
- if (is_mime_type (mime_type, "application/x-7z-compressed-tar")) {
+ if (_g_mime_type_matches (mime_type, "application/x-7z-compressed-tar")) {
char *try_command[3] = { "7za", "7zr", "7z" };
int i;
for (i = 0; i < G_N_ELEMENTS (try_command); i++) {
- if (is_program_in_path (try_command[i])) {
+ if (_g_program_is_in_path (try_command[i])) {
comm_tar->compress_command = g_strdup (try_command[i]);
break;
}
@@ -1087,25 +1087,25 @@ static const char *
fr_command_tar_get_packages (FrCommand *comm,
const char *mime_type)
{
- if (is_mime_type (mime_type, "application/x-tar"))
+ if (_g_mime_type_matches (mime_type, "application/x-tar"))
return PACKAGES ("tar");
- else if (is_mime_type (mime_type, "application/x-compressed-tar"))
+ else if (_g_mime_type_matches (mime_type, "application/x-compressed-tar"))
return PACKAGES ("tar,gzip");
- else if (is_mime_type (mime_type, "application/x-bzip-compressed-tar"))
+ else if (_g_mime_type_matches (mime_type, "application/x-bzip-compressed-tar"))
return PACKAGES ("tar,bzip2");
- else if (is_mime_type (mime_type, "application/x-tarz"))
+ else if (_g_mime_type_matches (mime_type, "application/x-tarz"))
return PACKAGES ("tar,gzip,ncompress");
- else if (is_mime_type (mime_type, "application/x-lrzip-compressed-tar"))
+ else if (_g_mime_type_matches (mime_type, "application/x-lrzip-compressed-tar"))
return PACKAGES ("tar,lrzip");
- else if (is_mime_type (mime_type, "application/x-lzip-compressed-tar"))
+ else if (_g_mime_type_matches (mime_type, "application/x-lzip-compressed-tar"))
return PACKAGES ("tar,lzip");
- else if (is_mime_type (mime_type, "application/x-lzma-compressed-tar"))
+ else if (_g_mime_type_matches (mime_type, "application/x-lzma-compressed-tar"))
return PACKAGES ("tar,lzma");
- else if (is_mime_type (mime_type, "application/x-xz-compressed-tar"))
+ else if (_g_mime_type_matches (mime_type, "application/x-xz-compressed-tar"))
return PACKAGES ("tar,xz");
- else if (is_mime_type (mime_type, "application/x-lzop-compressed-tar"))
+ else if (_g_mime_type_matches (mime_type, "application/x-lzop-compressed-tar"))
return PACKAGES ("tar,lzop");
- else if (is_mime_type (mime_type, "application/x-7z-compressed-tar"))
+ else if (_g_mime_type_matches (mime_type, "application/x-7z-compressed-tar"))
return PACKAGES ("tar,p7zip");
return NULL;
diff --git a/src/fr-command-unstuff.c b/src/fr-command-unstuff.c
index 9dfae8c..e7cb4be 100644
--- a/src/fr-command-unstuff.c
+++ b/src/fr-command-unstuff.c
@@ -23,13 +23,12 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
-
#include <glib.h>
-
#include "file-data.h"
#include "file-utils.h"
#include "fr-command.h"
#include "fr-command-unstuff.h"
+#include "glib-utils.h"
static void fr_command_unstuff_class_init (FrCommandUnstuffClass *class);
static void fr_command_unstuff_init (FrCommand *afile);
@@ -164,8 +163,8 @@ process_line (char *line,
fdata->full_path = filename;
fdata->original_path = filename;
fdata->link = NULL;
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
+ fdata->path = _g_path_remove_level (fdata->full_path);
fdata->size = 0;
fdata->modified = time (NULL);
@@ -201,7 +200,7 @@ fr_command_unstuff_list (FrCommand *comm)
fr_process_add_arg (comm->process, "--trace");
/* Actually unpack everything in a temporary directory */
- path = get_temp_work_dir (NULL);
+ path = _g_path_get_temp_work_dir (NULL);
path_dots = unstuff_is_shit_with_filenames (path);
g_free (path);
@@ -293,7 +292,7 @@ fr_command_unstuff_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_available ("unstuff", check_command))
+ if (_g_program_is_available ("unstuff", check_command))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/fr-command-zip.c b/src/fr-command-zip.c
index abcc6ed..788d984 100644
--- a/src/fr-command-zip.c
+++ b/src/fr-command-zip.c
@@ -149,10 +149,10 @@ list__process_line (char *line,
fdata->dir = line[0] == 'd';
if (fdata->dir)
- fdata->name = dir_name_from_path (fdata->full_path);
+ fdata->name = _g_path_get_dir_name (fdata->full_path);
else
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
+ fdata->path = _g_path_remove_level (fdata->full_path);
if (*fdata->name == 0)
file_data_free (fdata);
@@ -401,13 +401,13 @@ fr_command_zip_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES | FR_COMMAND_CAN_ENCRYPT;
- if (is_program_available ("zip", check_command)) {
+ if (_g_program_is_available ("zip", check_command)) {
if (strcmp (mime_type, "application/x-ms-dos-executable") == 0)
capabilities |= FR_COMMAND_CAN_READ;
else
capabilities |= FR_COMMAND_CAN_WRITE;
}
- if (is_program_available ("unzip", check_command))
+ if (_g_program_is_available ("unzip", check_command))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/fr-command-zoo.c b/src/fr-command-zoo.c
index 4f0f0f5..a0086a1 100644
--- a/src/fr-command-zoo.c
+++ b/src/fr-command-zoo.c
@@ -208,8 +208,8 @@ process_zoo_line (char *line,
fdata->original_path = fdata->full_path + 1;
}
- fdata->name = g_strdup (file_name_from_path (fdata->full_path));
- fdata->path = remove_level_from_path (fdata->full_path);
+ fdata->name = g_strdup (_g_path_get_file_name (fdata->full_path));
+ fdata->path = _g_path_remove_level (fdata->full_path);
if (*fdata->name == 0)
file_data_free (fdata);
@@ -337,7 +337,7 @@ fr_command_zoo_get_capabilities (FrCommand *comm,
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_available ("zoo", check_command))
+ if (_g_program_is_available ("zoo", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
return capabilities;
diff --git a/src/fr-init.c b/src/fr-init.c
index 13fc0ba..f039731 100644
--- a/src/fr-init.c
+++ b/src/fr-init.c
@@ -180,12 +180,12 @@ migrate_options_directory (void)
old_directory_path = get_home_relative_path (".gnome2/file-roller/options");
old_directory = g_file_new_for_path (old_directory_path);
- new_directory = get_user_config_subdirectory (ADD_FOLDER_OPTIONS_DIR, FALSE);
+ new_directory = _g_file_new_user_config_subdir (ADD_FOLDER_OPTIONS_DIR, FALSE);
if (g_file_query_exists (old_directory, NULL) && ! g_file_query_exists (new_directory, NULL)) {
GFile *parent;
parent = g_file_get_parent (new_directory);
- if (make_directory_tree (parent, 0700, NULL))
+ if (_g_file_make_directory_tree (parent, 0700, NULL))
g_file_move (old_directory, new_directory, 0, NULL, NULL, NULL, NULL);
g_object_unref (parent);
@@ -459,7 +459,7 @@ get_archive_filename_extension (const char *filename)
if (filename == NULL)
return NULL;
- ext = get_file_extension (filename);
+ ext = _g_filename_get_extension (filename);
if (ext == NULL)
return NULL;
@@ -623,7 +623,7 @@ command_done (CommandData *cdata)
if (cdata == NULL)
return;
- if ((cdata->temp_dir != NULL) && path_is_dir (cdata->temp_dir)) {
+ if ((cdata->temp_dir != NULL) && _g_path_query_is_dir (cdata->temp_dir)) {
char *argv[4];
argv[0] = "rm";
diff --git a/src/fr-window.c b/src/fr-window.c
index f263bbd..e4bce48 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -1238,7 +1238,7 @@ get_parent_dir (const char *current_dir)
dir = g_strdup (current_dir);
dir[strlen (dir) - 1] = 0;
- new_dir = remove_level_from_path (dir);
+ new_dir = _g_path_remove_level (dir);
g_free (dir);
if (new_dir[strlen (new_dir) - 1] == '/')
@@ -1562,10 +1562,10 @@ fr_window_populate_file_list (FrWindow *window,
char *s_time;
if (fdata->list_dir)
- tmp = remove_ending_separator (fr_window_get_current_location (window));
+ tmp = _g_path_remove_ending_separator (fr_window_get_current_location (window));
else
- tmp = remove_level_from_path (fdata->path);
+ tmp = _g_path_remove_level (fdata->path);
utf8_path = g_filename_display_name (tmp);
g_free (tmp);
@@ -1720,7 +1720,7 @@ fr_window_update_current_location (FrWindow *window)
fr_window_history_print (window);
#endif
- path = remove_ending_separator (current_dir);
+ path = _g_path_remove_ending_separator (current_dir);
if (get_tree_iter_from_path (window, path, NULL, &iter)) {
GtkTreeSelection *selection;
GtkTreePath *t_path;
@@ -1778,9 +1778,9 @@ fr_window_update_dir_tree (FrWindow *window)
}
if (fdata->dir)
- dir = remove_ending_separator (fdata->full_path);
+ dir = _g_path_remove_ending_separator (fdata->full_path);
else
- dir = remove_level_from_path (fdata->full_path);
+ dir = _g_path_remove_level (fdata->full_path);
while ((dir != NULL) && (strcmp (dir, "/") != 0)) {
char *new_dir;
@@ -1792,7 +1792,7 @@ fr_window_update_dir_tree (FrWindow *window)
g_ptr_array_add (dirs, new_dir);
g_hash_table_replace (dir_cache, new_dir, "1");
- dir = remove_level_from_path (new_dir);
+ dir = _g_path_remove_level (new_dir);
}
g_free (dir);
@@ -1837,7 +1837,7 @@ fr_window_update_dir_tree (FrWindow *window)
GtkTreeIter parent;
GtkTreeIter node;
- parent_dir = remove_level_from_path (dir);
+ parent_dir = _g_path_remove_level (dir);
if (parent_dir == NULL)
continue;
@@ -1848,7 +1848,7 @@ fr_window_update_dir_tree (FrWindow *window)
gtk_tree_store_append (window->priv->tree_store, &node, &parent);
gtk_tree_store_set (window->priv->tree_store, &node,
TREE_COLUMN_ICON, icon,
- TREE_COLUMN_NAME, file_name_from_path (dir),
+ TREE_COLUMN_NAME, _g_path_get_file_name (dir),
TREE_COLUMN_PATH, dir,
TREE_COLUMN_WEIGHT, PANGO_WEIGHT_NORMAL,
-1);
@@ -2747,7 +2747,7 @@ static void
fr_window_add_to_recent_list (FrWindow *window,
char *uri)
{
- if (is_temp_dir (uri))
+ if (_g_path_is_temp_dir (uri))
return;
if (window->archive->content_type != NULL) {
@@ -2999,7 +2999,7 @@ convert__action_performed (FrArchive *archive,
if (error->type == FR_PROC_ERROR_NONE)
open_progress_dialog_with_open_archive (window);
- remove_local_directory (window->priv->convert_data.temp_dir);
+ _g_path_remove_directory (window->priv->convert_data.temp_dir);
fr_window_convert_data_free (window, FALSE);
fr_window_update_sensitivity (window);
@@ -3085,8 +3085,8 @@ action_performed (FrArchive *archive,
break;
}
- archive_dir = remove_level_from_path (window->priv->archive_uri);
- temp_dir = is_temp_dir (archive_dir);
+ archive_dir = _g_path_remove_level (window->priv->archive_uri);
+ temp_dir = _g_path_is_temp_dir (archive_dir);
if (! window->priv->archive_present) {
window->priv->archive_present = TRUE;
@@ -3148,7 +3148,7 @@ action_performed (FrArchive *archive,
case FR_ACTION_EXTRACTING_FILES:
if (error->type != FR_PROC_ERROR_NONE) {
if (window->priv->convert_data.converting) {
- remove_local_directory (window->priv->convert_data.temp_dir);
+ _g_path_remove_directory (window->priv->convert_data.temp_dir);
fr_window_convert_data_free (window, TRUE);
}
break;
@@ -4044,15 +4044,15 @@ fr_window_drag_data_received (GtkWidget *widget,
(GFreeFunc) _g_string_list_free);
first_item = (char*) list->data;
- folder = remove_level_from_path (first_item);
+ folder = _g_path_remove_level (first_item);
if (folder != NULL)
fr_window_set_open_default_dir (window, folder);
if ((list->next != NULL) && (folder != NULL)) {
- archive_name = file_name_from_path (folder);
+ archive_name = _g_path_get_file_name (folder);
}
else {
- if (uri_is_local (first_item)) {
+ if (_g_uri_is_local (first_item)) {
local_path = g_filename_from_uri (first_item, NULL, NULL);
if (local_path)
utf8_path = g_filename_to_utf8 (local_path, -1, NULL, NULL, NULL);
@@ -4063,7 +4063,7 @@ fr_window_drag_data_received (GtkWidget *widget,
else {
utf8_path = g_strdup (first_item);
}
- archive_name = file_name_from_path (utf8_path);
+ archive_name = _g_path_get_file_name (utf8_path);
}
show_new_archive_dialog (window, archive_name);
@@ -4272,7 +4272,7 @@ fr_window_folder_tree_drag_data_get (GtkWidget *widget,
destination = get_xds_atom_value (context);
g_return_val_if_fail (destination != NULL, FALSE);
- destination_folder = remove_level_from_path (destination);
+ destination_folder = _g_path_remove_level (destination);
g_free (destination);
/* check whether the extraction can be performed in the destination
@@ -4280,7 +4280,7 @@ fr_window_folder_tree_drag_data_get (GtkWidget *widget,
g_clear_error (&window->priv->drag_error);
- if (! check_permissions (destination_folder, R_OK | W_OK)) {
+ if (! _g_uri_check_permissions (destination_folder, R_OK | W_OK)) {
char *destination_folder_display_name;
destination_folder_display_name = g_filename_display_name (destination_folder);
@@ -4352,7 +4352,7 @@ fr_window_file_list_drag_data_get (FrWindow *window,
destination = get_xds_atom_value (context);
g_return_val_if_fail (destination != NULL, FALSE);
- destination_folder = remove_level_from_path (destination);
+ destination_folder = _g_path_remove_level (destination);
g_free (destination);
/* check whether the extraction can be performed in the destination
@@ -4360,7 +4360,7 @@ fr_window_file_list_drag_data_get (FrWindow *window,
g_clear_error (&window->priv->drag_error);
- if (! check_permissions (destination_folder, R_OK | W_OK)) {
+ if (! _g_uri_check_permissions (destination_folder, R_OK | W_OK)) {
char *destination_folder_display_name;
destination_folder_display_name = g_filename_display_name (destination_folder);
@@ -5432,9 +5432,9 @@ fr_window_construct (FrWindow *window)
window->priv->action = FR_ACTION_NONE;
- window->priv->open_default_dir = g_strdup (get_home_uri ());
- window->priv->add_default_dir = g_strdup (get_home_uri ());
- window->priv->extract_default_dir = g_strdup (get_home_uri ());
+ window->priv->open_default_dir = g_strdup (_g_uri_get_home ());
+ window->priv->add_default_dir = g_strdup (_g_uri_get_home ());
+ window->priv->extract_default_dir = g_strdup (_g_uri_get_home ());
window->priv->give_focus_to_the_list = FALSE;
@@ -6181,7 +6181,7 @@ fr_window_archive_save_as (FrWindow *window,
window);
window->priv->convert_data.converting = TRUE;
- window->priv->convert_data.temp_dir = get_temp_work_dir (NULL);
+ window->priv->convert_data.temp_dir = _g_path_get_temp_work_dir (NULL);
fr_process_clear (window->archive->process);
fr_archive_extract_to_local (window->archive,
@@ -6699,7 +6699,7 @@ fr_window_archive_extract (FrWindow *window,
return;
}
- if (! uri_is_dir (edata->extract_to_dir)) {
+ if (! _g_uri_query_is_dir (edata->extract_to_dir)) {
/* There is nothing to ask if the destination doesn't exist. */
if (edata->overwrite == FR_OVERWRITE_ASK)
@@ -6734,7 +6734,7 @@ fr_window_archive_extract (FrWindow *window,
do_not_extract = TRUE;
}
- if (! do_not_extract && ! ensure_dir_exists (edata->extract_to_dir, 0755, &error)) {
+ if (! do_not_extract && ! _g_uri_ensure_dir_exists (edata->extract_to_dir, 0755, &error)) {
GtkWidget *d;
char *details;
@@ -7309,7 +7309,7 @@ rename_selection (FrWindow *window,
fr_process_clear (archive->process);
- tmp_dir = get_temp_work_dir (NULL);
+ tmp_dir = _g_path_get_temp_work_dir (NULL);
if (is_dir)
file_list = get_dir_list_from_path (window, rdata->path_to_rename);
@@ -7523,8 +7523,8 @@ fr_window_rename_selection (FrWindow *window,
path_to_rename = fr_window_get_selected_folder_in_tree_view (window);
if (path_to_rename == NULL)
return;
- parent_dir = remove_level_from_path (path_to_rename);
- old_name = g_strdup (file_name_from_path (path_to_rename));
+ parent_dir = _g_path_remove_level (path_to_rename);
+ old_name = g_strdup (_g_path_get_file_name (path_to_rename));
renaming_dir = TRUE;
}
else {
@@ -7545,12 +7545,12 @@ fr_window_rename_selection (FrWindow *window,
}
else {
if (renaming_dir) {
- path_to_rename = remove_ending_separator (selected_item->full_path);
- parent_dir = remove_level_from_path (path_to_rename);
+ path_to_rename = _g_path_remove_ending_separator (selected_item->full_path);
+ parent_dir = _g_path_remove_level (path_to_rename);
}
else {
path_to_rename = g_strdup (selected_item->original_path);
- parent_dir = remove_level_from_path (selected_item->full_path);
+ parent_dir = _g_path_remove_level (selected_item->full_path);
}
old_name = g_strdup (selected_item->name);
}
@@ -7683,7 +7683,7 @@ fr_window_get_selection (FrWindow *window,
files = fr_window_get_folder_tree_selection (window, TRUE, NULL);
selected_folder = fr_window_get_selected_folder_in_tree_view (window);
- parent_folder = remove_level_from_path (selected_folder);
+ parent_folder = _g_path_remove_level (selected_folder);
if (parent_folder == NULL)
base_dir = g_strdup ("/");
else if (parent_folder[strlen (parent_folder) - 1] == '/')
@@ -7911,19 +7911,19 @@ fr_window_paste_from_clipboard_data (FrWindow *window,
current_dir_relative = data->current_dir + 1;
- data->tmp_dir = get_temp_work_dir (NULL);
+ data->tmp_dir = _g_path_get_temp_work_dir (NULL);
created_dirs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
for (scan = data->files; scan; scan = scan->next) {
const char *old_name = (char*) scan->data;
char *new_name = g_build_filename (current_dir_relative, old_name + strlen (data->base_dir) - 1, NULL);
- char *dir = remove_level_from_path (new_name);
+ char *dir = _g_path_remove_level (new_name);
if ((dir != NULL) && (g_hash_table_lookup (created_dirs, dir) == NULL)) {
char *dir_path;
dir_path = g_build_filename (data->tmp_dir, dir, NULL);
debug (DEBUG_INFO, "mktree %s\n", dir_path);
- make_directory_tree_from_path (dir_path, 0700, NULL);
+ _g_path_make_directory_tree (dir_path, 0700, NULL);
g_free (dir_path);
g_hash_table_replace (created_dirs, g_strdup (dir), "1");
@@ -8017,7 +8017,7 @@ fr_window_paste_selection (FrWindow *window,
g_free (utf8_path);
if (destination[0] != '/')
- current_dir = build_uri (fr_window_get_current_location (window), destination, NULL);
+ current_dir = _g_uri_build (fr_window_get_current_location (window), destination, NULL);
else
current_dir = g_strdup (destination);
g_free (destination);
@@ -8109,7 +8109,7 @@ open_files_data_new (FrWindow *window,
odata->file_list = _g_string_list_dup (file_list);
odata->ask_application = ask_application;
odata->cdata = g_new0 (CommandData, 1);
- odata->cdata->temp_dir = get_temp_work_dir (NULL);
+ odata->cdata->temp_dir = _g_path_get_temp_work_dir (NULL);
odata->cdata->file_list = NULL;
for (scan = file_list; scan; scan = scan->next) {
char *file = scan->data;
@@ -8206,7 +8206,7 @@ open_file_modified_cb (GFileMonitor *monitor,
file = NULL;
for (scan = window->priv->open_files; scan; scan = scan->next) {
OpenFile *test = scan->data;
- if (uricmp (test->extracted_uri, monitor_uri) == 0) {
+ if (_g_uri_cmp (test->extracted_uri, monitor_uri) == 0) {
file = test;
break;
}
@@ -8285,7 +8285,7 @@ fr_window_open_extracted_files (OpenFilesData *odata)
return FALSE;
}
- first_mime_type = get_file_mime_type_for_path (first_file, FALSE);
+ first_mime_type = _g_path_get_mime_type (first_file, FALSE);
app = g_app_info_get_default_for_type (first_mime_type, FALSE);
if (app == NULL) {
@@ -8302,7 +8302,7 @@ fr_window_open_extracted_files (OpenFilesData *odata)
const char *path = scan->data;
const char *mime_type;
- mime_type = get_file_mime_type_for_path (path, FALSE);
+ mime_type = _g_path_get_mime_type (path, FALSE);
if (mime_type == NULL)
continue;
@@ -8400,7 +8400,7 @@ fr_window_open_files (FrWindow *window,
static char*
get_default_dir (const char *dir)
{
- if (! is_temp_dir (dir))
+ if (! _g_path_is_temp_dir (dir))
return g_strdup (dir);
else
return NULL;
@@ -8424,7 +8424,7 @@ const char *
fr_window_get_open_default_dir (FrWindow *window)
{
if (window->priv->open_default_dir == NULL)
- return get_home_uri ();
+ return _g_uri_get_home ();
else
return window->priv->open_default_dir;
}
@@ -8447,7 +8447,7 @@ const char *
fr_window_get_add_default_dir (FrWindow *window)
{
if (window->priv->add_default_dir == NULL)
- return get_home_uri ();
+ return _g_uri_get_home ();
else
return window->priv->add_default_dir;
}
@@ -8478,7 +8478,7 @@ const char *
fr_window_get_extract_default_dir (FrWindow *window)
{
if (window->priv->extract_default_dir == NULL)
- return get_home_uri ();
+ return _g_uri_get_home ();
else
return window->priv->extract_default_dir;
}
@@ -8590,7 +8590,7 @@ fr_window_exec_batch_action (FrWindow *window,
case FR_BATCH_ACTION_LOAD:
debug (DEBUG_INFO, "[BATCH] LOAD\n");
- if (! uri_exists ((char*) action->data))
+ if (! _g_uri_query_exists ((char*) action->data))
fr_window_archive_new (window, (char*) action->data);
else
fr_window_archive_open (window, (char*) action->data, GTK_WINDOW (window));
@@ -8936,7 +8936,7 @@ fr_window_set_batch__add (FrWindow *window,
const char *archive,
GList *file_list)
{
- window->priv->batch_adding_one_file = (file_list->next == NULL) && (uri_is_file (file_list->data));
+ window->priv->batch_adding_one_file = (file_list->next == NULL) && (_g_uri_query_is_file (file_list->data));
if (archive != NULL)
fr_window_append_batch_action (window,
diff --git a/src/gio-utils.c b/src/gio-utils.c
index d567e3b..d070f06 100644
--- a/src/gio-utils.c
+++ b/src/gio-utils.c
@@ -94,7 +94,7 @@ filter_matches (Filter *filter,
g_return_val_if_fail (name != NULL, FALSE);
- file_name = file_name_from_path (name);
+ file_name = _g_path_get_file_name (name);
if ((filter->options & FILTER_NODOTFILES)
&& ((file_name[0] == '.') || (strstr (file_name, "/.") != NULL)))
@@ -537,7 +537,7 @@ get_dir_list_from_file_list (GHashTable *h_dirs,
if (is_dir_list)
dir_name = g_strdup (filename + base_dir_len + 1);
else
- dir_name = remove_level_from_path (filename + base_dir_len + 1);
+ dir_name = _g_path_remove_level (filename + base_dir_len + 1);
while ((dir_name != NULL) && (dir_name[0] != '\0') && (strcmp (dir_name, "/") != 0)) {
char *tmp;
@@ -554,7 +554,7 @@ get_dir_list_from_file_list (GHashTable *h_dirs,
g_free (dir);
tmp = dir_name;
- dir_name = remove_level_from_path (tmp);
+ dir_name = _g_path_remove_level (tmp);
g_free (tmp);
}
@@ -830,7 +830,7 @@ g_list_items_async (GList *items,
char *uri = scan->data;
/* FIXME: this is not async */
- if (uri_is_dir (uri)) {
+ if (_g_uri_query_is_dir (uri)) {
gfl->to_visit = g_list_prepend (gfl->to_visit, g_strdup (uri));
}
else {
diff --git a/src/glib-utils.c b/src/glib-utils.c
index fea3aa8..b3715c6 100644
--- a/src/glib-utils.c
+++ b/src/glib-utils.c
@@ -19,6 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <glib.h>
@@ -704,7 +705,7 @@ _g_time_to_string (time_t time)
}
-/* uri */
+/* uri/path/filename */
char*
@@ -720,6 +721,492 @@ _g_uri_display_basename (const char *uri)
}
+const char *
+_g_uri_get_home (void)
+{
+ static char *home_uri = NULL;
+ if (home_uri == NULL)
+ home_uri = g_filename_to_uri (g_get_home_dir (), NULL, NULL);
+ return home_uri;
+}
+
+
+char *
+_g_uri_get_home_relative (const char *partial_uri)
+{
+ return g_strconcat (_g_uri_get_home (),
+ "/",
+ partial_uri,
+ NULL);
+}
+
+
+const char *
+_g_uri_remove_host (const char *uri)
+{
+ const char *idx, *sep;
+
+ if (uri == NULL)
+ return NULL;
+
+ idx = strstr (uri, "://");
+ if (idx == NULL)
+ return uri;
+ idx += 3;
+ if (*idx == '\0')
+ return "/";
+ sep = strstr (idx, "/");
+ if (sep == NULL)
+ return idx;
+ return sep;
+}
+
+
+char *
+_g_uri_get_host (const char *uri)
+{
+ const char *idx;
+
+ idx = strstr (uri, "://");
+ if (idx == NULL)
+ return NULL;
+ idx = strstr (idx + 3, "/");
+ if (idx == NULL)
+ return NULL;
+ return g_strndup (uri, (idx - uri));
+}
+
+
+char *
+_g_uri_get_root (const char *uri)
+{
+ char *host;
+ char *root;
+
+ host = _g_uri_get_host (uri);
+ if (host == NULL)
+ return NULL;
+ root = g_strconcat (host, "/", NULL);
+ g_free (host);
+
+ return root;
+}
+
+
+gboolean
+_g_uri_is_local (const char *uri)
+{
+ return strncmp (uri, "file://", 7) == 0;
+}
+
+
+int
+_g_uri_cmp (const char *uri1,
+ const char *uri2)
+{
+ return _g_strcmp_null_tolerant (uri1, uri2);
+}
+
+
+char *
+_g_uri_build (const char *base, ...)
+{
+ va_list args;
+ const char *child;
+ GString *uri;
+
+ uri = g_string_new (base);
+
+ va_start (args, base);
+ while ((child = va_arg (args, const char *)) != NULL) {
+ if (! g_str_has_suffix (uri->str, "/") && ! g_str_has_prefix (child, "/"))
+ g_string_append (uri, "/");
+ g_string_append (uri, child);
+ }
+ va_end (args);
+
+ return g_string_free (uri, FALSE);
+}
+
+
+/* like g_path_get_basename but does not warn about NULL and does not
+ * alloc a new string. */
+const gchar *
+_g_path_get_file_name (const gchar *file_name)
+{
+ register char *base;
+ register gssize last_char;
+
+ if (file_name == NULL)
+ return NULL;
+
+ if (file_name[0] == '\0')
+ return "";
+
+ last_char = strlen (file_name) - 1;
+
+ if (file_name [last_char] == G_DIR_SEPARATOR)
+ return "";
+
+ base = g_utf8_strrchr (file_name, -1, G_DIR_SEPARATOR);
+ if (! base)
+ return file_name;
+
+ return base + 1;
+}
+
+
+char *
+_g_path_get_dir_name (const gchar *path)
+{
+ register gssize base;
+ register gssize last_char;
+
+ if (path == NULL)
+ return NULL;
+
+ if (path[0] == '\0')
+ return g_strdup ("");
+
+ last_char = strlen (path) - 1;
+ if (path[last_char] == G_DIR_SEPARATOR)
+ last_char--;
+
+ base = last_char;
+ while ((base >= 0) && (path[base] != G_DIR_SEPARATOR))
+ base--;
+
+ return g_strndup (path + base + 1, last_char - base);
+}
+
+
+gchar *
+_g_path_remove_level (const gchar *path)
+{
+ int p;
+ const char *ptr = path;
+ char *new_path;
+
+ if (path == NULL)
+ return NULL;
+
+ p = strlen (path) - 1;
+ if (p < 0)
+ return NULL;
+
+ while ((p > 0) && (ptr[p] != '/'))
+ p--;
+ if ((p == 0) && (ptr[p] == '/'))
+ p++;
+ new_path = g_strndup (path, (guint)p);
+
+ return new_path;
+}
+
+
+char *
+_g_path_remove_ending_separator (const char *path)
+{
+ gint len, copy_len;
+
+ if (path == NULL)
+ return NULL;
+
+ copy_len = len = strlen (path);
+ if ((len > 1) && (path[len - 1] == '/'))
+ copy_len--;
+
+ return g_strndup (path, copy_len);
+}
+
+
+gchar *
+_g_path_remove_extension (const gchar *path)
+{
+ int len;
+ int p;
+ const char *ptr = path;
+ char *new_path;
+
+ if (! path)
+ return NULL;
+
+ len = strlen (path);
+ if (len == 1)
+ return g_strdup (path);
+
+ p = len - 1;
+ while ((p > 0) && (ptr[p] != '.'))
+ p--;
+ if (p == 0)
+ p = len;
+ new_path = g_strndup (path, (guint) p);
+
+ return new_path;
+}
+
+/* Check whether the dirname is contained in filename */
+gboolean
+_g_path_is_parent_of (const char *dirname,
+ const char *filename)
+{
+ int dirname_l, filename_l, separator_position;
+
+ if ((dirname == NULL) || (filename == NULL))
+ return FALSE;
+
+ dirname_l = strlen (dirname);
+ filename_l = strlen (filename);
+
+ if ((dirname_l == filename_l + 1)
+ && (dirname[dirname_l - 1] == '/'))
+ return FALSE;
+
+ if ((filename_l == dirname_l + 1)
+ && (filename[filename_l - 1] == '/'))
+ return FALSE;
+
+ if (dirname[dirname_l - 1] == '/')
+ separator_position = dirname_l - 1;
+ else
+ separator_position = dirname_l;
+
+ return ((filename_l > dirname_l)
+ && (strncmp (dirname, filename, dirname_l) == 0)
+ && (filename[separator_position] == '/'));
+}
+
+
+gboolean
+_g_filename_is_hidden (const gchar *name)
+{
+ if (name[0] != '.') return FALSE;
+ if (name[1] == '\0') return FALSE;
+ if ((name[1] == '.') && (name[2] == '\0')) return FALSE;
+
+ return TRUE;
+}
+
+
+const char *
+_g_filename_get_extension (const char *filename)
+{
+ const char *ptr = filename;
+ int len;
+ int p;
+ const char *ext;
+
+ if (filename == NULL)
+ return NULL;
+
+ len = strlen (filename);
+ if (len <= 1)
+ return NULL;
+
+ p = len - 1;
+ while ((p >= 0) && (ptr[p] != '.'))
+ p--;
+ if (p < 0)
+ return NULL;
+
+ ext = filename + p;
+ if (ext - 4 > filename) {
+ const char *test = ext - 4;
+ if (strncmp (test, ".tar", 4) == 0)
+ ext = ext - 4;
+ }
+ return ext;
+}
+
+
+gboolean
+_g_filename_has_extension (const char *filename,
+ const char *ext)
+{
+ int filename_l, ext_l;
+
+ filename_l = strlen (filename);
+ ext_l = strlen (ext);
+
+ if (filename_l < ext_l)
+ return FALSE;
+ return strcasecmp (filename + filename_l - ext_l, ext) == 0;
+}
+
+
+gboolean
+_g_mime_type_matches (const char *mime_type,
+ const char *pattern)
+{
+ return (strcasecmp (mime_type, pattern) == 0);
+}
+
+
+/* GFile */
+
+
+GFile *
+_g_file_new_home_relative (const char *partial_uri)
+{
+ GFile *file;
+ char *uri;
+
+ uri = g_strconcat (_g_uri_get_home (), "/", partial_uri, NULL);
+ file = g_file_new_for_uri (uri);
+ g_free (uri);
+
+ return file;
+}
+
+
+GList *
+_g_file_list_dup (GList *l)
+{
+ GList *r = NULL, *scan;
+ for (scan = l; scan; scan = scan->next)
+ r = g_list_prepend (r, g_file_dup ((GFile*) scan->data));
+ return g_list_reverse (r);
+}
+
+
+void
+_g_file_list_free (GList *l)
+{
+ GList *scan;
+ for (scan = l; scan; scan = scan->next)
+ g_object_unref (scan->data);
+ g_list_free (l);
+}
+
+
+GList *
+_g_file_list_new_from_uri_list (GList *uris)
+{
+ GList *r = NULL, *scan;
+ for (scan = uris; scan; scan = scan->next)
+ r = g_list_prepend (r, g_file_new_for_uri ((char*)scan->data));
+ return g_list_reverse (r);
+}
+
+
+/* line parser */
+
+
+gboolean
+_g_line_matches_pattern (const char *line,
+ const char *pattern)
+{
+ const char *l = line, *p = pattern;
+
+ for (/* void */; (*p != 0) && (*l != 0); p++, l++) {
+ if (*p != '%') {
+ if (*p != *l)
+ return FALSE;
+ }
+ else {
+ p++;
+ switch (*p) {
+ case 'a':
+ break;
+ case 'n':
+ if (!isdigit (*l))
+ return FALSE;
+ break;
+ case 'c':
+ if (!isalpha (*l))
+ return FALSE;
+ break;
+ default:
+ return FALSE;
+ }
+ }
+ }
+
+ return (*p == 0);
+}
+
+
+int
+_g_line_get_index_from_pattern (const char *line,
+ const char *pattern)
+{
+ int line_l, pattern_l;
+ const char *l;
+
+ line_l = strlen (line);
+ pattern_l = strlen (pattern);
+
+ if ((pattern_l == 0) || (line_l == 0))
+ return -1;
+
+ for (l = line; *l != 0; l++)
+ if (_g_line_matches_pattern (l, pattern))
+ return (l - line);
+
+ return -1;
+}
+
+
+char*
+_g_line_get_next_field (const char *line,
+ int start_from,
+ int field_n)
+{
+ const char *f_start, *f_end;
+
+ line = line + start_from;
+
+ f_start = line;
+ while ((*f_start == ' ') && (*f_start != *line))
+ f_start++;
+ f_end = f_start;
+
+ while ((field_n > 0) && (*f_end != 0)) {
+ if (*f_end == ' ') {
+ field_n--;
+ if (field_n != 0) {
+ while ((*f_end == ' ') && (*f_end != *line))
+ f_end++;
+ f_start = f_end;
+ }
+ }
+ else
+ f_end++;
+ }
+
+ return g_strndup (f_start, f_end - f_start);
+}
+
+
+char*
+_g_line_get_prev_field (const char *line,
+ int start_from,
+ int field_n)
+{
+ const char *f_start, *f_end;
+
+ f_start = line + start_from - 1;
+ while ((*f_start == ' ') && (*f_start != *line))
+ f_start--;
+ f_end = f_start;
+
+ while ((field_n > 0) && (*f_start != *line)) {
+ if (*f_start == ' ') {
+ field_n--;
+ if (field_n != 0) {
+ while ((*f_start == ' ') && (*f_start != *line))
+ f_start--;
+ f_end = f_start;
+ }
+ }
+ else
+ f_start--;
+ }
+
+ return g_strndup (f_start + 1, f_end - f_start);
+}
+
+
/* debug */
void
diff --git a/src/glib-utils.h b/src/glib-utils.h
index 6bab1ae..7fd180b 100644
--- a/src/glib-utils.h
+++ b/src/glib-utils.h
@@ -23,95 +23,148 @@
#define _GLIB_UTILS_H
#include <time.h>
-
-#define g_signal_handlers_disconnect_by_data(instance, data) \
- g_signal_handlers_disconnect_matched ((instance), G_SIGNAL_MATCH_DATA, \
- 0, 0, NULL, NULL, (data))
+#include <glib.h>
+#include <gio/gio.h>
#ifndef __GNUC__
#define __FUNCTION__ ""
#endif
#define DEBUG_INFO __FILE__, __LINE__, __FUNCTION__
+#define MIME_TYPE_DIRECTORY "folder"
+#define MIME_TYPE_ARCHIVE "application/x-archive"
+
+#define get_home_relative_path(x) \
+ g_strconcat (g_get_home_dir (), \
+ "/", \
+ (x), \
+ NULL)
+
+#define g_signal_handlers_disconnect_by_data(instance, data) \
+ g_signal_handlers_disconnect_matched ((instance), G_SIGNAL_MATCH_DATA, \
+ 0, 0, NULL, NULL, (data))
/* gobject */
-gpointer _g_object_ref (gpointer object);
-void _g_object_unref (gpointer object);
+gpointer _g_object_ref (gpointer object);
+void _g_object_unref (gpointer object);
/* string */
-gboolean _g_strchrs (const char *str,
- const char *chars);
-char * _g_str_substitute (const char *str,
- const char *from_str,
- const char *to_str);
-int _g_strcmp_null_tolerant (const char *s1,
- const char *s2);
-char* _g_str_escape_full (const char *str,
- const char *meta_chars,
- const char prefix,
- const char postfix);
-char* _g_str_escape (const char *str,
- const char *meta_chars);
-char * _g_str_shell_escape (const char *filename);
-char * _g_strdup_with_max_size (const char *s,
- int max_size);
-const char * _g_str_eat_spaces (const char *line);
-const char * _g_str_eat_void_chars (const char *line);
-char ** _g_str_split_line (const char *line,
- int n_fields);
-const char * _g_str_get_last_field (const char *line,
- int last_field);
-const char * _g_str_get_static (const char *s);
+gboolean _g_strchrs (const char *str,
+ const char *chars);
+char * _g_str_substitute (const char *str,
+ const char *from_str,
+ const char *to_str);
+int _g_strcmp_null_tolerant (const char *s1,
+ const char *s2);
+char* _g_str_escape_full (const char *str,
+ const char *meta_chars,
+ const char prefix,
+ const char postfix);
+char* _g_str_escape (const char *str,
+ const char *meta_chars);
+char * _g_str_shell_escape (const char *filename);
+char * _g_strdup_with_max_size (const char *s,
+ int max_size);
+const char * _g_str_eat_spaces (const char *line);
+const char * _g_str_eat_void_chars (const char *line);
+char ** _g_str_split_line (const char *line,
+ int n_fields);
+const char * _g_str_get_last_field (const char *line,
+ int last_field);
+const char * _g_str_get_static (const char *s);
/* string vector */
-char ** _g_strv_prepend (char **str_array,
- const char *str);
-gboolean _g_strv_remove (char **str_array,
- const char *str);
+char ** _g_strv_prepend (char **str_array,
+ const char *str);
+gboolean _g_strv_remove (char **str_array,
+ const char *str);
/* string list */
-void _g_string_list_free (GList *path_list);
-GList * _g_string_list_dup (GList *path_list);
+void _g_string_list_free (GList *path_list);
+GList * _g_string_list_dup (GList *path_list);
/* GPtrArray */
-GPtrArray * _g_ptr_array_copy (GPtrArray *array);
-void _g_ptr_array_free_full (GPtrArray *array,
- GFunc func,
- gpointer user_data);
-void _g_ptr_array_reverse (GPtrArray *array);
-int _g_ptr_array_binary_search (GPtrArray *array,
- gpointer value,
- GCompareFunc func);
+GPtrArray * _g_ptr_array_copy (GPtrArray *array);
+void _g_ptr_array_free_full (GPtrArray *array,
+ GFunc func,
+ gpointer user_data);
+void _g_ptr_array_reverse (GPtrArray *array);
+int _g_ptr_array_binary_search (GPtrArray *array,
+ gpointer value,
+ GCompareFunc func);
/* GRegex */
-gboolean _g_regexp_matchv (GRegex **regexps,
- const char *string,
- GRegexMatchFlags match_options);
-void _g_regexp_freev (GRegex **regexps);
-char ** _g_regexp_get_patternv (const char *pattern_string);
-GRegex ** _g_regexp_split_from_patterns (const char *pattern_string,
- GRegexCompileFlags compile_options);
+gboolean _g_regexp_matchv (GRegex **regexps,
+ const char *string,
+ GRegexMatchFlags match_options);
+void _g_regexp_freev (GRegex **regexps);
+char ** _g_regexp_get_patternv (const char *pattern_string);
+GRegex ** _g_regexp_split_from_patterns (const char *pattern_string,
+ GRegexCompileFlags compile_options);
/* time */
-char * _g_time_to_string (time_t time);
-
-/* uri */
-
-char * _g_uri_display_basename (const char *uri);
+char * _g_time_to_string (time_t time);
+
+/* uri/path/filename */
+
+char * _g_uri_display_basename (const char *uri);
+const char * _g_uri_get_home (void);
+char * _g_uri_get_home_relative (const char *partial_uri);
+const char * _g_uri_remove_host (const char *uri);
+char * _g_uri_get_host (const char *uri);
+char * _g_uri_get_root (const char *uri);
+gboolean _g_uri_is_local (const char *uri);
+int _g_uri_cmp (const char *uri1,
+ const char *uri2);
+char * _g_uri_build (const char *base,
+ ...);
+const char * _g_path_get_file_name (const char *path);
+char * _g_path_get_dir_name (const char *path);
+char * _g_path_remove_level (const char *path);
+char * _g_path_remove_ending_separator(const char *path);
+char * _g_path_remove_extension (const char *path);
+gboolean _g_path_is_parent_of (const char *dirname,
+ const char *filename);
+gboolean _g_filename_is_hidden (const char *name);
+const char * _g_filename_get_extension (const char *filename);
+gboolean _g_filename_has_extension (const char *filename,
+ const char *ext);
+gboolean _g_mime_type_matches (const char *type,
+ const char *pattern);
+
+/* GFile */
+
+GFile * _g_file_new_home_relative (const char *partial_uri);
+GList * _g_file_list_dup (GList *l);
+void _g_file_list_free (GList *l);
+GList * _g_file_list_new_from_uri_list (GList *uris);
+
+/* functions used to parse a command output lines. */
+
+gboolean _g_line_matches_pattern (const char *line,
+ const char *pattern);
+int _g_line_get_index_from_pattern (const char *line,
+ const char *pattern);
+char* _g_line_get_next_field (const char *line,
+ int start_from,
+ int field_n);
+char* _g_line_get_prev_field (const char *line,
+ int start_from,
+ int field_n);
/* debug */
-void debug (const char *file,
- int line,
- const char *function,
- const char *format,
- ...);
+void debug (const char *file,
+ int line,
+ const char *function,
+ const char *format,
+ ...);
#endif /* _GLIB_UTILS_H */
diff --git a/src/main.c b/src/main.c
index a0a8402..3262603 100644
--- a/src/main.c
+++ b/src/main.c
@@ -38,6 +38,7 @@
#include "eggdesktopfile.h"
#include "file-utils.h"
#include "fr-init.h"
+#include "glib-utils.h"
#include "gtk-utils.h"
@@ -402,7 +403,7 @@ handle_method_call (GDBusConnection *connection,
file_list = g_list_reverse (file_list);
if ((destination == NULL) || (strcmp (destination, "") == 0))
- destination = remove_level_from_path (file_list->data);
+ destination = _g_path_remove_level (file_list->data);
window = fr_window_new ();
fr_window_use_progress_dialog (FR_WINDOW (window), use_progress_dialog);
diff --git a/src/open-file.c b/src/open-file.c
index 0061fdc..14eb5b6 100644
--- a/src/open-file.c
+++ b/src/open-file.c
@@ -34,12 +34,12 @@ open_file_new (const char *path,
ofile = g_new0 (OpenFile, 1);
ofile->path = g_strdup (path);
ofile->extracted_uri = g_filename_to_uri (extracted_path, NULL, NULL);
- if (! uri_exists (ofile->extracted_uri)) {
+ if (! _g_uri_query_exists (ofile->extracted_uri)) {
open_file_free (ofile);
return NULL;
}
ofile->temp_dir = g_strdup (temp_dir);
- ofile->last_modified = get_file_mtime (ofile->extracted_uri);
+ ofile->last_modified = _g_uri_get_file_mtime (ofile->extracted_uri);
return ofile;
}
diff --git a/src/rar-utils.c b/src/rar-utils.c
index e3081a3..e6ccc3e 100644
--- a/src/rar-utils.c
+++ b/src/rar-utils.c
@@ -25,6 +25,7 @@
#include "file-utils.h"
#include "fr-command.h"
#include "gio-utils.h"
+#include "glib-utils.h"
typedef enum {
@@ -109,7 +110,7 @@ rar_check_multi_volume (FrCommand *comm)
char *volume_name = NULL;
char *name;
- name = g_filename_to_utf8 (file_name_from_path (comm->filename), -1, NULL, NULL, NULL);
+ name = g_filename_to_utf8 (_g_path_get_file_name (comm->filename), -1, NULL, NULL, NULL);
volume_name = get_first_volume_name (name, "^(.*\\.part)([0-9]+)(\\.rar)$", FIRST_VOLUME_IS_001);
if (volume_name == NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]