aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Input/sid/decodersidfactory.cpp
Commit message (Expand)AuthorAgeFilesLines
* removed function DecoderFactory::supportstrialuser022016-07-261-18/+0
* added wildmidi-0.4.0 supporttrialuser022016-06-201-0/+8
* decreased compiling timetrialuser022016-06-131-1/+4
* sid plugin: added "*.c64" filter, fixed default HVSC pathtrialuser022016-05-231-3/+3
* added feature to exclude cue data filestrialuser022015-01-171-3/+3
* added function: Qmmp::configDir()trialuser022014-02-171-1/+1
* sid plugin: song length db optimizationtrialuser022013-04-281-3/+16
* sid plugin: added settings dialogtrialuser022013-04-281-2/+4
* sid plugin: added multiple tracks supporttrialuser022013-04-271-13/+21
* sid plugin: added metadata supporttrialuser022013-04-271-4/+19
* sid plugin: added about dialogtrialuser022013-04-271-7/+8
* prepare for sid plugin implementationtrialuser022013-04-271-0/+97
2:24:16 +0000 committer trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> 2008-12-16 12:24:16 +0000 added some mpris methods' href='/qmmp/commit/src/qmmpui/playlistmodel.cpp?id=8ab140dace337d1d413433510a87e161759ccc53'>8ab140dac
9c02a3609
2e689e667

ebd7f9bc6
6ba4fc48f
6ba4fc48f
7586a6542
92f1159a1
90d3aeb64

14ff3ad80
2d622fd9b
90d3aeb64
6cf6bc2f6
2d622fd9b
b917024aa
92f1159a1
6cf6bc2f6
24af8da3f
ebd7f9bc6
92f1159a1









9783fa786

24af8da3f

ebd7f9bc6
2d622fd9b



a65a14049
1d93bac0b
2d622fd9b

1d93bac0b
2d622fd9b

90d3aeb64






e2225dbc1




90d3aeb64

245d0ac0c
2d622fd9b
1d93bac0b
aa167f22d
ebd7f9bc6
2d622fd9b
1d93bac0b
48a0ee1fc

1d93bac0b
ebd7f9bc6
48a0ee1fc
92f1159a1
18b1a7a93



ebd7f9bc6

90d3aeb64
7e58dddb0
30142bc1a
90d3aeb64
245d0ac0c
90d3aeb64
90d3aeb64
ebd7f9bc6

01bb81fdc





ebd7f9bc6
01bb81fdc






1e31fe896
03082b6a3
aa167f22d
8ae997e7c
03082b6a3
cef2410a9
ebd7f9bc6

2d622fd9b

24af8da3f

b2576ddc1
24af8da3f



b2576ddc1
24af8da3f

7b5e9960a


aa167f22d
7b5e9960a
ebd7f9bc6

7b5e9960a



ebd7f9bc6
7b5e9960a






ebd7f9bc6

7b5e9960a

3be88d8c0

9783fa786



3be88d8c0

30142bc1a
7b5e9960a



ebd7f9bc6

1e31fe896
7b5e9960a

aa167f22d
7b5e9960a



ebd7f9bc6
7b5e9960a





ebd7f9bc6

7b5e9960a

87f088c76




30142bc1a
9783fa786






7b5e9960a

55869c8c5
7b5e9960a



3be88d8c0


7b5e9960a
3be88d8c0
b2576ddc1
3be88d8c0
3be88d8c0




1e31fe896
3be88d8c0

f5effb9a6
3be88d8c0



7b5e9960a

245d0ac0c
2d622fd9b
1d93bac0b
2d622fd9b

245d0ac0c
2d622fd9b
1d93bac0b
2d622fd9b

d894be75f




195d573df




245d0ac0c
24af8da3f
b917024aa
245d0ac0c



1d93bac0b
b917024aa
245d0ac0c
b917024aa
c6e0029ee

e2bc4908a
1d93bac0b
b917024aa
1d93bac0b
40ee4f96d

3a965fcd4
e662c2f44
1d93bac0b
e662c2f44

3a965fcd4

1d93bac0b
3a965fcd4

245d0ac0c

1d93bac0b
245d0ac0c

b94095cd8




245d0ac0c
2d622fd9b



