/** * gdict_context_match_word: * @context: a #GdictContext * @database: a database name to search into, or %NULL for the * default database * @strategy: a strategy name to use for matching, or %NULL for * the default strategy * @word: the word to match * @error: return location for a #GError, or %NULL * * Query @context for a list of word matching @word inside @database, * using @strategy as a matching strategy. Each time a matching word * is found, the "match-found" signal is fired. * * Return value: %TRUE if the query was successfully started. * * Since: 1.0 */ gboolean gdict_context_match_word (GdictContext *context, const gchar *database, const gchar *strategy, const gchar *word, GError **error) { g_return_val_if_fail (GDICT_IS_CONTEXT (context), FALSE); g_return_val_if_fail (word != NULL, FALSE); if (!GDICT_CONTEXT_GET_IFACE (context)->match_word) { g_warning ("Object `%s' does not implement the match_word " "virtual function.", g_type_name (G_OBJECT_TYPE (context))); return FALSE; } return GDICT_CONTEXT_GET_IFACE (context)->match_word (context, database, strategy, word, error); }
/** * gdict_context_set_local_only: * @context: a #GdictContext * @local_only: %TRUE if only local resources will be used * * Sets whether only local resources will be used when querying for databases, * strategies, matches or definitions. * * Since: 1.0 */ void gdict_context_set_local_only (GdictContext *context, gboolean local_only) { g_return_if_fail (GDICT_IS_CONTEXT (context)); g_object_set (context, "local-only", &local_only, NULL); }
/** * gdict_database_chooser_new_with_context: * @context: a #GdictContext * * Creates a new #GdictDatabaseChooser, using @context as the representation * of the dictionary source to query for the list of available databases. * * Return value: the newly created #GdictDatabaseChooser widget. * * Since: 0.10 */ GtkWidget * gdict_database_chooser_new_with_context (GdictContext *context) { g_return_val_if_fail (GDICT_IS_CONTEXT (context), NULL); return g_object_new (GDICT_TYPE_DATABASE_CHOOSER, "context", context, NULL); }
/** * gdict_speller_new_with_context: * @context: a #GdictContext * * FIXME * * Return value: FIXME * * Since: */ GtkWidget * gdict_speller_new_with_context (GdictContext *context) { g_return_val_if_fail (GDICT_IS_CONTEXT (context), NULL); return g_object_new (GDICT_TYPE_SPELLER, "context", context, NULL); }
/** * gdict_database_chooser_set_context: * @chooser: a #GdictDatabaseChooser * @context: a #GdictContext * * Sets the #GdictContext to be used to query a dictionary source * for the list of available databases. * * Since: 0.10 */ void gdict_database_chooser_set_context (GdictDatabaseChooser *chooser, GdictContext *context) { g_return_if_fail (GDICT_IS_DATABASE_CHOOSER (chooser)); g_return_if_fail (context == NULL || GDICT_IS_CONTEXT (context)); set_gdict_context (chooser, context); g_object_notify (G_OBJECT (chooser), "context"); }
static void set_gdict_context (GdictDatabaseChooser *chooser, GdictContext *context) { GdictDatabaseChooserPrivate *priv; g_assert (GDICT_IS_DATABASE_CHOOSER (chooser)); priv = chooser->priv; if (priv->context) { if (priv->start_id) { GDICT_NOTE (CHOOSER, "Removing old context handlers"); g_signal_handler_disconnect (priv->context, priv->start_id); g_signal_handler_disconnect (priv->context, priv->match_id); g_signal_handler_disconnect (priv->context, priv->end_id); priv->start_id = 0; priv->end_id = 0; priv->match_id = 0; } if (priv->error_id) { g_signal_handler_disconnect (priv->context, priv->error_id); priv->error_id = 0; } GDICT_NOTE (CHOOSER, "Removing old context"); g_object_unref (G_OBJECT (priv->context)); priv->context = NULL; priv->results = -1; } if (!context) return; if (!GDICT_IS_CONTEXT (context)) { g_warning ("Object of type '%s' instead of a GdictContext\n", g_type_name (G_OBJECT_TYPE (context))); return; } GDICT_NOTE (CHOOSER, "Setting new context"); priv->context = g_object_ref (context); priv->results = 0; }
/** * gdict_context_get_local_only: * @context: a #GdictContext * * Gets whether only local resources will be used when querying. * * Return value: %TRUE if only local resources will be used. * * Since: 1.0 */ gboolean gdict_context_get_local_only (GdictContext *context) { gboolean local_only; g_return_val_if_fail (GDICT_IS_CONTEXT (context), FALSE); g_object_get (context, "local-only", &local_only, NULL); return local_only; }
/** * gdict_speller_set_context: * @speller: a #GdictSpeller * @context: a #GdictContext * * FIXME * * Since: */ void gdict_speller_set_context (GdictSpeller *speller, GdictContext *context) { g_return_if_fail (GDICT_IS_SPELLER (speller)); g_return_if_fail (context == NULL || GDICT_IS_CONTEXT (context)); set_gdict_context (speller, context); g_object_notify (G_OBJECT (speller), "context"); }
static void set_gdict_context (GdictSpeller *speller, GdictContext *context) { GdictSpellerPrivate *priv; g_assert (GDICT_IS_SPELLER (speller)); priv = speller->priv; if (priv->context) { if (priv->start_id) { GDICT_NOTE (SPELLER, "Removing old context handlers"); g_signal_handler_disconnect (priv->context, priv->start_id); g_signal_handler_disconnect (priv->context, priv->match_id); g_signal_handler_disconnect (priv->context, priv->end_id); priv->start_id = 0; priv->end_id = 0; priv->match_id = 0; } if (priv->error_id) { g_signal_handler_disconnect (priv->context, priv->error_id); priv->error_id = 0; } GDICT_NOTE (SPELLER, "Removing old context"); g_object_unref (G_OBJECT (priv->context)); } if (!context) return; if (!GDICT_IS_CONTEXT (context)) { g_warning ("Object of type `%s' instead of a GdictContext\n", g_type_name (G_OBJECT_TYPE (context))); return; } GDICT_NOTE (SPELLER, "Setting new context\n"); priv->context = context; g_object_ref (G_OBJECT (priv->context)); }
/** * gdict_context_lookup_strategies: * @context: a #GdictContext * @error: return location for a #GError, or %NULL * * Query @context for the list of matching strategies available. Each * time a new strategy is found, the "strategy-found" signal is fired. * * Return value: %TRUE if the query was successfully started. * * Since: 1.0 */ gboolean gdict_context_lookup_strategies (GdictContext *context, GError **error) { g_return_val_if_fail (GDICT_IS_CONTEXT (context), FALSE); if (!GDICT_CONTEXT_GET_IFACE (context)->get_strategies) { g_warning ("Object `%s' does not implement the get_strategies " "virtual function.", g_type_name (G_OBJECT_TYPE (context))); return FALSE; } return GDICT_CONTEXT_GET_IFACE (context)->get_strategies (context, error); }
static void gdict_look_up_word_and_quit (GdictApp *app) { GdictSource *source; GdictContext *context; GSList *l; if ((!app->lookup_words) || (!app->match_words)) { g_print (_("See mate-dictionary --help for usage\n")); gdict_cleanup (); exit (1); } if (app->source_name) source = gdict_source_loader_get_source (app->loader, app->source_name); else source = gdict_source_loader_get_source (app->loader, GDICT_DEFAULT_SOURCE_NAME); if (!source) { g_warning (_("Unable to find a suitable dictionary source")); gdict_cleanup (); exit (1); } /* we'll just use this one context, so we can destroy it along with * the source that contains it */ context = gdict_source_peek_context (source); g_assert (GDICT_IS_CONTEXT (context)); g_signal_connect (context, "definition-found", G_CALLBACK (definition_found_cb), app); g_signal_connect (context, "error", G_CALLBACK (error_cb), app); g_signal_connect (context, "lookup-end", G_CALLBACK (lookup_end_cb), app); app->remaining_words = 0; for (l = app->lookup_words; l != NULL; l = l->next) { gchar *word = l->data; GError *err = NULL; app->remaining_words += 1; gdict_context_define_word (context, app->database, word, &err); if (err) { g_warning (_("Error while looking up the definition of \"%s\":\n%s"), word, err->message); g_error_free (err); } } gtk_main (); g_object_unref (source); gdict_cleanup (); exit (0); }