2006-11-13 08:33:07 +00:00
|
|
|
/*
|
2010-05-19 11:11:26 +01:00
|
|
|
* Copyright (c) 2009, 2010 Intel, Inc.
|
|
|
|
* Copyright (c) 2010 Red Hat, Inc.
|
2006-11-13 08:33:07 +00:00
|
|
|
*
|
2010-05-19 11:11:26 +01:00
|
|
|
* The Control Center 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.
|
2006-11-13 08:33:07 +00:00
|
|
|
*
|
2010-05-19 11:11:26 +01:00
|
|
|
* The Control Center 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.
|
2006-11-13 08:33:07 +00:00
|
|
|
*
|
2010-05-19 11:11:26 +01:00
|
|
|
* 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
|
2006-11-13 08:33:07 +00:00
|
|
|
*
|
2010-05-19 11:11:26 +01:00
|
|
|
* Author: Thomas Wood <thos@gnome.org>
|
2006-11-13 08:33:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2010-05-24 22:48:34 +01:00
|
|
|
#include <glib/gi18n.h>
|
2010-12-02 19:17:38 +00:00
|
|
|
#include <stdlib.h>
|
2010-05-24 22:48:34 +01:00
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
#include "gnome-control-center.h"
|
|
|
|
|
2006-11-13 08:33:07 +00:00
|
|
|
#include <gtk/gtk.h>
|
2010-05-19 11:11:26 +01:00
|
|
|
#include <string.h>
|
2006-11-13 08:33:07 +00:00
|
|
|
|
2011-03-22 16:46:55 +00:00
|
|
|
#include "cc-shell-log.h"
|
|
|
|
|
2010-12-02 19:17:38 +00:00
|
|
|
G_GNUC_NORETURN static gboolean
|
|
|
|
option_version_cb (const gchar *option_name,
|
|
|
|
const gchar *value,
|
|
|
|
gpointer data,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_print ("%s %s\n", PACKAGE, VERSION);
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char **start_panels = NULL;
|
|
|
|
static gboolean show_overview = FALSE;
|
2011-03-22 16:46:55 +00:00
|
|
|
static gboolean verbose = FALSE;
|
2011-04-07 21:18:06 -04:00
|
|
|
static gboolean show_help = FALSE;
|
2011-06-10 17:23:23 +01:00
|
|
|
static gboolean show_help_gtk = FALSE;
|
|
|
|
static gboolean show_help_all = FALSE;
|
2010-12-02 19:17:38 +00:00
|
|
|
|
|
|
|
const GOptionEntry all_options[] = {
|
|
|
|
{ "version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_version_cb, NULL, NULL },
|
2011-03-22 16:46:55 +00:00
|
|
|
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, N_("Enable verbose mode"), NULL },
|
2011-02-02 20:35:54 +01:00
|
|
|
{ "overview", 'o', 0, G_OPTION_ARG_NONE, &show_overview, N_("Show the overview"), NULL },
|
2011-06-10 17:23:23 +01:00
|
|
|
{ "help", 'h', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &show_help, N_("Show help options"), NULL },
|
|
|
|
{ "help-all", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &show_help_all, N_("Show help options"), NULL },
|
|
|
|
{ "help-gtk", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &show_help_gtk, N_("Show help options"), NULL },
|
2011-02-02 20:35:54 +01:00
|
|
|
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &start_panels, N_("Panel to display"), NULL },
|
2010-12-02 19:17:38 +00:00
|
|
|
{ NULL } /* end the list */
|
|
|
|
};
|
2010-10-22 14:08:11 +01:00
|
|
|
|
2010-10-29 15:55:40 +01:00
|
|
|
static int
|
2010-10-22 14:08:11 +01:00
|
|
|
application_command_line_cb (GApplication *application,
|
2010-12-02 19:17:38 +00:00
|
|
|
GApplicationCommandLine *command_line,
|
|
|
|
GnomeControlCenter *shell)
|
2009-08-08 15:07:16 +02:00
|
|
|
{
|
2010-10-22 14:08:11 +01:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
2010-10-29 15:55:40 +01:00
|
|
|
int retval = 0;
|
2010-12-02 19:17:38 +00:00
|
|
|
GOptionContext *context;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2011-04-07 21:18:06 -04:00
|
|
|
verbose = FALSE;
|
|
|
|
show_overview = FALSE;
|
|
|
|
show_help = FALSE;
|
|
|
|
start_panels = NULL;
|
|
|
|
|
2010-12-02 19:17:38 +00:00
|
|
|
argv = g_application_command_line_get_arguments (command_line, &argc);
|
|
|
|
|
|
|
|
context = g_option_context_new (N_("- System Settings"));
|
|
|
|
g_option_context_add_main_entries (context, all_options, GETTEXT_PACKAGE);
|
|
|
|
g_option_context_set_translation_domain(context, GETTEXT_PACKAGE);
|
|
|
|
g_option_context_add_group (context, gtk_get_option_group (TRUE));
|
2011-04-07 21:18:06 -04:00
|
|
|
g_option_context_set_help_enabled (context, FALSE);
|
2010-12-02 19:17:38 +00:00
|
|
|
|
|
|
|
if (g_option_context_parse (context, &argc, &argv, &error) == FALSE)
|
|
|
|
{
|
|
|
|
g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
|
|
|
|
error->message, argv[0]);
|
|
|
|
g_error_free (error);
|
|
|
|
g_option_context_free (context);
|
2011-04-07 21:18:06 -04:00
|
|
|
return 1;
|
2010-12-02 19:17:38 +00:00
|
|
|
}
|
2011-04-07 21:18:06 -04:00
|
|
|
|
2011-06-10 17:23:23 +01:00
|
|
|
if (show_help || show_help_all || show_help_gtk)
|
2011-04-07 21:18:06 -04:00
|
|
|
{
|
|
|
|
gchar *help;
|
2011-06-10 17:23:23 +01:00
|
|
|
GOptionGroup *group;
|
2011-04-07 21:18:06 -04:00
|
|
|
|
2011-06-10 17:23:23 +01:00
|
|
|
if (show_help || show_help_all)
|
|
|
|
group = NULL;
|
|
|
|
else
|
|
|
|
group = gtk_get_option_group (FALSE);
|
|
|
|
|
|
|
|
help = g_option_context_get_help (context, FALSE, group);
|
2011-05-20 12:27:05 +02:00
|
|
|
g_print ("%s", help);
|
2011-04-07 21:18:06 -04:00
|
|
|
g_free (help);
|
|
|
|
g_option_context_free (context);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-02 19:17:38 +00:00
|
|
|
g_option_context_free (context);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2011-03-22 16:46:55 +00:00
|
|
|
cc_shell_log_set_debug (verbose);
|
|
|
|
|
2010-11-19 15:08:23 -05:00
|
|
|
gnome_control_center_show (shell, GTK_APPLICATION (application));
|
|
|
|
|
2010-12-02 19:17:38 +00:00
|
|
|
if (show_overview)
|
|
|
|
{
|
|
|
|
gnome_control_center_set_overview_page (shell);
|
|
|
|
}
|
|
|
|
else if (start_panels != NULL && start_panels[0] != NULL)
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2010-12-02 19:17:38 +00:00
|
|
|
const char *start_id;
|
2010-05-19 11:11:26 +01:00
|
|
|
GError *err = NULL;
|
2010-07-12 18:07:47 +01:00
|
|
|
|
2010-12-02 19:17:38 +00:00
|
|
|
start_id = start_panels[0];
|
2010-10-22 14:08:11 +01:00
|
|
|
|
|
|
|
if (!cc_shell_set_active_panel_from_id (CC_SHELL (shell), start_id, &err))
|
2010-05-19 11:11:26 +01:00
|
|
|
{
|
2010-10-22 14:08:11 +01:00
|
|
|
g_warning ("Could not load setting panel \"%s\": %s", start_id,
|
|
|
|
(err) ? err->message : "Unknown error");
|
2010-10-29 15:55:40 +01:00
|
|
|
retval = 1;
|
2010-05-19 11:11:26 +01:00
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
g_error_free (err);
|
2010-10-22 14:08:11 +01:00
|
|
|
err = NULL;
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-19 15:08:23 -05:00
|
|
|
|
|
|
|
gnome_control_center_present (shell);
|
2011-03-29 13:48:58 +01:00
|
|
|
gdk_notify_startup_complete ();
|
2010-11-19 15:08:23 -05:00
|
|
|
|
2010-10-22 14:08:11 +01:00
|
|
|
g_strfreev (argv);
|
2010-12-02 19:17:38 +00:00
|
|
|
if (start_panels != NULL)
|
|
|
|
{
|
|
|
|
g_strfreev (start_panels);
|
|
|
|
start_panels = NULL;
|
|
|
|
}
|
|
|
|
show_overview = FALSE;
|
|
|
|
|
2010-10-29 15:55:40 +01:00
|
|
|
return retval;
|
2010-10-22 14:08:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
application_startup_cb (GApplication *application,
|
2010-12-02 19:17:38 +00:00
|
|
|
GnomeControlCenter *shell)
|
2010-10-22 14:08:11 +01:00
|
|
|
{
|
2010-11-19 15:08:23 -05:00
|
|
|
/* nothing to do here, we don't want to show a window before
|
|
|
|
* we've looked at the commandline
|
|
|
|
*/
|
2009-08-08 15:07:16 +02:00
|
|
|
}
|
|
|
|
|
2006-11-13 08:33:07 +00:00
|
|
|
int
|
2010-05-19 11:11:26 +01:00
|
|
|
main (int argc, char **argv)
|
2006-11-13 08:33:07 +00:00
|
|
|
{
|
2010-05-19 11:11:26 +01:00
|
|
|
GnomeControlCenter *shell;
|
2010-06-20 22:07:05 +01:00
|
|
|
GtkApplication *application;
|
2010-10-22 14:08:11 +01:00
|
|
|
int status;
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2010-05-24 22:48:34 +01:00
|
|
|
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
|
|
|
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
|
|
textdomain (GETTEXT_PACKAGE);
|
|
|
|
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
g_thread_init (NULL);
|
|
|
|
gtk_init (&argc, &argv);
|
2011-03-22 16:46:55 +00:00
|
|
|
cc_shell_log_init ();
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2011-05-20 12:28:27 -04:00
|
|
|
/* register a symbolic icon size for use in sidebar lists */
|
|
|
|
gtk_icon_size_register ("cc-sidebar-list", 24, 24);
|
|
|
|
|
2010-05-19 11:11:26 +01:00
|
|
|
shell = gnome_control_center_new ();
|
|
|
|
|
2010-06-20 22:07:05 +01:00
|
|
|
/* enforce single instance of this application */
|
2010-10-22 14:08:11 +01:00
|
|
|
application = gtk_application_new ("org.gnome.ControlCenter", G_APPLICATION_HANDLES_COMMAND_LINE);
|
|
|
|
g_signal_connect (application, "startup",
|
|
|
|
G_CALLBACK (application_startup_cb), shell);
|
|
|
|
g_signal_connect (application, "command-line",
|
|
|
|
G_CALLBACK (application_command_line_cb), shell);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2010-10-22 14:08:11 +01:00
|
|
|
status = g_application_run (G_APPLICATION (application), argc, argv);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2010-06-20 22:07:05 +01:00
|
|
|
g_object_unref (application);
|
2010-05-19 11:11:26 +01:00
|
|
|
|
2010-10-22 14:08:11 +01:00
|
|
|
return status;
|
2010-05-19 11:11:26 +01:00
|
|
|
}
|