]> icculus.org git repositories - dana/openbox.git/blob - obt/linkbase.c
Add linkbase which will keep track of available .desktop files for application launch...
[dana/openbox.git] / obt / linkbase.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2  
3    obt/linkbase.c for the Openbox window manager
4    Copyright (c) 2010        Dana Jansens
5  
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10  
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15  
16    See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #include "obt/linkbase.h"
20 #include "obt/link.h"
21 #include "obt/paths.h"
22 #include "obt/watch.h"
23
24 struct _ObtLinkBase {
25     gint ref;
26
27     ObtWatch *watch;
28     GHashTable *base;
29 };
30
31 static void func(ObtWatch *w, const gchar *subpath, ObtWatchNotifyType type,
32                  gpointer data)
33 {
34 }
35
36 ObtLinkBase* obt_linkbase_new(ObtPaths *paths)
37 {
38     ObtLinkBase *b;
39     GSList *it;
40     
41     b = g_slice_new(ObtLinkBase);
42     b->watch = obt_watch_new();
43     b->base = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
44                                     (GDestroyNotify)obt_link_unref);
45
46     for (it = obt_paths_data_dirs(paths); it; it = g_slist_next(it)) {
47         gchar *p;
48         p = g_strconcat(it->data, "/applications", NULL);
49         obt_watch_add(b->watch, p, FALSE, func, b);
50     }
51     return b;
52 }
53
54 void obt_linkbase_ref(ObtLinkBase *lb)
55 {
56     ++lb->ref;
57 }
58
59 void obt_linkbase_unref(ObtLinkBase *lb)
60 {
61     if (--lb->ref < 1) {
62         obt_watch_unref(lb->watch);
63         g_hash_table_unref(lb->base);
64         g_slice_free(ObtLinkBase, lb);
65     }
66 }