annotate dpi/downloads.cc @ 2048:5060d415a85a

clickable menu items (even those introducing submenus) MUST have callbacks I clicked on the "Panel size" item itself instead of any of the options in its submenu, and: Segfault!
author corvid <corvid@lavabit.com>
date Thu, 26 May 2011 02:51:18 +0000
parents db2bd1610db1
children 16e52ecf20a8
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 * File: downloads.cc
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3 *
35
d9e7b35430de Updated copyright lines
jcid
parents: 0
diff changeset
4 * Copyright (C) 2005-2007 Jorge Arellano Cid <jcid@dillo.org>
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9 * (at your option) any later version.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12 /*
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
13 * A FLTK-based GUI for the downloads dpi (dillo plugin).
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
14 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
15
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
16 #include <stdio.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
17 #include <stdlib.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18 #include <string.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19 #include <unistd.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20 #include <errno.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21 #include <fcntl.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22 #include <ctype.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
23 #include <math.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
24 #include <time.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25 #include <signal.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26 #include <sys/types.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27 #include <sys/socket.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28 #include <sys/stat.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29 #include <sys/un.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30 #include <sys/wait.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
32 #include <FL/Fl.H>
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
33 #include <FL/fl_draw.H>
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
34 #include <FL/fl_ask.H>
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
35 #include <FL/Fl_File_Chooser.H>
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
36 #include <FL/Fl_Window.H>
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
37 #include <FL/Fl_Widget.H>
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
38 #include <FL/Fl_Group.H>
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
39 #include <FL/Fl_Scroll.H>
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
40 #include <FL/Fl_Pack.H>
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
41 #include <FL/Fl_Box.H>
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
42 #include <FL/Fl_Button.H>
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
43
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
44 #include "dpiutil.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
45 #include "../dpip/dpip.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
46
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48 * Debugging macros
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50 #define _MSG(...)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51 #define MSG(...) printf("[downloads dpi]: " __VA_ARGS__)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
52
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
53 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
54 * Internal types
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
56 typedef enum {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
57 DL_NEWFILE,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
58 DL_CONTINUE,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
59 DL_RENAME,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
60 DL_OVERWRITE,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
61 DL_ABORT
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
62 } DLAction;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
63
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
64 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
65 * Class declarations
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
66 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
67
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
68 // ProgressBar widget --------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
69
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
70 class ProgressBar : public Fl_Box {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
71 protected:
1916
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
72 double mMin;
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
73 double mMax;
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
74 double mPresent;
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
75 double mStep;
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
76 bool mShowPct, mShowMsg;
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
77 char mMsg[64];
1918
55af06da5523 merge in recent changes from main repo
corvid <corvid@lavabit.com>
parents: 1816 1917
diff changeset
78 Fl_Color mTextColor;
1916
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
79 void draw();
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
80 public:
1916
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
81 ProgressBar(int x, int y, int w, int h, const char *lbl = 0);
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
82 void range(double min, double max, double step = 1) {
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
83 mMin = min; mMax = max; mStep = step;
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
84 };
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
85 void step(double step) { mPresent += step; redraw(); };
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
86 void move(double step);
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
87 double minimum() { return mMin; }
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
88 double maximum() { return mMax; }
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
89 void minimum(double nm) { mMin = nm; };
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
90 void maximum(double nm) { mMax = nm; };
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
91 double position () { return mPresent; }
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
92 double step() { return mStep; }
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
93 void position(double pos) { mPresent = pos; redraw(); }
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
94 void showtext(bool st) { mShowPct = st; }
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
95 void message(char *msg) { mShowMsg = true; strncpy(mMsg,msg,63); redraw(); }
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
96 bool showtext() { return mShowPct; }
1918
55af06da5523 merge in recent changes from main repo
corvid <corvid@lavabit.com>
parents: 1816 1917
diff changeset
97 void text_color(Fl_Color col) { mTextColor = col; }
55af06da5523 merge in recent changes from main repo
corvid <corvid@lavabit.com>
parents: 1816 1917
diff changeset
98 Fl_Color text_color() { return mTextColor; }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
99 };
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
100
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
101 // Download-item class -------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
102
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
103 class DLItem {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
104 enum {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
105 ST_newline, ST_number, ST_discard, ST_copy
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
106 };
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 928
diff changeset
107
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
108 pid_t mPid;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
109 int LogPipe[2];
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
110 char *shortname, *fullname;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
111 char *target_dir;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
112 int log_len, log_max, log_state;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
113 char *log_text;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
114 time_t init_time;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
115 char **dl_argv;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
116 time_t twosec_time, onesec_time;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
117 int twosec_bytesize, onesec_bytesize;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
118 int init_bytesize, curr_bytesize, total_bytesize;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
119 int DataDone, LogDone, ForkDone, UpdatesDone, WidgetDone;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
120 int WgetStatus;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
121
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
122 int gw, gh;
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
123 Fl_Group *group;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
124 ProgressBar *prBar;
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
125 Fl_Button *prButton;
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
126 Fl_Widget *prTitle, *prGot, *prSize, *prRate, *pr_Rate, *prETA, *prETAt;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
127
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
128 public:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
129 DLItem(const char *full_filename, const char *url, DLAction action);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
130 ~DLItem();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
131 void child_init();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
132 void father_init();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
133 void update_size(int new_sz);
306
7a76f872ce73 - Eliminated gcc 4.2.3 warnings on 64bit OS.
jcid
parents: 272
diff changeset
134 void log_text_add(const char *buf, ssize_t st);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
135 void log_text_show();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
136 void abort_dl();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
137 void prButton_cb();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
138 pid_t pid() { return mPid; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
139 void pid(pid_t p) { mPid = p; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
140 void child_finished(int status);
306
7a76f872ce73 - Eliminated gcc 4.2.3 warnings on 64bit OS.
jcid
parents: 272
diff changeset
141 void status_msg(const char *msg) { prBar->message((char*)msg); }
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
142 Fl_Widget *get_widget() { return group; }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
143 int widget_done() { return WidgetDone; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
144 void widget_done(int val) { WidgetDone = val; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
145 int updates_done() { return UpdatesDone; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
146 void updates_done(int val) { UpdatesDone = val; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
147 int fork_done() { return ForkDone; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
148 void fork_done(int val) { ForkDone = val; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
149 int log_done() { return LogDone; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
150 void log_done(int val) { LogDone = val; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
151 int wget_status() { return WgetStatus; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
152 void wget_status(int val) { WgetStatus = val; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
153 void update_prSize(int newsize);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
154 void update();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
155 };
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
156
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
157 // DLItem List ---------------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
158
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
159 /// BUG: make dynamic
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
160 class DLItemList {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
161 DLItem *mList[32];
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
162 int mNum, mMax;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
163
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
164 public:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
165 DLItemList() { mNum = 0; mMax = 32; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
166 ~DLItemList() { }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
167 int num() { return mNum; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
168 void add(DLItem *i) { if (mNum < mMax) mList[mNum++] = i; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
169 DLItem *get(int n) { return (n >= 0 && n < mNum) ? mList[n] : NULL; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
170 void del(int n) { if (n >= 0 && n < mNum) mList[n] = mList[--mNum]; }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
171 };
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
172
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
173 // DLWin ---------------------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
174
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
175 class DLWin {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
176 DLItemList *mDList;
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
177 Fl_Window *mWin;
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
178 Fl_Scroll *mScroll;
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
179 Fl_Pack *mPG;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
180
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
181 public:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
182 DLWin(int ww, int wh);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
183 void add(const char *full_filename, const char *url, DLAction action);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
184 void del(int n_item);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
185 int num();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
186 int num_running();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
187 void listen(int req_fd);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
188 void show() { mWin->show(); }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
189 void hide() { mWin->hide(); }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
190 void abort_all();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
191 DLAction check_filename(char **p_dl_dest);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
192 };
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
193
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
194
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
195 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
196 * Global variables
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
197 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
198
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
199 // SIGCHLD mask
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
200 sigset_t mask_sigchld;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
201
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
202 // SIGCHLD flag
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
203 volatile sig_atomic_t caught_sigchld = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
204
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
205 // The download window object
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
206 static class DLWin *dl_win = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
207
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
208
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
209
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
210 // ProgressBar widget --------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
211
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
212 void ProgressBar::move(double step)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
213 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
214 mPresent += step;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
215 if (mPresent > mMax)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
216 mPresent = mMin;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
217 redraw();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
218 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
219
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
220 ProgressBar::ProgressBar(int x, int y, int w, int h, const char *lbl)
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
221 : Fl_Box(x, y, w, h, lbl)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
222 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
223 mMin = mPresent = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
224 mMax = 100;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
225 mShowPct = true;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
226 mShowMsg = false;
1993
26d85eeb723a downloads GUI: fixed a couple of rendering glitches
Jorge Arellano Cid <jcid@dillo.org>
parents: 1992
diff changeset
227 box(FL_THIN_UP_BOX);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
228 color(FL_WHITE);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
229 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
230
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
231 void ProgressBar::draw()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
232 {
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
233 struct Rectangle {
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
234 int x, y, w, h;
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
235 };
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
236
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
237 //drawstyle(style(), flags());
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
238 draw_box();
1816
9c30b99e1141 downloads: fix progress bar
corvid <corvid@lavabit.com>
parents: 1815
diff changeset
239 Rectangle r = {x(), y(), w(), h()};
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
240 if (mPresent > mMax)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
241 mPresent = mMax;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
242 if (mPresent < mMin)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
243 mPresent = mMin;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
244 double pct = (mPresent - mMin) / mMax;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
245
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
246 r.w = r.w * pct + .5;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
247
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
248 if (mShowPct) {
1816
9c30b99e1141 downloads: fix progress bar
corvid <corvid@lavabit.com>
parents: 1815
diff changeset
249 fl_rectf(r.x, r.y, r.w, r.h, FL_BLUE);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
250 } else {
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
251 fl_push_clip(int (r.w * pct), 0, int (w() * .1), h());
1816
9c30b99e1141 downloads: fix progress bar
corvid <corvid@lavabit.com>
parents: 1815
diff changeset
252 fl_rectf(r.x, r.y, r.w, r.h, FL_BLUE);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
253 fl_pop_clip();
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
254 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
255
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
256 if (mShowMsg) {
1816
9c30b99e1141 downloads: fix progress bar
corvid <corvid@lavabit.com>
parents: 1815
diff changeset
257 fl_color(FL_RED);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
258 fl_font(this->labelfont(), this->labelsize());
1816
9c30b99e1141 downloads: fix progress bar
corvid <corvid@lavabit.com>
parents: 1815
diff changeset
259 fl_draw(mMsg, x(), y(), w(), h(), FL_ALIGN_CENTER);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
260 } else if (mShowPct) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
261 char buffer[30];
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
262 sprintf(buffer, "%d%%", int (pct * 100 + .5));
1816
9c30b99e1141 downloads: fix progress bar
corvid <corvid@lavabit.com>
parents: 1815
diff changeset
263 fl_color(FL_RED);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
264 fl_font(this->labelfont(), this->labelsize());
1816
9c30b99e1141 downloads: fix progress bar
corvid <corvid@lavabit.com>
parents: 1815
diff changeset
265 fl_draw(buffer, x(), y(), w(), h(), FL_ALIGN_CENTER);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
266 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
267 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
268
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
269
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
270 // Download-item class -------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
271
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
272 static void prButton_scb(Fl_Widget *, void *cb_data)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
273 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
274 DLItem *i = (DLItem *)cb_data;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
275
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
276 i->prButton_cb();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
277 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
278
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
279 DLItem::DLItem(const char *full_filename, const char *url, DLAction action)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
280 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
281 struct stat ss;
1096
bd988ddb1251 add a couple of const
Jorge Arellano Cid <jcid@dillo.org>
parents: 1012
diff changeset
282 const char *p;
bd988ddb1251 add a couple of const
Jorge Arellano Cid <jcid@dillo.org>
parents: 1012
diff changeset
283 char *esc_url;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
284
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
285 if (pipe(LogPipe) < 0) {
483
ba5eed484075 Ensure that the dlib dStr* functions are used everywhere.
Jorge Arellano Cid <jcid@dillo.org>
parents: 444
diff changeset
286 MSG("pipe, %s\n", dStrerror(errno));
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
287 return;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
288 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
289 /* Set FD to background */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
290 fcntl(LogPipe[0], F_SETFL,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
291 O_NONBLOCK | fcntl(LogPipe[0], F_GETFL));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
292
227
1819823535ed - s/strdup/dStrdup/
jcid
parents: 212
diff changeset
293 fullname = dStrdup(full_filename);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
294 p = strrchr(fullname, '/');
227
1819823535ed - s/strdup/dStrdup/
jcid
parents: 212
diff changeset
295 shortname = (p) ? dStrdup(p + 1) : dStrdup("??");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
296 p = strrchr(full_filename, '/');
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
297 target_dir= p ? dStrndup(full_filename,p-full_filename+1) : dStrdup("??");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
298
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
299 log_len = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
300 log_max = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
301 log_state = ST_newline;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
302 log_text = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
303 onesec_bytesize = twosec_bytesize = curr_bytesize = init_bytesize = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
304 total_bytesize = -1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
305
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
306 // Init value. Reset later, upon the first data bytes arrival
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
307 init_time = time(NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
308
1917
ab62ebbd29ba downloads dpi: init some time variables
corvid <corvid@lavabit.com>
parents: 1916
diff changeset
309 twosec_time = onesec_time = init_time;
ab62ebbd29ba downloads dpi: init some time variables
corvid <corvid@lavabit.com>
parents: 1916
diff changeset
310
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
311 // BUG:? test a URL with ' inside.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
312 /* escape "'" character for the shell. Is it necessary? */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
313 esc_url = Escape_uri_str(url, "'");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
314 /* avoid malicious SMTP relaying with FTP urls */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
315 if (dStrncasecmp(esc_url, "ftp:/", 5) == 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
316 Filter_smtp_hack(esc_url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
317 dl_argv = new char*[8];
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
318 int i = 0;
306
7a76f872ce73 - Eliminated gcc 4.2.3 warnings on 64bit OS.
jcid
parents: 272
diff changeset
319 dl_argv[i++] = (char*)"wget";
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
320 if (action == DL_CONTINUE) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
321 if (stat(fullname, &ss) == 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
322 init_bytesize = (int)ss.st_size;
306
7a76f872ce73 - Eliminated gcc 4.2.3 warnings on 64bit OS.
jcid
parents: 272
diff changeset
323 dl_argv[i++] = (char*)"-c";
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
324 }
306
7a76f872ce73 - Eliminated gcc 4.2.3 warnings on 64bit OS.
jcid
parents: 272
diff changeset
325 dl_argv[i++] = (char*)"--load-cookies";
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
326 dl_argv[i++] = dStrconcat(dGethomedir(), "/.dillo/cookies.txt", NULL);
306
7a76f872ce73 - Eliminated gcc 4.2.3 warnings on 64bit OS.
jcid
parents: 272
diff changeset
327 dl_argv[i++] = (char*)"-O";
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
328 dl_argv[i++] = fullname;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
329 dl_argv[i++] = esc_url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
330 dl_argv[i++] = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
331
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
332 DataDone = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
333 LogDone = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
334 UpdatesDone = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
335 ForkDone = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
336 WidgetDone = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
337 WgetStatus = -1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
338
272
be34e080c435 - Made the download dpi's panels resize horizontally.
jcid
parents: 227
diff changeset
339 gw = 400, gh = 70;
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
340 group = new Fl_Group(0,0,gw,gh);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
341 group->begin();
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
342 prTitle = new Fl_Box(24, 7, 290, 23, shortname);
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
343 prTitle->box(FL_RSHADOW_BOX);
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
344 prTitle->color(FL_WHITE);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
345 prTitle->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_CLIP);
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
346 //prTitle->clear_flag (SHORTCUT_LABEL);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
347 // Attach this 'log_text' to the tooltip
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
348 log_text_add("Target File: ", 13);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
349 log_text_add(fullname, strlen(fullname));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
350 log_text_add("\n\n", 2);
1916
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
351
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
352 prBar = new ProgressBar(24, 40, 92, 20);
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
353 prBar->box(FL_THIN_UP_BOX);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
354 prBar->tooltip("Progress Status");
1916
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
355
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
356 int ix = 122, iy = 36, iw = 50, ih = 14;
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
357 Fl_Widget *o = new Fl_Box(ix,iy,iw,ih, "Got");
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
358 o->box(FL_RFLAT_BOX);
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
359 o->color(FL_DARK2);
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
360 o->labelsize(12);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
361 o->tooltip("Downloaded Size");
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
362 prGot = new Fl_Box(ix,iy+14,iw,ih, "0KB");
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
363 prGot->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
364 prGot->labelcolor((Fl_Color)0x6c6cbd00);
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
365 prGot->labelsize(12);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
366 prGot->box(FL_NO_BOX);
1918
55af06da5523 merge in recent changes from main repo
corvid <corvid@lavabit.com>
parents: 1816 1917
diff changeset
367
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
368 ix += iw;
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
369 o = new Fl_Box(ix,iy,iw,ih, "Size");
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
370 o->box(FL_RFLAT_BOX);
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
371 o->color(FL_DARK2);
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
372 o->labelsize(12);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
373 o->tooltip("Total Size");
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
374 prSize = new Fl_Box(ix,iy+14,iw,ih, "??");
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
375 prSize->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
376 prSize->labelsize(12);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
377 prSize->box(FL_NO_BOX);
1916
8dd80f88c992 dpi/downloads.cc: make the indentation consistent.
Jeremy Henty <onepoint@starurchin.org>
parents: 1778
diff changeset
378
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
379 ix += iw;
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
380 o = new Fl_Box(ix,iy,iw,ih, "Rate");
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
381 o->box(FL_RFLAT_BOX);
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
382 o->color(FL_DARK2);
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
383 o->labelsize(12);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
384 o->tooltip("Current transfer Rate (KBytes/sec)");
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
385 prRate = new Fl_Box(ix,iy+14,iw,ih, "??");
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
386 prRate->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
387 prRate->labelsize(12);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
388 prRate->box(FL_NO_BOX);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
389
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
390 ix += iw;
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
391 o = new Fl_Box(ix,iy,iw,ih, "~Rate");
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
392 o->box(FL_RFLAT_BOX);
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
393 o->color(FL_DARK2);
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
394 o->labelsize(12);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
395 o->tooltip("Average transfer Rate (KBytes/sec)");
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
396 pr_Rate = new Fl_Box(ix,iy+14,iw,ih, "??");
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
397 pr_Rate->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
398 pr_Rate->labelsize(12);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
399 pr_Rate->box(FL_NO_BOX);
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
400
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
401 ix += iw;
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
402 prETAt = o = new Fl_Box(ix,iy,iw,ih, "ETA");
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
403 o->box(FL_RFLAT_BOX);
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
404 o->color(FL_DARK2);
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
405 o->labelsize(12);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
406 o->tooltip("Estimated Time of Arrival");
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
407 prETA = new Fl_Box(ix,iy+14,iw,ih, "??");
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
408 prETA->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
409 prETA->labelsize(12);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
410 prETA->box(FL_NO_BOX);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
411
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
412 //ix += 50;
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
413 //prButton = new Fl_Button(ix, 41, 38, 19, "Stop");
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
414 prButton = new Fl_Button(328, 9, 38, 19, "Stop");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
415 prButton->tooltip("Stop this transfer");
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
416 prButton->box(FL_UP_BOX);
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
417 prButton->clear_visible_focus();
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
418 prButton->callback(prButton_scb, this);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
419
1993
26d85eeb723a downloads GUI: fixed a couple of rendering glitches
Jorge Arellano Cid <jcid@dillo.org>
parents: 1992
diff changeset
420 //group->box(FL_ROUND_UP_BOX); --BUG in FLTK-1.3
26d85eeb723a downloads GUI: fixed a couple of rendering glitches
Jorge Arellano Cid <jcid@dillo.org>
parents: 1992
diff changeset
421 group->box(FL_ROUNDED_BOX);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
422 group->end();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
423 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
424
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
425 DLItem::~DLItem()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
426 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
427 free(shortname);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
428 dFree(fullname);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
429 dFree(target_dir);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
430 free(log_text);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
431 int idx = (strcmp(dl_argv[1], "-c")) ? 2 : 3;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
432 dFree(dl_argv[idx]);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
433 dFree(dl_argv[idx+3]);
2038
db2bd1610db1 delete []
corvid <corvid@lavabit.com>
parents: 1993
diff changeset
434 delete [] dl_argv;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
435
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
436 delete(group);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
437 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
438
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
439 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
440 * Abort a running download
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
441 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
442 void DLItem::abort_dl()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
443 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
444 if (!log_done()) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
445 close(LogPipe[0]);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
446 Fl::remove_fd(LogPipe[0]);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
447 log_done(1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
448 // Stop wget
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
449 if (!fork_done())
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
450 kill(pid(), SIGTERM);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
451 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
452 widget_done(1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
453 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
454
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
455 void DLItem::prButton_cb()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
456 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
457 prButton->deactivate();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
458 abort_dl();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
459 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
460
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
461 void DLItem::child_init()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
462 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
463 close(0); // stdin
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
464 close(1); // stdout
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
465 close(LogPipe[0]);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
466 dup2(LogPipe[1], 2); // stderr
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
467 // set the locale to C for log parsing
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
468 setenv("LC_ALL", "C", 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
469 // start wget
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
470 execvp(dl_argv[0], dl_argv);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
471 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
472
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
473 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
474 * Update displayed size
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
475 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
476 void DLItem::update_prSize(int newsize)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
477 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
478 char num[64];
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
479
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
480 if (newsize > 1024 * 1024)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
481 snprintf(num, 64, "%.1fMB", (float)newsize / (1024*1024));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
482 else
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
483 snprintf(num, 64, "%.0fKB", (float)newsize / 1024);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
484 prSize->copy_label(num);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
485 prSize->redraw_label();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
486 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
487
306
7a76f872ce73 - Eliminated gcc 4.2.3 warnings on 64bit OS.
jcid
parents: 272
diff changeset
488 void DLItem::log_text_add(const char *buf, ssize_t st)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
489 {
306
7a76f872ce73 - Eliminated gcc 4.2.3 warnings on 64bit OS.
jcid
parents: 272
diff changeset
490 const char *p;
7a76f872ce73 - Eliminated gcc 4.2.3 warnings on 64bit OS.
jcid
parents: 272
diff changeset
491 char *q, *d, num[64];
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
492
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
493 // Make room...
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
494 if (log_len + st >= log_max) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
495 log_max = log_len + st + 1024;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
496 log_text = (char *) realloc (log_text, log_max);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
497 log_text[log_len] = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
498 prTitle->tooltip(log_text);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
499 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
500
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
501 // FSM to remove wget's "dot-progress" (i.e. "^ " || "^[0-9]+K")
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
502 q = log_text + log_len;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
503 for (p = buf; (p - buf) < st; ++p) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
504 switch (log_state) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
505 case ST_newline:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
506 if (*p == ' ') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
507 log_state = ST_discard;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
508 } else if (isdigit(*p)) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
509 *q++ = *p; log_state = ST_number;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
510 } else if (*p == '\n') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
511 *q++ = *p;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
512 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
513 *q++ = *p; log_state = ST_copy;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
514 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
515 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
516 case ST_number:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
517 if (isdigit(*q++ = *p)) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
518 // keep here
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
519 } else if (*p == 'K') {
928
7771cf243ca6 's/if(/if (/g' 's/for(/for (/g' 's/while(/while (/g', and indentation.
Jorge Arellano Cid <jcid@dillo.org>
parents: 483
diff changeset
520 for (--q; isdigit(q[-1]); --q) ; log_state = ST_discard;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
521 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
522 log_state = ST_copy;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
523 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
524 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
525 case ST_discard:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
526 if (*p == '\n')
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
527 log_state = ST_newline;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
528 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
529 case ST_copy:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
530 if ((*q++ = *p) == '\n')
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
531 log_state = ST_newline;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
532 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
533 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
534 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
535 *q = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
536 log_len = strlen(log_text);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
537
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
538 // Now scan for the length of the file
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
539 if (total_bytesize == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
540 p = strstr(log_text, "\nLength: ");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
541 if (p && isdigit(p[9]) && strchr(p + 9, ' ')) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
542 for (p += 9, d = &num[0]; *p != ' '; ++p)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
543 if (isdigit(*p))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
544 *d++ = *p;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
545 *d = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
546 total_bytesize = strtol (num, NULL, 10);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
547 // Update displayed size
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
548 update_prSize(total_bytesize);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
549 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
550 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
551
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
552 // Show we're connecting...
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
553 if (curr_bytesize == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
554 prTitle->label("Connecting...");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
555 prTitle->redraw_label();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
556 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
557 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
558
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
559 ///
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
560 void DLItem::log_text_show()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
561 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
562 MSG("\nStored Log:\n%s", log_text);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
563 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
564
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
565 void DLItem::update_size(int new_sz)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
566 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
567 char buf[64];
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
568
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
569 if (curr_bytesize == 0 && new_sz) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
570 // Start the timer with the first bytes got
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
571 init_time = time(NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
572 // Update the title
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
573 prTitle->label(shortname);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
574 prTitle->redraw_label();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
575 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
576
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
577 curr_bytesize = new_sz;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
578 if (curr_bytesize > 1024 * 1024)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
579 snprintf(buf, 64, "%.1fMB", (float)curr_bytesize / (1024*1024));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
580 else
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
581 snprintf(buf, 64, "%.0fKB", (float)curr_bytesize / 1024);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
582 prGot->copy_label(buf);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
583 prGot->redraw_label();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
584 if (total_bytesize == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
585 prBar->showtext(false);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
586 prBar->move(1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
587 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
588 prBar->showtext(true);
1420
1361c2d932a3 downloads dpi div. by 0
corvid <corvid@lavabit.com>
parents: 1393
diff changeset
589 double pos = 100.0;
1361c2d932a3 downloads dpi div. by 0
corvid <corvid@lavabit.com>
parents: 1393
diff changeset
590 if (total_bytesize > 0)
1361c2d932a3 downloads dpi div. by 0
corvid <corvid@lavabit.com>
parents: 1393
diff changeset
591 pos *= (double)curr_bytesize / total_bytesize;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
592 prBar->position(pos);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
593 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
594 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
595
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
596 static void read_log_cb(int fd_in, void *data)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
597 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
598 DLItem *dl_item = (DLItem *)data;
1716
c805b4e0b7ce make dillo compile with clang
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1420
diff changeset
599 const int BufLen = 4096;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
600 char Buf[BufLen];
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
601 ssize_t st;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
602 int ret = -1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
603
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
604 do {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
605 st = read(fd_in, Buf, BufLen);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
606 if (st < 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
607 if (errno == EAGAIN) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
608 ret = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
609 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
610 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
611 perror("read, ");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
612 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
613 } else if (st == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
614 close(fd_in);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
615 Fl::remove_fd(fd_in, 1);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
616 dl_item->log_done(1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
617 ret = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
618 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
619 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
620 dl_item->log_text_add(Buf, st);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
621 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
622 } while (1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
623 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
624
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
625 void DLItem::father_init()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
626 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
627 close(LogPipe[1]);
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
628 Fl::add_fd(LogPipe[0], 1, read_log_cb, this); // Read
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
629
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
630 // Start the timer after the child is running.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
631 // (this makes a big difference with wget)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
632 //init_time = time(NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
633 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
634
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
635 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
636 * Our wget exited, let's check its status and update the panel.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
637 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
638 void DLItem::child_finished(int status)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
639 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
640 wget_status(status);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
641
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
642 if (status == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
643 prButton->label("Done");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
644 prButton->tooltip("Close this information panel");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
645 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
646 prButton->label("Close");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
647 prButton->tooltip("Close this information panel");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
648 status_msg("ABORTED");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
649 if (curr_bytesize == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
650 // Update the title
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
651 prTitle->label(shortname);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
652 prTitle->redraw_label();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
653 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
654 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
655 prButton->activate();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
656 prButton->redraw();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
657 MSG("wget status %d\n", status);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
658 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
659
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
660 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
661 * Convert seconds into human readable [hour]:[min]:[sec] string.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
662 */
51
6ff7b6758e0c Added the "static" qualifier where missing.
jcid
parents: 35
diff changeset
663 static void secs2timestr(int et, char *str)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
664 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
665 int eh, em, es;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
666
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
667 eh = et / 3600; em = (et % 3600) / 60; es = et % 60;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
668 if (eh == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
669 if (em == 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
670 snprintf(str, 8, "%ds", es);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
671 else
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
672 snprintf(str, 8, "%dm%ds", em, es);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
673 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
674 snprintf(str, 8, "%dh%dm", eh, em);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
675 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
676 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
677
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
678 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
679 * Update Got, Rate, ~Rate and ETA
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
680 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
681 void DLItem::update()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
682 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
683 struct stat ss;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
684 time_t curr_time;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
685 float csec, tsec, rate, _rate = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
686 char str[64];
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
687 int et;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
688
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
689 if (updates_done())
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
690 return;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
691
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
692 /* Update curr_size */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
693 if (stat(fullname, &ss) == -1) {
483
ba5eed484075 Ensure that the dlib dStr* functions are used everywhere.
Jorge Arellano Cid <jcid@dillo.org>
parents: 444
diff changeset
694 MSG("stat, %s\n", dStrerror(errno));
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
695 return;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
696 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
697 update_size((int)ss.st_size);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
698
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
699 /* Get current time */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
700 time(&curr_time);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
701 csec = (float) (curr_time - init_time);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
702
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
703 /* Rate */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
704 if (csec >= 2) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
705 tsec = (float) (curr_time - twosec_time);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
706 rate = ((float)(curr_bytesize-twosec_bytesize) / 1024) / tsec;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
707 snprintf(str, 64, (rate < 100) ? "%.1fK/s" : "%.0fK/s", rate);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
708 prRate->copy_label(str);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
709 prRate->redraw_label();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
710 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
711 /* ~Rate */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
712 if (csec >= 1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
713 _rate = ((float)(curr_bytesize-init_bytesize) / 1024) / csec;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
714 snprintf(str, 64, (_rate < 100) ? "%.1fK/s" : "%.0fK/s", _rate);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
715 pr_Rate->copy_label(str);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
716 pr_Rate->redraw_label();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
717 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
718
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
719 /* ETA */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
720 if (fork_done()) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
721 updates_done(1); // Last update
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
722 prETAt->label("Time");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
723 prETAt->tooltip("Download Time");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
724 prETAt->redraw();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
725 secs2timestr((int)csec, str);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
726 prETA->copy_label(str);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
727 if (total_bytesize == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
728 update_prSize(curr_bytesize);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
729 if (wget_status() == 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
730 status_msg("Done");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
731 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
732 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
733 if (_rate > 0 && total_bytesize > 0 && curr_bytesize > 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
734 et = (int)((total_bytesize-curr_bytesize) / (_rate * 1024));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
735 secs2timestr(et, str);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
736 prETA->copy_label(str);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
737 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
738 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
739 prETA->redraw_label();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
740
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
741 /* Update one and two secs ago times and bytesizes */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
742 twosec_time = onesec_time;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
743 onesec_time = curr_time;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
744 twosec_bytesize = onesec_bytesize;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
745 onesec_bytesize = curr_bytesize;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
746 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
747
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
748 // SIGCHLD -------------------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
749
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
750 /*! SIGCHLD handler
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
751 */
51
6ff7b6758e0c Added the "static" qualifier where missing.
jcid
parents: 35
diff changeset
752 static void raw_sigchld(int)
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 928
diff changeset
753 {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
754 caught_sigchld = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
755 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
756
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
757 /*! Establish SIGCHLD handler */
51
6ff7b6758e0c Added the "static" qualifier where missing.
jcid
parents: 35
diff changeset
758 static void est_sigchld(void)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
759 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
760 struct sigaction sigact;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
761 sigset_t set;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
762
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
763 (void) sigemptyset(&set);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
764 sigact.sa_handler = raw_sigchld;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
765 sigact.sa_mask = set;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
766 sigact.sa_flags = SA_NOCLDSTOP;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
767 if (sigaction(SIGCHLD, &sigact, NULL) == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
768 perror("sigaction");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
769 exit(1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
770 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
771 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
772
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
773 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
774 * Timeout function to check wget's exit status.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
775 */
51
6ff7b6758e0c Added the "static" qualifier where missing.
jcid
parents: 35
diff changeset
776 static void cleanup_cb(void *data)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
777 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
778 DLItemList *list = (DLItemList *)data;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
779
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
780 sigprocmask(SIG_BLOCK, &mask_sigchld, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
781 if (caught_sigchld) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
782 /* Handle SIGCHLD */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
783 int i, status;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
784 for (i = 0; i < list->num(); ++i) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
785 if (!list->get(i)->fork_done() &&
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
786 waitpid(list->get(i)->pid(), &status, WNOHANG) > 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
787 list->get(i)->child_finished(status);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
788 list->get(i)->fork_done(1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
789 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
790 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
791 caught_sigchld = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
792 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
793 sigprocmask(SIG_UNBLOCK, &mask_sigchld, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
794
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
795 Fl::repeat_timeout(1.0,cleanup_cb,data);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
796 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
797
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
798 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
799 * Timeout function to update the widget indicators,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
800 * also remove widgets marked "done".
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
801 */
51
6ff7b6758e0c Added the "static" qualifier where missing.
jcid
parents: 35
diff changeset
802 static void update_cb(void *data)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
803 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
804 static int cb_used = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
805
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
806 DLItemList *list = (DLItemList *)data;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
807
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
808 /* Update the widgets and remove the ones marked as done */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
809 for (int i = 0; i < list->num(); ++i) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
810 if (!list->get(i)->widget_done()) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
811 list->get(i)->update();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
812 } else if (list->get(i)->fork_done()) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
813 // widget_done and fork_done avoid a race condition.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
814 dl_win->del(i); --i;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
815 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
816 cb_used = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
817 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
818
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
819 if (cb_used && list->num() == 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
820 exit(0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
821
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
822 Fl::repeat_timeout(1.0,update_cb,data);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
823 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
824
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
825
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
826 // DLWin ---------------------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
827
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
828 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
829 * Make a new name and place it in 'dl_dest'.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
830 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
831 static void make_new_name(char **dl_dest, const char *url)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
832 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
833 Dstr *gstr = dStr_new(*dl_dest);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
834 int idx = gstr->len;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
835
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
836 if (gstr->str[idx - 1] != '/'){
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
837 dStr_append_c(gstr, '/');
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
838 ++idx;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
839 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
840
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
841 /* Use a mangled url as name */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
842 dStr_append(gstr, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
843 for ( ; idx < gstr->len; ++idx)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
844 if (!isalnum(gstr->str[idx]))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
845 gstr->str[idx] = '_';
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
846
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
847 /* free memory */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
848 dFree(*dl_dest);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
849 *dl_dest = gstr->str;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
850 dStr_free(gstr, FALSE);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
851 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
852
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
853 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
854 * Callback function for the request socket.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
855 * Read the request, parse and start a new download.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
856 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
857 static void read_req_cb(int req_fd, void *)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
858 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
859 struct sockaddr_un clnt_addr;
1393
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
860 int sock_fd;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
861 socklen_t csz;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
862 struct stat sb;
1393
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
863 Dsh *sh = NULL;
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
864 char *dpip_tag = NULL, *cmd = NULL, *url = NULL, *dl_dest = NULL;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
865 DLAction action = DL_ABORT; /* compiler happiness */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
866
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
867 /* Initialize the value-result parameter */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
868 csz = sizeof(struct sockaddr_un);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
869 /* accept the request */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
870 do {
1393
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
871 sock_fd = accept(req_fd, (struct sockaddr *) &clnt_addr, &csz);
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
872 } while (sock_fd == -1 && errno == EINTR);
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
873 if (sock_fd == -1) {
483
ba5eed484075 Ensure that the dlib dStr* functions are used everywhere.
Jorge Arellano Cid <jcid@dillo.org>
parents: 444
diff changeset
874 MSG("accept, %s fd=%d\n", dStrerror(errno), req_fd);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
875 return;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
876 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
877
1393
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
878 /* create a sock handler */
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
879 sh = a_Dpip_dsh_new(sock_fd, sock_fd, 8*1024);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
880
1393
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
881 /* Authenticate our client... */
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
882 if (!(dpip_tag = a_Dpip_dsh_read_token(sh, 1)) ||
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
883 a_Dpip_check_auth(dpip_tag) < 0) {
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
884 MSG("can't authenticate request: %s fd=%d\n", dStrerror(errno), sock_fd);
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
885 a_Dpip_dsh_close(sh);
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
886 goto end;
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
887 }
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
888 dFree(dpip_tag);
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
889
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
890 /* Read request */
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
891 if (!(dpip_tag = a_Dpip_dsh_read_token(sh, 1))) {
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
892 MSG("can't read request: %s fd=%d\n", dStrerror(errno), sock_fd);
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
893 a_Dpip_dsh_close(sh);
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
894 goto end;
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
895 }
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
896 a_Dpip_dsh_close(sh);
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
897 _MSG("Received tag={%s}\n", dpip_tag);
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
898
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
899 if ((cmd = a_Dpip_get_attr(dpip_tag, "cmd")) == NULL) {
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
900 MSG("Failed to parse 'cmd' in {%s}\n", dpip_tag);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
901 goto end;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
902 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
903 if (strcmp(cmd, "DpiBye") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
904 MSG("got DpiBye, ignoring...\n");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
905 goto end;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
906 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
907 if (strcmp(cmd, "download") != 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
908 MSG("unknown command: '%s'. Aborting.\n", cmd);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
909 goto end;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
910 }
1393
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
911 if (!(url = a_Dpip_get_attr(dpip_tag, "url"))){
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
912 MSG("Failed to parse 'url' in {%s}\n", dpip_tag);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
913 goto end;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
914 }
1393
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
915 if (!(dl_dest = a_Dpip_get_attr(dpip_tag, "destination"))){
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
916 MSG("Failed to parse 'destination' in {%s}\n", dpip_tag);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
917 goto end;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
918 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
919 /* 'dl_dest' may be a directory */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
920 if (stat(dl_dest, &sb) == 0 && S_ISDIR(sb.st_mode)) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
921 make_new_name(&dl_dest, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
922 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
923 action = dl_win->check_filename(&dl_dest);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
924 if (action != DL_ABORT) {
1778
corvid <corvid@lavabit.com>
parents: 1764
diff changeset
925 // Start the whole thing within FLTK.
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
926 dl_win->add(dl_dest, url, action);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
927 } else if (dl_win->num() == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
928 exit(0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
929 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
930
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
931 end:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
932 dFree(cmd);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
933 dFree(url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
934 dFree(dl_dest);
1393
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
935 dFree(dpip_tag);
dcf1ec78121a Made downloads dpi use dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1236
diff changeset
936 a_Dpip_dsh_free(sh);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
937 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
938
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
939 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
940 * Callback for close window request (WM or EscapeKey press)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
941 */
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
942 static void dlwin_esc_cb(Fl_Widget *, void *)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
943 {
306
7a76f872ce73 - Eliminated gcc 4.2.3 warnings on 64bit OS.
jcid
parents: 272
diff changeset
944 const char *msg = "There are running downloads.\n"
7a76f872ce73 - Eliminated gcc 4.2.3 warnings on 64bit OS.
jcid
parents: 272
diff changeset
945 "ABORT them and EXIT anyway?";
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
946
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
947 if (dl_win && dl_win->num_running() > 0) {
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
948 int ch = fl_choice("%s", "Cancel", "*No", "Yes", msg);
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
949 if (ch == 0 || ch == 1)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
950 return;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
951 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
952
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
953 /* abort each download properly */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
954 dl_win->abort_all();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
955 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
956
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
957 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
958 * Add a new download request to the main window and
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
959 * fork a child to do the job.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
960 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
961 void DLWin::add(const char *full_filename, const char *url, DLAction action)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
962 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
963 DLItem *dl_item = new DLItem(full_filename, url, action);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
964 mDList->add(dl_item);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
965 mPG->insert(*dl_item->get_widget(), 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
966
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
967 _MSG("Child index = %d\n", mPG->find(dl_item->get_widget()));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
968
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
969 // Start the child process
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
970 pid_t f_pid = fork();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
971 if (f_pid == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
972 /* child */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
973 dl_item->child_init();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
974 _exit(EXIT_FAILURE);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
975 } else if (f_pid < 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
976 perror("fork, ");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
977 exit(1);
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 928
diff changeset
978 } else {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
979 /* father */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
980 dl_win->show();
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
981 dl_item->get_widget()->redraw();
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
982 dl_item->pid(f_pid);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
983 dl_item->father_init();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
984 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
985 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
986
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
987 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
988 * Decide what to do when the filename already exists.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
989 * (renaming takes place here when necessary)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
990 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
991 DLAction DLWin::check_filename(char **p_fullname)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
992 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
993 struct stat ss;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
994 Dstr *ds;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
995 int ch;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
996 DLAction ret = DL_ABORT;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
997
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
998 if (stat(*p_fullname, &ss) == -1)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
999 return DL_NEWFILE;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1000
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1001 ds = dStr_sized_new(128);
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 928
diff changeset
1002 dStr_sprintf(ds,
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1003 "The file:\n %s (%d Bytes)\nalready exists. What do we do?",
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1004 *p_fullname, (int)ss.st_size);
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
1005 ch = fl_choice("%s", "Abort", "Continue", "Rename", ds->str);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1006 dStr_free(ds, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1007 MSG("Choice %d\n", ch);
1992
75b1b909ffbc Fixed downloads dpi GUI (close and rename dialogs, colors)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1940
diff changeset
1008 if (ch == 2) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1009 const char *p;
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
1010 p = fl_file_chooser("Enter a new name:", NULL, *p_fullname);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1011 if (p) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1012 dFree(*p_fullname);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1013 *p_fullname = dStrdup(p);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1014 ret = check_filename(p_fullname);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1015 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1016 } else if (ch == 1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1017 ret = DL_CONTINUE;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1018 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1019 return ret;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1020 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1021
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1022 /*
1012
306ce2f3228f [mq]: fix-dlwin_new-comment
Jeremy Henty <onepoint@starurchin.org>
parents: 967
diff changeset
1023 * Delete a download request from the main window.
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1024 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1025 void DLWin::del(int n_item)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1026 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1027 DLItem *dl_item = mDList->get(n_item);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1028
444
32cbd6607669 - Set the ScrollGroup as the resizable widget in downloads dpi.
jcid
parents: 442
diff changeset
1029 // Remove the widget from the packed group
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1030 mPG->remove(dl_item->get_widget());
1993
26d85eeb723a downloads GUI: fixed a couple of rendering glitches
Jorge Arellano Cid <jcid@dillo.org>
parents: 1992
diff changeset
1031 mScroll->redraw();
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1032 mDList->del(n_item);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1033 delete(dl_item);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1034 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1035
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1036 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1037 * Return number of entries
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1038 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1039 int DLWin::num()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1040 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1041 return mDList->num();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1042 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1043
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1044 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1045 * Return number of running downloads
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1046 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1047 int DLWin::num_running()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1048 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1049 int i, nr;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1050
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1051 for (i = nr = 0; i < mDList->num(); ++i)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1052 if (!mDList->get(i)->fork_done())
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1053 ++nr;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1054 return nr;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1055 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1056
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1057 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1058 * Set a callback function for the request socket
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1059 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1060 void DLWin::listen(int req_fd)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1061 {
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
1062 Fl::add_fd(req_fd, 1, read_req_cb, NULL); // Read
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1063 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1064
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1065 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1066 * Abort each download properly, and let the main cycle exit
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1067 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1068 void DLWin::abort_all()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1069 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1070 for (int i = 0; i < mDList->num(); ++i)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1071 mDList->get(i)->abort_dl();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1072 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1073
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1074 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1075 * Create the main window and an empty list of requests.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1076 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1077 DLWin::DLWin(int ww, int wh) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1078
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1079 // Init an empty list for the download requests
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1080 mDList = new DLItemList();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1081
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1082 // Create the empty main window
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
1083 mWin = new Fl_Window(ww, wh, "Downloads:");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1084 mWin->begin();
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
1085 mScroll = new Fl_Scroll(0,0,ww,wh);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1086 mScroll->begin();
1993
26d85eeb723a downloads GUI: fixed a couple of rendering glitches
Jorge Arellano Cid <jcid@dillo.org>
parents: 1992
diff changeset
1087 mPG = new Fl_Pack(0,0,ww-18,wh);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1088 mPG->end();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1089 mScroll->end();
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
1090 mScroll->type(Fl_Scroll::VERTICAL);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1091 mWin->end();
444
32cbd6607669 - Set the ScrollGroup as the resizable widget in downloads dpi.
jcid
parents: 442
diff changeset
1092 mWin->resizable(mScroll);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1093 mWin->callback(dlwin_esc_cb, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1094 mWin->show();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1095
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1096 // Set SIGCHLD handlers
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1097 sigemptyset(&mask_sigchld);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1098 sigaddset(&mask_sigchld, SIGCHLD);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1099 est_sigchld();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1100
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1101 // Set the cleanup timeout
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
1102 Fl::add_timeout(1.0, cleanup_cb, mDList);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1103 // Set the update timeout
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
1104 Fl::add_timeout(1.0, update_cb, mDList);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1105 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1106
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1107
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1108 // ---------------------------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1109
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1110
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1111
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1112 //int main(int argc, char **argv)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1113 int main()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1114 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1115 int ww = 420, wh = 85;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1116
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
1117 Fl::lock();
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1118
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1119 // Create the download window
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1120 dl_win = new DLWin(ww, wh);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1121
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1122 // Start listening to the request socket
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1123 dl_win->listen(STDIN_FILENO);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1124
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1125 MSG("started...\n");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1126
1815
2e454b989709 downloader compiles
corvid <corvid@lavabit.com>
parents: 1778
diff changeset
1127 return Fl::run();
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1128 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1129