[glom/maemo5] Maemo: Show Add Related buttons when showing portals on details.



commit 031685e91d0daffd6facde1ee6f66cd35523420e
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Oct 15 09:54:18 2009 +0200

    Maemo: Show Add Related buttons when showing portals on details.
    
    * glom/application.[h|cc]: Removed unused on_menu_add_record().
    * glom/mode_data/box_data_portal.[h|cc]: On Maemo, add a Hildon::Button
    to the application's AppMenu on realize, removing it on unrealize.
    Added a virtual do_add_record() that is called when the button is clicked.
    * glom/mode_data/box_data_calendar_related.[h|cc]:
    * glom/mode_data/box_data_list_related.[h|cc]: Added do_add_record()
    overrides, though they are empty so far.

 ChangeLog                                   |   12 ++++
 glom/application.cc                         |   12 +++-
 glom/application.h                          |    6 +-
 glom/frame_glom.cc                          |    2 +-
 glom/mode_data/box_data_calendar_related.cc |    8 ++-
 glom/mode_data/box_data_calendar_related.h  |    6 ++
 glom/mode_data/box_data_list_related.cc     |   10 +++-
 glom/mode_data/box_data_list_related.h      |    6 ++
 glom/mode_data/box_data_portal.cc           |   92 +++++++++++++++++++++++----
 glom/mode_data/box_data_portal.h            |   22 +++++++
 glom/utility_widgets/flowtable.h            |    7 +-
 11 files changed, 158 insertions(+), 25 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 651400d..43a1811 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2009-10-15  Murray Cumming  <murrayc murrayc com>
+
+	Maemo: Show Add Related buttons when showing portals on details.
+
+	* glom/application.[h|cc]: Removed unused on_menu_add_record().
+	* glom/mode_data/box_data_portal.[h|cc]: On Maemo, add a Hildon::Button 
+	to the application's AppMenu on realize, removing it on unrealize.
+	Added a virtual do_add_record() that is called when the button is clicked.
+	* glom/mode_data/box_data_calendar_related.[h|cc]:
+	* glom/mode_data/box_data_list_related.[h|cc]: Added do_add_record() 
+	overrides, though they are empty so far.
+	
 2009-10-13  Murray Cumming  <murrayc murrayc com>
 
 	Maemo: Add a Add Record to the App Menu and remove it from the List View.
diff --git a/glom/application.cc b/glom/application.cc
index 31bfa2c..92cf288 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -367,10 +367,6 @@ static void add_button_to_appmenu(Hildon::AppMenu& appmenu, const Glib::ustring&
   appmenu.append(*button);
 }
 
-void App_Glom::on_menu_add_record()
-{
-}
-
 void App_Glom::init_menus()
 {
   //There is no real menu on Maemo. We use HildonAppMenu instead.
@@ -1294,10 +1290,18 @@ void App_Glom::update_userlevel_ui()
 }
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
+#ifndef GLOM_ENABLE_MAEMO
 Glib::RefPtr<Gtk::UIManager> App_Glom::get_ui_manager()
 {
   return m_refUIManager;
 }
