<commit_before>/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qdeclarativevaluespacesubscriber_p.h"

class QDeclarativeValueSpaceSubscriberPrivate
{
public:
    QDeclarativeValueSpaceSubscriberPrivate();
    ~QDeclarativeValueSpaceSubscriberPrivate();

    QValueSpaceSubscriber *subscriber;
};

QDeclarativeValueSpaceSubscriberPrivate::QDeclarativeValueSpaceSubscriberPrivate() :
    subscriber(0)
{
}

QDeclarativeValueSpaceSubscriberPrivate::~QDeclarativeValueSpaceSubscriberPrivate()
{
    if (subscriber)
        delete subscriber;
}

/*!
    \qmlclass ValueSpaceSubscriber QDeclarativeValueSpaceSubscriber

    \brief The QValueSpaceSubscriber class allows applications to read and
           subscribe to Value Space paths.

    \ingroup qml-publishsubscribe

    The ValueSpaceSubscriber element is part of the \bold {QtMobility.publishsubscribe 1.1} module.

    Each \l ValueSpaceSubscriber element represents a single value or path in the Value Space. The
    path is set using the \i path property.

    \code
    ValueSpaceSubscriber {
        id: nowPlaying
        path: "/applications/mediaplayer/now-playing"
    }
    \endcode

    The value is accessed using the \i value property.

    \code
    Text {
        text: nowPlaying.value
    }
    \endcode
*/

QDeclarativeValueSpaceSubscriber::QDeclarativeValueSpaceSubscriber() :
    d(new QDeclarativeValueSpaceSubscriberPrivate)
{
}

QDeclarativeValueSpaceSubscriber::~QDeclarativeValueSpaceSubscriber()
{
    delete d;
}

/*!
    \qmlproperty string ValueSpaceSubscriber::path

    This property holds the base path of the subscriber, and is read/write.
*/
void QDeclarativeValueSpaceSubscriber::setPath(QString path)
{
    if (subscriber) {
        if (d->subscriber->path() == path)
            return;
        d->subscriber->setPath(path);
        emit pathChanged();
    } else {
        d->subscriber = new QValueSpaceSubscriber(path);
        emit pathChanged();
    }
    // re-connect the signal
    connect(subscriber, SIGNAL(contentsChanged()),
            this, SIGNAL(contentsChanged()));
}

QString QDeclarativeValueSpaceSubscriber::path() const
{
    if (!d->subscriber)
        return QString();
    return d->subscriber->path();
}

/*!
    \qmlproperty QVariant ValueSpaceSubscriber::value

    This property holds the value of the key at the set path in the Value Space.
    Read-only.
*/
QVariant QDeclarativeValueSpaceSubscriber::value(const QString &subPath, const QVariant &def) const
{
    if (!d->subscriber)
        return QVariant();
    return d->subscriber->value(subPath, def);
}

/*!
    \qmlproperty QStringList ValueSpaceSubscriber::subPaths

    This property holds a list of known sub-paths of the currently set path.
*/
QStringList QDeclarativeValueSpaceSubscriber::subPaths() const
{
    if (!d->subscriber)
        return QStringList();
    return d->subscriber->subPaths();
}

/*!
    \qmlproperty bool ValueSpaceSubscriber::connected

    This property holds whether the subscriber is currently connected to the
    backing store of the Value Space.
*/
bool QDeclarativeValueSpaceSubscriber::isConnected() const
{
    if (!d->subscriber)
        return false;
    return d->subscriber->isConnected();
}
<commit_msg>Fixing up new declarative plugin so it actually builds<commit_after>/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qdeclarativevaluespacesubscriber_p.h"

class QDeclarativeValueSpaceSubscriberPrivate
{
public:
    QDeclarativeValueSpaceSubscriberPrivate();
    ~QDeclarativeValueSpaceSubscriberPrivate();

    QValueSpaceSubscriber *subscriber;
};

QDeclarativeValueSpaceSubscriberPrivate::QDeclarativeValueSpaceSubscriberPrivate() :
    subscriber(0)
{
}

QDeclarativeValueSpaceSubscriberPrivate::~QDeclarativeValueSpaceSubscriberPrivate()
{
    if (subscriber)
        delete subscriber;
}

/*!
    \qmlclass ValueSpaceSubscriber QDeclarativeValueSpaceSubscriber

    \brief The QValueSpaceSubscriber class allows applications to read and
           subscribe to Value Space paths.

    \ingroup qml-publishsubscribe

    The ValueSpaceSubscriber element is part of the \bold {QtMobility.publishsubscribe 1.1} module.

    Each \l ValueSpaceSubscriber element represents a single value or path in the Value Space. The
    path is set using the \i path property.

    \code
    ValueSpaceSubscriber {
        id: nowPlaying
        path: "/applications/mediaplayer/now-playing"
    }
    \endcode

    The value is accessed using the \i value property.

    \code
    Text {
        text: nowPlaying.value
    }
    \endcode
*/

QDeclarativeValueSpaceSubscriber::QDeclarativeValueSpaceSubscriber() :
    d(new QDeclarativeValueSpaceSubscriberPrivate)
{
}

QDeclarativeValueSpaceSubscriber::~QDeclarativeValueSpaceSubscriber()
{
    delete d;
}

/*!
    \qmlproperty string ValueSpaceSubscriber::path

    This property holds the base path of the subscriber, and is read/write.
*/
void QDeclarativeValueSpaceSubscriber::setPath(QString path)
{
    if (d->subscriber) {
        if (d->subscriber->path() == path)
            return;
        d->subscriber->setPath(path);
        emit pathChanged();
    } else {
        d->subscriber = new QValueSpaceSubscriber(path);
        emit pathChanged();
    }
    // re-connect the signal
    connect(d->subscriber, SIGNAL(contentsChanged()),
            this, SIGNAL(contentsChanged()));
}

QString QDeclarativeValueSpaceSubscriber::path() const
{
    if (!d->subscriber)
        return QString();
    return d->subscriber->path();
}

/*!
    \qmlproperty QVariant ValueSpaceSubscriber::value

    This property holds the value of the key at the set path in the Value Space.
    Read-only.
*/
QVariant QDeclarativeValueSpaceSubscriber::value(const QString &subPath, const QVariant &def) const
{
    if (!d->subscriber)
        return QVariant();
    return d->subscriber->value(subPath, def);
}

/*!
    \qmlproperty QStringList ValueSpaceSubscriber::subPaths

    This property holds a list of known sub-paths of the currently set path.
*/
QStringList QDeclarativeValueSpaceSubscriber::subPaths() const
{
    if (!d->subscriber)
        return QStringList();
    return d->subscriber->subPaths();
}

/*!
    \qmlproperty bool ValueSpaceSubscriber::connected

    This property holds whether the subscriber is currently connected to the
    backing store of the Value Space.
*/
bool QDeclarativeValueSpaceSubscriber::isConnected() const
{
    if (!d->subscriber)
        return false;
    return d->subscriber->isConnected();
}
<|endoftext|>


<commit_before>/*
 * Copyright 2009-2011 Bjorn Fahller <bjorn@fahller.se>
 * All rights reserved
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. 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.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
 */

#ifndef POLL_HPP
#define POLL_HPP

extern "C" void perror(const char*);
#include <cassert>

namespace crpcut {
  namespace wrapped {
    int close(int fd);
  }
}

extern "C"
{
#include <sys/select.h>
}

namespace crpcut {
  namespace wrapped {
    int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
  }
  template <size_t N>
  struct polldata

  {
    polldata()
      : num_subscribers(0U),
        pending_fds(0U)
    {
      memset(&rset, 0, sizeof(rset));
      memset(&wset, 0, sizeof(wset));
      memset(&xset, 0, sizeof(xset));
      // FD_ZERO(&rset);
      // FD_ZERO(&wset);
      // FD_ZERO(&xset);
    }
    struct fdinfo
    {
      fdinfo(int fd_ = 0, int mode_ = 0, void *ptr_ = 0)
        : fd(fd_), mode(mode_), ptr(ptr_)
      {
      }
      int   fd;
      int   mode;
      void *ptr;
    };
    fdinfo access[N];
    size_t num_subscribers;
    size_t pending_fds;
    fd_set rset;
    fd_set wset;
    fd_set xset;

    static const int readbit  = 1;
    static const int writebit = 2;
    static const int hupbit   = 4;
  };
}

namespace crpcut {
  template <typename T, size_t N>
  class poll : private polldata<N>
  {
  public:
    struct polltype
    {
      typedef enum { r = 1, w = 2, rw = 3 } type;
    };
    class descriptor
    {
    public:
      T* operator->() const { return data; }
      T* get() const { return data; }
      bool read() const;
      bool write() const;
      bool hup() const;
      bool timeout() const { return mode == 0; }
    private:
      descriptor(T* t, int m) : data(t), mode(m) {}

      T* data;
      int mode;
      friend class poll<T, N>;
    };
    poll();
    ~poll();
    void add_fd(int fd, T* data, int flags = polltype::r);
    void del_fd(int fd);
    descriptor wait(int timeout_ms = -1);
    size_t num_fds() const;
  };
}

namespace crpcut {
  template <typename T, size_t N>
  inline bool poll<T, N>::descriptor::read() const
  {
    return mode & polldata<N>::readbit;
  }

  template <typename T, size_t N>
  inline bool poll<T, N>::descriptor::write() const
  {
    return mode & polldata<N>::writebit;
  }

  template <typename T, size_t N>
  inline bool poll<T, N>::descriptor::hup() const
  {
    return mode & polldata<N>::hupbit;
  }

  template <typename T, size_t N>
  inline poll<T, N>::poll()
  {
  }

  template <typename T, size_t N>
  inline poll<T, N>::~poll()
  {
  }

  template <typename T, size_t N>
  inline void poll<T, N>::add_fd(int fd, T* data, int flags)
  {
    this->access[this->num_subscribers++] = typename polldata<N>::fdinfo(fd, flags, data);
  }

  template <typename T, size_t N>
  inline void poll<T, N>::del_fd(int fd)
  {
    for (size_t i = 0; i < this->num_subscribers; ++i)
      {
        if (this->access[i].fd == fd)
          {
            this->access[i] = this->access[--this->num_subscribers];
            if (   FD_ISSET(fd, &this->xset)
                || FD_ISSET(fd, &this->rset)
                || FD_ISSET(fd, &this->wset))
              {
                FD_CLR(fd, &this->rset);
                FD_CLR(fd, &this->wset);
                FD_CLR(fd, &this->xset);
                --this->pending_fds;
              }
            return;
          }
      }
    assert("fd not found" == 0);
  }

