diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2008-11-16 01:26:13 -0200 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2008-11-16 01:26:13 -0200 |
commit | e4997e2899e1870f5ee53e72a72d49f09ef47a7e (patch) | |
tree | 45e60f1eb3af6fc9a29b3f4038b27c9c187ced3d | |
parent | 60c3a3c2818fb9a088b9f2ea033fbc671fb3abc8 (diff) | |
download | mediapointer-dvb-s2-e4997e2899e1870f5ee53e72a72d49f09ef47a7e.tar.gz mediapointer-dvb-s2-e4997e2899e1870f5ee53e72a72d49f09ef47a7e.tar.bz2 |
select video device via a popup menu
From: Mauro Carvalho Chehab <mchehab@redhat.com>
Seeking for a video device at /dev is sometimes hard, since not all
distros create a /dev/v4l dir. Instead of opening a file, be more
user-friendly, by just displaying the valid files.
Priority: normal
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | v4l2-apps/util/qv4l2/qv4l2.cpp | 58 | ||||
-rw-r--r-- | v4l2-apps/util/qv4l2/qv4l2.h | 3 |
2 files changed, 53 insertions, 8 deletions
diff --git a/v4l2-apps/util/qv4l2/qv4l2.cpp b/v4l2-apps/util/qv4l2/qv4l2.cpp index a93608af2..eb1506531 100644 --- a/v4l2-apps/util/qv4l2/qv4l2.cpp +++ b/v4l2-apps/util/qv4l2/qv4l2.cpp @@ -31,6 +31,7 @@ #include <fcntl.h> #include <sys/ioctl.h> #include <errno.h> +#include <dirent.h> #include "fileopen.xpm" @@ -41,6 +42,7 @@ ApplicationWindow::ApplicationWindow() fd = -1; + videoDevice = NULL; sigMapper = NULL; QToolBar * fileTools = new QToolBar( this, "file operations" ); fileTools->setLabel( "File Operations" ); @@ -129,17 +131,57 @@ void ApplicationWindow::setDevice(const QString &device) setCentralWidget(tabs); } -void ApplicationWindow::choose() +void ApplicationWindow::selectdev(int index) +{ + setDevice(videoDevice->text(index)); +} + +void ApplicationWindow::add_dirVideoDevice(char *dirname) { - QString fn = QFileDialog::getOpenFileName( "/dev/v4l", QString::null, - this); - if ( !fn.isEmpty() ) { - setDevice(fn); - } - else - statusBar()->message( "Loading aborted", 2000 ); + DIR *dir; + struct dirent *entry; + char *vid = "video"; + char *rad = "radio"; + char *vbi = "vbi"; + char name[512], *p; + + dir = opendir(dirname); + if (!dir) + return; + + strcpy(name, dirname); + strcat(name, "/"); + p = name + strlen(name); + + entry = readdir(dir); + while (entry) { + if (!strncmp(entry->d_name, vid, strlen(vid)) || + !strncmp(entry->d_name, rad, strlen(rad)) || + !strncmp(entry->d_name, vbi, strlen(vbi))) { + strcpy(p, entry->d_name); + + videoDevice->insertItem(name); + } + entry = readdir(dir); + } + closedir(dir); } +void ApplicationWindow::choose() +{ + if (videoDevice) + delete videoDevice; + + videoDevice = new QPopupMenu(this); + + add_dirVideoDevice("/dev"); + add_dirVideoDevice("/dev/v4l"); + + connect(videoDevice, SIGNAL(activated(int)), this, SLOT(selectdev(int))); + + videoDevice->show(); + videoDevice->setFocus(); +} void ApplicationWindow::closeEvent( QCloseEvent* ce ) { diff --git a/v4l2-apps/util/qv4l2/qv4l2.h b/v4l2-apps/util/qv4l2/qv4l2.h index 1a0a8e15d..805c5d612 100644 --- a/v4l2-apps/util/qv4l2/qv4l2.h +++ b/v4l2-apps/util/qv4l2/qv4l2.h @@ -59,12 +59,14 @@ protected: void closeEvent( QCloseEvent* ); private slots: + void selectdev(int); void choose(); void ctrlAction(int); void about(); private: + void add_dirVideoDevice(char *dirname); void addTabs(); void finishGrid(QWidget *vbox, QGrid *grid, unsigned ctrl_class, bool odd); void addCtrl(QGrid *grid, const struct v4l2_queryctrl &qctrl); @@ -88,6 +90,7 @@ private: QString filename; QSignalMapper *sigMapper; QTabWidget *tabs; + QPopupMenu *videoDevice; int fd; CtrlMap ctrlMap; WidgetMap widgetMap; |