#ifndef XDIRCOMP_H
#define XDIRCOMP_H

//$Id: XDirComp.h,v 1.38 2006/06/05 16:46:02 markus Rel $

// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


#include <string>

#include <gtkmm/table.h>
#include <gtkmm/label.h>
#include <gtkmm/statusbar.h>
#include <gtkmm/scrolledwindow.h>

#ifdef ENABLE_THREADS
#  include <YGP/Thread.h>
#  include <YGP/Mutex.h>
#endif
#include <YGP/ATStamp.h>

#include <XGP/XFileEntry.h>
#include <XGP/XApplication.h>

#include "CompDir.h"
#include "DCFileList.h"


// Forward declarations
namespace YGP {
#ifndef ENABLE_THREADS
   typedef void Thread;
#endif
   class  IDirectorySearch;
}


namespace Gtk {
   class CheckMenuItem;
}


// Class to display the result of CompareDirs
class XCompareDirs : public CompareDirs {
 public:
   XCompareDirs (DCFileList& destination, Gtk::Statusbar& statusbar
#ifdef ENABLE_THREADS
                 , YGP::Thread* thrd
#endif
                 )
      : cChangedFiles (0), cNewFiles (0), cAllFiles (0), list (destination), info (statusbar)
#ifdef ENABLE_THREADS
      , thread (thrd)
#endif
 { }
   virtual ~XCompareDirs () { }

   int getChangedFiles () const { return cChangedFiles; }
   int getNewFiles () const { return cNewFiles; }
   int getNumFiles () const { return cAllFiles; }

   void reset ();

#ifdef ENABLE_THREADS
   void lock () { mxAccess.lock (); }
   void unlock () { mxAccess.unlock (); }
#endif

 protected:
   virtual void showFile (const Status diff, const YGP::File* pFileOrig,
                          const YGP::File* pFileComp = NULL);

   virtual void enterDirectory (const std::string& path);

 private:
   unsigned int cChangedFiles;
   unsigned int cNewFiles;
   unsigned int cAllFiles;

   DCFileList&     list;
   Gtk::Statusbar& info;
#ifdef ENABLE_THREADS
   YGP::Thread* thread;
   YGP::Mutex   mxAccess;
#endif
};


// Class with the graphical interface to DirComp
class XDirComp : public XGP::XApplication {
 public:
   // Manager functions
   XDirComp ();
   ~XDirComp () { }

 protected:
   virtual const char* getHelpfile () { return DOCUDIR "/XDirComp.html"; }

 private:
   // Protected manager functions
   XDirComp (const XDirComp&);
   const XDirComp& operator= (const XDirComp&);

   // Event-handling
   void startCompare ();
   void endCompare ();
   void save ();
   void print ();
   void quit ();
   void toggleOption (XCompareDirs::Options option);
   void searchSubdirs ();
   void searchEqualSubdirs ();
   void compareAlways ();
   void selectFiles ();
   void selectDirectories ();
   void selectDate (bool upper);

   void dirChanged ();
   void saveToFile (const std::string& file);
   void writeToStream (FILE* file);

   virtual void showAboutbox ();

   void menuInSearch (bool search = false);

   Gtk::Table      tblInput;
   XGP::XFileEntry inDirComp;
   XGP::XFileEntry inDirOrig;
   Gtk::Label      lblDirOrig;
   Gtk::Label      lblDirComp;
   DCFileList      listFiles;

   Gtk::Statusbar      status;
   Gtk::ScrolledWindow scroll;

   XCompareDirs dc;

#ifdef ENABLE_THREADS
   YGP::OThread<XDirComp>* childSearch;
#endif

   void* compare (YGP::Thread* pArgs);
   std::string getDifferentFiles () const;

   static const char* pTitles[];

   static const char* xpmAuthor[];
   static const char* xpmXDirComp[];

   std::string files;
   std::string dirInExcl;
   YGP::ATimestamp dateStart, dateEnd;

   enum { START = 0, STOP, SAVE, PRINT, SUBDIRS, EQUALSUBDIRS, COMPARE, LAST };
   Glib::RefPtr<Gtk::Action> apMenus[LAST];
};

#endif


syntax highlighted by Code2HTML, v. 0.9.1