CMakeSetupDialog.cxx 41 KB
Newer Older
1
2
3
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4

5
6
  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.
7

8
9
10
11
  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
12
13
14
15
16

#include "CMakeSetupDialog.h"
#include <QFileDialog>
#include <QProgressBar>
#include <QMessageBox>
Clinton Stimpson's avatar
   
Clinton Stimpson committed
17
18
19
#include <QStatusBar>
#include <QToolButton>
#include <QDialogButtonBox>
Clinton Stimpson's avatar
   
Clinton Stimpson committed
20
#include <QCloseEvent>
Clinton Stimpson's avatar
   
Clinton Stimpson committed
21
#include <QCoreApplication>
Clinton Stimpson's avatar
   
Clinton Stimpson committed
22
#include <QSettings>
Clinton Stimpson's avatar
Clinton Stimpson committed
23
24
#include <QMenu>
#include <QMenuBar>
Clinton Stimpson's avatar
   
Clinton Stimpson committed
25
26
27
#include <QDragEnterEvent>
#include <QMimeData>
#include <QUrl>
Clinton Stimpson's avatar
   
Clinton Stimpson committed
28
#include <QShortcut>
29
#include <QKeySequence>
30
#include <QMacInstallDialog.h>
31
#include <QInputDialog>
32
33
34

#include "QCMake.h"
#include "QCMakeCacheView.h"
Clinton Stimpson's avatar
   
Clinton Stimpson committed
35
#include "AddCacheEntry.h"
Clinton Stimpson's avatar
   
Clinton Stimpson committed
36
#include "FirstConfigure.h"
37
#include "cmSystemTools.h"
Clinton Stimpson's avatar
   
Clinton Stimpson committed
38
#include "cmVersion.h"
39

40
QCMakeThread::QCMakeThread(QObject* p)
Clinton Stimpson's avatar
   
Clinton Stimpson committed
41
  : QThread(p), CMakeInstance(NULL)
42
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
}

QCMake* QCMakeThread::cmakeInstance() const
{
  return this->CMakeInstance;
}

void QCMakeThread::run()
{
  this->CMakeInstance = new QCMake;
  // emit that this cmake thread is ready for use
  emit this->cmakeInitialized();
  this->exec();
  delete this->CMakeInstance;
  this->CMakeInstance = NULL;
}
59
60

CMakeSetupDialog::CMakeSetupDialog()
61
  : ExitAfterGenerate(true), CacheModified(false), ConfigureNeeded(true), CurrentState(Interrupting)
62
{
63
64
65
66
  QString title = QString(tr("CMake %1"));
  title = title.arg(cmVersion::GetCMakeVersion());
  this->setWindowTitle(title);

67
  // create the GUI
Clinton Stimpson's avatar
   
Clinton Stimpson committed
68
69
  QSettings settings;
  settings.beginGroup("Settings/StartPath");
70
71
  restoreGeometry(settings.value("geometry").toByteArray());
  restoreState(settings.value("windowState").toByteArray());
Clinton Stimpson's avatar
   
Clinton Stimpson committed
72

73
  this->AddVariableNames = settings.value("AddVariableNames",
74
                           QStringList("CMAKE_INSTALL_PREFIX")).toStringList();
75
76
  this->AddVariableTypes = settings.value("AddVariableTypes",
                                           QStringList("PATH")).toStringList();
77

Clinton Stimpson's avatar
   
Clinton Stimpson committed
78
79
  QWidget* cont = new QWidget(this);
  this->setupUi(cont);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
80
  this->Splitter->setStretchFactor(0, 3);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
81
  this->Splitter->setStretchFactor(1, 1);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
82
  this->setCentralWidget(cont);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
83
  this->ProgressBar->reset();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
84
  this->RemoveEntry->setEnabled(false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
85
  this->AddEntry->setEnabled(false);
86

Clinton Stimpson's avatar
   
Clinton Stimpson committed
87
88
  QByteArray p = settings.value("SplitterSizes").toByteArray();
  this->Splitter->restoreState(p);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
89

Clinton Stimpson's avatar
   
Clinton Stimpson committed
90
  bool groupView = settings.value("GroupView", false).toBool();
91
92
  this->setGroupedView(groupView);
  this->groupedCheck->setCheckState(groupView ? Qt::Checked : Qt::Unchecked);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
93

94
95
96
97
  bool advancedView = settings.value("AdvancedView", false).toBool();
  this->setAdvancedView(advancedView);
  this->advancedCheck->setCheckState(advancedView?Qt::Checked : Qt::Unchecked);

Clinton Stimpson's avatar
Clinton Stimpson committed
98
  QMenu* FileMenu = this->menuBar()->addMenu(tr("&File"));
Clinton Stimpson's avatar
   
Clinton Stimpson committed
99
  this->ReloadCacheAction = FileMenu->addAction(tr("&Reload Cache"));
100
  QObject::connect(this->ReloadCacheAction, SIGNAL(triggered(bool)),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
101
102
                   this, SLOT(doReloadCache()));
  this->DeleteCacheAction = FileMenu->addAction(tr("&Delete Cache"));
103
  QObject::connect(this->DeleteCacheAction, SIGNAL(triggered(bool)),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
104
                   this, SLOT(doDeleteCache()));
105
  this->ExitAction = FileMenu->addAction(tr("E&xit"));
106
  this->ExitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
107
  QObject::connect(this->ExitAction, SIGNAL(triggered(bool)),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
108
109
110
111
                   this, SLOT(close()));

  QMenu* ToolsMenu = this->menuBar()->addMenu(tr("&Tools"));
  this->ConfigureAction = ToolsMenu->addAction(tr("&Configure"));
112
113
  // prevent merging with Preferences menu item on Mac OS X
  this->ConfigureAction->setMenuRole(QAction::NoRole);
114
  QObject::connect(this->ConfigureAction, SIGNAL(triggered(bool)),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
115
116
                   this, SLOT(doConfigure()));
  this->GenerateAction = ToolsMenu->addAction(tr("&Generate"));
117
  QObject::connect(this->GenerateAction, SIGNAL(triggered(bool)),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
118
                   this, SLOT(doGenerate()));
Clinton Stimpson's avatar
   
Clinton Stimpson committed
119
  QAction* showChangesAction = ToolsMenu->addAction(tr("&Show My Changes"));
120
  QObject::connect(showChangesAction, SIGNAL(triggered(bool)),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
121
                   this, SLOT(showUserChanges()));
122
#if defined(Q_WS_MAC)
123
  this->InstallForCommandLineAction
124
    = ToolsMenu->addAction(tr("&Install For Command Line Use"));
125
  QObject::connect(this->InstallForCommandLineAction, SIGNAL(triggered(bool)),
126
                   this, SLOT(doInstallForCommandLine()));
127
#endif
128
129
  ToolsMenu->addSeparator();
  ToolsMenu->addAction(tr("&Find in Output..."),
130
131
                       this, SLOT(doOutputFindDialog()),
                       QKeySequence::Find);
132
  ToolsMenu->addAction(tr("Find Next"),
133
134
                       this, SLOT(doOutputFindNext()),
                       QKeySequence::FindNext);
135
  ToolsMenu->addAction(tr("Find Previous"),
136
137
                       this, SLOT(doOutputFindPrev()),
                       QKeySequence::FindPrevious);
138
139
140
141
142
  ToolsMenu->addAction(tr("Goto Next Error"),
                       this, SLOT(doOutputErrorNext()),
                       QKeySequence(Qt::Key_F8));  // in Visual Studio
  new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Period),
                       this, SLOT(doOutputErrorNext()));  // in Eclipse
