Remoto - VFS: VFS_node_type.cpp Source File
Remoto - VFS
VFS_node_type.cpp
Go to the documentation of this file.
1 
2 #include <QFileInfo>
3 
4 #include "VFS_node_type.h"
5 
34 QMap<QString, QString> VFS_node_type::initTypes()
35 {
36  QMap<QString, QString> t;
37 
38  t["rui"] = "layoutWrapper";
39 // t["rts"] = "textStream";
40  t["rfm"] = "form";
41  t["rpt"] = "paneTransitioner";
42  t["rcs"] = "contentSelector";
43 // t["rlt"] = "layoutTransitioner";
44  t["rnc"] = "nodeCanvas";
45  t["rnd"] = "nodeCanvasNode";
46 // t["rmn"] = "menu";
47  t["rn3"] = "glCanvas";
48 // t["req"] = "requireModule";
49  t["acl"] = "aclFile";
50 
51  t["img"] = "image";
52  t["vid"] = "video";
53 
54  t["runity"] = "unityPane";
55 
56 // t["nk"] = "nodeCanvas"; //FIXME! This should be dynamically registered
57 
58  //t["dir"] = "listing"; //stubbed as a reminder
59 
60  return t;
61 }
62 
73 QMap<QString, bool> VFS_node_type::initJsons()
74 {
75  QMap<QString, bool> j;
76 
77  foreach(QString t,VFS_node_type::typeMap)
78  j[ t ] = true; //all the default types are JSON types
79 
80  j["textStream"] = false;
81 
82  j["listing"] = true; //for directory listings
83 
84  return j;
85 }
86 
87 QMap<QString, QString> VFS_node_type::typeMap = VFS_node_type::initTypes();
88 QMap<QString, bool> VFS_node_type::jsonMap = VFS_node_type::initJsons();
89 
99 QString VFS_node_type::getType(QString _path, QString _default)
100 {
101  QFileInfo info(_path);
102 
103  QString ext = info.suffix();
104 
105  if (typeMap.contains(ext))
106  return typeMap.value(ext,_default);
107  else if (info.isDir())
108  return "listing";
109 
110  //FIXME
111  //else other options...
112 
113  return _default;
114 }
115 
122 bool VFS_node_type::isJsonType(QString _type)
123 {
124  return jsonMap.value(_type,false);
125 }
126 
139 bool VFS_node_type::registerType( QString type, QString handler, bool json )
140 {
141  if (typeMap.contains( type ))
142  return false;
143 
144  typeMap[type] = handler;
145  jsonMap[type] = json;
146 
147  return true;
148 }
149 
157 {
158  if (typeMap.contains(type))
159  {
160  typeMap.remove(type);
161  jsonMap.remove(type);
162  return true;
163  }
164 
165  return false;
166 }
167 
static bool registerType(QString type, QString handler, bool json=true)
Add a type to the registry.
static QMap< QString, QString > initTypes()
Initialize the type library.
static QMap< QString, bool > initJsons()
Initialize the jsons library.
static bool isJsonType(QString _type)
Check if a type is known to be json.
static QMap< QString, QString > typeMap
The extension:type map.
Definition: VFS_node_type.h:21
static QString getType(QString _path, QString _default="unknownType")
Fetch the type of a file, based on path/filename.ext.
static QMap< QString, bool > jsonMap
The extension:isjson map.
Definition: VFS_node_type.h:22
static bool unregisterType(QString type)
Remove a type from the registry.
setter type
a setter DOCME