00001 #ifndef __MPDC_H
00002 #define __MPDC_H
00003
00004 #include <iostream>
00005 #include <qmessagebox.h>
00006 #include <qstring.h>
00007
00008
00009
00010 #define __VERSION "0.3 rc1"
00011 #define __AUTHORS "Copyright (c) 2004 by A.E. van Putten and A.J. Admiraal. Licensed under the GPL. Visit engineering.kabel.utwente.nl for more information."
00012
00013 #if defined(LANGUAGE_NL)
00014 #include "language.nl"
00015 #elif defined(LANGUAGE_DE)
00016 #include "language.de"
00017 #elif defined(LANGUAGE_FR)
00018 #include "language.fr"
00019 #elif defined(LANGUAGE_ES)
00020 #include "language.es"
00021 #else
00022 #include "language.en"
00023 #endif
00024
00025
00026 #ifdef _MSC_VER
00027 #define OLD_FOR_SCOPE_PATCH if(true)
00028 #else
00029 #define OLD_FOR_SCOPE_PATCH
00030 #endif
00031
00032 typedef enum { T_OK = 0, T_WARNING = 1, T_ERROR = -1 } status_t;
00033
00034 #define test(expr,txt) if(expr) \
00035 { \
00036 QMessageBox mb ( "Error", txt, QMessageBox::Warning, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton ); \
00037 mb.exec(); \
00038 return; \
00039 }
00040
00041 #define dbgConnect(sender,signal,receiver,slot) \
00042 if( !connect(sender,signal,receiver,slot ) ) std::cerr << __FILE__ << ":" << __LINE__ << " > " << "Slot not connected signal: " << #signal << " slot: " << #slot << std::endl;
00043
00044 #ifdef QT_NO_DEBUG
00045 #define debug(txt) ;
00046 #else
00047 #define debug(txt) std::cout << __FILE__ << ":" << __LINE__ << " > " << txt << std::endl;
00048 #endif
00049
00050 inline QString secToHMS(unsigned s)
00051 {
00052 int sec = s % 60;
00053 int min = (s / 60) % 60;
00054 int hour = s / 3600;
00055
00056 return( QString::number(hour) + ":" +
00057 ("0" + QString::number(min)).right(2) + ":" +
00058 ("0" + QString::number(sec)).right(2));
00059 }
00060
00061 inline bool getSongArtist(QString filename, QString &song, QString &artist)
00062 {
00063 QString name = "";
00064
00065 for (int i=filename.length()-1; (i>=0) && (filename[i] != '/') && (filename[i] != '\\'); i--)
00066 name = filename[i] + name;
00067
00068 while (((name[0] >= '0') && (name[0] <= '9')) || (name[0] == '.') || (name[0] == ' ') || (name[0] == '-'))
00069 name = name.right(name.length()-1);
00070
00071 int dot = name.find('.', name.length()-7);
00072 if (dot >= 0)
00073 name = name.left(dot);
00074
00075 int br1 = name.find('[');
00076 int br2 = name.find(']', br1);
00077 if ((br1 < br2) && (br1 >= 0))
00078 {
00079 artist = name.mid(br1+1, br2-br1-1).simplifyWhiteSpace();
00080 song = name.left(br1).simplifyWhiteSpace();
00081
00082 return true;
00083 }
00084
00085 int minus = name.find('-');
00086 if (minus >= 0)
00087 {
00088 artist = name.left(minus).simplifyWhiteSpace();
00089 song = name.right(name.length()-minus-1).simplifyWhiteSpace();
00090
00091 return true;
00092 }
00093
00094 return false;
00095 }
00096
00097 inline QString getArtist(QString filename)
00098 {
00099 QString song, artist;
00100 if( getSongArtist(filename, song, artist ) )
00101 {
00102 return artist;
00103 }
00104 return "";
00105 }
00106
00107 inline QString getTitle(QString filename)
00108 {
00109 QString song, artist;
00110 if( getSongArtist(filename, song, artist ) )
00111 {
00112 return song;
00113 }
00114 return "";
00115 }
00116
00117 #endif