WorkspaceWorker.cpp 2.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*****************************************************************************
 * WorkspaceWorker.cpp: The Workspace worker
 *****************************************************************************
 * Copyright (C) 2008-2010 VideoLAN
 *
 * 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 "WorkspaceWorker.h"

#include "Media.h"
#include "SettingsManager.h"

28
#include <cerrno>
29 30 31 32 33 34 35 36 37 38 39 40 41 42
#include <QFile>
#include <QFileInfo>

#include <QtDebug>

WorkspaceWorker::WorkspaceWorker( Media *media ) :
    m_media( media )
{
    connect( this, SIGNAL( finished() ), this, SLOT( deleteLater() ) );
}

void
WorkspaceWorker::run()
{
43
    const QString   &projectPath = VLMC_PROJECT_GET_STRING( "general/Workspace" );
44
    const QString   dest = projectPath + '/' + m_media->fileInfo()->fileName();
45
    bool            hardLinkOk = false;
46

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#ifdef Q_OS_UNIX
    if ( link( m_media->fileInfo()->absoluteFilePath().toStdString().c_str(),
          dest.toStdString().c_str() ) < 0 )
    {
        qDebug() << "Can't create hard link:" << strerror(errno) << "falling back to"
                " hard copy mode.";
    }
    else
    {
        qDebug() << "Media hard linked to:" << dest;
        hardLinkOk = true;
    }
#endif

    if ( hardLinkOk == false )
    {
        QFile           file( m_media->fileInfo()->absoluteFilePath() );

        file.copy( m_media->fileInfo()->absoluteFilePath(), dest );
        qDebug() << "Media copied to:" << dest;
    }
68 69
    emit copied( m_media, dest );
}