  template <typename T, size_t N>
  inline typename poll<T, N>::descriptor poll<T, N>::wait(int timeout_ms)
  {
    if (this->pending_fds == 0)
      {
        int maxfd = 0;
        for (size_t i = 0; i < this->num_subscribers; ++i)
          {
            int fd = this->access[i].fd;
            if (fd > maxfd) maxfd = fd;
            if (this->access[i].mode & polltype::r) FD_SET(fd, &this->rset);
            if (this->access[i].mode & polltype::w) FD_SET(fd, &this->wset);
            FD_SET(fd, &this->xset);
          }
        struct timeval tv = { timeout_ms / 1000, (timeout_ms % 1000) * 1000 };
        for (;;)
          {
            int rv = wrapped::select(maxfd + 1,
                                     &this->rset,
                                     &this->wset,
                                     &this->xset,
                                     timeout_ms == -1 ? 0 : &tv);
            if (rv == -1 && errno == EINTR) continue;
            assert(rv >= 0);
            if (rv == 0) return descriptor(0,0); // timeout
            this->pending_fds = size_t(rv);
            break;
          }
      }
    for (size_t j = 0; j < this->num_subscribers; ++j)
      {
        int fd = this->access[j].fd;
        int mode = 0;
        if (FD_ISSET(fd, &this->rset))
          {
            mode|= polldata<N>::readbit;
            FD_CLR(fd, &this->rset);
          }
        if (FD_ISSET(fd, &this->wset))
          {
            mode|= polldata<N>::writebit;
            FD_CLR(fd, &this->wset);
          }
        if (FD_ISSET(fd, &this->xset))
          {
            mode|= polldata<N>::hupbit;
            FD_CLR(fd, &this->xset);
          }
        if (mode)
          {
            --this->pending_fds;
            return descriptor(static_cast<T*>(this->access[j].ptr), mode);
          }
      }
    assert("no matching fd" == 0);
    return descriptor(0, 0);
  }

  template <typename T, size_t N>
  inline size_t poll<T, N>::num_fds() const
  {
    return this->num_subscribers;
  }
}

#endif // POLL_HPP
<commit_msg>Went a bit overboard with clang++ cleanup<commit_after>/*
 * Copyright 2009-2011 Bjorn Fahller <bjorn@fahller.se>
 * All rights reserved
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. 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.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
 */

#ifndef POLL_HPP
#define POLL_HPP

extern "C" void perror(const char*);
#include <cassert>

namespace crpcut {
  namespace wrapped {
    int close(int fd);
  }
}

extern "C"
{
#include <sys/select.h>
}

namespace crpcut {
  namespace wrapped {
    int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
  }
  template <size_t N>
  struct polldata

  {
    polldata()
      : num_subscribers(0U),
        pending_fds(0U)
    {
      FD_ZERO(&rset);
      FD_ZERO(&wset);
      FD_ZERO(&xset);
    }
    struct fdinfo
    {
      fdinfo(int fd_ = 0, int mode_ = 0, void *ptr_ = 0)
        : fd(fd_), mode(mode_), ptr(ptr_)
      {
      }
      int   fd;
      int   mode;
      void *ptr;
    };
    fdinfo access[N];
    size_t num_subscribers;
    size_t pending_fds;
    fd_set rset;
    fd_set wset;
    fd_set xset;

    static const int readbit  = 1;
    static const int writebit = 2;
    static const int hupbit   = 4;
  };
}

namespace crpcut {
  template <typename T, size_t N>
  class poll : private polldata<N>
  {
  public:
    struct polltype
    {
      typedef enum { r = 1, w = 2, rw = 3 } type;
    };
    class descriptor
    {
    public:
      T* operator->() const { return data; }
      T* get() const { return data; }
      bool read() const;
      bool write() const;
      bool hup() const;
      bool timeout() const { return mode == 0; }
    private:
      descriptor(T* t, int m) : data(t), mode(m) {}

      T* data;
      int mode;
      friend class poll<T, N>;
    };
    poll();
    ~poll();
    void add_fd(int fd, T* data, int flags = polltype::r);
    void del_fd(int fd);
    descriptor wait(int timeout_ms = -1);
    size_t num_fds() const;
  };
}

namespace crpcut {
  template <typename T, size_t N>
  inline bool poll<T, N>::descriptor::read() const
  {
    return mode & polldata<N>::readbit;
  }

  template <typename T, size_t N>
  inline bool poll<T, N>::descriptor::write() const
  {
    return mode & polldata<N>::writebit;
  }

  template <typename T, size_t N>
  inline bool poll<T, N>::descriptor::hup() const
  {
    return mode & polldata<N>::hupbit;
  }

  template <typename T, size_t N>
  inline poll<T, N>::poll()
  {
  }

  template <typename T, size_t N>
  inline poll<T, N>::~poll()
  {
  }

  template <typename T, size_t N>
  inline void poll<T, N>::add_fd(int fd, T* data, int flags)
  {
    this->access[this->num_subscribers++] = typename polldata<N>::fdinfo(fd, flags, data);
  }

  template <typename T, size_t N>
  inline void poll<T, N>::del_fd(int fd)
  {
    for (size_t i = 0; i < this->num_subscribers; ++i)
      {
        if (this->access[i].fd == fd)
          {
            this->access[i] = this->access[--this->num_subscribers];
            if (   FD_ISSET(fd, &this->xset)
                || FD_ISSET(fd, &this->rset)
                || FD_ISSET(fd, &this->wset))
              {
                FD_CLR(fd, &this->rset);
                FD_CLR(fd, &this->wset);
                FD_CLR(fd, &this->xset);
                --this->pending_fds;
              }
            return;
          }
      }
    assert("fd not found" == 0);
  }

  template <typename T, size_t N>
  inline typename poll<T, N>::descriptor poll<T, N>::wait(int timeout_ms)
  {
    if (this->pending_fds == 0)
      {
        int maxfd = 0;
        for (size_t i = 0; i < this->num_subscribers; ++i)
          {
            int fd = this->access[i].fd;
            if (fd > maxfd) maxfd = fd;
            if (this->access[i].mode & polltype::r) FD_SET(fd, &this->rset);
            if (this->access[i].mode & polltype::w) FD_SET(fd, &this->wset);
            FD_SET(fd, &this->xset);
          }
        struct timeval tv = { timeout_ms / 1000, (timeout_ms % 1000) * 1000 };
        for (;;)
          {
            int rv = wrapped::select(maxfd + 1,
                                     &this->rset,
                                     &this->wset,
                                     &this->xset,
                                     timeout_ms == -1 ? 0 : &tv);
            if (rv == -1 && errno == EINTR) continue;
            assert(rv >= 0);
            if (rv == 0) return descriptor(0,0); // timeout
            this->pending_fds = size_t(rv);
            break;
          }
      }
    for (size_t j = 0; j < this->num_subscribers; ++j)
      {
        int fd = this->access[j].fd;
        int mode = 0;
        if (FD_ISSET(fd, &this->rset))
          {
            mode|= polldata<N>::readbit;
            FD_CLR(fd, &this->rset);
          }
        if (FD_ISSET(fd, &this->wset))
          {
            mode|= polldata<N>::writebit;
            FD_CLR(fd, &this->wset);
          }
        if (FD_ISSET(fd, &this->xset))
          {
            mode|= polldata<N>::hupbit;
            FD_CLR(fd, &this->xset);
          }
        if (mode)
          {
            --this->pending_fds;
            return descriptor(static_cast<T*>(this->access[j].ptr), mode);
          }
      }
    assert("no matching fd" == 0);
    return descriptor(0, 0);
  }

  template <typename T, size_t N>
  inline size_t poll<T, N>::num_fds() const
  {
    return this->num_subscribers;
  }
}

#endif // POLL_HPP
<|endoftext|>


<commit_before>/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.

Licensed 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

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#include "tensorflow_lite_support/cc/port/gmock.h"
#include "tensorflow_lite_support/cc/port/gtest.h"
#include "tensorflow_lite_support/cc/test/test_utils.h"
#include "tensorflow_lite_support/c/task/vision/image_classifier_c_api.h"
#include "tensorflow_lite_support/examples/task/vision/desktop/utils/image_utils_c.h"
#include "tensorflow_lite_support/c/task/vision/classification_result_c_api.h"
#include "tensorflow_lite_support/c/task/vision/core/frame_buffer_c_api.h"

namespace tflite {
namespace task {
namespace vision {
namespace {

using ::tflite::task::JoinPath;

constexpr char kTestDataDirectory[] =
    "tensorflow_lite_support/cc/test/testdata/task/vision/";
// Float model.
constexpr char kMobileNetFloatWithMetadata[] = "mobilenet_v2_1.0_224.tflite";
// Quantized model.
constexpr char kMobileNetQuantizedWithMetadata[] =
    "mobilenet_v1_0.25_224_quant.tflite";
// Hello world flowers classifier supporting 5 classes (quantized model).
constexpr char kAutoMLModelWithMetadata[] = "automl_labeler_model.tflite";

ImageData LoadImage(const char* image_name) {
  return DecodeImageFromFile(JoinPath("./" /*test src dir*/,
                                      kTestDataDirectory, image_name).data());
}

TEST(ImageClassifierFromFileTest, FailsWithMissingModelPath) {
//   ImageClassifierOptions *options = ImageClassifierOptionsCreate();

  ImageClassifier *image_classifier = ImageClassifierFromFile("");
  ASSERT_EQ(image_classifier, nullptr);
}

TEST(ImageClassifierFromFileTest, SucceedsWithModelPath) {
  ImageClassifier *image_classifier = ImageClassifierFromFile(JoinPath("./" /*test src dir*/, kTestDataDirectory,
               kMobileNetQuantizedWithMetadata).data());
  EXPECT_NE(image_classifier, nullptr);
  ImageClassifierDelete(image_classifier);
}

TEST(ImageClassifierFromOptionsTest, FailsWithMissingModelPath) {
  ImageClassifierOptions *options = ImageClassifierOptionsCreate();
  ImageClassifier *image_classifier = ImageClassifierFromOptions(options);
  ASSERT_EQ(image_classifier, nullptr);
}

TEST(ImageClassifierFromOptionsTest, SucceedsWithModelPath) {
  ImageClassifierOptions *options = ImageClassifierOptionsCreate();
  const char *model_path = JoinPath("./" /*test src dir*/, kTestDataDirectory,
               kMobileNetQuantizedWithMetadata).data();

  ImageClassifierOptionsSetModelFilePath(options, model_path);
  ImageClassifier *image_classifier = ImageClassifierFromOptions(options);
  EXPECT_NE(image_classifier, nullptr);
  ImageClassifierDelete(image_classifier);
}

class ImageClassifierClassifyTest : public ::testing::Test {
 protected:
  void SetUp() override {
     image_classifier = ImageClassifierFromFile(JoinPath("./" /*test src dir*/, kTestDataDirectory,
               kMobileNetQuantizedWithMetadata).data());
     ASSERT_NE(image_classifier, nullptr);
  }

  void TearDown() override {
     ImageClassifierDelete(image_classifier);
  }

  ImageClassifier *image_classifier;
};

TEST_F(ImageClassifierClassifyTest, SucceedsWithModelPath) {
  struct ImageData image_data = LoadImage("burger-224.png");

  struct FrameBuffer frame_buffer = {.dimension.width = image_data.width,
                                     .dimension.height = image_data.height,
                                     .plane.buffer = image_data.pixel_data,
                                     .plane.stride.row_stride_bytes = image_data.width  * image_data.channels,
                                     .plane.stride.pixel_stride_bytes = image_data.channels,
                                     .format = kRGB};

  struct ClassificationResult *classification_result = ImageClassifierClassify(image_classifier, &frame_buffer);

  ImageDataFree(&image_data);

  ASSERT_NE(classification_result, nullptr) << "Classification Result is NULL";
  EXPECT_TRUE(classification_result->size >= 1) << "Classification Result size is 0";
  EXPECT_NE(classification_result->classifications, nullptr) << "Classification Result Classifications is NULL";
  EXPECT_TRUE(classification_result->classifications->size >= 1) << "Classification Result Classifications Size is NULL";
  EXPECT_NE(classification_result->classifications->classes, nullptr) << "Classification Result Classifications Classes is NULL";

  ImageClassifierClassificationResultDelete(classification_result);
}

}  // namespace
}  // namespace vision
}  // namespace task
}  // namespace tflite
<commit_msg>Image Classifier C API: Updated test<commit_after>/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.

