New lang, download manager tweaks.

This commit is contained in:
Martin Rotter 2015-03-15 17:42:36 +01:00
parent cbf16f6233
commit 41eb010c12
16 changed files with 198 additions and 55 deletions

View File

@ -69,7 +69,7 @@
</message> </message>
<message> <message>
<source>Error: %1</source> <source>Error: %1</source>
<translation type="unfinished">Chyba: %1. {1?}</translation> <translation>Chyba: %1</translation>
</message> </message>
<message> <message>
<source>Cannot open folder</source> <source>Cannot open folder</source>
@ -138,6 +138,14 @@
<source>GB</source> <source>GB</source>
<translation></translation> <translation></translation>
</message> </message>
<message numerus="yes">
<source>Downloading %n file(s)...</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
</context> </context>
<context> <context>
<name>FeedMessageViewer</name> <name>FeedMessageViewer</name>

View File

@ -136,6 +136,13 @@
<source>GB</source> <source>GB</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message numerus="yes">
<source>Downloading %n file(s)...</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
</context> </context>
<context> <context>
<name>FeedMessageViewer</name> <name>FeedMessageViewer</name>

View File

@ -136,6 +136,13 @@
<source>GB</source> <source>GB</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message numerus="yes">
<source>Downloading %n file(s)...</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
</context> </context>
<context> <context>
<name>FeedMessageViewer</name> <name>FeedMessageViewer</name>

View File

@ -4,7 +4,7 @@
<context> <context>
<name>Application</name> <name>Application</name>
<message> <message>
<location filename="../src/miscellaneous/application.cpp" line="109"/> <location filename="../src/miscellaneous/application.cpp" line="122"/>
<source>Application is already running.</source> <source>Application is already running.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -132,7 +132,15 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message numerus="yes"> <message numerus="yes">
<location filename="../src/network-web/downloadmanager.cpp" line="668"/> <location filename="../src/network-web/downloadmanager.cpp" line="563"/>
<source>Downloading %n file(s)...</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
<message numerus="yes">
<location filename="../src/network-web/downloadmanager.cpp" line="701"/>
<source>%n minutes remaining</source> <source>%n minutes remaining</source>
<translation type="unfinished"> <translation type="unfinished">
<numerusform></numerusform> <numerusform></numerusform>
@ -140,7 +148,7 @@
</translation> </translation>
</message> </message>
<message numerus="yes"> <message numerus="yes">
<location filename="../src/network-web/downloadmanager.cpp" line="672"/> <location filename="../src/network-web/downloadmanager.cpp" line="705"/>
<source>%n seconds remaining</source> <source>%n seconds remaining</source>
<translation type="unfinished"> <translation type="unfinished">
<numerusform></numerusform> <numerusform></numerusform>
@ -148,22 +156,22 @@
</translation> </translation>
</message> </message>
<message> <message>
<location filename="../src/network-web/downloadmanager.cpp" line="684"/> <location filename="../src/network-web/downloadmanager.cpp" line="717"/>
<source>bytes</source> <source>bytes</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/network-web/downloadmanager.cpp" line="688"/> <location filename="../src/network-web/downloadmanager.cpp" line="721"/>
<source>kB</source> <source>kB</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/network-web/downloadmanager.cpp" line="692"/> <location filename="../src/network-web/downloadmanager.cpp" line="725"/>
<source>MB</source> <source>MB</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/network-web/downloadmanager.cpp" line="696"/> <location filename="../src/network-web/downloadmanager.cpp" line="729"/>
<source>GB</source> <source>GB</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -3119,12 +3127,12 @@ currently installed one.</source>
<context> <context>
<name>StatusBar</name> <name>StatusBar</name>
<message> <message>
<location filename="../src/gui/statusbar.cpp" line="36"/> <location filename="../src/gui/statusbar.cpp" line="37"/>
<source>Fullscreen mode</source> <source>Fullscreen mode</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../src/gui/statusbar.cpp" line="37"/> <location filename="../src/gui/statusbar.cpp" line="38"/>
<source>Switch application between fulscreen/normal states right from this status bar icon.</source> <source>Switch application between fulscreen/normal states right from this status bar icon.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View File

@ -136,6 +136,13 @@
<source>GB</source> <source>GB</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message numerus="yes">
<source>Downloading %n file(s)...</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
</context> </context>
<context> <context>
<name>FeedMessageViewer</name> <name>FeedMessageViewer</name>

View File

@ -136,6 +136,13 @@
<source>GB</source> <source>GB</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message numerus="yes">
<source>Downloading %n file(s)...</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
</context> </context>
<context> <context>
<name>FeedMessageViewer</name> <name>FeedMessageViewer</name>

View File

