File: ReportViewModel.cpp

package info (click to toggle)
mediainfo 20.09-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 14,732 kB
  • sloc: cpp: 15,682; objc: 2,760; sh: 1,343; xml: 926; python: 259; perl: 207; makefile: 173
file content (174 lines) | stat: -rw-r--r-- 6,599 bytes parent folder | download | duplicates (4)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
*  Use of this source code is governed by a BSD-style license that can
*  be found in the License.html file in the root of the source tree.
*/

//---------------------------------------------------------------------------
#include "pch.h"
#include "ReportViewModel.h"

#include "ZenLib/Ztring.h"

//---------------------------------------------------------------------------
using namespace ZenLib;
using namespace MediaInfo;
using namespace MediaInfoLib;

//---------------------------------------------------------------------------
// Constructor/Destructor
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
ReportViewModel::ReportViewModel(Report^ SourceReport)
{
    Source=SourceReport;
}

//---------------------------------------------------------------------------
// Properties
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
Report^ ReportViewModel::Source::get()
{
    return _Source;
}

//---------------------------------------------------------------------------
void ReportViewModel::Source::set(Report^ Value)
{
    _Source=Value;

    _MI.Close();

    if (Value && Value->Data)
    {
        _MI.Option(__T("Input_Compressed"), __T("zlib+base64"));

        Ztring Input(Value->Data->Data());

        _MI.Open_Buffer_Init(Input.To_UTF8().length(), 0L);
        _MI.Open_Buffer_Continue((int8u*)Input.To_UTF8().c_str(), Input.To_UTF8().length());
        _MI.Open_Buffer_Finalize();
    }
}

//---------------------------------------------------------------------------
Platform::String^ ReportViewModel::ReportText::get()
{
    if (!_Source || !Source->Data)
        return L"";

    return Inform(AppCore::View, true);
}

//---------------------------------------------------------------------------
Platform::String^ ReportViewModel::ReportHtml::get()
{
    if (!_Source || !Source->Data)
        return L"";

    if (AppCore::View==L"HTML")
       return Inform(AppCore::View, false);

    ZenLib::Ztring Content=ZenLib::Ztring(Inform(AppCore::View, false)->Data());
    Content.FindAndReplace(__T("\t"), __T("    "), 0, ZenLib::Ztring_Recursive);
    Content.FindAndReplace(__T("<"), __T("&lt;"), 0, ZenLib::Ztring_Recursive);
    Platform::String^ ToReturn=ref new Platform::String();
    ToReturn+=L"<html><head></head><body><pre>";
    ToReturn+=ref new Platform::String(Content.c_str());
    ToReturn+="</pre></body></html>";

    return ToReturn;
}

//---------------------------------------------------------------------------
// Functions
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
Platform::String^ ReportViewModel::Summary(size_t StreamKind, size_t StreamNumber)
{
    _MI.Option(__T("Inform"), __T("Summary"));
    Ztring Output=_MI.Get(static_cast<stream_t>(StreamKind), StreamNumber, __T("Inform"));

    return ref new Platform::String(Output.c_str());
}

//---------------------------------------------------------------------------
Platform::String^ ReportViewModel::Inform(Platform::String ^ Format, bool Export)
{
    if (Format==L"Easy")
        Format=L"Text";

    _MI.Option(__T("Inform_Compress"), __T(""));
    _MI.Option(__T("Inform"), Ztring().From_Unicode(Format->Data()));

    if (Format=="Text" && !Export)
        _MI.Option(__T("Language"), __T("  Config_Text_ColumnSize;25"));
    else
        _MI.Option(__T("Language"), __T("  Config_Text_ColumnSize;40")); // TODO: reset value

    Ztring Output=_MI.Inform();

    _MI.Option(__T("Language"), __T("  Config_Text_ColumnSize;40")); // TODO: reset value

    return ref new Platform::String(Output.c_str());
}

//---------------------------------------------------------------------------
Platform::String^ ReportViewModel::Inform_Get(size_t StreamKind, size_t StreamPos)
{
    _MI.Option(__T("Inform_Compress"), __T(""));
    _MI.Option(__T("Inform"), __T(""));

    Ztring Output=_MI.Get(static_cast<stream_t>(StreamKind), StreamPos, __T("Inform"));

    return ref new Platform::String(Output.c_str());
}

Platform::String^ ReportViewModel::GetI(size_t StreamKind, size_t StreamNumber, size_t Parameter)
{
    return GetI(StreamKind, StreamNumber, Parameter, static_cast<size_t>(MediaInfoLib::Info_Text));
}

//---------------------------------------------------------------------------
Platform::String^ ReportViewModel::GetI(size_t StreamKind, size_t StreamNumber, size_t Parameter, size_t InfoKind)
{
    Ztring Output=_MI.Get(static_cast<stream_t>(StreamKind), StreamNumber, Parameter, static_cast<info_t>(InfoKind));

    return ref new Platform::String(Output.c_str());
}

//---------------------------------------------------------------------------
Platform::String^ ReportViewModel::Get(size_t StreamKind, size_t StreamNumber, Platform::String^ Parameter, size_t InfoKind, size_t SearchKind)
{
    Ztring Output=_MI.Get(static_cast<stream_t>(StreamKind), StreamNumber, Parameter->Data(), static_cast<info_t>(InfoKind), static_cast<info_t>(SearchKind));

    return ref new Platform::String(Output.c_str());
}

//---------------------------------------------------------------------------
Platform::String^ ReportViewModel::Get(size_t StreamKind, size_t StreamNumber, Platform::String^ Parameter, size_t InfoKind)
{
    return Get(StreamKind, StreamNumber, Parameter, InfoKind, static_cast<size_t>(MediaInfoLib::Info_Name));
}

//---------------------------------------------------------------------------
Platform::String^ ReportViewModel::Get(size_t StreamKind, size_t StreamNumber, Platform::String^ Parameter)
{
    return Get(StreamKind, StreamNumber, Parameter, static_cast<size_t>(MediaInfoLib::Info_Text), static_cast<size_t>(MediaInfoLib::Info_Name));
}

//---------------------------------------------------------------------------
size_t ReportViewModel::Count_Get(size_t StreamKind, size_t StreamNumber)
{
    return _MI.Count_Get(static_cast<stream_t>(StreamKind), StreamNumber);
}

//---------------------------------------------------------------------------
size_t ReportViewModel::Count_Get(size_t StreamKind)
{
    return _MI.Count_Get(static_cast<stream_t>(StreamKind), static_cast<size_t>(-1));
}