SF.net SVN: geany-plugins: [10] trunk/geanysendmail/geanysendmail.c

frlan at users.sourceforge.net frlan at xxxxx
Tue May 13 19:17:09 UTC 2008


Revision: 10
          http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=10&view=rev
Author:   frlan
Date:     2008-05-13 12:17:02 -0700 (Tue, 13 May 2008)

Log Message:
-----------
Make icon is loaded, when activating option inside configuration dialog

Modified Paths:
--------------
    trunk/geanysendmail/geanysendmail.c

Modified: trunk/geanysendmail/geanysendmail.c
===================================================================
--- trunk/geanysendmail/geanysendmail.c	2008-05-13 18:10:59 UTC (rev 9)
+++ trunk/geanysendmail/geanysendmail.c	2008-05-13 19:17:02 UTC (rev 10)
@@ -58,7 +58,91 @@
 GtkWidget *separator = NULL;
 GtkWidget *separator2 = NULL;
 
+/* Callback for sending file as attachment */
+static void
+send_as_attachment(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata)
+{
+	guint	idx;
+	gchar	*locale_filename = NULL;
+	gchar	*command = NULL;
+	GError	*error = NULL;
+	GString	*cmd_str = NULL;
 
+
+	idx = documents->get_cur_idx();
+
+	if (doc_list[idx].file_name == NULL)
+	{
+		dialogs->show_save_as();
+	}
+	else
+	{
+		documents->save_file(idx, FALSE);
+	}
+
+    if (doc_list[idx].file_name != NULL)
+	{
+		if (mailer)
+		{
+			locale_filename = utils->get_locale_from_utf8(doc_list[idx].file_name);
+			cmd_str = g_string_new(mailer);
+
+			if (! utils->string_replace_all(cmd_str, "%f", locale_filename))
+				ui->set_statusbar(FALSE, _("Filename placeholder not found. The executed command might have failed."));
+
+			command = g_string_free(cmd_str, FALSE);
+			g_spawn_command_line_async(command, &error);
+			if (error != NULL)
+			{
+				ui->set_statusbar(FALSE, _("Could not execute mailer. Please check your configuration."));
+				g_error_free(error);
+			}
+
+			g_free(locale_filename);
+			g_free(command);
+		}
+		else
+		{
+			ui->set_statusbar(FALSE, _("Have to define some mailing tool before."));
+		}
+	}
+	else
+	{
+		ui->set_statusbar(FALSE, _("File have to be saved before sending."));
+	}
+}
+
+static void key_send_as_attachment(G_GNUC_UNUSED guint key_id)
+{
+	send_as_attachment(NULL, NULL);
+}
+
+void show_icon()
+{
+	GdkPixbuf *pixbuf = NULL;
+	GtkWidget *icon = NULL;
+		
+	int number_of_icons = 0;
+	number_of_icons = gtk_toolbar_get_n_items(GTK_TOOLBAR(app->toolbar));
+		
+	pixbuf = gdk_pixbuf_new_from_inline(-1, mail_pixbuf, FALSE, NULL);
+	icon = gtk_image_new_from_pixbuf(pixbuf);
+	g_object_unref(pixbuf);
+
+	separator = (GtkWidget*) gtk_separator_tool_item_new();
+	gtk_widget_show (separator);
+	gtk_toolbar_insert(GTK_TOOLBAR(app->toolbar), GTK_TOOL_ITEM(separator), number_of_icons - 2);
+
+	mailbutton = (GtkWidget*) gtk_tool_button_new (icon, "Mail");
+	gtk_toolbar_insert(GTK_TOOLBAR(app->toolbar), GTK_TOOL_ITEM(mailbutton), number_of_icons - 1);
+	g_signal_connect (G_OBJECT(mailbutton), "clicked", G_CALLBACK(send_as_attachment), NULL);
+	gtk_widget_show_all (mailbutton);
+	
+	separator2 = (GtkWidget*) gtk_separator_tool_item_new();
+	gtk_widget_show (separator2);
+	gtk_toolbar_insert(GTK_TOOLBAR(app->toolbar), GTK_TOOL_ITEM(separator2), number_of_icons);
+}
+
 void configure(GtkWidget *parent)
 {
 	GtkWidget	*dialog, *label1, *label2, *entry, *vbox;
@@ -113,8 +197,16 @@
 		g_free(mailer);
 		mailer = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
 		
-		icon_in_toolbar = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox_icon_to_toolbar));
-		
+		if (icon_in_toolbar == FALSE && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox_icon_to_toolbar)) == TRUE)
+		{
+			icon_in_toolbar = TRUE;
+			show_icon();
+		}
+		else
+		{
+			icon_in_toolbar = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox_icon_to_toolbar));
+		}
+			
 		g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL);
 		g_key_file_set_string(config, "tools", "mailer", mailer);
 		g_key_file_set_boolean(config, "icon", "show_icon", icon_in_toolbar);
