void Submit::senddata_finished(QNetworkReply *reply) { //emit add_log(LOG_INFO, "Submit::senddata_finished"); if ( reply->error() != QNetworkReply::NoError ) { nr_submit->disconnect(SIGNAL(uploadProgress(qint64, qint64))); nr_submit->deleteLater(); emit finished(false, tr("SUBMIT %1: Request failed, %2") .arg(SITE_NAME[index], reply->errorString())); return; } emit add_log(LOG_INFO, QString("SUBMIT: %1 Request succeeded") .arg(SITE_NAME[index])); QString result(reply->readAll()); emit add_log(LOG_INFO, QString("%1: Server response: %2") .arg(SITE_NAME[index], result)); if (result != "") { if (result.contains("no POST parameters")) { // Server problem - http://www.last.fm/forum/21716/_/201367 // "FAILED Plugin bug: Not all request variables are set - no POST parameters" // This if statement can be removed if/when fixed need_handshake = true; reset_tracks(); do_submit(); return; } else if (result.contains("BADSESSION")) { need_handshake = true; reset_tracks(); do_submit(); return; } else if (result.contains("FAILED")) { emit add_log(LOG_INFO, QString("%1: Submission FAILED").arg(SITE_NAME[index])); nr_submit->disconnect(SIGNAL(uploadProgress(qint64, qint64))); nr_submit->deleteLater(); emit finished(false, tr("%1: Server returned an error after sending data") .arg(SITE_NAME[index])); return; } else if (result.contains("OK")) { context.mutex->lock(); int i; int count = 0; for ( i = 0; i < entry_index.size(); i++ ) { int entry_num = entry_index.value(i); scrob_entry tmp = context.entries->at(entry_num); tmp.sent[index] = SENT_SUCCESS; context.entries->replace(entry_num, tmp); } for (i = 0; i < context.entries->size(); i++) { if (SENT_UNSENT == context.entries->at(i).sent[index]) count++; } context.mutex->unlock(); if (count > 0) do_submit(); else { emit add_log(LOG_DEBUG, QString("%1: Submission complete") .arg(SITE_NAME[index])); nr_submit->disconnect(SIGNAL(uploadProgress(qint64, qint64))); nr_submit->deleteLater(); nr_handshake->deleteLater(); submission_ok = true; emit finished(true, ""); } } } else { nr_submit->disconnect(SIGNAL(uploadProgress(qint64, qint64))); nr_submit->deleteLater(); emit finished(false, tr("%1: Empty result from server") .arg(SITE_NAME[index])); return; } }
void Submit::senddata() { //emit add_log(LOG_INFO, "Submit::senddata"); entry_index.clear(); QString data = "s=" + sessionid; // lock context.mutex->lock(); for ( int i = 0; i < context.entries->size(); i++ ) { scrob_entry tmp = context.entries->at(i); if (SENT_UNSENT == tmp.sent[index]) { entry_index.append(i); tmp.sent[index] = SENT_FAILED; context.entries->replace(i, tmp); // check length of musicbrainz id QString mbid = ""; if (tmp.mb_track_id.length() == 36) mbid = tmp.mb_track_id; QString tracknum = ""; if (tmp.tracknum != 0) tracknum = QString::number(tmp.tracknum); QString str_count = QString::number(entry_index.size() - 1); data += "&a[" + str_count + "]=" + QUrl::toPercentEncoding(tmp.artist) + "&t[" + str_count + "]=" + QUrl::toPercentEncoding(tmp.title) + "&b[" + str_count + "]=" + QUrl::toPercentEncoding(tmp.album) + "&m[" + str_count + "]=" + mbid + "&l[" + str_count + "]=" + QString::number(tmp.length) + "&i[" + str_count + "]=" + QString::number(tmp.when) + "&o[" + str_count + "]=P" + "&n[" + str_count + "]=" + tracknum + "&r[" + str_count + "]="; } // do we have enough tracks? if (entry_index.size() == 50) break; } context.mutex->unlock(); emit add_log(LOG_INFO, QString("entry_index: %1").arg(entry_index.size())); if (0 == entry_index.size()) { // should never be true... nr_submit->disconnect(SIGNAL(uploadProgress(qint64, qint64))); nr_submit->deleteLater(); emit finished(false, tr("%1: Error, attempted to send an empty submission!") .arg(SITE_NAME[index])); return; } data += "&portable=1"; // Magic from the official last.fm client source batch_current += entry_index.size(); emit progress(context.site_index, batch_current, batch_total); emit add_log(LOG_TRACE, QString("%1: Data: %2") .arg(SITE_NAME[index], data)); emit add_log(LOG_INFO, QString("%1: Submitting %2 entries") .arg(SITE_NAME[index]).arg(entry_index.size())); QNetworkRequest submit_handshake; submit_handshake.setUrl(submit_url); submit_handshake.setRawHeader("User-Agent", CLIENT_USERAGENT); // MUST have a content type, otherwise both last.fm and libre.fm will // reject the post. submit_handshake.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); QByteArray submit_data = QByteArray(data.toLocal8Bit()); nr_submit = nam_submit->post(submit_handshake, submit_data); }
void PropagateUploadFileQNAM::startNextChunk() { if (_propagator->_abortRequested.fetchAndAddRelaxed(0)) return; if (! _jobs.isEmpty() && _currentChunk + _startChunk >= _chunkCount - 1) { // Don't do parallel upload of chunk if this might be the last chunk because the server cannot handle that // https://github.com/owncloud/core/issues/11106 // We return now and when the _jobs will be finished we will proceed the last chunk return; } quint64 fileSize = _item._size; QMap<QByteArray, QByteArray> headers; headers["OC-Total-Length"] = QByteArray::number(fileSize); headers["OC-Async"] = "1"; headers["Content-Type"] = "application/octet-stream"; headers["X-OC-Mtime"] = QByteArray::number(qint64(_item._modtime)); if (!_item._etag.isEmpty() && _item._etag != "empty_etag" && _item._instruction != CSYNC_INSTRUCTION_NEW // On new files never send a If-Match ) { // We add quotes because the owncloud server always add quotes around the etag, and // csync_owncloud.c's owncloud_file_id always strip the quotes. headers["If-Match"] = '"' + _item._etag + '"'; } QString path = _item._file; UploadDevice *device = 0; if (_chunkCount > 1) { int sendingChunk = (_currentChunk + _startChunk) % _chunkCount; // XOR with chunk size to make sure everything goes well if chunk size change between runs uint transid = _transferId ^ chunkSize(); path += QString("-chunking-%1-%2-%3").arg(transid).arg(_chunkCount).arg(sendingChunk); headers["OC-Chunked"] = "1"; int currentChunkSize = chunkSize(); if (sendingChunk == _chunkCount - 1) { // last chunk currentChunkSize = (fileSize % chunkSize()); if( currentChunkSize == 0 ) { // if the last chunk pretents to be 0, its actually the full chunk size. currentChunkSize = chunkSize(); } } device = new UploadDevice(_file, chunkSize() * quint64(sendingChunk), currentChunkSize, &_propagator->_bandwidthManager); } else { device = new UploadDevice(_file, 0, fileSize, &_propagator->_bandwidthManager); } bool isOpen = true; if (!device->isOpen()) { isOpen = device->open(QIODevice::ReadOnly); } if( isOpen ) { PUTFileJob* job = new PUTFileJob(AccountManager::instance()->account(), _propagator->_remoteFolder + path, device, headers, _currentChunk); _jobs.append(job); job->setTimeout(_propagator->httpTimeout() * 1000); connect(job, SIGNAL(finishedSignal()), this, SLOT(slotPutFinished())); connect(job, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(slotUploadProgress(qint64,qint64))); connect(job, SIGNAL(uploadProgress(qint64,qint64)), device, SLOT(slotJobUploadProgress(qint64,qint64))); connect(job, SIGNAL(destroyed(QObject*)), this, SLOT(slotJobDestroyed(QObject*))); job->start(); _propagator->_activeJobs++; _currentChunk++; QByteArray env = qgetenv("OWNCLOUD_PARALLEL_CHUNK"); bool parallelChunkUpload = env=="true" || env =="1";; if (_currentChunk + _startChunk >= _chunkCount - 1) { // Don't do parallel upload of chunk if this might be the last chunk because the server cannot handle that // https://github.com/owncloud/core/issues/11106 parallelChunkUpload = false; } if (parallelChunkUpload && (_propagator->_activeJobs < _propagator->maximumActiveJob()) && _currentChunk < _chunkCount ) { startNextChunk(); } if (!parallelChunkUpload || _chunkCount - _currentChunk <= 0) { emitReady(); } } else {
void PropagateUploadFile::startNextChunk() { if (_propagator->_abortRequested.fetchAndAddRelaxed(0)) return; if (! _jobs.isEmpty() && _currentChunk + _startChunk >= _chunkCount - 1) { // Don't do parallel upload of chunk if this might be the last chunk because the server cannot handle that // https://github.com/owncloud/core/issues/11106 // We return now and when the _jobs are finished we will proceed with the last chunk // NOTE: Some other parts of the code such as slotUploadProgress also assume that the last chunk // is sent last. return; } quint64 fileSize = _item->_size; QMap<QByteArray, QByteArray> headers; headers["OC-Total-Length"] = QByteArray::number(fileSize); headers["OC-Async"] = "1"; headers["OC-Chunk-Size"]= QByteArray::number(quint64(chunkSize())); headers["Content-Type"] = "application/octet-stream"; headers["X-OC-Mtime"] = QByteArray::number(qint64(_item->_modtime)); if(_item->_file.contains(".sys.admin#recall#")) { // This is a file recall triggered by the admin. Note: the // recall list file created by the admin and downloaded by the // client (.sys.admin#recall#) also falls into this category // (albeit users are not supposed to mess up with it) // We use a special tag header so that the server may decide to store this file away in some admin stage area // And not directly in the user's area (which would trigger redownloads etc). headers["OC-Tag"] = ".sys.admin#recall#"; } if (!_item->_etag.isEmpty() && _item->_etag != "empty_etag" && _item->_instruction != CSYNC_INSTRUCTION_NEW // On new files never send a If-Match && _item->_instruction != CSYNC_INSTRUCTION_TYPE_CHANGE && !_deleteExisting ) { // We add quotes because the owncloud server always adds quotes around the etag, and // csync_owncloud.c's owncloud_file_id always strips the quotes. headers["If-Match"] = '"' + _item->_etag + '"'; } QString path = _item->_file; UploadDevice *device = new UploadDevice(&_propagator->_bandwidthManager); qint64 chunkStart = 0; qint64 currentChunkSize = fileSize; bool isFinalChunk = false; if (_chunkCount > 1) { int sendingChunk = (_currentChunk + _startChunk) % _chunkCount; // XOR with chunk size to make sure everything goes well if chunk size changes between runs uint transid = _transferId ^ chunkSize(); qDebug() << "Upload chunk" << sendingChunk << "of" << _chunkCount << "transferid(remote)=" << transid; path += QString("-chunking-%1-%2-%3").arg(transid).arg(_chunkCount).arg(sendingChunk); headers["OC-Chunked"] = "1"; chunkStart = chunkSize() * quint64(sendingChunk); currentChunkSize = chunkSize(); if (sendingChunk == _chunkCount - 1) { // last chunk currentChunkSize = (fileSize % chunkSize()); if( currentChunkSize == 0 ) { // if the last chunk pretends to be 0, its actually the full chunk size. currentChunkSize = chunkSize(); } isFinalChunk = true; } } else { // if there's only one chunk, it's the final one isFinalChunk = true; } if (isFinalChunk && !_transmissionChecksumType.isEmpty()) { headers[checkSumHeaderC] = makeChecksumHeader( _transmissionChecksumType, _transmissionChecksum); } const QString fileName = _propagator->getFilePath(_item->_file); if (! device->prepareAndOpen(fileName, chunkStart, currentChunkSize)) { qDebug() << "ERR: Could not prepare upload device: " << device->errorString(); // If the file is currently locked, we want to retry the sync // when it becomes available again. if (FileSystem::isFileLocked(fileName)) { emit _propagator->seenLockedFile(fileName); } // Soft error because this is likely caused by the user modifying his files while syncing abortWithError( SyncFileItem::SoftError, device->errorString() ); delete device; return; } // job takes ownership of device via a QScopedPointer. Job deletes itself when finishing PUTFileJob* job = new PUTFileJob(_propagator->account(), _propagator->_remoteFolder + path, device, headers, _currentChunk); _jobs.append(job); connect(job, SIGNAL(finishedSignal()), this, SLOT(slotPutFinished())); connect(job, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(slotUploadProgress(qint64,qint64))); connect(job, SIGNAL(uploadProgress(qint64,qint64)), device, SLOT(slotJobUploadProgress(qint64,qint64))); connect(job, SIGNAL(destroyed(QObject*)), this, SLOT(slotJobDestroyed(QObject*))); job->start(); _propagator->_activeJobList.append(this); _currentChunk++; bool parallelChunkUpload = true; QByteArray env = qgetenv("OWNCLOUD_PARALLEL_CHUNK"); if (!env.isEmpty()) { parallelChunkUpload = env != "false" && env != "0"; } else { int versionNum = _propagator->account()->serverVersionInt(); if (versionNum < 0x080003) { // Disable parallel chunk upload severs older than 8.0.3 to avoid too many // internal sever errors (#2743, #2938) parallelChunkUpload = false; } } if (_currentChunk + _startChunk >= _chunkCount - 1) { // Don't do parallel upload of chunk if this might be the last chunk because the server cannot handle that // https://github.com/owncloud/core/issues/11106 parallelChunkUpload = false; } if (parallelChunkUpload && (_propagator->_activeJobList.count() < _propagator->maximumActiveJob()) && _currentChunk < _chunkCount ) { startNextChunk(); } if (!parallelChunkUpload || _chunkCount - _currentChunk <= 0) { emit ready(); } }
void Utils::start() { if(quee.isEmpty()) { //qDebug() << "quee.isEmpty"; return; } RequestData data = quee.takeFirst(); QUrl url(data.url); QNetworkRequest req(url); //qDebug() << "Authorization: " << data.auth; //qDebug() << "Url: " << url.toEncoded(); req.setRawHeader("Authorization", data.auth.toAscii()); if(data.isDownload) { QNetworkReply* reply = _nam->get(req); connect(reply,SIGNAL(finished()),this,SLOT(downloadFinished())); connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadProgress(qint64,qint64))); connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(error(QNetworkReply::NetworkError))); cur_reply = reply; cur_folder = data.folder; cur_filename = data.filename; cur_size = data.size; isFinished = false; emit downloadStarted(data.filename); //qDebug() << "startDownload, filename: " << cur_filename; } else { QString filepath = data.folder + "/" + data.filename; //qDebug() << "filapath: " << filepath; cur_file = new QFile(filepath); if(cur_file->open(QIODevice::ReadOnly)) { QNetworkReply* reply = _nam->put(req,cur_file); connect(reply,SIGNAL(finished()),this,SLOT(uploadFinished())); connect(reply,SIGNAL(uploadProgress(qint64,qint64)),this,SLOT(uploadProgress(qint64,qint64))); connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(error(QNetworkReply::NetworkError))); cur_reply = reply; cur_folder = data.folder; cur_filename = data.filename; cur_size = cur_file->size(); isFinished = false; emit uploadStarted(data.filename); //qDebug() << "size:" << cur_file->size(); } else { qDebug() << "error: file not open!"; } } }
void PropagateUploadFileQNAM::startNextChunk() { if (_propagator->_abortRequested.fetchAndAddRelaxed(0)) return; if (! _jobs.isEmpty() && _currentChunk + _startChunk >= _chunkCount - 1) { // Don't do parallel upload of chunk if this might be the last chunk because the server cannot handle that // https://github.com/owncloud/core/issues/11106 // We return now and when the _jobs will be finished we will proceed the last chunk // NOTE: Some other part of the code such as slotUploadProgress assume also that the last chunk // is sent last. return; } quint64 fileSize = _item._size; QMap<QByteArray, QByteArray> headers; headers["OC-Total-Length"] = QByteArray::number(fileSize); headers["OC-Async"] = "1"; headers["OC-Chunk-Size"]= QByteArray::number(quint64(chunkSize())); headers["Content-Type"] = "application/octet-stream"; headers["X-OC-Mtime"] = QByteArray::number(qint64(_item._modtime)); if (!_item._etag.isEmpty() && _item._etag != "empty_etag" && _item._instruction != CSYNC_INSTRUCTION_NEW // On new files never send a If-Match ) { // We add quotes because the owncloud server always add quotes around the etag, and // csync_owncloud.c's owncloud_file_id always strip the quotes. headers["If-Match"] = '"' + _item._etag + '"'; } QString path = _item._file; UploadDevice *device = new UploadDevice(&_propagator->_bandwidthManager); qint64 chunkStart = 0; qint64 currentChunkSize = fileSize; if (_chunkCount > 1) { int sendingChunk = (_currentChunk + _startChunk) % _chunkCount; // XOR with chunk size to make sure everything goes well if chunk size change between runs uint transid = _transferId ^ chunkSize(); path += QString("-chunking-%1-%2-%3").arg(transid).arg(_chunkCount).arg(sendingChunk); headers["OC-Chunked"] = "1"; chunkStart = chunkSize() * quint64(sendingChunk); currentChunkSize = chunkSize(); if (sendingChunk == _chunkCount - 1) { // last chunk currentChunkSize = (fileSize % chunkSize()); if( currentChunkSize == 0 ) { // if the last chunk pretents to be 0, its actually the full chunk size. currentChunkSize = chunkSize(); } } } if (! device->prepareAndOpen(_propagator->getFilePath(_item._file), chunkStart, currentChunkSize)) { qDebug() << "ERR: Could not prepare upload device: " << device->errorString(); // Soft error because this is likely caused by the user modifying his files while syncing abortWithError( SyncFileItem::SoftError, device->errorString() ); delete device; return; } // job takes ownership of device via a QScopedPointer. Job deletes itself when finishing PUTFileJob* job = new PUTFileJob(_propagator->account(), _propagator->_remoteFolder + path, device, headers, _currentChunk); _jobs.append(job); connect(job, SIGNAL(finishedSignal()), this, SLOT(slotPutFinished())); connect(job, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(slotUploadProgress(qint64,qint64))); connect(job, SIGNAL(uploadProgress(qint64,qint64)), device, SLOT(slotJobUploadProgress(qint64,qint64))); connect(job, SIGNAL(destroyed(QObject*)), this, SLOT(slotJobDestroyed(QObject*))); job->start(); _propagator->_activeJobs++; _currentChunk++; bool parallelChunkUpload = true; QByteArray env = qgetenv("OWNCLOUD_PARALLEL_CHUNK"); if (!env.isEmpty()) { parallelChunkUpload = env != "false" && env != "0"; } else { auto version = _propagator->account()->serverVersion(); auto components = version.split('.'); int versionNum = (components.value(0).toInt() << 16) + (components.value(1).toInt() << 8) + components.value(2).toInt(); if (versionNum < 0x080003) { // Disable parallel chunk upload severs older than 8.0.3 to avoid too many // internal sever errors (#2743, #2938) parallelChunkUpload = false; } } if (_currentChunk + _startChunk >= _chunkCount - 1) { // Don't do parallel upload of chunk if this might be the last chunk because the server cannot handle that // https://github.com/owncloud/core/issues/11106 parallelChunkUpload = false; } if (parallelChunkUpload && (_propagator->_activeJobs < _propagator->maximumActiveJob()) && _currentChunk < _chunkCount ) { startNextChunk(); } if (!parallelChunkUpload || _chunkCount - _currentChunk <= 0) { emit ready(); } }
void TtbDialog::requestUpload() { assert(sessionId.length() > 0 ); progressLabel->setText(tr("preparing upload ...")); QHttpMultiPart *body = new QHttpMultiPart( QHttpMultiPart::FormDataType ); QHttpPart textPart; textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"upload_submit\"")); textPart.setBody("hrm"); body->append( textPart ); QString fname = context->athlete->home.absoluteFilePath(".ttbupload.pwx" ); QFile *uploadFile = new QFile( fname ); uploadFile->setParent(body); PwxFileReader reader; reader.writeRideFile(context, ride->ride(), *uploadFile ); progressBar->setValue(12); int limit = proMember ? 8 * 1024 * 1024 : 4 * 1024 * 1024; if( uploadFile->size() >= limit ){ progressLabel->setText(tr("temporary file too large for upload: %1 > %1 bytes") .arg(uploadFile->size()) .arg(limit) ); closeButton->setText(tr("&Close")); return; } QHttpPart filePart; filePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/occtet-stream")); filePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"file\"; filename=\"gc-upload-ttb.pwx\"")); uploadFile->open(QIODevice::ReadOnly); filePart.setBodyDevice(uploadFile); body->append( filePart ); progressLabel->setText(tr("uploading ...")); currentRequest = reqUpload; QUrl url( TTB_URL + "/file/upload" ); url.addQueryItem( "view", "xml" ); url.addQueryItem( "sso", sessionId ); QNetworkRequest request = QNetworkRequest(url); request.setRawHeader( "Accept-Encoding", "identity" ); request.setRawHeader( "Accept", "application/xml" ); request.setRawHeader( "Accept-Charset", "utf-8" ); QNetworkReply *reply = networkMgr.post( request, body ); body->setParent( reply ); connect(reply, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(uploadProgress(qint64,qint64))); }
void PendingUpload::HandleGotServer (QNetworkReply *reply) { if (!Conn_->CheckFinishedReply (reply)) return; const auto& json = Util::ParseJson (reply, Q_FUNC_INFO); try { Conn_->CheckReplyData (json, reply); } catch (const VkConnection::RecoverableException&) { return; } catch (const VkConnection::UnrecoverableException& ex) { emit errorAppeared (TEProtocolError, tr ("Unable to get upload server from VKontakte, protocol error %1: %2.") .arg (ex.GetCode ()) .arg (ex.GetMessage ())); emit stateChanged (TSFinished); return; } Acc_->GetLogger () << "got upload server:" << json; const QUrl uploadUrl { json.toMap () ["response"].toMap () ["upload_url"].toByteArray () }; if (!uploadUrl.isValid ()) { emit errorAppeared (TEProtocolError, tr ("Unable to get upload server from VKontakte")); emit stateChanged (TSFinished); return; } emit stateChanged (TSTransfer); const auto multipart = new QHttpMultiPart { QHttpMultiPart::FormDataType }; QHttpPart filePart; filePart.setHeader (QNetworkRequest::ContentDispositionHeader, QString ("form-data; name=\"file\"; filename=\"%1\"") .arg (QFileInfo { Path_ }.fileName ())); const auto file = new QFile { Path_ }; file->open (QIODevice::ReadOnly); filePart.setBodyDevice (file); file->setParent (multipart); multipart->append (filePart); const auto nam = Acc_->GetCoreProxy ()->GetNetworkAccessManager (); const auto upReply = nam->post (QNetworkRequest { uploadUrl }, multipart); connect (upReply, SIGNAL (uploadProgress (qint64, qint64)), this, SIGNAL (transferProgress (qint64, qint64))); connect (upReply, SIGNAL (finished ()), this, SLOT (handleUploadFinished ())); multipart->setParent (upReply); }
void imgUploader::onUploadProgress(qint64 uploaded, qint64 total) { emit uploadProgress( uploaded, total); }
MainWindow::MainWindow(Eros *eros, QWidget *parent ) : QMainWindow(parent) { QFontDatabase::addApplicationFont(":/font/NotoSans-Regular"); QFontDatabase::addApplicationFont(":/font/NotoSans-Bold"); QFontDatabase::addApplicationFont(":/font/NotoSans-Italic"); QFontDatabase::addApplicationFont(":/font/NotoSans-BoldItalic"); QFontDatabase::addApplicationFont(":/font/Gobold"); QFontDatabase::addApplicationFont(":/font/Gobold-bold"); QFontDatabase::addApplicationFont(":/font/Gobold-thin"); QFile version(":/data/version_info"); if(!version.open(QIODevice::ReadOnly)) { this->local_version_ = 1; } else { QByteArray data = version.readAll(); QStringList tokens = QString::fromUtf8(data).split('|'); this->local_version_ = tokens[0].toInt(); version.close(); } ui.setupUi(this); ui.centralWidget->setMouseTracking(true); this->setWindowTitle(tr("Alpha Version %1").arg(this->local_version_)); setUiEnabled(false); this->eros_ = eros; this->config_ = new Config(this); this->connection_timer_ = new QTimer(this); this->matchmaking_timer_ = new QTimer(this); this->matchmaking_timer_->setInterval(500); this->matchmaking_start_ = new QTime(); this->matchmaking_result_time_ = new QTime(); this->long_process_start_time_ = new QTime(); this->watcher_ = new DirectoryWatcher(this); this->watches_ = QList<DirectoryWatch*>(); this->update_checker_nam_ = new QNetworkAccessManager(this); this->update_timer_ = new QTimer(this); this->long_process_timer_ = new QTimer(this); this->tray_icon_ = new QSystemTrayIcon(this); this->tray_icon_menu_ = new QMenu(this); this->preview_loader_nam_ = new QNetworkAccessManager(this); this->preview_cache_ = QMap<QString, QPixmap*>(); this->upload_queue_ = QMap<QString, QTime*>(); this->upload_queue_timer_ = new QTimer(this); tray_icon_action_show_ = new QAction("Hide Eros", this); tray_icon_action_close_ = new QAction("Close Eros", this); QObject::connect(tray_icon_action_show_, SIGNAL(triggered()), this, SLOT(toggleWindow())); QObject::connect(tray_icon_action_close_, SIGNAL(triggered()), qApp, SLOT(quit())); QObject::connect(this->tray_icon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason))); this->tray_icon_->setIcon(QIcon(":/img/client/icons/icon_32x32")); this->tray_icon_menu_->addAction(tray_icon_action_show_); this->tray_icon_menu_->addAction(tray_icon_action_close_); this->tray_icon_->setContextMenu(this->tray_icon_menu_); #if !defined(Q_OS_MAC) title_bar_ = ErosTitleBar::addToLayout(this, ui.verticalLayout); title_bar_->setMenu(this->tray_icon_menu_); #endif // File watcher QObject::connect(this->watcher_, SIGNAL(added(const QString &, const QString &)), this, SLOT(fileAdded(const QString &, const QString&))); // Update checker QObject::connect(update_checker_nam_, SIGNAL(finished(QNetworkReply*)), this, SLOT(updateCheckerFinished(QNetworkReply*))); QObject::connect(this->update_timer_, SIGNAL(timeout()), this, SLOT(updateCheckerTimerWorker())); //Preview loader QObject::connect(preview_loader_nam_, SIGNAL(finished(QNetworkReply*)), this, SLOT(previewDownloadFinished(QNetworkReply*))); // Set up Eros signals /// Eros Signals QObject::connect(eros_, SIGNAL(stateChanged(ErosState)), this, SLOT(erosStateChanged(ErosState))); QObject::connect(eros_, SIGNAL(connectionError(QAbstractSocket::SocketError, const QString)), this, SLOT(erosConnectionError(QAbstractSocket::SocketError, const QString))); QObject::connect(eros_, SIGNAL(connected()), this, SLOT(erosConnected())); QObject::connect(eros_, SIGNAL(disconnected()), this, SLOT(erosDisconnected())); QObject::connect(eros_, SIGNAL(authenticationFailed()), this, SLOT(erosAuthenticationFailed())); QObject::connect(eros_, SIGNAL(alreadyLoggedIn()), this, SLOT(erosAlreadyLoggedIn())); QObject::connect(eros_, SIGNAL(broadcastAlert(const QString, int)), this, SLOT(erosBroadcastAlert(const QString, int))); QObject::connect(eros_, SIGNAL(chatRoomAdded(ChatRoom*)), this, SLOT(erosChatRoomAdded(ChatRoom*))); QObject::connect(eros_, SIGNAL(chatRoomRemoved(ChatRoom*)), this, SLOT(erosChatRoomRemoved(ChatRoom*))); QObject::connect(eros_, SIGNAL(chatRoomJoined(ChatRoom*)), this, SLOT(erosChatRoomJoined(ChatRoom*))); QObject::connect(eros_, SIGNAL(chatRoomLeft(ChatRoom*)), this, SLOT(erosChatRoomLeft(ChatRoom*))); QObject::connect(eros_, SIGNAL(chatMessageReceieved(User*, const QString)), this, SLOT(erosChatMessageReceieved(User*, const QString))); QObject::connect(eros_, SIGNAL(localUserUpdated(LocalUser*)), this, SLOT(erosLocalUserUpdated(LocalUser*))); QObject::connect(eros_, SIGNAL(matchmakingStateChanged(ErosMatchmakingState)), this, SLOT(erosMatchmakingStateChanged(ErosMatchmakingState))); QObject::connect(eros_, SIGNAL(matchmakingMatchFound(MatchmakingMatch *)), this, SLOT(erosMatchmakingMatchFound(MatchmakingMatch *))); //QObject::connect(eros_, SIGNAL(regionStatsUpdated(ErosRegion, int)), this, SLOT(erosRegionStatsUpdated(ErosRegion, int))); QObject::connect(eros_, SIGNAL(statsUpdated(int, int)), this, SLOT(erosStatsUpdated(int, int))); QObject::connect(eros_, SIGNAL(replayUploadError(ErosError)), this, SLOT(erosReplayUploadError(ErosError))); QObject::connect(eros_, SIGNAL(replayUploaded()), this, SLOT(erosReplayUploaded())); QObject::connect(eros_, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(erosUploadProgress(qint64, qint64))); QObject::connect(eros_, SIGNAL(longProcessStateChanged(ErosLongProcessState)), this, SLOT(erosLongProcessStateChanged(ErosLongProcessState))); QObject::connect(eros_, SIGNAL(drawRequested()), this, SLOT(erosDrawRequested())); QObject::connect(eros_, SIGNAL(drawRequestFailed()), this, SLOT(erosDrawRequestFailed())); QObject::connect(eros_, SIGNAL(noShowRequested()), this, SLOT(erosNoShowRequested())); QObject::connect(eros_, SIGNAL(noShowRequestFailed()), this, SLOT(erosNoShowRequestFailed())); QObject::connect(eros_, SIGNAL(acknowledgeLongProcessFailed()), this, SLOT(erosAcknowledgeLongProcessFailed())); QObject::connect(eros_, SIGNAL(acknowledgedLongProcess()), this, SLOT(erosAcknowledgedLongProcess())); QObject::connect(eros_, SIGNAL(vetoesUpdated()), this, SLOT(erosVetoesUpdated())); QObject::connect(eros_, SIGNAL(toggleVetoFailed(Map*,ErosError)), this, SLOT(erosToggleVetoFailed(Map*,ErosError))); /// Eros Slots QObject::connect(this, SIGNAL(connectToEros(const QString, const QString, const QString)), eros_, SLOT(connectToEros(const QString, const QString, const QString))); QObject::connect(this, SIGNAL(disconnectFromEros()), eros_, SLOT(disconnectFromEros())); QObject::connect(ui.btnRefreshChats, SIGNAL(clicked()), eros_, SLOT(refreshChatRooms())); QObject::connect(this, SIGNAL(joinChatRoom(ChatRoom *, const QString)), eros_, SLOT(joinChatRoom(ChatRoom *, const QString))); QObject::connect(this, SIGNAL(leaveChatRoom(ChatRoom *)), eros_, SLOT(leaveChatRoom(ChatRoom *))); QObject::connect(this, SIGNAL(queueMatchmaking(ErosRegion, int)), eros_, SLOT(queueMatchmaking(ErosRegion, int))); QObject::connect(this, SIGNAL(queueMatchmaking(ErosRegionList, int)), eros_, SLOT(queueMatchmaking(ErosRegionList, int))); QObject::connect(this, SIGNAL(dequeueMatchmaking()), eros_, SLOT(dequeueMatchmaking())); QObject::connect(this, SIGNAL(forfeitMatchmaking()), eros_, SLOT(forfeitMatchmaking())); QObject::connect(this, SIGNAL(uploadReplay(QIODevice*)), eros_, SLOT(uploadReplay(QIODevice*))); QObject::connect(this, SIGNAL(uploadReplay(const QString)), eros_, SLOT(uploadReplay(const QString))); QObject::connect(this, SIGNAL(requestDraw()), eros_, SLOT(requestDraw())); QObject::connect(this, SIGNAL(requestNoShow()), eros_, SLOT(requestNoShow())); QObject::connect(this, SIGNAL(acknowledgeLongProcess(bool)), eros_, SLOT(acknowledgeLongProcess(bool))); QObject::connect(this, SIGNAL(toggleVeto(Map*)), eros_, SLOT(toggleVeto(Map*))); // timers QObject::connect(this->connection_timer_, SIGNAL(timeout()), this, SLOT(connectionTimerWorker())); QObject::connect(this->matchmaking_timer_, SIGNAL(timeout()), this, SLOT(matchmakingTimerWorker())); QObject::connect(this->long_process_timer_, SIGNAL(timeout()), this, SLOT(longProcessTimerWorker())); QObject::connect(this->upload_queue_timer_, SIGNAL(timeout()), this, SLOT(uploadTimerWorker())); this->long_process_timer_->setInterval(250); // UI Stuff settings_window_ = nullptr; bnetsettings_window_ = nullptr; // Remove the close box from the first 2 tabs. // On mac it's LeftSide. Assuming RightSide causes a nullptr. for (int i = 0; i < 3; i++) { QWidget *tab = ui.tabContainer->tabBar()->tabButton(i, QTabBar::RightSide); if (tab != nullptr) tab->resize(0, 0); tab = ui.tabContainer->tabBar()->tabButton(i, QTabBar::LeftSide); if (tab != nullptr) tab->resize(0, 0); } ui.tabContainer->tabBar()->setUsesScrollButtons(true); QObject::connect(ui.tabContainer, SIGNAL(tabCloseRequested(int)), this, SLOT(tabContainer_tabCloseRequested(int))); QObject::connect(ui.tabContainer, SIGNAL(currentChanged(int)), this, SLOT(tabContainer_currentChanged(int))); QObject::connect(ui.lblBottomMenu, SIGNAL(linkActivated(const QString &)), this, SLOT(label_linkActivated(const QString&))); QObject::connect(ui.btnJoinRoom, SIGNAL(clicked()), this, SLOT(btnJoinRoom_pressed())); QObject::connect(ui.lstChats, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(lstChats_currentItemChanged(QListWidgetItem *, QListWidgetItem *))); QObject::connect(ui.lstChats, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(lstChats_itemDoubleClicked(QListWidgetItem*))); QObject::connect(ui.cmbRegion, SIGNAL(currentIndexChanged(int)), this, SLOT(cmbRegion_currentIndexChanged(int))); QObject::connect(ui.cmbMapRegion, SIGNAL(currentIndexChanged(int)), this, SLOT(cmbMapRegion_currentIndexChanged(int))); QObject::connect(ui.btnQueue, SIGNAL(clicked()), this, SLOT(btnQueue_pressed())); QObject::connect(ui.btnDraw, SIGNAL(clicked()), this, SLOT(btnDraw_pressed())); QObject::connect(ui.btnNoShow, SIGNAL(clicked()), this, SLOT(btnNoShow_pressed())); QObject::connect(ui.lstMaps, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(lstMaps_currentItemChanged(QListWidgetItem *, QListWidgetItem *))); QObject::connect(ui.btnToggleVeto, SIGNAL(clicked()), this, SLOT(btnToggleVeto_clicked())); QObject::connect(ui.chkQueueRegion, SIGNAL(stateChanged(int)), this, SLOT(chkQueueRegion_stateChanged(int))); #if !defined(Q_OS_MAC) this->tray_icon_->show(); #endif // The user should be prevented from emptying invalid values in the settings dialog. if (this->config_->profiles().count() == 0) { QMessageBox::information(this, "Eros", tr("Welcome to Eros! You need to configure some settings in order to continue. The settings window will now open.")); openSettings(); } else { this->connection_timer_->setInterval(500); this->connection_timer_->start(); } QTimer::singleShot(0, this, SLOT(updateCheckerTimerWorker())); this->update_timer_->setInterval(1000 * 60 * 10); this->update_timer_->start(); notification_sound_ = new QSound(":/sound/notification", this); }
void Plugin::HandleTransfer (quint64 sent, quint64 total) { emit uploadProgress (sent, total); }