GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Files | Data Structures | Macros | Typedefs | Functions
File History Menu Items

Files

file  gnc-plugin-file-history.c
 Functions providing the file history menu.
 
file  gnc-plugin-file-history.h
 Functions providing the file history menu.
 

Data Structures

struct  GncPluginFileHistoryPrivate
 
struct  GncPluginFileHistory
 
struct  GncPluginFileHistoryClass
 

Macros

#define FILENAME_STRING   "filename"
 
#define MAX_HISTORY_FILES   10 /* May be any number up to 10 */
 
#define GNC_PREFS_GROUP_HISTORY   "history"
 
#define GNC_PREF_HISTORY_MAXFILES   "maxfiles"
 
#define HISTORY_STRING_FILE_N   "file%d"
 
#define PLUGIN_ACTIONS_NAME   "gnc-plugin-file-history-actions"
 
#define PLUGIN_UI_FILENAME   "gnc-plugin-file-history-ui.xml"
 
#define GNOME1_HISTORY   "History"
 
#define GNOME1_MAXFILES   "MaxFiles"
 
#define GNC_PLUGIN_FILE_HISTORY_GET_PRIVATE(o)   (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_PLUGIN_FILE_HISTORY, GncPluginFileHistoryPrivate))
 
#define GNC_TYPE_PLUGIN_FILE_HISTORY   (gnc_plugin_file_history_get_type ())
 
#define GNC_PLUGIN_FILE_HISTORY(obj)   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_PLUGIN_FILE_HISTORY, GncPluginFileHistory))
 
#define GNC_PLUGIN_FILE_HISTORY_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_PLUGIN_FILE_HISTORY, GncPluginFileHistoryClass))
 
#define GNC_IS_PLUGIN_FILE_HISTORY(obj)   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_PLUGIN_FILE_HISTORY))
 
#define GNC_IS_PLUGIN_FILE_HISTORY_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_PLUGIN_FILE_HISTORY))
 
#define GNC_PLUGIN_FILE_HISTORY_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_PLUGIN_FILE_HISTORY, GncPluginFileHistoryClass))
 
#define GNC_PLUGIN_FILE_HISTORY_NAME   "gnc-plugin-file-history"
 

Typedefs

typedef struct
GncPluginFileHistoryPrivate 
GncPluginFileHistoryPrivate
 

Functions

void gnc_history_add_file (const char *newfile)
 
void gnc_history_remove_file (const char *oldfile)
 
char * gnc_history_get_last (void)
 
GType gnc_plugin_file_history_get_type (void)
 
GncPlugingnc_plugin_file_history_new (void)
 

Detailed Description

Macro Definition Documentation

#define PLUGIN_ACTIONS_NAME   "gnc-plugin-file-history-actions"

The label given to the main window for this plugin.

Definition at line 72 of file gnc-plugin-file-history.c.

#define PLUGIN_UI_FILENAME   "gnc-plugin-file-history-ui.xml"

The name of the UI description file for this plugin.

Definition at line 74 of file gnc-plugin-file-history.c.

Typedef Documentation

The instance private data for a file history plugin. This data structure is unused.

Function Documentation

void gnc_history_add_file ( const char *  filename)

Add a file name to the front of the file "history list". If the name already exist on the list, then it is moved from its current location to the front of the list.

Parameters
filenameThe name of the file to add to the list.

Definition at line 159 of file gnc-plugin-file-history.c.

160 {
161  gchar *filename, *from, *to;
162  gint i, last;
163 
164  if (newfile == NULL)
165  return;
166  if (!g_utf8_validate(newfile, -1, NULL))
167  return;
168 
169  /*
170  * Look for the filename in preferences.
171  */
172  last = MAX_HISTORY_FILES - 1;
173  for (i = 0; i < MAX_HISTORY_FILES; i++)
174  {
175  from = gnc_history_index_to_pref_name(i);
176  filename = gnc_prefs_get_string(GNC_PREFS_GROUP_HISTORY, from);
177  g_free(from);
178 
179  if (!filename)
180  {
181  last = i;
182  break;
183  }
184  if (g_utf8_collate(newfile, filename) == 0)
185  {
186  g_free(filename);
187  last = i;
188  break;
189  }
190  g_free(filename);
191  }
192 
193  /*
194  * Shuffle filenames upward through preferences.
195  */
196  to = gnc_history_index_to_pref_name(last);
197  for (i = last - 1; i >= 0; i--)
198  {
199  from = gnc_history_index_to_pref_name(i);
200  filename = gnc_prefs_get_string(GNC_PREFS_GROUP_HISTORY, from);
201  if (filename)
202  {
203  gnc_prefs_set_string(GNC_PREFS_GROUP_HISTORY, to, filename);
204  g_free(filename);
205  }
206  else
207  {
208  gnc_prefs_reset(GNC_PREFS_GROUP_HISTORY, to);
209  }
210  g_free(to);
211  to = from;
212  }
213 
214  /*
215  * Store the new zero entry.
216  */
217  gnc_prefs_set_string(GNC_PREFS_GROUP_HISTORY, to, newfile);
218  g_free(to);
219 }
gchar * gnc_prefs_get_string(const gchar *group, const gchar *pref_name)
Definition: gnc-prefs.c:237
void gnc_prefs_reset(const gchar *group, const gchar *pref_name)
Definition: gnc-prefs.c:366
gboolean gnc_prefs_set_string(const gchar *group, const gchar *pref_name, const gchar *value)
Definition: gnc-prefs.c:324
char * gnc_history_get_last ( void  )

