Author: echatellier Date: 2010-01-04 10:02:46 +0100 (Mon, 04 Jan 2010) New Revision: 2717 Added: trunk/src/main/java/org/chorem/jtimer/ui/system/macos/ trunk/src/main/java/org/chorem/jtimer/ui/system/macos/ApplicationServices.java trunk/src/main/java/org/chorem/jtimer/ui/system/macos/MacOSSystemInfo.java trunk/src/main/java/org/chorem/jtimer/ui/system/macos/package-info.java Modified: trunk/changelog.txt trunk/pom.xml trunk/src/main/java/org/chorem/jtimer/ui/system/SystemInfoFactory.java trunk/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java Log: Add Mac OS 10.4+ idle time detection support Modified: trunk/changelog.txt =================================================================== --- trunk/changelog.txt 2009-12-18 09:11:04 UTC (rev 2716) +++ trunk/changelog.txt 2010-01-04 09:02:46 UTC (rev 2717) @@ -3,6 +3,7 @@ jTimer (1.3.2) stable; urgency=low + * Add Mac OS 10.4+ idle time detection support * Allow adding notes on synchronized projects * #80 : Add parent node to select/unselect all projects on report UI * Freemarker updated to 2.3.16 Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-12-18 09:11:04 UTC (rev 2716) +++ trunk/pom.xml 2010-01-04 09:02:46 UTC (rev 2717) @@ -222,7 +222,7 @@ <version>2.4</version> <configuration> <configLocation>checkstyle.xml</configLocation> - <excludes>**/Xss.java,**/X11.java,**/Kernel32.java,**/User32.java</excludes> + <excludes>**/Xss.java,**/X11.java,**/Kernel32.java,**/User32.java, **/ApplicationServices.java</excludes> </configuration> </plugin> <plugin> @@ -266,7 +266,7 @@ </plugin> <plugin> <artifactId>maven-changes-plugin</artifactId> - <version>2.1</version> + <version>2.3</version> <reportSets> <reportSet> <reports> Modified: trunk/src/main/java/org/chorem/jtimer/ui/system/SystemInfoFactory.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/system/SystemInfoFactory.java 2009-12-18 09:11:04 UTC (rev 2716) +++ trunk/src/main/java/org/chorem/jtimer/ui/system/SystemInfoFactory.java 2010-01-04 09:02:46 UTC (rev 2717) @@ -20,6 +20,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.ui.system.macos.MacOSSystemInfo; import org.chorem.jtimer.ui.system.unix.UnixSystemInfo; import org.chorem.jtimer.ui.system.win32.Win32SystemInfo; @@ -69,8 +70,10 @@ // try windows if (os.contains("windows")) { instance = new Win32SystemInfo(); - } else if (os.contains("linux") || os.contains("mac os")) { + } else if (os.contains("linux")) { instance = new UnixSystemInfo(); + } else if (os.contains("mac os")) { + instance = new MacOSSystemInfo(); } else { // system unknown throw new UnsupportedSystemInfoException( Added: trunk/src/main/java/org/chorem/jtimer/ui/system/macos/ApplicationServices.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/system/macos/ApplicationServices.java (rev 0) +++ trunk/src/main/java/org/chorem/jtimer/ui/system/macos/ApplicationServices.java 2010-01-04 09:02:46 UTC (rev 2717) @@ -0,0 +1,59 @@ +/* * + * Copyright (C) 2010 Code Lutin, Eric Chatellier + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + **/ + +package org.chorem.jtimer.ui.system.macos; + +import com.sun.jna.Library; +import com.sun.jna.Native; + +/** + * Quartz 2D API. + * + * @author chatellier + * @version $Revision$ + * @since 1.3.2 + * + * Last update : $Date$ + * By : $Author: chatellier $ + */ +public interface ApplicationServices extends Library { + + ApplicationServices INSTANCE = (ApplicationServices) Native.loadLibrary( + "ApplicationServices", ApplicationServices.class); + + /** Constants that specify an input event. */ + int kCGAnyInputEventType = -1; + /** Specifies that an event source should use a private event state table. */ + int kCGEventSourceStatePrivate = -1; + /** Specifies that an event source should use the event state table that reflects the combined state of all event sources posting to the current user login session. */ + int kCGEventSourceStateCombinedSessionState = 0; + /** Specifies that an event source should use the event state table that reflects the combined state of all hardware event sources posting from the HID system. */ + int kCGEventSourceStateHIDSystemState = 1; + + /** + * Returns the elapsed time since the last event for a Quartz event source. + * + * @param sourceStateId The source state to access + * @param eventType The event type to access + * @return the time in seconds since the previous input event of the specified type + * + * @see <a href="http://developer.apple.com/mac/library/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html#//apple_ref/c/func/CGEventSourceSecondsSinceLastEventType">Quartz API</a> + */ + public double CGEventSourceSecondsSinceLastEventType(int sourceStateId, + int eventType); +} \ No newline at end of file Property changes on: trunk/src/main/java/org/chorem/jtimer/ui/system/macos/ApplicationServices.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" Added: trunk/src/main/java/org/chorem/jtimer/ui/system/macos/MacOSSystemInfo.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/system/macos/MacOSSystemInfo.java (rev 0) +++ trunk/src/main/java/org/chorem/jtimer/ui/system/macos/MacOSSystemInfo.java 2010-01-04 09:02:46 UTC (rev 2717) @@ -0,0 +1,49 @@ +/* * + * Copyright (C) 2010 Code Lutin, Eric Chatellier + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + **/ + +package org.chorem.jtimer.ui.system.macos; + +import org.chorem.jtimer.ui.system.SystemInfo; + +/** + * MacOSSystemInfo + * + * Source : http://ochafik.free.fr/blog/?p=98#comment-17694 + * + * @author chatellier + * @version $Revision$ + * @since 1.3.2 + * + * Last update : $Date$ + * By : $Author: chatellier $ + */ +public class MacOSSystemInfo implements SystemInfo { + + /* + * @see org.chorem.jtimer.ui.system.SystemInfo#getIdleTime() + */ + @Override + public long getIdleTime() { + double idleTimeSeconds = ApplicationServices.INSTANCE + .CGEventSourceSecondsSinceLastEventType( + ApplicationServices.kCGEventSourceStateCombinedSessionState, + ApplicationServices.kCGAnyInputEventType); + return (long) (idleTimeSeconds * 1000); + } + +} Property changes on: trunk/src/main/java/org/chorem/jtimer/ui/system/macos/MacOSSystemInfo.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" Added: trunk/src/main/java/org/chorem/jtimer/ui/system/macos/package-info.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/system/macos/package-info.java (rev 0) +++ trunk/src/main/java/org/chorem/jtimer/ui/system/macos/package-info.java 2010-01-04 09:02:46 UTC (rev 2717) @@ -0,0 +1,4 @@ +/** + * Mac OS specific system info implementation. + */ +package org.chorem.jtimer.ui.system.macos; Property changes on: trunk/src/main/java/org/chorem/jtimer/ui/system/macos/package-info.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" Modified: trunk/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java 2009-12-18 09:11:04 UTC (rev 2716) +++ trunk/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java 2010-01-04 09:02:46 UTC (rev 2717) @@ -28,7 +28,7 @@ * @author chatellier * @version $Revision$ * - * @see "http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui..." + * @see <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputstructures/lastinputinfo.asp">Windows API</a> * * Last update : $Date$ * By : $Author$