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

Method slotAddToFavorite

App/Client/Favorite/FavoriteView.cpp:262–309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

260}
261
262void CFavoriteView::slotAddToFavorite(const QString &file,
263 const QString &szName,
264 const QString &szDescription,
265 const QIcon &icon
266 )
267{
268 if(!m_pModel || !m_pTreeView) return;
269
270 QString szFile = CDatabaseFile::SetFile(file);
271
272 int parentId = 0;
273 QString szGroup = tr("Root");
274 auto indexes = m_pTreeView->selectionModel()->selectedIndexes();
275 if(!indexes.isEmpty())
276 {
277 QModelIndex idx = indexes.at(0);
278 while (idx.isValid()) {
279 CFavoriteDatabase::Item item =
280 m_pModel->data(idx, CFavoriteModel::RoleItem).value<CFavoriteDatabase::Item>();
281 if(item.isFolder() && item.id > 0) {
282 parentId = item.id;
283 szGroup = item.szName;
284 break;
285 }
286 idx = idx.parent();
287 }
288 }
289 // Check if it already exists
290 auto item = m_pModel->GetFavorite(szFile);
291 if(item.id > 0) {
292 if(item.parentId == parentId) {
293 QMessageBox::information(
294 nullptr, tr("Add favorite"),
295 tr("\"%1\" already exists in \"%2\"").arg(szName, szGroup));
296 return;
297 }
298 int ret = QMessageBox::warning(
299 nullptr, tr("Add favorite"),
300 tr("\"%1\" already exists, do you want to move it to \"%2\"?").arg(szName, szGroup),
301 QMessageBox::Ok | QMessageBox::No);
302 if(QMessageBox::Ok != ret)
303 return;
304 }
305
306 m_pModel->AddFavorite(szFile, szName, icon, szDescription, parentId);
307
308 return;
309}
310
311void CFavoriteView::slotUpdateFavorite(
312 const QString &szFile, const QString &szName,

Callers

nothing calls this directly

Calls 7

isValidMethod · 0.80
isEmptyMethod · 0.45
dataMethod · 0.45
isFolderMethod · 0.45
parentMethod · 0.45
GetFavoriteMethod · 0.45
AddFavoriteMethod · 0.45

Tested by

no test coverage detected