From 1cdba285be9bebd9b793fc6ae0369d201a0e713b Mon Sep 17 00:00:00 2001 From: saturneric Date: Mon, 1 Jan 2024 17:15:25 +0800 Subject: feat: improve file browser's functions and tidy up codes --- src/ui/main_window/MainWindowSlotFunction.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/ui/main_window/MainWindowSlotFunction.cpp') diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index e4038f66..95eb9871 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -28,6 +28,7 @@ #include #include +#include #include "MainWindow.h" #include "core/GpgConstants.h" @@ -249,7 +250,25 @@ void MainWindow::upload_key_to_server() { dialog->SlotUpload(); } -void MainWindow::SlotOpenFile(QString& path) { edit_->SlotOpenFile(path); } +void MainWindow::SlotOpenFile(const QString& path) { + QFileInfo const info(path); + if (!info.isFile() || !info.isReadable()) { + QMessageBox::critical(this, _("Error"), + _("Cannot open this file. Please make sure that this " + "is a regular file and it's readable.")); + return; + } + + if (info.size() > static_cast(1024 * 1024)) { + QMessageBox::critical( + this, _("Error"), + _("Cannot open this file. The file is TOO LARGE (>1MB) for " + "GpgFrontend Text Editor.")); + return; + } + + edit_->SlotOpenFile(path); +} void MainWindow::slot_version_upgrade_nofity() { SPDLOG_DEBUG( -- cgit v1.2.3