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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
/**
* Copyright (C) 2021-2024 Saturneric <[email protected]>
*
* This file is part of GpgFrontend.
*
* GpgFrontend 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 3 of the License, or
* (at your option) any later version.
*
* GpgFrontend 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 GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
*
* The initial version of the source code is inherited from
* the gpg4usb project, which is under GPL-3.0-or-later.
*
* All the source code of GpgFrontend was modified and released by
* Saturneric <[email protected]> starting on May 12, 2021.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include "ui/widgets/FilePage.h"
#include "core/function/GlobalSettingStation.h"
#include "ui/UISignalStation.h"
#include "ui/main_window/MainWindow.h"
#include "ui_FilePage.h"
namespace GpgFrontend::UI {
FilePage::FilePage(QWidget* parent, const QString& target_path)
: QWidget(parent),
ui_(GpgFrontend::SecureCreateSharedObject<Ui_FilePage>()),
file_tree_view_(new FileTreeView(this, target_path)) {
ui_->setupUi(this);
ui_->trewViewLayout->addWidget(file_tree_view_);
ui_->batchModeButton->setToolTip(tr("Switch Batch Mode"));
connect(ui_->upPathButton, &QPushButton::clicked, file_tree_view_,
&FileTreeView::SlotUpLevel);
connect(ui_->refreshButton, &QPushButton::clicked, this,
&FilePage::SlotGoPath);
connect(this->ui_->newDirButton, &QPushButton::clicked, file_tree_view_,
&FileTreeView::SlotMkdir);
ui_->pathEdit->setText(file_tree_view_->GetCurrentPath());
path_edit_completer_ = new QCompleter(this);
path_complete_model_ = new QStringListModel();
path_edit_completer_->setModel(path_complete_model_);
path_edit_completer_->setCaseSensitivity(Qt::CaseInsensitive);
path_edit_completer_->setCompletionMode(
QCompleter::UnfilteredPopupCompletion);
ui_->pathEdit->setCompleter(path_edit_completer_);
option_popup_menu_ = new QMenu(this);
auto* show_hidden_act = new QAction(tr("Show Hidden File"), this);
show_hidden_act->setCheckable(true);
connect(show_hidden_act, &QAction::triggered, file_tree_view_,
&FileTreeView::SlotShowHiddenFile);
option_popup_menu_->addAction(show_hidden_act);
auto* show_system_act = new QAction(tr("Show System File"), this);
show_system_act->setCheckable(true);
connect(show_system_act, &QAction::triggered, file_tree_view_,
&FileTreeView::SlotShowSystemFile);
option_popup_menu_->addAction(show_system_act);
auto* switch_asc_mode_act = new QAction(tr("ASCII Mode"), this);
switch_asc_mode_act->setCheckable(true);
connect(switch_asc_mode_act, &QAction::triggered, this,
[=](bool on) { ascii_mode_ = on; });
option_popup_menu_->addAction(switch_asc_mode_act);
ui_->optionsButton->setMenu(option_popup_menu_);
ascii_mode_ = !(
GetSettings().value("gnupg/non_ascii_at_file_operation", true).toBool());
switch_asc_mode_act->setChecked(ascii_mode_);
connect(ui_->pathEdit, &QLineEdit::textChanged, [=]() {
auto path = ui_->pathEdit->text();
auto dir = QDir(path);
if (path.endsWith("/") && dir.isReadable()) {
auto dir_list = dir.entryInfoList(QDir::AllEntries);
QStringList paths;
for (int i = 1; i < dir_list.size(); i++) {
const auto file_path = dir_list.at(i).filePath();
const auto file_name = dir_list.at(i).fileName();
if (file_name == "." || file_name == "..") continue;
paths.append(file_path);
}
path_complete_model_->setStringList(paths);
}
});
connect(this, &FilePage::SignalRefreshInfoBoard,
UISignalStation::GetInstance(),
&UISignalStation::SignalRefreshInfoBoard);
connect(file_tree_view_, &FileTreeView::SignalPathChanged, this,
[this](const QString& path) { this->ui_->pathEdit->setText(path); });
connect(file_tree_view_, &FileTreeView::SignalPathChanged, this,
&FilePage::SignalPathChanged);
connect(file_tree_view_, &FileTreeView::SignalOpenFile,
UISignalStation::GetInstance(),
&UISignalStation::SignalMainWindowOpenFile);
connect(file_tree_view_, &FileTreeView::SignalSelectedChanged, this,
&FilePage::update_main_basic_opera_menu);
connect(this, &FilePage::SignalCurrentTabChanged, this,
[this]() { update_main_basic_opera_menu(GetSelected()); });
connect(this, &FilePage::SignalMainWindowUpdateBasicOperaMenu,
UISignalStation::GetInstance(),
&UISignalStation::SignalMainWindowUpdateBasicOperaMenu);
connect(ui_->batchModeButton, &QToolButton::toggled, file_tree_view_,
&FileTreeView::SlotSwitchBatchMode);
}
auto FilePage::GetSelected() const -> QStringList {
return file_tree_view_->GetSelectedPaths();
}
void FilePage::SlotGoPath() {
file_tree_view_->SlotGoPath(ui_->pathEdit->text());
}
void FilePage::keyPressEvent(QKeyEvent* event) {
if (ui_->pathEdit->hasFocus() &&
(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)) {
SlotGoPath();
}
}
void FilePage::update_main_basic_opera_menu(const QStringList& selected_paths) {
if (selected_paths.isEmpty()) {
emit SignalMainWindowUpdateBasicOperaMenu(MainWindow::OperationMenu::kNone);
return;
}
MainWindow::OperationMenu::OperationType operation_type =
MainWindow::OperationMenu::kNone;
LOG_D() << "selected path size: " << selected_paths.size();
LOG_D() << "selected paths: " << selected_paths;
QContainer<QFileInfo> infos;
for (const auto& path : selected_paths) {
infos.append(QFileInfo(path));
}
bool c_encr =
std::all_of(infos.cbegin(), infos.cend(), [](const QFileInfo& info) {
return (info.isDir() || info.isFile()) &&
(info.suffix() != "gpg" && info.suffix() != "pgp" &&
info.suffix() != "sig" && info.suffix() != "asc");
});
if (c_encr) {
operation_type |= MainWindow::OperationMenu::kEncrypt |
MainWindow::OperationMenu::kEncryptAndSign;
}
bool c_decr =
std::all_of(infos.cbegin(), infos.cend(), [](const QFileInfo& info) {
return info.isFile() &&
(info.suffix() == "gpg" || info.suffix() == "pgp" ||
info.suffix() == "asc");
});
if (c_decr) {
operation_type |= MainWindow::OperationMenu::kDecrypt |
MainWindow::OperationMenu::kDecryptAndVerify;
}
bool c_sign =
std::all_of(infos.cbegin(), infos.cend(), [](const QFileInfo& info) {
return info.isFile() &&
(info.suffix() != "gpg" && info.suffix() != "pgp" &&
info.suffix() != "sig" && info.suffix() != "asc");
});
if (c_sign) operation_type |= MainWindow::OperationMenu::kSign;
bool c_verify =
std::all_of(infos.cbegin(), infos.cend(), [](const QFileInfo& info) {
return info.isFile() &&
(info.suffix() == "sig" || info.suffix() == "gpg" ||
info.suffix() == "pgp" || info.suffix() == "asc");
});
if (c_verify) operation_type |= MainWindow::OperationMenu::kVerify;
emit SignalMainWindowUpdateBasicOperaMenu(operation_type);
}
auto FilePage::IsBatchMode() const -> bool {
return ui_->batchModeButton->isChecked();
}
auto FilePage::IsASCIIMode() const -> bool { return ascii_mode_; }
} // namespace GpgFrontend::UI
|