Remove dependency on gtk

Change-Id: Ic87401a0c7f192951fcdb86cd45bf1f870e06779
This commit is contained in:
Hualet Wang 2017-02-15 17:10:32 +08:00
parent 4624920533
commit 395cd66b23
Notes: Deepin Code Review 2017-02-16 10:49:09 +08:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: Hualet Wang <mr.asianwang@gmail.com>
Submitted-by: Hualet Wang <mr.asianwang@gmail.com>
Submitted-at: Thu, 16 Feb 2017 10:49:09 +0800
Reviewed-on: https://cr.deepin.io/20233
Project: dde/dde-dock
Branch: refs/heads/master
7 changed files with 24 additions and 199 deletions

1
debian/control vendored
View File

@ -4,7 +4,6 @@ Priority: optional
Maintainer: Deepin Sysdev <sysdev@deepin.com>
Build-Depends: debhelper (>= 8.0.0), pkg-config,
qt5-qmake, qt5-default,
libgtk2.0-dev,
libxcb-image0-dev, libxcb-composite0-dev,
libxcb-ewmh-dev, libqt5x11extras5-dev,
libxcb-damage0-dev, libqt5svg5-dev,

View File

@ -8,7 +8,7 @@ DESTDIR = $$_PRO_FILE_PWD_/../
TEMPLATE = app
CONFIG += c++11 link_pkgconfig
PKGCONFIG += xcb-ewmh gtk+-2.0 dtkwidget dtkbase dtkutil
PKGCONFIG += xcb-ewmh dtkwidget dtkbase dtkutil
SOURCES += main.cpp \
window/mainwindow.cpp \

View File

@ -53,8 +53,6 @@ int main(int argc, char *argv[])
QDir::setCurrent(QApplication::applicationDirPath());
#endif
ThemeAppIcon::gtkInit();
MainWindow mw;
DBusDockAdaptors adaptor(&mw);
QDBusConnection::sessionBus().registerService("com.deepin.dde.Dock");

View File

@ -5,11 +5,14 @@
#include <QDebug>
#include <QX11Info>
#include <DApplication>
#define ICON_SIZE_LARGE 48
#define ICON_SIZE_MEDIUM 36
#define ICON_SIZE_SMALL 30
#define FASHION_MODE_PADDING 30
#define PROP_GTK_ICON_THEME_NAME "gtk-icon-theme-name"
DWIDGET_USE_NAMESPACE
DockSettings::DockSettings(QWidget *parent)
: QObject(parent),
@ -107,9 +110,10 @@ DockSettings::DockSettings(QWidget *parent)
connect(m_displayInter, &DBusDisplay::ScreenHeightChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
connect(m_displayInter, &DBusDisplay::ScreenWidthChanged, this, &DockSettings::primaryScreenChanged, Qt::QueuedConnection);
// monitor gtk icon theme changed
GtkSettings *gs = gtk_settings_get_default();
g_signal_connect(gs, "notify::" PROP_GTK_ICON_THEME_NAME, G_CALLBACK(gtkIconThemeChanged), m_itemController);
DApplication *app = qobject_cast<DApplication*>(qApp);
if (app) {
connect(app, &DApplication::iconThemeChanged, this, &DockSettings::gtkIconThemeChanged);
}
calculateWindowConfig();
resetFrontendGeometry();
@ -445,13 +449,7 @@ void DockSettings::calculateWindowConfig()
resetFrontendGeometry();
}
void DockSettings::gtkIconThemeChanged(GtkSettings *gs, GParamSpec *pspec, gpointer udata)
void DockSettings::gtkIconThemeChanged()
{
Q_UNUSED(gs)
Q_ASSERT(udata);
Q_ASSERT(!strcmp(g_param_spec_get_name(pspec), PROP_GTK_ICON_THEME_NAME));
DockItemController *itemController = static_cast<DockItemController *>(udata);
itemController->refershItemsIcon();
m_itemController->refershItemsIcon();
}

View File

@ -15,17 +15,6 @@
#include <QStyleFactory>
extern "C"
{
#ifdef signals
#undef signals
#endif
#include <gtk/gtk.h>
#undef signals
#define signals public
}
DWIDGET_USE_NAMESPACE
using namespace Dock;
@ -90,7 +79,7 @@ private slots:
private:
void calculateWindowConfig();
static void gtkIconThemeChanged(GtkSettings *gs, GParamSpec *pspec, gpointer udata);
void gtkIconThemeChanged();
private:
int m_iconSize;

View File

