Changeset 14403


Ignore:
Timestamp:
Dec 26, 2014, 6:41:47 PM (8 years ago)
Author:
mikedld
Message:

Refactor FreespaceLabel? to make it possible for it to be created in Qt Designer

Location:
trunk/qt
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/freespace-label.cc

    r14394 r14403  
    2020}
    2121
    22 FreespaceLabel::FreespaceLabel (Session        & session,
    23                                 const QString  & path,
    24                                 QWidget        * parent):
     22FreespaceLabel::FreespaceLabel (QWidget * parent):
    2523  QLabel (parent),
    26   mySession (session),
     24  mySession (nullptr),
    2725  myTag (-1),
    2826  myTimer (this)
    2927{
    30   myTimer.setSingleShot (false);
     28  myTimer.setSingleShot (true);
    3129  myTimer.setInterval (INTERVAL_MSEC);
    32   myTimer.start ();
    3330
    34   connect (&myTimer, SIGNAL(timeout()), this, SLOT(onTimer()));
     31  connect (&myTimer, SIGNAL (timeout ()), this, SLOT (onTimer ()));
     32}
    3533
    36   connect (&mySession, SIGNAL(executed(int64_t, QString, tr_variant *)),
    37            this,       SLOT(onSessionExecuted(int64_t, QString, tr_variant *)));
     34void
     35FreespaceLabel::setSession (Session& session)
     36{
     37  if (mySession == &session)
     38    return;
    3839
    39   setPath (path);
     40  if (mySession != nullptr)
     41    disconnect (mySession, nullptr, this, nullptr);
     42
     43  mySession = &session;
     44
     45  connect (mySession, SIGNAL (executed (int64_t, QString, tr_variant *)),
     46           this,      SLOT (onSessionExecuted (int64_t, QString, tr_variant *)));
     47
     48  onTimer ();
    4049}
    4150
     
    5463FreespaceLabel::onTimer ()
    5564{
    56   const int64_t tag = mySession.getUniqueTag ();
     65  myTimer.stop ();
     66
     67  if (mySession == nullptr || myPath.isEmpty ())
     68    return;
     69
     70  const int64_t tag = mySession->getUniqueTag ();
    5771  const QByteArray myPathUtf8 = myPath.toUtf8 ();
    5872
     
    6478  tr_variant * args = tr_variantDictAddDict (&top, TR_KEY_arguments, 1);
    6579  tr_variantDictAddStr (args, TR_KEY_path, myPathUtf8.constData());
    66   mySession.exec (&top);
     80  mySession->exec (&top);
    6781  tr_variantFree (&top);
    6882}
     
    92106  str = QString::fromUtf8 (path, len);
    93107  setToolTip (str);
     108
     109  myTimer.start ();
    94110}
  • trunk/qt/freespace-label.h

    r14378 r14403  
    2929
    3030  public:
    31     FreespaceLabel (Session&, const QString& path, QWidget *parent=0);
     31    FreespaceLabel (QWidget * parent = 0);
    3232    virtual ~FreespaceLabel () {}
     33
     34    void setSession (Session& session);
    3335    void setPath (const QString& folder);
    3436
    3537  private:
    36     Session& mySession;
     38    Session * mySession;
    3739    int64_t myTag;
    3840    QString myPath;
  • trunk/qt/options.cc

    r14394 r14403  
    110110  layout->addWidget (l, ++row, 0, Qt::AlignLeft);
    111111  const QString downloadDir (prefs.getString (Prefs::DOWNLOAD_DIR));
    112   myFreespaceLabel = new FreespaceLabel (mySession, downloadDir, this);
     112  myFreespaceLabel = new FreespaceLabel (this);
     113  myFreespaceLabel->setSession (mySession);
     114  myFreespaceLabel->setPath (downloadDir);
    113115
    114116  if (session.isLocal ())
  • trunk/qt/prefs-dialog.cc

    r14397 r14403  
    605605
    606606    const QString downloadDir (myPrefs.getString(Prefs::DOWNLOAD_DIR));
    607     l = myFreespaceLabel = new FreespaceLabel (mySession, downloadDir, this);
     607    l = myFreespaceLabel = new FreespaceLabel (this);
     608    myFreespaceLabel->setSession (mySession);
     609    myFreespaceLabel->setPath (downloadDir);
    608610    QHBoxLayout * h = new QHBoxLayout ();
    609611    h->addStretch (1);
Note: See TracChangeset for help on using the changeset viewer.