[pan2/download-meter: 3/3] glldf



commit 01103be9ec949e072ec1a80867b726bba7011992
Author: Heinrich MÃller <henmull src gnome org>
Date:   Sun Sep 23 20:48:41 2012 +0200

    glldf

 pan/gui/download-meter.cc |   11 +++++++----
 pan/gui/gui.cc            |    3 +--
 pan/gui/prefs.cc          |   23 +++++++++++++++++++++++
 pan/gui/prefs.h           |   15 +++++++++++++++
 pan/tasks/nntp.cc         |    2 +-
 pan/tasks/nntp.h          |    2 +-
 pan/tasks/socket.h        |    6 +++++-
 7 files changed, 53 insertions(+), 9 deletions(-)
---
diff --git a/pan/gui/download-meter.cc b/pan/gui/download-meter.cc
index 53cdce8..09d3ff5 100644
--- a/pan/gui/download-meter.cc
+++ b/pan/gui/download-meter.cc
@@ -23,15 +23,18 @@
 
 using namespace pan;
 
-DownloadMeter :: DownloadMeter () : _val(0ul), _view(new ProgressView()), _progress(new Progress("Downloaded bytes"))
+DownloadMeter :: DownloadMeter (Prefs& prefs) : _val(0ul), _view(new ProgressView()), _progress(new Progress("Downloaded bytes"))
 {
+
+  const uint64_t MAX_BYTES (1024*1024*1024*42); // 42 GB
+
   _view->set_progress(_progress);
-  _progress->add_steps (1000);
+  _progress->add_steps (prefs.get_long64("dl-limit", MAX_BYTES));
   _progress->set_status_va("Downloaded bytes (%lu)", 0);
 }
 
 void
