CMakeSetupDialog.cxx 42.4 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 <QInputDialog>
31
32
33

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

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

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;
}
58
59

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Clinton Stimpson's avatar
   
Clinton Stimpson committed
287
288
289
290
291
292
293
294
295
296
  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());
    }
297
298
299
300
}

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

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

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

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

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

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

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

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

361
void CMakeSetupDialog::doConfigure()
362
{
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
  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
385
386
387
388
389
390
391
392
    {
    this->enterState(ReadyGenerate);
    }
  else
    {
    this->enterState(ReadyConfigure);
    this->CacheValues->scrollToTop();
    }
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
  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();
409

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

  return 0 == err;
418
419
}

420
void CMakeSetupDialog::doInstallForCommandLine()
421
{
422
423
424
425
426
427
  QString title = tr("How to Install For Command Line Use");
  QString msg = tr(
    "One may add CMake to the PATH:\n"
    "\n"
    " PATH=\"%1\":\"$PATH\"\n"
    "\n"
428
    "Or, to install symlinks to '/usr/local/bin', run:\n"
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
    "\n"
    " sudo \"%2\" --install\n"
    "\n"
    "Or, to install symlinks to another directory, run:\n"
    "\n"
    " sudo \"%3\" --install=/path/to/bin\n"
    );
  msg = msg.arg(cmSystemTools::GetFilenamePath(
                  cmSystemTools::GetCMakeCommand()).c_str());
  msg = msg.arg(cmSystemTools::GetCMakeGUICommand().c_str());
  msg = msg.arg(cmSystemTools::GetCMakeGUICommand().c_str());

  QDialog dialog;
  dialog.setWindowTitle(title);
  QVBoxLayout* l = new QVBoxLayout(&dialog);
  QLabel* lab = new QLabel(&dialog);
  l->addWidget(lab);
  lab->setText(msg);
  lab->setWordWrap(false);
448
  lab->setTextInteractionFlags(Qt::TextSelectableByMouse);
449
450
451
452
453
  QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
                                                Qt::Horizontal, &dialog);
  QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  l->addWidget(btns);
  dialog.exec();
454
455
456
457
458
459
460
461
462
}

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

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

Clinton Stimpson's avatar
   
Clinton Stimpson committed
463
  if(err != 0)
Clinton Stimpson's avatar
   
Clinton Stimpson committed
464
    {
465
    QMessageBox::critical(this, tr("Error"),
Clinton Stimpson's avatar
   
Clinton Stimpson committed
466
467
468
      tr("Error in generation process, project files may be invalid"),
      QMessageBox::Ok);
    }
469

470
  return 0 == err;
471
472
}

Clinton Stimpson's avatar
Clinton Stimpson committed
473
void CMakeSetupDialog::doGenerate()
474
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
475
476
477
478
479
480
  if(this->CurrentState == Generating)
    {
    // stop generate
    doInterrupt();
    return;
    }
481
482
483
484
485
486
487
488
489
490
491
492
493

  // 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
494
  this->enterState(Generating);
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517

  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;
518
}
519

Clinton Stimpson's avatar
   
