Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/Develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Allexin committed Feb 21, 2016
2 parents 6d3a0cf + f0d56bb commit cdaa24b
Show file tree
Hide file tree
Showing 53 changed files with 3,400 additions and 988 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/build-*
*.pro.user
/build_64_release/
/TrackYourTime.app/
/build_64_debug/
36 changes: 27 additions & 9 deletions BUILD_README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@

For building this application, Qt 5 is required
For building this application, Qt 5 is required

You can get it here: https://www.qt.io/download/
You can get it here: https://www.qt.io/download/

First build TrackYourTime.pro with Qt Creator - it is a typical Qt project
First build TrackYourTime.pro with Qt Creator - it is a typical Qt project

After building do the following:
After building do the following:

#Windows

Place TrackYourTime.exe in build folder, copy data folder,
copy platforms plugin with qwindows, copy necessary qt libs
Pack in compressed folder TrackYourTime_Windows.zip
Place TrackYourTime.exe in build folder, copy data folder,
copy platforms plugin with qwindows, copy necessary qt libs
Pack in compressed folder TrackYourTime_Windows.zip

#Mac OS X

Copy data into TrackYourTime.app/Contents/MacOS
Copy data into TrackYourTime.app/Contents/MacOS
copy platforms/libqcocoa.dylib into TrackYourTime.app/Contents/PlugIns/platforms
add key LSUIElement with value 1 into TrackYourTime.app/Contents/Info.plist
execute macdeployqt with -dmg flag
execute macdeployqt with -dmg flag(<path_to_qt/macdeployqt TrackYourTime.app -dmg>)
Rename package to TrackYourTime_MacOSX.dmg

#Linux
Place TrackYourTime in build folder,
copy data folder, copy checksystem
Pack into TrackYourTime_Linux.tar.gz


#Localization
its possible to make this work from console without QtCreator.
But QtCreator is simple and powerfull tool and i prefer to use it.

Open project in QtCreator
Go to menu Tools->External->Linguist->Update Translations(lupdate)
Launch Qt Linguist(<qt_path/bin/linguist>)
Open *.ts file for edit
Edit file(edit item and press Ctrl+Enter)
Save file
Go to menu Tools->External->Linguist->Release Translations(lrelease)
Move *.qm file into data/languages

If you create new language - create file with name data/languages/lang_<lang_id>_name.utf8
Open this file in utf8 text editor
And place only one line in utd8 encoding - name of language in native format
22 changes: 18 additions & 4 deletions TrackYourTime/TrackYourTime.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

mac:LIBS += -framework CoreGraphics
mac:LIBS += -framework AppKit
mac: QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.8

TARGET = TrackYourTime
TEMPLATE = app
CONFIG+=address_sanitizer
CONFIG+=C++11

TRANSLATIONS = lang_en.ts lang_ru.ts

QMAKE_CXXFLAGS += -DQT_COMPILING_QSTRING_COMPAT_CPP

unix:!mac:QMAKE_CXXFLAGS += -std=c++0x
unix:!mac: LIBS += -rdynamic

win32:QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01

Expand All @@ -29,7 +32,7 @@ mac:ICON = main.icns
win32:LIBS += -luser32
unix:!mac:LIBS += -lX11

INCLUDEPATH += "ui"
INCLUDEPATH += ui data tools

SOURCES += \
main.cpp \
Expand All @@ -47,7 +50,11 @@ SOURCES += \
data/cscriptsmanager.cpp \
ui/app_settingswindow.cpp \
data/capppredefinedinfo.cpp \
tools/tools.cpp
tools/tools.cpp \
data/cschedule.cpp \
ui/schedulewindow.cpp \
ui/notification_dummy.cpp \
ui/notificationwindow.cpp

HEADERS += \
ui/settingswindow.h \
Expand All @@ -64,12 +71,19 @@ HEADERS += \
data/cscriptsmanager.h \
ui/app_settingswindow.h \
data/capppredefinedinfo.h \
tools/tools.h
tools/tools.h \
data/cschedule.h \
ui/schedulewindow.h \
ui/notification_dummy.h \
ui/notificationwindow.h