@@ -138,66 +230,8 @@
 	gtk_widget_destroy(dialog);
 }
 
-/* Callback for sending file as attachment */
-static void
-send_as_attachment(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata)
-{
-	guint	idx;
-	gchar	*locale_filename = NULL;
-	gchar	*command = NULL;
-	GError	*error = NULL;
-	GString	*cmd_str = NULL;
 
 
-	idx = documents->get_cur_idx();
-
-	if (doc_list[idx].file_name == NULL)
-	{
-		dialogs->show_save_as();
-	}
-	else
-	{
-		documents->save_file(idx, FALSE);
-	}
-
-    if (doc_list[idx].file_name != NULL)
-	{
-		if (mailer)
-		{
-			locale_filename = utils->get_locale_from_utf8(doc_list[idx].file_name);
-			cmd_str = g_string_new(mailer);
-
-			if (! utils->string_replace_all(cmd_str, "%f", locale_filename))
-				ui->set_statusbar(FALSE, _("Filename placeholder not found. The executed command might have failed."));
-
-			command = g_string_free(cmd_str, FALSE);
-			g_spawn_command_line_async(command, &error);
-			if (error != NULL)
-			{
-				ui->set_statusbar(FALSE, _("Could not execute mailer. Please check your configuration."));
-				g_error_free(error);
-			}
-
-			g_free(locale_filename);
-			g_free(command);
-		}
-		else
-		{
-			ui->set_statusbar(FALSE, _("Have to define some mailing tool before."));
-		}
-	}
-	else
-	{
-		ui->set_statusbar(FALSE, _("File have to be saved before sending."));
-	}
-}
-
-static void key_send_as_attachment(G_GNUC_UNUSED guint key_id)
-{
-	send_as_attachment(NULL, NULL);
-}
-
-
 /* Called by Geany to initialize the plugin */
 void init(GeanyData *data)
 {
@@ -210,9 +244,8 @@
 	GtkWidget *menu_mail = NULL;
 	GtkWidget *menu_mail_submenu = NULL;
 	GtkWidget *menu_mail_attachment = NULL;
-	GdkPixbuf *pixbuf = NULL;
-	GtkWidget *icon = NULL;
 
+
 	config_file = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "plugins", G_DIR_SEPARATOR_S,
 		"geanysendmail", G_DIR_SEPARATOR_S, "mail.conf", NULL);
 
@@ -229,28 +262,7 @@
 
 	if (icon_in_toolbar == TRUE)
 	{
-
-		int number_of_icons = 0;
-		number_of_icons = gtk_toolbar_get_n_items(GTK_TOOLBAR(app->toolbar));
-		
-		pixbuf = gdk_pixbuf_new_from_inline(-1, mail_pixbuf, FALSE, NULL);
-		icon = gtk_image_new_from_pixbuf(pixbuf);
-		g_object_unref(pixbuf);
-
-		separator = (GtkWidget*) gtk_separator_tool_item_new();
-		gtk_widget_show (separator);
-		gtk_toolbar_insert(GTK_TOOLBAR(app->toolbar), GTK_TOOL_ITEM(separator), number_of_icons - 2);
-
-		mailbutton = (GtkWidget*) gtk_tool_button_new (icon, "Mail");
-		gtk_toolbar_insert(GTK_TOOLBAR(app->toolbar), GTK_TOOL_ITEM(mailbutton), number_of_icons - 1);
-		g_signal_connect (G_OBJECT(mailbutton), "clicked", G_CALLBACK(send_as_attachment), NULL);
-		gtk_widget_show_all (mailbutton);
-	
-		separator2 = (GtkWidget*) gtk_separator_tool_item_new();
-		gtk_widget_show (separator2);
-		gtk_toolbar_insert(GTK_TOOLBAR(app->toolbar), GTK_TOOL_ITEM(separator2), number_of_icons);
-
-
+		show_icon();
 	}
 
 	// Build up menu


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Plugins-Commits mailing list