almanah r144 - in trunk: . data src



Author: pwithnall
Date: Sun Mar 22 22:33:11 2009
New Revision: 144
URL: http://svn.gnome.org/viewvc/almanah?rev=144&view=rev

Log:
2009-03-22  Philip Withnall  <philip tecnocode co uk>

	* data/almanah.ui:
	* src/entry.c (almanah_entry_class_init), (almanah_entry_finalize),
	(almanah_entry_get_property), (almanah_entry_set_property),
	(almanah_entry_is_important), (almanah_entry_set_is_important):
	* src/entry.h:
	* src/main-window.c (almanah_main_window_new),
	(mw_important_activate_cb), (mw_about_activate_cb),
	(mw_calendar_day_selected_cb):
	* src/storage-manager.c (create_tables),
	(almanah_storage_manager_get_entry),
	(almanah_storage_manager_set_entry),
	(almanah_storage_manager_search_entries):
	* src/storage-manager.h: Add the ability to mark entries as important.
	(Helps: #572927)



Modified:
   trunk/ChangeLog
   trunk/data/almanah.ui
   trunk/src/entry.c
   trunk/src/entry.h
   trunk/src/main-window.c
   trunk/src/storage-manager.c
   trunk/src/storage-manager.h

Modified: trunk/data/almanah.ui
==============================================================================
--- trunk/data/almanah.ui	(original)
+++ trunk/data/almanah.ui	Sun Mar 22 22:33:11 2009
@@ -120,7 +120,7 @@
 					<accelerator key="U" modifiers="GDK_CONTROL_MASK"/>
 				</child>
 				<child>
-					<object class="GtkToggleAction" id="almanah_ui_insert_time">
+					<object class="GtkAction" id="almanah_ui_insert_time">
 						<property name="name">format-insert-time</property>
 						<property name="label" translatable="yes">Insert _Time</property>
 						<signal name="activate" handler="mw_insert_time_activate_cb"/>
@@ -128,6 +128,15 @@
 					<accelerator key="T" modifiers="GDK_CONTROL_MASK"/>
 				</child>
 				<child>
+					<object class="GtkToggleAction" id="almanah_ui_important">
+						<property name="name">format-important</property>
+						<property name="label" translatable="yes">I_mportant</property>
+						<property name="icon-name">gtk-info</property>
+						<signal name="activate" handler="mw_important_activate_cb"/>
+					</object>
+					<accelerator key="M" modifiers="GDK_CONTROL_MASK"/>
+				</child>
+				<child>
 					<object class="GtkAction" id="almanah_ui_help">
 						<property name="name">help</property>
 						<property name="label" translatable="yes">_Help</property>
@@ -188,6 +197,8 @@
 					<menuitem action="almanah_ui_print_preview"/>
 					<menuitem action="almanah_ui_print"/>
 					<separator/>
+					<menuitem action="almanah_ui_jump_to_today"/>
+					<separator/>
 					<menuitem action="almanah_ui_quit"/>
 				</menu>
 				<menu action="almanah_ui_edit">
@@ -206,6 +217,7 @@
 					<menuitem action="almanah_ui_underline"/>
 					<separator/>
 					<menuitem action="almanah_ui_insert_time"/>
+					<menuitem action="almanah_ui_important"/>
 				</menu>
 				<menu action="almanah_ui_definitions">
 					<menuitem action="almanah_ui_add_definition"/>
@@ -219,6 +231,7 @@
 			</menubar>
 			<toolbar name="almanah_mw_toolbar">
 				<toolitem action="almanah_ui_jump_to_today"/>
+				<toolitem action="almanah_ui_important"/>
 				<separator/>
 				<toolitem action="almanah_ui_bold"/>
 				<toolitem action="almanah_ui_italic"/>

Modified: trunk/src/entry.c
==============================================================================
--- trunk/src/entry.c	(original)
+++ trunk/src/entry.c	Sun Mar 22 22:33:11 2009
@@ -1,7 +1,7 @@
 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 /*
  * Almanah
- * Copyright (C) Philip Withnall 2008 <philip tecnocode co uk>
+ * Copyright (C) Philip Withnall 2008-2009 <philip tecnocode co uk>
  * 
  * Almanah is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -34,12 +34,14 @@
 	guint8 *data;
 	gsize length;
 	gboolean is_empty;
+	gboolean is_important;
 };
 
 enum {
 	PROP_DAY = 1,
 	PROP_MONTH,
-	PROP_YEAR
+	PROP_YEAR,
+	PROP_IS_IMPORTANT
 };
 
 G_DEFINE_TYPE (AlmanahEntry, almanah_entry, G_TYPE_OBJECT)
@@ -71,6 +73,10 @@
 					"Year", "The year for which this is the entry.",
 					1, (1 << 16) - 1, 1,
 					G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+	g_object_class_install_property (gobject_class, PROP_IS_IMPORTANT,
+				g_param_spec_boolean ("is-important",
+					"Important?", "Whether the entry is particularly important to the user.",
+					FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 }
 
 static void
@@ -88,7 +94,6 @@
 	AlmanahEntryPrivate *priv = ALMANAH_ENTRY (object)->priv;
 
 	g_free (priv->data);
-	priv->data = NULL;
 
 	/* Chain up to the parent class */
 	G_OBJECT_CLASS (almanah_entry_parent_class)->finalize (object);
@@ -109,6 +114,9 @@
 		case PROP_YEAR:
 			g_value_set_uint (value, g_date_get_year (&(priv->date)));
 			break;
+		case PROP_IS_IMPORTANT:
+			g_value_set_boolean (value, priv->is_important);
+			break;
 		default:
 			/* We don't have any other property... */
 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -131,6 +139,9 @@
 		case PROP_YEAR:
 			g_date_set_year (&(priv->date), g_value_get_uint (value));
 			break;
+		case PROP_IS_IMPORTANT:
+			priv->is_important = g_value_get_boolean (value);
+			break;
 		default:
 			/* We don't have any other property... */
 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -264,3 +275,16 @@
 		self->priv->data == NULL ||
 		self->priv->data[0] == '\0') ? TRUE : FALSE;
 }
