/*
 *  This file is part of RawTherapee.
 *
 *  Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
 *
 *  RawTherapee 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 3 of the License, or
 *  (at your option) any later version.
 * 
 *  RawTherapee 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 RawTherapee.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef _EXIFPANEL_
#define _EXIFPANEL_

#include <gtkmm.h>
#include <toolpanel.h>

class ExifPanel : public Gtk::VBox, public ToolPanel {

    private: 
        const rtengine::ImageMetaData* idata;
        int fullw, fullh, cx, cy, cw, ch;
        bool crenabled;
        std::vector<rtengine::procparams::ExifPair> changeList;
        std::vector<rtengine::procparams::ExifPair> defChangeList;
        bool recursiveOp;
        
        class ExifColumns : public Gtk::TreeModelColumnRecord {
            public:
                Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > icon;
                Gtk::TreeModelColumn<Glib::ustring> field;
                Gtk::TreeModelColumn<Glib::ustring> field_nopango;
                Gtk::TreeModelColumn<Glib::ustring> value;
                Gtk::TreeModelColumn<Glib::ustring> value_nopango;
                Gtk::TreeModelColumn<Glib::ustring> orig_value;
                Gtk::TreeModelColumn<int>           action; // = 0: dont write to output,  =1: write to output, =2: chagned by RT (not editable/deletable), =3: new addition
                Gtk::TreeModelColumn<bool>          editable;
                Gtk::TreeModelColumn<bool>          edited;

                ExifColumns() { add(field); add(value); add(icon); add(action); add(edited); add(field_nopango); add(value_nopango); add(editable); add(orig_value); }
        };
        Glib::RefPtr<Gdk::Pixbuf> delicon;
        Glib::RefPtr<Gdk::Pixbuf> keepicon;
        Glib::RefPtr<Gdk::Pixbuf> editicon;
        
        ExifColumns exifColumns;
        Gtk::TreeView* exifTree;
        Gtk::ScrolledWindow* scrolledWindow;
        Glib::RefPtr<Gtk::TreeStore> exifTreeModel;
    
        Gtk::Button* remove;
        Gtk::Button* keep;
        Gtk::Button* add;
        Gtk::Button* reset;
        Gtk::Button* resetAll;
        
        Gtk::TreeModel::Children addTag  (const Gtk::TreeModel::Children& root, Glib::ustring field, Glib::ustring value, int action, bool editable);
        void editTag (Gtk::TreeModel::Children root, Glib::ustring name, Glib::ustring value);
        void updateChangeList (Gtk::TreeModel::Children root, std::string prefix);
        void addDirectory (const rtexif::TagDirectory* dir, Gtk::TreeModel::Children root);       
        Glib::ustring getSelection (bool onlyifeditable=false);
        Glib::ustring getSelectedValue ();
        void updateChangeList ();
        void applyChangeList ();
        void keepIt  (Gtk::TreeModel::iterator iter);
        void delIt   (Gtk::TreeModel::iterator iter);
        Gtk::TreeModel::iterator resetIt (Gtk::TreeModel::iterator iter);
    public:
        ExifPanel ();
        virtual ~ExifPanel ();
        
		void read           (const rtengine::procparams::ProcParams* pp, const ParamsEdited* pedited=NULL); 
		void write          (rtengine::procparams::ProcParams* pp, ParamsEdited* pedited=NULL);
		void setDefaults    (const rtengine::procparams::ProcParams* defParams, const ParamsEdited* pedited=NULL);
        
        void setImageData (const rtengine::ImageMetaData* id);       

        void exifSelectionChanged ();
        void removePressed ();
        void keepPressed ();
        void resetPressed ();
        void resetAllPressed ();
        void addPressed ();
        void row_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);
        
        void notifyListener ();
        
};

#endif
