"Fossies" - the Fresh Open Source Software Archive

Member "seafile-client-7.0.4/src/ui/repo-detail-dialog.cpp" (19 Nov 2019, 4083 Bytes) of package /linux/www/seafile-client-7.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "repo-detail-dialog.cpp" see the Fossies "Dox" file reference documentation.

    1 #include <QtGlobal>
    2 
    3 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
    4 #include <QtWidgets>
    5 #else
    6 #include <QtGui>
    7 #endif
    8 #include <QDir>
    9 #include <QTimer>
   10 
   11 #include "utils/utils.h"
   12 #include "account-mgr.h"
   13 #include "seafile-applet.h"
   14 #include "configurator.h"
   15 #include "api/requests.h"
   16 #include "rpc/rpc-client.h"
   17 #include "rpc/clone-task.h"
   18 #include "rpc/local-repo.h"
   19 #include "utils/utils.h"
   20 
   21 #include "repo-detail-dialog.h"
   22 
   23 namespace {
   24 
   25 
   26 const int kRefrshRepoStatusInterval = 1000; // 1s
   27 
   28 } // namespace
   29 
   30 
   31 RepoDetailDialog::RepoDetailDialog(const ServerRepo &repo, QWidget *parent)
   32     : QDialog(parent),
   33       repo_(repo)
   34 {
   35     setupUi(this);
   36     setWindowTitle(tr("Library \"%1\"").arg(repo.name));
   37     setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
   38     setWindowIcon(QIcon(":/images/seafile.png"));
   39 
   40     mTimeLabel->setText(translateCommitTime(repo.mtime));
   41     mOwnerLabel->setText(repo.owner);
   42     mSizeLabel->setText(readableFileSize(repo.size));
   43 
   44     LocalRepo lrepo;
   45     seafApplet->rpcClient()->getLocalRepo(repo.id, &lrepo);
   46     if (lrepo.isValid()) {
   47         lpathLabel->setVisible(true);
   48         mLpathLabel->setVisible(true);
   49         mLpathLabel->setText(QDir::toNativeSeparators(lrepo.worktree));
   50         if (lrepo.sync_state == LocalRepo::SYNC_STATE_ERROR) {
   51             mStatus->setText(lrepo.sync_error_str);
   52         } else {
   53             mStatus->setText(lrepo.sync_state_str);
   54         }
   55     } else {
   56         mStatus->setText(tr("This library is not downloaded yet"));
   57         lpathLabel->setVisible(false);
   58         mLpathLabel->setVisible(false);
   59     }
   60 
   61     mRepoIcon->setPixmap(repo_.getPixmap());
   62     mRepoName->setText(repo_.name);
   63     #if defined(Q_OS_MAC)
   64     layout()->setContentsMargins(8, 9, 9, 4);
   65     layout()->setSpacing(5);
   66     #endif
   67 
   68     resize(sizeHint());
   69     updateRepoStatus();
   70 
   71     refresh_timer_ = new QTimer(this);
   72     connect(refresh_timer_, SIGNAL(timeout()), this, SLOT(updateRepoStatus()));
   73     refresh_timer_->start(kRefrshRepoStatusInterval);
   74 }
   75 
   76 void RepoDetailDialog::updateRepoStatus()
   77 {
   78     LocalRepo r;
   79     QString text;
   80     seafApplet->rpcClient()->getLocalRepo(repo_.id, &r);
   81     if (r.isValid()) {
   82         if (r.sync_state == LocalRepo::SYNC_STATE_ERROR) {
   83             text = "<p style='color:red'>" + tr("Error: ") + r.sync_error_str + "</p>";
   84         } else {
   85             text = r.sync_state_str;
   86             if (r.sync_state == LocalRepo::SYNC_STATE_ING) {
   87                 // add transfer rate and finished percent
   88                 int rate, percent;
   89                 if (seafApplet->rpcClient()->getRepoTransferInfo(repo_.id, &rate, &percent) == 0) {
   90                     text += ", " + QString::number(percent) + "%, " +  QString("%1 kB/s").arg(rate / 1024);
   91                 }
   92             }
   93         }
   94 
   95         int sync_interval = 0;
   96         QString interval_string;
   97         if (seafApplet->rpcClient()->getRepoProperty(r.id, "sync-interval", &interval_string) == 0) {
   98             sync_interval = interval_string.toInt();
   99             if (sync_interval > 0) {
  100                 mSyncInterval->setText(tr("every %1 seconds").arg(sync_interval));
  101             } else {
  102                 mSyncIntervalLabel->hide();
  103                 mSyncInterval->hide();
  104             }
  105         }
  106 
  107     } else {
  108         std::vector<CloneTask> tasks;
  109         seafApplet->rpcClient()->getCloneTasks(&tasks);
  110 
  111         CloneTask task;
  112 
  113         if (!tasks.empty()) {
  114             for (size_t i = 0; i < tasks.size(); ++i) {
  115                 CloneTask clone_task = tasks[i];
  116                 if (clone_task.repo_id == repo_.id) {
  117                     task = clone_task;
  118                     break;
  119                 }
  120             }
  121         }
  122 
  123         if (task.isValid() && task.isDisplayable()) {
  124             if (task.error_str.length() > 0) {
  125                 text = task.error_str;
  126             } else {
  127                 text = task.state_str;
  128             }
  129         } else {
  130             text = tr("This library is not downloaded yet");
  131         }
  132 
  133         mSyncIntervalLabel->hide();
  134         mSyncInterval->hide();
  135     }
  136 
  137     mStatus->setText(text);
  138 }