Changeset 12658


Ignore:
Timestamp:
Aug 9, 2011, 5:47:24 AM (10 years ago)
Author:
jordan
Message:

(trunk gtk) use G_DEFINE_TYPE when implementing the tr-core and torent-cell-renderer classes

Location:
trunk/gtk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/torrent-cell-renderer.c

    r12651 r12658  
    309309***/
    310310
    311 static GtkCellRendererClass * parent_class = NULL;
    312 
    313311struct TorrentCellRendererPrivate
    314312{
     
    893891}
    894892
     893G_DEFINE_TYPE (TorrentCellRenderer, torrent_cell_renderer, GTK_TYPE_CELL_RENDERER)
     894
    895895static void
    896896torrent_cell_renderer_class_init( TorrentCellRendererClass * klass )
     
    901901    g_type_class_add_private( klass,
    902902                             sizeof( struct TorrentCellRendererPrivate ) );
    903 
    904     parent_class = (GtkCellRendererClass*) g_type_class_peek_parent( klass );
    905903
    906904    cell_class->render = torrent_cell_renderer_render;
     
    942940
    943941static void
    944 torrent_cell_renderer_init( GTypeInstance * instance, gpointer g_class UNUSED )
     942torrent_cell_renderer_init( TorrentCellRenderer * self )
    945943{
    946944    struct TorrentCellRendererPrivate * p;
    947     TorrentCellRenderer * self = TORRENT_CELL_RENDERER( instance );
    948945
    949946    p = self->priv = G_TYPE_INSTANCE_GET_PRIVATE(
     
    967964}
    968965
    969 GType
    970 torrent_cell_renderer_get_type( void )
    971 {
    972     static GType type = 0;
    973 
    974     if( !type )
    975     {
    976         static const GTypeInfo info =
    977         {
    978             sizeof( TorrentCellRendererClass ),
    979             NULL,                                            /* base_init */
    980             NULL,                                            /* base_finalize */
    981             (GClassInitFunc)torrent_cell_renderer_class_init,
    982             NULL,                                            /* class_finalize
    983                                                                */
    984             NULL,                                            /* class_data */
    985             sizeof( TorrentCellRenderer ),
    986             0,                                               /* n_preallocs */
    987             (GInstanceInitFunc)torrent_cell_renderer_init,
    988             NULL
    989         };
    990 
    991         type = g_type_register_static( GTK_TYPE_CELL_RENDERER,
    992                                        "TorrentCellRenderer",
    993                                        &info, (GTypeFlags)0 );
    994     }
    995 
    996     return type;
    997 }
    998966
    999967GtkCellRenderer *
  • trunk/gtk/torrent-cell-renderer.h

    r11709 r12658  
    1414#define GTR_TORRENT_CELL_RENDERER_H
    1515
    16 #include <glib-object.h>
    1716#include <gtk/gtk.h>
    1817
     
    3029struct TorrentCellRenderer
    3130{
    32     GtkCellRenderer                      parent;
    33     struct TorrentCellRendererPrivate *  priv;
     31    GtkCellRenderer parent;
     32
     33    /*< private >*/
     34    struct TorrentCellRendererPrivate * priv;
    3435};
    3536
    3637struct TorrentCellRendererClass
    3738{
    38     GtkCellRendererClass    parent;
     39    GtkCellRendererClass parent;
    3940};
    4041
    41 GType             torrent_cell_renderer_get_type( void );
     42GType torrent_cell_renderer_get_type( void ) G_GNUC_CONST;
    4243
    4344GtkCellRenderer * torrent_cell_renderer_new( void );
  • trunk/gtk/tr-core.c

    r12656 r12658  
    6262};
    6363
    64 static guint core_signals[LAST_SIGNAL] = { 0 };
     64static guint signals[LAST_SIGNAL] = { 0 };
    6565
    6666static void core_maybe_inhibit_hibernation( TrCore * core );
     
    119119}
    120120
    121 static void
    122 gtr_core_class_init( gpointer g_class, gpointer g_class_data UNUSED )
     121G_DEFINE_TYPE (TrCore, tr_core, G_TYPE_OBJECT)
     122
     123static void
     124tr_core_class_init( TrCoreClass * core_class )
    123125{
    124126    GObjectClass * gobject_class;
    125 
    126     g_type_class_add_private( g_class, sizeof( struct TrCorePrivate ) );
    127 
    128     gobject_class = G_OBJECT_CLASS( g_class );
     127    GType core_type = G_TYPE_FROM_CLASS( core_class );
     128
     129    g_type_class_add_private( core_class, sizeof( struct TrCorePrivate ) );
     130
     131    gobject_class = G_OBJECT_CLASS( core_class );
    129132    gobject_class->dispose = core_dispose;
    130133    gobject_class->finalize = core_finalize;
    131134
    132     core_signals[ADD_ERROR_SIGNAL] = g_signal_new(
    133         "add-error",
    134         G_TYPE_FROM_CLASS( g_class ),
    135         G_SIGNAL_RUN_LAST,
    136         G_STRUCT_OFFSET(TrCoreClass, add_error),
    137         NULL, NULL,
    138         g_cclosure_marshal_VOID__UINT_POINTER,
    139         G_TYPE_NONE,
    140         2, G_TYPE_UINT, G_TYPE_POINTER );
    141 
    142     core_signals[ADD_PROMPT_SIGNAL] = g_signal_new(
    143         "add-prompt",
    144         G_TYPE_FROM_CLASS( g_class ),
    145         G_SIGNAL_RUN_LAST,
    146         G_STRUCT_OFFSET(TrCoreClass, add_prompt),
    147         NULL, NULL,
    148         g_cclosure_marshal_VOID__POINTER,
    149         G_TYPE_NONE,
    150         1, G_TYPE_POINTER );
    151 
    152     core_signals[BUSY_SIGNAL] = g_signal_new(
    153         "busy",
    154         G_TYPE_FROM_CLASS( g_class ),
    155         G_SIGNAL_RUN_FIRST,
    156         G_STRUCT_OFFSET(TrCoreClass, busy),
    157         NULL, NULL,
    158         g_cclosure_marshal_VOID__BOOLEAN,
    159         G_TYPE_NONE,
    160         1, G_TYPE_BOOLEAN );
    161 
    162     core_signals[BLOCKLIST_SIGNAL] = g_signal_new(
    163         "blocklist-updated",
    164         G_TYPE_FROM_CLASS( g_class ),
    165         G_SIGNAL_RUN_FIRST,
    166         G_STRUCT_OFFSET(TrCoreClass, blocklist_updated),
    167         NULL, NULL,
    168         g_cclosure_marshal_VOID__INT,
    169         G_TYPE_NONE,
    170         1, G_TYPE_INT );
    171 
    172     core_signals[PORT_SIGNAL] = g_signal_new(
    173         "port-tested",
    174         G_TYPE_FROM_CLASS( g_class ),
    175         G_SIGNAL_RUN_LAST,
    176         G_STRUCT_OFFSET(TrCoreClass, port_tested),
    177         NULL, NULL,
    178         g_cclosure_marshal_VOID__BOOLEAN,
    179         G_TYPE_NONE,
    180         1, G_TYPE_BOOLEAN );
    181 
    182     core_signals[PREFS_SIGNAL] = g_signal_new(
    183         "prefs-changed",
    184         G_TYPE_FROM_CLASS( g_class ),
    185         G_SIGNAL_RUN_LAST,
    186         G_STRUCT_OFFSET(TrCoreClass, prefs_changed),
    187         NULL, NULL,
    188         g_cclosure_marshal_VOID__STRING,
    189         G_TYPE_NONE,
    190         1, G_TYPE_STRING );
    191 }
    192 
    193 static void
    194 core_init( GTypeInstance * instance, gpointer g_class UNUSED )
     135    signals[ADD_ERROR_SIGNAL] =
     136        g_signal_new( "add-error", core_type,
     137                      G_SIGNAL_RUN_LAST,
     138                      G_STRUCT_OFFSET(TrCoreClass, add_error),
     139                      NULL, NULL,
     140                      g_cclosure_marshal_VOID__UINT_POINTER,
     141                      G_TYPE_NONE,
     142                      2, G_TYPE_UINT, G_TYPE_POINTER );
     143
     144    signals[ADD_PROMPT_SIGNAL] =
     145        g_signal_new( "add-prompt", core_type,
     146                      G_SIGNAL_RUN_LAST,
     147                      G_STRUCT_OFFSET(TrCoreClass, add_prompt),
     148                      NULL, NULL,
     149                      g_cclosure_marshal_VOID__POINTER,
     150                      G_TYPE_NONE,
     151                      1, G_TYPE_POINTER );
     152
     153    signals[BUSY_SIGNAL] =
     154        g_signal_new( "busy", core_type,
     155                      G_SIGNAL_RUN_FIRST,
     156                      G_STRUCT_OFFSET(TrCoreClass, busy),
     157                      NULL, NULL,
     158                      g_cclosure_marshal_VOID__BOOLEAN,
     159                      G_TYPE_NONE,
     160                      1, G_TYPE_BOOLEAN );
     161
     162    signals[BLOCKLIST_SIGNAL] =
     163        g_signal_new( "blocklist-updated", core_type,
     164                      G_SIGNAL_RUN_FIRST,
     165                      G_STRUCT_OFFSET(TrCoreClass, blocklist_updated),
     166                      NULL, NULL,
     167                      g_cclosure_marshal_VOID__INT,
     168                      G_TYPE_NONE,
     169                      1, G_TYPE_INT );
     170
     171    signals[PORT_SIGNAL] =
     172        g_signal_new( "port-tested", core_type,
     173                      G_SIGNAL_RUN_LAST,
     174                      G_STRUCT_OFFSET(TrCoreClass, port_tested),
     175                      NULL, NULL,
     176                      g_cclosure_marshal_VOID__BOOLEAN,
     177                      G_TYPE_NONE,
     178                      1, G_TYPE_BOOLEAN );
     179
     180    signals[PREFS_SIGNAL] =
     181        g_signal_new( "prefs-changed", core_type,
     182                      G_SIGNAL_RUN_LAST,
     183                      G_STRUCT_OFFSET(TrCoreClass, prefs_changed),
     184                      NULL, NULL,
     185                      g_cclosure_marshal_VOID__STRING,
     186                      G_TYPE_NONE,
     187                      1, G_TYPE_STRING );
     188}
     189
     190static void
     191tr_core_init( TrCore * core )
    195192{
    196193    GtkListStore * store;
    197194    struct TrCorePrivate * p;
    198     TrCore * self = (TrCore *) instance;
    199195
    200196    /* column types for the model used to store torrent information */
     
    215211                      G_TYPE_INT };     /* MC_ACTIVE_PEER_COUNT */
    216212
    217     p = self->priv = G_TYPE_INSTANCE_GET_PRIVATE( self,
     213    p = core->priv = G_TYPE_INSTANCE_GET_PRIVATE( core,
    218214                                                  TR_CORE_TYPE,
    219215                                                  struct TrCorePrivate );
     
    229225}
    230226
    231 GType
    232 gtr_core_get_type( void )
    233 {
    234     static GType type = 0;
    235 
    236     if( !type )
    237     {
    238         static const GTypeInfo info =
    239         {
    240             sizeof( TrCoreClass ),
    241             NULL,                 /* base_init */
    242             NULL,                 /* base_finalize */
    243             gtr_core_class_init,  /* class_init */
    244             NULL,                 /* class_finalize */
    245             NULL,                 /* class_data */
    246             sizeof( TrCore ),
    247             0,                    /* n_preallocs */
    248             core_init,            /* instance_init */
    249             NULL,
    250         };
    251         type = g_type_register_static( G_TYPE_OBJECT, "TrCore", &info, 0 );
    252     }
    253 
    254     return type;
    255 }
     227
    256228
    257229/***
     
    262234core_emit_blocklist_udpated( TrCore * core, int ruleCount )
    263235{
    264     g_signal_emit( core, core_signals[BLOCKLIST_SIGNAL], 0, ruleCount );
     236    g_signal_emit( core, signals[BLOCKLIST_SIGNAL], 0, ruleCount );
    265237}
    266238
     
    268240core_emit_port_tested( TrCore * core, gboolean is_open )
    269241{
    270     g_signal_emit( core, core_signals[PORT_SIGNAL], 0, is_open );
     242    g_signal_emit( core, signals[PORT_SIGNAL], 0, is_open );
    271243}
    272244
     
    274246core_emit_err( TrCore * core, enum tr_core_err type, const char * msg )
    275247{
    276     g_signal_emit( core, core_signals[ADD_ERROR_SIGNAL], 0, type, msg );
     248    g_signal_emit( core, signals[ADD_ERROR_SIGNAL], 0, type, msg );
    277249}
    278250
     
    280252core_emit_busy( TrCore * core, gboolean is_busy )
    281253{
    282     g_signal_emit( core, core_signals[BUSY_SIGNAL], 0, is_busy );
     254    g_signal_emit( core, signals[BUSY_SIGNAL], 0, is_busy );
    283255}
    284256
     
    286258gtr_core_pref_changed( TrCore * core, const char * key )
    287259{
    288     g_signal_emit( core, core_signals[PREFS_SIGNAL], 0, key );
     260    g_signal_emit( core, signals[PREFS_SIGNAL], 0, key );
    289261}
    290262
     
    10571029        default:
    10581030            if( do_prompt )
    1059                 g_signal_emit( core, core_signals[ADD_PROMPT_SIGNAL], 0, ctor );
     1031                g_signal_emit( core, signals[ADD_PROMPT_SIGNAL], 0, ctor );
    10601032            else {
    10611033                gtr_core_add_torrent( core, core_create_new_torrent( core, ctor ), do_notify );
  • trunk/gtk/tr-core.h

    r12656 r12658  
    3232#include <libtransmission/bencode.h>
    3333
    34 #define TR_CORE_TYPE ( gtr_core_get_type() )
    35 #define TR_CORE(o) G_TYPE_CHECK_INSTANCE_CAST((o), TR_CORE_TYPE, TrCore)
    36 #define TR_IS_CORE(o) G_TYPE_CHECK_INSTANCE_TYPE((o), TR_CORE_TYPE )
    37 #define TR_CORE_CLASS(k) G_TYPE_CHECK_CLASS_CAST((k), TR_CORE_TYPE, TrCoreClass)
    38 #define TR_IS_CORE_CLASS(k) G_TYPE_CHECK_CLASS_TYPE((k), TR_CORE_TYPE )
    39 #define TR_CORE_GET_CLASS(o) G_TYPE_INSTANCE_GET_CLASS((o), TR_CORE_TYPE, TrCoreClass)
     34G_BEGIN_DECLS
     35
     36#define TR_CORE_TYPE (tr_core_get_type ())
     37#define TR_CORE(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), TR_CORE_TYPE, TrCore))
    4038
    4139typedef struct _TrCore
     
    4341    GObject parent;
    4442
     43    /*< private >*/
    4544    struct TrCorePrivate  * priv;
    4645}
     
    6867TrCoreClass;
    6968
    70 GType          gtr_core_get_type( void );
     69GType          tr_core_get_type (void) G_GNUC_CONST;
    7170
    7271TrCore *       gtr_core_new( tr_session * );
     
    195194};
    196195
     196G_END_DECLS
     197
    197198
    198199#endif /* GTR_CORE_H */
Note: See TracChangeset for help on using the changeset viewer.