143

Clinton Stimpson's avatar
   
Clinton Stimpson committed
144
  QMenu* OptionsMenu = this->menuBar()->addMenu(tr("&Options"));
145
146
  this->SuppressDevWarningsAction =
    OptionsMenu->addAction(tr("&Suppress dev Warnings (-Wno-dev)"));
Clinton Stimpson's avatar
   
Clinton Stimpson committed
147
  this->SuppressDevWarningsAction->setCheckable(true);
148
149
150
  this->WarnUninitializedAction =
    OptionsMenu->addAction(tr("&Warn Uninitialized (--warn-uninitialized)"));
  this->WarnUninitializedAction->setCheckable(true);
151
  this->WarnUnusedAction =
152
    OptionsMenu->addAction(tr("&Warn Unused (--warn-unused-vars)"));
153
  this->WarnUnusedAction->setCheckable(true);
154

Clinton Stimpson's avatar
   
Clinton Stimpson committed
155
156
  QAction* debugAction = OptionsMenu->addAction(tr("&Debug Output"));
  debugAction->setCheckable(true);
157
  QObject::connect(debugAction, SIGNAL(toggled(bool)),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
158
                   this, SLOT(setDebugOutput(bool)));
159

Clinton Stimpson's avatar
   
Clinton Stimpson committed
160
161
  OptionsMenu->addSeparator();
  QAction* expandAction = OptionsMenu->addAction(tr("&Expand Grouped Entries"));
162
  QObject::connect(expandAction, SIGNAL(triggered(bool)),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
163
                   this->CacheValues, SLOT(expandAll()));
Clinton Stimpson's avatar
   
Clinton Stimpson committed
164
  QAction* collapseAction = OptionsMenu->addAction(tr("&Collapse Grouped Entries"));
165
  QObject::connect(collapseAction, SIGNAL(triggered(bool)),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
166
                   this->CacheValues, SLOT(collapseAll()));
167

Clinton Stimpson's avatar
Clinton Stimpson committed
168
  QMenu* HelpMenu = this->menuBar()->addMenu(tr("&Help"));
Clinton Stimpson's avatar
   
Clinton Stimpson committed
169
  QAction* a = HelpMenu->addAction(tr("About"));
Clinton Stimpson's avatar
Clinton Stimpson committed
170
171
172
173
174
  QObject::connect(a, SIGNAL(triggered(bool)),
                   this, SLOT(doAbout()));
  a = HelpMenu->addAction(tr("Help"));
  QObject::connect(a, SIGNAL(triggered(bool)),
                   this, SLOT(doHelp()));
175

Clinton Stimpson's avatar
   
Clinton Stimpson committed
176
  this->setAcceptDrops(true);
177

178
179
180
  // get the saved binary directories
  QStringList buildPaths = this->loadBuildPaths();
  this->BinaryDirectory->addItems(buildPaths);
181

Clinton Stimpson's avatar
   
Clinton Stimpson committed
182
183
  this->BinaryDirectory->setCompleter(new QCMakeFileCompleter(this, true));
  this->SourceDirectory->setCompleter(new QCMakeFileCompleter(this, true));
184

185
186
187
  // fixed pitch font in output window
  QFont outputFont("Courier");
  this->Output->setFont(outputFont);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
188
  this->ErrorFormat.setForeground(QBrush(Qt::red));
Clinton Stimpson's avatar
   
Clinton Stimpson committed
189

190
191
192
193
  this->Output->setContextMenuPolicy(Qt::CustomContextMenu);
  connect(this->Output, SIGNAL(customContextMenuRequested(const QPoint&)),
          this, SLOT(doOutputContextMenu(const QPoint &)));

