void StorageGroup::StaticInit(void) { QMutexLocker locker(&m_staticInitLock); if (m_staticInitDone) return; m_staticInitDone = true; m_builtinGroups["ChannelIcons"] = GetConfDir() + "/ChannelIcons"; m_builtinGroups["Themes"] = GetConfDir() + "/themes"; m_builtinGroups["Temp"] = GetConfDir() + "/tmp"; QMap<QString, QString>::iterator it = m_builtinGroups.begin(); for (; it != m_builtinGroups.end(); ++it) { QDir qdir(it.value()); if (!qdir.exists()) qdir.mkpath(it.value()); if (!qdir.exists()) LOG(VB_GENERAL, LOG_ERR, QString("SG() Error: Could not create builtin" "Storage Group directory '%1' for '%2'").arg(it.value()) .arg(it.key())); } }
/** \fn GalleryDatabaseHelper::LoadDirectoryThumbnailValues(ImageMetadata *) * \brief Gets four images from the directory from the * database which will be used as a folder thumbnail * \param im Holds the loaded information * \return void */ void GalleryDatabaseHelper::LoadDirectoryThumbnailValues(ImageMetadata *im) { // Try to get four new thumbnail filenames // from the available images in this folder MSqlQuery query(MSqlQuery::InitCon()); query.prepare(QString("SELECT filename, path FROM gallery_files " "WHERE path LIKE '\%%1\%' " "AND type = '4' " "AND hidden = '0' LIMIT %2;") .arg(im->m_fileName) .arg(kMaxFolderThumbnails)); if (!query.exec()) LOG(VB_GENERAL, LOG_ERR, MythDB::DBErrorMessage(query.lastError())); for (int i = 0; i < query.size(); ++i) { query.next(); QString thumbFileName = QString("%1%2") .arg(GetConfDir().append("/MythImage/")) .arg(query.value(0).toString()); im->m_thumbFileNameList->replace(i, thumbFileName); im->m_thumbPath = query.value(1).toString(); } // Set the path to the thumbnail files. As a default this will be // the path ".mythtv/MythGallery" in the users home directory im->m_thumbPath.prepend(GetConfDir().append("/MythImage/")); }
/** \fn GalleryDatabaseHelper::LoadDirectoryThumbnailValues(ImageMetadata *) * \brief Gets four images from the directory from the * database which will be used as a folder thumbnail * \param im Holds the loaded information * \return void */ void GalleryDatabaseHelper::LoadDirectoryThumbnailValues(ImageMetadata *im) { // Try to get four new thumbnail filenames // from the available images in this folder MSqlQuery query(MSqlQuery::InitCon()); query.prepare("SELECT CONCAT_WS('/', path, filename), path FROM gallery_files " "WHERE path = :PATH " "AND type = '4' " "AND hidden = '0' LIMIT :LIMIT"); query.bindValue(":PATH", im->m_path); query.bindValue(":LIMIT", kMaxFolderThumbnails); if (!query.exec()) LOG(VB_GENERAL, LOG_ERR, MythDB::DBErrorMessage(query.lastError())); int i = 0; while (query.next()) { QString thumbFileName = QString("%1%2") .arg(GetConfDir().append("/MythImage/")) .arg(query.value(0).toString()); if (i >= im->m_thumbFileNameList->size()) break; im->m_thumbFileNameList->replace(i, thumbFileName); im->m_thumbPath = query.value(1).toString(); ++i; } // Set the path to the thumbnail files. As a default this will be // the path ".mythtv/MythGallery" in the users home directory im->m_thumbPath.prepend(GetConfDir().append("/MythImage/")); }
void DecoderHandler::createPlaylistFromRemoteUrl(const QUrl &url) { LOG(VB_NETWORK, LOG_INFO, QString("Retrieving playlist from '%1'").arg(url.toString())); doOperationStart(tr("Retrieving playlist")); QString extension = QFileInfo(url.path()).suffix().toLower(); QString saveFilename = GetConfDir() + "/MythMusic/playlist." + extension; GetMythDownloadManager()->queueDownload(url.toString(), saveFilename, this); //TODO should find a better way to do this QTime time; time.start(); while (m_state == LOADING) { if (time.elapsed() > 30000) { doOperationStop(); GetMythDownloadManager()->cancelDownload(url.toString()); LOG(VB_GENERAL, LOG_ERR, QString("DecoderHandler:: Timed out trying to download playlist from: %1") .arg(url.toString())); m_state = STOPPED; } qApp->processEvents(); usleep(500); } }
void ThemeChooser::removeThemeDir(const QString &dirname) { QString themeDir = GetConfDir() + "/themes/"; if ((!dirname.startsWith(themeDir)) && (!dirname.startsWith(GetMythUI()->GetThemeCacheDir()))) return; QDir dir(dirname); if (!dir.exists()) return; QFileInfoList list = dir.entryInfoList(); QFileInfoList::const_iterator it = list.begin(); const QFileInfo *fi; while (it != list.end()) { fi = &(*it++); if (fi->fileName() == "." || fi->fileName() == "..") continue; if (fi->isFile() && !fi->isSymLink()) { QFile::remove(fi->absoluteFilePath()); } else if (fi->isDir() && !fi->isSymLink()) { removeThemeDir(fi->absoluteFilePath()); } } dir.rmdir(dirname); }
XmlConfiguration::XmlConfiguration( const QString &sFileName ) { m_sPath = GetConfDir(); m_sFileName = sFileName; Load(); }
QString getDownloadFilename(QString title, QString url) { QString fileprefix = GetConfDir(); QDir dir(fileprefix); if (!dir.exists()) dir.mkdir(fileprefix); fileprefix += "/cache/metadata-thumbcache"; dir = QDir(fileprefix); if (!dir.exists()) dir.mkdir(fileprefix); QByteArray titlearr(title.toLatin1()); quint16 titleChecksum = qChecksum(titlearr.data(), titlearr.length()); QByteArray urlarr(url.toLatin1()); quint16 urlChecksum = qChecksum(urlarr.data(), urlarr.length()); QUrl qurl(url); QString ext = QFileInfo(qurl.path()).suffix(); QString basefilename = QString("thumbnail_%1_%2.%3") .arg(QString::number(urlChecksum)) .arg(QString::number(titleChecksum)).arg(ext); QString outputfile = QString("%1/%2").arg(fileprefix).arg(basefilename); return outputfile; }
// Load the font. Copied, generally, from OSD::LoadFont. bool MHIContext::LoadFont(QString name) { QString fullnameA = GetConfDir() + "/" + name; QByteArray fnameA = fullnameA.toAscii(); FT_Error errorA = FT_New_Face(ft_library, fnameA.constData(), 0, &m_face); if (!errorA) return true; QString fullnameB = GetFontsDir() + name; QByteArray fnameB = fullnameB.toAscii(); FT_Error errorB = FT_New_Face(ft_library, fnameB.constData(), 0, &m_face); if (!errorB) return true; QString fullnameC = GetShareDir() + "themes/" + name; QByteArray fnameC = fullnameC.toAscii(); FT_Error errorC = FT_New_Face(ft_library, fnameC.constData(), 0, &m_face); if (!errorC) return true; QString fullnameD = name; QByteArray fnameD = fullnameD.toAscii(); FT_Error errorD = FT_New_Face(ft_library, fnameD.constData(), 0, &m_face); if (!errorD) return true; LOG(VB_GENERAL, LOG_ERR, QString("[mhi] Unable to find font: %1").arg(name)); return false; }
ImportIconsWizard::ImportIconsWizard(MythScreenStack *parent, bool fRefresh, const QString &channelname) :MythScreenType(parent, "ChannelIconImporter"), m_strChannelname(channelname), m_fRefresh(fRefresh), m_nMaxCount(0), m_nCount(0), m_missingMaxCount(0), m_missingCount(0), m_url("http://services.mythtv.org/channel-icon/"), m_progressDialog(NULL), m_iconsList(NULL), m_manualEdit(NULL), m_nameText(NULL), m_manualButton(NULL), m_skipButton(NULL), m_statusText(NULL), m_preview(NULL), m_previewtitle(NULL) { m_strChannelname.detach(); if (!m_strChannelname.isEmpty()) LOG(VB_GENERAL, LOG_INFO, QString("Fetching icon for channel %1").arg(m_strChannelname)); else LOG(VB_GENERAL, LOG_INFO, "Fetching icons for multiple channels"); m_popupStack = GetMythMainWindow()->GetStack("popup stack"); m_tmpDir = QDir(QString("%1/tmp/icon").arg(GetConfDir())); if (!m_tmpDir.exists()) m_tmpDir.mkpath(m_tmpDir.absolutePath()); }
// static function QString ThumbGenerator::getThumbcacheDir(const QString& inDir) { QString galleryDir = gCoreContext->GetSetting("GalleryDir"); // For directory "/my/images/january", this function either returns // "/my/images/january/.thumbcache" or // "~/.mythtv/mythgallery/january/.thumbcache" QString aPath = inDir + QString("/.thumbcache/"); QDir dir(aPath); if (gCoreContext->GetNumSetting("GalleryThumbnailLocation") && !dir.exists() && inDir.startsWith(galleryDir)) { dir.mkpath(aPath); } if (!gCoreContext->GetNumSetting("GalleryThumbnailLocation") || !dir.exists() || !inDir.startsWith(galleryDir)) { // Arrive here if storing thumbs in home dir, // OR failed to create thumb dir in gallery pics location int prefixLen = galleryDir.length(); QString location = ""; if (prefixLen < inDir.length()) location = QString("%1/") .arg(inDir.right(inDir.length() - prefixLen)); aPath = QString("%1/MythGallery/%2").arg(GetConfDir()) .arg(location); dir.setPath(aPath); dir.mkpath(aPath); } return aPath; }
void fillSelections(void) { clearSelections(); QString xmltvFile = GetConfDir() + '/' + sourceName + ".xmltv"; if (QFile::exists(xmltvFile)) { QFile file(xmltvFile); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; QStringList idList; while (!file.atEnd()) { QByteArray line = file.readLine(); if (line.startsWith("channel=")) { QString id = line.mid(8, -1).trimmed(); idList.append(id); } } idList.sort(); for (int x = 0; x < idList.size(); x++) addSelection(idList.at(x), idList.at(x)); } }
void ThemeChooser::removeTheme(void) { MythUIButtonListItem *current = m_themes->GetItemCurrent(); if (!current) { ShowOkPopup(tr("Error, no theme selected.")); return; } ThemeInfo *info = qVariantValue<ThemeInfo *>(current->GetData()); if (!info) { ShowOkPopup(tr("Error, unable to find current theme.")); return; } QString themeDir = GetConfDir() + "/themes/"; if (!info->GetPreviewPath().startsWith(themeDir)) { ShowOkPopup(tr("%1 is not a user-installed theme and can not " "be deleted.").arg(info->GetName())); return; } themeDir.append(info->GetDirectoryName()); removeThemeDir(themeDir); ReloadInBackground(); }
QString HardwareProfile::GetPublicUUIDFromFile() const { QString ret; QString pubuuid_file = GetConfDir() + "/HardwareProfile/uuiddb.cfg"; QString pubuuid; QFile pubfile(pubuuid_file); if (pubfile.open( QIODevice::ReadOnly )) { QString s; QTextStream stream(&pubfile); while ( !stream.atEnd() ) { s = stream.readLine(); if (s.contains(m_uuid)) { ret = s.section("=",1,1); ret = ret.trimmed(); } } pubfile.close(); } return ret; }
bool ThemeUpdateTask::DoRun(void) { QString MythVersion = MYTH_SOURCE_PATH; // Treat devel branches as master if (MythVersion.startsWith("devel/")) MythVersion = "master"; // FIXME: For now, treat git master the same as svn trunk if (MythVersion == "master") MythVersion = "trunk"; if (MythVersion != "trunk") { MythVersion = MYTH_BINARY_VERSION; // Example: 0.25.20101017-1 MythVersion.replace(QRegExp("\\.[0-9]{8,}.*"), ""); } QString remoteThemesDir = GetConfDir(); remoteThemesDir.append("/tmp/remotethemes"); QDir dir(remoteThemesDir); if (!dir.exists() && !dir.mkpath(remoteThemesDir)) { LOG(VB_GENERAL, LOG_ERR, QString("HouseKeeper: Error creating %1" "directory for remote themes info cache.") .arg(remoteThemesDir)); return false; } QString remoteThemesFile = remoteThemesDir; remoteThemesFile.append("/themes.zip"); QString url = QString("%1/%2/themes.zip") .arg(gCoreContext->GetSetting("ThemeRepositoryURL", "http://themes.mythtv.org/themes/repository")).arg(MythVersion); bool result = GetMythDownloadManager()->download(url, remoteThemesFile); if (!result) { LOG(VB_GENERAL, LOG_ERR, QString("HouseKeeper: Error downloading %1" "remote themes info package.").arg(url)); return false; } if (!extractZIP(remoteThemesFile, remoteThemesDir)) { LOG(VB_GENERAL, LOG_ERR, QString("HouseKeeper: Error extracting %1" "remote themes info package.").arg(remoteThemesFile)); QFile::remove(remoteThemesFile); return false; } return true; }
HostLineEdit *GetScreenshotDir() { HostLineEdit *gc = new HostLineEdit("mythgame.screenshotdir"); gc->setLabel(QObject::tr("Directory where Game Screenshots are stored")); gc->setValue(GetConfDir() + "/MythGame/Screenshots"); gc->setHelpText(QObject::tr("This directory will be the default browse " "location when assigning screenshots.")); return gc; }
HostLineEdit *GetFanartDir() { HostLineEdit *gc = new HostLineEdit("mythgame.fanartdir"); gc->setLabel(QObject::tr("Directory where Game Fanart is stored")); gc->setValue(GetConfDir() + "/MythGame/Fanart"); gc->setHelpText(QObject::tr("This directory will be the default browse " "location when assigning fanart.")); return gc; }
/** \brief Creates a new MythPandora Screen * \param parent Pointer to the screen stack * \param name The name of the window */ MythPandora::MythPandora(MythScreenStack *parent, QString name) : MythScreenType(parent, name), m_coverArtFetcher(NULL), m_coverArtTempFile(NULL), m_Timer(NULL) { //example of how to find the configuration dir currently used. QString confdir = GetConfDir(); VERBOSE(VB_IMPORTANT, "MythPandora Conf dir:" + confdir); }
/** \brief Creates a new MythPianod Screen * \param parent Pointer to the screen stack * \param name The name of the window */ MythPianod::MythPianod(MythScreenStack *parent, QString name) : MythScreenType(parent, name), m_coverArtFetcher(NULL), m_coverArtTempFile(NULL), m_Timer(NULL) { //example of how to find the configuration dir currently used. QString confdir = GetConfDir(); LOG(VB_GENERAL, LOG_INFO, "MythPianod Conf dir:" + confdir); }
/** \fn GalleryDatabaseHelper::LoadFileThumbnailValues(ImageMetadata *) * \brief Sets the thumbnail information for a file * \param im Holds the loaded information * \return void */ void GalleryDatabaseHelper::LoadFileThumbnailValues(ImageMetadata *im) { // Set the path to the thumbnail files. As a default this will be // the path ".mythtv/MythGallery" in the users home directory im->m_thumbPath = im->m_path; im->m_thumbPath.prepend(GetConfDir().append("/MythImage/")); // Create the full path and filename to the thumbnail image QString thumbFileName = QString("%1%2") .arg(GetConfDir().append("/MythImage/")) .arg(im->m_fileName); // If the file is a video then append a png, otherwise the preview // image would not be readable due to the video file extension if (im->m_type == kVideoFile) thumbFileName.append(".png"); im->m_thumbFileNameList->replace(0, thumbFileName); }
QString MythUIHelper::GetThemeCacheDir(void) { QString cachedirname = GetConfDir() + "/cache/themecache/"; QString tmpcachedir = cachedirname + GetMythDB()->GetSetting("Theme", DEFAULT_UI_THEME) + "." + QString::number(d->m_screenwidth) + "." + QString::number(d->m_screenheight); return tmpcachedir; }
static HostLineEdit *GetBoxartDir() { HostLineEdit *gc = new HostLineEdit("mythgame.boxartdir"); gc->setLabel(MythGameGeneralSettings::tr("Directory where Game Boxart is " "stored")); gc->setValue(GetConfDir() + "/MythGame/Boxart"); gc->setHelpText(MythGameGeneralSettings::tr("This directory will be the " "default browse location when " "assigning boxart.")); return gc; }
static HostLineEdit *GetScreenshotDir() { HostLineEdit *gc = new HostLineEdit("mythgame.screenshotdir"); gc->setLabel(MythGameGeneralSettings::tr("Directory where Game Screenshots " "are stored")); gc->setValue(GetConfDir() + "/MythGame/Screenshots"); gc->setHelpText(MythGameGeneralSettings::tr("This directory will be the " "default browse location when " "assigning screenshots.")); return gc; }
static HostTextEditSetting *GetFanartDir() { HostTextEditSetting *gc = new HostTextEditSetting("mythgame.fanartdir"); gc->setLabel(TR("Directory where Game Fanart is " "stored")); gc->setValue(GetConfDir() + "/MythGame/Fanart"); gc->setHelpText(TR("This directory will be the " "default browse location when " "assigning fanart.")); return gc; }
void AlbumArtImages::addImage(const AlbumArtImage &newImage) { // do we already have an image of this type? AlbumArtImage *image = NULL; AlbumArtList::iterator it = m_imageList.begin(); for (; it != m_imageList.end(); ++it) { if ((*it)->imageType == newImage.imageType && (*it)->embedded == newImage.embedded) { image = *it; break; } } if (!image) { // not found so just add it to the list image = new AlbumArtImage(newImage); m_imageList.push_back(image); } else { // we already have an image of this type so just update it with the new info image->filename = newImage.filename; image->imageType = newImage.imageType; image->embedded = newImage.embedded; image->description = newImage.description; } // if this is an embedded image copy it to disc to speed up its display if (image->embedded && m_parent->getTagger()->supportsEmbeddedImages()) { QString path = GetConfDir() + "/MythMusic/AlbumArt/"; QDir dir(path); QString filename = QString("%1-%2.jpg").arg(m_parent->ID()).arg(AlbumArtImages::getTypeFilename(image->imageType)); if (!QFile::exists(path + filename)) { if (!dir.exists()) dir.mkpath(path); QImage *saveImage = m_parent->getTagger()->getAlbumArt(m_parent->Filename(), image->imageType); if (saveImage) { saveImage->save(path + filename, "JPEG"); delete saveImage; } } image->filename = path + filename; } }
void EditAlbumartDialog::removeCachedImage(const AlbumArtImage *image) { if (!image->embedded) return; QString imageFilename = QString(GetConfDir() + "/MythMusic/AlbumArt/%1-%2.jpg") .arg(m_metadata->ID()).arg(AlbumArtImages::getTypeFilename(image->imageType)); if (QFile::exists(imageFilename)) QFile::remove(imageFilename); GetMythUI()->RemoveFromCacheByFile(imageFilename); }
/// search flickr for genre images void EditMetadataDialog::searchForGenreImages(void) { QString genre= m_metadata->Genre().replace(' ', '+'); genre = QUrl::toPercentEncoding(genre, "+"); QUrl url("http://www.flickr.com/search/groups/?w=908425%40N22&m=pool&q=" + genre, QUrl::TolerantMode); QString cleanName = fixFilename(m_metadata->Genre().toLower()); QString file = GetConfDir() + QString("/MythMusic/Icons/%1/%2.jpg").arg("genre").arg(cleanName); QFileInfo fi(file); GetMythMainWindow()->HandleMedia("WebBrowser", url.toString(), fi.absolutePath() + '/', fi.fileName()); }
/// search google for artist images void EditMetadataDialog::searchForArtistImages(void) { QString artist = m_metadata->Artist().replace(' ', '+'); artist = QUrl::toPercentEncoding(artist, "+"); QUrl url("http://www.google.co.uk/images?q=" + artist, QUrl::TolerantMode); QString cleanName = fixFilename(m_metadata->Artist().toLower()); QString file = GetConfDir() + QString("/MythMusic/Icons/%1/%2.jpg").arg("artist").arg(cleanName); QFileInfo fi(file); GetMythMainWindow()->HandleMedia("WebBrowser", url.toString(), fi.absolutePath() + '/', fi.fileName()); }
bool BlurayMetadata::OpenDisc(void) { QString keyfile = QString("%1/KEYDB.cfg").arg(GetConfDir()); QByteArray keyarray = keyfile.toAscii(); const char *keyfilepath = keyarray.data(); m_bdnav = bd_open(m_path.toLatin1().data(), keyfilepath); if (!m_bdnav) return false; return true; }
static QNetworkAccessManager *GetNetworkAccessManager(void) { if (networkManager) return networkManager; networkManager = new MythNetworkAccessManager(); LOG(VB_GENERAL, LOG_DEBUG, "Copying DLManager's Cookie Jar"); GetMythDownloadManager()->loadCookieJar(GetConfDir() + "/MythBrowser/cookiejar.txt"); networkManager->setCookieJar(GetMythDownloadManager()->copyCookieJar()); atexit(DestroyNetworkAccessManager); return networkManager; }
QStringList Channel::GetXMLTVIdList( uint SourceID ) { MSqlQuery query(MSqlQuery::InitCon()); if (!query.isConnected()) throw( QString("Database not open while trying to get source name.")); query.prepare("SELECT name FROM videosource WHERE sourceid = :SOURCEID "); query.bindValue(":SOURCEID", SourceID); if (!query.exec()) { MythDB::DBError("MythAPI::GetXMLTVIdList()", query); throw( QString( "Database Error executing query." )); } QStringList idList; if (query.next()) { QString sourceName = query.value(0).toString(); QString xmltvFile = GetConfDir() + '/' + sourceName + ".xmltv"; if (QFile::exists(xmltvFile)) { QFile file(xmltvFile); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return idList; while (!file.atEnd()) { QByteArray line = file.readLine(); if (line.startsWith("channel=")) { QString id = line.mid(8, -1).trimmed(); idList.append(id); } } idList.sort(); } } else throw(QString("SourceID (%1) not found").arg(SourceID)); return idList; }