+#else
+Hildon::AppMenu* App_Glom::get_maemo_appmenu()
+{
+  return &m_maemo_appmenu;
+}
+#endif //GLOM_ENABLE_MAEMO
+
 
 bool App_Glom::offer_new_or_existing()
 {
diff --git a/glom/application.h b/glom/application.h
index c190dff..6ff2a6e 100644
--- a/glom/application.h
+++ b/glom/application.h
@@ -65,7 +65,11 @@ public:
   //virtual void statusbar_clear();
 
   /// Get the UIManager so we can merge new menus in.
+  #ifndef GLOM_ENABLE_MAEMO
   Glib::RefPtr<Gtk::UIManager> get_ui_manager();
+  #else
+  Hildon::AppMenu* get_maemo_appmenu();
+  #endif //GLOM_ENABLE_MAEMO
 
   /** Changes the mode to Data mode, as if the user had selected the Data Mode menu item.
    */
@@ -125,8 +129,6 @@ private:
 
 #ifndef GLOM_ENABLE_MAEMO
   void on_menu_help_contents();
-#else
-  void on_menu_add_record();
 #endif //GLOM_ENABLE_MAEMO
 
   /** Check that the file's hosting mode is supported by this build and 
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index e32b3e2..d671589 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -338,7 +338,7 @@ void Frame_Glom::set_mode_widget(Gtk::Widget& widget)
   App_Glom* pApp = dynamic_cast<App_Glom*>(get_app_window());
   if(pApp)
   {
-    Glib::RefPtr<Gtk::UIManager> ui_manager = pApp->get_ui_manager();
+    //Glib::RefPtr<Gtk::UIManager> ui_manager = pApp->get_ui_manager();
 
     Notebook_Glom* notebook_current = dynamic_cast<Notebook_Glom*>(m_pBox_Mode->get_child());
     if(notebook_current)
diff --git a/glom/mode_data/box_data_calendar_related.cc b/glom/mode_data/box_data_calendar_related.cc
index 27b485d..41caa0f 100644
--- a/glom/mode_data/box_data_calendar_related.cc
+++ b/glom/mode_data/box_data_calendar_related.cc
@@ -625,7 +625,13 @@ 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
 
 
 
diff --git a/glom/mode_data/box_data_calendar_related.h b/glom/mode_data/box_data_calendar_related.h
index 98f0c15..31314f9 100644
--- a/glom/mode_data/box_data_calendar_related.h
+++ b/glom/mode_data/box_data_calendar_related.h
@@ -110,6 +110,12 @@ 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_list_related.cc b/glom/mode_data/box_data_list_related.cc
index cdd0263..205c373 100644
--- a/glom/mode_data/box_data_list_related.cc
+++ b/glom/mode_data/box_data_list_related.cc
@@ -241,7 +241,8 @@ bool Box_Data_List_Related::on_script_button_idle(const Gnome::Gda::Value& prima
 
 void Box_Data_List_Related::on_adddel_record_added(const Gtk::TreeModel::iterator& row, const Gnome::Gda::Value& primary_key_value)
 {
-  //Note that on_record_added() would only be called on the AddDel itself, so we need ot handle this AddDel signal.
+  //Note that on_record_added() would only be called on the AddDel itself, 
+  //so we need to handle this AddDel signal.
   
   //primary_key_value is a new autogenerated or human-entered key for the row.
   //It has already been added to the database.
@@ -490,6 +491,11 @@ 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 c7aa80d..d2cbcd6 100644
--- a/glom/mode_data/box_data_list_related.h
+++ b/glom/mode_data/box_data_list_related.h
@@ -87,6 +87,12 @@ 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 03d2f75..f166675 100644
--- a/glom/mode_data/box_data_portal.cc
+++ b/glom/mode_data/box_data_portal.cc
@@ -23,12 +23,16 @@
 #include <glom/glade_utils.h>
 #include <glom/frame_glom.h> //For show_ok_dialog()
 #include <glom/utils_ui.h> //For bold_message()).
+#include <glom/application.h>
 #include <glibmm/i18n.h>
 
 namespace Glom
 {
 
 Box_Data_Portal::Box_Data_Portal()
+#ifdef GLOM_ENABLE_MAEMO
+: m_maemo_appmenubutton_add(Gtk::Hildon::SIZE_AUTO, Hildon::BUTTON_ARRANGEMENT_VERTICAL)
+#endif
 {
   set_size_request(400, -1); //An arbitrary default.
 
@@ -48,8 +52,67 @@ Box_Data_Portal::Box_Data_Portal()
   add(m_Frame);
 
   m_layout_name = "list_portal"; //Replaced by derived classes.
+  
+  #ifdef GLOM_ENABLE_MAEMO
+  #ifndef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+  signal_realize().connect(sigc::mem_fun(*this, &Box_Data_Portal::on_realize));
+  signal_unrealize().connect(sigc::mem_fun(*this, &Box_Data_Portal::on_unrealize));  
+  #endif //GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+
+  m_maemo_appmenubutton_add.signal_clicked().connect(
+    sigc::mem_fun(*this, &Box_Data_Portal::on_maemo_appmenubutton_add));
+  #endif //GLOM_ENABLE_MAEMO
 }
 
+void Box_Data_Portal::on_maemo_appmenubutton_add()
+{
+  do_add_record();
+}
+
+#ifdef GLOM_ENABLE_MAEMO
+void Box_Data_Portal::on_realize()
+{
+  // Add an Add Related Something button to the application's AppMenu.
+  // This will be removed when the portal is hidden.
+  //TODO: Use the ustring compose thingy. murrayc.
+  //TODO: Allow the designer to specify a singluar form for tables (and portals), 
+  //so we can say Add Related Something instead of Somethings: Add Related.
+  const Glib::ustring title = 
+    Glib::ustring::compose(_("%1: Add Related"), get_title());
+  m_maemo_appmenubutton_add.set_title(title);
+  m_maemo_appmenubutton_add.set_value(_("Add related record"));
+  App_Glom* app = App_Glom::get_application();
+  g_assert(app);
+  if(app)
+  {
+    Hildon::AppMenu* appmenu = app->get_maemo_appmenu();
+    g_assert(appmenu);
+    if(appmenu)
+    {
+      m_maemo_appmenubutton_add.show();
+      appmenu->append(m_maemo_appmenubutton_add);
+    }
+  }
+}
+
+void Box_Data_Portal::on_unrealize()
+{
+  // Remove the AppMenu button when the portal is no longer shown: 
+  App_Glom* app = App_Glom::get_application();
+  g_assert(app);
+  if(app)
+  {
+    Hildon::AppMenu* appmenu = app->get_maemo_appmenu();
+    g_assert(appmenu);
+    if(appmenu)
+    {
+      m_maemo_appmenubutton_add.hide();
+      Gtk::Container* container = appmenu;
+      container->remove(m_maemo_appmenubutton_add);
+    }
+  }
+}
+#endif //GLOM_ENABLE_MAEMO
 
 bool Box_Data_Portal::init_db_details(const sharedptr<const LayoutItem_Portal>& portal, bool show_title)
 {
@@ -58,10 +121,25 @@ bool Box_Data_Portal::init_db_details(const sharedptr<const LayoutItem_Portal>&
   Glib::ustring parent_table;
   if(m_portal)
     parent_table = m_portal->get_from_table();
-
+      
   return init_db_details(parent_table, show_title);
 }
 
+Glib::ustring Box_Data_Portal::get_title() const
+{
+  //TODO: This same code is in box_data_related_list.cc. Remove the duplication.
+  Glib::ustring relationship_title;
+  if(m_portal && m_portal->get_has_relationship_name())
+    relationship_title = m_portal->get_title_used(Glib::ustring() /* parent title - not relevant */);
+  else
+  {
+    //Note to translators: This text is shown instead of a table title, when the table has not yet been chosen.
+    relationship_title = _("Undefined Table");
+  }
+  
+  return relationship_title;
+}
+
 //TODO: Is this base class implemenation actually called by anything?
 bool Box_Data_Portal::init_db_details(const Glib::ustring& parent_table, bool show_title)
 {
@@ -76,17 +154,7 @@ bool Box_Data_Portal::init_db_details(const Glib::ustring& parent_table, bool sh
 
   if(show_title)
   {
-    //TODO: This same code is in box_data_related_list.cc. Remove the duplication.
-    Glib::ustring relationship_title;
-    if(m_portal && m_portal->get_has_relationship_name())
-      relationship_title = m_portal->get_title_used(Glib::ustring() /* parent title - not relevant */);
-    else
-    {
-      //Note to translators: This text is shown instead of a table title, when the table has not yet been chosen.
-      relationship_title = _("Undefined Table");
-    }
-
-    m_Label.set_markup(Utils::bold_message(relationship_title));
+    m_Label.set_markup(Utils::bold_message( get_title() ));
     m_Label.show();
 
     m_Alignment.set_padding(Utils::DEFAULT_SPACING_SMALL /* top */, 0, Utils::DEFAULT_SPACING_LARGE /* left */, 0);
diff --git a/glom/mode_data/box_data_portal.h b/glom/mode_data/box_data_portal.h
index 5684973..5371d63 100644
--- a/glom/mode_data/box_data_portal.h
+++ b/glom/mode_data/box_data_portal.h
@@ -26,6 +26,11 @@
 #include "box_data_manyrecords.h"
 #include <glom/utility_widgets/layoutwidgetbase.h>
 
+#ifdef GLOM_ENABLE_MAEMO
+#include <hildonmm/button.h>
+#endif
+
+
 namespace Glom
 {
 
@@ -88,6 +93,8 @@ protected:
 protected:
   virtual Document::type_list_layout_groups create_layout_get_layout(); //override.
 
+  Glib::ustring get_title() const;
+
   Gtk::Frame m_Frame;
   Gtk::Alignment m_Alignment;
   Gtk::Label m_Label;
@@ -98,6 +105,21 @@ protected:
   Gnome::Gda::Value m_key_value;
     
   type_signal_portal_record_changed m_signal_portal_record_changed;
+  
+private:
+  #ifdef GLOM_ENABLE_MAEMO
+  void on_realize();
+  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;
+  #endif //GLOM_ENABLE_MAEMO
 };
 
 } //namespace Glom
diff --git a/glom/utility_widgets/flowtable.h b/glom/utility_widgets/flowtable.h
index 73ca856..75b3cd7 100644
--- a/glom/utility_widgets/flowtable.h
+++ b/glom/utility_widgets/flowtable.h
@@ -95,9 +95,10 @@ private:
   virtual void on_remove(Gtk::Widget* child);
 
   //Do extra drawing:
-  virtual void on_realize();
-  virtual void on_unrealize();
-  virtual bool on_expose_event(GdkEventExpose* event);
+  //Virtual method overrides:
+  void on_realize();
+  void on_unrealize();
+  bool on_expose_event(GdkEventExpose* event);
 
 protected:
   int get_column_height(guint start_widget, guint widget_count, int& total_width) const;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]