Debian Codegraph @

lib/tools.cpp

raw symbols SCIP
1 #include "tools.h"
2
3 #include <QCoreApplication>
4 #include <QDir>
5 #include <QtDebug>
6
7
8 Q_LOGGING_CATEGORY(qtermwidgetLogger, "qtermwidget", QtWarningMsg)
9
10 /*! Helper function to get possible location of layout files.
11 By default the KB_LAYOUT_DIR is used (linux/BSD/macports).
12 But in some cases (apple bundle) there can be more locations).
13 */
14 QString get_kb_layout_dir()
15 {
16 // qDebug() << __FILE__ << __FUNCTION__;
17
18 QString rval = QString();
19 QString k(qgetenv("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 */
47 namespace {
48 QStringList custom_color_schemes_dirs;
49 }
50 void 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.
57 By default the COLORSCHEMES_DIR is used (linux/BSD/macports).
58 But in some cases (apple bundle) there can be more locations).
59 */
60 const QStringList get_color_schemes_dirs()
61 {
62 // qDebug() << __FILE__ << __FUNCTION__;
63
64 QStringList rval;
65 QString k(qgetenv("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 }