File: GUI_Preferences_Sheet.cpp

package info (click to toggle)
mediainfo 25.04-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 17,124 kB
  • sloc: cpp: 18,542; objc: 3,089; sh: 1,417; xml: 1,268; python: 319; makefile: 214; perl: 207
file content (304 lines) | stat: -rw-r--r-- 12,034 bytes parent folder | download | duplicates (2)
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*  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.
 */

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Preferences interface of MediaInfo
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//---------------------------------------------------------------------------
// Compilation condition
#ifndef MEDIAINFOGUI_PREFS_NO
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "GUI/VCL/GUI_Preferences_Sheet.h"
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#pragma resource "*.dfm"
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#include "Common/Preferences.h"
#ifdef MEDIAINFO_DLL_RUNTIME
    #include "MediaInfoDLL/MediaInfoDLL.h"
    #define MediaInfoNameSpace MediaInfoDLL
#elif defined MEDIAINFO_DLL_STATIC
    #include "MediaInfoDLL/MediaInfoDLL_Static.h"
    #define MediaInfoNameSpace MediaInfoDLL
#else
    #include "MediaInfo/MediaInfoList.h"
    #define MediaInfoNameSpace MediaInfoLib
#endif
//---------------------------------------------------------------------------


//***************************************************************************
// Constructor/Destructor
//***************************************************************************

//---------------------------------------------------------------------------
__fastcall TPreferences_SheetF::TPreferences_SheetF(TComponent* Owner)
    : TForm(Owner)
{
    Columns_Count=0;

    //Columns count
    for (int I1=0; I1<100; I1++)
        ColumnsCount->Items->Add(WideString(I1));
    ColumnsCount->ItemIndex=1;
}
//---------------------------------------------------------------------------

