CMakeSetupDialog.cxx 20 KB

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