Tue, 01 Jun 2004 01:55:55 +0000
[gaim-migrate @ 9941]
make deryni's removed placement option a plugin
| 9157 | 1 | #include "internal.h" |
| 2 | #include "conversation.h" | |
| 3 | ||
| 4 | #define EXTPLACEMENT_OPT "/plugins/core/nosnilmot/extplacement" | |
| 5 | ||
| 6 | static void | |
| 7 | conv_placement_last_created_win_split(GaimConversation *conv) | |
| 8 | { | |
| 9 | GaimConvWindow *win; | |
| 10 | ||
| 11 | win = gaim_get_last_window_with_type(gaim_conversation_get_type(conv)); | |
| 12 | ||
| 13 | if (win == NULL) { | |
| 14 | win = gaim_conv_window_new(); | |
| 15 | ||
| 16 | gaim_conv_window_add_conversation(win, conv); | |
| 17 | gaim_conv_window_show(win); | |
| 18 | } | |
| 19 | else | |
| 20 | gaim_conv_window_add_conversation(win, conv); | |
| 21 | } | |
| 22 | ||
| 23 | static void | |
| 24 | conv_placement_by_number(GaimConversation *conv) | |
| 25 | { | |
| 26 | GaimConvWindow *win = NULL; | |
| 27 | ||
| 28 | if (gaim_prefs_get_bool("/core/conversations/combine_chat_im")) | |
| 29 | win = g_list_last(gaim_get_windows())->data; | |
| 30 | else | |
| 31 | win = gaim_get_last_window_with_type(gaim_conversation_get_type(conv)); | |
| 32 | ||
| 33 | if (win == NULL) { | |
| 34 | win = gaim_conv_window_new(); | |
| 35 | ||
| 36 | gaim_conv_window_add_conversation(win, conv); | |
| 37 | gaim_conv_window_show(win); | |
| 38 | } else { | |
| 39 | int max_count = gaim_prefs_get_int(EXTPLACEMENT_OPT "/placement_number"); | |
| 40 | int count = gaim_conv_window_get_conversation_count(win); | |
| 41 | ||
| 42 | if (count < max_count) | |
| 43 | gaim_conv_window_add_conversation(win, conv); | |
| 44 | else { | |
| 45 | GList *l = NULL; | |
| 46 | ||
| 47 | for (l = gaim_get_windows(); l != NULL; l = l->next) { | |
| 48 | win = (GaimConvWindow *)l->data; | |
| 49 | ||
| 50 | count = gaim_conv_window_get_conversation_count(win); | |
| 51 | if (count < max_count) { | |
| 52 | gaim_conv_window_add_conversation(win, conv); | |
| 53 | return; | |
| 54 | } | |
| 55 | } | |
| 56 | win = gaim_conv_window_new(); | |
| 57 | ||
| 58 | gaim_conv_window_add_conversation(win, conv); | |
| 59 | gaim_conv_window_show(win); | |
| 60 | } | |
| 61 | } | |
| 62 | } | |
| 63 | ||
| 64 | static gboolean | |
| 65 | plugin_load(GaimPlugin *plugin) | |
| 66 | { | |
| 67 | gaim_prefs_add_none("/plugins/core/nosnilmot"); | |
| 68 | gaim_prefs_add_none("/plugins/core/nosnilmot/extplacement"); | |
| 69 | gaim_prefs_add_int(EXTPLACEMENT_OPT "/placement_number", 4); | |
| 70 | gaim_conv_placement_add_fnc("im_chat", _("Separate IM and Chat windows"), | |
| 71 | &conv_placement_last_created_win_split); | |
| 72 | gaim_conv_placement_add_fnc("number", _("By conversation count"), | |
| 73 | &conv_placement_by_number); | |
| 74 | return TRUE; | |
| 75 | } | |
| 76 | ||
| 77 | static gboolean | |
| 78 | plugin_unload(GaimPlugin *plugin) | |
| 79 | { | |
| 80 | gaim_conv_placement_remove_fnc("im_chat"); | |
| 81 | gaim_conv_placement_remove_fnc("number"); | |
| 82 | return TRUE; | |
| 83 | } | |
| 84 | ||
| 85 | static GaimPluginPrefFrame * | |
| 86 | get_plugin_pref_frame(GaimPlugin *plugin) { | |
| 87 | GaimPluginPrefFrame *frame; | |
| 88 | GaimPluginPref *ppref; | |
| 89 | ||
| 90 | frame = gaim_plugin_pref_frame_new(); | |
| 91 | ||
| 92 | ppref = gaim_plugin_pref_new_with_label("Conversation Placement"); | |
| 93 | gaim_plugin_pref_frame_add(frame, ppref); | |
| 94 | ||
| 95 | ppref = gaim_plugin_pref_new_with_name_and_label( | |
| 96 | EXTPLACEMENT_OPT "/placement_number", | |
| 97 | "Number of conversations per window"); | |
| 98 | gaim_plugin_pref_set_bounds(ppref, 1, 50); | |
| 99 | gaim_plugin_pref_frame_add(frame, ppref); | |
| 100 | ||
| 101 | return frame; | |
| 102 | } | |
| 103 | ||
| 104 | static GaimPluginUiInfo prefs_info = { | |
| 105 | get_plugin_pref_frame | |
| 106 | }; | |
| 107 | ||
| 108 | static GaimPluginInfo info = | |
| 109 | { | |
| 110 | GAIM_PLUGIN_API_VERSION, /**< api_version */ | |
| 111 | GAIM_PLUGIN_STANDARD, /**< type */ | |
| 112 | NULL, /**< ui_requirement */ | |
| 113 | 0, /**< flags */ | |
| 114 | NULL, /**< dependencies */ | |
| 115 | GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 116 | ||
| 117 | "core-nosnilmot-extplacement", /**< id */ | |
| 118 | N_("ExtPlacement"), /**< name */ | |
| 119 | VERSION, /**< version */ | |
| 120 | /** summary */ | |
| 121 | N_("Extra conversation placement options."), | |
| 122 | /** description */ | |
| 123 | N_("Either restrict the number of conversations per windows" | |
| 124 | " or use separate windows for IMs and Chats"), | |
| 125 | "Stu Tomlinson <stu@nosnilmot.com>", /**< author */ | |
| 126 | "http://www.nosnilmot.com/gaim/plugins/", /**< homepage */ | |
| 127 | ||
| 128 | plugin_load, /**< load */ | |
| 129 | plugin_unload, /**< unload */ | |
| 130 | NULL, /**< destroy */ | |
| 131 | ||
| 132 | NULL, /**< ui_info */ | |
| 133 | NULL, /**< extra_info */ | |
| 134 | &prefs_info, /**< prefs_info */ | |
| 135 | NULL /**< actions */ | |
| 136 | }; | |
| 137 | ||
| 138 | static void | |
| 139 | init_plugin(GaimPlugin *plugin) | |
| 140 | { | |
| 141 | } | |
| 142 | ||
| 143 | GAIM_INIT_PLUGIN(extplacement, init_plugin, info) |