Skip to content

Commit

Permalink
Merge pull request dolphin-emu#8176 from VinDuv/handle-open-files
Browse files Browse the repository at this point in the history
QtGui: Handle file open events
  • Loading branch information
stenzek authored Jun 29, 2019
2 parents 8a122de + 2f63b71 commit 341ce45
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Source/Core/DolphinQt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/DolphinQt/DolphinQt.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -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" />
Expand Down Expand Up @@ -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" />
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/DolphinQt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions Source/Core/DolphinQt/QtUtils/FileOpenEventFilter.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
20 changes: 20 additions & 0 deletions Source/Core/DolphinQt/QtUtils/FileOpenEventFilter.h
Original file line number Diff line number Diff line change
@@ -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.