aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodrigo Moya <rodrigo@ximian.com>2003-10-25 01:46:27 +0800
committerRodrigo Moya <rodrigo@src.gnome.org>2003-10-25 01:46:27 +0800
commit602ee2f49664f532de6ba5f44b323dcb26192012 (patch)
tree19dd7fa0562e21fc049cc46ac5c093f01b45395a
parentea5a22bc0ee7a3ed18d67a750cdfdb0cfe22007d (diff)
downloadgsoc2013-evolution-602ee2f49664f532de6ba5f44b323dcb26192012.tar.gz
gsoc2013-evolution-602ee2f49664f532de6ba5f44b323dcb26192012.tar.zst
gsoc2013-evolution-602ee2f49664f532de6ba5f44b323dcb26192012.zip
removed repeated initialization. (calendar_component_peek): use G_STRLOC
2003-10-24 Rodrigo Moya <rodrigo@ximian.com> * gui/calendar-component.c (calendar_component_class_init): removed repeated initialization. (calendar_component_peek): use G_STRLOC for g_warning's. * gui/tsaks-control.[ch] (tasks_control_activate, tasks_control_deactivate): made these 2 functions public. * gui/tasks-component.[ch]: implementation of the tasks component. * gui/Makefile.am: * gui/GNOME_Evolution_Calendar.server.in.in: added tasks component. * gui/main.c: ditto. (factory): added code to create the tasks component when requested. svn path=/trunk/; revision=23065
-rw-r--r--calendar/ChangeLog17
-rw-r--r--calendar/gui/GNOME_Evolution_Calendar.server.in.in15
-rw-r--r--calendar/gui/Makefile.am2
-rw-r--r--calendar/gui/calendar-component.c4
-rw-r--r--calendar/gui/main.c8
-rw-r--r--calendar/gui/tasks-component.c347
-rw-r--r--calendar/gui/tasks-component.h60
-rw-r--r--calendar/gui/tasks-control.c9
-rw-r--r--calendar/gui/tasks-control.h5
9 files changed, 455 insertions, 12 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 4ebfac9422..6de9cee8f4 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,20 @@
+2003-10-24 Rodrigo Moya <rodrigo@ximian.com>
+
+ * gui/calendar-component.c (calendar_component_class_init): removed
+ repeated initialization.
+ (calendar_component_peek): use G_STRLOC for g_warning's.
+
+ * gui/tsaks-control.[ch] (tasks_control_activate,
+ tasks_control_deactivate): made these 2 functions public.
+
+ * gui/tasks-component.[ch]: implementation of the tasks component.
+
+ * gui/Makefile.am:
+ * gui/GNOME_Evolution_Calendar.server.in.in: added tasks component.
+
+ * gui/main.c: ditto.
+ (factory): added code to create the tasks component when requested.
+
2003-10-24 Dan Winship <danw@ximian.com>
* cal-client/cal-client.c (cal_client_get_changes): Remove type arg
diff --git a/calendar/gui/GNOME_Evolution_Calendar.server.in.in b/calendar/gui/GNOME_Evolution_Calendar.server.in.in
index 21615173f5..d5b43c698b 100644
--- a/calendar/gui/GNOME_Evolution_Calendar.server.in.in
+++ b/calendar/gui/GNOME_Evolution_Calendar.server.in.in
@@ -64,6 +64,21 @@
_value="Evolution Calendar viewer"/>
</oaf_server>
+<oaf_server iid="OAFIID:GNOME_Evolution_Tasks_Component"
+ type="factory"
+ location="OAFIID:GNOME_Evolution_Calendar_Factory_2">
+
+ <oaf_attribute name="repo_ids" type="stringv">
+ <item value="IDL:GNOME/Evolution/Component:1.0"/>
+ </oaf_attribute>
+
+ <oaf_attribute name="name" type="string" _value="Evolution's Tasks component"/>
+
+ <oaf_attribute name="evolution:button_label" type="string" _value="Tasks"/>
+ <oaf_attribute name="evolution:button_icon" type="string" value="evolution-tasks.png"/>
+ <oaf_attribute name="evolution:button_sort_order" type="string" value="-8"/>
+</oaf_server>
+
<oaf_server iid="OAFIID:GNOME_Evolution_Tasks_Control"
type="factory"
location="OAFIID:GNOME_Evolution_Calendar_Factory_2">
diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am
index 19edf95953..0106a248c6 100644
--- a/calendar/gui/Makefile.am
+++ b/calendar/gui/Makefile.am
@@ -177,6 +177,8 @@ libevolution_calendar_la_SOURCES = \
print.h \
tag-calendar.c \
tag-calendar.h \
+ tasks-component.c \
+ tasks-component.h \
tasks-control.c \
tasks-control.h \
weekday-picker.c \
diff --git a/calendar/gui/calendar-component.c b/calendar/gui/calendar-component.c
index 4f89a5e8d3..eec39adad6 100644
--- a/calendar/gui/calendar-component.c
+++ b/calendar/gui/calendar-component.c
@@ -276,8 +276,6 @@ calendar_component_class_init (CalendarComponentClass *class)
object_class->dispose = impl_dispose;
object_class->finalize = impl_finalize;
-
- epv->createControls = impl_createControls;
}
static void
@@ -349,7 +347,7 @@ calendar_component_peek (void)
component = g_object_new (calendar_component_get_type (), NULL);
if (e_mkdir_hier (calendar_component_peek_config_directory (component), 0777) != 0) {
- g_warning ("Cannot create directory %s: %s",
+ g_warning (G_STRLOC, ": Cannot create directory %s: %s",
calendar_component_peek_config_directory (component),
g_strerror (errno));
g_object_unref (component);
diff --git a/calendar/gui/main.c b/calendar/gui/main.c
index 681417f1df..73b3705b3c 100644
--- a/calendar/gui/main.c
+++ b/calendar/gui/main.c
@@ -47,12 +47,14 @@
#include "control-factory.h"
#include "itip-bonobo-control.h"
#include "tasks-control.h"
+#include "tasks-component.h"
#define FACTORY_ID "OAFIID:GNOME_Evolution_Calendar_Factory_2"
#define CALENDAR_COMPONENT_ID "OAFIID:GNOME_Evolution_Calendar_Component"
#define CALENDAR_CONTROL_ID "OAFIID:GNOME_Evolution_Calendar_Control"
+#define TASKS_COMPONENT_ID "OAFIID:GNOME_Evolution_Tasks_Component"
#define TASKS_CONTROL_ID "OAFIID:GNOME_Evolution_Tasks_Control"
#define ITIP_CONTROL_ID "OAFIID:GNOME_Evolution_Calendar_iTip_Control"
#define CONFIG_CONTROL_ID "OAFIID:GNOME_Evolution_Calendar_ConfigControl"
@@ -161,7 +163,11 @@ factory (BonoboGenericFactory *factory,
return object;
} else if (strcmp (component_id, CALENDAR_CONTROL_ID) == 0)
return BONOBO_OBJECT (control_factory_new_control ());
- else if (strcmp (component_id, TASKS_CONTROL_ID) == 0)
+ else if (strcmp (component_id, TASKS_COMPONENT_ID) == 0) {
+ BonoboObject *object = BONOBO_OBJECT (tasks_component_peek ());
+ bonobo_object_ref (object);
+ return object;
+ } else if (strcmp (component_id, TASKS_CONTROL_ID) == 0)
return BONOBO_OBJECT (tasks_control_new ());
else if (strcmp (component_id, ITIP_CONTROL_ID) == 0)
return BONOBO_OBJECT (itip_bonobo_control_new ());
diff --git a/calendar/gui/tasks-component.c b/calendar/gui/tasks-component.c
new file mode 100644
index 0000000000..5eca87f078
--- /dev/null
+++ b/calendar/gui/tasks-component.c
@@ -0,0 +1,347 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* tasks-component.c
+ *
+ * Copyright (C) 2003 Rodrigo Moya
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program 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 this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Rodrigo Moya <rodrigo@ximian.com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <string.h>
+#include <bonobo/bonobo-control.h>
+#include <bonobo/bonobo-i18n.h>
+#include <gconf/gconf-client.h>
+#include "cal-client/cal-client.h"
+#include "e-cal-model.h"
+#include "e-tasks.h"
+#include "tasks-component.h"
+#include "tasks-control.h"
+#include "widgets/misc/e-source-selector.h"
+
+#define PARENT_TYPE bonobo_object_get_type ()
+
+static BonoboObjectClass *parent_class = NULL;
+
+struct _TasksComponentPrivate {
+ char *config_directory;
+ GConfClient *gconf_client;
+ ESourceList *source_list;
+ GSList *source_selection;
+ GtkWidget *tasks;
+};
+
+/* Utility functions. */
+
+static void
+add_uri_for_source (ESource *source, ETasks *tasks)
+{
+ CalClient *client;
+ ECalModel *model;
+ GError *error = NULL;
+ char *uri = e_source_get_uri (source);
+
+ model = e_calendar_table_get_model (e_tasks_get_calendar_table (tasks));
+ client = e_cal_model_get_client_for_uri (model, uri);
+ if (!client) {
+ client = cal_client_new (uri, CALOBJ_TYPE_TODO);
+ if (cal_client_open (client, TRUE, &error)) {
+ e_cal_model_add_client (model, client);
+ } else {
+ g_warning (G_STRLOC ": Could not open tasks at %s: %s", uri, error->message);
+ g_error_free (error);
+ g_object_unref (client);
+ }
+ }
+
+ g_free (uri);
+}
+
+static void
+remove_uri_for_source (ESource *source, ETasks *tasks)
+{
+ CalClient *client;
+ ECalModel *model;
+ char *uri = e_source_get_uri (source);
+
+ model = e_calendar_table_get_model (e_tasks_get_calendar_table (tasks));
+ client = e_cal_model_get_client_for_uri (model, uri);
+ if (client)
+ e_cal_model_remove_client (model, client);
+
+ g_free (uri);
+}
+
+static gboolean
+is_in_selection (GSList *selection, ESource *source)
+{
+ GSList *l;
+
+ for (l = selection; l; l = l->next) {
+ ESource *selected_source = l->data;
+
+ if (!strcmp (e_source_peek_uid (selected_source), e_source_peek_uid (source)))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+update_uris_for_selection (ESourceSelector *selector, TasksComponent *component)
+{
+ TasksComponentPrivate *priv;
+ GSList *selection, *l;
+
+ selection = e_source_selector_get_selection (selector);
+
+ priv = component->priv;
+
+ for (l = priv->source_selection; l; l = l->next) {
+ ESource *old_selected_source = l->data;
+
+ if (!is_in_selection (selection, old_selected_source))
+ remove_uri_for_source (old_selected_source, priv->tasks);
+ }
+
+ for (l = selection; l; l = l->next) {
+ ESource *selected_source = l->data;
+
+ add_uri_for_source (selected_source, priv->tasks);
+ }
+
+ e_source_selector_free_selection (priv->source_selection);
+ priv->source_selection = selection;
+}
+
+/* Callbacks. */
+static void
+source_selection_changed_cb (ESourceSelector *selector, TasksComponent *component)
+{
+ update_uris_for_selection (selector, component);
+}
+
+static void
+primary_source_selection_changed_cb (ESourceSelector *selector, TasksComponent *component)
+{
+ TasksComponentPrivate *priv;
+ ESource *source;
+ CalClient *client;
+ char *uri;
+ ECalModel *model;
+
+ priv = component->priv;
+
+ source = e_source_selector_peek_primary_selection (selector);
+ if (!source)
+ return;
+
+ /* Set the default */
+ uri = e_source_get_uri (source);
+ model = e_calendar_table_get_model (e_tasks_get_calendar_table (E_TASKS (priv->tasks)));
+ client = e_cal_model_get_client_for_uri (model, uri);
+ if (client)
+ e_cal_model_set_default_client (model, client);
+
+ g_free (uri);
+
+}
+
+/* GObject methods */
+
+static void
+impl_dispose (GObject *object)
+{
+ TasksComponentPrivate *priv = TASKS_COMPONENT (object)->priv;
+
+ if (priv->source_list != NULL) {
+ g_object_unref (priv->source_list);
+ priv->source_list = NULL;
+ }
+
+ if (priv->source_selection != NULL) {
+ e_source_selector_free_selection (priv->source_selection);
+ priv->source_selection = NULL;
+ }
+
+ if (priv->gconf_client != NULL) {
+ g_object_unref (priv->gconf_client);
+ priv->gconf_client = NULL;
+ }
+
+ (* G_OBJECT_CLASS (parent_class)->dispose) (object);
+}
+
+static void
+impl_finalize (GObject *object)
+{
+ TasksComponentPrivate *priv = TASKS_COMPONENT (object)->priv;
+
+ g_free (priv->config_directory);
+ g_free (priv);
+
+ (* G_OBJECT_CLASS (parent_class)->finalize) (object);
+}
+
+/* Evolution::Component CORBA methods */
+
+static void
+control_activate_cb (BonoboControl *control, gboolean activate, gpointer data)
+{
+ ETasks *tasks = data;
+
+ if (activate)
+ tasks_control_activate (control, tasks);
+ else
+ tasks_control_deactivate (control, tasks);
+}
+
+static void
+impl_createControls (PortableServer_Servant servant,
+ Bonobo_Control *corba_sidebar_control,
+ Bonobo_Control *corba_view_control,
+ CORBA_Environment *ev)
+{
+ TasksComponent *component = TASKS_COMPONENT (bonobo_object_from_servant (servant));
+ TasksComponentPrivate *priv;
+ GtkWidget *selector;
+ GtkWidget *selector_scrolled_window;
+ BonoboControl *sidebar_control, *view_control;
+
+ priv = component->priv;
+
+ /* create sidebar selector */
+ selector = e_source_selector_new (priv->source_list);
+ gtk_widget_show (selector);
+
+ selector_scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+ gtk_container_add (GTK_CONTAINER (selector_scrolled_window), selector);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (selector_scrolled_window),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (selector_scrolled_window),
+ GTK_SHADOW_IN);
+ gtk_widget_show (selector_scrolled_window);
+
+ sidebar_control = bonobo_control_new (selector_scrolled_window);
+
+ /* create the tasks view */
+ view_control = tasks_control_new ();
+ priv->tasks = bonobo_control_get_widget (view_control);
+ g_signal_connect (view_control, "activate", G_CALLBACK (control_activate_cb), priv->tasks);
+
+ g_signal_connect_object (selector, "selection_changed",
+ G_CALLBACK (source_selection_changed_cb),
+ G_OBJECT (component), 0);
+ g_signal_connect_object (selector, "primary_selection_changed",
+ G_CALLBACK (primary_source_selection_changed_cb),
+ G_OBJECT (component), 0);
+
+ update_uris_for_selection (E_SOURCE_SELECTOR (selector), component);
+
+ *corba_sidebar_control = CORBA_Object_duplicate (BONOBO_OBJREF (sidebar_control), ev);
+ *corba_view_control = CORBA_Object_duplicate (BONOBO_OBJREF (view_control), ev);
+}
+
+/* Initialization */
+
+static void
+tasks_component_class_init (TasksComponentClass *klass)
+{
+ POA_GNOME_Evolution_Component__epv *epv = &klass->epv;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ epv->createControls = impl_createControls;
+
+ object_class->dispose = impl_dispose;
+ object_class->finalize = impl_finalize;
+}
+
+static void
+tasks_component_init (TasksComponent *component, TasksComponentClass *klass)
+{
+ TasksComponentPrivate *priv;
+ GSList *groups;
+
+ priv = g_new0 (TasksComponentPrivate, 1);
+ priv->config_directory = g_build_filename (g_get_home_dir (),
+ ".evolution", "tasks", "config",
+ NULL);
+
+ /* load the groups from the configuration */
+ priv->gconf_client = gconf_client_get_default ();
+ priv->source_list = e_source_list_new_for_gconf (priv->gconf_client,
+ "/apps/evolution/tasks/sources");
+
+ /* create default tasks folders if there are no groups */
+ groups = e_source_list_peek_groups (priv->source_list);
+ if (!groups) {
+ ESourceGroup *group;
+ ESource *source;
+ char *base_uri, *new_dir;
+
+ /* create the source group */
+ base_uri = g_build_filename (g_get_home_dir (),
+ ".evolution/tasks/local/OnThisComputer/",
+ NULL);
+ group = e_source_group_new (_("On This Computer"), base_uri);
+ e_source_list_add_group (priv->source_list, group, -1);
+
+ /* FIXME: migrate tasks from older setups */
+ new_dir = g_build_filename (base_uri, "Personal/", NULL);
+ if (!e_mkdir_hier (new_dir, 0700)) {
+ source = e_source_new (_("Personal"), "Personal");
+ e_source_group_add_source (group, source, -1);
+ }
+
+ g_free (new_dir);
+ g_free (base_uri);
+ }
+}
+
+/* Public API */
+
+TasksComponent *
+tasks_component_peek (void)
+{
+ static TasksComponent *component = NULL;
+
+ if (component == NULL) {
+ component = g_object_new (tasks_component_get_type (), NULL);
+
+ if (e_mkdir_hier (component->priv->config_directory, 0777) != 0) {
+ g_warning (G_STRLOC ": Cannot create directory %s: %s",
+ component->priv->config_directory, g_strerror (errno));
+ g_object_unref (component);
+ component = NULL;
+ }
+ }
+
+ return component;
+}
+
+const char *
+tasks_component_peek_config_directory (TasksComponent *component)
+{
+ return (const char *) component->priv->config_directory;
+}
+
+BONOBO_TYPE_FUNC_FULL (TasksComponent, GNOME_Evolution_Component, PARENT_TYPE, tasks_component)
diff --git a/calendar/gui/tasks-component.h b/calendar/gui/tasks-component.h
new file mode 100644
index 0000000000..8fa94d4469
--- /dev/null
+++ b/calendar/gui/tasks-component.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* tasks-component.h
+ *
+ * Copyright (C) 2003 Rodrigo Moya
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program 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 this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Rodrigo Moya <rodrigo@ximian.com>
+ */
+
+#ifndef _TASKS_COMPONENT_H_
+#define _TASKS_COMPONENT_H_
+
+#include <bonobo/bonobo-object.h>
+#include "Evolution.h"
+#include "e-util/e-source-list.h"
+
+
+#define TASKS_TYPE_COMPONENT (tasks_component_get_type ())
+#define TASKS_COMPONENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TASKS_TYPE_COMPONENT, TasksComponent))
+#define TASKS_COMPONENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TASKS_TYPE_COMPONENT, TasksComponentClass))
+#define TASKS_IS_COMPONENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TASKS_TYPE_COMPONENT))
+#define TASKS_IS_COMPONENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), TASKS_TYPE_COMPONENT))
+
+
+typedef struct _TasksComponent TasksComponent;
+typedef struct _TasksComponentPrivate TasksComponentPrivate;
+typedef struct _TasksComponentClass TasksComponentClass;
+
+struct _TasksComponent {
+ BonoboObject parent;
+
+ TasksComponentPrivate *priv;
+};
+
+struct _TasksComponentClass {
+ BonoboObjectClass parent_class;
+
+ POA_GNOME_Evolution_Component__epv epv;
+};
+
+
+GType tasks_component_get_type (void);
+TasksComponent *tasks_component_peek (void);
+const char *tasks_component_peek_config_directory (TasksComponent *component);
+ESourceList *tasks_component_peek_source_list (TasksComponent *component);
+
+#endif /* _TASKS_COMPONENT_H_ */
diff --git a/calendar/gui/tasks-control.c b/calendar/gui/tasks-control.c
index d97ed2d585..e0482b2d77 100644
--- a/calendar/gui/tasks-control.c
+++ b/calendar/gui/tasks-control.c
@@ -70,11 +70,6 @@ static void tasks_control_set_property (BonoboPropertyBag *bag,
static void tasks_control_activate_cb (BonoboControl *control,
gboolean activate,
gpointer user_data);
-static void tasks_control_activate (BonoboControl *control,
- ETasks *tasks);
-static void tasks_control_deactivate (BonoboControl *control,
- ETasks *tasks);
-
static void tasks_control_new_task_cmd (BonoboUIComponent *uic,
gpointer data,
const char *path);
@@ -287,7 +282,7 @@ static BonoboUIVerb verbs [] = {
BONOBO_UI_VERB_END
};
-static void
+void
tasks_control_activate (BonoboControl *control, ETasks *tasks)
{
Bonobo_UIContainer remote_uih;
@@ -339,7 +334,7 @@ tasks_control_activate (BonoboControl *control, ETasks *tasks)
}
-static void
+void
tasks_control_deactivate (BonoboControl *control, ETasks *tasks)
{
BonoboUIComponent *uic = bonobo_control_get_ui_component (control);
diff --git a/calendar/gui/tasks-control.h b/calendar/gui/tasks-control.h
index c74b6d220b..eca68c3f0a 100644
--- a/calendar/gui/tasks-control.h
+++ b/calendar/gui/tasks-control.h
@@ -24,8 +24,11 @@
#ifndef _TASKS_CONTROL_H_
#define _TASKS_CONTROL_H_
+#include "e-tasks.h"
-BonoboControl *tasks_control_new (void);
+BonoboControl *tasks_control_new (void);
+void tasks_control_activate (BonoboControl *control, ETasks *tasks);
+void tasks_control_deactivate (BonoboControl *control, ETasks *tasks);
#endif /* _TASKS_CONTROL_H_ */