| 29 | static const int FROM_FILESYSTEM_SOURCE_INDEX = 0; |
| 30 | |
| 31 | ProjectSourcePage::ProjectSourcePage(const QUrl& initial, const QUrl& repoUrl, IPlugin* preSelectPlugin, |
| 32 | QWidget* parent) |
| 33 | : QWidget(parent) |
| 34 | { |
| 35 | m_ui = new Ui::ProjectSourcePage; |
| 36 | m_ui->setupUi(this); |
| 37 | |
| 38 | m_ui->status->setCloseButtonVisible(false); |
| 39 | m_ui->status->setMessageType(KMessageWidget::Error); |
| 40 | |
| 41 | m_ui->workingDir->setUrl(initial); |
| 42 | m_ui->workingDir->setMode(KFile::Directory); |
| 43 | |
| 44 | m_ui->sources->addItem(QIcon::fromTheme(QStringLiteral("folder")), i18nc("@item:inlistbox", "From File System")); |
| 45 | m_plugins.append(nullptr); |
| 46 | |
| 47 | int preselectIndex = -1; |
| 48 | IPluginController* pluginManager = ICore::self()->pluginController(); |
| 49 | const QList<IPlugin*> vcsPlugins = pluginManager->allPluginsForExtension( QStringLiteral("org.kdevelop.IBasicVersionControl") ); |
| 50 | m_plugins.reserve(m_plugins.size() + vcsPlugins.size()); |
| 51 | for (IPlugin* p : vcsPlugins) { |
| 52 | if (p == preSelectPlugin) { |
| 53 | preselectIndex = m_plugins.count(); |
| 54 | } |
| 55 | m_plugins.append(p); |
| 56 | m_ui->sources->addItem(QIcon::fromTheme(pluginManager->pluginInfo(p).iconName()), p->extension<IBasicVersionControl>()->name()); |
| 57 | } |
| 58 | |
| 59 | const QList<IPlugin*> projectPlugins = pluginManager->allPluginsForExtension( QStringLiteral("org.kdevelop.IProjectProvider") ); |
| 60 | m_plugins.reserve(m_plugins.size() + projectPlugins.size()); |
| 61 | for (IPlugin* p : projectPlugins) { |
| 62 | if (p == preSelectPlugin) { |
| 63 | preselectIndex = m_plugins.count(); |
| 64 | } |
| 65 | m_plugins.append(p); |
| 66 | m_ui->sources->addItem(QIcon::fromTheme(pluginManager->pluginInfo(p).iconName()), p->extension<IProjectProvider>()->name()); |
| 67 | } |
| 68 | |
| 69 | if (preselectIndex == -1) { |
| 70 | // "From File System" is quite unlikely to be what the user wants, so default to first real plugin... |
| 71 | const int defaultIndex = (m_plugins.count() > 1) ? 1 : 0; |
| 72 | KConfigGroup configGroup = KSharedConfig::openConfig()->group(QStringLiteral("Providers")); |
| 73 | preselectIndex = configGroup.readEntry("LastProviderIndex", defaultIndex); |
| 74 | } |
| 75 | preselectIndex = qBound(0, preselectIndex, m_ui->sources->count() - 1); |
| 76 | m_ui->sources->setCurrentIndex(preselectIndex); |
| 77 | setSourceWidget(preselectIndex, repoUrl); |
| 78 | |
| 79 | // connect as last step, otherwise KMessageWidget could get both animatedHide() and animatedShow() |
| 80 | // during setup and due to a bug will ignore any but the first call |
| 81 | // Only fixed for KF5 5.32 |
| 82 | connect(m_ui->workingDir, &KUrlRequester::textChanged, this, &ProjectSourcePage::reevaluateCorrection); |
| 83 | connect(m_ui->sources, QOverload<int>::of(&QComboBox::currentIndexChanged), |
| 84 | this, &ProjectSourcePage::setSourceIndex); |
| 85 | connect(m_ui->get, &QPushButton::clicked, this, &ProjectSourcePage::checkoutVcsProject); |
| 86 | } |
| 87 | |
| 88 | ProjectSourcePage::~ProjectSourcePage() |
nothing calls this directly
no test coverage detected