summaryrefslogtreecommitdiffstats
path: root/src/gui/clientFileSendDialog.cpp
diff options
context:
space:
mode:
authorFabian Schillinger2010-11-01 17:35:27 +0100
committerFabian Schillinger2010-11-01 17:35:27 +0100
commitea3fb17345e5f82db9f2e98a8062e95797700ace (patch)
tree1da0d1a8ec9455364386af78762d0f6fed187824 /src/gui/clientFileSendDialog.cpp
parentProcess start/stop/view functionality (diff)
parent[PVSGUI] No X required for --help and --version (diff)
downloadpvs-ea3fb17345e5f82db9f2e98a8062e95797700ace.tar.gz
pvs-ea3fb17345e5f82db9f2e98a8062e95797700ace.tar.xz
pvs-ea3fb17345e5f82db9f2e98a8062e95797700ace.zip
Merge branch 'master' of openslx.org:pvs
Conflicts: CMakeLists.txt src/core/pvsConnectionManager.cpp src/pvs.cpp src/pvs.h
Diffstat (limited to 'src/gui/clientFileSendDialog.cpp')
-rw-r--r--src/gui/clientFileSendDialog.cpp201
1 files changed, 182 insertions, 19 deletions
diff --git a/src/gui/clientFileSendDialog.cpp b/src/gui/clientFileSendDialog.cpp
index b4512c0..93da725 100644
--- a/src/gui/clientFileSendDialog.cpp
+++ b/src/gui/clientFileSendDialog.cpp
@@ -22,6 +22,10 @@ ClientFileSendDialog::ClientFileSendDialog(QWidget *parent) :
{
setupUi(this);
+ _transferID = 0;
+ _error = false;
+ _isMulticast = false;
+
_file = NULL;
_socket = NULL;
_clientNicklistDialog = new ClientNicklistDialog(this);
@@ -58,7 +62,15 @@ void ClientFileSendDialog::open()
reject();
return;
}
- open(_clientNicklistDialog->getNick());
+
+ if (_clientNicklistDialog->isSendToAll())
+ {
+ sendToAll();
+ }
+ else
+ {
+ open(_clientNicklistDialog->getNick());
+ }
}
void ClientFileSendDialog::open(QString nick)
@@ -73,6 +85,70 @@ void ClientFileSendDialog::open(QString nick)
open(nick, filename);
}
+void ClientFileSendDialog::sendToAll()
+{
+ QString filename = QFileDialog::getOpenFileName(this, tr("Send File"), QDir::homePath(), "");
+ if (filename == "")
+ {
+ reject();
+ return;
+ }
+ sendToAll(filename);
+}
+
+void ClientFileSendDialog::sendToAll(QString filename)
+{
+ _isMulticast = true;
+
+ connect(_ifaceDBus, SIGNAL(outgoingMulticastTransferStarted(qulonglong)), SLOT(multicastTransferStarted(qulonglong)));
+ connect(_ifaceDBus, SIGNAL(outgoingMulticastTransferProgress(qulonglong,qulonglong,qulonglong)), SLOT(multicastTransferProgress(qulonglong, qulonglong, qulonglong)));
+ connect(_ifaceDBus, SIGNAL(outgoingMulticastTransferFinished(qulonglong)), SLOT(multicastTransferFinished(qulonglong)));
+ connect(_ifaceDBus, SIGNAL(outgoingMulticastTransferFailed(qulonglong, QString const&)), SLOT(multicastTransferFailed(qulonglong, QString const&)));
+
+ filenameLabel->setText(filename);
+ progressBar->setRange(0, 0);
+ labelNick->setText(tr("all"));
+ labelStatus->setText(tr("Waiting to start"));
+
+ QString errorMessage("Backend error");
+
+ // We need to jump through a lot of hoops because this call is prone to time out, and
+ // QtDBus does not support specifying timeouts in generated interfaces.
+ QDBusMessage call = QDBusMessage::createMethodCall("org.openslx.pvs", "/", "org.openslx.pvs", "createMulticastTransfer");
+ call << filename;
+
+ QDBusMessage reply = _ifaceDBus->connection().call(call, QDBus::Block, 5000);
+ if (reply.type() == QDBusMessage::ErrorMessage)
+ {
+ QMessageBox::critical(this, tr("File Send error"), tr("Error communicating with backend: %1: %2").arg(reply.errorName()).arg(reply.errorMessage()));
+ reject();
+ return;
+ }
+ else if (reply.type() == QDBusMessage::InvalidMessage)
+ {
+ QMessageBox::critical(this, tr("File Send error"), tr("Something went wrong while communicating with backend, but I don't know what."));
+ reject();
+ return;
+ }
+ else if (reply.type() == QDBusMessage::ReplyMessage)
+ {
+ QList<QVariant> args = reply.arguments();
+ bool created = args.at(0).toBool();
+ _transferID = args.at(1).toULongLong();
+ QString errorMessage = args.at(2).toString();
+ if (!created)
+ {
+ QMessageBox::critical(this, tr("File Send error"), tr("Could not create a multicast transfer: %1").arg(errorMessage));
+ reject();
+ return;
+ }
+ }
+
+ connect(cancelButton, SIGNAL(clicked()), SLOT(canceled()));
+
+ show();
+}
+
void ClientFileSendDialog::open(QString nick, QString filename)
{
// open file
@@ -127,6 +203,8 @@ void ClientFileSendDialog::receiveAck()
QString ack = QString::fromUtf8(_socket->readLine());
if (ack != "ok\n")
{
+ _error = true;
+ _reason = tr("Receiver declined");
qDebug("[%s] Received nack!", metaObject()->className());
close();
return;
@@ -158,27 +236,30 @@ void ClientFileSendDialog::sendFile()
void ClientFileSendDialog::close()
{
- if (_file && _file->isOpen())
- {
- _file->close();
- qDebug("[%s] File closed.", metaObject()->className());
- }
-
- if (_socket && _socket->isOpen())
+ if (!_isMulticast)
{
- disconnect(_socket, SIGNAL(readyRead()), this, SLOT(receiveAck()));
- disconnect(_socket, SIGNAL(bytesWritten(qint64)), this, SLOT(sendFile()));
- disconnect(_socket, SIGNAL(disconnected()), this, SLOT(close()));
- disconnect(_socket, SIGNAL(connected()), this, SLOT(sendHeader()));
- disconnect(_socket, SIGNAL(error(QAbstractSocket::SocketError)),
- this, SLOT(error(QAbstractSocket::SocketError)));
- _socket->disconnectFromHost();
- qDebug("[%s] Connection closed.", metaObject()->className());
+ if (_file && _file->isOpen())
+ {
+ _file->close();
+ qDebug("[%s] File closed.", metaObject()->className());
+ }
+
+ if (_socket && _socket->isOpen())
+ {
+ disconnect(_socket, SIGNAL(readyRead()), this, SLOT(receiveAck()));
+ disconnect(_socket, SIGNAL(bytesWritten(qint64)), this, SLOT(sendFile()));
+ disconnect(_socket, SIGNAL(disconnected()), this, SLOT(close()));
+ disconnect(_socket, SIGNAL(connected()), this, SLOT(sendHeader()));
+ disconnect(_socket, SIGNAL(error(QAbstractSocket::SocketError)),
+ this, SLOT(error(QAbstractSocket::SocketError)));
+ _socket->disconnectFromHost();
+ qDebug("[%s] Connection closed.", metaObject()->className());
+ }
}
- disconnect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
+ disconnect(cancelButton, SIGNAL(clicked()), this, SLOT(canceled()));
- if (_bytesToWrite == 0)
+ if (!_error)
{
accept();
QMessageBox::information(0, tr("PVS - File Transfer"),
@@ -188,12 +269,26 @@ void ClientFileSendDialog::close()
{
reject();
QMessageBox::warning(0, tr("PVS - File Transfer"),
- tr("File Transfer canceled!"));
+ tr("File Transfer canceled: %1").arg(_reason));
}
}
+void ClientFileSendDialog::canceled()
+{
+ if(_isMulticast)
+ {
+ _ifaceDBus->cancelOutgoingMulticastTransfer(_transferID);
+ }
+
+ _error = true;
+ _reason = tr("You clicked 'Cancel'");
+ close();
+}
+
void ClientFileSendDialog::error(QAbstractSocket::SocketError error)
{
+ _error = true;
+ _reason = tr("Socket Error");
qDebug("[%s] Socket error: %i", metaObject()->className(), error);
close();
}
@@ -210,6 +305,55 @@ QString ClientFileSendDialog::formatSize(qint64 size)
return QString("%1B").arg((qreal)size, 0, 'f',1);
}
+void ClientFileSendDialog::multicastTransferStarted(qulonglong transferID)
+{
+ qDebug() << "multicastTransferStarted(" << transferID << ")";
+ if (transferID != _transferID)
+ {
+ return;
+ }
+ labelStatus->setText("Started");
+}
+
+void ClientFileSendDialog::multicastTransferProgress(qulonglong transferID, qulonglong bytes, qulonglong of)
+{
+ qDebug() << "multicastTransferProgress(" << transferID << bytes << of << ")";
+ if (transferID != _transferID)
+ {
+ return;
+ }
+
+ if(bytes < of)
+ {
+ labelStatus->setText("Transferring");
+ progressBar->setRange(0, of);
+ progressBar->setValue(bytes);
+ }
+ else
+ {
+ labelStatus->setText("Waiting to finish");
+ progressBar->setRange(0, 0);
+ }
+
+ labelA->setText(formatSize(bytes));
+ labelB->setText(formatSize(of));
+}
+
+void ClientFileSendDialog::multicastTransferFinished(quint64 transferID)
+{
+ qDebug() << "multicastTransferFinished(" << transferID << ")";
+ qDebug("[%s] MulticastTransfer finished", metaObject()->className());
+ close();
+}
+
+void ClientFileSendDialog::multicastTransferFailed(quint64 transferID, QString const& reason)
+{
+ qDebug() << "multicastTransferFailed(" << transferID << reason << ")";
+ _error = true;
+ _reason = reason;
+ close();
+}
+
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@@ -233,6 +377,25 @@ ClientNicklistDialog::ClientNicklistDialog(QWidget *parent) :
listWidget->addItems(nicknames);
listWidget->setCurrentRow(0);
+
+ connect(sendToAllCheckBox, SIGNAL(stateChanged(int)), SLOT(sendToAllStateChanged(int)));
+
+ sendToAllCheckBox->setCheckState(Qt::Unchecked);
+ _isSendToAll = false;
+}
+
+void ClientNicklistDialog::sendToAllStateChanged(int state)
+{
+ if (state)
+ {
+ listWidget->setEnabled(false);
+ _isSendToAll = true;
+ }
+ else
+ {
+ listWidget->setEnabled(true);
+ _isSendToAll = false;
+ }
}
ClientNicklistDialog::~ClientNicklistDialog()