<commit_before>/*************************************************************************
 *
 *  $RCSfile: optinet2.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: obo $ $Date: 2004-04-29 16:24:12 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library 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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef _SVX_OPTINET_HXX
#define _SVX_OPTINET_HXX

#ifndef _SV_LSTBOX_HXX
#include <vcl/lstbox.hxx>
#endif
#ifndef _SV_GROUP_HXX
#include <vcl/group.hxx>
#endif
#ifndef _SV_FIELD_HXX
#include <vcl/field.hxx>
#endif
#ifndef _SVARRAY_HXX
#include <svtools/svarray.hxx>
#endif
#ifndef _STDCTRL_HXX //autogen
#include <svtools/stdctrl.hxx>
#endif
#ifndef _SVTABBX_HXX //autogen
#include <svtools/svtabbx.hxx>
#endif
#ifndef _SFXTABDLG_HXX //autogen
#include <sfx2/tabdlg.hxx>
#endif
#ifndef _SVX_SRCHNCFG_HXX
#include "srchcfg.hxx"
#endif

#ifdef _SVX_OPTINET2_CXX
#ifndef _HEADBAR_HXX //autogen
#include <svtools/headbar.hxx>
#endif
#else
class HeaderBar;
#endif

#ifndef _SVX_READONLYIMAGE_HXX
#include <readonlyimage.hxx>
#endif

class SfxFilter;
class SvtInetOptions;

#ifndef SV_NODIALOG
#define PROXY_CONTROLS  23
#define CACHE_CONTROLS  20
#define INET_SEARCH     19

#if defined(OS2) || defined(MAC)
#define TYPE_CONTROLS  20
#else
#define TYPE_CONTROLS  18
#endif

// class SvxNoSpaceEdit --------------------------------------------------

class SvxNoSpaceEdit : public Edit
{
private:
    BOOL            bOnlyNumeric;

public:
    SvxNoSpaceEdit(Window* pParent, ResId rResId, BOOL bNum = FALSE ) :
        Edit( pParent, rResId ), bOnlyNumeric( bNum ) {}

    virtual void    KeyInput( const KeyEvent& rKEvent );
    virtual void    Modify();
};

typedef SfxFilter* SfxFilterPtr;
SV_DECL_PTRARR( SfxFilterPtrArr, SfxFilterPtr, 0, 4 )

// class SvxProxyTabPage -------------------------------------------------

class SvxProxyTabPage : public SfxTabPage
{
private:
    FixedLine       aOptionGB;

    FixedText       aProxyModeFT;
    ListBox         aProxyModeLB;

    FixedText       aHttpProxyFT;
    SvxNoSpaceEdit  aHttpProxyED;
    FixedText       aHttpPortFT;
    SvxNoSpaceEdit  aHttpPortED;

    FixedText       aFtpProxyFT;
    SvxNoSpaceEdit  aFtpProxyED;
    FixedText       aFtpPortFT;
    SvxNoSpaceEdit  aFtpPortED;

    FixedText       aNoProxyForFT;
    Edit            aNoProxyForED;
    FixedText       aNoProxyDescFT;

    String          sFromBrowser;

    SvtInetOptions* pInetOptions;
#ifdef _SVX_OPTINET2_CXX
    void            EnableControls_Impl(BOOL bEnable);

    DECL_LINK( ProxyHdl_Impl, ListBox * );
    DECL_LINK( LoseFocusHdl_Impl, Edit * );
#endif

    SvxProxyTabPage( Window* pParent, const SfxItemSet& rSet );
    virtual ~SvxProxyTabPage();

public:
    static SfxTabPage*  Create( Window* pParent, const SfxItemSet& rAttrSet );
    virtual BOOL        FillItemSet( SfxItemSet& rSet );
    virtual void        Reset( const SfxItemSet& rSet );
};

// class SvxSearchTabPage ------------------------------------------------
class SvxSearchConfig;
class SvxSearchTabPage : public SfxTabPage
{
private:
    FixedLine       aSearchGB;
    ListBox         aSearchLB;
    FixedText       aSearchNameFT;
    SvxNoSpaceEdit  aSearchNameED;

    FixedText       aSearchFT;
    RadioButton     aAndRB;
    RadioButton     aOrRB;
    RadioButton     aExactRB;

    FixedText       aURLFT;
    SvxNoSpaceEdit  aURLED;

    FixedText       aPostFixFT;
    SvxNoSpaceEdit  aPostFixED;
    FixedText       aSeparatorFT;
    SvxNoSpaceEdit  aSeparatorED;
    FixedText       aCaseFT;
    ListBox         aCaseED;

    PushButton      aNewPB;
    PushButton      aAddPB;
    PushButton      aChangePB;
    PushButton      aDeletePB;

    String          sLastSelectedEntry;
    String          sModifyMsg;

    SvxSearchConfig     aSearchConfig;
    SvxSearchEngineData aCurrentSrchData;

#ifdef _SVX_OPTINET2_CXX
    void            FillSearchBox_Impl();
    String          GetSearchString_Impl();

    DECL_LINK( NewSearchHdl_Impl, PushButton * );
    DECL_LINK( AddSearchHdl_Impl, PushButton * );
    DECL_LINK( ChangeSearchHdl_Impl, PushButton * );
    DECL_LINK( DeleteSearchHdl_Impl, PushButton * );
    DECL_LINK( SearchEntryHdl_Impl, ListBox * );
    DECL_LINK( SearchModifyHdl_Impl, SvxNoSpaceEdit * );
    DECL_LINK( SearchPartHdl_Impl, RadioButton * );
#endif

    virtual void        ActivatePage( const SfxItemSet& rSet );
    virtual int         DeactivatePage( SfxItemSet* pSet = 0 );
    BOOL                ConfirmLeave( const String& rStringSelection );   //add by BerryJia for fixing Bug102610 Time:2002-8-29 11:00 (China Standard Time GMT+08:00)

    SvxSearchTabPage( Window* pParent, const SfxItemSet& rSet );
    virtual ~SvxSearchTabPage();

public:
    static SfxTabPage*  Create( Window* pParent, const SfxItemSet& rAttrSet );
    virtual BOOL        FillItemSet( SfxItemSet& rSet );
    virtual void        Reset( const SfxItemSet& rSet );
};

// #98647# class SvxScriptExecListBox ------------------------------------
class SvxScriptExecListBox : public ListBox
{ // for adding tooltips to ListBox
public:
    SvxScriptExecListBox( Window* pParent, WinBits nStyle = WB_BORDER )
            :ListBox(pParent, nStyle) {}
    SvxScriptExecListBox( Window* pParent, const ResId& rResId )
            :ListBox(pParent, rResId) {}

protected:
    virtual void RequestHelp( const HelpEvent& rHEvt );
};

// class SvxScriptingTabPage ---------------------------------------------

class SvtJavaOptions;
class SvtSecurityOptions;

class SvxScriptingTabPage : public SfxTabPage
{
private:
    // readonly ------------------------------------
    sal_Bool bROConfirm;
    sal_Bool bROWarning;
    sal_Bool bROScriptExec;
    sal_Bool bROExePlug;
    sal_Bool bROExecMacro;

    sal_Bool bROJavaEnabled;
    sal_Bool bROJavaSecurity;
    sal_Bool bROJavaNetAccess;
    sal_Bool bROJavaUserClassPath;
    sal_Bool bROJavaExecuteApplets;

    // Execute

    FixedLine           aGrpScriptingStarBasic;

    ReadOnlyImage       aExecMacroFI;
    FixedText           aExecMacroFT;
    ListBox             aExecMacroLB;

    ReadOnlyImage       aConfirmFI;
    CheckBox            aConfirmCB;

    ReadOnlyImage       aWarningFI;
    CheckBox            aWarningCB;

    ReadOnlyImage       aScriptExecFI;
    FixedText           aPathListFT;
    // #98647# ------------------------------------
    SvxScriptExecListBox aLbScriptExec;
    PushButton          aBtnScriptExecDelete;
    PushButton          aBtnScriptExecDefault;

    FixedText           aNewPathFT;
    Edit                aEdtScriptExec;
    PushButton          aBtnScriptExecInsert;

    FixedLine           aHyperlinksFL;
    ReadOnlyImage       aHyperlinksFI;
    FixedText           aHyperlinksFT;
    ListBox             aHyperlinksLB;

    FixedLine           aJavaFL;
    ReadOnlyImage       aJavaEnableFI;
    CheckBox            aJavaEnableCB;
    ReadOnlyImage       aJavaSecurityFI;
    CheckBox            aJavaSecurityCB;
    ReadOnlyImage       aNetAccessFI;
    FixedText           aNetAccessFT;
    ListBox             aNetAccessLB;
    FixedText           aClassPathFT;
    ReadOnlyImage       aClassPathFI;
    Edit                aClassPathED;
    PushButton          aClassPathPB;

    FixedLine           aSeparatorFL;

    FixedLine           aExecuteGB;
    ReadOnlyImage       aExePlugFI;
    CheckBox            aExePlugCB;
    ReadOnlyImage       aExecAppletsFI;
    CheckBox            aExecAppletsCB;

    Image               aLockImg;
    Image               aLockHCImg;

    SvtJavaOptions*     pJavaOptions;
    SvtSecurityOptions* pSecurityOptions;
#ifdef _SVX_OPTINET2_CXX
    DECL_LINK( EditHdl_Impl, Edit* );
    DECL_LINK( LBHdl_Impl, ListBox* );
    DECL_LINK( BtnHdl_Impl, PushButton* );
    DECL_LINK( RunHdl_Impl, ListBox* );
    DECL_LINK( JavaEnableHdl_Impl, CheckBox* );
    DECL_LINK( ClassPathHdl_Impl, PushButton* );

    void                FillListBox_Impl();
    void                EnableJava_Impl( BOOL bEnable, BOOL bOnlySecurity );
#endif
                SvxScriptingTabPage( Window* pParent, const SfxItemSet& rSet );
    virtual     ~SvxScriptingTabPage();

protected:
    virtual void        ActivatePage( const SfxItemSet& rSet );
    virtual int         DeactivatePage( SfxItemSet* pSet = 0 );

public:
    static SfxTabPage*  Create( Window* pParent, const SfxItemSet& rAttrSet );
    virtual BOOL        FillItemSet( SfxItemSet& rSet );
    virtual void        Reset( const SfxItemSet& rSet );
};

#endif

#endif // #ifndef _SVX_OPTINET_HXX

<commit_msg>INTEGRATION: CWS defaultmailer (1.3.44); FILE MERGED 2004/06/03 09:45:48 obr 1.3.44.1: #109597#,#i21321# moved mailer configuration to Internet section and disabled tabpage on Windows entirely<commit_after>/*************************************************************************
 *
 *  $RCSfile: optinet2.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: rt $ $Date: 2004-06-17 15:52:46 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library 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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef _SVX_OPTINET_HXX
#define _SVX_OPTINET_HXX

#ifndef _SV_LSTBOX_HXX
#include <vcl/lstbox.hxx>
#endif
#ifndef _SV_GROUP_HXX
#include <vcl/group.hxx>
#endif
#ifndef _SV_FIELD_HXX
#include <vcl/field.hxx>
#endif
#ifndef _SVARRAY_HXX
#include <svtools/svarray.hxx>
#endif
#ifndef _STDCTRL_HXX //autogen
#include <svtools/stdctrl.hxx>
#endif
#ifndef _SVTABBX_HXX //autogen
#include <svtools/svtabbx.hxx>
#endif
#ifndef _SFXTABDLG_HXX //autogen
#include <sfx2/tabdlg.hxx>
#endif
#ifndef _SVX_SRCHNCFG_HXX
#include "srchcfg.hxx"
#endif

#ifdef _SVX_OPTINET2_CXX
#ifndef _HEADBAR_HXX //autogen
#include <svtools/headbar.hxx>
#endif
#else
class HeaderBar;
#endif

#ifndef _SVX_READONLYIMAGE_HXX
#include <readonlyimage.hxx>
#endif

class SfxFilter;
class SvtInetOptions;

#ifndef SV_NODIALOG
#define PROXY_CONTROLS  23
#define CACHE_CONTROLS  20
#define INET_SEARCH     19

#if defined(OS2) || defined(MAC)
#define TYPE_CONTROLS  20
#else
#define TYPE_CONTROLS  18
#endif

// class SvxNoSpaceEdit --------------------------------------------------

class SvxNoSpaceEdit : public Edit
{
private:
    BOOL            bOnlyNumeric;

public:
    SvxNoSpaceEdit(Window* pParent, ResId rResId, BOOL bNum = FALSE ) :
        Edit( pParent, rResId ), bOnlyNumeric( bNum ) {}

    virtual void    KeyInput( const KeyEvent& rKEvent );
    virtual void    Modify();
};

typedef SfxFilter* SfxFilterPtr;
SV_DECL_PTRARR( SfxFilterPtrArr, SfxFilterPtr, 0, 4 )

// class SvxProxyTabPage -------------------------------------------------

class SvxProxyTabPage : public SfxTabPage
{
private:
    FixedLine       aOptionGB;

    FixedText       aProxyModeFT;
    ListBox         aProxyModeLB;

    FixedText       aHttpProxyFT;
    SvxNoSpaceEdit  aHttpProxyED;
    FixedText       aHttpPortFT;
    SvxNoSpaceEdit  aHttpPortED;

    FixedText       aFtpProxyFT;
    SvxNoSpaceEdit  aFtpProxyED;
    FixedText       aFtpPortFT;
    SvxNoSpaceEdit  aFtpPortED;

    FixedText       aNoProxyForFT;
    Edit            aNoProxyForED;
    FixedText       aNoProxyDescFT;

    String          sFromBrowser;

    SvtInetOptions* pInetOptions;
#ifdef _SVX_OPTINET2_CXX
    void            EnableControls_Impl(BOOL bEnable);

    DECL_LINK( ProxyHdl_Impl, ListBox * );
    DECL_LINK( LoseFocusHdl_Impl, Edit * );
#endif

    SvxProxyTabPage( Window* pParent, const SfxItemSet& rSet );
    virtual ~SvxProxyTabPage();

public:
    static SfxTabPage*  Create( Window* pParent, const SfxItemSet& rAttrSet );
    virtual BOOL        FillItemSet( SfxItemSet& rSet );
    virtual void        Reset( const SfxItemSet& rSet );
};

// class SvxSearchTabPage ------------------------------------------------
class SvxSearchConfig;
class SvxSearchTabPage : public SfxTabPage
{
private:
    FixedLine       aSearchGB;
    ListBox         aSearchLB;
    FixedText       aSearchNameFT;
    SvxNoSpaceEdit  aSearchNameED;

    FixedText       aSearchFT;
    RadioButton     aAndRB;
    RadioButton     aOrRB;
    RadioButton     aExactRB;

    FixedText       aURLFT;
    SvxNoSpaceEdit  aURLED;

    FixedText       aPostFixFT;
    SvxNoSpaceEdit  aPostFixED;
    FixedText       aSeparatorFT;
    SvxNoSpaceEdit  aSeparatorED;
    FixedText       aCaseFT;
    ListBox         aCaseED;

    PushButton      aNewPB;
    PushButton      aAddPB;
    PushButton      aChangePB;
    PushButton      aDeletePB;

    String          sLastSelectedEntry;
    String          sModifyMsg;

    SvxSearchConfig     aSearchConfig;
    SvxSearchEngineData aCurrentSrchData;

#ifdef _SVX_OPTINET2_CXX
    void            FillSearchBox_Impl();
    String          GetSearchString_Impl();

    DECL_LINK( NewSearchHdl_Impl, PushButton * );
    DECL_LINK( AddSearchHdl_Impl, PushButton * );
    DECL_LINK( ChangeSearchHdl_Impl, PushButton * );
    DECL_LINK( DeleteSearchHdl_Impl, PushButton * );
    DECL_LINK( SearchEntryHdl_Impl, ListBox * );
    DECL_LINK( SearchModifyHdl_Impl, SvxNoSpaceEdit * );
    DECL_LINK( SearchPartHdl_Impl, RadioButton * );
#endif

    virtual void        ActivatePage( const SfxItemSet& rSet );
    virtual int         DeactivatePage( SfxItemSet* pSet = 0 );
    BOOL                ConfirmLeave( const String& rStringSelection );   //add by BerryJia for fixing Bug102610 Time:2002-8-29 11:00 (China Standard Time GMT+08:00)

    SvxSearchTabPage( Window* pParent, const SfxItemSet& rSet );
    virtual ~SvxSearchTabPage();

public:
    static SfxTabPage*  Create( Window* pParent, const SfxItemSet& rAttrSet );
    virtual BOOL        FillItemSet( SfxItemSet& rSet );
    virtual void        Reset( const SfxItemSet& rSet );
};

// #98647# class SvxScriptExecListBox ------------------------------------
class SvxScriptExecListBox : public ListBox
{ // for adding tooltips to ListBox
public:
    SvxScriptExecListBox( Window* pParent, WinBits nStyle = WB_BORDER )
            :ListBox(pParent, nStyle) {}
    SvxScriptExecListBox( Window* pParent, const ResId& rResId )
            :ListBox(pParent, rResId) {}

protected:
    virtual void RequestHelp( const HelpEvent& rHEvt );
};

// class SvxScriptingTabPage ---------------------------------------------

class SvtJavaOptions;
class SvtSecurityOptions;

class SvxScriptingTabPage : public SfxTabPage
{
private:
    // readonly ------------------------------------
    sal_Bool bROConfirm;
    sal_Bool bROWarning;
    sal_Bool bROScriptExec;
    sal_Bool bROExePlug;
    sal_Bool bROExecMacro;

    sal_Bool bROJavaEnabled;
    sal_Bool bROJavaSecurity;
    sal_Bool bROJavaNetAccess;
    sal_Bool bROJavaUserClassPath;
    sal_Bool bROJavaExecuteApplets;

    // Execute

    FixedLine           aGrpScriptingStarBasic;

    ReadOnlyImage       aExecMacroFI;
    FixedText           aExecMacroFT;
    ListBox             aExecMacroLB;

    ReadOnlyImage       aConfirmFI;
    CheckBox            aConfirmCB;

    ReadOnlyImage       aWarningFI;
    CheckBox            aWarningCB;

    ReadOnlyImage       aScriptExecFI;
    FixedText           aPathListFT;
    // #98647# ------------------------------------
    SvxScriptExecListBox aLbScriptExec;
    PushButton          aBtnScriptExecDelete;
    PushButton          aBtnScriptExecDefault;

    FixedText           aNewPathFT;
    Edit                aEdtScriptExec;
    PushButton          aBtnScriptExecInsert;

    FixedLine           aHyperlinksFL;
    ReadOnlyImage       aHyperlinksFI;
    FixedText           aHyperlinksFT;
    ListBox             aHyperlinksLB;

    FixedLine           aJavaFL;
    ReadOnlyImage       aJavaEnableFI;
    CheckBox            aJavaEnableCB;
    ReadOnlyImage       aJavaSecurityFI;
    CheckBox            aJavaSecurityCB;
    ReadOnlyImage       aNetAccessFI;
    FixedText           aNetAccessFT;
    ListBox             aNetAccessLB;
    FixedText           aClassPathFT;
    ReadOnlyImage       aClassPathFI;
    Edit                aClassPathED;
    PushButton          aClassPathPB;

    FixedLine           aSeparatorFL;

    FixedLine           aExecuteGB;
    ReadOnlyImage       aExePlugFI;
    CheckBox            aExePlugCB;
    ReadOnlyImage       aExecAppletsFI;
    CheckBox            aExecAppletsCB;

    Image               aLockImg;
    Image               aLockHCImg;

    SvtJavaOptions*     pJavaOptions;
    SvtSecurityOptions* pSecurityOptions;
#ifdef _SVX_OPTINET2_CXX
    DECL_LINK( EditHdl_Impl, Edit* );
    DECL_LINK( LBHdl_Impl, ListBox* );
    DECL_LINK( BtnHdl_Impl, PushButton* );
    DECL_LINK( RunHdl_Impl, ListBox* );
    DECL_LINK( JavaEnableHdl_Impl, CheckBox* );
    DECL_LINK( ClassPathHdl_Impl, PushButton* );

    void                FillListBox_Impl();
    void                EnableJava_Impl( BOOL bEnable, BOOL bOnlySecurity );
#endif
                SvxScriptingTabPage( Window* pParent, const SfxItemSet& rSet );
    virtual     ~SvxScriptingTabPage();

protected:
    virtual void        ActivatePage( const SfxItemSet& rSet );
    virtual int         DeactivatePage( SfxItemSet* pSet = 0 );

public:
    static SfxTabPage*  Create( Window* pParent, const SfxItemSet& rAttrSet );
    virtual BOOL        FillItemSet( SfxItemSet& rSet );
    virtual void        Reset( const SfxItemSet& rSet );
};

#endif

/* -----------------------------20.06.01 16:32--------------------------------

 ---------------------------------------------------------------------------*/
