File indexing completed on 2025-01-19 04:23:32
0001 #include "tools.h" 0002 0003 #include <QCoreApplication> 0004 #include <QDir> 0005 #include <QtDebug> 0006 0007 0008 /*! Helper function to get possible location of layout files. 0009 By default the KB_LAYOUT_DIR is used (linux/BSD/macports). 0010 But in some cases (apple bundle) there can be more locations). 0011 */ 0012 QString get_kb_layout_dir() 0013 { 0014 // qDebug() << __FILE__ << __FUNCTION__; 0015 0016 QString rval = QString(); 0017 QString k(qgetenv("KB_LAYOUT_DIR")); 0018 QDir d(k); 0019 0020 qDebug() << "default KB_LAYOUT_DIR: " << k; 0021 0022 if (d.exists()) 0023 { 0024 rval = k.append(QLatin1Char('/')); 0025 return rval; 0026 } 0027 0028 // subdir in the app location 0029 d.setPath(QCoreApplication::applicationDirPath() + QLatin1String("/kb-layouts/")); 0030 //qDebug() << d.path(); 0031 if (d.exists()) 0032 return QCoreApplication::applicationDirPath() + QLatin1String("/kb-layouts/"); 0033 #ifdef Q_WS_MAC 0034 d.setPath(QCoreApplication::applicationDirPath() + "/../Resources/kb-layouts/"); 0035 if (d.exists()) 0036 return QCoreApplication::applicationDirPath() + "/../Resources/kb-layouts/"; 0037 #endif 0038 qDebug() << "Cannot find KB_LAYOUT_DIR. Default:" << k; 0039 return QString(); 0040 } 0041 0042 /*! Helper function to add custom location of color schemes. 0043 */ 0044 namespace { 0045 QStringList custom_color_schemes_dirs; 0046 } 0047 void add_custom_color_scheme_dir(const QString& custom_dir) 0048 { 0049 if (!custom_color_schemes_dirs.contains(custom_dir)) 0050 custom_color_schemes_dirs << custom_dir; 0051 } 0052 0053 /*! Helper function to get possible locations of color schemes. 0054 By default the COLORSCHEMES_DIR is used (linux/BSD/macports). 0055 But in some cases (apple bundle) there can be more locations). 0056 */ 0057 const QStringList get_color_schemes_dirs() 0058 { 0059 // qDebug() << __FILE__ << __FUNCTION__; 0060 0061 QStringList rval; 0062 QString k(qgetenv("COLORSCHEMES_DIR")); 0063 QDir d(k); 0064 0065 // qDebug() << "default COLORSCHEMES_DIR: " << k; 0066 0067 if (d.exists()) 0068 rval << k.append(QLatin1Char('/')); 0069 0070 // subdir in the app location 0071 d.setPath(QCoreApplication::applicationDirPath() + QLatin1String("/color-schemes/")); 0072 //qDebug() << d.path(); 0073 if (d.exists()) 0074 { 0075 if (!rval.isEmpty()) 0076 rval.clear(); 0077 rval << (QCoreApplication::applicationDirPath() + QLatin1String("/color-schemes/")); 0078 } 0079 #ifdef Q_WS_MAC 0080 d.setPath(QCoreApplication::applicationDirPath() + "/../Resources/color-schemes/"); 0081 if (d.exists()) 0082 { 0083 if (!rval.isEmpty()) 0084 rval.clear(); 0085 rval << (QCoreApplication::applicationDirPath() + "/../Resources/color-schemes/"); 0086 } 0087 #endif 0088 for (const QString& custom_dir : const_cast<const QStringList&>(custom_color_schemes_dirs)) 0089 { 0090 d.setPath(custom_dir); 0091 if (d.exists()) 0092 rval << custom_dir; 0093 } 0094 #ifdef QT_DEBUG 0095 if(!rval.isEmpty()) { 0096 qDebug() << "Using color-schemes: " << rval; 0097 } else { 0098 qDebug() << "Cannot find color-schemes in any location!"; 0099 } 0100 #endif 0101 return rval; 0102 }