3a965fcd4
2d622fd9b
0566de768
11b7655bb
1d93bac0b
245d0ac0c
b94095cd8



3a965fcd4
245d0ac0c
ebd7f9bc6
013ee07b5
2d622fd9b

245d0ac0c
03082b6a3
1d93bac0b
03082b6a3
1d93bac0b
03082b6a3

664d78f03

0566de768
664d78f03
1d93bac0b
664d78f03

b94095cd8

0566de768
b94095cd8
70637af74
b94095cd8

2d622fd9b

245d0ac0c
6d1217944
b917024aa
ebd7f9bc6
6d1217944

0566de768
4221ec3de
ebd7f9bc6


013ee07b5
4221ec3de

24af8da3f
2d622fd9b
2d622fd9b




0566de768
2d622fd9b
90d3aeb64
2d622fd9b



24af8da3f
2d622fd9b
b917024aa
1d93bac0b
a823ec787
aa167f22d
2d622fd9b
ebd7f9bc6
2d622fd9b



1d93bac0b
ebd7f9bc6
2d622fd9b

245d0ac0c
10cf99e34
1d93bac0b
2d622fd9b

245d0ac0c
2d622fd9b
1d93bac0b
2d622fd9b

542c1d2d3

76b31b99f
542c1d2d3
76b31b99f


aa167f22d
542c1d2d3
76b31b99f
542c1d2d3


a537e1ec3
245d0ac0c
a537e1ec3
245d0ac0c

332e5b1d4
176523a60
332e5b1d4
176523a60

42e660551


b917024aa
42e660551














3a965fcd4
2d622fd9b
1d93bac0b
ebd7f9bc6
2d622fd9b

30142bc1a
70637af74
1e31fe896
70637af74
ebd7f9bc6
70637af74

30142bc1a
70637af74
1e31fe896
70637af74
ebd7f9bc6
70637af74

215a0d9e8













ebd7f9bc6
215a0d9e8

30142bc1a
3810b6fb8
1e31fe896
3810b6fb8



2d622fd9b

ae16fa17d
2d622fd9b



ae16fa17d


245d0ac0c
fedd13511
ebd7f9bc6


fedd13511

0400576a8
43bf74b18
1d93bac0b

43bf74b18

9c9631639








0566de768
9c9631639


































ae16fa17d

2d622fd9b
ae16fa17d
ebd7f9bc6
ae16fa17d
1d93bac0b
2d622fd9b
1d93bac0b
0566de768
2d622fd9b
ebd7f9bc6
2d622fd9b
1d93bac0b
467be1724

ae16fa17d
2d622fd9b




ebd7f9bc6
ae16fa17d
ebd7f9bc6

1d93bac0b
ebd7f9bc6

ae16fa17d
2d622fd9b

ebd7f9bc6


80298eeab
ebd7f9bc6














b917024aa
ebd7f9bc6



aa167f22d

ebd7f9bc6




b917024aa
ebd7f9bc6










0566de768
ebd7f9bc6








2d622fd9b



0566de768
1d93bac0b
ebd7f9bc6
2d622fd9b



0566de768
1d93bac0b
ebd7f9bc6
2d622fd9b

24af8da3f
2d622fd9b
a2b0cb8e8

0566de768
2d622fd9b
a2b0cb8e8


ebd7f9bc6

a2b0cb8e8



eee0a25a3
e336a9c15
eee0a25a3
a2b0cb8e8
2d622fd9b
2d622fd9b

047d5bb26

0566de768
047d5bb26
0566de768
e336a9c15
eee0a25a3
047d5bb26



2d622fd9b

0566de768
2d622fd9b
0566de768
2d622fd9b






0566de768
2d622fd9b
0566de768
2d622fd9b




ed3492210
9548b5189
aa167f22d
9548b5189

ae7155e16
2d622fd9b

0566de768
2d622fd9b

14ff3ad80



2d622fd9b
6cf6bc2f6

14ff3ad80
0566de768
14ff3ad80



1d93bac0b
ef9971268
1d93bac0b
ebd7f9bc6
ef9971268
2d622fd9b

ae7155e16
2d622fd9b
0566de768
2d622fd9b

0566de768
2d622fd9b
0566de768
2d622fd9b






