| 843 | } |
| 844 | |
| 845 | void WizFolder::moveToLocation(const QString& strDestLocation) |
| 846 | { |
| 847 | Q_ASSERT(strDestLocation.right(1) == "/"); |
| 848 | Q_ASSERT(strDestLocation.left(1) == "/"); |
| 849 | |
| 850 | if (!canMove(location(), strDestLocation)) |
| 851 | return; |
| 852 | |
| 853 | QString strOldLocation = location(); |
| 854 | |
| 855 | CWizDocumentDataArray arrayDocument; |
| 856 | if (!m_db.getDocumentsByLocation(strOldLocation, arrayDocument, true)) { |
| 857 | TOLOG1("Failed to get documents by location (include sub folders): %1", strOldLocation); |
| 858 | return; |
| 859 | } |
| 860 | |
| 861 | int i = 0; |
| 862 | CWizDocumentDataArray::const_iterator it; |
| 863 | for (it = arrayDocument.begin(); it != arrayDocument.end(); it++) { |
| 864 | WIZDOCUMENTDATA data = *it; |
| 865 | |
| 866 | if (!data.strLocation.startsWith(strOldLocation)) { |
| 867 | TOLOG("Error location of document!"); |
| 868 | continue; |
| 869 | } |
| 870 | |
| 871 | data.strLocation.remove(0, strOldLocation.length()); |
| 872 | data.strLocation.insert(0, strDestLocation); |
| 873 | data.nVersion = -1; |
| 874 | |
| 875 | if (!m_db.modifyDocumentLocation(data)) { |
| 876 | TOLOG("Failed to move note to new folder!"); |
| 877 | continue; |
| 878 | } |
| 879 | |
| 880 | Q_EMIT moveDocument(arrayDocument.size(), i++, strOldLocation, strDestLocation, data); |
| 881 | } |
| 882 | |
| 883 | CWizStdStringArray arrayFolder; |
| 884 | m_db.getExtraFolder(arrayFolder); |
| 885 | for (CWizStdStringArray::const_iterator it = arrayFolder.begin(); |
| 886 | it != arrayFolder.end(); |
| 887 | it++) { |
| 888 | QString strFolder = *it; |
| 889 | if (strFolder.right(1) != "/") { |
| 890 | strFolder.append("/"); |
| 891 | } |
| 892 | if (strFolder.startsWith(strOldLocation)) { |
| 893 | strFolder.remove(0, strOldLocation.length()); |
| 894 | strFolder.insert(0, strDestLocation); |
| 895 | qDebug() << "Add new folder ; " << strFolder; |
| 896 | m_db.addExtraFolder(strFolder); |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | qDebug() << "Delete old location ; " << strOldLocation; |
| 901 | m_db.deleteExtraFolder(strOldLocation); |
| 902 | m_db.setLocalValueVersion("folders", -1); |
no test coverage detected