~ubuntu-branches/debian/sid/v4l-utils/sid

« back to all changes in this revision

Viewing changes to utils/qv4l2-qt3/qv4l2.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gregor Jasny
  • Date: 2010-02-28 19:44:15 UTC
  • Revision ID: james.westby@ubuntu.com-20100228194415-067hdj8rvawj91zw
Tags: upstream-0.7.90
ImportĀ upstreamĀ versionĀ 0.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "qv4l2.h"
 
3
#include "general-tab.h"
 
4
#include "libv4l2util.h"
 
5
 
 
6
#include <qimage.h>
 
7
#include <qpixmap.h>
 
8
#include <qtoolbar.h>
 
9
#include <qtoolbutton.h>
 
10
#include <qpopupmenu.h>
 
11
#include <qmenubar.h>
 
12
#include <qfile.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>
 
19
#include <qlayout.h>
 
20
#include <qvbox.h>
 
21
#include <qhbox.h>
 
22
#include <qlabel.h>
 
23
#include <qslider.h>
 
24
#include <qspinbox.h>
 
25
#include <qcombobox.h>
 
26
#include <qcheckbox.h>
 
27
#include <qpushbutton.h>
 
28
#include <qtooltip.h>
 
29
#include <qwhatsthis.h>
 
30
 
 
31
#include <fcntl.h>
 
32
#include <sys/ioctl.h>
 
33
#include <errno.h>
 
34
#include <dirent.h>
 
35
 
 
36
#include "fileopen.xpm"
 
37
 
 
38
ApplicationWindow::ApplicationWindow()
 
39
    : QMainWindow( 0, "V4L2 main window", WDestructiveClose | WGroupLeader )
 
40
{
 
41
    QPixmap openIcon, saveIcon;
 
42
 
 
43
    fd = -1;
 
44
 
 
45
    videoDevice = NULL;
 
46
    sigMapper = NULL;
 
47
    QToolBar * fileTools = new QToolBar( this, "file operations" );
 
48
    fileTools->setLabel( "File Operations" );
 
49
 
 
50
    openIcon = QPixmap( fileopen );
 
51
    QToolButton * fileOpen
 
52
        = new QToolButton( openIcon, "Open File", QString::null,
 
53
                           this, SLOT(choose()), fileTools, "open file" );
 
54
 
 
55
    (void)QWhatsThis::whatsThisButton( fileTools );
 
56
 
 
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>";
 
61
 
 
62
    QWhatsThis::add( fileOpen, fileOpenText );
 
63
 
 
64
    QMimeSourceFactory::defaultFactory()->setPixmap( "fileopen", openIcon );
 
65
 
 
66
    QPopupMenu * file = new QPopupMenu( this );
 
67
    menuBar()->insertItem( "&File", file );
 
68
 
 
69
 
 
70
    int id;
 
71
    id = file->insertItem( openIcon, "&Open...",
 
72
                           this, SLOT(choose()), CTRL+Key_O );
 
73
    file->setWhatsThis( id, fileOpenText );
 
74
 
 
75
    file->insertSeparator();
 
76
 
 
77
    file->insertItem( "&Close", this, SLOT(close()), CTRL+Key_W );
 
78
 
 
79
    file->insertItem( "&Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q );
 
80
 
 
81
    menuBar()->insertSeparator();
 
82
 
 
83
    QPopupMenu * help = new QPopupMenu( this );
 
84
    menuBar()->insertItem( "&Help", help );
 
85
 
 
86
    help->insertItem( "&About", this, SLOT(about()), Key_F1 );
 
87
    help->insertItem( "What's &This", this, SLOT(whatsThis()), SHIFT+Key_F1 );
 
88
 
 
89
    statusBar()->message( "Ready", 2000 );
 
90
 
 
91
    tabs = new QTabWidget(this);
 
92
    tabs->setMargin(3);
 
93
 
 
94
    //resize( 450, 600 );
 
95
}
 
96
 
 
97
 
 
98
ApplicationWindow::~ApplicationWindow()
 
99
{
 
100
        if (fd >= 0) ::close(fd);
 
101
}
 
102
 
 
103
 
 
104
void ApplicationWindow::setDevice(const QString &device)
 
105
{
 
106
        if (fd >= 0) ::close(fd);
 
107
        while (QWidget *page = tabs->page(0)) {
 
108
                tabs->removePage(page);
 
109
                delete page;
 
110
        }
 
111
        delete tabs;
 
112
        delete sigMapper;
 
113
        tabs = new QTabWidget(this);
 
114
        tabs->setMargin(3);
 
115
        sigMapper = new QSignalMapper(this);
 
116
        connect(sigMapper, SIGNAL(mapped(int)), this, SLOT(ctrlAction(int)));
 
117
        ctrlMap.clear();
 
118
        widgetMap.clear();
 
119
        classMap.clear();
 
120
 
 
121
        fd = ::open(device, O_RDONLY);
 
122
        if (fd >= 0) {
 
123
                tabs->addTab(new GeneralTab(device, fd, 4, tabs), "General");
 
124
                addTabs();
 
125
        }
 
126
        if (QWidget *current = tabs->currentPage()) {
 
127
                current->show();
 
128
        }
 
129
        tabs->show();
 
130
        tabs->setFocus();
 
131
        setCentralWidget(tabs);
 
132
}
 
133
 
 
134
void ApplicationWindow::selectdev(int index)
 
135
{
 
136
        setDevice(videoDevice->text(index));
 
137
}
 
138
 
 
139
void ApplicationWindow::add_dirVideoDevice(const char *dirname)
 
140
{
 
141
        DIR             *dir;
 
142
        struct dirent   *entry;
 
143
        const char      *vid = "video";
 
144
        const char      *rad = "radio";
 
145
        const char      *vbi = "vbi";
 
146
        char            name[512], *p;
 
147
 
 
148
        dir = opendir(dirname);
 
149
        if (!dir)
 
150
                return;
 
151
 
 
152
        strcpy(name, dirname);
 
153
        strcat(name, "/");
 
154
        p = name + strlen(name);
 
155
 
 
156
        entry = readdir(dir);
 
157
        while (entry) {
 
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);
 
162
 
 
163
                        videoDevice->insertItem(name);
 
164
                }
 
165
                entry = readdir(dir);
 
166
        }
 
