Remoto - VFS: logView.cpp Source File
Remoto - VFS
logView.cpp
Go to the documentation of this file.
1 
2 #include "VFS.h"
3 #include "VFS_icons.h"
4 #include "utilities/rutils.h"
5 
6 #include "logView.h"
7 
19 {
20  _iconColors["default"] = "black";
21  _iconColors["log"] = "black";
22  _iconColors["messages"] = "black";
23  _iconColors["warnings"] = "orange";
24  _iconColors["errors"] = "red";
25  _iconColors["critical"] = "red";
26 }
27 
29 {
30 }
31 
37 QByteArray logView::icon()
38 {
39  return (char *) "data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 791.911 791.911\"><rect x=\"120\" y=\"20\" fill=\"white\" width=\"550\" height=\"760\"/><path d=\"M641.43 0H150.481c-25.924 0-46.964 21.129-46.964 46.964v697.983c0 25.924 21.129 46.964 46.964 46.964H641.43c25.924 0 46.964-21.13 46.964-46.964V46.964C688.395 21.129 667.354 0 641.43 0zm11.542 745.036c0 6.747-4.794 11.541-11.541 11.541h-490.95c-6.747 0-11.541-4.794-11.541-11.541V46.964c0-6.747 4.794-11.541 11.541-11.541H641.43c6.747 0 11.541 4.794 11.541 11.541v698.072zm-81.5-188.923c0 9.588-7.635 17.223-17.223 17.223H333.633c-9.588 0-17.223-7.635-17.223-17.223s7.635-17.223 17.223-17.223H554.16c8.701-.976 17.312 7.635 17.312 17.223zm0 106.447c0 9.588-7.635 17.223-17.223 17.223H333.633c-9.588 0-17.223-7.635-17.223-17.223s7.635-17.223 17.223-17.223H554.16c8.701-.977 17.312 7.635 17.312 17.223zm0-211.916c0 9.588-7.635 17.223-17.223 17.223H333.633c-9.588 0-17.223-7.635-17.223-17.223s7.635-17.223 17.223-17.223H554.16c8.701-.001 17.312 7.635 17.312 17.223zm0-104.494c0 9.588-7.635 17.223-17.223 17.223H333.633c-9.588 0-17.223-7.635-17.223-17.223s7.635-17.223 17.223-17.223H554.16c8.701 0 17.312 7.635 17.312 17.223zM315.433 241.657c0-9.588 7.635-17.223 17.223-17.223h218.575c9.588 0 17.223 7.635 17.223 17.223s-7.635 17.223-17.223 17.223H332.745c-9.588 0-17.312-7.635-17.312-17.223zm0-105.47c0-9.588 7.635-17.223 17.223-17.223h218.575c9.588 0 17.223 7.635 17.223 17.223s-7.635 17.223-17.223 17.223H332.745c-9.588.977-17.312-7.634-17.312-17.223zm-63.3 0c0 10.565-8.612 19.176-19.176 19.176-10.565 0-19.176-8.612-19.176-19.176 0-10.565 8.612-19.176 19.176-19.176 10.565 0 19.176 8.612 19.176 19.176zm0 105.47c0 10.565-8.612 19.176-19.176 19.176-10.565 0-19.176-8.612-19.176-19.176s8.612-19.176 19.176-19.176c10.565-.977 19.176 7.635 19.176 19.176zm0 102.54c0 10.565-8.612 19.176-19.176 19.176-10.565 0-19.176-8.612-19.176-19.176s8.612-19.176 19.176-19.176c10.565-.888 19.176 7.724 19.176 19.176zm0 104.582c0 10.565-8.612 19.176-19.176 19.176-10.565 0-19.176-8.612-19.176-19.176 0-10.565 8.612-19.176 19.176-19.176 10.565 0 19.176 8.612 19.176 19.176zm0 108.311c0 10.565-8.612 19.176-19.176 19.176-10.565 0-19.176-8.612-19.176-19.176 0-10.565 8.612-19.176 19.176-19.176 10.565 0 19.176 8.611 19.176 19.176zm0 105.47c0 10.565-8.612 19.176-19.176 19.176-10.565 0-19.176-8.612-19.176-19.176 0-10.565 8.612-19.176 19.176-19.176 10.565-.977 19.176 8.611 19.176 19.176z\"/></svg>";
40  //return VFS_icons::get("stream");
41 }
42 
50 {
51  Q_UNUSED(r);
52 
53  return this;
54 }
55 
75 {
76  if (r->_path == "")
77  {
78  VFS_request *s = r->getCallback(this);
79  s->_path = "logs";
80  s->_requestType = VFS_request::read; //this line is key! We want the request to be a read, even when the true request is a subscribe.
81 
82  issueRequest(s);
83 
84  return;
85  }
86 
87  VFS_node::read(r);
88 }
89 
100 {
101  int logLevel, logTime;
102  VFS::root()->getLogSettings(logLevel,logTime);
103 
104  if (r->_path == "")
105  {
106  QJsonObject a;
107  a["type"] = "openLayout";
108 
109  r->_metadata["icon"] = QString(icon());
110  r->_metadata["action"] = a;
111  r->_metadata["logLevel"] = logLevel;
112  r->_metadata["logTime"] = logTime;
113 
114  QJsonObject l = rutils::jsonResource(":/admin/templates/logViewLayout.json");
115  l["icon"] = "@icon@";
116  QJsonObject t;
117  t["openLayout"] = l;
118 
119  r->_metadata["template"] = t;
120  r->_metadata["where"] = "nearest";
121  r->_success = true;
122  }
123  else
124  {
125  QString ic = QString(icon()).replace("svg xmlns",QString("svg fill=\"%1\" xmlns").arg( _iconColors.value(r->_path,"default") ));
126 
127  QJsonObject a;
128  a["type"] = "openLayout";
129 
130  r->_metadata["icon"] = ic;
131  r->_metadata["action"] = a;
132 
133  QJsonObject l;
134  //if (r->_path == "log")
135  l = rutils::jsonResource(":/admin/templates/logLayoutColor.json");
136  //else
137  // l = rutils::jsonResource(":/admin/templates/logLayout.json");
138 
139  //l["icon"] = ic;
140  l["icon"] = "@icon@";
141  QJsonObject t;
142  t["openLayout"] = l;
143 
144  r->_metadata["template"] = t;
145  r->_metadata["where"] = "nearest";
146  r->_metadata["alwaysNewTab"] = true;
147  r->_metadata["logLevel"] = logLevel;
148  r->_metadata["logTime"] = logTime;
149  r->_success = true;
150  }
151 }
A common base class for all things that want to act like an application or include ACL support.
VFS_node is the base class from which all other VFS_node classes derive.
Definition: VFS_node.h:143
virtual void read(VFS_request *r)
Return the data contents of this node, or if it's a container call ls()
Definition: VFS_node.cpp:724
virtual void issueRequest(VFS_request *t)
A convenience function.
Definition: VFS_node.cpp:1933
The base class for all requests between nodes.
Definition: VFS_node.h:54
@ read
read full contents (4)
Definition: VFS_node.h:68
requestType _requestType
the action this request is performing or requesting
Definition: VFS_node.h:87
QString _path
the target path remnant... the remaining path element once the request has found its target
Definition: VFS_node.h:95
bool _success
if the request was successfully completed
Definition: VFS_node.h:107
virtual VFS_request * getCallback(VFS_node *receiver)
Create and chain a VFS_request for a receiver.
Definition: VFS_node.cpp:316
QJsonObject _metadata
the request payload
Definition: VFS_node.h:101
static VFS * root()
Return the root node of the VFS filesystem.
Definition: VFS.cpp:399
void getLogSettings(int &loglevel, int &logtime)
Get the loglevel and logtime values for the logger.
Definition: VFS.cpp:182
Q_INVOKABLE logView()
Definition: logView.cpp:17
virtual ~logView()
Definition: logView.cpp:28
virtual void metadata(VFS_request *r)
Return metadata about a path that this node serves.
Definition: logView.cpp:99
virtual QByteArray icon()
The "stream" icon found in the VFS_icons library.
Definition: logView.cpp:37
virtual void read(VFS_request *r)
Read the list of logs available.
Definition: logView.cpp:74
QMap< QString, QString > _iconColors
The colors returned for served icons.
Definition: logView.h:29
virtual VFS_node * find(VFS_request *r)
Find a child of this node...
Definition: logView.cpp:49
QJsonObject jsonResource(QString resource, bool *ok=nullptr)
Fetch the contents of a Qt resource as a QJsonObject.
Definition: rutils.cpp:90