source: ogBrowser-Git/qtermwidget/lib/tools.cpp @ c0cec9d

jenkinsmain
Last change on this file since c0cec9d was 64efc22, checked in by Vadim Troshchinskiy <vtroshchinskiy@…>, 19 months ago

Update qtermwidget to modern version

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