added channel search to channelfeed ui

fixed timestamp not being set in p3distrib 
and also removed memory look in channel ui (fillchannelList)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3677 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2010-10-17 14:43:49 +00:00
parent af8ad4e862
commit 884f0e7a22
5 changed files with 330 additions and 82 deletions

View File

@ -692,6 +692,10 @@ void p3GroupDistrib::loadMsg(RsDistribSignedMsg *newMsg, std::string src, bool l
/* accept message */ /* accept message */
(git->second).msgs[msg->msgId] = msg; (git->second).msgs[msg->msgId] = msg;
// update the time stamp of group for last post
if((git->second.lastPost < msg->timestamp))
git->second.lastPost = msg->timestamp;
/* now update parents TS */ /* now update parents TS */
locked_updateChildTS(git->second, msg); locked_updateChildTS(git->second, msg);

View File

@ -22,6 +22,7 @@
#include <QMenu> #include <QMenu>
#include <QTimer> #include <QTimer>
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QDateTime>
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
@ -48,6 +49,8 @@
#define ROLE_ID Qt::UserRole #define ROLE_ID Qt::UserRole
#define ROLE_CHANNEL_TITLE Qt::UserRole + 1 #define ROLE_CHANNEL_TITLE Qt::UserRole + 1
#define ROLE_CHANNEL_DESC Qt::UserRole + 2
#define ROLE_CHANNEL_TS Qt::UserRole + 3
/**** /****
* #define CHAN_DEBUG * #define CHAN_DEBUG
@ -65,6 +68,9 @@ ChannelFeed::ChannelFeed(QWidget *parent)
connect(subscribeButton, SIGNAL( clicked( void ) ), this, SLOT( subscribeChannel ( void ) ) ); connect(subscribeButton, SIGNAL( clicked( void ) ), this, SLOT( subscribeChannel ( void ) ) );
connect(unsubscribeButton, SIGNAL( clicked( void ) ), this, SLOT( unsubscribeChannel ( void ) ) ); connect(unsubscribeButton, SIGNAL( clicked( void ) ), this, SLOT( unsubscribeChannel ( void ) ) );
connect(setAllAsReadButton, SIGNAL(clicked()), this, SLOT(setAllAsReadClicked())); connect(setAllAsReadButton, SIGNAL(clicked()), this, SLOT(setAllAsReadClicked()));
connect(searchLine, SIGNAL(returnPressed()), this, SLOT(searchChannels( void )));
connect(pushButtonSearch, SIGNAL(clicked()), this, SLOT(searchChannels( void )));
connect(resetButton, SIGNAL(clicked()), this, SLOT(finishSearching( void )));
connect(NotifyQt::getInstance(), SIGNAL(channelMsgReadSatusChanged(QString,QString,int)), this, SLOT(channelMsgReadSatusChanged(QString,QString,int))); connect(NotifyQt::getInstance(), SIGNAL(channelMsgReadSatusChanged(QString,QString,int)), this, SLOT(channelMsgReadSatusChanged(QString,QString,int)));
@ -130,6 +136,7 @@ ChannelFeed::ChannelFeed(QWidget *parent)
channelmenu->addAction(actionCreate_Channel); channelmenu->addAction(actionCreate_Channel);
channelmenu->addSeparator(); channelmenu->addSeparator();
channelpushButton->setMenu(channelmenu); channelpushButton->setMenu(channelmenu);
resetButton->setVisible(false);
updateChannelMsgs(); updateChannelMsgs();
} }
@ -288,6 +295,45 @@ void ChannelFeed::updateDisplay()
} }
} }
void ChannelFeed::searchChannels(){
// do not allow update of page (new items to be added)
RsAutoUpdatePage::lockAllEvents();
if(searchLine->text().isEmpty())
finishSearching();
resetButton->setVisible(true);
QChannelItem::setSearchText(searchLine->text());
model->item(OWN)->sortChildren(COLUMN_NAME, Qt::DescendingOrder);
model->item(SUBSCRIBED)->sortChildren(COLUMN_NAME, Qt::DescendingOrder);
model->item(POPULAR)->sortChildren(COLUMN_NAME, Qt::DescendingOrder);
model->item(OTHER)->sortChildren(COLUMN_NAME, Qt::DescendingOrder);
return;
}
void ChannelFeed::finishSearching(){
// unlock channel page update if user is done searching
RsAutoUpdatePage::unlockAllEvents();
searchLine->clear();
resetButton->setVisible(false);
return;
}
void ChannelFeed::searchMessages(){
return;
}
void ChannelFeed::updateChannelList() void ChannelFeed::updateChannelList()
{ {
if (!rsChannels) { if (!rsChannels) {
@ -310,7 +356,8 @@ void ChannelFeed::updateChannelList()
/* sort it into Publish (Own), Subscribed, Popular and Other */ /* sort it into Publish (Own), Subscribed, Popular and Other */
uint32_t flags = it->channelFlags; uint32_t flags = it->channelFlags;
if ((flags & RS_DISTRIB_ADMIN) && (flags & RS_DISTRIB_SUBSCRIBED)) { if ((flags & (RS_DISTRIB_ADMIN | RS_DISTRIB_PUBLISH)) && (flags & RS_DISTRIB_SUBSCRIBED)
) {
adminList.push_back(*it); adminList.push_back(*it);
} else if (flags & RS_DISTRIB_SUBSCRIBED) { } else if (flags & RS_DISTRIB_SUBSCRIBED) {
subList.push_back(*it); subList.push_back(*it);
@ -376,14 +423,14 @@ void ChannelFeed::fillChannelList(int channelItem, std::list<ChannelInfo> &chann
} }
} }
QStandardItem *chNameItem = new QStandardItem(); QStandardItem *chNameItem = NULL;//new QChannelItem(); // use channel item to enable channel specific sorting
QStandardItem *chPopItem = new QStandardItem(); QStandardItem *chPopItem = NULL;// new QStandardItem();
if (row < rowCount) { if (row < rowCount) {
chNameItem = groupItem->child(row, COLUMN_NAME); chNameItem = groupItem->child(row, COLUMN_NAME);
chPopItem = groupItem->child(row, COLUMN_POPULARITY); chPopItem = groupItem->child(row, COLUMN_POPULARITY);
} else { } else {
QList<QStandardItem*> channel; QList<QStandardItem*> channel;
chNameItem = new QStandardItem(); chNameItem = new QChannelItem();
chPopItem = new QStandardItem(); chPopItem = new QStandardItem();
chNameItem->setSizeHint(QSize(22, 22)); chNameItem->setSizeHint(QSize(22, 22));
@ -397,6 +444,11 @@ void ChannelFeed::fillChannelList(int channelItem, std::list<ChannelInfo> &chann
chNameItem->setText(QString::fromStdWString(ci.channelName)); chNameItem->setText(QString::fromStdWString(ci.channelName));
groupItem->child(chNameItem->index().row(), COLUMN_DATA)->setData(QString::fromStdWString(ci.channelName), ROLE_CHANNEL_TITLE); groupItem->child(chNameItem->index().row(), COLUMN_DATA)->setData(QString::fromStdWString(ci.channelName), ROLE_CHANNEL_TITLE);
// important for searching channels
groupItem->child(chNameItem->index().row(), COLUMN_DATA)->setData(QString::fromStdWString(ci.channelDesc), ROLE_CHANNEL_DESC);
groupItem->child(chNameItem->index().row(), COLUMN_DATA)->setData(QDateTime::fromTime_t(ci.lastPost), ROLE_CHANNEL_TS);
chNameItem->setToolTip(tr("Popularity: %1\nFetches: %2\nAvailable: %3").arg(QString::number(ci.pop)).arg(9999).arg(9999)); chNameItem->setToolTip(tr("Popularity: %1\nFetches: %2\nAvailable: %3").arg(QString::number(ci.pop)).arg(9999).arg(9999));
QPixmap chanImage; QPixmap chanImage;
@ -443,6 +495,7 @@ void ChannelFeed::fillChannelList(int channelItem, std::list<ChannelInfo> &chann
row++; row++;
} }
} }
} }
void ChannelFeed::channelMsgReadSatusChanged(const QString& channelId, const QString& msgId, int status) void ChannelFeed::channelMsgReadSatusChanged(const QString& channelId, const QString& msgId, int status)
@ -651,3 +704,47 @@ void ChannelFeed::setAllAsReadClicked()
} }
} }
} }
QString QChannelItem::searchText = "";
QChannelItem::QChannelItem()
: QStandardItem(){
}
QChannelItem::~QChannelItem(){
}
bool QChannelItem::operator<(const QStandardItem& other) const {
// calculate *this/other search scores
int otherCount = other.data(ROLE_CHANNEL_TITLE).toString().count(searchText,Qt::CaseInsensitive);
otherCount += other.data(ROLE_CHANNEL_DESC).toString().count(searchText,Qt::CaseInsensitive);
int thisCount = this->data(ROLE_CHANNEL_TITLE).toString().count(searchText, Qt:: CaseInsensitive);
thisCount += this->data(ROLE_CHANNEL_DESC).toString().count(searchText, Qt:: CaseInsensitive);
uint otherChanTs = other.data(ROLE_CHANNEL_TS).toDateTime().toTime_t();
uint thisChanTs = this->data(ROLE_CHANNEL_TS).toDateTime().toTime_t();
// if counts are equal then determine by who has the most recent post
if(otherCount == thisCount){
if(otherChanTs < thisChanTs)
return true;
}
// choose the item where the string occurs the most
if(thisCount < otherCount)
return true;
return false;
}
void QChannelItem::setSearchText(const QString& sText){
searchText = sText;
return;
}