194
195
  // start the cmake worker thread
  this->CMakeThread = new QCMakeThread(this);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
196
  QObject::connect(this->CMakeThread, SIGNAL(cmakeInitialized()),
197
                   this, SLOT(initialize()), Qt::QueuedConnection);
198
  this->CMakeThread->start();
199

Clinton Stimpson's avatar
   
Clinton Stimpson committed
200
  this->enterState(ReadyConfigure);
201
202
203

  ProgressOffset = 0.0;
  ProgressFactor = 1.0;
204
205
206
207
208
}

void CMakeSetupDialog::initialize()
{
  // now the cmake worker thread is running, lets make our connections to it
209
  QObject::connect(this->CMakeThread->cmakeInstance(),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
210
      SIGNAL(propertiesChanged(const QCMakePropertyList&)),
211
      this->CacheValues->cacheModel(),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
212
      SLOT(setProperties(const QCMakePropertyList&)));
213

Clinton Stimpson's avatar
   
Clinton Stimpson committed
214
  QObject::connect(this->ConfigureButton, SIGNAL(clicked(bool)),
215
                   this, SLOT(doConfigure()));
216
217
218
219
220

  QObject::connect(this->CMakeThread->cmakeInstance(), SIGNAL(configureDone(int)),
                   this, SLOT(exitLoop(int)));
  QObject::connect(this->CMakeThread->cmakeInstance(), SIGNAL(generateDone(int)),
                   this, SLOT(exitLoop(int)));
221

Clinton Stimpson's avatar
   
Clinton Stimpson committed
222
  QObject::connect(this->GenerateButton, SIGNAL(clicked(bool)),
Clinton Stimpson's avatar
Clinton Stimpson committed
223
                   this, SLOT(doGenerate()));
224

225
226
227
228
  QObject::connect(this->BrowseSourceDirectoryButton, SIGNAL(clicked(bool)),
                   this, SLOT(doSourceBrowse()));
  QObject::connect(this->BrowseBinaryDirectoryButton, SIGNAL(clicked(bool)),
                   this, SLOT(doBinaryBrowse()));
229

Clinton Stimpson's avatar
   
Clinton Stimpson committed
230
  QObject::connect(this->BinaryDirectory, SIGNAL(editTextChanged(QString)),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
231
                   this, SLOT(onBinaryDirectoryChanged(QString)));
Clinton Stimpson's avatar
   
Clinton Stimpson committed
232
  QObject::connect(this->SourceDirectory, SIGNAL(textChanged(QString)),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
233
                   this, SLOT(onSourceDirectoryChanged(QString)));
234

Clinton Stimpson's avatar
   
Clinton Stimpson committed
235
236
  QObject::connect(this->CMakeThread->cmakeInstance(),
                   SIGNAL(sourceDirChanged(QString)),
237
                   this, SLOT(updateSourceDirectory(QString)));
238
239
240
  QObject::connect(this->CMakeThread->cmakeInstance(),
                   SIGNAL(binaryDirChanged(QString)),
                   this, SLOT(updateBinaryDirectory(QString)));
241

Clinton Stimpson's avatar
   
Clinton Stimpson committed
242
243
  QObject::connect(this->CMakeThread->cmakeInstance(),
                   SIGNAL(progressChanged(QString, float)),
244
                   this, SLOT(showProgress(QString,float)));
245

Clinton Stimpson's avatar
   
Clinton Stimpson committed
246
  QObject::connect(this->CMakeThread->cmakeInstance(),
247
248
                   SIGNAL(errorMessage(QString)),
                   this, SLOT(error(QString)));
249

Clinton Stimpson's avatar
   
Clinton Stimpson committed
250
251
  QObject::connect(this->CMakeThread->cmakeInstance(),
                   SIGNAL(outputMessage(QString)),
252
                   this, SLOT(message(QString)));
Clinton Stimpson's avatar
   
Clinton Stimpson committed
253

254
255
256
257
  QObject::connect(this->groupedCheck, SIGNAL(toggled(bool)),
                   this, SLOT(setGroupedView(bool)));
  QObject::connect(this->advancedCheck, SIGNAL(toggled(bool)),
                   this, SLOT(setAdvancedView(bool)));
258
  QObject::connect(this->Search, SIGNAL(textChanged(QString)),
259
                   this, SLOT(setSearchFilter(QString)));
260

261
262
263
264
  QObject::connect(this->CMakeThread->cmakeInstance(),
                   SIGNAL(generatorChanged(QString)),
                   this, SLOT(updateGeneratorLabel(QString)));
  this->updateGeneratorLabel(QString());
265

266
  QObject::connect(this->CacheValues->cacheModel(),
267
                   SIGNAL(dataChanged(QModelIndex,QModelIndex)),
268
                   this, SLOT(setCacheModified()));
269

Clinton Stimpson's avatar
   
Clinton Stimpson committed
270
  QObject::connect(this->CacheValues->selectionModel(),
271
                   SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
272
                   this, SLOT(selectionChanged()));
273
  QObject::connect(this->RemoveEntry, SIGNAL(clicked(bool)),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
274
                   this, SLOT(removeSelectedCacheEntries()));
275
  QObject::connect(this->AddEntry, SIGNAL(clicked(bool)),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
276
                   this, SLOT(addCacheEntry()));
277

278
  QObject::connect(this->SuppressDevWarningsAction, SIGNAL(triggered(bool)),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
279
                   this->CMakeThread->cmakeInstance(), SLOT(setSuppressDevWarnings(bool)));
280

281
  QObject::connect(this->WarnUninitializedAction, SIGNAL(triggered(bool)),
282
                   this->CMakeThread->cmakeInstance(),
283
                   SLOT(setWarnUninitializedMode(bool)));
284
285
286
  QObject::connect(this->WarnUnusedAction, SIGNAL(triggered(bool)),
                   this->CMakeThread->cmakeInstance(),
                   SLOT(setWarnUnusedMode(bool)));
287

Clinton Stimpson's avatar
   
Clinton Stimpson committed
288
289
290
291
292
293
294
295
296
297
  if(!this->SourceDirectory->text().isEmpty() ||
     !this->BinaryDirectory->lineEdit()->text().isEmpty())
    {
    this->onSourceDirectoryChanged(this->SourceDirectory->text());
    this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
    }
  else
    {
    this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
    }
298
299
300
301
}

