3
#include "general-tab.h"
4
#include "libv4l2util.h"
9
#include <qtoolbutton.h>
10
#include <qpopupmenu.h>
13
#include <qfiledialog.h>
14
#include <qstatusbar.h>
15
#include <qapplication.h>
16
#include <qmessagebox.h>
17
#include <qlineedit.h>
18
#include <qvalidator.h>
25
#include <qcombobox.h>
26
#include <qcheckbox.h>
27
#include <qpushbutton.h>
29
#include <qwhatsthis.h>
32
#include <sys/ioctl.h>
36
#include "fileopen.xpm"
38
ApplicationWindow::ApplicationWindow()
39
: QMainWindow( 0, "V4L2 main window", WDestructiveClose | WGroupLeader )
41
QPixmap openIcon, saveIcon;
47
QToolBar * fileTools = new QToolBar( this, "file operations" );
48
fileTools->setLabel( "File Operations" );
50
openIcon = QPixmap( fileopen );
51
QToolButton * fileOpen
52
= new QToolButton( openIcon, "Open File", QString::null,
53
this, SLOT(choose()), fileTools, "open file" );
55
(void)QWhatsThis::whatsThisButton( fileTools );
57
const char * fileOpenText = "<p><img source=\"fileopen\"> "
58
"Click this button to open a <em>new v4l device</em>.<br>"
59
"You can also select the <b>Open</b> command "
60
"from the <b>File</b> menu.</p>";
62
QWhatsThis::add( fileOpen, fileOpenText );
64
QMimeSourceFactory::defaultFactory()->setPixmap( "fileopen", openIcon );
66
QPopupMenu * file = new QPopupMenu( this );
67
menuBar()->insertItem( "&File", file );
71
id = file->insertItem( openIcon, "&Open...",
72
this, SLOT(choose()), CTRL+Key_O );
73
file->setWhatsThis( id, fileOpenText );
75
file->insertSeparator();
77
file->insertItem( "&Close", this, SLOT(close()), CTRL+Key_W );
79
file->insertItem( "&Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q );
81
menuBar()->insertSeparator();
83
QPopupMenu * help = new QPopupMenu( this );
84
menuBar()->insertItem( "&Help", help );
86
help->insertItem( "&About", this, SLOT(about()), Key_F1 );
87
help->insertItem( "What's &This", this, SLOT(whatsThis()), SHIFT+Key_F1 );
89
statusBar()->message( "Ready", 2000 );
91
tabs = new QTabWidget(this);
98
ApplicationWindow::~ApplicationWindow()
100
if (fd >= 0) ::close(fd);
104
void ApplicationWindow::setDevice(const QString &device)
106
if (fd >= 0) ::close(fd);
107
while (QWidget *page = tabs->page(0)) {
108
tabs->removePage(page);
113
tabs = new QTabWidget(this);
115
sigMapper = new QSignalMapper(this);
116
connect(sigMapper, SIGNAL(mapped(int)), this, SLOT(ctrlAction(int)));
121
fd = ::open(device, O_RDONLY);
123
tabs->addTab(new GeneralTab(device, fd, 4, tabs), "General");
126
if (QWidget *current = tabs->currentPage()) {
131
setCentralWidget(tabs);
134
void ApplicationWindow::selectdev(int index)
136
setDevice(videoDevice->text(index));
139
void ApplicationWindow::add_dirVideoDevice(const char *dirname)
142
struct dirent *entry;
143
const char *vid = "video";
144
const char *rad = "radio";
145
const char *vbi = "vbi";
148
dir = opendir(dirname);
152
strcpy(name, dirname);
154
p = name + strlen(name);
156
entry = readdir(dir);
158
if (!strncmp(entry->d_name, vid, strlen(vid)) ||
159
!strncmp(entry->d_name, rad, strlen(rad)) ||
160
!strncmp(entry->d_name, vbi, strlen(vbi))) {
161
strcpy(p, entry->d_name);
163
videoDevice->insertItem(name);
165
entry = readdir(dir);
170
void ApplicationWindow::choose()
175
videoDevice = new QPopupMenu(this);
177
add_dirVideoDevice("/dev");
178
add_dirVideoDevice("/dev/v4l");
180
connect(videoDevice, SIGNAL(activated(int)), this, SLOT(selectdev(int)));
183
videoDevice->setFocus();
186
void ApplicationWindow::closeEvent( QCloseEvent* ce )
191
bool ApplicationWindow::doIoctl(QString descr, unsigned cmd, void *arg)
193
statusBar()->clear();
194
int err = ioctl(fd, cmd, arg);
197
QString s = strerror(errno);
198
statusBar()->message(descr + ": " + s, 10000);
203
void ApplicationWindow::about()
205
QMessageBox::about( this, "V4L2 Control Panel",
206
"This program allows easy experimenting with video4linux devices.");
209
ApplicationWindow *g_mw;
211
int main(int argc, char **argv)
213
QApplication a(argc, argv);
214
g_mw = new ApplicationWindow();
215
g_mw->setCaption( "V4L2 Control Panel" );
216
g_mw->setDevice("/dev/video0");
218
a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) );