@ -1,175 +1,25 @@
#include "themeappicon.h"
#include <QFile>
#include <QPainter>
#include <QSvgRenderer>
#include <QPixmap>
#include <QDir>
#include <QDebug>
#undef signals
extern "C" {
#include <string.h>
#include <gtk/gtk.h>
// #include <gio/gdesktopappinfo.h>
}
#define signals public
//static GtkIconTheme* them = NULL;
//inline char* get_icon_theme_name()
//{
// GtkSettings* gs = gtk_settings_get_default();
// char* name = NULL;
// g_object_get(gs, "gtk-icon-theme-name", &name, NULL);
// return name;
//}
#include <QIcon>
ThemeAppIcon::ThemeAppIcon(QObject *parent) : QObject(parent)
{
}
void ThemeAppIcon::gtkInit(){
gtk_init(NULL, NULL);
gdk_error_trap_push();
}
QPixmap ThemeAppIcon::getIconPixmap(QString iconPath, int width, int height){
Q_ASSERT(false);
if (iconPath.length() == 0){
iconPath = "application-x-desktop";
}
QPixmap pixmap(width, height);
// iconPath is an absolute path of the system
if (QFile::exists(iconPath) && iconPath.contains(QDir::separator())) {
pixmap = QPixmap(iconPath);
} else if (iconPath.startsWith("data:image/")){
// iconPath is a string representing an inline image.
QStringList strs = iconPath.split("base64,");
if (strs.length() == 2) {
QByteArray data = QByteArray::fromBase64(strs.at(1).toLatin1());
pixmap.loadFromData(data);
}
}else {
// try to read the iconPath as a icon name.
QString path = getThemeIconPath(iconPath, width);
if (path.length() == 0){
path = ":/skin/images/application-default-icon.svg";
}
if (path.endsWith(".svg")) {
QSvgRenderer renderer(path);
pixmap.fill(Qt::transparent);
QPainter painter;
painter.begin(&pixmap);
renderer.render(&painter);
painter.end();
qDebug() << "path svg:" << path;
} else {
pixmap.load(path);
}
}
return pixmap;
}
QString ThemeAppIcon::getThemeIconPath(QString iconName, int size)
{
QByteArray bytes = iconName.toUtf8();
char *name = bytes.data();
if (g_path_is_absolute(name))
return g_strdup(name);
g_return_val_if_fail(name != NULL, NULL);
int pic_name_len = strlen(name);
char* ext = strrchr(name, '.');
if (ext != NULL) {
if (g_ascii_strcasecmp(ext+1, "png") == 0 || g_ascii_strcasecmp(ext+1, "svg") == 0 || g_ascii_strcasecmp(ext+1, "jpg") == 0) {
pic_name_len = ext - name;
// qDebug() << "desktop's Icon name should an absoulte path or an basename without extension";
}
}
// In pratice, default icon theme may not gets the right icon path when program starting.
// if (them == NULL)
// them = gtk_icon_theme_new();
// char* icon_theme_name = get_icon_theme_name();
// gtk_icon_theme_set_custom_theme(them, icon_theme_name);
// g_free(icon_theme_name);
char* pic_name = g_strndup(name, pic_name_len);
GtkIconInfo* info = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(), pic_name, size, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
// if (info == NULL) {
// info = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(), pic_name, size, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
// if (info == NULL) {
//// qWarning() << "get gtk icon theme info failed for" << pic_name;
// g_free(pic_name);
// return "";
// }
// }
g_free(pic_name);
char* path = g_strdup(gtk_icon_info_get_filename(info));
#if GTK_MAJOR_VERSION >= 3
g_object_unref(info);
#elif GTK_MAJOR_VERSION == 2
gtk_icon_info_free(info);
#endif
g_debug("get icon from icon theme is: %s", path);
return path;
}
QPixmap ThemeAppIcon::getIcon(const QString iconName, const int size)
{
QString fileName = getThemeIconPath(iconName, size);
if (fileName.isEmpty())
fileName = getThemeIconPath("application-x-desktop", size);
if (iconName.startsWith("data:image/"))
fileName = iconName;
QPixmap pixmap;
if (fileName.startsWith("data:image/")) {
//This icon file is an inline image
QStringList strs = fileName.split("base64,");
if (strs.length() == 2) {
QByteArray data = QByteArray::fromBase64(strs.at(1).toLatin1());
pixmap.loadFromData(data);
}
} else if (fileName.endsWith(".svg", Qt::CaseInsensitive))
pixmap = loadSvg(fileName, size);
else
pixmap = QPixmap(fileName);
if (pixmap.isNull())
pixmap = loadSvg(":/icons/resources/application-x-desktop.svg", size);
return pixmap.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
QPixmap ThemeAppIcon::loadSvg(const QString &fileName, const int size)
{
QPixmap pixmap(size, size);
QSvgRenderer renderer(fileName);
pixmap.fill(Qt::transparent);
QPainter painter;
painter.begin(&pixmap);
renderer.render(&painter);
painter.end();
return pixmap;
}
ThemeAppIcon::~ThemeAppIcon()
{
}
QPixmap ThemeAppIcon::getIcon(const QString iconName, const int size)
{
QIcon icon = QIcon::fromTheme(iconName, QIcon::fromTheme("application-x-desktop"));
QPixmap pix = icon.pixmap(QSize(size, size));
if (pix.isNull()) {
pix = QPixmap(":/icons/resources/application-x-desktop.svg").scaled(size, size);
}
return pix;
}

View File

@ -10,16 +10,7 @@ public:
explicit ThemeAppIcon(QObject *parent = 0);
~ThemeAppIcon();
static void gtkInit();
static QPixmap getIconPixmap(QString iconPath, int width=64, int height=64);
static QString getThemeIconPath(QString iconName, int size=64);
static QPixmap getIcon(const QString iconName, const int size);
static QPixmap loadSvg(const QString &fileName, const int size);
signals:
public slots:
};
#endif // THEMEAPPICON_H