CMakeSetupDialog::~CMakeSetupDialog()
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
302
303
  QSettings settings;
  settings.beginGroup("Settings/StartPath");
304
305
  settings.setValue("windowState", QVariant(saveState()));
  settings.setValue("geometry", QVariant(saveGeometry()));
Clinton Stimpson's avatar
   
Clinton Stimpson committed
306
  settings.setValue("SplitterSizes", this->Splitter->saveState());
Clinton Stimpson's avatar
   
Clinton Stimpson committed
307

308
309
  // wait for thread to stop
  this->CMakeThread->quit();
310
  this->CMakeThread->wait();
311
}
312

313
bool CMakeSetupDialog::prepareConfigure()
314
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
315
  // make sure build directory exists
Clinton Stimpson's avatar
   
Clinton Stimpson committed
316
317
  QString bindir = this->CMakeThread->cmakeInstance()->binaryDirectory();
  QDir dir(bindir);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
318
319
  if(!dir.exists())
    {
Clinton Stimpson's avatar
Clinton Stimpson committed
320
    QString msg = tr("Build directory does not exist, "
321
322
                         "should I create it?\n\n"
                      "Directory: ");
Clinton Stimpson's avatar
Clinton Stimpson committed
323
    msg += bindir;
Clinton Stimpson's avatar
   
Clinton Stimpson committed
324
    QString title = tr("Create Directory");
Clinton Stimpson's avatar
   
Clinton Stimpson committed
325
    QMessageBox::StandardButton btn;
326
    btn = QMessageBox::information(this, title, msg,
Clinton Stimpson's avatar
   
Clinton Stimpson committed
327
                                   QMessageBox::Yes | QMessageBox::No);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
328
329
    if(btn == QMessageBox::No)
      {
330
      return false;
Clinton Stimpson's avatar
   
Clinton Stimpson committed
331
      }
332
333
    if(!dir.mkpath("."))
      {
334
335
      QMessageBox::information(this, tr("Create Directory Failed"),
        QString(tr("Failed to create directory %1")).arg(dir.path()),
336
337
        QMessageBox::Ok);

338
      return false;
339
      }
Clinton Stimpson's avatar
   
Clinton Stimpson committed
340
    }
Clinton Stimpson's avatar
   
Clinton Stimpson committed
341

Clinton Stimpson's avatar
   
Clinton Stimpson committed
342
  // if no generator, prompt for it and other setup stuff
Clinton Stimpson's avatar
   
Clinton Stimpson committed
343
344
  if(this->CMakeThread->cmakeInstance()->generator().isEmpty())
    {
Clinton Stimpson's avatar
   
Clinton Stimpson committed
345
    if(!this->setupFirstConfigure())
Clinton Stimpson's avatar
   
Clinton Stimpson committed
346
      {
347
      return false;
Clinton Stimpson's avatar
   
Clinton Stimpson committed
348
      }
Clinton Stimpson's avatar
   
Clinton Stimpson committed
349
350
    }

Clinton Stimpson's avatar
   
Clinton Stimpson committed
351
352
  // remember path
  this->addBinaryPath(dir.absolutePath());
353

354
355
  return true;
}
Clinton Stimpson's avatar
   
Clinton Stimpson committed
356

357
358
359
void CMakeSetupDialog::exitLoop(int err)
{
  this->LocalLoop.exit(err);
360
361
}

362
void CMakeSetupDialog::doConfigure()
363
{
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
  if(this->CurrentState == Configuring)
    {
    // stop configure
    doInterrupt();
    return;
    }

  if(!prepareConfigure())
    {
    return;
    }

  this->enterState(Configuring);

  bool ret = doConfigureInternal();

  if(ret)
    {
    this->ConfigureNeeded = false;
    }

  if(ret && !this->CacheValues->cacheModel()->newPropertyCount())
Clinton Stimpson's avatar
   
Clinton Stimpson committed
386
387
388
389
390
391
392
393
    {
    this->enterState(ReadyGenerate);
    }
  else
    {
    this->enterState(ReadyConfigure);
    this->CacheValues->scrollToTop();
    }
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
  this->ProgressBar->reset();
}

bool CMakeSetupDialog::doConfigureInternal()
{
  this->Output->clear();
  this->CacheValues->selectionModel()->clear();

  QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
    "setProperties", Qt::QueuedConnection,
    Q_ARG(QCMakePropertyList,
      this->CacheValues->cacheModel()->properties()));
  QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
    "configure", Qt::QueuedConnection);

  int err = this->LocalLoop.exec();
410

Clinton Stimpson's avatar
   
Clinton Stimpson committed
411
  if(err != 0)
Clinton Stimpson's avatar
   
Clinton Stimpson committed
412
    {
413
414
    QMessageBox::critical(this, tr("Error"),
      tr("Error in configuration process, project files may be invalid"),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
415
416
      QMessageBox::Ok);
    }
417
418

  return 0 == err;
419
420
}

421
void CMakeSetupDialog::doInstallForCommandLine()
422
{
423
424
425
426
427
428
429
430
431
432
433
  QMacInstallDialog setupdialog(0);
  setupdialog.exec();
}

