~ubuntu-branches/ubuntu/karmic/ktimetrace/karmic

« back to all changes in this revision

Viewing changes to ktimetrace/bufferdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): David Schleef
  • Date: 2002-03-03 02:12:29 UTC
  • Revision ID: james.westby@ubuntu.com-20020303021229-kqwt09smq7hblfhh
Tags: upstream-0.2.33
ImportĀ upstreamĀ versionĀ 0.2.33

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          bufferdialog.cpp  -  description
 
3
                             -------------------
 
4
    begin                : Thu Jun 14 2001
 
5
    copyright            : (C) 2001 by Frank Mori Hess
 
6
    email                : fmhess@uiuc.edu
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
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.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
 
 
19
#include "bufferdialog.h"
 
20
#include "resource.h"
 
21
 
 
22
#include <qmessagebox.h>
 
23
#include <qwhatsthis.h>
 
24
 
 
25
#include <iostream.h>
 
26
#include <cmath>
 
27
#include <sys/types.h>
 
28
#include <unistd.h>
 
29
 
 
30
BufferDialog::BufferDialog(adc *myADC, QWidget *parent, const char *name) : QDialog(parent, name, true)
 
31
{
 
32
        const int kByte = 1024;
 
33
 
 
34
        board = myADC;
 
35
        mBSize = myADC->maxBufferSize() / kByte;
 
36
        bSize = myADC->bufferSize() / kByte;
 
37
        maxModified = false;
 
38
        QString string;
 
39
 
 
40
        // create sub-widgets
 
41
        const int hsep = 10;
 
42
        const int vsep = 10;
 
43
 
 
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);
 
50
 
 
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.");
 
65
 
 
66
        bufSizeLabel = new QLabel("Comedi's buffer size / (kilobytes)", this);
 
67
        bufSizeLabel->move(bufSize->geometry().right() + hsep, bufSize->y());
 
68
        bufSizeLabel->adjustSize();
 
69
 
 
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.");
 
83
 
 
84
        maxBufSizeLabel = new QLabel("Comedi's maximum buffer size / (kilobytes)", this);
 
85
        maxBufSizeLabel->move(maxBufSize->geometry().right() + hsep, maxBufSize->y());
 
86
        maxBufSizeLabel->adjustSize();
 
87
 
 
88
        okButton = new QPushButton("&Ok", this);
 
89
        okButton->move(maxBufSize->x(), maxBufSize->geometry().bottom() + 2 * vsep);
 
90
        okButton->adjustSize();
 
91
 
 
92
        applyButton = new QPushButton("&Apply", this);
 
93
        applyButton->move(okButton->geometry().right() + hsep, okButton->y());
 
94
        applyButton->adjustSize();
 
95
 
 
96
        cancelButton = new QPushButton("&Cancel", this);
 
97
        cancelButton->move(applyButton->geometry().right() + hsep, okButton->y());
 
98
        cancelButton->adjustSize();
 
99
 
 
100
        // adjust overall dialog size
 
101
        adjustSize();
 
102
 
 
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()));
 
109
}
 
110
 
 
111
BufferDialog::~BufferDialog()
 
112
{
 
113
}
 
114
 
 
115
void BufferDialog::slotBufSize(int size)
 
116
{
 
117
        bSize = size;
 
118
}
 
119
 
 
120
void BufferDialog::slotMaxBufSize(int size)
 
121
{
 
122
        if(size != mBSize)
 
123
        {
 
124
                maxModified = true;
 
125
                mBSize = size;
 
126
                bufSize->setMaxValue(mBSize);
 
127
        }
 
128
}
 
129
 
 
130
void BufferDialog::slotApply()
 
131
{
 
132
        const int kByte = 1024;
 
133
        int ret;
 
134
 
 
135
        //adjust comedi's maximum buffer size (requires root privilege)
 
136
        if(maxModified)
 
137
        {
 
138
                ret = board->maxBufferSize(mBSize * kByte);
 
139
                if(ret < 0)
 
140
                {
 
141
                        QMessageBox::warning(this, "Warning",
 
142
                                "An error occured while attempting to\n"
 
143
                                "adjust comedi's maximum buffer size");
 
144
                        return;
 
145
                }
 
146
                mBSize = ret / kByte;
 
147
                maxBufSize->setValue(mBSize);
 
148
                maxModified = false;
 
149
        }
 
150
 
 
151
        // adjust comedi's buffer size
 
152
        ret = board->bufferSize(bSize * kByte);
 
153
        if(ret < 0)
 
154
        {
 
155
                QMessageBox::warning(this, "Warning",
 
156
                        "An error occured while attempting to\n"
 
157
                        "adjust comedi's buffer size");
 
158
                return;
 
159
        }
 
160
        bSize = ret / kByte;
 
161
        bufSize->setValue(bSize);
 
162
 
 
163
        return;
 
164
}
 
165
 
 
166
void BufferDialog::slotOk()
 
167
{
 
168
        slotApply();
 
169
        accept();
 
170
}