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
|
/***************************************************************************
* Copyright (C) 2010~2012 by CSSlayer *
* *
* This program 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. *
***************************************************************************/
#include <gtk/gtk.h>
#include <langinfo.h>
#include <libintl.h>
#include <locale.h>
#include "config.h"
#include "main_window.h"
#include "config_widget.h"
#include "fcitx-config-gtk3-resources.h"
static void
fcitx_config_app_activate (GApplication *application)
{
GList* list = gtk_application_get_windows (GTK_APPLICATION(application));
if (list)
{
gtk_window_present (GTK_WINDOW (list->data));
}
else {
GtkWidget *window;
window = fcitx_main_window_new();
gtk_application_add_window(GTK_APPLICATION(application), GTK_WINDOW(window));
gtk_widget_show_all (GTK_WIDGET (window));
}
}
typedef GtkApplication FcitxConfigApp;
typedef GtkApplicationClass FcitxConfigAppClass;
G_DEFINE_TYPE (FcitxConfigApp, fcitx_config_app, GTK_TYPE_APPLICATION)
static void
fcitx_config_app_finalize (GObject *object)
{
G_OBJECT_CLASS (fcitx_config_app_parent_class)->finalize (object);
}
static void
fcitx_config_app_init (FcitxConfigApp *app)
{
fcitx_config_gtk3_register_resource();
g_resources_register (fcitx_config_gtk3_get_resource ());
}
int fcitx_config_app_handle_command_line (GApplication *application,
GApplicationCommandLine *command_line,
gpointer user_data
)
{
int argc;
gchar** argv = g_application_command_line_get_arguments(command_line, &argc);
g_application_activate(G_APPLICATION (application));
GList* list = gtk_application_get_windows (GTK_APPLICATION(application));
if (list) {
FcitxMainWindow* mainWindow = FCITX_MAIN_WINDOW (list->data);
FcitxAddon* addon = NULL;
if (argc >= 2 && argv[1])
addon = find_addon_by_name(mainWindow->addons, argv[1]);
if (addon) {
GtkWidget* dialog = fcitx_config_dialog_new(addon, GTK_WINDOW(mainWindow));
if (dialog)
gtk_widget_show_all(GTK_WIDGET(dialog));
}
}
g_strfreev(argv);
return 0;
}
static void
fcitx_config_app_class_init (FcitxConfigAppClass *klass)
{
G_OBJECT_CLASS (klass)->finalize= fcitx_config_app_finalize;
G_APPLICATION_CLASS (klass)->activate = fcitx_config_app_activate;
}
FcitxConfigApp *
fcitx_config_app_new (void)
{
#if !GLIB_CHECK_VERSION(2, 35, 1)
g_type_init();
#endif
FcitxConfigApp* app = g_object_new (fcitx_config_app_get_type (),
"application-id", "org.fcitx.FcitxConfigGtk3",
"flags", G_APPLICATION_HANDLES_COMMAND_LINE,
NULL);
g_signal_connect(app, "command-line", (GCallback)fcitx_config_app_handle_command_line, NULL);
return app;
}
int
main(int argc, char **argv)
{
setlocale(LC_ALL, "");
bindtextdomain("fcitx-configtool", LOCALEDIR);
bind_textdomain_codeset("fcitx-configtool", "UTF-8");
bindtextdomain("fcitx", LOCALEDIR);
bind_textdomain_codeset("fcitx", "UTF-8");
textdomain("fcitx-configtool");
FcitxLogSetLevel(FCITX_NONE);
GtkApplication* app = fcitx_config_app_new();
int status = 0;
if (app) {
GError* error = NULL;
if (!g_application_register(G_APPLICATION(app), NULL, &error)) {
g_warning("Cannot register %s", error->message);
g_error_free(error);
error = NULL;
}
if (g_application_get_is_registered(G_APPLICATION(app))) {
if (g_application_get_is_remote(G_APPLICATION(app))) {
g_message("fcitx-config-gtk3 is running.");
}
}
}
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
|