3 * A Nautilus extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009, 2010, 2011, 2012 Pierre Wieser and others (see AUTHORS)
9 * This Program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This Program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this Library; see the file COPYING. If not,
21 * write to the Free Software Foundation, Inc., 59 Temple Place,
22 * Suite 330, Boston, MA 02111-1307, USA.
25 * Frederic Ruaudel <grumz@grumz.net>
26 * Rodrigo Moya <rodrigo@gnome-db.org>
27 * Pierre Wieser <pwieser@trychlos.org>
28 * ... and many others (see AUTHORS)
37 #include <api/na-core-utils.h>
39 #include "na-importer.h"
40 #include "na-iprefs.h"
41 #include "na-settings.h"
49 /* sort mode of the items in the file manager context menu
50 * enum is defined in core/na-iprefs.h
52 #define ORDER_ALPHA_ASC_STR "AscendingOrder"
53 #define ORDER_ALPHA_DESC_STR "DescendingOrder"
54 #define ORDER_MANUAL_STR "ManualOrder"
56 static EnumMap st_order_mode
[] = {
57 { IPREFS_ORDER_ALPHA_ASCENDING
, ORDER_ALPHA_ASC_STR
},
58 { IPREFS_ORDER_ALPHA_DESCENDING
, ORDER_ALPHA_DESC_STR
},
59 { IPREFS_ORDER_MANUAL
, ORDER_MANUAL_STR
},
63 static const gchar
*enum_map_string_from_id( const EnumMap
*map
, guint id
);
64 static guint
enum_map_id_from_string( const EnumMap
*map
, const gchar
*str
);
67 * na_iprefs_get_order_mode:
68 * @mandatory: if not %NULL, a pointer to a boolean which will receive the
71 * Returns: the order mode currently set.
74 na_iprefs_get_order_mode( gboolean
*mandatory
)
76 gchar
*order_mode_str
;
79 order_mode_str
= na_settings_get_string( NA_IPREFS_ITEMS_LIST_ORDER_MODE
, NULL
, mandatory
);
80 order_mode
= enum_map_id_from_string( st_order_mode
, order_mode_str
);
81 g_free( order_mode_str
);
87 * na_iprefs_get_order_mode_by_label:
90 * This function converts a label (e.g. 'ManualOrder') stored in user preferences
91 * into the corresponding integer internally used. This is needed e.g. when
92 * monitoring the preferences changes.
94 * Returns: the order mode currently set.
97 na_iprefs_get_order_mode_by_label( const gchar
*label
)
101 order_mode
= enum_map_id_from_string( st_order_mode
, label
);
103 return( order_mode
);
107 * na_iprefs_set_order_mode:
108 * @mode: the new value to be written.
110 * Writes the current status of 'alphabetical order' to the GConf
114 na_iprefs_set_order_mode( guint mode
)
116 const gchar
*order_str
;
118 order_str
= enum_map_string_from_id( st_order_mode
, mode
);
119 na_settings_set_string( NA_IPREFS_ITEMS_LIST_ORDER_MODE
, order_str
);
123 * na_iprefs_write_level_zero:
124 * @items: the #GList of items whose first level is to be written.
125 * @messages: a pointer to a #GSList in which we will add happening
127 * the pointer may be %NULL;
128 * if not %NULL, the #GSList must have been initialized by the
131 * Rewrite the level-zero items in GConf preferences.
133 * Returns: %TRUE if successfully written (i.e. writable, not locked,
134 * and so on), %FALSE else.
136 * @messages #GSList is only filled up in case of an error has occured.
137 * If there is no error (na_iprefs_write_level_zero() returns %TRUE), then
138 * the caller may safely assume that @messages is returned in the same
139 * state that it has been provided.
142 na_iprefs_write_level_zero( const GList
*items
, GSList
**messages
)
152 for( it
= items
; it
; it
= it
->next
){
153 id
= na_object_get_id( it
->data
);
154 content
= g_slist_prepend( content
, id
);
156 content
= g_slist_reverse( content
);
158 written
= na_settings_set_string_list( NA_IPREFS_ITEMS_LEVEL_ZERO_ORDER
, content
);
160 na_core_utils_slist_free( content
);
166 enum_map_string_from_id( const EnumMap
*map
, guint id
)
168 const EnumMap
*i
= map
;
180 enum_map_id_from_string( const EnumMap
*map
, const gchar
*str
)
182 const EnumMap
*i
= map
;
185 if( !strcmp( i
->str
, str
)){