summaryrefslogtreecommitdiff
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp151
1 files changed, 87 insertions, 64 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 7dba6c72..44ccc642 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -891,13 +891,15 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event)
void MainWindow::toolPluginInvoke()
{
QAction *triggeredAction = qobject_cast<QAction*>(sender());
- IPluginTool *plugin = (IPluginTool*)triggeredAction->data().value<void*>();
- try {
- plugin->display();
- } catch (const std::exception &e) {
- reportError(tr("Plugin \"%1\" failed: %2").arg(plugin->name()).arg(e.what()));
- } catch (...) {
- reportError(tr("Plugin \"%1\" failed").arg(plugin->name()));
+ IPluginTool *plugin = qobject_cast<IPluginTool*>(triggeredAction->data().value<QObject*>());
+ if (plugin != nullptr) {
+ try {
+ plugin->display();
+ } catch (const std::exception &e) {
+ reportError(tr("Plugin \"%1\" failed: %2").arg(plugin->name()).arg(e.what()));
+ } catch (...) {
+ reportError(tr("Plugin \"%1\" failed").arg(plugin->name()));
+ }
}
}
@@ -905,11 +907,13 @@ void MainWindow::modPagePluginInvoke()
{
QAction *triggeredAction = qobject_cast<QAction*>(sender());
IPluginModPage *plugin = qobject_cast<IPluginModPage*>(triggeredAction->data().value<QObject*>());
- if (plugin->useIntegratedBrowser()) {
- m_IntegratedBrowser.setWindowTitle(plugin->displayName());
- m_IntegratedBrowser.openUrl(plugin->pageURL());
- } else {
- ::ShellExecuteW(nullptr, L"open", ToWString(plugin->pageURL().toString()).c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ if (plugin != nullptr) {
+ if (plugin->useIntegratedBrowser()) {
+ m_IntegratedBrowser.setWindowTitle(plugin->displayName());
+ m_IntegratedBrowser.openUrl(plugin->pageURL());
+ } else {
+ ::ShellExecuteW(nullptr, L"open", ToWString(plugin->pageURL().toString()).c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ }
}
}
@@ -918,7 +922,7 @@ void MainWindow::registerPluginTool(IPluginTool *tool)
QAction *action = new QAction(tool->icon(), tool->displayName(), ui->toolBar);
action->setToolTip(tool->tooltip());
tool->setParentWidget(this);
- action->setData(qVariantFromValue((void*)tool));
+ action->setData(qVariantFromValue((QObject*)tool));
connect(action, SIGNAL(triggered()), this, SLOT(toolPluginInvoke()), Qt::QueuedConnection);
QToolButton *toolBtn = qobject_cast<QToolButton*>(ui->toolBar->widgetForAction(ui->actionTool));
toolBtn->menu()->addAction(action);
@@ -1007,11 +1011,11 @@ void MainWindow::on_profileBox_currentIndexChanged(int index)
}
if (ui->profileBox->currentIndex() == 0) {
- ProfilesDialog(m_GamePath, this).exec();
+ ui->profileBox->setCurrentIndex(previousIndex);
+ ProfilesDialog(ui->profileBox->currentText(), this).exec();
while (!refreshProfiles()) {
- ProfilesDialog(m_GamePath, this).exec();
+ ProfilesDialog(ui->profileBox->currentText(), this).exec();
}
- ui->profileBox->setCurrentIndex(previousIndex);
} else {
activateSelectedProfile();
}
@@ -1677,8 +1681,11 @@ static HRESULT CreateShortcut(LPCWSTR targetFileName, LPCWSTR arguments,
result = shellLink->QueryInterface(IID_IPersistFile, (LPVOID*)&persistFile);
if (SUCCEEDED(result)) {
wchar_t linkFileNameW[MAX_PATH];
- MultiByteToWideChar(CP_ACP, 0, linkFileName, -1, linkFileNameW, MAX_PATH);
- result = persistFile->Save(linkFileNameW, TRUE);
+ if (MultiByteToWideChar(CP_ACP, 0, linkFileName, -1, linkFileNameW, MAX_PATH) > 0) {
+ result = persistFile->Save(linkFileNameW, TRUE);
+ } else {
+ qCritical("failed to create link: %s", linkFileName);
+ }
persistFile->Release();
} else {
qCritical("failed to create IPersistFile instance");
@@ -1850,6 +1857,14 @@ void MainWindow::modorder_changed()
QModelIndex current = ui->modList->currentIndex();
if (current.isValid()) {
ModInfo::Ptr modInfo = ModInfo::getByIndex(current.data(Qt::UserRole + 1).toInt());
+ // clear caches on all mods conflicting with the moved mod
+ for (int i : modInfo->getModOverwrite()) {
+ ModInfo::getByIndex(i)->clearCaches();
+ }
+ for (int i : modInfo->getModOverwritten()) {
+ ModInfo::getByIndex(i)->clearCaches();
+ }
+ // update conflict check on the moved mod
modInfo->doConflictCheck();
m_OrganizerCore.modList()->setOverwriteMarkers(modInfo->getModOverwrite(), modInfo->getModOverwritten());
if (m_ModListSortProxy != nullptr) {
@@ -2523,6 +2538,12 @@ void MainWindow::on_modList_doubleClicked(const QModelIndex &index)
if (!index.isValid()) {
return;
}
+
+ if (m_OrganizerCore.modList()->timeElapsedSinceLastChecked() <= QApplication::doubleClickInterval()) {
+ // don't interpret double click if we only just checked a mod
+ return;
+ }
+
QModelIndex sourceIdx = mapToModel(m_OrganizerCore.modList(), index);
if (!sourceIdx.isValid()) {
return;
@@ -2530,7 +2551,6 @@ void MainWindow::on_modList_doubleClicked(const QModelIndex &index)
try {
m_ContextRow = m_ModListSortProxy->mapToSource(index).row();
-// displayModInformation(m_ModListSortProxy->mapToSource(index).row());
displayModInformation(sourceIdx.row());
// workaround to cancel the editor that might have opened because of
// selection-click
@@ -4602,7 +4622,7 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event)
//types
QList<QUrl> urls = data->urls();
bool ok = true;
- for (auto url : urls) {
+ for (const QUrl &url : urls) {
if (url.isLocalFile()) {
QString local = url.toLocalFile();
bool fok = false;
@@ -4617,8 +4637,6 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event)
break;
}
}
- //We should probably allow the user to drop urls here and remember the
- //url for installing later.
}
if (ok) {
event->accept();
@@ -4627,56 +4645,61 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event)
}
}
+void MainWindow::dropLocalFile(const QUrl &url, const QString &outputDir, bool move)
+{
+ QFileInfo file(url.toLocalFile());
+ if (!file.exists()) {
+ qWarning("invalid source file %s", qPrintable(file.absoluteFilePath()));
+ return;
+ }
+ QString target = outputDir + "/" + file.fileName();
+ if (QFile::exists(target)) {
+ QMessageBox box(QMessageBox::Question,
+ file.fileName(),
+ tr("A file with the same name has already been downloaded. "
+ "What would you like to do?"));
+ box.addButton(tr("Overwrite"), QMessageBox::ActionRole);
+ box.addButton(tr("Rename new file"), QMessageBox::YesRole);
+ box.addButton(tr("Ignore file"), QMessageBox::RejectRole);
+
+ box.exec();
+ switch (box.buttonRole(box.clickedButton())) {
+ case QMessageBox::RejectRole:
+ return;
+ case QMessageBox::ActionRole:
+ break;
+ default:
+ case QMessageBox::YesRole:
+ target = m_OrganizerCore.downloadManager()->getDownloadFileName(file.fileName());
+ break;
+ }
+ }
+
+ bool success = false;
+ if (move) {
+ success = shellMove(file.absoluteFilePath(), target, true, this);
+ } else {
+ success = shellCopy(file.absoluteFilePath(), target, true, this);
+ }
+ if (!success) {
+ qCritical("file operation failed: %s", qPrintable(windowsErrorString(::GetLastError())));
+ }
+}
+
void MainWindow::dropEvent(QDropEvent *event)
{
Qt::DropAction action = event->proposedAction();
- QString output_dir = m_OrganizerCore.downloadManager()->getOutputDirectory();
+ QString outputDir = m_OrganizerCore.downloadManager()->getOutputDirectory();
if (action == Qt::MoveAction) {
//Tell windows I'm taking control and will delete the source of a move.
event->setDropAction(Qt::TargetMoveAction);
}
- for (auto url : event->mimeData()->urls()) {
- QFileInfo file(url.toLocalFile());
- QString target = output_dir + "/" + file.fileName();
- if (QFile::exists(target)) {
- QMessageBox box(QMessageBox::Question,
- file.fileName(),
- tr("A file with the same name has already been downloaded. "
- "What would you like to do?"));
- box.addButton(tr("Overwrite"), QMessageBox::ActionRole);
- box.addButton(tr("Rename new file"), QMessageBox::YesRole);
- box.addButton(tr("Ignore file"), QMessageBox::RejectRole);
-
- box.exec();
- QMessageBox::ButtonRole role = box.buttonRole(box.clickedButton());
- switch (role)
- {
- case QMessageBox::RejectRole:
- continue;
-
- case QMessageBox::ActionRole:
- break;
-
- default:
- case QMessageBox::YesRole:
- target = m_OrganizerCore.downloadManager()->getDownloadFileName(file.fileName());
- break;
-
- }
- }
-
- if (action == Qt::MoveAction) {
- if (shellMove(file.absoluteFilePath(), target, true, this)) {
- continue;
- }
- }
- else {
- if (shellCopy(file.absoluteFilePath(), target, true, this)) {
- continue;
- }
+ for (const QUrl &url : event->mimeData()->urls()) {
+ if (url.isLocalFile()) {
+ dropLocalFile(url, outputDir, action == Qt::MoveAction);
+ } else {
+ m_OrganizerCore.downloadManager()->startDownloadURLs(QStringList() << url.url());
}
- //Something has gone horribly wrong here
- qDebug("error %d", GetLastError());
}
event->accept();
}