/*
 * menu_vwfilebrowser.c: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */

#include "menu_vwfilebrowser.h"
#include "tools.h"

class cViewerStatebag : public cFilebrowserStatebag {
public:
  cViewerStatebag(char *Dir=NULL);
};

cViewerStatebag::cViewerStatebag(char *Dir) : cFilebrowserStatebag()
{
  ShowHiddenFiles=true;
  //Set Base Directory - that is important
  if(Dir)
     ParseDirectory(Dir, BaseDir, NULL);
  else
     strcpy(BaseDir, "/");
//  GetCommands()->Add(new cFilebrowserCommandContainer(new cCustomCommand()));
}

// --- cMenuViewerFilebrowser ---------------------------------------------------------

cMenuViewerFilebrowser::cMenuViewerFilebrowser(char *filename, bool * pOk, cFilebrowserStatebag* Statebag)
:cOsdMenuFilebrowser(filename, Statebag? Statebag : new cViewerStatebag)
{
  ParseDirectory(filename, Filename, Dirname);
  pFilename=filename;
  pok=pOk;
  *pok=false;
}

cMenuViewerFilebrowser::~cMenuViewerFilebrowser()
{
}

eOSState cMenuViewerFilebrowser::ProcessKey(eKeys Key)
{
  eOSState state=cOsdMenuFilebrowser::ProcessKey(Key);

  cOsdItemFileEntry *pItem=(cOsdItemFileEntry*)Get(Current());

  switch(Key) {
  case kOk: 
             if(pItem && !pItem->IsDir()) {
                strn0cpy(pFilename, pItem->GetFilename(), MaxFileName);
                *pok=true;
                return osBack;
             }
             break;
  default:
             break;
  }
  return state;
}
