summaryrefslogtreecommitdiffstats
path: root/tdecore/kinstance.h
blob: 2d94d10c14dbc587e219a0dbb04220595820a877 (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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* This file is part of the KDE libraries
   Copyright (C) 1999 Torben Weis <weis@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/
#ifndef _KINSTANCE_H
#define _KINSTANCE_H

class KStandardDirs;
class KAboutData;
class KConfig;
class KIconLoader;
class KCharsets;
class TQFont;
class KInstancePrivate;
class KMimeSourceFactory;
class KSharedConfig;
class TDEHardwareDevices;
class TDEGlobalNetworkManager;

#include <tqstring.h>
#include "tdelibs_export.h"


/**
 * Access to KDE global objects for use in shared libraries.  In
 * practical terms, this class is used in KDE components.  This allows
 * components to store things that normally would be accessed by
 * KGlobal.
 *
 * @author Torben Weis
 */
class TDECORE_EXPORT KInstance
{
    friend class KStandardDirs;

 public:
    /**
     *  Constructor.
     *  @param instanceName the name of the instance
     */
    KInstance( const TQCString& instanceName) ;

    /**
     *  Constructor.
     *  When building a KInstance that is not your TDEApplication,
     *  make sure that the KAboutData and the KInstance have the same life time.
     *  You have to destroy both, since the instance doesn't own the about data.
     *  Don't build a KAboutData on the stack in this case !
     *  Building a KAboutData on the stack is only ok for usage with
     *  TDECmdLineArgs and TDEApplication (not destroyed until the app exits).
     *  @param aboutData data about this instance (see KAboutData)
     */
    KInstance( const KAboutData * aboutData );

    /*
     * @internal
     * Only for K(Unique)Application
     * Initialize from src and delete it.
     */

    KInstance( KInstance* src );

    /**
     * Destructor.
     */
    virtual ~KInstance();

    /**
     * Returns the application standard dirs object.
     * @return The KStandardDirs of the application.
     */
    KStandardDirs	*dirs() const;

    /**
     * Returns the general config object ("appnamerc").
     * @return the KConfig object for the instance.
     */
    KConfig            *config() const;

    /**
     * Returns the general config object ("appnamerc").
     * @return the KConfig object for the instance.
     */
    KSharedConfig      *sharedConfig() const;

    /**
     * Set a read-only flag on the configuration files
     * This must be called before config() or dirs() to have any effect
     * Defaults to FALSE
     * @param ro read only if TRUE
     */
    void                setConfigReadOnly(bool ro);

    /**
     *  Returns an iconloader object.
     * @return the iconloader object.
     */
    KIconLoader	       *iconLoader() const;

    /**
     *  Returns a TDEHardwareDevices object.
     * @return the hardwaredevices object.
     */
    TDEHardwareDevices	*hardwareDevices() const;

    /**
     *  Returns a TDEGlobalNetworkManager object.
     * @return the networkmanager object.
     */
    TDEGlobalNetworkManager  *networkManager() const;

    /**
     * Re-allocate the global iconloader.
     */
    void newIconLoader() const;

    /**
     *  Returns the about data of this instance
     *  Warning, can be 0L
     * @return the about data of the instance, or 0 if it has 
     *         not been set yet
     */
    const KAboutData *aboutData() const;

    /**
     * Returns the name of the instance
     * @return the instance name, can be null if the KInstance has been 
     *         created with a null name
     */
    TQCString          instanceName() const;

    /**
     * Returns the KMimeSourceFactory of the instance.
     * Mainly added for API completeness and future extensibility.
     * @return the KMimeSourceFactory set as default for this application.
     */
    KMimeSourceFactory* mimeSourceFactory () const;

protected:
    /**
     *  Copy Constructor is not allowed
     */
    KInstance( const KInstance& );

    /**
     * Set name of default config file.
     * @param name the name of the default config file
     * @since 3.1
     */
    void setConfigName(const TQString &name);

private:
    mutable KStandardDirs       *_dirs;

    mutable KConfig             *_config;
    mutable KIconLoader         *_iconLoader;

    mutable TDEHardwareDevices  *_hardwaredevices;
    mutable TDEGlobalNetworkManager  *_networkmanager;
    mutable void                *_placeholder;

    TQCString                     _name;
    const KAboutData            *_aboutData;

protected:
    virtual void virtual_hook( int id, void* data );
private:
    KInstancePrivate *d;
    bool m_configReadOnly;
};

#endif