blob: 646f853018ead745fd0166178846bfcff9926dd6 (
plain)
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
|
/*
* Copyright (C) 2018 Aetf <aetf@unlimitedcodeworks.xyz>
*
* 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 or (at your option)
* version 3 of the License.
*
* 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/>.
*/
#include "FdoSecretsPlugin.h"
#include "fdosecrets/FdoSecretsSettings.h"
#include "fdosecrets/objects/DBusTypes.h"
#include "fdosecrets/objects/Service.h"
#include "fdosecrets/widgets/SettingsWidgetFdoSecrets.h"
#include "gui/DatabaseTabWidget.h"
#include <utility>
using FdoSecrets::Service;
FdoSecretsPlugin::FdoSecretsPlugin(DatabaseTabWidget* tabWidget)
: m_dbTabs(tabWidget)
{
FdoSecrets::registerDBusTypes();
}
QWidget* FdoSecretsPlugin::createWidget()
{
return new SettingsWidgetFdoSecrets(this);
}
void FdoSecretsPlugin::loadSettings(QWidget* widget)
{
qobject_cast<SettingsWidgetFdoSecrets*>(widget)->loadSettings();
}
void FdoSecretsPlugin::saveSettings(QWidget* widget)
{
qobject_cast<SettingsWidgetFdoSecrets*>(widget)->saveSettings();
updateServiceState();
}
void FdoSecretsPlugin::updateServiceState()
{
if (FdoSecrets::settings()->isEnabled()) {
if (!m_secretService && m_dbTabs) {
m_secretService.reset(new Service(this, m_dbTabs));
connect(m_secretService.data(), &Service::error, this, [this](const QString& msg) {
emit error(tr("Fdo Secret Service: %1").arg(msg));
});
if (!m_secretService->initialize()) {
m_secretService.reset();
FdoSecrets::settings()->setEnabled(false);
return;
}
emit secretServiceStarted();
}
} else {
if (m_secretService) {
m_secretService.reset();
emit secretServiceStopped();
}
}
}
Service* FdoSecretsPlugin::serviceInstance() const
{
return m_secretService.data();
}
DatabaseTabWidget* FdoSecretsPlugin::dbTabs() const
{
return m_dbTabs;
}
void FdoSecretsPlugin::emitRequestSwitchToDatabases()
{
emit requestSwitchToDatabases();
}
void FdoSecretsPlugin::emitRequestShowNotification(const QString& msg, const QString& title)
{
if (!FdoSecrets::settings()->showNotification()) {
return;
}
emit requestShowNotification(msg, title, 10000);
}
|