#ifdef WNT
#else
#define HELPER_PAGE_COMPLETE
#endif

struct SvxEMailTabPage_Impl;
class SvxEMailTabPage : public SfxTabPage
{
    FixedLine       aMailFL;
    ReadOnlyImage   aMailerURLFI;
    FixedText       aMailerURLFT;
    Edit            aMailerURLED;
    PushButton      aMailerURLPB;

    String          m_sDefaultFilterName;

    SvxEMailTabPage_Impl* pImpl;

    DECL_LINK(  FileDialogHdl_Impl, PushButton* ) ;

public:
    SvxEMailTabPage( Window* pParent, const SfxItemSet& rSet );
    ~SvxEMailTabPage();

    static SfxTabPage*  Create( Window* pParent, const SfxItemSet& rAttrSet );

    virtual BOOL        FillItemSet( SfxItemSet& rSet );
    virtual void        Reset( const SfxItemSet& rSet );
};

#endif // #ifndef _SVX_OPTINET_HXX

<|endoftext|>


<commit_before><commit_msg>Fix fdo#41995 fallout - recognize .svg in odf container<commit_after><|endoftext|>


<commit_before><commit_msg>coverity#704849 Unchecked dynamic_cast<commit_after><|endoftext|>


<commit_before>/*===================================================================
APM_PLANNER Open Source Ground Control Station

(c) 2013 APM_PLANNER PROJECT <http://www.diydrones.com>

This file is part of the APM_PLANNER project

    APM_PLANNER 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.

    APM_PLANNER 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 APM_PLANNER. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

/**
 * @file
 *   @brief APM Hardware Configuration widget source.
 *
 *   @author Michael Carpenter <malcom2073@gmail.com>
 *
 */
#include "QsLog.h"
#include "ApmHardwareConfig.h"

