Browse Source

2009-05-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	DownloadResult now has the list of FileEntry.  The download
	summary displays the path of first selected file and the number of
	remaining files for multi-file torrent.
	* src/DownloadResult.h
	* src/RequestGroup.cc
	* src/RequestGroupMan.cc
	* test/RequestGroupTest.cc
Tatsuhiro Tsujikawa 16 years ago
parent
commit
8bbbc9c33b
5 changed files with 66 additions and 11 deletions
  1. 10 0
      ChangeLog
  2. 5 3
      src/DownloadResult.h
  3. 1 1
      src/RequestGroup.cc
  4. 48 6
      src/RequestGroupMan.cc
  5. 2 1
      test/RequestGroupTest.cc

+ 10 - 0
ChangeLog

@@ -1,3 +1,13 @@
+2009-05-12  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	DownloadResult now has the list of FileEntry.  The download
+	summary displays the path of first selected file and the number of
+	remaining files for multi-file torrent.
+	* src/DownloadResult.h
+	* src/RequestGroup.cc
+	* src/RequestGroupMan.cc
+	* test/RequestGroupTest.cc
+	
 2009-05-12  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 2009-05-12  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 
 	Fixed segmentation fault error when no file is selected in
 	Fixed segmentation fault error when no file is selected in

+ 5 - 3
src/DownloadResult.h

@@ -40,8 +40,10 @@
 #include <stdint.h>
 #include <stdint.h>
 
 
 #include <string>
 #include <string>
+#include <deque>
 
 
 #include "SharedHandle.h"
 #include "SharedHandle.h"
+#include "FileEntry.h"
 
 
 namespace aria2 {
 namespace aria2 {
 
 
@@ -62,7 +64,7 @@ public:
 
 
   int32_t gid;
   int32_t gid;
  
  
-  std::string filePath;
+  std::deque<SharedHandle<FileEntry> > fileEntries;
 
 
   uint64_t totalLength;
   uint64_t totalLength;
 
 
@@ -78,7 +80,7 @@ public:
   RESULT result;
   RESULT result;
 
 
   DownloadResult(int32_t gid,
   DownloadResult(int32_t gid,
-		 const std::string& filePath,
+		 const std::deque<SharedHandle<FileEntry> >& fileEntries,
 		 uint64_t totalLength,
 		 uint64_t totalLength,
 		 const std::string& uri,
 		 const std::string& uri,
 		 size_t numUri,
 		 size_t numUri,
@@ -86,7 +88,7 @@ public:
 		 int64_t sessionTime,
 		 int64_t sessionTime,
 		 RESULT result):
 		 RESULT result):
     gid(gid),
     gid(gid),
-    filePath(filePath),
+    fileEntries(fileEntries),
     totalLength(totalLength),
     totalLength(totalLength),
     uri(uri),
     uri(uri),
     numUri(numUri),
     numUri(numUri),

+ 1 - 1
src/RequestGroup.cc

@@ -1025,7 +1025,7 @@ DownloadResultHandle RequestGroup::createDownloadResult() const
   return
   return
     SharedHandle<DownloadResult>
     SharedHandle<DownloadResult>
     (new DownloadResult(_gid,
     (new DownloadResult(_gid,
-			getFilePath(),
+			_downloadContext->getFileEntries(),
 			getTotalLength(),
 			getTotalLength(),
 			uris.empty() ? A2STR::NIL:uris.front(),
 			uris.empty() ? A2STR::NIL:uris.front(),
 			uris.size(),
 			uris.size(),

+ 48 - 6
src/RequestGroupMan.cc

@@ -538,6 +538,50 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const
   }
   }
 }
 }
 
 
+template<typename InputIterator>
+static SharedHandle<FileEntry> getFirstRequestedFileEntry
+(InputIterator first, InputIterator last)
+{
+  for(; first != last; ++first) {
+    if((*first)->isRequested()) {
+      return *first;
+    }
+  }
+  return SharedHandle<FileEntry>();
+}
+
+template<typename InputIterator>
+static size_t countRequestedFileEntry(InputIterator first, InputIterator last)
+{
+  size_t count = 0;
+  for(; first != last; ++first) {
+    if((*first)->isRequested()) {
+      ++count;
+    }
+  }
+  return count;
+}
+
+template<typename InputIterator>
+static void writeFilePath
+(InputIterator first, InputIterator last, std::ostream& o)
+{
+  SharedHandle<FileEntry> e = getFirstRequestedFileEntry(first, last);
+  if(e.isNull()) {
+    o << "n/a";
+  } else {
+    if(e->getPath().empty()) {
+      o << "n/a";
+    } else {
+      o << e->getPath();
+    }
+    size_t count = countRequestedFileEntry(first, last);
+    if(count > 1) {
+      o << " (" << count-1 << "more)";
+    }
+  }
+}
+
 std::string RequestGroupMan::formatDownloadResult(const std::string& status, const DownloadResultHandle& downloadResult) const
 std::string RequestGroupMan::formatDownloadResult(const std::string& status, const DownloadResultHandle& downloadResult) const
 {
 {
   std::stringstream o;
   std::stringstream o;
@@ -552,15 +596,13 @@ std::string RequestGroupMan::formatDownloadResult(const std::string& status, con
     o << "n/a";
     o << "n/a";
   }
   }
   o << "|";
   o << "|";
+  const std::deque<SharedHandle<FileEntry> >& fileEntries =
+    downloadResult->fileEntries;
   if(downloadResult->result == DownloadResult::FINISHED) {
   if(downloadResult->result == DownloadResult::FINISHED) {
-    o << downloadResult->filePath;
+    writeFilePath(fileEntries.begin(), fileEntries.end(), o);
   } else {
   } else {
     if(downloadResult->numUri == 0) {
     if(downloadResult->numUri == 0) {
-      if(downloadResult->filePath.empty()) {
-	o << "n/a";
-      } else {
-	o << downloadResult->filePath;
-      }
+      writeFilePath(fileEntries.begin(), fileEntries.end(), o);
     } else {
     } else {
       o << downloadResult->uri;
       o << downloadResult->uri;
       if(downloadResult->numUri > 1) {
       if(downloadResult->numUri > 1) {

+ 2 - 1
test/RequestGroupTest.cc

@@ -112,7 +112,8 @@ void RequestGroupTest::testCreateDownloadResult()
   {
   {
     SharedHandle<DownloadResult> result = group.createDownloadResult();
     SharedHandle<DownloadResult> result = group.createDownloadResult();
   
   
-    CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"), result->filePath);
+    CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"),
+			 result->fileEntries[0]->getPath());
     CPPUNIT_ASSERT_EQUAL((uint64_t)1024*1024, result->totalLength);
     CPPUNIT_ASSERT_EQUAL((uint64_t)1024*1024, result->totalLength);
     CPPUNIT_ASSERT_EQUAL(std::string("http://first/file"), result->uri);
     CPPUNIT_ASSERT_EQUAL(std::string("http://first/file"), result->uri);
     CPPUNIT_ASSERT_EQUAL((size_t)2, result->numUri);
     CPPUNIT_ASSERT_EQUAL((size_t)2, result->numUri);