From 7f88c51d6788c9eabddaa44161b1b449ba50f53d Mon Sep 17 00:00:00 2001 From: zalox Date: Mon, 2 Nov 2015 14:39:00 +0100 Subject: [PATCH] Intermediate commit, please ignore --- src/CMakeLists.txt | 3 ++- src/dialogs.h | 12 +++++++----- src/dialogs_win.cc | 28 +++++++++++----------------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e66417f..6df0f15 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,7 +28,8 @@ find_package(LibClang REQUIRED) #find_package(PythonLibs 2.7) #find_package(Boost 1.55 COMPONENTS python thread log system filesystem REQUIRED) -find_package(Boost 1.55 COMPONENTS thread log system filesystem REQUIRED) + +find_package(Boost 1.55 COMPONENTS thread log system filesystem locale REQUIRED) pkg_check_modules(GTKMM gtkmm-3.0 REQUIRED) # The name GTKMM is set here for the variables abouve diff --git a/src/dialogs.h b/src/dialogs.h index 92638f5..fe64b2b 100644 --- a/src/dialogs.h +++ b/src/dialogs.h @@ -21,6 +21,7 @@ class Dialog { #include #include #include +#include class WinString { public: @@ -29,10 +30,11 @@ public: ~WinString() { CoTaskMemFree(static_cast(str)); } std::string operator()(); wchar_t** operator&() { return &str; } + static std::wstring s2ws(const std::string& str); + static std::string ws2s(const std::wstring& wstr); + private: wchar_t* str; - std::wstring s2ws(const std::string& str); - std::string ws2s(const std::wstring& wstr); }; class CommonDialog { @@ -42,7 +44,7 @@ public: void add_option(unsigned option); void set_title(const std::string &title); /** Sets the extensions the browser can find */ - void set_file_extensions(const std::vector file_extensions); + void set_file_extensions(const std::vector &file_extensions); /** Sets the directory to start browsing */ void set_default_folder(const std::string &directory_path); /** Returns the selected item's path as a string */ @@ -55,11 +57,11 @@ private: class OpenDialog : public CommonDialog { public: - OpenDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileOpenDialog); + OpenDialog(const std::string &title, unsigned option); }; class SaveDialog : public CommonDialog { public: - SaveDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileSaveDialog); + SaveDialog(const std::string &title, unsigned option); }; #endif // __WIN32 diff --git a/src/dialogs_win.cc b/src/dialogs_win.cc index 22db8fa..b74338a 100644 --- a/src/dialogs_win.cc +++ b/src/dialogs_win.cc @@ -1,7 +1,7 @@ #ifdef _WIN32 #include "dialogs.h" #include "singletons.h" - +#include #ifndef check HRESULT __hr__; #define check(__fun__, error_message) \ @@ -29,17 +29,12 @@ std::string WinString::operator()() { return res; } -// http://stackoverflow.com/questions/4804298/how-to-convert-wstring-into-string std::wstring WinString::s2ws(const std::string& str) { - typedef std::codecvt_utf8 convert_typeX; - std::wstring_convert converterX; - return converterX.from_bytes(str); + return boost::locale::conv::utf_to_utf(str); } std::string WinString::ws2s(const std::wstring& wstr) { - typedef std::codecvt_utf8 convert_typeX; - std::wstring_convert converterX; - return converterX.to_bytes(wstr); + return boost::locale::conv::utf_to_utf(wstr); } // WINSTRING } @@ -51,9 +46,7 @@ CommonDialog::CommonDialog(CLSID type) : dialog(nullptr) { } void CommonDialog::set_title(const std::string &title) { - auto tmp = std::wstring(title.begin(), title.end()); - auto t = tmp.data(); - check(dialog->SetTitle(t), "Failed to set dialog title"); + check(dialog->SetTitle(), "Failed to set dialog title"); } void CommonDialog::add_option(unsigned option) { @@ -65,10 +58,11 @@ void CommonDialog::set_file_extensions(const std::vector &file_exte } void CommonDialog::set_default_folder(const std::string &directory_path) { + std::cout << directory_path << std::endl; IShellItem * folder = nullptr; - WinString str; - &str = (str.s2ws(directory_path)).data(); - check(SHCreateItemFromParsingName(&str, NULL, IID_PPV_ARGS(&folder)), "Failed to create string"); + auto dir = WinString::s2ws(directory_path); + std::wcout << dir << std::endl; + check(SHCreateItemFromParsingName(dir.data(), nullptr, IID_PPV_ARGS(&folder)), "Failed to create string"); check(dialog->SetDefaultFolder(folder), "Failed to set default folder"); folder->Release(); } @@ -87,18 +81,18 @@ std::string CommonDialog::show() { } } -OpenDialog::OpenDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileOpenDialog); { +OpenDialog::OpenDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileOpenDialog) { set_title(title); add_option(option); auto dirs = Singleton::directories()->current_path; - set_default_folder(dirs.empty() ? boost::filesystem::current_path() : dirs); + set_default_folder(dirs.empty() ? boost::filesystem::current_path().string() : dirs.string()); } SaveDialog::SaveDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileSaveDialog) { set_title(title); add_option(option); auto dirs = Singleton::directories()->current_path; - set_default_folder(dirs.empty() ? boost::filesystem::current_path() : dirs); + set_default_folder(dirs.empty() ? boost::filesystem::current_path().string() : dirs.string()); } // DIALOGS }}