1
/***************************************************************************
2
bufferdialog.cpp - description
4
begin : Thu Jun 14 2001
5
copyright : (C) 2001 by Frank Mori Hess
6
email : fmhess@uiuc.edu
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
19
#include "bufferdialog.h"
22
#include <qmessagebox.h>
23
#include <qwhatsthis.h>
27
#include <sys/types.h>
30
BufferDialog::BufferDialog(adc *myADC, QWidget *parent, const char *name) : QDialog(parent, name, true)
32
const int kByte = 1024;
35
mBSize = myADC->maxBufferSize() / kByte;
36
bSize = myADC->bufferSize() / kByte;
44
boardDesc = new QLabel(this);
45
boardDesc->move(hsep, vsep);
46
string = "<b>Device: " + board->boardName() + " on " + board->devicePath() + "</b>";
47
boardDesc->setTextFormat(RichText);
48
boardDesc->resize(boardDesc->fontMetrics().size(0, string));
49
boardDesc->setText(string);
51
bufSize = new QSpinBox(this);
52
bufSize->move(boardDesc->x(), boardDesc->geometry().bottom() + vsep);
53
// set max value large temporarily before calling adjustSize();
54
bufSize->setMaxValue(pow(2, 31) - 1);
55
bufSize->adjustSize();
56
bufSize->setMaxValue(mBSize);
57
bufSize->setMinValue(1);
58
bufSize->setValue(bSize);
59
QWhatsThis::add(bufSize,
60
"Changes the size of the memory buffer that comedi uses to store data "
61
"waiting to be read from /dev/comediX (by this program). A larger "
62
"buffer can be helpful if you are taking data at high frequencies. "
63
"The comedi_config program included with comedilib can be used to "
64
"adjust the maximum allowed buffer size.");
66
bufSizeLabel = new QLabel("Comedi's buffer size / (kilobytes)", this);
67
bufSizeLabel->move(bufSize->geometry().right() + hsep, bufSize->y());
68
bufSizeLabel->adjustSize();
70
maxBufSize = new QSpinBox(this);
71
maxBufSize->move(bufSize->x(), bufSize->geometry().bottom() + vsep);
72
maxBufSize->setMinValue(1);
73
maxBufSize->setMaxValue(pow(2, 31) - 1);
74
maxBufSize->setValue(mBSize);
75
maxBufSize->adjustSize();
76
// enable if we are root
77
maxBufSize->setEnabled(getuid() == 0);
78
QWhatsThis::add(maxBufSize,
79
"This allows you to adjust comedi's maximum allowed "
80
"buffer size. You must have root privilege. "
81
"The comedi_config program included with comedilib can also be used to "
82
"adjust the maximum allowed buffer size.");
84
maxBufSizeLabel = new QLabel("Comedi's maximum buffer size / (kilobytes)", this);
85
maxBufSizeLabel->move(maxBufSize->geometry().right() + hsep, maxBufSize->y());
86
maxBufSizeLabel->adjustSize();
88
okButton = new QPushButton("&Ok", this);
89
okButton->move(maxBufSize->x(), maxBufSize->geometry().bottom() + 2 * vsep);
90
okButton->adjustSize();
92
applyButton = new QPushButton("&Apply", this);
93
applyButton->move(okButton->geometry().right() + hsep, okButton->y());
94
applyButton->adjustSize();
96
cancelButton = new QPushButton("&Cancel", this);
97
cancelButton->move(applyButton->geometry().right() + hsep, okButton->y());
98
cancelButton->adjustSize();
100
// adjust overall dialog size
103
// connect signals/slots
104
connect(bufSize, SIGNAL(valueChanged(int)), SLOT(slotBufSize(int)));
105
connect(maxBufSize, SIGNAL(valueChanged(int)), SLOT(slotMaxBufSize(int)));
106
connect(okButton, SIGNAL(clicked()), SLOT(slotOk()));
107
connect(applyButton, SIGNAL(clicked()), SLOT(slotApply()));
108
connect(cancelButton, SIGNAL(clicked()), SLOT(reject()));
111
BufferDialog::~BufferDialog()
115
void BufferDialog::slotBufSize(int size)
120
void BufferDialog::slotMaxBufSize(int size)
126
bufSize->setMaxValue(mBSize);
130
void BufferDialog::slotApply()
132
const int kByte = 1024;
135
//adjust comedi's maximum buffer size (requires root privilege)
138
ret = board->maxBufferSize(mBSize * kByte);
141
QMessageBox::warning(this, "Warning",
142
"An error occured while attempting to\n"
143
"adjust comedi's maximum buffer size");
146
mBSize = ret / kByte;
147
maxBufSize->setValue(mBSize);
151
// adjust comedi's buffer size
152
ret = board->bufferSize(bSize * kByte);
155
QMessageBox::warning(this, "Warning",
156
"An error occured while attempting to\n"
157
"adjust comedi's buffer size");
161
bufSize->setValue(bSize);
166
void BufferDialog::slotOk()