Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void MainWindow::ontime()
- {
- if (Timer_Count == 5) // check for new day
- {
- date_today = QDate::currentDate(); // get today date
- day = date_today.day(); // refresh day
- month = date_today.month(); // refresh month
- year = date_today.year(); // refresh year
- int cl_day; int cl_month; int cl_year;
- cl_day = date_opened.day(); // get day on which program has started
- cl_month = date_opened.month();
- cl_year = date_opened.year();
- if (cl_day != day) // if new day reset today.db
- { // and save it to /daily
- dump = chdir(workdir.toAscii());
- QString newfilename;
- newfilename = date_to_name(cl_year,cl_month,cl_day); // get new daily filename
- dump = system("cp today.db " + dailydir.toAscii() + newfilename.toAscii()); // save to daily
- dump = system("rm today.db"); // remove today.db
- today_db.open(QIODevice::Text | QIODevice::ReadWrite); // recreates the file
- create_today_db();
- date_opened.setDate(year,month,day); // reset to be opened now
- }
- inifile->beginGroup("Settings"); // anti crash safeguard
- inifile->setValue("closing_day",day); // save day
- inifile->setValue("closing_month",month); // save month
- inifile->setValue("closing_year",year); // save year
- inifile->endGroup();
- inifile->sync(); // save inifile
- timer_count2 = 0; // reset timer
- }
- AppName = get_process_name(); // get name of focused process
- PrevApp = CurApp; // sets previous application
- CurApp = AppName; // sets current application name
- PrevTime = CurTime ; // saves time
- CurTime = CurTime + (timer_delay / 1000); // advances time
- if (CurApp != PrevApp) // if new app then save it with half time
- save_app(CurApp,CurTime / 2);
- else save_app(CurApp,CurTime); // else save with full time
- if (Timer_Count == 20) // save to disk
- {
- Timer_Count = 0; // new timer cycle
- save_today_db(); // save db
- }
- if (CurApp != PrevApp) // if new app then
- { // save with half the timer_delay time
- save_app(PrevApp,(PrevTime + ( (timer_delay / 1000) / 2 )));
- }
- if ((MainWindow::isHidden() == false) && (visible_check == true))
- // if MainWindow is not hidden and today tab is focused then
- fill_today_table(today); // update table
- Timer_Count++;
- timer_count2++;
- save_today_db();
- app_name_bar->setText(AppName); // set app name
- }
- void MainWindow::trayClicked(QSystemTrayIcon::ActivationReason reason)
- {
- if (reason == QSystemTrayIcon::Trigger) // if tray clicked
- {
- if (MainWindow::isHidden() == true) // if hidden
- MainWindow::show(); // show
- else // else
- MainWindow::hide(); // hide
- }
- fill_today_table(today);
- }
- int MainWindow::save_app(QString application,int app_time)
- {
- int time_buff; // modify time buffer
- CurTime = 0; // reset the timer
- if (CurApp == PrevApp) // cpu load minimizer
- {
- time_buff = get_time(today,application); // get saved time
- time_buff = time_buff + app_time; // add saved time
- modify(today,application,time_buff); // modify time
- return 1;
- }
- if (exists(today,application)) // if the app exists
- {
- time_buff = get_time(today,application); // get saved time
- time_buff = time_buff + app_time; // add saved time
- modify(today,application,time_buff); // modify time
- }
- else // else insert new line
- {
- root.appendChild(ins(today,application,app_time));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement