Skip to content
Permalink
Browse files

Merge pull request #8176 from VinDuv/handle-open-files

QtGui: Handle file open events
  • Loading branch information...
stenzek committed Jun 29, 2019
2 parents 8a122de + 2f63b71 commit 341ce45ed6586953238035f44e69b075920b1062
@@ -202,6 +202,8 @@ add_executable(dolphin-emu
QtUtils/DoubleClickEventFilter.h
QtUtils/ElidedButton.cpp
QtUtils/ElidedButton.h
QtUtils/FileOpenEventFilter.cpp
QtUtils/FileOpenEventFilter.h
QtUtils/FlowLayout.cpp
QtUtils/FlowLayout.h
QtUtils/ModalMessageBox.cpp
@@ -156,6 +156,7 @@
<QtMoc Include="QtUtils\BlockUserInputFilter.h" />
<QtMoc Include="QtUtils\DoubleClickEventFilter.h" />
<QtMoc Include="QtUtils\ElidedButton.h" />
<QtMoc Include="QtUtils\FileOpenEventFilter.h" />
<QtMoc Include="QtUtils\FlowLayout.h" />
<QtMoc Include="QtUtils\ModalMessageBox.h" />
<QtMoc Include="QtUtils\WindowActivationEventFilter.h" />
@@ -193,6 +194,7 @@
<ClCompile Include="$(QtMocOutPrefix)EnhancementsWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)FIFOAnalyzer.cpp" />
<ClCompile Include="$(QtMocOutPrefix)FIFOPlayerWindow.cpp" />
<ClCompile Include="$(QtMocOutPrefix)FileOpenEventFilter.cpp" />
<ClCompile Include="$(QtMocOutPrefix)FilesystemWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)GCKeyboardEmu.cpp" />
<ClCompile Include="$(QtMocOutPrefix)GCMemcardManager.cpp" />
@@ -379,6 +381,7 @@
<ClCompile Include="QtUtils\BlockUserInputFilter.cpp" />
<ClCompile Include="QtUtils\DoubleClickEventFilter.cpp" />
<ClCompile Include="QtUtils\ElidedButton.cpp" />
<ClCompile Include="QtUtils\FileOpenEventFilter.cpp" />
<ClCompile Include="QtUtils\FlowLayout.cpp" />
<ClCompile Include="QtUtils\ImageConverter.cpp" />
<ClCompile Include="QtUtils\ModalMessageBox.cpp" />
@@ -84,6 +84,7 @@
#include "DolphinQt/NetPlay/NetPlayBrowser.h"
#include "DolphinQt/NetPlay/NetPlayDialog.h"
#include "DolphinQt/NetPlay/NetPlaySetupDialog.h"
#include "DolphinQt/QtUtils/FileOpenEventFilter.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/QtUtils/QueueOnObject.h"
#include "DolphinQt/QtUtils/RunOnObject.h"
@@ -336,6 +337,12 @@ void MainWindow::InitCoreCallbacks()
});
installEventFilter(this);
m_render_widget->installEventFilter(this);

// Handle file open events
auto* filter = new FileOpenEventFilter(QGuiApplication::instance());
connect(filter, &FileOpenEventFilter::fileOpened, this, [=](const QString& file_name) {
StartGame(BootParameters::GenerateFromFile(file_name.toStdString()));
});
}

static void InstallHotkeyFilter(QWidget* dialog)
@@ -0,0 +1,24 @@
// Copyright 2019 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <QFileOpenEvent>

#include "DolphinQt/QtUtils/FileOpenEventFilter.h"

FileOpenEventFilter::FileOpenEventFilter(QObject* event_source) : QObject(event_source)
{
event_source->installEventFilter(this);
}

bool FileOpenEventFilter::eventFilter(QObject* object, QEvent* event)
{
if (event->type() == QEvent::FileOpen)
{
auto* openEvent = static_cast<QFileOpenEvent*>(event);
emit fileOpened(openEvent->file());
return true;
}

return false;
}
@@ -0,0 +1,20 @@
// Copyright 2019 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <QObject>

class FileOpenEventFilter : public QObject
{
Q_OBJECT
public:
explicit FileOpenEventFilter(QObject* event_source);

signals:
void fileOpened(const QString& file_name);

private:
bool eventFilter(QObject* object, QEvent* event) override;
};

0 comments on commit 341ce45

Please sign in to comment.
You can’t perform that action at this time.