Ejemplo n.º 1
0
static void
gedit_dict_panel_draw (GeditDictPanel *panel)
{
	GtkWidget  *vbox;
	GtkWidget  *hbox;
	
	vbox = gtk_vbox_new (FALSE, 6);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
	gtk_widget_show (vbox);
 
	hbox = gtk_hbox_new (FALSE, 12);
	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
	gtk_widget_show (hbox);
	
	/*
	 * Look up Button
	 */
	panel->priv->button = gtk_button_new_with_mnemonic (_("Look _up:"));
	g_signal_connect(panel->priv->button, "clicked",
				 G_CALLBACK (gedit_dict_panel_entry_activate_cb),
				 panel);
	gtk_button_set_relief (GTK_BUTTON (panel->priv->button), GTK_RELIEF_NONE);
	gtk_box_pack_start (GTK_BOX (hbox), panel->priv->button, FALSE, FALSE, 0);
 	gtk_widget_show(panel->priv->button);
	
	/*
	 * Entry
	 */
	panel->priv->entry = gtk_entry_new ();
	if (panel->priv->word)
		gtk_entry_set_text (GTK_ENTRY (panel->priv->entry), panel->priv->word);
  
	g_signal_connect (panel->priv->entry, "activate",
				  G_CALLBACK (gedit_dict_panel_entry_activate_cb),
				  panel);
	gtk_box_pack_start (GTK_BOX (hbox), panel->priv->entry, TRUE, TRUE, 0);
	gtk_widget_show (panel->priv->entry);


	/*
	 * Defbox
	 */
	panel->priv->defbox = gdict_defbox_new ();
	if (panel->priv->context)
		gdict_defbox_set_context (GDICT_DEFBOX (panel->priv->defbox),
					  panel->priv->context);
	g_signal_connect(panel->priv->defbox, "link-clicked",
			 G_CALLBACK(gedit_dict_panel_link_clicked), panel);
	
	gtk_container_add (GTK_CONTAINER (vbox), panel->priv->defbox);
	gtk_widget_show (panel->priv->defbox);
	
	panel->priv->sidebar = gdict_sidebar_new ();
	g_signal_connect (panel->priv->sidebar, "page-changed",
			  G_CALLBACK (sidebar_page_changed_cb),
			  panel);

	/*
	 * Paned
	 */
	panel->priv->paned = GTK_PANED(gtk_vpaned_new());
	gtk_box_pack_start (GTK_BOX (panel), GTK_WIDGET(panel->priv->paned), TRUE, TRUE, 0);
	gtk_paned_pack1 (panel->priv->paned, vbox, FALSE, TRUE);
	gtk_paned_pack2 (panel->priv->paned, panel->priv->sidebar, TRUE, TRUE);
	gtk_widget_show (GTK_WIDGET(panel->priv->paned));
	
	g_signal_connect(panel->priv->paned, "notify::position",
			 G_CALLBACK(store_position), NULL);
	
	
	/*
	 * Speller
	 */
	panel->priv->speller = gdict_speller_new ();
	if (panel->priv->context)
		gdict_speller_set_context (GDICT_SPELLER (panel->priv->speller),
					   panel->priv->context);
	g_signal_connect (panel->priv->speller, "word-activated",
			  G_CALLBACK (speller_word_activated_cb),
			  panel);
  
	gdict_sidebar_add_page (GDICT_SIDEBAR (panel->priv->sidebar),
				GDICT_SIDEBAR_SPELLER_PAGE,
				_("Similar words"),
				panel->priv->speller);
	gtk_widget_show (panel->priv->speller);

	/*
	 * db chooser
	 */
  	panel->priv->db_chooser = gdict_database_chooser_new ();
	if (panel->priv->context)
		gdict_database_chooser_set_context (GDICT_DATABASE_CHOOSER (panel->priv->db_chooser),
						    panel->priv->context);
	g_signal_connect (panel->priv->db_chooser, "database-activated",
			  G_CALLBACK (database_activated_cb),
			  panel);
	gdict_sidebar_add_page (GDICT_SIDEBAR (panel->priv->sidebar),
				GDICT_SIDEBAR_DATABASES_PAGE,
				_("Available dictionaries"),
				panel->priv->db_chooser);
	gtk_widget_show (panel->priv->db_chooser);

	/*
	 * Strategy chooser
	 */
  	panel->priv->strat_chooser = gdict_strategy_chooser_new ();
	if (panel->priv->context)
		gdict_strategy_chooser_set_context (GDICT_STRATEGY_CHOOSER (panel->priv->strat_chooser),
						    panel->priv->context);
	g_signal_connect (panel->priv->strat_chooser, "strategy-activated",
			  G_CALLBACK (strategy_activated_cb),
			  panel);
	gdict_sidebar_add_page (GDICT_SIDEBAR (panel->priv->sidebar),
				GDICT_SIDEBAR_STRATEGIES_PAGE,
				_("Available strategies"),
				panel->priv->strat_chooser);
	gtk_widget_show (panel->priv->strat_chooser);

	gtk_widget_show (panel->priv->sidebar);
	
	
}
Ejemplo n.º 2
0
static void
update_dialog_ui (GdictSourceDialog *dialog)
{
  GdictSource *source;
  
  /* TODO - add code to update the contents of the dialog depending
   * on the action; if we are in _CREATE, no action is needed
   */
  switch (dialog->action)
    {
    case GDICT_SOURCE_DIALOG_VIEW:
    case GDICT_SOURCE_DIALOG_EDIT:
      if (!dialog->source_name)
	{
          g_warning ("Attempting to retrieve source, but no "
		     "source name has been defined.  Aborting...");
	  return;
	}
      
      source = gdict_source_loader_get_source (dialog->loader,
		      			       dialog->source_name);
      if (!source)
	{
          g_warning ("Attempting to retrieve source, but no "
		     "source named `%s' was found.  Aborting...",
		     dialog->source_name);
	  return;
	}
      
      g_object_ref (source);
      
      dialog->source = source;
      set_text_to_entry (dialog, "description_entry",
		         gdict_source_get_description (source));

      dialog->transport = gdict_source_get_transport (source);
      gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->transport_combo),
                                (gint) dialog->transport);

      /* set the context for the database and strategy choosers */
      dialog->context = gdict_source_get_context (source);
      if (!dialog->context)
        {
          g_warning ("Attempting to retrieve the context, but "
                     "none was found for source `%s'.",
                     dialog->source_name);
          return;
        }
      
      set_transport_settings (dialog);

      gdict_database_chooser_set_context (GDICT_DATABASE_CHOOSER (dialog->db_chooser),
                                          dialog->context);
      gdict_database_chooser_refresh (GDICT_DATABASE_CHOOSER (dialog->db_chooser));
      gdict_strategy_chooser_set_context (GDICT_STRATEGY_CHOOSER (dialog->strat_chooser),
                                          dialog->context);
      gdict_strategy_chooser_refresh (GDICT_STRATEGY_CHOOSER (dialog->strat_chooser));
      break;
    case GDICT_SOURCE_DIALOG_CREATE:
      /* DICTD transport is default */
      gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->transport_combo), 0);
      g_signal_emit_by_name (dialog->transport_combo, "changed");
      break;
    default:
      g_assert_not_reached ();
      break;
    }
}
Ejemplo n.º 3
0
static void
gtr_dict_panel_init (GtrDictPanel * panel)
{
  GtrDictPanelPrivate *priv;
  GtkWidget *vbox;
  GtkWidget *hbox;

  panel->priv = GTR_DICT_PANEL_GET_PRIVATE (panel);
  priv = panel->priv;

  priv->status = NULL;

  if (!priv->loader)
    panel->priv->loader = gdict_source_loader_new ();

  gtk_orientable_set_orientation (GTK_ORIENTABLE (panel),
                                  GTK_ORIENTATION_VERTICAL);

  /* add our data dir inside $HOME to the loader's search paths */
  gdict_source_loader_add_search_path (priv->loader,
                                       gtr_dirs_get_user_config_dir ());

  /* settings */
  priv->settings = g_settings_new ("org.gnome.gtranslator.plugins.dictionary");

  g_signal_connect (priv->settings,
                    "changed",
                    G_CALLBACK (on_settings_changed),
                    panel);

  /* force retrieval of the configuration from gsettings */
  gtr_dict_panel_set_source_name (panel, NULL);

  /* Draw widgets */
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
  gtk_widget_show (vbox);

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  /* Look up Button */
  panel->priv->button = gtk_button_new_with_mnemonic (_("Look _up:"));
  g_signal_connect (panel->priv->button, "clicked",
                    G_CALLBACK (gtr_dict_panel_entry_activate_cb), panel);
  gtk_button_set_relief (GTK_BUTTON (panel->priv->button), GTK_RELIEF_NONE);
  gtk_box_pack_start (GTK_BOX (hbox), panel->priv->button, FALSE, FALSE, 0);
  gtk_widget_show (panel->priv->button);

  /* Entry */
  panel->priv->entry = gtk_entry_new ();
  if (panel->priv->word)
    gtk_entry_set_text (GTK_ENTRY (panel->priv->entry), panel->priv->word);

  g_signal_connect (panel->priv->entry, "activate",
                    G_CALLBACK (gtr_dict_panel_entry_activate_cb), panel);
  gtk_box_pack_start (GTK_BOX (hbox), panel->priv->entry, TRUE, TRUE, 0);
  gtk_widget_show (panel->priv->entry);

  /* Defbox */
  panel->priv->defbox = gdict_defbox_new ();
  if (panel->priv->context)
    gdict_defbox_set_context (GDICT_DEFBOX (panel->priv->defbox),
                              panel->priv->context);
  g_signal_connect (panel->priv->defbox, "link-clicked",
                    G_CALLBACK (gtr_dict_panel_link_clicked), panel);

  gtk_container_add (GTK_CONTAINER (vbox), panel->priv->defbox);
  gtk_widget_show (panel->priv->defbox);

  /* Sidebar */
  panel->priv->sidebar = gdict_sidebar_new ();
  g_signal_connect (panel->priv->sidebar, "page-changed",
                    G_CALLBACK (sidebar_page_changed_cb), panel);

  /* Paned */
  panel->priv->paned = GTK_PANED (gtk_paned_new (GTK_ORIENTATION_VERTICAL));
  gtk_box_pack_start (GTK_BOX (panel), GTK_WIDGET (panel->priv->paned), TRUE,
                      TRUE, 0);
  gtk_paned_pack1 (panel->priv->paned, vbox, FALSE, TRUE);
  gtk_paned_pack2 (panel->priv->paned, panel->priv->sidebar, TRUE, TRUE);
  gtk_widget_show (GTK_WIDGET (panel->priv->paned));

  g_settings_bind (panel->priv->settings,
                   DICTIONARY_SETTINGS_POSITION_KEY,
                   panel->priv->paned,
                   "position",
                   G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);

  /* Speller */
  panel->priv->speller = gdict_speller_new ();
  if (panel->priv->context)
    gdict_speller_set_context (GDICT_SPELLER (panel->priv->speller),
                               panel->priv->context);
  g_signal_connect (panel->priv->speller, "word-activated",
                    G_CALLBACK (speller_word_activated_cb), panel);

  gdict_sidebar_add_page (GDICT_SIDEBAR (panel->priv->sidebar),
                          GDICT_SIDEBAR_SPELLER_PAGE,
                          _("Similar words"), panel->priv->speller);
  gtk_widget_show (panel->priv->speller);

  /* db chooser */
  panel->priv->db_chooser = gdict_database_chooser_new ();
  if (panel->priv->context)
    gdict_database_chooser_set_context (GDICT_DATABASE_CHOOSER
                                        (panel->priv->db_chooser),
                                        panel->priv->context);
  g_signal_connect (panel->priv->db_chooser, "database-activated",
                    G_CALLBACK (database_activated_cb), panel);
  gdict_sidebar_add_page (GDICT_SIDEBAR (panel->priv->sidebar),
                          GDICT_SIDEBAR_DATABASES_PAGE,
                          _("Available dictionaries"),
                          panel->priv->db_chooser);
  gtk_widget_show (panel->priv->db_chooser);

  /* Strategy chooser */
  panel->priv->strat_chooser = gdict_strategy_chooser_new ();
  if (panel->priv->context)
    gdict_strategy_chooser_set_context (GDICT_STRATEGY_CHOOSER
                                        (panel->priv->strat_chooser),
                                        panel->priv->context);
  g_signal_connect (panel->priv->strat_chooser, "strategy-activated",
                    G_CALLBACK (strategy_activated_cb), panel);
  gdict_sidebar_add_page (GDICT_SIDEBAR (panel->priv->sidebar),
                          GDICT_SIDEBAR_STRATEGIES_PAGE,
                          _("Available strategies"),
                          panel->priv->strat_chooser);
  gtk_widget_show (panel->priv->strat_chooser);

  /* Source chooser */
  panel->priv->source_chooser =
    gdict_source_chooser_new_with_loader (panel->priv->loader);
  g_signal_connect (panel->priv->source_chooser, "source-activated",
                    G_CALLBACK (source_activated_cb), panel);
  gdict_sidebar_add_page (GDICT_SIDEBAR (panel->priv->sidebar),
                          GDICT_SIDEBAR_SOURCES_PAGE, _("Dictionary sources"),
                          panel->priv->source_chooser);
  gtk_widget_show (panel->priv->source_chooser);

  gtk_widget_show (panel->priv->sidebar);

}