1 /*
2    mkvmerge GUI -- utility for splicing together matroska files
3    from component media subtypes
4 
5    Distributed under the GPL v2
6    see the file COPYING for details
7    or visit https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
8 
9    Matroska file analyzer (Qt interface)
10 
11    Written by Moritz Bunkus <moritz@bunkus.org>.
12 */
13 
14 #include "common/common_pch.h"
15 
16 #include <QMessageBox>
17 
18 #include "common/qt.h"
19 #include "mkvtoolnix-gui/util/kax_analyzer.h"
20 
21 namespace mtx::gui::Util {
22 
KaxAnalyzer(QWidget * parent,QString const & fileName)23 KaxAnalyzer::KaxAnalyzer(QWidget *parent,
24                              QString const &fileName)
25   : kax_analyzer_c{to_utf8(fileName)}
26   , m_parent{parent}
27 {
28 }
29 
30 void
show_progress_start(int64_t size)31 KaxAnalyzer::show_progress_start(int64_t size) {
32   m_size           = size;
33   m_progressDialog = std::make_unique<QProgressDialog>(QY("The file is being analyzed."), QY("Cancel"), 0, 100, m_parent);
34   m_progressDialog->setWindowModality(Qt::WindowModal);
35 }
36 
37 bool
show_progress_running(int percentage)38 KaxAnalyzer::show_progress_running(int percentage) {
39   if (!m_progressDialog)
40     return false;
41 
42   m_progressDialog->setValue(percentage);
43   return !m_progressDialog->wasCanceled();
44 }
45 
46 void
show_progress_done()47 KaxAnalyzer::show_progress_done() {
48   if (m_progressDialog)
49     m_progressDialog->setValue(100);
50   m_progressDialog.reset();
51 }
52 
53 void
displayUpdateElementResult(QWidget * parent,update_element_result_e result,QString const & message)54 KaxAnalyzer::displayUpdateElementResult(QWidget *parent,
55                                           update_element_result_e result,
56                                           QString const &message) {
57   switch (result) {
58     case kax_analyzer_c::uer_success:
59       return;
60 
61     case kax_analyzer_c::uer_error_segment_size_for_element:
62       QMessageBox::critical(parent, QY("Error writing Matroska file"),
63                             Q("%1 %2").arg(message).arg(QY("The element was written at the end of the file, but the segment size could not be updated. Therefore the element will not be visible. "
64                                                            "The process will be aborted. The file has been changed!")));
65       return;
66 
67     case kax_analyzer_c::uer_error_segment_size_for_meta_seek:
68       QMessageBox::critical(parent, QY("Error writing Matroska file"),
69                             Q("%1 %2").arg(message).arg(QY("The meta seek element was written at the end of the file, but the segment size could not be updated. Therefore the element will not be visible. "
70                                                            "The process will be aborted. The file has been changed!")));
71       return;
72 
73     case kax_analyzer_c::uer_error_meta_seek:
74       QMessageBox::warning(parent, QY("File structure warning"),
75                            Q("%1 %2").arg(message).arg(QY("The Matroska file was modified, but the meta seek entry could not be updated. This means that players might have a hard time finding the element. "
76                                                           "Please use your favorite player to check this file.")));
77       return;
78 
79     case kax_analyzer_c::uer_error_opening_for_reading:
80       QMessageBox::critical(parent, QY("Error reading Matroska file"),
81                             Q("%1 %2 %3")
82                             .arg(message)
83                             .arg(QY("The file could not be opened for reading."))
84                             .arg(QY("Possible reasons are: the file is not a Matroska file; the file is write-protected; the file is locked by another process; you do not have permission to access the file.")));
85       return;
86 
87     case kax_analyzer_c::uer_error_opening_for_writing:
88       QMessageBox::critical(parent, QY("Error writing Matroska file"),
89                             Q("%1 %2 %3")
90                             .arg(message)
91                             .arg(QY("The file could not be opened for writing."))
92                             .arg(QY("Possible reasons are: the file is not a Matroska file; the file is write-protected; the file is locked by another process; you do not have permission to access the file.")));
93       return;
94 
95     case kax_analyzer_c::uer_error_fixing_last_element_unknown_size_failed:
96       QMessageBox::critical(parent, QY("Error writing Matroska file"),
97                             Q("%1 %2 %3 %4 %5 %6")
98                             .arg(message)
99                             .arg(QY("The Matroska file's last element is set to an unknown size."))
100                             .arg(QY("Due to the particular structure of the file this situation cannot be fixed automatically."))
101                             .arg(QY("The file can be fixed by multiplexing it with mkvmerge again."))
102                             .arg(QY("The process will be aborted."))
103                             .arg(QY("The file has not been modified.")));
104       return;
105 
106     default:
107       QMessageBox::critical(parent, QY("Internal program error"), Q("%1 %2").arg(message).arg(QY("An unknown error occurred. The file has been modified.")));
108   }
109 }
110 
111 }
112