[Aptitude-svn-commit] r3750 - in branches/aptitude-0.3/aptitude: . src

Daniel Burrows dburrows at costa.debian.org
Mon Aug 8 18:49:48 UTC 2005


Author: dburrows
Date: Mon Aug  8 18:49:45 2005
New Revision: 3750

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/pkg_view.cc
   branches/aptitude-0.3/aptitude/src/pkg_view.h
Log:
Update the package view generation code for refcounting.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Mon Aug  8 18:49:45 2005
@@ -1,14 +1,14 @@
 2005-08-08  Daniel Burrows  <dburrows at debian.org>
 
+	* src/pkg_view.cc, src/pkg_view.h:
+
+	  Update the package view generation code for refcounting.
+
 	* src/vscreen/ref_ptr.h:
 
 	  Make the dynamic downcast take a target class, not a target
 	  class pointer, as its template argument.
 
-	* src/pkg_view.cc, src/pkg_view.h:
-
-	  Update the package view generation code for refcounting.
-
 	* src/pkg_ver_item.cc, src/pkg_ver_item.h:
 
 	  Update pkg_ver_item for refcounting.

Modified: branches/aptitude-0.3/aptitude/src/pkg_view.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/pkg_view.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/pkg_view.cc	Mon Aug  8 18:49:45 2005
@@ -68,13 +68,20 @@
     have_pkg=false;
   }
 
-public:
+protected:
   pkg_handling_label(column_definition_list *_columns)
     :vs_label(" "), columns(_columns), have_pkg(false)
   {
     cache_closed.connect(sigc::mem_fun(*this, &pkg_handling_label::zap_package));
   }
 
+public:
+  static ref_ptr<pkg_handling_label>
+  create(column_definition_list *columns)
+  {
+    return new pkg_handling_label(columns);
+  }
+
   ~pkg_handling_label() {delete columns;}
 
   size size_request() {return size(1,1);}
@@ -122,9 +129,13 @@
   }
 };
 
+typedef ref_ptr<pkg_handling_label> pkg_handling_label_ref;
+
 static void do_set_column_format(string key, string the_default,
-				 pkg_handling_label *l)
+				 pkg_handling_label &lBare)
 {
+  pkg_handling_label_ref l(&lBare);
+
   string format=aptcfg->Find(key, the_default.c_str());
   wstring wformat;
 
@@ -146,7 +157,16 @@
 class pkg_description_widget:public vs_text_layout
 {
   int start_line;
+protected:
+  pkg_description_widget()
+  {
+  }
 public:
+  static ref_ptr<pkg_description_widget> create()
+  {
+    return new pkg_description_widget;
+  }
+
   void set_package(const pkgCache::PkgIterator &pkg,
 		   const pkgCache::VerIterator &ver)
   {
@@ -183,6 +203,8 @@
   }
 };
 
+typedef ref_ptr<pkg_description_widget> pkg_description_widget_ref;
+
 // In order to properly dispatch line-up/down events to the sub-widgets,
 // we need a meta-widget that knows about them.
 //
@@ -195,11 +217,11 @@
 // This is still rather gross, and a better way would be nice.
 class info_area_multiplex:public vs_multiplex
 {
-  vs_hier_editor *editor;
-  pkg_description_widget *description;
-  vs_table *description_table;
-  vs_text_layout *reasons;
-  vs_table *reasons_table;
+  vs_hier_editor_ref editor;
+  pkg_description_widget_ref description;
+  vs_table_ref description_table;
+  vs_text_layout_ref reasons;
+  vs_table_ref reasons_table;
 
   pkgCache::PkgIterator lastPkg;
   pkgCache::VerIterator lastVer;
@@ -210,14 +232,15 @@
   /** If the view was autoswitched to breakage reasons, this is set
    *  to the widget we switched away from; otherwise, it is \b NULL.
    */
-  vscreen_widget *autoswitch;
-public:
-  info_area_multiplex(vs_hier_editor *_editor,
-		      pkg_description_widget *_description,
-		      vs_table *_description_table,
-		      vs_text_layout *_reasons,
-		      vs_table *_reasons_table)
-    :vs_multiplex(),
+  vs_widget_ref autoswitch;
+
+protected:
+  info_area_multiplex(const vs_hier_editor_ref &_editor,
+		      const pkg_description_widget_ref &_description,
+		      const vs_table_ref &_description_table,
+		      const vs_text_layout_ref &_reasons,
+		      const vs_table_ref &_reasons_table)
+    :vs_multiplex(false),
      editor(_editor),
      description(_description), description_table(_description_table),
      reasons(_reasons), reasons_table(_reasons_table),
@@ -227,9 +250,21 @@
 						 &info_area_multiplex::reset_package));
   }
 
