summaryrefslogtreecommitdiffstats
path: root/kbugbuster/gui/cwbuglistcontainer.cpp
blob: 2eeadee358d275670592b0df48ab320093bf1ef0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
    cwbuglistcontainer.cpp  -  Container for the bug list

    copyright   : (c) 2001 by Martijn Klingens
    email       : [email protected]

    *************************************************************************
    *                                                                       *
    * This program is free software; you can redistribute it and/or modify  *
    * it under the terms of the GNU General Public License as published by  *
    * the Free Software Foundation; either version 2 of the License, or     *
    * (at your option) any later version.                                   *
    *                                                                       *
    *************************************************************************
*/

#include <tqpushbutton.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqwidgetstack.h>

#include <tdeapplication.h>
#include <kiconloader.h>
#include <tdelistview.h>
#include <tdelocale.h>
#include <kdialog.h>
#if KDE_IS_VERSION( 3, 2, 90 )
#include <tdelistviewsearchline.h>
#endif
#include <kdebug.h>

#include "bugsystem.h"

#include "cwloadingwidget.h"
#include "buglvi.h"
#include "kbbprefs.h"
#include "kfind.h"

#include "cwbuglistcontainer.h"
#include <kfinddialog.h>

using namespace KBugBusterMainWindow;

CWBugListContainer::CWBugListContainer( TQWidget *parent , const char * name )
  : TQWidget( parent, name ), m_find(0), m_findItem(0)
{
    TQBoxLayout *topLayout = new TQVBoxLayout( this );
    topLayout->setSpacing( KDialog::spacingHint() );
    topLayout->setMargin( KDialog::marginHint() );

    m_listLabel = new TQLabel( this );
    topLayout->addWidget( m_listLabel );
    topLayout->setStretchFactor( m_listLabel, 0 );

    TQFont f = m_listLabel->font();
    f.setBold( true );
    m_listLabel->setFont( f );

    m_listStack = new TQWidgetStack( this );

    // Create Outstanding Bugs listview
    m_listBugs = new TDEListView( m_listStack );

    topLayout->addWidget( new TDEListViewSearchLineWidget( m_listBugs, this ) );
    topLayout->addWidget( m_listStack );
    topLayout->setStretchFactor( m_listStack, 1 );

    m_listBugs->addColumn( i18n( "Number" ) );
    m_listBugs->addColumn( i18n( "Age" ) );
    m_listBugs->addColumn( i18n( "Title" ), 500 ); // so that the widthmode isn't "Maximum"
    m_listBugs->addColumn( i18n( "Status" ) );
    m_listBugs->addColumn( i18n( "Severity" ) );
    m_listBugs->addColumn( i18n( "Sender" ), 150 ); // idem. hardcoded widths suck a bit, but...
    m_listBugs->setAllColumnsShowFocus( true );
    m_listBugs->setColumnAlignment( 0, AlignRight );
    m_listBugs->setSorting( 0, false );
    m_listBugs->setShowSortIndicator( true );
    m_listBugs->setSelectionMode( TQListView::Extended ); // needed for merging bugs

    m_listBugs->restoreLayout( KBBPrefs::instance()->config(), "BugListLayout" );

    connect( m_listBugs, TQT_SIGNAL( executed( TQListViewItem * ) ),
             TQT_SLOT( execute( TQListViewItem * ) ) );
    connect( m_listBugs, TQT_SIGNAL( returnPressed( TQListViewItem * ) ),
             TQT_SLOT( execute( TQListViewItem * ) ) );
    connect( m_listBugs, TQT_SIGNAL( currentChanged( TQListViewItem * ) ),
             TQT_SLOT( changeCurrent( TQListViewItem * ) ) );

    // Fill WidgetStack in Outstanding Bugs pane
    m_listLoading = new CWLoadingWidget( CWLoadingWidget::TopFrame,
                                         m_listStack );
    connect( m_listLoading, TQT_SIGNAL( clicked() ), TQT_SIGNAL( searchPackage() ) );

    m_listStack->addWidget( m_listBugs, 0 );
    m_listStack->addWidget( m_listLoading,  1 );

    setNoList();

    connect( BugSystem::self(), TQT_SIGNAL( bugListLoading( const Package &, const TQString & ) ),
             TQT_SLOT( setLoading( const Package &, const TQString & ) ) );
    connect( BugSystem::self(), TQT_SIGNAL( bugListLoading( const TQString & ) ),
             TQT_SLOT( setLoading( const TQString & ) ) );
    connect( BugSystem::self(), TQT_SIGNAL( bugListCacheMiss( const Package & ) ),
             TQT_SLOT( setCacheMiss( const Package & ) ) );
    connect( BugSystem::self(), TQT_SIGNAL( bugListCacheMiss( const TQString & ) ),
             TQT_SLOT( setCacheMiss( const TQString & ) ) );
    connect( BugSystem::self(), TQT_SIGNAL( commandQueued( BugCommand * ) ),
             TQT_SLOT( markBugCommand( BugCommand * ) ) );
    connect( BugSystem::self(), TQT_SIGNAL( commandCanceled( const TQString & ) ),
             TQT_SLOT( clearCommand( const TQString & ) ) );
}

