This example is somewhat confusing on UNIX since the directory
used does not exist on my system, or indeed on most systems.
The result is an empty list of files, making me think that
the example is broken.

I have attached a version which uses the last argiment on the
command line if that argument is a diretory, otherwise $HOME.

The code would be a little cleaner if createApplication() had
easy access to a sanitized argc/argv. By that I mean argc/argv
that when the application is invoked as e.g.

  ./filetreetable.wt --docroot . --http-address 0.0.0.0 --http-port 8080 /tmp

it would look as if the invocation had been

  ./filetreetable.wt /tmp

/Lars
/*
 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */

# ifndef WIN32
#     include <sys/stat.h>
# endif

#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WTree>
#include <Wt/WTreeTableNode>

#include "FileTreeTable.h"

using namespace Wt;

static char const *dirname = "c://temp";

WApplication *createApplication(const WEnvironment& env)
{
  WApplication *app = new WApplication(env);
  app->setTitle("File explorer example");
  app->useStyleSheet("filetree.css");

  FileTreeTable *treeTable = new FileTreeTable(dirname);
  treeTable->resize(500, 300);
  treeTable->tree()->setSelectionMode(ExtendedSelection);
  treeTable->treeRoot()->setNodeVisible(false);
  treeTable->treeRoot()->setChildCountPolicy(WTreeNode::Enabled);

  app->root()->addWidget(treeTable);

  return app;
}

int main(int argc, char **argv)
{
# ifndef WIN32
  struct stat fstat;
  dirname = (0 == ::stat(argv[argc-1], &fstat)) && S_ISDIR(fstat.st_mode) ? argv[argc-1] : getenv("HOME");
# endif

   return WRun(argc, argv, &createApplication);
}

------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to