ae7155e16
2d622fd9b
0566de768
2d622fd9b

0566de768
2d622fd9b
0566de768
2d622fd9b






ae7155e16
2d622fd9b
ae7155e16
ae7155e16
3a965fcd4
2d622fd9b


3a965fcd4
2d622fd9b
245d0ac0c
0566de768
2d622fd9b
0566de768
2d622fd9b






3b41c0698
2d622fd9b
245d0ac0c
1e31fe896
2d622fd9b
245d0ac0c

2d622fd9b
245d0ac0c
2d622fd9b

9548b5189

1d93bac0b
9548b5189

2d622fd9b

463f4e95c
ebd7f9bc6
1e31fe896
245d0ac0c
ebd7f9bc6

2d622fd9b

245d0ac0c
2d622fd9b
0566de768
d4bb0061a
e6223d1c6
d4bb0061a
ebd7f9bc6
2d622fd9b

245d0ac0c
2d622fd9b



2d622fd9b




245d0ac0c
6d1217944
245d0ac0c
6d1217944






30142bc1a
6d1217944
245d0ac0c
6d1217944

2d622fd9b

3cce6c1d8



ebd7f9bc6
2d622fd9b



fce0e4d52



ebd7f9bc6
2d622fd9b
2d622fd9b
b97d5da36
2d622fd9b
3b41c0698

ebd7f9bc6
90f13f20a
2d622fd9b

b97d5da36
2d622fd9b
80567cfa3

ebd7f9bc6
90f13f20a







195d573df
90f13f20a


2d622fd9b

2d622fd9b

0566de768
2d622fd9b

0566de768
2d622fd9b


2d622fd9b

a5a2707ad

b917024aa
a5a2707ad








ebd7f9bc6


a37bc1f38

61f5091df
a37bc1f38

ebd7f9bc6


11aafe91c

ebd7f9bc6
11aafe91c
ebd7f9bc6






11aafe91c






ebd7f9bc6
2ab1fd161

ebd7f9bc6

6cf6bc2f6
ebd7f9bc6











b917024aa
ebd7f9bc6


463f4e95c

ebd7f9bc6
463f4e95c
ebd7f9bc6

463f4e95c




ebd7f9bc6




da0d54137



ebd7f9bc6
a5a2707ad

eee0a25a3







86f6a3667


eee0a25a3

86f6a3667




































eee0a25a3
























86f6a3667

eee0a25a3

86f6a3667


eee0a25a3







2d622fd9b

a8de6bc53







2d622fd9b

cf021281c
2d622fd9b
b2576ddc1





2d622fd9b

b67a746b1
2d622fd9b
b67a746b1

2d622fd9b
b67a746b1
1d93bac0b
883075834
b67a746b1
2d622fd9b

03082b6a3




2d622fd9b



cda0f909b
039a1be23
43bf74b18
ebd7f9bc6
43bf74b18
29c73615f


ebd7f9bc6
29c73615f
6d1217944
9e379f3ee




6d1217944


b917024aa
ebd7f9bc6
6d1217944



245d0ac0c
1cebfa814
6d1217944

