Revision
14470
Author
jmesquita
Date
2009-08-09 00:21:08 -0500 (Sun, 09 Aug 2009)

Log Message

Connect and disconnect controls and closing tabs now work.

Modified Paths

Diff

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/fsgui/appmanager.cpp (14469 => 14470)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/fsgui/appmanager.cpp	2009-08-09 04:06:18 UTC (rev 14469)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/fsgui/appmanager.cpp	2009-08-09 05:21:08 UTC (rev 14470)
@@ -61,7 +61,6 @@
     bool help_exists = false;
     QList<QAction *> list = menu_bar->actions();
     for (int i = 0; i < list.size(); ++i) {
-        qDebug() << "I am trying";
         if (QString::compare(list.at(i)->text(), tr("&File"), Qt::CaseInsensitive) == 0)
         {
             list.at(i)->menu()->addAction(action_exit);
@@ -69,7 +68,6 @@
         }
         if (QString::compare(list.at(i)->text(), tr("&Preferences"), Qt::CaseInsensitive) == 0)
         {
-            qDebug() << "Teste!";
             list.at(i)->menu()->addAction(action_preferences);
             edit_exists = true;
         }

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.cpp (14469 => 14470)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.cpp	2009-08-09 04:06:18 UTC (rev 14469)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.cpp	2009-08-09 05:21:08 UTC (rev 14470)
@@ -15,6 +15,16 @@
 {
     consoleWindow->setupUi(this);
     consoleWindow->tabConsole->clear();
+
+    QObject::connect(consoleWindow->tabConsole, SIGNAL(tabCloseRequested(int)),
+                     this, SLOT(tabClose(int)));
+    QObject::connect(consoleWindow->tabConsole, SIGNAL(currentChanged(int)),
+                     this, SLOT(tabChanged(int)));
+
+    QObject::connect(consoleWindow->action_Connect, SIGNAL(triggered()),
+                     this, SLOT(connect()));
+    QObject::connect(consoleWindow->action_Disconnect, SIGNAL(triggered()),
+                     this, SLOT(disconnect()));
 }
 
 ConsolePlugin::~ConsolePlugin(){}
@@ -92,51 +102,49 @@
                      this, SLOT(newConnection()));
 }
 
-void ConsolePlugin::connected()
-{
-    consoleWindow->action_Connect->setEnabled(false);
-    consoleWindow->action_Disconnect->setEnabled(true);
-}
-
-void ConsolePlugin::disconnected()
-{
-    consoleWindow->action_Connect->setEnabled(true);
-    consoleWindow->action_Disconnect->setEnabled(false);
-}
-
-void ConsolePlugin::connectionFailed(QString /*reason*/)
-{
-}
-
 void ConsolePlugin::newConnection()
 {
     if (serverManager->exec())
     {
         ESLconnection *esl = serverManager->getESLconnection();
-        consoleWindow->tabConsole->addTab(new ConsoleTabWidget(this, esl), esl->getName());
+
         if (hashESL.contains(esl->getName()))
         {
-            esl->disconnect();
-            esl->wait();
-            hashESL.remove(esl->getName());
-            delete esl;
+            for (int i = 0; i < consoleWindow->tabConsole->count(); i++)
+            {
+                if (consoleWindow->tabConsole->tabText(i) == esl->getName())
+                {
+                    consoleWindow->tabConsole->setCurrentIndex(i);
+                    delete esl;
+                    return;
+                }
+            }
         }
+
+        ConsoleTabWidget *newTab = new ConsoleTabWidget(this, esl);
+        consoleWindow->tabConsole->addTab(newTab, esl->getName());
+        consoleWindow->tabConsole->setCurrentWidget(newTab);
         hashESL.insert(esl->getName(), esl);
         QObject::connect(esl, SIGNAL(connected()),
-                         this, SLOT(connected()));
+                         this, SLOT(connectionStateChanged()));
+        QObject::connect(esl, SIGNAL(disconnected()),
+                         this, SLOT(connectionStateChanged()));
         QObject::connect(esl, SIGNAL(connectionFailed(QString)),
-                         this, SLOT(connectionFailed(QString)));
-        QObject::connect(esl, SIGNAL(disconnected()),
-                         this, SLOT(disconnected()));
+                         this, SLOT(connectionStateChanged()));
     }
 }
 
