1 // copyright (c) 2019-2021 hors<horsicq@gmail.com>
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 
10 // The above copyright notice and this permission notice shall be included in all
11 // copies or substantial portions of the Software.
12 
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 //
21 #ifndef SEARCHSIGNATURESWIDGET_H
22 #define SEARCHSIGNATURESWIDGET_H
23 
24 #include "xshortcutswidget.h"
25 #include <QFile>
26 #include <QStandardItemModel>
27 #include <QSortFilterProxyModel>
28 #include <QFileDialog>
29 #include <QMenu>
30 #include <QApplication>
31 #include <QClipboard>
32 #include <QFutureWatcher>
33 #include <QtConcurrent>
34 #include "dialogmultisearchprocess.h"
35 #include "xformats.h"
36 
37 namespace Ui
38 {
39 class SearchSignaturesWidget;
40 }
41 
42 class SearchSignaturesWidget : public XShortcutsWidget
43 {
44     Q_OBJECT
45 
46 public:
47     struct OPTIONS
48     {
49         QString sSignaturesPath;
50         bool bMenu_Hex;
51         QString sUserSignature;
52     };
53 
54     explicit SearchSignaturesWidget(QWidget *pParent=nullptr);
55     ~SearchSignaturesWidget();
56     void setData(QIODevice *pDevice,XBinary::FT fileType,OPTIONS options,bool bAuto=false);
57     void setOptions(OPTIONS options);
58     OPTIONS getOptions();
59     void setSignaturesPath(QString sPath);
60 
61     void reload();
62     bool getInitStatus();
63 
64 private slots:
65     void on_pushButtonSave_clicked();
66     void on_pushButtonSearch_clicked();
67     void on_tableViewResult_customContextMenuRequested(const QPoint &pos);
68     void _copyAddress();
69     void _copyOffset();
70     void _copyName();
71     void _copySignature();
72     void _hex();
73     void search();
74     void deleteOldModel();
75     void loadSignatures(QString sFileName);
76     void on_comboBoxFile_currentIndexChanged(int index);
77 
78 protected:
79     virtual void registerShortcuts(bool bState);
80 
81 signals:
82     void showHex(qint64 nOffset,qint64 nSize);
83 
84 private:
85     Ui::SearchSignaturesWidget *ui;
86     QIODevice *g_pDevice;
87     QSortFilterProxyModel *g_pFilter;
88     XBinary::FT g_fileType;
89     QStandardItemModel *g_pModel;
90     bool g_bInit;
91     QStandardItemModel *g_pOldModel;
92     QFutureWatcher<void> g_watcher;
93     QList<MultiSearch::SIGNATURE_RECORD> g_listSignatureRecords;
94     OPTIONS g_options;
95 
96     QShortcut *g_scCopyName;
97     QShortcut *g_scCopySignature;
98     QShortcut *g_scCopyAddress;
99     QShortcut *g_scCopyOffset;
100     QShortcut *g_scHex;
101 };
102 
103 #endif // SEARCHSIGNATURESWIDGET_H
104