Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / QtDialog / QMacInstallDialog.cxx
blobfbeb10efb53c3e7ca60d1866167b9ddfe2c3650c
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 if(!cmSystemTools::RemoveFile(newName.c_str()))
74 QString message = tr("Failed to remove file "
75 "installation may be incomplete: ");
76 message += newName.c_str();
77 QString title = tr("Error Removing file");
78 QMessageBox::StandardButton btn =
79 QMessageBox::critical(this, title, message,
80 QMessageBox::Ok|QMessageBox::Abort);
81 if(btn == QMessageBox::Abort)
83 return;
87 std::cout << "ln -s [" << file << "] [";
88 std::cout << newName << "]\n";
89 if(!cmSystemTools::CreateSymlink(file.c_str(),
90 newName.c_str()))
92 QString message = tr("Failed create symlink "
93 "installation may be incomplete: ");
94 message += newName.c_str();
95 QString title = tr("Error Creating Symlink");
96 QMessageBox::StandardButton btn =
97 QMessageBox::critical(this, title, message,
98 QMessageBox::Ok|QMessageBox::Abort);
99 if(btn == QMessageBox::Abort)
101 return;
105 this->done(0);
108 void QMacInstallDialog::SkipInstall()
110 this->done(0);
114 void QMacInstallDialog::ShowBrowser()
116 QString dir = QFileDialog::getExistingDirectory(this,
117 tr("Enter Install Prefix"), this->Internals->InstallPrefix->text());
118 if(!dir.isEmpty())
120 this->Internals->InstallPrefix->setText(dir);