From 28066be1fb73d647508a192b6da858832522ad88 Mon Sep 17 00:00:00 2001 From: Ting-Wei Lan Date: Sun, 11 May 2014 03:07:06 +0800 Subject: Make all internal functions private All internal functions in autoar-common is moved to autoar-private, and their documentation are not generated now. Public functions and data types in autoar-common are moved to autoar-misc. --- Makefile.am | 9 +- docs/reference/Makefile.am | 6 + docs/reference/gnome-autoar-docs.xml | 2 +- gnome-autoar/autoar-common.c | 288 ----------------------------------- gnome-autoar/autoar-common.h | 71 --------- gnome-autoar/autoar-create.c | 5 +- gnome-autoar/autoar-extract.c | 4 +- gnome-autoar/autoar-misc.c | 48 ++++++ gnome-autoar/autoar-misc.h | 47 ++++++ gnome-autoar/autoar-private.c | 281 ++++++++++++++++++++++++++++++++++ gnome-autoar/autoar-private.h | 61 ++++++++ gnome-autoar/autoar.h | 2 +- 12 files changed, 457 insertions(+), 367 deletions(-) delete mode 100644 gnome-autoar/autoar-common.c delete mode 100644 gnome-autoar/autoar-common.h create mode 100644 gnome-autoar/autoar-misc.c create mode 100644 gnome-autoar/autoar-misc.h create mode 100644 gnome-autoar/autoar-private.c create mode 100644 gnome-autoar/autoar-private.h diff --git a/Makefile.am b/Makefile.am index 73d105a..2970c80 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,19 +22,23 @@ EXTRA_DIST += \ $(NULL) libgnome_autoar_la_headers = \ - gnome-autoar/autoar-common.h \ gnome-autoar/autoar-create.h \ gnome-autoar/autoar-extract.h \ gnome-autoar/autoar-format-filter.h \ + gnome-autoar/autoar-misc.h \ gnome-autoar/autoar-pref.h \ $(NULL) libgnome_autoar_la_sources = \ - gnome-autoar/autoar-common.c \ gnome-autoar/autoar-create.c \ gnome-autoar/autoar-extract.c \ gnome-autoar/autoar-format-filter.c \ + gnome-autoar/autoar-misc.c \ gnome-autoar/autoar-pref.c \ $(NULL) +libgnome_autoar_la_private_files = \ + gnome-autoar/autoar-private.h \ + gnome-autoar/autoar-private.c \ + $(NULL) libgnome_autoar_la_generated_files = \ gnome-autoar/autoar-enum-types.h \ gnome-autoar/autoar-enum-types.c \ @@ -63,6 +67,7 @@ autoarinclude_HEADERS = \ gnome_autoar_libgnome_autoar_la_SOURCES = \ $(libgnome_autoar_la_generated_files) \ + $(libgnome_autoar_la_private_files) \ $(libgnome_autoar_la_headers) \ $(libgnome_autoar_la_sources) \ $(NULL) diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am index f2e4903..8667e5d 100644 --- a/docs/reference/Makefile.am +++ b/docs/reference/Makefile.am @@ -17,6 +17,12 @@ IGNORE_HFILES = \ autoar.h \ autoar-gtk.h \ autoar-enum-types.h \ + autoar-private.h \ + $(NULL) + +IGNORE_CFILES = \ + autoar-enum-types.c \ + autoar-private.c \ $(NULL) GTKDOC_CFLAGS = \ diff --git a/docs/reference/gnome-autoar-docs.xml b/docs/reference/gnome-autoar-docs.xml index ead4aa4..ec38f72 100644 --- a/docs/reference/gnome-autoar-docs.xml +++ b/docs/reference/gnome-autoar-docs.xml @@ -23,7 +23,7 @@ gnome-autoar Utilities - + gnome-autoar GTK+ Widgets diff --git a/gnome-autoar/autoar-common.c b/gnome-autoar/autoar-common.c deleted file mode 100644 index fc4f2fb..0000000 --- a/gnome-autoar/autoar-common.c +++ /dev/null @@ -1,288 +0,0 @@ -/* vim: set sw=2 ts=2 sts=2 et: */ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * autoar-common.c - * Some common functions used in several classes of autoarchive - * This file does NOT declare any new classes! - * - * Copyright (C) 2013 Ting-Wei Lan - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#include "config.h" - -#include "autoar-common.h" - -#include -#include -#include - -/** - * SECTION:autoar-common - * @Short_description: Miscellaneous functions used by gnome-autoar - * @Title: autoar-common - * @Include: gnome-autoar/autoar.h - * - * Public utility functions used internally by other gnome-autoar functions. - **/ - -typedef struct _AutoarCommonSignalData AutoarCommonSignalData; - -struct _AutoarCommonSignalData -{ - GValue instance_and_params[3]; /* Maximum number of parameters + 1 */ - gssize used_values; /* Number of GValues to be unset */ - guint signal_id; - GQuark detail; -}; - -/** - * autoar_common_libarchive_quark: - * - * Gets the libarchive Error Quark. - * - * Returns: a #GQuark. - **/ -G_DEFINE_QUARK (libarchive-quark, autoar_common_libarchive) - -/** - * autoar_common_get_filename_extension: - * @filename: a filename - * - * Gets the extension of a filename. - * - * Returns: (transfer none): a pointer to the extension of the filename - **/ -char* -autoar_common_get_filename_extension (const char *filename) -{ - char *dot_location; - - dot_location = strrchr (filename, '.'); - if (dot_location == NULL || dot_location == filename) { - return (char*)filename; - } - - if (dot_location - 4 > filename && strncmp (dot_location - 4, ".tar", 4) == 0) - dot_location -= 4; - else if (dot_location - 5 > filename && strncmp (dot_location - 5, ".cpio", 5) == 0) - dot_location -= 5; - - return dot_location; -} - -/** - * autoar_common_get_basename_remove_extension: - * @filename: a filename - * - * Gets the basename of a path without its file name extension. - * - * Returns: (transfer full): a new filename without extension. Free the - * returned string with g_free(). - **/ -char* -autoar_common_get_basename_remove_extension (const char *filename) -{ - char *dot_location; - char *basename; - - if (filename == NULL) { - return NULL; - } - - /* filename must not be directory, so we do not get a bad basename. */ - basename = g_path_get_basename (filename); - - dot_location = autoar_common_get_filename_extension (basename); - if (dot_location != basename) - *dot_location = '\0'; - - g_debug ("autoar_common_get_basename_remove_extension: %s => %s", - filename, - basename); - return basename; -} - -static void -autoar_common_signal_data_free (AutoarCommonSignalData *signal_data) -{ - int i; - - for (i = 0; i < signal_data->used_values; i++) - g_value_unset (signal_data->instance_and_params + i); - - g_free (signal_data); -} - -static gboolean -autoar_common_g_signal_emit_main_context (void *data) -{ - AutoarCommonSignalData *signal_data = data; - g_signal_emitv (signal_data->instance_and_params, - signal_data->signal_id, - signal_data->detail, - NULL); - autoar_common_signal_data_free (signal_data); - return FALSE; -} - -/** - * autoar_common_g_signal_emit: - * @instance: the instance the signal is being emitted on. - * @in_thread: %TRUE if you are not call this function inside the main thread. - * @signal_id: the signal id - * @detail: the detail - * @...: parameters to be passed to the signal. - * - * This is a wrapper for g_signal_emit(). If @in_thread is %FALSE, this - * function is the same as g_signal_emit(). If @in_thread is %TRUE, the - * signal will be emitted from the main thread. This function will send - * the signal emission job via g_main_context_invoke(), but it does not - * wait for the signal emission job to be completed. Hence, the signal - * may emitted after autoar_common_g_signal_emit() is returned. - **/ -void -autoar_common_g_signal_emit (gpointer instance, - gboolean in_thread, - guint signal_id, - GQuark detail, - ...) -{ - va_list ap; - - va_start (ap, detail); - if (in_thread) { - int i; - gchar *error; - GSignalQuery query; - AutoarCommonSignalData *data; - - error = NULL; - data = g_new0 (AutoarCommonSignalData, 1); - data->signal_id = signal_id; - data->detail = detail; - data->used_values = 1; - g_value_init (data->instance_and_params, G_TYPE_FROM_INSTANCE (instance)); - g_value_set_instance (data->instance_and_params, instance); - - g_signal_query (signal_id, &query); - if (query.signal_id == 0) { - autoar_common_signal_data_free (data); - va_end (ap); - return; - } - - for (i = 0; i < query.n_params; i++) { - G_VALUE_COLLECT_INIT (data->instance_and_params + i + 1, - query.param_types[i], - ap, - 0, - &error); - if (error != NULL) - break; - data->used_values++; - } - - if (error == NULL) { - g_main_context_invoke (NULL, autoar_common_g_signal_emit_main_context, data); - } else { - autoar_common_signal_data_free (data); - g_debug ("G_VALUE_COLLECT_INIT: Error: %s", error); - g_free (error); - va_end (ap); - return; - } - } else { - g_signal_emit_valist (instance, signal_id, detail, ap); - } - va_end (ap); -} - -/** - * autoar_common_g_object_unref: - * @object: a #GObject - * - * This is a wrapper for g_object_unref(). If @object is %NULL, this function - * does nothing. Otherwise, it will call g_object_unref() on the @object. - **/ -void -autoar_common_g_object_unref (gpointer object) -{ - if (object != NULL) - g_object_unref (object); -} - -/** - * autoar_common_g_error_new_a: - * @a: a archive object - * @pathname: the file which causes error, or %NULL - * - * Creates a new #GError with error messages got from libarchive. - * - * Returns: (transfer full): a #GError. Free with g_error_free(). - **/ -GError* -autoar_common_g_error_new_a (struct archive *a, - const char *pathname) -{ - GError *newerror; - newerror = g_error_new (AUTOAR_LIBARCHIVE_ERROR, - archive_errno (a), - "%s%s%s%s", - pathname != NULL ? "\'" : "", - pathname != NULL ? pathname : "", - pathname != NULL ? "\': " : "", - archive_error_string (a)); - return newerror; -} - -/** - * autoar_common_g_error_new_a_entry: - * @a: a archive object - * @entry: a archive_entry object - * - * Gets pathname from @entry and call autoar_common_g_error_new_a(). - * - * Returns: (transfer full): a #GError. Free with g_error_free(). - **/ -GError* -autoar_common_g_error_new_a_entry (struct archive *a, - struct archive_entry *entry) -{ - return autoar_common_g_error_new_a (a, archive_entry_pathname (entry)); -} - -/** - * autoar_common_g_file_get_name: - * @file: a #GFile - * - * Gets a string represents the @file. It will be the path of @file if - * available. Otherwise, it will be the URI of @file. - * - * Returns: (transfer full): a string represents the file. Free the string - * with g_free(). - **/ -char* -autoar_common_g_file_get_name (GFile *file) -{ - char *name; - name = g_file_get_path (file); - if (name == NULL) - name = g_file_get_uri (file); - return name; -} diff --git a/gnome-autoar/autoar-common.h b/gnome-autoar/autoar-common.h deleted file mode 100644 index 2070c55..0000000 --- a/gnome-autoar/autoar-common.h +++ /dev/null @@ -1,71 +0,0 @@ -/* vim: set sw=2 ts=2 sts=2 et: */ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * autoar-common.h - * Some common functions used in several classes of autoarchive - * This file does NOT declare any new classes! - * - * Copyright (C) 2013 Ting-Wei Lan - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef AUTOAR_COMMON_H -#define AUTOAR_COMMON_H - -/* archive.h use time_t */ -#include - -#include -#include -#include -#include -#include - -G_BEGIN_DECLS - -/** - * AUTOAR_LIBARCHIVE_ERROR: - * - * Error domain for libarchive. Error returned by functions in libarchive uses - * this domain. Error code and messages are got using archive_errno() and - * archive_error_string(). - **/ -#define AUTOAR_LIBARCHIVE_ERROR autoar_common_libarchive_quark() - -GQuark autoar_common_libarchive_quark (void); - -char* autoar_common_get_basename_remove_extension (const char *filename); -char* autoar_common_get_filename_extension (const char *filename); - -void autoar_common_g_signal_emit (gpointer instance, - gboolean in_thread, - guint signal_id, - GQuark detail, - ...); -void autoar_common_g_object_unref (gpointer object); - -GError* autoar_common_g_error_new_a (struct archive *a, - const char *pathname); -GError* autoar_common_g_error_new_a_entry (struct archive *a, - struct archive_entry *entry); - -char* autoar_common_g_file_get_name (GFile *file); - -G_END_DECLS - -#endif /* AUTOAR_COMMON_H */ diff --git a/gnome-autoar/autoar-create.c b/gnome-autoar/autoar-create.c index 68ca0cf..b76678b 100644 --- a/gnome-autoar/autoar-create.c +++ b/gnome-autoar/autoar-create.c @@ -24,9 +24,10 @@ */ #include "config.h" - #include "autoar-create.h" -#include "autoar-common.h" + +#include "autoar-misc.h" +#include "autoar-private.h" #include "autoar-pref.h" #include diff --git a/gnome-autoar/autoar-extract.c b/gnome-autoar/autoar-extract.c index 384f506..bfdfd9d 100644 --- a/gnome-autoar/autoar-extract.c +++ b/gnome-autoar/autoar-extract.c @@ -24,10 +24,10 @@ */ #include "config.h" - #include "autoar-extract.h" -#include "autoar-common.h" +#include "autoar-misc.h" +#include "autoar-private.h" #include "autoar-pref.h" #include diff --git a/gnome-autoar/autoar-misc.c b/gnome-autoar/autoar-misc.c new file mode 100644 index 0000000..0467fa9 --- /dev/null +++ b/gnome-autoar/autoar-misc.c @@ -0,0 +1,48 @@ +/* vim: set sw=2 ts=2 sts=2 et: */ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * autoar-misc.c + * Miscellaneous functions and shared data types used by gnome-autoar + * + * Copyright (C) 2014 Ting-Wei Lan + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" +#include "autoar-misc.h" + +#include + +/** + * SECTION:autoar-misc + * @Short_description: Miscellaneous functions and shared data types used + * by gnome-autoar + * @Title: autoar-misc + * @Include: gnome-autoar/autoar.h + * + * Public utility functions and data types used by gnome-autoar; + **/ + +/** + * autoar_libarchive_quark: + * + * Gets the libarchive Error Quark. + * + * Returns: a #GQuark. + **/ +G_DEFINE_QUARK (libarchive-quark, autoar_libarchive) diff --git a/gnome-autoar/autoar-misc.h b/gnome-autoar/autoar-misc.h new file mode 100644 index 0000000..6038452 --- /dev/null +++ b/gnome-autoar/autoar-misc.h @@ -0,0 +1,47 @@ +/* vim: set sw=2 ts=2 sts=2 et: */ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * autoar-misc.h + * Miscellaneous functions and shared data types used by gnome-autoar + * + * Copyright (C) 2014 Ting-Wei Lan + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef AUTOAR_MISC_H +#define AUTOAR_MISC_H + +#include + +G_BEGIN_DECLS + +/** + * AUTOAR_LIBARCHIVE_ERROR: + * + * Error domain for libarchive. Error returned by functions in libarchive uses + * this domain. Error code and messages are got using archive_errno() and + * archive_error_string() functions provided by libarchive. + **/ + +#define AUTOAR_LIBARCHIVE_ERROR autoar_libarchive_quark() + +GQuark autoar_libarchive_quark (void); + +G_END_DECLS + +#endif /* AUTOAR_COMMON_H */ diff --git a/gnome-autoar/autoar-private.c b/gnome-autoar/autoar-private.c new file mode 100644 index 0000000..d80e5e7 --- /dev/null +++ b/gnome-autoar/autoar-private.c @@ -0,0 +1,281 @@ +/* vim: set sw=2 ts=2 sts=2 et: */ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * autoar-private.c + * Some common functions used in several classes of gnome-autoar + * This file does NOT declare any new classes and it should NOT + * be used outside the library itself! + * + * Copyright (C) 2013, 2014 Ting-Wei Lan + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" +#include "autoar-private.h" + +#include "autoar-misc.h" + +#include +#include +#include + +/** + * SECTION:autoar-common + * @Short_description: Miscellaneous functions used by gnome-autoar + * @Title: autoar-common + * @Include: gnome-autoar/autoar.h + * + * Public utility functions used internally by other gnome-autoar functions. + **/ + +typedef struct _AutoarCommonSignalData AutoarCommonSignalData; + +struct _AutoarCommonSignalData +{ + GValue instance_and_params[3]; /* Maximum number of parameters + 1 */ + gssize used_values; /* Number of GValues to be unset */ + guint signal_id; + GQuark detail; +}; + +/** + * autoar_common_get_filename_extension: + * @filename: a filename + * + * Gets the extension of a filename. + * + * Returns: (transfer none): a pointer to the extension of the filename + **/ +G_GNUC_INTERNAL char* +autoar_common_get_filename_extension (const char *filename) +{ + char *dot_location; + + dot_location = strrchr (filename, '.'); + if (dot_location == NULL || dot_location == filename) { + return (char*)filename; + } + + if (dot_location - 4 > filename && strncmp (dot_location - 4, ".tar", 4) == 0) + dot_location -= 4; + else if (dot_location - 5 > filename && strncmp (dot_location - 5, ".cpio", 5) == 0) + dot_location -= 5; + + return dot_location; +} + +/** + * autoar_common_get_basename_remove_extension: + * @filename: a filename + * + * Gets the basename of a path without its file name extension. + * + * Returns: (transfer full): a new filename without extension. Free the + * returned string with g_free(). + **/ +G_GNUC_INTERNAL char* +autoar_common_get_basename_remove_extension (const char *filename) +{ + char *dot_location; + char *basename; + + if (filename == NULL) { + return NULL; + } + + /* filename must not be directory, so we do not get a bad basename. */ + basename = g_path_get_basename (filename); + + dot_location = autoar_common_get_filename_extension (basename); + if (dot_location != basename) + *dot_location = '\0'; + + g_debug ("autoar_common_get_basename_remove_extension: %s => %s", + filename, + basename); + return basename; +} + +static void +autoar_common_signal_data_free (AutoarCommonSignalData *signal_data) +{ + int i; + + for (i = 0; i < signal_data->used_values; i++) + g_value_unset (signal_data->instance_and_params + i); + + g_free (signal_data); +} + +static gboolean +autoar_common_g_signal_emit_main_context (void *data) +{ + AutoarCommonSignalData *signal_data = data; + g_signal_emitv (signal_data->instance_and_params, + signal_data->signal_id, + signal_data->detail, + NULL); + autoar_common_signal_data_free (signal_data); + return FALSE; +} + +/** + * autoar_common_g_signal_emit: + * @instance: the instance the signal is being emitted on. + * @in_thread: %TRUE if you are not call this function inside the main thread. + * @signal_id: the signal id + * @detail: the detail + * @...: parameters to be passed to the signal. + * + * This is a wrapper for g_signal_emit(). If @in_thread is %FALSE, this + * function is the same as g_signal_emit(). If @in_thread is %TRUE, the + * signal will be emitted from the main thread. This function will send + * the signal emission job via g_main_context_invoke(), but it does not + * wait for the signal emission job to be completed. Hence, the signal + * may emitted after autoar_common_g_signal_emit() is returned. + **/ +G_GNUC_INTERNAL void +autoar_common_g_signal_emit (gpointer instance, + gboolean in_thread, + guint signal_id, + GQuark detail, + ...) +{ + va_list ap; + + va_start (ap, detail); + if (in_thread) { + int i; + gchar *error; + GSignalQuery query; + AutoarCommonSignalData *data; + + error = NULL; + data = g_new0 (AutoarCommonSignalData, 1); + data->signal_id = signal_id; + data->detail = detail; + data->used_values = 1; + g_value_init (data->instance_and_params, G_TYPE_FROM_INSTANCE (instance)); + g_value_set_instance (data->instance_and_params, instance); + + g_signal_query (signal_id, &query); + if (query.signal_id == 0) { + autoar_common_signal_data_free (data); + va_end (ap); + return; + } + + for (i = 0; i < query.n_params; i++) { + G_VALUE_COLLECT_INIT (data->instance_and_params + i + 1, + query.param_types[i], + ap, + 0, + &error); + if (error != NULL) + break; + data->used_values++; + } + + if (error == NULL) { + g_main_context_invoke (NULL, autoar_common_g_signal_emit_main_context, data); + } else { + autoar_common_signal_data_free (data); + g_debug ("G_VALUE_COLLECT_INIT: Error: %s", error); + g_free (error); + va_end (ap); + return; + } + } else { + g_signal_emit_valist (instance, signal_id, detail, ap); + } + va_end (ap); +} + +/** + * autoar_common_g_object_unref: + * @object: a #GObject + * + * This is a wrapper for g_object_unref(). If @object is %NULL, this function + * does nothing. Otherwise, it will call g_object_unref() on the @object. + **/ +G_GNUC_INTERNAL void +autoar_common_g_object_unref (gpointer object) +{ + if (object != NULL) + g_object_unref (object); +} + +/** + * autoar_common_g_error_new_a: + * @a: a archive object + * @pathname: the file which causes error, or %NULL + * + * Creates a new #GError with error messages got from libarchive. + * + * Returns: (transfer full): a #GError. Free with g_error_free(). + **/ +G_GNUC_INTERNAL GError* +autoar_common_g_error_new_a (struct archive *a, + const char *pathname) +{ + GError *newerror; + newerror = g_error_new (AUTOAR_LIBARCHIVE_ERROR, + archive_errno (a), + "%s%s%s%s", + pathname != NULL ? "\'" : "", + pathname != NULL ? pathname : "", + pathname != NULL ? "\': " : "", + archive_error_string (a)); + return newerror; +} + +/** + * autoar_common_g_error_new_a_entry: + * @a: a archive object + * @entry: a archive_entry object + * + * Gets pathname from @entry and call autoar_common_g_error_new_a(). + * + * Returns: (transfer full): a #GError. Free with g_error_free(). + **/ +G_GNUC_INTERNAL GError* +autoar_common_g_error_new_a_entry (struct archive *a, + struct archive_entry *entry) +{ + return autoar_common_g_error_new_a (a, archive_entry_pathname (entry)); +} + +/** + * autoar_common_g_file_get_name: + * @file: a #GFile + * + * Gets a string represents the @file. It will be the path of @file if + * available. Otherwise, it will be the URI of @file. + * + * Returns: (transfer full): a string represents the file. Free the string + * with g_free(). + **/ +G_GNUC_INTERNAL char* +autoar_common_g_file_get_name (GFile *file) +{ + char *name; + name = g_file_get_path (file); + if (name == NULL) + name = g_file_get_uri (file); + return name; +} diff --git a/gnome-autoar/autoar-private.h b/gnome-autoar/autoar-private.h new file mode 100644 index 0000000..0b5e49a --- /dev/null +++ b/gnome-autoar/autoar-private.h @@ -0,0 +1,61 @@ +/* vim: set sw=2 ts=2 sts=2 et: */ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * autoar-private.h + * Some common functions used in several classes of gnome-autoar + * This file does NOT declare any new classes and it should NOT + * be used outside the library itself! + * + * Copyright (C) 2013, 2014 Ting-Wei Lan + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef AUTOAR_PRIVATE_H +#define AUTOAR_PRIVATE_H + +/* archive.h use time_t */ +#include + +#include +#include +#include +#include +#include + +G_BEGIN_DECLS + +char* autoar_common_get_basename_remove_extension (const char *filename); +char* autoar_common_get_filename_extension (const char *filename); + +void autoar_common_g_signal_emit (gpointer instance, + gboolean in_thread, + guint signal_id, + GQuark detail, + ...); +void autoar_common_g_object_unref (gpointer object); + +GError* autoar_common_g_error_new_a (struct archive *a, + const char *pathname); +GError* autoar_common_g_error_new_a_entry (struct archive *a, + struct archive_entry *entry); + +char* autoar_common_g_file_get_name (GFile *file); + +G_END_DECLS + +#endif /* AUTOAR_COMMON_H */ diff --git a/gnome-autoar/autoar.h b/gnome-autoar/autoar.h index 2556546..ce558f9 100644 --- a/gnome-autoar/autoar.h +++ b/gnome-autoar/autoar.h @@ -23,10 +23,10 @@ #ifndef AUTOARCHIVE_H #define AUTOARHICVE_H -#include #include #include #include +#include #include #endif /* AUTOARCHIVE_H */ -- cgit v1.2.3