b917024aa
1cebfa814
6d1217944
245d0ac0c
6d1217944
b917024aa
1cebfa814
6d1217944
245d0ac0c
6d1217944
ebd7f9bc6
6d1217944
ebd7f9bc6
245d0ac0c
1cebfa814
6d1217944
6d1217944
92f1159a1
ebd7f9bc6
92f1159a1



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
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
                                                                            
                                                                            
                                                                            



                                                                            
                                                                            








                                                                            
                                                                            
                                                                             
                      
                    
                 
                                 
                             

                           
                                

                               
                           
                         
                        
                          
                           

                          
                        
 
                                                                  
                                    
 
                          
                                               
 
                                    
                                    









                                                                                               

                                                                                      

                                                                    
                                                                



                               
                       
                       

                        
                       

 






                                                




                               

 
                                             
 
                                 
                                          
                  
 
                                      

                                
                                                
                         
     
                                             



                                                          

                            
 
 
                                                             
 
                        
               
 

                  





                                                          
                         






                                                          
                                                
     
                                              
                               
     
                       

                            

 

                                            
                        



                                                 
                         

 


                                                           
                                          
 

                  



                                                
                         






                                                          

                            

 

                                                                      



                                                     

 
                                                                           



                        

                  
                                                

                                               
                                              



                                                    
                             





                                                      

                            

 




                                                             
                                                                                      






                                                     

                                                          
                                         



                                                               


                                                  
     
                                                        
                                        
     




                                                              
                                         

                                  
                                                                           



                                         

 
                                
 
                                

 
                                     
 
                                     

 




                                   




                                                     
                                                  
 
                                                              



                                               
                                               
                       
                                                      
                       

                                    
                                          
                                                       
                       
                                     

 
                                                    
 
                                      

 

                                                  
                                    

 

                                                    
                                     

 




                                                    
                                       



                     
                                         
 
                                      
                     
                                                  
                       



                                        
                      
                                                          
                              
                

 
                                                    
 
                                     
                     
                                                   

 

                                            
                                      
                     
                                                

 

                                            
                                      
                     
                                               

 

                          
                                      
     
                               
                                     

                     
                                 
     


                                                          
                    

     
                             
                                




                                
                             
                                
                                    



                           
                       
                  
                           
                         
                           
                         
                               
                                                                           



                                    
                                  
                                

 
                                                                  
 
                                        

 
                                               
 
                                          

 

                                                
                                                 
     


                                    
                            
                        
     


                 
                                                
 
                                            

 
                                                              
 
                                               

 


                                                                         
                                 














                                                                               
                                                         
 
                                              
                                

 
                                                                                    
 
                                            
                                 
                                

 
                                                                                  
 
                                          
                                 
                                

 













                                                                   
                                

 
                                                                         
 
                                           



                                                

                                    
                           



                                      


                          
                                       
 


                                       

 
                                                     
 

                                                  

 








                                                                    
                                                    


































                                                                              

                                                  
              
                                 
                  
 
                                                               
     
                                                  
                                                             
         
                                            
 
                                      

                         
                                    




                
                                                                              
 

                                
                                                            

                           
 

                            


                                
 














                                                 
                               



                           

                                                            




                                  
                                      










                                                                                     
                       








                                                                             



                                     
                                                 
                                                                 
                                



                               
                                                 
                                          
                                

 
                                                
 

                                           
                                                 
     


                                                     

                                          



                                  
                                                                      
                                                    
                                                                                            
                  
     

 

                                                          
                       
     
                                                                                            
                                                    
                                                                                            



                  

                                              
                                   
     
                         






                                              
                                         
     
                         




                     
                                           
 
                            

 
                                               

                              
                  

               



                                                    
 

                                                                                                             
 
                                                      



                                                      
                                                     
     
                                                          
                                    
     

 
                                              
 
                

                 
                                   
     
                         






                         
                                                 
 
                          

                   
                                          
     
                         






                         
                                                           
 
                                                
                                                      
                                                       


                       
                                                 
 
                             
                                                 
     
                                              






                                    
                                                            
 
                                          
                                                  
     

                                                                        
     
                           

 

                                                  
                                

 

                                
                                                                   
                       
                                                         
                         

                            

 
                                                  
 
                      
                                       
        
                                     
                            

 
                                                    



                                      




                                        
                                                          
 
                                         






                                    
                                                               
 
                                

 

                                   



                                                      
                                



                                 



                                                      
                                
 
 
                                                
 

                              
 
                                                       

 
                                       
 

                              
 







                                              
                                             


                                                        

 

                                                      
                    

                            
           


                                                  

 

                                               
                                           








                                                          


                                

                                    
                               

 


                                                                        

                        
               
     






                                                                                              






                                                                             
                                                          

                                                                

                                                            
                                              











                                                                          
                                       


                                    

                                                                         
             
                                               

                                   




                                                  




                                    



                                       
     

 







                                                            


                                                               

                                              




































                                                                                                                               
























                                                                                      

                                 

     


                               







                                     

                                             







                                                  

 
                                                       
 





                                                                            

 
                                                       
 

                                                 
     
                      
                                           
     
                                                

 




                                           



                                      
 
                                         
 
                                                                        
 


                                      
                                                                     
 
 




                                                            


                                
                            
                             



                                       
                                                             
 

                                 
                                                                                               
                                     
     
                                         
     
                                                                                               
                                     
     
                                        
     
                           
                     
                            
                                             
                                             
     
 
 
                                   



                                        
/***************************************************************************
 *   Copyright(C) 2006-2021 by Ilya Kotov                                  *
 *   forkotov02@ya.ru                                                      *
 *                                                                         *
 *   This program 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.                                    *
 *                                                                         *
 *   This program 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 this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/
#include <QTextStream>
#include <algorithm>
#include <time.h>
#include <qmmp/metadatamanager.h>
#include "metadatahelper_p.h"
#include "playlistparser.h"
#include "playlistformat.h"
#include "playlistcontainer_p.h"
#include "groupedcontainer_p.h"
#include "normalcontainer_p.h"
#include "playlisttask_p.h"
#include "fileloader_p.h"
#include "playstate_p.h"
#include "detailsdialog.h"
#include "qmmpuisettings.h"
#include "playlistmodel.h"

#define INVALID_INDEX -1

PlayListModel::PlayListModel(const QString &name, QObject *parent)
    : QObject(parent) , m_name(name)
{
    qsrand(time(nullptr));
    m_ui_settings = QmmpUiSettings::instance();

    m_loader = new FileLoader(this);
    m_task = new PlayListTask(this);
    if(m_ui_settings->isGroupsEnabled())
        m_container = new GroupedContainer;
    else
        m_container = new NormalContainer;
    if(m_ui_settings->isShuffle())
        m_play_state = new ShufflePlayState(this);
    else
        m_play_state = new NormalPlayState(this);
    connect(m_ui_settings, SIGNAL(groupsChanged(bool)), SLOT(prepareGroups(bool)));
    connect(m_ui_settings, SIGNAL(shuffleChanged(bool)), SLOT(prepareForShufflePlaying(bool)));
    connect(m_loader, SIGNAL(newTracksToInsert(PlayListItem*, QList<PlayListTrack*>)),
            SLOT(insert(PlayListItem*, QList<PlayListTrack*>)), Qt::QueuedConnection);
    connect(m_loader, SIGNAL(finished()), SLOT(preparePlayState()));
    connect(m_loader, SIGNAL(finished()), SIGNAL(loaderFinished()));
    connect(m_task, SIGNAL(finished()), SLOT(onTaskFinished()));
}

PlayListModel::~PlayListModel()
{
    blockSignals(true);
    m_loader->finish();
    clear();
    delete m_play_state;
    delete m_container;
}

QString PlayListModel::name() const
{
    return m_name;
}

void PlayListModel::setName(const QString &name)
{
    if(m_name != name)
    {
        m_name = name;
        emit nameChanged(name);
    }
}

void PlayListModel::add(PlayListTrack *track)
{
    m_container->addTrack(track);
    m_total_duration += track->duration();
    int flags = 0;

    if(m_container->trackCount() == 1)
    {
        m_current_track = track;
        m_current = m_container->indexOf(track);
        flags |= CURRENT;
    }
    else if(m_ui_settings->isGroupsEnabled())
    {
        //update current index for grouped container only
        m_current = m_container->indexOf(m_current_track);
    }
    flags |= STRUCTURE;
    emit listChanged(flags);
}

void PlayListModel::add(const QList<PlayListTrack *> &tracks)
{
    if(tracks.isEmpty())
        return;

    int flags = 0;

    m_container->addTracks(tracks);

    if(m_container->trackCount() == tracks.count())
    {
        m_current_track = tracks.first();
        m_current = m_container->indexOf(m_current_track);
        flags |= CURRENT;
    }
    else if(m_ui_settings->isGroupsEnabled())
    {
        //update current index for grouped container only
        m_current = m_container->indexOf(m_current_track);
    }

    for(PlayListTrack *track : qAsConst(tracks))
    {
        m_total_duration += track->duration();
        emit trackAdded(track);
    }
    preparePlayState();
    flags |= STRUCTURE;
    emit listChanged(flags);
}

void PlayListModel::add(const QString &path)
{
    m_loader->add(path);
}

void PlayListModel::add(const QStringList &paths)
{
    m_loader->add(paths);
}

void PlayListModel::insert(int index, PlayListTrack *track)
{
    m_container->insertTrack(index, track);
    m_total_duration += track->duration();

    int flags = 0;

    if(m_container->trackCount() == 1)
    {
        m_current_track = track;
        m_current = m_container->indexOf(track);
        flags |= CURRENT;
    }
    else
    {
        //update current index
        m_current = m_container->indexOf(m_current_track);
    }
    emit trackAdded(track);
    flags |= STRUCTURE;
    emit listChanged(flags);
}

void PlayListModel::insert(PlayListItem *before, PlayListTrack *track)
{
     if(before)
         insert(m_container->indexOf(before), track);
     else
         add(track);
}

void PlayListModel::insert(int index, const QList<PlayListTrack *> &tracks)
{
    if(tracks.isEmpty())
        return;

    int flags = 0;

    for(PlayListTrack *track : qAsConst(tracks))
    {
        m_container->insertTrack(index, track);
        m_total_duration += track->duration();
        if(m_container->trackCount() == 1)
        {
            m_current_track = track;
            m_current = m_container->indexOf(track);
            flags |= CURRENT;
        }
        emit trackAdded(track);
    }
    //update current index
    m_current = m_container->indexOf(m_current_track);
    preparePlayState();
    flags |= STRUCTURE;
    emit listChanged(flags);
}

void PlayListModel::insert(int index, const QByteArray &json)
{
    insert(index, PlayListParser::deserialize(json));
}

void PlayListModel::insert(PlayListItem *before, const QList<PlayListTrack *> &tracks)
{
    if(before)
        insert(m_container->indexOf(before), tracks);
    else
        add(tracks);
}

void PlayListModel::insert(int index, const QString &path)
{
    insert(index, QStringList() << path);
}

void PlayListModel::insert(int index, const QStringList &paths)
{
    if(index < 0 || index >= m_container->count())
        add(paths);
    else
    {
        PlayListItem *before = m_container->item(index);
        m_loader->insert(before, paths);
    }
}

void PlayListModel::insert(int index, const QList<QUrl> &urls)
{
    QStringList paths;
    for(const QUrl &url : qAsConst(urls))
    {
        if(url.scheme() == "file")
            paths.append(QFileInfo(url.toLocalFile()).canonicalFilePath());
        else
            paths.append(url.toString());
    }
    insert(index, paths);
}

int PlayListModel::count() const
{
    return m_container->count();
}

int PlayListModel::trackCount() const
{
    return m_container->trackCount();
}

bool PlayListModel::isEmpty() const
{
    return m_container->isEmpty();
}

int PlayListModel::columnCount() const
{
    return MetaDataHelper::instance()->columnCount();
}

PlayListTrack* PlayListModel::currentTrack() const
{
    return m_container->isEmpty() ? nullptr : m_current_track;
}

PlayListTrack *PlayListModel::nextTrack() const
{
    if(m_container->isEmpty() || !m_play_state)
        return nullptr;
    if(m_stop_track && m_stop_track == currentTrack())
        return nullptr;
    if(!isEmptyQueue())
        return m_queued_songs.at(0);
    int index = m_play_state->nextIndex();
    if(index < 0 || (index + 1 > m_container->count()))
        return nullptr;
    return m_container->track(index);
}

int PlayListModel::indexOf(PlayListItem* item) const
{
    return m_container->indexOf(item);
}

PlayListItem* PlayListModel::item(int index) const
{
    return m_container->item(index);
}

PlayListTrack* PlayListModel::track(int index) const
{
    return m_container->track(index);
}

PlayListGroup* PlayListModel::group(int index) const
{
    return m_container->group(index);
}

int PlayListModel::currentIndex() const
{
    return m_current;
}

bool PlayListModel::setCurrent(int index)
{
    if(index > count()-1 || index < 0)
        return false;
    PlayListItem *item = m_container->item(index);
    if(item->isGroup())
    {
        index++;
        item = m_container->item(index);
    }
    m_current = index;
    m_current_track = dynamic_cast<PlayListTrack*> (item);
    emit listChanged(CURRENT);
    return true;
}

bool PlayListModel::setCurrent(PlayListTrack *track)
{
    if(!m_container->contains(track))
        return false;
    return setCurrent(m_container->indexOf(track));
}

bool PlayListModel::isTrack(int index) const
{
    if(index > count()-1 || index < 0)
        return false;
    return !m_container->item(index)->isGroup();
}

bool PlayListModel::isGroup(int index) const
{
    if(index > count()-1 || index < 0)
        return false;
    return m_container->item(index)->isGroup();
}

bool PlayListModel::next()
{
    if(m_stop_track == currentTrack())
    {
        m_stop_track = nullptr;
        emit listChanged(STOP_AFTER);
        return false;
    }
    if(!m_queued_songs.isEmpty())
    {
        m_current_track = m_queued_songs.dequeue();
        m_current = m_container->indexOf(m_current_track);
        emit listChanged(CURRENT | QUEUE);
        return true;
    }

    if(m_loader->isRunning())
        m_play_state->prepare();
    return m_play_state->next();
}

bool PlayListModel::previous()
{
    if(m_loader->isRunning())
        m_play_state->prepare();
    return m_play_state->previous();
}

void PlayListModel::clear()
{
    m_loader->finish();
    m_current = 0;
    m_stop_track = nullptr;
    m_container->clear();
    m_queued_songs.clear();
    m_total_duration = 0;
    m_play_state->resetState();
    emit listChanged(STRUCTURE | QUEUE | STOP_AFTER | CURRENT | SELECTION);
}

void PlayListModel::clearSelection()
{
    m_container->clearSelection();
    emit listChanged(SELECTION);
}

QList<PlayListItem *> PlayListModel::mid(int pos, int count) const
{
    return m_container->mid(pos, count);
}

bool PlayListModel::isSelected(int index) const
{
    return m_container->isSelected(index);
}

bool PlayListModel::contains(const QString &url)
{
    for(int i = 0; i < m_container->count(); ++i)
    {
        PlayListTrack *t = track(i);
        if(!t)
            continue;
        if(t->path() == url)
            return true;
    }
    return false;
}

int PlayListModel::indexOfTrack(int index) const
{
    return m_container->indexOfTrack(index);
}

PlayListTrack *PlayListModel::findTrack(int track_index) const
{
    return m_container->findTrack(track_index);
}

QList<PlayListItem *> PlayListModel::findTracks(const QString &str) const
{
    QList<PlayListItem *> items;
    PlayListItem *item = nullptr;
    if(str.isEmpty())
        return items;

    for(int i = 0; i < m_container->count(); ++i)
    {
        item = m_container->item(i);
        if(item->isGroup())
            continue;

        if(!item->formattedTitles().filter(str, Qt::CaseInsensitive).isEmpty())
            items.append(item);
    }
    return items;
}

void PlayListModel::setSelected(int index, bool selected)
{
    m_container->setSelected(index, selected);
    emit listChanged(SELECTION);
}

void PlayListModel::setSelected(const QList<PlayListTrack *> &tracks, bool selected)
{
    for(PlayListTrack *t : qAsConst(tracks))
        t->setSelected(selected);
    emit listChanged(SELECTION);
}

void PlayListModel::setSelected(const QList<PlayListItem *> &items, bool selected)
{
    for(PlayListItem *i : qAsConst(items))
        i->setSelected(selected);
    emit listChanged(SELECTION);
}

void PlayListModel::setSelected(int first, int last, bool selected)
{
    if(first > last)
    {
        setSelected(last, first, selected);
        return;
    }
    for(int index = first; index <= last; ++index)
    {
        PlayListItem *i = item(index);
        if(!i)
            continue;
        i->setSelected(selected);
    }
    emit listChanged(SELECTION);
}

void PlayListModel::setSelected(const QList<int> &indexes, bool selected)
{
    for(const int &idx : qAsConst(indexes))
        m_container->setSelected(idx, selected);
    emit listChanged(SELECTION);
}

void PlayListModel::removeSelected()
{
    removeSelection(false);
}

void PlayListModel::removeUnselected()
{
    removeSelection(true);
}

void PlayListModel::removeTrack (int i)
{
    int flags = removeTrackInternal(i);
    if(flags)
        emit listChanged(flags);
}

void PlayListModel::removeTrack (PlayListItem *track)
{
    if(m_container->contains(track))
        removeTrack (m_container->indexOf(track));
}

void PlayListModel::removeTracks(const QList<PlayListItem *> &items)
{
    int i = 0;
    int select_after_delete = -1;