Improved MessagesDialog:

- corrected calculation of message counts
- p3MsgService::checkOutgoingMessages -> notify when message was sent
- refill of message list without clear, selected messages and scroll position are not changed
- corrected sorting of date with only time for today
- changed context menu in message list

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2863 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-05-07 22:23:38 +00:00
parent 5813a6454a
commit f239e7e4d4
4 changed files with 396 additions and 359 deletions

View File

@ -186,6 +186,9 @@ int p3MsgService::checkOutgoingMessages()
* if online, send
*/
bool changed = false ;
{
const std::string ownId = mConnMgr->getOwnId();
std::list<uint32_t>::iterator it;
@ -224,6 +227,8 @@ int p3MsgService::checkOutgoingMessages()
sendItem(mit->second);
toErase.push_back(mit->first);
changed = true ;
}
else
{
@ -246,6 +251,10 @@ int p3MsgService::checkOutgoingMessages()
{
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
}
}
if(changed)
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
return 0;
}

View File

@ -79,7 +79,9 @@ MessagesDialog::MessagesDialog(QWidget *parent)
connect(ui.forwardmessageButton, SIGNAL(clicked()), this, SLOT(forwardmessage()));
connect(ui.actionPrint, SIGNAL(triggered()), this, SLOT(print()));
ui.actionPrint->setDisabled(true);
connect(ui.actionPrintPreview, SIGNAL(triggered()), this, SLOT(printpreview()));
ui.actionPrintPreview->setDisabled(true);
connect(ui.printbutton, SIGNAL(clicked()), this, SLOT(print()));
@ -93,6 +95,7 @@ MessagesDialog::MessagesDialog(QWidget *parent)
connect(ui.actionTextUnderIcon, SIGNAL(triggered()), this, SLOT(buttonstextundericon()));
connect(ui.actionSave_as, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
ui.actionSave_as->setDisabled(true);
connect( ui.clearButton, SIGNAL(clicked()), this, SLOT(clearFilter()));
connect( ui.filterPatternLineEdit, SIGNAL( textChanged(const QString &)), this, SLOT(toggleclearButton()));
@ -120,6 +123,8 @@ MessagesDialog::MessagesDialog(QWidget *parent)
proxyModel = new QSortFilterProxyModel(this);
proxyModel->setDynamicSortFilter(true);
proxyModel->setSourceModel(MessagesModel);
proxyModel->setSortRole(Qt::UserRole);
proxyModel->sort (3, Qt::DescendingOrder);
ui.messagestreeView->setModel(proxyModel);
ui.messagestreeView->setSelectionBehavior(QTreeView::SelectRows);
@ -216,22 +221,13 @@ MessagesDialog::~MessagesDialog()
// MainPage::keyPressEvent(e) ;
//}
void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point )
int MessagesDialog::getSelectedMsgCount ()
{
QMenu contextMnu( this );
QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );
contextMnu.clear();
newmsgAct = new QAction(QIcon(IMAGE_MESSAGE), tr( "New Message" ), this );
connect( newmsgAct , SIGNAL( triggered() ), this, SLOT( newmessage() ) );
//To check if the selection has more than one row.
QList<QModelIndex> selectedIndexList = ui.messagestreeView->selectionModel() -> selectedIndexes ();
QList<int> rowList;
for(QList<QModelIndex>::iterator it = selectedIndexList.begin(); it != selectedIndexList.end(); it++)
{
int row = it->row();
if (rowList.contains(row) == false)
{
@ -239,15 +235,23 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point )
}
}
int nn = rowList.size();
if(nn > 1)
{
removemsgAct = new QAction(QIcon(IMAGE_MESSAGEREMOVE), tr( "Remove Messages" ), this );
connect( removemsgAct , SIGNAL( triggered() ), this, SLOT( removemessage() ) );
contextMnu.addAction( removemsgAct);
}
else if(nn == 1)
{
return rowList.size();
}
void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point )
{
QMenu contextMnu( this );
QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );
contextMnu.clear();
/** Defines the actions for the context menu */
QAction* newmsgAct = NULL;
QAction* replytomsgAct = NULL;
QAction* replyallmsgAct = NULL;
QAction* forwardmsgAct = NULL;
QAction* removemsgAct = NULL;
replytomsgAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr( "Reply to Message" ), this );
connect( replytomsgAct , SIGNAL( triggered() ), this, SLOT( replytomessage() ) );
contextMnu.addAction( replytomsgAct);
@ -262,21 +266,43 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point )
contextMnu.addSeparator();
int nCount = getSelectedMsgCount ();
if (nCount > 1) {
removemsgAct = new QAction(QIcon(IMAGE_MESSAGEREMOVE), tr( "Remove Messages" ), this );
} else {
removemsgAct = new QAction(QIcon(IMAGE_MESSAGEREMOVE), tr( "Remove Message" ), this );
}
connect( removemsgAct , SIGNAL( triggered() ), this, SLOT( removemessage() ) );
contextMnu.addAction( removemsgAct);
}
contextMnu.addAction( ui.actionSave_as);
contextMnu.addAction( ui.actionPrintPreview);
contextMnu.addAction( ui.actionPrint);
contextMnu.addSeparator();
newmsgAct = new QAction(QIcon(IMAGE_MESSAGE), tr( "New Message" ), this );
connect( newmsgAct , SIGNAL( triggered() ), this, SLOT( newmessage() ) );
contextMnu.addAction( newmsgAct);
if (nCount != 1) {
replytomsgAct->setDisabled(true);
replyallmsgAct->setDisabled(true);
forwardmsgAct->setDisabled(true);
}
if (nCount == 0) {
removemsgAct->setDisabled(true);
}
contextMnu.exec( mevent->globalPos() );
}
void MessagesDialog::msgfilelistWidgetCostumPopupMenu( QPoint point )
{
QAction* getRecAct = NULL;
QAction* getAllRecAct = NULL;
QMenu contextMnu( this );
QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );
@ -287,7 +313,6 @@ void MessagesDialog::msgfilelistWidgetCostumPopupMenu( QPoint point )
// getAllRecAct = new QAction(QIcon(IMAGE_DOWNLOADALL), tr( "Download" ), this );
// connect( getAllRecAct , SIGNAL( triggered() ), this, SLOT( getallrecommended() ) );
contextMnu.clear();
contextMnu.addAction( getRecAct);
// contextMnu.addAction( getAllRecAct);
@ -572,6 +597,8 @@ void MessagesDialog::getallrecommended()
void MessagesDialog::changeBox(int)
{
MessagesModel->removeRows (0, MessagesModel->rowCount());
insertMessages();
insertMsgTxtAndFiles();
}
@ -580,33 +607,21 @@ void MessagesDialog::insertMessages()
{
std::cerr <<"MessagesDialog::insertMessages called";
fflush(0);
int c;
c = MessagesModel->rowCount();
MessagesModel->removeRows(0,c);
//ui.messagestreeView->showColumn(4);
//ui.messagestreeView->showColumn(5);
std::list<MsgInfoSummary> msgList;
std::list<MsgInfoSummary>::const_iterator it;
rsMsgs -> getMessageSummaries(msgList);
/* get the MsgId of the current one ... */
std::string cid;
std::string mid;
bool oldSelected = getCurrentMsg(cid, mid);
QStandardItem *newSelected = NULL;
/* remove old items ??? */
int listrow = ui.listWidget -> currentRow();
std::cerr << "MessagesDialog::insertMessages()" << std::endl;
std::cerr << "Current Row: " << listrow << std::endl;
fflush(0);
/* check the mode we are in */
unsigned int msgbox = 0;
bool bFill = true;
switch(listrow)
{
case 3:
@ -619,13 +634,35 @@ void MessagesDialog::insertMessages()
msgbox = RS_MSG_OUTBOX;
break;
case 0:
default:
msgbox = RS_MSG_INBOX;
break;
default:
bFill = false;
}
if (bFill) {
/* remove old items */
int nRowCount = MessagesModel->rowCount();
int nRow = 0;
for (nRow = 0; nRow < nRowCount; ) {
for(it = msgList.begin(); it != msgList.end(); it++) {
if ((it->msgflags & RS_MSG_BOXMASK) != msgbox) {
continue;
}
if (it->msgId == MessagesModel->item(nRow, 5)->text().toStdString()) {
break;
}
}
if (it == msgList.end ()) {
MessagesModel->removeRow (nRow);
nRowCount = MessagesModel->rowCount();
} else {
nRow++;
}
}
//std::list<std::string>::iterator it;
for(it = msgList.begin(); it != msgList.end(); it++)
{
/* check the message flags, to decide which
@ -653,14 +690,41 @@ void MessagesDialog::insertMessages()
continue;
}
// search exisisting items
nRowCount = MessagesModel->rowCount();
for (nRow = 0; nRow < nRowCount; nRow++) {
if (it->msgId == MessagesModel->item(nRow, 5)->text().toStdString()) {
break;
}
}
/* make a widget per friend */
QStandardItem *item0 = new QStandardItem();
QStandardItem *item1 = new QStandardItem();
QStandardItem *item2 = new QStandardItem();
QStandardItem *item3 = new QStandardItem();
QStandardItem *item4 = new QStandardItem();
QStandardItem *item5 = new QStandardItem();
QStandardItem *item0 = NULL;
QStandardItem *item1 = NULL;
QStandardItem *item2 = NULL;
QStandardItem *item3 = NULL;
QStandardItem *item4 = NULL;
QStandardItem *item5 = NULL;
bool bInsert = false;
if (nRow < nRowCount) {
item0 = MessagesModel->item(nRow, 0);
item1 = MessagesModel->item(nRow, 1);
item2 = MessagesModel->item(nRow, 2);
item3 = MessagesModel->item(nRow, 3);
item4 = MessagesModel->item(nRow, 4);
item5 = MessagesModel->item(nRow, 5);
} else {
item0 = new QStandardItem();
item1 = new QStandardItem();
item2 = new QStandardItem();
item3 = new QStandardItem();
item4 = new QStandardItem();
item5 = new QStandardItem();
bInsert = true;
}
//set this false if you want to expand on double click
item0->setEditable(false);
@ -669,7 +733,6 @@ void MessagesDialog::insertMessages()
item3->setEditable(false);
item4->setEditable(false);
/* So Text should be:
* (1) Msg / Broadcast
* (1b) Person / Channel Name
@ -698,15 +761,19 @@ void MessagesDialog::insertMessages()
QVariant varDateTime(qdatetime);
item3->setData(varDateTime, Qt::DisplayRole);
}
// for sorting
item3->setData(qdatetime, Qt::UserRole);
}
// From ....
{
item2 -> setText(QString::fromStdString(rsPeers->getPeerName(it->srcId)));
item2->setData(item2->text(), Qt::UserRole);
}
// Subject
item1 -> setText(QString::fromStdWString(it->title));
item1->setData(item1->text(), Qt::UserRole);
if ((it -> msgflags & RS_MSG_NEW) == RS_MSG_NEW)
{
@ -770,17 +837,14 @@ void MessagesDialog::insertMessages()
std::ostringstream out;
out << it -> count;
item0 -> setText(QString::fromStdString(out.str()));
item0->setData(item0->text(), Qt::UserRole);
//item -> setTextAlignment( 0, Qt::AlignCenter );
}
item4 -> setText(QString::fromStdString(it->srcId));
item5 -> setText(QString::fromStdString(it->msgId));
if ((oldSelected) && (mid == it->msgId))
{
//newSelected = item;
}
if (bInsert) {
/* add to the list */
QList<QStandardItem *> itemList;
itemList.append(item0);
@ -791,6 +855,10 @@ void MessagesDialog::insertMessages()
itemList.append(item5);
MessagesModel->appendRow(itemList);
}
}
} else {
MessagesModel->removeRows (0, MessagesModel->rowCount());
}
updateMessageSummaryList();
ui.messagestreeView->hideColumn(4);
@ -890,6 +958,10 @@ void MessagesDialog::insertMsgTxtAndFiles(QModelIndex Index)
ui.msgList->clear();
ui.msgText->clear();
ui.actionSave_as->setDisabled(true);
ui.actionPrintPreview->setDisabled(true);
ui.actionPrint->setDisabled(true);
return;
}
else
@ -903,6 +975,16 @@ void MessagesDialog::insertMsgTxtAndFiles(QModelIndex Index)
mid = item->text().toStdString();
}
int nCount = getSelectedMsgCount ();
if (nCount == 1) {
ui.actionSave_as->setEnabled(true);
ui.actionPrintPreview->setEnabled(true);
ui.actionPrint->setEnabled(true);
} else {
ui.actionSave_as->setDisabled(true);
ui.actionPrintPreview->setDisabled(true);
ui.actionPrint->setDisabled(true);
}
/* Save the Data.... for later */
@ -1312,19 +1394,18 @@ void MessagesDialog::updateMessageSummaryList()
/*calculating the new messages*/
for(it = msgList.begin(); it != msgList.end(); it++)
{
if ((it -> msgflags & RS_MSG_BOXMASK) == RS_MSG_INBOX && ((it -> msgflags & RS_MSG_NEW) == RS_MSG_NEW))
{
newInboxCount ++;
}
if ((it -> msgflags & RS_MSG_BOXMASK) == RS_MSG_INBOX )
if ((it -> msgflags & RS_MSG_BOXMASK) == RS_MSG_INBOX)
{
inboxCount ++;
if ((it -> msgflags & RS_MSG_NEW) == RS_MSG_NEW) {
newInboxCount ++;
}
if ((it -> msgflags & RS_MSG_BOXMASK) == RS_MSG_OUTBOX )
}
if ((it -> msgflags & RS_MSG_BOXMASK) == RS_MSG_OUTBOX)
{
newOutboxCount ++;
}
if ((it -> msgflags & RS_MSG_BOXMASK) == RS_MSG_DRAFTBOX )
if ((it -> msgflags & RS_MSG_BOXMASK) == RS_MSG_DRAFTBOX)
{
newDraftCount ++;
}
@ -1336,10 +1417,11 @@ void MessagesDialog::updateMessageSummaryList()
QString textItem;
/*updating the labels in leftcolumn*/
if(newInboxCount != 0)
{
//QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const
QListWidgetItem* item = ui.listWidget->item(0);
if (newInboxCount != 0)
{
textItem = tr("Inbox") + " " + "(" + QString::number(newInboxCount)+")";
item->setText(textItem);
QFont qf = item->font();
@ -1350,8 +1432,6 @@ void MessagesDialog::updateMessageSummaryList()
}
else
{
QListWidgetItem* item = ui.listWidget->item(0);
textItem = tr("Inbox");
item->setText(textItem);
QFont qf = item->font();
@ -1361,11 +1441,10 @@ void MessagesDialog::updateMessageSummaryList()
item->setForeground(QBrush(QColor(0, 0, 0)));
}
if(newOutboxCount != 0)
{
//QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const
QListWidgetItem* item = ui.listWidget->item(1);
item = ui.listWidget->item(1);
if (newOutboxCount != 0)
{
textItem = tr("Outbox") + " " + "(" + QString::number(newOutboxCount)+")";
item->setText(textItem);
QFont qf = item->font();
@ -1374,8 +1453,6 @@ void MessagesDialog::updateMessageSummaryList()
}
else
{
QListWidgetItem* item = ui.listWidget->item(1);
textItem = tr("Outbox");
item->setText(textItem);
QFont qf = item->font();
@ -1384,11 +1461,11 @@ void MessagesDialog::updateMessageSummaryList()
}
if(newDraftCount != 0)
{
//QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const
QListWidgetItem* item = ui.listWidget->item(2);
//QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const
item = ui.listWidget->item(2);
if (newDraftCount != 0)
{
textItem = tr("Draft") + "(" + QString::number(newDraftCount)+")";
item->setText(textItem);
QFont qf = item->font();
@ -1397,8 +1474,6 @@ void MessagesDialog::updateMessageSummaryList()
}
else
{
QListWidgetItem* item = ui.listWidget->item(2);
textItem = tr("Draft");
item->setText(textItem);
QFont qf = item->font();
@ -1408,48 +1483,14 @@ void MessagesDialog::updateMessageSummaryList()
}
/* Total Inbox */
if(inboxCount != 0)
{
QListWidgetItem* item = ui.listWidget->item(5);
item = ui.listWidget->item(5);
textItem = tr("Total Inbox:") + " " + QString::number(inboxCount);
item->setText(textItem);
/*QFont qf = item->font();
qf.setBold(true);
item->setFont(qf);*/
}
else
{
QListWidgetItem* item = ui.listWidget->item(5);
textItem = tr("Total Inbox:") + " " + "0";
item->setText(textItem);
/*QFont qf = item->font();
qf.setBold(false);
item->setFont(qf);*/
}
/* Total Sent */
if(newSentboxCount != 0)
{
QListWidgetItem* item = ui.listWidget->item(6);
item = ui.listWidget->item(6);
textItem = tr("Total Sent:") + " " + QString::number(newSentboxCount);
item->setText(textItem);
/*QFont qf = item->font();
qf.setBold(true);
item->setFont(qf);*/
}
else
{
QListWidgetItem* item = ui.listWidget->item(6);
textItem = tr("Total Sent:") + " " + "0";
item->setText(textItem);
/*QFont qf = item->font();
qf.setBold(false);
item->setFont(qf);*/
}
}
/** clear Filter **/

View File

@ -110,24 +110,11 @@ private:
void setCurrentFileName(const QString &fileName);
int getSelectedMsgCount ();
std::string mCurrCertId;
std::string mCurrMsgId;
/** Define the popup menus for the Context menu */
QMenu* contextMnu;
/** Defines the actions for the context menu */
QAction* newmsgAct;
QAction* replytomsgAct;
QAction* replyallmsgAct;
QAction* forwardmsgAct;
QAction* removemsgAct;
QAction* getRecAct;
QAction* getAllRecAct;
QString fileName;
QFont mFont;

View File

@ -948,13 +948,13 @@ border-image: url(:/images/closepressed.png)
<widget class="QListWidget" name="listWidget">
<property name="minimumSize">
<size>
<width>120</width>
<width>140</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<width>140</width>
<height>16777215</height>
</size>
</property>