@ -136,6 +136,13 @@
<source>GB</source> <source>GB</source>
<translation>GB</translation> <translation>GB</translation>
</message> </message>
<message numerus="yes">
<source>Downloading %n file(s)...</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
</context> </context>
<context> <context>
<name>FeedMessageViewer</name> <name>FeedMessageViewer</name>

View File

@ -136,6 +136,13 @@
<source>GB</source> <source>GB</source>
<translation>GB</translation> <translation>GB</translation>
</message> </message>
<message numerus="yes">
<source>Downloading %n file(s)...</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
</context> </context>
<context> <context>
<name>FeedMessageViewer</name> <name>FeedMessageViewer</name>

View File

@ -164,20 +164,20 @@ void FeedMessageViewer::updateTrayIconStatus(int unread_messages, int total_mess
void FeedMessageViewer::onFeedUpdatesStarted() { void FeedMessageViewer::onFeedUpdatesStarted() {
//: Text display in status bar when feed update is started. //: Text display in status bar when feed update is started.
qApp->mainForm()->statusBar()->showProgress(0, tr("Feed update started")); qApp->mainForm()->statusBar()->showProgressFeeds(0, tr("Feed update started"));
} }
void FeedMessageViewer::onFeedUpdatesProgress(FeedsModelFeed *feed, int current, int total) { void FeedMessageViewer::onFeedUpdatesProgress(FeedsModelFeed *feed, int current, int total) {
// Some feed got updated. // Some feed got updated.
m_feedsView->updateCountsOfParticularFeed(feed, true); m_feedsView->updateCountsOfParticularFeed(feed, true);
qApp->mainForm()->statusBar()->showProgress((current * 100.0) / total, qApp->mainForm()->statusBar()->showProgressFeeds((current * 100.0) / total,
//: Text display in status bar when particular feed is updated. //: Text display in status bar when particular feed is updated.
tr("Updated feed '%1'").arg(feed->title())); tr("Updated feed '%1'").arg(feed->title()));
} }
void FeedMessageViewer::onFeedUpdatesFinished() { void FeedMessageViewer::onFeedUpdatesFinished() {
qApp->closeLock()->unlock(); qApp->closeLock()->unlock();
qApp->mainForm()->statusBar()->clearProgress(); qApp->mainForm()->statusBar()->clearProgressFeeds();
m_messagesView->reloadSelections(1); m_messagesView->reloadSelections(1);
} }

View File

@ -17,11 +17,14 @@
#include "gui/statusbar.h" #include "gui/statusbar.h"
#include "gui/formmain.h"
#include "gui/tabwidget.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include <QToolButton> #include <QToolButton>
#include <QLabel> #include <QLabel>
#include <QProgressBar> #include <QProgressBar>
#include <QThread>
StatusBar::StatusBar(QWidget *parent) : QStatusBar(parent) { StatusBar::StatusBar(QWidget *parent) : QStatusBar(parent) {
@ -36,18 +39,33 @@ StatusBar::StatusBar(QWidget *parent) : QStatusBar(parent) {
m_fullscreenSwitcher->setText(tr("Fullscreen mode")); m_fullscreenSwitcher->setText(tr("Fullscreen mode"));
m_fullscreenSwitcher->setToolTip(tr("Switch application between fulscreen/normal states right from this status bar icon.")); m_fullscreenSwitcher->setToolTip(tr("Switch application between fulscreen/normal states right from this status bar icon."));
m_progressBar = new QProgressBar(this); m_barProgressFeeds = new QProgressBar(this);
m_progressBar->setTextVisible(false); m_barProgressFeeds->setTextVisible(false);
m_progressBar->setFixedWidth(100); m_barProgressFeeds->setFixedWidth(100);
m_progressBar->setVisible(false); m_barProgressFeeds->setVisible(false);
m_progressLabel = new QLabel(this); m_lblProgressFeeds = new QLabel(this);
m_progressLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); m_lblProgressFeeds->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_progressLabel->setVisible(false); m_lblProgressFeeds->setVisible(false);
m_barProgressDownload = new QProgressBar(this);
m_barProgressDownload->setTextVisible(true);
m_barProgressDownload->setFixedWidth(100);
m_barProgressDownload->setVisible(false);
m_lblProgressDownload = new QLabel(this);
m_lblProgressDownload->setText("Downloading files in background");
m_lblProgressDownload->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_lblProgressDownload->setVisible(false);
// TODO: nastavit event filter na label a progress aby se po kliku
// otevřel download manager
// Add widgets. // Add widgets.
addWidget(m_progressBar); addPermanentWidget(m_lblProgressFeeds);
addWidget(m_progressLabel); addPermanentWidget(m_barProgressFeeds);
addPermanentWidget(m_lblProgressDownload);
addPermanentWidget(m_barProgressDownload);
addPermanentWidget(m_fullscreenSwitcher); addPermanentWidget(m_fullscreenSwitcher);
} }
@ -55,15 +73,33 @@ StatusBar::~StatusBar() {
qDebug("Destroying StatusBar instance."); qDebug("Destroying StatusBar instance.");
} }
void StatusBar::showProgress(int progress, const QString &label) { void StatusBar::displayDownloadManager() {
m_progressLabel->setVisible(true); qApp->mainForm()->tabWidget()->showDownloadManager();
m_progressBar->setVisible(true);
m_progressLabel->setText(label);
m_progressBar->setValue(progress);
} }
void StatusBar::clearProgress() { void StatusBar::showProgressFeeds(int progress, const QString &label) {
m_progressLabel->setVisible(false); m_lblProgressFeeds->setVisible(true);
m_progressBar->setVisible(false); m_barProgressFeeds->setVisible(true);
m_lblProgressFeeds->setText(label);
m_barProgressFeeds->setValue(progress);
}
void StatusBar::clearProgressFeeds() {
m_lblProgressFeeds->setVisible(false);
m_barProgressFeeds->setVisible(false);
}
void StatusBar::showProgressDownload(int progress, const QString &tooltip) {
m_lblProgressDownload->setVisible(true);
m_barProgressDownload->setVisible(true);
m_barProgressDownload->setValue(progress);
m_barProgressDownload->setToolTip(tooltip);
m_lblProgressDownload->setToolTip(tooltip);
}
void StatusBar::clearProgressDownload() {
m_lblProgressDownload->setVisible(false);
m_barProgressDownload->setVisible(false);
m_barProgressDownload->setValue(0);
} }

