summaryrefslogtreecommitdiffstats
path: root/tdeui/kdcopactionproxy.cpp
blob: c8444cfdff8739254169876fd763ae19e26cb31e (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
/* 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.
*/

#include "kdcopactionproxy.h"

#include <dcopclient.h>
#include <kapplication.h>
#include <tdeaction.h>
#include <kdebug.h>
#include <kdcoppropertyproxy.h>

#include <ctype.h>

class KDCOPActionProxy::KDCOPActionProxyPrivate
{
public:
  KDCOPActionProxyPrivate()
  {
  }
  ~KDCOPActionProxyPrivate()
  {
  }

  TDEActionCollection *m_actionCollection;
  DCOPObject *m_parent;
  TQCString m_prefix;
  int m_pos;
};

KDCOPActionProxy::KDCOPActionProxy( TDEActionCollection *actionCollection, DCOPObject *parent )
{
  init( actionCollection, parent );
}

KDCOPActionProxy::KDCOPActionProxy( DCOPObject *parent )
{
  init( 0, parent );
}

void KDCOPActionProxy::init( TDEActionCollection *collection, DCOPObject *parent )
{
  d = new KDCOPActionProxyPrivate;
  d->m_actionCollection = collection;
  d->m_parent = parent;
  d->m_prefix = parent->objId() + "/action/";
  d->m_pos = d->m_prefix.length();
}

KDCOPActionProxy::~KDCOPActionProxy()
{
  delete d;
}

TQValueList<TDEAction *>KDCOPActionProxy::actions() const
{
  if ( !d->m_actionCollection )
    return TQValueList<TDEAction *>();

  return d->m_actionCollection->actions();
}

TDEAction *KDCOPActionProxy::action( const char *name ) const
{
  if ( !d->m_actionCollection )
    return 0;

  return d->m_actionCollection->action( name );
}

TQCString KDCOPActionProxy::actionObjectId( const TQCString &name ) const
{
  return d->m_prefix + name;
}

TQMap<TQCString,DCOPRef> KDCOPActionProxy::actionMap( const TQCString &appId ) const
{
  TQMap<TQCString,DCOPRef> res;

  TQCString id = appId;
  if ( id.isEmpty() )
    id = kapp->dcopClient()->appId();

  TQValueList<TDEAction *> lst = actions();
  TQValueList<TDEAction *>::ConstIterator it = lst.begin();
  TQValueList<TDEAction *>::ConstIterator end = lst.end();
  for (; it != end; ++it )
    res.insert( (*it)->name(), DCOPRef( id, actionObjectId( (*it)->name() ) ) );

  return res;
}

bool KDCOPActionProxy::process( const TQCString &obj, const TQCString &fun, const TQByteArray &data,
                                TQCString &replyType, TQByteArray &replyData )
{
  if ( obj.left( d->m_pos ) != d->m_prefix )
    return false;

  TDEAction *act = action( obj.mid( d->m_pos ) );
  if ( !act )
    return false;

  return processAction( obj, fun, data, replyType, replyData, act );
}

bool KDCOPActionProxy::processAction( const TQCString &, const TQCString &fun, const TQByteArray &data,
                                      TQCString &replyType, TQByteArray &replyData, TDEAction *action )
{
  if ( fun == "activate()" )
  {
    replyType = "void";
    action->activate();
    return true;
  }

  if ( fun == "isPlugged()" )
  {
    replyType = "bool";
    TQDataStream reply( replyData, IO_WriteOnly );
    reply << (TQ_INT8)action->isPlugged();
    return true;
  }

  if ( fun == "functions()" )
  {
    TQValueList<TQCString> res;
    res << "QCStringList functions()";
    res << "void activate()";
    res << "bool isPlugged()";

    res += KDCOPPropertyProxy::functions( action );

    replyType = "QCStringList";
    TQDataStream reply( replyData, IO_WriteOnly );
    reply << res;
    return true;
  }

  return KDCOPPropertyProxy::processPropertyRequest( fun, data, replyType, replyData, action );
}

void KDCOPActionProxy::virtual_hook( int id, void* data )
{ DCOPObjectProxy::virtual_hook( id, data ); }