Merge pull request #4630 from Red-F/gotham-resume-pvr-lastplayedposition
[vuplus_xbmc] / xbmc / dialogs / GUIDialogSeekBar.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "GUIDialogSeekBar.h"
22 #include "guilib/GUISliderControl.h"
23 #include "Application.h"
24 #include "GUIInfoManager.h"
25 #include "utils/TimeUtils.h"
26 #include "FileItem.h"
27 #include "utils/SeekHandler.h"
28
29 #define SEEK_BAR_DISPLAY_TIME 2000L
30 #define SEEK_BAR_SEEK_TIME     500L
31
32 #define POPUP_SEEK_SLIDER       401
33 #define POPUP_SEEK_LABEL        402
34
35 CGUIDialogSeekBar::CGUIDialogSeekBar(void)
36     : CGUIDialog(WINDOW_DIALOG_SEEK_BAR, "DialogSeekBar.xml")
37 {
38   m_loadType = LOAD_ON_GUI_INIT;    // the application class handles our resources
39 }
40
41 CGUIDialogSeekBar::~CGUIDialogSeekBar(void)
42 {
43 }
44
45 bool CGUIDialogSeekBar::OnMessage(CGUIMessage& message)
46 {
47   switch ( message.GetMessage() )
48   {
49   case GUI_MSG_WINDOW_INIT:
50   case GUI_MSG_WINDOW_DEINIT:
51     return CGUIDialog::OnMessage(message);
52
53   case GUI_MSG_LABEL_SET:
54     {
55       if (message.GetSenderId() == GetID() && message.GetControlId() == POPUP_SEEK_LABEL)
56         CGUIDialog::OnMessage(message);
57     }
58     break;
59   }
60   return false; // don't process anything other than what we need!
61 }
62
63 void CGUIDialogSeekBar::FrameMove()
64 {
65   if (!g_application.m_pPlayer->HasPlayer())
66   {
67     Close(true);
68     return;
69   }
70
71   // update controls
72   if (!g_application.GetSeekHandler()->InProgress() && !g_infoManager.m_performingSeek)
73   { // position the bar at our current time
74     CGUISliderControl *pSlider = (CGUISliderControl*)GetControl(POPUP_SEEK_SLIDER);
75     if (pSlider && g_infoManager.GetTotalPlayTime())
76       pSlider->SetPercentage((float)g_infoManager.GetPlayTime()/g_infoManager.GetTotalPlayTime() * 0.1f);
77
78     CGUIMessage msg(GUI_MSG_LABEL_SET, GetID(), POPUP_SEEK_LABEL);
79     msg.SetLabel(g_infoManager.GetCurrentPlayTime());
80     OnMessage(msg);
81   }
82   else
83   {
84     CGUISliderControl *pSlider = (CGUISliderControl*)GetControl(POPUP_SEEK_SLIDER);
85     if (pSlider)
86       pSlider->SetPercentage(g_application.GetSeekHandler()->GetPercent());
87
88     CGUIMessage msg(GUI_MSG_LABEL_SET, GetID(), POPUP_SEEK_LABEL);
89     msg.SetLabel(g_infoManager.GetCurrentSeekTime());
90     OnMessage(msg);
91   }
92
93   CGUIDialog::FrameMove();
94 }