1 /***************************************************************************
2 * Copyright (C) 2010 by Pascal Fleury (fleury@users.sourceforge.net) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "jogshuttleconfig.h"
31 using std::stringstream;
33 // these 2 functions will convert the action maps to and from a string representation not unlike this:
34 // button1=rewind_one_frame;button2=forward_one_frame;button15=play
36 static const QChar DELIMITER = ';';
37 static const QChar KEY_VALUE_SEP = '=';
38 static const QString BUTTON_PREFIX("button");
40 QStringList JogShuttleConfig::actionMap(const QString& actionsConfig)
42 QStringList actionMap;
43 QStringList mappings = actionsConfig.split(DELIMITER);
45 foreach (const QString& mapping, mappings) {
46 QStringList parts = mapping.split(KEY_VALUE_SEP);
47 if (parts.size() != 2) {
48 fprintf(stderr, "Invalid button configuration: %s", mapping.toAscii().constData());
51 // skip the 'button' prefix
52 int button_id = parts[0].mid(BUTTON_PREFIX.length()).toInt();
53 //fprintf(stderr, " - Handling map key='%s' (ID=%d), value='%s'\n", parts[0].data().toAscii(), button_id, parts[1].data().toAscii()); // DBG
54 while (actionMap.size() <= button_id)
55 actionMap << QString();
56 actionMap[button_id] = parts[1];
59 //for (int i = 0; i < actionMap.size(); i++) fprintf(stderr, "button #%d -> action '%s'\n", i, actionMap[i].data().toAscii()); //DBG
63 QString JogShuttleConfig::actionMap(const QStringList& actionMap)
66 for (int i=0; i < actionMap.size(); ++i) {
67 if (actionMap[i] == "")
69 mappings << QString("%1%2%3%4").arg(BUTTON_PREFIX).arg(i).arg(KEY_VALUE_SEP).arg(actionMap[i]);
72 return mappings.join(DELIMITER);