The files contained in this repository can be downloaded to your computer using a svn client.
On Linux you simply type the command displayed below.

This URL has Read-Only access.

Statistics
| Revision:

root / trunk / DomotiGa / FTVGuide.class @ 348

History | View | Annotate | Download (14.3 kB)

1
' Gambas class file
2
3
' Description:
4
' FTVGuide.class
5
' Form for showing TV guide.
6
7
' Development Status:
8
' Imported from Kris's own project, needs testing.
9
10
' DomotiGa - an open source home automation program.
11
' Copyright(C) 2008-2010 Ron Klinkien
12
13
' This module is written by and Copyright(C) 2009 Kris Wauters on February, 14th - 2010
14
' For more info or help, mailto: kris@digitalplayground.be
15
16
' Read file called COPYING for license details.
17
18
PUBLIC SUB Form_Open()
19
20
  IF Main.bTVGuideEnabled THEN
21
    TxtDate.text = Format(Now, "dd/mm/yyyy")
22
    'LoadPreview(Main.DateFromAppToSQL(TxtDate.text))
23
    ChkProgramName.Value = TRUE
24
  ELSE
25
    TxtDate.Enabled = FALSE
26
    BtnSearch.Enabled = FALSE
27
    BtnPreview.Enabled = FALSE
28
    ChkProgramDescription.Enabled = FALSE
29
    ChkProgramName.Enabled = FALSE
30
    TxtSearch.Enabled = FALSE
31
  END IF
32
33
END
34
35
PUBLIC SUB Form_Resize()
36
37
  frmPreview.Move(4, 30, ME.ClientWidth - 8, ME.ClientHeight - 30)
38
  ScrollPrograms.Move(127, 40, ME.ClientWidth - 142, ME.ClientHeight - 94)
39
  ScrollScale.Move(127, 2, ME.ClientWidth - 140, 35)
40
  ScrollChannels.Move(7, 40, 119, ME.ClientHeight - 110)
41
  LblInfo.Move(7, ME.ClientHeight - 50, ME.ClientWidth - 25, 15)
42
43
END
44
45
' this is where all the *magic* happens, make a preview of the TVguide-data that sits in the database
46
PRIVATE SUB LoadPreview(StrDate AS String)
47
48
  '--- declare variables ---
49
  DIM rResChannel, rResProgram AS Result
50
  DIM TmpBtnChannel, TmpBtnProgram AS Button
51
  DIM TmpLbl AS Label
52
  DIM SepLine AS Separator
53
  DIM IntChannelCount, IntWidth, IntLeft, IntI, IntStartHour, IntStartMinute, IntStopHour, IntStopMinute AS Integer
54
  DIM BoolOK AS Boolean
55
  DIM StrFileLogo AS String
56
57
  '--- first remove previous childs ---
58
  FOR IntI = ScrollChannels.Children.Count - 1 TO 0 STEP -1
59
    ScrollChannels.Children[IntI].Delete
60
  NEXT
61
  FOR IntI = ScrollPrograms.Children.Count - 1 TO 0 STEP -1
62
    ScrollPrograms.Children[IntI].Delete
63
  NEXT
64
  '--- set datelabel ---
65
  LblDate.text = Format(Date(CInt(Left(StrDate, 4)), CInt(Mid(StrDate, 5, 2)), CInt(Mid(StrDate, 7, 2))), "dddd") & gb.newline & Format(Date(CInt(Left(StrDate, 4)), CInt(Mid(StrDate, 5, 2)), CInt(Mid(StrDate, 7, 2))), "dd mmmm yyyy")
66
  'FrmPreview.Enabled = FALSE
67
  Application.Busy = TRUE
68
  '--- setup 2 dummy labels to "fullfill" the correct width ---
69
  TmpLbl = NEW Label(ScrollPrograms)
70
  TmpLbl.X = 0
71
  TmpLbl.Width = 24 * 480
72
  TmpLbl.text = ""
73
  TmpLbl.Transparent = TRUE
74
  TmpLbl = NEW Label(ScrollScale)
75
  TmpLbl.X = 0
76
  TmpLbl.Width = 24 * 480
77
  TmpLbl.text = ""
78
  TmpLbl.Transparent = TRUE
79
  '--- put Hour-scale on top of scrollbox ---
80
  FOR IntI = 0 TO 24
