aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/function/gpg/GpgContext.cpp12
-rw-r--r--src/ui/widgets/FilePage.cpp29
-rw-r--r--src/ui/widgets/FilePage.h2
-rw-r--r--src/ui/widgets/FileTreeView.cpp82
-rw-r--r--src/ui/widgets/FileTreeView.h6
-rw-r--r--ui/FilePage.ui23
6 files changed, 80 insertions, 74 deletions
diff --git a/src/core/function/gpg/GpgContext.cpp b/src/core/function/gpg/GpgContext.cpp
index 49d39650..0f7d30de 100644
--- a/src/core/function/gpg/GpgContext.cpp
+++ b/src/core/function/gpg/GpgContext.cpp
@@ -88,7 +88,7 @@ class GpgAgentProcess {
args.append("--disable-scdaemon");
}
- LOG_E() << "gpg-agent start args: " << args << "channel:" << channel_;
+ LOG_D() << "gpg-agent start args: " << args << "channel:" << channel_;
process_.setProgram(info.absoluteFilePath());
process_.setArguments(args);
@@ -162,8 +162,8 @@ class GpgContext::Impl {
[[nodiscard]] auto Good() const -> bool { return good_; }
- auto SetPassphraseCb(const gpgme_ctx_t &ctx,
- gpgme_passphrase_cb_t cb) -> bool {
+ auto SetPassphraseCb(const gpgme_ctx_t &ctx, gpgme_passphrase_cb_t cb)
+ -> bool {
if (gpgme_get_pinentry_mode(ctx) != GPGME_PINENTRY_MODE_LOOPBACK) {
if (CheckGpgError(gpgme_set_pinentry_mode(
ctx, GPGME_PINENTRY_MODE_LOOPBACK)) != GPG_ERR_NO_ERROR) {
@@ -258,8 +258,8 @@ class GpgContext::Impl {
return res == pass_size + 1 ? 0 : GPG_ERR_CANCELED;
}
- static auto TestStatusCb(void *hook, const char *keyword,
- const char *args) -> gpgme_error_t {
+ static auto TestStatusCb(void *hook, const char *keyword, const char *args)
+ -> gpgme_error_t {
FLOG_D("keyword %s", keyword);
return GPG_ERR_NO_ERROR;
}
@@ -544,7 +544,7 @@ class GpgContext::Impl {
args.append({"--kill", "gpg-agent"});
- LOG_E() << "gpgconf kill args: " << args
+ LOG_D() << "gpgconf kill args: " << args
<< "channel:" << parent_->GetChannel();
QProcess process;
diff --git a/src/ui/widgets/FilePage.cpp b/src/ui/widgets/FilePage.cpp
index 95dbfac9..59a3c9ed 100644
--- a/src/ui/widgets/FilePage.cpp
+++ b/src/ui/widgets/FilePage.cpp
@@ -37,21 +37,20 @@ 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_(GpgFrontend::SecureCreateSharedObject<Ui_FilePage>()) {
ui_->setupUi(this);
- ui_->trewViewLayout->addWidget(file_tree_view_);
ui_->batchModeButton->setToolTip(tr("Switch Batch Mode"));
- connect(ui_->upPathButton, &QPushButton::clicked, file_tree_view_,
+ connect(ui_->upPathButton, &QPushButton::clicked, ui_->treeView,
&FileTreeView::SlotUpLevel);
connect(ui_->refreshButton, &QPushButton::clicked, this,
&FilePage::SlotGoPath);
- connect(this->ui_->newDirButton, &QPushButton::clicked, file_tree_view_,
+ connect(this->ui_->newDirButton, &QPushButton::clicked, ui_->treeView,
&FileTreeView::SlotMkdir);
- ui_->pathEdit->setText(file_tree_view_->GetCurrentPath());
+ ui_->treeView->SetPath(target_path);
+ ui_->pathEdit->setText(ui_->treeView->GetCurrentPath());
path_edit_completer_ = new QCompleter(this);
path_complete_model_ = new QStringListModel();
@@ -64,13 +63,13 @@ FilePage::FilePage(QWidget* parent, const QString& target_path)
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_,
+ connect(show_hidden_act, &QAction::triggered, ui_->treeView,
&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_,
+ connect(show_system_act, &QAction::triggered, ui_->treeView,
&FileTreeView::SlotShowSystemFile);
option_popup_menu_->addAction(show_system_act);
@@ -105,30 +104,30 @@ FilePage::FilePage(QWidget* parent, const QString& target_path)
connect(this, &FilePage::SignalRefreshInfoBoard,
UISignalStation::GetInstance(),
&UISignalStation::SignalRefreshInfoBoard);
- connect(file_tree_view_, &FileTreeView::SignalPathChanged, this,
+ connect(ui_->treeView, &FileTreeView::SignalPathChanged, this,
[this](const QString& path) { this->ui_->pathEdit->setText(path); });
- connect(file_tree_view_, &FileTreeView::SignalPathChanged, this,
+ connect(ui_->treeView, &FileTreeView::SignalPathChanged, this,
&FilePage::SignalPathChanged);
- connect(file_tree_view_, &FileTreeView::SignalOpenFile,
+ connect(ui_->treeView, &FileTreeView::SignalOpenFile,
UISignalStation::GetInstance(),
&UISignalStation::SignalMainWindowOpenFile);
- connect(file_tree_view_, &FileTreeView::SignalSelectedChanged, this,
+ connect(ui_->treeView, &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_,
+ connect(ui_->batchModeButton, &QToolButton::toggled, ui_->treeView,
&FileTreeView::SlotSwitchBatchMode);
}
auto FilePage::GetSelected() const -> QStringList {
- return file_tree_view_->GetSelectedPaths();
+ return ui_->treeView->GetSelectedPaths();
}
void FilePage::SlotGoPath() {
- file_tree_view_->SlotGoPath(ui_->pathEdit->text());
+ ui_->treeView->SlotGoPath(ui_->pathEdit->text());
}
void FilePage::keyPressEvent(QKeyEvent* event) {
diff --git a/src/ui/widgets/FilePage.h b/src/ui/widgets/FilePage.h
index fbf99ae9..94b90b0d 100644
--- a/src/ui/widgets/FilePage.h
+++ b/src/ui/widgets/FilePage.h
@@ -29,7 +29,6 @@
#pragma once
#include "ui/GpgFrontendUI.h"
-#include "ui/widgets/FileTreeView.h"
#include "ui/widgets/InfoBoardWidget.h"
class Ui_FilePage;
@@ -126,7 +125,6 @@ class FilePage : public QWidget {
QMenu* popup_menu_{}; ///<
QMenu* option_popup_menu_{}; ///<
- FileTreeView* file_tree_view_;
bool ascii_mode_;
private slots:
diff --git a/src/ui/widgets/FileTreeView.cpp b/src/ui/widgets/FileTreeView.cpp
index 8ebd7274..db628d60 100644
--- a/src/ui/widgets/FileTreeView.cpp
+++ b/src/ui/widgets/FileTreeView.cpp
@@ -35,7 +35,7 @@
namespace GpgFrontend::UI {
-FileTreeView::FileTreeView(QWidget* parent, const QString& target_path)
+FileTreeView::FileTreeView(QWidget* parent)
: QTreeView(parent), dir_model_(new QFileSystemModel(this)) {
dir_model_->setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);
dir_model_->setRootPath(QDir::homePath());
@@ -58,43 +58,6 @@ FileTreeView::FileTreeView(QWidget* parent, const QString& target_path)
&FileTreeView::slot_adjust_column_widths);
connect(dir_model_, &QFileSystemModel::dataChanged, this,
&FileTreeView::slot_adjust_column_widths);
-
- LOG_D() << "try to open target path:" << target_path;
-
- QFileInfo info(target_path);
- QString effective_path;
-
- if (info.exists()) {
- effective_path =
- info.isFile() ? info.absolutePath() : info.absoluteFilePath();
- } else {
- effective_path = QDir::currentPath();
- }
-
- LOG_D() << "effective path:" << effective_path;
-
- dir_model_->setRootPath(effective_path);
- current_path_ = dir_model_->rootPath();
- QModelIndex root_index = dir_model_->index(current_path_);
-
- if (root_index.isValid()) {
- QPointer<FileTreeView> self(this);
- this->setRootIndex(root_index);
- QTimer::singleShot(200, [=]() {
- if (self != nullptr && info.isFile()) {
- self->setCurrentIndex(dir_model_->index(info.absoluteFilePath()));
- self->expand(currentIndex().parent());
- self->scrollTo(currentIndex(), QAbstractItemView::PositionAtCenter);
- self->selectionModel()->select(
- currentIndex(),
- QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
- }
- });
- } else {
- LOG_W() << "invalid path, fallback to current dir.";
- current_path_ = QDir::currentPath();
- this->setRootIndex(dir_model_->index(current_path_));
- }
}
void FileTreeView::selectionChanged(const QItemSelection& selected,
@@ -446,9 +409,8 @@ void FileTreeView::slot_calculate_hash() {
return;
}
auto result = ExtractParams<QString>(data_object, 0);
- emit UISignalStation::GetInstance()
- -> SignalRefreshInfoBoard(result,
- InfoBoardStatus::INFO_ERROR_OK);
+ emit UISignalStation::GetInstance() -> SignalRefreshInfoBoard(
+ result, InfoBoardStatus::INFO_ERROR_OK);
},
"calculate_file_hash");
});
@@ -481,4 +443,42 @@ void FileTreeView::SlotSwitchBatchMode(bool batch) {
selectionModel()->clearSelection();
}
+void FileTreeView::SetPath(const QString& target_path) {
+ LOG_D() << "try to open target path:" << target_path;
+
+ QFileInfo info(target_path);
+ QString effective_path;
+
+ if (info.exists()) {
+ effective_path =
+ info.isFile() ? info.absolutePath() : info.absoluteFilePath();
+ } else {
+ effective_path = QDir::currentPath();
+ }
+
+ LOG_D() << "effective path:" << effective_path;
+
+ dir_model_->setRootPath(effective_path);
+ current_path_ = dir_model_->rootPath();
+ QModelIndex root_index = dir_model_->index(current_path_);
+
+ if (root_index.isValid()) {
+ QPointer<FileTreeView> self(this);
+ this->setRootIndex(root_index);
+ QTimer::singleShot(200, [=]() {
+ if (self != nullptr && info.isFile()) {
+ self->setCurrentIndex(dir_model_->index(info.absoluteFilePath()));
+ self->expand(currentIndex().parent());
+ self->scrollTo(currentIndex(), QAbstractItemView::PositionAtCenter);
+ self->selectionModel()->select(
+ currentIndex(),
+ QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
+ }
+ });
+ } else {
+ LOG_W() << "invalid path, fallback to current dir.";
+ current_path_ = QDir::currentPath();
+ this->setRootIndex(dir_model_->index(current_path_));
+ }
+}
} // namespace GpgFrontend::UI
diff --git a/src/ui/widgets/FileTreeView.h b/src/ui/widgets/FileTreeView.h
index 333e06bc..e7ddb607 100644
--- a/src/ui/widgets/FileTreeView.h
+++ b/src/ui/widgets/FileTreeView.h
@@ -41,7 +41,11 @@ class FileTreeView : public QTreeView {
* @param parent
* @param target_path
*/
- explicit FileTreeView(QWidget* parent, const QString& target_path);
+ explicit FileTreeView(QWidget* parent);
+
+ /**
+ */
+ void SetPath(const QString& target_path);
/**
* @brief Get the Current Path object
diff --git a/ui/FilePage.ui b/ui/FilePage.ui
index b9ae7043..97a3ad94 100644
--- a/ui/FilePage.ui
+++ b/ui/FilePage.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>858</width>
- <height>64</height>
+ <width>805</width>
+ <height>666</height>
</rect>
</property>
<property name="sizePolicy">
@@ -16,12 +16,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="maximumSize">
- <size>
- <width>1041</width>
- <height>619</height>
- </size>
- </property>
<property name="windowTitle">
<string>Form</string>
</property>
@@ -190,7 +184,11 @@
</layout>
</item>
<item>
- <layout class="QVBoxLayout" name="trewViewLayout"/>
+ <layout class="QVBoxLayout" name="trewViewLayout">
+ <item>
+ <widget class="GpgFrontend::UI::FileTreeView" name="treeView"/>
+ </item>
+ </layout>
</item>
</layout>
</item>
@@ -198,6 +196,13 @@
</item>
</layout>
</widget>
+ <customwidgets>
+ <customwidget>
+ <class>GpgFrontend::UI::FileTreeView</class>
+ <extends>QTreeView</extends>
+ <header>ui/widgets/FileTreeView.h</header>
+ </customwidget>
+ </customwidgets>
<resources>
<include location="../gpgfrontend.qrc"/>
</resources>