Changeset 119 for smplayer/trunk/src/playlist.cpp
- Timestamp:
- Dec 27, 2011, 5:44:12 PM (14 years ago)
- Location:
- smplayer/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
smplayer/trunk
-
Property svn:mergeinfo
set to
/smplayer/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
smplayer/trunk/src/playlist.cpp
r112 r119 1 1 /* smplayer, GUI front-end for mplayer. 2 Copyright (C) 2006-201 0Ricardo Villalba <rvm@escomposlinux.org>2 Copyright (C) 2006-2011 Ricardo Villalba <rvm@escomposlinux.org> 3 3 4 4 This program is free software; you can redistribute it and/or modify … … 52 52 #include "extensions.h" 53 53 #include "guiconfig.h" 54 #include "playlistpreferences.h"55 54 56 55 #include <stdlib.h> … … 74 73 save_playlist_in_config = true; 75 74 recursive_add_directory = false; 76 #ifdef Q_OS_WIN77 75 automatically_get_info = false; 78 #else79 automatically_get_info = true;80 #endif81 76 play_files_from_start = true; 82 77 … … 176 171 connect( listView, SIGNAL(cellActivated(int,int)), 177 172 this, SLOT(itemDoubleClicked(int)) ); 173 174 // EDIT BY NEO --> 175 connect( listView->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(sortBy(int))); 176 // <-- 178 177 } 179 178 … … 205 204 shuffleAct = new MyAction(this, "pl_shuffle", false); 206 205 shuffleAct->setCheckable(true); 207 208 preferencesAct = new MyAction(this, "pl_preferences", false);209 connect( preferencesAct, SIGNAL(triggered()), this, SLOT(editPreferences()) );210 206 211 207 // Add actions … … 270 266 toolbar->addAction(moveUpAct); 271 267 toolbar->addAction(moveDownAct); 272 toolbar->addSeparator();273 toolbar->addAction(preferencesAct);274 268 275 269 // Popup menu … … 311 305 shuffleAct->change( Images::icon("shuffle"), tr("S&huffle") ); 312 306 313 preferencesAct->change( Images::icon("prefs"), tr("Preferences") );314 315 307 // Add actions 316 308 addCurrentAct->change( tr("Add ¤t file") ); … … 345 337 (*it).duration() ); 346 338 } 339 } 340 341 342 QString Playlist::print(QString seperator){ 343 qDebug("Playlist::print"); 344 QString output = ""; 345 346 PlaylistItemList::iterator it; 347 for ( it = pl.begin(); it != pl.end(); ++it ) { 348 output += it->filename() + seperator + it->name() + seperator + QString::number(it->duration()) + "\r\n"; 349 } 350 351 return output; 347 352 } 348 353 … … 421 426 422 427 setModified( false ); 428 } 429 430 void Playlist::remove(int i){ 431 if(i > -1 && i < pl.count()){ 432 pl.removeAt(i); 433 if(current_item == i && i == (pl.count() - 1)) 434 setCurrentItem(i - 1); 435 setModified(false); 436 updateView(); 437 } //end if 423 438 } 424 439 … … 473 488 } 474 489 } 490 491 // EDIT BY NEO --> 492 void Playlist::sortBy(int section) { 493 qDebug("Playlist::sortBy"); 494 495 sortBy(section, false, 0); 496 } 497 498 void Playlist::sortBy(int section, bool revert, int count) { 499 // Bubble sort 500 bool swaped = false; 501 502 for ( int n = 0; n < (pl.count() - count); n++) { 503 504 int last = n - 1; 505 int current = n; 506 507 // Revert the sort 508 if (revert) { 509 last = n; 510 current = n - 1; 511 } 512 513 if (n > 0) { 514 int compare = 0; 515 516 if (section == 0) { 517 // Sort by played 518 bool lastItem = pl[last].played(); 519 bool currentItem = pl[current].played(); 520 521 if (!lastItem && currentItem) { 522 compare = 1; 523 } else if (lastItem && currentItem) { 524 if (last == current_item) { 525 compare = 1; 526 } else { 527 compare = -1; 528 } 529 } else { 530 compare = -1; 531 } 532 } 533 else if (section == 1) { 534 // Sort alphabetically 535 QString lastItem = pl[last].name(); 536 QString currentItem = pl[current].name(); 537 compare = lastItem.compare(currentItem); 538 } else if (section == 2) { 539 // Sort by duration 540 double lastItem = pl[last].duration(); 541 double currentItem = pl[current].duration(); 542 543 if (lastItem == currentItem) { 544 compare = 0; 545 } else if (lastItem > currentItem) { 546 compare = 1; 547 } else { 548 compare = -1; 549 } 550 } 551 552 // Swap items 553 if(compare > 0) { 554 swapItems(n, n - 1); 555 556 if (current_item == (n - 1)) { 557 current_item = n; 558 } else if (current_item == n) { 559 current_item = n - 1; 560 } 561 562 listView->clearSelection(); 563 listView->setCurrentCell(n - 1, 0); 564 565 swaped = true; 566 } 567 } 568 } 569 570 if ((count == 0) && !swaped && !revert) { 571 // Revert sort 572 sortBy(section, true, 0); 573 }else if(swaped) { 574 // Sort until there is nothing to sort 575 sortBy(section, revert, ++count); 576 } else { 577 updateView(); 578 } 579 } 580 // <-- 475 581 476 582 void Playlist::load_m3u(QString file) { … … 908 1014 909 1015 void Playlist::addFiles() { 1016 Extensions e; 910 1017 QStringList files = MyFileDialog::getOpenFileNames( 911 1018 this, tr("Select one or more files to open"), 912 1019 lastDir(), 1020 tr("Multimedia") + e.multimedia().forFilter() + ";;" + 913 1021 tr("All files") +" (*.*)" ); 914 1022 … … 1113 1221 qDebug(" currentRow: %d", current ); 1114 1222 1223 moveItemUp(current); 1224 1225 } 1226 1227 void Playlist::downItem() { 1228 qDebug("Playlist::downItem"); 1229 1230 int current = listView->currentRow(); 1231 qDebug(" currentRow: %d", current ); 1232 1233 moveItemDown(current); 1234 } 1235 1236 void Playlist::moveItemUp(int current){ 1237 qDebug("Playlist::moveItemUp"); 1238 1115 1239 if (current >= 1) { 1116 1240 swapItems( current, current-1 ); … … 1123 1247 } 1124 1248 } 1125 1126 void Playlist::downItem() { 1127 qDebug("Playlist::downItem"); 1128 1129 int current = listView->currentRow(); 1130 qDebug(" currentRow: %d", current ); 1249 void Playlist::moveItemDown(int current ){ 1250 qDebug("Playlist::moveItemDown"); 1131 1251 1132 1252 if ( (current > -1) && (current < (pl.count()-1)) ) { … … 1166 1286 setModified( true ); 1167 1287 } 1168 }1169 1170 void Playlist::editPreferences() {1171 PlaylistPreferences d(this);1172 1173 d.setDirectoryRecursion(recursive_add_directory);1174 d.setAutoGetInfo(automatically_get_info);1175 d.setSavePlaylistOnExit(save_playlist_in_config);1176 d.setPlayFilesFromStart(play_files_from_start);1177 1178 if (d.exec() == QDialog::Accepted) {1179 recursive_add_directory = d.directoryRecursion();1180 automatically_get_info = d.autoGetInfo();1181 save_playlist_in_config = d.savePlaylistOnExit();1182 play_files_from_start = d.playFilesFromStart();1183 }1184 1288 } 1185 1289 … … 1218 1322 } 1219 1323 1324 1220 1325 QStringList only_files; 1221 1326 for (int n = 0; n < files.count(); n++) { … … 1228 1333 addFiles( only_files ); 1229 1334 } 1335 1230 1336 1231 1337 void Playlist::hideEvent( QHideEvent * ) {
Note:
See TracChangeset
for help on using the changeset viewer.