summaryrefslogtreecommitdiffstats
path: root/kcontrol/tdefontinst/tdeio/KioFonts.h
blob: 52516fe62aad57f5094e5980a7d2e44e38245ff2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#ifndef __TDEIO_FONTS_H__
#define __TDEIO_FONTS_H__

////////////////////////////////////////////////////////////////////////////////
//
// Class Name    : KFI::CKioFonts
// Author        : Craig Drummond
// Project       : K Font Installer
// Creation Date : 05/03/2003
// Version       : $Revision$ $Date$
//
////////////////////////////////////////////////////////////////////////////////
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//
////////////////////////////////////////////////////////////////////////////////
// (C) Craig Drummond, 2003, 2004
////////////////////////////////////////////////////////////////////////////////

#include <fontconfig/fontconfig.h>
#include <time.h>
#include <tdeio/slavebase.h>
#include <kurl.h>
#include <tdelocale.h>
#include <tqstring.h>
#include <tqcstring.h>
#include <tqmap.h>
#include <tqvaluelist.h>
#include "Misc.h"
#include "KfiConstants.h"

namespace KFI
{

class CKioFonts : public TDEIO::SlaveBase
{
    private:

    enum EConstants
    {
        KFI_PARAMS = 8
    };

    enum EDest
    {
        DEST_UNCHANGED,
        DEST_SYS,
        DEST_USER
    };

    enum EFolder
    {
        FOLDER_SYS,
        FOLDER_USER,

        FOLDER_COUNT
    };

    enum EOp
    {
        OP_COPY,
        OP_MOVE,
        OP_DELETE
    };

    class CDirList : public TQStringList
    {
        public:

        CDirList()                                      { }
        CDirList(const TQString &str) : TQStringList(str) { }

        void add(const TQString &d)                      { if ( contains(d)) append(d); }
    };

    struct TFolder
    {
        TQString                                 location;
        CDirList                                modified;
        TQMap<TQString, TQValueList<FcPattern *> > fontMap;   // Maps from "Times New Roman" -> $HOME/.fonts/times.ttf
    };

    public:

    CKioFonts(const TQCString &pool, const TQCString &app);
    virtual ~CKioFonts();

    static TQString getSect(const TQString &f) { return f.section('/', 1, 1); }

    void listDir(const KURL &url);
    void stat(const KURL &url);
    bool createStatEntry(TDEIO::UDSEntry &entry, const KURL &url, EFolder folder);
    void get(const KURL &url);
    void put(const KURL &url, int mode, bool overwrite, bool resume);
    void copy(const KURL &src, const KURL &dest, int mode, bool overwrite);
    void rename(const KURL &src, const KURL &dest, bool overwrite);
    void del(const KURL &url, bool isFile);

    private:

    bool     putReal(const TQString &destOrig, const TQCString &destOrigC, bool origExists, int mode, bool resume);
    void     modified(EFolder folder, bool clearList=true, const CDirList &dirs=CDirList());
    void     special(const TQByteArray &a);
    void     createRootRefreshCmd(TQCString &cmd, const CDirList &dirs=CDirList(), bool reparseCfg=true);
    void     doModified();
    TQString  getRootPasswd(bool askPasswd=true);
    bool     doRootCmd(const char *cmd, const TQString &passwd);
    bool     doRootCmd(const char *cmd, bool askPasswd=true) { return doRootCmd(cmd, getRootPasswd(askPasswd)); }
    bool     confirmUrl(KURL &url);
    void     clearFontList();
    bool     updateFontList();
    EFolder  getFolder(const KURL &url);
    TQMap<TQString, TQValueList<FcPattern *> >::Iterator getMap(const KURL &url);
    TQValueList<FcPattern *> * getEntries(const KURL &url);
    FcPattern * getEntry(EFolder folder, const TQString &file, bool full=false);
    bool     checkFile(const TQString &file);
    bool     getSourceFiles(const KURL &src, TQStringList &files);
    bool     checkDestFile(const KURL &src, const KURL &dest, EFolder destFolder, bool overwrite);
    bool     checkDestFiles(const KURL &src, TQMap<TQString, TQString> &map, const KURL &dest, EFolder destFolder, bool overwrite);
    bool     confirmMultiple(const KURL &url, const TQStringList &files, EFolder folder, EOp op);
    bool     confirmMultiple(const KURL &url, TQValueList<FcPattern *> *patterns, EFolder folder, EOp op);
    bool     checkUrl(const KURL &u, bool rootOk=false);
    bool     checkAllowed(const KURL &u);
    void     createAfm(const TQString &file, bool nrs=false, const TQString &passwd=TQString::null);
    void     reparseConfig();

    private:

    bool         itsRoot,
                 itsCanStorePasswd,
                 itsUsingFcFpe,
                 itsUsingXfsFpe,
                 itsHasSys,
                 itsAddToSysFc;
    TQString      itsPasswd;
    unsigned int itsFontChanges;
    EDest        itsLastDest;
    time_t       itsLastDestTime,
                 itsLastFcCheckTime;
    FcFontSet    *itsFontList;
    TFolder      itsFolders[FOLDER_COUNT];
    char         itsNrsKfiParams[KFI_PARAMS],
                 itsNrsNonMainKfiParams[KFI_PARAMS],
                 itsKfiParams[KFI_PARAMS];
};

}

#endif