~ubuntu-branches/ubuntu/maverick/gnome-session/maverick

« back to all changes in this revision

Viewing changes to gnome-session/gsm-xsmp-client.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2009-04-08 09:47:57 UTC
  • mto: This revision was merged to the branch mainline in revision 110.
  • Revision ID: james.westby@ubuntu.com-20090408094757-rs8ialby8p72at4e
Tags: upstream-2.26.0svn20090408
ImportĀ upstreamĀ versionĀ 2.26.0svn20090408

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
        guint      watch_id;
53
53
        guint      protocol_timeout;
54
54
 
 
55
        char      *description;
 
56
        GPtrArray *props;
 
57
 
 
58
        /* SaveYourself state */
55
59
        int        current_save_yourself;
56
60
        int        next_save_yourself;
57
 
        char      *description;
58
 
        GPtrArray *props;
 
61
        guint      next_save_yourself_allow_interact : 1;
59
62
};
60
63
 
61
64
enum {
221
224
        client->priv->props = g_ptr_array_new ();
222
225
        client->priv->current_save_yourself = -1;
223
226
        client->priv->next_save_yourself = -1;
 
227
        client->priv->next_save_yourself_allow_interact = FALSE;
224
228
}
225
229
 
226
230
 
403
407
        return prop_to_command (prop);
404
408
}
405
409
 
406
 
#if 0
407
410
static char *
408
411
xsmp_get_discard_command (GsmClient *client)
409
412
{
417
420
 
418
421
        return prop_to_command (prop);
419
422
}
420
 
#endif
421
423
 
422
424
static void
423
425
do_save_yourself (GsmXSMPClient *client,
424
426
                  int            save_type,
425
 
                  gboolean       forceful)
 
427
                  gboolean       allow_interact)
