diff -Nru minitunes-0.1.1/debian/changelog minitunes-0.1.1+git08302010/debian/changelog --- minitunes-0.1.1/debian/changelog 2010-10-21 22:36:05.000000000 +0000 +++ minitunes-0.1.1+git08302010/debian/changelog 2010-10-23 01:21:15.000000000 +0000 @@ -1,3 +1,11 @@ +minitunes (0.1.1+git08302010-0~ppa1) maverick; urgency=low + + * New snapshot from git (http://gitorious.org/minitunes/). + - remove executable bits. + - playlist persistence and the empty playlist text overlay. + + -- Nicola Ferralis Fri, 22 Oct 2010 18:06:46 -0700 + minitunes (0.1.1-0nf4~ppa1) maverick; urgency=low * Patch: fixed prefix in base directory (from /usr/local to /usr) diff -Nru minitunes-0.1.1/debian/patches/add_git_to_version.diff minitunes-0.1.1+git08302010/debian/patches/add_git_to_version.diff --- minitunes-0.1.1/debian/patches/add_git_to_version.diff 1970-01-01 00:00:00.000000000 +0000 +++ minitunes-0.1.1+git08302010/debian/patches/add_git_to_version.diff 2010-10-23 01:34:29.000000000 +0000 @@ -0,0 +1,11 @@ +diff -Nru minitunes.orig//minitunes.pro minitunes/minitunes.pro +--- minitunes.orig//minitunes.pro 2010-10-22 18:19:15.000000000 -0700 ++++ minitunes/minitunes.pro 2010-10-22 18:33:38.982951001 -0700 +@@ -1,6 +1,6 @@ + CONFIG += release + TEMPLATE = app +-VERSION = 0.1.1 ++VERSION = 0.1.1+git08302010 + DEFINES += APP_VERSION="$$VERSION" + INCLUDEPATH += /usr/include/phonon + INCLUDEPATH += /usr/include/taglib diff -Nru minitunes-0.1.1/debian/patches/series minitunes-0.1.1+git08302010/debian/patches/series --- minitunes-0.1.1/debian/patches/series 2010-10-21 22:32:40.000000000 +0000 +++ minitunes-0.1.1+git08302010/debian/patches/series 2010-10-23 01:35:06.000000000 +0000 @@ -1 +1,2 @@ +add_git_to_version.diff prefix_usr_local.diff diff -Nru minitunes-0.1.1/.gitignore minitunes-0.1.1+git08302010/.gitignore --- minitunes-0.1.1/.gitignore 2010-07-13 10:30:19.000000000 +0000 +++ minitunes-0.1.1+git08302010/.gitignore 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -build/ -Makefile* -minitunes.pro.user -.settings/ -.DS_Store -.cproject -.project -stuff -*.sh -local/ diff -Nru minitunes-0.1.1/src/mainwindow.cpp minitunes-0.1.1+git08302010/src/mainwindow.cpp --- minitunes-0.1.1/src/mainwindow.cpp 2010-07-13 10:30:19.000000000 +0000 +++ minitunes-0.1.1+git08302010/src/mainwindow.cpp 2010-10-23 01:19:30.000000000 +0000 @@ -77,6 +77,7 @@ if (db.status() == ScanComplete) { showMediaView(); + loadPlaylist(); // update the collection when idle QTimer::singleShot(1000, this, SLOT(startIncrementalScan())); @@ -621,6 +622,7 @@ } void MainWindow::quit() { + savePlaylist(); writeSettings(); /* CollectionScanner *scanner = CollectionScanner::instance(); @@ -988,3 +990,41 @@ if (updateChecker) delete updateChecker; statusBar()->addWidget(message); } + +void MainWindow::savePlaylist() +{ + const PlaylistModel* playlistModel = mediaView->getPlaylistModel(); + if (playlistModel == 0) + return; + + QSettings settings; + + const QString storageLocation = + QDesktopServices::storageLocation(QDesktopServices::DataLocation); + // We need to use a default name, so why not the application one? (minitunes.pls sounds fine) + QString defaultPls = QString("%1/%2.pls").arg(storageLocation).arg(qApp->applicationName()); + QString plsPath = settings.value("loadedPlaylist", defaultPls).toString(); + + QFile plsFile(plsPath); + QTextStream plsStream(&plsFile); + if ( plsFile.open(QFile::WriteOnly | QFile::Truncate) && playlistModel->saveTo(plsStream) ) + settings.setValue("loadedPlaylist", plsPath); +} + +void MainWindow::loadPlaylist() +{ + QSettings settings; + QString plsPath = settings.value("loadedPlaylist").toString(); + qDebug() << "loading playlist: " << plsPath; + if (!QFile::exists(plsPath)) + return; + PlaylistModel* playlistModel = mediaView->getPlaylistModel(); + if (playlistModel == 0) + return; + QFile plsFile(plsPath); + QTextStream plsStream(&plsFile); + if ( plsFile.open(QFile::ReadOnly) ) + playlistModel->loadFrom(plsStream); + else + qDebug() << "Fail to open: " << plsPath; +} diff -Nru minitunes-0.1.1/src/mainwindow.h minitunes-0.1.1+git08302010/src/mainwindow.h --- minitunes-0.1.1/src/mainwindow.h 2010-07-13 10:30:19.000000000 +0000 +++ minitunes-0.1.1+git08302010/src/mainwindow.h 2010-10-23 01:19:30.000000000 +0000 @@ -78,6 +78,8 @@ void initPhonon(); void checkForUpdate(); static QString formatTime(qint64 time); + void savePlaylist(); + void loadPlaylist(); // view mechanism QStackedWidget *views; diff -Nru minitunes-0.1.1/src/mediaview.cpp minitunes-0.1.1+git08302010/src/mediaview.cpp --- minitunes-0.1.1/src/mediaview.cpp 2010-07-13 10:30:19.000000000 +0000 +++ minitunes-0.1.1+git08302010/src/mediaview.cpp 2010-10-23 01:19:25.000000000 +0000 @@ -43,6 +43,7 @@ // playlist view playlistView = new PlaylistView(this); + playlistView->setEmptyPlaylistMessage(tr("Drop items here")); playlistView->setDropArea(dropArea); playlistView->setPlaylistModel(playlistModel); // connect(playlistView, SIGNAL(needDropArea()), SLOT(showDropArea())); diff -Nru minitunes-0.1.1/src/playlistmodel.cpp minitunes-0.1.1+git08302010/src/playlistmodel.cpp --- minitunes-0.1.1/src/playlistmodel.cpp 2010-07-13 10:30:19.000000000 +0000 +++ minitunes-0.1.1+git08302010/src/playlistmodel.cpp 2010-10-23 01:19:25.000000000 +0000 @@ -384,5 +384,56 @@ qDebug() << "removing track from playlist model" << track; removeRows(trackRow, 1, QModelIndex()); } +} + +bool PlaylistModel::saveTo(QTextStream & stream) const +{ + // stream not opened or not writable + if ( !stream.device()->isOpen() || !stream.device()->isWritable() ) + return false; + + stream.setCodec("UTF-8"); + stream << "[playlist]" << endl; + int idx = 1; + foreach(Track* tr, tracks) + { + stream << "File" << idx << "=" << tr->getPath() << endl; + stream << "Title" << idx << "=" << tr->getTitle() << endl; + stream << "Length" << idx++ << "=" << tr->getLength() << endl; + } + stream << "NumberOfEntries=" << tracks.count() << endl; + stream << "Version=2" << endl; + + return true; +} + +bool PlaylistModel::loadFrom(QTextStream & stream) +{ + // stream not opened or not writable + if ( !stream.device()->isOpen() || !stream.device()->isReadable() ) + return false; + + stream.setCodec("UTF-8"); + QString header; + QString tag; + Track* cur = 0; + stream >> header; + while ( !stream.atEnd() ) + { + QString line = stream.readLine(1024); + if ( line.startsWith("File") ) + { + QString path = line.section("=", -1); + cur = Track::forPath(path); + addTrack(cur); + } + else if ( line.startsWith("Title") && cur != NULL ) + { + tag = line.right(line.size()-line.indexOf("=")-1); + if ( !tag.isNull() && !tag.isEmpty() ) + cur->setTitle(tag); + } + } + return true; } diff -Nru minitunes-0.1.1/src/playlistmodel.h minitunes-0.1.1+git08302010/src/playlistmodel.h --- minitunes-0.1.1/src/playlistmodel.h 2010-07-13 10:30:19.000000000 +0000 +++ minitunes-0.1.1+git08302010/src/playlistmodel.h 2010-10-23 01:19:25.000000000 +0000 @@ -48,6 +48,10 @@ Track* getActiveTrack() const; int getTotalLength() { return Track::getTotalLength(tracks); } + // IO methods + bool saveTo(QTextStream& stream) const; + bool loadFrom(QTextStream& stream); + public slots: void addTrack(Track* track); void addTracks(QList tracks); diff -Nru minitunes-0.1.1/src/playlistview.cpp minitunes-0.1.1+git08302010/src/playlistview.cpp --- minitunes-0.1.1/src/playlistview.cpp 2010-07-13 10:30:19.000000000 +0000 +++ minitunes-0.1.1+git08302010/src/playlistview.cpp 2010-10-23 01:19:25.000000000 +0000 @@ -12,7 +12,7 @@ PlaylistView::PlaylistView(QWidget *parent) : QListView(parent), - playlistModel(0) { + playlistModel(0), overlayLabel(0) { // delegate setItemDelegate(new PlaylistItemDelegate(this)); @@ -159,3 +159,32 @@ QTimer::singleShot(1000, dropArea, SLOT(hide())); } */ + +void PlaylistView::paintEvent(QPaintEvent *event) { + QListView::paintEvent(event); + + if ( playlistModel->rowCount() == 0 + && !emptyMessage.isEmpty()) { + + event->accept(); + + QPainter painter(this->viewport()); + QPen textPen(Qt::DashLine); + textPen.setWidth(2); + painter.setPen(textPen); + + QFont biggerFont = qApp->font(); + biggerFont.setPointSize(24); + painter.setFont(biggerFont); + + QSize textSize(this->size().width()-5, 100); + QPoint centerPoint((this->width()-textSize.width())/2, + (this->height()/3)); + QRect centerRect(centerPoint, textSize); + QRect boundRect; + painter.drawText(centerRect, Qt::AlignCenter, emptyMessage, &boundRect); + boundRect.adjust(-7, -7, 7, 7); + painter.drawRect(boundRect); + } +} + diff -Nru minitunes-0.1.1/src/playlistview.h minitunes-0.1.1+git08302010/src/playlistview.h --- minitunes-0.1.1/src/playlistview.h 2010-07-13 10:30:19.000000000 +0000 +++ minitunes-0.1.1+git08302010/src/playlistview.h 2010-10-23 01:19:25.000000000 +0000 @@ -17,6 +17,9 @@ void setDropArea(DropArea *dropArea) { this->dropArea = dropArea; } + void setEmptyPlaylistMessage(QString emptyMessage) { + this->emptyMessage = emptyMessage; + } signals: void needDropArea(); @@ -30,8 +33,10 @@ void updatePlaylistActions(); void selectTracks(QList tracks); - /* + protected: + void paintEvent(QPaintEvent *event); + /* void dragEnterEvent(QDragEnterEvent *event); void dragLeaveEvent(QDragLeaveEvent *event); */ @@ -40,6 +45,8 @@ PlaylistModel *playlistModel; DropArea *dropArea; bool willHideDropArea; + QString emptyMessage; + QLabel* overlayLabel; };