void LCD::SetupLCD (void) { QString lcd_host; int lcd_port; if (m_lcd) { delete m_lcd; m_lcd = NULL; m_serverUnavailable = false; } lcd_host = GetMythDB()->GetSetting("LCDServerHost", "localhost"); lcd_port = GetMythDB()->GetNumSetting("LCDServerPort", 6545); m_enabled = GetMythDB()->GetNumSetting("LCDEnable", 0); // workaround a problem with Ubuntu not resolving localhost properly if (lcd_host == "localhost") lcd_host = "127.0.0.1"; if (m_enabled && lcd_host.length() > 0 && lcd_port > 1024) { LCD *lcd = LCD::Get(); if (lcd->connectToHost(lcd_host, lcd_port) == false) { delete m_lcd; m_lcd = NULL; m_serverUnavailable = false; } } }
MSqlQueryInfo MSqlQuery::InitCon(ConnectionReuse _reuse) { bool reuse = kNormalConnection == _reuse; MSqlDatabase *db = GetMythDB()->GetDBManager()->popConnection(reuse); MSqlQueryInfo qi; InitMSqlQueryInfo(qi); // Bootstrapping without a database? //if (db->pretendHaveDB) if (db->m_db.hostName().isEmpty()) { // Return an invalid database so that QSqlQuery does nothing. // Also works around a Qt4 bug where QSqlQuery::~QSqlQuery // calls QMYSQLResult::cleanup() which uses mysql_next_result() GetMythDB()->GetDBManager()->pushConnection(db); qi.returnConnection = false; return qi; } qi.db = db; qi.qsqldb = db->db(); db->KickDatabase(); return qi; }
void MythLocale::Init(const QString &localeName) { QString dbLanguage = GetMythDB()->GetSetting("Language", ""); QString dbCountry = GetMythDB()->GetSetting("Country", ""); if (!localeName.isEmpty()) { m_localeCode = localeName; } else if (!dbLanguage.isEmpty() && !dbCountry.isEmpty()) { QString langcode = dbLanguage.section('_',0,0); m_localeCode = QString("%1_%2").arg(langcode) .arg(dbCountry.toUpper()); } else { QLocale locale = QLocale::system(); if (locale.name().isEmpty() || locale.name() == "C") { // If all else has failed use the US locale m_localeCode = "en_US"; } else m_localeCode = locale.name(); } m_qtLocale = QLocale(m_localeCode); }
void EditAlbumartDialog::showMenu(void ) { QString label = tr("Options"); MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); MythDialogBox *menu = new MythDialogBox(label, popupStack, "optionsmenu"); if (!menu->Create()) { delete menu; return; } menu->SetReturnEvent(this, "optionsmenu"); menu->AddButton(tr("Edit Metadata")); menu->AddButton(tr("Rescan For Images")); menu->AddButton(tr("Search Internet For Images")); if (m_coverartList->GetItemCurrent()) { menu->AddButton(tr("Change Image Type"), NULL, true); if (GetMythDB()->GetNumSetting("AllowTagWriting", 0)) { MythUIButtonListItem *item = m_coverartList->GetItemCurrent(); if (item) { AlbumArtImage *image = qVariantValue<AlbumArtImage*> (item->GetData()); if (image) { if (!image->embedded) { if (m_metadata->getTagger()->supportsEmbeddedImages()) menu->AddButton(tr("Copy Selected Image To Tag")); } else { if (m_metadata->getTagger()->supportsEmbeddedImages()) menu->AddButton(tr("Remove Selected Image From Tag")); } } } } } if (GetMythDB()->GetNumSetting("AllowTagWriting", 0)) { if (m_metadata->getTagger()->supportsEmbeddedImages()) menu->AddButton(tr("Copy Image To Tag")); } menu->AddButton(tr("Cancel")); popupStack->AddScreen(menu); }
/** * \brief Returns the full path to the theme denoted by themename * * If the theme cannot be found falls back to the DEFAULT_UI_THEME. * If the DEFAULT_UI_THEME doesn't exist then returns an empty string. * \param themename The theme name. * \return Path to theme or empty string. */ QString MythUIHelper::FindThemeDir(const QString &themename) { QString testdir; QDir dir; if (!themename.isEmpty()) { testdir = d->m_userThemeDir + themename; dir.setPath(testdir); if (dir.exists()) return testdir; testdir = GetThemesParentDir() + themename; dir.setPath(testdir); if (dir.exists()) return testdir; LOG(VB_GENERAL, LOG_WARNING, LOC + QString("No theme dir: '%1'") .arg(dir.absolutePath())); } testdir = GetThemesParentDir() + DEFAULT_UI_THEME; dir.setPath(testdir); if (dir.exists()) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Could not find theme: %1 - Switching to %2") .arg(themename).arg(DEFAULT_UI_THEME)); GetMythDB()->OverrideSettingForSession("Theme", DEFAULT_UI_THEME); return testdir; } LOG(VB_GENERAL, LOG_WARNING, LOC + QString("No default theme dir: '%1'") .arg(dir.absolutePath())); testdir = GetThemesParentDir() + FALLBACK_UI_THEME; dir.setPath(testdir); if (dir.exists()) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Could not find theme: %1 - Switching to %2") .arg(themename).arg(FALLBACK_UI_THEME)); GetMythDB()->OverrideSettingForSession("Theme", FALLBACK_UI_THEME); return testdir; } LOG(VB_GENERAL, LOG_ERR, LOC + QString("No fallback GUI theme dir: '%1'") .arg(dir.absolutePath())); return QString(); }
void MythThemedMenu::customEvent(QEvent *event) { if (event->type() == DialogCompletionEvent::kEventType) { DialogCompletionEvent *dce = (DialogCompletionEvent*)(event); QString resultid = dce->GetId(); //int buttonnum = dce->GetResult(); QString halt_cmd = GetMythDB()->GetSetting("HaltCommand"); QString reboot_cmd = GetMythDB()->GetSetting("RebootCommand"); if (resultid == "popmenu") { QString action = dce->GetData().toString(); if (action == "shutdown") { if (!halt_cmd.isEmpty()) myth_system(halt_cmd); } else if (action == "reboot") { if (!reboot_cmd.isEmpty()) myth_system(reboot_cmd); } else if (action == "about") { aboutScreen(); } else if (action == "standby") { QString arg("standby_mode"); m_state->m_callback(m_state->m_callbackdata, arg); } } else if (resultid == "password") { QString text = dce->GetResultText(); MythUIButtonListItem *item = m_buttonList->GetItemCurrent(); ThemedButton button = item->GetData().value<ThemedButton>(); QString password = GetMythDB()->GetSetting(button.password); if (text == password) { QString timestamp_setting = QString("%1Time").arg(button.password); QDateTime curr_time = QDateTime::currentDateTime(); QString last_time_stamp = curr_time.toString(Qt::TextDate); GetMythDB()->SetSetting(timestamp_setting, last_time_stamp); GetMythDB()->SaveSetting(timestamp_setting, last_time_stamp); buttonAction(item, true); } } m_menuPopup = NULL; } }
MythUIClock::MythUIClock(MythUIType *parent, const QString &name) : MythUIText(parent, name) { m_DateFormat = GetMythDB()->GetSetting("DateFormat", "ddd d MMMM"); m_ShortDateFormat = GetMythDB()->GetSetting("ShortDateFormat", "ddd d"); m_TimeFormat = GetMythDB()->GetSetting("TimeFormat", "hh:mm"); m_Format = QString("%1, %2").arg(m_DateFormat).arg(m_TimeFormat); m_Flash = false; }
bool MSqlQuery::testDBConnection() { MSqlDatabase *db = GetMythDB()->GetDBManager()->popConnection(true); // popConnection() has already called OpenDatabase(), // so we only have to check if it was successful: bool isOpen = db->isOpen(); GetMythDB()->GetDBManager()->pushConnection(db); return isOpen; }
void LCD::init() { // Stop the timer m_retryTimer->stop(); // Get LCD settings m_lcdShowMusic = (GetMythDB()->GetSetting("LCDShowMusic", "1") == "1"); m_lcdShowTime = (GetMythDB()->GetSetting("LCDShowTime", "1") == "1"); m_lcdShowChannel = (GetMythDB()->GetSetting("LCDShowChannel", "1") == "1"); m_lcdShowGeneric = (GetMythDB()->GetSetting("LCDShowGeneric", "1") == "1"); m_lcdShowVolume = (GetMythDB()->GetSetting("LCDShowVolume", "1") == "1"); m_lcdShowMenu = (GetMythDB()->GetSetting("LCDShowMenu", "1") == "1"); m_lcdShowRecStatus = (GetMythDB()->GetSetting("LCDShowRecStatus", "1") == "1"); m_lcdKeyString = GetMythDB()->GetSetting("LCDKeyString", "ABCDEF"); m_connected = true; m_lcdReady = true; // send buffer if there's anything in there if (m_sendBuffer.length() > 0) { sendToServer(m_sendBuffer); m_sendBuffer = ""; } }
/** \brief Queries the user for a password to enter a part of MythTV * restricted by a password. * * \param timestamp_setting time settings to be checked * \param password_setting password to be checked * \param text the message text to be displayed * \return true if password checks out or is not needed. */ bool MythThemedMenu::checkPinCode(const QString &password_setting) { QString timestamp_setting = QString("%1Time").arg(password_setting); QDateTime curr_time = QDateTime::currentDateTime(); QString last_time_stamp = GetMythDB()->GetSetting(timestamp_setting); QString password = GetMythDB()->GetSetting(password_setting); // Password empty? Then skip asking for it if (password.isEmpty()) return true; if (last_time_stamp.length() < 1) { LOG(VB_GENERAL, LOG_ERR, "MythThemedMenu: Could not read password/pin time stamp.\n" "This is only an issue if it happens repeatedly."); } else { QDateTime last_time = QDateTime::fromString(last_time_stamp, Qt::TextDate); if (last_time.secsTo(curr_time) < 120) { last_time_stamp = curr_time.toString(Qt::TextDate); GetMythDB()->SetSetting(timestamp_setting, last_time_stamp); GetMythDB()->SaveSetting(timestamp_setting, last_time_stamp); return true; } } LOG(VB_GENERAL, LOG_INFO, QString("Using Password: %1") .arg(password_setting)); QString text = tr("Enter password:"******"popup stack"); MythTextInputDialog *dialog = new MythTextInputDialog(popupStack, text, FilterNone, true); if (dialog->Create()) { dialog->SetReturnEvent(this, "password"); popupStack->AddScreen(dialog); } else delete dialog; return false; }
void ResetTimer(void) { LOG(VB_PLAYBACK, LOG_DEBUG, LOC + "ResetTimer -- begin"); StopTimer(); if (m_timeoutInterval == -1) { m_timeoutInterval = GetMythDB()->GetNumSettingOnHost( "xscreensaverInterval", GetMythDB()->GetHostName(), 50) * 1000; } if (m_timeoutInterval > 0) StartTimer(); LOG(VB_PLAYBACK, LOG_DEBUG, LOC + "ResetTimer -- end"); }
void UPnpDeviceDesc::_InternalLoad( QDomNode oNode, UPnpDevice *pCurDevice ) { QString pin = GetMythDB()->GetSetting( "SecurityPin", ""); pCurDevice->m_securityPin = !(pin.isEmpty() || pin == "0000"); for ( oNode = oNode.firstChild(); !oNode.isNull(); oNode = oNode.nextSibling() ) { QDomElement e = oNode.toElement(); if (e.isNull()) continue; // TODO: make this table driven (using offset within structure) if ( e.tagName() == "deviceType" ) SetStrValue( e, pCurDevice->m_sDeviceType); else if ( e.tagName() == "friendlyName" ) SetStrValue( e, pCurDevice->m_sFriendlyName ); else if ( e.tagName() == "manufacturer" ) SetStrValue( e, pCurDevice->m_sManufacturer ); else if ( e.tagName() == "manufacturerURL" ) SetStrValue( e, pCurDevice->m_sManufacturerURL ); else if ( e.tagName() == "modelDescription" ) SetStrValue( e, pCurDevice->m_sModelDescription); else if ( e.tagName() == "modelName" ) SetStrValue( e, pCurDevice->m_sModelName ); else if ( e.tagName() == "modelNumber" ) SetStrValue( e, pCurDevice->m_sModelNumber ); else if ( e.tagName() == "modelURL" ) SetStrValue( e, pCurDevice->m_sModelURL ); else if ( e.tagName() == "serialNumber" ) SetStrValue( e, pCurDevice->m_sSerialNumber ); else if ( e.tagName() == "UPC" ) SetStrValue( e, pCurDevice->m_sUPC ); else if ( e.tagName() == "presentationURL" ) SetStrValue( e, pCurDevice->m_sPresentationURL ); else if ( e.tagName() == "UDN" ) SetStrValue( e, pCurDevice->m_sUDN ); else if ( e.tagName() == "iconList" ) ProcessIconList( oNode, pCurDevice ); else if ( e.tagName() == "serviceList" ) ProcessServiceList( oNode, pCurDevice ); else if ( e.tagName() == "deviceList" ) ProcessDeviceList ( oNode, pCurDevice ); else if ( e.tagName() == "mythtv:X_secure" ) SetBoolValue( e, pCurDevice->m_securityPin ); else if ( e.tagName() == "mythtv:X_protocol" ) SetStrValue( e, pCurDevice->m_protocolVersion ); else { // Not one of the expected element names... add to extra list. QString sValue = ""; SetStrValue( e, sValue ); pCurDevice->m_lstExtra.push_back(NameValue(e.tagName(), sValue)); } } }
QString Myth::GetFormatDate(const QDateTime Date, bool ShortDate) { QString dateFormat; if (ShortDate) dateFormat = gCoreContext->GetSetting("ShortDateFormat", "ddd d"); else dateFormat = GetMythDB()->GetSetting("DateFormat", "ddd d MMMM"); return gCoreContext->GetQLocale().toString(Date, dateFormat); }
bool MSqlQuery::prepare(const QString& query) { if (!m_db) { // Database structure's been deleted return false; } m_last_prepared_query = query; #ifdef DEBUG_QT4_PORT if (query.contains(m_testbindings)) { LOG(VB_GENERAL, LOG_DEBUG, QString("\n\nQuery contains bind value \"%1\" twice:\n\n\n") .arg(m_testbindings.cap(1)) + query); #if 0 exit(1); #endif } #endif // Database connection down. Try to restart it, give up if it's still // down if (!m_db) { // Database structure has been deleted... return false; } if (!m_db->isOpen() && !Reconnect()) { LOG(VB_GENERAL, LOG_INFO, "MySQL server disconnected"); return false; } bool ok = QSqlQuery::prepare(query); // if the prepare failed with "MySQL server has gone away" // Close and reopen the database connection and retry the query if it // connects again if (!ok && QSqlQuery::lastError().number() == 2006 && Reconnect()) ok = true; if (!ok && !(GetMythDB()->SuppressDBMessages())) { LOG(VB_GENERAL, LOG_ERR, QString("Error preparing query: %1").arg(query)); LOG(VB_GENERAL, LOG_ERR, MythDB::DBErrorMessage(QSqlQuery::lastError())); } return ok; }
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; }
void MythUIHelper::Init(MythUIMenuCallbacks &cbs) { d->Init(); d->callbacks = cbs; d->m_maxCacheSize.fetchAndStoreRelease( GetMythDB()->GetNumSetting("UIImageCacheSize", 30) * 1024 * 1024); LOG(VB_GUI, LOG_INFO, LOC + QString("MythUI Image Cache size set to %1 bytes") .arg(d->m_maxCacheSize.fetchAndAddRelease(0))); }
MSqlQuery::~MSqlQuery() { if (m_returnConnection) { MDBManager *dbmanager = GetMythDB()->GetDBManager(); if (dbmanager && m_db) { dbmanager->pushConnection(m_db); } } }
void EditMetadataCommon::saveAll() { if (GetMythDB()->GetNumSetting("AllowTagWriting", 0)) { MetaIO *tagger = m_metadata->getTagger(); if (tagger) tagger->write(m_metadata); } saveToDatabase(); cleanupAndClose(); }
/** * \brief Write the changable metadata, e.g. ratings, playcounts; to the * \p filename if the tag format supports it. * * Creates a \p MetaIO object using \p Decoder::doCreateTagger and * asks the MetaIO object to write changes to a specific subset of metadata * to \p filename. * * \params mdata the metadata to write to the disk */ void Decoder::commitVolatileMetadata(const Metadata *mdata) { if (!mdata || !GetMythDB()->GetNumSetting("AllowTagWriting", 0)) return; MetaIO* p_tagger = doCreateTagger(); if (p_tagger) { p_tagger->writeVolatileMetadata(mdata); delete p_tagger; } mdata->UpdateModTime(); }
void EditMetadataDialog::saveAll() { cancelPopup(); if (GetMythDB()->GetNumSetting("AllowTagWriting", 0)) { Decoder *decoder = Decoder::create(m_metadata->Filename(), NULL, NULL, true); if (decoder) { decoder->commitMetadata(m_metadata); delete decoder; } } saveToDatabase(); }
MSqlQueryInfo MSqlQuery::DDCon() { MSqlDatabase *db = GetMythDB()->GetDBManager()->getDDCon(); MSqlQueryInfo qi; InitMSqlQueryInfo(qi); qi.returnConnection = false; if (db) { qi.db = db; qi.qsqldb = db->db(); db->KickDatabase(); } return qi; }
void MythThemedMenu::ShowMenu() { if (m_menuPopup) return; int override_menu = GetMythDB()->GetNumSetting("OverrideExitMenu"); QString label = tr("System Menu"); MythScreenStack* mainStack = GetMythMainWindow()->GetMainStack(); m_menuPopup = new MythDialogBox(label, mainStack, "menuPopup"); if (m_menuPopup->Create()) mainStack->AddScreen(m_menuPopup); switch (override_menu) { case 2: case 4: // shutdown m_menuPopup->SetReturnEvent(this,"popmenu_shutdown"); m_menuPopup->AddButton(tr("Shutdown")); break; case 5: // reboot m_menuPopup->SetReturnEvent(this,"popmenu_reboot"); m_menuPopup->AddButton(tr("Reboot")); break; case 3: case 6: // both m_menuPopup->SetReturnEvent(this,"popmenu_exit"); m_menuPopup->AddButton(tr("Shutdown")); m_menuPopup->AddButton(tr("Reboot")); break; case 0: default: m_menuPopup->SetReturnEvent(this,"popmenu_noexit"); break; } m_menuPopup->AddButton(tr("About")); m_menuPopup->AddButton(tr("Cancel")); }
void MythThemedMenu::ShowMenu() { if (m_menuPopup) return; int override_menu = GetMythDB()->GetNumSetting("OverrideExitMenu"); QString label = tr("System Menu"); MythScreenStack* mainStack = GetMythMainWindow()->GetMainStack(); m_menuPopup = new MythDialogBox(label, mainStack, "menuPopup"); if (m_menuPopup->Create()) mainStack->AddScreen(m_menuPopup); m_menuPopup->SetReturnEvent(this, "popmenu"); // HACK Implement a better check for this if (QCoreApplication::applicationName() == MYTH_APPNAME_MYTHFRONTEND) m_menuPopup->AddButton(tr("Enter standby mode"), QVariant("standby")); switch (override_menu) { case 2: case 4: // shutdown m_menuPopup->AddButton(tr("Shutdown"), QVariant("shutdown")); break; case 5: // reboot m_menuPopup->AddButton(tr("Reboot"), QVariant("reboot")); break; case 3: case 6: // both m_menuPopup->AddButton(tr("Shutdown"), QVariant("shutdown")); m_menuPopup->AddButton(tr("Reboot"), QVariant("reboot")); break; case 0: default: break; } m_menuPopup->AddButton(tr("About"), QVariant("about")); }
/** * \brief Returns the full path to the menu theme denoted by menuname * * If the theme cannot be found falls back to the default menu. * If the default menu theme doesn't exist then returns an empty string. * \param menuname The menutheme name. * \return Path to theme or empty string. */ QString MythUIHelper::FindMenuThemeDir(const QString &menuname) { QString testdir; QDir dir; testdir = d->m_userThemeDir + menuname; dir.setPath(testdir); if (dir.exists()) return testdir; testdir = GetThemesParentDir() + menuname; dir.setPath(testdir); if (dir.exists()) return testdir; testdir = GetShareDir(); dir.setPath(testdir); if (dir.exists()) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Could not find menu theme: %1 - Switching to default") .arg(menuname)); GetMythDB()->SaveSetting("MenuTheme", "default"); return testdir; } LOG(VB_GENERAL, LOG_ERR, LOC + QString("Could not find menu theme: %1 - Fallback to default failed.") .arg(menuname)); return QString(); }
void DBConfiguration::SetValue( const QString &sSetting, QString sValue ) { GetMythDB()->SaveSetting( sSetting, sValue ); }
bool MSqlQuery::prepare(const QString& query) { if (!m_db) { // Database structure's been deleted return false; } m_last_prepared_query = query; #ifdef DEBUG_QT4_PORT if (query.contains(m_testbindings)) { LOG(VB_GENERAL, LOG_DEBUG, QString("\n\nQuery contains bind value \"%1\" twice:\n\n\n") .arg(m_testbindings.cap(1)) + query); #if 0 exit(1); #endif } #endif // Database connection down. Try to restart it, give up if it's still // down if (!m_db) { // Database structure has been deleted... return false; } if (!m_db->isOpen() && !Reconnect()) { LOG(VB_GENERAL, LOG_INFO, "MySQL server disconnected"); return false; } // QT docs indicate that there are significant speed ups and a reduction // in memory usage by enabling forward-only cursors // // Unconditionally enable this since all existing uses of the database // iterate forward over the result set. setForwardOnly(true); bool ok = QSqlQuery::prepare(query); // if the prepare failed with "MySQL server has gone away" // Close and reopen the database connection and retry the query if it // connects again if (!ok && QSqlQuery::lastError().number() == 2006 && Reconnect()) ok = true; if (!ok && !(GetMythDB()->SuppressDBMessages())) { LOG(VB_GENERAL, LOG_ERR, QString("Error preparing query: %1").arg(query)); LOG(VB_GENERAL, LOG_ERR, MythDB::DBErrorMessage(QSqlQuery::lastError())); } return ok; }
int DBConfiguration::GetValue( const QString &sSetting, int nDefault ) { return GetMythDB()->GetNumSetting( sSetting, nDefault ); }
QString DBConfiguration::GetValue( const QString &sSetting, QString sDefault ) { return GetMythDB()->GetSetting( sSetting, sDefault ); }
bool MSqlDatabase::OpenDatabase(bool skipdb) { if (!m_db.isValid()) { LOG(VB_GENERAL, LOG_ERR, "MSqlDatabase::OpenDatabase(), db object is not valid!"); return false; } bool connected = true; if (!m_db.isOpen()) { if (!skipdb) m_dbparms = GetMythDB()->GetDatabaseParams(); m_db.setDatabaseName(m_dbparms.dbName); m_db.setUserName(m_dbparms.dbUserName); m_db.setPassword(m_dbparms.dbPassword); m_db.setHostName(m_dbparms.dbHostName); if (m_dbparms.dbHostName.isEmpty()) // Bootstrapping without a database? { connected = true; // Pretend to be connected return true; // to reduce errors } if (m_dbparms.dbPort) m_db.setPort(m_dbparms.dbPort); // Prefer using the faster localhost connection if using standard // ports, even if the user specified a DBHostName of 127.0.0.1. This // will cause MySQL to use a Unix socket (on *nix) or shared memory (on // Windows) connection. if ((m_dbparms.dbPort == 0 || m_dbparms.dbPort == 3306) && m_dbparms.dbHostName == "127.0.0.1") m_db.setHostName("localhost"); connected = m_db.open(); if (!connected && m_dbparms.wolEnabled) { int trycount = 0; while (!connected && trycount++ < m_dbparms.wolRetry) { LOG(VB_GENERAL, LOG_INFO, QString("Using WOL to wakeup database server (Try %1 of " "%2)") .arg(trycount).arg(m_dbparms.wolRetry)); if (myth_system(m_dbparms.wolCommand) != GENERIC_EXIT_OK) { LOG(VB_GENERAL, LOG_ERR, QString("Failed to run WOL command '%1'") .arg(m_dbparms.wolCommand)); } sleep(m_dbparms.wolReconnect); connected = m_db.open(); } if (!connected) { LOG(VB_GENERAL, LOG_ERR, "WOL failed, unable to connect to database!"); } } if (connected) { LOG(VB_DATABASE, LOG_INFO, QString("[%1] Connected to database '%2' at host: %3") .arg(m_name) .arg(m_db.databaseName()).arg(m_db.hostName())); InitSessionVars(); // WriteDelayed depends on SetHaveDBConnection() and SetHaveSchema() // both being called with true, so order is important here. GetMythDB()->SetHaveDBConnection(true); if (!GetMythDB()->HaveSchema()) { // We can't just check the count of QSqlDatabase::tables() // because it returns all tables visible to the user in *all* // databases (not just the current DB). bool have_schema = false; QString sql = "SELECT COUNT( " " INFORMATION_SCHEMA.TABLES.TABLE_NAME " " ) " " FROM INFORMATION_SCHEMA.TABLES " " WHERE INFORMATION_SCHEMA.TABLES.TABLE_SCHEMA " " = DATABASE() " " AND INFORMATION_SCHEMA.TABLES.TABLE_TYPE = " " 'BASE TABLE';"; // We can't use MSqlQuery to determine if we have a schema, // since it will open a new connection, which will try to check // if we have a schema QSqlQuery query = m_db.exec(sql); // don't convert to MSqlQuery if (query.next()) have_schema = query.value(0).toInt() > 1; GetMythDB()->SetHaveSchema(have_schema); } GetMythDB()->WriteDelayedSettings(); } } if (!connected) { GetMythDB()->SetHaveDBConnection(false); LOG(VB_GENERAL, LOG_ERR, QString("[%1] Unable to connect to database!").arg(m_name)); LOG(VB_GENERAL, LOG_ERR, MythDB::DBErrorMessage(m_db.lastError())); } return connected; }
void DBConfiguration::ClearValue( const QString &sSetting ) { GetMythDB()->ClearSetting( sSetting ); }