ApmHardwareConfig::ApmHardwareConfig(QWidget *parent) : QWidget(parent),
    m_paramDownloadState(none),
    m_paramDownloadCount(0),
    m_uas(NULL)
{
    ui.setupUi(this);

    ui.mandatoryHardware->setVisible(false);
    ui.frameTypeButton->setVisible(false);
    ui.compassButton->setVisible(false);
    ui.accelCalibrateButton->setVisible(false);
    ui.failSafeButton->setVisible(false);
    ui.flightModesButton->setVisible(false);
    ui.arduPlaneLevelButton->setVisible(false);
    ui.radioCalibrateButton->setVisible(false);
    ui.batteryMonitorButton->setVisible(false);
    ui.sonarButton->setVisible(false);
    ui.airspeedButton->setVisible(false);
    ui.opticalFlowButton->setVisible(false);
    ui.osdButton->setVisible(false);
    ui.cameraGimbalButton->setVisible(false);

    connect(ui.mandatoryHardware, SIGNAL(toggled(bool)),
            this, SLOT(toggleMandatoryShown(bool)));
    connect(ui.optionalHardwareButton, SIGNAL(toggled(bool)),
            this, SLOT(toggleOptionalShown(bool)));

    m_apmFirmwareConfig = new ApmFirmwareConfig(this);
    ui.stackedWidget->addWidget(m_apmFirmwareConfig); //Firmware placeholder.
    m_buttonToConfigWidgetMap[ui.firmwareButton] = m_apmFirmwareConfig;
    connect(ui.firmwareButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_flightConfig = new FlightModeConfig(this);
    ui.stackedWidget->addWidget(m_flightConfig);
    m_buttonToConfigWidgetMap[ui.flightModesButton] = m_flightConfig;
    connect(ui.flightModesButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_frameConfig = new FrameTypeConfig(this);
    ui.stackedWidget->addWidget(m_frameConfig);
    m_buttonToConfigWidgetMap[ui.frameTypeButton] = m_frameConfig;
    connect(ui.frameTypeButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_compassConfig = new CompassConfig(this);
    ui.stackedWidget->addWidget(m_compassConfig);
    m_buttonToConfigWidgetMap[ui.compassButton] = m_compassConfig;
    connect(ui.compassButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_failSafeConfig = new FailSafeConfig(this);
    ui.stackedWidget->addWidget(m_failSafeConfig);
    m_buttonToConfigWidgetMap[ui.failSafeButton] = m_failSafeConfig;
    connect(ui.failSafeButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_accelConfig = new AccelCalibrationConfig(this);
    ui.stackedWidget->addWidget(m_accelConfig);
    m_buttonToConfigWidgetMap[ui.accelCalibrateButton] = m_accelConfig;
    connect(ui.accelCalibrateButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_planeLevel = new ApmPlaneLevel(this);
    ui.stackedWidget->addWidget(m_planeLevel);
    m_buttonToConfigWidgetMap[ui.arduPlaneLevelButton] = m_planeLevel;
    connect(ui.arduPlaneLevelButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_radioConfig = new RadioCalibrationConfig(this);
    ui.stackedWidget->addWidget(m_radioConfig);
    m_buttonToConfigWidgetMap[ui.radioCalibrateButton] = m_radioConfig;
    connect(ui.radioCalibrateButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_radio3drConfig = new Radio3DRConfig(this);
    ui.stackedWidget->addWidget(m_radio3drConfig);
    m_buttonToConfigWidgetMap[ui.radio3DRButton] = m_radio3drConfig;
    connect(ui.radio3DRButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_batteryConfig = new BatteryMonitorConfig(this);
    ui.stackedWidget->addWidget(m_batteryConfig);
    m_buttonToConfigWidgetMap[ui.batteryMonitorButton] = m_batteryConfig;
    connect(ui.batteryMonitorButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_sonarConfig = new SonarConfig(this);
    ui.stackedWidget->addWidget(m_sonarConfig);
    m_buttonToConfigWidgetMap[ui.sonarButton] = m_sonarConfig;
    connect(ui.sonarButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_airspeedConfig = new AirspeedConfig(this);
    ui.stackedWidget->addWidget(m_airspeedConfig);
    m_buttonToConfigWidgetMap[ui.airspeedButton] = m_airspeedConfig;
    connect(ui.airspeedButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_opticalFlowConfig = new OpticalFlowConfig(this);
    ui.stackedWidget->addWidget(m_opticalFlowConfig);
    m_buttonToConfigWidgetMap[ui.opticalFlowButton] = m_opticalFlowConfig;
    connect(ui.opticalFlowButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_osdConfig = new OsdConfig(this);
    ui.stackedWidget->addWidget(m_osdConfig);
    m_buttonToConfigWidgetMap[ui.osdButton] = m_osdConfig;
    connect(ui.osdButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_cameraGimbalConfig = new CameraGimbalConfig(this);
    ui.stackedWidget->addWidget(m_cameraGimbalConfig);
    m_buttonToConfigWidgetMap[ui.cameraGimbalButton] = m_cameraGimbalConfig;
    connect(ui.cameraGimbalButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_antennaTrackerConfig = new AntennaTrackerConfig(this);
    ui.stackedWidget->addWidget(m_antennaTrackerConfig);
    m_buttonToConfigWidgetMap[ui.antennaTrackerButton] = m_antennaTrackerConfig;
    connect(ui.antennaTrackerButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));
    m_uas=0;
    connect(UASManager::instance(),SIGNAL(activeUASSet(UASInterface*)),this,SLOT(activeUASSet(UASInterface*)));
    if (UASManager::instance()->getActiveUAS())
    {
        activeUASSet(UASManager::instance()->getActiveUAS());
    }

    // Setup Parameter Progress bars
    ui.globalParamProgressBar->setRange(0,100);
}
void ApmHardwareConfig::activateStackedWidget()
{
    if (ui.failSafeButton == sender())
    {
        QMessageBox::information(this,"Warning","Ensure all rotors/props are REMOVED from your aircraft before proceeding");
    }
    if (m_buttonToConfigWidgetMap.contains(sender()))
    {
        ui.stackedWidget->setCurrentWidget(m_buttonToConfigWidgetMap[sender()]);
    }
}

ApmHardwareConfig::~ApmHardwareConfig()
{
}
void ApmHardwareConfig::uasConnected()
{
    if (!m_uas)
    {
        return;
    }
    // Hide offline options and show Optional and Mandatory buttons
    ui.radio3DRButton->setVisible(false);
    ui.antennaTrackerButton->setVisible(false);

    ui.mandatoryHardware->setVisible(true);
    ui.mandatoryHardware->setChecked(false);
    ui.optionalHardwareButton->setVisible(true);
    ui.optionalHardwareButton->setChecked(false);

    ui.mandatoryHardware->setAutoExclusive(true);
    ui.optionalHardwareButton->setAutoExclusive(true);
}

void ApmHardwareConfig::uasDisconnected()
{
    if (!m_uas)
    {
        return;
    }
    // Show offline options and hide Optional and Mandatory buttons
    ui.radio3DRButton->setVisible(true);
    ui.antennaTrackerButton->setVisible(true);

    ui.mandatoryHardware->setVisible(false);
    ui.mandatoryHardware->setChecked(false);
    ui.optionalHardwareButton->setChecked(false);

    ui.frameTypeButton->setShown(false);
    ui.sonarButton->setShown(false);
    ui.compassButton->setShown(false);
    ui.accelCalibrateButton->setShown(false);
    ui.radioCalibrateButton->setShown(false);

    ui.flightModesButton->setShown(false);
    ui.failSafeButton->setShown(false);

    ui.batteryMonitorButton->setShown(false);
    ui.airspeedButton->setShown(false);
    ui.opticalFlowButton->setShown(false);
    ui.osdButton->setShown(false);
    ui.cameraGimbalButton->setShown(false);

    ui.mandatoryHardware->setAutoExclusive(false);
    ui.optionalHardwareButton->setAutoExclusive(false);

    ui.stackedWidget->setCurrentWidget(m_buttonToConfigWidgetMap[ui.firmwareButton]);
}
void ApmHardwareConfig::activeUASSet(UASInterface *uas)
{
    if (m_uas)
    {
        uasDisconnected();
        disconnect(m_uas,SIGNAL(connected()),this,SLOT(uasConnected()));
        disconnect(m_uas,SIGNAL(disconnected()),this,SLOT(uasDisconnected()));

        disconnect(m_uas,SIGNAL(parameterChanged(int,int,int,int,QString,QVariant)),
                this,SLOT(parameterChanged(int,int,int,int,QString,QVariant)));

        m_uas = 0;
    }
    if (!uas)
    {
        return;
    }
    m_uas = uas;
    connect(m_uas,SIGNAL(connected()),this,SLOT(uasConnected()));
    connect(m_uas,SIGNAL(disconnected()),this,SLOT(uasDisconnected()));

    connect(m_uas,SIGNAL(parameterChanged(int,int,int,int,QString,QVariant)),
            this,SLOT(parameterChanged(int,int,int,int,QString,QVariant)));

    uasConnected();

}

void ApmHardwareConfig::toggleOptionalShown(bool show)
{
    QLOG_DEBUG() << "toggleOptionalShown" << show;
    if(!m_uas)
        return;
    toggleMandatoryShown(!show);
}

void ApmHardwareConfig::toggleMandatoryShown(bool show)
{
    QLOG_DEBUG() << "toggleMandatoryShown" << show;

    if(!m_uas)
        return;

    if (m_uas->isMultirotor()){
        QLOG_DEBUG() << "Multirotor";
        // Buttons to disable
        ui.airspeedButton->setShown(false);

        // Mandatory Options to show
        ui.frameTypeButton->setShown(show);
        ui.compassButton->setShown(show);
        ui.accelCalibrateButton->setShown(show);
        ui.radioCalibrateButton->setShown(show);
        ui.flightModesButton->setShown(show);
        ui.failSafeButton->setShown(show);

        // Optional Options to Hide
        ui.radio3DRButton->setShown(!show);
        ui.batteryMonitorButton->setShown(!show);
        ui.opticalFlowButton->setShown(!show);
        ui.osdButton->setShown(!show);
        ui.cameraGimbalButton->setShown(!show);
        ui.antennaTrackerButton->setShown(!show);
        ui.sonarButton->setShown(!show);

    } else if (m_uas->isFixedWing()){
        QLOG_DEBUG() << "FixedWing";
        // Buttons to disable
        ui.frameTypeButton->setShown(false);

        // Mandatory Options to show
        ui.compassButton->setShown(show);
        ui.accelCalibrateButton->setShown(show);
        ui.radioCalibrateButton->setShown(show);
        ui.flightModesButton->setShown(show);
        ui.failSafeButton->setShown(show);

        // Optional Options to Hide
        ui.radio3DRButton->setShown(!show);
        ui.batteryMonitorButton->setShown(!show);
        ui.opticalFlowButton->setShown(!show);
        ui.osdButton->setShown(!show);
        ui.cameraGimbalButton->setShown(!show);
        ui.antennaTrackerButton->setShown(!show);
        ui.airspeedButton->setShown(!show);

    } else {
        // Assume Ground Vehicle et al.
        QLOG_DEBUG() << "Ground Vehicle & Other";
        // Butons to disable
        ui.frameTypeButton->setShown(false);
        ui.airspeedButton->setShown(false);

        // Mandatory Options to show
        ui.compassButton->setShown(show);
        ui.accelCalibrateButton->setShown(show);
        ui.radioCalibrateButton->setShown(show);
        ui.flightModesButton->setShown(show);
        ui.failSafeButton->setShown(show);

        // Optional Options to Hide
        ui.radio3DRButton->setShown(!show);
        ui.batteryMonitorButton->setShown(!show);
        ui.opticalFlowButton->setShown(!show);
        ui.osdButton->setShown(!show);
        ui.cameraGimbalButton->setShown(!show);
        ui.antennaTrackerButton->setShown(!show);
        ui.sonarButton->setShown(!show);
    }
}

void ApmHardwareConfig::parameterChanged(int uas, int component, int parameterCount, int parameterId, QString parameterName, QVariant value)
{
    QString countString;
    // Create progress of downloading all parameters for UI
    switch (m_paramDownloadState){
    case none:
        if (parameterId == UINT16_MAX){
            // This is an ACK package, not a full read
            break;
        } else if ((parameterId == 0) && (parameterCount != UINT16_MAX)) {
            // Its a new download List, Start from zero.
            ui.globalParamStateLabel->setText(tr("Downloading Params..."));
        } else {
            break;
        }

        // Otherwise, trigger progress bar update.
    case startRead:
        QLOG_INFO() << "Starting Global Param Progress Bar Updating sys:" << uas;
        m_paramDownloadCount = 1;

        countString = QString::number(m_paramDownloadCount) + "/"
                        + QString::number(parameterCount);
        QLOG_INFO() << "Global Param Progress Bar: " << countString
                     << "paramId:" << parameterId << "name:" << parameterName
                     << "paramValue:" << value;
        ui.globalParamProgressLabel->setText(countString);
        ui.globalParamProgressBar->setValue((m_paramDownloadCount/(float)parameterCount)*100.0);

        m_paramDownloadState = readingParams;
        break;

    case readingParams:
        m_paramDownloadCount++;
        countString = QString::number(m_paramDownloadCount) + "/"
                        + QString::number(parameterCount);
        QLOG_INFO() << "Param Progress Bar: " << countString
                     << "paramId:" << parameterId << "name:" << parameterName
                     << "paramValue:" << value;
        ui.globalParamProgressLabel->setText(countString);
        ui.globalParamProgressBar->setValue((m_paramDownloadCount/(float)parameterCount)*100.0);

        if (m_paramDownloadCount == parameterCount){
            m_paramDownloadState = completed;
            ui.globalParamStateLabel->setText(tr("Params Downloaded"));
        }
        break;

    case completed:
        QLOG_INFO() << "Global Finished Downloading Params" << m_paramDownloadCount;
        m_paramDownloadState = none;
        break;

    default:
        ; // Do Nothing
    }
}
<commit_msg>Fixes issue with Optional Button clicked would show unavailable options when disconnected<commit_after>/*===================================================================
APM_PLANNER Open Source Ground Control Station

(c) 2013 APM_PLANNER PROJECT <http://www.diydrones.com>

This file is part of the APM_PLANNER project

    APM_PLANNER 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.

    APM_PLANNER 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 APM_PLANNER. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

/**
 * @file
 *   @brief APM Hardware Configuration widget source.
 *
 *   @author Michael Carpenter <malcom2073@gmail.com>
 *
 */
#include "QsLog.h"
#include "ApmHardwareConfig.h"

ApmHardwareConfig::ApmHardwareConfig(QWidget *parent) : QWidget(parent),
    m_paramDownloadState(none),
    m_paramDownloadCount(0),
    m_uas(NULL)
{
    ui.setupUi(this);

    ui.mandatoryHardware->setVisible(false);
    ui.frameTypeButton->setVisible(false);
    ui.compassButton->setVisible(false);
    ui.accelCalibrateButton->setVisible(false);
    ui.failSafeButton->setVisible(false);
    ui.flightModesButton->setVisible(false);
    ui.arduPlaneLevelButton->setVisible(false);
    ui.radioCalibrateButton->setVisible(false);
    ui.batteryMonitorButton->setVisible(false);
    ui.sonarButton->setVisible(false);
    ui.airspeedButton->setVisible(false);
    ui.opticalFlowButton->setVisible(false);
    ui.osdButton->setVisible(false);
    ui.cameraGimbalButton->setVisible(false);

    m_apmFirmwareConfig = new ApmFirmwareConfig(this);
    ui.stackedWidget->addWidget(m_apmFirmwareConfig); //Firmware placeholder.
    m_buttonToConfigWidgetMap[ui.firmwareButton] = m_apmFirmwareConfig;
    connect(ui.firmwareButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_flightConfig = new FlightModeConfig(this);
    ui.stackedWidget->addWidget(m_flightConfig);
    m_buttonToConfigWidgetMap[ui.flightModesButton] = m_flightConfig;
    connect(ui.flightModesButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_frameConfig = new FrameTypeConfig(this);
    ui.stackedWidget->addWidget(m_frameConfig);
    m_buttonToConfigWidgetMap[ui.frameTypeButton] = m_frameConfig;
    connect(ui.frameTypeButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_compassConfig = new CompassConfig(this);
    ui.stackedWidget->addWidget(m_compassConfig);
    m_buttonToConfigWidgetMap[ui.compassButton] = m_compassConfig;
    connect(ui.compassButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_failSafeConfig = new FailSafeConfig(this);
    ui.stackedWidget->addWidget(m_failSafeConfig);
    m_buttonToConfigWidgetMap[ui.failSafeButton] = m_failSafeConfig;
    connect(ui.failSafeButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_accelConfig = new AccelCalibrationConfig(this);
    ui.stackedWidget->addWidget(m_accelConfig);
    m_buttonToConfigWidgetMap[ui.accelCalibrateButton] = m_accelConfig;
    connect(ui.accelCalibrateButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_planeLevel = new ApmPlaneLevel(this);
    ui.stackedWidget->addWidget(m_planeLevel);
    m_buttonToConfigWidgetMap[ui.arduPlaneLevelButton] = m_planeLevel;
    connect(ui.arduPlaneLevelButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_radioConfig = new RadioCalibrationConfig(this);
    ui.stackedWidget->addWidget(m_radioConfig);
    m_buttonToConfigWidgetMap[ui.radioCalibrateButton] = m_radioConfig;
    connect(ui.radioCalibrateButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_radio3drConfig = new Radio3DRConfig(this);
    ui.stackedWidget->addWidget(m_radio3drConfig);
    m_buttonToConfigWidgetMap[ui.radio3DRButton] = m_radio3drConfig;
    connect(ui.radio3DRButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_batteryConfig = new BatteryMonitorConfig(this);
    ui.stackedWidget->addWidget(m_batteryConfig);
    m_buttonToConfigWidgetMap[ui.batteryMonitorButton] = m_batteryConfig;
    connect(ui.batteryMonitorButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_sonarConfig = new SonarConfig(this);
    ui.stackedWidget->addWidget(m_sonarConfig);
    m_buttonToConfigWidgetMap[ui.sonarButton] = m_sonarConfig;
    connect(ui.sonarButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_airspeedConfig = new AirspeedConfig(this);
    ui.stackedWidget->addWidget(m_airspeedConfig);
    m_buttonToConfigWidgetMap[ui.airspeedButton] = m_airspeedConfig;
    connect(ui.airspeedButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_opticalFlowConfig = new OpticalFlowConfig(this);
    ui.stackedWidget->addWidget(m_opticalFlowConfig);
    m_buttonToConfigWidgetMap[ui.opticalFlowButton] = m_opticalFlowConfig;
    connect(ui.opticalFlowButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_osdConfig = new OsdConfig(this);
    ui.stackedWidget->addWidget(m_osdConfig);
    m_buttonToConfigWidgetMap[ui.osdButton] = m_osdConfig;
    connect(ui.osdButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_cameraGimbalConfig = new CameraGimbalConfig(this);
    ui.stackedWidget->addWidget(m_cameraGimbalConfig);
    m_buttonToConfigWidgetMap[ui.cameraGimbalButton] = m_cameraGimbalConfig;
    connect(ui.cameraGimbalButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));

    m_antennaTrackerConfig = new AntennaTrackerConfig(this);
    ui.stackedWidget->addWidget(m_antennaTrackerConfig);
    m_buttonToConfigWidgetMap[ui.antennaTrackerButton] = m_antennaTrackerConfig;
    connect(ui.antennaTrackerButton,SIGNAL(clicked()),this,SLOT(activateStackedWidget()));
    m_uas=0;
    connect(UASManager::instance(),SIGNAL(activeUASSet(UASInterface*)),this,SLOT(activeUASSet(UASInterface*)));
    if (UASManager::instance()->getActiveUAS())
    {
        activeUASSet(UASManager::instance()->getActiveUAS());
    }

    // Setup Parameter Progress bars
    ui.globalParamProgressBar->setRange(0,100);
}
void ApmHardwareConfig::activateStackedWidget()
{
    if (ui.failSafeButton == sender())
    {
        QMessageBox::information(this,"Warning","Ensure all rotors/props are REMOVED from your aircraft before proceeding");
    }
    if (m_buttonToConfigWidgetMap.contains(sender()))
    {
        ui.stackedWidget->setCurrentWidget(m_buttonToConfigWidgetMap[sender()]);
    }
}

ApmHardwareConfig::~ApmHardwareConfig()
{
}
void ApmHardwareConfig::uasConnected()
{
    if (!m_uas)
    {
        return;
    }
    QLOG_DEBUG() << "AHC: uasConnected()";
    // Hide offline options and show Optional and Mandatory buttons
    ui.radio3DRButton->setVisible(false);
    ui.antennaTrackerButton->setVisible(false);

    ui.mandatoryHardware->setVisible(true);
    ui.mandatoryHardware->setChecked(false);
    ui.optionalHardwareButton->setVisible(true);
    ui.optionalHardwareButton->setChecked(false);

    ui.mandatoryHardware->setAutoExclusive(true);
    ui.optionalHardwareButton->setAutoExclusive(true);

    connect(ui.mandatoryHardware, SIGNAL(toggled(bool)),
            this, SLOT(toggleMandatoryShown(bool)));
    connect(ui.optionalHardwareButton, SIGNAL(toggled(bool)),
            this, SLOT(toggleOptionalShown(bool)));

}

void ApmHardwareConfig::uasDisconnected()
{
    if (!m_uas)
    {
        return;
    }
    QLOG_DEBUG() << "AHC: uasDisconnected()";
    // Show offline options and hide Optional and Mandatory buttons
    ui.mandatoryHardware->setAutoExclusive(false);
    ui.optionalHardwareButton->setAutoExclusive(false);

    disconnect(ui.mandatoryHardware, SIGNAL(toggled(bool)),
                this, SLOT(toggleMandatoryShown(bool)));
    disconnect(ui.optionalHardwareButton, SIGNAL(toggled(bool)),
                this, SLOT(toggleOptionalShown(bool)));

    ui.optionalHardwareButton->setChecked(true);
    ui.radio3DRButton->setVisible(true);
    ui.antennaTrackerButton->setVisible(true);

    ui.mandatoryHardware->setVisible(false);
    ui.mandatoryHardware->setChecked(false);

    ui.frameTypeButton->setShown(false);
    ui.sonarButton->setShown(false);
    ui.compassButton->setShown(false);
    ui.accelCalibrateButton->setShown(false);
    ui.radioCalibrateButton->setShown(false);

    ui.flightModesButton->setShown(false);
    ui.failSafeButton->setShown(false);

    ui.batteryMonitorButton->setShown(false);
    ui.airspeedButton->setShown(false);
    ui.opticalFlowButton->setShown(false);
    ui.osdButton->setShown(false);
    ui.cameraGimbalButton->setShown(false);

    ui.stackedWidget->setCurrentWidget(m_buttonToConfigWidgetMap[ui.firmwareButton]);
}
void ApmHardwareConfig::activeUASSet(UASInterface *uas)
{
    if (m_uas)
    {
        uasDisconnected();
        disconnect(m_uas,SIGNAL(connected()),this,SLOT(uasConnected()));
        disconnect(m_uas,SIGNAL(disconnected()),this,SLOT(uasDisconnected()));

        disconnect(m_uas,SIGNAL(parameterChanged(int,int,int,int,QString,QVariant)),
                this,SLOT(parameterChanged(int,int,int,int,QString,QVariant)));

        m_uas = 0;
    }
    if (!uas)
    {
        return;
    }
    m_uas = uas;
    connect(m_uas,SIGNAL(connected()),this,SLOT(uasConnected()));
    connect(m_uas,SIGNAL(disconnected()),this,SLOT(uasDisconnected()));

    connect(m_uas,SIGNAL(parameterChanged(int,int,int,int,QString,QVariant)),
            this,SLOT(parameterChanged(int,int,int,int,QString,QVariant)));

    uasConnected();

}

void ApmHardwareConfig::toggleOptionalShown(bool show)
{
    QLOG_DEBUG() << "toggleOptionalShown" << show;
    if(!m_uas)
        return;
    toggleMandatoryShown(!show);
}

void ApmHardwareConfig::toggleMandatoryShown(bool show)
{
    QLOG_DEBUG() << "toggleMandatoryShown" << show;

    if(!m_uas)
        return;

    if (m_uas->isMultirotor()){
        QLOG_DEBUG() << "Multirotor";
        // Buttons to disable
        ui.airspeedButton->setShown(false);

        // Mandatory Options to show
        ui.frameTypeButton->setShown(show);
        ui.compassButton->setShown(show);
        ui.accelCalibrateButton->setShown(show);
        ui.radioCalibrateButton->setShown(show);
        ui.flightModesButton->setShown(show);
        ui.failSafeButton->setShown(show);

        // Optional Options to Hide
        ui.radio3DRButton->setShown(!show);
        ui.batteryMonitorButton->setShown(!show);
        ui.opticalFlowButton->setShown(!show);
        ui.osdButton->setShown(!show);
        ui.cameraGimbalButton->setShown(!show);
        ui.antennaTrackerButton->setShown(!show);
        ui.sonarButton->setShown(!show);

    } else if (m_uas->isFixedWing()){
        QLOG_DEBUG() << "FixedWing";
        // Buttons to disable
        ui.frameTypeButton->setShown(false);

        // Mandatory Options to show
        ui.compassButton->setShown(show);
        ui.accelCalibrateButton->setShown(show);
        ui.radioCalibrateButton->setShown(show);
        ui.flightModesButton->setShown(show);
        ui.failSafeButton->setShown(show);

        // Optional Options to Hide
        ui.radio3DRButton->setShown(!show);
        ui.batteryMonitorButton->setShown(!show);
        ui.opticalFlowButton->setShown(!show);
        ui.osdButton->setShown(!show);
        ui.cameraGimbalButton->setShown(!show);
        ui.antennaTrackerButton->setShown(!show);
        ui.airspeedButton->setShown(!show);

    } else {
        // Assume Ground Vehicle et al.
        QLOG_DEBUG() << "Ground Vehicle & Other";
        // Butons to disable
        ui.frameTypeButton->setShown(false);
        ui.airspeedButton->setShown(false);

        // Mandatory Options to show
        ui.compassButton->setShown(show);
        ui.accelCalibrateButton->setShown(show);
        ui.radioCalibrateButton->setShown(show);
        ui.flightModesButton->setShown(show);
        ui.failSafeButton->setShown(show);

        // Optional Options to Hide
        ui.radio3DRButton->setShown(!show);
        ui.batteryMonitorButton->setShown(!show);
        ui.opticalFlowButton->setShown(!show);
        ui.osdButton->setShown(!show);
        ui.cameraGimbalButton->setShown(!show);
        ui.antennaTrackerButton->setShown(!show);
        ui.sonarButton->setShown(!show);
    }
}

void ApmHardwareConfig::parameterChanged(int uas, int component, int parameterCount, int parameterId, QString parameterName, QVariant value)
{
    QString countString;
    // Create progress of downloading all parameters for UI
    switch (m_paramDownloadState){
    case none:
        if (parameterId == UINT16_MAX){
            // This is an ACK package, not a full read
            break;
        } else if ((parameterId == 0) && (parameterCount != UINT16_MAX)) {
            // Its a new download List, Start from zero.
            ui.globalParamStateLabel->setText(tr("Downloading Params..."));
        } else {
            break;
        }

        // Otherwise, trigger progress bar update.
    case startRead:
        QLOG_INFO() << "Starting Global Param Progress Bar Updating sys:" << uas;
        m_paramDownloadCount = 1;

        countString = QString::number(m_paramDownloadCount) + "/"
                        + QString::number(parameterCount);
        QLOG_INFO() << "Global Param Progress Bar: " << countString
                     << "paramId:" << parameterId << "name:" << parameterName
                     << "paramValue:" << value;
        ui.globalParamProgressLabel->setText(countString);
        ui.globalParamProgressBar->setValue((m_paramDownloadCount/(float)parameterCount)*100.0);

        m_paramDownloadState = readingParams;
        break;

    case readingParams:
        m_paramDownloadCount++;
        countString = QString::number(m_paramDownloadCount) + "/"
                        + QString::number(parameterCount);
        QLOG_INFO() << "Param Progress Bar: " << countString
                     << "paramId:" << parameterId << "name:" << parameterName
                     << "paramValue:" << value;
        ui.globalParamProgressLabel->setText(countString);
        ui.globalParamProgressBar->setValue((m_paramDownloadCount/(float)parameterCount)*100.0);

        if (m_paramDownloadCount == parameterCount){
            m_paramDownloadState = completed;
            ui.globalParamStateLabel->setText(tr("Params Downloaded"));
        }
        break;

    case completed:
        QLOG_INFO() << "Global Finished Downloading Params" << m_paramDownloadCount;
        m_paramDownloadState = none;
        break;

    default:
        ; // Do Nothing
    }
}
<|endoftext|>


<commit_before>//===----------------------------------------------------------------------===//
//
//                         Peloton
//
// index_factory.cpp
//
// Identification: src/index/index_factory.cpp
//
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include <iostream>

#include "common/logger.h"
#include "common/macros.h"
#include "index/bwtree_index.h"
#include "index/index_factory.h"
#include "index/index_key.h"
#include "type/types.h"

namespace peloton {
namespace index {

Index *IndexFactory::GetIndex(IndexMetadata *metadata) {
  LOG_TRACE("Creating index %s", metadata->GetName().c_str());

  // The size of the key in bytes
  const auto key_size = metadata->key_schema->GetLength();
  LOG_TRACE("key_size : %d", key_size);
  LOG_TRACE("Indexed column count: %ld",
            metadata->key_schema->GetIndexedColumns().size());

  // Check whether the index key only has ints.
  // If so, then we can rock a specialized IntsKeyComparator
  // that is faster than the FastGenericComparator
  bool ints_only = true;
  for (auto column : metadata->key_schema->GetColumns()) {
    auto col_type = column.GetType();
    if (col_type != type::Type::TINYINT && col_type != type::Type::SMALLINT &&
        col_type != type::Type::INTEGER && col_type != type::Type::BIGINT) {
      ints_only = false;
      break;
    }
  }  // FOR

  // If we want to use a specialized IntsKey template, make sure that
  // we are not longer than the largest IntsKey that we have
  if (ints_only && key_size > sizeof(uint64_t) * INTSKEY_MAX_SLOTS) {
    ints_only = false;
  }

  auto index_type = metadata->GetIndexType();
  Index *index = nullptr;
  LOG_TRACE("Index type : %d", index_type);

  // -----------------------
  // BW-TREE
  // -----------------------
  if (index_type == INDEX_TYPE_BWTREE) {
    if (ints_only) {
      index = IndexFactory::GetBwTreeIntsKeyIndex(metadata);
    } else {
      index = IndexFactory::GetBwTreeGenericKeyIndex(metadata);
    }

    // -----------------------
    // ERROR
    // -----------------------
  } else {
    throw IndexException("Unsupported index scheme.");
  }
  PL_ASSERT(index != nullptr);

  return (index);
}

Index *IndexFactory::GetBwTreeIntsKeyIndex(IndexMetadata *metadata) {
  // Our new Index!
  Index *index = nullptr;

  // The size of the key in bytes
  const auto key_size = metadata->key_schema->GetLength();

  // Debug Output
#ifdef LOG_TRACE_ENABLED
  std::string comparatorType;
#endif

  if (key_size <= sizeof(uint64_t)) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "CompactIntsKey<1>";
#endif
    index = \
        new BWTreeIndex<CompactIntsKey<1>,
        ItemPointer *,
        CompactIntsComparator<1>,
        CompactIntsEqualityChecker<1>,
        CompactIntsHasher<1>,
        ItemPointerComparator,
        ItemPointerHashFunc>(metadata);
  } else if (key_size <= sizeof(uint64_t) * 2) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "CompactIntsKey<2>";
#endif
    index = \
        new BWTreeIndex<CompactIntsKey<2>,
        ItemPointer *,
        CompactIntsComparator<2>,
        CompactIntsEqualityChecker<2>,
        CompactIntsHasher<2>,
        ItemPointerComparator,
        ItemPointerHashFunc>(metadata);
  } else if (key_size <= sizeof(uint64_t) * 3) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "CompactIntsKey<3>";
#endif
    index = \
        new BWTreeIndex<CompactIntsKey<3>,
        ItemPointer *,
        CompactIntsComparator<3>,
        CompactIntsEqualityChecker<3>,
        CompactIntsHasher<3>,
        ItemPointerComparator,
        ItemPointerHashFunc>(metadata);
  } else if (key_size <= sizeof(uint64_t) * 4) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "CompactIntsKey<4>";
#endif
    index = \
        new BWTreeIndex<CompactIntsKey<4>,
        ItemPointer *,
        CompactIntsComparator<4>,
        CompactIntsEqualityChecker<4>,
        CompactIntsHasher<4>,
        ItemPointerComparator,
        ItemPointerHashFunc>(metadata);
  } else {
    throw IndexException("Unsupported IntsKey scheme");
  }

#ifdef LOG_TRACE_ENABLED
  LOG_TRACE("%s", IndexFactory::GetInfo(metadata, comparatorType).c_str());
#endif
  return (index);
}

Index *IndexFactory::GetBwTreeGenericKeyIndex(IndexMetadata *metadata) {
  // Our new Index!
  Index *index = nullptr;

  // The size of the key in bytes
  const auto key_size = metadata->key_schema->GetLength();

  // Debug Output
#ifdef LOG_TRACE_ENABLED
  std::string comparatorType;
#endif

  if (key_size <= 4) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "GenericKey<4>";
#endif
    index =
        new BWTreeIndex<GenericKey<4>,
<<<<<<< HEAD
                        ItemPointer *,
                        FastGenericComparator<4>,
                        GenericEqualityChecker<4>,
                        GenericHasher<4>,
                        ItemPointerComparator,
                        ItemPointerHashFunc>(metadata);
=======
        ItemPointer *,
        GenericComparator<4>,
        GenericEqualityChecker<4>,
        GenericHasher<4>,
        ItemPointerComparator,
        ItemPointerHashFunc>(metadata);
>>>>>>> Removed libcds and btree index
  } else if (key_size <= 8) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "GenericKey<8>";
#endif
    index =
        new BWTreeIndex<GenericKey<8>,
<<<<<<< HEAD
                        ItemPointer *,
                        FastGenericComparator<8>,
                        GenericEqualityChecker<8>,
                        GenericHasher<8>,
                        ItemPointerComparator,
                        ItemPointerHashFunc>(metadata);
=======
        ItemPointer *,
        GenericComparator<8>,
        GenericEqualityChecker<8>,
        GenericHasher<8>,
        ItemPointerComparator,
        ItemPointerHashFunc>(metadata);
>>>>>>> Removed libcds and btree index
  } else if (key_size <= 16) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "GenericKey<16>";
#endif
    index =
        new BWTreeIndex<GenericKey<16>,
<<<<<<< HEAD
                        ItemPointer *,
                        FastGenericComparator<16>,
                        GenericEqualityChecker<16>,
                        GenericHasher<16>,
                        ItemPointerComparator,
                        ItemPointerHashFunc>(metadata);
=======
        ItemPointer *,
        GenericComparator<16>,
        GenericEqualityChecker<16>,
        GenericHasher<16>,
        ItemPointerComparator,
        ItemPointerHashFunc>(metadata);
>>>>>>> Removed libcds and btree index
  } else if (key_size <= 64) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "GenericKey<64>";
#endif
    index =
        new BWTreeIndex<GenericKey<64>,
<<<<<<< HEAD
                        ItemPointer *,
                        FastGenericComparator<64>,
                        GenericEqualityChecker<64>,
                        GenericHasher<64>,
                        ItemPointerComparator,
                        ItemPointerHashFunc>(metadata);
=======
        ItemPointer *,
        GenericComparator<64>,
        GenericEqualityChecker<64>,
        GenericHasher<64>,
        ItemPointerComparator,
        ItemPointerHashFunc>(metadata);
>>>>>>> Removed libcds and btree index
  } else if (key_size <= 256) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "GenericKey<256>";
#endif
    index =
        new BWTreeIndex<GenericKey<256>,
<<<<<<< HEAD
                        ItemPointer *,
                        FastGenericComparator<256>,
                        GenericEqualityChecker<256>,
                        GenericHasher<256>,
                        ItemPointerComparator,
                        ItemPointerHashFunc>(metadata);
=======
        ItemPointer *,
        GenericComparator<256>,
        GenericEqualityChecker<256>,
        GenericHasher<256>,
        ItemPointerComparator,
        ItemPointerHashFunc>(metadata);
>>>>>>> Removed libcds and btree index
  } else {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "TupleKey";
#endif
    index =
        new BWTreeIndex<TupleKey,
        ItemPointer *,
        TupleKeyComparator,
        TupleKeyEqualityChecker,
        TupleKeyHasher,
        ItemPointerComparator,
        ItemPointerHashFunc>(metadata);
  }

#ifdef LOG_TRACE_ENABLED
  LOG_TRACE("%s", IndexFactory::GetInfo(metadata, comparatorType).c_str());
#endif
  return (index);
}

std::string IndexFactory::GetInfo(IndexMetadata *metadata,
                                  std::string comparatorType) {
  std::ostringstream os;
  os << "Index '" << metadata->GetName() << "' => "
      << IndexTypeToString(metadata->GetIndexType())
      << "::" << comparatorType << "(";
  bool first = true;
  for (auto column : metadata->key_schema->GetColumns()) {
    if (first == false) os << ", ";
    os << column.GetName();
    first = false;
  }
  os << ")";
  return (os.str());
}

}  // End index namespace
}  // End peloton namespace
<commit_msg>Fixed merge conflict<commit_after>//===----------------------------------------------------------------------===//
//
//                         Peloton
//
// index_factory.cpp
//
// Identification: src/index/index_factory.cpp
//
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include <iostream>

#include "common/logger.h"
#include "common/macros.h"
#include "index/bwtree_index.h"
#include "index/index_factory.h"
#include "index/index_key.h"
#include "type/types.h"

namespace peloton {
namespace index {

Index *IndexFactory::GetIndex(IndexMetadata *metadata) {
  LOG_TRACE("Creating index %s", metadata->GetName().c_str());

  // The size of the key in bytes
  const auto key_size = metadata->key_schema->GetLength();
  LOG_TRACE("key_size : %d", key_size);
  LOG_TRACE("Indexed column count: %ld",
            metadata->key_schema->GetIndexedColumns().size());

  // Check whether the index key only has ints.
  // If so, then we can rock a specialized IntsKeyComparator
  // that is faster than the FastGenericComparator
  bool ints_only = true;
  for (auto column : metadata->key_schema->GetColumns()) {
    auto col_type = column.GetType();
    if (col_type != type::Type::TINYINT && col_type != type::Type::SMALLINT &&
        col_type != type::Type::INTEGER && col_type != type::Type::BIGINT) {
      ints_only = false;
      break;
    }
  }  // FOR

  // If we want to use a specialized IntsKey template, make sure that
  // we are not longer than the largest IntsKey that we have
  if (ints_only && key_size > sizeof(uint64_t) * INTSKEY_MAX_SLOTS) {
    ints_only = false;
  }

  auto index_type = metadata->GetIndexType();
  Index *index = nullptr;
  LOG_TRACE("Index type : %d", index_type);

  // -----------------------
  // BW-TREE
  // -----------------------
  if (index_type == INDEX_TYPE_BWTREE) {
    if (ints_only) {
      index = IndexFactory::GetBwTreeIntsKeyIndex(metadata);
    } else {
      index = IndexFactory::GetBwTreeGenericKeyIndex(metadata);
    }

    // -----------------------
    // ERROR
    // -----------------------
  } else {
    throw IndexException("Unsupported index scheme.");
  }
  PL_ASSERT(index != nullptr);

  return (index);
}

Index *IndexFactory::GetBwTreeIntsKeyIndex(IndexMetadata *metadata) {
  // Our new Index!
  Index *index = nullptr;

  // The size of the key in bytes
  const auto key_size = metadata->key_schema->GetLength();

  // Debug Output
#ifdef LOG_TRACE_ENABLED
  std::string comparatorType;
#endif

  if (key_size <= sizeof(uint64_t)) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "CompactIntsKey<1>";
#endif
    index = \
        new BWTreeIndex<CompactIntsKey<1>,
        ItemPointer *,
        CompactIntsComparator<1>,
        CompactIntsEqualityChecker<1>,
        CompactIntsHasher<1>,
        ItemPointerComparator,
        ItemPointerHashFunc>(metadata);
  } else if (key_size <= sizeof(uint64_t) * 2) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "CompactIntsKey<2>";
#endif
    index = \
        new BWTreeIndex<CompactIntsKey<2>,
        ItemPointer *,
        CompactIntsComparator<2>,
        CompactIntsEqualityChecker<2>,
        CompactIntsHasher<2>,
        ItemPointerComparator,
        ItemPointerHashFunc>(metadata);
  } else if (key_size <= sizeof(uint64_t) * 3) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "CompactIntsKey<3>";
#endif
    index = \
        new BWTreeIndex<CompactIntsKey<3>,
        ItemPointer *,
        CompactIntsComparator<3>,
        CompactIntsEqualityChecker<3>,
        CompactIntsHasher<3>,
        ItemPointerComparator,
        ItemPointerHashFunc>(metadata);
  } else if (key_size <= sizeof(uint64_t) * 4) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "CompactIntsKey<4>";
#endif
    index = \
        new BWTreeIndex<CompactIntsKey<4>,
        ItemPointer *,
        CompactIntsComparator<4>,
        CompactIntsEqualityChecker<4>,
        CompactIntsHasher<4>,
        ItemPointerComparator,
        ItemPointerHashFunc>(metadata);
  } else {
    throw IndexException("Unsupported IntsKey scheme");
  }

#ifdef LOG_TRACE_ENABLED
  LOG_TRACE("%s", IndexFactory::GetInfo(metadata, comparatorType).c_str());
#endif
  return (index);
}

Index *IndexFactory::GetBwTreeGenericKeyIndex(IndexMetadata *metadata) {
  // Our new Index!
  Index *index = nullptr;

  // The size of the key in bytes
  const auto key_size = metadata->key_schema->GetLength();

  // Debug Output
#ifdef LOG_TRACE_ENABLED
  std::string comparatorType;
#endif

  if (key_size <= 4) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "GenericKey<4>";
#endif
    index =
        new BWTreeIndex<GenericKey<4>,
                        ItemPointer *,
                        FastGenericComparator<4>,
                        GenericEqualityChecker<4>,
                        GenericHasher<4>,
                        ItemPointerComparator,
                        ItemPointerHashFunc>(metadata);
  } else if (key_size <= 8) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "GenericKey<8>";
#endif
    index =
        new BWTreeIndex<GenericKey<8>,
                        ItemPointer *,
                        FastGenericComparator<8>,
                        GenericEqualityChecker<8>,
                        GenericHasher<8>,
                        ItemPointerComparator,
                        ItemPointerHashFunc>(metadata);
  } else if (key_size <= 16) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "GenericKey<16>";
#endif
    index =
        new BWTreeIndex<GenericKey<16>,
                        ItemPointer *,
                        FastGenericComparator<16>,
                        GenericEqualityChecker<16>,
                        GenericHasher<16>,
                        ItemPointerComparator,
                        ItemPointerHashFunc>(metadata);
  } else if (key_size <= 64) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "GenericKey<64>";
#endif
    index =
        new BWTreeIndex<GenericKey<64>,
                        ItemPointer *,
                        FastGenericComparator<64>,
                        GenericEqualityChecker<64>,
                        GenericHasher<64>,
                        ItemPointerComparator,
                        ItemPointerHashFunc>(metadata);
  } else if (key_size <= 256) {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "GenericKey<256>";
#endif
    index =
        new BWTreeIndex<GenericKey<256>,
                        ItemPointer *,
                        FastGenericComparator<256>,
                        GenericEqualityChecker<256>,
                        GenericHasher<256>,
                        ItemPointerComparator,
                        ItemPointerHashFunc>(metadata);
  } else {
#ifdef LOG_TRACE_ENABLED
    comparatorType = "TupleKey";
#endif
    index =
        new BWTreeIndex<TupleKey,
        ItemPointer *,
        TupleKeyComparator,
        TupleKeyEqualityChecker,
        TupleKeyHasher,
        ItemPointerComparator,
        ItemPointerHashFunc>(metadata);
  }

#ifdef LOG_TRACE_ENABLED
  LOG_TRACE("%s", IndexFactory::GetInfo(metadata, comparatorType).c_str());
#endif
  return (index);
}

std::string IndexFactory::GetInfo(IndexMetadata *metadata,
                                  std::string comparatorType) {
  std::ostringstream os;
  os << "Index '" << metadata->GetName() << "' => "
      << IndexTypeToString(metadata->GetIndexType())
      << "::" << comparatorType << "(";
  bool first = true;
  for (auto column : metadata->key_schema->GetColumns()) {
    if (first == false) os << ", ";
    os << column.GetName();
    first = false;
  }
  os << ")";
  return (os.str());
}

}  // End index namespace
}  // End peloton namespace
<|endoftext|>


<commit_before>#include "stdafx.h"
#include "PyMI.h"
#include "Utils.h"
#include "instance.h"

#include <datetime.h>

void GetIndexOrName(PyObject *item, std::wstring& name, Py_ssize_t& i)
{
    name.clear();
    i = -1;

#ifndef IS_PY3K
    if (PyString_Check(item))
    {
        char* s = PyString_AsString(item);
        DWORD len = lstrlenA(s) + 1;
        wchar_t* w = new wchar_t[len];

        if (::MultiByteToWideChar(CP_ACP, 0, s, len, w, len) != len)
        {
            delete [] w;
            throw MI::Exception(L"MultiByteToWideChar failed");
        }
        name.assign(w, len);
        delete[] w;
    }
    else
#endif
    if (PyUnicode_Check(item))
    {
        DWORD len = PyUnicode_GetSize(item) + 1;
        wchar_t* w = new wchar_t[len];

        if (PyUnicode_AsWideChar((PYUNICODEASVARCHARARG1TYPE*)item, w, len) < 0)
        {
            delete[] w;
            throw MI::Exception(L"PyUnicode_AsWideChar failed");
        }
        name.assign(w, len);
        delete[] w;
    }
    else if (PyIndex_Check(item))
    {
        i = PyNumber_AsSsize_t(item, PyExc_IndexError);
        if (i == -1 && PyErr_Occurred())
            throw MI::Exception(L"Index error");
    }
    else
        throw MI::Exception(L"Invalid name or index");
}

void Py2MI(PyObject* pyValue, MI_Value& value, MI_Type valueType)
{
    ZeroMemory(&value, sizeof(value));

    if (pyValue == Py_None)
    {
        return;
    }
    if (PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyBool_Type)))
    {
        value.boolean = PyObject_IsTrue(pyValue) ? MI_TRUE : MI_FALSE;
    }
    else if (PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyLong_Type)))
    {
        switch (valueType)
        {
        case MI_UINT8:
            value.uint8 = (MI_Uint8)PyLong_AsUnsignedLong(pyValue);
            break;
        case MI_SINT8:
            value.sint8 = (MI_Sint8)PyLong_AsLong(pyValue);
            break;
        case MI_UINT16:
            value.uint16 = (MI_Uint16)PyLong_AsUnsignedLong(pyValue);
            break;
        case MI_SINT16:
            value.sint16 = (MI_Sint16)PyLong_AsLong(pyValue);
            break;
        case MI_UINT32:
            value.uint32 = PyLong_AsUnsignedLong(pyValue);
            break;
        case MI_SINT32:
            value.sint32 = PyLong_AsLong(pyValue);
            break;
        case MI_UINT64:
            value.uint64 = PyLong_AsUnsignedLongLong(pyValue);
            break;
        case MI_SINT64:
            value.sint64 = PyLong_AsLongLong(pyValue);
            break;
        default:
            throw TypeConversionException();
        }
    }
#ifndef IS_PY3K
    else if (PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyInt_Type)))
    {
        switch (valueType)
        {
        case MI_UINT8:
            value.uint8 = (MI_Uint8)PyInt_AsLong(pyValue);
            break;
        case MI_SINT8:
            value.sint8 = (MI_Sint8)PyInt_AsLong(pyValue);
            break;
        case MI_UINT16:
            value.uint16 = (MI_Uint16)PyInt_AsLong(pyValue);
            break;
        case MI_SINT16:
            value.sint16 = (MI_Sint16)PyInt_AsLong(pyValue);
            break;
        case MI_UINT32:
            value.uint32 = PyInt_AsLong(pyValue);
            break;
        case MI_SINT32:
            value.sint32 = PyInt_AsLong(pyValue);
            break;
        case MI_UINT64:
            value.uint64 = PyInt_AsLong(pyValue);
            break;
        case MI_SINT64:
            value.sint64 = PyInt_AsLong(pyValue);
            break;
        default:
            throw TypeConversionException();
        }
    }
    else if (PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyString_Type)))
    {
        unsigned len = 0;
        char* s = NULL;

        switch (valueType)
        {
        case MI_STRING:
            s = PyString_AsString(pyValue);
            len = lstrlenA(s) + 1;
            // Note: caller owns the memory
            value.string = (MI_Char*)HeapAlloc(GetProcessHeap(), 0, len * sizeof(MI_Char));
            if (!value.string)
            {
                throw OutOfMemoryException();
            }
            if (::MultiByteToWideChar(CP_ACP, 0, s, len, value.string, len) != len)
            {
                HeapFree(GetProcessHeap(), 0, value.string);
                value.string = NULL;
                throw MI::Exception(L"MultiByteToWideChar failed");
            }
            break;
        default:
            throw TypeConversionException();
        }
    }
#endif
    else if (PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyUnicode_Type)))
    {
        Py_ssize_t len = 0;

        switch (valueType)
        {
        case MI_STRING:
            // TODO: use PyUnicode_GetLength on 3.x
            len = PyUnicode_GetSize(pyValue) + 1;
            // Note: caller owns the memory
            value.string = (MI_Char*)HeapAlloc(GetProcessHeap(), 0, len * sizeof(MI_Char));
            if (!value.string)
            {
                throw OutOfMemoryException();
            }

            if (PyUnicode_AsWideChar((PYUNICODEASVARCHARARG1TYPE*)pyValue, value.string, len) < 0)
            {
                throw MI::Exception(L"PyUnicode_AsWideChar failed");
            }
            break;
        default:
            throw TypeConversionException();
        }
    }
    else if (PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&InstanceType)))
    {
        switch (valueType)
        {
        case MI_REFERENCE:
            value.reference = ((Instance*)pyValue)->instance->GetMIObject();
            break;
        default:
            throw TypeConversionException();
        }
    }
    else if (PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyTuple_Type)) ||
             PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyList_Type)))
    {
        bool isTuple = PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyTuple_Type)) != 0;
        Py_ssize_t size = 0;
        if (isTuple)
        {
            size = PyTuple_Size(pyValue);
        }
        else
        {
            size = PyList_Size(pyValue);
        }

        if (size == 0)
            return;

        switch (valueType)
        {
        case MI_UINT32A:
            value.uint32a.size = (unsigned)size;
            value.uint32a.data = (MI_Uint32*)HeapAlloc(GetProcessHeap(), 0, sizeof(MI_Uint32) * size);
            break;
        case MI_STRINGA:
            value.stringa.size = (unsigned)size;
            value.stringa.data = (MI_Char**)HeapAlloc(GetProcessHeap(), 0, sizeof(MI_Char*) * size);
            break;
        case MI_REFERENCEA:
            value.referencea.size = (unsigned)size;
            value.referencea.data = (MI_Instance**)HeapAlloc(GetProcessHeap(), 0, sizeof(MI_Instance*) * size);
            break;
        default:
            throw TypeConversionException();
        }

        for (Py_ssize_t i = 0; i < size; i++)
        {
            MI_Value tmpVal;
            PyObject* pyObj = NULL;

            if (isTuple)
            {
                pyObj = PyTuple_GetItem(pyValue, i);
            }
            else
            {
                pyObj = PyList_GetItem(pyValue, i);
            }

            switch (valueType)
            {
            case MI_UINT32A:
                Py2MI(pyObj, tmpVal, MI_UINT32);
                value.uint32a.data[i] = tmpVal.uint32;
                break;
            case MI_STRINGA:
                Py2MI(pyObj, tmpVal, MI_STRING);
                value.stringa.data[i] = tmpVal.string;
                break;
            case MI_REFERENCEA:
                Py2MI(pyObj, tmpVal, MI_REFERENCE);
                value.referencea.data[i] = tmpVal.reference;
                break;
            default:
                throw TypeConversionException();
            }
        }
    }
    else
    {
        throw TypeConversionException();
    }
}

