3
Copyright (C) 1998 Stefan Westerfeld
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
#include "midiinstdlg.h"
30
#include <kbuttonbox.h>
31
#include <kseparator.h>
34
static QStringList getArtsPath()
37
QString dir = locate("data", "artsbuilder/examples/");
39
QString home = QDir::homeDirPath() + "/arts/structures/";
44
static QStringList listFiles(QString directory, QString extension)
47
QStringList artsPath = getArtsPath();
49
QStringList::Iterator it;
50
for ( it = artsPath.begin(); it != artsPath.end(); it++ ) {
51
QString pathname = *it + "/" + directory;
52
QDir dir(pathname, extension);
54
//kdDebug() << "found dir " << dir.absPath() << endl;
55
result += dir.entryList();
62
MidiInstDlg::MidiInstDlg(QWidget *parent)
63
:QDialog(parent,"instrument",TRUE)
65
QVBoxLayout *mainlayout = new QVBoxLayout(this);
67
// caption label: title
69
mainlayout->addSpacing(5);
70
QLabel *captionlabel = new QLabel(this);
71
QFont labelfont(captionlabel->font());
72
labelfont.setPointSize(labelfont.pointSize()*3/2);
73
captionlabel->setFont(labelfont);
74
captionlabel->setText(QString(" ")+QString(i18n("Instrument"))+QString(" "));
75
captionlabel->setAlignment(AlignCenter);
76
//min_size(captionlabel);
77
mainlayout->addWidget(captionlabel);
81
mainlayout->addSpacing(5);
82
KSeparator *ruler2 = new KSeparator( KSeparator::HLine, this);
83
mainlayout->addWidget(ruler2);
84
mainlayout->addSpacing(5);
88
box = new QComboBox(this);
90
QStringList instruments = listFiles(".","*.arts");
91
QStringList::Iterator it;
92
for ( it = instruments.begin(); it != instruments.end(); it++ ) {
93
QString modname = *it;
94
QString prefix = QString::fromLatin1("instrument_");
95
if (modname.length() > 5)
96
modname.truncate(modname.length()-5); // kill .arts extension
97
if ( (modname.startsWith(prefix)) && (!modname.contains("_GUI")) )
98
box->insertItem(modname.mid(prefix.length()));
99
//kdDebug() << "inserted instrument: " << modname.mid(prefix.length()) << endl;
103
QStringList maps = listFiles(".","*.arts-map");
105
for ( it = maps.begin(); it != maps.end(); it++ ) {
106
QString modname = *it;
107
QString prefix = QString::fromLatin1("instrument_");
108
if (modname.length() > 9)
109
modname.truncate(modname.length()-9); // kill .arts-map extension
110
if (modname.startsWith(prefix))
111
box->insertItem(modname.mid(prefix.length()));
112
//kdDebug() << "inserted map: " << modname.mid(prefix.length()) << endl;
115
mainlayout->addWidget(box);
119
mainlayout->addSpacing(5);
120
KSeparator *ruler = new KSeparator( KSeparator::HLine, this);
121
mainlayout->addWidget(ruler);
122
mainlayout->addSpacing(5);
126
QHBoxLayout *buttonlayout = new QHBoxLayout;
127
mainlayout->addSpacing(5);
128
mainlayout->addLayout(buttonlayout);
129
mainlayout->addSpacing(5);
131
buttonlayout->addSpacing(5);
132
KButtonBox *bbox = new KButtonBox(this);
134
bbox->addButton(i18n("Help"));
137
QButton *okbutton = bbox->addButton(i18n("OK"));
138
connect( okbutton, SIGNAL( clicked() ), SLOT(accept() ) );
142
buttonlayout->addWidget(bbox);
143
buttonlayout->addSpacing(5);
145
mainlayout->freeze();
148
QCString MidiInstDlg::filename()
150
QStringList artsPath = getArtsPath();
151
QString instrument = box->currentText();
153
QStringList::Iterator it;
155
for ( it = artsPath.begin(); it != artsPath.end(); it++ ) {
156
QString pathname = *it + QString::fromLatin1("/instrument_") + instrument + QString::fromLatin1(".arts");
157
QFileInfo fi(pathname);
158
if (fi.exists() && fi.isReadable())
159
return QFile::encodeName(pathname);
161
pathname = *it + QString::fromLatin1("/instrument_") + instrument + QString::fromLatin1(".arts-map");
162
fi.setFile(pathname);
163
if (fi.exists() && fi.isReadable())
164
return QFile::encodeName(pathname);
169
#include "midiinstdlg.moc"