root/lang/vb2005/Tween/Tween/StatusDictionary.vb @ 22965

Revision 22965, 19.4 kB (checked in by syo68k, 5 years ago)

全体的にリファクタリング(@takeshik)

Line 
1Imports System.Collections.Generic
2Imports System.Collections.ObjectModel
3Imports Tween.TweenCustomControl
4
5Public Class Statuses
6    Private _statuses As Dictionary(Of String, MyListItem)
7    Private _addedIds As Specialized.StringCollection
8    Private _tabs As TabInformations
9
10    Public Sub New()
11        _statuses = New Dictionary(Of String, MyListItem)
12    End Sub
13
14    Public Sub BeginUpdate()
15        _addedIds = New Specialized.StringCollection()  '�^�u�lj�pID�R���N�V��������   End Sub
16
17    Public Function EndUpdate() As String
18        Dim NotifyString As String = _tabs.Distribute(_addedIds)    '�^�u�ɒlj�
19        _tabs.Sort()    '�\�[�g
20        Return NotifyString     '�ʒm�p���b�Z�[�W���
21    End Function
22
23    Public Sub Add(ByRef Item As MyListItem)
24        _statuses.Add(Item.Id, Item)
25        _addedIds.Add(Item.Id)
26    End Sub
27
28    Public Function Remove(ByVal Key As String) As Integer
29        _statuses.Remove(Key)
30    End Function
31
32    Public WriteOnly Property TabsClass() As TabInformations
33        Set(ByVal value As TabInformations)
34            _tabs = value
35        End Set
36    End Property
37End Class
38
39
40
41'Public Class StatusDictionary
42'    Private _tabs As TabInformations  '�v�fTabsClass�N���X�̃W�F�l���b�N���X�g�C���X�^���X�i�^�u���p�j
43'    Private _statuses As New Dictionary(Of String, MyListItem)
44'    Private _setting As Setting
45
46'    Private _notifymsg As New NotifyMessage
47
48'    Public Structure NotifyMessage
49'        Public Count As Integer
50'        Public Message As String
51'        Public Reply As Boolean
52'        Public Direct As Boolean
53'        Public AllCount As Integer
54'        Public SoundFile As String
55'    End Structure
56
57'    Public Sub New(ByVal Section As ListSection, ByVal MySetting As Setting)
58'        _tabs = New TabInformations(_section.SortColumn, _section.SortOrder, MySetting)
59'        _setting = MySetting
60'    End Sub
61
62'    Public ReadOnly Property Tabs() As TabInformations
63'        Get
64'            Return _tabs
65'        End Get
66'    End Property
67
68'    Public ReadOnly Property Items(ByVal ID As String) As MyListItem
69'        Get
70'            Return _statuses(ID)
71'        End Get
72'    End Property
73
74'    Public Function Add(ByVal Item As MyListItem, ByVal Initial As Boolean, ByVal DirectMessage As Boolean) As Boolean
75'        If _statuses.ContainsKey(Item.Id) = True Then
76'            Return False
77'        End If
78
79'        DoFilter(Item, Initial, DirectMessage)
80
81'        _statuses.Add(Item.Id, Item)
82'        Return True
83'    End Function
84
85'    Public Function Remove(ByVal ID As String) As Boolean
86'        Dim rd As Boolean = False
87
88'        If _statuses.ContainsKey(ID) Then
89'            rd = _statuses(ID).Readed
90'            _statuses.Remove(ID)
91'        Else
92'            Return False
93'        End If
94
95'        For Each ts As TabsClass In _tabs.Tabs
96'            If ts.Contains(ID) Then
97'                ts.Remove(ID)
98'                ts.AllCount -= 1
99'                If ts.UnreadManage And rd = False Then
100'                    ts.UnreadCount -= 1
101'                    ts.OldestUnreadItem = ""
102'                    For Each tsid As String In ts.StatusIDs
103'                        If _statuses(tsid).Readed = False Then
104'                            ts.OldestUnreadItem = tsid
105'                            Exit For
106'                        End If
107'                    Next
108'                    If ts.UnreadCount = 0 Then ts.TabPage.ImageIndex = -1
109'                End If
110'            End If
111'        Next
112'    End Function
113
114'    Public Property Readed(ByVal ID As String) As Boolean
115'        Get
116'            If _statuses.ContainsKey(ID) Then
117'                Return _statuses(ID).Readed
118'            Else
119'                Return False
120'            End If
121'        End Get
122'        Set(ByVal value As Boolean)
123'            If _statuses.ContainsKey(ID) = False Then Return False
124
125'            For Each ts As TabsClass In _tabs.Tabs
126'                If ts.Contains(ID) Then
127'                    If ts.UnreadManage And _statuses(ID).Readed <> value Then
128'                        If value = True Then
129'                            ts.UnreadCount -= 1
130'                            If ts.OldestUnreadItem = ID Then
131'                                Dim idx As Integer = ts.StatusIDs.IndexOf(ID)
132
133'                            End If
134'                            ts.OldestUnreadItem = ""
135'                            For Each tsid As String In ts.StatusIDs
136'                                If _statuses(tsid).Readed = False Then
137'                                    ts.OldestUnreadItem = tsid
138'                                    Exit For
139'                                End If
140'                            Next
141'                            If ts.UnreadCount = 0 Then ts.TabPage.ImageIndex = -1
142'                        End If
143'                    End If
144'                End If
145'            Next
146'        End Set
147'    End Property
148
149'    Public Function Contains(ByVal ID As String) As Boolean
150'        Return _statuses.ContainsKey(ID)
151'    End Function
152
153'    Public Sub GetNotifyInfo(ByVal nf As NotifyMessage)
154'        nf.AllCount = _notifymsg.AllCount
155'        nf.Count = _notifymsg.Count
156'        nf.Message = _notifymsg.Message
157'        nf.Reply = _notifymsg.Reply
158'        nf.Direct = _notifymsg.Direct
159'        nf.SoundFile = _notifymsg.SoundFile
160'        _notifymsg.AllCount = 0
161'        _notifymsg.Count = 0
162'        _notifymsg.Message = ""
163'        _notifymsg.Reply = False
164'        _notifymsg.Direct = False
165'        _notifymsg.SoundFile = ""
166'    End Sub
167
168'    Private Sub DoFilter(ByVal Item As MyListItem, ByVal Initial As Boolean, ByVal Direct As Boolean)
169'        Dim reply As Boolean = False
170'        Dim nm As String
171'        Dim snd As String = ""
172
173'        If (Initial = False Or (Initial And _setting.Readed = False)) And _setting.UnreadManage Then
174'            Item.Readed = False
175'        End If
176
177'        Dim mv As Boolean = False
178'        Dim nf As Boolean = False
179'        Dim mk As Boolean = False
180'        If Direct = False Then
181'            For Each ts As TabsClass In _tabs.Tabs
182'                Dim hit As Boolean = False
183'                If tskey <> "Recent" And tskey <> "Reply" And tskey <> "Direct" Then
184'                    For Each ft As FilterClass In ts.Filters
185'                        Dim bHit As Boolean = True
186'                        Dim tBody As String = IIf(ft.SearchURL, Item.OrgData, Item.Data)
187'                        If ft.SearchBoth Then
188'                            If ft.IDFilter = "" Or Item.Name = ft.IDFilter Then
189'                                For Each fs As String In ft.BodyFilter
190'                                    If ft.UseRegex Then
191'                                        If Regex.IsMatch(tBody, fs, RegexOptions.IgnoreCase) = False Then bHit = False
192'                                    Else
193'                                        If tBody.ToLower.Contains(fs.ToLower) = False Then bHit = False
194'                                    End If
195'                                    If bHit = False Then Exit For
196'                                Next
197'                            Else
198'                                bHit = False
199'                            End If
200'                        Else
201'                            For Each fs As String In ft.BodyFilter
202'                                If ft.UseRegex Then
203'                                    If Regex.IsMatch(Item.Name + tBody, fs, RegexOptions.IgnoreCase) = False Then bHit = False
204'                                Else
205'                                    If (Item.Name + tBody).ToLower.Contains(fs.ToLower) = False Then bHit = False
206'                                End If
207'                                If bHit = False Then Exit For
208'                            Next
209'                        End If
210'                        If bHit = True Then
211'                            hit = True
212'                            If ft.SetMark Then mk = True
213'                            If ft.moveFrom Then mv = True
214'                        End If
215'                        If hit And mv And mk Then Exit For
216'                    Next
217'                ElseIf tskey = "Reply" Then
218'                    If Item.Reply Or Regex.IsMatch(Item.Data, "@" + _username + "([^a-zA-Z0-9_]|$)", RegexOptions.IgnoreCase) Then
219'                        hit = True
220'                        reply = True
221'                    End If
222'                End If
223
224'                If hit Then
225'                    ts.Add(Item.Id, Item.Readed)
226'                    If ts.Notify Then nf = True
227'                    If snd = "" Then snd = ts.SoundFile
228'                End If
229'            Next
230'            If mv = False Then
231'                Dim ts As TabsClass = _tabs.Tabs("Recent")
232'                If mk Then Item.Mark = True
233'                ts.Add(Item.Id, Item.Readed)
234'                If ts.Notify Then nf = True
235'                If snd = "" Then snd = ts.SoundFile
236'            End If
237'        Else
238'            Dim ts As TabsClass = _tabs.Tabs("Direct")
239'            ts.Add(Item.Id, Item.Readed)
240'            nf = ts.Notify
241'            snd = ts.SoundFile
242'        End If
243
244
245'        nm = ""
246'        Select Case _setting.NameBalloon
247'            Case NameBalloonEnum.None
248'                nm = ""
249'            Case NameBalloonEnum.UserID
250'                nm = lItem.Name
251'            Case NameBalloonEnum.NickName
252'                nm = lItem.Nick
253'        End Select
254'        Dim pmsg As String
255'        pmsg = nm + " : " + Item.Data
256'        If nf = True Then
257'            _notifymsg.Count += 1
258'            If _notifymsg.Message = "" Then
259'                _notifymsg.Message = pmsg
260'            Else
261'                _notifymsg.Message += vbCrLf + pmsg
262'            End If
263'            If reply Then _notifymsg.Reply = True
264'            If Direct Then _notifymsg.Direct = True
265'        End If
266'        _notifymsg.AllCount += 1
267'        _notifymsg.SoundFile = snd
268'    End Sub
269
270'End Class
271
272Public Class MyListItem
273    Public Nick As String
274    Public Data As String
275    Public ImageUrl As String
276    Public Name As String
277    Public PDate As DateTime
278    Public Id As String
279    Public Fav As Boolean
280    Public OrgData As String
281    Public Read As Boolean
282    Public Reply As Boolean
283    Public Protect As Boolean
284    Public OWL As Boolean
285    Public Mark As Boolean
286End Class
287
288Public Class TabInformations
289    '�•ʃ^�u�̏���tionary�ŕێ�
290    Private _sorter As ListViewItemComparerClass
291    Private _tabs As New Dictionary(Of String, TabClass)()
292    Private _statuses As Statuses
293
294    Public Sub New()
295        _sorter = New ListViewItemComparerClass
296    End Sub
297
298    Public Sub Add(ByVal TabText As String)
299        _tabs.Add(TabText, New TabClass)
300    End Sub
301
302    Public Function Contains(ByVal TabText As String) As Boolean
303        Return _tabs.ContainsKey(TabText)
304    End Function
305
306    Public Function Contains(ByVal ts As TabClass) As Boolean
307        Return _tabs.ContainsValue(ts)
308    End Function
309
310    Public ReadOnly Property Tabs() As Dictionary(Of String, TabClass)
311        Get
312            Return _tabs
313        End Get
314    End Property
315
316    Public ReadOnly Property Keys() As Collections.Generic.Dictionary(Of String, TabClass).KeyCollection
317        Get
318            Return _tabs.Keys
319        End Get
320    End Property
321
322    Public Sub Sort()
323        For Each key As String In _tabs.Keys
324            _tabs(key).Sort(_sorter)
325        Next
326    End Sub
327
328    Public ReadOnly Property Sorter() As ListViewItemComparerClass
329        Get
330            Return _sorter
331        End Get
332    End Property
333
334    Public Property SortOrder() As SortOrder
335        Get
336            Return _sorter.Order
337        End Get
338        Set(ByVal value As SortOrder)
339            _sorter.Order = value
340        End Set
341    End Property
342
343    Public WriteOnly Property Statuses() As Statuses
344        Set(ByVal value As Statuses)
345            _statuses = value
346        End Set
347    End Property
348
349    Public Function Distribute(ByVal AddedIDs As Specialized.StringCollection) As String
350        '�e�^�u�̃t�B���^�[�Əƍ��B���v�������u��D�lj�
351        Return "�ʒm���b�Z�[�W"
352    End Function
353
354End Class
355
356Public Class TabClass
357    Private _tabPage As System.Windows.Forms.TabPage
358    Private _listCustom As DetailsListView
359    'Public colHd1 As System.Windows.Forms.ColumnHeader
360    'Public colHd2 As System.Windows.Forms.ColumnHeader
361    'Public colHd3 As System.Windows.Forms.ColumnHeader
362    'Public colHd4 As System.Windows.Forms.ColumnHeader
363    'Public colHd5 As System.Windows.Forms.ColumnHeader
364    'Public idCol As System.Collections.Specialized.StringCollection
365    'Public tabName As String
366    'Public sorter As ListViewItemComparer
367    Private _unreadManage As Boolean
368    Private _notify As Boolean
369    Private _soundFile As String
370    Private _filters As List(Of FilterClass)
371    Private _modified As Boolean
372    'Private _oldestUnreadItem As ListViewItem
373    Private _oldestUnreadItem As String     'ID
374    Private _unreadCount As Integer
375    Private _allCount As Integer
376    Private _ids As List(Of String)
377
378    Public Sub New()
379        _filters = New List(Of FilterClass)
380        _notify = True
381        _soundFile = ""
382        _unreadManage = True
383        _ids = New List(Of String)
384    End Sub
385
386    Public Sub Sort(ByVal Sorter As ListViewItemComparerClass)
387        _ids.Sort(Sorter)
388    End Sub
389
390    Public Sub Add(ByVal ID As String, ByVal Read As Boolean)
391        If _ids.Contains(ID) Then Exit Sub
392
393        _ids.Add(ID)
394        If _oldestUnreadItem = "" Then
395            If ID < _oldestUnreadItem Then _oldestUnreadItem = ID
396        Else
397            _oldestUnreadItem = ID
398        End If
399
400        _allCount += 1
401        If Read = False And _unreadManage Then _unreadCount += 1
402    End Sub
403
404    Public Sub Remove(ByVal ID As String)
405        If _ids.Contains(ID) = False Then Exit Sub
406
407        _ids.Remove(ID)
408    End Sub
409
410    Public Property TabPage() As TabPage
411        Get
412            Return _tabPage
413        End Get
414        Set(ByVal value As TabPage)
415            _tabPage = value
416        End Set
417    End Property
418
419    Public Property ListCustom() As DetailsListView
420        Get
421            Return _listCustom
422        End Get
423        Set(ByVal value As DetailsListView)
424            _listCustom = value
425        End Set
426    End Property
427
428    Public Property UnreadManage() As Boolean
429        Get
430            Return _unreadManage
431        End Get
432        Set(ByVal value As Boolean)
433            _unreadManage = value
434        End Set
435    End Property
436
437    Public Property Notify() As Boolean
438        Get
439            Return _notify
440        End Get
441        Set(ByVal value As Boolean)
442            _notify = value
443        End Set
444    End Property
445
446    Public Property SoundFile() As String
447        Get
448            Return _soundFile
449        End Get
450        Set(ByVal value As String)
451            _soundFile = value
452        End Set
453    End Property
454
455    Public Property Modified() As Boolean
456        Get
457            Return _modified
458        End Get
459        Set(ByVal value As Boolean)
460            _modified = value
461        End Set
462    End Property
463
464    Public Property OldestUnreadItem() As String
465        Get
466            Return _oldestUnreadItem
467        End Get
468        Set(ByVal value As String)
469            _oldestUnreadItem = value
470        End Set
471    End Property
472
473    Public Property UnreadCount() As Integer
474        Get
475            Return _unreadCount
476        End Get
477        Set(ByVal value As Integer)
478            _unreadCount = value
479        End Set
480    End Property
481
482    Public Property AllCount() As Integer
483        Get
484            Return _allCount
485        End Get
486        Set(ByVal value As Integer)
487            _allCount = value
488        End Set
489    End Property
490
491    Public Overrides Function ToString() As String
492        Return _tabPage.Text
493    End Function
494
495    Public Property Filters() As List(Of FilterClass)
496        Get
497            Return _filters
498        End Get
499        Set(ByVal value As List(Of FilterClass))
500            _filters = value
501        End Set
502    End Property
503
504    Public Function Contains(ByVal ID As String) As Boolean
505        Return _ids.Contains(ID)
506    End Function
507
508    Public ReadOnly Property StatusIDs() As List(Of String)
509        Get
510            Return _ids
511        End Get
512    End Property
513
514End Class
515
516Public Class FiltersClass
517    Public IDFilter As String
518    Public BodyFilter As New List(Of String)()
519    Public SearchBoth As Boolean
520    Public moveFrom As Boolean
521    Public SetMark As Boolean
522    Public SearchURL As Boolean
523    Public UseRegex As Boolean
524End Class
525
526
527Public Class ListViewItemComparerClass
528    Implements IComparer(Of String)
529
530    '''' <summary>
531    '''' �������@
532    '''' </summary>
533    'Public Enum ComparerMode
534    '    [String]
535    '    [Integer]
536    '    DateTime
537    '    None
538    'End Enum
539
540    'Private _column As Integer
541    Private _order As SortOrder
542    'Private _mode As ComparerMode
543    'Private _columnModes() As ComparerMode
544
545    '''' <summary>
546    '''' ��ёւ���stView��ԍ�
547    '''' </summary>
548    'Public Property Column() As Integer
549    '    Get
550    '        Return _column
551    '    End Get
552    '    Set(ByVal Value As Integer)
553    '        If _column = Value Then
554    '            If _order = SortOrder.Ascending Then
555    '                _order = SortOrder.Descending
556    '            Else
557    '                If _order = SortOrder.Descending Then
558    '                    _order = SortOrder.Ascending
559    '                End If
560    '            End If
561    '        End If
562    '        _column = Value
563    '    End Set
564    'End Property
565
566    ''' <summary>
567    ''' �������~����
568    ''' </summary>
569    Public Property Order() As SortOrder
570        Get
571            Return _order
572        End Get
573        Set(ByVal Value As SortOrder)
574            _order = Value
575        End Set
576    End Property
577
578    '''' <summary>
579    '''' ��ёւ��̕�    '''' </summary>
580    'Public Property Mode() As ComparerMode
581    '    Get
582    '        Return _mode
583    '    End Get
584    '    Set(ByVal Value As ComparerMode)
585    '        _mode = Value
586    '    End Set
587    'End Property
588
589    '''' <summary>
590    '''' �񂲂Ƃ̕�ёւ��̕�    '''' </summary>
591    'Public WriteOnly Property ColumnModes() As ComparerMode()
592    '    Set(ByVal Value As ComparerMode())
593    '        _columnModes = Value
594    '    End Set
595    'End Property
596
597    ''' <summary>
598    ''' ListViewItemComparer�N���X�̃R���X�g���N�^
599    ''' </summary>
600    ''' <param name="col">��ёւ����ԍ�</param>
601    ''' <param name="ord">�������~����</param>
602    ''' <param name="cmod">��ёւ��̕�param>
603    Public Sub New(ByVal ord As SortOrder)
604        _order = ord
605    End Sub
606
607    Public Sub New()
608        _order = SortOrder.Ascending
609    End Sub
610
611    'x��y���������Ƃ��̓}�C�i�X�̐��A�傫���Ƃ��̓v���X�̐��A
612    '�����Ƃ������
613    Public Function Compare(ByVal x As String, ByVal y As String) _
614            As Integer Implements IComparer(Of String).Compare
615        Dim result As Integer = 0
616
617        result = String.Compare(x, y)
618        '�~���̎��͌��ʂ�t�ɂ���        If _order = SortOrder.Descending Then
619            result = -result
620        End If
621        Return result
622
623    End Function
624End Class
Note: See TracBrowser for help on using the browser.