1
/* smplayer, GUI front-end for mplayer.
2
Copyright (C) 2007 Ricardo Villalba <rvm@escomposlinux.org>
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
#include <qtextstream.h>
27
#include "filedialog.h"
29
#include <qfileinfo.h>
30
#include <qmessagebox.h>
31
#include <qpushbutton.h>
32
#include <qpopupmenu.h>
33
#include <qdragobject.h>
35
#include <qdatetime.h>
36
#include <qsettings.h>
37
#include <qinputdialog.h>
38
#include <qtoolbutton.h>
46
#include "preferences.h"
62
Playlist::Playlist( Core *c, QWidget * parent, const char * name, WFlags f)
63
: QMainWindow(parent, name, f)
72
setCentralWidget( listView );
82
setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding );
85
//setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum );
86
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
94
srand( t.hour() * 3600 + t.minute() * 60 + t.second() );
98
// Save config every 5 minutes.
99
save_timer = new QTimer(this);
100
connect( save_timer, SIGNAL(timeout()), this, SLOT(maybeSaveSettings()) );
101
save_timer->start( 5 * 60000 );
104
Playlist::~Playlist() {
108
void Playlist::setModified(bool mod) {
109
qDebug("Playlist::setModified: %d", mod);
112
emit modifiedChanged(modified);
115
void Playlist::createTable() {
116
listView = new MyTable( this, "listView" );
117
listView->setSizeHint(QSize(100,100));
119
listView->setShowGrid( FALSE );
120
listView->setNumCols(COL_TIME + 1);
121
listView->setReadOnly(TRUE);
122
listView->setFocusStyle(QTable::FollowStyle);
123
listView->setSelectionMode(QTable::MultiRow);
124
//listView->verticalHeader()->hide();
125
listView->setSorting(FALSE);
127
connect( listView, SIGNAL(doubleClicked(int,int,int,const QPoint &)),
128
this, SLOT(itemDoubleClicked(int)) );
130
connect( core, SIGNAL(mediaFinished()), this, SLOT(playNext()) );
132
connect( core, SIGNAL(mediaLoaded()),
133
this, SLOT(getMediaInfo()) );
136
void Playlist::createActions() {
137
openAct = new MyAction(this, "pl_open");
138
connect( openAct, SIGNAL(activated()), this, SLOT(load()) );
140
saveAct = new MyAction(this, "pl_save");
141
connect( saveAct, SIGNAL(activated()), this, SLOT(save()) );
143
playAct = new MyAction(this, "pl_play");
144
connect( playAct, SIGNAL(activated()), this, SLOT(playCurrent()) );
146
nextAct = new MyAction(Qt::Key_N /*Qt::Key_Greater*/, this, "pl_next");
147
connect( nextAct, SIGNAL(activated()), this, SLOT(playNext()) );
149
prevAct = new MyAction(Qt::Key_P /*Qt::Key_Less*/, this, "pl_prev");
150
connect( prevAct, SIGNAL(activated()), this, SLOT(playPrev()) );
152
moveUpAct = new MyAction(this, "pl_move_up");
153
connect( moveUpAct, SIGNAL(activated()), this, SLOT(upItem()) );
155
moveDownAct = new MyAction(this, "pl_move_down");
156
connect( moveDownAct, SIGNAL(activated()), this, SLOT(downItem()) );
158
repeatAct = new MyAction(this, "pl_repeat");
159
repeatAct->setToggleAction(true);
161
shuffleAct = new MyAction(this, "pl_shuffle");
162
shuffleAct->setToggleAction(true);
165
addCurrentAct = new MyAction(this, "pl_add_current");
166
connect( addCurrentAct, SIGNAL(activated()), this, SLOT(addCurrentFile()) );
168
addFilesAct = new MyAction(this, "pl_add_files");
169
connect( addFilesAct, SIGNAL(activated()), this, SLOT(addFiles()) );
171
addDirectoryAct = new MyAction(this, "pl_add_directory");
172
connect( addDirectoryAct, SIGNAL(activated()), this, SLOT(addDirectory()) );
175
removeSelectedAct = new MyAction(this, "pl_remove_selected");
176
connect( removeSelectedAct, SIGNAL(activated()), this, SLOT(removeSelected()) );
178
removeAllAct = new MyAction(this, "pl_remove_all");
179
connect( removeAllAct, SIGNAL(activated()), this, SLOT(removeAll()) );
182
editAct = new MyAction(this, "pl_edit");
183
connect( editAct, SIGNAL(activated()), this, SLOT(editCurrentItem()) );
186
void Playlist::createToolbar() {
187
toolbar = new QToolBar(this, "toolbar");
188
toolbar->setResizeEnabled(false);
189
toolbar->setMovingEnabled(false);
190
addDockWindow(toolbar, Qt::DockBottom );
192
openAct->addTo( toolbar );
193
saveAct->addTo( toolbar );
194
toolbar->addSeparator();
196
add_menu = new QPopupMenu( this, "add_menu" );
197
addCurrentAct->addTo( add_menu );
198
addFilesAct->addTo( add_menu );
199
addDirectoryAct->addTo( add_menu );
201
add_button = new QToolButton( toolbar, "add_button" );
202
add_button->setPopup( add_menu );
203
add_button->setPopupDelay(1);
205
remove_menu = new QPopupMenu( this, "remove_menu" );
206
removeSelectedAct->addTo( remove_menu );
207
removeAllAct->addTo( remove_menu );
209
remove_button = new QToolButton( toolbar, "remove_button" );
210
remove_button->setPopup( remove_menu );
211
remove_button->setPopupDelay(1);
213
toolbar->addSeparator();
214
playAct->addTo( toolbar );
215
toolbar->addSeparator();
216
prevAct->addTo( toolbar );
217
nextAct->addTo( toolbar );
218
toolbar->addSeparator();
219
repeatAct->addTo( toolbar );
220
shuffleAct->addTo( toolbar );
221
toolbar->addSeparator();
222
moveUpAct->addTo( toolbar );
223
moveDownAct->addTo( toolbar );
226
popup = new QPopupMenu(this, "popup");
227
playAct->addTo( popup );
228
removeSelectedAct->addTo( popup );
229
editAct->addTo( popup );
230
connect( listView, SIGNAL(contextMenuRequested(int,int,const QPoint &)),
231
this, SLOT(showPopup(int,int,const QPoint &)) );
234
void Playlist::languageChange() {
235
listView->horizontalHeader()->setLabel( COL_PLAY, " " );
236
listView->horizontalHeader()->setLabel( COL_NAME, tr("Name") );
237
listView->horizontalHeader()->setLabel( COL_TIME, tr("Length") );
239
openAct->change( Images::icon("open"), tr("&Load") );
240
saveAct->change( Images::icon("save"), tr("&Save") );
242
playAct->change( Images::icon("play"), tr("&Play") );
244
nextAct->change( Images::icon("next"), tr("&Next") );
245
prevAct->change( Images::icon("previous"), tr("Pre&vious") );
247
moveUpAct->change( Images::icon("up"), tr("Move &up") );
248
moveDownAct->change( Images::icon("down"), tr("Move &down") );
250
repeatAct->change( Images::icon("repeat"), tr("&Repeat") );
251
shuffleAct->change( Images::icon("shuffle"), tr("S&huffle") );
254
addCurrentAct->change( tr("Add ¤t file") );
255
addFilesAct->change( tr("Add &file(s)") );
256
addDirectoryAct->change( tr("Add &directory") );
259
removeSelectedAct->change( tr("Remove &selected") );
260
removeAllAct->change( tr("Remove &all") );
263
editAct->change( tr("&Edit") );
266
add_button->setIconSet( Images::icon("plus") );
267
QToolTip::add( add_button, tr("Add...") );
268
remove_button->setIconSet( Images::icon("minus") );
269
QToolTip::add( remove_button, tr("Remove...") );
272
setIcon( Images::icon("logo", 64) );
273
setCaption( tr( "SMPlayer - Playlist" ) );
276
void Playlist::list() {
277
qDebug("Playlist::list");
279
PlaylistItemList::iterator it;
280
for ( it = pl.begin(); it != pl.end(); ++it ) {
281
qDebug( "filename: '%s', name: '%s' duration: %f",
282
(*it).filename().utf8().data(), (*it).name().utf8().data(),
287
void Playlist::updateView() {
288
listView->setNumRows( pl.count() );
295
PlaylistItemList::iterator it;
297
for ( it = pl.begin(); it != pl.end(); ++it ) {
298
number.sprintf("%03d", n +1 );
300
if (name.isEmpty()) name = (*it).filename();
301
time = Helper::formatTime( (int) (*it).duration() );
303
//listView->setText(n, COL_POS, number);
304
listView->setText(n, COL_NAME, name);
305
listView->setText(n, COL_TIME, time);
307
if ((*it).played()) {
308
listView->setPixmap(n, COL_PLAY, Images::icon("ok_small") );
310
listView->setPixmap(n, COL_PLAY, QPixmap() );
316
for (n=0; n <= COL_TIME; n++)
317
listView->adjustColumn(n);
319
setCurrentItem(current_item);
324
void Playlist::setCurrentItem(int current) {
325
int old_current = current_item;
326
current_item = current;
328
if ((current_item > -1) && (current_item < pl.count())) {
329
pl[current_item].setPlayed(TRUE);
332
if ( (old_current >= 0) && (old_current < listView->numRows()) ) {
333
listView->setPixmap(old_current, COL_PLAY, QPixmap() );
336
if ( (current_item >= 0) && (current_item < listView->numRows()) ) {
337
listView->setPixmap(current_item, COL_PLAY, Images::icon("play") );
339
//if (current_item >= 0) listView->selectRow(current_item);
340
if (current_item >= 0) {
341
listView->clearSelection();
342
listView->setCurrentCell( current_item, 0);
343
listView->selectRow(current_item);
347
void Playlist::clear() {
349
listView->setNumRows(0);
352
setModified( false );
355
int Playlist::count() {
359
bool Playlist::isEmpty() {
363
void Playlist::addItem(QString filename, QString name, double duration) {
364
qDebug("Playlist::addItem: '%s'", filename.utf8().data());
367
filename = Helper::changeSlashes(filename);
370
// Test if already is in the list
372
PlaylistItemList::iterator it;
373
for ( it = pl.begin(); it != pl.end(); ++it ) {
374
if ( (*it).filename() == filename ) {
381
if (name.isEmpty()) {
382
QFileInfo fi(filename);
385
name = fi.fileName(); //fi.baseName(TRUE);
391
pl.append( PlaylistItem(filename, name, duration) );
392
//setModified( true ); // Better set the modified on a higher level
394
qDebug(" Not added. File already in the list");
398
void Playlist::load_m3u(QString file) {
399
qDebug("Playlist::load_m3u");
401
bool utf8 = (QFileInfo(file).extension(FALSE).lower() == "m3u8");
403
QRegExp m3u_id("^#EXTM3U|^#M3U");
404
QRegExp info("^#EXTINF:(.*),(.*)");
407
if ( f.open( IO_ReadOnly ) ) {
408
playlist_path = QFileInfo(file).dirPath();
415
QTextStream stream( &f );
418
stream.setEncoding(QTextStream::UnicodeUTF8);
420
stream.setEncoding(QTextStream::Locale);
423
while ( !stream.atEnd() ) {
424
line = stream.readLine(); // line of text excluding '\n'
425
qDebug( " * line: '%s'", line.utf8().data() );
426
if (m3u_id.search(line)!=-1) {
431
if (info.search(line)!=-1) {
432
duration = info.cap(1).toDouble();
434
qDebug(" * name: '%s', duration: %f", name.utf8().data(), duration );
437
if (line.startsWith("#")) {
442
QFileInfo fi(filename);
444
filename = fi.absFilePath();
447
if (QFileInfo( playlist_path + "/" + filename).exists() ) {
448
filename = playlist_path + "/" + filename;
451
addItem( filename, name, duration );
460
setModified( false );
466
bool Playlist::save_m3u(QString file) {
467
qDebug("Playlist::save_m3u: '%s'", file.utf8().data());
469
QString dir_path = QFileInfo(file).dirPath();
470
if (!dir_path.endsWith("/")) dir_path += "/";
473
dir_path = Helper::changeSlashes(dir_path);
476
qDebug(" * dirPath: '%s'", dir_path.utf8().data());
478
bool utf8 = (QFileInfo(file).extension(FALSE).lower() == "m3u8");
481
if ( f.open( IO_WriteOnly ) ) {
482
QTextStream stream( &f );
485
stream.setEncoding(QTextStream::UnicodeUTF8);
487
stream.setEncoding(QTextStream::Locale);
491
stream << "#EXTM3U" << "\n";
492
stream << "# Playlist created by SMPlayer " << VERSION << " \n";
494
PlaylistItemList::iterator it;
495
for ( it = pl.begin(); it != pl.end(); ++it ) {
496
filename = (*it).filename();
498
filename = Helper::changeSlashes(filename);
500
stream << "#EXTINF:";
501
stream << (*it).duration() << ",";
502
stream << (*it).name() << "\n";
503
// Try to save the filename as relative instead of absolute
504
if (filename.startsWith( dir_path )) {
505
filename = filename.mid( dir_path.length() );
507
stream << filename << "\n";
511
setModified( false );
518
void Playlist::load() {
520
QString s = MyFileDialog::getOpenFileName(
522
tr("Playlists") +" (*.m3u *.m3u8)",
525
tr("Choose a file") );
528
latest_dir = QFileInfo(s).dirPath(TRUE);
534
bool Playlist::save() {
535
QString s = MyFileDialog::getSaveFileName(
537
tr("Playlists") +" (*.m3u *.m3u8)",
540
tr("Choose a filename") );
543
// If filename has no extension, add it
544
if (QFileInfo(s).extension().isEmpty()) {
547
if (QFileInfo(s).exists()) {
548
int res = QMessageBox::question( this,
549
tr("Confirm overwrite?"),
550
tr("The file %1 already exists.\n"
551
"Do you want to overwrite?").arg(s),
554
QMessageBox::NoButton);
555
if (res == QMessageBox::No ) {
559
latest_dir = QFileInfo(s).dirPath(TRUE);
566
bool Playlist::maybeSave() {
567
if (!isModified()) return true;
569
int res = QMessageBox::question( this,
570
tr("Playlist modified"),
571
tr("There are unsaved changes, do you want to save the playlist?"),
574
QMessageBox::Cancel);
577
case QMessageBox::No : return true; // Discard changes
578
case QMessageBox::Cancel : return false; // Cancel operation
579
default : return save();
583
void Playlist::playCurrent() {
584
int current = listView->currentRow();
590
void Playlist::itemDoubleClicked(int row) {
591
qDebug("Playlist::itemDoubleClicked: row: %d", row );
595
void Playlist::showPopup(int row, int col, const QPoint & pos) {
596
qDebug("Playlist::showPopup: row: %d col: %d", row, col );
597
if (!popup->isVisible()) {
603
void Playlist::startPlay() {
605
if ( shuffleAct->isOn() )
606
playItem( chooseRandomItem() );
611
void Playlist::playItem( int n ) {
612
qDebug("Playlist::playItem: %d (count:%d)", n, pl.count());
614
if ( (n >= pl.count()) || (n < 0) ) {
615
qDebug(" out of range");
616
emit playlistEnded();
620
qDebug(" playlist_path: '%s'", playlist_path.utf8().data() );
622
QString filename = pl[n].filename();
623
QString filename_with_path = playlist_path + "/" + filename;
625
if (!filename.isEmpty()) {
626
//pl[n].setPlayed(TRUE);
628
core->open(filename, 0);
633
void Playlist::playNext() {
634
qDebug("Playlist::playNext");
636
if (shuffleAct->isOn()) {
638
int chosen_item = chooseRandomItem();
639
if (chosen_item == -1) {
641
if (repeatAct->isOn()) chosen_item = chooseRandomItem();
643
playItem( chosen_item );
645
bool finished_list = (current_item+1 >= pl.count());
646
if (finished_list) clearPlayedTag();
648
if ( (repeatAct->isOn()) && (finished_list) ) {
651
playItem( current_item+1 );
656
void Playlist::playPrev() {
657
qDebug("Playlist::playPrev");
658
playItem( current_item-1 );
661
void Playlist::getMediaInfo() {
662
qDebug("Playlist:: getMediaInfo");
664
QString filename = core->mdat.filename;
665
double duration = core->mdat.duration;
666
QString name = core->mdat.clip_name;
667
QString artist = core->mdat.clip_artist;
670
filename = Helper::changeSlashes(filename);
673
if (name.isEmpty()) {
674
QFileInfo fi(filename);
677
name = fi.fileName();
683
if (!artist.isEmpty()) name = artist + " - " + name;
686
PlaylistItemList::iterator it;
687
for ( it = pl.begin(); it != pl.end(); ++it ) {
688
if ( (*it).filename() == filename ) {
689
if ((*it).duration()<1) {
690
if (!name.isEmpty()) {
693
(*it).setDuration(duration);
694
//setModified( true );
697
// Edited name (sets duration to 1)
698
if ((*it).duration()==1) {
699
(*it).setDuration(duration);
700
//setModified( true );
709
// Add current file to playlist
710
void Playlist::addCurrentFile() {
711
qDebug("Playlist::addCurrentFile");
712
if (!core->mdat.filename.isEmpty()) {
713
addItem( core->mdat.filename, "", 0 );
718
void Playlist::addFiles() {
719
QStringList files = MyFileDialog::getOpenFileNames(
720
tr("All files") +" (*.*)",
724
tr("Select one or more files to open") );
726
if (files.count()!=0) addFiles(files);
729
void Playlist::addFiles(QStringList files) {
730
qDebug("Playlist::addFiles");
732
QStringList::Iterator it = files.begin();
733
while( it != files.end() ) {
734
addItem( (*it), "", 0 );
735
// FIXME: set latest_dir only if the file is a local file,
736
// to avoid that dvd:, vcd: and so on will be used.
737
/* latest_dir = QFileInfo((*it)).dirPath(TRUE); */
742
qDebug( " * latest_dir: '%s'", latest_dir.utf8().data() );
745
void Playlist::addDirectory() {
746
QString s = MyFileDialog::getExistingDirectory(
749
"get existing directory",
750
tr("Choose a directory"),
759
void Playlist::addDirectory(QString dir) {
760
QStringList dir_list = QDir(dir).entryList();
763
QStringList::Iterator it = dir_list.begin();
764
while( it != dir_list.end() ) {
766
if (filename.right(1)!="/") filename += "/";
768
if (!QFileInfo(filename).isDir()) {
769
addItem( filename, "", 0 );
776
// Remove selected items
777
void Playlist::removeSelected() {
778
qDebug("Playlist::removeSelected");
780
int first_selected = -1;
782
for (int n=0; n < listView->numRows(); n++) {
783
if (listView->isRowSelected(n)) {
784
qDebug(" row %d selected", n);
785
pl[n].setMarkForDeletion(TRUE);
786
if (first_selected == -1) first_selected = n;
790
PlaylistItemList::iterator it;
791
for ( it = pl.begin(); it != pl.end(); ++it ) {
792
if ( (*it).markedForDeletion() ) {
793
qDebug("Remove '%s'", (*it).filename().utf8().data());
800
if (isEmpty()) setModified(false);
803
if (first_selected >= listView->numRows())
804
first_selected = listView->numRows() - 1;
806
if ( ( first_selected > -1) && ( first_selected < listView->numRows() ) ) {
807
listView->clearSelection();
808
listView->setCurrentCell( first_selected, 0);
809
listView->selectRow( first_selected );
813
void Playlist::removeAll() {
817
setModified( false );
822
void Playlist::clearPlayedTag() {
823
PlaylistItemList::iterator it;
824
for ( it = pl.begin(); it != pl.end(); ++it ) {
825
(*it).setPlayed(FALSE);
830
int Playlist::chooseRandomItem() {
831
qDebug( "Playlist::chooseRandomItem");
832
QValueList <int> fi; //List of not played items (free items)
835
PlaylistItemList::iterator it;
836
for ( it = pl.begin(); it != pl.end(); ++it ) {
837
if (! (*it).played() ) fi.append(n);
841
qDebug(" * free items: %d", fi.count() );
843
if (fi.count()==0) return -1; // none free
845
qDebug(" * items: ");
846
for (int i=0; i < fi.count(); i++) {
847
qDebug(" * item: %d", fi[i]);
850
int selected = (int) ((double) fi.count() * rand()/(RAND_MAX+1.0));
851
qDebug(" * selected item: %d (%d)", selected, fi[selected]);
855
void Playlist::swapItems(int item1, int item2 ) {
856
PlaylistItem it1 = pl[item1];
857
pl[item1] = pl[item2];
863
void Playlist::upItem() {
864
qDebug("Playlist::upItem");
866
int current = listView->currentRow();
867
qDebug(" currentRow: %d", current );
870
swapItems( current, current-1 );
871
if (current_item == (current-1)) current_item = current;
873
if (current_item == current) current_item = current-1;
875
listView->clearSelection();
876
listView->setCurrentCell( current-1, 0);
880
void Playlist::downItem() {
881
qDebug("Playlist::downItem");
883
int current = listView->currentRow();
884
qDebug(" currentRow: %d", current );
886
if ( (current > -1) && (current < (pl.count()-1)) ) {
887
swapItems( current, current+1 );
888
if (current_item == (current+1)) current_item = current;
890
if (current_item == current) current_item = current+1;
892
listView->clearSelection();
893
listView->setCurrentCell( current+1, 0);
897
void Playlist::editCurrentItem() {
898
int current = listView->currentRow();
899
if (current > -1) editItem(current);
902
void Playlist::editItem(int item) {
903
QString current_name = pl[item].name();
904
if (current_name.isEmpty()) current_name = pl[item].filename();
907
QString text = QInputDialog::getText(
909
tr("Type the name that will be displayed in the playlist for this file:"),
911
current_name, &ok, this );
912
if ( ok && !text.isEmpty() ) {
913
// user entered something and pressed OK
914
pl[item].setName(text);
916
// If duration == 0 the name will be overwritten!
917
if (pl[item].duration()<1) pl[item].setDuration(1);
925
void Playlist::dragEnterEvent( QDragEnterEvent *e ) {
926
qDebug("Playlist::dragEnterEvent");
927
#if QT_VERSION < 0x040000
928
e->accept( (QUriDrag::canDecode(e) || QTextDrag::canDecode(e)) );
930
e->accept(QUriDrag::canDecode(e));
935
void Playlist::dropEvent( QDropEvent *e ) {
936
qDebug("Playlist::dropEvent");
940
if (QUriDrag::canDecode(e)) {
942
QUriDrag::decode(e, l);
945
for ( unsigned int i= 0; i < l.count(); ++i ) {
947
qDebug(" * '%s'", s.utf8().data() );
953
qDebug(" * protocol: '%s'", u.protocol().utf8().data());
954
qDebug(" * path: '%s'", u.path().utf8().data());
955
//qDebug(" filename:='%s'", u.fileName().utf8().data());
956
if (u.protocol()=="file") {
964
#if QT_VERSION < 0x040000
966
if (QTextDrag::canDecode(e)) {
968
if (QTextDrag::decode(e, s)) {
969
qDebug(" * '%s'", s.utf8().data() );
975
QStringList only_files;
976
for (int n = 0; n < files.count(); n++) {
977
if ( QFileInfo( files[n] ).isDir() ) {
978
addDirectory( files[n] );
980
//addFiles( files[n] );
981
//addItem( files[n], "", 0 );
982
only_files.append( files[n] );
987
addFiles( only_files );
991
void Playlist::hideEvent( QHideEvent * ) {
992
emit visibilityChanged();
995
void Playlist::showEvent( QShowEvent * ) {
996
emit visibilityChanged();
999
void Playlist::closeEvent( QCloseEvent * e ) {
1005
void Playlist::maybeSaveSettings() {
1006
qDebug("Playlist::maybeSaveSettings");
1007
if (isModified()) saveSettings();
1010
void Playlist::saveSettings() {
1011
qDebug("Playlist::saveSettings");
1013
QSettings * set = settings;
1015
set->beginGroup( "playlist");
1017
set->writeEntry( "repeat", repeatAct->isOn() );
1018
set->writeEntry( "shuffle", shuffleAct->isOn() );
1020
set->writeEntry( "window_width", size().width() );
1021
set->writeEntry( "window_height", size().height() );
1023
set->writeEntry( "latest_dir", latest_dir );
1028
set->beginGroup( "playlist_contents");
1030
set->writeEntry( "count", (int) pl.count() );
1031
for ( int n=0; n < pl.count(); n++ ) {
1032
set->writeEntry( QString("item_%1_filename").arg(n), pl[n].filename() );
1033
set->writeEntry( QString("item_%1_duration").arg(n), pl[n].duration() );
1034
set->writeEntry( QString("item_%1_name").arg(n), pl[n].name() );
1036
set->writeEntry( "current_item", current_item );
1037
set->writeEntry( "modified", modified );
1042
void Playlist::loadSettings() {
1043
qDebug("Playlist::loadSettings");
1045
QSettings * set = settings;
1047
set->beginGroup( "playlist");
1049
repeatAct->setOn( set->readBoolEntry( "repeat", repeatAct->isOn() ) );
1050
shuffleAct->setOn( set->readBoolEntry( "shuffle", shuffleAct->isOn() ) );
1054
s.setWidth( set->readNumEntry( "window_width", size().width() ) );
1055
s.setHeight( set->readNumEntry( "window_height", size().height() ) );
1059
latest_dir = set->readEntry( "latest_dir", latest_dir );
1064
set->beginGroup( "playlist_contents");
1066
int count = set->readNumEntry( "count", 0 );
1067
QString filename, name;
1069
for ( int n=0; n < count; n++ ) {
1070
filename = set->readEntry( QString("item_%1_filename").arg(n), "" );
1071
duration = set->readNumEntry( QString("item_%1_duration").arg(n), -1 );
1072
name = set->readEntry( QString("item_%1_name").arg(n), "" );
1073
addItem( filename, name, duration );
1075
setCurrentItem( set->readNumEntry( "current_item", -1 ) );
1076
setModified( set->readBoolEntry( "modified", false ) );
1082
QString Playlist::lastDir() {
1083
QString last_dir = latest_dir;
1084
if (last_dir.isEmpty()) last_dir = pref->latest_dir;