81
    '--- Hours ---
82
    IF IntI > 0 THEN
83
      TmpLbl = NEW Label(ScrollScale)
84
      TmpLbl.Width = 50
85
      TmpLbl.ForeColor = Color.DarkRed
86
      TmpLbl.Alignment = Align.Center
87
      IF IntI = 24 THEN
88
        TmpLbl.Text = "[" & Format(IntI, "00") & ":00]"
89
      ELSE
90
        TmpLbl.Text = "[" & Format(IntI, "00") & ":00]"
91
      END IF
92
      TmpLbl.Y = 1
93
      TmpLbl.X = (IntI * 480) - (TmpLbl.Width / 2)
94
      SepLine = NEW Separator(ScrollScale)
95
      SepLine.Y = 25
96
      SepLine.Height = 15
97
      SepLine.BackColor = Color.DarkRed
98
      SepLine.Width = 2
99
      SepLine.X = (IntI * 480)
100
      ScrollPrograms.ScrollX = SepLine.X - (ScrollScale.Width / 2)
101
    END IF
102
    '--- Half Hours ---
103
    IF IntI < 24 THEN
104
      TmpLbl = NEW Label(ScrollScale)
105
      TmpLbl.Width = 50
106
      TmpLbl.ForeColor = Color.DarkRed
107
      TmpLbl.Alignment = Align.Center
108
      TmpLbl.Text = "[" & Format(IntI, "00") & ":30]"
109
      TmpLbl.Y = 1
110
      TmpLbl.X = (IntI * 480) - (TmpLbl.Width / 2) + 240
111
      SepLine = NEW Separator(ScrollScale)
112
      SepLine.Y = 25
113
      SepLine.Height = 15
114
      SepLine.BackColor = Color.DarkRed
115
      SepLine.Width = 2
116
      SepLine.X = (IntI * 480) + 240
117
      ScrollPrograms.ScrollX = SepLine.X - (ScrollScale.Width / 2)
118
    END IF
119
  NEXT
120
  '--- next, loop trough all marked channels, and display the programinfo ---
121
  rResChannel = Main.hDB.Exec("SELECT * FROM tv_channels WHERE isUsed = 1 ORDER BY ChannelOrder")
122
  'rResChannel = Main.hDB.Exec("SELECT * FROM tv_channels ORDER BY ChannelOrder")
123
  IntChannelCount = 0
124
  IF rResChannel THEN
125
    IF rResChannel.Count > 0 THEN
126
      FOR EACH rResChannel
127
        IF IntChannelCount / 5 = Int(IntChannelCount / 5) THEN
128
          LblInfo.text = "Rendering channel " & CStr(IntChannelCount) & " from " & CStr(rResChannel.Count)
129
          LblInfo.Refresh
130
          WAIT
131
        ENDIF
132
        IntChannelCount = IntChannelCount + 1
133
        TmpBtnChannel = NEW Button(ScrollChannels)
134
        TmpBtnChannel.BackColor = Color.White
135
        TmpBtnChannel.Border = Border.None
136
        TmpBtnChannel.Mouse = Mouse.Pointing
137
        TmpBtnChannel.X = 0
138
        TmpBtnChannel.Y = (IntChannelCount - 1) * 42
139
        TmpBtnChannel.Width = 119
140
        TmpBtnChannel.Height = 43
141
        TmpBtnChannel.Action = "Channel|" & rResChannel!ChannelID
142
        IF Len(rResChannel!BLOBlogo.data) > 10 THEN
143
          StrFileLogo = Main.BlobFromDB("SELECT * FROM tv_channels WHERE RecID=" & rResChannel!RecID, "BLOBlogo", "EXTlogo")
144
          TmpBtnChannel.Picture = Picture.Load(StrFileLogo)
145
        ELSE
146
          TmpBtnChannel.Text = rResChannel!ChannelName
147
        ENDIF
148
        '--- next, read program info for the current channel ---
149
        BoolOK = FALSE
150
        rResProgram = Main.hDB.Exec("SELECT tv_programs.*,tv_categories.BackColor,tv_categories.ForeColor FROM tv_programs,tv_categories WHERE tv_programs.CategoryName = tv_categories.CategoryName AND (left(EndPoint,8) = '" & Left(StrDate, 8) & "' OR left(StartPoint,8) = '" & Left(StrDate, 8) & "') AND ChannelID = '" & rResChannel!ChannelID & "' ORDER BY StartPoint")