Licensed 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

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#include "tensorflow_lite_support/cc/port/gmock.h"
#include "tensorflow_lite_support/cc/port/gtest.h"
#include "tensorflow_lite_support/cc/test/test_utils.h"
#include "tensorflow_lite_support/c/task/vision/image_classifier_c_api.h"
#include "tensorflow_lite_support/examples/task/vision/desktop/utils/image_utils_c.h"
#include "tensorflow_lite_support/c/task/vision/classification_result_c_api.h"
#include "tensorflow_lite_support/c/task/vision/core/frame_buffer_c_api.h"

namespace tflite {
namespace task {
namespace vision {
namespace {

using ::tflite::task::JoinPath;

constexpr char kTestDataDirectory[] =
    "tensorflow_lite_support/cc/test/testdata/task/vision/";
// Float model.
constexpr char kMobileNetFloatWithMetadata[] = "mobilenet_v2_1.0_224.tflite";
// Quantized model.
constexpr char kMobileNetQuantizedWithMetadata[] =
    "mobilenet_v1_0.25_224_quant.tflite";
// Hello world flowers classifier supporting 5 classes (quantized model).
constexpr char kAutoMLModelWithMetadata[] = "automl_labeler_model.tflite";

ImageData LoadImage(const char* image_name) {
  return DecodeImageFromFile(JoinPath("./" /*test src dir*/,
                                      kTestDataDirectory, image_name).data());
}

TEST(ImageClassifierFromFileTest, FailsWithMissingModelPath) {
  ImageClassifier *image_classifier = ImageClassifierFromFile("");
  ASSERT_EQ(image_classifier, nullptr);
}

TEST(ImageClassifierFromFileTest, SucceedsWithModelPath) {
  ImageClassifier *image_classifier = ImageClassifierFromFile(JoinPath("./" /*test src dir*/, kTestDataDirectory,
               kMobileNetQuantizedWithMetadata).data());
  EXPECT_NE(image_classifier, nullptr);
  ImageClassifierDelete(image_classifier);
}

TEST(ImageClassifierFromOptionsTest, FailsWithMissingModelPath) {
  ImageClassifierOptions *options = ImageClassifierOptionsCreate();
  ImageClassifier *image_classifier = ImageClassifierFromOptions(options);
  ASSERT_EQ(image_classifier, nullptr);
}

TEST(ImageClassifierFromOptionsTest, SucceedsWithModelPath) {
  ImageClassifierOptions *options = ImageClassifierOptionsCreate();
  const char *model_path = JoinPath("./" /*test src dir*/, kTestDataDirectory,
               kMobileNetQuantizedWithMetadata).data();

  ImageClassifierOptionsSetModelFilePath(options, model_path);
  ImageClassifier *image_classifier = ImageClassifierFromOptions(options);
  EXPECT_NE(image_classifier, nullptr);
  ImageClassifierDelete(image_classifier);
}

class ImageClassifierClassifyTest : public ::testing::Test {
 protected:
  void SetUp() override {
     image_classifier = ImageClassifierFromFile(JoinPath("./" /*test src dir*/, kTestDataDirectory,
               kMobileNetQuantizedWithMetadata).data());
     ASSERT_NE(image_classifier, nullptr);
  }

  void TearDown() override {
     ImageClassifierDelete(image_classifier);
  }

  ImageClassifier *image_classifier;
};

TEST_F(ImageClassifierClassifyTest, SucceedsWithImageData) {
  struct ImageData image_data = LoadImage("burger-224.png");

  struct FrameBuffer frame_buffer = {.dimension.width = image_data.width,
                                     .dimension.height = image_data.height,
                                     .plane.buffer = image_data.pixel_data,
                                     .plane.stride.row_stride_bytes = image_data.width  * image_data.channels,
                                     .plane.stride.pixel_stride_bytes = image_data.channels,
                                     .format = kRGB};

  struct ClassificationResult *classification_result = ImageClassifierClassify(image_classifier, &frame_buffer);

  ImageDataFree(&image_data);

  ASSERT_NE(classification_result, nullptr) << "Classification Result is NULL";
  EXPECT_TRUE(classification_result->size >= 1) << "Classification Result size is 0";
  EXPECT_NE(classification_result->classifications, nullptr) << "Classification Result Classifications is NULL";
  EXPECT_TRUE(classification_result->classifications->size >= 1) << "Classification Result Classifications Size is NULL";
  EXPECT_NE(classification_result->classifications->classes, nullptr) << "Classification Result Classifications Classes is NULL";

  ImageClassifierClassificationResultDelete(classification_result);
}

}  // namespace
}  // namespace vision
}  // namespace task
}  // namespace tflite
<|endoftext|>


<commit_before>//------------------------------------------------------------------------------
// Copyright (c) 2016 John D. Haughton
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//------------------------------------------------------------------------------

#include <cstdio>

#include "ConsoleImpl.h"

#include "PLT/KeyCode.h"

static FILE* input_fp = nullptr;

bool ConsoleImpl::openInputFile(const char* filename)
{
   input_fp = fopen(filename, "r");
   return isInputFileOpen();
}

bool ConsoleImpl::isInputFileOpen() { return input_fp != nullptr; }

void ConsoleImpl::closeInputFile()
{
   fclose(input_fp);
   input_fp = nullptr;
}

int ConsoleImpl::getInput(unsigned timeout_ms)
{
   if(input_fp != nullptr)
   {
      if(feof(input_fp))
      {
         closeInputFile();
      }
      else
      {
         return fgetc(input_fp);
      }
   }

   curses.timeout(timeout_ms);

   int ch = curses.getch();

   // Some PLT::KeyCode to ZSCII conversions
   switch(ch)
   {
   case PLT::BACKSPACE: return 0x08;
   case PLT::TAB:       return 0x09;
   case PLT::RETURN:    return 0x0A;
   case PLT::ESCAPE:    return 0x1B;

   case 0x7F:           return 0x08;

   case PLT::UP:        return 0x81;
   case PLT::DOWN:      return 0x82;
   case PLT::LEFT:      return 0x83;
   case PLT::RIGHT:     return 0x84;

   case PLT::F1:        return 0x85;
   case PLT::F2:        return 0x86;
   case PLT::F3:        return 0x87;
   case PLT::F4:        return 0x88;
   case PLT::F5:        return 0x89;
   case PLT::F6:        return 0x8A;
   case PLT::F7:        return 0x8B;
   case PLT::F8:        return 0x8C;
   case PLT::F9:        return 0x8D;
   case PLT::F10:       return 0x8E;
   case PLT::F11:       return 0x8F;
   case PLT::F12:       return 0x90;

   // Ignore
   case PLT::MENU:      return 1;
   case PLT::SELECT:    return 1;
   case PLT::HOME:      return 1;
   case PLT::VOL_UP:    return 1;
   case PLT::VOL_DOWN:  return 1;

   // Quit game
   case PLT::BACK:      return -1;
   }

   return ch;
}
<commit_msg>Change some key mappings inside the Z engine<commit_after>//------------------------------------------------------------------------------
// Copyright (c) 2016 John D. Haughton
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//------------------------------------------------------------------------------

#include <cstdio>

#include "ConsoleImpl.h"

#include "PLT/KeyCode.h"

static FILE* input_fp = nullptr;

bool ConsoleImpl::openInputFile(const char* filename)
{
   input_fp = fopen(filename, "r");
   return isInputFileOpen();
}

bool ConsoleImpl::isInputFileOpen() { return input_fp != nullptr; }

void ConsoleImpl::closeInputFile()
{
   fclose(input_fp);
   input_fp = nullptr;
}

int ConsoleImpl::getInput(unsigned timeout_ms)
{
   if(input_fp != nullptr)
   {
      if(feof(input_fp))
      {
         closeInputFile();
      }
      else
      {
         return fgetc(input_fp);
      }
   }

   curses.timeout(timeout_ms);

   int ch = curses.getch();

   // Some PLT::KeyCode to ZSCII conversions
   switch(ch)
   {
   case PLT::BACKSPACE: return 0x08;
   case PLT::TAB:       return 0x09;
   case PLT::RETURN:    return 0x0A;
   case PLT::ESCAPE:    return 0x1B;

   case 0x7F:           return 0x08;

   case PLT::UP:        return 0x81;
   case PLT::DOWN:      return 0x82;
   case PLT::LEFT:      return 0x83;
   case PLT::RIGHT:     return 0x84;

   case PLT::F1:        return 0x85;
   case PLT::F2:        return 0x86;
   case PLT::F3:        return 0x87;
   case PLT::F4:        return 0x88;
   case PLT::F5:        return 0x89;
   case PLT::F6:        return 0x8A;
   case PLT::F7:        return 0x8B;
   case PLT::F8:        return 0x8C;
   case PLT::F9:        return 0x8D;
   case PLT::F10:       return 0x8E;
   case PLT::F11:       return 0x8F;
   case PLT::F12:       return 0x90;

   // Ignore
   case PLT::SELECT:    return 1;
   case PLT::HOME:      return 1;
   case PLT::END:       return 1;
   case PLT::PAGE_UP:   return 1;
   case PLT::PAGE_DOWN: return 1;
   case PLT::VOL_UP:    return 1;
   case PLT::VOL_DOWN:  return 1;

   // Quit game
   case PLT::MENU:      return -1;
   case PLT::BACK:      return -1;
   }

   return ch;
}
<|endoftext|>


<commit_before>#include "gtest/gtest.h"
#include <rapidcheck/gtest.h>

#include SPECIFIC_HEADER

// Running tests

TEST(TEST_NAME, Zero)
{
  ASSERT_EQ(0, less_significant(0));
}

TEST(TEST_NAME, PowerOfTwo)
{
  ASSERT_EQ(128, less_significant(128));
}

TEST(TEST_NAME, Nine)
{
  ASSERT_EQ(1, less_significant(9));
}

RC_GTEST_PROP(TEST_NAME, AnswerIsPowerOfTwo, (unsigned N))
{
  auto answer = less_significant(N);
  RC_ASSERT((answer & (answer-1)) == decltype(answer)());
}

RC_GTEST_PROP(TEST_NAME, AnswerIsBitOfInput, (unsigned N))
{
  auto answer = less_significant(N);
  RC_ASSERT((N | answer) == N);
}

RC_GTEST_PROP(TEST_NAME, AnswerIsTheLowestBit, (unsigned N))
{
  RC_PRE(N > unsigned());
  RC_PRE(N & (N-1)); //not a power of two
  auto answer = less_significant(N);
  RC_ASSERT((N ^ answer) > answer);
}

RC_GTEST_PROP(TEST_NAME, AnswerIsItselfForPowerOfTwo, ())
{
  auto power = *rc::gen::inRange(decltype(sizeof(unsigned))(), 8 * sizeof(unsigned));
  unsigned N = 1 << power;
  RC_ASSERT(N == less_significant(N));
}

int main(int argc, char **argv)
{
  ::testing::InitGoogleTest(&argc, argv);
  int ret { RUN_ALL_TESTS() };
  return ret;
}

<commit_msg>[less-significant-bit][vs] Fix implicit conversion from unsigned to bool<commit_after>#include "gtest/gtest.h"
#include <rapidcheck/gtest.h>

#include SPECIFIC_HEADER

// Running tests

TEST(TEST_NAME, Zero)
{
  ASSERT_EQ(0, less_significant(0));
}

TEST(TEST_NAME, PowerOfTwo)
{
  ASSERT_EQ(128, less_significant(128));
}

