/**************************************************************************

    This file is part of Xclass95, a Win95-looking GUI toolkit.
    Copyright (C) 1996, 1997 David Barth, Hector Peraza.

    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.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

**************************************************************************/

#ifndef __OXFILECONTAINER_H
#define __OXFILECONTAINER_H

#include <regex.h>
#include <X11/Xlib.h>

#include <xclass/OXFrame.h>
#include <xclass/OXWidgets.h>
#include <xclass/OXListView.h>
#include <xclass/OString.h>
#include <xclass/OPicture.h>
#include <xclass/OMimeTypes.h>


//----- sort types

#define SORT_BY_NAME  0
#define SORT_BY_TYPE  1
#define SORT_BY_SIZE  2
#define SORT_BY_DATE  3


#define FW_DIRCHANGED  (XC_MSGMAX + 1)

//-------------------------------------------------------------------

class OXFileIcon : public OXIcon {
public:
  OXFileIcon(const OXWindow *p, const OPicture *pic, const OPicture *lpic,
             unsigned int options = CHILD_FRAME,
             unsigned long back = _whitePixel) :
    OXIcon(p, pic, options, back) { _lpic = lpic; }

protected:
  virtual void _DoRedraw();

  const OPicture *_lpic;
};

//-------------------------------------------------------------------

class OXFileItem : public OXListItem {
public:
  OXFileItem(const OXWindow *p,
             const OPicture *bpic, const OPicture *blpic,
             const OPicture *spic, const OPicture *slpic,
             OString *name, int type, unsigned long size, int uid, int gid,
             int ViewMode, unsigned int options = VERTICAL_FRAME,
             unsigned long back = _whitePixel);

  virtual void SetViewMode(int ViewMode);

  int IsActive() const { return _active; }
  int IsSymLink() const { return _is_link; }
  int GetType() const { return _type; }
  int GetSize() const { return _size; }

//  void DoEdit() { _label->DoEdit(); }

protected:
  virtual void _DoRedraw();

  const OPicture *_blpic, *_slpic, *_lcurrent;
  int _type, _is_link, _uid, _gid;
  unsigned long _size;
};

//-------------------------------------------------------------------

class OXFileContainer : public OXListViewContainer {
public:
  OXFileContainer(const OXWindow *p, OMimeTypes *mime_types,
                  char *filter, int w, int h,
                  unsigned int options = SUNKEN_FRAME,
                  unsigned long back = _defaultFrameBackground);
  virtual ~OXFileContainer();

  virtual int HandleTimer(OTimer *t);

  void Sort(int sortType);
  void ChangeDirectory(const char *path);
  void DisplayDirectory();
  void SetFileFilter(char *filter);

  void GetFilePictures(const OPicture **pic, const OPicture **lpic, 
                       int file_type, int is_link, char *ext, int small);

private:
  SListFrameElt **_doSort(SListFrameElt **head, int n);
  int _compare(SListFrameElt *p1, SListFrameElt *p2);
  void CreateFileList();
  int _fileMatch(const char *filename);
  void _compileFilter(const char *filter);

protected:
  int _sortType;
  regex_t _filter;
  OTimer *_refresh;
  unsigned long _st_mtime;
  OMimeTypes *MimeTypesList;
  const OPicture *_folder_t, *_folder_s;
  const OPicture *_app_t,    *_app_s;
  const OPicture *_doc_t,    *_doc_s;
  const OPicture *_slink_t,  *_slink_s;
};


#endif  // __OXFILECONTAINER_H
