diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/help/AboutDialog.cpp | 2 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowFileSlotFunction.cpp | 52 | ||||
-rw-r--r-- | src/ui/thread/FileReadThread.cpp | 30 | ||||
-rw-r--r-- | src/ui/widgets/FilePage.cpp | 95 | ||||
-rw-r--r-- | src/ui/widgets/KeyList.cpp | 2 | ||||
-rw-r--r-- | src/ui/widgets/PlainTextEditorPage.cpp | 4 | ||||
-rw-r--r-- | src/ui/widgets/PlainTextEditorPage.h | 4 | ||||
-rw-r--r-- | src/ui/widgets/TextEdit.cpp | 16 |
8 files changed, 137 insertions, 68 deletions
diff --git a/src/ui/help/AboutDialog.cpp b/src/ui/help/AboutDialog.cpp index 8b51f6ec..bcb397cc 100644 --- a/src/ui/help/AboutDialog.cpp +++ b/src/ui/help/AboutDialog.cpp @@ -113,7 +113,7 @@ TranslatorsTab::TranslatorsTab(QWidget* parent) : QWidget(parent) { QFile translators_qfile; auto translators_file = GlobalSettingStation::GetInstance().GetResourceDir() / "TRANSLATORS"; - translators_qfile.setFileName(translators_file.string().c_str()); + translators_qfile.setFileName(translators_file.u8string().c_str()); #ifdef LINUX if(!translators_qfile.exists()) { translators_qfile.setFileName("/usr/local/share/GpgFrontend/TRANSLATORS"); diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp index 97cb6a8d..e688927e 100644 --- a/src/ui/main_window/MainWindowFileSlotFunction.cpp +++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp @@ -95,7 +95,7 @@ bool process_tarball_into_directory(QWidget* parent, if (if_error || !exists(target_path)) { throw std::runtime_error("Decompress Failed"); } - path = target_path.string().c_str(); + path = target_path.u8string().c_str(); } catch (...) { LOG(ERROR) << "decompress error"; return false; @@ -132,7 +132,7 @@ bool process_directory_into_tarball(QWidget* parent, QString& path) { if (if_error || !exists(target_path)) { throw std::runtime_error("Compress Failed"); } - path = target_path.string().c_str(); + path = target_path.u8string().c_str(); } catch (...) { LOG(ERROR) << "compress error"; return false; @@ -144,7 +144,10 @@ void MainWindow::SlotFileEncrypt() { auto fileTreeView = edit_->SlotCurPageFileTreeView(); auto path = fileTreeView->GetSelected(); - if (!path_pre_check(this, path)) return; + if (!path_pre_check(this, path)) { + LOG(ERROR) << "path pre check failed"; + return; + } // check selected keys auto key_ids = m_key_list_->GetChecked(); @@ -178,7 +181,11 @@ void MainWindow::SlotFileEncrypt() { auto out_path = path + _extension; if (QFile::exists(out_path)) { +#ifdef WINDOWS + std::filesystem::path _out_path = out_path.toStdU16String(); +#else std::filesystem::path _out_path = out_path.toStdString(); +#endif auto out_file_name = boost::format(_("The target file %1% already exists, " "do you need to overwrite it?")) % _out_path.filename(); @@ -271,7 +278,11 @@ void MainWindow::SlotFileDecrypt() { if (!path_pre_check(this, path)) return; +#ifdef WINDOWS + std::filesystem::path out_path = path.toStdU16String(); +#else std::filesystem::path out_path = path.toStdString(); +#endif if (out_path.extension() == ".asc" || out_path.extension() == ".gpg") { out_path = out_path.parent_path() / out_path.stem(); @@ -293,7 +304,7 @@ void MainWindow::SlotFileDecrypt() { bool if_error = false; process_operation(this, _("Decrypting"), [&]() { try { - error = GpgFileOpera::DecryptFile(path.toStdString(), out_path.string(), + error = GpgFileOpera::DecryptFile(path.toStdString(), out_path.u8string(), result); } catch (const std::runtime_error& e) { if_error = true; @@ -377,7 +388,12 @@ void MainWindow::SlotFileSign() { _extension = ".sig"; } +#ifdef WINDOWS + std::filesystem::path in_path = path.toStdU16String(); +#else std::filesystem::path in_path = path.toStdString(); +#endif + auto sig_file_path = in_path; sig_file_path += _extension; if (exists(sig_file_path)) { @@ -385,7 +401,7 @@ void MainWindow::SlotFileSign() { this, _("Warning"), QString(_("The signature file \"%1\" exists, " "do you need to overwrite it?")) - .arg(sig_file_path.filename().string().c_str()), + .arg(sig_file_path.filename().u8string().c_str()), QMessageBox::Ok | QMessageBox::Cancel); if (ret == QMessageBox::Cancel) return; @@ -397,8 +413,8 @@ void MainWindow::SlotFileSign() { process_operation(this, _("Signing"), [&]() { try { - error = GpgFileOpera::SignFile(std::move(keys), in_path.string(), - sig_file_path.string(), result, _channel); + error = GpgFileOpera::SignFile(std::move(keys), in_path.u8string(), + sig_file_path.u8string(), result, _channel); } catch (const std::runtime_error& e) { if_error = true; } @@ -424,7 +440,12 @@ void MainWindow::SlotFileVerify() { auto fileTreeView = edit_->SlotCurPageFileTreeView(); auto path = fileTreeView->GetSelected(); +#ifdef WINDOWS + std::filesystem::path in_path = path.toStdU16String(); +#else std::filesystem::path in_path = path.toStdString(); +#endif + std::filesystem::path sign_file_path = in_path, data_file_path; // Detect ascii mode @@ -453,7 +474,7 @@ void MainWindow::SlotFileVerify() { bool ok; QString text = QInputDialog::getText(this, _("Origin file to verify"), _("Filepath"), QLineEdit::Normal, - data_file_path.string().c_str(), &ok); + data_file_path.u8string().c_str(), &ok); if (ok && !text.isEmpty()) { data_file_path = text.toStdString(); } else { @@ -479,7 +500,7 @@ void MainWindow::SlotFileVerify() { process_operation(this, _("Verifying"), [&]() { try { error = GpgFileOpera::VerifyFile( - data_file_path.string(), sign_file_path.string(), result, _channel); + data_file_path.u8string(), sign_file_path.u8string(), result, _channel); } catch (const std::runtime_error& e) { if_error = true; } @@ -636,7 +657,12 @@ void MainWindow::SlotFileDecryptVerify() { if (!path_pre_check(this, path)) return; - std::filesystem::path in_path(path.toStdString()); +#ifdef WINDOWS + std::filesystem::path in_path = path.toStdU16String(); +#else + std::filesystem::path in_path = path.toStdString(); +#endif + std::filesystem::path out_path = in_path; if (in_path.extension() == ".asc" || in_path.extension() == ".gpg") { out_path = in_path.parent_path() / out_path.stem(); @@ -645,12 +671,12 @@ void MainWindow::SlotFileDecryptVerify() { } LOG(INFO) << "out path" << out_path; - if (QFile::exists(out_path.string().c_str())) { + if (QFile::exists(out_path.u8string().c_str())) { auto ret = QMessageBox::warning(this, _("Warning"), QString(_("The output file %1 already exists, do " "you need to overwrite it?")) - .arg(out_path.filename().string().c_str()), + .arg(out_path.filename().u8string().c_str()), QMessageBox::Ok | QMessageBox::Cancel); if (ret == QMessageBox::Cancel) return; @@ -663,7 +689,7 @@ void MainWindow::SlotFileDecryptVerify() { process_operation(this, _("Decrypting and Verifying"), [&]() { try { error = GpgFileOpera::DecryptVerifyFile( - path.toStdString(), out_path.string(), d_result, v_result); + path.toStdString(), out_path.u8string(), d_result, v_result); } catch (const std::runtime_error& e) { if_error = true; } diff --git a/src/ui/thread/FileReadThread.cpp b/src/ui/thread/FileReadThread.cpp index b0eae355..258b9405 100644 --- a/src/ui/thread/FileReadThread.cpp +++ b/src/ui/thread/FileReadThread.cpp @@ -36,25 +36,33 @@ FileReadThread::FileReadThread(std::string path) : path_(std::move(path)) { } void FileReadThread::run() { - LOG(INFO) << "started"; - std::filesystem::path read_file_path(this->path_); + LOG(INFO) << "started reading" << path_; + +#ifdef WINDOWS + std::filesystem::path read_file_path(QString::fromStdString(path_).toStdU16String()); +#else + std::filesystem::path read_file_path(QString::fromStdString(path_).toStdString()); +#endif + if (is_regular_file(read_file_path)) { - LOG(INFO) << "read open"; + LOG(INFO) << "read open" << read_file_path; - auto fp = fopen(read_file_path.string().c_str(), "rb"); - size_t read_size; + QFile file; + file.setFileName(QString::fromStdString(read_file_path.u8string())); + file.open(QIODevice::ReadOnly); + QByteArray read_buffer; LOG(INFO) << "thread start reading"; - char buffer[4096]; - while ((read_size = fread(buffer, sizeof(char), sizeof buffer, fp)) > 0) { + const size_t buffer_size = 4096; + while ((read_buffer = file.read(buffer_size)).size() > 0) { // Check isInterruptionRequested if (QThread::currentThread()->isInterruptionRequested()) { LOG(INFO) << "thread is interruption requested "; - fclose(fp); + file.close(); return; } - LOG(INFO) << "block size " << read_size; - std::string buffer_str(buffer, read_size); + LOG(INFO) << "block size " << read_buffer.size(); + std::string buffer_str(read_buffer.toStdString()); emit SignalSendReadBlock(buffer_str); #ifdef RELEASE @@ -63,7 +71,7 @@ void FileReadThread::run() { QThread::msleep(128); #endif } - fclose(fp); + file.close(); emit SignalReadDone(); LOG(INFO) << "thread end reading"; } diff --git a/src/ui/widgets/FilePage.cpp b/src/ui/widgets/FilePage.cpp index 7682448d..1047be75 100644 --- a/src/ui/widgets/FilePage.cpp +++ b/src/ui/widgets/FilePage.cpp @@ -99,17 +99,23 @@ FilePage::FilePage(QWidget* parent) } void FilePage::slot_file_tree_view_item_clicked(const QModelIndex& index) { +#ifdef WINDOWS + selected_path_ = std::filesystem::path( + dir_model_->fileInfo(index).absoluteFilePath().toStdU16String()); +#else selected_path_ = std::filesystem::path( dir_model_->fileInfo(index).absoluteFilePath().toStdString()); +#endif + m_path_ = selected_path_; - LOG(INFO) << "selected path" << selected_path_; + LOG(INFO) << "selected path" << selected_path_.u8string(); selected_path_ = std::filesystem::path(selected_path_); MainWindow::CryptoMenu::OperationType operation_type = MainWindow::CryptoMenu::None; if (index.isValid()) { - QFileInfo info(QString::fromStdString(selected_path_.string())); + QFileInfo info(QString::fromStdString(selected_path_.u8string())); if ((info.isDir() || info.isFile()) && (info.suffix() != "gpg" && info.suffix() != "sig" && @@ -145,17 +151,21 @@ void FilePage::slot_file_tree_view_item_clicked(const QModelIndex& index) { void FilePage::slot_up_level() { QModelIndex currentRoot = ui_->fileTreeView->rootIndex(); - - auto utf8_path = - dir_model_->fileInfo(currentRoot).absoluteFilePath().toStdString(); - std::filesystem::path path_obj(utf8_path); +#ifdef WINDOWS + auto str_path = + dir_model_->fileInfo(currentRoot).absoluteFilePath().toStdU16String(); +#else + auto str_path = + dir_model_->fileInfo(currentRoot).absoluteFilePath().toUtf8().toStdString(); +#endif + std::filesystem::path path_obj(str_path); m_path_ = path_obj; LOG(INFO) << "get path" << m_path_; if (m_path_.has_parent_path() && !m_path_.parent_path().empty()) { m_path_ = m_path_.parent_path(); LOG(INFO) << "parent path" << m_path_; - ui_->pathEdit->setText(m_path_.string().c_str()); + ui_->pathEdit->setText(m_path_.u8string().c_str()); this->SlotGoPath(); } } @@ -172,30 +182,38 @@ void FilePage::slot_file_tree_view_item_double_clicked( } QString FilePage::GetSelected() const { - return QString::fromStdString(selected_path_.string()); + return QString::fromStdString(selected_path_.u8string()); } void FilePage::SlotGoPath() { - const auto path_edit = ui_->pathEdit->text().toStdString(); - std::filesystem::path path_obj(path_edit); +#ifdef WINDOWS + std::filesystem::path path_edit_obj(ui_->pathEdit->text().toStdU16String()); +#else + std::filesystem::path path_edit_obj(ui_->pathEdit->text().toStdString()); +#endif - if (m_path_.string() != path_edit) m_path_ = path_obj; + m_path_ = m_path_ != path_edit_obj ? path_edit_obj : m_path_; auto fileInfo = QFileInfo(m_path_.string().c_str()); if (fileInfo.isDir() && fileInfo.isReadable() && fileInfo.isExecutable()) { +#ifdef WINDOWS + m_path_ = std::filesystem::path(fileInfo.filePath().toStdU16String()); +#else m_path_ = std::filesystem::path(fileInfo.filePath().toStdString()); - LOG(INFO) << "set path" << m_path_; +#endif + + LOG(INFO) << "set path" << m_path_.u8string(); ui_->fileTreeView->setRootIndex(dir_model_->index(fileInfo.filePath())); dir_model_->setRootPath(fileInfo.filePath()); for (int i = 1; i < dir_model_->columnCount(); ++i) { ui_->fileTreeView->resizeColumnToContents(i); } - ui_->pathEdit->setText(m_path_.generic_string().c_str()); + ui_->pathEdit->setText(QString::fromStdString(m_path_.u8string())); } else { QMessageBox::critical( this, _("Error"), _("The path is not exists, unprivileged or unreachable.")); } - emit SignalPathChanged(m_path_.string().c_str()); + emit SignalPathChanged(QString::fromStdString(m_path_.u8string())); } void FilePage::create_popup_menu() { @@ -234,10 +252,10 @@ void FilePage::create_popup_menu() { new_item_action_menu->addAction(ui_->actionMakeDirectory); popup_menu_->addAction(ui_->actionOpenFile); + popup_menu_->addMenu(new_item_action_menu); + popup_menu_->addSeparator(); popup_menu_->addAction(ui_->actionRenameFile); popup_menu_->addAction(ui_->actionDeleteFile); - popup_menu_->addSeparator(); - popup_menu_->addMenu(new_item_action_menu); popup_menu_->addAction(ui_->actionCompressFiles); popup_menu_->addAction(ui_->actionCalculateHash); @@ -251,7 +269,7 @@ void FilePage::create_popup_menu() { dir_model_->setFilter(dir_model_->filter() | QDir::Hidden); else dir_model_->setFilter(dir_model_->filter() & ~QDir::Hidden); - dir_model_->setRootPath(m_path_.string().c_str()); + dir_model_->setRootPath(m_path_.u8string().c_str()); }); option_popup_menu_->addAction(showHiddenAct); @@ -263,17 +281,22 @@ void FilePage::create_popup_menu() { dir_model_->setFilter(dir_model_->filter() | QDir::System); else dir_model_->setFilter(dir_model_->filter() & ~QDir::System); - dir_model_->setRootPath(m_path_.string().c_str()); + dir_model_->setRootPath(m_path_.u8string().c_str()); }); option_popup_menu_->addAction(showSystemAct); } void FilePage::onCustomContextMenu(const QPoint& point) { QModelIndex index = ui_->fileTreeView->indexAt(point); - LOG(INFO) << "right click" << selected_path_; + LOG(INFO) << "right click" << selected_path_.u8string(); - selected_path_ = std::filesystem::path( - dir_model_->fileInfo(index).absoluteFilePath().toStdString()); +#ifdef WINDOWS + auto index_dir_str = dir_model_->fileInfo(index).absoluteFilePath().toStdU16String(); +#else + auto index_dir_str = dir_model_->fileInfo(index).absoluteFilePath().toStdString(); +#endif + + selected_path_ = std::filesystem::path(index_dir_str); // update crypt menu slot_file_tree_view_item_clicked(index); @@ -283,7 +306,7 @@ void FilePage::onCustomContextMenu(const QPoint& point) { ui_->actionRenameFile->setEnabled(true); ui_->actionDeleteFile->setEnabled(true); - QFileInfo info(QString::fromStdString(selected_path_.string())); + QFileInfo info(QString::fromStdString(selected_path_.u8string())); ui_->actionCalculateHash->setEnabled(info.isFile() && info.isReadable()); } else { ui_->actionOpenFile->setEnabled(false); @@ -296,12 +319,12 @@ void FilePage::onCustomContextMenu(const QPoint& point) { } void FilePage::slot_open_item() { - QFileInfo info(QString::fromStdString(selected_path_.string())); + QFileInfo info(QString::fromStdString(selected_path_.u8string())); if (info.isDir()) { if (info.isReadable() && info.isExecutable()) { - const auto file_path = info.filePath().toStdString(); + const auto file_path = info.filePath().toUtf8().toStdString(); LOG(INFO) << "set path" << file_path; - ui_->pathEdit->setText(info.filePath()); + ui_->pathEdit->setText(info.filePath().toUtf8()); SlotGoPath(); } else { QMessageBox::critical(this, _("Error"), @@ -311,9 +334,9 @@ void FilePage::slot_open_item() { if (info.isReadable()) { // handle normal text or binary file auto main_window = qobject_cast<MainWindow*>(first_parent_); - LOG(INFO) << "open item" << selected_path_; - auto qt_path = QString::fromStdString(selected_path_.string()); - if (main_window != nullptr) main_window->SlotOpenFile(qt_path); + auto qt_open_path = QString::fromStdString(selected_path_.u8string()); + LOG(INFO) << "open item" << qt_open_path.toStdString(); + if (main_window != nullptr) main_window->SlotOpenFile(qt_open_path); } else { QMessageBox::critical(this, _("Error"), _("The file is unprivileged or unreachable.")); @@ -329,10 +352,14 @@ void FilePage::slot_rename_item() { bool ok; auto text = QInputDialog::getText(this, _("Rename"), _("New Filename"), - QLineEdit::Normal, old_name.string().c_str(), &ok); + QLineEdit::Normal, QString::fromStdString(old_name.u8string()), &ok); if (ok && !text.isEmpty()) { try { +#ifdef WINDOWS + new_name_path /= text.toStdU16String(); +#else new_name_path /= text.toStdString(); +#endif LOG(INFO) << "new name path" << new_name_path; std::filesystem::rename(old_name_path, new_name_path); // refresh @@ -382,7 +409,11 @@ void FilePage::slot_mkdir() { } void FilePage::slot_create_empty_file() { +#ifdef WINDOWS + auto root_path_str = dir_model_->rootPath().toStdU16String(); +#else auto root_path_str = dir_model_->rootPath().toStdString(); +#endif std::filesystem::path root_path(root_path_str); QString new_file_name; @@ -391,8 +422,12 @@ void FilePage::slot_create_empty_file() { _("Filename (you can given extension)"), QLineEdit::Normal, new_file_name, &ok); if (ok && !new_file_name.isEmpty()) { +#ifdef WINDOWS + auto file_path = root_path / new_file_name.toStdU16String(); +#else auto file_path = root_path / new_file_name.toStdString(); - QFile new_file(file_path.string().c_str()); +#endif + QFile new_file(file_path.u8string().c_str()); if (!new_file.open(QIODevice::WriteOnly | QIODevice::NewOnly)) { QMessageBox::critical(this, _("Error"), _("Unable to create the file.")); } diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index 75558edc..60cfbc84 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -58,7 +58,7 @@ void KeyList::init() { auto db_path = GpgFrontend::GlobalSettingStation::GetInstance() .GetStandaloneDatabaseDir(); GpgContext::CreateInstance( - _m_key_list_id, std::make_unique<GpgContext>(true, db_path.string(), true, + _m_key_list_id, std::make_unique<GpgContext>(true, db_path.u8string(), true, gpg_path.string())); #else new_default_settings_channel(m_key_list_id_); diff --git a/src/ui/widgets/PlainTextEditorPage.cpp b/src/ui/widgets/PlainTextEditorPage.cpp index 0161bf91..c70991b9 100644 --- a/src/ui/widgets/PlainTextEditorPage.cpp +++ b/src/ui/widgets/PlainTextEditorPage.cpp @@ -36,10 +36,10 @@ namespace GpgFrontend::UI { -PlainTextEditorPage::PlainTextEditorPage(QString filePath, QWidget *parent) +PlainTextEditorPage::PlainTextEditorPage(QString file_path, QWidget *parent) : QWidget(parent), ui_(std::make_shared<Ui_PlainTextEditor>()), - full_file_path_(std::move(filePath)) { + full_file_path_(std::move(file_path)) { ui_->setupUi(this); if (full_file_path_.isEmpty()) read_done_ = true; diff --git a/src/ui/widgets/PlainTextEditorPage.h b/src/ui/widgets/PlainTextEditorPage.h index f73e2282..e76c11e3 100644 --- a/src/ui/widgets/PlainTextEditorPage.h +++ b/src/ui/widgets/PlainTextEditorPage.h @@ -46,10 +46,10 @@ class PlainTextEditorPage : public QWidget { /** * @details Add layout and add plaintextedit * - * @param filePath Path of the file handled in this tab + * @param file_path Path of the file handled in this tab * @param parent Pointer to the parent widget */ - explicit PlainTextEditorPage(QString filePath = "", + explicit PlainTextEditorPage(QString file_path = "", QWidget* parent = nullptr); /** diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp index 5556397e..ecf1a4bd 100644 --- a/src/ui/widgets/TextEdit.cpp +++ b/src/ui/widgets/TextEdit.cpp @@ -108,23 +108,23 @@ void TextEdit::SlotOpenFile(QString& path) { } void TextEdit::SlotOpen() { - QStringList fileNames = + QStringList file_names = QFileDialog::getOpenFileNames(this, _("Open file"), QDir::currentPath()); - for (const auto& fileName : fileNames) { - if (!fileName.isEmpty()) { - QFile file(fileName); + for (const auto& file_name : file_names) { + if (!file_name.isEmpty()) { + QFile file(file_name); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { - auto* page = new PlainTextEditorPage(fileName); + auto* page = new PlainTextEditorPage(file_name); QTextStream in(&file); QApplication::setOverrideCursor(Qt::WaitCursor); page->GetTextPage()->setPlainText(in.readAll()); - page->SetFilePath(fileName); + page->SetFilePath(file_name); QTextDocument* document = page->GetTextPage()->document(); document->setModified(false); - tab_widget_->addTab(page, stripped_name(fileName)); + tab_widget_->addTab(page, stripped_name(file_name)); tab_widget_->setCurrentIndex(tab_widget_->count() - 1); QApplication::restoreOverrideCursor(); page->GetTextPage()->setFocus(); @@ -137,7 +137,7 @@ void TextEdit::SlotOpen() { QMessageBox::warning( this, _("Warning"), (boost::format(_("Cannot read file %1%:\n%2%.")) % - fileName.toStdString() % file.errorString().toStdString()) + file_name.toStdString() % file.errorString().toStdString()) .str() .c_str()); } |