00001 /*************************************************************************** 00002 lineakparser.h - description 00003 ------------------- 00004 begin : Sat May 25 2002 00005 copyright : (C) 2002 by Sheldon Lee Wen 00006 email : leewsb@hotmail.com 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef LINEAKPARSER_H 00019 #define LINEAKPARSER_H 00020 00021 #include <qstring.h> 00022 #include <qfile.h> 00023 #include <qdir.h> 00024 #include <qtextstream.h> 00025 #include <iostream.h> 00026 #include <map.h> 00027 #include <vector.h> 00028 #include <cstdlib> 00029 00030 #ifdef HAVE_CONFIG_H 00031 #include <config.h> 00032 #endif 00033 00034 extern "C" { 00035 #include "dcfp.h" 00036 #include <X11/Xlib.h> 00037 #include <X11/XKBlib.h> 00038 #include <X11/extensions/XKBfile.h> 00039 #include <sys/types.h> 00040 #include <unistd.h> 00041 } 00042 00043 #define CONF_HEADER \ 00044 "# LinEAK - Linux support for Easy Access and Internet Keyboards\n" \ 00045 "# Copyright (c) 2001,2002 Mark Smulders <Mark@PIRnet.nl>\n" \ 00046 "# http://lineak.sourceforge.net\n" \ 00047 "#\n" \ 00048 "# lineakd configuration file\n" \ 00049 "#\n" \ 00050 "# example key configuration:\n" \ 00051 "# \tplay\t= \"xmms --play-pause\"\n" \ 00052 "# \teject\t= EAK_EJECT\n" \ 00053 "#\n" \ 00054 "# available special actions:\n" \ 00055 "# \tEAK_EJECT\n" \ 00056 "# \tEAK_VOLUP\n" \ 00057 "# \tEAK_VOLDOWN\n" \ 00058 "# \tEAK_MUTE\n" \ 00059 "# \tEAK_SLEEP\n" \ 00060 "#\n" \ 00061 "\n" 00062 00063 /* special actions in .conf file */ 00064 #define NR_SPECIALS 5 00065 /* link them to strings */ 00066 #define EAK_EJECT "EAK_EJECT" 00067 #define EAK_VOLUP "EAK_VOLUP" 00068 #define EAK_VOLDOWN "EAK_VOLDOWN" 00069 #define EAK_MUTE "EAK_MUTE" 00070 #define EAK_SLEEP "EAK_SLEEP" 00071 00072 /* the conf and def filenames */ 00073 #define LINEAKDIR "/.lineak/" 00074 #define CONFFILE "/.lineak/lineakd.conf" /* (relative from $HOME dir) */ 00075 #define BAKFILE "/.lineak/.lineakd.conf.backup" 00076 #define PIDFILE "/.lineak/lineakd.pid" 00077 #define DEFFILE "lineakkb.def" 00078 00079 /* for volume settings using the mixer device */ 00080 #define MIXERDEV "/dev/mixer" 00081 #define VOLUP_VALUE 5 00082 #define VOLDOWN_VALUE -5 00083 #define VOLMUTE_VALUE 0 00084 #define MAX_VOLUME 100 00085 00086 class specialact { 00087 public: 00088 specialact(QString act="", QString lname="") : action(act), longname(lname) {} 00089 QString action; 00090 QString longname; 00091 }; 00092 00093 class EAkey { 00094 public: 00095 EAkey() { next=NULL; 00096 EAkeyname=""; 00097 EAkeycode=0; 00098 EAcommand=""; } 00099 EAkey *next; 00100 QString EAkeyname; 00101 int EAkeycode; 00102 KeySym EAkeysym; 00103 QString EAcommand; 00104 }; 00105 00106 /* the EAK we will use.. */ 00107 class EAKeyboard { 00108 public: 00109 EAKeyboard() : EAKnr(0), EAKtype(""), EAKbrand(""), 00110 EAKmodel(""), EAKeylist(NULL) { } 00111 int EAKnr; 00112 QString EAKtype; 00113 QString EAKbrand; 00114 QString EAKmodel; 00115 EAkey *EAKeylist; 00116 }; 00117 00122 class LineakParser { 00123 public: 00124 LineakParser(); 00125 ~LineakParser(); 00126 int get_lineakd_pid(void); 00127 int lineakd_running(void); 00128 void remove_pid_file(void); 00129 00130 private: 00131 /* function prototypes */ 00132 QString parseconffile(const QString &inFile=QString::null); 00133 bool parsedeffile(const QString &inFile=QString::null); 00134 bool initEAK (const QString &inKBType=QString::null); 00135 void cleanKeylist (void); 00136 void cleanConfdata(void); 00137 void cleanDefdata(void); 00138 void cleanexit(int status); 00139 QString backup_conffile (void); 00140 bool restore_conffile (void); 00141 bool save_conffile (void); 00142 00143 QString kbtype; 00144 QString cdromdev; 00145 QString mixdev; 00146 QFile conffilename; 00147 QFile deffilename; 00148 QFile backupfile; 00149 int nrkeyboards; 00150 const dcfp_data_struct *confdata; 00151 const dcfp_data_struct *defdata; 00152 const dcfp_data_struct *userdefdata; 00153 specialact specialacts[NR_SPECIALS]; 00155 EAKeyboard myEAK; 00157 map< QString, vector<QString> > bmmap; 00159 map<QString,QString> longkbname; 00161 void print(); 00162 friend class KlineakConfig; 00163 friend class KLineakDef; 00164 00165 00166 }; 00167 00168 #endif