Merge branch 'alpha' of tomsrv:tomamp into alpha
authortmarki <tmarki@gmail.com>
Fri, 20 Aug 2010 12:07:49 +0000 (14:07 +0200)
committertmarki <tmarki@gmail.com>
Fri, 20 Aug 2010 12:07:49 +0000 (14:07 +0200)
1  2 
tomamp/mainwindow.cpp
tomamp/playlistmanager.cpp

diff --combined tomamp/mainwindow.cpp
@@@ -37,7 -37,10 +37,10 @@@ MainWindow::MainWindow(
      setupShuffleList();
      setupActions();
      setupMenus();
-     setupUi();
+ /*    if (settings.value("uiflipped", false).toBool())
+         setupUiFlipped();
+     else*/
+     setupUi ();
      show ();
      timeLcd->display("00:00:00");
      plman.addStringList(settings.value("lastPlaylist").toStringList());
@@@ -143,11 -146,12 +146,12 @@@ void MainWindow::addUrl(
  
  void MainWindow::about()
  {
 -    QMessageBox::information(this, tr("About TomAmp v0.1"),
 +    QMessageBox::information(this, tr("About TomAmp v0.2"),
          tr("TomAmp is a simple playlist-based music player.\n\n"
          "(c) 2010 Tamas Marki <tmarki@gmail.com>\n\n"
          "Please send comments and bug reports to the above e-mail address.\n\n"
-         "Icons by http://itweek.deviantart.com/"));
+         "Icons by http://itweek.deviantart.com/\n\n"
+         "Special thanks to Attila Csipa"));
  }
  
  void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */)
              playAction->setEnabled(false);
              pauseAction->setEnabled(true);
              stopAction->setEnabled(true);
-             //lastPlayed = plman.indexOf(mediaObject->currentSource());
+             unhighlightRow(lastPlayed);
+             lastPlayed = plman.indexOf(mediaObject->currentSource());
+             highlightRow(plman.indexOf(mediaObject->currentSource()));
+             musicTable->selectRow(plman.indexOf(mediaObject->currentSource()));
              break;
          case Phonon::StoppedState:
              setWindowTitle("TomAmp");
