From 5d1154c24e2475ed2b7ac248de27ab7b501a1e5e Mon Sep 17 00:00:00 2001 From: Tannin Date: Sat, 16 Feb 2013 19:09:57 +0100 Subject: - hooks for CreateHardLink - createprocess hook will now reroute the cwd (fixes SUM, may break other tools?) - profile code moved to separate file - executables can now be linked to toolbar - category filters are now represented as a tree - csv export of mod list - ModInfoDialog is now "window modal" instead of "application modal" - nexus dialog now updates the mod-id field while browsing - right-click in nexus browser allows to open in external browser - ini viewer is no longer modal - bugfix: another attempt to fix processing of invalid header lines in fomod xmls (bom now handled) - bugfix: integrated fomod installer will no longer overwrite detected mod name by the one from the xml - bugfix: "hide file" from conflicted files list now updates that list - bugfix: conflicted files list no longer offers to hide files in BSAs - bugfix: pressing delete on the mod list with multiplie files selected offered to delete the wrong files - regression: mod name guessing with the old regular expression was less likely to lead to an empty mod name. Now both are tried --- src/nexusdialog.cpp | 618 ++++++++++++++++++++++++++-------------------------- 1 file changed, 314 insertions(+), 304 deletions(-) (limited to 'src/nexusdialog.cpp') diff --git a/src/nexusdialog.cpp b/src/nexusdialog.cpp index 770b740c..7046cdd7 100644 --- a/src/nexusdialog.cpp +++ b/src/nexusdialog.cpp @@ -17,307 +17,317 @@ You should have received a copy of the GNU General Public License along with Mod Organizer. If not, see . */ -#include "nexusdialog.h" -#include "ui_nexusdialog.h" - -#include "messagedialog.h" -#include "report.h" -#include "json.h" - -#include -#include -#include -#include -#include -#include -#include - - -NexusDialog::NexusDialog(NXMAccessManager *accessManager, QWidget *parent) - : QDialog(parent), ui(new Ui::NexusDialog), - m_AccessManager(accessManager), - m_Tutorial(this, "NexusDialog") -{ - ui->setupUi(this); - - Qt::WindowFlags flags = windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint; - Qt::WindowFlags helpFlag = Qt::WindowContextHelpButtonHint; - flags = flags & (~helpFlag); - setWindowFlags(flags); - - m_Tabs = this->findChild("browserTabWidget"); - - m_View = new NexusView(this); - - initTab(m_View); - - m_LoadProgress = this->findChild("loadProgress"); - - connect(m_Tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(tabCloseRequested(int))); - - m_Tutorial.registerControl(); -} - - -NexusDialog::~NexusDialog() -{ - - delete ui; -} - -void NexusDialog::closeEvent(QCloseEvent *event) -{ -// m_AccessManager->showCookies(); - QDialog::closeEvent(event); -} - -void NexusDialog::initTab(NexusView *newView) -{ - newView->page()->setNetworkAccessManager(m_AccessManager); - newView->page()->setForwardUnsupportedContent(true); - - connect(newView, SIGNAL(loadProgress(int)), this, SLOT(progress(int))); - connect(newView, SIGNAL(titleChanged(QString)), this, SLOT(titleChanged(QString))); - connect(newView, SIGNAL(initTab(NexusView*)), this, SLOT(initTab(NexusView*))); - connect(newView, SIGNAL(startFind()), this, SLOT(startSearch())); - connect(newView, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl))); - connect(newView, SIGNAL(openUrlInNewTab(QUrl)), this, SLOT(openInNewTab(QUrl))); - connect(newView->page(), SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequested(QNetworkRequest))); - - connect(newView->page(), SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(unsupportedContent(QNetworkReply*))); - connect(m_AccessManager, SIGNAL(requestNXMDownload(QString)), this, SLOT(requestNXMDownload(QString))); - - ui->backBtn->setEnabled(false); - ui->fwdBtn->setEnabled(false); - m_Tabs->addTab(newView, tr("new")); - - m_View->settings()->setAttribute(QWebSettings::PluginsEnabled, true); - m_View->settings()->setAttribute(QWebSettings::AutoLoadImages, true); -} - - -void NexusDialog::openInNewTab(const QUrl &url) -{ - NexusView *newView = new NexusView(this); - - initTab(newView); - newView->setUrl(url); -} - - -NexusView *NexusDialog::getCurrentView() -{ - return qobject_cast(m_Tabs->currentWidget()); -} - - -void NexusDialog::urlChanged(const QUrl&) -{ - NexusView *currentView = getCurrentView(); - if (currentView != NULL) { - ui->backBtn->setEnabled(currentView->history()->canGoBack()); - ui->fwdBtn->setEnabled(currentView->history()->canGoForward()); - } -} - - -void NexusDialog::openUrl(const QString &url) -{ - m_Url = url; - if (m_Url.startsWith("www")) { - m_Url.prepend("http://"); - } -} - -void NexusDialog::login(const QString &username, const QString &password) -{ - m_AccessManager->login(username, password); - - connect(m_AccessManager, SIGNAL(loginSuccessful(bool)), this, SLOT(loginFinished(bool))); - connect(m_AccessManager, SIGNAL(loginFailed(QString)), this, SLOT(loginFailed(QString))); -} - - -void NexusDialog::loginFailed(const QString &message) -{ - if (this->isVisible()) { - MessageDialog::showMessage(tr("login failed: %1").arg(message), this); - } -} - - -void NexusDialog::loginFinished(bool necessary) -{ - if (necessary && this->isVisible()) { - MessageDialog::showMessage(tr("login successful"), this); - } - loadNexus(); - emit loginSuccessful(necessary); -} - - -void NexusDialog::loadNexus() -{ - m_View->load(QUrl(m_Url)); -} - - -void NexusDialog::progress(int value) -{ - m_LoadProgress->setValue(value); - m_LoadProgress->setVisible(value != 100); -} - - -void NexusDialog::titleChanged(const QString &title) -{ - NexusView *view = qobject_cast(sender()); - for (int i = 0; i < m_Tabs->count(); ++i) { - if (m_Tabs->widget(i) == view) { - m_Tabs->setTabText(i, title.mid(0, 15)); - m_Tabs->setTabToolTip(i, title); - } - } -} - - -QString NexusDialog::guessFileName(const QString &url) -{ - QRegExp uploadsExp(QString("http://.+/uploads/([^/]+)$")); - if (uploadsExp.indexIn(url) != -1) { - // these seem to be premium downloads - return uploadsExp.cap(1); - } - - QRegExp filesExp(QString("http://.+\\?file=([^&]+)")); - if (filesExp.indexIn(url) != -1) { - // a regular manual download? - return filesExp.cap(1); - } - return "unknown"; -} - -void NexusDialog::unsupportedContent(QNetworkReply *reply) -{ - try { - QWebPage *page = qobject_cast(sender()); - if (page == NULL) { - qCritical("sender not a page"); - return; - } - NexusView *view = qobject_cast(page->view()); - if (view == NULL) { - qCritical("no view?"); - return; - } - - int modID = 0; - QString fileName = guessFileName(reply->url().toString()); - qDebug("unsupported: %s - %s", view->url().toString().toUtf8().constData(), reply->url().toString().toUtf8().constData()); - QRegExp sourceExp(QString("http://[a-zA-Z0-9.]*.nexusmods.com/.*"), Qt::CaseInsensitive); - QRegExp modidExp(QString("http://([a-zA-Z0-9]*).nexusmods.com/downloads/file.php\\?id=(\\d+)"), Qt::CaseInsensitive); - QRegExp modidAltExp(QString("http://([a-zA-Z0-9]*).nexusmods.com/mods/(\\d+)"), Qt::CaseInsensitive); - if (sourceExp.indexIn(reply->url().toString()) != -1) { - if (modidExp.indexIn(view->url().toString()) != -1) { - modID = modidExp.cap(2).toInt(); - } else if (modidAltExp.indexIn(view->url().toString()) != -1) { - modID = modidAltExp.cap(2).toInt(); - } else { - modID = view->getLastSeenModID(); - } - } else { - qDebug("not a nexus download: %s", reply->url().toString().toUtf8().constData()); - return; - } - emit requestDownload(reply, modID, fileName); - } catch (const std::exception &e) { - if (isVisible()) { - MessageDialog::showMessage(tr("failed to start download"), this); - } - qCritical("exception downloading unsupported content: %s", e.what()); - } -} - - -void NexusDialog::downloadRequested(const QNetworkRequest &request) -{ - qCritical("download request %s ignored", request.url().toString().toUtf8().constData()); -} - - -void NexusDialog::requestNXMDownload(const QString&) -{ - if (isVisible()) { - MessageDialog::showMessage(tr("Download started"), this); - } -} - - -void NexusDialog::tabCloseRequested(int index) -{ - if (m_Tabs->count() == 1) { - this->close(); - } else { - m_Tabs->widget(index)->deleteLater(); - m_Tabs->removeTab(index); - } -} - - -void NexusDialog::on_browserTabWidget_customContextMenuRequested(const QPoint&) -{ -} - -void NexusDialog::on_backBtn_clicked() -{ - NexusView *currentView = getCurrentView(); - if (currentView != NULL) { - currentView->back(); - } -} - -void NexusDialog::on_fwdBtn_clicked() -{ - NexusView *currentView = getCurrentView(); - if (currentView != NULL) { - currentView->forward(); - } -} - - -void NexusDialog::startSearch() -{ - ui->searchEdit->setFocus(); -} - - -void NexusDialog::on_modIDEdit_returnPressed() -{ - QString url = ToQString(GameInfo::instance().getNexusPage()).append("/downloads/file.php?id=%1").arg(ui->modIDEdit->text()); - NexusView *currentView = getCurrentView(); - if (currentView != NULL) { - currentView->load(QUrl(url)); - } -} - -void NexusDialog::on_searchEdit_returnPressed() -{ - NexusView *currentView = getCurrentView(); - if (currentView != NULL) { - currentView->findText(ui->searchEdit->text(), QWebPage::FindWrapsAroundDocument); - } -} - -void NexusDialog::on_browserTabWidget_currentChanged(QWidget *current) -{ - NexusView *currentView = qobject_cast(current); - if (currentView != NULL) { - ui->backBtn->setEnabled(currentView->history()->canGoBack()); - ui->fwdBtn->setEnabled(currentView->history()->canGoForward()); - } -} - -void NexusDialog::on_refreshBtn_clicked() -{ - getCurrentView()->reload(); -} +#include "nexusdialog.h" +#include "ui_nexusdialog.h" + +#include "messagedialog.h" +#include "report.h" +#include "json.h" + +#include +#include +#include +#include +#include +#include +#include + + +NexusDialog::NexusDialog(NXMAccessManager *accessManager, QWidget *parent) + : QDialog(parent), ui(new Ui::NexusDialog), + m_ModUrlExp(QString("http://([a-zA-Z0-9]*).nexusmods.com/mods/(\\d+)"), Qt::CaseInsensitive), + m_AccessManager(accessManager), + m_Tutorial(this, "NexusDialog") +{ + ui->setupUi(this); + + Qt::WindowFlags flags = windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint; + Qt::WindowFlags helpFlag = Qt::WindowContextHelpButtonHint; + flags = flags & (~helpFlag); + setWindowFlags(flags); + + m_Tabs = this->findChild("browserTabWidget"); + + m_View = new NexusView(this); + + initTab(m_View); + + m_LoadProgress = this->findChild("loadProgress"); + + connect(m_Tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(tabCloseRequested(int))); + m_Tutorial.registerControl(); +} + + +NexusDialog::~NexusDialog() +{ + + delete ui; +} + +void NexusDialog::closeEvent(QCloseEvent *event) +{ +// m_AccessManager->showCookies(); + QDialog::closeEvent(event); +} + +void NexusDialog::initTab(NexusView *newView) +{ + newView->page()->setNetworkAccessManager(m_AccessManager); + newView->page()->setForwardUnsupportedContent(true); + + connect(newView, SIGNAL(loadProgress(int)), this, SLOT(progress(int))); + connect(newView, SIGNAL(titleChanged(QString)), this, SLOT(titleChanged(QString))); + connect(newView, SIGNAL(initTab(NexusView*)), this, SLOT(initTab(NexusView*))); + connect(newView, SIGNAL(startFind()), this, SLOT(startSearch())); + connect(newView, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl))); + connect(newView, SIGNAL(openUrlInNewTab(QUrl)), this, SLOT(openInNewTab(QUrl))); + connect(newView->page(), SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequested(QNetworkRequest))); + + connect(newView->page(), SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(unsupportedContent(QNetworkReply*))); + connect(m_AccessManager, SIGNAL(requestNXMDownload(QString)), this, SLOT(requestNXMDownload(QString))); + + ui->backBtn->setEnabled(false); + ui->fwdBtn->setEnabled(false); + m_Tabs->addTab(newView, tr("new")); + + m_View->settings()->setAttribute(QWebSettings::PluginsEnabled, true); + m_View->settings()->setAttribute(QWebSettings::AutoLoadImages, true); +} + + +void NexusDialog::openInNewTab(const QUrl &url) +{ + NexusView *newView = new NexusView(this); + + initTab(newView); + newView->setUrl(url); +} + + +NexusView *NexusDialog::getCurrentView() +{ + return qobject_cast(m_Tabs->currentWidget()); +} + + +void NexusDialog::urlChanged(const QUrl &url) +{ + NexusView *sendingView = qobject_cast(sender()); + NexusView *currentView = getCurrentView(); + if ((m_ModUrlExp.indexIn(url.toString()) != -1) && + (sendingView == currentView)) { + ui->modIDEdit->setText(m_ModUrlExp.cap(2)); + } + + if (currentView != NULL) { + ui->backBtn->setEnabled(currentView->history()->canGoBack()); + ui->fwdBtn->setEnabled(currentView->history()->canGoForward()); + } +} + + +void NexusDialog::openUrl(const QString &url) +{ + m_Url = url; + if (m_Url.startsWith("www")) { + m_Url.prepend("http://"); + } +} + +void NexusDialog::login(const QString &username, const QString &password) +{ + m_AccessManager->login(username, password); + + connect(m_AccessManager, SIGNAL(loginSuccessful(bool)), this, SLOT(loginFinished(bool))); + connect(m_AccessManager, SIGNAL(loginFailed(QString)), this, SLOT(loginFailed(QString))); +} + + +void NexusDialog::loginFailed(const QString &message) +{ + if (this->isVisible()) { + MessageDialog::showMessage(tr("login failed: %1").arg(message), this); + } +} + + +void NexusDialog::loginFinished(bool necessary) +{ + if (necessary && this->isVisible()) { + MessageDialog::showMessage(tr("login successful"), this); + } + loadNexus(); + emit loginSuccessful(necessary); +} + + +void NexusDialog::loadNexus() +{ + m_View->load(QUrl(m_Url)); +} + + +void NexusDialog::progress(int value) +{ + m_LoadProgress->setValue(value); + m_LoadProgress->setVisible(value != 100); +} + + +void NexusDialog::titleChanged(const QString &title) +{ + NexusView *view = qobject_cast(sender()); + for (int i = 0; i < m_Tabs->count(); ++i) { + if (m_Tabs->widget(i) == view) { + m_Tabs->setTabText(i, title.mid(0, 15)); + m_Tabs->setTabToolTip(i, title); + } + } +} + + +QString NexusDialog::guessFileName(const QString &url) +{ + QRegExp uploadsExp(QString("http://.+/uploads/([^/]+)$")); + if (uploadsExp.indexIn(url) != -1) { + // these seem to be premium downloads + return uploadsExp.cap(1); + } + + QRegExp filesExp(QString("http://.+\\?file=([^&]+)")); + if (filesExp.indexIn(url) != -1) { + // a regular manual download? + return filesExp.cap(1); + } + return "unknown"; +} + +void NexusDialog::unsupportedContent(QNetworkReply *reply) +{ + try { + QWebPage *page = qobject_cast(sender()); + if (page == NULL) { + qCritical("sender not a page"); + return; + } + NexusView *view = qobject_cast(page->view()); + if (view == NULL) { + qCritical("no view?"); + return; + } + + int modID = 0; + QString fileName = guessFileName(reply->url().toString()); + qDebug("unsupported: %s - %s", view->url().toString().toUtf8().constData(), reply->url().toString().toUtf8().constData()); + QRegExp sourceExp(QString("http://[a-zA-Z0-9.]*.nexusmods.com/.*"), Qt::CaseInsensitive); + QRegExp modidExp(QString("http://([a-zA-Z0-9]*).nexusmods.com/downloads/file.php\\?id=(\\d+)"), Qt::CaseInsensitive); + QRegExp modidAltExp(QString("http://([a-zA-Z0-9]*).nexusmods.com/mods/(\\d+)"), Qt::CaseInsensitive); + if (sourceExp.indexIn(reply->url().toString()) != -1) { + if (modidExp.indexIn(view->url().toString()) != -1) { + modID = modidExp.cap(2).toInt(); + } else if (modidAltExp.indexIn(view->url().toString()) != -1) { + modID = modidAltExp.cap(2).toInt(); + } else { + modID = view->getLastSeenModID(); + } + } else { + qDebug("not a nexus download: %s", reply->url().toString().toUtf8().constData()); + return; + } + emit requestDownload(reply, modID, fileName); + } catch (const std::exception &e) { + if (isVisible()) { + MessageDialog::showMessage(tr("failed to start download"), this); + } + qCritical("exception downloading unsupported content: %s", e.what()); + } +} + + +void NexusDialog::downloadRequested(const QNetworkRequest &request) +{ + qCritical("download request %s ignored", request.url().toString().toUtf8().constData()); +} + + +void NexusDialog::requestNXMDownload(const QString&) +{ + if (isVisible()) { + MessageDialog::showMessage(tr("Download started"), this); + } +} + + +void NexusDialog::tabCloseRequested(int index) +{ + if (m_Tabs->count() == 1) { + this->close(); + } else { + m_Tabs->widget(index)->deleteLater(); + m_Tabs->removeTab(index); + } +} + + +void NexusDialog::on_browserTabWidget_customContextMenuRequested(const QPoint&) +{ +} + +void NexusDialog::on_backBtn_clicked() +{ + NexusView *currentView = getCurrentView(); + if (currentView != NULL) { + currentView->back(); + } +} + +void NexusDialog::on_fwdBtn_clicked() +{ + NexusView *currentView = getCurrentView(); + if (currentView != NULL) { + currentView->forward(); + } +} + + +void NexusDialog::startSearch() +{ + ui->searchEdit->setFocus(); +} + + +void NexusDialog::on_modIDEdit_returnPressed() +{ + QString url = ToQString(GameInfo::instance().getNexusPage()).append("/downloads/file.php?id=%1").arg(ui->modIDEdit->text()); + NexusView *currentView = getCurrentView(); + if (currentView != NULL) { + currentView->load(QUrl(url)); + } +} + +void NexusDialog::on_searchEdit_returnPressed() +{ + NexusView *currentView = getCurrentView(); + if (currentView != NULL) { + currentView->findText(ui->searchEdit->text(), QWebPage::FindWrapsAroundDocument); + } +} + +void NexusDialog::on_browserTabWidget_currentChanged(QWidget *current) +{ + NexusView *currentView = qobject_cast(current); + if (currentView != NULL) { + ui->backBtn->setEnabled(currentView->history()->canGoBack()); + ui->fwdBtn->setEnabled(currentView->history()->canGoForward()); + } + + if (m_ModUrlExp.indexIn(currentView->url().toString()) != -1) { + ui->modIDEdit->setText(m_ModUrlExp.cap(2)); + } +} + +void NexusDialog::on_refreshBtn_clicked() +{ + getCurrentView()->reload(); +} -- cgit v1.3.1