Library.cpp 3.1 KB
Newer Older
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
1
2
3
/*****************************************************************************
 * Library.cpp: Multimedia library
 *****************************************************************************
4
 * Copyright (C) 2008-2016 VideoLAN
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
5
 *
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
6
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 *
 * 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.
 *****************************************************************************/

23
24
/** \file
  * This file the library contains class implementation.
25
  * It's the backend part of the Library widget of vlmc.
26
  * It can load and unload Medias (Medias.h/Media.cpp)
27
  * It can load and unload Clips (Clip.h/Clip.cpp)
28
29
  */

30
31
32
33
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
34
#include "Library.h"
35
36
#include "Media/Clip.h"
#include "Media/Media.h"
37
#include "Project/Project.h"
38
#include "Settings/Settings.h"
39
#include "Tools/VlmcDebug.h"
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
40

luyikei's avatar
luyikei committed
41
#include <QVariant>
42
43
44
#include <QHash>
#include <QUuid>

luyikei's avatar
luyikei committed
45
Library::Library( Settings *projectSettings )
46
    : m_cleanState( true )
luyikei's avatar
luyikei committed
47
    , m_settings( new Settings )
48
{
luyikei's avatar
luyikei committed
49
    m_settings->createVar( SettingValue::List, QString( "medias" ), QVariantList(), "", "", SettingValue::Nothing );
luyikei's avatar
luyikei committed
50
51
52
    connect( m_settings, &Settings::postLoad, this, &Library::postLoad, Qt::DirectConnection );
    connect( m_settings, &Settings::preSave, this, &Library::preSave, Qt::DirectConnection );

luyikei's avatar
luyikei committed
53
54
55
    projectSettings->addSettings( "Library", *m_settings );
}

luyikei's avatar
luyikei committed
56
57
58
59
void
Library::preSave()
{
    QVariantList l;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
60
    for ( auto val : m_media )
luyikei's avatar
luyikei committed
61
62
        l << val->toVariant();
    m_settings->value( "medias" )->set( l );
63
    setCleanState( true );
luyikei's avatar
luyikei committed
64
65
66
67
68
69
}

void
Library::postLoad()
{
    for ( const auto& var : m_settings->value( "medias" )->get().toList() )
70
71
72
73
    {
        auto m = Media::fromVariant( var );
        addMedia( m );
    }
luyikei's avatar
luyikei committed
74
75
}

luyikei's avatar
luyikei committed
76
77
78
Library::~Library()
{
    delete m_settings;
79
80
81
}

void
82
Library::addMedia( QSharedPointer<Media> media )
83
84
{
    setCleanState( false );
85
    if ( m_media.contains( media->id() ) )
86
        return;
87
    m_media[media->id()] = media;
88
89
90
91
92
93
94
95
}

bool
Library::isInCleanState() const
{
    return m_cleanState;
}

96
QSharedPointer<Media>
97
Library::media( qint64 mediaId )
98
{
99
    return m_media.value( mediaId );
100
101
}

102
Clip*
103
Library::clip( const QUuid& uuid )
104
105
106
107
108
109
110
111
{
    return m_clips.value( uuid );

}

void
Library::clear()
{
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
112
    m_media.clear();
113
114
115
116
    m_clips.clear();
    setCleanState( true );
}

117
118
119
120
121
122
123
124
125
void
Library::setCleanState( bool newState )
{
    if ( newState != m_cleanState )
    {
        m_cleanState = newState;
        emit cleanStateChanged( newState );
    }
}