FORMS += \
ui/settingswindow.ui \
ui/statisticwindow.ui \
ui/applicationswindow.ui \
ui/profileswindow.ui \
ui/aboutwindow.ui \
ui/app_settingswindow.ui
ui/app_settingswindow.ui \
ui/schedulewindow.ui \
ui/notification_dummy.ui \
ui/notificationwindow.ui
137 changes: 100 additions & 37 deletions TrackYourTime/data/cdatamanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <QFileInfo>
#include <QDir>
#include <QStandardPaths>
#include <QSettings>
#include "../tools/tools.h"
#include "../tools/os_api.h"
#include "../tools/cfilebin.h"
#include "cdbversionconverter.h"
Expand All @@ -33,12 +33,20 @@ const QString cDataManager::CONF_AUTOSAVE_DELAY_ID = "AUTOSAVE_DELAY";
const QString cDataManager::CONF_STORAGE_FILENAME_ID = "STORAGE_FILENAME";
const QString cDataManager::CONF_LANGUAGE_ID = "LANGUAGE";
const QString cDataManager::CONF_FIRST_LAUNCH_ID = "FIRST_LAUNCH";
const QString cDataManager::CONF_SHOW_BALOONS_ID = "SHOW_BALOONS";
const QString cDataManager::CONF_NOTIFICATION_TYPE_ID = "NOTIFICATION_TYPE";
const QString cDataManager::CONF_NOTIFICATION_MESSAGE_ID = "NOTIFICATION_MESSAGE";
const QString cDataManager::CONF_NOTIFICATION_HIDE_SECONDS_ID = "NOTIFICATION_HIDE_SECONDS";
const QString cDataManager::CONF_NOTIFICATION_HIDE_MOVES_ID = "NOTIFICATION_HIDE_MOVES";
const QString cDataManager::CONF_NOTIFICATION_POSITION_ID = "NOTIFICATION_POSITION";
const QString cDataManager::CONF_NOTIFICATION_SIZE_ID = "NOTIFICATION_SIZE";
const QString cDataManager::CONF_NOTIFICATION_OPACITY_ID = "NOTIFICATION_OPACITY";
const QString cDataManager::CONF_AUTORUN_ID = "AUTORUN_ENABLED";
const QString cDataManager::CONF_CLIENT_MODE_ID = "CLIENT_MODE";
const QString cDataManager::CONF_CLIENT_MODE_HOST_ID = "CLIENT_MODE_HOST";

