2 Copyright (C) 2015-2024 Ben Kibbey <bjk@luxsci.net>
4 This file is part of qpwmc.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21 #include <QCommonStyle>
22 #include "pwmdPasswordDialog.h"
23 #include "pwmdFileDialog.h"
25 PwmdPasswordDialog::PwmdPasswordDialog (QWidget
*p
) : QDialog (p
)
29 ui
.tb_openKeyFile
->setIcon (QIcon (":icons/rodentia-icons_folder-open-blue.svg"));
30 ui
.tb_saveKeyFile
->setIcon (QIcon (":icons/rodentia-icons_folder-open-blue.svg"));
31 ui
.tb_signKeyFile
->setIcon (QIcon (":icons/rodentia-icons_folder-open-blue.svg"));
36 connect (ui
.tb_openKeyFile
, SIGNAL (clicked()), this, SLOT (slotSelectDecryptKeyFile ()));
37 connect (ui
.tb_saveKeyFile
, SIGNAL (clicked()), this, SLOT (slotSelectEncryptKeyFile ()));
38 connect (ui
.tb_signKeyFile
, SIGNAL (clicked()), this, SLOT (slotSelectSignKeyFile ()));
41 PwmdPasswordDialog::~PwmdPasswordDialog ()
46 PwmdPasswordDialog::setSymmetric (bool b
)
49 ui
.l_saveKeyFile
->setHidden (!b
);
50 ui
.le_saveKeyFile
->setHidden (!b
);
51 ui
.tb_saveKeyFile
->setHidden (!b
);
55 PwmdPasswordDialog::setNewFile (bool b
)
58 ui
.l_openKeyFile
->setHidden (b
);
59 ui
.le_openKeyFile
->setHidden (b
);
60 ui
.tb_openKeyFile
->setHidden (b
);
64 PwmdPasswordDialog::setHasSigners (bool b
)
67 ui
.l_signKeyFile
->setHidden (!b
);
68 ui
.le_signKeyFile
->setHidden (!b
);
69 ui
.tb_signKeyFile
->setHidden (!b
);
73 PwmdPasswordDialog::slotSelectDecryptKeyFile ()
75 PwmdFileDialog
d (this, tr ("Decryption passphrase file"));
77 d
.setFileMode (PwmdFileDialog::ExistingFile
);
78 d
.setOption (PwmdFileDialog::ReadOnly
);
80 d
.setWindowState (Qt::WindowFullScreen
);
83 if (!d
.exec () || !d
.selectedFiles ().count ())
85 ui
.le_openKeyFile
->setText (d
.selectedFiles ().at (0));
89 PwmdPasswordDialog::decryptKeyFile ()
91 return ui
.le_openKeyFile
->text ();
95 PwmdPasswordDialog::setDecryptKeyFile (QString s
)
98 ui
.gr_keyFile
->setChecked (true);
100 ui
.le_openKeyFile
->setText (s
);
104 PwmdPasswordDialog::slotSelectEncryptKeyFile ()
106 PwmdFileDialog
d (this, tr ("Encryption passphrase file"),
110 QDir::home ().path ()
114 d
.setFileMode (PwmdFileDialog::ExistingFile
);
115 d
.setOption (PwmdFileDialog::ReadOnly
);
117 d
.setWindowState (Qt::WindowFullScreen
);
120 if (!d
.exec () || !d
.selectedFiles ().count ())
122 ui
.le_saveKeyFile
->setText (d
.selectedFiles ().at (0));
126 PwmdPasswordDialog::encryptKeyFile ()
128 return ui
.le_saveKeyFile
->text ();
132 PwmdPasswordDialog::setEncryptKeyFile (QString s
)
135 ui
.gr_keyFile
->setChecked (true);
137 ui
.le_saveKeyFile
->setText (s
);
141 PwmdPasswordDialog::slotSelectSignKeyFile ()
143 PwmdFileDialog
d (this, tr ("Signing passphrase file"),
147 QDir::home ().path ()
151 d
.setFileMode (PwmdFileDialog::ExistingFile
);
152 d
.setOption (PwmdFileDialog::ReadOnly
);
154 d
.setWindowState (Qt::WindowFullScreen
);
157 if (!d
.exec () || !d
.selectedFiles ().count ())
159 ui
.le_signKeyFile
->setText (d
.selectedFiles ().at (0));
163 PwmdPasswordDialog::signKeyFile ()
165 return ui
.le_signKeyFile
->text ();
169 PwmdPasswordDialog::setSignKeyFile (QString s
)
172 ui
.gr_keyFile
->setChecked (true);
174 ui
.le_signKeyFile
->setText (s
);
178 PwmdPasswordDialog::useKeyFile ()
180 return ui
.gr_keyFile
->isChecked () &&
181 (!ui
.le_openKeyFile
->text().isEmpty ()
182 || !ui
.le_saveKeyFile
->text().isEmpty ()
183 || !ui
.le_signKeyFile
->text().isEmpty ());