<commit_before>/*
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2010, Willow Garage, Inc.
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of Willow Garage, Inc. nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER 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.
 *
 *
 */

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::transformPointCloud (const pcl::PointCloud<PointT> &cloud_in,
                          pcl::PointCloud<PointT> &cloud_out,
                          const Eigen::Affine3f &transform)
{
  // In order to transform the data, we need to remove NaNs
  cloud_out.is_dense = true;
  if (&cloud_in != &cloud_out)
  {
    // Note: could be replaced by cloud_out = cloud_in
    cloud_out.header   = cloud_in.header;
    cloud_out.width    = cloud_in.width;
    cloud_out.height   = cloud_in.height;
    cloud_out.points.reserve (cloud_out.points.size ());
    cloud_out.points.assign (cloud_in.points.begin (), cloud_in.points.end ());
  }

  if (cloud_in.is_dense)
  {
    // If the dataset is dense, simply transform it!
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
      cloud_out.points[i].getVector3fMap () = transform *
                                              cloud_in.points[i].getVector3fMap ();
  }
  else
  {
    // Dataset might contain NaNs and Infs, so check for them first,
    // otherwise we get errors during the multiplication (?)
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
    {
      if (!pcl_isfinite (cloud_in.points[i].x) ||
          !pcl_isfinite (cloud_in.points[i].y) ||
          !pcl_isfinite (cloud_in.points[i].z))
        continue;
      cloud_out.points[i].getVector3fMap () = transform *
                                              cloud_in.points[i].getVector3fMap ();
    }
  }
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::transformPointCloud (const pcl::PointCloud<PointT> &cloud_in,
                          const std::vector<int> &indices,
                          pcl::PointCloud<PointT> &cloud_out,
                          const Eigen::Affine3f &transform)
{
  size_t npts = indices.size ();
  // In order to transform the data, we need to remove NaNs
  cloud_out.is_dense = true;
  cloud_out.header   = cloud_in.header;
  cloud_out.width    = npts;
  cloud_out.height   = 1;
  cloud_out.points.resize (npts);

  if (cloud_in.is_dense)
  {
    // If the dataset is dense, simply transform it!
    for (size_t i = 0; i < npts; ++i)
      cloud_out.points[i].getVector3fMap () = transform *
                                              cloud_in.points[indices[i]].getVector3fMap ();
  }
  else
  {
    // Dataset might contain NaNs and Infs, so check for them first,
    // otherwise we get errors during the multiplication (?)
    for (size_t i = 0; i < npts; ++i)
    {
      if (!pcl_isfinite (cloud_in.points[indices[i]].x) ||
          !pcl_isfinite (cloud_in.points[indices[i]].y) ||
          !pcl_isfinite (cloud_in.points[indices[i]].z))
        continue;
      cloud_out.points[i].getVector3fMap () = transform *
                                              cloud_in.points[indices[i]].getVector3fMap ();
    }
  }
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::transformPointCloudWithNormals (const pcl::PointCloud<PointT> &cloud_in,
                                     pcl::PointCloud<PointT> &cloud_out,
                                     const Eigen::Affine3f &transform)
{
  if (&cloud_in != &cloud_out)
  {
    // Note: could be replaced by cloud_out = cloud_in
    cloud_out.header   = cloud_in.header;
    cloud_out.width    = cloud_in.width;
    cloud_out.height   = cloud_in.height;
    cloud_out.is_dense = cloud_in.is_dense;
    cloud_out.points.reserve (cloud_out.points.size ());
    cloud_out.points.assign (cloud_in.points.begin (), cloud_in.points.end ());
  }

  // If the data is dense, we don't need to check for NaN
  if (cloud_in.is_dense)
  {
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
    {
      cloud_out.points[i].getVector3fMap() = transform *
                                             cloud_in.points[i].getVector3fMap ();

      // Rotate normals
      cloud_out.points[i].getNormalVector3fMap() = transform.rotation () *
                                                   cloud_in.points[i].getNormalVector3fMap ();
    }
  }
  // Dataset might contain NaNs and Infs, so check for them first.
  else
  {
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
    {
      if (!pcl_isfinite (cloud_in.points[i].x) ||
          !pcl_isfinite (cloud_in.points[i].y) ||
          !pcl_isfinite (cloud_in.points[i].z))
        continue;
      cloud_out.points[i].getVector3fMap() = transform *
                                             cloud_in.points[i].getVector3fMap ();

      // Rotate normals
      cloud_out.points[i].getNormalVector3fMap() = transform.rotation () *
                                                   cloud_in.points[i].getNormalVector3fMap ();
    }
  }
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::transformPointCloud (const pcl::PointCloud<PointT> &cloud_in,
                          pcl::PointCloud<PointT> &cloud_out,
                          const Eigen::Matrix4f &transform)
{
  if (&cloud_in != &cloud_out)
  {
    // Note: could be replaced by cloud_out = cloud_in
    cloud_out.header   = cloud_in.header;
    cloud_out.width    = cloud_in.width;
    cloud_out.height   = cloud_in.height;
    cloud_out.is_dense = cloud_in.is_dense;
    cloud_out.points.reserve (cloud_out.points.size ());
    cloud_out.points.assign (cloud_in.points.begin (), cloud_in.points.end ());
  }

  Eigen::Matrix3f rot   = transform.block<3, 3> (0, 0);
  Eigen::Vector3f trans = transform.block<3, 1> (0, 3);
  // If the data is dense, we don't need to check for NaN
  if (cloud_in.is_dense)
  {
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
      cloud_out.points[i].getVector3fMap () = rot *
                                              cloud_in.points[i].getVector3fMap () + trans;
  }
  // Dataset might contain NaNs and Infs, so check for them first.
  else
  {
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
    {
      if (!pcl_isfinite (cloud_in.points[i].x) ||
          !pcl_isfinite (cloud_in.points[i].y) ||
          !pcl_isfinite (cloud_in.points[i].z))
        continue;
      cloud_out.points[i].getVector3fMap () = rot *
                                              cloud_in.points[i].getVector3fMap () + trans;
    }
  }
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::transformPointCloudWithNormals (const pcl::PointCloud<PointT> &cloud_in,
                                     pcl::PointCloud<PointT> &cloud_out,
                                     const Eigen::Matrix4f &transform)
{
  if (&cloud_in != &cloud_out)
  {
    // Note: could be replaced by cloud_out = cloud_in
    cloud_out.header   = cloud_in.header;
    cloud_out.width    = cloud_in.width;
    cloud_out.height   = cloud_in.height;
    cloud_out.is_dense = cloud_in.is_dense;
    cloud_out.points.reserve (cloud_out.points.size ());
    cloud_out.points.assign (cloud_in.points.begin (), cloud_in.points.end ());
  }

  Eigen::Matrix3f rot   = transform.block<3, 3> (0, 0);
  Eigen::Vector3f trans = transform.block<3, 1> (0, 3);

  // If the data is dense, we don't need to check for NaN
  if (cloud_in.is_dense)
  {
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
    {
      cloud_out.points[i].getVector3fMap () = rot *
                                              cloud_in.points[i].getVector3fMap () + trans;

      // Rotate normals
      cloud_out.points[i].getNormalVector3fMap() = rot *
                                                   cloud_in.points[i].getNormalVector3fMap ();
    }
  }
  // Dataset might contain NaNs and Infs, so check for them first.
  else
  {
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
    {
      if (!pcl_isfinite (cloud_in.points[i].x) ||
          !pcl_isfinite (cloud_in.points[i].y) ||
          !pcl_isfinite (cloud_in.points[i].z))
        continue;
      cloud_out.points[i].getVector3fMap () = rot *
                                              cloud_in.points[i].getVector3fMap () + trans;

      // Rotate normals
      cloud_out.points[i].getNormalVector3fMap() = rot *
                                                   cloud_in.points[i].getNormalVector3fMap ();
    }
  }
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> inline void
pcl::transformPointCloud (const pcl::PointCloud<PointT> &cloud_in,
                          pcl::PointCloud<PointT> &cloud_out,
                          const Eigen::Vector3f &offset,
                          const Eigen::Quaternionf &rotation)
{
  Eigen::Translation3f translation (offset);
  // Assemble an Eigen Transform
  Eigen::Affine3f t;
  t = translation * rotation;
  transformPointCloud (cloud_in, cloud_out, t);
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> inline void
pcl::transformPointCloudWithNormals (const pcl::PointCloud<PointT> &cloud_in,
                                     pcl::PointCloud<PointT> &cloud_out,
                                     const Eigen::Vector3f &offset,
                                     const Eigen::Quaternionf &rotation)
{
  Eigen::Translation3f translation (offset);
  // Assemble an Eigen Transform
  Eigen::Affine3f t;
  t = translation * rotation;
  transformPointCloudWithNormals (cloud_in, cloud_out, t);
}
<commit_msg>is_dense fix for transformPointCloud (thanks Aitor)<commit_after>/*
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2010, Willow Garage, Inc.
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of Willow Garage, Inc. nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER 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.
 *
 *
 */

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::transformPointCloud (const pcl::PointCloud<PointT> &cloud_in,
                          pcl::PointCloud<PointT> &cloud_out,
                          const Eigen::Affine3f &transform)
{
  if (&cloud_in != &cloud_out)
  {
    // Note: could be replaced by cloud_out = cloud_in
    cloud_out.header   = cloud_in.header;
    cloud_out.is_dense = cloud_in.is_dense;
    cloud_out.width    = cloud_in.width;
    cloud_out.height   = cloud_in.height;
    cloud_out.points.reserve (cloud_out.points.size ());
    cloud_out.points.assign (cloud_in.points.begin (), cloud_in.points.end ());
  }

  if (cloud_in.is_dense)
  {
    // If the dataset is dense, simply transform it!
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
      cloud_out.points[i].getVector3fMap () = transform *
                                              cloud_in.points[i].getVector3fMap ();
  }
  else
  {
    // Dataset might contain NaNs and Infs, so check for them first,
    // otherwise we get errors during the multiplication (?)
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
    {
      if (!pcl_isfinite (cloud_in.points[i].x) ||
          !pcl_isfinite (cloud_in.points[i].y) ||
          !pcl_isfinite (cloud_in.points[i].z))
        continue;
      cloud_out.points[i].getVector3fMap () = transform *
                                              cloud_in.points[i].getVector3fMap ();
    }
  }
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::transformPointCloud (const pcl::PointCloud<PointT> &cloud_in,
                          const std::vector<int> &indices,
                          pcl::PointCloud<PointT> &cloud_out,
                          const Eigen::Affine3f &transform)
{
  size_t npts = indices.size ();
  // In order to transform the data, we need to remove NaNs
  cloud_out.is_dense = cloud_in.is_dense;
  cloud_out.header   = cloud_in.header;
  cloud_out.width    = npts;
  cloud_out.height   = 1;
  cloud_out.points.resize (npts);

  if (cloud_in.is_dense)
  {
    // If the dataset is dense, simply transform it!
    for (size_t i = 0; i < npts; ++i)
      cloud_out.points[i].getVector3fMap () = transform *
                                              cloud_in.points[indices[i]].getVector3fMap ();
  }
  else
  {
    // Dataset might contain NaNs and Infs, so check for them first,
    // otherwise we get errors during the multiplication (?)
    for (size_t i = 0; i < npts; ++i)
    {
      if (!pcl_isfinite (cloud_in.points[indices[i]].x) ||
          !pcl_isfinite (cloud_in.points[indices[i]].y) ||
          !pcl_isfinite (cloud_in.points[indices[i]].z))
        continue;
      cloud_out.points[i].getVector3fMap () = transform *
                                              cloud_in.points[indices[i]].getVector3fMap ();
    }
  }
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::transformPointCloudWithNormals (const pcl::PointCloud<PointT> &cloud_in,
                                     pcl::PointCloud<PointT> &cloud_out,
                                     const Eigen::Affine3f &transform)
{
  if (&cloud_in != &cloud_out)
  {
    // Note: could be replaced by cloud_out = cloud_in
    cloud_out.header   = cloud_in.header;
    cloud_out.width    = cloud_in.width;
    cloud_out.height   = cloud_in.height;
    cloud_out.is_dense = cloud_in.is_dense;
    cloud_out.points.reserve (cloud_out.points.size ());
    cloud_out.points.assign (cloud_in.points.begin (), cloud_in.points.end ());
  }

  // If the data is dense, we don't need to check for NaN
  if (cloud_in.is_dense)
  {
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
    {
      cloud_out.points[i].getVector3fMap() = transform *
                                             cloud_in.points[i].getVector3fMap ();

      // Rotate normals
      cloud_out.points[i].getNormalVector3fMap() = transform.rotation () *
                                                   cloud_in.points[i].getNormalVector3fMap ();
    }
  }
  // Dataset might contain NaNs and Infs, so check for them first.
  else
  {
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
    {
      if (!pcl_isfinite (cloud_in.points[i].x) ||
          !pcl_isfinite (cloud_in.points[i].y) ||
          !pcl_isfinite (cloud_in.points[i].z))
        continue;
      cloud_out.points[i].getVector3fMap() = transform *
                                             cloud_in.points[i].getVector3fMap ();

      // Rotate normals
      cloud_out.points[i].getNormalVector3fMap() = transform.rotation () *
                                                   cloud_in.points[i].getNormalVector3fMap ();
    }
  }
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::transformPointCloud (const pcl::PointCloud<PointT> &cloud_in,
                          pcl::PointCloud<PointT> &cloud_out,
                          const Eigen::Matrix4f &transform)
{
  if (&cloud_in != &cloud_out)
  {
    // Note: could be replaced by cloud_out = cloud_in
    cloud_out.header   = cloud_in.header;
    cloud_out.width    = cloud_in.width;
    cloud_out.height   = cloud_in.height;
    cloud_out.is_dense = cloud_in.is_dense;
    cloud_out.points.reserve (cloud_out.points.size ());
    cloud_out.points.assign (cloud_in.points.begin (), cloud_in.points.end ());
  }

  Eigen::Matrix3f rot   = transform.block<3, 3> (0, 0);
  Eigen::Vector3f trans = transform.block<3, 1> (0, 3);
  // If the data is dense, we don't need to check for NaN
  if (cloud_in.is_dense)
  {
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
      cloud_out.points[i].getVector3fMap () = rot *
                                              cloud_in.points[i].getVector3fMap () + trans;
  }
  // Dataset might contain NaNs and Infs, so check for them first.
  else
  {
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
    {
      if (!pcl_isfinite (cloud_in.points[i].x) ||
          !pcl_isfinite (cloud_in.points[i].y) ||
          !pcl_isfinite (cloud_in.points[i].z))
        continue;
      cloud_out.points[i].getVector3fMap () = rot *
                                              cloud_in.points[i].getVector3fMap () + trans;
    }
  }
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> void
pcl::transformPointCloudWithNormals (const pcl::PointCloud<PointT> &cloud_in,
                                     pcl::PointCloud<PointT> &cloud_out,
                                     const Eigen::Matrix4f &transform)
{
  if (&cloud_in != &cloud_out)
  {
    // Note: could be replaced by cloud_out = cloud_in
    cloud_out.header   = cloud_in.header;
    cloud_out.width    = cloud_in.width;
    cloud_out.height   = cloud_in.height;
    cloud_out.is_dense = cloud_in.is_dense;
    cloud_out.points.reserve (cloud_out.points.size ());
    cloud_out.points.assign (cloud_in.points.begin (), cloud_in.points.end ());
  }

  Eigen::Matrix3f rot   = transform.block<3, 3> (0, 0);
  Eigen::Vector3f trans = transform.block<3, 1> (0, 3);

  // If the data is dense, we don't need to check for NaN
  if (cloud_in.is_dense)
  {
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
    {
      cloud_out.points[i].getVector3fMap () = rot *
                                              cloud_in.points[i].getVector3fMap () + trans;

      // Rotate normals
      cloud_out.points[i].getNormalVector3fMap() = rot *
                                                   cloud_in.points[i].getNormalVector3fMap ();
    }
  }
  // Dataset might contain NaNs and Infs, so check for them first.
  else
  {
    for (size_t i = 0; i < cloud_out.points.size (); ++i)
    {
      if (!pcl_isfinite (cloud_in.points[i].x) ||
          !pcl_isfinite (cloud_in.points[i].y) ||
          !pcl_isfinite (cloud_in.points[i].z))
        continue;
      cloud_out.points[i].getVector3fMap () = rot *
                                              cloud_in.points[i].getVector3fMap () + trans;

      // Rotate normals
      cloud_out.points[i].getNormalVector3fMap() = rot *
                                                   cloud_in.points[i].getNormalVector3fMap ();
    }
  }
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> inline void
pcl::transformPointCloud (const pcl::PointCloud<PointT> &cloud_in,
                          pcl::PointCloud<PointT> &cloud_out,
                          const Eigen::Vector3f &offset,
                          const Eigen::Quaternionf &rotation)
{
  Eigen::Translation3f translation (offset);
  // Assemble an Eigen Transform
  Eigen::Affine3f t;
  t = translation * rotation;
  transformPointCloud (cloud_in, cloud_out, t);
}

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT> inline void
pcl::transformPointCloudWithNormals (const pcl::PointCloud<PointT> &cloud_in,
                                     pcl::PointCloud<PointT> &cloud_out,
                                     const Eigen::Vector3f &offset,
                                     const Eigen::Quaternionf &rotation)
{
  Eigen::Translation3f translation (offset);
  // Assemble an Eigen Transform
  Eigen::Affine3f t;
  t = translation * rotation;
  transformPointCloudWithNormals (cloud_in, cloud_out, t);
}
<|endoftext|>


<commit_before>#include "../../../../runtime/types/InternalTypes.h"

void FileType::__constructor__() {
	auto self = Program::create<FileInstance>();
	auto file_path = Program::argument<TextInstance>();

	self->file_path = file_path->text();
	Program::push(self);
}

void FileType::open() {
    auto self = Program::argument<FileInstance>();
	auto mode = Program::argument<TextInstance>();

	if(mode->text() == "r") {
		self->file.open(self->file_path, std::ios::in);
	} else if(mode->text() == "w") {
		self->file.open(self->file_path, std::ios::out);
	} else {
		throw RuntimeError("Invalid file mode"); // TODO: throw user exception
	}
}

void FileType::close() {
	auto self = Program::argument<FileInstance>();

	self->file.close();
}

void FileType::write() {
    auto self = Program::argument<FileInstance>();
	auto contents = Program::argument<TextInstance>();

	self->file << contents->text();
}

void FileType::read() {
	auto self = Program::argument<FileInstance>();

	std::stringstream sstr;
	sstr << self->file.rdbuf();
	Program::push(Program::create<TextInstance>(sstr.str()));
}

std::string FileInstance::text() {
	return "File(" + this->file_path + ")";
}

bool FileInstance::boolean() {
	return file.good();
}

<commit_msg>Add binary mode support for FileType<commit_after>#include "../../../../runtime/types/InternalTypes.h"

void FileType::__constructor__() {
	auto self = Program::create<FileInstance>();
	auto file_path = Program::argument<TextInstance>();

	self->file_path = file_path->text();
	Program::push(self);
}

void FileType::open() {
    auto self = Program::argument<FileInstance>();
	auto mode = Program::argument<TextInstance>();
    auto mode_type = mode->text();

	if(mode_type == "r") {
		self->file.open(self->file_path, std::ios::in);
	} else if(mode_type == "w") {
		self->file.open(self->file_path, std::ios::out);
	} else if(mode_type == "rb") {
        self->file.open(self->file_path, std::ios::in | std::ios::binary);
    } else if(mode_type == "wb"){
        self->file.open(self->file_path, std::ios::out | std::ios::binary);
    } else {
        throw RuntimeError("Invalid file mode"); // TODO: throw user exception
	}
}

void FileType::close() {
	auto self = Program::argument<FileInstance>();

	self->file.close();
}

void FileType::write() {
    auto self = Program::argument<FileInstance>();
	auto contents = Program::argument<TextInstance>();

	self->file << contents->text();
}

void FileType::read() {
	auto self = Program::argument<FileInstance>();

	std::stringstream sstr;
	sstr << self->file.rdbuf();
	Program::push(Program::create<TextInstance>(sstr.str()));
}

std::string FileInstance::text() {
	return "File(" + this->file_path + ")";
}

bool FileInstance::boolean() {
	return file.good();
}

<|endoftext|>


<commit_before>#include "test_helper.h"
#include "uTensor/loaders/tensorIdxImporter.hpp"
#include "MatrixOps.hpp"

#include <iostream>
using std::cout;
using std::endl;

TensorIdxImporter t_import;
Context ctx;

void test_operators_fusedConvMaxpool12(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size2_input.idx"), "x_1_2");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size2_weights.idx"), "w_1_2");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth1_pool_size2_output.idx"), "ref_1_2");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_1_2");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 2, 2, 1 },VALID),
            { "x_1_2", "w_1_2"}, {"out_1_2"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool13(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size3_input.idx"), "x_1_3");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size3_weights.idx"), "w_1_3");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth1_pool_size3_output.idx"), "ref_1_3");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_1_3");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 3, 3, 1 },VALID),
            { "x_1_3", "w_1_3"}, {"out_1_3"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool14(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size4_input.idx"), "x_1_4");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size4_weights.idx"), "w_1_4");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth1_pool_size4_output.idx"), "ref_1_4");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_1_4");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 4, 4, 1 },VALID),
            { "x_1_4", "w_1_4"}, {"out_1_4"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool22(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size2_input.idx"), "x_2_2");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size2_weights.idx"), "w_2_2");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth2_pool_size2_output.idx"), "ref_2_2");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_2_2");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 2, 2, 1 },VALID),
            { "x_2_2", "w_2_2"}, {"out_2_2"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool23(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size3_input.idx"), "x_2_3");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size3_weights.idx"), "w_2_3");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth2_pool_size3_output.idx"), "ref_2_3");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_2_3");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 3, 3, 1 },VALID),
            { "x_2_3", "w_2_3"}, {"out_2_3"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool24(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size4_input.idx"), "x_2_4");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size4_weights.idx"), "w_2_4");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth2_pool_size4_output.idx"), "ref_2_4");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_2_4");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 4, 4, 1 },VALID),
            { "x_2_4", "w_2_4"}, {"out_2_4"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool32(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size2_input.idx"), "x_3_2");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size2_weights.idx"), "w_3_2");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth3_pool_size2_output.idx"), "ref_3_2");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_3_2");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 2, 2, 1 },VALID),
            { "x_3_2", "w_3_2"}, {"out_3_2"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool33(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size3_input.idx"), "x_3_3");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size3_weights.idx"), "w_3_3");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth3_pool_size3_output.idx"), "ref_3_3");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_3_3");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 3, 3, 1 },VALID),
            { "x_3_3", "w_3_3"}, {"out_3_3"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool34(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size4_input.idx"), "x_3_4");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size4_weights.idx"), "w_3_4");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth3_pool_size4_output.idx"), "ref_3_4");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_3_4");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 4, 4, 1 },VALID),
            { "x_3_4", "w_3_4"}, {"out_3_4"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}

