From: Guido S. <gs...@us...> - 2009-09-22 20:12:29
|
Update of /cvsroot/alsamodular/qarecord/src In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv1670/src Modified Files: main.cpp mainwindow.cpp settings.cpp settings.h settingsdialog.cpp Log Message: QSettings usage removed, compiler warnings complaining uninitialized variables fixed, key strings for configuration file changed to "static const char" Index: mainwindow.cpp =================================================================== RCS file: /cvsroot/alsamodular/qarecord/src/mainwindow.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** mainwindow.cpp 5 Sep 2009 11:16:02 -0000 1.12 --- mainwindow.cpp 22 Sep 2009 20:12:20 -0000 1.13 *************** *** 360,364 **** { QString qs1, qs2, qs3; ! unsigned long current, peak, size; QTime seconds; --- 360,366 ---- { QString qs1, qs2, qs3; ! unsigned long size; ! unsigned long current = 0; ! unsigned long peak = 0; QTime seconds; Index: main.cpp =================================================================== RCS file: /cvsroot/alsamodular/qarecord/src/main.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** main.cpp 6 Sep 2009 12:54:13 -0000 1.15 --- main.cpp 22 Sep 2009 20:12:20 -0000 1.16 *************** *** 29,36 **** // Parse settings SettingsData settings; ! QCoreApplication::setOrganizationName(PACKAGE); // Which organization are we anyway? ! QCoreApplication::setApplicationName(PACKAGE); ! QSettings qs; ! settings.loadFromQSettings(qs); if (!settings.parseCmdLine(argc, argv)) { exit(EXIT_SUCCESS); --- 29,33 ---- // Parse settings SettingsData settings; ! settings.load(); if (!settings.parseCmdLine(argc, argv)) { exit(EXIT_SUCCESS); Index: settings.h =================================================================== RCS file: /cvsroot/alsamodular/qarecord/src/settings.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** settings.h 6 Sep 2009 12:54:13 -0000 1.5 --- settings.h 22 Sep 2009 20:12:20 -0000 1.6 *************** *** 5,9 **** #include <QString> #include <QTextStream> - #include <QSettings> class SettingsData : public QObject --- 5,8 ---- *************** *** 40,45 **** int parseCmdLine(int argc, char *argv[]); ! void loadFromQSettings(QSettings& qs); ! void saveToQSettings(QSettings& qs); void validateSettings(); --- 39,44 ---- int parseCmdLine(int argc, char *argv[]); ! void load(); ! void save(); void validateSettings(); Index: settingsdialog.cpp =================================================================== RCS file: /cvsroot/alsamodular/qarecord/src/settingsdialog.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** settingsdialog.cpp 6 Sep 2009 12:54:13 -0000 1.3 --- settingsdialog.cpp 22 Sep 2009 20:12:20 -0000 1.4 *************** *** 7,12 **** ui.setupUi(this); ! connect(ui.driverComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateEnabled())); ! connect(ui.midiTriggerEnabledCheckBox, SIGNAL(stateChanged(int)), this, SLOT(updateEnabled())); connect(ui.resetButton, SIGNAL(clicked()), this, SLOT(loadFromFile())); --- 7,14 ---- ui.setupUi(this); ! connect(ui.driverComboBox, SIGNAL(currentIndexChanged(int)), ! this, SLOT(updateEnabled())); ! connect(ui.midiTriggerEnabledCheckBox, SIGNAL(stateChanged(int)), ! this, SLOT(updateEnabled())); connect(ui.resetButton, SIGNAL(clicked()), this, SLOT(loadFromFile())); *************** *** 53,58 **** { SettingsData def; ! QSettings qs; ! def.loadFromQSettings(qs); def.validateSettings(); loadFromSettings(def); --- 55,59 ---- { SettingsData def; ! def.load(); def.validateSettings(); loadFromSettings(def); *************** *** 84,90 **** { SettingsData s; - QSettings qs; saveToSettings(s); ! s.saveToQSettings(qs); ! QMessageBox::information(this, APP_NAME, tr("Settings saved to %1").arg(qs.fileName())); } --- 85,89 ---- { SettingsData s; saveToSettings(s); ! s.save(); } Index: settings.cpp =================================================================== RCS file: /cvsroot/alsamodular/qarecord/src/settings.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** settings.cpp 6 Sep 2009 12:54:13 -0000 1.13 --- settings.cpp 22 Sep 2009 20:12:20 -0000 1.14 *************** *** 1,2 **** --- 1,5 ---- + #include <QDateTime> + #include <QDir> + #include <QFile> #include <QTextStream> #include <getopt.h> *************** *** 6,24 **** // Option names - do not translate ! #define ENABLE32BIT_O "32bit" ! #define RINGBUFSIZE_O "buffersize" ! #define CHANNELS_O "channels" ! #define ENABLEJACK_O "jack" ! #define METERRANGE_O "meterrange" ! #define SPLITMB_O "split" ! #define ALSAPCMNAME_O "device" ! #define ALSAPERIODS_O "fragments" ! #define ALSAPERIODSIZE_O "periodsize" ! #define RATE_O "rate" ! #define DISABLEMIDITRIGGER_O "noMidiTrigger" ! #define MIDICHANNEL_O "midiChannel" ! #define MIDINOTE_O "midiNote" static struct option options[] = --- 9,30 ---- // Option names - do not translate ! static const char ENABLE32BIT_O[] = "32bit"; ! static const char RINGBUFSIZE_O[] = "buffersize"; ! static const char CHANNELS_O[] = "channels"; ! static const char ENABLEJACK_O[] = "jack"; ! static const char METERRANGE_O[] = "meterrange"; ! static const char SPLITMB_O[] = "split"; ! static const char ALSAPCMNAME_O[] = "device"; ! static const char ALSAPERIODS_O[] = "fragments"; ! static const char ALSAPERIODSIZE_O[] = "periodsize"; ! static const char RATE_O[] = "rate"; ! static const char DISABLEMIDITRIGGER_O[] = "nomiditrigger"; ! static const char MIDICHANNEL_O[] = "midichannel"; ! static const char MIDINOTE_O[] = "midinote"; ! ! static const char KS[] = "="; ! static const char QARECORDRC[] = ".qarecordrc"; static struct option options[] = *************** *** 208,247 **** ! void SettingsData::loadFromQSettings(QSettings& qs) { ! enable32bit = qs.value(ENABLE32BIT_O, enable32bit).toBool(); ! ringBufSize = qs.value(RINGBUFSIZE_O, (int) ringBufSize).toInt(); ! channels = qs.value(CHANNELS_O, channels).toInt(); ! enableJack = qs.value(ENABLEJACK_O, enableJack).toBool(); ! meterRange = qs.value(METERRANGE_O, meterRange).toInt(); ! splitMB = qs.value(SPLITMB_O, splitMB).toInt(); ! alsaPcmName = qs.value(ALSAPCMNAME_O, alsaPcmName).toString(); ! alsaPeriods = qs.value(ALSAPERIODS_O, alsaPeriods).toInt(); ! alsaPeriodsize = qs.value(ALSAPERIODSIZE_O, alsaPeriodsize).toInt(); ! rate = qs.value(RATE_O, rate).toInt(); ! disableMidiTrigger = qs.value(DISABLEMIDITRIGGER_O, disableMidiTrigger).toBool(); ! midiChannel = qs.value(MIDICHANNEL_O, midiChannel).toInt(); ! midiNote = qs.value(MIDINOTE_O, midiNote).toInt(); } ! void SettingsData::saveToQSettings(QSettings& qs) { ! qs.setValue(ENABLE32BIT_O, enable32bit); ! qs.setValue(RINGBUFSIZE_O, (int) ringBufSize); ! qs.setValue(CHANNELS_O, channels); ! qs.setValue(ENABLEJACK_O, enableJack); ! qs.setValue(METERRANGE_O, meterRange); ! qs.setValue(SPLITMB_O, splitMB); ! qs.setValue(ALSAPCMNAME_O, alsaPcmName); ! qs.setValue(ALSAPERIODS_O, alsaPeriods); ! qs.setValue(ALSAPERIODSIZE_O, alsaPeriodsize); ! qs.setValue(RATE_O, rate); ! qs.setValue(DISABLEMIDITRIGGER_O, disableMidiTrigger); ! qs.setValue(MIDICHANNEL_O, midiChannel); ! qs.setValue(MIDINOTE_O, midiNote); } --- 214,310 ---- ! void SettingsData::load() { ! QFile file(QDir::homePath() + "/" + QARECORDRC); ! /* if no configuration file is found, just keep defaults */ ! if (!file.open(QIODevice::ReadOnly)) ! return; ! QTextStream ts(&file); ! QString s, key, value; ! ! while (!ts.atEnd()) { ! s = ts.readLine(); ! if (!s.startsWith("#")) { ! key = s.section(KS, 0, 0); ! value = s.section(KS, 1).trimmed(); + if (key.compare(ENABLE32BIT_O) == 0) { + enable32bit = value.toInt(); + } + else if (key.compare(RINGBUFSIZE_O) == 0) { + ringBufSize = value.toInt(); + } + else if (key.compare(CHANNELS_O) == 0) { + channels = value.toInt(); + } + else if (key.compare(ENABLEJACK_O) == 0) { + enableJack = value.toInt(); + } + else if (key.compare(METERRANGE_O) == 0) { + meterRange = value.toInt(); + } + else if (key.compare(SPLITMB_O) == 0) { + splitMB = value.toInt(); + } + else if (key.compare(ALSAPCMNAME_O) == 0) { + alsaPcmName = value; + } + else if (key.compare(ALSAPERIODS_O) == 0) { + alsaPeriods = value.toInt(); + } + else if (key.compare(ALSAPERIODSIZE_O) == 0) { + alsaPeriodsize = value.toInt(); + } + else if (key.compare(RATE_O) == 0) { + rate = value.toInt(); + } + else if (key.compare(DISABLEMIDITRIGGER_O) == 0) { + disableMidiTrigger = value.toInt(); + } + else if (key.compare(MIDICHANNEL_O) == 0) { + midiChannel = value.toInt(); + } + else if (key.compare(MIDINOTE_O) == 0) { + midiNote = value.toInt(); + } + } + } + file.close(); } ! void SettingsData::save() { ! QFile file(QDir::homePath() + '/' + QARECORDRC); ! ! if (!file.open(QIODevice::WriteOnly)) { ! qWarning("Error: Could not save configuration" ! " file: ~/%s", QARECORDRC); ! return; ! } ! QDateTime dt = QDateTime::currentDateTime(); ! QTextStream ts(&file); ! ts << "# " PACKAGE " configuration file" << endl ! << "# last modified: " << dt.toString(Qt::ISODate) << endl ! << "#" << endl ! << ENABLE32BIT_O << KS << enable32bit << endl ! << RINGBUFSIZE_O << KS << ringBufSize << endl ! << CHANNELS_O << KS << channels << endl ! << ENABLEJACK_O << KS << enableJack << endl ! << METERRANGE_O << KS << meterRange << endl ! << SPLITMB_O << KS << splitMB << endl ! ! << ALSAPCMNAME_O << KS << alsaPcmName << endl ! << ALSAPERIODS_O << KS << alsaPeriods << endl ! << ALSAPERIODSIZE_O << KS << alsaPeriodsize << endl ! << RATE_O << KS << rate << endl ! ! << DISABLEMIDITRIGGER_O << KS << disableMidiTrigger << endl ! << MIDICHANNEL_O << KS << midiChannel << endl ! << MIDINOTE_O << KS << midiNote << endl; ! ! file.close(); } |