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)
75 asprintf(&buffer,item->Type()==otFile?"%s":"[%s]",item->Name());
76 SetText(buffer,false);
79 // --- cMenuBrowse ------------------------------------------------------
81 cFileObj *cMenuBrowse::lastselect=0;
83 cMenuBrowse::cMenuBrowse(cFileSource *Source, bool Dirselect, bool WithID3, const char *title, const char * const *Excl)
87 delete lastselect; lastselect=0;
90 dirselectable=Dirselect;
98 cMenuBrowse::~cMenuBrowse()
105 cFileObj *cMenuBrowse::CurrentItem(void)
107 cMenuBrowseItem *item = (cMenuBrowseItem *)Get(Current());
108 return item ? item->Item():0;
111 void cMenuBrowse::SetButtons(void)
113 SetHelp(tr("Select"), currentdir?tr("Parent"):0, 0, withID3?tr("ID3 info"):0);
117 void cMenuBrowse::SetSource(cFileSource *Source)
120 free(currentdir); currentdir=0;
121 free(parent); parent=0;
122 source->GetRemember(currentdir,parent);
125 bool cMenuBrowse::LoadDir(const char *dir)
128 Status(tr("Scanning directory..."));
129 bool res=list->Load(source,dir,excl);
131 cFileObj *item=list->First();
133 Add(new cMenuBrowseItem(item),(parent && !strcmp(item->Name(),parent)));
134 item=list->Next(item);
141 bool cMenuBrowse::NewDir(const char *dir)
143 char *ncur=dir ? strdup(dir):0;
144 bool r=LoadDir(ncur);
150 free(currentdir); currentdir=ncur;
152 cFileObj *item=CurrentItem();
153 source->SetRemember(currentdir,item?item->Name():0);
159 Error(tr("Error scanning directory!"));
163 eOSState cMenuBrowse::Parent(void)
165 eOSState res=osContinue;
169 char *ss=strrchr(currentdir,'/');
175 else parent=strdup(currentdir);
177 if(!NewDir(ss)) res=osEnd;
182 eOSState cMenuBrowse::Select(bool isred)
184 eOSState res=osContinue;
187 if((item=CurrentItem())) {
188 switch(item->Type()) {
190 if(!isred || !dirselectable)
194 if(!isred || !dirselectable) {
195 if(!NewDir(item->Path())) res=osEnd;
198 // fall through to otFile
200 lastselect=new cFileObj(item);
210 eOSState cMenuBrowse::ID3Info(void)
215 eOSState cMenuBrowse::ProcessStdKey(eKeys Key, eOSState state)
217 if(state==osUnknown) {
219 case kOk: state=Select(false); break;
220 case kRed: state=Select(true); break;
221 case kGreen: state=Parent(); break;
222 case kBlue: if(withID3) state=ID3Info();
224 //case kMenu: state=osEnd; break;
228 if(state==osEnd || state==osBack) {
229 cFileObj *item=CurrentItem();
230 if(item) source->SetRemember(currentdir,item->Name());
235 // --- cMenuSourceItem ----------------------------------------------------------
237 class cMenuSourceItem : public cOsdItem {
240 virtual void Set(void);
242 cMenuSourceItem(cFileSource *Source);
243 cFileSource *Source(void) { return source; }
246 cMenuSourceItem::cMenuSourceItem(cFileSource *Source)
252 void cMenuSourceItem::Set(void)
255 asprintf(&buffer, "%s\t%s\t%s", source->NeedsMount()?(source->Status()?"*":">"):"", source->Description(), source->BaseDir());
256 SetText(buffer,false);
259 // --- cMenuSource --------------------------------------------------
261 cFileSource *cMenuSource::selected=0;
263 cMenuSource::cMenuSource(cFileSources *Sources, const char *title)
264 :cOsdMenu(title,2,20)
267 current=Sources->GetSource();
268 cFileSource *source=Sources->First();
270 cOsdMenu::Add(new cMenuSourceItem(source),source==current);
271 source=Sources->Next(source);
274 SetHelp(tr("Select"), tr("Mount"), tr("Unmount"), tr("Eject"));
278 bool cMenuSource::DoMount(cFileSource *src)
280 bool res=src->Mount();
282 DisplayCurrent(true);
286 bool cMenuSource::CheckMount(void)
288 cFileSource *src=selected ? selected:current;
289 if(src->NeedsMount() && !src->Status()) {
290 Error(tr("Selected source is not mounted!"));
296 eOSState cMenuSource::Select(void)
298 if(HasSubMenu() || Count() == 0) return osContinue;
300 cFileSource *src = ((cMenuSourceItem *)Get(Current()))->Source();
301 if(src->NeedsMount() && !src->Status()) {
302 if(!DoMount(src)) Error(tr("Mount failed!"));
304 if(!src->NeedsMount() || src->Status()) {
311 eOSState cMenuSource::Mount(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)) Info(tr("Mount succeeded"));
318 else Error(tr("Mount failed!"));
323 eOSState cMenuSource::Unmount(void)
325 if(HasSubMenu() || Count() == 0) return osContinue;
327 cFileSource *src = ((cMenuSourceItem *)Get(Current()))->Source();
328 if(src->NeedsMount() && src->Status()) {
329 bool res=src->Unmount();
331 DisplayCurrent(true);
332 if(res) Info(tr("Unmount succeeded"));
333 else Error(tr("Unmount failed!"));
338 eOSState cMenuSource::Eject(void)
340 if(HasSubMenu() || Count() == 0) return osContinue;
342 cFileSource *src = ((cMenuSourceItem *)Get(Current()))->Source();
343 if(src->NeedsMount()) {
344 bool res=src->Eject();
346 DisplayCurrent(true);
347 if(!res) Error(tr("Eject failed!"));
352 eOSState cMenuSource::ProcessKey(eKeys Key)
354 eOSState state = cOsdMenu::ProcessKey(Key);
356 if(state==osBack && !CheckMount()) state=osContinue;
357 if(state==osUnknown) {
360 case kRed: return Select();
361 case kGreen: return Mount();
362 case kYellow: return Unmount();
363 case kBlue: return Eject();
364 case kMenu: CheckMount(); return osEnd;
371 // --- cProgressBar ------------------------------------------------------------
373 cProgressBar::cProgressBar(int Width, int Height, int Current, int Total)
374 :cBitmap(Width, Height, 2)
377 int p = Current * Width / Total;;
378 DrawRectangle(0, 0, p, Height - 1, clrGreen);
379 DrawRectangle(p + 1, 0, Width - 1, Height - 1, clrWhite);