// First configure the uTensor test runner
UTENSOR_TEST_CONFIGURE()

// Second declare tests to run
UTENSOR_TEST(operators, fusedConvMaxpool12, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool13, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool14, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool22, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool23, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool24, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool32, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool33, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool34, "Generated Fused Conv Maxpool test")

// Third, run like hell
UTENSOR_TEST_RUN()

<commit_msg>Change to SAME padding<commit_after>#include "test_helper.h"
#include "uTensor/loaders/tensorIdxImporter.hpp"
#include "MatrixOps.hpp"

#include <iostream>
using std::cout;
using std::endl;

TensorIdxImporter t_import;
Context ctx;

void test_operators_fusedConvMaxpool12(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size2_input.idx"), "x_1_2");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size2_weights.idx"), "w_1_2");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth1_pool_size2_output.idx"), "ref_1_2");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_1_2");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 2, 2, 1 },SAME),
            { "x_1_2", "w_1_2"}, {"out_1_2"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool13(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size3_input.idx"), "x_1_3");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size3_weights.idx"), "w_1_3");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth1_pool_size3_output.idx"), "ref_1_3");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_1_3");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 3, 3, 1 },SAME),
            { "x_1_3", "w_1_3"}, {"out_1_3"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool14(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size4_input.idx"), "x_1_4");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth1_pool_size4_weights.idx"), "w_1_4");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth1_pool_size4_output.idx"), "ref_1_4");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_1_4");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 4, 4, 1 },SAME),
            { "x_1_4", "w_1_4"}, {"out_1_4"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool22(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size2_input.idx"), "x_2_2");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size2_weights.idx"), "w_2_2");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth2_pool_size2_output.idx"), "ref_2_2");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_2_2");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 2, 2, 1 },SAME),
            { "x_2_2", "w_2_2"}, {"out_2_2"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool23(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size3_input.idx"), "x_2_3");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size3_weights.idx"), "w_2_3");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth2_pool_size3_output.idx"), "ref_2_3");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_2_3");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 3, 3, 1 },SAME),
            { "x_2_3", "w_2_3"}, {"out_2_3"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool24(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size4_input.idx"), "x_2_4");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth2_pool_size4_weights.idx"), "w_2_4");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth2_pool_size4_output.idx"), "ref_2_4");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_2_4");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 4, 4, 1 },SAME),
            { "x_2_4", "w_2_4"}, {"out_2_4"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool32(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size2_input.idx"), "x_3_2");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size2_weights.idx"), "w_3_2");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth3_pool_size2_output.idx"), "ref_3_2");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_3_2");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 2, 2, 1 },SAME),
            { "x_3_2", "w_3_2"}, {"out_3_2"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool33(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size3_input.idx"), "x_3_3");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size3_weights.idx"), "w_3_3");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth3_pool_size3_output.idx"), "ref_3_3");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_3_3");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 3, 3, 1 },SAME),
            { "x_3_3", "w_3_3"}, {"out_3_3"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}
