MythTV  0.26-pre
netcommon.cpp
Go to the documentation of this file.
00001 #include <QDir>
00002 #include <QNetworkAccessManager>
00003 #include <QNetworkReply>
00004 #include <QEventLoop>
00005 
00006 #include <mythdirs.h>
00007 #include <mythdb.h>
00008 #include <mythcontext.h>
00009 #include <netgrabbermanager.h>
00010 
00011 #include "netcommon.h"
00012 
00013 QString GetThumbnailFilename(QString url, QString title)
00014 {
00015     QString fileprefix = GetConfDir();
00016 
00017     QDir dir(fileprefix);
00018     if (!dir.exists())
00019         dir.mkdir(fileprefix);
00020 
00021     fileprefix += "/MythNetvision";
00022 
00023     dir = QDir(fileprefix);
00024     if (!dir.exists())
00025         dir.mkdir(fileprefix);
00026 
00027     fileprefix += "/thumbcache";
00028 
00029     dir = QDir(fileprefix);
00030     if (!dir.exists())
00031         dir.mkdir(fileprefix);
00032 
00033     QString sFilename = QString("%1/%2_%3")
00034         .arg(fileprefix)
00035         .arg(qChecksum(url.toLocal8Bit().constData(),
00036                        url.toLocal8Bit().size()))
00037         .arg(qChecksum(title.toLocal8Bit().constData(),
00038                        title.toLocal8Bit().size()));
00039     return sFilename;
00040 }
00041 
00042 QString GetMythXMLURL(void)
00043 {
00044     // Get MasterServerIP
00045     //   The data for MasterServerIP setting is the same as the data for
00046     //   BackendServerIP setting
00047     QString MasterIP = gCoreContext->GetSetting("MasterServerIP");
00048 
00049     MSqlQuery query(MSqlQuery::InitCon());
00050     // Get hostname of Master Server by comparing BackendServerIP to
00051     // the just-retrieved MasterServerIP
00052     query.prepare("SELECT hostname FROM settings "
00053                   " WHERE value = 'BackendServerIP'"
00054                   "   AND data = :IPADDRESS");
00055     query.bindValue(":IPADDRESS", MasterIP);
00056     if (!query.exec() || !query.next())
00057         MythDB::DBError("Find Master Server Hostname", query);
00058 
00059     QString MasterHost = query.value(0).toString();
00060 
00061     // Use hostname to get BackendStatusPort
00062     int MasterStatusPort = gCoreContext->GetNumSettingOnHost("BackendStatusPort",
00063                                                           MasterHost);
00064 
00065     return QString("http://%1:%2/InternetContent/").arg(MasterIP).arg(MasterStatusPort);
00066 }
00067 
00068 QUrl GetMythXMLSearch(QString url, QString query, QString grabber,
00069                          uint pagenum)
00070 {
00071     QString tmp = QString("%1GetInternetSearch?Query=%2&Grabber=%3&Page=%4")
00072         .arg(url).arg(query).arg(grabber).arg(QString::number(pagenum));
00073     return QUrl(tmp);
00074 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends