Rivendellaudio/lib/rdhotkeylist.cpp
Fred Gleason 57abeada3c 2021-02-24 Fred Gleason <fredg@paravelsystems.com>
* Updated build system to use Qt5 instead of Qt4.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
2021-02-24 16:12:22 -05:00

126 lines
2.9 KiB
C++

// rdhotkeylist.cpp
//
// An Abstract of the rdhotkeylist
//
// (C) Copyright 2002-2021 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include<rdhotkeylist.h>
RDHotKeyList::RDHotKeyList( )
{
hotkeylist.resize(0);
BuildKeyList();
}
RDHotKeyList::~RDHotKeyList()
{
hotkeylist.clear();
}
void RDHotKeyList::BuildKeyList( )
{
char qtpath[256];
char keyfile[256];
char line[256];
FILE *hkeyfile;
char enumstring[11] = "enum Key {";
QString KeyString;
QString KeyHex;
QString Filestring;
keyList CurKey;
char *p = {0};
if(getenv("QTDIR")==NULL) {
return;
}
strcpy(qtpath, (const char *) getenv("QTDIR"));
strcpy(keyfile,qtpath);
strcat(keyfile,"/include/qnamespace.h");
hkeyfile = fopen(keyfile,"r");
if (hkeyfile==NULL) {
return;
}
if (fgets(line,256,hkeyfile) !=NULL) {
while ((p = strstr(line,enumstring))== NULL ) {
if (fgets(line,256,hkeyfile) == NULL) {
break;
}
}
if (p != NULL) {
while ( ( fgets(line,256,hkeyfile) != NULL) && (!(strstr(line,"}")) ) ) {
QString buf = cleanStrings(line);
int acomment = buf.indexOf("//");
int eqsign = buf.indexOf("=");
if ((eqsign != -1) && (acomment != 0) ) {
KeyString = buf.left((eqsign ));
KeyString = KeyString.mid(4); // Remove 'Key_'
int comma = buf.indexOf(",");
if (comma != -1) {
KeyHex = buf.mid((eqsign + 1),
(comma - eqsign)-1 );
}
else {
int comment = buf.indexOf("//");
if (comment != -1) {
KeyHex = buf.mid( (eqsign+1),
(comment - eqsign) );
}
else {
KeyHex = buf.mid( (eqsign+1),
(buf.length() - eqsign) );
}
}
bool ok;
int hotkey_int = KeyHex.toInt(&ok,16); //Convert to decimal
if (ok) {
CurKey.decvalue = hotkey_int;
CurKey.stringvalue = KeyString;
hotkeylist.push_back(CurKey) ;
}
}
}
}
}
fclose(hkeyfile);
}
QString RDHotKeyList::cleanStrings( const QString sent)
{
QString ret;
for(int i=0;i<sent.length();i++) {
if((sent.at(i)!=QChar('\n'))&&(sent.at(i)!=QChar('\t'))) {
ret+=sent.at(i);
}
}
return ret;
}
QString RDHotKeyList::GetKeyCode(int number)
{
for (unsigned i = 0; i < hotkeylist.size(); i++) {
if ((hotkeylist.at(i).decvalue) == number){
return hotkeylist.at(i).stringvalue;
}
}
return (QString(""));
}