Code

Persist User / Server / ChatServer name across succesful sessions (Given By Botty)
[inkscape.git] / src / jabber_whiteboard / session-manager.cpp
index a52a7a878997815576e11190ef3277ee3b27ca23..9a314842ea928bde9cfb32ff71f3fcf7e99e1c45 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "gc-anchored.h"
 
+#include "prefs-utils.h"
+
 #include "xml/repr.h"
 #include "xml/node-observer.h"
 
@@ -60,10 +62,6 @@ namespace Inkscape {
 
 namespace Whiteboard {
 
-#ifdef WIN32
-static bool lm_initialize_called = false;
-#endif
-
 SessionData::SessionData(SessionManager *sm)
 {
        this->_sm = sm;
@@ -109,10 +107,12 @@ SessionManager::SessionManager(::SPDesktop *desktop)
 
 #ifdef WIN32
     //# lm_initialize() must be called before any network code
+/*
     if (!lm_initialize_called) {
         lm_initialize();
         lm_initialize_called = true;
        }
+*/
 #endif
 
        this->_setVerbSensitivity(INITIAL);
@@ -173,8 +173,8 @@ SessionManager::setDesktop(::SPDesktop* desktop)
        if (this->_myDoc != NULL) {
                Inkscape::GC::release(this->_myDoc);
        }
-       if (SP_DT_DOCUMENT(desktop) != NULL) {
-               this->_myDoc = SP_DT_DOCUMENT(desktop);
+       if (sp_desktop_document(desktop) != NULL) {
+               this->_myDoc = sp_desktop_document(desktop);
                Inkscape::GC::anchor(this->_myDoc);
        }
 }
@@ -212,6 +212,9 @@ SessionManager::connectToServer(Glib::ustring const& server, Glib::ustring const
 
        lm_connection_set_port(this->session_data->connection, atoi(port.c_str()));
 
+        g_log(NULL, G_LOG_LEVEL_DEBUG, "Opened connection to %s at port %s.  Connecting...",
+                    server.c_str(), port.c_str());
+
        if (usessl) {
                if (lm_ssl_is_supported()) {
                        this->session_data->ssl = lm_ssl_new(NULL, ssl_error_handler, reinterpret_cast< gpointer >(this), NULL);
@@ -236,11 +239,13 @@ SessionManager::connectToServer(Glib::ustring const& server, Glib::ustring const
        //      to convert this from synchronous to asynchronous Loudmouth calls.
        if (!lm_connection_open_and_block(this->session_data->connection, &error)) {
                if (error != NULL) {
-                       g_warning("Failed to open: %s", error->message);
+                       std::cout << "Failed to open: " <<  error->message << std::endl;
                }
                return FAILED_TO_CONNECT;
        }
 
+        g_log(NULL, G_LOG_LEVEL_DEBUG, "Opened Loudmouth connection in blocking mode.");
+
        // Authenticate
        if (!lm_connection_authenticate_and_block(this->session_data->connection, username.c_str(), pw.c_str(), RESOURCE_NAME, &error)) {
                if (error != NULL) {
@@ -252,6 +257,8 @@ SessionManager::connectToServer(Glib::ustring const& server, Glib::ustring const
                return INVALID_AUTH;
        }
 
+        g_log(NULL, G_LOG_LEVEL_DEBUG, "Successfully authenticated.");
+
        // Register message handler for presence messages
        mh = lm_message_handler_new((LmHandleMessageFunction)presence_handler, reinterpret_cast< gpointer >(this->_myMessageHandler), NULL);
        lm_connection_register_message_handler(this->session_data->connection, mh, LM_MESSAGE_TYPE_PRESENCE, LM_HANDLER_PRIORITY_NORMAL);
@@ -284,6 +291,14 @@ SessionManager::connectToServer(Glib::ustring const& server, Glib::ustring const
 
        this->_setVerbSensitivity(ESTABLISHED_CONNECTION);
 
+       //On successful connect, remember info
+       prefs_set_string_attribute("whiteboard.server", "name", server.c_str());
+       prefs_set_string_attribute("whiteboard.server", "port", port.c_str());
+       prefs_set_string_attribute("whiteboard.server", "username", username.c_str());
+       prefs_set_int_attribute("whiteboard.server", "ssl", (usessl) ? 1 : 0);
+       //Option to store password here?
+
+
        return CONNECT_SUCCESS;
 }
 
@@ -776,7 +791,7 @@ SessionManager::loadSessionFile(Glib::ustring filename)
 void
 SessionManager::userConnectedToWhiteboard(gchar const* JID)
 {
-       SP_DT_MSGSTACK(this->_myDesktop)->flashF(Inkscape::INFORMATION_MESSAGE, _("Established whiteboard session with <b>%s</b>."), JID);
+       sp_desktop_message_stack(this->_myDesktop)->flashF(Inkscape::INFORMATION_MESSAGE, _("Established whiteboard session with <b>%s</b>."), JID);
 }
 
 
@@ -784,7 +799,7 @@ void
 SessionManager::userDisconnectedFromWhiteboard(std::string const& JID)
 {
 
-       SP_DT_MSGSTACK(this->_myDesktop)->flashF(Inkscape::INFORMATION_MESSAGE, _("<b>%s</b> has <b>left</b> the whiteboard session."), JID.c_str());
+       sp_desktop_message_stack(this->_myDesktop)->flashF(Inkscape::INFORMATION_MESSAGE, _("<b>%s</b> has <b>left</b> the whiteboard session."), JID.c_str());
 
        // Inform the user
        // TRANSLATORS: %1 is the name of the user that disconnected, %2 is the name of the user whom the disconnected user disconnected from.