View File

@ -23,6 +23,7 @@
#define _CHANNEL_FEED_DIALOG_H #define _CHANNEL_FEED_DIALOG_H
#include <retroshare/rschannels.h> #include <retroshare/rschannels.h>
#include <QStandardItemModel>
#include "mainpage.h" #include "mainpage.h"
#include "RsAutoUpdatePage.h" #include "RsAutoUpdatePage.h"
@ -31,6 +32,8 @@
#include "gui/feeds/FeedHolder.h" #include "gui/feeds/FeedHolder.h"
#define OWN 0 #define OWN 0
#define SUBSCRIBED 1 #define SUBSCRIBED 1
#define POPULAR 2 #define POPULAR 2
@ -78,6 +81,9 @@ private slots:
void shareKey(); void shareKey();
void channelMsgReadSatusChanged(const QString& channelId, const QString& msgId, int status); void channelMsgReadSatusChanged(const QString& channelId, const QString& msgId, int status);
void searchChannels();
void searchMessages();
void finishSearching();
private: private:
void updateChannelList(); void updateChannelList();
@ -99,6 +105,30 @@ private:
QFont itemFont; QFont itemFont;
}; };
class QChannelItem : public QStandardItem
{
public:
QChannelItem();
virtual ~QChannelItem();
/**
* Allows users to set the search text for QChannel items
* @param
*/
static void setSearchText(const QString& sText);
/**
* reimplementing comparison operator so QChannelItems can be ordered in terms
* of occurences of property searchText in its data columns
*/
bool operator<(const QStandardItem& other) const;
private:
static QString searchText;
};
#endif #endif

