CMakeSetupDialog.cxx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "CMakeSetupDialog.h"
  14. #include <QFileDialog>
  15. #include <QProgressBar>
  16. #include <QMessageBox>
  17. #include <QStatusBar>
  18. #include <QToolButton>
  19. #include <QDialogButtonBox>
  20. #include <QCloseEvent>
  21. #include <QCoreApplication>
  22. #include <QCompleter>
  23. #include <QDirModel>
  24. #include <QSettings>
  25. #include <QMenu>
  26. #include <QMenuBar>
  27. #include <QDragEnterEvent>
  28. #include <QMimeData>
  29. #include <QUrl>
  30. #include "QCMake.h"
  31. #include "QCMakeCacheView.h"
  32. #include "AddCacheEntry.h"
  33. QCMakeThread::QCMakeThread(QObject* p)
  34. : QThread(p), CMakeInstance(NULL)
  35. {
  36. }
  37. QCMake* QCMakeThread::cmakeInstance() const
  38. {
  39. return this->CMakeInstance;
  40. }
  41. void QCMakeThread::processEvents()
  42. {
  43. QCoreApplication::processEvents();
  44. }
  45. void QCMakeThread::run()
  46. {
  47. this->CMakeInstance = new QCMake;
  48. // make the cmake thread to process events it receives from the GUI thread
  49. QObject::connect(this->CMakeInstance, SIGNAL(progressChanged(QString, float)),
  50. this, SLOT(processEvents()), Qt::DirectConnection);
  51. QObject::connect(this->CMakeInstance, SIGNAL(outputMessage(QString)),
  52. this, SLOT(processEvents()), Qt::DirectConnection);
  53. // emit that this cmake thread is ready for use
  54. emit this->cmakeInitialized();
  55. this->exec();
  56. delete this->CMakeInstance;
  57. this->CMakeInstance = NULL;
  58. }
  59. CMakeSetupDialog::CMakeSetupDialog()
  60. : ExitAfterGenerate(true), CacheModified(false), CurrentState(Interrupting)
  61. {
  62. // create the GUI
  63. QSettings settings;
  64. settings.beginGroup("Settings/StartPath");
  65. int h = settings.value("Height", 500).toInt();
  66. int w = settings.value("Width", 700).toInt();
  67. this->resize(w, h);
  68. QWidget* cont = new QWidget(this);
  69. this->setupUi(cont);
  70. this->Splitter->setStretchFactor(0, 3);
  71. this->Splitter->setStretchFactor(1, 1);
  72. this->setCentralWidget(cont);
  73. this->ProgressBar->reset();
  74. this->RemoveEntry->setEnabled(false);
  75. this->AddEntry->setEnabled(false);
  76. QMenu* FileMenu = this->menuBar()->addMenu(tr("&File"));
  77. this->ReloadCacheAction = FileMenu->addAction(tr("&Reload Cache"));
  78. QObject::connect(this->ReloadCacheAction, SIGNAL(triggered(bool)),
  79. this, SLOT(doReloadCache()));
  80. this->DeleteCacheAction = FileMenu->addAction(tr("&Delete Cache"));
  81. QObject::connect(this->DeleteCacheAction, SIGNAL(triggered(bool)),
  82. this, SLOT(doDeleteCache()));
  83. this->ExitAction = FileMenu->addAction(tr("&Exit"));
  84. QObject::connect(this->ExitAction, SIGNAL(triggered(bool)),
  85. this, SLOT(close()));
  86. QMenu* ToolsMenu = this->menuBar()->addMenu(tr("&Tools"));
  87. this->ConfigureAction = ToolsMenu->addAction(tr("&Configure"));
  88. QObject::connect(this->ConfigureAction, SIGNAL(triggered(bool)),
  89. this, SLOT(doConfigure()));
  90. this->GenerateAction = ToolsMenu->addAction(tr("&Generate"));
  91. QObject::connect(this->GenerateAction, SIGNAL(triggered(bool)),
  92. this, SLOT(doGenerate()));
  93. QMenu* HelpMenu = this->menuBar()->addMenu(tr("&Help"));
  94. QAction* a = HelpMenu->addAction(tr("About"));
  95. QObject::connect(a, SIGNAL(triggered(bool)),
  96. this, SLOT(doAbout()));
  97. a = HelpMenu->addAction(tr("Help"));
  98. QObject::connect(a, SIGNAL(triggered(bool)),
  99. this, SLOT(doHelp()));
  100. this->setAcceptDrops(true);
  101. // get the saved binary directories
  102. QStringList buildPaths = this->loadBuildPaths();
  103. this->BinaryDirectory->addItems(buildPaths);
  104. QCompleter* compBinaryDir = new QCompleter(this);
  105. QDirModel* modelBinaryDir = new QDirModel(compBinaryDir);
  106. modelBinaryDir->setFilter(QDir::NoDotAndDotDot | QDir::Dirs);
  107. compBinaryDir->setModel(modelBinaryDir);
  108. this->BinaryDirectory->setCompleter(compBinaryDir);
  109. QCompleter* compSourceDir = new QCompleter(this);
  110. QDirModel* modelSourceDir = new QDirModel(compSourceDir);
  111. modelSourceDir->setFilter(QDir::NoDotAndDotDot | QDir::Dirs);
  112. compSourceDir->setModel(modelSourceDir);
  113. this->SourceDirectory->setCompleter(compSourceDir);
  114. // start the cmake worker thread
  115. this->CMakeThread = new QCMakeThread(this);
  116. QObject::connect(this->CMakeThread, SIGNAL(cmakeInitialized()),
  117. this, SLOT(initialize()), Qt::QueuedConnection);
  118. this->CMakeThread->start();
  119. this->enterState(ReadyConfigure);
  120. }
  121. void CMakeSetupDialog::initialize()
  122. {
  123. // now the cmake worker thread is running, lets make our connections to it
  124. QObject::connect(this->CMakeThread->cmakeInstance(),
  125. SIGNAL(propertiesChanged(const QCMakeCachePropertyList&)),
  126. this->CacheValues->cacheModel(),
  127. SLOT(setProperties(const QCMakeCachePropertyList&)));
  128. QObject::connect(this->ConfigureButton, SIGNAL(clicked(bool)),
  129. this, SLOT(doConfigure()));
  130. QObject::connect(this->CMakeThread->cmakeInstance(),
  131. SIGNAL(configureDone(int)),
  132. this, SLOT(finishConfigure(int)));
  133. QObject::connect(this->CMakeThread->cmakeInstance(),
  134. SIGNAL(generateDone(int)),
  135. this, SLOT(finishGenerate(int)));
  136. QObject::connect(this->GenerateButton, SIGNAL(clicked(bool)),
  137. this, SLOT(doGenerate()));
  138. QObject::connect(this->BrowseSourceDirectoryButton, SIGNAL(clicked(bool)),
  139. this, SLOT(doSourceBrowse()));
  140. QObject::connect(this->BrowseBinaryDirectoryButton, SIGNAL(clicked(bool)),
  141. this, SLOT(doBinaryBrowse()));
  142. QObject::connect(this->BinaryDirectory, SIGNAL(editTextChanged(QString)),
  143. this, SLOT(onBinaryDirectoryChanged(QString)));
  144. QObject::connect(this->SourceDirectory, SIGNAL(textChanged(QString)),
  145. this, SLOT(onSourceDirectoryChanged(QString)));
  146. QObject::connect(this->CMakeThread->cmakeInstance(),
  147. SIGNAL(sourceDirChanged(QString)),
  148. this, SLOT(updateSourceDirectory(QString)));
  149. QObject::connect(this->CMakeThread->cmakeInstance(),
  150. SIGNAL(progressChanged(QString, float)),
  151. this, SLOT(showProgress(QString,float)));
  152. QObject::connect(this->CMakeThread->cmakeInstance(),
  153. SIGNAL(errorMessage(QString)),
  154. this, SLOT(error(QString)));
  155. QObject::connect(this->CMakeThread->cmakeInstance(),
  156. SIGNAL(outputMessage(QString)),
  157. this->Output, SLOT(append(QString)));
  158. QObject::connect(this->Advanced, SIGNAL(clicked(bool)),
  159. this->CacheValues, SLOT(setShowAdvanced(bool)));
  160. QObject::connect(this->Search, SIGNAL(textChanged(QString)),
  161. this->CacheValues, SLOT(setSearchFilter(QString)));
  162. QObject::connect(this->CMakeThread->cmakeInstance(),
  163. SIGNAL(generatorChanged(QString)),
  164. this, SLOT(updateGeneratorLabel(QString)));
  165. this->updateGeneratorLabel(QString());
  166. QObject::connect(this->CacheValues->cacheModel(),
  167. SIGNAL(dataChanged(QModelIndex,QModelIndex)),
  168. this, SLOT(setCacheModified()));
  169. QObject::connect(this->CacheValues->selectionModel(),
  170. SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
  171. this, SLOT(selectionChanged()));
  172. QObject::connect(this->RemoveEntry, SIGNAL(clicked(bool)),
  173. this, SLOT(removeSelectedCacheEntries()));
  174. QObject::connect(this->AddEntry, SIGNAL(clicked(bool)),
  175. this, SLOT(addCacheEntry()));
  176. if(!this->SourceDirectory->text().isEmpty() ||
  177. !this->BinaryDirectory->lineEdit()->text().isEmpty())
  178. {
  179. this->onSourceDirectoryChanged(this->SourceDirectory->text());
  180. this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
  181. }
  182. else
  183. {
  184. this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
  185. }
  186. }
  187. CMakeSetupDialog::~CMakeSetupDialog()
  188. {
  189. QSettings settings;
  190. settings.beginGroup("Settings/StartPath");
  191. settings.setValue("Height", this->height());
  192. settings.setValue("Width", this->width());
  193. // wait for thread to stop
  194. this->CMakeThread->quit();
  195. this->CMakeThread->wait();
  196. }
  197. void CMakeSetupDialog::doConfigure()
  198. {
  199. if(this->CurrentState == Configuring)
  200. {
  201. // stop configure
  202. doInterrupt();
  203. return;
  204. }
  205. QString bindir = this->CMakeThread->cmakeInstance()->binaryDirectory();
  206. QDir dir(bindir);
  207. if(!dir.exists())
  208. {
  209. QString message = tr("Build directory does not exist, "
  210. "should I create it?\n\n"
  211. "Directory: ");
  212. message += bindir;
  213. QString title = tr("Create Directory");
  214. QMessageBox::StandardButton btn;
  215. btn = QMessageBox::information(this, title, message,
  216. QMessageBox::Yes | QMessageBox::No);
  217. if(btn == QMessageBox::No)
  218. {
  219. return;
  220. }
  221. dir.mkpath(".");
  222. }
  223. // prompt for generator if one doesn't exist
  224. if(this->CMakeThread->cmakeInstance()->generator().isEmpty())
  225. {
  226. this->promptForGenerator();
  227. }
  228. // remember path
  229. this->addBinaryPath(dir.absolutePath());
  230. this->enterState(Configuring);
  231. this->Output->clear();
  232. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  233. "setProperties", Qt::QueuedConnection,
  234. Q_ARG(QCMakeCachePropertyList,
  235. this->CacheValues->cacheModel()->properties()));
  236. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  237. "configure", Qt::QueuedConnection);
  238. }
  239. void CMakeSetupDialog::finishConfigure(int err)
  240. {
  241. if(0 == err && 0 == this->CacheValues->cacheModel()->newCount())
  242. {
  243. this->enterState(ReadyGenerate);
  244. }
  245. else
  246. {
  247. this->enterState(ReadyConfigure);
  248. this->CacheValues->scrollToTop();
  249. }
  250. if(err != 0)
  251. {
  252. QMessageBox::critical(this, tr("Error"),
  253. tr("Error in configuration process, project files may be invalid"),
  254. QMessageBox::Ok);
  255. }
  256. }
  257. void CMakeSetupDialog::finishGenerate(int err)
  258. {
  259. this->enterState(ReadyGenerate);
  260. if(err != 0)
  261. {
  262. QMessageBox::critical(this, tr("Error"),
  263. tr("Error in generation process, project files may be invalid"),
  264. QMessageBox::Ok);
  265. }
  266. }
  267. void CMakeSetupDialog::doGenerate()
  268. {
  269. if(this->CurrentState == Generating)
  270. {
  271. // stop generate
  272. doInterrupt();
  273. return;
  274. }
  275. this->enterState(Generating);
  276. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  277. "generate", Qt::QueuedConnection);
  278. }
  279. void CMakeSetupDialog::closeEvent(QCloseEvent* e)
  280. {
  281. // don't close if we're busy
  282. if(this->CurrentState == Configuring || this->CurrentState == Generating)
  283. {
  284. e->ignore();
  285. }
  286. // prompt for close if there are unsaved changes
  287. if(this->CacheModified)
  288. {
  289. QString message = tr("You have changed options but not rebuilt, "
  290. "are you sure you want to exit?");
  291. QString title = tr("Confirm Exit");
  292. QMessageBox::StandardButton btn;
  293. btn = QMessageBox::critical(this, title, message,
  294. QMessageBox::Yes | QMessageBox::No);
  295. if(btn == QMessageBox::No)
  296. {
  297. e->ignore();
  298. }
  299. }
  300. }
  301. void CMakeSetupDialog::doHelp()
  302. {
  303. QString msg = tr("CMake is used to configure and generate build files for "
  304. "software projects. The basic steps for configuring a project are as "
  305. "follows:\r\n\r\n1. Select the source directory for the project. This should "
  306. "contain the CMakeLists.txt files for the project.\r\n\r\n2. Select the build "
  307. "directory for the project. This is the directory where the project will be "
  308. "built. It can be the same or a different directory than the source "
  309. "directory. For easy clean up, a separate build directory is recommended. "
  310. "CMake will create the directory if it does not exist.\r\n\r\n3. Once the "
  311. "source and binary directories are selected, it is time to press the "
  312. "Configure button. This will cause CMake to read all of the input files and "
  313. "discover all the variables used by the project. The first time a variable "
  314. "is displayed it will be in Red. Users should inspect red variables making "
  315. "sure the values are correct. For some projects the Configure process can "
  316. "be iterative, so continue to press the Configure button until there are no "
  317. "longer red entries.\r\n\r\n4. Once there are no longer red entries, you "
  318. "should click the Generate button. This will write the build files to the build "
  319. "directory.");
  320. QDialog dialog;
  321. dialog.setWindowTitle(tr("CMakeSetup Help"));
  322. QVBoxLayout* l = new QVBoxLayout(&dialog);
  323. QLabel* lab = new QLabel(&dialog);
  324. l->addWidget(lab);
  325. lab->setText(msg);
  326. lab->setWordWrap(true);
  327. QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
  328. Qt::Horizontal, &dialog);
  329. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  330. l->addWidget(btns);
  331. dialog.exec();
  332. }
  333. void CMakeSetupDialog::doInterrupt()
  334. {
  335. this->enterState(Interrupting);
  336. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  337. "interrupt", Qt::QueuedConnection);
  338. }
  339. void CMakeSetupDialog::doSourceBrowse()
  340. {
  341. QString dir = QFileDialog::getExistingDirectory(this,
  342. tr("Enter Path to Source"), this->SourceDirectory->text());
  343. if(!dir.isEmpty())
  344. {
  345. this->setSourceDirectory(dir);
  346. }
  347. }
  348. void CMakeSetupDialog::updateSourceDirectory(const QString& dir)
  349. {
  350. if(this->SourceDirectory->text() != dir)
  351. {
  352. this->setSourceDirectory(dir);
  353. }
  354. }
  355. void CMakeSetupDialog::doBinaryBrowse()
  356. {
  357. QString dir = QFileDialog::getExistingDirectory(this,
  358. tr("Enter Path to Build"), this->BinaryDirectory->currentText());
  359. if(!dir.isEmpty() && dir != this->BinaryDirectory->currentText())
  360. {
  361. this->setBinaryDirectory(dir);
  362. }
  363. }
  364. void CMakeSetupDialog::setBinaryDirectory(const QString& dir)
  365. {
  366. this->BinaryDirectory->setEditText(dir);
  367. }
  368. void CMakeSetupDialog::onSourceDirectoryChanged(const QString& dir)
  369. {
  370. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  371. "setSourceDirectory", Qt::QueuedConnection, Q_ARG(QString, dir));
  372. }
  373. void CMakeSetupDialog::onBinaryDirectoryChanged(const QString& dir)
  374. {
  375. this->CacheModified = false;
  376. this->CacheValues->cacheModel()->clear();
  377. this->Output->clear();
  378. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  379. "setBinaryDirectory", Qt::QueuedConnection, Q_ARG(QString, dir));
  380. }
  381. void CMakeSetupDialog::setSourceDirectory(const QString& dir)
  382. {
  383. this->SourceDirectory->setText(dir);
  384. }
  385. void CMakeSetupDialog::showProgress(const QString& /*msg*/, float percent)
  386. {
  387. this->ProgressBar->setValue(qRound(percent * 100));
  388. }
  389. void CMakeSetupDialog::error(const QString& message)
  390. {
  391. this->Output->append(QString("<b><font color=red>%1</font></b>").arg(message));
  392. }
  393. void CMakeSetupDialog::setEnabledState(bool enabled)
  394. {
  395. // disable parts of the GUI during configure/generate
  396. this->CacheValues->cacheModel()->setEditEnabled(enabled);
  397. this->SourceDirectory->setEnabled(enabled);
  398. this->BrowseSourceDirectoryButton->setEnabled(enabled);
  399. this->BinaryDirectory->setEnabled(enabled);
  400. this->BrowseBinaryDirectoryButton->setEnabled(enabled);
  401. this->ReloadCacheAction->setEnabled(enabled);
  402. this->DeleteCacheAction->setEnabled(enabled);
  403. this->ExitAction->setEnabled(enabled);
  404. this->ConfigureAction->setEnabled(enabled);
  405. this->AddEntry->setEnabled(enabled);
  406. this->RemoveEntry->setEnabled(false); // let selection re-enable it
  407. }
  408. void CMakeSetupDialog::promptForGenerator()
  409. {
  410. QSettings settings;
  411. settings.beginGroup("Settings/StartPath");
  412. QString lastGen = settings.value("LastGenerator").toString();
  413. QStringList gens = this->CMakeThread->cmakeInstance()->availableGenerators();
  414. QDialog dialog;
  415. dialog.setWindowTitle(tr("CMakeSetup choose generator"));
  416. QLabel* lab = new QLabel(&dialog);
  417. lab->setText(tr("Please select what build system you want CMake to generate files for.\n"
  418. "You should select the tool that you will use to build the project.\n"
  419. "Press OK once you have made your selection."));
  420. QComboBox* combo = new QComboBox(&dialog);
  421. combo->addItems(gens);
  422. int idx = combo->findText(lastGen);
  423. if(idx != -1)
  424. {
  425. combo->setCurrentIndex(idx);
  426. }
  427. QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
  428. Qt::Horizontal, &dialog);
  429. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  430. QVBoxLayout* l = new QVBoxLayout(&dialog);
  431. l->addWidget(lab);
  432. l->addWidget(combo);
  433. l->addWidget(btns);
  434. dialog.exec();
  435. lastGen = combo->currentText();
  436. settings.setValue("LastGenerator", lastGen);
  437. this->CMakeThread->cmakeInstance()->setGenerator(combo->currentText());
  438. }
  439. void CMakeSetupDialog::updateGeneratorLabel(const QString& gen)
  440. {
  441. QString str = tr("Current Generator: ");
  442. if(gen.isEmpty())
  443. {
  444. str += tr("None");
  445. }
  446. else
  447. {
  448. str += gen;
  449. }
  450. this->Generator->setText(str);
  451. }
  452. void CMakeSetupDialog::doReloadCache()
  453. {
  454. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  455. "reloadCache", Qt::QueuedConnection);
  456. }
  457. void CMakeSetupDialog::doDeleteCache()
  458. {
  459. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  460. "deleteCache", Qt::QueuedConnection);
  461. }
  462. void CMakeSetupDialog::doAbout()
  463. {
  464. QString msg = "CMakeSetup\nwww.cmake.org";
  465. QDialog dialog;
  466. dialog.setWindowTitle(tr("About CMakeSetup"));
  467. QVBoxLayout* l = new QVBoxLayout(&dialog);
  468. QLabel* lab = new QLabel(&dialog);
  469. l->addWidget(lab);
  470. lab->setText(msg);
  471. lab->setWordWrap(true);
  472. QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
  473. Qt::Horizontal, &dialog);
  474. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  475. l->addWidget(btns);
  476. dialog.exec();
  477. }
  478. void CMakeSetupDialog::setExitAfterGenerate(bool b)
  479. {
  480. this->ExitAfterGenerate = b;
  481. }
  482. void CMakeSetupDialog::addBinaryPath(const QString& path)
  483. {
  484. QString cleanpath = QDir::cleanPath(path);
  485. // update UI
  486. this->BinaryDirectory->blockSignals(true);
  487. int idx = this->BinaryDirectory->findText(cleanpath);
  488. if(idx != -1)
  489. {
  490. this->BinaryDirectory->removeItem(idx);
  491. }
  492. this->BinaryDirectory->insertItem(0, cleanpath);
  493. this->BinaryDirectory->setCurrentIndex(0);
  494. this->BinaryDirectory->blockSignals(false);
  495. // save to registry
  496. QStringList buildPaths = this->loadBuildPaths();
  497. buildPaths.removeAll(cleanpath);
  498. buildPaths.prepend(cleanpath);
  499. this->saveBuildPaths(buildPaths);
  500. }
  501. void CMakeSetupDialog::dragEnterEvent(QDragEnterEvent* e)
  502. {
  503. if(this->CurrentState != ReadyConfigure ||
  504. this->CurrentState != ReadyGenerate)
  505. {
  506. e->ignore();
  507. return;
  508. }
  509. const QMimeData* dat = e->mimeData();
  510. QList<QUrl> urls = dat->urls();
  511. QString file = urls.count() ? urls[0].toLocalFile() : QString();
  512. if(!file.isEmpty() &&
  513. (file.endsWith("CMakeCache.txt", Qt::CaseInsensitive) ||
  514. file.endsWith("CMakeLists.txt", Qt::CaseInsensitive) ) )
  515. {
  516. e->accept();
  517. }
  518. else
  519. {
  520. e->ignore();
  521. }
  522. }
  523. void CMakeSetupDialog::dropEvent(QDropEvent* e)
  524. {
  525. if(this->CurrentState != ReadyConfigure ||
  526. this->CurrentState != ReadyGenerate)
  527. {
  528. return;
  529. }
  530. const QMimeData* dat = e->mimeData();
  531. QList<QUrl> urls = dat->urls();
  532. QString file = urls.count() ? urls[0].toLocalFile() : QString();
  533. if(file.endsWith("CMakeCache.txt", Qt::CaseInsensitive))
  534. {
  535. QFileInfo info(file);
  536. if(this->CMakeThread->cmakeInstance()->binaryDirectory() != info.absolutePath())
  537. {
  538. this->setBinaryDirectory(info.absolutePath());
  539. }
  540. }
  541. else if(file.endsWith("CMakeLists.txt", Qt::CaseInsensitive))
  542. {
  543. QFileInfo info(file);
  544. if(this->CMakeThread->cmakeInstance()->binaryDirectory() != info.absolutePath())
  545. {
  546. this->setSourceDirectory(info.absolutePath());
  547. this->setBinaryDirectory(info.absolutePath());
  548. }
  549. }
  550. }
  551. QStringList CMakeSetupDialog::loadBuildPaths()
  552. {
  553. QSettings settings;
  554. settings.beginGroup("Settings/StartPath");
  555. QStringList buildPaths;
  556. for(int i=0; i<10; i++)
  557. {
  558. QString p = settings.value(QString("WhereBuild%1").arg(i)).toString();
  559. if(!p.isEmpty())
  560. {
  561. buildPaths.append(p);
  562. }
  563. }
  564. return buildPaths;
  565. }
  566. void CMakeSetupDialog::saveBuildPaths(const QStringList& paths)
  567. {
  568. QSettings settings;
  569. settings.beginGroup("Settings/StartPath");
  570. int num = paths.count();
  571. if(num > 10)
  572. {
  573. num = 10;
  574. }
  575. for(int i=0; i<num; i++)
  576. {
  577. settings.setValue(QString("WhereBuild%1").arg(i), paths[i]);
  578. }
  579. }
  580. void CMakeSetupDialog::setCacheModified()
  581. {
  582. this->CacheModified = true;
  583. this->enterState(ReadyConfigure);
  584. }
  585. void CMakeSetupDialog::removeSelectedCacheEntries()
  586. {
  587. QModelIndexList idxs = this->CacheValues->selectionModel()->selectedRows();
  588. QList<QPersistentModelIndex> pidxs;
  589. foreach(QModelIndex i, idxs)
  590. {
  591. pidxs.append(i);
  592. }
  593. foreach(QPersistentModelIndex pi, pidxs)
  594. {
  595. this->CacheValues->model()->removeRow(pi.row());
  596. }
  597. }
  598. void CMakeSetupDialog::selectionChanged()
  599. {
  600. QModelIndexList idxs = this->CacheValues->selectionModel()->selectedRows();
  601. if(idxs.count() &&
  602. (this->CurrentState == ReadyConfigure ||
  603. this->CurrentState == ReadyGenerate) )
  604. {
  605. this->RemoveEntry->setEnabled(true);
  606. }
  607. else
  608. {
  609. this->RemoveEntry->setEnabled(false);
  610. }
  611. }
  612. void CMakeSetupDialog::enterState(CMakeSetupDialog::State s)
  613. {
  614. if(s == this->CurrentState)
  615. {
  616. return;
  617. }
  618. this->CurrentState = s;
  619. if(s == Interrupting)
  620. {
  621. this->ConfigureButton->setEnabled(false);
  622. this->GenerateButton->setEnabled(false);
  623. }
  624. else if(s == Configuring)
  625. {
  626. this->Output->clear();
  627. this->setEnabledState(false);
  628. this->GenerateButton->setEnabled(false);
  629. this->GenerateAction->setEnabled(false);
  630. this->ConfigureButton->setText(tr("Stop"));
  631. }
  632. else if(s == Generating)
  633. {
  634. this->CacheModified = false;
  635. this->Output->clear();
  636. this->setEnabledState(false);
  637. this->ConfigureButton->setEnabled(false);
  638. this->GenerateAction->setEnabled(false);
  639. this->GenerateButton->setText(tr("Stop"));
  640. }
  641. else if(s == ReadyConfigure)
  642. {
  643. this->ProgressBar->reset();
  644. this->setEnabledState(true);
  645. this->GenerateButton->setEnabled(false);
  646. this->GenerateAction->setEnabled(false);
  647. this->ConfigureButton->setEnabled(true);
  648. this->ConfigureButton->setText(tr("Configure"));
  649. this->GenerateButton->setText(tr("Generate"));
  650. }
  651. else if(s == ReadyGenerate)
  652. {
  653. this->ProgressBar->reset();
  654. this->setEnabledState(true);
  655. this->GenerateButton->setEnabled(true);
  656. this->GenerateAction->setEnabled(true);
  657. this->ConfigureButton->setEnabled(true);
  658. this->ConfigureButton->setText(tr("Configure"));
  659. this->GenerateButton->setText(tr("Generate"));
  660. }
  661. }
  662. void CMakeSetupDialog::addCacheEntry()
  663. {
  664. QDialog dialog(this);
  665. dialog.resize(400, 200);
  666. dialog.setWindowTitle(tr("CMakeSetup Help"));
  667. QVBoxLayout* l = new QVBoxLayout(&dialog);
  668. AddCacheEntry* w = new AddCacheEntry(&dialog);
  669. QDialogButtonBox* btns = new QDialogButtonBox(
  670. QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
  671. Qt::Horizontal, &dialog);
  672. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  673. QObject::connect(btns, SIGNAL(rejected()), &dialog, SLOT(reject()));
  674. l->addWidget(w);
  675. l->addStretch();
  676. l->addWidget(btns);
  677. if(QDialog::Accepted == dialog.exec())
  678. {
  679. QCMakeCacheModel* m = this->CacheValues->cacheModel();
  680. m->insertRows(0, 1, QModelIndex());
  681. m->setData(m->index(0, 0), w->type(), QCMakeCacheModel::TypeRole);
  682. m->setData(m->index(0, 0), w->name(), Qt::DisplayRole);
  683. m->setData(m->index(0, 0), w->description(), QCMakeCacheModel::HelpRole);
  684. m->setData(m->index(0, 0), 0, QCMakeCacheModel::AdvancedRole);
  685. if(w->type() == QCMakeCacheProperty::BOOL)
  686. {
  687. m->setData(m->index(0, 1), w->value().toBool() ?
  688. Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
  689. }
  690. else
  691. {
  692. m->setData(m->index(0, 1), w->value(), Qt::DisplayRole);
  693. }
  694. }
  695. }