/*
-----BEGIN QCMOD-----
name: Qt >= 5.0.0
-----END QCMOD-----
*/
class qc_qt5 : public ConfObj
{
public:
    qc_qt5(Conf *c) : ConfObj(c) {}
    QString name() const { return "Qt >= 5.0.0"; }
    QString shortname() const { return "qt5"; }
    bool exec()
    {
    	return(QT_VERSION >= 0x050000);
    }

    QString resultString() const
    {
    	return QT_VERSION_STR;
    }
};

class QtCompFinder : public ConfObj
{
protected:
    QString compId;
    QString compShortName;
    QString compName;
    QString extraConfIfFound;
    QString finderResult;

public:
    /**
     * id - (QT += <id>)
     * shortName - used with QC_ENABLE_<shortName> | QC_DISABLE_<shortName> env vars
     *             MUST MATCH with qcm module name without extension
     * name - something visible in the log
     * extraConfIfFound - extra string added to conf.pri if found
     */
    QtCompFinder(const QString &id,const QString &shortName, const QString &name,
    	     const QString &extraConfIfFound, Conf *c) :
    	ConfObj(c), compId(id), compShortName(shortName), compName(name),
    	extraConfIfFound(extraConfIfFound)
    {}

    QString name() const { return compName; }
    QString shortname() const { return compShortName; }
    QString resultString() const
    {
        if (!finderResult.isEmpty())
            return finderResult;

        return ConfObj::resultString();
    }

    bool exec()
    {
        if (!conf->getenv("QC_DISABLE_" + compShortName).isEmpty()) {
            finderResult = "disabled";
            return false;
        }

    	QString proextra =
    	"CONFIG += qt\n"
    	"QT -= gui\n"
    	"QT += ";
    	
    	proextra += compId;

    	QString str =
    	"\n"
    	"int main()\n"
    	"{\n"
    	"	return 0;\n"
    	"}\n";

    	int ret;
    	if(!conf->doCompileAndLink(str, QStringList(), QString(), proextra, &ret))
    		return false;
    	if(ret != 0)
    		return false;

    	if (!extraConfIfFound.isEmpty()) {
    		conf->addExtra(extraConfIfFound);
    	}

    	return true;
    }
};

#define QC_AS_STR(s) #s

#define QC_SILENT_NOT_FOUND(modname) \
class qc_##modname : public ConfObj \
{ \
public: \
    qc_##modname(Conf *c) : ConfObj(c) {} \
    QString name() const { return QC_AS_STR(modname); } \
    QString shortname() const { return QC_AS_STR(modname); } \
    QString checkString() const { return QString(); } \
    bool exec() { return false; } \
};

#define QC_FIND_QT_COMP_BASE(id, shortname, name, extraConfIfFound, suffix) \
class qc_##shortname##suffix : public QtCompFinder \
{ \
public: \
    qc_##shortname##suffix(Conf *c) : QtCompFinder(QC_AS_STR(id), QC_AS_STR(shortname), QC_AS_STR(name), extraConfIfFound, c) {} \
};

#define QC_FIND_QT_COMP_E(id, shortname, name, extraConfIfFound) QC_FIND_QT_COMP_BASE(id, shortname, name, extraConfIfFound,)
#define QC_FIND_QT_COMP(id, shortname, name) QC_FIND_QT_COMP_E(id, shortname, name, "")
