CMakeSetupDialog.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  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 <QSettings>
  23. #include <QMenu>
  24. #include <QMenuBar>
  25. #include <QDragEnterEvent>
  26. #include <QMimeData>
  27. #include <QUrl>
  28. #include "QCMake.h"
  29. #include "QCMakeCacheView.h"
  30. QCMakeThread::QCMakeThread(QObject* p)
  31. : QThread(p), CMakeInstance(NULL)
  32. {
  33. }
  34. QCMake* QCMakeThread::cmakeInstance() const
  35. {
  36. return this->CMakeInstance;
  37. }
  38. void QCMakeThread::processEvents()
  39. {
  40. QCoreApplication::processEvents();
  41. }
  42. void QCMakeThread::run()
  43. {
  44. this->CMakeInstance = new QCMake;
  45. // make the cmake thread to process events it receives from the GUI thread
  46. QObject::connect(this->CMakeInstance, SIGNAL(progressChanged(QString, float)),
  47. this, SLOT(processEvents()), Qt::DirectConnection);
  48. QObject::connect(this->CMakeInstance, SIGNAL(outputMessage(QString)),
  49. this, SLOT(processEvents()), Qt::DirectConnection);
  50. // emit that this cmake thread is ready for use
  51. emit this->cmakeInitialized();
  52. this->exec();
  53. delete this->CMakeInstance;
  54. this->CMakeInstance = NULL;
  55. }
  56. CMakeSetupDialog::CMakeSetupDialog()
  57. : ExitAfterGenerate(true)
  58. {
  59. // create the GUI
  60. QSettings settings;
  61. settings.beginGroup("Settings/StartPath");
  62. int h = settings.value("Height", 500).toInt();
  63. int w = settings.value("Width", 700).toInt();
  64. this->resize(w, h);
  65. QWidget* cont = new QWidget(this);
  66. this->setupUi(cont);
  67. this->Splitter->setStretchFactor(0, 3);
  68. this->Splitter->setStretchFactor(1, 1);
  69. this->setCentralWidget(cont);
  70. this->ProgressBar->reset();
  71. this->InterruptButton->setIcon(
  72. this->style()->standardPixmap(QStyle::SP_DialogCancelButton));
  73. QMenu* FileMenu = this->menuBar()->addMenu(tr("&File"));
  74. this->ReloadCacheAction = FileMenu->addAction(tr("&Reload Cache"));
  75. QObject::connect(this->ReloadCacheAction, SIGNAL(triggered(bool)),
  76. this, SLOT(doReloadCache()));
  77. this->DeleteCacheAction = FileMenu->addAction(tr("&Delete Cache"));
  78. QObject::connect(this->DeleteCacheAction, SIGNAL(triggered(bool)),
  79. this, SLOT(doDeleteCache()));
  80. this->ExitAction = FileMenu->addAction(tr("&Exit"));
  81. QObject::connect(this->ExitAction, SIGNAL(triggered(bool)),
  82. this, SLOT(close()));
  83. QMenu* ToolsMenu = this->menuBar()->addMenu(tr("&Tools"));
  84. this->ConfigureAction = ToolsMenu->addAction(tr("&Configure"));
  85. QObject::connect(this->ConfigureAction, SIGNAL(triggered(bool)),
  86. this, SLOT(doConfigure()));
  87. this->GenerateAction = ToolsMenu->addAction(tr("&Generate"));
  88. QObject::connect(this->GenerateAction, SIGNAL(triggered(bool)),
  89. this, SLOT(doGenerate()));
  90. /*
  91. QMenu* OptionsMenu = this->menuBar()->addMenu(tr("&Options"));
  92. QAction* a = OptionsMenu->addAction(tr("Exit after Generation"));
  93. a->setCheckable(true);
  94. this->ExitAfterGenerate = settings.value("ExitAfterGenerate", true).toBool();
  95. a->setChecked(this->ExitAfterGenerate);
  96. QObject::connect(a, SIGNAL(triggered(bool)),
  97. this, SLOT(setExitAfterGenerate(bool)));
  98. */
  99. QMenu* HelpMenu = this->menuBar()->addMenu(tr("&Help"));
  100. QAction* a = HelpMenu->addAction(tr("About"));
  101. QObject::connect(a, SIGNAL(triggered(bool)),
  102. this, SLOT(doAbout()));
  103. a = HelpMenu->addAction(tr("Help"));
  104. QObject::connect(a, SIGNAL(triggered(bool)),
  105. this, SLOT(doHelp()));
  106. this->setGenerateEnabled(false);
  107. this->setAcceptDrops(true);
  108. // start the cmake worker thread
  109. this->CMakeThread = new QCMakeThread(this);
  110. QObject::connect(this->CMakeThread, SIGNAL(cmakeInitialized()),
  111. this, SLOT(initialize()), Qt::QueuedConnection);
  112. this->CMakeThread->start();
  113. }
  114. void CMakeSetupDialog::initialize()
  115. {
  116. // now the cmake worker thread is running, lets make our connections to it
  117. QObject::connect(this->CMakeThread->cmakeInstance(),
  118. SIGNAL(propertiesChanged(const QCMakeCachePropertyList&)),
  119. this->CacheValues->cacheModel(),
  120. SLOT(setProperties(const QCMakeCachePropertyList&)));
  121. QObject::connect(this->ConfigureButton, SIGNAL(clicked(bool)),
  122. this, SLOT(doConfigure()));
  123. QObject::connect(this->CMakeThread->cmakeInstance(),
  124. SIGNAL(configureDone(int)),
  125. this, SLOT(finishConfigure(int)));
  126. QObject::connect(this->CMakeThread->cmakeInstance(),
  127. SIGNAL(generateDone(int)),
  128. this, SLOT(finishGenerate(int)));
  129. QObject::connect(this->GenerateButton, SIGNAL(clicked(bool)),
  130. this, SLOT(doGenerate()));
  131. QObject::connect(this->BrowseSourceDirectoryButton, SIGNAL(clicked(bool)),
  132. this, SLOT(doSourceBrowse()));
  133. QObject::connect(this->BrowseBinaryDirectoryButton, SIGNAL(clicked(bool)),
  134. this, SLOT(doBinaryBrowse()));
  135. QObject::connect(this->BinaryDirectory, SIGNAL(editTextChanged(QString)),
  136. this, SLOT(onBinaryDirectoryChanged(QString)));
  137. QObject::connect(this->SourceDirectory, SIGNAL(textChanged(QString)),
  138. this, SLOT(onSourceDirectoryChanged(QString)));
  139. QObject::connect(this->CMakeThread->cmakeInstance(),
  140. SIGNAL(sourceDirChanged(QString)),
  141. this, SLOT(updateSourceDirectory(QString)));
  142. QObject::connect(this->CMakeThread->cmakeInstance(),
  143. SIGNAL(progressChanged(QString, float)),
  144. this, SLOT(showProgress(QString,float)));
  145. QObject::connect(this->CMakeThread->cmakeInstance(),
  146. SIGNAL(error(QString, QString, bool*)),
  147. this, SLOT(error(QString,QString,bool*)),
  148. Qt::BlockingQueuedConnection);
  149. QObject::connect(this->InterruptButton, SIGNAL(clicked(bool)),
  150. this, SLOT(doInterrupt()));
  151. QObject::connect(this->CMakeThread->cmakeInstance(),
  152. SIGNAL(outputMessage(QString)),
  153. this->Output, SLOT(append(QString)));
  154. QObject::connect(this->Advanced, SIGNAL(clicked(bool)),
  155. this->CacheValues, SLOT(setShowAdvanced(bool)));
  156. QObject::connect(this->Search, SIGNAL(textChanged(QString)),
  157. this->CacheValues, SLOT(setSearchFilter(QString)));
  158. QObject::connect(this->CMakeThread->cmakeInstance(),
  159. SIGNAL(generatorChanged(QString)),
  160. this, SLOT(updateGeneratorLabel(QString)));
  161. this->updateGeneratorLabel(QString());
  162. QObject::connect(this->CacheValues->cacheModel(),
  163. SIGNAL(dataChanged(QModelIndex, QModelIndex)),
  164. this, SLOT(cacheModelDirty()));
  165. QObject::connect(this->CacheValues->cacheModel(), SIGNAL(modelReset()),
  166. this, SLOT(cacheModelDirty()));
  167. QObject::connect(this->DeleteCacheButton, SIGNAL(clicked(bool)),
  168. this, SLOT(doDeleteCache()));
  169. // get the saved binary directories
  170. QStringList buildPaths = this->loadBuildPaths();
  171. this->BinaryDirectory->blockSignals(true);
  172. this->BinaryDirectory->addItems(buildPaths);
  173. this->BinaryDirectory->blockSignals(false);
  174. if(!this->SourceDirectory->text().isEmpty() ||
  175. !this->BinaryDirectory->lineEdit()->text().isEmpty())
  176. {
  177. this->onSourceDirectoryChanged(this->SourceDirectory->text());
  178. this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
  179. }
  180. else
  181. {
  182. this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
  183. }
  184. }
  185. CMakeSetupDialog::~CMakeSetupDialog()
  186. {
  187. QSettings settings;
  188. settings.beginGroup("Settings/StartPath");
  189. settings.setValue("Height", this->height());
  190. settings.setValue("Width", this->width());
  191. // wait for thread to stop
  192. this->CMakeThread->quit();
  193. this->CMakeThread->wait();
  194. }
  195. void CMakeSetupDialog::doConfigure()
  196. {
  197. QString bindir = this->CMakeThread->cmakeInstance()->binaryDirectory();
  198. QDir dir(bindir);
  199. if(!dir.exists())
  200. {
  201. QString message = tr("Build directory does not exist, "
  202. "should I create it?\n\n"
  203. "Directory: ");
  204. message += bindir;
  205. QString title = tr("Create Directory");
  206. QMessageBox::StandardButton btn;
  207. btn = QMessageBox::information(this, title, message,
  208. QMessageBox::Yes | QMessageBox::No);
  209. if(btn == QMessageBox::No)
  210. {
  211. return;
  212. }
  213. dir.mkpath(".");
  214. }
  215. // prompt for generator if one doesn't exist
  216. if(this->CMakeThread->cmakeInstance()->generator().isEmpty())
  217. {
  218. this->promptForGenerator();
  219. }
  220. // remember path
  221. this->addBinaryPath(dir.absolutePath());
  222. this->InterruptButton->setEnabled(true);
  223. this->setEnabledState(false);
  224. this->setGenerateEnabled(false);
  225. this->Output->clear();
  226. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  227. "setProperties", Qt::QueuedConnection,
  228. Q_ARG(QCMakeCachePropertyList,
  229. this->CacheValues->cacheModel()->properties()));
  230. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  231. "configure", Qt::QueuedConnection);
  232. }
  233. void CMakeSetupDialog::finishConfigure(int err)
  234. {
  235. this->InterruptButton->setEnabled(false);
  236. this->setEnabledState(true);
  237. this->ProgressBar->reset();
  238. if(err != 0)
  239. {
  240. QMessageBox::critical(this, tr("Error"),
  241. tr("Error in configuration process, project files may be invalid"),
  242. QMessageBox::Ok);
  243. }
  244. else if(!this->CacheValues->cacheModel()->modifiedValues())
  245. {
  246. this->setGenerateEnabled(true);
  247. }
  248. }
  249. void CMakeSetupDialog::finishGenerate(int err)
  250. {
  251. this->InterruptButton->setEnabled(false);
  252. this->setEnabledState(true);
  253. this->setGenerateEnabled(true);
  254. this->ProgressBar->reset();
  255. if(err != 0)
  256. {
  257. QMessageBox::critical(this, tr("Error"),
  258. tr("Error in generation process, project files may be invalid"),
  259. QMessageBox::Ok);
  260. }
  261. /*
  262. else if(this->ExitAfterGenerate)
  263. {
  264. QApplication::quit();
  265. }
  266. */
  267. }
  268. void CMakeSetupDialog::doGenerate()
  269. {
  270. this->InterruptButton->setEnabled(true);
  271. this->setEnabledState(false);
  272. this->setGenerateEnabled(false);
  273. this->Output->clear();
  274. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  275. "generate", Qt::QueuedConnection);
  276. }
  277. void CMakeSetupDialog::closeEvent(QCloseEvent* e)
  278. {
  279. // don't close if we're busy
  280. if(this->InterruptButton->isEnabled())
  281. {
  282. e->ignore();
  283. }
  284. // prompt for close if there are unsaved changes
  285. if(this->CacheValues->cacheModel()->modifiedValues())
  286. {
  287. QString message = tr("You have changed options but not rebuilt, "
  288. "are you sure you want to exit?");
  289. QString title = tr("Confirm Exit");
  290. QMessageBox::StandardButton btn;
  291. btn = QMessageBox::critical(this, title, message,
  292. QMessageBox::Yes | QMessageBox::No);
  293. if(btn == QMessageBox::No)
  294. {
  295. e->ignore();
  296. }
  297. }
  298. }
  299. void CMakeSetupDialog::doHelp()
  300. {
  301. QString msg = tr("CMake is used to configure and generate build files for "
  302. "software projects. The basic steps for configuring a project are as "
  303. "follows:\r\n\r\n1. Select the source directory for the project. This should "
  304. "contain the CMakeLists.txt files for the project.\r\n\r\n2. Select the build "
  305. "directory for the project. This is the directory where the project will be "
  306. "built. It can be the same or a different directory than the source "
  307. "directory. For easy clean up, a separate build directory is recommended. "
  308. "CMake will create the directory if it does not exist.\r\n\r\n3. Once the "
  309. "source and binary directories are selected, it is time to press the "
  310. "Configure button. This will cause CMake to read all of the input files and "
  311. "discover all the variables used by the project. The first time a variable "
  312. "is displayed it will be in Red. Users should inspect red variables making "
  313. "sure the values are correct. For some projects the Configure process can "
  314. "be iterative, so continue to press the Configure button until there are no "
  315. "longer red entries.\r\n\r\n4. Once there are no longer red entries, you "
  316. "should click the OK button. This will write the build files to the build "
  317. "directory and exit CMake.");
  318. QDialog dialog;
  319. dialog.setWindowTitle(tr("CMakeSetup Help"));
  320. QVBoxLayout* l = new QVBoxLayout(&dialog);
  321. QLabel* lab = new QLabel(&dialog);
  322. l->addWidget(lab);
  323. lab->setText(msg);
  324. lab->setWordWrap(true);
  325. QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
  326. Qt::Horizontal, &dialog);
  327. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  328. l->addWidget(btns);
  329. dialog.exec();
  330. }
  331. void CMakeSetupDialog::doInterrupt()
  332. {
  333. this->InterruptButton->setEnabled(false);
  334. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  335. "interrupt", Qt::QueuedConnection);
  336. }
  337. void CMakeSetupDialog::doSourceBrowse()
  338. {
  339. QString dir = QFileDialog::getExistingDirectory(this,
  340. tr("Enter Path to Source"), this->SourceDirectory->text());
  341. if(!dir.isEmpty())
  342. {
  343. this->setSourceDirectory(dir);
  344. }
  345. }
  346. void CMakeSetupDialog::updateSourceDirectory(const QString& dir)
  347. {
  348. if(this->SourceDirectory->text() != dir)
  349. {
  350. this->setSourceDirectory(dir);
  351. }
  352. }
  353. void CMakeSetupDialog::doBinaryBrowse()
  354. {
  355. QString dir = QFileDialog::getExistingDirectory(this,
  356. tr("Enter Path to Build"), this->BinaryDirectory->currentText());
  357. if(!dir.isEmpty() && dir != this->BinaryDirectory->currentText())
  358. {
  359. this->setBinaryDirectory(dir);
  360. }
  361. }
  362. void CMakeSetupDialog::setBinaryDirectory(const QString& dir)
  363. {
  364. this->BinaryDirectory->setEditText(dir);
  365. }
  366. void CMakeSetupDialog::onSourceDirectoryChanged(const QString& dir)
  367. {
  368. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  369. "setSourceDirectory", Qt::QueuedConnection, Q_ARG(QString, dir));
  370. }
  371. void CMakeSetupDialog::onBinaryDirectoryChanged(const QString& dir)
  372. {
  373. this->CacheValues->cacheModel()->clear();
  374. this->Output->clear();
  375. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  376. "setBinaryDirectory", Qt::QueuedConnection, Q_ARG(QString, dir));
  377. }
  378. void CMakeSetupDialog::setSourceDirectory(const QString& dir)
  379. {
  380. this->SourceDirectory->setText(dir);
  381. }
  382. void CMakeSetupDialog::showProgress(const QString& /*msg*/, float percent)
  383. {
  384. this->ProgressBar->setValue(qRound(percent * 100));
  385. }
  386. void CMakeSetupDialog::error(const QString& title, const QString& message,
  387. bool* cancel)
  388. {
  389. QMessageBox::StandardButton btn;
  390. QString msg = message + "\n\n" +
  391. tr("(Press cancel to suppress any further messages.)");
  392. btn = QMessageBox::critical(this, title, msg,
  393. QMessageBox::Ok | QMessageBox::Cancel);
  394. if(btn == QMessageBox::Cancel)
  395. {
  396. *cancel = false;
  397. }
  398. }
  399. void CMakeSetupDialog::setEnabledState(bool enabled)
  400. {
  401. // disable parts of the GUI during configure/generate
  402. this->CacheValues->cacheModel()->setEditEnabled(enabled);
  403. this->SourceDirectory->setEnabled(enabled);
  404. this->BrowseSourceDirectoryButton->setEnabled(enabled);
  405. this->BinaryDirectory->setEnabled(enabled);
  406. this->BrowseBinaryDirectoryButton->setEnabled(enabled);
  407. this->ConfigureButton->setEnabled(enabled);
  408. this->ReloadCacheAction->setEnabled(enabled);
  409. this->DeleteCacheAction->setEnabled(enabled);
  410. this->DeleteCacheButton->setEnabled(enabled);
  411. this->ExitAction->setEnabled(enabled);
  412. this->ConfigureAction->setEnabled(enabled);
  413. // generate button/action are handled separately
  414. }
  415. void CMakeSetupDialog::promptForGenerator()
  416. {
  417. QSettings settings;
  418. settings.beginGroup("Settings/StartPath");
  419. QString lastGen = settings.value("LastGenerator").toString();
  420. QStringList gens = this->CMakeThread->cmakeInstance()->availableGenerators();
  421. QDialog dialog;
  422. dialog.setWindowTitle(tr("CMakeSetup choose generator"));
  423. QLabel* lab = new QLabel(&dialog);
  424. lab->setText(tr("Please select what build system you want CMake to generate files for.\n"
  425. "You should select the tool that you will use to build the project.\n"
  426. "Press OK once you have made your selection."));
  427. QComboBox* combo = new QComboBox(&dialog);
  428. combo->addItems(gens);
  429. int idx = combo->findText(lastGen);
  430. if(idx != -1)
  431. {
  432. combo->setCurrentIndex(idx);
  433. }
  434. QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
  435. Qt::Horizontal, &dialog);
  436. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  437. QVBoxLayout* l = new QVBoxLayout(&dialog);
  438. l->addWidget(lab);
  439. l->addWidget(combo);
  440. l->addWidget(btns);
  441. dialog.exec();
  442. lastGen = combo->currentText();
  443. settings.setValue("LastGenerator", lastGen);
  444. this->CMakeThread->cmakeInstance()->setGenerator(combo->currentText());
  445. }
  446. void CMakeSetupDialog::updateGeneratorLabel(const QString& gen)
  447. {
  448. QString str = tr("Current Generator: ");
  449. if(gen.isEmpty())
  450. {
  451. str += tr("None");
  452. }
  453. else
  454. {
  455. str += gen;
  456. }
  457. this->Generator->setText(str);
  458. }
  459. void CMakeSetupDialog::doReloadCache()
  460. {
  461. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  462. "reloadCache", Qt::QueuedConnection);
  463. }
  464. void CMakeSetupDialog::doDeleteCache()
  465. {
  466. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  467. "deleteCache", Qt::QueuedConnection);
  468. }
  469. void CMakeSetupDialog::doAbout()
  470. {
  471. QString msg = "CMakeSetup\nwww.cmake.org";
  472. QDialog dialog;
  473. dialog.setWindowTitle(tr("About CMakeSetup"));
  474. QVBoxLayout* l = new QVBoxLayout(&dialog);
  475. QLabel* lab = new QLabel(&dialog);
  476. l->addWidget(lab);
  477. lab->setText(msg);
  478. lab->setWordWrap(true);
  479. QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
  480. Qt::Horizontal, &dialog);
  481. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  482. l->addWidget(btns);
  483. dialog.exec();
  484. }
  485. void CMakeSetupDialog::setExitAfterGenerate(bool b)
  486. {
  487. this->ExitAfterGenerate = b;
  488. /*
  489. QSettings settings;
  490. settings.beginGroup("Settings/StartPath");
  491. settings.setValue("ExitAfterGenerate", b);
  492. */
  493. }
  494. void CMakeSetupDialog::cacheModelDirty()
  495. {
  496. if(this->CacheValues->cacheModel()->modifiedValues())
  497. {
  498. this->setGenerateEnabled(false);
  499. }
  500. }
  501. void CMakeSetupDialog::setGenerateEnabled(bool b)
  502. {
  503. this->GenerateButton->setEnabled(b);
  504. this->GenerateAction->setEnabled(b);
  505. }
  506. void CMakeSetupDialog::addBinaryPath(const QString& path)
  507. {
  508. QString cleanpath = QDir::cleanPath(path);
  509. // update UI
  510. this->BinaryDirectory->blockSignals(true);
  511. int idx = this->BinaryDirectory->findText(cleanpath);
  512. if(idx != -1)
  513. {
  514. this->BinaryDirectory->removeItem(idx);
  515. }
  516. this->BinaryDirectory->insertItem(0, cleanpath);
  517. this->BinaryDirectory->setCurrentIndex(0);
  518. this->BinaryDirectory->blockSignals(false);
  519. // save to registry
  520. QStringList buildPaths = this->loadBuildPaths();
  521. buildPaths.removeAll(cleanpath);
  522. buildPaths.prepend(cleanpath);
  523. this->saveBuildPaths(buildPaths);
  524. }
  525. void CMakeSetupDialog::dragEnterEvent(QDragEnterEvent* e)
  526. {
  527. if(!this->ConfigureButton->isEnabled())
  528. {
  529. e->ignore();
  530. return;
  531. }
  532. const QMimeData* dat = e->mimeData();
  533. QList<QUrl> urls = dat->urls();
  534. QString file = urls.count() ? urls[0].toLocalFile() : QString();
  535. if(!file.isEmpty() &&
  536. (file.endsWith("CMakeCache.txt", Qt::CaseInsensitive) ||
  537. file.endsWith("CMakeLists.txt", Qt::CaseInsensitive) ) )
  538. {
  539. e->accept();
  540. }
  541. else
  542. {
  543. e->ignore();
  544. }
  545. }
  546. void CMakeSetupDialog::dropEvent(QDropEvent* e)
  547. {
  548. if(!this->ConfigureButton->isEnabled())
  549. {
  550. return;
  551. }
  552. const QMimeData* dat = e->mimeData();
  553. QList<QUrl> urls = dat->urls();
  554. QString file = urls.count() ? urls[0].toLocalFile() : QString();
  555. if(file.endsWith("CMakeCache.txt", Qt::CaseInsensitive))
  556. {
  557. QFileInfo info(file);
  558. if(this->CMakeThread->cmakeInstance()->binaryDirectory() != info.absolutePath())
  559. {
  560. this->setBinaryDirectory(info.absolutePath());
  561. }
  562. }
  563. else if(file.endsWith("CMakeLists.txt", Qt::CaseInsensitive))
  564. {
  565. QFileInfo info(file);
  566. if(this->CMakeThread->cmakeInstance()->binaryDirectory() != info.absolutePath())
  567. {
  568. this->setSourceDirectory(info.absolutePath());
  569. this->setBinaryDirectory(info.absolutePath());
  570. }
  571. }
  572. }
  573. QStringList CMakeSetupDialog::loadBuildPaths()
  574. {
  575. QSettings settings;
  576. settings.beginGroup("Settings/StartPath");
  577. QStringList buildPaths;
  578. for(int i=0; i<10; i++)
  579. {
  580. QString p = settings.value(QString("WhereBuild%1").arg(i)).toString();
  581. if(!p.isEmpty())
  582. {
  583. buildPaths.append(p);
  584. }
  585. }
  586. return buildPaths;
  587. }
  588. void CMakeSetupDialog::saveBuildPaths(const QStringList& paths)
  589. {
  590. QSettings settings;
  591. settings.beginGroup("Settings/StartPath");
  592. int num = paths.count();
  593. if(num > 10)
  594. {
  595. num = 10;
  596. }
  597. for(int i=0; i<num; i++)
  598. {
  599. settings.setValue(QString("WhereBuild%1").arg(i), paths[i]);
  600. }
  601. }