static void
xml_planner_plugin_export (GtkAction *action,
			   gpointer   user_data)
{
	PlannerPlugin     *plugin;
	MrpProject        *project;
	GError            *error = NULL;
	GtkWidget         *file_chooser;
	GtkWidget         *dialog;
	gint               response;
	gchar             *filename = NULL;
	gchar             *real_filename;
	gchar             *last_dir;

	plugin = PLANNER_PLUGIN (user_data);

 try_again:

	file_chooser = gtk_file_chooser_dialog_new (_("Export"),
						    GTK_WINDOW (plugin->main_window),
						    GTK_FILE_CHOOSER_ACTION_SAVE,
						    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
						    GTK_STOCK_SAVE, GTK_RESPONSE_OK,
						    NULL);
	gtk_window_set_modal (GTK_WINDOW (file_chooser), TRUE);

	last_dir = get_last_dir ();
	gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (file_chooser), last_dir);
	g_free (last_dir);

	response = gtk_dialog_run (GTK_DIALOG (file_chooser));
	if (response == GTK_RESPONSE_OK) {
		filename = gtk_file_chooser_get_filename (
			GTK_FILE_CHOOSER (file_chooser));
	}

	gtk_widget_destroy (file_chooser);

	if (filename) {
		if (!g_str_has_suffix (filename, ".mrproject") && !g_str_has_suffix (filename, ".planner")) {
			/* Add the old extension for old format files. */
			real_filename = g_strconcat (filename, ".mrproject", NULL);
		} else {
			real_filename = g_strdup (filename);
		}

		if (g_file_test (real_filename, G_FILE_TEST_EXISTS)) {
			dialog = gtk_message_dialog_new (GTK_WINDOW (plugin->main_window),
							 GTK_DIALOG_MODAL |
							 GTK_DIALOG_DESTROY_WITH_PARENT,
							 GTK_MESSAGE_WARNING,
							 GTK_BUTTONS_YES_NO,
							 _("File \"%s\" exists, "
							   "do you want to overwrite it?"),
							 real_filename);

			response = gtk_dialog_run (GTK_DIALOG (dialog));
			gtk_widget_destroy (dialog);

			switch (response) {
			case GTK_RESPONSE_YES:
				break;
			default:
				g_free (real_filename);
				goto try_again;
			}
		}
	}

	if (!filename) {
		return;
	}

	project = planner_window_get_project (plugin->main_window);

	if (!mrp_project_export (project, real_filename,
				 "Planner XML pre-0.12",
				 TRUE,
				 &error)) {
		g_warning ("Error while export to Planner XML: %s", error->message);
	}

	last_dir = g_path_get_dirname (real_filename);
	planner_conf_set_string (CONF_MAIN_LAST_XML_EXPORT_DIR, last_dir, NULL);
	g_free (last_dir);

	g_free (real_filename);
	g_free (filename);
}
Exemple #2
0
static void
msp_plugin_set_last_dir (PlannerPlugin *plugin,
                         const gchar   *dir)
{
    planner_conf_set_string (CONF_MSP_PLUGIN_LAST_DIR, dir, NULL);
}
Exemple #3
0
static gboolean
sql_plugin_retrieve_db_values (PlannerPlugin  *plugin,
			       const gchar    *title,
			       gchar         **server,
			       gchar         **port,
			       gchar         **database,
			       gchar         **login,
			       gchar         **password)
{
	PlannerApplication *application;
	gchar              *filename;
	GladeXML           *gui;
	GtkWidget          *dialog;
	gchar              *str;
	gint                response;
	GtkWidget          *server_entry;
	GtkWidget          *db_entry;
	GtkWidget          *user_entry;
	GtkWidget          *password_entry;
	gboolean            ret;

	application = planner_window_get_application (plugin->main_window);

	filename = mrp_paths_get_glade_dir ("sql.glade");
	gui = glade_xml_new (filename, "open_dialog" , NULL);
	g_free (filename);

	dialog = glade_xml_get_widget (gui, "open_dialog");

	gtk_window_set_title (GTK_WINDOW (dialog), title);

	server_entry   = glade_xml_get_widget (gui, "server_entry");
	db_entry       = glade_xml_get_widget (gui, "db_entry");
	user_entry     = glade_xml_get_widget (gui, "user_entry");
	password_entry = glade_xml_get_widget (gui, "password_entry");

	str = planner_conf_get_string (CONF_SERVER, NULL);
	if (str) {
		gtk_entry_set_text (GTK_ENTRY (server_entry), str);
		g_free (str);
	}

	str = planner_conf_get_string (CONF_DATABASE, NULL);
	if (str) {
		gtk_entry_set_text (GTK_ENTRY (db_entry), str);
		g_free (str);
	}

	str = planner_conf_get_string (CONF_USERNAME, NULL);
	if (str) {
		gtk_entry_set_text (GTK_ENTRY (user_entry), str);
		g_free (str);
	}

	g_object_unref (gui);

	response = gtk_dialog_run (GTK_DIALOG (dialog));

	switch (response) {
	case GTK_RESPONSE_OK:
		*server = strdup_null_if_empty (gtk_entry_get_text (GTK_ENTRY (server_entry)));
		*port = NULL;
		*database = strdup_null_if_empty (gtk_entry_get_text (GTK_ENTRY (db_entry)));
		*login = strdup_null_if_empty (gtk_entry_get_text (GTK_ENTRY (user_entry)));
		*password = strdup_null_if_empty (gtk_entry_get_text (GTK_ENTRY (password_entry)));

		planner_conf_set_string (CONF_SERVER,
					 *server ? *server : "",
					 NULL);

		planner_conf_set_string (CONF_DATABASE,
					 *database ? *database : "",
					 NULL);

		planner_conf_set_string (CONF_USERNAME,
					 *login ? *login : "",
					 NULL);
		ret = TRUE;
		break;

	default:
		ret = FALSE;
		break;
	}

	gtk_widget_destroy (dialog);

	return ret;
}