<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: webdavcontent.hxx,v $
 *
 *  $Revision: 1.19 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 16:15:42 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 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
 *
 ************************************************************************/

#ifndef _WEBDAV_UCP_CONTENT_HXX
#define _WEBDAV_UCP_CONTENT_HXX

#include <memory>
#include <list>

#ifndef _RTL_REF_HXX_
#include <rtl/ref.hxx>
#endif

#ifndef _COM_SUN_STAR_UCB_CONTENTCREATIONEXCEPTION_HPP_
#include <com/sun/star/ucb/ContentCreationException.hpp>
#endif
#ifndef _COM_SUN_STAR_UCB_XCONTENTCREATOR_HPP_
#include <com/sun/star/ucb/XContentCreator.hpp>
#endif

#ifndef _UCBHELPER_CONTENTHELPER_HXX
#include <ucbhelper/contenthelper.hxx>
#endif

#ifndef _DAVRESOURCEACCESS_HXX_
#include "DAVResourceAccess.hxx"
#endif
#ifndef _WEBDAV_UCP_PROPERTYMAP_HXX
#include "PropertyMap.hxx"
#endif

namespace com { namespace sun { namespace star { namespace beans {
    struct Property;
    struct PropertyValue;
} } } }

namespace com { namespace sun { namespace star { namespace io {
    class XInputStream;
} } } }

namespace com { namespace sun { namespace star { namespace sdbc {
    class XRow;
} } } }

namespace com { namespace sun { namespace star { namespace ucb {
    struct OpenCommandArgument2;
    struct PostCommandArgument2;
    struct TransferInfo;
} } } }

