GtkWidget *
terminal_search_dialog_new (GtkWindow   *parent)
{
  GtkWidget *dialog;
  TerminalSearchDialogPrivate *priv;
  GtkListStore *store;
  GtkEntryCompletion *completion;

  priv = g_new0 (TerminalSearchDialogPrivate, 1);

  if (!terminal_util_load_builder_file ("find-dialog.ui",
					"find-dialog", &dialog,
					"search-label", &priv->search_label,
					"search-entry", &priv->search_entry,
					"match-case-checkbutton", &priv->match_case_checkbutton,
					"entire-word-checkbutton", &priv->entire_word_checkbutton,
					"regex-checkbutton", &priv->regex_checkbutton,
					"search-backwards-checkbutton", &priv->backwards_checkbutton,
					"wrap-around-checkbutton", &priv->wrap_around_checkbutton,
					NULL))
  {
    g_free (priv);
    return NULL;
  }

  g_object_set_qdata_full (G_OBJECT (dialog), get_quark (), priv,
			   (GDestroyNotify) terminal_search_dialog_private_destroy);


  priv->search_text_entry = gtk_bin_get_child (GTK_BIN (priv->search_entry));
  gtk_widget_set_size_request (priv->search_entry, 300, -1);

  priv->store = store = gtk_list_store_new (1, G_TYPE_STRING);
  g_object_set (G_OBJECT (priv->search_entry),
		"model", store,
		"text-column", 0,
		NULL);

  priv->completion = completion = gtk_entry_completion_new ();
  gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (store));
  gtk_entry_completion_set_text_column (completion, 0);
  gtk_entry_completion_set_minimum_key_length (completion, HISTORY_MIN_ITEM_LEN);
  gtk_entry_completion_set_popup_completion (completion, FALSE);
  gtk_entry_completion_set_inline_completion (completion, TRUE);
  gtk_entry_set_completion (GTK_ENTRY (priv->search_text_entry), completion);

  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
  gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, FALSE);

  gtk_entry_set_activates_default (GTK_ENTRY (priv->search_text_entry), TRUE);
  g_signal_connect (priv->search_text_entry, "changed", G_CALLBACK (update_sensitivity), dialog);
  g_signal_connect (priv->regex_checkbutton, "toggled", G_CALLBACK (update_sensitivity), dialog);

  g_signal_connect (dialog, "response", G_CALLBACK (response_handler), NULL);

  if (parent)
    gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);

  return GTK_WIDGET (dialog);
}
void
terminal_encoding_dialog_show (GtkWindow *transient_parent)
{
	TerminalApp *app;
	GtkCellRenderer *cell_renderer;
	GtkTreeViewColumn *column;
	GtkTreeModel *model;
	EncodingDialogData *data;

	if (encoding_dialog)
	{
		gtk_window_set_transient_for (GTK_WINDOW (encoding_dialog), transient_parent);
		gtk_window_present (GTK_WINDOW (encoding_dialog));
		return;
	}

	data = g_new (EncodingDialogData, 1);

	if (!terminal_util_load_builder_file ("encodings-dialog.ui",
	                                      "encodings-dialog", &data->dialog,
	                                      "add-button", &data->add_button,
	                                      "remove-button", &data->remove_button,
	                                      "available-treeview", &data->available_tree_view,
	                                      "displayed-treeview", &data->active_tree_view,
	                                      NULL))
	{
		g_free (data);
		return;
	}

	g_object_set_data_full (G_OBJECT (data->dialog), "GT::Data", data, (GDestroyNotify) encoding_dialog_data_free);

	gtk_window_set_transient_for (GTK_WINDOW (data->dialog), transient_parent);
	gtk_window_set_role (GTK_WINDOW (data->dialog), "mate-terminal-encodings");
	g_signal_connect (data->dialog, "response",
	                  G_CALLBACK (response_callback), data);

	/* buttons */
	g_signal_connect (data->add_button, "clicked",
	                  G_CALLBACK (button_clicked_cb), data);

	g_signal_connect (data->remove_button, "clicked",
	                  G_CALLBACK (button_clicked_cb), data);

	/* Tree view of available encodings */
	/* Column 1 */
	cell_renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes (_("_Description"),
	         cell_renderer,
	         "text", COLUMN_NAME,
	         NULL);
	gtk_tree_view_append_column (data->available_tree_view, column);
	gtk_tree_view_column_set_sort_column_id (column, COLUMN_NAME);

	/* Column 2 */
	cell_renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes (_("_Encoding"),
	         cell_renderer,
	         "text", COLUMN_CHARSET,
	         NULL);
	gtk_tree_view_append_column (data->available_tree_view, column);
	gtk_tree_view_column_set_sort_column_id (column, COLUMN_CHARSET);

	data->available_selection = gtk_tree_view_get_selection (data->available_tree_view);
	gtk_tree_selection_set_mode (data->available_selection, GTK_SELECTION_BROWSE);

	g_signal_connect (data->available_selection, "changed",
	                  G_CALLBACK (selection_changed_cb), data);

	/* Tree view of selected encodings */
	/* Column 1 */
	cell_renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes (_("_Description"),
	         cell_renderer,
	         "text", COLUMN_NAME,
	         NULL);
	gtk_tree_view_append_column (data->active_tree_view, column);
	gtk_tree_view_column_set_sort_column_id (column, COLUMN_NAME);

	/* Column 2 */
	cell_renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes (_("_Encoding"),
	         cell_renderer,
	         "text", COLUMN_CHARSET,
	         NULL);
	gtk_tree_view_append_column (data->active_tree_view, column);
	gtk_tree_view_column_set_sort_column_id (column, COLUMN_CHARSET);

	/* Add the data */

	data->active_selection = gtk_tree_view_get_selection (data->active_tree_view);
	gtk_tree_selection_set_mode (data->active_selection, GTK_SELECTION_BROWSE);

	g_signal_connect (data->active_selection, "changed",
	                  G_CALLBACK (selection_changed_cb), data);

	data->base_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, TERMINAL_TYPE_ENCODING);

	app = terminal_app_get ();
	encodings_list_changed_cb (app, data);
	g_signal_connect (app, "encoding-list-changed",
	                  G_CALLBACK (encodings_list_changed_cb), data);

	/* Now turn on sorting */
	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (data->base_store),
	                                      COLUMN_NAME,
	                                      GTK_SORT_ASCENDING);

	model = encodings_create_treemodel (data->base_store, FALSE);
	gtk_tree_view_set_model (data->available_tree_view, model);
	g_object_unref (model);

	model = encodings_create_treemodel (data->base_store, TRUE);
	gtk_tree_view_set_model (data->active_tree_view, model);
	g_object_unref (model);

	g_object_unref (data->base_store);

	gtk_window_present (GTK_WINDOW (data->dialog));

	encoding_dialog = data->dialog;
	g_signal_connect (data->dialog, "destroy",
	                  G_CALLBACK (gtk_widget_destroyed), &encoding_dialog);
}
Example #3
0
void
terminal_skey_do_popup (GtkWindow *window,
                        TerminalScreen *screen,
			const gchar    *skey_match)
{
  GtkWidget *dialog, *label, *entry, *ok_button;
  char *title_text;
  char *seed;
  int seq;
  int hash = MD5;
  SkeyData *data;

  if (strncmp (SKEY_PREFIX, skey_match, strlen (SKEY_PREFIX)) == 0)
    {
      if (!extract_seq_and_seed (skey_match, &seq, &seed))
	{
	  terminal_util_show_error_dialog (window, NULL, NULL,
					   _("The text you clicked on doesn't "
					     "seem to be a valid S/Key "
					     "challenge."));
	  return;
	}
    }
  else
    {
      if (!extract_hash_seq_and_seed (skey_match, &hash, &seq, &seed))
	{
	  terminal_util_show_error_dialog (window, NULL, NULL,
					   _("The text you clicked on doesn't "
					     "seem to be a valid OTP "
					     "challenge."));
	  return;
	}
    }

  if (!terminal_util_load_builder_file ("skey-challenge.ui",
                                        "skey-dialog", &dialog,
                                        "skey-entry", &entry,
                                        "text-label", &label,
                                        "skey-ok-button", &ok_button,
                                        NULL))
    {
      g_free (seed);
      return;
    }

  title_text = g_strdup_printf ("<big><b>%s</b></big>",
                                gtk_label_get_text (GTK_LABEL (label)));
  gtk_label_set_label (GTK_LABEL (label), title_text);
  g_free (title_text);

  g_object_set_data (G_OBJECT (dialog), "skey-entry", entry);

  gtk_widget_grab_focus (entry);
  gtk_widget_grab_default (ok_button);
  gtk_entry_set_text (GTK_ENTRY (entry), "");

  gtk_window_set_transient_for (GTK_WINDOW (dialog), window);
  gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
  gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);

  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
                                           GTK_RESPONSE_OK,
                                           GTK_RESPONSE_CANCEL,
                                           -1);

  /* FIXME: make this dialogue close if the screen closes! */

  data = g_new (SkeyData, 1);
  data->hash = hash;
  data->seq = seq;
  data->seed = seed;
  data->screen = screen;

  g_signal_connect_data (dialog, "response",
                         G_CALLBACK (skey_challenge_response_cb),
                         data, (GClosureNotify) skey_data_free, 0);
  g_signal_connect (dialog, "delete-event",
                    G_CALLBACK (terminal_util_dialog_response_on_delete), NULL);

  gtk_window_present (GTK_WINDOW (dialog));
}
Example #4
0
void
terminal_edit_keys_dialog_show (GtkWindow *transient_parent)
{
	TerminalApp *app;
	GtkWidget *dialog, *tree_view, *disable_mnemonics_button, *disable_menu_accel_button;
	GtkTreeViewColumn *column;
	GtkCellRenderer *cell_renderer;
	GtkTreeStore *tree;
	guint i;

	if (edit_keys_dialog != NULL)
		goto done;

	if (!terminal_util_load_builder_file ("keybinding-editor.ui",
	                                      "keybindings-dialog", &dialog,
	                                      "disable-mnemonics-checkbutton", &disable_mnemonics_button,
	                                      "disable-menu-accel-checkbutton", &disable_menu_accel_button,
	                                      "accelerators-treeview", &tree_view,
	                                      NULL))
		return;

	app = terminal_app_get ();
	terminal_util_bind_object_property_to_widget (G_OBJECT (app), TERMINAL_APP_ENABLE_MNEMONICS,
	        disable_mnemonics_button, 0);
	terminal_util_bind_object_property_to_widget (G_OBJECT (app), TERMINAL_APP_ENABLE_MENU_BAR_ACCEL,
	        disable_menu_accel_button, 0);

	/* Column 1 */
	cell_renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes (_("_Action"),
	         cell_renderer,
	         "text", ACTION_COLUMN,
	         NULL);
	gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
	gtk_tree_view_column_set_sort_column_id (column, ACTION_COLUMN);

	/* Column 2 */
	cell_renderer = gtk_cell_renderer_accel_new ();
	g_object_set (cell_renderer,
	              "editable", TRUE,
	              "accel-mode", GTK_CELL_RENDERER_ACCEL_MODE_GTK,
	              NULL);
	g_signal_connect (cell_renderer, "accel-edited",
	                  G_CALLBACK (accel_edited_callback), tree_view);
	g_signal_connect (cell_renderer, "accel-cleared",
	                  G_CALLBACK (accel_cleared_callback), tree_view);

	column = gtk_tree_view_column_new ();
	gtk_tree_view_column_set_title (column, _("Shortcut _Key"));
	gtk_tree_view_column_pack_start (column, cell_renderer, TRUE);
	gtk_tree_view_column_set_cell_data_func (column, cell_renderer, accel_set_func, NULL, NULL);
	gtk_tree_view_column_set_sort_column_id (column, KEYVAL_COLUMN);
	gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);

	/* Add the data */

	tree = edit_keys_store = gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER);

