From b2aaae15f1f7d85835f768d566b09a24774adef8 Mon Sep 17 00:00:00 2001 From: Malte Marquarding Date: Fri, 26 Nov 2010 14:35:43 +1100 Subject: [PATCH] comit the changes for quick-widgets-0.2.1 --- ProcessObject.cpp | 1 + ProcessObject.h | 1 + plugins/qmlprocess/ProcessObject.cpp | 4 +- plugins/qmlprocess/meminfo.qml | 35 +++++++++++ plugins/qmlprocess/process.qml | 44 ++++++++++++++ plugins/qmlprocess/qmlprocess.cpp | 2 +- plugins/qmlprocess/qmlprocess.pro | 2 + plugins/qmlprocess/qmlprocess.pro.user | 18 +++--- plugins/qmlprocess/qmlprocess/ProcessLabel.qml | 75 ++++++++++++++++++++++++ plugins/qmlprocess/qmlprocess/qmldir | 2 + 10 files changed, 174 insertions(+), 10 deletions(-) create mode 120000 ProcessObject.cpp create mode 120000 ProcessObject.h create mode 100644 plugins/qmlprocess/meminfo.qml create mode 100644 plugins/qmlprocess/process.qml create mode 100644 plugins/qmlprocess/qmlprocess/ProcessLabel.qml create mode 100644 plugins/qmlprocess/qmlprocess/qmldir diff --git a/ProcessObject.cpp b/ProcessObject.cpp new file mode 120000 index 0000000..e64c8a1 --- /dev/null +++ b/ProcessObject.cpp @@ -0,0 +1 @@ +plugins/qmlprocess/ProcessObject.cpp \ No newline at end of file diff --git a/ProcessObject.h b/ProcessObject.h new file mode 120000 index 0000000..a243678 --- /dev/null +++ b/ProcessObject.h @@ -0,0 +1 @@ +plugins/qmlprocess/ProcessObject.h \ No newline at end of file diff --git a/plugins/qmlprocess/ProcessObject.cpp b/plugins/qmlprocess/ProcessObject.cpp index 9e68381..c1dbdb3 100644 --- a/plugins/qmlprocess/ProcessObject.cpp +++ b/plugins/qmlprocess/ProcessObject.cpp @@ -73,13 +73,13 @@ void ProcessObject::processFinished(int exitCode, { QString out(m_process->readAllStandardOutput()); qDebug() << "normal"; - emit completed(out); + emit completed(out.trimmed()); } else { QString err(m_process->readAllStandardError()); qDebug() << "failed"; - emit failed(exitCode, err, m_process->error()); + emit failed(exitCode, err.trimmed(), m_process->error()); } } else diff --git a/plugins/qmlprocess/meminfo.qml b/plugins/qmlprocess/meminfo.qml new file mode 100644 index 0000000..b013d12 --- /dev/null +++ b/plugins/qmlprocess/meminfo.qml @@ -0,0 +1,35 @@ +import Qt 4.7 +import qmlprocess 1.0 +//import "content" + + Column { + id: col + spacing: 2 + width: 210 + height: childrenRect.height + + ProcessLabel { + label: "Active:" + width: parent.width; + color: "grey" + command: "sh -c \"cat /proc/meminfo | /bin/grep 'Active:'\"" + interval_in_sec: 5 + } + + ProcessLabel { + label: "Free:" + width: parent.width + color: "black" + interval_in_sec: 10 + command: "sh -c \"cat /proc/meminfo | /bin/grep 'MemFree:'\"" + } + + ProcessLabel { + label: "Total:" + width: parent.width + color: "#222222" + interval_in_sec: 0 + command: "sh -c \"cat /proc/meminfo | /bin/grep 'MemTotal:'\"" + } +} + diff --git a/plugins/qmlprocess/process.qml b/plugins/qmlprocess/process.qml new file mode 100644 index 0000000..cd1fef2 --- /dev/null +++ b/plugins/qmlprocess/process.qml @@ -0,0 +1,44 @@ +import Qt 4.7 +import qmlprocess + +Item { + width: childrenRect.width + height: childrenRect.height + + Rectangle { + id: bg + anchors.fill: txt + color: "blue" + opacity: 0.8 + radius: 5 + } + Text { + id: txt + smooth: true + font.pointSize: 12 + wrapMode: Text.Wrap + text: "Active Mem: MB" + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + //width: parent.width + //height: parent.height + color: "white" + } + function parse(out) { + var x = out.match(/[0-9]+/gi); + console.log(x) + return "Active Mem: "+Math.round(x/1024)+ " MB" + } + Process { + id: process + command: "sh -c \"cat /proc/meminfo | /bin/grep 'Active:'\"" + onCompleted: { txt.text = parse(stdout) } + onFailed: { bg.color = "red"; txt.text = stderr } + } + Timer { + running: runtime.isActiveWindow + repeat: true + interval: 5000 + onTriggered: { process.run() } + } +} \ No newline at end of file diff --git a/plugins/qmlprocess/qmlprocess.cpp b/plugins/qmlprocess/qmlprocess.cpp index 0ec99d1..9408193 100644 --- a/plugins/qmlprocess/qmlprocess.cpp +++ b/plugins/qmlprocess/qmlprocess.cpp @@ -44,7 +44,7 @@ void qmlprocess::registerTypes(const char *uri) { - Q_ASSERT(uri == QLatin1String("quickwidget")); + Q_ASSERT(uri == QLatin1String("qmlprocess")); qmlRegisterType(uri, 1, 0, "Process"); } diff --git a/plugins/qmlprocess/qmlprocess.pro b/plugins/qmlprocess/qmlprocess.pro index 73e7fbd..4f73aa0 100644 --- a/plugins/qmlprocess/qmlprocess.pro +++ b/plugins/qmlprocess/qmlprocess.pro @@ -15,3 +15,5 @@ OTHER_FILES=qmldir HEADERS += \ qmlprocess.h \ ProcessObject.h + +DESTDIR = qmlprocess diff --git a/plugins/qmlprocess/qmlprocess.pro.user b/plugins/qmlprocess/qmlprocess.pro.user index 91bd8a4..0f54791 100644 --- a/plugins/qmlprocess/qmlprocess.pro.user +++ b/plugins/qmlprocess/qmlprocess.pro.user @@ -45,11 +45,11 @@ qtlocal Debug Qt4ProjectManager.Qt4BuildConfiguration - 2 + 0 /home/mar637/Documents/qmlprocess-build-desktop 6 0 - true + false @@ -155,15 +155,19 @@ 4 - + + -I + . + meminfo.qml + 2 - + /var/tmp/mar637/qtsdk-2010.05/qt/bin/qmlviewer false - - false + qmlviewer + true $BUILDDIR - Custom Executable + qmlviewer ProjectExplorer.CustomExecutableRunConfiguration 1 diff --git a/plugins/qmlprocess/qmlprocess/ProcessLabel.qml b/plugins/qmlprocess/qmlprocess/ProcessLabel.qml new file mode 100644 index 0000000..5ac5d56 --- /dev/null +++ b/plugins/qmlprocess/qmlprocess/ProcessLabel.qml @@ -0,0 +1,75 @@ +import Qt 4.7 +//import quickwidgets 1.0 + +Rectangle { + id: proclabel + width: 100 + height: childrenRect.height + color: "blue" + opacity: 0.8 + radius: 5 + + function parse(stdout) { + var rx = /[0-9]+/gi; + var val = stdout.match(rx) + return String(val) + } + + property string command: "sh -c \"cat /proc/meminfo | /bin/grep 'Active:'\"" + property string label: "Value:" + property string textcolor: "white" + property real interval_in_sec: 5 + + function setText() { + txt.text = txt.stagedtxt + } + + Text { + property string stagedtxt: "" + id: txt + smooth: true + font.pointSize: 16 + anchors.right: proclabel.right + anchors.margins: 5 + text: "" + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignRight + color: proclabel.textcolor + Behavior on stagedtxt { + SequentialAnimation { + NumberAnimation { target: txt; property: "opacity"; to: 0; duration: 300 } + ScriptAction { script: setText(); } + NumberAnimation { target: txt; property: "opacity"; to: 1; duration: 500 } + } + } + } + + Text { + id: label + smooth: true + font.pointSize: 16 + font.weight: Font.Bold + anchors.left: proclabel.left + anchors.margins: 5 + text: proclabel.label + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignLeft + color: proclabel.textcolor + } + + Process { + id: process + command: proclabel.command + onCompleted: { txt.stagedtxt = parse(stdout);} + onFailed: { proclabel.color = "red"; txt.stagedtxt = stderr } + } + + Timer { + id: timer + triggeredOnStart: true + running: runtime.isActiveWindow + repeat: true + interval: proclabel.interval_in_sec*1000 + onTriggered: { process.run() } + } + } diff --git a/plugins/qmlprocess/qmlprocess/qmldir b/plugins/qmlprocess/qmlprocess/qmldir new file mode 100644 index 0000000..8e02799 --- /dev/null +++ b/plugins/qmlprocess/qmlprocess/qmldir @@ -0,0 +1,2 @@ +ProcessLabel 1.0 ProcessLabel.qml +plugin qmlprocess -- 1.7.9.5