PyObject* MI2Py(const MI_Value& value, MI_Type valueType, MI_Uint32 flags)
{
    if (flags & MI_FLAG_NULL)
        Py_RETURN_NONE;

    size_t len = 0;
    PyObject* pyObj = NULL;

    switch (valueType)
    {
    case MI_BOOLEAN:
        return PyBool_FromLong(value.boolean);
    case MI_SINT8:
        return PyLong_FromLong(value.sint8);
    case MI_UINT8:
        return PyLong_FromUnsignedLong(value.uint8);
    case MI_SINT16:
        return PyLong_FromLong(value.sint16);
    case MI_UINT16:
        return PyLong_FromUnsignedLong(value.uint16);
    case MI_SINT32:
        return PyLong_FromLong(value.sint32);
    case MI_UINT32:
        return PyLong_FromUnsignedLong(value.uint32);
    case MI_SINT64:
        return PyLong_FromLongLong(value.sint64);
    case MI_UINT64:
        return PyLong_FromUnsignedLongLong(value.uint64);
    case MI_REAL32:
        return PyFloat_FromDouble(value.real32);
    case MI_REAL64:
        return PyFloat_FromDouble(value.real64);
    case MI_CHAR16:
        return PyLong_FromLong(value.char16);
    case MI_DATETIME:
        // TODO: understand where this needs to be set
        PyDateTime_IMPORT;
        if (value.datetime.isTimestamp)
        {
            const MI_Timestamp& ts = value.datetime.u.timestamp;
            // TODO: Add timezone support!
            return PyDateTime_FromDateAndTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.microseconds);
        }
        else
        {
            const MI_Interval& ti = value.datetime.u.interval;
            return PyDelta_FromDSU(ti.days, ti.hours * 3600 + ti.minutes * 60 + ti.seconds, ti.microseconds);
        }
        break;
    case MI_STRING:
        len = wcslen(value.string);
        return PyUnicode_FromWideChar(value.string, len);
    case MI_BOOLEANA:
    case MI_SINT8A:
    case MI_UINT8A:
    case MI_SINT16A:
        return NULL;
    case MI_UINT16A:
        pyObj = PyTuple_New(value.uint16a.size);
        for (MI_Uint32 i = 0; i < value.uint16a.size; i++)
        {
            MI_Value tmpVal;
            tmpVal.uint16 = value.uint16a.data[i];
            if (PyTuple_SetItem(pyObj, i, MI2Py(tmpVal, MI_UINT16, 0)))
            {
                Py_DECREF(pyObj);
                throw MI::Exception(L"PyTuple_SetItem failed");
            }
        }
        return pyObj;
    case MI_SINT32A:
        return NULL;
    case MI_UINT32A:
        pyObj = PyTuple_New(value.uint32a.size);
        for (MI_Uint32 i = 0; i < value.uint32a.size; i++)
        {
            MI_Value tmpVal;
            tmpVal.uint32 = value.uint32a.data[i];
            if (PyTuple_SetItem(pyObj, i, MI2Py(tmpVal, MI_UINT32, 0)))
            {
                Py_DECREF(pyObj);
                throw MI::Exception(L"PyTuple_SetItem failed");
            }
        }
        return pyObj;
    case MI_SINT64A:
        return NULL;
    case MI_UINT64A:
        return NULL;
    case MI_REAL32A:
        return NULL;
    case MI_REAL64A:
        return NULL;
    case MI_CHAR16A:
        return NULL;
    case MI_DATETIMEA:
        pyObj = PyTuple_New(value.datetimea.size);
        for (MI_Uint32 i = 0; i < value.datetimea.size; i++)
        {
            MI_Value tmpVal;
            tmpVal.datetime = value.datetimea.data[i];
            if (PyTuple_SetItem(pyObj, i, MI2Py(tmpVal, MI_DATETIME, 0)))
            {
                Py_DECREF(pyObj);
                throw MI::Exception(L"PyTuple_SetItem failed");
            }
        }
        return pyObj;
    case MI_STRINGA:
        pyObj = PyTuple_New(value.stringa.size);
        for (MI_Uint32 i = 0; i < value.stringa.size; i++)
        {
            MI_Value tmpVal;
            tmpVal.string = value.stringa.data[i];
            if (PyTuple_SetItem(pyObj, i, MI2Py(tmpVal, MI_STRING, 0)))
            {
                Py_DECREF(pyObj);
                throw MI::Exception(L"PyTuple_SetItem failed");
            }
        }
        return pyObj;
    case MI_INSTANCE:
        pyObj = (PyObject*)Instance_New(new MI::Instance(value.instance, false));
        return pyObj;
    case MI_REFERENCE:
        pyObj = (PyObject*)Instance_New(new MI::Instance(value.reference, false));
        return pyObj;
    case MI_INSTANCEA:
        pyObj = PyTuple_New(value.instancea.size);
        for (unsigned i = 0; i < value.instancea.size; i++)
        {
            MI_Value tmpVal;
            tmpVal.instance = value.instancea.data[i];
            if (PyTuple_SetItem(pyObj, i, MI2Py(tmpVal, MI_INSTANCE, 0)))
            {
                Py_DECREF(pyObj);
                throw MI::Exception(L"PyTuple_SetItem failed");
            }
        }
        return pyObj;
    case MI_REFERENCEA:
        pyObj = PyTuple_New(value.stringa.size);
        for (unsigned i = 0; i < value.referencea.size; i++)
        {
            MI_Value tmpVal;
            tmpVal.reference = value.referencea.data[i];
            if (PyTuple_SetItem(pyObj, i, MI2Py(tmpVal, MI_REFERENCE, 0)))
            {
                Py_DECREF(pyObj);
                throw MI::Exception(L"PyTuple_SetItem failed");
            }
        }
        return pyObj;
    default:
        return NULL;
    }
}