namespace webdav_ucp
{

//=========================================================================

// UNO service name for the content.
#define WEBDAV_CONTENT_SERVICE_NAME "com.sun.star.ucb.WebDAVContent"

//=========================================================================

class ContentProvider;
class ContentProperties;

class Content : public ::ucb::ContentImplHelper,
                public com::sun::star::ucb::XContentCreator
{
    enum ResourceType
    {
        UNKNOWN,
        FTP,
        NON_DAV,
        DAV
    };

    std::auto_ptr< DAVResourceAccess > m_xResAccess;
    std::auto_ptr< ContentProperties > m_xCachedProps; // locally cached props
    rtl::OUString     m_aEscapedTitle;
    ResourceType      m_eResourceType;
    ContentProvider*  m_pProvider; // No need for a ref, base class holds object
      sal_Bool        m_bTransient;
    sal_Bool          m_bCollection;

private:
    virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
    getProperties( const com::sun::star::uno::Reference<
                    com::sun::star::ucb::XCommandEnvironment > & xEnv );
    virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo >
    getCommands( const com::sun::star::uno::Reference<
                    com::sun::star::ucb::XCommandEnvironment > & xEnv );
      virtual ::rtl::OUString getParentURL();

      sal_Bool isFolder( const ::com::sun::star::uno::Reference<
                        ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
        throw ( ::com::sun::star::uno::Exception );

    void getProperties( const ::com::sun::star::uno::Reference<
                            ::com::sun::star::ucb::XCommandEnvironment >& xEnv,
                        PropertyMap & rProps );

      ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
      getPropertyValues( const ::com::sun::star::uno::Sequence<
                           ::com::sun::star::beans::Property >& rProperties,
                          const ::com::sun::star::uno::Reference<
                        ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
        throw ( ::com::sun::star::uno::Exception );

    ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
    setPropertyValues(
                     const ::com::sun::star::uno::Sequence<
                         ::com::sun::star::beans::PropertyValue >& rValues,
                        const ::com::sun::star::uno::Reference<
                        ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
        throw ( ::com::sun::star::uno::Exception );

    typedef rtl::Reference< Content > ContentRef;
      typedef std::list< ContentRef > ContentRefList;
      void queryChildren( ContentRefList& rChildren);

      sal_Bool exchangeIdentity(
                const ::com::sun::star::uno::Reference<
                        ::com::sun::star::ucb::XContentIdentifier >& xNewId );

    const rtl::OUString getBaseURI();

    const ResourceType & getResourceType(
                    const ::com::sun::star::uno::Reference<
                        ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
        throw ( ::com::sun::star::uno::Exception );

    // Command "open"
    com::sun::star::uno::Any open(
                const com::sun::star::ucb::OpenCommandArgument2 & rArg,
                const com::sun::star::uno::Reference<
                        com::sun::star::ucb::XCommandEnvironment > & xEnv )
        throw( ::com::sun::star::uno::Exception );

    // Command "post"
    void post( const com::sun::star::ucb::PostCommandArgument2 & rArg,
               const com::sun::star::uno::Reference<
                        com::sun::star::ucb::XCommandEnvironment > & xEnv )
        throw( ::com::sun::star::uno::Exception );

      // Command "insert"
      void insert( const ::com::sun::star::uno::Reference<
                    ::com::sun::star::io::XInputStream > & xInputStream,
                   sal_Bool bReplaceExisting,
                   const com::sun::star::uno::Reference<
                      com::sun::star::ucb::XCommandEnvironment >& Environment )
        throw( ::com::sun::star::uno::Exception );

    // Command "transfer"
    void transfer( const ::com::sun::star::ucb::TransferInfo & rArgs,
                   const com::sun::star::uno::Reference<
                      com::sun::star::ucb::XCommandEnvironment >& Environment )
        throw( ::com::sun::star::uno::Exception );

    // Command "delete"
      void destroy( sal_Bool bDeletePhysical )
        throw( ::com::sun::star::uno::Exception );

    ::com::sun::star::uno::Any MapDAVException( const DAVException & e,
                                                sal_Bool bWrite );
    void cancelCommandExecution(
                    const DAVException & e,
                    const ::com::sun::star::uno::Reference<
                        com::sun::star::ucb::XCommandEnvironment > & xEnv,
                    sal_Bool bWrite = sal_False )
        throw( ::com::sun::star::uno::Exception );

    static bool shouldAccessNetworkAfterException( const DAVException & e );

public:
      Content( const ::com::sun::star::uno::Reference<
                ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
                ContentProvider* pProvider,
                const ::com::sun::star::uno::Reference<
                ::com::sun::star::ucb::XContentIdentifier >& Identifier,
             rtl::Reference< DAVSessionFactory > const & rSessionFactory )
        throw ( ::com::sun::star::ucb::ContentCreationException );
      Content( const ::com::sun::star::uno::Reference<
                ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
                ContentProvider* pProvider,
                const ::com::sun::star::uno::Reference<
                ::com::sun::star::ucb::XContentIdentifier >& Identifier,
             rtl::Reference< DAVSessionFactory > const & rSessionFactory,
                sal_Bool isCollection )
        throw ( ::com::sun::star::ucb::ContentCreationException );
      virtual ~Content();

      // XInterface
      XINTERFACE_DECL()

    // XTypeProvider
    XTYPEPROVIDER_DECL()

    // XServiceInfo
    virtual ::rtl::OUString SAL_CALL
      getImplementationName()
        throw( ::com::sun::star::uno::RuntimeException );
      virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
      getSupportedServiceNames()
        throw( ::com::sun::star::uno::RuntimeException );

      // XContent
      virtual rtl::OUString SAL_CALL
      getContentType()
        throw( com::sun::star::uno::RuntimeException );

      // XCommandProcessor
      virtual com::sun::star::uno::Any SAL_CALL
      execute( const com::sun::star::ucb::Command& aCommand,
                sal_Int32 CommandId,
                const com::sun::star::uno::Reference<
                   com::sun::star::ucb::XCommandEnvironment >& Environment )
        throw( com::sun::star::uno::Exception,
                  com::sun::star::ucb::CommandAbortedException,
                  com::sun::star::uno::RuntimeException );
      virtual void SAL_CALL
      abort( sal_Int32 CommandId )
        throw( com::sun::star::uno::RuntimeException );

      // XPropertyContainer
    virtual void SAL_CALL
    addProperty( const rtl::OUString& Name,
                 sal_Int16 Attributes,
                 const com::sun::star::uno::Any& DefaultValue )
        throw( com::sun::star::beans::PropertyExistException,
               com::sun::star::beans::IllegalTypeException,
               com::sun::star::lang::IllegalArgumentException,
               com::sun::star::uno::RuntimeException );

    virtual void SAL_CALL
    removeProperty( const rtl::OUString& Name )
        throw( com::sun::star::beans::UnknownPropertyException,
               com::sun::star::beans::NotRemoveableException,
               com::sun::star::uno::RuntimeException );

      //////////////////////////////////////////////////////////////////////
      // Additional interfaces
      //////////////////////////////////////////////////////////////////////

      // XContentCreator
    virtual com::sun::star::uno::Sequence<
        com::sun::star::ucb::ContentInfo > SAL_CALL
      queryCreatableContentsInfo()
        throw( com::sun::star::uno::RuntimeException );
      virtual com::sun::star::uno::Reference<
          com::sun::star::ucb::XContent > SAL_CALL
      createNewContent( const com::sun::star::ucb::ContentInfo& Info )
        throw( com::sun::star::uno::RuntimeException );

      //////////////////////////////////////////////////////////////////////
      // Non-interface methods.
      //////////////////////////////////////////////////////////////////////

    DAVResourceAccess & getResourceAccess() { return *m_xResAccess; }

      // Called from resultset data supplier.
      static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
      getPropertyValues( const ::com::sun::star::uno::Reference<
                              ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
                       const ::com::sun::star::uno::Sequence<
                              ::com::sun::star::beans::Property >& rProperties,
                          const ContentProperties& rData,
                       const rtl::Reference<
                           ::ucb::ContentProviderImplHelper >&  rProvider,
                          const ::rtl::OUString& rContentId );
};

};

#endif
<commit_msg>INTEGRATION: CWS warnings01 (1.19.10); FILE MERGED 2005/11/10 18:10:31 pl 1.19.10.1: #i55991# removed warnings<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: webdavcontent.hxx,v $
 *
 *  $Revision: 1.20 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-20 05:38:19 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 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
 *
 ************************************************************************/

#ifndef _WEBDAV_UCP_CONTENT_HXX
#define _WEBDAV_UCP_CONTENT_HXX

#include <memory>
#include <list>

#ifndef _RTL_REF_HXX_
#include <rtl/ref.hxx>
#endif

#ifndef _COM_SUN_STAR_UCB_CONTENTCREATIONEXCEPTION_HPP_
#include <com/sun/star/ucb/ContentCreationException.hpp>
#endif
#ifndef _COM_SUN_STAR_UCB_XCONTENTCREATOR_HPP_
#include <com/sun/star/ucb/XContentCreator.hpp>
#endif

#ifndef _UCBHELPER_CONTENTHELPER_HXX
#include <ucbhelper/contenthelper.hxx>
#endif

#ifndef _DAVRESOURCEACCESS_HXX_
#include "DAVResourceAccess.hxx"
#endif
#ifndef _WEBDAV_UCP_PROPERTYMAP_HXX
#include "PropertyMap.hxx"
#endif

namespace com { namespace sun { namespace star { namespace beans {
    struct Property;
    struct PropertyValue;
} } } }

namespace com { namespace sun { namespace star { namespace io {
    class XInputStream;
} } } }

namespace com { namespace sun { namespace star { namespace sdbc {
    class XRow;
} } } }

namespace com { namespace sun { namespace star { namespace ucb {
    struct OpenCommandArgument2;
    struct PostCommandArgument2;
    struct TransferInfo;
} } } }

namespace webdav_ucp
{

//=========================================================================

// UNO service name for the content.
#define WEBDAV_CONTENT_SERVICE_NAME "com.sun.star.ucb.WebDAVContent"

//=========================================================================

class ContentProvider;
class ContentProperties;

class Content : public ::ucb::ContentImplHelper,
                public com::sun::star::ucb::XContentCreator
{
    enum ResourceType
    {
        UNKNOWN,
        FTP,
        NON_DAV,
        DAV
    };

    std::auto_ptr< DAVResourceAccess > m_xResAccess;
    std::auto_ptr< ContentProperties > m_xCachedProps; // locally cached props
    rtl::OUString     m_aEscapedTitle;
    ResourceType      m_eResourceType;
    ContentProvider*  m_pProvider; // No need for a ref, base class holds object
      sal_Bool        m_bTransient;
    sal_Bool          m_bCollection;

private:
    virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
    getProperties( const com::sun::star::uno::Reference<
                    com::sun::star::ucb::XCommandEnvironment > & xEnv );
    virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo >
    getCommands( const com::sun::star::uno::Reference<
                    com::sun::star::ucb::XCommandEnvironment > & xEnv );
      virtual ::rtl::OUString getParentURL();

      sal_Bool isFolder( const ::com::sun::star::uno::Reference<
                        ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
        throw ( ::com::sun::star::uno::Exception );

    void getProperties( const ::com::sun::star::uno::Reference<
                            ::com::sun::star::ucb::XCommandEnvironment >& xEnv,
                        PropertyMap & rProps );

      ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
      getPropertyValues( const ::com::sun::star::uno::Sequence<
                           ::com::sun::star::beans::Property >& rProperties,
                          const ::com::sun::star::uno::Reference<
                        ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
        throw ( ::com::sun::star::uno::Exception );

    ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
    setPropertyValues(
                     const ::com::sun::star::uno::Sequence<
                         ::com::sun::star::beans::PropertyValue >& rValues,
                        const ::com::sun::star::uno::Reference<
                        ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
        throw ( ::com::sun::star::uno::Exception );

    typedef rtl::Reference< Content > ContentRef;
      typedef std::list< ContentRef > ContentRefList;
      void queryChildren( ContentRefList& rChildren);

      sal_Bool exchangeIdentity(
                const ::com::sun::star::uno::Reference<
                        ::com::sun::star::ucb::XContentIdentifier >& xNewId );

    const rtl::OUString getBaseURI();

    const ResourceType & getResourceType(
                    const ::com::sun::star::uno::Reference<
                        ::com::sun::star::ucb::XCommandEnvironment >& xEnv )
        throw ( ::com::sun::star::uno::Exception );

    // Command "open"
    com::sun::star::uno::Any open(
                const com::sun::star::ucb::OpenCommandArgument2 & rArg,
                const com::sun::star::uno::Reference<
                        com::sun::star::ucb::XCommandEnvironment > & xEnv )
        throw( ::com::sun::star::uno::Exception );

    // Command "post"
    void post( const com::sun::star::ucb::PostCommandArgument2 & rArg,
               const com::sun::star::uno::Reference<
                        com::sun::star::ucb::XCommandEnvironment > & xEnv )
        throw( ::com::sun::star::uno::Exception );

      // Command "insert"
      void insert( const ::com::sun::star::uno::Reference<
                    ::com::sun::star::io::XInputStream > & xInputStream,
                   sal_Bool bReplaceExisting,
                   const com::sun::star::uno::Reference<
                      com::sun::star::ucb::XCommandEnvironment >& Environment )
        throw( ::com::sun::star::uno::Exception );

    // Command "transfer"
    void transfer( const ::com::sun::star::ucb::TransferInfo & rArgs,
                   const com::sun::star::uno::Reference<
                      com::sun::star::ucb::XCommandEnvironment >& Environment )
        throw( ::com::sun::star::uno::Exception );

    // Command "delete"
      void destroy( sal_Bool bDeletePhysical )
        throw( ::com::sun::star::uno::Exception );

    ::com::sun::star::uno::Any MapDAVException( const DAVException & e,
                                                sal_Bool bWrite );
    void cancelCommandExecution(
                    const DAVException & e,
                    const ::com::sun::star::uno::Reference<
                        com::sun::star::ucb::XCommandEnvironment > & xEnv,
                    sal_Bool bWrite = sal_False )
        throw( ::com::sun::star::uno::Exception );

    static bool shouldAccessNetworkAfterException( const DAVException & e );

public:
      Content( const ::com::sun::star::uno::Reference<
                ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
                ContentProvider* pProvider,
                const ::com::sun::star::uno::Reference<
                ::com::sun::star::ucb::XContentIdentifier >& Identifier,
             rtl::Reference< DAVSessionFactory > const & rSessionFactory )
        throw ( ::com::sun::star::ucb::ContentCreationException );
      Content( const ::com::sun::star::uno::Reference<
                ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
                ContentProvider* pProvider,
                const ::com::sun::star::uno::Reference<
                ::com::sun::star::ucb::XContentIdentifier >& Identifier,
             rtl::Reference< DAVSessionFactory > const & rSessionFactory,
                sal_Bool isCollection )
        throw ( ::com::sun::star::ucb::ContentCreationException );
      virtual ~Content();

      // XInterface
      XINTERFACE_DECL()

    // XTypeProvider
    XTYPEPROVIDER_DECL()

    // XServiceInfo
    virtual ::rtl::OUString SAL_CALL
      getImplementationName()
        throw( ::com::sun::star::uno::RuntimeException );
      virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
      getSupportedServiceNames()
        throw( ::com::sun::star::uno::RuntimeException );

      // XContent
      virtual rtl::OUString SAL_CALL
      getContentType()
        throw( com::sun::star::uno::RuntimeException );

      // XCommandProcessor
      virtual com::sun::star::uno::Any SAL_CALL
      execute( const com::sun::star::ucb::Command& aCommand,
                sal_Int32 CommandId,
                const com::sun::star::uno::Reference<
                   com::sun::star::ucb::XCommandEnvironment >& Environment )
        throw( com::sun::star::uno::Exception,
                  com::sun::star::ucb::CommandAbortedException,
                  com::sun::star::uno::RuntimeException );
      virtual void SAL_CALL
      abort( sal_Int32 CommandId )
        throw( com::sun::star::uno::RuntimeException );

      // XPropertyContainer
    virtual void SAL_CALL
    addProperty( const rtl::OUString& Name,
                 sal_Int16 Attributes,
                 const com::sun::star::uno::Any& DefaultValue )
        throw( com::sun::star::beans::PropertyExistException,
               com::sun::star::beans::IllegalTypeException,
               com::sun::star::lang::IllegalArgumentException,
               com::sun::star::uno::RuntimeException );

    virtual void SAL_CALL
    removeProperty( const rtl::OUString& Name )
        throw( com::sun::star::beans::UnknownPropertyException,
               com::sun::star::beans::NotRemoveableException,
               com::sun::star::uno::RuntimeException );

      //////////////////////////////////////////////////////////////////////
      // Additional interfaces
      //////////////////////////////////////////////////////////////////////

      // XContentCreator
    virtual com::sun::star::uno::Sequence<
        com::sun::star::ucb::ContentInfo > SAL_CALL
      queryCreatableContentsInfo()
        throw( com::sun::star::uno::RuntimeException );
      virtual com::sun::star::uno::Reference<
          com::sun::star::ucb::XContent > SAL_CALL
      createNewContent( const com::sun::star::ucb::ContentInfo& Info )
        throw( com::sun::star::uno::RuntimeException );

      //////////////////////////////////////////////////////////////////////
      // Non-interface methods.
      //////////////////////////////////////////////////////////////////////

    DAVResourceAccess & getResourceAccess() { return *m_xResAccess; }

      // Called from resultset data supplier.
      static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
      getPropertyValues( const ::com::sun::star::uno::Reference<
                              ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
                       const ::com::sun::star::uno::Sequence<
                              ::com::sun::star::beans::Property >& rProperties,
                          const ContentProperties& rData,
                       const rtl::Reference<
                           ::ucb::ContentProviderImplHelper >&  rProvider,
                          const ::rtl::OUString& rContentId );
};

}

#endif
<|endoftext|>


<commit_before>/*
 * LinuxFileMonitor.cpp
 *
 * Copyright (C) 2009-11 by RStudio, Inc.
 *
 * This program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */

#include <core/system/FileMonitor.hpp>

#include <core/Log.hpp>
#include <core/Error.hpp>
#include <core/FileInfo.hpp>

#include <core/system/FileScanner.hpp>
#include <core/system/System.hpp>

#include "FileMonitorImpl.hpp"

namespace core {
namespace system {
namespace file_monitor {

namespace {

} // anonymous namespace

namespace detail {

// register a new file monitor
Handle registerMonitor(const core::FilePath& filePath,
                       bool recursive,
                       const Callbacks& callbacks)
{
   return NULL;
}

// unregister a file monitor
void unregisterMonitor(Handle handle)
{

}

void run(const boost::function<void()>& checkForInput)
{

}

void stop()
{

}

} // namespace detail
} // namespace file_monitor
} // namespace system
} // namespace core

<commit_msg>fix handle ref in linux filemon<commit_after>/*
 * LinuxFileMonitor.cpp
 *
 * Copyright (C) 2009-11 by RStudio, Inc.
 *
 * This program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */

#include <core/system/FileMonitor.hpp>

#include <core/Log.hpp>
#include <core/Error.hpp>
#include <core/FileInfo.hpp>

#include <core/system/FileScanner.hpp>
#include <core/system/System.hpp>

#include "FileMonitorImpl.hpp"

namespace core {
namespace system {
namespace file_monitor {

namespace {

} // anonymous namespace

namespace detail {

// register a new file monitor
Handle registerMonitor(const core::FilePath& filePath,
                       bool recursive,
                       const Callbacks& callbacks)
{
   return Handle();
}

// unregister a file monitor
void unregisterMonitor(Handle handle)
{

}

void run(const boost::function<void()>& checkForInput)
{

}

void stop()
{

}

} // namespace detail
} // namespace file_monitor
} // namespace system
} // namespace core

<|endoftext|>


<commit_before>/*
 *  stepguider_SxAO.cpp
 *  PHD Guiding
 *
 *  Created by Bret McKee
 *  Copyright (c) 2013 Bret McKee
 *  All rights reserved.
 *
 *  This source code is distributed under the following "BSD" license
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *    Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *    Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *    Neither the name of Bret McKee, Dad Dog Development, nor the names of its
 *     Craig Stark, Stark Labs nor the names of its
 *     contributors may be used to endorse or promote products derived from
 *     this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include "phd.h"
#ifdef STEPGUIDER_SXAO
StepGuiderSxAO::StepGuiderSxAO(void)
{
    m_pSerialPort = NULL;
    m_Name = "SXV-AO";
}

StepGuiderSxAO::~StepGuiderSxAO(void)
{
    delete m_pSerialPort;
}

bool StepGuiderSxAO::Connect(void)
{
    bool bError = false;

    try
    {
#ifdef USE_LOOPBACK_SERIAL
        m_pSerialPort = new SerialPortLoopback();
#else
        m_pSerialPort = SerialPort::SerialPortFactory();
#endif

        if (!m_pSerialPort)
        {
            throw ERROR_INFO("StepGuiderSxAO::Connect: serial port is NULL");
        }

        wxArrayString serialPorts = m_pSerialPort->GetSerialPortList();

        if (serialPorts.IsEmpty())
        {
            wxMessageBox(_("No serial ports found"),_("Error"), wxOK | wxICON_ERROR);
            throw ERROR_INFO("No Serial port found");
        }

        wxString lastSerialPort = pConfig->Profile.GetString("/stepguider/sxao/serialport", "");
        int resp = serialPorts.Index(lastSerialPort);

        resp = wxGetSingleChoiceIndex(_("Select serial port"),_("Serial Port"), serialPorts,
                NULL, wxDefaultCoord, wxDefaultCoord, true, wxCHOICE_WIDTH, wxCHOICE_HEIGHT,
                resp);

        if (m_pSerialPort->Connect(serialPorts[resp], 9600, 8, 1, SerialPort::ParityNone, false, false))
        {
            throw ERROR_INFO("StepGuiderSxAO::Connect: serial port connect failed");
        }

        pConfig->Profile.SetString("/stepguider/sxao/serialport", serialPorts[resp]);

        if (m_pSerialPort->SetReceiveTimeout(DefaultTimeout))
        {
            throw ERROR_INFO("StepGuiderSxAO::Connect: SetReceiveTimeout failed");
        }

        unsigned version;

        if (FirmwareVersion(version))
        {
            throw ERROR_INFO("StepGuiderSxAO::Connect: unable to get firmware version");
        }

        if (Center())
        {
            if (Unjam())
            {
                throw ERROR_INFO("StepGuiderSxAO::Connect: unable to center or Unjam");
            }
        }

        StepGuider::Connect();
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::Disconnect(void)
{
    bool bError = false;

    try
    {
        if (m_pSerialPort && m_pSerialPort->Disconnect())
        {
            throw ERROR_INFO("StepGuiderSxAO::serial port disconnect failed");
        }

        delete m_pSerialPort;
        m_pSerialPort = NULL;
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::SendThenReceive(unsigned char sendChar, unsigned char& receivedChar)
{
    bool bError = false;

    try
    {
        if (m_pSerialPort->Send(&sendChar, 1))
        {
            throw ERROR_INFO("StepGuiderSxAO::SendThenReceive serial send failed");
        }

        if (m_pSerialPort->Receive(&receivedChar, 1))
        {
            throw ERROR_INFO("StepGuiderSxAO::SendThenReceive serial receive failed");
        }
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::SendThenReceive(unsigned char *pBuffer, unsigned bufferSize, unsigned char& recievedChar)
{
    bool bError = false;

    try
    {
        if (m_pSerialPort->Send(pBuffer, bufferSize))
        {
            throw ERROR_INFO("StepGuiderSxAO::SendThenReceive serial send failed");
        }

        if (m_pSerialPort->Receive(&recievedChar, 1))
        {
            throw ERROR_INFO("StepGuiderSxAO::SendThenReceive serial receive failed");
        }

        if (recievedChar == 'W')
        {
            if (m_pSerialPort->Receive(&recievedChar, 1))
            {
                throw ERROR_INFO("StepGuiderSxAO::step: Error reading another character after 'W'");
            }
        }
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::SendShortCommand(unsigned char command, unsigned char& response)
{
    bool bError = false;

    try
    {
        bError = SendThenReceive(command, response);
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

/*
 * Long commands send 7 bytes to the AO. The first char
 * is the command, the second is the direction and the remaining
 * 5 characters are a count.
 */

bool StepGuiderSxAO::SendLongCommand(unsigned char command, unsigned char parameter, unsigned count, unsigned char& response)
{
    bool bError = false;

    try
    {
        unsigned char cmdBuf[8]; // 7 chars + NULL

        if (count > 99999)
        {
            throw ERROR_INFO("StepGuiderSxAO::SendLongCommand invalid count");
        }

        int ret = _snprintf((char *)&cmdBuf, sizeof(cmdBuf), "%c%c%5.5d", command, parameter, count);

        if (ret < 0)
        {
            throw ERROR_INFO("StepGuiderSxAO::SendLongCommand snprintf failed");
        }

        if (ret >= sizeof(cmdBuf))
        {
            throw ERROR_INFO("StepGuiderSxAO::SendLongCommand snprintf buffer to small");
        }

        if (SendThenReceive((unsigned char *)&cmdBuf, 7, response))
        {
            throw ERROR_INFO("StepGuiderSxAO::SendLongCommand SendThenReceive failed");
        }
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

/*
 * the firmwareVersion command is unique command.  It sends 1 byte, and receives 3 digits
 * in response.
 */

bool StepGuiderSxAO::FirmwareVersion(unsigned& version)
{
    bool bError = false;

    try
    {
        version = 0;
        unsigned char cmd = 'V';
        unsigned char response;

        if (SendThenReceive(cmd, response))
        {
            throw ERROR_INFO("StepGuiderSxAO::firmwareVersion: SendThenReceive failed");
        }

        if (response != cmd)
        {
            throw ERROR_INFO("StepGuiderSxAO::firmwareVersion: response != cmd");
        }

        unsigned char buf[3];

        if (m_pSerialPort->Receive((unsigned char*)&buf, sizeof(buf)))
        {
            throw ERROR_INFO("StepGuiderSxAO::firmwareVersion: Receive failed");
        }

        for(int i=0;i<3;i++)
        {
            unsigned char ch = buf[i];

            if (ch < '0' || ch > '9')
            {
                throw ERROR_INFO("StepGuiderSxAO::firmwareVersion: invalid character");
            }
            version = (version * 10 ) + (ch - '0');
        }
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::Center(unsigned char cmd)
{
    bool bError = false;

    try
    {
        unsigned char response;

        if (m_pSerialPort->SetReceiveTimeout(CenterTimeout))
        {
            throw ERROR_INFO("StepGuiderSxAO::Center: SetReceiveTimeout failed");
        }

        if (SendShortCommand(cmd, response))
        {
            throw ERROR_INFO("StepGuiderSxAO::center SendShortCommand failed");
        }

        // there are two center commands and both return 'K'
        if (response != 'K')
        {
            throw ERROR_INFO("StepGuiderSxAO::center response != cmd");
        }

        if (m_pSerialPort->SetReceiveTimeout(DefaultTimeout))
        {
            throw ERROR_INFO("StepGuiderSxAO::Center: SetReceiveTimeout failed");
        }

        StepGuider::ZeroCurrentPosition();
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::Center()
{
    bool bError = false;

    try
    {
        if (Center('K'))
        {
            throw ERROR_INFO("StepGuiderSxAO::Center: Center() failed");
        }
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::Unjam(void)
{
    bool bError = false;

    try
    {
        if (Center('R'))
        {
            throw ERROR_INFO("StepGuiderSxAO::Center: Center() failed");
        }

    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::Step(GUIDE_DIRECTION direction, int steps)
{
    bool bError = false;

    try
    {
        unsigned char cmd = 'G';
        unsigned char parameter;
        unsigned char response;
        int currentPos = 0;

        switch (direction)
        {
            case NORTH:
                parameter = 'N';
                break;
            case SOUTH:
                parameter = 'S';
                break;
            case EAST:
                parameter = 'T';
                break;
            case WEST:
                parameter = 'W';
                break;
            default:
                throw ERROR_INFO("StepGuiderSxAO::step: invalid direction");
                break;
        }

        if (SendLongCommand(cmd, parameter, steps, response))
        {
            throw ERROR_INFO("StepGuiderSxAO::step: SendLongCommand failed");
        }

        if (response == 'L')
        {
            throw ERROR_INFO("StepGuiderSxAO::step: step: at limit");
        }

        if (response != cmd)
        {
            throw ERROR_INFO("StepGuiderSxAO::step: response != cmd");
        }

    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

int StepGuiderSxAO::MaxPosition(GUIDE_DIRECTION direction)
{
    return MaxSteps;
}

bool StepGuiderSxAO::IsAtLimit(GUIDE_DIRECTION direction, bool& isAtLimit)
{
    bool bError = false;

    try
    {
        unsigned char cmd = 'L';
        unsigned char response;

        if (SendThenReceive(cmd, response))
        {
            throw ERROR_INFO("StepGuiderSxAO::IsAtLimit: SendThenReceive failed");
        }

        if ((response & 0xf0) != 0x30)
        {
            throw ERROR_INFO("StepGuiderSxAO::IsAtLimit: invalid response ");
        }

        switch (direction)
        {
            case NORTH:
                isAtLimit = (response & 0x1) == 0x1;
                break;
            case SOUTH:
                isAtLimit = (response & 0x2) == 0x2;
                break;
            case EAST:
                isAtLimit = (response & 0x4) == 0x4;
                break;
            case WEST:
                isAtLimit = (response & 0x8) == 0x8;
                break;
            default:
                throw ERROR_INFO("StepGuiderSxAO::step: invalid direction");
                break;
        }
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::ST4HasGuideOutput(void)
{
    return true;
}

bool StepGuiderSxAO::ST4HostConnected(void)
{
    return IsConnected();
}

bool StepGuiderSxAO::ST4HasNonGuiMove(void)
{
    return true;
}

bool StepGuiderSxAO::ST4PulseGuideScope(int direction, int duration)
{
    bool bError = false;

    try
    {
        char cmd = 'M';
        char parameter = 0;
        unsigned char response;

        switch (direction)
        {
            case NORTH:
                parameter = 'N';
                break;
            case SOUTH:
                parameter = 'S';
                break;
            case EAST:
                parameter = 'T';
                break;
            case WEST:
                parameter = 'W';
                break;
            default:
                throw ERROR_INFO("StepGuiderSxAO::ST4PulseGuideScope(): invalid direction");
                break;
        }

        if (SendLongCommand(cmd, parameter, duration, response))
        {
            throw ERROR_INFO("StepGuiderSxAO::ST4PulseGuideScope(): SendLongCommand failed");
        }

        if (response != cmd)
        {
            throw ERROR_INFO("StepGuiderSxAO::ST4PulseGuideScope(): response != cmd");
        }

        // The Step function is asynchronous, and there is no way to wait for it, so we just
        // wait
        wxMilliSleep(duration);
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

#endif // STEPGUIDER_SXAO

<commit_msg>fix a bug where it was impossible to disconnect an SXAO without exiting PHD2<commit_after>/*
 *  stepguider_SxAO.cpp
 *  PHD Guiding
 *
 *  Created by Bret McKee
 *  Copyright (c) 2013 Bret McKee
 *  All rights reserved.
 *
 *  This source code is distributed under the following "BSD" license
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *    Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *    Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *    Neither the name of Bret McKee, Dad Dog Development, nor the names of its
 *     Craig Stark, Stark Labs nor the names of its
 *     contributors may be used to endorse or promote products derived from
 *     this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include "phd.h"
#ifdef STEPGUIDER_SXAO
StepGuiderSxAO::StepGuiderSxAO(void)
{
    m_pSerialPort = NULL;
    m_Name = "SXV-AO";
}

StepGuiderSxAO::~StepGuiderSxAO(void)
{
    delete m_pSerialPort;
}

bool StepGuiderSxAO::Connect(void)
{
    bool bError = false;

    try
    {
#ifdef USE_LOOPBACK_SERIAL
        m_pSerialPort = new SerialPortLoopback();
#else
        m_pSerialPort = SerialPort::SerialPortFactory();
#endif

        if (!m_pSerialPort)
        {
            throw ERROR_INFO("StepGuiderSxAO::Connect: serial port is NULL");
        }

        wxArrayString serialPorts = m_pSerialPort->GetSerialPortList();

        if (serialPorts.IsEmpty())
        {
            wxMessageBox(_("No serial ports found"),_("Error"), wxOK | wxICON_ERROR);
            throw ERROR_INFO("No Serial port found");
        }

        wxString lastSerialPort = pConfig->Profile.GetString("/stepguider/sxao/serialport", "");
        int resp = serialPorts.Index(lastSerialPort);

        resp = wxGetSingleChoiceIndex(_("Select serial port"),_("Serial Port"), serialPorts,
                NULL, wxDefaultCoord, wxDefaultCoord, true, wxCHOICE_WIDTH, wxCHOICE_HEIGHT,
                resp);

        if (m_pSerialPort->Connect(serialPorts[resp], 9600, 8, 1, SerialPort::ParityNone, false, false))
        {
            throw ERROR_INFO("StepGuiderSxAO::Connect: serial port connect failed");
        }

        pConfig->Profile.SetString("/stepguider/sxao/serialport", serialPorts[resp]);

        if (m_pSerialPort->SetReceiveTimeout(DefaultTimeout))
        {
            throw ERROR_INFO("StepGuiderSxAO::Connect: SetReceiveTimeout failed");
        }

        unsigned version;

        if (FirmwareVersion(version))
        {
            throw ERROR_INFO("StepGuiderSxAO::Connect: unable to get firmware version");
        }

        if (Center())
        {
            if (Unjam())
            {
                throw ERROR_INFO("StepGuiderSxAO::Connect: unable to center or Unjam");
            }
        }

        StepGuider::Connect();
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::Disconnect(void)
{
    if (StepGuider::Disconnect())
    {
        return true;
    }

    bool bError = false;

    try
    {
        if (m_pSerialPort && m_pSerialPort->Disconnect())
        {
            throw ERROR_INFO("StepGuiderSxAO::serial port disconnect failed");
        }

        delete m_pSerialPort;
        m_pSerialPort = NULL;
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::SendThenReceive(unsigned char sendChar, unsigned char& receivedChar)
{
    bool bError = false;

    try
    {
        if (m_pSerialPort->Send(&sendChar, 1))
        {
            throw ERROR_INFO("StepGuiderSxAO::SendThenReceive serial send failed");
        }

        if (m_pSerialPort->Receive(&receivedChar, 1))
        {
            throw ERROR_INFO("StepGuiderSxAO::SendThenReceive serial receive failed");
        }
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::SendThenReceive(unsigned char *pBuffer, unsigned bufferSize, unsigned char& recievedChar)
{
    bool bError = false;

    try
    {
        if (m_pSerialPort->Send(pBuffer, bufferSize))
        {
            throw ERROR_INFO("StepGuiderSxAO::SendThenReceive serial send failed");
        }

        if (m_pSerialPort->Receive(&recievedChar, 1))
        {
            throw ERROR_INFO("StepGuiderSxAO::SendThenReceive serial receive failed");
        }

        if (recievedChar == 'W')
        {
            if (m_pSerialPort->Receive(&recievedChar, 1))
            {
                throw ERROR_INFO("StepGuiderSxAO::step: Error reading another character after 'W'");
            }
        }
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::SendShortCommand(unsigned char command, unsigned char& response)
{
    bool bError = false;

    try
    {
        bError = SendThenReceive(command, response);
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

/*
 * Long commands send 7 bytes to the AO. The first char
 * is the command, the second is the direction and the remaining
 * 5 characters are a count.
 */

bool StepGuiderSxAO::SendLongCommand(unsigned char command, unsigned char parameter, unsigned count, unsigned char& response)
{
    bool bError = false;

    try
    {
        unsigned char cmdBuf[8]; // 7 chars + NULL

        if (count > 99999)
        {
            throw ERROR_INFO("StepGuiderSxAO::SendLongCommand invalid count");
        }

        int ret = _snprintf((char *)&cmdBuf, sizeof(cmdBuf), "%c%c%5.5d", command, parameter, count);

        if (ret < 0)
        {
            throw ERROR_INFO("StepGuiderSxAO::SendLongCommand snprintf failed");
        }

        if (ret >= sizeof(cmdBuf))
        {
            throw ERROR_INFO("StepGuiderSxAO::SendLongCommand snprintf buffer to small");
        }

        if (SendThenReceive((unsigned char *)&cmdBuf, 7, response))
        {
            throw ERROR_INFO("StepGuiderSxAO::SendLongCommand SendThenReceive failed");
        }
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

/*
 * the firmwareVersion command is unique command.  It sends 1 byte, and receives 3 digits
 * in response.
 */

bool StepGuiderSxAO::FirmwareVersion(unsigned& version)
{
    bool bError = false;

    try
    {
        version = 0;
        unsigned char cmd = 'V';
        unsigned char response;

        if (SendThenReceive(cmd, response))
        {
            throw ERROR_INFO("StepGuiderSxAO::firmwareVersion: SendThenReceive failed");
        }

        if (response != cmd)
        {
            throw ERROR_INFO("StepGuiderSxAO::firmwareVersion: response != cmd");
        }

        unsigned char buf[3];

        if (m_pSerialPort->Receive((unsigned char*)&buf, sizeof(buf)))
        {
            throw ERROR_INFO("StepGuiderSxAO::firmwareVersion: Receive failed");
        }

        for(int i=0;i<3;i++)
        {
            unsigned char ch = buf[i];

            if (ch < '0' || ch > '9')
            {
                throw ERROR_INFO("StepGuiderSxAO::firmwareVersion: invalid character");
            }
            version = (version * 10 ) + (ch - '0');
        }
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::Center(unsigned char cmd)
{
    bool bError = false;

    try
    {
        unsigned char response;

        if (m_pSerialPort->SetReceiveTimeout(CenterTimeout))
        {
            throw ERROR_INFO("StepGuiderSxAO::Center: SetReceiveTimeout failed");
        }

        if (SendShortCommand(cmd, response))
        {
            throw ERROR_INFO("StepGuiderSxAO::center SendShortCommand failed");
        }

        // there are two center commands and both return 'K'
        if (response != 'K')
        {
            throw ERROR_INFO("StepGuiderSxAO::center response != cmd");
        }

        if (m_pSerialPort->SetReceiveTimeout(DefaultTimeout))
        {
            throw ERROR_INFO("StepGuiderSxAO::Center: SetReceiveTimeout failed");
        }

        StepGuider::ZeroCurrentPosition();
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::Center()
{
    bool bError = false;

    try
    {
        if (Center('K'))
        {
            throw ERROR_INFO("StepGuiderSxAO::Center: Center() failed");
        }
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::Unjam(void)
{
    bool bError = false;

    try
    {
        if (Center('R'))
        {
            throw ERROR_INFO("StepGuiderSxAO::Center: Center() failed");
        }

    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::Step(GUIDE_DIRECTION direction, int steps)
{
    bool bError = false;

    try
    {
        unsigned char cmd = 'G';
        unsigned char parameter;
        unsigned char response;
        int currentPos = 0;

        switch (direction)
        {
            case NORTH:
                parameter = 'N';
                break;
            case SOUTH:
                parameter = 'S';
                break;
            case EAST:
                parameter = 'T';
                break;
            case WEST:
                parameter = 'W';
                break;
            default:
                throw ERROR_INFO("StepGuiderSxAO::step: invalid direction");
                break;
        }

        if (SendLongCommand(cmd, parameter, steps, response))
        {
            throw ERROR_INFO("StepGuiderSxAO::step: SendLongCommand failed");
        }

        if (response == 'L')
        {
            throw ERROR_INFO("StepGuiderSxAO::step: step: at limit");
        }

        if (response != cmd)
        {
            throw ERROR_INFO("StepGuiderSxAO::step: response != cmd");
        }

    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

int StepGuiderSxAO::MaxPosition(GUIDE_DIRECTION direction)
{
    return MaxSteps;
}

bool StepGuiderSxAO::IsAtLimit(GUIDE_DIRECTION direction, bool& isAtLimit)
{
    bool bError = false;

    try
    {
        unsigned char cmd = 'L';
        unsigned char response;

        if (SendThenReceive(cmd, response))
        {
            throw ERROR_INFO("StepGuiderSxAO::IsAtLimit: SendThenReceive failed");
        }

        if ((response & 0xf0) != 0x30)
        {
            throw ERROR_INFO("StepGuiderSxAO::IsAtLimit: invalid response ");
        }

        switch (direction)
        {
            case NORTH:
                isAtLimit = (response & 0x1) == 0x1;
                break;
            case SOUTH:
                isAtLimit = (response & 0x2) == 0x2;
                break;
            case EAST:
                isAtLimit = (response & 0x4) == 0x4;
                break;
            case WEST:
                isAtLimit = (response & 0x8) == 0x8;
                break;
            default:
                throw ERROR_INFO("StepGuiderSxAO::step: invalid direction");
                break;
        }
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

bool StepGuiderSxAO::ST4HasGuideOutput(void)
{
    return true;
}

bool StepGuiderSxAO::ST4HostConnected(void)
{
    return IsConnected();
}

bool StepGuiderSxAO::ST4HasNonGuiMove(void)
{
    return true;
}

bool StepGuiderSxAO::ST4PulseGuideScope(int direction, int duration)
{
    bool bError = false;

    try
    {
        char cmd = 'M';
        char parameter = 0;
        unsigned char response;

        switch (direction)
        {
            case NORTH:
                parameter = 'N';
                break;
            case SOUTH:
                parameter = 'S';
                break;
            case EAST:
                parameter = 'T';
                break;
            case WEST:
                parameter = 'W';
                break;
            default:
                throw ERROR_INFO("StepGuiderSxAO::ST4PulseGuideScope(): invalid direction");
                break;
        }

        if (SendLongCommand(cmd, parameter, duration, response))
        {
            throw ERROR_INFO("StepGuiderSxAO::ST4PulseGuideScope(): SendLongCommand failed");
        }

        if (response != cmd)
        {
            throw ERROR_INFO("StepGuiderSxAO::ST4PulseGuideScope(): response != cmd");
        }

        // The Step function is asynchronous, and there is no way to wait for it, so we just
        // wait
        wxMilliSleep(duration);
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}

#endif // STEPGUIDER_SXAO

<|endoftext|>


<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
 */
#ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_WTYPESELECT_HXX
#define INCLUDED_DBACCESS_SOURCE_UI_INC_WTYPESELECT_HXX

#include "FieldDescControl.hxx"
#include "TypeInfo.hxx"
#include "WTabPage.hxx"

#include <vcl/button.hxx>
#include <vcl/field.hxx>
#include <vcl/fixed.hxx>
#include <vcl/lstbox.hxx>

class SvStream;
class SvParser;
namespace dbaui
{
    class OTableDesignHelpBar;
    // OWizTypeSelectControl
    class OWizTypeSelectControl : public OFieldDescControl
    {
    protected:
        virtual void        ActivateAggregate( EControlType eType );
        virtual void        DeactivateAggregate( EControlType eType );

        virtual void        CellModified(long nRow, sal_uInt16 nColId );

        virtual ::com::sun::star::lang::Locale  GetLocale() const;
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > GetFormatter() const;
        virtual TOTypeInfoSP        getTypeInfo(sal_Int32 _nPos);
        virtual const OTypeInfoMap* getTypeInfo() const;
        virtual sal_Bool            isAutoIncrementValueEnabled() const;
        virtual OUString     getAutoIncrementValue() const;

    public:
        OWizTypeSelectControl(Window* pParent, const ResId& rResId,OTableDesignHelpBar* pHelpBar=NULL);
        virtual ~OWizTypeSelectControl();

        virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData> getMetaData();
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> getConnection();
    };

    // Wizard Page: OWizTypeSelectList
    // just defines the ::com::sun::star::ucb::Command for the Contextmenu
    class OWizTypeSelectList : public MultiListBox
    {
        sal_Bool                m_bPKey;
        sal_Bool                IsPrimaryKeyAllowed() const;
        void                    setPrimaryKey(  OFieldDescription* _pFieldDescr,
                                                sal_uInt16 _nPos,
                                                sal_Bool _bSet=sal_False);
    protected:
        virtual bool            PreNotify( NotifyEvent& rNEvt );
    public:
        OWizTypeSelectList( Window* pParent, WinBits nStyle = WB_BORDER ) : MultiListBox(pParent,nStyle) {};
        OWizTypeSelectList( Window* pParent, const ResId& rResId ) : MultiListBox(pParent,rResId) {};
        void                    SetPKey(sal_Bool bPKey) { m_bPKey = bPKey; }
    };

    // Wizard Page: OWizTypeSelect
    // Serves as base class for different copy properties.
    // Calls FillColumnList, when button AUTO is triggered
    class OWizTypeSelect : public OWizardPage
    {
        friend class OWizTypeSelectControl;
        friend class OWizTypeSelectList;

        DECL_LINK( ColumnSelectHdl, MultiListBox* );
        DECL_LINK( ButtonClickHdl, Button * );
    protected:
        OWizTypeSelectList      m_lbColumnNames;
        FixedLine               m_flColumns;
        OWizTypeSelectControl   m_aTypeControl;
        FixedLine               m_flAutoType;
        FixedText               m_ftAuto;
        NumericField            m_etAuto;
        PushButton              m_pbAuto;

        Image                   m_imgPKey;
        SvStream*               m_pParserStream; // stream to read the tokens from or NULL
        OUString         m_sAutoIncrementValue;
        sal_Int32               m_nDisplayRow;
        sal_Bool                m_bAutoIncrementEnabled;
        sal_Bool                m_bDuplicateName;

        void                    fillColumnList(sal_uInt32 nRows);
        virtual SvParser*       createReader(sal_Int32 _nRows) = 0;

        void                    EnableAuto(sal_Bool bEnable);
    public:
        virtual void            Reset ( );
        virtual void            ActivatePage( );
        virtual void            Resize();
        virtual sal_Bool        LeavePage();
        virtual OUString        GetTitle() const;

        OWizTypeSelect(Window* pParent, SvStream* _pStream = NULL );
        virtual ~OWizTypeSelect();

        inline void setDisplayRow(sal_Int32 _nRow) { m_nDisplayRow = _nRow - 1; }
        inline void setDuplicateName(sal_Bool _bDuplicateName) { m_bDuplicateName = _bDuplicateName; }
    };

    typedef OWizTypeSelect* (*TypeSelectionPageFactory)( Window*, SvStream& );
}
#endif // INCLUDED_DBACCESS_SOURCE_UI_INC_WTYPESELECT_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>coverity#707736 : Uninitialized scalar field<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
 */
#ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_WTYPESELECT_HXX
#define INCLUDED_DBACCESS_SOURCE_UI_INC_WTYPESELECT_HXX

#include "FieldDescControl.hxx"
#include "TypeInfo.hxx"
#include "WTabPage.hxx"

#include <vcl/button.hxx>
#include <vcl/field.hxx>
#include <vcl/fixed.hxx>
#include <vcl/lstbox.hxx>

class SvStream;
class SvParser;
namespace dbaui
{
    class OTableDesignHelpBar;
    // OWizTypeSelectControl
    class OWizTypeSelectControl : public OFieldDescControl
    {
    protected:
        virtual void        ActivateAggregate( EControlType eType );
        virtual void        DeactivateAggregate( EControlType eType );

        virtual void        CellModified(long nRow, sal_uInt16 nColId );

        virtual ::com::sun::star::lang::Locale  GetLocale() const;
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > GetFormatter() const;
        virtual TOTypeInfoSP        getTypeInfo(sal_Int32 _nPos);
        virtual const OTypeInfoMap* getTypeInfo() const;
        virtual sal_Bool            isAutoIncrementValueEnabled() const;
        virtual OUString     getAutoIncrementValue() const;

    public:
        OWizTypeSelectControl(Window* pParent, const ResId& rResId,OTableDesignHelpBar* pHelpBar=NULL);
        virtual ~OWizTypeSelectControl();

        virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData> getMetaData();
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> getConnection();
    };

    // Wizard Page: OWizTypeSelectList
    // just defines the ::com::sun::star::ucb::Command for the Contextmenu
    class OWizTypeSelectList : public MultiListBox
    {
        sal_Bool                m_bPKey;
        sal_Bool                IsPrimaryKeyAllowed() const;
        void                    setPrimaryKey(  OFieldDescription* _pFieldDescr,
                                                sal_uInt16 _nPos,
                                                sal_Bool _bSet = sal_False);
    protected:
        virtual bool            PreNotify( NotifyEvent& rNEvt );
    public:
        OWizTypeSelectList( Window* pParent, WinBits nStyle = WB_BORDER )
            : MultiListBox(pParent,nStyle)
            , m_bPKey(sal_False)
            {}
        OWizTypeSelectList( Window* pParent, const ResId& rResId )
            : MultiListBox(pParent,rResId)
            , m_bPKey(sal_False)
            {}
        void                    SetPKey(sal_Bool bPKey) { m_bPKey = bPKey; }
    };

    // Wizard Page: OWizTypeSelect
    // Serves as base class for different copy properties.
    // Calls FillColumnList, when button AUTO is triggered
    class OWizTypeSelect : public OWizardPage
    {
        friend class OWizTypeSelectControl;
        friend class OWizTypeSelectList;

        DECL_LINK( ColumnSelectHdl, MultiListBox* );
        DECL_LINK( ButtonClickHdl, Button * );
    protected:
        OWizTypeSelectList      m_lbColumnNames;
        FixedLine               m_flColumns;
        OWizTypeSelectControl   m_aTypeControl;
        FixedLine               m_flAutoType;
        FixedText               m_ftAuto;
        NumericField            m_etAuto;
        PushButton              m_pbAuto;

        Image                   m_imgPKey;
        SvStream*               m_pParserStream; // stream to read the tokens from or NULL
        OUString         m_sAutoIncrementValue;
        sal_Int32               m_nDisplayRow;
        sal_Bool                m_bAutoIncrementEnabled;
        sal_Bool                m_bDuplicateName;

        void                    fillColumnList(sal_uInt32 nRows);
        virtual SvParser*       createReader(sal_Int32 _nRows) = 0;

        void                    EnableAuto(sal_Bool bEnable);
    public:
        virtual void            Reset ( );
        virtual void            ActivatePage( );
        virtual void            Resize();
        virtual sal_Bool        LeavePage();
        virtual OUString        GetTitle() const;

        OWizTypeSelect(Window* pParent, SvStream* _pStream = NULL );
        virtual ~OWizTypeSelect();

        inline void setDisplayRow(sal_Int32 _nRow) { m_nDisplayRow = _nRow - 1; }
        inline void setDuplicateName(sal_Bool _bDuplicateName) { m_bDuplicateName = _bDuplicateName; }
    };

    typedef OWizTypeSelect* (*TypeSelectionPageFactory)( Window*, SvStream& );
}
#endif // INCLUDED_DBACCESS_SOURCE_UI_INC_WTYPESELECT_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<|endoftext|>


<commit_before>#include "dcpbuttoncomponent.h"

#include <duilinearlayout.h>
#include <duigridlayout.h>
#include <duilabel.h>
#include <duibutton.h>
#include <duitheme.h>

#include "dcpimageutils.h"
#include "dcpappletmetadata.h"

#include <QDebug>

DcpButtonComponent::DcpButtonComponent(
                            DcpCategory *category,
                            DcpAppletMetadata * metadata,
                            const QString& title,
                            QGraphicsWidget *parent):
    DcpComponent(category, title, parent), m_Metadata(metadata)
{

  createContents();
}

DcpButtonComponent::~DcpButtonComponent() {
}

void
DcpButtonComponent::createContents()
{

  //dummy, must modify constructor
  QString bigLabel = metadata()->text1();
  int bigWidth = 350;
  int bigHeight = 100;
  QString smallLabel = metadata()->text2();
  int smallX = 200;
  int smallY = 40;
  int smallWidth = 50;
  int smallHeight = 20;
  bool enable = true;

    m_GridLayout = new DuiGridLayout();

    m_GridLayout->setColumnMinimumWidth ( 0, smallX );
    m_GridLayout->setColumnMinimumWidth ( 1, smallWidth );
    m_GridLayout->setColumnMinimumWidth ( 2, bigWidth - smallX - smallWidth );

    m_GridLayout->setColumnMaximumWidth ( 0, smallX );
    m_GridLayout->setColumnMaximumWidth ( 1, smallWidth );
    m_GridLayout->setColumnMaximumWidth ( 2, bigWidth - smallX - smallWidth );

    m_GridLayout->setRowMinimumHeight ( 0, smallY );
    m_GridLayout->setRowMinimumHeight ( 1, smallHeight );
    m_GridLayout->setRowMinimumHeight ( 2, bigHeight - smallY - smallHeight );

    m_GridLayout->setRowMaximumHeight ( 0, smallY );
    m_GridLayout->setRowMaximumHeight ( 1, smallHeight );
    m_GridLayout->setRowMaximumHeight ( 2, bigHeight - smallY - smallHeight );

    /* //only test
    for (int yy =0; yy<3; yy++)
        for (int xx =0; xx<3; xx++)
            m_Layout->addItem(new DuiButton("text"), xx, yy, Qt::AlignCenter);
     */

    m_BigButton = new DuiButton(bigLabel);
//    m_BigButton->setView(new DcpButtonView(m_BigButton));
    m_BigButton->setObjectName("BigButton");
    m_BigButton->setMinimumWidth(bigWidth);
    m_BigButton->setMaximumWidth(bigWidth);
    m_BigButton->setMinimumHeight(bigHeight);
    m_BigButton->setMaximumHeight(bigHeight);

    m_SmallButtonOn = new DuiButton(smallLabel);
    m_SmallButtonOn->setObjectName("SmallButtonOn");
    m_SmallButtonOn->setMinimumWidth(smallWidth);
    m_SmallButtonOn->setMaximumWidth(smallWidth);
    m_SmallButtonOn->setMinimumHeight(smallHeight);
    m_SmallButtonOn->setMaximumHeight(smallHeight);

    m_SmallButtonOff = new DuiButton(smallLabel);
    m_SmallButtonOff->setObjectName("SmallButtonOff");
    m_SmallButtonOff->setMinimumWidth(smallWidth);
    m_SmallButtonOff->setMaximumWidth(smallWidth);
    m_SmallButtonOff->setMinimumHeight(smallHeight);
    m_SmallButtonOff->setMaximumHeight(smallHeight);

    m_DisableButton = new DuiButton(smallLabel);
    m_DisableButton->setObjectName("SmallButtonDisable");
    m_DisableButton->setMinimumWidth(smallWidth);
    m_DisableButton->setMaximumWidth(smallWidth);
    m_DisableButton->setMinimumHeight(smallHeight);
    m_DisableButton->setMaximumHeight(smallHeight);

    //m_Layout->addItem(m_BigButton, 0, 0, 3, 3, Qt::AlignCenter);
    m_GridLayout->addItem(m_BigButton, 0, 0, 3, 3, Qt::AlignLeft);
    m_GridLayout->addItem(m_SmallButtonOn, 1, 1, Qt::AlignCenter);
    m_GridLayout->addItem(m_SmallButtonOff, 1, 1, Qt::AlignCenter);
    m_GridLayout->addItem(m_DisableButton, 1, 1, Qt::AlignCenter);

    connect(m_BigButton, SIGNAL(clicked()), this, SLOT(bigClicked()));
    connect(m_SmallButtonOn, SIGNAL(clicked()), this, SLOT(smallClickedOn()));
    connect(m_SmallButtonOff, SIGNAL(clicked()), this, SLOT(smallClickedOff()));
    connect(m_DisableButton, SIGNAL(clicked()), this, SLOT(disableClicked()));

    setEnable(enable);

    m_BigButton->setZValue(1);
    m_SmallButtonOn->setZValue(2);
    m_SmallButtonOff->setZValue(3);
    m_DisableButton->setZValue(4);

    m_Layout = new DuiLinearLayout(Qt::Vertical);
    m_Layout->addItem(m_GridLayout);
    setLayout(m_Layout);
}

void DcpButtonComponent::setEnable(bool enable) {

    m_Enable = enable;

    if (m_Enable) {
        m_SmallButtonOn->show();
        m_SmallButtonOff->hide();
        m_DisableButton->hide();
    } else {
        m_SmallButtonOn->hide();
        m_SmallButtonOff->hide();
        m_DisableButton->show();
    }

}

void
DcpButtonComponent::onOrientationChange (const Dui::Orientation &orientation)
{
    // DcpComponent::onOrientationChange(orientation);
    Q_UNUSED(orientation);
}

/*
void DcpButtonComponent::paint (QPainter * painter,
                                     const QStyleOptionGraphicsItem * option,
                                     QWidget * widget)
{

    Q_UNUSED(option);
    Q_UNUSED(widget);

    // TODO: move to stylesheet
    int borderWidth = 2;
    QColor lineColor = QColor::fromRgb(0x3d, 0x2a, 0x0f);
    QColor bgColor = Qt::black;
    QColor borderColor = Qt::lightGray;
    // --

    if (m_Background.isNull() || m_Background.width() != size().width()){
        m_Background = DcpImageUtils::instance()->scaledPixmap(
                "C2-container-dark-landscape-123px", size().toSize());
        if (m_Background.isNull()) {
            qWarning ("theme lacks bg picture for settings component");
            return;
        }
    }
    painter->drawPixmap(QPoint(0, 0), m_Background);

//    DuiWidget::paint(painter, option, widget);

    // line between the title & description:
    QPen pen = painter->pen();
    pen.setColor(lineColor);
    pen.setWidth(1);
    painter->setPen(pen);
    qreal y = m_Caption->y() + m_Caption->size().height() + 2;
    painter->drawLine(borderWidth, y, size().width()-2*borderWidth, y);

}*/

void DcpButtonComponent::setTitleAlignment(Qt::Alignment align)
{
 //   m_Caption->setAlignment(align);
}

void DcpButtonComponent::addItem ( QGraphicsLayoutItem * item )
{
    m_Layout->addItem(item);
}

void
DcpButtonComponent::switchToSubPage()
{
    emit openSubPage(subPageId(), m_Metadata->name());
}

void
DcpButtonComponent::bigClicked()
{
    switchToSubPage();
}

<commit_msg>button backgrounds are restored for personalization<commit_after>#include "dcpbuttoncomponent.h"

#include <duilinearlayout.h>
#include <duigridlayout.h>
#include <duilabel.h>
#include <duibutton.h>
#include <duitheme.h>

#include "dcpimageutils.h"
#include "dcpappletmetadata.h"
#include "dcpbuttonview.h"

#include <QDebug>

DcpButtonComponent::DcpButtonComponent(
                            DcpCategory *category,
                            DcpAppletMetadata * metadata,
                            const QString& title,
                            QGraphicsWidget *parent):
    DcpComponent(category, title, parent), m_Metadata(metadata)
{

  createContents();
}

DcpButtonComponent::~DcpButtonComponent() {
}

void
DcpButtonComponent::createContents()
{

  //dummy, must modify constructor
  QString bigLabel = metadata()->text1();
  int bigWidth = 350;
  int bigHeight = 100;
  QString smallLabel = metadata()->text2();
  int smallX = 200;
  int smallY = 40;
  int smallWidth = 50;
  int smallHeight = 20;
  bool enable = true;

    m_GridLayout = new DuiGridLayout();

    m_GridLayout->setColumnMinimumWidth ( 0, smallX );
    m_GridLayout->setColumnMinimumWidth ( 1, smallWidth );
    m_GridLayout->setColumnMinimumWidth ( 2, bigWidth - smallX - smallWidth );

    m_GridLayout->setColumnMaximumWidth ( 0, smallX );
    m_GridLayout->setColumnMaximumWidth ( 1, smallWidth );
    m_GridLayout->setColumnMaximumWidth ( 2, bigWidth - smallX - smallWidth );

    m_GridLayout->setRowMinimumHeight ( 0, smallY );
    m_GridLayout->setRowMinimumHeight ( 1, smallHeight );
    m_GridLayout->setRowMinimumHeight ( 2, bigHeight - smallY - smallHeight );

    m_GridLayout->setRowMaximumHeight ( 0, smallY );
    m_GridLayout->setRowMaximumHeight ( 1, smallHeight );
    m_GridLayout->setRowMaximumHeight ( 2, bigHeight - smallY - smallHeight );

    /* //only test
    for (int yy =0; yy<3; yy++)
        for (int xx =0; xx<3; xx++)
            m_Layout->addItem(new DuiButton("text"), xx, yy, Qt::AlignCenter);
     */

    m_BigButton = new DuiButton(bigLabel);

    // TODO: this moves to the view config file when updating to newer dui
    m_BigButton->setView(new DcpButtonView(m_BigButton));
    // --

    m_BigButton->setObjectName("BigButton");
    m_BigButton->setMinimumWidth(bigWidth);
    m_BigButton->setMaximumWidth(bigWidth);
    m_BigButton->setMinimumHeight(bigHeight);
    m_BigButton->setMaximumHeight(bigHeight);

    m_SmallButtonOn = new DuiButton(smallLabel);
    m_SmallButtonOn->setObjectName("SmallButtonOn");
    m_SmallButtonOn->setMinimumWidth(smallWidth);
    m_SmallButtonOn->setMaximumWidth(smallWidth);
    m_SmallButtonOn->setMinimumHeight(smallHeight);
    m_SmallButtonOn->setMaximumHeight(smallHeight);

    m_SmallButtonOff = new DuiButton(smallLabel);
    m_SmallButtonOff->setObjectName("SmallButtonOff");
    m_SmallButtonOff->setMinimumWidth(smallWidth);
    m_SmallButtonOff->setMaximumWidth(smallWidth);
    m_SmallButtonOff->setMinimumHeight(smallHeight);
    m_SmallButtonOff->setMaximumHeight(smallHeight);

    m_DisableButton = new DuiButton(smallLabel);
    m_DisableButton->setObjectName("SmallButtonDisable");
    m_DisableButton->setMinimumWidth(smallWidth);
    m_DisableButton->setMaximumWidth(smallWidth);
    m_DisableButton->setMinimumHeight(smallHeight);
    m_DisableButton->setMaximumHeight(smallHeight);

    //m_Layout->addItem(m_BigButton, 0, 0, 3, 3, Qt::AlignCenter);
    m_GridLayout->addItem(m_BigButton, 0, 0, 3, 3, Qt::AlignLeft);
    m_GridLayout->addItem(m_SmallButtonOn, 1, 1, Qt::AlignCenter);
    m_GridLayout->addItem(m_SmallButtonOff, 1, 1, Qt::AlignCenter);
    m_GridLayout->addItem(m_DisableButton, 1, 1, Qt::AlignCenter);

    connect(m_BigButton, SIGNAL(clicked()), this, SLOT(bigClicked()));
    connect(m_SmallButtonOn, SIGNAL(clicked()), this, SLOT(smallClickedOn()));
    connect(m_SmallButtonOff, SIGNAL(clicked()), this, SLOT(smallClickedOff()));
    connect(m_DisableButton, SIGNAL(clicked()), this, SLOT(disableClicked()));

    setEnable(enable);

    m_BigButton->setZValue(1);
    m_SmallButtonOn->setZValue(2);
    m_SmallButtonOff->setZValue(3);
    m_DisableButton->setZValue(4);

    m_Layout = new DuiLinearLayout(Qt::Vertical);
    m_Layout->addItem(m_GridLayout);
    setLayout(m_Layout);
}

void DcpButtonComponent::setEnable(bool enable) {

    m_Enable = enable;

    if (m_Enable) {
        m_SmallButtonOn->show();
        m_SmallButtonOff->hide();
        m_DisableButton->hide();
    } else {
        m_SmallButtonOn->hide();
        m_SmallButtonOff->hide();
        m_DisableButton->show();
    }

}

void
DcpButtonComponent::onOrientationChange (const Dui::Orientation &orientation)
{
    // DcpComponent::onOrientationChange(orientation);
    Q_UNUSED(orientation);
}

/*
void DcpButtonComponent::paint (QPainter * painter,
                                     const QStyleOptionGraphicsItem * option,
                                     QWidget * widget)
{

    Q_UNUSED(option);
    Q_UNUSED(widget);

    // TODO: move to stylesheet
    int borderWidth = 2;
    QColor lineColor = QColor::fromRgb(0x3d, 0x2a, 0x0f);
    QColor bgColor = Qt::black;
    QColor borderColor = Qt::lightGray;
    // --

    if (m_Background.isNull() || m_Background.width() != size().width()){
        m_Background = DcpImageUtils::instance()->scaledPixmap(
                "C2-container-dark-landscape-123px", size().toSize());
        if (m_Background.isNull()) {
            qWarning ("theme lacks bg picture for settings component");
            return;
        }
    }
    painter->drawPixmap(QPoint(0, 0), m_Background);

//    DuiWidget::paint(painter, option, widget);

    // line between the title & description:
    QPen pen = painter->pen();
    pen.setColor(lineColor);
    pen.setWidth(1);
    painter->setPen(pen);
    qreal y = m_Caption->y() + m_Caption->size().height() + 2;
    painter->drawLine(borderWidth, y, size().width()-2*borderWidth, y);

}*/

void DcpButtonComponent::setTitleAlignment(Qt::Alignment align)
{
 //   m_Caption->setAlignment(align);
}

void DcpButtonComponent::addItem ( QGraphicsLayoutItem * item )
{
    m_Layout->addItem(item);
}

void
DcpButtonComponent::switchToSubPage()
{
    emit openSubPage(subPageId(), m_Metadata->name());
}

void
DcpButtonComponent::bigClicked()
{
    switchToSubPage();
}

<|endoftext|>