-
Notifications
You must be signed in to change notification settings - Fork 2
/
menu_options.c
142 lines (122 loc) · 2.94 KB
/
menu_options.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "menu_options.h"
cMpvMenuOptions::cMpvMenuOptions(cMpvPlayer *Player)
:cOsdMenu(tr("Options"))
{
SetDisplayMenu();
player = Player;
ShowOptions();
Show();
Display();
}
cMpvMenuOptions::~cMpvMenuOptions()
{
#ifdef DEBUG
dsyslog ("dekonstruktor\n");
#endif
}
void cMpvMenuOptions::ShowOptions()
{
// display chapter select menu if the file has named named chapters
if (player->NumChapters() && player->ChapterTitle(1) != "")
Add(new cOsdItem(tr("Show chapters"), osUser1));
if (player->TotalListPos() > 1)
Add(new cOsdItem(tr("Show playlist"), osUser2));
}
eOSState cMpvMenuOptions::ProcessKey(eKeys Key)
{
eOSState State = cOsdMenu::ProcessKey(Key);
if (!HasSubMenu())
{
switch (Key)
{
case kOk:
if(State == osUser1)
AddSubMenu(new cMpvMenuChapters(player));
if(State == osUser2)
AddSubMenu(new cMpvMenuPlaylist(player));
break;
default:
break;
}
}
return State;
}
//Chapters
cMpvMenuChapters::cMpvMenuChapters(cMpvPlayer *Player)
:cOsdMenu(tr("Chapters"))
{
player = Player;
for (int i=1; i<=player->NumChapters(); i++)
AddItem(player->ChapterTitle(i), i);
Display();
}
eOSState cMpvMenuChapters::ProcessKey(eKeys Key)
{
eOSState State = cOsdMenu::ProcessKey(Key);
if (State == osUnknown)
{
switch (Key)
{
case kOk:
cMpvMenuChapterItem *item = (cMpvMenuChapterItem *) Get(Current());
player->SetChapter(item->Number());
return osEnd;
}
}
return State;
}
void cMpvMenuChapters::AddItem(string Title, int Number)
{
bool Current = false;
if (player->ChapterTitle(player->CurrentChapter()) == Title)
Current = true;
Add(new cMpvMenuChapterItem(Title, Number), Current);
}
cMpvMenuChapterItem::cMpvMenuChapterItem(string Title, int Number)
{
number = Number;
Title = std::to_string(number) + " " + Title;
SetText(Title.c_str());
}
//Playlist
cMpvMenuPlaylist::cMpvMenuPlaylist(cMpvPlayer *Player)
:cOsdMenu(tr("Playlist"))
{
player = Player;
for (int i=1; i<=player->TotalListPos(); i++)
AddItem(player->ListTitle(i), i);
Display();
}
eOSState cMpvMenuPlaylist::ProcessKey(eKeys Key)
{
eOSState State = cOsdMenu::ProcessKey(Key);
if (State == osUnknown)
{
switch (Key)
{
case kOk:
if (player->IsRecord())
{
Skins.Message(mtError, tr("Recording - can't play!"));
break;
}
cMpvMenuPlaylistItem *item = (cMpvMenuPlaylistItem *) Get(Current());
player->PlayIndex(item->Number());
return osEnd;
}
}
return State;
}
void cMpvMenuPlaylist::AddItem(string Title, int Number)
{
bool Current = false;
if (player->ListTitle(player->CurrentListPos()) == Title)
Current = true;
Add(new cMpvMenuPlaylistItem(Title, Number), Current);
}
cMpvMenuPlaylistItem::cMpvMenuPlaylistItem(string Title, int Number)
{
number = Number;
Title = std::to_string(number) + " " + Title;
SetText(Title.c_str());
}