void test_operators_fusedConvMaxpool34(void) {
    ctx.gc();

    //inputs
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size4_input.idx"), "x_3_4");
    ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/in/depth3_pool_size4_weights.idx"), "w_3_4");

    //reference outputs
    S_TENSOR ref = ctx.add(t_import.float_import("/fs/constants/fusedConvMaxpool/out/depth3_pool_size4_output.idx"), "ref_3_4");

    //Outputs
    S_TENSOR out = ctx.add(new RamTensor<float>(ref->getShape()), "out_3_4");

    ctx.push(new FusedConvMaxpoolOp<float,float,float>({ 1, 1 }, { 1, 4, 4, 1 },SAME),
            { "x_3_4", "w_3_4"}, {"out_3_4"});

    ctx.eval();

    double result = meanPercentErr<float>(ref.get(), out.get());
    EXPECT_EQ(result, 0);

}

// First configure the uTensor test runner
UTENSOR_TEST_CONFIGURE()

// Second declare tests to run
UTENSOR_TEST(operators, fusedConvMaxpool12, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool13, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool14, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool22, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool23, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool24, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool32, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool33, "Generated Fused Conv Maxpool test")
UTENSOR_TEST(operators, fusedConvMaxpool34, "Generated Fused Conv Maxpool test")

