1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #ifndef PERFOCESETTINGS_H
34 #define PERFOCESETTINGS_H
36 #include <QtCore/QString>
37 #include <QtCore/QScopedPointer>
49 bool equals(const Settings &s) const;
50 QStringList commonP4Arguments() const;
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);
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); }
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". */
87 class PerforceSettings {
88 Q_DISABLE_COPY(PerforceSettings)
93 inline bool isValid() const
95 return !m_topLevel.isEmpty() && !m_settings.p4Command.isEmpty();
98 void fromSettings(QSettings *settings);
99 void toSettings(QSettings *) const;
101 void setSettings(const Settings &s);
102 Settings settings() const;
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; }
108 inline int logCount() const { return m_settings.logCount; }
110 QString topLevel() const;
111 QString topLevelSymLinkTarget() const;
113 void setTopLevel(const QString &);
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;
122 // Map p4 path back to file system in case of a symlinked top-level
123 QString mapToFileSystem(const QString &perforceFilePath) const;
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);
135 // Return basic arguments, including -d and server connection parameters.
136 QStringList commonP4Arguments(const QString &workingDir) const;
139 inline QStringList workingDirectoryArguments(const QString &workingDir) const;
140 void clearTopLevel();
144 QString m_topLevelSymLinkTarget;
145 QScopedPointer<QDir> m_topLevelDir;
151 #endif // PERFOCESETTINGS_H