-DownloadMeter :: add (unsigned long bytes)
+DownloadMeter :: add (uint64_t bytes)
 {
   if (bytes > 0)
   {
@@ -50,7 +53,7 @@ DownloadMeter :: reset ()
 }
 
 void
-DownloadMeter :: fire_xfer_bytes (unsigned long bytes)
+DownloadMeter :: fire_xfer_bytes (uint64_t bytes)
 {
   for (lit it(_listeners.begin()), end(_listeners.end()); it!=end; )
     (*it++)->on_xfer_bytes (bytes);
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index efb283a..8470370 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -995,8 +995,7 @@ void GUI :: on_progress_finished (Progress & p, int status)
 
 void GUI :: on_xfer_bytes (unsigned long bytes)
 {
-  // todo set new "progress" for download meter
-  std::cerr<<bytes<<"\n";
+  // TODO : perhaps some code for prefs / UI interaction??
 }
 
 void GUI :: do_read_selected_article ()
diff --git a/pan/gui/prefs.cc b/pan/gui/prefs.cc
index 174f76b..5d21af7 100644
--- a/pan/gui/prefs.cc
+++ b/pan/gui/prefs.cc
@@ -164,6 +164,9 @@ Prefs :: to_string (int depth, std::string& setme) const
   foreach_const (ints_t, _ints, it)
     out << indent(depth) << "<int name='" << escaped(it->first) << "' value='" << it->second << "'/>\n";
 
+  foreach_const (longs_t, _longs, it)
+    out << indent(depth) << "<long name='" << escaped(it->first) << "' value='" << it->second << "'/>\n";
+
   foreach_const (strings_t, _strings, it)
     out << indent(depth) << "<string name='" << escaped(it->first) << "' value='" << escaped(it->second) << "'/>\n";
 
@@ -298,6 +301,26 @@ Prefs :: set_int (const StringView& key, int value)
 }
 
 /***
+****  LONG64
+***/
+
+uint64_t
+Prefs :: get_long64 (const StringView& key, uint64_t fallback) const
+{
+  if (!_ints.count (key))
+    _longs[key] = fallback;
+  return _longs[key];
+}
+
+void
+Prefs :: set_long64 (const StringView& key, uint64_t value)
+{
+  _longs[key] = value;
+  fire_long64_changed (key, value);
+}
+
+
+/***
 ****  STRINGS
 ***/
 
diff --git a/pan/gui/prefs.h b/pan/gui/prefs.h
index 26e178b..748834a 100644
--- a/pan/gui/prefs.h
+++ b/pan/gui/prefs.h
@@ -29,6 +29,10 @@
 #include <pan/gui/pan-colors.h>
 #include "gtk-compat.h"
 
+extern "C" {
+  #include <stdint.h>
+}
+
 namespace pan
 {
   /**
@@ -45,6 +49,7 @@ namespace pan
         virtual void on_prefs_string_changed (const StringView& key, const StringView& value) = 0;
         virtual void on_prefs_color_changed (const StringView& key, const GdkColor& color) = 0;
         virtual void on_prefs_hotkey_changed (const StringView& key, const StringView& value) {}
+        virtual void on_prefs_long64_changed(const StringView& key, const uint64_t& value) {}
       };
       void add_listener (Listener* l) { _listeners.insert(l); }
       void remove_listener (Listener* l) {_listeners.erase(l); }
@@ -62,6 +67,10 @@ namespace pan
         for (listeners_t::iterator it(_listeners.begin()), end(_listeners.end()); it!=end; )
           (*it++)->on_prefs_int_changed (key, value);
       }
+      void fire_long64_changed (const StringView& key, uint64_t value) {
+        for (listeners_t::iterator it(_listeners.begin()), end(_listeners.end()); it!=end; )
+          (*it++)->on_prefs_long64_changed (key, value);
+      }
       void fire_string_changed (const StringView& key, const StringView& value) {
         for (listeners_t::iterator it(_listeners.begin()), end(_listeners.end()); it!=end; )
           (*it++)->on_prefs_string_changed (key, value);
@@ -86,10 +95,14 @@ namespace pan
     public:
       bool get_flag (const StringView& key, bool fallback) const;
       void set_flag (const StringView& key, bool);
+
       int get_int (const StringView& key, int fallback) const;
       int get_int_min  (const StringView& key, int fallback) const;
       void set_int (const StringView& key, int);
 
+      uint64_t get_long64 (const StringView& key, uint64_t fallback) const;
+      void set_long64 (const StringView& key, uint64_t value);
+
       std::string get_string (const StringView& key, const StringView& fallback) const;
       void set_string (const StringView& key, const StringView&);
 
@@ -137,6 +150,8 @@ namespace pan
       mutable colors_t _colors;
       typedef std::map<std::string,int> ints_t;
       mutable ints_t _ints;
+      typedef std::map<std::string,uint64_t> longs_t;
+      mutable longs_t _longs;
 
     public:
       colors_t& get_colors() { return _colors; }
diff --git a/pan/tasks/nntp.cc b/pan/tasks/nntp.cc
index 69ee914..5061aa4 100644
--- a/pan/tasks/nntp.cc
+++ b/pan/tasks/nntp.cc
@@ -267,7 +267,7 @@ NNTP :: on_socket_error (Socket * sock UNUSED)
 }
 
 void
-NNTP :: on_socket_bytes_transferred (unsigned long bytes, Socket*)
+NNTP :: on_socket_bytes_transferred (uint64_t bytes, Socket*)
 {
    _meter.add (bytes);
 }
diff --git a/pan/tasks/nntp.h b/pan/tasks/nntp.h
index a4fb40c..12a454d 100644
--- a/pan/tasks/nntp.h
+++ b/pan/tasks/nntp.h
@@ -338,7 +338,7 @@ namespace pan
       virtual bool on_socket_response (Socket*, const StringView& line);
       virtual void on_socket_error (Socket*);
       virtual void on_socket_abort (Socket*);
-      virtual void on_socket_bytes_transferred (unsigned long bytes, Socket*) ;
+      virtual void on_socket_bytes_transferred (uint64_t bytes, Socket*) ;
 
     public:
 
diff --git a/pan/tasks/socket.h b/pan/tasks/socket.h
index 2fed292..af26a62 100644
--- a/pan/tasks/socket.h
+++ b/pan/tasks/socket.h
@@ -23,6 +23,10 @@
 #include <string>
 #include <config.h>
 
+extern "C" {
+  #include <stdint.h>
+}
+
 #ifdef HAVE_GNUTLS
   #include <gnutls/gnutls.h>
 #endif
@@ -54,7 +58,7 @@ namespace pan
         virtual bool on_socket_response (Socket*, const StringView& line) = 0;
         virtual void on_socket_error (Socket*) = 0;
         virtual void on_socket_abort (Socket*) = 0;
-        virtual void on_socket_bytes_transferred (unsigned long bytes, Socket*) = 0;
+        virtual void on_socket_bytes_transferred (uint64_t bytes, Socket*) = 0;
       };
 
     public:



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