X-Git-Url: http://git.maemo.org/git/?p=stockwidget;a=blobdiff_plain;f=lib-stock-home-widget.c;h=13891cfd7586af234207d2f1b0cfa96660391c52;hp=14a2b81f9682bee4e8f83b663156eba2deb2566f;hb=0a7576b8a8d2fc462bf80f2e3baaee0b08c9fea5;hpb=1cc1919c45f938fb16928d7e1e1fb9acf6c3567c diff --git a/lib-stock-home-widget.c b/lib-stock-home-widget.c index 14a2b81..13891cf 100644 --- a/lib-stock-home-widget.c +++ b/lib-stock-home-widget.c @@ -13,22 +13,40 @@ HD_DEFINE_PLUGIN_MODULE (StockPlugin, stock_plugin, HD_TYPE_HOME_PLUGIN_ITEM) static void +OnClickUpdate(GtkWidget *widget, GdkEventButton *event, StockPluginContext *psContext) +{ + char szBuffer[1024]; + + DebugOut(("OnClickUpdate")); + + sprintf(szBuffer,"Retrieving %s...",psContext->psSettings->ppszTickers[0]); + + /* Hide the stock arrow when we're updating */ + psContext->bArrowActive = FALSE; + gtk_widget_hide(GTK_WIDGET(psContext->psArrow)); + + gtk_label_set_markup(GTK_LABEL(psContext->psLabel),szBuffer); + gtk_widget_queue_draw(GTK_WIDGET(psContext->psParent)); +} + +static void OnClickRefresh(GtkWidget *widget, GdkEventButton *event, StockPluginContext *psContext) { DebugOut(("OnClickRefresh")); /* Disable button while getting latest stocks */ { + char szBuffer[1024]; float fPrice; float fChange; - char szBuffer[1024]; if(RetrieveStockPrice(psContext->hSG,psContext->psSettings->ppszTickers[0],&fPrice,NULL,&fChange) == SG_OK) { - char szTime[80]; char *pszColour = NULL; time_t rawtime; struct tm *timeinfo; + char szTime[80]; + int nImageSel; time(&rawtime); timeinfo = localtime(&rawtime); @@ -36,9 +54,23 @@ OnClickRefresh(GtkWidget *widget, GdkEventButton *event, StockPluginContext *psC /* Highlight the change in price */ if(fChange > 0.0f) + { + nImageSel = STOCK_IMAGE_INCREASE; pszColour = "green"; + } else + { + nImageSel = STOCK_IMAGE_DECREASE; pszColour = "red"; + } + + gtk_image_set_from_pixbuf(GTK_IMAGE(psContext->psArrow),psContext->asStockImage[nImageSel]); + + if(!psContext->bArrowActive) + { + gtk_widget_show(psContext->psArrow); + psContext->bArrowActive = TRUE; + } /* Update to latest price */ sprintf(szBuffer, @@ -54,7 +86,8 @@ OnClickRefresh(GtkWidget *widget, GdkEventButton *event, StockPluginContext *psC */ else { - hildon_banner_show_information(GTK_WIDGET(widget),NULL,"Failed to retrieve stock information, check ticker symbol and try again."); + gtk_label_set_markup(GTK_LABEL(psContext->psLabel),"Failed: Check ticker and try again."); + gtk_widget_queue_draw(GTK_WIDGET(psContext->psParent)); } } } @@ -277,25 +310,39 @@ stock_show_settings_dialog(GtkWidget* widget, gpointer data) static GtkWidget *stock_create_gui(gchar *pszStockLabel, StockPluginContext *psContext) { + GtkWidget *hbox; + GtkWidget *arrow; GtkWidget *label; GtkWidget *eventbox; DebugOut(("stock_create_gui")); + + psContext->asStockImage[STOCK_IMAGE_INCREASE] = gdk_pixbuf_new_from_file(STOCK_PLUGIN_RESOURCE_UP_ARROW, NULL); + psContext->asStockImage[STOCK_IMAGE_DECREASE] = gdk_pixbuf_new_from_file(STOCK_PLUGIN_RESOURCE_DOWN_ARROW, NULL); label = gtk_label_new(pszStockLabel); eventbox = gtk_event_box_new(); + arrow = gtk_image_new_from_pixbuf(psContext->asStockImage[0]); + hbox = gtk_hbox_new(FALSE,5); gtk_event_box_set_visible_window(GTK_EVENT_BOX(eventbox),FALSE); gtk_container_set_border_width(GTK_CONTAINER(eventbox),10); - gtk_container_add(GTK_CONTAINER(eventbox),label); + gtk_box_pack_start(GTK_BOX(hbox), arrow, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + + gtk_container_add(GTK_CONTAINER(eventbox),hbox); - g_signal_connect(GTK_CONTAINER(eventbox),"button-press-event",G_CALLBACK(OnClickRefresh),(gpointer)psContext); + g_signal_connect(GTK_CONTAINER(eventbox),"button-press-event",G_CALLBACK(OnClickUpdate),(gpointer)psContext); + g_signal_connect(GTK_CONTAINER(eventbox),"button-release-event",G_CALLBACK(OnClickRefresh),(gpointer)psContext); - /* Display */ - gtk_widget_show_all(GTK_WIDGET(eventbox)); + /* Display all but the arrow */ + gtk_widget_show_all(eventbox); + gtk_widget_hide(arrow); + psContext->bArrowActive = FALSE; - psContext->psLabel = label; + psContext->psArrow = arrow; + psContext->psLabel = label; psContext->psEventBox = eventbox; return eventbox; @@ -325,6 +372,12 @@ stock_plugin_finalize (GObject *object) psContext->nTimerID = -1; } + if(psContext->asStockImage[STOCK_IMAGE_DECREASE] != NULL) + g_object_unref(psContext->asStockImage[STOCK_IMAGE_DECREASE]); + + if(psContext->asStockImage[STOCK_IMAGE_INCREASE] != NULL) + g_object_unref(psContext->asStockImage[STOCK_IMAGE_INCREASE]); + if(psContext->hSG) FreeStockGetter(psContext->hSG); @@ -359,7 +412,7 @@ stock_plugin_init (StockPlugin *desktop_plugin) /* Create GUI widget interface (and sets links in context) */ stock_create_gui("Click to Update",psContext); - + gtk_container_add(GTK_CONTAINER(desktop_plugin), psContext->psEventBox); psContext->hSG = hSG;