From df14a46d4864eecbb0344eb05dcb929f72954871 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 12 Sep 2013 23:30:35 +0100 Subject: Allow users to set default muc service and nickname per account See #238 Conflicts: src/config/accounts.c --- src/config/accounts.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/config/accounts.h | 4 +++ 2 files changed, 99 insertions(+), 1 deletion(-) (limited to 'src/config') diff --git a/src/config/accounts.c b/src/config/accounts.c index 3e3daec0..b903d6be 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -39,7 +39,15 @@ static GKeyFile *accounts; static Autocomplete all_ac; static Autocomplete enabled_ac; -static gchar *string_keys[] = {"jid", "server", "resource", "presence.last", "presence.login"}; +static gchar *string_keys[] = { + "jid", + "server", + "resource", + "presence.last", + "presence.login", + "muc.service", + "muc.nick" +}; static void _fix_legacy_accounts(const char * const account_name); static void _save_accounts(void); @@ -129,6 +137,19 @@ accounts_add(const char *account_name, const char *altdomain) if (altdomain != NULL) { g_key_file_set_string(accounts, account_name, "server", altdomain); } + + Jid *jidp = jid_create(barejid); + 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); + 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); + g_key_file_set_string(accounts, account_name, "presence.last", "online"); g_key_file_set_string(accounts, account_name, "presence.login", "online"); g_key_file_set_integer(accounts, account_name, "priority.online", 0); @@ -220,6 +241,27 @@ accounts_get_account(const char * const name) account->priority_xa = g_key_file_get_integer(accounts, name, "priority.xa", NULL); account->priority_dnd = g_key_file_get_integer(accounts, name, "priority.dnd", NULL); + gchar *muc_service = g_key_file_get_string(accounts, name, "muc.service", NULL); + if (muc_service == NULL) { + GString *g_muc_service = g_string_new("conference."); + Jid *jidp = jid_create(account->jid); + g_string_append(g_muc_service, jidp->domainpart); + account->muc_service = strdup(g_muc_service->str); + g_string_free(g_muc_service, TRUE); + jid_destroy(jidp); + } else { + account->muc_service = strdup(muc_service); + } + + gchar *muc_nick = g_key_file_get_string(accounts, name, "muc.nick", NULL); + if (muc_nick == NULL) { + Jid *jidp = jid_create(account->jid); + account->muc_nick = strdup(jidp->localpart); + jid_destroy(jidp); + } else { + account->muc_nick = strdup(muc_nick); + } + // get room history account->room_history = NULL; gsize history_size = 0; @@ -250,6 +292,8 @@ accounts_free_account(ProfAccount *account) free(account->server); free(account->last_presence); free(account->login_presence); + free(account->muc_service); + free(account->muc_nick); free(account); } } @@ -344,6 +388,17 @@ accounts_set_jid(const char * const account_name, const char * const value) if (jid->resourcepart != NULL) { g_key_file_set_string(accounts, account_name, "resource", jid->resourcepart); } + + GString *muc_service = g_string_new("conference."); + g_string_append(muc_service, jid->domainpart); + g_key_file_set_string(accounts, account_name, "muc.service", muc_service->str); + g_string_free(muc_service, TRUE); + if (jid->localpart == NULL) { + g_key_file_set_string(accounts, account_name, "muc.nick", jid->domainpart); + } else { + g_key_file_set_string(accounts, account_name, "muc.nick", jid->localpart); + } + _save_accounts(); } } @@ -367,6 +422,24 @@ accounts_set_resource(const char * const account_name, const char * const value) } } +void +accounts_set_muc_service(const char * const account_name, const char * const value) +{ + if (accounts_account_exists(account_name)) { + g_key_file_set_string(accounts, account_name, "muc.service", value); + _save_accounts(); + } +} + +void +accounts_set_muc_nick(const char * const account_name, const char * const value) +{ + if (accounts_account_exists(account_name)) { + g_key_file_set_string(accounts, account_name, "muc.nick", value); + _save_accounts(); + } +} + void accounts_set_priority_online(const char * const account_name, const gint value) { @@ -558,6 +631,27 @@ _fix_legacy_accounts(const char * const account_name) _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); } diff --git a/src/config/accounts.h b/src/config/accounts.h index d74e8fe5..4c74a523 100644 --- a/src/config/accounts.h +++ b/src/config/accounts.h @@ -37,6 +37,8 @@ typedef struct prof_account_t { gint priority_away; gint priority_xa; gint priority_dnd; + gchar *muc_service; + gchar *muc_nick; gboolean enabled; GSList *room_history; } ProfAccount; @@ -60,6 +62,8 @@ gboolean accounts_account_exists(const char * const account_name); void accounts_set_jid(const char * const account_name, const char * const value); void accounts_set_server(const char * const account_name, const char * const value); void accounts_set_resource(const char * const account_name, const char * const value); +void accounts_set_muc_service(const char * const account_name, const char * const value); +void accounts_set_muc_nick(const char * const account_name, const char * const value); void accounts_set_last_presence(const char * const account_name, const char * const value); void accounts_set_login_presence(const char * const account_name, const char * const value); resource_presence_t accounts_get_login_presence(const char * const account_name); -- cgit 1.4.1-2-gfad0 3'>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