diff --git a/gsmartcontrol/Makefile.am b/gsmartcontrol/Makefile.am index ecb27fb..41b7ea5 100644 --- a/gsmartcontrol/Makefile.am +++ b/gsmartcontrol/Makefile.am @@ -156,37 +156,37 @@ win-dist-prepare: all # $(MKDIR_P) win-dist/share/icons # cp -p "@WINDOWS_SYSROOT@"/share/icons/hicolor win-dist/share/icons -# needed for window titlebar - $(MKDIR_P) win-dist/share/icons/Adwaita/16x16/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/16x16/actions/window-close-symbolic.symbolic.png win-dist/share/icons/Adwaita/16x16/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/16x16/actions/window-maximize-symbolic.symbolic.png win-dist/share/icons/Adwaita/16x16/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/16x16/actions/window-minimize-symbolic.symbolic.png win-dist/share/icons/Adwaita/16x16/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/16x16/actions/window-restore-symbolic.symbolic.png win-dist/share/icons/Adwaita/16x16/actions - $(MKDIR_P) win-dist/share/icons/Adwaita/24x24/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/24x24/actions/window-close-symbolic.symbolic.png win-dist/share/icons/Adwaita/24x24/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/24x24/actions/window-maximize-symbolic.symbolic.png win-dist/share/icons/Adwaita/24x24/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/24x24/actions/window-minimize-symbolic.symbolic.png win-dist/share/icons/Adwaita/24x24/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/24x24/actions/window-restore-symbolic.symbolic.png win-dist/share/icons/Adwaita/24x24/actions - $(MKDIR_P) win-dist/share/icons/Adwaita/32x32/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/32x32/actions/window-close-symbolic.symbolic.png win-dist/share/icons/Adwaita/32x32/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/32x32/actions/window-maximize-symbolic.symbolic.png win-dist/share/icons/Adwaita/32x32/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/32x32/actions/window-minimize-symbolic.symbolic.png win-dist/share/icons/Adwaita/32x32/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/32x32/actions/window-restore-symbolic.symbolic.png win-dist/share/icons/Adwaita/32x32/actions - $(MKDIR_P) win-dist/share/icons/Adwaita/48x48/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/48x48/actions/window-close-symbolic.symbolic.png win-dist/share/icons/Adwaita/48x48/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/48x48/actions/window-maximize-symbolic.symbolic.png win-dist/share/icons/Adwaita/48x48/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/48x48/actions/window-minimize-symbolic.symbolic.png win-dist/share/icons/Adwaita/48x48/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/48x48/actions/window-restore-symbolic.symbolic.png win-dist/share/icons/Adwaita/48x48/actions - $(MKDIR_P) win-dist/share/icons/Adwaita/64x64/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/64x64/actions/window-close-symbolic.symbolic.png win-dist/share/icons/Adwaita/64x64/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/64x64/actions/window-maximize-symbolic.symbolic.png win-dist/share/icons/Adwaita/64x64/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/64x64/actions/window-minimize-symbolic.symbolic.png win-dist/share/icons/Adwaita/64x64/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/64x64/actions/window-restore-symbolic.symbolic.png win-dist/share/icons/Adwaita/64x64/actions - $(MKDIR_P) win-dist/share/icons/Adwaita/96x96/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/96x96/actions/window-close-symbolic.symbolic.png win-dist/share/icons/Adwaita/96x96/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/96x96/actions/window-maximize-symbolic.symbolic.png win-dist/share/icons/Adwaita/96x96/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/96x96/actions/window-minimize-symbolic.symbolic.png win-dist/share/icons/Adwaita/96x96/actions - cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/96x96/actions/window-restore-symbolic.symbolic.png win-dist/share/icons/Adwaita/96x96/actions +# needed for window titlebar (if using client-side decorations) +# $(MKDIR_P) win-dist/share/icons/Adwaita/16x16/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/16x16/actions/window-close-symbolic.symbolic.png win-dist/share/icons/Adwaita/16x16/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/16x16/actions/window-maximize-symbolic.symbolic.png win-dist/share/icons/Adwaita/16x16/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/16x16/actions/window-minimize-symbolic.symbolic.png win-dist/share/icons/Adwaita/16x16/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/16x16/actions/window-restore-symbolic.symbolic.png win-dist/share/icons/Adwaita/16x16/actions +# $(MKDIR_P) win-dist/share/icons/Adwaita/24x24/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/24x24/actions/window-close-symbolic.symbolic.png win-dist/share/icons/Adwaita/24x24/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/24x24/actions/window-maximize-symbolic.symbolic.png win-dist/share/icons/Adwaita/24x24/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/24x24/actions/window-minimize-symbolic.symbolic.png win-dist/share/icons/Adwaita/24x24/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/24x24/actions/window-restore-symbolic.symbolic.png win-dist/share/icons/Adwaita/24x24/actions +# $(MKDIR_P) win-dist/share/icons/Adwaita/32x32/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/32x32/actions/window-close-symbolic.symbolic.png win-dist/share/icons/Adwaita/32x32/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/32x32/actions/window-maximize-symbolic.symbolic.png win-dist/share/icons/Adwaita/32x32/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/32x32/actions/window-minimize-symbolic.symbolic.png win-dist/share/icons/Adwaita/32x32/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/32x32/actions/window-restore-symbolic.symbolic.png win-dist/share/icons/Adwaita/32x32/actions +# $(MKDIR_P) win-dist/share/icons/Adwaita/48x48/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/48x48/actions/window-close-symbolic.symbolic.png win-dist/share/icons/Adwaita/48x48/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/48x48/actions/window-maximize-symbolic.symbolic.png win-dist/share/icons/Adwaita/48x48/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/48x48/actions/window-minimize-symbolic.symbolic.png win-dist/share/icons/Adwaita/48x48/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/48x48/actions/window-restore-symbolic.symbolic.png win-dist/share/icons/Adwaita/48x48/actions +# $(MKDIR_P) win-dist/share/icons/Adwaita/64x64/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/64x64/actions/window-close-symbolic.symbolic.png win-dist/share/icons/Adwaita/64x64/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/64x64/actions/window-maximize-symbolic.symbolic.png win-dist/share/icons/Adwaita/64x64/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/64x64/actions/window-minimize-symbolic.symbolic.png win-dist/share/icons/Adwaita/64x64/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/64x64/actions/window-restore-symbolic.symbolic.png win-dist/share/icons/Adwaita/64x64/actions +# $(MKDIR_P) win-dist/share/icons/Adwaita/96x96/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/96x96/actions/window-close-symbolic.symbolic.png win-dist/share/icons/Adwaita/96x96/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/96x96/actions/window-maximize-symbolic.symbolic.png win-dist/share/icons/Adwaita/96x96/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/96x96/actions/window-minimize-symbolic.symbolic.png win-dist/share/icons/Adwaita/96x96/actions +# cp -p "@WINDOWS_SYSROOT@"/share/icons/Adwaita/96x96/actions/window-restore-symbolic.symbolic.png win-dist/share/icons/Adwaita/96x96/actions # other cp -p "@WINDOWS_SYSROOT@"/bin/libgcc_s_*.dll win-dist/ diff --git a/gsmartcontrol/src/applib/app_gtkmm_utils.cpp b/gsmartcontrol/src/applib/app_gtkmm_utils.cpp index a578020..201f3b4 100644 --- a/gsmartcontrol/src/applib/app_gtkmm_utils.cpp +++ b/gsmartcontrol/src/applib/app_gtkmm_utils.cpp @@ -129,6 +129,18 @@ namespace { +Glib::ustring app_ustring_from_gchar(gchar* str) +{ + if (!str) { + return Glib::ustring(); + } + Glib::ustring ustr(str); + g_free(str); + return ustr; +} + + + Glib::ustring app_utf8_make_valid(const Glib::ustring& str) { char* s = gsc_g_utf8_make_valid(str.c_str()); diff --git a/gsmartcontrol/src/applib/app_gtkmm_utils.h b/gsmartcontrol/src/applib/app_gtkmm_utils.h index 5463510..622b043 100644 --- a/gsmartcontrol/src/applib/app_gtkmm_utils.h +++ b/gsmartcontrol/src/applib/app_gtkmm_utils.h @@ -73,6 +73,10 @@ bool app_gtkmm_icon_theme_has_icon(Glib::RefPtr theme, const Glib::ustring& icon_name, int size); +/// Get Glib::ustring from gchar*, freeing gchar*. +Glib::ustring app_ustring_from_gchar(gchar* str); + + /// Convert a possibly invalid utf-8 string to valid utf-8. /// \param str string to test and fix. Glib::ustring app_utf8_make_valid(const Glib::ustring& str); diff --git a/gsmartcontrol/src/gsc_add_device_window.cpp b/gsmartcontrol/src/gsc_add_device_window.cpp index d71eefe..03963ca 100644 --- a/gsmartcontrol/src/gsc_add_device_window.cpp +++ b/gsmartcontrol/src/gsc_add_device_window.cpp @@ -11,9 +11,11 @@ #include #include // GDK_KEY_Escape +#include #include "hz/fs_path.h" #include "hz/string_sprintf.h" +#include "hz/scoped_ptr.h" #include "applib/app_gtkmm_utils.h" #include "gsc_add_device_window.h" @@ -169,6 +171,20 @@ void GscAddDeviceWindow::on_device_name_browse_button_clicked() if (!entry) return; + hz::FsPath path(entry->get_text()); + + int result = 0; + +#if GTK_CHECK_VERSION(3, 20, 0) + hz::scoped_ptr dialog(gtk_file_chooser_native_new( + "Choose Device...", this->gobj(), GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL), g_object_unref); + + if (path.is_absolute()) + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog.get()), path.c_str()); + + result = gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog.get())); + +#else Gtk::FileChooserDialog dialog(*this, "Choose Device...", Gtk::FILE_CHOOSER_ACTION_OPEN); @@ -177,18 +193,24 @@ void GscAddDeviceWindow::on_device_name_browse_button_clicked() dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT); // Note: This works on absolute paths only (otherwise it's gtk warning). - hz::FsPath p(entry->get_text()); - if (p.is_absolute()) - dialog.set_filename(p.str()); // change to its dir and select it if exists. + if (path.is_absolute()) + dialog.set_filename(path.str()); // change to its dir and select it if exists. // Show the dialog and wait for a user response - int result = dialog.run(); // the main cycle blocks here + result = dialog.run(); // the main cycle blocks here +#endif // Handle the response switch (result) { case Gtk::RESPONSE_ACCEPT: { - entry->set_text(std::string(dialog.get_filename())); + Glib::ustring file; +#if GTK_CHECK_VERSION(3, 20, 0) + file = app_ustring_from_gchar(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog.get()))); +#else + file = dialog.get_filename(); // in fs encoding +#endif + entry->set_text(file); break; } diff --git a/gsmartcontrol/src/gsc_executor_log_window.cpp b/gsmartcontrol/src/gsc_executor_log_window.cpp index dbca2c1..d05714f 100644 --- a/gsmartcontrol/src/gsc_executor_log_window.cpp +++ b/gsmartcontrol/src/gsc_executor_log_window.cpp @@ -16,6 +16,7 @@ #include "applib/app_gtkmm_utils.h" // app_gtkmm_create_tree_view_column #include "applib/app_gtkmm_features.h" +#include "hz/scoped_ptr.h" #include "gsc_executor_log_window.h" #include "gsc_init.h" // app_get_debug_buffer_str() @@ -190,9 +191,21 @@ void GscExecutorLogWindow::on_window_save_current_button_clicked() Gtk::TreeIter iter = selection->get_selected(); CmdexSyncCommandInfoRefPtr entry = (*iter)[col_entry]; - static std::string last_dir; + int result = 0; +#if GTK_CHECK_VERSION(3, 20, 0) + hz::scoped_ptr dialog(gtk_file_chooser_native_new( + "Save Data As...", this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL), g_object_unref); + + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog.get()), true); + + if (!last_dir.empty()) + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog.get()), last_dir.c_str()); + + result = gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog.get())); + +#else Gtk::FileChooserDialog dialog(*this, "Save Data As...", Gtk::FILE_CHOOSER_ACTION_SAVE); @@ -206,15 +219,22 @@ void GscExecutorLogWindow::on_window_save_current_button_clicked() dialog.set_current_folder(last_dir); // Show the dialog and wait for a user response - int result = dialog.run(); // the main cycle blocks here + result = dialog.run(); // the main cycle blocks here +#endif // Handle the response switch (result) { case Gtk::RESPONSE_ACCEPT: { - last_dir = dialog.get_current_folder(); // safe for the future + std::string file; +#if GTK_CHECK_VERSION(3, 20, 0) + file = app_ustring_from_gchar(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog.get()))); + last_dir = hz::path_get_dirname(file); +#else + file = dialog.get_filename(); // in fs encoding + last_dir = dialog.get_current_folder(); // save for the future +#endif - std::string file = dialog.get_filename(); hz::File f(file); if (!f.put_contents(entry->std_output)) { gui_show_error_dialog("Cannot save data to file", f.get_error_utf8(), this); @@ -263,7 +283,20 @@ void GscExecutorLogWindow::on_window_save_all_button_clicked() static std::string last_dir; + int result = 0; +#if GTK_CHECK_VERSION(3, 20, 0) + hz::scoped_ptr dialog(gtk_file_chooser_native_new( + "Save Data As...", this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL), g_object_unref); + + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog.get()), true); + + if (!last_dir.empty()) + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog.get()), last_dir.c_str()); + + result = gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog.get())); + +#else Gtk::FileChooserDialog dialog(*this, "Save Data As...", Gtk::FILE_CHOOSER_ACTION_SAVE); @@ -278,14 +311,21 @@ void GscExecutorLogWindow::on_window_save_all_button_clicked() // Show the dialog and wait for a user response int result = dialog.run(); // the main cycle blocks here +#endif // Handle the response switch (result) { case Gtk::RESPONSE_ACCEPT: { - last_dir = dialog.get_current_folder(); // safe for the future + std::string file; +#if GTK_CHECK_VERSION(3, 20, 0) + file = app_ustring_from_gchar(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog.get()))); + last_dir = hz::path_get_dirname(file); +#else + file = dialog.get_filename(); // in fs encoding + last_dir = dialog.get_current_folder(); // save for the future +#endif - std::string file = dialog.get_filename(); hz::File f(file); if (!f.put_contents(exss.str())) { gui_show_error_dialog("Cannot save data to file", f.get_error_utf8(), this); diff --git a/gsmartcontrol/src/gsc_info_window.cpp b/gsmartcontrol/src/gsc_info_window.cpp index c212ee2..c1a7099 100644 --- a/gsmartcontrol/src/gsc_info_window.cpp +++ b/gsmartcontrol/src/gsc_info_window.cpp @@ -14,6 +14,7 @@ #include // better use vector, it's needed by others too #include // std::min, std::max +#include "hz/scoped_ptr.h" #include "hz/down_cast.h" #include "hz/string_num.h" // number_to_string #include "hz/string_sprintf.h" // string_sprintf @@ -1321,7 +1322,25 @@ void GscInfoWindow::on_view_output_button_clicked() void GscInfoWindow::on_save_info_button_clicked() { static std::string last_dir; + int result = 0; + std::string filename = drive->get_save_filename(); + +#if GTK_CHECK_VERSION(3, 20, 0) + hz::scoped_ptr dialog(gtk_file_chooser_native_new( + "Save Data As...", this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL), g_object_unref); + + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog.get()), true); + + if (!last_dir.empty()) + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog.get()), last_dir.c_str()); + + if (!filename.empty()) + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog.get()), filename.c_str()); + + result = gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog.get())); + +#else Gtk::FileChooserDialog dialog(*this, "Save Data As...", Gtk::FILE_CHOOSER_ACTION_SAVE); @@ -1334,21 +1353,26 @@ void GscInfoWindow::on_save_info_button_clicked() if (!last_dir.empty()) dialog.set_current_folder(last_dir); - std::string filename = drive->get_save_filename(); if (!filename.empty()) dialog.set_current_name(filename); - // Show the dialog and wait for a user response - int result = dialog.run(); // the main cycle blocks here + result = dialog.run(); // the main cycle blocks here +#endif // Handle the response switch (result) { case Gtk::RESPONSE_ACCEPT: { - last_dir = dialog.get_current_folder(); // safe for the future + std::string file; +#if GTK_CHECK_VERSION(3, 20, 0) + file = app_ustring_from_gchar(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog.get()))); + last_dir = hz::path_get_dirname(file); +#else + file = dialog.get_filename(); // in fs encoding + last_dir = dialog.get_current_folder(); // save for the future +#endif - std::string file = dialog.get_filename(); hz::File f(file); std::string data = this->drive->get_full_output(); if (data.empty()) { diff --git a/gsmartcontrol/src/gsc_init.cpp b/gsmartcontrol/src/gsc_init.cpp index 55c8570..426bfef 100644 --- a/gsmartcontrol/src/gsc_init.cpp +++ b/gsmartcontrol/src/gsc_init.cpp @@ -291,7 +291,7 @@ namespace { std::string warningtext = std::string("\nWarning: GSmartControl"); warningtext += " comes with ABSOLUTELY NO WARRANTY.\n"; warningtext += "See LICENSE_gsmartcontrol.txt file for details.\n"; - warningtext += "\nCopyright (C) 2008 - 2012 Alexander Shaduri \n\n"; + warningtext += "\nCopyright (C) 2008 - 2017 Alexander Shaduri \n\n"; std::fprintf(stdout, "%s%s", versiontext.c_str(), warningtext.c_str()); } diff --git a/gsmartcontrol/src/gsc_main_window.cpp b/gsmartcontrol/src/gsc_main_window.cpp index 84499f1..16a541a 100644 --- a/gsmartcontrol/src/gsc_main_window.cpp +++ b/gsmartcontrol/src/gsc_main_window.cpp @@ -15,6 +15,7 @@ #include "hz/string_algo.h" // string_split #include "hz/fs_file.h" // hz::File #include "hz/debug.h" +#include "hz/scoped_ptr.h" #include "rconfig/rconfig_mini.h" #include "applib/storage_detector.h" #include "applib/smartctl_parser.h" @@ -1265,7 +1266,19 @@ void GscMainWindow::show_add_device_chooser() void GscMainWindow::show_load_virtual_file_chooser() { static std::string last_dir; + int result = 0; +#if GTK_CHECK_VERSION(3, 20, 0) + hz::scoped_ptr dialog(gtk_file_chooser_native_new( + "Load Data From...", this->gobj(), GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL), g_object_unref); + + if (!last_dir.empty()) { + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog.get()), last_dir.c_str()); + } + + result = gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog.get())); + +#else Gtk::FileChooserDialog dialog(*this, "Load Data From...", Gtk::FILE_CHOOSER_ACTION_OPEN); @@ -1277,15 +1290,22 @@ void GscMainWindow::show_load_virtual_file_chooser() dialog.set_current_folder(last_dir); // Show the dialog and wait for a user response - int result = dialog.run(); // the main cycle blocks here + result = dialog.run(); // the main cycle blocks here +#endif // Handle the response switch (result) { case Gtk::RESPONSE_ACCEPT: { - last_dir = dialog.get_current_folder(); // safe for the future + std::string file; - std::string file = dialog.get_filename(); // in fs encoding +#if GTK_CHECK_VERSION(3, 20, 0) + file = app_ustring_from_gchar(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog.get()))); + last_dir = hz::path_get_dirname(file); +#else + file = dialog.get_filename(); // in fs encoding + last_dir = dialog.get_current_folder(); // save for the future +#endif this->add_virtual_drive(file); break; } diff --git a/gsmartcontrol/src/gsc_preferences_window.cpp b/gsmartcontrol/src/gsc_preferences_window.cpp index e380082..9d23ad8 100644 --- a/gsmartcontrol/src/gsc_preferences_window.cpp +++ b/gsmartcontrol/src/gsc_preferences_window.cpp @@ -15,6 +15,7 @@ #include "hz/fs_path.h" #include "hz/string_sprintf.h" +#include "hz/scoped_ptr.h" #include "rconfig/rconfig_mini.h" #include "applib/storage_settings.h" #include "applib/app_gtkmm_utils.h" @@ -571,6 +572,20 @@ void GscPreferencesWindow::on_smartctl_binary_browse_button_clicked() if (!entry) return; + hz::FsPath path(entry->get_text()); + + int result = 0; + +#if GTK_CHECK_VERSION(3, 20, 0) + hz::scoped_ptr dialog(gtk_file_chooser_native_new( + "Choose Smartctl Binary...", this->gobj(), GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL), g_object_unref); + + if (path.is_absolute()) + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog.get()), path.c_str()); + + result = gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog.get())); + +#else Gtk::FileChooserDialog dialog(*this, "Choose Smartctl Binary...", Gtk::FILE_CHOOSER_ACTION_OPEN); @@ -579,18 +594,24 @@ void GscPreferencesWindow::on_smartctl_binary_browse_button_clicked() dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT); // Note: This works on absolute paths only (otherwise it's gtk warning). - hz::FsPath p(entry->get_text()); - if (p.is_absolute()) - dialog.set_filename(p.str()); // change to its dir and select it if exists. + if (path.is_absolute()) + dialog.set_filename(path.str()); // change to its dir and select it if exists. // Show the dialog and wait for a user response - int result = dialog.run(); // the main cycle blocks here + result = dialog.run(); // the main cycle blocks here +#endif // Handle the response switch (result) { case Gtk::RESPONSE_ACCEPT: { - entry->set_text(std::string(dialog.get_filename())); + Glib::ustring file; +#if GTK_CHECK_VERSION(3, 20, 0) + file = app_ustring_from_gchar(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog.get()))); +#else + file = dialog.get_filename(); // in fs encoding +#endif + entry->set_text(file); break; } diff --git a/gsmartcontrol/src/gsc_text_window.h b/gsmartcontrol/src/gsc_text_window.h index e5add56..00cfdd3 100644 --- a/gsmartcontrol/src/gsc_text_window.h +++ b/gsmartcontrol/src/gsc_text_window.h @@ -17,6 +17,7 @@ #include "hz/debug.h" #include "hz/fs_file.h" +#include "hz/scoped_ptr.h" #include "applib/app_gtkmm_features.h" #include "applib/app_ui_res_utils.h" @@ -140,7 +141,23 @@ class GscTextWindow : public AppUIResWidget, Insta void on_save_as_button_clicked() { static std::string last_dir; + int result = 0; +#if GTK_CHECK_VERSION(3, 20, 0) + hz::scoped_ptr dialog(gtk_file_chooser_native_new( + "Save Data As...", this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL), g_object_unref); + + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog.get()), true); + + if (!last_dir.empty()) + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog.get()), last_dir.c_str()); + + if (!save_filename_.empty()) + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog.get()), save_filename_.c_str()); + + result = gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog.get())); + +#else Gtk::FileChooserDialog dialog(*this, "Save Data As...", Gtk::FILE_CHOOSER_ACTION_SAVE); @@ -157,15 +174,21 @@ class GscTextWindow : public AppUIResWidget, Insta dialog.set_current_name(save_filename_); // Show the dialog and wait for a user response - int result = dialog.run(); // the main cycle blocks here + result = dialog.run(); // the main cycle blocks here +#endif // Handle the response switch (result) { case Gtk::RESPONSE_ACCEPT: { - last_dir = dialog.get_current_folder(); // safe for the future - - std::string file = dialog.get_filename(); + std::string file; +#if GTK_CHECK_VERSION(3, 20, 0) + file = app_ustring_from_gchar(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog.get()))); + last_dir = hz::path_get_dirname(file); +#else + file = dialog.get_filename(); // in fs encoding + last_dir = dialog.get_current_folder(); // save for the future +#endif hz::File f(file); if (!f.put_contents(this->contents_)) { // this will send to debug_ too. gui_show_error_dialog("Cannot save data to file", f.get_error_utf8(), this);