diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/dialog/Wizard.cpp | 167 | ||||
-rw-r--r-- | src/ui/widgets/FilePage.cpp | 29 | ||||
-rw-r--r-- | src/ui/widgets/FilePage.h | 2 | ||||
-rw-r--r-- | src/ui/widgets/FileTreeView.cpp | 82 | ||||
-rw-r--r-- | src/ui/widgets/FileTreeView.h | 6 |
5 files changed, 147 insertions, 139 deletions
diff --git a/src/ui/dialog/Wizard.cpp b/src/ui/dialog/Wizard.cpp index a126d995..4f2dbbdf 100644 --- a/src/ui/dialog/Wizard.cpp +++ b/src/ui/dialog/Wizard.cpp @@ -59,84 +59,87 @@ void Wizard::slot_wizard_accepted() { } IntroPage::IntroPage(QWidget* parent) : QWizardPage(parent) { - setTitle(tr("Getting Started...")); - setSubTitle(tr("... with GpgFrontend")); - - auto* top_label = new QLabel( - tr("Welcome to GpgFrontend for decrypting and signing text or files!") + - " <br><br><a href='https://gpgfrontend.bktus.com'>GpgFrontend</a> " + - tr("is a Powerful, Easy-to-Use, Compact, Cross-Platform, and " - "Installation-Free OpenPGP Crypto Tool. ") + - tr("To get started, be sure to check out the") + + setTitle(tr("Welcome to GpgFrontend")); + setSubTitle(tr("Your OpenPGP encryption companion.")); + + // Intro text + auto* intro_label = new QLabel( + tr("<b>GpgFrontend</b> is a free, user-friendly, and cross-platform tool " + "for " + "OpenPGP encryption, decryption, and signing of text and files.") + + "<br><br>" + tr("To get started, take a quick look at the") + " <a href='https://gpgfrontend.bktus.com/overview/glance'>" + - tr("Overview") + "</a> (" + - tr("by clicking the link, the page will open in your web browser") + - "). <br>"); - top_label->setTextFormat(Qt::RichText); - top_label->setTextInteractionFlags(Qt::TextBrowserInteraction); - top_label->setOpenExternalLinks(true); - top_label->setWordWrap(true); - - // QComboBox for language selection + tr("Overview Page") + "</a>." + " " + + tr("It will open in your default browser.")); + intro_label->setTextFormat(Qt::RichText); + intro_label->setTextInteractionFlags(Qt::TextBrowserInteraction); + intro_label->setOpenExternalLinks(true); + intro_label->setWordWrap(true); + + // Language info auto* lang_label = - new QLabel(tr("If it supports the language currently being used in your " - "system, GpgFrontend will automatically set it.")); + new QLabel(tr("GpgFrontend will automatically use the language of your " + "system if supported. " + "You can change the language later in settings.")); lang_label->setWordWrap(true); - // set layout and add widgets + // Layout auto* layout = new QVBoxLayout; - layout->addWidget(top_label); - layout->addStretch(); + layout->addWidget(intro_label); + layout->addSpacing(20); layout->addWidget(lang_label); - + layout->addStretch(); setLayout(layout); } auto IntroPage::nextId() const -> int { return Wizard::kPAGE_CHOOSE; } ChoosePage::ChoosePage(QWidget* parent) : QWizardPage(parent) { - setTitle(tr("Choose your action...")); - setSubTitle(tr("...by clicking on the appropriate link.")); - - auto* keygen_label = new QLabel( - tr("If you have never used GpgFrontend before and also don't own a gpg " - "key yet you may possibly want to read how to") + - " <a href=\"https://gpgfrontend.bktus.com/guides/generate-key\">" + - tr("Generate Key") + "</a><hr>"); - keygen_label->setTextFormat(Qt::RichText); - keygen_label->setTextInteractionFlags(Qt::TextBrowserInteraction); - keygen_label->setOpenExternalLinks(true); - keygen_label->setWordWrap(true); - - auto* encr_decy_text_label = new QLabel( - tr("If you want to learn how to encrypt, decrypt, sign and verify text, " - "you can read ") + - "<a href=\"https://gpgfrontend.bktus.com/guides/encrypt-decrypt-text\">" + - tr("Encrypt & Decrypt Text") + "</a> " + tr("or") + - " <a href=\"https://gpgfrontend.bktus.com/guides/sign-verify-text\">" + - tr("Sign & Verify Text") + "</a><hr>"); - - encr_decy_text_label->setTextFormat(Qt::RichText); - encr_decy_text_label->setTextInteractionFlags(Qt::TextBrowserInteraction); - encr_decy_text_label->setOpenExternalLinks(true); - encr_decy_text_label->setWordWrap(true); - - auto* sign_verify_text_label = new QLabel( - tr("If you want to operate file, you can read ") + - "<a href=\"https://gpgfrontend.bktus.com/guides/encrypt-decrypt-file\">" + - tr("Encrypt & Sign File") + "</a> " + tr("or") + - " <a href=\"https://gpgfrontend.bktus.com/guides/sign-verify-file\">" + - tr("Sign & Verify File") + "</a><hr>"); - sign_verify_text_label->setTextFormat(Qt::RichText); - sign_verify_text_label->setTextInteractionFlags(Qt::TextBrowserInteraction); - sign_verify_text_label->setOpenExternalLinks(true); - sign_verify_text_label->setWordWrap(true); - - auto* layout = new QVBoxLayout(); - layout->addWidget(keygen_label); - layout->addWidget(encr_decy_text_label); - layout->addWidget(sign_verify_text_label); + setTitle(tr("Welcome to GpgFrontend")); + setSubTitle(tr("These quick guides will help you get started.")); + + auto* layout = new QVBoxLayout; + + // Section 1: Fundamental Concepts + auto* concepts_title = new QLabel(tr("<b>New to encryption?</b>")); + auto* concepts_desc = new QLabel( + tr("Understand the basics of OpenPGP and how GpgFrontend works.")); + auto* concepts_link = new QLabel( + "<a " + "href=\"https://gpgfrontend.bktus.com/guides/fundamental-concepts/\">" + + tr("Fundamental Concepts") + "</a>"); + + // Section 2: Text operations + auto* textops_title = new QLabel(tr("<b>Working with text?</b>")); + auto* textops_desc = new QLabel( + tr("Learn how to encrypt, decrypt, sign, and verify text messages.")); + auto* textops_link = new QLabel( + "<a href=\"https://gpgfrontend.bktus.com/guides/text-opetations/\">" + + tr("Text Operations Guide") + "</a>"); + + // Section 3: File operations + auto* fileops_title = new QLabel(tr("<b>Working with files?</b>")); + auto* fileops_desc = + new QLabel(tr("Learn how to encrypt, sign, and verify files securely.")); + auto* fileops_link = new QLabel( + "<a href=\"https://gpgfrontend.bktus.com/guides/file-operations/\">" + + tr("File Operations Guide") + "</a>"); + + // All labels: uniform setup + const QList<QLabel*> labels = {concepts_title, concepts_desc, concepts_link, + textops_title, textops_desc, textops_link, + fileops_title, fileops_desc, fileops_link}; + for (auto* l : labels) { + l->setTextFormat(Qt::RichText); + l->setTextInteractionFlags(Qt::TextBrowserInteraction); + l->setOpenExternalLinks(true); + l->setWordWrap(true); + layout->addWidget(l); + } + + layout->addStretch(); // push content upward setLayout(layout); + next_page_ = Wizard::kPAGE_CONCLUSION; } @@ -152,42 +155,46 @@ void ChoosePage::slot_jump_page(const QString& page) { } ConclusionPage::ConclusionPage(QWidget* parent) : QWizardPage(parent) { - setTitle(tr("Ready.")); - setSubTitle(tr("Have fun with GpgFrontend!")); + setTitle(tr("You're all set!")); + setSubTitle(tr("GpgFrontend is ready to use.")); auto* bottom_label = new QLabel( - tr("You are ready to use GpgFrontend now.<br><br>") + - "<a href=\"https://gpgfrontend.bktus.com/guides/fundamental-concepts\">" + - tr("The Online Document") + "</a>" + - tr(" will get you started with GpgFrontend. Anytime you encounter " - "problems, please try to find help from the documentation") + - "<br>"); - + tr("GpgFrontend is now fully set up and ready to go.") + "<br><br>" + + tr("If you encounter any issues or have questions, feel free to ") + + "<a href=\"https://github.com/saturneric/GpgFrontend/issues\">" + + tr("submit an issue on GitHub") + "</a> " + tr("or ") + + "<a href=\"https://gpgfrontend.bktus.com/overview/contact/\">" + + tr("contact the developer") + "</a>." + "<br>" + + tr("Any feedback is welcome and valuable!")); bottom_label->setTextFormat(Qt::RichText); bottom_label->setTextInteractionFlags(Qt::TextBrowserInteraction); bottom_label->setOpenExternalLinks(true); bottom_label->setWordWrap(true); - open_help_check_box_ = new QCheckBox(tr("Open offline help.")); + // Option checkboxes + open_help_check_box_ = new QCheckBox(tr("Open offline help now")); open_help_check_box_->setChecked(true); dont_show_wizard_checkbox_ = - new QCheckBox(tr("Don't show the wizard again.")); + new QCheckBox(tr("Don't show this setup wizard again")); dont_show_wizard_checkbox_->setChecked(true); - check_updates_checkbox_ = - new QCheckBox(tr("Check for updates at each startup.")); + check_updates_checkbox_ = new QCheckBox(tr("Check for updates on startup")); check_updates_checkbox_->setChecked(true); + // Register fields registerField("showWizard", dont_show_wizard_checkbox_); registerField("checkUpdate", check_updates_checkbox_); + // Layout auto* layout = new QVBoxLayout; layout->addWidget(bottom_label); - layout->addWidget(dont_show_wizard_checkbox_); + layout->addSpacing(15); + // layout->addWidget(open_help_check_box_); layout->addWidget(check_updates_checkbox_); + layout->addWidget(dont_show_wizard_checkbox_); + layout->addStretch(); setLayout(layout); - setVisible(true); } auto ConclusionPage::nextId() const -> int { return -1; } 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 |