TreeStore not showing in TreeView?



Hi,

     I'm attempting to load a directory structure into a TreeModel. 
Using the TreeStore example from the site, I've added a function:
ScanDirTree(Glib::ustring path, Gtk::TreeModel::iterator parentrow)

	This is a simple recursive function; if a directory entry is itself a
directory, then a row is created and the ScanDirTree recurses adding the
children, otherwise a row is added for the file.

     The problem is that the although the Model seems to be filling
correctly (confirmed by m_refTreeModel->get_string() on the parentrow
and current row), there's nothing displayed. 
     :(
     
     Can anyone telling what I'm doing wrong.  This is my first Gtkmm
program and i'm sure there's something simple lacking in my understanding.
     
     
     thanks, code follows.  
     
     Caspar


     
     The function is called, with a null iterator, in the contructor 
ExampleWindow::ExampleWindow(): m_Button_Quit("Quit")  between
m_TreeView.set_reorderable()  and  show_all_children()  .
     
     Apart from additions to the ExampleWindow class for the directory
path data (ustring) and removing the example code filling the TreeView
model, the example code is unchanged.

     The function is: 

bool ExampleWindow::ScanDirTree(Glib::ustring path,
Gtk::TreeModel::iterator parentrow)
{

	static unsigned long int id = 1;
	DIR *dp, *cdp;
	struct dirent *ep;
	Gtk::TreeModel::Row row;
	Gtk::TreeModel::Row childrow;
	
	Gtk::TreeModel::iterator irow;
	
	dp = opendir(path.c_str());
	if (!dp){
		std::cerr << "ScanDirTree: DP unable to open dir:" << path << std::endl;
		return 1;
	}
	
	while((ep = readdir(dp))){
		if((strcmp(ep->d_name, ".") && strcmp(ep->d_name, ".."))){   //If not
self or parent dir
			cdp = opendir((path + '/' + ep->d_name).c_str());
			if(cdp){
				(parentrow) ?
					irow = (m_refTreeModel->append(parentrow->children())) :
					irow = (m_refTreeModel->append());
				row = *irow;
				row[m_Columns.m_col_id] = id++;
				row[m_Columns.m_col_name] = ep->d_name;
				
				std::cerr << "ScanDirTree: DIR added = " << path << '/' <<
ep->d_name << "    id = " << (id - 1) << "   Self:" <<
m_refTreeModel->get_string(irow) << "   Parent:";
				(parentrow) ? std::cerr << m_refTreeModel->get_string(parentrow) <<
std::endl : std::cerr << "NULL" << std::endl;
				
				closedir(cdp);
				
				ScanDirTree(path + '/' + ep->d_name, irow);
			}else{
				(parentrow) ?
					irow = (m_refTreeModel->append(parentrow->children())) :
					irow = (m_refTreeModel->append());
				row = *irow;
				row[m_Columns.m_col_id] = id++;
				row[m_Columns.m_col_name] = ep->d_name;
				row[m_Columns.m_col_path] = path;

				std::cerr << "ScanDirTree: FILE added = " << path << '/' <<
ep->d_name << "    id = " << (id - 1) << "   Self:" <<
m_refTreeModel->get_string(irow) << "   Parent:";
				(parentrow) ? std::cerr << m_refTreeModel->get_string(parentrow) <<
std::endl : std::cerr << "NULL" << std::endl;
			}
		}
	}
	closedir(dp);
	return 0;
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]