kivio

KIvioMapIface.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Laurent MONTEL <lmontel@mandrakesoft.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "KIvioMapIface.h"
21
22#include "kivio_map.h"
23#include "kivio_doc.h"
24#include "kivio_page.h"
25
26#include <tdeapplication.h>
27#include <dcopclient.h>
28#include <kdebug.h>
29
30KIvioMapIface::KIvioMapIface( KivioMap* map )
31 : DCOPObject( map )
32{
33 m_map = map;
34}
35
36DCOPRef KIvioMapIface::page( const TQString& name )
37{
38 KivioPage* t = m_map->findPage( name );
39 if ( !t )
40 return DCOPRef();
41
42 return DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
43}
44
45DCOPRef KIvioMapIface::pageByIndex( int index )
46{
47 KivioPage* t = m_map->pageList().at( index );
48 if ( !t )
49 {
50 kdDebug(43000) << "+++++ No page found at index " << index << endl;
51 return DCOPRef();
52 }
53
54 kdDebug(43000) << "+++++++ Returning page " << t->TQObject::name() << endl;
55
56 return DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
57}
58
59int KIvioMapIface::pageCount() const
60{
61 return m_map->count();
62}
63
64TQStringList KIvioMapIface::pageNames() const
65{
66 TQStringList names;
67
68 TQPtrList<KivioPage>& lst = m_map->pageList();
69 TQPtrListIterator<KivioPage> it( lst );
70 for( ; it.current(); ++it )
71 names.append( it.current()->name() );
72
73 return names;
74}
75
76TQValueList<DCOPRef> KIvioMapIface::pages()
77{
78 TQValueList<DCOPRef> t;
79
80 TQPtrList<KivioPage>& lst = m_map->pageList();
81 TQPtrListIterator<KivioPage> it( lst );
82 for( ; it.current(); ++it )
83 t.append( DCOPRef( kapp->dcopClient()->appId(), it.current()->dcopObject()->objId() ) );
84
85 return t;
86}
87
88DCOPRef KIvioMapIface::insertPage( const TQString& name )
89{
90 if ( m_map->findPage( name ) )
91 return page( name );
92
93 KivioPage* t = new KivioPage( m_map, name );
94 t->setPageName( name );
95 m_map->doc()->addPage( t );
96
97 return page( name );
98}
99
100bool KIvioMapIface::processDynamic(const TQCString &fun, const TQByteArray &/*data*/,
101 TQCString& replyType, TQByteArray &replyData)
102{
103 // Does the name follow the pattern "foobar()" ?
104 uint len = fun.length();
105 if ( len < 3 )
106 return false;
107
108 if ( fun[ len - 1 ] != ')' || fun[ len - 2 ] != '(' )
109 return false;
110
111 KivioPage* t = m_map->findPage( fun.left( len - 2 ).data() );
112 if ( !t )
113 return false;
114
115 replyType = "DCOPRef";
116 TQDataStream out( replyData, IO_WriteOnly );
117 out << DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
118 return true;
119}