maemo5settingsgui.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #include <algorithm>
  2. #include <QFileDialog>
  3. #include <QFileInfo>
  4. #include "maemo5settingsgui.h"
  5. #include "ui_maemo5settingsgui.h"
  6. #include "longinputdialog.h"
  7. #include "settings.h"
  8. // TODO perform sanity check of data input
  9. Maemo5SettingsGui::Maemo5SettingsGui(const QList<QString> & licences,
  10. const QString & app,
  11. QWidget * parent) :
  12. QWidget(parent),
  13. ui(new Ui::Maemo5SettingsGui),
  14. m_app(app)
  15. {
  16. ui->setupUi(this);
  17. ui->m_authorName->setText(Settings::get(Settings::HybridAuthor).toString());
  18. ui->m_authorEmail->setText(Settings::get(Settings::HybridEmail).toString());
  19. ui->m_shortDesc->setText(Settings::get(Settings::HybridShortDesc, app).toString());
  20. ui->m_longDesc->setText(Settings::get(Settings::HybridLongDesc, app).toString());
  21. // filling up ui->m_licence and selecting default licence (from setttings)
  22. ui->m_licence->addItems(licences);
  23. size_t
  24. licenceIndex = -1;
  25. if (licences.size() > 0)
  26. {
  27. QString
  28. licence = Settings::get(Settings::Licence).toString();
  29. QList<QString>::const_iterator
  30. foundIt = std::find(licences.begin(),
  31. licences.end(),
  32. licence);
  33. if (foundIt != licences.end())
  34. {
  35. licenceIndex = std::distance(licences.begin(),
  36. foundIt);
  37. }
  38. }
  39. ui->m_licence->setCurrentIndex(licenceIndex);
  40. ui->m_logFileValue->setText(Settings::get(Settings::LogFilePath).toString());
  41. QString
  42. bashPathStr = bashPath();
  43. if (bashPathStr.length() > 0)
  44. {
  45. ui->m_bashPath->setText(bashPathStr);
  46. }
  47. ui->m_checkWidgetPannable->setChecked(Settings::get(Settings::PanningEnabled).toBool());
  48. ui->m_checkTextSelectable->setChecked(Settings::get(Settings::TextSelectionEnabled).toBool());
  49. // Connect browse buttons
  50. connect(ui->m_buttonBrowseBash, SIGNAL(clicked()), this, SLOT(browseForBash()));
  51. connect(ui->m_buttonBrowseLog, SIGNAL(clicked()), this, SLOT(browseForLog()));
  52. connect(ui->m_longDescButton, SIGNAL(clicked()), this, SLOT(editLongDesc()));
  53. }
  54. Maemo5SettingsGui::~Maemo5SettingsGui()
  55. {
  56. delete ui;
  57. }
  58. void Maemo5SettingsGui::changeEvent(QEvent *e)
  59. {
  60. QWidget::changeEvent(e);
  61. switch (e->type()) {
  62. case QEvent::LanguageChange:
  63. ui->retranslateUi(this);
  64. break;
  65. default:
  66. break;
  67. }
  68. }
  69. void Maemo5SettingsGui::saveSettings() const
  70. {
  71. Settings::set(Settings::HybridAuthor, ui->m_authorName->text().trimmed());
  72. Settings::set(Settings::HybridEmail, ui->m_authorEmail->text().trimmed());
  73. Settings::set(Settings::HybridShortDesc, ui->m_shortDesc->text().trimmed(), m_app);
  74. Settings::set(Settings::HybridLongDesc, ui->m_longDesc->text().trimmed(), m_app);
  75. int
  76. licenceIndex = ui->m_licence->currentIndex();
  77. QString
  78. licence;
  79. if (licenceIndex != -1)
  80. {
  81. licence = ui->m_licence->itemText(licenceIndex);
  82. }
  83. Settings::set(Settings::Licence,
  84. licence);
  85. Settings::set(Settings::LogFilePath, ui->m_logFileValue->text().trimmed());
  86. // see comments in constructor about madde path
  87. QString
  88. bashPath = ui->m_bashPath->text().trimmed();
  89. QRegExp
  90. bashExeRx("[/\\\\]bash.exe$");
  91. QString
  92. maddePath = bashPath.replace(bashExeRx, "");
  93. if (QFileInfo(maddePath).isDir())
  94. {
  95. Settings::set(Settings::MaddePath, maddePath);
  96. }
  97. Settings::set(Settings::PanningEnabled, ui->m_checkWidgetPannable->isChecked());
  98. Settings::set(Settings::TextSelectionEnabled, ui->m_checkTextSelectable->isChecked());
  99. }
  100. void Maemo5SettingsGui::browseForBash()
  101. {
  102. QString
  103. bashPath = ui->m_bashPath->text();
  104. QFileInfo
  105. bash = getFileInfo(bashPath);
  106. bashPath = QFileDialog::getOpenFileName(this,
  107. tr("Select path to madde bash.exe"),
  108. bash.absolutePath(),
  109. tr("Bash.exe") + " (bash.exe);;" + tr("All Files (*)"));
  110. if (!bashPath.isEmpty())
  111. {
  112. bashPath = QDir::toNativeSeparators(bashPath);
  113. ui->m_bashPath->setText(bashPath);
  114. }
  115. }
  116. void Maemo5SettingsGui::browseForLog()
  117. {
  118. // Existing
  119. QFileInfo
  120. file = getFileInfo(ui->m_logFileValue->text());
  121. QString
  122. fileName = QFileDialog::getOpenFileName(this, tr("Select application log file"), file.absolutePath(), tr("Log files") + " (*.log);;" + tr("All Files (*)"));
  123. if (!fileName.isEmpty())
  124. {
  125. fileName = QDir::toNativeSeparators(fileName);
  126. ui->m_logFileValue->setText(fileName);
  127. }
  128. }
  129. void Maemo5SettingsGui::editLongDesc()
  130. {
  131. LongInputDialog
  132. liDlg(tr("Detail application description"),
  133. tr("Enter app description:"),
  134. ui->m_longDesc->text());
  135. if (liDlg.exec() == QDialog::Accepted)
  136. {
  137. ui->m_longDesc->setText(liDlg.contentText());
  138. }
  139. }
  140. QFileInfo Maemo5SettingsGui::getFileInfo(QString fileName)
  141. {
  142. QFileInfo file(fileName);
  143. if (!QFile::exists(file.absolutePath()))
  144. {
  145. file = QFileInfo(QDir::root().absolutePath());
  146. }
  147. return file;
  148. }
  149. QString Maemo5SettingsGui::bashPath()
  150. {
  151. // what we store in settings is path to the directory with "bash.exe"
  152. // and "mad" files - but for clarity, we make the user set the path
  153. // to bash.exe
  154. QString
  155. rv;
  156. QString
  157. maddePath = Settings::get(Settings::MaddePath).toString();
  158. if (maddePath.length() > 0)
  159. {
  160. rv = maddePath + QDir::separator() + "bash.exe";
  161. }
  162. return rv;
  163. }