~ubuntu-branches/debian/squeeze/qsampler/squeeze

« back to all changes in this revision

Viewing changes to src/qsamplerOptions.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2008-08-28 08:43:21 UTC
  • mfrom: (1.1.1 upstream) (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080828084321-guq8v04yg31co9gm
Tags: 0.2.1-1
* New upstream release
* Uploaded to Debian (Closes: #280576)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// qsamplerOptions.cpp
2
2
//
3
3
/****************************************************************************
4
 
   Copyright (C) 2003-2005, rncbc aka Rui Nuno Capela. All rights reserved.
 
4
   Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
 
5
   Copyright (C) 2007, Christian Schoenebeck
5
6
 
6
7
   This program is free software; you can redistribute it and/or
7
8
   modify it under the terms of the GNU General Public License
13
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
15
   GNU General Public License for more details.
15
16
 
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
   You should have received a copy of the GNU General Public License along
 
18
   with this program; if not, write to the Free Software Foundation, Inc.,
 
19
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
 
20
21
*****************************************************************************/
21
22
 
 
23
#include "qsamplerAbout.h"
22
24
#include "qsamplerOptions.h"
23
 
#include "qsamplerAbout.h"
24
25
 
25
 
#include <qcombobox.h>
 
26
#include <QTextStream>
 
27
#include <QComboBox>
26
28
 
27
29
#include <lscp/client.h>
28
30
 
29
 
#include "config.h"
30
 
 
31
31
#ifdef CONFIG_LIBGIG
32
32
#include <gig.h>
33
33
#endif
34
34
 
35
35
 
 
36
namespace QSampler {
 
37
 
36
38
//-------------------------------------------------------------------------
37
 
// qsamplerOptions - Prototype settings structure.
 
39
// QSampler::Options - Prototype settings structure.
38
40
//
39
41
 
40
42
// Constructor.
41
 
qsamplerOptions::qsamplerOptions (void)
 
43
Options::Options (void)
 
44
        : m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE)
42
45
{
43
 
    // Begin master key group.
44
 
    m_settings.beginGroup("/qsampler");
45
 
 
46
 
    // And go into general options group.
47
 
    m_settings.beginGroup("/Options");
48
 
 
49
 
    // Load server options...
50
 
    m_settings.beginGroup("/Server");
51
 
    sServerHost    = m_settings.readEntry("/ServerHost", "localhost");
52
 
    iServerPort    = m_settings.readNumEntry("/ServerPort", 8888);
53
 
    iServerTimeout = m_settings.readNumEntry("/ServerTimeout", 1000);
54
 
    bServerStart   = m_settings.readBoolEntry("/ServerStart", true);
55
 
    sServerCmdLine = m_settings.readEntry("/ServerCmdLine", "linuxsampler");
56
 
    iStartDelay    = m_settings.readNumEntry("/StartDelay", 3);
57
 
    m_settings.endGroup();
58
 
 
59
 
    // Load display options...
60
 
    m_settings.beginGroup("/Display");
61
 
    sDisplayFont     = m_settings.readEntry("/DisplayFont", QString::null);
62
 
    bDisplayEffect   = m_settings.readBoolEntry("/DisplayEffect", true);
63
 
    bAutoRefresh     = m_settings.readBoolEntry("/AutoRefresh", true);
64
 
    iAutoRefreshTime = m_settings.readNumEntry("/AutoRefreshTime", 1000);
65
 
    iMaxVolume       = m_settings.readNumEntry("/MaxVolume", 100);
66
 
    sMessagesFont    = m_settings.readEntry("/MessagesFont", QString::null);
67
 
    bMessagesLimit   = m_settings.readBoolEntry("/MessagesLimit", true);
68
 
    iMessagesLimitLines = m_settings.readNumEntry("/MessagesLimitLines", 1000);
69
 
    bConfirmRemove   = m_settings.readBoolEntry("/ConfirmRemove", true);
70
 
    bKeepOnTop       = m_settings.readBoolEntry("/KeepOnTop", true);
71
 
    bStdoutCapture   = m_settings.readBoolEntry("/StdoutCapture", true);
72
 
    bCompletePath    = m_settings.readBoolEntry("/CompletePath", true);
73
 
    iMaxRecentFiles  = m_settings.readNumEntry("/MaxRecentFiles", 5);
74
 
    bInstrumentNames = m_settings.readBoolEntry("/InstrumentNames", false);
75
 
    m_settings.endGroup();
76
 
 
77
 
    // And go into view options group.
78
 
    m_settings.beginGroup("/View");
79
 
    bMenubar     = m_settings.readBoolEntry("/Menubar", true);
80
 
    bToolbar     = m_settings.readBoolEntry("/Toolbar", true);
81
 
    bStatusbar   = m_settings.readBoolEntry("/Statusbar", true);
82
 
    bAutoArrange = m_settings.readBoolEntry("/AutoArrange", true);
83
 
    m_settings.endGroup();
84
 
 
85
 
    m_settings.endGroup(); // Options group.
86
 
 
87
 
    // Recent file list.
88
 
    m_settings.beginGroup("/RecentFiles");
89
 
    recentFiles.clear();
90
 
    for (int i = 0; i < iMaxRecentFiles; i++) {
91
 
        QString sFilename = m_settings.readEntry("/File" + QString::number(i + 1), QString::null);
92
 
        if (!sFilename.isEmpty())
93
 
            recentFiles.append(sFilename);
94
 
    }
95
 
    m_settings.endGroup();
96
 
 
97
 
    // Last but not least, get the default directories.
98
 
    m_settings.beginGroup("/Default");
99
 
    sSessionDir    = m_settings.readEntry("/SessionDir", QString::null);
100
 
    sInstrumentDir = m_settings.readEntry("/InstrumentDir", QString::null);
101
 
    sEngineName    = m_settings.readEntry("/EngineName", QString::null);
102
 
    sAudioDriver   = m_settings.readEntry("/AudioDriver", QString::null);
103
 
    sMidiDriver    = m_settings.readEntry("/MidiDriver", QString::null);
104
 
    m_settings.endGroup();
 
46
        // Begin into general options group.
 
47
        m_settings.beginGroup("/Options");
 
48
 
 
49
        // Load server options...
 
50
        m_settings.beginGroup("/Server");
 
51
        sServerHost    = m_settings.value("/ServerHost", "localhost").toString();
 
52
        iServerPort    = m_settings.value("/ServerPort", 8888).toInt();
 
53
        iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt();
 
54
        bServerStart   = m_settings.value("/ServerStart", true).toBool();
 
55
        sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString();
 
56
        iStartDelay    = m_settings.value("/StartDelay", 3).toInt();
 
57
        m_settings.endGroup();
 
58
 
 
59
        // Load display options...
 
60
        m_settings.beginGroup("/Display");
 
61
        sDisplayFont     = m_settings.value("/DisplayFont").toString();
 
62
        bDisplayEffect   = m_settings.value("/DisplayEffect", true).toBool();
 
63
        bAutoRefresh     = m_settings.value("/AutoRefresh", true).toBool();
 
64
        iAutoRefreshTime = m_settings.value("/AutoRefreshTime", 1000).toInt();
 
65
        iMaxVolume       = m_settings.value("/MaxVolume", 100).toInt();
 
66
        sMessagesFont    = m_settings.value("/MessagesFont").toString();
 
67
        bMessagesLimit   = m_settings.value("/MessagesLimit", true).toBool();
 
68
        iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt();
 
69
        bConfirmRemove   = m_settings.value("/ConfirmRemove", true).toBool();
 
70
        bKeepOnTop       = m_settings.value("/KeepOnTop", true).toBool();
 
71
        bStdoutCapture   = m_settings.value("/StdoutCapture", true).toBool();
 
72
        bCompletePath    = m_settings.value("/CompletePath", true).toBool();
 
73
        iMaxRecentFiles  = m_settings.value("/MaxRecentFiles", 5).toInt();
 
74
// if libgig provides a fast way to retrieve instrument names even for large
 
75
// .gig files, then we enable this feature by default
 
76
#if HAVE_LIBGIG_SETAUTOLOAD
 
77
        bInstrumentNames = m_settings.value("/InstrumentNames", true).toBool();
 
78
#else
 
79
        bInstrumentNames = m_settings.value("/InstrumentNames", false).toBool();
 
80
#endif
 
81
        m_settings.endGroup();
 
82
 
 
83
        // And go into view options group.
 
84
        m_settings.beginGroup("/View");
 
85
        bMenubar     = m_settings.value("/Menubar", true).toBool();
 
86
        bToolbar     = m_settings.value("/Toolbar", true).toBool();
 
87
        bStatusbar   = m_settings.value("/Statusbar", true).toBool();
 
88
        bAutoArrange = m_settings.value("/AutoArrange", true).toBool();
 
89
        m_settings.endGroup();
 
90
 
 
91
        m_settings.endGroup(); // Options group.
 
92
 
 
93
        // Recent file list.
 
94
        recentFiles.clear();
 
95
        m_settings.beginGroup("/RecentFiles");
 
96
        for (int iFile = 0; iFile < iMaxRecentFiles; iFile++) {
 
97
                QString sFilename = m_settings.value(
 
98
                        "/File" + QString::number(iFile + 1)).toString();
 
99
                if (!sFilename.isEmpty())
 
100
                        recentFiles.append(sFilename);
 
101
        }
 
102
        m_settings.endGroup();
 
103
 
 
104
        // Last but not least, get the default directories.
 
105
        m_settings.beginGroup("/Default");
 
106
        sSessionDir    = m_settings.value("/SessionDir").toString();
 
107
        sInstrumentDir = m_settings.value("/InstrumentDir").toString();
 
108
        sEngineName    = m_settings.value("/EngineName").toString();
 
109
        sAudioDriver   = m_settings.value("/AudioDriver").toString();
 
110
        sMidiDriver    = m_settings.value("/MidiDriver").toString();
 
111
        iMidiMap       = m_settings.value("/MidiMap",  0).toInt();
 
112
        iMidiBank      = m_settings.value("/MidiBank", 0).toInt();
 
113
        iMidiProg      = m_settings.value("/MidiProg", 0).toInt();
 
114
        iVolume        = m_settings.value("/Volume", 100).toInt();
 
115
        iLoadMode      = m_settings.value("/Loadmode", 0).toInt();
 
116
        m_settings.endGroup();
105
117
}
106
118
 
107
119
 
108
120
// Default Destructor.
109
 
qsamplerOptions::~qsamplerOptions (void)
 
121
Options::~Options (void)
110
122
{
111
 
    // Make program version available in the future.
112
 
    m_settings.beginGroup("/Program");
113
 
    m_settings.writeEntry("/Version", QSAMPLER_VERSION);
114
 
    m_settings.endGroup();
115
 
 
116
 
    // And go into general options group.
117
 
    m_settings.beginGroup("/Options");
118
 
 
119
 
    // Save server options.
120
 
    m_settings.beginGroup("/Server");
121
 
    m_settings.writeEntry("/ServerHost", sServerHost);
122
 
    m_settings.writeEntry("/ServerPort", iServerPort);
123
 
    m_settings.writeEntry("/ServerTimeout", iServerTimeout);
124
 
    m_settings.writeEntry("/ServerStart", bServerStart);
125
 
    m_settings.writeEntry("/ServerCmdLine", sServerCmdLine);
126
 
    m_settings.writeEntry("/StartDelay", iStartDelay);
127
 
    m_settings.endGroup();
128
 
 
129
 
    // Save display options.
130
 
    m_settings.beginGroup("/Display");
131
 
    m_settings.writeEntry("/DisplayFont", sDisplayFont);
132
 
    m_settings.writeEntry("/DisplayEffect", bDisplayEffect);
133
 
    m_settings.writeEntry("/AutoRefresh", bAutoRefresh);
134
 
    m_settings.writeEntry("/AutoRefreshTime", iAutoRefreshTime);
135
 
    m_settings.writeEntry("/MaxVolume", iMaxVolume);
136
 
    m_settings.writeEntry("/MessagesFont", sMessagesFont);
137
 
    m_settings.writeEntry("/MessagesLimit", bMessagesLimit);
138
 
    m_settings.writeEntry("/MessagesLimitLines", iMessagesLimitLines);
139
 
    m_settings.writeEntry("/ConfirmRemove", bConfirmRemove);
140
 
    m_settings.writeEntry("/KeepOnTop", bKeepOnTop);
141
 
    m_settings.writeEntry("/StdoutCapture", bStdoutCapture);
142
 
    m_settings.writeEntry("/CompletePath", bCompletePath);
143
 
    m_settings.writeEntry("/MaxRecentFiles", iMaxRecentFiles);
144
 
    m_settings.writeEntry("/InstrumentNames", bInstrumentNames);
145
 
    m_settings.endGroup();
146
 
 
147
 
    // View options group.
148
 
    m_settings.beginGroup("/View");
149
 
    m_settings.writeEntry("/Menubar", bMenubar);
150
 
    m_settings.writeEntry("/Toolbar", bToolbar);
151
 
    m_settings.writeEntry("/Statusbar", bStatusbar);
152
 
    m_settings.writeEntry("/AutoArrange", bAutoArrange);
153
 
    m_settings.endGroup();
154
 
 
155
 
    m_settings.endGroup(); // Options group.
156
 
 
157
 
    // Recent file list.
158
 
    m_settings.beginGroup("/RecentFiles");
159
 
    for (int i = 0; i < (int) recentFiles.count(); i++)
160
 
        m_settings.writeEntry("/File" + QString::number(i + 1), recentFiles[i]);
161
 
    m_settings.endGroup();
162
 
 
163
 
    // Default directories.
164
 
    m_settings.beginGroup("/Default");
165
 
    m_settings.writeEntry("/SessionDir", sSessionDir);
166
 
    m_settings.writeEntry("/InstrumentDir", sInstrumentDir);
167
 
    m_settings.writeEntry("/EngineName", sEngineName);
168
 
    m_settings.writeEntry("/AudioDriver", sAudioDriver);
169
 
    m_settings.writeEntry("/MidiDriver", sMidiDriver);
170
 
    m_settings.endGroup();
171
 
 
172
 
    m_settings.endGroup();
 
123
        // Make program version available in the future.
 
124
        m_settings.beginGroup("/Program");
 
125
        m_settings.setValue("/Version", QSAMPLER_VERSION);
 
126
        m_settings.endGroup();
 
127
 
 
128
        // And go into general options group.
 
129
        m_settings.beginGroup("/Options");
 
130
 
 
131
        // Save server options.
 
132
        m_settings.beginGroup("/Server");
 
133
        m_settings.setValue("/ServerHost", sServerHost);
 
134
        m_settings.setValue("/ServerPort", iServerPort);
 
135
        m_settings.setValue("/ServerTimeout", iServerTimeout);
 
136
        m_settings.setValue("/ServerStart", bServerStart);
 
137
        m_settings.setValue("/ServerCmdLine", sServerCmdLine);
 
138
        m_settings.setValue("/StartDelay", iStartDelay);
 
139
        m_settings.endGroup();
 
140
 
 
141
        // Save display options.
 
142
        m_settings.beginGroup("/Display");
 
143
        m_settings.setValue("/DisplayFont", sDisplayFont);
 
144
        m_settings.setValue("/DisplayEffect", bDisplayEffect);
 
145
        m_settings.setValue("/AutoRefresh", bAutoRefresh);
 
146
        m_settings.setValue("/AutoRefreshTime", iAutoRefreshTime);
 
147
        m_settings.setValue("/MaxVolume", iMaxVolume);
 
148
        m_settings.setValue("/MessagesFont", sMessagesFont);
 
149
        m_settings.setValue("/MessagesLimit", bMessagesLimit);
 
150
        m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines);
 
151
        m_settings.setValue("/ConfirmRemove", bConfirmRemove);
 
152
        m_settings.setValue("/KeepOnTop", bKeepOnTop);
 
153
        m_settings.setValue("/StdoutCapture", bStdoutCapture);
 
154
        m_settings.setValue("/CompletePath", bCompletePath);
 
155
        m_settings.setValue("/MaxRecentFiles", iMaxRecentFiles);
 
156
        m_settings.setValue("/InstrumentNames", bInstrumentNames);
 
157
        m_settings.endGroup();
 
158
 
 
159
        // View options group.
 
160
        m_settings.beginGroup("/View");
 
161
        m_settings.setValue("/Menubar", bMenubar);
 
162
        m_settings.setValue("/Toolbar", bToolbar);
 
163
        m_settings.setValue("/Statusbar", bStatusbar);
 
164
        m_settings.setValue("/AutoArrange", bAutoArrange);
 
165
        m_settings.endGroup();
 
166
 
 
167
        m_settings.endGroup(); // Options group.
 
168
 
 
169
        // Recent file list.
 
170
        int iFile = 0;
 
171
        m_settings.beginGroup("/RecentFiles");
 
172
        QStringListIterator iter(recentFiles);
 
173
        while (iter.hasNext())
 
174
                m_settings.setValue("/File" + QString::number(++iFile), iter.next());
 
175
        m_settings.endGroup();
 
176
 
 
177
        // Default directories.
 
178
        m_settings.beginGroup("/Default");
 
179
        m_settings.setValue("/SessionDir", sSessionDir);
 
180
        m_settings.setValue("/InstrumentDir", sInstrumentDir);
 
181
        m_settings.setValue("/EngineName", sEngineName);
 
182
        m_settings.setValue("/AudioDriver", sAudioDriver);
 
183
        m_settings.setValue("/MidiDriver", sMidiDriver);
 
184
        m_settings.setValue("/MidiMap", iMidiMap);
 
185
        m_settings.setValue("/MidiBank", iMidiBank);
 
186
        m_settings.setValue("/MidiProg", iMidiProg);
 
187
        m_settings.setValue("/Volume", iVolume);
 
188
        m_settings.setValue("/Loadmode", iLoadMode);
 
189
        m_settings.endGroup();
173
190
}
174
191
 
175
192
//-------------------------------------------------------------------------
176
193
// Settings accessor.
177
194
//
178
195
 
179
 
QSettings& qsamplerOptions::settings (void)
 
196
QSettings& Options::settings (void)
180
197
{
181
 
    return m_settings;
 
198
        return m_settings;
182
199
}
183
200
 
184
201
 
187
204
//
188
205
 
189
206
// Help about command line options.
190
 
void qsamplerOptions::print_usage ( const char *arg0 )
 
207
void Options::print_usage ( const char *arg0 )
191
208
{
192
 
    const QString sEot = "\n\t";
193
 
    const QString sEol = "\n\n";
194
 
 
195
 
    fprintf(stderr, QObject::tr("Usage") + ": %s [" + QObject::tr("options") + "] [" +
196
 
        QObject::tr("session-file") + "]" + sEol, arg0);
197
 
    fprintf(stderr, QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE) + sEol);
198
 
    fprintf(stderr, QObject::tr("Options") + ":" + sEol);
199
 
    fprintf(stderr, "  -s, --start" + sEot +
200
 
        QObject::tr("Start linuxsampler server locally") + sEol);
201
 
    fprintf(stderr, "  -h, --hostname" + sEot +
202
 
        QObject::tr("Specify linuxsampler server hostname") + sEol);
203
 
    fprintf(stderr, "  -p, --port" + sEot +
204
 
        QObject::tr("Specify linuxsampler server port number") + sEol);
205
 
    fprintf(stderr, "  -?, --help" + sEot +
206
 
        QObject::tr("Show help about command line options") + sEol);
207
 
    fprintf(stderr, "  -v, --version" + sEot +
208
 
        QObject::tr("Show version information") + sEol);
 
209
        QTextStream out(stderr);
 
210
        out << QObject::tr("Usage: %1 [options] [session-file]\n\n"
 
211
                QSAMPLER_TITLE " - " QSAMPLER_SUBTITLE "\n\n"
 
212
                "Options:\n\n"
 
213
                "  -s, --start\n\tStart linuxsampler server locally\n\n"
 
214
                "  -h, --hostname\n\tSpecify linuxsampler server hostname\n\n"
 
215
                "  -p, --port\n\tSpecify linuxsampler server port number\n\n"
 
216
                "  -?, --help\n\tShow help about command line options\n\n"
 
217
                "  -v, --version\n\tShow version information\n\n")
 
218
                .arg(arg0);
209
219
}
210
220
 
