/** * Return the mimetype basing on the file extension * By default, the mimetype returns is image/jpeg * * @return QString the mimetype * @access private */ QString ImageShackUploader::mimeType(QString imagePath) { QFileInfo imageInfos(imagePath); QHashIterator<QString, QStringList> h(this->mimeTypeList()); while (h.hasNext()) { h.next(); if(h.value().contains(imageInfos.suffix())) return h.key(); } return QString("image/jpeg"); }
int LightTableThumbBar::countItems() const { return imageInfos().count(); }
/** * Upload an image. This method is called by * userUploadImage and anonymousUploadImage * methods * * @access public */ void ImageShackUploader::sendImage(ImageShackObject * imageToUpload , QHash<QString, QString> headers) { QString imagePath = imageToUpload->getObjectPath(); QFile image(imagePath); QFileInfo imageInfos(imagePath); QNetworkAccessManager * manager = new QNetworkAccessManager; QNetworkRequest request(this->imageUploadUrl); QByteArray boundary = "IMAGESHACKUPLOADER"; QByteArray cr = "\r\n"; QByteArray data; if(!image.open(QIODevice::ReadOnly)) { if(uploadAborted==false) { emit uploadError(ImageShackError::FailedOpeningTheFile); this->abortUploads(); } return; } // build of the header data.append("--" + boundary + cr); data.append("Content-Disposition: form-data; "); data.append( "name=\"fileupload\"; filename=\"" + imageInfos.absoluteFilePath() + "\";" + cr); data.append("Content-Type: " + this->mimeType(imagePath) + cr + cr); // insertion of the image data.append(image.readAll() + cr); image.close(); // build the footer QHashIterator<QString, QString> h(headers); while (h.hasNext()) { h.next(); data.append("--" + boundary + cr); data.append("Content-Disposition: form-data; "); data.append("name=\"" + h.key() + "\"" + cr + cr); data.append(h.value() + cr); } data.append("--" + boundary + "--" + cr); request.setHeader(QNetworkRequest::ContentTypeHeader, "multipart/form-data; boundary=" + boundary); request.setHeader(QNetworkRequest::ContentLengthHeader, QString::number(data.size()).toAscii()); // manage proxy if(this->proxy != NULL) manager->setProxy(*this->proxy); this->fileBeingUploaded = imageToUpload; //this->uploadsProcessing = true; timeoutTimer->start(TIMEOUT); this->networkReply = manager->post(request, data); connect(this->networkReply, SIGNAL(finished()) , this , SLOT (imageUploaded())); connect(this->networkReply, SIGNAL(error(QNetworkReply::NetworkError)) , this , SLOT (manageUploadError(QNetworkReply::NetworkError))); connect(this->networkReply, SIGNAL(uploadProgress(qint64,qint64)), this , SLOT (manageUploadProgress(qint64,qint64))); connect(manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this , SLOT (manageAuthentificationRequired(QNetworkReply*,QAuthenticator*))); connect(manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this , SLOT (manageProxyAuthentificationRequired(QNetworkProxy,QAuthenticator*))); }
status_t TeamDebugger::Init(team_id teamID, thread_id threadID, bool stopInMain) { bool targetIsLocal = true; // TODO: Support non-local targets! // the first thing we want to do when running PostMessage(MSG_LOAD_SETTINGS); fTeamID = teamID; // create debugger interface fDebuggerInterface = new(std::nothrow) DebuggerInterface(fTeamID); if (fDebuggerInterface == NULL) return B_NO_MEMORY; status_t error = fDebuggerInterface->Init(); if (error != B_OK) return error; // create file manager fFileManager = new(std::nothrow) FileManager; if (fFileManager == NULL) return B_NO_MEMORY; error = fFileManager->Init(targetIsLocal); if (error != B_OK) return error; // create team debug info TeamDebugInfo* teamDebugInfo = new(std::nothrow) TeamDebugInfo( fDebuggerInterface, fDebuggerInterface->GetArchitecture(), fFileManager); if (teamDebugInfo == NULL) return B_NO_MEMORY; BReference<TeamDebugInfo> teamDebugInfoReference(teamDebugInfo); error = teamDebugInfo->Init(); if (error != B_OK) return error; // check whether the team exists at all // TODO: That should be done in the debugger interface! team_info teamInfo; error = get_team_info(fTeamID, &teamInfo); if (error != B_OK) return error; // create a team object fTeam = new(std::nothrow) ::Team(fTeamID, fDebuggerInterface, fDebuggerInterface->GetArchitecture(), teamDebugInfo, teamDebugInfo); if (fTeam == NULL) return B_NO_MEMORY; error = fTeam->Init(); if (error != B_OK) return error; fTeam->SetName(teamInfo.args); // TODO: Set a better name! fTeam->AddListener(this); // init thread handler table error = fThreadHandlers.Init(); if (error != B_OK) return error; // create image handler table fImageHandlers = new(std::nothrow) ImageHandlerTable; if (fImageHandlers == NULL) return B_NO_MEMORY; error = fImageHandlers->Init(); if (error != B_OK) return error; // create our worker fWorker = new(std::nothrow) Worker; if (fWorker == NULL) return B_NO_MEMORY; error = fWorker->Init(); if (error != B_OK) return error; // create the breakpoint manager fBreakpointManager = new(std::nothrow) BreakpointManager(fTeam, fDebuggerInterface); if (fBreakpointManager == NULL) return B_NO_MEMORY; error = fBreakpointManager->Init(); if (error != B_OK) return error; // create the memory block manager fMemoryBlockManager = new(std::nothrow) TeamMemoryBlockManager(); if (fMemoryBlockManager == NULL) return B_NO_MEMORY; error = fMemoryBlockManager->Init(); if (error != B_OK) return error; // set team debugging flags fDebuggerInterface->SetTeamDebuggingFlags( B_TEAM_DEBUG_THREADS | B_TEAM_DEBUG_IMAGES); // get the initial state of the team AutoLocker< ::Team> teamLocker(fTeam); ThreadHandler* mainThreadHandler = NULL; { BObjectList<ThreadInfo> threadInfos(20, true); status_t error = fDebuggerInterface->GetThreadInfos(threadInfos); for (int32 i = 0; ThreadInfo* info = threadInfos.ItemAt(i); i++) { ::Thread* thread; error = fTeam->AddThread(*info, &thread); if (error != B_OK) return error; ThreadHandler* handler = new(std::nothrow) ThreadHandler(thread, fWorker, fDebuggerInterface, fBreakpointManager); if (handler == NULL) return B_NO_MEMORY; fThreadHandlers.Insert(handler); if (thread->IsMainThread()) mainThreadHandler = handler; handler->Init(); } } Image* appImage = NULL; { BObjectList<ImageInfo> imageInfos(20, true); status_t error = fDebuggerInterface->GetImageInfos(imageInfos); for (int32 i = 0; ImageInfo* info = imageInfos.ItemAt(i); i++) { Image* image; error = _AddImage(*info, &image); if (error != B_OK) return error; if (image->Type() == B_APP_IMAGE) appImage = image; ImageDebugInfoRequested(image); } } // create the debug event listener char buffer[128]; snprintf(buffer, sizeof(buffer), "team %ld debug listener", fTeamID); fDebugEventListener = spawn_thread(_DebugEventListenerEntry, buffer, B_NORMAL_PRIORITY, this); if (fDebugEventListener < 0) return fDebugEventListener; resume_thread(fDebugEventListener); // run looper thread_id looperThread = Run(); if (looperThread < 0) return looperThread; // init the UI error = fUserInterface->Init(fTeam, this); if (error != B_OK) { ERROR("Error: Failed to init the UI: %s\n", strerror(error)); return error; } // if requested, stop the given thread if (threadID >= 0) { if (stopInMain) { SymbolInfo symbolInfo; if (appImage != NULL && mainThreadHandler != NULL && fDebuggerInterface->GetSymbolInfo( fTeam->ID(), appImage->ID(), "main", B_SYMBOL_TYPE_TEXT, symbolInfo) == B_OK) { mainThreadHandler->SetBreakpointAndRun(symbolInfo.Address()); } } else { debug_thread(threadID); // TODO: Superfluous, if the thread is already stopped. } } fListener->TeamDebuggerStarted(this); return B_OK; }