1/* This file is part of the KDE project
2 Copyright (C) 2000 David Faure <faure@kde.org>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program 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
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "kserviceselectdlg.h"
19#include "kserviceselectdlg.moc"
20#include "kservicelistwidget.h"
21
22#include <klocale.h>
23#include <QVBoxLayout>
24#include <QLabel>
25
26KServiceSelectDlg::KServiceSelectDlg( const QString& /*serviceType*/, const QString& /*value*/, QWidget *parent )
27 : KDialog( parent )
28{
29 setObjectName( QLatin1String( "serviceSelectDlg" ) );
30 setModal( true );
31 setCaption( i18n( "Add Service" ) );
32 setButtons( Ok | Cancel );
33
34 QWidget *vbox = new QWidget( this );
35 QVBoxLayout *layout = new QVBoxLayout( vbox );
36
37 layout->addWidget( new QLabel( i18n( "Select service:" ), vbox ) );
38 m_listbox=new KListWidget( vbox );
39
40 // Can't make a KTrader query since we don't have a servicetype to give,
41 // we want all services that are not applications.......
42 // So we have to do it the slow way
43 // ### Why can't we query for KParts/ReadOnlyPart as the servicetype? Should work fine!
44 const KService::List allServices = KService::allServices();
45 KService::List::const_iterator it(allServices.constBegin());
46 for ( ; it != allServices.constEnd() ; ++it )
47 if ( (*it)->hasServiceType( "KParts/ReadOnlyPart" ) )
48 {
49 m_listbox->addItem( new KServiceListItem( (*it), KServiceListWidget::SERVICELIST_SERVICES ) );
50 }
51
52 m_listbox->model()->sort(0);
53 m_listbox->setMinimumHeight(350);
54 m_listbox->setMinimumWidth(400);
55 layout->addWidget( m_listbox );
56 connect(m_listbox,SIGNAL(itemDoubleClicked(QListWidgetItem*)),SLOT(slotOk()));
57 connect( this, SIGNAL(okClicked()), this, SLOT(slotOk()) );
58 setMainWidget(vbox);
59}
60
61KServiceSelectDlg::~KServiceSelectDlg()
62{
63}
64
65void KServiceSelectDlg::slotOk()
66{
67 accept();
68}
69
70KService::Ptr KServiceSelectDlg::service()
71{
72 int selIndex = m_listbox->currentRow();
73 KServiceListItem *selItem = static_cast<KServiceListItem *>(m_listbox->item(selIndex));
74 return KService::serviceByDesktopPath( selItem->desktopPath );
75}
76