| 227 | } |
| 228 | |
| 229 | bool CFavoriteModel::AddFavorite( |
| 230 | const QString &szFile, const QString& szName, const QIcon &icon, |
| 231 | const QString szDescription, int parentId) |
| 232 | { |
| 233 | if(!m_pDatabase || !m_Folders.contains(parentId)) return false; |
| 234 | int id = 0; |
| 235 | CFavoriteDatabase::Item item(TreeItem::Leaf); |
| 236 | // Check if it already exists |
| 237 | auto items = m_pDatabase->GetFavorite(szFile); |
| 238 | if(items.isEmpty()) { |
| 239 | // Add |
| 240 | id = m_pDatabase->AddFavorite(szFile, szName, icon, szDescription, parentId); |
| 241 | if(id <= 0 ) return false; |
| 242 | |
| 243 | item.id = id; |
| 244 | item.parentId = parentId; |
| 245 | item.szName = szName; |
| 246 | item.szFile = szFile; |
| 247 | item.icon = icon; |
| 248 | item.szDescription = szDescription; |
| 249 | AddTree(item, parentId); |
| 250 | } else { |
| 251 | // Update |
| 252 | auto it = items.at(0); |
| 253 | if(it.id <= 0) return false; |
| 254 | bool ok = MoveTree(it, parentId); |
| 255 | if(!ok) return false; |
| 256 | m_pDatabase->Move(it.id, parentId); |
| 257 | } |
| 258 | |
| 259 | return true; |
| 260 | } |
| 261 | |
| 262 | bool CFavoriteModel::UpdateFavorite( |
| 263 | const QString &szFile, const QString &szName, |
no test coverage detected