示例#1
0
void NewFormWidget::loadFrom(const QString &path, bool resourceFile, const QString &uiExtension,
                       const QString &selectedItem, QTreeWidgetItem *&selectedItemFound)
{
    const QDir dir(path);

    if (!dir.exists())
        return;

    // Iterate through the directory and add the templates
    const QFileInfoList list = dir.entryInfoList(QStringList(QLatin1String("*.") + uiExtension),
                                                 QDir::Files);

    if (list.isEmpty())
        return;

    const QChar separator = resourceFile ? QChar(QLatin1Char('/'))
                                         : QDir::separator();
    QTreeWidgetItem *root = new QTreeWidgetItem(m_ui->treeWidget);
    root->setFlags(root->flags() & ~Qt::ItemIsSelectable);
    // Try to get something that is easy to read.
    QString visiblePath = path;
    int index = visiblePath.lastIndexOf(separator);
    if (index != -1) {
        // try to find a second slash, just to be a bit better.
        const int index2 = visiblePath.lastIndexOf(separator, index - 1);
        if (index2 != -1)
            index = index2;
        visiblePath = visiblePath.mid(index + 1);
        visiblePath = QDir::toNativeSeparators(visiblePath);
    }

    const QChar underscore = QLatin1Char('_');
    const QChar blank = QLatin1Char(' ');
    root->setText(0, visiblePath.replace(underscore, blank));
    root->setToolTip(0, path);

    const QFileInfoList::const_iterator lcend = list.constEnd();
    for (QFileInfoList::const_iterator it = list.constBegin(); it != lcend; ++it) {
        if (!it->isFile())
            continue;

        QTreeWidgetItem *item = new QTreeWidgetItem(root);
        const QString text = it->baseName().replace(underscore, blank);
        if (selectedItemFound == 0 && text == selectedItem)
            selectedItemFound = item;
        item->setText(0, text);
        item->setData(0, TemplateNameRole, it->absoluteFilePath());
    }
}
// find default skins (resources)
static const Skins &defaultSkins() {
    static Skins rc;
    if (rc.empty()) {
        const QString skinPath = QLatin1String(skinResourcePathC);
        QString pattern = QLatin1String("*.");
        pattern += QLatin1String(skinExtensionC);
        const QDir dir(skinPath, pattern);
        const QFileInfoList list = dir.entryInfoList(QDir::Dirs|QDir::NoDotAndDotDot, QDir::Name);
        if (list.empty())
            return rc;
        const QFileInfoList::const_iterator lcend = list.constEnd();
        for (QFileInfoList::const_iterator it = list.constBegin(); it != lcend; ++it)
            rc.push_back(SkinNamePath(it->baseName(), it->filePath()));
    }
    return rc;
}
示例#3
0
QMap<QString, QString> QgsComposerManager::defaultTemplates() const
{
  QMap<QString, QString> templateMap;

  //search for default templates in $pkgDataPath/composer_templates
  QDir defaultTemplateDir( QgsApplication::pkgDataPath() + "/composer_templates" );
  if ( !defaultTemplateDir.exists() )
  {
    return templateMap;
  }

  QFileInfoList fileInfoList = defaultTemplateDir.entryInfoList( QDir::Files );
  QFileInfoList::const_iterator infoIt = fileInfoList.constBegin();
  for ( ; infoIt != fileInfoList.constEnd(); ++infoIt )
  {
    templateMap.insert( infoIt->baseName(), infoIt->absoluteFilePath() );
  }
  return templateMap;
}
示例#4
0
QMap<QString, QString> QgsComposerManager::defaultTemplates( bool fromUser ) const
{
  QMap<QString, QString> templateMap;

  //search for default templates in $pkgDataPath/composer_templates
  // user templates in $qgisSettingsDirPath/composer_templates
  QDir defaultTemplateDir( fromUser ? mUserTemplatesDir : mDefaultTemplatesDir );
  if ( !defaultTemplateDir.exists() )
  {
    return templateMap;
  }

  QFileInfoList fileInfoList = defaultTemplateDir.entryInfoList( QDir::Files );
  QFileInfoList::const_iterator infoIt = fileInfoList.constBegin();
  for ( ; infoIt != fileInfoList.constEnd(); ++infoIt )
  {
    templateMap.insert( infoIt->baseName(), infoIt->absoluteFilePath() );
  }
  return templateMap;
}
示例#5
0
// search local database for discID
bool Dbase::Search(Cddb::Matches& res, const Cddb::discid_t discID)
{
    res.matches.clear();
    res.discID = discID;

    if (CacheGet(res, discID))
        return true;

    QFileInfoList list = QDir(GetDB()).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
    for (QFileInfoList::const_iterator it = list.begin(); it != list.end(); ++it)
    {
        QString genre = it->baseName();

        QFileInfoList ids = QDir(it->canonicalFilePath()).entryInfoList(QDir::Files);
        for (QFileInfoList::const_iterator it2 = ids.begin(); it2 != ids.end(); ++it2)
        {
            if (it2->baseName().toUInt(nullptr,16) == discID)
            {
                QFile file(it2->canonicalFilePath());
                if (file.open(QIODevice::ReadOnly | QIODevice::Text))
                {
                    Cddb::Album a(QTextStream(&file).readAll());
                    a.discGenre = genre;
                    a.discID = discID;
                    LOG(VB_MEDIA, LOG_INFO, QString("LocalCDDB found %1 in ").
                        arg(discID,0,16) + genre + " : " +
                        a.artist + " / " + a.title);

                    CachePut(a);
                    res.matches.push_back(Cddb::Match(genre,discID,a.artist,a.title));
                }

            }
        }
    }
    return res.matches.size() > 0;
}
// find default skins (resources)
static const Skins &defaultSkins() {
    static Skins rc;
    if (rc.empty()) {
#ifdef DEFAULT_SKINS_FROM_RESOURCE
        const QString skinPath = QLatin1String(skinResourcePathC);
#else
        QString skinPath = QLibraryInfo::location(QLibraryInfo::PrefixPath);
        skinPath += QDir::separator();
        skinPath += QLatin1String("tools");
        skinPath += QDir::separator();
        skinPath += QLatin1String("qvfb");
#endif
        QString pattern = QLatin1String("*.");
        pattern += QLatin1String(skinExtensionC);
        const QDir dir(skinPath, pattern);
        const QFileInfoList list = dir.entryInfoList();
        if (list.empty())
            return rc;
        const QFileInfoList::const_iterator lcend = list.constEnd();
        for (QFileInfoList::const_iterator it = list.constBegin(); it != lcend; ++it)
            rc.push_back(SkinNamePath(it->baseName(), it->filePath()));
    }
    return rc;
}