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);
72 #define PLUGIN_ACTIONS_NAME "gnc-plugin-file-history-actions"
74 #define PLUGIN_UI_FILENAME "gnc-plugin-file-history-ui.xml"
76 #define GNOME1_HISTORY "History"
77 #define GNOME1_MAXFILES "MaxFiles"
84 static GtkActionEntry gnc_plugin_actions [] =
86 {
"RecentFile0Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
87 {
"RecentFile1Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
88 {
"RecentFile2Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
89 {
"RecentFile3Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
90 {
"RecentFile4Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
91 {
"RecentFile5Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
92 {
"RecentFile6Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
93 {
"RecentFile7Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
94 {
"RecentFile8Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
95 {
"RecentFile9Action", NULL,
"", NULL, NULL, G_CALLBACK (gnc_plugin_file_history_cmd_open_file) },
98 static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
109 #define GNC_PLUGIN_FILE_HISTORY_GET_PRIVATE(o) \
110 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_PLUGIN_FILE_HISTORY, GncPluginFileHistoryPrivate))
125 gnc_history_index_to_pref_name (guint index)
127 return g_strdup_printf(HISTORY_STRING_FILE_N, index);
140 gnc_history_pref_name_to_index (
const gchar *pref)
144 result = sscanf(pref, HISTORY_STRING_FILE_N, &index);
147 if ((index < 0) || (index >= gnc_plugin_n_actions))
161 gchar *filename, *from, *to;
166 if (!g_utf8_validate(newfile, -1, NULL))
172 last = MAX_HISTORY_FILES - 1;
173 for (i = 0; i < MAX_HISTORY_FILES; i++)
175 from = gnc_history_index_to_pref_name(i);
184 if (g_utf8_collate(newfile, filename) == 0)
196 to = gnc_history_index_to_pref_name(last);
197 for (i = last - 1; i >= 0; i--)
199 from = gnc_history_index_to_pref_name(i);
230 gchar *filename, *from, *to;
235 if (!g_utf8_validate(oldfile, -1, NULL))
238 for (i = 0, j = 0; i < MAX_HISTORY_FILES; i++)
240 from = gnc_history_index_to_pref_name(i);
245 if (g_utf8_collate(oldfile, filename) == 0)
253 to = gnc_history_index_to_pref_name(j);
272 char *filename, *pref;
274 pref = gnc_history_index_to_pref_name(0);
296 gnc_history_generate_label (
int index,
const gchar *filename)
298 gchar *label, *result;
305 label = g_path_get_basename ( filepath );
315 splitlabel = g_strsplit ( label,
"_", 0);
317 label = g_strjoinv (
"__", splitlabel);
318 g_strfreev (splitlabel);
320 result = g_strdup_printf (
"_%d %s", (index + 1) % 10, label);
337 gnc_history_generate_tooltip (
int index,
const gchar *filename)
370 const gchar *filename)
372 GtkActionGroup *action_group;
374 gchar *action_name, *label_name, *tooltip, *old_filename;
377 ENTER(
"window %p, index %d, filename %s", window, index,
378 filename ? filename :
"(null)");
383 action_name = g_strdup_printf(
"RecentFile%dAction", index);
384 action = gtk_action_group_get_action (action_group, action_name);
387 GNC_PREF_HISTORY_MAXFILES);
389 if (filename && (strlen(filename) > 0) && (index < limit))
392 label_name = gnc_history_generate_label(index, filename);
393 tooltip = gnc_history_generate_tooltip(index, filename);
394 g_object_set(G_OBJECT(action),
"label", label_name,
402 old_filename = g_object_get_data(G_OBJECT(action), FILENAME_STRING);
404 g_free(old_filename);
405 g_object_set_data(G_OBJECT(action), FILENAME_STRING, g_strdup(filename));
409 gtk_action_set_visible(action, FALSE);
427 gchar *filename, *pref;
431 for (i = 0; i < MAX_HISTORY_FILES; i++)
433 pref = gnc_history_index_to_pref_name(i);
435 gnc_history_update_action(window, i, filename);
455 gnc_plugin_history_list_changed (gpointer prefs,
460 const gchar *filename;
464 window = GNC_MAIN_WINDOW(user_data);
466 if (strcmp(pref, GNC_PREF_HISTORY_MAXFILES) == 0)
468 gnc_history_update_menus (window);
469 LEAVE(
"updated maxfiles");
472 index = gnc_history_pref_name_to_index(pref);
480 gnc_history_update_action (window, index, filename);
494 static GType gnc_plugin_file_history_type = 0;
496 if (gnc_plugin_file_history_type == 0)
498 static const GTypeInfo our_info =
503 (GClassInitFunc) gnc_plugin_file_history_class_init,
508 (GInstanceInitFunc) gnc_plugin_file_history_init
511 gnc_plugin_file_history_type =
512 g_type_register_static (GNC_TYPE_PLUGIN,
513 "GncPluginFileHistory",
517 return gnc_plugin_file_history_type;
525 GObjectClass *object_class = G_OBJECT_CLASS (klass);
528 parent_class = g_type_class_peek_parent (klass);
530 object_class->finalize = gnc_plugin_file_history_finalize;
533 plugin_class->
plugin_name = GNC_PLUGIN_FILE_HISTORY_NAME;
536 plugin_class->
add_to_window = gnc_plugin_file_history_add_to_window;
538 gnc_plugin_file_history_remove_from_window;
542 plugin_class->
actions = gnc_plugin_actions;
543 plugin_class->
n_actions = gnc_plugin_n_actions;
554 ENTER(
"plugin %p", plugin);
561 gnc_plugin_file_history_finalize (GObject *
object)
563 g_return_if_fail (GNC_IS_PLUGIN_FILE_HISTORY (
object));
565 ENTER(
"plugin %p",
object);
566 G_OBJECT_CLASS (parent_class)->finalize (
object);
580 plugin_page = GNC_PLUGIN (g_object_new (GNC_TYPE_PLUGIN_FILE_HISTORY, NULL));
581 LEAVE(
"plugin %p", plugin_page);
606 gnc_plugin_file_history_add_to_window (
GncPlugin *plugin,
611 gnc_plugin_history_list_changed, window);
612 gnc_history_update_menus(window);
628 gnc_plugin_file_history_remove_from_window (
GncPlugin *plugin,
633 gnc_plugin_history_list_changed, window);
653 gnc_plugin_file_history_cmd_open_file (GtkAction *action,
658 g_return_if_fail(GTK_IS_ACTION(action));
659 g_return_if_fail(data != NULL);
665 filename = g_object_get_data(G_OBJECT(action), FILENAME_STRING);
666 gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
668 gnc_file_open_file (filename, FALSE);
669 gnc_window_set_progressbar_window (NULL);
gchar * gnc_prefs_get_string(const gchar *group, const gchar *pref_name)
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
gboolean gnc_uri_is_file_uri(const gchar *uri)
Functions that are supported by all types of windows.
GncPlugin * gnc_plugin_file_history_new(void)
GKeyFile helper routines.
gchar * gnc_uri_get_path(const gchar *uri)
void gnc_prefs_reset(const gchar *group, const gchar *pref_name)
gboolean gnc_prefs_set_string(const gchar *group, const gchar *pref_name, const gchar *value)
#define ENTER(format, args...)
const gchar * ui_filename
gint gnc_prefs_get_int(const gchar *group, const gchar *pref_name)
Functions for adding content to a window.
void gnc_history_add_file(const char *newfile)
char * gnc_history_get_last(void)
gchar * gnc_uri_normalize_uri(const gchar *uri, gboolean allow_password)
void(* remove_from_window)(GncPlugin *plugin, GncMainWindow *window, GQuark type)
Functions providing the file history menu.
void gnc_history_remove_file(const char *oldfile)
All type declarations for the whole Gnucash engine.
const gchar * actions_name
Generic api to store and retrieve preferences.
GtkActionGroup * gnc_main_window_get_action_group(GncMainWindow *window, const gchar *group_name)
struct GncPluginFileHistoryPrivate GncPluginFileHistoryPrivate
const gchar * plugin_name
#define PLUGIN_ACTIONS_NAME
#define LEAVE(format, args...)
void(* add_to_window)(GncPlugin *plugin, GncMainWindow *window, GQuark type)
Utility functions for convert uri in separate components and back.
GType gnc_plugin_file_history_get_type(void)
void gnc_main_window_actions_updated(GncMainWindow *window)
#define PLUGIN_UI_FILENAME
const gchar * QofLogModule
void gnc_prefs_remove_cb_by_func(const gchar *group, const gchar *pref_name, gpointer func, gpointer user_data)