151
        IF rResProgram THEN
152
          IF rResProgram.Count > 0 THEN 
153
            BoolOK = TRUE
154
            FOR EACH rResProgram
155
              TmpBtnProgram = NEW Button(ScrollPrograms)
156
              IF Len(Trim(rResProgram!BackColor)) = 0 THEN
157
                TmpBtnProgram.BackColor = Color.White
158
              ELSE
159
                TmpBtnProgram.BackColor = Val(rResProgram!BackColor)
160
              END IF
161
              IF Len(Trim(rResProgram!ForeColor)) = 0 THEN
162
                TmpBtnProgram.ForeColor = Color.Black
163
              ELSE
164
                TmpBtnProgram.ForeColor = Val(rResProgram!ForeColor)
165
              END IF
166
              TmpBtnProgram.Border = Border.None
167
              TmpBtnProgram.Mouse = Mouse.Pointing
168
              TmpBtnProgram.Action = "Program|" & rResChannel!ChannelID & "|" & rResProgram!StartPoint
169
              TmpBtnProgram.Text = rResProgram!ProgramName & gb.newline & Mid(rResProgram!StartPoint, 9, 2) & ":" & Mid(rResProgram!StartPoint, 11, 2) & " - " & Mid(rResProgram!EndPoint, 9, 2) & ":" & Mid(rResProgram!EndPoint, 11, 2)
170
              TmpBtnProgram.ToolTip = TmpBtnProgram.Text
171
              TmpBtnProgram.Y = TmpBtnChannel.Y
172
              TmpBtnProgram.Height = TmpBtnChannel.Height
173
              IF Left(rResProgram!StartPoint, 8) <> StrDate THEN
174
                IntStartHour = 0
175
                IntStartMinute = 0
176
              ELSE
177
                IntStartHour = CInt(Mid(rResProgram!StartPoint, 9, 2))
178
                IntStartMinute = CInt(Mid(rResProgram!StartPoint, 11, 2))
179
              END IF
180
              IF Left(rResProgram!EndPoint, 8) <> StrDate THEN
181
                IntStopHour = 24
182
                IntStopMinute = 00
183
              ELSE
184
                IntStopHour = CInt(Mid(rResProgram!EndPoint, 9, 2))
185
                IntStopMinute = CInt(Mid(rResProgram!EndPoint, 11, 2))
186
              END IF
187
              IntLeft = (IntStartHour * 480) + (IntStartMinute * 8)
188
              IntWidth = ((IntStopHour * 480) + (IntStopMinute * 8)) - ((IntStartHour * 480) + (IntStartMinute * 8))
189
              TmpBtnProgram.X = IntLeft
190
              TmpBtnProgram.Width = IntWidth
191
            NEXT
192
          END IF
193
        END IF
194
        IF BoolOK = FALSE THEN
195
          '--- add dummy label, to get the exact same height in both scrollviews
196
          TmpLbl = NEW Label(ScrollPrograms)
197
          TmpLbl.Y = TmpBtnChannel.Y
198
          TmpLbl.X = 0
199
          TmpLbl.Width = 24 * 480
200
          TmpLbl.Height = TmpBtnChannel.Height
201
          TmpLbl.Text = ""
202
          TmpLbl.Transparent = TRUE
203
        END IF
204
      NEXT
205
    END IF
206
  END IF
207
  '--- re-enable frame, because otherwise positioning of scrollview is not possible ---
208
  Application.Busy = FALSE
209
  'FrmPreview.Enabled = TRUE
210
  '--- draw the "current time line" (do this only if the current date is today) ---
211
  IF Format(Now, "yyyymmdd") = StrDate THEN
212
    SepLine = NEW Separator(ScrollPrograms)
213
    SepLine.Y = 1
214
    SepLine.Height = ScrollPrograms.ScrollHeight - 2
215
    SepLine.BackColor = Color.Red
216
    SepLine.Width = 2
217
    SepLine.X = ((CInt(Format(Now, "hh")) * 480) + (CInt(Format(Now, "nn")) * 8))
218
    ScrollPrograms.ScrollX = SepLine.X - (ScrollPrograms.Width / 2)
219
    'LblInfo.text = ("Guide contains ") & CStr(rResChannel.Count) & (" channels.")
