rcmaemo5qtprojectgenerator.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. #include <QApplication>
  2. #include <QDir>
  3. #include "qtprojectgeneratorfactory.h"
  4. #include "rcbuildtask.h"
  5. #include "rcsession.h"
  6. #include "fileutilities.h"
  7. #include "defines.h"
  8. #include "rcmaemo5defines.h"
  9. #include "rcmaemo5qtprojectgenerator.h"
  10. #include "rcmaemo5settingsgui.h"
  11. #include "common/networksettingsdialog.h"
  12. #include "maemo5/maemo5statusupdater.h"
  13. RcMaemo5QtProjectGenerator::RcMaemo5QtProjectGenerator(const QString & platformId,
  14. GeneratorOutputView & outputView,
  15. QObject * parent)
  16. : Maemo5QtProjectGenerator(outputView,
  17. parent)
  18. , m_rcSession(NULL)
  19. , m_rcBuildTask(NULL)
  20. {
  21. // the platform id is actually the wccParams plus a prefix
  22. m_wccParams = platformId.mid(QString(DYN_BUILDTARGET).length());
  23. m_generatorData.setRemotelyCompiled(true);
  24. }
  25. RcMaemo5QtProjectGenerator::~RcMaemo5QtProjectGenerator()
  26. {
  27. delete m_rcBuildTask;
  28. m_rcBuildTask = NULL;
  29. }
  30. IStatusUpdater * RcMaemo5QtProjectGenerator::createStatusUpdater(QObject * parent)
  31. {
  32. // TODO for now, we reuse the same status updater as Maemo5QtProjectGenerator
  33. // later, we should probably need our own one. Reason: different amount
  34. // of log messages, different way of providing pkgFileInfo() about a successful
  35. // build, etc.
  36. return new Maemo5StatusUpdater(*this,
  37. parent);
  38. }
  39. void RcMaemo5QtProjectGenerator::build(const QString & widgetFile,
  40. RcSession & rcSession)
  41. {
  42. m_rcSession = &rcSession;
  43. if (!m_rcSession->isSignedOn())
  44. {
  45. NetworkSettingsDialog
  46. nsDlg(m_rcSession,
  47. NULL);
  48. nsDlg.exec();
  49. if (!nsDlg.justSignedIn())
  50. {
  51. registerStatus(false);
  52. m_outputView.printOutput("Connecting to remote compiler failed.");
  53. emit finished(EXIT_FAILURE);
  54. return;
  55. }
  56. }
  57. Maemo5QtProjectGenerator::build(widgetFile,
  58. rcSession);
  59. }
  60. void RcMaemo5QtProjectGenerator::rebuild(RcSession & rcSession)
  61. {
  62. m_rcSession = &rcSession;
  63. // TODO factor out with the above code
  64. if (!m_rcSession->isSignedOn())
  65. {
  66. NetworkSettingsDialog
  67. nsDlg(m_rcSession,
  68. NULL);
  69. nsDlg.exec();
  70. if (!nsDlg.justSignedIn())
  71. {
  72. registerStatus(false);
  73. m_outputView.printOutput("Connecting to remote compiler failed.");
  74. emit finished(EXIT_FAILURE);
  75. return;
  76. }
  77. }
  78. Maemo5QtProjectGenerator::rebuild(rcSession);
  79. }
  80. QString RcMaemo5QtProjectGenerator::getStatusText() const
  81. {
  82. QString statusText;
  83. switch(m_currentGeneratorPhase.m_phase)
  84. {
  85. case RCM5_UNZIP_WIDGET:
  86. statusText = HAG_STATUS_EXTRACTING_WIDGET;
  87. break;
  88. case RCM5_DPKG_BUILDPACKAGE:
  89. statusText = "Starting remote build task";
  90. break;
  91. case RCM5_PKGZIPPING:
  92. statusText = "Zipping package to upload";
  93. break;
  94. case RCM5_PKGUPLOADING_WAITING:
  95. statusText = "Uploading & waiting for remote build";
  96. break;
  97. case RCM5_DOWNLOADING:
  98. statusText = "Downloading built package";
  99. break;
  100. case RCM5_INITIAL:
  101. statusText = HAG_STATUS_IDLE;
  102. break;
  103. case RCM5_ENDED_SUCCESSFULLY:
  104. statusText = HAG_STATUS_COMPLETED_OK;
  105. break;
  106. case RCM5_ENDED_WITH_ERRORS:
  107. statusText = HAG_STATUS_COMPLETED_NOTOK;
  108. break;
  109. }
  110. return statusText;
  111. }
  112. QWidget * RcMaemo5QtProjectGenerator::createSettingsWidget(const QString & widgetFile,
  113. QWidget * parent) const
  114. {
  115. const QString
  116. TODO_COPYRIGHT_DIR("/templates/copyright/");
  117. QString
  118. copyrightDirPath = QApplication::applicationDirPath() + TODO_COPYRIGHT_DIR;
  119. QDir
  120. copyRightDir(copyrightDirPath);
  121. QList<QString>
  122. licenses = copyRightDir.entryList(QDir::Dirs
  123. | QDir::NoDotAndDotDot);
  124. // OBS (const_cast<RcMaemo5QtProjectGenerator*>(this))->sniffAppNames(widgetFile);
  125. QPair<QString, QString>
  126. appNames = FileUtilities::sniffAppNames(widgetFile);
  127. QWidget
  128. * rv = new RcMaemo5SettingsGui(licenses,
  129. // OBS m_appName,
  130. appNames.first,
  131. parent);
  132. return rv;
  133. }
  134. void RcMaemo5QtProjectGenerator::saveSettings(QWidget * settingsWidget) const
  135. {
  136. RcMaemo5SettingsGui
  137. * rcMaemo5SettingsGui = dynamic_cast<RcMaemo5SettingsGui*>(settingsWidget);
  138. if (rcMaemo5SettingsGui != NULL)
  139. {
  140. rcMaemo5SettingsGui->saveSettings();
  141. }
  142. }
  143. QStringList RcMaemo5QtProjectGenerator::errorsForTarget(GeneratorTarget generatorTarget) const
  144. {
  145. QStringList
  146. rv;
  147. QString
  148. forumNokiaUserName = Settings::get(Settings::ForumNokiaUserName).toString();
  149. int
  150. proxyConfig = Settings::get(Settings::ProxyConfig).toInt();
  151. if (forumNokiaUserName.length() == 0
  152. || proxyConfig == Settings::PCK_UndefinedProxyConfig)
  153. {
  154. rv.append("Network settings undefined");
  155. }
  156. QFile log(Settings::get(Settings::LogFilePath).toString());
  157. if (!log.open(QIODevice::ReadWrite | QIODevice::Text))
  158. {
  159. // Failed to open the log file
  160. if (generatorTarget != NO_TARGET)
  161. {
  162. rv.append("Failed to open log file for writing! Check settings.");
  163. }
  164. }
  165. log.close();
  166. if (Settings::get(Settings::HybridAuthor).toString().length() == 0)
  167. {
  168. rv.append("Author is not set");
  169. }
  170. if (Settings::get(Settings::HybridEmail).toString().length() == 0)
  171. {
  172. rv.append("Author email is not set");
  173. }
  174. else
  175. {
  176. QRegExp
  177. validEmailRx("(\\w|\\.-)+@(\\w|\\.)+");
  178. if (validEmailRx.indexIn(Settings::get(Settings::HybridEmail).toString()) == -1)
  179. {
  180. rv.append("Author email is set, but seems broken");
  181. }
  182. }
  183. // TODO - check long and short descriptions too
  184. return rv;
  185. }
  186. void RcMaemo5QtProjectGenerator::startBuild()
  187. {
  188. m_currentGeneratorPhase = RCM5_DPKG_BUILDPACKAGE;
  189. m_rcBuildTask = new RcBuildTask(this->m_outputView,
  190. *this->m_rcSession,
  191. this->m_appName,
  192. this->m_generatorData.projectDirectory(),
  193. this);
  194. connect(m_rcBuildTask,
  195. SIGNAL(buildCompleted(bool,QString)),
  196. this,
  197. SLOT(buildCompletedSlot(bool,QString)));
  198. connect(m_rcBuildTask,
  199. SIGNAL(zipping()),
  200. this,
  201. SLOT(zippingSlot()));
  202. connect(m_rcBuildTask,
  203. SIGNAL(uploadingAndWaiting()),
  204. this,
  205. SLOT(uploadingAndWaitingSlot()));
  206. connect(m_rcBuildTask,
  207. SIGNAL(downloading()),
  208. this,
  209. SLOT(downloadingSlot()));
  210. QDir
  211. dloadDir = this->m_generatorData.projectDirectory();
  212. dloadDir.cdUp();
  213. m_rcBuildTask->startBuilding(m_wccParams,
  214. dloadDir.absolutePath());
  215. }
  216. void RcMaemo5QtProjectGenerator::zippingSlot()
  217. {
  218. m_currentGeneratorPhase = RCM5_PKGZIPPING;
  219. }
  220. void RcMaemo5QtProjectGenerator::uploadingAndWaitingSlot()
  221. {
  222. m_currentGeneratorPhase = RCM5_PKGUPLOADING_WAITING;
  223. }
  224. void RcMaemo5QtProjectGenerator::downloadingSlot()
  225. {
  226. m_currentGeneratorPhase = RCM5_DOWNLOADING;
  227. }
  228. void RcMaemo5QtProjectGenerator::buildCompletedSlot(bool success,
  229. QString downloadedFile)
  230. {
  231. delete m_rcBuildTask;
  232. m_rcBuildTask = NULL;
  233. if (success)
  234. {
  235. m_currentGeneratorPhase = RCM5_ENDED_SUCCESSFULLY;
  236. m_outputView.printOutput(QString("Remote build succeeded, "
  237. "file downloaded to %1").arg(downloadedFile));
  238. emit finished(EXIT_SUCCESS);
  239. }
  240. else
  241. {
  242. m_currentGeneratorPhase = RCM5_ENDED_WITH_ERRORS;
  243. registerStatus(false);
  244. m_outputView.printOutput("Remote build failed.");
  245. emit finished(EXIT_FAILURE);
  246. }
  247. }