File History Menu Items
[Menu Only Plugins]


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

Defines

#define FILENAME_STRING   "filename"
#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"
#define MAX_HISTORY_FILES   10
#define HISTORY_STRING_SECTION   "history"
#define HISTORY_STRING_MAXFILES   "maxfiles"
#define HISTORY_STRING_FILE_N   "file%d"

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)


Define Documentation

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

The label given to the main window for this plugin.

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


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. The "list" is actually a sequence of up to ten gconf keys.

Parameters:
filename The name of the file to add to the list.

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

00154 {
00155   gchar *filename, *from, *to;
00156   gint i, last;
00157 
00158   if (newfile == NULL)
00159     return;
00160   if (!g_utf8_validate(newfile, -1, NULL))
00161     return;
00162 
00163   /*
00164    * Look for the filename in gconf.
00165    */
00166   last = MAX_HISTORY_FILES - 1;
00167   for (i = 0; i < MAX_HISTORY_FILES; i++) {
00168     from = gnc_history_gconf_index_to_key(i);
00169     filename = gnc_gconf_get_string(HISTORY_STRING_SECTION, from, NULL);
00170     g_free(from);
00171 
00172     if (!filename) {
00173       last = i;
00174       break;
00175     }
00176     if (g_utf8_collate(newfile, filename) == 0) {
00177       g_free(filename);
00178       last = i;
00179       break;
00180     }
00181     g_free(filename);
00182   }
00183 
00184   /*
00185    * Shuffle filenames upward through gconf.
00186    */
00187   to = gnc_history_gconf_index_to_key(last);
00188   for (i = last - 1; i >= 0; i--) {
00189     from = gnc_history_gconf_index_to_key(i);
00190     filename = gnc_gconf_get_string(HISTORY_STRING_SECTION, from, NULL);
00191     if (filename) {
00192       gnc_gconf_set_string(HISTORY_STRING_SECTION, to, filename, NULL);
00193       g_free(filename);
00194     } else {
00195       gnc_gconf_unset(HISTORY_STRING_SECTION, to, NULL);
00196     }
00197     g_free(to);
00198     to = from;
00199   }
00200 
00201   /*
00202    * Store the new zero entry.
00203    */
00204   gnc_gconf_set_string(HISTORY_STRING_SECTION, to, newfile, NULL);
00205   g_free(to);
00206 }

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. Since the "list" is actually a sequence of up to ten gconf keys, this is the value of key zero.

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

00252 {
00253   char *filename, *key;
00254 
00255   key = gnc_history_gconf_index_to_key(0);
00256   filename = gnc_gconf_get_string(HISTORY_STRING_SECTION, key, NULL);
00257   g_free(key);
00258 
00259   return filename;
00260 }

void gnc_history_remove_file ( const char *  filename  ) 

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:
filename The name of the file to remove from the list.

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

00216 {
00217   gchar *filename, *from, *to;
00218   gint i, j;
00219 
00220   if (!oldfile)
00221     return;
00222   if (!g_utf8_validate(oldfile, -1, NULL))
00223     return;
00224 
00225   for (i=0, j=0; i<MAX_HISTORY_FILES; i++) {
00226     from = gnc_history_gconf_index_to_key(i);
00227     filename = gnc_gconf_get_string(HISTORY_STRING_SECTION, from, NULL);
00228 
00229     if (filename) {
00230       if (g_utf8_collate(oldfile, filename) == 0) {
00231         gnc_gconf_unset(HISTORY_STRING_SECTION, from, NULL);
00232       } else {
00233         if (i != j) {
00234           to = gnc_history_gconf_index_to_key(j);
00235           gnc_gconf_set_string(HISTORY_STRING_SECTION, to, filename, NULL);
00236           gnc_gconf_unset(HISTORY_STRING_SECTION, from, NULL);
00237           g_free(to);
00238         }
00239         j++;
00240       }
00241     }
00242     g_free(from);
00243   }
00244 }

GType gnc_plugin_file_history_get_type ( void   ) 

Get the type of a file history plugin.

Returns:
A GType.

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

00520 {
00521         static GType gnc_plugin_file_history_type = 0;
00522 
00523         if (gnc_plugin_file_history_type == 0) {
00524                 static const GTypeInfo our_info = {
00525                         sizeof (GncPluginFileHistoryClass),
00526                         NULL,           /* base_init */
00527                         NULL,           /* base_finalize */
00528                         (GClassInitFunc) gnc_plugin_file_history_class_init,
00529                         NULL,           /* class_finalize */
00530                         NULL,           /* class_data */
00531                         sizeof (GncPluginFileHistory),
00532                         0,
00533                         (GInstanceInitFunc) gnc_plugin_file_history_init
00534                 };
00535 
00536                 gnc_plugin_file_history_type =
00537                   g_type_register_static (GNC_TYPE_PLUGIN,
00538                                           "GncPluginFileHistory",
00539                                           &our_info, 0);
00540         }
00541 
00542         return gnc_plugin_file_history_type;
00543 }

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

00612 {
00613         GncPlugin *plugin_page = NULL;
00614 
00615         ENTER("");
00616         plugin_page = GNC_PLUGIN (g_object_new (GNC_TYPE_PLUGIN_FILE_HISTORY, NULL));
00617         LEAVE("plugin %p", plugin_page);
00618         return plugin_page;
00619 }


Generated on Thu Jul 3 05:07:19 2008 for GnuCash by  doxygen 1.5.2