~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kcontrol/kfontinst/lib/Misc.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __MISC_H__
 
2
#define __MISC_H__
 
3
 
 
4
/*
 
5
 * KFontInst - KDE Font Installer
 
6
 *
 
7
 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
 
8
 *
 
9
 * ----
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 *
 
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.
 
25
 */
 
26
 
 
27
#include <unistd.h>
 
28
#include <sys/types.h>
 
29
#include <sys/stat.h>
 
30
#include <time.h>
 
31
 
 
32
#include <QtCore/QDataStream>
 
33
#include <QtCore/QFile>
 
34
#include <KDE/KUrl>
 
35
#include "KfiConstants.h"
 
36
 
 
37
class QTextStream;
 
38
class QByteArray;
 
39
 
 
40
namespace KFI
 
41
{
 
42
 
 
43
namespace Misc
 
44
{
 
45
    enum EConstants
 
46
    {
 
47
        FILE_PERMS = 0644,
 
48
        DIR_PERMS  = 0755
 
49
    };
 
50
 
 
51
    struct TFont
 
52
    {
 
53
        TFont(const QString &f=QString(), quint32 s=KFI_NO_STYLE_INFO) : family(f), styleInfo(s) { }
 
54
 
 
55
        bool operator==(const TFont &o) const { return o.styleInfo==styleInfo && o.family==family; }
 
56
 
 
57
        QString family;
 
58
        quint32 styleInfo;
 
59
    };
 
60
 
 
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    isBitmap(const QString &str);
 
88
    extern KDE_EXPORT bool    isMetrics(const QString &str);
 
89
    inline KDE_EXPORT bool    isMetrics(const KUrl &url) { return isMetrics(url.fileName()); }
 
90
    inline KDE_EXPORT bool    isPackage(const QString &file)
 
91
                      { return file.indexOf(KFI_FONTS_PACKAGE)==(file.length()-KFI_FONTS_PACKAGE_LEN); }
 
92
    extern KDE_EXPORT int     getIntQueryVal(const KUrl &url, const char *key, int defVal);
 
93
    extern KDE_EXPORT bool    printable(const QString &mime);
 
94
    inline KDE_EXPORT QString hide(const QString &f) { return '.'!=f[0] ? QChar('.')+f : f; }
 
95
    inline KDE_EXPORT QString unhide(const QString &f) { return '.'==f[0] ? f.mid(1) : f; }
 
96
    extern KDE_EXPORT uint    qHash(const TFont &key);
 
97
    extern KDE_EXPORT QString encodeText(const QString &str, QTextStream &s);
 
98
    extern KDE_EXPORT QString contractHome(QString path);
 
99
    extern KDE_EXPORT QString expandHome(QString path);
 
100
    extern KDE_EXPORT QMap<QString, QString> getFontFileMap(const QSet<QString> &files);
 
101
}
 
102
 
 
103
}
 
104
 
 
105
inline KDE_EXPORT QDataStream & operator<<(QDataStream &ds, const KFI::Misc::TFont &font)
 
106
{
 
107
    ds << font.family << font.styleInfo;
 
108
    return ds;
 
109
}
 
110
 
 
111
inline KDE_EXPORT QDataStream & operator>>(QDataStream &ds, KFI::Misc::TFont &font)
 
112
{
 
113
    ds >> font.family >> font.styleInfo;
 
114
    return ds;
 
115
}
 
116
 
 
117
#endif