cleanup & small fixes
authortmarki <tmarki@gmail.com>
Fri, 20 Aug 2010 16:07:19 +0000 (18:07 +0200)
committertmarki <tmarki@gmail.com>
Fri, 20 Aug 2010 16:07:19 +0000 (18:07 +0200)
tomamp/mainwindow.cpp
tomamp/playlistmanager.cpp

index 7776725..d95c2d6 100644 (file)
@@ -13,7 +13,6 @@
 MainWindow::MainWindow()
     : plman (this), settings (tr ("TomAmp"), "TomAmp"), isPlaying (false)
 {
-    setOrientation();
     audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
     mediaObject = new Phonon::MediaObject(this);
 
@@ -50,6 +49,7 @@ MainWindow::MainWindow()
         setItem (curind, false);
     audioOutput->setVolume(settings.value("volume", .5).toReal());
     QApplication::setWindowIcon(QIcon (QPixmap (":images/tomamp")));
+    setOrientation();
 }
 
 MainWindow::~MainWindow()
@@ -72,11 +72,17 @@ void MainWindow::setOrientation ()
 #ifdef Q_WS_MAEMO_5
     QString orient = settings.value("orientation", "Automatic").toString();
     if (orient == "Portrait")
+    {
         setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
+    }
     else if (orient == "Landscape")
+    {
         setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
+    }
     else
+    {
         setAttribute(Qt::WA_Maemo5AutoOrientation, true);
+    }
 #endif
 }
 
@@ -215,6 +221,7 @@ void MainWindow::next()
     if (mediaObject->queue().size())
     {
         setItem (plman.indexOf(mediaObject->queue()[0]), wasPlaying);
+        mediaObject->queue().clear();
         return;
     }
     int index = plman.indexOf(mediaObject->currentSource());
@@ -644,8 +651,11 @@ void MainWindow::setupUi()
 
     volumeSlider = new Phonon::VolumeSlider(this);
     volumeSlider->setAudioOutput(audioOutput);
-    volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
-    if (flip) volumeSlider->setOrientation(Qt::Vertical);
+    if (flip)
+    {
+        volumeSlider->setOrientation(Qt::Vertical);
+    }
+    volumeSlider->setMinimumWidth(150);
     volumeSlider->setMuteVisible(false);
     bar->addAction(playAction);
     bar->addAction(pauseAction);
@@ -680,6 +690,8 @@ void MainWindow::setupUi()
     musicTable->setHorizontalHeaderLabels(headers);
     musicTable->setSelectionMode(QAbstractItemView::SingleSelection);
     musicTable->setSelectionBehavior(QAbstractItemView::SelectRows);
