mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-05 09:35:39 -05:00
fixed search filter
This commit is contained in:
parent
59b1d44e5b
commit
c9561c2684
@ -823,7 +823,7 @@ void MessagesDialog::changeQuickView(int newrow)
|
|||||||
case 0x05: f = RsMessageModel::QUICK_VIEW_TODO ; break;
|
case 0x05: f = RsMessageModel::QUICK_VIEW_TODO ; break;
|
||||||
case 0x06: f = RsMessageModel::QUICK_VIEW_LATER ; break;
|
case 0x06: f = RsMessageModel::QUICK_VIEW_LATER ; break;
|
||||||
default:
|
default:
|
||||||
f = RsMessageModel::QuickViewFilter( (int)RsMessageModel::QUICK_VIEW_USER + newrow - 0x06);
|
f = RsMessageModel::QuickViewFilter( (int)RsMessageModel::QUICK_VIEW_USER + newrow - 0x07);
|
||||||
}
|
}
|
||||||
mMessageModel->setQuickViewFilter(f);
|
mMessageModel->setQuickViewFilter(f);
|
||||||
insertMsgTxtAndFiles(ui.messageTreeWidget->currentIndex());
|
insertMsgTxtAndFiles(ui.messageTreeWidget->currentIndex());
|
||||||
@ -1438,18 +1438,6 @@ void MessagesDialog::insertMsgTxtAndFiles(const QModelIndex& index)
|
|||||||
}
|
}
|
||||||
mid = index.data(RsMessageModel::MsgIdRole).toString().toStdString();
|
mid = index.data(RsMessageModel::MsgIdRole).toString().toStdString();
|
||||||
|
|
||||||
// int nCount = getSelectedMsgCount (NULL, NULL, NULL, NULL);
|
|
||||||
//
|
|
||||||
// if (nCount == 1) {
|
|
||||||
// ui.actionSaveAs->setEnabled(true);
|
|
||||||
// ui.actionPrintPreview->setEnabled(true);
|
|
||||||
// ui.actionPrint->setEnabled(true);
|
|
||||||
// } else {
|
|
||||||
// ui.actionSaveAs->setDisabled(true);
|
|
||||||
// ui.actionPrintPreview->setDisabled(true);
|
|
||||||
// ui.actionPrint->setDisabled(true);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/* Save the Data.... for later */
|
/* Save the Data.... for later */
|
||||||
|
|
||||||
MessageInfo msgInfo;
|
MessageInfo msgInfo;
|
||||||
@ -1458,27 +1446,17 @@ void MessagesDialog::insertMsgTxtAndFiles(const QModelIndex& index)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// QList<QTreeWidgetItem*> items;
|
bool bSetToReadOnActive = Settings->getMsgSetToReadOnActivate();
|
||||||
// items.append(item);
|
|
||||||
//
|
if (msgInfo.msgflags & RS_MSG_NEW) // set always to read or unread
|
||||||
// bool bSetToReadOnActive = Settings->getMsgSetToReadOnActivate();
|
{
|
||||||
//
|
if (!bSetToReadOnActive) // set locally to unread
|
||||||
// if (msgInfo.msgflags & RS_MSG_NEW) {
|
mMessageModel->setMsgReadStatus(index, false);
|
||||||
// // set always to read or unread
|
else
|
||||||
// if (bSetToReadOnActive == false || bSetToRead == false) {
|
mMessageModel->setMsgReadStatus(index, true);
|
||||||
// // set locally to unread
|
}
|
||||||
// setMsgAsReadUnread(items, false);
|
else if ((msgInfo.msgflags & RS_MSG_UNREAD_BY_USER) && bSetToReadOnActive) // set to read
|
||||||
// } else {
|
mMessageModel->setMsgReadStatus(index, true);
|
||||||
// setMsgAsReadUnread(items, true);
|
|
||||||
// }
|
|
||||||
// updateMessageSummaryList();
|
|
||||||
// } else {
|
|
||||||
// if ((msgInfo.msgflags & RS_MSG_UNREAD_BY_USER) && bSetToRead && bSetToReadOnActive) {
|
|
||||||
// // set to read
|
|
||||||
// setMsgAsReadUnread(items, true);
|
|
||||||
// updateMessageSummaryList();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
updateInterface();
|
updateInterface();
|
||||||
msgWidget->fill(mid);
|
msgWidget->fill(mid);
|
||||||
@ -1565,7 +1543,21 @@ void MessagesDialog::buttonStyle()
|
|||||||
void MessagesDialog::filterChanged(const QString& text)
|
void MessagesDialog::filterChanged(const QString& text)
|
||||||
{
|
{
|
||||||
QStringList items = text.split(' ',QString::SkipEmptyParts);
|
QStringList items = text.split(' ',QString::SkipEmptyParts);
|
||||||
mMessageModel->setFilter(ui.filterLineEdit->currentFilter(),items);
|
|
||||||
|
RsMessageModel::FilterType f = RsMessageModel::FILTER_TYPE_NONE;
|
||||||
|
|
||||||
|
switch(ui.filterLineEdit->currentFilter())
|
||||||
|
{
|
||||||
|
case COLUMN_SUBJECT: f = RsMessageModel::FILTER_TYPE_SUBJECT ; break;
|
||||||
|
case COLUMN_FROM: f = RsMessageModel::FILTER_TYPE_FROM ; break;
|
||||||
|
case COLUMN_DATE: f = RsMessageModel::FILTER_TYPE_DATE ; break;
|
||||||
|
case COLUMN_CONTENT: f = RsMessageModel::FILTER_TYPE_CONTENT ; break;
|
||||||
|
case COLUMN_TAGS: f = RsMessageModel::FILTER_TYPE_TAGS ; break;
|
||||||
|
case COLUMN_ATTACHEMENTS: f = RsMessageModel::FILTER_TYPE_ATTACHMENTS ; break;
|
||||||
|
default:break;
|
||||||
|
}
|
||||||
|
|
||||||
|
mMessageModel->setFilter(f,items);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesDialog::filterColumnChanged(int column)
|
void MessagesDialog::filterColumnChanged(int column)
|
||||||
@ -1573,8 +1565,21 @@ void MessagesDialog::filterColumnChanged(int column)
|
|||||||
if (inProcessSettings)
|
if (inProcessSettings)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
RsMessageModel::FilterType f = RsMessageModel::FILTER_TYPE_NONE;
|
||||||
|
|
||||||
|
switch(column)
|
||||||
|
{
|
||||||
|
case COLUMN_SUBJECT: f = RsMessageModel::FILTER_TYPE_SUBJECT ; break;
|
||||||
|
case COLUMN_FROM: f = RsMessageModel::FILTER_TYPE_FROM ; break;
|
||||||
|
case COLUMN_DATE: f = RsMessageModel::FILTER_TYPE_DATE ; break;
|
||||||
|
case COLUMN_CONTENT: f = RsMessageModel::FILTER_TYPE_CONTENT ; break;
|
||||||
|
case COLUMN_TAGS: f = RsMessageModel::FILTER_TYPE_TAGS ; break;
|
||||||
|
case COLUMN_ATTACHEMENTS: f = RsMessageModel::FILTER_TYPE_ATTACHMENTS ; break;
|
||||||
|
default:break;
|
||||||
|
}
|
||||||
|
|
||||||
QStringList items = ui.filterLineEdit->text().split(' ',QString::SkipEmptyParts);
|
QStringList items = ui.filterLineEdit->text().split(' ',QString::SkipEmptyParts);
|
||||||
mMessageModel->setFilter(column,items);
|
mMessageModel->setFilter(f,items);
|
||||||
|
|
||||||
// save index
|
// save index
|
||||||
Settings->setValueToGroup("MessageDialog", "filterColumn", column);
|
Settings->setValueToGroup("MessageDialog", "filterColumn", column);
|
||||||
|
@ -51,6 +51,7 @@ RsMessageModel::RsMessageModel(QObject *parent)
|
|||||||
mFilteringEnabled=false;
|
mFilteringEnabled=false;
|
||||||
mCurrentBox = BOX_NONE;
|
mCurrentBox = BOX_NONE;
|
||||||
mQuickViewFilter = QUICK_VIEW_ALL;
|
mQuickViewFilter = QUICK_VIEW_ALL;
|
||||||
|
mFilterType = FILTER_TYPE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsMessageModel::preMods()
|
void RsMessageModel::preMods()
|
||||||
@ -277,13 +278,13 @@ QVariant RsMessageModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
QVariant RsMessageModel::textColorRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const
|
QVariant RsMessageModel::textColorRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const
|
||||||
{
|
{
|
||||||
// if( (fmpe.msgflags & ForumModelPostEntry::FLAG_POST_IS_MISSING))
|
Rs::Msgs::MsgTagType tags;
|
||||||
// return QVariant(mTextColorMissing);
|
rsMsgs->getMessageTagTypes(tags);
|
||||||
//
|
|
||||||
// if(IS_MSG_UNREAD(fmpe.mMsgStatus) || (fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_IS_PINNED))
|
for(auto it(fmpe.msgtags.begin());it!=fmpe.msgtags.end();++it)
|
||||||
// return QVariant(mTextColorUnread);
|
for(auto it2(tags.types.begin());it2!=tags.types.end();++it2)
|
||||||
// else
|
if(it2->first == *it)
|
||||||
// return QVariant(mTextColorRead);
|
return QColor(it2->second.second);
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
@ -298,14 +299,42 @@ QVariant RsMessageModel::statusRole(const Rs::Msgs::MsgInfoSummary& fmpe,int col
|
|||||||
|
|
||||||
bool RsMessageModel::passesFilter(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const
|
bool RsMessageModel::passesFilter(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const
|
||||||
{
|
{
|
||||||
QString s = displayRole(fmpe,mFilterColumn).toString();
|
QString s ;
|
||||||
bool passes_strings = true ;
|
bool passes_strings = true ;
|
||||||
|
|
||||||
if(!mFilterStrings.empty())
|
if(!mFilterStrings.empty())
|
||||||
|
{
|
||||||
|
switch(mFilterType)
|
||||||
|
{
|
||||||
|
case FILTER_TYPE_SUBJECT: s = displayRole(fmpe,COLUMN_THREAD_SUBJECT).toString();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FILTER_TYPE_FROM:
|
||||||
|
case FILTER_TYPE_DATE: s = displayRole(fmpe,COLUMN_THREAD_DATE).toString();
|
||||||
|
break;
|
||||||
|
case FILTER_TYPE_CONTENT: {
|
||||||
|
Rs::Msgs::MessageInfo minfo;
|
||||||
|
rsMsgs->getMessage(fmpe.msgId,minfo);
|
||||||
|
s = QTextDocument(QString::fromUtf8(minfo.msg.c_str())).toPlainText();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case FILTER_TYPE_TAGS: s = displayRole(fmpe,COLUMN_THREAD_TAGS).toString();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FILTER_TYPE_ATTACHMENTS:
|
||||||
|
{
|
||||||
|
Rs::Msgs::MessageInfo minfo;
|
||||||
|
rsMsgs->getMessage(fmpe.msgId,minfo);
|
||||||
|
|
||||||
|
for(auto it(minfo.files.begin());it!=minfo.files.end();++it)
|
||||||
|
s += QString::fromUtf8((*it).fname.c_str())+" ";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!s.isNull())
|
||||||
for(auto iter(mFilterStrings.begin()); iter != mFilterStrings.end(); ++iter)
|
for(auto iter(mFilterStrings.begin()); iter != mFilterStrings.end(); ++iter)
|
||||||
passes_strings = passes_strings && s.contains(*iter,Qt::CaseInsensitive);
|
passes_strings = passes_strings && s.contains(*iter,Qt::CaseInsensitive);
|
||||||
else
|
|
||||||
passes_strings = true;
|
|
||||||
|
|
||||||
bool passes_quick_view =
|
bool passes_quick_view =
|
||||||
(mQuickViewFilter==QUICK_VIEW_ALL)
|
(mQuickViewFilter==QUICK_VIEW_ALL)
|
||||||
@ -333,11 +362,11 @@ uint32_t RsMessageModel::updateFilterStatus(ForumModelIndex i,int column,const Q
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RsMessageModel::setFilter(int column,const QStringList& strings)
|
void RsMessageModel::setFilter(FilterType filter_type, const QStringList& strings)
|
||||||
{
|
{
|
||||||
preMods();
|
preMods();
|
||||||
|
|
||||||
mFilterColumn = column;
|
mFilterType = filter_type;
|
||||||
mFilterStrings = strings;
|
mFilterStrings = strings;
|
||||||
|
|
||||||
postMods();
|
postMods();
|
||||||
@ -617,56 +646,6 @@ void RsMessageModel::updateMessages()
|
|||||||
setMessages(msgs);
|
setMessages(msgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// RsThread::async([this, group_id]()
|
|
||||||
// {
|
|
||||||
// // 1 - get message data from p3GxsForums
|
|
||||||
//
|
|
||||||
// std::list<RsGxsGroupId> forumIds;
|
|
||||||
// std::vector<RsMsgMetaData> msg_metas;
|
|
||||||
// std::vector<RsGxsForumGroup> groups;
|
|
||||||
//
|
|
||||||
// forumIds.push_back(group_id);
|
|
||||||
//
|
|
||||||
// if(!rsGxsForums->getForumsInfo(forumIds,groups))
|
|
||||||
// {
|
|
||||||
// std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve forum group info for forum " << group_id << std::endl;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if(!rsGxsForums->getForumMsgMetaData(group_id,msg_metas))
|
|
||||||
// {
|
|
||||||
// std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve forum message info for forum " << group_id << std::endl;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // 2 - sort the messages into a proper hierarchy
|
|
||||||
//
|
|
||||||
// auto post_versions = new std::map<RsGxsMessageId,std::vector<std::pair<time_t, RsGxsMessageId> > >() ;
|
|
||||||
// std::vector<ForumModelPostEntry> *vect = new std::vector<ForumModelPostEntry>();
|
|
||||||
// RsGxsForumGroup group = groups[0];
|
|
||||||
//
|
|
||||||
// computeMessagesHierarchy(group,msg_metas,*vect,*post_versions);
|
|
||||||
//
|
|
||||||
// // 3 - update the model in the UI thread.
|
|
||||||
//
|
|
||||||
// RsQThreadUtils::postToObject( [group,vect,post_versions,this]()
|
|
||||||
// {
|
|
||||||
// /* Here it goes any code you want to be executed on the Qt Gui
|
|
||||||
// * thread, for example to update the data model with new information
|
|
||||||
// * after a blocking call to RetroShare API complete, note that
|
|
||||||
// * Qt::QueuedConnection is important!
|
|
||||||
// */
|
|
||||||
//
|
|
||||||
// setPosts(group,*vect,*post_versions) ;
|
|
||||||
//
|
|
||||||
// delete vect;
|
|
||||||
// delete post_versions;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// }, this );
|
|
||||||
//
|
|
||||||
// });
|
|
||||||
|
|
||||||
static bool decreasing_time_comp(const std::pair<time_t,RsGxsMessageId>& e1,const std::pair<time_t,RsGxsMessageId>& e2) { return e2.first < e1.first ; }
|
static bool decreasing_time_comp(const std::pair<time_t,RsGxsMessageId>& e1,const std::pair<time_t,RsGxsMessageId>& e2) { return e2.first < e1.first ; }
|
||||||
|
|
||||||
void RsMessageModel::setMsgReadStatus(const QModelIndex& i,bool read_status)
|
void RsMessageModel::setMsgReadStatus(const QModelIndex& i,bool read_status)
|
||||||
|
@ -76,6 +76,16 @@ public:
|
|||||||
QUICK_VIEW_USER = 100
|
QUICK_VIEW_USER = 100
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum FilterType {
|
||||||
|
FILTER_TYPE_NONE = 0x00,
|
||||||
|
FILTER_TYPE_SUBJECT = 0x01, // These numbers have been carefuly chosen to match the ones in rsmsgs.h
|
||||||
|
FILTER_TYPE_FROM = 0x02,
|
||||||
|
FILTER_TYPE_DATE = 0x03,
|
||||||
|
FILTER_TYPE_CONTENT = 0x04,
|
||||||
|
FILTER_TYPE_TAGS = 0x05,
|
||||||
|
FILTER_TYPE_ATTACHMENTS = 0x06,
|
||||||
|
};
|
||||||
|
|
||||||
enum Roles{ SortRole = Qt::UserRole+1,
|
enum Roles{ SortRole = Qt::UserRole+1,
|
||||||
StatusRole = Qt::UserRole+2,
|
StatusRole = Qt::UserRole+2,
|
||||||
UnreadRole = Qt::UserRole+3,
|
UnreadRole = Qt::UserRole+3,
|
||||||
@ -95,9 +105,9 @@ public:
|
|||||||
|
|
||||||
void setCurrentBox(BoxName bn) ;
|
void setCurrentBox(BoxName bn) ;
|
||||||
void setQuickViewFilter(QuickViewFilter fn) ;
|
void setQuickViewFilter(QuickViewFilter fn) ;
|
||||||
void setFilter(int column, const QStringList& strings) ;
|
|
||||||
|
|
||||||
const RsMessageId& currentMessageId() const;
|
const RsMessageId& currentMessageId() const;
|
||||||
|
void setFilter(FilterType filter_type, const QStringList& strings) ;
|
||||||
|
|
||||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
@ -170,7 +180,7 @@ private:
|
|||||||
BoxName mCurrentBox ;
|
BoxName mCurrentBox ;
|
||||||
QuickViewFilter mQuickViewFilter ;
|
QuickViewFilter mQuickViewFilter ;
|
||||||
QStringList mFilterStrings;
|
QStringList mFilterStrings;
|
||||||
int mFilterColumn;
|
FilterType mFilterType;
|
||||||
bool mFilteringEnabled;
|
bool mFilteringEnabled;
|
||||||
|
|
||||||
std::vector<Rs::Msgs::MsgInfoSummary> mMessages;
|
std::vector<Rs::Msgs::MsgInfoSummary> mMessages;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user