Example #1
0
//
// <mapPathName>/<orbDirName>/<themeDirName>
//
void MapThemeManager::Private::addMapThemePaths( const QString& mapPathName, QStringList& result )
{
    QDir mapPath( mapPathName );
    QStringList orbDirNames = mapPath.entryList( QStringList( "*" ),
                              QDir::AllDirs
                              | QDir::NoSymLinks
                              | QDir::NoDotAndDotDot );
    QStringListIterator itOrb( orbDirNames );
    while ( itOrb.hasNext() ) {
        QString orbPathName = mapPathName + '/' + itOrb.next();
        result << orbPathName;

        QDir orbPath( orbPathName );
        QStringList themeDirNames = orbPath.entryList( QStringList( "*" ),
                                    QDir::AllDirs
                                    | QDir::NoSymLinks
                                    | QDir::NoDotAndDotDot );
        QStringListIterator itThemeDir( themeDirNames );
        while ( itThemeDir.hasNext() ) {
            QString themePathName = orbPathName + '/' + itThemeDir.next();
            result << themePathName;

            QDir themePath( themePathName );
            QStringList themeFileNames = themePath.entryList( QStringList( "*.dgml" ),
                                         QDir::Files
                                         | QDir::NoSymLinks );
            QStringListIterator itThemeFile( themeFileNames );
            while ( itThemeFile.hasNext() ) {
                QString themeFilePathName = themePathName + '/' + itThemeFile.next();
                result << themeFilePathName;
            }
        }
    }
}
Example #2
0
void GlobalOptionsDialog::open() {
	OptionsDialog::open();

#if !( defined(__DC__) || defined(__GP32__) || defined(__PLAYSTATION2__) )
	// Set _savePath to the current save path
	Common::String savePath(ConfMan.get("savepath", _domain));
	Common::String themePath(ConfMan.get("themepath", _domain));
	Common::String extraPath(ConfMan.get("extrapath", _domain));

	if (!savePath.empty()) {
		_savePath->setLabel(savePath);
	} else {
		// Default to the current directory...
		char buf[MAXPATHLEN];
		getcwd(buf, sizeof(buf));
		_savePath->setLabel(buf);
	}

	if (themePath.empty() || !ConfMan.hasKey("themepath", _domain)) {
		_themePath->setLabel("None");
	} else {
		_themePath->setLabel(themePath);
	}

	if (extraPath.empty() || !ConfMan.hasKey("extrapath", _domain)) {
		_extraPath->setLabel("None");
	} else {
		_extraPath->setLabel(extraPath);
	}
#endif
}
Example #3
0
void GlobalOptionsDialog::close() {
	if (getResult()) {
		// Savepath
		ConfMan.set("savepath", _savePath->getLabel(), _domain);

		String themePath(_themePath->getLabel());
		if (!themePath.empty() && (themePath != "None"))
			ConfMan.set("themepath", themePath, _domain);

		String extraPath(_extraPath->getLabel());
		if (!extraPath.empty() && (extraPath != "None"))
			ConfMan.set("extrapath", extraPath, _domain);
	}
	OptionsDialog::close();
}
bool IconCacheCreator::createCacheFile(const QString &cachePath, bool force) {
    QFileInfo themePath(m_path);

    if (!(themePath.exists() && themePath.isDir() && themePath.isReadable())) {
        DPRINT("theme path invaild.");
        return false;
    }

    QFile cacheFile(cachePath);

    if (cacheFile.exists()) {
        if (force) {
            cacheFile.remove();
        }
        else {
            DPRINT("cache file existed and can not force.");
            return false;
        }
    }


    if (!cacheFile.open(QIODevice::WriteOnly)) {
        DPRINT("can not open cache file: %s", qPrintable(cachePath));
        return false;
    }

    QFile indexFile(m_path + "/" + INDEX_FILE_NAME);

    if (!indexFile.open(QIODevice::ReadOnly)) {
        DPRINT("the index file of theme can not open.");
        return false;
    }

    QList<DirEntry *> dirEntryList;
    QSet<int> size;
    QSet<QString> cates;

    this->loadIndex(indexFile, dirEntryList, size, cates);

    QHash<QString, qint64> iconList;

    QStringList filters;
    filters.append("*.png");
    filters.append("*.xpm");
    filters.append("*.svg");

    QDataStream out(&cacheFile);
    out.setByteOrder(QDataStream::LittleEndian);
    QString keystr("%1-%2-%3");
    QString key;

    struct IconCache cache;

    out.writeRawData((const char *)&cache, sizeof(struct IconCache));

    cache.sizeHdr.num = size.size();
    cache.sizeHdr.sizes = out.device()->pos();

    this->writeSizeToCache(out, size.toList());

    cache.cateHdr.num = cates.size();
    cache.cateHdr.cates = cacheFile.pos();

    this->writeCatesToCache(out, cates.toList());

    for (int i = 0; i < dirEntryList.size(); i++) {
        if (dirEntryList.at(i) == NULL) {
            continue;
        }

        QDir dir(m_path);

        if (!dir.cd(dirEntryList.at(i)->path)) {
            DWARNING("theme subdir can not enter: %s", qPrintable(dirEntryList.at(i)->path));
            continue;
        }

        DPRINT("Dir in: %s", qPrintable(dir.canonicalPath()));
        QFileInfoList files = dir.entryInfoList(filters);

        for (int j = 0; j < files.size(); j++) {
            QFileInfo f = files.at(j);
            key = keystr.arg(QString::number(dirEntryList.at(i)->size), dirEntryList.at(i)->type, f.fileName());
            qint64 iconOffset = cacheFile.pos();

            if (!this->writeIconToCache(out, f)) {
                continue;
            }

            DPRINT("key: %s,%d", qPrintable(key), iconOffset);
            iconList.insert(key, iconOffset);
        }
    }

    DPRINT("Finished write icon data.");
    DPRINT("iconList: %d", iconList.size());
    cache.hashHdr.num = iconList.size();

    writeHashToCache(out, iconList, &(cache.hashHdr.data));

    DPRINT("Finished write hash data.");

    cacheFile.seek(0);
    DPRINT("%lld", cacheFile.size());
    out.writeRawData((const char *)&cache, sizeof(struct IconCache));
    DPRINT("%lld", cacheFile.size());

    if (out.byteOrder() == QDataStream::BigEndian) {
        DPRINT("big endian");
    }
    cacheFile.close();
    DPRINT("sizeof iconcahce: %d", sizeof(struct IconCache));
    DPRINT("Finished write head.");

    for (int i = 0; i < dirEntryList.size(); i++) {
        delete dirEntryList.at(i);
    }

    return true;
}
Example #5
0
bool StyledTTFont::loadFont(const Common::String &fontName, int32 point) {
	Common::String newFontName;
	if (fontName.matchString("*times new roman*", true) || fontName.matchString("*times*", true)) {
		if ((_style & (STTF_BOLD | STTF_ITALIC)) == (STTF_BOLD | STTF_ITALIC))
			newFontName = "timesbi.ttf";
		else if (_style & STTF_BOLD)
			newFontName = "timesbd.ttf";
		else if (_style & STTF_ITALIC)
			newFontName = "timesi.ttf";
		else
			newFontName = "times.ttf";

	} else if (fontName.matchString("*courier new*", true) || fontName.matchString("*courier*", true) || fontName.matchString("*ZorkDeath*", true)) {
		if ((_style & (STTF_BOLD | STTF_ITALIC)) == (STTF_BOLD | STTF_ITALIC))
			newFontName = "courbi.ttf";
		else if (_style & STTF_BOLD)
			newFontName = "courbd.ttf";
		else if (_style & STTF_ITALIC)
			newFontName = "couri.ttf";
		else
			newFontName = "cour.ttf";

	} else if (fontName.matchString("*century schoolbook*", true)) {
		if ((_style & (STTF_BOLD | STTF_ITALIC)) == (STTF_BOLD | STTF_ITALIC))
			newFontName = "censcbkbi.ttf";
		else if (_style & STTF_BOLD)
			newFontName = "censcbkbd.ttf";
		else if (_style & STTF_ITALIC)
			newFontName = "censcbki.ttf";
		else
			newFontName = "censcbk.ttf";

	} else if (fontName.matchString("*garamond*", true)) {
		if ((_style & (STTF_BOLD | STTF_ITALIC)) == (STTF_BOLD | STTF_ITALIC))
			newFontName = "garabi.ttf";
		else if (_style & STTF_BOLD)
			newFontName = "garabd.ttf";
		else if (_style & STTF_ITALIC)
			newFontName = "garai.ttf";
		else
			newFontName = "gara.ttf";

	} else if (fontName.matchString("*arial*", true) || fontName.matchString("*ZorkNormal*", true)) {
		if ((_style & (STTF_BOLD | STTF_ITALIC)) == (STTF_BOLD | STTF_ITALIC))
			newFontName = "arialbi.ttf";
		else if (_style & STTF_BOLD)
			newFontName = "arialbd.ttf";
		else if (_style & STTF_ITALIC)
			newFontName = "ariali.ttf";
		else
			newFontName = "arial.ttf";

	} else {
		debug("Could not identify font: %s. Reverting to Arial", fontName.c_str());
		newFontName = "arial.ttf";
	}

	bool sharp = (_style & STTF_SHARP) == STTF_SHARP;

	Common::File *file = _engine->getSearchManager()->openFile(newFontName);

	if (!file) {
		Common::SeekableReadStream *themeFile = nullptr;
		if (ConfMan.hasKey("themepath")) {
			Common::FSNode themePath(ConfMan.get("themepath"));
			if (themePath.exists()) {
				Common::FSNode scummModern = themePath.getChild("scummmodern.zip");
				if (scummModern.exists()) {
					themeFile = scummModern.createReadStream();
				}
			}
		}
		if (!themeFile) { // Fallback : Search for ScummModern.zip in SearchMan.
			themeFile = SearchMan.createReadStreamForMember("scummmodern.zip");
		}
		if (themeFile) {
			Common::Archive *themeArchive = Common::makeZipArchive(themeFile);
			if (themeArchive->hasFile("FreeSans.ttf")) {
				Common::SeekableReadStream *stream = nullptr;
				stream = themeArchive->createReadStreamForMember("FreeSans.ttf");
				Graphics::Font *_newFont = Graphics::loadTTFFont(*stream, point, 60, (sharp ? Graphics::kTTFRenderModeMonochrome : Graphics::kTTFRenderModeNormal)); // 66 dpi for 640 x 480 on 14" display
				if (_newFont) {
					if (!_font)
						delete _font;
					_font = _newFont;
				}
				if (stream)
					delete stream;
			}
			delete themeArchive;
			themeArchive = nullptr;
		}
	} else {
		Graphics::Font *_newFont = Graphics::loadTTFFont(*file, point, 60, (sharp ? Graphics::kTTFRenderModeMonochrome : Graphics::kTTFRenderModeNormal)); // 66 dpi for 640 x 480 on 14" display
		if (_newFont) {
			if (!_font)
				delete _font;
			_font = _newFont;
		}
		delete file;
	}

	_fntName = fontName;
	_lineHeight = point;

	if (_font)
		return true;
	return false;
}