• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kdeui

kdcopactionproxy.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kdcopactionproxy.h"
00021 
00022 #include <dcopclient.h>
00023 #include <kapplication.h>
00024 #include <kaction.h>
00025 #include <kdebug.h>
00026 #include <kdcoppropertyproxy.h>
00027 
00028 #include <ctype.h>
00029 
00030 class KDCOPActionProxy::KDCOPActionProxyPrivate
00031 {
00032 public:
00033   KDCOPActionProxyPrivate()
00034   {
00035   }
00036   ~KDCOPActionProxyPrivate()
00037   {
00038   }
00039 
00040   KActionCollection *m_actionCollection;
00041   DCOPObject *m_parent;
00042   QCString m_prefix;
00043   int m_pos;
00044 };
00045 
00046 KDCOPActionProxy::KDCOPActionProxy( KActionCollection *actionCollection, DCOPObject *parent )
00047 {
00048   init( actionCollection, parent );
00049 }
00050 
00051 KDCOPActionProxy::KDCOPActionProxy( DCOPObject *parent )
00052 {
00053   init( 0, parent );
00054 }
00055 
00056 void KDCOPActionProxy::init( KActionCollection *collection, DCOPObject *parent )
00057 {
00058   d = new KDCOPActionProxyPrivate;
00059   d->m_actionCollection = collection;
00060   d->m_parent = parent;
00061   d->m_prefix = parent->objId() + "/action/";
00062   d->m_pos = d->m_prefix.length();
00063 }
00064 
00065 KDCOPActionProxy::~KDCOPActionProxy()
00066 {
00067   delete d;
00068 }
00069 
00070 QValueList<KAction *>KDCOPActionProxy::actions() const
00071 {
00072   if ( !d->m_actionCollection )
00073     return QValueList<KAction *>();
00074 
00075   return d->m_actionCollection->actions();
00076 }
00077 
00078 KAction *KDCOPActionProxy::action( const char *name ) const
00079 {
00080   if ( !d->m_actionCollection )
00081     return 0;
00082 
00083   return d->m_actionCollection->action( name );
00084 }
00085 
00086 QCString KDCOPActionProxy::actionObjectId( const QCString &name ) const
00087 {
00088   return d->m_prefix + name;
00089 }
00090 
00091 QMap<QCString,DCOPRef> KDCOPActionProxy::actionMap( const QCString &appId ) const
00092 {
00093   QMap<QCString,DCOPRef> res;
00094 
00095   QCString id = appId;
00096   if ( id.isEmpty() )
00097     id = kapp->dcopClient()->appId();
00098 
00099   QValueList<KAction *> lst = actions();
00100   QValueList<KAction *>::ConstIterator it = lst.begin();
00101   QValueList<KAction *>::ConstIterator end = lst.end();
00102   for (; it != end; ++it )
00103     res.insert( (*it)->name(), DCOPRef( id, actionObjectId( (*it)->name() ) ) );
00104 
00105   return res;
00106 }
00107 
00108 bool KDCOPActionProxy::process( const QCString &obj, const QCString &fun, const QByteArray &data,
00109                                 QCString &replyType, QByteArray &replyData )
00110 {
00111   if ( obj.left( d->m_pos ) != d->m_prefix )
00112     return false;
00113 
00114   KAction *act = action( obj.mid( d->m_pos ) );
00115   if ( !act )
00116     return false;
00117 
00118   return processAction( obj, fun, data, replyType, replyData, act );
00119 }
00120 
00121 bool KDCOPActionProxy::processAction( const QCString &, const QCString &fun, const QByteArray &data,
00122                                       QCString &replyType, QByteArray &replyData, KAction *action )
00123 {
00124   if ( fun == "activate()" )
00125   {
00126     replyType = "void";
00127     action->activate();
00128     return true;
00129   }
00130 
00131   if ( fun == "isPlugged()" )
00132   {
00133     replyType = "bool";
00134     QDataStream reply( replyData, IO_WriteOnly );
00135     reply << (Q_INT8)action->isPlugged();
00136     return true;
00137   }
00138 
00139   if ( fun == "functions()" )
00140   {
00141     QValueList<QCString> res;
00142     res << "QCStringList functions()";
00143     res << "void activate()";
00144     res << "bool isPlugged()";
00145 
00146     res += KDCOPPropertyProxy::functions( action );
00147 
00148     replyType = "QCStringList";
00149     QDataStream reply( replyData, IO_WriteOnly );
00150     reply << res;
00151     return true;
00152   }
00153 
00154   return KDCOPPropertyProxy::processPropertyRequest( fun, data, replyType, replyData, action );
00155 }
00156 
00157 void KDCOPActionProxy::virtual_hook( int id, void* data )
00158 { DCOPObjectProxy::virtual_hook( id, data ); }
00159 

kdeui

Skip menu "kdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal