static gboolean gw_application_local_command_line (GApplication *application, gchar ***argv, gint *exit_status) { //Declarations int argc; gboolean handled; int i; //Initializations argc = g_strv_length (*argv); handled = FALSE; for (i = 0; (*argv)[i] != NULL; i++) { if (strcmp((*argv)[i], "-v") == 0 || strcmp((*argv)[i], "--version") == 0) { gw_application_print_about (GW_APPLICATION (application)); handled = TRUE; break; } else if (strcmp((*argv)[i], "-h") == 0 || strcmp((*argv)[i], "--help") == 0) { handled = TRUE; gw_application_parse_args (GW_APPLICATION (application), &argc, argv); break; } } return handled; }
static void gw_application_activate (GApplication *application) { GwApplicationPrivate *priv; GwSearchWindow *searchwindow; GwVocabularyWindow *vocabularywindow; GwSettingsWindow *settingswindow; GwDictionaryList *dictionarylist; priv = GW_APPLICATION (application)->priv; dictionarylist = gw_application_get_installed_dictionarylist (GW_APPLICATION (application)); if (priv->arg_new_vocabulary_window_switch) { vocabularywindow = GW_VOCABULARYWINDOW (gw_vocabularywindow_new (GTK_APPLICATION (application))); gtk_widget_show (GTK_WIDGET (vocabularywindow)); return; } else { searchwindow = GW_SEARCHWINDOW (gw_searchwindow_new (GTK_APPLICATION (application))); gtk_widget_show (GTK_WIDGET (searchwindow)); if (lw_dictionarylist_get_total (LW_DICTIONARYLIST (dictionarylist)) == 0) { settingswindow = GW_SETTINGSWINDOW (gw_settingswindow_new (GTK_APPLICATION (application))); gtk_window_set_transient_for (GTK_WINDOW (settingswindow), GTK_WINDOW (searchwindow)); gtk_widget_show (GTK_WIDGET (settingswindow)); } return; } }
static void gw_application_startup (GApplication *application) { G_APPLICATION_CLASS (gw_application_parent_class)->startup (application); gw_application_load_app_menu (GW_APPLICATION (application)); gw_application_load_menubar (GW_APPLICATION (application)); gw_application_attach_signals (GW_APPLICATION (application)); }
static int gw_application_command_line (GApplication *application, GApplicationCommandLine *command_line) { //Declarations LwDictionary *dictionary; GwSearchWindow *window; GwDictionaryList *dictionarylist; GwApplicationPrivate *priv; gint argc; gchar **argv; gint position; //Initializations priv = GW_APPLICATION (application)->priv; dictionarylist = gw_application_get_installed_dictionarylist (GW_APPLICATION (application)); argv = NULL; if (command_line != NULL) { argv = g_application_command_line_get_arguments (command_line, &argc); gw_application_parse_args (GW_APPLICATION (application), &argc, &argv); } g_application_activate (G_APPLICATION (application)); window = gw_application_get_last_focused_searchwindow (GW_APPLICATION (application)); if (window == NULL) return 0; dictionary = lw_dictionarylist_get_dictionary_fuzzy (LW_DICTIONARYLIST (dictionarylist), priv->arg_dictionary); //Set the initial dictionary if (dictionary != NULL) { position = lw_dictionarylist_get_position (LW_DICTIONARYLIST (dictionarylist), dictionary); gw_searchwindow_set_dictionary (window, position); } //Set the initial query text if it was passed as an argument to the program if (priv->arg_query != NULL) { gw_searchwindow_entry_set_text (window, priv->arg_query); gw_searchwindow_search_cb (GTK_WIDGET (window), window); } //Cleanup if (argv != NULL) g_strfreev (argv); argv = NULL; return 0; }
//! //! @brief Searches for the word in a webbrower in an external dictionary //! @param widget Unused GtkWidget pointer //! @param data Unused gpointer //! static void _resultpopup_search_online_cb (GtkMenuItem *widget, gpointer data) { //Sanity check g_assert (data != NULL); //Declarations GwApplication *application; LwSearchItem *item; GError *error; GwSearchWindow *window; GtkTextView *view; GwSearchData *sdata; //Initializations item = LW_SEARCHITEM (data); if (item != NULL) { sdata = GW_SEARCHDATA (lw_searchitem_get_data (item)); window = GW_SEARCHWINDOW (sdata->window); application = GW_APPLICATION (gw_window_get_application (GW_WINDOW (window))); view = gw_searchwindow_get_current_textview (window); sdata = gw_searchdata_new (view, window); lw_searchitem_set_data (item, sdata, LW_SEARCHITEM_DATA_FREE_FUNC (gw_searchdata_free)); error = NULL; printf("%s\n", item->queryline->string); gtk_show_uri (NULL, item->queryline->string, gtk_get_current_event_time (), &error); gw_application_handle_error (application, GTK_WINDOW (window), TRUE, &error); } }
G_MODULE_EXPORT gboolean gw_window_focus_in_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data) { //Declarations GwWindow *window; GwApplication *application; GMenuModel *menumodel; gboolean os_shows_win_menu; GtkSettings *settings; //Initializations window = GW_WINDOW (widget); application = gw_window_get_application (window); settings = gtk_settings_get_default (); g_object_get (settings, "gtk-shell-shows-menubar", &os_shows_win_menu, NULL); menumodel = gw_window_get_transient_for_menumodel (window); if (menumodel == NULL) menumodel = G_MENU_MODEL (g_menu_new ()); if (menumodel == NULL) return FALSE; if (os_shows_win_menu) gw_application_set_win_menubar (GW_APPLICATION (application), menumodel); return FALSE; }
static void gw_window_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { GwWindow *window; GwWindowPrivate *priv; window = GW_WINDOW (object); priv = window->priv; switch (property_id) { case PROP_APPLICATION: priv->application = GW_APPLICATION (g_value_get_object (value)); break; case PROP_UI_XML: if (priv->ui_xml != NULL) g_free (priv->ui_xml); priv->ui_xml = g_value_dup_string (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
static void gw_application_constructed (GObject *object) { //Chain the parent class { G_OBJECT_CLASS (gw_application_parent_class)->constructed (object); } lw_regex_initialize (); gw_application_initialize_accelerators (GW_APPLICATION (object)); /* #ifdef OS_MINGW GtkSettings *settings; settings = gtk_settings_get_default (); if (settings != NULL) { g_object_set (settings, "gtk-theme-name", "Raleigh", NULL); g_object_set (settings, "gtk-menu-images", FALSE, NULL); g_object_set (settings, "gtk-button-images", FALSE, NULL); g_object_set (settings, "gtk-cursor-blink", FALSE, NULL); g_object_set (settings, "gtk-alternative-button-order", TRUE, NULL); g_object_unref (settings); settings = NULL; } #endif */ }
void gw_application_open_settingswindow_cb (GSimpleAction *action, GVariant *parameter, gpointer data) { //Declarations GwApplication *application; GwSearchWindow *searchwindow; GtkWindow *settingswindow; GList *link; //Initializations searchwindow = GW_SEARCHWINDOW (gw_application_get_last_focused_searchwindow (GW_APPLICATION (data))); application = gw_window_get_application (GW_WINDOW (searchwindow)); link = gtk_application_get_windows (GTK_APPLICATION (application)); while (link != NULL && !GW_IS_SETTINGSWINDOW (link->data)) link = link->next; if (link != NULL) { settingswindow = GTK_WINDOW (link->data); gtk_window_set_transient_for (GTK_WINDOW (settingswindow), GTK_WINDOW (searchwindow)); gtk_window_present (GTK_WINDOW (settingswindow)); } else { settingswindow = gw_settingswindow_new (GTK_APPLICATION (application)); gtk_window_set_transient_for (GTK_WINDOW (settingswindow), GTK_WINDOW (searchwindow)); gtk_widget_show (GTK_WIDGET (settingswindow)); } }
void gw_application_quit_cb (GSimpleAction *action, GVariant *parameter, gpointer data) { gw_application_quit (GW_APPLICATION (data)); }
static void gw_application_finalize (GObject *object) { //Declarations GwApplication *application; GwApplicationPrivate *priv; application = GW_APPLICATION (object); priv = application->priv; gw_application_remove_signals (application); if (priv->error != NULL) g_error_free (priv->error); priv->error = NULL; if (priv->installable_dictionarylist != NULL) g_object_unref (priv->installable_dictionarylist); priv->installable_dictionarylist = NULL; if (priv->installed_dictionarylist != NULL) g_object_unref (priv->installed_dictionarylist); priv->installed_dictionarylist = NULL; if (priv->vocabularyliststore != NULL) g_object_unref (priv->vocabularyliststore); if (priv->context != NULL) g_option_context_free (priv->context); priv->context = NULL; if (priv->arg_query != NULL) g_free(priv->arg_query); priv->arg_query = NULL; if (priv->preferences != NULL) lw_preferences_free (priv->preferences); priv->preferences = NULL; #if WITH_MECAB if (lw_morphologyengine_has_default ()) { lw_morphologyengine_free (lw_morphologyengine_get_default ()); } #endif lw_regex_free (); G_OBJECT_CLASS (gw_application_parent_class)->finalize (object); }
G_MODULE_EXPORT void gw_application_open_vocabularywindow_cb (GSimpleAction *action, GVariant *parameter, gpointer data) { GwApplication *application; application = GW_APPLICATION (data); gw_application_show_vocabularywindow (application, -1); }
G_MODULE_EXPORT void gw_application_open_vocabularywindow_index_cb (GSimpleAction *action, GVariant *parameter, gpointer data) { GwApplication *application; const gchar *value; gint index; application = GW_APPLICATION (data); value = g_variant_get_string (parameter, NULL); index = (gint) g_ascii_strtoll (value, NULL, 10); gw_application_show_vocabularywindow (application, index); }
G_MODULE_EXPORT void gw_application_open_searchwindow_cb (GSimpleAction *action, GVariant *parameter, gpointer data) { //Declarations GwApplication *application; GtkWindow *window; //Initializations application = GW_APPLICATION (data); g_return_if_fail (application != NULL); window = gw_searchwindow_new (GTK_APPLICATION (application)); gtk_widget_show (GTK_WIDGET (window)); }
//! //! @brief Sets up the variables in main-interface.c and main-callbacks.c for use //! GtkWindow* gw_addvocabularywindow_new (GtkApplication *application) { g_assert (application != NULL); //Declarations GwAddVocabularyWindow *window; //Initializations window = GW_ADDVOCABULARYWINDOW (g_object_new (GW_TYPE_ADDVOCABULARYWINDOW, "type", GTK_WINDOW_TOPLEVEL, "application", GW_APPLICATION (application), "ui-xml", "addvocabularywindow.ui", NULL)); return GTK_WINDOW (window); }
//! //! @brief Sets up the variables in main-interface.c and main-callbacks.c for use //! GtkWindow* gw_installprogresswindow_new (GtkApplication *application) { g_assert (application != NULL); //Declarations GwInstallProgressWindow *window; //Initializations window = GW_INSTALLPROGRESSWINDOW (g_object_new (GW_TYPE_INSTALLPROGRESSWINDOW, "type", GTK_WINDOW_TOPLEVEL, "application", GW_APPLICATION (application), "ui-xml", "installprogresswindow.ui", NULL)); return GTK_WINDOW (window); }
//! //! @brief Callback to toggle spellcheck in the search entry //! @param widget Unused pointer to a GtkWidget //! @param data Unused gpointer //! void gw_application_spellcheck_toggled_cb (GSimpleAction *action, GVariant *parameter, gpointer data) { //Declarations GwApplication *application; LwPreferences *preferences; gboolean state; //Initializations application = GW_APPLICATION (data); preferences = gw_application_get_preferences (application); state = lw_preferences_get_boolean_by_schema (preferences, LW_SCHEMA_BASE, LW_KEY_SPELLCHECK); lw_preferences_set_boolean_by_schema (preferences, LW_SCHEMA_BASE, LW_KEY_SPELLCHECK, !state); }
//! //! @brief Sets up the variables in main-interface.c and main-callbacks.c for use //! GtkWindow* gw_kanjipadwindow_new (GtkApplication *application) { g_assert (application != NULL); //Declarations GwKanjipadWindow *window; //Initializations window = GW_KANJIPADWINDOW (g_object_new (GW_TYPE_KANJIPADWINDOW, "type", GTK_WINDOW_TOPLEVEL, "application", GW_APPLICATION (application), "ui-xml", "kanjipadwindow.ui", NULL)); return GTK_WINDOW (window); }
void gw_application_sync_spellcheck_cb (GSettings *settings, gchar *key, gpointer data) { //Declarations GwApplication *application; gboolean state; GAction *action; //Initializations application = GW_APPLICATION (data); state = lw_preferences_get_boolean (settings, key); action = g_action_map_lookup_action (G_ACTION_MAP (application), "toggle-spellcheck"); if (action != NULL) g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (state)); }
//! //! @brief Sets up the variables in main-interface.c and main-callbacks.c for use //! GtkWindow* gw_settingswindow_new (GtkApplication *application) { g_assert (application != NULL); //Declarations GwSettingsWindow *window; //Initializations window = GW_SETTINGSWINDOW (g_object_new (GW_TYPE_SETTINGSWINDOW, "type", GTK_WINDOW_TOPLEVEL, "application", GW_APPLICATION (application), "ui-xml", "settingswindow.ui", NULL)); return GTK_WINDOW (window); }
//! //! @brief Prints to the terminal the about message for the program. //! void gw_application_print_about (GwApplication *application) { const gchar *name; name = gw_application_get_program_name (GW_APPLICATION (application)); printf (gettext ("%s version %s"), name, VERSION); printf ("\n\n"); printf ("Check for the latest updates at <http://gwaei.sourceforge.net/>\n"); printf ("Code Copyright (C) 2009-2012 Zachary Dovel\n\n"); printf ("License:\n"); printf ("Copyright (C) 2008 Free Software Foundation, Inc.\nLicense GPLv3+: " "GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis" " is free software: you are free to change and redistribute it.\nThe" "re is NO WARRANTY, to the extent permitted by law.\n\n" ); }
static void gw_spellcheck_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { GwSpellcheck *spellcheck; GwSpellcheckPrivate *priv; spellcheck = GW_SPELLCHECK (object); priv = spellcheck->priv; switch (property_id) { case PROP_APPLICATION: priv->application = GW_APPLICATION (g_value_get_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
//! //! @brief Opens the gWaei dictionary glossary help documentation //! @param widget Unused GtkWidget pointer //! @param data Unused gpointer //! G_MODULE_EXPORT void gw_application_open_glossary_cb (GSimpleAction *action, GVariant *parameter, gpointer data) { //Declarations gchar *uri; GError *error; GwApplication *application; //Initializations application = GW_APPLICATION (data); uri = g_build_filename ("ghelp://", DATADIR2, "gnome", "help", "gwaei", "C", "glossary.xml", NULL); error = NULL; if (uri != NULL) { gtk_show_uri (NULL, uri, gtk_get_current_event_time (), &error); g_free (uri); uri = NULL; } gw_application_handle_error (application, NULL, FALSE, &error); }
void gw_window_load_menubar (GwWindow *window, const gchar* BASE_NAME) { //Declarations GwWindowPrivate *priv; GtkBuilder *builder; GtkApplication *application; GMenuModel *win_menu_model; gboolean loaded; gboolean os_shows_app_menu; gboolean os_shows_win_menu; gchar *filename; GtkWidget *menubar; GtkSettings *settings; //Initializations priv = window->priv; application = GTK_APPLICATION (gw_window_get_application (window)); menubar = NULL; loaded = FALSE; builder = NULL; filename = NULL; win_menu_model = NULL; settings = gtk_settings_get_default (); g_object_get (settings, "gtk-shell-shows-app-menu", &os_shows_app_menu, NULL); g_object_get (settings, "gtk-shell-shows-menubar", &os_shows_win_menu, NULL); builder = gtk_builder_new (); if (builder == NULL) goto errored; if (os_shows_app_menu && os_shows_win_menu) //Mac OS X style { filename = g_strjoin ("-", BASE_NAME, "menumodel", "macosx.ui", NULL); if (filename == NULL) goto errored; } else if (os_shows_app_menu != os_shows_win_menu) //Gnome 3 style { filename = g_strjoin ("-", BASE_NAME, "menumodel", "gnome.ui", NULL); if (filename == NULL) goto errored; } else //Windows style { filename = g_strjoin ("-", BASE_NAME, "menumodel", "standard.ui", NULL); if (filename == NULL) goto errored; } loaded = gw_application_load_xml (builder, filename); if (loaded == FALSE) goto errored; win_menu_model = G_MENU_MODEL (gtk_builder_get_object (builder, "menu")); if (win_menu_model == NULL) goto errored; //Set the whole menu to the window if appropriate if (os_shows_win_menu == FALSE) { menubar = gtk_menu_bar_new_from_model (win_menu_model); if (menubar == NULL) goto errored; gtk_box_pack_end (GTK_BOX (priv->toplevel), menubar, FALSE, FALSE, 0); gtk_widget_show_all (menubar); } gw_application_add_accelerators (GW_APPLICATION (application), win_menu_model); //Save the menu objects in the window if (priv->menu_model != NULL) g_object_unref (priv->menu_model); priv->menu_model = win_menu_model; win_menu_model = NULL; if (priv->menubar != NULL) gtk_widget_destroy (GTK_WIDGET (priv->menubar)); priv->menubar = GTK_MENU_BAR (menubar); menubar = NULL; errored: if (builder != NULL) g_object_unref (builder); builder = NULL; if (filename != NULL) g_free (filename); filename = NULL; if (win_menu_model != NULL) g_object_unref (G_OBJECT (win_menu_model)); if (menubar != NULL) { g_object_ref_sink (menubar); gtk_widget_destroy (menubar); }; }