diff --git a/plugins/appwizard/appwizardplugin.cpp b/plugins/appwizard/appwizardplugin.cpp index 99961ec12..452c45ae4 100644 --- a/plugins/appwizard/appwizardplugin.cpp +++ b/plugins/appwizard/appwizardplugin.cpp @@ -1,515 +1,515 @@ /*************************************************************************** * Copyright 2001 Bernd Gehrmann * * Copyright 2004-2005 Sascha Cunz * * Copyright 2005 Ian Reinhart Geiser * * Copyright 2007 Alexander Dymo * * Copyright 2008 Evgeniy Ivanov * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "appwizardplugin.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "appwizarddialog.h" #include "projectselectionpage.h" #include "projectvcspage.h" #include "projecttemplatesmodel.h" #include "debug.h" using namespace KDevelop; Q_LOGGING_CATEGORY(PLUGIN_APPWIZARD, "kdevplatform.plugins.appwizard") K_PLUGIN_FACTORY_WITH_JSON(AppWizardFactory, "kdevappwizard.json", registerPlugin();) AppWizardPlugin::AppWizardPlugin(QObject *parent, const QVariantList &) : KDevelop::IPlugin(QStringLiteral("kdevappwizard"), parent) , m_templatesModel(nullptr) { setXMLFile(QStringLiteral("kdevappwizard.rc")); m_newFromTemplate = actionCollection()->addAction(QStringLiteral("project_new")); m_newFromTemplate->setIcon(QIcon::fromTheme(QStringLiteral("project-development-new-template"))); m_newFromTemplate->setText(i18n("New From Template...")); connect(m_newFromTemplate, &QAction::triggered, this, &AppWizardPlugin::slotNewProject); m_newFromTemplate->setToolTip( i18n("Generate a new project from a template") ); m_newFromTemplate->setWhatsThis( i18n("This starts KDevelop's application wizard. " "It helps you to generate a skeleton for your " "application from a set of templates.") ); } AppWizardPlugin::~AppWizardPlugin() { } void AppWizardPlugin::slotNewProject() { model()->refresh(); AppWizardDialog dlg(core()->pluginController(), m_templatesModel); if (dlg.exec() == QDialog::Accepted) { QString project = createProject( dlg.appInfo() ); if (!project.isEmpty()) { core()->projectController()->openProject(QUrl::fromLocalFile(project)); KConfig templateConfig(dlg.appInfo().appTemplate); KConfigGroup general(&templateConfig, "General"); QString file = general.readEntry("ShowFilesAfterGeneration"); if (!file.isEmpty()) { file = KMacroExpander::expandMacros(file, m_variables); core()->documentController()->openDocument(QUrl::fromUserInput(file)); } } else { KMessageBox::error( ICore::self()->uiController()->activeMainWindow(), i18n("Could not create project from template\n"), i18n("Failed to create project") ); } } } namespace { IDistributedVersionControl* toDVCS(IPlugin* plugin) { Q_ASSERT(plugin); return plugin->extension(); } ICentralizedVersionControl* toCVCS(IPlugin* plugin) { Q_ASSERT(plugin); return plugin->extension(); } /*! Trouble while initializing version control. Show failure message to user. */ void vcsError(const QString &errorMsg, QTemporaryDir &tmpdir, const QUrl &dest, const QString &details = QString()) { QString displayDetails = details; if (displayDetails.isEmpty()) { displayDetails = i18n("Please see the Version Control toolview"); } KMessageBox::detailedError(nullptr, errorMsg, displayDetails, i18n("Version Control System Error")); KIO::del(dest, KIO::HideProgressInfo)->exec(); tmpdir.remove(); } /*! Setup distributed version control for a new project defined by @p info. Use @p scratchArea for temporary files */ bool initializeDVCS(IDistributedVersionControl* dvcs, const ApplicationInfo& info, QTemporaryDir& scratchArea) { Q_ASSERT(dvcs); qCDebug(PLUGIN_APPWIZARD) << "DVCS system is used, just initializing DVCS"; const QUrl& dest = info.location; //TODO: check if we want to handle KDevelop project files (like now) or only SRC dir VcsJob* job = dvcs->init(dest); if (!job || !job->exec() || job->status() != VcsJob::JobSucceeded) { vcsError(i18n("Could not initialize DVCS repository"), scratchArea, dest); return false; } qCDebug(PLUGIN_APPWIZARD) << "Initializing DVCS repository:" << dest; job = dvcs->add({dest}, KDevelop::IBasicVersionControl::Recursive); if (!job || !job->exec() || job->status() != VcsJob::JobSucceeded) { vcsError(i18n("Could not add files to the DVCS repository"), scratchArea, dest); return false; } - job = dvcs->commit(QStringLiteral("initial project import from KDevelop"), {dest}, + job = dvcs->commit(info.importCommitMessage, {dest}, KDevelop::IBasicVersionControl::Recursive); if (!job || !job->exec() || job->status() != VcsJob::JobSucceeded) { vcsError(i18n("Could not import project into %1.", dvcs->name()), scratchArea, dest, job ? job->errorString() : QString()); return false; } return true; // We're good } /*! Setup version control for a new project defined by @p info. Use @p scratchArea for temporary files */ bool initializeCVCS(ICentralizedVersionControl* cvcs, const ApplicationInfo& info, QTemporaryDir& scratchArea) { Q_ASSERT(cvcs); qCDebug(PLUGIN_APPWIZARD) << "Importing" << info.sourceLocation << "to" << info.repository.repositoryServer(); VcsJob* job = cvcs->import( info.importCommitMessage, QUrl::fromLocalFile(scratchArea.path()), info.repository); if (!job || !job->exec() || job->status() != VcsJob::JobSucceeded ) { vcsError(i18n("Could not import project"), scratchArea, QUrl::fromUserInput(info.repository.repositoryServer())); return false; } qCDebug(PLUGIN_APPWIZARD) << "Checking out"; job = cvcs->createWorkingCopy( info.repository, info.location, IBasicVersionControl::Recursive); if (!job || !job->exec() || job->status() != VcsJob::JobSucceeded ) { vcsError(i18n("Could not checkout imported project"), scratchArea, QUrl::fromUserInput(info.repository.repositoryServer())); return false; } return true; // initialization phase complete } QString generateIdentifier( const QString& appname ) { QString tmp = appname; QRegExp re("[^a-zA-Z0-9_]"); return tmp.replace(re, QStringLiteral("_")); } } // end anonymous namespace QString AppWizardPlugin::createProject(const ApplicationInfo& info) { QFileInfo templateInfo(info.appTemplate); if (!templateInfo.exists()) { qWarning() << "Project app template does not exist:" << info.appTemplate; return QString(); } QString templateName = templateInfo.baseName(); QString templateArchive; const QStringList filters = {templateName + QStringLiteral(".*")}; const QStringList matchesPaths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kdevappwizard/templates/"), QStandardPaths::LocateDirectory); foreach(const QString& matchesPath, matchesPaths) { const QStringList files = QDir(matchesPath).entryList(filters); if(!files.isEmpty()) { templateArchive = matchesPath + files.first(); } } if(templateArchive.isEmpty()) { qWarning() << "Template name does not exist in the template list"; return QString(); } QUrl dest = info.location; //prepare variable substitution hash m_variables.clear(); m_variables[QStringLiteral("APPNAME")] = info.name; m_variables[QStringLiteral("APPNAMEUC")] = info.name.toUpper(); m_variables[QStringLiteral("APPNAMELC")] = info.name.toLower(); m_variables[QStringLiteral("APPNAMEID")] = generateIdentifier(info.name); m_variables[QStringLiteral("PROJECTDIR")] = dest.toLocalFile(); // backwards compatibility m_variables[QStringLiteral("dest")] = m_variables[QStringLiteral("PROJECTDIR")]; m_variables[QStringLiteral("PROJECTDIRNAME")] = dest.fileName(); m_variables[QStringLiteral("VERSIONCONTROLPLUGIN")] = info.vcsPluginName; KArchive* arch = nullptr; if( templateArchive.endsWith(QLatin1String(".zip")) ) { arch = new KZip(templateArchive); } else { arch = new KTar(templateArchive, QStringLiteral("application/x-bzip")); } if (arch->open(QIODevice::ReadOnly)) { QTemporaryDir tmpdir; QString unpackDir = tmpdir.path(); //the default value for all Centralized VCS IPlugin* plugin = core()->pluginController()->loadPlugin( info.vcsPluginName ); if( info.vcsPluginName.isEmpty() || ( plugin && plugin->extension() ) ) { if( !QFileInfo::exists( dest.toLocalFile() ) ) { QDir::root().mkpath( dest.toLocalFile() ); } unpackDir = dest.toLocalFile(); //in DVCS we unpack template directly to the project's directory } else { QUrl url = KIO::upUrl(dest); if(!QFileInfo::exists(url.toLocalFile())) { QDir::root().mkpath(url.toLocalFile()); } } if ( !unpackArchive( arch->directory(), unpackDir ) ) { QString errorMsg = i18n("Could not create new project"); vcsError(errorMsg, tmpdir, QUrl::fromLocalFile(unpackDir)); return QString(); } if( !info.vcsPluginName.isEmpty() ) { if (!plugin) { // Red Alert, serious program corruption. // This should never happen, the vcs dialog presented a list of vcs // systems and now the chosen system doesn't exist anymore?? tmpdir.remove(); return QString(); } IDistributedVersionControl* dvcs = toDVCS(plugin); ICentralizedVersionControl* cvcs = toCVCS(plugin); bool success = false; if (dvcs) { success = initializeDVCS(dvcs, info, tmpdir); } else if (cvcs) { success = initializeCVCS(cvcs, info, tmpdir); } else { if (KMessageBox::Continue == KMessageBox::warningContinueCancel(nullptr, QStringLiteral("Failed to initialize version control system, " "plugin is neither VCS nor DVCS."))) success = true; } if (!success) return QString(); } tmpdir.remove(); }else { qCDebug(PLUGIN_APPWIZARD) << "failed to open template archive"; return QString(); } QString projectFileName = QDir::cleanPath( dest.toLocalFile() + '/' + info.name + ".kdev4" ); // Loop through the new project directory and try to detect the first .kdev4 file. // If one is found this file will be used. So .kdev4 file can be stored in any subdirectory and the // project templates can be more complex. QDirIterator it(QDir::cleanPath( dest.toLocalFile()), QStringList() << QStringLiteral("*.kdev4"), QDir::NoFilter, QDirIterator::Subdirectories); if(it.hasNext() == true) { projectFileName = it.next(); } qCDebug(PLUGIN_APPWIZARD) << "Returning" << projectFileName << QFileInfo::exists( projectFileName ) ; if( ! QFileInfo::exists( projectFileName ) ) { qCDebug(PLUGIN_APPWIZARD) << "creating .kdev4 file"; KSharedConfigPtr cfg = KSharedConfig::openConfig( projectFileName, KConfig::SimpleConfig ); KConfigGroup project = cfg->group( "Project" ); project.writeEntry( "Name", info.name ); QString manager = QStringLiteral("KDevGenericManager"); QDir d( dest.toLocalFile() ); auto data = ICore::self()->pluginController()->queryExtensionPlugins(QStringLiteral("org.kdevelop.IProjectFileManager")); foreach(const KPluginMetaData& info, data) { QStringList filter = KPluginMetaData::readStringList(info.rawData(), QStringLiteral("X-KDevelop-ProjectFilesFilter")); if (!filter.isEmpty()) { if (!d.entryList(filter).isEmpty()) { manager = info.pluginId(); break; } } } project.writeEntry( "Manager", manager ); project.sync(); cfg->sync(); KConfigGroup project2 = cfg->group( "Project" ); qCDebug(PLUGIN_APPWIZARD) << "kdev4 file contents:" << project2.readEntry("Name", "") << project2.readEntry("Manager", "" ); } return projectFileName; } bool AppWizardPlugin::unpackArchive(const KArchiveDirectory *dir, const QString &dest) { qCDebug(PLUGIN_APPWIZARD) << "unpacking dir:" << dir->name() << "to" << dest; const QStringList entries = dir->entries(); qCDebug(PLUGIN_APPWIZARD) << "entries:" << entries.join(QStringLiteral(",")); //This extra tempdir is needed just for the files files have special names, //which may contain macros also files contain content with macros. So the //easiest way to extract the files from the archive and then rename them //and replace the macros is to use a tempdir and copy the file (and //replacing while copying). This also allows one to easily remove all files, //by just unlinking the tempdir QTemporaryDir tdir; bool ret = true; foreach (const QString& entry, entries) { if (entry.endsWith(QLatin1String(".kdevtemplate"))) continue; if (dir->entry(entry)->isDirectory()) { const KArchiveDirectory *file = (KArchiveDirectory *)dir->entry(entry); QString newdest = dest + '/' + KMacroExpander::expandMacros(file->name(), m_variables); if( !QFileInfo::exists( newdest ) ) { QDir::root().mkdir( newdest ); } ret |= unpackArchive(file, newdest); } else if (dir->entry(entry)->isFile()) { const KArchiveFile *file = (KArchiveFile *)dir->entry(entry); file->copyTo(tdir.path()); QString destName = dest + '/' + file->name(); if (!copyFileAndExpandMacros(QDir::cleanPath(tdir.path()+'/'+file->name()), KMacroExpander::expandMacros(destName, m_variables))) { KMessageBox::sorry(nullptr, i18n("The file %1 cannot be created.", dest)); return false; } } } tdir.remove(); return ret; } bool AppWizardPlugin::copyFileAndExpandMacros(const QString &source, const QString &dest) { qCDebug(PLUGIN_APPWIZARD) << "copy:" << source << "to" << dest; QMimeDatabase db; QMimeType mime = db.mimeTypeForFile(source); if( !mime.inherits(QStringLiteral("text/plain")) ) { KIO::CopyJob* job = KIO::copy( QUrl::fromUserInput(source), QUrl::fromUserInput(dest), KIO::HideProgressInfo ); if( !job->exec() ) { return false; } return true; } else { QFile inputFile(source); QFile outputFile(dest); if (inputFile.open(QFile::ReadOnly) && outputFile.open(QFile::WriteOnly)) { QTextStream input(&inputFile); input.setCodec(QTextCodec::codecForName("UTF-8")); QTextStream output(&outputFile); output.setCodec(QTextCodec::codecForName("UTF-8")); while(!input.atEnd()) { QString line = input.readLine(); output << KMacroExpander::expandMacros(line, m_variables) << "\n"; } #ifndef Q_OS_WIN // Preserve file mode... QT_STATBUF statBuf; QT_FSTAT(inputFile.handle(), &statBuf); // Unix only, won't work in Windows, maybe KIO::chmod could be used ::fchmod(outputFile.handle(), statBuf.st_mode); #endif return true; } else { inputFile.close(); outputFile.close(); return false; } } } KDevelop::ContextMenuExtension AppWizardPlugin::contextMenuExtension(KDevelop::Context* context) { KDevelop::ContextMenuExtension ext; if ( context->type() != KDevelop::Context::ProjectItemContext || !static_cast(context)->items().isEmpty() ) { return ext; } ext.addAction(KDevelop::ContextMenuExtension::ProjectGroup, m_newFromTemplate); return ext; } ProjectTemplatesModel* AppWizardPlugin::model() { if(!m_templatesModel) m_templatesModel = new ProjectTemplatesModel(this); return m_templatesModel; } QAbstractItemModel* AppWizardPlugin::templatesModel() { return model(); } QString AppWizardPlugin::knsConfigurationFile() const { return QStringLiteral("kdevappwizard.knsrc"); } QStringList AppWizardPlugin::supportedMimeTypes() const { QStringList types; types << QStringLiteral("application/x-desktop"); types << QStringLiteral("application/x-bzip-compressed-tar"); types << QStringLiteral("application/zip"); return types; } QIcon AppWizardPlugin::icon() const { return QIcon::fromTheme(QStringLiteral("project-development-new-template")); } QString AppWizardPlugin::name() const { return i18n("Project Templates"); } void AppWizardPlugin::loadTemplate(const QString& fileName) { model()->loadTemplateFile(fileName); } void AppWizardPlugin::reload() { model()->refresh(); } #include "appwizardplugin.moc" diff --git a/plugins/appwizard/projectvcspage.cpp b/plugins/appwizard/projectvcspage.cpp index 308359cc0..3d027b036 100644 --- a/plugins/appwizard/projectvcspage.cpp +++ b/plugins/appwizard/projectvcspage.cpp @@ -1,154 +1,157 @@ /*************************************************************************** * This file is part of KDevelop * * Copyright 2007 Andreas Pakulat * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "projectvcspage.h" #include "ui_projectvcspage.h" #include #include #include #include #include #include #include using namespace KDevelop; ProjectVcsPage::ProjectVcsPage( KDevelop::IPluginController* controller, QWidget * parent ) : AppWizardPageWidget( parent ), m_ui( new Ui::ProjectVcsPage ) { m_ui->setupUi( this ); QList vcsplugins = controller->allPluginsForExtension ( QStringLiteral("org.kdevelop.IBasicVersionControl") ); int idx = 1; m_ui->vcsImportOptions->insertWidget( 0, new QWidget(this) ); m_ui->vcsTypes->insertItem( 0, i18nc("No Version Control Support chosen", "None") ); foreach( KDevelop::IPlugin* plugin, vcsplugins ) { KDevelop::IBasicVersionControl* iface = plugin->extension(); if( iface ) { KDevelop::VcsImportMetadataWidget* widget = iface->createImportMetadataWidget( m_ui->vcsImportOptions ); if( widget ) { + // untranslated on purpose, as English might be lingua franca at most target users + // perhaps make default string configurable if people request it + widget->setMessage(QStringLiteral("Initial import")); widget->setSourceLocationEditable( false ); widget->setUseSourceDirForDestination( true ); m_ui->vcsTypes->insertItem( idx, iface->name() ); importWidgets.push_back( widget ); vcsPlugins.push_back( qMakePair( controller->pluginInfo( plugin ).pluginId(), iface->name() ) ); m_ui->vcsImportOptions->insertWidget( idx, widget ); idx++; } } } connect( m_ui->vcsTypes, static_cast(&KComboBox::activated), m_ui->vcsImportOptions, &QStackedWidget::setCurrentIndex ); connect( m_ui->vcsTypes, static_cast(&KComboBox::activated), this, &ProjectVcsPage::vcsTypeChanged ); validateData(); } void ProjectVcsPage::vcsTypeChanged( int idx ) { validateData(); int widgetidx = idx - 1; disconnect( this, static_cast(nullptr), this, &ProjectVcsPage::validateData ); if ( widgetidx < 0 || widgetidx >= importWidgets.size()) return; connect( importWidgets[widgetidx], &VcsImportMetadataWidget::changed, this, &ProjectVcsPage::validateData ); } void ProjectVcsPage::validateData() { if( shouldContinue() ) { emit valid(); } else { emit invalid(); } } ProjectVcsPage::~ProjectVcsPage( ) { delete m_ui; } void ProjectVcsPage::setSourceLocation( const QUrl& s ) { foreach(KDevelop::VcsImportMetadataWidget* widget, importWidgets) { widget->setSourceLocation( KDevelop::VcsLocation( s ) ); } } QString ProjectVcsPage::pluginName() const { int idx = m_ui->vcsTypes->currentIndex() - 1; if ( idx < 0 || idx >= vcsPlugins.size()) return QString(); // FIXME: Two return statements return vcsPlugins[idx].first; } QString ProjectVcsPage::commitMessage() const { int idx = m_ui->vcsTypes->currentIndex() - 1; if ( idx < 0 || idx >= importWidgets.size()) return QString(); return importWidgets[idx]->message(); } QUrl ProjectVcsPage::source() const { int idx = m_ui->vcsTypes->currentIndex() - 1; if ( idx < 0 || idx >= importWidgets.size()) return QUrl(); return importWidgets[idx]->source(); } KDevelop::VcsLocation ProjectVcsPage::destination() const { int idx = m_ui->vcsTypes->currentIndex() - 1; if ( idx < 0 || idx >= importWidgets.size()) return KDevelop::VcsLocation(); return importWidgets[idx]->destination(); } bool ProjectVcsPage::shouldContinue() { int idx = m_ui->vcsTypes->currentIndex() - 1; if ( idx < 0 || idx >= importWidgets.size()) return true; KDevelop::VcsImportMetadataWidget* widget = importWidgets[idx]; return widget->hasValidData(); } diff --git a/plugins/cvs/importmetadatawidget.cpp b/plugins/cvs/importmetadatawidget.cpp index 338700f10..0a65fea0a 100644 --- a/plugins/cvs/importmetadatawidget.cpp +++ b/plugins/cvs/importmetadatawidget.cpp @@ -1,76 +1,81 @@ /*************************************************************************** * Copyright 2007 Robert Gruber * * Copyright 2007 Andreas Pakulat * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "importmetadatawidget.h" #include #include ImportMetadataWidget::ImportMetadataWidget(QWidget *parent) : KDevelop::VcsImportMetadataWidget(parent), m_ui( new Ui::ImportMetadataWidget ) { m_ui->setupUi(this); m_ui->sourceLoc->setEnabled( false ); m_ui->sourceLoc->setMode( KFile::Directory ); connect( m_ui->sourceLoc, &KUrlRequester::textChanged, this, &ImportMetadataWidget::changed ); connect( m_ui->sourceLoc, &KUrlRequester::urlSelected, this, &ImportMetadataWidget::changed ); connect( m_ui->comment, &KTextEdit::textChanged, this, &ImportMetadataWidget::changed ); connect( m_ui->module, &QLineEdit::textEdited, this, &ImportMetadataWidget::changed ); connect( m_ui->releaseTag, &QLineEdit::textEdited, this, &ImportMetadataWidget::changed ); connect( m_ui->repository, &QLineEdit::textEdited, this, &ImportMetadataWidget::changed ); connect( m_ui->vendorTag, &QLineEdit::textEdited, this, &ImportMetadataWidget::changed ); } ImportMetadataWidget::~ImportMetadataWidget() { delete m_ui; } QUrl ImportMetadataWidget::source() const { return m_ui->sourceLoc->url() ; } KDevelop::VcsLocation ImportMetadataWidget::destination() const { KDevelop::VcsLocation destloc; destloc.setRepositoryServer(m_ui->repository->text() ); destloc.setRepositoryModule(m_ui->module->text()); destloc.setRepositoryTag(m_ui->vendorTag->text()); destloc.setUserData(m_ui->releaseTag->text()); return destloc; } QString ImportMetadataWidget::message( ) const { return m_ui->comment->toPlainText(); } void ImportMetadataWidget::setSourceLocation( const KDevelop::VcsLocation& url ) { m_ui->sourceLoc->setUrl( url.localUrl() ); } void ImportMetadataWidget::setSourceLocationEditable( bool enable ) { m_ui->sourceLoc->setEnabled( enable ); } +void ImportMetadataWidget::setMessage(const QString& message) +{ + m_ui->comment->setText(message); +} + bool ImportMetadataWidget::hasValidData() const { return !m_ui->comment->toPlainText().isEmpty() && !m_ui->sourceLoc->text().isEmpty() && !m_ui->module->text().isEmpty() && !m_ui->repository->text().isEmpty(); } diff --git a/plugins/cvs/importmetadatawidget.h b/plugins/cvs/importmetadatawidget.h index fbfc4c3d0..80ca6136c 100644 --- a/plugins/cvs/importmetadatawidget.h +++ b/plugins/cvs/importmetadatawidget.h @@ -1,49 +1,50 @@ /*************************************************************************** * Copyright 2007 Robert Gruber * * Copyright 2007 Andreas Pakulat * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef KDEVPLATFORM_PLUGIN_IMPORTMETADATAWIDGET_H #define KDEVPLATFORM_PLUGIN_IMPORTMETADATAWIDGET_H #include #include "ui_importmetadatawidget.h" class CvsPlugin; namespace KDevelop { class VcsLocation; } /** * Asks the user for all options needed to import an existing directory into * a CVS repository * @author Robert Gruber */ class ImportMetadataWidget : public KDevelop::VcsImportMetadataWidget, private Ui::ImportMetadataWidget { Q_OBJECT public: explicit ImportMetadataWidget(QWidget* parent=nullptr); ~ImportMetadataWidget() override; QUrl source() const override; KDevelop::VcsLocation destination() const override; QString message() const override; void setSourceLocation( const KDevelop::VcsLocation& ) override; void setSourceLocationEditable( bool ) override; + void setMessage(const QString& message) override; bool hasValidData() const override; private: Ui::ImportMetadataWidget* m_ui; }; #endif diff --git a/plugins/subversion/svnimportmetadatawidget.cpp b/plugins/subversion/svnimportmetadatawidget.cpp index 63afab5c2..d9ed7e1a3 100644 --- a/plugins/subversion/svnimportmetadatawidget.cpp +++ b/plugins/subversion/svnimportmetadatawidget.cpp @@ -1,75 +1,80 @@ /*************************************************************************** * Copyright 2007 Dukju Ahn * * Copyright 2007 Andreas Pakulat * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "svnimportmetadatawidget.h" #include "ui_importmetadatawidget.h" #include SvnImportMetadataWidget::SvnImportMetadataWidget( QWidget *parent ) : VcsImportMetadataWidget( parent ), m_ui(new Ui::SvnImportMetadataWidget) , useSourceDirForDestination( false ) { m_ui->setupUi( this ); m_ui->srcEdit->setUrl( QUrl() ); connect( m_ui->srcEdit, SIGNAL(textChanged(QString)), SIGNAL(changed()) ); connect( m_ui->srcEdit, SIGNAL(urlSelected(QUrl)), SIGNAL(changed()) ); connect( m_ui->dest, SIGNAL(textChanged(QString)), this, SIGNAL(changed()) ); connect( m_ui->message, SIGNAL(textChanged()), this, SIGNAL(changed()) ); } SvnImportMetadataWidget::~SvnImportMetadataWidget() { delete m_ui; } void SvnImportMetadataWidget::setSourceLocation( const KDevelop::VcsLocation& importdir ) { m_ui->srcEdit->setUrl( importdir.localUrl() ); } QUrl SvnImportMetadataWidget::source() const { return m_ui->srcEdit->url(); } KDevelop::VcsLocation SvnImportMetadataWidget::destination() const { KDevelop::VcsLocation destloc; QString url = m_ui->dest->text(); if( useSourceDirForDestination ) { url += '/' + m_ui->srcEdit->url().fileName(); } destloc.setRepositoryServer(url); return destloc; } void SvnImportMetadataWidget::setUseSourceDirForDestination( bool b ) { useSourceDirForDestination = b; } void SvnImportMetadataWidget::setSourceLocationEditable( bool enable ) { m_ui->srcEdit->setEnabled( enable ); } +void SvnImportMetadataWidget::setMessage(const QString& message) +{ + m_ui->message->setText(message); +} + QString SvnImportMetadataWidget::message() const { return m_ui->message->toPlainText(); } bool SvnImportMetadataWidget::hasValidData() const { return !m_ui->message->toPlainText().isEmpty() && !m_ui->srcEdit->text().isEmpty(); } diff --git a/plugins/subversion/svnimportmetadatawidget.h b/plugins/subversion/svnimportmetadatawidget.h index 5c53c595a..5d3eaa9fe 100644 --- a/plugins/subversion/svnimportmetadatawidget.h +++ b/plugins/subversion/svnimportmetadatawidget.h @@ -1,41 +1,42 @@ /*************************************************************************** * Copyright 2007 Dukju Ahn * * Copyright 2007 Andreas Pakulat * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef KDEVPLATFORM_PLUGIN_SVNIMPORTMETADATAWIDGET_H #define KDEVPLATFORM_PLUGIN_SVNIMPORTMETADATAWIDGET_H #include namespace Ui { class SvnImportMetadataWidget; } class SvnImportMetadataWidget : public KDevelop::VcsImportMetadataWidget { Q_OBJECT public: explicit SvnImportMetadataWidget( QWidget *parent ); ~SvnImportMetadataWidget() override; void setSourceLocation( const KDevelop::VcsLocation& ) override; void setSourceLocationEditable( bool ) override; QUrl source() const override; KDevelop::VcsLocation destination() const override; QString message() const override; void setUseSourceDirForDestination( bool ) override; + void setMessage(const QString& message) override; bool hasValidData() const override; private: Ui::SvnImportMetadataWidget *m_ui; bool useSourceDirForDestination; }; #endif diff --git a/vcs/dvcs/ui/dvcsimportmetadatawidget.cpp b/vcs/dvcs/ui/dvcsimportmetadatawidget.cpp index f5d5194bd..100e5d6c3 100644 --- a/vcs/dvcs/ui/dvcsimportmetadatawidget.cpp +++ b/vcs/dvcs/ui/dvcsimportmetadatawidget.cpp @@ -1,98 +1,106 @@ /*************************************************************************** * Copyright 2007 Robert Gruber * * Copyright 2007 Andreas Pakulat * * * * Adapted for Git * * Copyright 2008 Evgeniy Ivanov * * * * Pimpl-ed and exported * * Copyright 2014 Maciej Poleski * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License or (at your option) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * ***************************************************************************/ #include "dvcsimportmetadatawidget.h" #include #include "ui_dvcsimportmetadatawidget.h" class DvcsImportMetadataWidgetPrivate { friend class DvcsImportMetadataWidget; explicit DvcsImportMetadataWidgetPrivate(Ui::DvcsImportMetadataWidget* ui) : m_ui(ui) {} ~DvcsImportMetadataWidgetPrivate() { delete m_ui; } Ui::DvcsImportMetadataWidget* m_ui; }; DvcsImportMetadataWidget::DvcsImportMetadataWidget(QWidget *parent) : KDevelop::VcsImportMetadataWidget(parent), d_ptr(new DvcsImportMetadataWidgetPrivate(new Ui::DvcsImportMetadataWidget)) { Q_D(DvcsImportMetadataWidget); d->m_ui->setupUi(this); d->m_ui->sourceLoc->setEnabled( false ); d->m_ui->sourceLoc->setMode( KFile::Directory ); connect( d->m_ui->sourceLoc, &KUrlRequester::textChanged, this, &DvcsImportMetadataWidget::changed ); connect( d->m_ui->sourceLoc, &KUrlRequester::urlSelected, this, &DvcsImportMetadataWidget::changed ); + connect(d->m_ui->message, &QTextEdit::textChanged, this, &DvcsImportMetadataWidget::changed); } DvcsImportMetadataWidget::~DvcsImportMetadataWidget() { delete d_ptr; } QUrl DvcsImportMetadataWidget::source() const { Q_D(const DvcsImportMetadataWidget); return d->m_ui->sourceLoc->url(); } KDevelop::VcsLocation DvcsImportMetadataWidget::destination() const { // Used for compatibility with import Q_D(const DvcsImportMetadataWidget); KDevelop::VcsLocation dest; dest.setRepositoryServer(d->m_ui->sourceLoc->url().url()); return dest; } QString DvcsImportMetadataWidget::message( ) const { - return QString(); + Q_D(const DvcsImportMetadataWidget); + return d->m_ui->message->toPlainText(); } void DvcsImportMetadataWidget::setSourceLocation( const KDevelop::VcsLocation& url ) { Q_D(const DvcsImportMetadataWidget); d->m_ui->sourceLoc->setUrl( url.localUrl() ); } void DvcsImportMetadataWidget::setSourceLocationEditable( bool enable ) { Q_D(const DvcsImportMetadataWidget); d->m_ui->sourceLoc->setEnabled( enable ); } +void DvcsImportMetadataWidget::setMessage(const QString& message) +{ + Q_D(DvcsImportMetadataWidget); + d->m_ui->message->setText(message); +} + bool DvcsImportMetadataWidget::hasValidData() const { Q_D(const DvcsImportMetadataWidget); - return !d->m_ui->sourceLoc->text().isEmpty(); + return !d->m_ui->message->toPlainText().isEmpty() && !d->m_ui->sourceLoc->text().isEmpty(); } diff --git a/vcs/dvcs/ui/dvcsimportmetadatawidget.h b/vcs/dvcs/ui/dvcsimportmetadatawidget.h index f48f0943c..ece608f00 100644 --- a/vcs/dvcs/ui/dvcsimportmetadatawidget.h +++ b/vcs/dvcs/ui/dvcsimportmetadatawidget.h @@ -1,64 +1,65 @@ /*************************************************************************** * Copyright 2007 Robert Gruber * * Copyright 2007 Andreas Pakulat * * * * Adapted for Git * * Copyright 2008 Evgeniy Ivanov * * * * Pimpl-ed and exported * * Copyright 2014 Maciej Poleski * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License or (at your option) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * ***************************************************************************/ #ifndef KDEVPLATFORM_DVCSIMPORTMETADATAWIDGET_H #define KDEVPLATFORM_DVCSIMPORTMETADATAWIDGET_H #include namespace Ui { class DvcsImportMetadataWidget; } class DvcsImportMetadataWidgetPrivate; /** * Asks the user for all options needed to import an existing directory into * a Git repository * @author Robert Gruber */ class KDEVPLATFORMVCS_EXPORT DvcsImportMetadataWidget : public KDevelop::VcsImportMetadataWidget { Q_OBJECT Q_DECLARE_PRIVATE(DvcsImportMetadataWidget) public: explicit DvcsImportMetadataWidget(QWidget* parent=nullptr); ~DvcsImportMetadataWidget() override; QUrl source() const override; KDevelop::VcsLocation destination() const override; QString message() const override; //Is not used, it returns an empty string void setSourceLocation( const KDevelop::VcsLocation& ) override; void setSourceLocationEditable( bool ) override; + void setMessage(const QString& message) override; bool hasValidData() const override; private: DvcsImportMetadataWidgetPrivate *const d_ptr; }; #endif diff --git a/vcs/dvcs/ui/dvcsimportmetadatawidget.ui b/vcs/dvcs/ui/dvcsimportmetadatawidget.ui index e5f122c47..608cc57e0 100644 --- a/vcs/dvcs/ui/dvcsimportmetadatawidget.ui +++ b/vcs/dvcs/ui/dvcsimportmetadatawidget.ui @@ -1,38 +1,63 @@ DvcsImportMetadataWidget 0 0 581 37 Import - + + + 0 + Source Directory: + + + + Commit Message: + + + + + + + + 0 + 1 + + + + KUrlRequester QWidget
kurlrequester.h
1
+ + KTextEdit + QTextEdit +
ktextedit.h
+
diff --git a/vcs/widgets/vcsimportmetadatawidget.h b/vcs/widgets/vcsimportmetadatawidget.h index 4925469c1..b049a6d4c 100644 --- a/vcs/widgets/vcsimportmetadatawidget.h +++ b/vcs/widgets/vcsimportmetadatawidget.h @@ -1,67 +1,68 @@ /*************************************************************************** * This file is part of KDevelop * * Copyright 2007 Andreas Pakulat * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef KDEVPLATFORM_VCSIMPORTMETADATAWIDGET_H #define KDEVPLATFORM_VCSIMPORTMETADATAWIDGET_H #include #include #include class QUrl; namespace KDevelop { class VcsLocation; class KDEVPLATFORMVCS_EXPORT VcsImportMetadataWidget : public QWidget { Q_OBJECT public: explicit VcsImportMetadataWidget( QWidget* parent ); ~VcsImportMetadataWidget() override; virtual QUrl source() const = 0; virtual VcsLocation destination() const = 0; virtual QString message() const = 0; /** * Check whether the given data is valid. * @returns true if all data in the widget is valid */ virtual bool hasValidData() const = 0; /** * Select whether the widget should re-use the last part of the source location * for the destination. The default implementation simply ignores this setting. */ virtual void setUseSourceDirForDestination( bool ) {} Q_SIGNALS: void changed(); public Q_SLOTS: virtual void setSourceLocation( const VcsLocation& ) = 0; virtual void setSourceLocationEditable( bool ) = 0; + virtual void setMessage(const QString& message) = 0; }; } #endif //kate: space-indent on; indent-width 4; replace-tabs on; auto-insert-doxygen on; indent-mode cstyle;