21 #include <qcheckbox.h>
24 #include <qbuttongroup.h>
26 #include <qcombobox.h>
28 #include <QVBoxLayout>
32 #include <kplugininfo.h>
34 #include <kpushbutton.h>
35 #include <kpluginfactory.h>
38 #include <kcombobox.h>
41 #include <qtabwidget.h>
46 registerPlugin<AVDeviceConfig>(); )
47 K_EXPORT_PLUGIN( KopeteAVDeviceConfigFactory(
"kcm_kopete_avdeviceconfig") )
50 :
KCModule( KopeteAVDeviceConfigFactory::componentData(), parent, args )
52 kDebug() <<
"kopete:config (avdevice): KopeteAVDeviceConfigFactory::componentData() called. ";
54 mPrfsVideoDevice =
new Ui_AVDeviceConfig_VideoDevice();
55 mPrfsVideoDevice->setupUi(
this);
57 mPrfsVideoDevice->VideoTabWidget->setTabEnabled(1,
false);
58 mPrfsVideoDevice->VideoTabWidget->setTabEnabled(2,
false);
59 mPrfsVideoDevice->VideoTabWidget->setTabEnabled(3,
false);
62 mPrfsVideoDevice->mVideoImageLabel->setScaledContents(
false);
63 mPrfsVideoDevice->mVideoImageLabel->setPixmap(KIcon(
"camera-web").pixmap(128,128));
65 mVideoDevicePool = NULL;
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();
77 clearControlGUIElements();
78 delete mPrfsVideoDevice;
82 void AVDeviceConfig::updateVideoDevicePool()
84 bool visible = isVisible();
86 if ((mVideoDevicePool && visible) || (!mVideoDevicePool && !visible))
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)));
95 mVideoDevicePool = Kopete::AV::VideoDevicePool::self();
97 if (EXIT_SUCCESS == mVideoDevicePool->open())
103 mVideoDevicePool->fillDeviceKComboBox(mPrfsVideoDevice->mDeviceKComboBox);
104 mVideoDevicePool->fillInputKComboBox(mPrfsVideoDevice->mInputKComboBox);
105 mVideoDevicePool->fillStandardKComboBox(mPrfsVideoDevice->mStandardKComboBox);
107 connect(mVideoDevicePool, SIGNAL(deviceRegistered(
QString)),
this,
108 SLOT(deviceRegistered(
QString)) );
109 connect(mVideoDevicePool, SIGNAL(deviceUnregistered(
QString)),
this,
110 SLOT(deviceUnregistered(
QString)) );
112 connect(&qtimer, SIGNAL(timeout()),
this, SLOT(slotUpdateImage()) );
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);
119 disconnect(mVideoDevicePool, SIGNAL(deviceRegistered(
QString)),
this,
120 SLOT(deviceRegistered(
QString)) );
121 disconnect(mVideoDevicePool, SIGNAL(deviceUnregistered(
QString)),
this,
122 SLOT(deviceUnregistered(
QString)) );
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)));
128 disconnect(&qtimer, SIGNAL(timeout()),
this, SLOT(slotUpdateImage()) );
131 mVideoDevicePool->close();
133 mVideoDevicePool = NULL;
136 mPrfsVideoDevice->mVideoImageLabel->setScaledContents(
false);
137 mPrfsVideoDevice->mVideoImageLabel->setPixmap(KIcon(
"camera-web").pixmap(128,128));
142 void AVDeviceConfig::setupControls()
146 clearControlGUIElements();
152 numericCtrls = mVideoDevicePool->getSupportedNumericControls();
153 booleanCtrls = mVideoDevicePool->getSupportedBooleanControls();
154 menuCtrls = mVideoDevicePool->getSupportedMenuControls();
155 actionCtrls = mVideoDevicePool->getSupportedActionControls();
157 kDebug() <<
"Supported controls:" << numericCtrls.
size() <<
"numeric," << booleanCtrls.
size()
158 <<
"boolean," << menuCtrls.
size() <<
"menus," << actionCtrls.
size() <<
"actions.";
162 for (k=0; k<numericCtrls.
size(); k++)
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));
169 for (k=0; k<booleanCtrls.
size(); k++)
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));
176 for (k=0; k<menuCtrls.
size(); k++)
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));
183 for (k=0; k<actionCtrls.
size(); k++)
184 addButtonControlElement(actionCtrls.
at(k).id, actionCtrls.
at(k).name);
188 if (numericCtrls.
size() || booleanCtrls.
size() || menuCtrls.
size())
190 int insert_row = mPrfsVideoDevice->actions_gridLayout->rowCount();
191 QLabel *label =
new QLabel( i18n(
"Reset sliders & options to default values") +
":", mPrfsVideoDevice->VideoTabWidget );
192 mPrfsVideoDevice->actions_gridLayout->addWidget( label, insert_row, 0 );
194 button->setText( i18n(
"Execute") );
195 mPrfsVideoDevice->actions_gridLayout->addWidget( button, insert_row, 1 );
196 connect( button, SIGNAL(pressed()),
this, SLOT(resetControls()) );
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());
207 void AVDeviceConfig::clearControlGUIElements()
209 for (
int k=0; k<ctrlWidgets.
size(); k++)
210 delete ctrlWidgets.
at(k);
212 mPrfsVideoDevice->VideoTabWidget->setTabEnabled(1,
false);
213 mPrfsVideoDevice->VideoTabWidget->setTabEnabled(2,
false);
214 mPrfsVideoDevice->VideoTabWidget->setTabEnabled(3,
false);
218 void AVDeviceConfig::addSliderControlElement(
int cid,
QString title,
int min,
int max,
int step,
int value)
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 );
229 connect( slider, SIGNAL(valueChanged(uint,
int)),
this, SLOT(changeVideoControlValue(uint,
int)) );
235 void AVDeviceConfig::addCheckBoxControlElement(
int cid,
QString title,
bool value)
239 mPrfsVideoDevice->checkboxOptions_verticalLayout->addWidget( checkbox );
241 connect( checkbox, SIGNAL(stateChanged(uint,
int)),
this, SLOT(changeVideoControlValue(uint,
int)) );
246 void AVDeviceConfig::addPopupMenuControlElement(
int cid,
QString title,
QStringList options,
int menuindex)
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 );
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)) );
261 void AVDeviceConfig::addButtonControlElement(
int cid,
QString title)
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 );
267 button->setText( i18n(
"Execute") );
268 mPrfsVideoDevice->actions_gridLayout->addWidget( button, insert_row, 1 );
269 connect( button, SIGNAL(pressed(uint)),
this, SLOT(changeVideoControlValue(uint)) );
281 mVideoDevicePool->saveCurrentDeviceConfig();
282 ctrl_values_bak.
clear();
294 void AVDeviceConfig::slotSettingsChanged(
bool)
299 void AVDeviceConfig::slotValueChanged(
int)
301 emit changed(
true );
304 void AVDeviceConfig::slotDeviceKComboBoxChanged(
int)
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()))
311 kDebug() <<
"kopete:config (avdevice): slotDeviceKComboBoxChanged(int) should change device. ";
313 mVideoDevicePool->close();
314 mVideoDevicePool->open(newdevice);
316 mVideoDevicePool->fillInputKComboBox(mPrfsVideoDevice->mInputKComboBox);
317 mVideoDevicePool->fillStandardKComboBox(mPrfsVideoDevice->mStandardKComboBox);
320 kDebug() <<
"kopete:config (avdevice): slotDeviceKComboBoxChanged(int) called. ";
321 emit changed(
true );
325 void AVDeviceConfig::slotInputKComboBoxChanged(
int)
327 int newinput = mPrfsVideoDevice->mInputKComboBox->currentIndex();
328 if ((newinput < mVideoDevicePool->inputs()) && (newinput != mVideoDevicePool->currentInput()))
331 mVideoDevicePool->selectInput(mPrfsVideoDevice->mInputKComboBox->currentIndex());
333 mVideoDevicePool->fillStandardKComboBox(mPrfsVideoDevice->mStandardKComboBox);
336 emit changed(
true );
340 void AVDeviceConfig::slotStandardKComboBoxChanged(
int)
343 emit changed(
true );
346 void AVDeviceConfig::changeVideoControlValue(
unsigned int id,
int value)
348 mVideoDevicePool->setControlValue(
id, value);
349 emit changed(
true );
353 void AVDeviceConfig::slotUpdateImage()
355 if (EXIT_SUCCESS == mVideoDevicePool->getFrame())
357 mVideoDevicePool->getImage(&qimage);
363 void AVDeviceConfig::deviceRegistered(
const QString & udi )
366 mVideoDevicePool->fillDeviceKComboBox(mPrfsVideoDevice->mDeviceKComboBox);
367 mVideoDevicePool->fillInputKComboBox(mPrfsVideoDevice->mInputKComboBox);
368 mVideoDevicePool->fillStandardKComboBox(mPrfsVideoDevice->mStandardKComboBox);
369 if (mVideoDevicePool->size() < 2)
371 if (EXIT_SUCCESS == mVideoDevicePool->open())
379 void AVDeviceConfig::deviceUnregistered(
const QString & udi )
381 mVideoDevicePool->fillDeviceKComboBox(mPrfsVideoDevice->mDeviceKComboBox);
382 mVideoDevicePool->fillInputKComboBox(mPrfsVideoDevice->mInputKComboBox);
383 mVideoDevicePool->fillStandardKComboBox(mPrfsVideoDevice->mStandardKComboBox);
384 if (capturingDevice_udi == udi)
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())
393 if (EXIT_SUCCESS == mVideoDevicePool->open())
402 void AVDeviceConfig::startCapturing()
404 mVideoDevicePool->setImageSize(320, 240);
405 mVideoDevicePool->startCapturing();
406 capturingDevice_udi = mVideoDevicePool->currentDeviceUdi();
408 mPrfsVideoDevice->mVideoImageLabel->setScaledContents(
true);
411 void AVDeviceConfig::stopCapturing()
414 mVideoDevicePool->stopCapturing();
415 mPrfsVideoDevice->mVideoImageLabel->setScaledContents(
false);
416 mPrfsVideoDevice->mVideoImageLabel->setPixmap(KIcon(
"camera-web").pixmap(128,128));
417 capturingDevice_udi.
clear();
420 void AVDeviceConfig::resetControls()
425 numericCtrls = mVideoDevicePool->getSupportedNumericControls();
426 for (k=0; k<numericCtrls.
size(); k++)
427 mVideoDevicePool->setControlValue(numericCtrls.
at(k).id, numericCtrls.
at(k).value_default);
430 booleanCtrls = mVideoDevicePool->getSupportedBooleanControls();
431 for (k=0; k<booleanCtrls.
size(); k++)
432 mVideoDevicePool->setControlValue(booleanCtrls.
at(k).id, booleanCtrls.
at(k).value_default);
435 menuCtrls = mVideoDevicePool->getSupportedMenuControls();
436 for (k=0; k<menuCtrls.
size(); k++)
437 mVideoDevicePool->setControlValue(menuCtrls.
at(k).id, menuCtrls.
at(k).index_default);
439 emit changed(
true );
442 if (ctrlWidgets.
size())
443 mPrfsVideoDevice->VideoTabWidget->setCurrentIndex(3);
451 KCModule::showEvent(event);
458 KCModule::hideEvent(event);
void push_back(const T &value)
const T & at(int i) const
K_PLUGIN_FACTORY(KopeteAVDeviceConfigFactory, registerPlugin< AVDeviceConfig >();) AVDeviceConfig
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
void setSliderPosition(int)
virtual void hideEvent(QHideEvent *event)
virtual void showEvent(QShowEvent *event)
void setText(const QString &text)
void setTickInterval(int ti)