From 8c80579ca768283f96b306e6fc9e5c938b212b79 Mon Sep 17 00:00:00 2001 From: Bartosz Szatkowski Date: Fri, 27 Aug 2010 09:13:17 +0200 Subject: [PATCH] Fixed stylesheet handling and automatic default generation --- styles.css | 22 ----------- trunk/src/base/backbone/ConfigGenerator.cpp | 45 ++++++++++++++++++++++ trunk/src/base/backbone/ConfigGenerator.h | 55 +++++++++++++++++++++++++++ trunk/src/base/backbone/backbone.cpp | 10 ++++- trunk/src/base/backbone/backbone.h | 2 + trunk/src/base/base.pro | 6 ++- trunk/src/base/gui/TranslationWidget.cpp | 9 ++++- trunk/src/base/style.css | 22 +++++++++++ trunk/src/base/xsl.xsl | 2 +- trunk/src/base/xslt2.qrc | 1 + 10 files changed, 146 insertions(+), 28 deletions(-) delete mode 100644 styles.css create mode 100644 trunk/src/base/backbone/ConfigGenerator.cpp create mode 100644 trunk/src/base/backbone/ConfigGenerator.h create mode 100644 trunk/src/base/style.css diff --git a/styles.css b/styles.css deleted file mode 100644 index c8490f2..0000000 --- a/styles.css +++ /dev/null @@ -1,22 +0,0 @@ -th.info { - background-color : #99FF99; -} - -th.key { - background-color : #99CCFF; -} - -span.i { - font-style : italic; -} - -span.b { - font-weight : bold; -} - -span.u { - text-decoration : underline; -} - - - diff --git a/trunk/src/base/backbone/ConfigGenerator.cpp b/trunk/src/base/backbone/ConfigGenerator.cpp new file mode 100644 index 0000000..6781903 --- /dev/null +++ b/trunk/src/base/backbone/ConfigGenerator.cpp @@ -0,0 +1,45 @@ +/******************************************************************************* + + This file is part of mDictionary. + + mDictionary 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 3 of the License, or + (at your option) any later version. + + mDictionary 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 mDictionary. If not, see . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +/*! \file ConfigGenerator.cpp +\brief Generating default config files, css stylesheet etc + +\author Bartosz Szatkowski +*/ + +#include "ConfigGenerator.h" + +ConfigGenerator::ConfigGenerator() {} + + +bool ConfigGenerator::generateCss(QString file) { + QFile _file(file); + if(_file.exists()) + return true; + QFile cssFile(":/xsl/style.css"); + if(cssFile.copy(file)) { + _file.setPermissions(QFile::ReadOwner | QFile::WriteOwner | + QFile::ReadGroup | QFile::WriteGroup | QFile::ReadOther); + return true; + } + return false; + +} diff --git a/trunk/src/base/backbone/ConfigGenerator.h b/trunk/src/base/backbone/ConfigGenerator.h new file mode 100644 index 0000000..f624c71 --- /dev/null +++ b/trunk/src/base/backbone/ConfigGenerator.h @@ -0,0 +1,55 @@ +/******************************************************************************* + + This file is part of mDictionary. + + mDictionary 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 3 of the License, or + (at your option) any later version. + + mDictionary 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 mDictionary. If not, see . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +/*! \file ConfigGenerator.h +\brief Generating default config files, css stylesheet etc + +\author Bartosz Szatkowski +*/ + +#ifndef CONFIGGENERATOR_H +#define CONFIGGENERATOR_H + +#include +#include +#include + +/*! ConfigGenerator generatesconfiguration files (with default values), +if given file dosent exists. + +For now only css is generateed in this way, but iam planign to refactor all +configuration files to work that way. +*/ +class ConfigGenerator { + +public: + ConfigGenerator(); + + + /*! Generates default css stylesheet for xslt transformations + \param file file to be generated + \return if file was generated - returns true; if file alredy exists + return true; if file dosent exists but cannot be generated returns false + */ + bool generateCss(QString file); +}; + +#endif // CONFIGGENERATOR_H diff --git a/trunk/src/base/backbone/backbone.cpp b/trunk/src/base/backbone/backbone.cpp index a1e8917..9262aa0 100644 --- a/trunk/src/base/backbone/backbone.cpp +++ b/trunk/src/base/backbone/backbone.cpp @@ -69,15 +69,21 @@ public: void Backbone::init() { + _dir = QDir::homePath() + "/.mdictionary/"; if(!_configPath.size()) - _configPath = QDir::homePath() + "/.mdictionary/mdictionary.config"; + _configPath = _dir + "mdictionary.config"; if(!_defaultConfigPath.size()) - _defaultConfigPath = QDir::homePath() + "/.mdictionary/mdictionary.defaults"; + _defaultConfigPath = _dir + "mdictionary.defaults"; if(!_pluginPath.size()) _pluginPath = "/usr/lib/mdictionary"; _historyLen = 10; _searchLimit = 15; + //Install default config files + ConfigGenerator().generateCss(_dir + "style.css"); + + + loadPrefs(_defaultConfigPath); // Default configuration are stored in separate config file and we dont want diff --git a/trunk/src/base/backbone/backbone.h b/trunk/src/base/backbone/backbone.h index 5affa3a..cf44ae6 100644 --- a/trunk/src/base/backbone/backbone.h +++ b/trunk/src/base/backbone/backbone.h @@ -49,6 +49,7 @@ #include "../../includes/translation.h" #include "../../includes/History.h" #include "../../includes/Notify.h" +#include "ConfigGenerator.h" #include "Bookmarks.h" @@ -305,6 +306,7 @@ private: QString _pluginPath, _defaultPluginPath; QString _configPath; QString _defaultConfigPath; + QString _dir; int _defaultSearchLimit; int _historyLen, _defaultHistoryLen; diff --git a/trunk/src/base/base.pro b/trunk/src/base/base.pro index 3e638ea..5a53384 100644 --- a/trunk/src/base/base.pro +++ b/trunk/src/base/base.pro @@ -30,7 +30,8 @@ SOURCES += gui/main.cpp \ gui/BookmarksWidget.cpp \ gui/WelcomeScreenWidget.cpp \ gui/AboutWidget.cpp \ - gui/TranslationTextEdit.cpp + gui/TranslationTextEdit.cpp \ + backbone/ConfigGenerator.cpp HEADERS += gui/MainWindow.h \ gui/AboutWidget.h \ gui/SearchBarWidget.h \ @@ -57,7 +58,8 @@ HEADERS += gui/MainWindow.h \ ../includes/Notify.h \ gui/TranslationTextEdit.h \ ../includes/AccentsNormalizer.h \ - ../includes/DictDialog.h + ../includes/DictDialog.h \ + backbone/ConfigGenerator.h FORMS += RESOURCES += ../../../data/icons/gui.qrc unix { diff --git a/trunk/src/base/gui/TranslationWidget.cpp b/trunk/src/base/gui/TranslationWidget.cpp index 91ba5b2..79f0402 100644 --- a/trunk/src/base/gui/TranslationWidget.cpp +++ b/trunk/src/base/gui/TranslationWidget.cpp @@ -79,7 +79,14 @@ void TranslationWidget::show(QStringList translations) { QImage image(":icons/16x16/staron.png"); QTextDocument *document = textEdit->document(); - document->addResource(QTextDocument::ImageResource, QUrl("mydata://image.png"), QVariant(image)); + document->addResource(QTextDocument::ImageResource, + QUrl("mydata://image.png"), QVariant(image)); + + QFile cssFile(QDir::homePath() + "/.mdictionary/style.css"); + cssFile.open(QFile::ReadOnly); + document->addResource(QTextDocument::StyleSheetResource, + QUrl("mydata://style.css"), + QVariant(cssFile.readAll())); trans=tr("") + tr("\n ") + trans + tr("\n "); diff --git a/trunk/src/base/style.css b/trunk/src/base/style.css new file mode 100644 index 0000000..c8490f2 --- /dev/null +++ b/trunk/src/base/style.css @@ -0,0 +1,22 @@ +th.info { + background-color : #99FF99; +} + +th.key { + background-color : #99CCFF; +} + +span.i { + font-style : italic; +} + +span.b { + font-weight : bold; +} + +span.u { + text-decoration : underline; +} + + + diff --git a/trunk/src/base/xsl.xsl b/trunk/src/base/xsl.xsl index 205b223..0a9f174 100644 --- a/trunk/src/base/xsl.xsl +++ b/trunk/src/base/xsl.xsl @@ -4,7 +4,7 @@ - + diff --git a/trunk/src/base/xslt2.qrc b/trunk/src/base/xslt2.qrc index 94c710a..818243c 100644 --- a/trunk/src/base/xslt2.qrc +++ b/trunk/src/base/xslt2.qrc @@ -1,5 +1,6 @@ xsl.xsl + style.css -- 1.7.9.5