summaryrefslogtreecommitdiff
path: root/gsearchtool/gsearchtool-support.c
diff options
context:
space:
mode:
Diffstat (limited to 'gsearchtool/gsearchtool-support.c')
-rw-r--r--gsearchtool/gsearchtool-support.c480
1 files changed, 121 insertions, 359 deletions
diff --git a/gsearchtool/gsearchtool-support.c b/gsearchtool/gsearchtool-support.c
index 95a8599f..6d368a2d 100644
--- a/gsearchtool/gsearchtool-support.c
+++ b/gsearchtool/gsearchtool-support.c
@@ -46,259 +46,11 @@
#define C_STANDARD_NUMERIC_STRFTIME_CHARACTERS "dHIjmMSUwWyY"
#define SUS_EXTENDED_STRFTIME_MODIFIERS "EO"
#define BINARY_EXEC_MIME_TYPE "application/x-executable"
-#define GSEARCH_DATE_FORMAT_LOCALE "locale"
-#define GSEARCH_DATE_FORMAT_ISO "iso"
GtkTreeViewColumn *
gsearchtool_gtk_tree_view_get_column_with_sort_column_id (GtkTreeView * treeview,
gint id);
-/* START OF THE MATECONF FUNCTIONS */
-
-static gboolean
-gsearchtool_mateconf_handle_error (GError ** error)
-{
- if (error != NULL) {
- if (*error != NULL) {
- g_warning (_("MateConf error:\n %s"), (*error)->message);
- g_error_free (*error);
- *error = NULL;
- return TRUE;
- }
- }
- return FALSE;
-}
-
-static MateConfClient *
-gsearchtool_mateconf_client_get_global (void)
-{
- static MateConfClient * global_mateconf_client = NULL;
-
- /* Initialize mateconf if needed */
- if (!mateconf_is_initialized ()) {
- char *argv[] = { "gsearchtool-preferences", NULL };
- GError *error = NULL;
-
- if (!mateconf_init (1, argv, &error)) {
- if (gsearchtool_mateconf_handle_error (&error)) {
- return NULL;
- }
- }
- }
-
- if (global_mateconf_client == NULL) {
- global_mateconf_client = mateconf_client_get_default ();
- }
-
- return global_mateconf_client;
-}
-
-char *
-gsearchtool_mateconf_get_string (const gchar * key)
-{
- MateConfClient * client;
- GError * error = NULL;
- gchar * result;
-
- g_return_val_if_fail (key != NULL, NULL);
-
- client = gsearchtool_mateconf_client_get_global ();
- g_return_val_if_fail (client != NULL, NULL);
-
- result = mateconf_client_get_string (client, key, &error);
-
- if (gsearchtool_mateconf_handle_error (&error)) {
- result = g_strdup ("");
- }
-
- return result;
-}
-
-void
-gsearchtool_mateconf_set_string (const gchar * key,
- const gchar * value)
-{
- MateConfClient * client;
- GError * error = NULL;
-
- g_return_if_fail (key != NULL);
-
- client = gsearchtool_mateconf_client_get_global ();
- g_return_if_fail (client != NULL);
-
- mateconf_client_set_string (client, key, value, &error);
-
- gsearchtool_mateconf_handle_error (&error);
-
-}
-
-GSList *
-gsearchtool_mateconf_get_list (const gchar * key,
- MateConfValueType list_type)
-{
- MateConfClient * client;
- GError * error = NULL;
- GSList * result;
-
- g_return_val_if_fail (key != NULL, FALSE);
-
- client = gsearchtool_mateconf_client_get_global ();
- g_return_val_if_fail (client != NULL, NULL);
-
- result = mateconf_client_get_list (client, key, list_type, &error);
-
- if (gsearchtool_mateconf_handle_error (&error)) {
- result = NULL;
- }
-
- return result;
-}
-
-void
-gsearchtool_mateconf_set_list (const gchar * key,
- GSList * list,
- MateConfValueType list_type)
-{
- MateConfClient * client;
- GError * error = NULL;
-
- g_return_if_fail (key != NULL);
-
- client = gsearchtool_mateconf_client_get_global ();
- g_return_if_fail (client != NULL);
-
- mateconf_client_set_list (client, key, list_type, list, &error);
-
- gsearchtool_mateconf_handle_error (&error);
-}
-
-gint
-gsearchtool_mateconf_get_int (const gchar * key)
-{
- MateConfClient * client;
- GError * error = NULL;
- gint result;
-
- g_return_val_if_fail (key != NULL, FALSE);
-
- client = gsearchtool_mateconf_client_get_global ();
- g_return_val_if_fail (client != NULL, FALSE);
-
- result = mateconf_client_get_int (client, key, &error);
-
- if (gsearchtool_mateconf_handle_error (&error)) {
- result = 0;
- }
-
- return result;
-}
-
-void
-gsearchtool_mateconf_set_int (const gchar * key,
- const gint value)
-{
- MateConfClient * client;
- GError * error = NULL;
-
- g_return_if_fail (key != NULL);
-
- client = gsearchtool_mateconf_client_get_global ();
- g_return_if_fail (client != NULL);
-
- mateconf_client_set_int (client, key, value, &error);
-
- gsearchtool_mateconf_handle_error (&error);
-}
-
-gboolean
-gsearchtool_mateconf_get_boolean (const gchar * key)
-{
- MateConfClient * client;
- GError * error = NULL;
- gboolean result;
-
- g_return_val_if_fail (key != NULL, FALSE);
-
- client = gsearchtool_mateconf_client_get_global ();
- g_return_val_if_fail (client != NULL, FALSE);
-
- result = mateconf_client_get_bool (client, key, &error);
-
- if (gsearchtool_mateconf_handle_error (&error)) {
- result = FALSE;
- }
-
- return result;
-}
-
-void
-gsearchtool_mateconf_set_boolean (const gchar * key,
- const gboolean flag)
-{
- MateConfClient * client;
- GError * error = NULL;
-
- g_return_if_fail (key != NULL);
-
- client = gsearchtool_mateconf_client_get_global ();
- g_return_if_fail (client != NULL);
-
- mateconf_client_set_bool (client, key, flag, &error);
-
- gsearchtool_mateconf_handle_error (&error);
-}
-
-void
-gsearchtool_mateconf_add_dir (const gchar * dir)
-{
- MateConfClient * client;
- GError * error = NULL;
-
- g_return_if_fail (dir != NULL);
-
- client = gsearchtool_mateconf_client_get_global ();
- g_return_if_fail (client != NULL);
-
- mateconf_client_add_dir (client,
- dir,
- MATECONF_CLIENT_PRELOAD_RECURSIVE,
- &error);
-
- gsearchtool_mateconf_handle_error (&error);
-}
-
-void
-gsearchtool_mateconf_watch_key (const gchar * dir,
- const gchar * key,
- MateConfClientNotifyFunc callback,
- gpointer user_data)
-{
- MateConfClient * client;
- GError * error = NULL;
-
- g_return_if_fail (key != NULL);
- g_return_if_fail (dir != NULL);
-
- client = gsearchtool_mateconf_client_get_global ();
- g_return_if_fail (client != NULL);
-
- mateconf_client_add_dir (client,
- dir,
- MATECONF_CLIENT_PRELOAD_NONE,
- &error);
-
- gsearchtool_mateconf_handle_error (&error);
-
- mateconf_client_notify_add (client,
- key,
- callback,
- user_data,
- NULL,
- &error);
-
- gsearchtool_mateconf_handle_error (&error);
-}
-
/* START OF GENERIC MATE-SEARCH-TOOL FUNCTIONS */
gboolean
@@ -334,10 +86,13 @@ is_path_hidden (const gchar * path)
gboolean
is_quick_search_excluded_path (const gchar * path)
{
- GSList * exclude_path_list;
- GSList * tmp_list;
+ GSettings * settings;
+ gchar ** exclude_path_list;
gchar * dir;
gboolean results = FALSE;
+ gint i;
+
+ settings = g_settings_new ("org.mate.search-tool");
dir = g_strdup (path);
@@ -355,65 +110,66 @@ is_quick_search_excluded_path (const gchar * path)
g_free (dir);
/* Check path against the Quick-Search-Excluded-Paths list. */
- exclude_path_list = gsearchtool_mateconf_get_list ("/apps/mate-search-tool/quick_search_excluded_paths",
- MATECONF_VALUE_STRING);
+ exclude_path_list = g_settings_get_strv (settings, "quick-search-excluded-paths");
- for (tmp_list = exclude_path_list; tmp_list; tmp_list = tmp_list->next) {
+ if (exclude_path_list) {
+ for (i = 0; exclude_path_list[i]; i++) {
- /* Skip empty or null values. */
- if ((tmp_list->data == NULL) || (strlen (tmp_list->data) == 0)) {
- continue;
- }
+ /* Skip empty or null values. */
+ if (strlen (exclude_path_list[i]) == 0) {
+ continue;
+ }
- dir = g_strdup (tmp_list->data);
+ dir = g_strdup (exclude_path_list[i]);
- /* Wild-card comparisons. */
- if (g_strstr_len (dir, strlen (dir), "*") != NULL) {
+ /* Wild-card comparisons. */
+ if (g_strstr_len (dir, strlen (dir), "*") != NULL) {
- if (g_pattern_match_simple (dir, path) == TRUE) {
+ if (g_pattern_match_simple (dir, path) == TRUE) {
- results = TRUE;
- g_free (dir);
- break;
+ results = TRUE;
+ g_free (dir);
+ break;
+ }
}
- }
- /* Non-wild-card comparisons. */
- else {
- /* Add a trailing G_DIR_SEPARATOR. */
- if (g_str_has_suffix (dir, G_DIR_SEPARATOR_S) == FALSE) {
+ /* Non-wild-card comparisons. */
+ else {
+ /* Add a trailing G_DIR_SEPARATOR. */
+ if (g_str_has_suffix (dir, G_DIR_SEPARATOR_S) == FALSE) {
- gchar *tmp;
+ gchar *tmp;
- tmp = dir;
- dir = g_strconcat (dir, G_DIR_SEPARATOR_S, NULL);
- g_free (tmp);
- }
+ tmp = dir;
+ dir = g_strconcat (dir, G_DIR_SEPARATOR_S, NULL);
+ g_free (tmp);
+ }
- if (strcmp (path, dir) == 0) {
+ if (strcmp (path, dir) == 0) {
- results = TRUE;
- g_free (dir);
- break;
+ results = TRUE;
+ g_free (dir);
+ break;
+ }
}
+ g_free (dir);
}
- g_free (dir);
+ g_strfreev (exclude_path_list);
}
- for (tmp_list = exclude_path_list; tmp_list; tmp_list = tmp_list->next) {
- g_free (tmp_list->data);
- }
- g_slist_free (exclude_path_list);
-
+ g_object_unref (settings);
return results;
}
gboolean
is_second_scan_excluded_path (const gchar * path)
{
- GSList * exclude_path_list;
- GSList * tmp_list;
+ GSettings * settings;
+ gchar ** exclude_path_list;
gchar * dir;
gboolean results = FALSE;
+ gint i;
+
+ settings = g_settings_new ("org.mate.search-tool");
dir = g_strdup (path);
@@ -431,55 +187,53 @@ is_second_scan_excluded_path (const gchar * path)
g_free (dir);
/* Check path against the Quick-Search-Excluded-Paths list. */
- exclude_path_list = gsearchtool_mateconf_get_list ("/apps/mate-search-tool/quick_search_second_scan_excluded_paths",
- MATECONF_VALUE_STRING);
+ exclude_path_list = g_settings_get_strv (settings, "quick-search-second-scan-excluded-paths");
- for (tmp_list = exclude_path_list; tmp_list; tmp_list = tmp_list->next) {
+ if (exclude_path_list) {
+ for (i = 0; exclude_path_list[i]; i++) {
- /* Skip empty or null values. */
- if ((tmp_list->data == NULL) || (strlen (tmp_list->data) == 0)) {
- continue;
- }
+ /* Skip empty or null values. */
+ if (strlen (exclude_path_list[i]) == 0) {
+ continue;
+ }
- dir = g_strdup (tmp_list->data);
+ dir = g_strdup (exclude_path_list[i]);
- /* Wild-card comparisons. */
- if (g_strstr_len (dir, strlen (dir), "*") != NULL) {
+ /* Wild-card comparisons. */
+ if (g_strstr_len (dir, strlen (dir), "*") != NULL) {
- if (g_pattern_match_simple (dir, path) == TRUE) {
+ if (g_pattern_match_simple (dir, path) == TRUE) {
- results = TRUE;
- g_free (dir);
- break;
+ results = TRUE;
+ g_free (dir);
+ break;
+ }
}
- }
- /* Non-wild-card comparisons. */
- else {
- /* Add a trailing G_DIR_SEPARATOR. */
- if (g_str_has_suffix (dir, G_DIR_SEPARATOR_S) == FALSE) {
+ /* Non-wild-card comparisons. */
+ else {
+ /* Add a trailing G_DIR_SEPARATOR. */
+ if (g_str_has_suffix (dir, G_DIR_SEPARATOR_S) == FALSE) {
- gchar *tmp;
+ gchar *tmp;
- tmp = dir;
- dir = g_strconcat (dir, G_DIR_SEPARATOR_S, NULL);
- g_free (tmp);
- }
+ tmp = dir;
+ dir = g_strconcat (dir, G_DIR_SEPARATOR_S, NULL);
+ g_free (tmp);
+ }
- if (strcmp (path, dir) == 0) {
+ if (strcmp (path, dir) == 0) {
- results = TRUE;
- g_free (dir);
- break;
+ results = TRUE;
+ g_free (dir);
+ break;
+ }
}
+ g_free (dir);
}
- g_free (dir);
+ g_strfreev (exclude_path_list);
}
- for (tmp_list = exclude_path_list; tmp_list; tmp_list = tmp_list->next) {
- g_free (tmp_list->data);
- }
- g_slist_free (exclude_path_list);
-
+ g_object_unref (settings);
return results;
}
@@ -622,7 +376,7 @@ backslash_special_characters (const gchar * string)
if (*string == '\\') {
g_string_append(gs, "\\\\");
}
- if (*string == '-') {
+ else if (*string == '-') {
g_string_append(gs, "\\-");
}
else {
@@ -654,7 +408,7 @@ remove_mnemonic_character (const gchar * string)
}
gchar *
-get_readable_date (const gchar * format_string,
+get_readable_date (const CajaDateFormat date_format_enum,
const time_t file_time_raw)
{
struct tm * file_time;
@@ -666,13 +420,11 @@ get_readable_date (const gchar * format_string,
file_time = localtime (&file_time_raw);
- /* Base format of date column on caja date_format key */
- if (format_string != NULL) {
- if (strcmp(format_string, GSEARCH_DATE_FORMAT_LOCALE) == 0) {
- return gsearchtool_strdup_strftime ("%c", file_time);
- } else if (strcmp (format_string, GSEARCH_DATE_FORMAT_ISO) == 0) {
- return gsearchtool_strdup_strftime ("%Y-%m-%d %H:%M:%S", file_time);
- }
+ /* Base format of date column on caja date-format key */
+ if (date_format_enum == CAJA_DATE_FORMAT_LOCALE) {
+ return gsearchtool_strdup_strftime ("%c", file_time);
+ } else if (date_format_enum == CAJA_DATE_FORMAT_ISO) {
+ return gsearchtool_strdup_strftime ("%Y-%m-%d %H:%M:%S", file_time);
}
file_date = g_date_new_dmy (file_time->tm_mday,
@@ -898,36 +650,31 @@ get_file_type_description (const gchar * file,
return desc;
}
-static gchar* gsearchtool_pixmap_file(const gchar* partial_path)
+static gchar *
+gsearchtool_pixmap_file (const gchar * partial_path)
{
- gchar* path;
+ gchar * path;
path = g_build_filename(DATADIR "/pixmaps/mate-search-tool", partial_path, NULL);
-
- if (g_file_test(path, G_FILE_TEST_EXISTS))
- {
+ if (g_file_test(path, G_FILE_TEST_EXISTS)){
return path;
}
-
- g_free(path);
-
+ g_free (path);
return NULL;
}
-static GdkPixbuf* gsearchtool_load_thumbnail_frame(void)
+static GdkPixbuf *
+gsearchtool_load_thumbnail_frame (void)
{
- GdkPixbuf* pixbuf = NULL;
- gchar* image_path;
+ GdkPixbuf * pixbuf = NULL;
+ gchar * image_path;
image_path = gsearchtool_pixmap_file("thumbnail_frame.png");
- if (image_path != NULL)
- {
+ if (image_path != NULL){
pixbuf = gdk_pixbuf_new_from_file(image_path, NULL);
}
-
g_free(image_path);
-
return pixbuf;
}
@@ -1433,35 +1180,47 @@ void
gsearchtool_set_columns_order (GtkTreeView * treeview)
{
GtkTreeViewColumn * last = NULL;
- GSList * order;
- GSList * it;
+ GSettings * settings;
+ GVariant * value;
- order = gsearchtool_mateconf_get_list ("/apps/mate-search-tool/columns_order", MATECONF_VALUE_INT);
+ settings = g_settings_new ("org.mate.search-tool");
- for (it = order; it; it = it->next) {
+ value = g_settings_get_value (settings, "columns-order");
- GtkTreeViewColumn * cur;
- gint id;
+ if (value) {
+ GVariantIter *iter;
+ GVariant *item;
+
+ g_variant_get (value, "ai", &iter);
+
+ while ((item = g_variant_iter_next_value (iter))) {
+ GtkTreeViewColumn * cur;
+ gint id;
- id = GPOINTER_TO_INT (it->data);
+ g_variant_get (item, "i", &id);
- if (id >= 0 && id < NUM_COLUMNS) {
+ if (id >= 0 && id < NUM_COLUMNS) {
- cur = gsearchtool_gtk_tree_view_get_column_with_sort_column_id (treeview, id);
+ cur = gsearchtool_gtk_tree_view_get_column_with_sort_column_id (treeview, id);
- if (cur && cur != last) {
- gtk_tree_view_move_column_after (treeview, cur, last);
- last = cur;
+ if (cur && cur != last) {
+ gtk_tree_view_move_column_after (treeview, cur, last);
+ last = cur;
+ }
}
+ g_variant_unref (item);
}
+ g_variant_iter_free (iter);
+ g_variant_unref (value);
}
- g_slist_free (order);
+ g_object_unref (settings);
}
void
gsearchtool_get_stored_window_geometry (gint * width,
gint * height)
{
+ GSettings * settings;
gint saved_width;
gint saved_height;
@@ -1469,8 +1228,10 @@ gsearchtool_get_stored_window_geometry (gint * width,
return;
}
- saved_width = gsearchtool_mateconf_get_int ("/apps/mate-search-tool/default_window_width");
- saved_height = gsearchtool_mateconf_get_int ("/apps/mate-search-tool/default_window_height");
+ settings = g_settings_new ("org.mate.search-tool");
+
+ saved_width = g_settings_get_int (settings, "default-window-width");
+ saved_height = g_settings_get_int (settings, "default-window-height");
if (saved_width == -1) {
saved_width = DEFAULT_WINDOW_WIDTH;
@@ -1482,6 +1243,7 @@ gsearchtool_get_stored_window_geometry (gint * width,
*width = MAX (saved_width, MINIMUM_WINDOW_WIDTH);
*height = MAX (saved_height, MINIMUM_WINDOW_HEIGHT);
+ g_object_unref (settings);
}
/* START OF CAJA/EEL FUNCTIONS: USED FOR HANDLING OF DUPLICATE FILENAMES */