summaryrefslogtreecommitdiffstats
path: root/src/common/cli/cli_log.cpp
blob: 603d5f8539a245476efc068eba0d2aaa4ff47891 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/***************************************************************************
 *   Copyright (C) 2005-2007 Nicolas Hadacek <hadacek@kde.org>             *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/
#include "cli_log.h"

#include "common/global/global.h"
#include "cli_global.h"

void CLI::View::doLog(Log::LineType type, const QString &text, Log::Action)
{
  QString s = text + "\n";
  switch (type.type()) {
    case Log::LineType::Error:
    case Log::LineType::SoftError: s = "Error: " + s; break;
    case Log::LineType::Warning: s = "Warning: " + s; break;
    default: break;
  }
#if QT_VERSION<0x040000
  if ( type==Log::LineType::Error || type==Log::LineType::SoftError ) fprintf(stderr, "%s", s.latin1());
  else fprintf(stdout, "%s", s.latin1());
#else
  QByteArray ba = s.toLatin1();
  if ( type==Log::LineType::Error || type==Log::LineType::SoftError ) fprintf(stderr, "%s", ba.constData());
  else fprintf(stdout, "%s", ba.constData());
#endif
}

void CLI::View::doLog(Log::DebugLevel, const QString &text, Log::Action)
{
  QString s = text + "\n";
#if QT_VERSION<0x040000
  fprintf(stdout, "%s", s.latin1());
#else
  QByteArray ba = s.toLatin1();
  fprintf(stdout, "%s", ba.constData());
#endif
}

void CLI::View::appendToLastLine(const QString &text)
{
#if QT_VERSION<0x040000
  fprintf(stdout, "%s", text.latin1());
#else
  QByteArray ba = text.toLatin1();
  fprintf(stdout, "%s", ba.constData());
#endif
}

void CLI::View::sorry(const QString &message, const QString &details)
{
  if ( details.isEmpty() ) log(Log::LineType::Error, message, Log::Immediate);
  else log(Log::LineType::Error, message + " (" + details + ")", Log::Immediate);
}

bool CLI::View::askContinue(const QString &message)
{
  log(Log::LineType::Warning, message + " " + (_force ? i18n("*yes*") : i18n("*no*")), Log::Immediate);
  if (_force) return true;
  if ( !_isInteractive ) return false; // always fail
  // #### TODO
  return false;
}

void CLI::View::logUserAbort()
{
  if ( !_isInteractive ) return;
  return;
  //Log::View::logUserAbort();
}