OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / libs / utils / pathchooser.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 PATHCHOOSER_H
34 #define PATHCHOOSER_H
35
36 #include "utils_global.h"
37
38 #include <QtGui/QWidget>
39
40 QT_BEGIN_NAMESPACE
41 class QAbstractButton;
42 class QLineEdit;
43 QT_END_NAMESPACE
44
45
46 namespace Utils {
47
48 class Environment;
49 class PathChooserPrivate;
50
51 class QTCREATOR_UTILS_EXPORT PathChooser : public QWidget
52 {
53     Q_DISABLE_COPY(PathChooser)
54     Q_OBJECT
55     Q_ENUMS(Kind)
56     Q_PROPERTY(QString path READ path WRITE setPath DESIGNABLE true)
57     Q_PROPERTY(QString promptDialogTitle READ promptDialogTitle WRITE setPromptDialogTitle DESIGNABLE true)
58     Q_PROPERTY(Kind expectedKind READ expectedKind WRITE setExpectedKind DESIGNABLE true)
59     Q_PROPERTY(QString baseDirectory READ baseDirectory WRITE setBaseDirectory DESIGNABLE true)
60     Q_PROPERTY(QStringList commandVersionArguments READ commandVersionArguments WRITE setCommandVersionArguments)
61     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly DESIGNABLE true)
62
63 public:
64     static const char * const browseButtonLabel;
65
66     explicit PathChooser(QWidget *parent = 0);
67     virtual ~PathChooser();
68
69     enum Kind {
70         ExistingDirectory,
71         Directory, // A directory, doesn't need to exist
72         File,
73         ExistingCommand, // A command that must exist at the time of selection
74         Command, // A command that may or may not exist at the time of selection (e.g. result of a build)
75         Any
76     };
77
78     // Default is <Directory>
79     void setExpectedKind(Kind expected);
80     Kind expectedKind() const;
81
82     void setPromptDialogTitle(const QString &title);
83     QString promptDialogTitle() const;
84
85     void setPromptDialogFilter(const QString &filter);
86     QString promptDialogFilter() const;
87
88     void setInitialBrowsePathBackup(const QString &path);
89
90     bool isValid() const;
91     QString errorMessage() const;
92
93     QString path() const;
94     QString rawPath() const; // The raw unexpanded input.
95
96     QString baseDirectory() const;
97     void setBaseDirectory(const QString &directory);
98
99     void setEnvironment(const Utils::Environment &env);
100
101     /** Returns the suggested label title when used in a form layout. */
102     static QString label();
103
104     virtual bool validatePath(const QString &path, QString *errorMessage = 0);
105
106     /** Return the home directory, which needs some fixing under Windows. */
107     static QString homePath();
108
109     void addButton(const QString &text, QObject *receiver, const char *slotFunc);
110     QAbstractButton *buttonAtIndex(int index) const;
111
112     QLineEdit *lineEdit() const;
113
114     // For PathChoosers of 'Command' type, this property specifies the arguments
115     // required to obtain the tool version (commonly, '--version'). Setting them
116     // causes the version to be displayed as a tooltip.
117     QStringList commandVersionArguments() const;
118     void setCommandVersionArguments(const QStringList &arguments);
119
120     // Utility to run a tool and return its stdout.
121     static QString toolVersion(const QString &binary, const QStringList &arguments);
122     // Install a tooltip on lineedits used for binaries showing the version.
123     static void installLineEditVersionToolTip(QLineEdit *le, const QStringList &arguments);
124
125     bool isReadOnly() const;
126     void setReadOnly(bool b);
127
128 private:
129     // Returns overridden title or the one from <title>
130     QString makeDialogTitle(const QString &title);
131
132 signals:
133     void validChanged();
134     void validChanged(bool validState);
135     void changed(const QString &text);
136     void editingFinished();
137     void beforeBrowsing();
138     void browsingFinished();
139     void returnPressed();
140
141 public slots:
142     void setPath(const QString &);
143
144 private slots:
145     void slotBrowse();
146
147 private:
148     PathChooserPrivate *m_d;
149 };
150
151 } // namespace Utils
152
153
154 #endif // PATHCHOOSER_H