~ubuntu-branches/ubuntu/precise/guayadeque/precise

« back to all changes in this revision

Viewing changes to src/PlayListFile.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2011-05-14 15:08:03 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110514150803-8b5evqetnaj35j34
Tags: 0.3.1~dfsg0-1
* New upstream release.
* Strip wxsqlite3 stuff out of upstream's tarballs.
* Update get-orig-source target in debian/rules.
* Update gbp config file.
* Bump Standards.
* Build-depend on libwxsqlite3-2.8-dev
* Enable parallel builds.
* Link binaries against the system-wide copy of wxsqlite3.
* Point sources to the correct wxcurl's headers location.
* Update copyright file as per DEP-5
* Improve debian/watch to handle the ~dfsg\d* suffix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// -------------------------------------------------------------------------------- //
2
 
//      Copyright (C) 2008-2010 J.Rios
 
2
//      Copyright (C) 2008-2011 J.Rios
3
3
//      anonbeat@gmail.com
4
4
//
5
5
//    This Program is free software; you can redistribute it and/or modify
6
6
//    it under the terms of the GNU General Public License as published by
7
 
//    the Free Software Foundation; either version 2, or (at your option)
 
7
//    the Free Software Foundation; either version 3, or (at your option)
8
8
//    any later version.
9
9
//
10
10
//    This Program is distributed in the hope that it will be useful,
34
34
WX_DEFINE_OBJARRAY(guStationPlayList);
35
35
 
36
36
// -------------------------------------------------------------------------------- //
 
37
// guStationPlayListItem
 
38
// -------------------------------------------------------------------------------- //
 
39
wxString guStationPlayListItem::GetLocation( const bool relative, const wxString &pathbase )
 
40
{
 
41
    if( relative )
 
42
    {
 
43
        wxFileName FileName( m_Location );
 
44
        if( FileName.MakeRelativeTo( pathbase ) )
 
45
        {
 
46
            return FileName.GetFullPath();
 
47
        }
 
48
    }
 
49
    return m_Location;
 
50
}
 
51
 
 
52
// -------------------------------------------------------------------------------- //
37
53
guPlayListFile::guPlayListFile( const wxString &uri )
38
54
{
39
55
    if( !uri.IsEmpty() )
127
143
}
128
144
 
129
145
// -------------------------------------------------------------------------------- //
130
 
bool guPlayListFile::Save( const wxString &filename )
 
146
bool guPlayListFile::Save( const wxString &filename, const bool relative )
131
147
{
132
148
    if( filename.Lower().EndsWith( wxT( ".pls" ) ) )
133
149
    {
134
 
        return WritePlsFile( filename );
 
150
        return WritePlsFile( filename, relative );
135
151
    }
136
152
    else if( filename.Lower().EndsWith( wxT( ".xspf" ) ) )
137
153
    {
138
 
        return WriteXspfFile( filename );
 
154
        return WriteXspfFile( filename, relative );
139
155
    }
140
156
    else if( filename.Lower().EndsWith( wxT( ".asx" ) ) )
141
157
    {
142
 
        return WriteAsxFile( filename );
 
158
        return WriteAsxFile( filename, relative );
143
159
    }
144
160
    else
145
161
    {
146
162
        wxString FileName = filename;
147
163
        if( !FileName.Lower().EndsWith( wxT( ".m3u" ) ) )
148
164
            FileName += wxT( ".m3u" );
149
 
        return WriteM3uFile( FileName );
 
165
        return WriteM3uFile( FileName, relative );
150
166
    }
151
167
    return false;
152
168
}
443
459
}
444
460
 
445
461
// -------------------------------------------------------------------------------- //
446
 
bool guPlayListFile::WritePlsFile( const wxString &filename )
 
