~ubuntu-branches/debian/experimental/nzbget/experimental

« back to all changes in this revision

Viewing changes to ColoredFrontend.cpp

  • Committer: Package Import Robot
  • Author(s): Andreas Moog
  • Date: 2014-12-25 12:58:06 UTC
  • mfrom: (1.2.1) (3.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20141225125806-vnzgajhm7mju9933
Tags: 14.1+dfsg-1
* New Upstream release (Closes: #768863)
* debian/patches:
  - Remove 0010_unnecessary_gcryptdep.patch, included upstream
  - Refresh remaining patches
* debian/control:
  - Remove no longer needed build-depends on libpar2-dev and libsigc++-dev
* debian/nzbget.conf
  - Update sample configuration file to include new options introduced by
    new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  This file if part of nzbget
3
 
 *
4
 
 *  Copyright (C) 2004 Sven Henkel <sidddy@users.sourceforge.net>
5
 
 *  Copyright (C) 2007-2010 Andrey Prygunkov <hugbug@users.sourceforge.net>
6
 
 *
7
 
 *  This program is free software; you can redistribute it and/or modify
8
 
 *  it under the terms of the GNU General Public License as published by
9
 
 *  the Free Software Foundation; either version 2 of the License, or
10
 
 *  (at your option) any later version.
11
 
 *
12
 
 *  This program is distributed in the hope that it will be useful,
13
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 *  GNU General Public License for more details.
16
 
 *
17
 
 *  You should have received a copy of the GNU General Public License
18
 
 *  along with this program; if not, write to the Free Software
19
 
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 
 *
21
 
 * $Revision: 544 $
22
 
 * $Date: 2013-01-18 22:36:17 +0100 (Fri, 18 Jan 2013) $
23
 
 *
24
 
 */
25
 
 
26
 
 
27
 
#ifdef HAVE_CONFIG_H
28
 
#include "config.h"
29
 
#endif
30
 
 
31
 
#ifdef WIN32
32
 
#include "win32.h"
33
 
#endif
34
 
 
35
 
#include <stdlib.h>
36
 
#include <string.h>
37
 
#include <stdio.h>
38
 
#ifndef WIN32
39
 
#include <unistd.h>
40
 
#endif
41
 
 
42
 
#include "nzbget.h"
43
 
#include "ColoredFrontend.h"
44
 
#include "Util.h"
45
 
 
46
 
ColoredFrontend::ColoredFrontend()
47
 
{
48
 
        m_bSummary = true;
49
 
        m_bNeedGoBack = false;
50
 
#ifdef WIN32
51
 
        m_hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
52
 
#endif
53
 
}
54
 
 
55
 
void ColoredFrontend::BeforePrint()
56
 
{
57
 
        if (m_bNeedGoBack)
58
 
        {
59
 
                // go back one line
60
 
#ifdef WIN32
61
 
                CONSOLE_SCREEN_BUFFER_INFO BufInfo;
62
 
                GetConsoleScreenBufferInfo(m_hConsole, &BufInfo);
63
 
                BufInfo.dwCursorPosition.Y--;
64
 
                SetConsoleCursorPosition(m_hConsole, BufInfo.dwCursorPosition);
65
 
#else
66
 
                printf("\r\033[1A");
67
 
#endif
68
 
                m_bNeedGoBack = false;
69
 
        }
70
 
}
71
 
 
72
 
void ColoredFrontend::PrintStatus()
73
 
{
74
 
        char tmp[1024];
75
 
        char timeString[100];
76
 
        timeString[0] = '\0';
77
 
        int iCurrentDownloadSpeed = m_bStandBy ? 0 : m_iCurrentDownloadSpeed;
78
 
 
79
 
        if (iCurrentDownloadSpeed > 0 && !(m_bPauseDownload || m_bPauseDownload2))
80
 
        {
81
 
                long long remain_sec = (long long)(m_lRemainingSize / iCurrentDownloadSpeed);
82
 
                int h = (int)(remain_sec / 3600);
83
 
                int m = (int)((remain_sec % 3600) / 60);
84
 
                int s = (int)(remain_sec % 60);
85
 
                sprintf(timeString, " (~ %.2d:%.2d:%.2d)", h, m, s);
86
 
        }
87
 
 
88
 
        char szDownloadLimit[128];
89
 
        if (m_iDownloadLimit > 0)
90
 
        {
91
 
                sprintf(szDownloadLimit, ", Limit %.0f KB/s", (float)m_iDownloadLimit / 1024.0);
92
 
        }
93
 
        else
94
 
        {
95
 
                szDownloadLimit[0] = 0;
96
 
        }
97
 
 
98
 
    char szPostStatus[128];
99
 
    if (m_iPostJobCount > 0)
100
 
    {
101
 
        sprintf(szPostStatus, ", %i post-job%s", m_iPostJobCount, m_iPostJobCount > 1 ? "s" : "");
102
 
    }
103
 
    else
104
 
    {
105
 
        szPostStatus[0] = 0;
106
 
    }
107
 
 
108
 
#ifdef WIN32
109
 
        char* szControlSeq = "";
110
 
#else
111
 
        printf("\033[s");
112
 
        const char* szControlSeq = "\033[K";
113
 
#endif
114
 
 
115
 
        snprintf(tmp, 1024, " %d threads, %.*f KB/s, %.2f MB remaining%s%s%s%s%s\n", 
116
 
                m_iThreadCount, (iCurrentDownloadSpeed >= 10*1024 ? 0 : 1), (float)iCurrentDownloadSpeed / 1024.0, 
117
 
                (float)(Util::Int64ToFloat(m_lRemainingSize) / 1024.0 / 1024.0), timeString, szPostStatus, 
118
 
                m_bPauseDownload || m_bPauseDownload2 ? (m_bStandBy ? ", Paused" : ", Pausing") : "",
119
 
                szDownloadLimit, szControlSeq);
120
 
        tmp[1024-1] = '\0';
121
 
        printf("%s", tmp);
122
 
        m_bNeedGoBack = true;
123
 
124
 
 
125
 
void ColoredFrontend::PrintMessage(Message * pMessage)
126
 
{
127
 
#ifdef WIN32
128
 
        switch (pMessage->GetKind())
129
 
        {
130
 
                case Message::mkDebug:
131
 
                        SetConsoleTextAttribute(m_hConsole, 8);
132
 
                        printf("[DEBUG]");
133
 
                        break;
134
 
                case Message::mkError:
135
 
                        SetConsoleTextAttribute(m_hConsole, 4);
136
 
                        printf("[ERROR]");
137
 
                        break; 
138
 
                case Message::mkWarning:
139
 
                        SetConsoleTextAttribute(m_hConsole, 5);
140
 
                        printf("[WARNING]");
141
 
                        break;
142
 
                case Message::mkInfo:
143
 
                        SetConsoleTextAttribute(m_hConsole, 2);
144
 
                        printf("[INFO]");
145
 
                        break;
146
 
                case Message::mkDetail:
147
 
                        SetConsoleTextAttribute(m_hConsole, 2);
148
 
                        printf("[DETAIL]");
149
 
                        break;
150
 
        }
151
 
        SetConsoleTextAttribute(m_hConsole, 7);
152
 
        char* msg = strdup(pMessage->GetText());
153
 
        CharToOem(msg, msg);
154
 
        printf(" %s\n", msg);
155
 
        free(msg);
156
 
#else
157
 
        const char* msg = pMessage->GetText();
158
 
        switch (pMessage->GetKind())
159
 
        {
160
 
                case Message::mkDebug:
161
 
                        printf("[DEBUG] %s\033[K\n", msg);
162
 
                        break;
163
 
                case Message::mkError:
164
 
                        printf("\033[31m[ERROR]\033[39m %s\033[K\n", msg);
165
 
                        break;
166
 
                case Message::mkWarning:
167
 
                        printf("\033[35m[WARNING]\033[39m %s\033[K\n", msg);
168
 
                        break;
169
 
                case Message::mkInfo:
170
 
                        printf("\033[32m[INFO]\033[39m %s\033[K\n", msg);
171
 
                        break;
172
 
                case Message::mkDetail:
173
 
                        printf("\033[32m[DETAIL]\033[39m %s\033[K\n", msg);
174
 
                        break;
175
 
        }
176
 
#endif
177
 
}
178
 
 
179
 
void ColoredFrontend::PrintSkip()
180
 
{
181
 
#ifdef WIN32
182
 
        printf(".....\n");
183
 
#else
184
 
        printf(".....\033[K\n");
185
 
#endif
186
 
}
187
 
 
188
 
void ColoredFrontend::BeforeExit()
189
 
{
190
 
        if (IsRemoteMode())
191
 
        {
192
 
                printf("\n");
193
 
        }
194
 
}