void ChooseRHome::setValue(const RVersion& value, bool preferR64) { if (value.isEmpty()) { if (preferR64) ui->radioDefault64->setChecked(true); else ui->radioDefault->setChecked(true); } else { ui->radioCustom->setChecked(true); QList<QListWidgetItem*> matches = ui->listHomeDir->findItems(value.description(), Qt::MatchExactly); if (matches.size() > 0) matches.first()->setSelected(true); ui->listHomeDir->setFocus(); } }
void ChooseRHome::chooseOther() { if (lastDir_.isEmpty()) { lastDir_ = QString::fromLocal8Bit(core::system::getenv("ProgramFiles").c_str()); } QString dir = QFileDialog::getExistingDirectory( this, QString::fromUtf8("Choose R Directory"), lastDir_, QFileDialog::ShowDirsOnly); if (dir.isEmpty()) return; lastDir_ = dir; QList<RVersion> versions = detectVersionsInDir(dir); RVersion rVer; if (versions.size() == 0) { showWarning( this, QString::fromUtf8("Invalid R Directory"), QString::fromUtf8("This directory does not appear to contain a " "valid R installation.\n\nPlease try again.")); return; } else if (versions.size() > 1) { QStringList items; for (int i = 0; i < versions.size(); i++) items << versions.at(i).description(); QInputDialog inputDialog(this); inputDialog.setOptions(QInputDialog::UseListViewForComboBoxItems); inputDialog.setComboBoxItems(items); inputDialog.setComboBoxEditable(false); inputDialog.setWindowTitle(QString::fromUtf8("Choose Version")); inputDialog.setLabelText(QString::fromUtf8("Please choose the version to use:")); if (inputDialog.exec() != QDialog::Accepted) return; int idx = items.indexOf(QRegExp(inputDialog.textValue(), Qt::CaseSensitive, QRegExp::FixedString)); if (idx < 0) return; rVer = versions.at(idx); } else // versions.size() == 1 { rVer = versions.at(0); } switch (rVer.validate()) { case desktop::ValidateSuccess: break; case desktop::ValidateNotFound: showWarning( this, QString::fromUtf8("Invalid R Directory"), QString::fromUtf8("This directory does not appear to contain a " "valid R installation.\n\nPlease try again.")); return; case desktop::ValidateBadArchitecture: showWarning( this, QString::fromUtf8("Incompatible R Build"), QString::fromUtf8("The version of R you've selected was built " "for a different CPU architecture and cannot " "be used with this version of RStudio.")); return; case desktop::ValidateVersionTooOld: default: showWarning( this, QString::fromUtf8("Incompatible R Build"), QString::fromUtf8("The version of R you've selected is not " "compatible with RStudio. Please install a " "newer version of R.")); return; } QList<QListWidgetItem*> items = ui->listHomeDir->findItems( rVer.description(), Qt::MatchExactly); if (!items.isEmpty()) { ui->listHomeDir->setCurrentItem(items[0]); } else { QListWidgetItem* pItem = toItem(rVer); ui->listHomeDir->addItem(pItem); pItem->setSelected(true); } }