CWBugListContainer::~CWBugListContainer()
{
    m_listBugs->saveLayout( KBBPrefs::instance()->config(), "BugListLayout" );
    KBBPrefs::instance()->writeConfig();
    delete m_find;
}

void CWBugListContainer::setBugList( const TQString &label, const Bug::List &bugs )
{
    // List pane is invisible by default, make visible
    show();

    m_listBugs->clear();
    emit resetProgressBar();
    bool showClosed = KBBPrefs::instance()->mShowClosedBugs;
    bool showWishes = KBBPrefs::instance()->mShowWishes;
    uint noBugs = 0;
    uint noWishes = 0;

    for ( Bug::List::ConstIterator it = bugs.begin(); it != bugs.end(); ++it )
    {
        if ( ( *it ).status() != Bug::Closed || showClosed )
        {
            if ( ( *it ).severity() != Bug::Wishlist || showWishes )
                new BugLVI( m_listBugs, *it );

            if ( ( *it ).severity() != Bug::Wishlist )
                noBugs++;
            else
                noWishes++;
        }
    }

    m_listLabel->setText( i18n( "%1 (%2 bugs, %3 wishes)" ).arg( label ).arg( noBugs ).arg( noWishes ) );
    m_listStack->raiseWidget( 0 );
}

void CWBugListContainer::setBugList( const Package &package, const TQString &component, const Bug::List &bugs )
{
    TQString listLabel;
    if ( component.isEmpty() )
    {
        if ( package.components().count() > 1 )
            listLabel = i18n( "Product '%1', all components" ).arg( package.name() );
        else
            listLabel = i18n( "Product '%1'" ).arg( package.name() );
    }
    else
    {
        listLabel = i18n( "Product '%1', component '%2'" ).arg( package.name(), component );
    }

    setBugList( listLabel, bugs );
}

void CWBugListContainer::execute( TQListViewItem *lvi )
{
    BugLVI *item = dynamic_cast<BugLVI *>( lvi );
    if( !item )
    {
        kdWarning() << "CWBugListContainer::execute() Selected bug "
                    << lvi->text( 0 )
                    << " is not a BugLVI! Ignoring event." << endl;
        return;
    }

    emit executed( item->bug() );
}

void CWBugListContainer::changeCurrent( TQListViewItem *lvi )
{
    if( !lvi ) {
        emit currentChanged( Bug() );
        return;
    }

    BugLVI *item = dynamic_cast<BugLVI *>( lvi );
    if( !item )
    {
        kdWarning() << "CWBugListContainer::changeCurrent() Selected bug "
                    << lvi->text( 0 )
                    << " is not a BugLVI! Ignoring event." << endl;
        return;
    }

    emit currentChanged( item->bug() );
}

void CWBugListContainer::setNoList()
{
    m_listLabel->setText( i18n("Outstanding Bugs") );
    m_listLoading->setText( i18n( "Click here to select a product" ) );
    m_listStack->raiseWidget( 1 );
}

