static GtkWidget *
create_collaboration_image (GeditCollaborationWindowHelper *helper)
{
	GdkPixbuf *icon;
	GtkWidget *image;
	gchar *datadir;

	datadir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (helper));
	icon = try_create_icon (datadir);
	g_free (datadir);

	if (icon == NULL)
	{
		icon = try_create_icon (GEDIT_PLUGINS_DATA_DIR "/collaboration");
	}

	image = gtk_image_new_from_pixbuf (icon);

	if (icon != NULL)
	{
		g_object_unref (icon);
	}

	return image;
}
Beispiel #2
0
static SpellConfigureDialog *
get_configure_dialog (PlumaSpellPlugin *plugin)
{
	SpellConfigureDialog *dialog = NULL;
	gchar *data_dir;
	gchar *ui_file;
	PlumaSpellPluginAutocheckType autocheck_type;
	GtkWidget *error_widget;
	gboolean ret;
	gchar *root_objects[] = {
		"spell_dialog_content",
		NULL
	};

	pluma_debug (DEBUG_PLUGINS);

	dialog = g_slice_new (SpellConfigureDialog);
	dialog->settings = g_object_ref (plugin->priv->settings);

	data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin));
	ui_file = g_build_filename (data_dir, "pluma-spell-setup-dialog.ui", NULL);
	ret = pluma_utils_get_ui_objects (ui_file,
					  root_objects,
					  &error_widget,
					  "spell_dialog_content", &dialog->content,
					  "autocheck_never", &dialog->never,
					  "autocheck_document", &dialog->document,
					  "autocheck_always", &dialog->always,
					  NULL);

	g_free (data_dir);
	g_free (ui_file);

	if (!ret)
	{
		return NULL;
	}

	autocheck_type = get_autocheck_type (plugin);

	if (autocheck_type == AUTOCHECK_ALWAYS)
	{
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->always), TRUE);
	}
	else if (autocheck_type == AUTOCHECK_DOCUMENT)
	{
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->document), TRUE);
	}
	else
	{
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->never), TRUE);
	}

	return dialog;
}
Beispiel #3
0
static void
set_language_cb (GSimpleAction *action,
                 GVariant      *parameter,
                 gpointer       data)
{
	GeditSpellPlugin *plugin = GEDIT_SPELL_PLUGIN (data);
	GeditSpellPluginPrivate *priv;
	GeditDocument *doc;
	GeditSpellChecker *spell;
	const GeditSpellCheckerLanguage *lang;
	GtkWidget *dlg;
	GtkWindowGroup *wg;
	gchar *data_dir;

	gedit_debug (DEBUG_PLUGINS);

	priv = plugin->priv;

	doc = gedit_window_get_active_document (priv->window);
	g_return_if_fail (doc != NULL);

	spell = get_spell_checker_from_document (doc);
	g_return_if_fail (spell != NULL);

	lang = gedit_spell_checker_get_language (spell);

	data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin));
	dlg = gedit_spell_language_dialog_new (GTK_WINDOW (priv->window),
					       lang,
					       data_dir);
	g_free (data_dir);

	wg = gedit_window_get_group (priv->window);

	gtk_window_group_add_window (wg, GTK_WINDOW (dlg));

	gtk_window_set_modal (GTK_WINDOW (dlg), TRUE);

	g_signal_connect (dlg,
			  "response",
			  G_CALLBACK (language_dialog_response),
			  spell);

	gtk_widget_show (dlg);
}
Beispiel #4
0
static void
set_language_cb (GtkAction   *action,
		 PlumaSpellPlugin *plugin)
{
	PlumaWindow *window;
	PlumaDocument *doc;
	PlumaSpellChecker *spell;
	const PlumaSpellCheckerLanguage *lang;
	GtkWidget *dlg;
	GtkWindowGroup *wg;
	gchar *data_dir;

	pluma_debug (DEBUG_PLUGINS);

	window = PLUMA_WINDOW (plugin->priv->window);
	doc = pluma_window_get_active_document (window);
	g_return_if_fail (doc != NULL);

	spell = get_spell_checker_from_document (doc);
	g_return_if_fail (spell != NULL);

	lang = pluma_spell_checker_get_language (spell);

	data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin));
	dlg = pluma_spell_language_dialog_new (GTK_WINDOW (window),
					       lang,
					       data_dir);
	g_free (data_dir);

	wg = pluma_window_get_group (window);

	gtk_window_group_add_window (wg, GTK_WINDOW (dlg));

	gtk_window_set_modal (GTK_WINDOW (dlg), TRUE);

	g_signal_connect (dlg,
			  "response",
			  G_CALLBACK (language_dialog_response),
			  spell);

	gtk_widget_show (dlg);
}
static gchar *
show_password_dialog (GeditCollaborationWindowHelper *helper,
                      GeditCollaborationUser         *user,
                      InfXmppConnection              *connection)
{
	GtkBuilder *builder;
	GtkWidget *dialog;
	GtkWidget *label;
	GtkWidget *entry;
	gchar *password;
	gchar *remote;
	gchar *text;
	gchar *name;
	gchar *username;
	gchar *remotename;
	gchar *datadir;

	datadir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (helper));
	builder = gedit_collaboration_create_builder (datadir,
	                                              "gedit-collaboration-password-dialog.ui");
	g_free (datadir);

	if (!builder)
	{
		return NULL;
	}

	dialog = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_password"));
	label = GTK_WIDGET (gtk_builder_get_object (builder, "label_caption"));
	entry = GTK_WIDGET (gtk_builder_get_object (builder, "entry_password"));

	g_object_get (connection, "remote-hostname", &remote, NULL);

	username = g_markup_escape_text (gedit_collaboration_user_get_name (user), -1);
	remotename = g_markup_escape_text (remote, -1);

	name = g_strdup_printf ("<i>%s@%s</i>", username, remotename);

	g_free (remote);
	g_free (username);
	g_free (remotename);

	text = g_strdup_printf (_("Please provide a password for %s"),
	                        name);
	g_free (name);

	if (!inf_xmpp_connection_get_tls_enabled (connection))
	{
		gchar *all = g_strdup_printf ("%s\n\n<small><b>%s</b></small>",
		                              text,
		                              _("Note: The connection is not secure"));

		g_free (text);
		text = all;
	}

	gtk_label_set_markup (GTK_LABEL (label),
	                      text);
	g_free (text);

	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);

	/* Need to do this modal/sync for now */
	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
	{
		password = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));

		if (!*password)
		{
			g_free (password);
			password = NULL;
		}
	}
	else
	{
		password = NULL;
	}

	g_object_unref (builder);
	gtk_widget_destroy (dialog);

	return password;
}
static gboolean
build_ui (GeditCollaborationWindowHelper *helper)
{
	GeditPanel *panel;
	GtkWidget *vbox;
	GtkWidget *sw;
	GtkWidget *toolbar;
	GtkWidget *image;
	GtkBuilder *builder;
	GtkWidget *paned;
	gchar *datadir;

	datadir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (helper));
	builder = gedit_collaboration_create_builder (datadir, XML_UI_FILE);
	g_free (datadir);

	if (!builder)
	{
		return FALSE;
	}

	helper->priv->builder = builder;
	helper->priv->uimanager = GTK_UI_MANAGER (gtk_builder_get_object (builder, "uimanager"));

	gtk_builder_connect_signals (builder, helper);

	/* Create panel */
	panel = gedit_window_get_side_panel (helper->priv->window);

	vbox = gtk_vbox_new (FALSE, 3);
	gtk_widget_show (vbox);

	toolbar = gtk_ui_manager_get_widget (helper->priv->uimanager, "/ToolBar");
	gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
	gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_MENU);
	gtk_widget_show (toolbar);

	gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, TRUE, 0);

	sw = gtk_scrolled_window_new (NULL, NULL);
	gtk_widget_show (sw);

	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
	                                GTK_POLICY_AUTOMATIC,
	                                GTK_POLICY_AUTOMATIC);

	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
	                                     GTK_SHADOW_ETCHED_IN);

	/* Initialize libinfinity stuff */
	init_infinity (helper);
	gtk_container_add (GTK_CONTAINER (sw), helper->priv->browser_view);

	gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);

	/* Create collaboration icon */
	image = create_collaboration_image (helper);

	gtk_widget_show (image);

	paned = gtk_vpaned_new ();
	gtk_paned_add1 (GTK_PANED (paned), vbox);

	gtk_container_child_set (GTK_CONTAINER (paned),
	                         vbox,
	                         "resize",
	                         TRUE,
	                         NULL);

	build_user_view (helper, &helper->priv->tree_view_user_view,
	                 &helper->priv->scrolled_window_user_view,
	                 TRUE);
	gtk_paned_add2 (GTK_PANED (paned), helper->priv->scrolled_window_user_view);

	gtk_container_child_set (GTK_CONTAINER (paned),
	                         helper->priv->scrolled_window_user_view,
	                         "resize",
	                         FALSE,
	                         NULL);

	gedit_panel_add_item (panel,
	                      paned,
			      "GeditCollaborationPanel",
			      _("Collaboration"),
			      image);

	helper->priv->panel_widget = paned;

	g_signal_connect_after (paned,
	                        "map",
	                        G_CALLBACK (on_paned_mapped),
	                        helper);

	update_sensitivity (helper);

	add_window_menu (helper);
	return TRUE;
}
Beispiel #7
0
static void
spell_cb (GSimpleAction *action,
          GVariant      *parameter,
          gpointer       data)
{
	GeditSpellPlugin *plugin = GEDIT_SPELL_PLUGIN (data);
	GeditSpellPluginPrivate *priv;
	GeditView *view;
	GeditDocument *doc;
	GeditSpellChecker *spell;
	GtkWidget *dlg;
	GtkTextIter start, end;
	gchar *word;
	gchar *data_dir;

	gedit_debug (DEBUG_PLUGINS);

	priv = plugin->priv;

	view = gedit_window_get_active_view (priv->window);
	g_return_if_fail (view != NULL);

	doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
	g_return_if_fail (doc != NULL);

	spell = get_spell_checker_from_document (doc);
	g_return_if_fail (spell != NULL);

	if (gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc)) <= 0)
	{
		GtkWidget *statusbar;

		statusbar = gedit_window_get_statusbar (priv->window);
		gedit_statusbar_flash_message (GEDIT_STATUSBAR (statusbar),
					       priv->message_cid,
					       _("The document is empty."));

		return;
	}

	if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc),
						   &start,
						   &end))
	{
		/* no selection, get the whole doc */
		gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc),
					    &start,
					    &end);
	}

	set_check_range (doc, &start, &end);

	word = get_next_misspelled_word (view);
	if (word == NULL)
	{
		GtkWidget *statusbar;

		statusbar = gedit_window_get_statusbar (priv->window);
		gedit_statusbar_flash_message (GEDIT_STATUSBAR (statusbar),
					       priv->message_cid,
					       _("No misspelled words"));

		return;
	}

	data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin));
	dlg = gedit_spell_checker_dialog_new_from_spell_checker (spell, data_dir);
	g_free (data_dir);
	gtk_window_set_modal (GTK_WINDOW (dlg), TRUE);
	gtk_window_set_transient_for (GTK_WINDOW (dlg),
				      GTK_WINDOW (priv->window));

	g_signal_connect (dlg, "ignore", G_CALLBACK (ignore_cb), view);
	g_signal_connect (dlg, "ignore_all", G_CALLBACK (ignore_cb), view);

	g_signal_connect (dlg, "change", G_CALLBACK (change_cb), view);
	g_signal_connect (dlg, "change_all", G_CALLBACK (change_all_cb), view);

	g_signal_connect (dlg, "add_word_to_personal", G_CALLBACK (add_word_cb), view);

	gedit_spell_checker_dialog_set_misspelled_word (GEDIT_SPELL_CHECKER_DIALOG (dlg),
							word,
							-1);

	g_free (word);

	gtk_widget_show (dlg);
}