add mp3 and ogg torrent url info to JamendoAlbum
[amarok.git] / src / filebrowserwidget.cpp
blob46306ffebe6a78f59719e60cda3c67f96c01cf5d
1 /***************************************************************************
2 * Copyright (c) 2007 Dan Meltzer <hydrogen@notyetimplemented.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
21 #include "collection/CollectionManager.h"
22 #include "filebrowserwidget.h"
23 #include "meta/meta.h"
24 #include "mydirlister.h"
25 #include "playlist/PlaylistModel.h"
26 #include "TheInstances.h"
28 #include <QDir>
29 #include <QListView>
30 #include <QVBoxLayout>
32 #include <KActionCollection>
33 #include <KDirModel>
34 #include <kdirsortfilterproxymodel.h>
35 #include <KUrlComboBox>
36 #include <KUrlCompletion>
39 FileBrowserWidget::FileBrowserWidget( const char *name )
41 m_combo = new KUrlComboBox( KUrlComboBox::Directories, true, this );
43 m_combo->setCompletionObject( new KUrlCompletion( KUrlCompletion::DirCompletion ) );
44 m_combo->setAutoDeleteCompletionObject( true );
45 m_combo->setMaxItems( 9 );
47 connect( m_combo, SIGNAL(returnPressed(QString)),
48 SLOT(setRootDirectory(QString)));
49 m_combo->setUrl( KUrl(QDir::home().path()) );
50 setObjectName( name );
52 m_model = new KDirModel( this );
53 m_model->setDirLister( new MyDirLister( true ) );
54 m_model->dirLister()->setShowingDotFiles( false );
56 m_sortModel = new KDirSortFilterProxyModel( this );
57 m_sortModel->setSourceModel( m_model );
59 m_view = new QListView( this );
61 m_view->setModel( m_sortModel );
63 connect( m_view, SIGNAL(doubleClicked(QModelIndex)),
64 SLOT(setRootDirectory(QModelIndex)));
66 m_model->dirLister()->openUrl( KUrl( "~" ) );
68 setFocusProxy( m_view );
72 FileBrowserWidget::~FileBrowserWidget()
74 delete m_model;
77 void
78 FileBrowserWidget::setRootDirectory( const QString &path )
80 m_model->dirLister()->openUrl( KUrl( path ) );
83 void
84 FileBrowserWidget::setRootDirectory( const QModelIndex &index )
86 QModelIndex sourceIndex = m_sortModel->mapToSource( index );
87 KFileItem fi = m_model->itemForIndex( sourceIndex );
89 if( fi.isDir() )
91 m_model->dirLister()->openUrl( fi.url() );
92 m_combo->setUrl( fi.url() );
94 else
96 Meta::TrackPtr track = CollectionManager::instance()->trackForUrl( fi.url() );
97 The::playlistModel()->insertOptioned( track, Playlist::Append );
101 #include "filebrowserwidget.moc"