OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / mercurial / mercurialcontrol.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2009 Brian McGillion
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "mercurialcontrol.h"
34 #include "mercurialclient.h"
35
36 #include <QtCore/QFileInfo>
37 #include <QtCore/QVariant>
38 #include <QtCore/QStringList>
39 #include <QtCore/QDir>
40
41 using namespace Mercurial::Internal;
42
43 MercurialControl::MercurialControl(MercurialClient *client)
44         :   mercurialClient(client)
45 {
46 }
47
48 QString MercurialControl::displayName() const
49 {
50     return tr("Mercurial");
51 }
52
53 bool MercurialControl::managesDirectory(const QString &directory, QString *topLevel) const
54 {
55     QFileInfo dir(directory);
56     const QString topLevelFound = mercurialClient->findTopLevelForFile(dir);
57     if (topLevel)
58         *topLevel = topLevelFound;
59     return !topLevelFound.isEmpty();
60 }
61
62 bool MercurialControl::supportsOperation(Operation operation) const
63 {
64     bool supported = true;
65     switch (operation) {
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:
73         break;
74     case Core::IVersionControl::OpenOperation:
75     case Core::IVersionControl::SnapshotOperations:
76         supported = false;
77         break;
78     }
79     return supported;
80 }
81
82 bool MercurialControl::vcsOpen(const QString &filename)
83 {
84     Q_UNUSED(filename)
85     return true;
86 }
87
88 bool MercurialControl::vcsAdd(const QString &filename)
89 {
90     const QFileInfo fi(filename);
91     return mercurialClient->synchronousAdd(fi.absolutePath(), fi.fileName());
92 }
93
94 bool MercurialControl::vcsDelete(const QString &filename)
95 {
96     const QFileInfo fi(filename);
97     return mercurialClient->synchronousRemove(fi.absolutePath(), fi.fileName());
98 }
99
100 bool MercurialControl::vcsMove(const QString &from, const QString &to)
101 {
102     const QFileInfo fromInfo(from);
103     const QFileInfo toInfo(to);
104     return mercurialClient->synchronousMove(fromInfo.absolutePath(),
105                                             fromInfo.absoluteFilePath(),
106                                             toInfo.absoluteFilePath());
107 }
108
109 bool MercurialControl::vcsCreateRepository(const QString &directory)
110 {
111     return mercurialClient->synchronousCreateRepository(directory);
112 }
113
114 QString MercurialControl::vcsCreateSnapshot(const QString &)
115 {
116     return QString();
117 }
118
119 QStringList MercurialControl::vcsSnapshots(const QString &)
120 {
121     return QStringList();
122 }
123
124 bool MercurialControl::vcsRestoreSnapshot(const QString &, const QString &)
125 {
126     return false;
127 }
128
129 bool MercurialControl::vcsRemoveSnapshot(const QString &, const QString &)
130 {
131     return false;
132 }
133
134 bool MercurialControl::vcsAnnotate(const QString &file, int line)
135 {
136     const QFileInfo fi(file);
137     mercurialClient->annotate(fi.absolutePath(), fi.fileName(), QString(), line);
138     return true;
139 }
140
141 bool MercurialControl::sccManaged(const QString &filename)
142 {
143     const QFileInfo fi(filename);
144     QString topLevel;
145     const bool managed = managesDirectory(fi.absolutePath(), &topLevel);
146     if (!managed || topLevel.isEmpty())
147         return false;
148     const QDir topLevelDir(topLevel);
149     return mercurialClient->manifestSync(topLevel, topLevelDir.relativeFilePath(filename));
150 }
151
152 bool MercurialControl::vcsCheckout(const QString &directory, const QByteArray &url)
153 {
154     return mercurialClient->synchronousClone(QString(), directory, url);
155 }
156
157 QString MercurialControl::vcsGetRepositoryURL(const QString &directory)
158 {
159     return mercurialClient->vcsGetRepositoryURL(directory);
160 }
161
162 void MercurialControl::changed(const QVariant &v)
163 {
164     switch (v.type()) {
165     case QVariant::String:
166         emit repositoryChanged(v.toString());
167         break;
168     case QVariant::StringList:
169         emit filesChanged(v.toStringList());
170         break;
171     default:
172         break;
173     }
174 }