2 * MP3/MPlayer plugin to VDR (C++)
4 * (C) 2001-2007 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 #if APIVERSNUM >= 10307
43 Skins.Message(mtStatus,text);
46 Interface->Status(text);
52 void Error(const char *text)
54 #if APIVERSNUM >= 10307
55 Skins.Message(mtError,text);
57 Interface->Error(text);
61 void Info(const char *text)
63 #if APIVERSNUM >= 10307
64 Skins.Message(mtInfo,text);
66 Interface->Info(text);
70 // --- cMenuBrowseItem ---------------------------------------------------------
72 class cMenuBrowseItem : public cOsdItem {
75 virtual void Set(void);
77 cMenuBrowseItem(cFileObj *Item);
78 cFileObj *Item(void) { return item; }
81 cMenuBrowseItem::cMenuBrowseItem(cFileObj *Item)
87 void cMenuBrowseItem::Set(void)
90 asprintf(&buffer,item->Type()==otFile?"%s":"[%s]",item->Name());
91 SetText(buffer,false);
94 // --- cMenuBrowse ------------------------------------------------------
96 cFileObj *cMenuBrowse::lastselect=0;
98 cMenuBrowse::cMenuBrowse(cFileSource *Source, bool Dirselect, bool WithID3, const char *title, const char * const *Excl)
102 delete lastselect; lastselect=0;
105 dirselectable=Dirselect;
113 cMenuBrowse::~cMenuBrowse()
120 cFileObj *cMenuBrowse::CurrentItem(void)
122 cMenuBrowseItem *item = (cMenuBrowseItem *)Get(Current());
123 return item ? item->Item():0;
126 void cMenuBrowse::SetButtons(void)
128 SetHelp(tr("Select"), currentdir?tr("Parent"):0, 0, withID3?tr("ID3 info"):0);
132 void cMenuBrowse::SetSource(cFileSource *Source)
135 free(currentdir); currentdir=0;
136 free(parent); parent=0;
137 source->GetRemember(currentdir,parent);
140 bool cMenuBrowse::LoadDir(const char *dir)
143 Status(tr("Scanning directory..."));
144 bool res=list->Load(source,dir,excl);
146 cFileObj *item=list->First();
148 Add(new cMenuBrowseItem(item),(parent && !strcmp(item->Name(),parent)));
149 item=list->Next(item);
156 bool cMenuBrowse::NewDir(const char *dir)
158 char *ncur=dir ? strdup(dir):0;
159 bool r=LoadDir(ncur);
165 free(currentdir); currentdir=ncur;
167 cFileObj *item=CurrentItem();
168 source->SetRemember(currentdir,item?item->Name():0);
174 Error(tr("Error scanning directory!"));
178 eOSState cMenuBrowse::Parent(void)
180 eOSState res=osContinue;
184 char *ss=strrchr(currentdir,'/');
190 else parent=strdup(currentdir);
192 if(!NewDir(ss)) res=osEnd;
197 eOSState cMenuBrowse::Select(bool isred)
199 eOSState res=osContinue;
202 if((item=CurrentItem())) {
203 switch(item->Type()) {
205 if(!isred || !dirselectable)
209 if(!isred || !dirselectable) {
210 if(!NewDir(item->Path())) res=osEnd;
213 // fall through to otFile
215 lastselect=new cFileObj(item);
225 eOSState cMenuBrowse::ID3Info(void)
230 eOSState cMenuBrowse::ProcessStdKey(eKeys Key, eOSState state)
232 if(state==osUnknown) {
234 case kOk: state=Select(false); break;
235 case kRed: state=Select(true); break;
236 case kGreen: state=Parent(); break;
237 case kBlue: if(withID3) state=ID3Info();
239 //case kMenu: state=osEnd; break;
243 if(state==osEnd || state==osBack) {
244 cFileObj *item=CurrentItem();
245 if(item) source->SetRemember(currentdir,item->Name());
250 // --- cMenuSourceItem ----------------------------------------------------------
252 class cMenuSourceItem : public cOsdItem {
255 virtual void Set(void);
257 cMenuSourceItem(cFileSource *Source);
258 cFileSource *Source(void) { return source; }
261 cMenuSourceItem::cMenuSourceItem(cFileSource *Source)
267 void cMenuSourceItem::Set(void)
270 asprintf(&buffer, "%s\t%s\t%s", source->NeedsMount()?(source->Status()?"*":">"):"", source->Description(), source->BaseDir());
271 SetText(buffer,false);
274 // --- cMenuSource --------------------------------------------------
276 cFileSource *cMenuSource::selected=0;
278 cMenuSource::cMenuSource(cFileSources *Sources, const char *title)
279 :cOsdMenu(title,2,20)
282 current=Sources->GetSource();
283 cFileSource *source=Sources->First();
285 cOsdMenu::Add(new cMenuSourceItem(source),source==current);
286 source=Sources->Next(source);
289 SetHelp(tr("Select"), tr("Mount"), tr("Unmount"), tr("Eject"));
293 bool cMenuSource::DoMount(cFileSource *src)
295 bool res=src->Mount();
297 DisplayCurrent(true);
301 bool cMenuSource::CheckMount(void)
303 cFileSource *src=selected ? selected:current;
304 if(src->NeedsMount() && !src->Status()) {
305 Error(tr("Selected source is not mounted!"));
311 eOSState cMenuSource::Select(void)
313 if(HasSubMenu() || Count() == 0) return osContinue;
315 cFileSource *src = ((cMenuSourceItem *)Get(Current()))->Source();
316 if(src->NeedsMount() && !src->Status()) {
317 if(!DoMount(src)) Error(tr("Mount failed!"));
319 if(!src->NeedsMount() || src->Status()) {
326 eOSState cMenuSource::Mount(void)
328 if(HasSubMenu() || Count() == 0) return osContinue;
330 cFileSource *src = ((cMenuSourceItem *)Get(Current()))->Source();
331 if(src->NeedsMount() && !src->Status()) {
332 if(DoMount(src)) Info(tr("Mount succeeded"));
333 else Error(tr("Mount failed!"));
338 eOSState cMenuSource::Unmount(void)
340 if(HasSubMenu() || Count() == 0) return osContinue;
342 cFileSource *src = ((cMenuSourceItem *)Get(Current()))->Source();
343 if(src->NeedsMount() && src->Status()) {
344 bool res=src->Unmount();
346 DisplayCurrent(true);
347 if(res) Info(tr("Unmount succeeded"));
348 else Error(tr("Unmount failed!"));
353 eOSState cMenuSource::Eject(void)
355 if(HasSubMenu() || Count() == 0) return osContinue;
357 cFileSource *src = ((cMenuSourceItem *)Get(Current()))->Source();
358 if(src->NeedsMount()) {
359 bool res=src->Eject();
361 DisplayCurrent(true);
362 if(!res) Error(tr("Eject failed!"));
367 eOSState cMenuSource::ProcessKey(eKeys Key)
369 eOSState state = cOsdMenu::ProcessKey(Key);
371 if(state==osBack && !CheckMount()) state=osContinue;
372 if(state==osUnknown) {
375 case kRed: return Select();
376 case kGreen: return Mount();
377 case kYellow: return Unmount();
378 case kBlue: return Eject();
379 case kMenu: CheckMount(); return osEnd;
386 // --- cProgressBar ------------------------------------------------------------
388 cProgressBar::cProgressBar(int Width, int Height, int Current, int Total)
389 :cBitmap(Width, Height, 2)
392 int p = Current * Width / Total;;
393 #if APIVERSNUM >= 10307
394 DrawRectangle(0, 0, p, Height - 1, clrGreen);
395 DrawRectangle(p + 1, 0, Width - 1, Height - 1, clrWhite);
397 Fill(0, 0, p, Height - 1, clrGreen);
398 Fill(p + 1, 0, Width - 1, Height - 1, clrWhite);