1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/*
* Copyright (C) 2013 Collabora Ltd.
*
* Author: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
*/
#include "config.h"
#include "favorites.h"
#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
#include <gtk/gtk.h>
#include "app-icon.h"
enum {
PROP_0,
};
struct WestonGtkFavoritesPrivate {
GSettings *settings;
};
G_DEFINE_TYPE(WestonGtkFavorites, weston_gtk_favorites, GTK_TYPE_BOX)
static void
favorite_clicked (GtkButton *button,
WestonGtkFavorites *self)
{
GAppInfo *info = g_object_get_data (G_OBJECT(button), "info");
GError *error = NULL;
g_app_info_launch (info, NULL, NULL, &error);
if (error)
{
g_warning ("Could not launch app %s: %s",
g_app_info_get_name (info),
error->message);
g_clear_error (&error);
}
}
static void
add_favorite (WestonGtkFavorites *self,
const gchar *favorite)
{
GDesktopAppInfo *info;
GtkWidget *button, *image;
GIcon *icon;
info = g_desktop_app_info_new (favorite);
if (!info)
return;
icon = g_app_info_get_icon (G_APP_INFO (info));
button = weston_gtk_app_icon_new_from_gicon (icon);
g_object_set_data_full (G_OBJECT (button), "info", info, g_object_unref);
g_signal_connect (button, "clicked", G_CALLBACK (favorite_clicked), self);
gtk_box_pack_end (GTK_BOX (self), button, FALSE, FALSE, 0);
}
static void
remove_favorite (GtkWidget *favorite,
gpointer user_data)
{
gtk_widget_destroy (favorite);
}
static void
favorites_changed (GSettings *settings,
const gchar *key,
WestonGtkFavorites *self)
{
gchar **favorites = g_settings_get_strv (settings, key);
gint i;
/* Remove all favorites first */
gtk_container_foreach (GTK_CONTAINER (self), remove_favorite, NULL);
for (i = 0; i < g_strv_length (favorites); i++)
{
gchar *fav = favorites[i];
add_favorite (self, fav);
}
g_strfreev (favorites);
}
static void
weston_gtk_favorites_dispose (GObject *object)
{
WestonGtkFavorites *self = WESTON_GTK_FAVORITES (object);
g_clear_object (&self->priv->settings);
G_OBJECT_CLASS (weston_gtk_favorites_parent_class)->dispose (object);
}
static void
weston_gtk_favorites_init (WestonGtkFavorites *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
WESTON_GTK_TYPE_FAVORITES,
WestonGtkFavoritesPrivate);
self->priv->settings = g_settings_new ("org.raspberrypi.maynard");
g_signal_connect (self->priv->settings, "changed::favorites",
G_CALLBACK (favorites_changed), self);
favorites_changed (self->priv->settings, "favorites", self);
gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL);
}
static void
weston_gtk_favorites_class_init (WestonGtkFavoritesClass *klass)
{
GObjectClass *object_class = (GObjectClass *)klass;
object_class->dispose = weston_gtk_favorites_dispose;
g_type_class_add_private (object_class, sizeof (WestonGtkFavoritesPrivate));
}
GtkWidget *
weston_gtk_favorites_new (void)
{
return g_object_new (WESTON_GTK_TYPE_FAVORITES,
"orientation", GTK_ORIENTATION_VERTICAL,
NULL);
}
|