File indexing completed on 2024-05-12 04:51:08

0001 /*
0002     SPDX-FileCopyrightText: 2003 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-FileCopyrightText: 2009 Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
0004     SPDX-FileCopyrightText: 2010-2011 Michal Malek <michalm@jabster.pl>
0005     SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 
0011 #include "k3bmovixfileitem.h"
0012 #include "k3bmovixdoc.h"
0013 #include "k3bdiritem.h"
0014 
0015 K3b::MovixSubtitleItem::MovixSubtitleItem( const QString& fileName,
0016                                            K3b::MovixDoc& doc,
0017                                            K3b::MovixFileItem* parent,
0018                                            const QString& k3bName )
0019     : K3b::MovixFileItem( fileName, doc, k3bName ),
0020       m_parent( parent )
0021 {
0022 }
0023 
0024 K3b::MovixSubtitleItem::~MovixSubtitleItem()
0025 {
0026 }
0027 
0028 K3b::MovixFileItem::MovixFileItem( const QString& fileName,
0029                                    K3b::MovixDoc& doc,
0030                                    const QString& k3bName )
0031     : K3b::FileItem( fileName, doc, k3bName ),
0032       m_subTitleItem(0)
0033 {
0034 }
0035 
0036 
0037 K3b::MovixFileItem::~MovixFileItem()
0038 {
0039     if( m_subTitleItem ) {
0040         delete m_subTitleItem;
0041         m_subTitleItem = 0;
0042     }
0043 
0044     // remove this from parentdir
0045     // it is important to do it here and not
0046     // rely on the K3b::FileItem destructor because
0047     // otherwise the doc is not informed early enough
0048     if( parent() )
0049         parent()->takeDataItem( this );
0050 }
0051 
0052 
0053 void K3b::MovixFileItem::setK3bName( const QString& newName )
0054 {
0055     K3b::FileItem::setK3bName( newName );
0056 
0057     // take care of the subTitle file
0058     if( m_subTitleItem ) {
0059         m_subTitleItem->setK3bName( subTitleFileName(k3bName()) );
0060     }
0061 }
0062 
0063 QString K3b::MovixFileItem::subTitleFileName( const QString& name )
0064 {
0065     // remove ending from k3bName
0066     QString subName = name;
0067     int pos = subName.lastIndexOf('.');
0068     if( pos > 0 )
0069         subName.truncate( pos );
0070     subName += ".sub";
0071     return subName;
0072 }
0073