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/nexusview.cpp | 167 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 99 insertions(+), 68 deletions(-) (limited to 'src/nexusview.cpp') diff --git a/src/nexusview.cpp b/src/nexusview.cpp index 1099fff2..c8c7f09d 100644 --- a/src/nexusview.cpp +++ b/src/nexusview.cpp @@ -17,71 +17,102 @@ You should have received a copy of the GNU General Public License along with Mod Organizer. If not, see . */ -#include "nexusview.h" - -#include -#include -#include -#include -#include -#include -#include -#include "utility.h" - -NexusView::NexusView(QWidget *parent) - : QWebView(parent), m_LastSeenModID(0) -{ - installEventFilter(this); -// this->pageAction(QWebPage::OpenLinkInNewWindow) - connect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl))); - - page()->settings()->setMaximumPagesInCache(10); -} - - -void NexusView::urlChanged(const QUrl &url) -{ - QRegExp modidExp(QString("http://([a-zA-Z0-9]*).nexusmods.com/downloads/file.php\\?id=(\\d+)"), Qt::CaseInsensitive); - if (modidExp.indexIn(url.toString()) != -1) { - m_LastSeenModID = modidExp.cap(2).toInt(); - } -} - - -QWebView *NexusView::createWindow(QWebPage::WebWindowType) -{ - NexusView *newView = new NexusView(parentWidget()); - emit initTab(newView); - return newView; -} - - -bool NexusView::eventFilter(QObject *obj, QEvent *event) -{ - if (event->type() == QEvent::ShortcutOverride) { - QKeyEvent *keyEvent = static_cast(event); - if (keyEvent->matches(QKeySequence::Find)) { - emit startFind(); - } else if (keyEvent->matches(QKeySequence::FindNext)) { - emit findAgain(); - } - } else if (event->type() == QEvent::MouseButtonPress) { - QMouseEvent *mouseEvent = static_cast(event); - if (mouseEvent->button() == Qt::MidButton) { - mouseEvent->ignore(); - return true; - } - } else if (event->type() == QEvent::MouseButtonRelease) { - QMouseEvent *mouseEvent = static_cast(event); - if (mouseEvent->button() == Qt::MidButton) { - QWebHitTestResult hitTest = page()->frameAt(mouseEvent->pos())->hitTestContent(mouseEvent->pos()); - if (hitTest.linkUrl().isValid()) { - emit openUrlInNewTab(hitTest.linkUrl()); - } - mouseEvent->ignore(); - - return true; - } - } - return QWebView::eventFilter(obj, event); -} +#include "nexusview.h" + +#include +#include +#include +#include +#include +#include +#include +#include "utility.h" + +NexusView::NexusView(QWidget *parent) + : QWebView(parent), m_LastSeenModID(0) +{ + installEventFilter(this); +// this->pageAction(QWebPage::OpenLinkInNewWindow) + connect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl))); + + page()->settings()->setMaximumPagesInCache(10); +} + + +void NexusView::urlChanged(const QUrl &url) +{ + QRegExp modidExp(QString("http://([a-zA-Z0-9]*).nexusmods.com/downloads/file.php\\?id=(\\d+)"), Qt::CaseInsensitive); + if (modidExp.indexIn(url.toString()) != -1) { + m_LastSeenModID = modidExp.cap(2).toInt(); + } +} + +void NexusView::openPageExternal() +{ + ::ShellExecuteW(NULL, L"open", ToWString(url().toString()).c_str(), NULL, NULL, SW_SHOWNORMAL); +} + +void NexusView::openLinkExternal() +{ + ::ShellExecuteW(NULL, L"open", ToWString(m_ContextURL.toString()).c_str(), NULL, NULL, SW_SHOWNORMAL); +} + + +QWebView *NexusView::createWindow(QWebPage::WebWindowType) +{ + NexusView *newView = new NexusView(parentWidget()); + emit initTab(newView); + return newView; +} + + +bool NexusView::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::ShortcutOverride) { + QKeyEvent *keyEvent = static_cast(event); + if (keyEvent->matches(QKeySequence::Find)) { + emit startFind(); + } else if (keyEvent->matches(QKeySequence::FindNext)) { + emit findAgain(); + } + } else if (event->type() == QEvent::MouseButtonPress) { + QMouseEvent *mouseEvent = static_cast(event); + if (mouseEvent->button() == Qt::MidButton) { + mouseEvent->ignore(); + return true; + } + } else if (event->type() == QEvent::MouseButtonRelease) { + QMouseEvent *mouseEvent = static_cast(event); + if (mouseEvent->button() == Qt::MidButton) { + QWebHitTestResult hitTest = page()->frameAt(mouseEvent->pos())->hitTestContent(mouseEvent->pos()); + if (hitTest.linkUrl().isValid()) { + emit openUrlInNewTab(hitTest.linkUrl()); + } + mouseEvent->ignore(); + + return true; + } + } + return QWebView::eventFilter(obj, event); +} + + +void NexusView::contextMenuEvent(QContextMenuEvent *event) +{ + if (!page()->swallowContextMenuEvent(event)) { + QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos()); + + QMenu *menu = page()->createStandardContextMenu(); + QAction *openExternalAction = new QAction("Open in external browser", menu); + if (r.linkUrl().isEmpty()) { + connect(openExternalAction, SIGNAL(triggered()), this, SLOT(openPageExternal())); + } else { + m_ContextURL = r.linkUrl(); + connect(openExternalAction, SIGNAL(triggered()), this, SLOT(openLinkExternal())); + } + + menu->addSeparator(); + menu->addAction(openExternalAction); + menu->exec(mapToGlobal(event->pos())); + } +} -- cgit v1.3.1