TEST(TEST_NAME, Nine)
{
  ASSERT_EQ(1, less_significant(9));
}

RC_GTEST_PROP(TEST_NAME, AnswerIsPowerOfTwo, (unsigned N))
{
  auto answer = less_significant(N);
  RC_ASSERT((answer & (answer-1)) == decltype(answer)());
}

RC_GTEST_PROP(TEST_NAME, AnswerIsBitOfInput, (unsigned N))
{
  auto answer = less_significant(N);
  RC_ASSERT((N | answer) == N);
}

RC_GTEST_PROP(TEST_NAME, AnswerIsTheLowestBit, (unsigned N))
{
  RC_PRE(N > unsigned());
  RC_PRE((N & (N-1)) != unsigned()); //not a power of two
  auto answer = less_significant(N);
  RC_ASSERT((N ^ answer) > answer);
}

RC_GTEST_PROP(TEST_NAME, AnswerIsItselfForPowerOfTwo, ())
{
  auto power = *rc::gen::inRange(decltype(sizeof(unsigned))(), 8 * sizeof(unsigned));
  unsigned N = 1 << power;
  RC_ASSERT(N == less_significant(N));
}

int main(int argc, char **argv)
{
  ::testing::InitGoogleTest(&argc, argv);
  int ret { RUN_ALL_TESTS() };
  return ret;
}

<|endoftext|>


<commit_before><commit_msg>Lower image quality for chromoting to improve encode speed and compression ratio<commit_after><|endoftext|>


<commit_before><commit_msg>remove unused #define SFX_ITEMTYPE_STATBAR in workwin.cxx<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: objshimp.hxx,v $
 *
 *  $Revision: 1.41 $
 *
 *  last change: $Author: obo $ $Date: 2008-02-26 15:12:13 $
 *
 *  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 _SFX_OBJSHIMP_HXX
#define _SFX_OBJSHIMP_HXX

//#include <hash_map>

#ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
#include <com/sun/star/frame/XModel.hpp>
#endif
#ifndef _DATETIME_HXX
#include <tools/datetime.hxx>
#endif

#include <svtools/securityoptions.hxx>
#include <sfx2/objsh.hxx>
#include "sfx2/docmacromode.hxx"
#include "bitset.hxx"

namespace svtools { class AsynchronLink; }

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

DBG_NAMEEX(SfxObjectShell)

class SfxViewFrame;
struct MarkData_Impl
{
    String aMark;
    String aUserData;
    SfxViewFrame* pFrame;
};

class SfxFrame;
class SfxToolBoxConfig;
class SfxAcceleratorManager;
class SfxBasicManagerHolder;

struct SfxObjectShell_Impl : public ::sfx2::IMacroDocumentAccess
{
    ::comphelper::EmbeddedObjectContainer* mpObjectContainer;
    SfxAcceleratorManager*  pAccMgr;
    SfxConfigManager*   pCfgMgr;
    SfxBasicManagerHolder*
                        pBasicManager;
    SfxObjectShell&     rDocShell;
    ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >
                        xBasicLibraries;
    ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >
                        xDialogLibraries;
    ::sfx2::DocumentMacroMode
                        aMacroMode;
    SfxProgress*        pProgress;
    String              aTitle;
    String              aTempName;
    DateTime            nTime;
    sal_uInt16          nVisualDocumentNumber;
    sal_Int16           nDocumentSignatureState;
    sal_Int16           nScriptingSignatureState;
    sal_Bool            bTemplateConfig:1,
                        bInList:1,          // ob per First/Next erreichbar
                        bClosing:1,         // sal_True w"aehrend Close(), um Benachrichtigungs-Rekursionen zu verhindern
                        bSetInPlaceObj:1,   // sal_True, falls bereits versucht wurde pInPlaceObject zu casten
                        bIsSaving:1,
                        bPasswd:1,
                        bIsTmp:1,
                        bIsNamedVisible:1,
                        bIsTemplate:1,
                        bIsAbortingImport:1,  // Importvorgang soll abgebrochen werden.
                        bImportDone : 1, //Import schon fertig? Fuer AutoReload von Docs.
                        bInPrepareClose : 1,
                        bPreparedForClose : 1,
                        bWaitingForPicklist : 1,// Muss noch in die Pickliste
                        bModuleSearched : 1,
                        bIsBasicDefault : 1,
                        bIsHelpObjSh : 1,
                        bForbidCaching : 1,
                        bForbidReload : 1,
                        bSupportsEventMacros: 1,
                        bLoadingWindows: 1,
                        bBasicInitialized :1,
                        //bHidden :1, // indicates a hidden view shell
                        bIsPrintJobCancelable :1, // Stampit disable/enable cancel button for print jobs ... default = true = enable!
                        bOwnsStorage:1,
                        bNoBaseURL:1,
                        bInitialized:1,
                        bSignatureErrorIsShown:1,
                        bModelInitialized:1, // whether the related model is initialized
                        bPreserveVersions:1,
                        m_bMacroSignBroken:1, // whether the macro signature was explicitly broken
                        m_bNoBasicCapabilities:1,
                        bQueryLoadTemplate:1,
                        bLoadReadonly:1,
                        bUseUserData:1,
                        bSaveVersionOnClose:1;

    String              aNewName;  // Der Name, unter dem das Doc gespeichert
                                   // werden soll
    IndexBitSet         aBitSet;
    sal_uInt32               lErr;
    sal_uInt16              nEventId;           // falls vor Activate noch ein
                                            // Open/Create gesendet werden mu/s
    sal_Bool                bDoNotTouchDocInfo;

    AutoReloadTimer_Impl *pReloadTimer;
    MarkData_Impl*      pMarkData;
    sal_uInt16              nLoadedFlags;
    sal_uInt16              nFlagsInProgress;
    String              aMark;
    Size                aViewSize;          // wird leider vom Writer beim
    sal_Bool                bInFrame;           // HTML-Import gebraucht
    sal_Bool                bModalMode;
    sal_Bool                bRunningMacro;
    sal_Bool                bReloadAvailable;
    sal_uInt16              nAutoLoadLocks;
    SfxModule*              pModule;
    SfxFrame*               pFrame;
    SfxToolBoxConfig*       pTbxConfig;
    SfxEventConfigItem_Impl* pEventConfig;
    SfxObjectShellFlags     eFlags;
    svtools::AsynchronLink* pCloser;
    String                  aBaseURL;
    sal_Bool                bReadOnlyUI;
    SvRefBaseRef            xHeaderAttributes;
    sal_Bool                bHiddenLockedByAPI;
    sal_Bool                bInCloseEvent;
    ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > xModel;
    sal_uInt16              nStyleFilter;
    sal_Bool                bDisposing;

    sal_Bool                m_bEnableSetModified;
    sal_Bool                m_bIsModified;

    Rectangle               m_aVisArea;
    MapUnit                 m_nMapUnit;

    sal_Bool                m_bCreateTempStor;
    ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xDocStorage;

    ::com::sun::star::uno::Reference<
        ::com::sun::star::util::XModifyListener > m_xDocInfoListener;

    sal_Bool                m_bIsInit;

    SfxObjectShell_Impl( SfxObjectShell& _rDocShell );
    virtual ~SfxObjectShell_Impl();

    // IMacroDocumentAccess overridables
    virtual sal_Int16 getImposedMacroExecMode() const;
    virtual sal_Bool setImposedMacroExecMode( sal_uInt16 nMacroMode );
    virtual ::rtl::OUString getDocumentLocation() const;
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > getLastCommitDocumentStorage();
    virtual sal_Bool documentStorageHasMacros() const;
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts > getEmbeddedDocumentScripts() const;
    virtual sal_Int16 getScriptingSignatureState() const;
    virtual void showBrokenSignatureWarning( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _rxInteraction ) const;
};

#endif

<commit_msg>INTEGRATION: CWS odbmacros2 (1.39.2); FILE MERGED 2008/03/04 12:12:04 fs 1.39.2.3: RESYNC: (1.40-1.41); FILE MERGED 2008/02/04 13:15:52 fs 1.39.2.2: RESYNC: (1.39-1.40); FILE MERGED 2007/12/12 14:43:12 fs 1.39.2.1: bIsBasicDefault is not used<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: objshimp.hxx,v $
 *
 *  $Revision: 1.42 $
 *
 *  last change: $Author: kz $ $Date: 2008-03-06 19:57:35 $
 *
 *  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 _SFX_OBJSHIMP_HXX
#define _SFX_OBJSHIMP_HXX

//#include <hash_map>

#ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
#include <com/sun/star/frame/XModel.hpp>
#endif
#ifndef _DATETIME_HXX
#include <tools/datetime.hxx>
#endif

#include <svtools/securityoptions.hxx>
#include <sfx2/objsh.hxx>
#include "sfx2/docmacromode.hxx"
#include "bitset.hxx"

namespace svtools { class AsynchronLink; }

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

DBG_NAMEEX(SfxObjectShell)

class SfxViewFrame;
struct MarkData_Impl
{
    String aMark;
    String aUserData;
    SfxViewFrame* pFrame;
};

class SfxFrame;
class SfxToolBoxConfig;
class SfxAcceleratorManager;
class SfxBasicManagerHolder;

struct SfxObjectShell_Impl : public ::sfx2::IMacroDocumentAccess
{
    ::comphelper::EmbeddedObjectContainer* mpObjectContainer;
    SfxAcceleratorManager*  pAccMgr;
    SfxConfigManager*   pCfgMgr;
    SfxBasicManagerHolder*
                        pBasicManager;
    SfxObjectShell&     rDocShell;
    ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >
                        xBasicLibraries;
    ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >
                        xDialogLibraries;
    ::sfx2::DocumentMacroMode
                        aMacroMode;
    SfxProgress*        pProgress;
    String              aTitle;
    String              aTempName;
    DateTime            nTime;
    sal_uInt16          nVisualDocumentNumber;
    sal_Int16           nDocumentSignatureState;
    sal_Int16           nScriptingSignatureState;
    sal_Bool            bTemplateConfig:1,
                        bInList:1,          // ob per First/Next erreichbar
                        bClosing:1,         // sal_True w"aehrend Close(), um Benachrichtigungs-Rekursionen zu verhindern
                        bSetInPlaceObj:1,   // sal_True, falls bereits versucht wurde pInPlaceObject zu casten
                        bIsSaving:1,
                        bPasswd:1,
                        bIsTmp:1,
                        bIsNamedVisible:1,
                        bIsTemplate:1,
                        bIsAbortingImport:1,  // Importvorgang soll abgebrochen werden.
                        bImportDone : 1, //Import schon fertig? Fuer AutoReload von Docs.
                        bInPrepareClose : 1,
                        bPreparedForClose : 1,
                        bWaitingForPicklist : 1,// Muss noch in die Pickliste
                        bModuleSearched : 1,
                        bIsHelpObjSh : 1,
                        bForbidCaching : 1,
                        bForbidReload : 1,
                        bSupportsEventMacros: 1,
                        bLoadingWindows: 1,
                        bBasicInitialized :1,
                        //bHidden :1, // indicates a hidden view shell
                        bIsPrintJobCancelable :1, // Stampit disable/enable cancel button for print jobs ... default = true = enable!
                        bOwnsStorage:1,
                        bNoBaseURL:1,
                        bInitialized:1,
                        bSignatureErrorIsShown:1,
                        bModelInitialized:1, // whether the related model is initialized
                        bPreserveVersions:1,
                        m_bMacroSignBroken:1, // whether the macro signature was explicitly broken
                        m_bNoBasicCapabilities:1,
                        bQueryLoadTemplate:1,
                        bLoadReadonly:1,
                        bUseUserData:1,
                        bSaveVersionOnClose:1;