Clinton Stimpson committed
520
void CMakeSetupDialog::closeEvent(QCloseEvent* e)
521
{
522
  // prompt for close if there are unsaved changes, and we're not busy
523
  if(this->CacheModified)
Clinton Stimpson's avatar
   
Clinton Stimpson committed
524
    {
Clinton Stimpson's avatar
Clinton Stimpson committed
525
    QString msg = tr("You have changed options but not rebuilt, "
Clinton Stimpson's avatar
   
Clinton Stimpson committed
526
527
                    "are you sure you want to exit?");
    QString title = tr("Confirm Exit");
Clinton Stimpson's avatar
   
Clinton Stimpson committed
528
    QMessageBox::StandardButton btn;
Clinton Stimpson's avatar
Clinton Stimpson committed
529
    btn = QMessageBox::critical(this, title, msg,
Clinton Stimpson's avatar
   
Clinton Stimpson committed
530
                                QMessageBox::Yes | QMessageBox::No);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
531
    if(btn == QMessageBox::No)
Clinton Stimpson's avatar
   
Clinton Stimpson committed
532
      {
Clinton Stimpson's avatar
   
Clinton Stimpson committed
533
      e->ignore();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
534
535
      }
    }
536
537
538
539

  // don't close if we're busy, unless the user really wants to
  if(this->CurrentState == Configuring)
    {
540
    QString msg = tr("You are in the middle of a Configure.\n"
541
                   "If you Exit now the configure information will be lost.\n"
542
                   "Are you sure you want to Exit?");
543
544
    QString title = tr("Confirm Exit");
    QMessageBox::StandardButton btn;
Clinton Stimpson's avatar
Clinton Stimpson committed
545
    btn = QMessageBox::critical(this, title, msg,
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
                                QMessageBox::Yes | QMessageBox::No);
    if(btn == QMessageBox::No)
      {
      e->ignore();
      }
    else
      {
      this->doInterrupt();
      }
    }

  // let the generate finish
  if(this->CurrentState == Generating)
    {
    e->ignore();
    }
562
563
564
565
}

void CMakeSetupDialog::doHelp()
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
  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 "
581
582
    "should click the Generate button.  This will write the build files to the build "
    "directory.");
Clinton Stimpson's avatar
   
Clinton Stimpson committed
583
584

  QDialog dialog;
585
586
587
  QFontMetrics met(this->font());
  int msgWidth = met.width(msg);
  dialog.setMinimumSize(msgWidth/15,20);
588
  dialog.setWindowTitle(tr("Help"));
Clinton Stimpson's avatar
   
Clinton Stimpson committed
589
  QVBoxLayout* l = new QVBoxLayout(&dialog);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
590
591
592
  QLabel* lab = new QLabel(&dialog);
  lab->setText(msg);
  lab->setWordWrap(true);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
593
594
595
  QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
                                                Qt::Horizontal, &dialog);
  QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
596
  l->addWidget(lab);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
597
598
599
600
601
602
  l->addWidget(btns);
  dialog.exec();
}

void CMakeSetupDialog::doInterrupt()
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
603
  this->enterState(Interrupting);
604
  this->CMakeThread->cmakeInstance()->interrupt();
605
606
607
608
}

void CMakeSetupDialog::doSourceBrowse()
{
609
  QString dir = QFileDialog::getExistingDirectory(this,
610
611
    tr("Enter Path to Source"), this->SourceDirectory->text(),
    QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
612
613
  if(!dir.isEmpty())
    {
614
    this->setSourceDirectory(dir);
615
616
617
618
619
    }
}

void CMakeSetupDialog::updateSourceDirectory(const QString& dir)
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
620
621
  if(this->SourceDirectory->text() != dir)
    {
Clinton Stimpson's avatar
   
Clinton Stimpson committed
622
623
624
    this->SourceDirectory->blockSignals(true);
    this->SourceDirectory->setText(dir);
    this->SourceDirectory->blockSignals(false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
625
    }
626
627
}

628
629
630
631
632
633
634
635
636
637
void CMakeSetupDialog::updateBinaryDirectory(const QString& dir)
{
  if(this->BinaryDirectory->currentText() != dir)
    {
    this->BinaryDirectory->blockSignals(true);
    this->BinaryDirectory->setEditText(dir);
    this->BinaryDirectory->blockSignals(false);
    }
}

638
639
void CMakeSetupDialog::doBinaryBrowse()
{
640
  QString dir = QFileDialog::getExistingDirectory(this,
641
642
    tr("Enter Path to Build"), this->BinaryDirectory->currentText(),
    QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
643
  if(!dir.isEmpty() && dir != this->BinaryDirectory->currentText())
644
    {
645
    this->setBinaryDirectory(dir);
646
647
648
649
    }
}

void CMakeSetupDialog::setBinaryDirectory(const QString& dir)
Clinton Stimpson's avatar
   
Clinton Stimpson committed
650
651
652
653
654
655
{
  this->BinaryDirectory->setEditText(dir);
}

void CMakeSetupDialog::onSourceDirectoryChanged(const QString& dir)
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
656
  this->Output->clear();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
657
658
659
660
661
  QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
    "setSourceDirectory", Qt::QueuedConnection, Q_ARG(QString, dir));
}

