android: Fix XML form filter.
[qpwmc.git] / pwmdPasswordDialog.cpp
blob66077881e24a0bef69588d14a032d181298ac5ff
1 /*
2 Copyright (C) 2015-2023 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
19 USA
21 #include <QCommonStyle>
22 #include "pwmdPasswordDialog.h"
23 #include "pwmdFileDialog.h"
25 PwmdPasswordDialog::PwmdPasswordDialog (QWidget *p) : QDialog (p)
27 QCommonStyle style;
28 ui.setupUi (this);
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"));
32 _symmetric = false;
33 _newFile = false;
34 _signers = false;
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 ()
45 void
46 PwmdPasswordDialog::setSymmetric (bool b)
48 _symmetric = b;
49 ui.l_saveKeyFile->setHidden (!b);
50 ui.le_saveKeyFile->setHidden (!b);
51 ui.tb_saveKeyFile->setHidden (!b);
54 void
55 PwmdPasswordDialog::setNewFile (bool b)
57 _newFile = b;
58 ui.l_openKeyFile->setHidden (b);
59 ui.le_openKeyFile->setHidden (b);
60 ui.tb_openKeyFile->setHidden (b);
63 void
64 PwmdPasswordDialog::setHasSigners (bool b)
66 _signers = b;
67 ui.l_signKeyFile->setHidden (!b);
68 ui.le_signKeyFile->setHidden (!b);
69 ui.tb_signKeyFile->setHidden (!b);
72 void
73 PwmdPasswordDialog::slotSelectDecryptKeyFile ()
75 PwmdFileDialog d (this, tr ("Decryption passphrase file"));
77 d.setFileMode (PwmdFileDialog::ExistingFile);
78 d.setOption (PwmdFileDialog::ReadOnly);
79 #ifdef Q_OS_ANDROID
80 d.setWindowState (Qt::WindowFullScreen);
81 #endif
83 if (!d.exec () || !d.selectedFiles ().count ())
84 return;
85 ui.le_openKeyFile->setText (d.selectedFiles ().at (0));
88 QString
89 PwmdPasswordDialog::decryptKeyFile ()
91 return ui.le_openKeyFile->text ();
94 void
95 PwmdPasswordDialog::setDecryptKeyFile (QString s)
97 if (!s.isEmpty ())
98 ui.gr_keyFile->setChecked (true);
100 ui.le_openKeyFile->setText (s);
103 void
104 PwmdPasswordDialog::slotSelectEncryptKeyFile ()
106 PwmdFileDialog d (this, tr ("Encryption passphrase file"),
107 #ifdef Q_OS_ANDROID
108 "/sdcard"
109 #else
110 QDir::home ().path ()
111 #endif
114 d.setFileMode (PwmdFileDialog::ExistingFile);
115 d.setOption (PwmdFileDialog::ReadOnly);
116 #ifdef Q_OS_ANDROID
117 d.setWindowState (Qt::WindowFullScreen);
118 #endif
120 if (!d.exec () || !d.selectedFiles ().count ())
121 return;
122 ui.le_saveKeyFile->setText (d.selectedFiles ().at (0));
125 QString
126 PwmdPasswordDialog::encryptKeyFile ()
128 return ui.le_saveKeyFile->text ();
131 void
132 PwmdPasswordDialog::setEncryptKeyFile (QString s)
134 if (!s.isEmpty ())
135 ui.gr_keyFile->setChecked (true);
137 ui.le_saveKeyFile->setText (s);
140 void
141 PwmdPasswordDialog::slotSelectSignKeyFile ()
143 PwmdFileDialog d (this, tr ("Signing passphrase file"),
144 #ifdef Q_OS_ANDROID
145 "/sdcard"
146 #else
147 QDir::home ().path ()
148 #endif
151 d.setFileMode (PwmdFileDialog::ExistingFile);
152 d.setOption (PwmdFileDialog::ReadOnly);
153 #ifdef Q_OS_ANDROID
154 d.setWindowState (Qt::WindowFullScreen);
155 #endif
157 if (!d.exec () || !d.selectedFiles ().count ())
158 return;
159 ui.le_signKeyFile->setText (d.selectedFiles ().at (0));
162 QString
163 PwmdPasswordDialog::signKeyFile ()
165 return ui.le_signKeyFile->text ();
168 void
169 PwmdPasswordDialog::setSignKeyFile (QString s)
171 if (!s.isEmpty ())
172 ui.gr_keyFile->setChecked (true);
174 ui.le_signKeyFile->setText (s);
177 bool
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 ());