Ignore:
Timestamp:
Jan 24, 2017, 12:41:54 PM (8 years ago)
Author:
Silvan Scherrer
Message:

SMPlayer: update trunk to version 17.1.0

Location:
smplayer/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • smplayer/trunk

  • smplayer/trunk/src/playlist.cpp

    r181 r188  
    11/*  smplayer, GUI front-end for mplayer.
    2     Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
     2    Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
    33
    44    This program is free software; you can redistribute it and/or modify
     
    4545#include <QMimeData>
    4646#include <QDomDocument>
     47#include <QDesktopServices>
    4748#include <QDebug>
    4849
     
    6162#include "extensions.h"
    6263#include "guiconfig.h"
     64
     65#ifdef CHROMECAST_SUPPORT
     66#include "chromecast.h"
     67#endif
    6368
    6469#ifdef PLAYLIST_DOWNLOAD
     
    224229}
    225230
     231void PLItem::setExtraParams(const QStringList & pars) {
     232        setData(pars, Role_Params);
     233}
     234
     235QStringList PLItem::extraParams() {
     236        return data(Role_Params).toStringList();
     237}
     238
     239void PLItem::setVideoURL(const QString & url) {
     240        setData(url, Role_Video_URL);
     241}
     242
     243QString PLItem::videoURL() {
     244        return data(Role_Video_URL).toString();
     245}
    226246
    227247/* ----------------------------------------------------------- */
     
    237257        , play_files_from_start(true)
    238258        , row_spacing(-1) // Default height
     259        , start_play_on_load(true)
    239260        , automatically_play_next(true)
    240261        , ignore_player_errors(false)
     
    245266        latest_dir = "";
    246267
     268        filter_edit = new MyLineEdit(this);
     269        connect(filter_edit, SIGNAL(textChanged(const QString &)), this, SLOT(filterEditChanged(const QString &)));
     270
    247271        createTable();
    248272        createActions();
     
    250274
    251275        QVBoxLayout *layout = new QVBoxLayout;
     276#ifdef PLAYLIST_DOUBLE_TOOLBAR
     277        layout->addWidget(toolbar);
     278        layout->addWidget(listView);
     279        layout->addWidget(toolbar2);
     280#else
    252281        layout->addWidget(listView);
    253282        layout->addWidget(toolbar);
    254 #ifdef PLAYLIST_DOUBLE_TOOLBAR
    255         layout->addWidget(toolbar2);
     283        layout->addWidget(filter_edit);
     284        filter_edit->hide();
    256285#endif
    257286        setLayout(layout);
     
    291320
    292321        history_urls = new URLHistory;
    293         history_urls->addUrl("http://smplayer.info/onlinetv.php");
     322        history_urls->addUrl("http://smplayer.info/sample.m3u8");
    294323#endif
    295324}
     
    320349}
    321350
     351void Playlist::updateWindowTitle() {
     352        QString title;
     353
     354        title = playlist_filename;
     355        if (title.isEmpty()) title = tr("Untitled playlist");
     356        if (modified) title += " (*)";
     357
     358        qDebug() << "Playlist::updateWindowTitle:" << title;
     359
     360        setWindowTitle(title);
     361        emit windowTitleChanged(title);
     362}
     363
     364void Playlist::setPlaylistFilename(const QString & f) {
     365        playlist_filename = f;
     366        updateWindowTitle();
     367}
    322368
    323369void Playlist::setModified(bool mod) {
     
    326372        modified = mod;
    327373        emit modifiedChanged(modified);
     374        updateWindowTitle();
    328375}
    329376
     
    358405        listView->setShowGrid(false);
    359406        listView->setSortingEnabled(true);
     407        listView->setWordWrap(false);
    360408#if !USE_ITEM_DELEGATE
    361409        listView->setAlternatingRowColors(true);
     
    376424#endif
    377425        listView->horizontalHeader()->setStretchLastSection(true);
     426        listView->horizontalHeader()->setSortIndicator(0, Qt::AscendingOrder);
    378427
    379428        /*
     
    393442        connect(listView, SIGNAL(activated(const QModelIndex &)),
    394443            this, SLOT(itemActivated(const QModelIndex &)) );
     444
     445        setFilenameColumnVisible(false);
    395446}
    396447
     
    405456
    406457        saveAct = new MyAction(this, "pl_save", false);
    407         connect( saveAct, SIGNAL(triggered()), this, SLOT(save()) );
     458        connect( saveAct, SIGNAL(triggered()), this, SLOT(saveCurrentPlaylist()) );
     459
     460        saveAsAct = new MyAction(this, "pl_save_as", false);
     461        connect( saveAsAct, SIGNAL(triggered()), this, SLOT(save()) );
    408462
    409463        playAct = new MyAction(this, "pl_play", false);
     
    452506        connect( editAct, SIGNAL(triggered()), this, SLOT(editCurrentItem()) );
    453507
     508#ifdef PLAYLIST_DELETE_FROM_DISK
    454509        deleteSelectedFileFromDiskAct = new MyAction(this, "pl_delete_from_disk");
    455510        connect( deleteSelectedFileFromDiskAct, SIGNAL(triggered()), this, SLOT(deleteSelectedFileFromDisk()));
     511#endif
     512
     513        copyURLAct = new MyAction(this, "pl_copy_url");
     514        connect( copyURLAct, SIGNAL(triggered()), this, SLOT(copyURL()));
     515
     516        openFolderAct = new MyAction(this, "pl_open_folder");
     517        connect( openFolderAct, SIGNAL(triggered()), this, SLOT(openFolder()));
     518
     519#ifdef CHROMECAST_SUPPORT
     520        playOnChromecastAct = new MyAction(this, "pl_chromecast");
     521        connect( playOnChromecastAct, SIGNAL(triggered()), this, SLOT(playOnChromecast()));
     522#else
     523        openURLInWebAct = new MyAction(this, "pl_url_in_web");
     524        connect( openURLInWebAct, SIGNAL(triggered()), this, SLOT(openURLInWeb()));
     525#endif
     526
     527        showSearchAct = new MyAction(this, "pl_show_search", false);
     528        showSearchAct->setCheckable(true);
     529        connect(showSearchAct, SIGNAL(toggled(bool)), filter_edit, SLOT(setVisible(bool)));
     530
     531        showPositionColumnAct = new MyAction(this, "pl_show_position_column");
     532        showPositionColumnAct->setCheckable(true);
     533        connect(showPositionColumnAct, SIGNAL(toggled(bool)), this, SLOT(setPositionColumnVisible(bool)));
     534
     535        showNameColumnAct = new MyAction(this, "pl_show_name_column");
     536        showNameColumnAct->setCheckable(true);
     537        connect(showNameColumnAct, SIGNAL(toggled(bool)), this, SLOT(setNameColumnVisible(bool)));
     538
     539        showDurationColumnAct = new MyAction(this, "pl_show_duration_column");
     540        showDurationColumnAct->setCheckable(true);
     541        connect(showDurationColumnAct, SIGNAL(toggled(bool)), this, SLOT(setDurationColumnVisible(bool)));
     542
     543        showFilenameColumnAct = new MyAction(this, "pl_show_filename_column");
     544        showFilenameColumnAct->setCheckable(true);
     545        connect(showFilenameColumnAct, SIGNAL(toggled(bool)), this, SLOT(setFilenameColumnVisible(bool)));
    456546}
    457547
     
    466556#endif
    467557
     558/*
    468559        toolbar->addAction(openAct);
    469560#ifdef PLAYLIST_DOWNLOAD
     
    472563        toolbar->addAction(saveAct);;
    473564        toolbar->addSeparator();
     565*/
     566
     567        file_menu = new QMenu(this);
     568        file_menu->addAction(openAct);
     569        file_menu->addAction(saveAct);
     570        file_menu->addAction(saveAsAct);
     571#ifdef PLAYLIST_DOWNLOAD
     572        file_menu->addAction(openUrlAct);
     573#endif
     574
     575        file_button = new QToolButton(this);
     576        file_button->setMenu(file_menu);
     577        file_button->setPopupMode(QToolButton::InstantPopup);
    474578
    475579        add_menu = new QMenu( this );
     
    491595        remove_button->setPopupMode(QToolButton::InstantPopup);
    492596
    493         filter_edit = new MyLineEdit(this);
    494         connect(filter_edit, SIGNAL(textChanged(const QString &)), this, SLOT(filterEditChanged(const QString &)));
    495597
    496598#ifdef PLAYLIST_DOWNLOAD
     
    501603#endif
    502604
     605        toolbar->addWidget(file_button);
     606        toolbar->addSeparator();
    503607        toolbar->addWidget(add_button);
    504608        toolbar->addWidget(remove_button);
     
    526630        toolbar->addAction(moveDownAct);
    527631        toolbar->addSeparator();
    528         toolbar->addWidget(filter_edit);
     632        toolbar->addAction(showSearchAct);
     633        // toolbar->addWidget(filter_edit);
    529634        #ifdef PLAYLIST_DOWNLOAD
    530635        loading_label_action = toolbar->addWidget(loading_label);
     
    541646        popup->addAction(removeSelectedAct);
    542647        popup->addAction(editAct);
     648#ifdef PLAYLIST_DELETE_FROM_DISK
    543649        popup->addAction(deleteSelectedFileFromDiskAct);
     650#endif
     651        popup->addAction(copyURLAct);
     652        popup->addAction(openFolderAct);
     653#ifdef CHROMECAST_SUPPORT
     654        popup->addAction(playOnChromecastAct);
     655#else
     656        popup->addAction(openURLInWebAct);
     657#endif
     658        popup->addSeparator();
     659        popup->addAction(showPositionColumnAct);
     660        popup->addAction(showNameColumnAct);
     661        popup->addAction(showDurationColumnAct);
     662        popup->addAction(showFilenameColumnAct);
    544663
    545664        connect( listView, SIGNAL(customContextMenuRequested(const QPoint &)),
     
    550669        table->setHorizontalHeaderLabels(QStringList() << " " << tr("Name") << tr("Length") << tr("Filename / URL") );
    551670
    552         openAct->change( Images::icon("open"), tr("&Load") );
     671        openAct->change( Images::icon("open"), tr("&Load...") );
    553672#ifdef PLAYLIST_DOWNLOAD
    554         openUrlAct->change( Images::icon("url"), tr("&Open URL") );
     673        openUrlAct->change( Images::icon("url"), tr("Load playlist from &URL...") );
    555674        openUrlAct->setToolTip(tr("Download playlist from URL"));
    556675#endif
    557676        saveAct->change( Images::icon("save"), tr("&Save") );
     677        saveAsAct->change( Images::icon("save"), tr("Save &as...") );
    558678
    559679        playAct->change( tr("&Play") );
     
    579699
    580700        // Remove actions
    581         removeSelectedAct->change( tr("Remove &selected") );
     701        removeSelectedAct->change( Images::icon("delete"), tr("Remove &selected") );
    582702        removeAllAct->change( tr("Remove &all") );
    583703
     704#ifdef PLAYLIST_DELETE_FROM_DISK
    584705        deleteSelectedFileFromDiskAct->change( tr("&Delete file from disk") );
     706#endif
     707
     708        copyURLAct->change( Images::icon("copy"), tr("&Copy file path to clipboard") );
     709        openFolderAct->change( Images::icon("openfolder"), tr("&Open source folder") );
     710
     711#ifdef CHROMECAST_SUPPORT
     712        playOnChromecastAct->change( Images::icon("chromecast"), tr("Play on Chromec&ast") );
     713#else
     714        openURLInWebAct->change( tr("Open stream in &a web browser") );
     715#endif
     716
     717        showSearchAct->change(Images::icon("find"), tr("Search"));
     718
     719        showPositionColumnAct->change(tr("Show position column"));
     720        showNameColumnAct->change(tr("Show name column"));
     721        showDurationColumnAct->change(tr("Show length column"));
     722        showFilenameColumnAct->change(tr("Show filename column"));
    585723
    586724        // Edit
     
    588726
    589727        // Tool buttons
     728        file_button->setIcon(Images::icon("open")); // FIXME: change icon
     729        file_button->setToolTip(tr("Load/Save"));
    590730        add_button->setIcon( Images::icon("plus") );
    591731        add_button->setToolTip( tr("Add...") );
     
    600740        // Icon
    601741        setWindowIcon( Images::icon("logo", 64) );
    602         setWindowTitle( tr( "SMPlayer - Playlist" ) );
     742        //setWindowTitle( tr( "SMPlayer - Playlist" ) );
    603743}
    604744
     
    619759        qDebug() << "Playlist::filterEditChanged:" << text;
    620760        setFilter(text);
     761
     762        if (text.isEmpty()) {
     763                qApp->processEvents();
     764                listView->scrollTo(listView->currentIndex(), QAbstractItemView::PositionAtCenter);
     765        }
    621766}
    622767
     
    675820
    676821bool Playlist::isEmpty() {
    677         return (table->rowCount() > 0);
     822        return (table->rowCount() == 0);
    678823}
    679824
     
    713858*/
    714859
    715 void Playlist::addItem(QString filename, QString name, double duration) {
     860void Playlist::addItem(QString filename, QString name, double duration, QStringList params, QString video_url) {
    716861        //qDebug() << "Playlist::addItem:" << filename;
    717862
     
    733878
    734879        PLItem * i = new PLItem(filename, name, duration);
     880        i->setExtraParams(params);
     881        i->setVideoURL(video_url);
    735882        i->setPosition(count()+1);
    736883        table->appendRow(i->items());
     
    802949                QString name="";
    803950                double duration=0;
     951                QStringList extra_params;
    804952
    805953                QTextStream stream( &f );
     
    833981                                if (fields.count() >= 1) duration = fields[0].toDouble();
    834982                                if (fields.count() >= 2) name = fields[1];
     983                        }
     984                        else
     985                        if (line.startsWith("#EXTVLCOPT:")) {
     986                                QString par = line.mid(11);
     987                                qDebug() << "Playlist::load_m3u: EXTVLCOPT:" << par;
     988                                extra_params << par;
    835989                        }
    836990                        else
     
    8491003                                        }
    8501004                                }
    851                                 addItem( filename, name, duration );
     1005                                name.replace("&#44;", ",");
     1006                                //qDebug() << "Playlist::load_m3u: extra_params:" << extra_params;
     1007                                addItem( filename, name, duration, extra_params );
    8521008                                name="";
    8531009                                duration = 0;
     1010                                extra_params.clear();
    8541011                        }
    8551012                }
     
    8571014                //list();
    8581015
     1016                setPlaylistFilename(file);
    8591017                setModified( false );
    8601018
    861                 startPlay();
     1019                if (start_play_on_load) startPlay();
    8621020        }
    8631021}
     
    9061064        //list();
    9071065
     1066        setPlaylistFilename(file);
    9081067        setModified( false );
    9091068
    910         if (set.status() == QSettings::NoError) startPlay();
     1069        if (set.status() == QSettings::NoError && start_play_on_load) startPlay();
    9111070}
    9121071
     
    9481107
    9491108                //list();
     1109                setPlaylistFilename(filename);
    9501110                setModified( false );
    951                 startPlay();
     1111                if (start_play_on_load) startPlay();
    9521112        }
    9531113}
     
    9771137
    9781138                QString filename;
     1139                QString name;
    9791140
    9801141                stream << "#EXTM3U" << "\n";
     
    9871148                        filename = Helper::changeSlashes(filename);
    9881149                        #endif
     1150                        name = i->name();
     1151                        name.replace(",", "&#44;");
    9891152                        stream << "#EXTINF:";
    9901153                        stream << i->duration() << ",";
    991                         stream << i->name() << "\n";
     1154                        stream << name << "\n";
     1155
     1156                        // Save extra params
     1157                        QStringList params = i->extraParams();
     1158                        foreach(QString par, params) {
     1159                                stream << "#EXTVLCOPT:" << par << "\n";
     1160                        }
     1161
    9921162                        // Try to save the filename as relative instead of absolute
    9931163                        if (filename.startsWith( dir_path )) {
     
    9981168                f.close();
    9991169
     1170                setPlaylistFilename(file);
    10001171                setModified( false );
    10011172                return true;
     
    10481219
    10491220        bool ok = (set.status() == QSettings::NoError);
    1050         if (ok) setModified( false );
     1221        if (ok) {
     1222                setPlaylistFilename(file);
     1223                setModified( false );
     1224        }
    10511225
    10521226        return ok;
     
    11121286                stream << "</playlist>\n";
    11131287
     1288                setPlaylistFilename(filename);
    11141289                setModified(false);
    11151290                return true;
     
    11471322}
    11481323
    1149 bool Playlist::save() {
    1150         Extensions e;
    1151         QString s = MyFileDialog::getSaveFileName(
     1324bool Playlist::saveCurrentPlaylist() {
     1325        qDebug("Playlist::saveCurrentPlaylist");
     1326        return save(playlistFilename());
     1327}
     1328
     1329bool Playlist::save(const QString & filename) {
     1330        qDebug() << "Playlist::save:" << filename;
     1331
     1332        QString s = filename;
     1333
     1334        if (s.isEmpty()) {
     1335                Extensions e;
     1336                s = MyFileDialog::getSaveFileName(
    11521337                    this, tr("Choose a filename"),
    11531338                    lastDir(),
    11541339                    tr("Playlists") + e.playlist().forFilter() + ";;" + tr("All files") +" (*)");
     1340        }
    11551341
    11561342        if (!s.isEmpty()) {
     
    12221408        qDebug("Playlist::showPopup: x: %d y: %d", pos.x(), pos.y() );
    12231409
     1410        QModelIndex index = listView->currentIndex();
     1411        if (!index.isValid()) {
     1412                playAct->setEnabled(false);
     1413                removeSelectedAct->setEnabled(false);
     1414                editAct->setEnabled(false);
     1415                #ifdef PLAYLIST_DELETE_FROM_DISK
     1416                deleteSelectedFileFromDiskAct->setEnabled(false);
     1417                #endif
     1418                copyURLAct->setEnabled(false);
     1419                openFolderAct->setEnabled(false);
     1420                #ifdef CHROMECAST_SUPPORT
     1421                playOnChromecastAct->setEnabled(false);
     1422                #else
     1423                openURLInWebAct->setEnabled(false);
     1424                #endif
     1425        } else {
     1426                playAct->setEnabled(true);
     1427                removeSelectedAct->setEnabled(true);
     1428                editAct->setEnabled(true);
     1429                #ifdef PLAYLIST_DELETE_FROM_DISK
     1430                deleteSelectedFileFromDiskAct->setEnabled(true);
     1431                #endif
     1432                copyURLAct->setEnabled(true);
     1433                openFolderAct->setEnabled(true);
     1434                #ifdef CHROMECAST_SUPPORT
     1435                playOnChromecastAct->setEnabled(true);
     1436                #else
     1437                openURLInWebAct->setEnabled(true);
     1438                #endif
     1439
     1440                QModelIndex s_index = proxy->mapToSource(index);
     1441                int current = s_index.row();
     1442                PLItem * i = itemData(current);
     1443                QString filename = i->filename();
     1444                QFileInfo fi(filename);
     1445
     1446                if (fi.exists()) {
     1447                        copyURLAct->setText( tr("&Copy file path to clipboard") );
     1448                        #ifndef CHROMECAST_SUPPORT
     1449                        openURLInWebAct->setEnabled(false);
     1450                        #endif
     1451                } else {
     1452                        copyURLAct->setText( tr("&Copy URL to clipboard") );
     1453                        openFolderAct->setEnabled(false);
     1454                }
     1455        }
     1456
    12241457        if (!popup->isVisible()) {
    12251458                popup->move( listView->viewport()->mapToGlobal(pos) );
     
    12451478        }
    12461479
    1247         QString filename = itemFromProxy(n)->filename();
     1480        PLItem * i = itemFromProxy(n);
     1481        QString filename = i->filename();
     1482        QStringList params = i->extraParams();
     1483
    12481484        if (!filename.isEmpty()) {
    12491485                setCurrentItem(n);
    1250                 if (play_files_from_start) {
    1251                         emit requestToPlayFile(filename, 0);
     1486
     1487                if (!params.isEmpty()) {
     1488                        emit requestToPlayStream(filename, params);
    12521489                } else {
    1253                         emit requestToPlayFile(filename);
     1490                        if (play_files_from_start) {
     1491                                emit requestToPlayFile(filename, 0);
     1492                        } else {
     1493                                emit requestToPlayFile(filename);
     1494                        }
    12541495                }
    12551496        }
     
    12941535}
    12951536
     1537void Playlist::playNextAuto() {
     1538        qDebug("Playlist::playNextAuto");
     1539        if (automatically_play_next) {
     1540                playNext();
     1541        } else {
     1542                emit playlistEnded();
     1543        }
     1544}
    12961545
    12971546void Playlist::resumePlay() {
     
    13111560        double duration = mdat.duration;
    13121561        QString artist = mdat.clip_artist;
     1562        QString video_url = mdat.stream_path;
    13131563
    13141564        #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
     
    13501600                                i->setDuration(duration);
    13511601                        }
     1602                        i->setVideoURL(video_url);
    13521603                }
    13531604        }
     
    13681619                            tr("All files") +" (*.*)" );
    13691620
    1370         if (files.count()!=0) addFiles(files); 
     1621        if (files.count() != 0) {
     1622                addFiles(files);
     1623                setModified(true);
     1624        }
    13711625}
    13721626
     
    14461700                        if (!u.isEmpty()) addItem( u, "", 0 );
    14471701                }
     1702                setModified(true);
    14481703        }
    14491704}
     
    14871742                }
    14881743        }
     1744        setModified(true);
    14891745}
    14901746
     
    15131769void Playlist::removeAll() {
    15141770        clear();
     1771        setPlaylistFilename("");
    15151772}
    15161773
     
    15681825                table->insertRow(s_prev.row(), cells);
    15691826                listView->selectionModel()->setCurrentIndex(listView->model()->index(index.row()-1, 0), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
     1827
     1828                setModified(true);
    15701829        }
    15711830}
     
    15981857                table->insertRow(s_next.row(), cells);
    15991858                listView->selectionModel()->setCurrentIndex(listView->model()->index(index.row()+1, 0), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
     1859
     1860                setModified(true);
    16001861        }
    16011862}
     
    16221883            QLineEdit::Normal,
    16231884            current_name, &ok );
    1624     if ( ok && !text.isEmpty() ) {
     1885        if ( ok && !text.isEmpty() ) {
    16251886                // user entered something and pressed OK
    16261887                i->setName(text);
     
    16331894}
    16341895
     1896#ifdef PLAYLIST_DELETE_FROM_DISK
    16351897void Playlist::deleteSelectedFileFromDisk() {
    16361898        qDebug("Playlist::deleteSelectedFileFromDisk");
     
    16831945        }
    16841946}
     1947#endif
     1948
     1949void Playlist::copyURL() {
     1950        qDebug("Playlist::copyURL");
     1951
     1952        QModelIndexList indexes = listView->selectionModel()->selectedRows();
     1953        int count = indexes.count();
     1954
     1955        QString text;
     1956
     1957        for (int n = 0; n < count; n++) {
     1958                QModelIndex s_index = proxy->mapToSource(indexes.at(n));
     1959                int current = s_index.row();
     1960                text += itemData(current)->filename();
     1961                if (n < count-1) {
     1962                        #ifdef Q_OS_WIN
     1963                        text += "\r\n";
     1964                        #else
     1965                        text += "\n";
     1966                        #endif
     1967                }
     1968        }
     1969
     1970        if (!text.isEmpty()) QApplication::clipboard()->setText(text);
     1971}
     1972
     1973void Playlist::openFolder() {
     1974        qDebug("Playlist::openFolder");
     1975
     1976        QModelIndex index = listView->currentIndex();
     1977        if (!index.isValid()) return;
     1978        QModelIndex s_index = proxy->mapToSource(index);
     1979        int current = s_index.row();
     1980        PLItem * i = itemData(current);
     1981        QString filename = i->filename();
     1982
     1983        qDebug() << "Playlist::openFolder: filename:" << filename;
     1984
     1985        QFileInfo fi(filename);
     1986        if (fi.exists()) {
     1987                QString src_folder = fi.absolutePath();
     1988                QDesktopServices::openUrl(QUrl::fromLocalFile(src_folder));
     1989        }
     1990}
     1991
     1992#ifdef CHROMECAST_SUPPORT
     1993void Playlist::playOnChromecast() {
     1994        qDebug("Playlist::playOnChromecast");
     1995
     1996        QModelIndex index = listView->currentIndex();
     1997        if (!index.isValid()) return;
     1998        QModelIndex s_index = proxy->mapToSource(index);
     1999        int current = s_index.row();
     2000        PLItem * i = itemData(current);
     2001        QString filename = i->filename();
     2002        QString video_url = i->videoURL();
     2003
     2004        QString url = filename;
     2005        if (!video_url.isEmpty()) url = video_url;
     2006
     2007        if (QFile::exists(filename)) {
     2008                Chromecast::instance()->openLocal(url, i->name());
     2009        } else {
     2010                Chromecast::instance()->openStream(url, i->name());
     2011        }
     2012}
     2013#else
     2014void Playlist::openURLInWeb() {
     2015        qDebug("Playlist::openURLInWeb");
     2016
     2017        QModelIndex index = listView->currentIndex();
     2018        if (!index.isValid()) return;
     2019        QModelIndex s_index = proxy->mapToSource(index);
     2020        int current = s_index.row();
     2021        PLItem * i = itemData(current);
     2022        QString filename = i->filename();
     2023        QString video_url = i->videoURL();
     2024
     2025        QString url = filename;
     2026        if (!video_url.isEmpty()) url = video_url;
     2027
     2028        QDesktopServices::openUrl(QUrl(url));
     2029}
     2030#endif
    16852031
    16862032// Drag&drop
     
    17312077                }
    17322078        }
     2079
     2080        if (only_files.count() == 1) {
     2081                // Check if the file is a playlist
     2082                QString filename = only_files[0];
     2083                QFileInfo fi(filename);
     2084                QString extension = fi.suffix().toLower();
     2085                if (extension == "m3u8" || extension == "m3u") { load_m3u(filename); return; }
     2086                else
     2087                if (extension == "pls") { load_pls(filename); return; }
     2088                else
     2089                if (extension == "xspf") { loadXSPF(filename); return; }
     2090        }
     2091
    17332092        addFiles( only_files );
     2093        setModified(true);
    17342094}
    17352095
     
    17832143        set->setValue( "save_playlist_in_config", save_playlist_in_config );
    17842144        set->setValue( "play_files_from_start", play_files_from_start );
     2145        set->setValue( "start_play_on_load", start_play_on_load );
    17852146        set->setValue( "automatically_play_next", automatically_play_next );
    17862147        set->setValue( "ignore_player_errors", ignore_player_errors );
     
    17922153        set->setValue( "size", size() );
    17932154#endif
    1794         set->setValue(QString("header_state/%1").arg(Helper::qtVersion()), listView->horizontalHeader()->saveState());
     2155
     2156        set->setValue(QString("header_state/2/%1").arg(Helper::qtVersion()), listView->horizontalHeader()->saveState());
    17952157
    17962158        set->setValue( "sort_column", proxy->sortColumn() );
    17972159        set->setValue( "sort_order", proxy->sortOrder() );
    1798         set->setValue( "filter_case_sensivity", proxy->filterCaseSensitivity() );
     2160        set->setValue( "filter_case_sensitive", filterCaseSensitive() );
    17992161        set->setValue( "filter", filter_edit->text() );
    1800         set->setValue( "sort_case_sensivity", proxy->sortCaseSensitivity() );
     2162        set->setValue( "sort_case_sensitive", sortCaseSensitive() );
     2163        set->setValue( "auto_sort", autoSort() );
     2164
     2165        set->setValue( "show_search", showSearchAct->isChecked() );
    18012166
    18022167        set->endGroup();
     
    18182183                        set->setValue( QString("item_%1_duration").arg(n), i->duration() );
    18192184                        set->setValue( QString("item_%1_name").arg(n), i->name() );
     2185                        set->setValue( QString("item_%1_params").arg(n), i->extraParams() );
     2186                        set->setValue( QString("item_%1_video_url").arg(n), i->videoURL() );
    18202187                }
    18212188                set->endArray();
    18222189                set->setValue( "current_item", findCurrentItem() );
     2190                set->setValue("filename", playlistFilename());
    18232191                set->setValue( "modified", modified );
    18242192
     
    18342202
    18352203        if (set->contains("playlist/change_title")) set->remove("playlist/change_title");
     2204        if (set->contains("playlist/sort_case_sensivity")) set->remove("playlist/sort_case_sensivity");
     2205        if (set->contains("playlist/filter_case_sensivity")) set->remove("playlist/filter_case_sensivity");
    18362206}
    18372207
     
    18502220        save_playlist_in_config = set->value( "save_playlist_in_config", save_playlist_in_config ).toBool();
    18512221        play_files_from_start = set->value( "play_files_from_start", play_files_from_start ).toBool();
     2222        start_play_on_load = set->value( "start_play_on_load", start_play_on_load ).toBool();
    18522223        automatically_play_next = set->value( "automatically_play_next", automatically_play_next ).toBool();
    18532224        ignore_player_errors = set->value( "ignore_player_errors", ignore_player_errors ).toBool();
     
    18592230        resize( set->value("size", size()).toSize() );
    18602231#endif
    1861         listView->horizontalHeader()->restoreState(set->value(QString("header_state/%1").arg(Helper::qtVersion()), QByteArray()).toByteArray());
     2232
     2233        listView->horizontalHeader()->restoreState(set->value(QString("header_state/2/%1").arg(Helper::qtVersion()), QByteArray()).toByteArray());
    18622234
    18632235        int sort_column = set->value("sort_column", COL_NUM).toInt();
    18642236        int sort_order = set->value("sort_order", Qt::AscendingOrder).toInt();
    1865         int filter_case_sensivity = set->value("filter_case_sensivity", Qt::CaseInsensitive).toInt();
     2237        bool filter_case_sensitive = set->value("filter_case_sensitive", false).toBool();
    18662238        QString filter = set->value( "filter").toString();
    1867         int sort_case_sensivity = set->value("sort_case_sensivity", Qt::CaseInsensitive).toInt();
     2239        bool sort_case_sensitive = set->value("sort_case_sensitive", false).toBool();
     2240        bool auto_sort = set->value("auto_sort", false).toBool();
     2241
     2242        showSearchAct->setChecked( set->value( "show_search", false).toBool() );
    18682243
    18692244        set->endGroup();
     
    18882263                        duration = set->value( QString("item_%1_duration").arg(n), -1 ).toDouble();
    18892264                        name = set->value( QString("item_%1_name").arg(n), "" ).toString();
    1890                         addItem( filename, name, duration );
     2265                        QStringList params = set->value( QString("item_%1_params").arg(n), QStringList()).toStringList();
     2266                        QString video_url = set->value( QString("item_%1_video_url").arg(n), "").toString();
     2267                        addItem( filename, name, duration, params, video_url );
    18912268                }
    18922269                set->endArray();
    18932270                setCurrentItem( set->value( "current_item", -1 ).toInt() );
     2271                setPlaylistFilename( set->value("filename", "").toString() );
    18942272                setModified( set->value( "modified", false ).toBool() );
    18952273
     
    19052283#endif
    19062284
    1907         proxy->setFilterCaseSensitivity( (Qt::CaseSensitivity) filter_case_sensivity);
    1908         proxy->setSortCaseSensitivity( (Qt::CaseSensitivity) sort_case_sensivity);
     2285        setFilterCaseSensitive(filter_case_sensitive);
     2286        setSortCaseSensitive(sort_case_sensitive);
    19092287        proxy->sort(sort_column, (Qt::SortOrder) sort_order);
    19102288        filter_edit->setText(filter);
     2289        setAutoSort(auto_sort);
     2290
     2291        if (!listView->isColumnHidden(COL_NUM)) showPositionColumnAct->setChecked(true);
     2292        if (!listView->isColumnHidden(COL_NAME)) showNameColumnAct->setChecked(true);
     2293        if (!listView->isColumnHidden(COL_TIME)) showDurationColumnAct->setChecked(true);
     2294        if (!listView->isColumnHidden(COL_FILENAME)) showFilenameColumnAct->setChecked(true);
    19112295}
    19122296
     
    19142298        QString last_dir = latest_dir;
    19152299        return last_dir;
     2300}
     2301
     2302void Playlist::setPositionColumnVisible(bool b) {
     2303        listView->setColumnHidden(COL_NUM, !b);
     2304}
     2305
     2306void Playlist::setNameColumnVisible(bool b) {
     2307        listView->setColumnHidden(COL_NAME, !b);
     2308}
     2309
     2310void Playlist::setDurationColumnVisible(bool b) {
     2311        listView->setColumnHidden(COL_TIME, !b);
     2312}
     2313
     2314void Playlist::setFilenameColumnVisible(bool b) {
     2315        listView->setColumnHidden(COL_FILENAME, !b);
     2316}
     2317
     2318void Playlist::setAutoSort(bool b) {
     2319        proxy->setDynamicSortFilter(b);
     2320}
     2321
     2322bool Playlist::autoSort() {
     2323        return proxy->dynamicSortFilter();
     2324}
     2325
     2326void Playlist::setSortCaseSensitive(bool b) {
     2327        Qt::CaseSensitivity c = b ? Qt::CaseSensitive : Qt::CaseInsensitive;
     2328        proxy->setSortCaseSensitivity(c);
     2329}
     2330
     2331bool Playlist::sortCaseSensitive() {
     2332        return (proxy->sortCaseSensitivity() == Qt::CaseSensitive);
     2333}
     2334
     2335void Playlist::setFilterCaseSensitive(bool b) {
     2336        Qt::CaseSensitivity c = b ? Qt::CaseSensitive : Qt::CaseInsensitive;
     2337        proxy->setFilterCaseSensitivity(c);
     2338}
     2339
     2340bool Playlist::filterCaseSensitive() {
     2341        return (proxy->filterCaseSensitivity() == Qt::CaseSensitive);
    19162342}
    19172343
     
    19602386        if (data.contains("#EXTM3U")) {
    19612387                load_m3u(tfile, M3U8);
     2388                setPlaylistFilename("");
    19622389        }
    19632390        else
    19642391        if (data.contains("[playlist]")) {
    19652392                load_pls(tfile);
     2393                setPlaylistFilename("");
    19662394        }
    19672395        else
    19682396        if (data.contains("xspf.org")) {
    19692397                loadXSPF(tfile);
     2398                setPlaylistFilename("");
    19702399        }
    19712400        else {
Note: See TracChangeset for help on using the changeset viewer.