]> git.sesse.net Git - kdenlive/blob - src/jogshuttleconfig.cpp
Fix label
[kdenlive] / src / jogshuttleconfig.cpp
1 /***************************************************************************
2  *   Copyright (C) 2010 by Pascal Fleury (fleury@users.sourceforge.net)    *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20 #include "jogshuttleconfig.h"
21
22 #include <vector>
23 #include <string>
24 #include <sstream>
25 #include <cstdio>
26
27 #include <stdlib.h>
28
29 using std::string;
30 using std::vector;
31 using std::stringstream;
32
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
35
36 static const QChar DELIMITER = ';';
37 static const QChar KEY_VALUE_SEP = '=';
38 static const QString BUTTON_PREFIX("button");
39
40 QStringList JogShuttleConfig::actionMap(const QString& actionsConfig)
41 {
42   QStringList actionMap;
43   QStringList mappings = actionsConfig.split(DELIMITER);
44
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());
49       continue;
50     }
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];
57   }
58   
59   //for (int i = 0; i < actionMap.size(); ++i) fprintf(stderr, "button #%d -> action '%s'\n", i, actionMap[i].data().toAscii());  //DBG
60   return actionMap;
61 }
62
63 QString JogShuttleConfig::actionMap(const QStringList& actionMap)
64 {
65   QStringList mappings;
66   for (int i=0; i < actionMap.size(); ++i) {
67       if (actionMap[i].isEmpty())
68           continue;
69       mappings << QString::fromLatin1("%1%2%3%4").arg(BUTTON_PREFIX).arg(i).arg(KEY_VALUE_SEP).arg(actionMap[i]);
70   }
71
72   return mappings.join(DELIMITER);
73 }