2 Copyright 2004-2005 Chris Tallon, Andreas Vogel
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP 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 VOMP. If not, see <https://www.gnu.org/licenses/>.
21 Hints for the directory playing:
22 depending on the configValue directoryMode: none|audio|picture|count
23 it will be decided what to do if a directory is selected with [PLAY]:
24 none: as currently - simply go into
25 audio: start picture viewer and audio, audio on top
26 picture: start picture viewer and audio, picture on top
27 count: count occurence of both types, decide for audio/picture
28 Synchronization is done via the "directoryDone" call,
29 this is issued if the Viewer top engine has finished it's list
31 We will the go back one level and continue
32 Currently we will traverse to new directories only at the beginning
33 or the real end of each dir.
34 This is handled only by playAll (never by getMedia).
35 As we sort always in a way that all directories come first this should be OK.
36 there are 2 situations where we give the user a chance to interrupt (this is handled
37 by starting a 10ms timer and afterwrads sending a PLAYER_EVENT with the timer ref as
39 empty directory found - timer 1 - call directoryDone
40 after changing to a new directory the first entry is again a directory - timer 2 - playAll
42 directoryPlaying: globally set as long as we play a dir, reset on any key press here
43 startLevel: in DirList - set to the level where we started playing, if we are
44 back to this playing is finished
45 configuredDirmode: configured mode
57 #include "vmedialist.h"
59 #include "vmediaview.h"
60 #include "vvideomedia.h"
68 #include "messagequeue.h"
71 #include "mediaplayer.h"
73 #include "localmediafile.h"
74 #include "mediaoptions.h"
77 class MediaListHolder {
79 MediaListHolder(MediaList *l) {
88 Log::getInstance()->log("##MLH",Log::DEBUG,"ref %p now %d",_list,_ref);
92 Log::getInstance()->log("##MLH",Log::DEBUG,"unref %p now %d",_list,_ref);
93 if (_ref == 0) delete this;
96 if (_list) delete _list;
103 class MediaDirectory {
109 MediaListHolder *holder;
111 void setMediaType(ULONG n) {mtype=n;}
112 void setSortorder(int s) {
115 void setSelection(int s) {
121 bool move(ULONG mv) {
122 if (! holder) return false;
124 case VMediaList::MV_NEXT:
125 if (selection < ((int)holder->list()->size() -1)) {
130 case VMediaList::MV_PREV:
140 ULONG getMediaType(){return mtype;}
144 const MediaURI * getURI() {
147 const char * getDisplayName() {
148 if (! uri || ! uri->getDisplayName()) return "/";
149 return uri->getDisplayName();
151 //get the holder (increment refcount)
152 MediaListHolder *getHolder() {
153 if ( !holder) return NULL;
157 //assign a holder to the directory (auto ref)
158 void assignHolder(MediaListHolder *h) {
159 if (holder) holder->unref();
165 //constructor with copy!
166 MediaDirectory(const MediaURI *u) : selection(0),
167 sortorder(0),mtype(MEDIA_TYPE_ALL),holder(NULL){
173 MediaDirectory(MediaDirectory &c) {
174 setSelection(c.getSelection());
175 setMediaType(c.getMediaType());
176 setSortorder(c.getSortorder());
177 uri=new MediaURI(c.getURI());
178 holder=c.getHolder();
182 if (holder) holder->unref();
186 typedef std::vector<MediaDirectory*> MDirList;
196 list.push_back(new MediaDirectory(NULL));
198 DirList(DirList *cp) {
200 for (MDirList::iterator it=cp->list.begin();it<cp->list.end();it++) {
201 list.push_back(new MediaDirectory(*(*it)));
205 list.push_back(new MediaDirectory(NULL));
208 startlevel=cp->startlevel;
209 if (startlevel > current) startlevel=current;
212 MDirList::iterator it;
213 for (it=list.begin();it<list.end();it++) {
217 MediaDirectory *getCurrent() {
218 return list[current];
220 const MediaURI * getURI() {
221 return getCurrent()->getURI();
231 int append(const MediaURI *uri) {
232 if (! uri) return current;
233 MediaDirectory* md=new MediaDirectory(uri);
242 void setStartLevel() {
245 bool isOnStartLevel() {
246 return (startlevel == current);
252 class MediaSorterName
255 bool operator() (const Media* a, const Media* b)
257 if (b->getMediaType() == MEDIA_TYPE_DIR &&
258 a->getMediaType() != MEDIA_TYPE_DIR)
260 if ( b->getMediaType() != MEDIA_TYPE_DIR &&
261 a->getMediaType() == MEDIA_TYPE_DIR)
263 int c = strcmp(b->getFileName(), a->getFileName());
264 if (c > 0) return true;
269 //a sorter with a randomly initialized order
270 class MediaSorterRandom
273 MediaSorterRandom(int start) {
276 bool operator() (const Media* a, const Media* b)
278 if (b->getMediaType() == MEDIA_TYPE_DIR &&
279 a->getMediaType() != MEDIA_TYPE_DIR)
281 if ( b->getMediaType() != MEDIA_TYPE_DIR &&
282 a->getMediaType() == MEDIA_TYPE_DIR)
284 unsigned char suma=sum(a->getFileName(),(unsigned char)mystart);
285 unsigned char sumb=sum(b->getFileName(),(unsigned char)mystart);
286 if (sumb > suma) return true;
290 unsigned char sum(const char *name,unsigned char start) {
291 for (;*name!=0;name++) start=start ^ (unsigned char)*name;
298 struct MediaSorterTime
300 bool operator() (const Media* a, const Media* b)
302 if (b->getMediaType() == MEDIA_TYPE_DIR &&
303 a->getMediaType() != MEDIA_TYPE_DIR)
305 if ( b->getMediaType() != MEDIA_TYPE_DIR &&
306 a->getMediaType() == MEDIA_TYPE_DIR)
308 if (b->getTime()>a->getTime()) return true;
314 VMediaList::VMediaList()
316 boxstack = BoxStack::getInstance();
318 Log::getInstance()->log("VMediaList::VMediaList", Log::DEBUG, "start");
319 dirlist=new DirList();
321 Log::getInstance()->log("VMediaList::VMediaList", Log::DEBUG, "dirlist=%p,curren=%p",dirlist,dirlist->getCurrent());
322 dirlist->getCurrent()->setSortorder(SORT_NAME);
325 if (Video::getInstance()->getFormat() == Video::PAL)
331 setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
333 sl.setPosition(10, 30 + 5);
334 sl.setSize(area.w - 20, area.h - 30 - 15 - 30);
343 const char *dmstring=MediaOptions::getInstance()->getStringOption("DirectoryPlayMode");
345 if (strcmp(dmstring,"count") == 0) dirmode=M_COUNT;
346 else if (strcmp(dmstring,"audio") == 0) dirmode=M_AUDIO;
347 else if (strcmp(dmstring,"picture") == 0) dirmode=M_PICTURE;
350 //init additional providers
352 LocalMediaFile::init();
354 MessageQueue::getInstance()->addReceiver(this);
358 VMediaList::~VMediaList()
360 MessageQueue::getInstance()->removeReceiver(this);
361 Log::getInstance()->log("VMediaList::~VMediaList", Log::DEBUG, "start");
362 Timers::getInstance()->cancelTimer(this,1);
363 Timers::getInstance()->cancelTimer(this,2);
366 if (audiodirlist) delete audiodirlist;
367 Log::getInstance()->log("VMediaList::~VMediaList", Log::DEBUG, "finished");
370 void VMediaList::removeViewer() {
372 BoxStack::getInstance()->remove(viewer);
377 VMediaView * VMediaList::getViewer() {
379 viewer=VMediaView::createViewer(this);
385 void VMediaList::playAudio(bool all,bool activate, bool showInfo) {
386 MediaListHolder *h=dirlist->getCurrent()->getHolder();
388 VMediaView *player=getViewer();
389 //OK make a copy of the current active list for audio playing
390 if (audiodirlist) delete audiodirlist;
391 audiodirlist=new DirList(dirlist);
392 player->play(all,activate,MV_NONE,showInfo);
396 void VMediaList::updateAll() {
397 BoxStack::getInstance()->update(this);
398 if (viewer) BoxStack::getInstance()->update(viewer);
399 BoxStack::getInstance()->update(NULL);
405 int VMediaList::getNumEntries(ULONG mediaType,int lowerThen,bool noAudioList) {
406 MediaListHolder *h=dirlist->getCurrent()->getHolder();
407 Log::getInstance()->log("VMediaList",Log::DEBUG,"getNumEntries type=%lu,lt=%d,na=%d,h=%p,l=%p",
408 mediaType,lowerThen,(int)noAudioList,h,(h?h->list():0));
410 if (mediaType == MEDIA_TYPE_ALL && lowerThen < 0) {
412 return h->list()->size();
414 if (lowerThen < 0) lowerThen=h->list()->size();
416 MediaList *ml=h->list();
418 if (mediaType == MEDIA_TYPE_AUDIO) {
419 //OK we look into the separate audiolist (if we have it...)
420 if (audiodirlist && ! noAudioList) {
421 MediaListHolder *ah=audiodirlist->getCurrent()->getHolder();
428 for (int i=0;i<(int)(ml->size()) && i <= lowerThen;i++) {
429 if ((*ml)[i]->getMediaType() & mediaType) rt++;
434 void VMediaList::setList(MediaListHolder* tlist)
436 dirlist->getCurrent()->assignHolder(tlist);
438 sortList(dirlist->getCurrent()->getSortorder());
439 updateSelectList(dirlist->getCurrent()->getSelection());
443 void VMediaList::updateSelectList(){
444 updateSelectList(-1);
446 void VMediaList::updateSelectList(int currentNumber){
447 MediaListHolder *h=dirlist->getCurrent()->getHolder();
449 char tempA[Media::TIMEBUFLEN];
450 Log::getInstance()->log("VMediaList::updateSelectList", Log::DEBUG, "media=%p",h);
453 ULONG currentSelection=0;
454 if (sl.getNumOptions() >= 1 && currentNumber < 0) {
455 currentSelection=sl.getCurrentOptionData();
463 for (UINT i = 0; i < h->list()->size(); i++)
465 media = (*h->list())[i];
466 if (media->getMediaType() == MEDIA_TYPE_DIR) {
467 sprintf(str, "%04u %s [%s]", i,media->getTimeString(tempA), media->getDisplayName());
468 //Log::getInstance()->log("VMediaList", Log::DEBUG, "add to select list %s",str);
469 media->index = sl.addOption(str, (ULONG)media, first);
472 sprintf(str, "%04u %s %s", i,media->getTimeString(tempA), media->getDisplayName());
473 //Log::getInstance()->log("VMediaList", Log::DEBUG, "add to select list %s",str);
474 media->index = sl.addOption(str, (ULONG)media, first);
479 if (currentNumber >= 0) sl.hintSetCurrent(currentNumber);
480 else sl.hintSetCurrent(0);
481 if (currentSelection != 0) {
483 //position to the previous selection
484 for (int i=0;i<sl.getNumOptions();i++) {
485 sl.hintSetCurrent(i);
486 if (sl.getCurrentOptionData() == currentSelection) {
491 if (! found) sl.hintSetCurrent(0);
494 if (sl.getNumOptions() > 0)
501 void VMediaList::draw()
503 Log::getInstance()->log("VMediaList::draw", Log::DEBUG, "namestr=%s",dirlist->getCurrent()->getDisplayName());
505 SNPRINTF(title, 398, tr("Media - %s"), dirlist->getCurrent()->getDisplayName());
511 sl.setVisible(false);
513 drawText(tr("Loading..."), 240, 180, DrawStyle::LIGHTTEXT);
517 //if (sl.getNumOptions() > 0) sl.draw();
521 // Put the status stuff at the bottom
526 w.nextSymbol = WSymbol::UP;
527 w.setPosition(20, 385);
530 w.nextSymbol = WSymbol::DOWN;
531 w.setPosition(50, 385);
534 w.nextSymbol = WSymbol::SKIPBACK;
535 w.setPosition(85, 385);
538 w.nextSymbol = WSymbol::SKIPFORWARD;
539 w.setPosition(115, 385);
542 w.nextSymbol = WSymbol::PLAY;
543 w.setPosition(150, 385);
550 void VMediaList::doShowingBar()
552 int topOption = sl.getTopOption() + 1;
553 if (sl.getNumOptions() == 0) topOption = 0;
556 const char* strmode=NULL;
568 SNPRINTF(showing, 250,tr("%i to %i of %i"),
569 topOption, sl.getBottomOption(), sl.getNumOptions());
572 // b.setSurfaceOffset(220, 385);
573 // b.setDimensions(160, 25);
574 // b.fillColour(DrawStyle::VIEWBACKGROUND);
575 // b.drawText(showing, 0, 0, DrawStyle::LIGHTTEXT);
577 rectangle(200, 384, 18, 16, DrawStyle::VIDEOBLUE);
578 rectangle(220, 385, 220+160, 385+25, DrawStyle::VIEWBACKGROUND);
579 drawText(strmode, 220, 385, DrawStyle::LIGHTTEXT);
580 drawText(showing, 280, 385, DrawStyle::LIGHTTEXT);
581 if (sl.getCurrentOptionData() != 0) Log::getInstance()->log("VMediaList",Log::DEBUG,"selected %s",((Media *)sl.getCurrentOptionData())->getDisplayName());
584 //find the next entry in the media list
585 //return the index in the list (starting with 0)
586 //return -1 if none found
587 int VMediaList::findNextEntry(int current, MediaList *list,ULONG ltype, ULONG move,bool wrap) {
588 if (! list) return -1;
589 if (current < 0) current=0;
590 if (current >= (int)list->size()) current=list->size()-1;
614 if (next >= (int)list->size()) {
622 if (next == current && move != MV_NONE) {
625 if (((*list)[next])->getMediaType() != ltype) {
639 Media * VMediaList::getMedia(ULONG ltype,ULONG move) {
641 MediaList *list=NULL;
642 MediaListHolder *h=NULL;
643 Log::getInstance()->log("VMediaList",Log::DEBUG,"getMedia, t=%lu, mv=%lu",ltype,move);
645 //the currently active one (dirlist->getCurrent()->getHolder())
646 //and potentially a second one for audio (audiolist)
647 //currently (no recursive playing) we should always have an attached medialist in the audiolist
648 if (ltype == MEDIA_TYPE_AUDIO && audiodirlist != NULL ) {
649 h=audiodirlist->getCurrent()->getHolder();
651 Log::getInstance()->log("VMediaList",Log::ERR,"getMedia AUDIO empty medialist");
654 int nentry=findNextEntry(audiodirlist->getCurrent()->getSelection(),h->list(),ltype,move,false);
656 Log::getInstance()->log("VMediaList",Log::DEBUG,"getMedia AUDIO no next entry");
660 audiodirlist->getCurrent()->setSelection(nentry);
662 rt=new Media((*list)[nentry]);
664 Log::getInstance()->log("VMediaList",Log::DEBUG,"getMedia AUDIO next entry %d",nentry);
667 h=dirlist->getCurrent()->getHolder();
669 Log::getInstance()->log("VMediaList",Log::ERR,"getMedia PICTURE empty medialist");
672 int nentry=findNextEntry(dirlist->getCurrent()->getSelection(),h->list(),ltype,move,false);
674 Log::getInstance()->log("VMediaList",Log::DEBUG,"getMedia type=%lu no next entry",ltype);
678 Log::getInstance()->log("VMediaList",Log::DEBUG,"getMedia type=%lu next entry %d",ltype,nentry);
679 dirlist->getCurrent()->setSelection(nentry);
680 updateSelection(true);
683 rt=new Media((*list)[nentry]);
685 if (! rt->getURI()) {
686 MediaURI *uri=list->getURI(rt);
693 void VMediaList::updateSelection(bool toSelectList) {
695 dirlist->getCurrent()->setSelection(sl.getCurrentOption());
697 sl.hintSetCurrent(dirlist->getCurrent()->getSelection());
702 Media * VMediaList::getCurrentMedia(DirList *dl) {
703 if (! dl) return NULL;
704 MediaDirectory *d=dirlist->getCurrent();
705 if (! d) return NULL;
706 MediaListHolder *h=d->getHolder();
707 if (! h) return NULL;
708 if (d->getSelection() < 0 || d->getSelection() >= (int)h->list()->size()) return NULL;
709 Media *rt= (*h->list())[d->getSelection()];
715 int VMediaList::handleCommand(int command)
722 sl.hintSetCurrent(0);
726 boxstack->update(this);
727 return BoxStack::COMMAND_HANDLED;
736 boxstack->update(this);
737 return BoxStack::COMMAND_HANDLED;
746 boxstack->update(this);
747 return BoxStack::COMMAND_HANDLED;
749 case Input::SKIPBACK:
756 boxstack->update(this);
757 return BoxStack::COMMAND_HANDLED;
759 case Input::SKIPFORWARD:
766 boxstack->update(this);
767 return BoxStack::COMMAND_HANDLED;
774 boxstack->update(this);
775 return BoxStack::COMMAND_HANDLED;
777 sortList(SORT_RANDOM);
778 boxstack->update(this);
779 return BoxStack::COMMAND_HANDLED;
782 boxstack->update(this);
783 return BoxStack::COMMAND_HANDLED;
790 if (dirlist) media = getCurrentMedia(dirlist);
791 if (media == NULL) return BoxStack::COMMAND_HANDLED;
792 Log::getInstance()->log("VMediaList", Log::DEBUG, "activated %lu", media->index);
793 switch(media->getMediaType())
798 Log::getInstance()->log("VMediaList", Log::DEBUG, "create child for %s",media->getFileName());
799 if (media->getFileName() == NULL ) return BoxStack::COMMAND_HANDLED;
800 if (command == Input::PLAY) {
801 dirlist->setStartLevel();
804 bool rt=changeDirectory(media);
805 if (command == Input::PLAY && rt) {
813 case MEDIA_TYPE_AUDIO:
814 Log::getInstance()->log("VMediaList", Log::DEBUG, "play audio file %s",
815 media->getFileName());
816 if (dirmode != M_NONE && command == Input::PLAY)
819 playAudio(command==Input::PLAY,true,true);
821 case MEDIA_TYPE_VIDEO: {
822 #ifndef WIN32 //Only DVB style MPEG is supported by the Windows Part!
823 Log::getInstance()->log("VMediaList", Log::DEBUG, "play video file %s",
824 media->getFileName());
826 if (! media->getURI()) {
828 MediaListHolder *h=dirlist->getCurrent()->getHolder();
830 Log::getInstance()->log("VMediaList", Log::ERR, "no media List");
833 MediaURI *u=h->list()->getURI(media);
839 VVideoMedia *v=new VVideoMedia(media,this);
840 BoxStack::getInstance()->add(v);
841 BoxStack::getInstance()->update(v);
846 case MEDIA_TYPE_PICTURE:
847 Log::getInstance()->log("VMediaList", Log::DEBUG, "show picture file %s",
848 media->getFileName());
849 if (dirmode != M_NONE && command == Input::PLAY)
852 getViewer()->showPicture(MV_NONE,command==Input::PLAY,true);
855 Log::getInstance()->log("VMediaList", Log::DEBUG, "unknown media type %d file %s",
856 media->getMediaType(),media->getFileName());
860 VVideoLive* v = new VVideoLive(dirlist->getCurrent()->getHolder(), media->type, this);
866 v->medianelChange(VVideoLive::NUMBER, media->number);
869 return BoxStack::COMMAND_HANDLED;
873 if (dirlist->getLevel() < 1) return BoxStack::DELETE_ME;
878 // stop command getting to any more views
879 return BoxStack::ABANDON_COMMAND;
882 //go to the next level dir
883 //if OK - delete current medialist
884 bool VMediaList::changeDirectory(Media *media) {
885 Log::getInstance()->log("VMediaList",Log::DEBUG,"cd to %s",media->getFileName());
887 dirlist->getCurrent()->setSortorder(sortOrder);
888 if (dirlist->getLevel() > 200) {
889 Log::getInstance()->log("VMediaList",Log::ERR,"above 300 levels, stop here...");
892 MediaListHolder *h=dirlist->getCurrent()->getHolder();
893 dirlist->getCurrent()->assignHolder(NULL); //prepare old holder for deletion
897 MediaURI *uri=h->list()->getURI(media);
898 dirlist->append(uri);
900 //same sort order for next level
901 dirlist->getCurrent()->setSortorder(sortOrder);
904 h->unref(); //this deletes now the old list
905 Log::getInstance()->log("VMediaList",Log::DEBUG,"cd OK");
908 //we were no able to load the new list - so go back to our current list
910 dirlist->getCurrent()->assignHolder(h); //OK so we saved our list...
912 Log::getInstance()->log("VMediaList",Log::DEBUG,"cd failed");
916 void VMediaList::directoryDone() {
917 if (! playingAll) return;
918 //go up until we are on the startlevel
919 Log::getInstance()->log("VMediaList", Log::DEBUG, "DirectoryDone ");
920 while ( ! dirlist->isOnStartLevel()) {
923 if (dirlist->isOnStartLevel()) break;
924 if (dirlist->getCurrent()->move(MV_NEXT))
927 if ( dirlist->isOnStartLevel()) {
930 Log::getInstance()->log("VMediaList", Log::DEBUG, "finished playing all l=%lu",dirlist->getLevel());
933 updateSelection(true);
937 bool VMediaList::playAll() {
938 if (dirmode == M_NONE) return false;
942 dirlist->setStartLevel();
946 Media *media=getCurrentMedia(dirlist);
949 Log::getInstance()->log("VMediaList", Log::DEBUG, "empty dir when calling playall");
951 Timers::getInstance()->setTimerD(this,1,0,10000000l); //10ms
954 Media *mcopy=new Media(media);
955 Log::getInstance()->log("VMediaList", Log::DEBUG, "playing all name=%s,t=%lu, started=%d",
956 mcopy->getDisplayName(),mcopy->getMediaType(),(int)started);
957 while (mcopy->getMediaType()==MEDIA_TYPE_DIR) {
958 //recurse to the next directory
959 bool rt=changeDirectory(mcopy);
961 //OK succesfully changed dir
962 int entries=getNumEntries(MEDIA_TYPE_AUDIO|MEDIA_TYPE_DIR|MEDIA_TYPE_PICTURE);
963 Log::getInstance()->log("VMediaList", Log::DEBUG, "cd OK, entries=%d",entries);
964 media=getCurrentMedia(dirlist);
965 if (entries==0 || media == NULL) {
966 Log::getInstance()->log("VMediaList", Log::DEBUG, "playing all name=%s empty",mcopy->getDisplayName());
968 //trigger directory end with the ability of user intervention
969 Timers::getInstance()->setTimerD(this,1,0,10000000l); //10ms
974 if (media->getMediaType()==MEDIA_TYPE_DIR) {
975 //send a defered event to give the user a chance to interrupt
976 //will again call playAll (but this does not chage the start level)
977 Timers::getInstance()->setTimerD(this,2,0,10000000l); //10ms
984 //unable to change to the directory
985 if (dirlist->getCurrent()->move(MV_NEXT)) {
986 //OK there is still a next medium here
987 updateSelection(true);
988 media=getCurrentMedia(dirlist);
990 Timers::getInstance()->setTimerD(this,1,0,10000000l); //10ms
994 mcopy=new Media(media);
997 //hmm - no entries here any more
1004 Log::getInstance()->log("VMediaList", Log::DEBUG, "playing all on level %d, sele=%d",
1005 dirlist->getLevel(),dirlist->getCurrent()->getSelection());
1007 enum Dirmode currentMode=dirmode;
1008 //OK now we handled all directories - now deal with the current one
1009 //1st determine the number of entries
1010 int aentries=getNumEntries(MEDIA_TYPE_AUDIO,-1,true);
1011 int pentries=getNumEntries(MEDIA_TYPE_PICTURE,-1,true);
1012 if (aentries == 0 && pentries == 0) {
1016 if (currentMode == M_COUNT) {
1017 if (aentries > pentries) currentMode=M_AUDIO;
1018 else currentMode=M_PICTURE;
1020 Log::getInstance()->log("VMediaList", Log::DEBUG, "mode=%d,ae=%d,pe=%d",currentMode,aentries,pentries);
1021 //now find the matching entries and start playing
1022 MediaListHolder *h=dirlist->getCurrent()->getHolder();
1024 Log::getInstance()->log("VMediaList", Log::ERR, "playing all empty medialist");
1029 Media *mpicture=NULL;
1030 int audioselection=-1;
1031 int pictureselection=-1;
1032 for (int i=dirlist->getCurrent()->getSelection();i<(int)h->list()->size();i++) {
1033 Media *m=(*h->list())[i];
1034 if (m->getMediaType() == MEDIA_TYPE_AUDIO && maudio == NULL) {
1038 if (m->getMediaType() == MEDIA_TYPE_PICTURE && mpicture == NULL) {
1042 if (maudio != NULL && mpicture != NULL) break;
1044 //OK now we found the first media for both - start players
1045 if (maudio != NULL) {
1046 dirlist->getCurrent()->setSelection(audioselection);
1047 playAudio(true,currentMode==M_AUDIO,mpicture==NULL); //this makes now a copy of dirlist...
1049 if (mpicture != NULL) {
1050 dirlist->getCurrent()->setSelection(pictureselection);
1051 getViewer()->showPicture(MV_NONE,true,currentMode==M_PICTURE);
1054 updateSelection(true);
1065 void VMediaList::processMessage(Message* m)
1067 if (m->message == Message::MOUSE_MOVE)
1069 if (sl.mouseMove(m->parameter - getScreenX(), m->tag - getScreenY()))
1073 boxstack->update(this);
1077 else if (m->message == Message::MOUSE_LBDOWN)
1079 if (sl.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
1082 Input::sendInputKey(Input::OK);
1084 else if (coordsOutsideBox(m))
1086 Input::sendInputKey(Input::BACK);
1089 else if (m->message == Message::PLAYER_EVENT) {
1090 switch (m->parameter) {
1101 int VMediaList::createList() {
1102 Log::getInstance()->log("VMediaList::createList", Log::DEBUG, "");
1103 VMediaList *vmn=new VMediaList();
1104 //show the "loading" indicator
1105 BoxStack::getInstance()->add(vmn);
1108 BoxStack::getInstance()->remove(vmn);
1113 void VMediaList::sortList(int newSort) {
1114 MediaListHolder *h=dirlist->getCurrent()->getHolder();
1116 Log::getInstance()->log("VMediaList::sortList", Log::DEBUG, "p=%p,sort=%d,osort=%d, size=%d",this,newSort,sortOrder,h->list()->size());
1117 if (sortOrder == newSort) return;
1118 if (h->list()->begin() != h->list()->end()) {
1121 ::sort(h->list()->begin(),h->list()->end(),MediaSorterTime());
1124 ::sort(h->list()->begin(),h->list()->end(),MediaSorterName());
1127 ::sort(h->list()->begin(),h->list()->end(),MediaSorterRandom(time(NULL)));
1134 Log::getInstance()->log("VMediaList::sortList", Log::DEBUG, "done ");
1138 int VMediaList::load() {
1142 boxstack->update(this);
1143 MediaPlayer * mp=MediaPlayer::getInstance();
1144 Log::getInstance()->log("VMediaList::load", Log::DEBUG, "load list for %p",dirlist->getURI());
1145 MediaDirectory *md=dirlist->getCurrent();
1148 mn=mp->getMediaList(md->getURI());
1151 mn=mp->getRootList();
1154 MediaListHolder *h=new MediaListHolder(mn);
1159 boxstack->update(this);
1163 Log::getInstance()->log("VMediaList", Log::ERR, "unable to get MediaList for %p",dirlist->getURI());
1165 VInfo* vi = new VInfo();
1166 vi->setSize(400, 150);
1170 vi->setTitleBarOn(0);
1172 if (Video::getInstance()->getFormat() == Video::PAL)
1173 vi->setPosition(170, 200);
1175 vi->setPosition(160, 150);
1176 vi->setOneLiner(tr("unable to get media list"));
1179 Message* m = new Message();
1180 m->message = Message::ADD_VIEW;
1181 m->p_to = Message::BOXSTACK;
1182 m->data = reinterpret_cast<void*>(vi);
1183 MessageQueue::getInstance()->postMessage(m);
1188 const char * VMediaList::getDirname(ULONG mtype) const {
1189 if (mtype == MEDIA_TYPE_AUDIO && audiodirlist) {
1190 return audiodirlist->getCurrent()->getDisplayName();
1192 return dirlist->getCurrent()->getDisplayName();
1195 void VMediaList::timercall(int ref) {
1196 if (ref == 1 || ref == 2 ) {
1197 //send a directory done event
1198 Message* m = new Message();
1199 m->message = Message::PLAYER_EVENT;
1202 MessageQueue::getInstance()->postMessage(m);