extList->setModel( model );
// Buttons' layout
- QHBoxLayout *hbox = new QHBoxLayout;
- hbox->addItem( new QSpacerItem( 1, 1, QSizePolicy::Expanding,
- QSizePolicy::Fixed ) );
+ QDialogButtonBox *buttonsBox = new QDialogButtonBox;
// More information button
butMoreInfo = new QPushButton( QIcon( ":/menu/info" ),
qtr( "More information..." ),
this );
CONNECT( butMoreInfo, clicked(), this, moreInformation() );
- hbox->addWidget( butMoreInfo );
+ buttonsBox->addButton( butMoreInfo, QDialogButtonBox::ActionRole );
// Reload button
ExtensionsManager *EM = ExtensionsManager::getInstance( p_intf );
selectionChanged( const QItemSelection &, const QItemSelection & ),
this,
updateButtons() );
- hbox->addWidget( reload );
+ buttonsBox->addButton( reload, QDialogButtonBox::ResetRole );
- // Add buttons hbox
- layout->addItem( hbox );
+ layout->addWidget( buttonsBox );
updateButtons();
}
void ExtensionTab::moreInformation()
{
QModelIndex index = extList->selectionModel()->selectedIndexes().first();
- ExtensionCopy *ext = (ExtensionCopy*) index.internalPointer();
- if( !ext )
+
+ if( !index.isValid() )
return;
- ExtensionInfoDialog dlg( *ext, p_intf, this );
+ ExtensionInfoDialog dlg( index, p_intf, this );
dlg.exec();
}
/* Safe copy of the extension_t struct */
-class ExtensionCopy
+ExtensionListModel::ExtensionCopy::ExtensionCopy( extension_t *p_ext )
{
-public:
- ExtensionCopy( extension_t *p_ext )
+ name = qfu( p_ext->psz_name );
+ description = qfu( p_ext->psz_description );
+ shortdesc = qfu( p_ext->psz_shortdescription );
+ if( description.isEmpty() )
+ description = shortdesc;
+ if( shortdesc.isEmpty() && !description.isEmpty() )
+ shortdesc = description;
+ title = qfu( p_ext->psz_title );
+ author = qfu( p_ext->psz_author );
+ version = qfu( p_ext->psz_version );
+ url = qfu( p_ext->psz_url );
+ icon = loadPixmapFromData( p_ext->p_icondata, p_ext->i_icondata_size );
+}
+
+ExtensionListModel::ExtensionCopy::~ExtensionCopy()
+{
+ delete icon;
+}
+
+QVariant ExtensionListModel::ExtensionCopy::data( int role ) const
+{
+ switch( role )
{
- name = qfu( p_ext->psz_name );
- description = qfu( p_ext->psz_description );
- shortdesc = qfu( p_ext->psz_shortdescription );
- if( description.isEmpty() )
- description = shortdesc;
- if( shortdesc.isEmpty() && !description.isEmpty() )
- shortdesc = description;
- title = qfu( p_ext->psz_title );
- author = qfu( p_ext->psz_author );
- version = qfu( p_ext->psz_version );
- url = qfu( p_ext->psz_url );
- icon = loadPixmapFromData( p_ext->p_icondata, p_ext->i_icondata_size );
+ case Qt::DisplayRole:
+ return title;
+ case Qt::DecorationRole:
+ if ( !icon ) return QPixmap( ":/logo/vlc48.png" );
+ return *icon;
+ case DescriptionRole:
+ return shortdesc;
+ case VersionRole:
+ return version;
+ case AuthorRole:
+ return author;
+ case LinkRole:
+ return url;
+ case NameRole:
+ return name;
+ default:
+ return QVariant();
}
- ~ExtensionCopy() { delete icon; }
-
- QString name, title, description, shortdesc, author, version, url;
- QPixmap *icon;
-};
+}
/* Extensions list model for the QListView */
if( !index.isValid() )
return QVariant();
- switch( role )
- {
- default:
- return QVariant();
- }
+ ExtensionCopy * extension =
+ static_cast<ExtensionCopy *>(index.internalPointer());
+
+ return extension->data( role );
}
QModelIndex ExtensionListModel::index( int row, int column,
const QStyleOptionViewItem &option,
const QModelIndex &index ) const
{
- ExtensionCopy *ext = ( ExtensionCopy* ) index.internalPointer();
- assert( ext != NULL );
-
int width = option.rect.width();
// Pixmap: buffer where to draw
QFontMetrics metrics = option.fontMetrics;
// Icon
- if( ext->icon != NULL )
+ QPixmap icon = index.data( Qt::DecorationRole ).value<QPixmap>();
+ if( !icon.isNull() )
{
pixpaint->drawPixmap( 7, 7, 2*metrics.height(), 2*metrics.height(),
- *ext->icon );
+ icon );
}
// Title: bold
pixpaint->drawText( QRect( 17 + 2 * metrics.height(), 7,
width - 40 - 2 * metrics.height(),
metrics.height() ),
- Qt::AlignLeft, ext->title );
+ Qt::AlignLeft, index.data( Qt::DisplayRole ).toString() );
// Short description: normal
font.setBold( false );
pixpaint->drawText( QRect( 17 + 2 * metrics.height(),
7 + metrics.height(), width - 40,
metrics.height() ),
- Qt::AlignLeft, ext->shortdesc );
+ Qt::AlignLeft, index.data( ExtensionListModel::DescriptionRole ).toString() );
// Flush paint operations
delete pixpaint;
/* "More information" dialog */
-ExtensionInfoDialog::ExtensionInfoDialog( const ExtensionCopy& extension,
+ExtensionInfoDialog::ExtensionInfoDialog( const QModelIndex &index,
intf_thread_t *p_intf,
QWidget *parent )
: QVLCDialog( parent, p_intf )
setWindowModality( Qt::WindowModal );
// Window title
- setWindowTitle( qtr( "About" ) + " " + extension.title );
+ setWindowTitle( qtr( "About" ) + " " + index.data(Qt::DisplayRole).toString() );
// Layout
QGridLayout *layout = new QGridLayout( this );
// Icon
QLabel *icon = new QLabel( this );
- if( !extension.icon )
- {
- QPixmap pix( ":/logo/vlc48.png" );
- icon->setPixmap( pix );
- }
- else
- {
- icon->setPixmap( *extension.icon );
- }
+ QPixmap pix = index.data(Qt::DecorationRole).value<QPixmap>();
+ Q_ASSERT( !pix.isNull() );
+ icon->setPixmap( pix );
icon->setAlignment( Qt::AlignCenter );
icon->setFixedSize( 48, 48 );
layout->addWidget( icon, 1, 0, 2, 1 );
// Title
- QLabel *label = new QLabel( extension.title, this );
+ QLabel *label = new QLabel( index.data(Qt::DisplayRole).toString(), this );
QFont font = label->font();
font.setBold( true );
font.setPointSizeF( font.pointSizeF() * 1.3f );
// Version
label = new QLabel( "<b>" + qtr( "Version" ) + ":</b>", this );
layout->addWidget( label, 1, 1, 1, 1, Qt::AlignBottom );
- label = new QLabel( extension.version, this );
+ label = new QLabel( index.data(ExtensionListModel::VersionRole).toString(), this );
layout->addWidget( label, 1, 2, 1, 2, Qt::AlignBottom );
// Author
label = new QLabel( "<b>" + qtr( "Author" ) + ":</b>", this );
layout->addWidget( label, 2, 1, 1, 1, Qt::AlignTop );
- label = new QLabel( extension.author, this );
+ label = new QLabel( index.data(ExtensionListModel::AuthorRole).toString(), this );
layout->addWidget( label, 2, 2, 1, 2, Qt::AlignTop );
// Description
label = new QLabel( this );
- label->setText( extension.description );
+ label->setText( index.data(ExtensionListModel::DescriptionRole).toString() );
label->setWordWrap( true );
label->setOpenExternalLinks( true );
layout->addWidget( label, 4, 0, 1, -1 );
label = new QLabel( "<b>" + qtr( "Website" ) + ":</b>", this );
layout->addWidget( label, 5, 0, 1, 2 );
label = new QLabel( QString("<a href=\"%1\">%2</a>")
- .arg( extension.url ).arg( extension.url )
+ .arg( index.data(ExtensionListModel::LinkRole).toString() )
+ .arg( index.data(ExtensionListModel::LinkRole).toString() )
, this );
label->setOpenExternalLinks( true );
layout->addWidget( label, 5, 2, 1, -1 );
// Script file
label = new QLabel( "<b>" + qtr( "File" ) + ":</b>", this );
layout->addWidget( label, 6, 0, 1, 2 );
- QLineEdit *line = new QLineEdit( extension.name, this );
+ QLineEdit *line =
+ new QLineEdit( index.data(ExtensionListModel::NameRole).toString(), this );
line->setReadOnly( true );
layout->addWidget( line, 6, 2, 1, -1 );