forked from USBGuard/usbguard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.h
124 lines (101 loc) · 4.92 KB
/
MainWindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// Copyright (C) 2015 Red Hat, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Authors: Daniel Kopecek <dkopecek@redhat.com>
//
#pragma once
#include "DeviceModel.h"
#include "TargetDelegate.h"
#include <QSystemTrayIcon>
#include <QMainWindow>
#include <QTimer>
#include <QSettings>
#include <IPCClient.hpp>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow, public usbguard::IPCClient
{
using IPCClient::allowDevice;
using IPCClient::blockDevice;
using IPCClient::rejectDevice;
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
signals:
void uiDeviceInserted(quint32 id, const std::map<std::string, std::string>& attributes, const std::vector<usbguard::USBInterfaceType>& interfaces, bool rule_match);
void uiDevicePresent(quint32 id, const std::map<std::string, std::string>& attributes, const std::vector<usbguard::USBInterfaceType>& interfaces, usbguard::Rule::Target target);
void uiDeviceRemoved(quint32 id, const std::map<std::string, std::string>& attributes);
void uiDeviceAllowed(quint32 id, const std::map<std::string, std::string>& attributes);
void uiDeviceBlocked(quint32 id, const std::map<std::string, std::string>& attributes);
void uiDeviceRejected(quint32 id, const std::map<std::string, std::string>& attributes);
void uiConnected();
void uiDisconnected();
protected slots:
void switchVisibilityState(QSystemTrayIcon::ActivationReason reason);
void flashStep();
void ipcTryConnect();
void showDeviceDialog(quint32 id, const std::map<std::string, std::string>& attributes, const std::vector<usbguard::USBInterfaceType>& interfaces, bool rule_match);
void showMessage(const QString &message, bool alert = false);
void notifyInserted(quint32 id, const std::map<std::string, std::string>& attributes, const std::vector<usbguard::USBInterfaceType>& interfaces, bool rule_matched);
void notifyPresent(quint32 id, const std::map<std::string, std::string>& attributes, const std::vector<usbguard::USBInterfaceType>& interfaces, usbguard::Rule::Target target);
void notifyRemoved(quint32 id, const std::map<std::string, std::string>& attributes);
void notifyAllowed(quint32 id, const std::map<std::string, std::string>& attributes);
void notifyBlocked(quint32 id, const std::map<std::string, std::string>& attributes);
void notifyRejected(quint32 id, const std::map<std::string, std::string>& attributes);
void notifyIPCConnected();
void notifyIPCDisconnected();
void allowDevice(quint32 id, bool append);
void blockDevice(quint32 id, bool append);
void rejectDevice(quint32 id, bool append);
void handleIPCConnect();
void handleIPCDisconnect();
void handleDeviceInsert(quint32 id);
void handleDeviceAllow(quint32 id);
void handleDeviceBlock(quint32 id);
void handleDeviceRemove(quint32 id);
void loadSettings();
void saveSettings();
void loadDeviceList();
void editDeviceListRow(const QModelIndex &index);
void commitDeviceListChanges();
void clearDeviceList();
void resetDeviceList();
protected:
void changeEvent(QEvent *e) override;
void setupSystemTray();
void setupSettingsWatcher();
void startFlashing();
void stopFlashing();
void DeviceInserted(quint32 id, const std::map<std::string, std::string>& attributes, const std::vector<usbguard::USBInterfaceType>& interfaces, bool rule_match, quint32 rule_id) override;
void DevicePresent(quint32 id, const std::map<std::string, std::string>& attributes, const std::vector<usbguard::USBInterfaceType>& interfaces, usbguard::Rule::Target target) override;
void DeviceRemoved(quint32 id, const std::map<std::string, std::string>& attributes) override;
void DeviceAllowed(quint32 id, const std::map<std::string, std::string>& attributes, bool rule_match, quint32 rule_id) override;
void DeviceBlocked(quint32 id, const std::map<std::string, std::string>& attributes, bool rule_match, quint32 rule_id) override;
void DeviceRejected(quint32 id, const std::map<std::string ,std::string>& attributes, bool rule_match, quint32 rule_id) override;
void IPCConnected() override;
void IPCDisconnected(bool exception_initiated, const usbguard::IPCException& exception) override;
private:
Ui::MainWindow *ui;
QSystemTrayIcon *systray;
QTimer _flash_timer;
bool _flash_state;
QTimer _ipc_timer;
QSettings _settings;
DeviceModel _device_model;
TargetDelegate _target_delegate;
};