[glom/maemo5] In the client-only build,
- From: Murray Cumming <murrayc src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glom/maemo5] In the client-only build,
- Date: Sat, 5 Sep 2009 12:09:35 +0000 (UTC)
commit 6e9869c86643c800e4676d4f0695380acab93fb0
Author: Murray Cumming <murrayc murrayc com>
Date: Sat Sep 5 14:09:19 2009 +0200
In the client-only build,
actually handle the enum for opening an existing file in client mode.
ChangeLog | 5 +
glom/application.cc | 360 +++++++++++++++++++++++++--------------------------
glom/frame_glom.cc | 2 +
3 files changed, 185 insertions(+), 182 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 94cc416..8cbbdf7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2009-09-05 Murray Cumming <murrayc murrayc com>
+ * glom/application.cc: offer_new_or_existing(): In the client-only build,
+ actually handle the enum for opening an existing file in client mode.
+
+2009-09-05 Murray Cumming <murrayc murrayc com>
+
offer_new_or_existing(): Add Gtk::Builder error handling .
* glom/application.cc: offer_new_or_existing(): Add error handling to
diff --git a/glom/application.cc b/glom/application.cc
index 36fb434..a703bed 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -918,240 +918,236 @@ bool App_Glom::on_document_load()
//m_pFrame->load_from_document();
Document* pDocument = static_cast<Document*>(get_document());
if(!pDocument)
- {
return false;
- }
- else
- {
+
#ifndef GLOM_ENABLE_CLIENT_ONLY
- //Connect signals:
- pDocument->signal_userlevel_changed().connect( sigc::mem_fun(*this, &App_Glom::on_userlevel_changed) );
+ //Connect signals:
+ pDocument->signal_userlevel_changed().connect( sigc::mem_fun(*this, &App_Glom::on_userlevel_changed) );
- //Disable/Enable actions, depending on userlevel:
- pDocument->emit_userlevel_changed();
+ //Disable/Enable actions, depending on userlevel:
+ pDocument->emit_userlevel_changed();
#endif // !GLOM_ENABLE_CLIENT_ONLY
- if(pDocument->get_connection_database().empty()) //If it is a new (default) document.
- {
- //offer_new_or_existing();
- }
- else
- {
+ if(pDocument->get_connection_database().empty()) //If it is a new (default) document.
+ {
+ //offer_new_or_existing();
+ }
+ else
+ {
#ifndef GLOM_ENABLE_CLIENT_ONLY
- //Prevent saving until we are sure that everything worked.
- //This also stops us from losing the example data as soon as we say the new file (created from the example) is not an example.
- pDocument->set_allow_autosave(false);
+ //Prevent saving until we are sure that everything worked.
+ //This also stops us from losing the example data as soon as we say the new file (created from the example) is not an example.
+ pDocument->set_allow_autosave(false);
#endif // !GLOM_ENABLE_CLIENT_ONLY
- // Example files are not supported in client only mode because they
- // would need to be saved, but saving support is disabled.
+ // Example files are not supported in client only mode because they
+ // would need to be saved, but saving support is disabled.
#ifndef GLOM_ENABLE_CLIENT_ONLY
- const bool is_example = pDocument->get_is_example_file();
+ const bool is_example = pDocument->get_is_example_file();
#endif // !GLOM_ENABLE_CLIENT_ONLY
- if(pDocument->get_is_example_file())
- {
+ if(pDocument->get_is_example_file())
+ {
#ifndef GLOM_ENABLE_CLIENT_ONLY
- // Remember the URI to the example file to be able to prevent
- // adding the URI to the recently used files in document_history_add.
- // We want to add the document that is created from the example
- // instead of the example itself.
- // TODO: This is a weird hack. Find a nicer way. murrayc.
- m_example_uri = pDocument->get_file_uri();
-
- pDocument->set_file_uri(Glib::ustring()); //Prevent it from defaulting to the read-only examples directory when offering saveas.
- //m_ui_save_extra_* are used by offer_saveas() if it's not empty:
- m_ui_save_extra_showextras = true;
- m_ui_save_extra_title = _("Creating From Example File");
- m_ui_save_extra_message = _("To use this example file you must save an editable copy of the file. A new database will also be created on the server.");
- m_ui_save_extra_newdb_title = "TODO";
- m_ui_save_extra_newdb_hosting_mode = Document::HOSTING_MODE_DEFAULT;
+ // Remember the URI to the example file to be able to prevent
+ // adding the URI to the recently used files in document_history_add.
+ // We want to add the document that is created from the example
+ // instead of the example itself.
+ // TODO: This is a weird hack. Find a nicer way. murrayc.
+ m_example_uri = pDocument->get_file_uri();
+
+ pDocument->set_file_uri(Glib::ustring()); //Prevent it from defaulting to the read-only examples directory when offering saveas.
+ //m_ui_save_extra_* are used by offer_saveas() if it's not empty:
+ m_ui_save_extra_showextras = true;
+ m_ui_save_extra_title = _("Creating From Example File");
+ m_ui_save_extra_message = _("To use this example file you must save an editable copy of the file. A new database will also be created on the server.");
+ m_ui_save_extra_newdb_title = "TODO";
+ m_ui_save_extra_newdb_hosting_mode = Document::HOSTING_MODE_DEFAULT;
- // Reinit cancelled state
- set_operation_cancelled(false);
+ // Reinit cancelled state
+ set_operation_cancelled(false);
- offer_saveas();
- // Note that bakery will try to add the example file itself to the
- // recently used documents, which is not what we want.
- m_ui_save_extra_message.clear();
- m_ui_save_extra_title.clear();
-
- if(!get_operation_cancelled())
- {
- //Get the results from the extended save dialog:
- pDocument->set_database_title(m_ui_save_extra_newdb_title);
- pDocument->set_hosting_mode(m_ui_save_extra_newdb_hosting_mode);
- m_ui_save_extra_newdb_hosting_mode = Document::HOSTING_MODE_DEFAULT;
- pDocument->set_is_example_file(false);
-
- // For self-hosting, we will choose a port later. For central
- // hosting, try several default ports. Don't use the values that
- // are set in the example file.
- pDocument->set_connection_port(0);
- pDocument->set_connection_try_other_ports(true);
-
- // We have a valid uri, so we can set it to !new and modified here
- }
+ offer_saveas();
+ // Note that bakery will try to add the example file itself to the
+ // recently used documents, which is not what we want.
+ m_ui_save_extra_message.clear();
+ m_ui_save_extra_title.clear();
+
+ if(!get_operation_cancelled())
+ {
+ //Get the results from the extended save dialog:
+ pDocument->set_database_title(m_ui_save_extra_newdb_title);
+ pDocument->set_hosting_mode(m_ui_save_extra_newdb_hosting_mode);
+ m_ui_save_extra_newdb_hosting_mode = Document::HOSTING_MODE_DEFAULT;
+ pDocument->set_is_example_file(false);
+
+ // For self-hosting, we will choose a port later. For central
+ // hosting, try several default ports. Don't use the values that
+ // are set in the example file.
+ pDocument->set_connection_port(0);
+ pDocument->set_connection_try_other_ports(true);
+
+ // We have a valid uri, so we can set it to !new and modified here
+ }
- m_ui_save_extra_newdb_title.clear();
- m_ui_save_extra_showextras = false;
+ m_ui_save_extra_newdb_title.clear();
+ m_ui_save_extra_showextras = false;
- if(get_operation_cancelled())
- {
- pDocument->set_modified(false);
- pDocument->set_is_new(true);
- std::cout << "debug: user cancelled creating database" << std::endl;
- return false;
- }
+ if(get_operation_cancelled())
+ {
+ pDocument->set_modified(false);
+ pDocument->set_is_new(true);
+ std::cout << "debug: user cancelled creating database" << std::endl;
+ return false;
+ }
#else // !GLOM_ENABLE_CLIENT_ONLY
- // TODO_clientonly: Tell the user that opening example files is
- // not supported. This could alternatively also be done in
- // Document_after::load_after, I am not sure which is better.
- return false;
+ // TODO_clientonly: Tell the user that opening example files is
+ // not supported. This could alternatively also be done in
+ // Document_after::load_after, I am not sure which is better.
+ return false;
#endif // GLOM_ENABLE_CLIENT_ONLY
- }
+ }
#ifndef GLOM_ENABLE_CLIENT_ONLY
- //Warn about read-only files, because users will otherwise wonder why they can't use Developer mode:
- Document::userLevelReason reason = Document::USER_LEVEL_REASON_UNKNOWN;
- const AppState::userlevels userlevel = pDocument->get_userlevel(reason);
- if( (userlevel == AppState::USERLEVEL_OPERATOR) && (reason == Document::USER_LEVEL_REASON_FILE_READ_ONLY) )
- {
- Gtk::MessageDialog dialog(Utils::bold_message(_("Opening Read-Only File.")), true, Gtk::MESSAGE_INFO, Gtk::BUTTONS_NONE);
- dialog.set_secondary_text(_("This file is read only, so you will not be able to enter Developer mode to make design changes."));
- dialog.set_transient_for(*this);
- dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
- dialog.add_button(_("Continue without Developer Mode"), Gtk::RESPONSE_OK); //arbitrary response code.
-
- const int response = dialog.run();
- dialog.hide();
- if((response == Gtk::RESPONSE_CANCEL) || (response == Gtk::RESPONSE_DELETE_EVENT))
- return false;
- }
+ //Warn about read-only files, because users will otherwise wonder why they can't use Developer mode:
+ const Document::userLevelReason reason = Document::USER_LEVEL_REASON_UNKNOWN;
+ const AppState::userlevels userlevel = pDocument->get_userlevel(reason);
+ if( (userlevel == AppState::USERLEVEL_OPERATOR) && (reason == Document::USER_LEVEL_REASON_FILE_READ_ONLY) )
+ {
+ Gtk::MessageDialog dialog(Utils::bold_message(_("Opening Read-Only File.")), true, Gtk::MESSAGE_INFO, Gtk::BUTTONS_NONE);
+ dialog.set_secondary_text(_("This file is read only, so you will not be able to enter Developer mode to make design changes."));
+ dialog.set_transient_for(*this);
+ dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ dialog.add_button(_("Continue without Developer Mode"), Gtk::RESPONSE_OK); //arbitrary response code.
+
+ const int response = dialog.run();
+ dialog.hide();
+ if((response == Gtk::RESPONSE_CANCEL) || (response == Gtk::RESPONSE_DELETE_EVENT))
+ return false;
+ }
#endif // !GLOM_ENABLE_CLIENT_ONLY
- //Read the connection information from the document:
- ConnectionPool* connection_pool = ConnectionPool::get_instance();
- if(!connection_pool)
- return false; //Impossible anyway.
- else
- {
+ //Read the connection information from the document:
+ ConnectionPool* connection_pool = ConnectionPool::get_instance();
+ if(!connection_pool)
+ return false; //Impossible anyway.
+ else
+ {
#ifndef GLOM_ENABLE_CLIENT_ONLY
- connection_pool->set_get_document_func( sigc::mem_fun(*this, &App_Glom::on_connection_pool_get_document) );
+ connection_pool->set_get_document_func( sigc::mem_fun(*this, &App_Glom::on_connection_pool_get_document) );
#endif
- connection_pool->set_ready_to_connect(true); //connect_to_server() will now attempt the connection-> Shared instances of m_Connection will also be usable.
+ connection_pool->set_ready_to_connect(true); //connect_to_server() will now attempt the connection-> Shared instances of m_Connection will also be usable.
- //Attempt to connect to the specified database:
- bool test = false;
+ //Attempt to connect to the specified database:
+ bool test = false;
#ifndef GLOM_ENABLE_CLIENT_ONLY
- if(is_example)
- {
- //The user has already had the chance to specify a new filename and database name.
- test = m_pFrame->connection_request_password_and_choose_new_database_name();
- }
- else
+ if(is_example)
+ {
+ //The user has already had the chance to specify a new filename and database name.
+ test = m_pFrame->connection_request_password_and_choose_new_database_name();
+ }
+ else
#endif // !GLOM_ENABLE_CLIENT_ONLY
- {
- //Ask for the username/password and connect:
- //Note that m_temp_username and m_temp_password are set if
- //we already asked for them when getting the document over the network:
+ {
+ //Ask for the username/password and connect:
+ //Note that m_temp_username and m_temp_password are set if
+ //we already asked for them when getting the document over the network:
- //Use the default username/password if opening as non network-shared:
- if(!(pDocument->get_network_shared()))
- {
- // If the document is centrally hosted, don't pretend to know the
- // username or password, because we don't. The user will enter
- // the login credentials in a dialog.
- if(pDocument->get_hosting_mode() != Document::HOSTING_MODE_POSTGRES_CENTRAL)
- m_temp_username = Privs::get_default_developer_user_name(m_temp_password);
- }
+ //Use the default username/password if opening as non network-shared:
+ if(!(pDocument->get_network_shared()))
+ {
+ // If the document is centrally hosted, don't pretend to know the
+ // username or password, because we don't. The user will enter
+ // the login credentials in a dialog.
+ if(pDocument->get_hosting_mode() != Document::HOSTING_MODE_POSTGRES_CENTRAL)
+ m_temp_username = Privs::get_default_developer_user_name(m_temp_password);
+ }
- bool database_not_found = false;
- test = m_pFrame->connection_request_password_and_attempt(database_not_found, m_temp_username, m_temp_password);
- m_temp_username = Glib::ustring();
- m_temp_password = Glib::ustring();
+ bool database_not_found = false;
+ test = m_pFrame->connection_request_password_and_attempt(database_not_found, m_temp_username, m_temp_password);
+ m_temp_username = Glib::ustring();
+ m_temp_password = Glib::ustring();
- if(!test && database_not_found)
- {
- #ifndef GLOM_ENABLE_CLIENT_ONLY
- if(!is_example)
- {
- //The connection to the server is OK, but the database is not there yet.
- Frame_Glom::show_ok_dialog(_("Database Not Found On Server"), _("The database could not be found on the server. Please consult your system administrator."), *this, Gtk::MESSAGE_ERROR);
- }
- else
- #endif // !GLOM_ENABLE_CLIENT_ONLY
- std::cerr << "App_Glom::on_document_load(): unexpected database_not_found error when opening example." << std::endl;
- }
- else if(!test)
+ if(!test && database_not_found)
+ {
+ #ifndef GLOM_ENABLE_CLIENT_ONLY
+ if(!is_example)
{
- std::cerr << "App_Glom::on_document_load(): unexpected error." << std::endl;
+ //The connection to the server is OK, but the database is not there yet.
+ Frame_Glom::show_ok_dialog(_("Database Not Found On Server"), _("The database could not be found on the server. Please consult your system administrator."), *this, Gtk::MESSAGE_ERROR);
}
+ else
+ #endif // !GLOM_ENABLE_CLIENT_ONLY
+ std::cerr << "App_Glom::on_document_load(): unexpected database_not_found error when opening example." << std::endl;
+ }
+ else if(!test)
+ {
+ std::cerr << "App_Glom::on_document_load(): unexpected error." << std::endl;
}
+ }
- if(!test)
- return false; //Failed. Close the document.
+ if(!test)
+ return false; //Failed. Close the document.
#ifndef GLOM_ENABLE_CLIENT_ONLY
- if(is_example)
+ if(is_example)
+ {
+ //Create the example database:
+ //connection_request_password_and_choose_new_database_name() has already change the database name to a new unused one:
+ bool user_cancelled = false;
+ const bool test = recreate_database(user_cancelled);
+ if(!test)
{
- //Create the example database:
- //connection_request_password_and_choose_new_database_name() has already change the database name to a new unused one:
- bool user_cancelled = false;
- const bool test = recreate_database(user_cancelled);
- if(!test)
+ // TODO: Do we need to call connection_pool->cleanup() here, for
+ // stopping self-hosted databases? armin.
+ connection_pool->cleanup( sigc::mem_fun(*this, &App_Glom::on_connection_close_progress) );
+ //If the database was not successfully recreated:
+ if(!user_cancelled)
{
- // TODO: Do we need to call connection_pool->cleanup() here, for
- // stopping self-hosted databases? armin.
- connection_pool->cleanup( sigc::mem_fun(*this, &App_Glom::on_connection_close_progress) );
- //If the database was not successfully recreated:
- if(!user_cancelled)
- {
- //Let the user try again.
- //A warning has already been shown.
- //TODO: No, I don't think there is a warning.
- std::cerr << "App_Glom::on_document_load(): recreate_database() failed." << std::endl;
- return offer_new_or_existing();
- }
- else
- return false;
+ //Let the user try again.
+ //A warning has already been shown.
+ //TODO: No, I don't think there is a warning.
+ std::cerr << "App_Glom::on_document_load(): recreate_database() failed." << std::endl;
+ return offer_new_or_existing();
}
else
- {
- //Make sure that the changes (mark as non example, and save the new database name) are really saved:
- //Change the user level temporarily so that save_changes() actually saves:
- const AppState::userlevels user_level = pDocument->get_userlevel();
- pDocument->set_userlevel(AppState::USERLEVEL_DEVELOPER);
- pDocument->set_modified(true);
- pDocument->set_userlevel(user_level); //Change it back.
- }
+ return false;
}
+ else
+ {
+ //Make sure that the changes (mark as non example, and save the new database name) are really saved:
+ //Change the user level temporarily so that save_changes() actually saves:
+ const AppState::userlevels user_level = pDocument->get_userlevel();
+ pDocument->set_userlevel(AppState::USERLEVEL_DEVELOPER);
+ pDocument->set_modified(true);
+ pDocument->set_userlevel(user_level); //Change it back.
+ }
+ }
#endif // !GLOM_ENABLE_CLIENT_ONLY
- //Switch to operator mode when opening new documents:
- pDocument->set_userlevel(AppState::USERLEVEL_OPERATOR);
+ //Switch to operator mode when opening new documents:
+ pDocument->set_userlevel(AppState::USERLEVEL_OPERATOR);
- //Open default table, or show list of tables instead:
- m_pFrame->do_menu_Navigate_Table(true /* open the default if there is one */);
+ //Open default table, or show list of tables instead:
+ m_pFrame->do_menu_Navigate_Table(true /* open the default if there is one */);
- }
}
+ }
- //List the non-hidden tables in the menu:
- fill_menu_tables();
+ //List the non-hidden tables in the menu:
+ fill_menu_tables();
- update_network_shared_ui();
+ update_network_shared_ui();
#ifndef GLOM_ENABLE_CLIENT_ONLY
- pDocument->set_allow_autosave(true);
+ pDocument->set_allow_autosave(true);
#endif // !GLOM_ENABLE_CLIENT_ONLY
- return true; //Loading of the document into the application succeeded.
- }
+ return true; //Loading of the document into the application succeeded.
}
void App_Glom::on_connection_close_progress()
@@ -1300,24 +1296,24 @@ bool App_Glom::offer_new_or_existing()
{
switch(dialog->get_action())
{
- case Dialog_ExistingOrNew::NONE:
- // This should not happen
- break;
#ifndef GLOM_ENABLE_CLIENT_ONLY
case Dialog_ExistingOrNew::NEW_EMPTY:
existing_or_new_new();
break;
case Dialog_ExistingOrNew::NEW_FROM_TEMPLATE:
+#endif // !GLOM_ENABLE_CLIENT_ONLY
case Dialog_ExistingOrNew::OPEN_URI:
open_document(dialog->get_uri());
break;
-#endif // !GLOM_ENABLE_CLIENT_ONLY
#ifndef G_OS_WIN32
case Dialog_ExistingOrNew::OPEN_REMOTE:
open_browsed_document(dialog->get_service_info(), dialog->get_service_name());
break;
#endif
+ case Dialog_ExistingOrNew::NONE:
default:
+ std::cerr << "App_Glom::offer_new_or_existing(): Unhandled action: " << dialog->get_action() << std::endl;
+ g_assert_not_reached();
break;
}
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index 7cfec54..57e94cf 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -1926,6 +1926,8 @@ namespace
#endif // GLOM_ENABLE_SQLITE
default:
+ //on_document_load() should have checked for this already, informing the user.
+ std::cerr << "Glom: setup_connection_pool_from_document(): Unhandled hosting mode: " << document->get_hosting_mode() << std::endl;
g_assert_not_reached();
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]