bool CMakeSetupDialog::doGenerateInternal()
{
  QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
    "generate", Qt::QueuedConnection);

  int err = this->LocalLoop.exec();

Clinton Stimpson's avatar
   
Clinton Stimpson committed
434
  if(err != 0)
Clinton Stimpson's avatar
   
Clinton Stimpson committed
435
    {
436
    QMessageBox::critical(this, tr("Error"),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
437
438
439
      tr("Error in generation process, project files may be invalid"),
      QMessageBox::Ok);
    }
440

441
  return 0 == err;
442
443
}

Clinton Stimpson's avatar
Clinton Stimpson committed
444
void CMakeSetupDialog::doGenerate()
445
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
446
447
448
449
450
451
  if(this->CurrentState == Generating)
    {
    // stop generate
    doInterrupt();
    return;
    }
452
453
454
455
456
457
458
459
460
461
462
463
464

  // see if we need to configure
  // we'll need to configure if:
  //   the configure step hasn't been done yet
  //   generate was the last step done
  if(this->ConfigureNeeded)
    {
    if(!prepareConfigure())
      {
      return;
      }
    }

Clinton Stimpson's avatar
   
Clinton Stimpson committed
465
  this->enterState(Generating);
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488

  bool config_passed = true;
  if(this->ConfigureNeeded)
    {
    this->CacheValues->cacheModel()->setShowNewProperties(false);
    this->ProgressFactor = 0.5;
    config_passed = doConfigureInternal();
    this->ProgressOffset = 0.5;
    }

  if(config_passed)
    {
    doGenerateInternal();
    }

  this->ProgressOffset = 0.0;
  this->ProgressFactor = 1.0;
  this->CacheValues->cacheModel()->setShowNewProperties(true);

  this->enterState(ReadyConfigure);
  this->ProgressBar->reset();

  this->ConfigureNeeded = true;
489
}
490

Clinton Stimpson's avatar
   
Clinton Stimpson committed
491
void CMakeSetupDialog::closeEvent(QCloseEvent* e)
492
{
493
  // prompt for close if there are unsaved changes, and we're not busy
494
  if(this->CacheModified)
Clinton Stimpson's avatar
   
Clinton Stimpson committed
495
    {
Clinton Stimpson's avatar
Clinton Stimpson committed
496
    QString msg = tr("You have changed options but not rebuilt, "
Clinton Stimpson's avatar
   
Clinton Stimpson committed
497
498
                    "are you sure you want to exit?");
    QString title = tr("Confirm Exit");
Clinton Stimpson's avatar
   
Clinton Stimpson committed
499
    QMessageBox::StandardButton btn;
Clinton Stimpson's avatar
Clinton Stimpson committed
500
    btn = QMessageBox::critical(this, title, msg,
Clinton Stimpson's avatar
   
Clinton Stimpson committed
501
                                QMessageBox::Yes | QMessageBox::No);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
502
    if(btn == QMessageBox::No)
Clinton Stimpson's avatar
   
Clinton Stimpson committed
503
      {
Clinton Stimpson's avatar
   
Clinton Stimpson committed
504
      e->ignore();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
505
506
      }
    }
507
508
509
510

  // don't close if we're busy, unless the user really wants to
  if(this->CurrentState == Configuring)
    {
511
    QString msg = tr("You are in the middle of a Configure.\n"
512
                   "If you Exit now the configure information will be lost.\n"
513
                   "Are you sure you want to Exit?");
514
515
    QString title = tr("Confirm Exit");
    QMessageBox::StandardButton btn;
Clinton Stimpson's avatar
Clinton Stimpson committed
516
    btn = QMessageBox::critical(this, title, msg,
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
                                QMessageBox::Yes | QMessageBox::No);
    if(btn == QMessageBox::No)
      {
      e->ignore();
      }
    else
      {
      this->doInterrupt();
      }
    }

  // let the generate finish
  if(this->CurrentState == Generating)
    {
    e->ignore();
    }
533
534
535
536
}

void CMakeSetupDialog::doHelp()
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
  QString msg = tr("CMake is used to configure and generate build files for "
    "software projects.   The basic steps for configuring a project are as "
    "follows:\r\n\r\n1. Select the source directory for the project.  This should "
    "contain the CMakeLists.txt files for the project.\r\n\r\n2. Select the build "
    "directory for the project.   This is the directory where the project will be "
    "built.  It can be the same or a different directory than the source "
    "directory.   For easy clean up, a separate build directory is recommended. "
    "CMake will create the directory if it does not exist.\r\n\r\n3. Once the "
    "source and binary directories are selected, it is time to press the "
    "Configure button.  This will cause CMake to read all of the input files and "
    "discover all the variables used by the project.   The first time a variable "
    "is displayed it will be in Red.   Users should inspect red variables making "
    "sure the values are correct.   For some projects the Configure process can "
    "be iterative, so continue to press the Configure button until there are no "
    "longer red entries.\r\n\r\n4. Once there are no longer red entries, you "
552
553
    "should click the Generate button.  This will write the build files to the build "
    "directory.");
Clinton Stimpson's avatar
   
Clinton Stimpson committed
554
555

  QDialog dialog;
556
557
558
  QFontMetrics met(this->font());
  int msgWidth = met.width(msg);
  dialog.setMinimumSize(msgWidth/15,20);
559
  dialog.setWindowTitle(tr("Help"));
Clinton Stimpson's avatar
   
Clinton Stimpson committed
560
  QVBoxLayout* l = new QVBoxLayout(&dialog);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
