Commit 66d86ee5 authored by Murray Cumming's avatar Murray Cumming Committed by Murray Cumming
Browse files

Added missing file to fix the build.

2009-03-30  Murray Cumming  <murrayc@murrayc.com>

* glom/glade_utils.cc: Added missing file to fix the build.

* glom/Makefile.am:
* glom/libglom/Makefile.am:
* glom/libglom/utils.cc:
* glom/libglom/utils.h: Moved some of these functions to new 
glom/utils_ui.[h|cc] files to avoid having the UI stuff in libglom.
*.cc: Adapted.
glom/libglom/connectionpool.[h|cc]:
* glom/libglom/connectionpool_backends/backend.[h|cc]:
* glom/libglom/connectionpool_backends/postgres.[h|cc]:
* glom/libglom/connectionpool_backends/postgres_self.[h|cc]: 
initialize(): Return an enum instead of a bool, to report errors, instead of 
showing a UI warning here.
Added set_avahi_publish_callbacks() to avoid showing that UI here.
* glom/frame_glom.[h|cc]: Adapt to the new API, showing UI here instead of 
in libglom.

* glom/libglom/spawn_with_feedback.cc: Disconnect the progress timeout 
dlers.

* glom/libglom/data_structure/layout/layoutitem_image.[h|cc]: Removed 
get_image_as_pixbuf() to avoid a gtkmm dependency in libglom. Made m_image 
public instead, to avoid performance problems with copying lots of binary 
data via a get*() method.
* glom/libglom/document/document_glom.cc: Adapted.

* glom/libglom/data_structure/print_layout.[h|cc]: Use a string instead of a 
Gtk::PrintLayout, using the Glib::KeyFile format, to avoid depending on gtkmm 
in libglom.
* glom/mode_design/print_layouts/canvas_layout_item.cc:
* glom/mode_design/print_layouts/canvas_print_layout.cc: Adapted.

svn path=/trunk/; revision=2034
parent 64acd12c
2009-03-30 Murray Cumming <murrayc@murrayc.com>
* glom/glade_utils.cc: Added missing file to fix the build.
* glom/Makefile.am:
* glom/libglom/Makefile.am:
* glom/libglom/utils.cc:
* glom/libglom/utils.h: Moved some of these functions to new
glom/utils_ui.[h|cc] files to avoid having the UI stuff in libglom.
*.cc: Adapted.
* glom/libglom/connectionpool.[h|cc]:
* glom/libglom/connectionpool_backends/backend.[h|cc]:
* glom/libglom/connectionpool_backends/postgres.[h|cc]:
* glom/libglom/connectionpool_backends/postgres_self.[h|cc]:
initialize(): Return an enum instead of a bool, to report errors, instead of
showing a UI warning here.
Added set_avahi_publish_callbacks() to avoid showing that UI here.
* glom/frame_glom.[h|cc]: Adapt to the new API, showing UI here instead of
in libglom.
* glom/libglom/spawn_with_feedback.cc: Disconnect the progress timeout
handlers.
* glom/libglom/data_structure/layout/layoutitem_image.[h|cc]: Removed
get_image_as_pixbuf() to avoid a gtkmm dependency in libglom. Made m_image
public instead, to avoid performance problems with copying lots of binary
data via a get*() method.
* glom/libglom/document/document_glom.cc: Adapted.
* glom/libglom/data_structure/print_layout.[h|cc]: Use a string instead of a
Gtk::PrintLayout, using the Glib::KeyFile format, to avoid depending on gtkmm
in libglom.
* glom/mode_design/print_layouts/canvas_layout_item.cc:
* glom/mode_design/print_layouts/canvas_print_layout.cc: Adapted.
2009-03-27 Murray Cumming <murrayc@murrayc.com>
 
