Esempio n. 1
0
static QRect spinBoxEditFieldRect(const QWidget* w, const QStyleOptionSpinBox& option)
{
	QRect r = w->style()->subControlRect(QStyle::CC_SpinBox, &option, QStyle::SC_SpinBoxEditField);
	if (isOxygenStyle(w))
	{
		int xadjust = (KDE::version() >= KDE_MAKE_VERSION(4,6,0)) ? 3 : 2;
		r.adjust(xadjust, 2, -xadjust, -2);
	}
	return r;
}
Esempio n. 2
0
void SpinMirror::setFrame()
{
	// Paint the left hand frame of the main spinbox.
	// Use the part to the left of the edit field, plus a slice at
	// the left of the edit field stretched for the rest of the width.
	// This avoids possibly grabbing text and displaying it in the
	// spin button area.
	QGraphicsScene* c = scene();
	QStyleOptionSpinBox option;
	option.initFrom(mMainSpinbox);
	QRect r = spinBoxEditFieldRect(mMainSpinbox, option);
	bool rtl = QApplication::isRightToLeft();
	QPixmap p;
	if (mMirrored)
	{
		int x = rtl ? 0 : mMainSpinbox->width() - width();
		p = grabWidget(mMainSpinbox, QRect(x, 0, width(), height()));
	}
	else
	{
		// Grab a single pixel wide vertical slice through the main spinbox, between the
		// frame and edit field.
		bool oxygen  = mMainSpinbox->style()->inherits("Oxygen::Style"); // KDE >= 4.4 Oxygen style
		bool oxygen1 = mMainSpinbox->style()->inherits("OxygenStyle");   // KDE <= 4.3 Oxygen style
		int editOffsetY = oxygen ? 5 : oxygen1 ? 6 : 2;   // offset to edit field
		int editOffsetX = (oxygen || oxygen1) ? (KDE::version() >= KDE_MAKE_VERSION(4,6,0) ? 4 : 2) : 2;   // offset to edit field
		int x = rtl ? r.right() - editOffsetX : r.left() + editOffsetX;
		p = grabWidget(mMainSpinbox, QRect(x, 0, 1, height()));
		// Blot out edit field stuff from the middle of the slice
		QPixmap dot = grabWidget(mMainSpinbox, QRect(x, editOffsetY, 1, 1));
		QPainter painter(&p);
		painter.drawTiledPixmap(0, editOffsetY, 1, height() - 2*editOffsetY, dot, 0, 0);
		painter.end();
		// Horizontally fill the mirror widget with the vertical slice
		p = p.scaled(size());
		// Grab the left hand border of the main spinbox, and draw it into the mirror widget.
		QRect endr = rect();
		if (rtl)
		{
			int mr = mMainSpinbox->width() - 1;
			endr.setWidth(mr - r.right() + editOffsetX);
			endr.moveRight(mr);
		}
		else
			endr.setWidth(r.left() + editOffsetX);
		x = rtl ? width() - endr.width() : 0;
		mMainSpinbox->render(&p, QPoint(x, 0), endr, QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask);
	}
	c->setBackgroundBrush(p);
}
Esempio n. 3
0
void KMimeTypeTest::testPatterns_data()
{
    QTest::addColumn<QString>("mimeType");
    QTest::addColumn<QString>("patterns");
    QTest::addColumn<QString>("mainExtension");
    QTest::newRow("mimetype with a single pattern") << "application/pdf" << "*.pdf" << ".pdf";
    QTest::newRow("mimetype with multiple patterns") << "application/x-kpresenter" << "*.kpr;*.kpt" << ".kpr";
    if (KMimeType::sharedMimeInfoVersion() > KDE_MAKE_VERSION(0, 60, 0)) {
        QTest::newRow("mimetype with many patterns") << "application/vnd.wordperfect" << "*.wp;*.wp4;*.wp5;*.wp6;*.wpd;*.wpp" << ".wp";
    }
    QTest::newRow("oasis text mimetype") << "application/vnd.oasis.opendocument.text" << "*.odt" << ".odt";
    QTest::newRow("oasis presentation mimetype") << "application/vnd.oasis.opendocument.presentation" << "*.odp" << ".odp";
    QTest::newRow("mimetype with multiple patterns, *.doc added by kde") << "text/plain" << "*.asc;*.txt;*.doc;*,v" << ".txt";
    QTest::newRow("mimetype with uncommon pattern") << "application/x-kcachegrind" << "callgrind.out*;cachegrind.out*" << QString();
    QTest::newRow("mimetype with no patterns") << "application/x-ole-storage" << QString() << QString();
}
Esempio n. 4
0
void KMimeTypeTest::testFindByPathUsingFileName_data()
{
    QTest::addColumn<QString>("fileName");
    QTest::addColumn<QString>("expectedMimeType");
    // Maybe we could also add a expectedAccuracy column...

    QTest::newRow("text") << "textfile.txt" << "text/plain";
    QTest::newRow("case-insensitive search") << "textfile.TxT" << "text/plain";
    // With QMime, this needs shared-mime-info > 0.91. Earlier versions wrote .Z to the mime.cache file...
    if (KMimeType::sharedMimeInfoVersion() > KDE_MAKE_VERSION(0, 91, 0)) {
        QTest::newRow("case-insensitive match on a non-lowercase glob") << "foo.z" << "application/x-compress";
    }

    QTest::newRow("case-sensitive uppercase match") << "textfile.C" << "text/x-c++src";
    QTest::newRow("case-sensitive lowercase match") << "textfile.c" << "text/x-csrc";
    QTest::newRow("case-sensitive long-extension match") << "foo.PS.gz" << "application/x-gzpostscript";
    QTest::newRow("case-sensitive-only match") << "core" << "application/x-core";
    QTest::newRow("case-sensitive-only match") << "Core" << "application/octet-stream"; // #198477

    QTest::newRow("desktop file") << "foo.desktop" << "application/x-desktop";
    QTest::newRow("old kdelnk file is x-desktop too") << "foo.kdelnk" << "application/x-desktop";
    QTest::newRow("double-extension file") << "foo.tar.bz2" << "application/x-bzip-compressed-tar";
    QTest::newRow("single-extension file") << "foo.bz2" << "application/x-bzip";
    QTest::newRow(".doc should assume msword") << "somefile.doc" << "application/msword"; // #204139
    QTest::newRow("glob that uses [] syntax, 1") << "Makefile" << "text/x-makefile";
    QTest::newRow("glob that uses [] syntax, 2") << "makefile" << "text/x-makefile";
    QTest::newRow("glob that ends with *, no extension") << "README" << "text/x-readme";
    QTest::newRow("glob that ends with *, extension") << "README.foo" << "text/x-readme";
    QTest::newRow("glob that ends with *, also matches *.txt. Higher weight wins.") << "README.txt" << "text/plain";
    QTest::newRow("glob that ends with *, also matches *.nfo. Higher weight wins.") << "README.nfo" << "text/x-nfo";
    // fdo bug 15436, needs shared-mime-info >= 0.40 (and this tests the globs2-parsing code).
    QTest::newRow("glob that ends with *, also matches *.pdf. *.pdf has higher weight") << "README.pdf" << "application/pdf";
    QTest::newRow("directory") << "/" << "inode/directory";
    QTest::newRow("doesn't exist, no extension") << "IDontExist" << "application/octet-stream";
    QTest::newRow("doesn't exist but has known extension") << "IDontExist.txt" << "text/plain";
    QTest::newRow("png image") << QFINDTESTDATA("image.png") << "image/png";

    const QString exePath = QStandardPaths::findExecutable("cmake");
    QVERIFY2(!exePath.isEmpty(), "cmake not found. Isn't it in your $PATH?");
#ifdef Q_OS_WIN
    const QString executableType = QString::fromLatin1("application/x-ms-dos-executable");
#else
    const QString executableType = QString::fromLatin1("application/x-executable");
#endif
    QTest::newRow("executable") << exePath << executableType;
}
Esempio n. 5
0
    void testLoadMimeTypeIcon_data()
    {
        QTest::addColumn<QString>("iconName");
        QTest::addColumn<QString>("expectedFileName");

        QTest::newRow("existing icon") << "text-plain" << "text-plain.png";
        QTest::newRow("octet-stream icon") << "application-octet-stream" << "application-octet-stream.png";
        QTest::newRow("non-existing icon") << "foo-bar" << "application-octet-stream.png";
        // Test this again, because now we won't go into the "fast path" of loadMimeTypeIcon anymore.
        QTest::newRow("existing icon again") << "text-plain" << "text-plain.png";
        QTest::newRow("generic fallback") << "image-foo-bar" << "image-x-generic.png";
        QTest::newRow("video generic fallback") << "video-foo-bar" << "video-x-generic.png";
        QTest::newRow("image-x-generic itself") << "image-x-generic" << "image-x-generic.png";
        QTest::newRow("x-office-document icon") << "x-office-document" << "x-office-document.png";
        QTest::newRow("unavailable generic icon") << "application/x-font-vfont" << "application-octet-stream.png";
        QTest::newRow("#184852") << "audio/x-tuxguitar" << "audio-x-generic.png";
        QTest::newRow("#178847") << "image/x-compressed-xcf" << "image-x-generic.png";

        if (sharedMimeInfoVersion >= KDE_MAKE_VERSION(0, 40, 0)) {
            QTest::newRow("mimetype generic icon") << "application-x-fluid" << "x-office-document.png";
        }
    }