    String              aNewName;  // Der Name, unter dem das Doc gespeichert
                                   // werden soll
    IndexBitSet         aBitSet;
    sal_uInt32               lErr;
    sal_uInt16              nEventId;           // falls vor Activate noch ein
                                            // Open/Create gesendet werden mu/s
    sal_Bool                bDoNotTouchDocInfo;

    AutoReloadTimer_Impl *pReloadTimer;
    MarkData_Impl*      pMarkData;
    sal_uInt16              nLoadedFlags;
    sal_uInt16              nFlagsInProgress;
    String              aMark;
    Size                aViewSize;          // wird leider vom Writer beim
    sal_Bool                bInFrame;           // HTML-Import gebraucht
    sal_Bool                bModalMode;
    sal_Bool                bRunningMacro;
    sal_Bool                bReloadAvailable;
    sal_uInt16              nAutoLoadLocks;
    SfxModule*              pModule;
    SfxFrame*               pFrame;
    SfxToolBoxConfig*       pTbxConfig;
    SfxEventConfigItem_Impl* pEventConfig;
    SfxObjectShellFlags     eFlags;
    svtools::AsynchronLink* pCloser;
    String                  aBaseURL;
    sal_Bool                bReadOnlyUI;
    SvRefBaseRef            xHeaderAttributes;
    sal_Bool                bHiddenLockedByAPI;
    sal_Bool                bInCloseEvent;
    ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > xModel;
    sal_uInt16              nStyleFilter;
    sal_Bool                bDisposing;

    sal_Bool                m_bEnableSetModified;
    sal_Bool                m_bIsModified;

    Rectangle               m_aVisArea;
    MapUnit                 m_nMapUnit;

    sal_Bool                m_bCreateTempStor;
    ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xDocStorage;

    ::com::sun::star::uno::Reference<
        ::com::sun::star::util::XModifyListener > m_xDocInfoListener;

    sal_Bool                m_bIsInit;

    SfxObjectShell_Impl( SfxObjectShell& _rDocShell );
    virtual ~SfxObjectShell_Impl();

    // IMacroDocumentAccess overridables
    virtual sal_Int16 getImposedMacroExecMode() const;
    virtual sal_Bool setImposedMacroExecMode( sal_uInt16 nMacroMode );
    virtual ::rtl::OUString getDocumentLocation() const;
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > getLastCommitDocumentStorage();
    virtual sal_Bool documentStorageHasMacros() const;
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts > getEmbeddedDocumentScripts() const;
    virtual sal_Int16 getScriptingSignatureState() const;
    virtual void showBrokenSignatureWarning( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _rxInteraction ) const;
};

#endif

<|endoftext|>


<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/
#ifndef _SFX_TEMPDLGI_HXX
#define _SFX_TEMPDLGI_HXX

class SfxTemplateControllerItem;

#include <vcl/button.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/lstbox.hxx>
#include <svl/lstner.hxx>
#include <svtools/svtreebx.hxx>
#include <svl/eitem.hxx>

#define _SVSTDARR_USHORTS
#include <svl/svstdarr.hxx>     // SvUShorts

#include <rsc/rscsfx.hxx>
#include <tools/rtti.hxx>

#include <sfx2/childwin.hxx>
#include <sfx2/templdlg.hxx>

class SfxStyleFamilies;
class SfxStyleFamilyItem;
class SfxTemplateItem;
class SfxBindings;
class SfxStyleSheetBasePool;
class SvTreeListBox ;
class StyleTreeListBox_Impl;
class SfxTemplateDialog_Impl;
class SfxCommonTemplateDialog_Impl;
class SfxTemplateDialogWrapper;
class SfxDockingWindow;

namespace com { namespace sun { namespace star { namespace frame { class XModuleManager; } } } }

// class DropListBox_Impl ------------------------------------------------

class DropListBox_Impl : public SvTreeListBox
{
private:
    DECL_LINK( OnAsyncExecuteDrop, SvLBoxEntry* );
    DECL_LINK( OnAsyncExecuteError, void* );

protected:
    SfxCommonTemplateDialog_Impl* pDialog;
    USHORT                        nModifier;

public:
    DropListBox_Impl( Window* pParent, const ResId& rId, SfxCommonTemplateDialog_Impl* pD ) :
        SvTreeListBox( pParent, rId ), pDialog( pD ) {}
    DropListBox_Impl( Window* pParent, WinBits nWinBits, SfxCommonTemplateDialog_Impl* pD ) :
        SvTreeListBox( pParent, nWinBits ), pDialog( pD ) {}

    virtual void     MouseButtonDown( const MouseEvent& rMEvt );
    virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt );
    using SvLBox::ExecuteDrop;
    virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt );

    USHORT           GetModifier() const { return nModifier; }

    virtual long     Notify( NotifyEvent& rNEvt );
};

// class SfxActionListBox ------------------------------------------------

class SfxActionListBox : public DropListBox_Impl
{
protected:
public:
    SfxActionListBox( SfxCommonTemplateDialog_Impl* pParent, WinBits nWinBits );
    SfxActionListBox( SfxCommonTemplateDialog_Impl* pParent, const ResId &rResId );

    virtual PopupMenu*  CreateContextMenu( void );
};

// class SfxCommonTemplateDialog_Impl ------------------------------------

struct Deleted
{
    bool bDead;

    Deleted() : bDead(false) {}

    inline bool operator()() { return bDead; }
};

class SfxCommonTemplateDialog_Impl : public SfxListener
{
private:
    class ISfxTemplateCommon_Impl : public ISfxTemplateCommon
    {
    private:
        SfxCommonTemplateDialog_Impl* pDialog;
    public:
        ISfxTemplateCommon_Impl( SfxCommonTemplateDialog_Impl* pDialogP ) : pDialog( pDialogP ) {}
        virtual SfxStyleFamily GetActualFamily() const { return pDialog->GetActualFamily(); }
        virtual String GetSelectedEntry() const { return pDialog->GetSelectedEntry(); }
    };

    ISfxTemplateCommon_Impl     aISfxTemplateCommon;

    void    ReadResource();
    void    ClearResource();

protected:
#define MAX_FAMILIES            5
#define COUNT_BOUND_FUNC        13

#define UPDATE_FAMILY_LIST      0x0001
#define UPDATE_FAMILY           0x0002

    friend class DropListBox_Impl;
    friend class SfxTemplateControllerItem;
    friend class SfxTemplateDialogWrapper;

    SfxBindings*                pBindings;
    SfxTemplateControllerItem*  pBoundItems[COUNT_BOUND_FUNC];

    Window*                     pWindow;
    SfxModule*                  pModule;
    Timer*                      pTimer;

    ResId*                      m_pStyleFamiliesId;
    SfxStyleFamilies*           pStyleFamilies;
    SfxTemplateItem*            pFamilyState[MAX_FAMILIES];
    SfxStyleSheetBasePool*      pStyleSheetPool;
    SvTreeListBox*              pTreeBox;
    SfxObjectShell*             pCurObjShell;
    ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager >
                                xModuleManager;
    Deleted*                    pbDeleted;

    SfxActionListBox            aFmtLb;
    ListBox                     aFilterLb;
    Size                        aSize;

    USHORT                      nActFamily;     // Id in the ToolBox = Position - 1
    USHORT                      nActFilter; // FilterIdx
    USHORT                      nAppFilter;     // Filter, which has set the application (for automatic)

    BOOL                        bDontUpdate             :1,
                                bIsWater                :1,
                                bEnabled                :1,
                                bUpdate                 :1,
                                bUpdateFamily           :1,
                                bCanEdit                :1,
                                bCanDel                 :1,
                                bCanNew                 :1,
                                bWaterDisabled          :1,
                                bNewByExampleDisab§led   :1,
                                bUpdateByExampleDisabled:1,
                                bTreeDrag               :1,
                                bHierarchical           :1,
                                bBindingUpdate          :1;

    DECL_LINK( FilterSelectHdl, ListBox * );
    DECL_LINK( FmtSelectHdl, SvTreeListBox * );
    DECL_LINK( ApplyHdl, Control * );
    DECL_LINK( DropHdl, StyleTreeListBox_Impl * );
    DECL_LINK( TimeOut, Timer * );

    virtual void        EnableItem( USHORT /*nMesId*/, BOOL /*bCheck*/ = TRUE ) {}
    virtual void        CheckItem( USHORT /*nMesId*/, BOOL /*bCheck*/ = TRUE ) {}
    virtual BOOL        IsCheckedItem( USHORT /*nMesId*/ ) { return TRUE; }
    virtual void        LoadedFamilies() {}
    virtual void        Update() { UpdateStyles_Impl(UPDATE_FAMILY_LIST); }
    virtual void        InvalidateBindings();
    virtual void        InsertFamilyItem( USHORT nId, const SfxStyleFamilyItem* pIten ) = 0;
    virtual void        EnableFamilyItem( USHORT nId, BOOL bEnabled = TRUE ) = 0;
    virtual void        ClearFamilyList() = 0;
    virtual void        ReplaceUpdateButtonByMenu();

        void                NewHdl( void* );
    void                EditHdl( void* );
    void                DeleteHdl( void* );

    BOOL                Execute_Impl( USHORT nId, const String& rStr, const String& rRefStr,
                                      USHORT nFamily, USHORT nMask = 0,
                                      USHORT* pIdx = NULL, const USHORT* pModifier = NULL );

    void                        UpdateStyles_Impl(USHORT nFlags);
    const SfxStyleFamilyItem*   GetFamilyItem_Impl() const;
    BOOL                        IsInitialized() { return nActFamily != 0xffff; }
    void                        ResetFocus();
    void                        EnableDelete();
    void                        Initialize();

    void                FilterSelect( USHORT nFilterIdx, BOOL bForce = FALSE );
    void                SetFamilyState( USHORT nSlotId, const SfxTemplateItem* );
    void                SetWaterCanState( const SfxBoolItem* pItem );

    void                SelectStyle( const String& rStyle );
    BOOL                HasSelectedStyle() const;
    void                FillTreeBox();
    void                Update_Impl();
    void                UpdateFamily_Impl();

    // In which FamilyState do I have to look , in order to get the
    // information of the ith Family in the pStyleFamilies.
    USHORT              StyleNrToInfoOffset( USHORT i );
    USHORT              InfoOffsetToStyleNr( USHORT i );

    void                Notify( SfxBroadcaster& rBC, const SfxHint& rHint );

    void                FamilySelect( USHORT nId );
    void                SetFamily( USHORT nId );
    void                ActionSelect( USHORT nId );

    sal_Int32           LoadFactoryStyleFilter( SfxObjectShell* i_pObjSh );
    void                SaveFactoryStyleFilter( SfxObjectShell* i_pObjSh, sal_Int32 i_nFilter );

public:
    TYPEINFO();

    SfxCommonTemplateDialog_Impl( SfxBindings* pB, SfxDockingWindow* );
    SfxCommonTemplateDialog_Impl( SfxBindings* pB, ModalDialog* );
    ~SfxCommonTemplateDialog_Impl();

    DECL_LINK( MenuSelectHdl, Menu * );

    virtual void        EnableEdit( BOOL b = TRUE ) { bCanEdit = b; }
    virtual void        EnableDel( BOOL b = TRUE )  { bCanDel = b; }
    virtual void        EnableNew( BOOL b = TRUE )  { bCanNew = b; }

