show title and mime in GUI

pull/40/head
Nestal Wan 2013-04-30 00:13:13 +08:00
parent 15b3b85807
commit d5ca8e0afa
5 changed files with 38 additions and 3 deletions

View File

@ -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() ;

View File

@ -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 :

View File

@ -20,16 +20,39 @@
#include "MainWnd.hh"
#include "drive2/Resource.hh"
#include <QtCore/QDebug>
#include <cassert>
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

View File

@ -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 ;

View File

@ -23,6 +23,7 @@
#include "CommonUri.hh"
#include "Feed.hh"
#include "protocol/Json.hh"
#include "util/Exception.hh"
#include <iostream>
#include <iterator>
@ -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) ) ;
}