symbianstatusupdater.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #include <QDebug>
  2. #include <QRegExp>
  3. #include "defines.h"
  4. #include "symbiandefines.h"
  5. #include "symbianstatusupdater.h"
  6. #define PROGRESS_MAX 1000
  7. SymbianStatusUpdater::SymbianStatusUpdater(SymbianQtProjectGenerator & generator,
  8. QObject * parent)
  9. : IStatusUpdater(parent),
  10. m_generator(generator)
  11. {
  12. // Connect generator messages
  13. connect(&m_generator,
  14. SIGNAL(started(GeneratorTarget)),
  15. this,
  16. SLOT(start(GeneratorTarget)));
  17. connect(&m_generator,
  18. SIGNAL(finished(int)),
  19. this,
  20. SLOT(stop()));
  21. connect(&(m_generator.outputView()),
  22. SIGNAL(message(QString)),
  23. this,
  24. SLOT(increase(QString)));
  25. // Some defaults if others are not provided
  26. m_phasesInAction = 5;
  27. m_maximumValue = PROGRESS_MAX;
  28. m_lastLogCounter = 0;
  29. // Reset values that can be changed outside
  30. reset();
  31. }
  32. SymbianStatusUpdater::~SymbianStatusUpdater()
  33. {
  34. ;
  35. }
  36. void SymbianStatusUpdater::updateGeneratorStatus(bool manualTrigger)
  37. {
  38. // If progress is indefinite, we're doing some time consuming
  39. // task with indefinite progress, so do not update the status.
  40. if (m_indefinite)
  41. return;
  42. GeneratorPhase phase = m_generator.getCurrentPhase();
  43. if (phase == ENDED_SUCCESSFULLY || phase == ENDED_WITH_ERRORS)
  44. {
  45. m_currentValue = m_maximumValue;
  46. m_statusText = m_generator.getStatusText();
  47. emit updated();
  48. emit finished(phase == ENDED_SUCCESSFULLY);
  49. }
  50. else if (!manualTrigger)
  51. {
  52. // Progressbar steps in phase
  53. int phaseStep = m_maximumValue / m_phasesInAction;
  54. // Progressbar steps in one message. Phases have very different amount of messages,
  55. // so we'll calculate an approximation for this.
  56. int messageStep = phaseStep / phaseLength(phase);
  57. int currentValue = m_currentValue;
  58. int nextPhaseStart = (currentValue / phaseStep + 1) * phaseStep;
  59. if (phase != m_lastPhase)
  60. {
  61. // Set the progressbar to the beginning of the next step
  62. m_statusText = m_generator.getStatusText();
  63. m_currentValue = nextPhaseStart;
  64. emit updated();
  65. }
  66. else
  67. {
  68. // Update at every step, but only up to the next phase's start
  69. if ((currentValue + messageStep) < nextPhaseStart)
  70. {
  71. m_currentValue = currentValue + messageStep;
  72. emit updated();
  73. }
  74. }
  75. }
  76. m_lastPhase = phase;
  77. }
  78. void SymbianStatusUpdater::setIndefiniteProgress(bool indefinite)
  79. {
  80. m_indefinite = indefinite;
  81. }
  82. void SymbianStatusUpdater::setPhases(int phases)
  83. {
  84. m_phasesInAction = phases;
  85. }
  86. void SymbianStatusUpdater::reset()
  87. {
  88. m_currentValue = 0;
  89. m_logSize = 0;
  90. m_phase = INITIAL;
  91. m_lastPhase = INITIAL;
  92. m_statusText = m_generator.getStatusText();
  93. m_indefinite = false;
  94. emit updated();
  95. }
  96. int SymbianStatusUpdater::maximumProgress()
  97. {
  98. return m_maximumValue;
  99. }
  100. int SymbianStatusUpdater::currentProgress()
  101. {
  102. return m_currentValue;
  103. }
  104. QString SymbianStatusUpdater::statusText()
  105. {
  106. return m_statusText;
  107. }
  108. int SymbianStatusUpdater::logSize()
  109. {
  110. return m_logSize;
  111. }
  112. QFileInfo SymbianStatusUpdater::pkgFileInfo()
  113. {
  114. // Look for the sis file name in the lastlog
  115. QRegExp rx;
  116. rx.setPattern(".*Successfully created.*([^ ]+\\.sis).*");
  117. for (int i = 0;i < LASTLOG_ITEMS; i++)
  118. {
  119. if (rx.indexIn(m_lastLog[i]) != -1)
  120. {
  121. QFileInfo info(m_generator.generatorData().projectDirectory() + "/" + rx.cap(1));
  122. if (info.exists())
  123. {
  124. return info;
  125. }
  126. }
  127. }
  128. return QFileInfo();
  129. }
  130. void SymbianStatusUpdater::increase(QString message)
  131. {
  132. // Set the last log messages to an array
  133. m_lastLog[m_lastLogCounter] = message;
  134. m_lastLogCounter = (m_lastLogCounter + 1) % LASTLOG_ITEMS;
  135. // See if progress is on and status should be updated
  136. if (m_phasesInAction > 0)
  137. {
  138. m_logSize++;
  139. updateGeneratorStatus(false);
  140. }
  141. }
  142. void SymbianStatusUpdater::start(GeneratorTarget target)
  143. {
  144. reset();
  145. switch (target)
  146. {
  147. case PREVIEW:
  148. m_phasesInAction = 3;
  149. break;
  150. case BUILD:
  151. m_phasesInAction = 9;
  152. break;
  153. case REBUILD:
  154. m_phasesInAction = 8;
  155. break;
  156. default:
  157. m_indefinite = true;
  158. break;
  159. }
  160. }
  161. void SymbianStatusUpdater::stop()
  162. {
  163. updateGeneratorStatus(true);
  164. }
  165. int SymbianStatusUpdater::phaseLength(GeneratorPhase phase)
  166. {
  167. switch (phase.m_phase)
  168. {
  169. case INITIAL:
  170. return 1;
  171. case UNZIP_WIDGET:
  172. return 150;
  173. case QMAKE_APP:
  174. return 10;
  175. case MAKE_APP:
  176. return 100;
  177. case MAKESIS_APP:
  178. return 6;
  179. case ENDED_SUCCESSFULLY:
  180. return 1;
  181. case ENDED_WITH_ERRORS:
  182. return 1;
  183. default:
  184. return 10;
  185. }
  186. }