Changeset 8846


Ignore:
Timestamp:
Jul 22, 2009, 3:55:48 PM (13 years ago)
Author:
charles
Message:

remove some unused utilities. better commenting on the utils that remain.

Location:
trunk/gtk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/dialogs.h

    r6795 r8846  
    3030#include "util.h"
    3131
     32
     33/* used for a callback function with a data parameter */
     34typedef void ( *callbackfunc_t )( gpointer );
     35
    3236/* prompt if the user wants to quit, calls func with cbdata if they do */
    33 void askquit(                               TrCore*,
    34                              GtkWindow*    parent,
    35                              callbackfunc_t func,
    36                              void*          cbdata );
     37void askquit( TrCore          * core,
     38              GtkWindow       * parent,
     39              callbackfunc_t    func,
     40              gpointer          cbdata );
    3741
    3842void confirmRemove( GtkWindow * parent,
    39                     TrCore *    core,
    40                     GSList *    gtorrents,
     43                    TrCore    * core,
     44                    GSList    * gtorrents,
    4145                    gboolean    doDelete );
    4246
  • trunk/gtk/main.c

    r8766 r8846  
    102102                                TrWindow *      wind );
    103103
    104 static void           wannaquit( void * vdata );
     104static void           wannaquit( gpointer vdata );
    105105
    106106static void           setupdrag( GtkWidget *    widget,
     
    472472    else if( err )
    473473    {
    474         gtk_widget_show( errmsg_full( NULL, (callbackfunc_t)gtk_main_quit,
    475                                       NULL, "%s", err ) );
     474        const char * primary_text = _( "Transmission cannot be started." );
     475        GtkWidget * w = gtk_message_dialog_new( NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, primary_text, NULL );
     476        gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG( w ), "%s", err );
     477        g_signal_connect( w, "response", G_CALLBACK(gtk_main_quit), NULL );
     478        gtk_widget_show( w );
    476479        g_free( err );
    477480        gtk_main( );
     
    671674
    672675static void
    673 wannaquit( void * vdata )
     676wannaquit( gpointer vdata )
    674677{
    675678    GtkWidget *r, *p, *b, *w, *c;
     
    832835
    833836    gtk_drag_dest_set( widget, GTK_DEST_DEFAULT_ALL, targets,
    834                        ALEN( targets ), GDK_ACTION_COPY | GDK_ACTION_MOVE );
     837                       G_N_ELEMENTS( targets ), GDK_ACTION_COPY | GDK_ACTION_MOVE );
    835838}
    836839
     
    902905        case TR_CORE_ERR_NO_MORE_TORRENTS:
    903906            showTorrentErrors( c );
    904             break;
    905 
    906         case TR_CORE_ERR_SAVE_STATE:
    907             errmsg( c->wind, "%s", msg );
    908907            break;
    909908
  • trunk/gtk/msgwin.c

    r8724 r8846  
    7676
    7777static void
    78 doSave( GtkWindow *      parent,
    79         struct MsgData * data,
    80         const char *     filename )
     78doSave( GtkWindow * parent, struct MsgData * data, const char * filename )
    8179{
    8280    FILE * fp = fopen( filename, "w+" );
     
    8482    if( !fp )
    8583    {
    86         errmsg( parent,
    87                _( "Couldn't save file \"%1$s\": %2$s" ),
    88                filename, g_strerror( errno ) );
     84        GtkWidget * w = gtk_message_dialog_new( parent, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _( "Couldn't save \"%s\"" ), filename );
     85        gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG( w ), "%s", g_strerror( errno ) );
     86        g_signal_connect_swapped( w, "response", G_CALLBACK( gtk_widget_destroy ), w );
     87        gtk_widget_show( w );
    8988    }
    9089    else
    9190    {
    92         GtkTreeIter    iter;
     91        GtkTreeIter iter;
    9392        GtkTreeModel * model = GTK_TREE_MODEL( data->sort );
    9493        if( gtk_tree_model_iter_children( model, &iter, NULL ) ) do
    95             {
    96                 char *                     date;
    97                 const char *               levelStr;
    98                 const struct tr_msg_list * node;
    99 
    100                 gtk_tree_model_get( model, &iter,
    101                                     COL_TR_MSG, &node,
    102                                     -1 );
    103                 date = gtr_localtime( node->when );
    104                 switch( node->level )
    105                 {
    106                     case TR_MSG_DBG:
    107                         levelStr = "debug"; break;
    108 
    109                     case TR_MSG_ERR:
    110                         levelStr = "error"; break;
    111 
    112                     default:
    113                         levelStr = "     "; break;
    114                 }
    115                 fprintf( fp, "%s\t%s\t%s\t%s\n", date, levelStr,
    116                         ( node->name ? node->name : "" ),
    117                         ( node->message ? node->message : "" ) );
    118 
    119                 g_free( date );
     94        {
     95            char * date;
     96            const char * levelStr;
     97            const struct tr_msg_list * node;
     98
     99            gtk_tree_model_get( model, &iter, COL_TR_MSG, &node, -1 );
     100            date = gtr_localtime( node->when );
     101            switch( node->level ) {
     102                case TR_MSG_DBG: levelStr = "debug"; break;
     103                case TR_MSG_ERR: levelStr = "error"; break;
     104                default:         levelStr = "     "; break;
    120105            }
    121             while( gtk_tree_model_iter_next( model, &iter ) );
     106            fprintf( fp, "%s\t%s\t%s\t%s\n", date, levelStr,
     107                     ( node->name ? node->name : "" ),
     108                     ( node->message ? node->message : "" ) );
     109            g_free( date );
     110        }
     111        while( gtk_tree_model_iter_next( model, &iter ) );
    122112
    123113        fclose( fp );
     
    126116
    127117static void
    128 onSaveDialogResponse( GtkWidget * d,
    129                       int         response,
    130                       gpointer    data )
     118onSaveDialogResponse( GtkWidget * d, int response, gpointer data )
    131119{
    132120    if( response == GTK_RESPONSE_ACCEPT )
    133121    {
    134         char * filename =
    135             gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( d ) );
    136         doSave( GTK_WINDOW( d ), data, filename );
    137         g_free( filename );
     122        char * file = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( d ) );
     123        doSave( GTK_WINDOW( d ), data, file );
     124        g_free( file );
    138125    }
    139126
     
    146133{
    147134    GtkWindow * window = GTK_WINDOW( gtk_widget_get_toplevel( w ) );
    148     GtkWidget * d = gtk_file_chooser_dialog_new( _(
    149                                                      "Save Log" ), window,
     135    GtkWidget * d = gtk_file_chooser_dialog_new( _( "Save Log" ), window,
    150136                                                 GTK_FILE_CHOOSER_ACTION_SAVE,
    151137                                                 GTK_STOCK_CANCEL,
  • trunk/gtk/tr-core.c

    r8763 r8846  
    628628
    629629    /* create the model used to store torrent data */
    630     g_assert( ALEN( types ) == MC_ROW_COUNT );
     630    g_assert( G_N_ELEMENTS( types ) == MC_ROW_COUNT );
    631631    store = gtk_list_store_newv( MC_ROW_COUNT, types );
    632632
  • trunk/gtk/tr-core.h

    r8763 r8846  
    8888    TR_CORE_ERR_ADD_TORRENT_ERR  = TR_EINVALID,
    8989    TR_CORE_ERR_ADD_TORRENT_DUP  = TR_EDUPLICATE,
    90     TR_CORE_ERR_NO_MORE_TORRENTS,  /* finished adding a batch */
    91     TR_CORE_ERR_SAVE_STATE         /* error saving state */
     90    TR_CORE_ERR_NO_MORE_TORRENTS  /* finished adding a batch */
    9291};
    9392
  • trunk/gtk/util.c

    r8758 r8846  
    1 /******************************************************************************
    2  * $Id$
     1/*
     2 * This file Copyright (C) 2008-2009 Charles Kerr <charles@transmissionbt.com>
    33 *
    4  * Copyright (c) 2005-2008 Transmission authors and contributors
     4 * This file is licensed by the GPL version 2.  Works owned by the
     5 * Transmission project are granted a special exemption to clause 2(b)
     6 * so that the bulk of its code can remain under the MIT license.
     7 * This exemption does not extend to derived works not owned by
     8 * the Transmission project.
    59 *
    6  * Permission is hereby granted, free of charge, to any person obtaining a
    7  * copy of this software and associated documentation files (the "Software"),
    8  * to deal in the Software without restriction, including without limitation
    9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    10  * and/or sell copies of the Software, and to permit persons to whom the
    11  * Software is furnished to do so, subject to the following conditions:
    12  *
    13  * The above copyright notice and this permission notice shall be included in
    14  * all copies or substantial portions of the Software.
    15  *
    16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    22  * DEALINGS IN THE SOFTWARE.
    23  *****************************************************************************/
     10 * $Id:$
     11 */
    2412
    2513#include <ctype.h> /* isxdigit() */
     
    305293    g_free( pwd );
    306294    return g_slist_reverse( ret );
    307 }
    308 
    309 static void
    310 onErrorResponse( GtkWidget * dialog,
    311                  int resp    UNUSED,
    312                  gpointer    glist )
    313 {
    314     GSList * list = glist;
    315 
    316     if( list )
    317     {
    318         callbackfunc_t func = list->data;
    319         gpointer       user_data = list->next->data;
    320         func( user_data );
    321         g_slist_free( list );
    322     }
    323 
    324     gtk_widget_destroy( dialog );
    325 }
    326 
    327 static GtkWidget *
    328 verrmsg_full( GtkWindow *    wind,
    329               callbackfunc_t func,
    330               void *         data,
    331               const char *   format,
    332               va_list        ap )
    333 {
    334     GtkWidget *dialog;
    335     char *     msg;
    336     GSList *   funcdata = NULL;
    337 
    338     msg = g_strdup_vprintf( format, ap );
    339 
    340     if( NULL == wind )
    341         dialog = gtk_message_dialog_new(
    342             NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", msg );
    343     else
    344         dialog = gtk_message_dialog_new(
    345             wind,
    346             GTK_DIALOG_MODAL |
    347             GTK_DIALOG_DESTROY_WITH_PARENT,
    348             GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
    349             "%s", msg );
    350 
    351     if( func )
    352     {
    353         funcdata = g_slist_append( funcdata, (gpointer)func );
    354         funcdata = g_slist_append( funcdata, data );
    355     }
    356     g_signal_connect( dialog, "response", G_CALLBACK(
    357                           onErrorResponse ), funcdata );
    358     g_free( msg );
    359 
    360     return dialog;
    361295}
    362296
     
    402336    g_free( secondary );
    403337}
    404 
    405 void
    406 errmsg( GtkWindow *  wind,
    407         const char * format,
    408         ... )
    409 {
    410     GtkWidget * dialog;
    411     va_list     ap;
    412 
    413     va_start( ap, format );
    414     dialog = verrmsg_full( wind, NULL, NULL, format, ap );
    415     va_end( ap );
    416 
    417     if( NULL != wind && !GTK_WIDGET_MAPPED( GTK_WIDGET( wind ) ) )
    418     {
    419         g_signal_connect_swapped( wind, "map",
    420                                   G_CALLBACK( gtk_widget_show ), dialog );
    421     }
    422     else
    423     {
    424         gtk_widget_show( dialog );
    425     }
    426 }
    427 
    428 GtkWidget *
    429 errmsg_full( GtkWindow *    wind,
    430              callbackfunc_t func,
    431              void *         data,
    432              const char *   format,
    433              ... )
    434 {
    435     GtkWidget * dialog;
    436     va_list     ap;
    437 
    438     va_start( ap, format );
    439     dialog = verrmsg_full( wind, func, data, format, ap );
    440     va_end( ap );
    441 
    442     return dialog;
    443 }
    444 
    445338typedef void ( PopupFunc )( GtkWidget*, GdkEventButton* );
    446339
  • trunk/gtk/util.h

    r8757 r8846  
    1 /******************************************************************************
    2  * $Id$
     1/*
     2 * This file Copyright (C) 2008-2009 Charles Kerr <charles@transmissionbt.com>
    33 *
    4  * Copyright (c) 2005-2008 Transmission authors and contributors
     4 * This file is licensed by the GPL version 2.  Works owned by the
     5 * Transmission project are granted a special exemption to clause 2(b)
     6 * so that the bulk of its code can remain under the MIT license.
     7 * This exemption does not extend to derived works not owned by
     8 * the Transmission project.
    59 *
    6  * Permission is hereby granted, free of charge, to any person obtaining a
    7  * copy of this software and associated documentation files (the "Software"),
    8  * to deal in the Software without restriction, including without limitation
    9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    10  * and/or sell copies of the Software, and to permit persons to whom the
    11  * Software is furnished to do so, subject to the following conditions:
    12  *
    13  * The above copyright notice and this permission notice shall be included in
    14  * all copies or substantial portions of the Software.
    15  *
    16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    22  * DEALINGS IN THE SOFTWARE.
    23  *****************************************************************************/
     10 * $Id:$
     11 */
    2412
    25 #ifndef TG_UTIL_H
    26 #define TG_UTIL_H
     13#ifndef GTR_UTIL_H
     14#define GTR_UTIL_H
    2715
    2816#include <sys/types.h>
    29 #include <stdarg.h>
    3017
    3118/* macro to shut up "unused parameter" warnings */
     
    3421#endif
    3522
    36 /* return number of items in array */
    37 #define ALEN( a ) ( (signed)G_N_ELEMENTS( a ) )
    38 
    39 /* used for a callback function with a data parameter */
    40 typedef void ( *callbackfunc_t )( void* );
    41 
    4223/* return a human-readable string for the size given in bytes. */
    43 char*       tr_strlsize( char *   buf,
    44                          guint64  size,
    45                          size_t   buflen );
     24char* tr_strlsize( char * buf, guint64  size, size_t buflen );
    4625
    4726/* return a human-readable string for the transfer rate given in bytes. */
    48 char*       tr_strlspeed( char * buf,
    49                           double KiBps,
    50                           size_t buflen );
     27char* tr_strlspeed( char * buf, double KiBps, size_t buflen );
    5128
    5229/* return a human-readable string for the given ratio. */
    53 char*       tr_strlratio( char * buf,
    54                           double ratio,
    55                           size_t buflen );
     30char* tr_strlratio( char * buf, double ratio, size_t buflen );
    5631
    5732/* return a human-readable string for the time given in seconds. */
    58 char*       tr_strltime( char * buf,
    59                          int    secs,
    60                          size_t buflen );
     33char* tr_strltime( char * buf, int secs, size_t buflen );
    6134
    62 char*       gtr_localtime( time_t time );
     35/* similar to asctime, but is utf8-clean */
     36char* gtr_localtime( time_t time );
    6337
    64 char*       gtr_localtime2( char * buf, time_t time, size_t buflen );
     38/* similar to asctime, but is utf8-clean */
     39char* gtr_localtime2( char * buf, time_t time, size_t buflen );
    6540
    6641/* create a directory and any missing parent directories */
    67 int         mkdir_p( const char *name,
    68                      mode_t      mode );
     42int mkdir_p( const char *name, mode_t mode );
     43
     44/***
     45****
     46***/
    6947
    7048/* create a copy of a GSList of strings, this dups the actual strings too */
    71 GSList *    dupstrlist( GSList * list );
     49GSList * dupstrlist( GSList * list );
    7250
    7351/* joins a GSList of strings into one string using an optional separator */
    74 char *      joinstrlist( GSList *list,
    75                          char *  sep );
     52char * joinstrlist( GSList *list, char *  sep );
    7653
    7754/* free a GSList of strings */
    78 void        freestrlist( GSList *list );
     55void freestrlist( GSList *list );
    7956
    8057/* decodes a string that has been urlencoded */
    81 char *      decode_uri( const char * uri );
     58char * decode_uri( const char * uri );
    8259
    8360/* return a list of cleaned-up paths, with invalid directories removed */
    84 GSList *    checkfilenames( int     argc,
    85                             char ** argv );
     61GSList * checkfilenames( int argc, char ** argv );
     62
     63/***
     64****
     65***/
    8666
    8767void        gtr_open_file( const char * path );
     
    9373char*       gtr_get_help_url( void );
    9474
     75/***
     76****
     77***/
     78
     79/* GTK-related utilities */
    9580#ifdef GTK_MAJOR_VERSION
    9681
    97 guint       gtr_timeout_add_seconds( guint       seconds,
    98                                      GSourceFunc function,
    99                                      gpointer    data );
     82/* backwards-compatible wrapper around gdk_threads_add_timeout_seconds() */
     83guint gtr_timeout_add_seconds( guint seconds, GSourceFunc func, gpointer data );
    10084
    101 void        gtr_idle_add( GSourceFunc  func,
    102                           gpointer    data );
     85/* backwards-compatible wrapper around gdk_threads_add_idle() */
     86void gtr_idle_add( GSourceFunc  func, gpointer data );
    10387
    104 void        gtr_toolbar_set_orientation( GtkToolbar      * toolbar,
    105                                          GtkOrientation    orientation );
     88/* backwards-compatible wrapper around gtk_orientable_set_orientation() */
     89void gtr_toolbar_set_orientation( GtkToolbar * tb, GtkOrientation orientation );
    10690
    107 void        gtr_widget_set_tooltip_text( GtkWidget * w, const char * tip );
     91/* backwards-compatible wrapper around gtk_widget_set_tooltip_text() */
     92void gtr_widget_set_tooltip_text( GtkWidget * w, const char * tip );
    10893
     94/* backwards-compatible wrapper around g_object_ref_sink() */
     95gpointer tr_object_ref_sink( gpointer object );
     96
     97/***
     98****
     99***/
     100
     101/* create a button with the specified mnemonic and stock icon */
    109102GtkWidget * gtr_button_new_from_stock( const char * stock,
    110103                                       const char * mnemonic );
    111104
    112 void        addTorrentErrorDialog( GtkWidget *  window_or_child,
    113                                    int          err,
    114                                    const char * filename );
    115 
    116 /* create an error dialog, if wind is NULL or mapped then show dialog now,
    117    otherwise show it when wind becomes mapped */
    118 void        errmsg( GtkWindow *  wind,
    119                     const char * format,
    120                     ... ) G_GNUC_PRINTF( 2, 3 );
    121 
    122 /* create an error dialog but do not gtk_widget_show() it,
    123    calls func( data ) when the dialog is closed */
    124 GtkWidget * errmsg_full( GtkWindow *    wind,
    125                          callbackfunc_t func,
    126                          void *         data,
    127                          const char *   format,
    128                          ... ) G_GNUC_PRINTF( 4, 5 );
     105void addTorrentErrorDialog( GtkWidget  * window_or_child,
     106                            int          err,
     107                            const char * filename );
    129108
    130109/* pop up the context menu if a user right-clicks.
    131110   if the row they right-click on isn't selected, select it. */
    132 gboolean    on_tree_view_button_pressed( GtkWidget *      view,
    133                                          GdkEventButton * event,
    134                                          gpointer         unused );
     111gboolean on_tree_view_button_pressed( GtkWidget      * view,
     112                                      GdkEventButton * event,
     113                                      gpointer         unused );
    135114
    136115/* if the click didn't specify a row, clear the selection */
    137 gboolean    on_tree_view_button_released( GtkWidget *      view,
    138                                           GdkEventButton * event,
    139                                           gpointer         unused );
     116gboolean on_tree_view_button_released( GtkWidget      * view,
     117                                       GdkEventButton * event,
     118                                       gpointer         unused );
    140119
    141120
    142 
    143 gpointer    tr_object_ref_sink( gpointer object );
    144 
    145 int         tr_file_trash_or_remove( const char * filename );
     121/* move a file to the trashcan if GIO is available; otherwise, delete it */
     122int tr_file_trash_or_remove( const char * filename );
    146123
    147124#endif /* GTK_MAJOR_VERSION */
    148125
    149 #endif /* TG_UTIL_H */
     126#endif /* GTR_UTIL_H */
Note: See TracChangeset for help on using the changeset viewer.