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
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
|
#include "stdafx.h"
#include "GUIWindowMusicBase.h"
#include "MusicInfoTagLoaderFactory.h"
#include "GUIWindowMusicInfo.h"
#include "FileSystem/HDdirectory.h"
#include "FileSystem/ZipManager.h"
#include "PlayListFactory.h"
#include "Util.h"
#include "PlayListM3U.h"
#include "Application.h"
#include "PlayListPlayer.h"
#include "GUIThumbnailPanel.h"
#include "GUIListControl.h"
#include "FileSystem/DirectoryCache.h"
#include "CDRip/CDDARipper.h"
#include "GUIPassword.h"
#include "AutoSwitch.h"
#include "GUIFontManager.h"
#define CONTROL_BTNVIEWASICONS 2
#define CONTROL_BTNTYPE 6
#define CONTROL_BTNSEARCH 8
#define CONTROL_LIST 50
#define CONTROL_THUMBS 51
#define CONTROL_BIGLIST 52
using namespace MUSIC_GRABBER;
using namespace DIRECTORY;
using namespace PLAYLIST;
int CGUIWindowMusicBase::m_nTempPlayListWindow = 0;
CStdString CGUIWindowMusicBase::m_strTempPlayListDirectory = "";
CGUIWindowMusicBase::CGUIWindowMusicBase ()
: CGUIWindow(0)
{
m_nSelectedItem = -1;
m_iLastControl = -1;
m_bDisplayEmptyDatabaseMessage = false;
m_Directory.m_bIsFolder = true;
m_bSectionsLoaded=false;
}
CGUIWindowMusicBase::~CGUIWindowMusicBase ()
{
}
/// \brief Handle actions on window.
/// \param action Action that can be reacted on.
bool CGUIWindowMusicBase::OnAction(const CAction& action)
{
if (action.wID == ACTION_PARENT_DIR)
{
GoParentFolder();
return true;
}
if (action.wID == ACTION_PREVIOUS_MENU)
{
if (!g_application.m_guiDialogMusicScan.IsRunning())
{
CUtil::ThumbCacheClear();
CUtil::RemoveTempFiles();
}
m_gWindowManager.ActivateWindow(WINDOW_HOME);
return true;
}
if (action.wID == ACTION_SHOW_PLAYLIST)
{
m_gWindowManager.ActivateWindow(WINDOW_MUSIC_PLAYLIST);
return true;
}
return CGUIWindow::OnAction(action);
}
/*!
\brief Handle messages on window.
\param message GUI Message that can be reacted on.
\return if a message can't be processed, return \e false
On these messages this class reacts.\n
When retrieving...
- #GUI_MSG_PLAYBACK_ENDED\n
...and...
- #GUI_MSG_PLAYBACK_STOPPED\n
...it deselects the current playing item in list/thumb control,
if we are in a temporary playlist or in playlistwindow
- #GUI_MSG_PLAYLIST_PLAY_NEXT_PREV\n
...the next playing item is set in list/thumb control
- #GUI_MSG_DVDDRIVE_EJECTED_CD\n
...it will look, if m_strDirectory contains a path from a DVD share.
If it is, Update() is called with a empty directory.
- #GUI_MSG_DVDDRIVE_CHANGED_CD\n
...and m_strDirectory is empty, Update is called to renew icons after
disc is changed.
- #GUI_MSG_WINDOW_DEINIT\n
...the last focused control is saved to m_iLastControl.
- #GUI_MSG_WINDOW_INIT\n
...the musicdatabase is opend and the music extensions and shares are set.
The last focused control is set.
- #GUI_MSG_CLICKED\n
... the base class reacts on the following controls:\n
Buttons:\n
- #CONTROL_BTNVIEWASICONS - switch between list, thumb and with large items
- #CONTROL_BTNTYPE - switch between music windows
- #CONTROL_BTNSEARCH - Search for items\n
Other Controls:
- #CONTROL_LIST and #CONTROL_THUMB\n
Have the following actions in message them clicking on them.
- #ACTION_QUEUE_ITEM - add selected item to playlist
- #ACTION_SHOW_INFO - retrieve album info from the internet
- #ACTION_SELECT_ITEM - Item has been selected. Overwrite OnClick() to react on it
*/
bool CGUIWindowMusicBase::OnMessage(CGUIMessage& message)
{
switch ( message.GetMessage() )
{
case GUI_MSG_PLAYBACK_STARTED:
{
UpdateButtons();
}
break;
case GUI_MSG_PLAYBACK_ENDED:
case GUI_MSG_PLAYBACK_STOPPED:
case GUI_MSG_PLAYLISTPLAYER_STOPPED:
{
CStdString strDirectory = m_Directory.m_strPath;
if (CUtil::HasSlashAtEnd(strDirectory))
strDirectory.Delete(strDirectory.size() - 1);
if ((m_nTempPlayListWindow == GetID() && m_strTempPlayListDirectory == strDirectory)
|| (GetID() == WINDOW_MUSIC_PLAYLIST) )
{
for (int i = 0; i < m_vecItems.Size(); ++i)
{
CFileItem* pItem = m_vecItems[i];
if (pItem && pItem->IsSelected())
{
pItem->Select(false);
break;
}
}
}
UpdateButtons();
}
break;
case GUI_MSG_PLAYLISTPLAYER_STARTED:
case GUI_MSG_PLAYLISTPLAYER_CHANGED:
{
// started playing another song...
int nCurrentPlaylist = message.GetParam1();
CStdString strDirectory = m_Directory.m_strPath;
if (CUtil::HasSlashAtEnd(strDirectory))
strDirectory.Delete(strDirectory.size() - 1);
if ((nCurrentPlaylist == PLAYLIST_MUSIC_TEMP && m_nTempPlayListWindow == GetID() && m_strTempPlayListDirectory == strDirectory )
|| (GetID() == WINDOW_MUSIC_PLAYLIST && nCurrentPlaylist == PLAYLIST_MUSIC))
{
int nCurrentItem = 0;
int nPreviousItem = -1;
if (message.GetMessage() == GUI_MSG_PLAYLISTPLAYER_STARTED)
{
nCurrentItem = message.GetParam2();
}
else if (message.GetMessage() == GUI_MSG_PLAYLISTPLAYER_CHANGED)
{
nCurrentItem = LOWORD(message.GetParam2());
nPreviousItem = HIWORD(message.GetParam2());
}
int nFolderCount = m_vecItems.GetFolderCount();
// is the previous item in this directory
for (int i = nFolderCount, n = 0; i < m_vecItems.Size(); i++)
{
CFileItem* pItem = m_vecItems[i];
if (pItem)
pItem->Select(false);
}
if (nFolderCount + nCurrentItem < m_vecItems.Size())
{
for (int i = nFolderCount, n = 0; i < m_vecItems.Size(); i++)
{
CFileItem* pItem = m_vecItems[i];
if (pItem)
{
if (!pItem->IsPlayList() && !pItem->IsNFO())
n++;
if ((n - 1) == nCurrentItem)
{
pItem->Select(true);
break;
}
}
} // for (int i=nFolderCount, n=0; i<(int)m_vecItems.size(); i++)
}
}
}
break;
case GUI_MSG_DVDDRIVE_EJECTED_CD:
{
if ( !m_Directory.IsVirtualDirectoryRoot() )
{
if (m_Directory.IsCDDA() || m_Directory.IsDVD() || m_Directory.IsISO9660())
{
// Disc has changed and we are inside a DVD Drive share, get out of here :)
Update("");
}
}
else
{
int iItem = m_viewControl.GetSelectedItem();
Update(m_Directory.m_strPath);
m_viewControl.SetSelectedItem(iItem);
}
}
break;
case GUI_MSG_DVDDRIVE_CHANGED_CD:
{
if (m_Directory.IsVirtualDirectoryRoot())
{
int iItem = m_viewControl.GetSelectedItem();
Update(m_Directory.m_strPath);
m_viewControl.SetSelectedItem(iItem);
}
}
break;
case GUI_MSG_WINDOW_DEINIT:
{
m_nSelectedItem = m_viewControl.GetSelectedItem();
m_iLastControl = GetFocusedControl();
ClearFileItems();
g_musicDatabase.Close();
if (m_bSectionsLoaded)
{
CSectionLoader::Unload("LIBID3");
// CSectionLoader::Unload("LIBMP4");
CSectionLoader::UnloadDLL(APE_DLL);
CSectionLoader::UnloadDLL(SHN_DLL);
CSectionLoader::UnloadDLL(MPC_DLL);
CSectionLoader::UnloadDLL(OGG_DLL);
CSectionLoader::UnloadDLL(AAC_DLL);
m_bSectionsLoaded=false;
}
}
break;
case GUI_MSG_WINDOW_INIT:
{
int iLastControl = m_iLastControl;
CGUIWindow::OnMessage(message);
CSectionLoader::Load("LIBID3");
// CSectionLoader::Load("LIBMP4");
CSectionLoader::LoadDLL(APE_DLL);
CSectionLoader::LoadDLL(SHN_DLL);
CSectionLoader::LoadDLL(MPC_DLL);
CSectionLoader::LoadDLL(OGG_DLL);
CSectionLoader::LoadDLL(AAC_DLL);
m_bSectionsLoaded=true;
g_musicDatabase.Open();
m_dlgProgress = (CGUIDialogProgress*)m_gWindowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
m_rootDir.SetMask(g_stSettings.m_szMyMusicExtensions);
m_rootDir.SetShares(g_settings.m_vecMyMusicShares);
Update(m_Directory.m_strPath);
if (iLastControl > -1)
{
SET_CONTROL_FOCUS(iLastControl, 0);
}
else
{
SET_CONTROL_FOCUS(m_dwDefaultFocusControlID, 0);
}
if (m_nSelectedItem > -1)
{
m_viewControl.SetSelectedItem(m_nSelectedItem);
}
return true;
}
break;
case GUI_MSG_CLICKED:
{
int iControl = message.GetSenderId();
if (iControl == CONTROL_BTNVIEWASICONS)
{
if ( m_Directory.IsVirtualDirectoryRoot() )
{
m_iViewAsIconsRoot++;
if (m_iViewAsIconsRoot > VIEW_AS_LARGE_ICONS) m_iViewAsIconsRoot = VIEW_AS_LIST;
}
else
{
m_iViewAsIcons++;
if (m_iViewAsIcons > VIEW_AS_LARGE_ICONS) m_iViewAsIcons = VIEW_AS_LIST;
}
UpdateButtons();
}
else if (iControl == CONTROL_BTNTYPE)
{
CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), CONTROL_BTNTYPE);
m_gWindowManager.SendMessage(msg);
int nWindow = WINDOW_MUSIC_FILES + msg.GetParam1();
if (nWindow == GetID())
return true;
g_stSettings.m_iMyMusicStartWindow = nWindow;
g_settings.Save();
m_gWindowManager.ActivateWindow(g_stSettings.m_iMyMusicStartWindow);
CGUIMessage msg2(GUI_MSG_SETFOCUS, g_stSettings.m_iMyMusicStartWindow, CONTROL_BTNTYPE);
g_graphicsContext.SendMessage(msg2);
return true;
}
else if (iControl == CONTROL_BTNSEARCH)
{
OnSearch();
}
else if (m_viewControl.HasControl(iControl)) // list/thumb control
{
int iItem = m_viewControl.GetSelectedItem();
int iAction = message.GetParam1();
// iItem is checked for validity inside these routines
if (iAction == ACTION_QUEUE_ITEM || iAction == ACTION_MOUSE_MIDDLE_CLICK)
{
OnQueueItem(iItem);
}
else if (iAction == ACTION_SELECT_ITEM || iAction == ACTION_MOUSE_LEFT_CLICK)
{
OnClick(iItem);
}
else if (iAction == ACTION_SHOW_INFO)
{
OnInfo(iItem);
}
else if (iAction == ACTION_CONTEXT_MENU || iAction == ACTION_MOUSE_RIGHT_CLICK)
{
OnPopupMenu(iItem);
}
// use play button to add folders of items to temp playlist
else if (iAction == ACTION_PLAYER_PLAY)
{
// if playback is paused or playback speed != 1, return
if (g_application.IsPlayingAudio())
{
if (g_application.m_pPlayer->IsPaused()) return false;
if (g_application.GetPlaySpeed() != 1) return false;
}
// not playing audio, or playback speed == 1
PlayItem(iItem);
}
}
}
case GUI_MSG_SETFOCUS:
{
if (m_viewControl.HasControl(message.GetControlId()) && m_viewControl.GetCurrentControl() != message.GetControlId())
{
m_viewControl.SetFocused();
return true;
}
}
}
return CGUIWindow::OnMessage(message);
}
void CGUIWindowMusicBase::OnWindowLoaded()
{
CGUIWindow::OnWindowLoaded();
// add the view controls to our view controller
m_viewControl.Reset();
m_viewControl.SetParentWindow(GetID());
m_viewControl.AddView(VIEW_AS_LIST, GetControl(CONTROL_LIST));
m_viewControl.AddView(VIEW_AS_ICONS, GetControl(CONTROL_THUMBS));
m_viewControl.AddView(VIEW_AS_LARGE_ICONS, GetControl(CONTROL_THUMBS));
m_viewControl.AddView(VIEW_AS_LARGE_LIST, GetControl(CONTROL_BIGLIST));
m_viewControl.SetViewControlID(CONTROL_BTNVIEWASICONS);
}
/// \brief Remove items from list/thumb control and \e m_vecItems.
void CGUIWindowMusicBase::ClearFileItems()
{
m_viewControl.Clear();
m_vecItems.Clear(); // will clean up everything
}
/// \brief Updates list/thumb control
/// Sets item labels (text and thumbs), sorts items and adds them to the control
void CGUIWindowMusicBase::UpdateListControl()
{
// Cache available album thumbs
g_directoryCache.InitMusicThumbCache();
for (int i = 0; i < m_vecItems.Size(); i++)
{
CFileItem* pItem = m_vecItems[i];
// Format label for listcontrol
// and set thumb/icon for item
OnFileItemFormatLabel(pItem);
}
g_directoryCache.ClearMusicThumbCache();
DoSort(m_vecItems);
m_viewControl.SetItems(m_vecItems);
}
/// \brief Set window to a specific directory
/// \param strDirectory The directory to be displayed in list/thumb control
void CGUIWindowMusicBase::Update(const CStdString &strDirectory)
{
// get selected item
int iItem = m_viewControl.GetSelectedItem();
CStdString strSelectedItem = "";
if (iItem >= 0 && iItem < m_vecItems.Size())
{
CFileItem* pItem = m_vecItems[iItem];
if (pItem->GetLabel() != "..")
{
GetDirectoryHistoryString(pItem, strSelectedItem);
}
}
ClearFileItems();
m_history.Set(strSelectedItem, m_Directory.m_strPath);
m_Directory.m_strPath = strDirectory;
GetDirectory(m_Directory.m_strPath, m_vecItems);
RetrieveMusicInfo();
UpdateListControl();
UpdateButtons();
strSelectedItem = m_history.Get(m_Directory.m_strPath);
int iCurrentPlaylistSong = -1;
// Search current playlist item
CStdString strCurrentDirectory = m_Directory.m_strPath;
if (CUtil::HasSlashAtEnd(strCurrentDirectory))
strCurrentDirectory.Delete(strCurrentDirectory.size() - 1);
if ((m_nTempPlayListWindow == GetID() && m_strTempPlayListDirectory == strCurrentDirectory && g_application.IsPlayingAudio()
&& g_playlistPlayer.GetCurrentPlaylist() == PLAYLIST_MUSIC_TEMP)
|| (GetID() == WINDOW_MUSIC_PLAYLIST && g_playlistPlayer.GetCurrentPlaylist() == PLAYLIST_MUSIC && g_application.IsPlayingAudio()) )
{
iCurrentPlaylistSong = g_playlistPlayer.GetCurrentSong();
}
bool bSelectedFound = false, bCurrentSongFound = false;
int iSongInDirectory = -1;
for (int i = 0; i < m_vecItems.Size(); ++i)
{
CFileItem* pItem = m_vecItems[i];
// Update selected item
if (!bSelectedFound)
{
CStdString strHistory;
GetDirectoryHistoryString(pItem, strHistory);
if (strHistory == strSelectedItem)
{
m_viewControl.SetSelectedItem(i);
bSelectedFound = true;
}
}
// synchronize playlist with current directory
if (!bCurrentSongFound && iCurrentPlaylistSong > -1)
{
if (!pItem->m_bIsFolder && !pItem->IsPlayList() && !pItem->IsNFO())
iSongInDirectory++;
if (iSongInDirectory == iCurrentPlaylistSong)
{
pItem->Select(true);
bCurrentSongFound = true;
}
}
}
}
/// \brief Call to go to parent folder
void CGUIWindowMusicBase::GoParentFolder()
{
CURL url(m_Directory.m_strPath);
if ((url.GetProtocol() == "rar") || (url.GetProtocol() == "zip"))
{
// check for step-below, if, unmount rar
if (url.GetFileName().IsEmpty())
{
if (url.GetProtocol() == "zip")
g_ZipManager.release(m_Directory.m_strPath); // release resources
m_rootDir.RemoveShare(m_Directory.m_strPath);
CStdString strPath;
CUtil::GetDirectory(url.GetHostName(),strPath);
Update(strPath);
return;
}
}
CStdString strPath(m_strParentPath), strOldPath(m_Directory.m_strPath);
Update(strPath);
if (!g_guiSettings.GetBool("FileLists.FullDirectoryHistory"))
m_history.Remove(strOldPath); //Delete current path
}
/// \brief Tests if a network/removeable share is available
/// \param strPath Root share to go into
/// \param iDriveType If share is remote, dvd or hd. See: CShare
/// \return If drive is available, returns \e true
/// \todo Handle not connected to a remote share
bool CGUIWindowMusicBase::HaveDiscOrConnection( CStdString& strPath, int iDriveType )
{
if ( iDriveType == SHARE_TYPE_DVD )
{
CDetectDVDMedia::WaitMediaReady();
if ( !CDetectDVDMedia::IsDiscInDrive() )
{
CGUIDialogOK* dlg = (CGUIDialogOK*)m_gWindowManager.GetWindow(WINDOW_DIALOG_OK);
if (dlg)
{
dlg->SetHeading( 218 );
dlg->SetLine( 0, 219 );
dlg->SetLine( 1, L"" );
dlg->SetLine( 2, L"" );
dlg->DoModal( GetID() );
}
// Update listcontrol, maybe share
// was selected while disc change
int iItem = m_viewControl.GetSelectedItem();
Update( m_Directory.m_strPath );
m_viewControl.SetSelectedItem(iItem);
return false;
}
}
else if (iDriveType == SHARE_TYPE_REMOTE)
{
// TODO: Handle not connected to a remote share
if ( !CUtil::IsEthernetConnected() )
{
CGUIDialogOK* dlg = (CGUIDialogOK*)m_gWindowManager.GetWindow(WINDOW_DIALOG_OK);
if (dlg)
{
dlg->SetHeading( 220 );
dlg->SetLine( 0, 221 );
dlg->SetLine( 1, L"" );
dlg->SetLine( 2, L"" );
dlg->DoModal( GetID() );
}
return false;
}
}
return true;
}
/// \brief Retrieves music info for albums from allmusic.com and displays them in CGUIWindowMusicInfo
/// \param iItem Item in list/thumb control
void CGUIWindowMusicBase::OnInfo(int iItem)
{
if ( iItem < 0 || iItem >= m_vecItems.Size() ) return ;
CGUIDialogOK* pDlgOK = (CGUIDialogOK*)m_gWindowManager.GetWindow(WINDOW_DIALOG_OK);
CFileItem* pItem;
pItem = m_vecItems[iItem];
if (pItem->m_bIsFolder && pItem->GetLabel() == "..") return ;
// show dialog box indicating we're searching the album name
if (m_dlgProgress)
{
m_dlgProgress->SetHeading(185);
m_dlgProgress->SetLine(0, 501);
m_dlgProgress->SetLine(1, "");
m_dlgProgress->SetLine(2, "");
m_dlgProgress->StartModal(GetID());
m_dlgProgress->Progress();
}
CStdString strPath;
if (pItem->m_bIsFolder)
{
strPath = pItem->m_strPath;
if (CUtil::HasSlashAtEnd(strPath))
strPath.Delete(strPath.size() - 1);
}
else
{
CUtil::GetDirectory(pItem->m_strPath, strPath);
}
// Try to find an album name for this item.
// Only save to database, if album name is found there.
VECALBUMS albums;
bool bSaveDb = false;
bool bSaveDirThumb = false;
CStdString strLabel = pItem->GetLabel();
CAlbum album;
if (pItem->m_musicInfoTag.Loaded())
{
CStdString strAlbum = pItem->m_musicInfoTag.GetAlbum();
if (!strAlbum.IsEmpty())
strLabel = strAlbum;
if (g_musicDatabase.GetAlbumsByPath(strPath, albums))
{
if (albums.size() == 1)
bSaveDirThumb = true;
bSaveDb = true;
}
else if (!pItem->m_bIsFolder) // handle files
{
set<CStdString> albums;
// Get album names found in directory
for (int i = 0; i < m_vecItems.Size(); i++)
{
CFileItem* pItem = m_vecItems[i];
if (pItem->m_musicInfoTag.Loaded() && !pItem->m_musicInfoTag.GetAlbum().IsEmpty())
{
CStdString strAlbum = pItem->m_musicInfoTag.GetAlbum();
albums.insert(strAlbum);
}
}
// the only album in this directory?
if (albums.size() == 1)
{
CStdString strAlbum = *albums.begin();
strLabel = strAlbum;
bSaveDirThumb = true;
}
}
}
else if (pItem->m_bIsFolder && g_musicDatabase.GetAlbumsByPath(strPath, albums))
{ // Normal folder, query database for albums in this directory
if (albums.size() == 1)
{
CAlbum& album = albums[0];
strLabel = album.strAlbum;
bSaveDirThumb = true;
}
else
{
// More then one album is found in this directory
// let the user choose
CGUIDialogSelect *pDlg = (CGUIDialogSelect*)m_gWindowManager.GetWindow(WINDOW_DIALOG_SELECT);
if (pDlg)
{
pDlg->SetHeading(181);
pDlg->Reset();
pDlg->EnableButton(false);
for (int i = 0; i < (int)albums.size(); ++i)
{
CAlbum& album = albums[i];
pDlg->Add(album.strAlbum);
}
pDlg->Sort();
pDlg->DoModal(GetID());
// and wait till user selects one
int iSelectedAlbum = pDlg->GetSelectedLabel();
if (iSelectedAlbum < 0)
{
if (m_dlgProgress) m_dlgProgress->Close();
return ;
}
strLabel = pDlg->GetSelectedLabelText();
}
}
bSaveDb = true;
}
else if (pItem->m_bIsFolder)
{
// No album name found for folder found in database. Look into
// the directory, but don't save albuminfo to database.
CFileItemList items;
GetDirectory(strPath, items);
OnRetrieveMusicInfo(items);
set<CStdString> albums;
// Get album names found in directory
for (int i = 0; i < items.Size(); i++)
{
CFileItem* pItem = items[i];
if (pItem->m_musicInfoTag.Loaded() && !pItem->m_musicInfoTag.GetAlbum().IsEmpty())
{
CStdString strAlbum = pItem->m_musicInfoTag.GetAlbum();
if (!strAlbum.IsEmpty())
albums.insert(strAlbum);
}
}
// no album found in folder use the
// item label, we may find something?
if (albums.size() == 0)
{
if (m_dlgProgress) m_dlgProgress->Close();
bSaveDirThumb = true;
}
if (albums.size() == 1)
{
CStdString strAlbum = *albums.begin();
strLabel = strAlbum;
bSaveDirThumb = true;
}
if (albums.size() > 1)
{
// More then one album is found in this directory
// let the user choose
CGUIDialogSelect *pDlg = (CGUIDialogSelect*)m_gWindowManager.GetWindow(WINDOW_DIALOG_SELECT);
if (pDlg)
{
pDlg->SetHeading(181);
pDlg->Reset();
pDlg->EnableButton(false);
for (set<CStdString>::iterator it = albums.begin(); it != albums.end(); it++)
{
CStdString strAlbum = *it;
pDlg->Add(strAlbum);
}
pDlg->Sort();
pDlg->DoModal(GetID());
// and wait till user selects one
int iSelectedAlbum = pDlg->GetSelectedLabel();
if (iSelectedAlbum < 0)
{
if (m_dlgProgress) m_dlgProgress->Close();
return ;
}
strLabel = pDlg->GetSelectedLabelText();
}
}
}
else
{
// single file, not in database
// get correct tag parser
CMusicInfoTagLoaderFactory factory;
auto_ptr<IMusicInfoTagLoader> pLoader (factory.CreateLoader(pItem->m_strPath));
if (NULL != pLoader.get())
{
// get id3tag
CMusicInfoTag& tag = pItem->m_musicInfoTag;
if ( pLoader->Load(pItem->m_strPath, tag))
{
// get album
CStdString strAlbum = tag.GetAlbum();
if (!strAlbum.IsEmpty())
{
strLabel = strAlbum;
}
}
}
}
if (m_dlgProgress) m_dlgProgress->Close();
ShowAlbumInfo(strLabel, strPath, bSaveDb, bSaveDirThumb, false);
}
void CGUIWindowMusicBase::ShowAlbumInfo(const CStdString& strAlbum, const CStdString& strPath, bool bSaveDb, bool bSaveDirThumb, bool bRefresh)
{
bool bUpdate = false;
// check cache
CAlbum albuminfo;
VECSONGS songs;
if (!bRefresh && g_musicDatabase.GetAlbumInfo(strAlbum, strPath, albuminfo, songs))
{
vector<CMusicSong> vecSongs;
for (int i = 0; i < (int)songs.size(); i++)
{
CSong& song = songs[i];
CMusicSong musicSong(song.iTrack, song.strTitle, song.iDuration);
vecSongs.push_back(musicSong);
}
CMusicAlbumInfo album;
album.Set(albuminfo);
album.SetSongs(vecSongs);
CGUIWindowMusicInfo *pDlgAlbumInfo = (CGUIWindowMusicInfo*)m_gWindowManager.GetWindow(WINDOW_MUSIC_INFO);
if (pDlgAlbumInfo)
{
pDlgAlbumInfo->SetAlbum(album);
pDlgAlbumInfo->DoModal(GetID());
if (!pDlgAlbumInfo->NeedRefresh()) return ;
bRefresh = true;
}
}
// If we are scanning for music info in the background,
// other writing access to the database is prohibited.
CGUIDialogMusicScan* dlgMusicScan = (CGUIDialogMusicScan*)m_gWindowManager.GetWindow(WINDOW_DIALOG_MUSIC_SCAN);
if (dlgMusicScan->IsRunning())
{
CGUIDialogOK *pDlg = (CGUIDialogOK*)m_gWindowManager.GetWindow(WINDOW_DIALOG_OK);
if (pDlg)
{
pDlg->SetHeading(189);
pDlg->SetLine(0, 14057);
pDlg->SetLine(1, "");
pDlg->SetLine(2, "");
pDlg->DoModal(GetID());
return ;
}
}
// find album info
CMusicAlbumInfo album;
if (FindAlbumInfo(strAlbum, album))
{
// download the album info
bool bLoaded = album.Loaded();
if ( bLoaded )
{
// set album title from musicinfotag, not the one we got from allmusic.com
album.SetTitle(strAlbum);
// set path, needed to store album in database
album.SetAlbumPath(strPath);
if (bSaveDb)
{
CAlbum albuminfo;
albuminfo.strAlbum = album.GetTitle();
albuminfo.strArtist = album.GetArtist();
albuminfo.strGenre = album.GetGenre();
albuminfo.strTones = album.GetTones();
albuminfo.strStyles = album.GetStyles();
albuminfo.strReview = album.GetReview();
albuminfo.strImage = album.GetImageURL();
albuminfo.iRating = album.GetRating();
albuminfo.iYear = atol( album.GetDateOfRelease().c_str() );
albuminfo.strPath = album.GetAlbumPath();
for (int i = 0; i < (int)album.GetNumberOfSongs(); i++)
{
CMusicSong musicSong = album.GetSong(i);
CSong song;
song.iTrack = musicSong.GetTrack();
song.strTitle = musicSong.GetSongName();
song.iDuration = musicSong.GetDuration();
songs.push_back(song);
}
// save to database
if (bRefresh)
g_musicDatabase.UpdateAlbumInfo(albuminfo, songs);
else
g_musicDatabase.AddAlbumInfo(albuminfo, songs);
}
if (m_dlgProgress)
m_dlgProgress->Close();
// ok, show album info
CGUIWindowMusicInfo *pDlgAlbumInfo = (CGUIWindowMusicInfo*)m_gWindowManager.GetWindow(WINDOW_MUSIC_INFO);
if (pDlgAlbumInfo)
{
pDlgAlbumInfo->SetAlbum(album);
pDlgAlbumInfo->DoModal(GetID());
// Save directory thumb
if (bSaveDirThumb)
{
CStdString strThumb;
CUtil::GetAlbumThumb(album.GetTitle(), album.GetAlbumPath(), strThumb);
// Was the download of the album art
// from allmusic.com successfull...
if (CUtil::FileExists(strThumb))
{
// ...yes...
CFileItem item(album.GetAlbumPath(), true);
if (!item.IsCDDA())
{
// ...also save a copy as directory thumb,
// if the album isn't located on an audio cd
CStdString strFolderThumb;
CUtil::GetAlbumFolderThumb(album.GetAlbumPath(), strFolderThumb);
::CopyFile(strThumb, strFolderThumb, false);
}
}
}
if (pDlgAlbumInfo->NeedRefresh())
{
ShowAlbumInfo(strAlbum, strPath, bSaveDb, bSaveDirThumb, true);
return ;
}
}
bUpdate = true;
}
else
{
// failed 2 download album info
CGUIDialogOK* pDlgOK = (CGUIDialogOK*)m_gWindowManager.GetWindow(WINDOW_DIALOG_OK);
if (pDlgOK)
{
pDlgOK->SetHeading(185);
pDlgOK->SetLine(0, L"");
pDlgOK->SetLine(1, 500);
pDlgOK->SetLine(2, L"");
pDlgOK->DoModal(GetID());
}
}
}
if (bUpdate)
{
int iSelectedItem = m_viewControl.GetSelectedItem();
if (iSelectedItem >= 0 && m_vecItems[iSelectedItem] && m_vecItems[iSelectedItem]->m_bIsFolder)
{
// refresh only the icon of
// the current folder
m_vecItems[iSelectedItem]->FreeIcons();
m_vecItems[iSelectedItem]->SetMusicThumb();
m_vecItems[iSelectedItem]->FillInDefaultIcon();
}
else
{
// Refresh all items
for (int i = 0; i < m_vecItems.Size(); ++i)
{
CFileItem* pItem = m_vecItems[i];
pItem->FreeIcons();
}
m_vecItems.SetMusicThumbs();
m_vecItems.FillInDefaultIcons();
}
// HACK: If we are in files view
// autoswitch between list/thumb control
if (GetID() == WINDOW_MUSIC_FILES && !m_Directory.IsVirtualDirectoryRoot() && g_guiSettings.GetBool("MusicLists.UseAutoSwitching"))
{
m_iViewAsIcons = CAutoSwitch::GetView(m_vecItems);
m_viewControl.SetCurrentView(m_iViewAsIcons);
UpdateButtons();
}
}
if (m_dlgProgress)
m_dlgProgress->Close();
}
/// \brief Can be overwritten to implement an own tag filling function.
/// \param items File items to fill
void CGUIWindowMusicBase::OnRetrieveMusicInfo(CFileItemList& items)
{
}
/// \brief Retrieve tag information for \e m_vecItems
void CGUIWindowMusicBase::RetrieveMusicInfo()
{
DWORD dwTick = timeGetTime();
OnRetrieveMusicInfo(m_vecItems);
dwTick = timeGetTime() - dwTick;
CStdString strTmp;
strTmp.Format("RetrieveMusicInfo() took %imsec\n", dwTick);
OutputDebugString(strTmp.c_str());
}
/// \brief Add selected list/thumb control item to playlist and start playing
/// \param iItem Selected Item in list/thumb control
void CGUIWindowMusicBase::OnQueueItem(int iItem)
{
if ( iItem < 0 || iItem >= m_vecItems.Size() ) return ;
int iOldSize=g_playlistPlayer.GetPlaylist(PLAYLIST_MUSIC).size();
// add item 2 playlist
const CFileItem* pItem = m_vecItems[iItem];
AddItemToPlayList(pItem);
//move to next item
m_viewControl.SetSelectedItem(iItem + 1);
if (g_playlistPlayer.GetPlaylist(PLAYLIST_MUSIC).size() && !g_application.IsPlayingAudio() )
{
g_playlistPlayer.Reset();
g_playlistPlayer.SetCurrentPlaylist(PLAYLIST_MUSIC);
if (g_playlistPlayer.ShuffledPlay(PLAYLIST_MUSIC))
{
// if shuffled dont start on first song
g_playlistPlayer.SetCurrentSong(0);
g_playlistPlayer.PlayNext();
}
else
g_playlistPlayer.Play(iOldSize); // Start playlist with the first new song added
}
}
/// \brief Add file or folder and its subfolders to playlist
/// \param pItem The file item to add
void CGUIWindowMusicBase::AddItemToPlayList(const CFileItem* pItem)
{
if (pItem->m_bIsFolder)
{
// Check if we add a locked share
if ( pItem->m_bIsShareOrDrive )
{
CFileItem item = *pItem;
if ( !g_passwordManager.IsItemUnlocked( &item, "music" ) )
return ;
}
// recursive
if (pItem->GetLabel() == "..") return ;
CStdString strDirectory = m_Directory.m_strPath;
m_Directory.m_strPath = pItem->m_strPath;
CFileItemList items;
GetDirectory(m_Directory.m_strPath, items);
DoSort(items);
for (int i = 0; i < items.Size(); ++i)
{
AddItemToPlayList(items[i]);
}
m_Directory.m_strPath = strDirectory;
}
else
{
if (!pItem->IsNFO() && pItem->IsAudio() && !pItem->IsPlayList())
{
CPlayList::CPlayListItem playlistItem;
CUtil::ConvertFileItemToPlayListItem(pItem, playlistItem);
g_playlistPlayer.GetPlaylist( PLAYLIST_MUSIC ).Add(playlistItem);
}
}
}
/// \brief Make the actual search for the OnSearch function.
/// \param strSearch The search string
/// \param items Items Found
void CGUIWindowMusicBase::DoSearch(const CStdString& strSearch, CFileItemList& items)
{
}
/// \brief Search the current directory for a string got from the virtual keyboard
void CGUIWindowMusicBase::OnSearch()
{
CStdString strSearch;
if ( !GetKeyboard(strSearch) )
return ;
strSearch.ToLower();
if (m_dlgProgress)
{
m_dlgProgress->SetHeading(194);
m_dlgProgress->SetLine(0, strSearch);
m_dlgProgress->SetLine(1, L"");
m_dlgProgress->SetLine(2, L"");
m_dlgProgress->StartModal(GetID());
m_dlgProgress->Progress();
}
CFileItemList items;
DoSearch(strSearch, items);
if (items.Size())
{
CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)m_gWindowManager.GetWindow(WINDOW_DIALOG_SELECT);
pDlgSelect->Reset();
pDlgSelect->SetHeading(283);
CUtil::SortFileItemsByName(items);
for (int i = 0; i < (int)items.Size(); i++)
{
CFileItem* pItem = items[i];
pDlgSelect->Add(pItem->GetLabel());
}
pDlgSelect->DoModal(GetID());
int iItem = pDlgSelect->GetSelectedLabel();
if (iItem < 0)
{
if (m_dlgProgress) m_dlgProgress->Close();
return ;
}
CFileItem* pSelItem = new CFileItem(*items[iItem]);
OnSearchItemFound(pSelItem);
delete pSelItem;
if (m_dlgProgress) m_dlgProgress->Close();
}
else
{
if (m_dlgProgress) m_dlgProgress->Close();
CGUIDialogOK* dlg = (CGUIDialogOK*)m_gWindowManager.GetWindow(WINDOW_DIALOG_OK);
if (dlg)
{
dlg->SetHeading( 194 );
dlg->SetLine( 0, 284 );
dlg->SetLine( 1, L"" );
dlg->SetLine( 2, L"" );
dlg->DoModal( GetID() );
}
}
}
/// \brief Display virtual keyboard
/// \param strInput Set as defaultstring in keyboard and retrieves the input from keyboard
bool CGUIWindowMusicBase::GetKeyboard(CStdString& strInput)
{
CGUIDialogKeyboard *pKeyboard = (CGUIDialogKeyboard*)m_gWindowManager.GetWindow(WINDOW_DIALOG_KEYBOARD);
if (!pKeyboard) return false;
// setup keyboard
pKeyboard->CenterWindow();
pKeyboard->SetText(strInput);
pKeyboard->DoModal(m_gWindowManager.GetActiveWindow());
pKeyboard->Close();
if (pKeyboard->IsDirty())
{ // have text - update this.
strInput = pKeyboard->GetText();
if (strInput.IsEmpty())
return false;
return true;
}
return false;
}
/// \brief Can be overwritten to build an own history string for \c m_history
/// \param pItem Item to build the history string from
/// \param strHistoryString History string build as return value
void CGUIWindowMusicBase::GetDirectoryHistoryString(const CFileItem* pItem, CStdString& strHistoryString)
{
strHistoryString = pItem->m_strPath;
if (CUtil::HasSlashAtEnd(strHistoryString))
strHistoryString.Delete(strHistoryString.size() - 1);
}
void CGUIWindowMusicBase::UpdateButtons()
{
// Update window selection control
// Remove labels from the window selection
CGUIMessage msg(GUI_MSG_LABEL_RESET, GetID(), CONTROL_BTNTYPE);
g_graphicsContext.SendMessage(msg);
// Add labels to the window selection
CStdString strItem = g_localizeStrings.Get(744); // Files
CGUIMessage msg2(GUI_MSG_LABEL_ADD, GetID(), CONTROL_BTNTYPE);
msg2.SetLabel(strItem);
g_graphicsContext.SendMessage(msg2);
strItem = g_localizeStrings.Get(15100); // Library
msg2.SetLabel(strItem);
g_graphicsContext.SendMessage(msg2);
strItem = g_localizeStrings.Get(271); // Top 100
msg2.SetLabel(strItem);
g_graphicsContext.SendMessage(msg2);
// Select the current window as default item
CONTROL_SELECT_ITEM(CONTROL_BTNTYPE, g_stSettings.m_iMyMusicStartWindow - WINDOW_MUSIC_FILES);
}
/// \brief React on the selected search item
/// \param pItem Search result item
void CGUIWindowMusicBase::OnSearchItemFound(const CFileItem* pItem)
{
}
bool CGUIWindowMusicBase::FindAlbumInfo(const CStdString& strAlbum, CMusicAlbumInfo& album)
{
// quietly return if Internet lookups are disabled
if (!g_guiSettings.GetBool("Network.EnableInternet")) return false;
CGUIDialogOK* pDlgOK = (CGUIDialogOK*)m_gWindowManager.GetWindow(WINDOW_DIALOG_OK);
// show dialog box indicating we're searching the album
if (m_dlgProgress)
{
m_dlgProgress->SetHeading(185);
m_dlgProgress->SetLine(0, strAlbum);
m_dlgProgress->SetLine(1, "");
m_dlgProgress->SetLine(2, "");
m_dlgProgress->StartModal(GetID());
}
try
{
CMusicInfoScraper scraper;
scraper.FindAlbuminfo(strAlbum);
while (!scraper.Completed())
{
if (m_dlgProgress)
{
if (m_dlgProgress->IsCanceled())
scraper.Cancel();
m_dlgProgress->Progress();
}
}
if (scraper.Successfull())
{
// did we found at least 1 album?
int iAlbumCount = scraper.GetAlbumCount();
if (iAlbumCount >= 1)
{
//yes
// if we found more then 1 album, let user choose one
int iSelectedAlbum = 0;
if (iAlbumCount > 1)
{
//show dialog with all albums found
const WCHAR* szText = g_localizeStrings.Get(181).c_str();
CGUIDialogSelect *pDlg = (CGUIDialogSelect*)m_gWindowManager.GetWindow(WINDOW_DIALOG_SELECT);
if (pDlg)
{
pDlg->SetHeading(szText);
pDlg->Reset();
pDlg->EnableButton(true);
pDlg->SetButtonLabel(413); // manual
for (int i = 0; i < iAlbumCount; ++i)
{
CMusicAlbumInfo& info = scraper.GetAlbum(i);
pDlg->Add(info.GetTitle2());
}
pDlg->DoModal(GetID());
// and wait till user selects one
iSelectedAlbum = pDlg->GetSelectedLabel();
if (iSelectedAlbum < 0)
{
if (!pDlg->IsButtonPressed()) return false;
CStdString strNewAlbum = strAlbum;
if (!GetKeyboard(strNewAlbum)) return false;
if (strNewAlbum == "") return false;
if (m_dlgProgress)
{
m_dlgProgress->SetLine(0, strNewAlbum);
m_dlgProgress->Progress();
}
return FindAlbumInfo(strNewAlbum, album);
}
}
}
// ok, downloading the album info
scraper.LoadAlbuminfo(iSelectedAlbum);
while (!scraper.Completed())
{
if (m_dlgProgress)
{
if (m_dlgProgress->IsCanceled())
scraper.Cancel();
m_dlgProgress->Progress();
}
}
if (scraper.Successfull())
album = scraper.GetAlbum(iSelectedAlbum);
return scraper.Successfull();
}
else
{
// no albums found
if (pDlgOK)
{
pDlgOK->SetHeading(185);
pDlgOK->SetLine(0, L"");
pDlgOK->SetLine(1, 187);
pDlgOK->SetLine(2, L"");
pDlgOK->DoModal(GetID());
}
}
}
if (!scraper.IsCanceled())
{
// unable 2 connect to www.allmusic.com
if (pDlgOK)
{
pDlgOK->SetHeading(185);
pDlgOK->SetLine(0, L"");
pDlgOK->SetLine(1, 499);
pDlgOK->SetLine(2, L"");
pDlgOK->DoModal(GetID());
}
}
}
catch (...)
{
if (m_dlgProgress && m_dlgProgress->IsRunning())
m_dlgProgress->Close();
CLog::Log(LOGERROR, "Exception while downloading album info");
}
return false;
}
void CGUIWindowMusicBase::DisplayEmptyDatabaseMessage(bool bDisplay)
{
m_bDisplayEmptyDatabaseMessage = bDisplay;
}
void CGUIWindowMusicBase::Render()
{
CGUIWindow::Render();
if (m_bDisplayEmptyDatabaseMessage)
{
CGUIListControl *pControl = (CGUIListControl *)GetControl(CONTROL_LIST);
int iX = pControl->GetXPosition() + pControl->GetWidth() / 2;
int iY = pControl->GetYPosition() + pControl->GetHeight() / 2;
CGUIFont *pFont = g_fontManager.GetFont(pControl->GetFontName());
if (pFont)
{
float fWidth, fHeight;
CStdStringW wszText = g_localizeStrings.Get(745); // "No scanned information for this view"
CStdStringW wszText2 = g_localizeStrings.Get(746); // "Switch back to Files view"
pFont->GetTextExtent(wszText, &fWidth, &fHeight);
pFont->DrawText((float)iX, (float)iY - fHeight, 0xffffffff, wszText.c_str(), XBFONT_CENTER_X | XBFONT_CENTER_Y);
pFont->DrawText((float)iX, (float)iY + fHeight, 0xffffffff, wszText2.c_str(), XBFONT_CENTER_X | XBFONT_CENTER_Y);
}
}
}
void CGUIWindowMusicBase::OnPopupMenu(int iItem)
{
if ( iItem < 0 || iItem >= m_vecItems.Size() ) return ;
// calculate our position
int iPosX = 200;
int iPosY = 100;
CGUIListControl *pList = (CGUIListControl *)GetControl(CONTROL_LIST);
if (pList)
{
iPosX = pList->GetXPosition() + pList->GetWidth() / 2;
iPosY = pList->GetYPosition() + pList->GetHeight() / 2;
}
// mark the item
bool bSelected = m_vecItems[iItem]->IsSelected(); // item maybe selected (playlistitem)
m_vecItems[iItem]->Select(true);
// popup the context menu
CGUIDialogContextMenu *pMenu = (CGUIDialogContextMenu *)m_gWindowManager.GetWindow(WINDOW_DIALOG_CONTEXT_MENU);
if (!pMenu) return ;
// clean any buttons not needed
pMenu->ClearButtons();
// add the needed buttons
pMenu->AddButton(13351); // 1: Music Information
pMenu->AddButton(13347); // 2: Queue Item
pMenu->AddButton(13358); // 3: Play Item
pMenu->AddButton(13350); // 4: Now Playing...
pMenu->AddButton(137); // 5: Search...
if (g_application.m_guiDialogMusicScan.IsRunning())
pMenu->AddButton(13353); // 6: Stop Scanning
else
pMenu->AddButton(13352); // 6: Scan Folder to Database
pMenu->AddButton(600); // 7: Rip CD Audio
pMenu->AddButton(5); // 8: Settings...
// turn off info/queue/play if the current item is goto parent ..
bool bIsGotoParent = m_vecItems[iItem]->GetLabel() == "..";
if (bIsGotoParent)
{
pMenu->EnableButton(1, false);
pMenu->EnableButton(2, false);
pMenu->EnableButton(3, false);
}
// turn off the now playing button if nothing is playing
if (!g_application.IsPlayingAudio())
pMenu->EnableButton(4, false);
// turn off the Scan button if we're not in files view or a internet stream
if (GetID() != WINDOW_MUSIC_FILES || m_Directory.IsInternetStream())
pMenu->EnableButton(6, false);
// turn off Rip CD Audio button if we don't have a CDDA disk in
CCdInfo *pCdInfo = CDetectDVDMedia::GetCdInfo();
if (!CDetectDVDMedia::IsDiscInDrive() || !pCdInfo || !pCdInfo->IsAudio(1))
pMenu->EnableButton(7, false);
// position it correctly
pMenu->SetPosition(iPosX - pMenu->GetWidth() / 2, iPosY - pMenu->GetHeight() / 2);
pMenu->DoModal(GetID());
switch (pMenu->GetButton())
{
case 1: // Music Information
OnInfo(iItem);
break;
case 2: // Queue Item
OnQueueItem(iItem);
break;
case 3: // Play Item
PlayItem(iItem);
break;
case 4: // Now Playing...
m_gWindowManager.ActivateWindow(WINDOW_MUSIC_PLAYLIST);
return;
break;
case 5: // Search
OnSearch();
break;
case 6: // Scan...
OnScan();
break;
case 7: // Rip CD...
OnRipCD();
break;
case 8: // Settings
m_gWindowManager.ActivateWindow(WINDOW_SETTINGS_MYMUSIC);
return;
break;
}
m_vecItems[iItem]->Select(bSelected);
}
void CGUIWindowMusicBase::OnRipCD()
{
CCdInfo *pCdInfo = CDetectDVDMedia::GetCdInfo();
if (CDetectDVDMedia::IsDiscInDrive() && pCdInfo && pCdInfo->IsAudio(1))
{
if (!g_application.CurrentFileItem().IsCDDA())
{
CCDDARipper ripper;
ripper.RipCD();
}
else
{
CGUIDialogOK* pDlgOK = (CGUIDialogOK*)m_gWindowManager.GetWindow(WINDOW_DIALOG_OK);
pDlgOK->SetHeading(257); // Error
pDlgOK->SetLine(0, "Can't rip CD or Track while playing from CD"); //
pDlgOK->SetLine(1, ""); //
pDlgOK->SetLine(2, "");
pDlgOK->DoModal(GetID());
}
}
}
void CGUIWindowMusicBase::SetLabelFromTag(CFileItem *pItem)
{
CStdString strLabel = ParseFormat(pItem, g_guiSettings.GetString("MusicLists.TrackFormat"));
CStdString strLabel2 = ParseFormat(pItem, g_guiSettings.GetString("MusicLists.TrackFormatRight"));
// set label 1
// if we don't have anything at the moment (due to empty tags),
// we just remove the extension
if (strLabel.size())
pItem->SetLabel(strLabel);
else if (g_guiSettings.GetBool("FileLists.HideExtensions"))
pItem->RemoveExtension();
// set label 2
if (strLabel2.size())
pItem->SetLabel2(strLabel2);
}
CStdString CGUIWindowMusicBase::ParseFormat(CFileItem *pItem, const CStdString& strFormat)
{
CStdString strLabel = "";
CMusicInfoTag& tag = pItem->m_musicInfoTag;
int iPos1 = 0;
int iPos2 = strFormat.Find('%', iPos1);
bool bDoneSomething = !(iPos1 == iPos2); // stuff in front should be applied - everything using this bool is added by spiff
while (iPos2 >= 0)
{
if( (iPos2 > iPos1) && bDoneSomething )
{
strLabel += strFormat.Mid(iPos1, iPos2 - iPos1);
bDoneSomething = false;
}
CStdString str;
if (strFormat[iPos2 + 1] == 'N' && tag.GetTrackNumber() > 0)
{ // number
str.Format("%02.2i", tag.GetTrackNumber());
bDoneSomething = true;
}
else if (strFormat[iPos2 + 1] == 'A' && tag.GetArtist().size())
{ // artist
str = tag.GetArtist();
bDoneSomething = true;
}
else if (strFormat[iPos2 + 1] == 'T' && tag.GetTitle().size())
{ // title
str = tag.GetTitle();
bDoneSomething = true;
}
else if (strFormat[iPos2 + 1] == 'B' && tag.GetAlbum().size())
{ // album
str = tag.GetAlbum();
bDoneSomething = true;
}
else if (strFormat[iPos2 + 1] == 'G' && tag.GetGenre().size())
{ // genre
str = tag.GetGenre();
bDoneSomething = true;
}
else if (strFormat[iPos2 + 1] == 'Y')
{ // year
str = tag.GetYear();
bDoneSomething = true;
}
else if (strFormat[iPos2 + 1] == 'F')
{ // filename
str = CUtil::GetTitleFromPath(pItem->m_strPath);
bDoneSomething = true;
}
else if (strFormat[iPos2 + 1] == 'D' && tag.GetDuration() > 0)
{ // duration
int nDuration = tag.GetDuration();
CUtil::SecondsToHMSString(nDuration, str);
bDoneSomething = true;
}
else if (strFormat[iPos2 + 1] == '%')
{ // %% to print %
str = '%';
bDoneSomething = true;
}
strLabel += str;
iPos1 = iPos2 + 2;
iPos2 = strFormat.Find('%', iPos1);
}
if (iPos1 < (int)strFormat.size())
strLabel += strFormat.Right(strFormat.size() - iPos1);
return strLabel;
}
void CGUIWindowMusicBase::AddItemToTempPlayList(const CFileItem* pItem)
{
if (pItem->m_bIsFolder)
{
// Check if we add a locked share
if ( pItem->m_bIsShareOrDrive )
{
CFileItem item = *pItem;
if ( !g_passwordManager.IsItemUnlocked( &item, "music" ) )
return ;
}
// recursive
if (pItem->GetLabel() == "..") return ;
CStdString strDirectory = m_Directory.m_strPath;
m_Directory.m_strPath = pItem->m_strPath;
CFileItemList items;
GetDirectory(m_Directory.m_strPath, items);
DoSort(items);
for (int i = 0; i < items.Size(); ++i)
{
AddItemToTempPlayList(items[i]);
}
m_Directory.m_strPath = strDirectory;
}
else
{
if (!pItem->IsNFO() && pItem->IsAudio() && !pItem->IsPlayList())
{
CPlayList::CPlayListItem playlistItem;
CUtil::ConvertFileItemToPlayListItem(pItem, playlistItem);
g_playlistPlayer.GetPlaylist(PLAYLIST_MUSIC_TEMP).Add(playlistItem);
}
}
}
void CGUIWindowMusicBase::PlayItem(int iItem)
{
// restrictions should be placed in the appropiate window code
// only call the base code if the item passes since this clears
// the currently playing temp playlist
const CFileItem* pItem = m_vecItems[iItem];
// if its a folder, build a temp playlist
if (pItem->m_bIsFolder)
{
// skip ".."
if (pItem->GetLabel() == "..")
return;
// clear current temp playlist
g_playlistPlayer.GetPlaylist(PLAYLIST_MUSIC_TEMP).Clear();
g_playlistPlayer.Reset();
// recursively add items to temp playlist
AddItemToTempPlayList(pItem);
// play!
g_playlistPlayer.SetCurrentPlaylist(PLAYLIST_MUSIC_TEMP);
if (g_playlistPlayer.ShuffledPlay(PLAYLIST_MUSIC_TEMP))
{
// if shuffled dont start on first song
g_playlistPlayer.SetCurrentSong(0);
g_playlistPlayer.PlayNext();
}
else
g_playlistPlayer.Play(0);
}
// otherwise just play the song
else
{
OnClick(iItem);
}
}
|