/*************************************************************************
    Sample specific initialisation goes here.
*************************************************************************/
bool TreeDemoSample::initialiseSample()
   {
   using namespace CEGUI;
   Tree *      theTree;
   TreeItem *  newTreeCtrlEntryLvl1;  // Level 1 TreeCtrlEntry (branch)
   TreeItem *  newTreeCtrlEntryLvl2;  // Level 2 TreeCtrlEntry (branch)
   TreeItem *  newTreeCtrlEntryLvl3;  // Level 3 TreeCtrlEntry (branch)
   TreeItem *  newTreeCtrlEntryParent;
   Image *     iconArray[9];

#if defined( __WIN32__ ) || defined( _WIN32 )
   // Windows specific code.
   srand(time(NULL));
#endif

   // Get window manager which we will use for a few jobs here.
   WindowManager& winMgr = WindowManager::getSingleton();

//   CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Standard);
//   CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);
   CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Insane);

   // Load the scheme to initialise the skin which we use in this sample
   SchemeManager::getSingleton().create(SCHEME_FILE_NAME);

   // set default mouse image
   System::getSingleton().setDefaultMouseCursor(IMAGES_FILE_NAME, "MouseArrow");

   // load an image to use as a background
   ImagesetManager::getSingleton().createFromImageFile("BackgroundImage", "GPN-2000-001437.tga");

   // Load some icon images for our test tree
  // Imageset *iconImages = ImagesetManager::getSingleton().create("TreeIcons.imageset");
   Imageset& drives = ImagesetManager::getSingleton().create("DriveIcons.imageset");

   // here we will use a StaticImage as the root, then we can use it to place a background image
   Window* background = winMgr.createWindow(STATICIMAGE_NAME);

   // set area rectangle
   background->setArea(URect(cegui_reldim(0), cegui_reldim(0), cegui_reldim(1), cegui_reldim(1)));
   // disable frame and standard background
   background->setProperty("FrameEnabled", "false");
   background->setProperty("BackgroundEnabled", "false");
   // set the background image
   background->setProperty("Image", "set:BackgroundImage image:full_image");
   // install this as the root GUI sheet
   System::getSingleton().setGUISheet(background);

//   CEGUI::System::getSingleton().setTooltip(TOOLTIP_NAME);

    FontManager::getSingleton().create("DejaVuSans-10.font");
//	if(!FontManager::getSingleton().isFontPresent("Commonwealth-10"))
//		FontManager::getSingleton().createFont("Commonwealth-10.font");


   TreeDemoWindow = winMgr.loadWindowLayout(LAYOUT_FILE_NAME);

   background->addChildWindow(TreeDemoWindow);

   // listen for key presses on the root window.
   background->subscribeEvent(Window::EventKeyDown, Event::Subscriber(&TreeDemoSample::handleRootKeyDown, this));

   theTree = (Tree *)TreeDemoWindow->getChild(TreeID);
   theTree->initialise();
   theTree->subscribeEvent(Tree::EventSelectionChanged, Event::Subscriber(&TreeDemoSample::handleEventSelectionChanged, this));
   theTree->subscribeEvent(Tree::EventBranchOpened, Event::Subscriber(&TreeDemoSample::handleEventBranchOpened, this));
   theTree->subscribeEvent(Tree::EventBranchClosed, Event::Subscriber(&TreeDemoSample::handleEventBranchClosed, this));

   // activate the background window
   background->activate();

   Imageset& iconImages = drives;
   iconArray[0] = (Image *)&iconImages.getImage("Artic");
   iconArray[1] = (Image *)&iconImages.getImage("Black");
   iconArray[2] = (Image *)&iconImages.getImage("Sunset");
   iconArray[3] = (Image *)&iconImages.getImage("DriveStack");
   iconArray[4] = (Image *)&iconImages.getImage("GlobalDrive");
   iconArray[5] = (Image *)&iconImages.getImage("Blue");
   iconArray[6] = (Image *)&iconImages.getImage("Lime");
   iconArray[7] = (Image *)&iconImages.getImage("Silver");
   iconArray[8] = (Image *)&iconImages.getImage("GreenCandy");

   // Create a top-most TreeCtrlEntry
   newTreeCtrlEntryLvl1 = new TreeItem("Tree Item Level 1a");
   newTreeCtrlEntryLvl1->setIcon(drives.getImage("Black"));
   newTreeCtrlEntryLvl1->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
//   newTreeCtrlEntryLvl1->setUserData((void *)someData);
   theTree->addItem(newTreeCtrlEntryLvl1);
   // Create a second-level TreeCtrlEntry and attach it to the top-most TreeCtrlEntry
   newTreeCtrlEntryLvl2 = new TreeItem("Tree Item Level 2a (1a)");
   newTreeCtrlEntryLvl2->setIcon(drives.getImage("Artic"));
   newTreeCtrlEntryLvl2->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
   newTreeCtrlEntryLvl1->addItem(newTreeCtrlEntryLvl2);
   // Create a third-level TreeCtrlEntry and attach it to the above TreeCtrlEntry
   newTreeCtrlEntryLvl3 = new TreeItem("Tree Item Level 3a (2a)");
   newTreeCtrlEntryLvl3->setIcon(drives.getImage("Blue"));
   newTreeCtrlEntryLvl3->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
   newTreeCtrlEntryLvl2->addItem(newTreeCtrlEntryLvl3);
   // Create another third-level TreeCtrlEntry and attach it to the above TreeCtrlEntry
   newTreeCtrlEntryLvl3 = new TreeItem("Tree Item Level 3b (2a)");
   newTreeCtrlEntryLvl3->setIcon(drives.getImage("Lime"));
   newTreeCtrlEntryLvl3->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
   newTreeCtrlEntryLvl2->addItem(newTreeCtrlEntryLvl3);
   // Create another second-level TreeCtrlEntry and attach it to the top-most TreeCtrlEntry
   newTreeCtrlEntryLvl2 = new TreeItem("Tree Item Level 2b (1a)");
   newTreeCtrlEntryLvl2->setIcon(drives.getImage("Sunset"));
   newTreeCtrlEntryLvl2->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
   newTreeCtrlEntryLvl1->addItem(newTreeCtrlEntryLvl2);
   // Create another second-level TreeCtrlEntry and attach it to the top-most TreeCtrlEntry
   newTreeCtrlEntryLvl2 = new TreeItem("Tree Item Level 2c (1a)");
   newTreeCtrlEntryLvl2->setIcon(drives.getImage("Silver"));
   newTreeCtrlEntryLvl2->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
   newTreeCtrlEntryLvl1->addItem(newTreeCtrlEntryLvl2);

   // Create another top-most TreeCtrlEntry
   newTreeCtrlEntryLvl1 = new TreeItem("Tree Item Level 1b");
   newTreeCtrlEntryLvl1->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
   newTreeCtrlEntryLvl1->setIcon(drives.getImage("DriveStack"));
   newTreeCtrlEntryLvl1->setDisabled(true); // Let's disable this one just to be sure it works
   theTree->addItem(newTreeCtrlEntryLvl1);
   // Create a second-level TreeCtrlEntry and attach it to the top-most TreeCtrlEntry
   newTreeCtrlEntryLvl2 = new TreeItem("Tree Item Level 2a (1b)");
   newTreeCtrlEntryLvl2->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
   newTreeCtrlEntryLvl1->addItem(newTreeCtrlEntryLvl2);
   // Create another second-level TreeCtrlEntry and attach it to the top-most TreeCtrlEntry
   newTreeCtrlEntryLvl2 = new TreeItem("Tree Item Level 2b (1b)");
   newTreeCtrlEntryLvl2->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
   newTreeCtrlEntryLvl1->addItem(newTreeCtrlEntryLvl2);

   newTreeCtrlEntryLvl1 = new TreeItem("Tree Item Level 1c");
   newTreeCtrlEntryLvl1->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
   theTree->addItem(newTreeCtrlEntryLvl1);

   // Now let's create a whole bunch of items automatically
   int levelIndex = 3;
   int idepthIndex;
   int childIndex;
   int childCount;
   unsigned int iconIndex;
   String itemText;
   while (levelIndex < 10)
      {
      idepthIndex = 0;
      itemText = "Tree Item Level " + PropertyHelper::intToString(levelIndex) + " Depth " + PropertyHelper::intToString(idepthIndex);
      newTreeCtrlEntryLvl1 = new TreeItem(itemText);
      // Set a random icon for the item.  Sometimes blank (on purpose).
      iconIndex = randInt(0, (sizeof(iconArray) / sizeof(iconArray[0])) + 2);
      if (iconIndex < sizeof(iconArray) / sizeof(iconArray[0]))
         newTreeCtrlEntryLvl1->setIcon(*iconArray[iconIndex]);
      newTreeCtrlEntryLvl1->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
      theTree->addItem(newTreeCtrlEntryLvl1);
      newTreeCtrlEntryParent = newTreeCtrlEntryLvl1;

#if 1
      childIndex = 0;
      childCount = randInt(0, 3);
      while (childIndex < childCount)
         {
         itemText = "Tree Item Level " + PropertyHelper::intToString(levelIndex) + " Depth " + PropertyHelper::intToString(idepthIndex + 1) + " Child " + PropertyHelper::intToString(childIndex + 1);
         newTreeCtrlEntryLvl2 = new TreeItem(itemText);
         // Set a random icon for the item.  Sometimes blank (on purpose).
         iconIndex = randInt(0, (sizeof(iconArray) / sizeof(iconArray[0]) + 2));
         if (iconIndex < sizeof(iconArray) / sizeof(iconArray[0]))
            newTreeCtrlEntryLvl2->setIcon(*iconArray[iconIndex]);
         newTreeCtrlEntryLvl2->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
         newTreeCtrlEntryParent->addItem(newTreeCtrlEntryLvl2);
         ++childIndex;
         }
#endif

      while (idepthIndex < 15)
         {
         itemText = "Tree Item Level " + PropertyHelper::intToString(levelIndex) + " Depth " + PropertyHelper::intToString(idepthIndex + 1);
         newTreeCtrlEntryLvl2 = new TreeItem(itemText);
         // Set a random icon for the item.  Sometimes blank (on purpose).
         iconIndex = randInt(0, (sizeof(iconArray) / sizeof(iconArray[0]) + 2));
         if (iconIndex < sizeof(iconArray) / sizeof(iconArray[0]))
            newTreeCtrlEntryLvl2->setIcon(*iconArray[iconIndex]);
         newTreeCtrlEntryLvl2->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
         newTreeCtrlEntryParent->addItem(newTreeCtrlEntryLvl2);
         newTreeCtrlEntryParent = newTreeCtrlEntryLvl2;

#if 1
         childIndex = 0;
         childCount = randInt(0, 3);
         while (childIndex < childCount)
            {
            itemText = "Tree Item Level " + PropertyHelper::intToString(levelIndex) + " Depth " + PropertyHelper::intToString(idepthIndex + 1) + " Child " + PropertyHelper::intToString(childIndex + 1);
            newTreeCtrlEntryLvl2 = new TreeItem(itemText);
            // Set a random icon for the item.  Sometimes blank (on purpose).
            iconIndex = randInt(0, (sizeof(iconArray) / sizeof(iconArray[0]) + 2));
            if (iconIndex < sizeof(iconArray) / sizeof(iconArray[0]))
               newTreeCtrlEntryLvl2->setIcon(*iconArray[iconIndex]);
            newTreeCtrlEntryLvl2->setSelectionBrushImage(IMAGES_FILE_NAME, BRUSH_NAME);
            newTreeCtrlEntryParent->addItem(newTreeCtrlEntryLvl2);
            ++childIndex;
            }
#endif
         ++idepthIndex;
         }
      ++levelIndex;
      }

   return true;
   }
