~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to arts/tools/midiinstdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
        /*
 
2
 
 
3
        Copyright (C) 1998 Stefan Westerfeld
 
4
                       stefan@space.twc.de
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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.
 
19
 
 
20
    */
 
21
 
 
22
#include "midiinstdlg.h"
 
23
#include <klocale.h>
 
24
#include <kstddirs.h>
 
25
 
 
26
#include <qlayout.h>
 
27
#include <qlabel.h>
 
28
#include <qfile.h>
 
29
#include <qdir.h>
 
30
#include <kbuttonbox.h>
 
31
#include <kseparator.h>
 
32
#include <kdebug.h>
 
33
 
 
34
static QStringList getArtsPath()
 
35
{
 
36
    QStringList artsPath;
 
37
        QString dir = locate("data", "artsbuilder/examples/");
 
38
        artsPath += dir;
 
39
    QString home = QDir::homeDirPath() + "/arts/structures/";
 
40
    artsPath += home;
 
41
        return artsPath;
 
42
}
 
43
 
 
44
static QStringList listFiles(QString directory, QString extension)
 
45
{
 
46
        QStringList result;
 
47
    QStringList artsPath = getArtsPath();
 
48
 
 
49
    QStringList::Iterator it;
 
50
    for ( it = artsPath.begin(); it != artsPath.end(); it++ ) {
 
51
        QString pathname = *it + "/" + directory;
 
52
        QDir dir(pathname, extension);
 
53
        if (dir.exists()) {
 
54
            //kdDebug() << "found dir " << dir.absPath() << endl;
 
55
            result += dir.entryList();
 
56
        }
 
57
    }
 
58
 
 
59
        return result;
 
60
}
 
61
 
 
62
MidiInstDlg::MidiInstDlg(QWidget *parent)
 
63
        :QDialog(parent,"instrument",TRUE)
 
64
{
 
65
        QVBoxLayout *mainlayout = new QVBoxLayout(this);
 
66
 
 
67
// caption label: title
 
68
 
 
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);
 
78
 
 
79
// hruler
 
80
 
 
81
        mainlayout->addSpacing(5);
 
82
        KSeparator *ruler2 = new KSeparator( KSeparator::HLine, this);
 
83
        mainlayout->addWidget(ruler2);
 
84
        mainlayout->addSpacing(5);
 
85
 
 
86
// combobox
 
87
 
 
88
        box = new QComboBox(this);
 
89
 
 
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;
 
100
    }
 
101
 
 
102
 
 
103
    QStringList maps = listFiles(".","*.arts-map");
 
104
 
 
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;
 
113
    }
 
114
 
 
115
        mainlayout->addWidget(box);
 
116
 
 
117
// hruler
 
118
 
 
119
        mainlayout->addSpacing(5);
 
120
        KSeparator *ruler = new KSeparator( KSeparator::HLine, this);
 
121
        mainlayout->addWidget(ruler);
 
122
        mainlayout->addSpacing(5);
 
123
 
 
124
// buttons
 
125
 
 
126
        QHBoxLayout *buttonlayout = new QHBoxLayout;
 
127
        mainlayout->addSpacing(5);
 
128
        mainlayout->addLayout(buttonlayout);
 
129
        mainlayout->addSpacing(5);
 
130
 
 
131
        buttonlayout->addSpacing(5);
 
132
        KButtonBox *bbox = new KButtonBox(this);
 
133
 
 
134
        bbox->addButton(i18n("Help"));
 
135
        bbox->addStretch(1);
 
136
 
 
137
        QButton *okbutton = bbox->addButton(i18n("OK"));
 
138
        connect( okbutton, SIGNAL( clicked() ), SLOT(accept() ) );
 
139
 
 
140
        bbox->layout();
 
141
 
 
142
        buttonlayout->addWidget(bbox);
 
143
        buttonlayout->addSpacing(5);
 
144
 
 
145
        mainlayout->freeze();
 
146
};
 
147
 
 
148
QCString MidiInstDlg::filename()
 
149
{
 
150
    QStringList artsPath = getArtsPath();
 
151
        QString instrument = box->currentText();
 
152
 
 
153
    QStringList::Iterator it;
 
154
 
 
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);
 
160
 
 
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);
 
165
    }
 
166
 
 
167
        return "";
 
168
}
 
169
#include "midiinstdlg.moc"