#include <shellapi.h>
#endif
+#include <libzakutils/libzakutils.h>
+
#include "solipa.h"
#include "utils.h"
static void solipa_on_btn_unselect_all_clicked (GtkButton *button,
gpointer user_data);
+G_DEPRECATED_FOR (zak_utils_file_exists)
gboolean
solipa_file_exists (const gchar *filename)
{
- return (g_file_query_exists (g_file_new_for_path (filename), NULL));
+ return zak_utils_file_exists (filename);
}
static gboolean
continue;
}
- if (solipa_file_exists (filename))
+ if (zak_utils_file_exists (filename))
{
GtkWidget *diag_req;
return ret;
}
+G_DEPRECATED_FOR (zak_utils_format_money)
gchar
*solipa_format_money (gdouble number,
gint decimals,
gboolean with_currency_symbol)
{
- gchar *ret;
-
- GRegex *regex;
- GError *error;
-
- gchar *str_format;
- gchar *str;
- gssize str_len;
-
- /* TODO
- * - get number of decimals from locale
- * - get grouping char from locale
- * - get currency symbol from locale
- */
-
- ret = g_strdup ("");
-
- error = NULL;
- regex = g_regex_new ("(^[-\\d]?\\d+)(\\d\\d\\d)", 0, 0, &error);
- if (regex == NULL || error != NULL)
- {
- g_warning ("Error on creating regex: %s.",
- error->message != NULL ? error->message : "no details");
- return "";
- }
-
- str_format = g_strdup_printf ("%%0%sf", decimals == 0 ? ".0" : (decimals < 0 ? ".2" : g_strdup_printf (".%d", decimals)));
- ret = g_strdup_printf (str_format, number);
-
- while (TRUE)
- {
- error = NULL;
- str_len = g_utf8_strlen (ret, -1);
- str = g_regex_replace ((const GRegex *)regex,
- ret, str_len, 0,
- "\\1.\\2", 0,
- &error);
- if (error != NULL)
- {
- g_warning ("Error on regex replacing: %s.",
- error->message != NULL ? error->message : "no details");
- g_regex_unref (regex);
- return "";
- }
- if (g_strcmp0 (ret, str) != 0)
- {
- ret = g_strdup (str);
- g_free (str);
- }
- else
- {
- break;
- }
- }
-
- if (with_currency_symbol)
- {
- ret = g_strconcat ("€ ", ret, NULL);
- }
-
- g_regex_unref (regex);
-
- return ret;
+ return zak_utils_format_money (number, decimals, with_currency_symbol);
}
+G_DEPRECATED_FOR (zak_utils_unformat_money)
gdouble
solipa_unformat_money (const gchar *value)
{
- gdouble ret;
-
- GRegex *regex;
- GError *error;
-
- gchar *str;
-
- ret = 0.0;
-
- error = NULL;
- regex = g_regex_new ("[€ .]", 0, 0, &error);
- if (error != NULL)
- {
- g_warning ("Error on creating regex: %s.",
- error->message != NULL ? error->message : "no details");
- return ret;
- }
-
- error = NULL;
- str = g_regex_replace ((const GRegex *)regex,
- value, -1, 0,
- "", 0,
- &error);
- if (error != NULL)
- {
- g_warning ("Error on regex replacing: %s.",
- error->message != NULL ? error->message : "no details");
- g_regex_unref (regex);
- return ret;
- }
-
- ret = g_strtod (str, NULL);
-
- g_regex_unref (regex);
-
- return ret;
+ return zak_utils_unformat_money (value);
}
+G_DEPRECATED_FOR (zak_utils_get_now_tm)
struct tm
*solipa_get_now_tm (void)
{
- time_t tt;
-
- tt = time (NULL);
-
- return localtime (&tt);
+ return zak_utils_get_now_tm ();
}
+G_DEPRECATED_FOR (zak_utils_get_today_gdate)
GDate
*solipa_get_today_gdate (void)
{
- struct tm *tt_tm = solipa_get_now_tm ();
-
- return g_date_new_dmy ((GDateDay)tt_tm->tm_mday,
- (GDateMonth)tt_tm->tm_mon + 1,
- (GDateYear)tt_tm->tm_year + 1900);
+ return zak_utils_get_today_gdate ();
}
+G_DEPRECATED_FOR (zak_utils_tm_to_gdatetime)
GDateTime
*solipa_tm_to_gdatetime (struct tm *tm_data)
{
- GDateTime *ret;
-
- ret = NULL;
- if (tm_data != NULL)
- {
- ret = g_date_time_new_local (tm_data->tm_year + 1900,
- tm_data->tm_mon + 1,
- tm_data->tm_mday,
- tm_data->tm_hour,
- tm_data->tm_min,
- tm_data->tm_sec);
- }
-
- return ret;
+ return zak_utils_tm_to_gdatetime (tm_data);
}
+G_DEPRECATED_FOR (zak_utils_gdatetime_to_tm)
struct tm
*solipa_gdatetime_to_tm (GDateTime *gdatetime)
{
- struct tm *ret;
-
- ret = g_new0 (struct tm, 1);
- ret->tm_year = g_date_time_get_year (gdatetime) - 1900;
- ret->tm_mon = g_date_time_get_month (gdatetime) - 1;
- ret->tm_mday = g_date_time_get_day_of_month (gdatetime);
- ret->tm_hour = g_date_time_get_hour (gdatetime);
- ret->tm_min = g_date_time_get_minute (gdatetime);
- ret->tm_sec = g_date_time_get_second (gdatetime);
- mktime (ret);
-
- return ret;
+ return zak_utils_gdatetime_to_tm (gdatetime);
}
+G_DEPRECATED_FOR (zak_utils_gdate_to_gdatetime)
GDateTime
*solipa_gdate_to_gdatetime (GDate *gdate)
{
- GDateTime *ret;
-
- ret = NULL;
- if (gdate != NULL && g_date_valid (gdate))
- {
- ret = g_date_time_new_local (g_date_get_year (gdate),
- g_date_get_month (gdate),
- g_date_get_day (gdate),
- 0, 0, 0.0);
- }
-
- return ret;
+ return zak_utils_gdate_to_gdatetime (gdate);
}
+G_DEPRECATED_FOR (zak_utils_gdatetime_to_gdate)
GDate
*solipa_gdatetime_to_gdate (GDateTime *gdatetime)
{
- GDate *ret;
-
- ret = NULL;
- if (gdatetime != NULL)
- {
- ret = g_new0 (GDate, 1);
- g_date_set_year (ret, g_date_time_get_year (gdatetime));
- g_date_set_month (ret, g_date_time_get_month (gdatetime));
- g_date_set_day (ret, g_date_time_get_day_of_month (gdatetime));
- }
-
- return ret;
+ return zak_utils_gdatetime_to_gdate (gdatetime);
}
+G_DEPRECATED_FOR (zak_utils_tm_to_sql)
const gchar
*solipa_tm_to_sql (struct tm *tm_data, const gchar *format)
{
- const gchar *ret;
-
- ret = g_strdup ("NULL");
-
- if (tm_data != NULL)
- {
- ret = solipa_gdatetime_to_sql (solipa_tm_to_gdatetime (tm_data), format);
- }
-
- return ret;
+ return zak_utils_tm_to_sql (tm_data, format);
}
+G_DEPRECATED_FOR (zak_utils_gdate_to_sql)
const gchar
*solipa_gdate_to_sql (GDate *gdate)
{
- const gchar *ret;
-
- ret = g_strdup ("NULL");
-
- if (gdate != NULL && g_date_valid (gdate))
- {
- ret = solipa_gdatetime_to_sql (solipa_gdate_to_gdatetime (gdate), "date");
- }
-
- return ret;
+ return zak_utils_gdate_to_sql (gdate, NULL);
}
+G_DEPRECATED_FOR (zak_utils_gdatetime_to_sql)
const gchar
*solipa_gdatetime_to_sql (GDateTime *gdatetime, const gchar *format)
{
- const gchar *ret;
- gchar *_format;
-
- ret = g_strdup ("NULL");
-
- if (gdatetime != NULL)
- {
- if (format == NULL)
- {
- _format = g_strdup ("%F %R:%S");
- }
- else
- {
- _format = g_strstrip (g_strdup (format));
- if (g_strcmp0 (_format, "") == 0
- || g_strcmp0 (_format, "datetime") == 0)
- {
- _format = g_strdup ("%F %R:%S");
- }
- else if (g_strcmp0 (_format, "date") == 0)
- {
- _format = g_strdup ("%F");
- }
- else if (g_strcmp0 (_format, "time") == 0)
- {
- _format = g_strdup ("%R:%S");
- }
- }
- ret = g_strdup_printf ("'%s'", g_date_time_format (gdatetime, _format));
- }
-
- return ret;
+ return zak_utils_gdatetime_to_sql (gdatetime, format);
}
+G_DEPRECATED_FOR (zak_utils_get_gdate_from_string)
GDate
*solipa_get_gdate_from_string (const gchar *string, const gchar *format)
{
- GDate *ret;
-
- GDateTime *gdatetime;
-
- gdatetime = solipa_get_gdatetime_from_string (string, format);
-
- ret = solipa_gdatetime_to_gdate (gdatetime);
-
- return ret;
+ return zak_utils_get_gdate_from_string (string, format);
}
+G_DEPRECATED_FOR (zak_utils_get_gdatetime_from_string)
GDateTime
*solipa_get_gdatetime_from_string (const gchar *string, const gchar *format)
{
- GDateTime *ret;
-
- gchar *new_str;
- gchar *new_format;
- gchar **str_tokens;
- gchar **format_tokens;
- gchar *delimiters;
- guint len_strv;
- guint len_formatv;
- guint i;
- guint i_to;
-
- gint year;
- gint month;
- gint day;
- gint hour;
- gint minute;
- gdouble seconds;
-
- gboolean error;
-
- g_return_val_if_fail (string != NULL, NULL);
-
- new_str = g_strstrip (g_strdup (string));
- if (g_strcmp0 (new_str, "") == 0)
- {
- g_free (new_str);
- return NULL;
- }
-
- if (format == NULL)
- {
- new_format = g_strdup ("%Y-%m-%d %H:%M:%S");
- }
- else
- {
- new_format = g_strstrip (g_strdup (format));
- if (g_strcmp0 (new_format, "") == 0)
- {
- new_format = g_strdup ("%Y-%m-%d %H:%M:%S");
- }
- }
-
- /* removes format identifiers to find delimiters */
- delimiters = solipa_string_replace (new_format, "%Y", "");
- delimiters = solipa_string_replace (delimiters, "%m", "");
- delimiters = solipa_string_replace (delimiters, "%d", "");
- delimiters = solipa_string_replace (delimiters, "%H", "");
- delimiters = solipa_string_replace (delimiters, "%M", "");
- delimiters = solipa_string_replace (delimiters, "%S", "");
-
- if (delimiters == NULL || g_strcmp0 (delimiters, "") == 0)
- {
- g_free (delimiters);
- g_free (new_format);
- g_free (new_str);
- return NULL;
- }
-
- str_tokens = g_strsplit_set (string, delimiters, -1);
- if (str_tokens == NULL)
- {
- g_free (delimiters);
- g_free (new_format);
- g_free (new_str);
- return NULL;
- }
-
- format_tokens = g_strsplit_set (format, delimiters, -1);
- if (format_tokens == NULL)
- {
- g_free (delimiters);
- g_free (new_format);
- g_free (new_str);
- return NULL;
- }
-
- len_strv = g_strv_length (str_tokens);
- len_formatv = g_strv_length (format_tokens);
-
- year = 1;
- month = 1;
- day = 1;
- hour = 0;
- minute = 0;
- seconds = 0.0;
-
- error = FALSE;
- ret = NULL;
-
- i_to = MIN (len_strv, len_formatv);
- for (i = 0; i < i_to; i++)
- {
- if (g_strcmp0 (format_tokens[i], "%Y") == 0)
- {
- year = strtol (str_tokens[i], NULL, 10);
- if (year < 1 || year > 9999)
- {
- error = TRUE;
- break;
- }
- }
- else if (g_strcmp0 (format_tokens[i], "%m") == 0)
- {
- month = strtol (str_tokens[i], NULL, 10);
- if (month < 1 || month > 12)
- {
- error = TRUE;
- break;
- }
- }
- else if (g_strcmp0 (format_tokens[i], "%d") == 0)
- {
- day = strtol (str_tokens[i], NULL, 10);
- if (day < 1 || day > 31)
- {
- error = TRUE;
- break;
- }
- }
- else if (g_strcmp0 (format_tokens[i], "%H") == 0)
- {
- hour = strtol (str_tokens[i], NULL, 10);
- if (hour > 23)
- {
- error = TRUE;
- break;
- }
- }
- else if (g_strcmp0 (format_tokens[i], "%M") == 0)
- {
- minute = strtol (str_tokens[i], NULL, 10);
- if (minute > 59)
- {
- error = TRUE;
- break;
- }
- }
- else if (g_strcmp0 (format_tokens[i], "%S") == 0)
- {
- seconds = g_strtod (str_tokens[i], NULL);
- if (seconds > 59.0)
- {
- error = TRUE;
- break;
- }
- }
- }
-
- g_strfreev (format_tokens);
- g_strfreev (str_tokens);
- g_free (delimiters);
- g_free (new_format);
- g_free (new_str);
-
- if (!error)
- {
- ret = g_date_time_new_local (year,
- month,
- day,
- hour,
- minute,
- seconds);
- }
-
- return ret;
+ return zak_utils_get_gdatetime_from_string (string, format);
}
+G_DEPRECATED_FOR (zak_utils_gdate_format)
gchar
*solipa_gdate_format (GDate *gdate, const gchar *format)
{
- gchar *ret;
-
- if (g_date_valid (gdate)) return "";
-
- ret = solipa_gdatetime_format (solipa_gdate_to_gdatetime (gdate), format);
-
- return ret;
+ return zak_utils_gdate_format (gdate, format);
}
+G_DEPRECATED_FOR (zak_utils_gdatetime_format)
gchar
*solipa_gdatetime_format (GDateTime *gdatetime, const gchar *format)
{
- gchar *ret;
-
- if (gdatetime == NULL) return "";
-
- ret = g_date_time_format (gdatetime, format);
-
- if (ret == NULL) return "";
-
- return ret;
+ return zak_utils_gdatetime_format (gdatetime, format);
}
+G_DEPRECATED_FOR (zak_utils_round)
gdouble
solipa_round (gdouble value, guint n_decimals)
{
- gfloat elev;
- gint i;
- gfloat ret;
-
- elev = pow (10.0, (gfloat)n_decimals);
-
- ret = (value * elev) + 0.5;
- i = (gint)ret;
-
- ret = (gfloat)i / elev;
-
- return ret;
+ return zak_utils_round (value, n_decimals);
}
const gchar
return pixbuf;
}
+G_DEPRECATED_FOR (zak_utils_gstring_initial_capital)
void
solipa_gstring_initial_capital (GString *gstring)
{
- const gchar *cutf8;
-
- GString *tmp;
- gboolean first;
- gunichar c;
-
- g_return_if_fail (gstring != NULL);
- g_return_if_fail (gstring->str != NULL);
- g_return_if_fail (g_utf8_validate (gstring->str, -1, NULL));
-
- tmp = g_string_new ("");
- first = TRUE;
-
- cutf8 = gstring->str;
- while (*cutf8)
- {
- c = g_utf8_get_char (cutf8);
- if (!g_unichar_isalpha (c))
- {
- first = TRUE;
- g_string_append_unichar (tmp, c);
- }
- else if (first)
- {
- first = FALSE;
- g_string_append_unichar (tmp, g_unichar_toupper (c));
- }
- else
- {
- g_string_append_unichar (tmp, g_unichar_tolower (c));
- }
- cutf8 = g_utf8_next_char (cutf8);
- }
-
- g_string_assign (gstring, tmp->str);
- g_string_free (tmp, TRUE);
+ zak_utils_gstring_initial_capital (gstring);
}
void
#endif
}
+G_DEPRECATED_FOR (zak_utils_compare_version)
int
solipa_compare_version (const gchar *ver1, const gchar *ver2, const gchar *delimiters, guint *part)
{
- gchar **_ver1;
- gchar **_ver2;
-
- gchar *_delimiters;
-
- guint i;
- guint l;
-
- if (ver1 == NULL)
- {
- return -1;
- }
- if (ver2 == NULL)
- {
- return 1;
- }
-
- if (delimiters == NULL)
- {
- _delimiters = g_strdup (".");
- }
- else
- {
- _delimiters = g_strstrip (g_strdup (delimiters));
- if (g_strcmp0 (_delimiters, "") == 0)
- {
- g_free (_delimiters);
- _delimiters = g_strdup (".");
- }
- }
-
- _ver1 = g_strsplit (g_strstrip (g_strdup (ver1)), _delimiters, -1);
- _ver2 = g_strsplit (g_strstrip (g_strdup (ver2)), _delimiters, -1);
-
- l = MIN (g_strv_length (_ver1), g_strv_length (_ver2));
- for (i = 0; i < l; i++)
- {
- if (strtol (_ver1[i], NULL, 10) < strtol (_ver2[i], NULL, 10))
- {
- if (part != NULL)
- {
- *part = i;
- }
- return -1;
- }
- else if (strtol (_ver1[i], NULL, 10) > strtol (_ver2[i], NULL, 10))
- {
- if (part != NULL)
- {
- *part = i;
- }
- return 1;
- }
- }
-
- if (g_strv_length (_ver1) < g_strv_length (_ver2))
- {
- *part = g_strv_length (_ver1) + 1;
- return -1;
- }
- else if (g_strv_length (_ver1) > g_strv_length (_ver2))
- {
- *part = g_strv_length (_ver2) + 1;
- return 1;
- }
-
- *part = 0;
- return 0;
+ return zak_utils_compare_version (ver1, ver2, delimiters, part);
}
+G_DEPRECATED_FOR (zak_utils_gvalue_new_int)
GValue
*solipa_gvalue_new_int (int i)
{
- GValue *gval;
-
- gval = g_new0 (GValue, 1);
- g_value_init (gval, G_TYPE_INT);
- g_value_set_int (gval, i);
-
- return gval;
+ return zak_utils_gvalue_new_int (i);
}
+G_DEPRECATED_FOR (zak_utils_gvalue_new_string)
GValue
*solipa_gvalue_new_string (const gchar *str)
{
- GValue *gval;
-
- gval = g_new0 (GValue, 1);
- g_value_init (gval, G_TYPE_STRING);
- g_value_set_string (gval, str);
-
- return gval;
+ return zak_utils_gvalue_new_string (str);
}
+G_DEPRECATED_FOR (zak_utils_gvalue_new_boolean)
GValue
*solipa_gvalue_new_boolean (gboolean b)
{
- GValue *gval;
-
- gval = g_new0 (GValue, 1);
- g_value_init (gval, G_TYPE_BOOLEAN);
- g_value_set_boolean (gval, b);
-
- return gval;
+ return zak_utils_gvalue_new_boolean (b);
}
+G_DEPRECATED_FOR (zak_utils_gvalue_new_float)
GValue
*solipa_gvalue_new_float (gfloat f)
{
- GValue *gval;
-
- gval = g_new0 (GValue, 1);
- g_value_init (gval, G_TYPE_FLOAT);
- g_value_set_float (gval, f);
-
- return gval;
+ return zak_utils_gvalue_new_float (f);
}
G_BEGIN_DECLS
-
+G_DEPRECATED_FOR (zak_utils_file_exists)
gboolean solipa_file_exists (const gchar *filename);
void solipa_gtkliststore_select_unselect_all (GtkListStore *store,
GType *solipa_gtktreemodel_get_gtypes (GtkTreeModel *model, guint *cols);
GtkTreeModel *solipa_gtktreemodel_copy (GtkTreeModel *model, gboolean only_schema);
+G_DEPRECATED_FOR (zak_utils_string_replace)
gchar *solipa_string_replace (const gchar *string,
const gchar *origin,
const gchar *replace);
+G_DEPRECATED_FOR (zak_utils_format_money)
gchar *solipa_format_money (gdouble number, gint decimals, gboolean with_currency_symbol);
+G_DEPRECATED_FOR (zak_utils_unformat_money)
gdouble solipa_unformat_money (const gchar *value);
+G_DEPRECATED_FOR (zak_utils_get_now_tm)
struct tm *solipa_get_now_tm (void);
+G_DEPRECATED_FOR (zak_utils_get_today_gdate)
GDate *solipa_get_today_gdate (void);
+G_DEPRECATED_FOR (zak_utils_tm_to_gdatetime)
GDateTime *solipa_tm_to_gdatetime (struct tm *tm_data);
+G_DEPRECATED_FOR (zak_utils_gdatetime_to_tm)
struct tm *solipa_gdatetime_to_tm (GDateTime *gdatetime);
+G_DEPRECATED_FOR (zak_utils_gdate_to_gdatetime)
GDateTime *solipa_gdate_to_gdatetime (GDate *gdate);
+G_DEPRECATED_FOR (zak_utils_gdatetime_to_gdate)
GDate *solipa_gdatetime_to_gdate (GDateTime *gdatetime);
+G_DEPRECATED_FOR (zak_utils_tm_to_sql)
const gchar *solipa_tm_to_sql (struct tm *tm_data, const gchar *format);
+G_DEPRECATED_FOR (zak_utils_gdate_to_sql)
const gchar *solipa_gdate_to_sql (GDate *gdate);
+G_DEPRECATED_FOR (zak_utils_gdatetime_to_sql)
const gchar *solipa_gdatetime_to_sql (GDateTime *gdatetime, const gchar *format);
+G_DEPRECATED_FOR (zak_utils_get_gdate_from_string)
GDate *solipa_get_gdate_from_string (const gchar *string, const gchar *format);
+G_DEPRECATED_FOR (zak_utils_get_gdate_from_string)
GDateTime *solipa_get_gdatetime_from_string (const gchar *string, const gchar *format);
+G_DEPRECATED_FOR (zak_utils_gdate_format)
gchar *solipa_gdate_format (GDate *gdate, const gchar *format);
+G_DEPRECATED_FOR (zak_utils_gdatetime_format)
gchar *solipa_gdatetime_format (GDateTime *gdatetime, const gchar *format);
+G_DEPRECATED_FOR (zak_utils_round)
gdouble solipa_round (gdouble value, guint n_decimals);
const gchar *solipa_gtk_tree_model_get_value_string (GtkTreeModel *model, GtkTreeIter *iter, gint column);
GdkPixbuf *solipa_file_get_icon_as_pixbuf (const gchar *filename, GtkWidget *widget, GtkIconSize size);
+G_DEPRECATED_FOR (zak_utils_gstring_initial_capital)
void solipa_gstring_initial_capital (GString *gstring);
void solipa_apri_collegamento (GtkWindow *transient, const gchar *indirizzo);
+G_DEPRECATED_FOR (zak_utils_compare_version)
int solipa_compare_version (const gchar *ver1, const gchar *ver2, const gchar *delimiters, guint *part);
+G_DEPRECATED_FOR (zak_utils_gvalue_new_int)
GValue *solipa_gvalue_new_int (int i);
+G_DEPRECATED_FOR (zak_utils_gvalue_new_string)
GValue *solipa_gvalue_new_string (const gchar *str);
+G_DEPRECATED_FOR (zak_utils_gvalue_new_boolean)
GValue *solipa_gvalue_new_boolean (gboolean b);
+G_DEPRECATED_FOR (zak_utils_gvalue_new_float)
GValue *solipa_gvalue_new_float (gfloat f);