summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLukáš Lalinský <lalinsky@gmail.com>2009-03-04 13:17:27 +0100
committerLukáš Lalinský <lalinsky@gmail.com>2009-03-04 13:17:27 +0100
commit79ca42fb34cc8f2a4fe893fcdccb9b385f4e1ba2 (patch)
treea986a6dc6817436d742a5ea63c60f5e844c017ac /src
parentda4daa6255bec2694bb7936bbe67cd5e19f0c5ef (diff)
downloaddbmodel-79ca42fb34cc8f2a4fe893fcdccb9b385f4e1ba2.tar.xz
Use QtIconLoader <http://code.google.com/p/qticonloader/>
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp39
-rw-r--r--src/mainwindow.h2
-rw-r--r--src/utils/iconloader/iconloader.pri7
-rw-r--r--src/utils/iconloader/qticonloader.cpp350
-rw-r--r--src/utils/iconloader/qticonloader.h44
-rw-r--r--src/utils/iconprovider.cpp116
-rw-r--r--src/utils/iconprovider.h34
-rw-r--r--src/utils/utils.pri4
8 files changed, 430 insertions, 166 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 98d8efd..fd7d9ee 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -32,12 +32,12 @@
#include <QDockWidget>
#include <QUndoView>
#include <QStackedWidget>
+#include "utils/iconloader/qticonloader.h"
#include "diagramitem.h"
#include "diagramobject.h"
#include "diagramitemfactory.h"
#include "diagramitemproperties.h"
#include "commands.h"
-#include "utils/iconprovider.h"
#include "mainwindow.h"
@@ -168,32 +168,45 @@ MainWindow::setupUi()
setCentralWidget(m_view);
}
+QIcon
+MainWindow::loadIcon(const QString &name)
+{
+ QIcon icon = QtIconLoader::icon(name);
+ if (icon.isNull()) {
+ QString path = ":/icons/16x16/" + name + ".png";
+ if (QFile::exists(path)) {
+ icon.addFile(path, QSize(16, 16));
+ }
+ }
+ return icon;
+}
+
void
MainWindow::setupActions()
{
m_actionNew = new QAction(this);
m_actionNew->setText(tr("&New"));
- m_actionNew->setIcon(IconProvider::findIcon(16, "document-new.png"));
+ m_actionNew->setIcon(loadIcon("document-new"));
m_actionNew->setShortcut(QKeySequence(tr("Ctrl+N")));
connect(m_actionNew, SIGNAL(triggered(bool)), SLOT(newModel()));
m_actionOpen = new QAction(this);
m_actionOpen->setText(tr("&Open..."));
- m_actionOpen->setIcon(IconProvider::findIcon(16, "document-open.png"));
+ m_actionOpen->setIcon(loadIcon("document-open"));
m_actionOpen->setShortcut(QKeySequence(tr("Ctrl+O")));
connect(m_actionOpen, SIGNAL(triggered(bool)), SLOT(open()));
m_actionSave = new QAction(this);
m_actionSave->setText(tr("&Save"));
- m_actionSave->setIcon(IconProvider::findIcon(16, "document-save.png"));
+ m_actionSave->setIcon(loadIcon("document-save"));
m_actionSave->setShortcut(QKeySequence(tr("Ctrl+S")));
//m_actionSave->setDisabled(true);
connect(m_actionSave, SIGNAL(triggered(bool)), SLOT(save()));
m_actionSaveAs = new QAction(this);
m_actionSaveAs->setText(tr("Save &As..."));
- m_actionSaveAs->setIcon(IconProvider::findIcon(16, "document-save-as.png"));
+ m_actionSaveAs->setIcon(loadIcon("document-save-as"));
//m_actionSaveAs->setDisabled(true);
connect(m_actionSaveAs, SIGNAL(triggered(bool)), SLOT(saveAs()));
@@ -228,10 +241,10 @@ MainWindow::setupActions()
m_actionUndo = new QAction(tr("&Undo"), this);
m_actionUndo->setShortcut(QKeySequence(tr("Ctrl+Z")));
- m_actionUndo->setIcon(IconProvider::findIcon(16, "edit-undo.png"));
+ m_actionUndo->setIcon(loadIcon("edit-undo"));
m_actionRedo = new QAction(tr("Re&do"), this);
m_actionRedo->setShortcut(QKeySequence(tr("Ctrl+Shift+Z")));
- m_actionRedo->setIcon(IconProvider::findIcon(16, "edit-redo.png"));
+ m_actionRedo->setIcon(loadIcon("edit-redo"));
connect(m_actionSwitchMode[0], SIGNAL(triggered(bool)), SLOT(switchModeSelect()));
connect(m_actionSwitchMode[1], SIGNAL(triggered(bool)), SLOT(switchModeAddTable()));
@@ -239,25 +252,25 @@ MainWindow::setupActions()
m_actionCut = new QAction(this);
m_actionCut->setText(tr("Cu&t"));
- m_actionCut->setIcon(IconProvider::findIcon(16, "edit-cut.png"));
+ m_actionCut->setIcon(loadIcon("edit-cut"));
m_actionCut->setShortcut(QKeySequence(tr("Ctrl+X")));
connect(m_actionCut, SIGNAL(triggered(bool)), SLOT(cut()));
m_actionCopy = new QAction(this);
m_actionCopy->setText(tr("&Copy"));
- m_actionCopy->setIcon(IconProvider::findIcon(16, "edit-copy.png"));
+ m_actionCopy->setIcon(loadIcon("edit-copy"));
m_actionCopy->setShortcut(QKeySequence(tr("Ctrl+C")));
connect(m_actionCopy, SIGNAL(triggered(bool)), SLOT(copy()));
m_actionPaste = new QAction(this);
m_actionPaste->setText(tr("&Paste"));
- m_actionPaste->setIcon(IconProvider::findIcon(16, "edit-paste.png"));
+ m_actionPaste->setIcon(loadIcon("edit-paste"));
m_actionPaste->setShortcut(QKeySequence(tr("Ctrl+V")));
connect(m_actionPaste, SIGNAL(triggered(bool)), SLOT(paste()));
m_actionDelete = new QAction(this);
m_actionDelete->setText(tr("&Delete"));
- m_actionDelete->setIcon(IconProvider::findIcon(16, "edit-delete.png"));
+ m_actionDelete->setIcon(loadIcon("edit-delete"));
m_actionDelete->setShortcut(QKeySequence(tr("Del")));
connect(m_actionDelete, SIGNAL(triggered(bool)), SLOT(deleteSelectedItems()));
@@ -267,13 +280,13 @@ MainWindow::setupActions()
m_actionClose = new QAction(this);
m_actionClose->setText(tr("&Close"));
- m_actionClose->setIcon(IconProvider::findIcon(16, "window-close.png"));
+ m_actionClose->setIcon(loadIcon("window-close"));
m_actionClose->setShortcut(QKeySequence(tr("Ctrl+W")));
connect(m_actionClose, SIGNAL(triggered(bool)), SLOT(close()));
m_actionQuit = new QAction(this);
m_actionQuit->setText(tr("&Quit"));
- m_actionQuit->setIcon(IconProvider::findIcon(16, "application-exit.png"));
+ m_actionQuit->setIcon(loadIcon("application-exit"));
m_actionQuit->setShortcut(QKeySequence(tr("Ctrl+Q")));
connect(m_actionQuit, SIGNAL(triggered(bool)), SLOT(closeAll()));
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 9cac7ce..eaf7626 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -34,6 +34,8 @@ public:
MainWindow();
~MainWindow();
+ QIcon loadIcon(const QString &name);
+
public slots:
void newModel(DiagramDocument *newModel = 0);
diff --git a/src/utils/iconloader/iconloader.pri b/src/utils/iconloader/iconloader.pri
new file mode 100644
index 0000000..33093ee
--- /dev/null
+++ b/src/utils/iconloader/iconloader.pri
@@ -0,0 +1,7 @@
+DEPENDPATH += $$PWD
+
+SOURCES += \
+ qticonloader.cpp
+
+HEADERS += \
+ qticonloader.h
diff --git a/src/utils/iconloader/qticonloader.cpp b/src/utils/iconloader/qticonloader.cpp
new file mode 100644
index 0000000..78e62b8
--- /dev/null
+++ b/src/utils/iconloader/qticonloader.cpp
@@ -0,0 +1,350 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtIconLoader project on Qt Software Labs.
+**
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information
+** to ensure GNU General Public Licensing requirements will be met:
+** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
+** http://www.gnu.org/copyleft/gpl.html. In addition, as a special
+** exception, Nokia gives you certain additional rights. These rights
+** are described in the Nokia Qt GPL Exception version 1.3, included in
+** the file GPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+
+#include "qticonloader.h"
+#include <QtGui/QPixmapCache>
+
+#include <QtCore/QList>
+#include <QtCore/QHash>
+#include <QtCore/QDir>
+#include <QtCore/QString>
+#include <QtCore/QLibrary>
+#include <QtCore/QSettings>
+#include <QtCore/QTextStream>
+
+#ifdef Q_WS_X11
+
+class QIconTheme
+{
+public:
+ QIconTheme(QHash <int, QString> dirList, QStringList parents) :
+ _dirList(dirList), _parents(parents), _valid(true){ }
+ QIconTheme() : _valid(false){ }
+ QHash <int, QString> dirList() {return _dirList;}
+ QStringList parents() {return _parents;}
+ bool isValid() {return _valid;}
+
+private:
+ QHash <int, QString> _dirList;
+ QStringList _parents;
+ bool _valid;
+};
+
+class QtIconLoaderImplementation
+{
+public:
+ QtIconLoaderImplementation();
+ QPixmap findIcon(int size, const QString &name) const;
+
+private:
+ QIconTheme parseIndexFile(const QString &themeName) const;
+ void lookupIconTheme() const;
+ QPixmap findIconHelper(int size,
+ const QString &themeName,
+ const QString &iconName,
+ QStringList &visited) const;
+ mutable QString themeName;
+ mutable QStringList iconDirs;
+ mutable QHash <QString, QIconTheme> themeList;
+};
+
+Q_GLOBAL_STATIC(QtIconLoaderImplementation, iconLoaderInstance)
+#endif
+
+/*!
+
+ Returns the standard icon for the given icon /a name
+ as specified in the freedesktop icon spec
+ http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
+
+ /a fallback is an optional argument to specify the icon to be used if
+ no icon is found on the platform. This is particularily useful for
+ crossplatform code.
+
+*/
+QIcon QtIconLoader::icon(const QString &name, const QIcon &fallback)
+{
+ QIcon icon;
+#ifdef Q_WS_X11
+ QString pngExtension(QLatin1String(".png"));
+ QList<int> iconSizes;
+ iconSizes << 16 << 24 << 32 << 48 << 64;
+ foreach (int size, iconSizes) {
+ icon.addPixmap(iconLoaderInstance()->findIcon(size, name + pngExtension));
+ }
+#else
+ if (icon.isNull())
+ icon = fallback;
+ Q_UNUSED(name);
+ Q_UNUSED(fallback);
+#endif // Q_WS_X11
+ return icon;
+}
+
+#ifdef Q_WS_X11
+
+QtIconLoaderImplementation::QtIconLoaderImplementation()
+{
+ lookupIconTheme();
+}
+
+extern "C" {
+ struct GConfClient;
+ struct GError;
+ typedef void (*Ptr_g_type_init)();
+ typedef GConfClient* (*Ptr_gconf_client_get_default)();
+ typedef char* (*Ptr_gconf_client_get_string)(GConfClient*, const char*, GError **);
+ typedef void (*Ptr_g_object_unref)(void *);
+ typedef void (*Ptr_g_error_free)(GError *);
+ typedef void (*Ptr_g_free)(void*);
+ static Ptr_g_type_init p_g_type_init = 0;
+ static Ptr_gconf_client_get_default p_gconf_client_get_default = 0;
+ static Ptr_gconf_client_get_string p_gconf_client_get_string = 0;
+ static Ptr_g_object_unref p_g_object_unref = 0;
+ static Ptr_g_error_free p_g_error_free = 0;
+ static Ptr_g_free p_g_free = 0;
+}
+
+
+static int kdeVersion()
+{
+ static int version = -1;
+ if (version == -1)
+ version = qgetenv("KDE_SESSION_VERSION").toInt();
+ return version;
+}
+
+static QString kdeHome()
+{
+ static QString kdeHomePath;
+ if (kdeHomePath.isEmpty()) {
+ kdeHomePath = QString::fromLocal8Bit(qgetenv("KDEHOME"));
+ if (kdeHomePath.isEmpty()) {
+ int kdeSessionVersion = QString::fromLocal8Bit(qgetenv("KDE_SESSION_VERSION")).toInt();
+ QDir homeDir(QDir::homePath());
+ QString kdeConfDir(QLatin1String("/.kde"));
+ if (4 == kdeSessionVersion && homeDir.exists(QLatin1String(".kde4")))
+ kdeConfDir = QLatin1String("/.kde4");
+ kdeHomePath = QDir::homePath() + kdeConfDir;
+ }
+ }
+ return kdeHomePath;
+}
+
+void QtIconLoaderImplementation::lookupIconTheme() const
+{
+
+#ifdef Q_WS_X11
+ QString dataDirs = QLatin1String(getenv("XDG_DATA_DIRS"));
+ if (dataDirs.isEmpty())
+ dataDirs = QLatin1String("/usr/local/share/:/usr/share/");
+
+ dataDirs.prepend(QDir::homePath() + QLatin1String("/:"));
+ iconDirs = dataDirs.split(QLatin1String(":"));
+
+ // If we are running GNOME we resolve and use GConf. In all other
+ // cases we currently use the KDE icon theme
+
+ if (qgetenv("DESKTOP_SESSION") == "gnome" ||
+ !qgetenv("GNOME_DESKTOP_SESSION_ID").isEmpty()) {
+
+ if (themeName.isEmpty()) {
+ // Resolve glib and gconf
+
+ p_g_type_init = (Ptr_g_type_init)QLibrary::resolve(QLatin1String("gobject-2.0"), 0, "g_type_init");
+ p_gconf_client_get_default = (Ptr_gconf_client_get_default)QLibrary::resolve(QLatin1String("gconf-2"), 4, "gconf_client_get_default");
+ p_gconf_client_get_string = (Ptr_gconf_client_get_string)QLibrary::resolve(QLatin1String("gconf-2"), 4, "gconf_client_get_string");
+ p_g_object_unref = (Ptr_g_object_unref)QLibrary::resolve(QLatin1String("gobject-2.0"), 0, "g_object_unref");
+ p_g_error_free = (Ptr_g_error_free)QLibrary::resolve(QLatin1String("glib-2.0"), 0, "g_error_free");
+ p_g_free = (Ptr_g_free)QLibrary::resolve(QLatin1String("glib-2.0"), 0, "g_free");
+
+ if (p_g_type_init && p_gconf_client_get_default &&
+ p_gconf_client_get_string && p_g_object_unref &&
+ p_g_error_free && p_g_free) {
+
+ p_g_type_init();
+ GConfClient* client = p_gconf_client_get_default();
+ GError *err = 0;
+
+ char *str = p_gconf_client_get_string(client, "/desktop/gnome/interface/icon_theme", &err);
+ if (!err) {
+ themeName = QString::fromUtf8(str);
+ p_g_free(str);
+ }
+
+ p_g_object_unref(client);
+ if (err)
+ p_g_error_free (err);
+ }
+ if (themeName.isEmpty())
+ themeName = QLatin1String("gnome");
+ }
+
+ if (!themeName.isEmpty())
+ return;
+ }
+
+ // KDE (and others)
+ if (dataDirs.isEmpty())
+ dataDirs = QLatin1String("/usr/local/share/:/usr/share/");
+
+ dataDirs += QLatin1Char(':') + kdeHome() + QLatin1String("/share");
+ dataDirs.prepend(QDir::homePath() + QLatin1String("/:"));
+ QStringList kdeDirs = QString::fromLocal8Bit(getenv("KDEDIRS")).split(QLatin1Char(':'));
+ foreach (const QString dirName, kdeDirs)
+ dataDirs.append(QLatin1String(":") + dirName + QLatin1String("/share"));
+ iconDirs = dataDirs.split(QLatin1Char(':'));
+
+ QFileInfo fileInfo(QLatin1String("/usr/share/icons/default.kde"));
+ QDir dir(fileInfo.canonicalFilePath());
+ int kdeVersion = qgetenv("KDE_SESSION_VERSION").toInt();
+ QString kdeDefault = kdeVersion >= 4 ? QString::fromLatin1("oxygen") : QString::fromLatin1("crystalsvg");
+ QString defaultTheme = fileInfo.exists() ? dir.dirName() : kdeDefault;
+ QSettings settings(kdeHome() + QLatin1String("/share/config/kdeglobals"), QSettings::IniFormat);
+ settings.beginGroup(QLatin1String("Icons"));
+ themeName = settings.value(QLatin1String("Theme"), defaultTheme).toString();
+#endif
+}
+
+QIconTheme QtIconLoaderImplementation::parseIndexFile(const QString &themeName) const
+{
+ QIconTheme theme;
+ QFile themeIndex;
+ QStringList parents;
+ QHash <int, QString> dirList;
+ for ( int i = 0 ; i < iconDirs.size() && !themeIndex.exists() ; ++i) {
+ const QString &contentDir = QLatin1String(iconDirs[i].startsWith(QDir::homePath()) ? "/.icons/" : "/icons/");
+ themeIndex.setFileName(iconDirs[i] + contentDir + themeName + QLatin1String("/index.theme"));
+ }
+
+ if (themeIndex.open(QIODevice::ReadOnly | QIODevice::Text)) {
+
+ QTextStream in(&themeIndex);
+
+ while (!in.atEnd()) {
+
+ QString line = in.readLine();
+
+ if (line.startsWith(QLatin1String("Inherits="))) {
+ line = line.right(line.length() - 9);
+ parents = line.split(QLatin1Char(','));
+ }
+
+ if (line.startsWith(QLatin1String("["))) {
+ line = line.trimmed();
+ line.chop(1);
+ QString dirName = line.right(line.length() - 1);
+ if (!in.atEnd()) {
+ line = in.readLine();
+ int size;
+ if (line.startsWith(QLatin1String("Size="))) {
+ size = line.right(line.length() - 5).toInt();
+ if (size)
+ dirList.insertMulti(size, dirName);
+ }
+ }
+ }
+ }
+ }
+
+ if (kdeVersion() >= 3) {
+ QFileInfo fileInfo(QLatin1String("/usr/share/icons/default.kde"));
+ QDir dir(fileInfo.canonicalFilePath());
+ QString defaultKDETheme = dir.exists() ? dir.dirName() : kdeVersion() == 3 ?
+ QString::fromLatin1("crystalsvg") : QString::fromLatin1("oxygen");
+ if (!parents.contains(defaultKDETheme) && themeName != defaultKDETheme)
+ parents.append(defaultKDETheme);
+ } else if (parents.isEmpty() && themeName != QLatin1String("hicolor")) {
+ parents.append(QLatin1String("hicolor"));
+ }
+
+ theme = QIconTheme(dirList, parents);
+ return theme;
+}
+
+QPixmap QtIconLoaderImplementation::findIconHelper(int size, const QString &themeName,
+ const QString &iconName, QStringList &visited) const
+{
+ QPixmap pixmap;
+
+ if (!themeName.isEmpty()) {
+ visited << themeName;
+ QIconTheme theme = themeList.value(themeName);
+
+ if (!theme.isValid()) {
+ theme = parseIndexFile(themeName);
+ themeList.insert(themeName, theme);
+ }
+
+ if (!theme.isValid())
+ return QPixmap();
+
+ QList <QString> subDirs = theme.dirList().values(size);
+
+ for ( int i = 0 ; i < iconDirs.size() ; ++i) {
+ for ( int j = 0 ; j < subDirs.size() ; ++j) {
+ QString contentDir = (iconDirs[i].startsWith(QDir::homePath())) ?
+ QLatin1String("/.icons/") : QLatin1String("/icons/");
+ QString fileName = iconDirs[i] + contentDir + themeName + QLatin1Char('/') + subDirs[j] + QLatin1Char('/') + iconName;
+ QFile file(fileName);
+ if (file.exists())
+ pixmap.load(fileName);
+ if (!pixmap.isNull())
+ break;
+ }
+ }
+
+ if (pixmap.isNull()) {
+ QStringList parents = theme.parents();
+ //search recursively through inherited themes
+ for (int i = 0 ; pixmap.isNull() && i < parents.size() ; ++i) {
+ QString parentTheme = parents[i].trimmed();
+ if (!visited.contains(parentTheme)) //guard against endless recursion
+ pixmap = findIconHelper(size, parentTheme, iconName, visited);
+ }
+ }
+ }
+ return pixmap;
+}
+
+QPixmap QtIconLoaderImplementation::findIcon(int size, const QString &name) const
+{
+ QPixmap pixmap;
+ QString pixmapName = QLatin1String("$qt") + name + QString::number(size);
+ if (QPixmapCache::find(pixmapName, pixmap))
+ return pixmap;
+
+ if (!themeName.isEmpty()) {
+ QStringList visited;
+ pixmap = findIconHelper(size, themeName, name, visited);
+ }
+ QPixmapCache::insert(pixmapName, pixmap);
+ return pixmap;
+}
+#endif //Q_WS_X11
diff --git a/src/utils/iconloader/qticonloader.h b/src/utils/iconloader/qticonloader.h
new file mode 100644
index 0000000..67c8f05
--- /dev/null
+++ b/src/utils/iconloader/qticonloader.h
@@ -0,0 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtIconLoader project on Qt Software Labs.
+**
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License versions 2.0 or 3.0 as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information
+** to ensure GNU General Public Licensing requirements will be met:
+** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
+** http://www.gnu.org/copyleft/gpl.html. In addition, as a special
+** exception, Nokia gives you certain additional rights. These rights
+** are described in the Nokia Qt GPL Exception version 1.3, included in
+** the file GPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef QTICONLOADER_H
+#define QTICONLOADER_H
+
+#include <QtGui/QIcon>
+
+// This is the QtIconLoader
+// Version 0.1
+//
+
+class QtIconLoader
+{
+public:
+ static QIcon icon(const QString &name, const QIcon &fallback = QIcon());
+};
+
+#endif // QTICONLOADER_H
diff --git a/src/utils/iconprovider.cpp b/src/utils/iconprovider.cpp
deleted file mode 100644
index 9830fa2..0000000
--- a/src/utils/iconprovider.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright (C) 2008 Lukas Lalinsky
-// Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
-//
-// This program 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 2 of the License, or
-// at your option) any later version.
-//
-// This program 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 this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-#include <cstdlib>
-#include <QDebug>
-#include <QIcon>
-#include <QDir>
-#include <QVariant>
-#include <QLibrary>
-#include <QApplication>
-#include "iconprovider.h"
-
-using namespace std;
-
-#ifdef Q_WS_X11
-extern "C" {
- struct GConfClient;
- struct GError;
- typedef void (*Ptr_g_type_init)();
- typedef GConfClient* (*Ptr_gconf_client_get_default)();
- typedef char* (*Ptr_gconf_client_get_string)(GConfClient*, const char*, GError **);
- typedef void (*Ptr_g_object_unref)(void *);
- typedef void (*Ptr_g_error_free)(GError *);
- typedef void (*Ptr_g_free)(void*);
-}
-
-static Ptr_g_type_init p_g_type_init = 0;
-static Ptr_gconf_client_get_default p_gconf_client_get_default = 0;
-static Ptr_gconf_client_get_string p_gconf_client_get_string = 0;
-static Ptr_g_object_unref p_g_object_unref = 0;
-static Ptr_g_error_free p_g_error_free = 0;
-static Ptr_g_free p_g_free = 0;
-#endif
-
-void IconProvider::gnomeLookupIconTheme()
-{
-#ifdef Q_WS_X11
- if (themeName.isEmpty()) {
- //resolve glib and gconf functions
- p_g_type_init = (Ptr_g_type_init)QLibrary::resolve(QLatin1String("gobject-2.0"), 0, "g_type_init");
- p_gconf_client_get_default = (Ptr_gconf_client_get_default)QLibrary::resolve(QLatin1String("gconf-2"), 4, "gconf_client_get_default");
- p_gconf_client_get_string = (Ptr_gconf_client_get_string)QLibrary::resolve(QLatin1String("gconf-2"), 4, "gconf_client_get_string");
- p_g_object_unref = (Ptr_g_object_unref)QLibrary::resolve(QLatin1String("gobject-2.0"), 0, "g_object_unref");
- p_g_error_free = (Ptr_g_error_free)QLibrary::resolve(QLatin1String("glib-2.0"), 0, "g_error_free");
- p_g_free = (Ptr_g_free)QLibrary::resolve(QLatin1String("glib-2.0"), 0, "g_free");
-
- if (p_g_type_init &&
- p_gconf_client_get_default &&
- p_gconf_client_get_string &&
- p_g_object_unref &&
- p_g_error_free &&
- p_g_free) {
-
- p_g_type_init();
- GConfClient* client = p_gconf_client_get_default();
- GError *err = 0;
- char *str = p_gconf_client_get_string(client, "/desktop/gnome/interface/icon_theme", &err);
- if (!err) {
- themeName = QString::fromUtf8(str);
- p_g_free(str);
- }
- p_g_object_unref(client);
- if (err)
- p_g_error_free (err);
- }
- if (themeName.isEmpty())
- themeName = QLatin1String("gnome");
- }
-#endif
-}
-
-IconProvider::IconProvider()
-{
-#ifdef Q_WS_X11
- if (getenv("GNOME_DESKTOP_SESSION_ID")) {
- gnomeLookupIconTheme();
- }
- else if (getenv("KDE_FULL_SESSION")) {
- // FIXME
- }
- if (!themeName.isEmpty()) {
- iconDirs << QDir::homePath() + "/.icons/";
- iconDirs << "/usr/share/icons/";
- }
-#endif
-}
-
-QIcon
-IconProvider::findIcon(int size, const QString &name)
-{
-#ifdef Q_WS_X11
- IconProvider *iconProvider = instance();
- QString sizeString = QString("/%1x%2/").arg(size).arg(size);
- foreach(QString path, iconProvider->iconDirs) {
- QString fullPath = path + iconProvider->themeName + sizeString + "actions/" + name;
- if (QFile::exists(fullPath)) {
- return QIcon(fullPath);
- }
- }
-#endif
- return QIcon(":/icons" + sizeString + name);
-}
diff --git a/src/utils/iconprovider.h b/src/utils/iconprovider.h
deleted file mode 100644
index 862c880..0000000
--- a/src/utils/iconprovider.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (C) 2008 Lukas Lalinsky
-// Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
-//
-// This program 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 2 of the License, or
-// at your option) any later version.
-//
-// This program 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 this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-#include <QString>
-#include "singelton.h"
-
-class IconProvider : public Singelton<IconProvider>
-{
-public:
- static QIcon findIcon(int size, const QString &name);
-
-protected:
- QString themeName;
- QStringList iconDirs;
-
-private:
- void gnomeLookupIconTheme();
- IconProvider();
- friend class Singelton<IconProvider>;
-};
diff --git a/src/utils/utils.pri b/src/utils/utils.pri
index 49a0e7f..d8ce23e 100644
--- a/src/utils/utils.pri
+++ b/src/utils/utils.pri
@@ -1,10 +1,8 @@
DEPENDPATH += $$PWD
-SOURCES += \
- iconprovider.cpp
+include(iconloader/iconloader.pri)
HEADERS += \
- iconprovider.h \
factory.h \
range.h \
singelton.h