From 656aa9db5dea0e1dae10065adfa7600b0dac5980 Mon Sep 17 00:00:00 2001
From: defnax <retroshare.project@gmail.com>
Date: Tue, 26 Jan 2010 14:57:05 +0000
Subject: [PATCH] Added Chunk size and Number of Chunks to DetailsDialog

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2131 b45a01b8-16f6-495d-af2f-9b41ad6348cc
---
 retroshare-gui/src/gui/DetailsDialog.cpp   | 36 +++++++++++
 retroshare-gui/src/gui/DetailsDialog.h     |  8 +++
 retroshare-gui/src/gui/DetailsDialog.ui    | 72 ++++++++++++++++------
 retroshare-gui/src/gui/TransfersDialog.cpp | 21 ++++++-
 4 files changed, 115 insertions(+), 22 deletions(-)

diff --git a/retroshare-gui/src/gui/DetailsDialog.cpp b/retroshare-gui/src/gui/DetailsDialog.cpp
index 4a01c7d48..2abcc01c3 100644
--- a/retroshare-gui/src/gui/DetailsDialog.cpp
+++ b/retroshare-gui/src/gui/DetailsDialog.cpp
@@ -36,6 +36,8 @@
 #include <QStandardItemModel>
 
 #include "util/misc.h"
+#include <rsiface/rsfiles.h>
+#include <rsiface/rstypes.h>
 
 /** Default constructor */
 DetailsDialog::DetailsDialog(QWidget *parent, Qt::WFlags flags)
@@ -60,6 +62,8 @@ DetailsDialog::DetailsDialog(QWidget *parent, Qt::WFlags flags)
   _coheader->resizeSection ( 0, 100 );
 	_coheader->resizeSection ( 1, 240 );
 	_coheader->resizeSection ( 2, 100 );
+	
+	updateDisplay();
 
  
 }
