ClipProperty.cpp 3.95 KB
Newer Older
1 2 3
/*****************************************************************************
 * ClipProperty.cpp: Handle the clip properties and meta tags edition
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#include "ClipProperty.h"
#include "ui_ClipProperty.h"
25

26
#include "Clip.h"
27 28
#include "ClipMetadataDisplayer.h"
#include "Media.h"
29 30

#include <QInputDialog>
31
#include <QPushButton>
32
#include <QRegExp>
33

34
ClipProperty::ClipProperty( Clip* clip, QWidget *parent ) :
35
    QDialog( parent ),
36
    ui( new Ui::ClipProperty ),
37
    m_clip( clip )
38 39 40 41
{
    ui->setupUi(this);
    connect( this, SIGNAL( accepted() ), this, SLOT( deleteLater() ) );
    connect( this, SIGNAL( rejected() ), this, SLOT( deleteLater() ) );
42

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
43
    setWindowTitle( m_clip->getMedia()->fileInfo()->fileName() + " " + tr( "properties" ) );
44
    //Snapshot
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
45
    ui->snapshotLabel->setPixmap( m_clip->getMedia()->snapshot().scaled( 128, 128, Qt::KeepAspectRatio ) );
46
    //Metatags
47 48 49 50
    const QPushButton* button = ui->buttonBox->button( QDialogButtonBox::Apply );
    Q_ASSERT( button != NULL);
    connect( button, SIGNAL( clicked() ), this, SLOT( apply() ) );

51
    m_model = new QStringListModel( m_clip->metaTags(), this );
52
    ui->metaTagsView->setModel( m_model );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
53

54
    //Notes:
55
    ui->annotationInput->setPlainText( m_clip->notes() );
56

57 58
    connect( ui->addTagsButton, SIGNAL( clicked() ), this, SLOT( addTagsRequired() ) );
    connect( ui->deleteTagsButton, SIGNAL( clicked() ), this, SLOT( removeTagsRequired() ) );
59

60
    ui->metadataContainer->setWatchedClip( clip );
61 62
}

63
ClipProperty::~ClipProperty()
64 65 66 67
{
    delete ui;
}

68 69
void
ClipProperty::changeEvent( QEvent *e )
70 71 72 73 74 75 76 77 78 79 80
{
    QDialog::changeEvent( e );
    switch ( e->type() )
    {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
81

82 83
void
ClipProperty::apply()
84
{
85
    m_clip->setNotes( ui->annotationInput->toPlainText() );
86
    m_clip->setMetaTags( m_model->stringList() );
87
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
88

89 90
void
ClipProperty::addTagsRequired()
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
91 92 93 94 95 96 97
{
    bool                ok;
    QString             newTags = QInputDialog::getText( this, tr( "New tags edition" ),
                                            tr( "Enter tags (you can enter multiple tags, separated by a comma)" ),
                                            QLineEdit::Normal, "", &ok );
    if ( ok == true && newTags.length() > 0 )
    {
98
        QStringList         list = m_model->stringList();
99 100
        QRegExp             regexp( "\\s*,\\s*" );
        QStringList         toAdd = newTags.split( regexp, QString::SkipEmptyParts );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
101
        list.append( toAdd );
102
        m_model->setStringList( list );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
103 104
    }
}
105

106 107
void
ClipProperty::removeTagsRequired()
108
{
109
    QItemSelectionModel     *selected = ui->metaTagsView->selectionModel();
110
    QModelIndexList         listSelected = selected->selectedIndexes();
111
    QStringList             list = m_model->stringList();
112 113
    while ( listSelected.empty() == false )
    {
114
        QVariant    elem = m_model->data( listSelected.first(), Qt::DisplayRole );
115 116 117
        list.removeOne( elem.toString() );
        listSelected.removeFirst();
    }
118
    m_model->setStringList( list );
119
}