167
        closedir(dir);
 
168
}
 
169
 
 
170
void ApplicationWindow::choose()
 
171
{
 
172
        if (videoDevice)
 
173
                delete videoDevice;
 
174
 
 
175
        videoDevice = new QPopupMenu(this);
 
176
 
 
177
        add_dirVideoDevice("/dev");
 
178
        add_dirVideoDevice("/dev/v4l");
 
179
 
 
180
        connect(videoDevice, SIGNAL(activated(int)), this, SLOT(selectdev(int)));
 
181
 
 
182
        videoDevice->show();
 
183
        videoDevice->setFocus();
 
184
}
 
185
 
 
186
void ApplicationWindow::closeEvent( QCloseEvent* ce )
 
187
{
 
188
        ce->accept();
 
189
}
 
190
 
 
191
bool ApplicationWindow::doIoctl(QString descr, unsigned cmd, void *arg)
 
192
{
 
193
        statusBar()->clear();
 
194
        int err = ioctl(fd, cmd, arg);
 
195
 
 
196
        if (err == -1) {
 
197
                QString s = strerror(errno);
 
198
                statusBar()->message(descr + ": " + s, 10000);
 
199
        }
 
200
        return err != -1;
 
201
}
 
202
 
 
203
void ApplicationWindow::about()
 
204
{
 
205
    QMessageBox::about( this, "V4L2 Control Panel",
 
206
                        "This program allows easy experimenting with video4linux devices.");
 
207
}
 
208
 
 
209
ApplicationWindow *g_mw;
 
210
 
 
211
int main(int argc, char **argv)
 
212
{
 
213
    QApplication a(argc, argv);
 
214
    g_mw = new ApplicationWindow();
 
215
    g_mw->setCaption( "V4L2 Control Panel" );
 
216
    g_mw->setDevice("/dev/video0");
 
217
    g_mw->show();
 
218
    a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) );
 
219
    return a.exec();
 
220
}