about summary refs log blame commit diff stats
path: root/view.c
blob: b2ee32f06721a71c405d7f0914545738ba3a4073 (plain) (tree)
= RESOURCE_CHAT; } else if (strcmp(setting, "away") == 0) { result = RESOURCE_AWAY; } else if (strcmp(setting, "xa") == 0) { result = RESOURCE_XA; } else if (strcmp(setting, "dnd") == 0) { result = RESOURCE_DND; } else if (strcmp(setting, "last") == 0) { result = accounts_get_last_presence(account_name); } else { log_warning("Error reading presence.login for account: '%s', value: '%s', defaulting to 'online'", account_name, setting); result = RESOURCE_ONLINE; } if (setting != NULL) { g_free(setting); } return result; } static void _fix_legacy_accounts(const char * const account_name) { // set barejid and resource const char *barejid = account_name; const char *resource = "profanity"; Jid *jid = jid_create(account_name); if (jid != NULL) { barejid = jid->barejid; if (jid->resourcepart != NULL) { resource = jid->resourcepart; } } // accounts with no jid property if (!g_key_file_has_key(accounts, account_name, "jid", NULL)) { g_key_file_set_string(accounts, account_name, "jid", barejid); _save_accounts(); } // accounts with no resource, property if (!g_key_file_has_key(accounts, account_name, "resource", NULL)) { g_key_file_set_string(accounts, account_name, "resource", resource); _save_accounts(); } // acounts with no muc service or nick if (!g_key_file_has_key(accounts, account_name, "muc.service", NULL)) { gchar *account_jid = g_key_file_get_string(accounts, account_name, "jid", NULL); Jid *jidp = jid_create(account_jid); GString *muc_service = g_string_new("conference."); g_string_append(muc_service, jidp->domainpart); g_key_file_set_string(accounts, account_name, "muc.service", muc_service->str); g_string_free(muc_service, TRUE); jid_destroy(jidp); } if (!g_key_file_has_key(accounts, account_name, "muc.nick", NULL)) { gchar *account_jid = g_key_file_get_string(accounts, account_name, "jid", NULL); Jid *jidp = jid_create(account_jid); if (jidp->localpart == NULL) { g_key_file_set_string(accounts, account_name, "muc.nick", jidp->domainpart); } else { g_key_file_set_string(accounts, account_name, "muc.nick", jidp->localpart); } jid_destroy(jidp); } jid_destroy(jid); } static void _save_accounts(void) { gsize g_data_size; gchar *g_accounts_data = g_key_file_to_data(accounts, &g_data_size, NULL); gchar *xdg_data = xdg_get_data_home(); GString *base_str = g_string_new(xdg_data); g_string_append(base_str, "/profanity/"); gchar *true_loc = get_file_or_linked(accounts_loc, base_str->str); g_file_set_contents(true_loc, g_accounts_data, g_data_size, NULL); g_chmod(accounts_loc, S_IRUSR | S_IWUSR); g_free(xdg_data); free(true_loc); g_free(g_accounts_data); g_string_free(base_str, TRUE); } static gchar * _get_accounts_file(void) { gchar *xdg_data = xdg_get_data_home(); GString *logfile = g_string_new(xdg_data); g_string_append(logfile, "/profanity/accounts"); gchar *result = strdup(logfile->str); g_free(xdg_data); g_string_free(logfile, TRUE); return result; }