211
221
 
212
222
// Parse command line arguments into m_settings.
213
 
bool qsamplerOptions::parse_args ( int argc, char **argv )
 
223
bool Options::parse_args ( int argc, char **argv )
214
224
{
215
 
    const QString sEol = "\n\n";
216
 
    int iCmdArgs = 0;
217
 
 
218
 
    for (int i = 1; i < argc; i++) {
219
 
 
220
 
        if (iCmdArgs > 0) {
221
 
            sSessionFile += " ";
222
 
            sSessionFile += argv[i];
223
 
            iCmdArgs++;
224
 
            continue;
225
 
        }
226
 
 
227
 
        QString sArg = argv[i];
228
 
        QString sVal = QString::null;
229
 
        int iEqual = sArg.find("=");
230
 
        if (iEqual >= 0) {
231
 
            sVal = sArg.right(sArg.length() - iEqual - 1);
232
 
            sArg = sArg.left(iEqual);
233
 
        }
234
 
        else if (i < argc)
235
 
            sVal = argv[i + 1];
236
 
 
237
 
        if (sArg == "-s" || sArg == "--start") {
238
 
            bServerStart = true;
239
 
        }
240
 
        else if (sArg == "-h" || sArg == "--hostname") {
241
 
            if (sVal.isNull()) {
242
 
                fprintf(stderr, QObject::tr("Option -h requires an argument (hostname).") + sEol);
243
 
                return false;
244
 
            }
245
 
            sServerHost = sVal;
246
 
            if (iEqual < 0)
247
 
                i++;
248
 
        }
249
 
        else if (sArg == "-p" || sArg == "--port") {
250
 
            if (sVal.isNull()) {
251
 
                fprintf(stderr, QObject::tr("Option -p requires an argument (port).") + sEol);
252
 
                return false;
253
 
            }
254
 
            iServerPort = sVal.toInt();
255
 
            if (iEqual < 0)
256
 
                i++;
257
 
        }
258
 
        else if (sArg == "-?" || sArg == "--help") {
259
 
            print_usage(argv[0]);
260
 
            return false;
261
 
        }
262
 
        else if (sArg == "-v" || sArg == "--version") {
263
 
            fprintf(stderr, "Qt: %s\n", qVersion());
 
225
        QTextStream out(stderr);
 
226
        const QString sEol = "\n\n";
 
227
        int iCmdArgs = 0;
 
228
 
 
229
        for (int i = 1; i < argc; i++) {
 
230
 
 
231
                if (iCmdArgs > 0) {
 
232
                        sSessionFile += " ";
 
233
                        sSessionFile += argv[i];
 
234
                        iCmdArgs++;
 
235
                        continue;
 
236
                }
 
237
 
 
238
                QString sArg = argv[i];
 
239
                QString sVal = QString::null;
 
240
                int iEqual = sArg.indexOf("=");
 
241
                if (iEqual >= 0) {
 
242
                        sVal = sArg.right(sArg.length() - iEqual - 1);
 
243
                        sArg = sArg.left(iEqual);
 
244
                }
 
245
                else if (i < argc)
 
246
                        sVal = argv[i + 1];
 
247
 
 
248
                if (sArg == "-s" || sArg == "--start") {
 
249
                        bServerStart = true;
 
250
                }
 
251
                else if (sArg == "-h" || sArg == "--hostname") {
 
252
                        if (sVal.isNull()) {
 
253
                                out << QObject::tr("Option -h requires an argument (hostname).") + sEol;
 
254
                                return false;
 
255
                        }
 
256
                        sServerHost = sVal;
 
257
                        if (iEqual < 0)
 
258
                                i++;
 
259
                }
 
260
                else if (sArg == "-p" || sArg == "--port") {
 
261
                        if (sVal.isNull()) {
 
262
                                out << QObject::tr("Option -p requires an argument (port).") + sEol;
 
263
                                return false;
 
264
                        }
 
265
                        iServerPort = sVal.toInt();
 
266
                        if (iEqual < 0)
 
267
                                i++;
 
268
                }
 
269
                else if (sArg == "-?" || sArg == "--help") {
 
270
                        print_usage(argv[0]);
 
271
                        return false;
 
272
                }
 
273
                else if (sArg == "-v" || sArg == "--version") {
 
274
                        out << QObject::tr("Qt: %1\n").arg(qVersion());
264
275
#ifdef CONFIG_LIBGIG
265
 
                        fprintf(stderr, "%s: %s\n", gig::libraryName().c_str(), gig::libraryVersion().c_str());
266
 
#endif            
267
 
            fprintf(stderr, "%s: %s\n", ::lscp_client_package(), ::lscp_client_version());
268
 
            fprintf(stderr, "qsampler: %s\n", QSAMPLER_VERSION);
269
 
            return false;
270
 
        }
271
 
        else {
272
 
            // If we don't have one by now,
273
 
            // this will be the startup sesion file...
274
 
            sSessionFile += sArg;
275
 
            iCmdArgs++;
276
 
        }
277
 
    }
 
276
                        out << QString("%1: %2\n")
 
277
                                .arg(gig::libraryName().c_str())
 
278
                                .arg(gig::libraryVersion().c_str());
 
279
#endif
 
280
                        out << QString("%1: %2\n")
 
281
                                .arg(::lscp_client_package())
 
282
                                .arg(::lscp_client_version());
 
283
                        out << QObject::tr(QSAMPLER_TITLE ": %1\n").arg(QSAMPLER_VERSION);
 
284
                        return false;
 
285
                }
 
286
                else {
 
287
                        // If we don't have one by now,
 
288
                        // this will be the startup sesion file...
 
289
                        sSessionFile += sArg;
 
290
                        iCmdArgs++;
 
291
                }
 
292
        }
278
293
 
279
 
    // Alright with argument parsing.
280
 
    return true;
 
294
        // Alright with argument parsing.
 
295
        return true;
281
296
}
282
297
 
