X-Git-Url: http://git.maemo.org/git/?p=stockwidget;a=blobdiff_plain;f=lib-stock-home-widget.c;h=13891cfd7586af234207d2f1b0cfa96660391c52;hp=3ee9f827406a77c490ae19d2a55760e732c34681;hb=0a7576b8a8d2fc462bf80f2e3baaee0b08c9fea5;hpb=eb7481a73b8073a06368daa0f878f7d890cb4a7e
diff --git a/lib-stock-home-widget.c b/lib-stock-home-widget.c
index 3ee9f82..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;
@@ -407,6 +460,8 @@ cairo_rounded_rectangle(cairo_t *cr,
double height,
double corner_div)
{
+ cairo_pattern_t *pat;
+
double aspect = 1.0;
double corner_radius = height / corner_div;
double radius = corner_radius / aspect;
@@ -419,10 +474,15 @@ cairo_rounded_rectangle(cairo_t *cr,
cairo_arc (cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
cairo_close_path (cr);
- cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.25);
+ pat = cairo_pattern_create_linear(0.0, 0.0, 0.0, height);
+
+ cairo_pattern_add_color_stop_rgba(pat,0.0, 0.8, 0.8, 0.8, 0.7);
+ cairo_pattern_add_color_stop_rgba(pat,1.0, 0.0, 0.0, 0.0, 0.7);
+
+ cairo_set_source(cr,pat);
cairo_fill_preserve (cr);
- cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
- cairo_set_line_width (cr, 1.0);
+
+ cairo_set_line_width (cr, 0.0);
cairo_stroke (cr);
}
@@ -430,28 +490,12 @@ static gboolean
stock_plugin_expose(GtkWidget* widget, GdkEventExpose *event)
{
cairo_t* cr;
- int width = 0;
- int height = 0;
- GdkRectangle *psRect;
cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
-
- psRect = &event->area;
-
- width = psRect->width;
- height = psRect->height;
-
- DebugOut(("X: %d Y: %d Width: %d Height %d",psRect->x,psRect->y,psRect->width,psRect->height));
-
- cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.5);
- #if 1
- cairo_rounded_rectangle(cr, 0, 0, width, height, 10.0);
- #else
- cairo_rectangle(cr, 0, 0, width, height);
- #endif
- cairo_fill(cr);
+ cairo_rounded_rectangle(cr, 0, 0, event->area.width, event->area.height, 10.0);
cairo_destroy(cr);
+
return GTK_WIDGET_CLASS(stock_plugin_parent_class)->expose_event(widget, event);
}