summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--MatrixWebView.cpp74
-rw-r--r--MatrixWebView.h65
-rwxr-xr-x[-rw-r--r--]main.cpp25
-rwxr-xr-x[-rw-r--r--]matrix_browser.pro5
4 files changed, 163 insertions, 6 deletions
diff --git a/MatrixWebView.cpp b/MatrixWebView.cpp
new file mode 100644
index 0000000..8126d65
--- /dev/null
+++ b/MatrixWebView.cpp
@@ -0,0 +1,74 @@
1/*
2 * MatrixWebView.cpp
3 *
4 * MatrixWebView Class inherted from QWebView to support additional
5 * functionalities such as signal handler
6 *
7 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
8 *
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the
20 * distribution.
21 *
22 * Neither the name of Texas Instruments Incorporated nor the names of
23 * its contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38*/
39
40#include "MatrixWebView.h"
41#include <sys/types.h>
42#include <sys/socket.h>
43#include <unistd.h>
44#include <QApplication>
45
46int MatrixWebView::sigtermFd[2];
47
48MatrixWebView::MatrixWebView(QWidget* parent)
49 : QWebView(parent)
50{
51 if (::socketpair(AF_UNIX, SOCK_STREAM, 0, sigtermFd))
52 qFatal("Couldn't create TERM socketpair");
53
54 snTerm = new QSocketNotifier(sigtermFd[1], QSocketNotifier::Read, this);
55 connect(snTerm, SIGNAL(activated(int)), this, SLOT(handleSigTerm()));
56}
57
58void MatrixWebView::termSignalHandler(int)
59{
60 char a = 1;
61 if(::write(sigtermFd[0], &a, sizeof(a))){}
62}
63
64void MatrixWebView::handleSigTerm()
65{
66 snTerm->setEnabled(false);
67 char tmp;
68 if(::read(sigtermFd[1], &tmp, sizeof(tmp))){}
69
70 // do Qt stuff
71 qApp->quit();
72
73 snTerm->setEnabled(true);
74}
diff --git a/MatrixWebView.h b/MatrixWebView.h
new file mode 100644
index 0000000..4944e7f
--- /dev/null
+++ b/MatrixWebView.h
@@ -0,0 +1,65 @@
1/*
2 * MatrixWebView.h
3 *
4 * MatrixWebView Class inherted from QWebView to support additional
5 * functionalities such as signal handler
6 *
7 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the
19 * distribution.
20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NO
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37*/
38
39#ifndef MATRIXWEBVIEW_H
40#define MATRIXWEBVIEW_H
41
42#include <QWebView>
43#include <QGraphicsWebView>
44#include <QSocketNotifier>
45
46class MatrixWebView : public QWebView
47{
48 Q_OBJECT
49
50public:
51 MatrixWebView(QWidget* parent = 0);
52
53 //Unix signal handler
54 static void termSignalHandler(int unused);
55
56public slots:
57 // Qt singal handler
58 void handleSigTerm();
59
60private:
61 static int sigtermFd[2];
62 QSocketNotifier *snTerm;
63};
64
65#endif
diff --git a/main.cpp b/main.cpp
index 6724c0d..72b490f 100644..100755
--- a/main.cpp
+++ b/main.cpp
@@ -3,7 +3,7 @@
3 * 3 *
4 * Simple web viewer used by Matrix application launcher 4 * Simple web viewer used by Matrix application launcher
5 * 5 *
6 * Copyright (C) 2011,2012 Texas Instruments Incorporated - http://www.ti.com/ 6 * Copyright (C) 2011-2015 Texas Instruments Incorporated - http://www.ti.com/
7 * 7 *
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
@@ -37,9 +37,24 @@
37*/ 37*/
38 38
39#include <QtWidgets> 39#include <QtWidgets>
40#include <QWebView>
41#include <QGraphicsWebView>
42#include <iostream> 40#include <iostream>
41#include <QApplication>
42#include "MatrixWebView.h"
43#include "signal.h"
44
45static int setup_unix_signal_handlers()
46{
47 struct sigaction term;
48
49 term.sa_handler = MatrixWebView::termSignalHandler;
50 sigemptyset(&term.sa_mask);
51 term.sa_flags = SA_RESTART;
52
53 if (sigaction(SIGTERM, &term, 0) > 0)
54 return 1;
55
56 return 0;
57}
43 58
44using std::endl; 59using std::endl;
45 60
@@ -56,7 +71,7 @@ int main(int argc, char **argv)
56 71
57 bool windowed = QApplication::arguments().contains("--windowed"); 72 bool windowed = QApplication::arguments().contains("--windowed");
58 73
59 QWebView view; 74 MatrixWebView view;
60 view.load(QUrl(args[1])); 75 view.load(QUrl(args[1]));
61 view.setContextMenuPolicy(Qt::NoContextMenu); 76 view.setContextMenuPolicy(Qt::NoContextMenu);
62 77
@@ -68,5 +83,7 @@ int main(int argc, char **argv)
68 else 83 else
69 view.show(); 84 view.show();
70 85
86 int ret = setup_unix_signal_handlers();
87
71 return app.exec(); 88 return app.exec();
72} 89}
diff --git a/matrix_browser.pro b/matrix_browser.pro
index 109e40c..a6d8e1c 100644..100755
--- a/matrix_browser.pro
+++ b/matrix_browser.pro
@@ -6,9 +6,10 @@ TEMPLATE = app
6TARGET = matrix_browser 6TARGET = matrix_browser
7DEPENDPATH += . 7DEPENDPATH += .
8INCLUDEPATH += . 8INCLUDEPATH += .
9QT += webkitwidgets 9QT += webkit webkitwidgets
10# Input 10# Input
11SOURCES += main.cpp 11SOURCES += main.cpp MatrixWebView.cpp
12HEADERS = MatrixWebView.h
12 13
13# install 14# install
14target.path = . 15target.path = .