1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "paths.h"
|
---|
20 | #include <QLibraryInfo>
|
---|
21 | #include <QLocale>
|
---|
22 | #include <QFile>
|
---|
23 | #include <QRegExp>
|
---|
24 | #include <QDir>
|
---|
25 |
|
---|
26 | #ifndef Q_OS_WIN
|
---|
27 | #include <stdlib.h>
|
---|
28 | #endif
|
---|
29 |
|
---|
30 | QString Paths::app_path;
|
---|
31 | QString Paths::config_path;
|
---|
32 |
|
---|
33 | void Paths::setAppPath(QString path) {
|
---|
34 | app_path = path;
|
---|
35 | }
|
---|
36 |
|
---|
37 | QString Paths::appPath() {
|
---|
38 | return app_path;
|
---|
39 | }
|
---|
40 |
|
---|
41 | QString Paths::dataPath() {
|
---|
42 | #ifdef DATA_PATH
|
---|
43 | QString path = QString(DATA_PATH);
|
---|
44 | if (!path.isEmpty())
|
---|
45 | return path;
|
---|
46 | else
|
---|
47 | return appPath();
|
---|
48 | #else
|
---|
49 | return appPath();
|
---|
50 | #endif
|
---|
51 | }
|
---|
52 |
|
---|
53 | QString Paths::translationPath() {
|
---|
54 | #ifdef TRANSLATION_PATH
|
---|
55 | QString path = QString(TRANSLATION_PATH);
|
---|
56 | if (!path.isEmpty())
|
---|
57 | return path;
|
---|
58 | else
|
---|
59 | return appPath() + "/translations";
|
---|
60 | #else
|
---|
61 | return appPath() + "/translations";
|
---|
62 | #endif
|
---|
63 | }
|
---|
64 |
|
---|
65 | QString Paths::docPath() {
|
---|
66 | #ifdef DOC_PATH
|
---|
67 | QString path = QString(DOC_PATH);
|
---|
68 | if (!path.isEmpty())
|
---|
69 | return path;
|
---|
70 | else
|
---|
71 | return appPath() + "/docs";
|
---|
72 | #else
|
---|
73 | return appPath() + "/docs";
|
---|
74 | #endif
|
---|
75 | }
|
---|
76 |
|
---|
77 | QString Paths::themesPath() {
|
---|
78 | #ifdef THEMES_PATH
|
---|
79 | QString path = QString(THEMES_PATH);
|
---|
80 | if (!path.isEmpty())
|
---|
81 | return path;
|
---|
82 | else
|
---|
83 | return appPath() + "/themes";
|
---|
84 | #else
|
---|
85 | return appPath() + "/themes";
|
---|
86 | #endif
|
---|
87 | }
|
---|
88 |
|
---|
89 | QString Paths::shortcutsPath() {
|
---|
90 | #ifdef SHORTCUTS_PATH
|
---|
91 | QString path = QString(SHORTCUTS_PATH);
|
---|
92 | if (!path.isEmpty())
|
---|
93 | return path;
|
---|
94 | else
|
---|
95 | return appPath() + "/shortcuts";
|
---|
96 | #else
|
---|
97 | return appPath() + "/shortcuts";
|
---|
98 | #endif
|
---|
99 | }
|
---|
100 |
|
---|
101 | QString Paths::qtTranslationPath() {
|
---|
102 | return QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
---|
103 | }
|
---|
104 |
|
---|
105 | QString Paths::doc(QString file, QString locale, bool english_fallback) {
|
---|
106 | if (locale.isEmpty()) {
|
---|
107 | locale = QLocale::system().name();
|
---|
108 | }
|
---|
109 |
|
---|
110 | QString f = docPath() + "/" + locale + "/" + file;
|
---|
111 | qDebug("Helper:doc: checking '%s'", f.toUtf8().data());
|
---|
112 | if (QFile::exists(f)) return f;
|
---|
113 |
|
---|
114 | if (locale.indexOf(QRegExp("_[A-Z]+")) != -1) {
|
---|
115 | locale.replace(QRegExp("_[A-Z]+"), "");
|
---|
116 | f = docPath() + "/" + locale + "/" + file;
|
---|
117 | qDebug("Helper:doc: checking '%s'", f.toUtf8().data());
|
---|
118 | if (QFile::exists(f)) return f;
|
---|
119 | }
|
---|
120 |
|
---|
121 | if (english_fallback) {
|
---|
122 | f = docPath() + "/en/" + file;
|
---|
123 | return f;
|
---|
124 | }
|
---|
125 |
|
---|
126 | return QString::null;
|
---|
127 | }
|
---|
128 |
|
---|
129 | void Paths::setConfigPath(QString path) {
|
---|
130 | config_path = path;
|
---|
131 | }
|
---|
132 |
|
---|
133 | QString Paths::configPath() {
|
---|
134 | if (!config_path.isEmpty()) {
|
---|
135 | return config_path;
|
---|
136 | } else {
|
---|
137 | #ifdef PORTABLE_APP
|
---|
138 | return appPath();
|
---|
139 | #else
|
---|
140 | #if !defined(Q_OS_WIN) && !defined(Q_OS_OS2)
|
---|
141 | const char * XDG_CONFIG_HOME = getenv("XDG_CONFIG_HOME");
|
---|
142 | if (XDG_CONFIG_HOME!=NULL) {
|
---|
143 | /* qDebug("Paths::configPath: XDG_CONFIG_HOME: %s", XDG_CONFIG_HOME); */
|
---|
144 | return QString(XDG_CONFIG_HOME) + "/smplayer";
|
---|
145 | }
|
---|
146 | else
|
---|
147 | return QDir::homePath() + "/.config/smplayer";
|
---|
148 | #else
|
---|
149 | return QDir::homePath() + "/.smplayer";
|
---|
150 | #endif
|
---|
151 | #endif
|
---|
152 | }
|
---|
153 | }
|
---|
154 |
|
---|
155 | QString Paths::iniPath() {
|
---|
156 | return configPath();
|
---|
157 | }
|
---|
158 |
|
---|
159 | QString Paths::subtitleStyleFile() {
|
---|
160 | return configPath() + "/styles.ass";
|
---|
161 | }
|
---|
162 |
|
---|
163 | #ifdef FONTS_HACK
|
---|
164 | QString Paths::fontPath() {
|
---|
165 | QString path = appPath() + "/mplayer/fonts";
|
---|
166 | QDir font_dir(path);
|
---|
167 | QStringList files = font_dir.entryList(QStringList() << "*.ttf" << "*.otf", QDir::Files);
|
---|
168 | //qDebug("Paths:fontPath: files in %s: %d", path.toUtf8().constData(), files.count());
|
---|
169 | if (files.count() > 0) {
|
---|
170 | return path;
|
---|
171 | } else {
|
---|
172 | return appPath() + "/open-fonts";
|
---|
173 | }
|
---|
174 | }
|
---|
175 | #endif
|
---|