aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/FileDialogs/TwoPanelFileDialog/twopanelfiledialogimpl.h
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2021-03-08 18:46:02 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2021-03-08 18:46:02 +0000
commitee5054a5e99dbb049a4bfe65c4a4297889117d6a (patch)
treeebc07b5a9d5649c4094300cdbdacb8fd967ab584 /src/plugins/FileDialogs/TwoPanelFileDialog/twopanelfiledialogimpl.h
parent75d525c88426040f9153ef704676a5ff92c4fcb6 (diff)
downloadqmmp-ee5054a5e99dbb049a4bfe65c4a4297889117d6a.tar.gz
qmmp-ee5054a5e99dbb049a4bfe65c4a4297889117d6a.tar.bz2
qmmp-ee5054a5e99dbb049a4bfe65c4a4297889117d6a.zip
fixed possible deadlock
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9750 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/FileDialogs/TwoPanelFileDialog/twopanelfiledialogimpl.h')
0 files changed, 0 insertions, 0 deletions
141'>141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
/***************************************************************************
 *   Copyright (C) 2013 by Ilya Kotov                                      *
 *   forkotov02@hotmail.ru                                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/

#include <QStringList>
#include <QDateTime>
#include <QFileInfo>
#include <QPluginLoader>
#include <QApplication>
#include <QTranslator>
#include "generalfactory.h"
#include "uifactory.h"
#include "filedialogfactory.h"
#include "qmmpuiplugincache_p.h"

QmmpUiPluginCache::QmmpUiPluginCache(const QString &file, QSettings *settings)
{
    m_error = false;
    m_instance = 0;
    m_generalFactory = 0;
    m_uiFactory = 0;
    m_fileDialogFactory = 0;
    m_priority = 0;
    bool update = false;
    QFileInfo info(file);
    m_path = info.QFileInfo::canonicalFilePath();

    settings->beginGroup("PluginCache");
    QString key = m_path;
#ifndef Q_OS_WIN
    key.remove(0,1);
#endif
    if(settings->allKeys().contains(key))

    {
        QStringList values = settings->value(m_path).toStringList();
        if(values.count() != 3)
            update = true;
        else
        {
            m_shortName = values.at(0);
            m_priority = values.at(1).toInt();
            update = (info.lastModified().toString(Qt::ISODate) != values.at(2));
        }
    }
    else
        update = true;


    if(update)
    {
        if(GeneralFactory *factory = generalFactory())
        {
            m_shortName = factory->properties().shortName;
            m_priority = 0;
        }
        else if(UiFactory *factory = uiFactory())
        {
            m_shortName = factory->properties().shortName;
            m_priority = 0;
        }
        else if(FileDialogFactory *factory = fileDialogFactory())
        {
            m_shortName = factory->properties().shortName;
            m_priority = 0;
        }
        else
        {
            qWarning("QmmpUiPluginCache: unknown plugin type: %s", qPrintable(m_path));
            m_error = true;
        }

        if (!m_error)
        {
            QStringList values;
            values << m_shortName;
            values << QString::number(m_priority);
            values << info.lastModified().toString(Qt::ISODate);
            settings->setValue(m_path, values);
            qDebug("QmmpUiPluginCache: added cache item \"%s=%s\"",
                   qPrintable(info.fileName()), qPrintable(values.join(",")));
        }
    }
    settings->endGroup();
}

QmmpUiPluginCache::QmmpUiPluginCache(QObject *instance)
{
    m_error = false;
    m_instance = instance;
    m_generalFactory = 0;
    m_uiFactory = 0;
    m_fileDialogFactory = 0;
    m_priority = 0;

    if(GeneralFactory *factory = generalFactory())
    {
        m_shortName = factory->properties().shortName;
        m_priority = 0;
    }
    else if(UiFactory *factory = uiFactory())
    {
        m_shortName = factory->properties().shortName;
        m_priority = 0;
    }
    else if(FileDialogFactory *factory = fileDialogFactory())
    {
        m_shortName = factory->properties().shortName;
        m_priority = 0;
    }
    else
    {
        qWarning("QmmpUiPluginCache: unknown plugin type");
        m_error = true;
        return;
    }
    qDebug("QmmpUiPluginCache: registered internal factory %s", qPrintable(m_shortName));
}

const QString QmmpUiPluginCache::shortName() const
{
    return m_shortName;
}

const QString QmmpUiPluginCache::file() const
{
    return m_path;
}

int QmmpUiPluginCache::priority() const
{
    return m_priority;
}

bool QmmpUiPluginCache::hasError() const
{
    return m_error;
}

GeneralFactory *QmmpUiPluginCache::generalFactory()
{
    if(!m_generalFactory)
    {
        m_generalFactory = qobject_cast<GeneralFactory *> (instance());
        if(m_generalFactory)
            qApp->installTranslator(m_generalFactory->createTranslator(qApp));
    }
    return m_generalFactory;
}

UiFactory *QmmpUiPluginCache::uiFactory()
{
    if(!m_uiFactory)
    {
        m_uiFactory = qobject_cast<UiFactory *> (instance());
        if(m_uiFactory)
            qApp->installTranslator(m_uiFactory->createTranslator(qApp));
    }
    return m_uiFactory;
}

FileDialogFactory *QmmpUiPluginCache::fileDialogFactory()
{
    if(!m_fileDialogFactory)
    {
        m_fileDialogFactory = qobject_cast<FileDialogFactory *> (instance());
        if(m_fileDialogFactory)
            qApp->installTranslator(m_fileDialogFactory->createTranslator(qApp));
    }
    return m_fileDialogFactory;
}

QObject *QmmpUiPluginCache::instance()
{
    if(m_error)
        return 0;
    if(m_instance)
        return m_instance;
    QPluginLoader loader(m_path);
    m_instance = loader.instance();
    if (loader.isLoaded())
        qDebug("QmmpUiPluginCache: loaded plugin %s", qPrintable(QFileInfo(m_path).fileName()));
    else
    {
        m_error = true;
        qWarning("QmmpUiPluginCache: error: %s", qPrintable(loader.errorString ()));
    }
    return m_instance;
}

void QmmpUiPluginCache::cleanup(QSettings *settings)
{