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 <span foreground=\"red\">%s</span>...",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);
/* 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,
*/
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),"<span foreground=\"red\"><b>Failed</b></span>: Check ticker and try again.");
+ gtk_widget_queue_draw(GTK_WIDGET(psContext->psParent));
}
}
}
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;
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);
/* 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;