summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2013-02-19 21:33:58 +0100
committerTannin <devnull@localhost>2013-02-19 21:33:58 +0100
commitcb297d20b616e49803470396c21dd5747370cfaf (patch)
tree19d2fe4119f65d23ba7e833a98bebd5cf854fe4d /src
parentefe42430777fe187c042d30e3496448fd12c9a82 (diff)
- proper detection of user-preferred language
- resume and removal of failed download fixed
Diffstat (limited to 'src')
-rw-r--r--src/downloadlistwidgetcompact.cpp443
-rw-r--r--src/downloadmanager.cpp4
-rw-r--r--src/mainwindow.cpp4
-rw-r--r--src/settings.cpp25
-rw-r--r--src/settings.h5
5 files changed, 257 insertions, 224 deletions
diff --git a/src/downloadlistwidgetcompact.cpp b/src/downloadlistwidgetcompact.cpp
index c2ff8a08..6e56d8c6 100644
--- a/src/downloadlistwidgetcompact.cpp
+++ b/src/downloadlistwidgetcompact.cpp
@@ -17,221 +17,228 @@ You should have received a copy of the GNU General Public License
along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "downloadlistwidgetcompact.h"
-#include "ui_downloadlistwidgetcompact.h"
-#include <QPainter>
-#include <QMouseEvent>
-#include <QMenu>
-#include <QMessageBox>
-#include <QSortFilterProxyModel>
-#include "downloadmanager.h"
-
-
-DownloadListWidgetCompact::DownloadListWidgetCompact(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::DownloadListWidgetCompact)
-{
- ui->setupUi(this);
-}
-
-DownloadListWidgetCompact::~DownloadListWidgetCompact()
-{
- delete ui;
-}
-
-
-DownloadListWidgetCompactDelegate::DownloadListWidgetCompactDelegate(DownloadManager *manager, QTreeView *view, QObject *parent)
- : QItemDelegate(parent), m_Manager(manager), m_ItemWidget(new DownloadListWidgetCompact), m_View(view)
-{
- m_NameLabel = m_ItemWidget->findChild<QLabel*>("nameLabel");
- m_Progress = m_ItemWidget->findChild<QProgressBar*>("downloadProgress");
- m_DoneLabel = m_ItemWidget->findChild<QLabel*>("doneLabel");
-
- m_DoneLabel->setVisible(false);
-}
-
-
-DownloadListWidgetCompactDelegate::~DownloadListWidgetCompactDelegate()
-{
- delete m_ItemWidget;
-}
-
-
-void DownloadListWidgetCompactDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
-{
- try {
-// m_ItemWidget->resize(option.rect.size());
- m_ItemWidget->resize(QSize(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2), option.rect.height()));
- if (index.row() % 2 == 1) {
- m_ItemWidget->setBackgroundRole(QPalette::AlternateBase);
- } else {
- m_ItemWidget->setBackgroundRole(QPalette::Base);
- }
-
- int downloadIndex = index.data().toInt();
-
- QString name = m_Manager->getFileName(downloadIndex);
- if (name.length() > 53) {
- name.truncate(50);
- name.append("...");
- }
- m_NameLabel->setText(name);
- DownloadManager::DownloadState state = m_Manager->getState(downloadIndex);
- if (state >= DownloadManager::STATE_READY) {
- m_DoneLabel->setVisible(true);
- m_Progress->setVisible(false);
- if (state == DownloadManager::STATE_INSTALLED) {
- m_DoneLabel->setText(tr("Installed"));
- m_DoneLabel->setForegroundRole(QPalette::Mid);
- } else {
- m_DoneLabel->setText(tr("Done"));
- m_DoneLabel->setForegroundRole(QPalette::WindowText);
- }
- if (m_Manager->isInfoIncomplete(downloadIndex)) {
- m_NameLabel->setText("<img src=\":/MO/gui/resources/dialog-warning_16.png\"/> " + m_NameLabel->text());
- }
- } else {
- m_DoneLabel->setVisible(false);
- m_Progress->setVisible(true);
- m_Progress->setValue(m_Manager->getProgress(downloadIndex));
- }
-
- painter->save();
- painter->translate(QPoint(0, option.rect.topLeft().y()));
- m_ItemWidget->render(painter);
- painter->restore();
- } catch (const std::exception &e) {
- qCritical("failed to paint download list item %d: %s", index.row(), e.what());
- }
-}
-
-QSize DownloadListWidgetCompactDelegate::sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const
-{
- const int width = m_ItemWidget->minimumWidth();
- const int height = m_ItemWidget->height();
- return QSize(width, height);
-}
-
-
-void DownloadListWidgetCompactDelegate::issueInstall()
-{
- emit installDownload(m_ContextIndex.row());
-}
-
-void DownloadListWidgetCompactDelegate::issueQueryInfo()
-{
- emit queryInfo(m_ContextIndex.row());
-}
-
-void DownloadListWidgetCompactDelegate::issueDelete()
-{
- emit removeDownload(m_ContextIndex.row(), true);
-}
-
-void DownloadListWidgetCompactDelegate::issueRemoveFromView()
-{
- emit removeDownload(m_ContextIndex.row(), false);
-}
-
-void DownloadListWidgetCompactDelegate::issueCancel()
-{
- emit cancelDownload(m_ContextIndex.row());
-}
-
-void DownloadListWidgetCompactDelegate::issuePause()
-{
- emit pauseDownload(m_ContextIndex.row());
-}
-
-void DownloadListWidgetCompactDelegate::issueResume()
-{
- emit resumeDownload(m_ContextIndex.row());
-}
-
-void DownloadListWidgetCompactDelegate::issueDeleteAll()
-{
- if (QMessageBox::question(NULL, tr("Are you sure?"),
- tr("This will remove all finished downloads from this list and from disk."),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
- emit removeDownload(-1, true);
- }
-}
-
-void DownloadListWidgetCompactDelegate::issueDeleteCompleted()
-{
- if (QMessageBox::question(NULL, tr("Are you sure?"),
- tr("This will remove all installed downloads from this list and from disk."),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
- emit removeDownload(-2, true);
- }
-}
-
-void DownloadListWidgetCompactDelegate::issueRemoveFromViewAll()
-{
- if (QMessageBox::question(NULL, tr("Are you sure?"),
- tr("This will permanently remove all finished downloads from this list (but NOT from disk)."),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
- emit removeDownload(-1, false);
- }
-}
-
-void DownloadListWidgetCompactDelegate::issueRemoveFromViewCompleted()
-{
- if (QMessageBox::question(NULL, tr("Are you sure?"),
- tr("This will permanently remove all installed downloads from this list (but NOT from disk)."),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
- emit removeDownload(-2, false);
- }
-}
-
-
-bool DownloadListWidgetCompactDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
- const QStyleOptionViewItem &option, const QModelIndex &index)
-{
- try {
- if (event->type() == QEvent::MouseButtonDblClick) {
- QModelIndex sourceIndex = qobject_cast<QSortFilterProxyModel*>(model)->mapToSource(index);
- if (m_Manager->getState(sourceIndex.row()) >= DownloadManager::STATE_READY) {
- emit installDownload(sourceIndex.row());
- }
- return true;
- } else if (event->type() == QEvent::MouseButtonRelease) {
- QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
- if (mouseEvent->button() == Qt::RightButton) {
- QMenu menu;
- m_ContextIndex = qobject_cast<QSortFilterProxyModel*>(model)->mapToSource(index);
- DownloadManager::DownloadState state = m_Manager->getState(m_ContextIndex.row());
- if (state >= DownloadManager::STATE_READY) {
- menu.addAction(tr("Install"), this, SLOT(issueInstall()));
- if (m_Manager->isInfoIncomplete(m_ContextIndex.row())) {
- menu.addAction(tr("Query Info"), this, SLOT(issueQueryInfo()));
- }
- menu.addAction(tr("Delete"), this, SLOT(issueDelete()));
- menu.addAction(tr("Remove from View"), this, SLOT(issueRemoveFromView()));
- } else if (state == DownloadManager::STATE_DOWNLOADING){
- menu.addAction(tr("Cancel"), this, SLOT(issueCancel()));
- menu.addAction(tr("Pause"), this, SLOT(issuePause()));
- } else if (state == DownloadManager::STATE_PAUSED) {
- menu.addAction(tr("Remove"), this, SLOT(issueDelete()));
- menu.addAction(tr("Resume"), this, SLOT(issueResume()));
- }
-
- menu.addSeparator();
- menu.addAction(tr("Delete Installed..."), this, SLOT(issueDeleteCompleted()));
- menu.addAction(tr("Delete All..."), this, SLOT(issueDeleteAll()));
- menu.addSeparator();
- menu.addAction(tr("Remove Installed..."), this, SLOT(issueRemoveFromViewCompleted()));
- menu.addAction(tr("Remove All..."), this, SLOT(issueRemoveFromViewAll()));
- menu.exec(mouseEvent->globalPos());
-
- event->accept();
- return false;
- }
- }
- } catch (const std::exception &e) {
- qCritical("failed to handle editor event: %s", e.what());
- }
-
- return QItemDelegate::editorEvent(event, model, option, index);
-}
-
+#include "downloadlistwidgetcompact.h"
+#include "ui_downloadlistwidgetcompact.h"
+#include <QPainter>
+#include <QMouseEvent>
+#include <QMenu>
+#include <QMessageBox>
+#include <QSortFilterProxyModel>
+#include "downloadmanager.h"
+
+
+DownloadListWidgetCompact::DownloadListWidgetCompact(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::DownloadListWidgetCompact)
+{
+ ui->setupUi(this);
+}
+
+DownloadListWidgetCompact::~DownloadListWidgetCompact()
+{
+ delete ui;
+}
+
+
+DownloadListWidgetCompactDelegate::DownloadListWidgetCompactDelegate(DownloadManager *manager, QTreeView *view, QObject *parent)
+ : QItemDelegate(parent), m_Manager(manager), m_ItemWidget(new DownloadListWidgetCompact), m_View(view)
+{
+ m_NameLabel = m_ItemWidget->findChild<QLabel*>("nameLabel");
+ m_Progress = m_ItemWidget->findChild<QProgressBar*>("downloadProgress");
+ m_DoneLabel = m_ItemWidget->findChild<QLabel*>("doneLabel");
+
+ m_DoneLabel->setVisible(false);
+}
+
+
+DownloadListWidgetCompactDelegate::~DownloadListWidgetCompactDelegate()
+{
+ delete m_ItemWidget;
+}
+
+
+void DownloadListWidgetCompactDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ try {
+// m_ItemWidget->resize(option.rect.size());
+ m_ItemWidget->resize(QSize(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2), option.rect.height()));
+ if (index.row() % 2 == 1) {
+ m_ItemWidget->setBackgroundRole(QPalette::AlternateBase);
+ } else {
+ m_ItemWidget->setBackgroundRole(QPalette::Base);
+ }
+
+ int downloadIndex = index.data().toInt();
+
+ QString name = m_Manager->getFileName(downloadIndex);
+ if (name.length() > 53) {
+ name.truncate(50);
+ name.append("...");
+ }
+ m_NameLabel->setText(name);
+ DownloadManager::DownloadState state = m_Manager->getState(downloadIndex);
+ if (state == DownloadManager::STATE_PAUSED) {
+ m_DoneLabel->setVisible(true);
+ m_Progress->setVisible(false);
+ m_DoneLabel->setText(tr("Paused"));
+ m_DoneLabel->setForegroundRole(QPalette::Link);
+ } else if (state >= DownloadManager::STATE_READY) {
+ m_DoneLabel->setVisible(true);
+ m_Progress->setVisible(false);
+ if (state == DownloadManager::STATE_INSTALLED) {
+ m_DoneLabel->setText(tr("Installed"));
+ m_DoneLabel->setForegroundRole(QPalette::Mid);
+ } else {
+ m_DoneLabel->setText(tr("Done"));
+ m_DoneLabel->setForegroundRole(QPalette::WindowText);
+ }
+ if (m_Manager->isInfoIncomplete(downloadIndex)) {
+ m_NameLabel->setText("<img src=\":/MO/gui/resources/dialog-warning_16.png\"/> " + m_NameLabel->text());
+ }
+ } else {
+ m_DoneLabel->setVisible(false);
+ m_Progress->setVisible(true);
+ m_Progress->setValue(m_Manager->getProgress(downloadIndex));
+ }
+
+ painter->save();
+ painter->translate(QPoint(0, option.rect.topLeft().y()));
+ m_ItemWidget->render(painter);
+ painter->restore();
+ } catch (const std::exception &e) {
+ qCritical("failed to paint download list item %d: %s", index.row(), e.what());
+ }
+}
+
+QSize DownloadListWidgetCompactDelegate::sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const
+{
+ const int width = m_ItemWidget->minimumWidth();
+ const int height = m_ItemWidget->height();
+ return QSize(width, height);
+}
+
+
+void DownloadListWidgetCompactDelegate::issueInstall()
+{
+ emit installDownload(m_ContextIndex.row());
+}
+
+void DownloadListWidgetCompactDelegate::issueQueryInfo()
+{
+ emit queryInfo(m_ContextIndex.row());
+}
+
+void DownloadListWidgetCompactDelegate::issueDelete()
+{
+ emit removeDownload(m_ContextIndex.row(), true);
+}
+
+void DownloadListWidgetCompactDelegate::issueRemoveFromView()
+{
+ emit removeDownload(m_ContextIndex.row(), false);
+}
+
+void DownloadListWidgetCompactDelegate::issueCancel()
+{
+ emit cancelDownload(m_ContextIndex.row());
+}
+
+void DownloadListWidgetCompactDelegate::issuePause()
+{
+ emit pauseDownload(m_ContextIndex.row());
+}
+
+void DownloadListWidgetCompactDelegate::issueResume()
+{
+ emit resumeDownload(m_ContextIndex.row());
+}
+
+void DownloadListWidgetCompactDelegate::issueDeleteAll()
+{
+ if (QMessageBox::question(NULL, tr("Are you sure?"),
+ tr("This will remove all finished downloads from this list and from disk."),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
+ emit removeDownload(-1, true);
+ }
+}
+
+void DownloadListWidgetCompactDelegate::issueDeleteCompleted()
+{
+ if (QMessageBox::question(NULL, tr("Are you sure?"),
+ tr("This will remove all installed downloads from this list and from disk."),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
+ emit removeDownload(-2, true);
+ }
+}
+
+void DownloadListWidgetCompactDelegate::issueRemoveFromViewAll()
+{
+ if (QMessageBox::question(NULL, tr("Are you sure?"),
+ tr("This will permanently remove all finished downloads from this list (but NOT from disk)."),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
+ emit removeDownload(-1, false);
+ }
+}
+
+void DownloadListWidgetCompactDelegate::issueRemoveFromViewCompleted()
+{
+ if (QMessageBox::question(NULL, tr("Are you sure?"),
+ tr("This will permanently remove all installed downloads from this list (but NOT from disk)."),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
+ emit removeDownload(-2, false);
+ }
+}
+
+
+bool DownloadListWidgetCompactDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
+ const QStyleOptionViewItem &option, const QModelIndex &index)
+{
+ try {
+ if (event->type() == QEvent::MouseButtonDblClick) {
+ QModelIndex sourceIndex = qobject_cast<QSortFilterProxyModel*>(model)->mapToSource(index);
+ if (m_Manager->getState(sourceIndex.row()) >= DownloadManager::STATE_READY) {
+ emit installDownload(sourceIndex.row());
+ } else if (m_Manager->getState(sourceIndex.row()) >= DownloadManager::STATE_PAUSED) {
+ emit resumeDownload(sourceIndex.row());
+ }
+ return true;
+ } else if (event->type() == QEvent::MouseButtonRelease) {
+ QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
+ if (mouseEvent->button() == Qt::RightButton) {
+ QMenu menu;
+ m_ContextIndex = qobject_cast<QSortFilterProxyModel*>(model)->mapToSource(index);
+ DownloadManager::DownloadState state = m_Manager->getState(m_ContextIndex.row());
+ if (state >= DownloadManager::STATE_READY) {
+ menu.addAction(tr("Install"), this, SLOT(issueInstall()));
+ if (m_Manager->isInfoIncomplete(m_ContextIndex.row())) {
+ menu.addAction(tr("Query Info"), this, SLOT(issueQueryInfo()));
+ }
+ menu.addAction(tr("Delete"), this, SLOT(issueDelete()));
+ menu.addAction(tr("Remove from View"), this, SLOT(issueRemoveFromView()));
+ } else if (state == DownloadManager::STATE_DOWNLOADING){
+ menu.addAction(tr("Cancel"), this, SLOT(issueCancel()));
+ menu.addAction(tr("Pause"), this, SLOT(issuePause()));
+ } else if (state == DownloadManager::STATE_PAUSED) {
+ menu.addAction(tr("Remove"), this, SLOT(issueDelete()));
+ menu.addAction(tr("Resume"), this, SLOT(issueResume()));
+ }
+
+ menu.addSeparator();
+ menu.addAction(tr("Delete Installed..."), this, SLOT(issueDeleteCompleted()));
+ menu.addAction(tr("Delete All..."), this, SLOT(issueDeleteAll()));
+ menu.addSeparator();
+ menu.addAction(tr("Remove Installed..."), this, SLOT(issueRemoveFromViewCompleted()));
+ menu.addAction(tr("Remove All..."), this, SLOT(issueRemoveFromViewAll()));
+ menu.exec(mouseEvent->globalPos());
+
+ event->accept();
+ return false;
+ }
+ }
+ } catch (const std::exception &e) {
+ qCritical("failed to handle editor event: %s", e.what());
+ }
+
+ return QItemDelegate::editorEvent(event, model, option, index);
+}
+
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index ab1f2613..2700e598 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -200,6 +200,7 @@ bool DownloadManager::addDownload(QNetworkReply *reply, const QString &fileName,
newDownload->m_ModID = modID;
newDownload->m_FileID = fileID;
newDownload->m_NexusInfo = nexusInfo;
+ newDownload->m_State = STATE_STARTED;
QString baseName = fileName;
@@ -286,7 +287,7 @@ void DownloadManager::removeFile(int index, bool deleteFile)
}
if (download->m_State == STATE_PAUSED) {
- filePath.append(UNFINISHED);
+ filePath = download->m_Output.fileName();
}
if (deleteFile) {
@@ -318,6 +319,7 @@ private:
DownloadManager *m_Manager;
};
+
bool DownloadManager::ByName(int LHS, int RHS)
{
return m_ActiveDownloads[LHS]->m_FileName < m_ActiveDownloads[RHS]->m_FileName;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 27ed5147..71cb1c9d 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1560,9 +1560,7 @@ void MainWindow::readSettings()
setCategoryListVisible(filtersVisible);
ui->displayCategoriesBtn->setChecked(filtersVisible);
-
- QString language = settings.value("Settings/language", QLocale::system().name()).toString();
- languageChange(language);
+ languageChange(m_Settings.language());
int selectedExecutable = settings.value("selected_executable").toInt();
setExecutableIndex(selectedExecutable);
}
diff --git a/src/settings.cpp b/src/settings.cpp
index e7553676..3ee916c0 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -238,6 +238,22 @@ QVariant Settings::pluginSetting(const QString &pluginName, const QString &key)
return *iterSetting;
}
+QString Settings::language()
+{
+ QString result = m_Settings.value("Settings/language", "").toString();
+ if (result.isEmpty()) {
+ QStringList languagePreferences = QLocale::system().uiLanguages();
+ if (languagePreferences.length() > 0) {
+ // the users most favoritest language
+ result = languagePreferences.at(0);
+ } else {
+ // fallback system locale
+ result = QLocale::system().name();
+ }
+ }
+ return result;
+}
+
void Settings::addLanguages(QComboBox *languageBox)
{
@@ -260,7 +276,6 @@ void Settings::addLanguages(QComboBox *languageBox)
languageString = "Chinese (simplified)";
}
}
-
languageBox->addItem(QString("%1").arg(languageString), exp.cap(1));
}
}
@@ -387,7 +402,13 @@ void Settings::query(QWidget *parent)
{
addLanguages(languageBox);
- int currentID = languageBox->findData(m_Settings.value("Settings/language", QLocale::system().name()).toString());
+ QString languageCode = language();
+ int currentID = languageBox->findData(languageCode);
+ // I made a mess. :( Most languages are stored with only the iso country code (2 characters like "de") but chinese
+ // with the exact language variant (zh_TW) so I have to search for both variants
+ if (currentID == -1) {
+ currentID = languageBox->findData(languageCode.mid(0, 2));
+ }
if (currentID != -1) {
languageBox->setCurrentIndex(currentID);
}
diff --git a/src/settings.h b/src/settings.h
index 04781611..34d61a24 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -187,6 +187,11 @@ public:
*/
QVariant pluginSetting(const QString &pluginName, const QString &key) const;
+ /**
+ * @return short code of the configured language (corresponding to the translation files)
+ */
+ QString language();
+
private:
QString obfuscate(const QString &password) const;