[libgda] Added gdaui_get_icon_for_db_engine()



commit a32f976fa87531f8a8a009371735a8308472f012
Author: Vivien Malerba <malerba gnome-db org>
Date:   Sun Jan 4 16:59:48 2015 +0100

    Added gdaui_get_icon_for_db_engine()

 libgda-ui/data/Bdb.png        |  Bin 0 -> 2853 bytes
 libgda-ui/data/Firebird.png   |  Bin 0 -> 8550 bytes
 libgda-ui/data/LDAP.png       |  Bin 0 -> 5726 bytes
 libgda-ui/data/Makefile.am    |   15 ++++++
 libgda-ui/data/Mariadb.png    |  Bin 0 -> 5738 bytes
 libgda-ui/data/Mdb.png        |  Bin 0 -> 5080 bytes
 libgda-ui/data/MySQL.png      |  Bin 0 -> 2946 bytes
 libgda-ui/data/Oracle.png     |  Bin 0 -> 1540 bytes
 libgda-ui/data/PostgreSQL.png |  Bin 0 -> 10315 bytes
 libgda-ui/data/SQLCipher.png  |  Bin 0 -> 4931 bytes
 libgda-ui/data/SQLite.png     |  Bin 0 -> 3148 bytes
 libgda-ui/data/SqlServer.png  |  Bin 0 -> 6880 bytes
 libgda-ui/data/Web.png        |  Bin 0 -> 15248 bytes
 libgda-ui/gdaui-init.c        |   97 +++++++++++++++++++++++++++++++++++++++++
 libgda-ui/gdaui.gresource.xml |   16 ++++++-
 libgda-ui/libgda-ui.h         |    3 +-
 libgda-ui/libgda-ui.symbols   |    1 +
 17 files changed, 130 insertions(+), 2 deletions(-)
---
diff --git a/libgda-ui/data/Bdb.png b/libgda-ui/data/Bdb.png
new file mode 100644
index 0000000..cf646aa
Binary files /dev/null and b/libgda-ui/data/Bdb.png differ
diff --git a/libgda-ui/data/Firebird.png b/libgda-ui/data/Firebird.png
new file mode 100644
index 0000000..7615c49
Binary files /dev/null and b/libgda-ui/data/Firebird.png differ
diff --git a/libgda-ui/data/LDAP.png b/libgda-ui/data/LDAP.png
new file mode 100644
index 0000000..2913eac
Binary files /dev/null and b/libgda-ui/data/LDAP.png differ
diff --git a/libgda-ui/data/Makefile.am b/libgda-ui/data/Makefile.am
index 07dd304..0e4f3af 100644
--- a/libgda-ui/data/Makefile.am
+++ b/libgda-ui/data/Makefile.am
@@ -8,7 +8,22 @@ icons_DATA= \
 xmldir = $(datadir)/libgda-$(GDA_ABI_MAJOR_VERSION).$(GDA_ABI_MINOR_VERSION)
 xml_DATA = import_encodings.xml
 
+# database engine's icons
+dbicons = Bdb.png \
+       Firebird.png \
+       LDAP.png \
+       Mariadb.png \
+       Mdb.png \
+       MySQL.png \
+       Oracle.png \
+       PostgreSQL.png \
+       SQLite.png \
+       SQLCipher.png \
+       SqlServer.png \
+       Web.png
+
 EXTRA_DIST = \
        $(icons_DATA) \
+       $(dbicons) \
        import_encodings.xml \
        server_operation.xml