int TPreferences_SheetF::Run(const Ztring &Name)
{
    EditedSheet.Load(Prefs->BaseFolder+Prefs->FolderNames[Prefs_Sheet]+__T("\\")+Name+__T(".csv"));
    ColumnsCount->ItemIndex=EditedSheet(__T("ColumnsCount"), 1).To_int32s();
    Columns_Adapt();
    for (int Pos=0; Pos<Columns_Count; Pos++)
    {
        Ztring Z1=__T("Column");
        Z1+=Ztring::ToZtring(Pos);
        int ItemIndex;
        AnsiString A=EditedSheet(Z1, 1).c_str();
        //Kind
        ItemIndex=Column_Kind[Pos]->Items->IndexOf(EditedSheet(Z1, 1).c_str());
        if (ItemIndex!=-1)
            Column_Kind[Pos]->ItemIndex=ItemIndex;
        Column_Kind0Change(Column_Kind[Pos]);
        //Pos
        ItemIndex=Column_Pos[Pos]->Items->IndexOf(EditedSheet(Z1, 2).c_str());
        if (ItemIndex!=-1)
            Column_Pos[Pos]->ItemIndex=ItemIndex;
        Column_Pos0Change(Column_Kind[Pos]);
        //Parameter
        ItemIndex=Column_Parameter[Pos]->Items->IndexOf(EditedSheet(Z1, 3).c_str());
        if (ItemIndex!=-1)
            Column_Parameter[Pos]->ItemIndex=ItemIndex;
        Column_Parameter0Change(Column_Parameter[Pos]);
        //Size
        ItemIndex=Column_Size[Pos]->Items->IndexOf(EditedSheet(Z1, 4).c_str());
        if (ItemIndex!=-1)
            Column_Size[Pos]->ItemIndex=ItemIndex;
    }
    Column_Size0Change(NULL);
    Sheet_Show->Cells[0][1]="(Example)";

    return ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall TPreferences_SheetF::ColumnsCountChange(TObject *Sender)
{
    EditedSheet(__T("ColumnsCount"))=GUI_Text(ColumnsCount->Text);
    Columns_Adapt();
}
//---------------------------------------------------------------------------

void TPreferences_SheetF::Columns_Adapt()
{
    int Before=Columns_Count;
    Columns_Count=EditedSheet(__T("ColumnsCount")).To_int32s();
    if (Columns_Count<0)
        Columns_Count=0;
    else if (Columns_Count>SHEETF_COLUMNS)
        Columns_Count=SHEETF_COLUMNS;

    if (Before<Columns_Count)
    {
        //More Columns
        for (int Pos=Before; Pos<Columns_Count; Pos++)
        {
            Column_Text[Pos]=new TLabel(this);
            Column_Text[Pos]->Parent=this;
            Column_Text[Pos]->Top=90+25*Pos;
            Column_Text[Pos]->Left=405;
            Column_Text[Pos]->Width=100;
            Column_Size[Pos]=new TComboBox(this);
            Column_Size[Pos]->Top=90+25*Pos;
            Column_Size[Pos]->Left=355;
            Column_Size[Pos]->Width=45;
            Column_Size[Pos]->Style=Stdctrls::csDropDownList;
            Column_Size[Pos]->OnChange=Column_Size0Change;
            Column_Size[Pos]->Parent=this;
            for (int I1=0; I1<100; I1++)
                Column_Size[Pos]->Items->Add(WideString(I1));
            Column_Size[Pos]->ItemIndex=10;
            Column_Parameter[Pos]=new TComboBox(this);
            Column_Parameter[Pos]->Top=90+25*Pos;
            Column_Parameter[Pos]->Left=205;
            Column_Parameter[Pos]->Style=Stdctrls::csDropDownList;
            Column_Parameter[Pos]->OnChange=Column_Parameter0Change;
            Column_Parameter[Pos]->Parent=this;
            Column_Pos[Pos]=new TComboBox(this);
            Column_Pos[Pos]->Top=90+25*Pos;
            Column_Pos[Pos]->Left=155;
            Column_Pos[Pos]->Width=45;
            Column_Pos[Pos]->Style=Stdctrls::csDropDownList;
            Column_Pos[Pos]->OnChange=Column_Pos0Change;
            Column_Pos[Pos]->Parent=this;
            for (int I1=0; I1<16; I1++)
                Column_Pos[Pos]->Items->Add(WideString(I1));
            Column_Pos[Pos]->ItemIndex=0;
            Column_Pos0Change(Column_Pos[Pos]);
            Column_Kind[Pos]=new TComboBox(this);
            Column_Kind[Pos]->Top=90+25*Pos;
            Column_Kind[Pos]->Left=5;
            Column_Kind[Pos]->Style=Stdctrls::csDropDownList;
            Column_Kind[Pos]->OnChange=Column_Kind0Change;
            Column_Kind[Pos]->Parent=this;
            Column_Kind[Pos]->Items->SetText(L"General\r\n"
                                             L"Video\r\n"
                                             L"Audio\r\n"
                                             L"Text\r\n"
                                             L"Chapters\r\n");
            Column_Kind[Pos]->ItemIndex=0;
            Column_Kind0Change(Column_Kind[Pos]);
        }
    }
    else
    {
        //Less columns
        for (int Pos=Before-1; Pos>=Columns_Count; Pos--)
        {
            delete Column_Text[Pos];
            delete Column_Size[Pos];
            delete Column_Parameter[Pos];
            delete Column_Pos[Pos];
            delete Column_Kind[Pos];
        }
    }

    //Manage Sheet_Show
    Column_Size0Change(NULL);
}
//---------------------------------------------------------------------------

void __fastcall TPreferences_SheetF::Column_Kind0Change(TObject *Sender)
{
    //Look for position of Sender
    int Pos=0;
    while (Sender!=Column_Kind[Pos])
        Pos++;
    //Set Pos to 0
    Column_Pos[Pos]->ItemIndex=0;

    //Fill Column_Parameter
    Column_Parameter[Pos]->Items->Clear();
    if (Column_Kind[Pos]->ItemIndex==0) //General
        Infos_Parameters[Pos].Write(Ztring(MediaInfoNameSpace::MediaInfo::Option_Static(__T("Info_Parameters_CSV"))).SubString(__T("General\r\n"), __T("\r\n\r\n")));
    if (Column_Kind[Pos]->ItemIndex==1) //Video
        Infos_Parameters[Pos].Write(Ztring(MediaInfoNameSpace::MediaInfo::Option_Static(__T("Info_Parameters_CSV"))).SubString(__T("Video\r\n"), __T("\r\n\r\n")));
    if (Column_Kind[Pos]->ItemIndex==2) //Audio
        Infos_Parameters[Pos].Write(Ztring(MediaInfoNameSpace::MediaInfo::Option_Static(__T("Info_Parameters_CSV"))).SubString(__T("Audio\r\n"), __T("\r\n\r\n")));
    if (Column_Kind[Pos]->ItemIndex==3) //Text
        Infos_Parameters[Pos].Write(Ztring(MediaInfoNameSpace::MediaInfo::Option_Static(__T("Info_Parameters_CSV"))).SubString(__T("Text\r\n"), __T("\r\n\r\n")));
    if (Column_Kind[Pos]->ItemIndex==4) //Chapters
        Infos_Parameters[Pos].Write(Ztring(MediaInfoNameSpace::MediaInfo::Option_Static(__T("Info_Parameters_CSV"))).SubString(__T("Chapters\r\n"), __T("")));
    for (size_t Info_Pos=0; Info_Pos<Infos_Parameters[Pos].size(); Info_Pos++)
        Column_Parameter[Pos]->Items->Add(Infos_Parameters[Pos].Read(Info_Pos, 0).c_str());
    Column_Parameter[Pos]->ItemIndex=0;
    Column_Parameter0Change(Column_Parameter[Pos]);
}
//---------------------------------------------------------------------------

void __fastcall TPreferences_SheetF::Column_Parameter0Change(TObject *Sender)
{
    //Look for position of Sender
    int Pos=0;
    while (Sender!=Column_Parameter[Pos])
        Pos++;

    //Fill Column_Text
    Column_Text[Pos]->Caption=Infos_Parameters[Pos](Column_Parameter[Pos]->ItemIndex, 1).c_str();

    //Fill Sheet_Show
    Sheet_Show->Cells[Pos][0]=Infos_Parameters[Pos](Column_Parameter[Pos]->ItemIndex, 0).c_str();
}
//---------------------------------------------------------------------------

void __fastcall TPreferences_SheetF::FormResize(TObject *Sender)
{
    OK->Left=ClientWidth-OK->Width;
    Cancel->Left=OK->Left-Cancel->Width;
}
//---------------------------------------------------------------------------

void __fastcall TPreferences_SheetF::OKClick(TObject *Sender)
{
    //Set count
    EditedSheet(__T("ColumnsCount"))=Ztring::ToZtring(Columns_Count);

    //Set lines
    for (int Pos=0; Pos<Columns_Count; Pos++)
    {
        Ztring Z1=__T("Column");
        Z1+=Ztring::ToZtring(Pos);
        EditedSheet(Z1, 1)=GUI_Text(Column_Kind[Pos]->Text);
        EditedSheet(Z1, 2)=GUI_Text(Column_Pos[Pos]->Text);
        EditedSheet(Z1, 3)=GUI_Text(Column_Parameter[Pos]->Text);
        EditedSheet(Z1, 4)=GUI_Text(Column_Size[Pos]->Text);
    }

    //Delete extra lines no more needed
    for (int Pos=SHEETF_COLUMNS-1; Pos>=Columns_Count; Pos--)
    {
        Ztring Z1=__T("Column");
        Z1+=Ztring::ToZtring(Pos);
        int I1=EditedSheet.Find(Z1);
        if (I1!=-1)
            EditedSheet.erase(EditedSheet.begin()+I1);
    }

    //TODO: Purge blank lines, but why is there blank lines?
    while (EditedSheet.Find(__T(""))!=-1)
    {
        int I1=EditedSheet.Find(__T(""));
        EditedSheet.erase(EditedSheet.begin()+I1);
    }

    //Save file
    EditedSheet.Save();
}
//---------------------------------------------------------------------------

void __fastcall TPreferences_SheetF::Column_Size0Change(TObject *Sender)
{
    //Sum of sizes
    int Total=0;
    for (int Pos=0; Pos<Columns_Count; Pos++)
    #ifdef UNICODE
        Total+=Ztring(WideString(Column_Size[Pos]->Text).c_bstr()).To_int32s();
    #else
        Total+=Ztring().From_Unicode(Column_Size[Pos]->Text.c_bstr()).To_int32s();
    #endif

    //Adapt column sizes
    Sheet_Show->ColCount=Columns_Count;
    for (int Pos=0; Pos<Columns_Count; Pos++)
    #ifdef UNICODE
         Sheet_Show->ColWidths[Pos]=Ztring(WideString(Column_Size[Pos]->Text).c_bstr()).To_int32s()*Sheet_Show->ClientWidth/Total;
    #else
         Sheet_Show->ColWidths[Pos]=Ztring().From_Unicode(Column_Size[Pos]->Text.c_bstr()).To_int32s()*Sheet_Show->ClientWidth/Total;
    #endif
}
//---------------------------------------------------------------------------

void __fastcall TPreferences_SheetF::Column_Pos0Change(TObject *Sender)
{
    return;
}

//***************************************************************************
// C++
//***************************************************************************

#endif //MEDIAINFOGUI_PREFS_NO