@@ -85,6 +89,7 @@ void DetailsDialog::on_cancel_dButton_clicked()
 void
 DetailsDialog::show()
 {
+    ui.tabWidget->setCurrentIndex(0);
     if (!this->isVisible()) {
     QDialog::show();
   } else {
@@ -180,3 +185,34 @@ void DetailsDialog::setLink(const QString & link)
 {
 	ui.Linktext->setText(link);
 }
+
+void DetailsDialog::showEvent(QShowEvent *event)
+{
+    updateDisplay();
+}
+
+void DetailsDialog::updateDisplay()
+{
+       
+       bool ok=true ;
+       FileInfo nfo ;
+       if(!rsFiles->FileDetails(_file_hash, RS_FILE_HINTS_DOWNLOAD, nfo)) 
+       ok = false ;
+       FileChunksInfo info ;
+       if(!rsFiles->FileDownloadChunksDetails(_file_hash, info)) 
+       ok = false ;
+            
+       if(ok)
+       {
+       uint32_t blockSize = info.chunk_size ;
+
+       ui.chunksizelabel->setText(misc::friendlyUnit(blockSize));
+       ui.numberofchunkslabel->setText(QString::number(info.chunks.size()));
+
+       }
+
+            
+}            
+
+
+            
\ No newline at end of file
diff --git a/retroshare-gui/src/gui/DetailsDialog.h b/retroshare-gui/src/gui/DetailsDialog.h
index 1d9e5d932..21450eac2 100644
--- a/retroshare-gui/src/gui/DetailsDialog.h
+++ b/retroshare-gui/src/gui/DetailsDialog.h
@@ -29,6 +29,7 @@
 
 #include "ui_DetailsDialog.h"
 
+class FileChunksInfo ;
 
 class DetailsDialog : public QDialog
 {
@@ -39,7 +40,10 @@ public:
   DetailsDialog(QWidget *parent = 0, Qt::WFlags flags = 0);
   /** Default destructor */
   ~DetailsDialog();
+  
+  void updateDisplay() ;
 
+	void setFileHash(const std::string& hash) { _file_hash = hash ; }
 
 public slots:
   /** Overloaded QWidget.show */
@@ -56,10 +60,13 @@ public slots:
 	void setCompleted(const qulonglong & completed); 
   void setRemaining(const qulonglong & remaining) ;
   void setType(const QString & type); 
+
  
 protected:
   void closeEvent (QCloseEvent * event);
   
+	virtual void showEvent(QShowEvent * event);
+  
 private slots:
   void on_ok_dButton_clicked();
   void on_cancel_dButton_clicked();
@@ -68,6 +75,7 @@ private:
 
 	class QStandardItemModel *CommentsModel;
 
+	 std::string _file_hash ;
 
   
   /** Qt Designer generated object */
diff --git a/retroshare-gui/src/gui/DetailsDialog.ui b/retroshare-gui/src/gui/DetailsDialog.ui
index 086e9cc99..ab7c0ae58 100644
--- a/retroshare-gui/src/gui/DetailsDialog.ui
+++ b/retroshare-gui/src/gui/DetailsDialog.ui
@@ -201,13 +201,6 @@
             </property>
            </widget>
           </item>
-          <item row="3" column="0">
-           <widget class="QLabel" name="remaining_label">
-            <property name="text">
-             <string>Remaining:</string>
-            </property>
-           </widget>
-          </item>
           <item row="0" column="1">
            <widget class="QLabel" name="sources_line">
             <property name="text">
@@ -229,18 +222,7 @@
             </property>
            </widget>
           </item>
-          <item row="3" column="1">
-           <widget class="QLabel" name="remaining_line">
-            <property name="text">
-             <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
-&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
-p, li { white-space: pre-wrap; }
-&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
-&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;Remaining Label&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-            </property>
-           </widget>
-          </item>
-          <item row="0" column="2" rowspan="4">
+          <item row="0" column="2" rowspan="7">
            <spacer name="horizontalSpacer_2">
             <property name="orientation">
              <enum>Qt::Horizontal</enum>
@@ -253,6 +235,58 @@ p, li { white-space: pre-wrap; }
             </property>
            </spacer>
           </item>
+          <item row="3" column="1">
+           <widget class="QLabel" name="chunksizelabel">
+            <property name="text">
+             <string>Chunks Label</string>
+            </property>
+           </widget>
+          </item>
+          <item row="3" column="0">
+           <widget class="QLabel" name="label">
+            <property name="text">
+             <string>Chunk size:</string>
+            </property>
+           </widget>
+          </item>
+          <item row="4" column="1">
+           <widget class="QLabel" name="numberofchunkslabel">
+            <property name="toolTip">
+             <string>Number of Chunks</string>
+            </property>
+            <property name="text">
+             <string>Chunks Number Label</string>
+            </property>
+           </widget>
+          </item>
+          <item row="4" column="0">
+           <widget class="QLabel" name="label_2">
+            <property name="toolTip">
+             <string>Number of Chunks</string>
+            </property>
+            <property name="text">
+             <string>Chunks:</string>
+            </property>
+           </widget>
+          </item>
+          <item row="5" column="1">
+           <widget class="QLabel" name="remaining_line">
+            <property name="text">
+             <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
+&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
+p, li { white-space: pre-wrap; }
+&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
+&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;Remaining Label&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+            </property>
+           </widget>
+          </item>
+          <item row="5" column="0">
+           <widget class="QLabel" name="remaining_label">
+            <property name="text">
+             <string>Remaining:</string>
+            </property>
+           </widget>
+          </item>
          </layout>
         </widget>
        </item>
diff --git a/retroshare-gui/src/gui/TransfersDialog.cpp b/retroshare-gui/src/gui/TransfersDialog.cpp
index 4c7864e70..923433410 100644
--- a/retroshare-gui/src/gui/TransfersDialog.cpp
+++ b/retroshare-gui/src/gui/TransfersDialog.cpp
@@ -384,16 +384,18 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
 		contextMnu.addAction( cancelAct);
 		contextMnu.addSeparator();
 	}
-#ifndef RS_RELEASE_VERSION
+
 	if(single)
 	{
+#ifndef RS_RELEASE_VERSION
 		contextMnu.addAction( openfileAct);
 		contextMnu.addAction( previewfileAct);
-		contextMnu.addAction( openfolderAct);
+#endif		
+    contextMnu.addAction( openfolderAct);
 		contextMnu.addAction( detailsfileAct);
 		contextMnu.addSeparator();
 	}
-#endif
+
 	contextMnu.addAction( clearcompletedAct);
 	contextMnu.addSeparator();
 #ifndef RS_RELEASE_VERSION
@@ -1156,6 +1158,8 @@ void TransfersDialog::showDetailsDialog()
     
     QModelIndexList lst = ui.downloadList->selectionModel ()->selectedIndexes ();
     RetroShareLinkAnalyzer analyzer;
+    
+    std::string file_hash ;
 
     for (int i = 0; i < lst.count (); i++)
     {
@@ -1174,6 +1178,17 @@ void TransfersDialog::showDetailsDialog()
             qulonglong fcompleted = ind.model ()->data (ind.model ()->index (ind.row (), COMPLETED)).toULongLong() ;
             qulonglong fremaining = ind.model ()->data (ind.model ()->index (ind.row (), REMAINING)).toULongLong() ;
             
+            int nb_select = 0 ;
+            
+            for(int i = 0; i <= DLListModel->rowCount(); i++) 
+            if(selection->isRowSelected(i, QModelIndex())) 
+            {
+              file_hash = getID(i, DLListModel).toStdString();
+              ++nb_select ;
+            }
+            
+            detailsdlg->setFileHash(file_hash);
+            
             // Set Details.. Window Title
             detailsdlg->setWindowTitle(tr("Details:") + fname);