1 #include "QMacInstallDialog.h"
3 #include "cmSystemTools.h"
6 #include "ui_MacInstallDialog.h"
8 class QMacInstallDialog::QMacInstallDialogInternals
: public Ui::Dialog
13 QMacInstallDialog::QMacInstallDialog(QWidget
*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?")
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] == '.')
64 std::string file
= fileInfo
.absoluteFilePath().toStdString();
65 std::string newName
= installTo
;
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
)
87 std::cout
<< "ln -s [" << file
<< "] [";
88 std::cout
<< newName
<< "]\n";
89 if(!cmSystemTools::CreateSymlink(file
.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
)
108 void QMacInstallDialog::SkipInstall()
114 void QMacInstallDialog::ShowBrowser()
116 QString dir
= QFileDialog::getExistingDirectory(this,
117 tr("Enter Install Prefix"), this->Internals
->InstallPrefix
->text());
120 this->Internals
->InstallPrefix
->setText(dir
);