* glom/bakery/app_withdoc.[h|cc]: Added on_document_close() virtual method
......@@ -22,7 +58,7 @@
allowing the caller to show UI if it wants, removing UI code from this part of
libglom.
* glom/Makefile.am:
* glom/Makefile.am:
* glom/libglom/dialog_progress_creating.[h|cc]: moved to
* glom/glom/glade_utils.[h|cc]: Moved get_and_show_pulse_dialog() here.
......
......@@ -51,6 +51,7 @@ glom_SOURCES = main.cc \
dialog_progress_creating.h dialog_progress_creating.cc \
box_reports.h box_reports.cc \
xsl_utils.h xsl_utils.cc \
utils_ui.h utils_ui.cc \
variablesmap.h variablesmap.cc \
signal_reemitter.h glade_utils.h glade_utils.cc
......
......@@ -31,12 +31,9 @@
#include <glom/utility_widgets/filechooserdialog_saveextras.h>
#endif // !GLOM_ENABLE_CLIENT_ONLY
#include <libglom/utils.h>
#include <glom/utils_ui.h>
#include <glom/glade_utils.h>
//#include <libglom/connectionpool_backends/postgres_central.h>
//#include <libglom/connectionpool_backends/postgres_self.h>
#include <cstdio>
#include <memory> //For std::auto_ptr<>
#include <giomm.h>
......@@ -107,6 +104,7 @@ App_Glom::App_Glom(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& bu
m_ui_save_extra_newdb_hosting_mode(Document_Glom::DEFAULT_HOSTED),
#endif // !GLOM_ENABLE_CLIENT_ONLY
m_avahi_progress_dialog(0),
m_show_sql_debug(false)
{
#ifdef GLIBMM_EXCEPTIONS_ENABLED
......@@ -143,6 +141,14 @@ App_Glom::App_Glom(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& bu
//Hide the toolbar because it doesn't contain anything useful for this app.
m_HandleBox_Toolbar.hide();
//Install UI hooks for this:
ConnectionPool* connection_pool = ConnectionPool::get_instance();
if(!connection_pool)
connection_pool->set_avahi_publish_callbacks(
sigc::mem_fun(*this, &App_Glom::on_connection_avahi_begin),
sigc::mem_fun(*this, &App_Glom::on_connection_avahi_progress),
sigc::mem_fun(*this, &App_Glom::on_connection_avahi_done) );
global_application = this;
}
......@@ -155,6 +161,44 @@ App_Glom::~App_Glom()
delete m_window_translations;
}
#endif // !GLOM_ENABLE_CLIENT_ONLY
if(m_avahi_progress_dialog)
{
delete m_avahi_progress_dialog;
m_avahi_progress_dialog = 0;
}
}
void App_Glom::on_connection_avahi_begin()
{
//Create the dialog:
if(m_avahi_progress_dialog)
{
delete m_avahi_progress_dialog;
m_avahi_progress_dialog = 0;
}
m_avahi_progress_dialog = new Gtk::MessageDialog(Utils::bold_message(_("Glom: Generating Encryption Certificates")), true, Gtk::MESSAGE_INFO);
m_avahi_progress_dialog->set_secondary_text(_("Please wait while Glom prepares your system for publishing over the network."));
m_avahi_progress_dialog->set_transient_for(*this);
m_avahi_progress_dialog->show();
}
void App_Glom::on_connection_avahi_progress()
{
//Allow GTK+ to process events, so that the UI is responsive:
while(Gtk::Main::events_pending())
Gtk::Main::iteration();
}
void App_Glom::on_connection_avahi_done()
{
//Delete the dialog:
if(m_avahi_progress_dialog)
{
delete m_avahi_progress_dialog;
m_avahi_progress_dialog = 0;
}
}
bool App_Glom::init(const Glib::ustring& document_uri)
......
......@@ -117,6 +117,10 @@ private:
bool recreate_database(bool& user_cancelled); //return indicates success.
void stop_self_hosting_of_document_database();
void on_connection_avahi_begin();
void on_connection_avahi_progress();
void on_connection_avahi_done();
#endif // !GLOM_ENABLE_CLIENT_ONLY
#ifndef G_OS_WIN32
......@@ -190,6 +194,8 @@ private:
//so we can use them again when connecting directly to the database:
Glib::ustring m_temp_username, m_temp_password;
Gtk::MessageDialog* m_avahi_progress_dialog;
bool m_show_sql_debug;
};
......
......@@ -36,7 +36,7 @@
//#endif // !GLOM_ENABLE_CLIENT_ONLY
//#include "reports/dialog_layout_report.h"
#include <libglom/utils.h>
#include <glom/utils_ui.h>
#include <glom/glade_utils.h>
#include <libglom/data_structure/glomconversions.h>
#include <libglom/data_structure/parameternamegenerator.h>
......@@ -155,7 +155,7 @@ void Base_DB::handle_error(const std::exception& ex)
bool Base_DB::handle_error()
{
return ConnectionPool::handle_error();
return ConnectionPool::handle_error_cerr_only();
}
//static:
......
......@@ -22,6 +22,7 @@
#include <libglom/data_structure/glomconversions.h>
#include <glom/application.h>
#include "python_embed/glom_python.h"
#include <glom/utils_ui.h>
#include <sstream>
#include <glibmm/i18n.h>
......
......@@ -19,7 +19,8 @@
*/
#include "box_withbuttons.h"
#include "application.h" //App_Glom.
#include <glom/application.h> //App_Glom.
#include <glom/utils_ui.h>
#include <libglom/appstate.h>
//#include <libgnomeui/gnome-app-helper.h>
......
......@@ -18,7 +18,8 @@
* Boston, MA 02111-1307, USA.
*/
#include "dialog_glom.h"
#include <glom/dialog_glom.h>
#include <glom/utils_ui.h>
namespace Glom
{
......
......@@ -20,7 +20,7 @@
#include "dialog_invalid_data.h"
#include <libglom/data_structure/glomconversions.h>
#include <libglom/utils.h>
#include <glom/utils_ui.h>
#include <glom/glade_utils.h>
namespace Glom
......@@ -48,7 +48,7 @@ bool glom_show_dialog_invalid_data(Field::glom_field_type glom_type)
refXml->get_widget_derived("dialog_data_invalid_format", dialog);
dialog->set_example_data(glom_type);
//dialog->set_transient_for(*this);
int response = Glom::Utils::dialog_run_with_help(dialog, "dialog_data_invalid_format");
const int response = Glom::Utils::dialog_run_with_help(dialog, "dialog_data_invalid_format");
delete dialog;
return (response == 2); //The glade file has a response of 2 for the Revert button.
......
......@@ -31,8 +31,7 @@ Dialog_NewSelfHostedConnection::Dialog_NewSelfHostedConnection(BaseObjectType* c
: Gtk::Dialog(cobject),
Base_DB(),
m_entry_user(0),
m_entry_password(0),
m_dialog_progess_connection_initialize(0)
m_entry_password(0)
{
builder->get_widget("entry_user", m_entry_user);
builder->get_widget("entry_password", m_entry_password);
......@@ -41,54 +40,16 @@ Dialog_NewSelfHostedConnection::Dialog_NewSelfHostedConnection(BaseObjectType* c
Dialog_NewSelfHostedConnection::~Dialog_NewSelfHostedConnection()
{
if(m_dialog_progess_connection_initialize)
{
delete m_dialog_progess_connection_initialize;
m_dialog_progess_connection_initialize = 0;
}
}
void Dialog_NewSelfHostedConnection::on_connection_initialization_progress()
Glib::ustring Dialog_NewSelfHostedConnection::get_user() const
{
if(!m_dialog_progess_connection_initialize)
m_dialog_progess_connection_initialize = Utils::get_and_show_pulse_dialog(_("Creating Database Data"), this);
m_dialog_progess_connection_initialize->pulse();
return m_entry_user->get_text();
}
bool Dialog_NewSelfHostedConnection::create_self_hosted()
Glib::ustring Dialog_NewSelfHostedConnection::get_password() const
{
//std::cout << "debug: Dialog_NewSelfHostedConnection::connect_to_server_with_connection_settings()" << std::endl;
//TODO: BusyCursor busy_cursor(get_app_window());
ConnectionPool* connection_pool = ConnectionPool::get_instance();
if(connection_pool)
{
//Set the connection details in the ConnectionPool singleton.
//The ConnectionPool will now use these every time it tries to connect.
const Document_Glom* document = get_document();
if(document)
{
// Create the files needed to self-host a database:
//connection_pool->set_self_hosted() has already been called.
connection_pool->set_user(m_entry_user->get_text());
connection_pool->set_password(m_entry_password->get_text());
//std::cout << "debug: Dialog_NewSelfHostedConnection::create_self_hosted() user=" << m_entry_user->get_text() << ", password=" << m_entry_password->get_text() << std::endl;
const bool created = connection_pool->initialize(
sigc::mem_fun(*this, &Dialog_NewSelfHostedConnection::on_connection_initialization_progress) );
if(!created)
{
return false;
}
return true;
}
}
return false;
return m_entry_password->get_text();
}
void Dialog_NewSelfHostedConnection::load_from_document()
......
......@@ -31,8 +31,6 @@
namespace Glom
{
class Dialog_ProgressCreating;
class Dialog_NewSelfHostedConnection
: public Gtk::Dialog,
public Base_DB
......@@ -43,19 +41,17 @@ public:
bool check_password();
bool create_self_hosted();
Glib::ustring get_user() const;
Glib::ustring get_password() const;
virtual void load_from_document(); //override
private:
void on_connection_initialization_progress();
Gtk::Entry* m_entry_user;
Gtk::Entry* m_entry_password;
Gtk::Entry* m_entry_password_confirm;
Dialog_ProgressCreating* m_dialog_progess_connection_initialize;
};
} //namespace Glom
......
......@@ -20,7 +20,7 @@
#include "filechooser_export.h"
#include "mode_data/dialog_layout_export.h"
#include <libglom/utils.h>
#include <glom/utils_ui.h>
#include <glom/glade_utils.h>
#include <gtkmm/stock.h>
#include <glibmm/i18n.h>
......
......@@ -20,10 +20,10 @@
#include <libglom/libglom_config.h> // For GLOM_ENABLE_SQLITE, GLOM_ENABLE_CLIENT_ONLY
#include "frame_glom.h"
#include "application.h"
#include "dialog_import_csv.h"
#include "dialog_import_csv_progress.h"
#include <glom/frame_glom.h>
#include <glom/application.h>
#include <glom/dialog_import_csv.h>
#include <glom/dialog_import_csv_progress.h>
#include <libglom/appstate.h>
#include <libglom/connectionpool.h>
......@@ -48,7 +48,7 @@
#include "relationships_overview/dialog_relationships_overview.h"
#endif // !GLOM_ENABLE_CLIENT_ONLY
#include <libglom/utils.h>
#include <glom/utils_ui.h>
#include <glom/glade_utils.h>
#include <libglom/data_structure/glomconversions.h>
#include <libglom/data_structure/layout/report_parts/layoutitem_summary.h>
......@@ -103,6 +103,7 @@ Frame_Glom::Frame_Glom(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>
m_dialog_relationships_overview(0),
#endif // !GLOM_ENABLE_CLIENT_ONLY
m_pDialogConnection(0),
m_dialog_progess_connection_initialize(0),
m_dialog_progess_connection_startup(0),
m_dialog_progess_connection_cleanup(0)
{
......@@ -180,6 +181,12 @@ Frame_Glom::~Frame_Glom()
m_pDialogConnection = 0;
}
if(m_dialog_progess_connection_initialize)
{
delete m_dialog_progess_connection_initialize;
m_dialog_progess_connection_initialize = 0;
}
if(m_dialog_progess_connection_startup)
{
delete m_dialog_progess_connection_startup;
......@@ -1706,6 +1713,15 @@ namespace
}
}
void Frame_Glom::on_connection_initialize_progress()
{
if(!m_dialog_progess_connection_initialize)
m_dialog_progess_connection_initialize = Utils::get_and_show_pulse_dialog(_("Initializing Database Data"), get_app_window());
m_dialog_progess_connection_initialize->pulse();
}
void Frame_Glom::on_connection_startup_progress()
{
if(!m_dialog_progess_connection_startup)
......@@ -1722,6 +1738,34 @@ void Frame_Glom::on_connection_cleanup_progress()
m_dialog_progess_connection_cleanup->pulse();
}
bool Frame_Glom::handle_connection_initialize_errors(ConnectionPool::InitErrors error)
{
Glib::ustring title;
Glib::ustring message;
if(error == ConnectionPool::Backend::INITERROR_NONE)
return true;
else if(error == ConnectionPool::Backend::INITERROR_DIRECTORY_ALREADY_EXISTS)
{
title = _("Directory Already Exists");
message = _("There is an existing directory with the same name as the directory that should be created for the new database files. You should specify a different filename to use a new directory instead.");
}
else if (error == ConnectionPool::Backend::INITERROR_COULD_NOT_CREATE_DIRECTORY)
{
title = _("Could Not Create Directory");
message = _("There was an error when attempting to create the directory for the new database files.");
}
else if(error == ConnectionPool::Backend::INITERROR_COULD_NOT_START_SERVER)
{
title = _("Could Not Start Database Server");
message = _("There was an error when attempting to start the database server.");
}
Utils::show_ok_dialog(title, message, *get_app_window(), Gtk::MESSAGE_ERROR);
return false;
}
bool Frame_Glom::connection_request_password_and_choose_new_database_name()
{
Document_Glom* document = dynamic_cast<Document_Glom*>(get_document());
......@@ -1778,7 +1822,7 @@ bool Frame_Glom::connection_request_password_and_choose_new_database_name()
bool keep_trying = true;
while(keep_trying)
{
response = Glom::Utils::dialog_run_with_help(dialog, "dialog_new_self_hosted_connection");
response = Utils::dialog_run_with_help(dialog, "dialog_new_self_hosted_connection");
//Check the password is acceptable:
if(response == Gtk::RESPONSE_OK)
......@@ -1797,24 +1841,34 @@ bool Frame_Glom::connection_request_password_and_choose_new_database_name()
dialog->hide();
// Create the requested self-hosting database:
bool created = false;
if(response == Gtk::RESPONSE_OK)
{
created = dialog->create_self_hosted();
if(!created)
//Set the connection details in the ConnectionPool singleton.
//The ConnectionPool will now use these every time it tries to connect.
connection_pool->set_user(dialog->get_user());
connection_pool->set_password(dialog->get_password());
const bool initialized = handle_connection_initialize_errors( connection_pool->initialize(
sigc::mem_fun(*this, &Frame_Glom::on_connection_initialize_progress) ) );
if(m_dialog_progess_connection_initialize)
{
delete m_dialog_progess_connection_initialize;
m_dialog_progess_connection_initialize = 0;
}
if(!initialized)
return false;
//Put the details into m_pDialogConnection too, because that's what we use to connect.
//This is a bit of a hack:
//Put the details into m_pDialogConnection too, because that's what we use to connect.
//This is a bit of a hack:
m_pDialogConnection->set_self_hosted_user_and_password(connection_pool->get_user(), connection_pool->get_password());
}
remove_view(dialog);
//std::cout << "DEBUG: after dialog->create_self_hosted(). The database cluster should now exist." << std::endl;
//std::cout << "DEBUG: after connection_pool->initialize(). The database cluster should now exist." << std::endl;
if(!created)
return false; // The user cancelled
#else
// Self-hosted postgres not supported in client only mode
g_assert_not_reached();
......@@ -1835,7 +1889,7 @@ bool Frame_Glom::connection_request_password_and_choose_new_database_name()
// We are not self-hosting, but we also call initialize() for
// consistency (the backend will ignore it anyway).
ConnectionPool::SlotProgress slot_ignored;
if(!connection_pool->initialize(slot_ignored))
if(!handle_connection_initialize_errors( connection_pool->initialize(slot_ignored)) )
return false;
}
else
......@@ -1851,7 +1905,8 @@ bool Frame_Glom::connection_request_password_and_choose_new_database_name()
case Document_Glom::HOSTING_MODE_SQLITE:
{
// sqlite
if(!connection_pool->initialize(get_app_window()))
ConnectionPool::SlotProgress slot_ignored;
if(!handle_connection_initialize_errors( connection_pool->initialize(slot_ignored)) )
return false;
m_pDialogConnection->load_from_document(); //Get good defaults.
......@@ -2251,7 +2306,20 @@ void Frame_Glom::on_menu_print_layout_selected(const Glib::ustring& print_layout
print->set_canvas(&canvas);
print->set_track_print_status();
print->set_default_page_setup(print_layout->get_page_setup());
//TODO: Put this in a utility function.
Glib::RefPtr<Gtk::PageSetup> page_setup;
const Glib::ustring key_file_text = print_layout->get_page_setup();
if(!key_file_text.empty())
{
Glib::KeyFile key_file;
key_file.load_from_data(key_file_text);
//TODO: Use this when gtkmm and GTK+ have been fixed: page_setup = Gtk::PageSetup::create(key_file);
page_setup = Glib::wrap(gtk_page_setup_new_from_key_file(key_file.gobj(), NULL, NULL));
}
print->set_default_page_setup(page_setup);
//print->set_print_settings(m_refSettings);
//print->signal_done().connect(sigc::bind(sigc::mem_fun(*this,
......
......@@ -218,9 +218,11 @@ protected:
void on_dialog_add_related_table_response(int response);
#endif // !GLOM_ENABLE_CLIENT_ONLY
void on_connection_initialize_progress();
void on_connection_startup_progress();
void on_connection_cleanup_progress();
void cleanup_connection();
bool handle_connection_initialize_errors(ConnectionPool::InitErrors error);
//Member data:
Glib::ustring m_table_name;
......@@ -268,6 +270,7 @@ protected:
#endif // !GLOM_ENABLE_CLIENT_ONLY
Dialog_Connection* m_pDialogConnection;
Dialog_ProgressCreating* m_dialog_progess_connection_initialize;
Dialog_ProgressCreating* m_dialog_progess_connection_startup;
Dialog_ProgressCreating* m_dialog_progess_connection_cleanup;
};
......
/* Glom
*
* Copyright (C) 2001-2004 Murray Cumming
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <glom/glade_utils.h>
#include <glibmm/i18n.h>
namespace Glom
{
namespace Utils
{
Dialog_ProgressCreating* get_and_show_pulse_dialog(const Glib::ustring& message, Gtk::Window* parent_window)
{
if(!parent_window)
std::cerr << "debug: Glom: get_and_show_pulse_dialog(): parent_window is NULL" << std::endl;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::RefPtr<Gtk::Builder> refXml = Gtk::Builder::create_from_file(Utils::get_glade_file_path("glom.glade"), "window_progress");
#else
std::auto_ptr<Glib::Error> error;
Glib::RefPtr<Gtk::Builder> refXml = Gtk::Builder::create_from_file(Utils::get_glade_file_path("glom.glade"), "window_progress", "", error);
if(error.get())
return 0;
#endif
if(refXml)
{
Dialog_ProgressCreating* dialog_progress = 0;
refXml->get_widget_derived("window_progress", dialog_progress);
if(dialog_progress)
{
dialog_progress->set_message(_("Processing"), message);
dialog_progress->set_modal();
if(parent_window)
dialog_progress->set_transient_for(*parent_window);
dialog_progress->show();
return dialog_progress;
}
}
return 0;
}
} //namespace Utils
} //namespace Glom
......@@ -18,8 +18,9 @@
* Boston, MA 02111-1307, USA.
*/
#include "dialog_group_by.h"
#include <glom/layout_item_dialogs/dialog_group_by.h>
#include <libglom/data_structure/glomconversions.h>
#include <glom/utils_ui.h>
#include <glom/glade_utils.h>
#include <sstream> //For stringstream