improvements MessagesDialog:

- new read/unread state - stored locally
- show all recipients in Outbox, Sentbox and Draftbox


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2975 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-05-23 17:21:30 +00:00
parent 61e8d588a8
commit cef2c1218f
10 changed files with 1619 additions and 1379 deletions

View File

@ -26,6 +26,7 @@
#include "util/printpreview.h"
#include "util/misc.h"
#include "rsiface/rsinit.h"
#include "rsiface/rsiface.h"
#include "rsiface/rspeers.h"
#include "rsiface/rsfiles.h"
@ -41,14 +42,47 @@
#define IMAGE_DOWNLOAD ":/images/start.png"
#define IMAGE_DOWNLOADALL ":/images/startall.png"
#define COLUMN_COUNT 7
#define COLUMN_COUNT 8
#define COLUMN_ATTACHEMENTS 0
#define COLUMN_SUBJECT 1
#define COLUMN_FROM 2
#define COLUMN_DATE 3
#define COLUMN_SRCID 4
#define COLUMN_MSGID 5
#define COLUMN_CONTENT 6
#define COLUMN_READ 2
#define COLUMN_FROM 3
#define COLUMN_DATE 4
#define COLUMN_SRCID 5
#define COLUMN_MSGID 6
#define COLUMN_CONTENT 7
#define CONFIG_SECTION_UNREAD "Unread"
class MyItemDelegate : public QItemDelegate
{
public:
MyItemDelegate(QObject *parent = 0) : QItemDelegate(parent)
{
}
void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem ownOption (option);
if (index.column() == COLUMN_READ) {
ownOption.state &= ~QStyle::State_HasFocus; // don't show text and focus rectangle
}
QItemDelegate::paint (painter, ownOption, index);
}
QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem ownOption (option);
if (index.column() == COLUMN_READ) {
ownOption.state &= ~QStyle::State_HasFocus; // don't show text and focus rectangle
}
return QItemDelegate::sizeHint(ownOption, index);
}
};
static int FilterColumnFromComboBox(int nIndex)
{
@ -94,6 +128,7 @@ MessagesDialog::MessagesDialog(QWidget *parent)
ui.setupUi(this);
m_bProcessSettings = false;
m_pConfig = new RSettings (RsInit::RsProfileConfigDirectory() + "/msg_locale.cfg");
connect( ui.messagestreeView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( messageslistWidgetCostumPopupMenu( QPoint ) ) );
connect( ui.msgList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( msgfilelistWidgetCostumPopupMenu( QPoint ) ) );
@ -112,7 +147,6 @@ MessagesDialog::MessagesDialog(QWidget *parent)
ui.actionPrintPreview->setDisabled(true);
connect(ui.printbutton, SIGNAL(clicked()), this, SLOT(print()));
connect(ui.expandFilesButton, SIGNAL(clicked()), this, SLOT(togglefileview()));
connect(ui.downloadButton, SIGNAL(clicked()), this, SLOT(getcurrentrecommended()));
@ -128,10 +162,7 @@ MessagesDialog::MessagesDialog(QWidget *parent)
connect( ui.clearButton, SIGNAL(clicked()), this, SLOT(clearFilter()));
connect( ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged()));
connect(ui.filterColumnComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(filterColumnChanged()));
connect(ui.filterColumnComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterColumnChanged()));
mCurrCertId = "";
mCurrMsgId = "";
@ -140,6 +171,7 @@ MessagesDialog::MessagesDialog(QWidget *parent)
MessagesModel = new QStandardItemModel(0, COLUMN_COUNT);
MessagesModel->setHeaderData(COLUMN_ATTACHEMENTS, Qt::Horizontal, tr("#"));
MessagesModel->setHeaderData(COLUMN_SUBJECT, Qt::Horizontal, tr("Subject"));
MessagesModel->setHeaderData(COLUMN_READ, Qt::Horizontal, QIcon(":/images/message-mail-state-header.png"), Qt::DecorationRole);
MessagesModel->setHeaderData(COLUMN_FROM, Qt::Horizontal, tr("From"));
MessagesModel->setHeaderData(COLUMN_DATE, Qt::Horizontal, tr("Date"));
MessagesModel->setHeaderData(COLUMN_SRCID, Qt::Horizontal, tr("SRCID"));
@ -154,6 +186,9 @@ MessagesDialog::MessagesDialog(QWidget *parent)
ui.messagestreeView->setModel(proxyModel);
ui.messagestreeView->setSelectionBehavior(QTreeView::SelectRows);
QItemDelegate *pDelegate = new MyItemDelegate(this);
ui.messagestreeView->setItemDelegate(pDelegate);
ui.messagestreeView->setRootIsDecorated(false);
ui.messagestreeView->setSortingEnabled(true);
ui.messagestreeView->sortByColumn(COLUMN_DATE, Qt::DescendingOrder);
@ -170,12 +205,11 @@ MessagesDialog::MessagesDialog(QWidget *parent)
ui.msgList->setRootIsDecorated( false );
ui.msgList->setSelectionMode( QAbstractItemView::ExtendedSelection );
/* Set header resize modes and initial section sizes */
/* Set header initial section sizes */
QHeaderView * msgwheader = ui.messagestreeView->header () ;
msgwheader->setResizeMode (COLUMN_DATE, QHeaderView::Interactive);
msgwheader->resizeSection (COLUMN_ATTACHEMENTS, 24);
msgwheader->resizeSection (COLUMN_SUBJECT, 250);
msgwheader->resizeSection (COLUMN_READ, 16);
msgwheader->resizeSection (COLUMN_FROM, 140);
msgwheader->resizeSection (COLUMN_DATE, 140);
@ -218,6 +252,11 @@ MessagesDialog::MessagesDialog(QWidget *parent)
// load settings
processSettings(true);
/* Set header sizes for the fixed columns and resize modes, must be set after processSettings */
msgwheader->setResizeMode (COLUMN_DATE, QHeaderView::Interactive);
msgwheader->setResizeMode (COLUMN_READ, QHeaderView::Fixed);
msgwheader->resizeSection (COLUMN_READ, 24);
// fill folder list
updateMessageSummaryList();
ui.listWidget->setCurrentRow(0);
@ -242,6 +281,8 @@ MessagesDialog::~MessagesDialog()
// save settings
processSettings(false);
delete (m_pConfig);
}
void MessagesDialog::processSettings(bool bLoad)
@ -299,8 +340,11 @@ void MessagesDialog::processSettings(bool bLoad)
// MainPage::keyPressEvent(e) ;
//}
int MessagesDialog::getSelectedMsgCount ()
int MessagesDialog::getSelectedMsgCount (QList<int> *pRowsRead, QList<int> *pRowsUnread)
{
if (pRowsRead) pRowsRead->clear();
if (pRowsUnread) pRowsUnread->clear();
//To check if the selection has more than one row.
QList<QModelIndex> selectedIndexList = ui.messagestreeView->selectionModel() -> selectedIndexes ();
QList<int> rowList;
@ -310,12 +354,28 @@ int MessagesDialog::getSelectedMsgCount ()
if (rowList.contains(row) == false)
{
rowList.append(row);
if (pRowsRead || pRowsUnread) {
int mappedRow = proxyModel->mapToSource(*it).row();
if (MessagesModel->item(mappedRow, COLUMN_SUBJECT)->font().bold()) {
if (pRowsUnread) pRowsUnread->append(mappedRow);
} else {
if (pRowsRead) pRowsRead->append(mappedRow);
}
}
}
}
return rowList.size();
}
bool MessagesDialog::isMessageRead(int nRow)
{
QStandardItem *item;
item = MessagesModel->item(nRow,COLUMN_SUBJECT);
return !item->font().bold();
}
void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point )
{
QMenu contextMnu( this );
@ -326,6 +386,8 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point )
QAction* replyallmsgAct = NULL;
QAction* forwardmsgAct = NULL;
QAction* removemsgAct = NULL;
QAction* markAsRead = NULL;
QAction* markAsUnread = NULL;
replytomsgAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr( "Reply to Message" ), this );
connect( replytomsgAct , SIGNAL( triggered() ), this, SLOT( replytomessage() ) );
@ -341,7 +403,9 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point )
contextMnu.addSeparator();
int nCount = getSelectedMsgCount ();
QList<int> RowsRead;
QList<int> RowsUnread;
int nCount = getSelectedMsgCount (&RowsRead, &RowsUnread);
if (nCount > 1) {
removemsgAct = new QAction(QIcon(IMAGE_MESSAGEREMOVE), tr( "Remove Messages" ), this );
@ -357,6 +421,22 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point )
contextMnu.addAction( ui.actionPrint);
contextMnu.addSeparator();
markAsRead = new QAction(QIcon(":/images/message-mail-read.png"), tr( "Mark as read" ), this);
connect(markAsRead , SIGNAL(triggered()), this, SLOT(markAsRead()));
contextMnu.addAction(markAsRead);
if (RowsUnread.size() == 0) {
markAsRead->setDisabled(true);
}
markAsUnread = new QAction(QIcon(":/images/message-mail.png"), tr( "Mark as unread" ), this);
connect(markAsUnread , SIGNAL(triggered()), this, SLOT(markAsUnread()));
contextMnu.addAction(markAsUnread);
if (RowsRead.size() == 0) {
markAsUnread->setDisabled(true);
}
contextMnu.addSeparator();
newmsgAct = new QAction(QIcon(IMAGE_MESSAGE), tr( "New Message" ), this );
connect( newmsgAct , SIGNAL( triggered() ), this, SLOT( newmessage() ) );
contextMnu.addAction( newmsgAct);
@ -498,9 +578,7 @@ void MessagesDialog::replyallmessage()
std::list<std::string> tl ( msgInfo.msgto );
for( std::list<std::string>::iterator tli = tl.begin();
tli!= tl.end() ;
tli++ )
for ( std::list<std::string>::iterator tli = tl.begin(); tli!= tl.end(); tli++ )
{
nMsgDialog->addRecipient( *tli ) ;
}
@ -576,13 +654,10 @@ void MessagesDialog::togglefileview_internal()
* three widgets...
*/
if (ui.expandFilesButton->isChecked())
{
if (ui.expandFilesButton->isChecked()) {
ui.expandFilesButton->setIcon(QIcon(QString(":/images/edit_remove24.png")));
ui.expandFilesButton->setToolTip(tr("Hide"));
}
else
{
} else {
ui.expandFilesButton->setIcon(QIcon(QString(":/images/edit_add24.png")));
ui.expandFilesButton->setToolTip(tr("Expand"));
}
@ -683,6 +758,55 @@ void MessagesDialog::changeBox(int)
insertMsgTxtAndFiles();
}
static void InitIconAndFont(RSettings *pConfig, QStandardItem *pItem [COLUMN_COUNT], int nFlag)
{
QString sText = pItem [COLUMN_SUBJECT]->text();
QString mid = pItem [COLUMN_MSGID]->text();
bool bNew = (nFlag & RS_MSG_NEW);
// show the real "New" state
if (bNew) {
if (sText.startsWith("Re:", Qt::CaseInsensitive)) {
pItem[COLUMN_SUBJECT]->setIcon(QIcon(":/images/message-mail-replied.png"));
} else if (sText.startsWith("Fwd:", Qt::CaseInsensitive)) {
pItem[COLUMN_SUBJECT]->setIcon(QIcon(":/images/message-mail-forwarded.png"));
} else {
pItem[COLUMN_SUBJECT]->setIcon(QIcon(":/images/message-mail.png"));
}
} else {
// Change Message icon when Subject is Re: or Fwd:
if (sText.startsWith("Re:", Qt::CaseInsensitive)) {
pItem[COLUMN_SUBJECT]->setIcon(QIcon(":/images/message-mail-replied-read.png"));
} else if (sText.startsWith("Fwd:", Qt::CaseInsensitive)) {
pItem[COLUMN_SUBJECT]->setIcon(QIcon(":/images/message-mail-forwarded-read.png"));
} else {
pItem[COLUMN_SUBJECT]->setIcon(QIcon(":/images/message-mail-read.png"));
}
}
// show the locale "New" state
if (bNew == false) {
// check locale config
pConfig->beginGroup(CONFIG_SECTION_UNREAD);
bNew = pConfig->value(mid, false).toBool();
pConfig->endGroup();
}
if (bNew) {
pItem[COLUMN_READ]->setIcon(QIcon(":/images/message-mail-state-unread.png"));
} else {
pItem[COLUMN_READ]->setIcon(QIcon(":/images/message-mail-state-read.png"));
}
// set font
for (int i = 0; i < COLUMN_COUNT; i++) {
QFont qf = pItem[i]->font();
qf.setBold(bNew);
pItem[i]->setFont(qf);
}
}
void MessagesDialog::insertMessages()
{
std::cerr <<"MessagesDialog::insertMessages called";
@ -690,6 +814,9 @@ void MessagesDialog::insertMessages()
std::list<MsgInfoSummary> msgList;
std::list<MsgInfoSummary>::const_iterator it;
MessageInfo msgInfo;
bool bGotInfo;
QString text;
rsMsgs -> getMessageSummaries(msgList);
@ -699,6 +826,7 @@ void MessagesDialog::insertMessages()
std::cerr << "Current Row: " << listrow << std::endl;
fflush(0);
int i;
int nFilterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex());
/* check the mode we are in */
@ -722,6 +850,12 @@ void MessagesDialog::insertMessages()
bFill = false;
}
if (msgbox == RS_MSG_INBOX) {
MessagesModel->setHeaderData(COLUMN_FROM, Qt::Horizontal, tr("From"));
} else {
MessagesModel->setHeaderData(COLUMN_FROM, Qt::Horizontal, tr("To"));
}
if (bFill) {
/* remove old items */
int nRowCount = MessagesModel->rowCount();
@ -732,7 +866,7 @@ void MessagesDialog::insertMessages()
continue;
}
if (it->msgId == MessagesModel->item(nRow, 5)->text().toStdString()) {
if (it->msgId == MessagesModel->item(nRow, COLUMN_MSGID)->text().toStdString()) {
break;
}
}
@ -772,10 +906,13 @@ void MessagesDialog::insertMessages()
continue;
}
bGotInfo = false;
msgInfo = MessageInfo(); // clear
// search exisisting items
nRowCount = MessagesModel->rowCount();
for (nRow = 0; nRow < nRowCount; nRow++) {
if (it->msgId == MessagesModel->item(nRow, 5)->text().toStdString()) {
if (it->msgId == MessagesModel->item(nRow, COLUMN_MSGID)->text().toStdString()) {
break;
}
}
@ -787,23 +924,20 @@ void MessagesDialog::insertMessages()
bool bInsert = false;
if (nRow < nRowCount) {
for (int i = 0; i < COLUMN_COUNT; i++) {
for (i = 0; i < COLUMN_COUNT; i++) {
item[i] = MessagesModel->item(nRow, i);
}
} else {
for (int i = 0; i < COLUMN_COUNT; i++) {
for (i = 0; i < COLUMN_COUNT; i++) {
item[i] = new QStandardItem();
}
bInsert = true;
}
//set this false if you want to expand on double click
item[COLUMN_ATTACHEMENTS]->setEditable(false);
item[COLUMN_SUBJECT]->setEditable(false);
item[COLUMN_FROM]->setEditable(false);
item[COLUMN_DATE]->setEditable(false);
item[COLUMN_SRCID]->setEditable(false);
item[COLUMN_CONTENT]->setEditable(false);
for (i = 0; i < COLUMN_COUNT; i++) {
item[i]->setEditable(false);
}
/* So Text should be:
* (1) Msg / Broadcast
@ -843,67 +977,47 @@ void MessagesDialog::insertMessages()
// From ....
{
item[COLUMN_FROM] -> setText(QString::fromStdString(rsPeers->getPeerName(it->srcId)));
item[COLUMN_FROM]->setData(item[COLUMN_FROM]->text() + dateString, Qt::UserRole);
if (msgbox == RS_MSG_INBOX) {
text = QString::fromStdString(rsPeers->getPeerName(it->srcId));
} else {
if (bGotInfo || rsMsgs->getMessage(it->msgId, msgInfo)) {
bGotInfo = true;
text.clear();
std::list<std::string>::const_iterator pit;
for (pit = msgInfo.msgto.begin(); pit != msgInfo.msgto.end(); pit++)
{
if (text.isEmpty() == false) {
text += ";";
}
QString sPeer = QString::fromStdString(rsPeers->getPeerName(*pit));
if (sPeer.isEmpty()) {
text += tr("Anonymous") + "@" + QString::fromStdString(*pit);
} else {
text += sPeer;
}
}
} else {
std::cerr << "MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg" << std::endl;
}
}
item[COLUMN_FROM]->setText(text);
item[COLUMN_FROM]->setData(text + dateString, Qt::UserRole);
}
// Subject
QString text = QString::fromStdWString(it->title);
text = QString::fromStdWString(it->title);
item[COLUMN_SUBJECT]->setText(text);
item[COLUMN_SUBJECT]->setData(text + dateString, Qt::UserRole);
if ((it -> msgflags & RS_MSG_NEW) == RS_MSG_NEW)
{
QFont qf = item[COLUMN_SUBJECT]->font();
qf.setBold(true);
item[COLUMN_SUBJECT]->setFont(qf);
// internal data
item[COLUMN_SRCID]->setText(QString::fromStdString(it->srcId));
item[COLUMN_MSGID]->setText(QString::fromStdString(it->msgId));
}
// Change Message icon when Subject is Re: or Fwd:
if (text.startsWith("Re:", Qt::CaseInsensitive))
{
item[COLUMN_SUBJECT] -> setIcon(QIcon(":/images/message-mail-replied-read.png"));
}
else if (text.startsWith("Fwd:", Qt::CaseInsensitive))
{
item[COLUMN_SUBJECT] -> setIcon(QIcon(":/images/message-mail-forwarded-read.png"));
}
else
{
item[COLUMN_SUBJECT] -> setIcon(QIcon(":/images/message-mail-read.png"));
}
if (it -> msgflags & RS_MSG_NEW)
{
for(int i = 0; i < 10; i++)
{
/*QFont qf = item->font(i);
qf.setBold(true);
item->setFont(i, qf);*/
}
if (text.startsWith("Re:", Qt::CaseInsensitive))
{
item[COLUMN_SUBJECT] -> setIcon(QIcon(":/images/message-mail-replied.png"));
}
else if (text.startsWith("Fwd:", Qt::CaseInsensitive))
{
item[COLUMN_SUBJECT] -> setIcon(QIcon(":/images/message-mail-forwarded.png"));
}
else
{
item[COLUMN_SUBJECT] -> setIcon(QIcon(":/images/message-mail.png"));
}
}
if ((it -> msgflags & RS_MSG_BOXMASK) == RS_MSG_OUTBOX )
{
MessagesModel->setHeaderData(2, Qt::Horizontal, tr("Recipient"));
}
else
{
MessagesModel->setHeaderData(2, Qt::Horizontal, tr("From"));
}
// Init icon and font
InitIconAndFont(m_pConfig, item, it->msgflags);
// No of Files.
{
@ -914,13 +1028,10 @@ void MessagesDialog::insertMessages()
//item -> setTextAlignment( 0, Qt::AlignCenter );
}
item[COLUMN_SRCID] -> setText(QString::fromStdString(it->srcId));
item[COLUMN_MSGID] -> setText(QString::fromStdString(it->msgId));
if (nFilterColumn == COLUMN_CONTENT) {
// need content for filter
MessageInfo msgInfo;
if (rsMsgs->getMessage(it->msgId, msgInfo)) {
if (bGotInfo || rsMsgs->getMessage(it->msgId, msgInfo)) {
bGotInfo = true;
QTextDocument doc;
doc.setHtml(QString::fromStdWString(msgInfo.msg));
item[COLUMN_CONTENT]->setText(doc.toPlainText().replace(QString("\n"), QString(" ")));
@ -933,7 +1044,7 @@ void MessagesDialog::insertMessages()
if (bInsert) {
/* add to the list */
QList<QStandardItem *> itemList;
for (int i = 0; i < COLUMN_COUNT; i++) {
for (i = 0; i < COLUMN_COUNT; i++) {
itemList.append(item[i]);
}
MessagesModel->appendRow(itemList);
@ -943,10 +1054,15 @@ void MessagesDialog::insertMessages()
MessagesModel->removeRows (0, MessagesModel->rowCount());
}
updateMessageSummaryList();
ui.messagestreeView->showColumn(COLUMN_ATTACHEMENTS);
ui.messagestreeView->showColumn(COLUMN_SUBJECT);
ui.messagestreeView->showColumn(COLUMN_READ);
ui.messagestreeView->showColumn(COLUMN_FROM);
ui.messagestreeView->showColumn(COLUMN_DATE);
ui.messagestreeView->hideColumn(COLUMN_SRCID);
ui.messagestreeView->hideColumn(COLUMN_MSGID);
ui.messagestreeView->hideColumn(COLUMN_CONTENT);
updateMessageSummaryList();
}
// current row in messagestreeView has changed
@ -960,6 +1076,21 @@ void MessagesDialog::currentChanged(const QModelIndex &index )
// click in messagestreeView
void MessagesDialog::clicked(const QModelIndex &index )
{
if (index.isValid() == false) {
return;
}
if (index.column() == COLUMN_READ) {
int mappedRow = proxyModel->mapToSource(index).row();
QList<int> Rows;
Rows.append(mappedRow);
setMsgAsReadUnread(Rows, !isMessageRead(mappedRow));
insertMsgTxtAndFiles(index, false);
updateMessageSummaryList();
return;
}
timer->stop();
timerIndex = index;
// show current message directly
@ -971,57 +1102,54 @@ void MessagesDialog::updateCurrentMessage()
{
timer->stop();
insertMsgTxtAndFiles(timerIndex);
setMsgAsRead(timerIndex);
}
void MessagesDialog::setMsgAsReadUnread(const QList<int> &Rows, bool bRead)
{
for (int nRow = 0; nRow < Rows.size(); nRow++) {
QStandardItem* item[COLUMN_COUNT];
for(int nCol = 0; nCol < COLUMN_COUNT; nCol++)
{
item[nCol] = MessagesModel->item(Rows [nRow], nCol);
}
QString mid = item[COLUMN_MSGID]->text();
m_pConfig->beginGroup(CONFIG_SECTION_UNREAD);
if (bRead) {
// set as read in config
m_pConfig->setValue(mid, false);
// set message to read
rsMsgs->MessageRead(mid.toStdString());
} else {
// set as unread in config
m_pConfig->setValue(mid, true);
}
m_pConfig->endGroup();
InitIconAndFont(m_pConfig, item, 0);
}
}
void MessagesDialog::markAsRead()
{
QList<int> RowsUnread;
getSelectedMsgCount (NULL, &RowsUnread);
setMsgAsReadUnread (RowsUnread, true);
updateMessageSummaryList();
}
void MessagesDialog::setMsgAsRead(const QModelIndex &index)
{
QString text;
QModelIndex currentIndex = proxyModel->mapToSource(index);
if (currentIndex.isValid() == false)
{
return;
}
else
{
for(int i = 0; i < COLUMN_COUNT; i++)
void MessagesDialog::markAsUnread()
{
QList<int> RowsRead;
getSelectedMsgCount (&RowsRead, NULL);
QStandardItem* item;
item = MessagesModel->item(currentIndex.row(),i);
QFont qf = item->font();
qf.setBold(false);
item->setFont(qf);
//change the icon to read. this need to be done when user clicks to the new message
if(i == COLUMN_SUBJECT)
{
text = item->text();
if (text.startsWith("Re:", Qt::CaseInsensitive))
{
item -> setIcon(QIcon(":/images/message-mail-replied-read.png"));
}
else if (text.startsWith("Fwd:", Qt::CaseInsensitive))
{
item -> setIcon(QIcon(":/images/message-mail-forwarded-read.png"));
}
else
{
item -> setIcon(QIcon(":/images/message-mail-read.png"));
setMsgAsReadUnread (RowsRead, false);
updateMessageSummaryList();
}
}
if(i == COLUMN_MSGID)
{
std::string mid(item->text().toStdString());
rsMsgs->MessageRead(mid);
}
}
}
}
void MessagesDialog::insertMsgTxtAndFiles(QModelIndex Index)
void MessagesDialog::insertMsgTxtAndFiles(QModelIndex Index, bool bSetToRead)
{
std::cerr << "MessagesDialog::insertMsgTxtAndFiles()" << std::endl;
@ -1059,7 +1187,7 @@ void MessagesDialog::insertMsgTxtAndFiles(QModelIndex Index)
mid = item->text().toStdString();
}
int nCount = getSelectedMsgCount ();
int nCount = getSelectedMsgCount (NULL, NULL);
if (nCount == 1) {
ui.actionSave_as->setEnabled(true);
ui.actionPrintPreview->setEnabled(true);
@ -1070,6 +1198,11 @@ void MessagesDialog::insertMsgTxtAndFiles(QModelIndex Index)
ui.actionPrint->setDisabled(true);
}
if (mCurrMsgId == mid) {
// message doesn't changed
return;
}
/* Save the Data.... for later */
mCurrCertId = cid;
@ -1082,6 +1215,27 @@ void MessagesDialog::insertMsgTxtAndFiles(QModelIndex Index)
return;
}
QList<int> Rows;
Rows.append(currentIndex.row());
bool bSetToReadOnActive = Settings->getMsgSetToReadOnActivate();
if (msgInfo.msgflags & RS_MSG_NEW) {
// set to read
setMsgAsReadUnread(Rows, true);
if (bSetToReadOnActive == false || bSetToRead == false) {
// set locally to unread
setMsgAsReadUnread(Rows, false);
}
updateMessageSummaryList();
} else {
if (bSetToRead && bSetToReadOnActive) {
// set to read
setMsgAsReadUnread(Rows, true);
updateMessageSummaryList();
}
}
const std::list<FileInfo> &recList = msgInfo.files;
std::list<FileInfo>::const_iterator it;
@ -1119,37 +1273,39 @@ void MessagesDialog::insertMsgTxtAndFiles(QModelIndex Index)
QString msgTxt;
for(pit = msgInfo.msgto.begin(); pit != msgInfo.msgto.end(); pit++)
{
if (QString::fromStdString(rsPeers->getPeerName(*pit)) == "")
QString sPeer = QString::fromStdString(rsPeers->getPeerName(*pit));
if (sPeer.isEmpty())
{
msgTxt += "<a style='color: black;'href='" + tr("Anonymous") + "@" + QString::fromStdString(*pit) + "'> " + tr("Anonymous") + "</a>" + " ";
}
else
msgTxt += "<a style='color: black;'href='" + QString::fromStdString(rsPeers->getPeerName(*pit)) + "@" + QString::fromStdString(*pit) + "'> " + QString::fromStdString(rsPeers->getPeerName(*pit)) + "</a>" + " ";
msgTxt += "<a style='color: black;'href='" + sPeer + "@" + QString::fromStdString(*pit) + "'> " + sPeer + "</a>" + " ";
}
if (msgInfo.msgcc.size() > 0)
msgTxt += "\nCc: ";
for(pit = msgInfo.msgcc.begin(); pit != msgInfo.msgcc.end(); pit++)
{
if (QString::fromStdString(rsPeers->getPeerName(*pit)) == "")
QString sPeer = QString::fromStdString(rsPeers->getPeerName(*pit));
if (sPeer.isEmpty())
{
msgTxt += "<a style='color: black;'href='" + tr("Anonymous") + "@" + QString::fromStdString(*pit) + "'> " + tr("Anonymous") + "</a>" + " ";
}
else
msgTxt += "<a style='color: black;'href='" + QString::fromStdString(rsPeers->getPeerName(*pit)) + "@" + QString::fromStdString(*pit) + "'> " + QString::fromStdString(rsPeers->getPeerName(*pit)) + "</a>" + " ";
msgTxt += "<a style='color: black;'href='" + sPeer + "@" + QString::fromStdString(*pit) + "'> " + sPeer + "</a>" + " ";
}
if (msgInfo.msgbcc.size() > 0)
msgTxt += "\nBcc: ";
for(pit = msgInfo.msgbcc.begin(); pit != msgInfo.msgbcc.end(); pit++)
{
if (QString::fromStdString(rsPeers->getPeerName(*pit)) == "")
QString sPeer = QString::fromStdString(rsPeers->getPeerName(*pit));
if (sPeer.isEmpty())
{
msgTxt += "<a style='color: black;'href='" + tr("Anonymous") + "@" + QString::fromStdString(*pit) + "'> " + tr("Anonymous") + "</a>" + " ";
}
else
msgTxt += "<a style='color: black;'href='" + QString::fromStdString(rsPeers->getPeerName(*pit)) + "@" + QString::fromStdString(*pit) + "'> " + QString::fromStdString(rsPeers->getPeerName(*pit)) + "</a>" + " ";
msgTxt += "<a style='color: black;'href='" + sPeer + "@" + QString::fromStdString(*pit) + "'> " + sPeer + "</a>" + " ";
}
{
@ -1212,8 +1368,8 @@ void MessagesDialog::removemessage()
QList<QModelIndex> selectedIndexList= ui.messagestreeView->selectionModel() -> selectedIndexes ();
QList<int> rowList;
QModelIndex selectedIndex;
for(QList<QModelIndex>::iterator it = selectedIndexList.begin(); it != selectedIndexList.end(); it++)
{
for(QList<QModelIndex>::iterator it = selectedIndexList.begin(); it != selectedIndexList.end(); it++) {
selectedIndex = proxyModel->mapToSource(*it);
int row = selectedIndex.row();
if (rowList.contains(row) == false)
@ -1222,9 +1378,14 @@ void MessagesDialog::removemessage()
}
}
for(QList<int>::const_iterator it1(rowList.begin());it1!=rowList.end();++it1)
{
rsMsgs->MessageDelete(MessagesModel->item((*it1),COLUMN_MSGID)->text().toStdString());
for(QList<int>::const_iterator it1(rowList.begin());it1!=rowList.end();++it1) {
QString mid = MessagesModel->item((*it1),COLUMN_MSGID)->text();
rsMsgs->MessageDelete(mid.toStdString());
// clean locale config
m_pConfig->beginGroup(CONFIG_SECTION_UNREAD);
m_pConfig->remove (mid);
m_pConfig->endGroup();
}
insertMessages();
@ -1494,7 +1655,40 @@ void MessagesDialog::updateMessageSummaryList()
unsigned int inboxCount = 0;
/* calculating the new messages */
rsMsgs->getMessageCount (&inboxCount, &newInboxCount, &newOutboxCount, &newDraftCount, &newSentboxCount);
// rsMsgs->getMessageCount (&inboxCount, &newInboxCount, &newOutboxCount, &newDraftCount, &newSentboxCount);
std::list<MsgInfoSummary> msgList;
std::list<MsgInfoSummary>::const_iterator it;
rsMsgs->getMessageSummaries(msgList);
/*calculating the new messages*/
for (it = msgList.begin(); it != msgList.end(); it++) {
switch (it->msgflags & RS_MSG_BOXMASK) {
case RS_MSG_INBOX:
inboxCount++;
if ((it->msgflags & RS_MSG_NEW) == RS_MSG_NEW) {
newInboxCount++;
} else {
// check locale config
m_pConfig->beginGroup(CONFIG_SECTION_UNREAD);
if (m_pConfig->value(QString::fromStdString(it->msgId), false).toBool()) {
newInboxCount++;
}
m_pConfig->endGroup();
}
break;
case RS_MSG_OUTBOX:
newOutboxCount++;
break;
case RS_MSG_DRAFTBOX:
newDraftCount++;
break;
case RS_MSG_SENTBOX:
newSentboxCount++;
break;
}
}
QString textItem;
/*updating the labels in leftcolumn*/
@ -1542,7 +1736,6 @@ void MessagesDialog::updateMessageSummaryList()
}
//QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const
item = ui.listWidget->item(2);
if (newDraftCount != 0)

View File

@ -33,6 +33,8 @@
#include "mainpage.h"
#include "ui_MessagesDialog.h"
class RSettings;
class MessagesDialog : public MainPage
{
Q_OBJECT
@ -43,7 +45,6 @@ public:
/** Default Destructor */
~MessagesDialog();
void insertMsgTxtAndFiles(QModelIndex index = QModelIndex());
// replaced by shortcut
// virtual void keyPressEvent(QKeyEvent *) ;
void updateMessageSummaryList();
@ -77,6 +78,9 @@ private slots:
void removemessage();
void markAsRead();
void markAsUnread();
void anchorClicked (const QUrl &);
void getcurrentrecommended();
@ -100,12 +104,15 @@ private:
class QStandardItemModel *MessagesModel;
QSortFilterProxyModel *proxyModel;
void insertMsgTxtAndFiles(QModelIndex index = QModelIndex(), bool bSetToRead = true);
bool getCurrentMsg(std::string &cid, std::string &mid);
void setMsgAsRead(const QModelIndex &index);
void setMsgAsReadUnread(const QList<int> &Rows, bool bRead);
void setCurrentFileName(const QString &fileName);
int getSelectedMsgCount ();
int getSelectedMsgCount (QList<int> *pRowsRead, QList<int> *pRowsUnread);
bool isMessageRead(int nRow);
/* internal handle splitter */
void togglefileview_internal();
@ -118,8 +125,8 @@ private:
std::string mCurrMsgId;
QString fileName;
QFont mFont;
RSettings *m_pConfig;
// timer and index for showing message
QTimer *timer;

View File

@ -270,6 +270,9 @@
<file>images/message-mail-forwarded-read.png</file>
<file>images/message-mail-replied.png</file>
<file>images/message-mail-forwarded.png</file>
<file>images/message-mail-state-read.png</file>
<file>images/message-mail-state-unread.png</file>
<file>images/message-mail-state-header.png</file>
<file>images/message-news.png</file>
<file>images/message.png</file>
<file>images/messages_new.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

View File

@ -22,12 +22,13 @@
#include "MessagePage.h"
#include "rshare.h"
#include "rsharesettings.h"
MessagePage::MessagePage(QWidget * parent, Qt::WFlags flags)
: ConfigPage(parent, flags)
{
ui.setupUi(this);
setAttribute(Qt::WA_QuitOnClose, false);
}
MessagePage::~MessagePage()
@ -40,11 +41,12 @@ MessagePage::closeEvent (QCloseEvent * event)
QWidget::closeEvent(event);
}
/** Saves the changes on this page */
bool
MessagePage::save(QString &errmsg)
{
Settings->setMsgSetToReadOnActivate(ui.setMsgToReadOnActivate->isChecked());
return true;
}
@ -52,6 +54,6 @@ MessagePage::save(QString &errmsg)
void
MessagePage::load()
{
ui.setMsgToReadOnActivate->setChecked(Settings->getMsgSetToReadOnActivate());
}

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MessagePage</class>
<widget class="QWidget" name="MessagePage">
@ -5,12 +6,12 @@
<rect>
<x>0</x>
<y>0</y>
<width>398</width>
<width>556</width>
<height>389</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -498,9 +499,29 @@
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>395</width>
<height>61</height>
</rect>
</property>
<property name="title">
<string>Misc</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QCheckBox" name="setMsgToReadOnActivate">
<property name="text">
<string>Set message to read on activate</string>
</property>
</widget>
<resources>
<include location="../images.qrc" />
</resources>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -345,3 +345,13 @@ void RshareSettings::loadWidgetInformation(QMainWindow *widget, QToolBar *toolBa
loadWidgetInformation(widget);
}
/* Messages */
bool RshareSettings::getMsgSetToReadOnActivate ()
{
return valueFromGroup("MessageDialog", "SetMsgToReadOnActivate", true).toBool();
}
void RshareSettings::setMsgSetToReadOnActivate (bool bValue)
{
setValueToGroup("MessageDialog", "SetMsgToReadOnActivate", bValue);
}

View File

@ -126,6 +126,10 @@ public:
//! Method overload. Restore window and toolbar information.
void loadWidgetInformation(QMainWindow *widget, QToolBar *toolBar);
/* Messages */
bool getMsgSetToReadOnActivate ();
void setMsgSetToReadOnActivate (bool bValue);
protected:
/** Default constructor. */
RshareSettings();