283
298
 
284
299
//---------------------------------------------------------------------------
285
300
// Widget geometry persistence helper methods.
286
301
 
287
 
void qsamplerOptions::loadWidgetGeometry ( QWidget *pWidget )
 
302
void Options::loadWidgetGeometry ( QWidget *pWidget )
288
303
{
289
 
    // Try to restore old form window positioning.
290
 
    if (pWidget) {
291
 
        QPoint fpos;
292
 
        QSize  fsize;
293
 
        bool bVisible;
294
 
        m_settings.beginGroup("/Geometry/" + QString(pWidget->name()));
295
 
        fpos.setX(m_settings.readNumEntry("/x", -1));
296
 
        fpos.setY(m_settings.readNumEntry("/y", -1));
297
 
        fsize.setWidth(m_settings.readNumEntry("/width", -1));
298
 
        fsize.setHeight(m_settings.readNumEntry("/height", -1));
299
 
        bVisible = m_settings.readBoolEntry("/visible", false);
300
 
        m_settings.endGroup();
301
 
        if (fpos.x() > 0 && fpos.y() > 0)
302
 
            pWidget->move(fpos);
303
 
        if (fsize.width() > 0 && fsize.height() > 0)
304
 
            pWidget->resize(fsize);
305
 
        else
306
 
            pWidget->adjustSize();
307
 
        if (bVisible)
308
 
            pWidget->show();
309
 
        else
310
 
            pWidget->hide();
311
 
    }
 
304
        // Try to restore old form window positioning.
 
305
        if (pWidget) {
 
306
                QPoint fpos;
 
307
                QSize  fsize;
 
308
                bool bVisible;
 
309
                m_settings.beginGroup("/Geometry/" + pWidget->objectName());
 
310
                fpos.setX(m_settings.value("/x", -1).toInt());
 
311
                fpos.setY(m_settings.value("/y", -1).toInt());
 
312
                fsize.setWidth(m_settings.value("/width", -1).toInt());
 
313
                fsize.setHeight(m_settings.value("/height", -1).toInt());
 
314
                bVisible = m_settings.value("/visible", false).toBool();
 
315
                m_settings.endGroup();
 
316
                if (fpos.x() > 0 && fpos.y() > 0)
 
317
                        pWidget->move(fpos);
 
318
                if (fsize.width() > 0 && fsize.height() > 0)
 
319
                        pWidget->resize(fsize);
 
320
                else
 
321
                        pWidget->adjustSize();
 
322
                if (bVisible)
 
323
                        pWidget->show();
 
324
                else
 
325
                        pWidget->hide();
 
326
        }
312
327
}
313
328
 
