1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef PERFOCESETTINGS_H
35 #define PERFOCESETTINGS_H
37 #include <QtCore/QString>
38 #include <QtCore/QScopedPointer>
50 bool equals(const Settings &s) const;
51 QStringList commonP4Arguments() const;
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);
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); }
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". */
88 class PerforceSettings {
89 Q_DISABLE_COPY(PerforceSettings)
94 inline bool isValid() const { return !m_topLevel.isEmpty(); }
96 void fromSettings(QSettings *settings);
97 void toSettings(QSettings *) const;
99 void setSettings(const Settings &s);
100 Settings settings() const;
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; }
106 inline int logCount() const { return m_settings.logCount; }
108 QString topLevel() const;
109 QString topLevelSymLinkTarget() const;
111 void setTopLevel(const QString &);
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;
120 // Map p4 path back to file system in case of a symlinked top-level
121 QString mapToFileSystem(const QString &perforceFilePath) const;
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);
133 // Return basic arguments, including -d and server connection parameters.
134 QStringList commonP4Arguments(const QString &workingDir) const;
137 inline QStringList workingDirectoryArguments(const QString &workingDir) const;
138 void clearTopLevel();
142 QString m_topLevelSymLinkTarget;
143 QScopedPointer<QDir> m_topLevelDir;
149 #endif // PERFOCESETTINGS_H