220
    LblInfo.Text = ""
221
  END IF
222
223
END
224
225
PUBLIC SUB BtnPreview_Click()
226
227
  LoadPreview(Main.DateFromAppToSQL(TxtDate.text))
228
229
END
230
231
PUBLIC SUB ScrollPrograms_Scroll()
232
233
  ScrollChannels.ScrollY = ScrollPrograms.ScrollY
234
  ScrollScale.ScrollX = ScrollPrograms.ScrollX
235
236
END
237
238
'--- handles the clicking action of the dynamically generated channel- & program-labels ---
239
PUBLIC SUB Action_Activate(key AS String) AS Boolean
240
241
  '--- declare variables ---
242
  DIM rRes AS Result
243
  DIM FrmTmpProgram AS NEW FTVGuideProgramDetail
244
  DIM FrmTmpChannel AS NEW FTVGuideChannelDetail
245
  DIM StrFile, StrTmpDate AS String
246
247
  SELECT CASE UCase(Main.ParseTag(key, 1, "|"))
248
    CASE "CHANNEL"
249
      FrmTmpChannel.tag = Main.ParseTag(Key, 2, "|") & "|" & Main.DateFromAppToSQL(TxtDate.Text)
250
      FrmTmpChannel.ShowDialog
251
    CASE "PROGRAM"
252
      rRes = Main.hDB.Exec("SELECT tv_programs.*,tv_channels.ChannelName,tv_channels.RecID as TVChannelRecID,tv_channels.BLOBlogo FROM tv_programs,tv_channels WHERE tv_programs.ChannelID = tv_channels.ChannelID AND tv_programs.ChannelID = '" & Main.ParseTag(key, 2, "|") & "' AND tv_programs.StartPoint = '" & Main.ParseTag(key, 3, "|") & "'")
253
      IF rRes THEN
254
        IF rRes.count > 0 THEN
255
          rRes.MoveFirst
256
          FrmTmpProgram.LblChannel.text = rRes!ChannelName
257
          FrmTmpProgram.LblDate.text = Main.DateFromSQLToApp(Left(rRes!StartPoint, 8))
258
          FrmTmpProgram.LblTime.Text = "[" & Main.TimeFromSQLToApp(Right(rRes!StartPoint, 4)) & " - " & Main.TimeFromSQLToApp(Right(rRes!EndPoint, 4)) & "]" 
259
          FrmTmpProgram.LblCategory.text = rRes!CategoryName
260
          FrmTmpProgram.LblSubCategory.text = rRes!SubCategoryName
261
          FrmTmpProgram.LblProgramName.text = rRes!ProgramName
262
          FrmTmpProgram.TxtProgramDescription.text = rRes!ProgramDescription
263
          StrTmpDate = Left(rRes!StartPoint, 8)
264
          FrmTmpProgram.LblDateDay.text = Format(Date(CInt(Left(StrTmpDate, 4)), CInt(Mid(StrTmpDate, 5, 2)), CInt(Mid(StrTmpDate, 7, 2))), "dddd")
265
          IF Len(rRes!BLOBlogo.data) > 10 THEN
266
            StrFile = Main.BlobFromDB("SELECT * FROM tv_channels WHERE RecID=" & rRes!TVChannelRecID, "BLOBlogo", "EXTlogo")
267
            FrmTmpProgram.PicLogo.Picture = Picture.Load(StrFile)
268
          END IF
269
          FrmTmpProgram.ShowDialog
270
        END IF
271
      END IF
272
      rRes = NULL
273
  END SELECT
274
275
END
276
277
PUBLIC SUB DtChooser_Change()
278
279
  '--- declare variables ---
280
  DIM rRes AS Result
281
  DIM StrDate AS String
282
283
  '--- take care that the selected date is within the min/max-range of the items in the tv_programs table ---
284
  StrDate = Format(DtChooser.Year, "0000") & Format(DtChooser.Month, "00") & Format(DtChooser.Day, "00")
285
  rRes = Main.hDB.Exec("SELECT MIN(StartPoint) AS MinDate, MAX(EndPoint) AS MaxDate FROM tv_programs")
286
  IF rRes THEN
287
    IF rRes.count > 0 THEN
288
      rRes.MoveFirst
289
      IF StrDate < Left(rRes!MinDate, 8) THEN
