| 67 | | const char *name, GaimPrefType type, gconstpointer val, gpointer data) { |
| 68 | | if (is_away) { |
| 69 | | if (gaim_prefs_get_bool("/plugins/gtk/autoprofile/queue_messages_when_away")) { |
| 70 | | gaim_prefs_set_string ("/gaim/gtk/conversations/im/hide_new", "away"); |
| 71 | | } else { |
| 72 | | gaim_prefs_set_string ("/gaim/gtk/conversations/im/hide_new", "never"); |
| | 72 | const char *name, GaimPrefType type, gconstpointer val, gpointer data) { |
| | 73 | if (is_away) { |
| | 74 | if (gaim_prefs_get_bool("/plugins/gtk/autoprofile/queue_messages_when_away")) { |
| | 75 | gaim_prefs_set_string ("/gaim/gtk/conversations/im/hide_new", "away"); |
| | 76 | } else { |
| | 77 | gaim_prefs_set_string ("/gaim/gtk/conversations/im/hide_new", "never"); |
| | 78 | } |
| 78 | | static gboolean plugin_load (GaimPlugin *plugin) |
| 79 | | { |
| 80 | | int interval; |
| 81 | | GList *comp_list; |
| 82 | | struct component *comp; |
| 83 | | |
| 84 | | /* TODO: This should go into a gtk_load or something like that */ |
| 85 | | gaim_prefs_connect_callback ( |
| 86 | | plugin_handle, |
| 87 | | "/plugins/gtk/autoprofile/queue_messages_when_away", queue_cb, NULL); |
| 88 | | |
| 89 | | |
| 90 | | /* Initialize variables */ |
| 91 | | components = get_components (); |
| 92 | | is_away = FALSE; |
| 93 | | sending_auto = FALSE; |
| 94 | | response_timeout = time (NULL); |
| 95 | | |
| 96 | | plugin_handle = plugin; |
| 97 | | |
| 98 | | /* Let components initialize */ |
| 99 | | comp_list = components; |
| 100 | | while (comp_list) { |
| 101 | | comp = comp_list->data; |
| 102 | | if (comp->load) |
| 103 | | (comp->load) (); |
| 104 | | comp_list = comp_list->next; |
| 105 | | } |
| 106 | | |
| 107 | | /* Begin updating profiles */ |
| 108 | | interval = 60 * 1000 * gaim_prefs_get_int ( |
| 109 | | "/plugins/gtk/autoprofile/delay_profile"); |
| 110 | | profile_timeout = GINT_TO_POINTER (g_timeout_add ( |
| 111 | | interval, profile_update, NULL)); |
| 112 | | profile_update (NULL); |
| 113 | | |
| 114 | | /* Connect command detector */ |
| 115 | | gaim_cmd_register ("away", "S", GAIM_CMD_P_PLUGIN, |
| 116 | | GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "", |
| 117 | | cmd_away_cb, |
| 118 | | "away <text>: Activate AutoProfile away with optional text " |
| 119 | | "added to message", NULL); |
| 120 | | |
| 121 | | gaim_cmd_register ("back", "", GAIM_CMD_P_PLUGIN, |
| 122 | | GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "", |
| 123 | | cmd_back_cb, |
| 124 | | "back: Turn off AutoProfile away status", NULL); |
| | 83 | static gboolean plugin_load (GaimPlugin *plugin) { |
| | 84 | int interval; |
| | 85 | GList *comp_list; |
| | 86 | struct component *comp; |
| | 87 | |
| | 88 | /* TODO: This should go into a gtk_load or something like that */ |
| | 89 | gaim_prefs_connect_callback ( |
| | 90 | plugin_handle, |
| | 91 | "/plugins/gtk/autoprofile/queue_messages_when_away", queue_cb, NULL); |
| | 92 | |
| | 93 | |
| | 94 | /* Initialize variables */ |
| | 95 | components = get_components (); |
| | 96 | is_away = FALSE; |
| | 97 | sending_auto = FALSE; |
| | 98 | response_timeout = time (NULL); |
| | 99 | |
| | 100 | plugin_handle = plugin; |
| | 101 | |
| | 102 | /* Let components initialize */ |
| | 103 | comp_list = components; |
| | 104 | while (comp_list) { |
| | 105 | comp = comp_list->data; |
| | 106 | if (comp->load) |
| | 107 | (comp->load) (); |
| | 108 | comp_list = comp_list->next; |
| | 109 | } |
| 126 | | return TRUE; |
| | 111 | /* Begin updating profiles */ |
| | 112 | interval = 60 * 1000 * gaim_prefs_get_int ( |
| | 113 | "/plugins/gtk/autoprofile/delay_profile"); |
| | 114 | profile_timeout = GINT_TO_POINTER (g_timeout_add ( |
| | 115 | interval, profile_update, NULL)); |
| | 116 | profile_update (NULL); |
| | 117 | |
| | 118 | /* Connect command detector */ |
| | 119 | gaim_cmd_register ("away", "S", GAIM_CMD_P_PLUGIN, |
| | 120 | GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "", |
| | 121 | cmd_away_cb, |
| | 122 | "away <text>: Activate AutoProfile away with optional text " |
| | 123 | "added to message", NULL); |
| | 124 | |
| | 125 | gaim_cmd_register ("back", "", GAIM_CMD_P_PLUGIN, |
| | 126 | GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "", |
| | 127 | cmd_back_cb, |
| | 128 | "back: Turn off AutoProfile away status", NULL); |
| | 129 | |
| | 130 | return TRUE; |
| 130 | | static gboolean plugin_unload (GaimPlugin *plugin) |
| 131 | | { |
| 132 | | GList *comp_list; |
| 133 | | struct component *comp; |
| 134 | | |
| 135 | | /* Remove global variables */ |
| 136 | | g_source_remove (GPOINTER_TO_INT (profile_timeout)); |
| 137 | | |
| 138 | | /* Unload components */ |
| 139 | | comp_list = components; |
| 140 | | while (comp_list) { |
| 141 | | comp = comp_list->data; |
| 142 | | if (comp->unload) // Make sure init_pref not null |
| 143 | | (comp->unload) (); |
| 144 | | comp_list = comp_list->next; |
| 145 | | } |
| 146 | | |
| 147 | | /* Not sure if component contents should be free'd as well */ |
| 148 | | g_list_free (components); |
| 149 | | components = NULL; |
| 150 | | |
| 151 | | /* Remove command detector */ |
| 152 | | gaim_cmd_unregister (cmd_away_id); |
| 153 | | gaim_cmd_unregister (cmd_back_id); |
| | 134 | static gboolean plugin_unload (GaimPlugin *plugin) { |
| | 135 | GList *comp_list; |
| | 136 | struct component *comp; |
| | 137 | |
| | 138 | /* Remove global variables */ |
| | 139 | g_source_remove (GPOINTER_TO_INT (profile_timeout)); |
| | 140 | |
| | 141 | /* Unload components */ |
| | 142 | comp_list = components; |
| | 143 | while (comp_list) { |
| | 144 | comp = comp_list->data; |
| | 145 | if (comp->unload) // Make sure init_pref not null |
| | 146 | (comp->unload) (); |
| | 147 | comp_list = comp_list->next; |
| | 148 | } |
| 163 | | static GaimPluginInfo info = |
| 164 | | { |
| 165 | | GAIM_PLUGIN_MAGIC, |
| 166 | | GAIM_MAJOR_VERSION, |
| 167 | | GAIM_MINOR_VERSION, |
| 168 | | GAIM_PLUGIN_STANDARD, /* type */ |
| 169 | | GAIM_GTK_PLUGIN_TYPE, /* ui_requirement */ |
| 170 | | 0, /* flags */ |
| 171 | | NULL, /* dependencies */ |
| 172 | | GAIM_PRIORITY_DEFAULT, /* priority */ |
| 173 | | |
| 174 | | N_("gtk-kluge-autoprofile"), /* id */ |
| 175 | | N_("AutoProfile"), /* name */ |
| 176 | | AUTOPROFILE_VERSION, /* version */ |
| 177 | | N_("User profile and away message management system"),/* summary */ |
| 178 | | /* description */ |
| 179 | | N_("Allows user to set up automatically updating\n" |
| 180 | | "away messages and profiles that contain dynamic " |
| 181 | | "text"), |
| 182 | | /* author */ |
| 183 | | N_("Casey Ho <caseyho at berkeley-edu>" |
| 184 | | "\n\t\t\taim:caseyho"), |
| 185 | | N_("http://hkn.eecs.berkeley.edu/~casey/" |
| 186 | | "autoprofile/"), /* homepage */ |
| 187 | | |
| 188 | | plugin_load, /* load */ |
| 189 | | plugin_unload, /* unload */ |
| 190 | | NULL, /* destroy */ |
| 191 | | |
| 192 | | &ui_info, /* ui_info */ |
| 193 | | NULL, /* extra_info */ |
| 194 | | NULL, /* prefs_info */ |
| 195 | | actions /* actions */ |
| | 166 | static GaimPluginInfo info = { |
| | 167 | GAIM_PLUGIN_MAGIC, |
| | 168 | GAIM_MAJOR_VERSION, |
| | 169 | GAIM_MINOR_VERSION, |
| | 170 | GAIM_PLUGIN_STANDARD, /* type */ |
| | 171 | GAIM_GTK_PLUGIN_TYPE, /* ui_requirement */ |
| | 172 | 0, /* flags */ |
| | 173 | NULL, /* dependencies */ |
| | 174 | GAIM_PRIORITY_DEFAULT, /* priority */ |
| | 175 | |
| | 176 | N_("gtk-kluge-autoprofile"), /* id */ |
| | 177 | N_("AutoProfile"), /* name */ |
| | 178 | AUTOPROFILE_VERSION, /* version */ |
| | 179 | N_("User profile and away message management system"),/* summary */ |
| | 180 | /* description */ |
| | 181 | N_("Allows user to set up automatically updating\n" |
| | 182 | "away messages and profiles that contain dynamic " |
| | 183 | "text"), |
| | 184 | /* author */ |
| | 185 | N_("Casey Ho <caseyho at berkeley-edu>" |
| | 186 | "\n\t\t\taim:caseyho"), |
| | 187 | N_("http://hkn.eecs.berkeley.edu/~casey/" |
| | 188 | "autoprofile/"), /* homepage */ |
| | 189 | |
| | 190 | plugin_load, /* load */ |
| | 191 | plugin_unload, /* unload */ |
| | 192 | NULL, /* destroy */ |
| | 193 | |
| | 194 | &ui_info, /* ui_info */ |
| | 195 | NULL, /* extra_info */ |
| | 196 | NULL, /* prefs_info */ |
| | 197 | actions /* actions */ |
| 204 | | char *output, *single_char, *cur_addition, *cur_addition_copy; |
| 205 | | |
| 206 | | GList *search_list; |
| 207 | | struct component *cur_comp; |
| 208 | | int space_left; |
| 209 | | int state; |
| 210 | | |
| 211 | | /* Set up strings */ |
| 212 | | output = (char *)malloc (sizeof(char) * AP_SIZE_MAXIMUM); |
| 213 | | *output = '\0'; |
| 214 | | single_char = (char *)malloc(2); |
| 215 | | *(single_char + 1) = '\0'; |
| 216 | | *single_char = 'a'; |
| 217 | | |
| 218 | | space_left = AP_SIZE_MAXIMUM - 1; |
| 219 | | |
| 220 | | /* When previous char was a %, state is 1, otherwise 0 */ |
| 221 | | state = 0; |
| 222 | | /* Process the format string, one char at a time! */ |
| 223 | | while (*format && space_left > 0) { |
| 224 | | if (state == 1) { |
| 225 | | /* Handle percentage value */ |
| 226 | | if (*format == '%') { |
| 227 | | /* Copy char straight over */ |
| 228 | | *single_char = *format++; |
| 229 | | strcat (output, single_char); |
| 230 | | space_left--; |
| 231 | | } else if (*format == 'a') { |
| 232 | | /* Copy string in */ |
| 233 | | cur_addition = (char *)gaim_prefs_get_string ( |
| 234 | | "/plugins/gtk/autoprofile/added_text"); |
| 235 | | if (strlen (cur_addition) < space_left) { |
| 236 | | strcat (output, cur_addition); |
| 237 | | space_left = space_left - strlen (cur_addition); |
| 238 | | } else { |
| 239 | | auto_debug ("generate", "added text too large, dropped"); |
| 240 | | } |
| 241 | | format++; |
| 242 | | } else if (*format == 'n' || |
| 243 | | *format == 't' || |
| 244 | | *format == 'd') { |
| 245 | | /* Copy %char straight over */ |
| 246 | | if (space_left > 1) { |
| 247 | | *single_char = '%'; |
| 248 | | strcat (output, single_char); |
| 249 | | *single_char = *format++; |
| 250 | | strcat (output, single_char); |
| 251 | | space_left = space_left - 2; |
| 252 | | } |
| 253 | | } else { |
| 254 | | /* Generate some string associated with char */ |
| 255 | | search_list = components; |
| 256 | | while (TRUE) { |
| 257 | | if (search_list == NULL) { |
| 258 | | auto_debug ("generate", "no matching component found "); |
| 259 | | if (space_left < 2) |
| 260 | | break; |
| 261 | | *single_char = '%'; |
| 262 | | strcat (output, single_char); |
| 263 | | *single_char = *format; |
| 264 | | strcat (output, single_char); |
| 265 | | space_left = space_left - 2; |
| 266 | | break; |
| 267 | | } else { |
| 268 | | cur_comp = (struct component *)search_list->data; |
| 269 | | if (cur_comp->format_char == *format) { |
| 270 | | cur_addition = (cur_comp->generate)(); |
| 271 | | /* Check for NULL component output */ |
| 272 | | if (!cur_addition) |
| 273 | | break; |
| 274 | | /* Insert <br> for \n to get more accurate size */ |
| 275 | | cur_addition_copy = gaim_strdup_withhtml (cur_addition); |
| 276 | | free (cur_addition); |
| 277 | | if (strlen (cur_addition_copy) < space_left) { |
| 278 | | strcat (output, cur_addition_copy); |
| 279 | | space_left = space_left - strlen (cur_addition_copy); |
| 280 | | } else { |
| 281 | | auto_debug ("generate", "component too large, dropped"); |
| 282 | | } |
| | 206 | char *output, *single_char, *cur_addition, *cur_addition_copy; |
| 284 | | free (cur_addition_copy); |
| 285 | | break; |
| | 208 | GList *search_list; |
| | 209 | struct component *cur_comp; |
| | 210 | int space_left; |
| | 211 | int state; |
| | 212 | |
| | 213 | /* Set up strings */ |
| | 214 | output = (char *)malloc (sizeof(char) * AP_SIZE_MAXIMUM); |
| | 215 | *output = '\0'; |
| | 216 | single_char = (char *)malloc(2); |
| | 217 | *(single_char + 1) = '\0'; |
| | 218 | *single_char = 'a'; |
| | 219 | |
| | 220 | space_left = AP_SIZE_MAXIMUM - 1; |
| | 221 | |
| | 222 | /* When previous char was a %, state is 1, otherwise 0 */ |
| | 223 | state = 0; |
| | 224 | /* Process the format string, one char at a time! */ |
| | 225 | while (*format && space_left > 0) { |
| | 226 | if (state == 1) { |
| | 227 | /* Handle percentage value */ |
| | 228 | if (*format == '%') { |
| | 229 | /* Copy char straight over */ |
| | 230 | *single_char = *format++; |
| | 231 | strcat (output, single_char); |
| | 232 | space_left--; |
| | 233 | } else if (*format == 'a') { |
| | 234 | /* Copy string in */ |
| | 235 | cur_addition = (char *)gaim_prefs_get_string ( |
| | 236 | "/plugins/gtk/autoprofile/added_text"); |
| | 237 | if (strlen (cur_addition) < space_left) { |
| | 238 | strcat (output, cur_addition); |
| | 239 | space_left = space_left - strlen (cur_addition); |
| | 240 | } else { |
| | 241 | auto_debug ("generate", "added text too large, dropped"); |
| | 242 | } |
| | 243 | format++; |
| | 244 | } else if (*format == 'n' || |
| | 245 | *format == 't' || |
| | 246 | *format == 'd') { |
| | 247 | /* Copy %char straight over */ |
| | 248 | if (space_left > 1) { |
| | 249 | *single_char = '%'; |
| | 250 | strcat (output, single_char); |
| | 251 | *single_char = *format++; |
| | 252 | strcat (output, single_char); |
| | 253 | space_left = space_left - 2; |
| | 254 | } |
| 287 | | search_list = search_list->next; |
| | 256 | /* Generate some string associated with char */ |
| | 257 | search_list = components; |
| | 258 | while (TRUE) { |
| | 259 | if (search_list == NULL) { |
| | 260 | auto_debug ("generate", "no matching component found "); |
| | 261 | if (space_left < 2) |
| | 262 | break; |
| | 263 | *single_char = '%'; |
| | 264 | strcat (output, single_char); |
| | 265 | *single_char = *format; |
| | 266 | strcat (output, single_char); |
| | 267 | space_left = space_left - 2; |
| | 268 | break; |
| | 269 | } else { |
| | 270 | cur_comp = (struct component *)search_list->data; |
| | 271 | if (cur_comp->format_char == *format) { |
| | 272 | cur_addition = (cur_comp->generate)(); |
| | 273 | /* Check for NULL component output */ |
| | 274 | if (!cur_addition) |
| | 275 | break; |
| | 276 | /* Insert <br> for \n to get more accurate size */ |
| | 277 | cur_addition_copy = gaim_strdup_withhtml (cur_addition); |
| | 278 | free (cur_addition); |
| | 279 | if (strlen (cur_addition_copy) < space_left) { |
| | 280 | strcat (output, cur_addition_copy); |
| | 281 | space_left = space_left - strlen (cur_addition_copy); |
| | 282 | } else { |
| | 283 | auto_debug ("generate", "component too large, dropped"); |
| | 284 | } |
| | 285 | |
| | 286 | free (cur_addition_copy); |
| | 287 | break; |
| | 288 | } else { |
| | 289 | search_list = search_list->next; |
| | 290 | |
| | 291 | } |
| | 292 | } |
| | 293 | } |
| 337 | | while (TRUE) { |
| 338 | | if (accounts == NULL) { |
| 339 | | gaim_notify_error (NULL, NULL, |
| 340 | | _("No accounts have been activated to go away"), |
| 341 | | _("Toggle the desired accounts under the accounts tab in " |
| 342 | | "AutoProfile preferences")); |
| 343 | | status_back (); |
| 344 | | return FALSE; |
| 345 | | } |
| 346 | | current = (GaimAccount *)accounts->data; |
| 347 | | if (gaim_account_is_connected (current) && |
| 348 | | get_account_boolean (current, "enable_away")) |
| 349 | | break; |
| 350 | | accounts = accounts->next; |
| 351 | | } |
| 352 | | |
| 353 | | interval = 60 * 1000 * gaim_prefs_get_int ( |
| 354 | | "/plugins/gtk/autoprofile/delay_away"); |
| 355 | | |
| 356 | | /* Disable troublesome variable values */ |
| 357 | | if (!is_away) { |
| 358 | | original_autoreply = strdup (gaim_prefs_get_string ( |
| 359 | | "/core/away/auto_reply")); |
| 360 | | if (!strcmp (original_autoreply, "never")) { |
| 361 | | original_autoresponse = FALSE; |
| | 329 | if (gaim_prefs_get_bool ("/plugins/gtk/autoprofile/queue_messages_when_away")) { |
| | 330 | gaim_prefs_set_string ("/gaim/gtk/conversations/im/hide_new", "away"); |
| 369 | | is_away = TRUE; |
| 370 | | if (away_timeout) |
| 371 | | g_source_remove (away_timeout); |
| 372 | | away_timeout = g_timeout_add (interval, away_update, NULL); |
| 373 | | away_update (NULL); |
| | 338 | while (TRUE) { |
| | 339 | if (accounts == NULL) { |
| | 340 | gaim_notify_error (NULL, NULL, |
| | 341 | _("No accounts have been activated to go away"), |
| | 342 | _("Toggle the desired accounts under the accounts tab in " |
| | 343 | "AutoProfile preferences")); |
| | 344 | status_back (); |
| | 345 | return FALSE; |
| | 346 | } |
| | 347 | current = (GaimAccount *)accounts->data; |
| | 348 | if (gaim_account_is_connected (current) && |
| | 349 | get_account_boolean (current, "enable_away")) |
| | 350 | break; |
| | 351 | accounts = accounts->next; |
| | 352 | } |
| 375 | | return TRUE; |
| | 354 | interval = 60 * 1000 * gaim_prefs_get_int ( |
| | 355 | "/plugins/gtk/autoprofile/delay_away"); |
| | 356 | |
| | 357 | /* Disable troublesome variable values */ |
| | 358 | if (!is_away) { |
| | 359 | original_autoreply = strdup (gaim_prefs_get_string ( |
| | 360 | "/purple/away/auto_reply")); |
| | 361 | if (!strcmp (original_autoreply, "never")) { |
| | 362 | original_autoresponse = FALSE; |
| | 363 | } else { |
| | 364 | original_autoresponse = TRUE; |
| | 365 | } |
| | 366 | } |
| | 367 | |
| | 368 | gaim_prefs_set_string ("/purple/away/auto_reply", "never"); |
| | 369 | |
| | 370 | is_away = TRUE; |
| | 371 | if (away_timeout) |
| | 372 | g_source_remove (away_timeout); |
| | 373 | away_timeout = g_timeout_add (interval, away_update, NULL); |
| | 374 | away_update (NULL); |
| | 375 | |
| | 376 | return TRUE; |