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