From 1d6806ff20234d7e3a984f34f143e93b7aebbefa Mon Sep 17 00:00:00 2001
From: Ricardo Diaz <oceanosoftlapalma@gmail.com>
Date: Fri, 19 Apr 2013 19:52:32 +0200
Subject: [PATCH 5/5] set trayicon to session's icon

---
 onmainwindow.cpp |   60 ++++++++++++++++++++++++++++++++++--------------------
 onmainwindow.h   |    3 +++
 2 files changed, 41 insertions(+), 22 deletions(-)

diff --git a/onmainwindow.cpp b/onmainwindow.cpp
index 0e35cd8..66670bc 100644
--- a/onmainwindow.cpp
+++ b/onmainwindow.cpp
@@ -1428,26 +1428,6 @@ void ONMainWindow::hideEvent(QHideEvent* event)
     if (event->spontaneous() && trayMinToTray)
         hide();
 
-    //set session icon to tray icon
-    if (trayIcon) {
-
-        X2goSettings* st;
-
-        if (!brokerMode)
-            st=new X2goSettings( "sessions" );
-        else
-            st= new X2goSettings(config.iniFile,QSettings::IniFormat);
-
-        QString sid;
-        if ( !embedMode )
-            sid=lastSession->id();
-        else
-            sid="embedded";
-
-        //trayIcon->setIcon(QIcon ( ":icons/128x128/x2go.png") );
-        QString imagePath = st->setting()->value(sid + "/icon", (QVariant) QString(":icons/128x128/x2go.png")).toString();
-        trayIcon->setIcon(QIcon (imagePath));
-    }
 }
 
 
@@ -3633,7 +3613,7 @@ void ONMainWindow::startNewSession()
         //if multidisplay = true or maxdim = true we set maximun display area available for the seleccted monitor
         if (st->setting()->value(sid + "/multidisp", (QVariant) false).toBool() || st->setting()->value(sid + "/maxdim", (QVariant) false).toBool()) {
             int selectedScreen = st->setting()->value(sid + "/display", (QVariant) -1).toInt();
-            height=QApplication::desktop()->availableGeometry(selectedScreen).height();
+            height=QApplication::desktop()->availableGeometry(selectedScreen).height() - 10;
             width=QApplication::desktop()->availableGeometry(selectedScreen).width();
         } else {
             height=st->setting()->value ( sid+"/height",
@@ -3881,8 +3861,10 @@ void ONMainWindow::startNewSession()
     sshConnection->executeCommand ( cmd, this, SLOT ( slotRetResumeSess ( bool,
                                     QString,int ) ) );
     passForm->hide();
-}
 
+    //change the trayicon picture
+    setTrayIconToSessionIcon(tr("Creating new session..."));
+}
 
 
 void ONMainWindow::resumeSession ( const x2goSession& s )
@@ -4117,8 +4099,42 @@ void ONMainWindow::resumeSession ( const x2goSession& s )
                                     int ) ));
     resumingSession=s;
     passForm->hide();
+
+    //change the trayicon picture
+    setTrayIconToSessionIcon(tr("Restoring session..."));
+
 }
 
+/*
+ * set the tray session icon picture as tray icon picture and show a tray icon information message about something is doing
+ * this message avoid the users thinks nothinh happend for some seconds while x2go session window is showed
+ */
+void ONMainWindow::setTrayIconToSessionIcon(QString info) {
+
+    //set session icon to tray icon
+    if (trayIcon && lastSession) {
+
+        X2goSettings* st;
+
+        if (!brokerMode)
+            st=new X2goSettings( "sessions" );
+        else
+            st= new X2goSettings(config.iniFile,QSettings::IniFormat);
+
+        QString sid;
+        if ( !embedMode )
+            sid=lastSession->id();
+        else
+            sid="embedded";
+
+        QString imagePath = st->setting()->value(sid + "/icon", (QVariant) QString(":icons/128x128/x2go.png")).toString();
+        trayIcon->setIcon(QIcon (imagePath));
+
+        //send a information notification about the connection is done
+        trayIcon->showMessage(tr("X2Go"), tr ("Established connection\n") + info, QSystemTrayIcon::Information, 15000);
+    }
+
+}
 
 void ONMainWindow::selectSession ( QStringList& sessions )
 {
diff --git a/onmainwindow.h b/onmainwindow.h
index b51caca..890704a 100644
--- a/onmainwindow.h
+++ b/onmainwindow.h
@@ -44,6 +44,7 @@
 #include "sshmasterconnection.h"
 
 
+
 #ifdef Q_OS_WIN
 #include <windows.h>
 #endif
@@ -521,6 +522,7 @@ public:
     }
 #endif
 
+
 private:
     QString m_x2goconfig;
     QStringList _internApplicationsNames;
@@ -891,6 +893,7 @@ private:
     void removeAppsFromTray();
     void plugAppsInTray();
     QMenu* initTrayAppMenu(QString text, QPixmap icon);
+    void setTrayIconToSessionIcon(QString info);
 
 
 protected:
-- 
1.7.10.4

