Пример #1
0
void Ripper::ejectCD()
{
    bool bEjectCD = gCoreContext->GetNumSetting("EjectCDAfterRipping",1);
    if (bEjectCD)
    {
#ifdef HAVE_CDAUDIO
        QByteArray devname = m_CDdevice.toAscii();
        int cdrom_fd = cd_init_device(const_cast<char*>(devname.constData()));
        VERBOSE(VB_MEDIA, "Ripper::ejectCD() - dev " + m_CDdevice);
        if (cdrom_fd != -1)
        {
            if (cd_eject(cdrom_fd) == -1)
                perror("Failed on cd_eject");

            cd_finish(cdrom_fd);
        }
        else
            perror("Failed on cd_init_device");
#else
        MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
        if (mon)
        {
            QByteArray devname = m_CDdevice.toAscii();
            MythMediaDevice *pMedia = mon->GetMedia(devname.constData());
            if (pMedia && mon->ValidateAndLock(pMedia))
            {
                pMedia->eject();
                mon->Unlock(pMedia);
            }
        }
#endif
    }
}
Пример #2
0
void Ripper::ejectCD()
{
    LOG(VB_MEDIA, LOG_INFO, __PRETTY_FUNCTION__);
    bool bEjectCD = gCoreContext->GetNumSetting("EjectCDAfterRipping",1);
    if (bEjectCD)
    {
#ifdef HAVE_CDIO
        LOG(VB_MEDIA, LOG_INFO, QString("Ripper::%1 '%2'").
            arg(__func__).arg(m_CDdevice));
        (void)cdio_eject_media_drive(m_CDdevice.toLatin1().constData());
#else
        MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
        if (mon)
        {
            QByteArray devname = m_CDdevice.toLatin1();
            MythMediaDevice *pMedia = mon->GetMedia(devname.constData());
            if (pMedia && mon->ValidateAndLock(pMedia))
            {
                pMedia->eject();
                mon->Unlock(pMedia);
            }
        }
#endif // HAVE_CDIO
    }
}
void MediaMonitor::SetCDSpeed(const char *device, int speed)
{
    MediaMonitor *mon = GetMediaMonitor();
    if (mon)
    {
        MythMediaDevice *pMedia = mon->GetMedia(device);
        if (pMedia && mon->ValidateAndLock(pMedia))
        {
            pMedia->setSpeed(speed);
            mon->Unlock(pMedia);
            return;
        }
    }

    MythCDROM *cd = MythCDROM::get(NULL, device, false, false);
    if (cd)
    {
        cd->setDeviceSpeed(device, speed);
        delete cd;
        return;
    }

    LOG(VB_MEDIA, LOG_INFO, 
             QString("MediaMonitor::setSpeed(%1) - Cannot find/create CDROM?")
                  .arg(device));
}
Пример #4
0
void IconView::HandleSettings(void)
{
    GallerySettings settings;
    settings.exec();
    gCoreContext->ClearSettingsCache();

    // reload settings
    m_showcaption = gCoreContext->GetNumSetting("GalleryOverlayCaption", 0);
    m_sortorder   = gCoreContext->GetNumSetting("GallerySortOrder", 0);
    m_useOpenGL   = gCoreContext->GetNumSetting("SlideshowUseOpenGL", 0);
    m_recurse     = gCoreContext->GetNumSetting("GalleryRecursiveSlideshow", 0);
    m_paths       = gCoreContext->GetSetting("GalleryImportDirs").split(":");
    m_allowImportScripts = gCoreContext->GetNumSetting("GalleryAllowImportScripts", 0);

    // reload directory
    MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
    if (m_currDevice && mon && mon->ValidateAndLock(m_currDevice))
    {
#ifdef _WIN32
        LoadDirectory(m_currDevice->getDevicePath());
#else
        LoadDirectory(m_currDevice->getMountPath());
#endif
        mon->Unlock(m_currDevice);
    }
    else
    {
        m_currDevice = NULL;
        LoadDirectory(m_galleryDir);
    }

    SetFocusWidget(m_imageList);
}
Пример #5
0
Ripper::Ripper(MythScreenStack *parent, QString device) :
    MythScreenType(parent, "ripcd"),
    m_tracks(new QVector<RipTrack*>),
    m_CDdevice(std::move(device))
{
#ifndef _WIN32
    // if the MediaMonitor is running stop it
    m_mediaMonitorActive = false;
    MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
    if (mon && mon->IsActive())
    {
        m_mediaMonitorActive = true;
        mon->StopMonitoring();
    }
#endif // _WIN32

    // make sure the directory where we temporarily save the rips is present
    QDir dir;
    dir.mkpath(GetConfDir() + "/tmp/RipTemp/");

    // remove any ripped tracks from the temp rip directory
    QString command = "rm -f " + GetConfDir() + "/tmp/RipTemp/*";
    myth_system(command);

    // get last host and directory we ripped to
    QString lastHost = gCoreContext->GetSetting("MythMusicLastRipHost", gCoreContext->GetMasterHostName());
    QStringList dirs = StorageGroup::getGroupDirs("Music", lastHost);
    if (dirs.count() > 0)
        m_musicStorageDir = StorageGroup::getGroupDirs("Music", lastHost).at(0);
}
Пример #6
0
Ripper::Ripper(MythScreenStack *parent, QString device) :
    MythScreenType(parent, "ripcd"),
    m_musicStorageDir(""),

    m_decoder(nullptr),

    m_artistEdit(nullptr),
    m_albumEdit(nullptr),
    m_genreEdit(nullptr),
    m_yearEdit(nullptr),

    m_compilationCheck(nullptr),

    m_trackList(nullptr),
    m_qualityList(nullptr),

    m_switchTitleArtist(nullptr),
    m_scanButton(nullptr),
    m_ripButton(nullptr),
    m_searchArtistButton(nullptr),
    m_searchAlbumButton(nullptr),
    m_searchGenreButton(nullptr),

    m_tracks(new QVector<RipTrack*>),

    m_somethingwasripped(false),
    m_mediaMonitorActive(false),

    m_CDdevice(device),

    m_ejectThread(nullptr), m_scanThread(nullptr)
{
#ifndef _WIN32
    // if the MediaMonitor is running stop it
    m_mediaMonitorActive = false;
    MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
    if (mon && mon->IsActive())
    {
        m_mediaMonitorActive = true;
        mon->StopMonitoring();
    }
#endif // _WIN32

    // make sure the directory where we temporarily save the rips is present
    QDir dir;
    dir.mkpath(GetConfDir() + "/tmp/RipTemp/");

    // remove any ripped tracks from the temp rip directory
    QString command = "rm -f " + GetConfDir() + "/tmp/RipTemp/*";
    myth_system(command);

    // get last host and directory we ripped to
    QString lastHost = gCoreContext->GetSetting("MythMusicLastRipHost", gCoreContext->GetMasterHostName());
    QStringList dirs = StorageGroup::getGroupDirs("Music", lastHost);
    if (dirs.count() > 0)
        m_musicStorageDir = StorageGroup::getGroupDirs("Music", lastHost).at(0);
}
Пример #7
0
/**
 * \brief Eject a disk, unmount a drive, open a tray
 *
 * If the Media Monitor is enabled, we use its fully-featured routine.
 * Otherwise, we guess a drive and use a primitive OS-specific command
 */
