1 /* This file is part of the KDE project
2 Copyright (C) 2000 David Faure <faure@kde.org>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License version 2 as published by the Free Software Foundation.
8 This program 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 General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; see the file COPYING. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "kserviceselectdlg.h"
20 #include "kserviceselectdlg.moc"
21 #include "kservicelistwidget.h"
25 #include <QtGui/QLabel>
27 KServiceSelectDlg::KServiceSelectDlg( const QString
& /*serviceType*/, const QString
& /*value*/, QWidget
*parent
)
30 setObjectName( "serviceSelectDlg" );
32 setCaption( i18n( "Add Service" ) );
33 setButtons( Ok
| Cancel
);
35 KVBox
*vbox
= new KVBox ( this );
37 vbox
->setSpacing( KDialog::spacingHint() );
38 new QLabel( i18n( "Select service:" ), vbox
);
39 m_listbox
=new KListWidget( vbox
);
41 // Can't make a KTrader query since we don't have a servicetype to give,
42 // we want all services that are not applications.......
43 // So we have to do it the slow way
44 // ### Why can't we query for KParts/ReadOnlyPart as the servicetype? Should work fine!
45 KService::List allServices
= KService::allServices();
46 KService::List::const_iterator
it(allServices
.begin());
47 for ( ; it
!= allServices
.end() ; ++it
)
48 if ( (*it
)->hasServiceType( "KParts/ReadOnlyPart" ) )
50 m_listbox
->addItem( new KServiceListItem( (*it
), KServiceListWidget::SERVICELIST_SERVICES
) );
53 m_listbox
->model()->sort(0);
54 m_listbox
->setMinimumHeight(350);
55 m_listbox
->setMinimumWidth(300);
56 connect(m_listbox
,SIGNAL(itemDoubleClicked(QListWidgetItem
*)),SLOT(slotOk()));
57 connect( this, SIGNAL(okClicked()), this, SLOT(slotOk()) );
61 KServiceSelectDlg::~KServiceSelectDlg()
65 void KServiceSelectDlg::slotOk()
70 KService::Ptr
KServiceSelectDlg::service()
72 int selIndex
= m_listbox
->currentRow();
73 KServiceListItem
*selItem
= static_cast<KServiceListItem
*>(m_listbox
->item(selIndex
));
74 return KService::serviceByDesktopPath( selItem
->desktopPath
);