OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / libs / utils / unixutils.cpp
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
34 #include "unixutils.h"
35 #include <QtCore/QSettings>
36 #include <QtCore/QObject>
37 #include <QtCore/QFileInfo>
38 #include <QtCore/QCoreApplication>
39
40 using namespace Utils;
41
42 QString UnixUtils::defaultFileBrowser()
43 {
44     return QLatin1String("xdg-open %d");
45 }
46
47 QString UnixUtils::fileBrowser(const QSettings *settings)
48 {
49     const QString dflt = defaultFileBrowser();
50     if (!settings)
51         return dflt;
52     return settings->value(QLatin1String("General/FileBrowser"), dflt).toString();
53 }
54
55 void UnixUtils::setFileBrowser(QSettings *settings, const QString &term)
56 {
57     return settings->setValue(QLatin1String("General/FileBrowser"), term);
58 }
59
60
61 QString UnixUtils::fileBrowserHelpText()
62 {
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>"
70             "</table>");
71     return help;
72 }
73
74 QString UnixUtils::substituteFileBrowserParameters(const QString &pre, const QString &file)
75 {
76     QString cmd;
77     for (int i = 0; i < pre.size(); ++i) {
78         QChar c = pre.at(i);
79         if (c == QLatin1Char('%') && i < pre.size()-1) {
80             c = pre.at(++i);
81             QString s;
82             if (c == QLatin1Char('d'))
83                 s = QFileInfo(file).path();
84             else if (c == QLatin1Char('f'))
85                 s = file;
86             else if (c == QLatin1Char('n'))
87                 s = QFileInfo(file).fileName();
88             else if (c == QLatin1Char('%'))
89                 s = c;
90             else {
91                 s = QLatin1Char('%');
92                 s += c;
93             }
94             cmd += s;
95             continue;
96
97         }
98         cmd += c;
99     }
100
101     return cmd;
102 }