Revision: 6702
Author: ek.kato
Date: Mon Aug 9 21:19:47 2010
Log: * scm/im-custom.scm
- (toolbar-icon) : New subgroup.
- (toolbar-icon-for-dark-background?) : New setting.
* qt/toolbar-common-uimstateindicator.cpp
- (UimStateIndicator::parseHelperStr) : Reload config.
- (UimStateIndicator::propListUpdate) : Use icon for dark
background if requested.
- (QHelperPopupMenu::insertHelperItem) : Ditto.
* qt4/toolbar/common-uimstateindicator.cpp
- Likewise.
* helper/toolbar-common-gtk.c
- (helper_toolbar_check_custom) : Add check for icon.
- (helper_toolbar_parse_helper_str) : Reset icon when custom
changes.
- (register_icon) : Use icon for dark background if requested.
- (reset_icon) : New.
- (toolbar_new) : Check custom before setting icon.
http://code.google.com/p/uim/source/detail?r=6702
Modified:
/trunk/helper/toolbar-common-gtk.c
/trunk/qt/toolbar-common-uimstateindicator.cpp
/trunk/qt4/toolbar/common-uimstateindicator.cpp
/trunk/scm/im-custom.scm
=======================================
--- /trunk/helper/toolbar-common-gtk.c Fri Jul 30 01:15:11 2010
+++ /trunk/helper/toolbar-common-gtk.c Mon Aug 9 21:19:47 2010
@@ -37,6 +37,7 @@
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
+#include <sys/stat.h>
#include <uim/uim.h>
#include "uim/uim-helper.h"
@@ -151,10 +152,12 @@
static GList *uim_icon_list;
static gboolean prop_menu_showing = FALSE;
static gboolean custom_enabled;
+static gboolean with_dark_bg;
static const char *safe_gettext(const char *msgid);
static gboolean has_n_strs(gchar **str_list, guint n);
static gboolean register_icon(const gchar *name);
+static void reset_icon(void);
static const char *
safe_gettext(const char *msgid)
@@ -780,6 +783,9 @@
for (i = 0; i < command_entry_len; i++)
command_entry[i].show_button =
uim_scm_symbol_value_bool(command_entry[i].custom_button_show_symbol);
+
+ with_dark_bg =
+ uim_scm_symbol_value_bool("toolbar-icon-for-dark-background?");
}
static void
@@ -794,6 +800,7 @@
else if (!strcmp("custom_reload_notify", lines[0])) {
uim_prop_reload_configs();
helper_toolbar_check_custom();
+ reset_icon();
}
g_strfreev(lines);
}
@@ -905,6 +912,7 @@
GtkIconSet *icon_set;
GdkPixbuf *pixbuf;
GString *filename;
+ struct stat st;
g_return_val_if_fail(uim_factory, FALSE);
@@ -913,8 +921,18 @@
filename = g_string_new(UIM_PIXMAPSDIR "/");
g_string_append(filename, name);
+ if (with_dark_bg) {
+ g_string_append(filename, "_dark_background");
+ }
g_string_append(filename, ".png");
+ if (with_dark_bg && stat(filename->str, &st) == -1) {
+ g_string_free(filename, TRUE);
+ filename = g_string_new(UIM_PIXMAPSDIR "/");
+ g_string_append(filename, name);
+ g_string_append(filename, ".png");
+ }
+
pixbuf = gdk_pixbuf_new_from_file(filename->str, NULL);
if (!pixbuf) {
g_string_free(filename, TRUE);
@@ -947,6 +965,22 @@
register_icon("uim-dict");
register_icon("null");
}
+
+static void
+reset_icon(void)
+{
+ g_list_foreach(uim_icon_list, (GFunc)g_free, NULL);
+ g_list_free(uim_icon_list);
+ uim_icon_list = NULL;
+
+ if (GTK_IS_ICON_FACTORY(uim_factory)) {
+ gtk_icon_factory_remove_default(uim_factory);
+ g_object_unref(uim_factory);
+ uim_factory = NULL;
+ init_icon();
+ }
+}
+
static GtkWidget *
toolbar_new(gint type)
@@ -966,6 +1000,7 @@
custom_enabled = (gboolean)uim_custom_enable();
#endif
+ helper_toolbar_check_custom();
init_icon();
/* create widgets */
@@ -1003,8 +1038,6 @@
g_object_set_data(G_OBJECT(hbox), OBJECT_DATA_TOOLBAR_TYPE,
GINT_TO_POINTER(type));
- helper_toolbar_check_custom();
-
uim_fd = -1;
if (type != TYPE_ICON) {
=======================================
--- /trunk/qt/toolbar-common-uimstateindicator.cpp Sun Apr 4 20:35:54 2010
+++ /trunk/qt/toolbar-common-uimstateindicator.cpp Mon Aug 9 21:19:47 2010
@@ -33,6 +33,7 @@
#include <config.h>
#include "toolbar-common-uimstateindicator.h"
+#include <uim/uim-scm.h>
#include <qsocketnotifier.h>
#include <qstring.h>
@@ -44,6 +45,7 @@
#include <string.h>
#include <stdlib.h>
+#include <sys/stat.h>
static const QString ICONDIR = UIM_PIXMAPSDIR;
static int uim_fd;
@@ -113,6 +115,8 @@
{
if ( lines[ 0 ] == "prop_list_update" )
propListUpdate( lines );
+ else if ( lines[ 0 ] == "custom_reload_notify" )
+ uim_prop_reload_configs();
}
}
@@ -155,7 +159,15 @@
buttons.append( button );
size_changed = true;
}
- QPixmap icon = QPixmap( ICONDIR + "/" + fields[1] + ".png"
);
+ uim_bool isDarkBg =
uim_scm_symbol_value_bool("toolbar-icon-for-dark-background?");
+ const QString append = isDarkBg ? "_dark_background" : "";
+ QString fileName = ICONDIR + "/" + fields[1] + append
+ ".png";
+ struct stat st;
+ if ( isDarkBg && stat( fileName.utf8(), &st ) == -1 )
+ {
+ fileName = ICONDIR + "/" + fields[1] + ".png";
+ }
+ QPixmap icon = QPixmap( fileName );
if (!icon.isNull()) {
QImage image = icon.convertToImage();
QPixmap scaledIcon = image.smoothScale( ICON_SIZE,
@@ -277,7 +289,16 @@
const QString &menucommandStr )
{
int id;
- QPixmap icon = QPixmap( ICONDIR + "/" + indicationIdStr + ".png" );
+ uim_bool isDarkBg =
+ uim_scm_symbol_value_bool("toolbar-icon-for-dark-background?");
+ const QString append = isDarkBg ? "_dark_background" : "";
+ QString fileName = ICONDIR + "/" + indicationIdStr + append + ".png";
+ struct stat st;
+ if ( isDarkBg && stat( fileName.utf8(), &st ) == -1 )
+ {
+ fileName = ICONDIR + "/" + indicationIdStr + ".png";
+ }
+ QPixmap icon = QPixmap( fileName );
if (!icon.isNull()) {
QImage image = icon.convertToImage();
=======================================
--- /trunk/qt4/toolbar/common-uimstateindicator.cpp Fri Jul 23 22:59:29 2010
+++ /trunk/qt4/toolbar/common-uimstateindicator.cpp Mon Aug 9 21:19:47 2010
@@ -33,6 +33,7 @@
#include <config.h>
#include "common-uimstateindicator.h"
+#include <uim/uim-scm.h>
#include <QtCore/QSocketNotifier>
#include <QtCore/QString>
@@ -45,6 +46,7 @@
#include <cstring>
#include <cstdlib>
+#include <sys/stat.h>
#include "qtgettext.h"
@@ -132,6 +134,8 @@
{
if ( lines[ 0 ] == "prop_list_update" )
propListUpdate( lines );
+ else if (lines[0] == "custom_reload_notify" )
+ uim_prop_reload_configs();
}
}
@@ -173,7 +177,17 @@
QHelperToolbarButton *button = new QHelperToolbarButton;
m_layout->addWidget( button );
buttons.append( button );
- QPixmap icon = QPixmap( ICONDIR + '/' + fields[1] + ".png"
);
+
+ uim_bool isDarkBg =
+
uim_scm_symbol_value_bool("toolbar-icon-for-dark-background?");
+ const QString append = isDarkBg ? "_dark_background" : "";
+ QString fileName = ICONDIR + '/' + fields[1] + append
+ ".png";
+ struct stat st;
+ if ( isDarkBg && stat( fileName.toUtf8().data(), &st ) ==
-1 )
+ {
+ fileName = ICONDIR + '/' + fields[1] + ".png";
+ }
+ QPixmap icon = QPixmap( fileName );
if (!icon.isNull()) {
QImage image = icon.toImage();
QPixmap scaledIcon = QPixmap::fromImage(
@@ -330,7 +344,16 @@
const QString &menucommandStr )
{
QAction *action;
- QPixmap icon = QPixmap( ICONDIR + '/' + indicationIdStr + ".png" );
+ uim_bool isDarkBg =
+ uim_scm_symbol_value_bool("toolbar-icon-for-dark-background?");
+ const QString append = isDarkBg ? "_dark_background" : "";
+ QString fileName = ICONDIR + '/' + indicationIdStr + append + ".png";
+ struct stat st;
+ if ( isDarkBg && stat( fileName.toUtf8().data(), &st ) == -1 )
+ {
+ fileName = ICONDIR + '/' + indicationIdStr + ".png";
+ }
+ QPixmap icon = QPixmap ( fileName );
if (!icon.isNull()) {
QImage image = icon.toImage();
=======================================
--- /trunk/scm/im-custom.scm Mon Aug 9 18:14:10 2010
+++ /trunk/scm/im-custom.scm Mon Aug 9 21:19:47 2010
@@ -130,6 +130,11 @@
(N_ "Help")
(N_ "long description will be here."))
+;; subgroup
+(define-custom-group 'toolbar-icon
+ (N_ "Icon")
+ (N_ "long description will be here."))
+
;; subgroup
(define-custom-group 'toolbar-widget
(N_ "Toolbar")
@@ -530,6 +535,12 @@
(lambda ()
(eq? toolbar-help-browser 'manual)))
+(define-custom 'toolbar-icon-for-dark-background? #f
+ '(toolbar toolbar-icon)
+ '(boolean)
+ (N_ "Use icon for dark background")
+ (N_ "long description will be here."))
+
(define-custom 'bridge-show-input-state? #f
'(global visual-preference)
'(boolean)