OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / perforce / perforcesettings.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
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 #ifndef PERFOCESETTINGS_H
34 #define PERFOCESETTINGS_H
35
36 #include <QtCore/QString>
37 #include <QtCore/QScopedPointer>
38
39 QT_BEGIN_NAMESPACE
40 class QSettings;
41 class QDir;
42 QT_END_NAMESPACE
43
44 namespace Perforce {
45 namespace Internal {
46
47 struct Settings {
48     Settings();
49     bool equals(const Settings &s) const;
50     QStringList commonP4Arguments() const;
51
52     // Checks. On success, errorMessage will contains the client root.
53     bool check(QString *repositoryRoot /* = 0*/, QString *errorMessage) const;
54     static bool doCheck(const QString &binary, const QStringList &basicArgs,
55                         QString *repositoryRoot /* = 0 */,
56                         QString *errorMessage);
57
58     QString p4Command;
59     QString p4Port;
60     QString p4Client;
61     QString p4User;
62     QString errorString;
63     int logCount;
64     bool defaultEnv;
65     int timeOutS;
66     bool promptToSubmit;
67     bool autoOpen;
68 };
69
70 inline bool operator==(const Settings &s1, const Settings &s2) { return s1.equals(s2); }
71 inline bool operator!=(const Settings &s1, const Settings &s2) { return !s1.equals(s2); }
72
73 /* PerforceSettings: Aggregates settings struct and toplevel directory
74  * which is determined externally by background checks and provides a convenience
75  * for determining the common arguments.
76  * Those must contain (apart from server connection settings) the working directory
77  * with the "-d" option. This is because the p4 command line client detects its path
78  * from the PWD environment variable which breaks relative paths since that is set by
79  * the shell running Creator and is not necessarily that of the working directory
80  * (see p4 documentation).
81  * An additional complication is that the repository might be a symbolic link on Unix,
82  * say "$HOME/dev" linked to "/depot". If the p4 client specification contains
83  * "$HOME/dev", paths containing "/depot" will be refused as "not under client's view" by
84  * p4. This is why the client root portion of working directory must be mapped for the
85  * "-d" option, so that running p4 in "/depot/dev/foo" results in "-d $HOME/dev/foo". */
86
87 class PerforceSettings {
88     Q_DISABLE_COPY(PerforceSettings)
89 public:
90     PerforceSettings();
91     ~PerforceSettings();
92
93     inline bool isValid() const
94     {
95         return !m_topLevel.isEmpty() && !m_settings.p4Command.isEmpty();
96     }
97
98     void fromSettings(QSettings *settings);
99     void toSettings(QSettings *) const;
100
101     void setSettings(const Settings &s);
102     Settings settings() const;
103
104     inline int timeOutS()      const { return m_settings.timeOutS;  }
105     inline int timeOutMS()     const { return m_settings.timeOutS * 1000;  }
106     inline int longTimeOutMS() const { return m_settings.timeOutS * 10000; }
107
108     inline int logCount() const { return m_settings.logCount; }
109
110     QString topLevel() const;
111     QString topLevelSymLinkTarget() const;
112
113     void setTopLevel(const QString &);
114
115     // Return relative path to top level. Returns "" if it is the same directory,
116     // ".." if it is not within.
117     QString relativeToTopLevel(const QString &dir) const;
118     // Return argument list relative to top level (empty meaning,
119     // it is the same directory).
120     QStringList relativeToTopLevelArguments(const QString &dir) const;
121
122     // Map p4 path back to file system in case of a symlinked top-level
123     QString mapToFileSystem(const QString &perforceFilePath) const;
124
125     QString p4Command() const;
126     QString p4Port() const;
127     QString p4Client() const;
128     QString p4User() const;
129     bool defaultEnv() const;
130     bool promptToSubmit() const;
131     void setPromptToSubmit(bool p);
132     bool autoOpen() const;
133     void setAutoOpen(bool p);
134
135     // Return basic arguments, including -d and server connection parameters.
136     QStringList commonP4Arguments(const QString &workingDir) const;
137
138 private:
139     inline QStringList workingDirectoryArguments(const QString &workingDir) const;
140     void clearTopLevel();
141
142     Settings m_settings;
143     QString m_topLevel;
144     QString m_topLevelSymLinkTarget;
145     QScopedPointer<QDir> m_topLevelDir;
146 };
147
148 } // Internal
149 } // Perforce
150
151 #endif // PERFOCESETTINGS_H