void MediaMonitor::ejectOpticalDisc()
{
    MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
    if (mon)
        mon->ChooseAndEjectMedia();
    else
    {
        VERBOSE(VB_MEDIA, "CD/DVD Monitor isn't enabled.");
#ifdef __linux__
        VERBOSE(VB_MEDIA, "Trying Linux 'eject -T' command");
        myth_system("eject -T");
#elif CONFIG_DARWIN
        VERBOSE(VB_MEDIA, "Trying 'disktool -e disk1");
        myth_system("disktool -e disk1");
#endif
    }
}
/**
 * \brief Eject a disk, unmount a drive, open a tray
 *
 * If the Media Monitor is enabled, we use its fully-featured routine.
 * Otherwise, we guess a drive and use a primitive OS-specific command
 */
void MediaMonitor::ejectOpticalDisc()
{
    MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
    if (mon)
        mon->ChooseAndEjectMedia();
    else
    {
        LOG(VB_MEDIA, LOG_INFO, "CD/DVD Monitor isn't enabled.");
#ifdef __linux__
        LOG(VB_MEDIA, LOG_INFO, "Trying Linux 'eject -T' command");
        myth_system("eject -T");
#elif CONFIG_DARWIN
        QString def = DEFAULT_CD;
        LOG(VB_MEDIA, LOG_INFO, "Trying 'disktool -e " + def);
        myth_system("disktool -e " + def);
#endif
    }
}
Пример #9
0
Ripper::~Ripper(void)
{
    if (m_decoder)
        delete m_decoder;

#ifndef _WIN32
    // if the MediaMonitor was active when we started then restart it
    if (m_mediaMonitorActive)
    {
        MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
        if (mon)
            mon->StartMonitoring();
    }
#endif

    if (m_somethingwasripped)
        emit ripFinished();
}
Пример #10
0
Ripper::Ripper(MythScreenStack *parent, QString device) :
    MythScreenType(parent, "ripcd"),
    m_decoder(NULL),

    m_artistEdit(NULL),
    m_albumEdit(NULL),
    m_genreEdit(NULL),
    m_yearEdit(NULL),

    m_compilationCheck(NULL),

    m_trackList(NULL),
    m_qualityList(NULL),

    m_switchTitleArtist(NULL),
    m_scanButton(NULL),
    m_ripButton(NULL),
    m_searchArtistButton(NULL),
    m_searchAlbumButton(NULL),
    m_searchGenreButton(NULL),

    m_tracks(new QVector<RipTrack*>),

    m_somethingwasripped(false),
    m_mediaMonitorActive(false),

    m_CDdevice(device),

    m_ejectThread(NULL), m_scanThread(NULL)
{
#ifndef _WIN32
    // if the MediaMonitor is running stop it
    m_mediaMonitorActive = false;
    MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
    if (mon && mon->IsActive())
    {
        m_mediaMonitorActive = true;
        mon->StopMonitoring();
    }
#endif
}
Пример #11
0
Ripper::~Ripper(void)
{
    // remove any ripped tracks from the temp rip directory
    QString command = "rm -f " + GetConfDir() + "/tmp/RipTemp/*";
    myth_system(command);

    delete m_decoder;

#ifndef _WIN32
    // if the MediaMonitor was active when we started then restart it
    if (m_mediaMonitorActive)
    {
        MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
        if (mon)
            mon->StartMonitoring();
    }
#endif // _WIN32

    if (m_somethingwasripped)
        emit ripFinished();
}
Пример #12
0
void IconView::SetupMediaMonitor(void)
{
#ifdef _WIN32
    if (m_currDevice)
        LoadDirectory(m_currDevice->getDevicePath());
#else
    MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
    if (m_currDevice && mon && mon->ValidateAndLock(m_currDevice))
    {
        bool mounted = m_currDevice->isMounted();
        if (!mounted)
            mounted = m_currDevice->mount();

        if (mounted)
        {
            connect(m_currDevice,
                SIGNAL(statusChanged(MythMediaStatus, MythMediaDevice*)),
                SLOT(mediaStatusChanged(MythMediaStatus, MythMediaDevice*)));

            LoadDirectory(m_currDevice->getMountPath());

            mon->Unlock(m_currDevice);
            return;
        }
        else
        {
//             DialogBox *dlg = new DialogBox(GetMythMainWindow(),
//                              tr("Failed to mount device: ") +
//                              m_currDevice->getDevicePath() + "\n\n" +
//                              tr("Showing the default MythGallery directory."));
//             dlg->AddButton(tr("OK"));
//             dlg->exec();
//             dlg->deleteLater();
            mon->Unlock(m_currDevice);
        }
    }
#endif // _WIN32
}
Пример #13
0
Ripper::Ripper(MythScreenStack *parent, QString device)
       : MythScreenType(parent, "ripcd"),
         m_ejectThread(NULL), m_scanThread(NULL)
{
    m_CDdevice = device;

#ifndef _WIN32
    // if the MediaMonitor is running stop it
    m_mediaMonitorActive = false;
    MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
    if (mon && mon->IsActive())
    {
        m_mediaMonitorActive = true;
        mon->StopMonitoring();
    }
#endif

    // Set this to false so we can tell if the ripper has done anything
    // (i.e. we can tell if the user quit prior to ripping)
    m_somethingwasripped = false;
    m_decoder = NULL;
    m_tracks = new QVector<RipTrack*>;
}
Пример #14
0
bool IconView::HandleMediaDeviceSelect(ThumbItem *item)
{
    MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
    if (mon && mon->ValidateAndLock(item->GetMediaDevice()))
    {
        m_currDevice = item->GetMediaDevice();

#ifdef _WIN32
        LoadDirectory(m_currDevice->getDevicePath());
#else
        if (!m_currDevice->isMounted(false))
            m_currDevice->mount();

        item->SetPath(m_currDevice->getMountPath(), true);

        connect(m_currDevice,
                SIGNAL(statusChanged(MythMediaStatus,
                                     MythMediaDevice*)),
                SLOT(mediaStatusChanged(MythMediaStatus,
                                        MythMediaDevice*)));

        LoadDirectory(m_currDevice->getMountPath());
#endif

        mon->Unlock(m_currDevice);
    }
    else
    {
        // device was removed
        QString msg = tr("Error") + '\n' +
                tr("The selected device is no longer available");
        ShowOkPopup(msg, this, SLOT(HandleShowDevices()));
    }

    return true;
}
Пример #15
0
void IconView::HandleShowDevices(void)
{
    MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
#ifndef _WIN32
    if (m_currDevice && mon && mon->ValidateAndLock(m_currDevice))
    {
        m_currDevice->disconnect(this);
        mon->Unlock(m_currDevice);
    }
    else
        m_currDir = m_galleryDir;
#endif

    m_currDevice = NULL;

    m_showDevices = true;

    while (!m_itemList.isEmpty())
        delete m_itemList.takeFirst();

    m_itemHash.clear();
    m_imageList->Reset();

    m_thumbGen->cancel();
    m_childCountThread->cancel();

    // add gallery directory
    ThumbItem *item = new ThumbItem("Gallery", m_galleryDir, true);
    m_itemList.append(item);
    m_itemHash.insert(item->GetName(), item);

    if (mon)
    {
        MythMediaType type = MythMediaType(MEDIATYPE_DATA | MEDIATYPE_MGALLERY | MEDIATYPE_MVIDEO);
        QList<MythMediaDevice*> removables = mon->GetMedias(type);
        QList<MythMediaDevice*>::Iterator it = removables.begin();
        for (; it != removables.end(); ++it)
        {
            if (mon->ValidateAndLock(*it))
            {
                item = new ThumbItem(
                    (*it)->getVolumeID().isEmpty() ?
                    (*it)->getDevicePath() : (*it)->getVolumeID(),
                    (*it)->getMountPath(), true, *it);

                m_itemList.append(item);
                m_itemHash.insert(item->GetName(), item);

                mon->Unlock(*it);
            }
        }
    }

    ThumbItem *thumbitem;
    for (int x = 0; x < m_itemList.size(); x++)
    {
        thumbitem = m_itemList.at(x);

        thumbitem->InitCaption(m_showcaption);
        MythUIButtonListItem* item =
            new MythUIButtonListItem(m_imageList, thumbitem->GetCaption(), 0,
                                     true, MythUIButtonListItem::NotChecked);
        item->SetData(qVariantFromValue(thumbitem));
    }

    // exit from menu on show devices action..
    SetFocusWidget(m_imageList);
}
Пример #16
0
int main(int argc, char **argv)
{
    bool bPromptForBackend    = false;
    bool bBypassAutoDiscovery = false;
    bool upgradeAllowed = false;

    bool cmdline_err;
    MythCommandLineParser cmdline(
        kCLPOverrideSettingsFile |
        kCLPOverrideSettings     |
        kCLPWindowed             |
        kCLPNoWindowed           |
        kCLPGetSettings          |
        kCLPQueryVersion         |
        kCLPVerbose              |
        kCLPNoUPnP               |
#ifdef USING_X11
        kCLPDisplay              |
#endif // USING_X11
        kCLPExtra                |
        kCLPGeometry);

    // Handle --help before QApplication is created, so that
    // we can print help even if X11 is absent.
    for (int argpos = 1; argpos < argc; ++argpos)
    {
        QString arg(argv[argpos]);
        if (arg == "-h" || arg == "--help" || arg == "--usage")
        {
            ShowUsage(cmdline);
            return GENERIC_EXIT_OK;
        }
    }

    for (int argpos = 1; argpos < argc; ++argpos)
    {
        if (cmdline.PreParse(argc, argv, argpos, cmdline_err))
        {
            if (cmdline_err)
                return GENERIC_EXIT_INVALID_CMDLINE;
            if (cmdline.WantsToExit())
                return GENERIC_EXIT_OK;
        }
    }

#ifdef Q_WS_MACX
    // Without this, we can't set focus to any of the CheckBoxSetting, and most
    // of the MythPushButton widgets, and they don't use the themed background.
    QApplication::setDesktopSettingsAware(false);
#endif
    QApplication a(argc, argv);

    QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHFRONTEND);

    QString pluginname;

    QFileInfo finfo(a.argv()[0]);

    QString binname = finfo.baseName();

    VERBOSE(VB_IMPORTANT, QString("%1 version: %2 [%3] www.mythtv.org")
                            .arg(MYTH_APPNAME_MYTHFRONTEND)
                            .arg(MYTH_SOURCE_PATH)
                            .arg(MYTH_SOURCE_VERSION));

    bool ResetSettings = false;

    if (binname.toLower() != "mythfrontend")
        pluginname = binname;

    for (int argpos = 1; argpos < a.argc(); ++argpos)
    {
        if (!strcmp(a.argv()[argpos],"--prompt") ||
            !strcmp(a.argv()[argpos],"-p" ))
        {
            bPromptForBackend = true;
        }
        else if (!strcmp(a.argv()[argpos],"--disable-autodiscovery") ||
                 !strcmp(a.argv()[argpos],"-d" ))
        {
            bBypassAutoDiscovery = true;
        }
        else if (!strcmp(a.argv()[argpos],"-l") ||
            !strcmp(a.argv()[argpos],"--logfile"))
        {
            if (a.argc()-1 > argpos)
            {
                logfile = a.argv()[argpos+1];
                if (logfile.startsWith('-'))
                {
                    cerr << "Invalid or missing argument"
                            " to -l/--logfile option\n";
                    return GENERIC_EXIT_INVALID_CMDLINE;
                }
                else
                {
                    ++argpos;
                }
            }
            else
            {
                cerr << "Missing argument to -l/--logfile option\n";
                return GENERIC_EXIT_INVALID_CMDLINE;
            }
        }
        else if (cmdline.Parse(a.argc(), a.argv(), argpos, cmdline_err))
        {
            if (cmdline_err)
                return GENERIC_EXIT_INVALID_CMDLINE;
            if (cmdline.WantsToExit())
                return GENERIC_EXIT_OK;
        }
    }
    QMap<QString,QString> settingsOverride = cmdline.GetSettingsOverride();

    if (logfile.size())
    {
        if (log_rotate(1) < 0)
            cerr << "cannot open logfile; using stdout/stderr" << endl;
        else
        {
            VERBOSE(VB_IMPORTANT, QString("%1 version: %2 [%3] www.mythtv.org")
                                    .arg(MYTH_APPNAME_MYTHFRONTEND)
                                    .arg(MYTH_SOURCE_PATH)
                                    .arg(MYTH_SOURCE_VERSION));

            signal(SIGHUP, &log_rotate_handler);
        }
    }

    if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
        cerr << "Unable to ignore SIGPIPE\n";

    if (!cmdline.GetDisplay().isEmpty())
    {
        MythUIHelper::SetX11Display(cmdline.GetDisplay());
    }

    if (!cmdline.GetGeometry().isEmpty())
    {
        MythUIHelper::ParseGeometryOverride(cmdline.GetGeometry());
    }

    CleanupGuard callCleanup(cleanup);

    gContext = new MythContext(MYTH_BINARY_VERSION);

    if (cmdline.IsUPnPEnabled())
    {
        g_pUPnp  = new MediaRenderer();
        if (!g_pUPnp->initialized())
        {
            delete g_pUPnp;
            g_pUPnp = NULL;
        }
    }

    // Override settings as early as possible to cover bootstrapped screens
    // such as the language prompt
    settingsOverride = cmdline.GetSettingsOverride();
    if (settingsOverride.size())
    {
        QMap<QString, QString>::iterator it;
        for (it = settingsOverride.begin(); it != settingsOverride.end(); ++it)
        {
            VERBOSE(VB_IMPORTANT, QString("Setting '%1' being forced to '%2'")
                                          .arg(it.key()).arg(*it));
            gCoreContext->OverrideSettingForSession(it.key(), *it);
        }
    }

    if (!gContext->Init(true, bPromptForBackend, bBypassAutoDiscovery))
    {
        VERBOSE(VB_IMPORTANT, "Failed to init MythContext, exiting.");
        return GENERIC_EXIT_NO_MYTHCONTEXT;
    }

    if (!GetMythDB()->HaveSchema())
    {
        if (!InitializeMythSchema())
            return GENERIC_EXIT_DB_ERROR;
    }

    for(int argpos = 1; argpos < a.argc(); ++argpos)
    {
        if (!strcmp(a.argv()[argpos],"-l") ||
            !strcmp(a.argv()[argpos],"--logfile"))
        {
            // Arg processing for logfile already done (before MythContext)
            ++argpos;
        } else if (!strcmp(a.argv()[argpos],"-v") ||
                   !strcmp(a.argv()[argpos],"--verbose"))
        {
            // Arg processing for verbose already done (before MythContext)
            ++argpos;
        }
        else if (!strcmp(a.argv()[argpos],"-r") ||
                 !strcmp(a.argv()[argpos],"--reset"))
        {
            ResetSettings = true;
        }
        else if (!strcmp(a.argv()[argpos],"--prompt") ||
                 !strcmp(a.argv()[argpos],"-p" ))
        {
        }
        else if (!strcmp(a.argv()[argpos],"--disable-autodiscovery") ||
                 !strcmp(a.argv()[argpos],"-d" ))
        {
        }
        else if (!strcmp(a.argv()[argpos],"--upgrade-schema") ||
                 !strcmp(a.argv()[argpos],"-u" ))
        {
            upgradeAllowed = true;
        }
        else if (cmdline.Parse(a.argc(), a.argv(), argpos, cmdline_err))
        {
            if (cmdline_err)
            {
                return GENERIC_EXIT_INVALID_CMDLINE;
            }

            if (cmdline.WantsToExit())
            {
                return GENERIC_EXIT_OK;
            }
        }
        else if ((argpos + 1 == a.argc()) &&
                 (!QString(a.argv()[argpos]).startsWith('-')))
        {
            pluginname = a.argv()[argpos];
        }
        else
        {
            cerr << "Invalid argument: " << a.argv()[argpos] << endl;
            ShowUsage(cmdline);
            return GENERIC_EXIT_INVALID_CMDLINE;
        }
    }

    QStringList settingsQuery = cmdline.GetSettingsQuery();
    if (!settingsQuery.empty())
    {
        QStringList::const_iterator it = settingsQuery.begin();
        for (; it != settingsQuery.end(); ++it)
        {
            QString value = gCoreContext->GetSetting(*it);
            QString out = QString("\tSettings Value : %1 = %2")
                .arg(*it).arg(value);
            cout << out.toLocal8Bit().constData() << endl;
        }
        return GENERIC_EXIT_OK;
    }

    QString fileprefix = GetConfDir();

    QDir dir(fileprefix);
    if (!dir.exists())
        dir.mkdir(fileprefix);

    if (ResetSettings)
    {
        AppearanceSettings as;
        as.Save();

        gCoreContext->SaveSetting("Theme", DEFAULT_UI_THEME);
        gCoreContext->SaveSetting("Language", "");
        gCoreContext->SaveSetting("Country", "");

        return GENERIC_EXIT_OK;
    }

    setuid(getuid());

    VERBOSE(VB_IMPORTANT,
            QString("Enabled verbose msgs: %1").arg(verboseString));

    LCD::SetupLCD();
    if (LCD *lcd = LCD::Get())
        lcd->setupLEDs(RemoteGetRecordingMask);

    MythTranslation::load("mythfrontend");

    QString themename = gCoreContext->GetSetting("Theme", DEFAULT_UI_THEME);

    QString themedir = GetMythUI()->FindThemeDir(themename);
    if (themedir.isEmpty())
    {
        VERBOSE(VB_IMPORTANT, QString("Couldn't find theme '%1'")
                .arg(themename));
        return GENERIC_EXIT_NO_THEME;
    }

    GetMythUI()->LoadQtConfig();

    themename = gCoreContext->GetSetting("Theme", DEFAULT_UI_THEME);
    themedir = GetMythUI()->FindThemeDir(themename);
    if (themedir.isEmpty())
    {
        VERBOSE(VB_IMPORTANT, QString("Couldn't find theme '%1'")
                .arg(themename));
        return GENERIC_EXIT_NO_THEME;
    }

    MythMainWindow *mainWindow = GetMythMainWindow();
    mainWindow->Init();
    mainWindow->setWindowTitle(QObject::tr("MythTV Frontend"));

    // We must reload the translation after a language change and this
    // also means clearing the cached/loaded theme strings, so reload the
    // theme which also triggers a translation reload
    if (LanguageSelection::prompt())
    {
        if (!reloadTheme())
            return GENERIC_EXIT_NO_THEME;
    }

    if (!UpgradeTVDatabaseSchema(upgradeAllowed))
    {
        VERBOSE(VB_IMPORTANT,
                "Couldn't upgrade database to new schema, exiting.");
        return GENERIC_EXIT_DB_OUTOFDATE;
    }

    WriteDefaults();

    // Refresh Global/Main Menu keys after DB update in case there was no DB
    // when they were written originally
    mainWindow->ResetKeys();

    InitJumpPoints();

    internal_media_init();

    CleanupMyOldInUsePrograms();

    pmanager = new MythPluginManager();
    gContext->SetPluginManager(pmanager);

    if (pluginname.size())
    {
        if (pmanager->run_plugin(pluginname) ||
            pmanager->run_plugin("myth" + pluginname))
        {
            qApp->exec();

            return GENERIC_EXIT_OK;
        }
        else
            return GENERIC_EXIT_INVALID_CMDLINE;
    }

    MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
    if (mon)
    {
        mon->StartMonitoring();
        mainWindow->installEventFilter(mon);
    }

    NetworkControl *networkControl = NULL;
    if (gCoreContext->GetNumSetting("NetworkControlEnabled", 0))
    {
        int networkPort = gCoreContext->GetNumSetting("NetworkControlPort", 6545);
        networkControl = new NetworkControl();
        if (!networkControl->listen(QHostAddress::Any,networkPort))
            VERBOSE(VB_IMPORTANT,
                    QString("NetworkControl failed to bind to port %1.")
                    .arg(networkPort));
    }

