Skip to content

Commit

Permalink
download status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
kaniol-lck committed Feb 18, 2022
1 parent 5216045 commit 054414b
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 12 deletions.
3 changes: 3 additions & 0 deletions modmanager.pro
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ SOURCES += \
src/ui/datetimetext.cpp \
src/ui/dockwidgetcontent.cpp \
src/ui/download/adddownloaddialog.cpp \
src/ui/download/downloadstatusbarwidget.cpp \
src/ui/downloadpathselectmenu.cpp \
src/ui/explorestatusbarwidget.cpp \
src/ui/framelesswrapper.cpp \
Expand Down Expand Up @@ -205,6 +206,7 @@ HEADERS += \
src/ui/datetimetext.h \
src/ui/dockwidgetcontent.h \
src/ui/download/adddownloaddialog.h \
src/ui/download/downloadstatusbarwidget.h \
src/ui/downloadpathselectmenu.h \
src/ui/explorestatusbarwidget.h \
src/ui/framelesswrapper.h \
Expand Down Expand Up @@ -284,6 +286,7 @@ FORMS += \
src/ui/datetimetext.ui \
src/ui/download/adddownloaddialog.ui \
src/ui/download/downloadbrowser.ui \
src/ui/download/downloadstatusbarwidget.ui \
src/ui/explorestatusbarwidget.ui \
src/ui/github/githubfileitemwidget.ui \
src/ui/github/githubfilelistwidget.ui \
Expand Down
14 changes: 5 additions & 9 deletions src/ui/download/downloadbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QToolBar>
#include <QClipboard>

#include "downloadstatusbarwidget.h"
#include "ui/download/qaria2downloaderitemwidget.h"
#include "download/downloadmanager.h"
#include "download/qaria2.h"
Expand All @@ -17,9 +18,11 @@
DownloadBrowser::DownloadBrowser(QWidget *parent) :
Browser(parent),
ui(new Ui::DownloadBrowser),
manager_(DownloadManager::manager())
manager_(DownloadManager::manager()),
statusBarWidget_(new DownloadStatusBarWidget(this))
{
ui->setupUi(this);
ui->statusbar->addPermanentWidget(statusBarWidget_);

for(auto &&toolBar : findChildren<QToolBar *>())
ui->menu_View->addAction(toolBar->toggleViewAction());
Expand All @@ -35,7 +38,7 @@ DownloadBrowser::DownloadBrowser(QWidget *parent) :
connect(manager_->qaria2(), &QAria2::finished, this, [=]{
ui->statusbar->showMessage("Idoling");
});
connect(manager_->qaria2(), &QAria2::downloadSpeed, this, &DownloadBrowser::downloadSpeed);
connect(manager_->qaria2(), &QAria2::downloadSpeed, statusBarWidget_, &DownloadStatusBarWidget::setDownloadSpeed);
onCurrentRowChanged();
connect(ui->downloaderListView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &DownloadBrowser::onCurrentRowChanged);
}
Expand All @@ -55,13 +58,6 @@ QString DownloadBrowser::name() const
return tr("Downloader");
}

void DownloadBrowser::downloadSpeed(qint64 download, qint64 upload)
{
auto text = tr("Download Speed:") + speedConvert(download) +
" " + tr("Upload Speed:") + speedConvert(upload);
ui->statusbar->showMessage(text);
}

void DownloadBrowser::onCurrentRowChanged()
{
auto row = ui->downloaderListView->currentIndex().row();
Expand Down
5 changes: 2 additions & 3 deletions src/ui/download/downloadbrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DownloadBrowser;
class DownloadManager;
class QAria2Downloader;
class QAria2;

class DownloadStatusBarWidget;
class DownloadBrowser : public Browser
{
Q_OBJECT
Expand All @@ -22,8 +22,6 @@ class DownloadBrowser : public Browser

QIcon icon() const override;
QString name() const override;
public slots:
void downloadSpeed(qint64 download, qint64 upload = 0);

private slots:
void onCurrentRowChanged();
Expand All @@ -45,6 +43,7 @@ private slots:
Ui::DownloadBrowser *ui;
DownloadManager *manager_;
QMetaObject::Connection conn_;
DownloadStatusBarWidget *statusBarWidget_;
};

#endif // DOWNLOADBROWSER_H
22 changes: 22 additions & 0 deletions src/ui/download/downloadstatusbarwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "downloadstatusbarwidget.h"
#include "ui_downloadstatusbarwidget.h"

#include "util/funcutil.h"

DownloadStatusBarWidget::DownloadStatusBarWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::DownloadStatusBarWidget)
{
ui->setupUi(this);
}

DownloadStatusBarWidget::~DownloadStatusBarWidget()
{
delete ui;
}

void DownloadStatusBarWidget::setDownloadSpeed(qint64 download, qint64 upload)
{
ui->downloadSpeed->setText(tr("Download: %1").arg(speedConvert(download)));
ui->uploadSpeed->setText(tr("Upload: %1").arg(speedConvert(upload)));
}
25 changes: 25 additions & 0 deletions src/ui/download/downloadstatusbarwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef DOWNLOADSTATUSBARWIDGET_H
#define DOWNLOADSTATUSBARWIDGET_H

#include <QWidget>

namespace Ui {
class DownloadStatusBarWidget;
}

class DownloadStatusBarWidget : public QWidget
{
Q_OBJECT

public:
explicit DownloadStatusBarWidget(QWidget *parent = nullptr);
~DownloadStatusBarWidget();

public slots:
void setDownloadSpeed(qint64 download, qint64 upload);

private:
Ui::DownloadStatusBarWidget *ui;
};

#endif // DOWNLOADSTATUSBARWIDGET_H
66 changes: 66 additions & 0 deletions src/ui/download/downloadstatusbarwidget.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DownloadStatusBarWidget</class>
<widget class="QWidget" name="DownloadStatusBarWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>24</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>363</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="downloadSpeed"/>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="uploadSpeed"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

0 comments on commit 054414b

Please sign in to comment.