diff --git a/libretroshare/src/services/p3distrib.cc b/libretroshare/src/services/p3distrib.cc index 8811db30b..c2d64d33d 100644 --- a/libretroshare/src/services/p3distrib.cc +++ b/libretroshare/src/services/p3distrib.cc @@ -692,6 +692,10 @@ void p3GroupDistrib::loadMsg(RsDistribSignedMsg *newMsg, std::string src, bool l /* accept message */ (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 */ locked_updateChildTS(git->second, msg); diff --git a/retroshare-gui/src/gui/ChannelFeed.cpp b/retroshare-gui/src/gui/ChannelFeed.cpp index 733d27614..a59e55860 100644 --- a/retroshare-gui/src/gui/ChannelFeed.cpp +++ b/retroshare-gui/src/gui/ChannelFeed.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -48,6 +49,8 @@ #define ROLE_ID Qt::UserRole #define ROLE_CHANNEL_TITLE Qt::UserRole + 1 +#define ROLE_CHANNEL_DESC Qt::UserRole + 2 +#define ROLE_CHANNEL_TS Qt::UserRole + 3 /**** * #define CHAN_DEBUG @@ -65,6 +68,9 @@ ChannelFeed::ChannelFeed(QWidget *parent) connect(subscribeButton, SIGNAL( clicked( void ) ), this, SLOT( subscribeChannel ( void ) ) ); connect(unsubscribeButton, SIGNAL( clicked( void ) ), this, SLOT( unsubscribeChannel ( void ) ) ); 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))); @@ -130,6 +136,7 @@ ChannelFeed::ChannelFeed(QWidget *parent) channelmenu->addAction(actionCreate_Channel); channelmenu->addSeparator(); channelpushButton->setMenu(channelmenu); + resetButton->setVisible(false); 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() { if (!rsChannels) { @@ -310,7 +356,8 @@ void ChannelFeed::updateChannelList() /* sort it into Publish (Own), Subscribed, Popular and Other */ 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); } else if (flags & RS_DISTRIB_SUBSCRIBED) { subList.push_back(*it); @@ -376,14 +423,14 @@ void ChannelFeed::fillChannelList(int channelItem, std::list &chann } } - QStandardItem *chNameItem = new QStandardItem(); - QStandardItem *chPopItem = new QStandardItem(); + QStandardItem *chNameItem = NULL;//new QChannelItem(); // use channel item to enable channel specific sorting + QStandardItem *chPopItem = NULL;// new QStandardItem(); if (row < rowCount) { chNameItem = groupItem->child(row, COLUMN_NAME); chPopItem = groupItem->child(row, COLUMN_POPULARITY); } else { QList channel; - chNameItem = new QStandardItem(); + chNameItem = new QChannelItem(); chPopItem = new QStandardItem(); chNameItem->setSizeHint(QSize(22, 22)); @@ -397,6 +444,11 @@ void ChannelFeed::fillChannelList(int channelItem, std::list &chann chNameItem->setText(QString::fromStdWString(ci.channelName)); 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)); QPixmap chanImage; @@ -443,6 +495,7 @@ void ChannelFeed::fillChannelList(int channelItem, std::list &chann row++; } } + } 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; +} + diff --git a/retroshare-gui/src/gui/ChannelFeed.h b/retroshare-gui/src/gui/ChannelFeed.h index 937b04d9a..88cb54774 100644 --- a/retroshare-gui/src/gui/ChannelFeed.h +++ b/retroshare-gui/src/gui/ChannelFeed.h @@ -23,6 +23,7 @@ #define _CHANNEL_FEED_DIALOG_H #include +#include #include "mainpage.h" #include "RsAutoUpdatePage.h" @@ -31,6 +32,8 @@ #include "gui/feeds/FeedHolder.h" + + #define OWN 0 #define SUBSCRIBED 1 #define POPULAR 2 @@ -78,6 +81,9 @@ private slots: void shareKey(); void channelMsgReadSatusChanged(const QString& channelId, const QString& msgId, int status); + void searchChannels(); + void searchMessages(); + void finishSearching(); private: void updateChannelList(); @@ -99,6 +105,30 @@ private: 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 diff --git a/retroshare-gui/src/gui/ChannelFeed.ui b/retroshare-gui/src/gui/ChannelFeed.ui index ec717ea74..e96d454bf 100644 --- a/retroshare-gui/src/gui/ChannelFeed.ui +++ b/retroshare-gui/src/gui/ChannelFeed.ui @@ -68,13 +68,7 @@ QFrame::Raised - - - 0 - - - 0 - + @@ -110,10 +104,7 @@ border: 1px solid #CCCCCC;} QFrame::Raised - - - 2 - + @@ -151,50 +142,6 @@ p, li { white-space: pre-wrap; } - - - - true - - - Add - - - 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; - } - - - - - - - :/images/edit_add24.png:/images/edit_add24.png - - - - 16 - 16 - - - - false - - - true - - - @@ -246,10 +193,198 @@ p, li { white-space: pre-wrap; } + + + + true + + + Add + + + 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; + } + + + + + + + :/images/edit_add24.png:/images/edit_add24.png + + + + 16 + 16 + + + + false + + + true + + + + channelpushButton + postButton + treeView + + + 0 + + + + + + 0 + 22 + + + + + 16777215 + 22 + + + + border: 2px solid #079E00; +background: white; + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 1 + + + 0 + + + + + + 16 + 16 + + + + + 16 + 16 + + + + Reset + + + QPushButton +{ + border-image: url(:/images/closenormal.png) +} + +QPushButton:hover +{ +border-image: url(:/images/closehover.png) +} + +QPushButton:pressed { +border-image: url(:/images/closepressed.png) +} + + + + + + + + + + + 3 + 0 + + + + + 0 + 16 + + + + + 1677777 + 16777215 + + + + Enter a Keyword here + + + QLineEdit#lineEdit{background: transparent; +border: none;} + + + + + + + + + + + Start Search + + + 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; +} + + + Search + + + + + + Qt::CustomContextMenu @@ -269,12 +404,6 @@ p, li { white-space: pre-wrap; } false - - false - - - false - @@ -564,8 +693,8 @@ border-image: url(:/images/btn_26_pressed.png) 4; 0 0 - 412 - 331 + 411 + 330 diff --git a/retroshare-gui/src/gui/channels/ChannelDetails.cpp b/retroshare-gui/src/gui/channels/ChannelDetails.cpp index 0bef8c5fd..616161052 100644 --- a/retroshare-gui/src/gui/channels/ChannelDetails.cpp +++ b/retroshare-gui/src/gui/channels/ChannelDetails.cpp @@ -100,17 +100,9 @@ void ChannelDetails::loadChannel() } uint32_t flags = 0; - std::list channelList; - std::list::iterator it; - ChannelInfo ci; rsChannels->getChannelInfo(cId, ci); - - rsChannels->getChannelList(channelList); - - - for(it = channelList.begin(); it != channelList.end(); it++) - { + flags = ci.channelFlags; // Set Channel Name ui.nameline->setText(QString::fromStdWString(ci.channelName)); @@ -118,14 +110,14 @@ void ChannelDetails::loadChannel() // Set Channel Popularity { std::ostringstream out; - out << it->pop; + out << ci.pop; ui.popline -> setText(QString::fromStdString(out.str())); } // Set Last Channel Post Date { QDateTime qtime; - qtime.setTime_t(it->lastPost); + qtime.setTime_t(ci.lastPost); QString timestamp = qtime.toString("yyyy-MM-dd hh:mm:ss"); ui.postline -> setText(timestamp); } @@ -146,10 +138,6 @@ void ChannelDetails::loadChannel() ui.typeEncrypted->setChecked(true); ui.typePrivate->setChecked(false); } - - - - } }