PersonView::PersonView( PolkaModel *model, QWidget *parent ) : QWidget( parent ), m_model( model ), m_dirWatch( 0 ) { QBoxLayout *topLayout = new QVBoxLayout( this ); m_webView = new QWebView; topLayout->addWidget( m_webView ); m_webView->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks ); connect( m_webView->page(), SIGNAL( linkClicked( const QUrl & ) ), SLOT( slotLinkClicked( const QUrl & ) ) ); m_addPictureWidget = new AddPictureWidget( m_model ); topLayout->addWidget( m_addPictureWidget ); m_addPictureWidget->hide(); connect( m_addPictureWidget, SIGNAL( grabPicture() ), SLOT( grabPicture() ) ); connect( m_addPictureWidget, SIGNAL( gotPicture( ImageLoader * ) ), SLOT( addPicture( ImageLoader * ) ) ); m_pictureSelectorControls = new PictureSelectorControls( m_model ); topLayout->addWidget( m_pictureSelectorControls ); m_pictureSelectorControls->hide(); QHBoxLayout *pictureSelectorLayout = new QHBoxLayout; topLayout->addLayout( pictureSelectorLayout ); m_pictureSelector = new PictureSelector( m_model ); pictureSelectorLayout->addWidget( m_pictureSelector ); connect( m_pictureSelector, SIGNAL( addPicture() ), SLOT( addPicture() ) ); connect( m_pictureSelector, SIGNAL( pictureSelected( const Polka::Picture & ) ), SLOT( selectPicture( const Polka::Picture & ) ) ); pictureSelectorLayout->addStretch( 1 ); connect( m_model, SIGNAL( identityChanged( const Polka::Identity & ) ), SLOT( showIdentity( const Polka::Identity & ) ) ); }
bool VideoPreview::extractImages() { VideoInfo i = getInfo(mplayer_bin, prop.input_video); int length = i.length; if (length == 0) { if (error_message.isEmpty()) error_message = tr("The length of the video is 0"); return false; } // Create a temporary directory QDir d(QDir::tempPath()); if (!d.exists(output_dir)) { if (!d.mkpath(output_dir)) { qDebug("VideoPreview::extractImages: error: can't create '%s'", full_output_dir.toUtf8().constData()); error_message = tr("The temporary directory (%1) can't be created").arg(full_output_dir); return false; } } displayVideoInfo(i); // Let's begin run.thumbnail_width = 0; int num_pictures = prop.n_cols * prop.n_rows; length -= prop.initial_step; int s_step = length / num_pictures; int current_time = prop.initial_step; canceled = false; progress->setLabelText(tr("Creating thumbnails...")); progress->setRange(0, num_pictures-1); progress->show(); double aspect_ratio = i.aspect; if (prop.aspect_ratio != 0) aspect_ratio = prop.aspect_ratio; for (int n = 0; n < num_pictures; n++) { qDebug("VideoPreview::extractImages: getting frame %d of %d...", n+1, num_pictures); progress->setValue(n); qApp->processEvents(); if (canceled) return false; if (!runPlayer(current_time, aspect_ratio)) return false; QString frame_picture = full_output_dir + "/" + framePicture(); if (!QFile::exists(frame_picture)) { error_message = tr("The file %1 doesn't exist").arg(frame_picture); return false; } #if RENAME_PICTURES QString extension = (extractFormat()==PNG) ? "png" : "jpg"; QString output_file = output_dir + QString("/picture_%1.%2").arg(current_time, 8, 10, QLatin1Char('0')).arg(extension); d.rename(output_dir + "/" + framePicture(), output_file); #else QString output_file = output_dir + "/" + framePicture(); #endif if (!addPicture(QDir::tempPath() +"/"+ output_file, n, current_time)) { return false; } current_time += s_step; } return true; }
void SkPictureRecord::drawPicture(SkPicture& picture) { addDraw(DRAW_PICTURE); addPicture(picture); validate(); }
// CommonMenu CommonMenu::CommonMenu(QObject *parent) : QObject(parent) { GraphicsController* gc = GraphicsController::instance(); menu_ = new QMenu; QMenu *add = new QMenu("Add", menu_); connect(add->addAction("Add ScreenCapture"), SIGNAL(triggered()), gc, SLOT(addScreenCapture())); connect(add->addAction("Add Picture"), SIGNAL(triggered()), gc, SLOT(addPicture())); connect(add->addAction("Add Video"), SIGNAL(triggered()), gc, SLOT(addVideo())); connect(add->addAction("Add Text"), SIGNAL(triggered()), gc, SLOT(addText())); menu_->addMenu(add); connect(menu_->addAction("Remove"), SIGNAL(triggered()), gc, SLOT(removeSelectedItems())); menu_->addSeparator(); QMenu *pos = new QMenu("Position", menu_); connect(pos->addAction("Center"), &QAction::triggered, [&]() { if(item_) { item_->setPosition(IGraphicsItem::CENTER); } }); connect(pos->addAction("TopLeft"), &QAction::triggered, [&]() { if(item_) { item_->setPosition(IGraphicsItem::TOP_LEFT); } }); connect(pos->addAction("TopRight"), &QAction::triggered, [&]() { if(item_) { item_->setPosition(IGraphicsItem::TOP_RIGHT); } }); connect(pos->addAction("BottomLeft"), &QAction::triggered, [&]() { if(item_) { item_->setPosition(IGraphicsItem::BOTTOM_LEFT); } }); connect(pos->addAction("BottomRight"), &QAction::triggered, [&]() { if(item_) { item_->setPosition(IGraphicsItem::BOTTOM_RIGHT); } }); menu_->addMenu(pos); connect(menu_->addAction("Default Size"), &QAction::triggered, [&]() { if(item_) { item_->restoreDefaultSize(); } }); }
/** * handle_client: Main application layer thread for each client * @author ndemarinis (Basic implementation) */ void *handle_client(void *data){ struct client_handler_data *clnt = (struct client_handler_data *)data; int pipes[2]; // Make a pipe to connect to the layer stack uint16_t cur_seq_num = 0; pid_t clnt_pid; // PID we receive from the client before startup struct layer_stack *stack; // Work data for layer stack implementation // Grab the client's identifier if((recv(clnt->sock, &clnt_pid, sizeof(pid_t), 0) != sizeof(pid_t))) die_with_error("Error receiving PID from client!"); stack = create_layer_stack(clnt->sock, clnt_pid, pipes); // Initialize all of our layer threads sleep(1); // Wait a second for the thread creation to settle int bytes_read; struct packet client_p; struct packet response_p; while(1){ //Wait for a packet to come in bytes_read = read(pipe_read(pipes), &client_p, sizeof(struct packet)); if(!bytes_read) // If we read nothing, it's time to terminate. { dprintf(DID_INFO, "APP: Read 0 bytes from layer stack. Terminating!\n"); break; } int opcode = client_p.opcode; //login if (opcode == __LOGIN_CODE){ //payload is just the username for this opcode if(login(client_p.payload) == 0){ //response code for SUCCESS response_p.opcode = 0x05; response_p.seq_num = cur_seq_num; cur_seq_num++; //no payload basic success response! response_p.length = 0; send_packet(pipes, response_p); } else { //basic response packet signaling invailed login response_p.opcode = __NOT_AUTHORIZED_CODE; response_p.seq_num = cur_seq_num; cur_seq_num++; response_p.length = 0; send_packet(pipes, response_p); } //create record } else if (opcode == __CREATE_CODE){ //payload syntax "<firstName>,<lastName>,<location>" char *firstName = strtok(client_p.payload, ","); char *lastName = strtok(NULL, ","); char *location = strtok(NULL, ""); //replace null with proper response once I determine what its for! char *response = malloc(10*sizeof(response)); int resp = createRecord(firstName, lastName, location, response); //if a 0 was not returned an error occured if (resp) { //send an error back! return_error(pipes, resp, &cur_seq_num); } else { //send back the data return_response(pipes, response, &cur_seq_num); } //query record } else if (opcode == __QUERY_CODE){ //payload syntax "NAME:<firstName>,<lastName>" // "LOCATION:<location>" char *queryType = strtok(client_p.payload, ":"); bodyEntry *responses; int resp; //two types of query name and location if (strcmp(queryType, "NAME") == 0){ //handle queries by name char *firstName = strtok(NULL, ","); char *lastName = strtok(NULL, ""); int respCount; //get the query response from the database resp = queryRecordByName(firstName, lastName, &responses, &respCount); //if resp is not 0 then an error occured if (resp){ //send an error back! return_error(pipes, resp, &cur_seq_num); } else { //send the information back to the client! char response[respCount*(16+20+36+3)]; memset(response,0,sizeof(response)); int i, rID; char recordID[10]; for (i = 0; i < respCount; i++){ rID = responses[i].id; sprintf(recordID, "%09d", rID); strcat(response, recordID); strcat(response, ","); strcat(response, responses[i].location); strcat(response, ","); } return_response(pipes, response, &cur_seq_num); } } else if (strcmp(queryType, "LOCATION") == 0){ //handle queries by location char *location = strtok(NULL, ""); int respCount; //get the query response from the database resp = queryRecordByLocation(location, &responses, &respCount); //if resp is not 0 then an error occured if (resp){ //send an error back! return_error(pipes, resp, &cur_seq_num); } else { //send the information back to the client! char response[respCount*(16+20+36+3)]; memset(response,0,sizeof(response)); int i, rID; char recordID[10]; for (i = 0; i < respCount; i++){ rID = responses[i].id; sprintf(recordID, "%09d", rID); strcat(response, recordID); strcat(response, ","); strcat(response, responses[i].firstName); strcat(response, ","); strcat(response, responses[i].lastName); strcat(response, ","); } return_response(pipes, response, &cur_seq_num); } } //update record } else if (opcode == __UPDATE_CODE){ //payload syntax "<recordId>,<firstName>,<lastName>" char *recordId = strtok(client_p.payload, ","); char *firstName = strtok(NULL, ","); char *lastName = strtok(NULL, ""); //convert recordID into an integer int rId = atoi(recordId); int resp = updateRecordName(rId, firstName, lastName); //if resp is not 0 then an error occured if (resp){ //send an error back! return_error(pipes, resp, &cur_seq_num); } else { //send the information back to the client! //basic success packet so an empty string is given for the payload return_response(pipes, "", &cur_seq_num); } //add picture } else if (opcode == __ADD_PIC_CODE){ /*payload syntax 1st packet: "<firstName>,<lastName>,<imageSize>" 2nd+ packets: "<pictureData>" These picture data packets will continue until the entirety of the picture has been transmitted The file is complete once the server has recieved a packet ending with an EOF character */ //get the name information from the first packet transmitted char *firstName = strtok(client_p.payload, ","); char *lastName = strtok(NULL, ","); char *imageSize = strtok(NULL, ""); unsigned long size = atol(imageSize); //create an array capable of holding the entire image char pictureData[size]; int i = 0; // DEBUG: Write out the file as we read it FILE *out = fopen("server_output.png", "w+"); //start recieving the picture data, continue until this entire picture has been recieved while(i < size - 1){ //read in a new packet of data bytes_read = read(pipe_read(pipes), &client_p, sizeof(struct packet)); dprintf(DID_APP_INFO, "APP: Received packet of %d bytes with payload of %d bytes.\n", bytes_read, client_p.length); //store the picture data into the array memcpy(pictureData + i, client_p.payload, client_p.length); //increment i by the length of the payload i += client_p.length; } // DEBUG: Write out that whole array to the test file printf("Received picture of %d total bytes.\n", i); write(fileno(out), pictureData, i); // DEBUG: Close that file fflush(out); fclose(out); char add_response[10]; int resp = addPicture(firstName, lastName, pictureData, add_response); if (resp){ //send an error back! return_error(pipes, resp, &cur_seq_num); } else { //send the information back to the client! return_response(pipes, add_response, &cur_seq_num); } //connect picture } else if (opcode == __CONNECT_PIC_CODE){ //payload syntax "<pictureID>,<recordID>" char *pictureID = strtok(client_p.payload, ","); char *recordID = strtok(NULL, ""); int pID = atoi(pictureID); int rID = atoi(recordID); int resp = connectPictureToRecord(pID, rID); if (resp){ //send and error back! return_error(pipes, resp, &cur_seq_num); } else { //send the success packet back! return_response(pipes, "", &cur_seq_num); } //logout! } else if (opcode == __LOGOUT_CODE){ //payload syntax NONE //break out of the while loop containin this and allow the thread processing this client to exit logout(); break; //download picture } else if (opcode == __QUERY_PIC_CODE){ //payload syntax "<pictureID>" char *pictureID = strtok(client_p.payload, ""); int pID = atoi(pictureID); char pictureData[__MAX_IMAGE_SIZE]; int resp = queryPicture(pID, pictureData); if (resp){ //send an error back! return_error(pipes, resp, &cur_seq_num); } else { //break the image into packets and send it back to the client! //write the data into a tempory file handle for simple reading when breaking into packets //base the temporary file off of the pid to ensure uniqueness char filename[MAX_FILENAME_SIZE]; int pid = getpid(); char cpid[10]; sprintf(cpid, "%d", pid); strcpy(filename, "temp_"); strcat(filename, cpid); strcat(filename, ".jpg"); //open the temp file for writing FILE *picture = fopen(filename, "w"); //write the entire image to the file! fwrite(pictureData, 1, sizeof(pictureData), picture); //send a simple packet informing the client of the size of the image that it is going to recieve response_p.opcode = 5; response_p.seq_num = cur_seq_num; cur_seq_num++; sprintf(response_p.payload, "%lu", sizeof(pictureData)); response_p.length = strlen(response_p.payload); send_packet(pipes, response_p); //read into packets and send them until the end of file is reached //note this uses the same packet pointer the entire time so the opcode does not need to be set again response_p.opcode = 5; while(!feof(picture)){ //read at most 251 bytes of the picture into the packets payload int readSize = fread(response_p.payload, 1, MAX_PAYLOAD, picture); //if there was no error then add the sequence number and the length to the packet then send it //DO NOT SET THE SEND FLAG, this will handle it on its own since there could be multiple sends if (!ferror(picture)){ response_p.seq_num = cur_seq_num; cur_seq_num++; response_p.length = (uint8_t)readSize; //send this packet down to the data link layer send_packet(pipes, response_p); } else { //an error occured return an error code so that the client can stop processing the image and drop the corrupt data return_error(pipes, 1, &cur_seq_num); break; } } //close the picture that was being read fclose(picture); //delete the temporary file remove(filename); } } // Send it straight back //printf("APP: Sending string of %d bytes: %s\n", to_read, read_buffer); //write(pipe_write(pipes), read_buffer, to_read); } curr_clients--; pthread_exit(NULL); }