Esempio n. 1
0
static PyObject *
Dialogs_show_input(PyObject *self, PyObject *args, PyObject *kwargs)
{
    (void)self;
    const gchar *title=NULL, *label_text=NULL, *default_text=NULL, *result=NULL;
    PyObject *py_win_obj = NULL;
    PyGObject *py_win_gobj;
    GtkWindow *win;
	static gchar *kwlist[] = { "title", "parent", "label_text", "default_text", NULL };

	if (PyArg_ParseTupleAndKeywords(args, kwargs, "|zOzz", kwlist,
		&title, &py_win_obj, &label_text, &default_text))
	{
        if (title == NULL)
            title = "";

        if (py_win_obj != NULL && py_win_obj != Py_None)
        {
            py_win_gobj = (PyGObject *) py_win_obj;
            win = GTK_WINDOW((GObject *) py_win_gobj->obj);
        }
        else
            win = GTK_WINDOW(geany->main_widgets->window);

        result = dialogs_show_input(title, win, label_text, default_text);
        if (result != NULL)
            return PyString_FromString(result);
    }

    Py_RETURN_NONE;
}
Esempio n. 2
0
/* Callback for sending file as attachment */
static void
send_as_attachment(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata)
{
	GeanyDocument *doc;
	gchar	*locale_filename = NULL;
	gchar	*command = NULL;
	GError	*error = NULL;
	GString	*cmd_str = NULL;
	gchar 		*data;

	doc = document_get_current();

	if (doc->file_name == NULL)
	{
		dialogs_show_save_as();
	}
	else
	{
		document_save_file(doc, FALSE);
	}

    if (doc->file_name != NULL)
	{
		if (mailer)
		{
			locale_filename = utils_get_locale_from_utf8(doc->file_name);
			cmd_str = g_string_new(mailer);
			if ((use_address_dialog == TRUE) && (g_strrstr(mailer, "%r") != NULL))
			{
				GKeyFile *config = NULL;
				gchar *config_dir = NULL;
 				gchar *input = dialogs_show_input(_("Recipient's Address"),
										GTK_WINDOW(geany->main_widgets->window),
										_("Enter the recipient's e-mail address:"),
										address);

				if (input)
				{
					config = g_key_file_new();
					g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL);

					g_free(address);
 					address = input;

 					g_key_file_set_string(config, "tools", "address", address);
 				}
 				else
 				{
					g_string_free(cmd_str, TRUE);
					g_free(locale_filename);
					return;
				}

				config_dir = g_path_get_dirname(config_file);


				if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) &&
				      utils_mkdir(config_dir, TRUE) != 0)
 				{
 					dialogs_show_msgbox(GTK_MESSAGE_ERROR,
 						_("Plugin configuration directory could not be created."));
 				}
 				else
 				{
 					/* write config to file */
 					data = g_key_file_to_data(config, NULL, NULL);
 					utils_write_file(config_file, data);
					g_free(data);
 				}
				g_key_file_free(config);
				g_free(config_dir);
 			}

			if (! utils_string_replace_all(cmd_str, "%f", locale_filename))
				ui_set_statusbar(FALSE,
				_("Filename placeholder not found. The executed command might have failed."));

			if (use_address_dialog == TRUE && address != NULL)
			{
				if (! utils_string_replace_all(cmd_str, "%r", address))
 					ui_set_statusbar(FALSE,
					_("Recipient address placeholder not found. The executed command might have failed."));
			}
			else
			{
				/* Removes %r if option was not activ but was included into command */
				utils_string_replace_all(cmd_str, "%r", "");
			}

			utils_string_replace_all(cmd_str, "%b", g_path_get_basename(locale_filename));

			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, _("Please define a mail client first."));
		}
	}
	else
	{
		ui_set_statusbar(FALSE, _("File has to be saved before sending."));
	}
}