314
329
 
315
 
void qsamplerOptions::saveWidgetGeometry ( QWidget *pWidget )
 
330
void Options::saveWidgetGeometry ( QWidget *pWidget )
316
331
{
317
 
    // Try to save form window position...
318
 
    // (due to X11 window managers ideossincrasies, we better
319
 
    // only save the form geometry while its up and visible)
320
 
    if (pWidget) {
321
 
        m_settings.beginGroup("/Geometry/" + QString(pWidget->name()));
322
 
        bool bVisible = pWidget->isVisible();
323
 
        if (bVisible) {
324
 
            QPoint fpos  = pWidget->pos();
325
 
            QSize  fsize = pWidget->size();
326
 
            m_settings.writeEntry("/x", fpos.x());
327
 
            m_settings.writeEntry("/y", fpos.y());
328
 
            m_settings.writeEntry("/width", fsize.width());
329
 
            m_settings.writeEntry("/height", fsize.height());
330
 
        }
331
 
        m_settings.writeEntry("/visible", bVisible);
332
 
        m_settings.endGroup();
333
 
    }
 
332
        // Try to save form window position...
 
333
        // (due to X11 window managers ideossincrasies, we better
 
334
        // only save the form geometry while its up and visible)
 
335
        if (pWidget) {
 
336
                m_settings.beginGroup("/Geometry/" + pWidget->objectName());
 
337
                bool bVisible = pWidget->isVisible();
 
338
                const QPoint& fpos  = pWidget->pos();
 
339
                const QSize&  fsize = pWidget->size();
 
340
                m_settings.setValue("/x", fpos.x());
 
341
                m_settings.setValue("/y", fpos.y());
 
342
                m_settings.setValue("/width", fsize.width());
 
343
                m_settings.setValue("/height", fsize.height());
 
344
                m_settings.setValue("/visible", bVisible);
 
345
                m_settings.endGroup();
 
346
        }
334
347
}
335
348
 
336
349
 
337
350
//---------------------------------------------------------------------------
338
351
// Combo box history persistence helper implementation.
339
352
 
340
 
void qsamplerOptions::add2ComboBoxHistory ( QComboBox *pComboBox, const QString& sNewText, int iLimit, int iIndex )
341
 
{
342
 
    int iCount = pComboBox->count();
343
 
    for (int i = 0; i < iCount; i++) {
344
 
        QString sText = pComboBox->text(i);
345
 
        if (sText == sNewText) {
346
 
            pComboBox->removeItem(i);
347
 
            iCount--;
348
 
            break;
349
 
        }
350
 
    }
351
 
    while (iCount >= iLimit)
352
 
        pComboBox->removeItem(--iCount);
353
 
    pComboBox->insertItem(sNewText, iIndex);
354
 
}
355
 
 
356
 
 
357
 
void qsamplerOptions::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )
358
 
{
359
 
    pComboBox->setUpdatesEnabled(false);
360
 
    pComboBox->setDuplicatesEnabled(false);
361
 
 
362
 
    m_settings.beginGroup("/History/" + QString(pComboBox->name()));
363
 
    for (int i = 0; i < iLimit; i++) {
364
 
        QString sText = m_settings.readEntry("/Item" + QString::number(i + 1), QString::null);
365
 
        if (sText.isEmpty())
366
 
            break;
367
 
        add2ComboBoxHistory(pComboBox, sText, iLimit);
368
 
    }
369
 
    m_settings.endGroup();
370
 
 
371
 
    pComboBox->setUpdatesEnabled(true);
372
 
}
373
 
 
374
 
 
375
 
