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 **************************************************************************/
34 #include "unixutils.h"
35 #include <QtCore/QSettings>
36 #include <QtCore/QObject>
37 #include <QtCore/QFileInfo>
38 #include <QtCore/QCoreApplication>
40 using namespace Utils;
42 QString UnixUtils::defaultFileBrowser()
44 return QLatin1String("xdg-open %d");
47 QString UnixUtils::fileBrowser(const QSettings *settings)
49 const QString dflt = defaultFileBrowser();
52 return settings->value(QLatin1String("General/FileBrowser"), dflt).toString();
55 void UnixUtils::setFileBrowser(QSettings *settings, const QString &term)
57 return settings->setValue(QLatin1String("General/FileBrowser"), term);
61 QString UnixUtils::fileBrowserHelpText()
63 QString help = QCoreApplication::translate("Utils::UnixTools",
64 "<table border=1 cellspacing=0 cellpadding=3>"
65 "<tr><th>Variable</th><th>Expands to</th></tr>"
66 "<tr><td>%d</td><td>directory of current file</td></tr>"
67 "<tr><td>%f</td><td>file name (with full path)</td></tr>"
68 "<tr><td>%n</td><td>file name (without path)</td></tr>"
69 "<tr><td>%%</td><td>%</td></tr>"
74 QString UnixUtils::substituteFileBrowserParameters(const QString &pre, const QString &file)
77 for (int i = 0; i < pre.size(); ++i) {
79 if (c == QLatin1Char('%') && i < pre.size()-1) {
82 if (c == QLatin1Char('d'))
83 s = QFileInfo(file).path();
84 else if (c == QLatin1Char('f'))
86 else if (c == QLatin1Char('n'))
87 s = QFileInfo(file).fileName();
88 else if (c == QLatin1Char('%'))