clonewizard.cpp 4.57 KB
Newer Older
cerf's avatar
cerf committed
1 2
/**************************************************************************
**
3
** Copyright (c) 2014 Hugues Delorme
4
** Contact: http://www.qt-project.org/legal
cerf's avatar
cerf committed
5
**
6
** This file is part of Qt Creator.
cerf's avatar
cerf committed
7
**
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
cerf's avatar
cerf committed
15 16
**
** GNU Lesser General Public License Usage
17 18 19 20 21 22
** 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.
cerf's avatar
cerf committed
23
**
hjk's avatar
hjk committed
24
** In addition, as a special exception, Digia gives you certain additional
25
** rights.  These rights are described in the Digia Qt LGPL Exception
cerf's avatar
cerf committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
28
****************************************************************************/
cerf's avatar
cerf committed
29 30 31 32 33 34 35 36

#include "clonewizard.h"
#include "clonewizardpage.h"
#include "cloneoptionspanel.h"
#include "bazaarplugin.h"
#include "bazaarclient.h"
#include "bazaarsettings.h"

37
#include <coreplugin/iversioncontrol.h>
38
#include <vcsbase/command.h>
cerf's avatar
cerf committed
39
#include <vcsbase/vcsbaseconstants.h>
40
#include <vcsbase/vcsconfigurationpage.h>
cerf's avatar
cerf committed
41

42
#include <QDebug>
cerf's avatar
cerf committed
43 44 45

using namespace Bazaar::Internal;

46
CloneWizardFactory::CloneWizardFactory()
cerf's avatar
cerf committed
47
{
hjk's avatar
hjk committed
48
    setId(QLatin1String(VcsBase::Constants::VCS_ID_BAZAAR));
hjk's avatar
hjk committed
49 50 51
    setIcon(QIcon(QLatin1String(":/bazaar/images/bazaar.png")));
    setDescription(tr("Clones a Bazaar branch and tries to load the contained project."));
    setDisplayName(tr("Bazaar Clone (Or Branch)"));
cerf's avatar
cerf committed
52 53
}

54
VcsBase::BaseCheckoutWizard *CloneWizardFactory::create(const Utils::FileName &path, QWidget *parent) const
55
{
56
    return new CloneWizard(path, parent);
cerf's avatar
cerf committed
57 58
}

59 60 61 62
// --------------------------------------------------------------------
// CloneWizard:
// --------------------------------------------------------------------

63
CloneWizard::CloneWizard(const Utils::FileName &path, QWidget *parent) :
64 65 66 67 68 69 70 71 72
    VcsBase::BaseCheckoutWizard(path, parent)
{
    setTitle(tr("Cloning"));
    setStartedStatus(tr("Cloning started..."));

    const Core::IVersionControl *vc = BazaarPlugin::instance()->versionControl();
    if (!vc->isConfigured())
        addPage(new VcsBase::VcsConfigurationPage(vc));
    CloneWizardPage *page = new CloneWizardPage;
73
    page->setPath(path.toString());
74 75 76
    addPage(page);
}

77
VcsBase::Command *CloneWizard::createCommand(Utils::FileName *checkoutDir)
cerf's avatar
cerf committed
78
{
79 80 81
    const CloneWizardPage *cwp = 0;
    foreach (int pageId, pageIds()) {
        if ((cwp = qobject_cast<const CloneWizardPage *>(page(pageId))))
82 83
            break;
    }
cerf's avatar
cerf committed
84

85
    if (!cwp)
86
        return 0;
cerf's avatar
cerf committed
87 88

    const BazaarSettings &settings = BazaarPlugin::instance()->settings();
89
    *checkoutDir = Utils::FileName::fromString(cwp->path() + QLatin1Char('/') + cwp->directory());
cerf's avatar
cerf committed
90

91
    const CloneOptionsPanel *panel = cwp->cloneOptionsPanel();
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    QStringList extraOptions;
    if (panel->isUseExistingDirectoryOptionEnabled())
        extraOptions += QLatin1String("--use-existing-dir");
    if (panel->isStackedOptionEnabled())
        extraOptions += QLatin1String("--stacked");
    if (panel->isStandAloneOptionEnabled())
        extraOptions += QLatin1String("--standalone");
    if (panel->isBindOptionEnabled())
        extraOptions += QLatin1String("--bind");
    if (panel->isSwitchOptionEnabled())
        extraOptions += QLatin1String("--switch");
    if (panel->isHardLinkOptionEnabled())
        extraOptions += QLatin1String("--hardlink");
    if (panel->isNoTreeOptionEnabled())
        extraOptions += QLatin1String("--no-tree");
    if (!panel->revision().isEmpty())
        extraOptions << QLatin1String("-r") << panel->revision();
cerf's avatar
cerf committed
109
    const BazaarClient *client = BazaarPlugin::instance()->client();
110
    QStringList args;
cerf's avatar
cerf committed
111
    args << client->vcsCommandString(BazaarClient::CloneCommand)
112
         << extraOptions << cwp->repository() << cwp->directory();
cerf's avatar
cerf committed
113

114
    VcsBase::Command *command = new VcsBase::Command(settings.binaryPath(), cwp->path(),
115 116 117
                                                     client->processEnvironment());
    command->addJob(args, -1);
    return command;
cerf's avatar
cerf committed
118
}