+
+gboolean
+almanah_entry_is_important (AlmanahEntry *self)
+{
+	return self->priv->is_important;
+}
+
+void
+almanah_entry_set_is_important (AlmanahEntry *self, gboolean is_important)
+{
+	self->priv->is_important = is_important;
+	g_object_notify (G_OBJECT (self), "is-important");
+}

Modified: trunk/src/entry.h
==============================================================================
--- trunk/src/entry.h	(original)
+++ trunk/src/entry.h	Sun Mar 22 22:33:11 2009
@@ -1,7 +1,7 @@
 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 /*
  * Almanah
- * Copyright (C) Philip Withnall 2008 <philip tecnocode co uk>
+ * Copyright (C) Philip Withnall 2008-2009 <philip tecnocode co uk>
  * 
  * Almanah is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -64,6 +64,9 @@
 AlmanahEntryEditability almanah_entry_get_editability (AlmanahEntry *self);
 gboolean almanah_entry_is_empty (AlmanahEntry *self);
 
+gboolean almanah_entry_is_important (AlmanahEntry *self);
+void almanah_entry_set_is_important (AlmanahEntry *self, gboolean is_important);
+
 G_END_DECLS
 
 #endif /* !ALMANAH_ENTRY_H */

Modified: trunk/src/main-window.c
==============================================================================
--- trunk/src/main-window.c	(original)
+++ trunk/src/main-window.c	Sun Mar 22 22:33:11 2009
@@ -1,7 +1,7 @@
 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 /*
  * Almanah
- * Copyright (C) Philip Withnall 2008 <philip tecnocode co uk>
+ * Copyright (C) Philip Withnall 2008-2009 <philip tecnocode co uk>
  * 
  * Almanah is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -77,6 +77,7 @@
 	GtkAction *cut_action;
 	GtkAction *copy_action;
 	GtkAction *delete_action;
+	GtkAction *important_action;
 
 	gboolean updating_formatting;
 	gboolean pending_bold_active;
@@ -183,6 +184,7 @@
 	priv->cut_action = GTK_ACTION (gtk_builder_get_object (builder, "almanah_ui_cut"));
 	priv->copy_action = GTK_ACTION (gtk_builder_get_object (builder, "almanah_ui_copy"));
 	priv->delete_action = GTK_ACTION (gtk_builder_get_object (builder, "almanah_ui_delete"));
+	priv->important_action = GTK_ACTION (gtk_builder_get_object (builder, "almanah_ui_important"));
 
 	/* Set up text formatting */
 	almanah_interface_create_text_tags (priv->entry_buffer, TRUE);
@@ -726,6 +728,12 @@
 }
 
 void
