mirror of
https://github.com/martinrotter/rssguard.git
synced 2024-12-27 08:33:27 +01:00
Initial implementation of ThemeFactory class.
This commit is contained in:
parent
6fd589aa7d
commit
d83d88fc98
@ -320,14 +320,14 @@ elseif(OS2)
|
||||
elseif(UNIX)
|
||||
message(STATUS "[${APP_LOW_NAME}] You will probably install on Linux.")
|
||||
install(TARGETS ${EXE_NAME} RUNTIME DESTINATION bin)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/resources/desktop/qonverter.desktop DESTINATION share/applications)
|
||||
install(FILES resources/graphics/qonverter.png DESTINATION share/icons/hicolor/256x256/apps/)
|
||||
install(FILES ${APP_QM} DESTINATION share/qonverter/l10n)
|
||||
install(FILES ${APP_SKIN_PLAIN} DESTINATION share/qonverter/skins/base)
|
||||
install(FILES ${APP_SKIN_MODERN} DESTINATION share/qonverter/skins/base)
|
||||
install(FILES ${APP_SKIN_DARK} DESTINATION share/qonverter/skins/fancy)
|
||||
install(FILES ${APP_SKIN_DARK_IMAGES} DESTINATION share/qonverter/skins/fancy/images)
|
||||
install(FILES ${APP_MISC} DESTINATION share/qonverter/information)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/resources/desktop/${APP_LOW_NAME}.desktop DESTINATION share/applications)
|
||||
install(FILES resources/graphics/${APP_LOW_NAME}.png DESTINATION share/icons/hicolor/256x256/apps/)
|
||||
install(FILES ${APP_QM} DESTINATION share/${APP_LOW_NAME}/l10n)
|
||||
install(FILES ${APP_SKIN_PLAIN} DESTINATION share/${APP_LOW_NAME}/skins/base)
|
||||
install(FILES ${APP_SKIN_MODERN} DESTINATION share/${APP_LOW_NAME}/skins/base)
|
||||
install(FILES ${APP_SKIN_DARK} DESTINATION share/${APP_LOW_NAME}/skins/fancy)
|
||||
install(FILES ${APP_SKIN_DARK_IMAGES} DESTINATION share/${APP_LOW_NAME}/skins/fancy/images)
|
||||
install(FILES ${APP_MISC} DESTINATION share/${APP_LOW_NAME}/information)
|
||||
endif(WIN32)
|
||||
|
||||
# Custom target for packaging.
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
#define APP_CFG_PATH "data/config/config.ini"
|
||||
#define APP_CFG_GUI "gui"
|
||||
#define APP_CFG_GEN "general"
|
||||
#define APP_CFG_GEN "main"
|
||||
#define APP_CFG_LANG "localization"
|
||||
|
||||
#define APP_DB_PATH "data/storage/database.db"
|
||||
@ -25,10 +25,10 @@
|
||||
|
||||
// TODO: OS/2 support missing. No way to test this w/o OS/2 machine.
|
||||
#if defined(Q_OS_LINUX)
|
||||
#define APP_LANG_PATH APP_PREFIX + QString("/share/qonverter/l10n")
|
||||
#define APP_SKIN_PATH APP_PREFIX + QString("/share/qonverter/skins")
|
||||
#define APP_INFO_PATH APP_PREFIX + QString("/share/qonverter/information")
|
||||
#define APP_THEME_PATH APP_PREFIX + QString("/share/qonverter/themes")
|
||||
#define APP_LANG_PATH APP_PREFIX + QString("/share/rssguard/l10n")
|
||||
#define APP_SKIN_PATH APP_PREFIX + QString("/share/rssguard/skins")
|
||||
#define APP_INFO_PATH APP_PREFIX + QString("/share/rssguard/information")
|
||||
#define APP_THEME_PATH APP_PREFIX + QString("/share/rssguard/themes")
|
||||
#elif defined(Q_OS_MAC)
|
||||
#define APP_LANG_PATH QApplication::applicationDirPath() + "/../Resources/l10n"
|
||||
#define APP_SKIN_PATH QApplication::applicationDirPath() + "/../Resources/skins"
|
||||
|
@ -6,6 +6,9 @@
|
||||
FormMain::FormMain(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::FormMain) {
|
||||
m_ui->setupUi(this);
|
||||
|
||||
// for testing purposes
|
||||
m_ui->toolButton->setIcon(QIcon::fromTheme("application-exit"));
|
||||
|
||||
createConnections();
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,27 @@
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget"/>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<widget class="QToolButton" name="toolButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>230</x>
|
||||
<y>150</y>
|
||||
<width>61</width>
|
||||
<height>51</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="m_menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
|
@ -1,7 +1,10 @@
|
||||
#include <QIcon>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QApplication>
|
||||
|
||||
#include "gui/themefactory.h"
|
||||
#include "core/settings.h"
|
||||
#include "core/defs.h"
|
||||
|
||||
|
||||
@ -10,7 +13,77 @@ ThemeFactory::ThemeFactory() {
|
||||
|
||||
void ThemeFactory::setupSearchPaths() {
|
||||
QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() << APP_THEME_PATH);
|
||||
|
||||
qDebug("Available icon theme paths: %s.",
|
||||
qPrintable(QIcon::themeSearchPaths().join(", ")));
|
||||
}
|
||||
|
||||
// TODO: Load currently selected "real" icon theme name instead of
|
||||
// Qt default "", which stands for currently active system icon theme name.
|
||||
QString ThemeFactory::getSystemIconTheme() {
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString ThemeFactory::getCurrentIconTheme() {
|
||||
QString current_theme_name = Settings::getInstance().value(APP_CFG_GUI,
|
||||
"icon_theme",
|
||||
getSystemIconTheme()).toString();
|
||||
return current_theme_name;
|
||||
}
|
||||
|
||||
void ThemeFactory::setCurrentIconTheme(const QString &theme_name) {
|
||||
Settings::getInstance().setValue(APP_CFG_GUI,
|
||||
"icon_theme",
|
||||
theme_name);
|
||||
loadCurrentIconTheme();
|
||||
}
|
||||
|
||||
void ThemeFactory::loadCurrentIconTheme() {
|
||||
QString theme_name = getCurrentIconTheme();
|
||||
QStringList installed_themes = getInstalledIconThemes();
|
||||
|
||||
qDebug("Installed icon themes are: %s.",
|
||||
qPrintable(installed_themes.join(", ")));
|
||||
|
||||
if (!installed_themes.contains(theme_name)) {
|
||||
qDebug("Icon theme '%s' cannot be loaded because it is not installed.",
|
||||
qPrintable(theme_name));
|
||||
return;
|
||||
}
|
||||
else {
|
||||
qDebug("Loading theme '%s'.", qPrintable(theme_name));
|
||||
QIcon::setThemeName(theme_name);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList ThemeFactory::getInstalledIconThemes() {
|
||||
QStringList icon_theme_names;
|
||||
|
||||
// Add system theme.
|
||||
icon_theme_names << getSystemIconTheme();
|
||||
|
||||
// Iterate all directories with icon themes.
|
||||
QStringList icon_themes_paths = QIcon::themeSearchPaths();
|
||||
icon_themes_paths.removeDuplicates();
|
||||
|
||||
foreach (QString icon_path, icon_themes_paths) {
|
||||
QDir icon_dir(icon_path);
|
||||
|
||||
// Iterate all icon themes in this directory.
|
||||
foreach (QString icon_theme_path, icon_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot |
|
||||
QDir::Readable | QDir::CaseSensitive |
|
||||
QDir::NoSymLinks,
|
||||
QDir::Time)) {
|
||||
// Check if index.theme file in this path exists.
|
||||
if (QFile::exists(icon_dir.path() + "/" + icon_theme_path + "/index.theme")) {
|
||||
icon_theme_names << icon_theme_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
icon_theme_names.removeDuplicates();
|
||||
return icon_theme_names;
|
||||
}
|
||||
|
||||
// zjištění názvů témat dle d:\Programovani\Materiály\Qt\qt5\qtbase\src\gui\image\qiconloader.cpp,
|
||||
// řádek 172, jak se prochází ty složky
|
||||
// http://doublecmd.svn.sourceforge.net/viewvc/doublecmd/trunk/src/platform/unix/uunixicontheme.pas
|
||||
|
@ -1,13 +1,34 @@
|
||||
#ifndef THEMEFACTORY_H
|
||||
#define THEMEFACTORY_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
class ThemeFactory {
|
||||
private:
|
||||
ThemeFactory();
|
||||
|
||||
public:
|
||||
// Adds custom application path to be search for icons.
|
||||
static void setupSearchPaths();
|
||||
|
||||
// Returns name of icon theme, which is selected as active for
|
||||
// system.
|
||||
static QString getSystemIconTheme();
|
||||
|
||||
// Returns list of installed themes, this includes:
|
||||
// a) system-wide themes,
|
||||
// b) application-wide themes.
|
||||
static QStringList getInstalledIconThemes();
|
||||
|
||||
// Loads name of selected icon theme for the application and activates it.
|
||||
static void loadCurrentIconTheme();
|
||||
|
||||
// Returns name of currently activated theme for the application.
|
||||
static QString getCurrentIconTheme();
|
||||
|
||||
// Sets icon theme with given name as the active one.
|
||||
static void setCurrentIconTheme(const QString &theme_name);
|
||||
};
|
||||
|
||||
#endif // THEMEFACTORY_H
|
||||
|
@ -55,6 +55,9 @@ int main(int argc, char *argv[]) {
|
||||
// Add an extra path for non-system icon themes.
|
||||
ThemeFactory::setupSearchPaths();
|
||||
|
||||
// Load icon theme from settings.
|
||||
ThemeFactory::loadCurrentIconTheme();
|
||||
|
||||
// These settings needs to be set before any QSettings object.
|
||||
QtSingleApplication::setApplicationName(APP_NAME);
|
||||
QtSingleApplication::setApplicationVersion(APP_VERSION);
|
||||
|
Loading…
Reference in New Issue
Block a user