/***************************************************************************
                          roaster_menu.h  -  description
                             -------------------
    begin                : Sa Jan 8 2005
    copyright            : (C) 2005 by Holger Brunn
    email                : holger.brunn@stud.uni-karlsruhe.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef ROASTER_MENU_H
#define ROASTER_MENU_H

#include <vdr/osdbase.h>
#include <vdr/status.h>
#include <vdr/keys.h>
#include <vdr/menuitems.h>
#include <vdr/tools.h>
#include "statebag.h"

/**
  *@author Holger Brunn
  */

// Forward declarations for commands.h
class cRoasterCommandContainer;
class cRoasterDestinationContainerCommand;

enum eMenuRoasterTask {taskBrowse, taskSelectDestination};

enum eRoasterOSStates
{
  osRoasterCloseRefresh = osUser1,
  osRoasterCloseExec = osUser2
};

class cOsdMenuRoaster : public cOsdMenu, public cStatus
{
  friend class cRoasterMarkCommand;
  friend class cRoasterMarkAllCommand;
  friend class cRoasterUnmarkCommand;
  friend class cRoasterUnmarkAllCommand;
  friend class cRoasterCommandThreadList;
  friend class cRoasterCommandSourcesList;
  friend class cRoasterCommandOtherCommands;
  friend class cRoasterDestinationContainerCommand;
  friend class cRoasterDestinationAbortCommand;
  friend class cRoasterDestinationNewCommand;

  protected:
    cRoasterStatebag* Statebag;

    cRoasterCommands* ActualCommands;
    cRoasterCommandContainer* LeftVisibleCommand;

    cRoasterDestinationContainerCommand* DestinationContainerCommand;

    char* BaseDirectory;

    void LoadDir(cString Directory);
    void Refresh(const char* CurrentFile=NULL);
    void UpdateHelp();

    char* CurrentFilename();

    eMenuRoasterTask Task;

    static int DirectorySort(const void* File1, const void* File2);
    /*
     *  This filters entries shown in Roaster
     *  The function uses Statebag->ShowHiddenFiles and Statebag->Filter
     *  Override it to have a custom filter if those are not enough
     */
    virtual bool MatchesFilter(dirent64* Entry);

    void UpdateCommands(const char* Filename, bool IsVirtualNewFile, bool NewFileInEditMode);

  public:
    cOsdMenuRoaster(char* Directory, cRoasterStatebag* Statebag);
    ~cOsdMenuRoaster();
    virtual eOSState ProcessKey(eKeys Key);
    /* cStatus */
    void OsdCurrentItem(const char *Text);
};

class cOsdItemFileEntry : public cOsdItem
{
  protected:
    char* Filename;
    char* Name;
    bool IsParentDir;
    bool Marked;
    cOsdItemFileEntry() {};

    void UpdateText();
  public:
    cOsdItemFileEntry(dirent64* DirectoryEntry, cString Directory, cRoasterStatebag* Statebag);
    ~cOsdItemFileEntry();
    virtual eOSState ProcessKey(eKeys Key);
    bool IsDir();
    bool IsParentDirectory() { return IsParentDir; };
    bool IsMarked() { return Marked; };
    char* GetFilename() { return Filename; };
    void Mark(bool Marked);
};

class cOsdItemNewFileEntry : public cMenuEditStrItem
{
  protected:
    char* Directory;
    char* Name;
    char* Filename;
    
  public:
    cOsdItemNewFileEntry(char* Value, cString Directory);
    ~cOsdItemNewFileEntry();
    eOSState ProcessKey(eKeys Key);
    char* GetFilename();
    bool InEditMode();
};


#endif
