Ignore:
Timestamp:
Dec 27, 2011, 5:44:12 PM (14 years ago)
Author:
Silvan Scherrer
Message:

SMPlayer: latest svn update

Location:
smplayer/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • smplayer/trunk

  • smplayer/trunk/src/playlist.cpp

    r112 r119  
    11/*  smplayer, GUI front-end for mplayer.
    2     Copyright (C) 2006-2010 Ricardo Villalba <rvm@escomposlinux.org>
     2    Copyright (C) 2006-2011 Ricardo Villalba <rvm@escomposlinux.org>
    33
    44    This program is free software; you can redistribute it and/or modify
     
    5252#include "extensions.h"
    5353#include "guiconfig.h"
    54 #include "playlistpreferences.h"
    5554
    5655#include <stdlib.h>
     
    7473        save_playlist_in_config = true;
    7574        recursive_add_directory = false;
    76 #ifdef Q_OS_WIN
    7775        automatically_get_info = false;
    78 #else
    79         automatically_get_info = true;
    80 #endif
    8176        play_files_from_start = true;
    8277
     
    176171        connect( listView, SIGNAL(cellActivated(int,int)),
    177172             this, SLOT(itemDoubleClicked(int)) );
     173
     174        // EDIT BY NEO -->
     175        connect( listView->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(sortBy(int)));
     176        // <--
    178177}
    179178
     
    205204        shuffleAct = new MyAction(this, "pl_shuffle", false);
    206205        shuffleAct->setCheckable(true);
    207 
    208         preferencesAct = new MyAction(this, "pl_preferences", false);
    209         connect( preferencesAct, SIGNAL(triggered()), this, SLOT(editPreferences()) );
    210206
    211207        // Add actions
     
    270266        toolbar->addAction(moveUpAct);
    271267        toolbar->addAction(moveDownAct);
    272         toolbar->addSeparator();
    273         toolbar->addAction(preferencesAct);
    274268
    275269        // Popup menu
     
    311305        shuffleAct->change( Images::icon("shuffle"), tr("S&huffle") );
    312306
    313         preferencesAct->change( Images::icon("prefs"), tr("Preferences") );
    314 
    315307        // Add actions
    316308        addCurrentAct->change( tr("Add &current file") );
     
    345337               (*it).duration() );
    346338        }
     339}
     340
     341
     342QString 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;
    347352}
    348353
     
    421426
    422427        setModified( false );
     428}
     429
     430void 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
    423438}
    424439
     
    473488        }
    474489}
     490
     491// EDIT BY NEO -->
     492void Playlist::sortBy(int section) {
     493        qDebug("Playlist::sortBy");
     494
     495        sortBy(section, false, 0);
     496}
     497
     498void 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// <--
    475581
    476582void Playlist::load_m3u(QString file) {
     
    9081014
    9091015void Playlist::addFiles() {
     1016        Extensions e;
    9101017        QStringList files = MyFileDialog::getOpenFileNames(
    9111018                            this, tr("Select one or more files to open"),
    9121019                            lastDir(),
     1020                            tr("Multimedia") + e.multimedia().forFilter() + ";;" +
    9131021                            tr("All files") +" (*.*)" );
    9141022
     
    11131221        qDebug(" currentRow: %d", current );
    11141222
     1223        moveItemUp(current);
     1224
     1225}
     1226
     1227void Playlist::downItem() {
     1228        qDebug("Playlist::downItem");
     1229
     1230        int current = listView->currentRow();
     1231        qDebug(" currentRow: %d", current );
     1232
     1233        moveItemDown(current);
     1234}
     1235
     1236void Playlist::moveItemUp(int current){
     1237        qDebug("Playlist::moveItemUp");
     1238
    11151239        if (current >= 1) {
    11161240                swapItems( current, current-1 );
     
    11231247        }
    11241248}
    1125 
    1126 void Playlist::downItem() {
    1127         qDebug("Playlist::downItem");
    1128 
    1129         int current = listView->currentRow();
    1130         qDebug(" currentRow: %d", current );
     1249void Playlist::moveItemDown(int current ){
     1250        qDebug("Playlist::moveItemDown");
    11311251
    11321252        if ( (current > -1) && (current < (pl.count()-1)) ) {
     
    11661286                setModified( true );
    11671287    }
    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         }
    11841288}
    11851289
     
    12181322        }
    12191323
     1324
    12201325        QStringList only_files;
    12211326        for (int n = 0; n < files.count(); n++) {
     
    12281333        addFiles( only_files );
    12291334}
     1335
    12301336
    12311337void Playlist::hideEvent( QHideEvent * ) {
Note: See TracChangeset for help on using the changeset viewer.