Example #1
0
// QtPluginIconPalletTool Interface
void
dmz::QtPluginIconPalletTool::_add_type (const ObjectType &Type) {

   const String IconResource = config_to_string (
      get_plugin_name () + ".resource",
      Type.get_config());

   const String IconName = _rc.find_file (IconResource);

   if (IconName) {

      const String Name = Type.get_name ();

      if (Name) {

         QImage back (
            (int)_iconExtent,
            (int)_iconExtent,
            QImage::Format_ARGB32_Premultiplied);
         QPainter painter (&back);
         painter.setCompositionMode (QPainter::CompositionMode_Source);
         painter.fillRect (back.rect (), Qt::transparent);
         painter.setCompositionMode (QPainter::CompositionMode_SourceOver);
         QSvgRenderer qsr (QString (IconName.get_buffer ()));
         QRectF size = qsr.viewBoxF ();
         qreal width = size.width ();
         qreal height = size.height ();
         qreal scale = (width > height) ? width : height;
         if (scale <= 0.0f) { scale = 1.0f; }
         scale = _iconExtent / scale;
         width *= scale;
         height *= scale;
         size.setWidth (width);
         size.setHeight (height);
         if (height < _iconExtent) { size.moveTop ((_iconExtent - height) * 0.5f); }
         if (width < _iconExtent) { size.moveLeft ((_iconExtent - width) * 0.5f); }
         qsr.render (&painter, size);
         painter.end ();
         QIcon icon;
         icon.addPixmap (QPixmap::fromImage (back));
         QStandardItem *item = new QStandardItem (icon, Name.get_buffer ());
         item->setEditable (false);
         _model.appendRow (item);
      }
   }
   else if (IconResource) {

      _log.error << "Unable to find icon resource: " << IconResource
          << " for object type: " << Type.get_name () << endl;
   }

   RuntimeIterator it;
   ObjectType next;

   while (Type.get_next_child (it, next)) { _add_type (next); }
}
dmz::Boolean
dmz::ReaderZip::open_file (const String &FileName) {

   Boolean result (False);

   if (_state.zf) {

      close_file ();

      result = _state.zip_error (unzLocateFile (
         _state.zf,
         FileName.get_buffer (),
         1)); // Case sensitive

      if (result) {

         result = _state.zip_error (unzOpenCurrentFile (_state.zf));

         if (result) { _state.fileName = FileName; }
      }
   }
   else { _state.error.flush () << "Zip archive not open."; }

   return result;
}
QGraphicsItem *
dmz::QtPluginCanvasObjectBasic::_create_image_item (
      ObjectStruct &os,
      QGraphicsItem *parent,
      const Config &Data,
      HashTableStringTemplate<String> &table) {

   QGraphicsItem *item (0);

   String fileName = config_to_string ("resource", Data);
   String *repName = table.lookup (fileName);

   const String File = _rc.find_file (repName ? *repName : fileName).to_lower ();
   QFileInfo fi (File.get_buffer ());

   if (fi.suffix () == QLatin1String ("svg")) {

      item = _create_svg_item (os, parent, Data, table);
   }
   else {

      item = _create_pixmap_item (os, parent, Data, table);
   }

   return item;
}
void
dmz::QtPluginCanvasObjectBasic::update_object_text (
      const UUID &Identity,
      const Handle ObjectHandle,
      const Handle AttributeHandle,
      const String &Value,
      const String *PreviousValue) {

   ObjectStruct *os (_objectTable.lookup (ObjectHandle));
   if (os) {

      QtCanvasObjectTextTable *textTable (os->textTable.lookup (AttributeHandle));

      if (textTable) {

         HashTableStringIterator it;
         QtCanvasObjectText *item (textTable->get_first (it));

         while (item) {

            item->set_text (Value.get_buffer ());
            item = textTable->get_next (it);
         }
      }
   }
}
Example #5
0
dmz::RenderPluginObjectOSG::ModelStruct *
dmz::RenderPluginObjectOSG::_load_model (const String &ResourceName) {

   ModelStruct *result (0);
   String foundFile (_rc.find_file (ResourceName));

   if (foundFile) {

      result = _modelTable.lookup (foundFile);

      if (!result) {

         result = new ModelStruct;
         result->model = osgDB::readNodeFile (foundFile.get_buffer ());

         if (result->model.valid ()) {

            osgUtil::Optimizer optimizer;
            optimizer.optimize(result->model.get());

            osg::Node::DescriptionList &list = result->model->getDescriptions ();

            String str ("<dmz><render><resource name=\"");
            str << ResourceName << "\"/></render></dmz>";
            list.push_back (str.get_buffer ());

            _log.info << "Loaded file: " << foundFile << " (" << ResourceName << ")"
               << endl;
            _modelTable.store (foundFile, result);
         }
         else {

            delete result; result = 0;
            _log.error << "Failed loading file: " << foundFile << " (" << ResourceName
               << ")" << endl;
         }
      }
   }

   return result;
}
// Object Observer Interface
void
dmz::QtPluginCanvasLink::link_objects (
      const Handle LinkHandle,
      const Handle AttributeHandle,
      const UUID &SuperIdentity,
      const Handle SuperHandle,
      const UUID &SubIdentity,
      const Handle SubHandle) {

   if (_canvasModule) {

      if (_linkAttrTable.lookup (AttributeHandle)) {

         QGraphicsItem *superItem (_canvasModule->lookup_item (SuperHandle));
         QGraphicsItem *subItem (_canvasModule->lookup_item (SubHandle));

         if (superItem && subItem) {

            LinkStruct *os (new LinkStruct (
               LinkHandle,
               AttributeHandle,
               SuperHandle,
               SubHandle,
               _penWidth,
               _arrowMultiplier));

            if (_linkTable.store (LinkHandle, os)) {

               Float32 minZ (qMin (superItem->zValue (), subItem->zValue ()));

               os->item->setZValue (minZ - 1.0f);

               String name ("Link");
               name << "." << AttributeHandle << "." << LinkHandle;

               os->item->setData (QtCanvasObjectNameIndex, name.get_buffer ());

               _store_edge (SuperHandle, os->item);
               _store_edge (SubHandle, os->item);

               _canvasModule->add_item (LinkHandle, os->item);

               QGraphicsItem *superParent = superItem->parentItem ();
               if (superParent) { os->item->setParentItem (superParent); }
            }
            else { delete os; os = 0; }
         }
      }
   }
}
/*!

\ingroup Foundation
\brief Converts an XML file to a config context tree.
\details Defined in dmzFoundationXMLUtil.h.
\param[in] FileName String containing name of XML file to parse.
\param[out] data Config object to store parsed XML data.
\param[in] log Pointer to Log for streaming log messages.
\return Returns dmz::True if the XML file was successfully parsed.
\sa dmz::Config \n dmz::ConfigContext

*/
dmz::Boolean
dmz::xml_to_config (const String &FileName, Config &data, Log *log) {

   if (!data) { Config tmp ("global"); data = tmp; }

   ParserXML parser;
   InterpreterXMLConfig interpreter (data);
   parser.set_interpreter (&interpreter);
   Boolean error (False);

   FILE *file = open_file (FileName, "rb");

   if (file) {

      String buffer;

      while (read_file (file, 1024, buffer) && !error) {

         const Int32 Length = buffer.get_length ();
         const char *cbuf = buffer.get_buffer ();

         if (!parser.parse_buffer (cbuf, Length, Length < 1024)) {

            error = True;

            if (log) {

               log->error << "In file: " << FileName << " : " << parser.get_error ()
                  << endl;
            }
         }
      }

      close_file (file);
   }
   else {

      error = True;

      if (log) {

         log->error << "Unable to open file: " << FileName << endl;
      }
   }

   return !error;
}
/*!

\brief Opens zip archive for reading.
\param[in] FileName String containing name of zip archive to open.
\param[in] Mode Parameter for future functionality.
\return Returns dmz::True if the zip archive was successfully opened.

*/
dmz::Boolean
dmz::ReaderZip::open_zip_file (const String &FileName, const UInt32 Mode) {

   Boolean result (False);

   close_zip_file ();

   _state.zf = unzOpen (FileName.get_buffer ());

   if (_state.zf) {

      _state.zipFileName = FileName;
      result = True;
   }

   return result;
}
/*!

\brief Creates zip archive for writing.
\details Will close any open zip archive before opening a new archive. If a zip archive
already exists with the same name, it will be overwritten.
\param[in] FileName String containing the name of the new zip archive.
\param[in] Mode Parameter for future functionality.
\return Returns dmz::True if the archive was successfully created.

*/
dmz::Boolean
dmz::WriterZip::open_zip_file (const String &FileName, const UInt32 Mode) {

   Boolean result (False);

   close_zip_file ();

   _state.zf = zipOpen (FileName.get_buffer (), APPEND_STATUS_CREATE);

   if (_state.zf) {

      _state.zipFileName = FileName;
      result = True;
   }

   return result;
}
dmz::Boolean
dmz::WriterZip::open_file (const String &FileName) {

   Boolean result (False);

   if (_state.zf) {

      close_file ();

      zip_fileinfo zinfo;

      zinfo.tmz_date.tm_sec = zinfo.tmz_date.tm_min = zinfo.tmz_date.tm_hour =
      zinfo.tmz_date.tm_mday = zinfo.tmz_date.tm_min = zinfo.tmz_date.tm_year = 0;
      zinfo.dosDate = 0;
      zinfo.internal_fa = 0;
      zinfo.external_fa = 0;

      time_t tm = time (0);

      struct tm *tms = localtime (&tm);

      if (tms) {

         zinfo.tmz_date.tm_sec  = tms->tm_sec;
         zinfo.tmz_date.tm_min  = tms->tm_min;
         zinfo.tmz_date.tm_hour = tms->tm_hour;
         zinfo.tmz_date.tm_mday = tms->tm_mday;
         zinfo.tmz_date.tm_mon  = tms->tm_mon;
         zinfo.tmz_date.tm_year = tms->tm_year + 1900;
      }

      result = _state.zip_error (zipOpenNewFileInZip (
         _state.zf,
         FileName.get_buffer (),
         &zinfo,
         0, 0, 0, 0, 0, // No comments
         Z_DEFLATED,
         _state.level));

      if (result) { _state.fileName = FileName; }
   }
   else { _state.error.flush () << "Zip archive not open."; }

   return result;
}
Example #11
0
/*!

\brief Read a block of data and store it in a String.
\ingroup System
\details Defined in dmzSystemFile.h.
Attempts to read \a Size number of bytes from \a File and store them in \a buffer.
\param[in] File C FILE * to read from.
\param[in] Size Size of data to attempt to read from \a File.
\param[out] buffer String to store read data in.
\return Returns dmz::True if any data was read.

*/
dmz::Int32
dmz::read_file (const FILE *File, const Int32 Size, String &buffer) {

    Int32 result (0);

    if (Size > 0) {

        buffer.set_buffer (0, Size + 1);

        if (buffer.get_size () >= Size) {

            result = fread ((void *)buffer.get_buffer (), sizeof (char), Size, (FILE *)File);
            buffer.set_length (result);
        }
    }

    return result;
}
Example #12
0
/*!

\ingroup Foundation
\brief Converts an XML String to a config context tree.
\details Defined in dmzFoundationXMLUtil.h.
\param[in] Value String containing the XML  to parse.
\param[out] data Config object to store parsed XML data.
\param[in] log Pointer to Log for streaming log messages.
\return Returns dmz::True if the XML was successfully parsed.
\sa dmz::Config \n dmz::ConfigContext

*/
dmz::Boolean
dmz::xml_string_to_config (const String &Value, Config &data, Log *log) {

   ParserXML parser;
   InterpreterXMLConfig interpreter (data);
   parser.set_interpreter (&interpreter);
   Boolean error (False);

   if (!parser.parse_buffer (Value.get_buffer (), Value.get_length (), True)) {

      error = True;

      if (log) {

         log->error << "Error parsing: " << endl << "\t"
            << Value << endl << "\t" << parser.get_error () << endl;
      }
   }

   return !error;
}
Example #13
0
Error EditorExportPlatformBB10::export_project(const String& p_path, bool p_debug, int p_flags) {


	EditorProgress ep("export","Exporting for BlackBerry 10",104);

	String src_template=custom_package;

	if (src_template=="") {
		String err;
		src_template = find_export_template("bb10.zip", &err);
		if (src_template=="") {
			EditorNode::add_io_error(err);
			return ERR_FILE_NOT_FOUND;
		}
	}

	FileAccess *src_f=NULL;
	zlib_filefunc_def io = zipio_create_io_from_file(&src_f);

	ep.step("Creating FileSystem for BAR",0);

	unzFile pkg = unzOpen2(src_template.utf8().get_data(), &io);
	if (!pkg) {

		EditorNode::add_io_error("Could not find template zip to export:\n"+src_template);
		return ERR_FILE_NOT_FOUND;
	}

	DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
	da->change_dir(EditorSettings::get_singleton()->get_settings_path());


	if (da->change_dir("tmp")!=OK) {
		da->make_dir("tmp");
		if (da->change_dir("tmp")!=OK)
			return ERR_CANT_CREATE;
	}

	if (da->change_dir("bb10_export")!=OK) {
		da->make_dir("bb10_export");
		if (da->change_dir("bb10_export")!=OK) {
			return ERR_CANT_CREATE;
		}
	}


	String bar_dir = da->get_current_dir();
	if (bar_dir.ends_with("/")) {
		bar_dir=bar_dir.substr(0,bar_dir.length()-1);
	}

	//THIS IS SUPER, SUPER DANGEROUS!!!!
	//CAREFUL WITH THIS CODE, MIGHT DELETE USERS HARD DRIVE OR HOME DIR
	//EXTRA CHECKS ARE IN PLACE EVERYWERE TO MAKE SURE NOTHING BAD HAPPENS BUT STILL....
	//BE SUPER CAREFUL WITH THIS PLEASE!!!
	//BLACKBERRY THIS IS YOUR FAULT FOR NOT MAKING A BETTER WAY!!

	bool berr = bar_dir.ends_with("bb10_export");
	if (berr) {
		if (da->list_dir_begin()) {
			EditorNode::add_io_error("Can't ensure that dir is empty:\n"+bar_dir);
			ERR_FAIL_COND_V(berr,FAILED);
		};

		String f = da->get_next();
		while (f != "") {

			if (f == "." || f == "..") {
				f = da->get_next();
				continue;
			};
			Error err = da->remove(bar_dir + "/" + f);
			if (err != OK) {
				EditorNode::add_io_error("Can't ensure that dir is empty:\n"+bar_dir);
				ERR_FAIL_COND_V(err!=OK,err);
			};
			f = da->get_next();
		};

		da->list_dir_end();

	} else {
		print_line("ARE YOU CRAZY??? THIS IS A SERIOUS BUG HERE!!!");
		ERR_FAIL_V(ERR_OMFG_THIS_IS_VERY_VERY_BAD);
	}


	ERR_FAIL_COND_V(!pkg, ERR_CANT_OPEN);
	int ret = unzGoToFirstFile(pkg);



	while(ret==UNZ_OK) {

		//get filename
		unz_file_info info;
		char fname[16384];
		ret = unzGetCurrentFileInfo(pkg,&info,fname,16384,NULL,0,NULL,0);

		String file=fname;

		Vector<uint8_t> data;
		data.resize(info.uncompressed_size);

		//read
		unzOpenCurrentFile(pkg);
		unzReadCurrentFile(pkg,data.ptr(),data.size());
		unzCloseCurrentFile(pkg);

		//write

		if (file=="bar-descriptor.xml") {

			_fix_descriptor(data);
		}

		if (file=="icon.png") {
			bool found=false;

			if (this->icon!="" && this->icon.ends_with(".png")) {

				FileAccess *f = FileAccess::open(this->icon,FileAccess::READ);
				if (f) {

					data.resize(f->get_len());
					f->get_buffer(data.ptr(),data.size());
					memdelete(f);
					found=true;
				}

			}

			if (!found) {

				String appicon = GlobalConfig::get_singleton()->get("application/icon");
				if (appicon!="" && appicon.ends_with(".png")) {
					FileAccess*f = FileAccess::open(appicon,FileAccess::READ);
					if (f) {
						data.resize(f->get_len());
						f->get_buffer(data.ptr(),data.size());
						memdelete(f);
					}
				}
			}
		}


		if (file.find("/")) {

			da->make_dir_recursive(file.get_base_dir());
		}

		FileAccessRef wf = FileAccess::open(bar_dir.plus_file(file),FileAccess::WRITE);
		wf->store_buffer(data.ptr(),data.size());

		ret = unzGoToNextFile(pkg);
	}

	ep.step("Adding Files..",2);

	FileAccess* dst = FileAccess::open(bar_dir+"/data.pck", FileAccess::WRITE);
	if (!dst) {
		EditorNode::add_io_error("Can't copy executable file to:\n "+p_path);
		return ERR_FILE_CANT_WRITE;
	}
	save_pack(dst, false, 1024);
	dst->close();
	memdelete(dst);

	ep.step("Creating BAR Package..",104);

	String bb_packager=EditorSettings::get_singleton()->get("export/blackberry/host_tools");
	bb_packager=bb_packager.plus_file("blackberry-nativepackager");
	if (OS::get_singleton()->get_name()=="Windows")
		bb_packager+=".bat";


	if (!FileAccess::exists(bb_packager)) {
		EditorNode::add_io_error("Can't find packager:\n"+bb_packager);
		return ERR_CANT_OPEN;
	}

	List<String> args;
	args.push_back("-package");
	args.push_back(p_path);
	if (p_debug) {

		String debug_token=EditorSettings::get_singleton()->get("export/blackberry/debug_token");
		if (!FileAccess::exists(debug_token)) {
			EditorNode::add_io_error("Debug token not found!");
		} else {
			args.push_back("-debugToken");
			args.push_back(debug_token);
		}
		args.push_back("-devMode");
		args.push_back("-configuration");
		args.push_back("Device-Debug");
	} else {

		args.push_back("-configuration");
		args.push_back("Device-Release");
	}
	args.push_back(bar_dir.plus_file("bar-descriptor.xml"));

	int ec;

	Error err = OS::get_singleton()->execute(bb_packager,args,true,NULL,NULL,&ec);

	if (err!=OK)
		return err;
	if (ec!=0)
		return ERR_CANT_CREATE;

	return OK;

}
dmz::QtCanvasObjectText *
dmz::QtPluginCanvasObjectBasic::_create_text_item (
      ObjectStruct &os,
      QGraphicsItem *parent,
      const Config &Data) {

   QtCanvasObjectText *item (new QtCanvasObjectText (parent));

   ConfigIterator it;
   Config cd;

   while (Data.get_next_config (it, cd)) {

      const String DataName (cd.get_name ().to_lower ());

      if (DataName == "text") {

         String text (config_to_string (cd));
         item->set_text (text.get_buffer ());
      }
      else if (DataName == "textcolor") {

         item->set_text_color (config_to_qcolor (cd));
      }
      else if (DataName == "outlinecolor") {

         item->set_outline_color (config_to_qcolor (cd));
      }
      else if (DataName == "backgroundcolor") {

         item->set_background_color (config_to_qcolor (cd));
      }
      else if (DataName == "enablebackground") {

         item->enable_background (config_to_boolean ("value", cd, true));
      }
      else if (DataName == "alignment") {

         String alignmentName (config_to_string (cd).to_lower ());
         if (alignmentName == "center") {  item->set_alignment (Qt::AlignCenter); }
         else if (alignmentName == "right") {  item->set_alignment (Qt::AlignRight); }
         else {  item->set_alignment (Qt::AlignLeft); }
      }
      else if (DataName == "max-length") {

         item->set_max_length (config_to_int32 ("value", cd));
      }
      else if (DataName == "translate") {

         Vector vec (config_to_vector (cd));
         String itemName = config_to_string ("name", cd);

         if (itemName) {

            QGraphicsItem *img = os.itemTable.lookup (itemName);
            if (img) {

               QRectF rect = img->boundingRect ();
               Vector rectVec;
               if (vec.get_x () == 0) { rectVec.set_x (0); }
               else if (vec.get_x() > 0) { rectVec.set_x (rect.center ().x ()); }
               else { rectVec.set_x (-rect.center ().x ()); }

               if (vec.get_y () == 0) { rectVec.set_y (0); }
               else if (vec.get_y () > 0) { rectVec.set_y (rect.center ().y ()); }
               else { rectVec.set_y (-rect.center ().y ()); }

               vec += rectVec;
               item->setPos (vec.get_x (), vec.get_y ());
            }
         }
         else { item->translate (vec.get_x (), vec.get_y ()); }
      }
      else if (DataName == "scale") {

         Vector vec (config_to_vector (cd));

         if (vec.get_x () && vec.get_y ()) {

            item->scale (vec.get_x (), vec.get_y ());
         }
      }
   }

   return item;
}
dmz::QtCanvasObjectGroup *
dmz::QtPluginCanvasObjectBasic::_create_item (
      ObjectStruct &os,
      QGraphicsItem *parent,
      const Config &ItemList,
      HashTableStringTemplate<String> &table) {

   QtCanvasObjectGroup *group (0);

   if (parent) {

      group = new QtCanvasObjectGroup (parent);

      QGraphicsItem *item (0);

      ConfigIterator it;
      Config cd;
      Float32 z (1.0);

      while (ItemList.get_next_config (it, cd)) {

         const String DataName (cd.get_name ().to_lower ());
         const String ItemName (config_to_string ("name", cd));
         const Boolean Isect (config_to_boolean ("isect", cd, True));

         if (DataName == "image") {

            item = _create_image_item (os, group, cd, table);

            if (Isect) {

               item->setData (QtCanvasObjectHandleIndex, (quint64)os.ObjHandle);
            }
         }
         else if (DataName == "text") {

            item =  _create_text_item (os, group, cd);

            if (Isect) {

               item->setData (QtCanvasObjectHandleIndex, (quint64)os.ObjHandle);
            }
         }
         else if (DataName == "group") {

            item = _create_item (os, group, cd, table);
         }

         if (item) {

            item->setFlag (QGraphicsItem::ItemIgnoresParentOpacity, true);
            item->setFlag (QGraphicsItem::ItemDoesntPropagateOpacityToChildren, true);

            item->setZValue (z++);

            if (ItemName) {

               String name (ItemName);
               name << "." << os.ObjHandle;

               item->setData (QtCanvasObjectNameIndex, name.get_buffer ());

               os.itemTable.store (ItemName, item);
            }
         }
      }
   }

   return group;
}
dmz::Boolean
dmz::QtPluginCanvasObjectBasic::_file_request (
   QGraphicsItem *item,
   const Config &Data,
   HashTableStringTemplate<String> &table) {

   Boolean result (False);
   String fileName = config_to_string ("resource", Data);
   String *repName = table.lookup (fileName);

   const String Resource (repName ? *repName : fileName);

   if (Resource && item) {

      const String File = _rc.find_file (Resource);

      if (File) {

         QGraphicsPixmapItem *pixmapItem (
            qgraphicsitem_cast<QGraphicsPixmapItem *> (item));

         if (pixmapItem) {

            QPixmap pixmap;

            //_log.info << "Loading pixmap file: " << LocalFilePath << endl;

            if (pixmap.load (File.get_buffer ())) {

               pixmapItem->setPixmap (pixmap);
               result = True;
            }
            else {

               _log.error << "Pixmap failed to load: " << File << endl;
            }
         }

         QGraphicsSvgItem *svgItem (qgraphicsitem_cast<QGraphicsSvgItem *> (item));

         if (svgItem) {

            QSvgRenderer *renderer (
               _svgRendererTable.lookup (File));

            if (!renderer) {

               renderer = new QSvgRenderer ();

               //_log.info << "Loading SVG file: " << LocalFilePath << endl;

               if (renderer->load (QString (File.get_buffer ()))) {

                  _svgRendererTable.store (File, renderer);
               }
               else {

                  _log.error << "SVG failed to load: " << File << endl;
                  delete renderer; renderer = 0;
               }
            }

            if (renderer) {

               svgItem->setSharedRenderer (renderer);
               result = True;
            }
         }
      }
      else {

         _log.error << "Resource not found: " << Resource << endl;
      }
   }
   else {

      _log.error << "Unable to process unknown resource." << endl;
   }

   return result;
}