aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-01-20 11:59:33 -0600
committerTed Gould <ted@gould.cx>2010-01-20 11:59:33 -0600
commit77f24c0cb4e46ea88a4594bd63875691c25234e4 (patch)
tree7b16fd761519d0f5a86852a46cfaeabd0f069b26 /src
parent064fd75a5fe489e03bba5b99ed170401d2fa1def (diff)
downloadlibayatana-appindicator-77f24c0cb4e46ea88a4594bd63875691c25234e4.tar.gz
libayatana-appindicator-77f24c0cb4e46ea88a4594bd63875691c25234e4.tar.bz2
libayatana-appindicator-77f24c0cb4e46ea88a4594bd63875691c25234e4.zip
Making a sort function that looks at two Apps and determines their ordering.
Diffstat (limited to 'src')
-rw-r--r--src/application-service-lru-file.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/application-service-lru-file.c b/src/application-service-lru-file.c
index 45fe9db..fd0b7ed 100644
--- a/src/application-service-lru-file.c
+++ b/src/application-service-lru-file.c
@@ -167,7 +167,9 @@ app_lru_file_touch (AppLruFile * lrufile, const gchar * id, const gchar * catego
appdata = (AppData *)data;
}
+ /* Touch it and mark the DB as dirty */
g_get_current_time(&(appdata->last_touched));
+ /* TODO: Make dirty */
return;
}
@@ -177,6 +179,48 @@ app_lru_file_sort (AppLruFile * lrufile, const gchar * id_a, const gchar * id_b)
{
g_return_val_if_fail(IS_APP_LRU_FILE(lrufile), -1);
+ /* Let's first look to see if the IDs are the same, this
+ really shouldn't happen, but it'll be confusing if we
+ don't get it out of the way to start. */
+ if (g_strcmp0(id_a, id_b) == 0) {
+ return 0;
+ }
+
+ AppLruFilePrivate * priv = APP_LRU_FILE_GET_PRIVATE(lrufile);
+
+ /* Now make sure we have app data for both of these. If
+ not we'll assume that the one without is newer? */
+ gpointer data_a = g_hash_table_lookup(priv->apps, id_a);
+ if (data_a == NULL) {
+ return -1;
+ }
+
+ gpointer data_b = g_hash_table_lookup(priv->apps, id_b);
+ if (data_b == NULL) {
+ return 1;
+ }
+
+ /* Ugly casting */
+ AppData * appdata_a = (AppData *)data_a;
+ AppData * appdata_b = (AppData *)data_b;
+
+ /* Look at categories, we'll put the categories in alpha
+ order if they're not the same. */
+ gint catcompare = g_strcmp0(appdata_a->category, appdata_b->category);
+ if (catcompare != 0) {
+ return catcompare;
+ }
+
+ /* Now we're looking at the first time that these two were
+ seen in this account. Only using seconds. I mean, seriously. */
+ if (appdata_a->first_touched.tv_sec < appdata_b->first_touched.tv_sec) {
+ return -1;
+ }
+ if (appdata_b->first_touched.tv_sec < appdata_a->first_touched.tv_sec) {
+ return 1;
+ }
- return 0;
+ /* Eh, this seems roughly impossible. But if we have to choose,
+ I like A better. */
+ return 1;
}