[glom/maemo5] Maemo: Show a new Details window when adding related records.
- From: Murray Cumming <murrayc src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glom/maemo5] Maemo: Show a new Details window when adding related records.
- Date: Fri, 16 Oct 2009 08:50:10 +0000 (UTC)
commit 9a369e03d277dc01543adde9a059f5424868b1b4
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Oct 15 19:21:08 2009 +0200
Maemo: Show a new Details window when adding related records.
* glom/mode_data/box_data_portal.[h|cc]:
* glom/mode_data/box_data_calendar_related.[h|cc]:
* glom/mode_data/box_data_list_related.[h|cc]:
Remove the just-added do_add_record() virtual method.
Instead add a Box_Data_Details and parent window to Box_Data_Portal,
used to show a details window for a new related record in
on_maemo_appmenubutton_add().
Move some code from Box_Data_List_Related::on_adddel_record_added() to
Box_Data_Portal::make_record_related() to make this easier.
ChangeLog | 14 ++++
glom/mode_data/box_data_calendar_related.cc | 9 ---
glom/mode_data/box_data_calendar_related.h | 6 --
glom/mode_data/box_data_details.h | 3 +
glom/mode_data/box_data_list_related.cc | 34 ++-------
glom/mode_data/box_data_list_related.h | 6 --
glom/mode_data/box_data_portal.cc | 100 ++++++++++++++++++++++++++-
glom/mode_data/box_data_portal.h | 21 ++++--
glom/utility_widgets/db_adddel/db_adddel.cc | 2 +-
9 files changed, 138 insertions(+), 57 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 38b4513..ca3e7ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
2009-10-15 Murray Cumming <murrayc murrayc com>
+ Maemo: Show a new Details window when adding related records.
+
+ * glom/mode_data/box_data_portal.[h|cc]:
+ * glom/mode_data/box_data_calendar_related.[h|cc]:
+ * glom/mode_data/box_data_list_related.[h|cc]:
+ Remove the just-added do_add_record() virtual method.
+ Instead add a Box_Data_Details and parent window to Box_Data_Portal,
+ used to show a details window for a new related record in
+ on_maemo_appmenubutton_add().
+ Move some code from Box_Data_List_Related::on_adddel_record_added() to
+ Box_Data_Portal::make_record_related() to make this easier.
+
+2009-10-15 Murray Cumming <murrayc murrayc com>
+
Developer: Tables: Add singular title.
* glom/libglom/data_structure/tableinfo.[h|cc]: Add
diff --git a/glom/mode_data/box_data_calendar_related.cc b/glom/mode_data/box_data_calendar_related.cc
index 41caa0f..00b8614 100644
--- a/glom/mode_data/box_data_calendar_related.cc
+++ b/glom/mode_data/box_data_calendar_related.cc
@@ -626,13 +626,4 @@ void Box_Data_Calendar_Related::set_primary_key_value(const Gtk::TreeModel::iter
//TODO
}
-#ifdef GLOM_ENABLE_MAEMO
-void Box_Data_Calendar_Related::do_add_record()
-{
- std::cerr << "Box_Data_Calendar_Related::do_add_record(): TODO: Unimplemented." << std::endl;
-}
-#endif //GLOM_ENABLE_MAEMO
-
-
-
} //namespace Glom
diff --git a/glom/mode_data/box_data_calendar_related.h b/glom/mode_data/box_data_calendar_related.h
index 31314f9..98f0c15 100644
--- a/glom/mode_data/box_data_calendar_related.h
+++ b/glom/mode_data/box_data_calendar_related.h
@@ -110,12 +110,6 @@ private:
typedef std::map<Glib::Date, type_list_vectors> type_map_values;
type_map_values m_map_values;
mutable int m_query_column_date_field;
-
-private:
-
- #ifdef GLOM_ENABLE_MAEMO
- virtual void do_add_record(); //override
- #endif
};
} //namespace Glom
diff --git a/glom/mode_data/box_data_details.h b/glom/mode_data/box_data_details.h
index ca638e1..4190ef6 100644
--- a/glom/mode_data/box_data_details.h
+++ b/glom/mode_data/box_data_details.h
@@ -77,7 +77,10 @@ protected:
//Implementations of pure virtual methods from Base_DB_Table_Data:
+public:
virtual Gnome::Gda::Value get_primary_key_value_selected() const; //Value in the primary key's cell.
+
+protected:
virtual void set_primary_key_value(const Gtk::TreeModel::iterator& row, const Gnome::Gda::Value& value);
virtual Gnome::Gda::Value get_primary_key_value(const Gtk::TreeModel::iterator& row) const; //Actual primary key value of this record.
diff --git a/glom/mode_data/box_data_list_related.cc b/glom/mode_data/box_data_list_related.cc
index 205c373..3df7266 100644
--- a/glom/mode_data/box_data_list_related.cc
+++ b/glom/mode_data/box_data_list_related.cc
@@ -283,26 +283,15 @@ void Box_Data_List_Related::on_adddel_record_added(const Gtk::TreeModel::iterato
//Create the link by setting the foreign key
if(m_key_field && m_portal)
{
- Glib::RefPtr<Gnome::Gda::Set> params = Gnome::Gda::Set::create();
- params->add_holder(m_key_field->get_holder(m_key_value));
- params->add_holder(field_primary_key->get_holder(primary_key_value));
- Glib::ustring strQuery = "UPDATE \"" + m_portal->get_table_used(Glib::ustring() /* not relevant */) + "\"";
- strQuery += " SET \"" + /* get_table_name() + "." +*/ m_key_field->get_name() + "\" = " + m_key_field->get_gda_holder_string();
- strQuery += " WHERE \"" + get_table_name() + "\".\"" + field_primary_key->get_name() + "\" = " + field_primary_key->get_gda_holder_string();
- //std::cout << "Box_Data_List_Related::on_adddel_record_added(): setting value in db=" << primary_key_value.to_string() << std::endl;
- const bool test = query_execute(strQuery, params);
- if(test)
- {
- //Show it on the view, if it's visible:
- sharedptr<LayoutItem_Field> layout_item = sharedptr<LayoutItem_Field>::create();
- layout_item->set_full_field_details(m_key_field);
+ make_record_related(primary_key_value);
+
+ //Show it on the view, if it's visible:
+ sharedptr<LayoutItem_Field> layout_item = sharedptr<LayoutItem_Field>::create();
+ layout_item->set_full_field_details(m_key_field);
- //TODO: Although the to-field value is visible on the new related record, get_value() returns NULL so you can't immediately navigate to the new record:
- //std::cout << "DEBUG: Box_Data_List_Related::on_record_added(): setting field=" << layout_item->get_name() << "m_key_value=" << m_key_value.to_string() << std::endl;
- m_AddDel.set_value(row, layout_item, m_key_value);
- }
- else
- std::cerr << "Box_Data_List_Related::on_record_added(): SQL query failed: " << strQuery << std::endl;
+ //TODO: Although the to-field value is visible on the new related record, get_value() returns NULL so you can't immediately navigate to the new record:
+ //std::cout << "DEBUG: Box_Data_List_Related::on_record_added(): setting field=" << layout_item->get_name() << "m_key_value=" << m_key_value.to_string() << std::endl;
+ m_AddDel.set_value(row, layout_item, m_key_value);
}
else
std::cerr << "Box_Data_List_Related::on_record_added(): m_key_field is NULL" << std::endl;
@@ -491,11 +480,4 @@ void Box_Data_List_Related::create_layout_add_group(const sharedptr<LayoutGroup>
}
}
-#ifdef GLOM_ENABLE_MAEMO
-void Box_Data_List_Related::do_add_record()
-{
- m_AddDel.start_new_record();
-}
-#endif //GLOM_ENABLE_MAEMO
-
} //namespace Glom
diff --git a/glom/mode_data/box_data_list_related.h b/glom/mode_data/box_data_list_related.h
index d2cbcd6..c7aa80d 100644
--- a/glom/mode_data/box_data_list_related.h
+++ b/glom/mode_data/box_data_list_related.h
@@ -87,12 +87,6 @@ protected:
//Member widgets:
mutable DbAddDel_WithButtons m_AddDel; //mutable because its get_ methods aren't const.
-
-private:
-
- #ifdef GLOM_ENABLE_MAEMO
- virtual void do_add_record(); //override
- #endif
};
} //namespace Glom
diff --git a/glom/mode_data/box_data_portal.cc b/glom/mode_data/box_data_portal.cc
index f166675..4c5cb21 100644
--- a/glom/mode_data/box_data_portal.cc
+++ b/glom/mode_data/box_data_portal.cc
@@ -24,6 +24,13 @@
#include <glom/frame_glom.h> //For show_ok_dialog()
#include <glom/utils_ui.h> //For bold_message()).
#include <glom/application.h>
+
+#ifdef GLOM_ENABLE_MAEMO
+#include <glom/mode_data/box_data_details.h>
+#include <glom/window_boxholder.h>
+#include <hildonmm/program.h>
+#endif //GLOM_ENABLE_MAEMO
+
#include <glibmm/i18n.h>
namespace Glom
@@ -31,7 +38,9 @@ namespace Glom
Box_Data_Portal::Box_Data_Portal()
#ifdef GLOM_ENABLE_MAEMO
-: m_maemo_appmenubutton_add(Gtk::Hildon::SIZE_AUTO, Hildon::BUTTON_ARRANGEMENT_VERTICAL)
+: m_maemo_appmenubutton_add(Gtk::Hildon::SIZE_AUTO, Hildon::BUTTON_ARRANGEMENT_VERTICAL),
+ m_window_maemo_details(0),
+ m_box_maemo_details(0)
#endif
{
set_size_request(400, -1); //An arbitrary default.
@@ -64,12 +73,97 @@ Box_Data_Portal::Box_Data_Portal()
#endif //GLOM_ENABLE_MAEMO
}
-void Box_Data_Portal::on_maemo_appmenubutton_add()
+Box_Data_Portal::~Box_Data_Portal()
+{
+ if(m_window_maemo_details)
+ delete m_window_maemo_details;
+
+ if(m_box_maemo_details)
+ {
+ remove_view(m_box_maemo_details);
+ delete m_box_maemo_details;
+ }
+}
+
+void Box_Data_Portal::make_record_related(const Gnome::Gda::Value& related_record_primary_key_value)
{
- do_add_record();
+ sharedptr<Field> field_primary_key = get_field_primary_key();
+
+ //Create the link by setting the foreign key
+ if(!m_key_field)
+ {
+ std::cerr << "Box_Data_Portal::make_record_related(): m_key_field was null." << std::endl;
+ }
+
+ if(!m_portal)
+ {
+ std::cerr << "Box_Data_Portal::make_record_related(): m_portal was null." << std::endl;
+ }
+
+ Glib::RefPtr<Gnome::Gda::Set> params = Gnome::Gda::Set::create();
+ params->add_holder(m_key_field->get_holder(m_key_value));
+ params->add_holder(field_primary_key->get_holder(related_record_primary_key_value));
+ Glib::ustring strQuery = "UPDATE \"" + m_portal->get_table_used(Glib::ustring() /* not relevant */) + "\"";
+ strQuery += " SET \"" + /* get_table_name() + "." +*/ m_key_field->get_name() + "\" = " + m_key_field->get_gda_holder_string();
+ strQuery += " WHERE \"" + get_table_name() + "\".\"" + field_primary_key->get_name() + "\" = " + field_primary_key->get_gda_holder_string();
+ //std::cout << "Box_Data_Portal::make_record_related(): setting value in db=" << primary_key_value.to_string() << std::endl;
+ const bool test = query_execute(strQuery, params);
+ if(!test)
+ {
+ std::cerr << "Box_Data_Portal::make_record_related(): SQL query failed: " << strQuery << std::endl;
+ }
}
+
#ifdef GLOM_ENABLE_MAEMO
+void Box_Data_Portal::on_maemo_appmenubutton_add()
+{
+ if(m_window_maemo_details)
+ delete m_window_maemo_details;
+
+ if(m_box_maemo_details)
+ {
+ remove_view(m_box_maemo_details);
+ delete m_box_maemo_details;
+ }
+
+ m_box_maemo_details = new Box_Data_Details();
+ add_view(m_box_maemo_details);
+ m_box_maemo_details->show_all();
+
+ m_window_maemo_details = new Window_BoxHolder(m_box_maemo_details, _("Details"));
+
+ //Let this window have the main AppMenu:
+ Hildon::Program::get_instance()->add_window(*m_window_maemo_details);
+
+ Gtk::Window* pWindow = get_app_window();
+ if(pWindow)
+ m_window_maemo_details->set_transient_for(*pWindow);
+
+ const Glib::ustring title =
+ Glib::ustring::compose(_("New Related %1"),
+ get_title());
+ pWindow->set_title(title);
+
+ FoundSet found_set;
+ found_set.m_table_name = m_portal->get_table_used(Glib::ustring());
+ Gnome::Gda::Value related_record_primary_key_value; //null for a new record.
+ m_box_maemo_details->init_db_details(found_set,
+ get_active_layout_platform(get_document()),
+ related_record_primary_key_value);
+
+ m_box_maemo_details->do_new_record(); //Doesn't block.
+
+ //Make the new record related:
+ //TODO: Test that this works if the primary key is not auto-generated.
+ related_record_primary_key_value =
+ m_box_maemo_details->get_primary_key_value_selected();
+ make_record_related(related_record_primary_key_value);
+
+ std::cout << "DEBUG: Showing details for new related record." << std::endl;
+ m_window_maemo_details->show();
+}
+
void Box_Data_Portal::on_realize()
{
// Add an Add Related Something button to the application's AppMenu.
diff --git a/glom/mode_data/box_data_portal.h b/glom/mode_data/box_data_portal.h
index 5371d63..59fc84f 100644
--- a/glom/mode_data/box_data_portal.h
+++ b/glom/mode_data/box_data_portal.h
@@ -28,12 +28,16 @@
#ifdef GLOM_ENABLE_MAEMO
#include <hildonmm/button.h>
-#endif
+//#include <glom/mode_data/box_data_details.h>
+#include <glom/window_boxholder.h>
+#endif //GLOM_ENABLE_MAEMO
namespace Glom
{
+class Box_Data_Details;
+
/** This is a base class for data widgets that should show multiple related records.
*/
class Box_Data_Portal :
@@ -42,7 +46,8 @@ class Box_Data_Portal :
{
public:
Box_Data_Portal();
-
+ virtual ~Box_Data_Portal();
+
/**
* @param portal: The full portal details
*/
@@ -93,6 +98,8 @@ protected:
protected:
virtual Document::type_list_layout_groups create_layout_get_layout(); //override.
+ void make_record_related(const Gnome::Gda::Value& related_record_primary_key_value);
+
Glib::ustring get_title() const;
Gtk::Frame m_Frame;
@@ -101,6 +108,9 @@ protected:
sharedptr<LayoutItem_Portal> m_portal;
Glib::ustring m_parent_table; //A duplicate of the from_table in m_portal, but only when m_portal is not null.
+
+ // m_key_field and m_key_value are the field and its value in this table that
+ // must match another field in the parent table.
sharedptr<Field> m_key_field;
Gnome::Gda::Value m_key_value;
@@ -112,13 +122,12 @@ private:
void on_unrealize();
void on_maemo_appmenubutton_add();
- /** Create a new (related) record.
- */
- virtual void do_add_record() = 0;
-
//Each related-records portal adds its own Add Something button
//to the application's AppMenu when the portal is visible.
Hildon::Button m_maemo_appmenubutton_add;
+
+ Window_BoxHolder* m_window_maemo_details;
+ Box_Data_Details* m_box_maemo_details;
#endif //GLOM_ENABLE_MAEMO
};
diff --git a/glom/utility_widgets/db_adddel/db_adddel.cc b/glom/utility_widgets/db_adddel/db_adddel.cc
index 738f654..66f28a3 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.cc
+++ b/glom/utility_widgets/db_adddel/db_adddel.cc
@@ -2564,7 +2564,7 @@ void DbAddDel::user_added(const Gtk::TreeModel::iterator& row)
Gnome::Gda::Value primary_key_value;
- sharedptr<Field> primary_key_field = get_key_field();
+ sharedptr<const Field> primary_key_field = get_key_field();
//Get the new primary key value, if one is available now:
if(primary_key_field->get_auto_increment())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]