Mercurial > pidgin.yaz
comparison plugins/napster.c @ 1427:28278bd61403
[gaim-migrate @ 1437]
Basic search support. This will continue to improve.
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Thu, 25 Jan 2001 20:31:12 +0000 |
parents | 9d8cf2e12e68 |
children | 336fc98b7f90 |
comparison
equal
deleted
inserted
replaced
1426:de21a6790603 | 1427:28278bd61403 |
---|---|
46 | 46 |
47 GSList *nap_connections = NULL; | 47 GSList *nap_connections = NULL; |
48 | 48 |
49 static unsigned int chat_id = 0; | 49 static unsigned int chat_id = 0; |
50 | 50 |
51 struct search_window { | |
52 GtkWidget *window; | |
53 GtkWidget *list; | |
54 }; | |
55 | |
51 struct browse_window { | 56 struct browse_window { |
52 GtkWidget *window; | 57 GtkWidget *window; |
53 GtkWidget *list; | 58 GtkWidget *list; |
54 struct gaim_connection *gc; | 59 struct gaim_connection *gc; |
55 char *name; | 60 char *name; |
86 GSList *channels; | 91 GSList *channels; |
87 GSList *requests; | 92 GSList *requests; |
88 GSList *browses; | 93 GSList *browses; |
89 }; | 94 }; |
90 | 95 |
96 static struct search_window *search_dialog = NULL; | |
97 | |
91 static char *nap_name() | 98 static char *nap_name() |
92 { | 99 { |
93 return "Napster"; | 100 return "Napster"; |
94 } | 101 } |
95 | 102 |
122 struct nap_data *ndata = (struct nap_data *)gc->proto_data; | 129 struct nap_data *ndata = (struct nap_data *)gc->proto_data; |
123 gchar buf[NAP_BUF_LEN]; | 130 gchar buf[NAP_BUF_LEN]; |
124 | 131 |
125 g_snprintf(buf, NAP_BUF_LEN, "%s \"%s\"", who, file); | 132 g_snprintf(buf, NAP_BUF_LEN, "%s \"%s\"", who, file); |
126 | 133 |
134 printf("%s\n", buf); | |
135 printf("%d\n", ndata->fd); | |
127 nap_write_packet(gc, 0xCB, buf); | 136 nap_write_packet(gc, 0xCB, buf); |
128 } | 137 } |
138 | |
139 // FIXME: These next two windows should really be together | |
140 // and should use the same clist style look too. | |
129 | 141 |
130 void nap_handle_download(GtkCList *clist, gint row, gint col, GdkEventButton *event, gpointer user_data) | 142 void nap_handle_download(GtkCList *clist, gint row, gint col, GdkEventButton *event, gpointer user_data) |
131 { | 143 { |
132 gchar **results; | 144 gchar **results; |
133 struct browse_window *bw = (struct browse_window *)user_data; | 145 struct browse_window *bw = (struct browse_window *)user_data; |
134 | 146 |
135 gtk_clist_get_text(GTK_CLIST(bw->list), row, 0, results); | 147 gtk_clist_get_text(GTK_CLIST(clist), row, 0, results); |
136 | 148 |
137 nap_send_download_req(bw->gc, bw->name, results[0]); | 149 nap_send_download_req(bw->gc, bw->name, results[0]); |
138 | 150 |
151 } | |
152 | |
153 void nap_handle_download_search(GtkCList *clist, gint row, gint col, GdkEventButton *event, gpointer user_data) | |
154 { | |
155 gchar *filename; | |
156 gchar *nick; | |
157 | |
158 int i = 0; | |
159 struct gaim_connection *gc = (struct gaim_connection *)user_data; | |
160 | |
161 filename = (gchar *)gtk_clist_get_row_data(GTK_CLIST(clist), row); | |
162 | |
163 gtk_clist_get_text(GTK_CLIST(clist), row, 1, &nick); | |
164 | |
165 printf("Trying to download: %s from %s\n", filename, nick); | |
166 nap_send_download_req(gc, nick, filename); | |
139 } | 167 } |
140 | 168 |
141 struct browse_window *browse_window_new(struct gaim_connection *gc, char *name) | 169 struct browse_window *browse_window_new(struct gaim_connection *gc, char *name) |
142 { | 170 { |
143 struct browse_window *browse = g_new0(struct browse_window, 1); | 171 struct browse_window *browse = g_new0(struct browse_window, 1); |
466 buf = (gchar *)g_malloc(sizeof(gchar) * (len + 1)); | 494 buf = (gchar *)g_malloc(sizeof(gchar) * (len + 1)); |
467 | 495 |
468 read(source, buf, len); | 496 read(source, buf, len); |
469 | 497 |
470 buf[len] = 0; | 498 buf[len] = 0; |
499 | |
500 printf("DEBUG: %s\n", buf); | |
471 | 501 |
472 if (command == 0xd6) { | 502 if (command == 0xd6) { |
473 res = g_strsplit(buf, " ", 0); | 503 res = g_strsplit(buf, " ", 0); |
474 /* Do we want to report what the users are doing? */ | 504 /* Do we want to report what the users are doing? */ |
475 printf("users: %s, files: %s, size: %sGB\n", res[0], res[1], res[2]); | 505 printf("users: %s, files: %s, size: %sGB\n", res[0], res[1], res[2]); |
647 browse_window_add_file(bw, file); | 677 browse_window_add_file(bw, file); |
648 | 678 |
649 free(buf); | 679 free(buf); |
650 return; | 680 return; |
651 | 681 |
682 } | |
683 | |
684 if (command == 0xc9) { | |
685 /* We've received a search response */ | |
686 gchar *file = (gchar *)g_malloc(sizeof(gchar) * (NAP_BUF_LEN+1)); | |
687 gchar *tmp; | |
688 gchar rest[NAP_BUF_LEN]; | |
689 gchar *data[5]; | |
690 gchar **parse_name; | |
691 | |
692 int i, j; | |
693 | |
694 for (i = 1, j = 0; buf[i] != '\"'; i++, j++) | |
695 { | |
696 file[j] = buf[i]; | |
697 } | |
698 | |
699 file[j] = 0; i++; | |
700 | |
701 tmp = (gchar *)g_malloc(sizeof(gchar) * (strlen(file) + 1)); | |
702 strcpy(tmp, rindex(file, '\\')+1); | |
703 | |
704 strcpy(rest, buf+i); | |
705 | |
706 parse_name = g_strsplit(rest, " ", 0); | |
707 | |
708 data[0] = g_strdup(tmp); | |
709 data[1] = g_strdup(parse_name[6]); | |
710 data[2] = g_strdup(parse_name[2]); | |
711 data[3] = g_strdup(parse_name[3]); | |
712 data[4] = g_strdup(parse_name[8]); | |
713 | |
714 // printf("File: %s, 1: %s, 2: %s, 3: %s\n", data[0], data[1], data[2], data[3]); | |
715 i = gtk_clist_append(GTK_CLIST(search_dialog->list), data); | |
716 | |
717 gtk_clist_set_row_data(GTK_CLIST(search_dialog->list), i, file); | |
718 g_strfreev(parse_name); | |
719 // g_free(file); | |
720 g_free(tmp); | |
721 g_free(buf); | |
722 return; | |
723 } | |
724 | |
725 if (command == 0xca) | |
726 { | |
727 /* End of search */ | |
728 g_free(buf); | |
729 return; | |
652 } | 730 } |
653 | 731 |
654 if (command == 0x12d) { | 732 if (command == 0x12d) { |
655 /* Our buddy was added successfully */ | 733 /* Our buddy was added successfully */ |
656 free(buf); | 734 free(buf); |
765 char c; | 843 char c; |
766 char z[4]; | 844 char z[4]; |
767 int i; | 845 int i; |
768 int status; | 846 int status; |
769 | 847 |
770 host = gethostbyname("n184.napster.com"); | 848 host = gethostbyname("208.184.216.87"); |
771 | 849 |
772 if (!host) { | 850 if (!host) { |
773 hide_login_progress(gc, "Unable to resolve hostname"); | 851 hide_login_progress(gc, "Unable to resolve hostname"); |
774 signoff(gc); | 852 signoff(gc); |
775 return; | 853 return; |
794 } | 872 } |
795 | 873 |
796 ndata->fd = fd; | 874 ndata->fd = fd; |
797 | 875 |
798 /* And write our signon data */ | 876 /* And write our signon data */ |
799 g_snprintf(buf, NAP_BUF_LEN, "%s %s 0 \"Gaim - Napster Plugin\" 0", gc->username, gc->password); | 877 g_snprintf(buf, NAP_BUF_LEN, "%s %s 0 \"gaimster\" 0", gc->username, gc->password); |
800 nap_write_packet(gc, 0x02, buf); | 878 nap_write_packet(gc, 0x02, buf); |
801 | 879 |
802 /* And set up the input watcher */ | 880 /* And set up the input watcher */ |
803 ndata->inpa = gdk_input_add(ndata->fd, GDK_INPUT_READ, nap_login_callback, gc); | 881 ndata->inpa = gdk_input_add(ndata->fd, GDK_INPUT_READ, nap_login_callback, gc); |
804 | 882 |
941 | 1019 |
942 g_snprintf(buf, NAP_BUF_LEN, "%s", who); | 1020 g_snprintf(buf, NAP_BUF_LEN, "%s", who); |
943 nap_write_packet(gc, 0xd3, buf); | 1021 nap_write_packet(gc, 0xd3, buf); |
944 } | 1022 } |
945 | 1023 |
1024 void nap_find_callback(GtkObject *w, GtkWidget *entry) | |
1025 { | |
1026 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); | |
1027 gchar *search; | |
1028 gchar buf[NAP_BUF_LEN]; | |
1029 | |
1030 search = gtk_entry_get_text(GTK_ENTRY(entry)); | |
1031 g_snprintf(buf, NAP_BUF_LEN, "FILENAME CONTAINS \"%s\" MAX_RESULTS 50", search); | |
1032 | |
1033 nap_write_packet(gc, 0xc8, buf); | |
1034 } | |
1035 | |
1036 void destroy_window(GtkObject *w, GtkWidget *win) | |
1037 { | |
1038 gtk_widget_destroy(win); | |
1039 } | |
1040 | |
1041 void nap_show_search(GtkObject *w, void *omit) | |
1042 { | |
1043 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); | |
1044 | |
1045 if (!search_dialog) | |
1046 { | |
1047 GtkWidget *window; | |
1048 GtkWidget *sw; | |
1049 GtkWidget *vbox; | |
1050 GtkWidget *hbox; | |
1051 GtkWidget *label; | |
1052 GtkWidget *button; | |
1053 GtkWidget *entry; | |
1054 GtkWidget *list; | |
1055 gchar *titles[5] = {"Mp3 Name", "Nick", "Size", "Bitrate", "Connection"}; | |
1056 search_dialog = g_new0(struct search_window, 1); | |
1057 | |
1058 window = gtk_window_new(GTK_WINDOW_DIALOG); | |
1059 | |
1060 vbox = gtk_vbox_new(FALSE, 0); | |
1061 | |
1062 /* First Line */ | |
1063 hbox = gtk_hbox_new(FALSE, 5); | |
1064 label = gtk_label_new("Search for:"); | |
1065 gtk_widget_show(label); | |
1066 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
1067 | |
1068 entry = gtk_entry_new(); | |
1069 gtk_widget_show(entry); | |
1070 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5); | |
1071 | |
1072 button = gtk_button_new_with_label("Find"); | |
1073 gtk_widget_show(button); | |
1074 gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
1075 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(nap_find_callback), entry); | |
1076 | |
1077 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
1078 | |
1079 button = gtk_button_new_with_label("Cancel"); | |
1080 gtk_widget_show(button); | |
1081 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
1082 | |
1083 | |
1084 gtk_widget_show(hbox); | |
1085 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
1086 /* End First List */ | |
1087 | |
1088 /* Second Line */ | |
1089 | |
1090 sw = gtk_scrolled_window_new(NULL, NULL); | |
1091 | |
1092 list = gtk_clist_new_with_titles(5, titles); | |
1093 | |
1094 gtk_clist_column_titles_show(GTK_CLIST(list)); | |
1095 | |
1096 gtk_signal_connect(GTK_OBJECT(list), "select-row", GTK_SIGNAL_FUNC(nap_handle_download_search), gc); | |
1097 | |
1098 gtk_container_add(GTK_CONTAINER(sw), list); | |
1099 gtk_widget_show(list); | |
1100 | |
1101 gtk_box_pack_start(GTK_BOX(vbox), sw, FALSE, FALSE, 5); | |
1102 | |
1103 gtk_widget_show(sw); | |
1104 | |
1105 /* End Second Line */ | |
1106 | |
1107 gtk_widget_show(vbox); | |
1108 | |
1109 gtk_container_add(GTK_CONTAINER(window), vbox); | |
1110 gtk_container_set_border_width(GTK_CONTAINER(window), 10); | |
1111 | |
1112 gtk_widget_set_usize(GTK_WIDGET(list), 500, 350); | |
1113 gtk_widget_set_usize(GTK_WIDGET(window), 500, 400); | |
1114 | |
1115 gtk_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(destroy_window), window); | |
1116 gtk_widget_show(window); | |
1117 | |
1118 search_dialog->window = window; | |
1119 search_dialog->list = list; | |
1120 } | |
1121 | |
1122 gtk_widget_show(search_dialog->window); | |
1123 } | |
1124 | |
946 static void nap_action_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) | 1125 static void nap_action_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) |
947 { | 1126 { |
948 GtkWidget *button; | 1127 GtkWidget *button; |
949 | 1128 |
950 button = gtk_menu_item_new_with_label("List Files"); | 1129 button = gtk_menu_item_new_with_label("Browse Files"); |
951 gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(nap_send_browse), who); | 1130 gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(nap_send_browse), who); |
1131 gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
1132 gtk_menu_append(GTK_MENU(menu), button); | |
1133 gtk_widget_show(button); | |
1134 | |
1135 button = gtk_menu_item_new_with_label("Search Napster"); | |
1136 gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(nap_show_search), NULL); | |
952 gtk_object_set_user_data(GTK_OBJECT(button), gc); | 1137 gtk_object_set_user_data(GTK_OBJECT(button), gc); |
953 gtk_menu_append(GTK_MENU(menu), button); | 1138 gtk_menu_append(GTK_MENU(menu), button); |
954 gtk_widget_show(button); | 1139 gtk_widget_show(button); |
955 } | 1140 } |
956 | 1141 |