File indexing completed on 2024-04-28 04:37:48
0001 /* 0002 SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "projectvcspage.h" 0008 #include "ui_projectvcspage.h" 0009 0010 #include <QStackedWidget> 0011 0012 #include <KComboBox> 0013 #include <KLocalizedString> 0014 0015 #include <interfaces/iplugincontroller.h> 0016 #include <interfaces/iplugin.h> 0017 0018 #include <vcs/vcslocation.h> 0019 #include <vcs/widgets/vcsimportmetadatawidget.h> 0020 #include <vcs/interfaces/ibasicversioncontrol.h> 0021 0022 using namespace KDevelop; 0023 0024 ProjectVcsPage::ProjectVcsPage( KDevelop::IPluginController* controller, QWidget * parent ) 0025 : AppWizardPageWidget(parent) 0026 , m_currentImportWidget(nullptr) 0027 , m_ui(new Ui::ProjectVcsPage) 0028 { 0029 m_ui->setupUi( this ); 0030 const QList<KDevelop::IPlugin*> vcsplugins = controller->allPluginsForExtension(QStringLiteral("org.kdevelop.IBasicVersionControl")); 0031 int idx = 1; 0032 m_ui->vcsImportOptions->insertWidget( 0, new QWidget(this) ); 0033 m_ui->vcsTypes->insertItem( 0, i18nc("@item:inlistbox No Version Control Support chosen", "None") ); 0034 for (KDevelop::IPlugin* plugin : vcsplugins) { 0035 auto* iface = plugin->extension<KDevelop::IBasicVersionControl>(); 0036 if( iface ) 0037 { 0038 KDevelop::VcsImportMetadataWidget* widget = iface->createImportMetadataWidget( 0039 m_ui->vcsImportOptions ); 0040 if( widget ) 0041 { 0042 // untranslated on purpose, as English might be lingua franca at most target users 0043 // perhaps make default string configurable if people request it 0044 widget->setMessage(QStringLiteral("Initial import")); 0045 widget->setSourceLocationEditable( false ); 0046 widget->setUseSourceDirForDestination( true ); 0047 m_ui->vcsTypes->insertItem( idx, iface->name() ); 0048 importWidgets.push_back( widget ); 0049 vcsPlugins.push_back( qMakePair( controller->pluginInfo( plugin ).pluginId(), iface->name() ) ); 0050 m_ui->vcsImportOptions->insertWidget( idx, widget ); 0051 idx++; 0052 } 0053 } 0054 } 0055 connect( m_ui->vcsTypes, QOverload<int>::of(&KComboBox::activated), 0056 m_ui->vcsImportOptions, &QStackedWidget::setCurrentIndex ); 0057 connect( m_ui->vcsTypes, QOverload<int>::of(&KComboBox::activated), 0058 this, &ProjectVcsPage::vcsTypeChanged ); 0059 vcsTypeChanged(m_ui->vcsTypes->currentIndex()); 0060 } 0061 0062 0063 void ProjectVcsPage::vcsTypeChanged( int idx ) 0064 { 0065 if (m_currentImportWidget) { 0066 disconnect(m_currentImportWidget, &VcsImportMetadataWidget::changed, this, &ProjectVcsPage::validateData); 0067 } 0068 0069 // first type in list is "no vcs", without an import widget 0070 const int widgetIndex = idx - 1; 0071 m_currentImportWidget = importWidgets.value(widgetIndex); 0072 0073 validateData(); 0074 0075 if (m_currentImportWidget) { 0076 connect(m_currentImportWidget, &VcsImportMetadataWidget::changed, this, &ProjectVcsPage::validateData); 0077 } 0078 } 0079 0080 void ProjectVcsPage::validateData() 0081 { 0082 if( shouldContinue() ) { 0083 emit valid(); 0084 } else { 0085 emit invalid(); 0086 } 0087 } 0088 0089 0090 ProjectVcsPage::~ProjectVcsPage( ) 0091 { 0092 delete m_ui; 0093 } 0094 0095 void ProjectVcsPage::setSourceLocation( const QUrl& s ) 0096 { 0097 for (KDevelop::VcsImportMetadataWidget* widget : qAsConst(importWidgets)) { 0098 widget->setSourceLocation( KDevelop::VcsLocation( s ) ); 0099 } 0100 } 0101 0102 QString ProjectVcsPage::pluginName() const 0103 { 0104 int idx = m_ui->vcsTypes->currentIndex() - 1; 0105 if ( idx < 0 || idx >= vcsPlugins.size()) 0106 return QString(); 0107 0108 // FIXME: Two return statements 0109 return vcsPlugins[idx].first; 0110 } 0111 0112 0113 QString ProjectVcsPage::commitMessage() const 0114 { 0115 if (!m_currentImportWidget) { 0116 return QString(); 0117 } 0118 0119 return m_currentImportWidget->message(); 0120 } 0121 0122 QUrl ProjectVcsPage::source() const 0123 { 0124 if (!m_currentImportWidget) { 0125 return QUrl(); 0126 } 0127 0128 return m_currentImportWidget->source(); 0129 } 0130 0131 KDevelop::VcsLocation ProjectVcsPage::destination() const 0132 { 0133 if (!m_currentImportWidget) { 0134 return KDevelop::VcsLocation(); 0135 } 0136 0137 return m_currentImportWidget->destination(); 0138 } 0139 0140 0141 bool ProjectVcsPage::shouldContinue() 0142 { 0143 if (!m_currentImportWidget) { 0144 return true; 0145 } 0146 0147 return m_currentImportWidget->hasValidData(); 0148 } 0149 0150 #include "moc_projectvcspage.cpp"