diff options
author | dknn <yoann.blein@free.fr> | 2012-08-06 14:40:13 (GMT) |
---|---|---|
committer | dknn <yoann.blein@free.fr> | 2012-09-22 09:32:38 (GMT) |
commit | d62f8088b8cc42417f97a3b5c3f99bf9288593d4 (patch) | |
tree | 46861355d40bfe5e18088496abc9654e0dbaa00c /Swift/QtUI | |
parent | 343f88e3048887e83cc91bb710510b3aa618f779 (diff) | |
download | swift-contrib-d62f8088b8cc42417f97a3b5c3f99bf9288593d4.zip swift-contrib-d62f8088b8cc42417f97a3b5c3f99bf9288593d4.tar.bz2 |
Add support for multiple sharing and control in chat view
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/QtChatView.cpp | 42 | ||||
-rw-r--r-- | Swift/QtUI/QtChatView.h | 4 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 53 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.h | 7 | ||||
-rw-r--r-- | Swift/QtUI/ScreenSharing/QtRemoteScreenWindow.cpp | 13 | ||||
-rw-r--r-- | Swift/QtUI/ScreenSharing/QtRemoteScreenWindow.h | 2 | ||||
-rw-r--r-- | Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.cpp | 20 | ||||
-rw-r--r-- | Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.h | 8 |
8 files changed, 134 insertions, 15 deletions
diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp index 81820a3..25b786f 100644 --- a/Swift/QtUI/QtChatView.cpp +++ b/Swift/QtUI/QtChatView.cpp @@ -444,6 +444,48 @@ void QtChatView::setWhiteboardSessionStatus(QString id, const ChatWindow::Whiteb divElement.setInnerXml(newInnerHTML); } +void QtChatView::setScreenSharingStatus(QString id, ScreenSharing::SCState state, const QString& /*msg*/) +{ + QWebElement ftElement = findDivElementWithID(document_, id); + if (ftElement.isNull()) { + SWIFT_LOG(debug) << "Tried to access screen sharing UI via invalid id! id = " << Q2PSTRING(id) << std::endl; + return; + } + + QString newInnerHTML = ""; + if (state == ScreenSharing::WaitingForAccept) { + newInnerHTML = tr("Waiting for other side to accept the sharing.") + "<br/>" + + QtChatWindow::buildChatWindowButton(tr("Cancel"), QtChatWindow::ButtonScreenSharingCancel, id); + } + if (state == ScreenSharing::Negotiating) { + newInnerHTML = tr("Negotiating...") + "<br/>" + + QtChatWindow::buildChatWindowButton(tr("Cancel"), QtChatWindow::ButtonScreenSharingCancel, id); + } + if (state == ScreenSharing::Connecting) { + newInnerHTML = tr("Connecting...") + "<br/>" + + QtChatWindow::buildChatWindowButton(tr("Cancel"), QtChatWindow::ButtonScreenSharingCancel, id); + } + if (state == ScreenSharing::BroadCasting) { + newInnerHTML = tr("Broadcasting the desktop...") + "<br/>" + + QtChatWindow::buildChatWindowButton(tr("Terminate"), QtChatWindow::ButtonScreenSharingStop, id); + } + else if (state == ScreenSharing::Receiving) { + newInnerHTML = tr("Receiving desktop from the other party...") + "<br/>" + + QtChatWindow::buildChatWindowButton(tr("Terminate"), QtChatWindow::ButtonScreenSharingStop, id); + } + else if (state == ScreenSharing::Canceled) { + newInnerHTML = tr("Sharing has been canceled!"); + } + else if (state == ScreenSharing::Finished) { + newInnerHTML = tr("Sharing finished."); + } + else if (state == ScreenSharing::Failed) { + newInnerHTML = tr("Sharing failed."); + } + + ftElement.setInnerXml(newInnerHTML); +} + void QtChatView::setMUCInvitationJoined(QString id) { QWebElement divElement = findElementWithID(document_, "div", id); QWebElement buttonElement = findElementWithID(divElement, "input", "mucinvite"); diff --git a/Swift/QtUI/QtChatView.h b/Swift/QtUI/QtChatView.h index 9080808..403dec0 100644 --- a/Swift/QtUI/QtChatView.h +++ b/Swift/QtUI/QtChatView.h @@ -17,6 +17,7 @@ #include "ChatSnippet.h" #include <Swift/Controllers/UIInterfaces/ChatWindow.h> +#include <Swiften/ScreenSharing/ScreenSharing.h> class QWebPage; class QUrl; @@ -43,7 +44,8 @@ namespace Swift { QString getLastSentMessage(); void addToJSEnvironment(const QString&, QObject*); void setFileTransferProgress(QString id, const int percentageDone); - void setFileTransferStatus(QString id, const ChatWindow::FileTransferState state, const QString& msg); + void setFileTransferStatus(QString id, const ChatWindow::FileTransferState state, const QString& /*msg*/); + void setScreenSharingStatus(QString id, ScreenSharing::SCState state, const QString& msg); void setWhiteboardSessionStatus(QString id, const ChatWindow::WhiteboardSessionState state); void setMUCInvitationJoined(QString id); void showEmoticons(bool show); diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 314e36c..730195c 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -61,6 +61,9 @@ const QString QtChatWindow::ButtonFileTransferCancel = QString("filetransfer-can const QString QtChatWindow::ButtonFileTransferSetDescription = QString("filetransfer-setdescription"); const QString QtChatWindow::ButtonFileTransferSendRequest = QString("filetransfer-sendrequest"); const QString QtChatWindow::ButtonFileTransferAcceptRequest = QString("filetransfer-acceptrequest"); +const QString QtChatWindow::ButtonScreenSharingCancel = QString("screensharing-cancel"); +const QString QtChatWindow::ButtonScreenSharingStop = QString("screensharing-stop"); +const QString QtChatWindow::ButtonScreenSharingAcceptRequest = QString("screensharing-acceptrequest"); const QString QtChatWindow::ButtonMUCInvite = QString("mucinvite"); @@ -685,6 +688,47 @@ void QtChatWindow::setWhiteboardSessionStatus(std::string id, const ChatWindow:: messageLog_->setWhiteboardSessionStatus(QString::fromStdString(id), state); } +std::string QtChatWindow::addScreenSharing(const std::string& senderName, bool incoming) +{ + SWIFT_LOG(debug) << "addScreenSharing" << std::endl; + QString ss_id = QString("ft%1").arg(P2QSTRING(boost::lexical_cast<std::string>(idCounter_++))); + + QString htmlString; + if (incoming) { + htmlString = P2QSTRING(senderName) + " shares his screen with you" + "<br/>" + + "<div id='" + ss_id + "'>" + + buildChatWindowButton(tr("Accept"), ButtonScreenSharingAcceptRequest, ss_id) + + buildChatWindowButton(tr("Cancel"), ButtonScreenSharingCancel, ss_id) + + "</div>"; + } else { + htmlString = tr("Sharing screen with ") + contact_ + "<br/>" + + "<div id='" + ss_id + "'>" + + buildChatWindowButton(tr("Cancel"), ButtonScreenSharingCancel, ss_id) + + "</div>"; + } + + bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasFileTransfer, senderName, !incoming); + if (lastLineTracker_.getShouldMoveLastLine()) { + /* should this be queued? */ + messageLog_->addLastSeenLine(); + /* if the line is added we should break the snippet */ + appendToPrevious = false; + } + QString qAvatarPath = "qrc:/icons/avatar.png"; + std::string id = "ssmessage" + boost::lexical_cast<std::string>(idCounter_++); + messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new MessageSnippet(htmlString, Qt::escape(P2QSTRING(senderName)), B2QDATE(boost::posix_time::second_clock::local_time()), qAvatarPath, !incoming, appendToPrevious, theme_, P2QSTRING(id)))); + + previousMessageWasSelf_ = !incoming; + previousSenderName_ = P2QSTRING(senderName); + previousMessageKind_ = PreviousMessageWasFileTransfer; + return Q2PSTRING(ss_id); +} + +void QtChatWindow::setScreenSharingStatus(std::string id, const ScreenSharing::SCState state, const std::string& msg) +{ + messageLog_->setScreenSharingStatus(QString::fromStdString(id), state, QString::fromStdString(msg)); +} + void QtChatWindow::handleHTMLButtonClicked(QString id, QString encodedArgument1, QString encodedArgument2, QString encodedArgument3) { QString arg1 = decodeButtonArgument(encodedArgument1); QString arg2 = decodeButtonArgument(encodedArgument2); @@ -731,6 +775,15 @@ void QtChatWindow::handleHTMLButtonClicked(QString id, QString encodedArgument1, QString id = arg1; onWhiteboardWindowShow(); } + else if (id.startsWith(ButtonScreenSharingAcceptRequest)) { + onScreenSharingAccept(Q2PSTRING(arg1)); + } + else if (id.startsWith(ButtonScreenSharingCancel)) { + onScreenSharingCancel(Q2PSTRING(arg1)); + } + else if (id.startsWith(ButtonScreenSharingStop)) { + onScreenSharingStop(Q2PSTRING(arg1)); + } else if (id.startsWith(ButtonMUCInvite)) { QString roomJID = arg1; QString password = arg2; diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h index 3416b42..d802bf9 100644 --- a/Swift/QtUI/QtChatWindow.h +++ b/Swift/QtUI/QtChatWindow.h @@ -80,6 +80,9 @@ namespace Swift { static const QString ButtonFileTransferSetDescription; static const QString ButtonFileTransferSendRequest; static const QString ButtonFileTransferAcceptRequest; + static const QString ButtonScreenSharingCancel; + static const QString ButtonScreenSharingStop; + static const QString ButtonScreenSharingAcceptRequest; static const QString ButtonMUCInvite; public: @@ -96,6 +99,10 @@ namespace Swift { std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes); void setFileTransferProgress(std::string id, const int percentageDone); void setFileTransferStatus(std::string id, const FileTransferState state, const std::string& msg); + + // Screen sharing related stuff + virtual std::string addScreenSharing(const std::string& senderName, bool incoming); + virtual void setScreenSharingStatus(std::string id, const ScreenSharing::SCState state, const std::string& msg = ""); std::string addWhiteboardRequest(bool senderIsSelf); void setWhiteboardSessionStatus(std::string id, const ChatWindow::WhiteboardSessionState state); diff --git a/Swift/QtUI/ScreenSharing/QtRemoteScreenWindow.cpp b/Swift/QtUI/ScreenSharing/QtRemoteScreenWindow.cpp index e6cd291..a1f1a88 100644 --- a/Swift/QtUI/ScreenSharing/QtRemoteScreenWindow.cpp +++ b/Swift/QtUI/ScreenSharing/QtRemoteScreenWindow.cpp @@ -8,15 +8,22 @@ #include "RemoteScreenViewerWidget.h" #include <QToolBar> +#include <QVBoxLayout> #include <Swiften/ScreenSharing/IncomingScreenSharing.h> namespace Swift { QtRemoteScreenWindow::QtRemoteScreenWindow(boost::shared_ptr<IncomingScreenSharing> incScreenSharing, QWidget *parent) - : QMainWindow(parent), RemoteScreenWindow(incScreenSharing) + : QMainWindow(parent), RemoteScreenWindow(incScreenSharing), viewer(new RemoteScreenViewerWidget(iss)) { - setCentralWidget(new RemoteScreenViewerWidget(iss)); + QVBoxLayout* centralLayout = new QVBoxLayout; + centralLayout->addWidget(viewer); + + QWidget* central = new QWidget(this); + central->setLayout(centralLayout); + + setCentralWidget(central); controlToolBar = addToolBar(tr("Control")); closeAction = controlToolBar->addAction(QIcon::fromTheme("window-close"), tr("&Terminate session"), this, SLOT(handleCloseTriggered())); @@ -28,7 +35,7 @@ QtRemoteScreenWindow::~QtRemoteScreenWindow() void QtRemoteScreenWindow::handleCloseTriggered() { - iss->stop(); + onStopRequest(); } } diff --git a/Swift/QtUI/ScreenSharing/QtRemoteScreenWindow.h b/Swift/QtUI/ScreenSharing/QtRemoteScreenWindow.h index 00ac803..d6c783a 100644 --- a/Swift/QtUI/ScreenSharing/QtRemoteScreenWindow.h +++ b/Swift/QtUI/ScreenSharing/QtRemoteScreenWindow.h @@ -13,6 +13,7 @@ class QToolBar; namespace Swift { + class RemoteScreenViewerWidget; class QtRemoteScreenWindow : public QMainWindow, public RemoteScreenWindow { Q_OBJECT @@ -25,6 +26,7 @@ namespace Swift { void handleCloseTriggered(); private: + RemoteScreenViewerWidget* viewer; QAction* closeAction; QToolBar* controlToolBar; }; diff --git a/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.cpp b/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.cpp index f601f1b..7bb3f26 100644 --- a/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.cpp +++ b/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.cpp @@ -18,7 +18,7 @@ namespace Swift { RemoteScreenViewerWidget::RemoteScreenViewerWidget(boost::shared_ptr<IncomingScreenSharing> incScreenSharing, QWidget *parent) : - QWidget(parent), iss(incScreenSharing) + QFrame(parent), iss(incScreenSharing) { iss->onNewImageReceived.connect(boost::bind(&RemoteScreenViewerWidget::handleNewImageReceived, this, _1)); } @@ -28,10 +28,11 @@ RemoteScreenViewerWidget::~RemoteScreenViewerWidget() iss->onNewImageReceived.disconnect(boost::bind(&RemoteScreenViewerWidget::handleNewImageReceived, this, _1)); } -void RemoteScreenViewerWidget::paintEvent(QPaintEvent *) +void RemoteScreenViewerWidget::paintEvent(QPaintEvent* event) { - QPainter painter(this); + QFrame::paintEvent(event); if (!pixmap.isNull()) { + QPainter painter(this); painter.translate(geometry().center()); painter.drawPixmap(-pixmap.rect().center(), pixmap); } @@ -39,15 +40,20 @@ void RemoteScreenViewerWidget::paintEvent(QPaintEvent *) void RemoteScreenViewerWidget::resizeEvent(QResizeEvent *event) { - if (!pixmap.isNull()) - pixmap = pixmap.scaled(event->size(), Qt::KeepAspectRatio); - QWidget::resizeEvent(event); + if (!pixmap.isNull()) { + int frameWidth2 = frameWidth() * 2; + QSize borders(frameWidth2, frameWidth2); + pixmap = pixmap.scaled(event->size() - borders, Qt::KeepAspectRatio); + } + QFrame::resizeEvent(event); } void RemoteScreenViewerWidget::handleNewImageReceived(const Image& image) { QImage qImg(image.data.data(), image.width, image.height, QImage::Format_RGB888); - pixmap = QPixmap::fromImage(qImg).scaled(size(), Qt::KeepAspectRatio); + int frameWidth2 = frameWidth() * 2; + QSize borders(frameWidth2, frameWidth2); + pixmap = QPixmap::fromImage(qImg).scaled(size() - borders, Qt::KeepAspectRatio); update(); } diff --git a/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.h b/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.h index 622bd26..c074e9f 100644 --- a/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.h +++ b/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.h @@ -6,7 +6,7 @@ #pragma once -#include <QWidget> +#include <QFrame> #include <boost/shared_ptr.hpp> @@ -14,15 +14,15 @@ namespace Swift { class IncomingScreenSharing; class Image; - class RemoteScreenViewerWidget : public QWidget { + class RemoteScreenViewerWidget : public QFrame { Q_OBJECT public: RemoteScreenViewerWidget(boost::shared_ptr<IncomingScreenSharing> incScreenSharing, QWidget *parent = 0); ~RemoteScreenViewerWidget(); protected: - void paintEvent(QPaintEvent *); - void resizeEvent(QResizeEvent *event); + void paintEvent(QPaintEvent* event); + void resizeEvent(QResizeEvent* event); private: void handleNewImageReceived(const Image& image); |