diff --git a/libgda-ui/data/Mariadb.png b/libgda-ui/data/Mariadb.png
new file mode 100644
index 0000000..462c049
Binary files /dev/null and b/libgda-ui/data/Mariadb.png differ
diff --git a/libgda-ui/data/Mdb.png b/libgda-ui/data/Mdb.png
new file mode 100644
index 0000000..8897b16
Binary files /dev/null and b/libgda-ui/data/Mdb.png differ
diff --git a/libgda-ui/data/MySQL.png b/libgda-ui/data/MySQL.png
new file mode 100644
index 0000000..3ad548d
Binary files /dev/null and b/libgda-ui/data/MySQL.png differ
diff --git a/libgda-ui/data/Oracle.png b/libgda-ui/data/Oracle.png
new file mode 100644
index 0000000..311d1a0
Binary files /dev/null and b/libgda-ui/data/Oracle.png differ
diff --git a/libgda-ui/data/PostgreSQL.png b/libgda-ui/data/PostgreSQL.png
new file mode 100644
index 0000000..f3f007f
Binary files /dev/null and b/libgda-ui/data/PostgreSQL.png differ
diff --git a/libgda-ui/data/SQLCipher.png b/libgda-ui/data/SQLCipher.png
new file mode 100644
index 0000000..9a820ef
Binary files /dev/null and b/libgda-ui/data/SQLCipher.png differ
diff --git a/libgda-ui/data/SQLite.png b/libgda-ui/data/SQLite.png
new file mode 100644
index 0000000..e0b003a
Binary files /dev/null and b/libgda-ui/data/SQLite.png differ
diff --git a/libgda-ui/data/SqlServer.png b/libgda-ui/data/SqlServer.png
new file mode 100644
index 0000000..38497c8
Binary files /dev/null and b/libgda-ui/data/SqlServer.png differ
diff --git a/libgda-ui/data/Web.png b/libgda-ui/data/Web.png
new file mode 100644
index 0000000..4f01436
Binary files /dev/null and b/libgda-ui/data/Web.png differ
diff --git a/libgda-ui/gdaui-init.c b/libgda-ui/gdaui-init.c
index 60fc5b4..3a4a049 100644
--- a/libgda-ui/gdaui-init.c
+++ b/libgda-ui/gdaui-init.c
@@ -831,3 +831,100 @@ gdaui_set_default_path (const gchar *path)
        if (path)
                gdaui_path = g_strdup (path);
 }
