Skip to content
Browse files

show title and mime in GUI

  • Loading branch information...
1 parent 15b3b85 commit d5ca8e0afaa433696b71abd0faeb4459941c93f1 @nestal nestal committed Apr 30, 2013
Showing with 38 additions and 3 deletions.
  1. +0 −1 bgrive/src/DriveModel.cc
  2. +0 −1 bgrive/src/DriveModel.hh
  3. +24 −1 bgrive/src/MainWnd.cc
  4. +8 −0 bgrive/src/MainWnd.hh
  5. +6 −0 libgrive/src/drive2/Drive.cc
View
1 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() ;
View
1 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 :
View
25 bgrive/src/MainWnd.cc
@@ -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
8 bgrive/src/MainWnd.hh
@@ -25,6 +25,8 @@
#include "DriveModel.hh"
+class QModelIndex ;
+
namespace gr {
namespace http
@@ -40,6 +42,12 @@ 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
6 libgrive/src/drive2/Drive.cc
@@ -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) ) ;
}

0 comments on commit d5ca8e0

Please sign in to comment.
Something went wrong with that request. Please try again.