00001
00002 #include <cstdlib>
00003
00004
00005 #include <iostream>
00006 using namespace std;
00007
00008
00009 #include <QApplication>
00010 #include <QLocale>
00011
00012
00013 #include <mythuitextedit.h>
00014 #include <mythuistatetype.h>
00015 #include <mythuiprogressbar.h>
00016 #include <mythuibutton.h>
00017 #include <mythuiimage.h>
00018 #include <mythdialogbox.h>
00019 #include <mythuibuttonlist.h>
00020 #include <mythuibuttontree.h>
00021 #include <mythuicheckbox.h>
00022 #include <mythuivideo.h>
00023 #include <audiooutput.h>
00024 #include <compat.h>
00025 #include <lcddevice.h>
00026
00027
00028 #include "metadata.h"
00029 #include "constants.h"
00030 #include "streaminput.h"
00031 #include "decoder.h"
00032 #include "mainvisual.h"
00033 #include "smartplaylist.h"
00034 #include "playlistcontainer.h"
00035 #include "search.h"
00036 #include "editmetadata.h"
00037 #include "playlist.h"
00038
00039 #include "musiccommon.h"
00040 #include "playlistview.h"
00041 #include "playlisteditorview.h"
00042 #include "visualizerview.h"
00043 #include "searchview.h"
00044
00045 MusicCommon::MusicCommon(MythScreenStack *parent, const QString &name)
00046 : MythScreenType(parent, name)
00047 {
00048 m_mainvisual = NULL;
00049 m_moveTrackMode = false;
00050 m_movingTrack = false;
00051 m_currentTime = 0;
00052 m_maxTime = 0;
00053
00054 #if 0
00055 cd_reader_thread = NULL;
00056 cd_watcher = NULL;
00057 scan_for_cd = gContext->GetNumSetting("AutoPlayCD", 0);
00058 m_CDdevice = dev;
00059 #endif
00060
00061 m_cycleVisualizer = gCoreContext->GetNumSetting("VisualCycleOnSongChange", 0);
00062
00063 if (LCD *lcd = LCD::Get())
00064 {
00065 lcd->switchToTime();
00066 lcd->setFunctionLEDs(FUNC_MUSIC, true);
00067 }
00068 }
00069
00070 MusicCommon::~MusicCommon(void)
00071 {
00072 gPlayer->removeListener(this);
00073
00074 if (m_mainvisual)
00075 {
00076 stopVisualizer();
00077 delete m_mainvisual;
00078 m_mainvisual = NULL;
00079 }
00080
00081 #if 0
00082 if (cd_reader_thread)
00083 {
00084 cd_watcher->stop();
00085 cd_reader_thread->wait();
00086 delete cd_reader_thread;
00087 }
00088
00089 if (class LCD *lcd = LCD::Get())
00090 lcd->switchToTime();
00091
00092 gMusicData->all_music->save();
00093 gPlayer->refreshMetadata();
00094 #endif
00095
00096 if (LCD *lcd = LCD::Get())
00097 {
00098 lcd->switchToTime();
00099 lcd->setFunctionLEDs(FUNC_MUSIC, false);
00100 }
00101 }
00102
00103 bool MusicCommon::CreateCommon(void)
00104 {
00105 bool err = false;
00106 UIUtilW::Assign(this, m_timeText, "time", &err);
00107 UIUtilW::Assign(this, m_infoText, "info", &err);
00108 UIUtilW::Assign(this, m_visualText, "visualizername", &err);
00109 UIUtilW::Assign(this, m_noTracksText, "notracks", &err);
00110
00111 UIUtilW::Assign(this, m_shuffleState, "shufflestate", &err);
00112 UIUtilW::Assign(this, m_repeatState, "repeatstate", &err);
00113 UIUtilW::Assign(this, m_movingTracksState, "movingtracksstate", &err);
00114
00115 UIUtilW::Assign(this, m_ratingState, "ratingstate", &err);
00116
00117 UIUtilW::Assign(this, m_trackProgress, "progress", &err);
00118 UIUtilW::Assign(this, m_trackProgressText, "trackprogress", &err);
00119 UIUtilW::Assign(this, m_trackSpeedText, "trackspeed", &err);
00120 UIUtilW::Assign(this, m_trackState, "trackstate", &err);
00121
00122 UIUtilW::Assign(this, m_volumeText, "volume", &err);
00123 UIUtilW::Assign(this, m_muteState, "mutestate", &err);
00124
00125 UIUtilW::Assign(this, m_playlistProgress, "playlistprogress", &err);
00126
00127 UIUtilW::Assign(this, m_prevButton, "prev", &err);
00128 UIUtilW::Assign(this, m_rewButton, "rew", &err);
00129 UIUtilW::Assign(this, m_pauseButton, "pause", &err);
00130 UIUtilW::Assign(this, m_playButton, "play", &err);
00131 UIUtilW::Assign(this, m_stopButton, "stop", &err);
00132 UIUtilW::Assign(this, m_ffButton, "ff", &err);
00133 UIUtilW::Assign(this, m_nextButton, "next", &err);
00134
00135 UIUtilW::Assign(this, m_coverartImage, "coverart", &err);
00136
00137 UIUtilW::Assign(this, m_currentPlaylist, "currentplaylist", &err);
00138 UIUtilW::Assign(this, m_playedTracksList, "playedtrackslist", &err);
00139
00140 UIUtilW::Assign(this, m_visualizerVideo, "visualizer", &err);
00141
00142 if (m_prevButton)
00143 connect(m_prevButton, SIGNAL(Clicked()), this, SLOT(previous()));
00144
00145 if (m_rewButton)
00146 connect(m_rewButton, SIGNAL(Clicked()), this, SLOT(seekback()));
00147
00148 if (m_pauseButton)
00149 {
00150 m_pauseButton->SetLockable(true);
00151 connect(m_pauseButton, SIGNAL(Clicked()), this, SLOT(pause()));
00152 }
00153
00154 if (m_playButton)
00155 {
00156 m_playButton->SetLockable(true);
00157 connect(m_playButton, SIGNAL(Clicked()), this, SLOT(play()));
00158 }
00159
00160 if (m_stopButton)
00161 {
00162 m_stopButton->SetLockable(true);
00163 connect(m_stopButton, SIGNAL(Clicked()), this, SLOT(stop()));
00164 }
00165
00166 if (m_ffButton)
00167 connect(m_ffButton, SIGNAL(Clicked()), this, SLOT(seekforward()));
00168
00169 if (m_nextButton)
00170 connect(m_nextButton, SIGNAL(Clicked()), this, SLOT(next()));
00171
00172 gPlayer->addListener(this);
00173
00174 if (!gPlayer->isPlaying())
00175 gPlayer->restorePosition();
00176
00177 m_currentTrack = gPlayer->getCurrentTrackPos();
00178
00179 Metadata *curMeta = gPlayer->getCurrentMetadata();
00180 if (curMeta)
00181 updateTrackInfo(curMeta);
00182
00183 updateProgressBar();
00184
00185 if (m_currentPlaylist)
00186 {
00187 connect(m_currentPlaylist, SIGNAL(itemClicked(MythUIButtonListItem*)),
00188 this, SLOT(playlistItemClicked(MythUIButtonListItem*)));
00189 connect(m_currentPlaylist, SIGNAL(itemVisible(MythUIButtonListItem*)),
00190 this, SLOT(playlistItemVisible(MythUIButtonListItem*)));
00191
00192 m_currentPlaylist->SetSearchFields("**search**");
00193
00194 updateUIPlaylist();
00195 }
00196
00197 if (m_visualizerVideo)
00198 {
00199
00200 m_mainvisual = new MainVisual(m_visualizerVideo);
00201 m_visualModes = m_mainvisual->getVisualizations();
00202
00203 m_fullscreenBlank = false;
00204
00205 m_randomVisualizer = gCoreContext->GetNumSetting("VisualRandomize", 0);
00206
00207 m_currentVisual = m_mainvisual->getCurrentVisual();
00208
00209
00210 if (m_currentVisual >= static_cast<uint>(m_visualModes.count()))
00211 {
00212 LOG(VB_GENERAL, LOG_ERR, QString("MusicCommon: Got a bad saved visualizer: %1").arg(m_currentVisual));
00213 m_currentVisual = 0;
00214 }
00215
00216 switchVisualizer(m_currentVisual);
00217
00218 if (gPlayer->isPlaying())
00219 startVisualizer();
00220 }
00221
00222 m_controlVolume = gCoreContext->GetNumSetting("MythControlsVolume", 0);
00223 updateVolume();
00224
00225 if (m_movingTracksState)
00226 m_movingTracksState->DisplayState("off");
00227
00228 if (m_stopButton)
00229 m_stopButton->SetLocked(gPlayer->isStopped());
00230 if (m_playButton)
00231 m_playButton->SetLocked(gPlayer->isPlaying());
00232 if (m_pauseButton)
00233 m_pauseButton->SetLocked(gPlayer->isPaused());
00234 if (m_trackState)
00235 {
00236 if (gPlayer->isPlaying())
00237 m_trackState->DisplayState("playing");
00238 else if (gPlayer->isPaused())
00239 m_trackState->DisplayState("paused");
00240 else
00241 m_trackState->DisplayState("stopped");
00242
00243 }
00244
00245 updateShuffleMode();
00246 updateRepeatMode();
00247
00248 gPlayer->getPlaylist()->getStats(&m_playlistTrackCount, &m_playlistMaxTime,
00249 m_currentTrack, &m_playlistPlayedTime);
00250
00251 if (m_playlistProgress)
00252 {
00253 m_playlistProgress->SetTotal(m_playlistMaxTime);
00254 m_playlistProgress->SetUsed(0);
00255 }
00256
00257 updatePlaylistStats();
00258
00259 return err;
00260 }
00261
00262 void MusicCommon::updateRepeatMode(void)
00263 {
00264 if (m_repeatState)
00265 {
00266 switch (gPlayer->getRepeatMode())
00267 {
00268 case MusicPlayer::REPEAT_OFF:
00269 m_repeatState->DisplayState("off");
00270 if (class LCD *lcd = LCD::Get())
00271 lcd->setMusicRepeat (LCD::MUSIC_REPEAT_NONE);
00272 break;
00273 case MusicPlayer::REPEAT_TRACK:
00274 m_repeatState->DisplayState("track");
00275 if (class LCD *lcd = LCD::Get())
00276 lcd->setMusicRepeat (LCD::MUSIC_REPEAT_TRACK);
00277 break;
00278 case MusicPlayer::REPEAT_ALL:
00279 m_repeatState->DisplayState("all");
00280 if (class LCD *lcd = LCD::Get())
00281 lcd->setMusicRepeat (LCD::MUSIC_REPEAT_ALL);
00282 break;
00283 default:
00284 m_repeatState->DisplayState("off");
00285 if (class LCD *lcd = LCD::Get())
00286 lcd->setMusicRepeat (LCD::MUSIC_REPEAT_NONE);
00287 break;
00288 }
00289 }
00290
00291
00292 Metadata *curMeta = gPlayer->getCurrentMetadata();
00293 if (curMeta)
00294 updateTrackInfo(curMeta);
00295 }
00296
00297 void MusicCommon::updateShuffleMode(bool updateUIList)
00298 {
00299 if (m_shuffleState)
00300 {
00301 switch (gPlayer->getShuffleMode())
00302 {
00303 case MusicPlayer::SHUFFLE_OFF:
00304 m_shuffleState->DisplayState("off");
00305 if (class LCD *lcd = LCD::Get())
00306 lcd->setMusicShuffle(LCD::MUSIC_SHUFFLE_NONE);
00307 break;
00308 case MusicPlayer::SHUFFLE_RANDOM:
00309 m_shuffleState->DisplayState("random");
00310 if (class LCD *lcd = LCD::Get())
00311 lcd->setMusicShuffle(LCD::MUSIC_SHUFFLE_RAND);
00312 break;
00313 case MusicPlayer::SHUFFLE_INTELLIGENT:
00314 m_shuffleState->DisplayState("intelligent");
00315 if (class LCD *lcd = LCD::Get())
00316 lcd->setMusicShuffle(LCD::MUSIC_SHUFFLE_SMART);
00317 break;
00318 case MusicPlayer::SHUFFLE_ALBUM:
00319 m_shuffleState->DisplayState("album");
00320 if (class LCD *lcd = LCD::Get())
00321 lcd->setMusicShuffle(LCD::MUSIC_SHUFFLE_ALBUM);
00322 break;
00323 case MusicPlayer::SHUFFLE_ARTIST:
00324 m_shuffleState->DisplayState("artist");
00325 if (class LCD *lcd = LCD::Get())
00326 lcd->setMusicShuffle(LCD::MUSIC_SHUFFLE_ARTIST);
00327 break;
00328 default:
00329 m_shuffleState->DisplayState("off");
00330 if (class LCD *lcd = LCD::Get())
00331 lcd->setMusicShuffle(LCD::MUSIC_SHUFFLE_NONE);
00332 break;
00333 }
00334 }
00335
00336 if (updateUIList)
00337 {
00338
00339 int curTrackID = -1;
00340 if (gPlayer->getCurrentMetadata())
00341 curTrackID = gPlayer->getCurrentMetadata()->ID();
00342
00343 updateUIPlaylist();
00344
00345 if (!restorePosition(curTrackID))
00346 playFirstTrack();
00347
00348
00349 Metadata *curMeta = gPlayer->getCurrentMetadata();
00350 if (curMeta)
00351 updateTrackInfo(curMeta);
00352 }
00353 }
00354
00355 void MusicCommon::switchView(MusicView view)
00356 {
00357 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00358
00359 stopVisualizer();
00360
00361 if (m_mainvisual)
00362 {
00363 delete m_mainvisual;
00364 m_mainvisual = NULL;
00365 }
00366
00367 gPlayer->removeListener(this);
00368 gPlayer->setAllowRestorePos(false);
00369
00370 switch (view)
00371 {
00372 case MV_PLAYLIST:
00373 {
00374 PlaylistView *view = new PlaylistView(mainStack);
00375
00376 if (view->Create())
00377 mainStack->AddScreen(view);
00378 else
00379 delete view;
00380
00381 break;
00382 }
00383
00384 case MV_PLAYLISTEDITORTREE:
00385 {
00386
00387
00388 bool restorePos = (m_currentView == MV_PLAYLISTEDITORGALLERY);
00389 PlaylistEditorView *oldView = dynamic_cast<PlaylistEditorView *>(this);
00390 if (oldView)
00391 oldView->saveTreePosition();
00392
00393 PlaylistEditorView *view = new PlaylistEditorView(mainStack, "tree", restorePos);
00394
00395 if (view->Create())
00396 mainStack->AddScreen(view);
00397 else
00398 delete view;
00399
00400 break;
00401 }
00402
00403 case MV_PLAYLISTEDITORGALLERY:
00404 {
00405
00406
00407 bool restorePos = (m_currentView == MV_PLAYLISTEDITORTREE);
00408 PlaylistEditorView *oldView = dynamic_cast<PlaylistEditorView *>(this);
00409 if (oldView)
00410 oldView->saveTreePosition();
00411
00412 PlaylistEditorView *view = new PlaylistEditorView(mainStack, "gallery", restorePos);
00413
00414 if (view->Create())
00415 mainStack->AddScreen(view);
00416 else
00417 delete view;
00418
00419 break;
00420 }
00421
00422 case MV_SEARCH:
00423 {
00424 SearchView *view = new SearchView(mainStack);
00425
00426 if (view->Create())
00427 mainStack->AddScreen(view);
00428 else
00429 delete view;
00430
00431 break;
00432 }
00433
00434 case MV_VISUALIZER:
00435 {
00436 VisualizerView *view = new VisualizerView(mainStack);
00437
00438 if (view->Create())
00439 mainStack->AddScreen(view);
00440 else
00441 delete view;
00442
00443 break;
00444 }
00445
00446 default:
00447 return;
00448 }
00449
00450 Close();
00451
00452 gPlayer->setAllowRestorePos(true);
00453 }
00454
00455 #if 0
00456 bool MusicCommon::onMediaEvent(MythMediaDevice*)
00457 {
00458 return scan_for_cd;
00459 }
00460 #endif
00461
00462 bool MusicCommon::keyPressEvent(QKeyEvent *e)
00463 {
00464 bool handled = false;
00465
00466 QStringList actions;
00467 handled = GetMythMainWindow()->TranslateKeyPress("Music", e, actions, true);
00468
00469 for (int i = 0; i < actions.size() && !handled; i++)
00470 {
00471 QString action = actions[i];
00472 handled = true;
00473
00474
00475
00476 if (m_moveTrackMode && m_movingTrack)
00477 {
00478 MythUIButtonListItem *item = m_currentPlaylist->GetItemCurrent();
00479 if (!item)
00480 return false;
00481
00482 if (action == "SELECT" || action == "ESCAPE")
00483 {
00484 m_movingTrack = false;
00485 item->DisplayState("off", "movestate");
00486 }
00487 else if (action == "UP")
00488 {
00489 gPlayer->moveTrackUpDown(true, m_currentPlaylist->GetCurrentPos());
00490 item->MoveUpDown(true);
00491 m_currentTrack = gPlayer->getCurrentTrackPos();
00492 gPlayer->getPlaylist()->getStats(&m_playlistTrackCount, &m_playlistMaxTime,
00493 m_currentTrack, &m_playlistPlayedTime);
00494 updatePlaylistStats();
00495 updateTrackInfo(gPlayer->getCurrentMetadata());
00496 }
00497 else if (action == "DOWN")
00498 {
00499 gPlayer->moveTrackUpDown(false, m_currentPlaylist->GetCurrentPos());
00500 item->MoveUpDown(false);
00501 m_currentTrack = gPlayer->getCurrentTrackPos();
00502 gPlayer->getPlaylist()->getStats(&m_playlistTrackCount, &m_playlistMaxTime,
00503 m_currentTrack, &m_playlistPlayedTime);
00504 updatePlaylistStats();
00505 updateTrackInfo(gPlayer->getCurrentMetadata());
00506 }
00507
00508 return true;
00509 }
00510
00511 if (action == "ESCAPE")
00512 {
00513 QString exit_action = gCoreContext->GetSetting("MusicExitAction", "prompt");
00514
00515 if (!gPlayer->isPlaying() || GetMythMainWindow()->IsExitingToMain())
00516 {
00517 gPlayer->savePosition();
00518 stopAll();
00519 Close();
00520 }
00521 else
00522 {
00523 if (exit_action == "stop")
00524 {
00525 gPlayer->savePosition();
00526 stopAll();
00527 Close();
00528 }
00529 else if (exit_action == "play")
00530 Close();
00531 else
00532 showExitMenu();
00533 }
00534 }
00535 else if (action == "THMBUP")
00536 changeRating(true);
00537 else if (action == "THMBDOWN")
00538 changeRating(false);
00539 else if (action == "NEXTTRACK")
00540 {
00541 if (m_nextButton)
00542 m_nextButton->Push();
00543 else
00544 next();
00545 }
00546 else if (action == "PREVTRACK")
00547 {
00548 if (m_prevButton)
00549 m_prevButton->Push();
00550 else
00551 previous();
00552 }
00553 else if (action == "FFWD")
00554 {
00555 if (m_ffButton)
00556 m_ffButton->Push();
00557 else
00558 seekforward();
00559 }
00560 else if (action == "RWND")
00561 {
00562 if (m_rewButton)
00563 m_rewButton->Push();
00564 else
00565 seekback();
00566 }
00567 else if (action == "PAUSE")
00568 {
00569
00570 if (gPlayer->isPlaying() || (gPlayer->getOutput() && gPlayer->getOutput()->IsPaused()))
00571 {
00572 if (m_pauseButton)
00573 m_pauseButton->Push();
00574 else
00575 pause();
00576 }
00577 else
00578 {
00579
00580 if (m_playButton)
00581 m_playButton->Push();
00582 else
00583 play();
00584 }
00585 }
00586 else if (action == "PLAY")
00587 {
00588 if (m_playButton)
00589 m_playButton->Push();
00590 else
00591 play();
00592 }
00593 else if (action == "STOP")
00594 {
00595 if (m_stopButton)
00596 m_stopButton->Push();
00597 else
00598 stop();
00599 m_currentTime = 0;
00600 }
00601 else if (action == "CYCLEVIS")
00602 cycleVisualizer();
00603 else if (action == "BLANKSCR")
00604 {
00605
00606 if (m_mainvisual)
00607 switchVisualizer("Blank");
00608
00609
00610 if (m_currentView != MV_VISUALIZER)
00611 switchView(MV_VISUALIZER);
00612 }
00613 else if (action == "VOLUMEDOWN")
00614 changeVolume(false);
00615 else if (action == "VOLUMEUP")
00616 changeVolume(true);
00617 else if (action == "SPEEDDOWN")
00618 changeSpeed(false);
00619 else if (action == "SPEEDUP")
00620 changeSpeed(true);
00621 else if (action == "MUTE")
00622 toggleMute();
00623 else if (action == "TOGGLEUPMIX")
00624 toggleUpmix();
00625 else if (action == "INFO" || action == "EDIT")
00626 {
00627 if (m_currentPlaylist && GetFocusWidget() == m_currentPlaylist)
00628 {
00629 if (m_currentPlaylist->GetItemCurrent())
00630 {
00631 Metadata *mdata = qVariantValue<Metadata*> (m_currentPlaylist->GetItemCurrent()->GetData());
00632 if (mdata)
00633 {
00634 if (action == "INFO")
00635 showTrackInfo(mdata);
00636 else
00637 editTrackInfo(mdata);
00638 }
00639 }
00640 }
00641 else
00642 {
00643 if (action == "INFO")
00644 showTrackInfo(gPlayer->getCurrentMetadata());
00645 else
00646 editTrackInfo(gPlayer->getCurrentMetadata());
00647 }
00648 }
00649 else if (action == "DELETE" && m_currentPlaylist && GetFocusWidget() == m_currentPlaylist)
00650 {
00651 MythUIButtonListItem *item = m_currentPlaylist->GetItemCurrent();
00652 if (item)
00653 {
00654 Metadata *mdata = qVariantValue<Metadata*> (item->GetData());
00655 if (mdata)
00656 gPlayer->removeTrack(mdata->ID());
00657 }
00658 }
00659 else if (action == "MENU")
00660 ShowMenu();
00661 else if (action == "REFRESH")
00662 {
00663 if (m_currentPlaylist)
00664 m_currentPlaylist->SetItemCurrent(m_currentTrack);
00665 }
00666 else if (action == "MARK")
00667 {
00668 if (!m_moveTrackMode)
00669 {
00670 m_moveTrackMode = true;
00671 m_movingTrack = false;
00672
00673 if (m_movingTracksState)
00674 m_movingTracksState->DisplayState((m_moveTrackMode ? "on" : "off"));
00675 }
00676 else
00677 {
00678 m_moveTrackMode = false;
00679
00680 if (m_currentPlaylist && m_movingTrack)
00681 {
00682 MythUIButtonListItem *item = m_currentPlaylist->GetItemCurrent();
00683 if (item)
00684 item->DisplayState("off", "movestate");
00685
00686 m_movingTrack = false;
00687 }
00688
00689 if (m_movingTracksState)
00690 m_movingTracksState->DisplayState((m_moveTrackMode ? "on" : "off"));
00691 }
00692 }
00693 else if (action == "SWITCHTOPLAYLIST" && m_currentView != MV_PLAYLIST)
00694 switchView(MV_PLAYLIST);
00695 else if (action == "SWITCHTOPLAYLISTEDITORTREE" && m_currentView != MV_PLAYLISTEDITORTREE)
00696 switchView(MV_PLAYLISTEDITORTREE);
00697 else if (action == "SWITCHTOPLAYLISTEDITORGALLERY" && m_currentView != MV_PLAYLISTEDITORGALLERY)
00698 switchView(MV_PLAYLISTEDITORGALLERY);
00699 else if (action == "SWITCHTOSEARCH" && m_currentView != MV_SEARCH)
00700 switchView(MV_SEARCH);
00701 else if (action == "SWITCHTOVISUALISER" && m_currentView != MV_VISUALIZER)
00702 switchView(MV_VISUALIZER);
00703 else if (action == "TOGGLESHUFFLE")
00704 {
00705 gPlayer->toggleShuffleMode();
00706 updateShuffleMode(true);
00707 }
00708 else if (action == "TOGGLEREPEAT")
00709 {
00710 gPlayer->toggleRepeatMode();
00711 updateRepeatMode();
00712 }
00713 else
00714 handled = false;
00715 }
00716
00717 return handled;
00718 }
00719
00720 void MusicCommon::changeVolume(bool up)
00721 {
00722 if (m_controlVolume && gPlayer->getOutput())
00723 {
00724 if (up)
00725 gPlayer->incVolume();
00726 else
00727 gPlayer->decVolume();
00728 showVolume();
00729 }
00730 }
00731
00732 void MusicCommon::changeSpeed(bool up)
00733 {
00734 if (gPlayer->getOutput())
00735 {
00736 if (up)
00737 gPlayer->incSpeed();
00738 else
00739 gPlayer->decSpeed();
00740 showSpeed(true);
00741 }
00742 }
00743
00744 void MusicCommon::toggleMute()
00745 {
00746 if (m_controlVolume)
00747 {
00748 gPlayer->toggleMute();
00749 showVolume();
00750 }
00751 }
00752
00753 void MusicCommon::toggleUpmix()
00754 {
00755 if (gPlayer->getOutput())
00756 gPlayer->getOutput()->ToggleUpmix();
00757 }
00758
00759 void MusicCommon::updateProgressBar()
00760 {
00761 if (m_trackProgress)
00762 {
00763 int percentplayed = 1;
00764 if (m_maxTime)
00765 percentplayed = (int)(((double)m_currentTime / (double)m_maxTime)*100);
00766 m_trackProgress->SetTotal(100);
00767 m_trackProgress->SetUsed(percentplayed);
00768 }
00769 }
00770
00771 void MusicCommon::showVolume(void)
00772 {
00773 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
00774
00775 MythMusicVolumeDialog *vol = new MythMusicVolumeDialog(popupStack, "volumepopup");
00776
00777 if (!vol->Create())
00778 {
00779 delete vol;
00780 return;
00781 }
00782
00783 popupStack->AddScreen(vol);
00784 }
00785
00786 void MusicCommon::showSpeed(bool show)
00787 {
00788 (void) show;
00789 #if 0
00790 if (speed_status)
00791 {
00792 if (volume_status && (volume_status->getOrder() != -1))
00793 {
00794 volume_status->SetOrder(-1);
00795 volume_status->refresh();
00796 }
00797
00798 if (show)
00799 {
00800 QString speed_text;
00801 float playSpeed = gPlayer->getSpeed();
00802 speed_text.sprintf("x%4.2f",playSpeed);
00803 speed_status->SetText(speed_text);
00804 speed_status->SetOrder(0);
00805 speed_status->refresh();
00806 volume_display_timer->setSingleShot(true);
00807 volume_display_timer->start(2000);
00808 }
00809 }
00810
00811 if (LCD *lcd = LCD::Get())
00812 {
00813 QString speed_text;
00814 float playSpeed = gPlayer->getSpeed();
00815 speed_text.sprintf("x%4.2f", playSpeed);
00816 speed_text = tr("Speed: ") + speed_text;
00817 QList<LCDTextItem> textItems;
00818 textItems.append(LCDTextItem(lcd->getLCDHeight() / 2, ALIGN_CENTERED,
00819 speed_text, "Generic", false));
00820 lcd->switchToGeneric(textItems);
00821 }
00822 #endif
00823 }
00824
00825 void MusicCommon::switchVisualizer(const QString &visual)
00826 {
00827 switchVisualizer(m_visualModes.indexOf(visual));
00828 }
00829
00830 void MusicCommon::switchVisualizer(int visual)
00831 {
00832 if (!m_mainvisual)
00833 return;
00834
00835 if (visual < 0 || visual > m_visualModes.count() - 1)
00836 visual = 0;
00837
00838 m_currentVisual = visual;
00839
00840 m_mainvisual->setVisual(m_visualModes[m_currentVisual]);
00841
00842 if (m_visualText)
00843 m_visualText->SetText(m_visualModes[m_currentVisual]);
00844 }
00845
00846 void MusicCommon::cycleVisualizer(void)
00847 {
00848 if (!m_mainvisual)
00849 return;
00850
00851
00852
00853 if (m_visualModes.count() > 1)
00854 {
00855 if (m_randomVisualizer)
00856 {
00857 unsigned int next_visualizer;
00858
00859
00860 do
00861 next_visualizer = random() % m_visualModes.count();
00862 while (next_visualizer == m_currentVisual);
00863 m_currentVisual = next_visualizer;
00864 }
00865 else
00866 {
00867
00868 m_currentVisual = (m_currentVisual + 1) % m_visualModes.count();
00869 }
00870
00871
00872 switchVisualizer(m_currentVisual);
00873 }
00874 }
00875
00876 void MusicCommon::startVisualizer(void)
00877 {
00878 if (!m_visualizerVideo || !m_mainvisual)
00879 return;
00880
00881 gPlayer->addVisual(m_mainvisual);
00882 }
00883
00884 void MusicCommon::stopVisualizer(void )
00885 {
00886 if (!m_visualizerVideo || !m_mainvisual)
00887 return;
00888
00889 gPlayer->removeVisual(m_mainvisual);
00890 }
00891
00892 void MusicCommon::setTrackOnLCD(Metadata *mdata)
00893 {
00894 LCD *lcd = LCD::Get();
00895 if (!lcd || !mdata)
00896 return;
00897
00898
00899 lcd->switchToMusic(mdata->Artist(),
00900 mdata->Album(),
00901 mdata->Title());
00902 }
00903
00904 void MusicCommon::stopAll()
00905 {
00906 if (LCD *lcd = LCD::Get())
00907 {
00908 lcd->switchToTime();
00909 }
00910
00911 stopVisualizer();
00912
00913 gPlayer->stop(true);
00914 }
00915
00916 void MusicCommon::play()
00917 {
00918 gPlayer->play();
00919 }
00920
00921 void MusicCommon::pause(void)
00922 {
00923 gPlayer->pause();
00924 }
00925
00926 void MusicCommon::stop(void)
00927 {
00928 gPlayer->stop();
00929
00930 QString time_string = getTimeString(m_maxTime, 0);
00931
00932 if (m_timeText)
00933 m_timeText->SetText(time_string);
00934 if (m_infoText)
00935 m_infoText->Reset();
00936 }
00937
00938 void MusicCommon::next()
00939 {
00940 if (m_cycleVisualizer)
00941 cycleVisualizer();
00942
00943
00944 gPlayer->next();
00945 }
00946
00947 void MusicCommon::previous()
00948 {
00949 if (m_cycleVisualizer)
00950 cycleVisualizer();
00951
00952 gPlayer->previous();
00953 }
00954
00955 void MusicCommon::seekforward()
00956 {
00957 int nextTime = m_currentTime + 5;
00958 if (nextTime > m_maxTime)
00959 nextTime = m_maxTime;
00960 seek(nextTime);
00961 }
00962
00963 void MusicCommon::seekback()
00964 {
00965 int nextTime = m_currentTime - 5;
00966 if (nextTime < 0)
00967 nextTime = 0;
00968 seek(nextTime);
00969 }
00970
00971 void MusicCommon::seek(int pos)
00972 {
00973 if (gPlayer->getOutput())
00974 {
00975 if (gPlayer->getDecoder() && gPlayer->getDecoder()->isRunning())
00976 {
00977 gPlayer->getDecoder()->lock();
00978 gPlayer->getDecoder()->seek(pos);
00979
00980 if (m_mainvisual)
00981 {
00982 m_mainvisual->mutex()->lock();
00983 m_mainvisual->prepare();
00984 m_mainvisual->mutex()->unlock();
00985 }
00986
00987 gPlayer->getDecoder()->unlock();
00988 }
00989
00990 gPlayer->getOutput()->SetTimecode(pos*1000);
00991
00992 if (!gPlayer->isPlaying())
00993 {
00994 m_currentTime = pos;
00995 if (m_timeText)
00996 m_timeText->SetText(getTimeString(pos, m_maxTime));
00997
00998 updateProgressBar();
00999
01000 if (LCD *lcd = LCD::Get())
01001 {
01002 float percent_heard = m_maxTime <= 0 ? 0.0 : ((float)pos /
01003 (float)m_maxTime);
01004
01005 QString lcd_time_string = getTimeString(pos, m_maxTime);
01006
01007
01008 if (lcd_time_string.length() > (int)lcd->getLCDWidth())
01009 lcd_time_string.remove(' ');
01010
01011 lcd->setMusicProgress(lcd_time_string, percent_heard);
01012 }
01013 }
01014 }
01015 }
01016
01017 void MusicCommon::changeRating(bool increase)
01018 {
01019
01020
01021
01022
01023
01024
01025 Metadata *curMeta = gPlayer->getCurrentMetadata();
01026 if (!curMeta)
01027 return;
01028
01029
01030 if (increase)
01031 curMeta->incRating();
01032 else
01033 curMeta->decRating();
01034
01035 gPlayer->sendTrackStatsChangedEvent(curMeta->ID());
01036 }
01037
01038 void MusicCommon::customEvent(QEvent *event)
01039 {
01040 QString statusString;
01041
01042 if (event->type() == OutputEvent::Playing)
01043 {
01044 Metadata *curMeta = gPlayer->getCurrentMetadata();
01045 if (curMeta)
01046 updateTrackInfo(curMeta);
01047
01048 statusString = tr("Playing stream.");
01049 if (gPlayer->isPlaying())
01050 {
01051 if (m_stopButton)
01052 m_stopButton->SetLocked(false);
01053 if (m_playButton)
01054 m_playButton->SetLocked(true);
01055 if (m_pauseButton)
01056 m_pauseButton->SetLocked(false);
01057 if (m_trackState)
01058 m_trackState->DisplayState("playing");
01059
01060 if (m_currentPlaylist)
01061 {
01062 MythUIButtonListItem *item = m_currentPlaylist->GetItemAt(m_currentTrack);
01063 if (item)
01064 {
01065 item->SetFontState("running");
01066 item->DisplayState("playing", "playstate");
01067 }
01068 }
01069
01070 startVisualizer();
01071
01072 updateVolume();
01073 }
01074 }
01075 else if (event->type() == OutputEvent::Buffering)
01076 {
01077 statusString = tr("Buffering stream.");
01078 }
01079 else if (event->type() == OutputEvent::Paused)
01080 {
01081 statusString = tr("Stream paused.");
01082
01083 if (m_stopButton)
01084 m_stopButton->SetLocked(false);
01085 if (m_playButton)
01086 m_playButton->SetLocked(false);
01087 if (m_pauseButton)
01088 m_pauseButton->SetLocked(true);
01089 if (m_trackState)
01090 m_trackState->DisplayState("paused");
01091
01092 if (m_currentPlaylist)
01093 {
01094 MythUIButtonListItem *item = m_currentPlaylist->GetItemAt(m_currentTrack);
01095 if (item)
01096 {
01097 item->SetFontState("idle");
01098 item->DisplayState("paused", "playstate");
01099 }
01100 }
01101 }
01102 else if (event->type() == OutputEvent::Info)
01103 {
01104
01105 OutputEvent *oe = dynamic_cast<OutputEvent *>(event);
01106
01107 if (!oe)
01108 return;
01109
01110 int rs;
01111 m_currentTime = rs = oe->elapsedSeconds();
01112
01113 QString time_string = getTimeString(rs, m_maxTime);
01114
01115 updateProgressBar();
01116
01117 Metadata *curMeta = gPlayer->getCurrentMetadata();
01118 if (curMeta)
01119 {
01120 if (LCD *lcd = LCD::Get())
01121 {
01122 float percent_heard = m_maxTime <= 0 ?
01123 0.0:((float)rs / (float)curMeta->Length()) * 1000.0;
01124
01125 QString lcd_time_string = time_string;
01126
01127
01128 if (time_string.length() > (int)lcd->getLCDWidth())
01129 lcd_time_string.remove(' ');
01130
01131 lcd->setMusicProgress(lcd_time_string, percent_heard);
01132 }
01133 }
01134
01135 QString info_string;
01136
01137
01138 if (oe->bitrate() < 2000)
01139 {
01140 info_string.sprintf(QString("%d "+tr("kbps")+ " %.1f "+ tr("kHz")+ " %s "+ tr("ch")).toUtf8().data(),
01141 oe->bitrate(), float(oe->frequency()) / 1000.0,
01142 oe->channels() > 1 ? "2" : "1");
01143 }
01144 else
01145 {
01146 info_string.sprintf(QString("%.1f "+ tr("kHz")+ " %s "+ tr("ch")).toUtf8().data(),
01147 float(oe->frequency()) / 1000.0,
01148 oe->channels() > 1 ? "2" : "1");
01149 }
01150
01151 if (curMeta )
01152 {
01153 if (m_timeText)
01154 m_timeText->SetText(time_string);
01155 if (m_infoText)
01156 m_infoText->SetText(info_string);
01157 }
01158
01159
01160 updatePlaylistStats();
01161 }
01162 else if (event->type() == OutputEvent::Error)
01163 {
01164 OutputEvent *aoe = dynamic_cast<OutputEvent *>(event);
01165
01166 if (!aoe)
01167 return;
01168
01169 statusString = tr("Output error.");
01170
01171 LOG(VB_GENERAL, LOG_ERR, QString("%1 %2").arg(statusString)
01172 .arg(*aoe->errorMessage()));
01173 ShowOkPopup(QString(tr("MythMusic has encountered the following error:\n%1"))
01174 .arg(*aoe->errorMessage()));
01175 stopAll();
01176 }
01177 else if (event->type() == OutputEvent::Stopped)
01178 {
01179 statusString = tr("Stream stopped.");
01180 if (m_stopButton)
01181 m_stopButton->SetLocked(true);
01182 if (m_playButton)
01183 m_playButton->SetLocked(false);
01184 if (m_pauseButton)
01185 m_pauseButton->SetLocked(false);
01186 if (m_trackState)
01187 m_trackState->DisplayState("stopped");
01188
01189 if (m_currentPlaylist)
01190 {
01191 MythUIButtonListItem *item = m_currentPlaylist->GetItemAt(m_currentTrack);
01192 if (item)
01193 {
01194 item->SetFontState("normal");
01195 item->DisplayState("stopped", "playstate");
01196 }
01197 }
01198
01199 stopVisualizer();
01200 }
01201 else if (event->type() == DecoderEvent::Error)
01202 {
01203 stopAll();
01204
01205 statusString = tr("Decoder error.");
01206
01207 DecoderEvent *dxe = dynamic_cast<DecoderEvent *>(event);
01208
01209 if (!dxe)
01210 return;
01211
01212 LOG(VB_GENERAL, LOG_ERR, QString("%1 %2").arg(statusString)
01213 .arg(*dxe->errorMessage()));
01214
01215 ShowOkPopup(QString(tr("MythMusic has encountered the following error:\n%1"))
01216 .arg(*dxe->errorMessage()));
01217 }
01218 else if (event->type() == DialogCompletionEvent::kEventType)
01219 {
01220 DialogCompletionEvent *dce = static_cast<DialogCompletionEvent*>(event);
01221
01222
01223 if (dce->GetResult() < 0)
01224 return;
01225
01226 QString resultid = dce->GetId();
01227 QString resulttext = dce->GetResultText();
01228 if (resultid == "viewmenu")
01229 {
01230 if (dce->GetResult() >= 0)
01231 {
01232 MusicView view = (MusicView)dce->GetData().toInt();
01233 switchView(view);
01234 }
01235 }
01236 else if (resultid == "actionmenu")
01237 {
01238 if (resulttext == tr("Search List..."))
01239 {
01240 searchButtonList();
01241 }
01242 }
01243 else if (resultid == "playlistmenu")
01244 {
01245 if (resulttext == tr("Sync List With Current Track"))
01246 {
01247 m_currentPlaylist->SetItemCurrent(m_currentTrack);
01248 }
01249 else if (resulttext == tr("Remove Selected Track"))
01250 {
01251 MythUIButtonListItem *item = m_currentPlaylist->GetItemCurrent();
01252 if (item)
01253 {
01254 Metadata *mdata = qVariantValue<Metadata*> (item->GetData());
01255 if (mdata)
01256 gPlayer->removeTrack(mdata->ID());
01257 }
01258 }
01259 else if (resulttext == tr("Remove All Tracks"))
01260 {
01261 gPlayer->getPlaylist()->removeAllTracks();
01262 gPlayer->activePlaylistChanged(-1, true);
01263 }
01264 else if (resulttext == tr("Save To New Playlist"))
01265 {
01266 QString message = tr("Enter new playlist name");
01267
01268 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
01269
01270 MythTextInputDialog *inputdialog = new MythTextInputDialog(popupStack, message);
01271
01272 if (inputdialog->Create())
01273 {
01274 inputdialog->SetReturnEvent(this, "addplaylist");
01275 popupStack->AddScreen(inputdialog);
01276 }
01277 else
01278 delete inputdialog;
01279 }
01280 else if (resulttext == tr("Save To Existing Playlist"))
01281 {
01282 QString message = tr("Select the playlist to save to");
01283 QStringList playlists = gMusicData->all_playlists->getPlaylistNames();
01284
01285 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
01286
01287 MythUISearchDialog *searchdialog = new MythUISearchDialog(popupStack, message, playlists);
01288
01289 if (searchdialog->Create())
01290 {
01291 searchdialog->SetReturnEvent(this, "updateplaylist");
01292 popupStack->AddScreen(searchdialog);
01293 }
01294 }
01295 else if (resulttext == tr("Switch To Move Mode"))
01296 {
01297 m_moveTrackMode = true;
01298 m_movingTrack = false;
01299
01300 if (m_movingTracksState)
01301 m_movingTracksState->DisplayState((m_moveTrackMode ? "on" : "off"));
01302 }
01303 else if (resulttext == tr("Switch To Select Mode"))
01304 {
01305 m_moveTrackMode = false;
01306
01307 if (m_currentPlaylist && m_movingTrack)
01308 {
01309 MythUIButtonListItem *item = m_currentPlaylist->GetItemCurrent();
01310 if (item)
01311 item->DisplayState("off", "movestate");
01312
01313 m_movingTrack = false;
01314 }
01315
01316 if (m_movingTracksState)
01317 m_movingTracksState->DisplayState((m_moveTrackMode ? "on" : "off"));
01318 }
01319 }
01320 else if (resultid == "repeatmenu")
01321 {
01322 int mode = dce->GetData().toInt();
01323 gPlayer->setRepeatMode((MusicPlayer::RepeatMode) mode);
01324 updateRepeatMode();
01325 }
01326 else if (resultid == "shufflemenu")
01327 {
01328 int mode = dce->GetData().toInt();
01329 gPlayer->setShuffleMode((MusicPlayer::ShuffleMode) mode);
01330 updateShuffleMode(true);
01331 }
01332 else if (resultid == "exitmenu")
01333 {
01334 if (resulttext == tr("No - Exit, Stop Playing"))
01335 {
01336 gPlayer->savePosition();
01337 stopAll();
01338 Close();
01339 }
01340 else if (resulttext == tr("Yes - Exit, Continue Playing"))
01341 {
01342 Close();
01343 }
01344 }
01345 else if (resultid == "playermenu")
01346 {
01347 if (resulttext == tr("Change Volume"))
01348 showVolume();
01349 else if (resulttext == tr("Mute"))
01350 toggleMute();
01351 else if (resulttext == tr("Previous Track"))
01352 previous();
01353 else if (resulttext == tr("Next Track"))
01354 next();
01355 else if (resulttext == tr("Jump Back"))
01356 seekback();
01357 else if (resulttext == tr("Jump Forward"))
01358 seekforward();
01359 else if (resulttext == tr("Play"))
01360 play();
01361 else if (resulttext == tr("Stop"))
01362 stop();
01363 else if (resulttext == tr("Pause"))
01364 pause();
01365 }
01366 else if (resultid == "quickplaylistmenu")
01367 {
01368 if (resulttext == tr("All Tracks"))
01369 allTracks();
01370 else if (resulttext == tr("From CD"))
01371 fromCD();
01372 else if (resulttext == tr("Tracks By Current Artist"))
01373 byArtist();
01374 else if (resulttext == tr("Tracks From Current Genre"))
01375 byGenre();
01376 else if (resulttext == tr("Tracks From Current Album"))
01377 byAlbum();
01378 else if (resulttext == tr("Tracks From Current Year"))
01379 byYear();
01380 else if (resulttext == tr("Tracks With Same Title"))
01381 byTitle();
01382 }
01383 else if (resultid == "playlistoptionsmenu")
01384 {
01385 if (resulttext == tr("Replace Tracks"))
01386 {
01387 m_playlistOptions.insertPLOption = PL_REPLACE;
01388 doUpdatePlaylist();
01389 }
01390 else if (resulttext == tr("Add Tracks"))
01391 {
01392 m_playlistOptions.insertPLOption = PL_INSERTATEND;
01393 doUpdatePlaylist();
01394 }
01395 }
01396 else if (resultid == "visualizermenu")
01397 {
01398 if (dce->GetResult() >= 0)
01399 {
01400 m_currentVisual = dce->GetData().toInt();
01401
01402
01403 switchVisualizer(m_currentVisual);
01404 }
01405 }
01406 else if (resultid == "addplaylist")
01407 {
01408 gMusicData->all_playlists->copyNewPlaylist(resulttext);
01409 Playlist *playlist = gMusicData->all_playlists->getPlaylist(resulttext);
01410 gPlayer->playlistChanged(playlist->getID());
01411 }
01412 else if (resultid == "updateplaylist")
01413 {
01414 Playlist *playlist = gMusicData->all_playlists->getPlaylist(resulttext);
01415 QString songList = gPlayer->getPlaylist()->toRawSonglist();
01416 playlist->removeAllTracks();
01417 playlist->fillSongsFromSonglist(songList);
01418 gPlayer->playlistChanged(playlist->getID());
01419 }
01420 }
01421 else if (event->type() == MusicPlayerEvent::TrackChangeEvent)
01422 {
01423 MusicPlayerEvent *mpe = dynamic_cast<MusicPlayerEvent *>(event);
01424
01425 if (!mpe)
01426 return;
01427
01428 int trackNo = mpe->TrackID;
01429
01430 if (m_currentPlaylist)
01431 {
01432 if (m_currentTrack >= 0 && m_currentTrack < m_currentPlaylist->GetCount())
01433 {
01434 MythUIButtonListItem *item = m_currentPlaylist->GetItemAt(m_currentTrack);
01435 if (item)
01436 {
01437 item->SetFontState("normal");
01438 item->DisplayState("default", "playstate");
01439 }
01440 }
01441
01442 if (trackNo >= 0 && trackNo < m_currentPlaylist->GetCount())
01443 {
01444 if (m_currentTrack == m_currentPlaylist->GetCurrentPos())
01445 m_currentPlaylist->SetItemCurrent(trackNo);
01446
01447 MythUIButtonListItem *item = m_currentPlaylist->GetItemAt(trackNo);
01448 if (item)
01449 {
01450 item->SetFontState("running");
01451 item->DisplayState("playing", "playstate");
01452 }
01453 }
01454 }
01455
01456 m_currentTrack = trackNo;
01457
01458 gPlayer->getPlaylist()->getStats(&m_playlistTrackCount, &m_playlistMaxTime,
01459 m_currentTrack, &m_playlistPlayedTime);
01460 if (m_playlistProgress)
01461 {
01462 m_playlistProgress->SetTotal(m_playlistMaxTime);
01463 m_playlistProgress->SetUsed(0);
01464 }
01465
01466 updatePlaylistStats();
01467 updateTrackInfo(gPlayer->getCurrentMetadata());
01468 }
01469 else if (event->type() == MusicPlayerEvent::VolumeChangeEvent)
01470 {
01471 updateVolume();
01472 }
01473 else if (event->type() == MusicPlayerEvent::TrackRemovedEvent)
01474 {
01475 MusicPlayerEvent *mpe = dynamic_cast<MusicPlayerEvent *>(event);
01476
01477 if (!mpe)
01478 return;
01479
01480 int trackID = mpe->TrackID;
01481
01482 if (m_currentPlaylist)
01483 {
01484
01485 for (int x = 0; x < m_currentPlaylist->GetCount(); x++)
01486 {
01487 MythUIButtonListItem *item = m_currentPlaylist->GetItemAt(x);
01488 Metadata *mdata = qVariantValue<Metadata*> (item->GetData());
01489 if (mdata && mdata->ID() == (Metadata::IdType) trackID)
01490 {
01491 m_currentPlaylist->RemoveItem(item);
01492 break;
01493 }
01494 }
01495 }
01496
01497 m_currentTrack = gPlayer->getCurrentTrackPos();
01498
01499
01500
01501 if (gPlayer->getCurrentMetadata())
01502 {
01503 if (gPlayer->getCurrentMetadata()->ID() == (Metadata::IdType) trackID)
01504 gPlayer->next();
01505 }
01506
01507 gPlayer->getPlaylist()->getStats(&m_playlistTrackCount, &m_playlistMaxTime,
01508 m_currentTrack, &m_playlistPlayedTime);
01509 updatePlaylistStats();
01510 updateTrackInfo(gPlayer->getCurrentMetadata());
01511 }
01512 else if (event->type() == MusicPlayerEvent::TrackAddedEvent)
01513 {
01514 MusicPlayerEvent *mpe = dynamic_cast<MusicPlayerEvent *>(event);
01515
01516 if (!mpe)
01517 return;
01518
01519 int trackID = mpe->TrackID;
01520
01521 if (m_currentPlaylist)
01522 {
01523 if (trackID == -1)
01524 {
01525
01526 updateUIPlaylist();
01527 }
01528 else
01529 {
01530
01531 Metadata *mdata = gMusicData->all_music->getMetadata(trackID);
01532
01533 if (mdata)
01534 {
01535 MetadataMap metadataMap;
01536 mdata->toMap(metadataMap);
01537
01538 MythUIButtonListItem *item =
01539 new MythUIButtonListItem(m_currentPlaylist, "", qVariantFromValue(mdata));
01540
01541 item->SetTextFromMap(metadataMap);
01542
01543 if (gPlayer->isPlaying() && gPlayer->getCurrentMetadata() &&
01544 mdata->ID() == gPlayer->getCurrentMetadata()->ID())
01545 {
01546 item->SetFontState("running");
01547 item->DisplayState("playing", "playstate");
01548 }
01549 else
01550 {
01551 item->SetFontState("normal");
01552 item->DisplayState("default", "playstate");
01553 }
01554 }
01555 }
01556 }
01557
01558 gPlayer->getPlaylist()->getStats(&m_playlistTrackCount, &m_playlistMaxTime,
01559 m_currentTrack, &m_playlistPlayedTime);
01560
01561 updatePlaylistStats();
01562 updateTrackInfo(gPlayer->getCurrentMetadata());
01563 }
01564 else if (event->type() == MusicPlayerEvent::AllTracksRemovedEvent)
01565 {
01566 updateUIPlaylist();
01567 updatePlaylistStats();
01568 updateTrackInfo(NULL);
01569 }
01570 else if (event->type() == MusicPlayerEvent::MetadataChangedEvent ||
01571 event->type() == MusicPlayerEvent::TrackStatsChangedEvent)
01572 {
01573 MusicPlayerEvent *mpe = dynamic_cast<MusicPlayerEvent *>(event);
01574
01575 if (!mpe)
01576 return;
01577
01578 uint trackID = mpe->TrackID;
01579
01580 if (m_currentPlaylist)
01581 {
01582 for (int x = 0; x < m_currentPlaylist->GetCount(); x++)
01583 {
01584 MythUIButtonListItem *item = m_currentPlaylist->GetItemAt(x);
01585 Metadata *mdata = qVariantValue<Metadata*> (item->GetData());
01586 if (mdata && mdata->ID() == trackID)
01587 {
01588 MetadataMap metadataMap;
01589 mdata->toMap(metadataMap);
01590 item->SetTextFromMap(metadataMap);
01591
01592 item->DisplayState(QString("%1").arg(mdata->Rating()), "ratingstate");
01593 }
01594 }
01595 }
01596
01597 if (gPlayer->getCurrentMetadata() && trackID == gPlayer->getCurrentMetadata()->ID())
01598 updateTrackInfo(gPlayer->getCurrentMetadata());
01599
01600
01601 if (gPlayer->getNextMetadata() && trackID == gPlayer->getNextMetadata()->ID())
01602 updateTrackInfo(gPlayer->getCurrentMetadata());
01603 }
01604 else if (event->type() == MusicPlayerEvent::AlbumArtChangedEvent)
01605 {
01606 MusicPlayerEvent *mpe = dynamic_cast<MusicPlayerEvent *>(event);
01607
01608 if (!mpe)
01609 return;
01610
01611 uint trackID = mpe->TrackID;
01612
01613 if (m_currentPlaylist)
01614 {
01615 for (int x = 0; x < m_currentPlaylist->GetCount(); x++)
01616 {
01617 MythUIButtonListItem *item = m_currentPlaylist->GetItemAt(x);
01618 Metadata *mdata = qVariantValue<Metadata*> (item->GetData());
01619 if (mdata && mdata->ID() == trackID)
01620 {
01621
01622 if (!item->GetImage().isEmpty())
01623 {
01624 QString artFile = mdata->getAlbumArtFile();
01625 if (artFile.isEmpty())
01626 {
01627 item->SetImage("");
01628 item->SetImage("", "coverart");
01629 }
01630 else
01631 {
01632 item->SetImage(mdata->getAlbumArtFile());
01633 item->SetImage(mdata->getAlbumArtFile(), "coverart");
01634 }
01635 }
01636 }
01637 }
01638 }
01639
01640 if (gPlayer->getCurrentMetadata() && trackID == gPlayer->getCurrentMetadata()->ID())
01641 updateTrackInfo(gPlayer->getCurrentMetadata());
01642 }
01643 }
01644
01645 void MusicCommon::updateVolume(void)
01646 {
01647 if (!m_controlVolume)
01648 {
01649 if (m_volumeText)
01650 m_volumeText->Hide();
01651
01652 if (m_muteState)
01653 m_muteState->Hide();
01654
01655 return;
01656 }
01657
01658 if (m_volumeText)
01659 {
01660 QHash<QString, QString> map;
01661 gPlayer->toMap(map);
01662 m_volumeText->SetTextFromMap(map);
01663 }
01664
01665 if (m_muteState)
01666 {
01667 bool muted = gPlayer->isMuted();
01668 m_muteState->DisplayState(muted ? "on" : "off");
01669 }
01670 }
01671
01672 void MusicCommon::editTrackInfo(Metadata *mdata)
01673 {
01674 if (!mdata)
01675 return;
01676
01677 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
01678
01679 EditMetadataDialog *editDialog = new EditMetadataDialog(mainStack, mdata);
01680
01681 if (!editDialog->Create())
01682 {
01683 delete editDialog;
01684 return;
01685 }
01686
01687 mainStack->AddScreen(editDialog);
01688 }
01689
01690 void MusicCommon::updateTrackInfo(Metadata *mdata)
01691 {
01692 if (!mdata)
01693 {
01694 MetadataMap metadataMap;
01695 Metadata metadata;
01696 metadata.toMap(metadataMap);
01697 metadata.toMap(metadataMap, "next");
01698 ResetMap(metadataMap);
01699
01700 if (m_coverartImage)
01701 m_coverartImage->Reset();
01702 if (m_ratingState)
01703 m_ratingState->DisplayState("0");
01704 if (m_timeText)
01705 m_timeText->Reset();
01706 if (m_infoText)
01707 m_infoText->Reset();
01708 if (m_trackProgress)
01709 m_trackProgress->SetUsed(0);
01710
01711 if (m_mainvisual)
01712 m_mainvisual->setVisual(m_visualModes[m_currentVisual]);
01713
01714 return;
01715 }
01716
01717 m_maxTime = mdata->Length() / 1000;
01718
01719
01720 MetadataMap metadataMap;
01721 mdata->toMap(metadataMap);
01722
01723
01724 Metadata *nextMetadata = gPlayer->getNextMetadata();
01725 if (nextMetadata)
01726 nextMetadata->toMap(metadataMap, "next");
01727
01728
01729 SetTextFromMap(metadataMap);
01730
01731 if (m_coverartImage)
01732 {
01733 QString filename = mdata->getAlbumArtFile();
01734 if (!filename.isEmpty())
01735 {
01736 m_coverartImage->SetFilename(filename);
01737 m_coverartImage->Load();
01738 }
01739 else
01740 m_coverartImage->Reset();
01741 }
01742
01743 if (m_ratingState)
01744 m_ratingState->DisplayState(QString("%1").arg(mdata->Rating()));
01745
01746 setTrackOnLCD(mdata);
01747 }
01748
01749 void MusicCommon::showTrackInfo(Metadata *mdata)
01750 {
01751 if (!mdata)
01752 return;
01753
01754 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
01755
01756 TrackInfoDialog *dlg = new TrackInfoDialog(popupStack, mdata, "trackinfopopup");
01757
01758 if (!dlg->Create())
01759 {
01760 delete dlg;
01761 return;
01762 }
01763
01764 popupStack->AddScreen(dlg);
01765 }
01766
01767 void MusicCommon::playlistItemClicked(MythUIButtonListItem *item)
01768 {
01769 if (!item)
01770 return;
01771
01772 if (m_moveTrackMode)
01773 {
01774 m_movingTrack = !m_movingTrack;
01775
01776 if (m_movingTrack)
01777 item->DisplayState("on", "movestate");
01778 else
01779 item->DisplayState("off", "movestate");
01780 }
01781 else
01782 gPlayer->setCurrentTrackPos(m_currentPlaylist->GetCurrentPos());
01783
01784 if (m_cycleVisualizer)
01785 cycleVisualizer();
01786 }
01787
01788 void MusicCommon::playlistItemVisible(MythUIButtonListItem *item)
01789 {
01790 if (!item)
01791 return;
01792
01793 Metadata *mdata = qVariantValue<Metadata*> (item->GetData());
01794 if (mdata)
01795 {
01796 if (item->GetImage().isEmpty())
01797 {
01798 QString artFile = mdata->getAlbumArtFile();
01799 if (artFile.isEmpty())
01800 {
01801 item->SetImage("");
01802 item->SetImage("", "coverart");
01803 }
01804 else
01805 {
01806 item->SetImage(mdata->getAlbumArtFile());
01807 item->SetImage(mdata->getAlbumArtFile(), "coverart");
01808 }
01809 }
01810
01811 if (item->GetText() == " ")
01812 {
01813 MetadataMap metadataMap;
01814 mdata->toMap(metadataMap);
01815 item->SetText("");
01816 item->SetTextFromMap(metadataMap);
01817 item->DisplayState(QString("%1").arg(mdata->Rating()), "ratingstate");
01818 }
01819 }
01820 }
01821
01822 void MusicCommon::updateUIPlaylist(void)
01823 {
01824 if (m_noTracksText)
01825 m_noTracksText->SetVisible((gPlayer->getPlaylist()->getSongs().count() == 0));
01826
01827 if (!m_currentPlaylist)
01828 return;
01829
01830 m_currentPlaylist->Reset();
01831
01832 Playlist *playlist = gPlayer->getPlaylist();
01833
01834 QList<Metadata*> songlist = playlist->getSongs();
01835 QList<Metadata*>::iterator it = songlist.begin();
01836 for (; it != songlist.end(); ++it)
01837 {
01838 Metadata *mdata = (*it);
01839 if (mdata)
01840 {
01841 MythUIButtonListItem *item =
01842 new MythUIButtonListItem(m_currentPlaylist, " ", qVariantFromValue(mdata));
01843
01844 item->SetText(mdata->Artist() + mdata->Album() + mdata->Title(), "**search**");
01845 item->SetFontState("normal");
01846 item->DisplayState("default", "playstate");
01847
01848
01849 if (gPlayer->getCurrentMetadata() && mdata->ID() == gPlayer->getCurrentMetadata()->ID())
01850 {
01851 if (gPlayer->isPlaying())
01852 {
01853 item->SetFontState("running");
01854 item->DisplayState("playing", "playstate");
01855 }
01856 else if (gPlayer->isPaused())
01857 {
01858 item->SetFontState("idle");
01859 item->DisplayState("paused", "playstate");
01860 }
01861 else
01862 {
01863 item->SetFontState("normal");
01864 item->DisplayState("stopped", "playstate");
01865 }
01866 }
01867
01868 if (gPlayer->getCurrentMetadata() && mdata->ID() == gPlayer->getCurrentMetadata()->ID())
01869 m_currentPlaylist->SetItemCurrent(item);
01870 }
01871 }
01872 }
01873
01874 void MusicCommon::updateUIPlayedList(void)
01875 {
01876 if (!m_playedTracksList)
01877 return;
01878
01879 m_playedTracksList->Reset();
01880
01881 QList<Metadata> playedList = gPlayer->getPlayedTracksList();
01882
01883 for (int x = playedList.count(); x > 0; x--)
01884 {
01885 Metadata *mdata = &playedList[x-1];
01886 MythUIButtonListItem *item =
01887 new MythUIButtonListItem(m_playedTracksList, "");
01888
01889 MetadataMap metadataMap;
01890 mdata->toMap(metadataMap);
01891 item->SetTextFromMap(metadataMap);
01892
01893 if (x == playedList.count() && gPlayer->isPlaying())
01894 {
01895 item->SetFontState("playing");
01896 item->DisplayState("playing", "playstate");
01897 }
01898 else
01899 {
01900 item->SetFontState("normal");
01901 item->DisplayState("default", "playstate");
01902 }
01903 }
01904 }
01905
01906 void MusicCommon::updatePlaylistStats(void)
01907 {
01908 int trackCount = gPlayer->getPlaylist()->getSongs().size();
01909
01910 QHash<QString, QString> map;
01911 if (gPlayer->isPlaying() && trackCount > 0)
01912 {
01913 QString playlistcurrent = QLocale::system().toString(m_currentTrack + 1);
01914 QString playlisttotal = QLocale::system().toString(trackCount);
01915
01916 map["playlistposition"] = QString(tr("%1 of %2")).arg(playlistcurrent)
01917 .arg(playlisttotal);
01918 map["playlistcurrent"] = playlistcurrent;
01919 map["playlistcount"] = playlisttotal;
01920 map["playlisttime"] = getTimeString(m_playlistPlayedTime + m_currentTime, m_playlistMaxTime);
01921 map["playlistplayedtime"] = getTimeString(m_playlistPlayedTime + m_currentTime, 0);
01922 map["playlisttotaltime"] = getTimeString(m_playlistMaxTime, 0);
01923 map["playlistname"] = gPlayer->getPlaylist()->getName();
01924 }
01925 else
01926 {
01927 map["playlistposition"] = "";
01928 map["playlistcurrent"] = "";
01929 map["playlistcount"] = "";
01930 map["playlisttime"] = "";
01931 map["playlistplayedtime"] = "";
01932 map["playlisttotaltime"] = "";
01933 map["playlistname"] = "";
01934 }
01935
01936 SetTextFromMap(map);
01937
01938 if (m_playlistProgress)
01939 m_playlistProgress->SetUsed(m_playlistPlayedTime + m_currentTime);
01940 }
01941
01942 QString MusicCommon::getTimeString(int exTime, int maxTime)
01943 {
01944 QString time_string;
01945
01946 int eh = exTime / 3600;
01947 int em = (exTime / 60) % 60;
01948 int es = exTime % 60;
01949
01950 int maxh = maxTime / 3600;
01951 int maxm = (maxTime / 60) % 60;
01952 int maxs = maxTime % 60;
01953
01954 if (maxTime <= 0)
01955 {
01956 if (eh > 0)
01957 time_string.sprintf("%d:%02d:%02d", eh, em, es);
01958 else
01959 time_string.sprintf("%02d:%02d", em, es);
01960 }
01961 else
01962 {
01963 if (maxh > 0)
01964 time_string.sprintf("%d:%02d:%02d / %02d:%02d:%02d", eh, em,
01965 es, maxh, maxm, maxs);
01966 else
01967 time_string.sprintf("%02d:%02d / %02d:%02d", em, es, maxm,
01968 maxs);
01969 }
01970
01971 return time_string;
01972 }
01973
01974
01975
01976 void MusicCommon::searchButtonList(void)
01977 {
01978 MythUIButtonList *buttonList = dynamic_cast<MythUIButtonList *>(GetFocusWidget());
01979 if (buttonList)
01980 buttonList->ShowSearchDialog();
01981
01982 MythUIButtonTree *buttonTree = dynamic_cast<MythUIButtonTree *>(GetFocusWidget());
01983 if (buttonTree)
01984 buttonTree->ShowSearchDialog();
01985 }
01986
01987 void MusicCommon::ShowMenu(void)
01988 {
01989 MythMenu *mainMenu = createMainMenu();
01990
01991 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
01992
01993 MythDialogBox *menuPopup = new MythDialogBox(mainMenu, popupStack, "actionmenu");
01994
01995 if (menuPopup->Create())
01996 popupStack->AddScreen(menuPopup);
01997 else
01998 delete mainMenu;
01999 }
02000
02001 MythMenu* MusicCommon::createMainMenu(void)
02002 {
02003 QString label = tr("Actions");
02004
02005 MythMenu *menu = new MythMenu(label, this, "actionmenu");
02006
02007 if (GetFocusWidget() && (GetFocusWidget()->inherits("MythUIButtonList") ||
02008 GetFocusWidget()->inherits("MythUIButtonTree")))
02009 menu->AddItem(tr("Search List..."));
02010
02011 menu->AddItem(tr("Switch View"), NULL, createViewMenu());
02012 menu->AddItem(tr("Playlist Options"), NULL, createPlaylistMenu());
02013 menu->AddItem(tr("Set Shuffle Mode"), NULL, createShuffleMenu());
02014 menu->AddItem(tr("Set Repeat Mode"), NULL, createRepeatMenu());
02015 menu->AddItem(tr("Player Options"), NULL, createPlayerMenu());
02016 menu->AddItem(tr("Quick Playlists"), NULL, createQuickPlaylistsMenu());
02017
02018 if (m_visualizerVideo)
02019 menu->AddItem(tr("Change Visualizer"), NULL, createVisualizerMenu());
02020
02021 return menu;
02022 }
02023
02024 MythMenu* MusicCommon::createViewMenu(void)
02025 {
02026 QString label = tr("Switch View");
02027
02028 MythMenu *menu = new MythMenu(label, this, "viewmenu");
02029
02030 if (m_currentView != MV_PLAYLIST)
02031 menu->AddItem(tr("Current Playlist"), qVariantFromValue((int)MV_PLAYLIST));
02032 if (m_currentView != MV_PLAYLISTEDITORTREE)
02033 menu->AddItem(tr("Playlist Editor - Tree"), qVariantFromValue((int)MV_PLAYLISTEDITORTREE));
02034 if (m_currentView != MV_PLAYLISTEDITORGALLERY)
02035 menu->AddItem(tr("Playlist Editor - Gallery"), qVariantFromValue((int)MV_PLAYLISTEDITORGALLERY));
02036 if (m_currentView != MV_SEARCH)
02037 menu->AddItem(tr("Search for Music"), qVariantFromValue((int)MV_SEARCH));
02038 if (m_currentView != MV_VISUALIZER)
02039 menu->AddItem(tr("Fullscreen Visualizer"), qVariantFromValue((int)MV_VISUALIZER));
02040
02041 return menu;
02042 }
02043
02044 MythMenu* MusicCommon::createPlaylistMenu(void)
02045 {
02046 QString label = tr("Playlist Options");
02047
02048 MythMenu *menu = new MythMenu(label, this, "playlistmenu");
02049
02050 if (m_currentPlaylist)
02051 {
02052 menu->AddItem(tr("Sync List With Current Track"));
02053 menu->AddItem(tr("Remove Selected Track"));
02054 }
02055
02056 menu->AddItem(tr("Remove All Tracks"));
02057
02058 if (m_currentPlaylist)
02059 {
02060 menu->AddItem(tr("Save To New Playlist"));
02061 menu->AddItem(tr("Save To Existing Playlist"));
02062
02063 if (m_moveTrackMode)
02064 menu->AddItem(tr("Switch To Select Mode"));
02065 else
02066 menu->AddItem(tr("Switch To Move Mode"));
02067 }
02068
02069 return menu;
02070 }
02071
02072 void MusicCommon::showExitMenu(void)
02073 {
02074 QString label = tr("Exiting Music Player.\n\n"
02075 "Do you want to continue playing in the background?");
02076
02077 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
02078
02079 MythDialogBox *menu = new MythDialogBox(label, popupStack, "exitmenu");
02080
02081 if (!menu->Create())
02082 {
02083 delete menu;
02084 return;
02085 }
02086
02087 menu->SetReturnEvent(this, "exitmenu");
02088
02089 menu->AddButton(tr("No - Exit, Stop Playing"));
02090 menu->AddButton(tr("Yes - Exit, Continue Playing"));
02091 menu->AddButton(tr("Cancel"));
02092
02093 popupStack->AddScreen(menu);
02094 }
02095
02096 MythMenu* MusicCommon::createPlayerMenu(void)
02097 {
02098 QString label = tr("Player Actions");
02099
02100 MythMenu *menu = new MythMenu(label, this, "playermenu");
02101
02102 menu->AddItem(tr("Change Volume"));
02103 menu->AddItem(tr("Mute"));
02104 menu->AddItem(tr("Previous Track"));
02105 menu->AddItem(tr("Next Track"));
02106 menu->AddItem(tr("Jump Back"));
02107 menu->AddItem(tr("Jump Forward"));
02108 menu->AddItem(tr("Play"));
02109 menu->AddItem(tr("Stop"));
02110 menu->AddItem(tr("Pause"));
02111
02112 return menu;
02113 }
02114
02115 MythMenu* MusicCommon::createRepeatMenu(void)
02116 {
02117 QString label = tr("Set Repeat Mode");
02118
02119 MythMenu *menu = new MythMenu(label, this, "repeatmenu");
02120
02121 menu->AddItem(tr("None"), qVariantFromValue((int)MusicPlayer::REPEAT_OFF));
02122 menu->AddItem(tr("Track"), qVariantFromValue((int)MusicPlayer::REPEAT_TRACK));
02123 menu->AddItem(tr("All"), qVariantFromValue((int)MusicPlayer::REPEAT_ALL));
02124
02125 return menu;
02126 }
02127
02128 MythMenu* MusicCommon::createShuffleMenu(void)
02129 {
02130 QString label = tr("Set Shuffle Mode");
02131
02132 MythMenu *menu = new MythMenu(label, this, "shufflemenu");
02133
02134 menu->AddItem(tr("None"), qVariantFromValue((int)MusicPlayer::SHUFFLE_OFF));
02135 menu->AddItem(tr("Random"), qVariantFromValue((int)MusicPlayer::SHUFFLE_RANDOM));
02136 menu->AddItem(tr("Smart"), qVariantFromValue((int)MusicPlayer::SHUFFLE_INTELLIGENT));
02137 menu->AddItem(tr("Album"), qVariantFromValue((int)MusicPlayer::SHUFFLE_ALBUM));
02138 menu->AddItem(tr("Artist"), qVariantFromValue((int)MusicPlayer::SHUFFLE_ARTIST));
02139
02140 return menu;
02141 }
02142
02143 MythMenu* MusicCommon::createQuickPlaylistsMenu(void)
02144 {
02145 QString label = tr("Quick Playlists");
02146
02147 MythMenu *menu = new MythMenu(label, this, "quickplaylistmenu");
02148
02149 menu->AddItem(tr("All Tracks"));
02150
02151 if (gMusicData->all_music->getCDTrackCount() > 0)
02152 menu->AddItem(tr("From CD"));
02153
02154 if (gPlayer->getCurrentMetadata())
02155 {
02156 menu->AddItem(tr("Tracks By Current Artist"));
02157 menu->AddItem(tr("Tracks From Current Album"));
02158 menu->AddItem(tr("Tracks From Current Genre"));
02159 menu->AddItem(tr("Tracks From Current Year"));
02160 menu->AddItem(tr("Tracks With Same Title"));
02161 }
02162
02163 return menu;
02164 }
02165
02166 MythMenu* MusicCommon::createVisualizerMenu(void)
02167 {
02168 QString label = tr("Choose Visualizer");
02169
02170 MythMenu *menu = new MythMenu(label, this, "visualizermenu");
02171
02172 for (int x = 0; x < m_visualModes.count(); x++)
02173 menu->AddItem(m_visualModes.at(x), qVariantFromValue(x));
02174
02175 return menu;
02176 }
02177
02178 MythMenu* MusicCommon::createPlaylistOptionsMenu(void)
02179 {
02180 QString label = tr("Add to Playlist Options");
02181
02182 MythMenu *menu = new MythMenu(label, this, "playlistoptionsmenu");
02183
02184 menu->AddItem(tr("Replace Tracks"));
02185 menu->AddItem(tr("Add Tracks"));
02186
02187 return menu;
02188 }
02189
02190 void MusicCommon::allTracks()
02191 {
02192 m_whereClause = "ORDER BY music_artists.artist_name, album_name, track";
02193 showPlaylistOptionsMenu();
02194 }
02195
02196 void MusicCommon::fromCD(void)
02197 {
02198 m_whereClause = "";
02199 m_songList.clear();
02200
02201
02202 for (int x = 1; x <= gMusicData->all_music->getCDTrackCount(); x++)
02203 {
02204 Metadata *mdata = gMusicData->all_music->getCDMetadata(x);
02205 if (mdata)
02206 {
02207 m_songList.append((mdata)->ID());
02208 }
02209 }
02210
02211 showPlaylistOptionsMenu();
02212 }
02213
02214 void MusicCommon::byArtist(void)
02215 {
02216 Metadata* mdata = gPlayer->getCurrentMetadata();
02217 if (!mdata)
02218 return;
02219
02220 QString value = formattedFieldValue(mdata->Artist().toUtf8().constData());
02221 m_whereClause = "WHERE music_artists.artist_name = " + value +
02222 " ORDER BY album_name, track";
02223
02224 showPlaylistOptionsMenu();
02225 }
02226
02227 void MusicCommon::byAlbum(void)
02228 {
02229 Metadata* mdata = gPlayer->getCurrentMetadata();
02230 if (!mdata)
02231 return;
02232
02233 QString value = formattedFieldValue(mdata->Album().toUtf8().constData());
02234 m_whereClause = "WHERE album_name = " + value +
02235 " ORDER BY track";
02236
02237 showPlaylistOptionsMenu();
02238 }
02239
02240 void MusicCommon::byGenre(void)
02241 {
02242 Metadata* mdata = gPlayer->getCurrentMetadata();
02243 if (!mdata)
02244 return;
02245
02246 QString value = formattedFieldValue(mdata->Genre().toUtf8().constData());
02247 m_whereClause = "WHERE genre = " + value +
02248 " ORDER BY music_artists.artist_name, album_name, track";
02249
02250 showPlaylistOptionsMenu();
02251 }
02252
02253 void MusicCommon::byYear(void)
02254 {
02255 Metadata* mdata = gPlayer->getCurrentMetadata();
02256 if (!mdata)
02257 return;
02258
02259 QString value = formattedFieldValue(mdata->Year());
02260 m_whereClause = "WHERE music_songs.year = " + value +
02261 " ORDER BY music_artists.artist_name, album_name, track";
02262
02263 showPlaylistOptionsMenu();
02264 }
02265
02266 void MusicCommon::byTitle(void)
02267 {
02268 Metadata* mdata = gPlayer->getCurrentMetadata();
02269 if (!mdata)
02270 return;
02271
02272 QString value = formattedFieldValue(mdata->Title().toUtf8().constData());
02273 m_whereClause = "WHERE music_songs.name = " + value +
02274 " ORDER BY music_artists.artist_name, album_name, track";
02275
02276 showPlaylistOptionsMenu();
02277 }
02278
02279 void MusicCommon::showPlaylistOptionsMenu(bool addMainMenu)
02280 {
02281 m_playlistOptions.playPLOption = PL_CURRENT;
02282
02283
02284 if (gPlayer->getPlaylist()->getSongs().count() == 0)
02285 {
02286 m_playlistOptions.insertPLOption = PL_REPLACE;
02287 doUpdatePlaylist();
02288 return;
02289 }
02290
02291 MythMenu *menu = createPlaylistOptionsMenu();
02292
02293 if (addMainMenu)
02294 menu->AddItem(tr("More Options"), NULL, createMainMenu());
02295
02296 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
02297
02298 MythDialogBox *menuPopup = new MythDialogBox(menu, popupStack, "playlistoptionsmenu");
02299
02300 if (menuPopup->Create())
02301 popupStack->AddScreen(menuPopup);
02302 else
02303 delete menu;
02304 }
02305
02306 void MusicCommon::doUpdatePlaylist(void)
02307 {
02308 int curTrackID, trackCount;
02309 int curPos = gPlayer->getCurrentTrackPos();
02310
02311 trackCount = gPlayer->getPlaylist()->getSongs().count();
02312
02313
02314 if (gPlayer->getCurrentMetadata())
02315 curTrackID = gPlayer->getCurrentMetadata()->ID();
02316 else
02317 curTrackID = -1;
02318
02319 if (!m_whereClause.isEmpty())
02320 {
02321
02322 gMusicData->all_playlists->getActive()->fillSonglistFromQuery(
02323 m_whereClause, true,
02324 m_playlistOptions.insertPLOption, curTrackID);
02325 m_whereClause.clear();
02326 }
02327 else if (!m_songList.isEmpty())
02328 {
02329
02330 gMusicData->all_playlists->getActive()->fillSonglistFromList(
02331 m_songList, true,
02332 m_playlistOptions.insertPLOption, curTrackID);
02333
02334 m_songList.clear();
02335 }
02336
02337 updateUIPlaylist();
02338
02339 switch (m_playlistOptions.playPLOption)
02340 {
02341 case PL_CURRENT:
02342 {
02343 if (!restorePosition(curTrackID))
02344 playFirstTrack();
02345
02346 break;
02347 }
02348
02349 case PL_FIRST:
02350 playFirstTrack();
02351 break;
02352
02353 case PL_FIRSTNEW:
02354 {
02355 switch (m_playlistOptions.insertPLOption)
02356 {
02357 case PL_REPLACE:
02358 playFirstTrack();
02359 break;
02360
02361 case PL_INSERTATEND:
02362 {
02363 pause();
02364 if (!gPlayer->setCurrentTrackPos(trackCount + 1))
02365 playFirstTrack();
02366 break;
02367 }
02368
02369 case PL_INSERTAFTERCURRENT:
02370 if (!gPlayer->setCurrentTrackPos(curPos + 1))
02371 playFirstTrack();
02372 break;
02373
02374 default:
02375 playFirstTrack();
02376 }
02377
02378 break;
02379 }
02380 }
02381
02382 gPlayer->getPlaylist()->getStats(&m_playlistTrackCount, &m_playlistMaxTime,
02383 m_currentTrack, &m_playlistPlayedTime);
02384 }
02385
02386 bool MusicCommon::restorePosition(int trackID)
02387 {
02388
02389 bool foundTrack = false;
02390
02391 if (trackID != -1)
02392 {
02393 for (int x = 0; x < gPlayer->getPlaylist()->getSongs().size(); x++)
02394 {
02395 Metadata *mdata = gPlayer->getPlaylist()->getSongs().at(x);
02396 if (mdata && mdata->ID() == (Metadata::IdType) trackID)
02397 {
02398 m_currentTrack = x;
02399 if (m_currentPlaylist)
02400 {
02401 m_currentPlaylist->SetItemCurrent(m_currentTrack);
02402 MythUIButtonListItem *item = m_currentPlaylist->GetItemCurrent();
02403 if (item)
02404 {
02405 item->SetFontState("running");
02406 item->DisplayState("playing", "playstate");
02407 }
02408 }
02409
02410 foundTrack = true;
02411
02412 break;
02413 }
02414 }
02415 }
02416
02417 return foundTrack;
02418 }
02419
02420 void MusicCommon::playFirstTrack()
02421 {
02422 gPlayer->setCurrentTrackPos(0);
02423 }
02424
02425
02426
02427
02428 #define MUSICVOLUMEPOPUPTIME 4 * 1000
02429
02430 MythMusicVolumeDialog::MythMusicVolumeDialog(MythScreenStack *parent, const char *name)
02431 : MythScreenType(parent, name, false)
02432 {
02433 m_displayTimer = NULL;
02434 }
02435
02436 MythMusicVolumeDialog::~MythMusicVolumeDialog(void)
02437 {
02438 if (m_displayTimer)
02439 {
02440 m_displayTimer->stop();
02441 delete m_displayTimer;
02442 m_displayTimer = NULL;
02443 }
02444 }
02445
02446 bool MythMusicVolumeDialog::Create(void)
02447 {
02448 if (!LoadWindowFromXML("music-ui.xml", "volume_popup", this))
02449 return false;
02450
02451 UIUtilW::Assign(this, m_volText, "volume");
02452 UIUtilW::Assign(this, m_volProgress, "volumeprogress");
02453 UIUtilW::Assign(this, m_muteState, "mutestate");
02454
02455 if (m_volProgress)
02456 m_volProgress->SetTotal(100);
02457
02458 updateDisplay();
02459
02460 m_displayTimer = new QTimer(this);
02461 connect(m_displayTimer, SIGNAL(timeout()), this, SLOT(Close()));
02462 m_displayTimer->setSingleShot(true);
02463 m_displayTimer->start(MUSICVOLUMEPOPUPTIME);
02464
02465 return true;
02466 }
02467
02468 bool MythMusicVolumeDialog::keyPressEvent(QKeyEvent *event)
02469 {
02470 QStringList actions;
02471 bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions, false);
02472
02473 for (int i = 0; i < actions.size() && !handled; i++)
02474 {
02475 QString action = actions[i];
02476 handled = true;
02477
02478 if (action == "UP" || action == "VOLUMEUP")
02479 increaseVolume();
02480 else if (action == "DOWN" || action == "VOLUMEDOWN")
02481 decreaseVolume();
02482 else if (action == "MUTE" || action == "SELECT")
02483 toggleMute();
02484 else
02485 handled = false;
02486 }
02487
02488 if (!handled && MythScreenType::keyPressEvent(event))
02489 handled = true;
02490
02491
02492
02493 if (handled)
02494 m_displayTimer->start(MUSICVOLUMEPOPUPTIME);
02495
02496 return handled;
02497 }
02498
02499 void MythMusicVolumeDialog::increaseVolume(void)
02500 {
02501 gPlayer->incVolume();
02502 updateDisplay();
02503 }
02504
02505 void MythMusicVolumeDialog::decreaseVolume(void)
02506 {
02507 gPlayer->decVolume();
02508 updateDisplay();
02509 }
02510
02511 void MythMusicVolumeDialog::toggleMute(void)
02512 {
02513 gPlayer->toggleMute();
02514 updateDisplay();
02515 }
02516
02517 void MythMusicVolumeDialog::updateDisplay()
02518 {
02519 if (m_muteState)
02520 m_muteState->DisplayState(gPlayer->isMuted() ? "on" : "off");
02521
02522 if (m_volProgress)
02523 m_volProgress->SetUsed(gPlayer->getVolume());
02524
02525 if (m_volText)
02526 {
02527 QHash<QString, QString> map;
02528 gPlayer->toMap(map);
02529 m_volText->SetTextFromMap(map);
02530 }
02531 }
02532
02533
02534
02535
02536 TrackInfoDialog::TrackInfoDialog(MythScreenStack *parent, Metadata *metadata, const char *name)
02537 : MythScreenType(parent, name, false)
02538 {
02539 m_metadata = metadata;
02540 }
02541
02542 TrackInfoDialog::~TrackInfoDialog(void)
02543 {
02544 }
02545
02546 bool TrackInfoDialog::Create(void)
02547 {
02548 if (!LoadWindowFromXML("music-ui.xml", "trackdetail_popup", this))
02549 return false;
02550
02551 MetadataMap metadataMap;
02552 m_metadata->toMap(metadataMap);
02553 SetTextFromMap(metadataMap);
02554
02555 MythUIStateType *ratingState = dynamic_cast<MythUIStateType *>(GetChild("rating_state"));
02556 if (ratingState)
02557 ratingState->DisplayState(QString("%1").arg(m_metadata->Rating()));
02558
02559 MythUIImage *albumImage = dynamic_cast<MythUIImage *>(GetChild("coverart"));
02560 if (albumImage)
02561 {
02562 if (!m_metadata->getAlbumArtFile().isEmpty())
02563 {
02564 albumImage->SetFilename(m_metadata->getAlbumArtFile());
02565 albumImage->Load();
02566 }
02567 }
02568
02569 return true;
02570 }
02571
02572 bool TrackInfoDialog::keyPressEvent(QKeyEvent *event)
02573 {
02574 QStringList actions;
02575 bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions, false);
02576
02577 for (int i = 0; i < actions.size() && !handled; i++)
02578 {
02579 QString action = actions[i];
02580 handled = true;
02581
02582 if (action == "INFO")
02583 Close();
02584 else
02585 handled = false;
02586 }
02587
02588 if (!handled && MythScreenType::keyPressEvent(event))
02589 handled = true;
02590
02591 return handled;
02592 }