lib

KoPartSelectAction.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 2001 David Faure <faure@kde.org>
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 version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17*/
18
19#include "KoPartSelectAction.h"
20#include "KoPartSelectDia.h"
21
22#include <kdebug.h>
23
24KoPartSelectAction::KoPartSelectAction( const TQString& text, TQObject* parent, const char* name )
25 : TDEActionMenu( text, parent, name )
26{
27 init();
28}
29
30KoPartSelectAction::KoPartSelectAction( const TQString& text, const TQString& icon,
31 TQObject* parent, const char* name )
32 : TDEActionMenu( text, icon, parent, name )
33{
34 init();
35}
36
37KoPartSelectAction::KoPartSelectAction( const TQString& text, const TQString& icon,
38 TQObject* receiver, const char* slot,
39 TQObject* parent, const char* name )
40 : TDEActionMenu( text, icon, parent, name )
41{
42 if (receiver)
43 connect( this, TQ_SIGNAL( activated() ), receiver, slot );
44 init();
45}
46
47void KoPartSelectAction::init()
48{
49 // Query for documents
50 m_lstEntries = KoDocumentEntry::query();
51 TQValueList<KoDocumentEntry>::Iterator it = m_lstEntries.begin();
52 for( ; it != m_lstEntries.end(); ++it ) {
53 KService::Ptr serv = (*it).service();
54 if (!serv->genericName().isEmpty()) {
55 TDEAction *action = new TDEAction( serv->genericName().replace('&',"&&"), serv->icon(), 0,
56 this, TQ_SLOT( slotActionActivated() ),
57 parentCollection(), serv->name().latin1() );
58 insert( action );
59 }
60 }
61
62}
63
64// Called when selecting a part
65void KoPartSelectAction::slotActionActivated()
66{
67 TQString servName = TQString::fromLatin1( sender()->name() );
68 KService::Ptr serv = KService::serviceByName( servName );
69 m_documentEntry = KoDocumentEntry( serv );
70 emit activated();
71}
72
73// Called when activating the toolbar button
74void KoPartSelectAction::slotActivated()
75{
76 m_documentEntry = KoPartSelectDia::selectPart( 0L );
77 emit activated();
78}
79
80#include "KoPartSelectAction.moc"
static TQValueList< KoDocumentEntry > query(const TQString &_constr=TQString())
This function will query tdesycoca to find all available components.
static KoDocumentEntry selectPart(TQWidget *parent=0L)
Convenience function for using the dialog.
TDEAction(const TQString &text, const TDEShortcut &cut, const TQObject *receiver, const char *slot, TDEActionCollection *parent, const char *name)
void activated()
TDEAction * action(StdAction act_enum, const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0L)
const char * name(StdAction id)