partexplorerform.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <qlineedit.h>
00013 #include <qtextedit.h>
00014 #include <qpushbutton.h>
00015 #include <qtooltip.h>
00016 #include <qlayout.h>
00017 #include <qwhatsthis.h>
00018 #include <qlabel.h>
00019
00020 #include <klistview.h>
00021 #include <klocale.h>
00022 #include <kmessagebox.h>
00023 #include <kdebug.h>
00024 #include <kcombobox.h>
00025 #include <kservicetype.h>
00026
00027 #include "partexplorerformbase.h"
00028 #include "partexplorerform.h"
00029
00031
00033 namespace PartExplorer{
00034
00035 class PropertyItem : public KListViewItem
00036 {
00037 public:
00038 PropertyItem( KListViewItem *parent, const QString &propertyName,
00039 const QString &propertyType, const QString &propertyValue )
00040 : KListViewItem( parent )
00041 {
00042 setText( 0, propertyName );
00043 setText( 1, propertyType );
00044 setText( 2, propertyValue );
00045 }
00046
00047 QString tipText() const
00048 {
00049 QString tip = i18n("Name: %1 | Type: %2 | Value: %3");
00050 return tip.arg( text(0) ).arg( text(1) ).arg( text(2) );
00051 }
00052 };
00053
00054 }
00056
00058
00059 class ResultList;
00060
00061 class ResultsToolTip: public QToolTip
00062 {
00063 public:
00064 ResultsToolTip( ResultsList* parent );
00065 virtual void maybeTip( const QPoint& p );
00066
00067 private:
00068 ResultsList* m_resultsList;
00069 };
00070
00071 class ResultsList : public KListView
00072 {
00073 public:
00074 ResultsList( QWidget *parent )
00075 : KListView( parent, "resultslist" )
00076 {
00077 this->setShowToolTips( false );
00078 new ResultsToolTip( this );
00079 }
00080
00081 virtual ~ResultsList() {}
00082
00083 void clear()
00084 {
00085 KListView::clear();
00086 }
00087 };
00088
00089 ResultsToolTip::ResultsToolTip( ResultsList* parent )
00090 : QToolTip( parent->viewport() ), m_resultsList( parent )
00091 {
00092 }
00093
00094 void ResultsToolTip::maybeTip( const QPoint& p )
00095 {
00096 PartExplorer::PropertyItem *item = dynamic_cast<PartExplorer::PropertyItem*>( m_resultsList->itemAt( p ) );
00097 if ( item )
00098 {
00099 QRect r = m_resultsList->itemRect( item );
00100 if ( r.isValid() )
00101 tip( r, item->tipText() );
00102 }
00103 }
00104
00105
00107
00109
00110 PartExplorerForm::PartExplorerForm( QWidget *parent )
00111 : KDialogBase( parent, "parteplorerform", false,
00112 i18n("Part Explorer - A Services Lister"), User1 | Close, User1, true )
00113 {
00114 m_base = new PartExplorerFormBase( this, "partexplorerformbase", 0 );
00115 m_resultsList = new ResultsList( m_base );
00116 m_resultsList->addColumn( i18n( "Property" ) );
00117 m_resultsList->addColumn( i18n( "Type" ) );
00118 m_resultsList->addColumn( i18n( "Value" ) );
00119 m_resultsList->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3,
00120 (QSizePolicy::SizeType)3, 0, 0,
00121 m_resultsList->sizePolicy().hasHeightForWidth() ) );
00122 QWhatsThis::add( m_resultsList, i18n("<b>Matching services</b><p>Results (if any) are shown grouped by matching service name.") );
00123 m_base->resultsLabel->setBuddy(m_resultsList);
00124 m_base->layout()->add( m_resultsList );
00125 setMainWidget( m_base );
00126 m_base->typeCombo->lineEdit()->setFocus();
00127
00128
00129 setButtonText( User1, i18n("&Search") );
00130
00131
00132 resize( 480, 512 );
00133
00134
00135
00136
00137 connect( actionButton(User1), SIGNAL(clicked()), this, SLOT(slotSearchRequested()) );
00138
00139
00140
00141
00142 KServiceType::List serviceList = KServiceType::allServiceTypes();
00143 QStringList list;
00144 KServiceType::List::Iterator it = serviceList.begin();
00145 while( it != serviceList.end() )
00146 {
00147 list << (*it)->name();
00148 ++it;
00149 }
00150 list.sort();
00151 m_base->typeCombo->insertStringList( list );
00152 }
00153
00155
00156 PartExplorerForm::~PartExplorerForm()
00157 {
00158 }
00159
00161
00162 void PartExplorerForm::slotSearchRequested()
00163 {
00164 QString serviceType = m_base->typeCombo->lineEdit()->text();
00165 QString constraints = m_base->constraintsText->text();
00166
00167 kdDebug(9000) << "===> PartExplorerForm::slotSearchRequested(): " <<
00168 " serviceType = " << serviceType << ", constraints = " << constraints << endl;
00169
00170
00171 KTrader::OfferList foundServices = KTrader::self()->query( serviceType, constraints );
00172 fillServiceList( foundServices );
00173 }
00174
00176
00177 void PartExplorerForm::slotDisplayError( QString errorMessage )
00178 {
00179 if (errorMessage.isEmpty())
00180 {
00181 errorMessage = i18n("Unknown error.");
00182 }
00183 KMessageBox::error( this, errorMessage );
00184 }
00185
00187
00188 void PartExplorerForm::fillServiceList( const KTrader::OfferList &services )
00189 {
00190 this->m_resultsList->clear();
00191
00192 if ( services.isEmpty())
00193 {
00194 slotDisplayError( i18n("No service found matching the criteria.") );
00195 return;
00196 }
00197
00198 this->m_resultsList->setRootIsDecorated( true );
00199
00200 KListViewItem *rootItem = 0;
00201
00202 KTrader::OfferList::ConstIterator it = services.begin();
00203 for ( ; it != services.end(); ++it )
00204 {
00205 KService::Ptr service = (*it);
00206 KListViewItem *serviceItem = new KListViewItem( this->m_resultsList, rootItem, service->name() );
00207
00208 QStringList propertyNames = service->propertyNames();
00209 for ( QStringList::const_iterator it = propertyNames.begin(); it != propertyNames.end(); ++it )
00210 {
00211 QString propertyName = (*it);
00212 QVariant property = service->property( propertyName );
00213 QString propertyType = property.typeName();
00214 QString propertyValue;
00215 if (propertyType == "QStringList") {
00216 propertyValue = property.toStringList().join(", ");
00217 }
00218 else {
00219 propertyValue = property.toString();
00220 }
00221
00222 QString dProperty = " *** Found property < %1, %2, %3 >";
00223 dProperty = dProperty.arg( propertyName ).arg( propertyType ).arg( propertyValue );
00224 kdDebug( 9000 ) << dProperty << endl;
00225
00226 new PartExplorer::PropertyItem( serviceItem, propertyName, propertyType, propertyValue );
00227 }
00228 }
00229 }
00230
00231 #include "partexplorerform.moc"
This file is part of the documentation for KDevelop Version 3.1.2.