1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2009 Brian McGillion
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "mercurialcontrol.h"
34 #include "mercurialclient.h"
36 #include <QtCore/QFileInfo>
37 #include <QtCore/QVariant>
38 #include <QtCore/QStringList>
39 #include <QtCore/QDir>
41 using namespace Mercurial::Internal;
43 MercurialControl::MercurialControl(MercurialClient *client)
44 : mercurialClient(client)
48 QString MercurialControl::displayName() const
50 return tr("Mercurial");
53 bool MercurialControl::managesDirectory(const QString &directory, QString *topLevel) const
55 QFileInfo dir(directory);
56 const QString topLevelFound = mercurialClient->findTopLevelForFile(dir);
58 *topLevel = topLevelFound;
59 return !topLevelFound.isEmpty();
62 bool MercurialControl::supportsOperation(Operation operation) const
64 bool supported = true;
66 case Core::IVersionControl::AddOperation:
67 case Core::IVersionControl::DeleteOperation:
68 case Core::IVersionControl::MoveOperation:
69 case Core::IVersionControl::CreateRepositoryOperation:
70 case Core::IVersionControl::AnnotateOperation:
71 case Core::IVersionControl::CheckoutOperation:
72 case Core::IVersionControl::GetRepositoryRootOperation:
74 case Core::IVersionControl::OpenOperation:
75 case Core::IVersionControl::SnapshotOperations:
82 bool MercurialControl::vcsOpen(const QString &filename)
88 bool MercurialControl::vcsAdd(const QString &filename)
90 const QFileInfo fi(filename);
91 return mercurialClient->synchronousAdd(fi.absolutePath(), fi.fileName());
94 bool MercurialControl::vcsDelete(const QString &filename)
96 const QFileInfo fi(filename);
97 return mercurialClient->synchronousRemove(fi.absolutePath(), fi.fileName());
100 bool MercurialControl::vcsMove(const QString &from, const QString &to)
102 const QFileInfo fromInfo(from);
103 const QFileInfo toInfo(to);
104 return mercurialClient->synchronousMove(fromInfo.absolutePath(),
105 fromInfo.absoluteFilePath(),
106 toInfo.absoluteFilePath());
109 bool MercurialControl::vcsCreateRepository(const QString &directory)
111 return mercurialClient->synchronousCreateRepository(directory);
114 QString MercurialControl::vcsCreateSnapshot(const QString &)
119 QStringList MercurialControl::vcsSnapshots(const QString &)
121 return QStringList();
124 bool MercurialControl::vcsRestoreSnapshot(const QString &, const QString &)
129 bool MercurialControl::vcsRemoveSnapshot(const QString &, const QString &)
134 bool MercurialControl::vcsAnnotate(const QString &file, int line)
136 const QFileInfo fi(file);
137 mercurialClient->annotate(fi.absolutePath(), fi.fileName(), QString(), line);
141 bool MercurialControl::sccManaged(const QString &filename)
143 const QFileInfo fi(filename);
145 const bool managed = managesDirectory(fi.absolutePath(), &topLevel);
146 if (!managed || topLevel.isEmpty())
148 const QDir topLevelDir(topLevel);
149 return mercurialClient->manifestSync(topLevel, topLevelDir.relativeFilePath(filename));
152 bool MercurialControl::vcsCheckout(const QString &directory, const QByteArray &url)
154 return mercurialClient->synchronousClone(QString(), directory, url);
157 QString MercurialControl::vcsGetRepositoryURL(const QString &directory)
159 return mercurialClient->vcsGetRepositoryURL(directory);
162 void MercurialControl::changed(const QVariant &v)
165 case QVariant::String:
166 emit repositoryChanged(v.toString());
168 case QVariant::StringList:
169 emit filesChanged(v.toStringList());