~ubuntu-branches/debian/sid/smplayer/sid

« back to all changes in this revision

Viewing changes to src/playlist.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Maia Kozheva
  • Date: 2009-03-31 23:05:43 UTC
  • mto: (1.1.9 upstream) (3.1.2 squeeze)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20090331230543-nsklbxenl2hf2n6h
Tags: upstream-0.6.7
ImportĀ upstreamĀ versionĀ 0.6.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*  smplayer, GUI front-end for mplayer.
2
 
    Copyright (C) 2006-2008 Ricardo Villalba <rvm@escomposlinux.org>
 
2
    Copyright (C) 2006-2009 Ricardo Villalba <rvm@escomposlinux.org>
3
3
 
4
4
    This program is free software; you can redistribute it and/or modify
5
5
    it under the terms of the GNU General Public License as published by
78
78
#else
79
79
        automatically_get_info = true;
80
80
#endif
 
81
        play_files_from_start = true;
81
82
 
82
83
        modified = false;
83
84
 
89
90
        createActions();
90
91
        createToolbar();
91
92
 
92
 
        connect( core, SIGNAL(mediaFinished()), this, SLOT(playNext()) );
 
93
        connect( core, SIGNAL(mediaFinished()), this, SLOT(playNext()), Qt::QueuedConnection );
93
94
        connect( core, SIGNAL(mediaLoaded()), this, SLOT(getMediaInfo()) );
94
95
 
95
96
        QVBoxLayout *layout = new QVBoxLayout;
111
112
#endif
112
113
 
113
114
        setAcceptDrops(true);
 
115
        setAttribute(Qt::WA_NoMousePropagation);
114
116
 
115
117
        // Random seed
116
118
        QTime t;
138
140
 
139
141
void Playlist::createTable() {
140
142
        listView = new MyTableWidget( 0, COL_TIME + 1, this);
 
143
        listView->setObjectName("playlist_table");
141
144
        listView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
142
145
        listView->setSelectionBehavior(QAbstractItemView::SelectRows);
143
146
        listView->setSelectionMode(QAbstractItemView::ExtendedSelection);
151
154
        listView->horizontalHeader()->setResizeMode(COL_TIME, QHeaderView::ResizeToContents);
152
155
        listView->horizontalHeader()->setResizeMode(COL_PLAY, QHeaderView::ResizeToContents);
153
156
        */
154
 
        listView->setIconSize( Images::icon("ok_small").size() );
 
157
        listView->setIconSize( Images::icon("ok").size() );
155
158
 
156
159
#if DRAG_ITEMS
157
160
        listView->setSelectionMode(QAbstractItemView::SingleSelection);
335
338
}
336
339
 
