/* ****************************************************************************
  This file is part of KBabel

  Copyright (C) 2002-2003 by Marco Wegner <mail@marcowegner.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.

  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.

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


#ifndef CVSHANDLER_H
#define CVSHANDLER_H

// Qt include files
#include <qmap.h>
#include <qobject.h>
// Project specific include files
#include "cvsdialog.h"
#include "cvsresources.h"
// Forwarding Qt classes
class QString;
class QStringList;

/**
 * This class is the backend for CVS support in Catalog Manager.
 *
 * @short  Backend for CVS support in Catalog Manager
 * @author Marco Wegner <mail@marcowegner.de>
 */
class CVSHandler : public QObject
{
  Q_OBJECT

  public:
    enum FileStatus {
      NO_REPOSITORY,
      NOT_IN_CVS,
      LOCALLY_ADDED,
      LOCALLY_REMOVED,
      LOCALLY_MODIFIED,
      CONFLICT,
      UP_TO_DATE
    };
  
    CVSHandler( const QString& poBaseDir = QString::null, const QString& potBaseDir = QString::null );

    void setPOBaseDir( const QString& dir );
    void setPOTBaseDir( const QString& dir );

    FileStatus fstatus( const QString& filename );
    QString fileStatus( const QString& filename );
    QString cvsStatus( const QString& filename ) const;

    void execCVSCommand(CVS::Command cmd, const QString& filename, bool templates = false);
    void execCVSCommand(CVS::Command cmd, const QStringList& files, bool templates = false);
    
    void setAutoUpdateTemplates( bool update );

  signals:
    void signalIsPORepository( bool );
    void signalIsPOTRepository( bool );
    void signalFilesCommitted( const QStringList& );

  private:
    void showDialog( CVS::Command cmd, const QStringList& files, const QString& commandLine );
    void checkToAdd( const QStringList& files );
    void processStatusOutput( const QString& status );

  private:
    QString _poBaseDir;
    QString _potBaseDir;
    bool _isPORepository;
    bool _isPOTRepository;
    bool _autoUpdateTemplates;
    QString _addCommand;
    
    /** Mapping the output of 'cvs status' against the filename. */
    QMap<QString,QString> map;
};

#endif // CVSHANDLER_H
