1
/***************************************************************************
2
* Copyright (C) 2003 by Mario Scalas *
3
* mario.scalas@libero.it *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
***************************************************************************/
12
#include <qlineedit.h>
13
#include <qtextedit.h>
14
#include <qpushbutton.h>
17
#include <qwhatsthis.h>
20
#include <klistview.h>
22
#include <kmessagebox.h>
24
#include <kcombobox.h>
25
#include <kservicetype.h>
27
#include "partexplorerformbase.h"
28
#include "partexplorerform.h"
30
///////////////////////////////////////////////////////////////////////////////
32
///////////////////////////////////////////////////////////////////////////////
33
namespace PartExplorer{
35
class PropertyItem : public KListViewItem
38
PropertyItem( KListViewItem *parent, const QString &propertyName,
39
const QString &propertyType, const QString &propertyValue )
40
: KListViewItem( parent )
42
setText( 0, propertyName );
43
setText( 1, propertyType );
44
setText( 2, propertyValue );
47
QString tipText() const
49
QString tip = i18n("Name: %1 | Type: %2 | Value: %3");
50
return tip.arg( text(0) ).arg( text(1) ).arg( text(2) );
55
///////////////////////////////////////////////////////////////////////////////
57
///////////////////////////////////////////////////////////////////////////////
61
class ResultsToolTip: public QToolTip
64
ResultsToolTip( ResultsList* parent );
65
virtual void maybeTip( const QPoint& p );
68
ResultsList* m_resultsList;
71
class ResultsList : public KListView
74
ResultsList( QWidget *parent )
75
: KListView( parent, "resultslist" )
77
this->setShowToolTips( false );
78
new ResultsToolTip( this );
81
virtual ~ResultsList() {}
89
ResultsToolTip::ResultsToolTip( ResultsList* parent )
90
: QToolTip( parent->viewport() ), m_resultsList( parent )
94
void ResultsToolTip::maybeTip( const QPoint& p )
96
PartExplorer::PropertyItem *item = dynamic_cast<PartExplorer::PropertyItem*>( m_resultsList->itemAt( p ) );
99
QRect r = m_resultsList->itemRect( item );
101
tip( r, item->tipText() );
106
///////////////////////////////////////////////////////////////////////////////
107
// class PartExplorerForm
108
///////////////////////////////////////////////////////////////////////////////
110
PartExplorerForm::PartExplorerForm( QWidget *parent )
111
: KDialogBase( parent, "parteplorerform", false,
112
i18n("Part Explorer - A Services Lister"), User1 | Close, User1, true )
114
m_base = new PartExplorerFormBase( this, "partexplorerformbase", 0 );
115
m_resultsList = new ResultsList( m_base );
116
m_resultsList->addColumn( i18n( "Property" ) );
117
m_resultsList->addColumn( i18n( "Type" ) );
118
m_resultsList->addColumn( i18n( "Value" ) );
119
m_resultsList->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3,
120
(QSizePolicy::SizeType)3, 0, 0,
121
m_resultsList->sizePolicy().hasHeightForWidth() ) );
122
QWhatsThis::add( m_resultsList, i18n("<b>Matching services</b><p>Results (if any) are shown grouped by matching service name.") );
123
m_base->resultsLabel->setBuddy(m_resultsList);
124
m_base->layout()->add( m_resultsList );
125
setMainWidget( m_base );
126
m_base->typeCombo->lineEdit()->setFocus();
129
setButtonText( User1, i18n("&Search") );
134
// connect( m_base->typeCombo->lineEdit(), SIGNAL(returnPressed()), this, SLOT(slotSearchRequested()) );
135
// connect( m_base->constraintsText, SIGNAL(returnPressed()), this, SLOT(slotSearchRequested()) );
137
connect( actionButton(User1), SIGNAL(clicked()), this, SLOT(slotSearchRequested()) );
138
// connect( m_base->typeCombo->lineEdit(), SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotServicetypeChanged( const QString& ) ) );
139
// slotServicetypeChanged( m_base->typeCombo->lineEdit()->text() );
141
// populating with all known servicetypes
142
KServiceType::List serviceList = KServiceType::allServiceTypes();
144
KServiceType::List::Iterator it = serviceList.begin();
145
while( it != serviceList.end() )
147
list << (*it)->name();
151
m_base->typeCombo->insertStringList( list );
154
///////////////////////////////////////////////////////////////////////////////
156
PartExplorerForm::~PartExplorerForm()
160
///////////////////////////////////////////////////////////////////////////////
162
void PartExplorerForm::slotSearchRequested()
164
QString serviceType = m_base->typeCombo->lineEdit()->text();
165
QString constraints = m_base->constraintsText->text();
167
kdDebug(9000) << "===> PartExplorerForm::slotSearchRequested(): " <<
168
" serviceType = " << serviceType << ", constraints = " << constraints << endl;
170
// Query for requested services
171
KTrader::OfferList foundServices = KTrader::self()->query( serviceType, constraints );
172
fillServiceList( foundServices );
175
///////////////////////////////////////////////////////////////////////////////
177
void PartExplorerForm::slotDisplayError( QString errorMessage )
179
if (errorMessage.isEmpty())
181
errorMessage = i18n("Unknown error.");
183
KMessageBox::error( this, errorMessage );
186
///////////////////////////////////////////////////////////////////////////////
188
void PartExplorerForm::fillServiceList( const KTrader::OfferList &services )
190
this->m_resultsList->clear();
192
if ( services.isEmpty())
194
slotDisplayError( i18n("No service found matching the criteria.") );
198
this->m_resultsList->setRootIsDecorated( true );
200
KListViewItem *rootItem = 0;
202
KTrader::OfferList::ConstIterator it = services.begin();
203
for ( ; it != services.end(); ++it )
205
KService::Ptr service = (*it);
206
KListViewItem *serviceItem = new KListViewItem( this->m_resultsList, rootItem, service->name() );
208
QStringList propertyNames = service->propertyNames();
209
for ( QStringList::const_iterator it = propertyNames.begin(); it != propertyNames.end(); ++it )
211
QString propertyName = (*it);
212
QVariant property = service->property( propertyName );
213
QString propertyType = property.typeName();
214
QString propertyValue;
215
if (propertyType == "QStringList") {
216
propertyValue = property.toStringList().join(", ");
219
propertyValue = property.toString();
222
QString dProperty = " *** Found property < %1, %2, %3 >";
223
dProperty = dProperty.arg( propertyName ).arg( propertyType ).arg( propertyValue );
224
kdDebug( 9000 ) << dProperty << endl;
226
new PartExplorer::PropertyItem( serviceItem, propertyName, propertyType, propertyValue );
231
#include "partexplorerform.moc"