diff options
author | saturneric <[email protected]> | 2024-01-01 09:15:25 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-01-01 09:15:25 +0000 |
commit | 1cdba285be9bebd9b793fc6ae0369d201a0e713b (patch) | |
tree | 6f38e86b19044ba9ecbe9a520e150dd49cb992a8 /src/ui/main_window/MainWindowSlotFunction.cpp | |
parent | feat: fully test basical operations of archive and file (diff) | |
download | GpgFrontend-1cdba285be9bebd9b793fc6ae0369d201a0e713b.tar.gz GpgFrontend-1cdba285be9bebd9b793fc6ae0369d201a0e713b.zip |
feat: improve file browser's functions and tidy up codes
Diffstat (limited to 'src/ui/main_window/MainWindowSlotFunction.cpp')
-rw-r--r-- | src/ui/main_window/MainWindowSlotFunction.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
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 <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time_io.hpp> +#include <cstddef> #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<qint64>(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( |