Skip to content

Commit

Permalink
Merge pull request #54 from Allexin/Develop
Browse files Browse the repository at this point in the history
0.9.2.1 Release
  • Loading branch information
Allexin committed Feb 25, 2016
2 parents 8887410 + 75beb46 commit 50406e2
Show file tree
Hide file tree
Showing 42 changed files with 1,393 additions and 268 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
*.pro.user
/build_64_release/
/TrackYourTime.app/
/build_64_debug/
*.dmg
11 changes: 8 additions & 3 deletions TrackYourTime/TrackYourTime.pro
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ SOURCES += \
data/cschedule.cpp \
ui/schedulewindow.cpp \
ui/notification_dummy.cpp \
ui/notificationwindow.cpp
ui/notificationwindow.cpp \
data/cupdater.cpp \
ui/updateavailablewindow.cpp

HEADERS += \
ui/settingswindow.h \
Expand All @@ -75,7 +77,9 @@ HEADERS += \
data/cschedule.h \
ui/schedulewindow.h \
ui/notification_dummy.h \
ui/notificationwindow.h
ui/notificationwindow.h \
data/cupdater.h \
ui/updateavailablewindow.h

FORMS += \
ui/settingswindow.ui \
Expand All @@ -86,4 +90,5 @@ FORMS += \
ui/app_settingswindow.ui \
ui/schedulewindow.ui \
ui/notification_dummy.ui \
ui/notificationwindow.ui
ui/notificationwindow.ui \
ui/updateavailablewindow.ui
134 changes: 102 additions & 32 deletions TrackYourTime/data/cdatamanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "../tools/cfilebin.h"
#include "cdbversionconverter.h"
#include "capppredefinedinfo.h"
#include <QFileInfo>

const QString cDataManager::CONF_UPDATE_DELAY_ID = "UPDATE_DELAY";
const QString cDataManager::CONF_IDLE_DELAY_ID = "IDLE_DELAY";
Expand All @@ -43,6 +44,10 @@ 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";
const QString cDataManager::CONF_LAST_AVAILABLE_VERSION_ID = "LAST_AVAILABLE_VERSION";
const QString cDataManager::CONF_BACKUP_FILENAME_ID = "BACKUP_FILENAME";
const QString cDataManager::CONF_BACKUP_DELAY_ID = "BACKUP_DELAY";


cDataManager::cDataManager():QObject()
{
Expand Down Expand Up @@ -70,14 +75,10 @@ cDataManager::cDataManager():QObject()
#else
m_StorageFileName = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)+"/db.bin";
#endif
m_BackupFolder = QFileInfo(m_StorageFileName).absolutePath()+"/backup/";

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

if (m_Profiles.size()==0){
sProfile defaultProfile;
Expand Down Expand Up @@ -111,8 +112,12 @@ void cDataManager::addNewProfile(const QString &Name, int CloneProfileIndex)
m_Profiles.push_back(profile);

for (int i = 0; i<m_Applications.size(); i++)
for (int j = 0; j<m_Applications[i]->activities.size(); j++)
m_Applications[i]->activities[j].categories.push_back(CloneProfileIndex==-1?-1:m_Applications[i]->activities[j].categories[CloneProfileIndex]);
for (int j = 0; j<m_Applications[i]->activities.size(); j++){
sActivityProfileState state;
state.category = CloneProfileIndex==-1?-1:m_Applications[i]->activities[j].categories[CloneProfileIndex].category;
state.visible = CloneProfileIndex==-1?false:m_Applications[i]->activities[j].categories[CloneProfileIndex].visible;
m_Applications[i]->activities[j].categories.push_back(state);
}
emit profilesChanged();
}

