~ken-vandine/telepathy-indicator/lp_1046360

« back to all changes in this revision

Viewing changes to src/indicator-approver.c

  • Committer: Ken VanDine
  • Date: 2012-10-09 20:17:04 UTC
  • Revision ID: ken.vandine@canonical.com-20121009201704-07s1vaz1pbibh4a1
don't register with messaging menu unless we have enabled IM accounts

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
#include <unity.h>
32
32
#include <messaging-menu.h>
 
33
#include <libaccounts-glib/accounts-glib.h>
33
34
 
34
35
static MessagingMenuApp *mmapp;
35
36
GHashTable *dispatch_ops;
978
979
        tp_account_manager_set_all_requested_presences (tp_am, status, "", "");
979
980
}
980
981
 
981
 
int
982
 
main (int argc, char **argv)
 
982
 
 
983
int setup ()
983
984
{
984
 
        GMainLoop *loop = NULL;
985
985
        TpConnectionPresenceType presence;
986
986
 
987
 
        g_type_init ();
988
 
 
989
 
        gtk_init (&argc, &argv);
990
987
        TpBaseClient *approver;
991
988
        TpBaseClient *observer;
992
989
 
993
 
        loop = g_main_loop_new (NULL, FALSE);
994
990
 
995
991
        TpAccountManager *tp_am = tp_account_manager_dup ();
996
992
 
1008
1004
        }
1009
1005
 
1010
1006
        mmapp = messaging_menu_app_new ("empathy.desktop");
1011
 
        messaging_menu_app_register (mmapp);
1012
1007
 
1013
1008
        g_signal_connect (mmapp, "activate-source",
1014
1009
                          G_CALLBACK (message_source_activated), tp_am);
1022
1017
 
1023
1018
        dispatch_ops = g_hash_table_new_full (g_str_hash, g_str_equal,
1024
1019
                                              g_free, g_object_unref);
1025
 
 
1026
1020
        launcher = unity_launcher_entry_get_for_desktop_id ("empathy.desktop");
1027
1021
 
1028
1022
        contact_list_setup (tp_am);
 
1023
}
 
1024
 
 
1025
gboolean check_ag_enabled_accounts ()
 
1026
{
 
1027
        gboolean r = FALSE;
 
1028
        AgManager* ag = ag_manager_new_for_service_type ("IM");
 
1029
        GList* account_list = ag_manager_get_enabled_account_services (ag);
 
1030
 
 
1031
        GList* account_service_list = NULL;
 
1032
        for (account_service_list = account_list; account_service_list != NULL; account_service_list = account_service_list->next) {
 
1033
                AgAccountService* account_service = NULL;
 
1034
                account_service = (AgAccountService*) account_service_list->data;
 
1035
                AgAccount* account;
 
1036
                account = ag_account_service_get_account (account_service);
 
1037
                g_message ("ENABLED: %s", ag_account_get_provider_name (account));
 
1038
        }
 
1039
        if (g_list_length (account_list) > 0)
 
1040
                r = TRUE;
 
1041
 
 
1042
        g_list_free (account_list);
 
1043
        g_list_free (account_service_list);
 
1044
        g_object_unref(G_OBJECT(ag));
 
1045
        return r;
 
1046
}
 
1047
 
 
1048
static void on_enabled_event (AgManager* self, guint account_id)
 
1049
{
 
1050
        if (check_ag_enabled_accounts ())
 
1051
        {
 
1052
                messaging_menu_app_register (mmapp);
 
1053
        } else
 
1054
        {
 
1055
                messaging_menu_app_unregister (mmapp);
 
1056
        }
 
1057
}
 
1058
 
 
1059
        
 
1060
 
 
1061
int
 
1062
main (int argc, char **argv)
 
1063
{
 
1064
        int ret = 0;
 
1065
        GMainLoop *loop = NULL;
 
1066
        g_type_init ();
 
1067
        gtk_init (&argc, &argv);
 
1068
 
 
1069
        loop = g_main_loop_new (NULL, FALSE);
 
1070
 
 
1071
        AgManager* ag = ag_manager_new_for_service_type ("IM");
 
1072
 
 
1073
        ret = setup ();
 
1074
        if (ret == 1)
 
1075
                return ret;
 
1076
 
 
1077
        if (check_ag_enabled_accounts ())
 
1078
                messaging_menu_app_register (mmapp);
 
1079
 
 
1080
        g_signal_connect (ag, "enabled-event", G_CALLBACK (on_enabled_event), NULL);
1029
1081
 
1030
1082
        g_debug ("Telepathy Indicator started");
1031
1083
        g_main_loop_run (loop);
1032
1084
 
1033
1085
        g_main_loop_unref (loop);
1034
 
        return 0;
 
1086
        return ret;
1035
1087
}