View File

@ -68,13 +68,7 @@
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QGridLayout" name="gridLayout_5"> <layout class="QGridLayout" name="gridLayout_9">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QFrame" name="chheaderframe"> <widget class="QFrame" name="chheaderframe">
<property name="minimumSize"> <property name="minimumSize">
@ -110,10 +104,7 @@ border: 1px solid #CCCCCC;}
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QGridLayout" name="gridLayout_6"> <layout class="QGridLayout" name="gridLayout_5">
<property name="margin">
<number>2</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<layout class="QGridLayout" name="_2"> <layout class="QGridLayout" name="_2">
<property name="verticalSpacing"> <property name="verticalSpacing">
@ -151,50 +142,6 @@ p, li { white-space: pre-wrap; }
</item> </item>
</layout> </layout>
</item> </item>
<item row="0" column="3">
<widget class="QPushButton" name="channelpushButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Add</string>
</property>
<property name="styleSheet">
<string notr="true">QPushButton::menu-indicator {
subcontrol-origin: padding;
subcontrol-position: bottom right;
}
QPushButton::menu-indicator:pressed, QPushButton::menu-indicator:open {
position: relative;
top: 2px; left: 2px; /* shift the arrow by 2 px */
}
QPushButton:hover {
border: 1px solid #CCCCCC;
}</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="images.qrc">
<normaloff>:/images/edit_add24.png</normaloff>:/images/edit_add24.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<spacer name="horizontalSpacer_3"> <spacer name="horizontalSpacer_3">
<property name="orientation"> <property name="orientation">
@ -246,10 +193,198 @@ p, li { white-space: pre-wrap; }
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="3">
<widget class="QPushButton" name="channelpushButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Add</string>
</property>
<property name="styleSheet">
<string notr="true">QPushButton::menu-indicator {
subcontrol-origin: padding;
subcontrol-position: bottom right;
}
QPushButton::menu-indicator:pressed, QPushButton::menu-indicator:open {
position: relative;
top: 2px; left: 2px; /* shift the arrow by 2 px */
}
QPushButton:hover {
border: 1px solid #CCCCCC;
}</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="images.qrc">
<normaloff>:/images/edit_add24.png</normaloff>:/images/edit_add24.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
<zorder>channelpushButton</zorder>
<zorder>postButton</zorder>
<zorder>treeView</zorder>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="searchlineframe">
<property name="minimumSize">
<size>
<width>0</width>
<height>22</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>22</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">border: 2px solid #079E00;
background: white;</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<property name="horizontalSpacing">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>1</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item row="0" column="1">
<widget class="QPushButton" name="resetButton">
<property name="minimumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="toolTip">
<string>Reset</string>
</property>
<property name="styleSheet">
<string notr="true">QPushButton
{
border-image: url(:/images/closenormal.png)
}
QPushButton:hover
{
border-image: url(:/images/closehover.png)
}
QPushButton:pressed {
border-image: url(:/images/closepressed.png)
}</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLineEdit" name="searchLine">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>3</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>16</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1677777</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Enter a Keyword here</string>
</property>
<property name="styleSheet">
<string notr="true">QLineEdit#lineEdit{background: transparent;
border: none;}
</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonSearch">
<property name="toolTip">
<string>Start Search</string>
</property>
<property name="styleSheet">
<string notr="true">QPushButton {
border-image: url(:/images/btn1.png) 4;
border-width: 4;
padding: 0px 6px;
font-size: 12px;
}
*{
color: black;
}
QPushButton:hover {
border-image: url(:/images/btn2.png) 4;
}
QPushButton:pressed{
border-image: url(:/images/btn3.png) 4;
}</string>
</property>
<property name="text">
<string>Search</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QTreeView" name="treeView"> <widget class="QTreeView" name="treeView">
<property name="contextMenuPolicy"> <property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum> <enum>Qt::CustomContextMenu</enum>
@ -269,12 +404,6 @@ p, li { white-space: pre-wrap; }
<attribute name="headerStretchLastSection"> <attribute name="headerStretchLastSection">
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<attribute name="headerStretchLastSection">
<bool>false</bool>
</attribute>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -564,8 +693,8 @@ border-image: url(:/images/btn_26_pressed.png) 4;
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>412</width> <width>411</width>
<height>331</height> <height>330</height>
</rect> </rect>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">