561
562
563
  QLabel* lab = new QLabel(&dialog);
  lab->setText(msg);
  lab->setWordWrap(true);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
564
565
566
  QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
                                                Qt::Horizontal, &dialog);
  QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
567
  l->addWidget(lab);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
568
569
570
571
572
573
  l->addWidget(btns);
  dialog.exec();
}

void CMakeSetupDialog::doInterrupt()
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
574
  this->enterState(Interrupting);
575
  this->CMakeThread->cmakeInstance()->interrupt();
576
577
578
579
}

void CMakeSetupDialog::doSourceBrowse()
{
580
  QString dir = QFileDialog::getExistingDirectory(this,
Clinton Stimpson's avatar
   
Clinton Stimpson committed
581
    tr("Enter Path to Source"), this->SourceDirectory->text());
582
583
  if(!dir.isEmpty())
    {
584
    this->setSourceDirectory(dir);
585
586
587
588
589
    }
}

void CMakeSetupDialog::updateSourceDirectory(const QString& dir)
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
590
591
  if(this->SourceDirectory->text() != dir)
    {
Clinton Stimpson's avatar
   
Clinton Stimpson committed
592
593
594
    this->SourceDirectory->blockSignals(true);
    this->SourceDirectory->setText(dir);
    this->SourceDirectory->blockSignals(false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
595
    }
596
597
}

598
599
600
601
602
603
604
605
606
607
void CMakeSetupDialog::updateBinaryDirectory(const QString& dir)
{
  if(this->BinaryDirectory->currentText() != dir)
    {
    this->BinaryDirectory->blockSignals(true);
    this->BinaryDirectory->setEditText(dir);
    this->BinaryDirectory->blockSignals(false);
    }
}

608
609
void CMakeSetupDialog::doBinaryBrowse()
{
610
  QString dir = QFileDialog::getExistingDirectory(this,
Clinton Stimpson's avatar
   
Clinton Stimpson committed
611
    tr("Enter Path to Build"), this->BinaryDirectory->currentText());
Clinton Stimpson's avatar
   
Clinton Stimpson committed
612
  if(!dir.isEmpty() && dir != this->BinaryDirectory->currentText())
613
    {
614
    this->setBinaryDirectory(dir);
615
616
617
618
    }
}

void CMakeSetupDialog::setBinaryDirectory(const QString& dir)
Clinton Stimpson's avatar
   
Clinton Stimpson committed
619
620
621
622
623
624
{
  this->BinaryDirectory->setEditText(dir);
}

void CMakeSetupDialog::onSourceDirectoryChanged(const QString& dir)
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
625
  this->Output->clear();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
626
627
628
629
630
  QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
    "setSourceDirectory", Qt::QueuedConnection, Q_ARG(QString, dir));
}

void CMakeSetupDialog::onBinaryDirectoryChanged(const QString& dir)
631
{
632
633
634
635
636
  QString title = QString(tr("CMake %1 - %2"));
  title = title.arg(cmVersion::GetCMakeVersion());
  title = title.arg(dir);
  this->setWindowTitle(title);

637
  this->CacheModified = false;
Clinton Stimpson's avatar
   
Clinton Stimpson committed
638
  this->CacheValues->cacheModel()->clear();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
639
  qobject_cast<QCMakeCacheModelDelegate*>(this->CacheValues->itemDelegate())->clearChanges();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
640
641
642
  this->Output->clear();
  QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
    "setBinaryDirectory", Qt::QueuedConnection, Q_ARG(QString, dir));
643
644
}

Clinton Stimpson's avatar
   
Clinton Stimpson committed
645
646
647
648
649
void CMakeSetupDialog::setSourceDirectory(const QString& dir)
{
  this->SourceDirectory->setText(dir);
}

Clinton Stimpson's avatar
   
Clinton Stimpson committed
650
void CMakeSetupDialog::showProgress(const QString& /*msg*/, float percent)
651
{
652
  percent = (percent * ProgressFactor) + ProgressOffset;
Clinton Stimpson's avatar
   
Clinton Stimpson committed
653
  this->ProgressBar->setValue(qRound(percent * 100));
654
}
Clinton Stimpson's avatar
   
Clinton Stimpson committed
655

Clinton Stimpson's avatar
Clinton Stimpson committed
656
void CMakeSetupDialog::error(const QString& msg)
657
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
658
  this->Output->setCurrentCharFormat(this->ErrorFormat);
659
660
661
662
663
664
665
  //QTextEdit will terminate the msg with a ParagraphSeparator, but it also replaces
  //all newlines with ParagraphSeparators. By replacing the newlines by ourself, one
  //error msg will be one paragraph.
  QString paragraph(msg);
  paragraph.replace(QLatin1Char('\n'), QChar::LineSeparator);
  this->Output->append(paragraph);

Clinton Stimpson's avatar
   
Clinton Stimpson committed
666
667
}

Clinton Stimpson's avatar
Clinton Stimpson committed
668
void CMakeSetupDialog::message(const QString& msg)
669
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
670
  this->Output->setCurrentCharFormat(this->MessageFormat);
Clinton Stimpson's avatar
Clinton Stimpson committed
671
  this->Output->append(msg);
672
673
}

Clinton Stimpson's avatar
   
Clinton Stimpson committed
674
675
void CMakeSetupDialog::setEnabledState(bool enabled)
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
676
  // disable parts of the GUI during configure/generate
Clinton Stimpson's avatar
   
Clinton Stimpson committed
677
  this->CacheValues->cacheModel()->setEditEnabled(enabled);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
678
679
680
681
  this->SourceDirectory->setEnabled(enabled);
  this->BrowseSourceDirectoryButton->setEnabled(enabled);
  this->BinaryDirectory->setEnabled(enabled);
  this->BrowseBinaryDirectoryButton->setEnabled(enabled);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
