00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "include/alarm_event.h"
00023 #include "rpc-systemui.h"
00024 #include "rpc-dbus.h"
00025 #include "rpc-ic.h"
00026 #include "rpc-mce.h"
00027 #include "actiondialog.h"
00028 #include "event.h"
00029 #include "debug.h"
00030
00031 #define STATUSBAR_SERVICE "com.nokia.statusbar"
00032
00033 static void alarmd_action_dialog_init(AlarmdActionDialog *action_dialog);
00034 static void alarmd_action_dialog_class_init(AlarmdActionDialogClass *klass);
00035 static void _alarmd_action_dialog_set_property(GObject *object,
00036 guint param_id,
00037 const GValue *value,
00038 GParamSpec *pspec);
00039 static void _alarmd_action_dialog_get_property(GObject *object,
00040 guint param_id,
00041 GValue *value,
00042 GParamSpec *pspec);
00043 static void _alarmd_action_dialog_run(AlarmdAction *action, gboolean delayed);
00044 static void _alarmd_action_dialog_real_run(gpointer action, gboolean snoozed);
00045 static void _alarmd_action_dialog_delayed_run(gpointer action);
00046 static void _alarmd_action_dialog_finalize(GObject *object);
00047 static GSList *_alarmd_action_dialog_get_saved_properties(void);
00048 static void _alarmd_action_dialog_real_do_action(AlarmdActionDialog *dialog);
00049 static void _alarmd_action_dialog_snooze_powerup(gpointer user_data, gboolean power_up);
00050 static void _alarmd_action_dialog_powerup(gpointer user_data, gboolean power_up);
00051 static void _alarmd_action_dialog_connected(gpointer act);
00052
00053 enum properties {
00054 PROP_TITLE = 1,
00055 PROP_MESSAGE,
00056 PROP_SOUND,
00057 PROP_ICON,
00058 };
00059
00060 enum saved_props {
00061 S_TITLE,
00062 S_MESSAGE,
00063 S_SOUND,
00064 S_ICON,
00065 S_COUNT
00066 };
00067
00068 static const gchar * const saved_properties[S_COUNT] = {
00069 "title",
00070 "message",
00071 "sound",
00072 "icon",
00073 };
00074
00075 enum Pending {
00076 PEND_SERVICE = 1 << 0,
00077 PEND_CONN = 1 << 1,
00078 };
00079
00080 typedef struct _AlarmdActionDialogPrivate AlarmdActionDialogPrivate;
00081 struct _AlarmdActionDialogPrivate {
00082 gchar *title;
00083 gchar *message;
00084 gchar *sound;
00085 gchar *icon;
00086 enum Pending pending;
00087 };
00088
00089 #define ALARMD_ACTION_DIALOG_GET_PRIVATE(obj) \
00090 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
00091 ALARMD_TYPE_ACTION_DIALOG, AlarmdActionDialogPrivate));
00092
00093 GType alarmd_action_dialog_get_type(void)
00094 {
00095 static GType action_dialog_type = 0;
00096
00097 if (!action_dialog_type)
00098 {
00099 static const GTypeInfo action_dialog_info =
00100 {
00101 sizeof (AlarmdActionDialogClass),
00102 NULL,
00103 NULL,
00104 (GClassInitFunc) alarmd_action_dialog_class_init,
00105 NULL,
00106 NULL,
00107 sizeof (AlarmdActionDialog),
00108 0,
00109 (GInstanceInitFunc) alarmd_action_dialog_init,
00110 NULL
00111 };
00112
00113 action_dialog_type = g_type_register_static(ALARMD_TYPE_ACTION,
00114 "AlarmdActionDialog",
00115 &action_dialog_info, 0);
00116 }
00117
00118 return action_dialog_type;
00119 }
00120
00121 void alarmd_action_dialog_do_action(AlarmdActionDialog *dialog)
00122 {
00123 ENTER_FUNC;
00124 ALARMD_ACTION_DIALOG_GET_CLASS(dialog)->do_action(dialog);
00125 LEAVE_FUNC;
00126 }
00127
00128 static void alarmd_action_dialog_class_init(AlarmdActionDialogClass *klass)
00129 {
00130 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
00131 AlarmdObjectClass *aobject_class = ALARMD_OBJECT_CLASS(klass);
00132 AlarmdActionClass *action_class = ALARMD_ACTION_CLASS(klass);
00133
00134 ENTER_FUNC;
00135 g_type_class_add_private(klass, sizeof(AlarmdActionDialogPrivate));
00136
00137 gobject_class->set_property = _alarmd_action_dialog_set_property;
00138 gobject_class->get_property = _alarmd_action_dialog_get_property;
00139 gobject_class->finalize = _alarmd_action_dialog_finalize;
00140 aobject_class->get_saved_properties = _alarmd_action_dialog_get_saved_properties;
00141 action_class->run = _alarmd_action_dialog_run;
00142 klass->do_action = _alarmd_action_dialog_real_do_action;
00143
00144 g_object_class_install_property(gobject_class,
00145 PROP_TITLE,
00146 g_param_spec_string("title",
00147 "Title of the dialog.",
00148 "The title for the alarm dialog.",
00149 NULL,
00150 G_PARAM_READABLE | G_PARAM_WRITABLE));
00151 g_object_class_install_property(gobject_class,
00152 PROP_MESSAGE,
00153 g_param_spec_string("message",
00154 "Message shown by dialog.",
00155 "Message that will be shown in the alarm dialog.",
00156 NULL,
00157 G_PARAM_READABLE | G_PARAM_WRITABLE));
00158 g_object_class_install_property(gobject_class,
00159 PROP_SOUND,
00160 g_param_spec_string("sound",
00161 "Sound played when alarm is due.",
00162 "Sound that should be played when showing the dialog.",
00163 NULL,
00164 G_PARAM_READABLE | G_PARAM_WRITABLE));
00165 g_object_class_install_property(gobject_class,
00166 PROP_ICON,
00167 g_param_spec_string("icon",
00168 "Icon for dialog.",
00169 "Icon that should be shown in the alarm dialog.",
00170 NULL,
00171 G_PARAM_READABLE | G_PARAM_WRITABLE));
00172
00173 LEAVE_FUNC;
00174 }
00175
00176 static void alarmd_action_dialog_init(AlarmdActionDialog *action_dialog)
00177 {
00178 AlarmdActionDialogPrivate *priv = ALARMD_ACTION_DIALOG_GET_PRIVATE(action_dialog);
00179 ENTER_FUNC;
00180
00181 priv->title = NULL;
00182 priv->message = NULL;
00183 priv->sound = NULL;
00184 priv->icon = NULL;
00185 priv->pending = 0;
00186 LEAVE_FUNC;
00187 }
00188
00189 static void _alarmd_action_dialog_set_property(GObject *object,
00190 guint param_id,
00191 const GValue *value,
00192 GParamSpec *pspec)
00193 {
00194 AlarmdActionDialogPrivate *priv = ALARMD_ACTION_DIALOG_GET_PRIVATE(object);
00195 ENTER_FUNC;
00196
00197 switch (param_id) {
00198 case PROP_TITLE:
00199 if (priv->title) {
00200 g_free(priv->title);
00201 }
00202 priv->title = g_strdup(g_value_get_string(value));
00203 break;
00204 case PROP_MESSAGE:
00205 if (priv->message) {
00206 g_free(priv->message);
00207 }
00208 priv->message = g_strdup(g_value_get_string(value));
00209 break;
00210 case PROP_SOUND:
00211 if (priv->sound) {
00212 g_free(priv->sound);
00213 }
00214 priv->sound = g_strdup(g_value_get_string(value));
00215 break;
00216 case PROP_ICON:
00217 if (priv->icon) {
00218 g_free(priv->icon);
00219 }
00220 priv->icon = g_strdup(g_value_get_string(value));
00221 break;
00222 default:
00223 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
00224 LEAVE_FUNC;
00225 return;
00226 }
00227 alarmd_object_changed(ALARMD_OBJECT(object));
00228 LEAVE_FUNC;
00229 }
00230
00231 static void _alarmd_action_dialog_get_property(GObject *object,
00232 guint param_id,
00233 GValue *value,
00234 GParamSpec *pspec)
00235 {
00236 AlarmdActionDialogPrivate *priv = ALARMD_ACTION_DIALOG_GET_PRIVATE(object);
00237 ENTER_FUNC;
00238
00239 switch (param_id) {
00240 case PROP_TITLE:
00241 g_value_set_string(value, priv->title);
00242 break;
00243 case PROP_MESSAGE:
00244 g_value_set_string(value, priv->message);
00245 break;
00246 case PROP_SOUND:
00247 g_value_set_string(value, priv->sound);
00248 break;
00249 case PROP_ICON:
00250 g_value_set_string(value, priv->icon);
00251 break;
00252 default:
00253 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
00254 }
00255 LEAVE_FUNC;
00256 }
00257
00258 static void _alarmd_action_dialog_finalize(GObject *object)
00259 {
00260 AlarmdActionDialogPrivate *priv = ALARMD_ACTION_DIALOG_GET_PRIVATE(object);
00261 ENTER_FUNC;
00262
00263 if (priv->title != NULL) {
00264 g_free(priv->title);
00265 }
00266 if (priv->message != NULL) {
00267 g_free(priv->message);
00268 }
00269 if (priv->sound != NULL) {
00270 g_free(priv->sound);
00271 }
00272 if (priv->icon != NULL) {
00273 g_free(priv->icon);
00274 }
00275 if (priv->pending & PEND_SERVICE) {
00276 dbus_unwatch_name(STATUSBAR_SERVICE, _alarmd_action_dialog_delayed_run, object);
00277 }
00278 if (priv->pending & PEND_CONN) {
00279 ic_unwait_connection(_alarmd_action_dialog_connected, object);
00280 }
00281 G_OBJECT_CLASS(g_type_class_peek(g_type_parent(ALARMD_TYPE_ACTION_DIALOG)))->finalize(object);
00282 LEAVE_FUNC;
00283 }
00284
00285 static void _alarmd_action_dialog_delayed_run(gpointer action)
00286 {
00287 AlarmdActionDialogPrivate *priv = ALARMD_ACTION_DIALOG_GET_PRIVATE(action);
00288 ENTER_FUNC;
00289 priv->pending &= ~PEND_SERVICE;
00290 alarmd_action_dialog_do_action(ALARMD_ACTION_DIALOG(action));
00291 LEAVE_FUNC;
00292 }
00293
00294 static void _alarmd_action_dialog_real_run(gpointer action, gboolean snoozed)
00295 {
00296 AlarmdActionDialogPrivate *priv = ALARMD_ACTION_DIALOG_GET_PRIVATE(action);
00297 gint32 flags;
00298 ENTER_FUNC;
00299
00300 g_object_get(action, "flags", &flags, NULL);
00301
00302 if (snoozed) {
00303 if (!(flags & ALARM_EVENT_NO_DIALOG)) {
00304 if (systemui_is_acting_dead()) {
00305 systemui_powerup_dialog_queue_append(_alarmd_action_dialog_snooze_powerup, action);
00306 }
00307 }
00308 alarmd_action_acknowledge(ALARMD_ACTION(action), ACK_SNOOZE);
00309 } else if (flags & ALARM_EVENT_ACTDEAD) {
00310 if (!(flags & ALARM_EVENT_NO_DIALOG)) {
00311 if (systemui_is_acting_dead()) {
00312 systemui_powerup_dialog_queue_append(_alarmd_action_dialog_powerup, action);
00313 } else {
00314 alarmd_action_dialog_do_action(ALARMD_ACTION_DIALOG(action));
00315 }
00316 } else {
00317 alarmd_action_dialog_do_action(ALARMD_ACTION_DIALOG(action));
00318 }
00319 } else {
00320 DBusConnection *system_bus = get_dbus_connection(DBUS_BUS_SYSTEM);
00321 mce_request_powerup(system_bus);
00322 dbus_connection_unref(system_bus);
00323 priv->pending |= PEND_SERVICE;
00324 dbus_watch_name(STATUSBAR_SERVICE, _alarmd_action_dialog_delayed_run, action);
00325 }
00326
00327 LEAVE_FUNC;
00328 }
00329
00330 static void _alarmd_action_dialog_connected(gpointer act)
00331 {
00332 AlarmdAction *action = act;
00333 AlarmdActionDialogPrivate *priv = ALARMD_ACTION_DIALOG_GET_PRIVATE(action);
00334 gint32 flags;
00335 ENTER_FUNC;
00336 priv->pending &= ~PEND_CONN;
00337
00338 g_object_get(action, "flags", &flags, NULL);
00339
00340 if (!(flags & ALARM_EVENT_NO_DIALOG)) {
00341 AlarmdEvent *event;
00342 time_t alarm_time;
00343
00344 g_object_get(action, "event", &event, NULL);
00345 alarm_time = alarmd_event_get_time(event);
00346 g_object_unref(event);
00347
00348 systemui_alarm_dialog_queue_append(alarm_time, priv->title, priv->message, priv->sound, priv->icon, !(flags & ALARM_EVENT_NO_SNOOZE), _alarmd_action_dialog_real_run, action);
00349 update_mce_alarm_visibility();
00350 } else {
00351 _alarmd_action_dialog_real_run(action, FALSE);
00352 }
00353
00354 LEAVE_FUNC;
00355 }
00356
00357 static void _alarmd_action_dialog_run(AlarmdAction *action, gboolean delayed)
00358 {
00359 AlarmdActionDialogPrivate *priv = ALARMD_ACTION_DIALOG_GET_PRIVATE(action);
00360 guint32 flags;
00361 ENTER_FUNC;
00362
00363 g_object_get(action, "flags", &flags, NULL);
00364 if (delayed && !(flags & ALARM_EVENT_RUN_DELAYED)) {
00365 alarmd_action_acknowledge(action, ACK_NORMAL);
00366 } else if ((flags & ALARM_EVENT_CONNECTED) &&
00367 !ic_get_connected()) {
00368 ic_wait_connection(_alarmd_action_dialog_connected, action);
00369 priv->pending |= PEND_CONN;
00370 } else if (!(flags & ALARM_EVENT_NO_DIALOG)) {
00371 AlarmdEvent *event;
00372 time_t alarm_time;
00373
00374 g_object_get(action, "event", &event, NULL);
00375 alarm_time = alarmd_event_get_time(event);
00376 g_object_unref(event);
00377
00378 systemui_alarm_dialog_queue_append(alarm_time, priv->title, priv->message, priv->sound, priv->icon, !(flags & ALARM_EVENT_NO_SNOOZE), _alarmd_action_dialog_real_run, action);
00379 update_mce_alarm_visibility();
00380 } else {
00381 _alarmd_action_dialog_real_run(action, FALSE);
00382 }
00383
00384 LEAVE_FUNC;
00385 }
00386
00387 static GSList *_alarmd_action_dialog_get_saved_properties(void)
00388 {
00389 guint i;
00390 GSList *retval = NULL;
00391 ENTER_FUNC;
00392 retval = ALARMD_OBJECT_CLASS(g_type_class_peek(g_type_parent(ALARMD_TYPE_ACTION_DIALOG)))->get_saved_properties();
00393 for (i = 0; i < S_COUNT; i++) {
00394 retval = g_slist_append(retval, (gpointer)saved_properties[i]);
00395 }
00396 LEAVE_FUNC;
00397 return retval;
00398 }
00399
00400 static void _alarmd_action_dialog_real_do_action(AlarmdActionDialog *dialog)
00401 {
00402 ENTER_FUNC;
00403 alarmd_action_acknowledge(ALARMD_ACTION(dialog), ACK_NORMAL);
00404 LEAVE_FUNC;
00405 }
00406
00407 static void _alarmd_action_dialog_powerup(gpointer user_data, gboolean power_up)
00408 {
00409 ENTER_FUNC;
00410
00411 if (power_up) {
00412 DBusConnection *system_bus =
00413 get_dbus_connection(DBUS_BUS_SYSTEM);
00414 if (system_bus) {
00415 mce_request_powerup(system_bus);
00416 dbus_connection_unref(system_bus);
00417 }
00418 }
00419 alarmd_action_acknowledge(ALARMD_ACTION(user_data), ACK_NORMAL);
00420 update_mce_alarm_visibility();
00421 LEAVE_FUNC;
00422 }
00423
00424 static void _alarmd_action_dialog_snooze_powerup(gpointer user_data, gboolean power_up)
00425 {
00426 ENTER_FUNC;
00427
00428 if (power_up) {
00429 DBusConnection *system_bus =
00430 get_dbus_connection(DBUS_BUS_SYSTEM);
00431 if (system_bus) {
00432 mce_request_powerup(system_bus);
00433 dbus_connection_unref(system_bus);
00434 }
00435 }
00436 alarmd_action_acknowledge(ALARMD_ACTION(user_data), ACK_SNOOZE);
00437 update_mce_alarm_visibility();
00438 LEAVE_FUNC;
00439 }