View File

@ -100,17 +100,9 @@ void ChannelDetails::loadChannel()
} }
uint32_t flags = 0; uint32_t flags = 0;
std::list<ChannelInfo> channelList;
std::list<ChannelInfo>::iterator it;
ChannelInfo ci; ChannelInfo ci;
rsChannels->getChannelInfo(cId, ci); rsChannels->getChannelInfo(cId, ci);
flags = ci.channelFlags;
rsChannels->getChannelList(channelList);
for(it = channelList.begin(); it != channelList.end(); it++)
{
// Set Channel Name // Set Channel Name
ui.nameline->setText(QString::fromStdWString(ci.channelName)); ui.nameline->setText(QString::fromStdWString(ci.channelName));
@ -118,14 +110,14 @@ void ChannelDetails::loadChannel()
// Set Channel Popularity // Set Channel Popularity
{ {
std::ostringstream out; std::ostringstream out;
out << it->pop; out << ci.pop;
ui.popline -> setText(QString::fromStdString(out.str())); ui.popline -> setText(QString::fromStdString(out.str()));
} }
// Set Last Channel Post Date // Set Last Channel Post Date
{ {
QDateTime qtime; QDateTime qtime;
qtime.setTime_t(it->lastPost); qtime.setTime_t(ci.lastPost);
QString timestamp = qtime.toString("yyyy-MM-dd hh:mm:ss"); QString timestamp = qtime.toString("yyyy-MM-dd hh:mm:ss");
ui.postline -> setText(timestamp); ui.postline -> setText(timestamp);
} }
@ -146,10 +138,6 @@ void ChannelDetails::loadChannel()
ui.typeEncrypted->setChecked(true); ui.typeEncrypted->setChecked(true);
ui.typePrivate->setChecked(false); ui.typePrivate->setChecked(false);
} }
}
} }