00001 #ifndef UTIL_H_
00002 #define UTIL_H_
00003
00004 #include <qstringlist.h>
00005 #include <qdatetime.h>
00006 #include <qcolor.h>
00007
00008 #include <stdint.h>
00009 #include <time.h>
00010
00011 #include "mythexp.h"
00012
00013 #define MYTH_SYSTEM_DONT_BLOCK_LIRC 0x1 //< myth_system() flag to avoid blocking
00014 #define MYTH_SYSTEM_DONT_BLOCK_JOYSTICK_MENU 0x2 //< myth_system() flag to avoid blocking
00015 #define MYTH_SYSTEM_DONT_BLOCK_PARENT 0x4 //< myth_system() flag to avoid blocking
00016
00017 class QPixmap;
00018 class QImage;
00019 class QPainter;
00020 class QFont;
00021 class QFile;
00022
00023 class MPUBLIC MythTimer
00024 {
00025 public:
00026 MythTimer() {}
00027
00028 void start() { m_timer.start(); }
00029 int restart() { int ret = elapsed();
00030 m_timer.restart();
00031 return ret;
00032 }
00033 int elapsed() { int ret = m_timer.elapsed();
00034 if (ret > 86300000) { ret = 0; m_timer.restart(); }
00035 return ret;
00036 }
00037
00038 void addMSecs(int ms) { m_timer.addMSecs(ms); }
00039
00040 private:
00041 QTime m_timer;
00042 };
00043
00044 MPUBLIC QDateTime mythCurrentDateTime();
00045 MPUBLIC int calc_utc_offset(void);
00046
00047
00048
00049 MPUBLIC inline long long absLongLong(long long n) { return n >= 0 ? n : -n; }
00050
00051 MPUBLIC void encodeLongLong(QStringList &list, long long num);
00052 MPUBLIC long long decodeLongLong(QStringList &list, uint offset);
00053 MPUBLIC long long decodeLongLong(QStringList &list, QStringList::const_iterator &it);
00054
00055 MPUBLIC QRgb blendColors(QRgb source, QRgb add, int alpha);
00056
00057 MPUBLIC uint myth_system(const QString &command, int flags = 0);
00058
00059 MPUBLIC QString cutDownString(const QString &text, QFont *testFont, uint maxwidth);
00060
00061 MPUBLIC QDateTime MythUTCToLocal(const QDateTime &utc);
00062 MPUBLIC int MythSecsTo(const QDateTime &from, const QDateTime &to);
00063
00064 MPUBLIC long long stringToLongLong(const QString &str);
00065 MPUBLIC QString longLongToString(long long ll);
00066
00067 MPUBLIC long long getDiskSpace(const QString&,long long&,long long&);
00068 MPUBLIC bool getUptime(time_t &uptime);
00069 MPUBLIC bool getMemStats(int &totalMB, int &freeMB, int &totalVM, int &freeVM);
00070
00071 MPUBLIC void myth_eject(void);
00072
00073 MPUBLIC bool hasUtf8(const char *str);
00074 #define M_QSTRING_UNICODE(str) hasUtf8(str) ? QString::fromUtf8(str) : str
00075
00076 MPUBLIC bool ping(const QString &host, int timeout);
00077 MPUBLIC bool telnet(const QString &host, int port);
00078
00079 MPUBLIC long long copy(QFile &dst, QFile &src, uint block_size = 0);
00080 MPUBLIC QString createTempFile(QString name_template = "/tmp/mythtv_XXXXXX",
00081 bool dir = false);
00082 MPUBLIC unsigned long long myth_get_approximate_large_file_size(
00083 const QString &fname);
00084
00085 MPUBLIC double MythGetPixelAspectRatio(void);
00086
00088 MPUBLIC bool IsPulseAudioRunning(void);
00089
00090
00091 #ifdef MMX
00092 #ifdef _WIN32
00093 #include "compat.h"
00094 inline void rdtsc(uint64_t &x)
00095 {
00096 QueryPerformanceCounter((LARGE_INTEGER*)(&x));
00097 }
00098 #else
00099 typedef struct {
00100 uint a;
00101 uint b;
00102 } timing_ab_t;
00103 inline void rdtsc(uint64_t &x)
00104 {
00105 timing_ab_t &y = (timing_ab_t&) x;
00106 asm("rdtsc \n"
00107 "mov %%eax, %0 \n"
00108 "mov %%edx, %1 \n"
00109 :
00110 : "m"(y.a), "m"(y.b)
00111 : "%eax", "%edx");
00112 }
00113 #endif
00114
00115 #else // if !MMX
00116 inline void rdtsc(uint64_t &x) { x = 0ULL; }
00117 #endif // !MMX
00118
00119 #endif // UTIL_H_