aboutsummaryrefslogtreecommitdiffstats
path: root/src/utility
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2005-09-03 12:48:59 +0000
committerVincent Richard <[email protected]>2005-09-03 12:48:59 +0000
commitf777b659b9bd43f90c3f8b224ad296e42d89a02b (patch)
tree20f08abf13d3f2cb3ff1bfaa83348d1f69cc20d9 /src/utility
parentUpdated code to use smart pointers. (diff)
downloadvmime-f777b659b9bd43f90c3f8b224ad296e42d89a02b.tar.gz
vmime-f777b659b9bd43f90c3f8b224ad296e42d89a02b.zip
Added progression notifications.
Diffstat (limited to 'src/utility')
-rw-r--r--src/utility/progressionListener.cpp75
-rw-r--r--src/utility/stringProxy.cpp22
2 files changed, 93 insertions, 4 deletions
diff --git a/src/utility/progressionListener.cpp b/src/utility/progressionListener.cpp
new file mode 100644
index 00000000..9dde80da
--- /dev/null
+++ b/src/utility/progressionListener.cpp
@@ -0,0 +1,75 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2005 Vincent Richard <[email protected]>
+//
+// 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; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+
+#include "vmime/utility/progressionListener.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+// progressionListenerSizeAdapter
+
+progressionListenerSizeAdapter::progressionListenerSizeAdapter
+ (progressionListener* list, const int total)
+ : m_wrapped(list), m_total(total)
+{
+}
+
+
+const bool progressionListenerSizeAdapter::cancel() const
+{
+ return (m_wrapped ? m_wrapped->cancel() : false);
+}
+
+
+void progressionListenerSizeAdapter::start(const int predictedTotal)
+{
+ if (m_wrapped)
+ m_wrapped->start(predictedTotal);
+}
+
+
+void progressionListenerSizeAdapter::progress(const int current, const int currentTotal)
+{
+ if (m_wrapped)
+ {
+ if (currentTotal > m_total)
+ m_total = currentTotal;
+
+ m_wrapped->progress(current, m_total);
+ }
+}
+
+
+void progressionListenerSizeAdapter::stop(const int total)
+{
+ if (m_wrapped)
+ {
+ if (total > m_total)
+ m_total = total;
+
+ m_wrapped->stop(m_total);
+ }
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/stringProxy.cpp b/src/utility/stringProxy.cpp
index 798cbf1a..ef8a0cea 100644
--- a/src/utility/stringProxy.cpp
+++ b/src/utility/stringProxy.cpp
@@ -85,12 +85,26 @@ stringProxy& stringProxy::operator=(const string_type& s)
}
-void stringProxy::extract(outputStream& os, const size_type start, const size_type end) const
+void stringProxy::extract(outputStream& os, const size_type start, const size_type end,
+ utility::progressionListener* progress) const
{
+ size_type len = 0;
+
if (end == std::numeric_limits <size_type>::max())
- os.write(m_buffer.data() + m_start + start, m_end - start - m_start);
- else
- os.write(m_buffer.data() + m_start + start, end - start - m_start);
+ len = m_end - start - m_start;
+ else if (end > start)
+ len = end - start - m_start;
+
+ if (progress)
+ progress->start(len);
+
+ os.write(m_buffer.data() + m_start + start, len);
+
+ if (progress)
+ {
+ progress->progress(len, len);
+ progress->stop(len);
+ }
}