[glom] Move some more methods from Base_DB.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Move some more methods from Base_DB.
- Date: Sat, 1 May 2010 12:37:53 +0000 (UTC)
commit 0b50bb065247647d5faec1c9d839181a42abad76
Author: Murray Cumming <murrayc murrayc com>
Date: Sat May 1 14:37:24 2010 +0200
Move some more methods from Base_DB.
* glom/base_db.[h|cc]: Move show_warning_no_records_found() to utils_ui.[h|cc].
get_find_where_clause_quick(): Move to utils.[h|cc].
* glom/frame_glom.cc: Adapted.
* glom/mode_design/layout/layout_item_dialogs/box_formatting.h:
* glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.[h|cc]:
* glom/mode_data/datawidget/dialog_choose_id.[h|cc]: Don't derive from Base_DB
because that is no longer necessary after adapting.
ChangeLog | 12 ++++
glom/base_db.cc | 63 --------------------
glom/base_db.h | 6 --
glom/frame_glom.cc | 4 +-
glom/libglom/utils.cc | 44 ++++++++++++++
glom/libglom/utils.h | 4 +
glom/mode_data/datawidget/dialog_choose_id.cc | 6 +-
glom/mode_data/datawidget/dialog_choose_id.h | 2 +-
.../layout/layout_item_dialogs/box_formatting.h | 2 +-
.../layout_item_dialogs/dialog_buttonscript.cc | 2 +-
.../layout_item_dialogs/dialog_buttonscript.h | 2 +-
glom/utils_ui.cc | 20 ++++++
glom/utils_ui.h | 5 ++
13 files changed, 95 insertions(+), 77 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9c37bde..fd13735 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2010-05-01 Murray Cumming <murrayc murrayc com>
+ Move some more methods from Base_DB.
+
+ * glom/base_db.[h|cc]: Move show_warning_no_records_found() to utils_ui.[h|cc].
+ get_find_where_clause_quick(): Move to utils.[h|cc].
+ * glom/frame_glom.cc: Adapted.
+ * glom/mode_design/layout/layout_item_dialogs/box_formatting.h:
+ * glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.[h|cc]:
+ * glom/mode_data/datawidget/dialog_choose_id.[h|cc]: Don't derive from Base_DB
+ because that is no longer necessary after adapting.
+
+2010-05-01 Murray Cumming <murrayc murrayc com>
+
* glom/libglom/db_utils.cc: create_database(): Actually use the progress slot.
2010-05-01 Murray Cumming <murrayc murrayc com>
diff --git a/glom/base_db.cc b/glom/base_db.cc
index 8d93b4d..6c6c3d8 100644
--- a/glom/base_db.cc
+++ b/glom/base_db.cc
@@ -817,69 +817,6 @@ void Base_DB::fill_full_field_details(const Glib::ustring& parent_table_name, sh
layout_item->set_full_field_details( get_document()->get_field(table_name, layout_item->get_name()) );
}
-
-//static
-bool Base_DB::show_warning_no_records_found(Gtk::Window& transient_for)
-{
- Glib::ustring message = _("Your find criteria did not match any records in the table.");
-
-#ifdef GLOM_ENABLE_MAEMO
- Hildon::Note dialog(Hildon::NOTE_TYPE_CONFIRMATION_BUTTON, transient_for, message);
-#else
- Gtk::MessageDialog dialog(Utils::bold_message(_("No Records Found")), true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
- dialog.set_secondary_text(message);
- dialog.set_transient_for(transient_for);
-#endif
-
- dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
- dialog.add_button(_("New Find"), Gtk::RESPONSE_OK);
-
- const bool find_again = (dialog.run() == Gtk::RESPONSE_OK);
- return find_again;
-}
-
-Glib::ustring Base_DB::get_find_where_clause_quick(const Glib::ustring& table_name, const Gnome::Gda::Value& quick_search) const
-{
- Glib::ustring strClause;
-
- const Document* document = get_document();
- if(document)
- {
- //TODO: Cache the list of all fields, as well as caching (m_Fields) the list of all visible fields:
- const Document::type_vec_fields fields = document->get_table_fields(table_name);
-
- type_vecLayoutFields fieldsToGet;
- for(Document::type_vec_fields::const_iterator iter = fields.begin(); iter != fields.end(); ++iter)
- {
- Glib::ustring strClausePart;
-
- sharedptr<const Field> field = *iter;
-
- bool use_this_field = true;
- if(field->get_glom_type() != Field::TYPE_TEXT)
- {
- use_this_field = false;
- }
-
- if(use_this_field)
- {
- //TODO: Use a SQL parameter instead of using sql().
- strClausePart = "\"" + table_name + "\".\"" + field->get_name() + "\" " + field->sql_find_operator() + " " + field->sql_find(quick_search);
- }
-
- if(!strClausePart.empty())
- {
- if(!strClause.empty())
- strClause += " OR ";
-
- strClause += strClausePart;
- }
- }
- }
-
- return strClause;
-}
-
sharedptr<Field> Base_DB::get_fields_for_table_one_field(const Glib::ustring& table_name, const Glib::ustring& field_name) const
{
//Initialize output parameter:
diff --git a/glom/base_db.h b/glom/base_db.h
index 08f795b..33295f3 100644
--- a/glom/base_db.h
+++ b/glom/base_db.h
@@ -136,9 +136,6 @@ protected:
sharedptr<LayoutItem_Notebook> offer_notebook(const sharedptr<LayoutItem_Notebook>& start_notebook, Gtk::Window* transient_for = 0);
#endif // !GLOM_ENABLE_CLIENT_ONLY
- ///@result Whether the user would like to find again.
- static bool show_warning_no_records_found(Gtk::Window& transient_for);
-
void fill_full_field_details(const Glib::ustring& parent_table_name, sharedptr<LayoutItem_Field>& layout_item);
bool get_relationship_exists(const Glib::ustring& table_name, const Glib::ustring& relationship_name);
@@ -161,9 +158,6 @@ protected:
sharedptr<Field> get_field_primary_key_for_table(const Glib::ustring& table_name) const;
- Glib::ustring get_find_where_clause_quick(const Glib::ustring& table_name, const Gnome::Gda::Value& quick_search) const;
-
-
//Methods to be overridden by derived classes:
virtual void set_entered_field_data(const sharedptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value);
virtual void set_entered_field_data(const Gtk::TreeModel::iterator& row, const sharedptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value);
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index 76d08dc..328f998 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -1467,7 +1467,7 @@ void Frame_Glom::on_button_quickfind()
}
else
{
- const Glib::ustring where_clause = get_find_where_clause_quick(m_table_name, Gnome::Gda::Value(criteria));
+ const Glib::ustring where_clause = Utils::get_find_where_clause_quick(get_document(), m_table_name, Gnome::Gda::Value(criteria));
//std::cout << "Frame_Glom::on_button_quickfind(): where_clause=" << where_clause << std::endl;
on_notebook_find_criteria(where_clause);
}
@@ -1501,7 +1501,7 @@ void Frame_Glom::on_notebook_find_criteria(const Glib::ustring& where_clause)
if(!records_found)
{
- const bool find_again = show_warning_no_records_found(*get_app_window());
+ const bool find_again = Utils::show_warning_no_records_found(*get_app_window());
if(find_again)
pApp->set_mode_find();
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index f4f1e94..5fe1625 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -841,4 +841,48 @@ bool Utils::file_exists(const Glib::ustring& uri)
}
}
+
+Glib::ustring Utils::get_find_where_clause_quick(Document* document, const Glib::ustring& table_name, const Gnome::Gda::Value& quick_search)
+{
+ Glib::ustring strClause;
+
+ if(document)
+ {
+ //TODO: Cache the list of all fields, as well as caching (m_Fields) the list of all visible fields:
+ const Document::type_vec_fields fields = document->get_table_fields(table_name);
+
+ typedef std::vector< sharedptr<LayoutItem_Field> > type_vecLayoutFields;
+ type_vecLayoutFields fieldsToGet;
+ for(Document::type_vec_fields::const_iterator iter = fields.begin(); iter != fields.end(); ++iter)
+ {
+ Glib::ustring strClausePart;
+
+ sharedptr<const Field> field = *iter;
+
+ bool use_this_field = true;
+ if(field->get_glom_type() != Field::TYPE_TEXT)
+ {
+ use_this_field = false;
+ }
+
+ if(use_this_field)
+ {
+ //TODO: Use a SQL parameter instead of using sql().
+ strClausePart = "\"" + table_name + "\".\"" + field->get_name() + "\" " + field->sql_find_operator() + " " + field->sql_find(quick_search);
+ }
+
+ if(!strClausePart.empty())
+ {
+ if(!strClause.empty())
+ strClause += " OR ";
+
+ strClause += strClausePart;
+ }
+ }
+ }
+
+ return strClause;
+}
+
+
} //namespace Glom
diff --git a/glom/libglom/utils.h b/glom/libglom/utils.h
index a20e369..c5ca8d3 100644
--- a/glom/libglom/utils.h
+++ b/glom/libglom/utils.h
@@ -23,6 +23,7 @@
#include <libglom/data_structure/field.h>
#include <libglom/data_structure/numeric_format.h>
+#include <libglom/document/document.h>
#include <libglom/data_structure/layout/layoutitem_field.h>
@@ -92,6 +93,9 @@ Glib::ustring build_sql_select_with_key(
const sharedptr<const Field>& key_field,
const Gnome::Gda::Value& key_value);
+Glib::ustring get_find_where_clause_quick(Document* document, const Glib::ustring& table_name, const Gnome::Gda::Value& quick_search);
+
+
typedef std::list< std::pair<Gnome::Gda::Value, Gnome::Gda::Value> > type_list_values_with_second;
type_list_values_with_second get_choice_values(const sharedptr<const LayoutItem_Field>& field);
diff --git a/glom/mode_data/datawidget/dialog_choose_id.cc b/glom/mode_data/datawidget/dialog_choose_id.cc
index 2955880..2320e06 100644
--- a/glom/mode_data/datawidget/dialog_choose_id.cc
+++ b/glom/mode_data/datawidget/dialog_choose_id.cc
@@ -121,7 +121,9 @@ void Dialog_ChooseID::on_button_quickfind()
}
else
{
- const Glib::ustring where_clause = get_find_where_clause_quick(m_table_name, Gnome::Gda::Value(criteria));
+ const Glib::ustring where_clause =
+ Utils::get_find_where_clause_quick(get_document(), m_table_name,
+ Gnome::Gda::Value(criteria));
on_box_find_criteria(where_clause);
}
}
@@ -137,7 +139,7 @@ void Dialog_ChooseID::on_box_find_criteria(const Glib::ustring& where_clause)
const bool records_found = m_box_select.init_db_details(found_set, m_layout_platform);
if(!records_found)
{
- const bool find_again = show_warning_no_records_found(*this);
+ const bool find_again = Utils::show_warning_no_records_found(*this);
if(!find_again)
response(Gtk::RESPONSE_CANCEL);
diff --git a/glom/mode_data/datawidget/dialog_choose_id.h b/glom/mode_data/datawidget/dialog_choose_id.h
index c4e3d0c..f0ae6af 100644
--- a/glom/mode_data/datawidget/dialog_choose_id.h
+++ b/glom/mode_data/datawidget/dialog_choose_id.h
@@ -35,7 +35,7 @@ namespace DataWidgetChildren
class Dialog_ChooseID
: public Gtk::Dialog,
- public Base_DB
+ public View_Composite_Glom
{
public:
static const char* glade_id;
diff --git a/glom/mode_design/layout/layout_item_dialogs/box_formatting.h b/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
index 6e31676..ebe72d7 100644
--- a/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
+++ b/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
@@ -34,7 +34,7 @@ namespace Glom
class Box_Formatting
: public Gtk::VBox,
- public Base_DB
+ public View_Composite_Glom
{
public:
static const char* glade_id;
diff --git a/glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.cc b/glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.cc
index 0ac3132..664d862 100644
--- a/glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.cc
+++ b/glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.cc
@@ -119,7 +119,7 @@ void Dialog_ButtonScript::on_button_test_script()
}
//We need the connection when we run the script, so that the script may use it.
- sharedptr<SharedConnection> sharedconnection = connect_to_server(this /* parent window */);
+ sharedptr<SharedConnection> sharedconnection = ConnectionPool::get_and_connect();
PythonUICallbacks callbacks;
glom_execute_python_function_implementation(calculation,
diff --git a/glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.h b/glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.h
index 45c34dc..01c7855 100644
--- a/glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.h
+++ b/glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.h
@@ -33,7 +33,7 @@ namespace Glom
class Dialog_ButtonScript
: public Gtk::Dialog,
- public Base_DB //Give this class access to the current document, and to some utility methods.
+ public View_Composite_Glom //Give this class access to the current document, and to some utility methods.
{
public:
diff --git a/glom/utils_ui.cc b/glom/utils_ui.cc
index 5e7f734..1a50ca9 100644
--- a/glom/utils_ui.cc
+++ b/glom/utils_ui.cc
@@ -30,6 +30,7 @@
#include <libgda/gda-blob-op.h> // For gda_blob_op_read_all()
#include <gtkmm/messagedialog.h>
+#include <gtkmm/stock.h>
#include <giomm.h>
@@ -497,5 +498,24 @@ Glib::RefPtr<Gdk::Pixbuf> Utils::image_scale_keeping_ratio(const Glib::RefPtr<Gd
return pixbuf->scale_simple(target_width, target_height, Gdk::INTERP_NEAREST);
}
+bool Utils::show_warning_no_records_found(Gtk::Window& transient_for)
+{
+ const Glib::ustring message = _("Your find criteria did not match any records in the table.");
+
+#ifdef GLOM_ENABLE_MAEMO
+ Hildon::Note dialog(Hildon::NOTE_TYPE_CONFIRMATION_BUTTON, transient_for, message);
+#else
+ Gtk::MessageDialog dialog(Utils::bold_message(_("No Records Found")), true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
+ dialog.set_secondary_text(message);
+ dialog.set_transient_for(transient_for);
+#endif
+
+ dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ dialog.add_button(_("New Find"), Gtk::RESPONSE_OK);
+
+ const bool find_again = (dialog.run() == Gtk::RESPONSE_OK);
+ return find_again;
+}
+
} //namespace Glom
diff --git a/glom/utils_ui.h b/glom/utils_ui.h
index 274b4b3..474d5ac 100644
--- a/glom/utils_ui.h
+++ b/glom/utils_ui.h
@@ -37,6 +37,7 @@
namespace Glom
{
+//TODO: Rename this to UiUtils
namespace Utils
{
@@ -102,6 +103,10 @@ int get_suitable_field_width_for_widget(Gtk::Widget& widget, const sharedptr<con
std::string get_filepath_with_extension(const std::string& filepath, const std::string& extension);
Glib::RefPtr<Gdk::Pixbuf> image_scale_keeping_ratio(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf, int target_height, int target_width);
+
+///@result Whether the user would like to find again.
+bool show_warning_no_records_found(Gtk::Window& transient_for);
+
} //namespace Utils
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]