source: titan/titan/download.h @ 16511

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

[titan] delete status.screencalc

File size: 3.0 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, 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                setnodeattr(download, framebuffer, 2);
37                status.rcowner = download;
38                bg = savescreen(download);
39                drawscreen(download, 0, 2);
40        }
41        else
42                drawscreen(download, 0, 0);
43
44
45        dnode = malloc(sizeof(struct download));
46        if(dnode == NULL)
47        {
48                err("no mem");
49                return 1;
50        }
51        memset(dnode, 0, sizeof(struct download));
52
53        dnode->host = host;
54        dnode->page = page;
55        dnode->port = port;
56        dnode->filename = filename;
57        dnode->auth = auth;
58        dnode->connfd = -1;
59        dnode->ret = -1;
60       
61        addtimer(&gethttpstruct, START, 1000, 1, (void*)dnode, NULL, NULL);
62
63        while(1)
64        {
65                rcret = waitrc(download, 1000, 0);
66
67                if(rcret == RCTIMEOUT)
68                {
69                        progress->progresssize = dnode->proz;
70                        tmpstr = oitoa(dnode->maxkb / 1024);
71                        tmpstr = ostrcat(_("Filesize (KB): "), tmpstr, 0, 1);
72                        changetext(maxkb, tmpstr);
73                        free(tmpstr); tmpstr = NULL;
74                        tmpstr = oitoa(dnode->aktkb / 1024);
75                        tmpstr = ostrcat(_("Download (KB): "), tmpstr, 0, 1);
76                        changetext(aktkb, tmpstr);
77                        free(tmpstr); tmpstr = NULL;
78                }
79                drawscreen(download, 0, 0);
80                if(rcret == getrcconfigint("rcexit", NULL)) break;
81                if(dnode->ret == 0)
82                {
83                        progress->progresssize = dnode->proz;
84                        tmpstr = oitoa(dnode->aktkb / 1024);
85                        tmpstr = ostrcat(_("Download (KB): "), tmpstr, 0, 1);
86                        changetext(aktkb, tmpstr);
87                        free(tmpstr); tmpstr = NULL;
88                        break;
89                }
90                if(dnode->ret > 0) break;
91        }
92
93        if(dnode->ret > 0 && rcret != getrcconfigint("rcexit", NULL))
94        {
95                changetext(file, _("download error"));
96                sleeptime = 5;
97        }
98        else
99                changetext(file, _("wait for stopping download"));
100        drawscreen(download, 0, 0);
101        sockclose(&dnode->connfd);
102        sleep(sleeptime);
103        count = 0;
104        while(dnode->ret < 0 && count < 10)
105        {
106                count++;
107                sleep(1);
108        }
109        ret = dnode->ret;
110        free(dnode); dnode = NULL;
111
112        if(fromthread == 1)
113        {
114                clearscreennolock(download);
115                restorescreen(bg, download);
116                blitfb(0);
117                sleep(1);
118                status.rcowner = NULL;
119                m_unlock(&status.rcmutex, 10);
120                m_unlock(&status.drawingmutex, 0);
121        }
122        else
123        {
124                clearscreen(download);
125                drawscreen(skin, 0, 0);
126        }
127
128        debug(1000, "out");
129
130        return ret;
131}
132
133#endif
Note: See TracBrowser for help on using the repository browser.