void SetPyException(const std::exception& ex)
{
    const char* message = ex.what();
    PyErr_SetString(PyMIError, message);
}
<commit_msg>Adds element assignment __str__ conversion<commit_after>#include "stdafx.h"
#include "PyMI.h"
#include "Utils.h"
#include "instance.h"

#include <datetime.h>

void GetIndexOrName(PyObject *item, std::wstring& name, Py_ssize_t& i)
{
    name.clear();
    i = -1;

#ifndef IS_PY3K
    if (PyString_Check(item))
    {
        char* s = PyString_AsString(item);
        DWORD len = lstrlenA(s) + 1;
        wchar_t* w = new wchar_t[len];

        if (::MultiByteToWideChar(CP_ACP, 0, s, len, w, len) != len)
        {
            delete [] w;
            throw MI::Exception(L"MultiByteToWideChar failed");
        }
        name.assign(w, len);
        delete[] w;
    }
    else
#endif
    if (PyUnicode_Check(item))
    {
        DWORD len = PyUnicode_GetSize(item) + 1;
        wchar_t* w = new wchar_t[len];

        if (PyUnicode_AsWideChar((PYUNICODEASVARCHARARG1TYPE*)item, w, len) < 0)
        {
            delete[] w;
            throw MI::Exception(L"PyUnicode_AsWideChar failed");
        }
        name.assign(w, len);
        delete[] w;
    }
    else if (PyIndex_Check(item))
    {
        i = PyNumber_AsSsize_t(item, PyExc_IndexError);
        if (i == -1 && PyErr_Occurred())
            throw MI::Exception(L"Index error");
    }
    else
        throw MI::Exception(L"Invalid name or index");
}

