1 /* This file is part of the KDE libraries 2 Copyright (C) 1999 Torben Weis <weis@kde.org> 3 Copyright (C) 2007 Matthias Kretz <kretz@kde.org> 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Library General Public 7 License version 2 as published by the Free Software Foundation. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public License 15 along with this library; see the file COPYING.LIB. If not, write to 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Boston, MA 02110-1301, USA. 18 */ 19 #ifndef KCOMPONENTDATA_H 20 #define KCOMPONENTDATA_H 21 22 #include <kdelibs4support_export.h> 23 24 #ifdef KDELIBS4SUPPORT_NO_DEPRECATED_NOISE 25 #warning "This file is deprecated." 26 #endif 27 28 #include <ksharedconfig.h> 29 #include <kaboutdata.h> 30 31 class QByteArray; 32 class QString; 33 class K4AboutData; 34 class KComponentDataPrivate; 35 36 /** 37 * @short Per component data. 38 * 39 * This class holds a K4AboutData object or only a component name, and a KSharedConfig object. 40 * Those objects normally are different per component but the same per 41 * instance of one component. 42 * 43 * The application component data can always be accessed using KComponentData::mainComponent() (or the 44 * convenience function KGlobal::dirs() and KSharedConfig::openConfig()) while the 45 * component data of the currently active component (mainly used for KParts) can be accessed using 46 * KGlobal::activeComponent(). 47 * 48 * @note This class has been deprecated, you should port code away from it; 49 * see https://community.kde.org/Frameworks/Porting_Notes#KComponentData for porting notes. 50 * 51 * @author Torben Weis 52 * @author Matthias Kretz <kretz@kde.org> 53 */ 54 class KDELIBS4SUPPORT_DEPRECATED_EXPORT_NOISE KComponentData // krazy:exclude=dpointer (implicitly shared) 55 { 56 public: 57 /** 58 * Creates an invalid KComponentData object. 59 * 60 * @see isValid() 61 */ 62 KComponentData(); 63 64 /** 65 * Copy constructor. 66 * 67 * It does not copy the data. The data is shared between the old and new objects. 68 */ 69 KComponentData(const KComponentData &); 70 71 /** 72 * Assignment operator. 73 * 74 * It does not copy the data. The data is shared between the old and new objects. 75 * 76 * If the data of the left hand side object was only referenced 77 * from this object and no referenced KSharedConfig object needs 78 * it anymore, it is deleted 79 */ 80 KComponentData &operator=(const KComponentData &); 81 82 /** 83 * Returns whether two KComponentData objects reference the same data. 84 */ 85 bool operator==(const KComponentData &) const; 86 87 /** 88 * Returns whether two KComponentData objects do not reference the same data. 89 */ 90 bool operator!=(const KComponentData &rhs) const; 91 92 enum MainComponentRegistration { 93 RegisterAsMainComponent, 94 SkipMainComponentRegistration 95 }; 96 97 /** 98 * Constructor. 99 * 100 * @param componentName the name of the component. 101 * @param catalogName the name of the translation catalog; 102 * if left empty @p componentName is used 103 * @param registerAsMain whether to register the component as the main component 104 * of the application. This has no effect, if the application 105 * already has a main component. 106 * @see KComponentData::mainComponent 107 */ 108 KDELIBS4SUPPORT_DEPRECATED explicit KComponentData(const QByteArray &componentName, const QByteArray &catalogName = QByteArray(), 109 MainComponentRegistration registerAsMain = RegisterAsMainComponent); 110 111 /** 112 * Constructor. 113 * 114 * A copy of the aboutData object is made. 115 * 116 * @param aboutData data about this component 117 * @param registerAsMain whether to register the component as the main component 118 * of the application. This has no effect, if the application 119 * already has a main component. 120 * @see KComponentData::mainComponent 121 * 122 * @see K4AboutData 123 */ 124 KDELIBS4SUPPORT_DEPRECATED explicit KComponentData(const K4AboutData &aboutData, MainComponentRegistration registerAsMain = RegisterAsMainComponent); 125 KDELIBS4SUPPORT_DEPRECATED explicit KComponentData(const K4AboutData *aboutData, MainComponentRegistration registerAsMain = RegisterAsMainComponent); 126 127 /** 128 * Destructor. 129 */ 130 virtual ~KComponentData(); 131 132 /** 133 * Implicit conversion to KAboutData, to be able to call setComponentData(myComponentData) 134 * even if the method is now setComponentData(const KAboutData &) 135 */ 136 operator KAboutData() const; 137 138 /** 139 * Returns whether this is a valid object. 140 * 141 * Don't call any functions on invalid objects, that will crash. Assignment (and of course 142 * destruction) is the only valid operation you may do. 143 */ 144 bool isValid() const; 145 146 /** 147 * Returns the general config object ("appnamerc"). 148 * @return the KConfig object for the component. 149 */ 150 const KSharedConfig::Ptr &config() const; //krazy:exclude=constref 151 152 /** 153 * Returns the about data of this component. 154 * 155 * @return The about data of the component. If none has been set in the 156 * constructor but a component name was set, a default constructed 157 * K4AboutData object is returned. 158 */ 159 KDELIBS4SUPPORT_DEPRECATED const K4AboutData *aboutData() const; 160 161 /** 162 * Sets the about data of this component. 163 * 164 * @since 4.5 165 */ 166 KDELIBS4SUPPORT_DEPRECATED void setAboutData(const K4AboutData &aboutData); 167 168 /** 169 * Returns the name of the component. 170 * 171 * @return The component name. 172 */ 173 QString componentName() const; 174 175 /** 176 * Returns the name of the translation catalog. 177 * 178 * @return The catalog name. 179 */ 180 QString catalogName() const; 181 182 /** 183 * @internal 184 * Returns whether a main KComponentData is available. 185 * @since 5.0 186 */ 187 static bool hasMainComponent(); 188 189 /** 190 * Returns the global component data, if one was set. 191 * @since 5.0 192 */ 193 static const KComponentData &mainComponent(); //krazy:exclude=constref (don't mess up ref-counting) 194 195 /** 196 * The component currently active (useful in a multi-component 197 * application, such as a KParts application). 198 * Don't use this - it was mainly for KAboutDialog and KBugReport. 199 * 200 * They now use KAboutData::applicationData() by default, or a specific KAboutData can be given 201 * to them. KHelpMenu always creates them with the application data. 202 * So this is now obsolete, the about-app and bug-report dialog simply use the app data 203 * rather than the active plugin data. 204 * 205 * @internal 206 * @since 5.0 (moved from KGlobal, but later on KComponentData was deprecated anyway) 207 */ 208 static const KComponentData &activeComponent(); //krazy:exclude=constref (don't mess up ref-counting) 209 210 /** 211 * Set the active component for use by KAboutDialog and KBugReport. 212 * To be used only by a multi-component (KParts) application. 213 * 214 * Since 5.0, KAboutDialog and KBugReport don't look at this anymore, 215 * so consider just removing the call. See activeComponent() for more details. 216 * 217 * @see activeComponent() 218 * @since 5.0 (moved from KGlobal, but later on KComponentData was deprecated anyway) 219 */ 220 static void setActiveComponent(const KComponentData &d); 221 222 protected: 223 friend class KApplicationPrivate; 224 225 /** 226 * Set name of default config file. 227 * @param name the name of the default config file 228 */ 229 void setConfigName(const QString &name); 230 231 /** Standard trick to add virtuals later. @internal */ 232 virtual void virtual_hook(int id, void *data); 233 234 private: 235 // Ref-counted data 236 KComponentDataPrivate *d; 237 friend class KComponentDataPrivate; 238 }; 239 240 #endif // KCOMPONENTDATA_H 241