mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-26 16:09:35 -05:00
added remove buttons for ongoing search entries
This commit is contained in:
parent
91fd38d46f
commit
c79ceba4ee
@ -59,6 +59,8 @@
|
||||
#define ROLE_SUBSCRIBE_FLAGS Qt::UserRole + 8
|
||||
#define ROLE_COLOR Qt::UserRole + 9
|
||||
#define ROLE_SAVED_ICON Qt::UserRole + 10
|
||||
#define ROLE_SEARCH_STRING Qt::UserRole + 11
|
||||
#define ROLE_REQUEST_ID Qt::UserRole + 12
|
||||
|
||||
#define FILTER_NAME_INDEX 0
|
||||
#define FILTER_DESC_INDEX 1
|
||||
@ -397,6 +399,32 @@ QTreeWidgetItem *GroupTreeWidget::addCategoryItem(const QString &name, const QIc
|
||||
return item;
|
||||
}
|
||||
|
||||
void GroupTreeWidget::removeSearchItem(QTreeWidgetItem *item)
|
||||
{
|
||||
ui->treeWidget->takeTopLevelItem(ui->treeWidget->indexOfTopLevelItem(item)) ;
|
||||
}
|
||||
|
||||
QTreeWidgetItem *GroupTreeWidget::addSearchItem(const QString& search_string, uint32_t id, const QIcon& icon)
|
||||
{
|
||||
QTreeWidgetItem *item = addCategoryItem(search_string,icon,true);
|
||||
|
||||
item->setData(COLUMN_DATA,ROLE_SEARCH_STRING,search_string) ;
|
||||
item->setData(COLUMN_DATA,ROLE_REQUEST_ID ,id) ;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
bool GroupTreeWidget::isSearchRequestItem(QPoint &point,uint32_t& search_req_id)
|
||||
{
|
||||
QTreeWidgetItem *item = ui->treeWidget->itemAt(point);
|
||||
if (item == NULL)
|
||||
return false;
|
||||
|
||||
search_req_id = item->data(COLUMN_DATA, ROLE_REQUEST_ID).toUInt();
|
||||
|
||||
return search_req_id > 0;
|
||||
}
|
||||
|
||||
QString GroupTreeWidget::itemId(QTreeWidgetItem *item)
|
||||
{
|
||||
if (item == NULL) {
|
||||
|
@ -82,6 +82,10 @@ public:
|
||||
|
||||
// Add a new category item
|
||||
QTreeWidgetItem *addCategoryItem(const QString &name, const QIcon &icon, bool expand);
|
||||
// Add a new search item
|
||||
QTreeWidgetItem *addSearchItem(const QString& search_string, uint32_t id, const QIcon &icon) ;
|
||||
void removeSearchItem(QTreeWidgetItem *item);
|
||||
|
||||
// Get id of item
|
||||
QString itemId(QTreeWidgetItem *item);
|
||||
QString itemIdAt(QPoint &point);
|
||||
@ -90,6 +94,8 @@ public:
|
||||
// Set the unread count of an item
|
||||
void setUnreadCount(QTreeWidgetItem *item, int unreadCount);
|
||||
|
||||
bool isSearchRequestItem(QPoint &point,uint32_t& search_req_id);
|
||||
|
||||
QTreeWidgetItem *getItemFromId(const QString &id);
|
||||
QTreeWidgetItem *activateId(const QString &id, bool focus);
|
||||
|
||||
|
@ -46,6 +46,7 @@
|
||||
#define IMAGE_EDIT ":/images/edit_16.png"
|
||||
#define IMAGE_SHARE ":/images/share-icon-16.png"
|
||||
#define IMAGE_TABNEW ":/images/tab-new.png"
|
||||
#define IMAGE_DELETE ":/images/delete.png"
|
||||
#define IMAGE_COMMENT ""
|
||||
|
||||
#define TOKEN_TYPE_GROUP_SUMMARY 1
|
||||
@ -252,16 +253,55 @@ void GxsGroupFrameDialog::todo()
|
||||
QMessageBox::information(this, "Todo", text(TEXT_TODO));
|
||||
}
|
||||
|
||||
void GxsGroupFrameDialog::removeCurrentSearch()
|
||||
{
|
||||
QAction *action = dynamic_cast<QAction*>(sender()) ;
|
||||
|
||||
if(!action)
|
||||
return ;
|
||||
|
||||
TurtleRequestId search_request_id = action->data().toUInt();
|
||||
|
||||
auto it = mSearchGroups.find(search_request_id) ;
|
||||
|
||||
if(it == mSearchGroups.end())
|
||||
return ;
|
||||
|
||||
ui->groupTreeWidget->removeSearchItem(it->second) ;
|
||||
mSearchGroups.erase(it);
|
||||
}
|
||||
|
||||
void GxsGroupFrameDialog::removeAllSearches()
|
||||
{
|
||||
for(auto it(mSearchGroups.begin());it!=mSearchGroups.end();++it)
|
||||
ui->groupTreeWidget->removeSearchItem(it->second) ;
|
||||
|
||||
mSearchGroups.clear();
|
||||
}
|
||||
void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point)
|
||||
{
|
||||
// First separately handle the case of search top level items
|
||||
|
||||
TurtleRequestId search_request_id = 0 ;
|
||||
|
||||
if(ui->groupTreeWidget->isSearchRequestItem(point,search_request_id))
|
||||
{
|
||||
QMenu contextMnu(this);
|
||||
|
||||
contextMnu.addAction(QIcon(IMAGE_DELETE), tr("Remove this search"), this, SLOT(removeCurrentSearch()))->setData(search_request_id);
|
||||
contextMnu.addAction(QIcon(IMAGE_DELETE), tr("Remove all searches"), this, SLOT(removeAllSearches()));
|
||||
contextMnu.exec(QCursor::pos());
|
||||
return ;
|
||||
}
|
||||
|
||||
QString id = ui->groupTreeWidget->itemIdAt(point);
|
||||
if (id.isEmpty()) return;
|
||||
|
||||
mGroupId = RsGxsGroupId(id.toStdString());
|
||||
int subscribeFlags = ui->groupTreeWidget->subscribeFlags(QString::fromStdString(mGroupId.toStdString()));
|
||||
|
||||
bool isAdmin = IS_GROUP_ADMIN(subscribeFlags);
|
||||
bool isPublisher = IS_GROUP_PUBLISHER(subscribeFlags);
|
||||
bool isAdmin = IS_GROUP_ADMIN(subscribeFlags);
|
||||
bool isPublisher = IS_GROUP_PUBLISHER(subscribeFlags);
|
||||
bool isSubscribed = IS_GROUP_SUBSCRIBED(subscribeFlags);
|
||||
|
||||
QMenu contextMnu(this);
|
||||
@ -1088,11 +1128,14 @@ TurtleRequestId GxsGroupFrameDialog::distantSearch(const QString& search_string)
|
||||
|
||||
void GxsGroupFrameDialog::searchNetwork(const QString& search_string)
|
||||
{
|
||||
if(search_string.isNull())
|
||||
return ;
|
||||
|
||||
uint32_t request_id = distantSearch(search_string);
|
||||
|
||||
if(request_id == 0)
|
||||
return ;
|
||||
|
||||
mSearchGroups[request_id] = ui->groupTreeWidget->addCategoryItem(tr("Search for")+ " \"" + search_string + "\"", QIcon(icon(ICON_SEARCH)), true);
|
||||
mSearchGroups[request_id] = ui->groupTreeWidget->addSearchItem(tr("Search for")+ " \"" + search_string + "\"",(uint32_t)request_id,QIcon(icon(ICON_SEARCH)));
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,10 @@ private slots:
|
||||
void sharePublishKey();
|
||||
|
||||
void loadComment(const RsGxsGroupId &grpId, const QVector<RsGxsMessageId>& msg_versions,const RsGxsMessageId &most_recent_msgId, const QString &title);
|
||||
|
||||
void searchNetwork(const QString &search_string) ;
|
||||
void removeAllSearches();
|
||||
void removeCurrentSearch();
|
||||
|
||||
private:
|
||||
virtual QString text(TextType type) = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user