/* list my signals */
enum {
QUEUE_CHANGED_SIGNAL,
+ QUEUE_EMPTY_SIGNAL,
NUM_SIGNALS
};
NULL, NULL,
modest_marshal_VOID__POINTER_INT,
G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_INT);
+
+ /**
+ * ModestMailOperationQueue::queue-empty
+ * @self: the #ModestMailOperationQueue that emits the signal
+ * @user_data: user data set when the signal handler was connected
+ *
+ * Issued whenever the queue is empty
+ */
+ signals[QUEUE_EMPTY_SIGNAL] =
+ g_signal_new ("queue-empty",
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (ModestMailOperationQueueClass, queue_empty),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
}
static void
* until the signal emission is complete. armin. */
/* modest_runtime_verify_object_last_ref (mail_op, ""); */
g_object_unref (G_OBJECT (mail_op));
+
+ /* Emit the queue empty-signal */
+ g_signal_emit (self, signals[QUEUE_EMPTY_SIGNAL], 0);
}
guint
void (*queue_changed) (ModestMailOperationQueue *self,
ModestMailOperation *mail_op,
ModestMailOperationQueueNotification type);
+
+ void (*queue_empty) (ModestMailOperationQueue *self);
};
/* member functions */
#include <widgets/modest-main-window.h>
#include <string.h>
+static gboolean
+on_idle_exit_modest (gpointer data)
+{
+ /* Protect the Gtk calls */
+ gdk_threads_enter ();
+
+ /* Wait for remaining tasks */
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
+ gtk_main_quit ();
+
+ gdk_threads_leave ();
+
+ return FALSE;
+}
+
+static void
+on_queue_empty (ModestMailOperationQueue *queue,
+ gpointer user_data)
+{
+ ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
+
+ /* Exit if the queue is empty and there are no more windows */
+ if (modest_window_mgr_num_windows (mgr) == 0)
+ g_idle_add_full (G_PRIORITY_LOW, on_idle_exit_modest, NULL, NULL);
+}
+
+static void
+on_window_list_empty (ModestWindowMgr *window_mgr,
+ gpointer user_data)
+{
+ ModestMailOperationQueue *queue = modest_runtime_get_mail_operation_queue ();
+
+ /* Exit if there are no more windows and the queue is empty */
+ if (modest_mail_operation_queue_num_elements (queue) == 0)
+ g_idle_add_full (G_PRIORITY_LOW, on_idle_exit_modest, NULL, NULL);
+}
+
int
main (int argc, char *argv[])
{
* be called. But that's annoying when starting from the
* command line.: */
gboolean show_ui_without_top_application_method = FALSE;
-
- ModestWindow *main_win;
int retval = 0;
if (argc >= 2) {
goto cleanup;
}
- /* this will create & register the window */
- main_win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(), TRUE);
- if (!main_win) {
- g_printerr ("modest: failed to get main window instance\n");
- retval = 1;
- goto cleanup;
- }
-
+ /* Connect to the queue-emtpy signal */
+ g_signal_connect (modest_runtime_get_mail_operation_queue (),
+ "queue-empty",
+ G_CALLBACK (on_queue_empty),
+ NULL);
+
+ g_signal_connect (modest_runtime_get_window_mgr (),
+ "window-list-empty",
+ G_CALLBACK (on_window_list_empty),
+ NULL);
+
/* Usually, we only show the UI when we get the "top_application" D-Bus method.
* This allows modest to start via D-Bus activation to provide a service,
* without showing the UI.
* when we receive the "top_application" D-Bus method.
*/
if (show_ui_without_top_application_method) {
+ ModestWindow *main_win;
+
+ /* this will create & register the window */
+ main_win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
+ TRUE);
+ if (!main_win) {
+ g_printerr ("modest: failed to get main window instance\n");
+ retval = 1;
+ goto cleanup;
+ }
+
gtk_widget_show_all (GTK_WIDGET(main_win));
/* Remove new mail notifications if exist */
/* list my signals */
enum {
- /* MY_SIGNAL_1, */
- /* MY_SIGNAL_2, */
- LAST_SIGNAL
+ WINDOW_LIST_EMPTY_SIGNAL,
+ NUM_SIGNALS
};
typedef struct _ModestWindowMgrPrivate ModestWindowMgrPrivate;
static GObjectClass *parent_class = NULL;
/* uncomment the following if you have defined any signals */
-/* static guint signals[LAST_SIGNAL] = {0}; */
+static guint signals[NUM_SIGNALS] = {0};
GType
modest_window_mgr_get_type (void)
gobject_class->finalize = modest_window_mgr_finalize;
g_type_class_add_private (gobject_class, sizeof(ModestWindowMgrPrivate));
+
+
+ /**
+ * ModestWindowMgr::window-list-empty
+ * @self: the #ModestWindowMgr that emits the signal
+ * @user_data: user data set when the signal handler was connected
+ *
+ * Issued whenever the window list becomes empty
+ */
+ signals[WINDOW_LIST_EMPTY_SIGNAL] =
+ g_signal_new ("window-list-empty",
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (ModestWindowMgrClass, window_list_empty),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
}
static void
g_signal_handler_disconnect (G_OBJECT (key), handler_id);
}
-
-
-/* interval before retrying to close the application */
-#define CLOSING_RETRY_INTERVAL 3000
-/* interval before cancel whatever is left in the queue, and closing anyway */
-#define MAX_WAIT_FOR_CLOSING 30 * 1000
-
-static gboolean
-on_quit_maybe (ModestWindowMgr *self)
-{
- ModestWindowMgrPrivate *priv;
- guint queue_num;
-
- priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
-
- /* it seems, in the meantime some windows were
- * created. in that case, stop 'on_quit_maybe' */
- if (priv->window_list) {
- priv->closing_time = 0;
- return FALSE;
- }
-
- if (priv->closing_time >= MAX_WAIT_FOR_CLOSING) {
- /* we waited long enough: cancel all remaining operations */
- g_debug ("%s: we waited long enough (%ds), cancelling queue and quiting",
- __FUNCTION__, priv->closing_time/1000);
- /* FIXME: below gives me a lot of:
- * GLIB CRITICAL ** default - modest_mail_operation_cancel:
- * assertion `priv->account' failed
- * which means there is no account for the given operation
- * so, we're not trying to be nice, we're just quiting.
- */
- //modest_mail_operation_queue_cancel_all
- // (modest_runtime_get_mail_operation_queue());
- } else {
-
- /* if there is anything left in our operation queue,
- * wait another round
- */
- queue_num = modest_mail_operation_queue_num_elements
- (modest_runtime_get_mail_operation_queue());
- if (queue_num > 0) {
- g_debug ("%s: waiting, there are still %d operation(s) queued",
- __FUNCTION__, queue_num);
- priv->closing_time += CLOSING_RETRY_INTERVAL;
- return TRUE;
- }
- }
-
- /* so: no windows left, nothing in the queue: quit */
- priv->closing_time = 0;
- gtk_main_quit ();
- return FALSE;
-}
-
-
void
modest_window_mgr_unregister_window (ModestWindowMgr *self,
ModestWindow *window)
/* Destroy the window */
gtk_widget_destroy (win->data);
- /* If there are no more windows registered then exit program */
+ /* If there are no more windows registered emit the signal */
if (priv->window_list == NULL)
- g_timeout_add (CLOSING_RETRY_INTERVAL,
- (GSourceFunc)on_quit_maybe, self);
+ g_signal_emit (self, signals[WINDOW_LIST_EMPTY_SIGNAL], 0);
}
remove_modal_from_queue (GTK_WIDGET (dialog), self);
}
+gint
+modest_window_mgr_num_windows (ModestWindowMgr *self)
+{
+ ModestWindowMgrPrivate *priv = MODEST_WINDOW_MGR_GET_PRIVATE(self);
+ gint num_windows = 0;
+
+ if (priv->window_list)
+ num_windows = g_list_length (priv->window_list);
+
+ return num_windows;
+}
struct _ModestWindowMgrClass {
GObjectClass parent_class;
+
+ /* Signals */
+ void (*window_list_empty) (ModestWindowMgr *self);
};
* application hibernation.
**/
void modest_window_mgr_save_state_for_all_windows (ModestWindowMgr *self);
+
+/**
+ * modest_window_mgr_num_windows:
+ * @self: a #ModestWindowMgr
+ *
+ * Gets the number of already registered windows
+ *
+ * Returns: the number of already registered windows
+ **/
+gint modest_window_mgr_num_windows (ModestWindowMgr *self);
G_END_DECLS