void MfSession::setup()
{
    if (!setupInProgress.testAndSetAcquire(0, 1)) {
        // If a session setup is in progress wait some time
        QTimer::singleShot(10, this, SLOT(setup()));
        return;
    }

    MfManager *manager = MfManager::instance();
    QVector<QStringList> feedbackDirLists = getFeedbackDirLists(manager->currentTheme(), appName);
    QStringList feedbackDirs;

    for (int i = 0; i < feedbackDirLists.size(); ++i) {
        feedbackDirs << feedbackDirLists[i][0];
    }

    if (feedbackDirLists.isEmpty()) {
        // Can't live without feedbacks
        qFatal("It is not possible to load any feedbacks.");
    }

    // Map the feedbacks
    foreach (const QStringList& feedbackDirList, feedbackDirLists) {
        MfFeedback *feedback = new MfFeedback(this);
        feedback->load(feedbackDirList);
        feedbackHash[feedback->name()] = feedback;
    }
Esempio n. 2
0
void Application::cleanup()
{
    // cleanup() can be called multiple times during shutdown. We only need it once.
    static QAtomicInt alreadyDone;
    if (!alreadyDone.testAndSetAcquire(0, 1))
        return;

#ifndef DISABLE_GUI
    if (m_window) {
        // Hide the window and don't leave it on screen as
        // unresponsive. Also for Windows take the WinId
        // after it's hidden, because hide() may cause a
        // WinId change.
        m_window->hide();

#ifdef Q_OS_WIN
        typedef BOOL (WINAPI *PSHUTDOWNBRCREATE)(HWND, LPCWSTR);
        const auto shutdownBRCreate = Utils::Misc::loadWinAPI<PSHUTDOWNBRCREATE>("User32.dll", "ShutdownBlockReasonCreate");
        // Only available on Vista+
        if (shutdownBRCreate)
            shutdownBRCreate((HWND)m_window->effectiveWinId(), tr("Saving torrent progress...").toStdWString().c_str());
#endif // Q_OS_WIN

        // Do manual cleanup in MainWindow to force widgets
        // to save their Preferences, stop all timers and
        // delete as many widgets as possible to leave only
        // a 'shell' MainWindow.
        // We need a valid window handle for Windows Vista+
        // otherwise the system shutdown will continue even
        // though we created a ShutdownBlockReason
        m_window->cleanup();
    }
#endif // DISABLE_GUI

#ifndef DISABLE_WEBUI
    delete m_webui;
#endif

    delete RSS::AutoDownloader::instance();
    delete RSS::Session::instance();

    ScanFoldersModel::freeInstance();
    BitTorrent::Session::freeInstance();
#ifndef DISABLE_COUNTRIES_RESOLUTION
    Net::GeoIPManager::freeInstance();
#endif
    Net::DownloadManager::freeInstance();
    Net::ProxyConfigurationManager::freeInstance();
    Preferences::freeInstance();
    SettingsStorage::freeInstance();
    delete m_fileLogger;
    Logger::freeInstance();
    IconProvider::freeInstance();
    SearchPluginManager::freeInstance();
    Utils::Fs::removeDirRecursive(Utils::Fs::tempPath());

#ifndef DISABLE_GUI
    if (m_window) {
#ifdef Q_OS_WIN
        typedef BOOL (WINAPI *PSHUTDOWNBRDESTROY)(HWND);
        const auto shutdownBRDestroy = Utils::Misc::loadWinAPI<PSHUTDOWNBRDESTROY>("User32.dll", "ShutdownBlockReasonDestroy");
        // Only available on Vista+
        if (shutdownBRDestroy)
            shutdownBRDestroy((HWND)m_window->effectiveWinId());
#endif // Q_OS_WIN
        delete m_window;
    }
#endif // DISABLE_GUI

    if (m_shutdownAct != ShutdownDialogAction::Exit) {
        qDebug() << "Sending computer shutdown/suspend/hibernate signal...";
        Utils::Misc::shutdownComputer(m_shutdownAct);
    }
}