| 1 | #include "tools.h" |
|---|---|
| 2 | |
| 3 | #include <QCoreApplication> |
| 4 | #include <QDir> |
| 5 | #include <QtDebug> |
| 6 | |
| 7 | |
| 8 | /*! Helper function to get possible location of layout files. |
| 9 | By default the KB_LAYOUT_DIR is used (linux/BSD/macports). |
| 10 | But in some cases (apple bundle) there can be more locations). |
| 11 | */ |
| 12 | QString get_kb_layout_dir() |
| 13 | { |
| 14 | // qDebug() << __FILE__ << __FUNCTION__; |
| 15 | |
| 16 | QString rval = QString(); |
| 17 | QString k(QLatin1String(KB_LAYOUT_DIR)); |
| 18 | QDir d(k); |
| 19 | |
| 20 | qDebug() << "default KB_LAYOUT_DIR: "<< k; |
| 21 | |
| 22 | if (d.exists()) |
| 23 | { |
| 24 | rval = k.append(QLatin1Char('/')); |
| 25 | return rval; |
| 26 | } |
| 27 | |
| 28 | // subdir in the app location |
| 29 | d.setPath(QCoreApplication::applicationDirPath() + QLatin1String("/kb-layouts/")); |
| 30 | //qDebug() << d.path(); |
| 31 | if (d.exists()) |
| 32 | return QCoreApplication::applicationDirPath() + QLatin1String("/kb-layouts/"); |
| 33 | #ifdef Q_WS_MAC |
| 34 | d.setPath(QCoreApplication::applicationDirPath() + "/../Resources/kb-layouts/"); |
| 35 | if (d.exists()) |
| 36 | return QCoreApplication::applicationDirPath() + "/../Resources/kb-layouts/"; |
| 37 | #endif |
| 38 | qDebug() << "Cannot find KB_LAYOUT_DIR. Default:"<< k; |
| 39 | return QString(); |
| 40 | } |
| 41 | |
| 42 | /*! Helper function to add custom location of color schemes. |
| 43 | */ |
| 44 | namespace { |
| 45 | QStringList custom_color_schemes_dirs; |
| 46 | } |
| 47 | void add_custom_color_scheme_dir(const QString& custom_dir) |
| 48 | { |
| 49 | if (!custom_color_schemes_dirs.contains(custom_dir)) |
| 50 | custom_color_schemes_dirs << custom_dir; |
| 51 | } |
| 52 | |
| 53 | /*! Helper function to get possible locations of color schemes. |
| 54 | By default the COLORSCHEMES_DIR is used (linux/BSD/macports). |
| 55 | But in some cases (apple bundle) there can be more locations). |
| 56 | */ |
| 57 | const QStringList get_color_schemes_dirs() |
| 58 | { |
| 59 | // qDebug() << __FILE__ << __FUNCTION__; |
| 60 | |
| 61 | QStringList rval; |
| 62 | QString k(QLatin1String(COLORSCHEMES_DIR)); |
| 63 | QDir d(k); |
| 64 | |
| 65 | // qDebug() << "default COLORSCHEMES_DIR: " << k; |
| 66 | |
| 67 | if (d.exists()) |
| 68 | rval << k.append(QLatin1Char('/')); |
| 69 | |
| 70 | // subdir in the app location |
| 71 | d.setPath(QCoreApplication::applicationDirPath() + QLatin1String("/color-schemes/")); |
| 72 | //qDebug() << d.path(); |
| 73 | if (d.exists()) |
| 74 | { |
| 75 | if (!rval.isEmpty()) |
| 76 | rval.clear(); |
| 77 | rval << (QCoreApplication::applicationDirPath() + QLatin1String("/color-schemes/")); |
| 78 | } |
| 79 | #ifdef Q_WS_MAC |
| 80 | d.setPath(QCoreApplication::applicationDirPath() + "/../Resources/color-schemes/"); |
| 81 | if (d.exists()) |
| 82 | { |
| 83 | if (!rval.isEmpty()) |
| 84 | rval.clear(); |
| 85 | rval << (QCoreApplication::applicationDirPath() + "/../Resources/color-schemes/"); |
| 86 | } |
| 87 | #endif |
| 88 | for (const QString& custom_dir : const_cast<const QStringList&>(custom_color_schemes_dirs)) |
| 89 | { |
| 90 | d.setPath(custom_dir); |
| 91 | if (d.exists()) |
| 92 | rval << custom_dir; |
| 93 | } |
| 94 | #ifdef QT_DEBUG |
| 95 | if(!rval.isEmpty()) { |
| 96 | qDebug() << "Using color-schemes: "<< rval; |
| 97 | } else { |
| 98 | qDebug() << "Cannot find color-schemes in any location!"; |
| 99 | } |
| 100 | #endif |
| 101 | return rval; |
| 102 | } |
| 103 |