426
428
{
427
429
        g_assert (client->priv->conn != NULL);
428
430
 
437
439
                g_debug ("GsmXSMPClient:   queuing new SaveYourself for '%s'",
438
440
                         client->priv->description);
439
441
                client->priv->next_save_yourself = save_type;
 
442
                client->priv->next_save_yourself_allow_interact = allow_interact;
440
443
        } else {
441
444
                client->priv->current_save_yourself = save_type;
 
445
                /* make sure we don't have anything queued */
 
446
                client->priv->next_save_yourself = -1;
 
447
                client->priv->next_save_yourself_allow_interact = FALSE;
442
448
 
443
449
                switch (save_type) {
444
450
                case SmSaveLocal:
452
458
 
453
459
                default:
454
460
                        /* Logout */
455
 
                        if (forceful) {
 
461
                        if (!allow_interact) {
456
462
                                SmsSaveYourself (client->priv->conn,
457
463
                                                 save_type, /* save type */
458
464
                                                 TRUE, /* shutdown */
470
476
        }
471
477
}
472
478
 
473
 
#if 0
474
479
static void
475
480
xsmp_save_yourself_phase2 (GsmClient *client)
476
481
{
490
495
 
491
496
        SmsInteract (xsmp->priv->conn);
492
497
}
493
 
#endif
494
498
 
495
499
static gboolean
496
500
xsmp_cancel_end_session (GsmClient *client,
509
513
        }
510
514
 
511
515
        SmsShutdownCancelled (xsmp->priv->conn);
 
516
 
 
517
        /* reset the state */
 
518
        xsmp->priv->current_save_yourself = -1;
 
519
        xsmp->priv->next_save_yourself = -1;
 
520
        xsmp->priv->next_save_yourself_allow_interact = FALSE;
 
521
 
512
522
        return TRUE;
513
523
}
514
524
 
620
630
xsmp_save (GsmClient *client,
621
631
           GError   **error)
622
632
{
623
 
        GKeyFile *keyfile;
 
633
        GKeyFile *keyfile = NULL;
624
634
        char     *desktop_file_path = NULL;
625
635
        char     *exec_program = NULL;
 
636
        char     *exec_discard = NULL;
626
637
        char     *startup_id = NULL;
627
638
        GError   *local_error;
628
639
 
631
642
 
632
643
        local_error = NULL;
633
644
 
 
645
        exec_program = xsmp_get_restart_command (client);
 
646
        if (!exec_program) {
 
647
                goto out;
 
648
        }
 
649
 
634
650
        desktop_file_path = get_desktop_file_path (GSM_XSMP_CLIENT (client));
635
651
 
636
652
        keyfile = create_client_key_file (client,
650
666
                               "X-GNOME-Autostart-startup-id",
651
667
                               startup_id);
652
668
 
653
 
        exec_program = xsmp_get_restart_command (client);
654
669
        g_key_file_set_string (keyfile,
655
670
                               G_KEY_FILE_DESKTOP_GROUP,
656
671
                               G_KEY_FILE_DESKTOP_KEY_EXEC,
657
672
                               exec_program);
658
673
 
 
674
        exec_discard = xsmp_get_discard_command (client);
 
675
        if (exec_discard)
 
676
                g_key_file_set_string (keyfile,
 
677
                                       G_KEY_FILE_DESKTOP_GROUP,
 
678
                                       "X-GNOME-Autostart-discard-exec",
 
679
                                       exec_discard);
 
680
 
659
681
out:
660
682
        g_free (desktop_file_path);
661
683
        g_free (exec_program);
 
684
        g_free (exec_discard);
662
685
        g_free (startup_id);
663
686
 
664
687
        if (local_error != NULL) {
689
712
                        guint      flags,
690
713
                        GError   **error)
691
714
{
692
 
        gboolean forceful;
 
715
        gboolean allow_interact;
 
716
        int      save_type;
693
717
 
694
718
        if (GSM_XSMP_CLIENT (client)->priv->conn == NULL) {
695
719
                g_set_error (error,
699
723
                return FALSE;
700
724
        }
701
725
 
702
 
        forceful = (flags & GSM_CLIENT_END_SESSION_FLAG_FORCEFUL);
703
 
        do_save_yourself (GSM_XSMP_CLIENT (client), SmSaveGlobal, forceful);
 
726
        allow_interact = !(flags & GSM_CLIENT_END_SESSION_FLAG_FORCEFUL);
 
727
 
 
728
        /* we don't want to save the session state, but we just want to know if
 
729
         * there's user data the client has to save and we want to give the
 
730
         * client a chance to tell the user about it. This is consistent with
 
731
         * the manager not setting GSM_CLIENT_END_SESSION_FLAG_SAVE for this
 
732
         * phase. */
 
733
        save_type = SmSaveGlobal;
 
734
 
 
735
        do_save_yourself (GSM_XSMP_CLIENT (client), save_type, allow_interact);
704
736
        return TRUE;
705
737
}
706
738
 
709
741
                  guint      flags,
710
742
                  GError   **error)
711
743
{
712
 
        gboolean forceful;
 
744
        gboolean phase2;
713
745
 
714
746
        if (GSM_XSMP_CLIENT (client)->priv->conn == NULL) {
715
747
                g_set_error (error,
719
751
                return FALSE;
720
752
        }
721
753
 
722
 
        forceful = (flags & GSM_CLIENT_END_SESSION_FLAG_FORCEFUL);
723
 
        do_save_yourself (GSM_XSMP_CLIENT (client), SmSaveGlobal, forceful);
 
754
        phase2 = (flags & GSM_CLIENT_END_SESSION_FLAG_LAST);
 
755
 
 
756
        if (phase2) {
 
757
                xsmp_save_yourself_phase2 (client);
 
758
        } else {
 
759
                gboolean allow_interact;
 
760
                int      save_type;
 
761
 
 
762
                /* we gave a chance to interact to the app during
 
763
                 * xsmp_query_end_session(), now it's too late to interact */
 
764
                allow_interact = FALSE;
 
765
 
 
766
                if (flags & GSM_CLIENT_END_SESSION_FLAG_SAVE) {
 
767
                        save_type = SmSaveBoth;
 
768
                } else {
 
769
                        save_type = SmSaveGlobal;
 
770
                }
 
771
 
 
772
                do_save_yourself (GSM_XSMP_CLIENT (client),
 
773
                                  save_type, allow_interact);
 
774
        }
 
775
 
724
776
        return TRUE;
725
777
}
726
778
 
1099
1151
                g_signal_emit (client, signals[LOGOUT_REQUEST], 0, !fast);
1100
1152
        } else if (!shutdown && !global) {
1101
1153
                g_debug ("GsmXSMPClient:   initiating checkpoint");
1102
 
                do_save_yourself (client, SmSaveLocal, FALSE);
 
1154
                do_save_yourself (client, SmSaveLocal, TRUE);
1103
1155
        } else {
1104
1156
                g_debug ("GsmXSMPClient:   ignoring");
1105
1157
        }
1114
1166
        g_debug ("GsmXSMPClient: Client '%s' received SaveYourselfPhase2Request",
1115
1167
                 client->priv->description);
1116
1168
 
1117
 
        /* Treat this just like a SaveYourselfDone */
1118
 
        if (client->priv->current_save_yourself == SmSaveLocal) {
1119
 
                client->priv->current_save_yourself = -1;
1120
 
                SmsSaveComplete (client->priv->conn);
1121
 
        } else {
1122
 
                client->priv->current_save_yourself = -1;
1123
 
        }
 
1169
        client->priv->current_save_yourself = -1;
1124
1170
 
1125
1171
        /* this is a valid response to SaveYourself and therefore
1126
1172
           may be a response to a QES or ES */
1127
 
        gdm_client_end_session_response (GSM_CLIENT (client),
1128
 
                                         TRUE,
 
1173
        gsm_client_end_session_response (GSM_CLIENT (client),
 
1174
                                         TRUE, TRUE, FALSE,
1129
1175
                                         NULL);
1130
 
 
1131
 
        /* FIXME: change priority so this client runs at the end? */
1132
1176
}
1133
1177
 
1134
1178
static void
1137
1181
                           int       dialog_type)
1138
1182
{
1139
1183
        GsmXSMPClient *client = manager_data;
 
1184
#if 0
1140
1185
        gboolean       res;
1141
1186
        GError        *error;
 
1187
#endif
1142
1188
 
1143
1189
        g_debug ("GsmXSMPClient: Client '%s' received InteractRequest(%s)",
1144
1190
                 client->priv->description,
1145
1191
                 dialog_type == SmDialogNormal ? "Dialog" : "Errors");
1146
1192
 
1147
 
        gdm_client_end_session_response (GSM_CLIENT (client),
1148
 
                                         FALSE,
 
1193
        gsm_client_end_session_response (GSM_CLIENT (client),
 
1194
                                         FALSE, FALSE, FALSE,
1149
1195
                                         _("This program is blocking log out."));
1150
1196
 
 
1197
#if 0
1151
1198
        /* Can't just call back with Interact because session client
1152
1199
           grabs the keyboard!  So, we try to get it to release
1153
1200
           grabs by telling it we've cancelled the shutdown.
1159
1206
                g_warning ("Unable to cancel end session: %s", error->message);
1160
1207
                g_error_free (error);
1161
1208
        }
 
1209
#endif
 
1210
        xsmp_interact (GSM_CLIENT (client));
1162
1211
}
1163
1212
 
1164
1213
static void
1172
1221
                 client->priv->description,
1173
1222
                 cancel_shutdown ? "True" : "False");
1174
1223
 
1175
 
        gdm_client_end_session_response (GSM_CLIENT (client),
1176
 
                                         TRUE,
 
1224
        gsm_client_end_session_response (GSM_CLIENT (client),
 
1225
                                         TRUE, FALSE, cancel_shutdown,
1177
1226
                                         NULL);
1178
1227
}
1179
1228
 
1188
1237
                 client->priv->description,
1189
1238
                 success ? "True" : "False");
1190
1239
 
1191
 
        if (client->priv->current_save_yourself == SmSaveLocal) {
1192
 
                client->priv->current_save_yourself = -1;
1193
 
                SmsSaveComplete (client->priv->conn);
1194
 
        } else {
1195
 
                client->priv->current_save_yourself = -1;
1196
 
        }
 
1240
        client->priv->current_save_yourself = -1;
 
1241
        SmsSaveComplete (client->priv->conn);
1197
1242
 
1198
 
        /* If success is false then the application still has
1199
 
           unsafe data.  We may also have tricked it into sending
1200
 
           us this message when we faked the ShutdownCancel to
1201
 
           break its grabs. */
1202
 
        if (success) {
1203
 
                gdm_client_end_session_response (GSM_CLIENT (client),
1204
 
                                                 TRUE,
1205
 
                                                 NULL);
1206
 
        }
 
1243
        /* If success is false then the application couldn't save data. Nothing
 
1244
         * the session manager can do about, though. FIXME: we could display a
 
1245
         * dialog about this, I guess. */
 
1246
        gsm_client_end_session_response (GSM_CLIENT (client),
 
1247
                                         TRUE, FALSE, FALSE,
 
1248
                                         NULL);
1207
1249
 
1208
1250
        if (client->priv->next_save_yourself) {
1209
 
                int save_type = client->priv->next_save_yourself;
 
1251
                int      save_type = client->priv->next_save_yourself;
 
1252
                gboolean allow_interact = client->priv->next_save_yourself_allow_interact;
1210
1253
 
1211
1254
                client->priv->next_save_yourself = -1;
1212
 
                do_save_yourself (client, save_type, FALSE);
 
1255
                client->priv->next_save_yourself_allow_interact = -1;
 
1256
                do_save_yourself (client, save_type, allow_interact);
1213
1257
        }
1214
1258
}
1215
1259