Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / QtDialog / QMacInstallDialog.cxx
blob70293f82b37ad0d0df7feecac9e752466bc1f44d
1 #include "QMacInstallDialog.h"
2 #include <QMessageBox>
3 #include "cmSystemTools.h"
4 #include <iostream>
5 #include <QFileDialog>
6 #include "ui_MacInstallDialog.h"
8 class QMacInstallDialog::QMacInstallDialogInternals : public Ui::Dialog
10 public:
13 QMacInstallDialog::QMacInstallDialog(QWidget*w)
14 :QDialog(w)
16 this->Internals = new QMacInstallDialogInternals;
17 this->Internals->setupUi(this);
18 QObject::connect(this->Internals->choosePathButton, SIGNAL(pressed()),
19 this, SLOT(ShowBrowser()));
20 QObject::connect(this->Internals->skipInstallButton, SIGNAL(pressed()),
21 this, SLOT(SkipInstall()));
22 QObject::connect(this->Internals->doInstallButton, SIGNAL(pressed()),
23 this, SLOT(DoInstall()));
24 this->Internals->InstallPrefix->setText("/usr/bin/");
28 QMacInstallDialog::~QMacInstallDialog()
30 delete this->Internals;
33 void QMacInstallDialog::DoInstall()
35 QDir installDir(this->Internals->InstallPrefix->text());
36 std::string installTo = installDir.path().toStdString();
37 if(!cmSystemTools::FileExists(installTo.c_str()))
39 QString message = tr("Build install does not exist, "
40 "should I create it?")
41 + "\n\n"
42 + tr("Directory: ");
43 message += installDir.path();
44 QString title = tr("Create Directory");
45 QMessageBox::StandardButton btn;
46 btn = QMessageBox::information(this, title, message,
47 QMessageBox::Yes | QMessageBox::No);
48 if(btn == QMessageBox::Yes)
50 cmSystemTools::MakeDirectory(installTo.c_str());
53 QDir cmExecDir(QApplication::applicationDirPath());
54 cmExecDir.cd("../bin");
55 QFileInfoList list = cmExecDir.entryInfoList();
56 for (int i = 0; i < list.size(); ++i)
58 QFileInfo fileInfo = list.at(i);
59 std::string filename = fileInfo.fileName().toStdString();
60 if(filename.size() && filename[0] == '.')
62 continue;
64 std::string file = fileInfo.absoluteFilePath().toStdString();
65 std::string newName = installTo;
66 newName += "/";
67 newName += filename;
68 // Remove the old files
69 if(cmSystemTools::FileExists(newName.c_str()))
71 std::cout << "rm [" << newName << "]\n";
72 cmSystemTools::RemoveFile(newName.c_str());
74 std::cout << "ln -s [" << file << "] [";
75 std::cout << newName << "]\n";
76 cmSystemTools::CreateSymlink(file.c_str(),
77 newName.c_str());
79 this->done(0);
82 void QMacInstallDialog::SkipInstall()
84 this->done(0);
88 void QMacInstallDialog::ShowBrowser()
90 QString dir = QFileDialog::getExistingDirectory(this,
91 tr("Enter Install Prefix"), this->Internals->InstallPrefix->text());
92 if(!dir.isEmpty())
94 this->Internals->InstallPrefix->setText(dir);