462
bool guPlayListFile::WritePlsFile( const wxString &filename, const bool relative )
447
463
{
448
464
    wxFile PlsFile;
449
465
    if( PlsFile.Create( filename, true ) && PlsFile.IsOpened() )
453
469
        PlsFile.Write( wxString::Format( wxT( "numberofentries=%u\n" ), Count ) );
454
470
        for( int Index = 0; Index < Count; Index++ )
455
471
        {
456
 
            PlsFile.Write( wxString::Format( wxT( "File%u=%s\n" ), Index + 1, m_PlayList[ Index ].m_Location.c_str() ) );
457
 
            PlsFile.Write( wxString::Format( wxT( "Title%u=%s\n" ), Index + 1, m_PlayList[ Index ].m_Name.c_str() ) );
 
472
            PlsFile.Write( wxString::Format( wxT( "File%u=%s\n" ), Index + 1,
 
473
                                m_PlayList[ Index ].GetLocation( relative, wxPathOnly( filename ) ).c_str() ) );
 
474
            PlsFile.Write( wxString::Format( wxT( "Title%u=%s\n" ), Index + 1,
 
475
                                m_PlayList[ Index ].m_Name.c_str() ) );
458
476
        }
459
477
        PlsFile.Close();
460
478
    }
466
484
}
467
485
 
468
486
// -------------------------------------------------------------------------------- //
469
 
bool guPlayListFile::WriteM3uFile( const wxString &filename )
 
487
bool guPlayListFile::WriteM3uFile( const wxString &filename, const bool relative )
470
488
{
471
489
    wxFile M3uFile;
472
490
    if( M3uFile.Create( filename, true ) && M3uFile.IsOpened() )
475
493
        int Count = m_PlayList.Count();
476
494
        for( int Index = 0; Index < Count; Index++ )
477
495
        {
478
 
            M3uFile.Write( m_PlayList[ Index ].m_Location );
 
496
            M3uFile.Write( m_PlayList[ Index ].GetLocation( relative, wxPathOnly( filename ) ) );
479
497
            M3uFile.Write( wxT( "\n" ) );
480
498
        }
481
499
        M3uFile.Close();
488
506
}
489
507
 
490
508
// -------------------------------------------------------------------------------- //
491
 
bool guPlayListFile::WriteXspfFile( const wxString &filename )
 
509
bool guPlayListFile::WriteXspfFile( const wxString &filename, const bool relative )
492
510
{
493
511
    wxXmlDocument OutXml;
494
512
    //OutXml.SetRoot(  );
507
525
        wxXmlNode * TrackNode = new wxXmlNode( wxXML_ELEMENT_NODE, wxT( "track" ) );
508
526
 
509
527
        wxXmlNode * LocationNode = new wxXmlNode( wxXML_ELEMENT_NODE, wxT( "location" ) );
510
 
        wxXmlNode * LocationNodeVal = new wxXmlNode( wxXML_TEXT_NODE, wxT( "location" ), m_PlayList[ Index ].m_Location );
 
528
        wxXmlNode * LocationNodeVal = new wxXmlNode( wxXML_TEXT_NODE, wxT( "location" ), m_PlayList[ Index ].GetLocation( relative, wxPathOnly( filename ) ) );
511
529
        LocationNode->AddChild( LocationNodeVal );
512
530
 
513
531
        wxXmlNode * TitleNode = new wxXmlNode( wxXML_ELEMENT_NODE, wxT( "title" ) );
525
543
}
526
544
 
527
545
// -------------------------------------------------------------------------------- //
528
 
bool guPlayListFile::WriteAsxFile( const wxString &filename )
 
546
bool guPlayListFile::WriteAsxFile( const wxString &filename, const bool relative )
529
547
{
530
548
    wxXmlDocument OutXml;
531
549
    //OutXml.SetRoot(  );
542
560
        wxXmlNode * EntryNode = new wxXmlNode( wxXML_ELEMENT_NODE, wxT( "entry" ) );
543
561
 
544
562
        wxXmlNode * RefNode = new wxXmlNode( wxXML_ELEMENT_NODE, wxT( "ref" ) );
545
 
        wxXmlProperty * RefNodeVal = new wxXmlProperty( wxT( "href" ), m_PlayList[ Index ].m_Location, NULL );
 
563
        wxXmlProperty * RefNodeVal = new wxXmlProperty( wxT( "href" ), m_PlayList[ Index ].GetLocation( relative, wxPathOnly( filename ) ), NULL );
546
564
        RefNode->SetProperties( RefNodeVal );
547
565
 
548
566
        wxXmlNode * TitleNode = new wxXmlNode( wxXML_ELEMENT_NODE, wxT( "title" ) );