+void ConsolePlugin::connectionStateChanged()
+{
+    tabChanged(consoleWindow->tabConsole->currentIndex());
+}
+
 void ConsolePlugin::setPalette(QLineEdit *control, QString key)
 {
-	QSettings settings;
-	if (settings.contains(key)) {
-		control->setPalette(settings.value(key).value<QPalette>());
-	}
+    QSettings settings;
+    if (settings.contains(key)) {
+        control->setPalette(settings.value(key).value<QPalette>());
+    }
 }
 
 void ConsolePlugin::readSettings()
@@ -356,4 +364,52 @@
     }
 }
 
+void ConsolePlugin::tabClose(int index)
+{
+    QWidget *tab = consoleWindow->tabConsole->widget(index);
+    ESLconnection *esl = hashESL.value(consoleWindow->tabConsole->tabText(index), NULL);
+    if (esl)
+    {
+        hashESL.remove(consoleWindow->tabConsole->tabText(index));
+        esl->disconnect();
+        esl->wait();
+        delete esl;
+    }
+    consoleWindow->tabConsole->removeTab(index);
+    delete tab;
+    if (consoleWindow->tabConsole->count() == 0)
+    {
+        consoleWindow->action_Connect->setEnabled(false);
+        consoleWindow->action_Disconnect->setEnabled(false);
+    }
+}
+
+void ConsolePlugin::tabChanged(int index)
+{
+    ESLconnection *esl = hashESL.value(consoleWindow->tabConsole->tabText(index), NULL);
+    if (esl)
+    {
+        consoleWindow->action_Connect->setDisabled(esl->isConnected());
+        consoleWindow->action_Disconnect->setEnabled(esl->isConnected());
+    }
+}
+
+void ConsolePlugin::connect()
+{
+    ESLconnection *esl = hashESL.value(consoleWindow->tabConsole->tabText(consoleWindow->tabConsole->currentIndex()), NULL);
+    if (esl)
+    {
+        esl->connect();
+    }
+}
+
+void ConsolePlugin::disconnect()
+{
+    ESLconnection *esl = hashESL.value(consoleWindow->tabConsole->tabText(consoleWindow->tabConsole->currentIndex()), NULL);
+    if (esl)
+    {
+        esl->disconnect();
+    }
+}
+
 Q_EXPORT_PLUGIN2(consoleplugin, ConsolePlugin)

Modified: freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.h (14469 => 14470)


--- freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.h	2009-08-09 04:06:18 UTC (rev 14469)
+++ freeswitch/trunk/contrib/jmesquita/fsgui/src/plugins/consoleplugin/consoleplugin.h	2009-08-09 05:21:08 UTC (rev 14470)
@@ -28,9 +28,9 @@
     void setServerManager(ServerManager *manager);
 
 private slots:
-    void connected();
-    void disconnected();
-    void connectionFailed(QString);
+    void connectionStateChanged();
+    void connect();
+    void disconnect();
     void newConnection();
     void changeConsoleBackgroundColor();
     void changeAlertBackgroundColor();
@@ -48,6 +48,8 @@
     void changeNoticeForegroundColor();
     void changeInfoForegroundColor();
     void changeDebugForegroundColor();
+    void tabClose(int index);
+    void tabChanged(int index);
     void readSettings();
     void writeSettings();
 
@@ -57,7 +59,7 @@
     ServerManager *serverManager;
     QHash<QString, ESLconnection *> hashESL;
 
-	void setPalette(QLineEdit *control, QString key);
+    void setPalette(QLineEdit *control, QString key);
 };
 
 #endif // CONSOLEPLUGIN_H