From b488deeb0cb6945b0de4a71fd7c389b4fd5938e0 Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Date: Mon, 20 Jul 2009 09:23:00 +0200
Subject: [PATCH] CVS: Add checkout wizard.

---
 src/plugins/cvs/checkoutwizard.cpp            | 89 +++++++++++++++++++
 src/plugins/cvs/checkoutwizard.h              | 58 ++++++++++++
 src/plugins/cvs/checkoutwizardpage.cpp        | 44 +++++++++
 src/plugins/cvs/checkoutwizardpage.h          | 46 ++++++++++
 src/plugins/cvs/cvs.pro                       |  8 +-
 src/plugins/cvs/cvsplugin.cpp                 |  3 +
 src/plugins/cvs/cvssettings.h                 |  1 -
 src/plugins/git/clonewizard.cpp               |  2 +-
 .../vcsbase/basecheckoutwizardpage.cpp        | 13 ++-
 src/plugins/vcsbase/basecheckoutwizardpage.h  |  3 +-
 src/plugins/vcsbase/checkoutjobs.cpp          |  3 +-
 11 files changed, 262 insertions(+), 8 deletions(-)
 create mode 100644 src/plugins/cvs/checkoutwizard.cpp
 create mode 100644 src/plugins/cvs/checkoutwizard.h
 create mode 100644 src/plugins/cvs/checkoutwizardpage.cpp
 create mode 100644 src/plugins/cvs/checkoutwizardpage.h

diff --git a/src/plugins/cvs/checkoutwizard.cpp b/src/plugins/cvs/checkoutwizard.cpp
new file mode 100644
index 00000000000..7e7eb026b24
--- /dev/null
+++ b/src/plugins/cvs/checkoutwizard.cpp
@@ -0,0 +1,89 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+**
+**************************************************************************/
+
+#include "checkoutwizard.h"
+#include "checkoutwizardpage.h"
+#include "cvsplugin.h"
+
+#include <vcsbase/checkoutjobs.h>
+#include <utils/qtcassert.h>
+
+#include <QtGui/QIcon>
+
+namespace CVS {
+namespace Internal {
+
+CheckoutWizard::CheckoutWizard(QObject *parent) :
+        VCSBase::BaseCheckoutWizard(parent)
+{
+}
+
+QIcon CheckoutWizard::icon() const
+{
+    return QIcon();
+}
+
+QString CheckoutWizard::description() const
+{
+    return tr("Check-out a project from a CVS repository.");
+}
+
+QString CheckoutWizard::name() const
+{
+    return tr("CVS Checkout");
+}
+
+QWizardPage *CheckoutWizard::createParameterPage(const QString &path)
+{
+    CheckoutWizardPage *cwp = new CheckoutWizardPage;
+    cwp->setPath(path);
+    return cwp;
+}
+
+QSharedPointer<VCSBase::AbstractCheckoutJob> CheckoutWizard::createJob(const QWizardPage *parameterPage,
+                                                                    QString *checkoutPath)
+{
+    // Collect parameters for the checkout command.
+    // CVS does not allow for checking out into a different directory.
+    const CheckoutWizardPage *cwp = qobject_cast<const CheckoutWizardPage *>(parameterPage);
+    QTC_ASSERT(cwp, return QSharedPointer<VCSBase::AbstractCheckoutJob>())
+    const CVSSettings settings = CVSPlugin::cvsPluginInstance()->settings();
+    const QString binary = settings.cvsCommand;
+    QStringList args;
+    const QString repository = cwp->repository();
+    args << QLatin1String("checkout") << repository;
+    const QString workingDirectory = cwp->path();
+    *checkoutPath = workingDirectory + QLatin1Char('/') + repository;
+    VCSBase::AbstractCheckoutJob *job = new VCSBase::ProcessCheckoutJob(binary, settings.addOptions(args),
+                                                                        workingDirectory);
+    return QSharedPointer<VCSBase::AbstractCheckoutJob>(job);
+}
+
+} // namespace Internal
+} // namespace CVS
diff --git a/src/plugins/cvs/checkoutwizard.h b/src/plugins/cvs/checkoutwizard.h
new file mode 100644
index 00000000000..53c7f86a961
--- /dev/null
+++ b/src/plugins/cvs/checkoutwizard.h
@@ -0,0 +1,58 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+**
+**************************************************************************/
+
+#ifndef CHECKOUTWIZARD_H
+#define CHECKOUTWIZARD_H
+
+#include <vcsbase/basecheckoutwizard.h>
+
+namespace CVS {
+namespace Internal {
+
+class CheckoutWizard : public VCSBase::BaseCheckoutWizard
+{
+public:
+    explicit CheckoutWizard(QObject *parent = 0);
+
+    // IWizard
+    virtual QIcon icon() const;
+    virtual QString description() const;
+    virtual QString name() const;
+
+protected:
+    // BaseCheckoutWizard
+    virtual QWizardPage *createParameterPage(const QString &path);
+    virtual QSharedPointer<VCSBase::AbstractCheckoutJob> createJob(const QWizardPage *parameterPage,
+                                                                   QString *checkoutPath);
+};
+
+} // namespace Internal
+} // namespace CVS
+
+#endif // CHECKOUTWIZARD_H
diff --git a/src/plugins/cvs/checkoutwizardpage.cpp b/src/plugins/cvs/checkoutwizardpage.cpp
new file mode 100644
index 00000000000..70c97a721aa
--- /dev/null
+++ b/src/plugins/cvs/checkoutwizardpage.cpp
@@ -0,0 +1,44 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+**
+**************************************************************************/
+
+#include "checkoutwizardpage.h"
+
+namespace CVS {
+namespace Internal {
+
+CheckoutWizardPage::CheckoutWizardPage(QWidget *parent) :
+    VCSBase::BaseCheckoutWizardPage(parent)
+{
+    setSubTitle(tr("Specify repository and path."));
+    setRepositoryLabel(tr("Repository:"));
+    setDirectoryVisible(false);
+}
+
+} // namespace Internal
+} // namespace CVS
diff --git a/src/plugins/cvs/checkoutwizardpage.h b/src/plugins/cvs/checkoutwizardpage.h
new file mode 100644
index 00000000000..cfab3a30403
--- /dev/null
+++ b/src/plugins/cvs/checkoutwizardpage.h
@@ -0,0 +1,46 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+**
+**************************************************************************/
+
+#ifndef CHECKOUTWIZARDPAGE_H
+#define CHECKOUTWIZARDPAGE_H
+
+#include <vcsbase/basecheckoutwizardpage.h>
+
+namespace CVS {
+namespace Internal {
+
+class CheckoutWizardPage : public VCSBase::BaseCheckoutWizardPage {
+    Q_OBJECT
+public:
+    CheckoutWizardPage(QWidget *parent = 0);
+};
+
+} // namespace Internal
+} // namespace CVS
+#endif // CHECKOUTWIZARDPAGE_H
diff --git a/src/plugins/cvs/cvs.pro b/src/plugins/cvs/cvs.pro
index 86244a20aac..a0d6f04602c 100644
--- a/src/plugins/cvs/cvs.pro
+++ b/src/plugins/cvs/cvs.pro
@@ -17,7 +17,9 @@ HEADERS += annotationhighlighter.h \
     cvssubmiteditor.h \
     cvssettings.h \
     cvsutils.h \
