summaryrefslogtreecommitdiff
path: root/null_applet/null_applet.c
blob: c1a873b0e3cb4fe96407313d8b15e3dc514cbb13 (plain)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* -*- mode: C; c-basic-offset: 4 -*-
 * Null Applet - The Applet Deprecation Applet
 * Copyright (c) 2004, Davyd Madeley
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author:
 *   Davyd Madeley <davyd@madeley.id.au>
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <gtk/gtk.h>
#include <mateconf/mateconf-client.h>
#include <mate-panel-applet.h>

static const char factory_iid[] = "OAFIID:MATE_NullApplet_Factory";

static inline void
insert_oafiids (GHashTable *hash_table)
{
	/*
	 * Add OAFIID's and descriptions of deprecated applets here
	 */
	g_hash_table_insert (hash_table,
			     "OAFIID:MATE_MailcheckApplet", _("Inbox Monitor"));
	g_hash_table_insert (hash_table,
			     "OAFIID:MATE_CDPlayerApplet", _("CD Player"));
	g_hash_table_insert (hash_table,
			     "OAFIID:MATE_MixerApplet_Factory", _("Volume Control"));
	g_hash_table_insert (hash_table,
			     "OAFIID:MATE_MixerApplet", _("Volume Control"));
	g_hash_table_insert (hash_table,
			     "OAFIID:MATE_KeyboardApplet", _("Keyboard Indicator"));
}

static gboolean already_running;

static void
response_cb (GtkWidget *dialog, gint arg1, gpointer user_data)
{
	gtk_widget_destroy (dialog);
}

static char
*get_all_applets (void)
{
	MateConfClient *client;
	GError *error;
	GSList *list, *l;
	char *key, *oafiid, *name;
	GHashTable *hash_table;
	GString *string;

	error = NULL;
	hash_table = g_hash_table_new (g_str_hash, g_str_equal);
	insert_oafiids (hash_table);

	string = g_string_new ("");

	client = mateconf_client_get_default ();

	mateconf_client_suggest_sync (client, NULL);
	
	list = mateconf_client_all_dirs (client,
		"/apps/panel/applets",
		&error);

	if (error)
	{
		g_warning ("Error: %s", error->message);
		g_error_free (error);
		error = NULL;
	}

	for (l = list; l; l = l->next)
	{
	    key = g_strdup_printf ("%s/matecomponent_iid", (gchar *)l->data);
		oafiid = mateconf_client_get_string (client, key, &error);
		if (error)
		{
			g_warning ("Error: %s", error->message);
			g_error_free (error);
			error = NULL;
		}
		g_free (key);
	
		if (oafiid)
		{
			name = g_hash_table_lookup (hash_table, oafiid);
			if (name)
			{
				mateconf_client_recursive_unset (client, l->data,
					MATECONF_UNSET_INCLUDING_SCHEMA_NAMES,
					&error);
				if (error)
				{
					g_warning ("Error: %s", error->message);
					g_error_free (error);
					error = NULL;
				}
				g_string_append_printf (string,
						"    • %s\n", name);
			}
			g_free (oafiid);
		}
		g_free (l->data);
	}

	g_slist_free (list);
	g_hash_table_destroy (hash_table);
	
	return g_string_free (string, FALSE);
}

static gboolean
applet_factory (MatePanelApplet *applet,
		const char  *iid,
		gpointer     user_data)
{
	char *applet_list;
	GtkWidget *dialog;

	if (already_running)
	{
		return FALSE;
	}
	already_running = TRUE;

	applet_list = get_all_applets ();

	dialog = gtk_message_dialog_new_with_markup (NULL,
			GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
			GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
			"<span size=\"large\" weight=\"bold\">%s</span>"
			"\n\n%s\n\n%s\n%s\n%s",
			_("Some panel items are no longer available"),
			_("One or more panel items (also referred to as applets"
			  ") are no longer available in the MATE desktop."),
			_("These items will now be removed from your "
			  "configuration:"),
			applet_list,
			_("You will not receive this message again.")
			);

	g_free (applet_list);

	g_signal_connect (G_OBJECT (dialog), "response",
			G_CALLBACK (response_cb), applet);
	
	gtk_widget_show_all (dialog);
		
	return TRUE;
}

MATE_PANEL_APPLET_MATECOMPONENT_FACTORY (factory_iid,
		PANEL_TYPE_APPLET,
		"Null-Applet", "0",
		applet_factory, NULL)