/****************************************************************************
** $Id: quickprojectsettingsinterfaceimpl.cpp  beta1   edited Dec 10 13:07 $
**
** Copyright (C) 2001-2002 Trolltech AS.  All rights reserved.
**
** This file is part of the Qt Script for Applications framework (QSA).
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding a valid QSA Beta Evaluation Version license may use
** this file in accordance with the QSA Beta Evaluation Version License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
**   information about QSA Commercial License Agreements.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
*****************************************************************************/

#include "quickprojectsettingsinterfaceimpl.h"
#include "quickprojectsettings.h"
#include <designerinterface.h>
#include <qstringlist.h>

QuickProjectSettingsInterfaceImpl::QuickProjectSettingsInterfaceImpl()
    : ref( 0 ), dIface( 0 )
{
    settingsTab = 0;
}

QuickProjectSettingsInterfaceImpl::~QuickProjectSettingsInterfaceImpl()
{
    if ( dIface )
	dIface->release();
}

QRESULT QuickProjectSettingsInterfaceImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
{
    *iface = 0;
    if ( uuid == IID_QUnknown )
	*iface = (QUnknownInterface*)this;
    else if ( uuid == IID_ProjectSettings )
	*iface = (ProjectSettingsInterface*)this;
    else
	return QE_NOINTERFACE;

    (*iface)->addRef();
    return QS_OK;
}

ulong QuickProjectSettingsInterfaceImpl::addRef()
{
    return ref++;
}

ulong QuickProjectSettingsInterfaceImpl::release()
{
    if ( !--ref ) {
	delete this;
	return 0;
    }
    return ref;
}

ProjectSettingsInterface::ProjectSettings *QuickProjectSettingsInterfaceImpl::projectSetting()
{
    if ( !settingsTab ) {
	settingsTab = new QuickProjectSettings( 0 );
	settingsTab->hide();
    }
    ProjectSettings *pf = 0;
    pf = new ProjectSettings;
    pf->tab = settingsTab;
    pf->title = "Qt Script";
    pf->receiver = pf->tab;
    pf->init_slot = SLOT( reInit( QUnknownInterface * ) );
    pf->accept_slot = SLOT( save( QUnknownInterface * ) );
    return pf;
}

QStringList QuickProjectSettingsInterfaceImpl::projectSettings() const
{
    QStringList l;
    l << "MAINFORM" << "USE_SERVER" << "QUICK_HOST" << "QUICK_USER" << "QUICK_PASSWD"
      << "QUICK_APPTYPE" << "QUICK_CGI_METHOD" << "QUICK_CGI_QUERY"
      << "QUICK_CGI_BROWSER_COMMAND" << "QUICK_APP_ARGS" << "QUICK_PACKAGES";
    return l;
}

void QuickProjectSettingsInterfaceImpl::connectTo( QUnknownInterface *appInterface )
{
    if ( dIface )
	return;

    dIface = 0;
    appInterface->queryInterface( IID_Designer, (QUnknownInterface**)&dIface );
}

void QuickProjectSettingsInterfaceImpl::deleteProjectSettingsObject( ProjectSettings *p )
{
    delete p;
}
