FormSessionManager.cpp

Go to the documentation of this file.
00001 /** @file    FormSessionManager.cpp
00002  *  @author  Alessandro Polo
00003  *  @version $Id: FormSessionManager.cpp 3775 2011-01-01 16:38:17Z alex $
00004  *  @brief
00005  * File containing methods for the wosh::gui::FormSessionManager class.
00006  * The header for this class can be found in FormSessionManager.h, check that file
00007  * for class description.
00008  ****************************************************************************/
00009 /* Copyright (c) 2007-2011, WOSH - Wide Open Smart Home 
00010  * by Alessandro Polo - OpenSmartHome.com
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *     * Redistributions of source code must retain the above copyright
00016  *       notice, this list of conditions and the following disclaimer.
00017  *     * Redistributions in binary form must reproduce the above copyright
00018  *       notice, this list of conditions and the following disclaimer in the
00019  *       documentation and/or other materials provided with the distribution.
00020  *     * Neither the name of the OpenSmartHome.com WOSH nor the
00021  *       names of its contributors may be used to endorse or promote products
00022  *       derived from this software without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
00025  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027  * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
00028  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00033  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  ****************************************************************************/
00035 
00036  #include "FormSessionManager.h"
00037  #include "ui_FormSessionManager.h"
00038  #include <framework/gui/GuiFactory.h>
00039  #include <core/MethodsCommon.h>
00040  #include <QtGui/QInputDialog>
00041  #include <QtGui/QMessageBox>
00042 
00043 
00044 using namespace std;
00045 namespace wosh {
00046  namespace gui {
00047 
00048  WOSH_REGISTER(wosh::gui::FormSessionManager, wosh::gui::WoshRemoteWidgetTW, 0.8677, gui_FormSessionManager)
00049  WOSH_GUI_BIND(wosh::gui::FormSessionManager, wosh::SessionManager, 0.0, gui_FormSessionManager1)
00050  WOSH_GUI_OVERRIDE(wosh::gui::FormSessionManager, wosh::SessionManager, "wosh::gui::wCore_Object", gui_FormSessionManager2)
00051 
00052 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00053 
00054 FormSessionManager::FormSessionManager( QWidget* parent )
00055     : WoshRemoteWidgetTW(parent) {
00056     this->m_ui = new Ui::FormSessionManager();
00057     this->m_ui->setupUi(this);
00058     WoshRemoteWidgetTW::setTargetURI(URI(_SessionManager_URI));
00059 
00060     buildMenus();
00061 
00062     // tab Sessions [0]
00063     this->m_ui->tableView->setResizeStretch("URI");
00064     this->m_ui->tableView->getTableView()->setContextMenuPolicy(Qt::CustomContextMenu);
00065     QObject::connect(this->m_ui->tableView, SIGNAL(postMessage(Message*)),this, SLOT(postMessage(Message*)) );
00066     QObject::connect(this->m_ui->tableView, SIGNAL(tableContextMenuRequested(const QPoint&, const QModelIndex&)),this, SLOT(tableView_ContextMenu(const QPoint&, const QModelIndex&)) );
00067     QObject::connect(this->m_ui->btnMonitorSession, SIGNAL(clicked()), this, SLOT(btnMonitorSession_clicked()));
00068     QObject::connect(this->m_ui->btnCloseSession, SIGNAL(clicked()), this, SLOT(btnCloseSession_clicked()));
00069     QObject::connect(this->m_ui->btnSendMessage, SIGNAL(clicked()), this, SLOT(btnSendMessage_clicked()));
00070 }
00071 
00072 FormSessionManager::~FormSessionManager() {
00073     delete this->m_ui;
00074  }
00075 
00076 void FormSessionManager::changeEvent(QEvent *e) {
00077     WoshRemoteWidgetTW::changeEvent(e);
00078     if ( e->type() == QEvent::LanguageChange )
00079         this->m_ui->retranslateUi(this);
00080  }
00081 
00082 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00083 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00084 
00085 WRESULT FormSessionManager::refresh( long options ) {
00086     WRESULT ret = WoshRemoteWidgetTW::refresh(options);
00087     setWindowTitle( tr("Session Manager [%1]").arg(this->getTargetURI().getKernelName().c_str()) );
00088     this->m_ui->tableView->refreshData();
00089     return ret;
00090  }
00091 
00092 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00093 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00094 
00095 void FormSessionManager::btnMonitorSession_clicked() {
00096     QMessageBox::critical(this, tr("NOT Implemented!"), tr("FormSessionManager::btnMonitorSession_clicked()") );
00097  }
00098 
00099 void FormSessionManager::btnCloseSession_clicked() {
00100     Variant sessionId = this->m_ui->tableView->getCurrentItemAsVariantAtCol(0);
00101     executeRemoteMethod( _SessionManager_METHOD_close_session, sessionId.clone() );
00102  }
00103 
00104 void FormSessionManager::btnSendMessage_clicked() {
00105     bool ok;
00106     Variant sessionId = this->m_ui->tableView->getCurrentItemAsVariantAtCol(0);
00107     QString text_msg = QInputDialog::getText(this, tr("Enter Message.."), tr("Send direct message:"), QLineEdit::Normal, "", &ok);
00108     if ( !ok || text_msg.isEmpty() ) return;
00109     List* args = List::createFrom<Variant>(sessionId, text_msg.toLatin1().constData());
00110     executeRemoteMethod( _SessionManager_METHOD_send_message, args );
00111  }
00112 
00113 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00114 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00115 
00116 void FormSessionManager::buildMenus() {
00117     this->menuTitle = new QAction(this);
00118     this->menuTitle->setEnabled(false);
00119 /*
00120     this->menuSharedLocal = new QAction(this);
00121     this->menuSharedLocal->setText(tr("&Locally Shared"));
00122     this->menuSharedLocal->setCheckable(true);
00123     this->menuSharedNetwork = new QAction(this);
00124     this->menuSharedNetwork->setText(tr("&Network Shared"));
00125     this->menuSharedNetwork->setCheckable(true);
00126     this->menuFlush = new QAction(this);
00127     this->menuFlush->setText(tr("&Flush queue"));
00128 */
00129     this->menuSendMessage = new QAction(this);
00130     this->menuSendMessage->setText(tr("&Send Message.."));
00131 
00132     this->menuTable = new QMenu(this);
00133     this->menuTable->addAction(this->menuTitle);
00134     this->menuTable->addSeparator();
00135 //  this->menuTable->addAction(this->menuSharedLocal);
00136 //  this->menuTable->addAction(this->menuSharedNetwork);
00137 //  this->menuTable->addSeparator();
00138 //  this->menuTable->addAction(this->menuFlush);
00139 //  this->menuTable->addSeparator();
00140     this->menuTable->addAction(this->menuSendMessage);
00141 
00142  }
00143 
00144 void FormSessionManager::tableView_ContextMenu( const QPoint& pos, const QModelIndex& index ) {
00145     QPoint globalPos = this->mapToGlobal(pos);
00146     if ( !index.isValid() || index.row() == 0 ) return;
00147     Variant busName = this->m_ui->tableView->getCurrentItemAsVariantAtCol(1);
00148     Variant busType = this->m_ui->tableView->getCurrentItemAsVariantAtCol(2);
00149     Variant locshared = this->m_ui->tableView->getCurrentItemAsVariantAtCol(4);
00150     Variant netshared = this->m_ui->tableView->getCurrentItemAsVariantAtCol(5);
00151 
00152     this->menuTitle->setText( busName.toString().c_str() );
00153     this->menuTitle->setIcon( GuiUtilities::createIconFor(busType.toString()) );
00154     this->menuSharedLocal->setChecked( locshared.toBoolean(false) );
00155     this->menuSharedNetwork->setChecked( netshared.toBoolean(false) );
00156 
00157     QAction* selected = this->menuTable->exec( globalPos );
00158     if ( selected == this->menuSharedLocal ) {
00159      }
00160     else if ( selected == this->menuSharedNetwork ) {
00161      }
00162     else if ( selected == this->menuSendMessage ) {
00163         btnSendMessage_clicked();
00164      }
00165  }
00166 
00167 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00168 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00169 
00170 void FormSessionManager::busMessage( const Message& message, const Bus* source ) {
00171     WoshRemoteWidgetTW::busMessage( message, source );
00172     if ( message.isEmpty() || !message.getContent()->isResponse() ) return;
00173     if ( !isMessageForMeOrFromTarget(message) ) return;
00174     const wosh::Response* response = message.getContent()->asResponse();
00175     this->m_ui->tableView->evalResponse(response);
00176  }
00177 
00178 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00179 
00180  }; // namespace gui
00181 }; // namespace wosh

Generated on Tue Feb 8 2011 09:32:54 for WOSH system 0.8.888 [wolf] by Alessandro Polo, using DoxyGen 1.7.2 hosted by WOSH Framework