diff --git a/bgrive/src/DriveModel.cc b/bgrive/src/DriveModel.cc index e2b7d4b..90cd2af 100644 --- a/bgrive/src/DriveModel.cc +++ b/bgrive/src/DriveModel.cc @@ -94,7 +94,6 @@ QModelIndex DriveModel::parent( const QModelIndex& idx ) const // if my parent is root, return model index of root (i.e. QModelIndex()) const Resource *parent = m_drv.Parent(res) ; - if ( parent == 0 || parent == m_drv.Root() || idx.column() != 0 ) return QModelIndex() ; diff --git a/bgrive/src/DriveModel.hh b/bgrive/src/DriveModel.hh index 1a74283..07d3b32 100644 --- a/bgrive/src/DriveModel.hh +++ b/bgrive/src/DriveModel.hh @@ -46,7 +46,6 @@ public : QModelIndex index( int row, int column, const QModelIndex& parent ) const ; QModelIndex parent( const QModelIndex& idx ) const ; -private : const v2::Resource* Res( const QModelIndex& idx ) const ; private : diff --git a/bgrive/src/MainWnd.cc b/bgrive/src/MainWnd.cc index 84bf64f..28d4e08 100644 --- a/bgrive/src/MainWnd.cc +++ b/bgrive/src/MainWnd.cc @@ -20,16 +20,39 @@ #include "MainWnd.hh" +#include "drive2/Resource.hh" + +#include + #include namespace gr { +using namespace v2 ; + MainWnd::MainWnd( http::Agent *agent ) : m_drive( agent ) { m_ui.setupUi(this) ; - m_ui.m_dir->setModel( &m_drive ) ; + + connect( + m_ui.m_dir, SIGNAL(activated(const QModelIndex&)), + this, SLOT(OnClick(const QModelIndex&)) + ) ; +} + +void MainWnd::OnClick( const QModelIndex& index ) +{ + const Resource *res = m_drive.Res(index) ; + if ( res != 0 ) + ShowResource( res ) ; +} + +void MainWnd::ShowResource( const v2::Resource *res ) +{ + m_ui.m_title->setText( QString::fromUtf8(res->Title().c_str()) ) ; + m_ui.m_mime_type->setText( QString::fromUtf8(res->Mime().c_str()) ) ; } } // end of namespace diff --git a/bgrive/src/MainWnd.hh b/bgrive/src/MainWnd.hh index 5551a6b..fe9401b 100644 --- a/bgrive/src/MainWnd.hh +++ b/bgrive/src/MainWnd.hh @@ -25,6 +25,8 @@ #include "DriveModel.hh" +class QModelIndex ; + namespace gr { namespace http @@ -39,6 +41,12 @@ class MainWnd : public QMainWindow public : MainWnd( http::Agent *agent ) ; +private : + void ShowResource( const v2::Resource *res ) ; + +public slots : + void OnClick( const QModelIndex& index ) ; + private : Ui::MainWindow m_ui ; DriveModel m_drive ; diff --git a/libgrive/src/drive2/Drive.cc b/libgrive/src/drive2/Drive.cc index 2a28cfd..cb3fad6 100644 --- a/libgrive/src/drive2/Drive.cc +++ b/libgrive/src/drive2/Drive.cc @@ -23,6 +23,7 @@ #include "CommonUri.hh" #include "Feed.hh" #include "protocol/Json.hh" +#include "util/Exception.hh" #include #include @@ -140,6 +141,11 @@ const Resource* Drive::Root() const const Resource* Drive::Child( const Resource *parent, std::size_t idx ) const { + if ( idx >= parent->ChildCount() ) + BOOST_THROW_EXCEPTION( + Exception() + ) ; + return Find( parent->At(idx) ) ; }