Commit 0b50bb06 authored by Murray Cumming's avatar Murray Cumming
Browse files

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.
parent 91a63962
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.
......
......@@ -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:
......
......@@ -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);
......
......@@ -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();
......
......@@ -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
......@@ -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);
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
......@@ -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,
......
......@@ -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:
......
......@@ -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
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment