Mercurial > pidgin.yaz
comparison src/util.c @ 2379:cacaf7ace3a5
[gaim-migrate @ 2392]
reorganization of some functions.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 28 Sep 2001 01:25:02 +0000 |
parents | 2927c2c26fe6 |
children | 569ae9f2bb89 |
comparison
equal
deleted
inserted
replaced
2378:dfaf5d9d433e | 2379:cacaf7ace3a5 |
---|---|
29 #include <sys/time.h> | 29 #include <sys/time.h> |
30 #include <sys/types.h> | 30 #include <sys/types.h> |
31 #include <sys/stat.h> | 31 #include <sys/stat.h> |
32 #include <string.h> | 32 #include <string.h> |
33 #include <sys/wait.h> | 33 #include <sys/wait.h> |
34 #include <gtk/gtk.h> | |
35 #include <ctype.h> | 34 #include <ctype.h> |
36 #include <math.h> | 35 #include <math.h> |
37 #include <pixmaps/aimicon.xpm> | |
38 #include "gaim.h" | 36 #include "gaim.h" |
39 #include "prpl.h" | 37 #include "prpl.h" |
40 | |
41 static GdkPixmap *icon_pm = NULL; | |
42 static GdkBitmap *icon_bm = NULL; | |
43 | 38 |
44 char *full_date() | 39 char *full_date() |
45 { | 40 { |
46 char *date; | 41 char *date; |
47 time_t tme; | 42 time_t tme; |
471 return open_log_file(name); | 466 return open_log_file(name); |
472 else | 467 else |
473 return open_gaim_log_file("system", &x); | 468 return open_gaim_log_file("system", &x); |
474 } | 469 } |
475 | 470 |
476 char *escape_text2(const char *msg) | |
477 { | |
478 char *c, *cpy; | |
479 char *woo; | |
480 int cnt = 0; | |
481 /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */ | |
482 if (strlen(msg) > BUF_LEN) { | |
483 fprintf(stderr, "Warning: truncating message to 2048 bytes\n"); | |
484 } | |
485 | |
486 woo = malloc(strlen(msg) * 4 + 1); | |
487 cpy = g_strndup(msg, 2048); | |
488 c = cpy; | |
489 while (*c) { | |
490 switch (*c) { | |
491 case '\n': | |
492 woo[cnt++] = '<'; | |
493 woo[cnt++] = 'B'; | |
494 woo[cnt++] = 'R'; | |
495 woo[cnt++] = '>'; | |
496 break; | |
497 case '{': | |
498 case '}': | |
499 case '\\': | |
500 case '"': | |
501 woo[cnt++] = '\\'; | |
502 /* Fall through */ | |
503 default: | |
504 woo[cnt++] = *c; | |
505 } | |
506 c++; | |
507 } | |
508 woo[cnt] = '\0'; | |
509 | |
510 g_free(cpy); | |
511 return woo; | |
512 } | |
513 | |
514 | |
515 char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" "0123456789+/"; | 471 char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" "0123456789+/"; |
516 | 472 |
517 | 473 |
518 char *tobase64(const char *text) | 474 char *tobase64(const char *text) |
519 { | 475 { |
677 | 633 |
678 if (pid == 0) | 634 if (pid == 0) |
679 return TRUE; | 635 return TRUE; |
680 | 636 |
681 return FALSE; | 637 return FALSE; |
682 } | |
683 | |
684 void aol_icon(GdkWindow *w) | |
685 { | |
686 #ifndef _WIN32 | |
687 if (icon_pm == NULL) { | |
688 icon_pm = gdk_pixmap_create_from_xpm_d(w, &icon_bm, NULL, (gchar **)aimicon_xpm); | |
689 } | |
690 gdk_window_set_icon(w, NULL, icon_pm, icon_bm); | |
691 if (mainwindow) | |
692 gdk_window_set_group(w, mainwindow->window); | |
693 #endif | |
694 } | 638 } |
695 | 639 |
696 struct aim_user *find_user(const char *name, int protocol) | 640 struct aim_user *find_user(const char *name, int protocol) |
697 { | 641 { |
698 char *who = g_strdup(normalize(name)); | 642 char *who = g_strdup(normalize(name)); |
770 } | 714 } |
771 cpy[cnt] = '\0'; | 715 cpy[cnt] = '\0'; |
772 return (cpy); | 716 return (cpy); |
773 } | 717 } |
774 | 718 |
775 GtkWidget *picture_button(GtkWidget *window, char *text, char **xpm) | |
776 { | |
777 GtkWidget *button; | |
778 GtkWidget *button_box, *button_box_2, *button_box_3; | |
779 GtkWidget *label; | |
780 GdkBitmap *mask; | |
781 GdkPixmap *pm; | |
782 GtkWidget *pixmap; | |
783 | |
784 button = gtk_button_new(); | |
785 if (misc_options & OPT_MISC_COOL_LOOK) | |
786 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
787 | |
788 button_box = gtk_hbox_new(FALSE, 5); | |
789 gtk_container_add(GTK_CONTAINER(button), button_box); | |
790 | |
791 button_box_2 = gtk_hbox_new(FALSE, 0); | |
792 button_box_3 = gtk_hbox_new(FALSE, 0); | |
793 gtk_box_pack_start(GTK_BOX(button_box), button_box_2, TRUE, TRUE, 0); | |
794 gtk_box_pack_start(GTK_BOX(button_box), button_box_3, TRUE, TRUE, 0); | |
795 pm = gdk_pixmap_create_from_xpm_d(window->window, &mask, NULL, xpm); | |
796 pixmap = gtk_pixmap_new(pm, mask); | |
797 gtk_box_pack_end(GTK_BOX(button_box_2), pixmap, FALSE, FALSE, 0); | |
798 | |
799 if (text) { | |
800 label = gtk_label_new(text); | |
801 gtk_box_pack_start(GTK_BOX(button_box_3), label, FALSE, FALSE, 2); | |
802 gtk_widget_show(label); | |
803 } | |
804 | |
805 gtk_widget_show(pixmap); | |
806 gtk_widget_show(button_box_2); | |
807 gtk_widget_show(button_box_3); | |
808 gtk_widget_show(button_box); | |
809 | |
810 /* this causes clipping on lots of buttons with long text */ | |
811 /* gtk_widget_set_usize(button, 75, 30);*/ | |
812 gtk_widget_show(button); | |
813 gdk_pixmap_unref(pm); | |
814 gdk_bitmap_unref(mask); | |
815 | |
816 return button; | |
817 } | |
818 | |
819 static GtkTooltips *button_tips = NULL; | |
820 GtkWidget *picture_button2(GtkWidget *window, char *text, char **xpm, short dispstyle) | |
821 { | |
822 GtkWidget *button; | |
823 GtkWidget *button_box, *button_box_2; | |
824 GdkBitmap *mask; | |
825 GdkPixmap *pm; | |
826 GtkWidget *pixmap; | |
827 GtkWidget *label; | |
828 | |
829 if (!button_tips) | |
830 button_tips = gtk_tooltips_new(); | |
831 button = gtk_button_new(); | |
832 if (misc_options & OPT_MISC_COOL_LOOK) | |
833 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
834 | |
835 button_box = gtk_hbox_new(FALSE, 0); | |
836 gtk_container_add(GTK_CONTAINER(button), button_box); | |
837 | |
838 button_box_2 = gtk_vbox_new(FALSE, 0); | |
839 | |
840 gtk_box_pack_start(GTK_BOX(button_box), button_box_2, TRUE, TRUE, 0); | |
841 gtk_widget_show(button_box_2); | |
842 gtk_widget_show(button_box); | |
843 if (dispstyle == 2 || dispstyle == 0) { | |
844 pm = gdk_pixmap_create_from_xpm_d(window->window, &mask, NULL, xpm); | |
845 pixmap = gtk_pixmap_new(pm, mask); | |
846 gtk_box_pack_start(GTK_BOX(button_box_2), pixmap, FALSE, FALSE, 0); | |
847 | |
848 gtk_widget_show(pixmap); | |
849 | |
850 gdk_pixmap_unref(pm); | |
851 gdk_bitmap_unref(mask); | |
852 } | |
853 | |
854 if (dispstyle == 2 || dispstyle == 1) { | |
855 label = gtk_label_new(text); | |
856 gtk_widget_show(label); | |
857 gtk_box_pack_end(GTK_BOX(button_box_2), label, FALSE, FALSE, 0); | |
858 } | |
859 | |
860 gtk_tooltips_set_tip(button_tips, button, text, "Gaim"); | |
861 gtk_widget_show(button); | |
862 return button; | |
863 } | |
864 | 719 |
865 | 720 |
866 /* remove leading whitespace from a string */ | 721 /* remove leading whitespace from a string */ |
867 char *remove_spaces(char *str) | 722 char *remove_spaces(char *str) |
868 { | 723 { |
1042 | 897 |
1043 g_free(tmp); | 898 g_free(tmp); |
1044 return buf; | 899 return buf; |
1045 } | 900 } |
1046 | 901 |
1047 int set_dispstyle(int chat) | |
1048 { | |
1049 int dispstyle; | |
1050 | |
1051 if (chat) { | |
1052 switch (chat_options & (OPT_CHAT_BUTTON_TEXT | OPT_CHAT_BUTTON_XPM)) { | |
1053 case OPT_CHAT_BUTTON_TEXT: | |
1054 dispstyle = 1; | |
1055 break; | |
1056 case OPT_CHAT_BUTTON_XPM: | |
1057 dispstyle = 0; | |
1058 break; | |
1059 default: /* both or neither */ | |
1060 dispstyle = 2; | |
1061 break; | |
1062 } | |
1063 } else { | |
1064 switch (im_options & (OPT_IM_BUTTON_TEXT | OPT_IM_BUTTON_XPM)) { | |
1065 case OPT_IM_BUTTON_TEXT: | |
1066 dispstyle = 1; | |
1067 break; | |
1068 case OPT_IM_BUTTON_XPM: | |
1069 dispstyle = 0; | |
1070 break; | |
1071 default: /* both or neither */ | |
1072 dispstyle = 2; | |
1073 break; | |
1074 } | |
1075 } | |
1076 return dispstyle; | |
1077 } | |
1078 | |
1079 | |
1080 void show_usage(int mode, char *name) | 902 void show_usage(int mode, char *name) |
1081 { | 903 { |
1082 switch (mode) { | 904 switch (mode) { |
1083 case 0: /* full help text */ | 905 case 0: /* full help text */ |
1084 printf("Usage: %s [OPTION]...\n\n" | 906 printf("Usage: %s [OPTION]...\n\n" |
1097 break; | 919 break; |
1098 } | 920 } |
1099 } | 921 } |
1100 | 922 |
1101 | 923 |
1102 void set_first_user(char *name) | |
1103 { | |
1104 struct aim_user *u; | |
1105 | |
1106 u = find_user(name, -1); | |
1107 | |
1108 if (!u) { /* new user */ | |
1109 u = g_new0(struct aim_user, 1); | |
1110 g_snprintf(u->username, sizeof(u->username), "%s", name); | |
1111 u->protocol = DEFAULT_PROTO; | |
1112 aim_users = g_list_prepend(aim_users, u); | |
1113 } else { /* user already exists */ | |
1114 aim_users = g_list_remove(aim_users, u); | |
1115 aim_users = g_list_prepend(aim_users, u); | |
1116 } | |
1117 save_prefs(); | |
1118 } | |
1119 | |
1120 | |
1121 /* <name> is a comma-separated list of names, or NULL | 924 /* <name> is a comma-separated list of names, or NULL |
1122 if NULL and there is at least one user defined in .gaimrc, try to login. | 925 if NULL and there is at least one user defined in .gaimrc, try to login. |
1123 if not NULL, parse <name> into separate strings, look up each one in | 926 if not NULL, parse <name> into separate strings, look up each one in |
1124 .gaimrc and, if it's there, try to login. | 927 .gaimrc and, if it's there, try to login. |
1125 returns: 0 if successful | 928 returns: 0 if successful |
1150 serv_login(u); | 953 serv_login(u); |
1151 } | 954 } |
1152 } | 955 } |
1153 | 956 |
1154 return retval; | 957 return retval; |
1155 } | |
1156 | |
1157 | |
1158 int file_is_dir(const char *path, GtkWidget *w) | |
1159 { | |
1160 struct stat st; | |
1161 char *name; | |
1162 | |
1163 if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) { | |
1164 /* append a / if needed */ | |
1165 if (path[strlen(path) - 1] != '/') { | |
1166 name = g_strconcat(path, "/", NULL); | |
1167 } else { | |
1168 name = g_strdup(path); | |
1169 } | |
1170 gtk_file_selection_set_filename(GTK_FILE_SELECTION(w), name); | |
1171 g_free(name); | |
1172 return 1; | |
1173 } | |
1174 | |
1175 return 0; | |
1176 } | 958 } |
1177 | 959 |
1178 GSList *message_split(char *message, int limit) | 960 GSList *message_split(char *message, int limit) |
1179 { | 961 { |
1180 static GSList *ret = NULL; | 962 static GSList *ret = NULL; |
1278 return; | 1060 return; |
1279 } | 1061 } |
1280 | 1062 |
1281 if (mesg == NULL) { | 1063 if (mesg == NULL) { |
1282 /* Use default message */ | 1064 /* Use default message */ |
1283 do_away_message((GtkWidget *)NULL, default_away); | 1065 do_away_message(NULL, default_away); |
1284 } else { | 1066 } else { |
1285 /* Use argument */ | 1067 /* Use argument */ |
1286 while (awy) { | 1068 while (awy) { |
1287 a = (struct away_message *)awy->data; | 1069 a = (struct away_message *)awy->data; |
1288 if (strcmp(a->name, mesg) == 0) { | 1070 if (strcmp(a->name, mesg) == 0) { |
1291 } | 1073 } |
1292 awy = awy->next; | 1074 awy = awy->next; |
1293 } | 1075 } |
1294 if (message == NULL) | 1076 if (message == NULL) |
1295 message = default_away; | 1077 message = default_away; |
1296 do_away_message((GtkWidget *)NULL, message); | 1078 do_away_message(NULL, message); |
1297 } | 1079 } |
1298 return; | 1080 return; |
1299 } | 1081 } |
1300 | 1082 |
1301 void system_log(enum log_event what, struct gaim_connection *gc, struct buddy *who, int why) | 1083 void system_log(enum log_event what, struct gaim_connection *gc, struct buddy *who, int why) |