Commit 18b22385 authored by Xuetian Weng's avatar Xuetian Weng
Browse files

kimpanel: fix some gtk icon, and wrong logo update

normalize gtk-stock-icon to xdg-ones which is not supported by kde.
icon name mapping is taken from:
https://docs.google.com/spreadsheet/pub?key=0AsPAM3pPwxagdGF4THNMMUpjUW5xMXZfdUNzMXhEa2c&output=html
clean up logo_prop and fix the update of logo.
parent 3a93fc1d
......@@ -93,6 +93,89 @@ ibus_disconnected_cb (IBusBus *m_bus,
app->finalize();
}
static void initIconMap(QMap<QByteArray, QByteArray>& iconMap)
{
iconMap["gtk-about"] = "help-about";
iconMap["gtk-add"] = "list-add";
iconMap["gtk-bold"] = "format-text-bold";
iconMap["gtk-cdrom"] = "media-optical";
iconMap["gtk-clear"] = "edit-clear";
iconMap["gtk-close"] = "window-close";
iconMap["gtk-copy"] = "edit-copy";
iconMap["gtk-cut"] = "edit-cut";
iconMap["gtk-delete"] = "edit-delete";
iconMap["gtk-dialog-authentication"] = "dialog-password";
iconMap["gtk-dialog-info"] = "dialog-information";
iconMap["gtk-dialog-warning"] = "dialog-warning";
iconMap["gtk-dialog-error"] = "dialog-error";
iconMap["gtk-dialog-question"] = "dialog-question";
iconMap["gtk-directory"] = "folder";
iconMap["gtk-execute"] = "system-run";
iconMap["gtk-file"] = "text-x-generic";
iconMap["gtk-find"] = "edit-find";
iconMap["gtk-find-and-replace"] = "edit-find-replace";
iconMap["gtk-floppy"] = "media-floppy";
iconMap["gtk-fullscreen"] = "view-fullscreen";
iconMap["gtk-goto-bottom"] = "go-bottom";
iconMap["gtk-goto-first"] = "go-first";
iconMap["gtk-goto-last"] = "go-last";
iconMap["gtk-goto-top"] = "go-top";
iconMap["gtk-go-back"] = "go-previous";
iconMap["gtk-go-down"] = "go-down";
iconMap["gtk-go-forward"] = "go-next";
iconMap["gtk-go-up"] = "go-up";
iconMap["gtk-harddisk"] = "drive-harddisk";
iconMap["gtk-help"] = "help-browser";
iconMap["gtk-home"] = "go-home";
iconMap["gtk-indent"] = "format-indent-more";
iconMap["gtk-info"] = "dialog-information";
iconMap["gtk-italic"] = "format-text-italic";
iconMap["gtk-jump-to"] = "go-jump";
iconMap["gtk-justify-center"] = "format-justify-center";
iconMap["gtk-justify-fill"] = "format-justify-fill";
iconMap["gtk-justify-left"] = "format-justify-left";
iconMap["gtk-justify-right"] = "format-justify-right";
iconMap["gtk-leave-fullscreen"] = "view-restore";
iconMap["gtk-missing-image"] = "image-missing";
iconMap["gtk-media-forward"] = "media-seek-forward";
iconMap["gtk-media-next"] = "media-skip-forward";
iconMap["gtk-media-pause"] = "media-playback-pause";
iconMap["gtk-media-play"] = "media-playback-start";
iconMap["gtk-media-previous"] = "media-skip-backward";
iconMap["gtk-media-record"] = "media-record";
iconMap["gtk-media-rewind"] = "media-seek-backward";
iconMap["gtk-media-stop"] = "media-playback-stop";
iconMap["gtk-network"] = "network-workgroup";
iconMap["gtk-new"] = "document-new";
iconMap["gtk-open"] = "document-open";
iconMap["gtk-page-setup"] = "document-page-setup";
iconMap["gtk-paste"] = "edit-paste";
iconMap["gtk-preferences"] = "preferences-system";
iconMap["gtk-print"] = "document-print";
iconMap["gtk-print-error"] = "printer-error";
iconMap["gtk-properties"] = "document-properties";
iconMap["gtk-quit"] = "application-exit";
iconMap["gtk-redo"] = "edit-redo";
iconMap["gtk-refresh"] = "view-refresh";
iconMap["gtk-remove"] = "list-remove";
iconMap["gtk-revert-to-saved"] = "document-revert";
iconMap["gtk-save"] = "document-save";
iconMap["gtk-save-as"] = "document-save-as";
iconMap["gtk-select-all"] = "edit-select-all";
iconMap["gtk-sort-ascending"] = "view-sort-ascending";
iconMap["gtk-sort-descending"] = "view-sort-descending";
iconMap["gtk-spell-check"] = "tools-check-spelling";
iconMap["gtk-stop"] = "process-stop";
iconMap["gtk-strikethrough"] = "format-text-strikethrough";
iconMap["gtk-underline"] = "format-text-underline";
iconMap["gtk-undo"] = "edit-undo";
iconMap["gtk-unindent"] = "format-indent-less";
iconMap["gtk-zoom-100"] = "zoom-original";
iconMap["gtk-zoom-fit"] = "zoom-fit-best";
iconMap["gtk-zoom-in"] = "zoom-in";
iconMap["gtk-zoom-out"] = "zoom-out";
}
App::App(int argc, char** argv): QGuiApplication(argc, argv)
,m_eventFilter(new XcbEventFilter)
,m_init(false)
......@@ -111,6 +194,8 @@ App::App(int argc, char** argv): QGuiApplication(argc, argv)
if (ibus_bus_is_connected (m_bus)) {
init();
}
initIconMap(m_iconMap);
}
uint App::getPrimaryModifier(uint state)
......@@ -248,6 +333,15 @@ void App::nameLost()
m_impanel = NULL;
}
QByteArray App::normalizeIconName(const QByteArray& icon) const
{
if (m_iconMap.contains(icon)) {
return m_iconMap[icon];
}
return icon;
}
void App::setTriggerKeys(QList< TriggerKey > triggersList)
{
if (m_doGrab) {
......
......@@ -26,6 +26,8 @@
#include <QAbstractNativeEventFilter>
#include <QGuiApplication>
#include <QMap>
#include <QByteArray>
#include <QPair>
#include "panel.h"
......@@ -49,6 +51,7 @@ public:
void init();
void nameAcquired();
void nameLost();
QByteArray normalizeIconName(const QByteArray& icon) const;
private Q_SLOTS:
void clean();
void grabKey();
......@@ -67,6 +70,7 @@ private:
bool m_keyboardGrabbed;
bool m_doGrab;
xcb_key_symbols_t* m_syms;
QMap<QByteArray, QByteArray> m_iconMap;
};
#endif // APP_H
......@@ -44,7 +44,6 @@ struct _IBusPanelImpanel {
IBusPanelService parent;
IBusBus *bus;
GDBusConnection *conn;
IBusProperty *logo_prop;
PropertyManager* propManager;
EngineManager* engineManager;
XkbLayoutManager* xkbLayoutManager;
......@@ -64,8 +63,10 @@ impanel_set_engine(IBusPanelImpanel* impanel, const char* name);
static QByteArray
ibus_property_to_propstr (IBusProperty *property,
gboolean useSymbol = FALSE,
IBusEngineDesc* engine = NULL);
gboolean useSymbol = FALSE);
static QByteArray
ibus_engine_desc_to_logo_propstr(IBusEngineDesc* engine);
void
impanel_update_logo_by_engine(IBusPanelImpanel* impanel, IBusEngineDesc* engine_desc)
......@@ -74,14 +75,7 @@ impanel_update_logo_by_engine(IBusPanelImpanel* impanel, IBusEngineDesc* engine_
return;
}
const gchar* icon_name = "input-keyboard";
if (engine_desc) {
icon_name = ibus_engine_desc_get_icon (engine_desc);
}
ibus_property_set_icon (impanel->logo_prop, icon_name);
QByteArray propstr = ibus_property_to_propstr(impanel->logo_prop, TRUE, engine_desc);
QByteArray propstr = ibus_engine_desc_to_logo_propstr(engine_desc);
g_dbus_connection_emit_signal (impanel->conn,
NULL, "/kimpanel", "org.kde.kimpanel.inputmethod", "UpdateProperty",
......@@ -271,32 +265,81 @@ ibus_property_args_to_propstr (const char *key,
QByteArray propstr("/IBus/");
QByteArray str(key);
str.replace(':', '!');
propstr += str.constData();
App* app = static_cast<App*>(qApp);
propstr += str;
propstr += prop_sep;
propstr += label;
propstr += QByteArray(label).replace(':', '-').constData();
propstr += prop_sep;
propstr += icon;
propstr += app->normalizeIconName(QByteArray(icon).replace(':', '-'));
propstr += prop_sep;
propstr += tooltip;
propstr += QByteArray(tooltip).replace(':', '-').constData();
return propstr;
}
static QByteArray
ibus_engine_desc_to_logo_propstr(IBusEngineDesc* engine)
{
const gchar* label = "IBus";
const gchar* tooltip = "";
const gchar* icon = "input-keyboard";
gchar xkbLabel[3];
if (engine) {
const gchar* iconname = ibus_engine_desc_get_icon(engine);
if (iconname && iconname[0]) {
icon = iconname;
}
if (strncmp("xkb:", ibus_engine_desc_get_name(engine), 4) == 0) {
strncpy(xkbLabel, ibus_engine_desc_get_name(engine) + 4, 2);
xkbLabel[2] = 0;
int i = 0;
while (xkbLabel[i]) {
if (xkbLabel[i] == ':') {
xkbLabel[i] = 0;
}
i++;
}
label = xkbLabel;
icon = "";
}
const gchar* longname = ibus_engine_desc_get_longname(engine);
if (longname && longname[0]) {
tooltip = longname;
}
}
return ibus_property_args_to_propstr("Logo",
label,
icon,
tooltip);
}
static QByteArray
ibus_property_to_propstr (IBusProperty *property,
gboolean useSymbol,
IBusEngineDesc* engine)
gboolean useSymbol)
{
const gchar* label = ibus_text_get_text (useSymbol ? ibus_property_get_symbol (property) : ibus_property_get_label(property));
const gchar* label = NULL;
const gchar* tooltip = ibus_text_get_text (ibus_property_get_tooltip (property));
const gchar* icon = ibus_property_get_icon (property);
if (engine && strncmp("xkb:", ibus_engine_desc_get_name(engine), 4) == 0) {
label = ibus_engine_desc_get_name(engine) + 4;
icon = "";
if (useSymbol) {
label = ibus_text_get_text(ibus_property_get_symbol (property));
if (!label || label[0] == '\0') {
label = ibus_text_get_text(ibus_property_get_label(property));
}
} else {
label = ibus_text_get_text(ibus_property_get_label(property));
}
return ibus_property_args_to_propstr(ibus_property_get_key (property),
label,
icon,
ibus_text_get_text (ibus_property_get_tooltip (property)));
tooltip);
}
static QByteArray
......@@ -961,17 +1004,6 @@ ibus_panel_impanel_init (IBusPanelImpanel *impanel)
on_name_lost,
impanel, NULL);
// some custom property
impanel->logo_prop = ibus_property_new ("Logo",
PROP_TYPE_NORMAL,
ibus_text_new_from_string ("IBus"),
"ibus",
ibus_text_new_from_string ("IBus input method"),
FALSE,
FALSE,
PROP_STATE_UNCHECKED,
NULL);
impanel->propManager = new PropertyManager;
impanel->engineManager = new EngineManager;
impanel->xkbLayoutManager = new XkbLayoutManager;
......@@ -980,8 +1012,6 @@ ibus_panel_impanel_init (IBusPanelImpanel *impanel)
static void
ibus_panel_impanel_destroy (IBusPanelImpanel *impanel)
{
g_object_unref (impanel->logo_prop);
impanel->logo_prop = NULL;
delete impanel->propManager;
impanel->propManager = NULL;
delete impanel->engineManager;
......@@ -1049,7 +1079,13 @@ ibus_panel_impanel_real_register_properties(IBusPanelImpanel* impanel)
GVariantBuilder builder;
g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
QByteArray propstr = ibus_property_to_propstr(impanel->logo_prop, TRUE);
IBusEngineDesc* engine_desc = NULL;
if (impanel->selected >= 0 && static_cast<size_t>(impanel->selected) < impanel->engineManager->length()) {
engine_desc = impanel->engineManager->engines()[impanel->selected];
} else {
engine_desc = ibus_bus_get_global_engine(impanel->bus);
}
QByteArray propstr = ibus_engine_desc_to_logo_propstr(engine_desc);
g_variant_builder_add (&builder, "s", propstr.constData());
IBusPropList* prop_list = impanel->propManager->properties();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment