|
| 1 | + |
1 | 2 | #include "rang.hpp"
|
2 |
| -#include "ffmpeg_coder.hpp" |
3 |
| -#include <iostream> |
4 |
| -#include <fstream> |
5 |
| -#include <vector> |
6 | 3 | #include "quickConvertSettings.hpp"
|
7 | 4 | #include "alib.hpp"
|
| 5 | +#include "ffmpeg_coder.hpp" |
| 6 | +#include <fstream> |
8 | 7 | #include <iomanip>
|
| 8 | +#include <iostream> |
| 9 | +#include <vector> |
| 10 | + |
| 11 | + |
| 12 | +void QC_Settings::set_setted_crf() { |
| 13 | + std::fstream qcsData; |
| 14 | + qcsData.open("appData/qcs_crf.bin", std::ios::in); |
9 | 15 |
|
| 16 | + if (qcsData.is_open()) { |
| 17 | + std::string def_crf; |
| 18 | + while (getline(qcsData, def_crf)) { def_crf = def_crf; } |
10 | 19 |
|
11 |
| -void QC_Settings::set_setted_crf(){ |
12 |
| - |
13 |
| - } |
| 20 | + if (def_crf == "20") |
| 21 | + setted_crf = 20; |
| 22 | + else if (def_crf == "24") |
| 23 | + setted_crf = 24; |
| 24 | + else if (def_crf == "26") |
| 25 | + setted_crf = 26; |
| 26 | + else if (def_crf == "28") |
| 27 | + setted_crf = 28; |
| 28 | + else |
| 29 | + setted_crf = 26; |
14 | 30 |
|
15 |
| -int QC_Settings::get_setted_crf(){ |
| 31 | + } else { |
| 32 | + setted_crf = 26; |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +int QC_Settings::get_setted_crf() { |
| 37 | + set_setted_crf(); |
16 | 38 | return setted_crf;
|
17 | 39 | }
|
18 | 40 |
|
19 |
| -void QC_Settings:: setDefault_encoding(){ |
20 |
| - std::fstream qcsData; |
21 |
| - qcsData.open("appData/qcs_encoding.bin", std::ios::in); |
22 |
| - |
23 |
| - if (qcsData.is_open()){ |
24 |
| - std::string def_encoding; |
25 |
| - while (getline(qcsData, def_encoding)) |
26 |
| - { |
27 |
| - default_encoding = def_encoding; |
28 |
| - } |
29 |
| - }else{ |
30 |
| - default_encoding = "h264"; |
31 |
| - } |
| 41 | +void QC_Settings::setDefault_encoding() { |
| 42 | + std::fstream qcsData; |
| 43 | + qcsData.open("appData/qcs_encoding.bin", std::ios::in); |
| 44 | + |
| 45 | + if (qcsData.is_open()) { |
| 46 | + std::string def_encoding; |
| 47 | + while (getline(qcsData, def_encoding)) { |
| 48 | + default_encoding = def_encoding; |
| 49 | + } |
| 50 | + } else { |
| 51 | + default_encoding = "h264"; |
| 52 | + } |
32 | 53 | }
|
33 | 54 |
|
34 |
| -std::string QC_Settings:: getDefault_encoding(){ |
| 55 | +std::string QC_Settings::getDefault_encoding() { |
35 | 56 | setDefault_encoding();
|
36 | 57 | return default_encoding;
|
37 | 58 | }
|
38 | 59 |
|
| 60 | +void QC_Settings::showOptions() { |
| 61 | + clear_screen(); |
| 62 | + std::vector<std::string> options; |
| 63 | + options.push_back("Set Default Encoding"); |
| 64 | + options.push_back("Set default CRF"); |
39 | 65 |
|
40 |
| -void QC_Settings::showOptions(){ |
41 |
| - clear_screen(); |
42 |
| - std::vector<std::string> options; |
43 |
| - options.push_back("Set Default Encoding"); |
44 |
| - options.push_back("Set default CRF"); |
45 |
| - |
46 |
| - |
47 |
| - // Showing the options |
48 |
| - for (int i =0; i < options.size(); i++){ |
49 |
| - std::cout << (i+1) << ". " << options[i] << std::endl; |
50 |
| - } |
| 66 | + // Showing the options |
| 67 | + for (int i = 0; i < options.size(); i++) { |
| 68 | + std::cout << (i + 1) << ". " << options[i] << std::endl; |
| 69 | + } |
51 | 70 |
|
52 |
| - // Taking user input |
53 |
| - std::cout<< rang::style::bold << rang::fg::blue << "\nChoose your option: " |
54 |
| - << rang::style::reset << rang::fg::reset; |
55 |
| - std::cin >> userChoice; |
| 71 | + // Taking user input |
| 72 | + std::cout << rang::style::bold << rang::fg::blue |
| 73 | + << "\nChoose your option: " << rang::style::reset |
| 74 | + << rang::fg::reset; |
| 75 | + std::cin >> userChoice; |
56 | 76 | }
|
57 | 77 |
|
| 78 | +void QC_Settings::settingsDataWriter(std::string filePath, |
| 79 | + std::string settings) { |
| 80 | + try { |
| 81 | + std::fstream qcsData; |
| 82 | + qcsData.open(filePath, std::ios::out); |
58 | 83 |
|
59 |
| -void QC_Settings:: settingsDataWriter(std::string filePath, std::string settings){ |
60 |
| -try |
61 |
| - { |
62 |
| - std::fstream qcsData; |
63 |
| - qcsData.open(filePath, std::ios::out); |
64 |
| - |
65 |
| - if (qcsData.is_open()){ |
66 |
| - qcsData << settings; |
| 84 | + if (qcsData.is_open()) { |
| 85 | + qcsData << settings; |
67 | 86 |
|
68 |
| - std::cout<<"\n|You preferred settings have been saved for future|"; |
69 |
| - } |
70 |
| - else |
71 |
| - throw 501; |
72 |
| - } |
73 |
| - catch(...) |
74 |
| - { |
75 |
| - std::cerr << "Error occured while openning data file!"; |
76 |
| - } |
| 87 | + std::cout |
| 88 | + << "\n|You preferred settings have been saved for future|"; |
| 89 | + } else |
| 90 | + throw 501; |
| 91 | + } catch (...) { std::cerr << "Error occured while openning data file!"; } |
77 | 92 | }
|
78 | 93 |
|
79 |
| -void QC_Settings::default_encoding_configurer(){ |
80 |
| - clear_screen(); |
81 |
| - std::string givenEncoding; |
82 |
| - int selectedOption; |
83 |
| - |
84 |
| - // Showing the current default encoding |
85 |
| - std::string currentDef = "The current default is: "+default_encoding; |
86 |
| - alib::decorateMe(currentDef,1," ",true); |
87 |
| - |
88 |
| - // Taking new encoding from user |
89 |
| - ffmpeg *fmpg = new ffmpeg(); |
90 |
| - fmpg->load_encodes(); |
91 |
| - fmpg->show_encodes(); |
92 |
| - selectedOption = fmpg->select_encodes(); |
93 |
| - |
94 |
| - if (selectedOption == 1){ |
95 |
| - settingsDataWriter("appData/qcs_encoding.bin", fmpg->encodes[0]); |
96 |
| - } |
97 |
| - else if(selectedOption == 2){ |
98 |
| - settingsDataWriter("appData/qcs_encoding.bin", fmpg->encodes[1]); |
99 |
| - } |
100 |
| - else |
101 |
| - std::cerr << "\nInvalid Option Selected ! Try again"; |
| 94 | +void QC_Settings::default_encoding_configurer() { |
| 95 | + clear_screen(); |
| 96 | + std::string givenEncoding; |
| 97 | + int selectedOption; |
| 98 | + |
| 99 | + // Showing the current default encoding |
| 100 | + std::string currentDef = "The current default is: " + default_encoding; |
| 101 | + alib::decorateMe(currentDef, 1, " ", true); |
| 102 | + |
| 103 | + // Taking new encoding from user |
| 104 | + ffmpeg *fmpg = new ffmpeg(); |
| 105 | + fmpg->load_encodes(); |
| 106 | + fmpg->show_encodes(); |
| 107 | + selectedOption = fmpg->select_encodes(); |
| 108 | + |
| 109 | + if (selectedOption == 1) { |
| 110 | + settingsDataWriter("appData/qcs_encoding.bin", fmpg->encodes[0]); |
| 111 | + } else if (selectedOption == 2) { |
| 112 | + settingsDataWriter("appData/qcs_encoding.bin", fmpg->encodes[1]); |
| 113 | + } else |
| 114 | + std::cerr << "\nInvalid Option Selected ! Try again"; |
102 | 115 | }
|
103 | 116 |
|
104 |
| -void QC_Settings::default_crf_configurer(){ |
105 |
| - |
| 117 | +void QC_Settings::default_crf_configurer() { |
| 118 | + clear_screen(); |
| 119 | + std::string givenCrf; |
| 120 | + int selectedOption; |
| 121 | + |
| 122 | + // Showing the current default encoding |
| 123 | + std::string currentDef = "The current default is: 26"; |
| 124 | + alib::decorateMe(currentDef, 1, " ", true); |
| 125 | + |
| 126 | + // Taking new encoding from user |
| 127 | + ffmpeg *fmpg = new ffmpeg(); |
| 128 | + fmpg->select_crf(); |
| 129 | + selectedOption = fmpg->selected_crf; |
| 130 | + |
| 131 | + if (selectedOption == 20) |
| 132 | + settingsDataWriter("appData/qcs_crf.bin","20"); |
| 133 | + else if (selectedOption == 24) |
| 134 | + settingsDataWriter("appData/qcs_crf.bin","24"); |
| 135 | + else if (selectedOption == 26) |
| 136 | + settingsDataWriter("appData/qcs_crf.bin","26"); |
| 137 | + else if (selectedOption == 28) |
| 138 | + settingsDataWriter("appData/qcs_crf.bin","28"); |
| 139 | + else |
| 140 | + settingsDataWriter("appData/qcs_crf.bin","26"); |
106 | 141 | }
|
107 | 142 |
|
108 |
| -void QC_Settings::optionsRouter(){ |
109 |
| - if (userChoice == 1) |
110 |
| - default_encoding_configurer(); |
111 |
| - else if (userChoice == 2) |
112 |
| - default_crf_configurer(); |
113 |
| - else |
114 |
| - std::cout<<"Invalid choice. Try again" |
| 143 | +void QC_Settings::optionsRouter() { |
| 144 | + if (userChoice == 1) |
| 145 | + default_encoding_configurer(); |
| 146 | + else if (userChoice == 2) |
| 147 | + default_crf_configurer(); |
| 148 | + else |
| 149 | + std::cout << "\nInvalid choice. Try again\n"; |
115 | 150 | }
|
0 commit comments