MCPcopy Create free account
hub / github.com/KangLin/RabbitRemoteControl / AddFavorite

Method AddFavorite

App/Client/Favorite/FavoriteModel.cpp:229–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

227}
228
229bool 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
262bool CFavoriteModel::UpdateFavorite(
263 const QString &szFile, const QString &szName,

Callers 1

slotAddToFavoriteMethod · 0.45

Calls 4

containsMethod · 0.45
GetFavoriteMethod · 0.45
isEmptyMethod · 0.45
MoveMethod · 0.45

Tested by

no test coverage detected