void EditorAutoloadSettings::update_autoload() {

	if (updating_autoload)
		return;

	updating_autoload = true;

	autoload_cache.clear();

	tree->clear();
	TreeItem *root = tree->create_item();

	List<PropertyInfo> props;
	ProjectSettings::get_singleton()->get_property_list(&props);

	for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {

		const PropertyInfo &pi = E->get();

		if (!pi.name.begins_with("autoload/"))
			continue;

		String name = pi.name.get_slice("/", 1);
		String path = ProjectSettings::get_singleton()->get(pi.name);

		if (name.empty())
			continue;

		AutoLoadInfo info;
		info.name = pi.name;
		info.order = ProjectSettings::get_singleton()->get_order(pi.name);

		autoload_cache.push_back(info);

		bool global = false;

		if (path.begins_with("*")) {
			global = true;
			path = path.substr(1, path.length());
		}

		TreeItem *item = tree->create_item(root);
		item->set_text(0, name);
		item->set_editable(0, true);

		item->set_text(1, path);
		item->set_selectable(1, false);

		item->set_cell_mode(2, TreeItem::CELL_MODE_CHECK);
		item->set_editable(2, true);
		item->set_text(2, TTR("Enable"));
		item->set_checked(2, global);

		item->add_button(3, get_icon("MoveUp", "EditorIcons"), BUTTON_MOVE_UP);
		item->add_button(3, get_icon("MoveDown", "EditorIcons"), BUTTON_MOVE_DOWN);
		item->add_button(3, get_icon("Del", "EditorIcons"), BUTTON_DELETE);
		item->set_selectable(3, false);
	}

	updating_autoload = false;
}
Example #3
0
void ModulesHandler::beginUpdateAll()
{
    TreeItem *root = m_model->rootItem();
    for (int i = root->rowCount(); --i >= 0; )
        static_cast<ModuleItem *>(root->child(i))->updated = false;
}
Example #4
0
bool ScenesDock::_create_tree(TreeItem *p_parent,EditorFileSystemDirectory *p_dir) {


	TreeItem *item = tree->create_item(p_parent);
	String dname=p_dir->get_name();
	if (dname=="")
		dname="res://";

	item->set_text(0,dname);
	item->set_icon(0,get_icon("Folder","EditorIcons"));
	item->set_selectable(0,true);
	String lpath = p_dir->get_path();
	if (lpath!="res://" && lpath.ends_with("/")) {
		lpath=lpath.substr(0,lpath.length()-1);
	}
	item->set_metadata(0,lpath);
	if (lpath==path) {
		item->select(0);
	}


	//item->set_custom_bg_color(0,get_color("prop_subsection","Editor"));

	bool has_items=false;

	for(int i=0;i<p_dir->get_subdir_count();i++) {

		if (_create_tree(item,p_dir->get_subdir(i)))
			has_items=true;
	}
#if 0
	for (int i=0;i<p_dir->get_file_count();i++) {

		String file_name = p_dir->get_file(i);
		String file_path = p_dir->get_file_path(i);

		// ScenesDockFilter::FILTER_PATH
		String search_from = file_path.right(6); // trim "res://"
		if (file_filter == ScenesDockFilter::FILTER_NAME)
			 search_from = file_name;
		else if (file_filter == ScenesDockFilter::FILTER_FOLDER)
			search_from = file_path.right(6).get_base_dir();

		if (search_term!="" && search_from.findn(search_term)==-1)
			continue;

		bool isfave = favorites.has(file_path);
		if (button_favorite->is_pressed() && !isfave)
			continue;

		TreeItem *fitem = tree->create_item(item);
		fitem->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
		fitem->set_editable(0,true);
		fitem->set_checked(0,isfave);
		fitem->set_text(0,file_name);

		Ref<Texture> icon = get_icon( (has_icon(p_dir->get_file_type(i),"EditorIcons")?p_dir->get_file_type(i):String("Object")),"EditorIcons");
		fitem->set_icon(0, icon );


		fitem->set_metadata(0,file_path);
		//if (p_dir->files[i]->icon.is_valid()) {
//			fitem->set_icon(0,p_dir->files[i]->icon);
//		}
		has_items=true;

	}
#endif
	/*if (!has_items) {

		memdelete(item);
		return false;

	}*/

	return true;
}
void EditorAutoloadSettings::_autoload_edited() {

	if (updating_autoload)
		return;

	TreeItem *ti = tree->get_edited();
	int column = tree->get_edited_column();

	UndoRedo *undo_redo = EditorNode::get_undo_redo();

	if (column == 0) {
		String name = ti->get_text(0);
		String old_name = selected_autoload.get_slice("/", 1);

		if (name == old_name)
			return;

		String error;
		if (!_autoload_name_is_valid(name, &error)) {
			ti->set_text(0, old_name);
			EditorNode::get_singleton()->show_warning(error);
			return;
		}

		if (ProjectSettings::get_singleton()->has("autoload/" + name)) {
			ti->set_text(0, old_name);
			EditorNode::get_singleton()->show_warning(vformat(TTR("Autoload '%s' already exists!"), name));
			return;
		}

		updating_autoload = true;

		name = "autoload/" + name;

		int order = ProjectSettings::get_singleton()->get_order(selected_autoload);
		String path = ProjectSettings::get_singleton()->get(selected_autoload);

		undo_redo->create_action(TTR("Rename Autoload"));

		undo_redo->add_do_property(ProjectSettings::get_singleton(), name, path);
		undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", name, order);
		undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", selected_autoload);

		undo_redo->add_undo_property(ProjectSettings::get_singleton(), selected_autoload, path);
		undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", selected_autoload, order);
		undo_redo->add_undo_method(ProjectSettings::get_singleton(), "clear", name);

		undo_redo->add_do_method(this, "update_autoload");
		undo_redo->add_undo_method(this, "update_autoload");

		undo_redo->add_do_method(this, "emit_signal", autoload_changed);
		undo_redo->add_undo_method(this, "emit_signal", autoload_changed);

		undo_redo->commit_action();

		selected_autoload = name;
	} else if (column == 2) {
		updating_autoload = true;

		bool checked = ti->is_checked(2);
		String base = "autoload/" + ti->get_text(0);

		int order = ProjectSettings::get_singleton()->get_order(base);
		String path = ProjectSettings::get_singleton()->get(base);

		if (path.begins_with("*"))
			path = path.substr(1, path.length());

		if (checked)
			path = "*" + path;

		undo_redo->create_action(TTR("Toggle AutoLoad Globals"));

		undo_redo->add_do_property(ProjectSettings::get_singleton(), base, path);
		undo_redo->add_undo_property(ProjectSettings::get_singleton(), base, ProjectSettings::get_singleton()->get(base));

		undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", base, order);
		undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", base, order);

		undo_redo->add_do_method(this, "update_autoload");
		undo_redo->add_undo_method(this, "update_autoload");

		undo_redo->add_do_method(this, "emit_signal", autoload_changed);
		undo_redo->add_undo_method(this, "emit_signal", autoload_changed);

		undo_redo->commit_action();
	}

	updating_autoload = false;
}
int QmitkDataStorageTreeModel::rowCount(const QModelIndex &parent) const
{
  TreeItem *parentTreeItem = this->TreeItemFromIndex(parent);
  return parentTreeItem->GetChildCount();
}
Example #7
0
bool ScenesDock::can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const{

	Dictionary drag_data = p_data;

	if (drag_data.has("type") && String(drag_data["type"])=="favorite") {

		//moving favorite around
		TreeItem *ti = tree->get_item_at_pos(p_point);
		if (!ti)
			return false;

		int what = tree->get_drop_section_at_pos(p_point);

		if (ti==tree->get_root()->get_children()) {
			return (what==1); //the parent, first fav
		}
		if (ti->get_parent() && tree->get_root()->get_children()==ti->get_parent()) {
			return true; // a favorite
		}

		if (ti==tree->get_root()->get_children()->get_next()) {
			return (what==-1); //the tree, last fav
		}

		return false;

	}


	if (drag_data.has("type") && String(drag_data["type"])=="resource") {
		return true;
	}

	if (drag_data.has("type") && ( String(drag_data["type"])=="files" || String(drag_data["type"])=="files_and_dirs")) {

		Vector<String> fnames = drag_data["files"];

		if (p_from==files) {

			int at_pos = files->get_item_at_pos(p_point);
			if (at_pos!=-1) {

				String dir = files->get_item_metadata(at_pos);
				if (dir.ends_with("/"))
					return true;
			}
		}

		if (p_from==tree) {

			TreeItem *ti = tree->get_item_at_pos(p_point);
			if (!ti)
				return false;
			String path = ti->get_metadata(0);

			if (path==String())
				return false;

			return true;
		}

	}

	return false;
}
Example #8
0
void ConnectionsDock::update_tree() {

	tree->clear();

	if (!selectedNode)
		return;

	TreeItem *root = tree->create_item();

	List<MethodInfo> node_signals;

	selectedNode->get_signal_list(&node_signals);

	//node_signals.sort_custom<_ConnectionsDockMethodInfoSort>();
	bool did_script = false;
	StringName base = selectedNode->get_class();

	while (base) {

		List<MethodInfo> node_signals;
		Ref<Texture> icon;
		String name;

		if (!did_script) {

			Ref<Script> scr = selectedNode->get_script();
			if (scr.is_valid()) {
				scr->get_script_signal_list(&node_signals);
				if (scr->get_path().is_resource_file())
					name = scr->get_path().get_file();
				else
					name = scr->get_class();

				if (has_icon(scr->get_class(), "EditorIcons")) {
					icon = get_icon(scr->get_class(), "EditorIcons");
				}
			}

		} else {

			ClassDB::get_signal_list(base, &node_signals, true);
			if (has_icon(base, "EditorIcons")) {
				icon = get_icon(base, "EditorIcons");
			}
			name = base;
		}

		TreeItem *pitem = NULL;

		if (node_signals.size()) {
			pitem = tree->create_item(root);
			pitem->set_text(0, name);
			pitem->set_icon(0, icon);
			pitem->set_selectable(0, false);
			pitem->set_editable(0, false);
			pitem->set_custom_bg_color(0, get_color("prop_subsection", "Editor"));
			node_signals.sort();
		}

		for (List<MethodInfo>::Element *E = node_signals.front(); E; E = E->next()) {

			MethodInfo &mi = E->get();

			String signaldesc;
			signaldesc = mi.name + "(";
			PoolStringArray argnames;
			if (mi.arguments.size()) {
				signaldesc += " ";
				for (int i = 0; i < mi.arguments.size(); i++) {

					PropertyInfo &pi = mi.arguments[i];

					if (i > 0)
						signaldesc += ", ";
					String tname = "var";
					if (pi.type == Variant::OBJECT && pi.class_name != StringName()) {
						tname = pi.class_name.operator String();
					} else if (pi.type != Variant::NIL) {
						tname = Variant::get_type_name(pi.type);
					}
					signaldesc += tname + " " + (pi.name == "" ? String("arg " + itos(i)) : pi.name);
					argnames.push_back(pi.name + ":" + tname);
				}
				signaldesc += " ";
			}

			signaldesc += ")";

			TreeItem *item = tree->create_item(pitem);
			item->set_text(0, signaldesc);
			Dictionary sinfo;
			sinfo["name"] = mi.name;
			sinfo["args"] = argnames;
			item->set_metadata(0, sinfo);
			item->set_icon(0, get_icon("Signal", "EditorIcons"));

			List<Object::Connection> connections;
			selectedNode->get_signal_connection_list(mi.name, &connections);

			for (List<Object::Connection>::Element *F = connections.front(); F; F = F->next()) {

				Object::Connection &c = F->get();
				if (!(c.flags & CONNECT_PERSIST))
					continue;

				Node *target = Object::cast_to<Node>(c.target);
				if (!target)
					continue;

				String path = String(selectedNode->get_path_to(target)) + " :: " + c.method + "()";
				if (c.flags & CONNECT_DEFERRED)
					path += " (deferred)";
				if (c.flags & CONNECT_ONESHOT)
					path += " (oneshot)";
				if (c.binds.size()) {

					path += " binds( ";
					for (int i = 0; i < c.binds.size(); i++) {

						if (i > 0)
							path += ", ";
						path += c.binds[i].operator String();
					}
					path += " )";
				}

				TreeItem *item2 = tree->create_item(item);
				item2->set_text(0, path);
				item2->set_metadata(0, c);
				item2->set_icon(0, get_icon("Slot", "EditorIcons"));
			}
		}

		if (!did_script) {
			did_script = true;
		} else {
			base = ClassDB::get_parent_class(base);
		}
	}

	connect_button->set_text(TTR("Connect"));
	connect_button->set_disabled(true);
}
Example #9
0
void ProjectExportDialog::_edit_preset(int p_index) {

	if (p_index < 0 || p_index >= presets->get_item_count()) {
		name->set_text("");
		name->set_editable(false);
		runnable->set_disabled(true);
		parameters->edit(NULL);
		delete_preset->set_disabled(true);
		sections->hide();
		patches->clear();
		export_error->hide();
		export_templates_error->hide();
		return;
	}

	Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(p_index);
	ERR_FAIL_COND(current.is_null());

	updating = true;

	presets->select(p_index);
	sections->show();

	name->set_editable(true);
	delete_preset->set_disabled(false);
	name->set_text(current->get_name());
	runnable->set_disabled(false);
	runnable->set_pressed(current->is_runnable());
	parameters->edit(current.ptr());

	export_filter->select(current->get_export_filter());
	include_filters->set_text(current->get_include_filter());
	exclude_filters->set_text(current->get_exclude_filter());

	patches->clear();
	TreeItem *patch_root = patches->create_item();
	Vector<String> patchlist = current->get_patches();
	for (int i = 0; i < patchlist.size(); i++) {
		TreeItem *patch = patches->create_item(patch_root);
		patch->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
		String file = patchlist[i].get_file();
		patch->set_editable(0, true);
		patch->set_text(0, file.get_file().replace("*", ""));
		if (file.ends_with("*"))
			patch->set_checked(0, true);
		patch->set_tooltip(0, patchlist[i]);
		patch->set_metadata(0, i);
		patch->add_button(0, get_icon("Del", "EditorIcons"), 0);
		patch->add_button(0, get_icon("folder", "FileDialog"), 1);
	}

	TreeItem *patch_add = patches->create_item(patch_root);
	patch_add->set_metadata(0, patchlist.size());
	if (patchlist.size() == 0)
		patch_add->set_text(0, "Add initial export..");
	else
		patch_add->set_text(0, "Add previous patches..");

	patch_add->add_button(0, get_icon("folder", "FileDialog"), 1);

	_fill_resource_tree();

	bool needs_templates;
	String error;
	if (!current->get_platform()->can_export(current, error, needs_templates)) {

		if (error != String()) {

			Vector<String> items = error.split("\n");
			error = "";
			for (int i = 0; i < items.size(); i++) {
				if (i > 0)
					error += "\n";
				error += " - " + items[i];
			}

			export_error->set_text(error);
			export_error->show();
		} else {
			export_error->hide();
		}
		if (needs_templates)
			export_templates_error->show();
		else
			export_templates_error->hide();

		export_button->set_disabled(true);

	} else {
		export_error->hide();
		export_templates_error->hide();
		export_button->set_disabled(false);
	}

	custom_features->set_text(current->get_custom_features());
	_update_feature_list();

	updating = false;
}
Example #10
0
void CreateDialog::popup_create(bool p_dont_clear, bool p_replace_mode) {

	type_list.clear();
	ClassDB::get_class_list(&type_list);
	ScriptServer::get_global_class_list(&type_list);
	type_list.sort_custom<StringName::AlphCompare>();

	recent->clear();

	FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("create_recent." + base_type), FileAccess::READ);

	if (f) {

		TreeItem *root = recent->create_item();

		while (!f->eof_reached()) {
			String l = f->get_line().strip_edges();

			if (l != String()) {

				TreeItem *ti = recent->create_item(root);
				ti->set_text(0, l);
				ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(l, base_type));
			}
		}

		memdelete(f);
	}

	favorites->clear();

	f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("favorites." + base_type), FileAccess::READ);

	favorite_list.clear();

	if (f) {

		while (!f->eof_reached()) {
			String l = f->get_line().strip_edges();

			if (l != String()) {
				favorite_list.push_back(l);
			}
		}

		memdelete(f);
	}

	_save_and_update_favorite_list();

	// Restore valid window bounds or pop up at default size.
	if (EditorSettings::get_singleton()->has_setting("interface/dialogs/create_new_node_bounds")) {
		popup(EditorSettings::get_singleton()->get("interface/dialogs/create_new_node_bounds"));
	} else {

		Size2 popup_size = Size2(900, 700) * editor_get_scale();
		Size2 window_size = get_viewport_rect().size;

		popup_size.x = MIN(window_size.x * 0.8, popup_size.x);
		popup_size.y = MIN(window_size.y * 0.8, popup_size.y);

		popup_centered(popup_size);
	}

	if (p_dont_clear) {
		search_box->select_all();
	} else {
		search_box->clear();
	}

	search_box->grab_focus();

	_update_search();

	bool enable_rl = EditorSettings::get_singleton()->get("docks/scene_tree/draw_relationship_lines");
	Color rl_color = EditorSettings::get_singleton()->get("docks/scene_tree/relationship_line_color");

	if (enable_rl) {
		search_options->add_constant_override("draw_relationship_lines", 1);
		search_options->add_color_override("relationship_line_color", rl_color);
	} else {
		search_options->add_constant_override("draw_relationship_lines", 0);
	}

	is_replace_mode = p_replace_mode;

	if (p_replace_mode) {
		set_title(vformat(TTR("Change %s Type"), base_type));
		get_ok()->set_text(TTR("Change"));
	} else {
		set_title(vformat(TTR("Create New %s"), base_type));
		get_ok()->set_text(TTR("Create"));
	}
}
Example #11
0
bool ConnectionsDock::_is_item_signal(TreeItem &item) {

	return (item.get_parent() == tree->get_root() || item.get_parent()->get_parent() == tree->get_root());
}
Example #12
0
void CreateDialog::_update_search() {

	search_options->clear();
	favorite->set_disabled(true);

	help_bit->set_text("");
	/*
	TreeItem *root = search_options->create_item();
	_parse_fs(EditorFileSystem::get_singleton()->get_filesystem());
*/

	HashMap<String, TreeItem *> types;

	TreeItem *root = search_options->create_item();
	EditorData &ed = EditorNode::get_editor_data();

	root->set_text(0, base_type);
	if (has_icon(base_type, "EditorIcons")) {
		root->set_icon(0, get_icon(base_type, "EditorIcons"));
	}

	TreeItem *to_select = search_box->get_text() == base_type ? root : NULL;

	for (List<StringName>::Element *I = type_list.front(); I; I = I->next()) {

		String type = I->get();
		bool cpp_type = ClassDB::class_exists(type);

		if (base_type == "Node" && type.begins_with("Editor"))
			continue; // do not show editor nodes

		if (cpp_type && !ClassDB::can_instance(type))
			continue; // can't create what can't be instanced

		bool skip = false;
		if (cpp_type) {
			for (Set<StringName>::Element *E = type_blacklist.front(); E && !skip; E = E->next()) {
				if (ClassDB::is_parent_class(type, E->get()))
					skip = true;
			}
			if (skip)
				continue;
		}

		if (search_box->get_text() == "") {
			add_type(type, types, root, &to_select);
		} else {

			bool found = false;
			String type = I->get();
			while (type != "" && (cpp_type ? ClassDB::is_parent_class(type, base_type) : ed.script_class_is_parent(type, base_type)) && type != base_type) {
				if (search_box->get_text().is_subsequence_ofi(type)) {

					found = true;
					break;
				}

				type = cpp_type ? ClassDB::get_parent_class(type) : ed.script_class_get_base(type);
			}

			if (found)
				add_type(I->get(), types, root, &to_select);
		}

		if (EditorNode::get_editor_data().get_custom_types().has(type) && ClassDB::is_parent_class(type, base_type)) {
			//there are custom types based on this... cool.

			const Vector<EditorData::CustomType> &ct = EditorNode::get_editor_data().get_custom_types()[type];
			for (int i = 0; i < ct.size(); i++) {

				bool show = search_box->get_text().is_subsequence_ofi(ct[i].name);

				if (!show)
					continue;

				if (!types.has(type))
					add_type(type, types, root, &to_select);

				TreeItem *ti;
				if (types.has(type))
					ti = types[type];
				else
					ti = search_options->get_root();

				TreeItem *item = search_options->create_item(ti);
				item->set_metadata(0, type);
				item->set_text(0, ct[i].name);
				if (ct[i].icon.is_valid()) {
					item->set_icon(0, ct[i].icon);
				}

				if (!to_select || ct[i].name == search_box->get_text()) {
					to_select = item;
				}
			}
		}
	}

	if (search_box->get_text() == "") {
		to_select = root;
	}

	if (to_select) {
		to_select->select(0);
		search_options->scroll_to_item(to_select);
		favorite->set_disabled(false);
		favorite->set_pressed(favorite_list.find(to_select->get_text(0)) != -1);
	}

	get_ok()->set_disabled(root->get_children() == NULL);
}
Example #13
0
void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p_types, TreeItem *p_root, TreeItem **to_select) {

	if (p_types.has(p_type))
		return;

	bool cpp_type = ClassDB::class_exists(p_type);
	EditorData &ed = EditorNode::get_editor_data();

	if (p_type == base_type)
		return;

	if (cpp_type) {
		if (!ClassDB::is_parent_class(p_type, base_type))
			return;
	} else {
		if (!ScriptServer::is_global_class(p_type) || !ed.script_class_is_parent(p_type, base_type))
			return;

		String script_path = ScriptServer::get_global_class_path(p_type);
		if (script_path.find("res://addons/", 0) != -1) {
			if (!EditorNode::get_singleton()->is_addon_plugin_enabled(script_path.get_slicec('/', 3)))
				return;
		}
	}

	String inherits = cpp_type ? ClassDB::get_parent_class(p_type) : ed.script_class_get_base(p_type);

	TreeItem *parent = p_root;

	if (inherits.length()) {

		if (!p_types.has(inherits)) {

			add_type(inherits, p_types, p_root, to_select);
		}

		if (p_types.has(inherits))
			parent = p_types[inherits];
		else if (ScriptServer::is_global_class(inherits))
			return;
	}

	bool can_instance = (cpp_type && ClassDB::can_instance(p_type)) || ScriptServer::is_global_class(p_type);

	TreeItem *item = search_options->create_item(parent);
	if (cpp_type) {
		item->set_text(0, p_type);
	} else {
		item->set_metadata(0, p_type);
		item->set_text(0, p_type + " (" + ScriptServer::get_global_class_path(p_type).get_file() + ")");
	}
	if (!can_instance) {
		item->set_custom_color(0, get_color("disabled_font_color", "Editor"));
		item->set_selectable(0, false);
	} else {
		bool is_search_subsequence = search_box->get_text().is_subsequence_ofi(p_type);
		String to_select_type = *to_select ? (*to_select)->get_text(0) : "";
		to_select_type = to_select_type.split(" ")[0];
		bool current_item_is_preferred;
		if (cpp_type) {
			String cpp_to_select_type = to_select_type;
			if (ScriptServer::is_global_class(to_select_type))
				cpp_to_select_type = ScriptServer::get_global_class_base(to_select_type);
			current_item_is_preferred = ClassDB::is_parent_class(p_type, preferred_search_result_type) && !ClassDB::is_parent_class(cpp_to_select_type, preferred_search_result_type);
		} else {
			current_item_is_preferred = ed.script_class_is_parent(p_type, preferred_search_result_type) && !ed.script_class_is_parent(to_select_type, preferred_search_result_type) && search_box->get_text() != to_select_type;
		}
		if (*to_select && p_type.length() < (*to_select)->get_text(0).length()) {
			current_item_is_preferred = true;
		}

		if (((!*to_select || current_item_is_preferred) && is_search_subsequence) || search_box->get_text() == p_type) {
			*to_select = item;
		}
	}

	if (bool(EditorSettings::get_singleton()->get("docks/scene_tree/start_create_dialog_fully_expanded"))) {
		item->set_collapsed(false);
	} else {
		// don't collapse search results
		bool collapse = (search_box->get_text() == "");
		// don't collapse the root node
		collapse &= (item != p_root);
		// don't collapse abstract nodes on the first tree level
		collapse &= ((parent != p_root) || (can_instance));
		item->set_collapsed(collapse);
	}

	const String &description = EditorHelp::get_doc_data()->class_list[p_type].brief_description;
	item->set_tooltip(0, description);

	item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, base_type));

	p_types[p_type] = item;
}
Example #14
0
	virtual void init() {
	
		SceneMainLoop::init();


#if 0


		Viewport *vp = memnew( Viewport );
		vp->set_world( Ref<World>( memnew( World )));
		get_root()->add_child(vp);

		vp->set_rect(Rect2(0,0,256,256));
		vp->set_as_render_target(true);
		vp->set_render_target_update_mode(Viewport::RENDER_TARGET_UPDATE_ALWAYS);


		Camera *camera = memnew( Camera );
		vp->add_child(camera);
		camera->make_current();

		TestCube *testcube = memnew( TestCube );
		vp->add_child(testcube);
		testcube->set_transform(Transform( Matrix3().rotated(Vector3(0,1,0),Math_PI*0.25), Vector3(0,0,-8)));

		Sprite *sp = memnew( Sprite );
		sp->set_texture( vp->get_render_target_texture() );
//		sp->set_texture( ResourceLoader::load("res://ball.png") );
		sp->set_pos(Point2(300,300));
		get_root()->add_child(sp);


		return;
#endif

		Panel * frame = memnew( Panel );
		frame->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END );
		frame->set_anchor( MARGIN_BOTTOM, Control::ANCHOR_END );
		frame->set_end( Point2(0,0) );
		
		get_root()->add_child( frame );

		Label *label = memnew( Label );

		label->set_pos( Point2( 80,90 ) );
		label->set_size( Point2( 170,80 ) );
		label->set_align( Label::ALIGN_FILL );
		//label->set_text("There");
		label->set_text("There was once upon a time a beautiful unicorn that loved to play with little girls...");

		frame->add_child(label);

		Button *button = memnew( Button );

		button->set_pos( Point2( 20,20 ) );
		button->set_size( Point2( 1,1 ) );
		button->set_text("This is a biggie button");


		frame->add_child( button );


