ktimetracker
karmutility.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "karmutility.h"
00023
00024 #include <KGlobal>
00025 #include <KLocale>
00026
00027 #include <math.h>
00028 #include <stdlib.h>
00029 #include <X11/Xlib.h>
00030 #include <fixx11h.h>
00031
00032 QString getFocusWindow()
00033 {
00034 Display *display = XOpenDisplay( 0 );
00035 char *name;
00036 Window window = 0;
00037 int i = 0;
00038 XGetInputFocus( display, &window, &i );
00039 XFetchName( display, window, &name );
00040 XCloseDisplay( display );
00041
00042 return QString( name );
00043 }
00044
00045 QString formatTime( double minutes, bool decimal )
00046
00047
00048
00049
00050
00051 {
00052 kDebug(5970) << "Entering function(minutes=" << minutes << ",decimal=" << decimal << ");";
00053 QString time;
00054 if ( decimal )
00055 {
00056 time.sprintf( "%.2f", minutes / 60.0 );
00057 time.replace( '.', KGlobal::locale()->decimalSymbol() );
00058 }
00059 else time.sprintf("%s%ld:%02ld",
00060 (minutes < 0) ? KGlobal::locale()->negativeSign().toUtf8().data() : "",
00061 labs(minutes / 60), labs(((int) round(minutes)) % 60));
00062 return time;
00063 }