QMacInstallDialog.cxx 2.8 KB

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