~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to parts/partexplorer/partexplorerform.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2003 by Mario Scalas                                    *
3
 
 *   mario.scalas@libero.it                                                *
4
 
 *                                                                         *
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.                                   *
9
 
 *                                                                         *
10
 
 ***************************************************************************/
11
 
 
12
 
#include <qlineedit.h>
13
 
#include <qtextedit.h>
14
 
#include <qpushbutton.h>
15
 
#include <qtooltip.h>
16
 
#include <qlayout.h>
17
 
#include <qwhatsthis.h>
18
 
#include <qlabel.h>
19
 
 
20
 
#include <klistview.h>
21
 
#include <klocale.h>
22
 
#include <kmessagebox.h>
23
 
#include <kdebug.h>
24
 
#include <kcombobox.h>
25
 
#include <kservicetype.h> 
26
 
 
27
 
#include "partexplorerformbase.h"
28
 
#include "partexplorerform.h"
29
 
 
30
 
///////////////////////////////////////////////////////////////////////////////
31
 
// class PropertyItem
32
 
///////////////////////////////////////////////////////////////////////////////
33
 
namespace PartExplorer{
34
 
 
35
 
class PropertyItem : public KListViewItem
36
 
{
37
 
public:
38
 
    PropertyItem( KListViewItem *parent, const QString &propertyName,
39
 
        const QString &propertyType, const QString &propertyValue )
40
 
        : KListViewItem( parent )
41
 
    {
42
 
        setText( 0, propertyName );
43
 
        setText( 1, propertyType );
44
 
        setText( 2, propertyValue );
45
 
    }
46
 
 
47
 
    QString tipText() const
48
 
    {
49
 
        QString tip = i18n("Name: %1 | Type: %2 | Value: %3");
50
 
        return tip.arg( text(0) ).arg( text(1) ).arg( text(2) );
51
 
    }
52
 
};
53
 
 
54
 
}
55
 
///////////////////////////////////////////////////////////////////////////////
56
 
// class ResultsList
57
 
///////////////////////////////////////////////////////////////////////////////
58
 
 
59
 
class ResultList;
60
 
 
61
 
class ResultsToolTip: public QToolTip
62
 
{
63
 
public:
64
 
    ResultsToolTip( ResultsList* parent );
65
 
    virtual void maybeTip( const QPoint& p );
66
 
 
67
 
private:
68
 
    ResultsList* m_resultsList;
69
 
};
70
 
 
71
 
class ResultsList : public KListView
72
 
{
73
 
public:
74
 
    ResultsList( QWidget *parent )
75
 
        : KListView( parent, "resultslist" )
76
 
    {
77
 
        this->setShowToolTips( false );
78
 
        new ResultsToolTip( this );
79
 
    }
80
 
 
81
 
    virtual ~ResultsList() {}
82
 
 
83
 
    void clear()
84
 
    {
85
 
        KListView::clear();
86
 
    }
87
 
};
88
 
 
89
 
ResultsToolTip::ResultsToolTip( ResultsList* parent )
90
 
    : QToolTip( parent->viewport() ), m_resultsList( parent )
91
 
{
92
 
}
93
 
 
94
 
void ResultsToolTip::maybeTip( const QPoint& p )
95
 
{
96
 
    PartExplorer::PropertyItem *item = dynamic_cast<PartExplorer::PropertyItem*>( m_resultsList->itemAt( p ) );
97
 
    if ( item )
98
 
    {
99
 
        QRect r = m_resultsList->itemRect( item );
100
 
        if ( r.isValid() )
101
 
            tip( r, item->tipText() );
102
 
    }
103
 
}
104
 
 
105
 
 
106
 
///////////////////////////////////////////////////////////////////////////////
107
 
// class PartExplorerForm
108
 
///////////////////////////////////////////////////////////////////////////////
109
 
 
110
 
PartExplorerForm::PartExplorerForm( QWidget *parent )
111
 
    : KDialogBase( parent, "parteplorerform", false,
112
 
        i18n("Part Explorer - A Services Lister"), User1 | Close, User1, true )
113
 
{
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();
127
 
 
128
 
    // User1 button text
129
 
    setButtonText( User1, i18n("&Search") );
130
 
 
131
 
    // Resize dialog
132
 
    resize( 480, 512 );
133
 
 
134
 
//    connect( m_base->typeCombo->lineEdit(), SIGNAL(returnPressed()), this, SLOT(slotSearchRequested()) );
135
 
//    connect( m_base->constraintsText, SIGNAL(returnPressed()), this, SLOT(slotSearchRequested()) );
136
 
 
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() );
140
 
 
141
 
        // populating with all known servicetypes
142
 
        KServiceType::List serviceList = KServiceType::allServiceTypes();
143
 
        QStringList list;
144
 
        KServiceType::List::Iterator it = serviceList.begin();
145
 
        while( it != serviceList.end() )
146
 
        {
147
 
                list << (*it)->name();
148
 
                ++it;
149
 
        }
150
 
        list.sort();
151
 
        m_base->typeCombo->insertStringList( list );
152
 
}
153
 
 
154
 
///////////////////////////////////////////////////////////////////////////////
155
 
 
156
 
PartExplorerForm::~PartExplorerForm()
157
 
{
158
 
}
159
 
 
160
 
///////////////////////////////////////////////////////////////////////////////
161
 
 
162
 
void PartExplorerForm::slotSearchRequested()
163
 
{
164
 
        QString serviceType = m_base->typeCombo->lineEdit()->text();
165
 
        QString constraints = m_base->constraintsText->text();
166
 
 
167
 
    kdDebug(9000) << "===> PartExplorerForm::slotSearchRequested(): " <<
168
 
        " serviceType = " << serviceType << ", constraints = " << constraints << endl;
169
 
 
170
 
    // Query for requested services
171
 
    KTrader::OfferList foundServices = KTrader::self()->query( serviceType, constraints );
172
 
    fillServiceList( foundServices );
173
 
}
174
 
 
175
 
///////////////////////////////////////////////////////////////////////////////
176
 
 
177
 
void PartExplorerForm::slotDisplayError( QString errorMessage )
178
 
{
179
 
    if (errorMessage.isEmpty())
180
 
    {
181
 
        errorMessage = i18n("Unknown error.");
182
 
    }
183
 
    KMessageBox::error( this, errorMessage );
184
 
}
185
 
 
186
 
///////////////////////////////////////////////////////////////////////////////
187
 
 
188
 
void PartExplorerForm::fillServiceList( const KTrader::OfferList &services )
189
 
{
190
 
    this->m_resultsList->clear();
191
 
 
192
 
    if ( services.isEmpty())
193
 
    {
194
 
        slotDisplayError( i18n("No service found matching the criteria.") );
195
 
        return;
196
 
    }
197
 
 
198
 
    this->m_resultsList->setRootIsDecorated( true );
199
 
 
200
 
    KListViewItem *rootItem = 0;
201
 
 
202
 
    KTrader::OfferList::ConstIterator it = services.begin();
203
 
    for ( ; it != services.end(); ++it )
204
 
    {
205
 
        KService::Ptr service = (*it);
206
 
        KListViewItem *serviceItem = new KListViewItem( this->m_resultsList, rootItem, service->name() );
207
 
 
208
 
        QStringList propertyNames = service->propertyNames();
209
 
        for ( QStringList::const_iterator it = propertyNames.begin(); it != propertyNames.end(); ++it )
210
 
        {
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(", ");
217
 
            }
218
 
            else {
219
 
                propertyValue = property.toString();
220
 
            }
221
 
 
222
 
            QString dProperty = " *** Found property < %1, %2, %3 >";
223
 
            dProperty = dProperty.arg( propertyName ).arg( propertyType ).arg( propertyValue );
224
 
            kdDebug( 9000 ) << dProperty << endl;
225
 
 
226
 
            new PartExplorer::PropertyItem( serviceItem, propertyName, propertyType, propertyValue );
227
 
        }
228
 
    }
229
 
}
230
 
 
231
 
#include "partexplorerform.moc"