    ISfxTemplateCommon* GetISfxTemplateCommon() { return &aISfxTemplateCommon; }
    Window*             GetWindow() { return pWindow; }

    void                EnableTreeDrag( BOOL b = TRUE );
    void                ExecuteContextMenu_Impl( const Point& rPos, Window* pWin );
    void                EnableExample_Impl( USHORT nId, BOOL bEnable );
    SfxStyleFamily      GetActualFamily() const;
    String              GetSelectedEntry() const;
    SfxObjectShell*     GetObjectShell() const { return pCurObjShell; }

    virtual void        PrepareDeleteAction();  // disable buttons, change button text, etc. when del is going to happen

    inline BOOL         CanEdit( void ) const   { return bCanEdit; }
    inline BOOL         CanDel( void ) const    { return bCanDel; }
    inline BOOL         CanNew( void ) const    { return bCanNew; }

    // normaly for derivates from SvTreeListBoxes, but in this case the dialog handles context menus
    virtual PopupMenu*  CreateContextMenu( void );

    // converts from SFX_STYLE_FAMILY Ids to 1-5
    static USHORT       SfxFamilyIdToNId( SfxStyleFamily nFamily );

    void                SetAutomaticFilter();
};

class DropToolBox_Impl : public ToolBox, public DropTargetHelper
{
    SfxTemplateDialog_Impl&     rParent;
protected:
    virtual sal_Int8    AcceptDrop( const AcceptDropEvent& rEvt );
    virtual sal_Int8    ExecuteDrop( const ExecuteDropEvent& rEvt );
public:
    DropToolBox_Impl(Window* pParent, SfxTemplateDialog_Impl* pTemplateDialog);
    ~DropToolBox_Impl();
};
// class SfxTemplateDialog_Impl ------------------------------------------

class SfxTemplateDialog_Impl :  public SfxCommonTemplateDialog_Impl
{
private:
    friend class SfxTemplateControllerItem;
    friend class SfxTemplateDialogWrapper;
    friend class DropToolBox_Impl;

    SfxTemplateDialog*  m_pFloat;
    BOOL                m_bZoomIn;
    DropToolBox_Impl    m_aActionTbL;
    ToolBox             m_aActionTbR;

    DECL_LINK( ToolBoxLSelect, ToolBox * );
    DECL_LINK( ToolBoxRSelect, ToolBox * );
    DECL_LINK( ToolBoxRClick, ToolBox * );
    DECL_LINK( MenuSelectHdl, Menu* );

protected:
    virtual void    Command( const CommandEvent& rMEvt );
    virtual void    EnableEdit( BOOL = TRUE );
    virtual void    EnableItem( USHORT nMesId, BOOL bCheck = TRUE );
    virtual void    CheckItem( USHORT nMesId, BOOL bCheck = TRUE );
    virtual BOOL    IsCheckedItem( USHORT nMesId );
    virtual void    LoadedFamilies();
    virtual void    InsertFamilyItem( USHORT nId, const SfxStyleFamilyItem* pIten );
    virtual void    EnableFamilyItem( USHORT nId, BOOL bEnabled = TRUE );
    virtual void    ClearFamilyList();
    virtual void    ReplaceUpdateButtonByMenu();

    void            Resize();
    Size            GetMinOutputSizePixel();

    void            updateFamilyImages();
    void            updateNonFamilyImages();

public:
    friend class SfxTemplateDialog;
    TYPEINFO();

    SfxTemplateDialog_Impl( Window* pParent, SfxBindings*, SfxTemplateDialog* pWindow );
    ~SfxTemplateDialog_Impl();
};

// class SfxTemplateCatalog_Impl -----------------------------------------

class SfxTemplateCatalog_Impl : public SfxCommonTemplateDialog_Impl
{
private:
    friend class SfxTemplateControllerItem;
    friend class SfxCommonTemplateDialog_Impl;

    ListBox                 aFamList;
    OKButton                aOkBtn;
    CancelButton            aCancelBtn;
    PushButton              aNewBtn;
    PushButton              aChangeBtn;
    PushButton              aDelBtn;
    PushButton              aOrgBtn;
    HelpButton              aHelpBtn;

    SfxTemplateCatalog*     pReal;
    SvUShorts               aFamIds;
    SfxModalDefParentHelper aHelper;

protected:
    virtual void    EnableItem( USHORT nMesId, BOOL bCheck = TRUE );
    virtual void    CheckItem( USHORT nMesId, BOOL bCheck = TRUE );
    virtual BOOL    IsCheckedItem( USHORT nMesId );
    virtual void    InsertFamilyItem( USHORT nId, const SfxStyleFamilyItem* pIten );
    virtual void    EnableFamilyItem( USHORT nId, BOOL bEnabled = TRUE );
    virtual void    ClearFamilyList();
    virtual void    EnableEdit( BOOL = TRUE );
    virtual void    EnableDel( BOOL = TRUE );
    virtual void    EnableNew( BOOL = TRUE );

        using SfxCommonTemplateDialog_Impl::NewHdl;
    DECL_LINK( FamListSelect, ListBox * );
    DECL_LINK( OkHdl, Button * );
    DECL_LINK( CancelHdl, Button * );
    DECL_LINK( NewHdl, Button * );
    DECL_LINK( ChangeHdl, Button * );
    DECL_LINK( DelHdl, Button * );
    DECL_LINK( OrgHdl, Button * );

public:
    TYPEINFO();
    SfxTemplateCatalog_Impl( Window* pParent, SfxBindings*, SfxTemplateCatalog* pWindow );
    ~SfxTemplateCatalog_Impl();

friend class SfxTemplateCatalog;

    virtual void    PrepareDeleteAction();
};

#endif // #ifndef _SFX_TEMPDLGI_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>random character added by translation<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/
#ifndef _SFX_TEMPDLGI_HXX
#define _SFX_TEMPDLGI_HXX

class SfxTemplateControllerItem;

#include <vcl/button.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/lstbox.hxx>
#include <svl/lstner.hxx>
#include <svtools/svtreebx.hxx>
#include <svl/eitem.hxx>

#define _SVSTDARR_USHORTS
#include <svl/svstdarr.hxx>     // SvUShorts

#include <rsc/rscsfx.hxx>
#include <tools/rtti.hxx>

#include <sfx2/childwin.hxx>
#include <sfx2/templdlg.hxx>

class SfxStyleFamilies;
class SfxStyleFamilyItem;
class SfxTemplateItem;
class SfxBindings;
class SfxStyleSheetBasePool;
class SvTreeListBox ;
class StyleTreeListBox_Impl;
class SfxTemplateDialog_Impl;
class SfxCommonTemplateDialog_Impl;
class SfxTemplateDialogWrapper;
class SfxDockingWindow;

namespace com { namespace sun { namespace star { namespace frame { class XModuleManager; } } } }

// class DropListBox_Impl ------------------------------------------------

class DropListBox_Impl : public SvTreeListBox
{
private:
    DECL_LINK( OnAsyncExecuteDrop, SvLBoxEntry* );
    DECL_LINK( OnAsyncExecuteError, void* );

protected:
    SfxCommonTemplateDialog_Impl* pDialog;
    USHORT                        nModifier;

public:
    DropListBox_Impl( Window* pParent, const ResId& rId, SfxCommonTemplateDialog_Impl* pD ) :
        SvTreeListBox( pParent, rId ), pDialog( pD ) {}
    DropListBox_Impl( Window* pParent, WinBits nWinBits, SfxCommonTemplateDialog_Impl* pD ) :
        SvTreeListBox( pParent, nWinBits ), pDialog( pD ) {}

    virtual void     MouseButtonDown( const MouseEvent& rMEvt );
    virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt );
    using SvLBox::ExecuteDrop;
    virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt );

    USHORT           GetModifier() const { return nModifier; }

    virtual long     Notify( NotifyEvent& rNEvt );
};

// class SfxActionListBox ------------------------------------------------

class SfxActionListBox : public DropListBox_Impl
{
protected:
public:
    SfxActionListBox( SfxCommonTemplateDialog_Impl* pParent, WinBits nWinBits );
    SfxActionListBox( SfxCommonTemplateDialog_Impl* pParent, const ResId &rResId );

    virtual PopupMenu*  CreateContextMenu( void );
};

// class SfxCommonTemplateDialog_Impl ------------------------------------

struct Deleted
{
    bool bDead;

    Deleted() : bDead(false) {}

    inline bool operator()() { return bDead; }
};

class SfxCommonTemplateDialog_Impl : public SfxListener
{
private:
    class ISfxTemplateCommon_Impl : public ISfxTemplateCommon
    {
    private:
        SfxCommonTemplateDialog_Impl* pDialog;
    public:
        ISfxTemplateCommon_Impl( SfxCommonTemplateDialog_Impl* pDialogP ) : pDialog( pDialogP ) {}
        virtual SfxStyleFamily GetActualFamily() const { return pDialog->GetActualFamily(); }
        virtual String GetSelectedEntry() const { return pDialog->GetSelectedEntry(); }
    };

    ISfxTemplateCommon_Impl     aISfxTemplateCommon;

    void    ReadResource();
    void    ClearResource();

protected:
#define MAX_FAMILIES            5
#define COUNT_BOUND_FUNC        13

#define UPDATE_FAMILY_LIST      0x0001
#define UPDATE_FAMILY           0x0002

    friend class DropListBox_Impl;
    friend class SfxTemplateControllerItem;
    friend class SfxTemplateDialogWrapper;

    SfxBindings*                pBindings;
    SfxTemplateControllerItem*  pBoundItems[COUNT_BOUND_FUNC];

    Window*                     pWindow;
    SfxModule*                  pModule;
    Timer*                      pTimer;

    ResId*                      m_pStyleFamiliesId;
    SfxStyleFamilies*           pStyleFamilies;
    SfxTemplateItem*            pFamilyState[MAX_FAMILIES];
    SfxStyleSheetBasePool*      pStyleSheetPool;
    SvTreeListBox*              pTreeBox;
    SfxObjectShell*             pCurObjShell;
    ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager >
                                xModuleManager;
    Deleted*                    pbDeleted;

    SfxActionListBox            aFmtLb;
    ListBox                     aFilterLb;
    Size                        aSize;

    USHORT                      nActFamily;     // Id in the ToolBox = Position - 1
    USHORT                      nActFilter; // FilterIdx
    USHORT                      nAppFilter;     // Filter, which has set the application (for automatic)

    BOOL                        bDontUpdate             :1,
                                bIsWater                :1,
                                bEnabled                :1,
                                bUpdate                 :1,
                                bUpdateFamily           :1,
                                bCanEdit                :1,
                                bCanDel                 :1,
                                bCanNew                 :1,
                                bWaterDisabled          :1,
                                bNewByExampleDisabled   :1,
                                bUpdateByExampleDisabled:1,
                                bTreeDrag               :1,
                                bHierarchical           :1,
                                bBindingUpdate          :1;

    DECL_LINK( FilterSelectHdl, ListBox * );
    DECL_LINK( FmtSelectHdl, SvTreeListBox * );
    DECL_LINK( ApplyHdl, Control * );
    DECL_LINK( DropHdl, StyleTreeListBox_Impl * );
    DECL_LINK( TimeOut, Timer * );

