2 * ModelCreaDevManagerTree.cpp
4 * Created on: 22/10/2012
8 #include "ModelCreaDevManagerTree.h"
12 #include <sys/types.h>
22 ModelCreaDevManagerTree::ModelCreaDevManagerTree()
26 ModelCreaDevManagerTree::~ModelCreaDevManagerTree()
30 bool ModelCreaDevManagerTree::CompareNodeItem(ModelCreaDevManagerTreeNode x, ModelCreaDevManagerTreeNode y)
35 string xName = x.GetName();
36 string yName = y.GetName();
37 unsigned char xType = x.GetType();
38 unsigned char yType = y.GetType();
40 while ((i < xName.length()) && (i < yName.length()))
42 if (tolower (xName[i]) < tolower (yName[i]))
48 else if (tolower (xName[i]) > tolower (yName[i]))
59 if (xName.length() < yName.length())
76 void ModelCreaDevManagerTree::addRoot(string path)
79 vector<string> breadcrumbs;
86 breadcrumbs.push_back(name);
90 for (int i = 0; i < breadcrumbs.size()-1; i++)
92 path += breadcrumbs[i] + "/";
94 name = breadcrumbs[breadcrumbs.size()-1];
95 this->projectRoots.push_back(ModelCreaDevManagerTreeNode(path,name,DT_DIR,0));
97 cout << "project root added: " << name << " in " << path << endl;
100 void ModelCreaDevManagerTree::populateNode(ModelCreaDevManagerTreeNode& node)
102 //cout << "populating " << node.GetName() << " path " << node.GetPath() << "..." << endl;
103 vector <ModelCreaDevManagerTreeNode>* nodes = new vector <ModelCreaDevManagerTreeNode>;
108 string path = node.GetPath()+node.GetName()+"/";
110 dp = opendir(path.c_str());
113 while ((ep = readdir (dp)) != NULL)
115 //cout << ep->d_name << endl;
116 if(strcmp(ep->d_name, ".") != 0 && strcmp(ep->d_name, "..") != 0 )
118 ModelCreaDevManagerTreeNode innerNode = ModelCreaDevManagerTreeNode(path, ep->d_name, ep->d_type, node.GetLevel()+1);
119 if (ep->d_type == DT_DIR)
121 this->populateNode(innerNode);
124 nodes->push_back(innerNode);
129 (void) closedir (dp);
131 sort (nodes->begin(), nodes->end(), CompareNodeItem);
133 node.SetChildren(*nodes);
137 cerr << "Couldn't open the directory" << endl;
141 void ModelCreaDevManagerTree::populateNode(string path)
143 if(path[path.size()-1] != '/')
145 cout << "searching " << path << endl;
146 for (int i = 0; i < this->projectRoots.size(); i++)
148 //cout << (this->projectRoots[i].GetPath() + this->projectRoots[i].GetName() + "/") << "..." << endl;
149 if(this->projectRoots[i].GetPath()+this->projectRoots[i].GetName()+"/" == path)
151 cout << "Populating Project: " << path << "..." << endl;
152 this->populateNode(this->projectRoots[i]);