-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTvMovieSetup++.vb
984 lines (832 loc) · 42.5 KB
/
TvMovieSetup++.vb
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
78
79
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
#Region "Copyright (C) 2005-2011 Team MediaPortal"
' Copyright (C) 2005-2011 Team MediaPortal
' http://www.team-mediaportal.com
'
' MediaPortal is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 2 of the License, or
' (at your option) any later version.
'
' MediaPortal is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with MediaPortal. If not, see <http://www.gnu.org/licenses/>.
#End Region
Imports System
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Drawing
Imports System.IO
Imports System.Threading
Imports System.Windows.Forms
Imports TvDatabase
Imports TvEngine
Imports TvLibrary.Log
Imports SetupTv
Imports TvMovie.TvEngine.TvMovie
Imports TvMovie.TvEngine
Imports Gentle.Framework
Namespace SetupTv.Sections
Partial Public Class TvMovieSetup
Inherits SectionSettings
#Region "ChannelInfo class"
Private Class ChannelInfo
Private _start As String = "00:00"
Private _end As String = "00:00"
Private _name As String = String.Empty
Public Property Start() As String
Get
Return _start
End Get
Set(ByVal value As String)
_start = value
End Set
End Property
Public Property [End]() As String
Get
Return _end
End Get
Set(ByVal value As String)
_end = value
End Set
End Property
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Sub New()
_start = "00:00"
_end = "00:00"
End Sub
End Class
#End Region
#Region "Form Methods"
Private Sub treeViewStations_DoubleClick(ByVal sender As Object, ByVal e As EventArgs) Handles treeViewTvMStations.DoubleClick
If treeViewTvMStations.SelectedNode IsNot Nothing Then
treeViewTvMStations.SelectedNode.Collapse()
End If
MapStation()
End Sub
Private Sub treeViewChannels_DoubleClick(ByVal sender As Object, ByVal e As EventArgs) Handles treeViewMpChannels.DoubleClick
UnmapStation()
End Sub
Private Sub linkLabelInfo_LinkClicked(ByVal sender As Object, ByVal e As LinkLabelLinkClickedEventArgs) Handles linkLabelInfo.LinkClicked
Process.Start("http://www.tvmovie.de/ClickFinder.57.0.html")
End Sub
Private Sub LinkClickfinderPG_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkClickfinderPG.LinkClicked
Process.Start("http://www.team-mediaportal.com/extensions/television/clickfinder-programguide?lang=en")
End Sub
Private Sub Linklabel_EpSc_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles Linklabel_EpSc.LinkClicked
Process.Start("http://forum.team-mediaportal.com/electronic-program-guide-67/new-tool-episodescanner-adds-series-episodenumbers-your-mediaportal-4tr-epg-76220/")
End Sub
#End Region
#Region "Constructor"
Public Sub New()
Me.New("TV Movie Clickfinder EPG import")
End Sub
Public Sub New(ByVal name As String)
MyBase.New(name)
InitializeComponent()
End Sub
#End Region
#Region "Serialisation"
Public Overrides Sub OnSectionDeActivated()
If tabControlTvMovie.SelectedIndex = 2 Then
SaveMapping()
End If
SaveDbSettings()
MyBase.OnSectionDeActivated()
End Sub
Private Sub SaveDbSettings()
Dim layer As New TvBusinessLayer()
DatabasePath = tbDbPath.Text
Dim setting As Setting = layer.GetSetting("TvMovieEnabled", "false")
If checkBoxEnableImport.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieShortProgramDesc", "false")
If checkBoxUseShortDesc.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieExtendDescription", "true")
If checkBoxAdditionalInfo.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieShowAudioFormat", "false")
If checkBoxShowAudioFormat.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieSlowImport", "true")
If checkBoxSlowImport.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieShowRatings", "true")
If checkBoxShowRatings.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieLimitActors", "5")
If checkBoxLimitActors.Checked Then
setting.Value = numericUpDownActorCount.Value.ToString()
Else
setting.Value = "0"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieShowLive", "true")
If checkBoxShowLive.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieShowRepeating", "false")
If checkBoxShowRepeat.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieRestPeriod", "24")
setting.Value = GetRestPeriod()
setting.Persist()
'TV Movie++ Enhancement by Scrounger
setting = layer.GetSetting("TvMovieRunAppAfter", String.Empty)
setting.Value = tbRunAppAfter.Text
setting.Persist()
setting = layer.GetSetting("TvMovieRunAppHidden", "true")
If checkBoxRunHidden.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieIsEpisodenScanner", "false")
If CheckBoxEpSc.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieMPDatabase", "C:\ProgramData\Team MediaPortal\MediaPortal\database")
setting.Value = tbMPDatabasePath.Text
setting.Persist()
setting = layer.GetSetting("TvMovieMPThumbsPath", "")
setting.Value = tbMPThumbs.Text
setting.Persist()
setting = layer.GetSetting("TvMovieImportTvSeriesInfos", "false")
If CheckBoxTvSeries.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieUseTheTvDb", "false")
If CheckBoxTheTvDb.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieImportMovingPicturesInfos", "false")
If CheckBoxMovingPictures.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieImportMyFilmsInfos", "false")
If CheckBoxMyFilms.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieImportVideoDatabaseInfos", "false")
If CheckBoxVideoDB.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("ClickfinderDataAvailable", "false")
If CheckBoxClickfinderPG.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieStartImportAtTime", "false")
If MpCheckBoxStartImportAtTime.Checked Then
setting.Value = "true"
Else
setting.Value = "false"
End If
setting.Persist()
setting = layer.GetSetting("TvMovieStartImportTime", "06:00")
setting.Value = tbImportStartTime.Text
setting.Persist()
End Sub
Public Overrides Sub OnSectionActivated()
LoadDbSettings()
MyBase.OnSectionActivated()
End Sub
Private Sub LoadDbSettings()
Dim layer As New TvBusinessLayer()
Dim _plugin As New TvEngine.TvMovie
'Neue Version: benötigte Einstellungen hier
If Not layer.GetSetting("TvMovieVersion", String.Empty).Value = _plugin.Version Then
MsgBox("New TvMovie++ Version detected!" & vbNewLine & vbNewLine & "All database tables must be reset for this new Version. That means you will lost your Series Mapping configuration and have to reconfigure the mappings !" & vbNewLine & vbNewLine & "You have to start a manual import to save the changes !!!", MsgBoxStyle.Information, "New Version")
Helper.DropSeriesMappingTable()
Helper.CreateOrClearTvMovieProgramTables()
'VersionsNr. speichern.
Dim Setting As Setting = layer.GetSetting("TvMovieVersion", String.Empty)
Setting.Value = _plugin.Version
Setting.Persist()
End If
checkBoxEnableImport.Checked = layer.GetSetting("TvMovieEnabled", "false").Value = "true"
checkBoxUseShortDesc.Checked = layer.GetSetting("TvMovieShortProgramDesc", "false").Value = "true"
checkBoxAdditionalInfo.Checked = layer.GetSetting("TvMovieExtendDescription", "true").Value = "true"
checkBoxShowRatings.Checked = layer.GetSetting("TvMovieShowRatings", "true").Value = "true"
checkBoxShowAudioFormat.Checked = layer.GetSetting("TvMovieShowAudioFormat", "false").Value = "true"
checkBoxSlowImport.Checked = layer.GetSetting("TvMovieSlowImport", "true").Value = "true"
Dim tvMovieLimitActors As Decimal = Convert.ToDecimal(layer.GetSetting("TvMovieLimitActors", "5").Value)
If tvMovieLimitActors < numericUpDownActorCount.Minimum OrElse tvMovieLimitActors > numericUpDownActorCount.Maximum Then
checkBoxLimitActors.Checked = False
numericUpDownActorCount.Value = numericUpDownActorCount.Minimum
Else
checkBoxLimitActors.Checked = True
numericUpDownActorCount.Value = tvMovieLimitActors
End If
checkBoxShowLive.Checked = layer.GetSetting("TvMovieShowLive", "true").Value = "true"
checkBoxShowRepeat.Checked = layer.GetSetting("TvMovieShowRepeating", "false").Value = "true"
SetRestPeriod(layer.GetSetting("TvMovieRestPeriod", "24").Value)
'TV Movie++ Enhancement by Scrounger
tbRunAppAfter.Text = layer.GetSetting("TvMovieRunAppAfter", String.Empty).Value
tbMPDatabasePath.Text = layer.GetSetting("TvMovieMPDatabase", "C:\ProgramData\Team MediaPortal\MediaPortal\database").Value
tbMPThumbs.Text = layer.GetSetting("TvMovieMPThumbsPath", "").Value
checkBoxRunHidden.Checked = layer.GetSetting("TvMovieRunAppHidden", "true").Value = "true"
CheckBoxEpSc.Checked = layer.GetSetting("TvMovieIsEpisodenScanner", "false").Value = "true"
CheckBoxTvSeries.Checked = layer.GetSetting("TvMovieImportTvSeriesInfos", "false").Value = "true"
CheckBoxTheTvDb.Checked = layer.GetSetting("TvMovieUseTheTvDb", "false").Value = "true"
CheckBoxMovingPictures.Checked = layer.GetSetting("TvMovieImportMovingPicturesInfos", "false").Value = "true"
CheckBoxMyFilms.Checked = layer.GetSetting("TvMovieImportMyFilmsInfos", "false").Value = "true"
CheckBoxVideoDB.Checked = layer.GetSetting("TvMovieImportVideoDatabaseInfos", "false").Value = "true"
CheckBoxClickfinderPG.Checked = layer.GetSetting("ClickfinderDataAvailable", "false").Value = "true"
MpCheckBoxStartImportAtTime.Checked = CBool(layer.GetSetting("TvMovieStartImportAtTime", "false").Value)
tbImportStartTime.Text = layer.GetSetting("TvMovieStartImportTime", "06:00").Value
If CheckBoxTvSeries.Checked = True Then
ButtonSeriesMapping.Enabled = True
Else
ButtonSeriesMapping.Enabled = False
End If
If CheckBoxTheTvDb.Checked And CheckBoxClickfinderPG.Checked Then
tbMPThumbs.Enabled = True
Else
tbMPThumbs.Enabled = False
End If
If MpCheckBoxStartImportAtTime.Checked Then
tbImportStartTime.Enabled = True
Else
tbImportStartTime.Enabled = False
End If
End Sub
#End Region
#Region "Mapping methods"
''' <summary>
''' Load stations from databases and fill controls with that data
''' </summary>
Private Sub LoadStations(ByVal localInstall As Boolean)
Dim database As New TvEngine.TvMovieDatabase()
If database.Connect() Then
Try
treeViewTvMStations.BeginUpdate()
Try
treeViewTvMStations.Nodes.Clear()
imageListTvmStations.Images.Clear()
treeViewTvMStations.ItemHeight = If(localInstall, 24, 16)
Dim GifBasePath As String = TVMovieProgramPath & "Gifs\"
For i As Integer = 0 To database.Stations.Count - 1
Try
Dim station As TvEngine.TVMChannel = database.Stations(i)
If localInstall Then
Dim channelLogo As String = GifBasePath & station.TvmZeichen
If Not File.Exists(channelLogo) Then
channelLogo = GifBasePath & "tvmovie_senderlogoplatzhalter.gif"
End If
' convert gif to ico
Dim tvmLogo As New Bitmap(channelLogo)
Dim iconHandle As IntPtr = tvmLogo.GetHicon()
Dim stationThumb As Icon = Icon.FromHandle(iconHandle)
imageListTvmStations.Images.Add(New Icon(stationThumb, New Size(32, 22)))
End If
Dim stationNode As New TreeNode(station.TvmEpgDescription, i, i)
', subItems);
Dim channelInfo As New ChannelInfo()
channelInfo.Name = station.TvmEpgChannel
stationNode.Tag = channelInfo
treeViewTvMStations.Nodes.Add(stationNode)
Catch exstat As Exception
MyLog.Info("TvMovieSetup: Error loading TV Movie station - {0}", exstat.Message)
End Try
Next
Finally
treeViewTvMStations.EndUpdate()
End Try
treeViewMpChannels.BeginUpdate()
Try
treeViewMpChannels.Nodes.Clear()
Dim mpChannelList As List(Of Channel) = database.GetChannels()
For Each channel As Channel In mpChannelList
'TreeNode[] subItems = new TreeNode[] { new TreeNode(channel.IdChannel.ToString()), new TreeNode(channel.DisplayName) };
Dim stationNode As New TreeNode(channel.DisplayName)
stationNode.Tag = channel
treeViewMpChannels.Nodes.Add(stationNode)
Next
Catch exdb As Exception
MyLog.Info("TvMovieSetup: Error loading MP's channels from database - {0}", exdb.Message)
Finally
treeViewMpChannels.EndUpdate()
End Try
Catch ex As Exception
MyLog.Info("TvMovieSetup: Unhandled error in LoadStations - {0}" & vbLf & "{1}", ex.Message, ex.StackTrace)
End Try
End If
End Sub
''' <summary>
''' Map selected TVMovie station to a selected MP channel
''' </summary>
Private Sub MapStation()
Dim selectedChannel As TreeNode = treeViewMpChannels.SelectedNode
If selectedChannel Is Nothing Then
Return
End If
While selectedChannel.Parent IsNot Nothing
selectedChannel = selectedChannel.Parent
End While
Dim selectedStation As TreeNode = DirectCast(treeViewTvMStations.SelectedNode.Clone(), TreeNode)
For Each stationNode As TreeNode In selectedChannel.Nodes
If stationNode.Text = selectedStation.Text Then
Return
End If
Next
If selectedChannel.Nodes.Count > 0 Then
selectedChannel.Nodes(0).ForeColor = Color.Green
selectedStation.ForeColor = Color.Green
Else
selectedStation.ForeColor = Color.Blue
End If
selectedChannel.Nodes.Add(selectedStation)
selectedChannel.Expand()
End Sub
''' <summary>
''' Remove TVMovie station mapping from selected MP channel
''' </summary>
Private Sub UnmapStation()
Dim selectedChannel As TreeNode = treeViewMpChannels.SelectedNode
If selectedChannel Is Nothing Then
Return
End If
If selectedChannel.Parent IsNot Nothing Then
If selectedChannel.Parent.Nodes.Count = 2 Then
selectedChannel.Parent.Nodes(0).ForeColor = Color.Blue
selectedChannel.Parent.Nodes(1).ForeColor = Color.Blue
End If
selectedChannel.Remove()
Else
selectedChannel.Nodes.Clear()
End If
End Sub
''' <summary>
''' Save station-channel mapping to database
''' </summary>
Private Sub SaveMapping()
Dim mappingList As IList(Of TvMovieMapping) = TvMovieMapping.ListAll()
If mappingList IsNot Nothing AndAlso mappingList.Count > 0 Then
For Each mapping As TvMovieMapping In mappingList
mapping.Remove()
Next
Else
MyLog.Info("TvMovieSetup: SaveMapping - no mappingList items")
End If
Dim layer As New TvBusinessLayer()
For Each channel As TreeNode In treeViewMpChannels.Nodes
'Mylog.Debug("TvMovieSetup: Processing channel {0}", channel.Text);
For Each station As TreeNode In channel.Nodes
Dim channelInfo As ChannelInfo = DirectCast(station.Tag, ChannelInfo)
'Mylog.Debug("TvMovieSetup: Processing channelInfo {0}", channelInfo.Name);
Dim mapping As TvMovieMapping = Nothing
Try
mapping = New TvMovieMapping(DirectCast(channel.Tag, Channel).IdChannel, channelInfo.Name, channelInfo.Start, channelInfo.[End])
Catch exm As Exception
MyLog.[Error]("TvMovieSetup: Error on new TvMovieMapping for channel {0} - {1}", channel.Text, exm.Message)
End Try
'Mylog.Write("TvMovieSetup: SaveMapping - new mapping for {0}/{1}", channel.Text, channelInfo.Name);
Try
MyLog.Debug("TvMovieSetup: Persisting TvMovieMapping for channel {0}", channel.Text)
mapping.Persist()
Catch ex As Exception
MyLog.[Error]("TvMovieSetup: Error on mapping.Persist() {0},{1}", ex.Message, ex.StackTrace)
End Try
Next
Next
End Sub
''' <summary>
''' Load station-channel mapping from database
''' </summary>
Private Sub LoadMapping()
treeViewMpChannels.BeginUpdate()
Try
For Each treeNode As TreeNode In treeViewMpChannels.Nodes
For Each childNode As TreeNode In treeNode.Nodes
childNode.Remove()
Next
Next
Try
Dim mappingDb As IList(Of TvMovieMapping) = TvMovieMapping.ListAll()
If mappingDb IsNot Nothing AndAlso mappingDb.Count > 0 Then
For Each mapping As TvMovieMapping In mappingDb
Dim MpChannelName As String = String.Empty
Try
Dim channelNode As TreeNode = FindChannel(mapping.IdChannel)
If channelNode IsNot Nothing Then
Dim stationName As String = mapping.StationName
If FindStation(stationName) IsNot Nothing Then
Dim stationNode As TreeNode = DirectCast(FindStation(stationName).Clone(), TreeNode)
Dim channelInfo As New ChannelInfo()
If stationNode IsNot Nothing Then
Dim start As String = mapping.TimeSharingStart
Dim [end] As String = mapping.TimeSharingEnd
If start <> "00:00" OrElse [end] <> "00:00" Then
stationNode.Text = String.Format("{0} ({1}-{2})", stationName, start, [end])
Else
stationNode.Text = String.Format("{0}", stationName)
End If
channelInfo.Start = start
channelInfo.[End] = [end]
channelInfo.Name = stationName
stationNode.Tag = channelInfo
channelNode.Nodes.Add(stationNode)
channelNode.Expand()
End If
Else
MyLog.Debug("TVMovie plugin: Channel {0} no longer present in Database - ignoring", stationName)
End If
End If
Catch exInner As Exception
MyLog.Debug("TVMovie plugin: Mapping of station {0} failed; maybe it has been deleted / changed ({1})", MpChannelName, exInner.Message)
End Try
Next
Else
MyLog.Debug("TVMovie plugin: LoadMapping did not find any mapped channels")
End If
Catch ex As Exception
MyLog.Debug("TVMovie plugin: LoadMapping failed - {0},{1}", ex.Message, ex.StackTrace)
End Try
ColorTree()
Finally
treeViewMpChannels.EndUpdate()
End Try
End Sub
Private Function FindChannel(ByVal mpChannelId As Integer) As TreeNode
For Each MpNode As TreeNode In treeViewMpChannels.Nodes
If MpNode.Tag IsNot Nothing Then
Dim checkChannel As Channel = TryCast(MpNode.Tag, Channel)
If checkChannel IsNot Nothing Then
If checkChannel.IdChannel = mpChannelId Then
Return MpNode
End If
Else
MyLog.Debug("TVMovie plugin: FindChannel failed - no Channel in Node tag of {0}", MpNode.Text)
End If
End If
Next
Return Nothing
End Function
Private Function FindStation(ByVal aTvMStationName As String) As TreeNode
For Each TvMNode As TreeNode In treeViewTvMStations.Nodes
If TvMNode.Tag IsNot Nothing Then
If DirectCast(TvMNode.Tag, ChannelInfo).Name = aTvMStationName Then
Return TvMNode
End If
End If
Next
Return Nothing
End Function
Private Sub ColorTree()
For Each parentNode As TreeNode In treeViewMpChannels.Nodes
For Each subNode As TreeNode In parentNode.Nodes
If parentNode.Nodes.Count > 1 Then
subNode.ForeColor = Color.Green
Else
subNode.ForeColor = Color.Blue
End If
Next
Next
End Sub
Private Sub ColorNode(ByVal channelNode As TreeNode, ByVal color As Color)
For Each stationNode As TreeNode In channelNode.Nodes
stationNode.ForeColor = color
Next
End Sub
Private Sub treeViewChannels_AfterSelect(ByVal sender As Object, ByVal e As TreeViewEventArgs) Handles treeViewMpChannels.AfterSelect
If e.Node.Parent Is Nothing OrElse e.Node.Tag Is Nothing Then
panelTimeSpan.Visible = False
Return
End If
panelTimeSpan.Visible = True
Dim channelInfo As ChannelInfo = DirectCast(e.Node.Tag, ChannelInfo)
maskedTextBoxTimeStart.Text = channelInfo.Start
maskedTextBoxTimeEnd.Text = channelInfo.[End]
End Sub
Private Function CleanInput(ByVal input As String) As String
Dim hours As Integer = 0
Dim minutes As Integer = 0
input = input.Trim()
Dim index As Integer = input.IndexOf(":"c)
If index > 0 Then
hours = Convert.ToInt16(input.Substring(0, index))
End If
If index + 1 < input.Length Then
minutes = Convert.ToInt16(input.Substring(index + 1))
End If
If hours > 23 Then
hours = 0
End If
If minutes > 59 Then
minutes = 0
End If
Return String.Format("{0:00}:{1:00}", hours, minutes)
End Function
Private Sub maskedTextBoxTimeStart_Validated(ByVal sender As Object, ByVal e As EventArgs) Handles maskedTextBoxTimeStart.Validated
Dim channelInfo As ChannelInfo = DirectCast(treeViewMpChannels.SelectedNode.Tag, ChannelInfo)
channelInfo.Start = CleanInput(maskedTextBoxTimeStart.Text)
maskedTextBoxTimeStart.Text = CleanInput(maskedTextBoxTimeStart.Text)
treeViewMpChannels.SelectedNode.Tag = channelInfo
If channelInfo.Start <> "00:00" OrElse channelInfo.[End] <> "00:00" Then
treeViewMpChannels.SelectedNode.Text = String.Format("{0} ({1}-{2})", channelInfo.Name, channelInfo.Start, channelInfo.[End])
Else
treeViewMpChannels.SelectedNode.Text = String.Format("{0}", channelInfo.Name)
End If
End Sub
Private Sub maskedTextBoxTimeEnd_Validated(ByVal sender As Object, ByVal e As EventArgs) Handles maskedTextBoxTimeEnd.Validated
Dim channelInfo As ChannelInfo = DirectCast(treeViewMpChannels.SelectedNode.Tag, ChannelInfo)
channelInfo.[End] = CleanInput(maskedTextBoxTimeEnd.Text)
maskedTextBoxTimeEnd.Text = CleanInput(maskedTextBoxTimeEnd.Text)
treeViewMpChannels.SelectedNode.Tag = channelInfo
If channelInfo.Start <> "00:00" OrElse channelInfo.[End] <> "00:00" Then
treeViewMpChannels.SelectedNode.Text = String.Format("{0} ({1}-{2})", channelInfo.Name, channelInfo.Start, channelInfo.[End])
Else
treeViewMpChannels.SelectedNode.Text = String.Format("{0}", channelInfo.Name)
End If
End Sub
#End Region
#Region "Form settings"
Private Sub checkBoxUseShortDesc_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
If checkBoxUseShortDesc.Checked Then
checkBoxAdditionalInfo.Checked = False
checkBoxAdditionalInfo.Enabled = False
End If
checkBoxAdditionalInfo.Enabled = True
End Sub
Private Sub checkBoxAdditionalInfo_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
If checkBoxAdditionalInfo.Checked Then
checkBoxUseShortDesc.Checked = False
End If
End Sub
Private Function GetRestPeriod() As String
If radioButton6h.Checked Then
Return "6"
ElseIf radioButton12h.Checked Then
Return "12"
ElseIf radioButton24h.Checked Then
Return "24"
ElseIf radioButton2d.Checked Then
Return "48"
ElseIf radioButton7d.Checked Then
Return "168"
End If
Return "24"
End Function
Private Sub SetRestPeriod(ByVal RadioButtonSetting As String)
Select Case RadioButtonSetting
Case "6"
radioButton6h.Checked = True
Exit Select
Case "12"
radioButton12h.Checked = True
Exit Select
Case "24"
radioButton24h.Checked = True
Exit Select
Case "48"
radioButton2d.Checked = True
Exit Select
Case "168"
radioButton7d.Checked = True
Exit Select
Case Else
radioButton24h.Checked = True
Exit Select
End Select
End Sub
Private Sub tabControlTvMovie_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles tabControlTvMovie.SelectedIndexChanged
If Not checkBoxEnableImport.Checked Then
tabControlTvMovie.SelectedIndex = 0
ElseIf tabControlTvMovie.SelectedIndex = 0 Then
SaveMapping()
End If
End Sub
Private Sub checkBoxEnableImport_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles checkBoxEnableImport.CheckedChanged
groupBoxDescriptions.Enabled = InlineAssignHelper(groupBoxImportTime.Enabled, InlineAssignHelper(groupBoxInstallMethod.Enabled, checkBoxEnableImport.Checked))
If checkBoxEnableImport.Checked Then
rbLocal.Enabled = InlineAssignHelper(rbLocal.Checked, Not String.IsNullOrEmpty(TVMovieProgramPath))
rbManual.Checked = Not rbLocal.Checked
tbDbPath.Text = DatabasePath
Try
LoadStations(rbLocal.Checked)
Catch ex1 As Exception
MessageBox.Show(Me, "Please make sure a supported TV Movie Clickfinder release has been successfully installed.", "Error loading TV Movie stations", MessageBoxButtons.OK, MessageBoxIcon.[Error])
checkBoxEnableImport.Checked = False
MyLog.Info("TVMovie plugin: Error enabling TV Movie import in LoadStations() - {0},{1}", ex1.Message, ex1.StackTrace)
Return
End Try
Try
LoadMapping()
Catch ex2 As Exception
MessageBox.Show(Me, "Please make sure your using a valid channel mapping.", "Error loading TVM <-> MP channel mapping", MessageBoxButtons.OK, MessageBoxIcon.[Error])
checkBoxEnableImport.Checked = False
MyLog.Info("TVMovie plugin: Error enabling TV Movie import in LoadMapping() - {0},{1}", ex2.Message, ex2.StackTrace)
Return
End Try
Else
SaveMapping()
End If
End Sub
#End Region
#Region "Manual import methods"
''' <summary>
''' Inmediately updates and imports EPG data
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub buttonImportNow_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttonImportNow.Click
buttonImportNow.Enabled = False
SaveDbSettings()
Try
Dim manualThread As New Thread(New ThreadStart(AddressOf ManualImportThread))
manualThread.Name = "TV Movie manual importer"
manualThread.Priority = ThreadPriority.Normal
manualThread.IsBackground = False
manualThread.Start()
Catch ex2 As Exception
MyLog.[Error]("TVMovie: Error spawing import thread - {0},{1}", ex2.Message, ex2.StackTrace)
buttonImportNow.Enabled = True
End Try
End Sub
Public Sub ManualImportThread()
Dim _database As New TvEngine.TvMovieDatabase()
Try
_database.LaunchTVMUpdater(False)
AddHandler _database.OnStationsChanged, New TvEngine.TvMovieDatabase.StationsChanged(AddressOf _database_OnStationsChanged)
If _database.Connect() Then
_database.Import()
End If
buttonImportNow.Enabled = True
Catch ex As Exception
MyLog.Info("TvMovie plugin error:")
MyLog.Write(ex)
buttonImportNow.Enabled = True
End Try
End Sub
Private Sub _database_OnStationsChanged(ByVal value As Integer, ByVal maximum As Integer, ByVal text As String)
progressBarImportTotal.Maximum = maximum
If value <= maximum AndAlso value >= 0 Then
progressBarImportTotal.Value = value
End If
End Sub
Private Sub rbLocal_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles rbLocal.CheckedChanged
tbDbPath.Enabled = Not rbLocal.Checked
End Sub
Private Sub buttonBrowse_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttonBrowse.Click
fileDialogDb.Filter = "Access database (*.mdb)|*.mdb|All files (*.*)|*.*"
fileDialogDb.InitialDirectory = tbDbPath.Text
If fileDialogDb.ShowDialog(Me) = DialogResult.OK Then
DatabasePath = InlineAssignHelper(tbDbPath.Text, fileDialogDb.FileName)
checkBoxEnableImport_CheckedChanged(sender, Nothing)
End If
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
#End Region
#Region "TVMovie++ enhancement"
Private Sub BTAppBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTAppBrowse.Click
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer)
openFileDialog1.Filter = "Application (*.exe)|*.exe|All files (*.*)|*.*"
If openFileDialog1.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
tbRunAppAfter.Text = openFileDialog1.FileName
End If
End Sub
Private Sub ButtonBrowseMPDatabases_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonBrowseMPDatabases.Click
' First create a FolderBrowserDialog object
Dim FolderBrowserDialog1 As New FolderBrowserDialog
' Then use the following code to create the Dialog window
' Change the .SelectedPath property to the default location
With FolderBrowserDialog1
' Desktop is the root folder in the diaMylog.
.RootFolder = Environment.SpecialFolder.Desktop
' Select the C:\Windows directory on entry.
.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer)
' Prompt the user with a custom message.
.Description = "Select the source directory"
If .ShowDialog = DialogResult.OK Then
' Display the selected folder if the user clicked on the OK button.
tbMPDatabasePath.Text = .SelectedPath
End If
End With
End Sub
Private Sub ButtonEPGgrab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEPGgrab.Click
SaveMapping()
Dim EPGgrab As New frmEPGgrab
EPGgrab.ShowDialog()
End Sub
#End Region
Private Sub CheckBoxTvSeries_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxTvSeries.CheckedChanged
If CheckBoxTvSeries.Checked Then
ButtonSeriesMapping.Enabled = True
Else
ButtonSeriesMapping.Enabled = False
End If
End Sub
Private Sub ButtonSeriesMapping_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSeriesMapping.Click
If File.Exists(tbMPDatabasePath.Text & "\" & "TVSeriesDatabase4.db3") Then
SaveMapping()
Dim _layer As New TvBusinessLayer
enrichEPG.MySettings.MpDatabasePath = _layer.GetSetting("TvMovieMPDatabase").Value
Dim SeriesManagement As New enrichEPG.seriesManagement
SeriesManagement.ShowDialog()
Else
MsgBox("TvSeries Datenbank nicht gefunden !", MsgBoxStyle.Critical, "Fehler")
End If
End Sub
Private Sub CheckBoxTheTvDb_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxTheTvDb.CheckedChanged
If CheckBoxTheTvDb.Checked And CheckBoxClickfinderPG.Checked Then
tbMPThumbs.Enabled = True
Else
tbMPThumbs.Enabled = False
End If
End Sub
Private Sub CheckBoxClickfinderPG_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxClickfinderPG.CheckedChanged
If CheckBoxClickfinderPG.Checked And CheckBoxTheTvDb.Checked Then
tbMPThumbs.Enabled = True
enrichEPG.MySettings.ClickfinderProgramGuideImportEnable = True
Else
tbMPThumbs.Enabled = False
enrichEPG.MySettings.ClickfinderProgramGuideImportEnable = False
End If
End Sub
Private Sub MpCheckBoxStartImportAtTime_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MpCheckBoxStartImportAtTime.CheckedChanged
If MpCheckBoxStartImportAtTime.Checked Then
tbImportStartTime.Enabled = True
Else
tbImportStartTime.Enabled = False
End If
End Sub
Private Sub BT_ResetEpisodeMapping_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT_ResetEpisodeMapping.Click
MsgBox("You have to start a manual import to save the changes !!!", MsgBoxStyle.Information, "ResetSeriesMapping")
Helper.DropEpisodeMappingTable()
Helper.CreateOrClearTvMovieProgramTables()
End Sub
Private Sub BT_ResetSeriesMapping_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT_ResetSeriesMapping.Click
MsgBox("You have to start a manual import to save the changes !!!", MsgBoxStyle.Information, "ResetSeriesMapping")
Helper.DropSeriesMappingTable()
Helper.CreateOrClearTvMovieProgramTables()
End Sub
End Class
End Namespace