00001 #ifndef MYTHCONTEXT_H_
00002 #define MYTHCONTEXT_H_
00003
00004 #include <qstring.h>
00005 #include <qdatetime.h>
00006 #include <qpixmap.h>
00007 #include <qpalette.h>
00008 #include <qobject.h>
00009 #include <qptrlist.h>
00010 #include <qevent.h>
00011 #include <qmutex.h>
00012 #include <qstringlist.h>
00013 #include <qnetwork.h>
00014 #include <qmap.h>
00015
00016 #include <cerrno>
00017 #include <iostream>
00018 #include <sstream>
00019 #include <vector>
00020
00021 #include "mythexp.h"
00022 #include "mythobservable.h"
00023 #include "mythsocket.h"
00024 #include "mythverbose.h"
00025
00026 using namespace std;
00027
00028 #if (QT_VERSION < 0x030300)
00029 #error You need Qt version >= 3.3.0 to compile MythTV.
00030 #endif
00031
00032 class Settings;
00033 class QSqlDatabase;
00034 class QSqlQuery;
00035 class QSqlError;
00036 class MythMainWindow;
00037 class MythPluginManager;
00038 class MediaMonitor;
00039 class MythMediaDevice;
00040 class DisplayRes;
00041 class MDBManager;
00042 class MythContextPrivate;
00043 class UPnp;
00044
00045
00046
00047
00048 MPUBLIC int parse_verbose_arg(QString arg);
00049
00050
00052 enum LogPriorities
00053 {
00054 LP_EMERG = 0,
00055 LP_ALERT = 1,
00056 LP_CRITICAL = 2,
00057 LP_ERROR = 3,
00058 LP_WARNING = 4,
00059 LP_NOTICE = 5,
00060 LP_INFO = 6,
00061 LP_DEBUG = 7
00062 };
00063
00065 struct MPUBLIC DatabaseParams
00066 {
00067 QString dbHostName;
00068 bool dbHostPing;
00069 int dbPort;
00070 QString dbUserName;
00071 QString dbPassword;
00072 QString dbName;
00073 QString dbType;
00074
00075 bool localEnabled;
00076 QString localHostName;
00077
00078 bool wolEnabled;
00079 int wolReconnect;
00080 int wolRetry;
00081 QString wolCommand;
00082 };
00083
00084
00095 class MPUBLIC MythPrivRequest
00096 {
00097 public:
00098 typedef enum { MythRealtime, MythExit, PrivEnd } Type;
00099 MythPrivRequest(Type t, void *data) : m_type(t), m_data(data) {}
00100 Type getType() const { return m_type; }
00101 void *getData() const { return m_data; }
00102 private:
00103 Type m_type;
00104 void *m_data;
00105 };
00106
00109 #define MYTH_BINARY_VERSION "0.21.20080304-1"
00110
00128 #define MYTH_PROTO_VERSION "40"
00129
00140 class MPUBLIC MythContext : public QObject, public MythObservable,
00141 public MythSocketCBs
00142 {
00143 Q_OBJECT
00144 public:
00145 MythContext(const QString &binversion);
00146 virtual ~MythContext();
00147
00148 bool Init(const bool gui = true,
00149 UPnp *UPnPclient = NULL,
00150 const bool promptForBackend = false,
00151 const bool bypassAutoDiscovery = false);
00152
00153 QString GetMasterHostPrefix(void);
00154
00155 QString GetHostName(void);
00156
00157 void ClearSettingsCache(QString myKey = "", QString newVal = "");
00158 void ActivateSettingsCache(bool activate = true);
00159 void OverrideSettingForSession(const QString &key, const QString &newValue);
00160
00161 bool ConnectToMasterServer(bool blockingClient = true);
00162 MythSocket *ConnectServer(MythSocket *eventSocket,
00163 const QString &hostname,
00164 int port,
00165 bool blockingClient = false);
00166 bool IsConnectedToMaster(void);
00167 void SetBackend(bool backend);
00168
00169 bool IsBackend(void);
00170 bool IsFrontendOnly(void);
00171
00172 bool IsMasterHost(void);
00173 bool IsMasterBackend(void);
00174 bool BackendIsRunning(void);
00175
00176 void BlockShutdown(void);
00177 void AllowShutdown(void);
00178
00179 QString GetInstallPrefix(void);
00180 QString GetShareDir(void);
00181 QString GetLibraryDir(void);
00182 static QString GetConfDir(void);
00183
00184 QString GetFilePrefix(void);
00185
00186 void LoadQtConfig(void);
00187 void UpdateImageCache(void);
00188
00189 void RefreshBackendConfig(void);
00190
00191
00192
00193 void GetScreenSettings(float &wmult, float &hmult);
00194 void GetScreenSettings(int &width, float &wmult,
00195 int &height, float &hmult);
00196 void GetScreenSettings(int &xbase, int &width, float &wmult,
00197 int &ybase, int &height, float &hmult);
00198
00199
00200 void GetScreenBounds(int &xbase, int &ybase, int &width, int &height);
00201
00202
00203 bool ParseGeometryOverride(const QString geometry);
00204
00205 QString FindThemeDir(const QString &themename);
00206 QString FindMenuThemeDir(const QString &menuname);
00207 QString GetThemeDir(void);
00208 QValueList<QString> GetThemeSearchPath(void);
00209
00210 QString GetMenuThemeDir(void);
00211
00212 QString GetThemesParentDir(void);
00213
00214 QString GetPluginsDir(void);
00215 QString GetPluginsNameFilter(void);
00216 QString FindPlugin(const QString &plugname);
00217
00218 QString GetTranslationsDir(void);
00219 QString GetTranslationsNameFilter(void);
00220 QString FindTranslation(const QString &translation);
00221
00222 QString GetFontsDir(void);
00223 QString GetFontsNameFilter(void);
00224 QString FindFont(const QString &fontname);
00225
00226 QString GetFiltersDir(void);
00227
00228 MDBManager *GetDBManager(void);
00229 static void DBError(const QString &where, const QSqlQuery &query);
00230 static QString DBErrorMessage(const QSqlError& err);
00231
00232 DatabaseParams GetDatabaseParams(void);
00233 bool SaveDatabaseParams(const DatabaseParams ¶ms);
00234
00235 void LogEntry(const QString &module, int priority,
00236 const QString &message, const QString &details);
00237
00238 Settings *qtconfig(void);
00239
00240 void SaveSetting(const QString &key, int newValue);
00241 void SaveSetting(const QString &key, const QString &newValue);
00242 QString GetSetting(const QString &key, const QString &defaultval = "");
00243 bool SaveSettingOnHost(const QString &key, const QString &newValue,
00244 const QString &host);
00245
00246
00247 int GetNumSetting(const QString &key, int defaultval = 0);
00248 double GetFloatSetting(const QString &key, double defaultval = 0.0);
00249 void GetResolutionSetting(const QString &type, int &width, int &height,
00250 double& forced_aspect, short &refreshrate,
00251 int index=-1);
00252 void GetResolutionSetting(const QString &type, int &width, int &height,
00253 int index=-1);
00254
00255 QString GetSettingOnHost(const QString &key, const QString &host,
00256 const QString &defaultval = "");
00257 int GetNumSettingOnHost(const QString &key, const QString &host,
00258 int defaultval = 0);
00259 double GetFloatSettingOnHost(const QString &key, const QString &host,
00260 double defaultval = 0.0);
00261
00262 void SetSetting(const QString &key, const QString &newValue);
00263
00264 QFont GetBigFont();
00265 QFont GetMediumFont();
00266 QFont GetSmallFont();
00267
00268 QString GetLanguage(void);
00269 QString GetLanguageAndVariant(void);
00270
00271 void ThemeWidget(QWidget *widget);
00272
00273 bool FindThemeFile(QString &filename);
00274 QPixmap *LoadScalePixmap(QString filename, bool fromcache = true);
00275 QImage *LoadScaleImage(QString filename, bool fromcache = true);
00276
00277 bool SendReceiveStringList(QStringList &strlist, bool quickTimeout = false,
00278 bool block = true);
00279
00280 QImage *CacheRemotePixmap(const QString &url, bool reCache = false);
00281
00282 void SetMainWindow(MythMainWindow *mainwin);
00283 MythMainWindow *GetMainWindow(void);
00284
00285 int PromptForSchemaUpgrade(const QString &dbver, const QString ¤t,
00286 const QString &backupResult);
00287 bool TestPopupVersion(const QString &name, const QString &libversion,
00288 const QString &pluginversion);
00289
00290 void SetDisableLibraryPopup(bool check);
00291
00292 void SetPluginManager(MythPluginManager *pmanager);
00293 MythPluginManager *getPluginManager(void);
00294
00295 bool CheckProtoVersion(MythSocket* socket);
00296
00297
00298 void DisableScreensaver(void);
00299 void RestoreScreensaver(void);
00300
00301
00302 void ResetScreensaver(void);
00303
00304
00305 void DoDisableScreensaver(void);
00306 void DoRestoreScreensaver(void);
00307 void DoResetScreensaver(void);
00308
00309
00310 bool GetScreensaverEnabled(void);
00311 bool GetScreenIsAsleep(void);
00312
00313 void addPrivRequest(MythPrivRequest::Type t, void *data);
00314 void waitPrivRequest() const;
00315 MythPrivRequest popPrivRequest();
00316
00317 void addCurrentLocation(QString location);
00318 QString removeCurrentLocation(void);
00319 QString getCurrentLocation(void);
00320
00321 void dispatch(MythEvent &event);
00322 void dispatchNow(MythEvent &event);
00323
00324 void sendPlaybackStart(void);
00325 void sendPlaybackEnd(void);
00326
00327 static void SetX11Display(const QString &display);
00328 static QString GetX11Display(void);
00329
00330 static QMutex verbose_mutex;
00331 static QString x11_display;
00332
00333 private:
00334 void SetPalette(QWidget *widget);
00335 void InitializeScreenSettings(void);
00336
00337 void ClearOldImageCache(void);
00338 void CacheThemeImages(void);
00339 void CacheThemeImagesDirectory(const QString &dirname,
00340 const QString &subdirname = "");
00341 void RemoveCacheDir(const QString &dirname);
00342
00343 void connected(MythSocket *sock);
00344 void connectionClosed(MythSocket *sock);
00345 void readyRead(MythSocket *sock);
00346 void connectionFailed(MythSocket *sock) { (void)sock; }
00347
00348 MythContextPrivate *d;
00349 QString app_binary_version;
00350
00351 QMutex locationLock;
00352 QValueList <QString> currentLocation;
00353 };
00354
00356 extern MPUBLIC MythContext *gContext;
00357
00359 extern MPUBLIC QMutex avcodeclock;
00360
00362 enum MythSchemaUpgrade
00363 {
00364 MYTH_SCHEMA_EXIT = 1,
00365 MYTH_SCHEMA_ERROR = 2,
00366 MYTH_SCHEMA_UPGRADE = 3,
00367 MYTH_SCHEMA_USE_EXISTING = 4
00368 };
00369
00371 extern MPUBLIC const QString gBackendURI;
00372
00373 #endif
00374
00375