void Py2MIString(PyObject* pyValue, MI_Value& value)
{
    PyObject* pyStrValue = PyObject_CallMethod(pyValue, "__str__", NULL);
    if (!pyStrValue)
    {
        throw MI::Exception(L"PyObject_CallMethod failed for __str__");
    }

    try
    {
        Py2MI(pyStrValue, value, MI_STRING);
        Py_DECREF(pyStrValue);
    }
    catch (std::exception&)
    {
        Py_DECREF(pyStrValue);
        throw;
    }
}

void Py2MI(PyObject* pyValue, MI_Value& value, MI_Type valueType)
{
    ZeroMemory(&value, sizeof(value));

    if (pyValue == Py_None)
    {
        return;
    }
    if (PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyBool_Type)))
    {
        value.boolean = PyObject_IsTrue(pyValue) ? MI_TRUE : MI_FALSE;
    }
    else if (PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyLong_Type)))
    {
        switch (valueType)
        {
        case MI_UINT8:
            value.uint8 = (MI_Uint8)PyLong_AsUnsignedLong(pyValue);
            break;
        case MI_SINT8:
            value.sint8 = (MI_Sint8)PyLong_AsLong(pyValue);
            break;
        case MI_UINT16:
            value.uint16 = (MI_Uint16)PyLong_AsUnsignedLong(pyValue);
            break;
        case MI_SINT16:
            value.sint16 = (MI_Sint16)PyLong_AsLong(pyValue);
            break;
        case MI_UINT32:
            value.uint32 = PyLong_AsUnsignedLong(pyValue);
            break;
        case MI_SINT32:
            value.sint32 = PyLong_AsLong(pyValue);
            break;
        case MI_UINT64:
            value.uint64 = PyLong_AsUnsignedLongLong(pyValue);
            break;
        case MI_SINT64:
            value.sint64 = PyLong_AsLongLong(pyValue);
            break;
        case MI_STRING:
            Py2MIString(pyValue, value);
            break;
        default:
            throw TypeConversionException();
        }
    }
