• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kopete/kopete

  • sources
  • kde-4.12
  • kdenetwork
  • kopete
  • kopete
  • config
  • avdevice
avdeviceconfig.cpp
Go to the documentation of this file.
1 /*
2  avdeviceconfig.cpp - Kopete Video Device Configuration Panel
3 
4  Copyright (c) 2005-2006 by Cláudio da Silveira Pinheiro <taupter@gmail.com>
5  Copyright (c) 2010 by Frank Schaefer <fschaefer.oss@googlemail.com>
6 
7  Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
8 
9  *************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  *************************************************************************
17 */
18 
19 #include "avdeviceconfig.h"
20 
21 #include <qcheckbox.h>
22 #include <qlayout.h>
23 #include <qlabel.h>
24 #include <qbuttongroup.h>
25 #include <qspinbox.h>
26 #include <qcombobox.h>
27 #include <qslider.h>
28 #include <QVBoxLayout>
29 #include <QShowEvent>
30 #include <QHideEvent>
31 
32 #include <kplugininfo.h>
33 #include <klocale.h>
34 #include <kpushbutton.h>
35 #include <kpluginfactory.h>
36 #include <ktrader.h>
37 #include <kconfig.h>
38 #include <kcombobox.h>
39 #include <qimage.h>
40 #include <qpixmap.h>
41 #include <qtabwidget.h>
42 #include "IdGuiElements.h"
43 
44 
45 K_PLUGIN_FACTORY( KopeteAVDeviceConfigFactory,
46  registerPlugin<AVDeviceConfig>(); )
47 K_EXPORT_PLUGIN( KopeteAVDeviceConfigFactory("kcm_kopete_avdeviceconfig") )
48 
49 AVDeviceConfig::AVDeviceConfig(QWidget *parent, const QVariantList &args)
50  : KCModule( KopeteAVDeviceConfigFactory::componentData(), parent, args )
51 {
52  kDebug() << "kopete:config (avdevice): KopeteAVDeviceConfigFactory::componentData() called. ";
53 // "Video" TAB ============================================================
54  mPrfsVideoDevice = new Ui_AVDeviceConfig_VideoDevice();
55  mPrfsVideoDevice->setupUi(this);
56 
57  mPrfsVideoDevice->VideoTabWidget->setTabEnabled(1, false);
58  mPrfsVideoDevice->VideoTabWidget->setTabEnabled(2, false);
59  mPrfsVideoDevice->VideoTabWidget->setTabEnabled(3, false);
60 
61  // set a default image for the webcam widget, in case the user does not have a video device
62  mPrfsVideoDevice->mVideoImageLabel->setScaledContents(false);
63  mPrfsVideoDevice->mVideoImageLabel->setPixmap(KIcon("camera-web").pixmap(128,128));
64 
65  mVideoDevicePool = NULL;
66 }
67 
68 
69 AVDeviceConfig::~AVDeviceConfig()
70 {
71  if (mVideoDevicePool)
72  {
73  for (int k=0; k<ctrl_values_bak.size(); k++)
74  mVideoDevicePool->setControlValue(ctrl_values_bak.at(k).id, ctrl_values_bak.at(k).value);
75  mVideoDevicePool->close();
76  }
77  clearControlGUIElements();
78  delete mPrfsVideoDevice;
79 }
80 
81 
82 void AVDeviceConfig::updateVideoDevicePool()
83 {
84  bool visible = isVisible();
85 
86  if ((mVideoDevicePool && visible) || (!mVideoDevicePool && !visible))
87  return;
88 
89  if (visible)
90  {
91  connect(mPrfsVideoDevice->mDeviceKComboBox, SIGNAL(activated(int)), this, SLOT(slotDeviceKComboBoxChanged(int)));
92  connect(mPrfsVideoDevice->mInputKComboBox, SIGNAL(activated(int)), this, SLOT(slotInputKComboBoxChanged(int)));
93  connect(mPrfsVideoDevice->mStandardKComboBox, SIGNAL(activated(int)), this, SLOT(slotStandardKComboBoxChanged(int)));
94 
95  mVideoDevicePool = Kopete::AV::VideoDevicePool::self();
96 
97  if (EXIT_SUCCESS == mVideoDevicePool->open())
98  {
99  setupControls();
100  startCapturing();
101  }
102 
103  mVideoDevicePool->fillDeviceKComboBox(mPrfsVideoDevice->mDeviceKComboBox);
104  mVideoDevicePool->fillInputKComboBox(mPrfsVideoDevice->mInputKComboBox);
105  mVideoDevicePool->fillStandardKComboBox(mPrfsVideoDevice->mStandardKComboBox);
106 
107  connect(mVideoDevicePool, SIGNAL(deviceRegistered(QString)), this,
108  SLOT(deviceRegistered(QString)) );
109  connect(mVideoDevicePool, SIGNAL(deviceUnregistered(QString)), this,
110  SLOT(deviceUnregistered(QString)) );
111 
112  connect(&qtimer, SIGNAL(timeout()), this, SLOT(slotUpdateImage()) );
113  }
114  else
115  {
116  for (int k=0; k<ctrl_values_bak.size(); k++)
117  mVideoDevicePool->setControlValue(ctrl_values_bak.at(k).id, ctrl_values_bak.at(k).value);
118 
119  disconnect(mVideoDevicePool, SIGNAL(deviceRegistered(QString)), this,
120  SLOT(deviceRegistered(QString)) );
121  disconnect(mVideoDevicePool, SIGNAL(deviceUnregistered(QString)), this,
122  SLOT(deviceUnregistered(QString)) );
123 
124  disconnect(mPrfsVideoDevice->mDeviceKComboBox, SIGNAL(activated(int)), this, SLOT(slotDeviceKComboBoxChanged(int)));
125  disconnect(mPrfsVideoDevice->mInputKComboBox, SIGNAL(activated(int)), this, SLOT(slotInputKComboBoxChanged(int)));
126  disconnect(mPrfsVideoDevice->mStandardKComboBox, SIGNAL(activated(int)), this, SLOT(slotStandardKComboBoxChanged(int)));
127 
128  disconnect(&qtimer, SIGNAL(timeout()), this, SLOT(slotUpdateImage()) );
129 
130  stopCapturing();
131  mVideoDevicePool->close();
132 
133  mVideoDevicePool = NULL;
134 
135  // set a default image for the webcam widget, in case the user does not have a video device
136  mPrfsVideoDevice->mVideoImageLabel->setScaledContents(false);
137  mPrfsVideoDevice->mVideoImageLabel->setPixmap(KIcon("camera-web").pixmap(128,128));
138  }
139 }
140 
141 
142 void AVDeviceConfig::setupControls()
143 {
144  int k = 0;
145  qint32 cval = 0;
146  clearControlGUIElements();
147 
148  QList<Kopete::AV::NumericVideoControl> numericCtrls;
149  QList<Kopete::AV::BooleanVideoControl> booleanCtrls;
150  QList<Kopete::AV::MenuVideoControl> menuCtrls;
151  QList<Kopete::AV::ActionVideoControl> actionCtrls;
152  numericCtrls = mVideoDevicePool->getSupportedNumericControls();
153  booleanCtrls = mVideoDevicePool->getSupportedBooleanControls();
154  menuCtrls = mVideoDevicePool->getSupportedMenuControls();
155  actionCtrls = mVideoDevicePool->getSupportedActionControls();
156 
157  kDebug() << "Supported controls:" << numericCtrls.size() << "numeric," << booleanCtrls.size()
158  << "boolean," << menuCtrls.size() << "menus," << actionCtrls.size() << "actions.";
159 
160  /* SETUP GUI-elements */
161  // Numeric Controls: => Slider
162  for (k=0; k<numericCtrls.size(); k++)
163  {
164  mVideoDevicePool->getControlValue(numericCtrls.at(k).id, &cval);
165  addSliderControlElement(numericCtrls.at(k).id, numericCtrls.at(k).name, numericCtrls.at(k).value_min, numericCtrls.at(k).value_max, numericCtrls.at(k).value_step, cval);
166  ctrl_values_bak.push_back(VideoControlValue(numericCtrls.at(k).id, cval));
167  }
168  // Boolean Controls: => Checkbox
169  for (k=0; k<booleanCtrls.size(); k++)
170  {
171  mVideoDevicePool->getControlValue(booleanCtrls.at(k).id, &cval);
172  addCheckBoxControlElement(booleanCtrls.at(k).id, booleanCtrls.at(k).name, cval);
173  ctrl_values_bak.push_back(VideoControlValue(booleanCtrls.at(k).id, cval));
174  }
175  // Menu Controls: => Combobox
176  for (k=0; k<menuCtrls.size(); k++)
177  {
178  mVideoDevicePool->getControlValue(menuCtrls.at(k).id, &cval);
179  addPopupMenuControlElement(menuCtrls.at(k).id, menuCtrls.at(k).name, menuCtrls.at(k).options, cval);
180  ctrl_values_bak.push_back(VideoControlValue(booleanCtrls.at(k).id, cval));
181  }
182  // Action Controls: => Button
183  for (k=0; k<actionCtrls.size(); k++)
184  addButtonControlElement(actionCtrls.at(k).id, actionCtrls.at(k).name);
185  /* TODO: check success of mVideoDevicePool->getControlValue() */
186 
187  // Button for resetting the control values:
188  if (numericCtrls.size() || booleanCtrls.size() || menuCtrls.size())
189  {
190  int insert_row = mPrfsVideoDevice->actions_gridLayout->rowCount();
191  QLabel *label = new QLabel( i18n("Reset sliders & options to default values") + ":", mPrfsVideoDevice->VideoTabWidget ); // "Reset sliders and options"
192  mPrfsVideoDevice->actions_gridLayout->addWidget( label, insert_row, 0 );
193  KPushButton *button = new KPushButton( mPrfsVideoDevice->VideoTabWidget );
194  button->setText( i18n("Execute") );
195  mPrfsVideoDevice->actions_gridLayout->addWidget( button, insert_row, 1 );
196  connect( button, SIGNAL(pressed()), this, SLOT(resetControls()) );
197  ctrlWidgets.push_back(label);
198  ctrlWidgets.push_back(button);
199  }
200 
201  mPrfsVideoDevice->VideoTabWidget->setTabEnabled(1, numericCtrls.size());
202  mPrfsVideoDevice->VideoTabWidget->setTabEnabled(2, booleanCtrls.size() + menuCtrls.size());
203  mPrfsVideoDevice->VideoTabWidget->setTabEnabled(3, numericCtrls.size() || booleanCtrls.size() || menuCtrls.size() || actionCtrls.size());
204 }
205 
206 
207 void AVDeviceConfig::clearControlGUIElements()
208 {
209  for (int k=0; k<ctrlWidgets.size(); k++)
210  delete ctrlWidgets.at(k);
211  ctrlWidgets.clear();
212  mPrfsVideoDevice->VideoTabWidget->setTabEnabled(1, false);
213  mPrfsVideoDevice->VideoTabWidget->setTabEnabled(2, false);
214  mPrfsVideoDevice->VideoTabWidget->setTabEnabled(3, false);
215 }
216 
217 
218 void AVDeviceConfig::addSliderControlElement(int cid, QString title, int min, int max, int step, int value)
219 {
220  int insert_row = mPrfsVideoDevice->sliders_gridLayout->rowCount();
221  QLabel *label = new QLabel( title + ":", mPrfsVideoDevice->VideoTabWidget );
222  mPrfsVideoDevice->sliders_gridLayout->addWidget( label, insert_row, 0 );
223  IdSlider *slider = new IdSlider(cid, Qt::Horizontal, mPrfsVideoDevice->VideoTabWidget);
224  mPrfsVideoDevice->sliders_gridLayout->addWidget( slider, insert_row, 1 );
225  slider->setMinimum( min );
226  slider->setMaximum( max );
227  slider->setSliderPosition( value );
228  slider->setTickInterval( step );
229  connect( slider, SIGNAL(valueChanged(uint,int)), this, SLOT(changeVideoControlValue(uint,int)) );
230  ctrlWidgets.push_back(label);
231  ctrlWidgets.push_back(slider);
232 }
233 
234 
235 void AVDeviceConfig::addCheckBoxControlElement(int cid, QString title, bool value)
236 {
237  IdCheckBox *checkbox = new IdCheckBox( cid, mPrfsVideoDevice->VideoTabWidget );
238  checkbox->setText( title );
239  mPrfsVideoDevice->checkboxOptions_verticalLayout->addWidget( checkbox );
240  checkbox->setChecked( value );
241  connect( checkbox, SIGNAL(stateChanged(uint,int)), this, SLOT(changeVideoControlValue(uint,int)) );
242  ctrlWidgets.push_back(checkbox);
243 }
244 
245 
246 void AVDeviceConfig::addPopupMenuControlElement(int cid, QString title, QStringList options, int menuindex)
247 {
248  int insert_row = mPrfsVideoDevice->menuOptions_gridLayout->rowCount();
249  QLabel *label = new QLabel( title + ":", mPrfsVideoDevice->VideoTabWidget );
250  mPrfsVideoDevice->menuOptions_gridLayout->addWidget( label, insert_row, 0 );
251  IdComboBox *combobox = new IdComboBox( cid, mPrfsVideoDevice->VideoTabWidget );
252  mPrfsVideoDevice->menuOptions_gridLayout->addWidget( combobox, insert_row, 1 );
253  combobox->addItems( options );
254  combobox->setCurrentIndex( menuindex );
255  connect( combobox, SIGNAL(currentIndexChanged(uint,int)), this, SLOT(changeVideoControlValue(uint,int)) );
256  ctrlWidgets.push_back(label);
257  ctrlWidgets.push_back(combobox);
258 }
259 
260 
261 void AVDeviceConfig::addButtonControlElement(int cid, QString title)
262 {
263  int insert_row = mPrfsVideoDevice->actions_gridLayout->rowCount();
264  QLabel *label = new QLabel( title + ":", mPrfsVideoDevice->VideoTabWidget );
265  mPrfsVideoDevice->actions_gridLayout->addWidget( label, insert_row, 0 );
266  IdPushButton *button = new IdPushButton( cid, mPrfsVideoDevice->VideoTabWidget );
267  button->setText( i18n("Execute") );
268  mPrfsVideoDevice->actions_gridLayout->addWidget( button, insert_row, 1 );
269  connect( button, SIGNAL(pressed(uint)), this, SLOT(changeVideoControlValue(uint)) );
270  ctrlWidgets.push_back(label);
271  ctrlWidgets.push_back(button);
272 }
273 
274 
275 
279 void AVDeviceConfig::save()
280 {
281  mVideoDevicePool->saveCurrentDeviceConfig();
282  ctrl_values_bak.clear();
283 }
284 
285 
289 void AVDeviceConfig::load()
290 {
292 }
293 
294 void AVDeviceConfig::slotSettingsChanged(bool)
295 {
296  emit changed(true);
297 }
298 
299 void AVDeviceConfig::slotValueChanged(int)
300 {
301  emit changed( true );
302 }
303 
304 void AVDeviceConfig::slotDeviceKComboBoxChanged(int)
305 {
306  kDebug() << "kopete:config (avdevice): slotDeviceKComboBoxChanged(int) called. ";
307  int newdevice = mPrfsVideoDevice->mDeviceKComboBox->currentIndex();
308  kDebug() << "kopete:config (avdevice): slotDeviceKComboBoxChanged(int) Current device: " << mVideoDevicePool->currentDevice() << "New device: " << newdevice;
309  if ((newdevice >= 0 && newdevice < mVideoDevicePool->size()) && (newdevice != mVideoDevicePool->currentDevice()))
310  {
311  kDebug() << "kopete:config (avdevice): slotDeviceKComboBoxChanged(int) should change device. ";
312  stopCapturing();
313  mVideoDevicePool->close();
314  mVideoDevicePool->open(newdevice);
315  /* NOTE: input and signal standard are set automatically */
316  mVideoDevicePool->fillInputKComboBox(mPrfsVideoDevice->mInputKComboBox);
317  mVideoDevicePool->fillStandardKComboBox(mPrfsVideoDevice->mStandardKComboBox);
318  setupControls();
319  startCapturing();
320  kDebug() << "kopete:config (avdevice): slotDeviceKComboBoxChanged(int) called. ";
321  emit changed( true );
322  }
323 }
324 
325 void AVDeviceConfig::slotInputKComboBoxChanged(int)
326 {
327  int newinput = mPrfsVideoDevice->mInputKComboBox->currentIndex();
328  if ((newinput < mVideoDevicePool->inputs()) && (newinput != mVideoDevicePool->currentInput()))
329  {
330  stopCapturing();
331  mVideoDevicePool->selectInput(mPrfsVideoDevice->mInputKComboBox->currentIndex());
332  /* FIXME: select signal standard ! */
333  mVideoDevicePool->fillStandardKComboBox(mPrfsVideoDevice->mStandardKComboBox);
334  setupControls();
335  startCapturing();
336  emit changed( true );
337  }
338 }
339 
340 void AVDeviceConfig::slotStandardKComboBoxChanged(int)
341 {
342  /* FIXME: select signal standard ! */
343  emit changed( true );
344 }
345 
346 void AVDeviceConfig::changeVideoControlValue(unsigned int id, int value)
347 {
348  mVideoDevicePool->setControlValue(id, value);
349  emit changed( true );
350  /* TODO: Check success, fallback */
351 }
352 
353 void AVDeviceConfig::slotUpdateImage()
354 {
355  if (EXIT_SUCCESS == mVideoDevicePool->getFrame())
356  {
357  mVideoDevicePool->getImage(&qimage);
358  mPrfsVideoDevice->mVideoImageLabel->setPixmap(QPixmap::fromImage(qimage));
359  //kDebug() << "kopete (avdeviceconfig_videoconfig): Image updated.";
360  }
361 }
362 
363 void AVDeviceConfig::deviceRegistered( const QString & udi )
364 {
365  (void) udi; /* avoid compiler warning about unused parameter */
366  mVideoDevicePool->fillDeviceKComboBox(mPrfsVideoDevice->mDeviceKComboBox);
367  mVideoDevicePool->fillInputKComboBox(mPrfsVideoDevice->mInputKComboBox);
368  mVideoDevicePool->fillStandardKComboBox(mPrfsVideoDevice->mStandardKComboBox);
369  if (mVideoDevicePool->size() < 2) // otherwise we are already capturing
370  {
371  if (EXIT_SUCCESS == mVideoDevicePool->open())
372  {
373  setupControls();
374  startCapturing();
375  }
376  }
377 }
378 
379 void AVDeviceConfig::deviceUnregistered( const QString & udi )
380 {
381  mVideoDevicePool->fillDeviceKComboBox(mPrfsVideoDevice->mDeviceKComboBox);
382  mVideoDevicePool->fillInputKComboBox(mPrfsVideoDevice->mInputKComboBox);
383  mVideoDevicePool->fillStandardKComboBox(mPrfsVideoDevice->mStandardKComboBox);
384  if (capturingDevice_udi == udi)
385  {
386  qtimer.stop();
387  mPrfsVideoDevice->mVideoImageLabel->setScaledContents(false);
388  mPrfsVideoDevice->mVideoImageLabel->setPixmap(KIcon("camera-web").pixmap(128,128));
389  capturingDevice_udi.clear();
390  clearControlGUIElements();
391  if (mVideoDevicePool->size())
392  {
393  if (EXIT_SUCCESS == mVideoDevicePool->open())
394  {
395  setupControls();
396  startCapturing();
397  }
398  }
399  }
400 }
401 
402 void AVDeviceConfig::startCapturing()
403 {
404  mVideoDevicePool->setImageSize(320, 240);
405  mVideoDevicePool->startCapturing();
406  capturingDevice_udi = mVideoDevicePool->currentDeviceUdi();
407  qtimer.start(40);
408  mPrfsVideoDevice->mVideoImageLabel->setScaledContents(true);
409 }
410 
411 void AVDeviceConfig::stopCapturing()
412 {
413  qtimer.stop();
414  mVideoDevicePool->stopCapturing();
415  mPrfsVideoDevice->mVideoImageLabel->setScaledContents(false);
416  mPrfsVideoDevice->mVideoImageLabel->setPixmap(KIcon("camera-web").pixmap(128,128));
417  capturingDevice_udi.clear();
418 }
419 
420 void AVDeviceConfig::resetControls()
421 {
422  int k = 0;
423  // Numeric controls:
424  QList<Kopete::AV::NumericVideoControl> numericCtrls;
425  numericCtrls = mVideoDevicePool->getSupportedNumericControls();
426  for (k=0; k<numericCtrls.size(); k++)
427  mVideoDevicePool->setControlValue(numericCtrls.at(k).id, numericCtrls.at(k).value_default);
428  // Boolean controls:
429  QList<Kopete::AV::BooleanVideoControl> booleanCtrls;
430  booleanCtrls = mVideoDevicePool->getSupportedBooleanControls();
431  for (k=0; k<booleanCtrls.size(); k++)
432  mVideoDevicePool->setControlValue(booleanCtrls.at(k).id, booleanCtrls.at(k).value_default);
433  // Menu controls:
434  QList<Kopete::AV::MenuVideoControl> menuCtrls;
435  menuCtrls = mVideoDevicePool->getSupportedMenuControls();
436  for (k=0; k<menuCtrls.size(); k++)
437  mVideoDevicePool->setControlValue(menuCtrls.at(k).id, menuCtrls.at(k).index_default);
438  // NOTE: action video controls can not be reset
439  emit changed( true );
440  // Adjust GUI-elements:
441  setupControls();
442  if (ctrlWidgets.size())
443  mPrfsVideoDevice->VideoTabWidget->setCurrentIndex(3);
444  // NOTE: TO BE IMPROVED
445 }
446 
447 void AVDeviceConfig::showEvent(QShowEvent *event)
448 {
449  // wait 1s so duplicate show/hide events will be skipped
450  QTimer::singleShot(1000, this, SLOT(updateVideoDevicePool()));
451  KCModule::showEvent(event);
452 }
453 
454 void AVDeviceConfig::hideEvent(QHideEvent *event)
455 {
456  // wait 1s so duplicate show/hide events will be skipped
457  QTimer::singleShot(1000, this, SLOT(updateVideoDevicePool()));
458  KCModule::hideEvent(event);
459 }
KPushButton
IdComboBox
Definition: IdGuiElements.h:44
IdSlider
Definition: IdGuiElements.h:74
K_PLUGIN_FACTORY
K_PLUGIN_FACTORY(KopeteAVDeviceConfigFactory, registerPlugin< AVDeviceConfig >();) AVDeviceConfig
Definition: avdeviceconfig.cpp:45
QWidget
AVDeviceConfig
Definition: avdeviceconfig.h:38
IdCheckBox
Definition: IdGuiElements.h:59
avdeviceconfig.h
IdGuiElements.h
AVDeviceConfig::hideEvent
virtual void hideEvent(QHideEvent *event)
Definition: avdeviceconfig.cpp:454
AVDeviceConfig::showEvent
virtual void showEvent(QShowEvent *event)
Definition: avdeviceconfig.cpp:447
AVDeviceConfig::~AVDeviceConfig
~AVDeviceConfig()
Definition: avdeviceconfig.cpp:69
AVDeviceConfig::save
virtual void save()
Definition: avdeviceconfig.cpp:279
QLabel
IdPushButton
Definition: IdGuiElements.h:27
AVDeviceConfig::load
virtual void load()
Definition: avdeviceconfig.cpp:289
KCModule
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/kopete

Skip menu "kopete/kopete"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal