diff -Naur kdebase-4.4.2.orig/apps/kdepasswd/kcm/chfacedlg.cpp kdebase-4.4.2/apps/kdepasswd/kcm/chfacedlg.cpp --- kdebase-4.4.2.orig/apps/kdepasswd/kcm/chfacedlg.cpp 2009-02-26 10:11:49.000000000 +0100 +++ kdebase-4.4.2/apps/kdepasswd/kcm/chfacedlg.cpp 2010-04-27 10:56:59.563534198 +0200 @@ -1,6 +1,7 @@ /** - * Copyright 2003 Braden MacDonald - * Copyright 2003 Ravikiran Rajagopal + * Copyright 2003 Braden MacDonald + * Copyright 2003 Ravikiran Rajagopal + * Copyright 2010 Felipe Ortiz * * 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 @@ -22,151 +23,170 @@ /** * @file UserInfo's Dialog for changing your face. - * @author Braden MacDonald + * @author Braden MacDonald - Felipe Ortiz */ -#include "chfacedlg.h" - -#include -#include -#include -#include -#include #include +#include #include +#include +#include +#include #include #include #include #include -#include -#include -#include -#include "settings.h" // KConfigXT +#include "chfacedlg.h" +#include "settings.h" +#include "webcamui.h" +#include "webcam.h" +ChFaceDlg::ChFaceDlg(const QString &picsDir, QWidget *parent) : KDialog(parent, Qt::Dialog) +{ + setupUi(mainWidget()); + dir = picsDir; -/** - * TODO: It would be nice if the widget were in a .ui - */ -ChFaceDlg::ChFaceDlg(const QString& picsdir, QWidget *parent) - : KDialog( parent ) + connect(lwImages, SIGNAL(clicked(const QModelIndex &)), this, SLOT(activateButtons())); + + connect(lwImages, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(accept())); + connect(pbFromFile, SIGNAL(clicked()), this, SLOT(slotGetImageFromFile())); + connect(pbDelete, SIGNAL(clicked()), this, SLOT(slotDelImage())); + connect(pbFromCam, SIGNAL(clicked()), this, SLOT(slotShowCamDlg())); + connect(this, SIGNAL(okClicked()), this, SLOT(accept())); + +// WebCam numCam(50, this); +// QMap devices = numCam.getCamList(); + + + scanImages(); + resize(420, 500); + enableButtonOk(false); + pbDelete->setEnabled(false); + pbFromCam->setEnabled(!WebCam::getCamList().isEmpty()); +} + +void ChFaceDlg::scanImages() +{ + if (lwImages->count()) { + lwImages->clear(); + } + + QDir imageDir(dir); + + if (!dir.isEmpty() && imageDir.exists()) { + const QStringList imgList = imageDir.entryList(QDir::Files); + for (QStringList::const_iterator i = imgList.constBegin(); i != imgList.constEnd(); ++i) { + new QListWidgetItem(QIcon(dir + *i), (*i).section('.', 0, 0), lwImages); + } + } + + imageDir.setPath(KCFGUserAccount::userFaceDir()); + + if (imageDir.exists()) { + const QStringList imgList = imageDir.entryList(QDir::Files); + + for (QStringList::const_iterator i = imgList.constBegin(); i != imgList.constEnd(); ++i) { + + new QListWidgetItem(QIcon(KCFGUserAccount::userFaceDir() + *i), + '/' + (*i) == KCFGUserAccount::customFaceFile() ? + i18n("(Custom)") : (*i).section('.' ,0 ,0 ), lwImages ); + } + } +} + +QPixmap ChFaceDlg::getFaceImage() const +{ + if(lwImages->currentItem()){ + return lwImages->currentItem()->icon().pixmap(64); + } + return QPixmap(); +} + +void ChFaceDlg::activateButtons() { - setCaption( i18n("Change your Face") ); - setButtons( Ok|Cancel ); - setDefaultButton( Ok ); - showButtonSeparator( true ); - - QWidget *faceDlg = new QWidget; - ui.setupUi(faceDlg); - - setMainWidget(faceDlg); - - connect( ui.m_FacesWidget, SIGNAL( currentItemChanged( QListWidgetItem *, QListWidgetItem * ) ), SLOT( slotFaceWidgetSelectionChanged( QListWidgetItem * ) ) ); - - connect( ui.m_FacesWidget, SIGNAL( doubleClicked( const QModelIndex & ) ), SLOT(accept()) ); - connect( this, SIGNAL(okClicked()), this, SLOT(accept())); - - connect( ui.browseBtn, SIGNAL( clicked() ), SLOT( slotGetCustomImage() ) ); - -#if 0 - QPushButton *acquireBtn = new QPushButton( i18n("&Acquire Image..."), page ); - acquireBtn->setEnabled( false ); - morePics->addWidget( acquireBtn ); -#endif - - // Filling the icon view - QDir facesDir( picsdir ); - if ( facesDir.exists() ) - { - const QStringList picslist = facesDir.entryList( QDir::Files ); - for ( QStringList::const_iterator it = picslist.constBegin(); it != picslist.constEnd(); ++it ) - new QListWidgetItem( QIcon( picsdir + *it ), (*it).section('.',0,0), ui.m_FacesWidget ); - } - facesDir.setPath( KCFGUserAccount::userFaceDir() ); - if ( facesDir.exists() ) - { - const QStringList picslist = facesDir.entryList( QDir::Files ); - for ( QStringList::const_iterator it = picslist.constBegin(); it != picslist.constEnd(); ++it ) - new QListWidgetItem( QIcon( KCFGUserAccount::userFaceDir() + *it ), - '/'+(*it) == KCFGUserAccount::customFaceFile() ? - i18n("(Custom)") : (*it).section('.',0,0), - ui.m_FacesWidget ); - } - - - enableButtonOk( false ); - //connect( this, SIGNAL( okClicked() ), SLOT( slotSaveCustomImage() ) ); - - resize( 420, 400 ); -} - -void ChFaceDlg::addCustomPixmap( const QString &imPath, bool saveCopy ) -{ - QImage pix( imPath ); - // TODO: save pix to TMPDIR/userinfo-tmp, - // then scale and copy *that* to ~/.faces - - if (pix.isNull()) - { - KMessageBox::sorry( this, i18n("There was an error loading the image.") ); - return; - } - if ( (pix.width() > KCFGUserAccount::faceSize()) - || (pix.height() > KCFGUserAccount::faceSize()) ) - pix = pix.scaled( KCFGUserAccount::faceSize(), KCFGUserAccount::faceSize(), Qt::KeepAspectRatio );// Should be no bigger than certain size. - - if ( saveCopy ) - { - // If we should save a copy: - QDir userfaces( KCFGUserAccount::userFaceDir() ); - if ( !userfaces.exists( ) ) - userfaces.mkdir( userfaces.absolutePath() ); - - pix.save( userfaces.absolutePath() + "/.userinfo-tmp" , "PNG" ); - KonqOperations::copy( this, KonqOperations::COPY, KUrl::List( KUrl( userfaces.absolutePath() + "/.userinfo-tmp" ) ), KUrl( userfaces.absolutePath() + '/' + QFileInfo(imPath).fileName().section('.',0,0) ) ); -#if 0 - if ( !pix.save( userfaces.absolutePath() + '/' + imPath , "PNG" ) ) - KMessageBox::sorry(this, i18n("There was an error saving the image:\n%1", userfaces.absolutePath() ) ); -#endif - } - - QListWidgetItem* newface = new QListWidgetItem( QIcon(QPixmap::fromImage(pix)), QFileInfo(imPath).fileName().section('.',0,0), ui.m_FacesWidget ); - ui.m_FacesWidget->scrollToItem( newface ); - ui.m_FacesWidget->setCurrentItem( newface ); -} - -void ChFaceDlg::slotGetCustomImage( ) -{ - QCheckBox* checkWidget = new QCheckBox( i18n("&Save copy in custom faces folder for future use"), 0 ); - - KFileDialog dlg( QDir::homePath(), KImageIO::pattern( KImageIO::Reading ), - this, checkWidget); - - dlg.setOperationMode( KFileDialog::Opening ); - dlg.setCaption( i18n("Choose Image") ); - dlg.setMode( KFile::File | KFile::LocalOnly ); - - KImageFilePreview *ip = new KImageFilePreview( &dlg ); - dlg.setPreviewWidget( ip ); - if (dlg.exec() == QDialog::Accepted) - addCustomPixmap( dlg.selectedFile(), checkWidget->isChecked() ); -} - -#if 0 -void ChFaceDlg::slotSaveCustomImage() -{ - if ( m_FacesWidget->currentItem()->key() == USER_CUSTOM_KEY) - { - QDir userfaces( QDir::homePath() + USER_FACES_DIR ); - if ( !userfaces.exists( ) ) - userfaces.mkdir( userfaces.absolutePath() ); - - if ( !m_FacesWidget->currentItem()->pixmap()->save( userfaces.absolutePath() + USER_CUSTOM_FILE , "PNG" ) ) - KMessageBox::sorry(this, i18n("There was an error saving the image:\n%1", userfaces.absolutePath() ) ); - } + enableButtonOk(true); + pbDelete->setEnabled(true); } -#endif +void ChFaceDlg::slotGetImageFromFile() +{ +// I think that this feature is not necesary now, because I add a delete button +// Up to date all image are stored. +// QCheckBox *chkSaveImg = new QCheckBox(i18n("&Save copy in custom faces folder for future use"), 0); + + KFileDialog openDlg(QDir::homePath(), + KImageIO::pattern(KImageIO::Reading), this); + + openDlg.setOperationMode(KFileDialog::Opening); + openDlg.setCaption(i18n("Choose Image")); + openDlg.setMode(KFile::File | KFile::LocalOnly); + + KImageFilePreview *imgPreview = new KImageFilePreview(&openDlg); + openDlg.setPreviewWidget(imgPreview); + if (openDlg.exec() == QDialog::Accepted){ + + const QImage pix(openDlg.selectedFile()); + if (pix.isNull()) { + KMessageBox::sorry(this, i18n("There was an error loading the image.")); + return; + } else { + addCustomPixmap(pix, QFileInfo(openDlg.selectedFile()).fileName().section('.', 0, 0)); + } + } +} + +void ChFaceDlg::slotDelImage() +{ + QString path = KCFGUserAccount::userFaceDir() + lwImages->currentItem()->text(); + + if (QFile::exists(path)) { + + int rsp = KMessageBox::warningYesNo(this, i18n("Do you really want to delete this image?"), + i18n("Delete image")); + if (rsp == KMessageBox::Yes) { + KonqOperations::del(this, KonqOperations::TRASH, KUrl(path)); + + delete lwImages->takeItem(lwImages->currentRow()); + } + } else { + KMessageBox::sorry(this, + i18n("You don't have appropriate permissions to delete this image")); + } +} + +void ChFaceDlg::slotShowCamDlg() +{ + WebCamUi *wui = new WebCamUi(this); + if (wui->exec() == QDialog::Accepted && wui->isPhotoTaken()) { + addCustomPixmap(wui->getImage(), wui->getImgName()); + } + delete wui; +} + +void ChFaceDlg::addCustomPixmap(const QImage &pix, const QString &name) +{ + QImage scaledPix; + + if ((pix.width() > KCFGUserAccount::faceSize()) || (pix.height() > KCFGUserAccount::faceSize())) { + // Should be no bigger than certain size. + scaledPix = pix.scaled(KCFGUserAccount::faceSize(), + KCFGUserAccount::faceSize(), + Qt::KeepAspectRatio); + } + + QDir userFaces(KCFGUserAccount::userFaceDir()); + if (!userFaces.exists()) { + userFaces.mkdir(userFaces.absolutePath()); + } + + scaledPix.save(userFaces.absolutePath() + "/" + name , "PNG"); + + QListWidgetItem *newFace = new QListWidgetItem(QIcon(QPixmap::fromImage(scaledPix)), + name, lwImages); + lwImages->scrollToItem(newFace); + lwImages->setCurrentItem(newFace); +} #include "chfacedlg.moc" diff -Naur kdebase-4.4.2.orig/apps/kdepasswd/kcm/chfacedlg.h kdebase-4.4.2/apps/kdepasswd/kcm/chfacedlg.h --- kdebase-4.4.2.orig/apps/kdepasswd/kcm/chfacedlg.h 2008-01-05 00:53:59.000000000 +0100 +++ kdebase-4.4.2/apps/kdepasswd/kcm/chfacedlg.h 2010-04-27 10:56:59.559368142 +0200 @@ -1,6 +1,7 @@ /** * Copyright 2003 Braden MacDonald * Copyright 2003 Ravikiran Rajagopal + * Copyright 2010 Felipe Ortiz C. * * 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 @@ -22,50 +23,39 @@ /** * @file UserInfo-chface: Dialog for choosing a new face for your user. - * @author Braden MacDonald + * @author Braden MacDonald - Felipe Ortiz */ #ifndef CHFACEDLG_H #define CHFACEDLG_H -#include #include +#include #include #include "ui_faceDlg.h" -enum FacePerm { adminOnly = 1, adminFirst = 2, userFirst = 3, userOnly = 4}; - -class ChFaceDlg : public KDialog +class ChFaceDlg : public KDialog, private Ui::faceDlg { - Q_OBJECT -public: - - - explicit ChFaceDlg(const QString& picsdirs, - QWidget *parent=0); - + Q_OBJECT - QPixmap getFaceImage() const - { - if(ui.m_FacesWidget->currentItem()) - return ui.m_FacesWidget->currentItem()->icon().pixmap(64); - else - return QPixmap(); - } +public: + explicit ChFaceDlg(const QString &picsDir, QWidget *parent = 0); + QPixmap getFaceImage() const; private Q_SLOTS: - void slotFaceWidgetSelectionChanged( QListWidgetItem *item ) - { enableButton( Ok, !item->icon().isNull() ); } - - void slotGetCustomImage(); - //void slotSaveCustomImage(); + void activateButtons(); + void slotGetImageFromFile(); + void slotDelImage(); + void slotShowCamDlg(); private: - void addCustomPixmap( const QString &imPath, bool saveCopy ); + void addCustomPixmap(const QImage &pix, const QString &name); + void scanImages(); - Ui::faceDlg ui; -}; + QSize getSize(); + QString dir; -#endif // CHFACEDLG_H +}; +#endif diff -Naur kdebase-4.4.2.orig/apps/kdepasswd/kcm/CMakeLists.txt kdebase-4.4.2/apps/kdepasswd/kcm/CMakeLists.txt --- kdebase-4.4.2.orig/apps/kdepasswd/kcm/CMakeLists.txt 2009-05-14 19:26:16.000000000 +0200 +++ kdebase-4.4.2/apps/kdepasswd/kcm/CMakeLists.txt 2010-04-27 10:56:59.559368142 +0200 @@ -1,19 +1,26 @@ +find_package(KDE4 REQUIRED) +find_package(OpenCV REQUIRED) + +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${OPENCV_INCLUDE_DIR} ${QT_INCLUDES} ${KDE4_INCLUDES}) add_subdirectory(pics) set(kcm_useraccount_PART_SRCS chfnprocess.cpp main.cpp - chfacedlg.cpp) + chfacedlg.cpp + webcam.cpp + webcamui.cpp) kde4_add_ui_files(kcm_useraccount_PART_SRCS main_widget.ui - faceDlg.ui) + faceDlg.ui + webcamui.ui) kde4_add_kcfg_files(kcm_useraccount_PART_SRCS settings.kcfgc pass.kcfgc) kde4_add_plugin(kcm_useraccount ${kcm_useraccount_PART_SRCS}) -target_link_libraries(kcm_useraccount konq ${KDE4_KIO_LIBS} ${KDE4_KDESU_LIBS}) +target_link_libraries(kcm_useraccount konq ${KDE4_KDEUI_LIBS} ${KDE4_SOLID_LIBS} ${KDE4_KIO_LIBS} ${KDE4_KDESU_LIBS} ${OpenCV_LIBS}) install(TARGETS kcm_useraccount DESTINATION ${PLUGIN_INSTALL_DIR}) install(FILES kcm_useraccount.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff -Naur kdebase-4.4.2.orig/apps/kdepasswd/kcm/faceDlg.ui kdebase-4.4.2/apps/kdepasswd/kcm/faceDlg.ui --- kdebase-4.4.2.orig/apps/kdepasswd/kcm/faceDlg.ui 2008-01-05 00:53:59.000000000 +0100 +++ kdebase-4.4.2/apps/kdepasswd/kcm/faceDlg.ui 2010-04-27 10:56:59.563534198 +0200 @@ -1,74 +1,142 @@ - + + faceDlg - - + + 0 0 - 400 - 306 + 455 + 528 - - - 400 - 199 - + + Select a new image - - - + + + - - - Select a new face: + + + Select a new image: - - + + + Qt::Horizontal + + - 64 - 64 + 40 + 20 - - QListView::Adjust + + + + + + + + true + + + QAbstractItemView::DragDrop + + + + 64 + 64 + + + + QListView::Free + + + QListView::LeftToRight + + + true + + + QListView::Adjust + + + QListView::IconMode + + + + + + + + + Qt::Horizontal - - QListView::IconMode + + + 40 + 20 + - + - - - - - Custom Image... - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + &Delete + + + + + + Add new image + + + + + + From File + + + + + + + From Webcam + + + + + + + + + + Qt::Horizontal + + + + + + KListWidget + QListWidget +
klistwidget.h
+
+ + KPushButton + QPushButton +
kpushbutton.h
+
+
diff -Naur kdebase-4.4.2.orig/apps/kdepasswd/kcm/kcm.patch kdebase-4.4.2/apps/kdepasswd/kcm/kcm.patch --- kdebase-4.4.2.orig/apps/kdepasswd/kcm/kcm.patch 1970-01-01 01:00:00.000000000 +0100 +++ kdebase-4.4.2/apps/kdepasswd/kcm/kcm.patch 2010-04-27 10:11:45.000000000 +0200 @@ -0,0 +1,1537 @@ +Index: CMakeLists.txt +=================================================================== +--- CMakeLists.txt (revision 1105532) ++++ CMakeLists.txt (working copy) +@@ -1,19 +1,26 @@ ++find_package(KDE4 REQUIRED) ++find_package(OpenCV REQUIRED) ++ ++include_directories(${CMAKE_CURRENT_BINARY_DIR} ${OPENCV_INCLUDE_DIR} ${QT_INCLUDES} ${KDE4_INCLUDES}) + add_subdirectory(pics) + + set(kcm_useraccount_PART_SRCS + chfnprocess.cpp + main.cpp +- chfacedlg.cpp) ++ chfacedlg.cpp ++ webcam.cpp ++ webcamui.cpp) + + kde4_add_ui_files(kcm_useraccount_PART_SRCS + main_widget.ui +- faceDlg.ui) ++ faceDlg.ui ++ webcamui.ui) + + kde4_add_kcfg_files(kcm_useraccount_PART_SRCS settings.kcfgc pass.kcfgc) + + kde4_add_plugin(kcm_useraccount ${kcm_useraccount_PART_SRCS}) + +-target_link_libraries(kcm_useraccount konq ${KDE4_KIO_LIBS} ${KDE4_KDESU_LIBS}) ++target_link_libraries(kcm_useraccount konq ${KDE4_KDEUI_LIBS} ${KDE4_SOLID_LIBS} ${KDE4_KIO_LIBS} ${KDE4_KDESU_LIBS} ${OpenCV_LIBS}) + + install(TARGETS kcm_useraccount DESTINATION ${PLUGIN_INSTALL_DIR}) + install(FILES kcm_useraccount.desktop DESTINATION ${SERVICES_INSTALL_DIR}) +Index: chfacedlg.h +=================================================================== +--- chfacedlg.h (revision 1105532) ++++ chfacedlg.h (working copy) +@@ -1,6 +1,7 @@ + /** + * Copyright 2003 Braden MacDonald + * Copyright 2003 Ravikiran Rajagopal ++ * Copyright 2010 Felipe Ortiz C. + * + * 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 +@@ -22,50 +23,39 @@ + + /** + * @file UserInfo-chface: Dialog for choosing a new face for your user. +- * @author Braden MacDonald ++ * @author Braden MacDonald - Felipe Ortiz + */ + + #ifndef CHFACEDLG_H + #define CHFACEDLG_H + +-#include + #include ++#include + + #include + + #include "ui_faceDlg.h" + +-enum FacePerm { adminOnly = 1, adminFirst = 2, userFirst = 3, userOnly = 4}; +- +-class ChFaceDlg : public KDialog ++class ChFaceDlg : public KDialog, private Ui::faceDlg + { +- Q_OBJECT +-public: +- +- +- explicit ChFaceDlg(const QString& picsdirs, +- QWidget *parent=0); +- ++ Q_OBJECT + +- QPixmap getFaceImage() const +- { +- if(ui.m_FacesWidget->currentItem()) +- return ui.m_FacesWidget->currentItem()->icon().pixmap(64); +- else +- return QPixmap(); +- } ++public: ++ explicit ChFaceDlg(const QString &picsDir, QWidget *parent = 0); ++ QPixmap getFaceImage() const; + + private Q_SLOTS: +- void slotFaceWidgetSelectionChanged( QListWidgetItem *item ) +- { enableButton( Ok, !item->icon().isNull() ); } +- +- void slotGetCustomImage(); +- //void slotSaveCustomImage(); ++ void activateButtons(); ++ void slotGetImageFromFile(); ++ void slotDelImage(); ++ void slotShowCamDlg(); + + private: +- void addCustomPixmap( const QString &imPath, bool saveCopy ); ++ void addCustomPixmap(const QImage &pix, const QString &name); ++ void scanImages(); + +- Ui::faceDlg ui; +-}; ++ QSize getSize(); ++ QString dir; + +-#endif // CHFACEDLG_H ++}; ++#endif +Index: chfacedlg.cpp +=================================================================== +--- chfacedlg.cpp (revision 1105532) ++++ chfacedlg.cpp (working copy) +@@ -1,6 +1,7 @@ + /** +- * Copyright 2003 Braden MacDonald +- * Copyright 2003 Ravikiran Rajagopal ++ * Copyright 2003 Braden MacDonald ++ * Copyright 2003 Ravikiran Rajagopal ++ * Copyright 2010 Felipe Ortiz + * + * 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 +@@ -22,151 +23,170 @@ + + /** + * @file UserInfo's Dialog for changing your face. +- * @author Braden MacDonald ++ * @author Braden MacDonald - Felipe Ortiz + */ + +-#include "chfacedlg.h" +- +-#include +-#include +-#include +-#include +-#include + #include ++#include + #include + ++#include ++#include ++#include + #include + #include + #include + #include +-#include +-#include +-#include + +-#include "settings.h" // KConfigXT ++#include "chfacedlg.h" ++#include "settings.h" ++#include "webcamui.h" ++#include "webcam.h" + ++ChFaceDlg::ChFaceDlg(const QString &picsDir, QWidget *parent) : KDialog(parent, Qt::Dialog) ++{ ++ setupUi(mainWidget()); + ++ dir = picsDir; + +-/** +- * TODO: It would be nice if the widget were in a .ui +- */ +-ChFaceDlg::ChFaceDlg(const QString& picsdir, QWidget *parent) +- : KDialog( parent ) ++ connect(lwImages, SIGNAL(clicked(const QModelIndex &)), this, SLOT(activateButtons())); ++ ++ connect(lwImages, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(accept())); ++ connect(pbFromFile, SIGNAL(clicked()), this, SLOT(slotGetImageFromFile())); ++ connect(pbDelete, SIGNAL(clicked()), this, SLOT(slotDelImage())); ++ connect(pbFromCam, SIGNAL(clicked()), this, SLOT(slotShowCamDlg())); ++ connect(this, SIGNAL(okClicked()), this, SLOT(accept())); ++ ++// WebCam numCam(50, this); ++// QMap devices = numCam.getCamList(); ++ ++ ++ scanImages(); ++ resize(420, 500); ++ enableButtonOk(false); ++ pbDelete->setEnabled(false); ++ pbFromCam->setEnabled(!WebCam::getCamList().isEmpty()); ++} ++ ++void ChFaceDlg::scanImages() ++{ ++ if (lwImages->count()) { ++ lwImages->clear(); ++ } ++ ++ QDir imageDir(dir); ++ ++ if (!dir.isEmpty() && imageDir.exists()) { ++ const QStringList imgList = imageDir.entryList(QDir::Files); ++ for (QStringList::const_iterator i = imgList.constBegin(); i != imgList.constEnd(); ++i) { ++ new QListWidgetItem(QIcon(dir + *i), (*i).section('.', 0, 0), lwImages); ++ } ++ } ++ ++ imageDir.setPath(KCFGUserAccount::userFaceDir()); ++ ++ if (imageDir.exists()) { ++ const QStringList imgList = imageDir.entryList(QDir::Files); ++ ++ for (QStringList::const_iterator i = imgList.constBegin(); i != imgList.constEnd(); ++i) { ++ ++ new QListWidgetItem(QIcon(KCFGUserAccount::userFaceDir() + *i), ++ '/' + (*i) == KCFGUserAccount::customFaceFile() ? ++ i18n("(Custom)") : (*i).section('.' ,0 ,0 ), lwImages ); ++ } ++ } ++} ++ ++QPixmap ChFaceDlg::getFaceImage() const ++{ ++ if(lwImages->currentItem()){ ++ return lwImages->currentItem()->icon().pixmap(64); ++ } ++ return QPixmap(); ++} ++ ++void ChFaceDlg::activateButtons() + { +- setCaption( i18n("Change your Face") ); +- setButtons( Ok|Cancel ); +- setDefaultButton( Ok ); +- showButtonSeparator( true ); +- +- QWidget *faceDlg = new QWidget; +- ui.setupUi(faceDlg); +- +- setMainWidget(faceDlg); +- +- connect( ui.m_FacesWidget, SIGNAL( currentItemChanged( QListWidgetItem *, QListWidgetItem * ) ), SLOT( slotFaceWidgetSelectionChanged( QListWidgetItem * ) ) ); +- +- connect( ui.m_FacesWidget, SIGNAL( doubleClicked( const QModelIndex & ) ), SLOT(accept()) ); +- connect( this, SIGNAL(okClicked()), this, SLOT(accept())); +- +- connect( ui.browseBtn, SIGNAL( clicked() ), SLOT( slotGetCustomImage() ) ); +- +-#if 0 +- QPushButton *acquireBtn = new QPushButton( i18n("&Acquire Image..."), page ); +- acquireBtn->setEnabled( false ); +- morePics->addWidget( acquireBtn ); +-#endif +- +- // Filling the icon view +- QDir facesDir( picsdir ); +- if ( facesDir.exists() ) +- { +- const QStringList picslist = facesDir.entryList( QDir::Files ); +- for ( QStringList::const_iterator it = picslist.constBegin(); it != picslist.constEnd(); ++it ) +- new QListWidgetItem( QIcon( picsdir + *it ), (*it).section('.',0,0), ui.m_FacesWidget ); +- } +- facesDir.setPath( KCFGUserAccount::userFaceDir() ); +- if ( facesDir.exists() ) +- { +- const QStringList picslist = facesDir.entryList( QDir::Files ); +- for ( QStringList::const_iterator it = picslist.constBegin(); it != picslist.constEnd(); ++it ) +- new QListWidgetItem( QIcon( KCFGUserAccount::userFaceDir() + *it ), +- '/'+(*it) == KCFGUserAccount::customFaceFile() ? +- i18n("(Custom)") : (*it).section('.',0,0), +- ui.m_FacesWidget ); +- } +- +- +- enableButtonOk( false ); +- //connect( this, SIGNAL( okClicked() ), SLOT( slotSaveCustomImage() ) ); +- +- resize( 420, 400 ); +-} +- +-void ChFaceDlg::addCustomPixmap( const QString &imPath, bool saveCopy ) +-{ +- QImage pix( imPath ); +- // TODO: save pix to TMPDIR/userinfo-tmp, +- // then scale and copy *that* to ~/.faces +- +- if (pix.isNull()) +- { +- KMessageBox::sorry( this, i18n("There was an error loading the image.") ); +- return; +- } +- if ( (pix.width() > KCFGUserAccount::faceSize()) +- || (pix.height() > KCFGUserAccount::faceSize()) ) +- pix = pix.scaled( KCFGUserAccount::faceSize(), KCFGUserAccount::faceSize(), Qt::KeepAspectRatio );// Should be no bigger than certain size. +- +- if ( saveCopy ) +- { +- // If we should save a copy: +- QDir userfaces( KCFGUserAccount::userFaceDir() ); +- if ( !userfaces.exists( ) ) +- userfaces.mkdir( userfaces.absolutePath() ); +- +- pix.save( userfaces.absolutePath() + "/.userinfo-tmp" , "PNG" ); +- KonqOperations::copy( this, KonqOperations::COPY, KUrl::List( KUrl( userfaces.absolutePath() + "/.userinfo-tmp" ) ), KUrl( userfaces.absolutePath() + '/' + QFileInfo(imPath).fileName().section('.',0,0) ) ); +-#if 0 +- if ( !pix.save( userfaces.absolutePath() + '/' + imPath , "PNG" ) ) +- KMessageBox::sorry(this, i18n("There was an error saving the image:\n%1", userfaces.absolutePath() ) ); +-#endif +- } +- +- QListWidgetItem* newface = new QListWidgetItem( QIcon(QPixmap::fromImage(pix)), QFileInfo(imPath).fileName().section('.',0,0), ui.m_FacesWidget ); +- ui.m_FacesWidget->scrollToItem( newface ); +- ui.m_FacesWidget->setCurrentItem( newface ); +-} +- +-void ChFaceDlg::slotGetCustomImage( ) +-{ +- QCheckBox* checkWidget = new QCheckBox( i18n("&Save copy in custom faces folder for future use"), 0 ); +- +- KFileDialog dlg( QDir::homePath(), KImageIO::pattern( KImageIO::Reading ), +- this, checkWidget); +- +- dlg.setOperationMode( KFileDialog::Opening ); +- dlg.setCaption( i18n("Choose Image") ); +- dlg.setMode( KFile::File | KFile::LocalOnly ); +- +- KImageFilePreview *ip = new KImageFilePreview( &dlg ); +- dlg.setPreviewWidget( ip ); +- if (dlg.exec() == QDialog::Accepted) +- addCustomPixmap( dlg.selectedFile(), checkWidget->isChecked() ); +-} +- +-#if 0 +-void ChFaceDlg::slotSaveCustomImage() +-{ +- if ( m_FacesWidget->currentItem()->key() == USER_CUSTOM_KEY) +- { +- QDir userfaces( QDir::homePath() + USER_FACES_DIR ); +- if ( !userfaces.exists( ) ) +- userfaces.mkdir( userfaces.absolutePath() ); +- +- if ( !m_FacesWidget->currentItem()->pixmap()->save( userfaces.absolutePath() + USER_CUSTOM_FILE , "PNG" ) ) +- KMessageBox::sorry(this, i18n("There was an error saving the image:\n%1", userfaces.absolutePath() ) ); +- } ++ enableButtonOk(true); ++ pbDelete->setEnabled(true); + } +-#endif + ++void ChFaceDlg::slotGetImageFromFile() ++{ ++// I think that this feature is not necesary now, because I add a delete button ++// Up to date all image are stored. ++// QCheckBox *chkSaveImg = new QCheckBox(i18n("&Save copy in custom faces folder for future use"), 0); ++ ++ KFileDialog openDlg(QDir::homePath(), ++ KImageIO::pattern(KImageIO::Reading), this); ++ ++ openDlg.setOperationMode(KFileDialog::Opening); ++ openDlg.setCaption(i18n("Choose Image")); ++ openDlg.setMode(KFile::File | KFile::LocalOnly); ++ ++ KImageFilePreview *imgPreview = new KImageFilePreview(&openDlg); ++ openDlg.setPreviewWidget(imgPreview); ++ if (openDlg.exec() == QDialog::Accepted){ ++ ++ const QImage pix(openDlg.selectedFile()); ++ if (pix.isNull()) { ++ KMessageBox::sorry(this, i18n("There was an error loading the image.")); ++ return; ++ } else { ++ addCustomPixmap(pix, QFileInfo(openDlg.selectedFile()).fileName().section('.', 0, 0)); ++ } ++ } ++} ++ ++void ChFaceDlg::slotDelImage() ++{ ++ QString path = KCFGUserAccount::userFaceDir() + lwImages->currentItem()->text(); ++ ++ if (QFile::exists(path)) { ++ ++ int rsp = KMessageBox::warningYesNo(this, i18n("Do you really want to delete this image?"), ++ i18n("Delete image")); ++ if (rsp == KMessageBox::Yes) { ++ KonqOperations::del(this, KonqOperations::TRASH, KUrl(path)); ++ ++ delete lwImages->takeItem(lwImages->currentRow()); ++ } ++ } else { ++ KMessageBox::sorry(this, ++ i18n("You don't have appropriate permissions to delete this image")); ++ } ++} ++ ++void ChFaceDlg::slotShowCamDlg() ++{ ++ WebCamUi *wui = new WebCamUi(this); ++ if (wui->exec() == QDialog::Accepted && wui->isPhotoTaken()) { ++ addCustomPixmap(wui->getImage(), wui->getImgName()); ++ } ++ delete wui; ++} ++ ++void ChFaceDlg::addCustomPixmap(const QImage &pix, const QString &name) ++{ ++ QImage scaledPix; ++ ++ if ((pix.width() > KCFGUserAccount::faceSize()) || (pix.height() > KCFGUserAccount::faceSize())) { ++ // Should be no bigger than certain size. ++ scaledPix = pix.scaled(KCFGUserAccount::faceSize(), ++ KCFGUserAccount::faceSize(), ++ Qt::KeepAspectRatio); ++ } ++ ++ QDir userFaces(KCFGUserAccount::userFaceDir()); ++ if (!userFaces.exists()) { ++ userFaces.mkdir(userFaces.absolutePath()); ++ } ++ ++ scaledPix.save(userFaces.absolutePath() + "/" + name , "PNG"); ++ ++ QListWidgetItem *newFace = new QListWidgetItem(QIcon(QPixmap::fromImage(scaledPix)), ++ name, lwImages); ++ lwImages->scrollToItem(newFace); ++ lwImages->setCurrentItem(newFace); ++} + #include "chfacedlg.moc" +Index: faceDlg.ui +=================================================================== +--- faceDlg.ui (revision 1105532) ++++ faceDlg.ui (working copy) +@@ -1,74 +1,142 @@ +- ++ ++ + faceDlg +- +- ++ ++ + + 0 + 0 +- 400 +- 306 ++ 455 ++ 528 + + +- +- +- 400 +- 199 +- ++ ++ Select a new image + +- +- +- ++ ++ ++ + +- +- +- Select a new face: ++ ++ ++ Select a new image: + + + + +- +- ++ ++ ++ Qt::Horizontal ++ ++ + +- 64 +- 64 ++ 40 ++ 20 + + +- +- QListView::Adjust ++ ++ ++ ++ ++ ++ ++ ++ true ++ ++ ++ QAbstractItemView::DragDrop ++ ++ ++ ++ 64 ++ 64 ++ ++ ++ ++ QListView::Free ++ ++ ++ QListView::LeftToRight ++ ++ ++ true ++ ++ ++ QListView::Adjust ++ ++ ++ QListView::IconMode ++ ++ ++ ++ ++ ++ ++ ++ ++ Qt::Horizontal + +- +- QListView::IconMode ++ ++ ++ 40 ++ 20 ++ + +- ++ + + +- +- +- +- +- Custom Image... +- +- +- +- +- +- +- Qt::Horizontal +- +- +- +- 40 +- 20 +- +- +- +- +- ++ ++ ++ &Delete ++ ++ + + + ++ ++ ++ ++ Add new image ++ ++ ++ ++ ++ ++ From File ++ ++ ++ ++ ++ ++ ++ From Webcam ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ Qt::Horizontal ++ ++ ++ + + ++ ++ ++ KListWidget ++ QListWidget ++
klistwidget.h
++
++ ++ KPushButton ++ QPushButton ++
kpushbutton.h
++
++
+ + +
+Index: main.h +=================================================================== +--- main.h (revision 1105532) ++++ main.h (working copy) +@@ -1,6 +1,7 @@ + + /** + * Copyright (C) 2004 Frans Englich ++ * Copyrigth (C) 2010 Felipe Ortiz + * + * 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 +@@ -31,6 +32,8 @@ class QEvent; + class QObject; + class KUrl; + ++enum FacePerm { adminOnly = 1, adminFirst = 2, userFirst = 3, userOnly = 4}; ++ + class MainWidget : public QWidget, public Ui::MainWidget + { + public: +@@ -52,10 +55,10 @@ public: + ~KCMUserAccount(); + + /** +- * The user data is loaded from chfn(/etc/password) and then ++ * The user data is loaded from chfn(/etc/password) and then + * written back as well as to KDE's own(KEmailSettings). +- * The user won't notice this(assuming they change the KDE settings via +- * this KCM) and will make KDE play nice with enviroments which uses ++ * The user won't notice this(assuming they change the KDE settings via ++ * this KCM) and will make KDE play nice with enviroments which uses + * /etc/password. + */ + void load(); +Index: main_widget.ui +=================================================================== +--- main_widget.ui (revision 1105532) ++++ main_widget.ui (working copy) +@@ -1,9 +1,8 @@ +- +- +- Frans Englich <frans.englich@telia.com> ++ ++ Frans Englich <frans.englich@telia.com> + MainWidget +- +- ++ ++ + + 0 + 0 +@@ -11,92 +10,89 @@ + 557 + + +- +- ++ ++ + 0 + + +- ++ + +- +- +- ++ ++ ++ + 0 + 0 + + +- ++ + + 74 + 74 + + +- ++ + + 74 + 74 + + +- ++ + true + +- +- Change your image +- +- ++ + + + + + +- +- ++ ++ + 0 + + +- +- ++ ++ + + +- ++ + Qt::AlignVCenter + +- ++ + false + + + + +- +- +- <i>Click to change your image</i> ++ ++ ++ <i>Click to change your image</i> + +- ++ + Qt::AlignVCenter + +- ++ + false + + + + +- ++ + +- +- ++ ++ + Change Password... + + + + + +- ++ + Qt::Horizontal + +- ++ + QSizePolicy::Expanding + +- ++ + + 158 + 18 +@@ -111,122 +107,122 @@ + + + +- +- ++ ++ + User Information + +- +- +- +- ++ ++ ++ ++ + &Name: + +- ++ + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + +- ++ + false + +- ++ + leRealname + + + +- +- +- ++ ++ ++ + true + + + +- +- +- ++ ++ ++ + &Organization: + +- ++ + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + +- ++ + false + +- ++ + leOrganization + + + +- +- +- ++ ++ ++ + true + + + +- +- +- ++ ++ ++ + &Email address: + +- ++ + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + +- ++ + false + +- ++ + leEmail + + + +- +- +- ++ ++ ++ + true + + + +- +- +- ++ ++ ++ + &SMTP server: + +- ++ + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + +- ++ + false + +- ++ + leSMTP + + + +- +- +- ++ ++ ++ + true + + + +- +- +- ++ ++ ++ + User ID: + +- ++ + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + +- ++ + false + + + +- +- +- ++ ++ ++ + + +- ++ + false + + +@@ -235,28 +231,28 @@ + + + +- +- ++ ++ + At Password Prompt + +- ++ + +- +- ++ ++ + Show one bullet for each letter + + + + +- +- ++ ++ + Show three bullets for each letter + + + + +- +- ++ ++ + Show nothing + + +@@ -266,13 +262,13 @@ + + + +- ++ + Qt::Vertical + +- ++ + QSizePolicy::Expanding + +- ++ + + 20 + 16 +@@ -282,7 +278,7 @@ + + + +- ++ + + KButtonGroup + QGroupBox +@@ -290,15 +286,15 @@ + 1 + + +- KPushButton +- QPushButton +-
kpushbutton.h
+-
+- + KLineEdit + QLineEdit +
klineedit.h
+
++ ++ KPushButton ++ QPushButton ++
kpushbutton.h
++
+
+ + btnChangeFace +Index: webcam.h +=================================================================== +--- webcam.h (revision 0) ++++ webcam.h (revision 0) +@@ -0,0 +1,74 @@ ++/** ++ * Copyright 2010 Felipe Ortiz ++ * ++ * 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 ++ * ++ * ++ * Please see the README ++ * ++ */ ++ ++/** ++ * @file Webcam interface based on OpenCV ++ * @author Felipe Ortiz ++ */ ++ ++#ifndef WEBCAM_H ++#define WEBCAM_H ++ ++#include ++#include ++#include ++#include ++ ++#include ++#include ++ ++#include ++#include ++ ++class WebCam : public QObject ++{ ++ Q_OBJECT ++ ++public: ++ explicit WebCam(int interval = 50, QObject *parent = 0); ++ ~WebCam(); ++ ++ void setDevice(const int id); ++ void setInterval(const int interval); ++ bool isStopped() const; ++ ++ static QMap getCamList(); ++ ++ ++Q_SIGNALS: ++ void newFrame(QImage img); ++ ++public Q_SLOTS: ++ void stop(); ++ void start(); ++ void sendNewFrame(); ++ ++private: ++ QImage prepareFrame(IplImage *frame); ++ ++ QTimer *timer; ++ CvCapture *cam; ++ int intervalTime; ++ int camId; ++ bool stopped; ++ ++}; ++#endif +Index: webcam.cpp +=================================================================== +--- webcam.cpp (revision 0) ++++ webcam.cpp (revision 0) +@@ -0,0 +1,140 @@ ++/** ++ * Copyright 2010 Felipe Ortiz ++ * ++ * 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 ++ * ++ * ++ * Please see the README ++ * ++ */ ++ ++/** ++ * @file Webcam interface based on OpenCV ++ * @author Felipe Ortiz ++ */ ++ ++#include ++#include ++ ++#include "webcam.h" ++ ++WebCam::WebCam(int interval, QObject *parent) : QObject(parent) ++{ ++ intervalTime = interval; ++ stopped = true; ++ ++ timer = new QTimer(this); ++ connect(timer, SIGNAL(timeout()), this, SLOT(sendNewFrame())); ++} ++ ++WebCam::~WebCam() ++{ ++ if(!isStopped()){ ++ stop(); ++ } ++} ++ ++void WebCam::setDevice(const int id) ++{ ++ camId = id; ++} ++ ++void WebCam::setInterval(const int interval) ++{ ++ intervalTime = interval; ++ ++ if (!isStopped()) { ++ timer->stop(); ++ timer->start(interval); ++ } ++} ++ ++bool WebCam::isStopped() const ++{ ++ return stopped; ++} ++ ++QMap WebCam::getCamList() ++{ ++ QMap camList; ++ QList devices = Solid::Device::listFromType(Solid::DeviceInterface::Video, ++ QString()); ++ foreach (const Solid::Device &dev, devices) { ++ QStringList protocols = dev.as()->supportedProtocols(); ++ ++ if (protocols.contains("video4linux")) { ++ QStringList drivers = dev.as()->supportedDrivers("video4linux"); ++ ++ if (drivers.contains("video4linux")) { ++ QString path = dev.as ()->driverHandle("video4linux").toString(); ++ ++ bool ok; ++ int devNumber = path.mid(10).toInt(&ok, 10); ++ if (ok) { ++ camList.insert(devNumber, dev.product()); ++ } ++ } ++ } ++ } ++ ++ return camList; ++} ++ ++void WebCam::stop() ++{ ++ if (!isStopped()) { ++ timer->stop(); ++ ++ if (cam) { ++ cvReleaseCapture(&cam); ++ } ++ stopped = true; ++ } ++} ++ ++void WebCam::start() ++{ ++ if (isStopped()) { ++ cam = cvCreateCameraCapture(camId); ++ ++ if (cam) { ++ timer->start(intervalTime); ++ stopped = false; ++ } else { ++ KMessageBox::sorry(0, i18n("Error while initializing the camera")); ++ } ++ } ++} ++ ++QImage WebCam::prepareFrame(IplImage *frame) ++{ ++ cvCvtColor(frame, frame, CV_BGR2RGB); ++ cvFlip(frame, frame, 1); ++ ++ QImage image((uchar *)frame->imageData, ++ frame->width, ++ frame->height, ++ QImage::Format_RGB888); ++ ++// preview = image; ++ return image; ++} ++ ++void WebCam::sendNewFrame() ++{ ++ IplImage *frame = cvQueryFrame(cam); ++ ++ emit newFrame(prepareFrame(frame)); ++} ++#include "webcam.moc" +Index: webcamui.h +=================================================================== +--- webcamui.h (revision 0) ++++ webcamui.h (revision 0) +@@ -0,0 +1,60 @@ ++/** ++ * Copyright 2010 Felipe Ortiz ++ * ++ * 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 ++ * ++ * ++ * Please see the README ++ * ++ */ ++ ++/** ++ * @file GUI for get picture from a webcam ++ * @author Felipe Ortiz ++ */ ++ ++#ifndef WEBCAMUI_H ++#define WEBCAMUI_H ++ ++#include ++ ++#include "webcam.h" ++#include "ui_webcamui.h" ++ ++class WebCamUi : public KDialog, private Ui::WebCamUi ++{ ++ Q_OBJECT ++ ++public: ++ explicit WebCamUi(QWidget *parent = 0); ++ ++ bool isPhotoTaken() const; ++ QImage getImage() const; ++ QString getImgName() const; ++ ++private: ++ void setCboCamera(); ++ ++private Q_SLOTS: ++ void switchCamera(int index); ++ void showImage(QImage image); ++ void saveImage(); ++ ++private: ++ QString fname; ++ QImage pix; ++ bool photo; ++ WebCam *cam; ++}; ++#endif +Index: webcamui.cpp +=================================================================== +--- webcamui.cpp (revision 0) ++++ webcamui.cpp (revision 0) +@@ -0,0 +1,103 @@ ++/** ++ * Copyright 2010 Felipe Ortiz ++ * ++ * 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 ++ * ++ * ++ * Please see the README ++ * ++ */ ++ ++/** ++ * @file GUI for get picture from a webcam ++ * @author Felipe Ortiz ++ */ ++ ++#include ++#include ++ ++#include "settings.h" ++#include "webcamui.h" ++ ++WebCamUi::WebCamUi(QWidget *parent) : KDialog(parent, Qt::Dialog) ++{ ++ photo = false; ++ setupUi(mainWidget()); ++ cam = new WebCam(50, this); ++ ++ setCboCamera(); ++ connect(cboDevice, SIGNAL(activated(int)), this, SLOT(switchCamera(int))); ++ connect(cam, SIGNAL(newFrame(QImage)), this, SLOT(showImage(QImage))); ++ connect(this, SIGNAL(okClicked()), this, SLOT(saveImage())); ++ ++ switchCamera(cboDevice->currentIndex()); ++} ++ ++bool WebCamUi::isPhotoTaken() const ++{ ++ return photo; ++} ++ ++void WebCamUi::setCboCamera() ++{ ++ QMap devices = WebCam::getCamList(); ++ QMap::const_iterator i; ++ ++ for (i = devices.constBegin(); i != devices.constEnd(); ++i) { ++ cboDevice->addItem(i.value(), i.key()); ++ } ++} ++ ++void WebCamUi::switchCamera(int index) ++{ ++ if (!cam->isStopped()) { ++ cam->stop(); ++ } ++ cam->setDevice(cboDevice->itemData(index).toInt()); ++ cam->start(); ++} ++ ++void WebCamUi::showImage(QImage image) ++{ ++ QSize size(lbVideo->width(), lbVideo->height()); ++ ++ lbVideo->setPixmap(QPixmap::fromImage(image.scaled(size, Qt::IgnoreAspectRatio))); ++} ++ ++QImage WebCamUi::getImage() const ++{ ++ return pix; ++} ++ ++QString WebCamUi::getImgName() const ++{ ++ return fname; ++} ++ ++void WebCamUi::saveImage() ++{ ++ ++ cam->stop(); ++ fname = QInputDialog::getText(this, i18n("New Image"), ++ i18n("Image name:"), ++ QLineEdit::Normal, ++ QString(), &photo); ++ ++ if (photo && !fname.isEmpty()) { ++ pix = lbVideo->pixmap()->toImage(); ++ } ++} ++ ++ ++#include "webcamui.moc" +Index: webcamui.ui +=================================================================== +--- webcamui.ui (revision 0) ++++ webcamui.ui (revision 0) +@@ -0,0 +1,82 @@ ++ ++ ++ WebCamUi ++ ++ ++ ++ 0 ++ 0 ++ 539 ++ 546 ++ ++ ++ ++ Take a Photo ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ Select Device: ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ Qt::Horizontal ++ ++ ++ ++ 40 ++ 20 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ 503 ++ 420 ++ ++ ++ ++ QFrame::StyledPanel ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ Qt::Horizontal ++ ++ ++ ++ ++ ++ ++ ++ KComboBox ++ QComboBox ++
kcombobox.h
++
++
++ ++ ++
diff -Naur kdebase-4.4.2.orig/apps/kdepasswd/kcm/main.h kdebase-4.4.2/apps/kdepasswd/kcm/main.h --- kdebase-4.4.2.orig/apps/kdepasswd/kcm/main.h 2008-01-05 00:53:59.000000000 +0100 +++ kdebase-4.4.2/apps/kdepasswd/kcm/main.h 2010-04-27 10:56:59.563534198 +0200 @@ -1,6 +1,7 @@ /** * Copyright (C) 2004 Frans Englich + * Copyrigth (C) 2010 Felipe Ortiz * * 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 @@ -31,6 +32,8 @@ class QObject; class KUrl; +enum FacePerm { adminOnly = 1, adminFirst = 2, userFirst = 3, userOnly = 4}; + class MainWidget : public QWidget, public Ui::MainWidget { public: @@ -52,10 +55,10 @@ ~KCMUserAccount(); /** - * The user data is loaded from chfn(/etc/password) and then + * The user data is loaded from chfn(/etc/password) and then * written back as well as to KDE's own(KEmailSettings). - * The user won't notice this(assuming they change the KDE settings via - * this KCM) and will make KDE play nice with enviroments which uses + * The user won't notice this(assuming they change the KDE settings via + * this KCM) and will make KDE play nice with enviroments which uses * /etc/password. */ void load(); diff -Naur kdebase-4.4.2.orig/apps/kdepasswd/kcm/webcam.cpp kdebase-4.4.2/apps/kdepasswd/kcm/webcam.cpp --- kdebase-4.4.2.orig/apps/kdepasswd/kcm/webcam.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kdebase-4.4.2/apps/kdepasswd/kcm/webcam.cpp 2010-04-27 10:57:07.830200025 +0200 @@ -0,0 +1,140 @@ +/** + * Copyright 2010 Felipe Ortiz + * + * 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 + * + * + * Please see the README + * + */ + +/** + * @file Webcam interface based on OpenCV + * @author Felipe Ortiz + */ + +#include +#include + +#include "webcam.h" + +WebCam::WebCam(int interval, QObject *parent) : QObject(parent) +{ + intervalTime = interval; + stopped = true; + + timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(sendNewFrame())); +} + +WebCam::~WebCam() +{ + if(!isStopped()){ + stop(); + } +} + +void WebCam::setDevice(const int id) +{ + camId = id; +} + +void WebCam::setInterval(const int interval) +{ + intervalTime = interval; + + if (!isStopped()) { + timer->stop(); + timer->start(interval); + } +} + +bool WebCam::isStopped() const +{ + return stopped; +} + +QMap WebCam::getCamList() +{ + QMap camList; + QList devices = Solid::Device::listFromType(Solid::DeviceInterface::Video, + QString()); + foreach (const Solid::Device &dev, devices) { + QStringList protocols = dev.as()->supportedProtocols(); + + if (protocols.contains("video4linux")) { + QStringList drivers = dev.as()->supportedDrivers("video4linux"); + + if (drivers.contains("video4linux")) { + QString path = dev.as ()->driverHandle("video4linux").toString(); + + bool ok; + int devNumber = path.mid(10).toInt(&ok, 10); + if (ok) { + camList.insert(devNumber, dev.product()); + } + } + } + } + + return camList; +} + +void WebCam::stop() +{ + if (!isStopped()) { + timer->stop(); + + if (cam) { + cvReleaseCapture(&cam); + } + stopped = true; + } +} + +void WebCam::start() +{ + if (isStopped()) { + cam = cvCreateCameraCapture(camId); + + if (cam) { + timer->start(intervalTime); + stopped = false; + } else { + KMessageBox::sorry(0, i18n("Error while initializing the camera")); + } + } +} + +QImage WebCam::prepareFrame(IplImage *frame) +{ + cvCvtColor(frame, frame, CV_BGR2RGB); + cvFlip(frame, frame, 1); + + QImage image((uchar *)frame->imageData, + frame->width, + frame->height, + QImage::Format_RGB888); + +// preview = image; + return image; +} + +void WebCam::sendNewFrame() +{ + IplImage *frame = cvQueryFrame(cam); + + emit newFrame(prepareFrame(frame)); +} +#include "webcam.moc" diff -Naur kdebase-4.4.2.orig/apps/kdepasswd/kcm/webcam.h kdebase-4.4.2/apps/kdepasswd/kcm/webcam.h --- kdebase-4.4.2.orig/apps/kdepasswd/kcm/webcam.h 1970-01-01 01:00:00.000000000 +0100 +++ kdebase-4.4.2/apps/kdepasswd/kcm/webcam.h 2010-04-27 10:57:07.830200025 +0200 @@ -0,0 +1,74 @@ +/** + * Copyright 2010 Felipe Ortiz + * + * 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 + * + * + * Please see the README + * + */ + +/** + * @file Webcam interface based on OpenCV + * @author Felipe Ortiz + */ + +#ifndef WEBCAM_H +#define WEBCAM_H + +#include +#include +#include +#include + +#include +#include + +#include +#include + +class WebCam : public QObject +{ + Q_OBJECT + +public: + explicit WebCam(int interval = 50, QObject *parent = 0); + ~WebCam(); + + void setDevice(const int id); + void setInterval(const int interval); + bool isStopped() const; + + static QMap getCamList(); + + +Q_SIGNALS: + void newFrame(QImage img); + +public Q_SLOTS: + void stop(); + void start(); + void sendNewFrame(); + +private: + QImage prepareFrame(IplImage *frame); + + QTimer *timer; + CvCapture *cam; + int intervalTime; + int camId; + bool stopped; + +}; +#endif diff -Naur kdebase-4.4.2.orig/apps/kdepasswd/kcm/webcamui.cpp kdebase-4.4.2/apps/kdepasswd/kcm/webcamui.cpp --- kdebase-4.4.2.orig/apps/kdepasswd/kcm/webcamui.cpp 1970-01-01 01:00:00.000000000 +0100 +++ kdebase-4.4.2/apps/kdepasswd/kcm/webcamui.cpp 2010-04-27 10:57:07.832697836 +0200 @@ -0,0 +1,103 @@ +/** + * Copyright 2010 Felipe Ortiz + * + * 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 + * + * + * Please see the README + * + */ + +/** + * @file GUI for get picture from a webcam + * @author Felipe Ortiz + */ + +#include +#include + +#include "settings.h" +#include "webcamui.h" + +WebCamUi::WebCamUi(QWidget *parent) : KDialog(parent, Qt::Dialog) +{ + photo = false; + setupUi(mainWidget()); + cam = new WebCam(50, this); + + setCboCamera(); + connect(cboDevice, SIGNAL(activated(int)), this, SLOT(switchCamera(int))); + connect(cam, SIGNAL(newFrame(QImage)), this, SLOT(showImage(QImage))); + connect(this, SIGNAL(okClicked()), this, SLOT(saveImage())); + + switchCamera(cboDevice->currentIndex()); +} + +bool WebCamUi::isPhotoTaken() const +{ + return photo; +} + +void WebCamUi::setCboCamera() +{ + QMap devices = WebCam::getCamList(); + QMap::const_iterator i; + + for (i = devices.constBegin(); i != devices.constEnd(); ++i) { + cboDevice->addItem(i.value(), i.key()); + } +} + +void WebCamUi::switchCamera(int index) +{ + if (!cam->isStopped()) { + cam->stop(); + } + cam->setDevice(cboDevice->itemData(index).toInt()); + cam->start(); +} + +void WebCamUi::showImage(QImage image) +{ + QSize size(lbVideo->width(), lbVideo->height()); + + lbVideo->setPixmap(QPixmap::fromImage(image.scaled(size, Qt::IgnoreAspectRatio))); +} + +QImage WebCamUi::getImage() const +{ + return pix; +} + +QString WebCamUi::getImgName() const +{ + return fname; +} + +void WebCamUi::saveImage() +{ + + cam->stop(); + fname = QInputDialog::getText(this, i18n("New Image"), + i18n("Image name:"), + QLineEdit::Normal, + QString(), &photo); + + if (photo && !fname.isEmpty()) { + pix = lbVideo->pixmap()->toImage(); + } +} + + +#include "webcamui.moc" diff -Naur kdebase-4.4.2.orig/apps/kdepasswd/kcm/webcamui.h kdebase-4.4.2/apps/kdepasswd/kcm/webcamui.h --- kdebase-4.4.2.orig/apps/kdepasswd/kcm/webcamui.h 1970-01-01 01:00:00.000000000 +0100 +++ kdebase-4.4.2/apps/kdepasswd/kcm/webcamui.h 2010-04-27 10:57:07.832697836 +0200 @@ -0,0 +1,60 @@ +/** + * Copyright 2010 Felipe Ortiz + * + * 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 + * + * + * Please see the README + * + */ + +/** + * @file GUI for get picture from a webcam + * @author Felipe Ortiz + */ + +#ifndef WEBCAMUI_H +#define WEBCAMUI_H + +#include + +#include "webcam.h" +#include "ui_webcamui.h" + +class WebCamUi : public KDialog, private Ui::WebCamUi +{ + Q_OBJECT + +public: + explicit WebCamUi(QWidget *parent = 0); + + bool isPhotoTaken() const; + QImage getImage() const; + QString getImgName() const; + +private: + void setCboCamera(); + +private Q_SLOTS: + void switchCamera(int index); + void showImage(QImage image); + void saveImage(); + +private: + QString fname; + QImage pix; + bool photo; + WebCam *cam; +}; +#endif diff -Naur kdebase-4.4.2.orig/apps/kdepasswd/kcm/webcamui.ui kdebase-4.4.2/apps/kdepasswd/kcm/webcamui.ui --- kdebase-4.4.2.orig/apps/kdepasswd/kcm/webcamui.ui 1970-01-01 01:00:00.000000000 +0100 +++ kdebase-4.4.2/apps/kdepasswd/kcm/webcamui.ui 2010-04-27 10:57:07.832697836 +0200 @@ -0,0 +1,82 @@ + + + WebCamUi + + + + 0 + 0 + 539 + 546 + + + + Take a Photo + + + + + + + + + + Select Device: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 503 + 420 + + + + QFrame::StyledPanel + + + + + + + + + + Qt::Horizontal + + + + + + + + KComboBox + QComboBox +
kcombobox.h
+
+
+ + +