summaryrefslogtreecommitdiffstats
path: root/tdeui/kdcopactionproxy.h
blob: 5b0ffdc1cdaca594309c1a6104e2f86253a261ab (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
/* This file is part of the KDE project
   Copyright (C) 1999 Simon Hausmann <hausmann@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 as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   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 __kdcopactionproxy_h__
#define __kdcopactionproxy_h__

#include <dcopobject.h>
#include <dcopref.h>
#include <kdelibs_export.h>

class KActionCollection;
class KAction;

/**
 * @short A proxy class publishing a DCOP interface for actions.
 *
 * The KDCOPActionProxy class provides an easy way to publish a collection of KAction objects
 * through DCOP. For the DCOP client the exported actions behave like full-fledged DCOP objects,
 * providing full access to the KAction object functionality in the server.
 *
 * This class can generate DCOP object ids for given action objects, which it automatically
 * processes, as being a DCOPObjectProxy .
 */
class KDEUI_EXPORT KDCOPActionProxy : public DCOPObjectProxy
{
public:
  /**
   * Constructs a dcop action proxy, being able to export the actions of the provided
   * KActionCollection through DCOP, using the parent DCOPObject's object id to
   * generate unique object ids for the actions.
   */
  KDCOPActionProxy( KActionCollection *actionCollection, DCOPObject *parent );
  /**
   * Use this constructor if do not want to provide the exportable actions through a
   * KActionCollection . You have to reimplement the virtual actions() and
   * action() methods if you use this constructor.
   */
  KDCOPActionProxy( DCOPObject *parent );
  /**
   * Destructor.
   */
  ~KDCOPActionProxy();

  /**
   * Returns a list of exportable actions. The default implementation returns a list of actions
   * provided by a KActionCollection, if the first constructor has been used.
   */
  virtual TQValueList<KAction *> actions() const;
  /**
   * Returns an action object with the given name. The default implementation queries the action object
   * from the KActionCollection, if the first constructor has been used.
   */
  virtual KAction *action( const char *name ) const;

  /**
   * Use this method to retrieve a DCOP object id for an action with the given name.
   * This class automatically takes care of processing DCOP object requests for the returned
   * object id.
   *
   * You can construct a global DCOP object referenence using DCOPRef. For example like
   * DCOPRef( kapp->dcopClient()->appId, actionProxy->actionObjectId( actionName ) );
   *
   * The action with the given name has to be available through the #action method.
   */
  virtual TQCString actionObjectId( const TQCString &name ) const;

  /**
   * Returns a map of all exported actions, with the action name as keys and a global DCOP reference
   * as data entries.
   * The appId argument is used to specify the appid component of the DCOP reference. By default the
   * global application id is used ( kapp->dcopClient()->appId() ) .
   */
  virtual TQMap<TQCString,DCOPRef> actionMap( const TQCString &appId = TQCString() ) const;

  /**
   * Internal reimplementation of DCOPObjectProxy::process .
   */
  virtual bool process( const TQCString &obj, const TQCString &fun, const TQByteArray &data,
                        TQCString &replyType, TQByteArray &replyData );

  /**
   * Called by the #process method and takes care of processing the object request for an
   * action object.
   */
  virtual bool processAction( const TQCString &obj, const TQCString &fun, const TQByteArray &data,
                              TQCString &replyType, TQByteArray &replyData, KAction *action );
private:
  void init( KActionCollection *collection, DCOPObject *parent );

protected:
  virtual void virtual_hook( int id, void* data );
private:
  class KDCOPActionProxyPrivate;
  KDCOPActionProxyPrivate *d;
};

#endif