Changeset 73
- Timestamp:
- 10/25/07 14:35:39 (1 year ago)
- Files:
-
- mh-shot-tool/trunk/Makefile (modified) (1 diff)
- mh-shot-tool/trunk/debian/changelog (modified) (1 diff)
- mh-shot-tool/trunk/shot.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
mh-shot-tool/trunk/Makefile
r71 r73 42 42 mh_shot_tool_CFLAGS += $(shell if pkg-config osso-browser-interface --exists; then pkg-config osso-browser-interface --cflags; echo -DOSSO_BROWSER; fi) 43 43 #mh_shot_tool_LDFLAGS += $(shell if pkg-config hildon-fm-2 --exists; then pkg-config hildon-fm-2 --libs; elif pkg-config hildon-fm --exists; then pkg-config hildon-fm --libs; fi) 44 mh_shot_tool_CFLAGS += $(shell if pkg-config hildon-1 --exists; then pkg-config hildon-1 --cflags; echo -DHILDON=1; elif pkg-config hildon-libs --exists; then pkg-config hildon-libs --cflags; echo -DHILDON=0; else pkg-config gtk+-2.0 --cflags; fi) 44 mh_shot_tool_CFLAGS += $(shell if pkg-config hildon-1 --exists; then \ 45 pkg-config hildon-1 --cflags; echo -DHILDON=1; \ 46 elif pkg-config hildon-libs --exists; then \ 47 pkg-config hildon-libs --cflags; echo -DHILDON=0; \ 48 else pkg-config gtk+-2.0 --cflags; fi) 45 49 mh_shot_tool_LDFLAGS += $(shell if pkg-config hildon-1 --exists; then pkg-config hildon-1 --libs; elif pkg-config hildon-libs --exists; then pkg-config hildon-libs --libs; else pkg-config gtk+-2.0 --libs; fi) 46 50 47 mh_shot_tool_CFLAGS += `pkg-config gtk+-2.0 libsoup-2.2 libosso --cflags` \51 mh_shot_tool_CFLAGS += `pkg-config gtk+-2.0 libsoup-2.2 libosso gconf-2.0 --cflags` \ 48 52 -DPLUGINDIR=\"$(PLUGINDIR)\" -DPACKAGE=\"$(PACKAGE)\" -DVERSION=\"$(VERSION)\" 49 mh_shot_tool_LDFLAGS += `pkg-config gtk+-2.0 libsoup-2.2 libosso --libs` -export-dynamic53 mh_shot_tool_LDFLAGS += `pkg-config gtk+-2.0 libsoup-2.2 libosso gconf-2.0 --libs` -export-dynamic 50 54 51 55 mh_shot_tool_SOURCES := shot.c mh-shot-tool/trunk/debian/changelog
r71 r73 1 mh-shot-tool (0.0.4) mistral; urgency=low 2 3 * Save method and path to gconf. 4 * Add progress bar. 5 6 -- Santtu Lakkala <inz@inz.fi> Thu, 25 Oct 2007 14:34:29 +0300 7 1 8 mh-shot-tool (0.0.3) mistral; urgency=low 2 9 mh-shot-tool/trunk/shot.c
r71 r73 7 7 #include <string.h> 8 8 #include <libosso.h> 9 #include <gconf/gconf-client.h> 9 10 #if defined(TABLET_BROWSER) 10 11 # include <tablet-browser-interface.h> … … 16 17 # include <hildon/hildon-window.h> 17 18 # include <hildon/hildon-defines.h> 19 # include <hildon/hildon-banner.h> 18 20 # else 19 21 # include <hildon-widgets/hildon-window.h> 20 22 # include <hildon-widgets/hildon-defines.h> 23 # include <hildon-widgets/hildon-banner.h> 21 24 # endif 22 25 #else … … 26 29 #define API_KEY "73fc51d360159c5bb4a8f147270cf0c9" 27 30 #define API_SECRET "2537d871c9392998" 31 32 struct PixbufWriteData { 33 GtkWidget *progbar; 34 GString *string; 35 FILE *file; 36 gsize data_written; 37 }; 38 39 static gboolean string_append_data(const gchar *bytes, 40 gsize len, 41 GError **error, 42 gpointer user_data) 43 { 44 struct PixbufWriteData *data = user_data; 45 46 (void)error; 47 48 if (data->file) { 49 fwrite(bytes, 1, len, data->file); 50 } else { 51 g_string_append_len(data->string, bytes, len); 52 } 53 54 data->data_written += len; 55 56 if (len > 0x800) { 57 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(data->progbar)); 58 while (gtk_events_pending()) 59 gtk_main_iteration(); 60 } 61 62 return TRUE; 63 } 64 65 static gchar *pixbuf_png_pack(GdkPixbuf *buf, 66 const gchar *file, 67 gsize *len, 68 GtkWidget *parent) 69 { 70 struct PixbufWriteData data = { NULL, NULL, NULL, 0 }; 71 GtkWidget *banner; 72 GError *error = NULL; 73 74 data.progbar = gtk_progress_bar_new(); 75 76 if (file) { 77 data.file = fopen(file, "w"); 78 } else { 79 data.string = g_string_new(""); 80 } 81 82 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(data.progbar)); 83 banner = hildon_banner_show_progress(parent, 84 GTK_PROGRESS_BAR(data.progbar), 85 "Compressing..."); 86 87 while (gtk_events_pending()) 88 gtk_main_iteration(); 89 90 gdk_pixbuf_save_to_callback(buf, 91 string_append_data, 92 &data, 93 "png", 94 &error, 95 NULL); 96 97 if (error != NULL) { 98 g_error_free(error); 99 } 100 101 if (len) { 102 *len = data.data_written; 103 } 104 105 gtk_widget_destroy(banner); 106 107 return data.string ? g_string_free(data.string, FALSE) : NULL; 108 } 109 28 110 29 111 struct form_multipart_builder … … 331 413 form_multipart_builder_append_string(builder, "auth_token", frob); 332 414 form_multipart_builder_append_string(builder, "content_type", "2"); 333 gdk_pixbuf_save_to_buffer(buf, 334 &buf_data, 335 &buf_size, 336 "png", 337 NULL, 338 NULL); 415 buf_data = pixbuf_png_pack(buf, 416 NULL, 417 &buf_size, 418 GTK_WIDGET(parent)); 339 419 form_multipart_builder_append_file_data(builder, "photo", "image/png", buffer, buf_data, (gssize)buf_size); 340 420 form_multipart_builder_to_message(builder, message); … … 365 445 time_t now = time(NULL); 366 446 struct tm times; 447 gchar *last_path; 367 448 gchar *save; 449 GConfClient *gc; 450 368 451 (void)osso; 452 453 gc = gconf_client_get_default(); 454 455 last_path = gconf_client_get_string(gc, 456 "/apps/mh-shot-tool/disk/path", 457 NULL); 369 458 370 459 localtime_r(&now, ×); 371 460 strftime(buffer, 1023, "shot-%Y-%m-%d-%H-%M-%S.png", ×); 372 461 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(chooser), buffer); 462 if (last_path) 463 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), 464 last_path); 373 465 gtk_widget_show_all(chooser); 374 466 … … 376 468 case SHOT_RESPONSE_OK: 377 469 save = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser)); 378 gdk_pixbuf_save(buf, save, "png", NULL, NULL); 470 pixbuf_png_pack(buf, save, NULL, GTK_WIDGET(parent)); 471 gconf_client_set_string(gc, 472 "/apps/mh-shot-tool/disk/path", 473 gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(chooser)), 474 NULL); 379 475 gtk_widget_destroy(chooser); 476 g_object_unref(gc); 380 477 return TRUE; 381 478 break; 382 479 case SHOT_RESPONSE_CANCEL: 383 480 default: 481 g_object_unref(gc); 384 482 return FALSE; 385 483 break; … … 449 547 int main(int argc, char **argv) 450 548 { 549 GConfClient *gc; 451 550 struct GrabbedData grab; 452 551 GtkWidget *combo; … … 457 556 GtkWidget *button; 458 557 gint ret = GTK_RESPONSE_NONE; 558 gchar *last_handler; 459 559 460 560 g_set_application_name("MH Shot Tool"); … … 486 586 gtk_box_pack_start(GTK_BOX(hbox), grab.spinner, FALSE, FALSE, 0); 487 587 gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new("second interval"), FALSE, FALSE, 0); 488 gtk_ container_add(GTK_CONTAINER(vbox), hbox);588 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); 489 589 490 hbox = gtk_hb ox_new(FALSE, HILDON_MARGIN_DEFAULT);590 hbox = gtk_hbutton_box_new(); 491 591 button = gtk_button_new_with_label("Ok"); 492 592 g_object_set_data(G_OBJECT(button), "response", 493 593 GINT_TO_POINTER(SHOT_RESPONSE_OK)); 494 594 g_signal_connect(button, "clicked", G_CALLBACK(_my_quit), &ret); 495 gtk_ box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);595 gtk_container_add(GTK_CONTAINER(hbox), button); 496 596 button = gtk_button_new_with_label("Cancel"); 497 597 g_object_set_data(G_OBJECT(button), "response", 498 598 GINT_TO_POINTER(SHOT_RESPONSE_CANCEL)); 499 599 g_signal_connect(button, "clicked", G_CALLBACK(_my_quit), &ret); 500 gtk_ box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);600 gtk_container_add(GTK_CONTAINER(hbox), button); 501 601 602 gc = gconf_client_get_default(); 603 last_handler = gconf_client_get_string(gc, 604 "/apps/mh-shot-tool/handler", 605 NULL); 606 502 607 combo = gtk_combo_box_new_text(); 503 608 for (i = 0; handlers[i].name; i++) { 504 609 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), 505 610 handlers[i].name); 506 } 507 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); 508 509 gtk_container_add(GTK_CONTAINER(vbox), combo); 510 gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); 611 if (last_handler && !strcmp(handlers[i].name, last_handler)) { 612 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), i); 613 } 614 } 615 if (gtk_combo_box_get_active(GTK_COMBO_BOX(combo)) == -1) 616 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); 617 618 gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, TRUE, 0); 619 gtk_box_pack_end(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); 511 620 gtk_container_add(GTK_CONTAINER(grab.window), vbox); 512 621 … … 518 627 { 519 628 case SHOT_RESPONSE_OK: 520 handlers[gtk_combo_box_get_active(GTK_COMBO_BOX(combo))].save(grab.buf, GTK_WINDOW(grab.window), osso); 629 i = gtk_combo_box_get_active(GTK_COMBO_BOX(combo)); 630 handlers[i].save(grab.buf, GTK_WINDOW(grab.window), osso); 631 gconf_client_set_string(gc, 632 "/apps/mh-shot-tool/handler", 633 handlers[i].name, 634 NULL); 521 635 break; 522 636 case SHOT_RESPONSE_CANCEL: … … 525 639 } 526 640 g_object_unref(grab.buf); 641 g_object_unref(gc); 642 g_free(last_handler); 527 643 osso_deinitialize(osso); 528 644
