summaryrefslogtreecommitdiff
path: root/src/videopreview/videopreview.h
blob: f25cd6d6b28f39c5babbbe684d4965d30329b872 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*  smplayer, GUI front-end for mplayer.
    Copyright (C) 2006-2018 Ricardo Villalba <rvm@users.sourceforge.net>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef VIDEOPREVIEW_H
#define VIDEOPREVIEW_H

#include <QWidget>
#include <QString>
#include <QList>

class QProgressDialog;
class QGridLayout;
class QLabel;
class QScrollArea;
class QDialogButtonBox;
class QSettings;
class QAction;

class VideoInfo 
{
public:
	VideoInfo() { filename.clear(); width = 0; height = 0; length = 0; 
                  size = 0; fps = 0; aspect = 0; video_bitrate = 0; 
                  audio_bitrate = 0; audio_rate = 0; };
	~VideoInfo() {};

	QString filename;
	int width;
	int height;
	int length;
	qint64 size;
	double fps;
	double aspect;
	int video_bitrate;
	int audio_bitrate;
	int audio_rate;
	QString video_format;
	QString audio_format;
};

class VideoPreview : public QWidget
{
	Q_OBJECT

public:
	enum ExtractFormat { JPEG = 1, PNG = 2 };

	VideoPreview(QString mplayer_path, QWidget * parent = 0);
	~VideoPreview();

	void setMplayerPath(QString mplayer_path);
	QString mplayerPath() { return mplayer_bin; };

	void setVideoFile(QString file) { prop.input_video = file; };
	QString videoFile() { return prop.input_video; };

	void setDVDDevice(const QString & dvd_device) { prop.dvd_device = dvd_device; };
	QString DVDDevice() { return prop.dvd_device; };

	void setCols(int cols) { prop.n_cols = cols; };
	int cols() { return prop.n_cols; };

	void setRows(int rows) { prop.n_rows = rows; };
	int rows() { return prop.n_rows; };

	void setGrid(int cols, int rows) { prop.n_cols = cols; prop.n_rows = rows; };

	void setInitialStep(int step) { prop.initial_step = step; };
	int initialStep() { return prop.initial_step; };

	void setMaxWidth(int w) { prop.max_width = w; };
	int maxWidth() { return prop.max_width; };

	void setDisplayOSD(bool b) { prop.display_osd = b; };
	bool displayOSD() { return prop.display_osd; };

	void setAspectRatio(double asp) { prop.aspect_ratio = asp; };
	double aspectRatio() { return prop.aspect_ratio; };

	void setExtractFormat( ExtractFormat format ) { prop.extract_format = format; };
	ExtractFormat extractFormat() { return prop.extract_format; };

	bool createThumbnails();

	bool showConfigDialog(QWidget * parent);

	void setSettings(QSettings * settings);
	QSettings * settings() { return set; };

	VideoInfo getInfo(const QString & mplayer_path, const QString & filename);
	QString errorMessage() { return error_message; };

	void adjustWindowSize();

protected slots:
	void cancelPressed();
	void saveImage();
	void showInfo(bool visible); 

protected:
	virtual void retranslateStrings();
	virtual void changeEvent( QEvent * event );

protected:
	bool extractImages();
	bool runPlayer(double seek, double aspect_ratio);
	bool addPicture(const QString & filename, int num, int time); 
	void displayVideoInfo(const VideoInfo & i);
	void cleanDir(QString directory);
	void clearThumbnails();
	QString framePicture();
	void saveSettings();
	void loadSettings();

#if defined(Q_OS_LINUX) && !defined(NO_SMPLAYER_SUPPORT)
	bool isOptionAvailableinMPV(const QString & option);
#endif

	QList <QLabel *> label_list;

	QGridLayout * grid_layout;
	QLabel * title;
	QLabel * info;
	QLabel * foot;
	QWidget * w_contents;
	QScrollArea * scroll_area;
	QDialogButtonBox * button_box;

	QString mplayer_bin;

	QString output_dir;
	QString full_output_dir;

	QProgressDialog * progress;
	bool canceled;

	QSettings * set;

	QAction * toggleInfoAct;

	struct Properties {
		QString input_video;
		QString dvd_device;
		int n_cols, n_rows, initial_step, max_width;
		double aspect_ratio;
		bool display_osd;
		ExtractFormat extract_format;
	} prop;

	struct {
		int thumbnail_width;
	} run;

	QString last_directory;
	bool save_last_directory;
	QString error_message;
};

#endif