File: application-browser.c

package info (click to toggle)
gnome-main-menu 1.8.0-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,748 kB
  • ctags: 724
  • sloc: ansic: 4,394; makefile: 150; sh: 17; xml: 2
file content (113 lines) | stat: -rw-r--r-- 3,514 bytes parent folder | download | duplicates (2)
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
/*
 * This file is part of the Application Browser.
 *
 * Copyright (c) 2006 Novell, Inc.
 *
 * The Application Browser 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.
 *
 * The Application Browser 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
 * the Control Center; if not, write to the Free Software Foundation, Inc., 51
 * Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "config.h"

#include <string.h>

#include <gtk/gtk.h>
#include <unique/unique.h>
#include <stdlib.h>
#include <glib/gi18n.h>
#include <gio/gio.h>
#include <libmate-slab/slab.h>

#define APPLICATION_BROWSER_SCHEMA  "org.mate.gnome-main-menu.application-browser"
#define NEW_APPS_MAX_ITEMS          "new-apps-max-items"

static UniqueResponse
unique_app_message_cb (UniqueApp *app, gint command, UniqueMessageData *data,
		       guint time, gpointer user_data)
{
	AppShellData *app_data = user_data;

	if (command != UNIQUE_ACTIVATE)
		return UNIQUE_RESPONSE_PASSTHROUGH;

	/* move the main window to the screen that sent us the command */
	gtk_window_set_screen (GTK_WINDOW (app_data->main_app),
			       unique_message_data_get_screen (data));
	if (!app_data->main_app_window_shown_once)
		show_shell (app_data);

	gtk_window_present_with_time (GTK_WINDOW (app_data->main_app), time);
	gtk_widget_grab_focus (SLAB_SECTION (app_data->filter_section)->contents);

	return UNIQUE_RESPONSE_OK;
}

int
main (int argc, char *argv[])
{
	UniqueApp *unique_app = NULL;
	gboolean hidden = FALSE;
	GError *error;
	GOptionEntry options[] = {
	  { "hide", 0, 0, G_OPTION_ARG_NONE, &hidden, N_("Hide on start (useful to preload the shell)"), NULL },
	  { NULL }
	};

#ifdef ENABLE_NLS
	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
#endif

	error = NULL;
	if (!gtk_init_with_args (&argc, &argv,
				 NULL, options, GETTEXT_PACKAGE, &error)) {
		g_printerr ("%s\n", error->message);
		g_error_free (error);
		return 1;
	}

	unique_app = unique_app_new ("org.gnome.MainMenu", NULL);

	if (unique_app_is_running (unique_app))
	{
		unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL);
		g_object_unref (unique_app);

		return 0;
	}

	//NewAppConfig *config = g_new0 (NewAppConfig, 1);
	GSettings *settings = g_settings_new (APPLICATION_BROWSER_SCHEMA);
	gint max_items = g_settings_get_int (settings, NEW_APPS_MAX_ITEMS);
	g_object_unref (settings);
	//config->name = _("New Applications");
	AppShellData *app_data = appshelldata_new ("mate-applications.menu",
		GTK_ICON_SIZE_DND, TRUE, FALSE, max_items);
	generate_categories (app_data);

	layout_shell (app_data, _("Filter"), _("Groups"), _("Application Actions"), NULL, NULL);

	create_main_window (app_data, "MyApplicationBrowser", _("Application Browser"),
		"gnome-fs-client", 940, 600, hidden);

	unique_app_watch_window (unique_app, GTK_WINDOW (app_data->main_app));
	g_signal_connect (unique_app, "message-received", G_CALLBACK (unique_app_message_cb), app_data);

	gtk_main ();

	g_object_unref (unique_app);

	return 0;
};