337
340
void Playlist::updateView() {
 
341
        qDebug("Playlist::updateView");
 
342
 
338
343
        listView->setRowCount( pl.count() );
339
344
 
340
345
        //QString number;
347
352
                time = Helper::formatTime( (int) pl[n].duration() );
348
353
                
349
354
                //listView->setText(n, COL_POS, number);
350
 
                qDebug("name: '%s'", name.toUtf8().data());
 
355
                qDebug("Playlist::updateView: name: '%s'", name.toUtf8().data());
351
356
                listView->setText(n, COL_NAME, name);
352
357
                listView->setText(n, COL_TIME, time);
353
358
 
354
359
                if (pl[n].played()) {
355
 
                        listView->setIcon(n, COL_PLAY, Images::icon("ok_small") );
 
360
                        listView->setIcon(n, COL_PLAY, Images::icon("ok") );
356
361
                } else {
357
362
                        listView->setIcon(n, COL_PLAY, QPixmap() );
358
363
                }
422
427
        #endif
423
428
 
424
429
        // Test if already is in the list
425
 
        bool exists = FALSE;
426
 
        PlaylistItemList::iterator it;
427
 
        for ( it = pl.begin(); it != pl.end(); ++it ) {
428
 
                if ( (*it).filename() == filename ) {
429
 
                        exists = TRUE;
 
430
        bool exists = false;
 
431
        for ( int n = 0; n < pl.count(); n++) {
 
432
                if ( pl[n].filename() == filename ) {
 
433
                        exists = true;
 
434
                        int last_item =  pl.count()-1;
 
435
                        pl.move(n, last_item);
 
436
                        qDebug("Playlist::addItem: item already in list (%d), moved to %d", n, last_item);
 
437
                        if (current_item > -1) {
 
438
                                if (current_item > n) current_item--;
 
439
                                else
 
440
                                if (current_item == n) current_item = last_item;
 
441
                        }
430
442
                        break;
431
443
                }
432
444
        }
434
446
        if (!exists) {
435
447
                if (name.isEmpty()) {
436
448
                        QFileInfo fi(filename);
437
 
                        if (fi.exists()) {
 
449
                        // Let's see if it looks like a file (no dvd://1 or something)
 
450
                        if (filename.indexOf(QRegExp("^.*://.*")) == -1) {
438
451
                                // Local file
439
452
                                name = fi.fileName(); //fi.baseName(TRUE);
440
453
                        } else {
445
458
                pl.append( PlaylistItem(filename, name, duration) );
446
459
                //setModified( true ); // Better set the modified on a higher level
447
460
        } else {
448
 
                qDebug(" Not added. File already in the list");
 
461
                qDebug("Playlist::addItem: item not added, already in the list");
449
462
        }
450
463
}
451
464
 
767
780
        qDebug("Playlist::playItem: %d (count:%d)", n, pl.count());
768
781
 
769
782
        if ( (n >= pl.count()) || (n < 0) ) {
770
 
                qDebug(" out of range");
 
783
                qDebug("Playlist::playItem: out of range");
771
784
                emit playlistEnded();
772
785
                return;
773
786
        }
780
793
        if (!filename.isEmpty()) {
781
794
                //pl[n].setPlayed(TRUE);
782
795
                setCurrentItem(n);
783
 
                core->open(filename, 0);
 
796
                if (play_files_from_start) 
 
797
                        core->open(filename, 0);
 
798
                else
 
799
                        core->open(filename);
784
800
        }
785
801
 
786
802
}
810
826
 
811
827
void Playlist::playPrev() {
812
828
        qDebug("Playlist::playPrev");
813
 
        playItem( current_item-1 );
 
829
        if (current_item > 0) {
 
830
                playItem( current_item-1 );
 
831
        } else {
 
832
                if (pl.count() > 1) playItem( pl.count() -1 );
 
833
        }
814
834
}
815
835
 
816
836
void Playlist::getMediaInfo() {
898
918
                if ( (get_info) && (QFile::exists((*it))) ) {
899
919
                        data = InfoProvider::getInfo( (*it) );
900
920
                        addItem( (*it), data.displayName(), data.duration );
901
 
                        updateView();
902
 
                        qApp->processEvents();
 
921
                        //updateView();
 
922
                        //qApp->processEvents();
903
923
                } else {
904
924
                        addItem( (*it), "", 0 );
905
925
                }
907
927
        addItem( (*it), "", 0 );
908
928
#endif
909
929
 
910
 
                // FIXME: set latest_dir only if the file is a local file,
911
 
        // to avoid that dvd:, vcd: and so on will be used.
912
 
                /* latest_dir = QFileInfo((*it)).dirPath(TRUE); */
 
930
                if (QFile::exists(*it)) {
 
931
                        latest_dir = QFileInfo((*it)).absolutePath();
 
932
                }
 
933
 
913
934
        ++it;
914
935
    }
915
936
#if USE_INFOPROVIDER
917
938
#endif
918
939
        updateView();
919
940
 
920
 
        qDebug( " * latest_dir: '%s'", latest_dir.toUtf8().data() );
 
941
        qDebug( "Playlist::addFiles: latest_dir: '%s'", latest_dir.toUtf8().constData() );
921
942
}
922
943
 
923
944
void Playlist::addFile(QString file, AutoGetInfo auto_get_info) {
1136
1157
        d.setDirectoryRecursion(recursive_add_directory);
1137
1158
        d.setAutoGetInfo(automatically_get_info);
1138
1159
        d.setSavePlaylistOnExit(save_playlist_in_config);
 
1160
        d.setPlayFilesFromStart(play_files_from_start);
1139
1161
 
1140
1162
        if (d.exec() == QDialog::Accepted) {
1141
1163
                recursive_add_directory = d.directoryRecursion();
1142
1164
                automatically_get_info = d.autoGetInfo();
1143
1165
                save_playlist_in_config = d.savePlaylistOnExit();
 
1166
                play_files_from_start = d.playFilesFromStart();
1144
1167
        }
1145
1168
}
1146
1169
 
1223
1246
        set->setValue( "auto_get_info", automatically_get_info );
1224
1247
        set->setValue( "recursive_add_directory", recursive_add_directory );
1225
1248
        set->setValue( "save_playlist_in_config", save_playlist_in_config );
 
1249
        set->setValue( "play_files_from_start", play_files_from_start );
1226
1250
 
1227
 
//#if !DOCK_PLAYLIST
1228
 
        set->setValue( "window_width", size().width() );
1229
 
        set->setValue( "window_height", size().height() );
1230
 
//#endif
 
1251
#if !DOCK_PLAYLIST
 
1252
        set->setValue( "size", size() );
 
1253
#endif
1231
1254
        set->setValue( "latest_dir", latest_dir );
1232
1255
 
1233
1256
        set->endGroup();
1262
1285
        automatically_get_info = set->value( "auto_get_info", automatically_get_info ).toBool();
1263
1286
        recursive_add_directory = set->value( "recursive_add_directory", recursive_add_directory ).toBool();
1264
1287
        save_playlist_in_config = set->value( "save_playlist_in_config", save_playlist_in_config ).toBool();
 
1288
        play_files_from_start = set->value( "play_files_from_start", play_files_from_start ).toBool();
1265
1289
 
1266
 
//#if !DOCK_PLAYLIST
1267
 
        QSize s;
1268
 
        s.setWidth( set->value( "window_width", size().width() ).toInt() );
1269
 
        s.setHeight( set->value( "window_height", size().height() ).toInt() );
1270
 
        resize( s );
1271
 
//#endif
 
1290
#if !DOCK_PLAYLIST
 
1291
        resize( set->value("size", size()).toSize() );
 
1292
#endif
1272
1293
 
1273
1294
        latest_dir = set->value( "latest_dir", latest_dir ).toString();
1274
1295