#if 0
		Sprite *tf = memnew( Sprite );
		frame->add_child(tf);
		Image img;
		ImageLoader::load_image("LarvoClub.png",&img);

		img.resize(512,512);
		img.generate_mipmaps();
		img.compress();
		Ref<Texture> text = memnew( Texture );
		text->create_from_image(img);
		tf->set_texture(text);
		tf->set_pos(Point2(50,50));
		//tf->set_scale(Point2(0.3,0.3));


		return;
#endif

		Tree * tree = memnew( Tree );
		tree->set_columns(2);

		tree->set_pos( Point2( 230,210 ) );
		tree->set_size( Point2( 150,250 ) );


		TreeItem *item = tree->create_item();
		item->set_editable(0,true);
		item->set_text(0,"root");
		item = tree->create_item( tree->get_root() );
		item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
		item->set_editable(0,true);
		item->set_text(0,"check");
		item->set_cell_mode(1, TreeItem::CELL_MODE_CHECK);
		item->set_editable(1,true);
		item->set_text(1,"check2");
		item = tree->create_item( tree->get_root() );
		item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
		item->set_editable(0,true);
		item->set_range_config(0,0,20,0.1);
		item->set_range(0,2);
		item->add_button(0,Theme::get_default()->get_icon("folder","FileDialog"));
		item->set_cell_mode(1, TreeItem::CELL_MODE_RANGE);
		item->set_editable(1,true);
		item->set_range_config(1,0,20,0.1);
		item->set_range(1,3);

		item = tree->create_item( tree->get_root() );
		item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
		item->set_editable(0,true);
		item->set_text(0,"Have,Many,Several,Options!");
		item->set_range(0,2);

		item = tree->create_item( item );
		item->set_editable(0,true);
		item->set_text(0,"Gershwin!");

		frame->add_child(tree);

		//control = memnew( Control );
		//root->add_child( control );


		
		LineEdit *line_edit = memnew( LineEdit );
		
		line_edit->set_pos( Point2( 30,190 ) );
		line_edit->set_size( Point2( 180,1 ) );
		
		frame->add_child(line_edit);
		
		HScrollBar *hscroll = memnew( HScrollBar );
		
		hscroll->set_pos( Point2( 30,290 ) );
		hscroll->set_size( Point2( 180,1 ) );
		hscroll->set_max(10);
		hscroll->set_page(4);
		
		frame->add_child(hscroll);



		SpinBox *spin = memnew( SpinBox );

		spin->set_pos( Point2( 30,260 ) );
		spin->set_size( Point2( 120,1 ) );

		frame->add_child(spin);
		hscroll->share(spin);

		ProgressBar *progress = memnew( ProgressBar );

		progress->set_pos( Point2( 30,330 ) );
		progress->set_size( Point2( 120,1 ) );

		frame->add_child(progress);
		hscroll->share(progress);

		MenuButton *menu_button = memnew( MenuButton );
		
		menu_button->set_text("I'm a menu!");
		menu_button->set_pos( Point2( 30,380 ) );
		menu_button->set_size( Point2( 1,1 ) );
		
		frame->add_child(menu_button);		
		
		PopupMenu *popup = menu_button->get_popup();
		
		popup->add_item("Hello, testing");
		popup->add_item("My Dearest");
		popup->add_separator();
		popup->add_item("Popup");
		popup->add_check_item("Check Popup");
		popup->set_item_checked(4,true);		
				
		OptionButton *options = memnew( OptionButton );
		
		options->add_item("Hello, testing");
		options->add_item("My Dearest");
		
		options->set_pos( Point2( 230,180 ) );
		options->set_size( Point2( 1,1 ) );
		
		frame->add_child(options);		

		/*
		Tree * tree = memnew( Tree );
		tree->set_columns(2);
		
		tree->set_pos( Point2( 230,210 ) );
		tree->set_size( Point2( 150,250 ) );


		TreeItem *item = tree->create_item();
		item->set_editable(0,true);
		item->set_text(0,"root");
		item = tree->create_item( tree->get_root() );
		item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
		item->set_editable(0,true);
		item->set_text(0,"check");
		item = tree->create_item( tree->get_root() );
		item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
		item->set_editable(0,true);
		item->set_range_config(0,0,20,0.1);
		item->set_range(0,2);
		item->add_button(0,Theme::get_default()->get_icon("folder","FileDialog"));
		item = tree->create_item( tree->get_root() );
		item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
		item->set_editable(0,true);
		item->set_text(0,"Have,Many,Several,Options!");
		item->set_range(0,2);
		
		frame->add_child(tree);
*/


		RichTextLabel *richtext = memnew( RichTextLabel );

		richtext->set_pos( Point2( 600,210 ) );
		richtext->set_size( Point2( 180,250 ) );
		richtext->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,20);

		frame->add_child(richtext);


		richtext->add_text("Hello, My Friends!\n\nWelcome to the amazing world of ");

		richtext->add_newline();
		richtext->add_newline();

		richtext->push_color(Color(1,0.5,0.5));
		richtext->add_text("leprechauns");
		richtext->pop();

		richtext->add_text(" and ");
		richtext->push_color(Color(0,1.0,0.5));
		richtext->add_text("faeries.\n");
		richtext->pop();
		richtext->add_text("In this new episode, we will attemp to ");
		richtext->push_font(richtext->get_font("mono_font","Fonts"));
		richtext->push_color(Color(0.7,0.5,1.0));
		richtext->add_text("deliver something nice");
		richtext->pop();
		richtext->pop();
		richtext->add_text(" to all the viewers! Unfortunately, I need to ");
		richtext->push_underline();
		richtext->add_text("keep writing a lot of text");
		richtext->pop();
		richtext->add_text(" so the label control overflows and the scrollbar appears.\n");
		//richtext->push_indent(1);
		//richtext->add_text("By the way, testing indent levels! Yohohoho! Everything should appear to the right sightly here!\n");
		//richtext->pop();
		richtext->push_meta("http://www.scrollingcapabilities.xz");
		richtext->add_text("This allows to test for the scrolling capabilities ");
		richtext->pop();
		richtext->add_text("of the rich text label for huge text (not like this text will really be huge but, you know).\nAs long as it is so long that it will work nicely for a test/demo, then it's welcomed in my book...\nChanging subject, the day is cloudy today and I'm wondering if I'll get che chance to travel somewhere nice. Sometimes, watching the clouds from satellite images may give a nice insight about how pressure zones in our planet work, althogh it also makes it pretty obvious to see why most weather forecasts get it wrong so often.\nClouds are so difficult to predict!\nBut it's pretty cool how our civilization has adapted to having water falling from the sky each time it rains...");
		//richtext->add_text("Hello!\nGorgeous..");


		//richtext->push_meta("http://www.scrollingcapabilities.xz");
		///richtext->add_text("Hello!\n");
		//richtext->pop();

		richtext->set_anchor(MARGIN_RIGHT,Control::ANCHOR_END);


		TabContainer * tabc = memnew( TabContainer );

		Control *ctl= memnew( Control );
		ctl->set_name("tab 1");
		tabc->add_child(ctl);

		ctl= memnew( Control );
		ctl->set_name("tab 2");
		tabc->add_child(ctl);
		label = memnew( Label );
		label->set_text("Some Label");
		label->set_pos( Point2(20,20) );
		ctl->add_child(label);;

		ctl= memnew( Control );
		ctl->set_name("tab 3");
		button = memnew( Button );
		button->set_text("Some Button");
		button->set_pos( Point2(30,50) );
		ctl->add_child(button);;

		tabc->add_child(ctl);

		frame->add_child(tabc);
		
		tabc->set_pos( Point2( 400,210 ) );
		tabc->set_size( Point2( 180,250 ) );

		
		Ref<ImageTexture> text = memnew( ImageTexture );
		text->load("test_data/concave.png");

		Sprite* sprite = memnew(Sprite);
		sprite->set_texture(text);
		sprite->set_pos(Point2(300, 300));
		frame->add_child(sprite);
		sprite->show();

		Sprite* sprite2 = memnew(Sprite);
		sprite->set_texture(text);
		sprite->add_child(sprite2);
		sprite2->set_pos(Point2(50, 50));
		sprite2->show();
	}
