OSDN Git Service

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