Commit 9eaf3edf authored by Nick Schermer's avatar Nick Schermer

Code layout improved, applied patch from Peggy Kutyla

(Old svn revision: 2243)
parent 0d8a0991
2006-12-17 16:11 nick
* Cleaned up the code
* Applied patch from Peggy Kutyla (Bug 2656)
2006-09-06 11:00 nick
* Addded $Id$'s using svn:keyword
......
XML information:
http://www.weather.com/documentation/xml/weather.dtd
\ No newline at end of file
* Use the Xfce hvbox
* Fix plugin when resuming from suspend
\ No newline at end of file
icons/liquid/25.png

6.57 KB | W: | H:

icons/liquid/25.png

6.56 KB | W: | H:

icons/liquid/25.png
icons/liquid/25.png
icons/liquid/25.png
icons/liquid/25.png
  • 2-up
  • Swipe
  • Onion skin
icons/liquid/36.png

6.57 KB | W: | H:

icons/liquid/36.png

6.29 KB | W: | H:

icons/liquid/36.png
icons/liquid/36.png
icons/liquid/36.png
icons/liquid/36.png
  • 2-up
  • Swipe
  • Onion skin
liquiddir = $(datadir)/xfce4/weather/icons/liquid
liquid_DATA = 1.png \
liquid_DATA = 0.png \
1.png \
2.png \
3.png \
4.png \
......@@ -46,7 +47,8 @@ liquid_DATA = 1.png \
44.png \
45.png \
46.png \
47.png
47.png \
99.png
EXTRA_DIST = \
$(liquid_DATA)
......@@ -243,6 +243,8 @@ apply_options (xfceweather_dialog *dialog)
cb (data);
}
static int
option_i (datas opt)
{
......@@ -257,6 +259,8 @@ option_i (datas opt)
return -1;
}
static gboolean
cb_findlocation (GtkButton *button,
gpointer user_data)
......@@ -277,6 +281,7 @@ cb_findlocation (GtkButton *button,
}
xfceweather_dialog *
create_config_dialog (xfceweather_data *data,
GtkWidget *vbox)
......@@ -335,7 +340,8 @@ create_config_dialog (xfceweather_data *data,
button = gtk_button_new ();
image = gtk_image_new_from_stock (GTK_STOCK_FIND, GTK_ICON_SIZE_BUTTON);
gtk_container_add (GTK_CONTAINER (button), image);
g_signal_connect (button, "clicked", G_CALLBACK (cb_findlocation), dialog);
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (cb_findlocation), dialog);
hbox = gtk_hbox_new (FALSE, BORDER);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
......@@ -375,19 +381,16 @@ create_config_dialog (xfceweather_data *data,
gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
g_signal_connect (dialog->chk_proxy_use, "toggled", G_CALLBACK (cb_toggle),
(gpointer) dialog->txt_proxy_host);
g_signal_connect (dialog->chk_proxy_use, "toggled", G_CALLBACK (cb_toggle),
(gpointer) dialog->txt_proxy_port);
g_signal_connect (dialog->chk_proxy_use, "toggled", G_CALLBACK (cb_toggle),
(gpointer) dialog->chk_proxy_fromenv);
g_signal_connect (dialog->chk_proxy_fromenv, "toggled",
G_CALLBACK (cb_not_toggle),
(gpointer) dialog->txt_proxy_host);
g_signal_connect (dialog->chk_proxy_fromenv, "toggled",
G_CALLBACK (cb_not_toggle),
(gpointer) dialog->txt_proxy_port);
g_signal_connect (G_OBJECT (dialog->chk_proxy_use), "toggled",
G_CALLBACK (cb_toggle), dialog->txt_proxy_host);
g_signal_connect (G_OBJECT (dialog->chk_proxy_use), "toggled",
G_CALLBACK (cb_toggle), dialog->txt_proxy_port);
g_signal_connect (G_OBJECT (dialog->chk_proxy_use), "toggled",
G_CALLBACK (cb_toggle), dialog->chk_proxy_fromenv);
g_signal_connect (G_OBJECT (dialog->chk_proxy_fromenv), "toggled",
G_CALLBACK (cb_not_toggle), dialog->txt_proxy_host);
g_signal_connect (G_OBJECT (dialog->chk_proxy_fromenv), "toggled",
G_CALLBACK (cb_not_toggle), dialog->txt_proxy_port);
if (dialog->wd->saved_proxy_host != NULL)
{
......@@ -417,7 +420,6 @@ create_config_dialog (xfceweather_data *data,
/* labels */
dialog->opt_xmloption = make_label ();
dialog->mdl_xmloption = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
dialog->lst_xmloption =
......@@ -466,14 +468,18 @@ create_config_dialog (xfceweather_data *data,
g_object_unref (G_OBJECT (sg));
g_object_unref (G_OBJECT (sg_buttons));
g_signal_connect (button_add, "clicked", G_CALLBACK (cb_addoption), dialog);
g_signal_connect (button_del, "clicked", G_CALLBACK (cb_deloption), dialog);
g_signal_connect (G_OBJECT (button_add), "clicked",
G_CALLBACK (cb_addoption), dialog);
g_signal_connect (G_OBJECT (button_del), "clicked",
G_CALLBACK (cb_deloption), dialog);
gtk_widget_show_all (vbox);
return dialog;
}
void
set_callback_config_dialog (xfceweather_dialog *dialog,
cb_function cb_new)
......
......@@ -15,32 +15,34 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef CONFIG_DIALOG_H
#define CONFIG_DIALOG_H
#ifndef __WEATHER_CONFIG_H__
#define __WEATHER_CONFIG_H__
G_BEGIN_DECLS typedef struct
G_BEGIN_DECLS
typedef struct
{
gchar *name;
datas number;
datas number;
}
labeloption;
typedef struct
{
GtkWidget *dialog;
GtkWidget *opt_unit;
GtkWidget *txt_loc_code;
GtkWidget *txt_proxy_host;
GtkWidget *txt_proxy_port;
GtkWidget *chk_proxy_use;
GtkWidget *chk_proxy_fromenv;
GtkWidget *dialog;
GtkWidget *opt_unit;
GtkWidget *txt_loc_code;
GtkWidget *txt_proxy_host;
GtkWidget *txt_proxy_port;
GtkWidget *chk_proxy_use;
GtkWidget *chk_proxy_fromenv;
GtkWidget *tooltip_yes;
GtkWidget *tooltip_no;
GtkWidget *tooltip_yes;
GtkWidget *tooltip_no;
GtkWidget *opt_xmloption;
GtkWidget *lst_xmloption;
GtkListStore *mdl_xmloption;
GtkWidget *opt_xmloption;
GtkWidget *lst_xmloption;
GtkListStore *mdl_xmloption;
xfceweather_data *wd;
}
......@@ -56,4 +58,5 @@ set_callback_config_dialog (xfceweather_dialog * dialog,
void apply_options (xfceweather_dialog * dialog);
G_END_DECLS
#endif
......@@ -32,14 +32,18 @@
#define EMPTY_STRING g_strdup("-")
#define CHK_NULL(str) str ? g_strdup(str) : EMPTY_STRING;
gchar *kill_ring[KILL_RING_S] = { NULL, };
#define debug_print printf
static gchar *
copy_buffer (gchar *str)
{
static gint p = 0;
gchar *s;
static gint p = 0;
gchar *s;
if (!str)
{
......@@ -60,6 +64,8 @@ copy_buffer (gchar *str)
return s;
}
void
free_get_data_buffer (void)
{
......@@ -72,6 +78,8 @@ free_get_data_buffer (void)
}
}
static gchar *
get_data_uv (xml_uv *data,
datas_uv type)
......@@ -98,6 +106,7 @@ get_data_uv (xml_uv *data,
}
static gchar *
get_data_bar (xml_bar *data,
datas_bar type)
......@@ -123,6 +132,8 @@ get_data_bar (xml_bar *data,
return CHK_NULL (str);
}
static gchar *
get_data_wind (xml_wind *data,
datas_wind type)
......@@ -160,6 +171,8 @@ get_data_wind (xml_wind *data,
return CHK_NULL (str);
}
/* -- This is not the same as the previous functions */
static gchar *
get_data_cc (xml_cc *data,
......@@ -223,6 +236,8 @@ get_data_cc (xml_cc *data,
return CHK_NULL (str);
}
static gchar *
get_data_loc (xml_loc *data,
datas_loc type)
......@@ -252,6 +267,7 @@ get_data_loc (xml_loc *data,
}
const gchar *
get_data (xml_weather *data,
datas type)
......@@ -283,6 +299,8 @@ get_data (xml_weather *data,
return p;
}
static gchar *
get_data_part (xml_part *data,
forecast type)
......@@ -316,6 +334,8 @@ get_data_part (xml_part *data,
return str;
}
const gchar *
get_data_f (xml_dayf *data,
forecast type)
......@@ -362,6 +382,8 @@ get_data_f (xml_dayf *data,
return p;
}
const gchar *
get_unit (units unit,
datas type)
......
......@@ -15,10 +15,12 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef GET_DATA_H
#define GET_DATA_H
#ifndef __WEATHER_DATA_H__
#define __WEATHER_DATA_H__
G_BEGIN_DECLS typedef enum
G_BEGIN_DECLS
typedef enum
{
_WIND_SPEED,
_WIND_GUST,
......@@ -44,29 +46,23 @@ datas_uv;
typedef enum
{
/* cc */
LSUP = 0x0101,
OBST = 0x0102,
TRANS = 0x0103,
UV_INDEX = 0x0105,
UV_TRANS = 0x0106,
LSUP = 0x0101,
OBST = 0x0102,
TRANS = 0x0103,
UV_INDEX = 0x0105,
UV_TRANS = 0x0106,
WIND_DIRECTION = 0x0107,
BAR_D = 0x0108,
WIND_TRANS = 0x0109,
WICON = 0x0110,
FLIK = 0x0120,
TEMP = 0x0121,
DEWP = 0x0122,
HMID = 0x0130,
WIND_SPEED = 0x0140,
WIND_GUST = 0x0141,
BAR_R = 0x0150,
VIS = 0x0160
BAR_D = 0x0108,
WIND_TRANS = 0x0109,
WICON = 0x0110,
FLIK = 0x0120,
TEMP = 0x0121,
DEWP = 0x0122,
HMID = 0x0130,
WIND_SPEED = 0x0140,
WIND_GUST = 0x0141,
BAR_R = 0x0150,
VIS = 0x0160
}
datas;
......@@ -80,30 +76,27 @@ datas_loc;
typedef enum
{
ITEMS = 0x0100,
WDAY = 0x0101,
TEMP_MIN = 0x0102,
TEMP_MAX = 0x0103,
F_ICON = 0x0001,
F_PPCP = 0x0002,
ITEMS = 0x0100,
WDAY = 0x0101,
TEMP_MIN = 0x0102,
TEMP_MAX = 0x0103,
F_ICON = 0x0001,
F_PPCP = 0x0002,
F_W_DIRECTION = 0x0003,
F_W_SPEED = 0x0004,
F_TRANS = 0x0005,
NPART = 0x0200,
ICON_N = 0x0201,
PPCP_N = 0x0202,
F_W_SPEED = 0x0004,
F_TRANS = 0x0005,
NPART = 0x0200,
ICON_N = 0x0201,
PPCP_N = 0x0202,
W_DIRECTION_N = 0x0203,
W_SPEED_N = 0x0204,
TRANS_N = 0x0205,
DPART = 0x0300,
ICON_D = 0x0301,
PPCP_D = 0x0302,
W_SPEED_N = 0x0204,
TRANS_N = 0x0205,
DPART = 0x0300,
ICON_D = 0x0301,
PPCP_D = 0x0302,
W_DIRECTION_D = 0x0303,
W_SPEED_D = 0x0304,
TRANS_D = 0x0305
W_SPEED_D = 0x0304,
TRANS_D = 0x0305
}
forecast;
......@@ -123,4 +116,5 @@ const gchar *get_unit (units unit, datas type);
void free_get_data_buffer (void);
G_END_DECLS
#endif
......@@ -37,32 +37,36 @@
struct request_data
{
int fd;
gint fd;
FILE *save_fp;
gchar *save_filename;
gchar **save_buffer;
FILE *save_fp;
gchar *save_filename;
gchar **save_buffer;
gboolean has_header;
gchar last_chars[4];
gboolean has_header;
gchar last_chars[4];
gchar *request_buffer;
gint offset;
gint size;
gchar *request_buffer;
gint offset;
gint size;
CB_TYPE cb_function;
gpointer cb_data;
CB_TYPE cb_function;
gpointer cb_data;
};
static gboolean keep_receiving (gpointer data);
static int
http_connect (gchar * hostname, gint port)
static gint
http_connect (gchar *hostname,
gint port)
{
struct sockaddr_in dest_host;
struct hostent *host_address;
gint fd;
struct sockaddr_in dest_host;
struct hostent *host_address;
gint fd;
if ((host_address = gethostbyname (hostname)) == NULL)
return -1;
......@@ -87,14 +91,13 @@ http_connect (gchar * hostname, gint port)
}
static void
request_free (struct request_data *request)
{
if (request->request_buffer)
g_free (request->request_buffer);
if (request->save_filename)
g_free (request->save_filename);
g_free (request->request_buffer);
g_free (request->save_filename);
if (request->save_fp)
fclose (request->save_fp);
......@@ -105,9 +108,14 @@ request_free (struct request_data *request)
panel_slice_free (struct request_data, request);
}
static void
request_save (struct request_data *request, const gchar * buffer)
request_save (struct request_data *request,
const gchar *buffer)
{
gchar *newbuff;
DBG ("Request Save");
if (request->save_filename)
......@@ -123,7 +131,7 @@ request_save (struct request_data *request, const gchar * buffer)
{
if (*request->save_buffer)
{
gchar *newbuff = g_strconcat (*request->save_buffer, buffer, NULL);
newbuff = g_strconcat (*request->save_buffer, buffer, NULL);
g_free (*request->save_buffer);
*request->save_buffer = newbuff;
}
......@@ -132,11 +140,13 @@ request_save (struct request_data *request, const gchar * buffer)
}
}
static gboolean
keep_sending (gpointer data)
{
struct request_data *request = (struct request_data *) data;
gint n;
gint n;
if (!request)
{
......@@ -161,9 +171,6 @@ keep_sending (gpointer data)
}
else if (errno != EAGAIN) /* some other error happened */
{
#if DEBUG
perror ("keep_sending()");
#endif
DBG ("file desc: %d", request->fd);
......@@ -174,14 +181,15 @@ keep_sending (gpointer data)
return TRUE;
}
static gboolean
keep_receiving (gpointer data)
{
struct request_data *request = (struct request_data *) data;
gchar recvbuffer[1024];
gint n;
gchar *p;
gchar *str = NULL;
gchar recvbuffer[1024];
gint n;
gchar *p, *str = NULL;
if (!request)
{
......@@ -222,11 +230,11 @@ keep_receiving (gpointer data)
else if (n == 0)
{
CB_TYPE callback = request->cb_function;
gpointer data = request->cb_data;
DBG ("keep_receiving(): ending with succes");
request_free (request);
callback (TRUE, data);
callback (TRUE, request->cb_data);
return FALSE;
}
else if (errno != EAGAIN)
......@@ -243,20 +251,21 @@ keep_receiving (gpointer data)
static gboolean
http_get (gchar * url,
gchar * hostname,
gboolean savefile,
gchar ** fname_buff,
gchar * proxy_host,
gint proxy_port, CB_TYPE callback, gpointer data)
http_get (gchar *url,
gchar *hostname,
gboolean savefile,
gchar **fname_buff,
gchar *proxy_host,
gint proxy_port,
CB_TYPE callback,
gpointer data)
{
struct request_data *request = panel_slice_new0 (struct request_data);
if (!request)
{
#if DEBUG
perror ("http_get(): empty request");
#endif
DBG ("http_get(): empty request");
return FALSE;
}
......@@ -292,9 +301,9 @@ http_get (gchar * url,
if (request->request_buffer == NULL)
{
#if DEBUG
perror ("http_get(): empty request buffer\n");
#endif
DBG ("http_get(): empty request buffer");
close (request->fd);
panel_slice_free (struct request_data, request);
return FALSE;
......@@ -316,23 +325,31 @@ http_get (gchar * url,
return TRUE;
}
gboolean
http_get_file (gchar * url,
gchar * hostname,
gchar * filename,
gchar * proxy_host,
gint proxy_port, CB_TYPE callback, gpointer data)
http_get_file (gchar *url,
gchar *hostname,
gchar *filename,
gchar *proxy_host,
gint proxy_port,
CB_TYPE callback,
gpointer data)
{
return http_get (url, hostname, TRUE, &filename, proxy_host, proxy_port,
callback, data);
}
gboolean
http_get_buffer (gchar * url,
gchar * hostname,
gchar * proxy_host,
gint proxy_port,
gchar ** buffer, CB_TYPE callback, gpointer data)
http_get_buffer (gchar *url,
gchar *hostname,
gchar *proxy_host,
gint proxy_port,
gchar **buffer,
CB_TYPE callback,
gpointer data)
{
return http_get (url, hostname, FALSE, buffer, proxy_host, proxy_port,