void qsamplerOptions::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )
376
 
{
377
 
    add2ComboBoxHistory(pComboBox, pComboBox->currentText(), iLimit, 0);
378
 
 
379
 
    m_settings.beginGroup("/History/" + QString(pComboBox->name()));
380
 
    for (int i = 0; i < iLimit && i < pComboBox->count(); i++) {
381
 
        QString sText = pComboBox->text(i);
382
 
        if (sText.isEmpty())
383
 
            break;
384
 
        m_settings.writeEntry("/Item" + QString::number(i + 1), sText);
385
 
    }
386
 
    m_settings.endGroup();
387
 
}
 
353
void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )
 
354
{
 
355
        // Load combobox list from configuration settings file...
 
356
        m_settings.beginGroup("/History/" + pComboBox->objectName());
 
357
 
 
358
        if (m_settings.childKeys().count() > 0) {
 
359
                pComboBox->setUpdatesEnabled(false);
 
360
                pComboBox->setDuplicatesEnabled(false);
 
361
                pComboBox->clear();
 
362
                for (int i = 0; i < iLimit; i++) {
 
363
                        const QString& sText = m_settings.value(
 
364
                                "/Item" + QString::number(i + 1)).toString();
 
365
                        if (sText.isEmpty())
 
366
                                break;
 
367
                        pComboBox->addItem(sText);
 
368
                }
 
369
                pComboBox->setUpdatesEnabled(true);
 
370
        }
 
371
 
 
372
        m_settings.endGroup();
 
373
}
 
