2010-05-21 09:54:40 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006, crypton
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include "rshare.h"
|
2010-05-23 13:21:30 -04:00
|
|
|
#include "rsharesettings.h"
|
2010-08-22 18:12:26 -04:00
|
|
|
#include "retroshare/rsmsgs.h"
|
|
|
|
|
2010-09-12 18:17:17 -04:00
|
|
|
#include "MessagePage.h"
|
|
|
|
#include "gui/common/TagDefs.h"
|
2010-08-22 18:12:26 -04:00
|
|
|
#include <algorithm>
|
|
|
|
#include "NewTag.h"
|
2010-05-27 15:48:52 -04:00
|
|
|
|
2013-10-18 17:10:33 -04:00
|
|
|
MessagePage::MessagePage(QWidget * parent, Qt::WindowFlags flags)
|
2010-05-21 09:54:40 -04:00
|
|
|
: ConfigPage(parent, flags)
|
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
2010-05-27 15:48:52 -04:00
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
m_pTags = new MsgTagType;
|
|
|
|
|
2010-05-27 15:48:52 -04:00
|
|
|
connect (ui.addpushButton, SIGNAL(clicked(bool)), this, SLOT (addTag()));
|
|
|
|
connect (ui.editpushButton, SIGNAL(clicked(bool)), this, SLOT (editTag()));
|
|
|
|
connect (ui.deletepushButton, SIGNAL(clicked(bool)), this, SLOT (deleteTag()));
|
2010-06-02 08:11:09 -04:00
|
|
|
connect (ui.defaultTagButton, SIGNAL(clicked(bool)), this, SLOT (defaultTag()));
|
2013-07-31 12:34:34 -04:00
|
|
|
connect (ui.encryptedMsgs_CB, SIGNAL(toggled(bool)), this, SLOT (toggleEnableEncryptedDistantMsgs(bool)));
|
2010-05-27 15:48:52 -04:00
|
|
|
|
|
|
|
connect (ui.tags_listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(currentRowChangedTag(int)));
|
|
|
|
|
|
|
|
ui.editpushButton->setEnabled(false);
|
|
|
|
ui.deletepushButton->setEnabled(false);
|
2011-06-03 20:46:02 -04:00
|
|
|
|
|
|
|
ui.openComboBox->addItem(tr("A new tab"), RshareSettings::MSG_OPEN_TAB);
|
|
|
|
ui.openComboBox->addItem(tr("A new window"), RshareSettings::MSG_OPEN_WINDOW);
|
2013-07-31 12:34:34 -04:00
|
|
|
|
2013-08-04 10:11:59 -04:00
|
|
|
//ui.encryptedMsgs_CB->setEnabled(false) ;
|
2010-05-21 09:54:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MessagePage::~MessagePage()
|
|
|
|
{
|
2010-08-22 18:12:26 -04:00
|
|
|
delete(m_pTags);
|
2010-05-21 09:54:40 -04:00
|
|
|
}
|
|
|
|
|
2013-07-31 12:34:34 -04:00
|
|
|
void MessagePage::toggleEnableEncryptedDistantMsgs(bool b)
|
|
|
|
{
|
|
|
|
rsMsgs->enableDistantMessaging(b) ;
|
|
|
|
}
|
|
|
|
|
2010-05-21 09:54:40 -04:00
|
|
|
/** Saves the changes on this page */
|
|
|
|
bool
|
2011-08-12 10:06:29 -04:00
|
|
|
MessagePage::save(QString &/*errmsg*/)
|
2010-05-21 09:54:40 -04:00
|
|
|
{
|
2010-05-23 13:21:30 -04:00
|
|
|
Settings->setMsgSetToReadOnActivate(ui.setMsgToReadOnActivate->isChecked());
|
2013-09-23 15:53:26 -04:00
|
|
|
Settings->setMsgLoadEmbeddedImages(ui.loadEmbeddedImages->isChecked());
|
2011-06-03 20:46:02 -04:00
|
|
|
Settings->setMsgOpen((RshareSettings::enumMsgOpen) ui.openComboBox->itemData(ui.openComboBox->currentIndex()).toInt());
|
2010-05-23 13:21:30 -04:00
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
std::map<uint32_t, std::pair<std::string, uint32_t> >::iterator Tag;
|
|
|
|
for (Tag = m_pTags->types.begin(); Tag != m_pTags->types.end(); Tag++) {
|
|
|
|
// check for changed tags
|
|
|
|
std::list<uint32_t>::iterator changedTagId;
|
|
|
|
for (changedTagId = m_changedTagIds.begin(); changedTagId != m_changedTagIds.end(); changedTagId++) {
|
|
|
|
if (*changedTagId == Tag->first) {
|
|
|
|
if (Tag->second.first.empty()) {
|
|
|
|
// delete tag
|
|
|
|
rsMsgs->removeMessageTagType(Tag->first);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
rsMsgs->setMessageTagType(Tag->first, Tag->second.first, Tag->second.second);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-05-27 15:48:52 -04:00
|
|
|
}
|
|
|
|
|
2010-05-23 13:21:30 -04:00
|
|
|
return true;
|
2010-05-21 09:54:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Loads the settings for this page */
|
|
|
|
void
|
|
|
|
MessagePage::load()
|
|
|
|
{
|
2010-05-23 13:21:30 -04:00
|
|
|
ui.setMsgToReadOnActivate->setChecked(Settings->getMsgSetToReadOnActivate());
|
2013-09-23 15:53:26 -04:00
|
|
|
ui.loadEmbeddedImages->setChecked(Settings->getMsgLoadEmbeddedImages());
|
2011-06-03 20:46:02 -04:00
|
|
|
ui.openComboBox->setCurrentIndex(ui.openComboBox->findData(Settings->getMsgOpen()));
|
2010-05-27 15:48:52 -04:00
|
|
|
|
2013-07-31 12:34:34 -04:00
|
|
|
ui.encryptedMsgs_CB->setChecked(rsMsgs->distantMessagingEnabled()) ;
|
2010-08-22 18:12:26 -04:00
|
|
|
// fill items
|
|
|
|
rsMsgs->getMessageTagTypes(*m_pTags);
|
|
|
|
fillTags();
|
2010-05-27 15:48:52 -04:00
|
|
|
}
|
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
// fill tags
|
|
|
|
void MessagePage::fillTags()
|
2010-06-02 08:11:09 -04:00
|
|
|
{
|
|
|
|
ui.tags_listWidget->clear();
|
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
std::map<uint32_t, std::pair<std::string, uint32_t> >::iterator Tag;
|
|
|
|
for (Tag = m_pTags->types.begin(); Tag != m_pTags->types.end(); Tag++) {
|
2010-09-12 18:17:17 -04:00
|
|
|
QString text = TagDefs::name(Tag->first, Tag->second.first);
|
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
QListWidgetItem *pItemWidget = new QListWidgetItem(text, ui.tags_listWidget);
|
|
|
|
pItemWidget->setTextColor(QColor(Tag->second.second));
|
|
|
|
pItemWidget->setData(Qt::UserRole, Tag->first);
|
2010-06-02 08:11:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-27 15:48:52 -04:00
|
|
|
void MessagePage::addTag()
|
|
|
|
{
|
2010-08-22 18:12:26 -04:00
|
|
|
NewTag TagDlg(*m_pTags);
|
|
|
|
if (TagDlg.exec() == QDialog::Accepted && TagDlg.m_nId) {
|
|
|
|
std::map<uint32_t, std::pair<std::string, uint32_t> >::iterator Tag;
|
|
|
|
Tag = m_pTags->types.find(TagDlg.m_nId);
|
|
|
|
if (Tag != m_pTags->types.end()) {
|
2010-09-12 18:17:17 -04:00
|
|
|
QString text = TagDefs::name(Tag->first, Tag->second.first);
|
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
QListWidgetItem *pItemWidget = new QListWidgetItem(text, ui.tags_listWidget);
|
|
|
|
pItemWidget->setTextColor(QColor(Tag->second.second));
|
|
|
|
pItemWidget->setData(Qt::UserRole, TagDlg.m_nId);
|
|
|
|
|
|
|
|
m_changedTagIds.push_back(TagDlg.m_nId);
|
|
|
|
}
|
2010-05-27 15:48:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessagePage::editTag()
|
|
|
|
{
|
|
|
|
QListWidgetItem *pItemWidget = ui.tags_listWidget->currentItem();
|
|
|
|
if (pItemWidget == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
uint32_t nId = pItemWidget->data(Qt::UserRole).toInt();
|
2010-05-27 15:48:52 -04:00
|
|
|
if (nId == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
NewTag TagDlg(*m_pTags, nId);
|
|
|
|
TagDlg.setWindowTitle(tr("Edit Tag"));
|
|
|
|
if (TagDlg.exec() == QDialog::Accepted && TagDlg.m_nId) {
|
|
|
|
std::map<uint32_t, std::pair<std::string, uint32_t> >::iterator Tag;
|
|
|
|
Tag = m_pTags->types.find(TagDlg.m_nId);
|
|
|
|
if (Tag != m_pTags->types.end()) {
|
|
|
|
if (Tag->first >= RS_MSGTAGTYPE_USER) {
|
|
|
|
pItemWidget->setText(QString::fromStdString(Tag->second.first));
|
|
|
|
}
|
|
|
|
pItemWidget->setTextColor(QColor(Tag->second.second));
|
|
|
|
|
|
|
|
if (std::find(m_changedTagIds.begin(), m_changedTagIds.end(), TagDlg.m_nId) == m_changedTagIds.end()) {
|
|
|
|
m_changedTagIds.push_back(TagDlg.m_nId);
|
|
|
|
}
|
|
|
|
}
|
2010-05-27 15:48:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessagePage::deleteTag()
|
|
|
|
{
|
|
|
|
QListWidgetItem *pItemWidget = ui.tags_listWidget->currentItem();
|
|
|
|
if (pItemWidget == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
uint32_t nId = pItemWidget->data(Qt::UserRole).toInt();
|
2010-05-27 15:48:52 -04:00
|
|
|
if (nId == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
if (nId < RS_MSGTAGTYPE_USER) {
|
|
|
|
// can't delete standard tag item
|
2010-05-27 15:48:52 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
std::map<uint32_t, std::pair<std::string, uint32_t> >::iterator Tag;
|
|
|
|
Tag = m_pTags->types.find(nId);
|
|
|
|
if (Tag != m_pTags->types.end()) {
|
|
|
|
// erase the text for later delete
|
|
|
|
Tag->second.first.erase();
|
|
|
|
}
|
2010-05-27 15:48:52 -04:00
|
|
|
|
|
|
|
ui.tags_listWidget->removeItemWidget(pItemWidget);
|
|
|
|
delete (pItemWidget);
|
2010-08-22 18:12:26 -04:00
|
|
|
|
|
|
|
if (std::find(m_changedTagIds.begin(), m_changedTagIds.end(), nId) == m_changedTagIds.end()) {
|
|
|
|
m_changedTagIds.push_back(nId);
|
|
|
|
}
|
2010-05-21 09:54:40 -04:00
|
|
|
}
|
|
|
|
|
2010-06-02 08:11:09 -04:00
|
|
|
void MessagePage::defaultTag()
|
|
|
|
{
|
2010-08-22 18:12:26 -04:00
|
|
|
rsMsgs->resetMessageStandardTagTypes(*m_pTags);
|
|
|
|
|
|
|
|
// add all standard items to changed list
|
|
|
|
std::map<uint32_t, std::pair<std::string, uint32_t> >::iterator Tag;
|
|
|
|
for (Tag = m_pTags->types.begin(); Tag != m_pTags->types.end(); Tag++) {
|
|
|
|
if (Tag->first < RS_MSGTAGTYPE_USER) {
|
|
|
|
if (std::find(m_changedTagIds.begin(), m_changedTagIds.end(), Tag->first) == m_changedTagIds.end()) {
|
|
|
|
m_changedTagIds.push_back(Tag->first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fillTags();
|
2010-06-02 08:11:09 -04:00
|
|
|
}
|
|
|
|
|
2010-05-27 15:48:52 -04:00
|
|
|
void MessagePage::currentRowChangedTag(int row)
|
|
|
|
{
|
|
|
|
QListWidgetItem *pItemWidget = ui.tags_listWidget->item(row);
|
|
|
|
|
|
|
|
bool bEditEnable = false;
|
|
|
|
bool bDeleteEnable = false;
|
|
|
|
|
|
|
|
if (pItemWidget) {
|
|
|
|
bEditEnable = true;
|
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
uint32_t nId = pItemWidget->data(Qt::UserRole).toInt();
|
2010-05-27 15:48:52 -04:00
|
|
|
|
2010-08-22 18:12:26 -04:00
|
|
|
if (nId >= RS_MSGTAGTYPE_USER) {
|
2010-05-27 15:48:52 -04:00
|
|
|
bDeleteEnable = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.editpushButton->setEnabled(bEditEnable);
|
|
|
|
ui.deletepushButton->setEnabled(bDeleteEnable);
|
|
|
|
}
|