#ifndef IS_PY3K
    else if (PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyInt_Type)))
    {
        switch (valueType)
        {
        case MI_UINT8:
            value.uint8 = (MI_Uint8)PyInt_AsLong(pyValue);
            break;
        case MI_SINT8:
            value.sint8 = (MI_Sint8)PyInt_AsLong(pyValue);
            break;
        case MI_UINT16:
            value.uint16 = (MI_Uint16)PyInt_AsLong(pyValue);
            break;
        case MI_SINT16:
            value.sint16 = (MI_Sint16)PyInt_AsLong(pyValue);
            break;
        case MI_UINT32:
            value.uint32 = PyInt_AsLong(pyValue);
            break;
        case MI_SINT32:
            value.sint32 = PyInt_AsLong(pyValue);
            break;
        case MI_UINT64:
            value.uint64 = PyInt_AsLong(pyValue);
            break;
        case MI_SINT64:
            value.sint64 = PyInt_AsLong(pyValue);
            break;
        case MI_STRING:
            Py2MIString(pyValue, value);
            break;
        default:
            throw TypeConversionException();
        }
    }
    else if (PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyString_Type)))
    {
        unsigned len = 0;
        char* s = NULL;

        switch (valueType)
        {
        case MI_STRING:
            s = PyString_AsString(pyValue);
            len = lstrlenA(s) + 1;
            // Note: caller owns the memory
            value.string = (MI_Char*)HeapAlloc(GetProcessHeap(), 0, len * sizeof(MI_Char));
            if (!value.string)
            {
                throw OutOfMemoryException();
            }
            if (::MultiByteToWideChar(CP_ACP, 0, s, len, value.string, len) != len)
            {
                HeapFree(GetProcessHeap(), 0, value.string);
                value.string = NULL;
                throw MI::Exception(L"MultiByteToWideChar failed");
            }
            break;
        default:
            throw TypeConversionException();
        }
    }
