aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2022-03-19 06:09:55 +0000
committerSaturneric <[email protected]>2022-03-19 06:09:55 +0000
commitdad03e9ccc57da0a04d058ec418ce0068ce3841d (patch)
treee3d6bec71f3c070139ef5dfa7cca0cf70acb4dd1
parent<fix>(ui): Fix the problem that the file cannot be signed (diff)
downloadGpgFrontend-dad03e9ccc57da0a04d058ec418ce0068ce3841d.tar.gz
GpgFrontend-dad03e9ccc57da0a04d058ec418ce0068ce3841d.zip
<fix>(core, ui): Fix path double-byte encoding problem under Windows
-rw-r--r--src/core/GpgConstants.cpp8
-rw-r--r--src/core/function/ArchiveFileOperator.cpp24
-rw-r--r--src/core/function/ArchiveFileOperator.h2
-rw-r--r--src/core/function/DataObjectOperator.cpp8
-rw-r--r--src/core/function/FileOperator.cpp11
-rw-r--r--src/core/function/GlobalSettingStation.cpp8
-rw-r--r--src/core/function/KeyPackageOperator.cpp6
-rw-r--r--src/core/function/gpg/GpgFileOpera.cpp91
-rw-r--r--src/init.cpp4
-rw-r--r--src/main.cpp6
-rw-r--r--src/ui/help/AboutDialog.cpp2
-rw-r--r--src/ui/main_window/MainWindowFileSlotFunction.cpp52
-rw-r--r--src/ui/thread/FileReadThread.cpp30
-rw-r--r--src/ui/widgets/FilePage.cpp95
-rw-r--r--src/ui/widgets/KeyList.cpp2
-rw-r--r--src/ui/widgets/PlainTextEditorPage.cpp4
-rw-r--r--src/ui/widgets/PlainTextEditorPage.h4
-rw-r--r--src/ui/widgets/TextEdit.cpp16
-rw-r--r--test/GpgFrontendTest.h4
19 files changed, 258 insertions, 119 deletions
diff --git a/src/core/GpgConstants.cpp b/src/core/GpgConstants.cpp
index f35c257d..284022a8 100644
--- a/src/core/GpgConstants.cpp
+++ b/src/core/GpgConstants.cpp
@@ -120,7 +120,7 @@ std::string GpgFrontend::read_all_data_in_file(const std::string& utf8_path) {
if (!exists(file_info) || !is_regular_file(file_info)) return {};
std::ifstream in_file;
#ifndef WINDOWS
- in_file.open(file_info.string(), std::ios::in);
+ in_file.open(file_info.u8string(), std::ios::in);
#else
in_file.open(file_info.wstring().c_str(), std::ios::in);
#endif
@@ -137,7 +137,7 @@ bool GpgFrontend::write_buffer_to_file(const std::string& utf8_path,
using namespace std::filesystem;
class path file_info(utf8_path.c_str());
#ifndef WINDOWS
- std::ofstream out_file(file_info.string(), std::ios::out | std::ios::trunc);
+ std::ofstream out_file(file_info.u8string(), std::ios::out | std::ios::trunc);
#else
std::ofstream out_file(file_info.wstring().c_str(),
std::ios::out | std::ios::trunc);
@@ -155,7 +155,7 @@ std::string GpgFrontend::get_file_extension(const std::string& path) {
// Check if file name in the path object has extension
if (path_obj.has_extension()) {
// Fetch the extension from path object and return
- return path_obj.extension().string();
+ return path_obj.extension().u8string();
}
// In case of no extension return empty string
return {};
@@ -167,7 +167,7 @@ std::string GpgFrontend::get_only_file_name_with_path(const std::string& path) {
// Check if file name in the path object has extension
if (path_obj.has_filename()) {
// Fetch the extension from path object and return
- return (path_obj.parent_path() / path_obj.stem()).string();
+ return (path_obj.parent_path() / path_obj.stem()).u8string();
}
// In case of no extension return empty string
return {};
diff --git a/src/core/function/ArchiveFileOperator.cpp b/src/core/function/ArchiveFileOperator.cpp
index 6315dcd5..dd7fbcf6 100644
--- a/src/core/function/ArchiveFileOperator.cpp
+++ b/src/core/function/ArchiveFileOperator.cpp
@@ -54,10 +54,10 @@ void GpgFrontend::ArchiveFileOperator::CreateArchive(
const std::filesystem::path &base_path,
const std::filesystem::path &archive_path, int compress,
const std::vector<std::filesystem::path> &files) {
- LOG(INFO) << "CreateArchive: " << archive_path.string();
+ LOG(INFO) << "CreateArchive: " << archive_path.u8string();
auto current_base_path_backup = QDir::currentPath();
- QDir::setCurrent(base_path.string().c_str());
+ QDir::setCurrent(base_path.u8string().c_str());
auto relative_archive_path = std::filesystem::relative(archive_path, base_path);
@@ -99,7 +99,7 @@ void GpgFrontend::ArchiveFileOperator::CreateArchive(
archive_write_set_format_ustar(a);
archive_write_set_format_pax_restricted(a);
- auto filename = relative_archive_path.string();
+ auto filename = relative_archive_path.u8string();
if (!filename.empty() && filename == "-")
throw std::runtime_error("cannot write to stdout");
@@ -112,9 +112,9 @@ void GpgFrontend::ArchiveFileOperator::CreateArchive(
#endif
int r;
- LOG(INFO) << "ReadFile: " << file.string();
+ LOG(INFO) << "ReadFile: " << file.u8string();
- r = archive_read_disk_open(disk, file.string().c_str());
+ r = archive_read_disk_open(disk, file.u8string().c_str());
if (r != ARCHIVE_OK) {
LOG(ERROR) << "archive_read_disk_open() failed: "
<< archive_error_string(disk);
@@ -163,10 +163,10 @@ void GpgFrontend::ArchiveFileOperator::ExtractArchive(
const std::filesystem::path &archive_path,
const std::filesystem::path &base_path) {
- LOG(INFO) << "ExtractArchive: " << archive_path.string();
+ LOG(INFO) << "ExtractArchive: " << archive_path.u8string();
auto current_base_path_backup = QDir::currentPath();
- QDir::setCurrent(base_path.string().c_str());
+ QDir::setCurrent(base_path.u8string().c_str());
struct archive *a;
struct archive *ext;
@@ -195,12 +195,16 @@ void GpgFrontend::ArchiveFileOperator::ExtractArchive(
archive_write_disk_set_standard_lookup(ext);
#endif
- auto filename = archive_path.string();
+ auto filename = archive_path.u8string();
- if (!filename.empty() && filename == "-") {
+ if (!filename.empty() && filename == u8"-") {
LOG(ERROR) << "cannot read from stdin";
}
- if ((r = archive_read_open_filename(a, filename.c_str(), 10240))) {
+#ifdef WINDOWS
+ if ((r = archive_read_open_filename_w(a, archive_path.wstring().c_str(), 10240))) {
+#else
+ if ((r = archive_read_open_filename(a, archive_path.u8string().c_str(), 10240))) {
+#endif
LOG(ERROR) << "archive_read_open_filename() failed: "
<< archive_error_string(a);
throw std::runtime_error("archive_read_open_filename() failed");
diff --git a/src/core/function/ArchiveFileOperator.h b/src/core/function/ArchiveFileOperator.h
index 8e1d9c44..c86c6f69 100644
--- a/src/core/function/ArchiveFileOperator.h
+++ b/src/core/function/ArchiveFileOperator.h
@@ -52,7 +52,7 @@ class ArchiveFileOperator {
a = archive_read_new();
archive_read_support_filter_all(a);
archive_read_support_format_all(a);
- r = archive_read_open_filename(a, archive_path.string().c_str(),
+ r = archive_read_open_filename(a, archive_path.u8string().c_str(),
10240); // Note 1
if (r != ARCHIVE_OK) return;
while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
diff --git a/src/core/function/DataObjectOperator.cpp b/src/core/function/DataObjectOperator.cpp
index a3f7fc70..1e216dd6 100644
--- a/src/core/function/DataObjectOperator.cpp
+++ b/src/core/function/DataObjectOperator.cpp
@@ -51,7 +51,7 @@ GpgFrontend::DataObjectOperator::DataObjectOperator(int channel)
}
std::string key;
- if (!FileOperator::ReadFileStd(app_secure_key_path_.string(), key)) {
+ if (!FileOperator::ReadFileStd(app_secure_key_path_.u8string(), key)) {
LOG(FATAL) << _("Failed to read app secure key file")
<< app_secure_key_path_;
throw std::runtime_error(_("Failed to read app secure key file"));
@@ -94,7 +94,7 @@ std::string GpgFrontend::DataObjectOperator::SaveDataObj(
LOG(INFO) << _("Saving data object") << _hash_obj_key << "to" << obj_path << encoded.size() << "bytes";
- FileOperator::WriteFileStd(obj_path.string(), encoded.toStdString());
+ FileOperator::WriteFileStd(obj_path.u8string(), encoded.toStdString());
return _key.empty() ? _hash_obj_key : std::string();
}
@@ -117,7 +117,7 @@ std::optional<nlohmann::json> GpgFrontend::DataObjectOperator::GetDataObject(
}
std::string buffer;
- if (!FileOperator::ReadFileStd(obj_path.string(), buffer)) {
+ if (!FileOperator::ReadFileStd(obj_path.u8string(), buffer)) {
LOG(ERROR) << _("Failed to read data object") << _key;
return {};
}
@@ -153,7 +153,7 @@ GpgFrontend::DataObjectOperator::GetDataObjectByRef(const std::string& _ref) {
if (!std::filesystem::exists(obj_path)) return {};
std::string buffer;
- if (!FileOperator::ReadFileStd(obj_path.string(), buffer)) return {};
+ if (!FileOperator::ReadFileStd(obj_path.u8string(), buffer)) return {};
auto encoded = QByteArray::fromStdString(buffer);
QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::ECB,
diff --git a/src/core/function/FileOperator.cpp b/src/core/function/FileOperator.cpp
index d0a3df23..4977b3a9 100644
--- a/src/core/function/FileOperator.cpp
+++ b/src/core/function/FileOperator.cpp
@@ -55,15 +55,18 @@ bool GpgFrontend::FileOperator::WriteFile(const QString& file_name,
bool GpgFrontend::FileOperator::ReadFileStd(
const std::filesystem::path& file_name, std::string& data) {
QByteArray byte_data;
- bool res = ReadFile(QString::fromStdString(file_name.string()), byte_data);
+#ifdef WINDOWS
+ bool res = ReadFile(QString::fromStdU16String(file_name.u16string()).toUtf8(), byte_data);
+#else
+ bool res = ReadFile(QString::fromStdString(file_name.u8string()).toUtf8(), byte_data);
+#endif
data = byte_data.toStdString();
return res;
}
bool GpgFrontend::FileOperator::WriteFileStd(
const std::filesystem::path& file_name, const std::string& data) {
- return WriteFile(QString::fromStdString(file_name.string()),
- QByteArray::fromStdString(data));
+ return WriteFile(QString::fromStdString(file_name.u8string()).toUtf8(), QByteArray::fromStdString(data));
}
std::string GpgFrontend::FileOperator::CalculateHash(
@@ -75,7 +78,7 @@ std::string GpgFrontend::FileOperator::CalculateHash(
if (info.isFile() && info.isReadable()) {
ss << "[#] " << _("File Hash Information") << std::endl;
ss << " " << _("filename") << _(": ")
- << file_path.filename().string().c_str() << std::endl;
+ << file_path.filename().u8string().c_str() << std::endl;
QFile f(info.filePath());
diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp
index 7b3e868e..43b5b884 100644
--- a/src/core/function/GlobalSettingStation.cpp
+++ b/src/core/function/GlobalSettingStation.cpp
@@ -39,7 +39,7 @@
void GpgFrontend::GlobalSettingStation::SyncSettings() noexcept {
using namespace libconfig;
try {
- ui_cfg_.writeFile(ui_config_path_.string().c_str());
+ ui_cfg_.writeFile(ui_config_path_.u8string().c_str());
LOG(INFO) << _("Updated ui configuration successfully written to")
<< ui_config_path_;
@@ -72,7 +72,7 @@ GpgFrontend::GlobalSettingStation::GlobalSettingStation(int channel) noexcept
if (!exists(ui_config_path_)) {
try {
- this->ui_cfg_.writeFile(ui_config_path_.string().c_str());
+ this->ui_cfg_.writeFile(ui_config_path_.u8string().c_str());
LOG(INFO) << _("UserInterface configuration successfully written to")
<< ui_config_path_;
@@ -83,7 +83,7 @@ GpgFrontend::GlobalSettingStation::GlobalSettingStation(int channel) noexcept
}
} else {
try {
- this->ui_cfg_.readFile(ui_config_path_.string().c_str());
+ this->ui_cfg_.readFile(ui_config_path_.u8string().c_str());
LOG(INFO) << _("UserInterface configuration successfully read from")
<< ui_config_path_;
} catch (const FileIOException &fioex) {
@@ -98,7 +98,7 @@ GpgFrontend::GlobalSettingStation::GlobalSettingStation(int channel) noexcept
void GpgFrontend::GlobalSettingStation::AddRootCert(
const std::filesystem::path &path) {
std::string out_buffer;
- if (!FileOperator::ReadFileStd(path.string(), out_buffer)) {
+ if (!FileOperator::ReadFileStd(path.u8string(), out_buffer)) {
LOG(ERROR) << _("Failed to read root certificate file") << path;
return;
}
diff --git a/src/core/function/KeyPackageOperator.cpp b/src/core/function/KeyPackageOperator.cpp
index 2b2802f7..67fa3fac 100644
--- a/src/core/function/KeyPackageOperator.cpp
+++ b/src/core/function/KeyPackageOperator.cpp
@@ -73,13 +73,13 @@ bool KeyPackageOperator::ImportKeyPackage(
const std::filesystem::path& phrase_path,
GpgFrontend::GpgImportInformation& import_info) {
- LOG(INFO) << "Importing key package: " << key_package_path.string();
+ LOG(INFO) << "Importing key package: " << key_package_path.u8string();
std::string encrypted_data;
FileOperator::ReadFileStd(key_package_path, encrypted_data);
if (encrypted_data.empty()) {
- LOG(ERROR) << "Failed to read key package: " << key_package_path.string();
+ LOG(ERROR) << "Failed to read key package: " << key_package_path.u8string();
return false;
};
@@ -87,7 +87,7 @@ bool KeyPackageOperator::ImportKeyPackage(
FileOperator::ReadFileStd(phrase_path, passphrase);
LOG(INFO) << "Passphrase: " << passphrase.size() << " bytes";
if (passphrase.size() != 256) {
- LOG(ERROR) << "Failed to read passphrase: " << phrase_path.string();
+ LOG(ERROR) << "Failed to read passphrase: " << phrase_path.u8string();
return false;
}
diff --git a/src/core/function/gpg/GpgFileOpera.cpp b/src/core/function/gpg/GpgFileOpera.cpp
index 7044353b..25357288 100644
--- a/src/core/function/gpg/GpgFileOpera.cpp
+++ b/src/core/function/gpg/GpgFileOpera.cpp
@@ -38,17 +38,26 @@ GpgFrontend::GpgError GpgFrontend::GpgFileOpera::EncryptFile(
KeyListPtr keys, const std::string& in_path, const std::string& out_path,
GpgEncrResult& result, int _channel) {
+#ifdef WINDOWS
+ auto in_path_std = std::filesystem::path(QString::fromStdString(in_path).toStdU16String());
+ auto out_path_std = std::filesystem::path(QString::fromStdString(out_path).toStdU16String());
+#else
+ auto in_path_std = std::filesystem::path(in_path);
+ auto out_path_std = std::filesystem::path(out_path);
+#endif
+
std::string in_buffer;
- if(!FileOperator::ReadFileStd(in_path, in_buffer)) {
+ if(!FileOperator::ReadFileStd(in_path_std, in_buffer)) {
throw std::runtime_error("read file error");
}
+
std::unique_ptr<std::string> out_buffer = nullptr;
auto err = GpgBasicOperator::GetInstance(_channel).Encrypt(
std::move(keys), in_buffer, out_buffer, result);
if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR)
- if (!FileOperator::WriteFileStd(out_path, *out_buffer)) {
+ if (!FileOperator::WriteFileStd(out_path_std, *out_buffer)) {
throw std::runtime_error("write_buffer_to_file error");
};
@@ -58,8 +67,17 @@ GpgFrontend::GpgError GpgFrontend::GpgFileOpera::EncryptFile(
GpgFrontend::GpgError GpgFrontend::GpgFileOpera::DecryptFile(
const std::string& in_path, const std::string& out_path,
GpgDecrResult& result) {
+
+#ifdef WINDOWS
+ auto in_path_std = std::filesystem::path(QString::fromStdString(in_path).toStdU16String());
+ auto out_path_std = std::filesystem::path(QString::fromStdString(out_path).toStdU16String());
+#else
+ auto in_path_std = std::filesystem::path(in_path);
+ auto out_path_std = std::filesystem::path(out_path);
+#endif
+
std::string in_buffer;
- if(!FileOperator::ReadFileStd(in_path, in_buffer)) {
+ if(!FileOperator::ReadFileStd(in_path_std, in_buffer)) {
throw std::runtime_error("read file error");
}
std::unique_ptr<std::string> out_buffer;
@@ -70,7 +88,7 @@ GpgFrontend::GpgError GpgFrontend::GpgFileOpera::DecryptFile(
assert(check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR);
if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR)
- if (!FileOperator::WriteFileStd(out_path, *out_buffer)) {
+ if (!FileOperator::WriteFileStd(out_path_std, *out_buffer)) {
throw std::runtime_error("write_buffer_to_file error");
};
@@ -82,8 +100,17 @@ gpgme_error_t GpgFrontend::GpgFileOpera::SignFile(KeyListPtr keys,
const std::string& out_path,
GpgSignResult& result,
int _channel) {
+
+#ifdef WINDOWS
+ auto in_path_std = std::filesystem::path(QString::fromStdString(in_path).toStdU16String());
+ auto out_path_std = std::filesystem::path(QString::fromStdString(out_path).toStdU16String());
+#else
+ auto in_path_std = std::filesystem::path(in_path);
+ auto out_path_std = std::filesystem::path(out_path);
+#endif
+
std::string in_buffer;
- if(!FileOperator::ReadFileStd(in_path, in_buffer)) {
+ if(!FileOperator::ReadFileStd(in_path_std, in_buffer)) {
throw std::runtime_error("read file error");
}
std::unique_ptr<std::string> out_buffer;
@@ -92,7 +119,7 @@ gpgme_error_t GpgFrontend::GpgFileOpera::SignFile(KeyListPtr keys,
std::move(keys), in_buffer, out_buffer, GPGME_SIG_MODE_DETACH, result);
if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR)
- if (!FileOperator::WriteFileStd(out_path, *out_buffer)) {
+ if (!FileOperator::WriteFileStd(out_path_std, *out_buffer)) {
throw std::runtime_error("write_buffer_to_file error");
};
@@ -102,14 +129,23 @@ gpgme_error_t GpgFrontend::GpgFileOpera::SignFile(KeyListPtr keys,
gpgme_error_t GpgFrontend::GpgFileOpera::VerifyFile(
const std::string& data_path, const std::string& sign_path,
GpgVerifyResult& result, int _channel) {
+
+#ifdef WINDOWS
+ auto data_path_std = std::filesystem::path(QString::fromStdString(data_path).toStdU16String());
+ auto sign_path_std = std::filesystem::path(QString::fromStdString(sign_path).toStdU16String());
+#else
+ auto data_path_std = std::filesystem::path(data_path);
+ auto sign_path_std = std::filesystem::path(sign_path);
+#endif
+
std::string in_buffer;
- if(!FileOperator::ReadFileStd(data_path, in_buffer)) {
+ if(!FileOperator::ReadFileStd(data_path_std, in_buffer)) {
throw std::runtime_error("read file error");
}
std::unique_ptr<std::string> sign_buffer = nullptr;
if (!sign_path.empty()) {
std::string sign_buffer_str;
- if (!FileOperator::ReadFileStd(sign_path, sign_buffer_str)) {
+ if (!FileOperator::ReadFileStd(sign_path_std, sign_buffer_str)) {
throw std::runtime_error("read file error");
}
sign_buffer =
@@ -124,8 +160,17 @@ gpg_error_t GpgFrontend::GpgFileOpera::EncryptSignFile(
KeyListPtr keys, KeyListPtr signer_keys, const std::string& in_path,
const std::string& out_path, GpgEncrResult& encr_res,
GpgSignResult& sign_res, int _channel) {
+
+#ifdef WINDOWS
+ auto in_path_std = std::filesystem::path(QString::fromStdString(in_path).toStdU16String());
+ auto out_path_std = std::filesystem::path(QString::fromStdString(out_path).toStdU16String());
+#else
+ auto in_path_std = std::filesystem::path(in_path);
+ auto out_path_std = std::filesystem::path(out_path);
+#endif
+
std::string in_buffer;
- if(!FileOperator::ReadFileStd(in_path, in_buffer)) {
+ if(!FileOperator::ReadFileStd(in_path_std, in_buffer)) {
throw std::runtime_error("read file error");
}
std::unique_ptr<std::string> out_buffer = nullptr;
@@ -135,7 +180,7 @@ gpg_error_t GpgFrontend::GpgFileOpera::EncryptSignFile(
sign_res);
if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR)
- if (!FileOperator::WriteFileStd(out_path, *out_buffer)) {
+ if (!FileOperator::WriteFileStd(out_path_std, *out_buffer)) {
throw std::runtime_error("write_buffer_to_file error");
};
@@ -145,8 +190,17 @@ gpg_error_t GpgFrontend::GpgFileOpera::EncryptSignFile(
gpg_error_t GpgFrontend::GpgFileOpera::DecryptVerifyFile(
const std::string& in_path, const std::string& out_path,
GpgDecrResult& decr_res, GpgVerifyResult& verify_res) {
+
+#ifdef WINDOWS
+ auto in_path_std = std::filesystem::path(QString::fromStdString(in_path).toStdU16String());
+ auto out_path_std = std::filesystem::path(QString::fromStdString(out_path).toStdU16String());
+#else
+ auto in_path_std = std::filesystem::path(in_path);
+ auto out_path_std = std::filesystem::path(out_path);
+#endif
+
std::string in_buffer;
- if(!FileOperator::ReadFileStd(in_path, in_buffer)) {
+ if(!FileOperator::ReadFileStd(in_path_std, in_buffer)) {
throw std::runtime_error("read file error");
}
@@ -155,7 +209,7 @@ gpg_error_t GpgFrontend::GpgFileOpera::DecryptVerifyFile(
decr_res, verify_res);
if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR)
- if (!FileOperator::WriteFileStd(out_path, *out_buffer)) {
+ if (!FileOperator::WriteFileStd(out_path_std, *out_buffer)) {
throw std::runtime_error("write file error");
};
@@ -164,8 +218,17 @@ gpg_error_t GpgFrontend::GpgFileOpera::DecryptVerifyFile(
unsigned int GpgFrontend::GpgFileOpera::EncryptFileSymmetric(
const std::string& in_path, const std::string& out_path,
GpgFrontend::GpgEncrResult& result, int _channel) {
+
+#ifdef WINDOWS
+ auto in_path_std = std::filesystem::path(QString::fromStdString(in_path).toStdU16String());
+ auto out_path_std = std::filesystem::path(QString::fromStdString(out_path).toStdU16String());
+#else
+ auto in_path_std = std::filesystem::path(in_path);
+ auto out_path_std = std::filesystem::path(out_path);
+#endif
+
std::string in_buffer;
- if(!FileOperator::ReadFileStd(in_path, in_buffer)) {
+ if(!FileOperator::ReadFileStd(in_path_std, in_buffer)) {
throw std::runtime_error("read file error");
}
@@ -174,7 +237,7 @@ unsigned int GpgFrontend::GpgFileOpera::EncryptFileSymmetric(
in_buffer, out_buffer, result);
if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR)
- if (!FileOperator::WriteFileStd(out_path, *out_buffer)) {
+ if (!FileOperator::WriteFileStd(out_path_std, *out_buffer)) {
throw std::runtime_error("write_buffer_to_file error");
};
diff --git a/src/init.cpp b/src/init.cpp
index ccfeca90..f5bbb750 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -76,7 +76,7 @@ void init_logging() {
to_iso_string(now));
logfile_path.replace_extension(".log");
defaultConf.setGlobally(el::ConfigurationType::Filename,
- logfile_path.string());
+ logfile_path.u8string());
el::Loggers::reconfigureLogger("default", defaultConf);
@@ -179,7 +179,7 @@ void init_locale() {
bindtextdomain(PROJECT_NAME,
GpgFrontend::GlobalSettingStation::GetInstance()
.GetLocaleDir()
- .string()
+ .u8string()
.c_str());
bind_textdomain_codeset(PROJECT_NAME, "utf-8");
textdomain(PROJECT_NAME);
diff --git a/src/main.cpp b/src/main.cpp
index 3f72be7f..a63d2d02 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -135,7 +135,7 @@ int main(int argc, char* argv[]) {
std::filesystem::path css_path =
GpgFrontend::GlobalSettingStation::GetInstance().GetResourceDir() /
"css" / "default.qss";
- QFile file(css_path.string().c_str());
+ QFile file(css_path.u8string().c_str());
file.open(QFile::ReadOnly);
QString styleSheet = QLatin1String(file.readAll());
qApp->setStyleSheet(styleSheet);
@@ -151,8 +151,8 @@ int main(int argc, char* argv[]) {
GpgFrontend::GpgContext::CreateInstance(
GpgFrontend::SingletonFunctionObject<
GpgFrontend::GpgContext>::GetDefaultChannel(),
- std::make_unique<GpgFrontend::GpgContext>(true, db_path.string(), true,
- gpg_path.string()));
+ std::make_unique<GpgFrontend::GpgContext>(true, db_path.u8string(), true,
+ gpg_path.u8string()));
#endif
// create the thread to load the gpg context
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());
}
diff --git a/test/GpgFrontendTest.h b/test/GpgFrontendTest.h
index 15efb650..ebd5e33a 100644
--- a/test/GpgFrontendTest.h
+++ b/test/GpgFrontendTest.h
@@ -168,8 +168,8 @@ class GpgCoreTest : public ::testing::Test {
GpgFrontend::GpgContextInitArgs args;
args.gpg_alone = true;
args.independent_database = true;
- args.db_path = db_path.string();
- args.gpg_path = gpg_path.string();
+ args.db_path = db_path.u8string();
+ args.gpg_path = gpg_path.u8string();
args.test_mode = true;
return std::make_unique<GpgFrontend::GpgContext>(args);
});