| 1 |
/* dvbcut settings |
| 2 |
Copyright (c) 2006 - 2009 Michael Riepe |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU General Public License as published by |
| 6 |
the Free Software Foundation; either version 2 of the License, or |
| 7 |
(at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program; if not, write to the Free Software |
| 16 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 |
*/ |
| 18 |
|
| 19 |
/* $Id$ */ |
| 20 |
|
| 21 |
#include <string> |
| 22 |
#include <vector> |
| 23 |
|
| 24 |
#include <qstringlist.h> |
| 25 |
|
| 26 |
#include <assert.h> |
| 27 |
|
| 28 |
#include "defines.h" |
| 29 |
#include "settings.h" |
| 30 |
|
| 31 |
#define DVBCUT_QSETTINGS_DOMAIN "dvbcut.sf.net" |
| 32 |
#define DVBCUT_QSETTINGS_PRODUCT "dvbcut" |
| 33 |
#define DVBCUT_QSETTINGS_PATH "/" DVBCUT_QSETTINGS_DOMAIN "/" DVBCUT_QSETTINGS_PRODUCT "/" |
| 34 |
|
| 35 |
#define DVBCUT_DEFAULT_PIPE_COMMAND \ |
| 36 |
"|dvdauthor -t -c '%CHAPTERS%' -v mpeg2 -o '%OUTPUT%' -" |
| 37 |
#define DVBCUT_DEFAULT_PIPE_POST \ |
| 38 |
"dvdauthor -o '%OUTPUT%' -T" |
| 39 |
#define DVBCUT_DEFAULT_PIPE_LABEL \ |
| 40 |
"DVD-Video titleset (dvdauthor)" |
| 41 |
#define DVBCUT_DEFAULT_PIPE_FORMAT (0) |
| 42 |
#define DVBCUT_DEFAULT_SEARCH_DUPS_RANGE 1500 |
| 43 |
/* |
| 44 |
// SOME OTHER EXAMPLES for the settings file ~/.qt/dvbcut.sf.netrc |
| 45 |
// (ok, for time consuming conversions one does not save any time, but it may be convenient...) |
| 46 |
// 1. Conversion to mpeg4 avi-file with ffmpeg: |
| 47 |
// (to recode to a smaller MPEG2 File use "--target dvd -acodec copy"?)! |
| 48 |
pipe/1/command=|ffmpeg -f mpeg2video -i - -f avi -vcodec mpeg4 -b 1200k -g 250 -bf 2 -acodec libmp3lame -ab 128k -ar 44100 '%OUTPUT%' |
| 49 |
pipe/1/format=1 |
| 50 |
pipe/1/label=MPEG-4/ASP (ffmpeg) |
| 51 |
pipe/1/post= |
| 52 |
// 2. Shrinking with vamps by 20%, before piping to dvdauthor: |
| 53 |
pipe/2/command=| vamps -E 1.2 -S 10000000000 -a 1,2,3 | dvdauthor -t -c '%CHAPTERS%' -v mpeg2 -o '%OUTPUT%' - |
| 54 |
pipe/2/format=0 |
| 55 |
pipe/2/label=20% shrinked DVD-Video titleset (vamps & dvdauthor) |
| 56 |
pipe/2/post=dvdauthor -o '%OUTPUT%' -T |
| 57 |
// 3. recoding to a (smaller?) MPEG2 file with DVD compliant resolution (ca. 3000kbps): |
| 58 |
pipe/3/command=|ffmpeg -f mpeg2video -i - --target dvd -qscale 3.0 -bf 2 -acodec copy '%OUTPUT%'" |
| 59 |
pipe/3/format=1 |
| 60 |
pipe/3/label=recoded DVD compliant video (ffmpeg) |
| 61 |
pipe/3/post= |
| 62 |
*/ |
| 63 |
|
| 64 |
dvbcut_settings::dvbcut_settings() : QSettings(DVBCUT_QSETTINGS_DOMAIN, DVBCUT_QSETTINGS_PRODUCT) { |
| 65 |
beginGroup("/" DVBCUT_QSETTINGS_DOMAIN "/" DVBCUT_QSETTINGS_PRODUCT); |
| 66 |
loaded = false; |
| 67 |
} |
| 68 |
|
| 69 |
dvbcut_settings::~dvbcut_settings() { |
| 70 |
if (loaded) { |
| 71 |
save_settings(); |
| 72 |
} |
| 73 |
endGroup(); |
| 74 |
} |
| 75 |
|
| 76 |
void |
| 77 |
dvbcut_settings::load_settings() { |
| 78 |
int version = value("/version", 0).toInt(); |
| 79 |
if (version >= 1) { |
| 80 |
// config format version 1 or later |
| 81 |
beginGroup("/wheel"); |
| 82 |
wheel_increments[WHEEL_INCR_NORMAL] = value("/incr_normal", 25*60).toInt(); |
| 83 |
wheel_increments[WHEEL_INCR_SHIFT] = value("/incr_shift", 25).toInt(); |
| 84 |
wheel_increments[WHEEL_INCR_CTRL] = value("/incr_ctrl", 1).toInt(); |
| 85 |
wheel_increments[WHEEL_INCR_ALT] = value("/incr_alt", 15*25*60).toInt(); |
| 86 |
wheel_threshold = value("/threshold", 24).toInt(); |
| 87 |
// Note: delta is a multiple of 120 (see Qt documentation) |
| 88 |
wheel_delta = value("/delta", 120).toInt(); |
| 89 |
if (wheel_delta == 0) |
| 90 |
wheel_delta = 1; // avoid devide by zero |
| 91 |
endGroup(); // wheel |
| 92 |
beginGroup("/slider"); |
| 93 |
jog_maximum = value("/jog_maximum", 180000).toInt(); |
| 94 |
jog_threshold = value("/jog_threshold", 50).toInt(); |
| 95 |
// to increase the "zero frames"-region of the jog-slider |
| 96 |
jog_offset = value("/jog_offset", 0.4).toDouble(); |
| 97 |
// sub-intervals of jog_maximum |
| 98 |
jog_interval = value("/jog_interval", 1).toInt(); |
| 99 |
if (jog_interval < 0) |
| 100 |
jog_interval = 0; |
| 101 |
lin_interval = value("/lin_interval", 3600).toInt(); |
| 102 |
if (lin_interval < 0) |
| 103 |
lin_interval = 0; |
| 104 |
endGroup(); // slider |
| 105 |
beginGroup("/lastdir"); |
| 106 |
lastdir = value("/name", ".").toString(); |
| 107 |
lastdir_update = value("/update", true).toBool(); |
| 108 |
endGroup(); // lastdir |
| 109 |
search_dups_range = value("/search_dups_range", DVBCUT_DEFAULT_SEARCH_DUPS_RANGE).toInt(); |
| 110 |
} |
| 111 |
else { |
| 112 |
// old (unnumbered) config format |
| 113 |
wheel_increments[WHEEL_INCR_NORMAL] = value("/wheel_incr_normal", 25*60).toInt(); |
| 114 |
wheel_increments[WHEEL_INCR_SHIFT] = value("/wheel_incr_shift", 25).toInt(); |
| 115 |
wheel_increments[WHEEL_INCR_CTRL] = value("/wheel_incr_ctrl", 1).toInt(); |
| 116 |
wheel_increments[WHEEL_INCR_ALT] = value("/wheel_incr_alt", 15*25*60).toInt(); |
| 117 |
wheel_threshold = value("/wheel_threshold", 24).toInt(); |
| 118 |
// Note: delta is a multiple of 120 (see Qt documentation) |
| 119 |
wheel_delta = value("/wheel_delta", 120).toInt(); |
| 120 |
if (wheel_delta == 0) |
| 121 |
wheel_delta = 1; // avoid devide by zero |
| 122 |
jog_maximum = value("/jog_maximum", 180000).toInt(); |
| 123 |
jog_threshold = value("/jog_threshold", 50).toInt(); |
| 124 |
// to increase the "zero frames"-region of the jog-slider |
| 125 |
jog_offset = value("/jog_offset", 0.4).toDouble(); |
| 126 |
// sub-intervals of jog_maximum |
| 127 |
jog_interval = value("/jog_interval", 1).toInt(); |
| 128 |
if (jog_interval < 0) |
| 129 |
jog_interval = 0; |
| 130 |
lin_interval = value("/lin_interval", 3600).toInt(); |
| 131 |
if (lin_interval < 0) |
| 132 |
lin_interval = 0; |
| 133 |
lastdir = value("/lastdir", ".").toString(); |
| 134 |
lastdir_update = true; |
| 135 |
// remove old-style entries |
| 136 |
remove("/wheel_incr_normal"); |
| 137 |
remove("/wheel_incr_shift"); |
| 138 |
remove("/wheel_incr_ctrl"); |
| 139 |
remove("/wheel_incr_alt"); |
| 140 |
remove("/wheel_threshold"); |
| 141 |
remove("/wheel_delta"); |
| 142 |
remove("/jog_maximum"); |
| 143 |
remove("/jog_threshold"); |
| 144 |
remove("/jog_offset"); |
| 145 |
remove("/jog_interval"); |
| 146 |
remove("/lin_interval"); |
| 147 |
remove("/lastdir"); |
| 148 |
remove("/idxfilter"); |
| 149 |
remove("/prjfilter"); |
| 150 |
remove("/loadfilter"); |
| 151 |
} |
| 152 |
if (version >= 2) { |
| 153 |
/* float view scale factor */ |
| 154 |
beginGroup("/viewscalefactor"); |
| 155 |
viewscalefactor = value("/current", 1.0).toDouble(); |
| 156 |
viewscalefactor_custom = value("/custom", 3.0).toDouble(); |
| 157 |
endGroup(); // viewscalefactor |
| 158 |
} |
| 159 |
else { |
| 160 |
viewscalefactor = (double)value("/viewscalefactor", 1).toInt(); |
| 161 |
viewscalefactor_custom = 3.0; |
| 162 |
remove("/viewscalefactor"); |
| 163 |
} |
| 164 |
export_format = value("/export_format", 0).toInt(); |
| 165 |
beginGroup("/recentfiles"); |
| 166 |
recentfiles_max = value("/max", 5).toInt(); |
| 167 |
recentfiles.clear(); |
| 168 |
std::list<std::string> filenames; |
| 169 |
beginGroup("/"); |
| 170 |
QStringList keys = childKeys(); |
| 171 |
for (unsigned int i = 0; i < recentfiles_max; ++i) { |
| 172 |
QString key = "/" + QString::number(i); |
| 173 |
if (version < 1 && keys.size()>1) { |
| 174 |
// OLD format (2 keys per input file, NO subkeys!) |
| 175 |
QString filename = value(key).toString(); |
| 176 |
if (filename.isEmpty()) |
| 177 |
continue; |
| 178 |
filenames.clear(); |
| 179 |
filenames.push_back(filename.toStdString()); |
| 180 |
QString idxfilename = value(key + "-idx", "").toString(); |
| 181 |
recentfiles.push_back( |
| 182 |
std::pair<std::list<std::string>,std::string>(filenames, idxfilename.toStdString())); |
| 183 |
} |
| 184 |
else { |
| 185 |
// NEW format with subkeys and multiple files! |
| 186 |
beginGroup(key); |
| 187 |
QString filename = value("/0").toString(); |
| 188 |
if (!filename.isEmpty()) { |
| 189 |
// multiple input files? |
| 190 |
int j=0; |
| 191 |
filenames.clear(); |
| 192 |
while(!filename.isEmpty()) { |
| 193 |
filenames.push_back(filename.toStdString()); |
| 194 |
filename = value("/" + QString::number(++j), "").toString(); |
| 195 |
} |
| 196 |
QString idxfilename = value("/idx", "").toString(); |
| 197 |
recentfiles.push_back( |
| 198 |
std::pair<std::list<std::string>,std::string>(filenames, idxfilename.toStdString())); |
| 199 |
} |
| 200 |
endGroup(); // key |
| 201 |
} |
| 202 |
} |
| 203 |
endGroup(); // "/" |
| 204 |
endGroup(); // recentfiles |
| 205 |
start_bof = value("/start_bof", true).toBool(); |
| 206 |
stop_eof = value("/stop_eof", true).toBool(); |
| 207 |
beginGroup("/snapshots"); |
| 208 |
snapshot_type = value("/type", "PNG").toString(); |
| 209 |
snapshot_quality = value("/quality", -1).toInt(); |
| 210 |
snapshot_prefix = value("/prefix", "").toString(); |
| 211 |
snapshot_delimiter = value("/delimiter", "_").toString(); |
| 212 |
snapshot_first = value("/first", 1).toInt(); |
| 213 |
snapshot_width = value("/width", 3).toInt(); |
| 214 |
snapshot_extension = value("/extension", "png").toString(); |
| 215 |
snapshot_range = value("/range", 0).toInt(); |
| 216 |
snapshot_samples = value("/samples", 1).toInt(); |
| 217 |
endGroup(); // snapshots |
| 218 |
beginGroup("/pipe"); |
| 219 |
pipe_command.clear(); |
| 220 |
pipe_post.clear(); |
| 221 |
pipe_label.clear(); |
| 222 |
pipe_format.clear(); |
| 223 |
beginGroup("/0"); |
| 224 |
QString command = value("/command", DVBCUT_DEFAULT_PIPE_COMMAND).toString(); |
| 225 |
QString post = value("/post", DVBCUT_DEFAULT_PIPE_POST).toString(); |
| 226 |
QString label = value("/label", DVBCUT_DEFAULT_PIPE_LABEL).toString(); |
| 227 |
int format = value("/format", DVBCUT_DEFAULT_PIPE_FORMAT).toInt(); |
| 228 |
endGroup(); // 0 |
| 229 |
unsigned int i = 0; |
| 230 |
while(!command.isEmpty() && !label.isEmpty()) { |
| 231 |
if(format<0 || format>3) format = 0; |
| 232 |
pipe_command.push_back(command); |
| 233 |
pipe_post.push_back(post); |
| 234 |
pipe_label.push_back(label); |
| 235 |
pipe_format.push_back(format); |
| 236 |
QString key = "/" + QString::number(++i); |
| 237 |
beginGroup(key); |
| 238 |
command = value("/command","").toString(); |
| 239 |
post = value("/post","").toString(); |
| 240 |
label = value("/label","").toString(); |
| 241 |
format = value("/format", "0").toInt(); |
| 242 |
endGroup(); // key |
| 243 |
} |
| 244 |
endGroup(); // pipe |
| 245 |
beginGroup("/chapters"); |
| 246 |
// length (>0) or number (<0) of chapter(s) |
| 247 |
chapter_interval = value("/interval", 600*25).toInt(); |
| 248 |
// detection of scene changes is rather time comsuming... |
| 249 |
//chapter_tolerance = readNumEntry("/tolerance", 10*25); |
| 250 |
//... better switch it off per default! |
| 251 |
chapter_tolerance = value("/tolerance", 0).toInt(); |
| 252 |
// average color distance needed for a scene change |
| 253 |
chapter_threshold = value("/threshold", 50.).toDouble(); |
| 254 |
// minimal length of a chapter |
| 255 |
chapter_minimum = value("/minimum", 200*25).toInt(); |
| 256 |
endGroup(); // auto chapters |
| 257 |
} |
| 258 |
|
| 259 |
void |
| 260 |
dvbcut_settings::save_settings() { |
| 261 |
setValue("/version", 2); // latest config version |
| 262 |
beginGroup("/wheel"); |
| 263 |
setValue("/incr_normal", wheel_increments[WHEEL_INCR_NORMAL]); |
| 264 |
setValue("/incr_shift", wheel_increments[WHEEL_INCR_SHIFT]); |
| 265 |
setValue("/incr_ctrl", wheel_increments[WHEEL_INCR_CTRL]); |
| 266 |
setValue("/incr_alt", wheel_increments[WHEEL_INCR_ALT]); |
| 267 |
setValue("/threshold", wheel_threshold); |
| 268 |
setValue("/delta", wheel_delta); |
| 269 |
endGroup(); // wheel |
| 270 |
beginGroup("/slider"); |
| 271 |
setValue("/jog_maximum", jog_maximum); |
| 272 |
setValue("/jog_threshold", jog_threshold); |
| 273 |
setValue("/jog_offset", jog_offset); |
| 274 |
setValue("/jog_interval", jog_interval); |
| 275 |
setValue("/lin_interval", lin_interval); |
| 276 |
endGroup(); // slider |
| 277 |
beginGroup("/lastdir"); |
| 278 |
setValue("/name", lastdir); |
| 279 |
setValue("/update", lastdir_update); |
| 280 |
endGroup(); // lastdir |
| 281 |
beginGroup("/viewscalefactor"); |
| 282 |
setValue("/current", viewscalefactor); |
| 283 |
setValue("/custom", viewscalefactor_custom); |
| 284 |
endGroup(); // viewscalefactor |
| 285 |
setValue("/export_format", export_format); |
| 286 |
beginGroup("/recentfiles"); |
| 287 |
// first remove any OLD recentfiles entries to clean the settings file (<revision 108)!!! |
| 288 |
beginGroup("/"); |
| 289 |
QStringList keys = childKeys(); |
| 290 |
for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) |
| 291 |
remove("/" + *it); |
| 292 |
// then remove ALL new recentfiles entries!!! |
| 293 |
// (otherwise it would be a mess with erased&inserted muliple file entries of different size) |
| 294 |
QStringList subkeys = childGroups(); |
| 295 |
for ( QStringList::Iterator its = subkeys.begin(); its != subkeys.end(); ++its ) { |
| 296 |
beginGroup("/" + *its); |
| 297 |
QStringList keys = childKeys(); |
| 298 |
for ( QStringList::Iterator itk = keys.begin(); itk != keys.end(); ++itk ) |
| 299 |
remove("/" + *its + "/" + *itk); |
| 300 |
endGroup(); // "/" + *its |
| 301 |
} |
| 302 |
endGroup(); // "/" |
| 303 |
setValue("/max", int(recentfiles_max)); |
| 304 |
// and NOW write the updated list from scratch!!! |
| 305 |
for (unsigned int i = 0; i < recentfiles.size(); ++i) { |
| 306 |
QString key = "/" + QString::number(i); |
| 307 |
beginGroup(key); |
| 308 |
int j=0; |
| 309 |
for(std::list<std::string>::iterator it=settings().recentfiles[i].first.begin(); |
| 310 |
it!=settings().recentfiles[i].first.end(); it++, j++) |
| 311 |
setValue("/" + QString::number(j), QString::fromStdString(*it)); |
| 312 |
setValue("/idx", QString::fromStdString(recentfiles[i].second)); |
| 313 |
endGroup(); // key |
| 314 |
} |
| 315 |
endGroup(); // recentfiles |
| 316 |
setValue("/start_bof", start_bof); |
| 317 |
setValue("/stop_eof", stop_eof); |
| 318 |
beginGroup("/snapshots"); |
| 319 |
setValue("/type", snapshot_type); |
| 320 |
setValue("/quality", snapshot_quality); |
| 321 |
setValue("/prefix", snapshot_prefix); |
| 322 |
setValue("/delimiter", snapshot_delimiter); |
| 323 |
setValue("/first", snapshot_first); |
| 324 |
setValue("/width", snapshot_width); |
| 325 |
setValue("/extension", snapshot_extension); |
| 326 |
setValue("/range", snapshot_range); |
| 327 |
setValue("/samples", snapshot_samples); |
| 328 |
endGroup(); // snapshots |
| 329 |
beginGroup("/pipe"); |
| 330 |
for (unsigned int i = 0; i < pipe_command.size(); ++i) { |
| 331 |
QString key = "/" + QString::number(i); |
| 332 |
beginGroup(key); |
| 333 |
setValue("/command", pipe_command[i]); |
| 334 |
setValue("/post", pipe_post[i]); |
| 335 |
setValue("/label", pipe_label[i]); |
| 336 |
setValue("/format", pipe_format[i]); |
| 337 |
endGroup(); // key |
| 338 |
} |
| 339 |
endGroup(); // pipe |
| 340 |
beginGroup("/chapters"); |
| 341 |
setValue("/interval", chapter_interval); |
| 342 |
setValue("/tolerance", chapter_tolerance); |
| 343 |
setValue("/threshold", chapter_threshold); |
| 344 |
setValue("/minimum", chapter_minimum); |
| 345 |
endGroup(); // auto chapters |
| 346 |
setValue("/search_dups_range", search_dups_range); |
| 347 |
} |
| 348 |
|
| 349 |
// private settings variable |
| 350 |
static dvbcut_settings mysettings; |
| 351 |
|
| 352 |
// access function (includes delayed loading) |
| 353 |
dvbcut_settings& settings() { |
| 354 |
if (!mysettings.loaded) { |
| 355 |
mysettings.load_settings(); |
| 356 |
mysettings.loaded = true; |
| 357 |
} |
| 358 |
return mysettings; |
| 359 |
} |