#ifdef __linux__
#ifdef CONFIG_BINDINGS_PYTHON
    HardwareProfile *profile = new HardwareProfile();
    if (profile && profile->NeedsUpdate())
        profile->SubmitProfile();
    delete profile;
#endif
#endif

    if (!RunMenu(themedir, themename) && !resetTheme(themedir, themename))
    {
        return GENERIC_EXIT_NO_THEME;
    }

#ifndef _MSC_VER
    // Setup handler for USR1 signals to reload theme
    signal(SIGUSR1, &signal_USR1_handler);
    // Setup handler for USR2 signals to restart LIRC
    signal(SIGUSR2, &signal_USR2_handler);
#endif
    ThemeUpdateChecker *themeUpdateChecker = NULL;
    if (gCoreContext->GetNumSetting("ThemeUpdateNofications", 1))
        themeUpdateChecker = new ThemeUpdateChecker();

    MythSystemEventHandler *sysEventHandler = new MythSystemEventHandler();
    GetMythMainWindow()->RegisterSystemEventHandler(sysEventHandler);

    BackendConnectionManager bcm;

    PreviewGeneratorQueue::CreatePreviewGeneratorQueue(
        PreviewGenerator::kRemote, 50, 60);

    int ret = qApp->exec();

    PreviewGeneratorQueue::TeardownPreviewGeneratorQueue();

    if (themeUpdateChecker)
        delete themeUpdateChecker;

    delete sysEventHandler;

    pmanager->DestroyAllPlugins();

    if (mon)
        mon->deleteLater();

    delete networkControl;

    DestroyMythMainWindow();

    return ret;

}