00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _KXMLGUICLIENT_H
00020 #define _KXMLGUICLIENT_H
00021
00022 #include <tqdom.h>
00023 #include <tqptrlist.h>
00024 #include <tqmap.h>
00025 #include <tqstringlist.h>
00026
00027 #include <tdelibs_export.h>
00028
00029 class TQWidget;
00030 class TDEAction;
00031 class TDEActionCollection;
00032 class TDEInstance;
00033 class KXMLGUIClientPrivate;
00034 class KXMLGUIFactory;
00035 class KXMLGUIBuilder;
00036
00043 class TDEUI_EXPORT KXMLGUIClient
00044 {
00045 friend class KEditToolbarWidget;
00046 public:
00052 KXMLGUIClient();
00053
00065 KXMLGUIClient( KXMLGUIClient *parent );
00066
00070 virtual ~KXMLGUIClient();
00071
00077 TDEAction* action( const char* name ) const;
00078
00084 virtual TDEAction *action( const TQDomElement &element ) const;
00085
00095 virtual TDEActionCollection* actionCollection() const;
00096
00100 virtual TDEInstance *instance() const;
00101
00107 virtual TQDomDocument domDocument() const;
00108
00122 virtual TQString xmlFile() const;
00123
00124 virtual TQString localXMLFile() const;
00125
00129 void setXMLGUIBuildDocument( const TQDomDocument &doc );
00133 TQDomDocument xmlguiBuildDocument() const;
00134
00139 void setFactory( KXMLGUIFactory *factory );
00145 KXMLGUIFactory *factory() const;
00146
00152 KXMLGUIClient *parentClient() const;
00153
00160 void insertChildClient( KXMLGUIClient *child );
00161
00165 void removeChildClient( KXMLGUIClient *child );
00166
00170 const TQPtrList<KXMLGUIClient> *childClients();
00171
00180 void setClientBuilder( KXMLGUIBuilder *builder );
00181
00186 KXMLGUIBuilder *clientBuilder() const;
00187
00195 void reloadXML();
00196
00237 void plugActionList( const TQString &name, const TQPtrList<TDEAction> &actionList );
00238
00242 void unplugActionList( const TQString &name );
00243
00244 static TQString findMostRecentXMLFile( const TQStringList &files, TQString &doc );
00245
00246 void addStateActionEnabled(const TQString& state, const TQString& action);
00247
00248 void addStateActionDisabled(const TQString& state, const TQString& action);
00249
00250 enum ReverseStateChange { StateNoReverse, StateReverse };
00251 struct StateChange
00252 {
00253 TQStringList actionsToEnable;
00254 TQStringList actionsToDisable;
00255 };
00256
00257 StateChange getActionsToChangeForState(const TQString& state);
00258
00260 void beginXMLPlug( TQWidget * );
00262 void endXMLPlug();
00264 void prepareXMLUnplug( TQWidget * );
00265
00266 protected:
00271
00272
00279 virtual void setInstance( TDEInstance *instance );
00280
00294 virtual void setXMLFile( const TQString& file, bool merge = false, bool setXMLDoc = true );
00295
00296 virtual void setLocalXMLFile( const TQString &file );
00297
00304 virtual void setXML( const TQString &document, bool merge = false );
00305
00312 virtual void setDOMDocument( const TQDomDocument &document, bool merge = false );
00313
00319 virtual void conserveMemory();
00320
00332 virtual void stateChanged(const TQString &newstate, ReverseStateChange reverse = StateNoReverse);
00333
00334
00335
00336
00337 private:
00338 struct DocStruct
00339 {
00340 TQString file;
00341 TQString data;
00342 };
00343
00344 bool mergeXML( TQDomElement &base, const TQDomElement &additive,
00345 TDEActionCollection *actionCollection );
00346
00347 TQDomElement findMatchingElement( const TQDomElement &base,
00348 const TQDomElement &additive );
00349
00350 typedef TQMap<TQString, TQMap<TQString, TQString> > ActionPropertiesMap;
00351
00352 static ActionPropertiesMap extractActionProperties( const TQDomDocument &doc );
00353
00354 static void storeActionProperties( TQDomDocument &doc, const ActionPropertiesMap &properties );
00355
00356 static TQString findVersionNumber( const TQString &_xml );
00357
00358
00359 TQMap<TQString,StateChange> m_actionsStateMap;
00360
00361 protected:
00362 virtual void virtual_hook( int id, void* data );
00363 private:
00364 KXMLGUIClientPrivate *d;
00365 };
00366
00367 #endif