comparison src/dialogs.c @ 5882:ea6dfabdf60f

[gaim-migrate @ 6314] The Add Buddy and Add Chat dialogs now have protocol icons. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sun, 15 Jun 2003 06:03:13 +0000
parents 1b85ff65be57
children 390d32a6b130
comparison
equal deleted inserted replaced
5881:cc7870e1e3b3 5882:ea6dfabdf60f
917 917
918 gtk_widget_show_all(a->window); 918 gtk_widget_show_all(a->window);
919 gtk_widget_grab_focus(GTK_WIDGET(a->entry)); 919 gtk_widget_grab_focus(GTK_WIDGET(a->entry));
920 } 920 }
921 921
922 static void addbuddy_select_account(GObject *w, GaimConnection *gc) 922 static void
923 { 923 addbuddy_select_account(GObject *w, GaimAccount *account,
924 struct addbuddy *b = g_object_get_data(w, "addbuddy"); 924 struct addbuddy *b)
925 925 {
926 /* Save our account */ 926 /* Save our account */
927 b->gc = gc; 927 b->gc = gaim_account_get_connection(account);
928 }
929
930 static void create_online_user_names(struct addbuddy *b)
931 {
932 char buf[2048]; /* Never hurts to be safe ;-) */
933 GList *g = gaim_connections_get_all();
934 GaimConnection *c;
935 GaimAccount *account;
936 GtkWidget *menu, *opt;
937 int count = 0;
938 int place = 0;
939
940 menu = gtk_menu_new();
941
942 while (g) {
943 c = (GaimConnection *)g->data;
944
945 account = gaim_connection_get_account(c);
946
947 g_snprintf(buf, sizeof(buf), "%s (%s)",
948 gaim_account_get_username(account),
949 c->prpl->info->name);
950 opt = gtk_menu_item_new_with_label(buf);
951 g_object_set_data(G_OBJECT(opt), "addbuddy", b);
952 g_signal_connect(G_OBJECT(opt), "activate",
953 G_CALLBACK(addbuddy_select_account),
954 c);
955 gtk_widget_show(opt);
956 gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt);
957
958 /* Now check to see if it's our current menu */
959 if (c == b->gc) {
960 place = count;
961 gtk_menu_item_activate(GTK_MENU_ITEM(opt));
962 gtk_option_menu_set_history(GTK_OPTION_MENU(b->account), count);
963
964 /* Do the cha cha cha */
965 }
966
967 count++;
968
969 g = g->next;
970 }
971
972 gtk_option_menu_remove_menu(GTK_OPTION_MENU(b->account));
973 gtk_option_menu_set_menu(GTK_OPTION_MENU(b->account), menu);
974 gtk_option_menu_set_history(GTK_OPTION_MENU(b->account), place);
975
976 gtk_widget_show(b->account);
977 gtk_widget_show(b->account->parent);
978
979 } 928 }
980 929
981 void show_add_buddy(GaimConnection *gc, char *buddy, char *group, char *alias) 930 void show_add_buddy(GaimConnection *gc, char *buddy, char *group, char *alias)
982 { 931 {
983 GtkWidget *table; 932 GtkWidget *table;
1064 /* Set up stuff for the account box */ 1013 /* Set up stuff for the account box */
1065 label = gtk_label_new(_("Add To")); 1014 label = gtk_label_new(_("Add To"));
1066 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); 1015 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1067 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4); 1016 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4);
1068 1017
1069 a->account = gtk_option_menu_new(); 1018 a->account = gaim_gtk_account_option_menu_new(NULL, FALSE,
1019 G_CALLBACK(addbuddy_select_account), a);
1020
1070 gtk_table_attach_defaults(GTK_TABLE(table), a->account, 1, 2, 3, 4); 1021 gtk_table_attach_defaults(GTK_TABLE(table), a->account, 1, 2, 3, 4);
1071 1022
1072 create_online_user_names(a);
1073
1074 /* End of account box */ 1023 /* End of account box */
1075 1024
1076 g_signal_connect(G_OBJECT(a->window), "response", G_CALLBACK(do_add_buddy), a); 1025 g_signal_connect(G_OBJECT(a->window), "response",
1026 G_CALLBACK(do_add_buddy), a);
1077 1027
1078 gtk_widget_show_all(a->window); 1028 gtk_widget_show_all(a->window);
1079 1029
1080 if (group != NULL) 1030 if (group != NULL)
1081 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(a->combo)->entry), group); 1031 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(a->combo)->entry), group);
1221 } 1171 }
1222 1172
1223 static void create_online_account_menu_for_add_chat(struct addchat *ac) 1173 static void create_online_account_menu_for_add_chat(struct addchat *ac)
1224 { 1174 {
1225 char buf[2048]; /* Never hurts to be safe ;-) */ 1175 char buf[2048]; /* Never hurts to be safe ;-) */
1226 GList *g = gaim_connections_get_all(); 1176 GList *g;
1227 GaimConnection *c; 1177 GaimConnection *c;
1228 GaimAccount *account; 1178 GaimAccount *account;
1229 GtkWidget *menu, *opt; 1179 GtkWidget *menu, *opt;
1180 GtkWidget *hbox;
1181 GtkWidget *label;
1182 GtkWidget *image;
1183 GdkPixbuf *pixbuf;
1184 GdkPixbuf *scale;
1185 GtkSizeGroup *sg;
1186 char *filename;
1187 const char *proto_name;
1230 int count = 0; 1188 int count = 0;
1231 int place = 0; 1189 int place = 0;
1232 1190
1233 menu = gtk_menu_new(); 1191 menu = gtk_menu_new();
1234 1192
1235 while (g) { 1193 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1194
1195 for (g = gaim_connections_get_all(); g != NULL; g = g->next) {
1196 GaimPluginProtocolInfo *prpl_info = NULL;
1197 GaimPlugin *plugin;
1198
1236 c = (GaimConnection *)g->data; 1199 c = (GaimConnection *)g->data;
1237 account = gaim_connection_get_account(c); 1200 account = gaim_connection_get_account(c);
1238 1201
1239 if (GAIM_PLUGIN_PROTOCOL_INFO(c->prpl)->join_chat) { 1202 plugin = c->prpl;
1240 g_snprintf(buf, sizeof(buf), "%s (%s)", 1203
1241 gaim_account_get_username(account), 1204 if (plugin == NULL)
1242 c->prpl->info->name); 1205 continue;
1243 opt = gtk_menu_item_new_with_label(buf); 1206
1244 g_object_set_data(G_OBJECT(opt), "addchat", ac); 1207 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin);
1245 g_signal_connect(G_OBJECT(opt), "activate", 1208
1246 G_CALLBACK(addchat_select_account), 1209 if (prpl_info == NULL || prpl_info->join_chat == NULL)
1247 c); 1210 continue;
1248 gtk_widget_show(opt); 1211
1249 gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt); 1212 opt = gtk_menu_item_new();
1250 1213
1251 /* Now check to see if it's our current menu */ 1214 /* Create the hbox. */
1252 if (c->account == ac->account) { 1215 hbox = gtk_hbox_new(FALSE, 4);
1253 place = count; 1216 gtk_container_add(GTK_CONTAINER(opt), hbox);
1254 gtk_menu_item_activate(GTK_MENU_ITEM(opt)); 1217 gtk_widget_show(hbox);
1255 gtk_option_menu_set_history(GTK_OPTION_MENU(ac->account_menu), count); 1218
1256 1219 /* Load the image. */
1257 /* Do the cha cha cha */ 1220 if (prpl_info != NULL) {
1221 proto_name = prpl_info->list_icon(NULL, NULL);
1222 g_snprintf(buf, sizeof(buf), "%s.png", proto_name);
1223
1224 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status",
1225 "default", buf, NULL);
1226 pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
1227 g_free(filename);
1228
1229 if (pixbuf != NULL) {
1230 /* Scale and insert the image */
1231 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16,
1232 GDK_INTERP_BILINEAR);
1233 image = gtk_image_new_from_pixbuf(scale);
1234
1235 g_object_unref(G_OBJECT(pixbuf));
1236 g_object_unref(G_OBJECT(scale));
1258 } 1237 }
1259 1238 else
1260 count++; 1239 image = gtk_image_new();
1261 } 1240 }
1262 1241 else
1263 g = g->next; 1242 image = gtk_image_new();
1264 } 1243
1244 gtk_size_group_add_widget(sg, image);
1245
1246 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
1247 gtk_widget_show(image);
1248
1249 g_snprintf(buf, sizeof(buf), "%s (%s)",
1250 gaim_account_get_username(account),
1251 c->prpl->info->name);
1252
1253 /* Create the label. */
1254 label = gtk_label_new(buf);
1255 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
1256 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1257 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
1258 gtk_widget_show(label);
1259
1260
1261 g_object_set_data(G_OBJECT(opt), "addchat", ac);
1262 g_signal_connect(G_OBJECT(opt), "activate",
1263 G_CALLBACK(addchat_select_account), c);
1264 gtk_widget_show(opt);
1265 gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt);
1266
1267 /* Now check to see if it's our current menu */
1268 if (c->account == ac->account) {
1269 place = count;
1270 gtk_menu_item_activate(GTK_MENU_ITEM(opt));
1271 gtk_option_menu_set_history(GTK_OPTION_MENU(ac->account_menu),
1272 count);
1273
1274 /* Do the cha cha cha */
1275 }
1276
1277 count++;
1278 }
1279
1280 g_object_unref(sg);
1265 1281
1266 gtk_option_menu_remove_menu(GTK_OPTION_MENU(ac->account_menu)); 1282 gtk_option_menu_remove_menu(GTK_OPTION_MENU(ac->account_menu));
1267 gtk_option_menu_set_menu(GTK_OPTION_MENU(ac->account_menu), menu); 1283 gtk_option_menu_set_menu(GTK_OPTION_MENU(ac->account_menu), menu);
1268 gtk_option_menu_set_history(GTK_OPTION_MENU(ac->account_menu), place); 1284 gtk_option_menu_set_history(GTK_OPTION_MENU(ac->account_menu), place);
1269 } 1285 }