cDataManager::cDataManager():QObject()
{
m_ShowBaloons = true;
m_NotificationType = NT_SYSTEM;

m_UpdateCounter = 0;
m_UpdateDelay = DEFAULT_SECONDS_UPDATE_DELAY;
Expand All @@ -64,10 +72,12 @@ cDataManager::cDataManager():QObject()
#endif

loadPreferences();
QDir storagePath(QFileInfo(m_StorageFileName).absolutePath());
if (!storagePath.exists())
storagePath.mkpath(".");
loadDB();
if (!m_StorageFileName.isEmpty()){
QDir storagePath(QFileInfo(m_StorageFileName).absolutePath());
if (!storagePath.exists())
storagePath.mkpath(".");
loadDB();
}

if (m_Profiles.size()==0){
sProfile defaultProfile;
Expand All @@ -87,6 +97,13 @@ cDataManager::~cDataManager()
delete m_Applications[i];
}

const sProfile *cDataManager::profiles(int index)
{
if (index<0 || index>=m_Profiles.size())
return NULL;
return &m_Profiles[index];
}

void cDataManager::addNewProfile(const QString &Name, int CloneProfileIndex)
{
sProfile profile;
Expand Down Expand Up @@ -187,23 +204,59 @@ void cDataManager::process()
m_CurrentMousePos = mousePos;
}

if (isUserActive)
m_LastLocalActivity = 0;
else
m_LastLocalActivity+=m_UpdateDelay;
int hostActivity = m_LastLocalActivity+1;
sOverrideTrackerInfo* info = m_ExternalTrackers.getOverrideTracker();
if (info)
hostActivity = info->IdleTime-2;


//Update application
bool isAppChanged = false;
sSysInfo currentAppInfo = getCurrentApplication();
int appIndex = getAppIndex(currentAppInfo);
int activityIndex = appIndex>-1?getActivityIndex(appIndex,currentAppInfo):0;

if (m_LastLocalActivity>hostActivity){
if (info){
sSysInfo remoteInfo;
remoteInfo.fileName = info->AppFileName;
remoteInfo.path = "";
remoteInfo.title = "";
appIndex = getAppIndex(remoteInfo);
activityIndex = appIndex>-1?getActivityIndexDirect(appIndex,info->State):0;
isUserActive = true;
}
}

if (appIndex!=m_CurrentApplicationIndex || activityIndex!=m_CurrentApplicationActivityIndex){
isUserActive = true;
isAppChanged = true;
m_CurrentApplicationIndex = appIndex;
m_CurrentApplicationActivityIndex = activityIndex;
if (m_CurrentApplicationIndex>-1){
int activityCategory = m_Applications[m_CurrentApplicationIndex]->activities[m_CurrentApplicationActivityIndex].categories[m_CurrentProfile];
if (m_CurrentApplicationActivityCategory!=activityCategory){
if (m_CurrentApplicationActivityCategory!=activityCategory || activityCategory==-1){
m_CurrentApplicationActivityCategory = activityCategory;
QString hint = m_Profiles[m_CurrentProfile].name+":"+(m_CurrentApplicationActivityCategory==-1?tr("Uncategorized"):m_Categories[m_CurrentApplicationActivityCategory].name);
if (m_ShowBaloons)
emit trayShowHint(hint);

switch(m_NotificationType){
case NT_NONE:{

};
break;
case NT_SYSTEM:{
QString hint = m_Profiles[m_CurrentProfile].name+":"+(m_CurrentApplicationActivityCategory==-1?tr("Uncategorized"):m_Categories[m_CurrentApplicationActivityCategory].name);
emit trayShowHint(hint);
};
break;
case NT_BUILTIN:{
emit showNotification();
};
break;
}
}
}
}
Expand Down Expand Up @@ -239,6 +292,18 @@ void cDataManager::process()
m_AutoSaveCounter = 0;
saveDB();
}

if (!m_Idle && m_ClientMode){
if (m_CurrentApplicationIndex>-1){
m_ExternalTrackers.sendOverrideTracker(m_Applications[m_CurrentApplicationIndex]->activities[0].name,
m_Applications[m_CurrentApplicationIndex]->activities[m_CurrentApplicationActivityIndex].name,
m_IdleCounter==m_UpdateDelay?0:m_IdleCounter,
m_ClientModeHost);
}
else{
m_ExternalTrackers.sendOverrideTracker("","",m_IdleCounter==m_UpdateDelay?0:m_IdleCounter,m_ClientModeHost);
}
}
}

void cDataManager::onPreferencesChanged()
Expand Down Expand Up @@ -283,12 +348,10 @@ int cDataManager::getActivityIndex(int appIndex,const sSysInfo &FileInfo)
emit debugScriptResult(m_ScriptsManager.evalute(FileInfo,m_DebugScript),FileInfo);
}

if (appInfo->trackerType==sAppInfo::eTrackerType::TT_EXECUTABLE_DETECTOR)
return 0;

QString activity;

switch(appInfo->trackerType){
case sAppInfo::eTrackerType::TT_EXECUTABLE_DETECTOR:
case sAppInfo::eTrackerType::TT_EXTERNAL_DETECTOR:{
if (!m_ExternalTrackers.getExternalTrackerState(appInfo->activities[0].name,activity))
activity="";
Expand All @@ -304,22 +367,26 @@ int cDataManager::getActivityIndex(int appIndex,const sSysInfo &FileInfo)
break;
}

return getActivityIndexDirect(appIndex,activity);
}

