Debian Codegraph @

player/configdialog_impl.cpp

raw symbols SCIP
1 #include "configdialog_impl.h"
2 #include "configdialog_impl.moc"
3
4 #include "playercontrol.h"
5
6 #include "aviplay.h"
7 #include "avm_creators.h"
8 #define DECLARE_REGISTRY_SHORTCUT
9 #include "configfile.h"
10 #undef DECLARE_REGISTRY_SHORTCUT
11
12 #include <qcolordialog.h>
13 #include <qcheckbox.h>
14 #include <qcombobox.h>
15 #include <qfont.h>
16 #include <qfontdialog.h>
17 #include <qlabel.h>
18 #include <qlineedit.h>
19 #include <qlistbox.h>
20 #include <qpushbutton.h>
21 #include <qslider.h>
22 #include <qspinbox.h>
23
24 #include <stdlib.h>
25 #include <stdio.h>
26
27
28 ConfigDialog_impl::ConfigDialog_impl(PlayerControl* control)
29 : ConfigDialog(0, "Configuration", true),
30 m_pControl(control), itemLast(0),
31 m_bFontChanged(false), m_bAudioChanged(false), m_bVideoChanged(false)
32 {
33 char* fs = 0;
34 char* http_proxy = 0;
35 unsigned int audio_resampling_rate;
36 int subtitle_async;
37 unsigned int rate;
38 bool audio_resampling;
39 bool use_yuv;
40 bool use_http_proxy;
41 bool autorepeat;
42 bool quality_auto;
43 bool preserve_aspect;
44 bool display_frame_pos;
45 bool video_buffered;
46 bool video_direct;
47 bool video_dropping;
48 avm::IAviPlayer* p = m_pControl->getPlayer(); // shortcut
49
50 p->Get(p->ASYNC_TIME_MS, &m_iAsyncOriginal,
51 p->SUBTITLE_FONT, &fs,
52 p->SUBTITLE_ASYNC_TIME_MS, &subtitle_async,
53 p->AUDIO_STREAM, &m_iAudioStreamOriginal,
54 p->HTTP_PROXY, &http_proxy,
55 p->USE_HTTP_PROXY, &use_http_proxy,
56 p->USE_YUV, &use_yuv,
57 p->AUDIO_RESAMPLING, &audio_resampling,
58 p->AUDIO_RESAMPLING_RATE, &audio_resampling_rate,
59 p->AUDIO_PLAYING_RATE, &rate,
60 p->AUTOREPEAT, &autorepeat,
61 p->VIDEO_QUALITY_AUTO, &quality_auto,
62 p->VIDEO_PRESERVE_ASPECT, &preserve_aspect,
63 p->DISPLAY_FRAME_POS, &display_frame_pos,
64 p->VIDEO_BUFFERED, &video_buffered,
65 p->VIDEO_DIRECT, &video_direct,
66 p->VIDEO_DROPPING, &video_dropping,
67 0);
68
69 m_iSubAsyncOriginal = subtitle_async;
70 m_pAsyncSlider->setValue(m_iAsyncOriginal / 10);
71 onAsyncValChanged(0);
72
73 if (fs)
74 {
75 char* n = strstr(fs, ":qtfont=");
76 m_pFontName->setText( (n) ? n + 8 : fs );
77 free(fs);
78 }
79 onFontChanged();
80 m_bFontChanged = false;
81
82 if (subtitle_async < 0)
83 {
84 m_pSubNegative->setChecked( true );
85 subtitle_async *= -1;
86 }
87 else
88 m_pSubNegative->setChecked( false );
89
90 subtitle_async /= 1000;
91 m_pSubAsyncMin->setValue( subtitle_async / 60 );
92 m_pSubAsyncSec->setValue( subtitle_async % 60 );
93
94 m_pDefAudio->setValue( m_iAudioStreamOriginal );
95
96 if (http_proxy)
97 {
98 if (strlen(http_proxy) > 0)
99 m_pProxyName->setText( http_proxy );
100 free(http_proxy);
101 }
102
103 if (use_http_proxy)
104 {
105 m_pUseProxy->setChecked(true);
106 m_pProxyName->setEnabled(true);
107 }
108
109 m_pHwaccel->setChecked(use_yuv);
110
111 #if QT_VERSION >= 300
112 QString usedefth = RS("theme", "default");
113 m_pNoDefaultTheme->setChecked( (usedefth != "default") );
114 m_pThemeList->setEnabled( m_pNoDefaultTheme->isChecked() );
115 m_pThemeList->setCurrentText( usedefth.ascii() );
116 #endif
117 #if QT_VERSION > 220
118 QString b;
119 b.sprintf("%d", audio_resampling_rate);
120 m_pAudioResamplingRate->lineEdit()->setText(b);
121 #else
122 for (unsigned i = 0; frequencyList[i]; i++)
123 if (audio_resampling_rate <= frequencyList[i])
124 m_pAudioResamplingRate->setCurrentItem(i);
125
126 #endif
127 for (unsigned i = 0; frequencyList[i]; i++)
128 if (frequencyList[i] == rate)
129 {
130 m_pAudioPlayingRate->setCurrentItem(i);
131 break;
132 }
133
134 m_pAudioResampling->setChecked(audio_resampling);
135 onAudioResamplingToggled();
136
137 m_pAutorepeat->setChecked(autorepeat);
138 m_pQualityAuto->setChecked(quality_auto);
139 m_pPreserveAspect->setChecked(preserve_aspect);
140 m_pDisplayFramePos->setChecked(display_frame_pos);
141 m_pVideoBuffered->setChecked(video_buffered);
142 m_pVideoDirect->setChecked(video_direct);
143 m_pVideoDropping->setChecked(video_dropping);
144
145 avm::StreamInfo* si = p->GetVideoStreamInfo();
146 fourcc_t fcc = (si) ? si->GetFormat() : avm::CodecInfo::ANY;
147 delete si;
148 avm::vector<const avm::CodecInfo*> infos;
149 avm::CodecInfo::Get(infos, avm::CodecInfo::Video, avm::CodecInfo::Decode, fcc);
150
151 int sel=0;
152 m_pVideoList->clear();
153 avm::vector<const avm::CodecInfo*>::iterator it;
154 for (it = infos.begin(); it != infos.end(); it++)
155 m_pVideoList->insertItem((*it)->GetName());
156
157 si = p->GetAudioStreamInfo();
158 fcc = (si) ? si->GetFormat() : avm::CodecInfo::ANY;
159 delete si;
160 infos.clear();
161 avm::CodecInfo::Get(infos, avm::CodecInfo::Audio, avm::CodecInfo::Decode, fcc);
162 m_pAudioList->clear();
163 for (it = infos.begin(); it != infos.end(); it++)
164 m_pAudioList->insertItem((*it)->GetName());
165
166 connect(m_pAsyncSlider, SIGNAL(valueChanged(int)), this, SLOT(onAsyncValChanged(int)));
167
168 connect(m_pSubAsyncMin, SIGNAL(valueChanged(int)), this, SLOT(onSubAsyncValChanged(int)));
169 connect(m_pSubAsyncSec, SIGNAL(valueChanged(int)), this, SLOT(onSubAsyncValChanged(int)));
170
171 connect(m_pUseProxy, SIGNAL(clicked()), this, SLOT(onProxyToggled()));
172 connect(m_pAudioResampling, SIGNAL(clicked()), this, SLOT(onAudioResamplingToggled()));
173 connect(m_pFontButton, SIGNAL(clicked()), this, SLOT(onFont()));
174
175 connect(m_pSubBGColor, SIGNAL(clicked()), this, SLOT(onBGColor()));
176 connect(m_pSubFGColor, SIGNAL(clicked()), this, SLOT(onFGColor()));
177
178 connect(m_pDefAudio, SIGNAL(valueChanged(int)), this, SLOT(onAudioStreamChanged(int)));
179
180 connect(m_pFontName, SIGNAL(returnPressed()), this, SLOT(onFontChanged()));
181 //connect(m_pVideoList, SIGNAL(selectionChanged(QListBoxItem*)), this, SLOT(onSelectionChanged(QListBoxItem*)));
182
183 #if QT_VERSION > 220
184 connect(m_pVideoList, SIGNAL(currentChanged(QListBoxItem*)), this, SLOT(onSelectionChanged(QListBoxItem*)));
185 connect(m_pVideoList, SIGNAL(pressed(QListBoxItem*)), this, SLOT(onListPressed(QListBoxItem*)));
186 connect(m_pVideoList, SIGNAL(clicked(QListBoxItem*)), this, SLOT(onListClicked(QListBoxItem*)));
187
188 connect(m_pAudioList, SIGNAL(currentChanged(QListBoxItem*)), this, SLOT(onSelectionChanged(QListBoxItem*)));
189 connect(m_pAudioList, SIGNAL(pressed(QListBoxItem*)), this, SLOT(onListPressed(QListBoxItem*)));
190 connect(m_pAudioList, SIGNAL(clicked(QListBoxItem*)), this, SLOT(onListClicked(QListBoxItem*)));
191 #endif
192 #if QT_VERSION >= 300
193 connect(m_pNoDefaultTheme, SIGNAL(clicked()), this, SLOT(onNoDefaultTheme()));
194 #endif
195 // 3.0
196 //connect(m_pVideoList, SIGNAL(mouseButtonPressed(int, QListBoxItem*, const QPOint&)), this,
197 // SLOT(onMouseButtonPressed(int, QListBoxItem*, const QPOint& )));
198 }
199
200 void ConfigDialog_impl::onSelectionChanged(QListBoxItem* item)
201 {
202 if (m_Mutex.TryLock() < 0)
203 return;
204
205 //printf("ONSEL %p last: %p\n", item, itemLast);
206 if (itemLast)
207 {
208 QListBox* lb = item->listBox();
209 int i = lb->index(item);
210 int ilast = lb->index(itemLast);
211
212 //printf("ONSEL locked %d <-> %d\n", i, ilast);
213 if (i >= 0 && ilast >= 0 && labs(i - ilast) < 2)
214 {
215 QString t = item->text();
216 QString tlast = itemLast->text();
217 // swap two items
218 //printf("swap %s %s\n idx1 %d idx2 %d\n", t.ascii(), tlast.ascii(), i, ilast);
219 lb->changeItem(tlast, i);
220 lb->changeItem(t, ilast);
221 //printf("New itemLast %p\n", itemLast);
222 itemLast = lb->item(i);
223 if (lb == m_pAudioList)
224 m_bAudioChanged = true;
225 else if (lb == m_pVideoList)
226 m_bVideoChanged = true;
227 }
228 }
229 m_Mutex.Unlock();
230 }
231
232 void ConfigDialog_impl::onListPressed(QListBoxItem* item)
233 {
234 //printf("onlistpressed\n");
235 itemLast = item;//(!itemLast) ? item : 0;
236 }
237
238 void ConfigDialog_impl::onListClicked(QListBoxItem* item)
239 {
240 //printf("onlistclicked\n");
241 itemLast = 0;
242 }
243
244 void ConfigDialog_impl::onMouseButtonPressed(int button, QListBoxItem* item, const QPoint& pos)
245 {
246 printf("Onmouse %d %s\n", button, item->text().ascii());
247 }
248
249 void ConfigDialog_impl::onProxyToggled()
250 {
251 m_pProxyName->setEnabled(m_pUseProxy->isChecked());
252 }
253
254 void ConfigDialog_impl::onAudioResamplingToggled()
255 {
256 bool s = m_pAudioResampling->isChecked();
257 m_pAudioResamplingRate->setEnabled(s);
258 m_pAudioPlayingRate->setEnabled(s);
259 }
260
261 void ConfigDialog_impl::onNoDefaultTheme()
262 {
263 m_pThemeList->setEnabled( m_pNoDefaultTheme->isChecked() );
264 }
265
266 void ConfigDialog_impl::apply()
267 {
268 avm::IAviPlayer* p = m_pControl->getPlayer();
269 #if QT_VERSION >= 300
270 if (m_pNoDefaultTheme->isChecked())
271 {
272 qApp->setStyle( m_pThemeList->currentText() );
273 WS("theme", m_pThemeList->currentText());
274 }
275 else
276 WS("theme", "default");
277 #endif
278
279 if (m_bFontChanged)
280 {
281 QString raw = m_defFont.rawName();
282 if (raw.find('-') == -1) {
283 raw = m_defFont.family();
284 QString s;
285 //encoding=iso10646-1:
286 s.sprintf("-%d:weight=", m_defFont.pointSize());
287 raw += s;
288 int w = m_defFont.weight();
289 if (w <= 25)
290 raw += "light";
291 else if (w <= 50)
292 raw += "medium";
293 else if (w <= 63)
294 raw += "demibold";
295 else if (w <= 75)
296 raw += "bold";
297 else
298 raw += "black";
299
300 if (m_defFont.italic())
301 raw += ":slant=italic";
302 else
303 raw += ":slant=roman";
304 }
305
306 #if QT_VERSION >= 300
307 raw += ":qtfont=";
308 raw += m_defFont.toString();
309 #endif
310 p->Set(p->SUBTITLE_FONT, raw.ascii(), 0);
311 }
312
313 QString vcodecs;
314 for (unsigned i = 0; i < m_pVideoList->count(); ++i)
315 {
316 if (!vcodecs.isEmpty())
317 vcodecs += ",";
318 vcodecs += m_pVideoList->text(i);
319 }
320
321 QString acodecs;
322 for (unsigned i = 0; i < m_pAudioList->count(); i++)
323 {
324 if (!acodecs.isEmpty())
325 acodecs += ",";
326 acodecs += m_pAudioList->text(i);
327 }
328
329 m_iAsyncOriginal = m_pAsyncSlider->value() * 10;
330
331 int sub_async = m_pSubAsyncMin->value()*60 + m_pSubAsyncSec->value();
332 sub_async *= (m_pSubNegative->isChecked()) ? -1000 : 1000;
333 m_iSubAsyncOriginal = sub_async;
334
335 p->Set(p->ASYNC_TIME_MS, m_iAsyncOriginal,
336 p->SUBTITLE_ASYNC_TIME_MS, sub_async,
337 p->USE_YUV, m_pHwaccel->isChecked(),
338 p->AUDIO_STREAM, m_pDefAudio->value(),
339 p->AUDIO_RESAMPLING, m_pAudioResampling->isChecked(),
340 p->AUDIO_RESAMPLING_RATE,
341 #if QT_VERSION > 220
342 atoi(m_pAudioResamplingRate->lineEdit()->text().ascii()),
343 #else
344 frequencyList[m_pAudioResamplingRate->currentItem()],
345 #endif
346 p->AUDIO_PLAYING_RATE,
347 frequencyList[m_pAudioPlayingRate->currentItem()],
348 p->USE_HTTP_PROXY, m_pUseProxy->isChecked(),
349 p->HTTP_PROXY, m_pProxyName->text().ascii(),
350 p->DISPLAY_FRAME_POS, m_pDisplayFramePos->isChecked(),
351 p->AUTOREPEAT, m_pAutorepeat->isChecked(),
352 p->VIDEO_PRESERVE_ASPECT, m_pPreserveAspect->isChecked(),
353 p->VIDEO_QUALITY_AUTO, m_pQualityAuto->isChecked(),
354 p->VIDEO_BUFFERED, m_pVideoBuffered->isChecked(),
355 p->VIDEO_DIRECT, m_pVideoDirect->isChecked(),
356 p->VIDEO_DROPPING, m_pVideoDropping->isChecked(),
357 0);
358
359 if (m_bVideoChanged)
360 p->Set(p->VIDEO_CODECS, vcodecs.ascii(), 0);
361 if (m_bAudioChanged)
362 p->Set(p->AUDIO_CODECS, acodecs.ascii(), 0);
363
364 m_pControl->setDisplayFramePos(m_pDisplayFramePos->isChecked());
365
366 m_bVideoChanged = m_bAudioChanged = m_bFontChanged = false;
367 }
368
369 void ConfigDialog_impl::accept()
370 {
371 apply();
372 ConfigDialog::accept();
373 }
374
375 void ConfigDialog_impl::reject()
376 {
377 avm::IAviPlayer* p;
378
379 m_pAsyncSlider->setValue( m_iAsyncOriginal / 10 );
380 m_pDefAudio->setValue( m_iAudioStreamOriginal );
381
382 if ((p = m_pControl->getPlayer()))
383 p->Set(p->SUBTITLE_ASYNC_TIME_MS, m_iSubAsyncOriginal, 0);
384
385 ConfigDialog::reject();
386 }
387
388 void ConfigDialog_impl::onAsyncValChanged(int)
389 {
390 avm::IAviPlayer* p;
391 QString t;
392
393 float value = (float)m_pAsyncSlider->value() / 100.f;
394 m_pAsync->setText(t.sprintf("%2.2f s", value));
395
396 if ((p = m_pControl->getPlayer()))
397 p->Set(p->ASYNC_TIME_MS, int(value * 1000), 0);
398 }
399
400 void ConfigDialog_impl::onSubAsyncValChanged(int)
401 {
402 avm::IAviPlayer* p = m_pControl->getPlayer();
403
404 if (p)
405 {
406 int sub_async = m_pSubAsyncMin->value() * 60 + m_pSubAsyncSec->value();
407 sub_async *= (m_pSubNegative->isChecked()) ? -1000 : 1000;
408 p->Set(p->SUBTITLE_ASYNC_TIME_MS, sub_async, 0);
409 }
410 }
411
412 void ConfigDialog_impl::onAudioStreamChanged(int)
413 {
414 avm::IAviPlayer* p = m_pControl->getPlayer();
415 if (p)
416 p->Set(p->AUDIO_STREAM, m_pDefAudio->value(), 0);
417 }
418
419 void ConfigDialog_impl::onFont()
420 {
421 bool isOk;
422
423 QFont font = QFontDialog::getFont(&isOk, m_defFont, this, "Select font");
424 #if QT_VERSION >= 300
425 //printf("WITH FONT:%s\nWITH RAW:%s\n", font.toString().ascii(), font.rawName().ascii());
426 //printf("Family %s size: %d bold: %d\n", m_defFont.family().ascii(), m_defFont.pointSize(), m_defFont.bold());
427 #endif
428
429 if (isOk)
430 {
431 //printf("QFONT %s\n>>> %s\n", font.toString().ascii(), font.rawName().ascii());
432 QString s = font.rawName().ascii();
433 #if QT_VERSION >= 300
434 if (s[0] != '-')
435 s = font.toString().ascii();
436 #endif
437 m_pFontName->setText( s );
438 onFontChanged();
439 }
440 }
441
442 void ConfigDialog_impl::onBGColor()
443 {
444 QColor color = QColorDialog::getColor(QColor(0, 0, 0));
445 }
446
447 void ConfigDialog_impl::onFGColor()
448 {
449 #if QT_VERSION >= 300
450 QRgb color = QColorDialog::getRgba(0);
451 #else
452 QColor color = QColorDialog::getColor(QColor(0, 0, 0));
453 #endif
454 }
455
456 void ConfigDialog_impl::onFontChanged()
457 {
458 QString s = m_pFontName->text();
459 #if QT_VERSION >= 300
460 if (s[0] != '-')
461 m_defFont.fromString( s );
462 else
463 #endif
464 m_defFont.setRawName( s );
465
466 //printf("ONFONTCHANGE %s\n", s.ascii());
467 if (!m_defFont.family().isNull())
468 s = m_defFont.family();
469
470 int i = s.find(':');
471 if (i != -1)
472 s[i] = 0;
473
474 if (s.isEmpty())
475 s = "default";
476
477 QString str;
478
479 s += str.sprintf(", %d pt", m_defFont.pointSize());
480
481 if (m_defFont.bold())
482 s += ", bold";
483
484 if (m_defFont.italic())
485 s += ", italic";
486
487 m_pFontType->setText( str );
488 m_pPreview->setFont( m_defFont );
489 m_bFontChanged = true;
490 update();
491 }