void CWBugListContainer::setLoading( const Package &package, const TQString &component )
{
    if ( component.isEmpty() )
        setLoading( i18n( "Retrieving List of Outstanding Bugs for Product '%1'..." ).arg( package.name() ) );
    else
        setLoading( i18n( "Retrieving List of Outstanding Bugs for Product '%1' (Component %2)..." ).arg( package.name(), component ) );
}

void CWBugListContainer::setLoading( const TQString &label )
{
    m_listLoading->setText( label );
    m_listStack->raiseWidget( 1 );
}

void CWBugListContainer::setCacheMiss( const Package &package )
{
    setCacheMiss( i18n( "Package '%1'" ).arg( package.name() ) );
}

void CWBugListContainer::setCacheMiss( const TQString &label )
{
    m_listLoading->setText( i18n( "%1 is not available offline." ).arg( label ) );
    m_listStack->raiseWidget( 1 );
}

void CWBugListContainer::markBugCommand( BugCommand *cmd )
{
    BugLVI *item = (BugLVI *)m_listBugs->firstChild();
    while( item ) {
        if ( item->bug().number() == cmd->bug().number() ) {
            item->setCommandState( BugCommand::Queued );
            break;
        }
        item = (BugLVI *)item->nextSibling();
    }
    m_listBugs->triggerUpdate();
}

void CWBugListContainer::clearCommand( const TQString &bug )
{
    BugLVI *item = (BugLVI *)m_listBugs->firstChild();
    while( item ) {
        if ( item->bug().number() == bug ) {
            item->setCommandState( BugCommand::None );
            break;
        }
        item = (BugLVI *)item->nextSibling();
    }
    m_listBugs->triggerUpdate();
}

void CWBugListContainer::searchBugByTitle( int options, const TQString& pattern )
{
    m_find = new KFind( pattern, options, this );
    // Connect signals to code which handles highlighting
    // of found text.
    connect(m_find, TQT_SIGNAL( highlight( const TQString &, int, int ) ),
            this, TQT_SLOT( searchHighlight( const TQString &, int, int ) ) );
    connect(m_find, TQT_SIGNAL( findNext() ), this, TQT_SLOT( slotFindNext() ) );

    m_findItem = (BugLVI *)m_listBugs->firstChild();
    if ( options & KFindDialog::FromCursor && m_listBugs->currentItem() )
        m_findItem = (BugLVI *)m_listBugs->currentItem();

    slotFindNext();
}

// Note: if a 'find next' action is added, then one should also ensure
// that m_findItem never becomes dangling (i.e. clear it when clearing the listview).
void CWBugListContainer::slotFindNext()
{
    KFind::Result res = KFind::NoMatch;
    while( res == KFind::NoMatch && m_findItem ) {

        if ( m_find->needData() )
            m_find->setData( m_findItem->text(2) );

        // Let KFind inspect the text fragment, and display a dialog if a match is found
        res = m_find->find();

        if ( res == KFind::NoMatch ) {
            if ( m_find->options() & KFindDialog::FindBackwards )
                m_findItem = (BugLVI *)m_findItem->itemAbove();
            else
                m_findItem = (BugLVI *)m_findItem->itemBelow();
        }
    }
    if ( res == KFind::NoMatch ) // i.e. at end
       if ( m_find->shouldRestart() ) {
           m_findItem = (BugLVI *)m_listBugs->firstChild();
           slotFindNext();
       } else {
           delete m_find;
           m_find = 0L;
       }
}

void CWBugListContainer::searchHighlight( const TQString &, int, int )
{
    if ( m_findItem ) {
        m_listBugs->clearSelection();
        m_listBugs->setSelected( m_findItem, true );
        m_listBugs->ensureItemVisible( m_findItem );
    }
}

TQStringList CWBugListContainer::selectedBugs() const
{
    TQStringList lst;
    BugLVI *item = (BugLVI *)m_listBugs->firstChild();
    while( item ) {
        if ( item->isSelected() )
            lst.append( item->bug().number() );
        item = (BugLVI *)item->nextSibling();
    }
    return lst;
}

#include "cwbuglistcontainer.moc"