682
683
684
685
  this->ReloadCacheAction->setEnabled(enabled);
  this->DeleteCacheAction->setEnabled(enabled);
  this->ExitAction->setEnabled(enabled);
  this->ConfigureAction->setEnabled(enabled);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
686
  this->AddEntry->setEnabled(enabled);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
687
  this->RemoveEntry->setEnabled(false);  // let selection re-enable it
688
689
}

Clinton Stimpson's avatar
   
Clinton Stimpson committed
690
bool CMakeSetupDialog::setupFirstConfigure()
Clinton Stimpson's avatar
   
Clinton Stimpson committed
691
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
692
  FirstConfigure dialog;
Clinton Stimpson's avatar
   
Clinton Stimpson committed
693

Clinton Stimpson's avatar
   
Clinton Stimpson committed
694
695
696
697
698
699
700
  // initialize dialog and restore saved settings

  // add generators
  dialog.setGenerators(this->CMakeThread->cmakeInstance()->availableGenerators());

  // restore from settings
  dialog.loadFromSettings();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
701

Clinton Stimpson's avatar
   
Clinton Stimpson committed
702
703
  if(dialog.exec() == QDialog::Accepted)
    {
Clinton Stimpson's avatar
   
Clinton Stimpson committed
704
705
    dialog.saveToSettings();
    this->CMakeThread->cmakeInstance()->setGenerator(dialog.getGenerator());
706

Clinton Stimpson's avatar
   
Clinton Stimpson committed
707
708
709
710
711
712
713
    QCMakeCacheModel* m = this->CacheValues->cacheModel();

    if(dialog.compilerSetup())
      {
      QString fortranCompiler = dialog.getFortranCompiler();
      if(!fortranCompiler.isEmpty())
        {
714
        m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER",
Clinton Stimpson's avatar
   
Clinton Stimpson committed
715
716
717
718
719
                          "Fortran compiler.", fortranCompiler, false);
        }
      QString cxxCompiler = dialog.getCXXCompiler();
      if(!cxxCompiler.isEmpty())
        {
720
        m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER",
Clinton Stimpson's avatar
   
Clinton Stimpson committed
721
722
                          "CXX compiler.", cxxCompiler, false);
        }
723

Clinton Stimpson's avatar
   
Clinton Stimpson committed
724
725
726
      QString cCompiler = dialog.getCCompiler();
      if(!cCompiler.isEmpty())
        {
727
        m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER",
Clinton Stimpson's avatar
   
Clinton Stimpson committed
728
729
730
731
732
                          "C compiler.", cCompiler, false);
        }
      }
    else if(dialog.crossCompilerSetup())
      {
Clinton Stimpson's avatar
   
Clinton Stimpson committed
733
734
      QString fortranCompiler = dialog.getFortranCompiler();
      if(!fortranCompiler.isEmpty())
Clinton Stimpson's avatar
   
Clinton Stimpson committed
735
        {
736
        m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER",
Clinton Stimpson's avatar
   
Clinton Stimpson committed
737
                          "Fortran compiler.", fortranCompiler, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
738
        }
Clinton Stimpson's avatar
   
Clinton Stimpson committed
739
740

      QString mode = dialog.getCrossIncludeMode();
741
      m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_INCLUDE",
742
                        tr("CMake Find Include Mode"), mode, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
743
      mode = dialog.getCrossLibraryMode();
744
      m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_LIBRARY",
745
                        tr("CMake Find Library Mode"), mode, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
746
      mode = dialog.getCrossProgramMode();
747
      m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_PROGRAM",
748
                        tr("CMake Find Program Mode"), mode, false);
749

Clinton Stimpson's avatar
   
Clinton Stimpson committed
750
      QString rootPath = dialog.getCrossRoot();
751
      m->insertProperty(QCMakeProperty::PATH, "CMAKE_FIND_ROOT_PATH",
752
                        tr("CMake Find Root Path"), rootPath, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
753
754

      QString systemName = dialog.getSystemName();
755
      m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_NAME",
756
                        tr("CMake System Name"), systemName, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
757
      QString cxxCompiler = dialog.getCXXCompiler();
758
      m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER",
759
                        tr("CXX compiler."), cxxCompiler, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
760
      QString cCompiler = dialog.getCCompiler();
761
      m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER",
762
                        tr("C compiler."), cCompiler, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
763
764
765
766
      }
    else if(dialog.crossCompilerToolChainFile())
      {
      QString toolchainFile = dialog.getCrossCompilerToolChainFile();
767
      m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_TOOLCHAIN_FILE",
768
                        tr("Cross Compile ToolChain File"), toolchainFile, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
769
      }
Clinton Stimpson's avatar
   
Clinton Stimpson committed
770
771
772
773
    return true;
    }

  return false;
Clinton Stimpson's avatar
   
Clinton Stimpson committed
774
}
775
776
777

void CMakeSetupDialog::updateGeneratorLabel(const QString& gen)
{
778
  QString str = tr("Current Generator: ");
779
780
781
782
783
784
785
786
787
788
789
  if(gen.isEmpty())
    {
    str += tr("None");
    }
  else
    {
    str += gen;
    }
  this->Generator->setText(str);
}

Clinton Stimpson's avatar
Clinton Stimpson committed
790
791
792
793
794
795
796
void CMakeSetupDialog::doReloadCache()
{
  QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
    "reloadCache", Qt::QueuedConnection);
}

