void ServerList_Update_favoriteButton(entity btn, entity me) { if(IsFavorite(me.ipAddressBox.text)) me.favoriteButton.setText(me.favoriteButton, _("Remove")); else me.favoriteButton.setText(me.favoriteButton, _("Bookmark")); }
void Favorite::AddFavorite(ByteString identifier) { if (!IsFavorite(identifier)) { favoritesList.push_back(identifier); } }
QVariant BookmarksModel::data (const QModelIndex& index, int role) const { if (index.row () < 0 || index.row () > Bookmarks_.count ()) return QVariant (); auto bookmark = Bookmarks_.at (index.row ()); switch (role) { case BRID: return bookmark->GetID (); case BRUrl: return bookmark->GetUrl (); case BRTitle: return bookmark->GetTitle (); case BRDescription: return bookmark->GetDescription (); case BRImageUrl: return bookmark->GetImageUrl (); case BRFavorite: return bookmark->IsFavorite (); case BRRead: return bookmark->IsRead (); case BRTags: return bookmark->GetTags ().join (','); case BRAddTime: return bookmark->GetAddTime (); case BRUpdateTime: return bookmark->GetUpdateTime (); case BRStatus: return bookmark->GetStatus (); default: return QVariant (); } }
void BookmarksModel::AddBookmarks (const Bookmarks_t& bookmarks) { Bookmarks_t bmss = bookmarks; for (int i = bmss.count () - 1; i >= 0; --i) { auto bms = bmss.at (i); auto it = std::find_if (Bookmarks_.begin (), Bookmarks_.end (), [bms] (decltype (Bookmarks_.front ()) bookmark) { return bms->GetID () == bookmark->GetID (); }); if (it != Bookmarks_.end ()) { const int pos = std::distance (Bookmarks_.begin (), it); switch (bms->GetStatus ()) { case Bookmark::SDeleted: RemoveBookmark (bms->GetID ()); break; case Bookmark::SArchived: { Bookmark *bm = Bookmarks_ [pos]; bm->SetIsRead (true); emit dataChanged (index (pos), index (pos)); break; } default: { Bookmark *bm = Bookmarks_ [pos]; bm->SetUrl (bms->GetUrl ()); bm->SetTitle (bms->GetTitle ()); bm->SetDescription (bms->GetDescription ()); bm->SetIsFavorite (bms->IsFavorite ()); bm->SetIsRead (bms->IsRead ()); bm->SetAddTime (bms->GetAddTime ()); bm->SetUpdateTime (bms->GetUpdateTime ()); bm->SetTags (bms->GetTags ()); bm->SetImageUrl (bms->GetImageUrl ()); bm->SetStatus (bms->GetStatus ()); emit dataChanged (index (pos), index (pos)); break; } } bmss.takeAt (i)->deleteLater (); } } beginInsertRows (QModelIndex (), rowCount (), rowCount () + bmss.count () - 1); Bookmarks_.append (bmss); endInsertRows (); }
int CRecentImp<T, S>::GetOldestItem( int nIndex, bool bFavorite ) { if( ! IsAvailable() ) return -1; if( nIndex >= *m_pnUserItemCount ) nIndex = *m_pnUserItemCount - 1; for( int i = nIndex; i >= 0; i-- ) { if( IsFavorite( i ) == bFavorite ) return i; } return -1; }
LPCTSTR CFileName::GetFullPath() { if (IsFavorite()) return SAFESTR(filename); if (!location) return NULL; if (fullpath) return fullpath; if (!IsFile()) return location; fullpath = (LPTSTR) malloc((_tcslen(location) + _tcslen(filename) + 2) * sizeof(TCHAR)); _stprintf(fullpath, _T("%s%s"), location, filename); return fullpath; }
bool CRecentImp<T, S>::DeleteItemsNoFavorite() { if( ! IsAvailable() ) return false; bool bDeleted = false; int i; for( i = *m_pnUserItemCount - 1; 0 <= i; i-- ) { if( false == IsFavorite( i ) ) { if( DeleteItem( i ) ) { bDeleted = true; } } } return bDeleted; }
bool CRecentImp<T, S>::MoveItem( int nSrcIndex, int nDstIndex ) { int i; bool bFavorite; if( ! IsAvailable() ) return false; if( nSrcIndex < 0 || nSrcIndex >= *m_pnUserItemCount ) return false; if( nDstIndex < 0 || nDstIndex >= *m_pnUserItemCount ) return false; if( nSrcIndex == nDstIndex ) return true; DataType pri; //移動する情報を退避 memcpy_raw( &pri, GetItemPointer( nSrcIndex ), sizeof(pri) ); bFavorite = IsFavorite( nSrcIndex ); if( nSrcIndex < nDstIndex ) { for( i = nSrcIndex; i < nDstIndex; i++ ) { CopyItem( i + 1, i ); } } else { for( i = nSrcIndex; i > nDstIndex; i-- ) { CopyItem( i - 1, i ); } } //新しい位置に格納 memcpy_raw( GetItemPointer( nDstIndex ), &pri, sizeof(pri) ); SetFavorite( nDstIndex, bFavorite ); return true; }
bool CRecentImp<T, S>::ChangeViewCount( int nViewCount ) { int i; int nIndex; //範囲外ならエラー if( ! IsAvailable() ) return false; if( nViewCount < 0 || nViewCount > m_nArrayCount ) return false; //表示個数を更新する。 if( m_pnUserViewCount ) { *m_pnUserViewCount = nViewCount; } //範囲内にすべて収まっているので何もしなくてよい。 if( nViewCount >= *m_pnUserItemCount ) return true; //最も古いお気に入りを探す。 i = GetOldestItem( *m_pnUserItemCount - 1, true ); if( -1 == i ) return true; //ないので何もしないで終了 //表示外アイテムを表示内に移動する。 for( ; i >= nViewCount; i-- ) { if( IsFavorite( i ) ) { //カレント位置から上に通常アイテムを探す nIndex = GetOldestItem( i - 1, false ); if( -1 == nIndex ) break; //もう1個もない //見つかったアイテムをカレント位置に移動する MoveItem( nIndex, i ); } } return true; }
// Slot: toggle the favorites indicator void tAllChannelStatus::ToggleFavorite() { if (m_Records.at(GetFocusRecordIndex())->IsUnsubscribed()) { return; } const bool isFav = IsFavorite(GetFocusRow()); //item(GetFocusRow(), FAV_COLUMN)->checkState() == Qt::Checked; const int serviceId = m_Records.at(GetFocusRecordIndex())->ServiceId(); // Update the set of favorites if (isFav) { m_Favorites.remove(serviceId); item(GetFocusRow(), FAV_COLUMN)->setCheckState(Qt::Unchecked); // Visual feedback } else { m_Favorites.insert(serviceId); item(GetFocusRow(), FAV_COLUMN)->setCheckState(Qt::Checked); // Visual feedback } //save it right away in case power goes down Save(); }
void XonoticServerList_draw(entity me) { float i, found, owned; if(me.currentSortField == -1) { me.setSortOrder(me, SLIST_FIELD_PING, +1); me.refreshServerList(me, 2); } else if(me.needsRefresh == 1) { me.needsRefresh = 2; // delay by one frame to make sure "slist" has been executed } else if(me.needsRefresh == 2) { me.needsRefresh = 0; me.refreshServerList(me, 0); } owned = ((me.selectedServer == me.ipAddressBox.text) && (me.ipAddressBox.text != "")); me.nItems = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT); me.connectButton.disabled = ((me.nItems == 0) && (me.ipAddressBox.text == "")); me.infoButton.disabled = ((me.nItems == 0) || !owned); found = 0; if(me.selectedServer) { for(i = 0; i < me.nItems; ++i) if(gethostcachestring(SLIST_FIELD_CNAME, i) == me.selectedServer) { if(i != me.selectedItem) { me.lastClickedServer = -1; me.selectedItem = i; } found = 1; break; } } if(!found) if(me.nItems > 0) { if(me.selectedItem >= me.nItems) me.selectedItem = me.nItems - 1; if(me.selectedServer) strunzone(me.selectedServer); me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); } if(owned) { if(me.selectedServer != me.ipAddressBox.text) { me.ipAddressBox.setText(me.ipAddressBox, me.selectedServer); me.ipAddressBox.cursorPos = strlen(me.selectedServer); me.ipAddressBoxFocused = -1; } } if(me.ipAddressBoxFocused != me.ipAddressBox.focused) { if(me.ipAddressBox.focused || me.ipAddressBoxFocused < 0) { if(IsFavorite(me.ipAddressBox.text)) me.favoriteButton.setText(me.favoriteButton, "Remove"); else me.favoriteButton.setText(me.favoriteButton, "Bookmark"); } me.ipAddressBoxFocused = me.ipAddressBox.focused; } SUPER(XonoticServerList).draw(me); }