add more spacing
[personal-kdebase.git] / workspace / kcontrol / kfontinst / lib / Misc.h
blobeb7b801958391b5563c48a07307840eb02bd97ec
1 #ifndef __MISC_H__
2 #define __MISC_H__
4 /*
5 * KFontInst - KDE Font Installer
7 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
9 * ----
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
27 #include <unistd.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <time.h>
32 #include <QtCore/QDataStream>
33 #include <QtCore/QFile>
34 #include <KDE/KUrl>
35 #include "KfiConstants.h"
37 class QTextStream;
38 class QByteArray;
40 namespace KFI
43 namespace Misc
45 enum EConstants
47 FILE_PERMS = 0644,
48 DIR_PERMS = 0755
51 struct TFont
53 TFont(const QString &f=QString(), quint32 s=KFI_NO_STYLE_INFO) : family(f), styleInfo(s) { }
55 bool operator==(const TFont &o) const { return o.styleInfo==styleInfo && o.family==family; }
57 QString family;
58 quint32 styleInfo;
61 extern KDE_EXPORT QString prettyUrl(const KUrl &url);
62 inline KDE_EXPORT bool isHidden(const QString &f) { return QChar('.')==f[0]; }
63 inline KDE_EXPORT bool isHidden(const KUrl &url) { return isHidden(url.fileName()); }
64 extern KDE_EXPORT bool check(const QString &path, bool file, bool checkW=false);
65 inline KDE_EXPORT bool fExists(const QString &p) { return check(p, true, false); }
66 inline KDE_EXPORT bool dExists(const QString &p) { return check(p, false, false); }
67 inline KDE_EXPORT bool fWritable(const QString &p) { return check(p, true, true); }
68 inline KDE_EXPORT bool dWritable(const QString &p) { return check(p, false, true); }
69 extern KDE_EXPORT QString linkedTo(const QString &i);
70 extern KDE_EXPORT QString dirSyntax(const QString &d); // Has trailing slash: /file/path/
71 extern KDE_EXPORT QString fileSyntax(const QString &f);
72 extern KDE_EXPORT QString getDir(const QString &f);
73 extern KDE_EXPORT QString getFile(const QString &f);
74 extern KDE_EXPORT bool createDir(const QString &dir);
75 extern KDE_EXPORT void setFilePerms(const QByteArray &f);
76 inline KDE_EXPORT void setFilePerms(const QString &f) { setFilePerms(QFile::encodeName(f)); }
77 extern KDE_EXPORT QString changeExt(const QString &f, const QString &newExt);
78 extern KDE_EXPORT bool doCmd(const QString &cmd, const QString &p1=QString(),
79 const QString &p2=QString(), const QString &p3=QString());
80 inline KDE_EXPORT bool root() { return 0==getuid(); }
81 extern KDE_EXPORT void getAssociatedFiles(const QString &file, QStringList &list,
82 bool afmAndPfm=true);
83 extern KDE_EXPORT time_t getTimeStamp(const QString &item);
84 extern KDE_EXPORT QString getFolder(const QString &defaultDir, const QString &root,
85 QStringList &dirs);
86 extern KDE_EXPORT bool checkExt(const QString &fname, const QString &ext);
87 extern KDE_EXPORT bool isMetrics(const QString &str);
88 inline KDE_EXPORT bool isMetrics(const KUrl &url) { return isMetrics(url.fileName()); }
89 inline KDE_EXPORT bool isPackage(const QString &file)
90 { return file.indexOf(KFI_FONTS_PACKAGE)==(file.length()-KFI_FONTS_PACKAGE_LEN); }
91 extern KDE_EXPORT int getIntQueryVal(const KUrl &url, const char *key, int defVal);
92 extern KDE_EXPORT bool printable(const QString &mime);
93 inline KDE_EXPORT QString unhide(const QString &f) { return '.'==f[0] ? f.mid(1) : f; }
94 extern KDE_EXPORT uint qHash(const TFont &key);
95 extern KDE_EXPORT bool configureForX11(const QString &dir);
96 extern KDE_EXPORT QString encodeText(const QString &str, QTextStream &s);
97 extern KDE_EXPORT QString contractHome(QString path);
102 inline KDE_EXPORT QDataStream & operator<<(QDataStream &ds, const KFI::Misc::TFont &font)
104 ds << font.family << font.styleInfo;
105 return ds;
108 inline KDE_EXPORT QDataStream & operator>>(QDataStream &ds, KFI::Misc::TFont &font)
110 ds >> font.family >> font.styleInfo;
111 return ds;
114 #endif