#ifdef MATE_ENABLE_DEBUG
	_TERMINAL_DEBUG_IF (TERMINAL_DEBUG_ACCELS)
	g_signal_connect (tree, "row-changed", G_CALLBACK (row_changed), NULL);
#endif

	for (i = 0; i < G_N_ELEMENTS (all_entries); ++i)
	{
		GtkTreeIter parent_iter;
		guint j;

		gtk_tree_store_append (tree, &parent_iter, NULL);
		gtk_tree_store_set (tree, &parent_iter,
		                    ACTION_COLUMN, _(all_entries[i].user_visible_name),
		                    -1);

		for (j = 0; j < all_entries[i].n_elements; ++j)
		{
			KeyEntry *key_entry = &(all_entries[i].key_entry[j]);
			GtkTreeIter iter;

			gtk_tree_store_insert_with_values (tree, &iter, &parent_iter, -1,
			                                   ACTION_COLUMN, _(key_entry->user_visible_name),
			                                   KEYVAL_COLUMN, key_entry,
			                                   -1);
		}
	}

	gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (tree),
	                                 KEYVAL_COLUMN, accel_compare_func,
	                                 NULL, NULL);
	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (tree), ACTION_COLUMN,
	                                      GTK_SORT_ASCENDING);

	gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (tree));
	g_object_unref (tree);

	gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));

	g_signal_connect (notification_group, "accel-changed",
	                  G_CALLBACK (treeview_accel_changed_cb), tree);

	edit_keys_dialog = dialog;
	g_signal_connect (dialog, "destroy",
	                  G_CALLBACK (edit_keys_dialog_destroy_cb), tree);
	g_signal_connect (dialog, "response",
	                  G_CALLBACK (edit_keys_dialog_response_cb),
	                  NULL);
	gtk_window_set_default_size (GTK_WINDOW (dialog), -1, 350);

done:
	gtk_window_set_transient_for (GTK_WINDOW (edit_keys_dialog), transient_parent);
	gtk_window_present (GTK_WINDOW (edit_keys_dialog));
}