void CMakeSetupDialog::onBinaryDirectoryChanged(const QString& dir)
662
{
663
664
665
666
667
  QString title = QString(tr("CMake %1 - %2"));
  title = title.arg(cmVersion::GetCMakeVersion());
  title = title.arg(dir);
  this->setWindowTitle(title);

668
  this->CacheModified = false;
Clinton Stimpson's avatar
   
Clinton Stimpson committed
669
  this->CacheValues->cacheModel()->clear();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
670
  qobject_cast<QCMakeCacheModelDelegate*>(this->CacheValues->itemDelegate())->clearChanges();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
671
672
673
  this->Output->clear();
  QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
    "setBinaryDirectory", Qt::QueuedConnection, Q_ARG(QString, dir));
674
675
}

Clinton Stimpson's avatar
   
Clinton Stimpson committed
676
677
678
679
680
void CMakeSetupDialog::setSourceDirectory(const QString& dir)
{
  this->SourceDirectory->setText(dir);
}

Clinton Stimpson's avatar
   
Clinton Stimpson committed
681
void CMakeSetupDialog::showProgress(const QString& /*msg*/, float percent)
682
{
683
  percent = (percent * ProgressFactor) + ProgressOffset;
Clinton Stimpson's avatar
   
Clinton Stimpson committed
684
  this->ProgressBar->setValue(qRound(percent * 100));
685
}
Clinton Stimpson's avatar
   
Clinton Stimpson committed
686

Clinton Stimpson's avatar
Clinton Stimpson committed
687
void CMakeSetupDialog::error(const QString& msg)
688
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
689
  this->Output->setCurrentCharFormat(this->ErrorFormat);
690
691
692
693
694
695
696
  //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
697
698
}

Clinton Stimpson's avatar
Clinton Stimpson committed
699
void CMakeSetupDialog::message(const QString& msg)
700
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
701
  this->Output->setCurrentCharFormat(this->MessageFormat);
Clinton Stimpson's avatar
Clinton Stimpson committed
702
  this->Output->append(msg);
703
704
}

Clinton Stimpson's avatar
   
Clinton Stimpson committed
705
706
void CMakeSetupDialog::setEnabledState(bool enabled)
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
707
  // disable parts of the GUI during configure/generate
Clinton Stimpson's avatar
   
Clinton Stimpson committed
708
  this->CacheValues->cacheModel()->setEditEnabled(enabled);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
709
710
711
712
  this->SourceDirectory->setEnabled(enabled);
  this->BrowseSourceDirectoryButton->setEnabled(enabled);
  this->BinaryDirectory->setEnabled(enabled);
  this->BrowseBinaryDirectoryButton->setEnabled(enabled);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
713
714
715
716
  this->ReloadCacheAction->setEnabled(enabled);
  this->DeleteCacheAction->setEnabled(enabled);
  this->ExitAction->setEnabled(enabled);
  this->ConfigureAction->setEnabled(enabled);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
717
  this->AddEntry->setEnabled(enabled);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
718
  this->RemoveEntry->setEnabled(false);  // let selection re-enable it
719
720
}

Clinton Stimpson's avatar
   
Clinton Stimpson committed
721
bool CMakeSetupDialog::setupFirstConfigure()
Clinton Stimpson's avatar
   
