WorkspaceWorker.cpp 2.12 KB
Newer Older
1 2 3
/*****************************************************************************
 * WorkspaceWorker.cpp: The Workspace worker
 *****************************************************************************
4
 * Copyright (C) 2008-2016 VideoLAN
5
 *
6
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
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 25 26
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

27
#include "Project/WorkspaceWorker.h"
28

29
#include "Media/Media.h"
30
#include "Settings/Settings.h"
31
#include "Tools/VlmcDebug.h"
32

33
#include <cerrno>
34 35
#include <unistd.h>

36 37 38
#include <QFile>
#include <QFileInfo>

39 40 41
WorkspaceWorker::WorkspaceWorker( Media *media, const QString &dest ) :
    m_media( media ),
    m_dest( dest )
42 43 44 45 46 47 48
{
    connect( this, SIGNAL( finished() ), this, SLOT( deleteLater() ) );
}

void
WorkspaceWorker::run()
{
49
    bool            hardLinkOk = false;
50

51
#ifdef Q_OS_UNIX
52
    errno = 0;
53
    if ( link( m_media->mrl().toUtf8().constData(),
54
          m_dest.toUtf8().constData() ) < 0 )
55
    {
56
        vlmcDebug() << "Can't create hard link:" << strerror(errno) << "falling back to"
57 58 59 60
                " hard copy mode.";
    }
    else
    {
61
        vlmcDebug() << "Media hard linked to:" << m_dest;
62 63 64 65 66 67
        hardLinkOk = true;
    }
#endif

    if ( hardLinkOk == false )
    {
68
        QFile::copy( m_media->mrl(), m_dest );
69
        vlmcDebug() << "Media copied to:" << m_dest;
70
    }
71
    emit copied( m_media, m_dest );
72
}