#endif
    else if (PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyUnicode_Type)))
    {
        Py_ssize_t len = 0;

        switch (valueType)
        {
        case MI_STRING:
            // TODO: use PyUnicode_GetLength on 3.x
            len = PyUnicode_GetSize(pyValue) + 1;
            // Note: caller owns the memory
            value.string = (MI_Char*)HeapAlloc(GetProcessHeap(), 0, len * sizeof(MI_Char));
            if (!value.string)
            {
                throw OutOfMemoryException();
            }

            if (PyUnicode_AsWideChar((PYUNICODEASVARCHARARG1TYPE*)pyValue, value.string, len) < 0)
            {
                throw MI::Exception(L"PyUnicode_AsWideChar failed");
            }
            break;
        default:
            throw TypeConversionException();
        }
    }
    else if (PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&InstanceType)))
    {
        switch (valueType)
        {
        case MI_REFERENCE:
            value.reference = ((Instance*)pyValue)->instance->GetMIObject();
            break;
        default:
            throw TypeConversionException();
        }
    }
    else if (PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyTuple_Type)) ||
             PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyList_Type)))
    {
        bool isTuple = PyObject_IsInstance(pyValue, reinterpret_cast<PyObject*>(&PyTuple_Type)) != 0;
        Py_ssize_t size = 0;
        if (isTuple)
        {
            size = PyTuple_Size(pyValue);
        }
        else
        {
            size = PyList_Size(pyValue);
        }

        if (size == 0)
            return;

        switch (valueType)
        {
        case MI_UINT32A:
            value.uint32a.size = (unsigned)size;
            value.uint32a.data = (MI_Uint32*)HeapAlloc(GetProcessHeap(), 0, sizeof(MI_Uint32) * size);
            break;
        case MI_STRINGA:
            value.stringa.size = (unsigned)size;
            value.stringa.data = (MI_Char**)HeapAlloc(GetProcessHeap(), 0, sizeof(MI_Char*) * size);
            break;
        case MI_REFERENCEA:
            value.referencea.size = (unsigned)size;
            value.referencea.data = (MI_Instance**)HeapAlloc(GetProcessHeap(), 0, sizeof(MI_Instance*) * size);
            break;
        default:
            throw TypeConversionException();
        }

        for (Py_ssize_t i = 0; i < size; i++)
        {
            MI_Value tmpVal;
            PyObject* pyObj = NULL;

            if (isTuple)
            {
                pyObj = PyTuple_GetItem(pyValue, i);
            }
            else
            {
                pyObj = PyList_GetItem(pyValue, i);
            }

            switch (valueType)
            {
            case MI_UINT32A:
                Py2MI(pyObj, tmpVal, MI_UINT32);
                value.uint32a.data[i] = tmpVal.uint32;
                break;
            case MI_STRINGA:
                Py2MI(pyObj, tmpVal, MI_STRING);
                value.stringa.data[i] = tmpVal.string;
                break;
            case MI_REFERENCEA:
                Py2MI(pyObj, tmpVal, MI_REFERENCE);
                value.referencea.data[i] = tmpVal.reference;
                break;
            default:
                throw TypeConversionException();
            }
        }
    }
    else
    {
        switch (valueType)
        {
        case MI_STRING:
            Py2MIString(pyValue, value);
            break;
        default:
            throw TypeConversionException();
        }
    }
}

PyObject* MI2Py(const MI_Value& value, MI_Type valueType, MI_Uint32 flags)
{
    if (flags & MI_FLAG_NULL)
        Py_RETURN_NONE;

    size_t len = 0;
    PyObject* pyObj = NULL;

    switch (valueType)
    {
    case MI_BOOLEAN:
        return PyBool_FromLong(value.boolean);
    case MI_SINT8:
        return PyLong_FromLong(value.sint8);
    case MI_UINT8:
        return PyLong_FromUnsignedLong(value.uint8);
    case MI_SINT16:
        return PyLong_FromLong(value.sint16);
    case MI_UINT16:
        return PyLong_FromUnsignedLong(value.uint16);
    case MI_SINT32:
        return PyLong_FromLong(value.sint32);
    case MI_UINT32:
        return PyLong_FromUnsignedLong(value.uint32);
    case MI_SINT64:
        return PyLong_FromLongLong(value.sint64);
    case MI_UINT64:
        return PyLong_FromUnsignedLongLong(value.uint64);
    case MI_REAL32:
        return PyFloat_FromDouble(value.real32);
    case MI_REAL64:
        return PyFloat_FromDouble(value.real64);
    case MI_CHAR16:
        return PyLong_FromLong(value.char16);
    case MI_DATETIME:
        // TODO: understand where this needs to be set
        PyDateTime_IMPORT;
        if (value.datetime.isTimestamp)
        {
            const MI_Timestamp& ts = value.datetime.u.timestamp;
            // TODO: Add timezone support!
            return PyDateTime_FromDateAndTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.microseconds);
        }
        else
        {
            const MI_Interval& ti = value.datetime.u.interval;
            return PyDelta_FromDSU(ti.days, ti.hours * 3600 + ti.minutes * 60 + ti.seconds, ti.microseconds);
        }
        break;
    case MI_STRING:
        len = wcslen(value.string);
        return PyUnicode_FromWideChar(value.string, len);
    case MI_BOOLEANA:
    case MI_SINT8A:
    case MI_UINT8A:
    case MI_SINT16A:
        return NULL;
    case MI_UINT16A:
        pyObj = PyTuple_New(value.uint16a.size);
        for (MI_Uint32 i = 0; i < value.uint16a.size; i++)
        {
            MI_Value tmpVal;
            tmpVal.uint16 = value.uint16a.data[i];
            if (PyTuple_SetItem(pyObj, i, MI2Py(tmpVal, MI_UINT16, 0)))
            {
                Py_DECREF(pyObj);
                throw MI::Exception(L"PyTuple_SetItem failed");
            }
        }
        return pyObj;
    case MI_SINT32A:
        return NULL;
    case MI_UINT32A:
        pyObj = PyTuple_New(value.uint32a.size);
        for (MI_Uint32 i = 0; i < value.uint32a.size; i++)
        {
            MI_Value tmpVal;
            tmpVal.uint32 = value.uint32a.data[i];
            if (PyTuple_SetItem(pyObj, i, MI2Py(tmpVal, MI_UINT32, 0)))
            {
                Py_DECREF(pyObj);
                throw MI::Exception(L"PyTuple_SetItem failed");
            }
        }
        return pyObj;
    case MI_SINT64A:
        return NULL;
    case MI_UINT64A:
        return NULL;
    case MI_REAL32A:
        return NULL;
    case MI_REAL64A:
        return NULL;
    case MI_CHAR16A:
        return NULL;
    case MI_DATETIMEA:
        pyObj = PyTuple_New(value.datetimea.size);
        for (MI_Uint32 i = 0; i < value.datetimea.size; i++)
        {
            MI_Value tmpVal;
            tmpVal.datetime = value.datetimea.data[i];
            if (PyTuple_SetItem(pyObj, i, MI2Py(tmpVal, MI_DATETIME, 0)))
            {
                Py_DECREF(pyObj);
                throw MI::Exception(L"PyTuple_SetItem failed");
            }
        }
        return pyObj;
    case MI_STRINGA:
        pyObj = PyTuple_New(value.stringa.size);
        for (MI_Uint32 i = 0; i < value.stringa.size; i++)
        {
            MI_Value tmpVal;
            tmpVal.string = value.stringa.data[i];
            if (PyTuple_SetItem(pyObj, i, MI2Py(tmpVal, MI_STRING, 0)))
            {
                Py_DECREF(pyObj);
                throw MI::Exception(L"PyTuple_SetItem failed");
            }
        }
        return pyObj;
    case MI_INSTANCE:
        pyObj = (PyObject*)Instance_New(new MI::Instance(value.instance, false));
        return pyObj;
    case MI_REFERENCE:
        pyObj = (PyObject*)Instance_New(new MI::Instance(value.reference, false));
        return pyObj;
    case MI_INSTANCEA:
        pyObj = PyTuple_New(value.instancea.size);
        for (unsigned i = 0; i < value.instancea.size; i++)
        {
            MI_Value tmpVal;
            tmpVal.instance = value.instancea.data[i];
            if (PyTuple_SetItem(pyObj, i, MI2Py(tmpVal, MI_INSTANCE, 0)))
            {
                Py_DECREF(pyObj);
                throw MI::Exception(L"PyTuple_SetItem failed");
            }
        }
        return pyObj;
    case MI_REFERENCEA:
        pyObj = PyTuple_New(value.stringa.size);
        for (unsigned i = 0; i < value.referencea.size; i++)
        {
            MI_Value tmpVal;
            tmpVal.reference = value.referencea.data[i];
            if (PyTuple_SetItem(pyObj, i, MI2Py(tmpVal, MI_REFERENCE, 0)))
            {
                Py_DECREF(pyObj);
                throw MI::Exception(L"PyTuple_SetItem failed");
            }
        }
        return pyObj;
    default:
        return NULL;
    }
}

void SetPyException(const std::exception& ex)
{
    const char* message = ex.what();
    PyErr_SetString(PyMIError, message);
}
<|endoftext|>


<commit_before>//
//  Layer.hpp
//  G3MiOSSDK
//
//  Created by José Miguel S N on 23/07/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#ifndef G3MiOSSDK_Layer_hpp
#define G3MiOSSDK_Layer_hpp

#include <string>
#include "Sector.hpp"

class Layer{

public:

  ~Layer(){};

  virtual bool fullContains(const Sector& s) const = 0;

  virtual std::string getRequest(const Sector& sector, int width, int height) const = 0;

};

#endif
<commit_msg>Warning solved<commit_after>//
//  Layer.hpp
//  G3MiOSSDK
//
//  Created by José Miguel S N on 23/07/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#ifndef G3MiOSSDK_Layer_hpp
#define G3MiOSSDK_Layer_hpp

#include <string>
#include "Sector.hpp"

class Layer{

public:

  virtual ~Layer(){};

  virtual bool fullContains(const Sector& s) const = 0;

  virtual std::string getRequest(const Sector& sector, int width, int height) const = 0;

};

#endif
<|endoftext|>


<commit_before><commit_msg>sw: tweak previous comment translation<commit_after><|endoftext|>