[Aptitude-devel] r3154 - in branches/aptitude-0.3/aptitude: . src

Daniel Burrows dburrows@costa.debian.org
Wed, 27 Apr 2005 16:40:33 +0000


Author: dburrows
Date: Wed Apr 27 16:40:30 2005
New Revision: 3154

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/pkg_tree.cc
   branches/aptitude-0.3/aptitude/src/pkg_tree.h
   branches/aptitude-0.3/aptitude/src/ui.cc
Log:
Defer building pkg_trees for the first time until the creator feels it's appropriate to do so.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Wed Apr 27 16:40:30 2005
@@ -1,5 +1,12 @@
 2005-04-27  Daniel Burrows  <dburrows@debian.org>
 
+	* src/pkg_tree.cc, src/pkg_tree.h, src/ui.cc:
+
+	  Don't implicitly build a pkg_tree when it's created.  Instead,
+	  expect the caller to call build_tree() once the tree is fully
+	  hooked up.  This avoids the inconsistencies caused by the tree's
+	  signal getting emitted before it's connected to anything.
+
 	* src/vscreen/vs_text_layout.cc:
 
 	  Fix the caching of text layouts: the 'lastw' variable wasn't

Modified: branches/aptitude-0.3/aptitude/src/pkg_tree.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/pkg_tree.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/pkg_tree.cc	Wed Apr 27 16:40:30 2005
@@ -1,6 +1,6 @@
 // pkg_tree.cc
 //
-//  Copyright 1999,2000,2001 Daniel Burrows
+//  Copyright 1999-2005 Daniel Burrows
 //
 //  This program is free software; you can redistribute it and/or modify
 //  it under the terms of the GNU General Public License as published by
@@ -470,48 +470,22 @@
   bindings=new keybindings(vs_tree::bindings);
 }
 
-void pkg_tree::init(const char *def_limit,
-		    OpProgress &progress)
-{
-  if(def_limit)
-    limitstr=def_limit;
-  else
-    limitstr=aptcfg->Find(PACKAGE "::Pkg-Display-Limit", "");
-
-  if(!limitstr.empty())
-    limit=parse_pattern(limitstr);
-
-  if(grouping)
-    build_tree(progress);
-
-  cache_closed.connect(sigc::mem_fun(*this, &pkg_tree::handle_cache_close));
-
-  cache_reloaded.connect(sigc::hide_return(sigc::mem_fun<bool, pkg_tree, pkg_tree>(*this, &pkg_tree::build_tree)));
-}
-
-pkg_tree::pkg_tree(const char *def_grouping,
-		   pkg_grouppolicy_factory *_grouping,
-		   const char *def_limit,
-		   OpProgress &progress):
-  grouping(_grouping), groupingstr(def_grouping),
-  sorting(parse_sortpolicy(aptcfg->Find(PACKAGE "::UI::Default-Sorting",
-					 "name"))),
-  limit(NULL)
-{
-  init(def_limit, progress);
-}
-
 pkg_tree::pkg_tree(const char *def_grouping,
 		   pkg_grouppolicy_factory *_grouping,
 		   const char *def_limit):
+  initialized(false),
   grouping(_grouping), groupingstr(def_grouping),
   sorting(parse_sortpolicy(aptcfg->Find(PACKAGE "::UI::Default-Sorting",
 					 "name"))),
   limit(NULL)
 {
-  OpProgress p;
+  if(def_limit)
+    limitstr=def_limit;
+  else
+    limitstr=aptcfg->Find(PACKAGE "::Pkg-Display-Limit", "");
 
-  init(def_limit, p);
+  if(!limitstr.empty())
+    limit=parse_pattern(limitstr);
 }
 
 void pkg_tree::handle_cache_close()