@@@ -259,8 -266,8 +266,8 @@@ void MainWindow::setItem(int i, bool do
  {
      if (i < plman.size() && i >= 0)
      {
-         if (lastPlayed >= 0)
-             unhighlightRow(lastPlayed);
+ /*        if (lastPlayed >= 0)
+             unhighlightRow(lastPlayed);*/
          if (shuffle)
          {
              mediaObject->setCurrentSource(plman.at (shuffleList[i]));
@@@ -488,6 -495,7 +495,7 @@@ void MainWindow::setupActions(
      shuffleAction->setCheckable(true);
      shuffleAction->setChecked(shuffle);
      shuffleAction->setShortcut(tr("Ctrl+H"));
+     enqueueActionButton = new QAction (tr ("E"), this);
      volumeAction = new QAction(QIcon (QPixmap (":images/volume")), "", this);
      volumeAction->setCheckable(true);
      volumeAction->setShortcut(tr("Ctrl+V"));
      connect(repeatAction, SIGNAL(triggered()), this, SLOT(repeatToggle()));
      connect(shuffleAction, SIGNAL(triggered()), this, SLOT(shuffleToggle()));
      connect(volumeAction, SIGNAL(triggered()), this, SLOT(volumeToggle()));
+     connect(enqueueActionButton, SIGNAL(triggered()), this, SLOT(enqueueSelected()));
  
      connect(addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles()));
      connect(addFoldersAction, SIGNAL(triggered()), this, SLOT(addFolder()));
@@@ -591,7 -600,7 +600,7 @@@ void MainWindow::volumeToggle (
  void MainWindow::play()
  {
      mediaObject->play();
-     lastPlayed = plman.indexOf(mediaObject->currentSource());
+ //    lastPlayed = plman.indexOf(mediaObject->currentSource());
      highlightRow(lastPlayed);
      isPlaying = true;
  }
@@@ -624,21 -633,20 +633,20 @@@ void MainWindow::setupMenus(
  void MainWindow::setupUi()
  {
      QToolBar *bar = new QToolBar;
+     bool flip = settings.value("uiflipped", false).toBool();
  
-     bar->setOrientation(Qt::Vertical);
+     if(!flip) bar->setOrientation(Qt::Vertical);
      bar->setStyleSheet("padding:7px");
  
      seekSlider = new Phonon::SeekSlider(this);
      seekSlider->setMediaObject(mediaObject);
+     if (flip) seekSlider->setOrientation(Qt::Vertical);
  
      volumeSlider = new Phonon::VolumeSlider(this);
      volumeSlider->setAudioOutput(audioOutput);
      volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
-     volumeSlider->setOrientation(Qt::Horizontal);
+     if (flip) volumeSlider->setOrientation(Qt::Vertical);
      volumeSlider->setMuteVisible(false);
- //    volumeAddedAction = bar->addWidget(volumeSlider);
- //    volumeAddedAction->setVisible(false);
      bar->addAction(playAction);
      bar->addAction(pauseAction);
      bar->addAction(stopAction);
      bar->addAction(upAction);
      bar->addAction(downAction);
      bar->addAction(delAction);
+     bar->addAction(enqueueActionButton);
  
      contextMenu = new QMenu (this);
      enqueueAction = contextMenu->addAction(tr ("Enqueue"));
      }
  
  
-     QHBoxLayout *seekerLayout = new QHBoxLayout;
+     QLayout *seekerLayout;
+     QLayout *playbackLayout;
+     if (flip)
+     {
+         seekerLayout = new QVBoxLayout;
+         playbackLayout = new QHBoxLayout;
+         bar->addWidget(timeLcd);
+     }
+     else
+     {
+         seekerLayout = new QHBoxLayout;
+         playbackLayout = new QVBoxLayout;
+     }
      QToolBar* bar2 = new QToolBar;
      bar2->addAction(volumeAction);
      seekerLayout->addWidget(bar2);
      seekerLayout->addWidget(volumeSlider);
      seekerLayout->addWidget(seekSlider);
-     seekerLayout->addWidget(timeLcd);
-     QVBoxLayout *playbackLayout = new QVBoxLayout;
+     if (!flip)
+         seekerLayout->addWidget(timeLcd);
      volumeSlider->hide ();
      playbackLayout->addWidget(bar);
  
      QVBoxLayout *seekAndTableLayout = new QVBoxLayout;
  
      seekAndTableLayout->addWidget(musicTable);
-     seekAndTableLayout->addLayout(seekerLayout);
      QHBoxLayout *mainLayout = new QHBoxLayout;
      mainLayout->addLayout(seekAndTableLayout);
-     mainLayout->addLayout(playbackLayout);
+     if (flip)
+     {
+         seekAndTableLayout->addLayout(playbackLayout);
+         mainLayout->addLayout(seekerLayout);
+     }
+     else
+     {
+         seekAndTableLayout->addLayout(seekerLayout);
+         mainLayout->addLayout(playbackLayout);
+     }
  
      QWidget *widget = new QWidget;
      widget->setLayout(mainLayout);
@@@ -724,7 -752,7 +752,7 @@@ void MainWindow::enqueueSelected(
          mediaObject->queue().clear();
          mediaObject->enqueue(plman.at(sel));
  #ifdef Q_WS_MAEMO_5
 -        QMaemo5InformationBox::information(this, tr ("Song enqueued as next song"),
 +        QMaemo5InformationBox::information(this, tr ("Enqueued as next song"),
          QMaemo5InformationBox::DefaultTimeout);
  #endif
  
@@@ -767,16 -795,7 +795,16 @@@ void MainWindow::savePlaylist (
      QString filename = QFileDialog::getSaveFileName(this, tr("Please select file name"), "", "Playlist Files (*.m3u *.pls)");
      if (filename.isEmpty())
          return;
 -    plman.savePlaylist(filename);
 +    if (!plman.savePlaylist(filename))
 +    {
 +#ifdef Q_WS_MAEMO_5
 +        QMaemo5InformationBox::information(this, tr ("Error writing playlist file"),
 +        QMaemo5InformationBox::DefaultTimeout);
 +#else
 +        QMessageBox::critical(this, "Write error", "Error writing playlist file", QMessageBox::Ok);
 +#endif
 +    }
 +
  }
  
  void MainWindow::loadPlaylist ()
@@@ -851,7 -870,6 +879,7 @@@ void MainWindow::setRowFromItem (int ro
          {
              QTableWidgetItem *item3 = new QTableWidgetItem(item.album);
              item3->setFlags(item3->flags() ^ Qt::ItemIsEditable);
 +
              musicTable->setItem(row, col, item3);
          }
      }
@@@ -975,9 -993,15 +1003,15 @@@ void MainWindow::downSelected(
  
  void MainWindow::showOptions ()
  {
+     bool flip = settings.value("uiflipped", false).toBool();
      OptionDialog* dlg = new OptionDialog (this, settings);
      dlg->exec();
      delete dlg;
+     if (flip != settings.value("uiflipped", false).toBool())
+     {
+         delete centralWidget();
+         setupUi ();
+     }
      setOrientation ();
      if (headers != settings.value("headers", QStringList ()).toStringList())
      {
@@@ -9,7 -9,7 +9,7 @@@ QStringList allowedExtensions
  PlaylistManager::PlaylistManager(QWidget* parent)
      : parentWidget (parent), lastMetaRead (-1)
  {
-     allowedExtensions << "mp3" << "ogg" << "wav" << "wmv" << "wma";
+     allowedExtensions << "mp3" << "ogg" << "wav" << "wmv" << "wma" << "flac";
  //    qDebug () << Phonon::BackendCapabilities::availableMimeTypes();
      metaInformationResolver = new Phonon::MediaObject(parent);
      connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
@@@ -29,7 -29,6 +29,6 @@@ int PlaylistManager::indexOf(const Phon
  void PlaylistManager::parseAndAddFolder(const QString &dir, bool recursive)
  {
      QStringList filters;
- //    filters << "*.mp3";
  
      QStringList files = QDir (dir).entryList(filters);
  
@@@ -38,7 -37,6 +37,6 @@@
  
      qDebug () << "Parsing folder " << dir;
  
-     //settings.setValue("LastFolder", dir);
      int index = items.size();
      foreach (QString string, files)
      {
@@@ -58,7 -56,6 +56,6 @@@
              items.append(PlaylistItem (PlaylistItem (fname)));
          }
      }
- //    if (!items.isEmpty())
      if (items.size () > index)
      {
          metaInformationResolver->setCurrentSource(items.at(index).source);
@@@ -79,7 -76,6 +76,6 @@@ void PlaylistManager::addStringList(con
              items.append(PlaylistItem (string));
          }
      }
- //    if (!items.isEmpty())
      if (items.size () > index)
      {
          metaInformationResolver->setCurrentSource(items.at(index).source);
@@@ -91,7 -87,7 +87,7 @@@
  void PlaylistManager::metaStateChanged(Phonon::State newState, Phonon::State oldState)
  {
      qDebug () << "Meta state now " << newState << " old state " << oldState;
-     // This is an ugly hack, since the metaInformationResolver doesn't properly load the assigned source when it's in the error state
+     // 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;
      if (wasError && newState == Phonon::StoppedState)
      }
  
      int index = lastMetaRead;
-     qDebug () << "Reading meta info of " << metaInformationResolver->currentSource().fileName() << " => " << index;
  
      QMap<QString, QString> metaData = metaInformationResolver->metaData();
  
          items[index].genre = metaData.value("GENRE");
          qDebug () << "Meta " << metaData;
          qDebug () << "Info is: " << items[index].year << " - " << items[index].genre;*/
-         if (metaData.isEmpty())
-             qDebug () << "Detected to be empty: " << items[index].uri;
-         else
+         if (!metaData.isEmpty())
              items[index].playable = true;
          emit itemUpdated (index);
      }
      }
  }
  
 -void PlaylistManager::savePlaylist(const QString& filenam)
 +bool PlaylistManager::savePlaylist(const QString& filenam)
  {
      QString filename = filenam;
      if (filename.isEmpty())
 -        return;
 +        return false;
      bool writepls = false;
      if (filename.length() < 4 || (filename.right(4).toLower() != ".m3u" && filename.right(4).toLower() != ".pls"))
      {
          if (writepls)
              f.write ("Version=2\n");
          f.close ();
 +        return true;
      }
      catch (...)
      {
 -//        QMessageBox::critical(this, "Write error", "Could not write playlist file", QMessageBox::Ok);
      }
 +    return false;
  }
  
  void PlaylistManager::loadPlaylist(const QString& filename)
@@@ -293,9 -285,6 +286,6 @@@ void PlaylistManager::clearPlaylist(
  {
      items.clear();
      emit playlistChanged(0);
- /*    while (musicTable->rowCount())
-         musicTable->removeRow(0);
-     mediaObject->clear();*/
  }
  
  QStringList PlaylistManager::playlistStrings() const
@@@ -316,7 -305,9 +306,9 @@@ void PlaylistManager::removeItem(int i
  
  bool PlaylistManager::fileSupported (const QString& fname) const
  {
-     QString ext = fname.right(3).toLower();
+     if (fname.lastIndexOf('.') < 0)
+         return false;
+     QString ext = fname.right(fname.size() - fname.lastIndexOf('.') - 1).toLower();
      foreach (QString e, allowedExtensions)
      {
          if (ext == e)
@@@ -334,7 -325,6 +326,6 @@@ bool PlaylistManager::moveItemUp (int i
          items[i - 1] = items[i];
          items[i] = tmp;
          return true;
- //        emit playlistChanged(i - 1);
      }
      return false;
  }
@@@ -347,7 -337,6 +338,6 @@@ bool PlaylistManager::moveItemDown (in
          items[i + 1] = items[i];
          items[i] = tmp;
          return true;
- //        emit playlistChanged(i - 1);
      }
      return false;
  }