+public:
+  static ref_ptr<info_area_multiplex>
+  create(const vs_hier_editor_ref &editor,
+	 const pkg_description_widget_ref &description,
+	 const vs_table_ref &description_table,
+	 const vs_text_layout_ref &reasons,
+	 const vs_table_ref &reasons_table)
+  {
+    return new info_area_multiplex(editor, description, description_table,
+				   reasons, reasons_table);
+  }
+
   void line_up()
   {
-    vscreen_widget *w=visible_widget();
+    vs_widget_ref w=visible_widget();
 
     if(w==description_table)
       description->line_up();
@@ -239,7 +274,7 @@
 
   void line_down()
   {
-    vscreen_widget *w=visible_widget();
+    vs_widget_ref w=visible_widget();
 
     if(w==description_table)
       description->line_down();
@@ -265,7 +300,7 @@
       {
 	// Don't clobber the autoswitch bread crumb if we were
 	// autoswitched and are still autoswitched.
-	if(!autoswitch)
+	if(!autoswitch.valid())
 	  autoswitch=visible_widget();
 	reasons_table->show();
       }
@@ -281,7 +316,7 @@
 	reasons->move_to_top();
       }
     // If we are autoswitched and unbroken, switch back.
-    else if(!hasBreakage && autoswitch)
+    else if(!hasBreakage && autoswitch.valid())
       {
 	autoswitch->show();
 	autoswitch=NULL;
@@ -293,7 +328,7 @@
   /** Cycles the multiplex, taking autoswitch behavior into account. */
   void cycle()
   {
-    if(autoswitch && autoswitch!=visible_widget())
+    if(autoswitch.valid() && autoswitch!=visible_widget())
       {
 	autoswitch->show();
 	autoswitch=NULL;
@@ -336,35 +371,41 @@
   }
 };
 
-static bool do_menu_test(vscreen_widget *view,
+typedef ref_ptr<info_area_multiplex> info_area_multiplex_ref;
+
+static bool do_menu_test(vscreen_widget &viewBare,
 			 menu_redirect *redirect,
 			 bool (menu_redirect::* test)())
 {
+  vs_widget_ref view(&viewBare);
+
   return active_main_widget()==view &&
     (redirect->*test)();
 }
 
-static bool do_menu_action(vscreen_widget *view,
+static bool do_menu_action(vscreen_widget &viewBare,
 			   menu_redirect *redirect,
 			   bool (menu_redirect::* action)())
 {
+  vs_widget_ref view(&viewBare);
+
   if(active_main_widget()==view)
     return (redirect->*action)();
   else
     return false;
 }
 
-vscreen_widget *make_package_view(list<package_view_item> &format,
-				  vscreen_widget *mainwidget,
-				  menu_redirect *menu_handler,
-				  pkg_signal *sig, desc_signal *desc_sig,
-				  bool show_reason_first)
+vs_widget_ref make_package_view(list<package_view_item> &format,
+				const vs_widget_ref &mainwidget,
+				menu_redirect *menu_handler,
+				pkg_signal *sig, desc_signal *desc_sig,
+				bool show_reason_first)
 {
   bool found_mainwidget=false;
 
-  vs_table *rval=new vs_table;
+  vs_table_ref rval=vs_table::create();
 
-  assert(mainwidget);
+  assert(mainwidget.valid());
 
   for(list<package_view_item>::iterator i=format.begin();
       i!=format.end();
@@ -383,36 +424,36 @@
 	    _error->Error(_("make_package_view: error in arguments -- bad column list for static item"));
 	  else
 	    {
-	      pkg_handling_label *l=new pkg_handling_label(i->columns);
+	      pkg_handling_label_ref l=pkg_handling_label::create(i->columns);
 	      i->widget=l;
 
 	      if(sig)
-		sig->connect(sigc::mem_fun(*l, &pkg_handling_label::do_columnify));
+		sig->connect(sigc::mem_fun(*l.unsafe_get_ref(), &pkg_handling_label::do_columnify));
 
 	      if(!i->columns_cfg.empty())
 		aptcfg->connect(i->columns_cfg,
 				sigc::bind(sigc::ptr_fun(do_set_column_format),
 					   i->columns_cfg,
 					   i->columns_cfg_default,
-					   l));
+					   l.weak_ref()));
 	    }
 	  break;
 	case PACKAGE_VIEW_DESCRIPTION:
 	  {
-	    vs_hier_editor *e=new vs_hier_editor;
-	    pkg_description_widget *w=new pkg_description_widget;
-	    vs_text_layout *l=new vs_text_layout;
-
-	    vs_table *wt=new vs_table;
-	    vs_table *lt=new vs_table;
-	    info_area_multiplex *m=new info_area_multiplex(e,
-							   w, wt,
-							   l, lt);
-	    vs_scrollbar *ws=new vs_scrollbar(vs_scrollbar::VERTICAL);
-	    vs_scrollbar *ls=new vs_scrollbar(vs_scrollbar::VERTICAL);
+	    vs_hier_editor_ref e=vs_hier_editor::create();
+	    pkg_description_widget_ref w=pkg_description_widget::create();
+	    vs_text_layout_ref l=vs_text_layout::create();
+
+	    vs_table_ref wt=vs_table::create();
+	    vs_table_ref lt=vs_table::create();
+	    info_area_multiplex_ref m=info_area_multiplex::create(e,
+								  w, wt,
+								  l, lt);
+	    vs_scrollbar_ref ws=vs_scrollbar::create(vs_scrollbar::VERTICAL);
+	    vs_scrollbar_ref ls=vs_scrollbar::create(vs_scrollbar::VERTICAL);
 
-	    w->location_changed.connect(sigc::mem_fun(*ws, &vs_scrollbar::set_slider));
-	    l->location_changed.connect(sigc::mem_fun(*ls, &vs_scrollbar::set_slider));
+	    w->location_changed.connect(sigc::mem_fun(*ws.unsafe_get_ref(), &vs_scrollbar::set_slider));
+	    l->location_changed.connect(sigc::mem_fun(*ls.unsafe_get_ref(), &vs_scrollbar::set_slider));
 
 	    wt->add_widget_opts(w, 0, 0, 1, 1, vs_table::EXPAND | vs_table::FILL | vs_table::SHRINK, vs_table::EXPAND | vs_table::FILL | vs_table::SHRINK);
 	    wt->add_widget_opts(ws, 0, 1, 1, 1, vs_table::ALIGN_RIGHT, vs_table::ALIGN_CENTER | vs_table::FILL);
@@ -421,7 +462,7 @@
 	    lt->add_widget_opts(ls, 0, 1, 1, 1, vs_table::ALIGN_RIGHT, vs_table::EXPAND | vs_table::ALIGN_CENTER | vs_table::FILL);
 
 	    // HACK: speaks for itself
-	    vs_tree *thetree=dynamic_cast<vs_tree *>(mainwidget);
+	    vs_tree_ref thetree=mainwidget.dyn_downcast<vs_tree>();
 
 	    i->widget=m;
 
@@ -431,32 +472,35 @@
 	    l->set_fragment(nopackage());
 
 	    if(sig)
-	      sig->connect(sigc::mem_fun(*m, &info_area_multiplex::set_package));
+	      sig->connect(sigc::mem_fun(*m.unsafe_get_ref(), &info_area_multiplex::set_package));
 
 	    if(desc_sig)
-	      desc_sig->connect(sigc::mem_fun(*m, &info_area_multiplex::set_description));
+	      desc_sig->connect(sigc::mem_fun(*m.unsafe_get_ref(), &info_area_multiplex::set_description));
 
 	    mainwidget->connect_key("DescriptionDown", &global_bindings,
-				    sigc::mem_fun(*m,
+				    sigc::mem_fun(*m.unsafe_get_ref(),
 						  &info_area_multiplex::line_down));
 	    mainwidget->connect_key("DescriptionUp", &global_bindings,
-				    sigc::mem_fun(*m,
+				    sigc::mem_fun(*m.unsafe_get_ref(),
 						  &info_area_multiplex::line_up));
 	    mainwidget->connect_key("DescriptionCycle", &global_bindings,
-				    sigc::mem_fun(*m, &info_area_multiplex::cycle));
+				    sigc::mem_fun(*m.unsafe_get_ref(),
+						  &info_area_multiplex::cycle));
 	    mainwidget->connect_key("EditHier", &global_bindings,
-				    sigc::mem_fun(*e, &vscreen_widget::show));
+				    sigc::mem_fun(*e.unsafe_get_ref(),
+						  &vscreen_widget::show));
 	    mainwidget->connect_key("EditHier", &global_bindings,
-				    sigc::mem_fun(*m, &vscreen_widget::show));
+				    sigc::mem_fun(*m.unsafe_get_ref(),
+						  &vscreen_widget::show));
 	    mainwidget->connect_key("EditHier", &global_bindings,
-				    sigc::bind(sigc::mem_fun(*rval, &vs_table::focus_widget),
-					       m));
+				    sigc::bind(sigc::mem_fun(*rval.unsafe_get_ref(), &vs_table::focus_widget_bare),
+					       m.weak_ref()));
 
-	    e->hidden_sig.connect(sigc::bind(sigc::mem_fun(*rval, &vs_table::focus_widget),
-					     mainwidget));
+	    e->hidden_sig.connect(sigc::bind(sigc::mem_fun(*rval.unsafe_get_ref(), &vs_table::focus_widget_bare),
+					     mainwidget.weak_ref()));
 
-	    if(thetree)
-	      e->commit_changes.connect(sigc::mem_fun(*thetree, &vs_tree::line_down));
+	    if(thetree.valid())
+	      e->commit_changes.connect(sigc::mem_fun(*thetree.unsafe_get_ref(), &vs_tree::line_down));
 
 	    m->add_visible_widget(e, false);
 	    m->add_visible_widget(wt, true);
@@ -477,7 +521,7 @@
 	  break;
 	}
 
-      if(i->widget)
+      if(i->widget.valid())
 	{
 	  // If we have a main widget or a description widget, the
 	  // size of the widget in question will be ignored.
@@ -498,7 +542,7 @@
 	  if(i->popupdownkey.size()>0)
 	    rval->connect_key(i->popupdownkey,
 			      &global_bindings,
-			      sigc::mem_fun(*i->widget,
+			      sigc::mem_fun(*i->widget.unsafe_get_ref(),
 					    &vscreen_widget::toggle_visible));
 
 	  if(i->visible)
@@ -518,13 +562,13 @@
 	  if(!strcasecmp(j->name.c_str(), i->popupdownlinked.c_str()))
 	    {
 	      // Having to make two connections is annoying.
-	      j->widget->shown_sig.connect(sigc::mem_fun(*i->widget, &vscreen_widget::show));
-	      j->widget->hidden_sig.connect(sigc::mem_fun(*i->widget, &vscreen_widget::hide));
+	      j->widget->shown_sig.connect(sigc::mem_fun(*i->widget.unsafe_get_ref(), &vscreen_widget::show));
+	      j->widget->hidden_sig.connect(sigc::mem_fun(*i->widget.unsafe_get_ref(), &vscreen_widget::hide));
 	      break;
 	    }
 	}
 
-  if(!mainwidget)
+  if(!mainwidget.valid())
     _error->Error(_("make_package_view: no main widget found"));
 
   if(menu_handler)
@@ -534,122 +578,122 @@
       // TODO: need to change the condition for enabling the menu to
       // check whether the overall widget is visible...
       package_menu_enabled.connect(sigc::bind(sigc::ptr_fun(do_menu_test),
-					      rval,
+					      rval.weak_ref(),
 					      menu_handler,
 					      &menu_redirect::package_enabled));
 
       package_install.connect(sigc::bind(sigc::ptr_fun(do_menu_action),
-					 rval,
+					 rval.weak_ref(),
 					 menu_handler,
 					 &menu_redirect::package_install));
 
       package_remove.connect(sigc::bind(sigc::ptr_fun(do_menu_action),
-					rval,
+					rval.weak_ref(),
 					menu_handler,
 					&menu_redirect::package_remove));
 
       package_purge.connect(sigc::bind(sigc::ptr_fun(do_menu_action),
-				       rval,
+				       rval.weak_ref(),
 				       menu_handler,
 				       &menu_redirect::package_purge));
 
       package_hold.connect(sigc::bind(sigc::ptr_fun(do_menu_action),
-				      rval,
+				      rval.weak_ref(),
 				      menu_handler,
 				     &menu_redirect::package_hold));
 
       package_keep.connect(sigc::bind(sigc::ptr_fun(do_menu_action),
-				      rval,
+				      rval.weak_ref(),
 				      menu_handler,
 				      &menu_redirect::package_keep));
 
       package_mark_auto.connect(sigc::bind(sigc::ptr_fun(do_menu_action),
-					   rval,
+					   rval.weak_ref(),
 					   menu_handler,
 					   &menu_redirect::package_mark_auto));
 
       package_unmark_auto.connect(sigc::bind(sigc::ptr_fun(do_menu_action),
-					     rval,
+					     rval.weak_ref(),
 					     menu_handler,
 					    &menu_redirect::package_unmark_auto));
 
       package_forbid_enabled.connect(sigc::bind(sigc::ptr_fun(do_menu_test),
-						rval,
+						rval.weak_ref(),
 						menu_handler,
 						&menu_redirect::package_forbid_enabled));
 
       package_forbid.connect(sigc::bind(sigc::ptr_fun(do_menu_action),
-					rval,
+					rval.weak_ref(),
 					menu_handler,
 					&menu_redirect::package_forbid));
 
       package_information_enabled.connect(sigc::bind(sigc::ptr_fun(do_menu_test),
-						     rval,
+						     rval.weak_ref(),
 						     menu_handler,
 						    &menu_redirect::package_information_enabled));
 
       package_information.connect(sigc::bind(sigc::ptr_fun(do_menu_action),
-					     rval,
+					     rval.weak_ref(),
 					     menu_handler,
 					     &menu_redirect::package_information));
 
       package_changelog_enabled.connect(sigc::bind(sigc::ptr_fun(do_menu_test),
-						   rval,
+						   rval.weak_ref(),
 						   menu_handler,
 						   &menu_redirect::package_changelog_enabled));
 
       package_changelog.connect(sigc::bind(sigc::ptr_fun(do_menu_action),
-					   rval,
+					   rval.weak_ref(),
 					   menu_handler,
 					   &menu_redirect::package_changelog));
 
       find_search_enabled.connect(sigc::bind(sigc::ptr_fun(do_menu_test),
-					     rval,
+					     rval.weak_ref(),
 					     menu_handler,
 					     &menu_redirect::find_search_enabled));
 
       find_search.connect(sigc::bind(sigc::ptr_fun(do_menu_action),
-				     rval,
+				     rval.weak_ref(),
 				     menu_handler,
 				     &menu_redirect::find_search));
 
       find_research_enabled.connect(sigc::bind(sigc::ptr_fun(do_menu_test),
-					       rval,
+					       rval.weak_ref(),
 					       menu_handler,
 					       &menu_redirect::find_research_enabled));
 
       find_research.connect(sigc::bind(sigc::ptr_fun(do_menu_action),
-				       rval,
+				       rval.weak_ref(),
 				       menu_handler,
 				       &menu_redirect::find_research));
 
       find_limit_enabled.connect(sigc::bind(sigc::ptr_fun(do_menu_test),
-					    rval,
+					    rval.weak_ref(),
 					    menu_handler,
 					   &menu_redirect::find_limit_enabled));
 
       find_limit.connect(sigc::bind(sigc::ptr_fun(do_menu_action),
-				    rval,
+				    rval.weak_ref(),
 				    menu_handler,
 				    &menu_redirect::find_limit));
 
       find_cancel_limit_enabled.connect(sigc::bind(sigc::ptr_fun(do_menu_test),
-						   rval,
+						   rval.weak_ref(),
 						   menu_handler,
 						   &menu_redirect::find_reset_limit_enabled));
 
       find_cancel_limit.connect(sigc::bind(sigc::ptr_fun(do_menu_action),
-					   rval,
+					   rval.weak_ref(),
 					   menu_handler,
 					   &menu_redirect::find_reset_limit));
 
       find_broken_enabled.connect(sigc::bind(sigc::ptr_fun(do_menu_test),
-					     rval,
+					     rval.weak_ref(),
 					     menu_handler,
 					     &menu_redirect::find_broken_enabled));
 
       find_broken.connect(sigc::bind(sigc::ptr_fun(do_menu_action),
-				     rval,
+				     rval.weak_ref(),
 				     menu_handler,
 				     &menu_redirect::find_broken));
     }

Modified: branches/aptitude-0.3/aptitude/src/pkg_view.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/pkg_view.h	(original)
+++ branches/aptitude-0.3/aptitude/src/pkg_view.h	Mon Aug  8 18:49:45 2005
@@ -27,6 +27,7 @@
 #ifndef PKG_VIEW_H
 #define PKG_VIEW_H
 
+#include "vscreen/ref_ptr.h"
 #include "vscreen/config/column_definition.h"
 #include "vscreen/config/style.h"
 #include "pkg_grouppolicy.h"
@@ -38,6 +39,7 @@
 class package_view_item;
 class pkg_grouppolicy_factory;
 class vscreen_widget;
+typedef ref_ptr<vscreen_widget> vs_widget_ref;
 
 // The available types of items are:
 //
@@ -84,7 +86,7 @@
   std::string popupdownlinked;
   // Who are we linked to for our popupdown status?
 
-  vscreen_widget *widget;
+  vs_widget_ref widget;
   // For the internal use of make_package_view (stores the widget this item
   // generated)
 
@@ -140,10 +142,10 @@
  *                         visible; otherwise, the description will be
  *                         initially visible.
  */
-vscreen_widget *make_package_view(std::list<package_view_item> &format,
-				  vscreen_widget *mainwidget,
-				  menu_redirect *menu_handler,
-				  pkg_signal *sig, desc_signal *desc_sig,
-				  bool show_reason_first);
+vs_widget_ref make_package_view(std::list<package_view_item> &format,
+				const vs_widget_ref &mainwidget,
+				menu_redirect *menu_handler,
+				pkg_signal *sig, desc_signal *desc_sig,
+				bool show_reason_first);
 
 #endif



More information about the Aptitude-svn-commit mailing list