Add GroupTreeWidget show header action.

It's not possible to resize them.
Friend's posts column can be shown too to understand sort.
Menu to show column is visible for all type of item.
This commit is contained in:
Phenom 2021-01-21 15:09:43 +01:00
parent 41727210cd
commit a0bf49448d
3 changed files with 252 additions and 233 deletions

View File

@ -35,13 +35,6 @@
#include <stdint.h> #include <stdint.h>
#define COLUMN_NAME 0
#define COLUMN_UNREAD 1
#define COLUMN_POPULARITY 2
#define COLUMN_LAST_POST 3
#define COLUMN_COUNT 4
#define COLUMN_DATA COLUMN_NAME
#define ROLE_ID Qt::UserRole #define ROLE_ID Qt::UserRole
#define ROLE_NAME Qt::UserRole + 1 #define ROLE_NAME Qt::UserRole + 1
#define ROLE_DESCRIPTION Qt::UserRole + 2 #define ROLE_DESCRIPTION Qt::UserRole + 2
@ -74,7 +67,7 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) :
actionSortByUnread = NULL; actionSortByUnread = NULL;
compareRole = new RSTreeWidgetItemCompareRole; compareRole = new RSTreeWidgetItemCompareRole;
compareRole->setRole(COLUMN_DATA, ROLE_NAME); compareRole->setRole(GTW_COLUMN_DATA, ROLE_NAME);
/* Connect signals */ /* Connect signals */
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged())); connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged()));
@ -94,41 +87,50 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) :
ui->treeWidget->setItemDelegate(itemDelegate); ui->treeWidget->setItemDelegate(itemDelegate);
/* Initialize tree widget */ /* Initialize tree widget */
ui->treeWidget->setColumnCount(COLUMN_COUNT); ui->treeWidget->setColumnCount(GTW_COLUMN_COUNT);
ui->treeWidget->enableColumnCustomize(true); ui->treeWidget->enableColumnCustomize(true);
ui->treeWidget->setColumnCustomizable(COLUMN_NAME, false); ui->treeWidget->setColumnCustomizable(GTW_COLUMN_NAME, false);
int S = QFontMetricsF(font()).height() ; int S = QFontMetricsF(font()).height() ;
int W = QFontMetricsF(font()).width("999") ; int W = QFontMetricsF(font()).width("_") ;
int D = QFontMetricsF(font()).width("9999-99-99[]") ; int D = QFontMetricsF(font()).width("9999-99-99[]") ;
QTreeWidgetItem *headerItem = ui->treeWidget->headerItem();
headerItem->setText(GTW_COLUMN_NAME, tr("Name"));
headerItem->setText(GTW_COLUMN_UNREAD, tr("Unread"));
headerItem->setText(GTW_COLUMN_POSTS, tr("F Posts"));
headerItem->setText(GTW_COLUMN_POPULARITY, tr("Popularity"));
headerItem->setText(GTW_COLUMN_LAST_POST, tr("Last Post"));
headerItem->setToolTip(GTW_COLUMN_NAME, tr("Name"));
headerItem->setToolTip(GTW_COLUMN_UNREAD, tr("Number of Unread message"));
headerItem->setToolTip(GTW_COLUMN_POSTS, tr("Friend's Posts"));
headerItem->setToolTip(GTW_COLUMN_POPULARITY, tr("Popularity"));
headerItem->setToolTip(GTW_COLUMN_LAST_POST, tr("Last Post"));
/* Set header resize modes and initial section sizes */ /* Set header resize modes and initial section sizes */
QHeaderView *header = ui->treeWidget->header (); QHeaderView *header = ui->treeWidget->header ();
header->setStretchLastSection(false); header->setStretchLastSection(false);
QHeaderView_setSectionResizeModeColumn(header, COLUMN_NAME, QHeaderView::Stretch); QHeaderView_setSectionResizeModeColumn(header, GTW_COLUMN_NAME, QHeaderView::Stretch);
header->resizeSection(COLUMN_NAME, 10*S) ; header->resizeSection(GTW_COLUMN_NAME, 10*W) ;
QHeaderView_setSectionResizeModeColumn(header, COLUMN_UNREAD, QHeaderView::Fixed); QHeaderView_setSectionResizeModeColumn(header, GTW_COLUMN_UNREAD, QHeaderView::Interactive);
header->resizeSection(COLUMN_UNREAD, W+4) ; header->resizeSection(GTW_COLUMN_UNREAD, 3*W+4) ;
QHeaderView_setSectionResizeModeColumn(header, COLUMN_POPULARITY, QHeaderView::Fixed); QHeaderView_setSectionResizeModeColumn(header, GTW_COLUMN_POSTS, QHeaderView::Interactive);
header->resizeSection(COLUMN_POPULARITY, 2*S) ; header->resizeSection(GTW_COLUMN_POSTS, 3*W+4) ;
QHeaderView_setSectionResizeModeColumn(header, COLUMN_LAST_POST, QHeaderView::Fixed); header->setSectionHidden(GTW_COLUMN_POSTS, true);
header->resizeSection(COLUMN_LAST_POST, D+4) ; QHeaderView_setSectionResizeModeColumn(header, GTW_COLUMN_POPULARITY, QHeaderView::Interactive);
header->setSectionHidden(COLUMN_LAST_POST, true); header->resizeSection(GTW_COLUMN_POPULARITY, 3*W) ;
QHeaderView_setSectionResizeModeColumn(header, GTW_COLUMN_LAST_POST, QHeaderView::Interactive);
QTreeWidgetItem *headerItem = ui->treeWidget->headerItem(); header->resizeSection(GTW_COLUMN_LAST_POST, D+4) ;
headerItem->setText(COLUMN_NAME, tr("Name")); header->setSectionHidden(GTW_COLUMN_LAST_POST, true);
headerItem->setText(COLUMN_UNREAD, tr("Unread"));
headerItem->setText(COLUMN_POPULARITY, tr("Popularity"));
headerItem->setText(COLUMN_LAST_POST, tr("Last Post"));
/* add filter actions */ /* add filter actions */
ui->filterLineEdit->addFilter(QIcon(), tr("Title"), FILTER_NAME_INDEX , tr("Search Title")); ui->filterLineEdit->addFilter(QIcon(), tr("Title"), FILTER_NAME_INDEX , tr("Search Title"));
ui->filterLineEdit->addFilter(QIcon(), tr("Description"), FILTER_DESC_INDEX , tr("Search Description")); ui->filterLineEdit->addFilter(QIcon(), tr("Description"), FILTER_DESC_INDEX , tr("Search Description"));
ui->filterLineEdit->setCurrentFilter(FILTER_NAME_INDEX); ui->filterLineEdit->setCurrentFilter(FILTER_NAME_INDEX);
ui->distantSearchLineEdit->setPlaceholderText(tr("Search entire network...")) ; ui->distantSearchLineEdit->setPlaceholderText(tr("Search entire network...")) ;
connect(ui->distantSearchLineEdit,SIGNAL(returnPressed()),this,SLOT(distantSearch())) ; connect(ui->distantSearchLineEdit,SIGNAL(returnPressed()),this,SLOT(distantSearch())) ;
/* Initialize display button */ /* Initialize display button */
initDisplayMenu(ui->displayButton); initDisplayMenu(ui->displayButton);
@ -179,15 +181,18 @@ void GroupTreeWidget::processSettings(bool load)
} }
const int SORTBY_NAME = 1; const int SORTBY_NAME = 1;
const int SORTBY_POPULRITY = 2; const int SORTBY_POPULARITY = 2;
const int SORTBY_LASTPOST = 3; const int SORTBY_LASTPOST = 3;
const int SORTBY_POSTS = 4; const int SORTBY_POSTS = 4;
const int SORTBY_UNREAD = 5; const int SORTBY_UNREAD = 5;
ui->treeWidget->setSettingsVersion(1);//Change it when modifing column properties
ui->treeWidget->processSettings(load); ui->treeWidget->processSettings(load);
if (load) { if (load) {
// load Settings // load Settings
bool showHeader = Settings->value("GroupShowHeader", false).toBool();
actionShowHeader->setChecked(showHeader);
// state of order // state of order
bool ascSort = Settings->value("GroupAscSort", true).toBool(); bool ascSort = Settings->value("GroupAscSort", true).toBool();
@ -202,7 +207,7 @@ void GroupTreeWidget::processSettings(bool load)
actionSortByName->setChecked(true); actionSortByName->setChecked(true);
} }
break; break;
case SORTBY_POPULRITY: case SORTBY_POPULARITY:
if (actionSortByPopularity) { if (actionSortByPopularity) {
actionSortByPopularity->setChecked(true); actionSortByPopularity->setChecked(true);
} }
@ -225,6 +230,7 @@ void GroupTreeWidget::processSettings(bool load)
} }
} else { } else {
// save Settings // save Settings
Settings->setValue("GroupShowHeader", !(actionShowHeader && actionShowHeader->isChecked())); //False by default
// state of order // state of order
Settings->setValue("GroupAscSort", !(actionSortDescending && actionSortDescending->isChecked())); //True by default Settings->setValue("GroupAscSort", !(actionSortDescending && actionSortDescending->isChecked())); //True by default
@ -234,7 +240,7 @@ void GroupTreeWidget::processSettings(bool load)
if (actionSortByName && actionSortByName->isChecked()) { if (actionSortByName && actionSortByName->isChecked()) {
sortby = SORTBY_NAME; sortby = SORTBY_NAME;
} else if (actionSortByPopularity && actionSortByPopularity->isChecked()) { } else if (actionSortByPopularity && actionSortByPopularity->isChecked()) {
sortby = SORTBY_POPULRITY; sortby = SORTBY_POPULARITY;
} else if (actionSortByLastPost && actionSortByLastPost->isChecked()) { } else if (actionSortByLastPost && actionSortByLastPost->isChecked()) {
sortby = SORTBY_LASTPOST; sortby = SORTBY_LASTPOST;
} else if (actionSortByPosts && actionSortByPosts->isChecked()) { } else if (actionSortByPosts && actionSortByPosts->isChecked()) {
@ -251,11 +257,15 @@ void GroupTreeWidget::initDisplayMenu(QToolButton *toolButton)
displayMenu = new QMenu(); displayMenu = new QMenu();
QActionGroup *actionGroupAsc = new QActionGroup(displayMenu); QActionGroup *actionGroupAsc = new QActionGroup(displayMenu);
actionSortDescending = displayMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/images/sort_decrease.png"), tr("Sort Descending Order"), this, SLOT(sort())); actionShowHeader = displayMenu->addAction(tr("Show Header"));
connect(actionShowHeader, SIGNAL(toggled(bool)), this, SLOT(showHeader(bool)));
actionShowHeader->setCheckable(true);
actionSortDescending = displayMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/images/sort_decrease.png"), tr("Sort Descending Order"), this, SLOT(sort()));
actionSortDescending->setCheckable(true); actionSortDescending->setCheckable(true);
actionSortDescending->setActionGroup(actionGroupAsc); actionSortDescending->setActionGroup(actionGroupAsc);
actionSortAscending = displayMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/images/sort_incr.png"), tr("Sort Ascending Order"), this, SLOT(sort())); actionSortAscending = displayMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/images/sort_incr.png"), tr("Sort Ascending Order"), this, SLOT(sort()));
actionSortAscending->setCheckable(true); actionSortAscending->setCheckable(true);
actionSortAscending->setActionGroup(actionGroupAsc); actionSortAscending->setActionGroup(actionGroupAsc);
@ -275,7 +285,7 @@ void GroupTreeWidget::initDisplayMenu(QToolButton *toolButton)
actionSortByLastPost->setCheckable(true); actionSortByLastPost->setCheckable(true);
actionSortByLastPost->setActionGroup(actionGroup); actionSortByLastPost->setActionGroup(actionGroup);
actionSortByPosts = displayMenu->addAction(QIcon(), tr("Sort by Number of Posts"), this, SLOT(sort())); actionSortByPosts = displayMenu->addAction(QIcon(), tr("Sort by Number of Friend's Posts"), this, SLOT(sort()));
actionSortByPosts->setCheckable(true); actionSortByPosts->setCheckable(true);
actionSortByPosts->setActionGroup(actionGroup); actionSortByPosts->setActionGroup(actionGroup);
@ -293,11 +303,11 @@ void GroupTreeWidget::updateColors()
while ((item = *itemIterator) != NULL) { while ((item = *itemIterator) != NULL) {
++itemIterator; ++itemIterator;
int color = item->data(COLUMN_DATA, ROLE_COLOR).toInt(); int color = item->data(GTW_COLUMN_DATA, ROLE_COLOR).toInt();
if (color >= 0) { if (color >= 0) {
item->setData(COLUMN_NAME, Qt::TextColorRole, mTextColor[color]); item->setData(GTW_COLUMN_NAME, Qt::TextColorRole, mTextColor[color]);
} else { } else {
item->setData(COLUMN_NAME, Qt::TextColorRole, QVariant()); item->setData(GTW_COLUMN_NAME, Qt::TextColorRole, QVariant());
} }
} }
@ -315,7 +325,7 @@ void GroupTreeWidget::currentItemChanged(QTreeWidgetItem *current, QTreeWidgetIt
QString id; QString id;
if (current) { if (current) {
id = current->data(COLUMN_DATA, ROLE_ID).toString(); id = current->data(GTW_COLUMN_DATA, ROLE_ID).toString();
} }
emit treeCurrentItemChanged(id); emit treeCurrentItemChanged(id);
@ -328,7 +338,7 @@ void GroupTreeWidget::itemActivated(QTreeWidgetItem *item, int column)
QString id; QString id;
if (item) { if (item) {
id = item->data(COLUMN_DATA, ROLE_ID).toString(); id = item->data(GTW_COLUMN_DATA, ROLE_ID).toString();
} }
emit treeItemActivated(id); emit treeItemActivated(id);
@ -343,18 +353,18 @@ QTreeWidgetItem *GroupTreeWidget::addCategoryItem(const QString &name, const QIc
ui->treeWidget->style()->unpolish(ui->treeWidget); ui->treeWidget->style()->unpolish(ui->treeWidget);
ui->treeWidget->style()->polish(ui->treeWidget); ui->treeWidget->style()->polish(ui->treeWidget);
item->setText(COLUMN_NAME, name); item->setText(GTW_COLUMN_NAME, name);
item->setData(COLUMN_DATA, ROLE_NAME, name); item->setData(GTW_COLUMN_DATA, ROLE_NAME, name);
font = item->font(COLUMN_NAME); font = item->font(GTW_COLUMN_NAME);
font.setBold(true); font.setBold(true);
item->setFont(COLUMN_NAME, font); item->setFont(GTW_COLUMN_NAME, font);
item->setIcon(COLUMN_NAME, icon); item->setIcon(GTW_COLUMN_NAME, icon);
int S = QFontMetricsF(font).height(); int S = QFontMetricsF(font).height();
item->setSizeHint(COLUMN_NAME, QSize(S*1.9, S*1.9)); item->setSizeHint(GTW_COLUMN_NAME, QSize(S*1.9, S*1.9));
item->setData(COLUMN_NAME, Qt::TextColorRole, textColorCategory()); item->setData(GTW_COLUMN_NAME, Qt::TextColorRole, textColorCategory());
item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_CATEGORY); item->setData(GTW_COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_CATEGORY);
item->setExpanded(expand); item->setExpanded(expand);
@ -370,8 +380,8 @@ QTreeWidgetItem *GroupTreeWidget::addSearchItem(const QString& search_string, ui
{ {
QTreeWidgetItem *item = addCategoryItem(search_string,icon,true); QTreeWidgetItem *item = addCategoryItem(search_string,icon,true);
item->setData(COLUMN_DATA,ROLE_SEARCH_STRING,search_string) ; item->setData(GTW_COLUMN_DATA,ROLE_SEARCH_STRING,search_string) ;
item->setData(COLUMN_DATA,ROLE_REQUEST_ID ,id) ; item->setData(GTW_COLUMN_DATA,ROLE_REQUEST_ID ,id) ;
return item; return item;
} }
@ -392,7 +402,7 @@ bool GroupTreeWidget::isSearchRequestResult(QPoint &point,QString& group_id,uint
if(parent == NULL) if(parent == NULL)
return false ; return false ;
search_req_id = parent->data(COLUMN_DATA, ROLE_REQUEST_ID).toUInt(); search_req_id = parent->data(GTW_COLUMN_DATA, ROLE_REQUEST_ID).toUInt();
group_id = itemId(item) ; group_id = itemId(item) ;
return search_req_id > 0; return search_req_id > 0;
@ -405,7 +415,7 @@ bool GroupTreeWidget::isSearchRequestResultItem(QTreeWidgetItem *item,QString& g
if(parent == NULL) if(parent == NULL)
return false ; return false ;
search_req_id = parent->data(COLUMN_DATA, ROLE_REQUEST_ID).toUInt(); search_req_id = parent->data(GTW_COLUMN_DATA, ROLE_REQUEST_ID).toUInt();
group_id = itemId(item) ; group_id = itemId(item) ;
return search_req_id > 0; return search_req_id > 0;
@ -417,7 +427,7 @@ bool GroupTreeWidget::isSearchRequestItem(QPoint &point,uint32_t& search_req_id)
if (item == NULL) if (item == NULL)
return false; return false;
search_req_id = item->data(COLUMN_DATA, ROLE_REQUEST_ID).toUInt(); search_req_id = item->data(GTW_COLUMN_DATA, ROLE_REQUEST_ID).toUInt();
return search_req_id > 0; return search_req_id > 0;
} }
@ -428,7 +438,7 @@ QString GroupTreeWidget::itemId(QTreeWidgetItem *item)
return ""; return "";
} }
return item->data(COLUMN_DATA, ROLE_ID).toString(); return item->data(GTW_COLUMN_DATA, ROLE_ID).toString();
} }
QString GroupTreeWidget::itemIdAt(QPoint &point) QString GroupTreeWidget::itemIdAt(QPoint &point)
@ -438,7 +448,7 @@ QString GroupTreeWidget::itemIdAt(QPoint &point)
return ""; return "";
} }
return item->data(COLUMN_DATA, ROLE_ID).toString(); return item->data(GTW_COLUMN_DATA, ROLE_ID).toString();
} }
void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<GroupItemInfo> &itemList) void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<GroupItemInfo> &itemList)
@ -460,7 +470,7 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
int childCount = categoryItem->childCount(); int childCount = categoryItem->childCount();
for (int child = 0; child < childCount; ++child) { for (int child = 0; child < childCount; ++child) {
QTreeWidgetItem *childItem = categoryItem->child(child); QTreeWidgetItem *childItem = categoryItem->child(child);
if (childItem->data(COLUMN_DATA, ROLE_ID).toString() == itemInfo.id) { if (childItem->data(GTW_COLUMN_DATA, ROLE_ID).toString() == itemInfo.id) {
/* Found child */ /* Found child */
item = childItem; item = childItem;
break; break;
@ -469,45 +479,46 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
if (item == NULL) { if (item == NULL) {
item = new RSTreeWidgetItem(compareRole); item = new RSTreeWidgetItem(compareRole);
item->setData(COLUMN_DATA, ROLE_ID, itemInfo.id); item->setData(GTW_COLUMN_DATA, ROLE_ID, itemInfo.id);
categoryItem->addChild(item); categoryItem->addChild(item);
} }
item->setText(COLUMN_NAME, itemInfo.name); item->setText(GTW_COLUMN_NAME, itemInfo.name);
item->setData(COLUMN_DATA, ROLE_NAME, itemInfo.name); item->setData(GTW_COLUMN_DATA, ROLE_NAME, itemInfo.name);
item->setData(COLUMN_DATA, ROLE_DESCRIPTION, itemInfo.description); item->setData(GTW_COLUMN_DATA, ROLE_DESCRIPTION, itemInfo.description);
// Add children for context strings. This happens in the search. // Add children for context strings. This happens in the search.
while(nullptr != item->takeChild(0)); while(nullptr != item->takeChild(0));
for(auto str:itemInfo.context_strings) for(auto& str:itemInfo.context_strings)
if(!str.empty()) if(!str.empty())
{ {
QTreeWidgetItem *it = new QTreeWidgetItem(QStringList(QString::fromUtf8(str.c_str()))); QTreeWidgetItem *wit = new QTreeWidgetItem(QStringList(QString::fromUtf8(str.c_str())));
it->setData(COLUMN_DATA,ROLE_ID,itemInfo.id); wit->setData(GTW_COLUMN_DATA,ROLE_ID,itemInfo.id);
item->addChild(it); item->addChild(wit);
} }
/* Set last post */ /* Set last post */
qlonglong lastPost = itemInfo.lastpost.toTime_t(); qlonglong lastPost = itemInfo.lastpost.toTime_t();
item->setData(COLUMN_DATA, ROLE_LASTPOST, -lastPost); // negative for correct sorting item->setData(GTW_COLUMN_DATA, ROLE_LASTPOST, -lastPost); // negative for correct sorting
if(itemInfo.lastpost == QDateTime::fromTime_t(0)) if(itemInfo.lastpost == QDateTime::fromTime_t(0))
item->setText(COLUMN_LAST_POST, tr("Never")); item->setText(GTW_COLUMN_LAST_POST, tr("Never"));
else else
item->setText(COLUMN_LAST_POST, itemInfo.lastpost.toString(Qt::ISODate).replace("T"," ")); item->setText(GTW_COLUMN_LAST_POST, itemInfo.lastpost.toString(Qt::ISODate).replace("T"," "));
/* Set visible posts */ /* Set visible posts */
item->setData(COLUMN_DATA, ROLE_POSTS, -itemInfo.max_visible_posts);// negative for correct sorting item->setText(GTW_COLUMN_POSTS, QString::number(itemInfo.max_visible_posts));
item->setData(GTW_COLUMN_DATA, ROLE_POSTS, -itemInfo.max_visible_posts);// negative for correct sorting
/* Set icon */ /* Set icon */
item->setIcon(COLUMN_NAME, itemInfo.icon); item->setIcon(GTW_COLUMN_NAME, itemInfo.icon);
/* Set popularity */ /* Set popularity */
QString tooltip = PopularityDefs::tooltip(itemInfo.popularity); QString tooltip = PopularityDefs::tooltip(itemInfo.popularity);
item->setIcon(COLUMN_POPULARITY, PopularityDefs::icon(itemInfo.popularity)); item->setIcon(GTW_COLUMN_POPULARITY, PopularityDefs::icon(itemInfo.popularity));
item->setData(COLUMN_DATA, ROLE_POPULARITY, -itemInfo.popularity); // negative for correct sorting item->setData(GTW_COLUMN_DATA, ROLE_POPULARITY, -itemInfo.popularity); // negative for correct sorting
/* Set tooltip */ /* Set tooltip */
if (itemInfo.adminKey) if (itemInfo.adminKey)
@ -525,31 +536,32 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
if(!IS_GROUP_SUBSCRIBED(itemInfo.subscribeFlags)) if(!IS_GROUP_SUBSCRIBED(itemInfo.subscribeFlags))
tooltip += "\n" + tr("Subscribe to download and read messages") ; tooltip += "\n" + tr("Subscribe to download and read messages") ;
QString desc = itemInfo.description.left(30); QString desc = itemInfo.description.left(30);
desc.replace("\n"," "); desc.replace("\n"," ");
desc.replace("\t"," "); desc.replace("\t"," ");
if(itemInfo.description.length() > 30) if(itemInfo.description.length() > 30)
desc += "..."; desc += "";
tooltip += "\n" + tr("Description") + ": " + desc; tooltip += "\n" + tr("Description") + ": " + desc;
tooltip += "\n" + tr("Id") + ": " + itemInfo.id; tooltip += "\n" + tr("Id") + ": " + itemInfo.id;
item->setToolTip(COLUMN_NAME, tooltip); item->setToolTip(GTW_COLUMN_NAME, tooltip);
item->setToolTip(COLUMN_UNREAD, tooltip); item->setToolTip(GTW_COLUMN_UNREAD, tooltip);
item->setToolTip(COLUMN_POPULARITY, tooltip); item->setToolTip(GTW_COLUMN_POSTS, tooltip);
item->setToolTip(GTW_COLUMN_POPULARITY, tooltip);
item->setData(COLUMN_DATA, ROLE_SUBSCRIBE_FLAGS, itemInfo.subscribeFlags); item->setData(GTW_COLUMN_DATA, ROLE_SUBSCRIBE_FLAGS, itemInfo.subscribeFlags);
/* Set color */ /* Set color */
if (itemInfo.publishKey) { if (itemInfo.publishKey) {
item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_PRIVATEKEY); item->setData(GTW_COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_PRIVATEKEY);
item->setData(COLUMN_NAME, Qt::ForegroundRole, QBrush(textColorPrivateKey())); item->setData(GTW_COLUMN_NAME, Qt::ForegroundRole, QBrush(textColorPrivateKey()));
} else { } else {
// Let StyleSheet color // Let StyleSheet color
item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_STANDARD); item->setData(GTW_COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_STANDARD);
item->setData(COLUMN_NAME, Qt::BackgroundRole, QVariant()); item->setData(GTW_COLUMN_NAME, Qt::BackgroundRole, QVariant());
} }
/* Calculate score */ /* Calculate score */
@ -560,7 +572,7 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
int child = 0; int child = 0;
int childCount = categoryItem->childCount(); int childCount = categoryItem->childCount();
while (child < childCount) { while (child < childCount) {
QString id = categoryItem->child(child)->data(COLUMN_DATA, ROLE_ID).toString(); QString id = categoryItem->child(child)->data(GTW_COLUMN_DATA, ROLE_ID).toString();
for (it = itemList.begin(); it != itemList.end(); ++it) { for (it = itemList.begin(); it != itemList.end(); ++it) {
if (it->id == id) { if (it->id == id) {
@ -585,18 +597,18 @@ void GroupTreeWidget::setUnreadCount(QTreeWidgetItem *item, int unreadCount)
return; return;
} }
QFont font = item->font(COLUMN_NAME); QFont font = item->font(GTW_COLUMN_NAME);
if (unreadCount) { if (unreadCount) {
item->setData(COLUMN_DATA, ROLE_UNREAD, unreadCount); item->setData(GTW_COLUMN_DATA, ROLE_UNREAD, unreadCount);
item->setText(COLUMN_UNREAD, QString::number(unreadCount)); item->setText(GTW_COLUMN_UNREAD, QString::number(unreadCount));
font.setBold(true); font.setBold(true);
} else { } else {
item->setText(COLUMN_UNREAD, ""); item->setText(GTW_COLUMN_UNREAD, "");
font.setBold(false); font.setBold(false);
} }
item->setFont(COLUMN_NAME, font); item->setFont(GTW_COLUMN_NAME, font);
} }
QTreeWidgetItem *GroupTreeWidget::getItemFromId(const QString &id) QTreeWidgetItem *GroupTreeWidget::getItemFromId(const QString &id)
@ -614,7 +626,7 @@ QTreeWidgetItem *GroupTreeWidget::getItemFromId(const QString &id)
if (item->parent() == NULL) { if (item->parent() == NULL) {
continue; continue;
} }
if (item->data(COLUMN_DATA, ROLE_ID).toString() == id) { if (item->data(GTW_COLUMN_DATA, ROLE_ID).toString() == id) {
return item; return item;
} }
} }
@ -642,7 +654,7 @@ bool GroupTreeWidget::setWaiting(const QString &id, bool wait)
return false; return false;
} }
item->setData(COLUMN_NAME, Qt::StatusTipRole, wait ? "waiting" : ""); item->setData(GTW_COLUMN_NAME, Qt::StatusTipRole, wait ? "waiting" : "");
return true; return true;
} }
@ -651,14 +663,14 @@ RSTreeWidget *GroupTreeWidget::treeWidget()
return ui->treeWidget; return ui->treeWidget;
} }
bool GroupTreeWidget::getGroupName(QString id, QString& name) bool GroupTreeWidget::getGroupName(const QString& id, QString& name)
{ {
QTreeWidgetItem *item = getItemFromId(id); QTreeWidgetItem *item = getItemFromId(id);
if (item == NULL) { if (item == NULL) {
return false; return false;
} }
name = item->data(COLUMN_DATA, ROLE_NAME).toString(); name = item->data(GTW_COLUMN_DATA, ROLE_NAME).toString();
return true; return true;
} }
@ -670,7 +682,7 @@ int GroupTreeWidget::subscribeFlags(const QString &id)
return 0; return 0;
} }
return item->data(COLUMN_DATA, ROLE_SUBSCRIBE_FLAGS).toInt(); return item->data(GTW_COLUMN_DATA, ROLE_SUBSCRIBE_FLAGS).toInt();
} }
void GroupTreeWidget::calculateScore(QTreeWidgetItem *item, const QString &filterText) void GroupTreeWidget::calculateScore(QTreeWidgetItem *item, const QString &filterText)
@ -686,10 +698,10 @@ void GroupTreeWidget::calculateScore(QTreeWidgetItem *item, const QString &filte
switch (ui->filterLineEdit->currentFilter()) { switch (ui->filterLineEdit->currentFilter()) {
case FILTER_NAME_INDEX: case FILTER_NAME_INDEX:
scoreString = item->data(COLUMN_DATA, ROLE_NAME).toString(); scoreString = item->data(GTW_COLUMN_DATA, ROLE_NAME).toString();
break; break;
case FILTER_DESC_INDEX: case FILTER_DESC_INDEX:
scoreString = item->data(COLUMN_DATA, ROLE_DESCRIPTION).toString(); scoreString = item->data(GTW_COLUMN_DATA, ROLE_DESCRIPTION).toString();
break; break;
} }
@ -702,7 +714,7 @@ void GroupTreeWidget::calculateScore(QTreeWidgetItem *item, const QString &filte
} }
} }
item->setData(COLUMN_DATA, ROLE_SEARCH_SCORE, -score); // negative for correct sorting item->setData(GTW_COLUMN_DATA, ROLE_SEARCH_SCORE, -score); // negative for correct sorting
return; return;
} }
@ -713,7 +725,7 @@ void GroupTreeWidget::calculateScore(QTreeWidgetItem *item, const QString &filte
while ((tmpItem = *itemIterator) != NULL) { while ((tmpItem = *itemIterator) != NULL) {
++itemIterator; ++itemIterator;
if (tmpItem->data(COLUMN_DATA, ROLE_ID).toString().isEmpty()) { if (tmpItem->data(GTW_COLUMN_DATA, ROLE_ID).toString().isEmpty()) {
continue; continue;
} }
@ -734,26 +746,26 @@ void GroupTreeWidget::resort(QTreeWidgetItem *categoryItem)
Qt::SortOrder order = (actionSortAscending == NULL || actionSortAscending->isChecked()) ? Qt::AscendingOrder : Qt::DescendingOrder; Qt::SortOrder order = (actionSortAscending == NULL || actionSortAscending->isChecked()) ? Qt::AscendingOrder : Qt::DescendingOrder;
if (ui->filterLineEdit->text().isEmpty() == false) { if (ui->filterLineEdit->text().isEmpty() == false) {
compareRole->setRole(COLUMN_DATA, ROLE_SEARCH_SCORE); compareRole->setRole(GTW_COLUMN_DATA, ROLE_SEARCH_SCORE);
compareRole->addRole(COLUMN_DATA, ROLE_LASTPOST); compareRole->addRole(GTW_COLUMN_DATA, ROLE_LASTPOST);
} else if (actionSortByName && actionSortByName->isChecked()) { } else if (actionSortByName && actionSortByName->isChecked()) {
compareRole->setRole(COLUMN_DATA, ROLE_NAME); compareRole->setRole(GTW_COLUMN_DATA, ROLE_NAME);
} else if (actionSortByPopularity && actionSortByPopularity->isChecked()) { } else if (actionSortByPopularity && actionSortByPopularity->isChecked()) {
compareRole->setRole(COLUMN_DATA, ROLE_POPULARITY); compareRole->setRole(GTW_COLUMN_DATA, ROLE_POPULARITY);
} else if (actionSortByLastPost && actionSortByLastPost->isChecked()) { } else if (actionSortByLastPost && actionSortByLastPost->isChecked()) {
compareRole->setRole(COLUMN_DATA, ROLE_LASTPOST); compareRole->setRole(GTW_COLUMN_DATA, ROLE_LASTPOST);
} else if (actionSortByPosts && actionSortByPosts->isChecked()) { } else if (actionSortByPosts && actionSortByPosts->isChecked()) {
compareRole->setRole(COLUMN_DATA, ROLE_POSTS); compareRole->setRole(GTW_COLUMN_DATA, ROLE_POSTS);
} else if (actionSortByUnread && actionSortByUnread->isChecked()) { } else if (actionSortByUnread && actionSortByUnread->isChecked()) {
compareRole->setRole(COLUMN_DATA, ROLE_UNREAD); compareRole->setRole(GTW_COLUMN_DATA, ROLE_UNREAD);
} }
if (categoryItem) { if (categoryItem) {
categoryItem->sortChildren(COLUMN_DATA, order); categoryItem->sortChildren(GTW_COLUMN_DATA, order);
} else { } else {
int count = ui->treeWidget->topLevelItemCount(); int count = ui->treeWidget->topLevelItemCount();
for (int child = 0; child < count; ++child) { for (int child = 0; child < count; ++child) {
ui->treeWidget->topLevelItem(child)->sortChildren(COLUMN_DATA, order); ui->treeWidget->topLevelItem(child)->sortChildren(GTW_COLUMN_DATA, order);
} }
} }
} }
@ -765,6 +777,11 @@ void GroupTreeWidget::distantSearch()
ui->distantSearchLineEdit->clear(); ui->distantSearchLineEdit->clear();
} }
void GroupTreeWidget::showHeader(bool toShow)
{
ui->treeWidget->header()->setVisible(toShow);
}
void GroupTreeWidget::sort() void GroupTreeWidget::sort()
{ {
resort(NULL); resort(NULL);

View File

@ -36,6 +36,14 @@ class RSTreeWidget;
#define GROUPTREEWIDGET_COLOR_PRIVATEKEY 1 #define GROUPTREEWIDGET_COLOR_PRIVATEKEY 1
#define GROUPTREEWIDGET_COLOR_COUNT 2 #define GROUPTREEWIDGET_COLOR_COUNT 2
#define GTW_COLUMN_NAME 0
#define GTW_COLUMN_UNREAD 1
#define GTW_COLUMN_POSTS 2
#define GTW_COLUMN_POPULARITY 3
#define GTW_COLUMN_LAST_POST 4
#define GTW_COLUMN_COUNT 5
#define GTW_COLUMN_DATA GTW_COLUMN_NAME
namespace Ui { namespace Ui {
class GroupTreeWidget; class GroupTreeWidget;
} }
@ -112,7 +120,7 @@ public:
void setTextColorCategory(QColor color) { mTextColor[GROUPTREEWIDGET_COLOR_CATEGORY] = color; } void setTextColorCategory(QColor color) { mTextColor[GROUPTREEWIDGET_COLOR_CATEGORY] = color; }
void setTextColorPrivateKey(QColor color) { mTextColor[GROUPTREEWIDGET_COLOR_PRIVATEKEY] = color; } void setTextColorPrivateKey(QColor color) { mTextColor[GROUPTREEWIDGET_COLOR_PRIVATEKEY] = color; }
bool getGroupName(QString id, QString& name); bool getGroupName(const QString& id, QString& name);
int subscribeFlags(const QString &id); int subscribeFlags(const QString &id);
@ -132,6 +140,7 @@ private slots:
void filterChanged(); void filterChanged();
void distantSearch(); void distantSearch();
void showHeader(bool toShow);
void sort(); void sort();
private: private:
@ -143,6 +152,7 @@ private:
private: private:
QMenu *displayMenu; QMenu *displayMenu;
QAction *actionShowHeader;
QAction *actionSortAscending; QAction *actionSortAscending;
QAction *actionSortDescending; QAction *actionSortDescending;
QAction *actionSortByName; QAction *actionSortByName;

View File

@ -101,7 +101,7 @@ GxsGroupFrameDialog::GxsGroupFrameDialog(RsGxsIfaceHelper *ifaceImpl, QWidget *p
mStateHelper->setLoading(TOKEN_TYPE_GROUP_SUMMARY, true); mStateHelper->setLoading(TOKEN_TYPE_GROUP_SUMMARY, true);
connect(ui->groupTreeWidget, SIGNAL(treeCustomContextMenuRequested(QPoint)), this, SLOT(groupTreeCustomPopupMenu(QPoint))); connect(ui->groupTreeWidget, SIGNAL(treeCustomContextMenuRequested(QPoint)), this, SLOT(groupTreeCustomPopupMenu(QPoint)));
connect(ui->groupTreeWidget, SIGNAL(treeCurrentItemChanged(QString)), this, SLOT(changedCurrentGroup(QString))); connect(ui->groupTreeWidget, SIGNAL(treeCurrentItemChanged(QString)), this, SLOT(changedCurrentGroup(QString)));
connect(ui->groupTreeWidget->treeWidget(), SIGNAL(signalMouseMiddleButtonClicked(QTreeWidgetItem*)), this, SLOT(groupTreeMiddleButtonClicked(QTreeWidgetItem*))); connect(ui->groupTreeWidget->treeWidget(), SIGNAL(signalMouseMiddleButtonClicked(QTreeWidgetItem*)), this, SLOT(groupTreeMiddleButtonClicked(QTreeWidgetItem*)));
connect(ui->messageTabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(messageTabCloseRequested(int))); connect(ui->messageTabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(messageTabCloseRequested(int)));
connect(ui->messageTabWidget, SIGNAL(currentChanged(int)), this, SLOT(messageTabChanged(int))); connect(ui->messageTabWidget, SIGNAL(currentChanged(int)), this, SLOT(messageTabChanged(int)));
@ -324,7 +324,7 @@ void GxsGroupFrameDialog::updateSearchResults(const TurtleRequestId& sid)
for(auto it3(group_infos.begin());it3!=group_infos.end();++it3) for(auto it3(group_infos.begin());it3!=group_infos.end();++it3)
{ {
std::cerr << " adding group " << it3->first << " " << it3->second.mGroupId << " \"" << it3->second.mGroupName << "\"" << std::endl; std::cerr << " adding group " << it3->first << " " << it3->second.mGroupId << " \"" << it3->second.mGroupName << "\"" << std::endl;
for(auto s:it3->second.mSearchContexts) for(auto& s:it3->second.mSearchContexts)
std::cerr << " Context string \"" << s << "\"" << std::endl; std::cerr << " Context string \"" << s << "\"" << std::endl;
GroupItemInfo i; GroupItemInfo i;
@ -409,121 +409,113 @@ uint32_t GxsGroupFrameDialog::checkDelay(uint32_t time_in_secs)
void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point) void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point)
{ {
QMenu contextMnu(this);
// First separately handle the case of search top level items // First separately handle the case of search top level items
TurtleRequestId search_request_id = 0 ; TurtleRequestId search_request_id = 0 ;
QString group_id_s;
if(ui->groupTreeWidget->isSearchRequestItem(point,search_request_id)) if(ui->groupTreeWidget->isSearchRequestItem(point,search_request_id))
{ {
QMenu contextMnu(this); contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_DELETE), tr("Remove this search"), this, SLOT(removeCurrentSearch()))->setData(search_request_id);
contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_DELETE), tr("Remove all searches"), this, SLOT(removeAllSearches()));
contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_DELETE), tr("Remove this search"), this, SLOT(removeCurrentSearch()))->setData(search_request_id);
contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_DELETE), tr("Remove all searches"), this, SLOT(removeAllSearches()));
contextMnu.exec(QCursor::pos());
return ;
} }
// Then check whether we have a searched item, or a normal group // Then check whether we have a searched item, or a normal group
else if(ui->groupTreeWidget->isSearchRequestResult(point,group_id_s,search_request_id))
QString group_id_s ; {
contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_RETRIEVE), tr("Request data"), this, SLOT(distantRequestGroupData()))->setData(group_id_s);
if(ui->groupTreeWidget->isSearchRequestResult(point,group_id_s,search_request_id))
{
QMenu contextMnu(this);
contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_RETRIEVE), tr("Request data"), this, SLOT(distantRequestGroupData()))->setData(group_id_s);
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 isSubscribed = IS_GROUP_SUBSCRIBED(subscribeFlags);
QMenu contextMnu(this);
QAction *action;
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_TABNEW), tr("Open in new tab"), this, SLOT(openInNewTab()));
if(mGroupId.isNull()) // dont enable the open in tab if a tab is already here
action->setEnabled(false);
if (isSubscribed) {
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_UNSUBSCRIBE), tr("Unsubscribe"), this, SLOT(unsubscribeGroup()));
action->setEnabled (!mGroupId.isNull() && IS_GROUP_SUBSCRIBED(subscribeFlags));
} else {
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_SUBSCRIBE), tr("Subscribe"), this, SLOT(subscribeGroup()));
action->setDisabled (mGroupId.isNull() || IS_GROUP_SUBSCRIBED(subscribeFlags));
} }
contextMnu.addSeparator(); else // Group Id
{
QString id = ui->groupTreeWidget->itemIdAt(point);
if (!id.isEmpty())
{
mGroupId = RsGxsGroupId(id.toStdString());
int subscribeFlags = ui->groupTreeWidget->subscribeFlags(QString::fromStdString(mGroupId.toStdString()));
contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(icon(ICON_NEW)), text(TEXT_NEW), this, SLOT(newGroup())); bool isAdmin = IS_GROUP_ADMIN(subscribeFlags);
bool isPublisher = IS_GROUP_PUBLISHER(subscribeFlags);
bool isSubscribed = IS_GROUP_SUBSCRIBED(subscribeFlags);
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_INFO), tr("Show Details"), this, SLOT(showGroupDetails())); QAction *action;
action->setEnabled (!mGroupId.isNull());
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_EDIT), tr("Edit Details"), this, SLOT(editGroupDetails())); action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_TABNEW), tr("Open in new tab"), this, SLOT(openInNewTab()));
action->setEnabled (!mGroupId.isNull() && isAdmin);
uint32_t current_store_time = checkDelay(mInterface->getStoragePeriod(mGroupId))/86400 ; if(mGroupId.isNull()) // dont enable the open in tab if a tab is already here
uint32_t current_sync_time = checkDelay(mInterface->getSyncPeriod(mGroupId))/86400 ; action->setEnabled(false);
std::cerr << "Got sync=" << current_sync_time << ". store=" << current_store_time << std::endl; if (isSubscribed) {
QAction *actnn = NULL; action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_UNSUBSCRIBE), tr("Unsubscribe"), this, SLOT(unsubscribeGroup()));
action->setEnabled (!mGroupId.isNull() && IS_GROUP_SUBSCRIBED(subscribeFlags));
} else {
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_SUBSCRIBE), tr("Subscribe"), this, SLOT(subscribeGroup()));
action->setDisabled (mGroupId.isNull() || IS_GROUP_SUBSCRIBED(subscribeFlags));
}
QMenu *ctxMenu2 = contextMnu.addMenu(tr("Synchronise posts of last...")) ; contextMnu.addSeparator();
actnn = ctxMenu2->addAction(tr(" 5 days" ),this,SLOT(setSyncPostsDelay())) ; actnn->setData(QVariant( 5)) ; if(current_sync_time == 5) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 2 weeks" ),this,SLOT(setSyncPostsDelay())) ; actnn->setData(QVariant( 15)) ; if(current_sync_time == 15) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 1 month" ),this,SLOT(setSyncPostsDelay())) ; actnn->setData(QVariant( 30)) ; if(current_sync_time == 30) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 3 months" ),this,SLOT(setSyncPostsDelay())) ; actnn->setData(QVariant( 90)) ; if(current_sync_time == 90) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 6 months" ),this,SLOT(setSyncPostsDelay())) ; actnn->setData(QVariant(180)) ; if(current_sync_time ==180) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 1 year " ),this,SLOT(setSyncPostsDelay())) ; actnn->setData(QVariant(365)) ; if(current_sync_time ==365) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" Indefinitly"),this,SLOT(setSyncPostsDelay())) ; actnn->setData(QVariant( 0)) ; if(current_sync_time == 0) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
ctxMenu2->setEnabled(isSubscribed);
ctxMenu2 = contextMnu.addMenu(tr("Store posts for at most...")) ; contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(icon(ICON_NEW)), text(TEXT_NEW), this, SLOT(newGroup()));
actnn = ctxMenu2->addAction(tr(" 5 days" ),this,SLOT(setStorePostsDelay())) ; actnn->setData(QVariant( 5)) ; if(current_store_time == 5) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 2 weeks" ),this,SLOT(setStorePostsDelay())) ; actnn->setData(QVariant( 15)) ; if(current_store_time == 15) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 1 month" ),this,SLOT(setStorePostsDelay())) ; actnn->setData(QVariant( 30)) ; if(current_store_time == 30) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 3 months" ),this,SLOT(setStorePostsDelay())) ; actnn->setData(QVariant( 90)) ; if(current_store_time == 90) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 6 months" ),this,SLOT(setStorePostsDelay())) ; actnn->setData(QVariant(180)) ; if(current_store_time ==180) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 1 year " ),this,SLOT(setStorePostsDelay())) ; actnn->setData(QVariant(365)) ; if(current_store_time ==365) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" Indefinitly"),this,SLOT(setStorePostsDelay())) ; actnn->setData(QVariant( 0)) ; if(current_store_time == 0) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
ctxMenu2->setEnabled(isSubscribed);
if (shareKeyType()) { action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_INFO), tr("Show Details"), this, SLOT(showGroupDetails()));
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_SHARE), tr("Share publish permissions..."), this, SLOT(sharePublishKey())); action->setEnabled (!mGroupId.isNull());
action->setEnabled(!mGroupId.isNull() && isPublisher);
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_EDIT), tr("Edit Details"), this, SLOT(editGroupDetails()));
action->setEnabled (!mGroupId.isNull() && isAdmin);
uint32_t current_store_time = checkDelay(mInterface->getStoragePeriod(mGroupId))/86400 ;
uint32_t current_sync_time = checkDelay(mInterface->getSyncPeriod(mGroupId))/86400 ;
std::cerr << "Got sync=" << current_sync_time << ". store=" << current_store_time << std::endl;
QAction *actnn = NULL;
QMenu *ctxMenu2 = contextMnu.addMenu(tr("Synchronise posts of last...")) ;
actnn = ctxMenu2->addAction(tr(" 5 days" ),this,SLOT(setSyncPostsDelay())) ; actnn->setData(QVariant( 5)) ; if(current_sync_time == 5) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 2 weeks" ),this,SLOT(setSyncPostsDelay())) ; actnn->setData(QVariant( 15)) ; if(current_sync_time == 15) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 1 month" ),this,SLOT(setSyncPostsDelay())) ; actnn->setData(QVariant( 30)) ; if(current_sync_time == 30) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 3 months" ),this,SLOT(setSyncPostsDelay())) ; actnn->setData(QVariant( 90)) ; if(current_sync_time == 90) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 6 months" ),this,SLOT(setSyncPostsDelay())) ; actnn->setData(QVariant(180)) ; if(current_sync_time ==180) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 1 year " ),this,SLOT(setSyncPostsDelay())) ; actnn->setData(QVariant(365)) ; if(current_sync_time ==365) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" Indefinitly"),this,SLOT(setSyncPostsDelay())) ; actnn->setData(QVariant( 0)) ; if(current_sync_time == 0) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
ctxMenu2->setEnabled(isSubscribed);
ctxMenu2 = contextMnu.addMenu(tr("Store posts for at most...")) ;
actnn = ctxMenu2->addAction(tr(" 5 days" ),this,SLOT(setStorePostsDelay())) ; actnn->setData(QVariant( 5)) ; if(current_store_time == 5) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 2 weeks" ),this,SLOT(setStorePostsDelay())) ; actnn->setData(QVariant( 15)) ; if(current_store_time == 15) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 1 month" ),this,SLOT(setStorePostsDelay())) ; actnn->setData(QVariant( 30)) ; if(current_store_time == 30) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 3 months" ),this,SLOT(setStorePostsDelay())) ; actnn->setData(QVariant( 90)) ; if(current_store_time == 90) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 6 months" ),this,SLOT(setStorePostsDelay())) ; actnn->setData(QVariant(180)) ; if(current_store_time ==180) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" 1 year " ),this,SLOT(setStorePostsDelay())) ; actnn->setData(QVariant(365)) ; if(current_store_time ==365) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
actnn = ctxMenu2->addAction(tr(" Indefinitly"),this,SLOT(setStorePostsDelay())) ; actnn->setData(QVariant( 0)) ; if(current_store_time == 0) { actnn->setEnabled(false);actnn->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/start.png"));}
ctxMenu2->setEnabled(isSubscribed);
if (shareKeyType()) {
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_SHARE), tr("Share publish permissions..."), this, SLOT(sharePublishKey()));
action->setEnabled(!mGroupId.isNull() && isPublisher);
}
if (getLinkType() != RetroShareLink::TYPE_UNKNOWN) {
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyGroupLink()));
action->setEnabled(!mGroupId.isNull());
}
contextMnu.addSeparator();
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(":/images/message-mail-read.png"), tr("Mark all as read"), this, SLOT(markMsgAsRead()));
action->setEnabled (!mGroupId.isNull() && isSubscribed);
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(":/images/message-mail.png"), tr("Mark all as unread"), this, SLOT(markMsgAsUnread()));
action->setEnabled (!mGroupId.isNull() && isSubscribed);
/* Add special actions */
QList<QAction*> actions;
groupTreeCustomActions(mGroupId, subscribeFlags, actions);
if (!actions.isEmpty()) {
contextMnu.addSeparator();
contextMnu.addActions(actions);
}
}
} }
if (getLinkType() != RetroShareLink::TYPE_UNKNOWN) {
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyGroupLink()));
action->setEnabled(!mGroupId.isNull());
}
contextMnu.addSeparator();
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(":/images/message-mail-read.png"), tr("Mark all as read"), this, SLOT(markMsgAsRead()));
action->setEnabled (!mGroupId.isNull() && isSubscribed);
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(":/images/message-mail.png"), tr("Mark all as unread"), this, SLOT(markMsgAsUnread()));
action->setEnabled (!mGroupId.isNull() && isSubscribed);
/* Add special actions */
QList<QAction*> actions;
groupTreeCustomActions(mGroupId, subscribeFlags, actions);
if (!actions.isEmpty()) {
contextMnu.addSeparator();
contextMnu.addActions(actions);
}
//Add Standard Menu //Add Standard Menu
ui->groupTreeWidget->treeWidget()->createStandardContextMenu(&contextMnu); ui->groupTreeWidget->treeWidget()->createStandardContextMenu(&contextMnu);
@ -731,10 +723,10 @@ void GxsGroupFrameDialog::loadComment(const RsGxsGroupId &grpId, const QVector<R
if (title.length() > MAX_COMMENT_TITLE) if (title.length() > MAX_COMMENT_TITLE)
{ {
comments.truncate(MAX_COMMENT_TITLE - 3); comments.truncate(MAX_COMMENT_TITLE - 3);
comments += "..."; comments += "";
} }
commentDialog = new GxsCommentDialog(this,RsGxsId(), mInterface->getTokenService(), commentService); commentDialog = new GxsCommentDialog(this,RsGxsId(), mInterface->getTokenService(), commentService);
QWidget *commentHeader = createCommentHeaderWidget(grpId, most_recent_msgId); QWidget *commentHeader = createCommentHeaderWidget(grpId, most_recent_msgId);
if (commentHeader) { if (commentHeader) {
@ -1025,13 +1017,13 @@ void GxsGroupFrameDialog::insertGroupsData(const std::list<RsGxsGenericGroupData
/* now we can add them in as a tree! */ /* now we can add them in as a tree! */
ui->groupTreeWidget->fillGroupItems(mYourGroups, adminList); ui->groupTreeWidget->fillGroupItems(mYourGroups, adminList);
mYourGroups->setText(2, QString::number(mYourGroups->childCount())); mYourGroups->setText(GTW_COLUMN_POPULARITY, QString::number(mYourGroups->childCount()));
ui->groupTreeWidget->fillGroupItems(mSubscribedGroups, subList); ui->groupTreeWidget->fillGroupItems(mSubscribedGroups, subList);
mSubscribedGroups->setText(2, QString::number(mSubscribedGroups->childCount())); // 1 COLUMN_UNREAD 2 COLUMN_POPULARITY mSubscribedGroups->setText(GTW_COLUMN_POPULARITY, QString::number(mSubscribedGroups->childCount())); // 1 COLUMN_UNREAD 2 COLUMN_POPULARITY
ui->groupTreeWidget->fillGroupItems(mPopularGroups, popList); ui->groupTreeWidget->fillGroupItems(mPopularGroups, popList);
mPopularGroups->setText(2, QString::number(mPopularGroups->childCount())); mPopularGroups->setText(GTW_COLUMN_POPULARITY, QString::number(mPopularGroups->childCount()));
ui->groupTreeWidget->fillGroupItems(mOtherGroups, otherList); ui->groupTreeWidget->fillGroupItems(mOtherGroups, otherList);
mOtherGroups->setText(2, QString::number(mOtherGroups->childCount())); mOtherGroups->setText(GTW_COLUMN_POPULARITY, QString::number(mOtherGroups->childCount()));
mInFill = false; mInFill = false;
@ -1061,7 +1053,7 @@ void GxsGroupFrameDialog::updateMessageSummaryListReal(RsGxsGroupId groupId)
} }
if (groupId.isNull()) if (groupId.isNull())
{ {
QTreeWidgetItem *items[2] = { mYourGroups, mSubscribedGroups }; QTreeWidgetItem *items[2] = { mYourGroups, mSubscribedGroups };
for (int item = 0; item < 2; ++item) { for (int item = 0; item < 2; ++item) {
int child; int child;
@ -1076,7 +1068,7 @@ void GxsGroupFrameDialog::updateMessageSummaryListReal(RsGxsGroupId groupId)
} }
} }
} }
else else
updateGroupStatistics(groupId); updateGroupStatistics(groupId);
} }
@ -1190,18 +1182,18 @@ void GxsGroupFrameDialog::getServiceStatistics(GxsServiceStatistic& stats) const
{ {
stats = GxsServiceStatistic(); // clears everything stats = GxsServiceStatistic(); // clears everything
for(auto it: mCachedGroupStats) for(auto& it: mCachedGroupStats)
{ {
const GxsGroupStatistic& s(it.second); const GxsGroupStatistic& s(it.second);
stats.mNumMsgs += s.mNumMsgs; stats.mNumMsgs += s.mNumMsgs;
stats.mNumGrps += 1; stats.mNumGrps += 1;
stats.mSizeOfMsgs += s.mTotalSizeOfMsgs; stats.mSizeOfMsgs += s.mTotalSizeOfMsgs;
stats.mNumThreadMsgsNew += s.mNumThreadMsgsNew; stats.mNumThreadMsgsNew += s.mNumThreadMsgsNew;
stats.mNumThreadMsgsUnread += s.mNumThreadMsgsUnread; stats.mNumThreadMsgsUnread += s.mNumThreadMsgsUnread;
stats.mNumChildMsgsNew += s.mNumChildMsgsNew ; stats.mNumChildMsgsNew += s.mNumChildMsgsNew ;
stats.mNumChildMsgsUnread += s.mNumChildMsgsUnread ; stats.mNumChildMsgsUnread += s.mNumChildMsgsUnread ;
} }
} }
TurtleRequestId GxsGroupFrameDialog::distantSearch(const QString& search_string) // this should be overloaded in the child class TurtleRequestId GxsGroupFrameDialog::distantSearch(const QString& search_string) // this should be overloaded in the child class