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

Daniel Burrows dburrows at costa.debian.org
Thu Sep 29 22:51:23 UTC 2005


Author: dburrows
Date: Thu Sep 29 22:51:19 2005
New Revision: 4337

Added:
   branches/aptitude-0.3/aptitude/src/ui_download_manager.cc
   branches/aptitude-0.3/aptitude/src/ui_download_manager.h
Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/po/POTFILES.in
   branches/aptitude-0.3/aptitude/src/Makefile.am
   branches/aptitude-0.3/aptitude/src/ui.cc
   branches/aptitude-0.3/aptitude/src/ui.h
Log:
Split the download wrapper class into a separate file.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Thu Sep 29 22:51:19 2005
@@ -1,5 +1,11 @@
 2005-09-29  Daniel Burrows  <dburrows at debian.org>
 
+	* po/POTFILES.in, src/Makefile.am, src/ui.cc, src/ui.h, src/ui_download_manager.cc, src/ui_download_manager.h:
+
+	  Split the wrapper class into another file.  Added some public UI
+	  routines to allow other code to manipulate the "is something
+	  downloading now?" state.
+
 	* src/ui.cc:
 
 	  Instead of subclassing the download managers, use a generic

Modified: branches/aptitude-0.3/aptitude/po/POTFILES.in
==============================================================================
--- branches/aptitude-0.3/aptitude/po/POTFILES.in	(original)
+++ branches/aptitude-0.3/aptitude/po/POTFILES.in	Thu Sep 29 22:51:19 2005
@@ -136,10 +136,11 @@
 src/generic/apt/download_signal_log.h
 src/generic/apt/download_manager.h
 src/generic/apt/download_install_manager.cc
-src/generic/apt/.#download_manager.h
+src/generic/apt/log.h
 src/generic/apt/download_update_manager.h
 src/generic/apt/download_update_manager.cc
 src/generic/apt/download_install_manager.h
+src/generic/apt/log.cc
 src/generic/problemresolver/problemresolver.h
 src/generic/problemresolver/test.cc
 src/generic/problemresolver/exceptions.h
@@ -275,3 +276,5 @@
 src/menu_tree.h
 src/menu_redirect.cc
 src/menu_tree.cc
+src/ui_download_manager.h
+src/ui_download_manager.cc

Modified: branches/aptitude-0.3/aptitude/src/Makefile.am
==============================================================================
--- branches/aptitude-0.3/aptitude/src/Makefile.am	(original)
+++ branches/aptitude-0.3/aptitude/src/Makefile.am	Thu Sep 29 22:51:19 2005
@@ -92,6 +92,8 @@
 	trust.cc	\
 	ui.cc		\
 	ui.h		\
+	ui_download_manager.cc \
+	ui_download_manager.h  \
 	view_changelog.cc \
 	view_changelog.h \
 	vs_progress.cc  \

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	Thu Sep 29 22:51:19 2005
@@ -99,7 +99,6 @@
 #include "download_bar.h"
 #include "download_list.h"
 #include "download_screen.h"
-#include "download_thread.h"
 #include "menu_tree.h"
 #include "pkg_columnizer.h"
 #include "pkg_grouppolicy.h"
@@ -107,6 +106,7 @@
 #include "pkg_tree.h"
 #include "pkg_ver_item.h"
 #include "pkg_view.h"
+#include "ui_download_manager.h"
 #include "vs_progress.h"
 
 using namespace std;
@@ -187,6 +187,17 @@
 const char *default_pkgheaderdisplay="%N %n #%B %u %o";
 const char *default_grpstr="task,status,section(subdir,passthrough),section(topdir)";
 
