aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalStatusServiceImpl.java
blob: 87e2b09fee39a75bd99e5a58c0345bdf794b47f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license. See terms of license at gnu.org.
 */
package net.java.sip.communicator.impl.globaldisplaydetails;

import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.service.protocol.globalstatus.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.account.*;

import org.jitsi.service.configuration.*;

import java.util.*;

/**
 * Global statuses service impl. Gives access to the outside for some
 * methods to change the global status and individual protocol provider
 * status. Use to implement global status menu with list of all account
 * statuses.
 * @author Damian Minkov
 */
public class GlobalStatusServiceImpl
    implements GlobalStatusService,
               RegistrationStateChangeListener
{
    /**
     * The object used for logging.
     */
    private final Logger logger
        = Logger.getLogger(GlobalStatusServiceImpl.class);

    /**
     * Handles newly added providers.
     * @param pps
     */
    void handleProviderAdded(ProtocolProviderService pps)
    {
        pps.addRegistrationStateChangeListener(this);

        if(pps.isRegistered())
        {
            handleProviderRegistered(pps);
        }
    }

    /**
     * Handles removed providers.
     * @param pps the provider.
     */
    void handleProviderRemoved(ProtocolProviderService pps)
    {
        pps.removeRegistrationStateChangeListener(this);
    }

    /**
     * Returns the global presence status.
     *
     * @return the current global presence status
     */
    public PresenceStatus getGlobalPresenceStatus()
    {
        int status = 0;

        Collection<ProtocolProviderService> pProviders
            = AccountUtils.getRegisteredProviders();

        // If we don't have registered providers we return offline status.
        if (pProviders == null || pProviders.size() <= 0)
            return getPresenceStatus(status);

        Iterator<ProtocolProviderService> providersIter = pProviders.iterator();

        boolean hasAvailableProvider = false;

        while (providersIter.hasNext())
        {
            ProtocolProviderService protocolProvider = providersIter.next();

            // We do not show hidden protocols in our status bar, so we do not
            // care about their status here.
            if (protocolProvider.getAccountID().isHidden())
                continue;

            if (!protocolProvider.isRegistered())
                continue;

            OperationSetPresence presence
                = protocolProvider.getOperationSet(OperationSetPresence.class);

            if(presence == null)
            {
                hasAvailableProvider = true;
                continue;
            }

            int presenceStatus
                = (presence == null)
                    ? PresenceStatus.AVAILABLE_THRESHOLD
                    : presence.getPresenceStatus().getStatus();

            if (status < presenceStatus)
                status = presenceStatus;
        }

        // if we have at least one online provider
        if(status == 0 && hasAvailableProvider)
            status = PresenceStatus.AVAILABLE_THRESHOLD;

        return getPresenceStatus(status);
    }

    /**
     * Returns the <tt>JCheckBoxMenuItem</tt> corresponding to the given status.
     * For status constants we use here the values defined in the
     * <tt>PresenceStatus</tt>, but this is only for convenience.
     *
     * @param status the status to which the item should correspond
     * @return the <tt>JCheckBoxMenuItem</tt> corresponding to the given status
     */
    private PresenceStatus getPresenceStatus(int status)
    {
        if(status < PresenceStatus.ONLINE_THRESHOLD)
        {
            return GlobalStatusEnum.OFFLINE;
        }
        else if(status < PresenceStatus.EXTENDED_AWAY_THRESHOLD)
        {
            return GlobalStatusEnum.DO_NOT_DISTURB;
        }
        else if(status < PresenceStatus.AWAY_THRESHOLD)
        {
            return GlobalStatusEnum.EXTENDED_AWAY;
        }
        else if(status < PresenceStatus.AVAILABLE_THRESHOLD)
        {
            return GlobalStatusEnum.AWAY;
        }
        else if(status < PresenceStatus.EAGER_TO_COMMUNICATE_THRESHOLD)
        {
            return GlobalStatusEnum.ONLINE;
        }
        else if(status < PresenceStatus.MAX_STATUS_VALUE)
        {
            return GlobalStatusEnum.FREE_FOR_CHAT;
        }
        else
        {
            return GlobalStatusEnum.OFFLINE;
        }
    }

    /**
     * Returns the last status that was stored in the configuration for the
     * given protocol provider.
     *
     * @param protocolProvider the protocol provider
     * @return the last status that was stored in the configuration for the
     *         given protocol provider
     */
    public PresenceStatus getLastPresenceStatus(
        ProtocolProviderService protocolProvider)
    {
        String lastStatus = getLastStatusString(protocolProvider);

        PresenceStatus status = null;

        if (lastStatus != null)
        {
            OperationSetPresence presence
                = protocolProvider.getOperationSet(OperationSetPresence.class);

            if (presence == null)
                return null;

            Iterator<PresenceStatus> i = presence.getSupportedStatusSet();

            // Check if there's such status in the supported presence status
            // set.
            while (i.hasNext())
            {
                PresenceStatus nextStatus = i.next();

                if (nextStatus.getStatusName().equals(lastStatus))
                    status = nextStatus;
            }

            // If we haven't found the last status in the protocol provider
            // supported status set, we'll have a look for a corresponding
            // global status and its protocol representation.
            if (status == null)
            {
                if (lastStatus.equals(GlobalStatusEnum.ONLINE_STATUS))
                {
                    status = getPresenceStatus(
                        protocolProvider,
                        PresenceStatus.AVAILABLE_THRESHOLD,
                        PresenceStatus.EAGER_TO_COMMUNICATE_THRESHOLD);
                }
                else if (lastStatus.equals(GlobalStatusEnum.AWAY_STATUS))
                {
                    status = getPresenceStatus(
                        protocolProvider,
                        PresenceStatus.AWAY_THRESHOLD,
                        PresenceStatus.AVAILABLE_THRESHOLD);
                }
                else if (lastStatus.equals(
                            GlobalStatusEnum.EXTENDED_AWAY_STATUS))
                {
                    status = getPresenceStatus(
                        protocolProvider,
                        PresenceStatus.EXTENDED_AWAY_THRESHOLD,
                        PresenceStatus.AWAY_THRESHOLD);
                }
                else if (lastStatus
                            .equals(GlobalStatusEnum.DO_NOT_DISTURB_STATUS))
                {
                    status = getPresenceStatus(
                            protocolProvider,
                            PresenceStatus.ONLINE_THRESHOLD,
                            PresenceStatus.EXTENDED_AWAY_THRESHOLD);
                }
                else if (lastStatus
                            .equals(GlobalStatusEnum.FREE_FOR_CHAT_STATUS))
                {
                    status = getPresenceStatus(
                            protocolProvider,
                            PresenceStatus.AVAILABLE_THRESHOLD,
                            PresenceStatus.MAX_STATUS_VALUE);
                }
                else if (lastStatus.equals(GlobalStatusEnum.OFFLINE_STATUS))
                {
                    status = getPresenceStatus(
                            protocolProvider,
                            0,
                            GlobalStatusEnum.ONLINE_THRESHOLD);
                }
            }
        }
        return status;
    }

    /**
     * Returns the last contact status saved in the configuration.
     *
     * @param protocolProvider the protocol provider to which the status
     *            corresponds
     * @return the last contact status saved in the configuration.
     */
    public String getLastStatusString(ProtocolProviderService protocolProvider)
    {
        // find the last contact status saved in the configuration.
        String lastStatus = null;

        ConfigurationService configService
            = GlobalDisplayDetailsActivator.getConfigurationService();
        String prefix = "net.java.sip.communicator.impl.gui.accounts";
        List<String> accounts
            = configService.getPropertyNamesByPrefix(prefix, true);
        String protocolProviderAccountUID
            = protocolProvider.getAccountID().getAccountUniqueID();

        for (String accountRootPropName : accounts)
        {
            String accountUID = configService.getString(accountRootPropName);

            if (accountUID.equals(protocolProviderAccountUID))
            {
                lastStatus =
                    configService.getString(accountRootPropName
                        + ".lastAccountStatus");

                if (lastStatus != null)
                    break;
            }
        }

        return lastStatus;
    }

    /**
     * Publish present status. We search for the highest value in the
     * given interval.
     *
     * @param protocolProvider the protocol provider to which we
     * change the status.
     * @param status the status to publish.
     */
    public void publishStatus(
            ProtocolProviderService protocolProvider,
            PresenceStatus status)
    {
        OperationSetPresence presence
                = protocolProvider.getOperationSet(OperationSetPresence.class);

        LoginManager loginManager = null;
        UIService uiService = GlobalDisplayDetailsActivator.getUIService();
        if(uiService != null)
        {
            loginManager = uiService.getLoginManager();
        }

        RegistrationState registrationState
            = protocolProvider.getRegistrationState();

        if (registrationState == RegistrationState.REGISTERED
            && presence != null
            && !presence.getPresenceStatus().equals(status))
        {
            if (status.isOnline())
            {
                new PublishPresenceStatusThread(
                        protocolProvider,
                        presence,
                        status).start();
            }
            else
            {
                if(loginManager != null)
                    loginManager.setManuallyDisconnected(true);
                LoginManager.logoff(protocolProvider);
            }
        }
        else if (registrationState != RegistrationState.REGISTERED
            && registrationState != RegistrationState.REGISTERING
            && registrationState != RegistrationState.AUTHENTICATING
            && status.isOnline())
        {
            // If provider fires registered, and while dispatching
            // the registered event a fatal error rise in the connection
            // and the provider goes in connection_failed we can end up here
            // calling login and going over the same cycle over and over again
            logger.warn("Called publish status for provider in wrong state " +
                " provider: " + protocolProvider + " registrationState: "
                + registrationState + " status: " + status);
            ///GlobalDisplayDetailsActivator.getUIService().getLoginManager()
            //    .login(protocolProvider);
        }
        else if (!status.isOnline()
                && !(registrationState
                        == RegistrationState.UNREGISTERING))
        {
            if(loginManager != null)
                loginManager.setManuallyDisconnected(true);
            LoginManager.logoff(protocolProvider);
        }

        saveStatusInformation(
            protocolProvider,
            status.getStatusName());
    }

    /**
     * Publish present status. We search for the highest value in the
     * given interval.
     *
     * change the status.
     * @param globalStatus
     */
    public void publishStatus(GlobalStatusEnum globalStatus)
    {
        String itemName = globalStatus.getStatusName();

        Iterator<ProtocolProviderService> pProviders
            = AccountUtils.getRegisteredProviders().iterator();

        while (pProviders.hasNext())
        {
            ProtocolProviderService protocolProvider = pProviders.next();

            if(itemName.equals(GlobalStatusEnum.ONLINE_STATUS))
            {
                if(!protocolProvider.isRegistered())
                {
                    saveStatusInformation(protocolProvider, itemName);

                    GlobalDisplayDetailsActivator.getUIService()
                        .getLoginManager().login(protocolProvider);
                }
                else
                {
                    OperationSetPresence presence
                        = protocolProvider
                            .getOperationSet(OperationSetPresence.class);

                    if (presence == null)
                    {
                        saveStatusInformation(protocolProvider, itemName);

                        continue;
                    }

                    Iterator<PresenceStatus> statusSet
                        = presence.getSupportedStatusSet();

                    while (statusSet.hasNext())
                    {
                        PresenceStatus status = statusSet.next();

                        if( status.getStatus()
                                < PresenceStatus.EAGER_TO_COMMUNICATE_THRESHOLD
                            && status.getStatus()
                                >= PresenceStatus.AVAILABLE_THRESHOLD)
                        {
                            new PublishPresenceStatusThread(protocolProvider,
                                                            presence, status)
                                .start();

                            this.saveStatusInformation( protocolProvider,
                                                        status.getStatusName());

                            break;
                        }
                    }
                }
            }
            else if (itemName.equals(GlobalStatusEnum.OFFLINE_STATUS))
            {
                if(    !protocolProvider.getRegistrationState()
                                .equals(RegistrationState.UNREGISTERED)
                    && !protocolProvider.getRegistrationState()
                                .equals(RegistrationState.UNREGISTERING))
                {
                    OperationSetPresence presence
                        = protocolProvider
                            .getOperationSet(OperationSetPresence.class);

                    if (presence == null)
                    {
                        saveStatusInformation(  protocolProvider,
                                                itemName);

                        LoginManager.logoff(protocolProvider);

                        continue;
                    }

                    Iterator<PresenceStatus> statusSet
                        = presence.getSupportedStatusSet();

                    while (statusSet.hasNext())
                    {
                        PresenceStatus status = statusSet.next();

                        if(status.getStatus()
                            < PresenceStatus.ONLINE_THRESHOLD)
                        {
                            this.saveStatusInformation( protocolProvider,
                                status.getStatusName());

                            break;
                        }
                    }

                    try
                    {
                        protocolProvider.unregister(true);
                    }
                    catch (OperationFailedException e1)
                    {
                        logger.error(
                            "Unable to unregister the protocol provider: "
                            + protocolProvider
                            + " due to the following exception: " + e1);
                    }
                }
            }
            else if (itemName.equals(GlobalStatusEnum.FREE_FOR_CHAT_STATUS))
            {
                if(!protocolProvider.isRegistered())
                {
                    saveStatusInformation(protocolProvider, itemName);

                    GlobalDisplayDetailsActivator.getUIService()
                        .getLoginManager().login(protocolProvider);
                }
                else
                    // we search for highest available status here
                    publishStatus(
                            protocolProvider,
                            PresenceStatus.AVAILABLE_THRESHOLD,
                            PresenceStatus.MAX_STATUS_VALUE);
            }
            else if (itemName.equals(GlobalStatusEnum.DO_NOT_DISTURB_STATUS))
            {
                if(!protocolProvider.isRegistered())
                {
                    saveStatusInformation(protocolProvider, itemName);

                    GlobalDisplayDetailsActivator.getUIService()
                        .getLoginManager().login(protocolProvider);
                }
                else
                    // status between online and away is DND
                    publishStatus(
                            protocolProvider,
                            PresenceStatus.ONLINE_THRESHOLD,
                            PresenceStatus.EXTENDED_AWAY_THRESHOLD);
            }
            else if (itemName.equals(GlobalStatusEnum.AWAY_STATUS))
            {
                if(!protocolProvider.isRegistered())
                {
                    saveStatusInformation(protocolProvider, itemName);

                    GlobalDisplayDetailsActivator.getUIService()
                        .getLoginManager().login(protocolProvider);
                }
                else
                    // a status in the away interval
                    publishStatus(
                            protocolProvider,
                            PresenceStatus.AWAY_THRESHOLD,
                            PresenceStatus.AVAILABLE_THRESHOLD);
            }
            else if (itemName.equals(GlobalStatusEnum.EXTENDED_AWAY_STATUS))
            {
                if(!protocolProvider.isRegistered())
                {
                    saveStatusInformation(protocolProvider, itemName);

                    GlobalDisplayDetailsActivator.getUIService()
                        .getLoginManager().login(protocolProvider);
                }
                else
                    // a status in the away interval
                    publishStatus(
                            protocolProvider,
                            PresenceStatus.EXTENDED_AWAY_THRESHOLD,
                            PresenceStatus.AWAY_THRESHOLD);
            }
        }
    }

    /**
     * Publish present status. We search for the highest value in the
     * given interval.
     *
     * @param protocolProvider the protocol provider to which we
     * change the status.
     * @param floorStatusValue the min status value.
     * @param ceilStatusValue the max status value.
     */
    private void publishStatus(
            ProtocolProviderService protocolProvider,
            int floorStatusValue, int ceilStatusValue)
    {
        if (!protocolProvider.isRegistered())
            return;

        PresenceStatus status = getPresenceStatus(protocolProvider,
            floorStatusValue,
            ceilStatusValue);

        if (status != null)
        {
            OperationSetPresence presence
                = protocolProvider
                    .getOperationSet(OperationSetPresence.class);

            new PublishPresenceStatusThread(protocolProvider, presence, status)
                .start();

            this.saveStatusInformation( protocolProvider,
                                        status.getStatusName());
        }
    }

    private PresenceStatus getPresenceStatus(
        ProtocolProviderService protocolProvider,
        int floorStatusValue,
        int ceilStatusValue)
    {
        OperationSetPresence presence
            = protocolProvider
                .getOperationSet(OperationSetPresence.class);

        if (presence == null)
            return null;

        Iterator<PresenceStatus> statusSet
            = presence.getSupportedStatusSet();

        PresenceStatus status = null;

        while (statusSet.hasNext())
        {
            PresenceStatus currentStatus = statusSet.next();

            if (status == null
                && currentStatus.getStatus() < ceilStatusValue
                && currentStatus.getStatus() >= floorStatusValue)
            {
                status = currentStatus;
            }

            if (status != null)
            {
                if (currentStatus.getStatus() < ceilStatusValue
                    && currentStatus.getStatus() >= floorStatusValue
                    && currentStatus.getStatus() > status.getStatus())
                {
                    status = currentStatus;
                }
            }
        }

        return status;
    }

    /**
     * Saves the last status for all accounts. This information is used
     * on loging. Each time user logs in he's logged with the same status
     * as he was the last time before closing the application.
     * @param protocolProvider the protocol provider to save status information
     * for
     * @param statusName the name of the status to save
     */
    private void saveStatusInformation(
            ProtocolProviderService protocolProvider,
            String statusName)
    {
        ConfigurationService configService
            = GlobalDisplayDetailsActivator.getConfigurationService();

        String prefix = "net.java.sip.communicator.impl.gui.accounts";

        List<String> accounts = configService
                .getPropertyNamesByPrefix(prefix, true);

        boolean savedAccount = false;

        for (String accountRootPropName : accounts) {
            String accountUID
                = configService.getString(accountRootPropName);

            if(accountUID.equals(protocolProvider
                    .getAccountID().getAccountUniqueID())) {

                configService.setProperty(
                        accountRootPropName + ".lastAccountStatus",
                        statusName);

                savedAccount = true;
            }
        }

        if(!savedAccount)
        {
            String accNodeName
                = "acc" + Long.toString(System.currentTimeMillis());

            String accountPackage
                = "net.java.sip.communicator.impl.gui.accounts."
                        + accNodeName;

            configService.setProperty(accountPackage,
                protocolProvider.getAccountID().getAccountUniqueID());

            configService.setProperty(
                accountPackage + ".lastAccountStatus",
                statusName);
        }
    }

    /**
     * Waits for providers to register and then checks for its last status
     * saved if any and used it to restore its status.
     * @param evt a <tt>RegistrationStateChangeEvent</tt> which describes the
    */
    @Override
    public void registrationStateChanged(RegistrationStateChangeEvent evt)
    {
        if(!evt.getNewState().equals(RegistrationState.REGISTERED))
            return;

        handleProviderRegistered(evt.getProvider());
    }

    /**
     * Handles registered providers. If provider has a stored last status
     * publish that status, otherwise we just publish that they
     * are Online/Available/
     * @param pps the provider
     */
    private void handleProviderRegistered(ProtocolProviderService pps)
    {
        PresenceStatus status = getLastPresenceStatus(pps);

        if(status == null)
        {
            // lets publish just online
            status = AccountStatusUtils.getOnlineStatus(pps);
        }

        if (status != null
            && status.getStatus() >= PresenceStatus.ONLINE_THRESHOLD)
        {
            publishStatus(pps, status);
        }
    }

    /**
     * Publishes the given status to the given presence operation set.
     */
    private class PublishPresenceStatusThread
        extends Thread
    {
        private ProtocolProviderService protocolProvider;

        private PresenceStatus status;

        private OperationSetPresence presence;

        /**
         * Publishes the given <tt>status</tt> through the given
         * <tt>presence</tt> operation set.
         * @param presence the operation set through which we publish the status
         * @param status the status to publish
         */
        public PublishPresenceStatusThread(
                                    ProtocolProviderService protocolProvider,
                                    OperationSetPresence presence,
                                    PresenceStatus status)
        {
            this.protocolProvider = protocolProvider;
            this.presence = presence;
            this.status = status;
        }

        @Override
        public void run()
        {
            try
            {
                presence.publishPresenceStatus(status, "");
            }
            catch (IllegalArgumentException e1)
            {

                logger.error("Error - changing status", e1);
            }
            catch (IllegalStateException e1)
            {

                logger.error("Error - changing status", e1);
            }
            catch (OperationFailedException e1)
            {
                if (e1.getErrorCode()
                    == OperationFailedException.GENERAL_ERROR)
                {
                    String msgText =
                        GlobalDisplayDetailsActivator.getResources()
                            .getI18NString(
                            "service.gui.STATUS_CHANGE_GENERAL_ERROR",
                            new String[]{
                                protocolProvider.getAccountID().getUserID(),
                                protocolProvider.getAccountID().getService()});

                    GlobalDisplayDetailsActivator.getAlertUIService()
                        .showAlertDialog(
                            GlobalDisplayDetailsActivator.getResources()
                                .getI18NString("service.gui.GENERAL_ERROR"),
                            msgText,
                            e1);
                }
                else if (e1.getErrorCode()
                    == OperationFailedException.NETWORK_FAILURE)
                {
                    String msgText =
                        GlobalDisplayDetailsActivator.getResources()
                            .getI18NString(
                            "service.gui.STATUS_CHANGE_NETWORK_FAILURE",
                            new String[]{
                                protocolProvider.getAccountID().getUserID(),
                                protocolProvider.getAccountID().getService()});

                    GlobalDisplayDetailsActivator.getAlertUIService()
                        .showAlertDialog(
                            msgText,
                            GlobalDisplayDetailsActivator.getResources()
                                .getI18NString("service.gui.NETWORK_FAILURE"),
                            e1);
                }
                else if (e1.getErrorCode()
                        == OperationFailedException.PROVIDER_NOT_REGISTERED)
                {
                    String msgText =
                        GlobalDisplayDetailsActivator.getResources()
                            .getI18NString(
                            "service.gui.STATUS_CHANGE_NETWORK_FAILURE",
                            new String[]{
                                protocolProvider.getAccountID().getUserID(),
                                protocolProvider.getAccountID().getService()});

                    GlobalDisplayDetailsActivator.getAlertUIService()
                    .showAlertDialog(
                        GlobalDisplayDetailsActivator.getResources()
                            .getI18NString("service.gui.NETWORK_FAILURE"),
                        msgText,
                        e1);
                }
                logger.error("Error - changing status", e1);
            }
        }
    }
}