Example #15
0
TreeItem* RhythmboxFeature::importPlaylists() {
    QFile db(QDir::homePath() + "/.gnome2/rhythmbox/playlists.xml");
    if (!db.exists()) {
        db.setFileName(QDir::homePath() + "/.local/share/rhythmbox/playlists.xml");
        if (!db.exists()) {
            return NULL;
        }
    }
    //Open file
     if (!db.open(QIODevice::ReadOnly | QIODevice::Text))
        return NULL;

    QSqlQuery query_insert_to_playlists(m_database);
    query_insert_to_playlists.prepare("INSERT INTO rhythmbox_playlists (id, name) "
                                      "VALUES (:id, :name)");

    QSqlQuery query_insert_to_playlist_tracks(m_database);
    query_insert_to_playlist_tracks.prepare(
            "INSERT INTO rhythmbox_playlist_tracks (playlist_id, track_id, position) "
            "VALUES (:playlist_id, :track_id, :position)");
    //The tree structure holding the playlists
    TreeItem* rootItem = new TreeItem();

    QXmlStreamReader xml(&db);
    while (!xml.atEnd() && !m_cancelImport) {
        xml.readNext();
        if (xml.isStartElement() && xml.name() == "playlist") {
            QXmlStreamAttributes attr = xml.attributes();

            //Only parse non build-in playlists
            if (attr.value("type").toString() == "static") {
                QString playlist_name = attr.value("name").toString();

                //Construct the childmodel
                TreeItem * item = new TreeItem(playlist_name, playlist_name, this, rootItem);
                rootItem->appendChild(item);

                //Execute SQL statement
                query_insert_to_playlists.bindValue(":name", playlist_name);

                if (!query_insert_to_playlists.exec()) {
                    LOG_FAILED_QUERY(query_insert_to_playlists)
                            << "Couldn't insert playlist:" << playlist_name;
                    continue;
                }

                // get playlist_id
                int playlist_id = query_insert_to_playlists.lastInsertId().toInt();

                //Process playlist entries
                importPlaylist(xml, query_insert_to_playlist_tracks, playlist_id);
            }
        }
    }

    if (xml.hasError()) {
        // do error handling
        qDebug() << "Cannot process Rhythmbox music collection";
        qDebug() << "XML ERROR: " << xml.errorString();
        delete rootItem;
        return NULL;
    }
    db.close();

    return rootItem;

}
void RenderSettingsDialog::update() {
	int index = ui->integratorBox->currentIndex();
	Properties integratorProps, samplerProps;
	bool needsUpdate = false;

	if (sender() == ui->samplerBox) {
		m_samplerNode->putProperties(samplerProps);
		needsUpdate = true;
	}

	if (sender() == ui->integratorBox) {
		m_integratorNode->putProperties(integratorProps);
		needsUpdate = true;
	}

	if (sender() == ui->rFilterBox ||
		sender() == ui->icBox ||
		sender() == ui->aiBox) {
		needsUpdate = true;
	}

	m_integratorNode = m_model->updateClass(m_integratorNode,
		ui->integratorBox->itemData(index).toList().at(0).toString(),
		ui->integratorBox->itemText(index));
	index = ui->samplerBox->currentIndex();
	m_samplerNode = m_model->updateClass(m_samplerNode,
		ui->samplerBox->itemData(index).toList().at(0).toString(),
		ui->samplerBox->itemText(index));
	index = ui->rFilterBox->currentIndex();
	m_rFilterNode = m_model->updateClass(m_rFilterNode,
		ui->rFilterBox->itemData(index).toList().at(0).toString(),
		ui->rFilterBox->itemText(index));

	if (ui->icBox->isChecked()) {
		m_icNode = m_model->updateClass(m_icNode,
			"IrradianceCacheIntegrator", tr("Irradiance Cache"));
	} else {
		m_icNode = m_model->updateClass(m_icNode, "", "");
	}

	if (ui->aiBox->isChecked()) {
		m_aiNode = m_model->updateClass(m_aiNode,
			"AdaptiveIntegrator", tr("Adaptive Integration"));
	} else {
		m_aiNode = m_model->updateClass(m_aiNode, "", "");
	}

	if (sender() == ui->integratorBox) {
		for (int i=0; i<m_integratorNode->childCount(); ++i) {
			TreeItem *treeItem = m_integratorNode->child(i);
			if (integratorProps.hasProperty(treeItem->getName().toStdString()))
				m_integratorNode->setProperty(treeItem->getName().toStdString(), integratorProps);
		}
	}

	if (sender() == ui->samplerBox) {
		for (int i=0; i<m_samplerNode->childCount(); ++i) {
			TreeItem *treeItem = m_samplerNode->child(i);
			if (samplerProps.hasProperty(treeItem->getName().toStdString()))
				m_samplerNode->setProperty(treeItem->getName().toStdString(), samplerProps);
		}
	}

	if (needsUpdate) {
		int row = 0;
		/* Make comboboxes etc editable by default */
		for (int i = 0; i < m_model->rowCount(); ++i) {
			QModelIndex index = m_model->index(i, 0);

			for (int j = 0; j < m_model->rowCount(index); ++j) {
				QModelIndex idx = m_model->index(j, 1, index);
				ui->treeView->openPersistentEditor(idx);
				QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(ui->treeView->indexWidget(idx));
				if (spinBox) {
					QLineEdit *edit = spinBox->findChild<QLineEdit*>();
					if (row % 2 == 0)
						edit->setStyleSheet("background-color: palette(alternate-base);");
					edit->deselect();
				}
				row++;
			}
		}
	}
	ui->treeView->expandAll();

	dataChanged();
}
Example #17
0
bool QmitkDataStorageTreeModel::dropMimeData(
  const QMimeData *data, Qt::DropAction action, int row, int /*column*/, const QModelIndex &parent)
{
  // Early exit, returning true, but not actually doing anything (ignoring data).
  if (action == Qt::IgnoreAction)
  {
    return true;
  }

  // Note, we are returning true if we handled it, and false otherwise
  bool returnValue = false;

  if (data->hasFormat("application/x-qabstractitemmodeldatalist"))
  {
    returnValue = true;

    // First we extract a Qlist of TreeItem* pointers.
    QList<TreeItem *> listOfItemsToDrop = ToTreeItemPtrList(data);
    if (listOfItemsToDrop.empty())
    {
      return false;
    }

    // Retrieve the TreeItem* where we are dropping stuff, and its parent.
    TreeItem *dropItem = this->TreeItemFromIndex(parent);
    TreeItem *parentItem = dropItem->GetParent();

    // If item was dropped onto empty space, we select the root node
    if (dropItem == m_Root)
    {
      parentItem = m_Root;
    }

    // Dragging and Dropping is only allowed within the same parent, so use the first item in list to validate.
    // (otherwise, you could have a derived image such as a segmentation, and assign it to another image).
    // NOTE: We are assuming the input list is valid... i.e. when it was dragged, all the items had the same parent.

    // Determine whether or not the drag and drop operation is a valid one.
    // Examples of invalid operations include:
    //  - dragging nodes with different parents
    //  - dragging nodes from one parent to another parent, if m_AllowHierarchyChange is false
    //  - dragging a node on one of its child nodes (only relevant if m_AllowHierarchyChange is true)

    bool isValidDragAndDropOperation(true);

    // different parents
    {
      TreeItem *firstParent = listOfItemsToDrop[0]->GetParent();
      QList<TreeItem *>::iterator diIter;
      for (diIter = listOfItemsToDrop.begin() + 1; diIter != listOfItemsToDrop.end(); diIter++)
      {
        if (firstParent != (*diIter)->GetParent())
        {
          isValidDragAndDropOperation = false;
          break;
        }
      }
    }

    // dragging from one parent to another
    if ((!m_AllowHierarchyChange) && isValidDragAndDropOperation)
    {
      if (row == -1) // drag onto a node
      {
        isValidDragAndDropOperation = listOfItemsToDrop[0]->GetParent() == parentItem;
      }
      else // drag between nodes
      {
        isValidDragAndDropOperation = listOfItemsToDrop[0]->GetParent() == dropItem;
      }
    }

    // dragging on a child node of one the dragged nodes
    {
      QList<TreeItem *>::iterator diIter;
      for (diIter = listOfItemsToDrop.begin(); diIter != listOfItemsToDrop.end(); diIter++)
      {
        TreeItem *tempItem = dropItem;

        while (tempItem != m_Root)
        {
          tempItem = tempItem->GetParent();
          if (tempItem == *diIter)
          {
            isValidDragAndDropOperation = false;
          }
        }
      }
    }

    if (!isValidDragAndDropOperation)
      return isValidDragAndDropOperation;

    if (listOfItemsToDrop[0] != dropItem && isValidDragAndDropOperation)
    {
      // Retrieve the index of where we are dropping stuff.
      QModelIndex parentModelIndex = this->IndexFromTreeItem(parentItem);

      int dragIndex = 0;

      // Iterate through the list of TreeItem (which may be at non-consecutive indexes).
      QList<TreeItem *>::iterator diIter;
      for (diIter = listOfItemsToDrop.begin(); diIter != listOfItemsToDrop.end(); diIter++)
      {
        TreeItem *itemToDrop = *diIter;

        // if the item is dragged down we have to compensate its final position for the
        // fact it is deleted lateron, this only applies if it is dragged within the same level
        if ((itemToDrop->GetIndex() < row) && (itemToDrop->GetParent() == dropItem))
        {
          dragIndex = 1;
        }

        // Here we assume that as you remove items, one at a time, that GetIndex() will be valid.
        this->beginRemoveRows(
          this->IndexFromTreeItem(itemToDrop->GetParent()), itemToDrop->GetIndex(), itemToDrop->GetIndex());
        itemToDrop->GetParent()->RemoveChild(itemToDrop);
        this->endRemoveRows();
      }

      // row = -1 dropped on an item, row != -1 dropped  in between two items
      // Select the target index position, or put it at the end of the list.
      int dropIndex = 0;
      if (row != -1)
      {
        if (dragIndex == 0)
          dropIndex = std::min(row, parentItem->GetChildCount() - 1);
        else
          dropIndex = std::min(row - 1, parentItem->GetChildCount() - 1);
      }
      else
      {
        dropIndex = dropItem->GetIndex();
      }

      QModelIndex dropItemModelIndex = this->IndexFromTreeItem(dropItem);
      if ((row == -1 && dropItemModelIndex.row() == -1) || dropItemModelIndex.row() > parentItem->GetChildCount())
        dropIndex = parentItem->GetChildCount() - 1;

      // Now insert items again at the drop item position

      if (m_AllowHierarchyChange)
      {
        this->beginInsertRows(dropItemModelIndex, dropIndex, dropIndex + listOfItemsToDrop.size() - 1);
      }
      else
      {
        this->beginInsertRows(parentModelIndex, dropIndex, dropIndex + listOfItemsToDrop.size() - 1);
      }

      for (diIter = listOfItemsToDrop.begin(); diIter != listOfItemsToDrop.end(); diIter++)
      {
        // dropped on node, behaviour depends on preference setting
        if (m_AllowHierarchyChange)
        {
          auto dataStorage = m_DataStorage.Lock();

          m_BlockDataStorageEvents = true;
          mitk::DataNode *droppedNode = (*diIter)->GetDataNode();
          mitk::DataNode *dropOntoNode = dropItem->GetDataNode();
          dataStorage->Remove(droppedNode);
          dataStorage->Add(droppedNode, dropOntoNode);
          m_BlockDataStorageEvents = false;

          dropItem->InsertChild((*diIter), dropIndex);
        }
        else
        {
          if (row == -1) // drag onto a node
          {
            parentItem->InsertChild((*diIter), dropIndex);
          }
          else // drag between nodes
          {
            dropItem->InsertChild((*diIter), dropIndex);
          }
        }

        dropIndex++;
      }
      this->endInsertRows();

      // Change Layers to match.
      this->AdjustLayerProperty();
    }
  }
  else if (data->hasFormat("application/x-mitk-datanodes"))
  {
    returnValue = true;

    int numberOfNodesDropped = 0;

    QList<mitk::DataNode *> dataNodeList = QmitkMimeTypes::ToDataNodePtrList(data);
    mitk::DataNode *node = nullptr;
    foreach (node, dataNodeList)
    {
      if (node && !m_DataStorage.IsExpired() && !m_DataStorage.Lock()->Exists(node))
      {
        m_DataStorage.Lock()->Add(node);
        mitk::BaseData::Pointer basedata = node->GetData();

        if (basedata.IsNotNull())
        {
          mitk::RenderingManager::GetInstance()->InitializeViews(
            basedata->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true);

          numberOfNodesDropped++;
        }
      }
    }
    // Only do a rendering update, if we actually dropped anything.
    if (numberOfNodesDropped > 0)
    {
      mitk::RenderingManager::GetInstance()->RequestUpdateAll();
    }
  }
Example #18
0
void EditorPluginSettings::update_plugins() {

	plugin_list->clear();

	DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
	Error err = da->change_dir("res://addons");
	if (err != OK) {
		memdelete(da);
		return;
	}

	updating = true;

	TreeItem *root = plugin_list->create_item();

	da->list_dir_begin();

	String d = da->get_next();

	Vector<String> plugins;

	while (d != String()) {

		bool dir = da->current_is_dir();
		String path = "res://addons/" + d + "/plugin.cfg";

		if (dir && FileAccess::exists(path)) {

			plugins.push_back(d);
		}

		d = da->get_next();
	}

	da->list_dir_end();
	memdelete(da);

	plugins.sort();

	for (int i = 0; i < plugins.size(); i++) {

		Ref<ConfigFile> cf;
		cf.instance();
		String path = "res://addons/" + plugins[i] + "/plugin.cfg";

		Error err2 = cf->load(path);

		if (err2 != OK) {
			WARN_PRINTS("Can't load plugin config: " + path);
		} else if (!cf->has_section_key("plugin", "name")) {
			WARN_PRINTS("Plugin misses plugin/name: " + path);
		} else if (!cf->has_section_key("plugin", "author")) {
			WARN_PRINTS("Plugin misses plugin/author: " + path);
		} else if (!cf->has_section_key("plugin", "version")) {
			WARN_PRINTS("Plugin misses plugin/version: " + path);
		} else if (!cf->has_section_key("plugin", "description")) {
			WARN_PRINTS("Plugin misses plugin/description: " + path);
		} else if (!cf->has_section_key("plugin", "script")) {
			WARN_PRINTS("Plugin misses plugin/script: " + path);
		} else {

			String d2 = plugins[i];
			String name = cf->get_value("plugin", "name");
			String author = cf->get_value("plugin", "author");
			String version = cf->get_value("plugin", "version");
			String description = cf->get_value("plugin", "description");
			String script = cf->get_value("plugin", "script");

			TreeItem *item = plugin_list->create_item(root);
			item->set_text(0, name);
			item->set_tooltip(0, "Name: " + name + "\nPath: " + path + "\nMain Script: " + script + "\nDescription: " + description);
			item->set_metadata(0, d2);
			item->set_text(1, version);
			item->set_metadata(1, script);
			item->set_text(2, author);
			item->set_metadata(2, description);
			item->set_cell_mode(3, TreeItem::CELL_MODE_RANGE);
			item->set_range_config(3, 0, 1, 1);
			item->set_text(3, "Inactive,Active");
			item->set_editable(3, true);
			item->add_button(4, get_icon("Edit", "EditorIcons"), BUTTON_PLUGIN_EDIT, false, TTR("Edit Plugin"));

			if (EditorNode::get_singleton()->is_addon_plugin_enabled(d2)) {
				item->set_custom_color(3, get_color("success_color", "Editor"));
				item->set_range(3, 1);
			} else {
				item->set_custom_color(3, get_color("disabled_font_color", "Editor"));
				item->set_range(3, 0);
			}
		}
	}

	updating = false;
}
Example #19
0
Variant ScenesDock::get_drag_data_fw(const Point2& p_point,Control* p_from) {

	if (p_from==tree) {

		TreeItem *selected = tree->get_selected();
		if (!selected)
			return Variant();

		String path = selected->get_metadata(0);
		if (path==String())
			return Variant();
		if (!path.ends_with("/"))
			path=path+"/";
		Vector<String> paths;
		paths.push_back(path);
		Dictionary d = EditorNode::get_singleton()->drag_files(paths,p_from);

		if (selected->get_parent() && tree->get_root()->get_children()==selected->get_parent()) {
			//a favorite.. treat as such
			d["type"]="favorite";
		}

		return d;

	}

	if (p_from==files) {

		List<int> seldirs;
		List<int> selfiles;

		for (int i = 0; i<files->get_item_count(); i++) {
			if (files->is_selected(i)) {
				String path = files->get_item_metadata(i);
				if (path.ends_with("/"))
					seldirs.push_back(i);
				else
					selfiles.push_back(i);
			}
		}

		if (seldirs.empty() && selfiles.empty())
			return Variant();
		//if (seldirs.size() && selfiles.size())
		//	return Variant(); //can't really mix files and dirs (i think?) - yes you can, commenting

		/*if (selfiles.size()==1) {
			Ref<Resource> resource = ResourceLoader::load(files->get_item_metadata(selfiles.front()->get()));
			if (resource.is_valid()) {
				return EditorNode::get_singleton()->drag_resource(resource,p_from);
			}
		}*/

		if (selfiles.size()>0 && seldirs.size()==0) {
			Vector<String> fnames;
			for(List<int>::Element *E=selfiles.front();E;E=E->next()) {
				fnames.push_back(files->get_item_metadata(E->get()));
			}
			return EditorNode::get_singleton()->drag_files(fnames,p_from);
		}

		if (selfiles.size()>0 || seldirs.size()>0) {
			Vector<String> fnames;
			for(List<int>::Element *E=selfiles.front();E;E=E->next()) {
				fnames.push_back(files->get_item_metadata(E->get()));
			}
			for(List<int>::Element *E=seldirs.front();E;E=E->next()) {
				fnames.push_back(files->get_item_metadata(E->get()));
			}
			return EditorNode::get_singleton()->drag_files_and_dirs(fnames,p_from);
		}

	}

	return Variant();
}
Example #20
0
INT_PTR CALLBACK Manager::ManagerDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
    case WM_INITDIALOG:
    {
        TranslateDialogDefault(hwndDlg);

        SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)Utils::loadIconEx("main"));
        SendDlgItemMessage(hwndDlg, IDC_BTN_SELECTALL, BUTTONSETASFLATBTN, 0, 0);
        SendDlgItemMessage(hwndDlg, IDC_BTN_SELECTALL, BM_SETIMAGE, IMAGE_ICON, (LPARAM)Skin_LoadIcon(SKINICON_OTHER_TICK));
        SendDlgItemMessage(hwndDlg, IDC_BTN_SELECTALL, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Select All"), BATF_TCHAR);
        SendDlgItemMessage(hwndDlg, IDC_BTN_DESELECTALL, BUTTONSETASFLATBTN, 0, 0);
        SendDlgItemMessage(hwndDlg, IDC_BTN_DESELECTALL, BM_SETIMAGE, IMAGE_ICON, (LPARAM)Skin_LoadIcon(SKINICON_OTHER_NOTICK));
        SendDlgItemMessage(hwndDlg, IDC_BTN_DESELECTALL, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Clear All"), BATF_TCHAR);
        SendDlgItemMessage(hwndDlg, IDC_BTN_DELETEFROMLIST, BUTTONSETASFLATBTN, 0, 0);
        SendDlgItemMessage(hwndDlg, IDC_BTN_DELETEFROMLIST, BM_SETIMAGE, IMAGE_ICON, (LPARAM)Utils::loadIconEx("clear"));
        SendDlgItemMessage(hwndDlg, IDC_BTN_DELETEFROMLIST, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Delete from List"), BATF_TCHAR);
        SendDlgItemMessage(hwndDlg, IDC_BTN_DELETE, BUTTONSETASFLATBTN, 0, 0);
        SendDlgItemMessage(hwndDlg, IDC_BTN_DELETE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)Utils::loadIconEx("delete"));
        SendDlgItemMessage(hwndDlg, IDC_BTN_DELETE, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Delete from FTP"), BATF_TCHAR);
        SendDlgItemMessage(hwndDlg, IDC_BTN_CLOSE, BUTTONSETASFLATBTN, 0, 0);
        SendDlgItemMessage(hwndDlg, IDC_BTN_CLOSE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)Skin_LoadIcon(SKINICON_OTHER_EXIT));
        SendDlgItemMessage(hwndDlg, IDC_BTN_CLOSE, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Close"), BATF_TCHAR);

        return TRUE;
    }
    case WM_COMMAND:
    {
        if (HIWORD(wParam) == BN_CLICKED)
        {
            switch (LOWORD(wParam))
            {
            case IDC_BTN_DELETE:
            {
                for (UINT i = 0; i < manDlg->items.size(); i++)
                {
                    TreeItem *item = manDlg->items[i];
                    if (item->getState() == STATE_CHECKED)
                    {
                        DeleteJob *job = new DeleteJob(DBEntry::get(item->fileID), item);
                        job->start();
                    }
                }
                break;
            }
            case IDC_BTN_DELETEFROMLIST:
            {
                for (UINT i = 0; i < manDlg->items.size(); i++)
                {
                    TreeItem *item = manDlg->items[i];
                    if (item->getState() == STATE_CHECKED)
                        item->remove();
                }
                break;
            }
            case IDC_BTN_SELECTALL:
            case IDC_BTN_DESELECTALL:
            {
                UINT newState = (LOWORD(wParam) == IDC_BTN_SELECTALL) ?
                                TreeItem::_CHECKED() : TreeItem::_UNCHECKED();

                for (UINT i = 0; i < manDlg->items.size(); i++)
                    manDlg->items[i]->setState(newState);

                break;
            }
            case IDC_BTN_CLOSE:
            {
                DestroyWindow(hwndDlg);
                break;
            }
            }
        }

        break;
    }
    case WM_NOTIFY:
    {
        if (((LPNMHDR)lParam)->idFrom == IDC_FILELIST)
        {
            switch(((LPNMHDR)lParam)->code)
            {
            case TVN_KEYDOWN:
                if (((LPNMTVKEYDOWN)lParam)->wVKey != VK_SPACE)
                    break;
            case NM_CLICK:
            {
                HTREEITEM hItem;
                TVHITTESTINFO hti = {0};
                hti.pt.x = (short)LOWORD(GetMessagePos());
                hti.pt.y = (short)HIWORD(GetMessagePos());
                ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt);
                if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti) || ((LPNMHDR)lParam)->code == TVN_KEYDOWN)
                {
                    if (((LPNMHDR)lParam)->code == TVN_KEYDOWN)
                    {
                        hti.flags |= TVHT_ONITEMSTATEICON;
                        hItem = TreeView_GetSelection(((LPNMHDR)lParam)->hwndFrom);
                    }
                    else
                    {
                        hItem = hti.hItem;
                    }

                    TreeItem *item = manDlg->getItem(hItem);
                    if (item && (hti.flags & TVHT_ONITEMSTATEICON))
                    {
                        if (item->isRoot())
                        {
                            for (UINT i = 0; i < manDlg->items.size(); i++)
                            {
                                if (manDlg->items[i]->parent == item->handle)
                                    manDlg->items[i]->toggleState();
                            }
                        }
                        else
                        {
                            item->toggleState();
                        }
                    }
                }
                return TRUE;
            }
            case NM_RCLICK:
            {
                TVHITTESTINFO hti;
                hti.pt.x = (short)LOWORD(GetMessagePos());
                hti.pt.y = (short)HIWORD(GetMessagePos());
                ScreenToClient(manDlg->hwndFileTree, &hti.pt);
                if (TreeView_HitTest(manDlg->hwndFileTree, &hti))
                {
                    HTREEITEM hItem = hti.hItem;
                    TreeItem *item = manDlg->getItem(hItem);
                    if (item && !item->isRoot())
                    {
                        POINT pt;
                        GetCursorPos(&pt);
                        SetForegroundWindow(hwndDlg);
                        HMENU hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_MENU_MANAGER));
                        if (hMenu)
                        {
                            HMENU hPopupMenu = GetSubMenu(hMenu, 0);
                            TranslateMenu(hPopupMenu);
                            int command = TrackPopupMenu(hPopupMenu, TPM_LEFTALIGN | TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, NULL);
                            switch (command)
                            {

                            case IDM_DELETEFROMLIST:
                            {
                                item->remove();
                                break;
                            }
                            case IDM_DELETEFROMFTP:
                            {
                                DeleteJob *job = new DeleteJob(DBEntry::get(item->fileID), item);
                                job->start();
                                break;
                            }
                            case IDM_COPYLINK:
                            case IDM_DOWNLOAD:
                            {
                                int ftpNum = manDlg->indexOf(item->parent);
                                if (ftpNum != -1)
                                {
                                    char buff[256];

                                    DBEntry *entry = DBEntry::get(item->fileID);
                                    Utils::createFileDownloadLink(ftpList[ftpNum]->szUrl, entry->szFileName, buff, sizeof(buff));
                                    delete entry;

                                    if (command == IDM_COPYLINK)
                                        Utils::copyToClipboard(buff);
                                    else
                                        ShellExecuteA(NULL, "open", buff, NULL, NULL, SW_SHOWNORMAL);
                                }
                                break;
                            }
                            }
                            DestroyMenu(hMenu);
                        }
                    }
                }
                return TRUE;
            }
            case TVN_GETINFOTIP:
            {
                NMTVGETINFOTIP *tvInfoTip = (NMTVGETINFOTIP *)lParam;
                TreeItem *item = manDlg->getItem(tvInfoTip->hItem);

                if (item)
                {
                    if (item->stzToolTip[0])
                    {
                        _tcsncpy(tvInfoTip->pszText, item->stzToolTip, tvInfoTip->cchTextMax - 1);
                        tvInfoTip->pszText[tvInfoTip->cchTextMax - 1] = 0;
                    }
                }

                return TRUE;
            }
            }
        }

        break;
    }
    case WM_CLOSE:
    {
        DestroyWindow(hwndDlg);
        return TRUE;
    }
    case WM_DESTROY:
    {
        delete manDlg;
        return TRUE;
    }
    }

    return FALSE;
}
Example #21
0
void ScenesDock::drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from){

	if (!can_drop_data_fw(p_point,p_data,p_from))
		return;
	Dictionary drag_data = p_data;

	if (drag_data.has("type") && String(drag_data["type"])=="favorite") {

		//moving favorite around
		TreeItem *ti = tree->get_item_at_pos(p_point);
		if (!ti)
			return;

		Vector<String> files = drag_data["files"];

		ERR_FAIL_COND(files.size()!=1);

		String swap = files[0];
		if (swap!="res://" && swap.ends_with("/")) {
			swap=swap.substr(0,swap.length()-1);
		}

		int what = tree->get_drop_section_at_pos(p_point);

		TreeItem *swap_item=NULL;

		if (ti==tree->get_root()->get_children()) {
			swap_item=tree->get_root()->get_children()->get_children();

		} else if (ti->get_parent() && tree->get_root()->get_children()==ti->get_parent()) {
			if (what==-1) {
				swap_item=ti;
			} else {
				swap_item=ti->get_next();
			}
		}

		String swap_with;

		if (swap_item) {
			swap_with=swap_item->get_metadata(0);
			if (swap_with!="res://" && swap_with.ends_with("/")) {
				swap_with=swap_with.substr(0,swap_with.length()-1);
			}
		}

		if (swap==swap_with)
			return;

		Vector<String> dirs = EditorSettings::get_singleton()->get_favorite_dirs();

		ERR_FAIL_COND(dirs.find(swap)==-1);
		ERR_FAIL_COND(swap_with!=String() && dirs.find(swap_with)==-1);

		dirs.erase(swap);

		if (swap_with==String()) {
			dirs.push_back(swap);
		} else {
			int idx = dirs.find(swap_with);
			dirs.insert(idx,swap);
		}

		EditorSettings::get_singleton()->set_favorite_dirs(dirs);
		_update_tree();
		return;

	}

	if (drag_data.has("type") && String(drag_data["type"])=="resource") {
		Ref<Resource> res = drag_data["resource"];

		if (!res.is_valid()) {
			return;
		}


		if (p_from==tree) {

			TreeItem *ti = tree->get_item_at_pos(p_point);
			if (!ti)
				return;
			String path = ti->get_metadata(0);

			if (path==String())
				return;

			EditorNode::get_singleton()->save_resource_as(res,path);
			return;

		}

		if (p_from==files) {
			String save_path=path;

			int at_pos = files->get_item_at_pos(p_point);
			if (at_pos!=-1) {
				String to_dir = files->get_item_metadata(at_pos);
				if (to_dir.ends_with("/")) {
					save_path=to_dir;
					if (save_path!="res://")
						save_path=save_path.substr(0,save_path.length()-1);
				}

			}

			EditorNode::get_singleton()->save_resource_as(res,save_path);
			return;
		}
	}

	if (drag_data.has("type") && ( String(drag_data["type"])=="files" || String(drag_data["type"])=="files_and_dirs")) {

		if (p_from==files || p_from==tree) {

			String to_dir;

			if (p_from==files) {

				int at_pos = files->get_item_at_pos(p_point);
				ERR_FAIL_COND(at_pos==-1);
				to_dir = files->get_item_metadata(at_pos);
			}  else {
				TreeItem *ti = tree->get_item_at_pos(p_point);
				if (!ti)
					return;
				to_dir = ti->get_metadata(0);
				ERR_FAIL_COND(to_dir==String());

			}

			if (to_dir!="res://" && to_dir.ends_with("/")) {
				to_dir=to_dir.substr(0,to_dir.length()-1);
			}

			Vector<String> fnames = drag_data["files"];
			move_files.clear();
			move_dirs.clear();

			for(int i=0;i<fnames.size();i++) {
				if (fnames[i].ends_with("/"))
					move_dirs.push_back(fnames[i]);
				else
					move_files.push_back(fnames[i]);
			}

			_move_operation(to_dir);
		}
	}

}
Example #22
0
void EditorHelpSearch::_update_search() {

	search_options->clear();
	search_options->set_hide_root(true);

	/*
	TreeItem *root = search_options->create_item();
	_parse_fs(EditorFileSystem::get_singleton()->get_filesystem());
*/

	List<String> type_list;
	ObjectTypeDB::get_type_list(&type_list);

	DocData *doc=EditorHelp::get_doc_data();
	String term = search_box->get_text();
	if (term.length()<3)
		return;

	TreeItem *root = search_options->create_item();



	Ref<Texture> def_icon = get_icon("Node","EditorIcons");
	//classes first
	for (Map<String,DocData::ClassDoc>::Element *E=doc->class_list.front();E;E=E->next()) {

		if (E->key().findn(term)!=-1) {

			TreeItem *item = search_options->create_item(root);
			item->set_metadata(0,"class_name:"+E->key());
			item->set_text(0,E->key()+" (Class)");
			if (has_icon(E->key(),"EditorIcons"))
				item->set_icon(0,get_icon(E->key(),"EditorIcons"));
			else
				item->set_icon(0,def_icon);


		}

	}

	//class methods, etc second
	for (Map<String,DocData::ClassDoc>::Element *E=doc->class_list.front();E;E=E->next()) {


		DocData::ClassDoc & c = E->get();

		Ref<Texture> cicon;
		if (has_icon(E->key(),"EditorIcons"))
			cicon=get_icon(E->key(),"EditorIcons");
		else
			cicon=def_icon;

		for(int i=0;i<c.methods.size();i++) {

			if (c.methods[i].name.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_method:"+E->key()+":"+c.methods[i].name);
				item->set_text(0,E->key()+"."+c.methods[i].name+" (Method)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.signals.size();i++) {

			if (c.signals[i].name.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_signal:"+E->key()+":"+c.signals[i].name);
				item->set_text(0,E->key()+"."+c.signals[i].name+" (Signal)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.constants.size();i++) {

			if (c.constants[i].name.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_constant:"+E->key()+":"+c.constants[i].name);
				item->set_text(0,E->key()+"."+c.constants[i].name+" (Constant)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.properties.size();i++) {

			if (c.properties[i].name.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_property:"+E->key()+":"+c.properties[i].name);
				item->set_text(0,E->key()+"."+c.properties[i].name+" (Property)");
				item->set_icon(0,cicon);
			}
		}

	}

	//same but descriptions

	for (Map<String,DocData::ClassDoc>::Element *E=doc->class_list.front();E;E=E->next()) {


		DocData::ClassDoc & c = E->get();

		Ref<Texture> cicon;
		if (has_icon(E->key(),"EditorIcons"))
			cicon=get_icon(E->key(),"EditorIcons");
		else
			cicon=def_icon;

		if (c.description.findn(term)!=-1) {


			TreeItem *item = search_options->create_item(root);
			item->set_metadata(0,"class_desc:"+E->key());
			item->set_text(0,E->key()+" (Class Description)");
			item->set_icon(0,cicon);

		}

		for(int i=0;i<c.methods.size();i++) {

			if (c.methods[i].description.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_method_desc:"+E->key()+":"+c.methods[i].name);
				item->set_text(0,E->key()+"."+c.methods[i].name+" (Method Description)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.signals.size();i++) {

			if (c.signals[i].description.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_signal:"+E->key()+":"+c.signals[i].name);
				item->set_text(0,E->key()+"."+c.signals[i].name+" (Signal Description)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.constants.size();i++) {

			if (c.constants[i].description.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_constant:"+E->key()+":"+c.constants[i].name);
				item->set_text(0,E->key()+"."+c.constants[i].name+" (Constant Description)");
				item->set_icon(0,cicon);
			}
		}

		for(int i=0;i<c.properties.size();i++) {

			if (c.properties[i].description.findn(term)!=-1) {

				TreeItem *item = search_options->create_item(root);
				item->set_metadata(0,"class_property_desc:"+E->key()+":"+c.properties[i].name);
				item->set_text(0,E->key()+"."+c.properties[i].name+" (Property Description)");
				item->set_icon(0,cicon);
			}
		}

	}

	get_ok()->set_disabled(root->get_children()==NULL);

}
Example #23
0
      OpenGL::OpenGL (QWidget* parent, const GL::Format& format) : QDialog (parent)
      {
        TreeModel* model = new TreeModel (this);

        TreeItem* root = model->rootItem;

        GLint i;
        gl::GetIntegerv (gl::MAJOR_VERSION, &i);
        std::string text = str(i) + ".";
        gl::GetIntegerv (gl::MINOR_VERSION, &i);
        text += str(i);

        root->appendChild (new TreeItem ("API version", text, root));
        root->appendChild (new TreeItem ("Renderer", (const char*) gl::GetString (gl::RENDERER), root));
        root->appendChild (new TreeItem ("Vendor", (const char*) gl::GetString (gl::VENDOR), root));
        root->appendChild (new TreeItem ("Version", (const char*) gl::GetString (gl::VERSION), root));

        TreeItem* bit_depths = new TreeItem ("Bit depths", std::string(), root);
        root->appendChild (bit_depths);

        bit_depths->appendChild (new TreeItem ("red", str (format.redBufferSize()), bit_depths));
        bit_depths->appendChild (new TreeItem ("green", str (format.greenBufferSize()), bit_depths));
        bit_depths->appendChild (new TreeItem ("blue", str (format.blueBufferSize()), bit_depths));
        bit_depths->appendChild (new TreeItem ("alpha", str (format.alphaBufferSize()), bit_depths));
        bit_depths->appendChild (new TreeItem ("depth", str (format.depthBufferSize()), bit_depths));
        bit_depths->appendChild (new TreeItem ("stencil", str (format.stencilBufferSize()), bit_depths));

#if QT_VERSION >= 0x050400
        root->appendChild (new TreeItem ("Buffering", format.swapBehavior() == QSurfaceFormat::SingleBuffer ? "single" :
               ( format.swapBehavior() == QSurfaceFormat::DoubleBuffer ? "double" : "triple" ), root));
#else
        root->appendChild (new TreeItem ("Buffering", format.doubleBuffer() ? "double" : "single", root));
#endif
        root->appendChild (new TreeItem ("VSync", format.swapInterval() ? "on" : "off", root));
        root->appendChild (new TreeItem ("Multisample anti-aliasing", format.samples() ? str(format.samples()).c_str() : "off", root));

        gl::GetIntegerv (gl::MAX_TEXTURE_SIZE, &i);
        root->appendChild (new TreeItem ("Maximum texture size", str (i), root));

        QTreeView* view = new QTreeView;
        view->setModel (model);
        view->resizeColumnToContents (0);
        view->resizeColumnToContents (1);
        view->setMinimumSize (500, 200);

        QDialogButtonBox* buttonBox = new QDialogButtonBox (QDialogButtonBox::Ok);
        connect (buttonBox, SIGNAL (accepted()), this, SLOT (accept()));

        QVBoxLayout* layout = new QVBoxLayout (this);
        layout->addWidget (view);
        layout->addWidget (buttonBox);
        setLayout (layout);

        setWindowTitle (tr ("OpenGL information"));
        setSizeGripEnabled (true);
        adjustSize();
      }
Example #24
0
void CreateDialog::_update_search() {


    search_options->clear();

    /*
    TreeItem *root = search_options->create_item();
    _parse_fs(EditorFileSystem::get_singleton()->get_filesystem());
    */

    List<StringName> type_list;
    ObjectTypeDB::get_type_list(&type_list);

    HashMap<String,TreeItem*> types;

    TreeItem *root = search_options->create_item();

    root->set_text(0,base_type);

    List<StringName>::Element *I=type_list.front();
    TreeItem *to_select=NULL;

    for(; I; I=I->next()) {


        String type=I->get();


        if (!ObjectTypeDB::can_instance(type))
            continue; // cant create what can't be instanced
        if (search_box->get_text()=="")
            add_type(type,types,root,&to_select);
        else {

            bool found=false;
            String type=I->get();
            while(type!="" && ObjectTypeDB::is_type(type,base_type) && type!=base_type) {
                if (type.findn(search_box->get_text())!=-1) {

                    found=true;
                    break;
                }

                type=ObjectTypeDB::type_inherits_from(type);
            }


            if (found)
                add_type(I->get(),types,root,&to_select);
        }

        if (EditorNode::get_editor_data().get_custom_types().has(type)) {
            //there are custom types based on this... cool.
            //print_line("there are custom types");


            const Vector<EditorData::CustomType> &ct = EditorNode::get_editor_data().get_custom_types()[type];
            for(int i=0; i<ct.size(); i++) {

                bool show = search_box->get_text()=="" || ct[i].name.findn(search_box->get_text())!=-1;

                if (!show)
                    continue;
                if (!types.has(type))
                    add_type(type,types,root,&to_select);

                TreeItem *ti;
                if (types.has(type) )
                    ti=types[type];
                else
                    ti=search_options->get_root();


                TreeItem *item = search_options->create_item(ti);
                item->set_metadata(0,type);
                item->set_text(0,ct[i].name);
                if (ct[i].icon.is_valid()) {
                    item->set_icon(0,ct[i].icon);

                }

                if (!to_select && (search_box->get_text()=="" || ct[i].name.findn(search_box->get_text())!=-1)) {
                    to_select=item;
                }

            }

        }
    }

    if (to_select)
        to_select->select(0);

    get_ok()->set_disabled(root->get_children()==NULL);

}
void EditorAutoloadSettings::_autoload_button_pressed(Object *p_item, int p_column, int p_button) {

	TreeItem *ti = Object::cast_to<TreeItem>(p_item);

	String name = "autoload/" + ti->get_text(0);

	UndoRedo *undo_redo = EditorNode::get_undo_redo();

	switch (p_button) {

		case BUTTON_MOVE_UP:
		case BUTTON_MOVE_DOWN: {

			TreeItem *swap = NULL;

			if (p_button == BUTTON_MOVE_UP) {
				swap = ti->get_prev();
			} else {
				swap = ti->get_next();
			}

			if (!swap)
				return;

			String swap_name = "autoload/" + swap->get_text(0);

			int order = ProjectSettings::get_singleton()->get_order(name);
			int swap_order = ProjectSettings::get_singleton()->get_order(swap_name);

			undo_redo->create_action(TTR("Move Autoload"));

			undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", name, swap_order);
			undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", name, order);

			undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", swap_name, order);
			undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", swap_name, swap_order);

			undo_redo->add_do_method(this, "update_autoload");
			undo_redo->add_undo_method(this, "update_autoload");

			undo_redo->add_do_method(this, "emit_signal", autoload_changed);
			undo_redo->add_undo_method(this, "emit_signal", autoload_changed);

			undo_redo->commit_action();
		} break;
		case BUTTON_DELETE: {

			int order = ProjectSettings::get_singleton()->get_order(name);

			undo_redo->create_action(TTR("Remove Autoload"));

			undo_redo->add_do_property(ProjectSettings::get_singleton(), name, Variant());

			undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, ProjectSettings::get_singleton()->get(name));
			undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_persisting", name, true);
			undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", order);

			undo_redo->add_do_method(this, "update_autoload");
			undo_redo->add_undo_method(this, "update_autoload");

			undo_redo->add_do_method(this, "emit_signal", autoload_changed);
			undo_redo->add_undo_method(this, "emit_signal", autoload_changed);

			undo_redo->commit_action();
		} break;
	}
}
Example #26
0
void CreateDialog::update_tree() {

    tree->clear();

    List<String> type_list;
    ObjectTypeDB::get_type_list(&type_list);

    HashMap<String,TreeItem*> types;

    TreeItem *root = tree->create_item();

    root->set_text(0,base);

    List<String>::Element *I=type_list.front();

    for(; I; I=I->next()) {


        String type=I->get();


        if (!ObjectTypeDB::can_instance(type))
            continue; // cant create what can't be instanced
        if (filter->get_text()=="")
            add_type(type,types,root);
        else {

            bool found=false;
            String type=I->get();
            while(type!="" && ObjectTypeDB::is_type(type,base) && type!=base) {
                if (type.findn(filter->get_text())!=-1) {

                    found=true;
                    break;
                }

                type=ObjectTypeDB::type_inherits_from(type);
            }


            if (found)
                add_type(I->get(),types,root);
        }

        if (EditorNode::get_editor_data().get_custom_types().has(type)) {
            //there are custom types based on this... cool.


            const Vector<EditorData::CustomType> &ct = EditorNode::get_editor_data().get_custom_types()[type];
            for(int i=0; i<ct.size(); i++) {

                bool show = filter->get_text()=="" || ct[i].name.findn(filter->get_text())!=-1;

                if (!show)
                    continue;
                if (!types.has(type))
                    add_type(type,types,root);

                TreeItem *ti;
                if (types.has(type) )
                    ti=types[type];
                else
                    ti=tree->get_root();


                TreeItem *item = tree->create_item(ti);
                item->set_metadata(0,type);
                item->set_text(0,ct[i].name);
                if (ct[i].icon.is_valid()) {
                    item->set_icon(0,ct[i].icon);

                }
            }

        }
    }


}
void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_control) {

	TreeItem *ti = tree->get_item_at_pos(p_point);

	if (!ti)
		return;

	int section = tree->get_drop_section_at_pos(p_point);

	if (section < -1)
		return;

	String name;
	bool move_to_back = false;

	if (section < 0) {
		name = ti->get_text(0);
	} else if (ti->get_next()) {
		name = ti->get_next()->get_text(0);
	} else {
		name = ti->get_text(0);
		move_to_back = true;
	}

	int order = ProjectSettings::get_singleton()->get_order("autoload/" + name);

	AutoLoadInfo aux;
	List<AutoLoadInfo>::Element *E = NULL;

	if (!move_to_back) {
		aux.order = order;
		E = autoload_cache.find(aux);
	}

	Dictionary drop_data = p_data;
	PoolStringArray autoloads = drop_data["autoloads"];

	Vector<int> orders;
	orders.resize(autoload_cache.size());

	for (int i = 0; i < autoloads.size(); i++) {
		aux.order = ProjectSettings::get_singleton()->get_order("autoload/" + autoloads[i]);

		List<AutoLoadInfo>::Element *I = autoload_cache.find(aux);

		if (move_to_back) {
			autoload_cache.move_to_back(I);
		} else if (E != I) {
			autoload_cache.move_before(I, E);
		} else if (E->next()) {
			E = E->next();
		} else {
			break;
		}
	}

	int i = 0;

	for (List<AutoLoadInfo>::Element *E = autoload_cache.front(); E; E = E->next()) {
		orders[i++] = E->get().order;
	}

	orders.sort();

	UndoRedo *undo_redo = EditorNode::get_undo_redo();

	undo_redo->create_action(TTR("Rearrange Autoloads"));

	i = 0;

	for (List<AutoLoadInfo>::Element *E = autoload_cache.front(); E; E = E->next()) {
		undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", E->get().name, orders[i++]);
		undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", E->get().name, E->get().order);
	}

	orders.clear();

	undo_redo->add_do_method(this, "update_autoload");
	undo_redo->add_undo_method(this, "update_autoload");

	undo_redo->add_do_method(this, "emit_signal", autoload_changed);
	undo_redo->add_undo_method(this, "emit_signal", autoload_changed);

	undo_redo->commit_action();
}
Example #28
0
void CreateDialog::add_type(const String& p_type,HashMap<String,TreeItem*>& p_types,TreeItem *p_root,TreeItem **to_select) {

    if (p_types.has(p_type))
        return;
    if (!ObjectTypeDB::is_type(p_type,base_type) || p_type==base_type)
        return;

    String inherits=ObjectTypeDB::type_inherits_from(p_type);

    TreeItem *parent=p_root;


    if (inherits.length()) {

        if (!p_types.has(inherits)) {

            add_type(inherits,p_types,p_root,to_select);
        }

        if (p_types.has(inherits) )
            parent=p_types[inherits];
    }

    TreeItem *item = search_options->create_item(parent);
    item->set_text(0,p_type);
    if (!ObjectTypeDB::can_instance(p_type)) {
        item->set_custom_color(0, Color(0.5,0.5,0.5) );
        item->set_selectable(0,false);
    } else {

        if (!*to_select && (search_box->get_text()=="" || p_type.findn(search_box->get_text())!=-1)) {
            *to_select=item;
        }

    }

    if (bool(EditorSettings::get_singleton()->get("scenetree_editor/start_create_dialog_fully_expanded"))) {
        item->set_collapsed(false);
    } else {
        // don't collapse search results
        bool collapse = (search_box->get_text() == "");
        // don't collapse the root node
        collapse &= (item != p_root);
        // don't collapse abstract nodes on the first tree level
        collapse &= ((parent != p_root) || (ObjectTypeDB::can_instance(p_type)));
        item->set_collapsed(collapse);
    }

    const String& description = EditorHelp::get_doc_data()->class_list[p_type].brief_description;
    item->set_tooltip(0,description);


    if (has_icon(p_type,"EditorIcons")) {

        item->set_icon(0, get_icon(p_type,"EditorIcons"));
    }



    p_types[p_type]=item;
}
Example #29
0
MixxxLibraryFeature::MixxxLibraryFeature(QObject* parent,
                                         TrackCollection* pTrackCollection,
                                         ConfigObject<ConfigValue>* pConfig)
        : LibraryFeature(parent),
          kMissingTitle(tr("Missing Tracks")),
          kHiddenTitle(tr("Hidden Tracks")),
          m_pMissingView(NULL),
          m_pHiddenView(NULL),
          m_trackDao(pTrackCollection->getTrackDAO()),
          m_pConfig(pConfig),
          m_pTrackCollection(pTrackCollection) {
    QStringList columns;
    columns << "library." + LIBRARYTABLE_ID
            << "library." + LIBRARYTABLE_PLAYED
            << "library." + LIBRARYTABLE_TIMESPLAYED
            //has to be up here otherwise Played and TimesPlayed are not show
            << "library." + LIBRARYTABLE_ARTIST
            << "library." + LIBRARYTABLE_TITLE
            << "library." + LIBRARYTABLE_ALBUM
            << "library." + LIBRARYTABLE_ALBUMARTIST
            << "library." + LIBRARYTABLE_YEAR
            << "library." + LIBRARYTABLE_DURATION
            << "library." + LIBRARYTABLE_RATING
            << "library." + LIBRARYTABLE_GENRE
            << "library." + LIBRARYTABLE_COMPOSER
            << "library." + LIBRARYTABLE_GROUPING
            << "library." + LIBRARYTABLE_FILETYPE
            << "library." + LIBRARYTABLE_TRACKNUMBER
            << "library." + LIBRARYTABLE_KEY
            << "library." + LIBRARYTABLE_KEY_ID
            << "library." + LIBRARYTABLE_DATETIMEADDED
            << "library." + LIBRARYTABLE_BPM
            << "library." + LIBRARYTABLE_BPM_LOCK
            << "library." + LIBRARYTABLE_BITRATE
            << "track_locations.location"
            << "track_locations.fs_deleted"
            << "library." + LIBRARYTABLE_COMMENT
            << "library." + LIBRARYTABLE_MIXXXDELETED;

    QSqlQuery query(pTrackCollection->getDatabase());
    QString tableName = "library_cache_view";
    QString queryString = QString(
        "CREATE TEMPORARY VIEW IF NOT EXISTS %1 AS "
        "SELECT %2 FROM library "
        "INNER JOIN track_locations ON library.location = track_locations.id")
            .arg(tableName, columns.join(","));
    query.prepare(queryString);
    if (!query.exec()) {
        LOG_FAILED_QUERY(query);
    }

    // Strip out library. and track_locations.
    for (QStringList::iterator it = columns.begin();
         it != columns.end(); ++it) {
        if (it->startsWith("library.")) {
            *it = it->replace("library.", "");
        } else if (it->startsWith("track_locations.")) {
            *it = it->replace("track_locations.", "");
        }
    }

    BaseTrackCache* pBaseTrackCache = new BaseTrackCache(
        pTrackCollection, tableName, LIBRARYTABLE_ID, columns, true);
    connect(&m_trackDao, SIGNAL(trackDirty(int)),
            pBaseTrackCache, SLOT(slotTrackDirty(int)));
    connect(&m_trackDao, SIGNAL(trackClean(int)),
            pBaseTrackCache, SLOT(slotTrackClean(int)));
    connect(&m_trackDao, SIGNAL(trackChanged(int)),
            pBaseTrackCache, SLOT(slotTrackChanged(int)));
    connect(&m_trackDao, SIGNAL(tracksAdded(QSet<int>)),
            pBaseTrackCache, SLOT(slotTracksAdded(QSet<int>)));
    connect(&m_trackDao, SIGNAL(tracksRemoved(QSet<int>)),
            pBaseTrackCache, SLOT(slotTracksRemoved(QSet<int>)));
    connect(&m_trackDao, SIGNAL(dbTrackAdded(TrackPointer)),
            pBaseTrackCache, SLOT(slotDbTrackAdded(TrackPointer)));

    m_pBaseTrackCache = QSharedPointer<BaseTrackCache>(pBaseTrackCache);
    pTrackCollection->setTrackSource(m_pBaseTrackCache);

    // These rely on the 'default' track source being present.
    m_pLibraryTableModel = new LibraryTableModel(this, pTrackCollection, "mixxx.db.model.library");

    TreeItem* pRootItem = new TreeItem();
    TreeItem* pmissingChildItem = new TreeItem(kMissingTitle, kMissingTitle,
                                       this, pRootItem);
    TreeItem* phiddenChildItem = new TreeItem(kHiddenTitle, kHiddenTitle,
                                       this, pRootItem);
    pRootItem->appendChild(pmissingChildItem);
    pRootItem->appendChild(phiddenChildItem);

    m_childModel.setRootItem(pRootItem);
}
Example #30
0
// Purpose: Parsing all the folder and playlists of Traktor
// This is a complex operation since Traktor uses the concept of folders and playlist.
// A folder can contain folders and playlists. A playlist contains entries but no folders.
// In other words, Traktor uses a tree structure to organize music.
// Inner nodes represent folders while leaves are playlists.
TreeItem* TraktorFeature::parsePlaylists(QXmlStreamReader &xml) {

    qDebug() << "Process RootFolder";
    //Each playlist is unique and can be identified by a path in the tree structure.
    QString current_path = "";
    QMap<QString,QString> map;

    QString delimiter = "-->";

    TreeItem *rootItem = new TreeItem();
    TreeItem * parent = rootItem;

    QSqlQuery query_insert_to_playlists(m_database);
    query_insert_to_playlists.prepare("INSERT INTO traktor_playlists (name) "
                  "VALUES (:name)");

    QSqlQuery query_insert_to_playlist_tracks(m_database);
    query_insert_to_playlist_tracks.prepare(
        "INSERT INTO traktor_playlist_tracks (playlist_id, track_id, position) "
        "VALUES (:playlist_id, :track_id, :position)");

    while (!xml.atEnd() && !m_cancelImport) {
        //read next XML element
        xml.readNext();

        if (xml.isStartElement()) {
            if (xml.name() == "NODE") {
                QXmlStreamAttributes attr = xml.attributes();
                QString name = attr.value("NAME").toString();
                QString type = attr.value("TYPE").toString();
               //TODO: What happens if the folder node is a leaf (empty folder)
               // Idea: Hide empty folders :-)
               if (type == "FOLDER") {
                    current_path += delimiter;
                    current_path += name;
                    //qDebug() << "Folder: " +current_path << " has parent " << parent->data().toString();
                    map.insert(current_path, "FOLDER");
                    TreeItem * item = new TreeItem(name,current_path, this, parent);
                    parent->appendChild(item);
                    parent = item;
               } else if (type == "PLAYLIST") {
                    current_path += delimiter;
                    current_path += name;
                    //qDebug() << "Playlist: " +current_path << " has parent " << parent->data().toString();
                    map.insert(current_path, "PLAYLIST");

                    TreeItem * item = new TreeItem(name,current_path, this, parent);
                    parent->appendChild(item);
                    // process all the entries within the playlist 'name' having path 'current_path'
                    parsePlaylistEntries(xml, current_path,
                                         query_insert_to_playlists,
                                         query_insert_to_playlist_tracks);
                }
            }
        }

        if (xml.isEndElement()) {
            if (xml.name() == "NODE") {
                if (map.value(current_path) == "FOLDER") {
                    parent = parent->parent();
                }

                //Whenever we find a closing NODE, remove the last component of the path
                int lastSlash = current_path.lastIndexOf (delimiter);
                int path_length = current_path.size();

                current_path.remove(lastSlash, path_length - lastSlash);
            }
            //We leave the infinte loop, if twe have the closing "PLAYLIST" tag
            if (xml.name() == "PLAYLISTS") {
                break;
            }
        }
    }
    return rootItem;
}