Changeset 4998


Ignore:
Timestamp:
Feb 9, 2008, 5:29:05 PM (14 years ago)
Author:
charles
Message:

(gtk) make TrCore?'s fields private

Location:
trunk/gtk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/stats.c

    r4481 r4998  
    5252    struct stat_ui * ui = gdata;
    5353    tr_session_stats one, all;
    54     tr_getSessionStats( ui->core->handle, &one );
    55     tr_getCumulativeSessionStats( ui->core->handle, &all );
     54    tr_getSessionStats( tr_core_handle( ui->core ), &one );
     55    tr_getCumulativeSessionStats( tr_core_handle( ui->core ), &all );
    5656
    5757    setLabel( ui->one_up_lb, tr_strlsize( buf, one.uploadedBytes, sizeof(buf) ) );
  • trunk/gtk/tr_core.c

    r4978 r4998  
    3939#include "util.h"
    4040
     41struct TrCorePrivate
     42{
     43    GtkTreeModel     * model;
     44    tr_handle        * handle;
     45    int                nextid;
     46    gboolean           quitting;
     47    struct core_stats  stats;
     48};
     49
    4150static void
    4251tr_core_marshal_err( GClosure * closure, GValue * ret UNUSED, guint count,
     
    118127}
    119128
     129static int
     130isDisposed( const TrCore * core )
     131{
     132    return !core || !core->priv;
     133}
     134
    120135static void
    121136tr_core_dispose( GObject * obj )
    122137{
    123     TrCore       * self = (TrCore *) obj;
     138    TrCore * core = TR_CORE( obj );
    124139    GObjectClass * parent;
    125140
    126     if( self->disposed )
    127         return;
    128 
    129     self->disposed = TRUE;
    130     pref_save( NULL );
     141    if( !isDisposed( core ) )
     142    {
     143        pref_save( NULL );
     144        core->priv = NULL;
     145    }
     146
    131147    parent = g_type_class_peek( g_type_parent( TR_CORE_TYPE ) );
    132148    parent->dispose( obj );
     
    142158    gobject_class = G_OBJECT_CLASS( g_class );
    143159    gobject_class->dispose = tr_core_dispose;
     160
     161    g_type_class_add_private( g_class,
     162                              sizeof(struct TrCorePrivate) );
     163
    144164
    145165    core_class = TR_CORE_CLASS( g_class );
     
    292312    int col = MC_TORRENT_RAW;
    293313    GtkSortType type = isReversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
    294     GtkTreeSortable * sortable = GTK_TREE_SORTABLE( core->model );
     314    GtkTreeModel * model = tr_core_model( core );
     315    GtkTreeSortable * sortable = GTK_TREE_SORTABLE( model );
    295316
    296317    if( !strcmp( mode, "sort-by-activity" ) )
     
    325346    {
    326347        const uint16_t val = pref_int_get( key );
    327         tr_setGlobalPeerLimit( core->handle, val );
     348        tr_setGlobalPeerLimit( tr_core_handle( core ), val );
    328349    }
    329350}
     
    335356    TrCore * self = (TrCore *) instance;
    336357    GtkListStore * store;
     358    struct TrCorePrivate * p;
    337359
    338360    /* column types for the model used to store torrent information */
     
    347369        G_TYPE_INT        /* ID for IPC */
    348370    };
     371
     372    p = self->priv = G_TYPE_INSTANCE_GET_PRIVATE( self,
     373                                                  TR_CORE_TYPE,
     374                                                  struct TrCorePrivate );
     375
    349376
    350377    h = tr_initFull( "gtk",
     
    367394    store = gtk_list_store_newv( MC_ROW_COUNT, types );
    368395
    369     self->model    = GTK_TREE_MODEL( store );
    370     self->handle   = h;
    371     self->nextid   = 1;
    372     self->quitting = FALSE;
    373     self->disposed = FALSE;
     396    p->model    = GTK_TREE_MODEL( store );
     397    p->handle   = h;
     398    p->nextid   = 1;
     399    p->quitting = FALSE;
    374400}
    375401
     
    419445
    420446GtkTreeModel *
    421 tr_core_model( TrCore * self )
    422 {
    423     g_return_val_if_fail (TR_IS_CORE(self), NULL);
    424 
    425     return self->disposed ? NULL : self->model;
     447tr_core_model( TrCore * core )
     448{
     449    return isDisposed( core ) ? NULL : core->priv->model;
    426450}
    427451
    428452tr_handle *
    429 tr_core_handle( TrCore * self )
    430 {
    431     g_return_val_if_fail (TR_IS_CORE(self), NULL);
    432 
    433     return self->disposed ? NULL : self->handle;
     453tr_core_handle( TrCore * core )
     454{
     455    return isDisposed( core ) ? NULL : core->priv->handle;
     456}
     457
     458
     459const struct core_stats*
     460tr_core_get_stats( const TrCore * core )
     461{
     462    return isDisposed( core ) ? NULL : &core->priv->stats;
    434463}
    435464
     
    464493    const tr_stat * torStat = tr_torrent_stat( tor );
    465494    char * collated = doCollate( inf->name );
     495    GtkListStore * store = GTK_LIST_STORE( tr_core_model( self ) );
    466496    GtkTreeIter unused;
    467     gtk_list_store_insert_with_values( GTK_LIST_STORE( self->model ), &unused, 0,
     497    gtk_list_store_insert_with_values( store, &unused, 0,
    468498                                       MC_NAME,          inf->name,
    469499                                       MC_NAME_COLLATED, collated,
     
    472502                                       MC_TORRENT_RAW,   tor->handle,
    473503                                       MC_STATUS,        torStat->status,
    474                                        MC_ID,            self->nextid,
     504                                       MC_ID,            self->priv->nextid,
    475505                                       -1);
    476     self->nextid++;
     506    self->priv->nextid++;
    477507    g_object_unref( tor );
    478508    g_free( collated );
     
    492522    path = getdownloaddir( );
    493523
    494     ctor = tr_ctorNew( self->handle );
     524    ctor = tr_ctorNew( tr_core_handle( self ) );
    495525    if( forcePaused )
    496526        tr_ctorSetPaused( ctor, TR_FORCE, TRUE );
     
    498528    tr_ctorSetMaxConnectedPeers( ctor, TR_FALLBACK, pref_int_get( PREF_KEY_MAX_PEERS_PER_TORRENT ) );
    499529
    500     torrents = tr_loadTorrents ( self->handle, ctor, &count );
     530    torrents = tr_loadTorrents ( tr_core_handle( self ), ctor, &count );
    501531    for( i=0; i<count; ++i )
    502532        tr_core_insert( self, tr_torrent_new_preexisting( torrents[i] ) );
     
    544574
    545575    errstr = NULL;
    546     tor = tr_torrent_new( self->handle, path, dir, act, paused, &errstr );
     576    tor = tr_torrent_new( tr_core_handle( self ), path, dir, act, paused, &errstr );
    547577    if( NULL == tor )
    548578    {
     
    613643    TR_IS_CORE( self );
    614644
    615     tor = tr_torrent_new_with_data( self->handle, data, size, dir,
     645    tor = tr_torrent_new_with_data( tr_core_handle( self ), data, size, dir,
    616646                                    paused, &errstr );
    617647    if( NULL == tor )
     
    641671{
    642672    TrTorrent * tor;
     673    GtkTreeModel * model = tr_core_model( self );
    643674
    644675    TR_IS_CORE( self );
    645676
    646     gtk_tree_model_get( self->model, iter, MC_TORRENT, &tor, -1 );
    647     gtk_list_store_remove( GTK_LIST_STORE( self->model ), iter );
     677    gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 );
     678    gtk_list_store_remove( GTK_LIST_STORE( model ), iter );
    648679    tr_torrentRemoveSaved( tr_torrent_handle( tor ) );
    649680
    650681    g_object_unref( G_OBJECT( tor ) );
    651682}
     683
     684/***
     685****
     686***/
    652687
    653688static gboolean
     
    694729    GtkSortType order;
    695730    GtkTreeSortable * sortable;
     731    GtkTreeModel * model = tr_core_model( self );
    696732
    697733    /* pause sorting */
    698     sortable = GTK_TREE_SORTABLE( self->model );
     734    sortable = GTK_TREE_SORTABLE( model );
    699735    gtk_tree_sortable_get_sort_column_id( sortable, &column, &order );
    700736    gtk_tree_sortable_set_sort_column_id( sortable, GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, order );
    701737
    702738    /* refresh the model */
    703     memset( &self->stats, 0, sizeof( struct core_stats ) );
    704     gtk_tree_model_foreach( self->model, update_foreach, &self->stats );
     739    memset( &self->priv->stats, 0, sizeof( struct core_stats ) );
     740    gtk_tree_model_foreach( model, update_foreach, &self->priv->stats );
    705741
    706742    /* resume sorting */
  • trunk/gtk/tr_core.h

    r4704 r4998  
    5353  ( G_TYPE_INSTANCE_GET_CLASS(  (obj),   TR_CORE_TYPE, TrCoreClass ) )
    5454
    55 typedef struct _TrCore TrCore;
    56 typedef struct _TrCoreClass TrCoreClass;
    5755
    5856struct core_stats
     
    6563
    6664/* treat the contents of this structure as private */
    67 struct _TrCore
    68 {
    69     GObject            parent;
    70     GtkTreeModel     * model;
    71     tr_handle        * handle;
    72     int                nextid;
    73     gboolean           quitting;
    74     gboolean           disposed;
    75     struct core_stats  stats;
    76 };
    77 
    78 struct _TrCoreClass
    79 {
    80     GObjectClass        parent;
     65typedef struct TrCore
     66{
     67    GObject                 parent;
     68    struct TrCorePrivate  * priv;
     69}
     70TrCore;
     71
     72typedef struct TrCoreClass
     73{
     74    GObjectClass parent;
     75
    8176    /* "error" signal:
    8277       void handler( TrCore *, enum tr_core_err, const char *, gpointer ) */
    83     int                 errsig;
     78    int errsig;
     79
    8480    /* "directory-prompt" signal:
    85        void handler( TrCore *, GList *, enum tr_torrent_action, gboolean,
    86                      gpointer ) */
    87     int                 promptsig;
     81       void handler( TrCore *, GList *, enum tr_torrent_action, gboolean, gpointer ) */
     82    int promptsig;
     83
    8884    /* "directory-prompt-data" signal:
    8985       void handler( TrCore *, uint8_t *, size_t, gboolean, gpointer ) */
    90     int                 promptdatasig;
     86    int promptdatasig;
     87
    9188    /* "quit" signal:
    9289       void handler( TrCore *, gpointer ) */
    93     int                 quitsig;
     90    int quitsig;
     91
    9492    /* "prefs-changed" signal:
    9593       void handler( TrCore *, int, gpointer ) */
    96     int                 prefsig;
    97 };
     94    int prefsig;
     95}
     96TrCoreClass;
    9897
    9998enum tr_core_err
     
    118117tr_handle *
    119118tr_core_handle( TrCore * self );
     119
     120const struct core_stats*
     121tr_core_get_stats( const TrCore * self );
    120122
    121123/* Load saved state, return number of torrents added. May trigger one
  • trunk/gtk/tr_icon.c

    r4975 r4998  
    6969    GtkStatusIcon * icon = GTK_STATUS_ICON( data );
    7070    TrCore * core = g_object_get_data( G_OBJECT( icon ), "tr-core" );
    71     const struct core_stats * stats = &core->stats;
     71    const struct core_stats * stats = tr_core_get_stats( core );
    7272    char downStr[32], upStr[32];
    7373    char tip[256];
Note: See TracChangeset for help on using the changeset viewer.