summaryrefslogtreecommitdiffstats
path: root/kivio/kiviopart/KIvioMapIface.cpp
blob: 99397692e7aa58156c58123211dac67700790705 (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
/* This file is part of the KDE project
   Copyright (C) 2002 Laurent MONTEL <lmontel@mandrakesoft.com>

   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 "KIvioMapIface.h"

#include "kivio_map.h"
#include "kivio_doc.h"
#include "kivio_page.h"

#include <tdeapplication.h>
#include <dcopclient.h>
#include <kdebug.h>

KIvioMapIface::KIvioMapIface( KivioMap* map )
    : DCOPObject( map )
{
    m_map = map;
}

DCOPRef KIvioMapIface::page( const TQString& name )
{
    KivioPage* t = m_map->findPage( name );
    if ( !t )
        return DCOPRef();

    return DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
}

DCOPRef KIvioMapIface::pageByIndex( int index )
{
    KivioPage* t = m_map->pageList().at( index );
    if ( !t )
    {
        kdDebug(43000) << "+++++ No page found at index " << index << endl;
        return DCOPRef();
    }

    kdDebug(43000) << "+++++++ Returning page " << t->TQObject::name() << endl;

    return DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
}

int KIvioMapIface::pageCount() const
{
    return m_map->count();
}

TQStringList KIvioMapIface::pageNames() const
{
    TQStringList names;

    TQPtrList<KivioPage>& lst = m_map->pageList();
    TQPtrListIterator<KivioPage> it( lst );
    for( ; it.current(); ++it )
        names.append( it.current()->name() );

    return names;
}

TQValueList<DCOPRef> KIvioMapIface::pages()
{
    TQValueList<DCOPRef> t;

    TQPtrList<KivioPage>& lst = m_map->pageList();
    TQPtrListIterator<KivioPage> it( lst );
    for( ; it.current(); ++it )
        t.append( DCOPRef( kapp->dcopClient()->appId(), it.current()->dcopObject()->objId() ) );

    return t;
}

DCOPRef KIvioMapIface::insertPage( const TQString& name )
{
    if ( m_map->findPage( name ) )
        return page( name );

    KivioPage* t = new KivioPage( m_map, name );
    t->setPageName( name );
    m_map->doc()->addPage( t );

    return page( name );
}

bool KIvioMapIface::processDynamic(const TQCString &fun, const TQByteArray &/*data*/,
                                     TQCString& replyType, TQByteArray &replyData)
{
    // Does the name follow the pattern "foobar()" ?
    uint len = fun.length();
    if ( len < 3 )
        return false;

    if ( fun[ len - 1 ] != ')' || fun[ len - 2 ] != '(' )
        return false;

    KivioPage* t = m_map->findPage( fun.left( len - 2 ).data() );
    if ( !t )
        return false;

    replyType = "DCOPRef";
    TQDataStream out( replyData, IO_WriteOnly );
    out << DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
    return true;
}