Changeset 249
- Timestamp:
- May 3, 2006, 10:09:11 AM (17 years ago)
- Location:
- trunk/gtk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gtk/conf.c
r248 r249 26 26 27 27 #include <sys/types.h> 28 #include <assert.h>29 28 #include <ctype.h> 30 29 #include <errno.h> … … 342 341 const char * 343 342 cf_getpref(const char *name) { 344 assert(NULL != gl_prefs);343 g_assert(NULL != gl_prefs); 345 344 346 345 return g_tree_lookup(gl_prefs, name); … … 349 348 void 350 349 cf_setpref(const char *name, const char *value) { 351 assert(NULL != gl_prefs);350 g_assert(NULL != gl_prefs); 352 351 353 352 g_tree_insert(gl_prefs, g_strdup(name), g_strdup(value)); -
trunk/gtk/dialogs.c
r248 r249 25 25 */ 26 26 27 #include <assert.h>28 27 #include <errno.h> 29 28 #include <stdlib.h> … … 174 173 175 174 #undef RN 176 assert(rowcount == ii);175 g_assert(rowcount == ii); 177 176 178 177 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(wind)->vbox), table); … … 496 495 INFOSEP(table, ii); 497 496 498 assert(rowcount == ii);497 g_assert(rowcount == ii); 499 498 500 499 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(wind)->vbox), table); -
trunk/gtk/ipc.c
r248 r249 28 28 #include <sys/socket.h> 29 29 #include <sys/un.h> 30 #include <assert.h>31 30 #include <errno.h> 32 31 #include <fcntl.h> -
trunk/gtk/main.c
r248 r249 26 26 27 27 #include <sys/param.h> 28 #include <assert.h>29 28 #include <errno.h> 30 29 #include <signal.h> … … 48 47 #include "util.h" 49 48 49 /* time in seconds to wait for torrents to stop when exiting */ 50 50 #define TRACKER_EXIT_TIMEOUT 5 51 52 /* interval in milliseconds to update the torrent list display */ 53 #define UPDATE_INTERVAL 500 54 55 /* interval in milliseconds to check for stopped torrents and update display */ 56 #define EXIT_CHECK_INTERVAL 500 51 57 52 58 struct cbdata { … … 73 79 void 74 80 makewind(GtkWidget *wind, TrBackend *back, benc_val_t *state, GList *args); 81 void 82 quittransmission(struct cbdata *data); 75 83 GtkWidget * 76 84 makewind_toolbar(struct cbdata *data); … … 81 89 gboolean 82 90 exitcheck(gpointer gdata); 83 void84 stoptransmission(struct cbdata *data);85 91 void 86 92 setupdrag(GtkWidget *widget, struct cbdata *data); … … 163 169 164 170 static sig_atomic_t global_sigcount = 0; 165 static int global_lastsig = 0;166 171 167 172 int … … 286 291 data->back = back; 287 292 data->wind = GTK_WINDOW(wind); 288 data->timer = -1;293 data->timer = 0; 289 294 /* filled in by makewind_list */ 290 295 data->model = NULL; … … 307 312 gtk_box_pack_start(GTK_BOX(vbox), status, FALSE, FALSE, 0); 308 313 314 gtk_container_set_focus_child(GTK_CONTAINER(vbox), scroll); 309 315 gtk_container_add(GTK_CONTAINER(wind), vbox); 310 316 gtk_window_set_title(data->wind, g_get_application_name()); … … 315 321 addtorrents(data, state, args, NULL, NULL); 316 322 317 data->timer = g_timeout_add( 500, updatemodel, data);323 data->timer = g_timeout_add(UPDATE_INTERVAL, updatemodel, data); 318 324 updatemodel(data); 319 325 … … 333 339 334 340 ipc_socket_setup(GTK_WINDOW(wind), addtorrents, data); 341 } 342 343 void 344 quittransmission(struct cbdata *data) { 345 g_object_unref(G_OBJECT(data->back)); 346 gtk_widget_destroy(GTK_WIDGET(data->wind)); 347 if(0 < data->timer) 348 g_source_remove(data->timer); 349 if(NULL != data->stupidpopuphack) 350 gtk_widget_destroy(data->stupidpopuphack); 351 g_free(data->buttons); 352 g_free(data); 353 gtk_main_quit(); 335 354 } 336 355 … … 389 408 char *str; 390 409 391 assert(MC_ROW_COUNT == ALEN(types));410 g_assert(MC_ROW_COUNT == ALEN(types)); 392 411 393 412 store = gtk_list_store_newv(MC_ROW_COUNT, types); … … 434 453 struct cbdata *data = gdata; 435 454 struct exitdata *edata; 436 tr_stat_t *st; 437 GtkTreeIter iter; 438 TrTorrent *tor; 439 gboolean going; 440 441 if(0 >= data->timer) 455 unsigned int ii; 456 457 /* stop the update timer */ 458 if(0 < data->timer) 442 459 g_source_remove(data->timer); 443 data->timer = -1; 444 445 going = gtk_tree_model_get_iter_first(data->model, &iter); 446 while(going) { 447 gtk_tree_model_get(data->model, &iter, MC_TORRENT, &tor, -1); 448 st = tr_torrent_stat(tor); 449 if(TR_STATUS_ACTIVE & st->status) { 450 tr_torrentStop(tr_torrent_handle(tor)); 451 going = gtk_tree_model_iter_next(data->model, &iter); 452 } else { 453 going = gtk_list_store_remove(GTK_LIST_STORE(data->model), &iter); 454 } 455 g_object_unref(G_OBJECT(tor)); 456 } 457 458 /* XXX should disable widgets or something */ 459 460 /* try to wait until torrents stop before exiting */ 460 data->timer = 0; 461 462 /* try to stop all the torrents */ 463 tr_backend_stop_torrents(data->back); 464 465 /* set things up to wait for torrents to stop */ 461 466 edata = g_new0(struct exitdata, 1); 462 467 edata->cbdata = data; 463 468 edata->started = time(NULL); 464 edata->timer = g_timeout_add(500, exitcheck, edata); 469 /* check if torrents are still running */ 470 if(exitcheck(edata)) { 471 /* yes, start the exit timer and disable widgets */ 472 edata->timer = g_timeout_add(EXIT_CHECK_INTERVAL, exitcheck, edata); 473 for(ii = 0; ii < ALEN(actionitems); ii++) 474 gtk_widget_set_sensitive(data->buttons[ii], FALSE); 475 gtk_widget_set_sensitive(GTK_WIDGET(data->view), FALSE); 476 } 465 477 466 478 /* returning FALSE means to destroy the window */ … … 471 483 exitcheck(gpointer gdata) { 472 484 struct exitdata *data = gdata; 473 tr_stat_t *st;474 GtkTreeIter iter;475 TrTorrent *tor;476 gboolean go;477 478 go = gtk_tree_model_get_iter_first(data->cbdata->model, &iter);479 while(go) {480 gtk_tree_model_get(data->cbdata->model, &iter, MC_TORRENT, &tor, -1);481 st = tr_torrent_stat(tor);482 if(!(TR_STATUS_PAUSE & st->status))483 go = gtk_tree_model_iter_next(data->cbdata->model, &iter);484 else {485 go = gtk_list_store_remove(GTK_LIST_STORE(data->cbdata->model), &iter);486 }487 g_object_unref(G_OBJECT(tor));488 }489 485 490 486 /* keep going if we still have torrents and haven't hit the exit timeout */ 491 if(0 < tr_torrentCount(tr_backend_handle(data->cbdata->back)) && 492 time(NULL) - data->started < TRACKER_EXIT_TIMEOUT) { 493 assert(gtk_tree_model_get_iter_first(data->cbdata->model, &iter)); 487 if(time(NULL) - data->started < TRACKER_EXIT_TIMEOUT && 488 !tr_backend_torrents_stopped(data->cbdata->back)) { 494 489 updatemodel(data->cbdata); 495 490 return TRUE; … … 497 492 498 493 /* exit otherwise */ 499 500 if(0 >= data->timer) 494 if(0 < data->timer) 501 495 g_source_remove(data->timer); 502 data->timer = -1; 503 504 stoptransmission(data->cbdata); 505 506 gtk_widget_destroy(GTK_WIDGET(data->cbdata->wind)); 507 if(NULL != data->cbdata->stupidpopuphack) 508 gtk_widget_destroy(data->cbdata->stupidpopuphack); 509 g_free(data->cbdata->buttons); 510 g_free(data->cbdata); 496 quittransmission(data->cbdata); 511 497 g_free(data); 512 gtk_main_quit();513 498 514 499 return FALSE; 515 }516 517 void518 stoptransmission(struct cbdata *data) {519 GtkTreeIter iter;520 TrTorrent *tor;521 gboolean go;522 523 go = gtk_tree_model_get_iter_first(data->model, &iter);524 while(go) {525 gtk_tree_model_get(data->model, &iter, MC_TORRENT, &tor, -1);526 go = gtk_list_store_remove(GTK_LIST_STORE(data->model), &iter);527 g_object_unref(G_OBJECT(tor));528 }529 g_assert(0 == tr_torrentCount(tr_backend_handle(data->back)));530 531 g_object_unref(G_OBJECT(data->back));532 500 } 533 501 … … 696 664 else { 697 665 top = g_strdup(""); 698 assert("XXX unknown status");666 g_assert_not_reached(); 699 667 } 700 668 … … 763 731 764 732 if(0 < global_sigcount) { 765 stoptransmission(data); 766 global_sigcount = SIGCOUNT_MAX; 767 raise(global_lastsig); 733 quittransmission(data); 734 return FALSE; 768 735 } 769 736 … … 929 896 if(actionitems[info.off].act == info.act) 930 897 break; 931 assert(info.off < ALEN(actionitems));898 g_assert(info.off < ALEN(actionitems)); 932 899 933 900 gtk_tree_selection_selected_foreach(sel, popupaction, &info); 934 901 935 902 for(ii = info.dead; NULL != ii; ii = ii->next) { 936 assert(gtk_tree_row_reference_valid(ii->data));903 g_assert(gtk_tree_row_reference_valid(ii->data)); 937 904 path = gtk_tree_row_reference_get_path(ii->data); 938 905 gtk_tree_selection_unselect_path(info.sel, path); 939 906 if(gtk_tree_model_get_iter(data->model, &iter, path)) 940 907 gtk_list_store_remove(GTK_LIST_STORE(data->model), &iter); 941 else 942 assert(!"bad path"); 908 else { 909 g_assert_not_reached(); 910 } 943 911 gtk_tree_path_free(path); 944 912 gtk_tree_row_reference_free(ii->data); … … 1142 1110 struct sigaction sa; 1143 1111 1144 global_lastsig = sig;1145 1146 1112 if(SIGCOUNT_MAX <= ++global_sigcount) { 1147 1113 bzero(&sa, sizeof(sa)); -
trunk/gtk/tr_backend.c
r248 r249 136 136 self->disposed = TRUE; 137 137 138 fprintf(stderr, "back dispose %p\n", self);139 140 138 if(NULL != self->torrents) { 141 139 for(ii = self->torrents; NULL != ii; ii = ii->next) … … 153 151 GObjectClass *parent = g_type_class_peek(g_type_parent(TR_BACKEND_TYPE)); 154 152 TrBackend *self = (TrBackend *)obj; 155 156 fprintf(stderr, "back finalize %p\n", self);157 153 158 154 if(NULL != self->handle) … … 237 233 back->torrents = g_list_remove(back->torrents, tor); 238 234 } 235 236 void 237 tr_backend_stop_torrents(TrBackend *back) { 238 GList *ii; 239 240 TR_IS_BACKEND(back); 241 242 for(ii = back->torrents; NULL != ii; ii = ii->next) 243 if(TR_STATUS_ACTIVE & tr_torrent_stat(ii->data)->status) 244 tr_torrentStop(tr_torrent_handle(ii->data)); 245 } 246 247 gboolean 248 tr_backend_torrents_stopped(TrBackend *back) { 249 GList *ii; 250 251 TR_IS_BACKEND(back); 252 253 for(ii = back->torrents; NULL != ii; ii = ii->next) 254 if(TR_STATUS_ACTIVE & tr_torrent_stat(ii->data)->status) 255 return FALSE; 256 257 return TRUE; 258 } -
trunk/gtk/tr_backend.h
r248 r249 49 49 tr_backend_load_state(TrBackend *back, benc_val_t *state, GList **errors); 50 50 51 void 52 tr_backend_stop_torrents(TrBackend *back); 53 54 gboolean 55 tr_backend_torrents_stopped(TrBackend *back); 56 51 57 #ifdef TR_WANT_BACKEND_PRIVATE 52 58 void -
trunk/gtk/tr_torrent.c
r248 r249 33 33 static void 34 34 tr_torrent_dispose(GObject *obj); 35 static void36 tr_torrent_finalize(GObject *obj);37 35 static void 38 36 tr_torrent_set_folder(TrTorrent *tor); … … 71 69 gobject_class->get_property = tr_torrent_get_property; 72 70 gobject_class->dispose = tr_torrent_dispose; 73 gobject_class->finalize = tr_torrent_finalize;74 71 75 72 pspec = g_param_spec_pointer("torrent-handle", "Torrent handle", … … 179 176 self->disposed = TRUE; 180 177 181 fprintf(stderr, "tor dispose %p\n", self);182 183 178 if(NULL != self->handle) { 184 179 if(!tr_torrent_paused(self)) … … 195 190 /* Chain up to the parent class */ 196 191 parent->dispose(obj); 197 }198 199 static void200 tr_torrent_finalize(GObject *obj) {201 GObjectClass *parent = g_type_class_peek(g_type_parent(TR_TORRENT_TYPE));202 TrTorrent *self = (TrTorrent *)obj;203 204 fprintf(stderr, "tor finalize %p\n", self);205 206 /* Chain up to the parent class */207 parent->finalize(obj);208 192 } 209 193
Note: See TracChangeset
for help on using the changeset viewer.