Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RWebDisplayArgs.cxx
Go to the documentation of this file.
1// Author: Sergey Linev <s.linev@gsi.de>
2// Date: 2018-10-24
3// Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
4
5/*************************************************************************
6 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
14
15#include <ROOT/RConfig.hxx>
16#include <ROOT/RLogger.hxx>
17#include <ROOT/RWebWindow.hxx>
18
19#include "TROOT.h"
20#include <string>
21
22using namespace ROOT::Experimental;
23
25{
26 static RLogChannel sLog("ROOT.WebGUI");
27 return sLog;
28}
29
30
31/** \class ROOT::Experimental::RWebDisplayArgs
32\ingroup webdisplay
33
34Holds different arguments for starting browser with RWebDisplayHandle::Display() method
35
36 */
37
38///////////////////////////////////////////////////////////////////////////////////////////
39/// Default constructor - browser kind configured from gROOT->GetWebDisplay()
40
42{
44}
45
46///////////////////////////////////////////////////////////////////////////////////////////
47/// Constructor - browser kind specified as std::string
48/// See SetBrowserKind() method for description of allowed parameters
49
50RWebDisplayArgs::RWebDisplayArgs(const std::string &browser)
51{
52 SetBrowserKind(browser);
53}
54
55///////////////////////////////////////////////////////////////////////////////////////////
56/// Constructor - browser kind specified as const char *
57/// See SetBrowserKind() method for description of allowed parameters
58
60{
61 SetBrowserKind(browser);
62}
63
64///////////////////////////////////////////////////////////////////////////////////////////
65/// Constructor - specify window width and height
66
67RWebDisplayArgs::RWebDisplayArgs(int width, int height, int x, int y, const std::string &browser)
68{
69 SetSize(width, height);
70 SetPos(x, y);
71 SetBrowserKind(browser);
72}
73
74///////////////////////////////////////////////////////////////////////////////////////////
75/// Constructor - specify master window and channel (if reserved already)
76
77RWebDisplayArgs::RWebDisplayArgs(std::shared_ptr<RWebWindow> master, int channel)
78{
79 SetMasterWindow(master, channel);
80}
81
82
83///////////////////////////////////////////////////////////////////////////////////////////
84/// Destructor
85
87{
88 // must be defined here to correctly call RWebWindow destructor
89}
90
91///////////////////////////////////////////////////////////////////////////////////////////
92/// Set size of web browser window as string like "800x600"
93
94bool RWebDisplayArgs::SetSizeAsStr(const std::string &str)
95{
96 auto separ = str.find("x");
97 if ((separ == std::string::npos) || (separ == 0) || (separ == str.length()-1)) return false;
98
99 int width = 0, height = 0;
100
101 try {
102 width = std::stoi(str.substr(0,separ));
103 height = std::stoi(str.substr(separ+1));
104 } catch(...) {
105 return false;
106 }
107
108 if ((width<=0) || (height<=0))
109 return false;
110
111 SetSize(width, height);
112 return true;
113}
114
115///////////////////////////////////////////////////////////////////////////////////////////
116/// Set position of web browser window as string like "100,100"
117
118bool RWebDisplayArgs::SetPosAsStr(const std::string &str)
119{
120 auto separ = str.find(",");
121 if ((separ == std::string::npos) || (separ == 0) || (separ == str.length()-1)) return false;
122
123 int x = 0, y = 0;
124
125 try {
126 x = std::stoi(str.substr(0,separ));
127 y = std::stoi(str.substr(separ+1));
128 } catch(...) {
129 return false;
130 }
131
132 if ((x<0) || (y<0))
133 return false;
134
135 SetPos(x, y);
136 return true;
137}
138
139///////////////////////////////////////////////////////////////////////////////////////////
140/// Set browser kind as string argument
141/// Recognized values:
142/// chrome - use Google Chrome web browser, supports headless mode from v60, default
143/// firefox - use Mozilla Firefox browser, supports headless mode from v57
144/// native - (or empty string) either chrome or firefox, only these browsers support batch (headless) mode
145/// browser - default system web-browser, no batch mode
146/// safari - Safari browser on Mac
147/// cef - Chromium Embeded Framework, local display, local communication
148/// qt5 - Qt5 WebEngine, local display, local communication
149/// local - either cef or qt5
150/// <prog> - any program name which will be started instead of default browser, like /usr/bin/opera
151
153{
154 std::string kind = _kind;
155
156 auto pos = kind.find("?");
157 if (pos == 0) {
158 SetUrlOpt(kind.substr(1));
159 kind.clear();
160 } else if (pos != std::string::npos) {
161 SetUrlOpt(kind.substr(pos+1));
162 kind.resize(pos);
163 }
164
165 pos = kind.find("size:");
166 if (pos != std::string::npos) {
167 auto epos = kind.find_first_of(" ;", pos+5);
168 if (epos == std::string::npos) epos = kind.length();
169 SetSizeAsStr(kind.substr(pos+5, epos-pos-5));
170 kind.erase(pos, epos-pos);
171 }
172
173 pos = kind.find("pos:");
174 if (pos != std::string::npos) {
175 auto epos = kind.find_first_of(" ;", pos+4);
176 if (epos == std::string::npos) epos = kind.length();
177 SetPosAsStr(kind.substr(pos+4, epos-pos-4));
178 kind.erase(pos, epos-pos);
179 }
180
181 // very special handling of qt5 which can specify pointer as a string
182 if (kind.find("qt5:") == 0) {
183 SetDriverData((void *) std::stoul(kind.substr(4)));
184 kind.resize(3);
185 }
186
187 // remove all trailing spaces
188 while ((kind.length() > 0) && (kind[kind.length()-1] == ' '))
189 kind.resize(kind.length()-1);
190
191 // remove any remaining spaces?
192 // kind.erase(remove_if(kind.begin(), kind.end(), std::isspace), kind.end());
193
194 if (kind.empty())
195 kind = gROOT->GetWebDisplay().Data();
196
197 if (kind == "local")
199 else if (kind.empty() || (kind == "native"))
201 else if (kind == "firefox")
203 else if ((kind == "chrome") || (kind == "chromium"))
205 else if ((kind == "cef") || (kind == "cef3"))
207 else if ((kind == "qt") || (kind == "qt5"))
209 else if ((kind == "embed") || (kind == "embedded"))
211 else if (!SetSizeAsStr(kind))
212 SetCustomExec(kind);
213
214 return *this;
215}
216
217/////////////////////////////////////////////////////////////////////
218/// Returns configured browser name
219
221{
222 switch (GetBrowserKind()) {
223 case kChrome: return "chrome";
224 case kFirefox: return "firefox";
225 case kNative: return "native";
226 case kCEF: return "cef";
227 case kQt5: return "qt5";
228 case kLocal: return "local";
229 case kStandard: return "default";
230 case kEmbedded: return "embed";
231 case kCustom:
232 auto pos = fExec.find(" ");
233 return (pos == std::string::npos) ? fExec : fExec.substr(0,pos);
234 }
235
236 return "";
237}
238
239///////////////////////////////////////////////////////////////////////////////////////////
240/// Assign window and channel id where other window will be embed
241
242void RWebDisplayArgs::SetMasterWindow(std::shared_ptr<RWebWindow> master, int channel)
243{
245 fMaster = master;
246 fMasterChannel = channel;
247}
248
249///////////////////////////////////////////////////////////////////////////////////////////
250/// Append string to url options
251/// Add "&" as separator if any options already exists
252
253void RWebDisplayArgs::AppendUrlOpt(const std::string &opt)
254{
255 if (opt.empty()) return;
256
257 if (!fUrlOpt.empty())
258 fUrlOpt.append("&");
259
260 fUrlOpt.append(opt);
261}
262
263///////////////////////////////////////////////////////////////////////////////////////////
264/// Returns full url, which is combined from URL and extra URL options
265/// Takes into account "#" symbol in url - options are inserted before that symbol
266
268{
269 std::string url = GetUrl(), urlopt = GetUrlOpt();
270 if (url.empty() || urlopt.empty()) return url;
271
272 auto rpos = url.find("#");
273 if (rpos == std::string::npos) rpos = url.length();
274
275 if (url.find("?") != std::string::npos)
276 url.insert(rpos, "&");
277 else
278 url.insert(rpos, "?");
279 url.insert(rpos+1, urlopt);
280
281 return url;
282}
283
284///////////////////////////////////////////////////////////////////////////////////////////
285/// Configure custom web browser
286/// Either just name of browser which can be used like "opera"
287/// or full execution string which must includes $url like "/usr/bin/opera $url"
288
289void RWebDisplayArgs::SetCustomExec(const std::string &exec)
290{
292 fExec = exec;
293}
294
295///////////////////////////////////////////////////////////////////////////////////////////
296/// returns custom executable to start web browser
297
299{
300 if (GetBrowserKind() != kCustom)
301 return "";
302
303#ifdef R__MACOSX
304 if ((fExec == "safari") || (fExec == "Safari"))
305 return "open -a Safari";
306#endif
307
308 return fExec;
309}
310
311///////////////////////////////////////////////////////////////////////////////////////////
312/// returns string which can be used as argument in RWebWindow::Show() method
313/// to display web window in provided QWidget
314/// After RWebWindow is displayed created QWebEngineView can be found with the command:
315/// auto view = qparent->findChild<QWebEngineView*>("RootWebView");
316
317std::string RWebDisplayArgs::GetQt5EmbedQualifier(const void *qparent, const std::string &urlopt)
318{
319 std::string where = "qt5";
320 if (qparent) {
321 where.append(":");
322 where.append(std::to_string((unsigned long) qparent));
323 }
324 if (!urlopt.empty()) {
325 where.append("?");
326 where.append(urlopt);
327 }
328 return where;
329}
330
include TDocParser_001 C image html pict1_TDocParser_001 png width
#define gROOT
Definition TROOT.h:406
A log configuration for a channel, e.g.
Definition RLogger.hxx:101
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
std::string GetBrowserName() const
Returns configured browser name.
const std::string & GetUrlOpt() const
returns window url options
bool SetPosAsStr(const std::string &str)
Set position of web browser window as string like "100,100".
RWebDisplayArgs & SetPos(int x=-1, int y=-1)
static std::string GetQt5EmbedQualifier(const void *qparent, const std::string &urlopt="")
returns string which can be used as argument in RWebWindow::Show() method to display web window in pr...
int fMasterChannel
! used master channel
void SetMasterWindow(std::shared_ptr< RWebWindow > master, int channel=-1)
Assign window and channel id where other window will be embed.
EBrowserKind GetBrowserKind() const
returns configured browser kind, see EBrowserKind for supported values
void SetCustomExec(const std::string &exec)
set custom executable to start web browser
std::shared_ptr< RWebWindow > fMaster
! master window
void AppendUrlOpt(const std::string &opt)
append extra url options, add "&" as separator if required
std::string GetFullUrl() const
returns window url with append options
RWebDisplayArgs & SetBrowserKind(const std::string &kind)
Set browser kind as string argument Recognized values: chrome - use Google Chrome web browser,...
std::string fExec
! string to run browser, used with kCustom type
std::string GetCustomExec() const
returns custom executable to start web browser
std::string fUrlOpt
! extra URL options, which are append to window URL
@ kFirefox
Mozilla Firefox browser.
@ kCEF
Chromium Embedded Framework - local display with CEF libs.
@ kCustom
custom web browser, execution string should be provided
@ kNative
either Chrome or Firefox - both support major functionality
@ kEmbedded
window will be embedded into other, no extra browser need to be started
@ kLocal
either CEF or Qt5 - both runs on local display without real http server
@ kStandard
standard system web browser, not recognized by ROOT, without batch mode
@ kQt5
QWebEngine libraries - Chrome code packed in qt5.
RWebDisplayArgs & SetUrlOpt(const std::string &opt)
set window url options
void SetDriverData(void *data)
[internal] set web-driver data, used to start window
RWebDisplayArgs & SetSize(int w, int h)
const std::string & GetUrl() const
returns window url
bool SetSizeAsStr(const std::string &str)
Set size of web browser window as string like "800x600".
RWebDisplayArgs()
Default constructor - browser kind configured from gROOT->GetWebDisplay()
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
RLogChannel & WebGUILog()
Log channel for WebGUI diagnostics.