77
79
virtual ~IconPolicy() {}
80
class ApplicationsPageModel : public KPageModel
84
typedef std::map< std::string, PackageListView * > Pages;
85
typedef std::pair< std::string, PackageListView * > Pair;
86
typedef std::vector< Pair > PageVec;
92
explicit ApplicationsPageModel( QObject *parent = 0 )
93
: KPageModel( parent )
96
virtual QModelIndex index( int row, int column,
97
const QModelIndex & = QModelIndex()
100
return createIndex( row, column, 0 );
103
bool valid( const QModelIndex &i ) const {
104
return i.row() < static_cast< int >( pages.size() ) && i.column() == 0;
107
std::string name( const QModelIndex &i ) {
109
return std::string();
110
return pages[ i.row() ].first;
113
QVariant data( const QModelIndex &i, int role = Qt::DisplayRole ) const
117
Pair p = pages[ i.row() ];
119
case Qt::DisplayRole:
120
case HeaderRole: return QVariant::fromValue( u8( p.first ) );
121
case WidgetRole: return QVariant::fromValue(
122
static_cast< QWidget * >( p.second ) );
123
case Qt::DecorationRole: return QVariant::fromValue(
124
QIcon( KIcon( iconPol.iconForGroup( u8( p.first ) ) ) ) );
125
default: return QVariant();
129
QModelIndex parent( const QModelIndex & ) const {
130
return QModelIndex();
133
int columnCount( const QModelIndex & ) const {
137
int rowCount( const QModelIndex &a ) const {
138
if ( a == QModelIndex() )
143
QModelIndex nameIndex( std::string n ) const {
145
for ( PageVec::const_iterator i = pages.begin(); i != pages.end(); ++i )
148
return createIndex( j, 0, 0 );
151
return createIndex( 0, 0, 0 );
154
void update( const Pages &visible ) {
155
layoutAboutToBeChanged();
157
std::copy( visible.begin(), visible.end(), std::back_inserter( pages ) );
158
dataChanged( createIndex( 0, 0, 0 ),
159
createIndex( pages.size() - 1, 1, 0 ) );
164
82
class ApplicationsWidget : public KVBox
169
86
KLineEdit *m_searchLine;
88
SidebarListWidget *m_groups;
89
PackageListView *m_list;
172
AppGroupPolicy groupPol;
173
ApplicationsPageModel *pg_model;
174
typedef std::map< std::string, PackageListView * > Pages;
175
92
typedef std::map< std::string, TokenModel * > Models;
94
std::string empty, current;
178
96
std::set< ept::Token > m_xapianSet;
179
97
Validator validator;
99
AppGroupPolicy groupPol;
206
127
return ept::Token();
130
TokenModel *model( std::string g ) {
131
if ( all.find( g ) == all.end() ) {
132
TokenModel *m = new TokenModel();
133
all.insert( std::make_pair( g, m ) );
135
return all.find( g )->second;
209
138
template< typename L >
210
139
void fillList( L l ) {
211
140
ProcessEvents::restart();
212
141
QApplication::setOverrideCursor( QCursor( Qt::BusyCursor ) );
143
for ( Models::iterator i = all.begin(); i != all.end(); ++i )
214
std::string current, goal;
215
pg->setUpdatesEnabled( false );
217
goal = pg_model->name( pg->currentPage() );
219
for ( Models::iterator i = models.begin(); i != models.end(); ++i )
222
148
while ( !l.empty() ) {
223
ProcessEvents::check( pg );
149
ProcessEvents::check( this );
225
151
ept::Token t = validate( l.head().token() );
232
158
std::string g = l.head().template get< desktop::Group >();
235
if ( models.find( g ) == models.end() ) {
236
TokenModel *m = new TokenModel();
237
models.insert( std::make_pair( g, m ) );
240
if ( all.find( g ) == all.end() ) {
241
PackageListView *w = setupList(
242
this, pg, models.find( g )->second, d );
243
w->setSortingEnabled( true );
245
std::cerr << "Adding group: " << g << std::endl;
246
all.insert( std::make_pair( g, w ) );
248
models.find( g )->second->appendToken( t );
161
model( g )->appendToken( t );
250
163
if ( visible.find( g ) == visible.end() ) {
251
if ( current.empty() || (!goal.empty() && g == goal) ) {
252
std::cerr << "setting current to " << g << std::endl;
255
visible.insert( visible.begin(), *all.find( g ) );
256
updateVisible( current );
164
visible[ g ] = model( g );
165
// visible.insert( visible.begin(), model( g ) );
260
for ( Models::iterator i = models.begin(); i != models.end(); ++i )
170
setUpdatesEnabled( true );
172
for ( Models::iterator i = all.begin(); i != all.end(); ++i )
261
173
i->second->end();
262
pg->setUpdatesEnabled( true );
263
174
QApplication::restoreOverrideCursor();
266
void updateVisible( std::string current ) {
267
pg_model->update( visible );
268
for ( Pages::iterator i = all.begin(); i != all.end(); ++i ) {
271
pg->setCurrentPage( pg_model->nameIndex( current ) );
272
all.find( current )->second->show(); // show the widget...
176
if ( !visible.count( current ) || current == empty ) {
177
if ( !visible.empty() )
178
current = visible.begin()->first;
183
QTimer::singleShot( 0, this, SLOT( updateVisible() ) );
187
void updateVisible() {
188
bool nocurrent = false;
189
if ( visible.empty() ) {
190
visible[ current ] = model( current );
192
if ( ! (visible.size() == 1 && visible.begin()->first == empty) )
193
visible.erase( empty );
195
if ( !visible.count( current ) ) {
196
visible[ current ] = model( current );
200
std::cerr << "-------------- (current = " << current << ") --"
202
for ( Models::iterator i = visible.begin(); i != visible.end(); ++i ) {
203
std::cerr << "Adding " << i->first << std::endl;
204
QIcon icon = QIcon( KIcon(
205
iconPol.iconForGroup( u8( i->first ) ) ) );
207
new SidebarItem( 0, icon, u8( i->first ) );
208
m_groups->addItem( it );
209
if ( i->first == current ) {
210
m_groups->setCurrentItem( it );
214
visible.erase( current );
220
void updateWidths() {
222
for ( int i = 0; i < m_groups->count(); ++i )
224
QSize s = m_groups->sizeHintForIndex(
225
m_groups->model()->index( i, 0 ) );
229
m_groups->setFixedWidth( w + 30 );
275
232
ApplicationsWidget( PackageData &_d, QWidget *p = 0 )
276
: KVBox( p ), d( _d ), validator( _d )
233
: KVBox( p ), d( _d ),
234
empty( s8( i18n( "No matches found" ) ) ),
278
237
KGlobal::dirs()->addResourceDir(
282
241
m_searchLine = new KLineEdit( this );
283
242
m_searchLine->setClearButtonShown( true );
284
243
m_searchLine->setClickMessage( i18n( "Search applications" ) );
285
pg = new KPageView( this );
286
pg_model = new ApplicationsPageModel( this );
287
pg->setModel( pg_model );
288
pg->setFaceType( KPageView::List );
244
hbox = new KHBox( this );
245
m_groups = new SidebarListWidget( hbox );
248
SidebarDelegate *deleg = new SidebarDelegate( m_groups );
249
deleg->setShowText( true ); // TODO: SETTINGS
250
m_groups->setItemDelegate( deleg );
251
m_groups->setIconSize( QSize( 48, 48 ) );
252
m_groups->setUniformItemSizes( true );
255
m_list = setupList( this, hbox, model( empty ), d );
257
connect( m_groups, SIGNAL( itemClicked( QListWidgetItem* ) ),
258
this, SLOT( selectGroup( QListWidgetItem* ) ) );
289
259
connect( m_searchLine, SIGNAL( returnPressed() ),
290
260
this, SLOT( search() ) );
294
267
void refreshSig();
271
std::cerr << "updateModel: '" << current << "' -> " <<
272
(void*) model( current ) << std::endl;
273
m_list->setModel( model( empty ) ); // work around something that looks
274
// like a QT bug to me
275
m_list->setModel( model( current ) );
278
void selectGroup( QListWidgetItem *i ) {
279
current = s8( i->text() );
298
284
m_xapianSet.clear();