    virtual void        EnableItem( USHORT /*nMesId*/, BOOL /*bCheck*/ = TRUE ) {}
    virtual void        CheckItem( USHORT /*nMesId*/, BOOL /*bCheck*/ = TRUE ) {}
    virtual BOOL        IsCheckedItem( USHORT /*nMesId*/ ) { return TRUE; }
    virtual void        LoadedFamilies() {}
    virtual void        Update() { UpdateStyles_Impl(UPDATE_FAMILY_LIST); }
    virtual void        InvalidateBindings();
    virtual void        InsertFamilyItem( USHORT nId, const SfxStyleFamilyItem* pIten ) = 0;
    virtual void        EnableFamilyItem( USHORT nId, BOOL bEnabled = TRUE ) = 0;
    virtual void        ClearFamilyList() = 0;
    virtual void        ReplaceUpdateButtonByMenu();

        void                NewHdl( void* );
    void                EditHdl( void* );
    void                DeleteHdl( void* );

    BOOL                Execute_Impl( USHORT nId, const String& rStr, const String& rRefStr,
                                      USHORT nFamily, USHORT nMask = 0,
                                      USHORT* pIdx = NULL, const USHORT* pModifier = NULL );

    void                        UpdateStyles_Impl(USHORT nFlags);
    const SfxStyleFamilyItem*   GetFamilyItem_Impl() const;
    BOOL                        IsInitialized() { return nActFamily != 0xffff; }
    void                        ResetFocus();
    void                        EnableDelete();
    void                        Initialize();

    void                FilterSelect( USHORT nFilterIdx, BOOL bForce = FALSE );
    void                SetFamilyState( USHORT nSlotId, const SfxTemplateItem* );
    void                SetWaterCanState( const SfxBoolItem* pItem );

    void                SelectStyle( const String& rStyle );
    BOOL                HasSelectedStyle() const;
    void                FillTreeBox();
    void                Update_Impl();
    void                UpdateFamily_Impl();

    // In which FamilyState do I have to look , in order to get the
    // information of the ith Family in the pStyleFamilies.
    USHORT              StyleNrToInfoOffset( USHORT i );
    USHORT              InfoOffsetToStyleNr( USHORT i );

    void                Notify( SfxBroadcaster& rBC, const SfxHint& rHint );

    void                FamilySelect( USHORT nId );
    void                SetFamily( USHORT nId );
    void                ActionSelect( USHORT nId );

    sal_Int32           LoadFactoryStyleFilter( SfxObjectShell* i_pObjSh );
    void                SaveFactoryStyleFilter( SfxObjectShell* i_pObjSh, sal_Int32 i_nFilter );

public:
    TYPEINFO();

    SfxCommonTemplateDialog_Impl( SfxBindings* pB, SfxDockingWindow* );
    SfxCommonTemplateDialog_Impl( SfxBindings* pB, ModalDialog* );
    ~SfxCommonTemplateDialog_Impl();

    DECL_LINK( MenuSelectHdl, Menu * );

    virtual void        EnableEdit( BOOL b = TRUE ) { bCanEdit = b; }
    virtual void        EnableDel( BOOL b = TRUE )  { bCanDel = b; }
    virtual void        EnableNew( BOOL b = TRUE )  { bCanNew = b; }

    ISfxTemplateCommon* GetISfxTemplateCommon() { return &aISfxTemplateCommon; }
    Window*             GetWindow() { return pWindow; }

    void                EnableTreeDrag( BOOL b = TRUE );
    void                ExecuteContextMenu_Impl( const Point& rPos, Window* pWin );
    void                EnableExample_Impl( USHORT nId, BOOL bEnable );
    SfxStyleFamily      GetActualFamily() const;
    String              GetSelectedEntry() const;
    SfxObjectShell*     GetObjectShell() const { return pCurObjShell; }

    virtual void        PrepareDeleteAction();  // disable buttons, change button text, etc. when del is going to happen

    inline BOOL         CanEdit( void ) const   { return bCanEdit; }
    inline BOOL         CanDel( void ) const    { return bCanDel; }
    inline BOOL         CanNew( void ) const    { return bCanNew; }

    // normaly for derivates from SvTreeListBoxes, but in this case the dialog handles context menus
    virtual PopupMenu*  CreateContextMenu( void );

    // converts from SFX_STYLE_FAMILY Ids to 1-5
    static USHORT       SfxFamilyIdToNId( SfxStyleFamily nFamily );

    void                SetAutomaticFilter();
};

class DropToolBox_Impl : public ToolBox, public DropTargetHelper
{
    SfxTemplateDialog_Impl&     rParent;
protected:
    virtual sal_Int8    AcceptDrop( const AcceptDropEvent& rEvt );
    virtual sal_Int8    ExecuteDrop( const ExecuteDropEvent& rEvt );
public:
    DropToolBox_Impl(Window* pParent, SfxTemplateDialog_Impl* pTemplateDialog);
    ~DropToolBox_Impl();
};
// class SfxTemplateDialog_Impl ------------------------------------------

class SfxTemplateDialog_Impl :  public SfxCommonTemplateDialog_Impl
{
private:
    friend class SfxTemplateControllerItem;
    friend class SfxTemplateDialogWrapper;
    friend class DropToolBox_Impl;

    SfxTemplateDialog*  m_pFloat;
    BOOL                m_bZoomIn;
    DropToolBox_Impl    m_aActionTbL;
    ToolBox             m_aActionTbR;

    DECL_LINK( ToolBoxLSelect, ToolBox * );
    DECL_LINK( ToolBoxRSelect, ToolBox * );
    DECL_LINK( ToolBoxRClick, ToolBox * );
    DECL_LINK( MenuSelectHdl, Menu* );

protected:
    virtual void    Command( const CommandEvent& rMEvt );
    virtual void    EnableEdit( BOOL = TRUE );
    virtual void    EnableItem( USHORT nMesId, BOOL bCheck = TRUE );
    virtual void    CheckItem( USHORT nMesId, BOOL bCheck = TRUE );
    virtual BOOL    IsCheckedItem( USHORT nMesId );
    virtual void    LoadedFamilies();
    virtual void    InsertFamilyItem( USHORT nId, const SfxStyleFamilyItem* pIten );
    virtual void    EnableFamilyItem( USHORT nId, BOOL bEnabled = TRUE );
    virtual void    ClearFamilyList();
    virtual void    ReplaceUpdateButtonByMenu();

    void            Resize();
    Size            GetMinOutputSizePixel();

    void            updateFamilyImages();
    void            updateNonFamilyImages();

public:
    friend class SfxTemplateDialog;
    TYPEINFO();

    SfxTemplateDialog_Impl( Window* pParent, SfxBindings*, SfxTemplateDialog* pWindow );
    ~SfxTemplateDialog_Impl();
};

// class SfxTemplateCatalog_Impl -----------------------------------------

class SfxTemplateCatalog_Impl : public SfxCommonTemplateDialog_Impl
{
private:
    friend class SfxTemplateControllerItem;
    friend class SfxCommonTemplateDialog_Impl;

    ListBox                 aFamList;
    OKButton                aOkBtn;
    CancelButton            aCancelBtn;
    PushButton              aNewBtn;
    PushButton              aChangeBtn;
    PushButton              aDelBtn;
    PushButton              aOrgBtn;
    HelpButton              aHelpBtn;

    SfxTemplateCatalog*     pReal;
    SvUShorts               aFamIds;
    SfxModalDefParentHelper aHelper;

protected:
    virtual void    EnableItem( USHORT nMesId, BOOL bCheck = TRUE );
    virtual void    CheckItem( USHORT nMesId, BOOL bCheck = TRUE );
    virtual BOOL    IsCheckedItem( USHORT nMesId );
    virtual void    InsertFamilyItem( USHORT nId, const SfxStyleFamilyItem* pIten );
    virtual void    EnableFamilyItem( USHORT nId, BOOL bEnabled = TRUE );
    virtual void    ClearFamilyList();
    virtual void    EnableEdit( BOOL = TRUE );
    virtual void    EnableDel( BOOL = TRUE );
    virtual void    EnableNew( BOOL = TRUE );

        using SfxCommonTemplateDialog_Impl::NewHdl;
    DECL_LINK( FamListSelect, ListBox * );
    DECL_LINK( OkHdl, Button * );
    DECL_LINK( CancelHdl, Button * );
    DECL_LINK( NewHdl, Button * );
    DECL_LINK( ChangeHdl, Button * );
    DECL_LINK( DelHdl, Button * );
    DECL_LINK( OrgHdl, Button * );

public:
    TYPEINFO();
    SfxTemplateCatalog_Impl( Window* pParent, SfxBindings*, SfxTemplateCatalog* pWindow );
    ~SfxTemplateCatalog_Impl();

friend class SfxTemplateCatalog;

    virtual void    PrepareDeleteAction();
};

#endif // #ifndef _SFX_TEMPDLGI_HXX

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


<commit_before>#include "tizen_utils.hpp"
#include "../../std/vector.hpp"

#include "../../tizen/inc/FBase.hpp"
#include "../base/logging.hpp"
#include <FSystem.h>

string FromTizenString(Tizen::Base::String const & str_tizen)
{
  string utf8Str;
  if (str_tizen.GetLength() == 0)
    return utf8Str;
  Tizen::Base::ByteBuffer * pBuffer = Tizen::Base::Utility::StringUtil::StringToUtf8N(str_tizen);
  if (pBuffer)
  {
    int byteCount = pBuffer->GetLimit();

    byteCount--; // Don't copy Zero at the end
    if (byteCount > 0)
    {
      vector<char> chBuf(byteCount);
      pBuffer->GetArray((byte *)&chBuf[0], 0, byteCount);
      utf8Str.assign(chBuf.begin(), chBuf.end());
    }
    delete pBuffer;
  }
  return utf8Str;
}

string GetTizenLocale()
{
  Tizen::Base::String languageCode;
  Tizen::System::SettingInfo::GetValue(L"http://tizen.org/setting/locale.language", languageCode);
  Tizen::Base::String languageCode_truncated;
  languageCode.SubString(0, 3, languageCode_truncated);
  return CodeFromISO369_2to_1(FromTizenString(languageCode_truncated));
}