+
+static guint
+nocase_hash (gconstpointer key)
+{
+       gchar *cmp;
+       cmp = g_utf8_casefold ((const gchar*) key, -1);
+       guint retval;
+       retval = g_str_hash (cmp);
+       g_free (cmp);
+       return retval;
+}
+
+static gboolean
+nocase_equal (gconstpointer a, gconstpointer b)
+{
+       gchar *ca, *cb;
+       ca = g_utf8_casefold ((const gchar*) a, -1);
+       cb = g_utf8_casefold ((const gchar*) b, -1);
+
+       gboolean retval;
+       retval = g_str_equal (ca, cb);
+       g_free (ca);
+       g_free (cb);
+       return retval;
+}
+
+/**
+ * gdaui_get_icon_for_db_engine:
+ * @engine: a database engine (case non sensitive), like "PostgreSQL", "MySQL", etc.
+ *
+ * Get an icon for the database engine.
+ *
+ * Returns: (transfer none): a #GdkPixbuf, or %NULL if none found
+ *
+ * Since: 6.0
+ */
+GdkPixbuf *
+gdaui_get_icon_for_db_engine (const gchar *engine)
+{
+       g_return_val_if_fail (engine && *engine, NULL);
+       static GHashTable *icons_hash = NULL;
+       GdkPixbuf *pix;
+
+       if (! icons_hash) {
+               icons_hash = g_hash_table_new_full (nocase_hash, nocase_equal, g_free, g_object_unref);
+               /* add icons from resources */
+               gchar **dbs;
+#define RESOURCES_PREFIX "/gdaui/db-engines/data"
+               dbs = g_resources_enumerate_children (RESOURCES_PREFIX, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
+               if (dbs) {
+                       guint i;
+                       for (i = 0; dbs[i]; i++) {
+                               /* dbs[i] is for example "Firebird.png", we need to grab the key from that */
+                               gchar *path;
+                               path = g_strdup_printf ("%s/%s", RESOURCES_PREFIX, dbs[i]);
+                               pix = gdk_pixbuf_new_from_resource (path, NULL);
+                               g_free (path);
+                               if (pix) {
+                                       gchar *tmp;
+                                       gint len;
+                                       len = strlen (dbs[i]) - 4;
+                                       g_assert (len > 0);
+                                       tmp = dbs[i] + len;
+                                       g_assert (! strcmp (tmp, ".png"));
+                                       if (tmp > dbs[i]) {
+                                               gchar *key, *tmp;
+                                               key = g_strdup (dbs[i]);
+                                               for (tmp = key + len;
+                                                    (tmp > key + 4) || ((len <= 4) && (tmp == key + len));
+                                                    tmp --) {
+                                                       *tmp = 0;
+                                                       if (g_hash_table_lookup (icons_hash, key)) {
+                                                               g_hash_table_remove (icons_hash, key);
+                                                               break;
+                                                       }
+                                                       g_print ("Inserted '%s'\n", key);
+                                                       g_hash_table_insert (icons_hash, g_strdup (key), 
g_object_ref (pix));
+                                               }
+                                               g_free (key);
+                                       }
+                                       g_object_unref (pix);
+                               }
+                               else
+                                       g_warning ("Could not load GdkPixbuf for resource %s", dbs[i]);
+                       }
+                       g_strfreev (dbs);
+               }
+               else
+                       g_warning ("Could not locate any DB engine resource");
+       }
+
+       gchar *ekey;
+       ekey = g_utf8_casefold (engine, -1);
+       pix = g_hash_table_lookup (icons_hash, ekey);
+       g_free (ekey);
+       return pix;
+}
diff --git a/libgda-ui/gdaui.gresource.xml b/libgda-ui/gdaui.gresource.xml
index d473440..bb9b463 100644
--- a/libgda-ui/gdaui.gresource.xml
+++ b/libgda-ui/gdaui.gresource.xml
@@ -22,6 +22,20 @@
     <file compressed="true">data-entries/gdaui-entry-number.xml</file>
   </gresource>
   <gresource prefix="/gdaui/glade">
-    <file compressed="no">data/server_operation.xml</file>
+    <file compressed="true">data/server_operation.xml</file>
+  </gresource>
+  <gresource prefix="/gdaui/db-engines">
+    <file>data/Bdb.png</file>
+    <file>data/Firebird.png</file>
+    <file>data/LDAP.png</file>
+    <file>data/Mariadb.png</file>
+    <file>data/Mdb.png</file>
+    <file>data/MySQL.png</file>
+    <file>data/Oracle.png</file>
+    <file>data/PostgreSQL.png</file>
+    <file>data/SQLite.png</file>
+    <file>data/SQLCipher.png</file>
+    <file>data/SqlServer.png</file>
+    <file>data/Web.png</file>
   </gresource>
 </gresources>
diff --git a/libgda-ui/libgda-ui.h b/libgda-ui/libgda-ui.h
index f9ecc0b..c0f7764 100644
--- a/libgda-ui/libgda-ui.h
+++ b/libgda-ui/libgda-ui.h
@@ -2,7 +2,7 @@
  * Copyright (C) 2000 Reinhard Müller <reinhard src gnome org>
  * Copyright (C) 2000 - 2002 Rodrigo Moya <rodrigo gnome-db org>
  * Copyright (C) 2001 Carlos Perell� Mar�n <carlos gnome-db org>
- * Copyright (C) 2001 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2001 - 2014 Vivien Malerba <malerba gnome-db org>
  * Copyright (C) 2002 Gonzalo Paniagua Javier <gonzalo src gnome org>
  *
  * This library is free software; you can redistribute it and/or
@@ -60,6 +60,7 @@ G_BEGIN_DECLS
 void         gdaui_init (void);
 const gchar *gdaui_get_default_path (void);
 void         gdaui_set_default_path (const gchar *path);
+GdkPixbuf   *gdaui_get_icon_for_db_engine (const gchar *engine);
 
 G_END_DECLS
 
diff --git a/libgda-ui/libgda-ui.symbols b/libgda-ui/libgda-ui.symbols
index 46f7f42..327d6b8 100644
--- a/libgda-ui/libgda-ui.symbols
+++ b/libgda-ui/libgda-ui.symbols
@@ -140,6 +140,7 @@
        gdaui_form_get_type
        gdaui_form_new
        gdaui_get_default_path
+       gdaui_get_icon_for_db_engine
        gdaui_grid_get_type
        gdaui_grid_new
        gdaui_grid_set_sample_size


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]