2 * MP3/MPlayer plugin to VDR (C++)
4 * (C) 2001-2009 Stefan Huelswitt <s.huelswitt@gmx.de>
6 * This code is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This code is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
28 #include <sys/ioctl.h>
29 #include <sys/types.h>
38 // -----------------------------------------------------------------------------
40 void Status(const char *text)
42 Skins.Message(mtStatus,text);
45 void Error(const char *text)
47 Skins.Message(mtError,text);
50 void Info(const char *text)
52 Skins.Message(mtInfo,text);
55 // --- cMenuBrowseItem ---------------------------------------------------------
57 class cMenuBrowseItem : public cOsdItem {
60 virtual void Set(void);
62 cMenuBrowseItem(cFileObj *Item);
63 cFileObj *Item(void) { return item; }
66 cMenuBrowseItem::cMenuBrowseItem(cFileObj *Item)
72 void cMenuBrowseItem::Set(void)
74 char *buffer=aprintf(item->Type()==otFile?"%s":"[%s]",item->Name());
75 SetText(buffer,false);
78 // --- cMenuBrowse ------------------------------------------------------
80 cFileObj *cMenuBrowse::lastselect=0;
82 cMenuBrowse::cMenuBrowse(cFileSource *Source, bool Dirselect, bool WithID3, const char *title, const char * const *Excl)
86 delete lastselect; lastselect=0;
89 dirselectable=Dirselect;
97 cMenuBrowse::~cMenuBrowse()
104 cFileObj *cMenuBrowse::CurrentItem(void)
106 cMenuBrowseItem *item = (cMenuBrowseItem *)Get(Current());
107 return item ? item->Item():0;
110 void cMenuBrowse::SetButtons(void)
112 SetHelp(tr("Select"), currentdir?tr("Parent"):0, 0, withID3?tr("ID3 info"):0);
116 void cMenuBrowse::SetSource(cFileSource *Source)
119 free(currentdir); currentdir=0;
120 free(parent); parent=0;
121 source->GetRemember(currentdir,parent);
124 bool cMenuBrowse::LoadDir(const char *dir)
127 Status(tr("Scanning directory..."));
128 bool res=list->Load(source,dir,excl);
130 cFileObj *item=list->First();
132 Add(new cMenuBrowseItem(item),(parent && !strcmp(item->Name(),parent)));
133 item=list->Next(item);
140 bool cMenuBrowse::NewDir(const char *dir)
142 char *ncur=dir ? strdup(dir):0;
143 bool r=LoadDir(ncur);
149 free(currentdir); currentdir=ncur;
151 cFileObj *item=CurrentItem();
152 source->SetRemember(currentdir,item?item->Name():0);
158 Error(tr("Error scanning directory!"));
162 eOSState cMenuBrowse::Parent(void)
164 eOSState res=osContinue;
168 char *ss=strrchr(currentdir,'/');
174 else parent=strdup(currentdir);
176 if(!NewDir(ss)) res=osEnd;
181 eOSState cMenuBrowse::Select(bool isred)
183 eOSState res=osContinue;
186 if((item=CurrentItem())) {
187 switch(item->Type()) {
189 if(!isred || !dirselectable)
193 if(!isred || !dirselectable) {
194 if(!NewDir(item->Path())) res=osEnd;
197 // fall through to otFile
199 lastselect=new cFileObj(item);
209 eOSState cMenuBrowse::ID3Info(void)
214 eOSState cMenuBrowse::ProcessStdKey(eKeys Key, eOSState state)
216 if(state==osUnknown) {
218 case kOk: state=Select(false); break;
219 case kRed: state=Select(true); break;
220 case kGreen: state=Parent(); break;
221 case kBlue: if(withID3) state=ID3Info();
223 //case kMenu: state=osEnd; break;
227 if(state==osEnd || state==osBack) {
228 cFileObj *item=CurrentItem();
229 if(item) source->SetRemember(currentdir,item->Name());
234 // --- cMenuSourceItem ----------------------------------------------------------
236 class cMenuSourceItem : public cOsdItem {
239 virtual void Set(void);
241 cMenuSourceItem(cFileSource *Source);
242 cFileSource *Source(void) { return source; }
245 cMenuSourceItem::cMenuSourceItem(cFileSource *Source)
251 void cMenuSourceItem::Set(void)
253 char *buffer=aprintf("%s\t%s\t%s", source->NeedsMount()?(source->Status()?"*":">"):"", source->Description(), source->BaseDir());
254 SetText(buffer,false);
257 // --- cMenuSource --------------------------------------------------
259 cFileSource *cMenuSource::selected=0;
261 cMenuSource::cMenuSource(cFileSources *Sources, const char *title)
262 :cOsdMenu(title,2,20)
265 current=Sources->GetSource();
266 cFileSource *source=Sources->First();
268 cOsdMenu::Add(new cMenuSourceItem(source),source==current);
269 source=Sources->Next(source);
272 SetHelp(tr("Select"), tr("Mount"), tr("Unmount"), tr("Eject"));
276 bool cMenuSource::DoMount(cFileSource *src)
278 bool res=src->Mount();
280 DisplayCurrent(true);
284 bool cMenuSource::CheckMount(void)
286 cFileSource *src=selected ? selected:current;
287 if(src->NeedsMount() && !src->Status()) {
288 Error(tr("Selected source is not mounted!"));
294 eOSState cMenuSource::Select(void)
296 if(HasSubMenu() || Count() == 0) return osContinue;
298 cFileSource *src = ((cMenuSourceItem *)Get(Current()))->Source();
299 if(src->NeedsMount() && !src->Status()) {
300 if(!DoMount(src)) Error(tr("Mount failed!"));
302 if(!src->NeedsMount() || src->Status()) {
309 eOSState cMenuSource::Mount(void)
311 if(HasSubMenu() || Count() == 0) return osContinue;
313 cFileSource *src = ((cMenuSourceItem *)Get(Current()))->Source();
314 if(src->NeedsMount() && !src->Status()) {
315 if(DoMount(src)) Info(tr("Mount succeeded"));
316 else Error(tr("Mount failed!"));
321 eOSState cMenuSource::Unmount(void)
323 if(HasSubMenu() || Count() == 0) return osContinue;
325 cFileSource *src = ((cMenuSourceItem *)Get(Current()))->Source();
326 if(src->NeedsMount() && src->Status()) {
327 bool res=src->Unmount();
329 DisplayCurrent(true);
330 if(res) Info(tr("Unmount succeeded"));
331 else Error(tr("Unmount failed!"));
336 eOSState cMenuSource::Eject(void)
338 if(HasSubMenu() || Count() == 0) return osContinue;
340 cFileSource *src = ((cMenuSourceItem *)Get(Current()))->Source();
341 if(src->NeedsMount()) {
342 bool res=src->Eject();
344 DisplayCurrent(true);
345 if(!res) Error(tr("Eject failed!"));
350 eOSState cMenuSource::ProcessKey(eKeys Key)
352 eOSState state = cOsdMenu::ProcessKey(Key);
354 if(state==osBack && !CheckMount()) state=osContinue;
355 if(state==osUnknown) {
358 case kRed: return Select();
359 case kGreen: return Mount();
360 case kYellow: return Unmount();
361 case kBlue: return Eject();
362 case kMenu: CheckMount(); return osEnd;
369 // --- cProgressBar ------------------------------------------------------------
371 cProgressBar::cProgressBar(int Width, int Height, int Current, int Total)
372 :cBitmap(Width, Height, 2)
375 int p = Current * Width / Total;;
376 DrawRectangle(0, 0, p, Height - 1, clrGreen);
377 DrawRectangle(p + 1, 0, Width - 1, Height - 1, clrWhite);