kivio

KIvioMapIface.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002 Laurent MONTEL <lmontel@mandrakesoft.com>
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 "KIvioMapIface.h"
00021 
00022 #include "kivio_map.h"
00023 #include "kivio_doc.h"
00024 #include "kivio_page.h"
00025 
00026 #include <kapplication.h>
00027 #include <dcopclient.h>
00028 #include <kdebug.h>
00029 
00030 KIvioMapIface::KIvioMapIface( KivioMap* map )
00031     : DCOPObject( map )
00032 {
00033     m_map = map;
00034 }
00035 
00036 DCOPRef KIvioMapIface::page( const QString& name )
00037 {
00038     KivioPage* t = m_map->findPage( name );
00039     if ( !t )
00040         return DCOPRef();
00041 
00042     return DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
00043 }
00044 
00045 DCOPRef KIvioMapIface::pageByIndex( int index )
00046 {
00047     KivioPage* t = m_map->pageList().at( index );
00048     if ( !t )
00049     {
00050         kdDebug(43000) << "+++++ No page found at index " << index << endl;
00051         return DCOPRef();
00052     }
00053 
00054     kdDebug(43000) << "+++++++ Returning page " << t->QObject::name() << endl;
00055 
00056     return DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
00057 }
00058 
00059 int KIvioMapIface::pageCount() const
00060 {
00061     return m_map->count();
00062 }
00063 
00064 QStringList KIvioMapIface::pageNames() const
00065 {
00066     QStringList names;
00067 
00068     QPtrList<KivioPage>& lst = m_map->pageList();
00069     QPtrListIterator<KivioPage> it( lst );
00070     for( ; it.current(); ++it )
00071         names.append( it.current()->name() );
00072 
00073     return names;
00074 }
00075 
00076 QValueList<DCOPRef> KIvioMapIface::pages()
00077 {
00078     QValueList<DCOPRef> t;
00079 
00080     QPtrList<KivioPage>& lst = m_map->pageList();
00081     QPtrListIterator<KivioPage> it( lst );
00082     for( ; it.current(); ++it )
00083         t.append( DCOPRef( kapp->dcopClient()->appId(), it.current()->dcopObject()->objId() ) );
00084 
00085     return t;
00086 }
00087 
00088 DCOPRef KIvioMapIface::insertPage( const QString& name )
00089 {
00090     if ( m_map->findPage( name ) )
00091         return page( name );
00092 
00093     KivioPage* t = new KivioPage( m_map, name );
00094     t->setPageName( name );
00095     m_map->doc()->addPage( t );
00096 
00097     return page( name );
00098 }
00099 
00100 bool KIvioMapIface::processDynamic(const QCString &fun, const QByteArray &/*data*/,
00101                                      QCString& replyType, QByteArray &replyData)
00102 {
00103     // Does the name follow the pattern "foobar()" ?
00104     uint len = fun.length();
00105     if ( len < 3 )
00106         return false;
00107 
00108     if ( fun[ len - 1 ] != ')' || fun[ len - 2 ] != '(' )
00109         return false;
00110 
00111     KivioPage* t = m_map->findPage( fun.left( len - 2 ).data() );
00112     if ( !t )
00113         return false;
00114 
00115     replyType = "DCOPRef";
00116     QDataStream out( replyData, IO_WriteOnly );
00117     out << DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
00118     return true;
00119 }
KDE Home | KDE Accessibility Home | Description of Access Keys