GnuCash  5.6-150-g038405b370+
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  _GncPluginFileHistory
 The instance 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"
 The name of the UI description file for this plugin. More...
 
#define GNOME1_HISTORY   "History"
 
#define GNOME1_MAXFILES   "MaxFiles"
 
#define GNC_TYPE_PLUGIN_FILE_HISTORY   (gnc_plugin_file_history_get_type ())
 
#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...
 
GncPlugin * gnc_plugin_file_history_new (void)
 Create a new 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 68 of file gnc-plugin-file-history.c.

◆ PLUGIN_UI_FILENAME

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

The name of the UI description file for this plugin.

Definition at line 70 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 155 of file gnc-plugin-file-history.c.

156 {
157  gchar *filename, *from, *to;
158  gint i, last;
159 
160  if (newfile == NULL)
161  return;
162  if (!g_utf8_validate(newfile, -1, NULL))
163  return;
164 
165  /*
166  * Look for the filename in preferences.
167  */
168  last = MAX_HISTORY_FILES - 1;
169  for (i = 0; i < MAX_HISTORY_FILES; i++)
170  {
171  from = gnc_history_index_to_pref_name(i);
172  filename = gnc_prefs_get_string(GNC_PREFS_GROUP_HISTORY, from);
173  g_free(from);
174 
175  if (!filename)
176  {
177  last = i;
178  break;
179  }
180  if (g_utf8_collate(newfile, filename) == 0)
181  {
182  g_free(filename);
183  last = i;
184  break;
185  }
186  g_free(filename);
187  }
188 
189  /*
190  * Shuffle filenames upward through preferences.
191  */
192  to = gnc_history_index_to_pref_name(last);
193  for (i = last - 1; i >= 0; i--)
194  {
195  from = gnc_history_index_to_pref_name(i);
196  filename = gnc_prefs_get_string(GNC_PREFS_GROUP_HISTORY, from);
197  if (filename && *filename)
198  {
199  gnc_prefs_set_string(GNC_PREFS_GROUP_HISTORY, to, filename);
200  }
201  else
202  {
203  gnc_prefs_reset(GNC_PREFS_GROUP_HISTORY, to);
204  }
205  g_free(filename);
206  g_free(to);
207  to = from;
208  }
209 
210  /*
211  * Store the new zero entry.
212  */
213  gnc_prefs_set_string(GNC_PREFS_GROUP_HISTORY, to, newfile);
214  g_free(to);
215 }
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 305 of file gnc-plugin-file-history.c.

306 {
307  char *filename, *pref;
308 
309  pref = gnc_history_index_to_pref_name(0);
310  filename = gnc_prefs_get_string(GNC_PREFS_GROUP_HISTORY, pref);
311  g_free(pref);
312 
313  return filename;
314 }
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 224 of file gnc-plugin-file-history.c.

225 {
226  gchar *filename, *from, *to;
227  gint i, j;
228 
229  if (!oldfile)
230  return;
231  if (!g_utf8_validate(oldfile, -1, NULL))
232  return;
233 
234  for (i = 0, j = 0; i < MAX_HISTORY_FILES; i++)
235  {
236  from = gnc_history_index_to_pref_name(i);
237  filename = gnc_prefs_get_string(GNC_PREFS_GROUP_HISTORY, from);
238 
239  if (filename)
240  {
241  if (g_utf8_collate(oldfile, filename) == 0)
242  {
243  gnc_prefs_reset(GNC_PREFS_GROUP_HISTORY, from);
244  }
245  else
246  {
247  if (i != j)
248  {
249  to = gnc_history_index_to_pref_name(j);
250  gnc_prefs_set_string(GNC_PREFS_GROUP_HISTORY, to, filename);
251  gnc_prefs_reset(GNC_PREFS_GROUP_HISTORY, from);
252  g_free(to);
253  }
254  j++;
255  }
256  g_free (filename);
257  }
258  g_free(from);
259  }
260 }
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 267 of file gnc-plugin-file-history.c.

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

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

598 {
599  GncPlugin *plugin_page = NULL;
600 
601  ENTER("");
602  plugin_page = GNC_PLUGIN (g_object_new (GNC_TYPE_PLUGIN_FILE_HISTORY, NULL));
603  LEAVE("plugin %p", plugin_page);
604  return plugin_page;
605 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282