Check-in [17cbddfd91]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added week numbers to the date picker; also, dates that have some info are shown in bold (doesn't work after switching months, though)
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 17cbddfd91ac4d0688f0c7f0626ddcfa9158f28b
User & Date: MCO 2011-05-05 12:21:49
Context
2011-05-08
17:35
Added global hotkey, timestamp of insert row gets updated a lot more often check-in: 0231250648 user: Martijn tags: trunk
2011-05-05
12:21
Added week numbers to the date picker; also, dates that have some info are shown in bold (doesn't work after switching months, though) check-in: 17cbddfd91 user: MCO tags: trunk
09:02
* If the program is already running, don't launch a second instance but activate the first; * If Shift is pressed during shutdown, no line '(closed)' is added.
check-in: 64b934fa0b user: MCO tags: trunk
Changes

Changes to src/F_Entry.dfm.

32
33
34
35
36
37
38

39
40
41
42
43
44
45
    Date = 40667.351732187500000000
    Format = 'd MMMM yyyy'
    Time = 40667.351732187500000000
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 1
    OnChange = dtpDayChange

  end
  object Grid: TStringGrid
    Left = 8
    Top = 35
    Width = 534
    Height = 375
    Anchors = [akLeft, akTop, akRight, akBottom]







>







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    Date = 40667.351732187500000000
    Format = 'd MMMM yyyy'
    Time = 40667.351732187500000000
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 1
    OnChange = dtpDayChange
    OnDropDown = dtpDayDropDown
  end
  object Grid: TStringGrid
    Left = 8
    Top = 35
    Width = 534
    Height = 375
    Anchors = [akLeft, akTop, akRight, akBottom]

Changes to src/F_Entry.pas.

15
16
17
18
19
20
21

22
23
24
25
26
27
28
..
43
44
45
46
47
48
49
50
51
52
53
54
55
56








57
58
59




60
61
62
63
64
65
66
..
74
75
76
77
78
79
80
81
82

83
84
85

86
87
88
89
90
91
92
...
132
133
134
135
136
137
138
























































139
140
141
142
143
144
145
...
296
297
298
299
300
301
302


303
304
305
306
307
308
309
...
314
315
316
317
318
319
320






























321
322
323
324
325
326
327
    procedure FormResize(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure tbsWeekChange(Sender: TObject; NewTab: Integer; var AllowChange: Boolean);
    procedure dtpDayChange(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure GridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);

  private
    { Private declarations }
    FDoneLoading: Boolean;
    FInhibitEvents: boolean;
    FDB: TSQLiteDatabase;
    FActiveDate: TDateTime;
    FLoadQuery: TSQLiteQuery;
................................................................................
  end;

var
  frmEntry: TfrmEntry;

implementation
uses
  DateUtils,
  L_KeysDown;

{$R *.dfm}

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmEntry.FormCreate(Sender: TObject);








var
  Row: Integer;
begin




  try
    dtpDay.MaxDate := dtpDay.Date + 7; // eigenlijk niet verder dan a.s. zondag...
    FillHeaders;
    InitializeDB;

    SetDate(Date);
    Row := AddRow(FActiveDate);
................................................................................
end;
{ ------------------------------------------------------------------------------------------------ }
procedure TfrmEntry.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
  Row: Integer;
begin
  if CanClose then begin
    if FDoneLoading and not isShiftDown then begin
      SetDate(Date);

      Row := AddRow(FActiveDate);
      Grid.Cells[1, Row] := '(overig)';
      Grid.Cells[2, Row] := 'Afgesloten';

      SaveGrid(FActiveDate);
    end;
  end;
end{TfrmEntry.FormCloseQuery};
{ ------------------------------------------------------------------------------------------------ }
procedure TfrmEntry.FormDestroy(Sender: TObject);
begin
................................................................................
{ ------------------------------------------------------------------------------------------------ }
procedure TfrmEntry.dtpDayChange(Sender: TObject);
begin
  if not FInhibitEvents then begin
    SetDate(dtpDay.Date);
  end;
end{TfrmEntry.dtpDayChange};

























































{ ------------------------------------------------------------------------------------------------ }
procedure TfrmEntry.tbsWeekChange(Sender: TObject; NewTab: Integer; var AllowChange: Boolean);
begin
  AllowChange := True;
  if not FInhibitEvents then begin
    if AllowChange then begin
................................................................................
  finally
    Cursor.Free;
  end;
end{TfrmEntry.LoadGrid};

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmEntry.InitializeDB;


begin
  // TODO: make it possible to move this elsewhere
  FDB := TSQLiteDatabase.Create(ChangeFileExt(ParamStr(0), '.sqlite'));

  if not FDB.TableExists('Entries') then begin
    FDB.Execute('PRAGMA user_version = 1;');

................................................................................
              + ' , activity              TEXT'
              + ' , date_inserted         TEXT    DEFAULT CURRENT_TIMESTAMP'
              + ' );');

    FDB.Execute('CREATE INDEX idx_Entries_datetime ON Entries (datetime);');
  end;































  FLoadQuery := FDB.PrepareSQL('   SELECT id'
                             + '   ,      time(datetime) AS time'
                             + '   ,      project'
                             + '   ,      activity'
                             + '     FROM Entries'
                             + '    WHERE datetime >= julianday(:Date)'
                             + '      AND datetime < julianday(:Date, "+1 day")'







>







 







|






>
>
>
>
>
>
>
>



>
>
>
>







 







|

>
|
|
|
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
..
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
78
79
..
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
...
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
    procedure FormResize(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure tbsWeekChange(Sender: TObject; NewTab: Integer; var AllowChange: Boolean);
    procedure dtpDayChange(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure GridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure dtpDayDropDown(Sender: TObject);
  private
    { Private declarations }
    FDoneLoading: Boolean;
    FInhibitEvents: boolean;
    FDB: TSQLiteDatabase;
    FActiveDate: TDateTime;
    FLoadQuery: TSQLiteQuery;
................................................................................
  end;

var
  frmEntry: TfrmEntry;

implementation
uses
  DateUtils, CommCtrl,
  L_KeysDown;

{$R *.dfm}

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmEntry.FormCreate(Sender: TObject);
const
  DTM_GETMCSTYLE = (DTM_FIRST + 12);
  DTM_SETMCSTYLE = (DTM_FIRST + 11);
  MCS_NOTRAILINGDATES = $0040;
  MCS_SHORTDAYSOFWEEK = $0080;
  MCS_NOSELCHANGEONNAV = $0100;
var
  style{, prevstyle}: LResult;
var
  Row: Integer;
begin
  style := SendMessage(dtpDay.Handle, DTM_GETMCSTYLE, 0, 0);
  style := style or MCS_DAYSTATE or MCS_WEEKNUMBERS or MCS_NOSELCHANGEONNAV;
  {prevstyle := }SendMessage(dtpDay.Handle, DTM_SETMCSTYLE, 0, style);

  try
    dtpDay.MaxDate := dtpDay.Date + 7; // eigenlijk niet verder dan a.s. zondag...
    FillHeaders;
    InitializeDB;

    SetDate(Date);
    Row := AddRow(FActiveDate);
................................................................................
end;
{ ------------------------------------------------------------------------------------------------ }
procedure TfrmEntry.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
  Row: Integer;
begin
  if CanClose then begin
    if FDoneLoading then begin
      SetDate(Date);
      if not isShiftDown then begin
        Row := AddRow(FActiveDate);
        Grid.Cells[1, Row] := '(overig)';
        Grid.Cells[2, Row] := 'Afgesloten';
      end;
      SaveGrid(FActiveDate);
    end;
  end;
end{TfrmEntry.FormCloseQuery};
{ ------------------------------------------------------------------------------------------------ }
procedure TfrmEntry.FormDestroy(Sender: TObject);
begin
................................................................................
{ ------------------------------------------------------------------------------------------------ }
procedure TfrmEntry.dtpDayChange(Sender: TObject);
begin
  if not FInhibitEvents then begin
    SetDate(dtpDay.Date);
  end;
end{TfrmEntry.dtpDayChange};

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmEntry.dtpDayDropDown(Sender: TObject);
const
  DTM_GETMCSTYLE = (DTM_FIRST + 12);
  DTM_SETMCSTYLE = (DTM_FIRST + 11);
  MCS_NOTRAILINGDATES = $0040;
  MCS_SHORTDAYSOFWEEK = $0080;
  MCS_NOSELCHANGEONNAV = $0100;
var
  monthCalHandle: THandle;
  monthRange: TSystemTimeRangeArray;
  FirstDate{, LastDate}: TDate;
  boldDates: array of TMonthDayState;
  im: Integer;
  Cursor: TSQLiteCursor;
  FS: TFormatSettings;
  MonthDay: Integer;
  fldBoldDate: TSQLiteField;
begin
  // TODO: write a TDateTimePicker that handles this properly!!!
  //       This will allow us to react to the MCN_GETDAYSTATE message, which is the proper place
  //       to handle bold days anyway (and it keeps working after you switch months)

  monthCalHandle := SendMessage(dtpDay.Handle, DTM_GETMONTHCAL, 0, 0);

  SetLength(boldDates, MonthCal_GetMonthRange(monthCalHandle, GMR_DAYSTATE, @monthRange));
  with monthRange[0] do FirstDate := EncodeDate(wYear, wMonth, wDay);
//  with monthRange[1] do LastDate := EncodeDate(wYear, wMonth, wDay);

  // make sure to set the relevant bit for each day in the specified month
  FS.DateSeparator := '-';
  FS.TimeSeparator := ':';
  FS.ShortDateFormat := 'yyyy-MM-dd';
  FS.LongDateFormat := 'yyyy-MM-dd';
  for im := 0 to High(boldDates) do begin
    boldDates[im] := 0;
    Cursor := FDB.GetCursor('   SELECT DISTINCT strftime("%d", datetime) AS bolddate'
                          + '     FROM Entries'
                          + '    WHERE substr(date(datetime), 1, 7) = ?1'
                          + ' ORDER BY bolddate'
                          , [ FormatDateTime('yyyy-MM', IncMonth(RecodeDay(FirstDate, 1), im), FS) ]
                          ) as TSQLiteCursor;
    try
      fldBoldDate := Cursor.Field['bolddate'] as TSQLiteField;
      while not Cursor.EOF do begin
        MonthDay := fldBoldDate.AsInteger;
        boldDates[im] := boldDates[im] or (1 shl (MonthDay - 1));
        Cursor.Next;
      end;
    finally
      Cursor.Free;
    end;
  end{for};
  SendMessage(monthCalHandle, MCM_SETDAYSTATE, Length(boldDates), integer(@boldDates[0]));
end;

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmEntry.tbsWeekChange(Sender: TObject; NewTab: Integer; var AllowChange: Boolean);
begin
  AllowChange := True;
  if not FInhibitEvents then begin
    if AllowChange then begin
................................................................................
  finally
    Cursor.Free;
  end;
end{TfrmEntry.LoadGrid};

{ ------------------------------------------------------------------------------------------------ }
procedure TfrmEntry.InitializeDB;
var
  OriginalDataVersion, DataVersion: Integer;
begin
  // TODO: make it possible to move this elsewhere
  FDB := TSQLiteDatabase.Create(ChangeFileExt(ParamStr(0), '.sqlite'));

  if not FDB.TableExists('Entries') then begin
    FDB.Execute('PRAGMA user_version = 1;');

................................................................................
              + ' , activity              TEXT'
              + ' , date_inserted         TEXT    DEFAULT CURRENT_TIMESTAMP'
              + ' );');

    FDB.Execute('CREATE INDEX idx_Entries_datetime ON Entries (datetime);');
  end;

  // Check the data version, and upgrade if necessary
  OriginalDataVersion := FDB.GetIntValue('PRAGMA user_version');
  DataVersion := OriginalDataVersion;

//  if DataVersion = 1 then begin
//    // Add the settings table
//
//    FDB.Execute(' CREATE TABLE Entries'
//              + ' ( id                    INTEGER PRIMARY KEY'
//              + ' , datetime              DOUBLE  NOT NULL'
//              + ' , project               TEXT    NOT NULL'
//              + ' , activity              TEXT'
//              + ' , date_inserted         TEXT    DEFAULT CURRENT_TIMESTAMP'
//              + ' );');
//
//    FDB.Execute('CREATE INDEX idx_Entries_datetime ON Entries (datetime);');
//
//    Inc(DataVersion);
//  end;


  // TODO: add necessary upgrades here



  if DataVersion <> OriginalDataVersion then begin
    FDB.Execute('PRAGMA user_version = ?1', [DataVersion]);
  end;

  // Prepare all the queries
  FLoadQuery := FDB.PrepareSQL('   SELECT id'
                             + '   ,      time(datetime) AS time'
                             + '   ,      project'
                             + '   ,      activity'
                             + '     FROM Entries'
                             + '    WHERE datetime >= julianday(:Date)'
                             + '      AND datetime < julianday(:Date, "+1 day")'

Changes to src/prj/D2010/Olam.dproj.

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
					</Parameters>
					<VersionInfo>
						<VersionInfo Name="IncludeVerInfo">True</VersionInfo>
						<VersionInfo Name="AutoIncBuild">True</VersionInfo>
						<VersionInfo Name="MajorVer">1</VersionInfo>
						<VersionInfo Name="MinorVer">0</VersionInfo>
						<VersionInfo Name="Release">0</VersionInfo>
						<VersionInfo Name="Build">5</VersionInfo>
						<VersionInfo Name="Debug">False</VersionInfo>
						<VersionInfo Name="PreRelease">False</VersionInfo>
						<VersionInfo Name="Special">False</VersionInfo>
						<VersionInfo Name="Private">True</VersionInfo>
						<VersionInfo Name="DLL">False</VersionInfo>
						<VersionInfo Name="Locale">1043</VersionInfo>
						<VersionInfo Name="CodePage">1252</VersionInfo>
					</VersionInfo>
					<VersionInfoKeys>
						<VersionInfoKeys Name="CompanyName">Martijn Coppoolse</VersionInfoKeys>
						<VersionInfoKeys Name="FileDescription">Olam Work registration helper</VersionInfoKeys>
						<VersionInfoKeys Name="FileVersion">1.0.0.5</VersionInfoKeys>
						<VersionInfoKeys Name="InternalName">Olam</VersionInfoKeys>
						<VersionInfoKeys Name="LegalCopyright"/>
						<VersionInfoKeys Name="LegalTrademarks"/>
						<VersionInfoKeys Name="OriginalFilename"/>
						<VersionInfoKeys Name="ProductName"/>
						<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
						<VersionInfoKeys Name="Comments"/>







|











|







80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
					</Parameters>
					<VersionInfo>
						<VersionInfo Name="IncludeVerInfo">True</VersionInfo>
						<VersionInfo Name="AutoIncBuild">True</VersionInfo>
						<VersionInfo Name="MajorVer">1</VersionInfo>
						<VersionInfo Name="MinorVer">0</VersionInfo>
						<VersionInfo Name="Release">0</VersionInfo>
						<VersionInfo Name="Build">7</VersionInfo>
						<VersionInfo Name="Debug">False</VersionInfo>
						<VersionInfo Name="PreRelease">False</VersionInfo>
						<VersionInfo Name="Special">False</VersionInfo>
						<VersionInfo Name="Private">True</VersionInfo>
						<VersionInfo Name="DLL">False</VersionInfo>
						<VersionInfo Name="Locale">1043</VersionInfo>
						<VersionInfo Name="CodePage">1252</VersionInfo>
					</VersionInfo>
					<VersionInfoKeys>
						<VersionInfoKeys Name="CompanyName">Martijn Coppoolse</VersionInfoKeys>
						<VersionInfoKeys Name="FileDescription">Olam Work registration helper</VersionInfoKeys>
						<VersionInfoKeys Name="FileVersion">1.0.0.7</VersionInfoKeys>
						<VersionInfoKeys Name="InternalName">Olam</VersionInfoKeys>
						<VersionInfoKeys Name="LegalCopyright"/>
						<VersionInfoKeys Name="LegalTrademarks"/>
						<VersionInfoKeys Name="OriginalFilename"/>
						<VersionInfoKeys Name="ProductName"/>
						<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
						<VersionInfoKeys Name="Comments"/>

Changes to src/prj/D2010/Olam.res.

cannot compute difference between binary files