File indexing completed on 2024-12-22 05:15:55
0001 #pragma once 0002 0003 /* 0004 * SPDX-FileCopyrightText: 2003-2007 Craig Drummond <craig@kde.org> 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include <sys/stat.h> 0009 #include <sys/types.h> 0010 #include <time.h> 0011 #include <unistd.h> 0012 0013 #include "KfiConstants.h" 0014 #include <QDataStream> 0015 #include <QFile> 0016 #include <QUrl> 0017 0018 #include "kfontinst_export.h" 0019 0020 class QTextStream; 0021 class QByteArray; 0022 0023 namespace KFI 0024 { 0025 namespace Misc 0026 { 0027 enum EConstants { 0028 FILE_PERMS = 0644, 0029 DIR_PERMS = 0755, 0030 }; 0031 0032 struct TFont { 0033 TFont(const QString &f = QString(), quint32 s = KFI_NO_STYLE_INFO) 0034 : family(f) 0035 , styleInfo(s) 0036 { 0037 } 0038 0039 bool operator==(const TFont &o) const 0040 { 0041 return o.styleInfo == styleInfo && o.family == family; 0042 } 0043 0044 QString family; 0045 quint32 styleInfo; 0046 }; 0047 0048 extern KFONTINST_EXPORT QString prettyUrl(const QUrl &url); 0049 inline KFONTINST_EXPORT bool isHidden(const QString &f) 0050 { 0051 return f.startsWith(QChar('.')); 0052 } 0053 inline KFONTINST_EXPORT bool isHidden(const QUrl &url) 0054 { 0055 return isHidden(url.fileName()); 0056 } 0057 extern KFONTINST_EXPORT bool check(const QString &path, bool file, bool checkW = false); 0058 inline KFONTINST_EXPORT bool fExists(const QString &p) 0059 { 0060 return check(p, true, false); 0061 } 0062 inline KFONTINST_EXPORT bool dExists(const QString &p) 0063 { 0064 return check(p, false, false); 0065 } 0066 inline KFONTINST_EXPORT bool fWritable(const QString &p) 0067 { 0068 return check(p, true, true); 0069 } 0070 inline KFONTINST_EXPORT bool dWritable(const QString &p) 0071 { 0072 return check(p, false, true); 0073 } 0074 extern KFONTINST_EXPORT QString linkedTo(const QString &i); 0075 extern KFONTINST_EXPORT QString dirSyntax(const QString &d); // Has trailing slash: /file/path/ 0076 extern KFONTINST_EXPORT QString fileSyntax(const QString &f); 0077 extern KFONTINST_EXPORT QString getDir(const QString &f); 0078 extern KFONTINST_EXPORT QString getFile(const QString &f); 0079 extern KFONTINST_EXPORT bool createDir(const QString &dir); 0080 extern KFONTINST_EXPORT void setFilePerms(const QByteArray &f); 0081 inline KFONTINST_EXPORT void setFilePerms(const QString &f) 0082 { 0083 setFilePerms(QFile::encodeName(f)); 0084 } 0085 extern KFONTINST_EXPORT QString changeExt(const QString &f, const QString &newExt); 0086 extern KFONTINST_EXPORT bool doCmd(const QString &cmd, const QString &p1 = QString(), const QString &p2 = QString(), const QString &p3 = QString()); 0087 inline KFONTINST_EXPORT bool root() 0088 { 0089 return 0 == getuid(); 0090 } 0091 extern KFONTINST_EXPORT void getAssociatedFiles(const QString &file, QStringList &list, bool afmAndPfm = true); 0092 extern KFONTINST_EXPORT time_t getTimeStamp(const QString &item); 0093 extern KFONTINST_EXPORT QString getFolder(const QString &defaultDir, const QString &root, QStringList &dirs); 0094 extern KFONTINST_EXPORT bool checkExt(const QString &fname, const QString &ext); 0095 extern KFONTINST_EXPORT bool isBitmap(const QString &str); 0096 extern KFONTINST_EXPORT bool isMetrics(const QString &str); 0097 inline KFONTINST_EXPORT bool isMetrics(const QUrl &url) 0098 { 0099 return isMetrics(url.fileName()); 0100 } 0101 inline KFONTINST_EXPORT bool isPackage(const QString &file) 0102 { 0103 return file.indexOf(KFI_FONTS_PACKAGE) == (file.length() - KFI_FONTS_PACKAGE_LEN); 0104 } 0105 extern KFONTINST_EXPORT int getIntQueryVal(const QUrl &url, const char *key, int defVal); 0106 extern KFONTINST_EXPORT bool printable(const QString &mime); 0107 inline KFONTINST_EXPORT QString hide(const QString &f) 0108 { 0109 return '.' != f[0] ? QChar('.') + f : f; 0110 } 0111 inline KFONTINST_EXPORT QString unhide(const QString &f) 0112 { 0113 return '.' == f[0] ? f.mid(1) : f; 0114 } 0115 extern KFONTINST_EXPORT uint qHash(const TFont &key); 0116 extern KFONTINST_EXPORT QString encodeText(const QString &str); 0117 extern KFONTINST_EXPORT QString encodeText(const QString &str, QTextStream &s); 0118 extern KFONTINST_EXPORT QString contractHome(QString path); 0119 extern KFONTINST_EXPORT QString expandHome(QString path); 0120 extern KFONTINST_EXPORT QMap<QString, QString> getFontFileMap(const QSet<QString> &files); 0121 extern KFONTINST_EXPORT QString modifyName(const QString &fname); 0122 inline QString getDestFolder(const QString &folder, const QString &file) 0123 { 0124 return folder + file[0].toLower() + '/'; 0125 } 0126 extern KFONTINST_EXPORT QString app(const QString &name, const char *path = nullptr); 0127 } 0128 0129 } 0130 0131 inline KFONTINST_EXPORT QDataStream &operator<<(QDataStream &ds, const KFI::Misc::TFont &font) 0132 { 0133 ds << font.family << font.styleInfo; 0134 return ds; 0135 } 0136 0137 inline KFONTINST_EXPORT QDataStream &operator>>(QDataStream &ds, KFI::Misc::TFont &font) 0138 { 0139 ds >> font.family >> font.styleInfo; 0140 return ds; 0141 }