string CodeFromISO369_2to_1(string const & code_ISO_639_2)
{
  static const string ar [] =
  {
    "aar",	"aa",
    "abk",	"ab",
    "afr",	"af",
    "aka",	"ak",
    "sqi",	"sq",
    "amh",	"am",
    "ara",	"ar",
    "arg",	"an",
    "hye",	"hy",
    "asm",	"as",
    "ava",	"av",
    "ave",	"ae",
    "aym",	"ay",
    "aze",	"az",
    "bak",	"ba",
    "bam",	"bm",
    "eus",	"eu",
    "bel",	"be",
    "ben",	"bn",
    "bih",	"bh",
    "bis",	"bi",
    "bod",	"bo",
    "bos",	"bs",
    "bre",	"br",
    "bul",	"bg",
    "mya",	"my",
    "cat",	"ca",
    "ces",	"cs",
    "cha",	"ch",
    "che",	"ce",
    "zho",	"zh",
    "chu",	"cu",
    "chv",	"cv",
    "cor",	"kw",
    "cos",	"co",
    "cre",	"cr",
    "cym",	"cy",
    "ces",	"cs",
    "dan",	"da",
    "deu",	"de",
    "div",	"dv",
    "nld",	"nl",
    "dzo",	"dz",
    "ell",	"el",
    "eng",	"en",
    "epo",	"eo",
    "est",	"et",
    "eus",	"eu",
    "ewe",	"ee",
    "fao",	"fo",
    "fas",	"fa",
    "fij",	"fj",
    "fin",	"fi",
    "fra",	"fr",
    "fra",	"fr",
    "fry",	"fy",
    "ful",	"ff",
    "kat",	"ka",
    "deu",	"de",
    "gla",	"gd",
    "gle",	"ga",
    "glg",	"gl",
    "glv",	"gv",
    "ell",	"el",
    "grn",	"gn",
    "guj",	"gu",
    "hat",	"ht",
    "hau",	"ha",
    "heb",	"he",
    "her",	"hz",
    "hin",	"hi",
    "hmo",	"ho",
    "hrv",	"hr",
    "hun",	"hu",
    "hye",	"hy",
    "ibo",	"ig",
    "ice",	"is",
    "ido",	"io",
    "iii",	"ii",
    "iku",	"iu",
    "ile",	"ie",
    "ina",	"ia",
    "ind",	"id",
    "ipk",	"ik",
    "isl",	"is",
    "ita",	"it",
    "jav",	"jv",
    "jpn",	"ja",
    "kal",	"kl",
    "kan",	"kn",
    "kas",	"ks",
    "kat",	"ka",
    "kau",	"kr",
    "kaz",	"kk",
    "khm",	"km",
    "kik",	"ki",
    "kin",	"rw",
    "kir",	"ky",
    "kom",	"kv",
    "kon",	"kg",
    "kor",	"ko",
    "kua",	"kj",
    "kur",	"ku",
    "lao",	"lo",
    "lat",	"la",
    "lav",	"lv",
    "lim",	"li",
    "lin",	"ln",
    "lit",	"lt",
    "ltz",	"lb",
    "lub",	"lu",
    "lug",	"lg",
    "mkd",	"mk",
    "mah",	"mh",
    "mal",	"ml",
    "mri",	"mi",
    "mar",	"mr",
    "msa",	"ms",
    "mkd",	"mk",
    "mlg",	"mg",
    "mlt",	"mt",
    "mon",	"mn",
    "mri",	"mi",
    "msa",	"ms",
    "mya",	"my",
    "nau",	"na",
    "nav",	"nv",
    "nbl",	"nr",
    "nde",	"nd",
    "ndo",	"ng",
    "nep",	"ne",
    "nld",	"nl",
    "nno",	"nn",
    "nob",	"nb",
    "nor",	"no",
    "nya",	"ny",
    "oci",	"oc",
    "oji",	"oj",
    "ori",	"or",
    "orm",	"om",
    "oss",	"os",
    "pan",	"pa",
    "fas",	"fa",
    "pli",	"pi",
    "pol",	"pl",
    "por",	"pt",
    "pus",	"ps",
    "que",	"qu",
    "roh",	"rm",
    "ron",	"ro",
    "ron",	"ro",
    "run",	"rn",
    "rus",	"ru",
    "sag",	"sg",
    "san",	"sa",
    "sin",	"si",
    "slk",	"sk",
    "slk",	"sk",
    "slv",	"sl",
    "sme",	"se",
    "smo",	"sm",
    "sna",	"sn",
    "snd",	"sd",
    "som",	"so",
    "sot",	"st",
    "spa",	"es",
    "sqi",	"sq",
    "srd",	"sc",
    "srp",	"sr",
    "ssw",	"ss",
    "sun",	"su",
    "swa",	"sw",
    "swe",	"sv",
    "tah",	"ty",
    "tam",	"ta",
    "tat",	"tt",
    "tel",	"te",
    "tgk",	"tg",
    "tgl",	"tl",
    "tha",	"th",
    "bod",	"bo",
    "tir",	"ti",
    "ton",	"to",
    "tsn",	"tn",
    "tso",	"ts",
    "tuk",	"tk",
    "tur",	"tr",
    "twi",	"tw",
    "uig",	"ug",
    "ukr",	"uk",
    "urd",	"ur",
    "uzb",	"uz",
    "ven",	"ve",
    "vie",	"vi",
    "vol",	"vo",
    "cym",	"cy",
    "wln",	"wa",
    "wol",	"wo",
    "xho",	"xh",
    "yid",	"yi",
    "yor",	"yo",
    "zha",	"za",
    "zho",	"zh",
    "zul",	"zu"
  };
  for (size_t i = 0; i < sizeof(ar)/sizeof(ar[0]); i += 2)
    if (code_ISO_639_2 == ar[i])
    {
      return ar[i + 1];
    }
  LOG(LDEBUG, ("Language not found", code_ISO_639_2));
  return "en";
}
<commit_msg>[Tizen] review fix<commit_after>#include "tizen_utils.hpp"
#include "../../std/vector.hpp"

#include "../../tizen/inc/FBase.hpp"
#include "../base/logging.hpp"
#include <FSystem.h>

string FromTizenString(Tizen::Base::String const & str_tizen)
{
  string utf8Str;
  if (str_tizen.GetLength() == 0)
    return utf8Str;
  Tizen::Base::ByteBuffer * pBuffer = Tizen::Base::Utility::StringUtil::StringToUtf8N(str_tizen);
  if (pBuffer)
  {
    int byteCount = pBuffer->GetLimit();

    byteCount--; // Don't copy Zero at the end
    if (byteCount > 0)
    {
      vector<char> chBuf(byteCount);
      pBuffer->GetArray((byte *)&chBuf[0], 0, byteCount);
      utf8Str.assign(chBuf.begin(), chBuf.end());
    }
    delete pBuffer;
  }
  return utf8Str;
}

string GetTizenLocale()
{
  Tizen::Base::String languageCode;
  Tizen::System::SettingInfo::GetValue(L"http://tizen.org/setting/locale.language", languageCode);
  Tizen::Base::String languageCode_truncated;
  languageCode.SubString(0, 3, languageCode_truncated);
  return CodeFromISO369_2to_1(FromTizenString(languageCode_truncated));
}

string CodeFromISO369_2to_1(string const & code_ISO_639_2)
{
  static const string ar [] =
  {
    "aar",	"aa",
    "abk",	"ab",
    "afr",	"af",
    "aka",	"ak",
    "sqi",	"sq",
    "amh",	"am",
    "ara",	"ar",
    "arg",	"an",
    "hye",	"hy",
    "asm",	"as",
    "ava",	"av",
    "ave",	"ae",
    "aym",	"ay",
    "aze",	"az",
    "bak",	"ba",
    "bam",	"bm",
    "eus",	"eu",
    "bel",	"be",
    "ben",	"bn",
    "bih",	"bh",
    "bis",	"bi",
    "bod",	"bo",
    "bos",	"bs",
    "bre",	"br",
    "bul",	"bg",
    "mya",	"my",
    "cat",	"ca",
    "ces",	"cs",
    "cha",	"ch",
    "che",	"ce",
    "zho",	"zh",
    "chu",	"cu",
    "chv",	"cv",
    "cor",	"kw",
    "cos",	"co",
    "cre",	"cr",
    "cym",	"cy",
    "ces",	"cs",
    "dan",	"da",
    "deu",	"de",
    "div",	"dv",
    "nld",	"nl",
    "dzo",	"dz",
    "ell",	"el",
    "eng",	"en",
    "epo",	"eo",
    "est",	"et",
    "eus",	"eu",
    "ewe",	"ee",
    "fao",	"fo",
    "fas",	"fa",
    "fij",	"fj",
    "fin",	"fi",
    "fra",	"fr",
    "fra",	"fr",
    "fry",	"fy",
    "ful",	"ff",
    "kat",	"ka",
    "deu",	"de",
    "gla",	"gd",
    "gle",	"ga",
    "glg",	"gl",
    "glv",	"gv",
    "ell",	"el",
    "grn",	"gn",
    "guj",	"gu",
    "hat",	"ht",
    "hau",	"ha",
    "heb",	"he",
    "her",	"hz",
    "hin",	"hi",
    "hmo",	"ho",
    "hrv",	"hr",
    "hun",	"hu",
    "hye",	"hy",
    "ibo",	"ig",
    "ice",	"is",
    "ido",	"io",
    "iii",	"ii",
    "iku",	"iu",
    "ile",	"ie",
    "ina",	"ia",
    "ind",	"id",
    "ipk",	"ik",
    "isl",	"is",
    "ita",	"it",
    "jav",	"jv",
    "jpn",	"ja",
    "kal",	"kl",
    "kan",	"kn",
    "kas",	"ks",
    "kat",	"ka",
    "kau",	"kr",
    "kaz",	"kk",
    "khm",	"km",
    "kik",	"ki",
    "kin",	"rw",
    "kir",	"ky",
    "kom",	"kv",
    "kon",	"kg",
    "kor",	"ko",
    "kua",	"kj",
    "kur",	"ku",
    "lao",	"lo",
    "lat",	"la",
    "lav",	"lv",
    "lim",	"li",
    "lin",	"ln",
    "lit",	"lt",
    "ltz",	"lb",
    "lub",	"lu",
    "lug",	"lg",
    "mkd",	"mk",
    "mah",	"mh",
    "mal",	"ml",
    "mri",	"mi",
    "mar",	"mr",
    "msa",	"ms",
    "mkd",	"mk",
    "mlg",	"mg",
    "mlt",	"mt",
    "mon",	"mn",
    "mri",	"mi",
    "msa",	"ms",
    "mya",	"my",
    "nau",	"na",
    "nav",	"nv",
    "nbl",	"nr",
    "nde",	"nd",
    "ndo",	"ng",
    "nep",	"ne",
    "nld",	"nl",
    "nno",	"nn",
    "nob",	"nb",
    "nor",	"no",
    "nya",	"ny",
    "oci",	"oc",
    "oji",	"oj",
    "ori",	"or",
    "orm",	"om",
    "oss",	"os",
    "pan",	"pa",
    "fas",	"fa",
    "pli",	"pi",
    "pol",	"pl",
    "por",	"pt",
    "pus",	"ps",
    "que",	"qu",
    "roh",	"rm",
    "ron",	"ro",
    "ron",	"ro",
    "run",	"rn",
    "rus",	"ru",
    "sag",	"sg",
    "san",	"sa",
    "sin",	"si",
    "slk",	"sk",
    "slk",	"sk",
    "slv",	"sl",
    "sme",	"se",
    "smo",	"sm",
    "sna",	"sn",
    "snd",	"sd",
    "som",	"so",
    "sot",	"st",
    "spa",	"es",
    "sqi",	"sq",
    "srd",	"sc",
    "srp",	"sr",
    "ssw",	"ss",
    "sun",	"su",
    "swa",	"sw",
    "swe",	"sv",
    "tah",	"ty",
    "tam",	"ta",
    "tat",	"tt",
    "tel",	"te",
    "tgk",	"tg",
    "tgl",	"tl",
    "tha",	"th",
    "bod",	"bo",
    "tir",	"ti",
    "ton",	"to",
    "tsn",	"tn",
    "tso",	"ts",
    "tuk",	"tk",
    "tur",	"tr",
    "twi",	"tw",
    "uig",	"ug",
    "ukr",	"uk",
    "urd",	"ur",
    "uzb",	"uz",
    "ven",	"ve",
    "vie",	"vi",
    "vol",	"vo",
    "cym",	"cy",
    "wln",	"wa",
    "wol",	"wo",
    "xho",	"xh",
    "yid",	"yi",
    "yor",	"yo",
    "zha",	"za",
    "zho",	"zh",
    "zul",	"zu"
  };
  for (size_t i = 0; i < sizeof(ar)/sizeof(ar[0]); i += 2)
  {
    if (code_ISO_639_2 == ar[i])
    {
      return ar[i + 1];
    }
  }
  LOG(LDEBUG, ("Language not found", code_ISO_639_2));
  return "en";
}
<|endoftext|>