Expand Down Expand Up @@ -157,11 +162,11 @@ void cDataManager::deleteCategory(int index)
for (int i = 0; i<m_Applications.size(); i++){
for (int j = 0; j<m_Applications[i]->activities.size(); j++){
for (int k = 0; k<m_Applications[i]->activities[j].categories.size(); k++){
if (m_Applications[i]->activities[j].categories[k]==index)
m_Applications[i]->activities[j].categories[k] = -1;
if (m_Applications[i]->activities[j].categories[k].category==index)
m_Applications[i]->activities[j].categories[k].category = -1;
else
if (m_Applications[i]->activities[j].categories[k]>index)
m_Applications[i]->activities[j].categories[k];
if (m_Applications[i]->activities[j].categories[k].category>index)
m_Applications[i]->activities[j].categories[k].category--;
}
}
}
Expand All @@ -173,12 +178,53 @@ void cDataManager::setApplicationActivityCategory(int profile, int appIndex, int
{
if (profile==-1){
for (int i = 0; i<m_Applications[appIndex]->activities[activityIndex].categories.size(); i++)
m_Applications[appIndex]->activities[activityIndex].categories[i] = category;
m_Applications[appIndex]->activities[activityIndex].categories[i].category = category;
}
else{
m_Applications[appIndex]->activities[activityIndex].categories[profile] = category;
m_Applications[appIndex]->activities[activityIndex].categories[profile].category = category;
}

}

void cDataManager::makeBackup()
{
int delayDays = -1;
switch(m_BackupDelay){
case BD_ONE_DAY:{
delayDays = 1;
}
break;
case BD_ONE_WEEK:{
delayDays = 7;
}
break;
case BD_ONE_MONTH:{
delayDays = 31;
}
break;
case BD_ONE_YEAR:{
delayDays = 365;
}
break;
case BD_FOREVER:{
delayDays = -1;
}
break;
}

QDateTime now = QDateTime::currentDateTime();
if (delayDays>-1){
QStringList backupFiles = QDir(m_BackupFolder).entryList(QStringList() << "*.backup");
for (int i = 0; i<backupFiles.size(); i++){
QFileInfo file(m_BackupFolder+"/"+backupFiles[i]);
if (now.daysTo(file.lastModified())>=delayDays){
QFile::remove(file.absoluteFilePath());
}
}
}

if (!m_StorageFileName.isEmpty())
QFile::copy(m_StorageFileName,m_BackupFolder+"/"+QFileInfo(m_StorageFileName).baseName()+"."+now.toString("yyyy_MM_dd__HH_mm")+".backup");
}

void cDataManager::process()
Expand Down Expand Up @@ -238,7 +284,8 @@ void cDataManager::process()
m_CurrentApplicationIndex = appIndex;
m_CurrentApplicationActivityIndex = activityIndex;
if (m_CurrentApplicationIndex>-1){
int activityCategory = m_Applications[m_CurrentApplicationIndex]->activities[m_CurrentApplicationActivityIndex].categories[m_CurrentProfile];
m_Applications[m_CurrentApplicationIndex]->activities[m_CurrentApplicationActivityIndex].categories[m_CurrentProfile].visible = true;
int activityCategory = m_Applications[m_CurrentApplicationIndex]->activities[m_CurrentApplicationActivityIndex].categories[m_CurrentProfile].category;
if (m_CurrentApplicationActivityCategory!=activityCategory || activityCategory==-1){
m_CurrentApplicationActivityCategory = activityCategory;

Expand Down Expand Up @@ -320,8 +367,9 @@ int cDataManager::getAppIndex(const sSysInfo &FileInfo)
if (FileInfo.fileName.isEmpty())
return -1;

QString upcaseFileName = FileInfo.fileName.toUpper();
for (int i = 0; i<m_Applications.size(); i++){
if (m_Applications[i]->activities[0].name==FileInfo.fileName){
if (m_Applications[i]->activities[0].nameUpcase==upcaseFileName){
if (m_Applications[i]->path.isEmpty() && !FileInfo.path.isEmpty()){
m_Applications[i]->path = FileInfo.path;
emit applicationsChanged();
Expand Down Expand Up @@ -353,7 +401,7 @@ int cDataManager::getActivityIndex(int appIndex,const sSysInfo &FileInfo)
switch(appInfo->trackerType){
case sAppInfo::eTrackerType::TT_EXECUTABLE_DETECTOR:
case sAppInfo::eTrackerType::TT_EXTERNAL_DETECTOR:{
if (!m_ExternalTrackers.getExternalTrackerState(appInfo->activities[0].name,activity))
if (!m_ExternalTrackers.getExternalTrackerState(appInfo->activities[0].nameUpcase,activity))
activity="";
};
break;
Expand All @@ -375,24 +423,28 @@ int cDataManager::getActivityIndexDirect(int appIndex, QString activityName)
if (activityName.isEmpty())
return 0;

QString activityNameUpcase = activityName.toUpper();

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

sActivityInfo ainfo;
ainfo.visible = true;
ainfo.name = activityName;
ainfo.nameUpcase = activityNameUpcase;
ainfo.categories.resize(m_Profiles.size());
for (int i = 0; i<ainfo.categories.size(); i++)
ainfo.categories[i] = -1;
for (int i = 0; i<ainfo.categories.size(); i++){
ainfo.categories[i].category = -1;
ainfo.categories[i].visible = false;
}
m_Applications[appIndex]->activities.push_back(ainfo);
emit applicationsChanged();
return m_Applications[appIndex]->activities.size()-1;
}

const int FILE_FORMAT_VERSION = 2;
const int FILE_FORMAT_VERSION = 3;

void cDataManager::saveDB()
{
Expand Down Expand Up @@ -429,14 +481,14 @@ void cDataManager::saveDB()

file.writeInt(m_Applications[i]->activities.size());
for (int activity = 0; activity<m_Applications[i]->activities.size(); activity++){
sActivityInfo* info = &m_Applications[i]->activities[activity];
file.writeInt(info->visible?1:0);
sActivityInfo* info = &m_Applications[i]->activities[activity];
file.writeString(info->name);

//app category for every profile
file.writeInt(info->categories.size());
for (int j = 0; j<info->categories.size(); j++){
file.writeInt(info->categories[j]);
file.writeInt(info->categories[j].category);
file.writeInt(info->categories[j].visible?1:0);
}

//total use time
Expand Down Expand Up @@ -466,7 +518,7 @@ void cDataManager::loadDB()
delete m_Applications[i];
m_Applications.resize(0);

convertToVersion2(m_StorageFileName,m_StorageFileName);
convertToVersion3(m_StorageFileName,m_StorageFileName);
cFileBin file( m_StorageFileName );
if ( file.open(QIODevice::ReadOnly) )
{
Expand Down Expand Up @@ -503,14 +555,15 @@ void cDataManager::loadDB()

m_Applications[i]->activities.resize(file.readInt());
for (int activity = 0; activity<m_Applications[i]->activities.size(); activity++){
sActivityInfo* info = &m_Applications[i]->activities[activity];
info->visible = file.readInt()==1;
sActivityInfo* info = &m_Applications[i]->activities[activity];
info->name = file.readString();
info->nameUpcase = info->name.toUpper();

//app category for every profile
info->categories.resize(file.readInt());
for (int j = 0; j<info->categories.size(); j++){
info->categories[j] = file.readInt();
info->categories[j].category = file.readInt();
info->categories[j].visible = file.readInt()==1;
}

//total use time
Expand Down Expand Up @@ -547,6 +600,21 @@ void cDataManager::loadPreferences()
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();

m_BackupDelay = (eBackupDelay)settings.db()->value(CONF_BACKUP_DELAY_ID,BD_ONE_WEEK).toInt();
m_BackupFolder = settings.db()->value(CONF_BACKUP_FILENAME_ID,m_BackupFolder).toString();

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

if (!m_BackupFolder.isEmpty()){
QDir backupPath(m_BackupFolder);
if (!backupPath.exists())
backupPath.mkpath(".");
}
}


Expand All @@ -568,11 +636,13 @@ sAppInfo::sAppInfo(QString name, int profilesCount)
predefinedInfo = new cAppPredefinedInfo(name);
visible = true;
sActivityInfo ainfo;
ainfo.visible = true;
ainfo.name = name;
ainfo.nameUpcase = name.toUpper();
ainfo.categories.resize(profilesCount);
for (int i = 0; i<ainfo.categories.size(); i++)
ainfo.categories[i] = -1;
for (int i = 0; i<ainfo.categories.size(); i++){
ainfo.categories[i].category = -1;
ainfo.categories[i].visible = false;
}
activities.push_back(ainfo);

trackerType = predefinedInfo->trackerType();
Expand Down
23 changes: 21 additions & 2 deletions TrackYourTime/data/cdatamanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ struct sTimePeriod{
int profileIndex;
};

struct sActivityProfileState{
int category;
bool visible;
};

struct sActivityInfo{
QString name;
QString nameUpcase;
QVector<sTimePeriod> periods;
QVector<int> categories;
bool visible;
QVector<sActivityProfileState> categories;
void incTime(bool FirstTime, int CurrentProfile, int UpdateDelay);
};

Expand Down Expand Up @@ -84,6 +89,13 @@ class cDataManager : public QObject {
NT_SYSTEM,
NT_BUILTIN
};
enum eBackupDelay{
BD_ONE_DAY = 0,
BD_ONE_WEEK,
BD_ONE_MONTH,
BD_ONE_YEAR,
BD_FOREVER
};

static const int DEFAULT_SECONDS_UPDATE_DELAY = 1;
static const int DEFAULT_SECONDS_IDLE_DELAY = 300;
Expand All @@ -105,6 +117,9 @@ class cDataManager : public QObject {
static const QString CONF_AUTORUN_ID;
static const QString CONF_CLIENT_MODE_ID;
static const QString CONF_CLIENT_MODE_HOST_ID;
static const QString CONF_LAST_AVAILABLE_VERSION_ID;
static const QString CONF_BACKUP_FILENAME_ID;
static const QString CONF_BACKUP_DELAY_ID;
protected:
cExternalTrackers m_ExternalTrackers;
cScriptsManager m_ScriptsManager;
Expand All @@ -117,6 +132,8 @@ class cDataManager : public QObject {
int m_LastLocalActivity;
int m_CurrentProfile;
QString m_StorageFileName;
QString m_BackupFolder;
eBackupDelay m_BackupDelay;

QString m_DebugScript;

Expand Down Expand Up @@ -179,6 +196,8 @@ class cDataManager : public QObject {

QString getStorageFileName(){return m_StorageFileName;}
void setDebugScript(const QString& script){m_DebugScript = script;}

void makeBackup();
public slots:
void process();
void onPreferencesChanged();
Expand Down
Loading

0 comments on commit 50406e2

Please sign in to comment.