2007-11-14 22:18:48 -05:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
2007-11-18 18:35:53 -05:00
|
|
|
* Copyright (C) 2006,2007 RetroShare Team
|
2007-11-14 22:18:48 -05:00
|
|
|
*
|
|
|
|
* 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.
|
2008-11-25 20:19:09 -05:00
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include "rshare.h"
|
|
|
|
#include "ChanMsgDialog.h"
|
|
|
|
|
2008-01-25 03:49:40 -05:00
|
|
|
#include "rsiface/rsiface.h"
|
|
|
|
#include "rsiface/rspeers.h"
|
2008-02-04 12:55:59 -05:00
|
|
|
#include "rsiface/rsmsgs.h"
|
2008-01-25 03:49:40 -05:00
|
|
|
|
2009-12-14 12:13:10 -05:00
|
|
|
#include <gui/settings/rsharesettings.h>
|
2009-07-10 19:48:20 -04:00
|
|
|
#include "util/misc.h"
|
2008-03-24 21:41:01 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include <QContextMenuEvent>
|
2008-03-24 21:41:01 -04:00
|
|
|
#include <QCloseEvent>
|
2008-03-24 13:36:17 -04:00
|
|
|
#include <QColorDialog>
|
2008-03-24 21:41:01 -04:00
|
|
|
#include <QClipboard>
|
2008-11-25 20:19:09 -05:00
|
|
|
#include <QFile>
|
|
|
|
#include <QFileDialog>
|
2008-03-24 21:41:01 -04:00
|
|
|
#include <QFileInfo>
|
2007-11-14 22:18:48 -05:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QCursor>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QMouseEvent>
|
2008-03-24 21:41:01 -04:00
|
|
|
#include <QMessageBox>
|
2007-11-14 22:18:48 -05:00
|
|
|
#include <QPixmap>
|
2008-11-25 20:19:09 -05:00
|
|
|
#include <QPrintDialog>
|
2008-03-24 21:41:01 -04:00
|
|
|
#include <QPrinter>
|
2007-11-17 21:24:03 -05:00
|
|
|
#include <QHeaderView>
|
2008-11-25 20:19:09 -05:00
|
|
|
#include <QTextCodec>
|
|
|
|
#include <QTextEdit>
|
|
|
|
#include <QTextCursor>
|
2008-03-24 13:36:17 -04:00
|
|
|
#include <QTextList>
|
2008-03-24 21:41:01 -04:00
|
|
|
#include <QTextStream>
|
2008-03-25 08:28:13 -04:00
|
|
|
#include <QTextDocumentFragment>
|
2007-11-17 21:24:03 -05:00
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
|
|
|
|
/** Constructor */
|
|
|
|
ChanMsgDialog::ChanMsgDialog(bool msg, QWidget *parent, Qt::WFlags flags)
|
|
|
|
: mIsMsg(msg), QMainWindow(parent, flags)
|
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
2007-11-14 22:18:48 -05:00
|
|
|
ui.setupUi(this);
|
2009-07-10 19:48:20 -04:00
|
|
|
|
2008-03-24 21:41:01 -04:00
|
|
|
setupFileActions();
|
|
|
|
setupEditActions();
|
2008-03-26 15:30:34 -04:00
|
|
|
setupViewActions();
|
|
|
|
setupInsertActions();
|
2008-03-24 21:41:01 -04:00
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
RshareSettings config;
|
2007-11-18 18:35:53 -05:00
|
|
|
config.loadWidgetInformation(this);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
setAttribute ( Qt::WA_DeleteOnClose, true );
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
//connect( ui.channelstreeView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( channelstreeViewCostumPopupMenu( QPoint ) ) );
|
2007-11-14 22:18:48 -05:00
|
|
|
//
|
|
|
|
|
|
|
|
// connect up the buttons.
|
|
|
|
connect( ui.actionSend, SIGNAL( triggered (bool)), this, SLOT( sendMessage( ) ) );
|
|
|
|
//connect( ui.actionReply, SIGNAL( triggered (bool)), this, SLOT( replyMessage( ) ) );
|
2008-03-24 13:36:17 -04:00
|
|
|
connect(ui.boldbtn, SIGNAL(clicked()), this, SLOT(textBold()));
|
|
|
|
connect(ui.underlinebtn, SIGNAL(clicked()), this, SLOT(textUnderline()));
|
|
|
|
connect(ui.italicbtn, SIGNAL(clicked()), this, SLOT(textItalic()));
|
|
|
|
connect(ui.colorbtn, SIGNAL(clicked()), this, SLOT(textColor()));
|
2008-03-25 08:28:13 -04:00
|
|
|
connect(ui.imagebtn, SIGNAL(clicked()), this, SLOT(addImage()));
|
2008-03-26 15:30:34 -04:00
|
|
|
//connect(ui.linkbtn, SIGNAL(clicked()), this, SLOT(insertLink()));
|
2008-03-24 13:36:17 -04:00
|
|
|
connect(ui.actionContactsView, SIGNAL(triggered()), this, SLOT(toggleContacts()));
|
2008-03-24 21:41:01 -04:00
|
|
|
connect(ui.actionSaveas, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
|
2008-03-24 13:36:17 -04:00
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
connect(ui.msgText, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)),
|
|
|
|
this, SLOT(currentCharFormatChanged(const QTextCharFormat &)));
|
|
|
|
connect(ui.msgText, SIGNAL(cursorPositionChanged()),
|
2008-03-24 13:36:17 -04:00
|
|
|
this, SLOT(cursorPositionChanged()));
|
2008-03-24 21:41:01 -04:00
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
connect(ui.msgText->document(), SIGNAL(modificationChanged(bool)),
|
|
|
|
actionSave, SLOT(setEnabled(bool)));
|
|
|
|
connect(ui.msgText->document(), SIGNAL(modificationChanged(bool)),
|
|
|
|
this, SLOT(setWindowModified(bool)));
|
|
|
|
connect(ui.msgText->document(), SIGNAL(undoAvailable(bool)),
|
|
|
|
actionUndo, SLOT(setEnabled(bool)));
|
|
|
|
connect(ui.msgText->document(), SIGNAL(redoAvailable(bool)),
|
|
|
|
actionRedo, SLOT(setEnabled(bool)));
|
|
|
|
|
|
|
|
setWindowModified(ui.msgText->document()->isModified());
|
|
|
|
actionSave->setEnabled(ui.msgText->document()->isModified());
|
|
|
|
actionUndo->setEnabled(ui.msgText->document()->isUndoAvailable());
|
|
|
|
actionRedo->setEnabled(ui.msgText->document()->isRedoAvailable());
|
|
|
|
|
|
|
|
connect(actionUndo, SIGNAL(triggered()), ui.msgText, SLOT(undo()));
|
|
|
|
connect(actionRedo, SIGNAL(triggered()), ui.msgText, SLOT(redo()));
|
|
|
|
|
|
|
|
actionCut->setEnabled(false);
|
|
|
|
actionCopy->setEnabled(false);
|
|
|
|
|
|
|
|
connect(actionCut, SIGNAL(triggered()), ui.msgText, SLOT(cut()));
|
|
|
|
connect(actionCopy, SIGNAL(triggered()), ui.msgText, SLOT(copy()));
|
|
|
|
connect(actionPaste, SIGNAL(triggered()), ui.msgText, SLOT(paste()));
|
|
|
|
|
|
|
|
connect(ui.msgText, SIGNAL(copyAvailable(bool)), actionCut, SLOT(setEnabled(bool)));
|
|
|
|
connect(ui.msgText, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool)));
|
|
|
|
|
2008-03-24 21:41:01 -04:00
|
|
|
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* if Msg */
|
|
|
|
if (mIsMsg)
|
|
|
|
{
|
|
|
|
connect(ui.msgSendList, SIGNAL(itemChanged( QTreeWidgetItem *, int ) ),
|
|
|
|
this, SLOT(togglePersonItem( QTreeWidgetItem *, int ) ));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
connect(ui.msgSendList, SIGNAL(itemChanged( QTreeWidgetItem *, int ) ),
|
|
|
|
this, SLOT(toggleChannelItem( QTreeWidgetItem *, int ) ));
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(ui.msgFileList, SIGNAL(itemChanged( QTreeWidgetItem *, int ) ),
|
|
|
|
this, SLOT(toggleRecommendItem( QTreeWidgetItem *, int ) ));
|
|
|
|
|
|
|
|
/* hide the Tree +/- */
|
|
|
|
ui.msgSendList -> setRootIsDecorated( false );
|
2007-11-17 21:24:03 -05:00
|
|
|
ui.msgFileList -> setRootIsDecorated( false );
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
/* to hide the header */
|
2007-11-17 21:24:03 -05:00
|
|
|
//ui.msgSendList->header()->hide();
|
2008-03-24 13:36:17 -04:00
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
QActionGroup *grp = new QActionGroup(this);
|
|
|
|
connect(grp, SIGNAL(triggered(QAction *)), this, SLOT(textAlign(QAction *)));
|
|
|
|
|
|
|
|
actionAlignLeft = new QAction(QIcon(":/images/textedit/textleft.png"), tr("&Left"), grp);
|
|
|
|
actionAlignLeft->setShortcut(Qt::CTRL + Qt::Key_L);
|
|
|
|
actionAlignLeft->setCheckable(true);
|
|
|
|
actionAlignCenter = new QAction(QIcon(":/images/textedit/textcenter.png"), tr("C&enter"), grp);
|
|
|
|
actionAlignCenter->setShortcut(Qt::CTRL + Qt::Key_E);
|
|
|
|
actionAlignCenter->setCheckable(true);
|
|
|
|
actionAlignRight = new QAction(QIcon(":/images/textedit/textright.png"), tr("&Right"), grp);
|
|
|
|
actionAlignRight->setShortcut(Qt::CTRL + Qt::Key_R);
|
|
|
|
actionAlignRight->setCheckable(true);
|
|
|
|
actionAlignJustify = new QAction(QIcon(":/images/textedit/textjustify.png"), tr("&Justify"), grp);
|
|
|
|
actionAlignJustify->setShortcut(Qt::CTRL + Qt::Key_J);
|
2008-03-24 13:36:17 -04:00
|
|
|
actionAlignJustify->setCheckable(true);
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
ui.comboStyle->addItem("Standard");
|
|
|
|
ui.comboStyle->addItem("Bullet List (Disc)");
|
|
|
|
ui.comboStyle->addItem("Bullet List (Circle)");
|
|
|
|
ui.comboStyle->addItem("Bullet List (Square)");
|
|
|
|
ui.comboStyle->addItem("Ordered List (Decimal)");
|
|
|
|
ui.comboStyle->addItem("Ordered List (Alpha lower)");
|
|
|
|
ui.comboStyle->addItem("Ordered List (Alpha upper)");
|
2008-03-24 13:36:17 -04:00
|
|
|
connect(ui.comboStyle, SIGNAL(activated(int)),this, SLOT(textStyle(int)));
|
|
|
|
|
|
|
|
connect(ui.comboFont, SIGNAL(activated(const QString &)), this, SLOT(textFamily(const QString &)));
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
ui.comboSize->setEditable(true);
|
|
|
|
|
|
|
|
QFontDatabase db;
|
|
|
|
foreach(int size, db.standardSizes())
|
|
|
|
ui.comboSize->addItem(QString::number(size));
|
|
|
|
|
|
|
|
connect(ui.comboSize, SIGNAL(activated(const QString &)),this, SLOT(textSize(const QString &)));
|
2008-03-24 13:36:17 -04:00
|
|
|
ui.comboSize->setCurrentIndex(ui.comboSize->findText(QString::number(QApplication::font().pointSize())));
|
|
|
|
|
|
|
|
ui.boldbtn->setIcon(QIcon(QString(":/images/textedit/textbold.png")));
|
2008-07-31 06:34:14 -04:00
|
|
|
ui.underlinebtn->setIcon(QIcon(QString(":/images/textedit/textunder.png")));
|
|
|
|
ui.italicbtn->setIcon(QIcon(QString(":/images/textedit/textitalic.png")));
|
2008-03-24 13:36:17 -04:00
|
|
|
ui.textalignmentbtn->setIcon(QIcon(QString(":/images/textedit/textcenter.png")));
|
2008-03-25 08:28:13 -04:00
|
|
|
ui.imagebtn->setIcon(QIcon(QString(":/images/lphoto24.png")));
|
2008-03-24 13:36:17 -04:00
|
|
|
ui.actionContactsView->setIcon(QIcon(":/images/contacts24.png"));
|
2008-03-24 21:41:01 -04:00
|
|
|
ui.actionSaveas->setIcon(QIcon(":/images/save24.png"));
|
|
|
|
|
|
|
|
/* ToolTips */
|
|
|
|
ui.actionSend->setStatusTip(tr("Send this message now"));
|
|
|
|
ui.actionContactsView->setStatusTip(tr("Toggle Contacts View"));
|
|
|
|
ui.actionSaveas->setStatusTip(tr("Save this message"));
|
|
|
|
|
2008-03-24 13:36:17 -04:00
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
QMenu * alignmentmenu = new QMenu();
|
|
|
|
alignmentmenu->addAction(actionAlignLeft);
|
|
|
|
alignmentmenu->addAction(actionAlignCenter);
|
|
|
|
alignmentmenu->addAction(actionAlignRight);
|
|
|
|
alignmentmenu->addAction(actionAlignJustify);
|
2008-03-24 13:36:17 -04:00
|
|
|
ui.textalignmentbtn->setMenu(alignmentmenu);
|
|
|
|
|
2009-07-10 19:48:20 -04:00
|
|
|
QPixmap pxm(24,24);
|
|
|
|
pxm.fill(Qt::black);
|
|
|
|
ui.colorbtn->setIcon(pxm);
|
|
|
|
|
|
|
|
/* Set header resize modes and initial section sizes */
|
|
|
|
ui.msgFileList->setColumnCount(5);
|
|
|
|
|
|
|
|
QHeaderView * _smheader = ui.msgFileList->header () ;
|
|
|
|
|
|
|
|
_smheader->resizeSection ( 0, 200 );
|
|
|
|
_smheader->resizeSection ( 1, 60 );
|
|
|
|
_smheader->resizeSection ( 2, 60 );
|
|
|
|
_smheader->resizeSection ( 3, 220 );
|
|
|
|
_smheader->resizeSection ( 4, 10 );
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
/* Hide platform specific features */
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ChanMsgDialog::channelstreeViewCostumPopupMenu( QPoint point )
|
|
|
|
{
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
QMenu contextMnu( this );
|
|
|
|
QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
deletechannelAct = new QAction( tr( "Delete Channel" ), this );
|
2007-11-14 22:18:48 -05:00
|
|
|
connect( deletechannelAct , SIGNAL( triggered() ), this, SLOT( deletechannel() ) );
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
createchannelmsgAct = new QAction( tr( "Create Channel MSG" ), this );
|
|
|
|
connect( createchannelmsgAct , SIGNAL( triggered() ), this, SLOT( createchannelmsg() ) );
|
|
|
|
|
|
|
|
|
|
|
|
contextMnu.clear();
|
2007-11-14 22:18:48 -05:00
|
|
|
contextMnu.addAction( deletechannelAct);
|
2008-11-25 20:19:09 -05:00
|
|
|
contextMnu.addAction( createchannelmsgAct);
|
|
|
|
contextMnu.exec( mevent->globalPos() );
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2007-11-18 18:35:53 -05:00
|
|
|
void ChanMsgDialog::closeEvent (QCloseEvent * event)
|
|
|
|
{
|
2009-02-11 13:43:37 -05:00
|
|
|
//=== uncheck all repecient's boxes =======
|
|
|
|
QTreeWidget *sendWidget = ui.msgSendList;
|
|
|
|
|
|
|
|
for(int i=0;i<sendWidget->topLevelItemCount();++i)
|
|
|
|
sendWidget->topLevelItem(i)->setCheckState(0,Qt::Unchecked) ;
|
|
|
|
|
|
|
|
|
2008-03-31 17:02:12 -04:00
|
|
|
event->accept();
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* We can save to Drafts.... but we'll do this later.
|
|
|
|
* ... no auto saving for the moment,
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if 0
|
2008-03-24 21:41:01 -04:00
|
|
|
if (maybeSave())
|
|
|
|
{
|
|
|
|
event->accept();
|
2008-11-25 20:19:09 -05:00
|
|
|
}
|
2008-03-24 21:41:01 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
event->ignore();
|
|
|
|
hide();
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
RshareSettings config;
|
2008-03-24 21:41:01 -04:00
|
|
|
config.saveWidgetInformation(this);
|
2008-03-31 17:02:12 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-11-18 18:35:53 -05:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
void ChanMsgDialog::deletechannel()
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
void ChanMsgDialog::createchannelmsg()
|
|
|
|
{
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
}
|
2008-11-25 20:19:09 -05:00
|
|
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
void ChanMsgDialog::insertSendList()
|
|
|
|
{
|
2008-01-25 03:49:40 -05:00
|
|
|
if (!rsPeers)
|
|
|
|
{
|
|
|
|
/* not ready yet! */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::list<std::string> peers;
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
|
|
|
|
rsPeers->getFriendList(peers);
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* get a link to the table */
|
|
|
|
QTreeWidget *sendWidget = ui.msgSendList;
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem *> items;
|
2008-01-25 03:49:40 -05:00
|
|
|
for(it = peers.begin(); it != peers.end(); it++)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-01-25 03:49:40 -05:00
|
|
|
|
|
|
|
RsPeerDetails detail;
|
|
|
|
if (!rsPeers->getPeerDetails(*it, detail))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-01-25 03:49:40 -05:00
|
|
|
continue; /* BAD */
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2008-01-25 03:49:40 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* make a widget per friend */
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
|
|
|
|
|
|
|
|
|
|
|
|
/* add all the labels */
|
|
|
|
/* (0) Person */
|
2008-01-25 03:49:40 -05:00
|
|
|
item -> setText(0, QString::fromStdString(detail.name));
|
2007-11-14 22:18:48 -05:00
|
|
|
/* () Org */
|
2008-01-26 08:08:28 -05:00
|
|
|
//item -> setText(1, QString::fromStdString(detail.org));
|
2007-11-14 22:18:48 -05:00
|
|
|
/* () Location */
|
2008-01-26 08:08:28 -05:00
|
|
|
//item -> setText(2, QString::fromStdString(detail.location));
|
2007-11-14 22:18:48 -05:00
|
|
|
/* () Country */
|
2008-01-26 08:08:28 -05:00
|
|
|
//item -> setText(3, QString::fromStdString(detail.email));
|
2008-01-25 03:49:40 -05:00
|
|
|
/* () Id */
|
2008-01-26 08:08:28 -05:00
|
|
|
item -> setText(1, QString::fromStdString(detail.id));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
item -> setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
|
2008-01-25 03:49:40 -05:00
|
|
|
item -> setCheckState(0, Qt::Unchecked);
|
2008-02-04 12:55:59 -05:00
|
|
|
|
|
|
|
if (rsicontrol->IsInMsg(detail.id))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
item -> setCheckState(0, Qt::Checked);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item -> setCheckState(0, Qt::Unchecked);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add to the list */
|
|
|
|
items.append(item);
|
|
|
|
}
|
|
|
|
|
2008-01-25 03:49:40 -05:00
|
|
|
/* remove old items ??? */
|
|
|
|
sendWidget->clear();
|
2008-01-26 08:08:28 -05:00
|
|
|
sendWidget->setColumnCount(1);
|
2008-01-25 03:49:40 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* add the items in! */
|
|
|
|
sendWidget->insertTopLevelItems(0, items);
|
|
|
|
|
|
|
|
sendWidget->update(); /* update display */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ChanMsgDialog::insertChannelSendList()
|
|
|
|
{
|
2008-06-24 00:36:45 -04:00
|
|
|
#if 0
|
2007-11-14 22:18:48 -05:00
|
|
|
rsiface->lockData(); /* Lock Interface */
|
|
|
|
|
|
|
|
std::map<RsChanId,ChannelInfo>::const_iterator it;
|
|
|
|
const std::map<RsChanId,ChannelInfo> &chans =
|
|
|
|
rsiface->getChannels();
|
|
|
|
|
|
|
|
/* get a link to the table */
|
|
|
|
QTreeWidget *sendWidget = ui.msgSendList;
|
|
|
|
|
|
|
|
/* remove old items ??? */
|
|
|
|
sendWidget->clear();
|
|
|
|
sendWidget->setColumnCount(4);
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem *> items;
|
|
|
|
for(it = chans.begin(); it != chans.end(); it++)
|
|
|
|
{
|
|
|
|
/* make a widget per friend */
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
|
|
|
|
|
|
|
|
/* (0) Title */
|
|
|
|
item -> setText(0, QString::fromStdString(it->second.chanName));
|
|
|
|
if (it->second.publisher)
|
|
|
|
{
|
|
|
|
item -> setText(1, "Publisher");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item -> setText(1, "Listener");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << it->second.chanId;
|
|
|
|
item -> setText(2, QString::fromStdString(out.str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
item -> setText(3, "Channel");
|
|
|
|
|
|
|
|
item -> setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
|
|
|
|
item -> setCheckState(0, Qt::Unchecked);
|
|
|
|
|
|
|
|
if (it -> second.inBroadcast)
|
|
|
|
{
|
|
|
|
item -> setCheckState(0, Qt::Checked);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item -> setCheckState(0, Qt::Unchecked);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add to the list */
|
|
|
|
items.append(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add the items in! */
|
|
|
|
sendWidget->insertTopLevelItems(0, items);
|
|
|
|
|
2008-06-24 00:36:45 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
rsiface->unlockData(); /* UnLock Interface */
|
|
|
|
|
|
|
|
sendWidget->update(); /* update display */
|
2008-06-24 00:36:45 -04:00
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Utility Fns */
|
|
|
|
/***
|
|
|
|
RsCertId getSenderRsCertId(QTreeWidgetItem *i)
|
|
|
|
{
|
|
|
|
RsCertId id = (i -> text(3)).toStdString();
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
|
|
/* get the list of peers from the RsIface. */
|
2009-05-17 15:38:42 -04:00
|
|
|
void ChanMsgDialog::insertFileList(const std::list<DirDetails>& files_info)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-05-17 15:38:42 -04:00
|
|
|
// rsiface->lockData(); /* Lock Interface */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-05-17 15:38:42 -04:00
|
|
|
_recList.clear() ;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-05-17 15:38:42 -04:00
|
|
|
// const std::list<FileInfo> &recList = rsiface->getRecommendList();
|
|
|
|
std::list<DirDetails>::const_iterator it;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* get a link to the table */
|
|
|
|
QTreeWidget *tree = ui.msgFileList;
|
|
|
|
|
2009-05-17 15:38:42 -04:00
|
|
|
tree->clear();
|
|
|
|
tree->setColumnCount(5);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-05-17 15:38:42 -04:00
|
|
|
QList<QTreeWidgetItem *> items;
|
|
|
|
for(it = files_info.begin(); it != files_info.end(); it++)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-05-17 15:38:42 -04:00
|
|
|
FileInfo info ;
|
|
|
|
info.fname = it->name ;
|
|
|
|
info.hash = it->hash ;
|
2009-08-10 14:55:49 -04:00
|
|
|
info.rank = 0;//it->rank ;
|
2009-05-17 15:38:42 -04:00
|
|
|
info.size = it->count ;
|
|
|
|
_recList.push_back(info) ;
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* make a widget per person */
|
2009-05-17 15:38:42 -04:00
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-05-17 15:38:42 -04:00
|
|
|
item->setText(0, QString::fromStdString(it->name)); /* (0) Filename */
|
2009-07-10 19:48:20 -04:00
|
|
|
item->setText(1, misc::friendlyUnit(it->count)); /* (1) Size */
|
2009-08-10 14:55:49 -04:00
|
|
|
item->setText(2, QString::number(0)) ;//it->rank));
|
2009-05-17 15:38:42 -04:00
|
|
|
item->setText(3, QString::fromStdString(it->hash));
|
|
|
|
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
|
|
|
|
item->setCheckState(0, Qt::Checked);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* add to the list */
|
|
|
|
items.append(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add the items in! */
|
|
|
|
tree->insertTopLevelItems(0, items);
|
|
|
|
|
2009-05-17 15:38:42 -04:00
|
|
|
// rsiface->unlockData(); /* UnLock Interface */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
tree->update(); /* update display */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ChanMsgDialog::newMsg()
|
|
|
|
{
|
|
|
|
/* clear all */
|
|
|
|
ui.titleEdit->setText("No Title");
|
|
|
|
ui.msgText->setText("");
|
|
|
|
|
|
|
|
/* worker fns */
|
|
|
|
if (mIsMsg)
|
|
|
|
{
|
|
|
|
insertSendList();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
insertChannelSendList();
|
|
|
|
}
|
|
|
|
|
2009-05-17 15:38:42 -04:00
|
|
|
// insertFileList(std::list<DirDetails>());
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::insertTitleText(std::string title)
|
|
|
|
{
|
|
|
|
ui.titleEdit->setText(QString::fromStdString(title));
|
|
|
|
}
|
|
|
|
|
2008-09-08 08:41:46 -04:00
|
|
|
void ChanMsgDialog::insertPastedText(std::string msg)
|
|
|
|
{
|
|
|
|
std::string::size_type i=0 ;
|
|
|
|
while( (i=msg.find_first_of('\n',i+1)) < msg.size())
|
|
|
|
msg.replace(i,1,std::string("\n<BR/>> ")) ;
|
|
|
|
|
|
|
|
ui.msgText->setHtml(QString("<HTML><font color=\"blue\">")+QString::fromStdString(std::string("> ") + msg)+"</font><br/><br/></HTML>") ;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
void ChanMsgDialog::insertForwardPastedText(std::string msg)
|
|
|
|
{
|
|
|
|
std::string::size_type i=0 ;
|
|
|
|
while( (i=msg.find_first_of('\n',i+1)) < msg.size())
|
|
|
|
msg.replace(i,1,std::string("\n<BR/>> ")) ;
|
|
|
|
|
|
|
|
ui.msgText->setHtml(QString("<HTML><blockquote ><font color=\"blue\">")+QString::fromStdString(std::string("") + msg)+"</font><br/><br/></blockquote></HTML>") ;
|
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
void ChanMsgDialog::insertMsgText(std::string msg)
|
|
|
|
{
|
|
|
|
ui.msgText->setText(QString::fromStdString(msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ChanMsgDialog::sendMessage()
|
|
|
|
{
|
|
|
|
/* construct a message */
|
|
|
|
MessageInfo mi;
|
|
|
|
|
2008-01-26 08:08:28 -05:00
|
|
|
mi.title = ui.titleEdit->text().toStdWString();
|
2008-03-24 13:36:17 -04:00
|
|
|
mi.msg = ui.msgText->toHtml().toStdWString();
|
|
|
|
|
2008-02-04 12:55:59 -05:00
|
|
|
|
|
|
|
rsiface->lockData(); /* Lock Interface */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-05-17 15:38:42 -04:00
|
|
|
// const std::list<FileInfo>& recList = rsiface->getRecommendList();
|
|
|
|
for(std::list<FileInfo>::const_iterator it(_recList.begin()); it != _recList.end(); ++it)
|
2007-11-14 22:18:48 -05:00
|
|
|
if (it -> inRecommend)
|
|
|
|
mi.files.push_back(*it);
|
|
|
|
|
2008-02-04 12:55:59 -05:00
|
|
|
rsiface->unlockData(); /* UnLock Interface */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-02-04 12:55:59 -05:00
|
|
|
/* get the ids from the send list */
|
|
|
|
std::list<std::string> peers;
|
|
|
|
std::list<std::string> msgto;
|
|
|
|
std::list<std::string>::iterator iit;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-02-04 12:55:59 -05:00
|
|
|
rsPeers->getFriendList(peers);
|
|
|
|
|
|
|
|
for(iit = peers.begin(); iit != peers.end(); iit++)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-02-04 12:55:59 -05:00
|
|
|
if (rsicontrol->IsInMsg(*iit))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-02-04 12:55:59 -05:00
|
|
|
mi.msgto.push_back(*iit);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-04 12:55:59 -05:00
|
|
|
rsMsgs->MessageSend(mi);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ChanMsgDialog::cancelMessage()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Toggling .... Check Boxes.....
|
|
|
|
* This is dependent on whether we are a
|
|
|
|
*
|
|
|
|
* Chan or Msg Dialog.
|
|
|
|
*/
|
|
|
|
|
2008-09-03 08:56:37 -04:00
|
|
|
void ChanMsgDialog::addRecipient(std::string id)
|
|
|
|
{
|
|
|
|
QTreeWidget *sendWidget = ui.msgSendList;
|
|
|
|
|
|
|
|
for(int i=0;i<sendWidget->topLevelItemCount();++i)
|
|
|
|
if(sendWidget->topLevelItem(i)->text(1).toStdString() == id)
|
|
|
|
sendWidget->topLevelItem(i)->setCheckState(0,Qt::Checked) ;
|
2009-02-11 13:43:37 -05:00
|
|
|
//else
|
|
|
|
//sendWidget->topLevelItem(i)->setCheckState(0,Qt::Unchecked) ;
|
2008-09-03 08:56:37 -04:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* First the Msg (People) ones */
|
|
|
|
void ChanMsgDialog::togglePersonItem( QTreeWidgetItem *item, int col )
|
|
|
|
{
|
2008-07-10 14:52:56 -04:00
|
|
|
//std::cerr << "TogglePersonItem()" << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* extract id */
|
2008-01-26 08:08:28 -05:00
|
|
|
std::string id = (item -> text(1)).toStdString();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* get state */
|
|
|
|
bool inMsg = (Qt::Checked == item -> checkState(0)); /* alway column 0 */
|
|
|
|
|
|
|
|
/* call control fns */
|
|
|
|
|
|
|
|
rsicontrol -> SetInMsg(id, inMsg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Second the Channel ones */
|
|
|
|
void ChanMsgDialog::toggleChannelItem( QTreeWidgetItem *item, int col )
|
|
|
|
{
|
2008-07-10 14:52:56 -04:00
|
|
|
//std::cerr << "ToggleChannelItem()" << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* extract id */
|
|
|
|
std::string id = (item -> text(2)).toStdString();
|
|
|
|
|
|
|
|
/* get state */
|
|
|
|
bool inBroad = (Qt::Checked == item -> checkState(0)); /* alway column 0 */
|
|
|
|
|
|
|
|
/* call control fns */
|
|
|
|
|
|
|
|
rsicontrol -> SetInBroadcast(id, inBroad);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is actually for both */
|
|
|
|
void ChanMsgDialog::toggleRecommendItem( QTreeWidgetItem *item, int col )
|
|
|
|
{
|
2008-07-10 14:52:56 -04:00
|
|
|
//std::cerr << "ToggleRecommendItem()" << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* extract name */
|
|
|
|
std::string id = (item -> text(0)).toStdString();
|
|
|
|
|
|
|
|
/* get state */
|
|
|
|
bool inRecommend = (Qt::Checked == item -> checkState(0)); /* alway column 0 */
|
|
|
|
|
|
|
|
/* call control fns */
|
|
|
|
|
|
|
|
rsicontrol -> SetInRecommend(id, inRecommend);
|
|
|
|
return;
|
|
|
|
}
|
2008-11-25 20:19:09 -05:00
|
|
|
|
|
|
|
|
|
|
|
void ChanMsgDialog::setupFileActions()
|
|
|
|
{
|
|
|
|
QMenu *menu = new QMenu(tr("&File"), this);
|
|
|
|
menuBar()->addMenu(menu);
|
|
|
|
|
|
|
|
QAction *a;
|
|
|
|
|
|
|
|
a = new QAction(QIcon(":/images/textedit/filenew.png"), tr("&New"), this);
|
|
|
|
a->setShortcut(QKeySequence::New);
|
|
|
|
connect(a, SIGNAL(triggered()), this, SLOT(fileNew()));
|
|
|
|
menu->addAction(a);
|
|
|
|
|
|
|
|
a = new QAction(QIcon(":/images/textedit/fileopen.png"), tr("&Open..."), this);
|
|
|
|
a->setShortcut(QKeySequence::Open);
|
|
|
|
connect(a, SIGNAL(triggered()), this, SLOT(fileOpen()));
|
|
|
|
menu->addAction(a);
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
actionSave = a = new QAction(QIcon(":/images/textedit/filesave.png"), tr("&Save"), this);
|
|
|
|
a->setShortcut(QKeySequence::Save);
|
|
|
|
connect(a, SIGNAL(triggered()), this, SLOT(fileSave()));
|
|
|
|
a->setEnabled(false);
|
|
|
|
menu->addAction(a);
|
|
|
|
|
|
|
|
a = new QAction(tr("Save &As..."), this);
|
|
|
|
connect(a, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
|
|
|
|
menu->addAction(a);
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
a = new QAction(QIcon(":/images/textedit/fileprint.png"), tr("&Print..."), this);
|
|
|
|
a->setShortcut(QKeySequence::Print);
|
|
|
|
connect(a, SIGNAL(triggered()), this, SLOT(filePrint()));
|
|
|
|
menu->addAction(a);
|
|
|
|
|
|
|
|
/*a = new QAction(QIcon(":/images/textedit/fileprint.png"), tr("Print Preview..."), this);
|
|
|
|
connect(a, SIGNAL(triggered()), this, SLOT(filePrintPreview()));
|
|
|
|
menu->addAction(a);*/
|
|
|
|
|
|
|
|
a = new QAction(QIcon(":/images/textedit/exportpdf.png"), tr("&Export PDF..."), this);
|
|
|
|
a->setShortcut(Qt::CTRL + Qt::Key_D);
|
|
|
|
connect(a, SIGNAL(triggered()), this, SLOT(filePrintPdf()));
|
|
|
|
menu->addAction(a);
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
a = new QAction(tr("&Quit"), this);
|
|
|
|
a->setShortcut(Qt::CTRL + Qt::Key_Q);
|
|
|
|
connect(a, SIGNAL(triggered()), this, SLOT(close()));
|
|
|
|
menu->addAction(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::setupEditActions()
|
|
|
|
{
|
|
|
|
QMenu *menu = new QMenu(tr("&Edit"), this);
|
|
|
|
menuBar()->addMenu(menu);
|
|
|
|
|
|
|
|
QAction *a;
|
|
|
|
a = actionUndo = new QAction(QIcon(":/images/textedit/editundo.png"), tr("&Undo"), this);
|
|
|
|
a->setShortcut(QKeySequence::Undo);
|
|
|
|
menu->addAction(a);
|
|
|
|
a = actionRedo = new QAction(QIcon(":/images/textedit/editredo.png"), tr("&Redo"), this);
|
|
|
|
a->setShortcut(QKeySequence::Redo);
|
|
|
|
menu->addAction(a);
|
|
|
|
menu->addSeparator();
|
|
|
|
a = actionCut = new QAction(QIcon(":/images/textedit/editcut.png"), tr("Cu&t"), this);
|
|
|
|
a->setShortcut(QKeySequence::Cut);
|
|
|
|
menu->addAction(a);
|
|
|
|
a = actionCopy = new QAction(QIcon(":/images/textedit/editcopy.png"), tr("&Copy"), this);
|
|
|
|
a->setShortcut(QKeySequence::Copy);
|
|
|
|
menu->addAction(a);
|
|
|
|
a = actionPaste = new QAction(QIcon(":/images/textedit/editpaste.png"), tr("&Paste"), this);
|
|
|
|
a->setShortcut(QKeySequence::Paste);
|
|
|
|
menu->addAction(a);
|
|
|
|
actionPaste->setEnabled(!QApplication::clipboard()->text().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::setupViewActions()
|
|
|
|
{
|
|
|
|
QMenu *menu = new QMenu(tr("&View"), this);
|
|
|
|
menuBar()->addMenu(menu);
|
|
|
|
|
|
|
|
QAction *a;
|
|
|
|
|
|
|
|
a = new QAction(QIcon(""), tr("&Contacts Sidebar"), this);
|
|
|
|
connect(a, SIGNAL(triggered()), this, SLOT(toggleContacts()));
|
|
|
|
menu->addAction(a);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::setupInsertActions()
|
|
|
|
{
|
|
|
|
QMenu *menu = new QMenu(tr("&Insert"), this);
|
|
|
|
menuBar()->addMenu(menu);
|
|
|
|
|
|
|
|
QAction *a;
|
|
|
|
|
|
|
|
a = new QAction(QIcon(""), tr("&Image"), this);
|
|
|
|
connect(a, SIGNAL(triggered()), this, SLOT(addImage()));
|
|
|
|
menu->addAction(a);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::textBold()
|
|
|
|
{
|
|
|
|
QTextCharFormat fmt;
|
|
|
|
fmt.setFontWeight(ui.boldbtn->isChecked() ? QFont::Bold : QFont::Normal);
|
|
|
|
mergeFormatOnWordOrSelection(fmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::textUnderline()
|
|
|
|
{
|
|
|
|
QTextCharFormat fmt;
|
|
|
|
fmt.setFontUnderline(ui.underlinebtn->isChecked());
|
|
|
|
mergeFormatOnWordOrSelection(fmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::textItalic()
|
|
|
|
{
|
|
|
|
QTextCharFormat fmt;
|
|
|
|
fmt.setFontItalic(ui.italicbtn->isChecked());
|
|
|
|
mergeFormatOnWordOrSelection(fmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::textFamily(const QString &f)
|
|
|
|
{
|
|
|
|
QTextCharFormat fmt;
|
|
|
|
fmt.setFontFamily(f);
|
|
|
|
mergeFormatOnWordOrSelection(fmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::textSize(const QString &p)
|
|
|
|
{
|
|
|
|
QTextCharFormat fmt;
|
|
|
|
fmt.setFontPointSize(p.toFloat());
|
|
|
|
mergeFormatOnWordOrSelection(fmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::textStyle(int styleIndex)
|
|
|
|
{
|
|
|
|
QTextCursor cursor = ui.msgText->textCursor();
|
|
|
|
|
|
|
|
if (styleIndex != 0) {
|
|
|
|
QTextListFormat::Style style = QTextListFormat::ListDisc;
|
|
|
|
|
|
|
|
switch (styleIndex) {
|
|
|
|
default:
|
|
|
|
case 1:
|
|
|
|
style = QTextListFormat::ListDisc;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
style = QTextListFormat::ListCircle;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
style = QTextListFormat::ListSquare;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
style = QTextListFormat::ListDecimal;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
style = QTextListFormat::ListLowerAlpha;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
style = QTextListFormat::ListUpperAlpha;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor.beginEditBlock();
|
|
|
|
|
|
|
|
QTextBlockFormat blockFmt = cursor.blockFormat();
|
|
|
|
|
|
|
|
QTextListFormat listFmt;
|
|
|
|
|
|
|
|
if (cursor.currentList()) {
|
|
|
|
listFmt = cursor.currentList()->format();
|
|
|
|
} else {
|
|
|
|
listFmt.setIndent(blockFmt.indent() + 1);
|
|
|
|
blockFmt.setIndent(0);
|
|
|
|
cursor.setBlockFormat(blockFmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
listFmt.setStyle(style);
|
|
|
|
|
|
|
|
cursor.createList(listFmt);
|
|
|
|
|
|
|
|
cursor.endEditBlock();
|
|
|
|
} else {
|
|
|
|
// ####
|
|
|
|
QTextBlockFormat bfmt;
|
|
|
|
bfmt.setObjectIndex(-1);
|
|
|
|
cursor.mergeBlockFormat(bfmt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::textColor()
|
|
|
|
{
|
|
|
|
QColor col = QColorDialog::getColor(ui.msgText->textColor(), this);
|
|
|
|
if (!col.isValid())
|
|
|
|
return;
|
|
|
|
QTextCharFormat fmt;
|
|
|
|
fmt.setForeground(col);
|
|
|
|
mergeFormatOnWordOrSelection(fmt);
|
|
|
|
colorChanged(col);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::textAlign(QAction *a)
|
|
|
|
{
|
|
|
|
if (a == actionAlignLeft)
|
|
|
|
ui.msgText->setAlignment(Qt::AlignLeft);
|
|
|
|
else if (a == actionAlignCenter)
|
|
|
|
ui.msgText->setAlignment(Qt::AlignHCenter);
|
|
|
|
else if (a == actionAlignRight)
|
|
|
|
ui.msgText->setAlignment(Qt::AlignRight);
|
|
|
|
else if (a == actionAlignJustify)
|
|
|
|
ui.msgText->setAlignment(Qt::AlignJustify);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::currentCharFormatChanged(const QTextCharFormat &format)
|
|
|
|
{
|
|
|
|
fontChanged(format.font());
|
|
|
|
colorChanged(format.foreground().color());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::cursorPositionChanged()
|
|
|
|
{
|
|
|
|
alignmentChanged(ui.msgText->alignment());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
|
|
|
|
{
|
|
|
|
QTextCursor cursor = ui.msgText->textCursor();
|
|
|
|
if (!cursor.hasSelection())
|
|
|
|
cursor.select(QTextCursor::WordUnderCursor);
|
|
|
|
cursor.mergeCharFormat(format);
|
|
|
|
ui.msgText->mergeCurrentCharFormat(format);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::fontChanged(const QFont &f)
|
|
|
|
{
|
|
|
|
ui.comboFont->setCurrentIndex(ui.comboFont->findText(QFontInfo(f).family()));
|
|
|
|
ui.comboSize->setCurrentIndex(ui.comboSize->findText(QString::number(f.pointSize())));
|
|
|
|
ui.boldbtn->setChecked(f.bold());
|
|
|
|
ui.italicbtn->setChecked(f.italic());
|
|
|
|
ui.underlinebtn->setChecked(f.underline());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::colorChanged(const QColor &c)
|
|
|
|
{
|
|
|
|
QPixmap pix(16, 16);
|
|
|
|
pix.fill(c);
|
|
|
|
ui.colorbtn->setIcon(pix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::alignmentChanged(Qt::Alignment a)
|
|
|
|
{
|
|
|
|
if (a & Qt::AlignLeft) {
|
|
|
|
actionAlignLeft->setChecked(true);
|
|
|
|
} else if (a & Qt::AlignHCenter) {
|
|
|
|
actionAlignCenter->setChecked(true);
|
|
|
|
} else if (a & Qt::AlignRight) {
|
|
|
|
actionAlignRight->setChecked(true);
|
|
|
|
} else if (a & Qt::AlignJustify) {
|
|
|
|
actionAlignJustify->setChecked(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::clipboardDataChanged()
|
|
|
|
{
|
|
|
|
actionPaste->setEnabled(!QApplication::clipboard()->text().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChanMsgDialog::fileNew()
|
|
|
|
{
|
|
|
|
if (maybeSave()) {
|
|
|
|
ui.msgText->clear();
|
|
|
|
//setCurrentFileName(QString());
|
|
|
|
}
|
2008-03-24 21:41:01 -04:00
|
|
|
}
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
void ChanMsgDialog::fileOpen()
|
|
|
|
{
|
|
|
|
QString fn = QFileDialog::getOpenFileName(this, tr("Open File..."),
|
|
|
|
QString(), tr("HTML-Files (*.htm *.html);;All Files (*)"));
|
|
|
|
if (!fn.isEmpty())
|
|
|
|
load(fn);
|
2008-03-24 21:41:01 -04:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
bool ChanMsgDialog::fileSave()
|
|
|
|
{
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
return fileSaveAs();
|
|
|
|
|
|
|
|
QFile file(fileName);
|
|
|
|
if (!file.open(QFile::WriteOnly))
|
|
|
|
return false;
|
|
|
|
QTextStream ts(&file);
|
|
|
|
ts.setCodec(QTextCodec::codecForName("UTF-8"));
|
|
|
|
ts << ui.msgText->document()->toHtml("UTF-8");
|
|
|
|
ui.msgText->document()->setModified(false);
|
|
|
|
return true;
|
2008-03-26 15:30:34 -04:00
|
|
|
}
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
bool ChanMsgDialog::fileSaveAs()
|
|
|
|
{
|
|
|
|
QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."),
|
|
|
|
QString(), tr("HTML-Files (*.htm *.html);;All Files (*)"));
|
|
|
|
if (fn.isEmpty())
|
|
|
|
return false;
|
|
|
|
setCurrentFileName(fn);
|
|
|
|
return fileSave();
|
2008-03-26 15:30:34 -04:00
|
|
|
}
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
void ChanMsgDialog::filePrint()
|
|
|
|
{
|
|
|
|
#ifndef QT_NO_PRINTER
|
|
|
|
QPrinter printer(QPrinter::HighResolution);
|
|
|
|
printer.setFullPage(true);
|
|
|
|
QPrintDialog *dlg = new QPrintDialog(&printer, this);
|
|
|
|
if (ui.msgText->textCursor().hasSelection())
|
|
|
|
dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection);
|
|
|
|
dlg->setWindowTitle(tr("Print Document"));
|
|
|
|
if (dlg->exec() == QDialog::Accepted) {
|
|
|
|
ui.msgText->print(&printer);
|
|
|
|
}
|
|
|
|
delete dlg;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*void TextEdit::filePrintPreview()
|
|
|
|
{
|
|
|
|
PrintPreview *preview = new PrintPreview(textEdit->document(), this);
|
|
|
|
preview->setWindowModality(Qt::WindowModal);
|
|
|
|
preview->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
preview->show();
|
|
|
|
}*/
|
|
|
|
|
|
|
|
void ChanMsgDialog::filePrintPdf()
|
|
|
|
{
|
|
|
|
#ifndef QT_NO_PRINTER
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, "Export PDF",
|
|
|
|
QString(), "*.pdf");
|
|
|
|
if (!fileName.isEmpty()) {
|
|
|
|
if (QFileInfo(fileName).suffix().isEmpty())
|
|
|
|
fileName.append(".pdf");
|
|
|
|
QPrinter printer(QPrinter::HighResolution);
|
|
|
|
printer.setOutputFormat(QPrinter::PdfFormat);
|
|
|
|
printer.setOutputFileName(fileName);
|
|
|
|
ui.msgText->document()->print(&printer);
|
|
|
|
}
|
|
|
|
#endif
|
2008-03-24 21:41:01 -04:00
|
|
|
}
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
void ChanMsgDialog::setCurrentFileName(const QString &fileName)
|
|
|
|
{
|
|
|
|
this->fileName = fileName;
|
|
|
|
ui.msgText->document()->setModified(false);
|
|
|
|
|
|
|
|
setWindowModified(false);
|
2008-03-24 21:41:01 -04:00
|
|
|
}
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
bool ChanMsgDialog::load(const QString &f)
|
|
|
|
{
|
|
|
|
if (!QFile::exists(f))
|
|
|
|
return false;
|
|
|
|
QFile file(f);
|
|
|
|
if (!file.open(QFile::ReadOnly))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QByteArray data = file.readAll();
|
|
|
|
QTextCodec *codec = Qt::codecForHtml(data);
|
|
|
|
QString str = codec->toUnicode(data);
|
|
|
|
if (Qt::mightBeRichText(str)) {
|
|
|
|
ui.msgText->setHtml(str);
|
|
|
|
} else {
|
|
|
|
str = QString::fromLocal8Bit(data);
|
|
|
|
ui.msgText->setPlainText(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
setCurrentFileName(f);
|
|
|
|
return true;
|
2008-03-24 21:41:01 -04:00
|
|
|
}
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
|
|
|
|
bool ChanMsgDialog::maybeSave()
|
|
|
|
{
|
|
|
|
if (!ui.msgText->document()->isModified())
|
|
|
|
return true;
|
|
|
|
if (fileName.startsWith(QLatin1String(":/")))
|
|
|
|
return true;
|
|
|
|
QMessageBox::StandardButton ret;
|
|
|
|
ret = QMessageBox::warning(this, tr("Save Message"),
|
|
|
|
tr("Message has not been Sent.\n"
|
|
|
|
"Do you want to save message ?"),
|
|
|
|
QMessageBox::Save | QMessageBox::Discard
|
|
|
|
| QMessageBox::Cancel);
|
|
|
|
if (ret == QMessageBox::Save)
|
|
|
|
return fileSave();
|
|
|
|
else if (ret == QMessageBox::Cancel)
|
|
|
|
return false;
|
|
|
|
return true;
|
2008-03-24 21:41:01 -04:00
|
|
|
}
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
|
|
|
|
void ChanMsgDialog::toggleContacts()
|
|
|
|
{
|
|
|
|
ui.contactsdockWidget->setVisible(!ui.contactsdockWidget->isVisible());
|
2008-03-24 13:36:17 -04:00
|
|
|
}
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
void ChanMsgDialog::addImage()
|
|
|
|
{
|
|
|
|
|
2008-03-25 08:28:13 -04:00
|
|
|
QString fileimg = QFileDialog::getOpenFileName( this, tr( "Choose Image" ),
|
|
|
|
QString(setter.value("LastDir").toString()) ,tr("Image Files supported (*.png *.jpeg *.jpg *.gif)"));
|
2008-11-25 20:19:09 -05:00
|
|
|
|
|
|
|
if ( fileimg.isEmpty() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage base(fileimg);
|
|
|
|
|
|
|
|
QString pathimage = fileimg.left(fileimg.lastIndexOf("/"))+"/";
|
|
|
|
setter.setValue("LastDir",pathimage);
|
|
|
|
|
|
|
|
Create_New_Image_Tag(fileimg);
|
2008-03-25 08:28:13 -04:00
|
|
|
}
|
|
|
|
|
2008-11-25 20:19:09 -05:00
|
|
|
void ChanMsgDialog::Create_New_Image_Tag( const QString urlremoteorlocal )
|
|
|
|
{
|
|
|
|
/*if (image_extension(urlremoteorlocal)) {*/
|
|
|
|
QString subtext = QString("<p><img src=\"%1\" />").arg(urlremoteorlocal);
|
|
|
|
///////////subtext.append("<br/><br/>Description on image.</p>");
|
|
|
|
QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(subtext);
|
|
|
|
ui.msgText->textCursor().insertFragment(fragment);
|
|
|
|
//emit statusMessage(QString("Image new :").arg(urlremoteorlocal));
|
|
|
|
//}
|
2008-03-25 08:28:13 -04:00
|
|
|
}
|
|
|
|
|
2008-03-26 15:30:34 -04:00
|
|
|
|
|
|
|
|