| 892 | } |
| 893 | |
| 894 | bool PlaylistTreeWidget::loadPlaylistFromByteArray(QByteArray data, QString filePath) |
| 895 | { |
| 896 | // Try to open the DOM document |
| 897 | QDomDocument doc; |
| 898 | QString errorMessage; |
| 899 | int errorLine; |
| 900 | int errorColumn; |
| 901 | bool success = doc.setContent(data, false, &errorMessage, &errorLine, &errorColumn); |
| 902 | if (!success) |
| 903 | { |
| 904 | QMessageBox::critical(this, |
| 905 | "Error loading playlist.", |
| 906 | errorMessage + |
| 907 | QString(" in line/column %1/%2").arg(errorLine).arg(errorColumn)); |
| 908 | return false; |
| 909 | } |
| 910 | |
| 911 | // Get the root and parser the header |
| 912 | auto root = doc.documentElement(); |
| 913 | auto tmp1 = root.tagName(); |
| 914 | auto tmp2 = root.attribute("version"); |
| 915 | if (root.tagName() == "plist" && root.attribute("version") == "1.0") |
| 916 | { |
| 917 | // This is a playlist file in the old format. This is not supported anymore. |
| 918 | QMessageBox::critical( |
| 919 | this, |
| 920 | "Error loading playlist.", |
| 921 | "The given playlist file seems to be in the old XML format. The playlist format was " |
| 922 | "changed a while back and the old format is no longer supported."); |
| 923 | return false; |
| 924 | } |
| 925 | if (root.tagName() != "playlistItems" || root.attribute("version") != "2.0") |
| 926 | { |
| 927 | QMessageBox::critical( |
| 928 | this, "Error loading playlist.", "The playlist file format could not be recognized."); |
| 929 | return false; |
| 930 | } |
| 931 | |
| 932 | // Iterate over all items in the playlist |
| 933 | auto n = root.firstChild(); |
| 934 | while (!n.isNull()) |
| 935 | { |
| 936 | if (n.isElement()) |
| 937 | this->appendNewItem(playlistItems::loadPlaylistItem(n.toElement(), filePath), false); |
| 938 | n = n.nextSibling(); |
| 939 | } |
| 940 | |
| 941 | // Iterate over the playlist again and load the view states |
| 942 | n = root.firstChild(); |
| 943 | while (!n.isNull()) |
| 944 | { |
| 945 | if (n.isElement()) |
| 946 | { |
| 947 | QDomElement elem = n.toElement(); |
| 948 | if (elem.tagName() == "viewStates") |
| 949 | stateHandler->loadPlaylist(elem); |
| 950 | } |
| 951 | n = n.nextSibling(); |
nothing calls this directly
no test coverage detected