Example #1
0
std::string Lyrics::GenerateFilename(const MPD::Song &s)
{
	std::string filename;
	if (Config.store_lyrics_in_song_dir)
	{
		if (s.isFromDB())
		{
			filename = Config.mpd_music_dir;
			filename += "/";
			filename += s.GetFile();
		}
		else
			filename = s.GetFile();
		// replace song's extension with .txt
		size_t dot = filename.rfind('.');
		assert(dot != std::string::npos);
		filename.resize(dot);
		filename += ".txt";
	}
	else
	{
		std::string file = locale_to_utf_cpy(s.GetArtist());
		file += " - ";
		file += locale_to_utf_cpy(s.GetTitle());
		file += ".txt";
		EscapeUnallowedChars(file);
		filename = Config.lyrics_directory;
		filename += "/";
		filename += file;
	}
	return filename;
}
  void Storage::loadNewSong(MPD::Song s) {
    // save current file
    currentArtist->saveArtist(filePath);

    if (Config::GetInstance()->isRemoteStorageEnabled()) {
      // save to shared storage
      if (remoteSaveArtist(filePath)) {
        currentArtist->setSynced(true);
      } else {
        currentArtist->setSynced(false);
      }

      // save with sync flags
      currentArtist->saveArtist(filePath);
    }

    // clear current Artist
    currentArtist->clear();

    // load new data to storage
    filePath = createArtistFilePath(s.GetArtist());


    currentArtist->name.set(s.GetArtist());
    currentArtist->album.set(s.GetAlbum());

    // check if file exists
    // search in local temp
    currentArtist->loadArtistFromFile(filePath);

    // if is enabled remote sharing, share
    if (Config::GetInstance()->isRemoteStorageEnabled()) {
      // remote load artist
      std::string remoteArtistContent = remoteLoadArtist(s.GetArtist());
      currentArtist->loadArtistFromRemoteContent(remoteArtistContent);
    }

    // classificate artist
    currentArtist->loadClassificator();

    currentArtist->classificateArtist();

    loadWidgets();
  }
void updatePlayer(MPD::Client *, MPD::StatusChanges changed, void *) {

  if (changed.SongID) {
    if (MPD::Client::GetInstance()->isPlaying()) {
#if DEBUG
      std::cout << "Song changed" << std::endl;
#endif

      MPD::Song song = MPD::Client::GetInstance()->GetCurrentSong();

      // set song parameters to storage
      Storage::GetInstance()->loadNewSong(song);

      // run agents
      AgentManager::GetInstance()->songChanged();

      // set text widgets
      GUI::MainWindow::GetInstance()->setSongLabel(song.GetArtist() + " - " + song.GetTitle());
      GUI::MainWindow::GetInstance()->setArtist(song.GetArtist());
      GUI::MainWindow::GetInstance()->setTitle(song.GetTitle());
      GUI::MainWindow::GetInstance()->setAlbum(song.GetAlbum());
      GUI::MainWindow::GetInstance()->setGenre(song.GetGenre());
      GUI::MainWindow::GetInstance()->setTimeScale(MPD::Client::GetInstance()->GetElapsedTime(), MPD::Client::GetInstance()->GetTotalTime());
    }
  }
  if (changed.ElapsedTime) {

    //    if (!Config::GetInstance()->isAgentsEnabled()) {
    //      AgentManager::GetInstance()->killAgents();
    //    }
    //
    //    AgentManager::GetInstance()->isSourcesChanged();

    // load new info to widgets
    GUI::MainWindow::GetInstance()->articlesWidget->updateArticlesWidget();
    GUI::MainWindow::GetInstance()->slideshowWidget->updateSlideshowWidget();
    //    GUI::MainWindow::GetInstance()->coverWidget->updateCoverWidget();


    GUI::MainWindow::GetInstance()->setTimeScale(MPD::Client::GetInstance()->GetElapsedTime(), MPD::Client::GetInstance()->GetTotalTime());

    if (MPD::Client::GetInstance()->isPlaying()) {
      MPD::Song song = MPD::Client::GetInstance()->GetCurrentSong();

      GUI::MainWindow::GetInstance()->setSongLabel(song.GetArtist() + " - " + song.GetTitle());

      GUI::MainWindow::GetInstance()->setStatusBar(_("IMPC Playing: ") + song.GetFile());
    }
  }
  if (changed.PlayerState) {

    MPD::PlayerState s = MPD::Client::GetInstance()->GetState();

    if (s == MPD::psPlay) {
      GUI::MainWindow::GetInstance()->on_play();
      GUI::MainWindow::GetInstance()->setPlayButtonActive(true);

      GUI::MainWindow::GetInstance()->setBitrate(MPD::Client::GetInstance()->GetBitrate());

    } else if (s == MPD::psPause) {
      GUI::MainWindow::GetInstance()->on_pause();
      GUI::MainWindow::GetInstance()->setPlayButtonActive(false);
    } else if (s == MPD::psStop) {
      GUI::MainWindow::GetInstance()->on_stop();
      GUI::MainWindow::GetInstance()->articlesWidget->clearArticlesWidget();
      GUI::MainWindow::GetInstance()->slideshowWidget->clearSlide();
    }
  }

  if (changed.DBUpdating) {
    GUI::MainWindow::GetInstance()->artistsWidget->reload();
  }

  if (changed.Volume) {
    // we set default volume
    GUI::MainWindow::GetInstance()->setVolume((double) MPD::Client::GetInstance()->GetVolume());
  }

  AgentManager::GetInstance()->checkIfAgentsEnabled();
}