View File

@ -37,13 +37,19 @@ class StatusBar : public QStatusBar {
return m_fullscreenSwitcher; return m_fullscreenSwitcher;
} }
public slots:
// Progress bar operations // Progress bar operations
void showProgress(int progress, const QString &label); void showProgressFeeds(int progress, const QString &label);
void clearProgress(); void clearProgressFeeds();
void showProgressDownload(int progress, const QString &tooltip);
void clearProgressDownload();
private: private:
QProgressBar *m_progressBar; QProgressBar *m_barProgressFeeds;
QLabel *m_progressLabel; QLabel *m_lblProgressFeeds;
QProgressBar *m_barProgressDownload;
QLabel *m_lblProgressDownload;
QToolButton *m_fullscreenSwitcher; QToolButton *m_fullscreenSwitcher;
}; };

View File

@ -118,9 +118,7 @@ class TabWidget : public QTabWidget {
int addLinkedBrowser(const QString &initial_url); int addLinkedBrowser(const QString &initial_url);
// General method for adding WebBrowsers. // General method for adding WebBrowsers.
int addBrowser(bool move_after_current, int addBrowser(bool move_after_current, bool make_active, const QUrl &initial_url = QUrl());
bool make_active,
const QUrl &initial_url = QUrl());
private: private:
PlainToolButton *m_btnAddTab; PlainToolButton *m_btnAddTab;

View File

@ -23,6 +23,7 @@
#include "gui/feedmessageviewer.h" #include "gui/feedmessageviewer.h"
#include "gui/messagebox.h" #include "gui/messagebox.h"
#include "gui/formmain.h" #include "gui/formmain.h"
#include "gui/statusbar.h"
#include <QSessionManager> #include <QSessionManager>
#include <QThread> #include <QThread>
@ -59,6 +60,18 @@ IconFactory *Application::icons() {
return m_icons; return m_icons;
} }
DownloadManager *Application::downloadManager() {
if (m_downloadManager == NULL) {
m_downloadManager = new DownloadManager();
connect(m_downloadManager, SIGNAL(downloadFinished()), mainForm()->statusBar(), SLOT(clearProgressDownload()));
connect(m_downloadManager, SIGNAL(downloadProgress(int,QString)),
mainForm()->statusBar(), SLOT(showProgressDownload(int,QString)));
}
return m_downloadManager;
}
bool Application::backupDatabaseSettings(bool backup_database, bool backup_settings, bool Application::backupDatabaseSettings(bool backup_database, bool backup_settings,
const QString &target_path, const QString &backup_name) { const QString &target_path, const QString &backup_name) {
if (!QFileInfo(target_path).isWritable()) { if (!QFileInfo(target_path).isWritable()) {

View File

@ -88,14 +88,7 @@ class Application : public QtSingleApplication {
} }
IconFactory *icons(); IconFactory *icons();
DownloadManager *downloadManager();
inline DownloadManager *downloadManager() {
if (m_downloadManager == NULL) {
m_downloadManager = new DownloadManager();
}
return m_downloadManager;
}
inline Settings *settings() { inline Settings *settings() {
if (m_settings == NULL) { if (m_settings == NULL) {

View File

@ -452,13 +452,15 @@ DownloadManager::~DownloadManager() {
} }
delete m_ui; delete m_ui;
qDebug("Destroying DownloadManager instance.");
} }
int DownloadManager::activeDownloads() const { int DownloadManager::activeDownloads() const {
int count = 0; int count = 0;
for (int i = 0; i < m_downloads.count(); i++) { foreach (DownloadItem *download, m_downloads) {
if (m_downloads.at(i)->m_ui->m_btnStopDownload->isEnabled()) { if (download->downloading()) {
count++; count++;
} }
} }
@ -466,6 +468,25 @@ int DownloadManager::activeDownloads() const {
return count; return count;
} }
int DownloadManager::downloadProgress() const {
qint64 bytes_total = 0;
qint64 bytes_received = 0;
foreach (DownloadItem *download, m_downloads) {
if (download->downloading()) {
bytes_total += download->bytesTotal();
bytes_received += download->bytesReceived();
}
}
if (bytes_total <= 0) {
return -1;
}
else {
return (bytes_received * 100.0) / bytes_total;
}
}
void DownloadManager::download(const QNetworkRequest &request) { void DownloadManager::download(const QNetworkRequest &request) {
if (!request.url().isEmpty()) { if (!request.url().isEmpty()) {
handleUnsupportedContent(m_networkManager->get(request)); handleUnsupportedContent(m_networkManager->get(request));
@ -501,7 +522,8 @@ void DownloadManager::handleUnsupportedContent(QNetworkReply *reply) {
void DownloadManager::addItem(DownloadItem *item) { void DownloadManager::addItem(DownloadItem *item) {
connect(item, SIGNAL(statusChanged()), this, SLOT(updateRow())); connect(item, SIGNAL(statusChanged()), this, SLOT(updateRow()));
connect(item, SIGNAL(downloadFinished()), this, SLOT(finished())); connect(item, SIGNAL(progress(qint64,qint64)), this, SLOT(itemProgress()));
connect(item, SIGNAL(downloadFinished()), this, SLOT(itemFinished()));
int row = m_downloads.count(); int row = m_downloads.count();
m_model->beginInsertRows(QModelIndex(), row, row); m_model->beginInsertRows(QModelIndex(), row, row);
@ -521,8 +543,8 @@ QNetworkAccessManager *DownloadManager::networkManager() const {
return m_networkManager; return m_networkManager;
} }
void DownloadManager::finished() { void DownloadManager::itemFinished() {
// NOTE: Download has finished. emit downloadFinished();
} }
void DownloadManager::updateRow() { void DownloadManager::updateRow() {
@ -531,6 +553,17 @@ void DownloadManager::updateRow() {
} }
} }
void DownloadManager::itemProgress() {
int progress = downloadProgress();
if (progress < 0) {
emit downloadFinished();
}
else {
emit downloadProgress(progress, tr("Downloading %n file(s)...", "", activeDownloads()));
}
}
void DownloadManager::updateRow(DownloadItem *item) { void DownloadManager::updateRow(DownloadItem *item) {
int row = m_downloads.indexOf(item); int row = m_downloads.indexOf(item);

View File

@ -109,16 +109,17 @@ class DownloadManager : public TabContent {
QNetworkAccessManager *networkManager() const; QNetworkAccessManager *networkManager() const;
int activeDownloads() const; int activeDownloads() const;
int downloadProgress() const;
RemovePolicy removePolicy() const; RemovePolicy removePolicy() const;
void setRemovePolicy(RemovePolicy policy); void setRemovePolicy(RemovePolicy policy);
static QString timeString(double time_remaining);
static QString dataString(qint64 size);
void setDownloadDirectory(const QString &directory); void setDownloadDirectory(const QString &directory);
QString downloadDirectory(); QString downloadDirectory();
static QString timeString(double time_remaining);
static QString dataString(qint64 size);
public slots: public slots:
void download(const QNetworkRequest &request); void download(const QNetworkRequest &request);
void download(const QUrl &url); void download(const QUrl &url);
@ -131,7 +132,12 @@ class DownloadManager : public TabContent {
void updateRow(DownloadItem *item); void updateRow(DownloadItem *item);
void updateRow(); void updateRow();
void finished(); void itemProgress();
void itemFinished();
signals:
void downloadProgress(int progress, const QString &description);
void downloadFinished();
private: private:
void addItem(DownloadItem *item); void addItem(DownloadItem *item);