void Fineline_File_System_Tree::assign_user_icons()
{
  static const char *L_folder_xpm[] = {
      "11 11 3 1",
      ".  c None",
      "x  c #d8d833",
      "@  c #808011",
      "...........",
      ".....@@@@..",
      "....@xxxx@.",
      "@@@@@xxxx@@",
      "@xxxxxxxxx@",
      "@xxxxxxxxx@",
      "@xxxxxxxxx@",
      "@xxxxxxxxx@",
      "@xxxxxxxxx@",
      "@xxxxxxxxx@",
      "@@@@@@@@@@@"};
  static Fl_Pixmap L_folderpixmap(L_folder_xpm);

   static const char *L_document_xpm[] = {
      "11 11 3 1",
      ".  c None",
      "x  c #d8d8f8",
      "@  c #202060",
      ".@@@@@@@@@.",
      ".@xxxxxxx@.",
      ".@xxxxxxx@.",
      ".@xxxxxxx@.",
      ".@xxxxxxx@.",
      ".@xxxxxxx@.",
      ".@xxxxxxx@.",
      ".@xxxxxxx@.",
      ".@xxxxxxx@.",
      ".@xxxxxxx@.",
      ".@@@@@@@@@."};
   static Fl_Pixmap L_documentpixmap(L_document_xpm);

  // Assign user icons to tree items
   for ( Fl_Tree_Item *item = first(); item; item=item->next())
   {
      item->usericon(item->has_children() ? &L_folderpixmap : &L_documentpixmap);
   }

}
Beispiel #2
0
static void scan_object(EdbusConnection *conn, EdbusMessage &msg, const char *service, const char *path, ObjectTree *self) {
	EdbusMessage reply;
	msg.create_method_call(service, path, INTROSPECTABLE_INTERFACE, INTROSPECTABLE_METHOD);

	if(!conn->send_with_reply_and_block(msg, 1000, reply)) {
		E_WARNING(E_STRLOC ": Did not get reply from service bus. Skipping introspection of '%s' service (object path: '%s')\n", service, path);
		return;
	}

	/* reply must be single element and string, which is xml */
	if(reply.size() != 1) {
		E_WARNING(E_STRLOC ": Expected only one element, but got '%i'\n", reply.size());
		return;
	}

	EdbusMessage::const_iterator it = reply.begin();
	if(!it->is_string()) {
		E_WARNING(E_STRLOC ": Expected string in reply, but got some junk\n");
		return;
	}

	TiXmlDocument doc;
	char buf[128];
	Fl_Tree_Item *titem;

	doc.Parse(it->to_string());
	TiXmlNode *el = doc.FirstChild("node");
	if(!el) return;

	for(el = el->FirstChildElement(); el; el = el->NextSibling()) {
		/* we have subobjects */
		if(STR_CMP_VALUE(el, "node")) {
			const char *name = el->ToElement()->Attribute("name");
			if(!name) {
				E_DEBUG(E_STRLOC ": <node> is expected to have 'name' attribute\n");
				continue;
			}

			/* TODO: maybe use EdbusObjectPath? */
			if(strcmp(path, "/") == 0)
				snprintf(buf, sizeof(buf), "/%s", name);
			else
				snprintf(buf, sizeof(buf), "%s/%s", path, name);

			titem = self->add(buf);
			self->close(titem);
			titem->usericon(&image_package);

			/* recurse */
			scan_object(conn, msg, service, buf, self);
		} else if(STR_CMP_VALUE(el, "interface")) {
			/* full interface: get methods and properties */
			const char *interface_name, *name = el->ToElement()->Attribute("name");
			/* remember it for Entity */
			interface_name = name;
			if(!name) {
				E_DEBUG(E_STRLOC ": <interface> is expected to have 'name' attribute\n");
				continue;
			}

			/* append interface to tree */
			snprintf(buf, sizeof(buf), "%s/%s", path, name);
			titem = self->add(buf);
			self->close(titem);
			titem->usericon(&image_interface);

			/* append methods, signals and properties */
			TiXmlNode *sel;
			char buf2[256];
			Fl_Pixmap *icon;
			EntityType et;

			for(sel = el->FirstChildElement(); sel; sel = sel->NextSibling()) {
				if(STR_CMP_VALUE(sel, "method")) {
					icon = &image_method;
					et = ENTITY_METHOD;
				} else if(STR_CMP_VALUE(sel, "signal")) {
					icon = &image_signal;
					et = ENTITY_SIGNAL;
				} else if(STR_CMP_VALUE(sel, "property")) {
					icon = &image_property;
					et = ENTITY_PROPERTY;
				} else {
					E_WARNING(E_STRLOC ": Got unknown node '%s'. Skipping...\n", sel->Value());
					continue;
				}

				/* everything else are common elements between different types */
				name = sel->ToElement()->Attribute("name");
				snprintf(buf2, sizeof(buf2), "%s/%s", buf, name);
				titem = self->add(buf2);
				titem->usericon(icon);
				self->close(titem);

				/* fill our metadata */
				Entity *en = new Entity();
				en->set_type(et);
				en->set_name(name);
				en->set_interface(interface_name);
				en->set_path(path);

				/* TODO: this doesn't have to be copied */
				en->set_service(service);

				if(et == ENTITY_PROPERTY) {
					const char *argstype, *argsname, *argsaccess;
					argstype = sel->ToElement()->Attribute("type");
					argsname = sel->ToElement()->Attribute("name");
					argsaccess = sel->ToElement()->Attribute("access");

					en->append_arg(argsname, argstype, DIRECTION_NONE, argsaccess);
				} else {
					TiXmlNode *argsnode;
					for(argsnode = sel->FirstChildElement(); argsnode; argsnode = argsnode->NextSibling()) {
						if(STR_CMP_VALUE(argsnode, "arg")) {
							/* arguments */
							const char *argstype, *argsname, *argsdirection;
							ArgDirection dir = DIRECTION_NONE;

							argstype = argsnode->ToElement()->Attribute("type");
							if(!argstype) continue;

							argsname = argsnode->ToElement()->Attribute("name");
							if(!argsname) continue;

							/* it is fine to not have direction, which means it is only a method */
							argsdirection = argsnode->ToElement()->Attribute("direction");
							if(argsdirection) {
								if(STR_CMP(argsdirection, "in"))
									dir = DIRECTION_IN;
								else if(STR_CMP(argsdirection, "out"))
									dir = DIRECTION_OUT;
							}

							en->append_arg(argsname, argstype, dir);
						} else if(STR_CMP_VALUE(argsnode, "annotation")) {
							const char *annoname, *argsval;

							annoname = argsnode->ToElement()->Attribute("name");
							/* allow whatever annotation name ending with '.DocString' to be supported (e.g. org.gtk.GDBus.DocString or org.equinoxproject.DBus.DocString) */
							if(!str_ends(annoname, ".DocString")) {
								E_WARNING(E_STRLOC ": We are supporting now only DocString annotations. Skipping '%s'...\n", annoname);
								continue;
							}

							argsval = argsnode->ToElement()->Attribute("value");
							if(argsval) en->set_doc(argsval);
						}
					}
				}

				/* put it inside our tree so we can manage it */
				self->append_entity(en);
				/* add also inside Fl_Tree_Item */
				titem->user_data(en);
			}
		}
	}
}