GnuCash  4.11-243-g1cac132214+
Files | Data Structures | Macros | 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
 The instance private data for a file history plugin. More...
 
struct  GncPluginFileHistory
 The instance data structure for a file history plugin. More...
 
struct  GncPluginFileHistoryClass
 The class data structure for a file history plugin. More...
 

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"
 The label given to the main window for this plugin. More...
 
#define PLUGIN_UI_FILENAME   "gnc-plugin-file-history-ui.xml"
 The name of the UI description file for this plugin. More...
 
#define GNOME1_HISTORY   "History"
 
#define GNOME1_MAXFILES   "MaxFiles"
 
#define GNC_PLUGIN_FILE_HISTORY_GET_PRIVATE(o)   ((GncPluginFileHistoryPrivate*)gnc_plugin_file_history_get_instance_private((GncPluginFileHistory*)o))
 
#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"
 

Functions

void gnc_history_add_file (const char *filename)
 Add a file name to the front of the file "history list". More...
 
void gnc_history_remove_file (const char *oldfile)
 Remove all occurrences of a file name from the history list. More...
 
gboolean gnc_history_test_for_file (const char *oldfile)
 Test for a file name existing in the history list. More...
 
char * gnc_history_get_last (void)
 Retrieve the name of the file most recently accessed. More...
 
GncPlugingnc_plugin_file_history_new (void)
 Create a new file history plugin. More...
 
GType gnc_plugin_file_history_get_type (void)
 Get the type of a file history plugin. More...
 

Detailed Description

Macro Definition Documentation

◆ PLUGIN_ACTIONS_NAME

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

The label given to the main window for this plugin.

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

◆ PLUGIN_UI_FILENAME

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

The name of the UI description file for this plugin.

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

Function Documentation

◆ gnc_history_add_file()

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 158 of file gnc-plugin-file-history.c.

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

◆ gnc_history_get_last()

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 308 of file gnc-plugin-file-history.c.

309 {
310  char *filename, *pref;
311 
312  pref = gnc_history_index_to_pref_name(0);
313  filename = gnc_prefs_get_string(GNC_PREFS_GROUP_HISTORY, pref);
314  g_free(pref);
315 
316  return filename;
317 }
gchar * gnc_prefs_get_string(const gchar *group, const gchar *pref_name)
Get a string value from the preferences backend.

◆ gnc_history_remove_file()

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.

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 227 of file gnc-plugin-file-history.c.

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

◆ gnc_history_test_for_file()

gboolean gnc_history_test_for_file ( const char *  oldfile)

Test for a file name existing in the history list.

Parameters
oldfileThe name of the file to test for in the list.
oldfileThe name of the file to test in the list.

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

271 {
272  gchar *filename, *from;
273  gint i;
274  gboolean found = FALSE;
275 
276  if (!oldfile)
277  return FALSE;
278  if (!g_utf8_validate(oldfile, -1, NULL))
279  return FALSE;
280 
281  for (i = 0; i < MAX_HISTORY_FILES; i++)
282  {
283  from = gnc_history_index_to_pref_name(i);
284  filename = gnc_prefs_get_string(GNC_PREFS_GROUP_HISTORY, from);
285  g_free(from);
286 
287  if (!filename)
288  continue;
289 
290  if (g_utf8_collate(oldfile, filename) == 0)
291  {
292  found = TRUE;
293  g_free (filename);
294  break;
295  }
296  g_free (filename);
297  }
298 
299  return found;
300 }
gchar * gnc_prefs_get_string(const gchar *group, const gchar *pref_name)
Get a string value from the preferences backend.

◆ gnc_plugin_file_history_get_type()

GType gnc_plugin_file_history_get_type ( void  )

Get the type of a file history plugin.

Returns
A GType.

◆ gnc_plugin_file_history_new()

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 582 of file gnc-plugin-file-history.c.

583 {
584  GncPlugin *plugin_page = NULL;
585 
586  ENTER("");
587  plugin_page = GNC_PLUGIN (g_object_new (GNC_TYPE_PLUGIN_FILE_HISTORY, NULL));
588  LEAVE("plugin %p", plugin_page);
589  return plugin_page;
590 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
The instance data structure for a menu-only plugin.
Definition: gnc-plugin.h:100
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282