// $Id: interfaces.cpp,v 1.5 2008/03/06 21:18:58 hvengel Exp $
//  
//  Lttle cms Profiler
// Copyright (C) 2005 - 2007 Hal Engel
//
// THIS SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
// EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
// WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
//
// IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
// INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
// OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
// WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
// LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
// OF THIS SOFTWARE.
//
// 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 3 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, see <http://www.gnu.org/licenses/>.
//
// Version 1.11

#include "lprofmain-priv.h"
#include "lprofmain.h" 

#include <qdir.h>

static targetTemplate tempTT;

QAssistantClient* getHelp()
{
    return help;
}

QString get_global_help_path()

{
    return global_help_path;
}

void ref_file::get( ref_file &out)
{
    QDir d;
    QString temp;

    out.items.temp_dir = temp_dir;
    out.items.template_dir = templates;
    out.items.ref_dir = ref_dir;
    out.items.home_dir = d.homeDirPath();
    out.items.settings = lprofSettings;
}

 void checkerP::get(checkerP &out)
{
     // qDebug("checkP::get");

    out.items.ref_dir=ref_dir;
    out.items.cur_ref = sys.hdr.cur_ref;
    out.items.profile=QString::fromLocal8Bit( sys.hdr.OutputProfileFile);
    out.items.msheet=QString::fromLocal8Bit( sys.hdr.MeasurementSheet);
    out.items.mon_profile_dir=QString::fromLocal8Bit( sys.hdr.mon_profile_dir);
    out.items.mon_profile_file_name=QString::fromLocal8Bit( sys.hdr.mon_profile_file_name);
}

void monVal::get(monVal* out)
{
    // qDebug("in get mon");
    out->items=monitorValues.items;
}

void monVal::put(monVal &in)
{
     // qDebug("in put mon");
    monitorValues.items=in.items;

    if (sys.Prelinearization[0]) cmsFreeGamma(sys.Prelinearization[0]);
    if (sys.Prelinearization[1]) cmsFreeGamma(sys.Prelinearization[1]);
    if (sys.Prelinearization[2]) cmsFreeGamma(sys.Prelinearization[2]);

    if (monitorValues.items.linked)
    {
        double val = monitorValues.items.rgamma;

        sys.Prelinearization[0] = cmsBuildGamma(256, val);
        sys.Prelinearization[1] = cmsBuildGamma(256, val);
        sys.Prelinearization[2] = cmsBuildGamma(256, val);
    }
    else
    {
        sys.Prelinearization[0] = cmsBuildGamma(256, monitorValues.items.rgamma);
        sys.Prelinearization[1] = cmsBuildGamma(256, monitorValues.items.ggamma);
        sys.Prelinearization[2] = cmsBuildGamma(256, monitorValues.items.bgamma);
    }
    monitorValues.items.valid_mon = TRUE;
}

void passSys::get( PROFILERDATA* out)
{
    // qDebug("passSys::get");
    // qDebug(sys.hdr.MonMeasurementSheet);
    // qDebug(sys.hdr.MonCalibrationSheet);
    out->hdr=sys.hdr;
    out->Prelinearization[0]=sys.Prelinearization[0];
    out->Prelinearization[1]=sys.Prelinearization[1];
    out->Prelinearization[2]=sys.Prelinearization[2];
    out->ReverseTables[0]=sys.ReverseTables[0];
    out->ReverseTables[1]=sys.ReverseTables[1];
    out->ReverseTables[2]=sys.ReverseTables[2];
    out->PreLab[0]=sys.PreLab[0];
    out->PreLab[1]=sys.PreLab[1];
    out->PreLab[2]=sys.PreLab[2];
    out->PreLabRev[0]=sys.PreLabRev[0];
    out->PreLabRev[1]=sys.PreLabRev[1];
    out->PreLabRev[2]=sys.PreLabRev[2];
    out->PrimariesMatrix=sys.PrimariesMatrix;
    out->PrimariesMatrixRev=sys.PrimariesMatrixRev;
    out->HiTerms=sys.HiTerms;
    out->LoTerms=sys.LoTerms;
    out->RsplSmoothness=sys.RsplSmoothness;
    out->lOptRGCV=sys.lOptRGCV;
    out->Rspl=sys.Rspl;
}

void passSys::put(PROFILERDATA &in)
{
     // qDebug("passSys::put");
//     sys.hdr=in.hdr;
//     sys.RsplSmoothness=in.RsplSmoothness;
//     sys.lOptRGCV=in.lOptRGCV;
    sys = in;
}

void targetTemplate::put(targetTemplate &in)
{
    if (in.items.targetFile != QString::fromLocal8Bit("") && in.items.templateFile != QString::fromLocal8Bit(""))
    {
        add_target(in.items);
        tempTT.items = in.items;
        refinstOK = true;
    }
}

void dialogSize::put(lprof_dialogs d, int h, int w)
{
    switch (d)
    {
        case refile: // reference file installer dialog
            dsizes.reffileH = h;
            dsizes.reffileW = w;
            break;
            
        case monVald: // monitorvalue dialog
            dsizes.monvalH = h;
            dsizes.monvalW = w;
            break;
            
        case profChecker: // ProfileChecker dialog
            dsizes.profchH = h;
            dsizes.profchW = w;
            break;
            
        case profID: //ProfileID dialog
            dsizes.profidH = h;
            dsizes.profidW = w;
            break;
            
        case profParms: //ProfileParms dialog
            dsizes.profparmsH = h;
            dsizes.profparmsW = w;
            break;
            
        case profParmsMon: //ProfileParms dialog
            dsizes.profparmsmonH = h;
            dsizes.profparmsmonW = w;
            break;
            
        case monCalControl:
            dsizes.moncalH = h;
            dsizes.moncalW = w;
            break;
            default:  break;
    }
}

void monCal::calOK(bool OK)
{
    monCalOK = OK;
}

void monCal::OK(bool OK)
{
    monMeasOK = OK;
}