// Third, run like hell
UTENSOR_TEST_RUN()

<|endoftext|>


<commit_before>//===========================================
//  Lumina-DE source code
//  Copyright (c) 2012, Ken Moore
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================

#include <QApplication>
#include <QX11Info>
#include <QProcess>
#include <QProcessEnvironment>
#include <QFile>
#include <QFileInfo>
#include <QString>
#include <QUrl>
#include <QDebug>
#include <QTranslator>
//#include <QLocale>
#include <QMessageBox>
#include <QSplashScreen>
#include <QDateTime>
#include <QPixmap>
#include <QColor>
#include <QFont>
//#include <QTextCodec>

#include "LFileDialog.h"

#include <LuminaXDG.h>
#include <LuminaUtils.h>
#include <LuminaOS.h>
#include <LuminaThemes.h>

void printUsageInfo(){
  qDebug() << "lumina-open: Application launcher for the Lumina Desktop Environment";
  qDebug() << "Description: Given a file (with absolute path) or URL, this utility will try to find the appropriate application with which to open the file. If the file is a *.desktop application shortcut, it will just start the application appropriately. It can also perform a few specific system operations if given special flags.";
  qDebug() << "Usage: lumina-open [-select] <absolute file path or URL>";
  qDebug() << "           lumina-open [-volumeup, -volumedown, -brightnessup, -brightnessdown]";
  qDebug() << "  [-select] (optional) flag to bypass any default application settings and show the application selector window";
  qDebug() << "Special Flags:";
  qDebug() << " \"-volume[up/down]\" Flag to increase/decrease audio volume by 5%";
  qDebug() << " \"-brightness[up/down]\" Flag to increase/decrease screen brightness by 5%";
  exit(1);
}