Clinton Stimpson committed
722
{
Clinton Stimpson's avatar
   
Clinton Stimpson committed
723
  FirstConfigure dialog;
Clinton Stimpson's avatar
   
Clinton Stimpson committed
724

Clinton Stimpson's avatar
   
Clinton Stimpson committed
725
726
727
728
729
730
731
  // 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
732

Clinton Stimpson's avatar
   
Clinton Stimpson committed
733
734
  if(dialog.exec() == QDialog::Accepted)
    {
Clinton Stimpson's avatar
   
Clinton Stimpson committed
735
736
    dialog.saveToSettings();
    this->CMakeThread->cmakeInstance()->setGenerator(dialog.getGenerator());
737

Clinton Stimpson's avatar
   
Clinton Stimpson committed
738
739
740
741
742
743
744
    QCMakeCacheModel* m = this->CacheValues->cacheModel();

    if(dialog.compilerSetup())
      {
      QString fortranCompiler = dialog.getFortranCompiler();
      if(!fortranCompiler.isEmpty())
        {
745
        m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER",
Clinton Stimpson's avatar
   
Clinton Stimpson committed
746
747
748
749
750
                          "Fortran compiler.", fortranCompiler, false);
        }
      QString cxxCompiler = dialog.getCXXCompiler();
      if(!cxxCompiler.isEmpty())
        {
751
        m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER",
Clinton Stimpson's avatar
   
Clinton Stimpson committed
752
753
                          "CXX compiler.", cxxCompiler, false);
        }
754

Clinton Stimpson's avatar
   
Clinton Stimpson committed
755
756
757
      QString cCompiler = dialog.getCCompiler();
      if(!cCompiler.isEmpty())
        {
758
        m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER",
Clinton Stimpson's avatar
   
Clinton Stimpson committed
759
760
761
762
763
                          "C compiler.", cCompiler, false);
        }
      }
    else if(dialog.crossCompilerSetup())
      {
Clinton Stimpson's avatar
   
Clinton Stimpson committed
764
765
      QString fortranCompiler = dialog.getFortranCompiler();
      if(!fortranCompiler.isEmpty())
Clinton Stimpson's avatar
   
Clinton Stimpson committed
766
        {
767
        m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER",
Clinton Stimpson's avatar
   
Clinton Stimpson committed
768
                          "Fortran compiler.", fortranCompiler, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
769
        }
Clinton Stimpson's avatar
   
Clinton Stimpson committed
770
771

      QString mode = dialog.getCrossIncludeMode();
772
      m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_INCLUDE",
773
                        tr("CMake Find Include Mode"), mode, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
774
      mode = dialog.getCrossLibraryMode();
775
      m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_LIBRARY",
776
                        tr("CMake Find Library Mode"), mode, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
777
      mode = dialog.getCrossProgramMode();
778
      m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_PROGRAM",
779
                        tr("CMake Find Program Mode"), mode, false);
780

Clinton Stimpson's avatar
   
Clinton Stimpson committed
781
      QString rootPath = dialog.getCrossRoot();
782
      m->insertProperty(QCMakeProperty::PATH, "CMAKE_FIND_ROOT_PATH",
783
                        tr("CMake Find Root Path"), rootPath, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
784
785

      QString systemName = dialog.getSystemName();
786
      m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_NAME",
787
                        tr("CMake System Name"), systemName, false);
788
789
790
      QString systemVersion = dialog.getSystemVersion();
      m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_VERSION",
                        tr("CMake System Version"), systemVersion, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
791
      QString cxxCompiler = dialog.getCXXCompiler();
792
      m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER",
793
                        tr("CXX compiler."), cxxCompiler, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
794
      QString cCompiler = dialog.getCCompiler();
795
      m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER",
796
                        tr("C compiler."), cCompiler, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
797
798
799
800
      }
    else if(dialog.crossCompilerToolChainFile())
      {
      QString toolchainFile = dialog.getCrossCompilerToolChainFile();
801
      m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_TOOLCHAIN_FILE",
802
                        tr("Cross Compile ToolChain File"), toolchainFile, false);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