if (activity.isEmpty())
int cDataManager::getActivityIndexDirect(int appIndex, QString activityName)
{
if (activityName.isEmpty())
return 0;

for (int i = 0; i<m_Applications[appIndex]->activities.size(); i++){
if (m_Applications[appIndex]->activities[i].name==activity){
if (m_Applications[appIndex]->activities[i].name==activityName){
return i;
}
}

sActivityInfo ainfo;
ainfo.visible = true;
ainfo.name = activity;
ainfo.name = activityName;
ainfo.categories.resize(m_Profiles.size());
for (int i = 0; i<ainfo.categories.size(); i++)
ainfo.categories[i] = m_Applications[appIndex]->activities[0].categories[i];
ainfo.categories[i] = -1;
m_Applications[appIndex]->activities.push_back(ainfo);
emit applicationsChanged();
return m_Applications[appIndex]->activities.size()-1;
Expand All @@ -329,6 +396,8 @@ const int FILE_FORMAT_VERSION = 2;

void cDataManager::saveDB()
{
if (m_StorageFileName.isEmpty())
return;
cFileBin file( m_StorageFileName+".new" );
if ( file.open(QIODevice::WriteOnly) )
{
Expand Down Expand Up @@ -390,6 +459,9 @@ void cDataManager::saveDB()

void cDataManager::loadDB()
{
if (m_StorageFileName.isEmpty())
return;
qDebug() << "cDataManager: start DB loading\n";
for (int i = 0; i<m_Applications.size(); i++)
delete m_Applications[i];
m_Applications.resize(0);
Expand Down Expand Up @@ -461,31 +533,22 @@ void cDataManager::loadDB()

file.close();
}
qDebug() << "cDataManager: end DB loading\n";
}

void cDataManager::loadPreferences()
{
QSettings settings;

m_UpdateDelay = settings.value(CONF_UPDATE_DELAY_ID,m_UpdateDelay).toInt();
m_IdleDelay = settings.value(CONF_IDLE_DELAY_ID,m_IdleDelay).toInt();
m_AutoSaveDelay = settings.value(CONF_AUTOSAVE_DELAY_ID,m_AutoSaveDelay).toInt();
m_StorageFileName = settings.value(CONF_STORAGE_FILENAME_ID,m_StorageFileName).toString();
m_ShowBaloons = settings.value(CONF_SHOW_BALOONS_ID,m_ShowBaloons).toBool();
cSettings settings;

m_UpdateDelay = settings.db()->value(CONF_UPDATE_DELAY_ID,m_UpdateDelay).toInt();
m_IdleDelay = settings.db()->value(CONF_IDLE_DELAY_ID,m_IdleDelay).toInt();
m_AutoSaveDelay = settings.db()->value(CONF_AUTOSAVE_DELAY_ID,m_AutoSaveDelay).toInt();
m_StorageFileName = settings.db()->value(CONF_STORAGE_FILENAME_ID,m_StorageFileName).toString();
m_NotificationType = (eNotificationType)settings.db()->value(CONF_NOTIFICATION_TYPE_ID,m_NotificationType).toInt();
m_ClientMode = settings.db()->value(CONF_CLIENT_MODE_ID,m_ClientMode).toBool();
m_ClientModeHost = settings.db()->value(CONF_CLIENT_MODE_HOST_ID,m_ClientModeHost).toString();
}

void cDataManager::savePreferences()
{
QSettings settings;

settings.setValue(CONF_UPDATE_DELAY_ID,m_UpdateDelay);
settings.setValue(CONF_IDLE_DELAY_ID,m_IdleDelay);
settings.setValue(CONF_AUTOSAVE_DELAY_ID,m_AutoSaveDelay);
settings.setValue(CONF_STORAGE_FILENAME_ID,m_StorageFileName);
settings.sync();
}




void sActivityInfo::incTime(bool FirstTime, int CurrentProfile, int UpdateDelay)
Expand Down
Loading

0 comments on commit cdaa24b

Please sign in to comment.