void showOSD(int argc, char **argv, QString message){
  //Setup the application
  QApplication App(argc, argv);
    LUtils::LoadTranslation(&App,"lumina-open");

  //Display the OSD
  QPixmap pix(":/icons/OSD.png");
  QSplashScreen splash(pix, Qt::SplashScreen | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
     splash.setWindowTitle("");
     QFont myfont;
	myfont.setBold(true);
	myfont.setPixelSize(13);
	splash.setFont(myfont);
  qDebug() << "Display OSD";
  splash.show();
  //qDebug() << " - show message";
  splash.showMessage(message, Qt::AlignCenter, Qt::white);
  //qDebug() << " - loop";
  QDateTime end = QDateTime::currentDateTime().addMSecs(800);
  while(QDateTime::currentDateTime() < end){ App.processEvents(); }
  splash.hide();
}

QString cmdFromUser(int argc, char **argv, QString inFile, QString extension, QString& path, bool showDLG=false){
    //First check to see if there is a default for this extension
    QString defApp;
    if(extension=="mimetype"){
	//qDebug() << "inFile:" << inFile;
	QStringList matches = LXDG::findAppMimeForFile(inFile, true).split("::::"); //allow multiple matches
	//qDebug() << "Matches:" << matches;
	for(int i=0; i<matches.length(); i++){
	  defApp = LXDG::findDefaultAppForMime(matches[i]);
	  if(!defApp.isEmpty()){ extension = matches[i]; break; }
	  else if(i+1==matches.length()){ extension = matches[0]; }
	}
    }else{ defApp = LFileDialog::getDefaultApp(extension); }

    if( !defApp.isEmpty() && !showDLG ){
      bool ok = false;
      if(defApp.endsWith(".desktop")){
        XDGDesktop DF = LXDG::loadDesktopFile(defApp, ok);
        if(ok){
      	  QString exec = LXDG::getDesktopExec(DF);
      	  if(!exec.isEmpty()){
      	    qDebug() << "[lumina-open] Using default application:" << DF.name << "File:" << inFile;
            if(!DF.path.isEmpty()){ path = DF.path; }
            return exec;
          }
        }
      }else{
	//Only binary given
	if(LUtils::isValidBinary(defApp)){
	  qDebug() << "[lumina-open] Using default application:" << defApp << "File:" << inFile;
	  return defApp; //just use the binary
	}
      }
      //invalid default - reset it and continue on
      LFileDialog::setDefaultApp(extension, "");
    }
    //Final catch: directory given - no valid default found - use lumina-fm
    if(extension=="directory" && !showDLG){ return "lumina-fm"; }
    //No default set -- Start up the application selection dialog
    QApplication App(argc, argv);
    LuminaThemeEngine theme(&App);
      LUtils::LoadTranslation(&App,"lumina-open");

    LFileDialog w;
    if(extension=="email" || extension=="webbrowser"){
      //URL
      w.setFileInfo(inFile, extension, false);
    }else{
      //File
      if(inFile.endsWith("/")){ inFile.chop(1); }
      w.setFileInfo(inFile.section("/",-1), extension, true);
    }

    w.show();
    App.exec();
    if(!w.appSelected){ return ""; }
    //Return the run path if appropriate
    if(!w.appPath.isEmpty()){ path = w.appPath; }
    //Just do the default application registration here for now
    //  might move it to the runtime phase later after seeing that the app has successfully started
    if(w.setDefault){
      if(!w.appFile.isEmpty()){ LFileDialog::setDefaultApp(extension, w.appFile); }
      else{ LFileDialog::setDefaultApp(extension, w.appExec); }
    }else{ LFileDialog::setDefaultApp(extension, ""); }
    //Now return the resulting application command
    return w.appExec;
}

void getCMD(int argc, char ** argv, QString& binary, QString& args, QString& path){
  //Get the input file
    //Make sure to load the proper system encoding first
    LUtils::LoadTranslation(0,""); //bypass application modification
  QString inFile;
  bool showDLG = false; //flag to bypass any default application setting
  if(argc > 1){
    for(int i=1; i<argc; i++){
      if(QString(argv[i]).simplified() == "-select"){
      	showDLG = true;
      }else if(QString(argv[i]).simplified() == "-volumeup"){
	int vol = LOS::audioVolume()+5; //increase 5%
	if(vol>100){ vol=100; }
	LOS::setAudioVolume(vol);
	showOSD(argc,argv, QString(QObject::tr("Audio Volume %1%")).arg(QString::number(vol)) );
	return;
      }else if(QString(argv[i]).simplified() == "-volumedown"){
	int vol = LOS::audioVolume()-5; //decrease 5%
	if(vol<0){ vol=0; }
	LOS::setAudioVolume(vol);
	showOSD(argc,argv, QString(QObject::tr("Audio Volume %1%")).arg(QString::number(vol)) );
	return;
      }else if(QString(argv[i]).simplified() == "-brightnessup"){
	int bright = LOS::ScreenBrightness();
	if(bright > 0){ //brightness control available
	  bright = bright+5; //increase 5%
	  if(bright>100){ bright = 100; }
	  LOS::setScreenBrightness(bright);
	  showOSD(argc,argv, QString(QObject::tr("Screen Brightness %1%")).arg(QString::number(bright)) );
	}
	return;
      }else if(QString(argv[i]).simplified() == "-brightnessdown"){
	int bright = LOS::ScreenBrightness();
	if(bright > 0){ //brightness control available
	  bright = bright-5; //decrease 5%
	  if(bright<0){ bright = 0; }
	  LOS::setScreenBrightness(bright);
	  showOSD(argc,argv, QString(QObject::tr("Screen Brightness %1%")).arg(QString::number(bright)) );
	}
	return;
      }else{
        inFile = QString::fromLocal8Bit(argv[i]);
        break;
      }
    }
  }else{
    printUsageInfo();
  }
  //Make sure that it is a valid file/URL
  bool isFile=false; bool isUrl=false;
  if(QFile::exists(inFile)){ isFile=true; }
  else if(QFile::exists(QDir::currentPath()+"/"+inFile)){isFile=true; inFile = QDir::currentPath()+"/"+inFile;} //account for relative paths
  else if(QUrl(inFile).isValid() && !inFile.startsWith("/") ){ isUrl=true; }
  if( !isFile && !isUrl ){ qDebug() << "Error: Invalid file or URL"; return;}
  //Determing the type of file (extension)
  QString extension;
  //qDebug() << "File Type:" << isFile << isUrl;
  if(isFile){
    QFileInfo info(inFile);
    extension=info.suffix();
    //qDebug() << " - Extension:" << extension;
    if(info.isDir()){ extension="directory"; }
    else if(info.isExecutable() && extension.isEmpty()){ extension="binary"; }
    else if(extension!="desktop"){ extension="mimetype"; } //flag to check for mimetype default based on file
  }
  else if(isUrl && inFile.startsWith("mailto:")){ extension = "email"; }
  else if(isUrl){ extension = "webbrowser"; }
  //qDebug() << "Input:" << inFile << isFile << isUrl << extension;
  //if not an application  - find the right application to open the file
  QString cmd;
  bool useInputFile = false;
  if(extension=="desktop" && !showDLG){
    bool ok = false;
    XDGDesktop DF = LXDG::loadDesktopFile(inFile, ok);
    if(!ok){
      qDebug() << "[ERROR] Input *.desktop file could not be read:" << inFile;
      exit(1);
    }
    switch(DF.type){
      case XDGDesktop::APP:
        if(!DF.exec.isEmpty()){
          cmd = LXDG::getDesktopExec(DF);
          if(!DF.path.isEmpty()){ path = DF.path; }
        }else{
          qDebug() << "[ERROR] Input *.desktop application file is missing the Exec line:" << inFile;
          exit(1);
        }
        break;
      case XDGDesktop::LINK:
        if(!DF.url.isEmpty()){
          //This is a URL - so adjust the input variables appropriately
          inFile = DF.url;
          cmd.clear();
          extension = inFile.section(":",0,0);
        }else{
          qDebug() << "[ERROR] Input *.desktop link file is missing the URL line:" << inFile;
          exit(1);
        }
        break;
      case XDGDesktop::DIR:
        if(!DF.path.isEmpty()){
          //This is a directory link - adjust inputs
          inFile = DF.path;
          cmd.clear();
          extension = "directory";
        }else{
          qDebug() << "[ERROR] Input *.desktop directory file is missing the Path line:" << inFile;
          exit(1);
        }
        break;
      default:
        qDebug() << "[ERROR] Unknown *.desktop file type:" << inFile;
        exit(1);
    }
  }
  if(cmd.isEmpty()){
    if(extension=="binary"){ cmd = inFile; }
    else{
    //Find out the proper application to use this file/directory
    useInputFile=true;
    cmd = cmdFromUser(argc, argv, inFile, extension, path, showDLG);
    if(cmd.isEmpty()){ return; }
    }
  }
  //Now assemble the exec string (replace file/url field codes as necessary)
  if(useInputFile){
    args = inFile; //just to keep them distinct internally
    // NOTE: lumina-open is only designed for a single input file,
    //    so no need to distinguish between the list codes (uppercase)
    //    and the single-file codes (lowercase)
    if(isFile && (cmd.contains("%f") || cmd.contains("%F") ) ){
      cmd.replace("%f","\""+inFile+"\"");
      cmd.replace("%F","\""+inFile+"\"");
    }else if(isUrl && (cmd.contains("%U") || cmd.contains("%u")) ){
      cmd.replace("%u","\""+inFile+"\"");
      cmd.replace("%U","\""+inFile+"\"");
    }else{
      //No field codes (or improper field codes given - which is quite common)
      // - Just tack the input file on the end and let the app handle it as necessary
      cmd.append(" \""+inFile+"\"");
    }
  }
  //qDebug() << "Found Command:" << cmd << "Extension:" << extension;
  //Clean up any leftover "Exec" field codes (should have already been replaced earlier)
  if(cmd.contains("%")){cmd = cmd.remove("%U").remove("%u").remove("%F").remove("%f").remove("%i").remove("%c").remove("%k").simplified(); }
  binary = cmd; //pass this string to the calling function

}

int main(int argc, char **argv){
  //Run all the actual code in a separate function to have as little memory usage
  //  as possible aside from the main application when running

  //Make sure the XDG environment variables exist first
  LXDG::setEnvironmentVars();
  //now get the command
  QString cmd, args, path;
  getCMD(argc, argv, cmd, args, path);
  //qDebug() << "Run CMD:" << cmd << args;
  //Now run the command (move to execvp() later?)
  if(cmd.isEmpty()){ return 0; } //no command to run (handled internally)
  //if(!args.isEmpty()){ cmd.append(" "+args+""); }
  //int retcode = system( cmd.toUtf8() );
  qDebug() << "[lumina-open] Running Cmd:" << cmd;
  QProcess *p = new QProcess();
  p->setProcessEnvironment(QProcessEnvironment::systemEnvironment());
  if(!path.isEmpty() && QFile::exists(path)){ p->setWorkingDirectory(path); }
  p->start(cmd);
  //Check the startup procedure
  /*while(!p->waitForStarted(5000)){
    if(p->state() == QProcess::NotRunning){
     //bad/invalid start
     qDebug() << "[lumina-open] Application did not start properly:"<<cmd;
     return p->exitCode();
    }else if(p->state() == QProcess::Running){
     //This just missed the "started" signal - continue
     break;
    }
  }*/
  //Now check up on it once every minute until it is finished
  while(!p->waitForFinished(60000)){
    //qDebug() << "[lumina-open] process check:" << p->state();
    if(p->state() != QProcess::Running){ break; } //somehow missed the finished signal
  }
  int retcode = p->exitCode();
  //qDebug() << "[lumina-open] Finished Cmd:" << cmd << retcode << p->exitStatus();

  //if(retcode!=0 ){
  if(p->exitStatus() == QProcess::CrashExit){
    qDebug() << "[lumina-open] Application Error:" << retcode;
    QString err = QString(p->readAllStandardError());
    if(err.isEmpty()){ err = QString(p->readAllStandardOutput()); }
    //Setup the application
    QApplication App(argc, argv);
    LuminaThemeEngine theme(&App);
	LUtils::LoadTranslation(&App,"lumina-open");
    QMessageBox dlg(QMessageBox::Critical, QObject::tr("Application Error"), QObject::tr("The following application experienced an error and needed to close:")+"\n\n"+cmd );
    if(!err.isEmpty()){ dlg.setDetailedText(err); }
    dlg.exec();
  }
  return retcode;
}
<commit_msg>Add a new error dialog to lumina-open so that there is a graphical notification if the input file could not be used for some reason.<commit_after>//===========================================
//  Lumina-DE source code
//  Copyright (c) 2012, Ken Moore
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================

#include <QApplication>
#include <QX11Info>
#include <QProcess>
#include <QProcessEnvironment>
#include <QFile>
#include <QFileInfo>
#include <QString>
#include <QUrl>
#include <QDebug>
#include <QTranslator>
//#include <QLocale>
#include <QMessageBox>
#include <QSplashScreen>
#include <QDateTime>
#include <QPixmap>
#include <QColor>
#include <QFont>
//#include <QTextCodec>

#include "LFileDialog.h"

#include <LuminaXDG.h>
#include <LuminaUtils.h>
#include <LuminaOS.h>
#include <LuminaThemes.h>

void printUsageInfo(){
  qDebug() << "lumina-open: Application launcher for the Lumina Desktop Environment";
  qDebug() << "Description: Given a file (with absolute path) or URL, this utility will try to find the appropriate application with which to open the file. If the file is a *.desktop application shortcut, it will just start the application appropriately. It can also perform a few specific system operations if given special flags.";
  qDebug() << "Usage: lumina-open [-select] <absolute file path or URL>";
  qDebug() << "           lumina-open [-volumeup, -volumedown, -brightnessup, -brightnessdown]";
  qDebug() << "  [-select] (optional) flag to bypass any default application settings and show the application selector window";
  qDebug() << "Special Flags:";
  qDebug() << " \"-volume[up/down]\" Flag to increase/decrease audio volume by 5%";
  qDebug() << " \"-brightness[up/down]\" Flag to increase/decrease screen brightness by 5%";
  exit(1);
}

void ShowErrorDialog(int argc, char **argv, QString message){
    //Setup the application
    QApplication App(argc, argv);
    LuminaThemeEngine theme(&App);
	LUtils::LoadTranslation(&App,"lumina-open");
    QMessageBox dlg(QMessageBox::Critical, QObject::tr("File Error"), message );
    dlg.exec();
    exit(1);
}

void showOSD(int argc, char **argv, QString message){
  //Setup the application
  QApplication App(argc, argv);
    LUtils::LoadTranslation(&App,"lumina-open");

  //Display the OSD
  QPixmap pix(":/icons/OSD.png");
  QSplashScreen splash(pix, Qt::SplashScreen | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
     splash.setWindowTitle("");
     QFont myfont;
	myfont.setBold(true);
	myfont.setPixelSize(13);
	splash.setFont(myfont);
  qDebug() << "Display OSD";
  splash.show();
  //qDebug() << " - show message";
  splash.showMessage(message, Qt::AlignCenter, Qt::white);
  //qDebug() << " - loop";
  QDateTime end = QDateTime::currentDateTime().addMSecs(800);
  while(QDateTime::currentDateTime() < end){ App.processEvents(); }
  splash.hide();
}

QString cmdFromUser(int argc, char **argv, QString inFile, QString extension, QString& path, bool showDLG=false){
    //First check to see if there is a default for this extension
    QString defApp;
    if(extension=="mimetype"){
	//qDebug() << "inFile:" << inFile;
	QStringList matches = LXDG::findAppMimeForFile(inFile, true).split("::::"); //allow multiple matches
	//qDebug() << "Matches:" << matches;
	for(int i=0; i<matches.length(); i++){
	  defApp = LXDG::findDefaultAppForMime(matches[i]);
	  if(!defApp.isEmpty()){ extension = matches[i]; break; }
	  else if(i+1==matches.length()){ extension = matches[0]; }
	}
    }else{ defApp = LFileDialog::getDefaultApp(extension); }

    if( !defApp.isEmpty() && !showDLG ){
      bool ok = false;
      if(defApp.endsWith(".desktop")){
        XDGDesktop DF = LXDG::loadDesktopFile(defApp, ok);
        if(ok){
      	  QString exec = LXDG::getDesktopExec(DF);
      	  if(!exec.isEmpty()){
      	    qDebug() << "[lumina-open] Using default application:" << DF.name << "File:" << inFile;
            if(!DF.path.isEmpty()){ path = DF.path; }
            return exec;
          }
        }
      }else{
	//Only binary given
	if(LUtils::isValidBinary(defApp)){
	  qDebug() << "[lumina-open] Using default application:" << defApp << "File:" << inFile;
	  return defApp; //just use the binary
	}
      }
      //invalid default - reset it and continue on
      LFileDialog::setDefaultApp(extension, "");
    }
    //Final catch: directory given - no valid default found - use lumina-fm
    if(extension=="directory" && !showDLG){ return "lumina-fm"; }
    //No default set -- Start up the application selection dialog
    QApplication App(argc, argv);
    LuminaThemeEngine theme(&App);
      LUtils::LoadTranslation(&App,"lumina-open");

    LFileDialog w;
    if(extension=="email" || extension=="webbrowser"){
      //URL
      w.setFileInfo(inFile, extension, false);
    }else{
      //File
      if(inFile.endsWith("/")){ inFile.chop(1); }
      w.setFileInfo(inFile.section("/",-1), extension, true);
    }

    w.show();
    App.exec();
    if(!w.appSelected){ return ""; }
    //Return the run path if appropriate
    if(!w.appPath.isEmpty()){ path = w.appPath; }
    //Just do the default application registration here for now
    //  might move it to the runtime phase later after seeing that the app has successfully started
    if(w.setDefault){
      if(!w.appFile.isEmpty()){ LFileDialog::setDefaultApp(extension, w.appFile); }
      else{ LFileDialog::setDefaultApp(extension, w.appExec); }
    }else{ LFileDialog::setDefaultApp(extension, ""); }
    //Now return the resulting application command
    return w.appExec;
}

void getCMD(int argc, char ** argv, QString& binary, QString& args, QString& path){
  //Get the input file
    //Make sure to load the proper system encoding first
    LUtils::LoadTranslation(0,""); //bypass application modification
  QString inFile;
  bool showDLG = false; //flag to bypass any default application setting
  if(argc > 1){
    for(int i=1; i<argc; i++){
      if(QString(argv[i]).simplified() == "-select"){
      	showDLG = true;
      }else if(QString(argv[i]).simplified() == "-volumeup"){
	int vol = LOS::audioVolume()+5; //increase 5%
	if(vol>100){ vol=100; }
	LOS::setAudioVolume(vol);
	showOSD(argc,argv, QString(QObject::tr("Audio Volume %1%")).arg(QString::number(vol)) );
	return;
      }else if(QString(argv[i]).simplified() == "-volumedown"){
	int vol = LOS::audioVolume()-5; //decrease 5%
	if(vol<0){ vol=0; }
	LOS::setAudioVolume(vol);
	showOSD(argc,argv, QString(QObject::tr("Audio Volume %1%")).arg(QString::number(vol)) );
	return;
      }else if(QString(argv[i]).simplified() == "-brightnessup"){
	int bright = LOS::ScreenBrightness();
	if(bright > 0){ //brightness control available
	  bright = bright+5; //increase 5%
	  if(bright>100){ bright = 100; }
	  LOS::setScreenBrightness(bright);
	  showOSD(argc,argv, QString(QObject::tr("Screen Brightness %1%")).arg(QString::number(bright)) );
	}
	return;
      }else if(QString(argv[i]).simplified() == "-brightnessdown"){
	int bright = LOS::ScreenBrightness();
	if(bright > 0){ //brightness control available
	  bright = bright-5; //decrease 5%
	  if(bright<0){ bright = 0; }
	  LOS::setScreenBrightness(bright);
	  showOSD(argc,argv, QString(QObject::tr("Screen Brightness %1%")).arg(QString::number(bright)) );
	}
	return;
      }else{
        inFile = QString::fromLocal8Bit(argv[i]);
        break;
      }
    }
  }else{
    printUsageInfo();
  }
  //Make sure that it is a valid file/URL
  bool isFile=false; bool isUrl=false;
  if(QFile::exists(inFile)){ isFile=true; }
  else if(QFile::exists(QDir::currentPath()+"/"+inFile)){isFile=true; inFile = QDir::currentPath()+"/"+inFile;} //account for relative paths
  else if(QUrl(inFile).isValid() && !inFile.startsWith("/") ){ isUrl=true; }
  if( !isFile && !isUrl ){ ShowErrorDialog( argc, argv, QString(QObject::tr("Invalid file or URL: %1")).arg(inFile) ); }
  //Determing the type of file (extension)
  QString extension;
  //qDebug() << "File Type:" << isFile << isUrl;
  if(isFile){
    QFileInfo info(inFile);
    extension=info.suffix();
    //qDebug() << " - Extension:" << extension;
    if(info.isDir()){ extension="directory"; }
    else if(info.isExecutable() && extension.isEmpty()){ extension="binary"; }
    else if(extension!="desktop"){ extension="mimetype"; } //flag to check for mimetype default based on file
  }
  else if(isUrl && inFile.startsWith("mailto:")){ extension = "email"; }
  else if(isUrl){ extension = "webbrowser"; }
  //qDebug() << "Input:" << inFile << isFile << isUrl << extension;
  //if not an application  - find the right application to open the file
  QString cmd;
  bool useInputFile = false;
  if(extension=="desktop" && !showDLG){
    bool ok = false;
    XDGDesktop DF = LXDG::loadDesktopFile(inFile, ok);
    if(!ok){
      ShowErrorDialog( argc, argv, QString(QObject::tr("File could not be opened: %1")).arg(inFile) );
    }
    switch(DF.type){
      case XDGDesktop::APP:
        if(!DF.exec.isEmpty()){
          cmd = LXDG::getDesktopExec(DF);
          if(!DF.path.isEmpty()){ path = DF.path; }
        }else{
	  ShowErrorDialog( argc, argv, QString(QObject::tr("Application shortcut is missing the launching information (malformed shortcut): %1")).arg(inFile) );
        }
        break;
      case XDGDesktop::LINK:
        if(!DF.url.isEmpty()){
          //This is a URL - so adjust the input variables appropriately
          inFile = DF.url;
          cmd.clear();
          extension = inFile.section(":",0,0);
        }else{
	  ShowErrorDialog( argc, argv, QString(QObject::tr("URL shortcut is missing the URL: %1")).arg(inFile) );
        }
        break;
      case XDGDesktop::DIR:
        if(!DF.path.isEmpty()){
          //This is a directory link - adjust inputs
          inFile = DF.path;
          cmd.clear();
          extension = "directory";
        }else{
	  ShowErrorDialog( argc, argv, QString(QObject::tr("Directory shortcut is missing the path to the directory: %1")).arg(inFile) );
        }
        break;
      default:
	ShowErrorDialog( argc, argv, QString(QObject::tr("Unknown type of shortcut : %1")).arg(inFile) );
    }
  }
  if(cmd.isEmpty()){
    if(extension=="binary"){ cmd = inFile; }
    else{
    //Find out the proper application to use this file/directory
    useInputFile=true;
    cmd = cmdFromUser(argc, argv, inFile, extension, path, showDLG);
    if(cmd.isEmpty()){ return; }
    }
  }
  //Now assemble the exec string (replace file/url field codes as necessary)
  if(useInputFile){
    args = inFile; //just to keep them distinct internally
    // NOTE: lumina-open is only designed for a single input file,
    //    so no need to distinguish between the list codes (uppercase)
    //    and the single-file codes (lowercase)
    if(isFile && (cmd.contains("%f") || cmd.contains("%F") ) ){
      cmd.replace("%f","\""+inFile+"\"");
      cmd.replace("%F","\""+inFile+"\"");
    }else if(isUrl && (cmd.contains("%U") || cmd.contains("%u")) ){
      cmd.replace("%u","\""+inFile+"\"");
      cmd.replace("%U","\""+inFile+"\"");
    }else{
      //No field codes (or improper field codes given - which is quite common)
      // - Just tack the input file on the end and let the app handle it as necessary
      cmd.append(" \""+inFile+"\"");
    }
  }
  //qDebug() << "Found Command:" << cmd << "Extension:" << extension;
  //Clean up any leftover "Exec" field codes (should have already been replaced earlier)
  if(cmd.contains("%")){cmd = cmd.remove("%U").remove("%u").remove("%F").remove("%f").remove("%i").remove("%c").remove("%k").simplified(); }
  binary = cmd; //pass this string to the calling function

}

int main(int argc, char **argv){
  //Run all the actual code in a separate function to have as little memory usage
  //  as possible aside from the main application when running

  //Make sure the XDG environment variables exist first
  LXDG::setEnvironmentVars();
  //now get the command
  QString cmd, args, path;
  getCMD(argc, argv, cmd, args, path);
  //qDebug() << "Run CMD:" << cmd << args;
  //Now run the command (move to execvp() later?)
  if(cmd.isEmpty()){ return 0; } //no command to run (handled internally)
  //if(!args.isEmpty()){ cmd.append(" "+args+""); }
  //int retcode = system( cmd.toUtf8() );
  qDebug() << "[lumina-open] Running Cmd:" << cmd;
  QProcess *p = new QProcess();
  p->setProcessEnvironment(QProcessEnvironment::systemEnvironment());
  if(!path.isEmpty() && QFile::exists(path)){ p->setWorkingDirectory(path); }
  p->start(cmd);
  //Check the startup procedure
  /*while(!p->waitForStarted(5000)){
    if(p->state() == QProcess::NotRunning){
     //bad/invalid start
     qDebug() << "[lumina-open] Application did not start properly:"<<cmd;
     return p->exitCode();
    }else if(p->state() == QProcess::Running){
     //This just missed the "started" signal - continue
     break;
    }
  }*/
  //Now check up on it once every minute until it is finished
  while(!p->waitForFinished(60000)){
    //qDebug() << "[lumina-open] process check:" << p->state();
    if(p->state() != QProcess::Running){ break; } //somehow missed the finished signal
  }
  int retcode = p->exitCode();
  //qDebug() << "[lumina-open] Finished Cmd:" << cmd << retcode << p->exitStatus();

  //if(retcode!=0 ){
  if(p->exitStatus() == QProcess::CrashExit){
    qDebug() << "[lumina-open] Application Error:" << retcode;
    QString err = QString(p->readAllStandardError());
    if(err.isEmpty()){ err = QString(p->readAllStandardOutput()); }
    //Setup the application
    QApplication App(argc, argv);
    LuminaThemeEngine theme(&App);
	LUtils::LoadTranslation(&App,"lumina-open");
    QMessageBox dlg(QMessageBox::Critical, QObject::tr("Application Error"), QObject::tr("The following application experienced an error and needed to close:")+"\n\n"+cmd );
    if(!err.isEmpty()){ dlg.setDetailedText(err); }
    dlg.exec();
  }
  return retcode;
}
<|endoftext|>


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

#include "config.h"

#if ENABLE(SVG)
#include "SVGPaintServerSolid.h"

#include "GraphicsContext.h"
#include "RenderPath.h"
#include "SkiaSupport.h"

#include <SkPaintContext.h>
#include "SkiaUtils.h"

namespace WebCore {

// TODO(jhaas): probably there's already an implementation of this somewhere; find it
  inline int FloatAlphaToInt(float alpha) { return std::min(0xFF, std::max(0, static_cast<int>(alpha * 0xFF))); }

bool SVGPaintServerSolid::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const
{
    const RenderStyle* style = object ? object->style() : NULL;
    const SVGRenderStyle* svgStyle = style ? style->svgStyle() : NULL;

    int red = color().red();
    int green = color().green();
    int blue = color().blue();
    int alpha = color().alpha();

    if ((type & ApplyToFillTargetType) && (!svgStyle || svgStyle->hasFill())) {
        if (svgStyle) {
            alpha = FloatAlphaToInt(svgStyle->fillOpacity());
            context->setFillRule(svgStyle->fillRule());
        }

        if (isPaintingText)
            context->setTextDrawingMode(cTextFill);

        context->setFillColor(SkColorSetARGB(alpha, red, green, blue));
    }

    if ((type & ApplyToStrokeTargetType) && (!svgStyle || svgStyle->hasStroke())) {
        if (svgStyle) {
            alpha = FloatAlphaToInt(svgStyle->strokeOpacity());
            context->setStrokeColor(SkColorSetARGB(alpha, red, green, blue));
        }

        if (isPaintingText)
            context->setTextDrawingMode(cTextStroke);

        applyStrokeStyleToContext(context, style, object);
    }

    return true;
}

} // namespace WebCore

#endif
<commit_msg>Add missing file from my last checkin moving Skia painting objects around. Review URL: http://codereview.chromium.org/8759<commit_after>// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//    * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//    * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//    * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "config.h"

#if ENABLE(SVG)
#include "SVGPaintServerSolid.h"

#include "GraphicsContext.h"
#include "RenderPath.h"
#include "SkiaSupport.h"

#include "SkiaUtils.h"

namespace WebCore {

// TODO(jhaas): probably there's already an implementation of this somewhere; find it
  inline int FloatAlphaToInt(float alpha) { return std::min(0xFF, std::max(0, static_cast<int>(alpha * 0xFF))); }

bool SVGPaintServerSolid::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const
{
    const RenderStyle* style = object ? object->style() : NULL;
    const SVGRenderStyle* svgStyle = style ? style->svgStyle() : NULL;

    int red = color().red();
    int green = color().green();
    int blue = color().blue();
    int alpha = color().alpha();

    if ((type & ApplyToFillTargetType) && (!svgStyle || svgStyle->hasFill())) {
        if (svgStyle) {
            alpha = FloatAlphaToInt(svgStyle->fillOpacity());
            context->setFillRule(svgStyle->fillRule());
        }

        if (isPaintingText)
            context->setTextDrawingMode(cTextFill);

        context->setFillColor(SkColorSetARGB(alpha, red, green, blue));
    }

    if ((type & ApplyToStrokeTargetType) && (!svgStyle || svgStyle->hasStroke())) {
        if (svgStyle) {
            alpha = FloatAlphaToInt(svgStyle->strokeOpacity());
            context->setStrokeColor(SkColorSetARGB(alpha, red, green, blue));
        }

        if (isPaintingText)
            context->setTextDrawingMode(cTextStroke);

        applyStrokeStyleToContext(context, style, object);
    }

    return true;
}

} // namespace WebCore

#endif
<|endoftext|>


<commit_before>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: securityenvironment_nssimpl.hxx,v $
 * $Revision: 1.8 $
 *
 * 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 _XSECURITYENVIRONMENT_NSSIMPL_HXX_
#define _XSECURITYENVIRONMENT_NSSIMPL_HXX_

#include <sal/config.h>
#include <rtl/ustring.hxx>
#include <cppuhelper/factory.hxx>
#include <cppuhelper/implbase4.hxx>
#include <com/sun/star/uno/Exception.hpp>

#ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_
#include <com/sun/star/uno/Reference.hxx>
#endif
#include <com/sun/star/lang/XSingleServiceFactory.hpp>

#ifndef _COM_SUN_STAR_LANG_XSECVICEINFO_HPP_
#include <com/sun/star/lang/XServiceInfo.hpp>
#endif
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
#include <com/sun/star/security/XCertificate.hpp>
#include <com/sun/star/security/CertificateCharacters.hpp>
#include <com/sun/star/security/CertificateValidity.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>

#include "osl/mutex.hxx"

#include "pk11func.h"
#include "keyhi.h"
#include "certdb.h"
#include "list"

#include "xmlsec/xmlsec.h"

class SecurityEnvironment_NssImpl : public ::cppu::WeakImplHelper4<
    ::com::sun::star::xml::crypto::XSecurityEnvironment ,
    ::com::sun::star::lang::XInitialization ,
    ::com::sun::star::lang::XServiceInfo ,
    ::com::sun::star::lang::XUnoTunnel >
{
private :

    std::list< PK11SlotInfo* > m_Slots;
    typedef std::list< PK11SlotInfo* >::const_iterator CIT_SLOTS;

    osl::Mutex m_mutex;

        CERTCertDBHandle*                   m_pHandler ;
        std::list< PK11SymKey* >            m_tSymKeyList ;
        std::list< SECKEYPublicKey* >       m_tPubKeyList ;
        std::list< SECKEYPrivateKey* >      m_tPriKeyList ;
        ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager ;

    public :
        SecurityEnvironment_NssImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ;
        virtual ~SecurityEnvironment_NssImpl() ;

        //Methods from XSecurityEnvironment

        //Methods from XInitialization
        virtual void SAL_CALL initialize(
            const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments
        ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        //Methods from XServiceInfo
        virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;

        virtual sal_Bool SAL_CALL supportsService(
            const ::rtl::OUString& ServiceName
        ) throw( ::com::sun::star::uno::RuntimeException ) ;

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

        //Helper for XServiceInfo
        static ::com::sun::star::uno::Sequence< ::rtl::OUString > impl_getSupportedServiceNames() ;

        static ::rtl::OUString impl_getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;

        //Helper for registry
        static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL impl_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager ) throw( ::com::sun::star::uno::RuntimeException ) ;

        static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > impl_createFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager ) ;

        virtual ::sal_Int32 SAL_CALL verifyCertificate( const ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate >& xCert ) throw (::com::sun::star::uno::SecurityException, ::com::sun::star::uno::RuntimeException) ;

        virtual ::sal_Int32 SAL_CALL getCertificateCharacters( const ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate >& xCert ) throw (::com::sun::star::uno::SecurityException, ::com::sun::star::uno::RuntimeException) ;

        virtual ::rtl::OUString SAL_CALL getSecurityEnvironmentInformation(  ) throw (::com::sun::star::uno::RuntimeException);

        //Methods from XUnoTunnel
        virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
            throw (::com::sun::star::uno::RuntimeException);

        static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId() ;
        static SecurityEnvironment_NssImpl* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xObj ) ;

        //Native mehtods
        virtual CERTCertDBHandle* getCertDb() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual void setCertDb( CERTCertDBHandle* aCertDb ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual void adoptSymKey( PK11SymKey* aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual void rejectSymKey( PK11SymKey* aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual PK11SymKey* getSymKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual void adoptPubKey( SECKEYPublicKey* aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual void rejectPubKey( SECKEYPublicKey* aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual SECKEYPublicKey* getPubKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual void adoptPriKey( SECKEYPrivateKey* aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual void rejectPriKey( SECKEYPrivateKey* aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual SECKEYPrivateKey* getPriKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > > SAL_CALL getPersonalCertificates() throw(  ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;

        virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL getCertificate( const ::rtl::OUString& issuerName, const ::com::sun::star::uno::Sequence< sal_Int8 >& serialNumber ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;

        virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL getCertificate( const ::rtl::OUString& issuerName, const ::rtl::OUString& serialNumber ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;

        virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > > SAL_CALL buildCertificatePath( const ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate >& beginCert ) throw(  ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;

        virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL createCertificateFromRaw( const ::com::sun::star::uno::Sequence< sal_Int8 >& rawCertificate ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;

        virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL createCertificateFromAscii( const ::rtl::OUString& asciiCertificate ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;

        //Native mehtods
        virtual xmlSecKeysMngrPtr createKeysManager() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
        virtual void destroyKeysManager(xmlSecKeysMngrPtr pKeysMngr) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

private:
        void updateSlots();

          virtual void addCryptoSlot( PK11SlotInfo* aSlot ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

} ;

#endif  // _XSECURITYENVIRONMENT_NSSIMPL_HXX_

<commit_msg>INTEGRATION: CWS cmcfixes48 (1.8.22); FILE MERGED 2008/07/30 09:30:34 cmc 1.8.22.1: #i92277# make this work on 64bit platforms<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: securityenvironment_nssimpl.hxx,v $
 * $Revision: 1.9 $
 *
 * 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 _XSECURITYENVIRONMENT_NSSIMPL_HXX_
#define _XSECURITYENVIRONMENT_NSSIMPL_HXX_

#include <sal/config.h>
#include <rtl/ustring.hxx>
#include <cppuhelper/factory.hxx>
#include <cppuhelper/implbase4.hxx>
#include <com/sun/star/uno/Exception.hpp>

#ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_
#include <com/sun/star/uno/Reference.hxx>
#endif
#include <com/sun/star/lang/XSingleServiceFactory.hpp>

#ifndef _COM_SUN_STAR_LANG_XSECVICEINFO_HPP_
#include <com/sun/star/lang/XServiceInfo.hpp>
#endif
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
#include <com/sun/star/security/XCertificate.hpp>
#include <com/sun/star/security/CertificateCharacters.hpp>
#include <com/sun/star/security/CertificateValidity.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>

#include "osl/mutex.hxx"

#include "pk11func.h"
#include "keyhi.h"
#include "certdb.h"
#include "list"

#include <sal/types.h>
//For reasons that escape me, this is what xmlsec does when size_t is not 4
#if SAL_TYPES_SIZEOFPOINTER != 4
#    define XMLSEC_NO_SIZE_T
#endif
#include "xmlsec/xmlsec.h"

class SecurityEnvironment_NssImpl : public ::cppu::WeakImplHelper4<
    ::com::sun::star::xml::crypto::XSecurityEnvironment ,
    ::com::sun::star::lang::XInitialization ,
    ::com::sun::star::lang::XServiceInfo ,
    ::com::sun::star::lang::XUnoTunnel >
{
private :

    std::list< PK11SlotInfo* > m_Slots;
    typedef std::list< PK11SlotInfo* >::const_iterator CIT_SLOTS;

    osl::Mutex m_mutex;

        CERTCertDBHandle*                   m_pHandler ;
        std::list< PK11SymKey* >            m_tSymKeyList ;
        std::list< SECKEYPublicKey* >       m_tPubKeyList ;
        std::list< SECKEYPrivateKey* >      m_tPriKeyList ;
        ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager ;

    public :
        SecurityEnvironment_NssImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ;
        virtual ~SecurityEnvironment_NssImpl() ;

        //Methods from XSecurityEnvironment

        //Methods from XInitialization
        virtual void SAL_CALL initialize(
            const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments
        ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        //Methods from XServiceInfo
        virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;

        virtual sal_Bool SAL_CALL supportsService(
            const ::rtl::OUString& ServiceName
        ) throw( ::com::sun::star::uno::RuntimeException ) ;

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

        //Helper for XServiceInfo
        static ::com::sun::star::uno::Sequence< ::rtl::OUString > impl_getSupportedServiceNames() ;

        static ::rtl::OUString impl_getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;

        //Helper for registry
        static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL impl_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager ) throw( ::com::sun::star::uno::RuntimeException ) ;

        static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > impl_createFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager ) ;

        virtual ::sal_Int32 SAL_CALL verifyCertificate( const ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate >& xCert ) throw (::com::sun::star::uno::SecurityException, ::com::sun::star::uno::RuntimeException) ;

        virtual ::sal_Int32 SAL_CALL getCertificateCharacters( const ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate >& xCert ) throw (::com::sun::star::uno::SecurityException, ::com::sun::star::uno::RuntimeException) ;

        virtual ::rtl::OUString SAL_CALL getSecurityEnvironmentInformation(  ) throw (::com::sun::star::uno::RuntimeException);

        //Methods from XUnoTunnel
        virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
            throw (::com::sun::star::uno::RuntimeException);

        static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId() ;
        static SecurityEnvironment_NssImpl* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xObj ) ;

        //Native mehtods
        virtual CERTCertDBHandle* getCertDb() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual void setCertDb( CERTCertDBHandle* aCertDb ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual void adoptSymKey( PK11SymKey* aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual void rejectSymKey( PK11SymKey* aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual PK11SymKey* getSymKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual void adoptPubKey( SECKEYPublicKey* aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual void rejectPubKey( SECKEYPublicKey* aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual SECKEYPublicKey* getPubKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual void adoptPriKey( SECKEYPrivateKey* aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual void rejectPriKey( SECKEYPrivateKey* aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual SECKEYPrivateKey* getPriKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

        virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > > SAL_CALL getPersonalCertificates() throw(  ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;

        virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL getCertificate( const ::rtl::OUString& issuerName, const ::com::sun::star::uno::Sequence< sal_Int8 >& serialNumber ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;

        virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL getCertificate( const ::rtl::OUString& issuerName, const ::rtl::OUString& serialNumber ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;

        virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > > SAL_CALL buildCertificatePath( const ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate >& beginCert ) throw(  ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;

        virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL createCertificateFromRaw( const ::com::sun::star::uno::Sequence< sal_Int8 >& rawCertificate ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;

        virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL createCertificateFromAscii( const ::rtl::OUString& asciiCertificate ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;

        //Native mehtods
        virtual xmlSecKeysMngrPtr createKeysManager() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
        virtual void destroyKeysManager(xmlSecKeysMngrPtr pKeysMngr) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

private:
        void updateSlots();

          virtual void addCryptoSlot( PK11SlotInfo* aSlot ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;

} ;

#endif  // _XSECURITYENVIRONMENT_NSSIMPL_HXX_

<|endoftext|>