SplashWindow::SplashWindow(bool testing)
    : QDeclarativeView(),
      m_stage(0),
      m_testing(testing)
{
    setWindowFlags(
            Qt::FramelessWindowHint |
            Qt::WindowStaysOnTopHint
        );

    if (m_testing) {
        setWindowState(Qt::WindowFullScreen);
    } else {
        setWindowFlags(Qt::X11BypassWindowManagerHint);
    }

    rootContext()->setContextProperty("screenSize", size());
    setSource(QUrl(themeDir(QApplication::arguments().at(1)) + "/main.qml"));
    setStyleSheet("background: #000000; border: none");
    setAttribute(Qt::WA_OpaquePaintEvent);
    setAttribute(Qt::WA_NoSystemBackground);
    //be sure it will be eventually closed
    //FIXME: should never be stuck
    QTimer::singleShot(30000, this, SLOT(close()));
}
void KTThemeSelector::saveSchema()
{
	QDir themeDir(CONFIG_DIR+"/themes");
	if ( ! themeDir.exists() )
	{
		themeDir.mkdir(themeDir.path());
	}
	
	QString fileName = QInputDialog::getText (this,tr("Name"), tr("Please choose a theme name"));
	
	if ( !fileName.endsWith(".ktt"))
	{
		fileName += ".ktt";
	}
	
	QFile file(themeDir.path()+"/"+fileName);
	
	if (file.open(QIODevice::WriteOnly ) )
	{
		QTextStream stream( &file );
		stream << document().toString() << endl;
		file.close();
		m_lastFile = themeDir.path()+"/"+fileName;
	}
	loadSchemes();
}
Exemple #3
0
ThemeManager::ThemeManager(QWidget* parent)
    : QWidget()
    , ui(new Ui::ThemeManager)
{
    ui->setupUi(parent);
    ui->license->hide();

    Settings settings;
    settings.beginGroup("Themes");
    m_activeTheme = settings.value("activeTheme", DEFAULT_THEME_NAME).toString();
    settings.endGroup();

    QDir themeDir(mApp->THEMESDIR);
    QStringList list = themeDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
    foreach(QString name, list) {
        Theme themeInfo = parseTheme(name);
        if (!themeInfo.isValid) {
            continue;
        }

        QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
        item->setText(themeInfo.name + "\n" + themeInfo.shortDescription);
        item->setIcon(themeInfo.icon);
        item->setData(Qt::UserRole, name);

        if (m_activeTheme == name) {
            ui->listWidget->setCurrentItem(item);
        }

        ui->listWidget->addItem(item);
    }
Exemple #4
0
void TupThemeSelector::loadSchemes()
{
    QDir themeDir(SHARE_DIR + "themes");
    
    if (themeDir.exists()) {
        m_allSchemes->clear();
        QFileInfoList files = themeDir.entryInfoList(QStringList() <<"*.tupt");
        
        for (int i = 0; i < files.count(); i++) {
             QFileInfo iterator = files[i];
             QTreeWidgetItem *item = new QTreeWidgetItem(m_allSchemes);
             item->setText(0, iterator.fileName());
             item->setText(1, iterator.owner());
             item->setText(2, iterator.created().toString());
        }
    }
}
Exemple #5
0
void LnfLogic::processThumbnail(const QString &path)
{
    if (path.isEmpty()) {
        return;
    }

    QDir themeDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) % QLatin1Literal("/plasma/look-and-feel/") % m_themeName);
    if (!themeDir.mkpath("contents/previews")) {
        qWarning() << "Impossible to create the layouts directory in the look and feel package";
    }

    QFile imageFile(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) % QLatin1Literal("/plasma/look-and-feel/") % m_themeName % QLatin1Literal("/contents/previews/preview.png"));
    if (!imageFile.open(QIODevice::WriteOnly)) {
        qWarning() << "Impossible to write to the thumbnail file";
        return;
    }

    QImage image(QUrl(path).path());
    if (image.isNull()) {
        qWarning() << "invalid image";
        return;
    }
    image = image.scaledToWidth(512, Qt::SmoothTransformation);

    image.save(&imageFile, "PNG"); // writes image into ba in PNG format
    imageFile.close();

    //copy the fullscreen preview
    QFile fullScreenImageFile(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) % QLatin1Literal("/plasma/look-and-feel/") % m_themeName % QLatin1Literal("/contents/previews/fullscreenpreview.jpg"));
    if (!fullScreenImageFile.open(QIODevice::WriteOnly)) {
        qWarning() << "Impossible to write to the thumbnail file";
        return;
    }

    QImage fullScreenImage(QUrl(path).path());
    if (fullScreenImage.isNull()) {
        qWarning() << "invalid image";
        return;
    }

    fullScreenImage.save(&fullScreenImageFile, "JPG"); // writes image into ba in PNG format
    fullScreenImageFile.close();

    emit themeChanged();
}
void StatusNotifierButton::refetchIcon(Status status)
{
    QString iconName;
    switch (status)
    {
        case Active:
            iconName = interface->overlayIconName();
            break;
        case NeedsAttention:
            iconName = interface->attentionIconName();
            break;
        case Passive:
            iconName = interface->iconName();
            break;
    }

    QIcon nextIcon;
    if (!iconName.isEmpty())
    {
        if (QIcon::hasThemeIcon(iconName))
            nextIcon = QIcon::fromTheme(iconName);
        else
        {
            QDir themeDir(interface->iconThemePath());
            if (themeDir.exists())
            {
                if (themeDir.exists(iconName + ".png"))
                    nextIcon.addFile(themeDir.filePath(iconName + ".png"));

                if (themeDir.cd("hicolor") || (themeDir.cd("icons") && themeDir.cd("hicolor")))
                {
                    QStringList sizes = themeDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
                    foreach (QString dir, sizes)
                    {
                        QStringList dirs = QDir(themeDir.filePath(dir)).entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
                        foreach (QString innerDir, dirs)
                        {
                            QString file = themeDir.absolutePath() + "/" + dir + "/" + innerDir + "/" + iconName + ".png";
                            if (QFile::exists(file))
                                nextIcon.addFile(file);
                        }
                    }
                }
            }
Exemple #7
0
void LnfLogic::dumpPlasmaLayout(const QString &pluginName)
{
    QDBusMessage message = QDBusMessage::createMethodCall("org.kde.plasmashell", "/PlasmaShell",
                                                     "org.kde.PlasmaShell", "dumpCurrentLayoutJS");
    QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(message);

    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);

    QObject::connect(watcher, &QDBusPendingCallWatcher::finished,
                     this, [=](QDBusPendingCallWatcher *watcher) {
        const QDBusMessage &msg = watcher->reply();
        watcher->deleteLater();
        if (watcher->isError()) {
            emit messageRequested(ErrorLevel::Error, i18n("Cannot retrieve the current Plasma layout."));
            return;
        }

        const QString layout = msg.arguments().first().toString();
        QDir themeDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) % QLatin1Literal("/plasma/look-and-feel/") % pluginName);
        if (!themeDir.mkpath("contents/layouts")) {
            qWarning() << "Impossible to create the layouts directory in the look and feel package";
            emit messageRequested(ErrorLevel::Error, i18n("Impossible to create the layouts directory in the look and feel package"));
            return;
        }

        QFile layoutFile(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) % QLatin1Literal("/plasma/look-and-feel/") % pluginName % QLatin1Literal("/contents/layouts/org.kde.plasma.desktop-layout.js"));
        if (layoutFile.open(QIODevice::WriteOnly)) {
            layoutFile.write(layout.toUtf8());
            layoutFile.close();
        } else {
            qWarning() << "Impossible to write to org.kde.plasma.desktop-layout.js";
            emit messageRequested(ErrorLevel::Error, i18n("Impossible to write to org.kde.plasma.desktop-layout.js"));
            return;
        }
        emit messageRequested(ErrorLevel::Info, i18n("Plasma Layout successfully duplicated"));
    });
}
void VConfigManager::initThemes()
{
    m_themes.clear();

    // Built-in.
    QString file(":/resources/themes/v_white/v_white.palette");
    m_themes.insert(VPalette::themeName(file), file);
    file = ":/resources/themes/v_pure/v_pure.palette";
    m_themes.insert(VPalette::themeName(file), file);
    file = ":/resources/themes/v_moonlight/v_moonlight.palette";
    m_themes.insert(VPalette::themeName(file), file);

    /* NOT ready yet. Wait for author's tuning.
    file = ":/resources/themes/v_material/v_material.palette";
    m_themes.insert(VPalette::themeName(file), file);
    */

    // User theme folder.
    QDir dir(getThemeConfigFolder());
    if (!dir.exists()) {
        dir.mkpath(getThemeConfigFolder());
        return;
    }

    dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
    QStringList dirs = dir.entryList();
    for (auto const &item : dirs) {
        QDir themeDir(dir.filePath(item));
        QStringList files = themeDir.entryList(QStringList() << "*.palette");
        if (files.size() != 1) {
            continue;
        }

        QFileInfo fi(files[0]);
        m_themes.insert(VPalette::themeName(files[0]), themeDir.filePath(files[0]));
    }
}
AppSettings::AppSettings()
{
    QCoreApplication::setOrganizationName("ghostwriter");
    QCoreApplication::setApplicationName("ghostwriter");
    QCoreApplication::setApplicationVersion(APPVERSION);

    // The following was lifted/modded from FocusWriter.
    // See GPL license at the beginning of this file.
    //
    QString appDir = qApp->applicationDirPath();

    // Set up portable settings directories.
#if defined(Q_OS_MAC)
    QFileInfo portable(appDir + "/../../../data");
#elif defined(Q_OS_UNIX)
    QFileInfo portable(appDir + "/data");
#else
    QFileInfo portable(appDir + "/data");
#endif

    // Handle portability
    QString userDir;

    if (portable.exists() && portable.isWritable())
    {
        userDir = portable.absoluteFilePath();
        QSettings::setDefaultFormat(QSettings::IniFormat);
        QSettings::setPath
        (
            QSettings::IniFormat,
            QSettings::UserScope,
            userDir + "/settings"
        );

        translationsPath = appDir + "/translations";
    }
    else
    {
#ifdef Q_OS_WIN32
        // On Windows, don't ever use the registry to store settings, for the
        // sake of cleanness, ability to load configuration files on other
        // machines, and also for the user's privacy.
        //
        QSettings::setDefaultFormat(QSettings::IniFormat);
#endif
        QSettings settings;
        userDir = QFileInfo(settings.fileName()).dir().absolutePath();

        QStringList translationPaths;
        translationPaths.append(appDir + "/translations");
        translationPaths.append(appDir + "/../share/" +
            QCoreApplication::applicationName().toLower() +
            "/translations");
        translationPaths.append(appDir + "/../Resources/translations");

        foreach (const QString& path, translationPaths)
        {
            if (QFile::exists(path))
            {
                translationsPath = path;
                break;
            }
        }
    }

    QDir themeDir(userDir + "/themes");

    if (!themeDir.exists())
    {
        themeDir.mkpath(themeDir.path());
    }

    themeDirectoryPath = themeDir.absolutePath();

    QDir dictionaryDir(userDir + "/dictionaries");

    if (!dictionaryDir.exists())
    {
        dictionaryDir.mkpath(dictionaryDir.path());
    }

    dictionaryPath = dictionaryDir.absolutePath();
    DictionaryManager::setPath(dictionaryPath);

    QStringList dictdirs;
    dictdirs.append(DictionaryManager::path());

    dictionaryDir = QDir(appDir + "/dictionaries");

    if (dictionaryDir.exists())
    {
        dictdirs.append(dictionaryDir.path());
    }

    QDir::setSearchPaths("dict", dictdirs);

    // End FocusWriter lift/mod

    // Depending on the OS and Qt version, the default monospaced font returned
    // by the Monospace style hint and/or font family tends to something not
    // even monospaced, or, at best "Courier".  QTBUG-34082 seems to be what is
    // causing the issue.  Regardless, we want the prettiest monospaced font
    // available, so see which preferred fonts are available on the system
    // before before resorting to style hints.
    //
    QFontDatabase fontDb;

    QStringList fontFamilies = fontDb.families();
    QStringList preferredFonts;

#ifdef Q_OS_MAC
    preferredFonts.append("Menlo");
#endif

    preferredFonts.append("DejaVu Sans Mono");

#ifdef Q_OS_MAC
    preferredFonts.append("Monaco");
#elif defined(Q_OS_LINUX)
    preferredFonts.append("Ubuntu Mono");
    preferredFonts.append("Liberation Mono");
#elif defined(Q_OS_WIN32)
    preferredFonts.append("Consolas");
    preferredFonts.append("Lucida Console");
#endif

    preferredFonts.append("Courier New");
    preferredFonts.append("Courier");

    // Pick the first font in the list of preferredFonts that is installed
    // (i.e., in the font database) to use as the default font on the very
    // first start up of this program.
    //
    bool fontMatchFound = false;

    for (int i = 0; i < preferredFonts.size(); i++)
    {
        fontMatchFound =
            std::binary_search
            (
                fontFamilies.begin(),
                fontFamilies.end(),
                preferredFonts[i]
            );

        if (fontMatchFound)
        {
            defaultFont = QFont(preferredFonts[i]);
            break;
        }
    }

    if (!fontMatchFound)
    {
        // This case should not really happen, since the Courier family is
        // cross-platform.  This is just a precaution.
        //
        qWarning() <<
            "No fixed-width fonts were found. Using sytem default...";
        defaultFont = QFont("");
        defaultFont.setFixedPitch(true);
        defaultFont.setStyleHint(QFont::Monospace);
    }

    // Last but not least, load some basic settings from the configuration file,
    // but only those that need special validation.  Things like window
    // dimensions and file history can be handled elsewhere.
    //
    QSettings appSettings;

    autoSaveEnabled = appSettings.value(GW_AUTOSAVE_KEY, QVariant(true)).toBool();
    backupFileEnabled = appSettings.value(GW_BACKUP_FILE_KEY, QVariant(true)).toBool();

    font = defaultFont;
    font.fromString(appSettings.value(GW_FONT_KEY, QVariant(defaultFont.toString())).toString());

    tabWidth = appSettings.value(GW_TAB_WIDTH_KEY, QVariant(DEFAULT_TAB_WIDTH)).toInt();

    if ((tabWidth < MIN_TAB_WIDTH) || (tabWidth > MAX_TAB_WIDTH))
    {
        tabWidth = DEFAULT_TAB_WIDTH;
    }

    insertSpacesForTabsEnabled = appSettings.value(GW_SPACES_FOR_TABS_KEY, QVariant(false)).toBool();
    useUnderlineForEmphasis = appSettings.value(GW_UNDERLINE_ITALICS_KEY, QVariant(false)).toBool();
    largeHeadingSizesEnabled = appSettings.value(GW_LARGE_HEADINGS_KEY, QVariant(true)).toBool();
    autoMatchEnabled = appSettings.value(GW_AUTO_MATCH_KEY, QVariant(true)).toBool();
    autoMatchDoubleQuotesEnabled = appSettings.value(GW_AUTO_MATCH_DOUBLE_QUOTES_KEY, QVariant(true)).toBool();
    autoMatchSingleQuotesEnabled = appSettings.value(GW_AUTO_MATCH_SINGLE_QUOTES_KEY, QVariant(true)).toBool();
    autoMatchParenthesesEnabled = appSettings.value(GW_AUTO_MATCH_PARENTHESES_KEY, QVariant(true)).toBool();
    autoMatchSquareBracketsEnabled = appSettings.value(GW_AUTO_MATCH_SQUARE_BRACKETS_KEY, QVariant(true)).toBool();
    autoMatchBracesEnabled = appSettings.value(GW_AUTO_MATCH_BRACES_KEY, QVariant(true)).toBool();
    autoMatchAsterisksEnabled = appSettings.value(GW_AUTO_MATCH_ASTERISKS_KEY, QVariant(true)).toBool();
    autoMatchUnderscoresEnabled = appSettings.value(GW_AUTO_MATCH_UNDERSCORES_KEY, QVariant(true)).toBool();
    autoMatchBackticksEnabled = appSettings.value(GW_AUTO_MATCH_BACKTICKS_KEY, QVariant(true)).toBool();
    autoMatchAngleBracketsEnabled = appSettings.value(GW_AUTO_MATCH_ANGLE_BRACKETS_KEY, QVariant(true)).toBool();
    bulletPointCyclingEnabled = appSettings.value(GW_BULLET_CYCLING_KEY, QVariant(true)).toBool();
    focusMode = (FocusMode) appSettings.value(GW_FOCUS_MODE_KEY, QVariant(FocusModeSentence)).toInt();

    if ((focusMode < FocusModeDisabled) || (focusMode > FocusModeParagraph))
    {
        focusMode = FocusModeSentence;
    }

    hideMenuBarInFullScreenEnabled = appSettings.value(GW_HIDE_MENU_BAR_IN_FULL_SCREEN_KEY, QVariant(true)).toBool();
    fileHistoryEnabled = appSettings.value(GW_REMEMBER_FILE_HISTORY_KEY, QVariant(true)).toBool();
    displayTimeInFullScreenEnabled = appSettings.value(GW_DISPLAY_TIME_IN_FULL_SCREEN_KEY, QVariant(true)).toBool();
    themeName = appSettings.value(GW_THEME_KEY, QVariant("Classic Light")).toString();
    dictionaryLanguage = appSettings.value(GW_DICTIONARY_KEY, QLocale().name()).toString();
    locale = appSettings.value(GW_LOCALE_KEY, QLocale().name()).toString();
    liveSpellCheckEnabled = appSettings.value(GW_LIVE_SPELL_CHECK_KEY, QVariant(true)).toBool();
    editorWidth = (EditorWidth) appSettings.value(GW_EDITOR_WIDTH_KEY, QVariant(EditorWidthMedium)).toInt();
    blockquoteStyle = (BlockquoteStyle) appSettings.value(GW_BLOCKQUOTE_STYLE_KEY, QVariant(BlockquoteStylePlain)).toInt();

    if ((editorWidth < EditorWidthNarrow) || (editorWidth > EditorWidthFull))
    {
        editorWidth = EditorWidthMedium;
    }


#ifdef Q_OS_MAC
    HudWindowButtonLayout defaultHudButtonLayout = HudWindowButtonLayoutLeft;
#else
    HudWindowButtonLayout defaultHudButtonLayout = HudWindowButtonLayoutRight;
#endif

    hudButtonLayout = (HudWindowButtonLayout) appSettings.value(GW_HUD_BUTTON_LAYOUT_KEY, QVariant(defaultHudButtonLayout)).toInt();
    alternateHudRowColorsEnabled = appSettings.value(GW_HUD_ROW_COLORS_KEY, QVariant(false)).toBool();
    desktopCompositingEnabled = appSettings.value(GW_DESKTOP_COMPOSITING_KEY, QVariant(true)).toBool();
    hudOpacity = appSettings.value(GW_HUD_OPACITY_KEY, QVariant(200)).toInt();
}
void StatusNotifierButton::refetchIcon(Status status, const QString& themePath)
{
    QString nameProperty, pixmapProperty;
    if (status == Active)
    {
        nameProperty = QLatin1String("OverlayIconName");
        pixmapProperty = QLatin1String("OverlayIconPixmap");
    }
    else if (status == NeedsAttention)
    {
        nameProperty = QLatin1String("AttentionIconName");
        pixmapProperty = QLatin1String("AttentionIconPixmap");
    }
    else // status == Passive
    {
        nameProperty = QLatin1String("IconName");
        pixmapProperty = QLatin1String("IconPixmap");
    }

    interface->propertyGetAsync(nameProperty, [this, status, pixmapProperty, themePath] (QString iconName) {
        QIcon nextIcon;
        if (!iconName.isEmpty())
        {
            if (QIcon::hasThemeIcon(iconName))
                nextIcon = QIcon::fromTheme(iconName);
            else
            {
                QDir themeDir(themePath);
                if (themeDir.exists())
                {
                    if (themeDir.exists(iconName + ".png"))
                        nextIcon.addFile(themeDir.filePath(iconName + ".png"));

                    if (themeDir.cd("hicolor") || (themeDir.cd("icons") && themeDir.cd("hicolor")))
                    {
                        const QStringList sizes = themeDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
                        for (const QString &dir : sizes)
                        {
                            const QStringList dirs = QDir(themeDir.filePath(dir)).entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
                            for (const QString &innerDir : dirs)
                            {
                                QString file = themeDir.absolutePath() + "/" + dir + "/" + innerDir + "/" + iconName + ".png";
                                if (QFile::exists(file))
                                    nextIcon.addFile(file);
                            }
                        }
                    }
                }
            }

            switch (status)
            {
                case Active:
                    mOverlayIcon = nextIcon;
                    break;
                case NeedsAttention:
                    mAttentionIcon = nextIcon;
                    break;
                case Passive:
                    mIcon = nextIcon;
                    break;
            }

            resetIcon();
        }
        else
        {
            interface->propertyGetAsync(pixmapProperty, [this, status, pixmapProperty] (IconPixmapList iconPixmaps) {
                if (iconPixmaps.empty())
                    return;

                QIcon nextIcon;

                for (IconPixmap iconPixmap: iconPixmaps)
                {
                    if (!iconPixmap.bytes.isNull())
                    {
                        QImage image((uchar*) iconPixmap.bytes.data(), iconPixmap.width,
                                     iconPixmap.height, QImage::Format_ARGB32);

                        const uchar *end = image.constBits() + image.byteCount();
                        uchar *dest = reinterpret_cast<uchar*>(iconPixmap.bytes.data());
                        for (const uchar *src = image.constBits(); src < end; src += 4, dest += 4)
                            qToUnaligned(qToBigEndian<quint32>(qFromUnaligned<quint32>(src)), dest);

                        nextIcon.addPixmap(QPixmap::fromImage(image));
                    }
                }

                switch (status)
                {
                    case Active:
                        mOverlayIcon = nextIcon;
                        break;
                    case NeedsAttention:
                        mAttentionIcon = nextIcon;
                        break;
                    case Passive:
                        mIcon = nextIcon;
                        break;
                }

                resetIcon();
            });
        }
    });
}