Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[7475bc]: xbmc / GUIWindowMusicBase.cpp Maximize Restore History

Repo status: analyzing...

Download this file

GUIWindowMusicBase.cpp    1400 lines (1234 with data), 43.8 kB

   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
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* 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, 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 XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "system.h"
#include "GUIUserMessages.h"
#include "GUIWindowMusicBase.h"
#include "GUIWindowMusicInfo.h"
#include "FileSystem/ZipManager.h"
#ifdef HAS_FILESYSTEM_DAAP
#include "FileSystem/DAAPDirectory.h"
#endif
#include "PlayListFactory.h"
#include "Util.h"
#include "PlayListM3U.h"
#include "Application.h"
#include "PlayListPlayer.h"
#include "FileSystem/DirectoryCache.h"
#ifdef HAS_CDDA_RIPPER
#include "cdrip/CDDARipper.h"
#endif
#include "GUIPassword.h"
#include "GUIDialogMusicScan.h"
#include "GUIDialogMediaSource.h"
#include "PartyModeManager.h"
#include "utils/GUIInfoManager.h"
#include "FileSystem/MusicDatabaseDirectory.h"
#include "GUIDialogSongInfo.h"
#include "GUIDialogSmartPlaylistEditor.h"
#include "LastFmManager.h"
#include "MusicInfoTag.h"
#include "GUIWindowManager.h"
#include "GUIDialogOK.h"
#include "GUIDialogKeyboard.h"
#include "GUIDialogProgress.h"
#include "FileItem.h"
#include "FileSystem/File.h"
#include "MediaManager.h"
#include "Settings.h"
#include "AdvancedSettings.h"
#include "GUISettings.h"
#include "LocalizeStrings.h"
#include "utils/TimeUtils.h"
#include "utils/log.h"
using namespace std;
using namespace XFILE;
using namespace MUSICDATABASEDIRECTORY;
using namespace PLAYLIST;
using namespace MUSIC_GRABBER;
using namespace MUSIC_INFO;
#define CONTROL_BTNVIEWASICONS 2
#define CONTROL_BTNSORTBY 3
#define CONTROL_BTNSORTASC 4
#define CONTROL_BTNTYPE 5
CGUIWindowMusicBase::CGUIWindowMusicBase(int id, const CStdString &xmlFile)
: CGUIMediaWindow(id, xmlFile)
{
}
CGUIWindowMusicBase::~CGUIWindowMusicBase ()
{
}
/// \brief Handle actions on window.
/// \param action Action that can be reacted on.
bool CGUIWindowMusicBase::OnAction(const CAction& action)
{
if (action.GetID() == ACTION_PREVIOUS_MENU)
{
CGUIDialogMusicScan *musicScan = (CGUIDialogMusicScan *)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_SCAN);
if (musicScan && !musicScan->IsDialogRunning())
{
CUtil::ThumbCacheClear();
CUtil::RemoveTempFiles();
}
}
if (action.GetID() == ACTION_SHOW_PLAYLIST)
{
g_windowManager.ActivateWindow(WINDOW_MUSIC_PLAYLIST);
return true;
}
return CGUIMediaWindow::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_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:
- The container controls\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_WINDOW_DEINIT:
{
m_musicdatabase.Close();
}
break;
case GUI_MSG_WINDOW_INIT:
{
m_dlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
m_musicdatabase.Open();
if (!CGUIMediaWindow::OnMessage(message))
return false;
// save current window, unless the current window is the music playlist window
if (GetID() != WINDOW_MUSIC_PLAYLIST &&
g_settings.m_iMyMusicStartWindow != GetID())
{
g_settings.m_iMyMusicStartWindow = GetID();
g_settings.Save();
}
return true;
}
break;
// update the display
case GUI_MSG_SCAN_FINISHED:
case GUI_MSG_REFRESH_THUMBS:
{
Update(m_vecItems->m_strPath);
}
break;
case GUI_MSG_CLICKED:
{
int iControl = message.GetSenderId();
if (iControl == CONTROL_BTNTYPE)
{
CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), CONTROL_BTNTYPE);
g_windowManager.SendMessage(msg);
int nWindow = WINDOW_MUSIC_FILES + msg.GetParam1();
if (nWindow == GetID())
return true;
g_settings.m_iMyMusicStartWindow = nWindow;
g_settings.Save();
g_windowManager.ChangeActiveWindow(nWindow);
CGUIMessage msg2(GUI_MSG_SETFOCUS, g_settings.m_iMyMusicStartWindow, CONTROL_BTNTYPE);
g_windowManager.SendMessage(msg2);
return true;
}
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_SHOW_INFO)
{
OnInfo(iItem);
}
else if (iAction == ACTION_DELETE_ITEM)
{
// is delete allowed?
// must be at the playlists directory
if (m_vecItems->m_strPath.Equals("special://musicplaylists/"))
OnDeleteItem(iItem);
// or be at the files window and have file deletion enabled
else if (GetID() == WINDOW_MUSIC_FILES &&
g_guiSettings.GetBool("filelists.allowfiledeletion"))
{
OnDeleteItem(iItem);
}
else
return false;
}
// 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);
return true;
}
}
}
}
return CGUIMediaWindow::OnMessage(message);
}
void CGUIWindowMusicBase::OnInfoAll(int iItem, bool bCurrent)
{
CGUIDialogMusicScan* musicScan = (CGUIDialogMusicScan *)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_SCAN);
CMusicDatabaseDirectory dir;
CStdString strPath = m_vecItems->m_strPath;
if (bCurrent)
strPath = m_vecItems->Get(iItem)->m_strPath;
if (dir.HasAlbumInfo(m_vecItems->Get(iItem)->m_strPath))
musicScan->StartAlbumScan(strPath);
else
musicScan->StartArtistScan(strPath);
}
/// \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, bool bShowInfo)
{
if ( iItem < 0 || iItem >= m_vecItems->Size() )
return;
CFileItemPtr item = m_vecItems->Get(iItem);
if (item->IsVideoDb())
{ // music video
OnContextButton(iItem, CONTEXT_BUTTON_INFO);
return;
}
OnInfo(item.get(), bShowInfo);
}
void CGUIWindowMusicBase::OnInfo(CFileItem *pItem, bool bShowInfo)
{
if ((pItem->IsMusicDb() && !pItem->HasMusicInfoTag()) || pItem->IsParentFolder() ||
CUtil::IsSpecial(pItem->m_strPath) || pItem->m_strPath.Left(14).Equals("musicsearch://"))
return; // nothing to do
if (!pItem->m_bIsFolder)
{ // song lookup
ShowSongInfo(pItem);
return;
}
CStdString strPath = pItem->m_strPath;
// Try to find an album to lookup from the current item
CAlbum album;
CArtist artist;
bool foundAlbum = false;
album.idAlbum = -1;
// we have a folder
if (pItem->IsMusicDb())
{
CQueryParams params;
CDirectoryNode::GetDatabaseInfo(pItem->m_strPath, params);
if (params.GetAlbumId() == -1)
{ // artist lookup
artist.idArtist = params.GetArtistId();
artist.strArtist = pItem->GetMusicInfoTag()->GetArtist();
}
else
{ // album lookup
album.idAlbum = params.GetAlbumId();
album.strAlbum = pItem->GetMusicInfoTag()->GetAlbum();
album.strArtist = pItem->GetMusicInfoTag()->GetArtist();
// we're going to need it's path as well (we assume that there's only one) - this is for
// assigning thumbs to folders, and obtaining the local folder.jpg
m_musicdatabase.GetAlbumPath(album.idAlbum, strPath);
}
}
else
{ // from filemode, so find the albums in the folder
CFileItemList items;
GetDirectory(strPath, items);
// show dialog box indicating we're searching the album name
if (m_dlgProgress && bShowInfo)
{
m_dlgProgress->SetHeading(185);
m_dlgProgress->SetLine(0, 501);
m_dlgProgress->SetLine(1, "");
m_dlgProgress->SetLine(2, "");
m_dlgProgress->StartModal();
m_dlgProgress->Progress();
if (m_dlgProgress->IsCanceled())
return;
}
// check the first song we find in the folder, and grab it's album info
for (int i = 0; i < items.Size() && !foundAlbum; i++)
{
CFileItemPtr pItem = items[i];
pItem->LoadMusicTag();
if (pItem->HasMusicInfoTag() && pItem->GetMusicInfoTag()->Loaded() &&
!pItem->GetMusicInfoTag()->GetAlbum().IsEmpty())
{
// great, have a song - use it.
CSong song(*pItem->GetMusicInfoTag());
// this function won't be needed if/when the tag has idSong information
if (!m_musicdatabase.GetAlbumFromSong(song, album))
{ // album isn't in the database - construct it from the tag info we have
CMusicInfoTag *tag = pItem->GetMusicInfoTag();
album.strAlbum = tag->GetAlbum();
album.strArtist = tag->GetAlbumArtist().IsEmpty() ? tag->GetArtist() : tag->GetAlbumArtist();
album.idAlbum = -1; // the -1 indicates it's not in the database
}
foundAlbum = true;
}
}
if (!foundAlbum)
{
CLog::Log(LOGINFO, "%s called on a folder containing no songs with tag info - nothing can be done", __FUNCTION__);
if (m_dlgProgress && bShowInfo)
m_dlgProgress->Close();
return;
}
if (m_dlgProgress && bShowInfo)
m_dlgProgress->Close();
}
if (album.idAlbum == -1 && foundAlbum == false)
ShowArtistInfo(artist, pItem->m_strPath, false, bShowInfo);
else
ShowAlbumInfo(album, strPath, false, bShowInfo);
}
void CGUIWindowMusicBase::OnManualAlbumInfo()
{
CAlbum album;
album.idAlbum = -1; // not in the db
if (!CGUIDialogKeyboard::ShowAndGetInput(album.strAlbum, g_localizeStrings.Get(16011), false))
return;
CStdString strNewArtist = "";
if (!CGUIDialogKeyboard::ShowAndGetInput(album.strArtist, g_localizeStrings.Get(16025), false))
return;
ShowAlbumInfo(album,"",true);
}
void CGUIWindowMusicBase::ShowArtistInfo(const CArtist& artist, const CStdString& path, bool bRefresh, bool bShowInfo)
{
bool saveDb = artist.idArtist != -1;
if (!g_settings.GetCurrentProfile().canWriteDatabases() && !g_passwordManager.bMasterUser)
saveDb = false;
// check cache
CArtist artistInfo;
artistInfo.strArtist = artist.strArtist;
if (m_musicdatabase.GetArtistInfo(artist.idArtist, artistInfo) && !bShowInfo)
return;
CGUIWindowMusicInfo *pDlgAlbumInfo = (CGUIWindowMusicInfo*)g_windowManager.GetWindow(WINDOW_MUSIC_INFO);
if (pDlgAlbumInfo && !bRefresh)
{
pDlgAlbumInfo->SetArtist(artistInfo, path);
if (bShowInfo)
pDlgAlbumInfo->DoModal();
else
pDlgAlbumInfo->RefreshThumb(); // downloads the thumb if we don't already have one
if (!pDlgAlbumInfo->NeedRefresh())
{
if (pDlgAlbumInfo->HasUpdatedThumb())
Update(m_vecItems->m_strPath);
return;
}
bRefresh = true;
m_musicdatabase.DeleteArtistInfo(artistInfo.idArtist);
}
// If we are scanning for music info in the background,
// other writing access to the database is prohibited.
CGUIDialogMusicScan* dlgMusicScan = (CGUIDialogMusicScan*)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_SCAN);
if (dlgMusicScan->IsDialogRunning())
{
CGUIDialogOK::ShowAndGetInput(189, 14057, 0, 0);
return;
}
CMusicArtistInfo info;
if (FindArtistInfo(artist.strArtist, info, bShowInfo ? (bRefresh ? SELECTION_FORCED : SELECTION_ALLOWED) : SELECTION_AUTO))
{
// download the album info
if ( info.Loaded() )
{
if (saveDb)
{
// save to database
m_musicdatabase.SetArtistInfo(artist.idArtist, info.GetArtist());
}
if (m_dlgProgress && bShowInfo)
m_dlgProgress->Close();
// ok, show album info
CGUIWindowMusicInfo *pDlgAlbumInfo = (CGUIWindowMusicInfo*)g_windowManager.GetWindow(WINDOW_MUSIC_INFO);
if (pDlgAlbumInfo)
{
pDlgAlbumInfo->SetArtist(info.GetArtist(), path);
if (bShowInfo)
pDlgAlbumInfo->DoModal();
else
pDlgAlbumInfo->RefreshThumb(); // downloads the thumb if we don't already have one
CArtist artistInfo = info.GetArtist();
artistInfo.idArtist = artist.idArtist;
/*
if (pDlgAlbumInfo->HasUpdatedThumb())
UpdateThumb(artistInfo, path);
*/
// just update for now
Update(m_vecItems->m_strPath);
if (pDlgAlbumInfo->NeedRefresh())
{
m_musicdatabase.DeleteArtistInfo(artistInfo.idArtist);
ShowArtistInfo(artist, path, true, bShowInfo);
return;
}
}
}
else
{
// failed 2 download album info
CGUIDialogOK::ShowAndGetInput(21889, 0, 20199, 0);
}
}
if (m_dlgProgress && bShowInfo)
m_dlgProgress->Close();
}
void CGUIWindowMusicBase::ShowAlbumInfo(const CAlbum& album, const CStdString& path, bool bRefresh, bool bShowInfo)
{
bool saveDb = album.idAlbum != -1;
if (!g_settings.GetCurrentProfile().canWriteDatabases() && !g_passwordManager.bMasterUser)
saveDb = false;
// check cache
CAlbum albumInfo;
if (!bRefresh && m_musicdatabase.GetAlbumInfo(album.idAlbum, albumInfo, &albumInfo.songs))
{
if (!bShowInfo)
return;
CGUIWindowMusicInfo *pDlgAlbumInfo = (CGUIWindowMusicInfo*)g_windowManager.GetWindow(WINDOW_MUSIC_INFO);
if (pDlgAlbumInfo)
{
pDlgAlbumInfo->SetAlbum(albumInfo, path);
if (bShowInfo)
pDlgAlbumInfo->DoModal();
else
pDlgAlbumInfo->RefreshThumb(); // downloads the thumb if we don't already have one
if (!pDlgAlbumInfo->NeedRefresh())
{
if (pDlgAlbumInfo->HasUpdatedThumb())
UpdateThumb(albumInfo, path);
return;
}
bRefresh = true;
m_musicdatabase.DeleteAlbumInfo(albumInfo.idAlbum);
}
}
// If we are scanning for music info in the background,
// other writing access to the database is prohibited.
CGUIDialogMusicScan* dlgMusicScan = (CGUIDialogMusicScan*)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_SCAN);
if (dlgMusicScan->IsDialogRunning())
{
CGUIDialogOK::ShowAndGetInput(189, 14057, 0, 0);
return;
}
CMusicAlbumInfo info;
if (FindAlbumInfo(album.strAlbum, album.strArtist, info, bShowInfo ? (bRefresh ? SELECTION_FORCED : SELECTION_ALLOWED) : SELECTION_AUTO))
{
// download the album info
if ( info.Loaded() )
{
// set album title from musicinfotag, not the one we got from allmusic.com
info.SetTitle(album.strAlbum);
if (saveDb)
{
// save to database
m_musicdatabase.SetAlbumInfo(album.idAlbum, info.GetAlbum(), info.GetSongs());
}
if (m_dlgProgress && bShowInfo)
m_dlgProgress->Close();
UpdateThumb(album, path);
// ok, show album info
CGUIWindowMusicInfo *pDlgAlbumInfo = (CGUIWindowMusicInfo*)g_windowManager.GetWindow(WINDOW_MUSIC_INFO);
if (pDlgAlbumInfo)
{
pDlgAlbumInfo->SetAlbum(info.GetAlbum(), path);
if (bShowInfo)
pDlgAlbumInfo->DoModal();
else
pDlgAlbumInfo->RefreshThumb(); // downloads the thumb if we don't already have one
CAlbum albumInfo = info.GetAlbum();
albumInfo.idAlbum = album.idAlbum;
if (pDlgAlbumInfo->HasUpdatedThumb())
UpdateThumb(albumInfo, path);
if (pDlgAlbumInfo->NeedRefresh())
{
m_musicdatabase.DeleteAlbumInfo(albumInfo.idAlbum);
ShowAlbumInfo(album, path, true, bShowInfo);
return;
}
}
}
else
{
// failed 2 download album info
CGUIDialogOK::ShowAndGetInput(185, 0, 500, 0);
}
}
if (m_dlgProgress && bShowInfo)
m_dlgProgress->Close();
}
void CGUIWindowMusicBase::ShowSongInfo(CFileItem* pItem)
{
CGUIDialogSongInfo *dialog = (CGUIDialogSongInfo *)g_windowManager.GetWindow(WINDOW_DIALOG_SONG_INFO);
if (dialog)
{
if (!pItem->IsMusicDb())
pItem->LoadMusicTag();
if (!pItem->HasMusicInfoTag())
return;
dialog->SetSong(pItem);
dialog->DoModal(GetID());
if (dialog->NeedsUpdate())
{ // update our file list
m_vecItems->RemoveDiscCache(GetID());
Update(m_vecItems->m_strPath);
}
}
}
/*
/// \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()
{
unsigned int startTick = CTimeUtils::GetTimeMS();
OnRetrieveMusicInfo(*m_vecItems);
CLog::Log(LOGDEBUG, "RetrieveMusicInfo() took %u msec",
CTimeUtils::GetTimeMS() - startTick);
}
/// \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 (make a copy as we alter the queuing state)
CFileItemPtr item(new CFileItem(*m_vecItems->Get(iItem)));
if (item->IsRAR() || item->IsZIP())
return;
// Allow queuing of unqueueable items
// when we try to queue them directly
if (!item->CanQueue())
item->SetCanQueue(true);
CLog::Log(LOGDEBUG, "Adding file %s%s to music playlist", item->m_strPath.c_str(), item->m_bIsFolder ? " (folder) " : "");
CFileItemList queuedItems;
AddItemToPlayList(item, queuedItems);
// select next item
m_viewControl.SetSelectedItem(iItem + 1);
// if party mode, add items but DONT start playing
if (g_partyModeManager.IsEnabled())
{
g_partyModeManager.AddUserSongs(queuedItems, false);
return;
}
g_playlistPlayer.Add(PLAYLIST_MUSIC, queuedItems);
if (g_playlistPlayer.GetPlaylist(PLAYLIST_MUSIC).size() && !g_application.IsPlayingAudio())
{
if (m_guiState.get())
m_guiState->SetPlaylistDirectory("playlistmusic://");
g_playlistPlayer.Reset();
g_playlistPlayer.SetCurrentPlaylist(PLAYLIST_MUSIC);
g_playlistPlayer.Play(iOldSize); // start playing at the first new item
}
}
/// \brief Add unique file and folders and its subfolders to playlist
/// \param pItem The file item to add
void CGUIWindowMusicBase::AddItemToPlayList(const CFileItemPtr &pItem, CFileItemList &queuedItems)
{
if (!pItem->CanQueue() || pItem->IsRAR() || pItem->IsZIP() || pItem->IsParentFolder()) // no zip/rar enques thank you!
return;
// fast lookup is needed here
queuedItems.SetFastLookup(true);
if (pItem->IsMusicDb() && pItem->m_bIsFolder && !pItem->IsParentFolder())
{ // we have a music database folder, just grab the "all" item underneath it
CMusicDatabaseDirectory dir;
if (!dir.ContainsSongs(pItem->m_strPath))
{ // grab the ALL item in this category
// Genres will still require 2 lookups, and queuing the entire Genre folder
// will require 3 lookups (genre, artist, album)
CFileItemPtr item(new CFileItem(pItem->m_strPath + "-1/", true));
item->SetCanQueue(true); // workaround for CanQueue() check above
AddItemToPlayList(item, queuedItems);
return;
}
}
if (pItem->m_bIsFolder || (g_windowManager.GetActiveWindow() == WINDOW_MUSIC_NAV && pItem->IsPlayList()))
{
// Check if we add a locked share
if ( pItem->m_bIsShareOrDrive )
{
CFileItem item = *pItem;
if ( !g_passwordManager.IsItemUnlocked( &item, "music" ) )
return ;
}
// recursive
CFileItemList items;
GetDirectory(pItem->m_strPath, items);
//OnRetrieveMusicInfo(items);
FormatAndSort(items);
SetupFanart(items);
for (int i = 0; i < items.Size(); ++i)
AddItemToPlayList(items[i], queuedItems);
}
else
{
if (pItem->IsPlayList())
{
auto_ptr<CPlayList> pPlayList (CPlayListFactory::Create(*pItem));
if (pPlayList.get())
{
// load it
if (!pPlayList->Load(pItem->m_strPath))
{
CGUIDialogOK::ShowAndGetInput(6, 0, 477, 0);
return; //hmmm unable to load playlist?
}
CPlayList playlist = *pPlayList;
for (int i = 0; i < (int)playlist.size(); ++i)
{
AddItemToPlayList(playlist[i], queuedItems);
}
return;
}
}
else if(pItem->IsInternetStream())
{ // just queue the internet stream, it will be expanded on play
queuedItems.Add(pItem);
}
else if (pItem->IsPlugin() && pItem->GetProperty("isplayable") == "true")
{
// python files can be played
queuedItems.Add(pItem);
}
else if (!pItem->IsNFO() && pItem->IsAudio())
{
CFileItemPtr itemCheck = queuedItems.Get(pItem->m_strPath);
if (!itemCheck || itemCheck->m_lStartOffset != pItem->m_lStartOffset)
{ // add item
CFileItemPtr item(new CFileItem(*pItem));
m_musicdatabase.SetPropertiesForFileItem(*item);
queuedItems.Add(item);
}
}
}
}
void CGUIWindowMusicBase::UpdateButtons()
{
// Update window selection control
// Remove labels from the window selection
CGUIMessage msg(GUI_MSG_LABEL_RESET, GetID(), CONTROL_BTNTYPE);
g_windowManager.SendMessage(msg);
// Add labels to the window selection
CGUIMessage msg2(GUI_MSG_LABEL_ADD, GetID(), CONTROL_BTNTYPE);
msg2.SetLabel(g_localizeStrings.Get(744)); // Files
g_windowManager.SendMessage(msg2);
msg2.SetLabel(g_localizeStrings.Get(15100)); // Library
g_windowManager.SendMessage(msg2);
// Select the current window as default item
CONTROL_SELECT_ITEM(CONTROL_BTNTYPE, g_settings.m_iMyMusicStartWindow - WINDOW_MUSIC_FILES);
CGUIMediaWindow::UpdateButtons();
}
bool CGUIWindowMusicBase::FindAlbumInfo(const CStdString& strAlbum, const CStdString& strArtist, CMusicAlbumInfo& album, ALLOW_SELECTION allowSelection)
{
// show dialog box indicating we're searching the album
if (m_dlgProgress && allowSelection != SELECTION_AUTO)
{
m_dlgProgress->SetHeading(185);
m_dlgProgress->SetLine(0, strAlbum);
m_dlgProgress->SetLine(1, strArtist);
m_dlgProgress->SetLine(2, "");
m_dlgProgress->StartModal();
}
CMusicInfoScanner scanner;
CStdString strPath;
CStdString strTempAlbum(strAlbum);
CStdString strTempArtist(strArtist);
long idAlbum = m_musicdatabase.GetAlbumByName(strAlbum,strArtist);
strPath.Format("musicdb://3/%d/",idAlbum);
bool bCanceled(false);
bool needsRefresh(true);
do
{
if (!scanner.DownloadAlbumInfo(strPath,strTempArtist,strTempAlbum,bCanceled,album,m_dlgProgress))
{
if (bCanceled)
return false;
if (m_dlgProgress && allowSelection != SELECTION_AUTO)
{
if (!CGUIDialogKeyboard::ShowAndGetInput(strTempAlbum, g_localizeStrings.Get(16011), false))
return false;
if (!CGUIDialogKeyboard::ShowAndGetInput(strTempArtist, g_localizeStrings.Get(16025), false))
return false;
}
else
needsRefresh = false;
}
else
needsRefresh = false;
}
while (needsRefresh || bCanceled);
// Read the album information from the database if we are dealing with a DB album.
if (idAlbum != -1)
m_musicdatabase.GetAlbumInfo(idAlbum,album.GetAlbum(),&album.GetAlbum().songs);
album.SetLoaded(true);
return true;
}
bool CGUIWindowMusicBase::FindArtistInfo(const CStdString& strArtist, CMusicArtistInfo& artist, ALLOW_SELECTION allowSelection)
{
// show dialog box indicating we're searching the album
if (m_dlgProgress && allowSelection != SELECTION_AUTO)
{
m_dlgProgress->SetHeading(21889);
m_dlgProgress->SetLine(0, strArtist);
m_dlgProgress->SetLine(1, "");
m_dlgProgress->SetLine(2, "");
m_dlgProgress->StartModal();
}
CMusicInfoScanner scanner;
CStdString strPath;
CStdString strTempArtist(strArtist);
long idArtist = m_musicdatabase.GetArtistByName(strArtist);
strPath.Format("musicdb://2/%u/",idArtist);
bool bCanceled(false);
bool needsRefresh(true);
do
{
if (!scanner.DownloadArtistInfo(strPath,strTempArtist,bCanceled,m_dlgProgress))
{
if (bCanceled)
return false;
if (m_dlgProgress && allowSelection != SELECTION_AUTO)
{
if (!CGUIDialogKeyboard::ShowAndGetInput(strTempArtist, g_localizeStrings.Get(16025), false))
return false;
}
else
needsRefresh = false;
}
else
needsRefresh = false;
}
while (needsRefresh || bCanceled);
m_musicdatabase.GetArtistInfo(idArtist,artist.GetArtist());
artist.SetLoaded(true);
return true;
}
void CGUIWindowMusicBase::GetContextButtons(int itemNumber, CContextButtons &buttons)
{
CFileItemPtr item;
if (itemNumber >= 0 && itemNumber < m_vecItems->Size())
item = m_vecItems->Get(itemNumber);
if (item && !item->GetPropertyBOOL("pluginreplacecontextitems"))
{
if (item && !item->IsParentFolder())
{
if (item->GetExtraInfo().Equals("lastfmloved"))
{
buttons.Add(CONTEXT_BUTTON_LASTFM_UNLOVE_ITEM, 15295); //unlove
}
else if (item->GetExtraInfo().Equals("lastfmbanned"))
{
buttons.Add(CONTEXT_BUTTON_LASTFM_UNBAN_ITEM, 15296); //unban
}
else if (item->CanQueue())
{
buttons.Add(CONTEXT_BUTTON_QUEUE_ITEM, 13347); //queue
// allow a folder to be ad-hoc queued and played by the default player
if (item->m_bIsFolder || (item->IsPlayList() &&
!g_advancedSettings.m_playlistAsFolders))
{
buttons.Add(CONTEXT_BUTTON_PLAY_ITEM, 208); // Play
}
else
{ // check what players we have, if we have multiple display play with option
VECPLAYERCORES vecCores;
CPlayerCoreFactory::GetPlayers(*item, vecCores);
if (vecCores.size() >= 1)
buttons.Add(CONTEXT_BUTTON_PLAY_WITH, 15213); // Play With...
}
if (item->IsSmartPlayList())
{
buttons.Add(CONTEXT_BUTTON_PLAY_PARTYMODE, 15216); // Play in Partymode
}
if (item->IsSmartPlayList() || m_vecItems->IsSmartPlayList())
buttons.Add(CONTEXT_BUTTON_EDIT_SMART_PLAYLIST, 586);
else if (item->IsPlayList() || m_vecItems->IsPlayList())
buttons.Add(CONTEXT_BUTTON_EDIT, 586);
}
}
}
CGUIMediaWindow::GetContextButtons(itemNumber, buttons);
}
void CGUIWindowMusicBase::GetNonContextButtons(CContextButtons &buttons)
{
if (!m_vecItems->IsVirtualDirectoryRoot())
buttons.Add(CONTEXT_BUTTON_GOTO_ROOT, 20128);
if (g_playlistPlayer.GetPlaylist(PLAYLIST_MUSIC).size() > 0)
buttons.Add(CONTEXT_BUTTON_NOW_PLAYING, 13350);
buttons.Add(CONTEXT_BUTTON_SETTINGS, 5);
}
bool CGUIWindowMusicBase::OnContextButton(int itemNumber, CONTEXT_BUTTON button)
{
CFileItemPtr item;
if (itemNumber >= 0 && itemNumber < m_vecItems->Size())
item = m_vecItems->Get(itemNumber);
switch (button)
{
case CONTEXT_BUTTON_QUEUE_ITEM:
OnQueueItem(itemNumber);
return true;
case CONTEXT_BUTTON_INFO:
OnInfo(itemNumber);
return true;
case CONTEXT_BUTTON_SONG_INFO:
{
ShowSongInfo(item.get());
return true;
}
case CONTEXT_BUTTON_EDIT:
{
CStdString playlist = item->IsPlayList() ? item->m_strPath : m_vecItems->m_strPath; // save path as activatewindow will destroy our items
g_windowManager.ActivateWindow(WINDOW_MUSIC_PLAYLIST_EDITOR, playlist);
// need to update
m_vecItems->RemoveDiscCache(GetID());
return true;
}
case CONTEXT_BUTTON_EDIT_SMART_PLAYLIST:
{
CStdString playlist = item->IsSmartPlayList() ? item->m_strPath : m_vecItems->m_strPath; // save path as activatewindow will destroy our items
if (CGUIDialogSmartPlaylistEditor::EditPlaylist(playlist, "music"))
{ // need to update
m_vecItems->RemoveDiscCache(GetID());
Update(m_vecItems->m_strPath);
}
return true;
}
case CONTEXT_BUTTON_PLAY_ITEM:
PlayItem(itemNumber);
return true;
case CONTEXT_BUTTON_PLAY_WITH:
{
VECPLAYERCORES vecCores; // base class?
CPlayerCoreFactory::GetPlayers(*item, vecCores);
g_application.m_eForcedNextPlayer = CPlayerCoreFactory::SelectPlayerDialog(vecCores);
if( g_application.m_eForcedNextPlayer != EPC_NONE )
OnClick(itemNumber);
return true;
}
case CONTEXT_BUTTON_PLAY_PARTYMODE:
g_partyModeManager.Enable(PARTYMODECONTEXT_MUSIC, item->m_strPath);
return true;
case CONTEXT_BUTTON_STOP_SCANNING:
{
CGUIDialogMusicScan *scanner = (CGUIDialogMusicScan *)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_SCAN);
if (scanner)
scanner->StopScanning();
return true;
}
case CONTEXT_BUTTON_NOW_PLAYING:
g_windowManager.ActivateWindow(WINDOW_MUSIC_PLAYLIST);
return true;
case CONTEXT_BUTTON_GOTO_ROOT:
Update("");
return true;
case CONTEXT_BUTTON_SETTINGS:
g_windowManager.ActivateWindow(WINDOW_SETTINGS_MYMUSIC);
return true;
case CONTEXT_BUTTON_LASTFM_UNBAN_ITEM:
if (CLastFmManager::GetInstance()->Unban(*item->GetMusicInfoTag()))
{
g_directoryCache.ClearDirectory(m_vecItems->m_strPath);
m_vecItems->RemoveDiscCache(GetID());
Update(m_vecItems->m_strPath);
}
return true;
case CONTEXT_BUTTON_LASTFM_UNLOVE_ITEM:
if (CLastFmManager::GetInstance()->Unlove(*item->GetMusicInfoTag()))
{
g_directoryCache.ClearDirectory(m_vecItems->m_strPath);
m_vecItems->RemoveDiscCache(GetID());
Update(m_vecItems->m_strPath);
}
return true;
default:
break;
}
return CGUIMediaWindow::OnContextButton(itemNumber, button);
}
void CGUIWindowMusicBase::OnRipCD()
{
if(g_mediaManager.IsAudio())
{
if (!g_application.CurrentFileItem().IsCDDA())
{
#ifdef HAS_CDDA_RIPPER
CCDDARipper ripper;
ripper.RipCD();
#endif
}
else
CGUIDialogOK::ShowAndGetInput(257, 20099, 0, 0);
}
}
void CGUIWindowMusicBase::OnRipTrack(int iItem)
{
if(g_mediaManager.IsAudio())
{
if (!g_application.CurrentFileItem().IsCDDA())
{
#ifdef HAS_CDDA_RIPPER
CCDDARipper ripper;
CFileItemPtr item = m_vecItems->Get(iItem);
ripper.RipTrack(item.get());
#endif
}
else
CGUIDialogOK::ShowAndGetInput(257, 20099, 0, 0);
}
}
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 current playlist
const CFileItemPtr pItem = m_vecItems->Get(iItem);
// special case for DAAP playlist folders
bool bIsDAAPplaylist = false;
#ifdef HAS_FILESYSTEM_DAAP
if (pItem->IsDAAP() && pItem->m_bIsFolder)
{
CDAAPDirectory dirDAAP;
if (dirDAAP.GetCurrLevel(pItem->m_strPath) == 0)
bIsDAAPplaylist = true;
}
#endif
// if its a folder, build a playlist
if ((pItem->m_bIsFolder && !pItem->IsPlugin()) || (g_windowManager.GetActiveWindow() == WINDOW_MUSIC_NAV && pItem->IsPlayList()))
{
// make a copy so that we can alter the queue state
CFileItemPtr item(new CFileItem(*m_vecItems->Get(iItem)));
// Allow queuing of unqueueable items
// when we try to queue them directly
if (!item->CanQueue())
item->SetCanQueue(true);
// skip ".."
if (item->IsParentFolder())
return;
CFileItemList queuedItems;
AddItemToPlayList(item, queuedItems);
if (g_partyModeManager.IsEnabled())
{
g_partyModeManager.AddUserSongs(queuedItems, true);
return;
}
/*
CStdString strPlayListDirectory = m_vecItems->m_strPath;
CUtil::RemoveSlashAtEnd(strPlayListDirectory);
*/
g_playlistPlayer.ClearPlaylist(PLAYLIST_MUSIC);
g_playlistPlayer.Reset();
g_playlistPlayer.Add(PLAYLIST_MUSIC, queuedItems);
g_playlistPlayer.SetCurrentPlaylist(PLAYLIST_MUSIC);
// activate the playlist window if its not activated yet
if (bIsDAAPplaylist && GetID() == g_windowManager.GetActiveWindow())
g_windowManager.ActivateWindow(WINDOW_MUSIC_PLAYLIST);
// play!
g_playlistPlayer.Play();
}
else if (pItem->IsPlayList())
{
// load the playlist the old way
LoadPlayList(pItem->m_strPath);
}
else
{
// just a single item, play it
// TODO: Add music-specific code for single playback of an item here (See OnClick in MediaWindow, and OnPlayMedia below)
OnClick(iItem);
}
}
void CGUIWindowMusicBase::LoadPlayList(const CStdString& strPlayList)
{
// if partymode is active, we disable it
if (g_partyModeManager.IsEnabled())
g_partyModeManager.Disable();
// load a playlist like .m3u, .pls
// first get correct factory to load playlist
auto_ptr<CPlayList> pPlayList (CPlayListFactory::Create(strPlayList));
if (pPlayList.get())
{
// load it
if (!pPlayList->Load(strPlayList))
{
CGUIDialogOK::ShowAndGetInput(6, 0, 477, 0);
return; //hmmm unable to load playlist?
}
}
int iSize = pPlayList->size();
if (g_application.ProcessAndStartPlaylist(strPlayList, *pPlayList, PLAYLIST_MUSIC))
{
if (m_guiState.get())
m_guiState->SetPlaylistDirectory("playlistmusic://");
// activate the playlist window if its not activated yet
if (GetID() == g_windowManager.GetActiveWindow() && iSize > 1)
{
g_windowManager.ActivateWindow(WINDOW_MUSIC_PLAYLIST);
}
}
}
bool CGUIWindowMusicBase::OnPlayMedia(int iItem)
{
CFileItemPtr pItem = m_vecItems->Get(iItem);
// party mode
if (g_partyModeManager.IsEnabled() && !pItem->IsLastFM())
{
CPlayList playlistTemp;
playlistTemp.Add(pItem);
g_partyModeManager.AddUserSongs(playlistTemp, true);
return true;
}
else if (!pItem->IsPlayList() && !pItem->IsInternetStream())
{ // single music file - if we get here then we have autoplaynextitem turned off or queuebydefault
// turned on, but we still want to use the playlist player in order to handle more queued items
// following etc.
// Karaoke items also can be added in runtime (while the song is played), so it should be queued too.
if ( (g_guiSettings.GetBool("musicplayer.queuebydefault") && g_windowManager.GetActiveWindow() != WINDOW_MUSIC_PLAYLIST_EDITOR)
|| pItem->IsKaraoke() )
{
// TODO: Should the playlist be cleared if nothing is already playing?
OnQueueItem(iItem);
return true;
}
g_playlistPlayer.Reset();
g_playlistPlayer.ClearPlaylist(PLAYLIST_MUSIC);
g_playlistPlayer.Add(PLAYLIST_MUSIC, pItem);
g_playlistPlayer.SetCurrentPlaylist(PLAYLIST_MUSIC);
g_playlistPlayer.Play();
return true;
}
return CGUIMediaWindow::OnPlayMedia(iItem);
}
void CGUIWindowMusicBase::UpdateThumb(const CAlbum &album, const CStdString &path)
{
// check user permissions
bool saveDb = album.idAlbum != -1;
bool saveDirThumb = true;
if (!g_settings.GetCurrentProfile().canWriteDatabases() && !g_passwordManager.bMasterUser)
{
saveDb = false;
saveDirThumb = false;
}
CStdString albumThumb(CUtil::GetCachedAlbumThumb(album.strAlbum, album.strArtist));
// Update the thumb in the music database (songs + albums)
CStdString albumPath(path);
if (saveDb && CFile::Exists(albumThumb))
m_musicdatabase.SaveAlbumThumb(album.idAlbum, albumThumb);
// Update currently playing song if it's from the same album. This is necessary as when the album
// first gets it's cover, the info manager's item doesn't have the updated information (so will be
// sending a blank thumb to the skin.)
if (g_application.IsPlayingAudio())
{
const CMusicInfoTag* tag=g_infoManager.GetCurrentSongTag();
if (tag)
{
// really, this may not be enough as it is to reliably update this item. eg think of various artists albums
// that aren't tagged as such (and aren't yet scanned). But we probably can't do anything better than this
// in that case
if (album.strAlbum == tag->GetAlbum() && (album.strArtist == tag->GetAlbumArtist() ||
album.strArtist == tag->GetArtist()))
{
g_infoManager.SetCurrentAlbumThumb(albumThumb);
}
}
}
// Save this thumb as the directory thumb if it's the only album in the folder (files view nicety)
// We do this by grabbing all the songs in the folder, and checking to see whether they come
// from the same album.
if (saveDirThumb && CFile::Exists(albumThumb) && !albumPath.IsEmpty() && !CUtil::IsCDDA(albumPath))
{
CFileItemList items;
GetDirectory(albumPath, items);
OnRetrieveMusicInfo(items);
VECSONGS songs;
for (int i = 0; i < items.Size(); i++)
{
CFileItemPtr item = items[i];
if (item->HasMusicInfoTag() && item->GetMusicInfoTag()->Loaded())
{
CSong song(*item->GetMusicInfoTag());
songs.push_back(song);
}
}
CMusicInfoScanner::CheckForVariousArtists(songs);
CStdString album, artist;
if (CMusicInfoScanner::HasSingleAlbum(songs, album, artist))
{ // can cache as the folder thumb
CStdString folderThumb(CUtil::GetCachedMusicThumb(albumPath));
CFile::Cache(albumThumb, folderThumb);
}
}
// update the file listing - we have to update the whole lot, as it's likely that
// more than just our thumbnaias changed
// TODO: Ideally this would only be done when needed - at the moment we appear to be
// doing this for every lookup, possibly twice (see ShowAlbumInfo)
m_vecItems->RemoveDiscCache(GetID());
Update(m_vecItems->m_strPath);
// Do we have to autoswitch to the thumb control?
m_guiState.reset(CGUIViewState::GetViewState(GetID(), *m_vecItems));
UpdateButtons();
}
void CGUIWindowMusicBase::OnRetrieveMusicInfo(CFileItemList& items)
{
if (items.GetFolderCount()==items.Size() || items.IsMusicDb() ||
(!g_guiSettings.GetBool("musicfiles.usetags") && !items.IsCDDA()))
{
return;
}
// Start the music info loader thread
m_musicInfoLoader.SetProgressCallback(m_dlgProgress);
m_musicInfoLoader.Load(items);
bool bShowProgress=!g_windowManager.HasModalDialog();
bool bProgressVisible=false;
unsigned int tick=CTimeUtils::GetTimeMS();
while (m_musicInfoLoader.IsLoading())
{
if (bShowProgress)
{ // Do we have to init a progress dialog?
unsigned int elapsed=CTimeUtils::GetTimeMS()-tick;
if (!bProgressVisible && elapsed>1500 && m_dlgProgress)
{ // tag loading takes more then 1.5 secs, show a progress dialog
CURL url(items.m_strPath);
CStdString strStrippedPath = url.GetWithoutUserDetails();
m_dlgProgress->SetHeading(189);
m_dlgProgress->SetLine(0, 505);
m_dlgProgress->SetLine(1, "");
m_dlgProgress->SetLine(2, strStrippedPath );
m_dlgProgress->StartModal();
m_dlgProgress->ShowProgressBar(true);
bProgressVisible = true;
}
if (bProgressVisible && m_dlgProgress && !m_dlgProgress->IsCanceled())
{ // keep GUI alive
m_dlgProgress->Progress();
}
} // if (bShowProgress)
Sleep(1);
} // while (m_musicInfoLoader.IsLoading())
if (bProgressVisible && m_dlgProgress)
m_dlgProgress->Close();
}
bool CGUIWindowMusicBase::GetDirectory(const CStdString &strDirectory, CFileItemList &items)
{
items.SetThumbnailImage("");
bool bResult = CGUIMediaWindow::GetDirectory(strDirectory,items);
if (bResult)
items.SetMusicThumb();
// add in the "New Playlist" item if we're in the playlists folder
if ((items.m_strPath == "special://musicplaylists/") && !items.Contains("newplaylist://"))
{
CFileItemPtr newPlaylist(new CFileItem(g_settings.GetUserDataItem("PartyMode.xsp"),false));
newPlaylist->SetLabel(g_localizeStrings.Get(16035));
newPlaylist->SetLabelPreformated(true);
newPlaylist->m_bIsFolder = true;
items.Add(newPlaylist);
newPlaylist.reset(new CFileItem("newplaylist://", false));
newPlaylist->SetLabel(g_localizeStrings.Get(525));
newPlaylist->SetLabelPreformated(true);
newPlaylist->SetSpecialSort(SORT_ON_BOTTOM);
newPlaylist->SetCanQueue(false);
items.Add(newPlaylist);
newPlaylist.reset(new CFileItem("newsmartplaylist://music", false));
newPlaylist->SetLabel(g_localizeStrings.Get(21437));
newPlaylist->SetLabelPreformated(true);
newPlaylist->SetSpecialSort(SORT_ON_BOTTOM);
newPlaylist->SetCanQueue(false);
items.Add(newPlaylist);
}
return bResult;
}
void CGUIWindowMusicBase::OnPrepareFileItems(CFileItemList &items)
{
if (!items.m_strPath.Equals("plugin://music/"))
items.SetCachedMusicThumbs();
}
void CGUIWindowMusicBase::SetupFanart(CFileItemList& items)
{
// set fanart
map<CStdString, CStdString> artists;
for (int i = 0; i < items.Size(); i++)
{
CFileItemPtr item = items[i];
CStdString strArtist;
if (item->HasProperty("fanart_image"))
continue;
if (item->HasMusicInfoTag())
strArtist = item->GetMusicInfoTag()->GetArtist();
if (item->HasVideoInfoTag())
strArtist = item->GetVideoInfoTag()->m_strArtist;
if (strArtist.IsEmpty())
continue;
map<CStdString, CStdString>::iterator artist = artists.find(item->GetMusicInfoTag()->GetArtist());
if (artist == artists.end())
{
CStdString strFanart = item->GetCachedFanart();
if (XFILE::CFile::Exists(strFanart))
item->SetProperty("fanart_image",strFanart);
else
strFanart = "";
artists.insert(make_pair(strArtist, strFanart));
}
else
item->SetProperty("fanart_image",artist->second);
}
}
CStdString CGUIWindowMusicBase::GetStartFolder(const CStdString &dir)
{
if (dir.Equals("Plugins") || dir.Equals("Addons"))
return "addons://sources/audio/";
else if (dir.Equals("$PLAYLISTS") || dir.Equals("Playlists"))
return "special://musicplaylists/";
return CGUIMediaWindow::GetStartFolder(dir);
}