aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui/widgets
diff options
context:
space:
mode:
authorChris Toshok <toshok@ximian.com>2001-05-18 07:30:57 +0800
committerChris Toshok <toshok@src.gnome.org>2001-05-18 07:30:57 +0800
commitbb0671f820227cd6759c5b77e678c87ff24af99a (patch)
tree3a00d31e02aaf352a35807d19f4276959bbe4111 /addressbook/gui/widgets
parente435c042d08e5b3a46889bd7fafd1ef0f28bc734 (diff)
downloadgsoc2013-evolution-bb0671f820227cd6759c5b77e678c87ff24af99a.tar
gsoc2013-evolution-bb0671f820227cd6759c5b77e678c87ff24af99a.tar.gz
gsoc2013-evolution-bb0671f820227cd6759c5b77e678c87ff24af99a.tar.bz2
gsoc2013-evolution-bb0671f820227cd6759c5b77e678c87ff24af99a.tar.lz
gsoc2013-evolution-bb0671f820227cd6759c5b77e678c87ff24af99a.tar.xz
gsoc2013-evolution-bb0671f820227cd6759c5b77e678c87ff24af99a.tar.zst
gsoc2013-evolution-bb0671f820227cd6759c5b77e678c87ff24af99a.zip
add our selection_change signal. (e_minicard_view_widget_realize): connect
2001-05-17 Chris Toshok <toshok@ximian.com> * gui/widgets/e-minicard-view-widget.c (e_minicard_view_widget_class_init): add our selection_change signal. (e_minicard_view_widget_realize): connect to the ESelectionModel's selection_changed signal. (e_minicard_view_widget_selected_count): new function. (selection_change): new function - emit our "selection_change" signal. * gui/widgets/e-minicard-view-widget.h (struct _EMinicardViewWidgetClass): add selection_change signal. also, add prototype for e_minicard_view_widget_selected_count. * gui/widgets/e-addressbook-view.c (e_addressbook_view_class_init): add our command_state_change signal. (e_addressbook_view_init): connect to the writable_status signal on the EAddressbookModel. (minicard_selection_change): new function - calls command_state_change. (create_minicard_view): connect to selection_change on the minicard_view so we know when to update command state. (table_selection_change): new function - calls command_state_change. (writable_status): new function - calls command_state_change. (command_state_change): new function - emits our "command_state_change" signal. (create_table_view): connect to the selection_change signal so we know to update the command state. (change_view_type): update the command state every time we change view types. (e_addressbook_view_can_create): new function. (e_addressbook_view_can_print): new function. (e_addressbook_view_can_delete): new function. (e_addressbook_view_can_stop): new function. * gui/widgets/e-addressbook-view.h (struct _EAddressbookViewClass): add command_state_change signal, and prototypes of functions the component can use to test the state of commands. * gui/widgets/e-addressbook-model.c (addressbook_destroy): unlink the writable_status signal on the EBook. (writable_status): new function. (e_addressbook_model_class_init): add our writable_status signal. (e_addressbook_model_init): init writable_status_id. (e_addressbook_model_set_arg): unlink the writable_status signal on the old EBook, and connect it on the new one. * gui/widgets/e-addressbook-model.h: add writable_status signal. * gui/component/addressbook.c (update_command_state): new function, set the sensitivity of the bonobo commands. (control_activate): update our command state immediately upon activating the control. (addressbook_factory_new_control): register command_state_change to update the commands. svn path=/trunk/; revision=9874
Diffstat (limited to 'addressbook/gui/widgets')
-rw-r--r--addressbook/gui/widgets/e-addressbook-model.c43
-rw-r--r--addressbook/gui/widgets/e-addressbook-model.h13
-rw-r--r--addressbook/gui/widgets/e-addressbook-view.c91
-rw-r--r--addressbook/gui/widgets/e-addressbook-view.h6
-rw-r--r--addressbook/gui/widgets/e-minicard-view-widget.c39
-rw-r--r--addressbook/gui/widgets/e-minicard-view-widget.h2
6 files changed, 186 insertions, 8 deletions
diff --git a/addressbook/gui/widgets/e-addressbook-model.c b/addressbook/gui/widgets/e-addressbook-model.c
index 60da28f6be..fbc67d6ed6 100644
--- a/addressbook/gui/widgets/e-addressbook-model.c
+++ b/addressbook/gui/widgets/e-addressbook-model.c
@@ -33,6 +33,7 @@ enum {
};
enum {
+ WRITABLE_STATUS,
STATUS_MESSAGE,
CARD_ADDED,
CARD_REMOVED,
@@ -83,8 +84,15 @@ addressbook_destroy(GtkObject *object)
remove_book_view(model);
- if (model->book)
+ if (model->book) {
+ if (model->writable_status_id)
+ gtk_signal_disconnect(GTK_OBJECT (model->book),
+ model->writable_status_id);
+
+ model->writable_status_id = 0;
+
gtk_object_unref(GTK_OBJECT(model->book));
+ }
for ( i = 0; i < model->data_count; i++ ) {
gtk_object_unref(GTK_OBJECT(model->data[i]));
@@ -166,6 +174,18 @@ status_message (EBookView *book_view,
}
static void
+writable_status (EBook *book,
+ gboolean writable,
+ EAddressbookModel *model)
+{
+ model->editable = writable;
+
+ gtk_signal_emit (GTK_OBJECT (model),
+ e_addressbook_model_signals [WRITABLE_STATUS],
+ writable);
+}
+
+static void
e_addressbook_model_class_init (GtkObjectClass *object_class)
{
parent_class = gtk_type_class (PARENT_TYPE);
@@ -181,6 +201,14 @@ e_addressbook_model_class_init (GtkObjectClass *object_class)
gtk_object_add_arg_type ("EAddressbookModel::editable", GTK_TYPE_BOOL,
GTK_ARG_READWRITE, ARG_EDITABLE);
+ e_addressbook_model_signals [WRITABLE_STATUS] =
+ gtk_signal_new ("writable_status",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (EAddressbookModelClass, writable_status),
+ gtk_marshal_NONE__BOOL,
+ GTK_TYPE_NONE, 1, GTK_TYPE_BOOL);
+
e_addressbook_model_signals [STATUS_MESSAGE] =
gtk_signal_new ("status_message",
GTK_RUN_LAST,
@@ -236,6 +264,7 @@ e_addressbook_model_init (GtkObject *object)
model->remove_card_id = 0;
model->modify_card_id = 0;
model->status_message_id = 0;
+ model->writable_status_id = 0;
model->data = NULL;
model->data_count = 0;
model->allocated_count = 0;
@@ -323,13 +352,23 @@ e_addressbook_model_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
switch (arg_id){
case ARG_BOOK:
- if (model->book)
+ if (model->book) {
+ if (model->writable_status_id)
+ gtk_signal_disconnect(GTK_OBJECT (model->book),
+ model->writable_status_id);
+
+ model->writable_status_id = 0;
+
gtk_object_unref(GTK_OBJECT(model->book));
+ }
model->book = E_BOOK(GTK_VALUE_OBJECT (*arg));
if (model->book) {
gtk_object_ref(GTK_OBJECT(model->book));
if (model->get_view_idle == 0)
model->get_view_idle = g_idle_add((GSourceFunc)get_view, model);
+ gtk_signal_connect (GTK_OBJECT(model->book),
+ "writable_status",
+ writable_status, model);
}
break;
case ARG_QUERY:
diff --git a/addressbook/gui/widgets/e-addressbook-model.h b/addressbook/gui/widgets/e-addressbook-model.h
index f8fd01b535..5443e2dbfb 100644
--- a/addressbook/gui/widgets/e-addressbook-model.h
+++ b/addressbook/gui/widgets/e-addressbook-model.h
@@ -29,7 +29,7 @@ struct _EAddressbookModel {
int data_count;
int allocated_count;
- int create_card_id, remove_card_id, modify_card_id, status_message_id;
+ int create_card_id, remove_card_id, modify_card_id, status_message_id, writable_status_id;
guint editable : 1;
guint first_get_view : 1;
@@ -42,11 +42,12 @@ struct _EAddressbookModelClass {
/*
* Signals
*/
- void (*status_message) (EAddressbookModel *model, const gchar *message);
- void (*card_added) (EAddressbookModel *model, gint index, gint count);
- void (*card_removed) (EAddressbookModel *model, gint index);
- void (*card_changed) (EAddressbookModel *model, gint index);
- void (*model_changed) (EAddressbookModel *model);
+ void (*writable_status) (EAddressbookModel *model, gboolean writable);
+ void (*status_message) (EAddressbookModel *model, const gchar *message);
+ void (*card_added) (EAddressbookModel *model, gint index, gint count);
+ void (*card_removed) (EAddressbookModel *model, gint index);
+ void (*card_changed) (EAddressbookModel *model, gint index);
+ void (*model_changed) (EAddressbookModel *model);
};
diff --git a/addressbook/gui/widgets/e-addressbook-view.c b/addressbook/gui/widgets/e-addressbook-view.c
index 352d1b4b62..2cc1acd7e4 100644
--- a/addressbook/gui/widgets/e-addressbook-view.c
+++ b/addressbook/gui/widgets/e-addressbook-view.c
@@ -62,6 +62,8 @@ static void e_addressbook_view_destroy (GtkObject *object);
static void change_view_type (EAddressbookView *view, EAddressbookViewType view_type);
static void status_message (GtkObject *object, const gchar *status, EAddressbookView *eav);
+static void writable_status (GtkObject *object, gboolean writable, EAddressbookView *eav);
+static void command_state_change (EAddressbookView *eav);
static GtkTableClass *parent_class = NULL;
@@ -75,6 +77,7 @@ enum {
enum {
STATUS_MESSAGE,
+ COMMAND_STATE_CHANGE,
LAST_SIGNAL
};
@@ -141,6 +144,14 @@ e_addressbook_view_class_init (EAddressbookViewClass *klass)
gtk_marshal_NONE__POINTER,
GTK_TYPE_NONE, 1, GTK_TYPE_POINTER);
+ e_addressbook_view_signals [COMMAND_STATE_CHANGE] =
+ gtk_signal_new ("command_state_change",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (EAddressbookViewClass, command_state_change),
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE, 0);
+
gtk_object_class_add_signals (object_class, e_addressbook_view_signals, LAST_SIGNAL);
}
@@ -156,6 +167,11 @@ e_addressbook_view_init (EAddressbookView *eav)
GTK_SIGNAL_FUNC (status_message),
eav);
+ gtk_signal_connect (GTK_OBJECT(eav->model),
+ "writable_status",
+ GTK_SIGNAL_FUNC (writable_status),
+ eav);
+
eav->editable = FALSE;
eav->book = NULL;
eav->query = g_strdup("(contains \"x-evolution-any-field\" \"\")");
@@ -321,6 +337,12 @@ create_alphabet (EAddressbookView *view)
}
static void
+minicard_selection_change (EMinicardViewWidget *widget, EAddressbookView *view)
+{
+ command_state_change (view);
+}
+
+static void
create_minicard_view (EAddressbookView *view)
{
GtkWidget *scrollframe;
@@ -337,6 +359,10 @@ create_minicard_view (EAddressbookView *view)
adapter = E_ADDRESSBOOK_REFLOW_ADAPTER(e_addressbook_reflow_adapter_new (view->model));
minicard_view = e_minicard_view_widget_new(adapter);
+ gtk_signal_connect(GTK_OBJECT(minicard_view), "selection_change",
+ GTK_SIGNAL_FUNC(minicard_selection_change), view);
+
+
view->object = GTK_OBJECT(minicard_view);
view->widget = minicard_hbox;
@@ -609,6 +635,12 @@ table_right_click(ETableScrolled *table, gint row, gint col, GdkEvent *event, EA
}
static void
+table_selection_change(ETableScrolled *table, EAddressbookView *view)
+{
+ command_state_change (view);
+}
+
+static void
table_drag_data_get (ETable *table,
int row,
int col,
@@ -648,6 +680,19 @@ status_message (GtkObject *object, const gchar *status, EAddressbookView *eav)
status);
}
+static void
+writable_status (GtkObject *object, gboolean writable, EAddressbookView *eav)
+{
+ command_state_change (eav);
+}
+
+static void
+command_state_change (EAddressbookView *eav)
+{
+ gtk_signal_emit (GTK_OBJECT (eav),
+ e_addressbook_view_signals [COMMAND_STATE_CHANGE]);
+}
+
#ifdef JUST_FOR_TRANSLATORS
static char *list [] = {
N_("* Click here to add a contact *"),
@@ -769,6 +814,8 @@ create_table_view (EAddressbookView *view)
GTK_SIGNAL_FUNC(table_double_click), view);
gtk_signal_connect(GTK_OBJECT(e_table_scrolled_get_table(E_TABLE_SCROLLED(table))), "right_click",
GTK_SIGNAL_FUNC(table_right_click), view);
+ gtk_signal_connect(GTK_OBJECT(e_table_scrolled_get_table(E_TABLE_SCROLLED(table))), "selection_change",
+ GTK_SIGNAL_FUNC(table_selection_change), view);
/* drag & drop signals */
e_table_drag_source_set (E_TABLE(E_TABLE_SCROLLED(table)->table), GDK_BUTTON1_MASK,
@@ -816,6 +863,8 @@ change_view_type (EAddressbookView *view, EAddressbookViewType view_type)
}
view->view_type = view_type;
+
+ command_state_change (view);
}
static void
@@ -1009,3 +1058,45 @@ e_addressbook_view_stop(EAddressbookView *view)
{
e_addressbook_model_stop (view->model);
}
+
+gboolean
+e_addressbook_view_can_create (EAddressbookView *view)
+{
+ return e_addressbook_model_editable (view->model);
+}
+
+gboolean
+e_addressbook_view_can_print (EAddressbookView *view)
+{
+ switch (view->view_type) {
+ case E_ADDRESSBOOK_VIEW_TABLE:
+ return e_table_selected_count (E_TABLE_SCROLLED(view->widget)->table) != 0;
+ case E_ADDRESSBOOK_VIEW_MINICARD:
+ return e_minicard_view_widget_selected_count (E_MINICARD_VIEW_WIDGET (view->object)) != 0;
+ default:
+ return FALSE;
+ }
+}
+
+gboolean
+e_addressbook_view_can_delete (EAddressbookView *view)
+{
+ if (!e_addressbook_model_editable (view->model))
+ return FALSE;
+
+ switch (view->view_type) {
+ case E_ADDRESSBOOK_VIEW_TABLE:
+ return e_table_selected_count (E_TABLE_SCROLLED(view->widget)->table) != 0;
+ case E_ADDRESSBOOK_VIEW_MINICARD:
+ return e_minicard_view_widget_selected_count (E_MINICARD_VIEW_WIDGET (view->object)) != 0;
+ default:
+ return FALSE;
+ }
+}
+
+gboolean
+e_addressbook_view_can_stop (EAddressbookView *view)
+{
+ return FALSE;
+}
+
diff --git a/addressbook/gui/widgets/e-addressbook-view.h b/addressbook/gui/widgets/e-addressbook-view.h
index 30633c57fe..19c83474fe 100644
--- a/addressbook/gui/widgets/e-addressbook-view.h
+++ b/addressbook/gui/widgets/e-addressbook-view.h
@@ -82,6 +82,7 @@ struct _EAddressbookViewClass
* Signals
*/
void (*status_message) (EAddressbookView *view, const gchar *message);
+ void (*command_state_change) (EAddressbookView *view);
};
GtkWidget *e_addressbook_view_new (void);
@@ -95,6 +96,11 @@ void e_addressbook_view_delete_selection (EAddressbookView *view);
void e_addressbook_view_show_all (EAddressbookView *view);
void e_addressbook_view_stop (EAddressbookView *view);
+gboolean e_addressbook_view_can_create (EAddressbookView *view);
+gboolean e_addressbook_view_can_print (EAddressbookView *view);
+gboolean e_addressbook_view_can_delete (EAddressbookView *view);
+gboolean e_addressbook_view_can_stop (EAddressbookView *view);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/addressbook/gui/widgets/e-minicard-view-widget.c b/addressbook/gui/widgets/e-minicard-view-widget.c
index 8944f2118c..576f8b3aab 100644
--- a/addressbook/gui/widgets/e-minicard-view-widget.c
+++ b/addressbook/gui/widgets/e-minicard-view-widget.c
@@ -37,6 +37,8 @@ static void e_minicard_view_widget_reflow (ECanvas *canvas);
static void e_minicard_view_widget_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
static void e_minicard_view_widget_realize (GtkWidget *widget);
+static void selection_change (ESelectionModel *esm, EMinicardViewWidget *widget);
+
static ECanvasClass *parent_class = NULL;
/* The arguments we take */
@@ -47,6 +49,13 @@ enum {
ARG_EDITABLE
};
+enum {
+ SELECTION_CHANGE,
+ LAST_SIGNAL
+};
+
+static guint e_minicard_view_widget_signals [LAST_SIGNAL] = {0, };
+
GtkType
e_minicard_view_widget_get_type (void)
{
@@ -92,6 +101,16 @@ e_minicard_view_widget_class_init (EMinicardViewWidgetClass *klass)
gtk_object_add_arg_type ("EMinicardViewWidget::editable", GTK_TYPE_BOOL,
GTK_ARG_READWRITE, ARG_EDITABLE);
+ e_minicard_view_widget_signals [SELECTION_CHANGE] =
+ gtk_signal_new ("selection_change",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (EMinicardViewWidgetClass, selection_change),
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE, 0);
+
+ gtk_object_class_add_signals (object_class, e_minicard_view_widget_signals, LAST_SIGNAL);
+
object_class->set_arg = e_minicard_view_widget_set_arg;
object_class->get_arg = e_minicard_view_widget_get_arg;
object_class->destroy = e_minicard_view_widget_destroy;
@@ -223,6 +242,10 @@ e_minicard_view_widget_realize (GtkWidget *widget)
"adapter", view->adapter,
NULL);
+ gtk_signal_connect (GTK_OBJECT (E_REFLOW(view->emv)->selection),
+ "selection_changed",
+ selection_change, view);
+
if (GTK_WIDGET_CLASS(parent_class)->realize)
GTK_WIDGET_CLASS(parent_class)->realize (widget);
}
@@ -275,6 +298,22 @@ e_minicard_view_widget_reflow(ECanvas *canvas)
NULL );
}
+static void
+selection_change (ESelectionModel *esm, EMinicardViewWidget *widget)
+{
+ gtk_signal_emit (GTK_OBJECT(widget),
+ e_minicard_view_widget_signals [SELECTION_CHANGE], widget);
+}
+
+gint
+e_minicard_view_widget_selected_count (EMinicardViewWidget *view)
+{
+ if (!view->emv)
+ return 0;
+ else
+ return e_selection_model_selected_count (E_REFLOW (view->emv)->selection);
+}
+
void
e_minicard_view_widget_remove_selection(EMinicardViewWidget *view,
EBookCallback cb,
diff --git a/addressbook/gui/widgets/e-minicard-view-widget.h b/addressbook/gui/widgets/e-minicard-view-widget.h
index db37d1631a..22156e2588 100644
--- a/addressbook/gui/widgets/e-minicard-view-widget.h
+++ b/addressbook/gui/widgets/e-minicard-view-widget.h
@@ -57,9 +57,11 @@ struct _EMinicardViewWidget
struct _EMinicardViewWidgetClass
{
ECanvasClass parent_class;
+ void (*selection_change) (EMinicardViewWidget*);
};
GtkType e_minicard_view_widget_get_type (void);
+gint e_minicard_view_widget_selected_count (EMinicardViewWidget *view);
void e_minicard_view_widget_remove_selection (EMinicardViewWidget *view,
EBookCallback cb,
gpointer closure);