26 #include <sys/types.h> 27 #include <sys/socket.h> 33 #include <FL/fl_ask.H> 34 #include <FL/fl_draw.H> 35 #include <FL/Fl_File_Chooser.H> 36 #include <FL/Fl_Window.H> 37 #include <FL/Fl_Widget.H> 38 #include <FL/Fl_Group.H> 39 #include <FL/Fl_Scroll.H> 40 #include <FL/Fl_Pack.H> 41 #include <FL/Fl_Box.H> 42 #include <FL/Fl_Button.H> 45 #include "../dpip/dpip.h" 51 #define MSG(...) printf("[downloads dpi]: " __VA_ARGS__) 70 ProgressBar(
int x,
int y,
int w,
int h,
const char *lbl = 0);
119 DLItem(
const char *full_filename,
const char *url);
172 DLWin(
int ww,
int wh);
173 void add(
const char *full_filename,
const char *url);
174 void del(
int n_item);
192 char *ret = (
char *) malloc(2 * len + 1);
232 : Fl_Box(x, y, w, h, lbl)
250 Rectangle r = {x(), y(), w(), h()};
257 r.w = r.w * pct + .5;
258 fl_rectf(r.x, r.y, r.w, r.h, FL_BLUE);
262 fl_font(this->labelfont(), this->labelsize());
263 fl_draw(
mMsg, x(), y(), w(), h(), FL_ALIGN_CENTER);
266 sprintf(buffer,
"%d%%",
int (pct * 100 + .5));
268 fl_font(this->labelfont(), this->labelsize());
269 fl_draw(buffer, x(), y(), w(), h(), FL_ALIGN_CENTER);
295 O_NONBLOCK | fcntl(
LogPipe[0], F_GETFL));
300 p = strrchr(full_filename,
'/');
327 dl_argv[i++] = (
char*)
"--load-cookies";
344 prTitle =
new Fl_Box(24, 7, 290, 23);
347 prTitle->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_CLIP);
355 prBar->box(FL_THIN_UP_BOX);
356 prBar->tooltip(
"Progress Status");
358 int ix = 122, iy = 37, iw = 50, ih = 14;
359 Fl_Widget *o =
new Fl_Box(ix,iy,iw,ih,
"Got");
360 o->box(FL_RFLAT_BOX);
363 o->tooltip(
"Downloaded Size");
364 prGot =
new Fl_Box(ix,iy+14,iw,ih,
"0KB");
365 prGot->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
366 prGot->labelcolor(FL_BLUE);
367 prGot->labelsize(12);
368 prGot->box(FL_NO_BOX);
371 o =
new Fl_Box(ix,iy,iw,ih,
"Size");
372 o->box(FL_RFLAT_BOX);
375 o->tooltip(
"Total Size");
376 prSize =
new Fl_Box(ix,iy+14,iw,ih,
"??");
377 prSize->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
382 o =
new Fl_Box(ix,iy,iw,ih,
"Rate");
383 o->box(FL_RFLAT_BOX);
386 o->tooltip(
"Current transfer Rate (KBytes/sec)");
387 prRate =
new Fl_Box(ix,iy+14,iw,ih,
"??");
388 prRate->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
393 o =
new Fl_Box(ix,iy,iw,ih,
"~Rate");
394 o->box(FL_RFLAT_BOX);
397 o->tooltip(
"Average transfer Rate (KBytes/sec)");
398 pr_Rate =
new Fl_Box(ix,iy+14,iw,ih,
"??");
399 pr_Rate->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
404 prETAt = o =
new Fl_Box(ix,iy,iw,ih,
"ETA");
405 o->box(FL_RFLAT_BOX);
408 o->tooltip(
"Estimated Time of Arrival");
409 prETA =
new Fl_Box(ix,iy+14,iw,ih,
"??");
410 prETA->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
411 prETA->labelsize(12);
412 prETA->box(FL_NO_BOX);
414 prButton =
new Fl_Button(326, 9, 44, 19,
"Stop");
415 prButton->tooltip(
"Stop this transfer");
420 group->box(FL_ROUNDED_BOX);
430 int idx = (strcmp(
dl_argv[1],
"-c")) ? 2 : 3;
449 kill(
pid(), SIGTERM);
467 setenv(
"LC_ALL",
"C", 1);
479 if (newsize > 1024 * 1024)
480 snprintf(num, 64,
"%.1fMB", (
float)newsize / (1024*1024));
482 snprintf(num, 64,
"%.0fKB", (
float)newsize / 1024);
489 char *esc_str, *q, *d, num[64];
494 esc_len = strlen(esc_str);
506 for (p = esc_str; (size_t)(p - esc_str) < esc_len; ++p) {
511 }
else if (isdigit(*p)) {
513 }
else if (*p ==
'\n') {
520 if (isdigit(*q++ = *p)) {
522 }
else if (*p ==
'K') {
533 if ((*q++ = *p) ==
'\n')
546 if (p && isdigit(p[9]) && strchr(p + 9,
' ')) {
547 for (p += 9, d = &num[0]; *p !=
' '; ++p)
563 prTitle->copy_label(
"Connecting...");
589 snprintf(buf, 64,
"%.1fMB", (
float)
curr_bytesize / (1024*1024));
592 prGot->copy_label(buf);
608 const int BufLen = 4096;
613 st = read(fd_in, Buf, BufLen);
615 if (errno == EAGAIN) {
620 }
else if (st == 0) {
622 Fl::remove_fd(fd_in, 1);
650 prButton->tooltip(
"Close this information panel");
653 prButton->tooltip(
"Close this information panel");
662 MSG(
"wget status %d\n", status);
672 eh = et / 3600; em = (et % 3600) / 60; es = et % 60;
675 snprintf(str, 8,
"%ds", es);
677 snprintf(str, 8,
"%dm%ds", em, es);
679 snprintf(str, 8,
"%dh%dm", eh, em);
690 float csec, tsec, rate, _rate = 0;
712 snprintf(str, 64, (rate < 100) ?
"%.1fK/s" :
"%.0fK/s", rate);
718 snprintf(str, 64, (_rate < 100) ?
"%.1fK/s" :
"%.0fK/s", _rate);
726 prETAt->tooltip(
"Download Time");
729 prETA->copy_label(str);
739 prETA->copy_label(str);
762 struct sigaction sigact;
765 (void) sigemptyset(&set);
767 sigact.sa_mask = set;
768 sigact.sa_flags = SA_NOCLDSTOP;
769 if (sigaction(SIGCHLD, &sigact, NULL) == -1) {
786 for (i = 0; i < list->
num(); ++i) {
788 waitpid(list->
get(i)->
pid(), &status, WNOHANG) > 0) {
806 static int cb_used = 0;
811 for (
int i = 0; i < list->
num(); ++i) {
821 if (cb_used && list->
num() == 0)
836 struct sockaddr_un clnt_addr;
840 char *dpip_tag = NULL, *cmd = NULL, *url = NULL, *dl_dest = NULL;
843 csz =
sizeof(
struct sockaddr_un);
846 sock_fd = accept(req_fd, (
struct sockaddr *) &clnt_addr, &csz);
847 }
while (sock_fd == -1 && errno == EINTR);
859 MSG(
"can't authenticate request: %s fd=%d\n",
dStrerror(errno), sock_fd);
867 MSG(
"can't read request: %s fd=%d\n",
dStrerror(errno), sock_fd);
872 _MSG(
"Received tag={%s}\n", dpip_tag);
875 MSG(
"Failed to parse 'cmd' in {%s}\n", dpip_tag);
878 if (strcmp(cmd,
"DpiBye") == 0) {
879 MSG(
"got DpiBye, ignoring...\n");
882 if (strcmp(cmd,
"download") != 0) {
883 MSG(
"unknown command: '%s'. Aborting.\n", cmd);
887 MSG(
"Failed to parse 'url' in {%s}\n", dpip_tag);
891 MSG(
"Failed to parse 'destination' in {%s}\n", dpip_tag);
909 const char *msg =
"There are running downloads.\n" 910 "ABORT them and EXIT anyway?";
913 fl_message_title(
"Dillo Downloads: Abort downloads?");
914 int ch = fl_choice(
"%s",
"Cancel",
"*No",
"Yes", msg);
915 if (ch == 0 || ch == 1)
936 pid_t f_pid = fork();
941 }
else if (f_pid < 0) {
1014 Fl_Scroll::resize(x_, y_, w_, h_);
1015 Fl_Widget *resizable_ = resizable();
1017 resizable_->h() <= h() ? 0 :
1018 scrollbar_size() ? scrollbar_size() :
1019 Fl::scrollbar_size();
1021 resizable_->resize(resizable_->x(),
1026 DlScroll(
int x,
int y,
int w,
int h,
const char *l = 0)
1027 : Fl_Scroll(x, y, w, h, l)
1041 mWin =
new Fl_Window(ww, wh,
"Dillo Downloads");
1045 mPG =
new Fl_Pack(0,0,ww-18,wh);
1048 mScroll->type(Fl_Scroll::VERTICAL);
1060 fl_message_title_default(
"Dillo Downloads: Message");
1077 const int interpret_symbols = 0;
1079 fl_draw_shortcut = 0;
1080 fl_font(o->font, o->size);
1081 fl_color((Fl_Color)o->color);
1082 fl_draw(o->value, X, Y, W,
H, align, o->image, interpret_symbols);
1087 const int interpret_symbols = 0;
1089 fl_draw_shortcut = 0;
1090 fl_font(o->font, o->size);
1091 fl_measure(o->value, W,
H, interpret_symbols);
1099 int ww = 420, wh = 85;
1114 MSG(
"started...\n");