void CMakeSetupDialog::doDeleteCache()
797
{
798
  QString title = tr("Delete Cache");
799
  QString msg = tr("Are you sure you want to delete the cache?");
800
  QMessageBox::StandardButton btn;
801
  btn = QMessageBox::information(this, title, msg,
802
803
804
805
806
                                 QMessageBox::Yes | QMessageBox::No);
  if(btn == QMessageBox::No)
    {
    return;
    }
Clinton Stimpson's avatar
Clinton Stimpson committed
807
  QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
808
                            "deleteCache", Qt::QueuedConnection);
Clinton Stimpson's avatar
Clinton Stimpson committed
809
810
811
812
}

void CMakeSetupDialog::doAbout()
{
813
814
  QString msg = tr(
    "CMake %1 (cmake.org).\n"
815
    "CMake suite maintained and supported by Kitware (kitware.com/cmake).\n"
816
817
818
819
    "Distributed under terms of the BSD 3-Clause License.\n"
    "\n"
    "CMake GUI maintained by csimsoft,\n"
    "built using Qt %2 (qt-project.org).\n"
820
821
822
823
824
825
#ifdef CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL
    "\n"
    "The Qt Toolkit is Copyright (C) Digia Plc and/or its subsidiary(-ies).\n"
    "Qt is licensed under terms of the GNU LGPLv2.1, available at:\n"
    " \"%3\""
#endif
826
    );
Clinton Stimpson's avatar
   
Clinton Stimpson committed
827
828
  msg = msg.arg(cmVersion::GetCMakeVersion());
  msg = msg.arg(qVersion());
829
830
831
832
#ifdef CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL
  std::string lgpl = cmSystemTools::GetCMakeRoot()+"/Licenses/LGPLv2.1.txt";
  msg = msg.arg(lgpl.c_str());
#endif
Clinton Stimpson's avatar
Clinton Stimpson committed
833
834

  QDialog dialog;
835
  dialog.setWindowTitle(tr("About"));
Clinton Stimpson's avatar
Clinton Stimpson committed
836
837
838
839
840
841
842
843
844
845
846
847
848
849
  QVBoxLayout* l = new QVBoxLayout(&dialog);
  QLabel* lab = new QLabel(&dialog);
  l->addWidget(lab);
  lab->setText(msg);
  lab->setWordWrap(true);
  QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
                                                Qt::Horizontal, &dialog);
  QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  l->addWidget(btns);
  dialog.exec();
}

void CMakeSetupDialog::setExitAfterGenerate(bool b)
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
850
  this->ExitAfterGenerate = b;
Clinton Stimpson's avatar
Clinton Stimpson committed
851
852
}

Clinton Stimpson's avatar
   
Clinton Stimpson committed
853
854
855
void CMakeSetupDialog::addBinaryPath(const QString& path)
{
  QString cleanpath = QDir::cleanPath(path);
856

Clinton Stimpson's avatar
   
Clinton Stimpson committed
857
858
  // update UI
  this->BinaryDirectory->blockSignals(true);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
859
860
861
862
863
864
865
  int idx = this->BinaryDirectory->findText(cleanpath);
  if(idx != -1)
    {
    this->BinaryDirectory->removeItem(idx);
    }
  this->BinaryDirectory->insertItem(0, cleanpath);
  this->BinaryDirectory->setCurrentIndex(0);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
866
  this->BinaryDirectory->blockSignals(false);
867

Clinton Stimpson's avatar
   
Clinton Stimpson committed
868
869
870
  // save to registry
  QStringList buildPaths = this->loadBuildPaths();
  buildPaths.removeAll(cleanpath);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
871
  buildPaths.prepend(cleanpath);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
872
  this->saveBuildPaths(buildPaths);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
873
874
875
876
}

void CMakeSetupDialog::dragEnterEvent(QDragEnterEvent* e)
{
877
  if(!(this->CurrentState == ReadyConfigure ||
878
     this->CurrentState == ReadyGenerate))
879
880
881
882
883
    {
    e->ignore();
    return;
    }

Clinton Stimpson's avatar
   
Clinton Stimpson committed
884
885
  const QMimeData* dat = e->mimeData();
  QList<QUrl> urls = dat->urls();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
886
  QString file = urls.count() ? urls[0].toLocalFile() : QString();
887
  if(!file.isEmpty() &&
Clinton Stimpson's avatar
   
Clinton Stimpson committed
888
889
890
891
892
893
894
895
896
897
898
899
900
    (file.endsWith("CMakeCache.txt", Qt::CaseInsensitive) ||
    file.endsWith("CMakeLists.txt", Qt::CaseInsensitive) ) )
    {
    e->accept();
    }
  else
    {
    e->ignore();
    }
}

void CMakeSetupDialog::dropEvent(QDropEvent* e)
{
901
  if(!(this->CurrentState == ReadyConfigure ||
902
     this->CurrentState == ReadyGenerate))
903
904
905
    {
    return;
    }
Clinton Stimpson's avatar
   
Clinton Stimpson committed
906

Clinton Stimpson's avatar
   
Clinton Stimpson committed
907
908
  const QMimeData* dat = e->mimeData();
  QList<QUrl> urls = dat->urls();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
909
910
911
912
  QString file = urls.count() ? urls[0].toLocalFile() : QString();
  if(file.endsWith("CMakeCache.txt", Qt::CaseInsensitive))
    {
    QFileInfo info(file);
913
914
915
916
    if(this->CMakeThread->cmakeInstance()->binaryDirectory() != info.absolutePath())
      {
      this->setBinaryDirectory(info.absolutePath());
      }
Clinton Stimpson's avatar
   
Clinton Stimpson committed
917
918
919
920
    }
  else if(file.endsWith("CMakeLists.txt", Qt::CaseInsensitive))
    {
    QFileInfo info(file);