aboutsummaryrefslogtreecommitdiff
path: root/src/application-service-lru-file.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-01-20 11:14:21 -0600
committerTed Gould <ted@gould.cx>2010-01-20 11:14:21 -0600
commitc663b234f90d1b6b5c5eea53d309d5295342b1e0 (patch)
tree368d86b6f3d1ef3804c5687d6984ef176f35b6b3 /src/application-service-lru-file.c
parenta634890d9684f87b796670c89383066bb674863d (diff)
downloadayatana-indicator-application-c663b234f90d1b6b5c5eea53d309d5295342b1e0.tar.gz
ayatana-indicator-application-c663b234f90d1b6b5c5eea53d309d5295342b1e0.tar.bz2
ayatana-indicator-application-c663b234f90d1b6b5c5eea53d309d5295342b1e0.zip
Allocating memory and objects in the lur world
Diffstat (limited to 'src/application-service-lru-file.c')
-rw-r--r--src/application-service-lru-file.c69
1 files changed, 68 insertions, 1 deletions
diff --git a/src/application-service-lru-file.c b/src/application-service-lru-file.c
index 47cfab9..a041453 100644
--- a/src/application-service-lru-file.c
+++ b/src/application-service-lru-file.c
@@ -6,7 +6,18 @@
typedef struct _AppLruFilePrivate AppLruFilePrivate;
struct _AppLruFilePrivate {
- gint temp;
+ GHashTable * apps;
+ gboolean dirty;
+ guint timer;
+ gchar * filename;
+};
+
+typedef struct _AppData AppData;
+struct _AppData {
+ gchar * id;
+ gchar * category;
+ GTimeVal last_touched;
+ GTimeVal first_touched;
};
#define APP_LRU_FILE_GET_PRIVATE(o) \
@@ -16,9 +27,12 @@ static void app_lru_file_class_init (AppLruFileClass *klass);
static void app_lru_file_init (AppLruFile *self);
static void app_lru_file_dispose (GObject *object);
static void app_lru_file_finalize (GObject *object);
+static void app_data_free (gpointer data);
+static gboolean load_from_file (gpointer data);
G_DEFINE_TYPE (AppLruFile, app_lru_file, G_TYPE_OBJECT);
+/* Set up the class variable stuff */
static void
app_lru_file_class_init (AppLruFileClass *klass)
{
@@ -32,29 +46,82 @@ app_lru_file_class_init (AppLruFileClass *klass)
return;
}
+/* Set all the data of the per-instance variables */
static void
app_lru_file_init (AppLruFile *self)
{
+ AppLruFilePrivate * priv = APP_LRU_FILE_GET_PRIVATE(self);
+
+ /* Default values */
+ priv->apps = NULL;
+ priv->dirty = FALSE;
+ priv->timer = 0;
+ priv->filename = NULL;
+
+ /* Now let's build some stuff */
+ priv->apps = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, app_data_free);
+ priv->filename = g_build_filename(g_get_user_config_dir(), "indicators", "application", "lru-file.json", NULL);
+
+ /* No reason to delay other stuff for this, we'll
+ merge any values that get touched. */
+ g_idle_add(load_from_file, self);
return;
}
+/* Get rid of objects and other big things */
static void
app_lru_file_dispose (GObject *object)
{
+ AppLruFilePrivate * priv = APP_LRU_FILE_GET_PRIVATE(object);
+
+ if (priv->timer != 0) {
+ g_source_remove(priv->timer);
+ priv->timer = 0;
+ }
+
+ if (priv->apps != NULL) {
+ /* Cleans up the keys and entries itself */
+ g_hash_table_destroy(priv->apps);
+ priv->apps = NULL;
+ }
G_OBJECT_CLASS (app_lru_file_parent_class)->dispose (object);
return;
}
+/* Deallocate memory */
static void
app_lru_file_finalize (GObject *object)
{
+ AppLruFilePrivate * priv = APP_LRU_FILE_GET_PRIVATE(object);
+
+ if (priv->filename != NULL) {
+ g_free(priv->filename);
+ priv->filename = NULL;
+ }
G_OBJECT_CLASS (app_lru_file_parent_class)->finalize (object);
return;
}
+/* Takes an AppData structure and free's the
+ memory from it. */
+static void
+app_data_free (gpointer data)
+{
+
+ return;
+}
+
+/* Loads all of the data out of a json file */
+static gboolean
+load_from_file (gpointer data)
+{
+
+ return FALSE;
+}
+
/* API */
/* Simple helper to create a new object */