| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2010 Ricardo Villalba <rvm@escomposlinux.org>
|
|---|
| 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) {
|
|---|
| 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 | f = docPath() + "/en/" + file;
|
|---|
| 122 | return f;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | void Paths::setConfigPath(QString path) {
|
|---|
| 126 | config_path = path;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | QString Paths::configPath() {
|
|---|
| 130 | if (!config_path.isEmpty()) {
|
|---|
| 131 | return config_path;
|
|---|
| 132 | } else {
|
|---|
| 133 | #ifdef PORTABLE_APP
|
|---|
| 134 | return appPath();
|
|---|
| 135 | #else
|
|---|
| 136 | #if !defined(Q_OS_WIN) && !defined(Q_OS_OS2)
|
|---|
| 137 | const char * XDG_CONFIG_HOME = getenv("XDG_CONFIG_HOME");
|
|---|
| 138 | if (XDG_CONFIG_HOME!=NULL) {
|
|---|
| 139 | qDebug("Paths::configPath: XDG_CONFIG_HOME: %s", XDG_CONFIG_HOME);
|
|---|
| 140 | return QString(XDG_CONFIG_HOME) + "/smplayer";
|
|---|
| 141 | }
|
|---|
| 142 | else
|
|---|
| 143 | return QDir::homePath() + "/.config/smplayer";
|
|---|
| 144 | #else
|
|---|
| 145 | return QDir::homePath() + "/.smplayer";
|
|---|
| 146 | #endif
|
|---|
| 147 | #endif
|
|---|
| 148 | }
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | QString Paths::iniPath() {
|
|---|
| 152 | return configPath();
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | QString Paths::subtitleStyleFile() {
|
|---|
| 156 | return configPath() + "/styles.ass";
|
|---|
| 157 | }
|
|---|