00001 #include <iostream>
00002 #include <cstdlib>
00003
00004
00005 #include <QKeyEvent>
00006 #include <QTimer>
00007
00008
00009 #include <mythcontext.h>
00010 #include <mythdbcon.h>
00011 #include <mythmainwindow.h>
00012 #include <mythuibuttonlist.h>
00013 #include <mythuiwebbrowser.h>
00014 #include <mythuitext.h>
00015 #include <mythuiutils.h>
00016 #include <mythdialogbox.h>
00017
00018
00019 #include "musiccommon.h"
00020 #include "visualizerview.h"
00021
00022 VisualizerView::VisualizerView(MythScreenStack *parent)
00023 :MusicCommon(parent, "visualizerview")
00024 {
00025 m_currentView = MV_VISUALIZER;
00026 }
00027
00028 VisualizerView::~VisualizerView()
00029 {
00030 }
00031
00032 bool VisualizerView::Create(void)
00033 {
00034 bool err = false;
00035
00036
00037 err = LoadWindowFromXML("music-ui.xml", "visualizerview", this);
00038
00039 if (!err)
00040 return false;
00041
00042
00043 err = CreateCommon();
00044
00045
00046
00047 if (err)
00048 {
00049 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'lyricsview'");
00050 return false;
00051 }
00052
00053 BuildFocusList();
00054
00055 return true;
00056 }
00057
00058 void VisualizerView::customEvent(QEvent *event)
00059 {
00060 if (event->type() == MusicPlayerEvent::TrackChangeEvent)
00061 showTrackInfoPopup();
00062
00063 MusicCommon::customEvent(event);
00064 }
00065
00066 bool VisualizerView::keyPressEvent(QKeyEvent *event)
00067 {
00068 if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
00069 return true;
00070
00071 bool handled = false;
00072 QStringList actions;
00073 handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions);
00074
00075 for (int i = 0; i < actions.size() && !handled; i++)
00076 {
00077 QString action = actions[i];
00078 handled = true;
00079
00080 if (action == "INFO")
00081 {
00082 showTrackInfoPopup();
00083 }
00084 else
00085 handled = false;
00086 }
00087
00088 if (!handled && MusicCommon::keyPressEvent(event))
00089 handled = true;
00090
00091 if (!handled && MythScreenType::keyPressEvent(event))
00092 handled = true;
00093
00094 return handled;
00095 }
00096
00097 void VisualizerView::ShowMenu(void)
00098 {
00099 QString label = tr("Actions");
00100
00101 MythMenu *menu = new MythMenu(label, this, "menu");
00102
00103 menu->AddItem(tr("Change Visualizer"), NULL, createVisualizerMenu());
00104 menu->AddItem(tr("Show Track Info"), SLOT(showTrackInfoPopup()));
00105 menu->AddItem(tr("Other Options"), NULL, createMainMenu());
00106
00107 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
00108
00109 MythDialogBox *menuPopup = new MythDialogBox(menu, popupStack, "actionmenu");
00110
00111 if (menuPopup->Create())
00112 popupStack->AddScreen(menuPopup);
00113 else
00114 delete menuPopup;
00115 }
00116
00117 void VisualizerView::showTrackInfoPopup(void)
00118 {
00119 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
00120
00121 TrackInfoPopup *popup = new TrackInfoPopup(popupStack, gPlayer->getCurrentMetadata());
00122
00123 if (!popup->Create())
00124 {
00125 delete popup;
00126 return;
00127 }
00128
00129 popupStack->AddScreen(popup);
00130 }
00131
00132
00133
00134
00135 #define MUSICINFOPOPUPTIME 8 * 1000
00136
00137 TrackInfoPopup::TrackInfoPopup(MythScreenStack *parent, Metadata *metadata)
00138 : MythScreenType(parent, "trackinfopopup", false)
00139 {
00140 m_metadata = metadata;
00141 m_displayTimer = NULL;
00142 }
00143
00144 TrackInfoPopup::~TrackInfoPopup(void)
00145 {
00146 if (m_displayTimer)
00147 {
00148 m_displayTimer->stop();
00149 delete m_displayTimer;
00150 m_displayTimer = NULL;
00151 }
00152 }
00153
00154 bool TrackInfoPopup::Create(void)
00155 {
00156 bool err = false;
00157
00158 err = LoadWindowFromXML("music-ui.xml", "trackinfo_popup", this);
00159
00160 if (!err)
00161 return false;
00162
00163
00164 MetadataMap metadataMap;
00165 m_metadata->toMap(metadataMap);
00166
00167
00168 Metadata *nextMetadata = gPlayer->getNextMetadata();
00169 if (nextMetadata)
00170 nextMetadata->toMap(metadataMap, "next");
00171
00172 SetTextFromMap(metadataMap);
00173
00174 MythUIStateType *ratingState = dynamic_cast<MythUIStateType *>(GetChild("ratingstate"));
00175 if (ratingState)
00176 ratingState->DisplayState(QString("%1").arg(m_metadata->Rating()));
00177
00178 MythUIImage *albumImage = dynamic_cast<MythUIImage *>(GetChild("coverart"));
00179 if (albumImage)
00180 {
00181 if (!m_metadata->getAlbumArtFile().isEmpty())
00182 {
00183 albumImage->SetFilename(m_metadata->getAlbumArtFile());
00184 albumImage->Load();
00185 }
00186 }
00187
00188 m_displayTimer = new QTimer(this);
00189 connect(m_displayTimer, SIGNAL(timeout()), this, SLOT(Close()));
00190 m_displayTimer->setSingleShot(true);
00191 m_displayTimer->start(MUSICINFOPOPUPTIME);
00192
00193 return true;
00194 }
00195
00196 bool TrackInfoPopup::keyPressEvent(QKeyEvent *event)
00197 {
00198 QStringList actions;
00199 bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions, false);
00200
00201 for (int i = 0; i < actions.size() && !handled; i++)
00202 {
00203 QString action = actions[i];
00204 handled = true;
00205
00206 if (action == "INFO")
00207 Close();
00208 else
00209 handled = false;
00210 }
00211
00212 if (!handled && MythScreenType::keyPressEvent(event))
00213 handled = true;
00214
00215 return handled;
00216 }