Changeset 49


Ignore:
Timestamp:
Jan 25, 2006, 4:35:17 PM (16 years ago)
Author:
joshe
Message:

Many small usability improvements.
Remove an ugly wart in the conf api.

Location:
branches/oneport
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/oneport/TODO

    r48 r49  
    1414remove torrents from saved state if they fail to open
    1515height of rows inconsistent between downloading and complete
     16reduce cpu usage, use select on non-beos platforms
    1617
    1718new libtransmission api:
  • branches/oneport/gtk/conf.c

    r24 r49  
    11/*
    2   Copyright (c) 2005 Joshua Elsasser. All rights reserved.
     2  Copyright (c) 2005-2006 Joshua Elsasser. All rights reserved.
    33   
    44  Redistribution and use in source and binary forms, with or without
     
    5454lockfile(const char *file, char **errstr);
    5555static gboolean
    56 writeprefs(char **errstr);
    57 static gboolean
    5856writefile_traverse(gpointer key, gpointer value, gpointer data);
    5957static char *
     
    204202}
    205203
    206 gboolean
    207 cf_setpref(const char *name, const char *value, char **errstr) {
     204void
     205cf_setpref(const char *name, const char *value) {
    208206  assert(NULL != prefs);
    209207
    210208  g_tree_insert(prefs, g_strdup(name), g_strdup(value));
    211 
    212   if(NULL != errstr)
    213     return writeprefs(errstr);
    214   else
    215     return TRUE;
    216209}
    217210
     
    221214};
    222215
    223 static gboolean
    224 writeprefs(char **errstr) {
     216gboolean
     217cf_saveprefs(char **errstr) {
    225218  char *file = g_build_filename(confdir, FILE_PREFS, NULL);
    226219  char *tmpfile = g_build_filename(confdir, FILE_PREFS_TMP, NULL);
     
    230223
    231224  assert(NULL != prefs);
     225  assert(NULL != errstr);
    232226
    233227  *errstr = NULL;
  • branches/oneport/gtk/conf.h

    r7 r49  
    11/*
    2   Copyright (c) 2005 Joshua Elsasser. All rights reserved.
     2  Copyright (c) 2005-2006 Joshua Elsasser. All rights reserved.
    33   
    44  Redistribution and use in source and binary forms, with or without
     
    4444const char *
    4545cf_getpref(const char *name);
    46 /* if errstr is NULL then prefs will not be saved */
     46void
     47cf_setpref(const char *name, const char *value);
    4748gboolean
    48 cf_setpref(const char *name, const char *value, char **errstr);
     49cf_saveprefs(char **errstr);
    4950GList *
    5051cf_loadstate(char **errstr);
  • branches/oneport/gtk/main.c

    r24 r49  
    11/*
    2   Copyright (c) 2005 Joshua Elsasser. All rights reserved.
     2  Copyright (c) 2005-2006 Joshua Elsasser. All rights reserved.
    33   
    44  Redistribution and use in source and binary forms, with or without
     
    171171  gtk_init(&argc, &argv);
    172172
     173  g_set_application_name("Transmission");
     174
    173175  tr = tr_init();
    174176
     
    273275
    274276  gtk_container_add(GTK_CONTAINER(wind), vbox);
     277  gtk_window_set_title(data->wind, g_get_application_name());
    275278  g_signal_connect(G_OBJECT(wind), "delete_event", G_CALLBACK(winclose), data);
    276279
     
    289292  gtk_widget_realize(wind);
    290293
    291   gtk_widget_size_request(wind, &req);
     294  gtk_widget_size_request(list, &req);
    292295  height = req.height;
    293296  gtk_widget_size_request(scroll, &req);
    294297  height -= req.height;
    295   gtk_widget_size_request(list, &req);
     298  gtk_widget_size_request(wind, &req);
    296299  height += req.height;
    297   gtk_window_set_default_size(GTK_WINDOW(wind), -1, MAX(height, 100));
     300  gtk_window_set_default_size(GTK_WINDOW(wind), -1, (height > req.width ?
     301     MIN(height, req.width * 8 / 5) : MAX(height, req.width * 5 / 8)));
    298302
    299303  gtk_widget_show(wind);
  • branches/oneport/gtk/prefs.c

    r40 r49  
    11/*
    2   Copyright (c) 2005 Joshua Elsasser. All rights reserved.
     2  Copyright (c) 2005-2006 Joshua Elsasser. All rights reserved.
    33   
    44  Redistribution and use in source and binary forms, with or without
     
    4141  GtkCheckButton *uselimit;
    4242  GtkSpinButton *limit;
    43   GtkEntry *dir;
     43  GtkFileChooser *dir;
    4444  GtkWindow *parent;
    4545  tr_handle_t *tr;
     
    7171void
    7272makeprefwindow(GtkWindow *parent, tr_handle_t *tr) {
    73   GtkWidget *wind = gtk_dialog_new_with_buttons("Preferences", parent,
    74     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK,
    75     GTK_RESPONSE_OK, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
     73  char *title = g_strconcat(g_get_application_name(), " Preferences", NULL);
     74  GtkWidget *wind = gtk_dialog_new_with_buttons(title, parent,
     75   GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
     76   GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
     77   GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
    7678  GtkWidget *table = gtk_table_new(4, 2, FALSE);
    7779  GtkWidget *portnum = gtk_spin_button_new_with_range(1, 0xffff, 1);
    7880  GtkWidget *limitbox = gtk_check_button_new_with_label("Limit upload speed");
    7981  GtkWidget *limitnum = gtk_spin_button_new_with_range(0, G_MAXLONG, 1);
    80   GtkWidget *dirstr = gtk_entry_new();
     82  GtkWidget *dirstr = gtk_file_chooser_button_new("Choose download directory",
     83    GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
    8184  GtkWidget *label;
     85  GtkWidget **array;
    8286  const char *pref;
    8387  struct prefdata *data = g_new0(struct prefdata, 1);
     88
     89  g_free(title);
     90  gtk_table_set_col_spacings(GTK_TABLE(table), 12);
     91  gtk_table_set_row_spacings(GTK_TABLE(table), 12);
     92  gtk_dialog_set_default_response(GTK_DIALOG(wind), GTK_RESPONSE_OK);
     93  gtk_container_set_border_width(GTK_CONTAINER(table), 12);
    8494
    8595  data->port = GTK_SPIN_BUTTON(portnum);
    8696  data->uselimit = GTK_CHECK_BUTTON(limitbox);
    8797  data->limit = GTK_SPIN_BUTTON(limitnum);
    88   data->dir = GTK_ENTRY(dirstr);
     98  data->dir = GTK_FILE_CHOOSER(dirstr);
    8999  data->parent = parent;
    90100  data->tr = tr;
    91101
    92102  /* port label and entry */
    93   label = gtk_label_new("Listening port");
    94   if(NULL != (pref = cf_getpref(PREF_PORT)))
    95     gtk_spin_button_set_value(GTK_SPIN_BUTTON(portnum), strtol(pref,NULL,10));
    96   else
    97     gtk_spin_button_set_value(GTK_SPIN_BUTTON(portnum), TR_DEFAULT_PORT);
     103  label = gtk_label_new("Listening port:");
     104  gtk_misc_set_alignment(GTK_MISC(label), 0, .5);
     105  pref = cf_getpref(PREF_PORT);
     106  gtk_spin_button_set_value(GTK_SPIN_BUTTON(portnum),
     107    (NULL == pref ? TR_DEFAULT_PORT : strtol(pref, NULL, 10)));
    98108  gtk_table_attach_defaults(GTK_TABLE(table), label,            0, 1, 0, 1);
    99109  gtk_table_attach_defaults(GTK_TABLE(table), portnum,          1, 2, 0, 1);
     
    103113  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(limitbox),
    104114    (NULL == pref ? TRUE : strbool(pref)));
    105   gtk_widget_set_sensitive(limitnum,
    106     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(limitbox)));
    107   g_signal_connect(G_OBJECT(limitbox), "clicked",
    108                    G_CALLBACK(clicklimitbox), limitnum);
     115  array = g_new(GtkWidget*, 2);
     116  g_signal_connect_data(limitbox, "clicked", G_CALLBACK(clicklimitbox),
     117                        array, (GClosureNotify)g_free, 0);
    109118  gtk_table_attach_defaults(GTK_TABLE(table), limitbox,         0, 2, 1, 2);
    110119
    111120  /* limit label and entry */
    112   label = gtk_label_new("Maximum upload speed");
     121  label = gtk_label_new("Maximum upload speed:");
     122  gtk_misc_set_alignment(GTK_MISC(label), 0, 1.0/3.0);
    113123  pref = cf_getpref(PREF_LIMIT);
    114124  gtk_spin_button_set_value(GTK_SPIN_BUTTON(limitnum),
     
    116126  gtk_table_attach_defaults(GTK_TABLE(table), label,            0, 1, 2, 3);
    117127  gtk_table_attach_defaults(GTK_TABLE(table), limitnum,         1, 2, 2, 3);
    118 
    119   /* directory label and entry */
    120   label = gtk_label_new("Download directory");
     128  array[0] = label;
     129  array[1] = limitnum;
     130  clicklimitbox(limitbox, array);
     131
     132  /* directory label and chooser */
     133  label = gtk_label_new("Download Directory:");
     134  gtk_misc_set_alignment(GTK_MISC(label), 0, .5);
    121135  if(NULL != (pref = cf_getpref(PREF_DIR)))
    122     gtk_entry_set_text(GTK_ENTRY(dirstr), pref);
     136    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dirstr), pref);
    123137  gtk_table_attach_defaults(GTK_TABLE(table), label,            0, 1, 3, 4);
    124138  gtk_table_attach_defaults(GTK_TABLE(table), dirstr,           1, 2, 3, 4);
    125139
    126140  gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(wind)->vbox), table);
    127   g_signal_connect(G_OBJECT(wind), "response", G_CALLBACK(clickdialog), data);
     141  g_signal_connect_data(wind, "response", G_CALLBACK(clickdialog),
     142                        data, (GClosureNotify)g_free, 0);
    128143  gtk_widget_show_all(wind);
    129144}
     
    131146static void
    132147clicklimitbox(GtkWidget *widget, gpointer gdata) {
    133   GtkWidget *entry = gdata;
    134 
    135   gtk_widget_set_sensitive(entry,
    136     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)));
     148  GtkWidget **widgets = gdata;
     149  int ii;
     150
     151  for(ii = 0; 2 > ii; ii++)
     152    gtk_widget_set_sensitive(widgets[ii],
     153      gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)));
    137154}
    138155
     
    147164  if(GTK_RESPONSE_OK == resp) {
    148165    /* check directory */
    149     strval = gtk_entry_get_text(data->dir);
    150     if('\0' != strval[0] &&!mkdir_p(strval, 0777)) {
    151       errmsg(data->parent, "Failed to create directory %s:\n%s",
    152              strval, strerror(errno));
    153       return;
     166    if(NULL != (strval = gtk_file_chooser_get_current_folder(data->dir))) {
     167      if(!mkdir_p(strval, 0777)) {
     168        errmsg(data->parent, "Failed to create directory %s:\n%s",
     169               strval, strerror(errno));
     170        return;
     171      }
     172
     173      /* save dir pref */
     174      cf_setpref(PREF_DIR, strval);
    154175    }
    155 
    156     /* save dir pref */
    157     cf_setpref(PREF_DIR, gtk_entry_get_text(data->dir), NULL);
    158176
    159177    /* save port pref */
    160178    strnum = g_strdup_printf("%i",
    161179      gtk_spin_button_get_value_as_int(data->port));
    162     cf_setpref(PREF_PORT, strnum, NULL);
     180    cf_setpref(PREF_PORT, strnum);
    163181    g_free(strnum);
    164182
    165183    /* save uselimit pref */
    166184    boolval = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->uselimit));
    167     cf_setpref(PREF_USELIMIT, (boolval ? "yes" : "no"), NULL);
     185    cf_setpref(PREF_USELIMIT, (boolval ? "yes" : "no"));
    168186
    169187    /* save limit pref */
    170188    intval = gtk_spin_button_get_value_as_int(data->limit);
    171189    strnum = g_strdup_printf("%i", intval);
    172     /*
    173       note that prefs aren't written to disk unless we pass a pointer
    174       to an error string, so do this for the last call to cf_setpref()
    175     */
    176     if(!cf_setpref(PREF_LIMIT, strnum, &errstr)) {
     190    cf_setpref(PREF_LIMIT, strnum);
     191
     192    /* save prefs */
     193    if(!cf_saveprefs(&errstr)) {
    177194      errmsg(data->parent, "%s", errstr);
    178195      g_free(strnum);
     
    185202
    186203  gtk_widget_destroy(widget);
    187   g_free(data);
    188204}
    189205
     
    207223    GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
    208224  struct addcb *data = g_new(struct addcb, 1);
    209   GtkWidget *vbox = gtk_vbox_new(FALSE, 5);
     225  GtkWidget *vbox = gtk_vbox_new(FALSE, 3);
    210226  GtkWidget *bbox = gtk_hbutton_box_new();
    211227  GtkWidget *autocheck = gtk_check_button_new_with_label(
     
    239255  if(NULL != (pref = cf_getpref(PREF_DIR)))
    240256    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(getdir), pref);
    241   else {
    242     pref = g_get_current_dir();
    243     gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(getdir), pref);
    244     g_free((char*)pref);
    245   }
    246257
    247258  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dircheck), FALSE);
     
    342353  } while(0);
    343354
    344 #define INFOSTATUS(st) \
    345   (TR_STATUS_CHECK    & (st) ? "check" : \
    346   (TR_STATUS_DOWNLOAD & (st) ? "download" : \
    347   (TR_STATUS_SEED     & (st) ? "seed" : \
    348   (TR_STATUS_STOPPING & (st) ? "stopping" : \
    349   (TR_STATUS_STOPPED  & (st) ? "stopped" : \
    350   (TR_STATUS_PAUSE    & (st) ? "pause" : \
    351   "???"))))))
    352 
    353355void
    354356makeinfowind(GtkWindow *parent, tr_handle_t *tr, int id) {
     
    357359  int ii;
    358360  char *str;
    359   const int rowcount = 11;
     361  const int rowcount = 12;
    360362
    361363  /* XXX would be nice to be able to stat just one */
    362364  if(id >= tr_torrentStat(tr, &sb))
    363365    assert(!"XXX ");
    364   str = g_strdup_printf("%s Properties", sb[id].info.name);
     366  str = g_strconcat(sb[id].info.name, " Properties", NULL);
    365367  wind = gtk_dialog_new_with_buttons(str, parent,
    366     GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
     368    GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
     369    GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
    367370  g_free(str);
    368371
    369372  table = gtk_table_new(rowcount, 2, FALSE);
    370   gtk_table_set_col_spacings(GTK_TABLE(table), 10);
    371   gtk_table_set_row_spacings(GTK_TABLE(table), 10);
     373  gtk_table_set_col_spacings(GTK_TABLE(table), 12);
     374  gtk_table_set_row_spacings(GTK_TABLE(table), 12);
    372375
    373376  label = gtk_label_new(NULL);
     
    394397  INFOLINEA(table, ii, "Uploaded", readablesize(sb[id].uploaded, 1));
    395398
     399  INFOSEP(table, ii);
     400
    396401  assert(rowcount == ii);
    397402
    398   gtk_container_set_border_width(GTK_CONTAINER(table), 10);
     403  gtk_container_set_border_width(GTK_CONTAINER(table), 12);
    399404  gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(wind)->vbox), table);
    400405  g_signal_connect(G_OBJECT(wind), "response",
Note: See TracChangeset for help on using the changeset viewer.