CreateForumMsg:

- removed memory leak in context menu
- cleaned includes

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3295 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-07-17 12:40:19 +00:00
parent 0ab77d8a40
commit de57423733
2 changed files with 122 additions and 136 deletions

View File

@ -15,169 +15,166 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * 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. * Boston, MA 02110-1301, USA.
****************************************************************/ ****************************************************************/
#include "CreateForumMsg.h" #include "CreateForumMsg.h"
#include <gui/settings/rsharesettings.h> #include <QMenu>
#include <QMessageBox>
#include <QFile>
#include <QFileDialog>
#include <QDesktopWidget>
#include <QDropEvent>
#include <gui/RetroShareLink.h>
#include <QtGui>
#include "rsiface/rsforums.h" #include "rsiface/rsforums.h"
#include "rsiface/rsfiles.h" #include "rsiface/rsfiles.h"
#include <sys/stat.h> #include "gui/settings/rsharesettings.h"
#include "gui/RetroShareLink.h"
#include "gui/feeds/AttachFileItem.h" #include "gui/feeds/AttachFileItem.h"
#include <sstream> #include <sys/stat.h>
/** Constructor */ /** Constructor */
CreateForumMsg::CreateForumMsg(std::string fId, std::string pId) CreateForumMsg::CreateForumMsg(std::string fId, std::string pId)
: QMainWindow(NULL), mForumId(fId), mParentId(pId) : QMainWindow(NULL), mForumId(fId), mParentId(pId)
{ {
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this); ui.setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, true); setAttribute(Qt::WA_DeleteOnClose, true);
Settings->loadWidgetInformation(this); Settings->loadWidgetInformation(this);
connect( ui.forumMessage, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( forumMessageCostumPopupMenu( QPoint ) ) );
// connect up the buttons.
connect( ui.postmessage_action, SIGNAL( triggered (bool) ), this, SLOT( createMsg( ) ) );
connect( ui.close_action, SIGNAL( triggered (bool) ), this, SLOT( cancelMsg( ) ) );
connect( ui.emoticonButton, SIGNAL(clicked()), this, SLOT(smileyWidgetForums()));
connect( ui.attachFileButton, SIGNAL(clicked() ), this , SLOT(addFile()));
connect( ui.pastersButton, SIGNAL(clicked() ), this , SLOT(pasteLink()));
newMsg(); connect( ui.forumMessage, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( forumMessageCostumPopupMenu( QPoint ) ) );
loadEmoticonsForums();
// connect up the buttons.
connect( ui.postmessage_action, SIGNAL( triggered (bool) ), this, SLOT( createMsg( ) ) );
connect( ui.close_action, SIGNAL( triggered (bool) ), this, SLOT( cancelMsg( ) ) );
connect( ui.emoticonButton, SIGNAL(clicked()), this, SLOT(smileyWidgetForums()));
connect( ui.attachFileButton, SIGNAL(clicked() ), this , SLOT(addFile()));
connect( ui.pastersButton, SIGNAL(clicked() ), this , SLOT(pasteLink()));
newMsg();
loadEmoticonsForums();
} }
/** context menu searchTablewidget2 **/ /** context menu searchTablewidget2 **/
void CreateForumMsg::forumMessageCostumPopupMenu( QPoint point ) void CreateForumMsg::forumMessageCostumPopupMenu( QPoint point )
{ {
QMenu contextMnu (this);
if(RSLinkClipboard::empty()) QAction *pasteLinkAct = new QAction(QIcon(":/images/pasterslink.png"), tr( "Paste retroshare Link" ), &contextMnu );
return ; QAction *pasteLinkFullAct = new QAction(QIcon(":/images/pasterslink.png"), tr( "Paste retroshare Link Full" ), &contextMnu );
contextMnu = new QMenu( this ); if (RSLinkClipboard::empty()) {
pasteLinkAct->setDisabled (true);
pasteLinkFullAct->setDisabled (true);
} else {
connect(pasteLinkAct , SIGNAL(triggered()), this, SLOT(pasteLink()));
connect(pasteLinkFullAct , SIGNAL(triggered()), this, SLOT(pasteLinkFull()));
}
pasteLinkAct = new QAction(QIcon(":/images/pasterslink.png"), tr( "Paste retroshare Link" ), this ); contextMnu.addAction(pasteLinkAct);
connect( pasteLinkAct , SIGNAL( triggered() ), this, SLOT( pasteLink() ) ); contextMnu.addAction(pasteLinkFullAct);
pasteLinkFullAct = new QAction(QIcon(":/images/pasterslink.png"), tr( "Paste retroshare Link Full" ), this ); contextMnu.exec(QCursor::pos());
connect( pasteLinkFullAct , SIGNAL( triggered() ), this, SLOT( pasteLinkFull() ) );
contextMnu->clear();
contextMnu->addAction( pasteLinkAct);
contextMnu->addAction( pasteLinkFullAct);
contextMnu->exec(QCursor::pos());
} }
void CreateForumMsg::newMsg() void CreateForumMsg::newMsg()
{ {
/* clear all */ /* clear all */
ForumInfo fi; ForumInfo fi;
if (rsForums->getForumInfo(mForumId, fi)) if (rsForums->getForumInfo(mForumId, fi))
{ {
ForumMsgInfo msg; ForumMsgInfo msg;
QString name = QString::fromStdWString(fi.forumName); QString name = QString::fromStdWString(fi.forumName);
QString subj; QString subj;
if ((mParentId != "") && (rsForums->getForumMessage( if ((mParentId != "") && (rsForums->getForumMessage(mForumId, mParentId, msg)))
mForumId, mParentId, msg))) {
{ name += " In Reply to: ";
name += " In Reply to: "; name += QString::fromStdWString(msg.title);
name += QString::fromStdWString(msg.title);
QString text = QString::fromStdWString(msg.title);
if (text.startsWith("Re:", Qt::CaseInsensitive))
{
subj = QString::fromStdWString(msg.title);
}
else
{
subj = "Re: " + QString::fromStdWString(msg.title);
}
}
ui.forumName->setText(name); QString text = QString::fromStdWString(msg.title);
ui.forumSubject->setText(subj);
if (text.startsWith("Re:", Qt::CaseInsensitive))
if (!ui.forumSubject->text().isEmpty()) {
{ subj = QString::fromStdWString(msg.title);
ui.forumMessage->setFocus(); }
else
{
subj = "Re: " + QString::fromStdWString(msg.title);
}
}
ui.forumName->setText(name);
ui.forumSubject->setText(subj);
if (!ui.forumSubject->text().isEmpty())
{
ui.forumMessage->setFocus();
}
else
{
ui.forumSubject->setFocus();
}
if (fi.forumFlags & RS_DISTRIB_AUTHEN_REQ)
{
ui.signBox->setChecked(true);
ui.signBox->setEnabled(false);
}
else
{
ui.signBox->setEnabled(true);
}
} }
else
{
ui.forumSubject->setFocus();
}
if (fi.forumFlags & RS_DISTRIB_AUTHEN_REQ) ui.forumMessage->setText("");
{
ui.signBox->setChecked(true);
ui.signBox->setEnabled(false);
}
else
{
ui.signBox->setEnabled(true);
}
}
ui.forumMessage->setText("");
} }
void CreateForumMsg::createMsg() void CreateForumMsg::createMsg()
{ {
QString name = ui.forumSubject->text(); QString name = ui.forumSubject->text();
QString desc = ui.forumMessage->toHtml(); QString desc = ui.forumMessage->toHtml();
if(name.isEmpty())
{ /* error message */
QMessageBox::warning(this, tr("RetroShare"),tr("Please set a Forum Subject and Forum Message"),
QMessageBox::Ok, QMessageBox::Ok);
return; //Don't add a empty Subject!!
}
if(name.isEmpty())
{ /* error message */
QMessageBox::warning(this, tr("RetroShare"),tr("Please set a Forum Subject and Forum Message"),
QMessageBox::Ok, QMessageBox::Ok);
ForumMsgInfo msgInfo; return; //Don't add a empty Subject!!
}
msgInfo.forumId = mForumId; ForumMsgInfo msgInfo;
msgInfo.threadId = "";
msgInfo.parentId = mParentId;
msgInfo.msgId = "";
msgInfo.title = name.toStdWString(); msgInfo.forumId = mForumId;
msgInfo.msg = desc.toStdWString(); msgInfo.threadId = "";
msgInfo.msgflags = 0; msgInfo.parentId = mParentId;
msgInfo.msgId = "";
if (ui.signBox->isChecked()) msgInfo.title = name.toStdWString();
{ msgInfo.msg = desc.toStdWString();
msgInfo.msgflags = RS_DISTRIB_AUTHEN_REQ; msgInfo.msgflags = 0;
}
if (ui.signBox->isChecked())
{
msgInfo.msgflags = RS_DISTRIB_AUTHEN_REQ;
}
if ((msgInfo.msg == L"") && (msgInfo.title == L"")) if ((msgInfo.msg == L"") && (msgInfo.title == L""))
return; /* do nothing */ return; /* do nothing */
rsForums->ForumMessageSend(msgInfo); rsForums->ForumMessageSend(msgInfo);
close(); close();
} }
void CreateForumMsg::closeEvent (QCloseEvent * event) void CreateForumMsg::closeEvent (QCloseEvent * event)
@ -187,7 +184,7 @@ void CreateForumMsg::closeEvent (QCloseEvent * event)
void CreateForumMsg::cancelMsg() void CreateForumMsg::cancelMsg()
{ {
close(); close();
} }
void CreateForumMsg::loadEmoticonsForums() void CreateForumMsg::loadEmoticonsForums()
@ -344,7 +341,7 @@ void CreateForumMsg::addAttachment(std::string filePath) {
/* add widget in for new destination */ /* add widget in for new destination */
AttachFileItem *file = new AttachFileItem(filePath); AttachFileItem *file = new AttachFileItem(filePath);
//file-> //file->
ui.verticalLayout->addWidget(file, 1, 0); ui.verticalLayout->addWidget(file, 1, 0);
//when the file is local or is finished hashing, call the fileHashingFinished method to send a forum message //when the file is local or is finished hashing, call the fileHashingFinished method to send a forum message
@ -372,14 +369,14 @@ void CreateForumMsg::fileHashingFinished(AttachFileItem* file) {
sprintf(fileSizeChar, "%llu", (unsigned long long int)file->FileSize()); sprintf(fileSizeChar, "%llu", (unsigned long long int)file->FileSize());
std::string fileSize = *(&fileSizeChar); std::string fileSize = *(&fileSizeChar);
std::string mesgString = "<a href='retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "'>" std::string mesgString = "<a href='retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "'>"
+ "retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "</a>" + "<br>"; + "retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "</a>" + "<br>";
#ifdef CHAT_DEBUG #ifdef CHAT_DEBUG
std::cerr << "CreateForumMsg::anchorClicked mesgString : " << mesgString << std::endl; std::cerr << "CreateForumMsg::anchorClicked mesgString : " << mesgString << std::endl;
#endif #endif
ui.forumMessage->textCursor().insertHtml(QString::fromStdString(mesgString)); ui.forumMessage->textCursor().insertHtml(QString::fromStdString(mesgString));
ui.forumMessage->setFocus( Qt::OtherFocusReason ); ui.forumMessage->setFocus( Qt::OtherFocusReason );
} }

