00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <QMenuBar>
00031 #include <QTextEdit>
00032 #include <QAction>
00033
00034 #include "bluetoothappwindow.h"
00035 #include "bluetoothdiscovery.h"
00036
00037
00038
00039
00040
00041
00042 BluetoothAppWindow::BluetoothAppWindow(QWidget *parent) :
00043 QMainWindow(parent)
00044 {
00045 addMenu();
00046 initializeWindow();
00047
00048 mBluetoothDiscovery = new BluetoothDiscovery(this);
00049
00050
00051 connect(mBluetoothDiscovery,SIGNAL(showMessage(bool , QString )),this, SLOT(showMessage(bool , QString )));
00052 connect(mBluetoothDiscovery,SIGNAL(changeMenu(int)),this, SLOT(changeMenu(int)));
00053 }
00054
00055
00056
00057
00058 void BluetoothAppWindow::addMenu()
00059 {
00060
00061 mDiscoverDevices = new QAction("Discover devices",this);
00062 connect(mDiscoverDevices, SIGNAL(triggered()), this, SLOT(discoverDevices()));
00063 menuBar()->addAction(mDiscoverDevices);
00064
00065 mDiscoverServices = new QAction("Discover services",this);
00066 connect(mDiscoverServices, SIGNAL(triggered()), this, SLOT(discoverServices()));
00067 menuBar()->addAction(mDiscoverServices);
00068 mDiscoverServices->setVisible(false);
00069
00070 mStopDiscovery= new QAction("Stop Discovery",this);
00071 connect(mStopDiscovery, SIGNAL(triggered()), this, SLOT(stopDiscovery()));
00072 menuBar()->addAction(mStopDiscovery);
00073
00074 mSendMessage = new QAction("Send Message",this);
00075 connect(mSendMessage, SIGNAL(triggered()), this, SLOT(sendMessage()));
00076 menuBar()->addAction(mSendMessage);
00077
00078 mStartSlave = new QAction("Start Slave",this);
00079 connect(mStartSlave, SIGNAL(triggered()), this, SLOT(startSlave()));
00080 menuBar()->addAction(mStartSlave);
00081
00082 mConnectDevices = new QAction("Connect devices",this);
00083 connect(mConnectDevices, SIGNAL(triggered()), this, SLOT(connectDevices()));
00084 menuBar()->addAction(mConnectDevices);
00085
00086 mStopSlave = new QAction("Stop Slave",this);
00087 connect(mStopSlave, SIGNAL(triggered()), this, SLOT(stopSlave()));
00088 menuBar()->addAction(mStopSlave);
00089
00090 mDisconnectDevices = new QAction("Disconnect devices",this);
00091 connect(mDisconnectDevices, SIGNAL(triggered()), this, SLOT(disconnectDevices()));
00092 menuBar()->addAction(mDisconnectDevices);
00093
00094 mShowConnectedDevices = new QAction("Show ConnectedDevices",this);
00095 connect(mShowConnectedDevices, SIGNAL(triggered()), this, SLOT(showConnectedDevices()));
00096 menuBar()->addAction(mShowConnectedDevices);
00097
00098 mClearText = new QAction("Clear Text",this);
00099 connect(mClearText, SIGNAL(triggered()), this, SLOT(clearText()));
00100 menuBar()->addAction(mClearText);
00101
00102 initializeMenu();
00103
00104 }
00105
00106
00107 void BluetoothAppWindow::initializeMenu()
00108 {
00109 mDiscoverDevices->setVisible(true);
00110 mDiscoverServices->setVisible(false);
00111 mStopDiscovery->setVisible(false);
00112 mStartSlave->setVisible(true);
00113 mStopSlave->setVisible(false);
00114 mConnectDevices->setVisible(false);
00115 mDisconnectDevices->setVisible(false);
00116 mShowConnectedDevices->setVisible(false);
00117 mSendMessage->setVisible(false);
00118 }
00119
00120
00121
00122
00123
00124 void BluetoothAppWindow::initializeWindow()
00125 {
00126 mRemoteDevicesList = new QTextEdit();
00127 mRemoteDevicesList->setText("All the remote devices \n"
00128 "detected by bluetooth are listed here");
00129 mRemoteDevicesList->setWordWrapMode(QTextOption::WordWrap);
00130
00131 mRemoteDevicesList->setReadOnly(true);
00132 setCentralWidget(mRemoteDevicesList);
00133 }
00134
00135
00136 void BluetoothAppWindow::discoverDevices()
00137 {
00138 mBluetoothDiscovery->discoverDevices();
00139 }
00140
00141
00142 void BluetoothAppWindow::discoverServices()
00143 {
00144 mBluetoothDiscovery->discoverServices();
00145 }
00146
00147
00148 void BluetoothAppWindow::stopDiscovery()
00149 {
00150 mDiscoverDevices->setVisible(true);
00151 mStopDiscovery->setVisible(false);
00152 mBluetoothDiscovery->stopDiscovery();
00153 }
00154
00155
00156 void BluetoothAppWindow::sendMessage()
00157 {
00158 mBluetoothDiscovery->sendMessage();
00159 }
00160
00161
00162 void BluetoothAppWindow::startSlave()
00163 {
00164 mStartSlave->setVisible(false);
00165 mBluetoothDiscovery->startSlave();
00166 }
00167
00168
00169 void BluetoothAppWindow::connectDevices()
00170 {
00171 mBluetoothDiscovery->connectDevices();
00172 }
00173
00174
00175 void BluetoothAppWindow::stopSlave()
00176 {
00177 mStartSlave->setVisible(true);
00178 mBluetoothDiscovery->stopSlave();
00179 }
00180
00181
00182 void BluetoothAppWindow::disconnectDevices()
00183 {
00184 mBluetoothDiscovery->disconnectDevices();
00185 }
00186
00187
00188 void BluetoothAppWindow::showConnectedDevices()
00189 {
00190 mBluetoothDiscovery->showConnectedDevices();
00191 }
00192
00193
00194 void BluetoothAppWindow::clearText()
00195 {
00196 mDisplayText.clear();
00197 mRemoteDevicesList->setText(mDisplayText);
00198 }
00199
00200
00201 void BluetoothAppWindow::changeMenu(int aMenuOptions)
00202 {
00203 switch(aMenuOptions)
00204 {
00205 case BluetoothAppWindow::EStopDeviceDiscovery:
00206 mDiscoverDevices->setVisible(false);
00207 mStopDiscovery->setVisible(true);
00208 break;
00209 case BluetoothAppWindow::EDeviceDiscoveryComplete:
00210 mDiscoverDevices->setVisible(true);
00211 mStopDiscovery->setVisible(false);
00212 break;
00213 case BluetoothAppWindow::EHasDevices:
00214 mDiscoverServices->setVisible(true);
00215 mStartSlave->setVisible(true);
00216 mConnectDevices->setVisible(false);
00217 mSendMessage->setVisible(false);
00218 mShowConnectedDevices->setVisible(false);
00219 mDisconnectDevices->setVisible(false);
00220 break;
00221 case BluetoothAppWindow::EHasServices:
00222 mConnectDevices->setVisible(true);
00223 mSendMessage->setVisible(false);
00224 mShowConnectedDevices->setVisible(false);
00225 mDisconnectDevices->setVisible(false);
00226 break;
00227 case BluetoothAppWindow::EHasConnections:
00228 mSendMessage->setVisible(true);
00229 mSendMessage->setVisible(true);
00230 mShowConnectedDevices->setVisible(true);
00231 mDisconnectDevices->setVisible(true);
00232 mConnectDevices->setVisible(false);
00233 break;
00234 case BluetoothAppWindow::EStopSlave:
00235 mStopSlave->setVisible(true);
00236 break;
00237 case BluetoothAppWindow::ESendMessage:
00238 mSendMessage->setVisible(true);
00239 break;
00240 }
00241 }
00242
00243
00244
00245 void BluetoothAppWindow::showMessage(bool aDrawLine,QString aDisplayMsg)
00246 {
00247 if(aDrawLine){
00248 mDisplayText.append("............................\n");
00249 }
00250 mDisplayText.append(aDisplayMsg);
00251
00252 mRemoteDevicesList->setText(mDisplayText);
00253 }