mirror of https://github.com/vitalif/grive2
show title and mime in GUI
parent
15b3b85807
commit
d5ca8e0afa
|
@ -94,7 +94,6 @@ QModelIndex DriveModel::parent( const QModelIndex& idx ) const
|
||||||
|
|
||||||
// if my parent is root, return model index of root (i.e. QModelIndex())
|
// if my parent is root, return model index of root (i.e. QModelIndex())
|
||||||
const Resource *parent = m_drv.Parent(res) ;
|
const Resource *parent = m_drv.Parent(res) ;
|
||||||
|
|
||||||
if ( parent == 0 || parent == m_drv.Root() || idx.column() != 0 )
|
if ( parent == 0 || parent == m_drv.Root() || idx.column() != 0 )
|
||||||
return QModelIndex() ;
|
return QModelIndex() ;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,6 @@ public :
|
||||||
QModelIndex index( int row, int column, const QModelIndex& parent ) const ;
|
QModelIndex index( int row, int column, const QModelIndex& parent ) const ;
|
||||||
QModelIndex parent( const QModelIndex& idx ) const ;
|
QModelIndex parent( const QModelIndex& idx ) const ;
|
||||||
|
|
||||||
private :
|
|
||||||
const v2::Resource* Res( const QModelIndex& idx ) const ;
|
const v2::Resource* Res( const QModelIndex& idx ) const ;
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
|
@ -20,16 +20,39 @@
|
||||||
|
|
||||||
#include "MainWnd.hh"
|
#include "MainWnd.hh"
|
||||||
|
|
||||||
|
#include "drive2/Resource.hh"
|
||||||
|
|
||||||
|
#include <QtCore/QDebug>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
namespace gr {
|
namespace gr {
|
||||||
|
|
||||||
|
using namespace v2 ;
|
||||||
|
|
||||||
MainWnd::MainWnd( http::Agent *agent ) :
|
MainWnd::MainWnd( http::Agent *agent ) :
|
||||||
m_drive( agent )
|
m_drive( agent )
|
||||||
{
|
{
|
||||||
m_ui.setupUi(this) ;
|
m_ui.setupUi(this) ;
|
||||||
|
|
||||||
m_ui.m_dir->setModel( &m_drive ) ;
|
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
|
} // end of namespace
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
#include "DriveModel.hh"
|
#include "DriveModel.hh"
|
||||||
|
|
||||||
|
class QModelIndex ;
|
||||||
|
|
||||||
namespace gr {
|
namespace gr {
|
||||||
|
|
||||||
namespace http
|
namespace http
|
||||||
|
@ -39,6 +41,12 @@ class MainWnd : public QMainWindow
|
||||||
public :
|
public :
|
||||||
MainWnd( http::Agent *agent ) ;
|
MainWnd( http::Agent *agent ) ;
|
||||||
|
|
||||||
|
private :
|
||||||
|
void ShowResource( const v2::Resource *res ) ;
|
||||||
|
|
||||||
|
public slots :
|
||||||
|
void OnClick( const QModelIndex& index ) ;
|
||||||
|
|
||||||
private :
|
private :
|
||||||
Ui::MainWindow m_ui ;
|
Ui::MainWindow m_ui ;
|
||||||
DriveModel m_drive ;
|
DriveModel m_drive ;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "CommonUri.hh"
|
#include "CommonUri.hh"
|
||||||
#include "Feed.hh"
|
#include "Feed.hh"
|
||||||
#include "protocol/Json.hh"
|
#include "protocol/Json.hh"
|
||||||
|
#include "util/Exception.hh"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
@ -140,6 +141,11 @@ const Resource* Drive::Root() const
|
||||||
|
|
||||||
const Resource* Drive::Child( const Resource *parent, std::size_t idx ) 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) ) ;
|
return Find( parent->At(idx) ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue