File: editconfigtreetext.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 (89 lines) | stat: -rw-r--r-- 2,898 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
/*  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 "editconfigtreetext.h"
#include "ui_editconfigtreetext.h"

#include "configtreetext.h"
#include "Common/Core.h"
#include <QCheckBox>

#include <ZenLib/Ztring.h>
using namespace ZenLib;
#define wstring2QString(_DATA) \
    QString::fromUtf8(Ztring(_DATA).To_UTF8().c_str())
#define QString2wstring(_DATA) \
    Ztring().From_UTF8(_DATA.toUtf8())

EditConfigTreeText::EditConfigTreeText(ConfigTreeText* ctt, Core* C, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::editConfigTreeText)
{
    ui->setupUi(this);
    this->C = C;
    this->ctt = ctt;
    fillToolBox();
    ui->lineEdit->setText(ctt->getName());
}

EditConfigTreeText::~EditConfigTreeText()
{
    delete ui;
}

void EditConfigTreeText::fillToolBox() {
    for(;ui->toolBox->count()>0;ui->toolBox->removeItem(0));

    for (int streamKind=0; streamKind<(int)Stream_Max; streamKind++) {
        if(streamKind==Stream_Other)
            continue;
        QFrame* box = new QFrame();
        qDebug() << "adding " << wstring2QString(C->StreamName((stream_t)streamKind));
        ui->toolBox->addItem(box,wstring2QString(C->StreamName((stream_t)streamKind)));
        QString s = wstring2QString(C->Parameters());
        s.replace("\r\n","\n").replace("\r","\n");
        s.remove(0,s.indexOf(wstring2QString(C->StreamName((stream_t)streamKind))+"\n"));
        s.truncate((s.indexOf("\n\n")==-1?s.size():s.indexOf("\n\n")));
        QStringList sl = s.split("\n");
        sl.removeAt(0);
        sl.replaceInStrings(QRegExp(";(.*)"),"");
        box->setLayout(new QVBoxLayout());
        for (int i=0; i<sl.size(); ++i) {
            QCheckBox* check = new QCheckBox(sl.at(i));
            check->setChecked(ctt->getFields(streamKind).contains(sl.at(i)));
            box->layout()->addWidget(check);
        }
    }
}

void EditConfigTreeText::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void EditConfigTreeText::apply() {
    ctt->setName(ui->lineEdit->text());

    for (int i=0; i<ui->toolBox->count(); i++) {
        for (int j=0; j<ui->toolBox->widget(i)->layout()->count(); ++j) {
            if(((QCheckBox*)ui->toolBox->widget(i)->layout()->itemAt(j)->widget())->isChecked()) {
                ctt->addField(i,((QCheckBox*)ui->toolBox->widget(i)->layout()->itemAt(j)->widget())->text());
                qDebug() << ctt->getFields(i).join(", ");
            } else {
                ctt->removeField(i,((QCheckBox*)ui->toolBox->widget(i)->layout()->itemAt(j)->widget())->text());
            }
        }
    }

    qDebug() << "Applying settings";
}