almanah r105 - in trunk: . src
- From: pwithnall svn gnome org
- To: svn-commits-list gnome org
- Subject: almanah r105 - in trunk: . src
- Date: Thu, 13 Nov 2008 23:37:49 +0000 (UTC)
Author: pwithnall
Date: Thu Nov 13 23:37:49 2008
New Revision: 105
URL: http://svn.gnome.org/viewvc/almanah?rev=105&view=rev
Log:
2008-11-13 Philip Withnall <philip tecnocode co uk>
* src/link.c: Remove an unnecessary comment.
* src/main-window.c (get_selected_date),
(add_link_to_current_entry), (remove_link_from_current_entry),
(mw_calendar_day_selected_cb), (mw_links_value_data_cb):
Refactor some of the date handling code into a separate
function.
* src/interface.c (almanah_calendar_month_changed_cb):
* src/storage-manager.c
(almanah_storage_manager_get_month_marked_days):
* src/storage-manager.h: Use a variable-length array for the
mark data for each month.
Modified:
trunk/ChangeLog
trunk/src/interface.c
trunk/src/link.c
trunk/src/main-window.c
trunk/src/storage-manager.c
trunk/src/storage-manager.h
Modified: trunk/src/interface.c
==============================================================================
--- trunk/src/interface.c (original)
+++ trunk/src/interface.c Thu Nov 13 23:37:49 2008
@@ -68,20 +68,19 @@
almanah_calendar_month_changed_cb (GtkCalendar *calendar, gpointer user_data)
{
/* Mark the days on the calendar which have diary entries */
- guint i, year, month;
+ guint i, year, month, num_days;
gboolean *days;
gtk_calendar_get_date (calendar, &year, &month, NULL);
month++;
- days = almanah_storage_manager_get_month_marked_days (almanah->storage_manager, year, month);
+ days = almanah_storage_manager_get_month_marked_days (almanah->storage_manager, year, month, &num_days);
- /* TODO: Don't like hard-coding the array length here */
gtk_calendar_clear_marks (calendar);
- for (i = 1; i < 32; i++) {
+ for (i = 0; i < num_days; i++) {
if (days[i] == TRUE)
- gtk_calendar_mark_day (calendar, i);
+ gtk_calendar_mark_day (calendar, i + 1);
else
- gtk_calendar_unmark_day (calendar, i);
+ gtk_calendar_unmark_day (calendar, i + 1);
}
g_free (days);
Modified: trunk/src/link.c
==============================================================================
--- trunk/src/link.c (original)
+++ trunk/src/link.c Thu Nov 13 23:37:49 2008
@@ -316,8 +316,6 @@
return g_strdup (self->priv->value2);
}
-/* TODO: Perhaps an almanah_link_set_values (AlmanahLink *self, const gchar *value, const gchar *value2) API would be better? */
-
void
almanah_link_set_value2 (AlmanahLink *self, const gchar *value)
{
Modified: trunk/src/main-window.c
==============================================================================
--- trunk/src/main-window.c (original)
+++ trunk/src/main-window.c Thu Nov 13 23:37:49 2008
@@ -412,6 +412,16 @@
}
static void
+get_selected_date (AlmanahMainWindow *self, GDate *date)
+{
+ guint year, month, day;
+
+ gtk_calendar_get_date (self->priv->calendar, &year, &month, &day);
+ month++;
+ g_date_set_dmy (date, day, month, year);
+}
+
+static void
add_link_to_current_entry (AlmanahMainWindow *self)
{
GtkTreeIter iter;
@@ -424,7 +434,6 @@
gtk_widget_show_all (almanah->add_link_dialog);
if (gtk_dialog_run (GTK_DIALOG (almanah->add_link_dialog)) == GTK_RESPONSE_OK) {
- guint year, month, day;
GDate date;
AlmanahLink *link = almanah_add_link_dialog_get_link (ALMANAH_ADD_LINK_DIALOG (almanah->add_link_dialog));
@@ -432,11 +441,7 @@
return;
/* Add to the DB */
- /* TODO: Clean this date stuff up and separate it out into its own function */
- gtk_calendar_get_date (priv->calendar, &year, &month, &day);
- month++;
- g_date_set_dmy (&date, day, month, year);
-
+ get_selected_date (self, &date);
almanah_storage_manager_add_entry_link (almanah->storage_manager, &date, link);
/* Add to the treeview */
@@ -456,7 +461,6 @@
remove_link_from_current_entry (AlmanahMainWindow *self)
{
gchar *link_type;
- guint year, month, day;
GDate date;
GtkTreeIter iter;
GtkTreeModel *model;
@@ -464,9 +468,7 @@
AlmanahMainWindowPrivate *priv = self->priv;
links = gtk_tree_selection_get_selected_rows (priv->links_selection, &model);
- gtk_calendar_get_date (priv->calendar, &year, &month, &day);
- month++;
- g_date_set_dmy (&date, day, month, year);
+ get_selected_date (self, &date);
for (; links != NULL; links = links->next) {
gtk_tree_model_get_iter (model, &iter, (GtkTreePath*) links->data);
@@ -788,7 +790,6 @@
{
GDate calendar_date;
gchar calendar_string[100];
- guint year, month, day;
AlmanahLink **links;
guint i;
GtkTreeIter iter;
@@ -798,9 +799,7 @@
AlmanahMainWindowPrivate *priv = main_window->priv;
/* Update the date label */
- gtk_calendar_get_date (calendar, &year, &month, &day);
- month++;
- g_date_set_dmy (&calendar_date, day, month, year);
+ get_selected_date (main_window, &calendar_date);
/* Translators: This is a strftime()-format string for the date displayed at the top of the main window. */
g_date_strftime (calendar_string, sizeof (calendar_string), _("%A, %e %B %Y"), &calendar_date);
@@ -909,7 +908,7 @@
gchar *new_value, *value, *value2, *type;
AlmanahLink *link;
- /* TODO: Should really create a new model to render AlmanahLinks --- or at least attach the approprite AlmanahLink to each tree model row */
+ /* TODO: Should really create a new model to render AlmanahLinks --- or at least attach the appropriate AlmanahLink to each tree model row */
gtk_tree_model_get (model, iter,
0, &type,
Modified: trunk/src/storage-manager.c
==============================================================================
--- trunk/src/storage-manager.c (original)
+++ trunk/src/storage-manager.c Thu Nov 13 23:37:49 2008
@@ -840,13 +840,18 @@
return result_count - 1;
}
-/* NOTE: Free results with g_free */
+/* NOTE: Free results with g_free. Return value is 0-based. */
gboolean *
-almanah_storage_manager_get_month_marked_days (AlmanahStorageManager *self, GDateYear year, GDateMonth month)
+almanah_storage_manager_get_month_marked_days (AlmanahStorageManager *self, GDateYear year, GDateMonth month, guint *num_days)
{
AlmanahQueryResults *results;
guint i;
- gboolean *days = g_malloc0 (sizeof (gboolean) * 32);
+ gboolean *days;
+
+ i = g_date_get_days_in_month (month, year);
+ if (num_days != NULL)
+ *num_days = i;
+ days = g_malloc0 (sizeof (gboolean) * i);
results = almanah_storage_manager_query (self, "SELECT day FROM entries WHERE year = %u AND month = %u", NULL,
year,
@@ -856,7 +861,7 @@
return days;
for (i = 1; i <= results->rows; i++)
- days[atoi (results->data[i])] = TRUE;
+ days[atoi (results->data[i]) - 1] = TRUE;
almanah_storage_manager_free_results (results);
Modified: trunk/src/storage-manager.h
==============================================================================
--- trunk/src/storage-manager.h (original)
+++ trunk/src/storage-manager.h Thu Nov 13 23:37:49 2008
@@ -83,7 +83,7 @@
gboolean almanah_storage_manager_set_entry (AlmanahStorageManager *self, AlmanahEntry *entry);
gint almanah_storage_manager_search_entries (AlmanahStorageManager *self, const gchar *search_string, GDate *matches[]);
-gboolean *almanah_storage_manager_get_month_marked_days (AlmanahStorageManager *self, GDateYear year, GDateMonth month);
+gboolean *almanah_storage_manager_get_month_marked_days (AlmanahStorageManager *self, GDateYear year, GDateMonth month, guint *num_days);
AlmanahLink **almanah_storage_manager_get_entry_links (AlmanahStorageManager *self, GDate *date);
gboolean almanah_storage_manager_add_entry_link (AlmanahStorageManager *self, GDate *date, AlmanahLink *link);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]