mainwindow.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. Copyright (c) 2010 Embedded Systems and Pervasive Laboratory, Federal
  3. University of Campina Grande, Brazil, Angelo Perkusich, Mirko Perkusich,
  4. Taciana Rached
  5. Permission is hereby granted, free of charge, to any person obtaining a
  6. copy of this software and associated documentation files (the
  7. "Software"), to deal in the Software without restriction, including
  8. without limitation the rights to use, copy, modify, merge, publish,
  9. distribute, sublicense, and/or sell copies of the Software, and to
  10. permit persons to whom the Software is furnished to do so, subject to
  11. the following conditions:
  12. The above copyright notice and this permission notice shall be included
  13. in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  18. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  19. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  20. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #include "mainwindow.h"
  23. MainWindow::MainWindow(QWidget *parent) :
  24. QMainWindow(parent)
  25. {
  26. /** Instantiate Picture Flow */
  27. pFlow = new PictureFlow();
  28. /** set main window */
  29. setMainWindow();
  30. /** set up connections */
  31. setupConnections();
  32. }
  33. void MainWindow::setupConnections()
  34. {
  35. QObject::connect(&btManager, SIGNAL(dataReceived(QByteArray)), this, SLOT(classifyData(QByteArray)));
  36. QObject::connect(connectButton, SIGNAL(clicked()), &btManager, SLOT(connect()));
  37. QObject::connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
  38. QObject::connect(&btManager, SIGNAL(connected()), this, SLOT(loadContactsInfo()));
  39. QObject::connect(&btManager, SIGNAL(connected()), this, SLOT(setWindow()));
  40. QObject::connect(&parser, SIGNAL(attentionLevel(int)), this, SLOT(attentionReceived(int)));
  41. QObject::connect(&parser, SIGNAL(meditationLevel(int)), this, SLOT(meditationReceived(int)));
  42. }
  43. void MainWindow::setWindow()
  44. {
  45. /** Set Picture Flow properties */
  46. pFlow->setSlideSize(QSize(300, 240));
  47. pFlow->resize(800, 300);
  48. pFlow->setCenterIndex(0);
  49. pFlow->setReflectionEffect(PictureFlow::NoReflection);
  50. pFlow->setBackgroundColor(Qt::black);
  51. pFlow->show();
  52. /** Set Widgets visibility*/
  53. connectButton->setVisible(false);
  54. quitButton->setVisible(false);
  55. pFlow->setVisible(true);
  56. medProgBar->setVisible(true);
  57. aProgBar->setVisible(true);
  58. pFlow->showNext();
  59. pFlow->showNext();
  60. }
  61. void MainWindow::loadContactsInfo()
  62. {
  63. /** Contacts manager for maemo 5*/
  64. QContactManager* myContactManager = new QContactManager("maemo5");
  65. /** List with all contacts */
  66. contacts = myContactManager->contacts();
  67. for(int i = 0; i < contacts.count(); i++){
  68. QContactThumbnail tInfo = contacts.at(i).detail(QContactThumbnail::DefinitionName);
  69. if (tInfo.isEmpty())
  70. /** load a Default Image */
  71. pFlow->addSlide(QImage(":/defaultImage.jpg"));
  72. else
  73. pFlow->addSlide(tInfo.thumbnail());
  74. pFlow->addSlideCaption(contacts.at(i).displayLabel());
  75. }
  76. }
  77. void MainWindow::classifyData(QByteArray data)
  78. {
  79. /* Classify Data */
  80. qDebug() << data.toHex();
  81. for(int i = 0; i < data.size(); i++)
  82. parser.parseByte(data.at(i));
  83. }
  84. void MainWindow::meditationReceived(int inMedLevel){
  85. medProgBar->setValue(inMedLevel);
  86. if (inMedLevel > 80)
  87. makeCall();
  88. }
  89. void MainWindow::attentionReceived(int inALevel){
  90. aProgBar->setValue(inALevel);
  91. if (inALevel > 0 && inALevel < 30)
  92. pFlow->showPrevious();
  93. else if (inALevel > 70)
  94. pFlow->showNext();
  95. }
  96. void MainWindow::makeCall()
  97. {
  98. /** get phone number from the contact currently at the center of the screen */
  99. QContactPhoneNumber phoneNumber = contacts.at(pFlow->centerIndex()).detail(QContactPhoneNumber::DefinitionName);
  100. /** phone number to be called */
  101. QString number = phoneNumber.number();
  102. qDebug() << "Phone number: " << number;
  103. QProcess *process = new QProcess();
  104. /** command to make a phone call on maemo 5 */
  105. QString command = QString("/usr/bin/run-standalone.sh dbus-send ") +
  106. QString("--system --type=method_call --print-reply ") +
  107. QString("--dest=com.nokia.csd.Call /com/nokia/csd/call ") +
  108. QString("com.nokia.csd.Call.CreateWith ") +
  109. QString("string:\"") + number + QString("\" ") +
  110. QString("uint32:0");
  111. /** command to turn loud speaker on on maemo 5 */
  112. QString command2 = QString("/usr/bin/run-standalone.sh dbus-send ") +
  113. QString("--type=method_call --dest=com.nokia.osso_hp_ls_controller ") +
  114. QString("/com/nokia/osso_hp_ls_controller com.nokia.osso_hp_ls_controller.") +
  115. QString("loudspeaker.force_loudspeaker_off");
  116. qDebug() << "Phone number: " << command;
  117. qDebug() << "Loud speaker: " << command2;
  118. /** make the phone call */
  119. process->start(command);
  120. /** turn loudspeaker on */
  121. process->start(command2);
  122. /** show application window full screen */
  123. this->showFullScreen();
  124. }
  125. void MainWindow::setMainWindow()
  126. {
  127. /** Progress Bars and Buttons Layout */
  128. QHBoxLayout* barsLayout = new QHBoxLayout();
  129. QHBoxLayout* buttonLayout = new QHBoxLayout();
  130. /** Set Buttons */
  131. connectButton = new QPushButton(this);
  132. connectButton->setText("Connect");
  133. quitButton = new QPushButton(this);
  134. quitButton->setText("Quit");
  135. /** Set Buttons Layout*/
  136. buttonLayout->addWidget(connectButton);
  137. QSpacerItem* horizontalSpacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
  138. buttonLayout->addItem(horizontalSpacer);
  139. buttonLayout->addWidget(quitButton);
  140. /** Set Vertical Layout */
  141. QWidget* layoutWidget = new QWidget(this);
  142. layoutWidget->setGeometry(0, 0, 800, 400);
  143. QVBoxLayout* layout = new QVBoxLayout(layoutWidget);
  144. layout->setGeometry(QRect(0, 50, 800, 300));
  145. layout->addLayout(buttonLayout);
  146. /** add and set PictureFlow widget */
  147. layout->addWidget(pFlow);
  148. pFlow->setVisible(false);
  149. /** add meditation and attention progress bars */
  150. medProgBar = new QProgressBar(this);
  151. barsLayout->addWidget(medProgBar);
  152. medProgBar->setVisible(false);
  153. aProgBar = new QProgressBar(this);
  154. barsLayout->addWidget(aProgBar);
  155. aProgBar->setVisible(false);
  156. layout->addLayout(barsLayout);
  157. }