35 #include <glib/gi18n.h> 36 #include <glib/gprintf.h> 48 static GObjectClass *parent_class = NULL;
50 #define FILENAME_STRING "filename" 51 #define MAX_HISTORY_FILES 10 52 #define GNC_PREFS_GROUP_HISTORY "history" 53 #define GNC_PREF_HISTORY_MAXFILES "maxfiles" 54 #define HISTORY_STRING_FILE_N "file%d" 58 static void gnc_plugin_file_history_finalize (GObject *
object);
61 static void gnc_plugin_file_history_remove_from_window (
GncPlugin *plugin,
GncMainWindow *window, GQuark type);
65 static QofLogModule log_module = GNC_MOD_GUI;
71 #define PLUGIN_ACTIONS_NAME "gnc-plugin-file-history-actions" 73 #define PLUGIN_UI_FILENAME "gnc-plugin-file-history-ui.xml" 75 #define GNOME1_HISTORY "History" 76 #define GNOME1_MAXFILES "MaxFiles" 83 static GtkActionEntry gnc_plugin_actions [] =
85 {
"RecentFile0Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
86 {
"RecentFile1Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
87 {
"RecentFile2Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
88 {
"RecentFile3Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
89 {
"RecentFile4Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
90 {
"RecentFile5Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
91 {
"RecentFile6Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
92 {
"RecentFile7Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
93 {
"RecentFile8Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
94 {
"RecentFile9Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
97 static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
108 #define GNC_PLUGIN_FILE_HISTORY_GET_PRIVATE(o) \ 109 ((GncPluginFileHistoryPrivate*)gnc_plugin_file_history_get_instance_private((GncPluginFileHistory*)o)) 124 gnc_history_index_to_pref_name (guint index)
126 return g_strdup_printf(HISTORY_STRING_FILE_N, index);
139 gnc_history_pref_name_to_index (
const gchar *pref)
143 result = sscanf(pref, HISTORY_STRING_FILE_N, &index);
146 if ((index < 0) || (index >= gnc_plugin_n_actions))
160 gchar *filename, *from, *to;
165 if (!g_utf8_validate(newfile, -1, NULL))
171 last = MAX_HISTORY_FILES - 1;
172 for (i = 0; i < MAX_HISTORY_FILES; i++)
174 from = gnc_history_index_to_pref_name(i);
183 if (g_utf8_collate(newfile, filename) == 0)
195 to = gnc_history_index_to_pref_name(last);
196 for (i = last - 1; i >= 0; i--)
198 from = gnc_history_index_to_pref_name(i);
200 if (filename && *filename)
229 gchar *filename, *from, *to;
234 if (!g_utf8_validate(oldfile, -1, NULL))
237 for (i = 0, j = 0; i < MAX_HISTORY_FILES; i++)
239 from = gnc_history_index_to_pref_name(i);
244 if (g_utf8_collate(oldfile, filename) == 0)
252 to = gnc_history_index_to_pref_name(j);
272 gchar *filename, *from;
274 gboolean found = FALSE;
278 if (!g_utf8_validate(oldfile, -1, NULL))
281 for (i = 0; i < MAX_HISTORY_FILES; i++)
283 from = gnc_history_index_to_pref_name(i);
290 if (g_utf8_collate(oldfile, filename) == 0)
310 char *filename, *pref;
312 pref = gnc_history_index_to_pref_name(0);
334 gnc_history_generate_label (
int index,
const gchar *filename)
336 gchar *label, *result;
343 label = g_path_get_basename ( filepath );
353 splitlabel = g_strsplit ( label,
"_", 0);
355 label = g_strjoinv (
"__", splitlabel);
356 g_strfreev (splitlabel);
358 result = g_strdup_printf (
"_%d %s", (index + 1) % 10, label);
375 gnc_history_generate_tooltip (
int index,
const gchar *filename)
408 const gchar *filename)
410 GtkActionGroup *action_group;
412 gchar *action_name, *label_name, *tooltip, *old_filename;
415 ENTER(
"window %p, index %d, filename %s", window, index,
416 filename ? filename :
"(null)");
421 action_name = g_strdup_printf(
"RecentFile%dAction", index);
422 action = gtk_action_group_get_action (action_group, action_name);
425 GNC_PREF_HISTORY_MAXFILES);
427 if (filename && (strlen(filename) > 0) && (index < limit))
430 label_name = gnc_history_generate_label(index, filename);
431 tooltip = gnc_history_generate_tooltip(index, filename);
432 g_object_set(G_OBJECT(action),
"label", label_name,
440 old_filename = g_object_get_data(G_OBJECT(action), FILENAME_STRING);
442 g_free(old_filename);
443 g_object_set_data(G_OBJECT(action), FILENAME_STRING, g_strdup(filename));
447 gtk_action_set_visible(action, FALSE);
465 gchar *filename, *pref;
469 for (i = 0; i < MAX_HISTORY_FILES; i++)
471 pref = gnc_history_index_to_pref_name(i);
473 gnc_history_update_action(window, i, filename);
493 gnc_plugin_history_list_changed (gpointer prefs,
502 window = GNC_MAIN_WINDOW(user_data);
504 if (strcmp(pref, GNC_PREF_HISTORY_MAXFILES) == 0)
506 gnc_history_update_menus (window);
507 LEAVE(
"updated maxfiles");
510 index = gnc_history_pref_name_to_index(pref);
518 gnc_history_update_action (window, index, filename);
533 GObjectClass *object_class = G_OBJECT_CLASS (klass);
536 parent_class = g_type_class_peek_parent (klass);
538 object_class->finalize = gnc_plugin_file_history_finalize;
541 plugin_class->
plugin_name = GNC_PLUGIN_FILE_HISTORY_NAME;
544 plugin_class->
add_to_window = gnc_plugin_file_history_add_to_window;
546 gnc_plugin_file_history_remove_from_window;
550 plugin_class->
actions = gnc_plugin_actions;
551 plugin_class->
n_actions = gnc_plugin_n_actions;
561 ENTER(
"plugin %p", plugin);
568 gnc_plugin_file_history_finalize (GObject *
object)
570 g_return_if_fail (GNC_IS_PLUGIN_FILE_HISTORY (
object));
572 ENTER(
"plugin %p",
object);
573 G_OBJECT_CLASS (parent_class)->finalize (
object);
587 plugin_page = GNC_PLUGIN (g_object_new (GNC_TYPE_PLUGIN_FILE_HISTORY, NULL));
588 LEAVE(
"plugin %p", plugin_page);
613 gnc_plugin_file_history_add_to_window (
GncPlugin *plugin,
618 gnc_plugin_history_list_changed, window);
619 gnc_history_update_menus(window);
635 gnc_plugin_file_history_remove_from_window (
GncPlugin *plugin,
640 gnc_plugin_history_list_changed, window);
660 gnc_plugin_file_history_cmd_open_file (GtkAction *action,
665 g_return_if_fail(GTK_IS_ACTION(action));
666 g_return_if_fail(data != NULL);
672 filename = g_object_get_data(G_OBJECT(action), FILENAME_STRING);
673 gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
675 gnc_file_open_file (GTK_WINDOW (data->window),
677 gnc_window_set_progressbar_window (NULL);
guint n_actions
The number of actions in the actions array.
gchar * gnc_prefs_get_string(const gchar *group, const gchar *pref_name)
Get a string value from the preferences backend.
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
Register a callback that gets triggered when the given preference changes.
void gnc_history_add_file(const char *newfile)
Add a file name to the front of the file "history list".
Functions that are supported by all types of windows.
GncPlugin * gnc_plugin_file_history_new(void)
Create a new file history plugin.
GKeyFile helper routines.
The instance data structure for a file history plugin.
gchar * gnc_uri_get_path(const gchar *uri)
Extracts the path part from a uri.
void gnc_prefs_reset(const gchar *group, const gchar *pref_name)
Reset a preference to its default value in the preferences backend.
The class data structure for a menu-only plugin.
gboolean gnc_prefs_set_string(const gchar *group, const gchar *pref_name, const gchar *value)
Store a string into the preferences backend.
#define ENTER(format, args...)
Print a function entry debugging message.
const gchar * ui_filename
The relative name of the XML file describing the menu/toolbar action items.
gint gnc_prefs_get_int(const gchar *group, const gchar *pref_name)
Get an integer value from the preferences backend.
Functions for adding content to a window.
GtkActionEntry * actions
An array of actions that should automatically be added to any GnuCash "main" content window that is o...
char * gnc_history_get_last(void)
Retrieve the name of the file most recently accessed.
gchar * gnc_uri_normalize_uri(const gchar *uri, gboolean allow_password)
Composes a normalized uri starting from any uri (filename, db spec,...).
Functions providing the file history menu.
void gnc_history_remove_file(const char *oldfile)
Remove all occurrences of a file name from the history list.
void(* remove_from_window)(GncPlugin *plugin, GncMainWindow *window, GQuark type)
A callback that will be invoked when this plugin is removed from a window.
All type declarations for the whole Gnucash engine.
void(* add_to_window)(GncPlugin *plugin, GncMainWindow *window, GQuark type)
A callback that will be invoked when this plugin is added to a window.
const gchar * actions_name
A name for the set of actions that will be added by this plugin.
Generic api to store and retrieve preferences.
gboolean gnc_uri_targets_local_fs(const gchar *uri)
Checks if the given uri is either a valid file uri or a local filesystem path.
gboolean gnc_history_test_for_file(const char *oldfile)
Test for a file name existing in the history list.
GtkActionGroup * gnc_main_window_get_action_group(GncMainWindow *window, const gchar *group_name)
Retrieve a specific set of user interface actions from a window.
The class data structure for a file history plugin.
const gchar * plugin_name
The textual name of this plugin.
The instance private data for a file history plugin.
The instance data structure for a menu-only plugin.
#define PLUGIN_ACTIONS_NAME
The label given to the main window for this plugin.
#define LEAVE(format, args...)
Print a function exit debugging message.
Utility functions for convert uri in separate components and back.
The instance data structure for a main window object.
void gnc_main_window_actions_updated(GncMainWindow *window)
Force a full update of the user interface for the specified window.
#define PLUGIN_UI_FILENAME
The name of the UI description file for this plugin.
void gnc_prefs_remove_cb_by_func(const gchar *group, const gchar *pref_name, gpointer func, gpointer user_data)
Remove a function that was registered for a callback when the given preference changed.