From ee0a8c4887520eb590611016ab73837cb549d5f6 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Thu, 1 Nov 2018 18:47:19 -0400 Subject: [PATCH] add drag'n'drop for extensions --- GUI/extenwindow.cpp | 56 ++++++++++++++++++++++++++++++--------------- GUI/extenwindow.h | 7 +++++- GUI/extenwindow.ui | 3 +++ include/defs.h | 2 +- 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/GUI/extenwindow.cpp b/GUI/extenwindow.cpp index 449ef62..9ab3b1b 100644 --- a/GUI/extenwindow.cpp +++ b/GUI/extenwindow.cpp @@ -1,7 +1,10 @@ #include "extenwindow.h" #include "ui_extenwindow.h" +#include "defs.h" #include "types.h" #include +#include +#include namespace { @@ -19,6 +22,7 @@ namespace void Load(QString extenName) { + if (extenName == ITH_DLL) return; // Extension is dll and exports "OnNewSentence" HMODULE module = GetModuleHandleW(extenName.toStdWString().c_str()); if (!module) module = LoadLibraryW(extenName.toStdWString().c_str()); @@ -91,19 +95,25 @@ ExtenWindow::~ExtenWindow() delete ui; } -void ExtenWindow::on_addButton_clicked() +void ExtenWindow::Sync() { - QString extenFileName = QFileDialog::getOpenFileName(this, "Select Extension", "C:\\", "Extensions (*.dll)"); - if (!extenFileName.size()) return; - QString extenName = extenFileName.mid(extenFileName.lastIndexOf("/") + 1); - QFile::copy(extenFileName, extenName); - Load(extenName.left(extenName.lastIndexOf(".dll"))); - Sync(); + extenList->clear(); + extenSaveFile.open(QIODevice::WriteOnly | QIODevice::Truncate); + std::shared_lock sharedLock(extenMutex); + for (auto extenName : extenNames) + { + extenList->addItem(extenName); + extenSaveFile.write((extenName + ">").toUtf8()); + } + extenSaveFile.close(); } -void ExtenWindow::on_rmvButton_clicked() +void ExtenWindow::Add(QString fileName) { - if (auto extenName = extenList->currentItem()) Unload(extenName->text()); + if (!fileName.endsWith(".dll")) return; + QString extenName = fileName.mid(fileName.lastIndexOf("/") + 1); + QFile::copy(fileName, extenName); + Load(extenName.split(".dll")[0]); Sync(); } @@ -120,15 +130,23 @@ bool ExtenWindow::eventFilter(QObject* target, QEvent* event) return false; } -void ExtenWindow::Sync() +void ExtenWindow::dragEnterEvent(QDragEnterEvent* event) { - extenList->clear(); - extenSaveFile.open(QIODevice::WriteOnly | QIODevice::Truncate); - std::shared_lock sharedLock(extenMutex); - for (auto extenName : extenNames) - { - extenList->addItem(extenName); - extenSaveFile.write((extenName + ">").toUtf8()); - } - extenSaveFile.close(); + event->acceptProposedAction(); +} + +void ExtenWindow::dropEvent(QDropEvent* event) +{ + for (auto file : event->mimeData()->urls()) Add(file.toLocalFile()); +} + +void ExtenWindow::on_addButton_clicked() +{ + Add(QFileDialog::getOpenFileName(this, "Select Extension", "C:\\", "Extensions (*.dll)")); +} + +void ExtenWindow::on_rmvButton_clicked() +{ + if (auto extenName = extenList->currentItem()) Unload(extenName->text()); + Sync(); } diff --git a/GUI/extenwindow.h b/GUI/extenwindow.h index 576de31..9923674 100644 --- a/GUI/extenwindow.h +++ b/GUI/extenwindow.h @@ -4,6 +4,8 @@ #include "qtcommon.h" #include #include +#include +#include namespace Ui { @@ -25,8 +27,11 @@ private slots: void on_rmvButton_clicked(); private: - bool eventFilter(QObject* target, QEvent* event); + void Add(QString fileName); void Sync(); + bool eventFilter(QObject* target, QEvent* event); + void dragEnterEvent(QDragEnterEvent* event); + void dropEvent(QDropEvent* event); Ui::ExtenWindow* ui; QFile extenSaveFile = QFile("Extensions.txt"); diff --git a/GUI/extenwindow.ui b/GUI/extenwindow.ui index 495b38a..d6273c3 100644 --- a/GUI/extenwindow.ui +++ b/GUI/extenwindow.ui @@ -10,6 +10,9 @@ 300 + + true + Extensions diff --git a/include/defs.h b/include/defs.h index da11226..de94067 100644 --- a/include/defs.h +++ b/include/defs.h @@ -3,7 +3,7 @@ // vnrhook/defs.h // 8/23/2013 jichi -#define ITH_DLL L"vnrhook.dll" +#define ITH_DLL L"vnrhook" // Pipes