forked from phonegap/phonegap-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added PowerManagement plugin for Qt port of PhoneGap
- Loading branch information
Viras-
committed
Sep 27, 2011
1 parent
4415249
commit bf3fb19
Showing
3 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "powermanagement.h" | ||
|
||
PowerManagement::PowerManagement(QWebFrame *p_webFrame) : | ||
PGPlugin(p_webFrame) | ||
{ | ||
m_systemScreenSaver = new QSystemScreenSaver(); | ||
} | ||
|
||
void PowerManagement::release( int scId, int ecId ) { | ||
m_systemScreenSaver->setScreenSaverInhibited(false); | ||
|
||
// Check if everything went fine | ||
if( !m_systemScreenSaver->screenSaverInhibited() ) { | ||
this->callback( scId, "" ); | ||
} | ||
else { | ||
this->callback( ecId, "" ); | ||
} | ||
} | ||
|
||
void PowerManagement::acquire( int scId, int ecId ) { | ||
m_systemScreenSaver->setScreenSaverInhibited(true); | ||
|
||
// Check if everything went fine | ||
if( m_systemScreenSaver->screenSaverInhibited() ) { | ||
this->callback( scId, "" ); | ||
} | ||
else { | ||
this->callback( ecId, "" ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef POWERMANAGEMENT_H | ||
#define POWERMANAGEMENT_H | ||
|
||
#include "../pgplugin.h" | ||
|
||
#include <QSystemScreenSaver> | ||
|
||
QTM_USE_NAMESPACE | ||
|
||
class PowerManagement : public PGPlugin | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit PowerManagement(QWebFrame *p_webFrame); | ||
|
||
signals: | ||
|
||
public slots: | ||
void release( int scId, int ecId ); | ||
void acquire( int scId, int ecId ); | ||
|
||
private: | ||
QSystemScreenSaver *m_systemScreenSaver; | ||
}; | ||
|
||
#endif // POWERMANAGEMENT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* PhoneGap is available under *either* the terms of the modified BSD license *or* the | ||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text. | ||
* | ||
* Copyright (c) 2011, Wolfgang Koller - http://www.gofg.at/ | ||
*/ | ||
|
||
function PowermanagementError() { | ||
}; | ||
|
||
PowermanagementError.cast = function( p_code, p_message ) { | ||
var powerManagementError = new PowermanagementError(); | ||
powerManagementError.code = p_code; | ||
powerManagementError.message = p_message; | ||
|
||
return powerManagementError; | ||
}; | ||
|
||
PowermanagementError.ALREADY_ACTIVE = 1; | ||
PowermanagementError.NOT_SUPPORTED = 2; | ||
PowermanagementError.NOT_ACTIVE = 3; | ||
|
||
PowermanagementError.prototype.code = 0; | ||
PowermanagementError.prototype.message = ""; | ||
|
||
function Powermanagement() { | ||
}; | ||
|
||
Powermanagement.prototype.acquired = false; | ||
|
||
Powermanagement.prototype.acquire = function( successCallback, errorCallback ) { | ||
if( this.acquired ) { | ||
errorCallback( PowermanagementError.cast( PowermanagementError.ALREADY_ACTIVE, "Powermanagement lock already active." ) ); | ||
return; | ||
} | ||
|
||
var me = this; | ||
PhoneGap.exec( function() { | ||
me.acquired = true; | ||
successCallback(); | ||
}, function() { | ||
me.acquired = false; | ||
errorCallback( PowermanagementError.cast( PowermanagementError.NOT_SUPPORTED, "Powermanagement not supported." ) ); | ||
}, "com.phonegap.plugin.Powermanagement", "acquire", [] ); | ||
}; | ||
|
||
Powermanagement.prototype.release = function( successCallback, errorCallback ) { | ||
if( !this.acquired ) { | ||
errorCallback( PowermanagementError.cast( PowermanagementError.NOT_ACTIVE, "Powermanagement lock not active." ) ); | ||
return; | ||
} | ||
|
||
var me = this; | ||
PhoneGap.exec( function() { | ||
me.acquired = false; | ||
successCallback(); | ||
}, function() { | ||
me.acquired = false; | ||
errorCallback( PowermanagementError.cast( PowermanagementError.NOT_SUPPORTED, "Powermanagement not supported." ) ); | ||
}, "com.phonegap.plugin.Powermanagement", "release", [] ); | ||
}; | ||
|
||
Powermanagement.prototype.dim = function( successCallback, errorCallback ) { | ||
if( this.acquired ) { | ||
errorCallback( PowermanagementError.cast( PowermanagementError.ALREADY_ACTIVE, "Powermanagement lock already active." ) ); | ||
return; | ||
} | ||
|
||
var me = this; | ||
if( !PhoneGap.exec( function() { | ||
me.acquired = true; | ||
successCallback(); | ||
}, function() { | ||
me.acquired = false; | ||
errorCallback( PowermanagementError.cast( PowermanagementError.NOT_SUPPORTED, "Powermanagement not supported." ) ); | ||
}, "com.phonegap.plugin.Powermanagement", "dim", [] ) ) { | ||
|
||
// If dimming doesn't work, try to acquire a full wake lock | ||
this.acquire( successCallback, errorCallback ); | ||
} | ||
}; | ||
|
||
/** | ||
* Create Powermanagement instance | ||
*/ | ||
PhoneGap.addConstructor( "com.phonegap.plugin.Powermanagement", function () { | ||
window.Powermanagement = new Powermanagement(); | ||
window.PowerManagement = window.Powermanagement; // Alias for backwards compatibility | ||
} ); |