Few corrections for configuration dialog in weather widget. wp-up
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 2 Aug 2014 17:14:57 +0000 (20:14 +0300)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 2 Aug 2014 17:48:36 +0000 (20:48 +0300)
src/plugins/weather/weather.c
src/plugins/weather/weatherwidget.c
src/plugins/weather/weatherwidget.h

index 1b31981..08fef1d 100644 (file)
 #include "yahooutil.h"
 #include "logutil.h"
 
-#include "../../private.h"
+#include "../../plugin.h"
 
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 #include <stdlib.h>
 
-/* External button-press handler from plugin.c */
-extern gboolean lxpanel_plugin_button_press_event(GtkWidget *widget, GdkEventButton *event, Panel *panel);
-
 /* Need to maintain count for bookkeeping */
 static gint g_iCount = 0;
 
@@ -105,12 +102,6 @@ weather_constructor(Panel *pPanel, config_setting_t *pConfig)
 
   GtkWidget * pEventBox = gtk_event_box_new();
 
-  /* Connect signals. */
-  g_signal_connect(pEventBox, 
-                   "button-press-event", 
-                   G_CALLBACK(lxpanel_plugin_button_press_event),
-                   pPanel);
-
   lxpanel_plugin_set_data(pEventBox, pPriv, weather_destructor);
   gtk_container_add(GTK_CONTAINER(pEventBox), pWidg);
 
@@ -121,6 +112,7 @@ weather_constructor(Panel *pPanel, config_setting_t *pConfig)
   /* use config settings */
   LocationInfo * pLocation = g_new0(LocationInfo, 1);
   const char *pczDummy = NULL;
+  int iDummyVal = 0;
 
   if (config_setting_lookup_string(pConfig, "alias", &pczDummy))
     {
@@ -162,6 +154,10 @@ weather_constructor(Panel *pPanel, config_setting_t *pConfig)
     {
       pLocation->pcWOEID_ = g_strndup(pczDummy, (pczDummy) ? strlen(pczDummy) : 0);
     }
+  else if (config_setting_lookup_int(pConfig, "woeid", &iDummyVal))
+    {
+      pLocation->pcWOEID_ = g_strdup_printf("%d", iDummyVal);
+    }
   else
     {
       LXW_LOG(LXW_ERROR, "Weather: could not lookup woeid in config.");
@@ -176,7 +172,6 @@ weather_constructor(Panel *pPanel, config_setting_t *pConfig)
       LXW_LOG(LXW_ERROR, "Weather: could not lookup units in config.");
     }
 
-  int iDummyVal = 0;
   if (config_setting_lookup_int(pConfig, "interval", &iDummyVal))
     {
       pLocation->uiInterval_ = (guint)iDummyVal;
@@ -221,23 +216,22 @@ weather_constructor(Panel *pPanel, config_setting_t *pConfig)
  *
  * @param pWidget Pointer to this widget.
  */
-static void
-weather_save_configuration(GtkWidget *pWidget)
+void weather_save_configuration(GtkWidget * pWeather, LocationInfo * pLocation)
 {
-  WeatherPluginPrivate * pPriv = (WeatherPluginPrivate *) lxpanel_plugin_get_data(pWidget);
-
-  LXW_LOG(LXW_DEBUG, "weather_save_configuration(%d)", pPriv->iMyId_);
-
-  GValue location = G_VALUE_INIT;
-
-  g_value_init(&location, G_TYPE_POINTER);
+  GtkWidget * pWidget = gtk_widget_get_parent(pWeather);
+  WeatherPluginPrivate * pPriv = NULL;
 
-  /* pwid is the WeatherWidget */
-  g_object_get_property(G_OBJECT(pPriv->pWeather_),
-                        "location",
-                        &location);
+  if (pWidget)
+    {
+      pPriv = (WeatherPluginPrivate *) lxpanel_plugin_get_data(pWidget);
+    }
+  if (pPriv == NULL)
+    {
+      LXW_LOG(LXW_ERROR, "Weather: weather_save_configuration() for invalid widget");
+      return;
+    }
 
-  LocationInfo * pLocation = g_value_get_pointer(&location);
+  LXW_LOG(LXW_DEBUG, "weather_save_configuration(%d)", pPriv->iMyId_);
 
   if (pLocation)
     {
@@ -280,8 +274,6 @@ weather_configuration_changed(Panel *pPanel, GtkWidget *pWidget)
               pPanel->width, panel_get_height(pPanel), 
               panel_get_icon_size(pPanel));
     }
-
-  weather_save_configuration(pWidget);
 }
 
 /**
index 88670c9..5564b07 100644 (file)
@@ -33,6 +33,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
+#include "../../plugin.h"
 
 /* Private structure, property and signal definitions. */
 #define GTK_WEATHER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
@@ -1149,6 +1150,8 @@ gtk_weather_preferences_dialog_response(GtkDialog *dialog, gint response, gpoint
           gtk_weather_get_forecast(GTK_WIDGET(weather));
 
           gtk_weather_render(weather);
+
+          weather_save_configuration(GTK_WIDGET(weather), location);
         }
 
       break;
@@ -1164,11 +1167,6 @@ gtk_weather_preferences_dialog_response(GtkDialog *dialog, gint response, gpoint
       break;
     }
 
-  if (GTK_IS_WIDGET(priv->preferences_data.dialog))
-    {
-      gtk_widget_destroy(priv->preferences_data.dialog);
-    }
-
   priv->preferences_data.dialog = NULL;
   
   priv->preferences_data.shown = FALSE;
@@ -1230,11 +1228,6 @@ gtk_weather_create_preferences_dialog(GtkWidget * widget)
 
   GtkWeatherPrivate * priv = GTK_WEATHER_GET_PRIVATE(weather);
 
-  if (priv->preferences_data.shown)
-    {
-      return priv->preferences_data.dialog;
-    }
-
   priv->preferences_data.dialog = gtk_dialog_new_with_buttons(_("Weather Preferences"),
                                                               NULL,
                                                               GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -1415,6 +1408,8 @@ gtk_weather_create_preferences_dialog(GtkWidget * widget)
 
   gtk_weather_update_preferences_dialog(weather);
 
+  gtk_widget_show_all(priv->preferences_data.dialog);
+
   return priv->preferences_data.dialog;
 }
 
@@ -1441,7 +1436,7 @@ gtk_weather_run_preferences_dialog(GtkWidget * widget)
   /* this dialog is the same one as priv->preferences_data.dialog */
   GtkWidget * dialog = gtk_weather_create_preferences_dialog(widget);
 
-  gtk_widget_show_all(dialog);
+  g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(gtk_widget_destroy), NULL);
 
   priv->preferences_data.shown = TRUE;
 }
index 3c94787..95f3530 100644 (file)
@@ -62,6 +62,8 @@ void        gtk_weather_run_conditions_dialog(GtkWidget * widget);
 gchar *     gtk_weather_get_tooltip_text(GtkWidget * widget);
 GtkWidget * gtk_weather_create_preferences_dialog(GtkWidget * widget);
 
+void weather_save_configuration(GtkWidget * pWeather, LocationInfo * pLocation);
+
 G_END_DECLS
 
 #endif