OSDN Git Service

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