+//    musicTable->setAlternatingRowColors(true);
+    musicTable->verticalHeader ()->hide();
     connect(musicTable, SIGNAL(cellDoubleClicked(int,int)),
         this, SLOT(tableClicked(int,int)));
     connect(musicTable, SIGNAL(cellClicked(int,int)),
@@ -747,12 +759,13 @@ void MainWindow::cellClicked(int /*row*/, int)
 void MainWindow::enqueueSelected()
 {
     int sel = musicTable->currentRow();
+    qDebug () << "Enqueue on " << sel;
     if (sel >= 0)
     {
         mediaObject->queue().clear();
         mediaObject->enqueue(plman.at(sel));
 #ifdef Q_WS_MAEMO_5
-        QMaemo5InformationBox::information(this, tr ("Enqueued as next song"),
+        QMaemo5InformationBox::information(this, plman.getItem(sel).title + tr (" enqueued as next song"),
         QMaemo5InformationBox::DefaultTimeout);
 #endif
 
@@ -888,7 +901,7 @@ void MainWindow::setRowFromItem (int row, const PlaylistItem& item)
     if (controlCol >= 0 && !musicTable->cellWidget(row, controlCol))
     {
         QLabel* label = new QLabel;
-        label->setText(QString::fromUtf8("<b><a style='text-decoration:none' href='up'>▲</a> <a style='text-decoration:none' href='down'>▼</a> <a style='text-decoration:none' href='del'>╳</a> <a style='text-decoration:none' href='info'>i</a></b>"));
+        label->setText(QString::fromUtf8("<b><a style='text-decoration:none' href='up'>▲</a> <a style='text-decoration:none' href='down'>▼</a> <a style='text-decoration:none' href='del'>╳</a> <a style='text-decoration:none' href='enq'>E</a></b>"));
         label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
         label->setProperty("row", row);
         musicTable->setCellWidget(row, controlCol, label);
@@ -899,13 +912,17 @@ void MainWindow::setRowFromItem (int row, const PlaylistItem& item)
 void MainWindow::playlistControl (const QString& con)
 {
     int i = sender ()->property("row").toInt();
-    qDebug () << "Playlist control: " << con << " on " << i;
     if (con == "up")
         buttonUp(i);
     else if (con == "down")
         buttonDown(i);
     else if (con == "del")
         buttonDel (i);
+    else if (con == "enq")
+    {
+        musicTable->selectRow(i);
+        enqueueSelected();
+    }
     else
         QMessageBox::information(this, tr ("Coming up..."), tr ("This feature is not implemented yet."));
 }
@@ -913,7 +930,6 @@ void MainWindow::playlistControl (const QString& con)
 
 void MainWindow::buttonUp(int i)
 {
-    qDebug () << "Presses up on " << i;
     if (i)
     {
         plman.moveItemUp(i);
@@ -931,7 +947,6 @@ void MainWindow::buttonUp(int i)
 
 void MainWindow::buttonDown(int i)
 {
-    qDebug () << "Presses down on " << i;
     if (i < plman.size() - 1)
     {
         plman.moveItemDown(i);
@@ -949,7 +964,6 @@ void MainWindow::buttonDown(int i)
 
 void MainWindow::buttonDel(int i)
 {
-    qDebug () << "Presses del on " << i;
     if (QMessageBox::question(this, "Confirm remove", "Are you sure you want to remove this item?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
         return;
     if (i < plman.size())
@@ -1020,4 +1034,7 @@ void MainWindow::showOptions ()
         musicTable->setHorizontalHeaderLabels(headers);
         playlistChanged(0);
     }
+    int curitem = plman.indexOf(mediaObject->currentSource());
+    if (curitem >= 0 && isPlaying)
+        highlightRow(curitem);
 }
index 0365042..5809d94 100644 (file)
@@ -10,7 +10,6 @@ PlaylistManager::PlaylistManager(QWidget* parent)
     : parentWidget (parent), lastMetaRead (-1)
 {
     allowedExtensions << "mp3" << "ogg" << "wav" << "wmv" << "wma" << "flac";
-//    qDebug () << Phonon::BackendCapabilities::availableMimeTypes();
     metaInformationResolver = new Phonon::MediaObject(parent);
     connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
         this, SLOT(metaStateChanged(Phonon::State,Phonon::State)));
@@ -35,7 +34,6 @@ void PlaylistManager::parseAndAddFolder(const QString &dir, bool recursive)
     if (files.isEmpty())
         return;
 
-    qDebug () << "Parsing folder " << dir;
 
     int index = items.size();
     foreach (QString string, files)
@@ -61,7 +59,6 @@ void PlaylistManager::parseAndAddFolder(const QString &dir, bool recursive)
         metaInformationResolver->setCurrentSource(items.at(index).source);
         lastMetaRead = index;
     }
-    qDebug () << " SIZE: " << items.size ();
     emit playlistChanged (index);
 }
 
@@ -72,7 +69,6 @@ void PlaylistManager::addStringList(const QStringList& list)
     {
         if (fileSupported(string) || string.toLower().startsWith("http"))
         {
-            qDebug () << "Adding " << string;
             items.append(PlaylistItem (string));
         }
     }
@@ -86,7 +82,6 @@ void PlaylistManager::addStringList(const QStringList& list)
 
 void PlaylistManager::metaStateChanged(Phonon::State newState, Phonon::State oldState)
 {
-    qDebug () << "Meta state now " << newState << " old state " << oldState;
     // NOTE: This is an ugly hack, since the metaInformationResolver doesn't properly load the assigned source when it's in the error state
     // In order to properly read the next file we have to set it as current source again when the resolver entered the stopped state after the error
     static bool wasError = false;
@@ -210,7 +205,6 @@ void PlaylistManager::addPlaylist(const QString& filename)
 
 void PlaylistManager::appendPlaylist(const QString& filename)
 {
-    qDebug () << "Attempting to load playlist: " << filename;
     QFile f(filename);
     if (!f.open (QFile::ReadOnly))
         return;
@@ -223,14 +217,12 @@ void PlaylistManager::appendPlaylist(const QString& filename)
         {
             continue;
         }
-        qDebug () << "Load " << l;
         items.append(PlaylistItem (l));
     }
 }
 
 void PlaylistManager::appendPlaylistPLS(const QString& filename)
 {
-    qDebug () << "Attempting to load playlist: " << filename;
     QFile f(filename);
     if (!f.open (QFile::ReadOnly))
         return;
@@ -245,7 +237,6 @@ void PlaylistManager::appendPlaylistPLS(const QString& filename)
         {
             continue;
         }
-        qDebug () << "PLS " << l;
         if (l.trimmed().toLower().left(4) == "file")
         {
             QStringList tokens = l.split('=');
@@ -253,7 +244,6 @@ void PlaylistManager::appendPlaylistPLS(const QString& filename)
                 continue;
             tokens[0] = tokens[0].mid (4);
             filemap.insert(tokens[0].toInt (), items.size ());
-            qDebug () << tokens;
             items.append(PlaylistItem (tokens[1]));
         }
         else if (l.trimmed().toLower().left(5) == "title")
@@ -263,9 +253,7 @@ void PlaylistManager::appendPlaylistPLS(const QString& filename)
                 continue;
             tokens[0] = tokens[0].mid (5);
             int toupdate = filemap[tokens[0].toInt()];
-            qDebug () << "Need to update " << toupdate << " for " << l;
             QStringList metatok = tokens[1].split (" - ");
-            qDebug () << metatok;
             if (metatok.size() > 2 && toupdate >= 0 && toupdate < items.size ())
             {
                 items[toupdate].artist = metatok[0];
@@ -293,7 +281,6 @@ QStringList PlaylistManager::playlistStrings() const
     QStringList ret;
     for (int i = 0; i < items.size (); ++i)
         ret << items[i].uri;
-    qDebug () << "Returning playlist " << ret << " SIZE: " << items.size ();
     return ret;
 }