]> granicus.if.org Git - transmission/commitdiff
(qt) #4076 'free space indicator': better user feedback when updating the freespace...
authorJordan Lee <jordan@transmissionbt.com>
Sat, 9 Feb 2013 04:42:07 +0000 (04:42 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Sat, 9 Feb 2013 04:42:07 +0000 (04:42 +0000)
qt/freespace-label.cc
qt/freespace-label.h
qt/options.cc
qt/options.h

index 25a955f9650491fefc84e327edd5ebaa25ac81f8..bffda4d53b9b07e0ff40cab5070f31b06d3c8624 100644 (file)
@@ -28,7 +28,6 @@ FreespaceLabel :: FreespaceLabel (Session        & session,
   QLabel (parent),
   mySession (session),
   myTag (-1),
-  myPath (path),
   myTimer (this)
 {
   myTimer.setSingleShot (false);
@@ -40,7 +39,18 @@ FreespaceLabel :: FreespaceLabel (Session        & session,
   connect (&mySession, SIGNAL(executed(int64_t, const QString&, struct tr_variant*)),
            this,       SLOT(onSessionExecuted(int64_t, const QString&, struct tr_variant*)));
 
-  onTimer ();
+  setPath (path);
+}
+
+void
+FreespaceLabel :: setPath (const QString& path)
+{
+  if (myPath != path)
+    {
+      setText (tr("<i>Counting Free Space...</i>"));
+      myPath = path;
+      onTimer ();
+    }
 }
 
 void
index ea844c1f467a93f2d28ad9346990dd178e5dac85..d280ed2e8f9975132b6c141f01f50d2dead3591a 100644 (file)
@@ -27,7 +27,7 @@ class FreespaceLabel: public QLabel
   public:
     FreespaceLabel (Session&, const QString& path, QWidget *parent=0);
     virtual ~FreespaceLabel () {}
-    void setPath (const QString& folder) { myPath=folder; onTimer(); }
+    void setPath (const QString& folder);
 
   private:
     Session& mySession;
index 2f60866baa2b44adc4e3acca8cc0d2b52fd4d2d8..d97ab32750a8a74a346210e646cc64570f8df119 100644 (file)
@@ -10,8 +10,6 @@
  * $Id$
  */
 
-#include <cstdio>
-
 #include <QApplication>
 #include <QCheckBox>
 #include <QComboBox>
@@ -87,14 +85,18 @@ Options :: Options( Session& session, const Prefs& prefs, const AddData& addme,
     myDestinationButton( 0 ),
     myVerifyButton( 0 ),
     myVerifyFile( 0 ),
-    myVerifyHash( QCryptographicHash::Sha1 )
-
+    myVerifyHash( QCryptographicHash::Sha1 ),
+    myEditTimer (this)
 {
     setWindowTitle( tr( "Open Torrent" ) );
     QFontMetrics fontMetrics( font( ) );
     QGridLayout * layout = new QGridLayout( this );
     int row = 0;
 
+    myEditTimer.setInterval (2000);
+    myEditTimer.setSingleShot (true);
+    connect (&myEditTimer, SIGNAL(timeout()), this, SLOT(onDestinationEditedIdle()));
+
     const int iconSize( style( )->pixelMetric( QStyle :: PM_SmallIconSize ) );
     QIcon fileIcon = style( )->standardIcon( QStyle::SP_FileIcon );
     const QPixmap filePixmap = fileIcon.pixmap( iconSize );
@@ -120,6 +122,7 @@ Options :: Options( Session& session, const Prefs& prefs, const AddData& addme,
     l = new QLabel( tr( "&Destination folder:" ) );
     layout->addWidget( l, ++row, 0, Qt::AlignLeft );
     const QString downloadDir (prefs.getString (Prefs::DOWNLOAD_DIR));
+    myFreespaceLabel = new FreespaceLabel (mySession, downloadDir, this);
 
     if( session.isLocal( ) )
     {
@@ -138,9 +141,10 @@ Options :: Options( Session& session, const Prefs& prefs, const AddData& addme,
         e->setText (downloadDir);
         layout->addWidget( e, row, 1 );
         l->setBuddy( e );
+        connect (e, SIGNAL(textEdited(const QString&)), this, SLOT(onDestinationEdited(const QString&)));
     }
 
-    l = myFreespaceLabel = new FreespaceLabel (mySession, downloadDir, this);
+    l = myFreespaceLabel;
     layout->addWidget (l, ++row, 0, 1, 2, Qt::Alignment (Qt::AlignRight | Qt::AlignTop));
     layout->setRowMinimumHeight (row, l->height() + HIG::PAD);
 
@@ -465,6 +469,20 @@ Options :: onDestinationsSelected (const QStringList& destinations)
     }
 }
 
+void
+Options :: onDestinationEdited (const QString& text)
+{
+  Q_UNUSED (text);
+
+  myEditTimer.start ();
+}
+
+void
+Options :: onDestinationEditedIdle ()
+{
+  myFreespaceLabel->setPath (myDestinationEdit->text());
+}
+
 /***
 ****
 ****  VERIFY
index d275ffb4a6a6e558ce8795ecce79c1c76efde8e2..ad7b99d074a24dd820d435ea7f291d79b2a09b5e 100644 (file)
@@ -102,6 +102,8 @@ class Options: public QDialog
         void onDestinationClicked( );
         void onFilesSelected( const QStringList& );
         void onDestinationsSelected( const QStringList& );
+        void onDestinationEdited (const QString&);
+        void onDestinationEditedIdle ();
 
     private:
         bool eventFilter( QObject *, QEvent * );
@@ -119,6 +121,7 @@ class Options: public QDialog
         QCryptographicHash myVerifyHash;
         typedef QMap<uint32_t,int32_t> mybins_t;
         mybins_t myVerifyBins;
+        QTimer myEditTimer;
 
 };