Changeset 8145 for trunk/gtk/tr-prefs.c


Ignore:
Timestamp:
Apr 5, 2009, 2:53:22 PM (13 years ago)
Author:
charles
Message:

(trunk gtk) #1679: schedule speed limit mode based on days, not just time.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/tr-prefs.c

    r8113 r8145  
    10721072
    10731073static void
     1074onWeekComboChanged( GtkComboBox * w, gpointer core )
     1075{
     1076    GtkTreeIter iter;
     1077
     1078    if( gtk_combo_box_get_active_iter( w, &iter ) )
     1079    {
     1080        int val = 0;
     1081        const char * key = g_object_get_data( G_OBJECT( w ), PREF_KEY );
     1082        gtk_tree_model_get( gtk_combo_box_get_model( w ), &iter, 0, &val, -1 );
     1083        tr_core_set_pref_int( TR_CORE( core ), key, val );
     1084    }
     1085}
     1086
     1087static GtkWidget*
     1088new_week_combo( GObject * core, const char * key )
     1089{
     1090    int i;
     1091    int selIndex;
     1092    GtkWidget * w;
     1093    GtkCellRenderer * r;
     1094    GtkListStore * store;
     1095    const int currentValue = pref_int_get( key );
     1096    const struct {
     1097        int value;
     1098        const char * text;
     1099    } items[] = {
     1100        { TR_SCHED_ALL,     N_( "Every Day" ) },
     1101        { TR_SCHED_WEEKDAY, N_( "Weekdays" ) },
     1102        { TR_SCHED_WEEKEND, N_( "Weekends" ) },
     1103        { TR_SCHED_SUN,     N_( "Sunday" ) },
     1104        { TR_SCHED_MON,     N_( "Monday" ) },
     1105        { TR_SCHED_TUES,    N_( "Tuesday" ) },
     1106        { TR_SCHED_WED,     N_( "Wednesday" ) },
     1107        { TR_SCHED_THURS,   N_( "Thursday" ) },
     1108        { TR_SCHED_FRI,     N_( "Friday" ) },
     1109        { TR_SCHED_SAT,     N_( "Saturday" ) }
     1110    };
     1111
     1112    /* build a store for the days of the week */
     1113    selIndex = -1;
     1114    store = gtk_list_store_new( 2, G_TYPE_INT, G_TYPE_STRING );
     1115    for( i=0; i<(int)G_N_ELEMENTS(items); ++i ) {
     1116        GtkTreeIter iter;
     1117        gtk_list_store_append( store, &iter );
     1118        gtk_list_store_set( store, &iter, 0, items[i].value, 1, _( items[i].text ), -1 );
     1119        if( items[i].value == currentValue )
     1120            selIndex = i;
     1121    }
     1122
     1123    /* build the widget */
     1124    w = gtk_combo_box_new_with_model( GTK_TREE_MODEL( store ) );
     1125    r = gtk_cell_renderer_text_new( );
     1126    gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( w ), r, TRUE );
     1127    gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( w ), r, "text", 1, NULL );
     1128    g_object_set_data_full( G_OBJECT( w ), PREF_KEY, tr_strdup( key ), g_free );
     1129    if( selIndex >= 0 )
     1130        gtk_combo_box_set_active( GTK_COMBO_BOX( w ), selIndex );
     1131    g_signal_connect( w, "changed", G_CALLBACK( onWeekComboChanged ), core );
     1132
     1133    /* cleanup */
     1134    g_object_unref( G_OBJECT( store ) );
     1135    return w;
     1136}
     1137
     1138static void
    10741139bandwidthPageFree( gpointer gpage )
    10751140{
     
    11271192        w = new_spin_button( TR_PREFS_KEY_ALT_SPEED_UP, core, 0, INT_MAX, 5 );
    11281193        hig_workarea_add_row( t, &row, s, w, NULL );
     1194
     1195        g_snprintf( buf, sizeof( buf ), "<small>%s</small>", _( "When enabled, Speed Limit Mode overrides the Global Bandwidth Limits" ) );
     1196        w = gtk_label_new( buf );
     1197        gtk_label_set_use_markup( GTK_LABEL( w ), TRUE );
     1198        gtk_misc_set_alignment( GTK_MISC( w ), 0.5f, 0.5f );
     1199        hig_workarea_add_wide_control( t, &row, w );
    11291200
    11301201        s = _( "Use Speed Limit Mode between:" );
     
    11431214        hig_workarea_add_row_w( t, &row, w, h, NULL );
    11441215
    1145         g_snprintf( buf, sizeof( buf ), "<small>%s</small>", _( "When enabled, Speed Limit Mode overrides the Global Bandwidth Limits" ) );
    1146         w = gtk_label_new( buf );
    1147         gtk_label_set_use_markup( GTK_LABEL( w ), TRUE );
    1148         gtk_misc_set_alignment( GTK_MISC( w ), 0.5f, 0.5f );
    1149         hig_workarea_add_wide_control( t, &row, w );
     1216        s = _( "_On days:" );
     1217        w = new_week_combo( core, TR_PREFS_KEY_ALT_SPEED_TIME_DAY );
     1218        page->sched_widgets = g_slist_append( page->sched_widgets, w );
     1219        w = hig_workarea_add_row( t, &row, s, w, NULL );
     1220        page->sched_widgets = g_slist_append( page->sched_widgets, w );
    11501221
    11511222    hig_workarea_finish( t, &row );
Note: See TracChangeset for help on using the changeset viewer.