source: titan/titan/download.h @ 15288

Last change on this file since 15288 was 14295, checked in by nit, 12 years ago

[titan] increase showtime on download err

File size: 3.2 KB
Line 
1#ifndef DOWNLOAD_H
2#define DOWNLOAD_H
3
4int screendownload(char* title, char* host, char* page, int port, char* filename, char* auth, int flag)
5{
6        debug(1000, "in");
7        int rcret = -1, tmpscreencalc = 0, count = 0, ret = 0, fromthread = 0, sleeptime = 2;
8        struct skin* download = getscreen("download");
9        struct skin* progress = getscreennode(download, "progress");
10        struct skin* file = getscreennode(download, "file");
11        struct skin* maxkb = getscreennode(download, "maxkb");
12        struct skin* aktkb = getscreennode(download, "aktkb");
13        struct skin* framebuffer = getscreen("framebuffer");
14        char* bg = NULL, *tmpstr = NULL;
15        struct download* dnode = NULL;
16
17        if(pthread_self() != status.mainthread)
18                fromthread = 1;
19
20        if(filename == NULL)
21        {
22                err("filename = NULL");
23                return 1;
24        }
25
26        changetitle(download, title);
27        changetext(file, filename);
28        progress->progresssize = 0;
29        changetext(maxkb, NULL);
30        changetext(aktkb, NULL);
31
32        if(fromthread == 1)
33        {
34                m_lock(&status.drawingmutex, 0);
35                m_lock(&status.rcmutex, 10);
36                tmpscreencalc = status.screencalc;
37                status.screencalc = 2;
38                setnodeattr(download, framebuffer);
39                status.screencalc = tmpscreencalc;
40                status.rcowner = download;
41                bg = savescreen(download);
42                tmpscreencalc = status.screencalc;
43                status.screencalc = 0;
44                drawscreen(download, 2);
45        }
46        else
47                drawscreen(download, 0);
48
49
50        dnode = malloc(sizeof(struct download));
51        if(dnode == NULL)
52        {
53                err("no mem");
54                return 1;
55        }
56        memset(dnode, 0, sizeof(struct download));
57
58        dnode->host = host;
59        dnode->page = page;
60        dnode->port = port;
61        dnode->filename = filename;
62        dnode->auth = auth;
63        dnode->connfd = -1;
64        dnode->ret = -1;
65       
66        addtimer(&gethttpstruct, START, 1000, 1, (void*)dnode, NULL, NULL);
67
68        while(1)
69        {
70                rcret = waitrc(download, 1000, 0);
71
72                if(rcret == RCTIMEOUT)
73                {
74                        progress->progresssize = dnode->proz;
75                        tmpstr = oitoa(dnode->maxkb / 1024);
76                        tmpstr = ostrcat(_("Filesize (KB): "), tmpstr, 0, 1);
77                        changetext(maxkb, tmpstr);
78                        free(tmpstr); tmpstr = NULL;
79                        tmpstr = oitoa(dnode->aktkb / 1024);
80                        tmpstr = ostrcat(_("Download (KB): "), tmpstr, 0, 1);
81                        changetext(aktkb, tmpstr);
82                        free(tmpstr); tmpstr = NULL;
83                }
84                drawscreen(download, 0);
85                if(rcret == getrcconfigint("rcexit", NULL)) break;
86                if(dnode->ret == 0)
87                {
88                        progress->progresssize = dnode->proz;
89                        tmpstr = oitoa(dnode->aktkb / 1024);
90                        tmpstr = ostrcat(_("Download (KB): "), tmpstr, 0, 1);
91                        changetext(aktkb, tmpstr);
92                        free(tmpstr); tmpstr = NULL;
93                        break;
94                }
95                if(dnode->ret > 0) break;
96        }
97
98        if(dnode->ret > 0 && rcret != getrcconfigint("rcexit", NULL))
99        {
100                changetext(file, _("download error"));
101                sleeptime = 5;
102        }
103        else
104                changetext(file, _("wait for stopping download"));
105        drawscreen(download, 0);
106        sockclose(&dnode->connfd);
107        sleep(sleeptime);
108        count = 0;
109        while(dnode->ret < 0 && count < 10)
110        {
111                count++;
112                sleep(1);
113        }
114        ret = dnode->ret;
115        free(dnode); dnode = NULL;
116
117        if(fromthread == 1)
118        {
119                clearscreennolock(download);
120                restorescreen(bg, download);
121                blitfb(0);
122                status.screencalc = tmpscreencalc;
123                sleep(1);
124                status.rcowner = NULL;
125                m_unlock(&status.rcmutex, 10);
126                m_unlock(&status.drawingmutex, 0);
127        }
128        else
129        {
130                clearscreen(download);
131                drawscreen(skin, 0);
132        }
133
134        debug(1000, "out");
135
136        return ret;
137}
138
139#endif
Note: See TracBrowser for help on using the repository browser.