@@ -572,6 +546,15 @@
 {
   bool rval;
 
+  if(!initialized)
+    {
+      cache_closed.connect(sigc::mem_fun(*this, &pkg_tree::handle_cache_close));
+
+      cache_reloaded.connect(sigc::hide_return(sigc::mem_fun<bool, pkg_tree, pkg_tree>(*this, &pkg_tree::build_tree)));
+
+      initialized=true;
+    }
+
   reset_incsearch();
 
   set_root(NULL);

Modified: branches/aptitude-0.3/aptitude/src/pkg_tree.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/pkg_tree.h	(original)
+++ branches/aptitude-0.3/aptitude/src/pkg_tree.h	Wed Apr 27 16:40:30 2005
@@ -1,6 +1,6 @@
 // pkg_tree.h      -*-c++-*-
 //
-//  Copyright 1999,2000 Daniel Burrows
+//  Copyright 1999-2002, 2004-2005 Daniel Burrows
 //
 //  This program is free software; you can redistribute it and/or modify
 //  it under the terms of the GNU General Public License as published by
@@ -160,6 +160,11 @@
 
 class pkg_tree:public pkg_menu_tree
 {
+  /** If \b true, the tree is fully initialized: in particular,
+   *  the cache-reload signals are connected up.
+   */
+  bool initialized;
+
   pkg_grouppolicy_factory *grouping;
   std::string groupingstr;
   pkg_sortpolicy *sorting;
@@ -175,16 +180,16 @@
 
   void handle_cache_close();
 
-  void init(const char *limitstr,
-	    OpProgress &progress);
+  /** Set up the limit and handle a few other things. */
+  void init(const char *limitstr);
+
 protected:
   virtual bool handle_char(chtype ch);
 public:
-  pkg_tree(const char *groupingstr,
-	   pkg_grouppolicy_factory *_grouping,
-	   const char *limitstr,
-	   OpProgress &progress);
-
+  /** Initialize a package tree, but don't build it.  The caller
+   *  should call build_tree().  The main reason to do this is so you
+   *  can connect up the tree's signals before building it.
+   */
   pkg_tree(const char *groupingstr,
 	   pkg_grouppolicy_factory *_grouping,
 	   const char *limitstr);

Modified: branches/aptitude-0.3/aptitude/src/ui.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/ui.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/ui.cc	Wed Apr 27 16:40:30 2005
@@ -545,13 +545,15 @@
 	grp=new pkg_grouppolicy_filter_factory(pkg_missing_filter,new pkg_grouppolicy_task_factory(new pkg_grouppolicy_status_factory(new pkg_grouppolicy_section_factory(pkg_grouppolicy_section_factory::split_subdir,true,new pkg_grouppolicy_section_factory(pkg_grouppolicy_section_factory::split_topdir,false,new pkg_grouppolicy_end_factory())))));
     }
 
-  pkg_tree *tree=new pkg_tree(grpstr.c_str(), grp, NULL, progress);
+  pkg_tree *tree=new pkg_tree(grpstr.c_str(), grp, NULL);
 
   add_main_widget(make_default_view(tree,
 				    &tree->selected_signal,
 				    &tree->selected_desc_signal),
 		  _("Packages"),
 		  _("View available packages and choose actions to perform"));
+
+  tree->build_tree(progress);
 }
 
 // For signal connections.
@@ -570,7 +572,7 @@
   grpstr="filter(missing),hier";
   grp=parse_grouppolicy(grpstr);
 
-  pkg_tree *tree=new pkg_tree(grpstr.c_str(), grp, NULL, progress);
+  pkg_tree *tree=new pkg_tree(grpstr.c_str(), grp, NULL);
   tree->set_limit("!~v");
   //tree->set_hierarchical(false);
 
@@ -579,6 +581,7 @@
 				    &tree->selected_desc_signal),
 		  "Packages",
 		  _("View available packages and choose actions to perform"));
+  tree->build_tree(progress);
 }
 
 // For signal connections.
@@ -815,6 +818,10 @@
 				       sigc::ptr_fun(actually_do_package_run));
       add_main_widget(active_preview, _("Preview of package installation"),
 		      _("View and/or adjust the actions that will be performed"));
+
+      vs_progress *p=gen_progress_bar();
+      active_preview_tree->build_tree(*p);
+      p->destroy();
     }
   else
     active_preview_tree->show();