-    cvsconstants.h
+    cvsconstants.h \
+    checkoutwizard.h  \
+    checkoutwizardpage.h
 
 SOURCES += annotationhighlighter.cpp \
     cvsplugin.cpp \
@@ -27,7 +29,9 @@ SOURCES += annotationhighlighter.cpp \
     cvseditor.cpp \
     cvssubmiteditor.cpp \
     cvssettings.cpp \
-    cvsutils.cpp
+    cvsutils.cpp \
+    checkoutwizard.cpp \
+    checkoutwizardpage.cpp
 
 FORMS += settingspage.ui
 
diff --git a/src/plugins/cvs/cvsplugin.cpp b/src/plugins/cvs/cvsplugin.cpp
index 85b08656c86..83d10fe004f 100644
--- a/src/plugins/cvs/cvsplugin.cpp
+++ b/src/plugins/cvs/cvsplugin.cpp
@@ -34,6 +34,7 @@
 #include "cvssubmiteditor.h"
 #include "cvsconstants.h"
 #include "cvscontrol.h"
+#include "checkoutwizard.h"
 
 #include <vcsbase/basevcseditorfactory.h>
 #include <vcsbase/vcsbaseeditor.h>
@@ -241,6 +242,8 @@ bool CVSPlugin::initialize(const QStringList &arguments, QString *errorMessage)
     m_cvsOutputWindow = new CVSOutputWindow(this);
     addAutoReleasedObject(m_cvsOutputWindow);
 
+    addAutoReleasedObject(new CheckoutWizard);
+
     //register actions
     Core::ActionManager *ami = core->actionManager();
     Core::ActionContainer *toolsContainer = ami->actionContainer(M_TOOLS);