+void ui_start_download()
+{
+  active_download = true;
+
+  if(apt_cache_file != NULL)
+    (*apt_cache_file)->set_read_only(true);
+
+  if(active_preview.valid())
+    active_preview->destroy();
+}
+
 static fragment *apt_error_fragment()
 {
   vector<fragment *> frags;
@@ -993,115 +1004,6 @@
 //  can to some degree)
 
 
-
-/** Used to indicate that a download was cancelled. */
-class downloader:public sigc::trackable
-{
-  bool aborted;
-public:
-  downloader() : aborted(false)
-  {
-  }
-
-  void abort()
-  {
-    aborted=true;
-  }
-
-  bool get_aborted()
-  {
-    return aborted;
-  }
-};
-
-/** Represents the UI end of a download process.  This object
- *  completely handles its own memory management -- you don't have to
- *  delete it and you shouldn't try.
- */
-class ui_download_manager : public sigc::trackable
-{
-  download_manager *manager;
-
-  download_thread *t;
-
-  downloader abort_state;
-
-  download_signal_log *log;
-
-  background_status st;
-public:
-  ui_download_manager(download_manager *_manager)
-    : manager(_manager),
-      t(NULL),
-      log(gen_download_progress(false, false,
-				_("Downloading packages"),
-				_("View the progress of the package download"),
-				_("Package Download"),
-				arg(sigc::mem_fun(abort_state,
-						  &downloader::abort)))),
-      st(log)
-  {
-    active_download = true;
-
-    if(apt_cache_file != NULL)
-      (*apt_cache_file)->set_read_only(true);
-
-    if(active_preview.valid())
-      active_preview->destroy();
-  }
-
-  ~ui_download_manager()
-  {
-    log->Complete();
-    delete manager;
-
-    active_download = false;
-    if(apt_cache_file != NULL)
-      (*apt_cache_file)->set_read_only(false);
-
-    abort_state.abort();
-
-    delete t;
-    delete log;
-  }
-
-  void start()
-  {
-    vs_progress_ref p = gen_progress_bar();
-
-    bool ok = manager->prepare(*p.unsafe_get_ref(), st, log);
-
-    p->destroy();
-
-    if(ok)
-      (new download_thread(manager,
-			   sigc::mem_fun(this,
-					 &ui_download_manager::done)))->start();
-    else
-      delete this;
-  }
-
-  void done(download_thread *, pkgAcquire::RunResult res)
-  {
-    vs_progress_ref p = gen_progress_bar();
-
-    download_manager::result run_res = manager->finish(res, *p.unsafe_get_ref());
-
-    p->destroy();
-
-    delete t;
-    t = NULL;
-
-    if(run_res == download_manager::do_again && !abort_state.get_aborted())
-      (new download_thread(manager,
-			   sigc::mem_fun(this,
-					 &ui_download_manager::done)))->start();
-    else
-      delete this;
-  }
-};
-
-
 void install_or_remove_packages()
 {
   (new ui_download_manager(new download_install_manager(false)))->start();

Modified: branches/aptitude-0.3/aptitude/src/ui.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/ui.h	(original)
+++ branches/aptitude-0.3/aptitude/src/ui.h	Thu Sep 29 22:51:19 2005
@@ -290,6 +290,18 @@
 		  slot0arg okslot=NULL,
 		  const style &st = style_attrs_flip(A_REVERSE));
 
+/** Call this when a download starts; it sets the flag associated with
+ *  the existence of a download, destroys the active preview (if any),
+ *  and maeks the apt cache read-only.
+ */
+void ui_start_download();
+
+/** Call this when a download finishes; it clears the flag associated
+ *  with the existence of a download and puts the cache back into
+ *  read-write mode.
+ */
+void ui_stop_download();
+
 // Can be used to manually pop up an error dialog, if necessary.
 void check_apt_errors();
 

Added: branches/aptitude-0.3/aptitude/src/ui_download_manager.cc
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/ui_download_manager.cc	Thu Sep 29 22:51:19 2005
@@ -0,0 +1,98 @@
+// ui_download_manager.cc
+//
+//   Copyright (C) 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 the Free Software Foundation; either version 2 of
+//   the License, or (at your option) any later version.
+//
+//   This program is distributed in the hope that it will be useful,
+//   but WITHOUT ANY WARRANTY; without even the implied warranty of
+//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//   General Public License for more details.
+//
+//   You should have received a copy of the GNU General Public License
+//   along with this program; see the file COPYING.  If not, write to
+//   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+//   Boston, MA 02111-1307, USA.
+
+#include "ui_download_manager.h"
+
+#include "aptitude.h"
+#include "ui.h"
+#include "vs_progress.h"
+
+#include <generic/apt/apt.h>
+#include <generic/apt/download_manager.h>
+#include <generic/apt/download_signal_log.h>
+
+#include <sigc++/functors/mem_fun.h>
+
+// HACK.  Should these be explicitly exported from UI?
+extern bool active_download;
+extern vs_widget_ref active_preview;
+
+ui_download_manager::ui_download_manager(download_manager *_manager)
+  : manager(_manager),
+    t(NULL),
+    log(gen_download_progress(false, false,
+			      _("Downloading packages"),
+			      _("View the progress of the package download"),
+			      _("Package Download"),
+			      arg(sigc::mem_fun(abort_state,
+						&aborter::abort)))),
+    st(log)
+{
+  ui_start_download();
+}
+
+ui_download_manager::~ui_download_manager()
+{
+  log->Complete();
+  delete manager;
+
+  active_download = false;
+  if(apt_cache_file != NULL)
+    (*apt_cache_file)->set_read_only(false);
+
+  abort_state.abort();
+
+  delete t;
+  delete log;
+}
+
+void ui_download_manager::done(download_thread *, pkgAcquire::RunResult res)
+{
+  vs_progress_ref p = gen_progress_bar();
+
+  download_manager::result run_res = manager->finish(res, *p.unsafe_get_ref());
+
+  p->destroy();
+
+  delete t;
+  t = NULL;
+
+  if(run_res == download_manager::do_again && !abort_state.get_aborted())
+    (new download_thread(manager,
+			 sigc::mem_fun(this,
+				       &ui_download_manager::done)))->start();
+  else
+    delete this;
+}
+
+void ui_download_manager::start()
+{
+  vs_progress_ref p = gen_progress_bar();
+
+  bool ok = manager->prepare(*p.unsafe_get_ref(), st, log);
+
+  p->destroy();
+
+  if(ok)
+    (new download_thread(manager,
+			 sigc::mem_fun(this,
+				       &ui_download_manager::done)))->start();
+  else
+    delete this;
+}

Added: branches/aptitude-0.3/aptitude/src/ui_download_manager.h
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/ui_download_manager.h	Thu Sep 29 22:51:19 2005
@@ -0,0 +1,81 @@
+// ui_download_manager.h                           -*-c++-*-
+//
+//   Copyright (C) 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 the Free Software Foundation; either version 2 of
+//   the License, or (at your option) any later version.
+//
+//   This program is distributed in the hope that it will be useful,
+//   but WITHOUT ANY WARRANTY; without even the implied warranty of
+//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//   General Public License for more details.
+//
+//   You should have received a copy of the GNU General Public License
+//   along with this program; see the file COPYING.  If not, write to
+//   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+//   Boston, MA 02111-1307, USA.
+//
+// Glue code to go between the UI and the download manager/thread
+// stuff.
+
+#ifndef UI_DOWNLOAD_MANAGER_H
+#define UI_DOWNLOAD_MANAGER_H
+
+#include "download_thread.h"
+
+#include <apt-pkg/acquire.h>
+
+#include <sigc++/trackable.h>
+
+class download_manager;
+class download_signal_log;
+class download_thread;
+
+/** Represents the UI end of a download process.  This object
+ *  completely handles its own memory management -- you don't have to
+ *  delete it and you shouldn't try.
+ */
+class ui_download_manager : public sigc::trackable
+{
+  /** Used to indicate that a download was cancelled. */
+  class aborter : public sigc::trackable
+  {
+    bool aborted;
+  public:
+    aborter() : aborted(false)
+    {
+    }
+
+    void abort()
+    {
+      aborted = true;
+    }
+
+    bool get_aborted()
+    {
+      return aborted;
+    }
+  };
+
+  download_manager *manager;
+
+  download_thread *t;
+
+  aborter abort_state;
+
+  download_signal_log *log;
+
+  background_status st;
+
+  void done(download_thread *, pkgAcquire::RunResult res);
+public:
+  ui_download_manager(download_manager *_manager);
+  ~ui_download_manager();
+
+  void start();
+};
+
+
+#endif



More information about the Aptitude-svn-commit mailing list