Back to index

bamf  0.2.120
bamf-tab.c
Go to the documentation of this file.
00001 /*
00002  * bamf-tab.c
00003  * This file is part of BAMF
00004  *
00005  * Copyright (C) 2010 - Jason Smith
00006  *
00007  * BAMF is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * BAMF is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with BAMF; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, 
00020  * Boston, MA  02110-1301  USA
00021  */
00022 
00023 #include "bamf-tab.h"
00024 #include "bamf-marshal.h"
00025 
00026 
00027 #define BAMF_TAB_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), BAMF_TYPE_TAB, BamfTabPrivate))
00028 
00029 enum
00030 {
00031   PROP_0,
00032   
00033   PROP_ID,
00034   PROP_URI,
00035   PROP_PREVIEW,
00036 };
00037 
00038 enum
00039 {
00040   URI_CHANGED,
00041   PREVIEW_UPDATED,
00042 
00043   LAST_SIGNAL,
00044 };
00045 
00046 static guint tab_signals[LAST_SIGNAL] = { 0 };
00047 
00048 struct _BamfTabPrivate
00049 {
00050   gchar *uri;
00051   gchar *preview_uri;
00052   gchar *id;
00053 };
00054 
00055 G_DEFINE_TYPE (BamfTab, bamf_tab, BAMF_TYPE_VIEW)
00056 
00057 gchar *
00058 bamf_tab_get_id (BamfTab *tab)
00059 {
00060   g_return_val_if_fail (BAMF_IS_TAB (tab), NULL);
00061   
00062   return tab->priv->id;
00063 }
00064 
00065 gchar *
00066 bamf_tab_get_preview (BamfTab *tab)
00067 {
00068   g_return_val_if_fail (BAMF_IS_TAB (tab), NULL);
00069   
00070   return tab->priv->preview_uri;
00071 }
00072 
00073 void
00074 bamf_tab_set_preview (BamfTab *tab, gchar *uri)
00075 {
00076   g_return_if_fail (BAMF_IS_TAB (tab));
00077   
00078   tab->priv->preview_uri = uri;
00079 }
00080 
00081 gchar *
00082 bamf_tab_get_uri (BamfTab *tab)
00083 {
00084   g_return_val_if_fail (BAMF_IS_TAB (tab), NULL);
00085   
00086   return tab->priv->uri;
00087 }
00088 
00089 void
00090 bamf_tab_set_uri (BamfTab *tab, gchar *uri)
00091 {
00092   gchar *old;
00093 
00094   g_return_if_fail (BAMF_IS_TAB (tab));
00095   
00096   old = tab->priv->uri;
00097   tab->priv->uri = uri;
00098 
00099   g_signal_emit (tab, tab_signals[URI_CHANGED], 0, old, uri);  
00100 }
00101 
00102 void bamf_tab_show (BamfTab *self)
00103 {
00104   if (BAMF_TAB_GET_CLASS (self)->show)
00105     BAMF_TAB_GET_CLASS (self)->show (self);
00106   else
00107     g_warning ("Default tab class implementation cannot perform show!\n");
00108 }
00109 
00110 static void
00111 bamf_tab_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
00112 {
00113   BamfTab *self;
00114 
00115   self = BAMF_TAB (object);
00116 
00117   switch (property_id)
00118     {
00119       case PROP_ID:
00120         self->priv->id = g_value_dup_string (value);
00121         break;
00122       case PROP_URI:
00123         bamf_tab_set_uri (self, g_value_dup_string (value));
00124         break;
00125       case PROP_PREVIEW:
00126         bamf_tab_set_preview (self, g_value_dup_string (value));
00127         break;
00128       default:
00129         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
00130     }
00131 }
00132 
00133 static void
00134 bamf_tab_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
00135 {
00136   BamfTab *self;
00137 
00138   self = BAMF_TAB (object);
00139 
00140   switch (property_id)
00141     {
00142       case PROP_ID:
00143         g_value_set_string (value, bamf_tab_get_id (self));
00144         break;
00145       case PROP_URI:
00146         g_value_set_string (value, bamf_tab_get_uri (self));
00147         break;
00148       case PROP_PREVIEW:
00149         g_value_set_string (value, bamf_tab_get_preview (self));
00150         break;
00151 
00152       default:
00153         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
00154     }
00155 }
00156 
00157 static void
00158 bamf_tab_constructed (GObject *object)
00159 {
00160   G_OBJECT_CLASS (bamf_tab_parent_class)->constructed (object);
00161 }
00162 
00163 static void
00164 bamf_tab_dispose (GObject *object)
00165 {
00166   G_OBJECT_CLASS (bamf_tab_parent_class)->dispose (object);
00167 }
00168 
00169 static void
00170 bamf_tab_class_init (BamfTabClass *klass)
00171 {
00172   GParamSpec *pspec;
00173   GObjectClass *object_class = G_OBJECT_CLASS (klass);
00174           
00175   object_class->constructed = bamf_tab_constructed;
00176   object_class->dispose = bamf_tab_dispose;
00177   object_class->set_property = bamf_tab_set_property;
00178   object_class->get_property = bamf_tab_get_property;
00179 
00180   pspec = g_param_spec_string ("id", "id", "id", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
00181   g_object_class_install_property (object_class, PROP_ID, pspec);
00182 
00183   pspec = g_param_spec_string ("uri", "uri", "uri", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
00184   g_object_class_install_property (object_class, PROP_URI, pspec);
00185 
00186   pspec = g_param_spec_string ("preview", "preview", "preview", NULL, G_PARAM_READWRITE);
00187   g_object_class_install_property (object_class, PROP_PREVIEW, pspec);
00188 
00189   g_type_class_add_private (object_class, sizeof (BamfTabPrivate));
00190   
00191   tab_signals [URI_CHANGED] = 
00192        g_signal_new ("uri-changed",
00193                      G_OBJECT_CLASS_TYPE (klass),
00194                      G_SIGNAL_RUN_FIRST,
00195                      G_STRUCT_OFFSET (BamfTabClass, uri_changed),
00196                      NULL, NULL,
00197                      _bamf_marshal_VOID__STRING_STRING,
00198                      G_TYPE_NONE, 2, 
00199                      G_TYPE_STRING, G_TYPE_STRING);
00200   
00201   tab_signals [PREVIEW_UPDATED] = 
00202        g_signal_new ("preview-updated",
00203                      G_OBJECT_CLASS_TYPE (klass),
00204                      G_SIGNAL_RUN_FIRST,
00205                      G_STRUCT_OFFSET (BamfTabClass, preview_updated),
00206                      NULL, NULL,
00207                      g_cclosure_marshal_VOID__VOID,
00208                      G_TYPE_NONE, 0);
00209 }
00210 
00211 static void
00212 bamf_tab_init (BamfTab *self)
00213 {
00214   self->priv = BAMF_TAB_GET_PRIVATE (self);
00215 }
00216 
00217 BamfTab *
00218 bamf_tab_new (gchar *id, gchar *uri)
00219 {
00220   return g_object_new (BAMF_TYPE_TAB, NULL);
00221 }