~ubuntu-branches/ubuntu/wily/smplayer/wily

« back to all changes in this revision

Viewing changes to src/videopreview/videopreview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Maia Kozheva
  • Date: 2009-03-31 23:05:43 UTC
  • mfrom: (1.2.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20090331230543-0h2hfwpwlu9opbv2
* New upstream release. (Closes: #523791)
  - Reworked subtitle font preferences. (Closes: #503295)
  - No longer installs qt_fr.qm. (Closes: #486314)
* debian/control:
  - Bumped Standards-Version to 3.8.1.
  - Changed maintainer name (still the same person and GPG key).
  - Changed section to video.
  - Build-depend on zlib1g-dev for findsubtitles.
  - Require Qt >= 4.3 per readme.
  - Added ${misc:Depends}.
  - Make smplayer-translations depend on smplayer and smplayer recommend
    smplayer-translations, not the other way round. (Closes: #489375)
* debian/copyright:
  - Significantly expanded per-file with new upstream authors.
* debian/rules:
  - Make make use correct uic in install.
  - Clean svn_revision.
  - Removed get-orig-source - not needed with uscan --repack.
* debian/patches/01_gl_translation.patch:
  - Added patch to fix lrelease error on smplayer_gl.ts.
* Added debian/README.source for simple-patchsys.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  smplayer, GUI front-end for mplayer.
 
2
    Copyright (C) 2006-2009 Ricardo Villalba <rvm@escomposlinux.org>
 
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
#include "videopreview.h"
 
20
#include "videopreviewconfigdialog.h"
 
21
#include <QProcess>
 
22
#include <QRegExp>
 
23
#include <QDir>
 
24
#include <QTime>
 
25
#include <QProgressDialog>
 
26
#include <QWidget>
 
27
#include <QGridLayout>
 
28
#include <QLabel>
 
29
#include <QScrollArea>
 
30
#include <QDialogButtonBox>
 
31
#include <QPushButton>
 
32
#include <QPainter>
 
33
#include <QFileDialog>
 
34
#include <QMessageBox>
 
35
#include <QSettings>
 
36
#include <QApplication>
 
37
#include <QPixmapCache>
 
38
#include <QImageWriter>
 
39
#include <QImageReader>
 
40
 
 
41
#include <cmath>
 
42
 
 
43
#define RENAME_PICTURES 0
 
44
 
 
45
VideoPreview::VideoPreview(QString mplayer_path, QWidget * parent) : QWidget(parent, Qt::Window)
 
46
{
 
47
        setMplayerPath(mplayer_path);
 
48
 
 
49
        set = 0; // settings
 
50
        save_last_directory = true;
 
51
 
 
52
        prop.input_video.clear();
 
53
        prop.dvd_device.clear();
 
54
        prop.n_cols = 4;
 
55
        prop.n_rows = 4;
 
56
        prop.initial_step = 20;
 
57
        prop.max_width = 800;
 
58
        prop.aspect_ratio = 0;
 
59
        prop.display_osd = true;
 
60
        prop.extract_format = JPEG;
 
61
 
 
62
        output_dir = "smplayer_preview";
 
63
        full_output_dir = QDir::tempPath() +"/"+ output_dir;
 
64
 
 
65
        progress = new QProgressDialog(this);
 
66
        progress->setMinimumDuration(0);
 
67
        connect( progress, SIGNAL(canceled()), this, SLOT(cancelPressed()) );
 
68
 
 
69
        w_contents = new QWidget(this);
 
70
        QPalette p = w_contents->palette();
 
71
        p.setColor(w_contents->backgroundRole(), Qt::white);
 
72
        p.setColor(w_contents->foregroundRole(), Qt::black);
 
73
        w_contents->setPalette(p);
 
74
 
 
75
        info = new QLabel(this);
 
76
 
 
77
        foot = new QLabel(this);
 
78
        foot->setAlignment(Qt::AlignRight);
 
79
 
 
80
        grid_layout = new QGridLayout;
 
81
        grid_layout->setSpacing(2);
 
82
 
 
83
        QVBoxLayout * l = new QVBoxLayout;
 
84
        l->setSizeConstraint(QLayout::SetFixedSize);
 
85
        l->addWidget(info);
 
86
        l->addLayout(grid_layout);
 
87
        l->addWidget(foot);
 
88
        
 
89
        w_contents->setLayout(l);
 
90
 
 
91
        scroll_area = new QScrollArea(this);
 
92
        scroll_area->setWidgetResizable(true);
 
93
        scroll_area->setAlignment(Qt::AlignCenter);
 
94
        scroll_area->setWidget( w_contents );
 
95
 
 
96
        button_box = new QDialogButtonBox(QDialogButtonBox::Close | QDialogButtonBox::Save, Qt::Horizontal, this);
 
97
        connect( button_box, SIGNAL(rejected()), this, SLOT(close()) );
 
98
        connect( button_box->button(QDialogButtonBox::Save), SIGNAL(clicked()), this, SLOT(saveImage()) );
 
99
 
 
100
        QVBoxLayout * my_layout = new QVBoxLayout;
 
101
        my_layout->addWidget(scroll_area);
 
102
        my_layout->addWidget(button_box);
 
103
        setLayout(my_layout);
 
104
 
 
105
        retranslateStrings();
 
106
 
 
107
        QList<QByteArray> r_formats = QImageReader::supportedImageFormats();
 
108
        QString read_formats;
 
109
        for (int n=0; n < r_formats.count(); n++) {
 
110
                read_formats.append(r_formats[n]+" ");
 
111
        }
 
112
        qDebug("VideoPreview::VideoPreview: supported formats for reading: %s", read_formats.toUtf8().constData());
 
113
 
 
114
        QList<QByteArray> w_formats = QImageWriter::supportedImageFormats();
 
115
        QString write_formats;
 
116
        for (int n=0; n < w_formats.count(); n++) {
 
117
                write_formats.append(w_formats[n]+" ");
 
118
        }
 
119
        qDebug("VideoPreview::VideoPreview: supported formats for writing: %s", write_formats.toUtf8().constData());
 
120
}
 
121
 
 
122
VideoPreview::~VideoPreview() {
 
123
        if (set) saveSettings();
 
124
}
 
125
 
 
126
void VideoPreview::retranslateStrings() {
 
127
        progress->setWindowTitle(tr("Video preview"));
 
128
        progress->setCancelButtonText( tr("Cancel") );
 
129
 
 
130
        foot->setText("<i>"+ tr("Generated by SMPlayer") +" </i>");
 
131
}
 
132
 
 
133
void VideoPreview::setMplayerPath(QString mplayer_path) {
 
134
        mplayer_bin = mplayer_path;
 
135
        QFileInfo fi(mplayer_bin);
 
136
        if (fi.exists() && fi.isExecutable() && !fi.isDir()) {
 
137
                mplayer_bin = fi.absoluteFilePath();
 
138
    }
 
139
 
 
140
        qDebug("VideoPreview::setMplayerPath: mplayer_bin: '%s'", mplayer_bin.toUtf8().constData());
 
141
}
 
142
 
 
143
void VideoPreview::setSettings(QSettings * settings) {
 
144
        set = settings;
 
145
        loadSettings();
 
146
}
 
147
 
 
148
void VideoPreview::clearThumbnails() {
 
149
        for (int n=0; n < label_list.count(); n++) {
 
150
                grid_layout->removeWidget( label_list[n] );
 
151
                delete label_list[n];
 
152
        }
 
153
        label_list.clear();
 
154
        info->clear();
 
155
}
 
156
 
 
157
QString VideoPreview::framePicture() {
 
158
        if (prop.extract_format == PNG)
 
159
                return "00000005.png";
 
160
        else
 
161
                return "00000005.jpg";
 
162
}
 
163
 
 
164
bool VideoPreview::createThumbnails() {
 
165
        clearThumbnails();
 
166
        error_message.clear();
 
167
 
 
168
        button_box->setEnabled(false);
 
169
 
 
170
        bool result = extractImages();
 
171
 
 
172
        progress->close();
 
173
 
 
174
        if ((result == false) && (!error_message.isEmpty())) {
 
175
                QMessageBox::critical(this, tr("Error"), 
 
176
                              tr("The following error has occurred while creating the thumbnails:")+"\n"+ error_message );
 
177
        }
 
178
 
 
179
        button_box->setEnabled(true);
 
180
 
 
181
        // Adjust size
 
182
        //resize( w_contents->sizeHint() );
 
183
 
 
184
        cleanDir(full_output_dir);
 
185
        return result;
 
186
}
 
187
 
 
188
bool VideoPreview::extractImages() {
 
189
        VideoInfo i = getInfo(mplayer_bin, prop.input_video);
 
190
        int length = i.length;
 
191
 
 
192
        if (length == 0) {
 
193
                if (error_message.isEmpty()) error_message = tr("The length of the video is 0");
 
194
                return false;
 
195
        }
 
196
 
 
197
        // Create a temporary directory
 
198
        QDir d(QDir::tempPath());
 
199
        if (!d.exists(output_dir)) {
 
200
                if (!d.mkpath(output_dir)) {
 
201
                        qDebug("VideoPreview::extractImages: error: can't create '%s'", full_output_dir.toUtf8().constData());
 
202
                        error_message = tr("The temporary directory (%1) can't be created").arg(full_output_dir);
 
203
                        return false;
 
204
                }
 
205
        }
 
206
 
 
207
        displayVideoInfo(i);
 
208
 
 
209
        // Let's begin
 
210
        run.thumbnail_width = 0;
 
211
 
 
212
        int num_pictures = prop.n_cols * prop.n_rows;
 
213
        length -= prop.initial_step;
 
214
        int s_step = length / num_pictures;
 
215
 
 
216
        int current_time = prop.initial_step;
 
217
 
 
218
        canceled = false;
 
219
        progress->setLabelText(tr("Creating thumbnails..."));
 
220
        progress->setRange(0, num_pictures-1);
 
221
        progress->show();
 
222
 
 
223
        double aspect_ratio = i.aspect;
 
224
        if (prop.aspect_ratio != 0) aspect_ratio = prop.aspect_ratio;
 
225
 
 
226
        for (int n = 0; n < num_pictures; n++) {
 
227
                qDebug("VideoPreview::extractImages: getting frame %d of %d...", n+1, num_pictures);
 
228
                progress->setValue(n);
 
229
                qApp->processEvents();
 
230
 
 
231
                if (canceled) return false;
 
232
 
 
233
                if (!runMplayer(current_time, aspect_ratio)) return false;
 
234
 
 
235
                QString frame_picture = full_output_dir + "/" + framePicture();
 
236
                if (!QFile::exists(frame_picture)) {
 
237
                        error_message = tr("The file %1 doesn't exist").arg(frame_picture);
 
238
                        return false;
 
239
                }
 
240
 
 
241
#if RENAME_PICTURES 
 
242
                QString extension = (extractFormat()==PNG) ? "png" : "jpg";
 
243
                QString output_file = output_dir + QString("/picture_%1.%2").arg(current_time, 8, 10, QLatin1Char('0')).arg(extension);
 
244
                d.rename(output_dir + "/" + framePicture(), output_file);
 
245
#else
 
246
                QString output_file = output_dir + "/" + framePicture();
 
247
#endif
 
248
 
 
249
                if (!addPicture(QDir::tempPath() +"/"+ output_file, n, current_time)) {
 
250
                        return false;
 
251
                }
 
252
 
 
253
                current_time += s_step;
 
254
        }
 
255
 
 
256
        return true;
 
257
}
 
258
 
 
259
bool VideoPreview::runMplayer(int seek, double aspect_ratio) {
 
260
        QStringList args;
 
261
        args << "-nosound";
 
262
 
 
263
        if (prop.extract_format == PNG) {
 
264
                args << "-vo"
 
265
                << "png:outdir=\""+full_output_dir+"\"";
 
266
        } else {
 
267
                args << "-vo"
 
268
                << "jpeg:outdir=\""+full_output_dir+"\"";
 
269
        }
 
270
 
 
271
        args << "-frames" << "6" << "-ss" << QString::number(seek);
 
272
 
 
273
        if (aspect_ratio != 0) {
 
274
                args << "-aspect" << QString::number(aspect_ratio) << "-zoom";
 
275
        }
 
276
 
 
277
        if (!prop.dvd_device.isEmpty()) {
 
278
                args << "-dvd-device" << prop.dvd_device;
 
279
        }
 
280
 
 
281
        /*
 
282
        if (display_osd) {
 
283
                args << "-vf" << "expand=osd=1" << "-osdlevel" << "2";
 
284
        }
 
285
        */
 
286
 
 
287
        args << prop.input_video;
 
288
 
 
289
        QString command = mplayer_bin + " ";
 
290
        for (int n = 0; n < args.count(); n++) command = command + args[n] + " ";
 
291
        qDebug("VideoPreview::runMplayer: command: %s", command.toUtf8().constData());
 
292
 
 
293
        QProcess p;
 
294
        p.start(mplayer_bin, args);
 
295
        if (!p.waitForFinished()) {
 
296
                qDebug("VideoPreview::runMplayer: error running process");
 
297
                error_message = tr("The mplayer process didn't run");
 
298
                return false;
 
299
        }
 
300
 
 
301
        return true;
 
302
}
 
303
 
 
304
 
 
305
bool VideoPreview::addPicture(const QString & filename, int num, int time) {
 
306
        int row = num / prop.n_cols;
 
307
        int col = num % prop.n_cols;
 
308
 
 
309
        qDebug("VideoPreview::addPicture: %d (row: %d col: %d) file: '%s'", num, row, col, filename.toUtf8().constData());
 
310
 
 
311
        QPixmapCache::clear();
 
312
        QPixmap picture;
 
313
        if (!picture.load(filename)) {
 
314
                qDebug("VideoPreview::addPicture: can't load file");
 
315
                error_message = tr("The file %1 can't be loaded").arg(filename);
 
316
                return false;
 
317
        }
 
318
 
 
319
        if (run.thumbnail_width == 0) {
 
320
                int spacing = grid_layout->horizontalSpacing() * (prop.n_cols-1);
 
321
                if (spacing < 0) spacing = 0;
 
322
                qDebug("VideoPreview::addPicture: spacing: %d", spacing);
 
323
                run.thumbnail_width = (prop.max_width - spacing) / prop.n_cols;
 
324
                if (run.thumbnail_width > picture.width()) run.thumbnail_width = picture.width();
 
325
                qDebug("VideoPreview::addPicture: thumbnail_width set to %d", run.thumbnail_width);
 
326
        }
 
327
 
 
328
        QPixmap scaled_picture = picture.scaledToWidth(run.thumbnail_width, Qt::SmoothTransformation);
 
329
 
 
330
        // Add current time text
 
331
        if (prop.display_osd) {
 
332
                QString stime = QTime().addSecs(time).toString("hh:mm:ss");
 
333
                QFont font("Arial");
 
334
                font.setBold(true);
 
335
                QPainter painter(&scaled_picture);
 
336
                painter.setPen( Qt::white );
 
337
                painter.setFont(font);
 
338
                painter.drawText(scaled_picture.rect(), Qt::AlignRight | Qt::AlignBottom, stime);
 
339
        }
 
340
 
 
341
        QLabel * l = new QLabel(this);
 
342
        label_list.append(l);
 
343
        l->setPixmap(scaled_picture);
 
344
        //l->setPixmap(picture);
 
345
        grid_layout->addWidget(l, row, col);
 
346
 
 
347
        return true;
 
348
}
 
349
 
 
350
void VideoPreview::displayVideoInfo(const VideoInfo & i) {
 
351
        // Display info about the video
 
352
        QTime t = QTime().addSecs(i.length);
 
353
 
 
354
        QString aspect = QString::number(i.aspect);
 
355
        if (fabs(1.77 - i.aspect) < 0.1) aspect = "16:9";
 
356
        else
 
357
        if (fabs(1.33 - i.aspect) < 0.1) aspect = "4:3";
 
358
        else
 
359
        if (fabs(2.35 - i.aspect) < 0.1) aspect = "2.35:1";
 
360
 
 
361
        QString no_info = tr("No info");
 
362
 
 
363
        QString fps = (i.fps==0 || i.fps==1000) ? no_info : QString("%1").arg(i.fps);
 
364
        QString video_bitrate = (i.video_bitrate==0) ? no_info : tr("%1 kbps").arg(i.video_bitrate/1000);
 
365
        QString audio_bitrate = (i.audio_bitrate==0) ? no_info : tr("%1 kbps").arg(i.audio_bitrate/1000);
 
366
        QString audio_rate = (i.audio_rate==0) ? no_info : tr("%1 Hz").arg(i.audio_rate);
 
367
 
 
368
        info->setText(
 
369
                "<b><font size=+1>" + i.filename +"</font></b>"
 
370
                "<table cellspacing=4 cellpadding=4><tr>"
 
371
                "<td>" +
 
372
                tr("Size: %1 MB").arg(i.size / (1024*1024)) + "<br>" +
 
373
                tr("Resolution: %1x%2").arg(i.width).arg(i.height) + "<br>" +
 
374
                tr("Length: %1").arg(t.toString("hh:mm:ss")) +
 
375
                "</td>"
 
376
                "<td>" +
 
377
                tr("Video format: %1").arg(i.video_format) + "<br>" +
 
378
                tr("Frames per second: %1").arg(fps) + "<br>" +
 
379
                tr("Aspect ratio: %1").arg(aspect) + //"<br>" +
 
380
                "</td>"
 
381
                "<td>" +
 
382
                tr("Video bitrate: %1").arg(video_bitrate) + "<br>" +
 
383
                tr("Audio bitrate: %1").arg(audio_bitrate) + "<br>" +
 
384
                tr("Audio rate: %1").arg(audio_rate) + //"<br>" +
 
385
                "</td>"
 
386
                "</tr></table>" 
 
387
        );
 
388
        setWindowTitle( tr("Video preview") + " - " + i.filename );
 
389
}
 
390
 
 
391
void VideoPreview::cleanDir(QString directory) {
 
392
        QStringList filter;
 
393
        if (prop.extract_format == PNG) {
 
394
                filter.append("*.png");
 
395
        } else {
 
396
                filter.append("*.jpg");
 
397
        }
 
398
 
 
399
        QDir d(directory);
 
400
        QStringList l = d.entryList( filter, QDir::Files, QDir::Unsorted);
 
401
 
 
402
        for (int n = 0; n < l.count(); n++) {
 
403
                qDebug("VideoPreview::cleanDir: deleting '%s'", l[n].toUtf8().constData());
 
404
                d.remove(l[n]);
 
405
        }
 
406
        qDebug("VideoPreview::cleanDir: removing directory '%s'", directory.toUtf8().constData());
 
407
        d.rmpath(directory);
 
408
}
 
409
 
 
410
VideoInfo VideoPreview::getInfo(const QString & mplayer_path, const QString & filename) {
 
411
        VideoInfo i;
 
412
 
 
413
        if (filename.isEmpty()) {
 
414
                error_message = tr("No filename");
 
415
                return i;
 
416
        }
 
417
 
 
418
        QFileInfo fi(filename);
 
419
        if (fi.exists()) {
 
420
                i.filename = fi.fileName();
 
421
                i.size = fi.size();
 
422
        }
 
423
 
 
424
        QRegExp rx("^ID_(.*)=(.*)");
 
425
 
 
426
        QProcess p;
 
427
        p.setProcessChannelMode( QProcess::MergedChannels );
 
428
 
 
429
        QStringList args;
 
430
        args << "-vo" << "null" << "-ao" << "null" << "-frames" << "1" << "-identify" << "-nocache" << "-noquiet" << filename;
 
431
 
 
432
        if (!prop.dvd_device.isEmpty()) {
 
433
                args << "-dvd-device" << prop.dvd_device;
 
434
        }
 
435
 
 
436
        p.start(mplayer_path, args);
 
437
 
 
438
        if (p.waitForFinished()) {
 
439
                QByteArray line;
 
440
                while (p.canReadLine()) {
 
441
                        line = p.readLine().trimmed();
 
442
                        qDebug("VideoPreview::getInfo: '%s'", line.constData());
 
443
                        if (rx.indexIn(line) > -1) {
 
444
                                QString tag = rx.cap(1);
 
445
                                QString value = rx.cap(2);
 
446
                                qDebug("VideoPreview::getInfo: tag: '%s', value: '%s'", tag.toUtf8().constData(), value.toUtf8().constData());
 
447
 
 
448
                                if (tag == "LENGTH") i.length = (int) value.toDouble();
 
449
                                else
 
450
                                if (tag == "VIDEO_WIDTH") i.width = value.toInt();
 
451
                                else
 
452
                                if (tag == "VIDEO_HEIGHT") i.height = value.toInt();
 
453
                                else
 
454
                                if (tag == "VIDEO_FPS") i.fps = value.toDouble();
 
455
                                else
 
456
                                if (tag == "VIDEO_ASPECT") {
 
457
                                        i.aspect = value.toDouble();
 
458
                                        if ((i.aspect == 0) && (i.width != 0) && (i.height != 0)) {
 
459
                                                i.aspect = (double) i.width / i.height;
 
460
                                        }
 
461
                                }
 
462
                                else
 
463
                                if (tag == "VIDEO_BITRATE") i.video_bitrate = value.toInt();
 
464
                                else
 
465
                                if (tag == "AUDIO_BITRATE") i.audio_bitrate = value.toInt();
 
466
                                else
 
467
                                if (tag == "AUDIO_RATE") i.audio_rate = value.toInt();
 
468
                                else
 
469
                                if (tag == "VIDEO_FORMAT") i.video_format = value;
 
470
                        }
 
471
                }
 
472
        } else {
 
473
                qDebug("VideoPreview::getInfo: error: process didn't start");
 
474
                error_message = tr("The mplayer process didn't start while trying to get info about the video");
 
475
        }
 
476
 
 
477
        qDebug("VideoPreview::getInfo: filename: '%s'", i.filename.toUtf8().constData());
 
478
        qDebug("VideoPreview::getInfo: resolution: '%d x %d'", i.width, i.height);
 
479
        qDebug("VideoPreview::getInfo: length: '%d'", i.length);
 
480
        qDebug("VideoPreview::getInfo: size: '%d'", (int) i.size);
 
481
 
 
482
        return i;
 
483
}
 
484
 
 
485
 
 
486
void VideoPreview::saveImage() {
 
487
        qDebug("VideoPreview::saveImage");
 
488
 
 
489
        // Proposed name
 
490
        QString proposed_name = "";
 
491
        if (save_last_directory) proposed_name = last_directory;
 
492
 
 
493
        QFileInfo fi(prop.input_video);
 
494
        if (fi.exists()) {
 
495
                if (!save_last_directory) proposed_name = fi.absolutePath();
 
496
                QString extension = (extractFormat()==PNG) ? "png" : "jpg";
 
497
                proposed_name += "/"+ fi.completeBaseName() +"_preview."+ extension;
 
498
        }
 
499
 
 
500
        // Formats
 
501
        QList<QByteArray> w_formats = QImageWriter::supportedImageFormats();
 
502
        QString write_formats;
 
503
        for (int n=0; n < w_formats.count(); n++) {
 
504
                write_formats.append("*."+w_formats[n]+" ");
 
505
        }
 
506
        if (write_formats.isEmpty()) {
 
507
                // Shouldn't happen!
 
508
                write_formats = "*.png *.jpg";
 
509
        }
 
510
 
 
511
        QString filename = QFileDialog::getSaveFileName(this, tr("Save file"),
 
512
                            proposed_name, tr("Images") +" ("+ write_formats +")");
 
513
 
 
514
        if (!filename.isEmpty()) {
 
515
                QPixmap image = QPixmap::grabWidget(w_contents);
 
516
                if (!image.save(filename)) {
 
517
                        // Failed!!!
 
518
                        qDebug("VideoPreview::saveImage: error saving '%s'", filename.toUtf8().constData());
 
519
                        QMessageBox::warning(this, tr("Error saving file"), 
 
520
                                 tr("The file couldn't be saved") );
 
521
                } else {
 
522
                        last_directory = QFileInfo(filename).absolutePath();
 
523
                }
 
524
        }
 
525
}
 
526
 
 
527
bool VideoPreview::showConfigDialog(QWidget * parent) {
 
528
        VideoPreviewConfigDialog d(parent);
 
529
 
 
530
        d.setVideoFile( videoFile() );
 
531
        d.setDVDDevice( DVDDevice() );
 
532
        d.setCols( cols() );
 
533
        d.setRows( rows() );
 
534
        d.setInitialStep( initialStep() );
 
535
        d.setMaxWidth( maxWidth() );
 
536
        d.setDisplayOSD( displayOSD() );
 
537
        d.setAspectRatio( aspectRatio() );
 
538
        d.setFormat( extractFormat() );
 
539
        d.setSaveLastDirectory( save_last_directory );
 
540
 
 
541
        if (d.exec() == QDialog::Accepted) {
 
542
                setVideoFile( d.videoFile() );
 
543
                setDVDDevice( d.DVDDevice() );
 
544
                setCols( d.cols() );
 
545
                setRows( d.rows() );
 
546
                setInitialStep( d.initialStep() );
 
547
                setMaxWidth( d.maxWidth() );
 
548
                setDisplayOSD( d.displayOSD() );
 
549
                setAspectRatio( d.aspectRatio() );
 
550
                setExtractFormat(d.format() );
 
551
                save_last_directory = d.saveLastDirectory();
 
552
 
 
553
                return true;
 
554
        }
 
555
 
 
556
        return false;
 
557
}
 
558
 
 
559
void VideoPreview::saveSettings() {
 
560
        qDebug("VideoPreview::saveSettings");
 
561
 
 
562
        set->beginGroup("videopreview");
 
563
 
 
564
        set->setValue("columns", cols());
 
565
        set->setValue("rows", rows());
 
566
        set->setValue("initial_step", initialStep());
 
567
        set->setValue("max_width", maxWidth());
 
568
        set->setValue("osd", displayOSD());
 
569
        set->setValue("format", extractFormat());
 
570
        set->setValue("save_last_directory", save_last_directory);
 
571
 
 
572
        if (save_last_directory) {
 
573
                set->setValue("last_directory", last_directory);
 
574
        }
 
575
 
 
576
        set->setValue("filename", videoFile());
 
577
        set->setValue("dvd_device", DVDDevice());
 
578
 
 
579
        set->endGroup();
 
580
}
 
581
 
 
582
void VideoPreview::loadSettings() {
 
583
        qDebug("VideoPreview::loadSettings");
 
584
 
 
585
        set->beginGroup("videopreview");
 
586
 
 
587
        setCols( set->value("columns", cols()).toInt() );
 
588
        setRows( set->value("rows", rows()).toInt() );
 
589
        setInitialStep( set->value("initial_step", initialStep()).toInt() );
 
590
        setMaxWidth( set->value("max_width", maxWidth()).toInt() );
 
591
        setDisplayOSD( set->value("osd", displayOSD()).toBool() );
 
592
        setExtractFormat( (ExtractFormat) set->value("format", extractFormat()).toInt() );
 
593
        save_last_directory = set->value("save_last_directory", save_last_directory).toBool();
 
594
        last_directory = set->value("last_directory", last_directory).toString();
 
595
 
 
596
        setVideoFile( set->value("filename", videoFile()).toString() );
 
597
        setDVDDevice( set->value("dvd_device", DVDDevice()).toString() );
 
598
 
 
599
        set->endGroup();
 
600
}
 
601
 
 
602
void VideoPreview::adjustWindowSize() {
 
603
        qDebug("VideoPreview::adjustWindowSize: window size: %d %d", width(), height());
 
604
        qDebug("VideoPreview::adjustWindowSize: scroll_area size: %d %d", scroll_area->width(), scroll_area->height());
 
605
 
 
606
        int diff_width = width() - scroll_area->maximumViewportSize().width();
 
607
        int diff_height = height() - scroll_area->maximumViewportSize().height();
 
608
 
 
609
        qDebug("VideoPreview::adjustWindowSize: diff_width: %d diff_height: %d", diff_width, diff_height);
 
610
 
 
611
        QSize new_size = w_contents->size() + QSize( diff_width, diff_height);
 
612
 
 
613
        qDebug("VideoPreview::adjustWindowSize: new_size: %d %d", new_size.width(), new_size.height());
 
614
 
 
615
        resize(new_size);
 
616
}
 
617
 
 
618
void VideoPreview::cancelPressed() {
 
619
        canceled = true;
 
620
}
 
621
 
 
622
// Language change stuff
 
623
void VideoPreview::changeEvent(QEvent *e) {
 
624
        if (e->type() == QEvent::LanguageChange) {
 
625
                retranslateStrings();
 
626
        } else {
 
627
                QWidget::changeEvent(e);
 
628
        }
 
629
}
 
630
 
 
631
#include "moc_videopreview.cpp"
 
632