//
//
// C++ Interface: tdefilereplacepart
//
// Description:
//
//
// Author: Andras Mantia <amantia@kde.org>, (C) 2003
// Maintainer: Emiliano Gulmini <emi_barbarossa@yahoo.it>, (C) 2004
//
// Copyright: GPL v2. See COPYING file that comes with this distribution
//
//

#ifndef TDEFILEREPLACEPART_H
#define TDEFILEREPLACEPART_H

// QT

// KDE
#include <tdeparts/part.h>
class TDEAboutApplication;
class TDEAboutData;
class TDEConfig;

// local
#include "configurationclasses.h"
class TDEFileReplaceView;

#define KFR_VERSION "0.8.1"

class TDEFileReplacePart: public KParts::ReadOnlyPart
{
  TQ_OBJECT
  

  private: //MEMBERS
    TDEFileReplaceView* m_view;
    TQWidget* m_parentWidget,
           * m_w;
    TDEConfig* m_config;
    TDEAboutApplication* m_aboutDlg;
    KeyValueMap m_replacementMap;
    RCOptions* m_option;
    bool m_stop;
    bool m_searchingOperation;
    bool m_circ_ref_warning_shown;
    int m_optionMask;

  public://Constructors
    TDEFileReplacePart(TQWidget *parentWidget,
                     const char *widgetName,
                     TQObject *parent,
                     const char *name,
                     const TQStringList &args);
    ~TDEFileReplacePart();

  //SLOTS
  private slots:
    void slotSetNewParameters();
    void slotSearchingOperation();
    void slotReplacingOperation();
    void slotSimulatingOperation();
    void slotStop();
    void slotCreateReport();
    void slotQuickStringsAdd();
    void slotOptionRecursive();
    void slotOptionBackup();
    void slotOptionCaseSensitive();
    void slotOptionVariables();
    void slotOptionRegularExpressions();
    void slotOptionPreferences();
    void showAboutApplication(void);
    void appHelpActivated();
    void reportBug();
    void updateGUI();
    void slotSearchMode(bool b){ m_option->m_searchingOnlyMode = b; }

  //METHODS
  public:
    static TDEAboutData* createAboutData();
    TDEConfig *config(){ return m_config; }

  protected:
    virtual bool openFile() { return false; }
    virtual bool openURL (const KURL &url);

  private:
    /**
     * Initialization methods
     */
    void initGUI();
    void initView();

    /**
     * This method freezes the GUI of tdefilereplace during searching
     */
    void freezeActions();

    /**
     * These methods load the resources from tdefilereplacerc
     */
    void loadOptionsFromRC();
    void loadOptions();
    void loadFileSizeOptions();
    void loadDateAccessOptions();
    void loadOwnerOptions();
    void loadCBLists();
    void loadFiltersList();
    void loadBackupExtensionOptions();

    /**
     * These methods save the resources to tdefilereplacerc
     */
    void saveOptionsToRC();
    void saveOptions();
    void saveFileSizeOptions();
    void saveDateAccessOptions();
    void saveOwnerOptions();
    void saveCBLists();
    void saveFiltersList();
    void saveBackupExtensionOptions();

    /**
     * Replacing methods
     */
    void fileReplace();
    void recursiveFileReplace(const TQString &directoryName, int &foldersNumber, int &filesNumber, int depth);
    void replaceAndBackup(const TQString& currentDir, const TQString& oldFileName);
    void replaceAndOverwrite(const TQString& currentDir, const TQString& oldFileName);
    void replacingLoop(TQString& line, TDEListViewItem** item, bool& atLeastOneStringFound, int& occur,
                       bool regularExpression, bool& askConfirmReplace);

    /**
     * Searching methods
     */
    void fileSearch(const TQString& dirName, const TQString& filters);
    void recursiveFileSearch(const TQString &dirName, const TQString &filters, int &foldersNumber, 
                             int &filesNumber, int depth);
    void search(const TQString& currentDir, const TQString& fileName);

    /**
     * Others methods
     */
    void loadViewContent();
    bool launchNewProjectDialog(const KURL& startURL);
    void setOptionMask();
    bool checkBeforeOperation();
    bool dontAskAgain();
    void whatsThis();
};

#endif// TDEFileReplacePart
