Back to index

bamf  0.2.120
bamf-tab-source.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Canonical Ltd.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of either or both of the following licenses:
00006  *
00007  * 1) the GNU Lesser General Public License version 3, as published by the
00008  * Free Software Foundation; and/or
00009  * 2) the GNU Lesser General Public License version 2.1, as published by
00010  * the Free Software Foundation.
00011  *
00012  * This program is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranties of
00014  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00015  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00016  * License for more details.
00017  *
00018  * You should have received a copy of both the GNU Lesser General Public
00019  * License version 3 and version 2.1 along with this program.  If not, see
00020  * <http://www.gnu.org/licenses/>
00021  *
00022  * Authored by: Jason Smith <jason.smith@canonical.com>
00023  *
00024  */
00025 
00026 #include "bamf-tab-source.h"
00027 #include "bamf-tab-source-glue.h"
00028 #include "bamf-marshal.h"
00029 
00030 #define BAMF_TAB_SOURCE_PATH "/org/bamf/tabsource"
00031 
00032 G_DEFINE_TYPE (BamfTabSource, bamf_tab_source, G_TYPE_OBJECT)
00033 #define BAMF_TAB_SOURCE_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), BAMF_TYPE_TAB_SOURCE, BamfTabSourcePrivate))
00034 
00035 enum
00036 {
00037   TAB_URI_CHANGED,
00038   TAB_OPENED,
00039   TAB_CLOSED,
00040 
00041   LAST_SIGNAL,
00042 };
00043 
00044 enum
00045 {
00046   PROP_0,
00047 
00048   PROP_ID,
00049 };
00050 
00051 static guint bamf_tab_source_signals[LAST_SIGNAL] = { 0 };
00052 
00053 struct _BamfTabSourcePrivate
00054 {
00055   char *id;
00056 };
00057 
00058 gboolean
00059 bamf_tab_source_show_tab        (BamfTabSource *source,
00060                                  char *tab_id,
00061                                  GError *error)
00062 {
00063   g_return_val_if_fail (BAMF_IS_TAB_SOURCE (source), TRUE);
00064 
00065   if (BAMF_TAB_SOURCE_GET_CLASS (source)->show_tab)
00066     BAMF_TAB_SOURCE_GET_CLASS (source)->show_tab (source, tab_id);
00067 
00068   return TRUE;
00069 }
00070 
00071 char **
00072 bamf_tab_source_get_tab_ids     (BamfTabSource *source)
00073 {
00074   g_return_val_if_fail (BAMF_IS_TAB_SOURCE (source), NULL);
00075 
00076   if (BAMF_TAB_SOURCE_GET_CLASS (source)->tab_ids)
00077     return BAMF_TAB_SOURCE_GET_CLASS (source)->tab_ids (source);
00078 
00079   return NULL;
00080 }
00081 
00082 GArray *
00083 bamf_tab_source_get_tab_preview (BamfTabSource *source,
00084                                  char *tab_id)
00085 {
00086   g_return_val_if_fail (BAMF_IS_TAB_SOURCE (source), NULL);
00087 
00088   if (BAMF_TAB_SOURCE_GET_CLASS (source)->tab_preview)
00089     return BAMF_TAB_SOURCE_GET_CLASS (source)->tab_preview (source, tab_id);
00090 
00091   return NULL;
00092 }
00093 
00094 char *
00095 bamf_tab_source_get_tab_uri     (BamfTabSource *source,
00096                                  char *tab_id)
00097 {
00098   g_return_val_if_fail (BAMF_IS_TAB_SOURCE (source), NULL);
00099 
00100   if (BAMF_TAB_SOURCE_GET_CLASS (source)->tab_uri)
00101     return BAMF_TAB_SOURCE_GET_CLASS (source)->tab_uri (source, tab_id);
00102 
00103   return NULL;
00104 }
00105 
00106 guint32
00107 bamf_tab_source_get_tab_xid     (BamfTabSource *source,
00108                                  char *tab_id)
00109 {
00110   g_return_val_if_fail (BAMF_IS_TAB_SOURCE (source), 0);
00111 
00112   if (BAMF_TAB_SOURCE_GET_CLASS (source)->tab_xid)
00113     return BAMF_TAB_SOURCE_GET_CLASS (source)->tab_xid (source, tab_id);
00114 
00115   return 0;
00116 }
00117 
00118 static void
00119 bamf_tab_source_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
00120 {
00121   BamfTabSource *self;
00122 
00123   self = BAMF_TAB_SOURCE (object);
00124 
00125   switch (property_id)
00126     {
00127       case PROP_ID:
00128         self->priv->id = g_strdup (g_value_get_string (value));
00129         break;
00130       default:
00131         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
00132     }
00133 
00134 }
00135 
00136 static void
00137 bamf_tab_source_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
00138 {
00139   BamfTabSource *self;
00140 
00141   self = BAMF_TAB_SOURCE (object);
00142 
00143   switch (property_id)
00144     {
00145       case PROP_ID:
00146         g_value_set_string (value, self->priv->id);
00147         break;
00148       default:
00149         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
00150     }
00151 
00152 }
00153 
00154 static void
00155 bamf_tab_source_dispose (GObject *object)
00156 {
00157   G_OBJECT_CLASS (bamf_tab_source_parent_class)->dispose (object);
00158 }
00159 
00160 static void
00161 bamf_tab_source_constructed (GObject *object)
00162 {
00163   char *path;
00164   DBusGConnection *bus;
00165   DBusGProxy      *proxy;
00166   GError *error = NULL;
00167 
00168   if (G_OBJECT_CLASS (bamf_tab_source_parent_class)->constructed)
00169     G_OBJECT_CLASS (bamf_tab_source_parent_class)->constructed (object);
00170 
00171   bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
00172   g_return_if_fail (bus);
00173 
00174   path = g_strdup_printf ("%s%s", BAMF_TAB_SOURCE_PATH, BAMF_TAB_SOURCE (object)->priv->id);
00175 
00176   dbus_g_connection_register_g_object (bus, path, object);
00177 
00178   proxy = dbus_g_proxy_new_for_name (bus,
00179                                      "org.ayatana.bamf",
00180                                      "/org/ayatana/bamf/control",
00181                                      "org.ayatana.bamf.control");
00182 
00183   error = NULL;
00184   if (!dbus_g_proxy_call (proxy,
00185                           "RegisterTabProvider",
00186                           &error,
00187                           G_TYPE_STRING, path,
00188                           G_TYPE_INVALID,
00189                           G_TYPE_INVALID))
00190     {
00191       g_warning ("Could not register tab source: %s", error->message);
00192       g_error_free (error);
00193     }
00194 
00195   g_object_unref (proxy);
00196 }
00197 
00198 static void
00199 bamf_tab_source_class_init (BamfTabSourceClass *klass)
00200 {
00201   GParamSpec *pspec;
00202   GObjectClass *object_class = G_OBJECT_CLASS (klass);
00203 
00204   object_class->constructed  = bamf_tab_source_constructed;
00205   object_class->dispose      = bamf_tab_source_dispose;
00206   object_class->get_property = bamf_tab_source_get_property;
00207   object_class->set_property = bamf_tab_source_set_property;
00208 
00209   pspec = g_param_spec_string ("id", "id", "id", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
00210   g_object_class_install_property (object_class, PROP_ID, pspec);
00211 
00212   g_type_class_add_private (object_class, sizeof (BamfTabSourcePrivate));
00213 
00214   dbus_g_object_type_install_info (BAMF_TYPE_TAB_SOURCE,
00215                                &dbus_glib_bamf_tab_source_object_info);
00216 
00217   bamf_tab_source_signals [TAB_URI_CHANGED] =
00218        g_signal_new ("tab-uri-changed",
00219                      G_OBJECT_CLASS_TYPE (klass),
00220                      G_SIGNAL_RUN_FIRST,
00221                      0,
00222                      NULL, NULL,
00223                      _bamf_marshal_VOID__STRING_STRING_STRING,
00224                      G_TYPE_NONE, 3,
00225                      G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
00226 
00227   bamf_tab_source_signals [TAB_OPENED] =
00228        g_signal_new ("tab-opened",
00229                      G_OBJECT_CLASS_TYPE (klass),
00230                      G_SIGNAL_RUN_FIRST,
00231                      0,
00232                      NULL, NULL,
00233                      g_cclosure_marshal_VOID__STRING,
00234                      G_TYPE_NONE, 1,
00235                      G_TYPE_STRING);
00236 
00237   bamf_tab_source_signals [TAB_CLOSED] =
00238        g_signal_new ("tab-closed",
00239                      G_OBJECT_CLASS_TYPE (klass),
00240                      G_SIGNAL_RUN_FIRST,
00241                      0,
00242                      NULL, NULL,
00243                      g_cclosure_marshal_VOID__STRING,
00244                      G_TYPE_NONE, 1,
00245                      G_TYPE_STRING);
00246 }
00247 
00248 static void
00249 bamf_tab_source_init (BamfTabSource *self)
00250 {
00251   self->priv = BAMF_TAB_SOURCE_GET_PRIVATE (self);
00252 }