+mw_important_activate_cb (GtkAction *action, AlmanahMainWindow *main_window)
+{
+	almanah_entry_set_is_important (main_window->priv->current_entry, gtk_toggle_action_get_active(GTK_TOGGLE_ACTION (action)));
+}
+
+void
 mw_search_activate_cb (GtkAction *action, gpointer user_data)
 {
 	if (almanah->search_dialog == NULL)
@@ -821,7 +829,7 @@
 
 	gtk_show_about_dialog (GTK_WINDOW (main_window),
 				"version", VERSION,
-				"copyright", _("Copyright \xc2\xa9 2008 Philip Withnall"),
+				"copyright", _("Copyright \xc2\xa9 2008-2009 Philip Withnall"),
 				"comments", description,
 				"authors", authors,
 				/* Translators: please include your names here to be credited for your hard work!
@@ -972,6 +980,8 @@
 
 	gtk_text_view_set_editable (priv->entry_view, almanah_entry_get_editability (priv->current_entry) != ALMANAH_ENTRY_FUTURE ? TRUE : FALSE);
 	gtk_text_buffer_set_modified (priv->entry_buffer, FALSE);
+	gtk_action_set_sensitive (priv->important_action, almanah_entry_get_editability (priv->current_entry) != ALMANAH_ENTRY_FUTURE ? TRUE : FALSE);
+	gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (priv->important_action), almanah_entry_is_important (priv->current_entry));
 
 	/* Prepare for the possibility of failure --- do as much of the general interface changes as possible first */
 	gtk_list_store_clear (priv->event_store);

Modified: trunk/src/storage-manager.c
==============================================================================
--- trunk/src/storage-manager.c	(original)
+++ trunk/src/storage-manager.c	Sun Mar 22 22:33:11 2009
@@ -1,7 +1,7 @@
 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 /*
  * Almanah
- * Copyright (C) Philip Withnall 2008 <philip tecnocode co uk>
+ * Copyright (C) Philip Withnall 2008-2009 <philip tecnocode co uk>
  * 
  * Almanah is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -185,6 +185,7 @@
 	const gchar *queries[] = {
 		"CREATE TABLE IF NOT EXISTS entries (year INTEGER, month INTEGER, day INTEGER, content TEXT, PRIMARY KEY (year, month, day))",
 		"CREATE TABLE IF NOT EXISTS definitions (definition_text TEXT, definition_type INTEGER, definition_value TEXT, definition_value2 TEXT, PRIMARY KEY (definition_text))",
+		"ALTER TABLE entries ADD COLUMN is_important INTEGER", /* added in 0.7.0 */
 		NULL
 	};
 
@@ -725,7 +726,7 @@
 
 	/* Prepare the statement */
 	if (sqlite3_prepare_v2 (self->priv->connection,
-				"SELECT content FROM entries WHERE year = ? AND month = ? AND day = ?", -1,
+				"SELECT content, is_important FROM entries WHERE year = ? AND month = ? AND day = ?", -1,
 				&statement, NULL) != SQLITE_OK) {
 		return NULL;
 	}
@@ -744,6 +745,7 @@
 	/* Get the data */
 	entry = almanah_entry_new (date);
 	almanah_entry_set_data (entry, sqlite3_column_blob (statement, 0), sqlite3_column_bytes (statement, 0));
+	almanah_entry_set_is_important (entry, (sqlite3_column_int (statement, 1) == 1) ? TRUE : FALSE);
 
 	sqlite3_finalize (statement);
 
@@ -788,7 +790,7 @@
 
 		/* Prepare the statement */
 		if (sqlite3_prepare_v2 (self->priv->connection,
-					"REPLACE INTO entries (year, month, day, content) VALUES (?, ?, ?, ?)", -1,
+					"REPLACE INTO entries (year, month, day, content, is_important) VALUES (?, ?, ?, ?, ?)", -1,
 					&statement, NULL) != SQLITE_OK) {
 			return FALSE;
 		}
@@ -801,6 +803,8 @@
 		data = almanah_entry_get_data (entry, &length);
 		sqlite3_bind_blob (statement, 4, data, length, SQLITE_TRANSIENT);
 
+		sqlite3_bind_int (statement, 5, almanah_entry_is_important (entry));
+
 		/* Execute the statement */
 		if (sqlite3_step (statement) != SQLITE_DONE) {
 			sqlite3_finalize (statement);
@@ -837,7 +841,7 @@
 
 	/* Prepare the statement */
 	if (sqlite3_prepare_v2 (self->priv->connection,
-				"SELECT content, day, month, year FROM entries", -1,
+				"SELECT content, day, month, year, is_important FROM entries", -1,
 				&statement, NULL) != SQLITE_OK) {
 		return -1;
 	}
@@ -854,6 +858,7 @@
 		g_date_set_dmy (date, sqlite3_column_int (statement, 1), sqlite3_column_int (statement, 2), sqlite3_column_int (statement, 3));
 		entry = almanah_entry_new (date);
 		almanah_entry_set_data (entry, sqlite3_column_blob (statement, 0), sqlite3_column_bytes (statement, 0));
+		almanah_entry_set_is_important (entry, (sqlite3_column_int (statement, 4) == 1) ? TRUE : FALSE);
 
 		/* Deserialise the entry into our buffer */
 		gtk_text_buffer_set_text (text_buffer, "", 0);

Modified: trunk/src/storage-manager.h
==============================================================================
--- trunk/src/storage-manager.h	(original)
+++ trunk/src/storage-manager.h	Sun Mar 22 22:33:11 2009
@@ -1,7 +1,7 @@
 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 /*
  * Almanah
- * Copyright (C) Philip Withnall 2008 <philip tecnocode co uk>
+ * Copyright (C) Philip Withnall 2008-2009 <philip tecnocode co uk>
  * 
  * Almanah is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]