diary r39 - in trunk: . data po src
- From: pwithnall svn gnome org
- To: svn-commits-list gnome org
- Subject: diary r39 - in trunk: . data po src
- Date: Sun, 8 Jun 2008 00:29:14 +0000 (UTC)
Author: pwithnall
Date: Sun Jun 8 00:29:14 2008
New Revision: 39
URL: http://svn.gnome.org/viewvc/diary?rev=39&view=rev
Log:
2008-06-08 Philip Withnall <philip tecnocode co uk>
* data/diary.ui:
* src/Makefile.am:
* src/interface.c: (diary_create_interface):
* src/main-window.c: (mw_select_date), (mw_search_activate_cb),
(mw_jump_to_today_activate_cb), (mw_calendar_day_selected_cb):
* src/main-window.h:
* src/main.c: (diary_quit):
* src/main.h:
* src/search-dialog.c: (results_selection_changed_cb),
(diary_search_dialog_setup), (sd_destroy_cb),
(sd_search_button_clicked_cb), (select_date),
(sd_results_tree_view_row_activated_cb),
(sd_view_button_clicked_cb):
* src/search-dialog.h:
* src/storage-manager.c: (diary_storage_manager_entry_is_editable),
(diary_storage_manager_set_entry),
(diary_storage_manager_search_entries):
* src/storage-manager.h: Added search functionality with a new search
dialogue. This involved a few cleanups to the interface, and also
resulted in some efficiency improvements by moving some GDates to the
stack from the heap.
Added:
trunk/src/search-dialog.c
trunk/src/search-dialog.h
Modified:
trunk/ChangeLog
trunk/data/diary.ui
trunk/po/ChangeLog
trunk/po/POTFILES.in
trunk/src/Makefile.am
trunk/src/interface.c
trunk/src/main-window.c
trunk/src/main-window.h
trunk/src/main.c
trunk/src/main.h
trunk/src/storage-manager.c
trunk/src/storage-manager.h
Modified: trunk/data/diary.ui
==============================================================================
--- trunk/data/diary.ui (original)
+++ trunk/data/diary.ui Sun Jun 8 00:29:14 2008
@@ -11,14 +11,14 @@
</child>
<child>
<object class="GtkAction" id="dry_ui_print">
- <property name="stock_id">gtk-print</property>
+ <property name="stock-id">gtk-print</property>
<property name="name">file-print</property>
<signal name="activate" handler="mw_print_activate_cb"/>
</object>
</child>
<child>
<object class="GtkAction" id="dry_ui_quit">
- <property name="stock_id">gtk-quit</property>
+ <property name="stock-id">gtk-quit</property>
<property name="name">file-quit</property>
<signal name="activate" handler="mw_quit_activate_cb"/>
</object>
@@ -31,33 +31,41 @@
</child>
<child>
<object class="GtkAction" id="dry_ui_cut">
- <property name="stock_id">gtk-cut</property>
+ <property name="stock-id">gtk-cut</property>
<property name="name">edit-cut</property>
<signal name="activate" handler="mw_cut_activate_cb"/>
</object>
</child>
<child>
<object class="GtkAction" id="dry_ui_copy">
- <property name="stock_id">gtk-copy</property>
+ <property name="stock-id">gtk-copy</property>
<property name="name">edit-copy</property>
<signal name="activate" handler="mw_copy_activate_cb"/>
</object>
</child>
<child>
<object class="GtkAction" id="dry_ui_paste">
- <property name="stock_id">gtk-paste</property>
+ <property name="stock-id">gtk-paste</property>
<property name="name">edit-paste</property>
<signal name="activate" handler="mw_paste_activate_cb"/>
</object>
</child>
<child>
<object class="GtkAction" id="dry_ui_delete">
- <property name="stock_id">gtk-delete</property>
+ <property name="stock-id">gtk-delete</property>
<property name="name">edit-delete</property>
<signal name="activate" handler="mw_delete_activate_cb"/>
</object>
</child>
<child>
+ <object class="GtkAction" id="dry_ui_search">
+ <property name="stock-id">gtk-find</property>
+ <property name="label" translatable="yes">_Search</property>
+ <property name="name">edit-search</property>
+ <signal name="activate" handler="mw_search_activate_cb"/>
+ </object>
+ </child>
+ <child>
<object class="GtkAction" id="dry_ui_help">
<property name="name">help</property>
<property name="label">_Help</property>
@@ -65,7 +73,7 @@
</child>
<child>
<object class="GtkAction" id="dry_ui_about">
- <property name="stock_id">gtk-about</property>
+ <property name="stock-id">gtk-about</property>
<property name="name">help-about</property>
<signal name="activate" handler="mw_about_activate_cb"/>
</object>
@@ -107,6 +115,8 @@
<menuitem action="dry_ui_copy"/>
<menuitem action="dry_ui_paste"/>
<menuitem action="dry_ui_delete"/>
+ <separator/>
+ <menuitem action="dry_ui_search"/>
</menu>
<menu action="dry_ui_help">
<menuitem action="dry_ui_about"/>
@@ -120,6 +130,7 @@
</toolbar>
</ui>
</object>
+
<!-- TODO: Change to dry_mw_link_store -->
<object class="GtkListStore" id="dry_mw_links_store">
<columns>
@@ -129,9 +140,11 @@
<column type="gchararray"/><!--Icon name-->
</columns>
</object>
+
<object class="GtkImage" id="dry_mw_view_button_image">
<property name="stock">gtk-open</property>
</object>
+
<object class="GtkWindow" id="dry_main_window">
<property name="title" translatable="yes">Diary</property>
<signal name="delete-event" handler="mw_delete_event_cb"/>
@@ -147,7 +160,6 @@
<object class="GtkToolbar" constructor="dry_ui_manager" id="dry_mw_toolbar"/>
<packing>
<property name="expand">False</property>
- <property name="position">1</property>
</packing>
</child>
<child>
@@ -180,9 +192,6 @@
</object>
</child>
</object>
- <packing>
- <property name="position">1</property>
- </packing>
</child>
</object>
<packing>
@@ -209,7 +218,6 @@
<signal name="month-changed" handler="diary_calendar_month_changed_cb"/>
</object>
<packing>
- <property name="position">1</property>
<property name="expand">False</property>
</packing>
</child>
@@ -220,7 +228,6 @@
</object>
<packing>
<property name="expand">False</property>
- <property name="position">2</property>
</packing>
</child>
<child>
@@ -255,9 +262,6 @@
</object>
</child>
</object>
- <packing>
- <property name="position">3</property>
- </packing>
</child>
<child>
<object class="GtkHButtonBox" id="buttonbox1">
@@ -285,7 +289,6 @@
</child>
</object>
<packing>
- <property name="position">4</property>
<property name="expand">False</property>
</packing>
</child>
@@ -296,9 +299,6 @@
</packing>
</child>
</object>
- <packing>
- <property name="position">2</property>
- </packing>
</child>
<child>
<object class="GtkStatusbar" id="dry_mw_statusbar">
@@ -306,12 +306,12 @@
</object>
<packing>
<property name="expand">False</property>
- <property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
+
<object class="GtkListStore" id="dry_ald_type_store">
<columns>
<column type="gchararray"/><!--Name-->
@@ -319,6 +319,7 @@
<column type="gchararray"/><!--Icon name-->
</columns>
</object>
+
<!-- TODO: Use the description of link types somewhere -->
<object class="GtkDialog" id="dry_add_link_dialog">
<property name="title" translatable="yes">Add Link</property>
@@ -396,8 +397,108 @@
</object>
</child>
<action-widgets>
- <action-widget response="-6">dry_ald_cancel_button</action-widget>
- <action-widget response="-5">dry_ald_add_button</action-widget>
+ <action-widget response="-6">dry_ald_cancel_button</action-widget><!--GTK_RESPONSE_CANCEL-->
+ <action-widget response="-5">dry_ald_add_button</action-widget><!--GTK_RESPONSE_OK-->
+ </action-widgets>
+ </object>
+
+ <object class="GtkImage" id="dry_sd_search_button_image">
+ <property name="stock">gtk-find</property>
+ </object>
+
+ <object class="GtkListStore" id="dry_sd_results_store">
+ <columns>
+ <column type="guint"/><!--Day-->
+ <column type="guint"/><!--Month-->
+ <column type="guint"/><!--Year-->
+ <column type="gchararray"/><!--Formatted date-->
+ </columns>
+ </object>
+
+ <object class="GtkDialog" id="dry_search_dialog">
+ <property name="title" translatable="yes">Search</property>
+ <property name="has-separator">False</property>
+ <signal name="destroy" handler="sd_destroy_cb"/>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="vbox2">
+ <child>
+ <object class="GtkHBox" id="hbox2">
+ <child>
+ <object class="GtkEntry" id="dry_sd_search_entry">
+ <property name="activates-default">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="dry_sd_search_button">
+ <property name="image">dry_sd_search_button_image</property>
+ <property name="label" translatable="yes">Search</property>
+ <property name="can-default">True</property>
+ <property name="has-default">True</property>
+ <signal name="clicked" handler="sd_search_button_clicked_cb"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="label"><b>Results</b></property>
+ <property name="use-markup">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolledwindow2">
+ <property name="hscrollbar-policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="vscrollbar-policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="shadow-type">GTK_SHADOW_IN</property>
+ <child>
+ <object class="GtkTreeView" id="dry_sd_results_tree_view">
+ <property name="model">dry_sd_results_store</property>
+ <property name="headers-visible">False</property>
+ <signal name="row-activated" handler="sd_results_tree_view_row_activated_cb"/>
+ <child>
+ <object class="GtkTreeViewColumn" id="column0">
+ <child>
+ <object class="GtkCellRendererText" id="renderer0"/>
+ <attributes>
+ <attribute name="text">3</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkHButtonBox" id="hbuttonbox2">
+ <child>
+ <object class="GtkButton" id="dry_sd_view_button">
+ <property name="label" translatable="yes">View Entry</property>
+ <property name="sensitive">False</property>
+ <signal name="clicked" handler="sd_view_button_clicked_cb"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="dry_sd_close_button">
+ <property name="use-stock">True</property>
+ <property name="label">gtk-close</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="-7">dry_sd_close_button</action-widget><!--GTK_RESPONSE_CLOSE-->
</action-widgets>
</object>
</interface>
Modified: trunk/po/POTFILES.in
==============================================================================
--- trunk/po/POTFILES.in (original)
+++ trunk/po/POTFILES.in Sun Jun 8 00:29:14 2008
@@ -9,4 +9,5 @@
src/main-window.c
src/main.c
src/printing.c
+src/search-dialog.c
src/storage-manager.c
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Sun Jun 8 00:29:14 2008
@@ -28,6 +28,8 @@
storage-manager.h \
add-link-dialog.c \
add-link-dialog.h \
+ search-dialog.c \
+ search-dialog.h \
printing.c \
printing.h \
link.c \
Modified: trunk/src/interface.c
==============================================================================
--- trunk/src/interface.c (original)
+++ trunk/src/interface.c Sun Jun 8 00:29:14 2008
@@ -24,6 +24,7 @@
#include "main.h"
#include "main-window.h"
#include "add-link-dialog.h"
+#include "search-dialog.h"
#include "interface.h"
GtkWidget *
@@ -80,6 +81,13 @@
diary->ald_type_store = GTK_LIST_STORE (gtk_builder_get_object (builder, "dry_ald_type_store"));
diary_add_link_dialog_setup (builder);
+ /* Set up the search dialogue */
+ diary->search_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "dry_search_dialog"));
+ diary->sd_search_entry = GTK_ENTRY (gtk_builder_get_object (builder, "dry_sd_search_entry"));
+ diary->sd_results_store = GTK_LIST_STORE (gtk_builder_get_object (builder, "dry_sd_results_store"));
+ diary->sd_results_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (builder, "dry_sd_results_tree_view")));
+ diary_search_dialog_setup (builder);
+
g_object_unref (builder);
return diary->main_window;
Modified: trunk/src/main-window.c
==============================================================================
--- trunk/src/main-window.c (original)
+++ trunk/src/main-window.c Sun Jun 8 00:29:14 2008
@@ -181,6 +181,13 @@
}
}
+void
+mw_select_date (GDate *date)
+{
+ gtk_calendar_select_month (diary->calendar, g_date_get_month (date) - 1, g_date_get_year (date));
+ gtk_calendar_select_day (diary->calendar, g_date_get_day (date));
+}
+
gboolean
mw_delete_event_cb (GtkWindow *window, gpointer user_data)
{
@@ -231,6 +238,19 @@
}
void
+mw_search_activate_cb (GtkAction *action, gpointer user_data)
+{
+ /* Ensure everything's tidy first */
+ gtk_list_store_clear (diary->sd_results_store);
+ gtk_entry_set_text (diary->sd_search_entry, "");
+
+ /* Run the dialogue */
+ gtk_widget_show_all (diary->search_dialog);
+ gtk_dialog_run (GTK_DIALOG (diary->search_dialog));
+ gtk_widget_hide_all (diary->search_dialog);
+}
+
+void
mw_about_activate_cb (GtkAction *action, gpointer user_data)
{
gchar *license, *description;
@@ -291,13 +311,9 @@
void
mw_jump_to_today_activate_cb (GtkAction *action, gpointer user_data)
{
- GDate *current_date;
- current_date = g_date_new ();
- g_date_set_time_t (current_date, time (NULL));
-
- gtk_calendar_select_day (diary->calendar, g_date_get_day (current_date));
-
- g_date_free (current_date);
+ GDate current_date;
+ g_date_set_time_t (¤t_date, time (NULL));
+ mw_select_date (¤t_date);
}
void
@@ -315,7 +331,7 @@
void
mw_calendar_day_selected_cb (GtkCalendar *calendar, gpointer user_data)
{
- GDate *calendar_date;
+ GDate calendar_date;
gchar calendar_string[100], *entry_text;
guint year, month, day;
DiaryLink **links;
@@ -326,12 +342,11 @@
/* Update the date label */
gtk_calendar_get_date (calendar, &year, &month, &day);
month++;
- calendar_date = g_date_new_dmy (day, month, year);
+ g_date_set_dmy (&calendar_date, day, month, year);
/* 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), _("<b>%A, %e %B %Y</b>"), calendar_date);
+ g_date_strftime (calendar_string, sizeof (calendar_string), _("<b>%A, %e %B %Y</b>"), &calendar_date);
gtk_label_set_markup (diary->date_label, calendar_string);
- g_date_free (calendar_date);
/* Update the entry */
entry_text = diary_storage_manager_get_entry (diary->storage_manager, year, month, day);
Modified: trunk/src/main-window.h
==============================================================================
--- trunk/src/main-window.h (original)
+++ trunk/src/main-window.h Sun Jun 8 00:29:14 2008
@@ -26,6 +26,7 @@
G_BEGIN_DECLS
void diary_main_window_setup (GtkBuilder *builder);
+void mw_select_date (GDate *date);
G_END_DECLS
Modified: trunk/src/main.c
==============================================================================
--- trunk/src/main.c (original)
+++ trunk/src/main.c Sun Jun 8 00:29:14 2008
@@ -34,6 +34,7 @@
diary_storage_manager_disconnect (diary->storage_manager);
gtk_widget_destroy (diary->add_link_dialog);
+ gtk_widget_destroy (diary->search_dialog);
gtk_widget_destroy (diary->main_window);
/* Quitting is actually done in the idle handler for disconnection
Modified: trunk/src/main.h
==============================================================================
--- trunk/src/main.h (original)
+++ trunk/src/main.h Sun Jun 8 00:29:14 2008
@@ -52,6 +52,11 @@
GtkTable *ald_table;
GtkListStore *ald_type_store;
+ GtkWidget *search_dialog;
+ GtkEntry *sd_search_entry;
+ GtkListStore *sd_results_store;
+ GtkTreeSelection *sd_results_selection;
+
gboolean debug;
gboolean quitting;
} Diary;
Added: trunk/src/search-dialog.c
==============================================================================
--- (empty file)
+++ trunk/src/search-dialog.c Sun Jun 8 00:29:14 2008
@@ -0,0 +1,111 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * Diary
+ * Copyright (C) Philip Withnall 2008 <philip tecnocode co uk>
+ *
+ * Diary is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Diary is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Diary. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "main.h"
+#include "storage-manager.h"
+#include "search-dialog.h"
+#include "main-window.h"
+
+static void
+results_selection_changed_cb (GtkTreeSelection *tree_selection, GtkWidget *button)
+{
+ gtk_widget_set_sensitive (button, gtk_tree_selection_count_selected_rows (tree_selection) == 0 ? FALSE : TRUE);
+}
+
+void
+diary_search_dialog_setup (GtkBuilder *builder)
+{
+ g_signal_connect (diary->sd_results_selection, "changed", (GCallback) results_selection_changed_cb,
+ gtk_builder_get_object (builder, "dry_sd_view_button"));
+}
+
+void
+sd_destroy_cb (GtkWindow *window, gpointer user_data)
+{
+ gtk_widget_hide_all (diary->search_dialog);
+}
+
+void
+sd_search_button_clicked_cb (GtkButton *self, gpointer user_data)
+{
+ GDate *results;
+ guint result_count, i;
+ GtkTreeIter iter;
+
+ result_count = diary_storage_manager_search_entries (diary->storage_manager,
+ gtk_entry_get_text (diary->sd_search_entry), &results);
+
+ for (i = 0; i < result_count; i++) {
+ gchar formatted_date[100];
+
+ /* Translators: This is a strftime()-format string for the dates displayed in search results. */
+ g_date_strftime (formatted_date, sizeof (formatted_date), _("%A, %e %B %Y"), &results[i]);
+
+ gtk_list_store_append (diary->sd_results_store, &iter);
+ gtk_list_store_set (diary->sd_results_store, &iter,
+ 0, g_date_get_day (&results[i]),
+ 1, g_date_get_month (&results[i]),
+ 2, g_date_get_year (&results[i]),
+ 3, &formatted_date,
+ -1);
+ }
+
+ g_free (results);
+}
+
+static void
+select_date (GtkTreeModel *model, GtkTreeIter *iter)
+{
+ guint day, month, year;
+ GDate date;
+
+ gtk_tree_model_get (model, iter,
+ 0, &day,
+ 1, &month,
+ 2, &year,
+ -1);
+
+ g_date_set_dmy (&date, day, month, year);
+ mw_select_date (&date);
+}
+
+void
+sd_results_tree_view_row_activated_cb (GtkTreeView *self, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+
+ model = gtk_tree_view_get_model (self);
+ gtk_tree_model_get_iter (model, &iter, path);
+ select_date (model, &iter);
+}
+
+void
+sd_view_button_clicked_cb (GtkButton *self, gpointer user_data)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+
+ if (gtk_tree_selection_get_selected (diary->sd_results_selection, &model, &iter) == TRUE)
+ select_date (model, &iter);
+}
Added: trunk/src/search-dialog.h
==============================================================================
--- (empty file)
+++ trunk/src/search-dialog.h Sun Jun 8 00:29:14 2008
@@ -0,0 +1,31 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * Diary
+ * Copyright (C) Philip Withnall 2008 <philip tecnocode co uk>
+ *
+ * Diary is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Diary is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Diary. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+
+#ifndef DIARY_SEARCH_DIALOG_H
+#define DIARY_SEARCH_DIALOG_H
+
+G_BEGIN_DECLS
+
+void diary_search_dialog_setup (GtkBuilder *builder);
+
+G_END_DECLS
+
+#endif /* !DIARY_SEARCH_DIALOG_H */
Modified: trunk/src/storage-manager.c
==============================================================================
--- trunk/src/storage-manager.c (original)
+++ trunk/src/storage-manager.c Sun Jun 8 00:29:14 2008
@@ -606,17 +606,14 @@
gboolean
diary_storage_manager_entry_is_editable (DiaryStorageManager *self, GDateYear year, GDateMonth month, GDateDay day)
{
- GDate *current_date, *entry_date;
+ GDate current_date, entry_date;
gint days_between;
- current_date = g_date_new ();
- g_date_set_time_t (current_date, time (NULL));
- entry_date = g_date_new_dmy (day, month, year);
+ g_date_set_time_t (¤t_date, time (NULL));
+ g_date_set_dmy (&entry_date, day, month, year);
/* Entries can't be edited before they've happened, or after 14 days after they've happened */
- days_between = g_date_days_between (entry_date, current_date);
- g_date_free (entry_date);
- g_date_free (current_date);
+ days_between = g_date_days_between (&entry_date, ¤t_date);
if (days_between < 0 || days_between > 14)
return FALSE;
@@ -658,7 +655,7 @@
* the entry for that date. It will return %TRUE if the content is
* non-empty, and %FALSE otherwise.
*
- * Return value: %TRUE if the entry non-empty
+ * Return value: %TRUE if the entry is non-empty
**/
gboolean
diary_storage_manager_set_entry (DiaryStorageManager *self, GDateYear year, GDateMonth month, GDateDay day, const gchar *content)
@@ -669,12 +666,12 @@
/* Can't nullify entries without permission */
if (content == NULL || content[0] == '\0') {
- GDate *date;
+ GDate date;
gchar date_string[100];
GtkWidget *dialog;
- date = g_date_new_dmy (day, month, year);
- g_date_strftime (date_string, sizeof (date_string), "%A, %e %B %Y", date);
+ g_date_set_dmy (&date, day, month, year);
+ g_date_strftime (date_string, sizeof (date_string), "%A, %e %B %Y", &date);
dialog = gtk_message_dialog_new (GTK_WINDOW (diary->main_window),
GTK_DIALOG_MODAL,
@@ -686,7 +683,6 @@
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
GTK_STOCK_DELETE, GTK_RESPONSE_ACCEPT,
NULL);
- g_date_free (date);
gtk_widget_show_all (dialog);
if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_ACCEPT) {
@@ -705,6 +701,51 @@
return TRUE;
}
+/**
+ * diary_storage_manager_search_entries:
+ * @self: a #DiaryStorageManager
+ * @search_string: string for which to search in entry content
+ * @matches: return location for the results
+ *
+ * Searches for @search_string in the content in entries in the
+ * database, and returns a the number of results. The results
+ * themselves are returned in @matches as an array of #GDates.
+ *
+ * If there are no results, @matches will be set to %NULL. It
+ * must otherwise be freed with g_free().
+ *
+ * Return value: number of results
+ **/
+guint
+diary_storage_manager_search_entries (DiaryStorageManager *self, const gchar *search_string, GDate *matches[])
+{
+ DiaryQueryResults *results;
+ guint i;
+
+ results = diary_storage_manager_query (self, "SELECT day, month, year FROM entries WHERE content LIKE '%%%q%%'", search_string);
+
+ /* No results? */
+ if (results->rows < 1) {
+ diary_storage_manager_free_results (results);
+ *matches = NULL;
+ return 0;
+ }
+
+ /* Allocate and set the results */
+ *matches = g_new0 (GDate, results->rows);
+
+ for (i = 0; i < results->rows; i++) {
+ g_date_set_dmy (&((*matches)[i]),
+ (GDateDay) atoi (results->data[(i + 1) * results->columns]),
+ (GDateMonth) atoi (results->data[(i + 1) * results->columns + 1]),
+ (GDateYear) atoi (results->data[(i + 1) * results->columns + 2]));
+ }
+
+ diary_storage_manager_free_results (results);
+
+ return i;
+}
+
/* NOTE: Free results with g_slice_free */
gboolean *
diary_storage_manager_get_month_marked_days (DiaryStorageManager *self, GDateYear year, GDateMonth month)
Modified: trunk/src/storage-manager.h
==============================================================================
--- trunk/src/storage-manager.h (original)
+++ trunk/src/storage-manager.h Sun Jun 8 00:29:14 2008
@@ -76,10 +76,14 @@
/* TODO: Surely just passing in GDates to these functions would be easier? */
gboolean diary_storage_manager_get_statistics (DiaryStorageManager *self, guint *entry_count, guint *link_count, guint *character_count);
+
gboolean diary_storage_manager_entry_is_editable (DiaryStorageManager *self, GDateYear year, GDateMonth month, GDateDay day);
gchar *diary_storage_manager_get_entry (DiaryStorageManager *self, GDateYear year, GDateMonth month, GDateDay day);
gboolean diary_storage_manager_set_entry (DiaryStorageManager *self, GDateYear year, GDateMonth month, GDateDay day, const gchar *content);
+guint diary_storage_manager_search_entries (DiaryStorageManager *self, const gchar *search_string, GDate *matches[]);
+
gboolean *diary_storage_manager_get_month_marked_days (DiaryStorageManager *self, GDateYear year, GDateMonth month);
+
DiaryLink **diary_storage_manager_get_entry_links (DiaryStorageManager *self, GDateYear year, GDateMonth month, GDateDay day);
gboolean diary_storage_manager_add_entry_link (DiaryStorageManager *self, GDateYear year, GDateMonth month, GDateDay day, const gchar *link_type, const gchar *link_value, const gchar *link_value2);
gboolean diary_storage_manager_remove_entry_link (DiaryStorageManager *self, GDateYear year, GDateMonth month, GDateDay day, const gchar *link_type);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]