diff --git a/src/plugins/cvs/cvssettings.h b/src/plugins/cvs/cvssettings.h
index ff37307f2bb..b6822674ffa 100644
--- a/src/plugins/cvs/cvssettings.h
+++ b/src/plugins/cvs/cvssettings.h
@@ -39,7 +39,6 @@ QT_END_NAMESPACE
 namespace CVS {
 namespace Internal {
 
-// Todo: Add user name and password?
 struct CVSSettings
 {
     CVSSettings();
diff --git a/src/plugins/git/clonewizard.cpp b/src/plugins/git/clonewizard.cpp
index 252534ec4be..80d3112504d 100644
--- a/src/plugins/git/clonewizard.cpp
+++ b/src/plugins/git/clonewizard.cpp
@@ -57,7 +57,7 @@ QString CloneWizard::description() const
 
 QString CloneWizard::name() const
 {
-    return tr("Git Checkout");
+    return tr("Git Repository Clone");
 }
 
 QWizardPage *CloneWizard::createParameterPage(const QString &path)
diff --git a/src/plugins/vcsbase/basecheckoutwizardpage.cpp b/src/plugins/vcsbase/basecheckoutwizardpage.cpp
index 565da4052ea..f9fdb1a6977 100644
--- a/src/plugins/vcsbase/basecheckoutwizardpage.cpp
+++ b/src/plugins/vcsbase/basecheckoutwizardpage.cpp
@@ -83,6 +83,12 @@ void BaseCheckoutWizardPage::setDirectory(const QString &dir)
     d->ui.checkoutDirectoryLineEdit->setText(dir);
 }
 
+void BaseCheckoutWizardPage::setDirectoryVisible(bool v)
+{
+    d->ui.checkoutDirectoryLabel->setVisible(v);
+    d->ui.checkoutDirectoryLineEdit->setVisible(v);
+}
+
 QString BaseCheckoutWizardPage::repository() const
 {
     return d->ui.repositoryLineEdit->text().trimmed();
@@ -95,13 +101,16 @@ void BaseCheckoutWizardPage::setRepository(const QString &r)
 
 void BaseCheckoutWizardPage::slotRepositoryChanged(const QString &repo)
 {
-    /* Try to figure out a good directory name from something like:
-     * "svn://<server>/path1/project" -> project */
     if (d->m_directoryEdited)
         return;
     d->ui.checkoutDirectoryLineEdit->setText(directoryFromRepository(repo));
 }
 
+QString BaseCheckoutWizardPage::directoryFromRepository(const QString &r) const
+{
+    return r;
+}
+
 void BaseCheckoutWizardPage::slotDirectoryEdited()
 {
     d->m_directoryEdited = true;
diff --git a/src/plugins/vcsbase/basecheckoutwizardpage.h b/src/plugins/vcsbase/basecheckoutwizardpage.h
index 2130c1944b0..adf5d60dccc 100644
--- a/src/plugins/vcsbase/basecheckoutwizardpage.h
+++ b/src/plugins/vcsbase/basecheckoutwizardpage.h
@@ -68,10 +68,11 @@ protected:
     void changeEvent(QEvent *e);
 
     void setRepositoryLabel(const QString &l);
+    void setDirectoryVisible(bool v);
 
     /* Determine a checkout directory name from
      * repository URL, that is, "protocol:/project" -> "project". */
-    virtual QString directoryFromRepository(const QString &r) const = 0;
+    virtual QString directoryFromRepository(const QString &r) const;
 
 private slots:
     void slotRepositoryChanged(const QString &url);
diff --git a/src/plugins/vcsbase/checkoutjobs.cpp b/src/plugins/vcsbase/checkoutjobs.cpp
index 1c19bfe7b3d..b3fe91e95f2 100644
--- a/src/plugins/vcsbase/checkoutjobs.cpp
+++ b/src/plugins/vcsbase/checkoutjobs.cpp
@@ -87,7 +87,8 @@ ProcessCheckoutJob::~ProcessCheckoutJob()
 
 void ProcessCheckoutJob::slotOutput()
 {
-    const QString s = QString::fromLocal8Bit(d->process.readAllStandardOutput());
+    const QByteArray data = d->process.readAllStandardOutput();
+    const QString s = QString::fromLocal8Bit(data, data.endsWith('\n') ? data.size() - 1: data.size());
     if (debug)
         qDebug() << s;
     emit output(s);
-- 
GitLab