Advertisement
Guest User

Untitled

a guest
May 28th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.40 KB | None | 0 0
  1.  
  2. void MainWindow::ontime()
  3. {
  4.     if (Timer_Count == 5)                   // check for new day
  5.     {
  6.         date_today = QDate::currentDate();  // get today date
  7.         day = date_today.day();             // refresh day
  8.         month = date_today.month();         // refresh month
  9.         year = date_today.year();           // refresh year
  10.         int cl_day;        int cl_month;        int cl_year;
  11.         cl_day = date_opened.day();         // get day on which program has started
  12.         cl_month = date_opened.month();
  13.         cl_year = date_opened.year();
  14.         if (cl_day != day)                  // if new day reset today.db
  15.         {                                     // and save it to /daily
  16.             dump = chdir(workdir.toAscii());
  17.             QString newfilename;
  18.             newfilename = date_to_name(cl_year,cl_month,cl_day);            // get new daily filename
  19.             dump = system("cp today.db " + dailydir.toAscii() + newfilename.toAscii());    // save to daily
  20.             dump = system("rm today.db");                                  // remove today.db
  21.             today_db.open(QIODevice::Text | QIODevice::ReadWrite);  // recreates the file
  22.             create_today_db();
  23.             date_opened.setDate(year,month,day);    // reset to be opened now
  24.         }
  25.         inifile->beginGroup("Settings");                // anti crash safeguard
  26.             inifile->setValue("closing_day",day);       // save day
  27.             inifile->setValue("closing_month",month);   // save month
  28.             inifile->setValue("closing_year",year);     // save year
  29.         inifile->endGroup();
  30.         inifile->sync();                                // save inifile
  31.         timer_count2 = 0;                               // reset timer
  32.     }
  33.  
  34.     AppName = get_process_name();       // get name of focused process
  35.     PrevApp = CurApp;                   // sets previous application
  36.     CurApp = AppName;                   // sets current application name
  37.  
  38.     PrevTime = CurTime ;                // saves time
  39.     CurTime = CurTime + (timer_delay / 1000);      // advances time
  40.  
  41.     if (CurApp != PrevApp)      // if new app then save it with half time
  42.         save_app(CurApp,CurTime / 2);
  43.     else save_app(CurApp,CurTime);  // else save with full time
  44.  
  45.     if (Timer_Count == 20)                           // save to disk
  46.         {
  47.             Timer_Count = 0;                        // new timer cycle
  48.             save_today_db();                        // save db
  49.         }
  50.  
  51.     if (CurApp != PrevApp)                          // if new app then
  52.         {                                           // save with half the timer_delay time
  53.             save_app(PrevApp,(PrevTime + ( (timer_delay / 1000) / 2 )));
  54.         }
  55.  
  56.     if ((MainWindow::isHidden() == false) && (visible_check == true))
  57.         // if MainWindow is not hidden and today tab is focused then
  58.             fill_today_table(today);                // update table
  59.  
  60.     Timer_Count++;
  61.     timer_count2++;
  62.     save_today_db();
  63.     app_name_bar->setText(AppName);                 // set app name
  64. }
  65.  
  66. void MainWindow::trayClicked(QSystemTrayIcon::ActivationReason reason)
  67. {
  68.     if (reason == QSystemTrayIcon::Trigger)     // if tray clicked
  69.         {
  70.             if (MainWindow::isHidden() == true) // if hidden
  71.                 MainWindow::show();             // show
  72.             else                                // else
  73.                 MainWindow::hide();             // hide
  74.         }
  75.     fill_today_table(today);   
  76. }
  77.  
  78. int MainWindow::save_app(QString application,int app_time)
  79. {
  80.     int time_buff;                      // modify time buffer
  81.     CurTime = 0;                        // reset the timer
  82.     if (CurApp == PrevApp)              // cpu load minimizer
  83.     {
  84.         time_buff = get_time(today,application);  // get saved time
  85.         time_buff = time_buff + app_time;         // add saved time
  86.         modify(today,application,time_buff);      // modify time
  87.         return 1;
  88.     }
  89.     if (exists(today,application))      // if the app exists
  90.     {
  91.         time_buff = get_time(today,application);  // get saved time
  92.         time_buff = time_buff + app_time;         // add saved time
  93.         modify(today,application,time_buff);      // modify time
  94.     }
  95.     else                                    // else insert new line
  96.     {
  97.         root.appendChild(ins(today,application,app_time));
  98.     }
  99.     return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement