aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-01-24 06:32:56 +0000
committersaturneric <[email protected]>2024-01-24 06:32:56 +0000
commit38c9d2ce81b2c4d33caa120d07fe9605525722bf (patch)
treeb8624478413ea55341bc58612b7300a83d7fdc62
parentfix: decrypt tar.gpg but output path is incorrect (diff)
downloadGpgFrontend-38c9d2ce81b2c4d33caa120d07fe9605525722bf.tar.gz
GpgFrontend-38c9d2ce81b2c4d33caa120d07fe9605525722bf.zip
fix: improve file page
-rw-r--r--src/core/utils/GpgUtils.cpp21
-rw-r--r--src/ui/main_window/MainWindowFileSlotFunction.cpp2
-rw-r--r--src/ui/widgets/FileTreeView.cpp53
-rw-r--r--src/ui/widgets/FileTreeView.h1
-rw-r--r--src/ui/widgets/PlainTextEditorPage.cpp39
-rw-r--r--src/ui/widgets/TextEdit.cpp5
6 files changed, 75 insertions, 46 deletions
diff --git a/src/core/utils/GpgUtils.cpp b/src/core/utils/GpgUtils.cpp
index cbe71a99..75041eca 100644
--- a/src/core/utils/GpgUtils.cpp
+++ b/src/core/utils/GpgUtils.cpp
@@ -99,8 +99,9 @@ auto TextIsSigned(QString text) -> int {
auto SetExtensionOfOutputFile(const QString& path, GpgOperation opera,
bool ascii) -> QString {
+ auto file_info = QFileInfo(path);
QString new_extension;
- QString current_extension = QFileInfo(path).suffix();
+ QString current_extension = file_info.suffix();
if (ascii) {
switch (opera) {
@@ -127,22 +128,24 @@ auto SetExtensionOfOutputFile(const QString& path, GpgOperation opera,
}
if (!new_extension.isEmpty()) {
- return QFileInfo(path).path() + "/" + QFileInfo(path).completeBaseName() +
- "." + new_extension;
+ return file_info.absolutePath() + "/" + file_info.completeBaseName() + "." +
+ new_extension;
}
- return QFileInfo(path).path() + "/" + QFileInfo(path).completeBaseName();
+ return file_info.absolutePath() + "/" + file_info.baseName();
}
auto SetExtensionOfOutputFileForArchive(const QString& path, GpgOperation opera,
bool ascii) -> QString {
QString extension;
+ auto file_info = QFileInfo(path);
if (ascii) {
switch (opera) {
case kENCRYPT:
case kENCRYPT_SIGN:
- extension = ".tar.asc";
- return path + extension;
+ if (file_info.completeSuffix() != "tar") extension += ".tar";
+ extension += ".asc";
+ return QFileInfo(path).absoluteFilePath() + extension;
break;
default:
break;
@@ -151,15 +154,15 @@ auto SetExtensionOfOutputFileForArchive(const QString& path, GpgOperation opera,
switch (opera) {
case kENCRYPT:
case kENCRYPT_SIGN:
- extension = ".tar.gpg";
- return path + extension;
+ if (file_info.completeSuffix() != "tar") extension += ".tar";
+ extension += ".gpg";
+ return QFileInfo(path).absoluteFilePath() + extension;
break;
default:
break;
}
}
- auto file_info = QFileInfo(path);
return file_info.absolutePath() + "/" + file_info.baseName();
}
diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp
index c2465d86..c1b1bba1 100644
--- a/src/ui/main_window/MainWindowFileSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp
@@ -280,6 +280,7 @@ void MainWindow::SlotFileDecrypt(const QString& path) {
}
auto out_path = SetExtensionOfOutputFile(path, kDECRYPT, true);
+ GF_UI_LOG_DEBUG("file decrypt target output path: {}", out_path);
if (QFileInfo(out_path).exists()) {
auto ret = QMessageBox::warning(
this, tr("Warning"),
@@ -329,6 +330,7 @@ void MainWindow::SlotArchiveDecrypt(const QString& path) {
}
auto out_path = SetExtensionOfOutputFileForArchive(path, kDECRYPT, true);
+ GF_UI_LOG_DEBUG("archive decrypt target output path: {}", out_path);
if (QFileInfo(out_path).exists()) {
auto ret = QMessageBox::warning(
this, tr("Warning"),
diff --git a/src/ui/widgets/FileTreeView.cpp b/src/ui/widgets/FileTreeView.cpp
index 0350bb09..91536cdf 100644
--- a/src/ui/widgets/FileTreeView.cpp
+++ b/src/ui/widgets/FileTreeView.cpp
@@ -49,6 +49,7 @@ FileTreeView::FileTreeView(QWidget* parent, const QString& target_path)
slot_create_popup_menu();
this->setContextMenuPolicy(Qt::CustomContextMenu);
+
connect(this, &QWidget::customContextMenuRequested, this,
&FileTreeView::slot_show_custom_context_menu);
connect(this, &QTreeView::doubleClicked, this,
@@ -204,6 +205,8 @@ void FileTreeView::SlotTouch() {
QLineEdit::Normal, new_file_name, &ok);
if (ok && !new_file_name.isEmpty()) {
auto file_path = root_path + "/" + new_file_name;
+ GF_UI_LOG_DEBUG("new file path: {}", file_path);
+
QFile new_file(file_path);
if (!new_file.open(QIODevice::WriteOnly | QIODevice::NewOnly)) {
QMessageBox::critical(this, tr("Error"),
@@ -215,6 +218,7 @@ void FileTreeView::SlotTouch() {
void FileTreeView::SlotTouchBelowAtSelectedItem() {
auto root_path(selected_path_);
+ if (root_path.isEmpty()) root_path = dir_model_->rootPath();
QString new_file_name;
bool ok;
@@ -223,6 +227,7 @@ void FileTreeView::SlotTouchBelowAtSelectedItem() {
QLineEdit::Normal, new_file_name, &ok);
if (ok && !new_file_name.isEmpty()) {
auto file_path = root_path + "/" + new_file_name;
+ GF_UI_LOG_DEBUG("new file path: {}", file_path);
QFile new_file(file_path);
if (!new_file.open(QIODevice::WriteOnly | QIODevice::NewOnly)) {
@@ -326,16 +331,16 @@ void FileTreeView::slot_create_popup_menu() {
connect(action_open_with_system_default_application, &QAction::triggered,
this, &FileTreeView::SlotOpenSelectedItemBySystemApplication);
- auto* new_item_action_menu = new QMenu(this);
- new_item_action_menu->setTitle(tr("New"));
- new_item_action_menu->addAction(action_create_empty_file_);
- new_item_action_menu->addAction(action_make_directory_);
+ new_item_action_menu_ = new QMenu(this);
+ new_item_action_menu_->setTitle(tr("New"));
+ new_item_action_menu_->addAction(action_create_empty_file_);
+ new_item_action_menu_->addAction(action_make_directory_);
popup_menu_->addAction(action_open_file_);
popup_menu_->addAction(action_open_with_system_default_application);
popup_menu_->addSeparator();
- popup_menu_->addMenu(new_item_action_menu);
+ popup_menu_->addMenu(new_item_action_menu_);
popup_menu_->addSeparator();
popup_menu_->addAction(action_rename_file_);
@@ -346,22 +351,40 @@ void FileTreeView::slot_create_popup_menu() {
void FileTreeView::slot_show_custom_context_menu(const QPoint& point) {
auto target_path = this->GetPathByClickPoint(point);
+ auto select_path = GetSelectedPath();
+
+ GF_UI_LOG_DEBUG("file tree view, target path: {}, select path: {}",
+ target_path, select_path);
+ if (target_path.isEmpty() && !select_path.isEmpty()) {
+ target_path = select_path;
+ }
+
+ QFileInfo file_info(target_path);
- if (!target_path.isEmpty()) {
- action_open_file_->setEnabled(true);
+ action_open_file_->setEnabled(false);
+ action_rename_file_->setEnabled(false);
+ action_delete_file_->setEnabled(false);
+ action_calculate_hash_->setEnabled(false);
+ action_make_directory_->setEnabled(false);
+ action_create_empty_file_->setEnabled(false);
+ action_calculate_hash_->setEnabled(false);
+
+ if (file_info.exists()) {
+ action_open_file_->setEnabled(file_info.isFile() && file_info.isReadable());
action_rename_file_->setEnabled(true);
action_delete_file_->setEnabled(true);
- QFileInfo const info(this->GetSelectedPath());
- action_calculate_hash_->setEnabled(info.isFile() && info.isReadable());
-
+ action_make_directory_->setEnabled(file_info.isDir() &&
+ file_info.isWritable());
+ action_create_empty_file_->setEnabled(file_info.isDir() &&
+ file_info.isWritable());
+ action_calculate_hash_->setEnabled(file_info.isFile() &&
+ file_info.isReadable());
} else {
- action_open_file_->setEnabled(false);
- action_rename_file_->setEnabled(false);
- action_delete_file_->setEnabled(false);
-
- action_calculate_hash_->setEnabled(false);
+ action_create_empty_file_->setEnabled(true);
+ action_make_directory_->setEnabled(true);
}
+
popup_menu_->exec(this->GetMousePointGlobal(point));
}
diff --git a/src/ui/widgets/FileTreeView.h b/src/ui/widgets/FileTreeView.h
index 95bbc4cd..cd3b1cb8 100644
--- a/src/ui/widgets/FileTreeView.h
+++ b/src/ui/widgets/FileTreeView.h
@@ -225,6 +225,7 @@ class FileTreeView : public QTreeView {
QString selected_path_; ///<
QMenu* popup_menu_;
+ QMenu* new_item_action_menu_;
QAction* action_open_file_;
QAction* action_rename_file_;
QAction* action_delete_file_;
diff --git a/src/ui/widgets/PlainTextEditorPage.cpp b/src/ui/widgets/PlainTextEditorPage.cpp
index 7d951006..8f4890cc 100644
--- a/src/ui/widgets/PlainTextEditorPage.cpp
+++ b/src/ui/widgets/PlainTextEditorPage.cpp
@@ -110,11 +110,11 @@ void PlainTextEditorPage::slot_format_gpg_header() {
QString content = ui_->textPage->toPlainText();
// Get positions of the gpg-headers, if they exist
- int start = content.indexOf(GpgFrontend::PGP_SIGNED_BEGIN);
- int startSig = content.indexOf(GpgFrontend::PGP_SIGNATURE_BEGIN);
- int endSig = content.indexOf(GpgFrontend::PGP_SIGNATURE_END);
+ auto start = content.indexOf(GpgFrontend::PGP_SIGNED_BEGIN);
+ auto start_sig = content.indexOf(GpgFrontend::PGP_SIGNATURE_BEGIN);
+ auto end_sig = content.indexOf(GpgFrontend::PGP_SIGNATURE_END);
- if (start < 0 || startSig < 0 || endSig < 0 || sign_marked_) {
+ if (start < 0 || start_sig < 0 || end_sig < 0 || sign_marked_) {
return;
}
@@ -127,8 +127,8 @@ void PlainTextEditorPage::slot_format_gpg_header() {
// set font style for the signature
QTextCursor cursor(ui_->textPage->document());
- cursor.setPosition(startSig, QTextCursor::MoveAnchor);
- cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, endSig);
+ cursor.setPosition(start_sig, QTextCursor::MoveAnchor);
+ cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, end_sig);
cursor.setCharFormat(signFormat);
// set the font style for the header
@@ -141,14 +141,13 @@ void PlainTextEditorPage::slot_format_gpg_header() {
void PlainTextEditorPage::ReadFile() {
read_done_ = false;
read_bytes_ = 0;
- ui_->textPage->setEnabled(false);
- ui_->textPage->setReadOnly(true);
- ui_->textPage->blockSignals(true);
- ui_->loadingLabel->setHidden(false);
- ui_->textPage->document()->blockSignals(true);
auto *text_page = this->GetTextPage();
+ text_page->setEnabled(false);
text_page->setReadOnly(true);
+ text_page->blockSignals(true);
+ text_page->document()->blockSignals(true);
+ ui_->loadingLabel->setHidden(false);
const auto target_path = this->full_file_path_;
@@ -161,17 +160,17 @@ void PlainTextEditorPage::ReadFile() {
connect(this, &PlainTextEditorPage::SignalUIBytesDisplayed, read_task,
&FileReadTask::SignalFileBytesReadNext, Qt::QueuedConnection);
- connect(read_task, &FileReadTask::SignalTaskShouldEnd, this,
- []() { GF_UI_LOG_DEBUG("read thread closed"); });
connect(this, &PlainTextEditorPage::close, read_task,
- [=]() { read_task->SignalTaskShouldEnd(0); });
+ [=]() { emit read_task->SignalTaskShouldEnd(0); });
connect(read_task, &FileReadTask::SignalFileBytesReadEnd, this, [=]() {
// set the UI
+ GF_UI_LOG_DEBUG("signal file bytes read end rised");
this->read_done_ = true;
- this->ui_->textPage->setEnabled(true);
+ text_page->setEnabled(true);
text_page->document()->setModified(false);
- this->ui_->textPage->blockSignals(false);
- this->ui_->textPage->document()->blockSignals(false);
+ text_page->blockSignals(false);
+ text_page->document()->blockSignals(false);
+ text_page->setReadOnly(false);
this->ui_->loadingLabel->setHidden(true);
});
@@ -193,10 +192,8 @@ void PlainTextEditorPage::slot_insert_text(QByteArray bytes_data) {
// insert the text to the text page
this->GetTextPage()->insertPlainText(bytes_data);
-
- auto text = this->GetTextPage()->toPlainText();
- auto str = tr("%1 character(s)").arg(text.size());
- this->ui_->characterLabel->setText(str);
+ this->ui_->characterLabel->setText(
+ tr("%1 character(s)").arg(this->GetTextPage()->toPlainText().size()));
QTimer::singleShot(25, this, &PlainTextEditorPage::SignalUIBytesDisplayed);
}
diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp
index 3a56b90d..1373c5d9 100644
--- a/src/ui/widgets/TextEdit.cpp
+++ b/src/ui/widgets/TextEdit.cpp
@@ -33,8 +33,8 @@
#include <vector>
#include "core/GpgModel.h"
-#include "core/function/CacheManager.h"
#include "core/function/GlobalSettingStation.h"
+#include "ui/UISignalStation.h"
#include "ui/struct/CacheObject.h"
namespace GpgFrontend::UI {
@@ -600,6 +600,9 @@ void TextEdit::slot_file_page_path_changed(const QString& path) const {
m_path = t_path;
}
tab_widget_->setTabText(index, m_path);
+
+ emit UISignalStation::GetInstance()->SignalMainWindowlUpdateBasicalOperaMenu(
+ 0);
}
void TextEdit::slot_save_status_to_cache_for_revovery() {