290
        DtChooser.value = Date(CInt(Left(rRes!MinDate, 4)), CInt(Mid(rRes!MinDate, 5, 2)), CInt(Mid(rRes!MinDate, 7, 2)))
291
      END IF
292
      IF StrDate > Left(rRes!MaxDate, 8) THEN
293
        DtChooser.value = Date(CInt(Left(rRes!MaxDate, 4)), CInt(Mid(rRes!MaxDate, 5, 2)), CInt(Mid(rRes!MaxDate, 7, 2)))
294
      END IF
295
    END IF
296
  END IF
297
  rRes = NULL
298
  TxtDate.text = Format(DtChooser.Day, "00") & "/" & Format(DtChooser.Month, "00") & "/" & Format(DtChooser.Year, "0000")
299
300
END
301
302
PUBLIC SUB DtChooser_Leave()
303
304
  DtChooser.Visible = FALSE
305
306
END
307
308
PUBLIC SUB TxtDate_Enter()
309
310
  IF Main.bTVGuideEnabled THEN
311
    IF TxtDate.Text = "00/00/0000" THEN
312
      DtChooser.Value = Now
313
    ELSE
314
      DtChooser.Value = Date(CInt(Mid(TxtDate.Text, 7, 4)), CInt(Mid(TxtDate.text, 4, 2)), CInt(Left(TxtDate.text, 2)))
315
    END IF
316
    DtChooser.Visible = TRUE
317
  END IF
318
319
END
320
321
PUBLIC SUB BtnSearch_Click()
322
323
  '--- declare variables ---
324
  DIM StrQuery AS String
325
  DIM FrmTmp AS NEW FTVGuideSearchDetail
326
327
  '--- at least one checkbox needs to be marked ! ---
328
  IF ChkProgramDescription.value = FALSE AND ChkProgramName.value = FALSE THEN
329
    Message.Info(("At least one checkbox need to be marked for a search !"))
330
    RETURN
331
  END IF
332
  '--- also, search with empty search-string is not allowed ---
333
  IF Len(Trim(TxtSearch.text)) < 1 THEN
334
    Message.Info(("No search-criteria found !"))
335
    RETURN
336
  ENDIF
337
  '--- if we are here, we can perform a search, so build a query ---
338
  StrQuery = "SELECT tv_channels.RecID,tv_channels.ChannelOrder, tv_channels.ChannelName,tv_channels.ChannelID,tv_channels.BLOBlogo,tv_channels.EXTlogo,tv_programs.* FROM tv_channels,tv_programs where tv_channels.ChannelID = tv_programs.ChannelID AND tv_channels.IsUsed=1"
339
  IF ChkProgramName.value = TRUE AND ChkProgramDescription.value = FALSE THEN
340
    StrQuery = StrQuery & " AND tv_programs.ProgramName like '%" & TxtSearch.Text & "%'"
341
  END IF
342
  IF ChkProgramName.value = FALSE AND ChkProgramDescription.value = TRUE THEN
343
    StrQuery = StrQuery & " AND tv_programs.ProgramDescription like '%" & TxtSearch.Text & "%'"
344
  END IF
345
  IF ChkProgramName.value = TRUE AND ChkProgramDescription.value = TRUE THEN
346
    StrQuery = StrQuery & " AND (tv_programs.ProgramName like '%" & TxtSearch.Text & "%' OR tv_programs.ProgramDescription like '%" & TxtSearch.text & "%')"
347
  END IF
348
  StrQuery = StrQuery & " AND left(StartPoint,8) >= '" & Format(Now, "yyyymmdd") & "' ORDER BY StartPoint,tv_channels.ChannelOrder"
349
  FrmTmp.Tag = StrQuery & "|" & Format(Now, "yyyymmdd") & "|" & TxtSearch.Text
350
  IF ChkProgramName.value = TRUE THEN
351
    FrmTmp.Tag = FrmTmp.tag & "|1"
352
  ELSE
353
    FrmTmp.Tag = FrmTmp.tag & "|0"
354
  END IF
355
  IF ChkProgramDescription.value = TRUE THEN
356
    FrmTmp.Tag = FrmTmp.tag & "|1"
357
  ELSE
358
    FrmTmp.Tag = FrmTmp.tag & "|0"
359
  END IF
360
  FrmTmp.ShowDialog
361
362
END