diff --git a/retroshare-gui/src/gui/MessagesDialog.cpp b/retroshare-gui/src/gui/MessagesDialog.cpp index df09d2c8f..4d5a13b20 100644 --- a/retroshare-gui/src/gui/MessagesDialog.cpp +++ b/retroshare-gui/src/gui/MessagesDialog.cpp @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. ****************************************************************/ @@ -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) { @@ -90,56 +124,54 @@ static int FilterColumnToComboBox(int nIndex) MessagesDialog::MessagesDialog(QWidget *parent) : MainPage(parent) { - /* Invoke the Qt Designer generated object setup routine */ - ui.setupUi(this); + /* Invoke the Qt Designer generated object setup routine */ + ui.setupUi(this); - m_bProcessSettings = false; + 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 ) ) ); - connect( ui.messagestreeView, SIGNAL(clicked ( const QModelIndex &) ) , this, SLOT( clicked( const QModelIndex & ) ) ); - connect( ui.listWidget, SIGNAL( currentRowChanged ( int) ), this, SLOT( changeBox ( int) ) ); - - connect(ui.newmessageButton, SIGNAL(clicked()), this, SLOT(newmessage())); - connect(ui.removemessageButton, SIGNAL(clicked()), this, SLOT(removemessage())); - connect(ui.replymessageButton, SIGNAL(clicked()), this, SLOT(replytomessage())); - connect(ui.replyallmessageButton, SIGNAL(clicked()), this, SLOT(replyallmessage())); - connect(ui.forwardmessageButton, SIGNAL(clicked()), this, SLOT(forwardmessage())); + connect( ui.messagestreeView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( messageslistWidgetCostumPopupMenu( QPoint ) ) ); + connect( ui.msgList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( msgfilelistWidgetCostumPopupMenu( QPoint ) ) ); + connect( ui.messagestreeView, SIGNAL(clicked ( const QModelIndex &) ) , this, SLOT( clicked( const QModelIndex & ) ) ); + connect( ui.listWidget, SIGNAL( currentRowChanged ( int) ), this, SLOT( changeBox ( int) ) ); - 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())); + connect(ui.newmessageButton, SIGNAL(clicked()), this, SLOT(newmessage())); + connect(ui.removemessageButton, SIGNAL(clicked()), this, SLOT(removemessage())); + connect(ui.replymessageButton, SIGNAL(clicked()), this, SLOT(replytomessage())); + connect(ui.replyallmessageButton, SIGNAL(clicked()), this, SLOT(replyallmessage())); + 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())); - connect(ui.expandFilesButton, SIGNAL(clicked()), this, SLOT(togglefileview())); - connect(ui.downloadButton, SIGNAL(clicked()), this, SLOT(getcurrentrecommended())); - - connect( ui.msgText, SIGNAL( anchorClicked(const QUrl &)), SLOT(anchorClicked(const QUrl &))); - - connect(ui.actionTextBesideIcon, SIGNAL(triggered()), this, SLOT(buttonstextbesideicon())); - connect(ui.actionIconOnly, SIGNAL(triggered()), this, SLOT(buttonsicononly())); - connect(ui.actionTextUnderIcon, SIGNAL(triggered()), this, SLOT(buttonstextundericon())); - - connect(ui.actionSave_as, SIGNAL(triggered()), this, SLOT(fileSaveAs())); - ui.actionSave_as->setDisabled(true); + connect(ui.expandFilesButton, SIGNAL(clicked()), this, SLOT(togglefileview())); + connect(ui.downloadButton, SIGNAL(clicked()), this, SLOT(getcurrentrecommended())); - connect( ui.clearButton, SIGNAL(clicked()), this, SLOT(clearFilter())); - connect( ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged())); + connect( ui.msgText, SIGNAL( anchorClicked(const QUrl &)), SLOT(anchorClicked(const QUrl &))); - connect(ui.filterColumnComboBox, SIGNAL(currentIndexChanged(int)), - this, SLOT(filterColumnChanged())); + connect(ui.actionTextBesideIcon, SIGNAL(triggered()), this, SLOT(buttonstextbesideicon())); + connect(ui.actionIconOnly, SIGNAL(triggered()), this, SLOT(buttonsicononly())); + 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(filterRegExpChanged())); - mCurrCertId = ""; - mCurrMsgId = ""; - - // Set the QStandardItemModel + connect(ui.filterColumnComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterColumnChanged())); + + mCurrCertId = ""; + mCurrMsgId = ""; + + // Set the QStandardItemModel 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")); @@ -153,9 +185,12 @@ MessagesDialog::MessagesDialog(QWidget *parent) proxyModel->sort (COLUMN_DATE, Qt::DescendingOrder); 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->setSortingEnabled(true); ui.messagestreeView->sortByColumn(COLUMN_DATE, Qt::DescendingOrder); // connect after setting model @@ -166,58 +201,62 @@ MessagesDialog::MessagesDialog(QWidget *parent) QShortcut *Shortcut = new QShortcut(QKeySequence (Qt::Key_Delete), ui.messagestreeView, 0, 0, Qt::WidgetShortcut); connect(Shortcut, SIGNAL(activated()), this, SLOT( removemessage ())); - /* hide the Tree +/- */ - ui.msgList->setRootIsDecorated( false ); - ui.msgList->setSelectionMode( QAbstractItemView::ExtendedSelection ); - - /* Set header resize modes and 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_FROM, 140 ); - msgwheader->resizeSection ( COLUMN_DATE, 140 ); - - /* Set header resize modes and initial section sizes */ - QHeaderView * msglheader = ui.msgList->header () ; - msglheader->setResizeMode (0, QHeaderView::Interactive); - msglheader->setResizeMode (1, QHeaderView::Interactive); - msglheader->setResizeMode (2, QHeaderView::Interactive); - msglheader->setResizeMode (3, QHeaderView::Interactive); - - msglheader->resizeSection ( 0, 200 ); - msglheader->resizeSection ( 1, 100 ); - msglheader->resizeSection ( 2, 100 ); - msglheader->resizeSection ( 3, 200 ); + /* hide the Tree +/- */ + ui.msgList->setRootIsDecorated( false ); + ui.msgList->setSelectionMode( QAbstractItemView::ExtendedSelection ); - ui.forwardmessageButton->setToolTip(tr("Forward selected Message")); - ui.replyallmessageButton->setToolTip(tr("Reply to All")); + /* Set header initial section sizes */ + QHeaderView * msgwheader = ui.messagestreeView->header () ; + 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); + + /* Set header resize modes and initial section sizes */ + QHeaderView * msglheader = ui.msgList->header () ; + msglheader->setResizeMode (0, QHeaderView::Interactive); + msglheader->setResizeMode (1, QHeaderView::Interactive); + msglheader->setResizeMode (2, QHeaderView::Interactive); + msglheader->setResizeMode (3, QHeaderView::Interactive); + + msglheader->resizeSection (0, 200); + msglheader->resizeSection (1, 100); + msglheader->resizeSection (2, 100); + msglheader->resizeSection (3, 200); + + ui.forwardmessageButton->setToolTip(tr("Forward selected Message")); + ui.replyallmessageButton->setToolTip(tr("Reply to All")); QMenu * printmenu = new QMenu(); printmenu->addAction(ui.actionPrint); printmenu->addAction(ui.actionPrintPreview); ui.printbutton->setMenu(printmenu); - + QMenu * viewmenu = new QMenu(); viewmenu->addAction(ui.actionTextBesideIcon); viewmenu->addAction(ui.actionIconOnly); //viewmenu->addAction(ui.actionTextUnderIcon); ui.viewtoolButton->setMenu(viewmenu); - loadToolButtonsettings(); - - mFont = QFont("Arial", 10, QFont::Bold); - ui.subjectText->setFont(mFont); + loadToolButtonsettings(); - //setting default filter by column as subject + mFont = QFont("Arial", 10, QFont::Bold); + ui.subjectText->setFont(mFont); + + //setting default filter by column as subject proxyModel->setFilterKeyColumn(FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex())); - - ui.clearButton->hide(); + + ui.clearButton->hide(); // 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 *pRowsRead, QList *pRowsUnread) { + if (pRowsRead) pRowsRead->clear(); + if (pRowsUnread) pRowsUnread->clear(); + //To check if the selection has more than one row. QList selectedIndexList = ui.messagestreeView->selectionModel() -> selectedIndexes (); QList 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 RowsRead; + QList 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); @@ -383,7 +463,7 @@ void MessagesDialog::msgfilelistWidgetCostumPopupMenu( QPoint point ) getRecAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download" ), this ); connect( getRecAct , SIGNAL( triggered() ), this, SLOT( getcurrentrecommended() ) ); - + // getAllRecAct = new QAction(QIcon(IMAGE_DOWNLOADALL), tr( "Download" ), this ); // connect( getAllRecAct , SIGNAL( triggered() ), this, SLOT( getallrecommended() ) ); @@ -408,166 +488,164 @@ void MessagesDialog::newmessage() void MessagesDialog::replytomessage() { - /* put msg on msgBoard, and switch to it. */ + /* put msg on msgBoard, and switch to it. */ - std::string cid; - std::string mid; + std::string cid; + std::string mid; - if(!getCurrentMsg(cid, mid)) - return ; + if(!getCurrentMsg(cid, mid)) + return ; - mCurrCertId = cid; - mCurrMsgId = mid; + mCurrCertId = cid; + mCurrMsgId = mid; - MessageInfo msgInfo; - if (!rsMsgs -> getMessage(mid, msgInfo)) - return ; + MessageInfo msgInfo; + if (!rsMsgs -> getMessage(mid, msgInfo)) + return ; - ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true); - /* fill it in */ - //std::cerr << "MessagesDialog::newmessage()" << std::endl; - nMsgDialog->newMsg(); - - QString text = QString::fromStdWString(msgInfo.title); - - if (text.startsWith("Re:", Qt::CaseInsensitive)) - { + ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true); + /* fill it in */ + //std::cerr << "MessagesDialog::newmessage()" << std::endl; + nMsgDialog->newMsg(); + + QString text = QString::fromStdWString(msgInfo.title); + + if (text.startsWith("Re:", Qt::CaseInsensitive)) + { nMsgDialog->insertTitleText( QString::fromStdWString(msgInfo.title).toStdString()) ; - } - else - { + } + else + { nMsgDialog->insertTitleText( (QString("Re: ") + QString::fromStdWString(msgInfo.title)).toStdString()) ; - } - - nMsgDialog->setWindowTitle( tr ("Compose: ") + tr("Re: ") + QString::fromStdWString(msgInfo.title) ) ; + } + + nMsgDialog->setWindowTitle( tr ("Compose: ") + tr("Re: ") + QString::fromStdWString(msgInfo.title) ) ; - QTextDocument doc ; - doc.setHtml(QString::fromStdWString(msgInfo.msg)) ; - std::string cited_text(doc.toPlainText().toStdString()) ; + QTextDocument doc ; + doc.setHtml(QString::fromStdWString(msgInfo.msg)) ; + std::string cited_text(doc.toPlainText().toStdString()) ; - nMsgDialog->insertPastedText(cited_text) ; - nMsgDialog->addRecipient( msgInfo.srcId ) ; - nMsgDialog->show(); - nMsgDialog->activateWindow(); + nMsgDialog->insertPastedText(cited_text) ; + nMsgDialog->addRecipient( msgInfo.srcId ) ; + nMsgDialog->show(); + nMsgDialog->activateWindow(); - /* window will destroy itself! */ + /* window will destroy itself! */ } void MessagesDialog::replyallmessage() { - /* put msg on msgBoard, and switch to it. */ + /* put msg on msgBoard, and switch to it. */ - std::string cid; - std::string mid; + std::string cid; + std::string mid; - if(!getCurrentMsg(cid, mid)) - return ; + if(!getCurrentMsg(cid, mid)) + return ; - mCurrCertId = cid; - mCurrMsgId = mid; + mCurrCertId = cid; + mCurrMsgId = mid; - MessageInfo msgInfo; - if (!rsMsgs -> getMessage(mid, msgInfo)) - return ; + MessageInfo msgInfo; + if (!rsMsgs -> getMessage(mid, msgInfo)) + return ; - ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true); - /* fill it in */ - //std::cerr << "MessagesDialog::newmessage()" << std::endl; - nMsgDialog->newMsg(); - - QString text = QString::fromStdWString(msgInfo.title); - - if (text.startsWith("Re:", Qt::CaseInsensitive)) - { + ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true); + /* fill it in */ + //std::cerr << "MessagesDialog::newmessage()" << std::endl; + nMsgDialog->newMsg(); + + QString text = QString::fromStdWString(msgInfo.title); + + if (text.startsWith("Re:", Qt::CaseInsensitive)) + { nMsgDialog->insertTitleText( QString::fromStdWString(msgInfo.title).toStdString()) ; - } - else - { + } + else + { nMsgDialog->insertTitleText( (QString("Re: ") + QString::fromStdWString(msgInfo.title)).toStdString()) ; - } - nMsgDialog->setWindowTitle( tr ("Compose: ") + tr("Re: ") + QString::fromStdWString(msgInfo.title) ) ; + } + nMsgDialog->setWindowTitle( tr ("Compose: ") + tr("Re: ") + QString::fromStdWString(msgInfo.title) ) ; - QTextDocument doc ; - doc.setHtml(QString::fromStdWString(msgInfo.msg)) ; - std::string cited_text(doc.toPlainText().toStdString()) ; + QTextDocument doc ; + doc.setHtml(QString::fromStdWString(msgInfo.msg)) ; + std::string cited_text(doc.toPlainText().toStdString()) ; + + nMsgDialog->insertPastedText(cited_text) ; + nMsgDialog->addRecipient( msgInfo.srcId ) ; - nMsgDialog->insertPastedText(cited_text) ; - nMsgDialog->addRecipient( msgInfo.srcId ) ; - std::list tl ( msgInfo.msgto ); - for( std::list::iterator tli = tl.begin(); - tli!= tl.end() ; - tli++ ) + for ( std::list::iterator tli = tl.begin(); tli!= tl.end(); tli++ ) { nMsgDialog->addRecipient( *tli ) ; - } - - nMsgDialog->show(); - nMsgDialog->activateWindow(); + } - /* window will destroy itself! */ + nMsgDialog->show(); + nMsgDialog->activateWindow(); + + /* window will destroy itself! */ } void MessagesDialog::forwardmessage() { - /* put msg on msgBoard, and switch to it. */ + /* put msg on msgBoard, and switch to it. */ - std::string cid; - std::string mid; + std::string cid; + std::string mid; - if(!getCurrentMsg(cid, mid)) - return ; + if(!getCurrentMsg(cid, mid)) + return ; - mCurrCertId = cid; - mCurrMsgId = mid; + mCurrCertId = cid; + mCurrMsgId = mid; - MessageInfo msgInfo; - if (!rsMsgs -> getMessage(mid, msgInfo)) - return ; + MessageInfo msgInfo; + if (!rsMsgs -> getMessage(mid, msgInfo)) + return ; - ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true); - /* fill it in */ - //std::cerr << "MessagesDialog::newmessage()" << std::endl; - nMsgDialog->newMsg(); - - QString text = QString::fromStdWString(msgInfo.title); - - if (text.startsWith("Fwd:", Qt::CaseInsensitive)) - { + ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true); + /* fill it in */ + //std::cerr << "MessagesDialog::newmessage()" << std::endl; + nMsgDialog->newMsg(); + + QString text = QString::fromStdWString(msgInfo.title); + + if (text.startsWith("Fwd:", Qt::CaseInsensitive)) + { nMsgDialog->insertTitleText( QString::fromStdWString(msgInfo.title).toStdString()) ; - } - else - { + } + else + { nMsgDialog->insertTitleText( (QString("Fwd: ") + QString::fromStdWString(msgInfo.title)).toStdString()) ; - } - - nMsgDialog->setWindowTitle( tr ("Compose: ") + tr("Fwd: ") + QString::fromStdWString(msgInfo.title) ) ; + } + + nMsgDialog->setWindowTitle( tr ("Compose: ") + tr("Fwd: ") + QString::fromStdWString(msgInfo.title) ) ; - QTextDocument doc ; - doc.setHtml(QString::fromStdWString(msgInfo.msg)) ; - std::string cited_text(doc.toPlainText().toStdString()) ; + QTextDocument doc ; + doc.setHtml(QString::fromStdWString(msgInfo.msg)) ; + std::string cited_text(doc.toPlainText().toStdString()) ; - nMsgDialog->insertForwardPastedText(cited_text) ; + nMsgDialog->insertForwardPastedText(cited_text) ; - std::list& files_info = msgInfo.files; + std::list& files_info = msgInfo.files; - /* enable all files for sending */ - std::list::iterator it; - for(it = files_info.begin(); it != files_info.end(); it++) - { - it->inRecommend = true; - } + /* enable all files for sending */ + std::list::iterator it; + for(it = files_info.begin(); it != files_info.end(); it++) + { + it->inRecommend = true; + } - nMsgDialog->insertFileList(files_info); - //nMsgDialog->addRecipient( msgInfo.srcId ) ; - nMsgDialog->show(); - nMsgDialog->activateWindow(); + nMsgDialog->insertFileList(files_info); + //nMsgDialog->addRecipient( msgInfo.srcId ) ; + nMsgDialog->show(); + nMsgDialog->activateWindow(); - /* window will destroy itself! */ + /* window will destroy itself! */ } void MessagesDialog::togglefileview_internal() @@ -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")); } @@ -600,353 +675,394 @@ void MessagesDialog::togglefileview() /* download the recommendations... */ void MessagesDialog::getcurrentrecommended() { - MessageInfo msgInfo; - if (!rsMsgs -> getMessage(mCurrMsgId, msgInfo)) - return; + MessageInfo msgInfo; + if (!rsMsgs -> getMessage(mCurrMsgId, msgInfo)) + return; - std::list srcIds; - srcIds.push_back(msgInfo.srcId); + std::list srcIds; + srcIds.push_back(msgInfo.srcId); - QModelIndexList list = ui.msgList->selectionModel()->selectedIndexes(); + QModelIndexList list = ui.msgList->selectionModel()->selectedIndexes(); - std::map files ; + std::map files ; - for(QModelIndexList::const_iterator it(list.begin());it!=list.end();++it) - { - FileInfo& f(files[it->row()]) ; + for(QModelIndexList::const_iterator it(list.begin());it!=list.end();++it) + { + FileInfo& f(files[it->row()]) ; - switch(it->column()) - { - case 0: f.fname = it->data().toString().toStdString() ; - break ; - case 1: f.size = it->data().toULongLong() ; - break ; - case 3: f.hash = it->data().toString().toStdString() ; - break ; - default: ; - } - } + switch(it->column()) + { + case 0: f.fname = it->data().toString().toStdString() ; + break ; + case 1: f.size = it->data().toULongLong() ; + break ; + case 3: f.hash = it->data().toString().toStdString() ; + break ; + default: ; + } + } - for(std::map::const_iterator it(files.begin());it!=files.end();++it) - { - const FileInfo& f(it->second) ; - std::cout << "Requesting file " << f.fname << ", size=" << f.size << ", hash=" << f.hash << std::endl ; - rsFiles -> FileRequest(it->second.fname,it->second.hash,it->second.size, "", RS_FILE_HINTS_NETWORK_WIDE, srcIds); - } + for(std::map::const_iterator it(files.begin());it!=files.end();++it) + { + const FileInfo& f(it->second) ; + std::cout << "Requesting file " << f.fname << ", size=" << f.size << ", hash=" << f.hash << std::endl ; + rsFiles -> FileRequest(it->second.fname,it->second.hash,it->second.size, "", RS_FILE_HINTS_NETWORK_WIDE, srcIds); + } } #if 0 void MessagesDialog::getallrecommended() { - /* get Message */ - MessageInfo msgInfo; - if (!rsMsgs -> getMessage(mCurrMsgId, msgInfo)) - { - return; - } + /* get Message */ + MessageInfo msgInfo; + if (!rsMsgs -> getMessage(mCurrMsgId, msgInfo)) + { + return; + } - const std::list &recList = msgInfo.files; - std::list::const_iterator it; + const std::list &recList = msgInfo.files; + std::list::const_iterator it; - std::list fnames; - std::list hashes; - std::list sizes; + std::list fnames; + std::list hashes; + std::list sizes; - for(it = recList.begin(); it != recList.end(); it++) - { - fnames.push_back(it->fname); - hashes.push_back(it->hash); - sizes.push_back(it->size); - } + for(it = recList.begin(); it != recList.end(); it++) + { + fnames.push_back(it->fname); + hashes.push_back(it->hash); + sizes.push_back(it->size); + } - /* now do requests */ - std::list::const_iterator fit; - std::list::const_iterator hit; - std::list::const_iterator sit; + /* now do requests */ + std::list::const_iterator fit; + std::list::const_iterator hit; + std::list::const_iterator sit; - for(fit = fnames.begin(), hit = hashes.begin(), sit = sizes.begin(); fit != fnames.end(); fit++, hit++, sit++) - { - std::cerr << "MessagesDialog::getallrecommended() Calling File Request"; - std::cerr << std::endl; - std::list srcIds; - srcIds.push_back(msgInfo.srcId); - rsFiles -> FileRequest(*fit, *hit, *sit, "", 0, srcIds); - } + for(fit = fnames.begin(), hit = hashes.begin(), sit = sizes.begin(); fit != fnames.end(); fit++, hit++, sit++) + { + std::cerr << "MessagesDialog::getallrecommended() Calling File Request"; + std::cerr << std::endl; + std::list srcIds; + srcIds.push_back(msgInfo.srcId); + rsFiles -> FileRequest(*fit, *hit, *sit, "", 0, srcIds); + } } #endif void MessagesDialog::changeBox(int) { - MessagesModel->removeRows (0, MessagesModel->rowCount()); + MessagesModel->removeRows (0, MessagesModel->rowCount()); - insertMessages(); - insertMsgTxtAndFiles(); + insertMessages(); + 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"; - fflush(0); + std::cerr <<"MessagesDialog::insertMessages called"; + fflush(0); - std::list msgList; - std::list::const_iterator it; + std::list msgList; + std::list::const_iterator it; + MessageInfo msgInfo; + bool bGotInfo; + QString text; - rsMsgs -> getMessageSummaries(msgList); + rsMsgs -> getMessageSummaries(msgList); - int listrow = ui.listWidget -> currentRow(); + int listrow = ui.listWidget -> currentRow(); - std::cerr << "MessagesDialog::insertMessages()" << std::endl; - std::cerr << "Current Row: " << listrow << std::endl; - fflush(0); + std::cerr << "MessagesDialog::insertMessages()" << std::endl; + std::cerr << "Current Row: " << listrow << std::endl; + fflush(0); - int nFilterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex()); + int i; + int nFilterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex()); - /* check the mode we are in */ - unsigned int msgbox = 0; - bool bFill = true; - switch(listrow) - { - case 3: - msgbox = RS_MSG_SENTBOX; - break; - case 2: - msgbox = RS_MSG_DRAFTBOX; - break; - case 1: - msgbox = RS_MSG_OUTBOX; - break; - case 0: - msgbox = RS_MSG_INBOX; - break; - default: - bFill = false; - } + /* check the mode we are in */ + unsigned int msgbox = 0; + bool bFill = true; + switch(listrow) + { + case 3: + msgbox = RS_MSG_SENTBOX; + break; + case 2: + msgbox = RS_MSG_DRAFTBOX; + break; + case 1: + msgbox = RS_MSG_OUTBOX; + break; + case 0: + 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 (msgbox == RS_MSG_INBOX) { + MessagesModel->setHeaderData(COLUMN_FROM, Qt::Horizontal, tr("From")); + } else { + MessagesModel->setHeaderData(COLUMN_FROM, Qt::Horizontal, tr("To")); + } - if (it->msgId == MessagesModel->item(nRow, 5)->text().toStdString()) { - break; - } - } + 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 == msgList.end ()) { - MessagesModel->removeRow (nRow); - nRowCount = MessagesModel->rowCount(); - } else { - nRow++; - } - } + if (it->msgId == MessagesModel->item(nRow, COLUMN_MSGID)->text().toStdString()) { + break; + } + } - for(it = msgList.begin(); it != msgList.end(); it++) - { - /* check the message flags, to decide which - * group it should go in... - * - * InBox - * OutBox - * Drafts - * Sent - * - * FLAGS = OUTGOING. - * -> Outbox/Drafts/Sent - * + SENT -> Sent - * + IN_PROGRESS -> Draft. - * + nuffing -> Outbox. - * FLAGS = INCOMING = (!OUTGOING) - * -> + NEW -> Bold. - * - */ + if (it == msgList.end ()) { + MessagesModel->removeRow (nRow); + nRowCount = MessagesModel->rowCount(); + } else { + nRow++; + } + } - if ((it -> msgflags & RS_MSG_BOXMASK) != msgbox) - { - //std::cerr << "Msg from other box: " << it->msgflags; - //std::cerr << std::endl; - continue; - } + for(it = msgList.begin(); it != msgList.end(); it++) + { + /* check the message flags, to decide which + * group it should go in... + * + * InBox + * OutBox + * Drafts + * Sent + * + * FLAGS = OUTGOING. + * -> Outbox/Drafts/Sent + * + SENT -> Sent + * + IN_PROGRESS -> Draft. + * + nuffing -> Outbox. + * FLAGS = INCOMING = (!OUTGOING) + * -> + NEW -> Bold. + * + */ - // search exisisting items - nRowCount = MessagesModel->rowCount(); - for (nRow = 0; nRow < nRowCount; nRow++) { - if (it->msgId == MessagesModel->item(nRow, 5)->text().toStdString()) { - break; - } - } + if ((it -> msgflags & RS_MSG_BOXMASK) != msgbox) + { + //std::cerr << "Msg from other box: " << it->msgflags; + //std::cerr << std::endl; + continue; + } - /* make a widget per friend */ + bGotInfo = false; + msgInfo = MessageInfo(); // clear - QStandardItem *item [COLUMN_COUNT]; + // search exisisting items + nRowCount = MessagesModel->rowCount(); + for (nRow = 0; nRow < nRowCount; nRow++) { + if (it->msgId == MessagesModel->item(nRow, COLUMN_MSGID)->text().toStdString()) { + break; + } + } - bool bInsert = false; + /* make a widget per friend */ - if (nRow < nRowCount) { - for (int i = 0; i < COLUMN_COUNT; i++) { - item[i] = MessagesModel->item(nRow, i); - } - } else { - for (int i = 0; i < COLUMN_COUNT; i++) { - item[i] = new QStandardItem(); - } - bInsert = true; - } + QStandardItem *item [COLUMN_COUNT]; - //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); + bool bInsert = false; - /* So Text should be: - * (1) Msg / Broadcast - * (1b) Person / Channel Name - * (2) Rank - * (3) Date - * (4) Title - * (5) Msg - * (6) File Count - * (7) File Total - */ + if (nRow < nRowCount) { + for (i = 0; i < COLUMN_COUNT; i++) { + item[i] = MessagesModel->item(nRow, i); + } + } else { + for (i = 0; i < COLUMN_COUNT; i++) { + item[i] = new QStandardItem(); + } + bInsert = true; + } - QString dateString; - // Date First.... (for sorting) - { - QDateTime qdatetime; - qdatetime.setTime_t(it->ts); + //set this false if you want to expand on double click + for (i = 0; i < COLUMN_COUNT; i++) { + item[i]->setEditable(false); + } - // add string to all data - dateString = qdatetime.toString("_yyyyMMdd_hhmmss"); - - //if the mail is on same date show only time. - if (qdatetime.daysTo(QDateTime::currentDateTime()) == 0) - { - QTime qtime = qdatetime.time(); - QVariant varTime(qtime); - item[COLUMN_DATE]->setData(varTime, Qt::DisplayRole); - } - else - { - QVariant varDateTime(qdatetime); - item[COLUMN_DATE]->setData(varDateTime, Qt::DisplayRole); - } - // for sorting - item[COLUMN_DATE]->setData(qdatetime, Qt::UserRole); - } + /* So Text should be: + * (1) Msg / Broadcast + * (1b) Person / Channel Name + * (2) Rank + * (3) Date + * (4) Title + * (5) Msg + * (6) File Count + * (7) File Total + */ - // From .... - { - item[COLUMN_FROM] -> setText(QString::fromStdString(rsPeers->getPeerName(it->srcId))); - item[COLUMN_FROM]->setData(item[COLUMN_FROM]->text() + dateString, Qt::UserRole); + QString dateString; + // Date First.... (for sorting) + { + QDateTime qdatetime; + qdatetime.setTime_t(it->ts); + + // add string to all data + dateString = qdatetime.toString("_yyyyMMdd_hhmmss"); + + //if the mail is on same date show only time. + if (qdatetime.daysTo(QDateTime::currentDateTime()) == 0) + { + QTime qtime = qdatetime.time(); + QVariant varTime(qtime); + item[COLUMN_DATE]->setData(varTime, Qt::DisplayRole); + } + else + { + QVariant varDateTime(qdatetime); + item[COLUMN_DATE]->setData(varDateTime, Qt::DisplayRole); + } + // for sorting + item[COLUMN_DATE]->setData(qdatetime, Qt::UserRole); + } + + // From .... + { + 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::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); - item[COLUMN_SUBJECT] -> setText(text); - item[COLUMN_SUBJECT]->setData(text + dateString, Qt::UserRole); + // Subject + 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); - - } - - // 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")); - } - } + // internal data + item[COLUMN_SRCID]->setText(QString::fromStdString(it->srcId)); + item[COLUMN_MSGID]->setText(QString::fromStdString(it->msgId)); - 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. - { - std::ostringstream out; - out << it -> count; - item[COLUMN_ATTACHEMENTS] -> setText(QString::fromStdString(out.str())); - item[COLUMN_ATTACHEMENTS]->setData(item[COLUMN_ATTACHEMENTS]->text() + dateString, Qt::UserRole); - //item -> setTextAlignment( 0, Qt::AlignCenter ); - } + // No of Files. + { + std::ostringstream out; + out << it -> count; + item[COLUMN_ATTACHEMENTS] -> setText(QString::fromStdString(out.str())); + item[COLUMN_ATTACHEMENTS]->setData(item[COLUMN_ATTACHEMENTS]->text() + dateString, Qt::UserRole); + //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 + 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(" "))); + } else { + std::cerr << "MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg" << std::endl; + item[COLUMN_CONTENT]->setText(""); + } + } - if (nFilterColumn == COLUMN_CONTENT) { - // need content for filter - MessageInfo msgInfo; - if (rsMsgs->getMessage(it->msgId, msgInfo)) { - QTextDocument doc; - doc.setHtml(QString::fromStdWString(msgInfo.msg)); - item[COLUMN_CONTENT]->setText(doc.toPlainText().replace(QString("\n"), QString(" "))); - } else { - std::cerr << "MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg" << std::endl; - item[COLUMN_CONTENT]->setText(""); - } - } + if (bInsert) { + /* add to the list */ + QList itemList; + for (i = 0; i < COLUMN_COUNT; i++) { + itemList.append(item[i]); + } + MessagesModel->appendRow(itemList); + } + } + } else { + MessagesModel->removeRows (0, MessagesModel->rowCount()); + } - if (bInsert) { - /* add to the list */ - QList itemList; - for (int i = 0; i < COLUMN_COUNT; i++) { - itemList.append(item[i]); - } - MessagesModel->appendRow(itemList); - } - } - } else { - MessagesModel->removeRows (0, MessagesModel->rowCount()); - } - - updateMessageSummaryList(); - ui.messagestreeView->hideColumn(COLUMN_SRCID); - ui.messagestreeView->hideColumn(COLUMN_MSGID); - ui.messagestreeView->hideColumn(COLUMN_CONTENT); + 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 Rows; + Rows.append(mappedRow); + setMsgAsReadUnread(Rows, !isMessageRead(mappedRow)); + insertMsgTxtAndFiles(index, false); + updateMessageSummaryList(); + return; + } + timer->stop(); timerIndex = index; // show current message directly @@ -969,266 +1100,296 @@ void MessagesDialog::clicked(const QModelIndex &index ) // show current message directly void MessagesDialog::updateCurrentMessage() { - timer->stop(); - insertMsgTxtAndFiles(timerIndex); - setMsgAsRead(timerIndex); - updateMessageSummaryList(); + timer->stop(); + insertMsgTxtAndFiles(timerIndex); } -void MessagesDialog::setMsgAsRead(const QModelIndex &index) +void MessagesDialog::setMsgAsReadUnread(const QList &Rows, bool bRead) { - QString text; - QModelIndex currentIndex = proxyModel->mapToSource(index); - if (currentIndex.isValid() == false) - { - return; - } - else - { - for(int i = 0; i < COLUMN_COUNT; i++) - { - - 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")); - } - - } - if(i == COLUMN_MSGID) - { - std::string mid(item->text().toStdString()); - rsMsgs->MessageRead(mid); - } - } - } -} - -void MessagesDialog::insertMsgTxtAndFiles(QModelIndex Index) -{ - std::cerr << "MessagesDialog::insertMsgTxtAndFiles()" << std::endl; - - /* get its Ids */ - std::string cid; - std::string mid; - - QModelIndex currentIndex = proxyModel->mapToSource(Index); - if (currentIndex.isValid() == false) - { - /* blank it */ - ui.dateText-> setText(""); - ui.toText->setText(""); - ui.fromText->setText(""); - ui.filesText->setText(""); - - ui.subjectText->setText(""); - ui.msgList->clear(); - ui.msgText->clear(); - - ui.actionSave_as->setDisabled(true); - ui.actionPrintPreview->setDisabled(true); - ui.actionPrint->setDisabled(true); - - return; - } - else - { - QStandardItem * item; - item = MessagesModel->item(currentIndex.row(),COLUMN_SRCID); - cid = item->text().toStdString(); - fflush(0); - - item = MessagesModel->item(currentIndex.row(),COLUMN_MSGID); - 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); + 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); } - /* Save the Data.... for later */ + QString mid = item[COLUMN_MSGID]->text(); - mCurrCertId = cid; - mCurrMsgId = mid; + 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(); - MessageInfo msgInfo; - if (!rsMsgs -> getMessage(mid, msgInfo)) - { - std::cerr << "MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg" << std::endl; - return; - } + InitIconAndFont(m_pConfig, item, 0); + } +} - const std::list &recList = msgInfo.files; - std::list::const_iterator it; +void MessagesDialog::markAsRead() +{ + QList RowsUnread; + getSelectedMsgCount (NULL, &RowsUnread); - /* get a link to the table */ - QTreeWidget *tree = ui.msgList; + setMsgAsReadUnread (RowsUnread, true); + updateMessageSummaryList(); +} - /* get the MessageInfo */ +void MessagesDialog::markAsUnread() +{ + QList RowsRead; + getSelectedMsgCount (&RowsRead, NULL); - tree->clear(); - tree->setColumnCount(5); + setMsgAsReadUnread (RowsRead, false); + updateMessageSummaryList(); +} - QList items; - for(it = recList.begin(); it != recList.end(); it++) - { - /* make a widget per person */ - QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0); - /* (0) Filename */ - item -> setText(0, QString::fromStdString(it->fname)); - //std::cerr << "Msg FileItem(" << it->fname.length() << ") :" << it->fname << std::endl; +void MessagesDialog::insertMsgTxtAndFiles(QModelIndex Index, bool bSetToRead) +{ + std::cerr << "MessagesDialog::insertMsgTxtAndFiles()" << std::endl; - item -> setText(1, QString::number(it->size)); /* (1) Size */ - item -> setText(2, QString::number(0)); /* (2) Rank */ // what is this ??? - item -> setText(3, QString::fromStdString(it->hash)); + /* get its Ids */ + std::string cid; + std::string mid; - /* add to the list */ - items.append(item); - } + QModelIndex currentIndex = proxyModel->mapToSource(Index); + if (currentIndex.isValid() == false) + { + /* blank it */ + ui.dateText-> setText(""); + ui.toText->setText(""); + ui.fromText->setText(""); + ui.filesText->setText(""); - /* add the items in! */ - tree->insertTopLevelItems(0, items); + ui.subjectText->setText(""); + ui.msgList->clear(); + ui.msgText->clear(); - /* iterate through the sources */ - std::list::const_iterator pit; + ui.actionSave_as->setDisabled(true); + ui.actionPrintPreview->setDisabled(true); + ui.actionPrint->setDisabled(true); - QString msgTxt; - for(pit = msgInfo.msgto.begin(); pit != msgInfo.msgto.end(); pit++) - { - if (QString::fromStdString(rsPeers->getPeerName(*pit)) == "") - { - msgTxt += " " + tr("Anonymous") + "" + " "; - } - else - msgTxt += " " + QString::fromStdString(rsPeers->getPeerName(*pit)) + "" + " "; - - } + return; + } + else + { + QStandardItem * item; + item = MessagesModel->item(currentIndex.row(),COLUMN_SRCID); + cid = item->text().toStdString(); + fflush(0); - if (msgInfo.msgcc.size() > 0) - msgTxt += "\nCc: "; - for(pit = msgInfo.msgcc.begin(); pit != msgInfo.msgcc.end(); pit++) - { - if (QString::fromStdString(rsPeers->getPeerName(*pit)) == "") - { - msgTxt += " " + tr("Anonymous") + "" + " "; - } - else - msgTxt += " " + QString::fromStdString(rsPeers->getPeerName(*pit)) + "" + " "; - } + item = MessagesModel->item(currentIndex.row(),COLUMN_MSGID); + mid = item->text().toStdString(); + } - if (msgInfo.msgbcc.size() > 0) - msgTxt += "\nBcc: "; - for(pit = msgInfo.msgbcc.begin(); pit != msgInfo.msgbcc.end(); pit++) - { - if (QString::fromStdString(rsPeers->getPeerName(*pit)) == "") - { - msgTxt += " " + tr("Anonymous") + "" + " "; - } - else - msgTxt += " " + QString::fromStdString(rsPeers->getPeerName(*pit)) + "" + " "; - } + int nCount = getSelectedMsgCount (NULL, NULL); + 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); + } - { - QDateTime qtime; - qtime.setTime_t(msgInfo.ts); - QString timestamp = qtime.toString("dd.MM.yyyy hh:mm:ss"); - ui.dateText-> setText(timestamp); - } - ui.toText->setText(msgTxt); - ui.fromText->setText(" " + QString::fromStdString(rsPeers->getPeerName(msgInfo.srcId)) +""); - ui.fromText->setToolTip(QString::fromStdString(rsPeers->getPeerName(msgInfo.srcId)) + "@" + QString::fromStdString(msgInfo.srcId)); + if (mCurrMsgId == mid) { + // message doesn't changed + return; + } - ui.subjectText->setText(QString::fromStdWString(msgInfo.title)); - ui.msgText->setHtml(QString::fromStdWString(msgInfo.msg)); + /* Save the Data.... for later */ - { - std::ostringstream out; - out << "(" << msgInfo.count << " Files)"; - ui.filesText->setText(QString::fromStdString(out.str())); - } + mCurrCertId = cid; + mCurrMsgId = mid; - std::cerr << "MessagesDialog::insertMsgTxtAndFiles() Msg Displayed OK!" << std::endl; + MessageInfo msgInfo; + if (!rsMsgs -> getMessage(mid, msgInfo)) + { + std::cerr << "MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg" << std::endl; + return; + } + + QList 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 &recList = msgInfo.files; + std::list::const_iterator it; + + /* get a link to the table */ + QTreeWidget *tree = ui.msgList; + + /* get the MessageInfo */ + + tree->clear(); + tree->setColumnCount(5); + + QList items; + for(it = recList.begin(); it != recList.end(); it++) + { + /* make a widget per person */ + QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0); + /* (0) Filename */ + item -> setText(0, QString::fromStdString(it->fname)); + //std::cerr << "Msg FileItem(" << it->fname.length() << ") :" << it->fname << std::endl; + + item -> setText(1, QString::number(it->size)); /* (1) Size */ + item -> setText(2, QString::number(0)); /* (2) Rank */ // what is this ??? + item -> setText(3, QString::fromStdString(it->hash)); + + /* add to the list */ + items.append(item); + } + + /* add the items in! */ + tree->insertTopLevelItems(0, items); + + /* iterate through the sources */ + std::list::const_iterator pit; + + QString msgTxt; + for(pit = msgInfo.msgto.begin(); pit != msgInfo.msgto.end(); pit++) + { + QString sPeer = QString::fromStdString(rsPeers->getPeerName(*pit)); + if (sPeer.isEmpty()) + { + msgTxt += " " + tr("Anonymous") + "" + " "; + } + else + msgTxt += " " + sPeer + "" + " "; + } + + if (msgInfo.msgcc.size() > 0) + msgTxt += "\nCc: "; + for(pit = msgInfo.msgcc.begin(); pit != msgInfo.msgcc.end(); pit++) + { + QString sPeer = QString::fromStdString(rsPeers->getPeerName(*pit)); + if (sPeer.isEmpty()) + { + msgTxt += " " + tr("Anonymous") + "" + " "; + } + else + msgTxt += " " + sPeer + "" + " "; + } + + if (msgInfo.msgbcc.size() > 0) + msgTxt += "\nBcc: "; + for(pit = msgInfo.msgbcc.begin(); pit != msgInfo.msgbcc.end(); pit++) + { + QString sPeer = QString::fromStdString(rsPeers->getPeerName(*pit)); + if (sPeer.isEmpty()) + { + msgTxt += " " + tr("Anonymous") + "" + " "; + } + else + msgTxt += " " + sPeer + "" + " "; + } + + { + QDateTime qtime; + qtime.setTime_t(msgInfo.ts); + QString timestamp = qtime.toString("dd.MM.yyyy hh:mm:ss"); + ui.dateText-> setText(timestamp); + } + ui.toText->setText(msgTxt); + ui.fromText->setText(" " + QString::fromStdString(rsPeers->getPeerName(msgInfo.srcId)) +""); + ui.fromText->setToolTip(QString::fromStdString(rsPeers->getPeerName(msgInfo.srcId)) + "@" + QString::fromStdString(msgInfo.srcId)); + + ui.subjectText->setText(QString::fromStdWString(msgInfo.title)); + ui.msgText->setHtml(QString::fromStdWString(msgInfo.msg)); + + { + std::ostringstream out; + out << "(" << msgInfo.count << " Files)"; + ui.filesText->setText(QString::fromStdString(out.str())); + } + + std::cerr << "MessagesDialog::insertMsgTxtAndFiles() Msg Displayed OK!" << std::endl; } bool MessagesDialog::getCurrentMsg(std::string &cid, std::string &mid) { - QModelIndex currentIndex = ui.messagestreeView->currentIndex(); - currentIndex = proxyModel->mapToSource(currentIndex); - int rowSelected = -1; + QModelIndex currentIndex = ui.messagestreeView->currentIndex(); + currentIndex = proxyModel->mapToSource(currentIndex); + int rowSelected = -1; - /* get its Ids */ - if (currentIndex.isValid() == false) - { - //If no message is selected. assume first message is selected. - if(MessagesModel->rowCount() == 0) - { - return false; - } - else - { - rowSelected = 0; - } - } - else - { - rowSelected = currentIndex.row(); - } + /* get its Ids */ + if (currentIndex.isValid() == false) + { + //If no message is selected. assume first message is selected. + if(MessagesModel->rowCount() == 0) + { + return false; + } + else + { + rowSelected = 0; + } + } + else + { + rowSelected = currentIndex.row(); + } - QStandardItem *item; - item = MessagesModel->item(rowSelected,COLUMN_SRCID); - cid = item->text().toStdString(); - - item = MessagesModel->item(rowSelected,COLUMN_MSGID); - mid = item->text().toStdString(); - return true; + QStandardItem *item; + item = MessagesModel->item(rowSelected,COLUMN_SRCID); + cid = item->text().toStdString(); + + item = MessagesModel->item(rowSelected,COLUMN_MSGID); + mid = item->text().toStdString(); + return true; } void MessagesDialog::removemessage() { - QList selectedIndexList= ui.messagestreeView->selectionModel() -> selectedIndexes (); - QList rowList; - QModelIndex selectedIndex; - for(QList::iterator it = selectedIndexList.begin(); it != selectedIndexList.end(); it++) - { - selectedIndex = proxyModel->mapToSource(*it); - int row = selectedIndex.row(); - if (rowList.contains(row) == false) - { - rowList.append(row); - } - } + QList selectedIndexList= ui.messagestreeView->selectionModel() -> selectedIndexes (); + QList rowList; + QModelIndex selectedIndex; - for(QList::const_iterator it1(rowList.begin());it1!=rowList.end();++it1) - { - rsMsgs->MessageDelete(MessagesModel->item((*it1),COLUMN_MSGID)->text().toStdString()); - } + for(QList::iterator it = selectedIndexList.begin(); it != selectedIndexList.end(); it++) { + selectedIndex = proxyModel->mapToSource(*it); + int row = selectedIndex.row(); + if (rowList.contains(row) == false) + { + rowList.append(row); + } + } - insertMessages(); - return; + for(QList::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(); + return; } void MessagesDialog::print() @@ -1255,55 +1416,55 @@ void MessagesDialog::printpreview() preview->show(); } -void MessagesDialog::anchorClicked (const QUrl& link ) +void MessagesDialog::anchorClicked (const QUrl& link ) { #ifdef FORUM_DEBUG - std::cerr << "MessagesDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl; + std::cerr << "MessagesDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl; #endif - - if (link.scheme() == "retroshare") - { - RetroShareLink rslnk(link.toString()) ; + + if (link.scheme() == "retroshare") + { + RetroShareLink rslnk(link.toString()) ; #ifdef FORUM_DEBUG - std::cerr << "MessagesDialog::anchorClicked FileRequest : fileName : " << fileName << ". fileHash : " << fileHash << ". fileSize : " << fileSize << std::endl; + std::cerr << "MessagesDialog::anchorClicked FileRequest : fileName : " << fileName << ". fileHash : " << fileHash << ". fileSize : " << fileSize << std::endl; #endif - if(rslnk.valid()) - { - std::list srcIds; + if(rslnk.valid()) + { + std::list srcIds; - if(rsFiles->FileRequest(rslnk.name().toStdString(), rslnk.hash().toStdString(), rslnk.size(), "", RS_FILE_HINTS_NETWORK_WIDE, srcIds)) - { - QMessageBox mb(tr("File Request Confirmation"), tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0); - mb.setButtonText( QMessageBox::Ok, "OK" ); - mb.exec(); - } - else - { - QMessageBox mb(tr("File Request canceled"), tr("The file has not been added to your download list, because you already have it."),QMessageBox::Information,QMessageBox::Ok,0,0); - mb.setButtonText( QMessageBox::Ok, "OK" ); - mb.exec(); - } - } - else - { - QMessageBox mb(tr("File Request Error"), tr("The file link is malformed."),QMessageBox::Information,QMessageBox::Ok,0,0); - mb.setButtonText( QMessageBox::Ok, "OK" ); - mb.exec(); - } - } - else if (link.scheme() == "http") - { - QDesktopServices::openUrl(link); - } - else if (link.scheme() == "") - { - //it's probably a web adress, let's add http:// at the beginning of the link - QString newAddress = link.toString(); - newAddress.prepend("http://"); - QDesktopServices::openUrl(QUrl(newAddress)); - } + if(rsFiles->FileRequest(rslnk.name().toStdString(), rslnk.hash().toStdString(), rslnk.size(), "", RS_FILE_HINTS_NETWORK_WIDE, srcIds)) + { + QMessageBox mb(tr("File Request Confirmation"), tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0); + mb.setButtonText( QMessageBox::Ok, "OK" ); + mb.exec(); + } + else + { + QMessageBox mb(tr("File Request canceled"), tr("The file has not been added to your download list, because you already have it."),QMessageBox::Information,QMessageBox::Ok,0,0); + mb.setButtonText( QMessageBox::Ok, "OK" ); + mb.exec(); + } + } + else + { + QMessageBox mb(tr("File Request Error"), tr("The file link is malformed."),QMessageBox::Information,QMessageBox::Ok,0,0); + mb.setButtonText( QMessageBox::Ok, "OK" ); + mb.exec(); + } + } + else if (link.scheme() == "http") + { + QDesktopServices::openUrl(link); + } + else if (link.scheme() == "") + { + //it's probably a web adress, let's add http:// at the beginning of the link + QString newAddress = link.toString(); + newAddress.prepend("http://"); + QDesktopServices::openUrl(QUrl(newAddress)); + } } bool MessagesDialog::fileSave() @@ -1414,38 +1575,38 @@ void MessagesDialog::loadToolButtonsettings() if(Settings->value("ToolButon_Stlye1","0").toInt() == 0) { - qDebug() << "ToolButon IconOnly"; - ui.newmessageButton->setToolButtonStyle(Qt::ToolButtonIconOnly); - ui.removemessageButton->setToolButtonStyle(Qt::ToolButtonIconOnly); - ui.replymessageButton->setToolButtonStyle(Qt::ToolButtonIconOnly); - ui.replyallmessageButton->setToolButtonStyle(Qt::ToolButtonIconOnly); - ui.forwardmessageButton->setToolButtonStyle(Qt::ToolButtonIconOnly); - ui.printbutton->setToolButtonStyle(Qt::ToolButtonIconOnly); - ui.viewtoolButton->setToolButtonStyle(Qt::ToolButtonIconOnly); + qDebug() << "ToolButon IconOnly"; + ui.newmessageButton->setToolButtonStyle(Qt::ToolButtonIconOnly); + ui.removemessageButton->setToolButtonStyle(Qt::ToolButtonIconOnly); + ui.replymessageButton->setToolButtonStyle(Qt::ToolButtonIconOnly); + ui.replyallmessageButton->setToolButtonStyle(Qt::ToolButtonIconOnly); + ui.forwardmessageButton->setToolButtonStyle(Qt::ToolButtonIconOnly); + ui.printbutton->setToolButtonStyle(Qt::ToolButtonIconOnly); + ui.viewtoolButton->setToolButtonStyle(Qt::ToolButtonIconOnly); } else if (Settings->value("ToolButon_Stlye1","2").toInt() ==2) { - qDebug() << "ToolButon TextBesideIcon"; - ui.newmessageButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - ui.removemessageButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - ui.replymessageButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - ui.replyallmessageButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - ui.forwardmessageButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - ui.printbutton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - ui.viewtoolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + qDebug() << "ToolButon TextBesideIcon"; + ui.newmessageButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + ui.removemessageButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + ui.replymessageButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + ui.replyallmessageButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + ui.forwardmessageButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + ui.printbutton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + ui.viewtoolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); } else if(Settings->value("ToolButon_Stlye1","3").toInt() ==3) { - qDebug() << "ToolButton TextUnderIcon"; - ui.newmessageButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - ui.removemessageButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - ui.replymessageButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - ui.replyallmessageButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - ui.forwardmessageButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - ui.printbutton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - ui.viewtoolButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + qDebug() << "ToolButton TextUnderIcon"; + ui.newmessageButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + ui.removemessageButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + ui.replymessageButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + ui.replyallmessageButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + ui.forwardmessageButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + ui.printbutton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + ui.viewtoolButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); } Settings->endGroup(); @@ -1460,11 +1621,11 @@ void MessagesDialog::filterRegExpChanged() if (text.isEmpty()) { - ui.clearButton->hide(); + ui.clearButton->hide(); } else { - ui.clearButton->show(); + ui.clearButton->show(); } } @@ -1487,96 +1648,128 @@ void MessagesDialog::filterColumnChanged() void MessagesDialog::updateMessageSummaryList() { - unsigned int newInboxCount = 0; - unsigned int newOutboxCount = 0; - unsigned int newDraftCount = 0; - unsigned int newSentboxCount = 0; - unsigned int inboxCount = 0; + unsigned int newInboxCount = 0; + unsigned int newOutboxCount = 0; + unsigned int newDraftCount = 0; + unsigned int newSentboxCount = 0; + unsigned int inboxCount = 0; - /* calculating the new messages */ - rsMsgs->getMessageCount (&inboxCount, &newInboxCount, &newOutboxCount, &newDraftCount, &newSentboxCount); + /* calculating the new messages */ +// rsMsgs->getMessageCount (&inboxCount, &newInboxCount, &newOutboxCount, &newDraftCount, &newSentboxCount); - QString textItem; - /*updating the labels in leftcolumn*/ + std::list msgList; + std::list::const_iterator it; - //QList 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(); - qf.setBold(true); - item->setFont(qf); - item->setIcon(QIcon(":/images/folder-inbox-new.png")); - item->setForeground(QBrush(QColor(49, 106, 197))); - } - else - { - textItem = tr("Inbox"); - item->setText(textItem); - QFont qf = item->font(); - qf.setBold(false); - item->setFont(qf); - item->setIcon(QIcon(":/images/folder-inbox.png")); - item->setForeground(QBrush(QColor(0, 0, 0))); - } - - //QList QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const - item = ui.listWidget->item(1); - if (newOutboxCount != 0) - { - textItem = tr("Outbox") + " " + "(" + QString::number(newOutboxCount)+")"; - item->setText(textItem); - QFont qf = item->font(); - qf.setBold(true); - item->setFont(qf); - } - else - { - textItem = tr("Outbox"); - item->setText(textItem); - QFont qf = item->font(); - qf.setBold(false); - item->setFont(qf); - - } - + rsMsgs->getMessageSummaries(msgList); - //QList 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(); - qf.setBold(true); - item->setFont(qf); - } - else - { - textItem = tr("Draft"); - item->setText(textItem); - QFont qf = item->font(); - qf.setBold(false); - item->setFont(qf); - - } + /*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; + } + } - /* Total Inbox */ - item = ui.listWidget->item(5); - textItem = tr("Total Inbox:") + " " + QString::number(inboxCount); - item->setText(textItem); + QString textItem; + /*updating the labels in leftcolumn*/ - /* Total Sent */ - item = ui.listWidget->item(6); - textItem = tr("Total Sent:") + " " + QString::number(newSentboxCount); - item->setText(textItem); + //QList 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(); + qf.setBold(true); + item->setFont(qf); + item->setIcon(QIcon(":/images/folder-inbox-new.png")); + item->setForeground(QBrush(QColor(49, 106, 197))); + } + else + { + textItem = tr("Inbox"); + item->setText(textItem); + QFont qf = item->font(); + qf.setBold(false); + item->setFont(qf); + item->setIcon(QIcon(":/images/folder-inbox.png")); + item->setForeground(QBrush(QColor(0, 0, 0))); + } + + //QList QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const + item = ui.listWidget->item(1); + if (newOutboxCount != 0) + { + textItem = tr("Outbox") + " " + "(" + QString::number(newOutboxCount)+")"; + item->setText(textItem); + QFont qf = item->font(); + qf.setBold(true); + item->setFont(qf); + } + else + { + textItem = tr("Outbox"); + item->setText(textItem); + QFont qf = item->font(); + qf.setBold(false); + item->setFont(qf); + + } + + //QList 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(); + qf.setBold(true); + item->setFont(qf); + } + else + { + textItem = tr("Draft"); + item->setText(textItem); + QFont qf = item->font(); + qf.setBold(false); + item->setFont(qf); + + } + + /* Total Inbox */ + item = ui.listWidget->item(5); + textItem = tr("Total Inbox:") + " " + QString::number(inboxCount); + item->setText(textItem); + + /* Total Sent */ + item = ui.listWidget->item(6); + textItem = tr("Total Sent:") + " " + QString::number(newSentboxCount); + item->setText(textItem); } /** clear Filter **/ void MessagesDialog::clearFilter() { - ui.filterPatternLineEdit->clear(); - ui.filterPatternLineEdit->setFocus(); + ui.filterPatternLineEdit->clear(); + ui.filterPatternLineEdit->setFocus(); } diff --git a/retroshare-gui/src/gui/MessagesDialog.h b/retroshare-gui/src/gui/MessagesDialog.h index 09105acc7..e00678a98 100644 --- a/retroshare-gui/src/gui/MessagesDialog.h +++ b/retroshare-gui/src/gui/MessagesDialog.h @@ -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 &Rows, bool bRead); void setCurrentFileName(const QString &fileName); - int getSelectedMsgCount (); + int getSelectedMsgCount (QList *pRowsRead, QList *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; diff --git a/retroshare-gui/src/gui/images.qrc b/retroshare-gui/src/gui/images.qrc index 091d69422..dc9892d4d 100644 --- a/retroshare-gui/src/gui/images.qrc +++ b/retroshare-gui/src/gui/images.qrc @@ -270,6 +270,9 @@ images/message-mail-forwarded-read.png images/message-mail-replied.png images/message-mail-forwarded.png + images/message-mail-state-read.png + images/message-mail-state-unread.png + images/message-mail-state-header.png images/message-news.png images/message.png images/messages_new.png diff --git a/retroshare-gui/src/gui/images/message-mail-state-header.png b/retroshare-gui/src/gui/images/message-mail-state-header.png new file mode 100644 index 000000000..df2ab6572 Binary files /dev/null and b/retroshare-gui/src/gui/images/message-mail-state-header.png differ diff --git a/retroshare-gui/src/gui/images/message-mail-state-read.png b/retroshare-gui/src/gui/images/message-mail-state-read.png new file mode 100644 index 000000000..a62a523d6 Binary files /dev/null and b/retroshare-gui/src/gui/images/message-mail-state-read.png differ diff --git a/retroshare-gui/src/gui/images/message-mail-state-unread.png b/retroshare-gui/src/gui/images/message-mail-state-unread.png new file mode 100644 index 000000000..e4fa9c227 Binary files /dev/null and b/retroshare-gui/src/gui/images/message-mail-state-unread.png differ diff --git a/retroshare-gui/src/gui/settings/MessagePage.cpp b/retroshare-gui/src/gui/settings/MessagePage.cpp index 8f99b961c..1817c7d49 100644 --- a/retroshare-gui/src/gui/settings/MessagePage.cpp +++ b/retroshare-gui/src/gui/settings/MessagePage.cpp @@ -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,18 +41,19 @@ MessagePage::closeEvent (QCloseEvent * event) QWidget::closeEvent(event); } - /** Saves the changes on this page */ bool MessagePage::save(QString &errmsg) { - return true; + Settings->setMsgSetToReadOnActivate(ui.setMsgToReadOnActivate->isChecked()); + + return true; } /** Loads the settings for this page */ void MessagePage::load() { - + ui.setMsgToReadOnActivate->setChecked(Settings->getMsgSetToReadOnActivate()); } diff --git a/retroshare-gui/src/gui/settings/MessagePage.ui b/retroshare-gui/src/gui/settings/MessagePage.ui index 7837d7e22..8063fa8eb 100644 --- a/retroshare-gui/src/gui/settings/MessagePage.ui +++ b/retroshare-gui/src/gui/settings/MessagePage.ui @@ -1,506 +1,527 @@ - - MessagePage - - - - 0 - 0 - 398 - 389 - - - - - 0 - 0 - - - - - - - - - 0 - 0 - 0 - - - - - - - 208 - 208 - 208 - - - - - - - 255 - 255 - 255 - - - - - - - 247 - 247 - 247 - - - - - - - 104 - 104 - 104 - - - - - - - 139 - 139 - 139 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 240 - 240 - 240 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 128 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 255 - - - - - - - 255 - 0 - 255 - - - - - - - 231 - 231 - 231 - - - - - - - - - 0 - 0 - 0 - - - - - - - 208 - 208 - 208 - - - - - - - 255 - 255 - 255 - - - - - - - 247 - 247 - 247 - - - - - - - 104 - 104 - 104 - - - - - - - 139 - 139 - 139 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 240 - 240 - 240 - - - - - - - 0 - 0 - 0 - - - - - - - 192 - 192 - 192 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 255 - - - - - - - 255 - 0 - 255 - - - - - - - 231 - 231 - 231 - - - - - - - - - 104 - 104 - 104 - - - - - - - 208 - 208 - 208 - - - - - - - 255 - 255 - 255 - - - - - - - 247 - 247 - 247 - - - - - - - 104 - 104 - 104 - - - - - - - 139 - 139 - 139 - - - - - - - 104 - 104 - 104 - - - - - - - 255 - 255 - 255 - - - - - - - 104 - 104 - 104 - - - - - - - 240 - 240 - 240 - - - - - - - 240 - 240 - 240 - - - - - - - 0 - 0 - 0 - - - - - - - 0 - 0 - 128 - - - - - - - 255 - 255 - 255 - - - - - - - 0 - 0 - 255 - - - - - - - 255 - 0 - 255 - - - - - - - 231 - 231 - 231 - - - - - - - - - Arial - 8 - 50 - false - false - false - false - - - - Qt::NoContextMenu - - - - - - - + + + MessagePage + + + + 0 + 0 + 556 + 389 + + + + + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 208 + 208 + 208 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 104 + 104 + 104 + + + + + + + 139 + 139 + 139 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 128 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 255 + + + + + + + 255 + 0 + 255 + + + + + + + 231 + 231 + 231 + + + + + + + + + 0 + 0 + 0 + + + + + + + 208 + 208 + 208 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 104 + 104 + 104 + + + + + + + 139 + 139 + 139 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 192 + 192 + 192 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 255 + + + + + + + 255 + 0 + 255 + + + + + + + 231 + 231 + 231 + + + + + + + + + 104 + 104 + 104 + + + + + + + 208 + 208 + 208 + + + + + + + 255 + 255 + 255 + + + + + + + 247 + 247 + 247 + + + + + + + 104 + 104 + 104 + + + + + + + 139 + 139 + 139 + + + + + + + 104 + 104 + 104 + + + + + + + 255 + 255 + 255 + + + + + + + 104 + 104 + 104 + + + + + + + 240 + 240 + 240 + + + + + + + 240 + 240 + 240 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 128 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 255 + + + + + + + 255 + 0 + 255 + + + + + + + 231 + 231 + 231 + + + + + + + + + Arial + 8 + 50 + false + false + false + false + + + + Qt::NoContextMenu + + + + + 10 + 10 + 395 + 61 + + + + Misc + + + + + + Set message to read on activate + + + + + + + + + diff --git a/retroshare-gui/src/gui/settings/rsharesettings.cpp b/retroshare-gui/src/gui/settings/rsharesettings.cpp index b610a5143..098cb2701 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.cpp +++ b/retroshare-gui/src/gui/settings/rsharesettings.cpp @@ -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); +} diff --git a/retroshare-gui/src/gui/settings/rsharesettings.h b/retroshare-gui/src/gui/settings/rsharesettings.h index 68694ce90..55d5501b7 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.h +++ b/retroshare-gui/src/gui/settings/rsharesettings.h @@ -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();