KDevelop API Documentation

parts/partexplorer/partexplorerform.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2003 by Mario Scalas * 00003 * mario.scalas@libero.it * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 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 00025 #include "partexplorerformbase.h" 00026 #include "partexplorerform.h" 00027 00029 // class PropertyItem 00031 00032 class PropertyItem : public KListViewItem 00033 { 00034 public: 00035 PropertyItem( KListViewItem *parent, const QString &propertyName, 00036 const QString &propertyType, const QString &propertyValue ) 00037 : KListViewItem( parent ) 00038 { 00039 setText( 0, propertyName ); 00040 setText( 1, propertyType ); 00041 setText( 2, propertyValue ); 00042 } 00043 00044 QString tipText() const 00045 { 00046 QString tip = i18n("Name: %1 | Type: %2 | Value: %3"); 00047 return tip.arg( text(0) ).arg( text(1) ).arg( text(2) ); 00048 } 00049 }; 00050 00052 // class ResultsList 00054 00055 class ResultList; 00056 00057 class ResultsToolTip: public QToolTip 00058 { 00059 public: 00060 ResultsToolTip( ResultsList* parent ); 00061 virtual void maybeTip( const QPoint& p ); 00062 00063 private: 00064 ResultsList* m_resultsList; 00065 }; 00066 00067 class ResultsList : public KListView 00068 { 00069 public: 00070 ResultsList( QWidget *parent ) 00071 : KListView( parent, "resultslist" ) 00072 { 00073 this->setShowToolTips( false ); 00074 new ResultsToolTip( this ); 00075 } 00076 00077 virtual ~ResultsList() {} 00078 00079 void clear() 00080 { 00081 KListView::clear(); 00082 } 00083 }; 00084 00085 ResultsToolTip::ResultsToolTip( ResultsList* parent ) 00086 : QToolTip( parent->viewport() ), m_resultsList( parent ) 00087 { 00088 } 00089 00090 void ResultsToolTip::maybeTip( const QPoint& p ) 00091 { 00092 PropertyItem *item = dynamic_cast<PropertyItem*>( m_resultsList->itemAt( p ) ); 00093 if ( item ) 00094 { 00095 QRect r = m_resultsList->itemRect( item ); 00096 if ( r.isValid() ) 00097 tip( r, item->tipText() ); 00098 } 00099 } 00100 00101 00103 // class PartExplorerForm 00105 00106 PartExplorerForm::PartExplorerForm( QWidget *parent ) 00107 : KDialogBase( parent, "parteplorerform", false, 00108 i18n("Part Explorer - A Services Lister"), User1 | Close, User1, true ) 00109 { 00110 m_base = new PartExplorerFormBase( this, "partexplorerformbase", 0 ); 00111 m_resultsList = new ResultsList( m_base ); 00112 m_resultsList->addColumn( i18n( "Property" ) ); 00113 m_resultsList->addColumn( i18n( "Type" ) ); 00114 m_resultsList->addColumn( i18n( "Value" ) ); 00115 m_resultsList->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, 00116 (QSizePolicy::SizeType)3, 0, 0, 00117 m_resultsList->sizePolicy().hasHeightForWidth() ) ); 00118 QWhatsThis::add( m_resultsList, i18n("<b>Matching services</b><p>Results (if any) are shown grouped by matching service name.") ); 00119 m_base->resultsLabel->setBuddy(m_resultsList); 00120 m_base->layout()->add( m_resultsList ); 00121 setMainWidget( m_base ); 00122 m_base->typeEdit->setFocus(); 00123 00124 // User1 button text 00125 setButtonText( User1, i18n("&Search") ); 00126 00127 // Resize dialog 00128 resize( 480, 512 ); 00129 00130 connect( m_base->typeEdit, SIGNAL(returnPressed()), this, SLOT(slotSearchRequested()) ); 00131 connect( m_base->costraintsText, SIGNAL(returnPressed()), this, SLOT(slotSearchRequested()) ); 00132 00133 connect( actionButton(User1), SIGNAL(clicked()), this, SLOT(slotSearchRequested()) ); 00134 connect( m_base->typeEdit, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotServicetypeChanged( const QString& ) ) ); 00135 slotServicetypeChanged( m_base->typeEdit->text() ); 00136 } 00137 00139 00140 PartExplorerForm::~PartExplorerForm() 00141 { 00142 } 00143 00144 void PartExplorerForm::slotServicetypeChanged( const QString& _text ) 00145 { 00146 enableButton( KDialogBase::User1, !_text.isEmpty() ); 00147 } 00148 00150 00151 QString PartExplorerForm::serviceType() const 00152 { 00153 QString st = m_base->typeEdit->text(); 00154 00155 return st.isEmpty()? QString::null : st; 00156 } 00157 00159 00160 QString PartExplorerForm::costraints() const 00161 { 00162 QString c = m_base->costraintsText->text(); 00163 return c.isEmpty()? QString::null : c; 00164 } 00165 00167 00168 void PartExplorerForm::slotSearchRequested() 00169 { 00170 if ( m_base->typeEdit->text().isEmpty() ) 00171 return; 00172 00173 QString serviceType = this->serviceType(), 00174 costraints = this->costraints(); 00175 00176 kdDebug(9000) << "===> PartExplorerForm::slotSearchRequested(): " << 00177 " serviceType = " << serviceType << ", costraints = " << costraints << endl; 00178 00179 if (serviceType.isNull()) // It is mandatory 00180 { 00181 slotDisplayError( i18n("You must fill at least the service type!!") ); 00182 return; 00183 } 00184 00185 // Query for requested services 00186 KTrader::OfferList foundServices = KTrader::self()->query( serviceType, costraints ); 00187 fillServiceList( foundServices ); 00188 } 00189 00191 00192 void PartExplorerForm::slotDisplayError( QString errorMessage ) 00193 { 00194 if (errorMessage.isEmpty()) 00195 { 00196 errorMessage = i18n("Unknown error!"); 00197 } 00198 KMessageBox::error( this, errorMessage ); 00199 } 00200 00202 00203 void PartExplorerForm::fillServiceList( const KTrader::OfferList &services ) 00204 { 00205 this->m_resultsList->clear(); 00206 00207 if ( services.isEmpty()) 00208 { 00209 slotDisplayError( i18n("No service found matching the criteria!") ); 00210 return; 00211 } 00212 00213 this->m_resultsList->setRootIsDecorated( true ); 00214 00215 KListViewItem *rootItem = 0; 00216 00217 KTrader::OfferList::ConstIterator it = services.begin(); 00218 for ( ; it != services.end(); ++it ) 00219 { 00220 KService::Ptr service = (*it); 00221 KListViewItem *serviceItem = new KListViewItem( this->m_resultsList, rootItem, service->name() ); 00222 00223 QStringList propertyNames = service->propertyNames(); 00224 for ( QStringList::const_iterator it = propertyNames.begin(); it != propertyNames.end(); ++it ) 00225 { 00226 QString propertyName = (*it); 00227 QVariant property = service->property( propertyName ); 00228 QString propertyType = property.typeName(); 00229 QString propertyValue; 00230 if (propertyType == "QStringList") { 00231 propertyValue = property.toStringList().join(", "); 00232 } 00233 else { 00234 propertyValue = property.toString(); 00235 } 00236 00237 QString dProperty = " *** Found property < %1, %2, %3 >"; 00238 dProperty = dProperty.arg( propertyName ).arg( propertyType ).arg( propertyValue ); 00239 kdDebug( 9000 ) << dProperty << endl; 00240 00241 new PropertyItem( serviceItem, propertyName, propertyType, propertyValue ); 00242 } 00243 } 00244 } 00245 00246 #include "partexplorerform.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:39:12 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003