Changeset 73

Show
Ignore:
Timestamp:
10/25/07 14:35:39 (1 year ago)
Author:
inz
Message:
  • Save method and path to gconf.
  • Add progress bar.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mh-shot-tool/trunk/Makefile

    r71 r73  
    4242mh_shot_tool_CFLAGS += $(shell if pkg-config osso-browser-interface --exists; then pkg-config osso-browser-interface --cflags; echo -DOSSO_BROWSER; fi) 
    4343#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) 
     44mh_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) 
    4549mh_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) 
    4650 
    47 mh_shot_tool_CFLAGS += `pkg-config gtk+-2.0 libsoup-2.2 libosso --cflags` \ 
     51mh_shot_tool_CFLAGS += `pkg-config gtk+-2.0 libsoup-2.2 libosso gconf-2.0 --cflags` \ 
    4852                -DPLUGINDIR=\"$(PLUGINDIR)\" -DPACKAGE=\"$(PACKAGE)\" -DVERSION=\"$(VERSION)\" 
    49 mh_shot_tool_LDFLAGS += `pkg-config gtk+-2.0 libsoup-2.2 libosso --libs` -export-dynamic 
     53mh_shot_tool_LDFLAGS += `pkg-config gtk+-2.0 libsoup-2.2 libosso gconf-2.0 --libs` -export-dynamic 
    5054 
    5155mh_shot_tool_SOURCES := shot.c 
  • mh-shot-tool/trunk/debian/changelog

    r71 r73  
     1mh-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 
    18mh-shot-tool (0.0.3) mistral; urgency=low 
    29 
  • mh-shot-tool/trunk/shot.c

    r71 r73  
    77#include <string.h> 
    88#include <libosso.h> 
     9#include <gconf/gconf-client.h> 
    910#if defined(TABLET_BROWSER) 
    1011# include <tablet-browser-interface.h> 
     
    1617#  include <hildon/hildon-window.h> 
    1718#  include <hildon/hildon-defines.h> 
     19#  include <hildon/hildon-banner.h> 
    1820# else 
    1921#  include <hildon-widgets/hildon-window.h> 
    2022#  include <hildon-widgets/hildon-defines.h> 
     23#  include <hildon-widgets/hildon-banner.h> 
    2124# endif 
    2225#else 
     
    2629#define API_KEY "73fc51d360159c5bb4a8f147270cf0c9" 
    2730#define API_SECRET "2537d871c9392998" 
     31 
     32struct PixbufWriteData { 
     33        GtkWidget *progbar; 
     34        GString *string; 
     35        FILE *file; 
     36        gsize data_written; 
     37}; 
     38 
     39static 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 
     65static 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 
    28110 
    29111struct form_multipart_builder 
     
    331413        form_multipart_builder_append_string(builder, "auth_token", frob); 
    332414        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)); 
    339419        form_multipart_builder_append_file_data(builder, "photo", "image/png", buffer, buf_data, (gssize)buf_size); 
    340420        form_multipart_builder_to_message(builder, message); 
     
    365445        time_t now = time(NULL); 
    366446        struct tm times; 
     447        gchar *last_path; 
    367448        gchar *save; 
     449        GConfClient *gc; 
     450 
    368451        (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); 
    369458 
    370459        localtime_r(&now, &times); 
    371460        strftime(buffer, 1023, "shot-%Y-%m-%d-%H-%M-%S.png", &times); 
    372461        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); 
    373465        gtk_widget_show_all(chooser); 
    374466 
     
    376468        case SHOT_RESPONSE_OK: 
    377469                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); 
    379475                gtk_widget_destroy(chooser); 
     476                g_object_unref(gc); 
    380477                return TRUE; 
    381478                break; 
    382479        case SHOT_RESPONSE_CANCEL: 
    383480        default: 
     481                g_object_unref(gc); 
    384482                return FALSE; 
    385483                break; 
     
    449547int main(int argc, char **argv) 
    450548{ 
     549        GConfClient *gc; 
    451550        struct GrabbedData grab; 
    452551        GtkWidget *combo; 
     
    457556        GtkWidget *button; 
    458557        gint ret = GTK_RESPONSE_NONE; 
     558        gchar *last_handler; 
    459559 
    460560        g_set_application_name("MH Shot Tool"); 
     
    486586        gtk_box_pack_start(GTK_BOX(hbox), grab.spinner, FALSE, FALSE, 0); 
    487587        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); 
    489589         
    490         hbox = gtk_hbox_new(FALSE, HILDON_MARGIN_DEFAULT); 
     590        hbox = gtk_hbutton_box_new(); 
    491591        button = gtk_button_new_with_label("Ok"); 
    492592        g_object_set_data(G_OBJECT(button), "response", 
    493593                          GINT_TO_POINTER(SHOT_RESPONSE_OK)); 
    494594        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); 
    496596        button = gtk_button_new_with_label("Cancel"); 
    497597        g_object_set_data(G_OBJECT(button), "response", 
    498598                          GINT_TO_POINTER(SHOT_RESPONSE_CANCEL)); 
    499599        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); 
    501601                                              
     602        gc = gconf_client_get_default(); 
     603        last_handler = gconf_client_get_string(gc, 
     604                                               "/apps/mh-shot-tool/handler", 
     605                                               NULL); 
     606         
    502607        combo = gtk_combo_box_new_text(); 
    503608        for (i = 0; handlers[i].name; i++) { 
    504609                gtk_combo_box_append_text(GTK_COMBO_BOX(combo), 
    505610                                          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); 
    511620        gtk_container_add(GTK_CONTAINER(grab.window), vbox); 
    512621 
     
    518627        { 
    519628        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); 
    521635                break; 
    522636        case SHOT_RESPONSE_CANCEL: 
     
    525639        } 
    526640        g_object_unref(grab.buf); 
     641        g_object_unref(gc); 
     642        g_free(last_handler); 
    527643        osso_deinitialize(osso); 
    528644