bool SharedMimeInfoVersion::supportsIcon()
{
    return KMimeType::sharedMimeInfoVersion() >= KDE_MAKE_VERSION(0, 40, 0);
}
Esempio n. 7
0
// uses a QIODevice to make unit tests possible
bool KMimeGlobsFileParser::parseGlobFile(QIODevice* file, Format format, AllGlobs& globs)
{
    if (!file->open(QIODevice::ReadOnly))
        return false;

    // If we're not going to get the "cs" flag because smi is too old, then we need to emulate it for *.C at least.
    const bool caseSensitiveHackNeeded = (KMimeType::sharedMimeInfoVersion() <= KDE_MAKE_VERSION(0, 60, 0));

    QTextStream stream(file);
    //stream.setCodec("UTF-8"); // should be all latin1
    QString lastMime, lastPattern;
    QString line;
    while (!stream.atEnd()) {
        line = stream.readLine();
        if (line.isEmpty() || line.startsWith(QLatin1Char('#')))
            continue;

        const QStringList fields = line.split(QLatin1Char(':'), QString::KeepEmptyParts);
        if (fields.count() < 2) // syntax error
            continue;

        //kDebug() << "line=" << line;

        QString mimeTypeName, pattern;
        QStringList flagList;
        int weight = 50;
        if (format == Globs2WithWeight) {
            if (fields.count() < 3) // syntax error
                continue;
            weight = fields[0].toInt();
            mimeTypeName = fields[1];
            pattern = fields[2];
            const QString flagsStr = fields.value(3); // could be empty
            flagList = flagsStr.split(QLatin1Char(','), QString::SkipEmptyParts);
        } else {
            mimeTypeName = fields[0];
            pattern = fields[1];
        }
        Q_ASSERT(!pattern.isEmpty());
        Q_ASSERT(!pattern.contains(QLatin1Char(':')));

        //kDebug() << " got:" << mimeTypeName << pattern;

        if (lastMime == mimeTypeName && lastPattern == pattern) {
            // Ignore duplicates, especially important for those with no flags after a line with flags:
            // 50:text/x-csrc:*.c:cs
            // 50:text/x-csrc:*.c
            continue;
        }

        bool caseSensitive = flagList.contains(QLatin1String("cs"));

        if (caseSensitiveHackNeeded && (pattern == QLatin1String("*.C") || pattern == QLatin1String("*.c") || pattern == QLatin1String("core")))
            caseSensitive = true;

        if (pattern == QLatin1String("__NOGLOBS__")) {
            //kDebug() << "removing" << mimeTypeName;
            globs.removeMime(mimeTypeName);
            lastMime.clear();
        } else {
            int flags = 0;
            if (caseSensitive)
                flags = KMimeTypeRepository::CaseSensitive;

            //if (mimeTypeName == "text/plain")
            //    kDebug() << "Adding pattern" << pattern << "to mimetype" << mimeTypeName << "from globs file, with weight" << weight;
            //if (pattern.toLower() == "*.c")
            //    kDebug() << " Adding pattern" << pattern << "to mimetype" << mimeTypeName << "from globs file, with weight" << weight << "flags" << flags;
            globs.addGlob(Glob(mimeTypeName, weight, pattern, flags));
            lastMime = mimeTypeName;
            lastPattern = pattern;
        }
    }
    return true;
}