1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2010 Hugues Delorme
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "bazaarcontrol.h"
35 #include "bazaarclient.h"
37 #include <QtCore/QFileInfo>
38 #include <QtCore/QVariant>
39 #include <QtCore/QStringList>
40 #include <QtCore/QDir>
42 using namespace Bazaar::Internal;
44 BazaarControl::BazaarControl(BazaarClient *client)
45 : m_bazaarClient(client)
49 QString BazaarControl::displayName() const
54 bool BazaarControl::managesDirectory(const QString &directory, QString *topLevel) const
56 QFileInfo dir(directory);
57 const QString topLevelFound = m_bazaarClient->findTopLevelForFile(dir);
59 *topLevel = topLevelFound;
60 return !topLevelFound.isEmpty();
63 bool BazaarControl::supportsOperation(Operation operation) const
65 bool supported = true;
67 case Core::IVersionControl::AddOperation:
68 case Core::IVersionControl::DeleteOperation:
69 case Core::IVersionControl::MoveOperation:
70 case Core::IVersionControl::CreateRepositoryOperation:
71 case Core::IVersionControl::AnnotateOperation:
72 case Core::IVersionControl::GetRepositoryRootOperation:
74 case Core::IVersionControl::CheckoutOperation:
75 case Core::IVersionControl::OpenOperation:
76 case Core::IVersionControl::SnapshotOperations:
83 bool BazaarControl::vcsOpen(const QString &filename)
89 bool BazaarControl::vcsAdd(const QString &filename)
91 const QFileInfo fi(filename);
92 return m_bazaarClient->synchronousAdd(fi.absolutePath(), fi.fileName());
95 bool BazaarControl::vcsDelete(const QString &filename)
97 const QFileInfo fi(filename);
98 return m_bazaarClient->synchronousRemove(fi.absolutePath(), fi.fileName());
101 bool BazaarControl::vcsMove(const QString &from, const QString &to)
103 const QFileInfo fromInfo(from);
104 const QFileInfo toInfo(to);
105 return m_bazaarClient->synchronousMove(fromInfo.absolutePath(),
106 fromInfo.absoluteFilePath(),
107 toInfo.absoluteFilePath());
110 bool BazaarControl::vcsCreateRepository(const QString &directory)
112 return m_bazaarClient->synchronousCreateRepository(directory);
115 QString BazaarControl::vcsCreateSnapshot(const QString &)
120 QStringList BazaarControl::vcsSnapshots(const QString &)
122 return QStringList();
125 bool BazaarControl::vcsRestoreSnapshot(const QString &, const QString &)
130 bool BazaarControl::vcsRemoveSnapshot(const QString &, const QString &)
135 bool BazaarControl::vcsAnnotate(const QString &file, int line)
137 const QFileInfo fi(file);
138 m_bazaarClient->annotate(fi.absolutePath(), fi.fileName(), QString(), line);
142 bool BazaarControl::vcsCheckout(const QString &directory, const QByteArray &url)
149 QString BazaarControl::vcsGetRepositoryURL(const QString &directory)
151 const QString repositoryRoot = m_bazaarClient->findTopLevelForFile(directory);
152 const BranchInfo branchInfo = m_bazaarClient->synchronousBranchQuery(repositoryRoot);
153 return branchInfo.isBoundToBranch ? branchInfo.branchLocation : QString();
156 void BazaarControl::changed(const QVariant &v)
159 case QVariant::String:
160 emit repositoryChanged(v.toString());
162 case QVariant::StringList:
163 emit filesChanged(v.toStringList());