803
      }
Clinton Stimpson's avatar
   
Clinton Stimpson committed
804
805
806
807
    return true;
    }

  return false;
Clinton Stimpson's avatar
   
Clinton Stimpson committed
808
}
809
810
811

void CMakeSetupDialog::updateGeneratorLabel(const QString& gen)
{
812
  QString str = tr("Current Generator: ");
813
814
815
816
817
818
819
820
821
822
823
  if(gen.isEmpty())
    {
    str += tr("None");
    }
  else
    {
    str += gen;
    }
  this->Generator->setText(str);
}

Clinton Stimpson's avatar
Clinton Stimpson committed
824
825
826
827
828
829
830
void CMakeSetupDialog::doReloadCache()
{
  QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
    "reloadCache", Qt::QueuedConnection);
}

void CMakeSetupDialog::doDeleteCache()
831
{
832
  QString title = tr("Delete Cache");
833
  QString msg = tr("Are you sure you want to delete the cache?");
834
  QMessageBox::StandardButton btn;
835
  btn = QMessageBox::information(this, title, msg,
836
837
838
839
840
                                 QMessageBox::Yes | QMessageBox::No);
  if(btn == QMessageBox::No)
    {
    return;
    }
Clinton Stimpson's avatar
Clinton Stimpson committed
841
  QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
842
                            "deleteCache", Qt::QueuedConnection);
Clinton Stimpson's avatar
Clinton Stimpson committed
843
844
845
846
}

void CMakeSetupDialog::doAbout()
{
847
848
  QString msg = tr(
    "CMake %1 (cmake.org).\n"
849
    "CMake suite maintained and supported by Kitware (kitware.com/cmake).\n"
850
851
852
853
    "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"
854
855
856
857
858
859
#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
860
    );
Clinton Stimpson's avatar
   
Clinton Stimpson committed
861
862
  msg = msg.arg(cmVersion::GetCMakeVersion());
  msg = msg.arg(qVersion());
863
864
865
866
#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
867
868

  QDialog dialog;
869
  dialog.setWindowTitle(tr("About"));
Clinton Stimpson's avatar
Clinton Stimpson committed
870
871
872
873
874
875
876
877
878
879
880
881
882
883
  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
884
  this->ExitAfterGenerate = b;
Clinton Stimpson's avatar
Clinton Stimpson committed
885
886
}

Clinton Stimpson's avatar
   
Clinton Stimpson committed
887
888
889
void CMakeSetupDialog::addBinaryPath(const QString& path)
{
  QString cleanpath = QDir::cleanPath(path);
890

Clinton Stimpson's avatar
   
Clinton Stimpson committed
891
892
  // update UI
  this->BinaryDirectory->blockSignals(true);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
893
894
895
896
897
898
899
  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
900
  this->BinaryDirectory->blockSignals(false);
901

Clinton Stimpson's avatar
   
Clinton Stimpson committed
902
903
904
  // save to registry
  QStringList buildPaths = this->loadBuildPaths();
  buildPaths.removeAll(cleanpath);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
905
  buildPaths.prepend(cleanpath);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
906
  this->saveBuildPaths(buildPaths);
Clinton Stimpson's avatar
   
Clinton Stimpson committed
907
908
909
910
}

void CMakeSetupDialog::dragEnterEvent(QDragEnterEvent* e)
{
911
  if(!(this->CurrentState == ReadyConfigure ||
912
     this->CurrentState == ReadyGenerate))
913
914
915
916
917
    {
    e->ignore();
    return;
    }

Clinton Stimpson's avatar
   
Clinton Stimpson committed
918
919
  const QMimeData* dat = e->mimeData();
  QList<QUrl> urls = dat->urls();
Clinton Stimpson's avatar
   
Clinton Stimpson committed
920
  QString file = urls.count() ? urls[0].toLocalFile() : QString();
Alexander Neundorf's avatar