File: todo.cpp

package info (click to toggle)
tea 28.1.1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,520 kB
  • ctags: 1,556
  • sloc: cpp: 10,148; ansic: 2,960; xml: 2,732; makefile: 7
file content (77 lines) | stat: -rw-r--r-- 1,503 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "todo.h"
#include "utils.h"


void CTodo::check_timeout()
{
  QDate cur_date = QDate::currentDate();
  if (cur_date.daysTo (prev_date) > 0)
      load_dayfile();
  
  QString time = QTime::currentTime().toString ("HH:mm");
  
  if (table.contains (time))
     {
      text_info->clear();
      text_info->insertHtml ("<b>" + time + "</b><br>");
      text_info->insertPlainText (table[time]);
     
      w->move (QPoint (1, 1));
     
      w->show();
      w->raise();
      w->activateWindow();
     } 
}


CTodo::~CTodo()
{
  delete w;
}


CTodo::CTodo()
{
  w = new QWidget(0, Qt::Window);
  w->resize (QSize (320, 240));
  w->setWindowTitle (tr ("Attention! Attention!"));
  text_info = new QTextEdit (w);   
  text_info->setReadOnly (true);
  text_info->resize (w->size());
  
  
  prev_date = QDate::currentDate();
  
  connect (&timer, SIGNAL(timeout()), this, SLOT(check_timeout()));
  timer.setInterval (1000 * 60);
  timer.start();
}


void CTodo::load_dayfile()
{
  QString fname = dir_days + "/" + QDate::currentDate().toString ("yyyy-MM-dd");
  
  if (! file_exists (fname))
     {
      table.clear();
      return;
     }
  
  QString s = qstring_load (fname);
  
  QStringList sl = s.split ('[');
  for (int i = 0; i < sl.size(); i++)
      {
       int br = sl[i].indexOf (']');
       if (br == -1)
          continue;
          
       QString time = sl[i].left (br);
       QString text = sl[i].right (sl[i].size() - br - 1);

       table.insert (time, text);
      }

}