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;
}
Ejemplo n.º 2
0
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));
}
static void
database_found_cb (GdictContext  *context,
		   GdictDatabase *database,
		   gpointer       user_data)
{
  GdictDatabaseChooser *chooser = GDICT_DATABASE_CHOOSER (user_data);
  GdictDatabaseChooserPrivate *priv = chooser->priv;
  GtkTreeIter iter;
  const gchar *name, *full_name;
  gint weight = PANGO_WEIGHT_NORMAL;

  name = gdict_database_get_name (database);
  full_name = gdict_database_get_full_name (database);

  if (priv->current_db && !strcmp (priv->current_db, name))
    weight = PANGO_WEIGHT_BOLD;

  GDICT_NOTE (CHOOSER, "DATABASE: `%s' (`%s')",
              name,
              full_name);
  
  gtk_list_store_append (priv->store, &iter);
  gtk_list_store_set (priv->store, &iter,
		      DB_COLUMN_TYPE, DATABASE_NAME,
		      DB_COLUMN_NAME, name,
		      DB_COLUMN_DESCRIPTION, full_name,
                      DB_COLUMN_CURRENT, weight,
		      -1);

  priv->results += 1;
}
Ejemplo n.º 4
0
static void
match_found_cb (GdictContext *context,
		GdictMatch   *match,
		gpointer      user_data)
{
  GdictSpeller *speller = GDICT_SPELLER (user_data);
  GdictSpellerPrivate *priv = speller->priv;
  GtkTreeIter iter;

  GDICT_NOTE (SPELLER, "MATCH: `%s' (from `%s')",
              gdict_match_get_word (match),
              gdict_match_get_database (match));

  gtk_list_store_append (priv->store, &iter);
  gtk_list_store_set (priv->store, &iter,
		      MATCH_COLUMN_TYPE, MATCH_WORD,
		      MATCH_COLUMN_DB_NAME, gdict_match_get_database (match),
		      MATCH_COLUMN_WORD, gdict_match_get_word (match),
		      -1);

  if (priv->results == -1)
    priv->results = 1;
  else
    priv->results += 1;
}
/**
 * gdict_source_chooser_set_current_source:
 * @chooser: a #GdictSourceChooser
 * @source_name: the name of a dictionary source
 *
 * Sets the current dictionary source named @source_name. The row
 * of the source, if found, will be selected and activated.
 *
 * Return value: %TRUE if the source was found
 *
 * Since: 0.12
 */
gboolean
gdict_source_chooser_set_current_source (GdictSourceChooser *chooser,
                                         const gchar        *source_name)
{
  GdictSourceChooserPrivate *priv;
  SelectData data;
  gboolean retval;

  g_return_val_if_fail (GDICT_IS_SOURCE_CHOOSER (chooser), FALSE);
  g_return_val_if_fail (source_name != NULL, FALSE);

  priv = chooser->priv;

  if (priv->current_source && !strcmp (priv->current_source, source_name))
    return TRUE;

  data.source_name = g_strdup (source_name);
  data.chooser = chooser;
  data.found = FALSE;
  data.do_select = TRUE;
  data.do_activate = TRUE;

  gtk_tree_model_foreach (GTK_TREE_MODEL (priv->store),
                          scan_for_source_name,
                          &data);

  retval = data.found;

  GDICT_NOTE (CHOOSER, "%s current source: %s",
              data.found ? "set" : "not set",
              data.source_name);

  if (data.found)
    {
      g_free (priv->current_source);
      priv->current_source = data.source_name;
    }
  else
    g_free (data.source_name);

  return retval;
}