Permalink
Browse files

Provide an API to get PhantomJS version.

  • Loading branch information...
1 parent 0110913 commit 3a0d0886b6fd0b82ce0a246ea3b6713c428ce276 @ariya committed Jan 1, 2011
Showing with 23 additions and 1 deletion.
  1. +5 −0 examples/version.js
  2. +18 −1 src/phantomjs.cpp
View
@@ -0,0 +1,5 @@
+console.log('using PhantomJS version ' +
+ phantom.version.major + '.' +
+ phantom.version.minor + '.' +
+ phantom.version.patch);
+phantom.exit();
View
@@ -35,6 +35,11 @@
#error Use Qt 4.7 or later version
#endif
+#define PHANTOMJS_VERSION_MAJOR 1
+#define PHANTOMJS_VERSION_MINOR 0
+#define PHANTOMJS_VERSION_PATCH 0
+#define PHANTOMJS_VERSION_STRING "1.0.0"
+
class WebPage: public QWebPage
{
Q_OBJECT
@@ -93,6 +98,7 @@ class Phantom: public QObject
Q_PROPERTY(QString loadStatus READ loadStatus)
Q_PROPERTY(QString state READ state WRITE setState)
Q_PROPERTY(QString userAgent READ userAgent WRITE setUserAgent)
+ Q_PROPERTY(QVariantMap version READ version)
Q_PROPERTY(QVariantMap viewportSize READ viewportSize WRITE setViewportSize)
public:
@@ -114,6 +120,8 @@ class Phantom: public QObject
void setUserAgent(const QString &ua);
QString userAgent() const;
+ QVariantMap version() const;
+
void setViewportSize(const QVariantMap &size);
QVariantMap viewportSize() const;
@@ -285,6 +293,15 @@ QString Phantom::userAgent() const
return m_page.m_userAgent;
}
+QVariantMap Phantom::version() const
+{
+ QVariantMap result;
+ result["major"] = PHANTOMJS_VERSION_MAJOR;
+ result["minor"] = PHANTOMJS_VERSION_MINOR;
+ result["patch"] = PHANTOMJS_VERSION_PATCH;
+ return result;
+}
+
void Phantom::setViewportSize(const QVariantMap &size)
{
int w = size.value("width").toInt();
@@ -317,7 +334,7 @@ int main(int argc, char** argv)
app.setApplicationName("PhantomJS");
app.setOrganizationName("Ofi Labs");
app.setOrganizationDomain("www.ofilabs.com");
- app.setApplicationVersion("1.0");
+ app.setApplicationVersion(PHANTOMJS_VERSION_STRING);
Phantom phantom;
phantom.execute(QString::fromLocal8Bit(argv[1]));

0 comments on commit 3a0d088

Please sign in to comment.