Retrieve the name of the file most recently accessed. This is the name at the front of the list.

Returns
This function returns an allocated string containing the name of the most recently accessed file. The caller is responsible for freeing this string.

Definition at line 270 of file gnc-plugin-file-history.c.

271 {
272  char *filename, *pref;
273 
274  pref = gnc_history_index_to_pref_name(0);
275  filename = gnc_prefs_get_string(GNC_PREFS_GROUP_HISTORY, pref);
276  g_free(pref);
277 
278  return filename;
279 }
gchar * gnc_prefs_get_string(const gchar *group, const gchar *pref_name)
Definition: gnc-prefs.c:237
void gnc_history_remove_file ( const char *  oldfile)

Remove all occurrences of a file name from the history list. Move the other file names up in the list to fill the gaps.

Parameters
oldfileThe name of the file to remove from the list.

Remove all occurences of a file name from the history list. Move the other key values up in the list to fill the gaps.

Parameters
oldfileThe name of the file to remove from the list.

Definition at line 228 of file gnc-plugin-file-history.c.

229 {
230  gchar *filename, *from, *to;
231  gint i, j;
232 
233  if (!oldfile)
234  return;
235  if (!g_utf8_validate(oldfile, -1, NULL))
236  return;
237 
238  for (i = 0, j = 0; i < MAX_HISTORY_FILES; i++)
239  {
240  from = gnc_history_index_to_pref_name(i);
241  filename = gnc_prefs_get_string(GNC_PREFS_GROUP_HISTORY, from);
242 
243  if (filename)
244  {
245  if (g_utf8_collate(oldfile, filename) == 0)
246  {
247  gnc_prefs_reset(GNC_PREFS_GROUP_HISTORY, from);
248  }
249  else
250  {
251  if (i != j)
252  {
253  to = gnc_history_index_to_pref_name(j);
254  gnc_prefs_set_string(GNC_PREFS_GROUP_HISTORY, to, filename);
255  gnc_prefs_reset(GNC_PREFS_GROUP_HISTORY, from);
256  g_free(to);
257  }
258  j++;
259  }
260  }
261  g_free(from);
262  }
263 }
gchar * gnc_prefs_get_string(const gchar *group, const gchar *pref_name)
Definition: gnc-prefs.c:237
void gnc_prefs_reset(const gchar *group, const gchar *pref_name)
Definition: gnc-prefs.c:366
gboolean gnc_prefs_set_string(const gchar *group, const gchar *pref_name, const gchar *value)
Definition: gnc-prefs.c:324
GType gnc_plugin_file_history_get_type ( void  )

Get the type of a file history plugin.

Returns
A GType.

Definition at line 492 of file gnc-plugin-file-history.c.

493 {
494  static GType gnc_plugin_file_history_type = 0;
495 
496  if (gnc_plugin_file_history_type == 0)
497  {
498  static const GTypeInfo our_info =
499  {
500  sizeof (GncPluginFileHistoryClass),
501  NULL, /* base_init */
502  NULL, /* base_finalize */
503  (GClassInitFunc) gnc_plugin_file_history_class_init,
504  NULL, /* class_finalize */
505  NULL, /* class_data */
506  sizeof (GncPluginFileHistory),
507  0,
508  (GInstanceInitFunc) gnc_plugin_file_history_init
509  };
510 
511  gnc_plugin_file_history_type =
512  g_type_register_static (GNC_TYPE_PLUGIN,
513  "GncPluginFileHistory",
514  &our_info, 0);
515  }
516 
517  return gnc_plugin_file_history_type;
518 }
GncPlugin * gnc_plugin_file_history_new ( void  )

Create a new file history plugin. This plugin attaches the file history menu to any window that is opened.

Returns
A pointer to the new object.

Definition at line 575 of file gnc-plugin-file-history.c.

576 {
577  GncPlugin *plugin_page = NULL;
578 
579  ENTER("");
580  plugin_page = GNC_PLUGIN (g_object_new (GNC_TYPE_PLUGIN_FILE_HISTORY, NULL));
581  LEAVE("plugin %p", plugin_page);
582  return plugin_page;
583 }
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271