[Spice-devel] [PATCH] Handle Application::set_hotkeys failure

Christophe Fergeau cfergeau at redhat.com
Wed Feb 8 05:46:00 PST 2012


Application::set_hotkeys can throw an exception if it fails parsing
the string describing the hotkeys to set. Currently this exception
is uncaught which causes spicec to terminate when the controller
tries to set invalid hotkeys. Fall back to using the default
hotkeys when the controller sends an invalid hotkeys string.
---
 client/application.cpp |   46 +++++++++++++++++++++++++++++-----------------
 client/application.h   |    1 +
 2 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/client/application.cpp b/client/application.cpp
index 08fa4fc..1d4da8b 100644
--- a/client/application.cpp
+++ b/client/application.cpp
@@ -393,21 +393,7 @@ Application::Application()
     Platform::get_app_data_dir(_host_auth_opt.CA_file, app_name);
     Platform::path_append(_host_auth_opt.CA_file, CA_FILE_NAME);
 
-    std::auto_ptr<HotKeysParser> parser(new HotKeysParser("toggle-fullscreen=shift+f11"
-                                                          ",release-cursor=shift+f12"
-#ifdef RED_DEBUG
-                                                          ",connect=shift+f5"
-                                                          ",disconnect=shift+f6"
-#endif
-#ifdef USE_GUI
-                                                          ",show-gui=shift+f7"
-#endif // USE_GUI
-#ifdef USE_SMARTCARD
-                                                          ",smartcard-insert=shift+f8"
-                                                          ",smartcard-remove=shift+f9"
-#endif
-                                                          , _commands_map));
-    _hot_keys = parser->get();
+    this->set_default_hotkeys();
 
     _sticky_info.trace_is_on = false;
     _sticky_info.sticky_mode = false;
@@ -1867,10 +1853,36 @@ void Application::hide_me()
     hide();
 }
 
+void Application::set_default_hotkeys(void)
+{
+    const std::string default_hotkeys = "toggle-fullscreen=shift+f11"
+                                        ",release-cursor=shift+f12"
+#ifdef RED_DEBUG
+                                        ",connect=shift+f5"
+                                        ",disconnect=shift+f6"
+#endif
+#ifdef USE_GUI
+                                        ",show-gui=shift+f7"
+#endif // USE_GUI
+#ifdef USE_SMARTCARD
+                                        ",smartcard-insert=shift+f8"
+                                        ",smartcard-remove=shift+f9"
+#endif
+                                        "";
+
+    this->set_hotkeys(default_hotkeys);
+}
+
 void Application::set_hotkeys(const std::string& hotkeys)
 {
-    std::auto_ptr<HotKeysParser> parser(new HotKeysParser(hotkeys, _commands_map));
-    _hot_keys = parser->get();
+
+    try {
+        std::auto_ptr<HotKeysParser> parser(new HotKeysParser(hotkeys, _commands_map));
+        _hot_keys = parser->get();
+    } catch (Exception &e) {
+        LOG_WARN("%s", e.what());
+        this->set_default_hotkeys();
+    }
 }
 
 int Application::get_controller_menu_item_id(int32_t opaque_conn_ref, uint32_t msg_id)
diff --git a/client/application.h b/client/application.h
index ac51cd2..c513d94 100644
--- a/client/application.h
+++ b/client/application.h
@@ -250,6 +250,7 @@ public:
     void show_me(bool full_screen);
     void hide_me();
     void set_hotkeys(const std::string& hotkeys);
+    void set_default_hotkeys(void);
     int get_controller_menu_item_id(int32_t opaque_conn_ref, uint32_t msg_id);
     void set_menu(Menu* menu);
     void delete_menu();
-- 
1.7.7.6



More information about the Spice-devel mailing list