View File

@ -15,7 +15,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * 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. * Boston, MA 02110-1301, USA.
****************************************************************/ ****************************************************************/
@ -23,14 +23,10 @@
#ifndef _CREATE_FORUM_MSG_DIALOG_H #ifndef _CREATE_FORUM_MSG_DIALOG_H
#define _CREATE_FORUM_MSG_DIALOG_H #define _CREATE_FORUM_MSG_DIALOG_H
#include <QtGui>
#include <QWidget>
#include <string>
#include "gui/feeds/AttachFileItem.h"
#include "ui_CreateForumMsg.h" #include "ui_CreateForumMsg.h"
class AttachFileItem;
class CreateForumMsg : public QMainWindow class CreateForumMsg : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
@ -39,9 +35,9 @@ public:
CreateForumMsg(std::string fId, std::string pId); CreateForumMsg(std::string fId, std::string pId);
void newMsg(); /* cleanup */ void newMsg(); /* cleanup */
void loadEmoticonsForums(); void loadEmoticonsForums();
private slots: private slots:
/** Create the context popup menu and it's submenus */ /** Create the context popup menu and it's submenus */
void forumMessageCostumPopupMenu( QPoint point ); void forumMessageCostumPopupMenu( QPoint point );
@ -54,27 +50,20 @@ private slots:
void pasteLinkFull(); void pasteLinkFull();
void smileyWidgetForums(); void smileyWidgetForums();
void addSmileys(); void addSmileys();
void addFile(); void addFile();
void addAttachment(std::string); void addAttachment(std::string);
protected: protected:
void closeEvent (QCloseEvent * event); void closeEvent (QCloseEvent * event);
virtual void dragEnterEvent(QDragEnterEvent *event); virtual void dragEnterEvent(QDragEnterEvent *event);
virtual void dropEvent(QDropEvent *event); virtual void dropEvent(QDropEvent *event);
private:
/** Define the popup menus for the Context menu */
QMenu* contextMnu;
/** Defines the actions for the context menu */
QAction* pasteLinkAct;
QAction* pasteLinkFullAct;
private:
std::string mForumId; std::string mForumId;
std::string mParentId; std::string mParentId;
QHash<QString, QString> smileys; QHash<QString, QString> smileys;
/** Qt Designer generated object */ /** Qt Designer generated object */