Git commit b7d3171ac39a3dab66d1fea2e1540a82e7d0c5d4 by Christophe Giboudeau= x, on behalf of Ren=C3=A9 J.V. Bertin. Committed on 31/07/2014 at 20:21. Pushed by cgiboudeaux into branch 'master'. Make KTimeTracker build on OSX On OSX, XScreensaver doesn't exist. This commit makes KTimeTracker use the = native method from the ApplicationServices framework on this platform. REVIEW: 119533 M +1 -2 CMakeLists.txt M +18 -6 ktimetracker/CMakeLists.txt M +25 -10 ktimetracker/idletimedetector.cpp M +5 -4 ktimetracker/idletimedetector.h M +2 -0 ktimetracker/ktimetrackerutility.cpp M +8 -0 ktimetracker/mainwindow.cpp http://commits.kde.org/kdepim/b7d3171ac39a3dab66d1fea2e1540a82e7d0c5d4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 470eddb..1f8670c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -306,8 +306,7 @@ else() if(QT_QT3SUPPORT_FOUND) macro_optional_add_subdirectory(knode) endif() - - if(Q_WS_X11) + if(NOT WIN32) macro_optional_add_subdirectory(ktimetracker) endif() = diff --git a/ktimetracker/CMakeLists.txt b/ktimetracker/CMakeLists.txt index bf7b0ef..f61c9c7 100644 --- a/ktimetracker/CMakeLists.txt +++ b/ktimetracker/CMakeLists.txt @@ -1,15 +1,18 @@ project(ktimetracker) = +if(NOT Q_WS_MAC) #We check if X11_Xscreensaver was found -if(X11_Xscreensaver_FOUND) - message(STATUS "Found the X11 screensaver extension") - macro_bool_to_01(X11_Xscreensaver_LIB HAVE_LIBXSS) + if(X11_Xscreensaver_FOUND) + message(STATUS "Found the X11 screensaver extension") + macro_bool_to_01(X11_Xscreensaver_LIB HAVE_LIBXSS) + else() + message(STATUS "The X11 screensaver extension was NOT found.") + endif() + add_feature_info("KtimeTracker idle detection" X11_Xscreensaver_FOUND "M= easure the screen idle time in KTimeTracker") else() - message(STATUS "The X11 screensaver extension was NOT found.") + add_feature_info("KtimeTracker idle detection" Q_WS_MAC "Measure the scr= een idle time in KTimeTracker") endif() = -add_feature_info("KtimeTracker idle detection" X11_Xscreensaver_FOUND "Mea= sure the screen idle time in KTimeTracker") - configure_file(config-ktimetracker.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/con= fig-ktimetracker.h ) = add_subdirectory( support ) @@ -69,6 +72,9 @@ target_link_libraries(ktimetracker ${KDE4_KCMUTILS_LIBS= } ${KDE4_KPARTS_LIBRARY if(X11_Xscreensaver_LIB) target_link_libraries(ktimetracker ${X11_Xscreensaver_LIB} ) endif() +if(Q_WS_MAC) + target_link_libraries(ktimetracker "-framework ApplicationServices" ) +endif() = install( TARGETS karm ${INSTALL_TARGETS_DEFAULT_ARGS} ) install( TARGETS ktimetracker ${INSTALL_TARGETS_DEFAULT_ARGS} ) @@ -84,6 +90,9 @@ target_link_libraries(kcm_ktimetracker ${KDE4_KIO_LIBS}= ${KDE4_KDEUI_LIBS} ${K if(X11_Xscreensaver_LIB) target_link_libraries(kcm_ktimetracker ${X11_Xscreensaver_LIB} ) endif() +if(Q_WS_MAC) + target_link_libraries(kcm_ktimetracker "-framework ApplicationServic= es" ) +endif() = install(TARGETS kcm_ktimetracker DESTINATION ${PLUGIN_INSTALL_DIR}) = @@ -99,6 +108,9 @@ target_link_libraries(ktimetrackerpart ${KDE4_KCMUTILS_L= IBS} ${KDEPIMLIBS_KCALC if(X11_Xscreensaver_LIB) target_link_libraries(ktimetrackerpart ${X11_Xscreensaver_LIB}) endif() +if(Q_WS_MAC) + target_link_libraries(ktimetrackerpart "-framework ApplicationServic= es" ) +endif() = = install(TARGETS ktimetrackerpart DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/ktimetracker/idletimedetector.cpp b/ktimetracker/idletimedetec= tor.cpp index 250dda5..ccd35f6 100644 --- a/ktimetracker/idletimedetector.cpp +++ b/ktimetracker/idletimedetector.cpp @@ -39,6 +39,10 @@ #include #endif = +#ifdef Q_OS_MAC +# include +#endif + IdleTimeDetector::IdleTimeDetector(int maxIdle) { _maxIdle =3D maxIdle; @@ -47,11 +51,16 @@ IdleTimeDetector::IdleTimeDetector(int maxIdle) int event_base, error_base; if(XScreenSaverQueryExtension(QX11Info::display(), &event_base, &error= _base)) _idleDetectionPossible =3D true; else _idleDetectionPossible =3D false; - _timer =3D new QTimer(this); - connect(_timer, SIGNAL(timeout()), this, SLOT(check())); +#elif defined(Q_OS_MAC) + _idleDetectionPossible =3D true; #else _idleDetectionPossible =3D false; #endif // HAVE_LIBXSS + if( _idleDetectionPossible ){ + _timer =3D new QTimer(this); + // the slot was renamed to runOnce() to avoid a macro defined thro= ugh ApplicationServices.h on OS X + connect(_timer, SIGNAL(timeout()), this, SLOT(runOnce())); + } } = bool IdleTimeDetector::isIdleDetectionPossible() @@ -59,11 +68,11 @@ bool IdleTimeDetector::isIdleDetectionPossible() return _idleDetectionPossible; } = -void IdleTimeDetector::check() +void IdleTimeDetector::runOnce() { kDebug(5970) << "Entering function"; #if defined(HAVE_LIBXSS) && defined(Q_WS_X11) - kDebug(5970) << "kompiled for libxss and x11, idledetectionpossible is= " << _idleDetectionPossible; + kDebug(5970) << "compiled for libxss and x11, idledetectionpossible is= " << _idleDetectionPossible; if (_idleDetectionPossible) { _mit_info =3D XScreenSaverAllocInfo(); @@ -74,6 +83,12 @@ void IdleTimeDetector::check() if (idleminutes >=3D _maxIdle) informOverrun(); } +#elif defined(Q_OS_MAC) + // see http://stackoverflow.com/a/22307622/1460868 + idleminutes =3D (int) CGEventSourceSecondsSinceLastEventType( kCGEvent= SourceStateHIDSystemState, kCGAnyInputEventType ) / secsPerMinute; + if( idleminutes >=3D _maxIdle ){ + informOverrun(); + } #endif // HAVE_LIBXSS } = @@ -92,7 +107,7 @@ void IdleTimeDetector::revert() emit(stopAllTimers(idlestart)); } = -#if defined(HAVE_LIBXSS) && defined(Q_WS_X11) +#if (defined(HAVE_LIBXSS) && defined(Q_WS_X11)) || defined(Q_OS_MAC) void IdleTimeDetector::informOverrun() { if (!_overAllIdleDetect) @@ -126,20 +141,20 @@ void IdleTimeDetector::informOverrun() kDebug(5970) << "Setting WinId " << dialog->winId() << " to deskTo= p " << KWindowSystem::self()->currentDesktop(); dialog->show(); } -#endif // HAVE_LIBXSS +#endif // HAVE_LIBXSS || Q_OS_MAC = void IdleTimeDetector::startIdleDetection() { -#if defined(HAVE_LIBXSS) && defined(Q_WS_X11) - if (!_timer->isActive()) +#if (defined(HAVE_LIBXSS) && defined(Q_WS_X11)) || defined(Q_OS_MAC) + if (!_timer->isActive()) _timer->start(testInterval); #endif //HAVE_LIBXSS } = void IdleTimeDetector::stopIdleDetection() { -#if defined(HAVE_LIBXSS) && defined(Q_WS_X11) - if (_timer->isActive()) +#if (defined(HAVE_LIBXSS) && defined(Q_WS_X11)) || defined(Q_OS_MAC) + if (_timer->isActive()) _timer->stop(); #endif // HAVE_LIBXSS } diff --git a/ktimetracker/idletimedetector.h b/ktimetracker/idletimedetecto= r.h index 524f739..ddf1166 100644 --- a/ktimetracker/idletimedetector.h +++ b/ktimetracker/idletimedetector.h @@ -59,13 +59,14 @@ public: Returns true if it is possible to do idle detection. Idle detection relys on a feature in the X server, which might not always be present. + On OS X, it uses CGEventSourceSecondsSinceLastEventType() from Applic= ationServices.framework **/ bool isIdleDetectionPossible(); = Q_SIGNALS: /** Tells the listener to subtract time from current timing. - The time to subtract is due to the idle time since the dialog wass + The time to subtract is due to the idle time since the dialog was shown, and until the user answers the dialog. @param minutes Minutes to subtract. **/ @@ -104,12 +105,12 @@ public Q_SLOTS: = = protected: -#if defined(HAVE_LIBXSS) && defined(Q_WS_X11) +#if (defined(HAVE_LIBXSS) && defined(Q_WS_X11)) || defined(Q_OS_MAC) void informOverrun(); -#endif // HAVE_LIBXSS +#endif // HAVE_LIBXSS || Q_OS_MAC = protected Q_SLOTS: - void check(); + void runOnce(); = private: #if defined(HAVE_LIBXSS) && defined(Q_WS_X11) diff --git a/ktimetracker/ktimetrackerutility.cpp b/ktimetracker/ktimetrack= erutility.cpp index efeba3a..567fa45 100644 --- a/ktimetracker/ktimetrackerutility.cpp +++ b/ktimetracker/ktimetrackerutility.cpp @@ -26,8 +26,10 @@ = #include #include +#ifdef Q_WS_X11 #include #include +#endif = QString getFocusWindow() { diff --git a/ktimetracker/mainwindow.cpp b/ktimetracker/mainwindow.cpp index 56d4c28..6661b9c 100644 --- a/ktimetracker/mainwindow.cpp +++ b/ktimetracker/mainwindow.cpp @@ -71,7 +71,15 @@ MainWindow::MainWindow( const QString &icsfile ) // and another one in the plugin. The build system should be fixed. //m_part =3D factory->create( this ); = +#ifdef Q_OS_MAC + // not sure if this is really required but this is the code that works= for me with g++-mp-4.8 + static KParts::ReadWritePart *rwp =3D factory->create( this ); + static ktimetrackerpart *mp =3D dynamic_cast( r= wp ); + m_part =3D dynamic_cast( rwp ); + kError() << "this=3D" << this << "; rwp=3D" << rwp << "; mp=3D" << mp = << "; m_part=3D" << m_part; +#else m_part =3D dynamic_cast( factory->create( this ) ); +#endif // Q_OS_MAC = if (m_part) {