void gToxFileRecv::pause() { if (m_state != RECVING) { return; } m_state = PAUSED; tox().file_control(m_file.nr, m_file.file_number, TOX_FILE_CONTROL_PAUSE); }
void gToxFileRecv::resume() { if (m_state != PAUSED) { return; } m_state = RECVING; if (m_file.file_size == m_position) { cancel(); std::clog << "Friend " << m_file.nr << " File " << m_file.file_number << " " << m_position << "/" << m_file.file_size << std::endl; observer_notify(ToxEvent(EventFileProgress{ this, m_file.nr, m_file.kind, m_file.file_number, m_position, m_file.file_size })); if (m_file.kind == TOX_FILE_KIND_AVATAR) { WidgetAvatar::set_avatar(observable(), m_path, WidgetAvatar::get_avatar(m_path, true)); } return; } tox().file_control(m_file.nr, m_file.file_number, TOX_FILE_CONTROL_RESUME); }
void gToxFileRecv::cancel() { if (m_state != STOPPED) { return; } m_state = STOPPED; tox().file_control(m_file.nr, m_file.file_number, TOX_FILE_CONTROL_CANCEL); //TODO: delete file }
static void plotpoint(double x, double y) { /* PURPOSE : PLOTS A SINGLE POINT ONTO THE SCREEN */ NOWX = tox(x); NOWY = toy(y); /* PLOT(NOWX, NOWY, COLOR); */ /* p2c: test3.pas, line 139: Warning: Symbol 'PLOT' is not defined [221] */ }
static void draws(double x, double y) { /* PURPOSE : DRAWS TO <X,Y> AND MAKES IT THE CURRENT POINT */ long temp; temp = toy(y); /* DRAW(NOWX, NOWY, tox(X_), TEMP, COLOR); */ /* p2c: test3.pas, line 160: Warning: Symbol 'DRAW' is not defined [221] */ NOWX = tox(x); NOWY = temp; }
gToxFileRecv::gToxFileRecv(gToxObservable* observable, Toxmm::EventFileRecv file) : gToxObserver(observable), m_file(file) { try { if (m_file.kind == TOX_FILE_KIND_AVATAR) { if (m_file.file_size > 65_kib) { //ignore file ! cancel(); return; } m_path = WidgetAvatar::get_avatar_path(observable, m_file.nr); if (m_file.file_size == 0) { //Remove avatar WidgetAvatar::set_avatar(observable, m_path, Glib::RefPtr<Gdk::Pixbuf>()); return; } //check if m_fd = ::open(m_path.c_str(), O_RDONLY); if (m_fd != -1) { std::vector<uint8_t> data; while(true) { char buf[1024]; int r = ::read(m_fd, buf, 1024); if (r <= 0) { break; } std::copy(buf, buf + r, std::back_inserter(data)); } close(m_fd); m_fd = -1; auto file_id_should = tox().hash(data); auto file_id = tox().file_get_field_id(m_file.nr, m_file.file_number); if (!std::equal(file_id.begin(), file_id.end(), file_id_should.begin())) { //Remove avatar, because it's wrong WidgetAvatar::set_avatar(observable, m_path, Glib::RefPtr<Gdk::Pixbuf>()); } } } else { m_path = Glib::build_filename(Glib::get_user_special_dir(GUserDirectory::G_USER_DIRECTORY_DOWNLOAD), m_file.filename); } std::clog << "Download " << m_path << std::endl; m_fd = ::open(m_path.c_str(), O_RDWR|O_CREAT, 0600); std::clog << "Open fd " << m_fd << std::endl; if (m_fd == -1) { throw std::runtime_error("gToxFileRecv couldn't open file"); } //read file size m_position = lseek(m_fd, 0, SEEK_END); tox().file_seek(m_file.nr, m_file.file_number, m_position); } catch(const Toxmm::Exception& exp) { //Ignore if (m_fd != -1) { ::close(m_fd); m_fd = -1; } } }