374
 
 
375
 
 
376
void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )
 
377
{
 
378
        // Add current text as latest item...
 
379
        const QString& sCurrentText = pComboBox->currentText();
 
380
        int iCount = pComboBox->count();
 
381
        for (int i = 0; i < iCount; i++) {
 
382
                const QString& sText = pComboBox->itemText(i);
 
383
                if (sText == sCurrentText) {
 
384
                        pComboBox->removeItem(i);
 
385
                        iCount--;
 
386
                        break;
 
387
                }
 
388
        }
 
389
        while (iCount >= iLimit)
 
390
                pComboBox->removeItem(--iCount);
 
391
        pComboBox->insertItem(0, sCurrentText);
 
392
        iCount++;
 
393
 
 
394
        // Save combobox list to configuration settings file...
 
395
        m_settings.beginGroup("/History/" + pComboBox->objectName());
 
396
        for (int i = 0; i < iCount; i++) {
 
397
                const QString& sText = pComboBox->itemText(i);
 
398
                if (sText.isEmpty())
 
399
                        break;
 
400
                m_settings.setValue("/Item" + QString::number(i + 1), sText);
 
401
        }
 
402
        m_settings.endGroup();
 
403
}
 
404
 
 
405
} // namespace QSampler
388
406
 
389
407
 
390
408
// end of qsamplerOptions.cpp