-rw-r--r-- | core/apps/embeddedkonsole/TEScreen.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/checkbook/listedit.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-console/TEScreen.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/Excel.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katedocument.cpp | 4 | ||||
-rw-r--r-- | noncore/comm/keypebble/krfbdecoder.cpp | 6 | ||||
-rw-r--r-- | noncore/games/sfcave/sfcave.cpp | 2 | ||||
-rw-r--r-- | noncore/settings/aqpkg/settingsimpl.cpp | 2 | ||||
-rw-r--r-- | noncore/settings/aqpkg/version.cpp | 2 |
9 files changed, 14 insertions, 14 deletions
diff --git a/core/apps/embeddedkonsole/TEScreen.cpp b/core/apps/embeddedkonsole/TEScreen.cpp index 8e69a88..1db34d2 100644 --- a/core/apps/embeddedkonsole/TEScreen.cpp +++ b/core/apps/embeddedkonsole/TEScreen.cpp | |||
@@ -757,480 +757,480 @@ void TEScreen::home() | |||
757 | } | 757 | } |
758 | 758 | ||
759 | /*! set cursor to the begin of the current line. | 759 | /*! set cursor to the begin of the current line. |
760 | */ | 760 | */ |
761 | 761 | ||
762 | void TEScreen::Return() | 762 | void TEScreen::Return() |
763 | { | 763 | { |
764 | cuX = 0; | 764 | cuX = 0; |
765 | } | 765 | } |
766 | 766 | ||
767 | /*! returns the current cursor columns. | 767 | /*! returns the current cursor columns. |
768 | */ | 768 | */ |
769 | 769 | ||
770 | int TEScreen::getCursorX() | 770 | int TEScreen::getCursorX() |
771 | { | 771 | { |
772 | return cuX; | 772 | return cuX; |
773 | } | 773 | } |
774 | 774 | ||
775 | /*! returns the current cursor line. | 775 | /*! returns the current cursor line. |
776 | */ | 776 | */ |
777 | 777 | ||
778 | int TEScreen::getCursorY() | 778 | int TEScreen::getCursorY() |
779 | { | 779 | { |
780 | return cuY; | 780 | return cuY; |
781 | } | 781 | } |
782 | 782 | ||
783 | // Erasing --------------------------------------------------------------------- | 783 | // Erasing --------------------------------------------------------------------- |
784 | 784 | ||
785 | /*! \section Erasing | 785 | /*! \section Erasing |
786 | 786 | ||
787 | This group of operations erase parts of the screen contents by filling | 787 | This group of operations erase parts of the screen contents by filling |
788 | it with spaces colored due to the current rendition settings. | 788 | it with spaces colored due to the current rendition settings. |
789 | 789 | ||
790 | Althought the cursor position is involved in most of these operations, | 790 | Althought the cursor position is involved in most of these operations, |
791 | it is never modified by them. | 791 | it is never modified by them. |
792 | */ | 792 | */ |
793 | 793 | ||
794 | /*! fill screen between (including) `loca' and `loce' with spaces. | 794 | /*! fill screen between (including) `loca' and `loce' with spaces. |
795 | 795 | ||
796 | This is an internal helper functions. The parameter types are internal | 796 | This is an internal helper functions. The parameter types are internal |
797 | addresses of within the screen image and make use of the way how the | 797 | addresses of within the screen image and make use of the way how the |
798 | screen matrix is mapped to the image vector. | 798 | screen matrix is mapped to the image vector. |
799 | */ | 799 | */ |
800 | 800 | ||
801 | void TEScreen::clearImage(int loca, int loce, char c) | 801 | void TEScreen::clearImage(int loca, int loce, char c) |
802 | { int i; | 802 | { int i; |
803 | int scr_TL=loc(0,hist.getLines()); | 803 | int scr_TL=loc(0,hist.getLines()); |
804 | //FIXME: check positions | 804 | //FIXME: check positions |
805 | 805 | ||
806 | //Clear entire selection if it overlaps region to be moved... | 806 | //Clear entire selection if it overlaps region to be moved... |
807 | if ( (sel_BR > (loca+scr_TL) )&&(sel_TL < (loce+scr_TL)) ) | 807 | if ( (sel_BR > (loca+scr_TL) )&&(sel_TL < (loce+scr_TL)) ) |
808 | { | 808 | { |
809 | clearSelection(); | 809 | clearSelection(); |
810 | } | 810 | } |
811 | for (i = loca; i <= loce; i++) | 811 | for (i = loca; i <= loce; i++) |
812 | { | 812 | { |
813 | image[i].c = c; | 813 | image[i].c = c; |
814 | image[i].f = ef_fg; //DEFAULT_FORE_COLOR; //FIXME: xterm and linux/ansi | 814 | image[i].f = ef_fg; //DEFAULT_FORE_COLOR; //FIXME: xterm and linux/ansi |
815 | image[i].b = ef_bg; //DEFAULT_BACK_COLOR; // many have different | 815 | image[i].b = ef_bg; //DEFAULT_BACK_COLOR; // many have different |
816 | image[i].r = ef_re; //DEFAULT_RENDITION; // ideas here. | 816 | image[i].r = ef_re; //DEFAULT_RENDITION; // ideas here. |
817 | } | 817 | } |
818 | } | 818 | } |
819 | 819 | ||
820 | /*! move image between (including) `loca' and `loce' to 'dst'. | 820 | /*! move image between (including) `loca' and `loce' to 'dst'. |
821 | 821 | ||
822 | This is an internal helper functions. The parameter types are internal | 822 | This is an internal helper functions. The parameter types are internal |
823 | addresses of within the screen image and make use of the way how the | 823 | addresses of within the screen image and make use of the way how the |
824 | screen matrix is mapped to the image vector. | 824 | screen matrix is mapped to the image vector. |
825 | */ | 825 | */ |
826 | 826 | ||
827 | void TEScreen::moveImage(int dst, int loca, int loce) | 827 | void TEScreen::moveImage(int dst, int loca, int loce) |
828 | { | 828 | { |
829 | //FIXME: check positions | 829 | //FIXME: check positions |
830 | if (loce < loca) { | 830 | if (loce < loca) { |
831 | // kdDebug() << "WARNING!!! call to TEScreen:moveImage with loce < loca!" << endl; | 831 | // kdDebug() << "WARNING!!! call to TEScreen:moveImage with loce < loca!" << endl; |
832 | return; | 832 | return; |
833 | } | 833 | } |
834 | memmove(&image[dst],&image[loca],(loce-loca+1)*sizeof(ca)); | 834 | memmove(&image[dst],&image[loca],(loce-loca+1)*sizeof(ca)); |
835 | } | 835 | } |
836 | 836 | ||
837 | /*! clear from (including) current cursor position to end of screen. | 837 | /*! clear from (including) current cursor position to end of screen. |
838 | */ | 838 | */ |
839 | 839 | ||
840 | void TEScreen::clearToEndOfScreen() | 840 | void TEScreen::clearToEndOfScreen() |
841 | { | 841 | { |
842 | clearImage(loc(cuX,cuY),loc(columns-1,lines-1),' '); | 842 | clearImage(loc(cuX,cuY),loc(columns-1,lines-1),' '); |
843 | } | 843 | } |
844 | 844 | ||
845 | /*! clear from begin of screen to (including) current cursor position. | 845 | /*! clear from begin of screen to (including) current cursor position. |
846 | */ | 846 | */ |
847 | 847 | ||
848 | void TEScreen::clearToBeginOfScreen() | 848 | void TEScreen::clearToBeginOfScreen() |
849 | { | 849 | { |
850 | clearImage(loc(0,0),loc(cuX,cuY),' '); | 850 | clearImage(loc(0,0),loc(cuX,cuY),' '); |
851 | } | 851 | } |
852 | 852 | ||
853 | /*! clear the entire screen. | 853 | /*! clear the entire screen. |
854 | */ | 854 | */ |
855 | 855 | ||
856 | void TEScreen::clearEntireScreen() | 856 | void TEScreen::clearEntireScreen() |
857 | { | 857 | { |
858 | clearImage(loc(0,0),loc(columns-1,lines-1),' '); | 858 | clearImage(loc(0,0),loc(columns-1,lines-1),' '); |
859 | } | 859 | } |
860 | 860 | ||
861 | /*! fill screen with 'E' | 861 | /*! fill screen with 'E' |
862 | This is to aid screen alignment | 862 | This is to aid screen alignment |
863 | */ | 863 | */ |
864 | 864 | ||
865 | void TEScreen::helpAlign() | 865 | void TEScreen::helpAlign() |
866 | { | 866 | { |
867 | clearImage(loc(0,0),loc(columns-1,lines-1),'E'); | 867 | clearImage(loc(0,0),loc(columns-1,lines-1),'E'); |
868 | } | 868 | } |
869 | 869 | ||
870 | /*! clear from (including) current cursor position to end of current cursor line. | 870 | /*! clear from (including) current cursor position to end of current cursor line. |
871 | */ | 871 | */ |
872 | 872 | ||
873 | void TEScreen::clearToEndOfLine() | 873 | void TEScreen::clearToEndOfLine() |
874 | { | 874 | { |
875 | clearImage(loc(cuX,cuY),loc(columns-1,cuY),' '); | 875 | clearImage(loc(cuX,cuY),loc(columns-1,cuY),' '); |
876 | } | 876 | } |
877 | 877 | ||
878 | /*! clear from begin of current cursor line to (including) current cursor position. | 878 | /*! clear from begin of current cursor line to (including) current cursor position. |
879 | */ | 879 | */ |
880 | 880 | ||
881 | void TEScreen::clearToBeginOfLine() | 881 | void TEScreen::clearToBeginOfLine() |
882 | { | 882 | { |
883 | clearImage(loc(0,cuY),loc(cuX,cuY),' '); | 883 | clearImage(loc(0,cuY),loc(cuX,cuY),' '); |
884 | } | 884 | } |
885 | 885 | ||
886 | /*! clears entire current cursor line | 886 | /*! clears entire current cursor line |
887 | */ | 887 | */ |
888 | 888 | ||
889 | void TEScreen::clearEntireLine() | 889 | void TEScreen::clearEntireLine() |
890 | { | 890 | { |
891 | clearImage( loc( 0, cuY),loc( columns - 1, cuY),' '); | 891 | clearImage( loc( 0, cuY),loc( columns - 1, cuY),' '); |
892 | } | 892 | } |
893 | 893 | ||
894 | // Rendition ------------------------------------------------------------------ | 894 | // Rendition ------------------------------------------------------------------ |
895 | 895 | ||
896 | /*! | 896 | /*! |
897 | set rendition mode | 897 | set rendition mode |
898 | */ | 898 | */ |
899 | 899 | ||
900 | void TEScreen::setRendition(int re) | 900 | void TEScreen::setRendition(int re) |
901 | { | 901 | { |
902 | cu_re |= re; | 902 | cu_re |= re; |
903 | effectiveRendition(); | 903 | effectiveRendition(); |
904 | } | 904 | } |
905 | 905 | ||
906 | /*! | 906 | /*! |
907 | reset rendition mode | 907 | reset rendition mode |
908 | */ | 908 | */ |
909 | 909 | ||
910 | void TEScreen::resetRendition(int re) | 910 | void TEScreen::resetRendition(int re) |
911 | { | 911 | { |
912 | cu_re &= ~re; | 912 | cu_re &= ~re; |
913 | effectiveRendition(); | 913 | effectiveRendition(); |
914 | } | 914 | } |
915 | 915 | ||
916 | /*! | 916 | /*! |
917 | */ | 917 | */ |
918 | 918 | ||
919 | void TEScreen::setDefaultRendition() | 919 | void TEScreen::setDefaultRendition() |
920 | { | 920 | { |
921 | setForeColorToDefault(); | 921 | setForeColorToDefault(); |
922 | setBackColorToDefault(); | 922 | setBackColorToDefault(); |
923 | cu_re = DEFAULT_RENDITION; | 923 | cu_re = DEFAULT_RENDITION; |
924 | effectiveRendition(); | 924 | effectiveRendition(); |
925 | } | 925 | } |
926 | 926 | ||
927 | /*! | 927 | /*! |
928 | */ | 928 | */ |
929 | 929 | ||
930 | void TEScreen::setForeColor(int fgcolor) | 930 | void TEScreen::setForeColor(int fgcolor) |
931 | { | 931 | { |
932 | cu_fg = (fgcolor&7)+((fgcolor&8) ? 4+8 : 2); | 932 | cu_fg = (fgcolor&7)+((fgcolor&8) ? 4+8 : 2); |
933 | effectiveRendition(); | 933 | effectiveRendition(); |
934 | } | 934 | } |
935 | 935 | ||
936 | /*! | 936 | /*! |
937 | */ | 937 | */ |
938 | 938 | ||
939 | void TEScreen::setBackColor(int bgcolor) | 939 | void TEScreen::setBackColor(int bgcolor) |
940 | { | 940 | { |
941 | cu_bg = (bgcolor&7)+((bgcolor&8) ? 4+8 : 2); | 941 | cu_bg = (bgcolor&7)+((bgcolor&8) ? 4+8 : 2); |
942 | effectiveRendition(); | 942 | effectiveRendition(); |
943 | } | 943 | } |
944 | 944 | ||
945 | /*! | 945 | /*! |
946 | */ | 946 | */ |
947 | 947 | ||
948 | void TEScreen::setBackColorToDefault() | 948 | void TEScreen::setBackColorToDefault() |
949 | { | 949 | { |
950 | cu_bg = DEFAULT_BACK_COLOR; | 950 | cu_bg = DEFAULT_BACK_COLOR; |
951 | effectiveRendition(); | 951 | effectiveRendition(); |
952 | } | 952 | } |
953 | 953 | ||
954 | /*! | 954 | /*! |
955 | */ | 955 | */ |
956 | 956 | ||
957 | void TEScreen::setForeColorToDefault() | 957 | void TEScreen::setForeColorToDefault() |
958 | { | 958 | { |
959 | cu_fg = DEFAULT_FORE_COLOR; | 959 | cu_fg = DEFAULT_FORE_COLOR; |
960 | effectiveRendition(); | 960 | effectiveRendition(); |
961 | } | 961 | } |
962 | 962 | ||
963 | /* ------------------------------------------------------------------------- */ | 963 | /* ------------------------------------------------------------------------- */ |
964 | /* */ | 964 | /* */ |
965 | /* Marking & Selection */ | 965 | /* Marking & Selection */ |
966 | /* */ | 966 | /* */ |
967 | /* ------------------------------------------------------------------------- */ | 967 | /* ------------------------------------------------------------------------- */ |
968 | 968 | ||
969 | void TEScreen::clearSelection() | 969 | void TEScreen::clearSelection() |
970 | { | 970 | { |
971 | sel_BR = -1; | 971 | sel_BR = -1; |
972 | sel_TL = -1; | 972 | sel_TL = -1; |
973 | sel_begin = -1; | 973 | sel_begin = -1; |
974 | } | 974 | } |
975 | 975 | ||
976 | void TEScreen::setSelBeginXY(const int x, const int y) | 976 | void TEScreen::setSelBeginXY(const int x, const int y) |
977 | { | 977 | { |
978 | if (histCursor > hist.getLines()) { | 978 | if (histCursor > hist.getLines()) { |
979 | histCursor = hist.getLines(); | 979 | histCursor = hist.getLines(); |
980 | } | 980 | } |
981 | sel_begin = loc(x,y+histCursor) ; | 981 | sel_begin = loc(x,y+histCursor) ; |
982 | sel_BR = sel_begin; | 982 | sel_BR = sel_begin; |
983 | sel_TL = sel_begin; | 983 | sel_TL = sel_begin; |
984 | } | 984 | } |
985 | 985 | ||
986 | void TEScreen::setSelExtentXY(const int x, const int y) | 986 | void TEScreen::setSelExtentXY(const int x, const int y) |
987 | { | 987 | { |
988 | if (sel_begin == -1) return; | 988 | if (sel_begin == -1) return; |
989 | if (histCursor > hist.getLines()) { | 989 | if (histCursor > hist.getLines()) { |
990 | histCursor = hist.getLines(); | 990 | histCursor = hist.getLines(); |
991 | } | 991 | } |
992 | int l = loc(x,y + histCursor); | 992 | int l = loc(x,y + histCursor); |
993 | 993 | ||
994 | if (l < sel_begin) | 994 | if (l < sel_begin) |
995 | { | 995 | { |
996 | sel_TL = l; | 996 | sel_TL = l; |
997 | sel_BR = sel_begin; | 997 | sel_BR = sel_begin; |
998 | } | 998 | } |
999 | else | 999 | else |
1000 | { | 1000 | { |
1001 | /* FIXME, HACK to correct for x too far to the right... */ | 1001 | /* FIXME, HACK to correct for x too far to the right... */ |
1002 | if (( x == columns )|| (x == 0)) l--; | 1002 | if (( x == columns )|| (x == 0)) l--; |
1003 | 1003 | ||
1004 | sel_TL = sel_begin; | 1004 | sel_TL = sel_begin; |
1005 | sel_BR = l; | 1005 | sel_BR = l; |
1006 | } | 1006 | } |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | QString TEScreen::getSelText(const BOOL preserve_line_breaks) | 1009 | QString TEScreen::getSelText(const BOOL preserve_line_breaks) |
1010 | { | 1010 | { |
1011 | if (sel_begin == -1) | 1011 | if (sel_begin == -1) |
1012 | return QString::null; // Selection got clear while selecting. | 1012 | return QString::null; // Selection got clear while selecting. |
1013 | 1013 | ||
1014 | int *m; // buffer to fill. | 1014 | int *m; // buffer to fill. |
1015 | int s, d; // source index, dest. index. | 1015 | int s, d; // source index, dest. index. |
1016 | int hist_BR = loc(0, hist.getLines()); | 1016 | int hist_BR = loc(0, hist.getLines()); |
1017 | int hY = sel_TL / columns; | 1017 | int hY = sel_TL / columns; |
1018 | int hX = sel_TL % columns; | 1018 | int hX = sel_TL % columns; |
1019 | int eol; // end of line | 1019 | int eol; // end of line |
1020 | 1020 | ||
1021 | s = sel_TL; // tracks copy in source. | 1021 | s = sel_TL; // tracks copy in source. |
1022 | 1022 | ||
1023 | // allocate buffer for maximum | 1023 | // allocate buffer for maximum |
1024 | // possible size... | 1024 | // possible size... |
1025 | d = (sel_BR - sel_TL) / columns + 1; | 1025 | d = (sel_BR - sel_TL) / columns + 1; |
1026 | m = new int[d * (columns + 1) + 2]; | 1026 | m = new int[d * (columns + 1) + 2]; |
1027 | d = 0; | 1027 | d = 0; |
1028 | 1028 | ||
1029 | while (s <= sel_BR) | 1029 | while (s <= sel_BR) |
1030 | { | 1030 | { |
1031 | if (s < hist_BR) | 1031 | if (s < hist_BR) |
1032 | { // get lines from hist.history | 1032 | { // get lines from hist.history |
1033 | // buffer. | 1033 | // buffer. |
1034 | eol = hist.getLineLen(hY); | 1034 | eol = hist.getLineLen(hY); |
1035 | 1035 | ||
1036 | if ((hY == (sel_BR / columns)) && | 1036 | if ((hY == (sel_BR / columns)) && |
1037 | (eol >= (sel_BR % columns))) | 1037 | (eol >= (sel_BR % columns))) |
1038 | { | 1038 | { |
1039 | eol = sel_BR % columns + 1; | 1039 | eol = sel_BR % columns + 1; |
1040 | } | 1040 | } |
1041 | 1041 | ||
1042 | while (hX < eol) | 1042 | while (hX < eol) |
1043 | { | 1043 | { |
1044 | m[d++] = hist.getCell(hY, hX++).c; | 1044 | m[d++] = hist.getCell(hY, hX++).c; |
1045 | s++; | 1045 | s++; |
1046 | } | 1046 | } |
1047 | 1047 | ||
1048 | if (s <= sel_BR) | 1048 | if (s <= sel_BR) |
1049 | { | 1049 | { |
1050 | // The line break handling | 1050 | // The line break handling |
1051 | // It's different from the screen | 1051 | // It's different from the screen |
1052 | // image case! | 1052 | // image case! |
1053 | if (eol % columns == 0) | 1053 | if (eol % columns == 0) |
1054 | { | 1054 | { |
1055 | // That's either a completely filled | 1055 | // That's either a completely filled |
1056 | // line or an empty line | 1056 | // line or an empty line |
1057 | if (eol == 0) | 1057 | if (eol == 0) |
1058 | { | 1058 | { |
1059 | m[d++] = '\n'; | 1059 | m[d++] = '\n'; |
1060 | } | 1060 | } |
1061 | else | 1061 | else |
1062 | { | 1062 | { |
1063 | // We have a full line. | 1063 | // We have a full line. |
1064 | // FIXME: How can we handle newlines | 1064 | // FIXME: How can we handle newlines |
1065 | // at this position?! | 1065 | // at this position?! |
1066 | } | 1066 | } |
1067 | } | 1067 | } |
1068 | else if ((eol + 1) % columns == 0) | 1068 | else if ((eol + 1) % columns == 0) |
1069 | { | 1069 | { |
1070 | // FIXME: We don't know if this was a | 1070 | // FIXME: We don't know if this was a |
1071 | // space at the last position or a | 1071 | // space at the last position or a |
1072 | // short line!! | 1072 | // short line!! |
1073 | m[d++] = ' '; | 1073 | m[d++] = ' '; |
1074 | } | 1074 | } |
1075 | else | 1075 | else |
1076 | { | 1076 | { |
1077 | // We have a short line here. Put a | 1077 | // We have a short line here. Put a |
1078 | // newline or a space into the | 1078 | // newline or a space into the |
1079 | // buffer. | 1079 | // buffer. |
1080 | m[d++] = preserve_line_breaks ? '\n' : ' '; | 1080 | m[d++] = preserve_line_breaks ? '\n' : ' '; |
1081 | } | 1081 | } |
1082 | } | 1082 | } |
1083 | 1083 | ||
1084 | hY++; | 1084 | hY++; |
1085 | hX = 0; | 1085 | hX = 0; |
1086 | s = hY * columns; | 1086 | s = hY * columns; |
1087 | } | 1087 | } |
1088 | else | 1088 | else |
1089 | { // or from screen image. | 1089 | { // or from screen image. |
1090 | eol = (s / columns + 1) * columns - 1; | 1090 | eol = (s / columns + 1) * columns - 1; |
1091 | 1091 | ||
1092 | if (eol < sel_BR) | 1092 | if (eol < sel_BR) |
1093 | { | 1093 | { |
1094 | while ((eol > s) && | 1094 | while ((eol > s) && |
1095 | isspace(image[eol - hist_BR].c)) | 1095 | isspace(image[eol - hist_BR].c)) |
1096 | { | 1096 | { |
1097 | eol--; | 1097 | eol--; |
1098 | } | 1098 | } |
1099 | } | 1099 | } |
1100 | else | 1100 | else |
1101 | { | 1101 | { |
1102 | eol = sel_BR; | 1102 | eol = sel_BR; |
1103 | } | 1103 | } |
1104 | 1104 | ||
1105 | while (s <= eol) | 1105 | while (s <= eol) |
1106 | { | 1106 | { |
1107 | m[d++] = image[s++ - hist_BR].c; | 1107 | m[d++] = image[s++ - hist_BR].c; |
1108 | } | 1108 | } |
1109 | 1109 | ||
1110 | if (eol < sel_BR) | 1110 | if (eol < sel_BR) |
1111 | { | 1111 | { |
1112 | // eol processing see below ... | 1112 | // eol processing see below ... |
1113 | if ((eol + 1) % columns == 0) | 1113 | if ((eol + 1) % columns == 0) |
1114 | { | 1114 | { |
1115 | if (image[eol - hist_BR].c == ' ') | 1115 | if (image[eol - hist_BR].c == ' ') |
1116 | { | 1116 | { |
1117 | m[d++] = ' '; | 1117 | m[d++] = ' '; |
1118 | } | 1118 | } |
1119 | } | 1119 | } |
1120 | else | 1120 | else |
1121 | { | 1121 | { |
1122 | m[d++] = ((preserve_line_breaks || | 1122 | m[d++] = ((preserve_line_breaks || |
1123 | ((eol % columns) == 0)) ? | 1123 | ((eol % columns) == 0)) ? |
1124 | '\n' : ' '); | 1124 | '\n' : ' '); |
1125 | } | 1125 | } |
1126 | } | 1126 | } |
1127 | 1127 | ||
1128 | s = (eol / columns + 1) * columns; | 1128 | s = (eol / columns + 1) * columns; |
1129 | } | 1129 | } |
1130 | } | 1130 | } |
1131 | 1131 | ||
1132 | QChar* qc = new QChar[d]; | 1132 | QChar* qc = new QChar[d]; |
1133 | 1133 | ||
1134 | for (int i = 0; i < d; i++) | 1134 | for (int i = 0; i < d; i++) |
1135 | { | 1135 | { |
1136 | qc[i] = m[i]; | 1136 | qc[i] = m[i]; |
1137 | } | 1137 | } |
1138 | 1138 | ||
1139 | QString res(qc, d); | 1139 | QString res(qc, d); |
1140 | 1140 | ||
1141 | delete m; | 1141 | delete [] m; |
1142 | delete qc; | 1142 | delete [] qc; |
1143 | 1143 | ||
1144 | return res; | 1144 | return res; |
1145 | } | 1145 | } |
1146 | /* above ... end of line processing for selection -- psilva | 1146 | /* above ... end of line processing for selection -- psilva |
1147 | cases: | 1147 | cases: |
1148 | 1148 | ||
1149 | 1) (eol+1)%columns == 0 --> the whole line is filled. | 1149 | 1) (eol+1)%columns == 0 --> the whole line is filled. |
1150 | If the last char is a space, insert (preserve) space. otherwise | 1150 | If the last char is a space, insert (preserve) space. otherwise |
1151 | leave the text alone, so that words that are broken by linewrap | 1151 | leave the text alone, so that words that are broken by linewrap |
1152 | are preserved. | 1152 | are preserved. |
1153 | 1153 | ||
1154 | FIXME: | 1154 | FIXME: |
1155 | * this suppresses \n for command output that is | 1155 | * this suppresses \n for command output that is |
1156 | sized to the exact column width of the screen. | 1156 | sized to the exact column width of the screen. |
1157 | 1157 | ||
1158 | 2) eol%columns == 0 --> blank line. | 1158 | 2) eol%columns == 0 --> blank line. |
1159 | insert a \n unconditionally. | 1159 | insert a \n unconditionally. |
1160 | Do it either you would because you are in preserve_line_break mode, | 1160 | Do it either you would because you are in preserve_line_break mode, |
1161 | or because it's an ASCII paragraph delimiter, so even when | 1161 | or because it's an ASCII paragraph delimiter, so even when |
1162 | not preserving line_breaks, you want to preserve paragraph breaks. | 1162 | not preserving line_breaks, you want to preserve paragraph breaks. |
1163 | 1163 | ||
1164 | 3) else --> partially filled line | 1164 | 3) else --> partially filled line |
1165 | insert a \n in preserve line break mode, else a space | 1165 | insert a \n in preserve line break mode, else a space |
1166 | The space prevents concatenation of the last word of one | 1166 | The space prevents concatenation of the last word of one |
1167 | line with the first of the next. | 1167 | line with the first of the next. |
1168 | 1168 | ||
1169 | */ | 1169 | */ |
1170 | 1170 | ||
1171 | void TEScreen::addHistLine() | 1171 | void TEScreen::addHistLine() |
1172 | { | 1172 | { |
1173 | assert(hasScroll() || histCursor == 0); | 1173 | assert(hasScroll() || histCursor == 0); |
1174 | 1174 | ||
1175 | // add to hist buffer | 1175 | // add to hist buffer |
1176 | // we have to take care about scrolling, too... | 1176 | // we have to take care about scrolling, too... |
1177 | 1177 | ||
1178 | if (hasScroll()){ | 1178 | if (hasScroll()){ |
1179 | ca dft; | 1179 | ca dft; |
1180 | 1180 | ||
1181 | int end = columns - 1; | 1181 | int end = columns - 1; |
1182 | while (end >= 0 && image[end] == dft) | 1182 | while (end >= 0 && image[end] == dft) |
1183 | end -= 1; | 1183 | end -= 1; |
1184 | 1184 | ||
1185 | hist.addCells( image, end + 1); | 1185 | hist.addCells( image, end + 1); |
1186 | hist.addLine(); | 1186 | hist.addLine(); |
1187 | 1187 | ||
1188 | // adjust history cursor | 1188 | // adjust history cursor |
1189 | histCursor += ( hist.getLines() - 1 == histCursor); | 1189 | histCursor += ( hist.getLines() - 1 == histCursor); |
1190 | } | 1190 | } |
1191 | 1191 | ||
1192 | if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround | 1192 | if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround |
1193 | } | 1193 | } |
1194 | 1194 | ||
1195 | void TEScreen::setHistCursor(int cursor) | 1195 | void TEScreen::setHistCursor(int cursor) |
1196 | { | 1196 | { |
1197 | histCursor = cursor; //FIXME:rangecheck | 1197 | histCursor = cursor; //FIXME:rangecheck |
1198 | if (histCursor > hist.getLines()) { | 1198 | if (histCursor > hist.getLines()) { |
1199 | histCursor = hist.getLines(); | 1199 | histCursor = hist.getLines(); |
1200 | } | 1200 | } |
1201 | if (histCursor < 0) { | 1201 | if (histCursor < 0) { |
1202 | histCursor = 0; | 1202 | histCursor = 0; |
1203 | } | 1203 | } |
1204 | } | 1204 | } |
1205 | 1205 | ||
1206 | void TEScreen::setHorzCursor(int cursor) | 1206 | void TEScreen::setHorzCursor(int cursor) |
1207 | { | 1207 | { |
1208 | horzCursor = cursor; | 1208 | horzCursor = cursor; |
1209 | } | 1209 | } |
1210 | 1210 | ||
1211 | int TEScreen::getHistCursor() | 1211 | int TEScreen::getHistCursor() |
1212 | { | 1212 | { |
1213 | return histCursor; | 1213 | return histCursor; |
1214 | } | 1214 | } |
1215 | 1215 | ||
1216 | int TEScreen::getHorzCursor() | 1216 | int TEScreen::getHorzCursor() |
1217 | { | 1217 | { |
1218 | return horzCursor; | 1218 | return horzCursor; |
1219 | } | 1219 | } |
1220 | 1220 | ||
1221 | int TEScreen::getHistLines() | 1221 | int TEScreen::getHistLines() |
1222 | { | 1222 | { |
1223 | return hist.getLines(); | 1223 | return hist.getLines(); |
1224 | } | 1224 | } |
1225 | 1225 | ||
1226 | void TEScreen::setScroll(bool on) | 1226 | void TEScreen::setScroll(bool on) |
1227 | { | 1227 | { |
1228 | histCursor = 0; | 1228 | histCursor = 0; |
1229 | clearSelection(); | 1229 | clearSelection(); |
1230 | hist.setScroll(on); | 1230 | hist.setScroll(on); |
1231 | } | 1231 | } |
1232 | 1232 | ||
1233 | bool TEScreen::hasScroll() | 1233 | bool TEScreen::hasScroll() |
1234 | { | 1234 | { |
1235 | return hist.hasScroll(); | 1235 | return hist.hasScroll(); |
1236 | } | 1236 | } |
diff --git a/noncore/apps/checkbook/listedit.cpp b/noncore/apps/checkbook/listedit.cpp index e40377b..b297d69 100644 --- a/noncore/apps/checkbook/listedit.cpp +++ b/noncore/apps/checkbook/listedit.cpp | |||
@@ -1,355 +1,355 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | =. | 3 | =. |
4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> | 4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This file is free software; you can | 6 | _;:, .> :=|. This file is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This file is distributed in the hope that | 13 | .i_,=:_. -<s. This file is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "listedit.h" | 29 | #include "listedit.h" |
30 | 30 | ||
31 | /* OPIE */ | 31 | /* OPIE */ |
32 | #include <opie2/odebug.h> | 32 | #include <opie2/odebug.h> |
33 | #include <opie2/oresource.h> | 33 | #include <opie2/oresource.h> |
34 | 34 | ||
35 | #include <qpe/applnk.h> | 35 | #include <qpe/applnk.h> |
36 | 36 | ||
37 | using namespace Opie::Core; | 37 | using namespace Opie::Core; |
38 | 38 | ||
39 | /* QT */ | 39 | /* QT */ |
40 | #include <qlayout.h> | 40 | #include <qlayout.h> |
41 | #include <qlineedit.h> | 41 | #include <qlineedit.h> |
42 | #include <qlistview.h> | 42 | #include <qlistview.h> |
43 | #include <qwidgetstack.h> | 43 | #include <qwidgetstack.h> |
44 | #include <qcombobox.h> | 44 | #include <qcombobox.h> |
45 | #include <qpushbutton.h> | 45 | #include <qpushbutton.h> |
46 | 46 | ||
47 | // --- ListEdit --------------------------------------------------------------- | 47 | // --- ListEdit --------------------------------------------------------------- |
48 | ListEdit::ListEdit( QWidget *parent, const char *sName ) | 48 | ListEdit::ListEdit( QWidget *parent, const char *sName ) |
49 | : QWidget(parent, sName), TableDef(sName) | 49 | : QWidget(parent, sName), TableDef(sName) |
50 | { | 50 | { |
51 | // get font height | 51 | // get font height |
52 | int fh = fontMetrics().height(); | 52 | int fh = fontMetrics().height(); |
53 | 53 | ||
54 | // create layout | 54 | // create layout |
55 | QGridLayout *layout=new QGridLayout(this); | 55 | QGridLayout *layout=new QGridLayout(this); |
56 | layout->setSpacing( 2 ); | 56 | layout->setSpacing( 2 ); |
57 | layout->setMargin( 4 ); | 57 | layout->setMargin( 4 ); |
58 | 58 | ||
59 | // type table | 59 | // type table |
60 | _typeTable = new QListView( this ); | 60 | _typeTable = new QListView( this ); |
61 | ColumnDef *def=first(); | 61 | ColumnDef *def=first(); |
62 | while( def ) { | 62 | while( def ) { |
63 | _typeTable->addColumn( def->getName() ); | 63 | _typeTable->addColumn( def->getName() ); |
64 | def=next(); | 64 | def=next(); |
65 | } | 65 | } |
66 | connect( _typeTable, SIGNAL( clicked(QListViewItem*,const QPoint&,int) ), this, SLOT( slotClick(QListViewItem*,const QPoint&,int) ) ); | 66 | connect( _typeTable, SIGNAL( clicked(QListViewItem*,const QPoint&,int) ), this, SLOT( slotClick(QListViewItem*,const QPoint&,int) ) ); |
67 | layout->addMultiCellWidget(_typeTable, 0,4,0,4); | 67 | layout->addMultiCellWidget(_typeTable, 0,4,0,4); |
68 | _currentItem=NULL; | 68 | _currentItem=NULL; |
69 | 69 | ||
70 | // edit field | 70 | // edit field |
71 | _stack=new QWidgetStack( this ); | 71 | _stack=new QWidgetStack( this ); |
72 | _stack->setMaximumHeight(fh+5); | 72 | _stack->setMaximumHeight(fh+5); |
73 | layout->addMultiCellWidget(_stack, 5,5,0,2); | 73 | layout->addMultiCellWidget(_stack, 5,5,0,2); |
74 | _typeEdit = new QLineEdit( _stack ); | 74 | _typeEdit = new QLineEdit( _stack ); |
75 | _stack->raiseWidget(_typeEdit ); | 75 | _stack->raiseWidget(_typeEdit ); |
76 | connect( _typeEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotEditChanged(const QString&) ) ); | 76 | connect( _typeEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotEditChanged(const QString&) ) ); |
77 | 77 | ||
78 | // combo box | 78 | // combo box |
79 | _box=new QComboBox( _stack ); | 79 | _box=new QComboBox( _stack ); |
80 | connect( _box, SIGNAL( activated(const QString&) ), this, SLOT( slotActivated(const QString&) ) ); | 80 | connect( _box, SIGNAL( activated(const QString&) ), this, SLOT( slotActivated(const QString&) ) ); |
81 | 81 | ||
82 | 82 | ||
83 | // add button | 83 | // add button |
84 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), | 84 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), |
85 | tr( "Add" ), this ); | 85 | tr( "Add" ), this ); |
86 | btn->setFixedHeight( AppLnk::smallIconSize()+4 ); | 86 | btn->setFixedHeight( AppLnk::smallIconSize()+4 ); |
87 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotAdd() ) ); | 87 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotAdd() ) ); |
88 | layout->addWidget( btn, 5, 3 ); | 88 | layout->addWidget( btn, 5, 3 ); |
89 | 89 | ||
90 | // delete button | 90 | // delete button |
91 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), this ); | 91 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), this ); |
92 | btn->setFixedHeight( AppLnk::smallIconSize()+4 ); | 92 | btn->setFixedHeight( AppLnk::smallIconSize()+4 ); |
93 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDel() ) ); | 93 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDel() ) ); |
94 | layout->addWidget( btn, 5, 4 ); | 94 | layout->addWidget( btn, 5, 4 ); |
95 | } | 95 | } |
96 | 96 | ||
97 | // --- ~ListEdit -------------------------------------------------------------- | 97 | // --- ~ListEdit -------------------------------------------------------------- |
98 | ListEdit::~ListEdit() | 98 | ListEdit::~ListEdit() |
99 | { | 99 | { |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
103 | // --- slotEditTypeChanged ---------------------------------------------------- | 103 | // --- slotEditTypeChanged ---------------------------------------------------- |
104 | void ListEdit::slotEditChanged(const QString &str) | 104 | void ListEdit::slotEditChanged(const QString &str) |
105 | { | 105 | { |
106 | if( !_currentItem || _currentColumn<0 ) return; | 106 | if( !_currentItem || _currentColumn<0 ) return; |
107 | _currentItem->setText(_currentColumn, str); | 107 | _currentItem->setText(_currentColumn, str); |
108 | } | 108 | } |
109 | 109 | ||
110 | // --- slotAddType ------------------------------------------------------------ | 110 | // --- slotAddType ------------------------------------------------------------ |
111 | void ListEdit::slotAdd() | 111 | void ListEdit::slotAdd() |
112 | { | 112 | { |
113 | // construct new row | 113 | // construct new row |
114 | QString args[8]; | 114 | QString args[8]; |
115 | ColumnDef *pCol=this->first(); | 115 | ColumnDef *pCol=this->first(); |
116 | int i=0; | 116 | int i=0; |
117 | while( pCol && i<8 ) { | 117 | while( pCol && i<8 ) { |
118 | args[i++]=pCol->getNewValue(); | 118 | args[i++]=pCol->getNewValue(); |
119 | pCol=this->next(); | 119 | pCol=this->next(); |
120 | } | 120 | } |
121 | _currentItem=new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7] ); | 121 | _currentItem=new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7] ); |
122 | 122 | ||
123 | // fix uniques | 123 | // fix uniques |
124 | fixTypes(); | 124 | fixTypes(); |
125 | 125 | ||
126 | // display col 0 of new value | 126 | // display col 0 of new value |
127 | QPoint pnt; | 127 | QPoint pnt; |
128 | slotClick(_currentItem, pnt, 0); | 128 | slotClick(_currentItem, pnt, 0); |
129 | _typeTable->setSelected( _currentItem, true ); | 129 | _typeTable->setSelected( _currentItem, true ); |
130 | 130 | ||
131 | // make it selected | 131 | // make it selected |
132 | _typeEdit->setCursorPosition(0); | 132 | _typeEdit->setCursorPosition(0); |
133 | _typeEdit->setSelection(0, _typeEdit->text().length() ); | 133 | _typeEdit->setSelection(0, _typeEdit->text().length() ); |
134 | } | 134 | } |
135 | 135 | ||
136 | // --- slotDel ------------------------------------------------------------- | 136 | // --- slotDel ------------------------------------------------------------- |
137 | void ListEdit::slotDel() | 137 | void ListEdit::slotDel() |
138 | { | 138 | { |
139 | if( !_currentItem ) return; | 139 | if( !_currentItem ) return; |
140 | delete _currentItem; | 140 | delete _currentItem; |
141 | _currentItem=NULL; | 141 | _currentItem=NULL; |
142 | _typeEdit->setText(""); | 142 | _typeEdit->setText(""); |
143 | _stack->raiseWidget(_typeEdit); | 143 | _stack->raiseWidget(_typeEdit); |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | // --- fixTypes ---------------------------------------------------------------- | 147 | // --- fixTypes ---------------------------------------------------------------- |
148 | // Makes sure all entries have a unique name and empty entries are replaced | 148 | // Makes sure all entries have a unique name and empty entries are replaced |
149 | // by a generic string. The first version performs the operation on a particular | 149 | // by a generic string. The first version performs the operation on a particular |
150 | // column, whereas the 2nd does it for all unique columns. | 150 | // column, whereas the 2nd does it for all unique columns. |
151 | class ColMap { | 151 | class ColMap { |
152 | public: | 152 | public: |
153 | ColMap(QString sValue, QListViewItem *pEntry) { | 153 | ColMap(QString sValue, QListViewItem *pEntry) { |
154 | _sValue=sValue; | 154 | _sValue=sValue; |
155 | _pEntry=pEntry; | 155 | _pEntry=pEntry; |
156 | } | 156 | } |
157 | QString &getValue() { return(_sValue); } | 157 | QString &getValue() { return(_sValue); } |
158 | QListViewItem *getItem() { return(_pEntry); } | 158 | QListViewItem *getItem() { return(_pEntry); } |
159 | 159 | ||
160 | protected: | 160 | protected: |
161 | QString _sValue; | 161 | QString _sValue; |
162 | QListViewItem *_pEntry; | 162 | QListViewItem *_pEntry; |
163 | }; | 163 | }; |
164 | 164 | ||
165 | class ColList : public QList<QString> | 165 | class ColList : public QList<QString> |
166 | { | 166 | { |
167 | public: | 167 | public: |
168 | ColList() : QList<QString>() { } | 168 | ColList() : QList<QString>() { } |
169 | 169 | ||
170 | protected: | 170 | protected: |
171 | int compareItems(QCollection::Item, QCollection::Item); | 171 | int compareItems(QCollection::Item, QCollection::Item); |
172 | }; | 172 | }; |
173 | 173 | ||
174 | int ColList::compareItems(QCollection::Item i1, QCollection::Item i2) { | 174 | int ColList::compareItems(QCollection::Item i1, QCollection::Item i2) { |
175 | return( ((QString *)i1)->compare(*(QString *)i2) ); | 175 | return( ((QString *)i1)->compare(*(QString *)i2) ); |
176 | } | 176 | } |
177 | 177 | ||
178 | void ListEdit::fixTypes(int iColumn) | 178 | void ListEdit::fixTypes(int iColumn) |
179 | { | 179 | { |
180 | // get column def | 180 | // get column def |
181 | ColumnDef *pDef=this->at(iColumn); | 181 | ColumnDef *pDef=this->at(iColumn); |
182 | 182 | ||
183 | // create map of entries | 183 | // create map of entries |
184 | if( !_typeTable->childCount() ) return; | 184 | if( !_typeTable->childCount() ) return; |
185 | ColMap **colMap=new ColMap *[_typeTable->childCount()]; | 185 | ColMap **colMap=new ColMap *[_typeTable->childCount()]; |
186 | QListViewItem *cur=_typeTable->firstChild(); | 186 | QListViewItem *cur=_typeTable->firstChild(); |
187 | ColList lst; | 187 | ColList lst; |
188 | for(int i=0; i<_typeTable->childCount(); i++) { | 188 | for(int i=0; i<_typeTable->childCount(); i++) { |
189 | colMap[i]=new ColMap(cur->text(iColumn), cur); | 189 | colMap[i]=new ColMap(cur->text(iColumn), cur); |
190 | lst.append( &(colMap[i]->getValue()) ); | 190 | lst.append( &(colMap[i]->getValue()) ); |
191 | cur=cur->nextSibling(); | 191 | cur=cur->nextSibling(); |
192 | } | 192 | } |
193 | 193 | ||
194 | // fix empty entries | 194 | // fix empty entries |
195 | int i=0; | 195 | int i=0; |
196 | for(QString *ptr=lst.first(); ptr; ptr=lst.next()) { | 196 | for(QString *ptr=lst.first(); ptr; ptr=lst.next()) { |
197 | *ptr=ptr->stripWhiteSpace(); | 197 | *ptr=ptr->stripWhiteSpace(); |
198 | if( ptr->isEmpty() ) { | 198 | if( ptr->isEmpty() ) { |
199 | i++; | 199 | i++; |
200 | if( i==1 ) *ptr=pDef->getNewValue(); | 200 | if( i==1 ) *ptr=pDef->getNewValue(); |
201 | else ptr->sprintf("%s %d", (const char *)pDef->getNewValue(), i); | 201 | else ptr->sprintf("%s %d", (const char *)pDef->getNewValue(), i); |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | // fix dups | 205 | // fix dups |
206 | lst.sort(); | 206 | lst.sort(); |
207 | QString repl; | 207 | QString repl; |
208 | for(uint iCur=0; iCur<lst.count()-1; iCur++) { | 208 | for(uint iCur=0; iCur<lst.count()-1; iCur++) { |
209 | QString *current=lst.at(iCur); | 209 | QString *current=lst.at(iCur); |
210 | for(uint iNext=iCur+1; iNext<lst.count(); iNext++ ) { | 210 | for(uint iNext=iCur+1; iNext<lst.count(); iNext++ ) { |
211 | if( *current!=*lst.at(iNext) ) continue; | 211 | if( *current!=*lst.at(iNext) ) continue; |
212 | for(int i=2; ; i++) { | 212 | for(int i=2; ; i++) { |
213 | repl.sprintf("%s %d", (const char *)*current, i); | 213 | repl.sprintf("%s %d", (const char *)*current, i); |
214 | bool bDup=false; | 214 | bool bDup=false; |
215 | uint iChk=iNext+1; | 215 | uint iChk=iNext+1; |
216 | while( iChk<lst.count() ) { | 216 | while( iChk<lst.count() ) { |
217 | QString *chk=lst.at(iChk); | 217 | QString *chk=lst.at(iChk); |
218 | if( !chk->startsWith(*current) ) break; | 218 | if( !chk->startsWith(*current) ) break; |
219 | if( *chk==repl ) { | 219 | if( *chk==repl ) { |
220 | bDup=true; | 220 | bDup=true; |
221 | break; | 221 | break; |
222 | } | 222 | } |
223 | iChk++; | 223 | iChk++; |
224 | } | 224 | } |
225 | if( !bDup ) { | 225 | if( !bDup ) { |
226 | *lst.at(iNext)=repl; | 226 | *lst.at(iNext)=repl; |
227 | break; | 227 | break; |
228 | } | 228 | } |
229 | } | 229 | } |
230 | } | 230 | } |
231 | } | 231 | } |
232 | lst.sort(); | 232 | lst.sort(); |
233 | 233 | ||
234 | // copy back clean up col map | 234 | // copy back clean up col map |
235 | for(int i=0; i<_typeTable->childCount(); i++) { | 235 | for(int i=0; i<_typeTable->childCount(); i++) { |
236 | colMap[i]->getItem()->setText(iColumn, colMap[i]->getValue()); | 236 | colMap[i]->getItem()->setText(iColumn, colMap[i]->getValue()); |
237 | delete colMap[i]; | 237 | delete colMap[i]; |
238 | } | 238 | } |
239 | delete colMap; | 239 | delete [] colMap; |
240 | } | 240 | } |
241 | 241 | ||
242 | void ListEdit::fixTypes() | 242 | void ListEdit::fixTypes() |
243 | { | 243 | { |
244 | int i; | 244 | int i; |
245 | ColumnDef *pDef; | 245 | ColumnDef *pDef; |
246 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { | 246 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { |
247 | if( pDef->hasFlag(ColumnDef::typeUnique) ) | 247 | if( pDef->hasFlag(ColumnDef::typeUnique) ) |
248 | fixTypes(i); | 248 | fixTypes(i); |
249 | } | 249 | } |
250 | _typeTable->sort(); | 250 | _typeTable->sort(); |
251 | } | 251 | } |
252 | 252 | ||
253 | 253 | ||
254 | // --- storeInList ------------------------------------------------------------ | 254 | // --- storeInList ------------------------------------------------------------ |
255 | void ListEdit::storeInList(QStringList &lst) | 255 | void ListEdit::storeInList(QStringList &lst) |
256 | { | 256 | { |
257 | // delete old content | 257 | // delete old content |
258 | lst.clear(); | 258 | lst.clear(); |
259 | 259 | ||
260 | // add new one | 260 | // add new one |
261 | fixTypes(); | 261 | fixTypes(); |
262 | QListViewItem *itm=_typeTable->firstChild(); | 262 | QListViewItem *itm=_typeTable->firstChild(); |
263 | while( itm ) { | 263 | while( itm ) { |
264 | int i=0; | 264 | int i=0; |
265 | QString sAdd; | 265 | QString sAdd; |
266 | ColumnDef *pDef; | 266 | ColumnDef *pDef; |
267 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { | 267 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { |
268 | if( i>=1 ) sAdd+=";"; | 268 | if( i>=1 ) sAdd+=";"; |
269 | sAdd += itm->text(i); | 269 | sAdd += itm->text(i); |
270 | } | 270 | } |
271 | lst.append( sAdd ); | 271 | lst.append( sAdd ); |
272 | itm=itm->nextSibling(); | 272 | itm=itm->nextSibling(); |
273 | } | 273 | } |
274 | } | 274 | } |
275 | 275 | ||
276 | 276 | ||
277 | // --- slotClicked ------------------------------------------------------------ | 277 | // --- slotClicked ------------------------------------------------------------ |
278 | void ListEdit::slotClick(QListViewItem *itm, const QPoint &pnt, int col) | 278 | void ListEdit::slotClick(QListViewItem *itm, const QPoint &pnt, int col) |
279 | { | 279 | { |
280 | (void)pnt; // get rid of unused warning; | 280 | (void)pnt; // get rid of unused warning; |
281 | 281 | ||
282 | // save values | 282 | // save values |
283 | _currentItem=itm; | 283 | _currentItem=itm; |
284 | _currentColumn=col; | 284 | _currentColumn=col; |
285 | if( itm==NULL ) { | 285 | if( itm==NULL ) { |
286 | _typeEdit->setText(""); | 286 | _typeEdit->setText(""); |
287 | _stack->raiseWidget(_typeEdit); | 287 | _stack->raiseWidget(_typeEdit); |
288 | return; | 288 | return; |
289 | } | 289 | } |
290 | 290 | ||
291 | // display value | 291 | // display value |
292 | if( _currentColumn<0 ) _currentColumn=0; | 292 | if( _currentColumn<0 ) _currentColumn=0; |
293 | ColumnDef *pDef=this->at(_currentColumn); | 293 | ColumnDef *pDef=this->at(_currentColumn); |
294 | if( pDef->isType(ColumnDef::typeString) ) { | 294 | if( pDef->isType(ColumnDef::typeString) ) { |
295 | _typeEdit->setText( _currentItem->text(_currentColumn) ); | 295 | _typeEdit->setText( _currentItem->text(_currentColumn) ); |
296 | _stack->raiseWidget(_typeEdit); | 296 | _stack->raiseWidget(_typeEdit); |
297 | } else if( pDef->isType(ColumnDef::typeList) ){ | 297 | } else if( pDef->isType(ColumnDef::typeList) ){ |
298 | _box->clear(); | 298 | _box->clear(); |
299 | _box->insertStringList( pDef->getValueList() ); | 299 | _box->insertStringList( pDef->getValueList() ); |
300 | QStringList::Iterator itr; | 300 | QStringList::Iterator itr; |
301 | int i=0; | 301 | int i=0; |
302 | for(itr=pDef->getValueList().begin(); itr!=pDef->getValueList().end(); itr++) { | 302 | for(itr=pDef->getValueList().begin(); itr!=pDef->getValueList().end(); itr++) { |
303 | if( (*itr)==_currentItem->text(_currentColumn) ) { | 303 | if( (*itr)==_currentItem->text(_currentColumn) ) { |
304 | _box->setCurrentItem(i); | 304 | _box->setCurrentItem(i); |
305 | i=-1; | 305 | i=-1; |
306 | break; | 306 | break; |
307 | } | 307 | } |
308 | i++; | 308 | i++; |
309 | } | 309 | } |
310 | if( i>=0 ) { | 310 | if( i>=0 ) { |
311 | _box->insertItem( _currentItem->text(_currentColumn) ); | 311 | _box->insertItem( _currentItem->text(_currentColumn) ); |
312 | _box->setCurrentItem(i); | 312 | _box->setCurrentItem(i); |
313 | } | 313 | } |
314 | _stack->raiseWidget(_box); | 314 | _stack->raiseWidget(_box); |
315 | } else { | 315 | } else { |
316 | odebug << "Unsupported column type for column " << (const char *)pDef->getName() << "" << oendl; | 316 | odebug << "Unsupported column type for column " << (const char *)pDef->getName() << "" << oendl; |
317 | _typeEdit->setText(""); | 317 | _typeEdit->setText(""); |
318 | _stack->raiseWidget(_typeEdit); | 318 | _stack->raiseWidget(_typeEdit); |
319 | } | 319 | } |
320 | } | 320 | } |
321 | 321 | ||
322 | 322 | ||
323 | // --- addColumnDef ----------------------------------------------------------- | 323 | // --- addColumnDef ----------------------------------------------------------- |
324 | void ListEdit::addColumnDef(ColumnDef *pDef) | 324 | void ListEdit::addColumnDef(ColumnDef *pDef) |
325 | { | 325 | { |
326 | _typeTable->addColumn( pDef->getName() ); | 326 | _typeTable->addColumn( pDef->getName() ); |
327 | _vColumns.append(pDef); | 327 | _vColumns.append(pDef); |
328 | } | 328 | } |
329 | 329 | ||
330 | // --- addData ---------------------------------------------------------------- | 330 | // --- addData ---------------------------------------------------------------- |
331 | void ListEdit::addData(QStringList &lst) | 331 | void ListEdit::addData(QStringList &lst) |
332 | { | 332 | { |
333 | // run through list | 333 | // run through list |
334 | QStringList::Iterator itr; | 334 | QStringList::Iterator itr; |
335 | for(itr=lst.begin(); itr!=lst.end(); itr++) { | 335 | for(itr=lst.begin(); itr!=lst.end(); itr++) { |
336 | QStringList split=QStringList::split(";", *itr, true); | 336 | QStringList split=QStringList::split(";", *itr, true); |
337 | QStringList::Iterator entry; | 337 | QStringList::Iterator entry; |
338 | QString args[8]; | 338 | QString args[8]; |
339 | int i=0; | 339 | int i=0; |
340 | for(entry=split.begin(); entry!=split.end() && i<8; entry++, i++) { | 340 | for(entry=split.begin(); entry!=split.end() && i<8; entry++, i++) { |
341 | args[i]= (*entry); | 341 | args[i]= (*entry); |
342 | } | 342 | } |
343 | while(i<8) { | 343 | while(i<8) { |
344 | args[i++]=""; | 344 | args[i++]=""; |
345 | } | 345 | } |
346 | new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); | 346 | new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); |
347 | } | 347 | } |
348 | } | 348 | } |
349 | 349 | ||
350 | // --- slotActivated ---------------------------------------------------------- | 350 | // --- slotActivated ---------------------------------------------------------- |
351 | void ListEdit::slotActivated(const QString &str) | 351 | void ListEdit::slotActivated(const QString &str) |
352 | { | 352 | { |
353 | if( _currentItem==NULL || _currentColumn<0 ) return; | 353 | if( _currentItem==NULL || _currentColumn<0 ) return; |
354 | _currentItem->setText(_currentColumn, str); | 354 | _currentItem->setText(_currentColumn, str); |
355 | } | 355 | } |
diff --git a/noncore/apps/opie-console/TEScreen.cpp b/noncore/apps/opie-console/TEScreen.cpp index 2675d31..8e91532 100644 --- a/noncore/apps/opie-console/TEScreen.cpp +++ b/noncore/apps/opie-console/TEScreen.cpp | |||
@@ -734,475 +734,475 @@ void TEScreen::setCursorY(int y) | |||
734 | */ | 734 | */ |
735 | 735 | ||
736 | void TEScreen::home() | 736 | void TEScreen::home() |
737 | { | 737 | { |
738 | cuX = 0; | 738 | cuX = 0; |
739 | cuY = 0; | 739 | cuY = 0; |
740 | } | 740 | } |
741 | 741 | ||
742 | /*! set cursor to the begin of the current line. | 742 | /*! set cursor to the begin of the current line. |
743 | */ | 743 | */ |
744 | 744 | ||
745 | void TEScreen::Return() | 745 | void TEScreen::Return() |
746 | { | 746 | { |
747 | cuX = 0; | 747 | cuX = 0; |
748 | } | 748 | } |
749 | 749 | ||
750 | /*! returns the current cursor columns. | 750 | /*! returns the current cursor columns. |
751 | */ | 751 | */ |
752 | 752 | ||
753 | int TEScreen::getCursorX() | 753 | int TEScreen::getCursorX() |
754 | { | 754 | { |
755 | return cuX; | 755 | return cuX; |
756 | } | 756 | } |
757 | 757 | ||
758 | /*! returns the current cursor line. | 758 | /*! returns the current cursor line. |
759 | */ | 759 | */ |
760 | 760 | ||
761 | int TEScreen::getCursorY() | 761 | int TEScreen::getCursorY() |
762 | { | 762 | { |
763 | return cuY; | 763 | return cuY; |
764 | } | 764 | } |
765 | 765 | ||
766 | // Erasing --------------------------------------------------------------------- | 766 | // Erasing --------------------------------------------------------------------- |
767 | 767 | ||
768 | /*! \section Erasing | 768 | /*! \section Erasing |
769 | 769 | ||
770 | This group of operations erase parts of the screen contents by filling | 770 | This group of operations erase parts of the screen contents by filling |
771 | it with spaces colored due to the current rendition settings. | 771 | it with spaces colored due to the current rendition settings. |
772 | 772 | ||
773 | Althought the cursor position is involved in most of these operations, | 773 | Althought the cursor position is involved in most of these operations, |
774 | it is never modified by them. | 774 | it is never modified by them. |
775 | */ | 775 | */ |
776 | 776 | ||
777 | /*! fill screen between (including) `loca' and `loce' with spaces. | 777 | /*! fill screen between (including) `loca' and `loce' with spaces. |
778 | 778 | ||
779 | This is an internal helper functions. The parameter types are internal | 779 | This is an internal helper functions. The parameter types are internal |
780 | addresses of within the screen image and make use of the way how the | 780 | addresses of within the screen image and make use of the way how the |
781 | screen matrix is mapped to the image vector. | 781 | screen matrix is mapped to the image vector. |
782 | */ | 782 | */ |
783 | 783 | ||
784 | void TEScreen::clearImage(int loca, int loce, char c) | 784 | void TEScreen::clearImage(int loca, int loce, char c) |
785 | { int i; | 785 | { int i; |
786 | int scr_TL=loc(0,hist.getLines()); | 786 | int scr_TL=loc(0,hist.getLines()); |
787 | //FIXME: check positions | 787 | //FIXME: check positions |
788 | 788 | ||
789 | //Clear entire selection if it overlaps region to be moved... | 789 | //Clear entire selection if it overlaps region to be moved... |
790 | if ( (sel_BR > (loca+scr_TL) )&&(sel_TL < (loce+scr_TL)) ) | 790 | if ( (sel_BR > (loca+scr_TL) )&&(sel_TL < (loce+scr_TL)) ) |
791 | { | 791 | { |
792 | clearSelection(); | 792 | clearSelection(); |
793 | } | 793 | } |
794 | for (i = loca; i <= loce; i++) | 794 | for (i = loca; i <= loce; i++) |
795 | { | 795 | { |
796 | image[i].c = c; | 796 | image[i].c = c; |
797 | image[i].f = ef_fg; //DEFAULT_FORE_COLOR; //FIXME: xterm and linux/ansi | 797 | image[i].f = ef_fg; //DEFAULT_FORE_COLOR; //FIXME: xterm and linux/ansi |
798 | image[i].b = ef_bg; //DEFAULT_BACK_COLOR; // many have different | 798 | image[i].b = ef_bg; //DEFAULT_BACK_COLOR; // many have different |
799 | image[i].r = ef_re; //DEFAULT_RENDITION; // ideas here. | 799 | image[i].r = ef_re; //DEFAULT_RENDITION; // ideas here. |
800 | } | 800 | } |
801 | } | 801 | } |
802 | 802 | ||
803 | /*! move image between (including) `loca' and `loce' to 'dst'. | 803 | /*! move image between (including) `loca' and `loce' to 'dst'. |
804 | 804 | ||
805 | This is an internal helper functions. The parameter types are internal | 805 | This is an internal helper functions. The parameter types are internal |
806 | addresses of within the screen image and make use of the way how the | 806 | addresses of within the screen image and make use of the way how the |
807 | screen matrix is mapped to the image vector. | 807 | screen matrix is mapped to the image vector. |
808 | */ | 808 | */ |
809 | 809 | ||
810 | void TEScreen::moveImage(int dst, int loca, int loce) | 810 | void TEScreen::moveImage(int dst, int loca, int loce) |
811 | { | 811 | { |
812 | //FIXME: check positions | 812 | //FIXME: check positions |
813 | if (loce < loca) { | 813 | if (loce < loca) { |
814 | // kdDebug() << "WARNING!!! call to TEScreen:moveImage with loce < loca!" << endl; | 814 | // kdDebug() << "WARNING!!! call to TEScreen:moveImage with loce < loca!" << endl; |
815 | return; | 815 | return; |
816 | } | 816 | } |
817 | memmove(&image[dst],&image[loca],(loce-loca+1)*sizeof(ca)); | 817 | memmove(&image[dst],&image[loca],(loce-loca+1)*sizeof(ca)); |
818 | } | 818 | } |
819 | 819 | ||
820 | /*! clear from (including) current cursor position to end of screen. | 820 | /*! clear from (including) current cursor position to end of screen. |
821 | */ | 821 | */ |
822 | 822 | ||
823 | void TEScreen::clearToEndOfScreen() | 823 | void TEScreen::clearToEndOfScreen() |
824 | { | 824 | { |
825 | clearImage(loc(cuX,cuY),loc(columns-1,lines-1),' '); | 825 | clearImage(loc(cuX,cuY),loc(columns-1,lines-1),' '); |
826 | } | 826 | } |
827 | 827 | ||
828 | /*! clear from begin of screen to (including) current cursor position. | 828 | /*! clear from begin of screen to (including) current cursor position. |
829 | */ | 829 | */ |
830 | 830 | ||
831 | void TEScreen::clearToBeginOfScreen() | 831 | void TEScreen::clearToBeginOfScreen() |
832 | { | 832 | { |
833 | clearImage(loc(0,0),loc(cuX,cuY),' '); | 833 | clearImage(loc(0,0),loc(cuX,cuY),' '); |
834 | } | 834 | } |
835 | 835 | ||
836 | /*! clear the entire screen. | 836 | /*! clear the entire screen. |
837 | */ | 837 | */ |
838 | 838 | ||
839 | void TEScreen::clearEntireScreen() | 839 | void TEScreen::clearEntireScreen() |
840 | { | 840 | { |
841 | clearImage(loc(0,0),loc(columns-1,lines-1),' '); | 841 | clearImage(loc(0,0),loc(columns-1,lines-1),' '); |
842 | } | 842 | } |
843 | 843 | ||
844 | /*! fill screen with 'E' | 844 | /*! fill screen with 'E' |
845 | This is to aid screen alignment | 845 | This is to aid screen alignment |
846 | */ | 846 | */ |
847 | 847 | ||
848 | void TEScreen::helpAlign() | 848 | void TEScreen::helpAlign() |
849 | { | 849 | { |
850 | clearImage(loc(0,0),loc(columns-1,lines-1),'E'); | 850 | clearImage(loc(0,0),loc(columns-1,lines-1),'E'); |
851 | } | 851 | } |
852 | 852 | ||
853 | /*! clear from (including) current cursor position to end of current cursor line. | 853 | /*! clear from (including) current cursor position to end of current cursor line. |
854 | */ | 854 | */ |
855 | 855 | ||
856 | void TEScreen::clearToEndOfLine() | 856 | void TEScreen::clearToEndOfLine() |
857 | { | 857 | { |
858 | clearImage(loc(cuX,cuY),loc(columns-1,cuY),' '); | 858 | clearImage(loc(cuX,cuY),loc(columns-1,cuY),' '); |
859 | } | 859 | } |
860 | 860 | ||
861 | /*! clear from begin of current cursor line to (including) current cursor position. | 861 | /*! clear from begin of current cursor line to (including) current cursor position. |
862 | */ | 862 | */ |
863 | 863 | ||
864 | void TEScreen::clearToBeginOfLine() | 864 | void TEScreen::clearToBeginOfLine() |
865 | { | 865 | { |
866 | clearImage(loc(0,cuY),loc(cuX,cuY),' '); | 866 | clearImage(loc(0,cuY),loc(cuX,cuY),' '); |
867 | } | 867 | } |
868 | 868 | ||
869 | /*! clears entire current cursor line | 869 | /*! clears entire current cursor line |
870 | */ | 870 | */ |
871 | 871 | ||
872 | void TEScreen::clearEntireLine() | 872 | void TEScreen::clearEntireLine() |
873 | { | 873 | { |
874 | clearImage(loc(0,cuY),loc(columns-1,cuY),' '); | 874 | clearImage(loc(0,cuY),loc(columns-1,cuY),' '); |
875 | } | 875 | } |
876 | 876 | ||
877 | // Rendition ------------------------------------------------------------------ | 877 | // Rendition ------------------------------------------------------------------ |
878 | 878 | ||
879 | /*! | 879 | /*! |
880 | set rendition mode | 880 | set rendition mode |
881 | */ | 881 | */ |
882 | 882 | ||
883 | void TEScreen::setRendition(int re) | 883 | void TEScreen::setRendition(int re) |
884 | { | 884 | { |
885 | cu_re |= re; | 885 | cu_re |= re; |
886 | effectiveRendition(); | 886 | effectiveRendition(); |
887 | } | 887 | } |
888 | 888 | ||
889 | /*! | 889 | /*! |
890 | reset rendition mode | 890 | reset rendition mode |
891 | */ | 891 | */ |
892 | 892 | ||
893 | void TEScreen::resetRendition(int re) | 893 | void TEScreen::resetRendition(int re) |
894 | { | 894 | { |
895 | cu_re &= ~re; | 895 | cu_re &= ~re; |
896 | effectiveRendition(); | 896 | effectiveRendition(); |
897 | } | 897 | } |
898 | 898 | ||
899 | /*! | 899 | /*! |
900 | */ | 900 | */ |
901 | 901 | ||
902 | void TEScreen::setDefaultRendition() | 902 | void TEScreen::setDefaultRendition() |
903 | { | 903 | { |
904 | setForeColorToDefault(); | 904 | setForeColorToDefault(); |
905 | setBackColorToDefault(); | 905 | setBackColorToDefault(); |
906 | cu_re = DEFAULT_RENDITION; | 906 | cu_re = DEFAULT_RENDITION; |
907 | effectiveRendition(); | 907 | effectiveRendition(); |
908 | } | 908 | } |
909 | 909 | ||
910 | /*! | 910 | /*! |
911 | */ | 911 | */ |
912 | 912 | ||
913 | void TEScreen::setForeColor(int fgcolor) | 913 | void TEScreen::setForeColor(int fgcolor) |
914 | { | 914 | { |
915 | cu_fg = (fgcolor&7)+((fgcolor&8) ? 4+8 : 2); | 915 | cu_fg = (fgcolor&7)+((fgcolor&8) ? 4+8 : 2); |
916 | effectiveRendition(); | 916 | effectiveRendition(); |
917 | } | 917 | } |
918 | 918 | ||
919 | /*! | 919 | /*! |
920 | */ | 920 | */ |
921 | 921 | ||
922 | void TEScreen::setBackColor(int bgcolor) | 922 | void TEScreen::setBackColor(int bgcolor) |
923 | { | 923 | { |
924 | cu_bg = (bgcolor&7)+((bgcolor&8) ? 4+8 : 2); | 924 | cu_bg = (bgcolor&7)+((bgcolor&8) ? 4+8 : 2); |
925 | effectiveRendition(); | 925 | effectiveRendition(); |
926 | } | 926 | } |
927 | 927 | ||
928 | /*! | 928 | /*! |
929 | */ | 929 | */ |
930 | 930 | ||
931 | void TEScreen::setBackColorToDefault() | 931 | void TEScreen::setBackColorToDefault() |
932 | { | 932 | { |
933 | cu_bg = DEFAULT_BACK_COLOR; | 933 | cu_bg = DEFAULT_BACK_COLOR; |
934 | effectiveRendition(); | 934 | effectiveRendition(); |
935 | } | 935 | } |
936 | 936 | ||
937 | /*! | 937 | /*! |
938 | */ | 938 | */ |
939 | 939 | ||
940 | void TEScreen::setForeColorToDefault() | 940 | void TEScreen::setForeColorToDefault() |
941 | { | 941 | { |
942 | cu_fg = DEFAULT_FORE_COLOR; | 942 | cu_fg = DEFAULT_FORE_COLOR; |
943 | effectiveRendition(); | 943 | effectiveRendition(); |
944 | } | 944 | } |
945 | 945 | ||
946 | /* ------------------------------------------------------------------------- */ | 946 | /* ------------------------------------------------------------------------- */ |
947 | /* */ | 947 | /* */ |
948 | /* Marking & Selection */ | 948 | /* Marking & Selection */ |
949 | /* */ | 949 | /* */ |
950 | /* ------------------------------------------------------------------------- */ | 950 | /* ------------------------------------------------------------------------- */ |
951 | 951 | ||
952 | void TEScreen::clearSelection() | 952 | void TEScreen::clearSelection() |
953 | { | 953 | { |
954 | sel_BR = -1; | 954 | sel_BR = -1; |
955 | sel_TL = -1; | 955 | sel_TL = -1; |
956 | sel_begin = -1; | 956 | sel_begin = -1; |
957 | } | 957 | } |
958 | 958 | ||
959 | void TEScreen::setSelBeginXY(const int x, const int y) | 959 | void TEScreen::setSelBeginXY(const int x, const int y) |
960 | { | 960 | { |
961 | sel_begin = loc(x,y+histCursor) ; | 961 | sel_begin = loc(x,y+histCursor) ; |
962 | sel_BR = sel_begin; | 962 | sel_BR = sel_begin; |
963 | sel_TL = sel_begin; | 963 | sel_TL = sel_begin; |
964 | } | 964 | } |
965 | 965 | ||
966 | void TEScreen::setSelExtentXY(const int x, const int y) | 966 | void TEScreen::setSelExtentXY(const int x, const int y) |
967 | { | 967 | { |
968 | if (sel_begin == -1) return; | 968 | if (sel_begin == -1) return; |
969 | int l = loc(x,y + histCursor); | 969 | int l = loc(x,y + histCursor); |
970 | 970 | ||
971 | if (l < sel_begin) | 971 | if (l < sel_begin) |
972 | { | 972 | { |
973 | sel_TL = l; | 973 | sel_TL = l; |
974 | sel_BR = sel_begin; | 974 | sel_BR = sel_begin; |
975 | } | 975 | } |
976 | else | 976 | else |
977 | { | 977 | { |
978 | /* FIXME, HACK to correct for x too far to the right... */ | 978 | /* FIXME, HACK to correct for x too far to the right... */ |
979 | if (( x == columns )|| (x == 0)) l--; | 979 | if (( x == columns )|| (x == 0)) l--; |
980 | 980 | ||
981 | sel_TL = sel_begin; | 981 | sel_TL = sel_begin; |
982 | sel_BR = l; | 982 | sel_BR = l; |
983 | } | 983 | } |
984 | } | 984 | } |
985 | 985 | ||
986 | QString TEScreen::getSelText(const BOOL preserve_line_breaks) | 986 | QString TEScreen::getSelText(const BOOL preserve_line_breaks) |
987 | { | 987 | { |
988 | if (sel_begin == -1) | 988 | if (sel_begin == -1) |
989 | return QString::null; // Selection got clear while selecting. | 989 | return QString::null; // Selection got clear while selecting. |
990 | 990 | ||
991 | int *m; // buffer to fill. | 991 | int *m; // buffer to fill. |
992 | int s, d; // source index, dest. index. | 992 | int s, d; // source index, dest. index. |
993 | int hist_BR = loc(0, hist.getLines()); | 993 | int hist_BR = loc(0, hist.getLines()); |
994 | int hY = sel_TL / columns; | 994 | int hY = sel_TL / columns; |
995 | int hX = sel_TL % columns; | 995 | int hX = sel_TL % columns; |
996 | int eol; // end of line | 996 | int eol; // end of line |
997 | 997 | ||
998 | s = sel_TL; // tracks copy in source. | 998 | s = sel_TL; // tracks copy in source. |
999 | 999 | ||
1000 | // allocate buffer for maximum | 1000 | // allocate buffer for maximum |
1001 | // possible size... | 1001 | // possible size... |
1002 | d = (sel_BR - sel_TL) / columns + 1; | 1002 | d = (sel_BR - sel_TL) / columns + 1; |
1003 | m = new int[d * (columns + 1) + 2]; | 1003 | m = new int[d * (columns + 1) + 2]; |
1004 | d = 0; | 1004 | d = 0; |
1005 | 1005 | ||
1006 | while (s <= sel_BR) | 1006 | while (s <= sel_BR) |
1007 | { | 1007 | { |
1008 | if (s < hist_BR) | 1008 | if (s < hist_BR) |
1009 | { // get lines from hist.history | 1009 | { // get lines from hist.history |
1010 | // buffer. | 1010 | // buffer. |
1011 | eol = hist.getLineLen(hY); | 1011 | eol = hist.getLineLen(hY); |
1012 | 1012 | ||
1013 | if ((hY == (sel_BR / columns)) && | 1013 | if ((hY == (sel_BR / columns)) && |
1014 | (eol >= (sel_BR % columns))) | 1014 | (eol >= (sel_BR % columns))) |
1015 | { | 1015 | { |
1016 | eol = sel_BR % columns + 1; | 1016 | eol = sel_BR % columns + 1; |
1017 | } | 1017 | } |
1018 | 1018 | ||
1019 | while (hX < eol) | 1019 | while (hX < eol) |
1020 | { | 1020 | { |
1021 | m[d++] = hist.getCell(hY, hX++).c; | 1021 | m[d++] = hist.getCell(hY, hX++).c; |
1022 | s++; | 1022 | s++; |
1023 | } | 1023 | } |
1024 | 1024 | ||
1025 | if (s <= sel_BR) | 1025 | if (s <= sel_BR) |
1026 | { | 1026 | { |
1027 | // The line break handling | 1027 | // The line break handling |
1028 | // It's different from the screen | 1028 | // It's different from the screen |
1029 | // image case! | 1029 | // image case! |
1030 | if (eol % columns == 0) | 1030 | if (eol % columns == 0) |
1031 | { | 1031 | { |
1032 | // That's either a completely filled | 1032 | // That's either a completely filled |
1033 | // line or an empty line | 1033 | // line or an empty line |
1034 | if (eol == 0) | 1034 | if (eol == 0) |
1035 | { | 1035 | { |
1036 | m[d++] = '\n'; | 1036 | m[d++] = '\n'; |
1037 | } | 1037 | } |
1038 | else | 1038 | else |
1039 | { | 1039 | { |
1040 | // We have a full line. | 1040 | // We have a full line. |
1041 | // FIXME: How can we handle newlines | 1041 | // FIXME: How can we handle newlines |
1042 | // at this position?! | 1042 | // at this position?! |
1043 | } | 1043 | } |
1044 | } | 1044 | } |
1045 | else if ((eol + 1) % columns == 0) | 1045 | else if ((eol + 1) % columns == 0) |
1046 | { | 1046 | { |
1047 | // FIXME: We don't know if this was a | 1047 | // FIXME: We don't know if this was a |
1048 | // space at the last position or a | 1048 | // space at the last position or a |
1049 | // short line!! | 1049 | // short line!! |
1050 | m[d++] = ' '; | 1050 | m[d++] = ' '; |
1051 | } | 1051 | } |
1052 | else | 1052 | else |
1053 | { | 1053 | { |
1054 | // We have a short line here. Put a | 1054 | // We have a short line here. Put a |
1055 | // newline or a space into the | 1055 | // newline or a space into the |
1056 | // buffer. | 1056 | // buffer. |
1057 | m[d++] = preserve_line_breaks ? '\n' : ' '; | 1057 | m[d++] = preserve_line_breaks ? '\n' : ' '; |
1058 | } | 1058 | } |
1059 | } | 1059 | } |
1060 | 1060 | ||
1061 | hY++; | 1061 | hY++; |
1062 | hX = 0; | 1062 | hX = 0; |
1063 | s = hY * columns; | 1063 | s = hY * columns; |
1064 | } | 1064 | } |
1065 | else | 1065 | else |
1066 | { // or from screen image. | 1066 | { // or from screen image. |
1067 | eol = (s / columns + 1) * columns - 1; | 1067 | eol = (s / columns + 1) * columns - 1; |
1068 | 1068 | ||
1069 | if (eol < sel_BR) | 1069 | if (eol < sel_BR) |
1070 | { | 1070 | { |
1071 | while ((eol > s) && | 1071 | while ((eol > s) && |
1072 | isspace(image[eol - hist_BR].c)) | 1072 | isspace(image[eol - hist_BR].c)) |
1073 | { | 1073 | { |
1074 | eol--; | 1074 | eol--; |
1075 | } | 1075 | } |
1076 | } | 1076 | } |
1077 | else | 1077 | else |
1078 | { | 1078 | { |
1079 | eol = sel_BR; | 1079 | eol = sel_BR; |
1080 | } | 1080 | } |
1081 | 1081 | ||
1082 | while (s <= eol) | 1082 | while (s <= eol) |
1083 | { | 1083 | { |
1084 | m[d++] = image[s++ - hist_BR].c; | 1084 | m[d++] = image[s++ - hist_BR].c; |
1085 | } | 1085 | } |
1086 | 1086 | ||
1087 | if (eol < sel_BR) | 1087 | if (eol < sel_BR) |
1088 | { | 1088 | { |
1089 | // eol processing see below ... | 1089 | // eol processing see below ... |
1090 | if ((eol + 1) % columns == 0) | 1090 | if ((eol + 1) % columns == 0) |
1091 | { | 1091 | { |
1092 | if (image[eol - hist_BR].c == ' ') | 1092 | if (image[eol - hist_BR].c == ' ') |
1093 | { | 1093 | { |
1094 | m[d++] = ' '; | 1094 | m[d++] = ' '; |
1095 | } | 1095 | } |
1096 | } | 1096 | } |
1097 | else | 1097 | else |
1098 | { | 1098 | { |
1099 | m[d++] = ((preserve_line_breaks || | 1099 | m[d++] = ((preserve_line_breaks || |
1100 | ((eol % columns) == 0)) ? | 1100 | ((eol % columns) == 0)) ? |
1101 | '\n' : ' '); | 1101 | '\n' : ' '); |
1102 | } | 1102 | } |
1103 | } | 1103 | } |
1104 | 1104 | ||
1105 | s = (eol / columns + 1) * columns; | 1105 | s = (eol / columns + 1) * columns; |
1106 | } | 1106 | } |
1107 | } | 1107 | } |
1108 | 1108 | ||
1109 | QChar* qc = new QChar[d]; | 1109 | QChar* qc = new QChar[d]; |
1110 | 1110 | ||
1111 | for (int i = 0; i < d; i++) | 1111 | for (int i = 0; i < d; i++) |
1112 | { | 1112 | { |
1113 | qc[i] = m[i]; | 1113 | qc[i] = m[i]; |
1114 | } | 1114 | } |
1115 | 1115 | ||
1116 | QString res(qc, d); | 1116 | QString res(qc, d); |
1117 | 1117 | ||
1118 | delete m; | 1118 | delete [] m; |
1119 | delete qc; | 1119 | delete [] qc; |
1120 | 1120 | ||
1121 | return res; | 1121 | return res; |
1122 | } | 1122 | } |
1123 | QString TEScreen::getHistory() { | 1123 | QString TEScreen::getHistory() { |
1124 | sel_begin = 0; | 1124 | sel_begin = 0; |
1125 | sel_BR = sel_begin; | 1125 | sel_BR = sel_begin; |
1126 | sel_TL = sel_begin; | 1126 | sel_TL = sel_begin; |
1127 | setSelExtentXY(columns-1,lines-1); | 1127 | setSelExtentXY(columns-1,lines-1); |
1128 | QString tmp=getSelText(true); | 1128 | QString tmp=getSelText(true); |
1129 | while (tmp.at(tmp.length()-2).unicode()==10 && tmp.at(tmp.length()-1).unicode()==10) | 1129 | while (tmp.at(tmp.length()-2).unicode()==10 && tmp.at(tmp.length()-1).unicode()==10) |
1130 | tmp.truncate(tmp.length()-1); | 1130 | tmp.truncate(tmp.length()-1); |
1131 | 1131 | ||
1132 | return tmp; | 1132 | return tmp; |
1133 | } | 1133 | } |
1134 | /* above ... end of line processing for selection -- psilva | 1134 | /* above ... end of line processing for selection -- psilva |
1135 | cases: | 1135 | cases: |
1136 | 1136 | ||
1137 | 1) (eol+1)%columns == 0 --> the whole line is filled. | 1137 | 1) (eol+1)%columns == 0 --> the whole line is filled. |
1138 | If the last char is a space, insert (preserve) space. otherwise | 1138 | If the last char is a space, insert (preserve) space. otherwise |
1139 | leave the text alone, so that words that are broken by linewrap | 1139 | leave the text alone, so that words that are broken by linewrap |
1140 | are preserved. | 1140 | are preserved. |
1141 | 1141 | ||
1142 | FIXME: | 1142 | FIXME: |
1143 | * this suppresses \n for command output that is | 1143 | * this suppresses \n for command output that is |
1144 | sized to the exact column width of the screen. | 1144 | sized to the exact column width of the screen. |
1145 | 1145 | ||
1146 | 2) eol%columns == 0 --> blank line. | 1146 | 2) eol%columns == 0 --> blank line. |
1147 | insert a \n unconditionally. | 1147 | insert a \n unconditionally. |
1148 | Do it either you would because you are in preserve_line_break mode, | 1148 | Do it either you would because you are in preserve_line_break mode, |
1149 | or because it's an ASCII paragraph delimiter, so even when | 1149 | or because it's an ASCII paragraph delimiter, so even when |
1150 | not preserving line_breaks, you want to preserve paragraph breaks. | 1150 | not preserving line_breaks, you want to preserve paragraph breaks. |
1151 | 1151 | ||
1152 | 3) else --> partially filled line | 1152 | 3) else --> partially filled line |
1153 | insert a \n in preserve line break mode, else a space | 1153 | insert a \n in preserve line break mode, else a space |
1154 | The space prevents concatenation of the last word of one | 1154 | The space prevents concatenation of the last word of one |
1155 | line with the first of the next. | 1155 | line with the first of the next. |
1156 | 1156 | ||
1157 | */ | 1157 | */ |
1158 | 1158 | ||
1159 | void TEScreen::addHistLine() | 1159 | void TEScreen::addHistLine() |
1160 | { | 1160 | { |
1161 | assert(hasScroll() || histCursor == 0); | 1161 | assert(hasScroll() || histCursor == 0); |
1162 | 1162 | ||
1163 | // add to hist buffer | 1163 | // add to hist buffer |
1164 | // we have to take care about scrolling, too... | 1164 | // we have to take care about scrolling, too... |
1165 | 1165 | ||
1166 | if (hasScroll()) | 1166 | if (hasScroll()) |
1167 | { ca dft; | 1167 | { ca dft; |
1168 | 1168 | ||
1169 | int end = columns-1; | 1169 | int end = columns-1; |
1170 | while (end >= 0 && image[end] == dft) | 1170 | while (end >= 0 && image[end] == dft) |
1171 | end -= 1; | 1171 | end -= 1; |
1172 | 1172 | ||
1173 | hist.addCells(image,end+1); | 1173 | hist.addCells(image,end+1); |
1174 | hist.addLine(); | 1174 | hist.addLine(); |
1175 | 1175 | ||
1176 | // adjust history cursor | 1176 | // adjust history cursor |
1177 | histCursor += (hist.getLines()-1 == histCursor); | 1177 | histCursor += (hist.getLines()-1 == histCursor); |
1178 | } | 1178 | } |
1179 | 1179 | ||
1180 | if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround | 1180 | if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround |
1181 | } | 1181 | } |
1182 | 1182 | ||
1183 | void TEScreen::setHistCursor(int cursor) | 1183 | void TEScreen::setHistCursor(int cursor) |
1184 | { | 1184 | { |
1185 | histCursor = cursor; //FIXME:rangecheck | 1185 | histCursor = cursor; //FIXME:rangecheck |
1186 | } | 1186 | } |
1187 | 1187 | ||
1188 | int TEScreen::getHistCursor() | 1188 | int TEScreen::getHistCursor() |
1189 | { | 1189 | { |
1190 | return histCursor; | 1190 | return histCursor; |
1191 | } | 1191 | } |
1192 | 1192 | ||
1193 | int TEScreen::getHistLines() | 1193 | int TEScreen::getHistLines() |
1194 | { | 1194 | { |
1195 | return hist.getLines(); | 1195 | return hist.getLines(); |
1196 | } | 1196 | } |
1197 | 1197 | ||
1198 | void TEScreen::setScroll(bool on) | 1198 | void TEScreen::setScroll(bool on) |
1199 | { | 1199 | { |
1200 | histCursor = 0; | 1200 | histCursor = 0; |
1201 | clearSelection(); | 1201 | clearSelection(); |
1202 | hist.setScroll(on); | 1202 | hist.setScroll(on); |
1203 | } | 1203 | } |
1204 | 1204 | ||
1205 | bool TEScreen::hasScroll() | 1205 | bool TEScreen::hasScroll() |
1206 | { | 1206 | { |
1207 | return hist.hasScroll(); | 1207 | return hist.hasScroll(); |
1208 | } | 1208 | } |
diff --git a/noncore/apps/opie-sheet/Excel.cpp b/noncore/apps/opie-sheet/Excel.cpp index 338bc30..51fe707 100644 --- a/noncore/apps/opie-sheet/Excel.cpp +++ b/noncore/apps/opie-sheet/Excel.cpp | |||
@@ -1,725 +1,725 @@ | |||
1 | /* | 1 | /* |
2 | =. This file is part of the Opie Project | 2 | =. This file is part of the Opie Project |
3 | .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org> | 3 | .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org> |
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This program is free software; you can | 5 | _;:, .> :=|. This program is free software; you can |
6 | .> <`_, > . <= redistribute it and/or modify it under | 6 | .> <`_, > . <= redistribute it and/or modify it under |
7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 11 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This program is distributed in the hope that | 12 | .i_,=:_. -<s. This program is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
17 | ..}^=.= = ; Library General Public License for more | 17 | ..}^=.= = ; Library General Public License for more |
18 | ++= -. .` .: details. | 18 | ++= -. .` .: details. |
19 | : = ...= . :.=- | 19 | : = ...= . :.=- |
20 | -. .:....=;==+<; You should have received a copy of the GNU | 20 | -. .:....=;==+<; You should have received a copy of the GNU |
21 | -_. . . )=. = Library General Public License along with | 21 | -_. . . )=. = Library General Public License along with |
22 | -- :-=` this library; see the file COPYING.LIB. | 22 | -- :-=` this library; see the file COPYING.LIB. |
23 | If not, write to the Free Software Foundation, | 23 | If not, write to the Free Software Foundation, |
24 | Inc., 59 Temple Place - Suite 330, | 24 | Inc., 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "Excel.h" | 29 | #include "Excel.h" |
30 | 30 | ||
31 | /* STD */ | 31 | /* STD */ |
32 | #include <stdio.h> | 32 | #include <stdio.h> |
33 | #include <stdlib.h> | 33 | #include <stdlib.h> |
34 | #include <math.h> | 34 | #include <math.h> |
35 | #include <time.h> | 35 | #include <time.h> |
36 | #include <sys/types.h> | 36 | #include <sys/types.h> |
37 | #include <strings.h> | 37 | #include <strings.h> |
38 | 38 | ||
39 | static xfrecord formatter[] = { | 39 | static xfrecord formatter[] = { |
40 | { 0xe , DATEFORMAT, "%m/%d/%y"}, | 40 | { 0xe , DATEFORMAT, "%m/%d/%y"}, |
41 | { 0xf , DATEFORMAT, "%d-%b-%y"}, | 41 | { 0xf , DATEFORMAT, "%d-%b-%y"}, |
42 | { 0x10, DATEFORMAT, "%d-%b"}, | 42 | { 0x10, DATEFORMAT, "%d-%b"}, |
43 | { 0x11, DATEFORMAT, "%b-%y"}, | 43 | { 0x11, DATEFORMAT, "%b-%y"}, |
44 | { 0x12, DATEFORMAT, "%I:%M %p"}, | 44 | { 0x12, DATEFORMAT, "%I:%M %p"}, |
45 | { 0x13, DATEFORMAT, "%I:%M:%S %p"}, | 45 | { 0x13, DATEFORMAT, "%I:%M:%S %p"}, |
46 | { 0x14, DATEFORMAT, "%H:%M"}, | 46 | { 0x14, DATEFORMAT, "%H:%M"}, |
47 | { 0x15, DATEFORMAT, "%H:%M:%S"}, | 47 | { 0x15, DATEFORMAT, "%H:%M:%S"}, |
48 | { 0x16, DATEFORMAT, "%m/%d/%y %H:%M"}, | 48 | { 0x16, DATEFORMAT, "%m/%d/%y %H:%M"}, |
49 | { 0x2d, DATEFORMAT, "%M:%S"}, | 49 | { 0x2d, DATEFORMAT, "%M:%S"}, |
50 | { 0x2e, DATEFORMAT, "%H:%M:%S"}, | 50 | { 0x2e, DATEFORMAT, "%H:%M:%S"}, |
51 | { 0x2f, DATEFORMAT, "%M:%S"}, | 51 | { 0x2f, DATEFORMAT, "%M:%S"}, |
52 | { 0xa5, DATEFORMAT, "%m/%d/%y %I:%M %p"}, | 52 | { 0xa5, DATEFORMAT, "%m/%d/%y %I:%M %p"}, |
53 | { 0x1 , NUMBERFORMAT, "%.0f"}, | 53 | { 0x1 , NUMBERFORMAT, "%.0f"}, |
54 | { 0x2 , NUMBERFORMAT, "%.2f"}, | 54 | { 0x2 , NUMBERFORMAT, "%.2f"}, |
55 | { 0x3 , NUMBERFORMAT, "#,##%.0f"}, | 55 | { 0x3 , NUMBERFORMAT, "#,##%.0f"}, |
56 | { 0x4 , NUMBERFORMAT, "#,##%.2f"}, | 56 | { 0x4 , NUMBERFORMAT, "#,##%.2f"}, |
57 | { 0x5 , NUMBERFORMAT, "$#,##%.0f"}, | 57 | { 0x5 , NUMBERFORMAT, "$#,##%.0f"}, |
58 | { 0x6 , NUMBERFORMAT, "$#,##%.0f"}, | 58 | { 0x6 , NUMBERFORMAT, "$#,##%.0f"}, |
59 | { 0x7 , NUMBERFORMAT, "$#,##%.2f"}, | 59 | { 0x7 , NUMBERFORMAT, "$#,##%.2f"}, |
60 | { 0x8 , NUMBERFORMAT, "$#,##%.2f"}, | 60 | { 0x8 , NUMBERFORMAT, "$#,##%.2f"}, |
61 | { 0x9 , NUMBERFORMAT, "%.0f%%"}, | 61 | { 0x9 , NUMBERFORMAT, "%.0f%%"}, |
62 | { 0xa , NUMBERFORMAT, "%.2f%%"}, | 62 | { 0xa , NUMBERFORMAT, "%.2f%%"}, |
63 | { 0xb , NUMBERFORMAT, "%e"}, | 63 | { 0xb , NUMBERFORMAT, "%e"}, |
64 | { 0x25, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, | 64 | { 0x25, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, |
65 | { 0x26, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, | 65 | { 0x26, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, |
66 | { 0x27, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, | 66 | { 0x27, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, |
67 | { 0x28, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, | 67 | { 0x28, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, |
68 | { 0x29, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, | 68 | { 0x29, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, |
69 | { 0x2a, NUMBERFORMAT, "$#,##%.0f;($#,##0)"}, | 69 | { 0x2a, NUMBERFORMAT, "$#,##%.0f;($#,##0)"}, |
70 | { 0x2b, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, | 70 | { 0x2b, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, |
71 | { 0x2c, NUMBERFORMAT, "$#,##%.2f;($#,##0.00)"}, | 71 | { 0x2c, NUMBERFORMAT, "$#,##%.2f;($#,##0.00)"}, |
72 | { 0x30, NUMBERFORMAT, "##0.0E0"}, | 72 | { 0x30, NUMBERFORMAT, "##0.0E0"}, |
73 | { 0, 0, ""} | 73 | { 0, 0, ""} |
74 | }; | 74 | }; |
75 | 75 | ||
76 | 76 | ||
77 | 77 | ||
78 | int ExcelBook::Integer2Byte(int b1, int b2) | 78 | int ExcelBook::Integer2Byte(int b1, int b2) |
79 | { | 79 | { |
80 | int i1 = b1 & 0xff; | 80 | int i1 = b1 & 0xff; |
81 | int i2 = b2 & 0xff; | 81 | int i2 = b2 & 0xff; |
82 | int val = i2 << 8 | i1; | 82 | int val = i2 << 8 | i1; |
83 | return val; | 83 | return val; |
84 | }; | 84 | }; |
85 | 85 | ||
86 | int ExcelBook::Integer4Byte(int b1,int b2,int b3,int b4) | 86 | int ExcelBook::Integer4Byte(int b1,int b2,int b3,int b4) |
87 | { | 87 | { |
88 | int i1 = Integer2Byte(b1, b2); | 88 | int i1 = Integer2Byte(b1, b2); |
89 | int i2 = Integer2Byte(b3, b4); | 89 | int i2 = Integer2Byte(b3, b4); |
90 | int val = i2 << 16 | i1; | 90 | int val = i2 << 16 | i1; |
91 | return val; | 91 | return val; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | int ExcelBook::Integer2ByteFile(FILE *f) | 94 | int ExcelBook::Integer2ByteFile(FILE *f) |
95 | { | 95 | { |
96 | int i1, i2; | 96 | int i1, i2; |
97 | i1 = fgetc(f); | 97 | i1 = fgetc(f); |
98 | i2 = fgetc(f); | 98 | i2 = fgetc(f); |
99 | return Integer2Byte(i1,i2); | 99 | return Integer2Byte(i1,i2); |
100 | }; | 100 | }; |
101 | 101 | ||
102 | float ExcelBook::Float4Byte(int b1, int b2, int b3, int b4) | 102 | float ExcelBook::Float4Byte(int b1, int b2, int b3, int b4) |
103 | { | 103 | { |
104 | int i; | 104 | int i; |
105 | float f; | 105 | float f; |
106 | unsigned char *ieee; | 106 | unsigned char *ieee; |
107 | ieee = (unsigned char *) &f; | 107 | ieee = (unsigned char *) &f; |
108 | for (i = 0; i < 4; i++) ieee[i] = 0; | 108 | for (i = 0; i < 4; i++) ieee[i] = 0; |
109 | ieee[0] = ((int)b4) & 0xff; | 109 | ieee[0] = ((int)b4) & 0xff; |
110 | ieee[1] = ((int)b3) & 0xff; | 110 | ieee[1] = ((int)b3) & 0xff; |
111 | ieee[2] = ((int)b2) & 0xff; | 111 | ieee[2] = ((int)b2) & 0xff; |
112 | ieee[3] = ((int)b1) & 0xff; | 112 | ieee[3] = ((int)b1) & 0xff; |
113 | return f; | 113 | return f; |
114 | }; | 114 | }; |
115 | 115 | ||
116 | double ExcelBook::Double4Byte(int b1, int b2, int b3, int b4) | 116 | double ExcelBook::Double4Byte(int b1, int b2, int b3, int b4) |
117 | { | 117 | { |
118 | long int rk; | 118 | long int rk; |
119 | double value; | 119 | double value; |
120 | 120 | ||
121 | rk=Integer4Byte(b1,b2,b3,b4); | 121 | rk=Integer4Byte(b1,b2,b3,b4); |
122 | //printf("Double4Bytes:%d,%d,%d,%d\r\n",b1,b2,b3,b4); | 122 | //printf("Double4Bytes:%d,%d,%d,%d\r\n",b1,b2,b3,b4); |
123 | if ( (rk & 0x02) != 0) | 123 | if ( (rk & 0x02) != 0) |
124 | { | 124 | { |
125 | long int intval = rk >> 2; //drops the 2 bits | 125 | long int intval = rk >> 2; //drops the 2 bits |
126 | printf("Double4Byte:intval=%d, rk=%d, rk>>2=%d\r\n",intval,rk,rk>>2); | 126 | printf("Double4Byte:intval=%d, rk=%d, rk>>2=%d\r\n",intval,rk,rk>>2); |
127 | value = (double) intval; | 127 | value = (double) intval; |
128 | printf("Double4Byte: VALUEINT=%f\r\n",value); | 128 | printf("Double4Byte: VALUEINT=%f\r\n",value); |
129 | if ( (rk & 0x01) != 0) | 129 | if ( (rk & 0x01) != 0) |
130 | { | 130 | { |
131 | value /= 100.0; | 131 | value /= 100.0; |
132 | }; | 132 | }; |
133 | return value; | 133 | return value; |
134 | } | 134 | } |
135 | else | 135 | else |
136 | { | 136 | { |
137 | 137 | ||
138 | union { double d; unsigned long int b[2]; } dbl_byte; | 138 | union { double d; unsigned long int b[2]; } dbl_byte; |
139 | unsigned long int valbits = (rk & 0xfffffffc); | 139 | unsigned long int valbits = (rk & 0xfffffffc); |
140 | #if defined(__arm__) && !defined(__vfp__) | 140 | #if defined(__arm__) && !defined(__vfp__) |
141 | dbl_byte.b[0]=valbits; | 141 | dbl_byte.b[0]=valbits; |
142 | dbl_byte.b[1]=0; | 142 | dbl_byte.b[1]=0; |
143 | #else | 143 | #else |
144 | dbl_byte.b[0]=0; | 144 | dbl_byte.b[0]=0; |
145 | dbl_byte.b[1]=valbits; | 145 | dbl_byte.b[1]=valbits; |
146 | #endif | 146 | #endif |
147 | printf("dbl_byte.b[0]=%d,dbl_byte.b[1]=%d\r\n",dbl_byte.b[0],dbl_byte.b[1]); | 147 | printf("dbl_byte.b[0]=%d,dbl_byte.b[1]=%d\r\n",dbl_byte.b[0],dbl_byte.b[1]); |
148 | value=dbl_byte.d; | 148 | value=dbl_byte.d; |
149 | printf("Double4Byte: VALUE=%f\r\n",value); | 149 | printf("Double4Byte: VALUE=%f\r\n",value); |
150 | 150 | ||
151 | if ( (rk & 0x01) != 0) | 151 | if ( (rk & 0x01) != 0) |
152 | { | 152 | { |
153 | value /= 100.0; | 153 | value /= 100.0; |
154 | }; | 154 | }; |
155 | return value; | 155 | return value; |
156 | }; | 156 | }; |
157 | }; | 157 | }; |
158 | 158 | ||
159 | void ExcelBook::DetectEndian(void) | 159 | void ExcelBook::DetectEndian(void) |
160 | { | 160 | { |
161 | int end; | 161 | int end; |
162 | long i = 0x44332211; | 162 | long i = 0x44332211; |
163 | unsigned char* a = (unsigned char*) &i; | 163 | unsigned char* a = (unsigned char*) &i; |
164 | end = (*a != 0x11); | 164 | end = (*a != 0x11); |
165 | if (end == 1) | 165 | if (end == 1) |
166 | { | 166 | { |
167 | endian = BIG_ENDIAN; | 167 | endian = BIG_ENDIAN; |
168 | printf("BIGENDIAN!\r\n"); | 168 | printf("BIGENDIAN!\r\n"); |
169 | } | 169 | } |
170 | else | 170 | else |
171 | { | 171 | { |
172 | endian = LITTLE_ENDIAN; | 172 | endian = LITTLE_ENDIAN; |
173 | printf("LITTLEENDIAN!\r\n"); | 173 | printf("LITTLEENDIAN!\r\n"); |
174 | } | 174 | } |
175 | }; | 175 | }; |
176 | 176 | ||
177 | double ExcelBook::Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8) | 177 | double ExcelBook::Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8) |
178 | { | 178 | { |
179 | int i; | 179 | int i; |
180 | double d; | 180 | double d; |
181 | unsigned char *ieee; | 181 | unsigned char *ieee; |
182 | ieee = (unsigned char *)&d; | 182 | ieee = (unsigned char *)&d; |
183 | for (i = 0; i < 8; i++) ieee[i] = 0; | 183 | for (i = 0; i < 8; i++) ieee[i] = 0; |
184 | if (endian == BIG_ENDIAN) | 184 | if (endian == BIG_ENDIAN) |
185 | { | 185 | { |
186 | ieee[0] = ((int)b8) & 0xff;ieee[1] = ((int)b7) & 0xff; | 186 | ieee[0] = ((int)b8) & 0xff;ieee[1] = ((int)b7) & 0xff; |
187 | ieee[2] = ((int)b6) & 0xff;ieee[3] = ((int)b5) & 0xff; | 187 | ieee[2] = ((int)b6) & 0xff;ieee[3] = ((int)b5) & 0xff; |
188 | ieee[4] = ((int)b4) & 0xff;ieee[5] = ((int)b3) & 0xff; | 188 | ieee[4] = ((int)b4) & 0xff;ieee[5] = ((int)b3) & 0xff; |
189 | ieee[6] = ((int)b2) & 0xff;ieee[7] = ((int)b1) & 0xff; | 189 | ieee[6] = ((int)b2) & 0xff;ieee[7] = ((int)b1) & 0xff; |
190 | } | 190 | } |
191 | else | 191 | else |
192 | { | 192 | { |
193 | ieee[0] = ((int)b1) & 0xff;ieee[1] = ((int)b2) & 0xff; | 193 | ieee[0] = ((int)b1) & 0xff;ieee[1] = ((int)b2) & 0xff; |
194 | ieee[2] = ((int)b3) & 0xff;ieee[3] = ((int)b4) & 0xff; | 194 | ieee[2] = ((int)b3) & 0xff;ieee[3] = ((int)b4) & 0xff; |
195 | ieee[4] = ((int)b5) & 0xff;ieee[5] = ((int)b6) & 0xff; | 195 | ieee[4] = ((int)b5) & 0xff;ieee[5] = ((int)b6) & 0xff; |
196 | ieee[6] = ((int)b7) & 0xff;ieee[7] = ((int)b8) & 0xff; | 196 | ieee[6] = ((int)b7) & 0xff;ieee[7] = ((int)b8) & 0xff; |
197 | } | 197 | } |
198 | return d; | 198 | return d; |
199 | }; | 199 | }; |
200 | 200 | ||
201 | bool ExcelBook::OpenFile(char *Filename) | 201 | bool ExcelBook::OpenFile(char *Filename) |
202 | { | 202 | { |
203 | printf("Opening excel file!\r\n"); | 203 | printf("Opening excel file!\r\n"); |
204 | File= fopen(Filename, "r"); | 204 | File= fopen(Filename, "r"); |
205 | Position=0; // first byte index in file | 205 | Position=0; // first byte index in file |
206 | XFRecords.resize(0); | 206 | XFRecords.resize(0); |
207 | SharedStrings.resize(0); | 207 | SharedStrings.resize(0); |
208 | Names.resize(0); | 208 | Names.resize(0); |
209 | Sheets.resize(0); | 209 | Sheets.resize(0); |
210 | if(File==NULL) return false; | 210 | if(File==NULL) return false; |
211 | printf("Opened excel file!\r\n"); | 211 | printf("Opened excel file!\r\n"); |
212 | return true; | 212 | return true; |
213 | }; | 213 | }; |
214 | 214 | ||
215 | bool ExcelBook::CloseFile(void) | 215 | bool ExcelBook::CloseFile(void) |
216 | { | 216 | { |
217 | int w1; | 217 | int w1; |
218 | for(w1=0;w1<(int)XFRecords.count();w1++) | 218 | for(w1=0;w1<(int)XFRecords.count();w1++) |
219 | { | 219 | { |
220 | if(XFRecords[w1]!=NULL) {delete XFRecords[w1];XFRecords[w1]=NULL;}; | 220 | if(XFRecords[w1]!=NULL) {delete XFRecords[w1];XFRecords[w1]=NULL;}; |
221 | }; | 221 | }; |
222 | for(w1=0;w1<(int)SharedStrings.count();w1++) | 222 | for(w1=0;w1<(int)SharedStrings.count();w1++) |
223 | { | 223 | { |
224 | if(SharedStrings[w1]!=NULL) {delete SharedStrings[w1];SharedStrings[w1]=NULL;}; | 224 | if(SharedStrings[w1]!=NULL) {delete SharedStrings[w1];SharedStrings[w1]=NULL;}; |
225 | }; | 225 | }; |
226 | for(w1=0;w1<(int)Names.count();w1++) | 226 | for(w1=0;w1<(int)Names.count();w1++) |
227 | { | 227 | { |
228 | if(Names[w1]!=NULL) {delete Names[w1];Names[w1]=NULL;}; | 228 | if(Names[w1]!=NULL) {delete Names[w1];Names[w1]=NULL;}; |
229 | }; | 229 | }; |
230 | for(w1=0;w1<(int)Sheets.count();w1++) | 230 | for(w1=0;w1<(int)Sheets.count();w1++) |
231 | { | 231 | { |
232 | if(Sheets[w1]!=NULL) {delete Sheets[w1];Sheets[w1]=NULL;}; | 232 | if(Sheets[w1]!=NULL) {delete Sheets[w1];Sheets[w1]=NULL;}; |
233 | }; | 233 | }; |
234 | XFRecords.resize(0); | 234 | XFRecords.resize(0); |
235 | SharedStrings.resize(0); | 235 | SharedStrings.resize(0); |
236 | Names.resize(0); | 236 | Names.resize(0); |
237 | Sheets.resize(0); | 237 | Sheets.resize(0); |
238 | fclose(File); | 238 | fclose(File); |
239 | printf("closed excel file!\r\n"); | 239 | printf("closed excel file!\r\n"); |
240 | if(File==NULL) return true; | 240 | if(File==NULL) return true; |
241 | return false; | 241 | return false; |
242 | }; | 242 | }; |
243 | 243 | ||
244 | void ExcelBook::SeekPosition(int pos) | 244 | void ExcelBook::SeekPosition(int pos) |
245 | { | 245 | { |
246 | if(!feof(File)) | 246 | if(!feof(File)) |
247 | { | 247 | { |
248 | Position=pos; | 248 | Position=pos; |
249 | //printf("SeekPosition:Pos:%d\r\n",Position); | 249 | //printf("SeekPosition:Pos:%d\r\n",Position); |
250 | fseek(File,pos,SEEK_SET); | 250 | fseek(File,pos,SEEK_SET); |
251 | }; | 251 | }; |
252 | }; | 252 | }; |
253 | 253 | ||
254 | void ExcelBook::SeekSkip(int pos) | 254 | void ExcelBook::SeekSkip(int pos) |
255 | { | 255 | { |
256 | if(!feof(File)) | 256 | if(!feof(File)) |
257 | { | 257 | { |
258 | Position=Position+pos; | 258 | Position=Position+pos; |
259 | //printf("SeekSkip:Pos:%d\r\n",Position); | 259 | //printf("SeekSkip:Pos:%d\r\n",Position); |
260 | fseek(File, Position, SEEK_SET); | 260 | fseek(File, Position, SEEK_SET); |
261 | }; | 261 | }; |
262 | }; | 262 | }; |
263 | 263 | ||
264 | int ExcelBook::FileEOF(void) | 264 | int ExcelBook::FileEOF(void) |
265 | { | 265 | { |
266 | if(File!=NULL) return(feof(File)); else return 0; | 266 | if(File!=NULL) return(feof(File)); else return 0; |
267 | //EOF is defined in stdlib as -1 | 267 | //EOF is defined in stdlib as -1 |
268 | }; | 268 | }; |
269 | 269 | ||
270 | int ExcelBook::Get2Bytes(void) | 270 | int ExcelBook::Get2Bytes(void) |
271 | { | 271 | { |
272 | int i1,i2; | 272 | int i1,i2; |
273 | i1=0; i2=0; | 273 | i1=0; i2=0; |
274 | if (!feof(File)) | 274 | if (!feof(File)) |
275 | { | 275 | { |
276 | i1=fgetc(File); | 276 | i1=fgetc(File); |
277 | Position++; | 277 | Position++; |
278 | }; | 278 | }; |
279 | if (!feof(File)) | 279 | if (!feof(File)) |
280 | { | 280 | { |
281 | i2=fgetc(File); | 281 | i2=fgetc(File); |
282 | Position++; | 282 | Position++; |
283 | }; | 283 | }; |
284 | return Integer2Byte(i1,i2); | 284 | return Integer2Byte(i1,i2); |
285 | }; | 285 | }; |
286 | 286 | ||
287 | char* ExcelBook::Read(int pos, int length) | 287 | char* ExcelBook::Read(int pos, int length) |
288 | { | 288 | { |
289 | int i; | 289 | int i; |
290 | char *data; | 290 | char *data; |
291 | data= new char[length]; | 291 | data= new char[length]; |
292 | SeekPosition(pos); | 292 | SeekPosition(pos); |
293 | for(i=0; i<length; i++) | 293 | for(i=0; i<length; i++) |
294 | { | 294 | { |
295 | if(!feof(File)) data[i]=fgetc(File); | 295 | if(!feof(File)) data[i]=fgetc(File); |
296 | }; | 296 | }; |
297 | Position= Position+length; | 297 | Position= Position+length; |
298 | return data; | 298 | return data; |
299 | }; | 299 | }; |
300 | 300 | ||
301 | QString ExcelBook::ReadUnicodeChar(int pos, int length) | 301 | QString ExcelBook::ReadUnicodeChar(int pos, int length) |
302 | { | 302 | { |
303 | int i; | 303 | int i; |
304 | QString data; | 304 | QString data; |
305 | int i1=' ',i2=' ',ii; | 305 | int i1=' ',i2=' ',ii; |
306 | SeekPosition(pos); | 306 | SeekPosition(pos); |
307 | for(i=0; i<length; i++) | 307 | for(i=0; i<length; i++) |
308 | { | 308 | { |
309 | if(!feof(File)) i1=fgetc(File); | 309 | if(!feof(File)) i1=fgetc(File); |
310 | if(!feof(File)) i2=fgetc(File); | 310 | if(!feof(File)) i2=fgetc(File); |
311 | ii=Integer2Byte(i1,i2); | 311 | ii=Integer2Byte(i1,i2); |
312 | data.append(ii); | 312 | data.append(ii); |
313 | Position+=2; | 313 | Position+=2; |
314 | }; | 314 | }; |
315 | return data; | 315 | return data; |
316 | }; | 316 | }; |
317 | 317 | ||
318 | QString* ExcelBook::GetString(int num) | 318 | QString* ExcelBook::GetString(int num) |
319 | { | 319 | { |
320 | if(num>=0 && num<(int)SharedStrings.count()) | 320 | if(num>=0 && num<(int)SharedStrings.count()) |
321 | { | 321 | { |
322 | return SharedStrings[num]; | 322 | return SharedStrings[num]; |
323 | }; | 323 | }; |
324 | return new QString(""); | 324 | return new QString(""); |
325 | }; | 325 | }; |
326 | 326 | ||
327 | int ExcelBook::SeekBOF(void) | 327 | int ExcelBook::SeekBOF(void) |
328 | { | 328 | { |
329 | int opcode,version,streamtype,length,ret=0; | 329 | int opcode,version,streamtype,length,ret=0; |
330 | char *data; | 330 | char *data; |
331 | while(!feof(File)) | 331 | while(!feof(File)) |
332 | { | 332 | { |
333 | opcode=Get2Bytes(); | 333 | opcode=Get2Bytes(); |
334 | if(opcode==XL_BOF) | 334 | if(opcode==XL_BOF) |
335 | { | 335 | { |
336 | length=Get2Bytes(); | 336 | length=Get2Bytes(); |
337 | data=Read(Position,length); | 337 | data=Read(Position,length); |
338 | version=Integer2Byte(data[0], data[1]); | 338 | version=Integer2Byte(data[0], data[1]); |
339 | streamtype=Integer2Byte(data[2], data[3]); | 339 | streamtype=Integer2Byte(data[2], data[3]); |
340 | printf("SEEKBOF:opcode=XLBOF, %d ,version %d\r\n",Position,version); | 340 | printf("SEEKBOF:opcode=XLBOF, %d ,version %d\r\n",Position,version); |
341 | delete data; data=NULL; | 341 | delete [] data; data=NULL; |
342 | if (version==BIFF8) ret=8; | 342 | if (version==BIFF8) ret=8; |
343 | else if(version==BIFF7) ret=7; | 343 | else if(version==BIFF7) ret=7; |
344 | printf("SEEKBOF:versionBIFF%d\r\n",ret); | 344 | printf("SEEKBOF:versionBIFF%d\r\n",ret); |
345 | if(streamtype==WBKGLOBAL) return ret *2; | 345 | if(streamtype==WBKGLOBAL) return ret *2; |
346 | else if(streamtype==WRKSHEET) return ret *1; | 346 | else if(streamtype==WRKSHEET) return ret *1; |
347 | return 1; | 347 | return 1; |
348 | }; | 348 | }; |
349 | }; | 349 | }; |
350 | return 0; | 350 | return 0; |
351 | }; | 351 | }; |
352 | 352 | ||
353 | ExcelBREC* ExcelBook::GetBREC(void) | 353 | ExcelBREC* ExcelBook::GetBREC(void) |
354 | { | 354 | { |
355 | ExcelBREC* rec; | 355 | ExcelBREC* rec; |
356 | rec= new ExcelBREC; | 356 | rec= new ExcelBREC; |
357 | if(FileEOF()) return NULL; | 357 | if(FileEOF()) return NULL; |
358 | rec->data=NULL; | 358 | rec->data=NULL; |
359 | rec->code=Get2Bytes(); | 359 | rec->code=Get2Bytes(); |
360 | rec->length=Get2Bytes(); | 360 | rec->length=Get2Bytes(); |
361 | rec->position=Position; | 361 | rec->position=Position; |
362 | SeekSkip(rec->length); | 362 | SeekSkip(rec->length); |
363 | return rec; | 363 | return rec; |
364 | }; | 364 | }; |
365 | 365 | ||
366 | ExcelBREC* ExcelBook::PeekBREC(void) | 366 | ExcelBREC* ExcelBook::PeekBREC(void) |
367 | { | 367 | { |
368 | int oldpos; | 368 | int oldpos; |
369 | ExcelBREC* NextRec; | 369 | ExcelBREC* NextRec; |
370 | oldpos=Position; | 370 | oldpos=Position; |
371 | NextRec=GetBREC(); | 371 | NextRec=GetBREC(); |
372 | SeekPosition(oldpos); | 372 | SeekPosition(oldpos); |
373 | return NextRec; | 373 | return NextRec; |
374 | }; | 374 | }; |
375 | 375 | ||
376 | char* ExcelBook::GetDataOfBREC(ExcelBREC* record) | 376 | char* ExcelBook::GetDataOfBREC(ExcelBREC* record) |
377 | { | 377 | { |
378 | if(record->data==NULL) | 378 | if(record->data==NULL) |
379 | { | 379 | { |
380 | ConvertCharToArray(record,Read(record->position,record->length),record->length); | 380 | ConvertCharToArray(record,Read(record->position,record->length),record->length); |
381 | }; | 381 | }; |
382 | return record->data;//new? | 382 | return record->data;//new? |
383 | }; | 383 | }; |
384 | 384 | ||
385 | void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length) | 385 | void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length) |
386 | { | 386 | { |
387 | record->data=new char[length]; | 387 | record->data=new char[length]; |
388 | for(int w1=0;w1<=length-1;w1++) | 388 | for(int w1=0;w1<=length-1;w1++) |
389 | record->data[w1]=chars[w1]; | 389 | record->data[w1]=chars[w1]; |
390 | }; | 390 | }; |
391 | 391 | ||
392 | 392 | ||
393 | bool ExcelSheet::InitCells() | 393 | bool ExcelSheet::InitCells() |
394 | { | 394 | { |
395 | int r; | 395 | int r; |
396 | Cells.resize(rows * cols + cols+1); | 396 | Cells.resize(rows * cols + cols+1); |
397 | if(Cells.count()==0) return false; | 397 | if(Cells.count()==0) return false; |
398 | for(r=0;r < Cells.count();r++) | 398 | for(r=0;r < Cells.count();r++) |
399 | { | 399 | { |
400 | Cells[r]=NULL; | 400 | Cells[r]=NULL; |
401 | }; | 401 | }; |
402 | return true; | 402 | return true; |
403 | }; | 403 | }; |
404 | 404 | ||
405 | void ExcelSheet::Set(int row, int col, ExcelCell* cell) | 405 | void ExcelSheet::Set(int row, int col, ExcelCell* cell) |
406 | { | 406 | { |
407 | if(cell!=NULL&&(row*cols+col)<Cells.count()) | 407 | if(cell!=NULL&&(row*cols+col)<Cells.count()) |
408 | { | 408 | { |
409 | Cells[row*cols+col]=cell; | 409 | Cells[row*cols+col]=cell; |
410 | }; | 410 | }; |
411 | }; | 411 | }; |
412 | 412 | ||
413 | ExcelCell* ExcelSheet::Get(int row, int col) | 413 | ExcelCell* ExcelSheet::Get(int row, int col) |
414 | { | 414 | { |
415 | ExcelCell* cell; | 415 | ExcelCell* cell; |
416 | cell=Cells[row*cols+col]; | 416 | cell=Cells[row*cols+col]; |
417 | if(cell==NULL) return NULL; | 417 | if(cell==NULL) return NULL; |
418 | return cell; | 418 | return cell; |
419 | }; | 419 | }; |
420 | 420 | ||
421 | int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record) | 421 | int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record) |
422 | { | 422 | { |
423 | char* data=NULL; | 423 | char* data=NULL; |
424 | switch (record->code) | 424 | switch (record->code) |
425 | { | 425 | { |
426 | case XL_DIMENSION: | 426 | case XL_DIMENSION: |
427 | data = GetDataOfBREC(record); | 427 | data = GetDataOfBREC(record); |
428 | if (record->length == 10) | 428 | if (record->length == 10) |
429 | { | 429 | { |
430 | sheet->rows = Integer2Byte(data[2], data[3]); | 430 | sheet->rows = Integer2Byte(data[2], data[3]); |
431 | sheet->cols = Integer2Byte(data[6], data[7]); | 431 | sheet->cols = Integer2Byte(data[6], data[7]); |
432 | } | 432 | } |
433 | else | 433 | else |
434 | { | 434 | { |
435 | sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]); | 435 | sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]); |
436 | sheet->cols = Integer2Byte(data[10], data[11]); | 436 | sheet->cols = Integer2Byte(data[10], data[11]); |
437 | } | 437 | } |
438 | sheet->InitCells(); | 438 | sheet->InitCells(); |
439 | break; | 439 | break; |
440 | 440 | ||
441 | case XL_LABELSST: | 441 | case XL_LABELSST: |
442 | HandleLabelSST(sheet, record); | 442 | HandleLabelSST(sheet, record); |
443 | break; | 443 | break; |
444 | 444 | ||
445 | case XL_RK: | 445 | case XL_RK: |
446 | case XL_RK2: | 446 | case XL_RK2: |
447 | HandleRK(sheet, record); | 447 | HandleRK(sheet, record); |
448 | break; | 448 | break; |
449 | 449 | ||
450 | case XL_MULRK: | 450 | case XL_MULRK: |
451 | HandleMulrk(sheet, record); | 451 | HandleMulrk(sheet, record); |
452 | break; | 452 | break; |
453 | 453 | ||
454 | case XL_ROW: | 454 | case XL_ROW: |
455 | break; | 455 | break; |
456 | 456 | ||
457 | case XL_NUMBER: | 457 | case XL_NUMBER: |
458 | HandleNumber(sheet, record); | 458 | HandleNumber(sheet, record); |
459 | break; | 459 | break; |
460 | 460 | ||
461 | case XL_BOOLERR: | 461 | case XL_BOOLERR: |
462 | break; | 462 | break; |
463 | 463 | ||
464 | case XL_CONTINUE: | 464 | case XL_CONTINUE: |
465 | break; | 465 | break; |
466 | 466 | ||
467 | case XL_FORMULA: | 467 | case XL_FORMULA: |
468 | case XL_FORMULA2: | 468 | case XL_FORMULA2: |
469 | HandleFormula(sheet, record); | 469 | HandleFormula(sheet, record); |
470 | break; | 470 | break; |
471 | 471 | ||
472 | case XL_LABEL: | 472 | case XL_LABEL: |
473 | break; | 473 | break; |
474 | 474 | ||
475 | case XL_NAME: | 475 | case XL_NAME: |
476 | HandleName(sheet, record); | 476 | HandleName(sheet, record); |
477 | break; | 477 | break; |
478 | 478 | ||
479 | case XL_BOF: | 479 | case XL_BOF: |
480 | break; | 480 | break; |
481 | case XL_EOF: | 481 | case XL_EOF: |
482 | return 0; | 482 | return 0; |
483 | default: | 483 | default: |
484 | break; | 484 | break; |
485 | }; | 485 | }; |
486 | return 1; | 486 | return 1; |
487 | }; | 487 | }; |
488 | 488 | ||
489 | int ExcelBook::ReadSheet(ExcelSheet* sheet) | 489 | int ExcelBook::ReadSheet(ExcelSheet* sheet) |
490 | { | 490 | { |
491 | ExcelBREC* record; | 491 | ExcelBREC* record; |
492 | int oldpos; | 492 | int oldpos; |
493 | oldpos = Position; | 493 | oldpos = Position; |
494 | SeekPosition(sheet->position); | 494 | SeekPosition(sheet->position); |
495 | record = GetBREC(); | 495 | record = GetBREC(); |
496 | while (record!=NULL) | 496 | while (record!=NULL) |
497 | { | 497 | { |
498 | if (!SheetHandleRecord(sheet, record)) break; | 498 | if (!SheetHandleRecord(sheet, record)) break; |
499 | record=GetBREC(); | 499 | record=GetBREC(); |
500 | }; | 500 | }; |
501 | SeekPosition(oldpos); | 501 | SeekPosition(oldpos); |
502 | return 1; | 502 | return 1; |
503 | }; | 503 | }; |
504 | 504 | ||
505 | ExcelSheet* ExcelBook::GetSheet(void) | 505 | ExcelSheet* ExcelBook::GetSheet(void) |
506 | { | 506 | { |
507 | ExcelSheet* sh=NULL; | 507 | ExcelSheet* sh=NULL; |
508 | int type; | 508 | int type; |
509 | type=SeekBOF(); | 509 | type=SeekBOF(); |
510 | Version=type; | 510 | Version=type; |
511 | sh=new ExcelSheet; | 511 | sh=new ExcelSheet; |
512 | if(type) | 512 | if(type) |
513 | { | 513 | { |
514 | sh->type=type; | 514 | sh->type=type; |
515 | sh->position=Position; | 515 | sh->position=Position; |
516 | sh->name=QString(""); | 516 | sh->name=QString(""); |
517 | }; | 517 | }; |
518 | if(type==8||type==7) | 518 | if(type==8||type==7) |
519 | { | 519 | { |
520 | ReadSheet(sh); | 520 | ReadSheet(sh); |
521 | }; | 521 | }; |
522 | return sh; | 522 | return sh; |
523 | }; | 523 | }; |
524 | 524 | ||
525 | void ExcelBook::ParseSheets(void) | 525 | void ExcelBook::ParseSheets(void) |
526 | { | 526 | { |
527 | int BOFs; | 527 | int BOFs; |
528 | ExcelBREC* r; | 528 | ExcelBREC* r; |
529 | BOFs=1; | 529 | BOFs=1; |
530 | r=GetBREC(); | 530 | r=GetBREC(); |
531 | while(BOFs) | 531 | while(BOFs) |
532 | { | 532 | { |
533 | r=GetBREC(); | 533 | r=GetBREC(); |
534 | switch(r->code) | 534 | switch(r->code) |
535 | { | 535 | { |
536 | case XL_SST: | 536 | case XL_SST: |
537 | HandleSST(r); | 537 | HandleSST(r); |
538 | break; | 538 | break; |
539 | 539 | ||
540 | case XL_TXO: | 540 | case XL_TXO: |
541 | break; | 541 | break; |
542 | case XL_NAME: | 542 | case XL_NAME: |
543 | break; | 543 | break; |
544 | case XL_ROW: | 544 | case XL_ROW: |
545 | break; | 545 | break; |
546 | 546 | ||
547 | case XL_FORMAT: | 547 | case XL_FORMAT: |
548 | HandleFormat(r); | 548 | HandleFormat(r); |
549 | break; | 549 | break; |
550 | 550 | ||
551 | case XL_XF: | 551 | case XL_XF: |
552 | HandleXF(r); | 552 | HandleXF(r); |
553 | break; | 553 | break; |
554 | 554 | ||
555 | case XL_BOUNDSHEET: | 555 | case XL_BOUNDSHEET: |
556 | HandleBoundSheet(r); | 556 | HandleBoundSheet(r); |
557 | break; | 557 | break; |
558 | 558 | ||
559 | case XL_EXTSST: | 559 | case XL_EXTSST: |
560 | break; | 560 | break; |
561 | case XL_CONTINUE: | 561 | case XL_CONTINUE: |
562 | break; | 562 | break; |
563 | 563 | ||
564 | case XL_EOF: | 564 | case XL_EOF: |
565 | BOFs--; | 565 | BOFs--; |
566 | break; | 566 | break; |
567 | 567 | ||
568 | default: | 568 | default: |
569 | break; | 569 | break; |
570 | }; | 570 | }; |
571 | }; | 571 | }; |
572 | }; | 572 | }; |
573 | 573 | ||
574 | void ExcelBook::GetSheets(void) | 574 | void ExcelBook::GetSheets(void) |
575 | { | 575 | { |
576 | ExcelSheet* sheet; | 576 | ExcelSheet* sheet; |
577 | Sheets.resize(0); | 577 | Sheets.resize(0); |
578 | sheet=GetSheet(); | 578 | sheet=GetSheet(); |
579 | while (sheet->Cells.count()!= 0 ) | 579 | while (sheet->Cells.count()!= 0 ) |
580 | { | 580 | { |
581 | Sheets.resize(Sheets.count()+1); | 581 | Sheets.resize(Sheets.count()+1); |
582 | Sheets[Sheets.count()-1]=sheet; | 582 | Sheets[Sheets.count()-1]=sheet; |
583 | sheet->name=*Names[Sheets.count()-1]; | 583 | sheet->name=*Names[Sheets.count()-1]; |
584 | sheet=GetSheet(); | 584 | sheet=GetSheet(); |
585 | }; | 585 | }; |
586 | }; | 586 | }; |
587 | 587 | ||
588 | bool ExcelBook::ParseBook(char *file) | 588 | bool ExcelBook::ParseBook(char *file) |
589 | { | 589 | { |
590 | dateformat=QString(""); | 590 | dateformat=QString(""); |
591 | DetectEndian(); | 591 | DetectEndian(); |
592 | if ( !OpenFile( file ) ) | 592 | if ( !OpenFile( file ) ) |
593 | return false; | 593 | return false; |
594 | SeekBOF(); | 594 | SeekBOF(); |
595 | ParseSheets(); | 595 | ParseSheets(); |
596 | GetSheets(); | 596 | GetSheets(); |
597 | return true; | 597 | return true; |
598 | }; | 598 | }; |
599 | 599 | ||
600 | QString ExcelBook::GetASCII(char* inbytes, int pos, int chars) | 600 | QString ExcelBook::GetASCII(char* inbytes, int pos, int chars) |
601 | { | 601 | { |
602 | int i; | 602 | int i; |
603 | QString outstr=""; | 603 | QString outstr=""; |
604 | for (i = 0; i < chars; i++) | 604 | for (i = 0; i < chars; i++) |
605 | { | 605 | { |
606 | outstr.append(inbytes[i+pos]); | 606 | outstr.append(inbytes[i+pos]); |
607 | }; | 607 | }; |
608 | return outstr; | 608 | return outstr; |
609 | }; | 609 | }; |
610 | 610 | ||
611 | QString ExcelBook::GetUnicode(char * inbytes, int pos, int chars) | 611 | QString ExcelBook::GetUnicode(char * inbytes, int pos, int chars) |
612 | { | 612 | { |
613 | QString outstr=""; | 613 | QString outstr=""; |
614 | int i; | 614 | int i; |
615 | int rc; | 615 | int rc; |
616 | for (i=0; i<chars*2; i++) | 616 | for (i=0; i<chars*2; i++) |
617 | { | 617 | { |
618 | rc=Integer2Byte(inbytes[i+pos],inbytes[i+pos+1]); | 618 | rc=Integer2Byte(inbytes[i+pos],inbytes[i+pos+1]); |
619 | outstr.append(QChar(rc)); | 619 | outstr.append(QChar(rc)); |
620 | i++; | 620 | i++; |
621 | }; | 621 | }; |
622 | return outstr; | 622 | return outstr; |
623 | }; | 623 | }; |
624 | 624 | ||
625 | 625 | ||
626 | void ExcelBook::HandleBoundSheet(ExcelBREC* rec) | 626 | void ExcelBook::HandleBoundSheet(ExcelBREC* rec) |
627 | { | 627 | { |
628 | char* data; | 628 | char* data; |
629 | int type; | 629 | int type; |
630 | int visibility; | 630 | int visibility; |
631 | int length; | 631 | int length; |
632 | int pos; | 632 | int pos; |
633 | QString name; | 633 | QString name; |
634 | pos = 8; | 634 | pos = 8; |
635 | data = GetDataOfBREC(rec); | 635 | data = GetDataOfBREC(rec); |
636 | type = data[4]; | 636 | type = data[4]; |
637 | visibility = data[5]; | 637 | visibility = data[5]; |
638 | length = data[6]; | 638 | length = data[6]; |
639 | if(data[7]==0) | 639 | if(data[7]==0) |
640 | { | 640 | { |
641 | //ascii | 641 | //ascii |
642 | name=GetASCII(data,pos,length); | 642 | name=GetASCII(data,pos,length); |
643 | } | 643 | } |
644 | else | 644 | else |
645 | { | 645 | { |
646 | name=GetUnicode(data,pos,length); | 646 | name=GetUnicode(data,pos,length); |
647 | }; | 647 | }; |
648 | Names.resize(Names.count()+1); | 648 | Names.resize(Names.count()+1); |
649 | Names[Names.count()-1]=new QString(name); | 649 | Names[Names.count()-1]=new QString(name); |
650 | }; | 650 | }; |
651 | 651 | ||
652 | void ExcelBook::HandleName(ExcelSheet* sheet, ExcelBREC* rec) | 652 | void ExcelBook::HandleName(ExcelSheet* sheet, ExcelBREC* rec) |
653 | { | 653 | { |
654 | char* data; | 654 | char* data; |
655 | QString name; | 655 | QString name; |
656 | int length; | 656 | int length; |
657 | int pos; | 657 | int pos; |
658 | pos = 15; | 658 | pos = 15; |
659 | data = GetDataOfBREC(rec); | 659 | data = GetDataOfBREC(rec); |
660 | length = data[3]; | 660 | length = data[3]; |
661 | name = GetASCII(data,pos,length); | 661 | name = GetASCII(data,pos,length); |
662 | 662 | ||
663 | 663 | ||
664 | }; | 664 | }; |
665 | 665 | ||
666 | ExcelFormat* ExcelBook::GetFormatting(int xf) | 666 | ExcelFormat* ExcelBook::GetFormatting(int xf) |
667 | { | 667 | { |
668 | int i; | 668 | int i; |
669 | ExcelFormat* rec; | 669 | ExcelFormat* rec; |
670 | rec=new ExcelFormat(); | 670 | rec=new ExcelFormat(); |
671 | for (i = 0; formatter[i].code != 0; i++) | 671 | for (i = 0; formatter[i].code != 0; i++) |
672 | { | 672 | { |
673 | if (xf == formatter[i].code) break; | 673 | if (xf == formatter[i].code) break; |
674 | }; | 674 | }; |
675 | if (formatter[i].format ==NULL) return NULL; | 675 | if (formatter[i].format ==NULL) return NULL; |
676 | rec->code = xf; | 676 | rec->code = xf; |
677 | rec->type = formatter[i].type; | 677 | rec->type = formatter[i].type; |
678 | rec->format = formatter[i].format; | 678 | rec->format = formatter[i].format; |
679 | return rec; | 679 | return rec; |
680 | }; | 680 | }; |
681 | 681 | ||
682 | void ExcelBook::HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes) | 682 | void ExcelBook::HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes) |
683 | { | 683 | { |
684 | QString str=QString(""); | 684 | QString str=QString(""); |
685 | char* data; | 685 | char* data; |
686 | int chars, pos, options, i; | 686 | int chars, pos, options, i; |
687 | int richstring, fareaststring, runlength=0; | 687 | int richstring, fareaststring, runlength=0; |
688 | int richruns=0,fareastsize=0; | 688 | int richruns=0,fareastsize=0; |
689 | int totalstrings; | 689 | int totalstrings; |
690 | int uniquestrings; | 690 | int uniquestrings; |
691 | data = GetDataOfBREC(rec); | 691 | data = GetDataOfBREC(rec); |
692 | totalstrings = Integer4Byte(data[0], data[1], data[2], data[3]); | 692 | totalstrings = Integer4Byte(data[0], data[1], data[2], data[3]); |
693 | uniquestrings = Integer4Byte(data[4], data[5], data[6], data[7]); | 693 | uniquestrings = Integer4Byte(data[4], data[5], data[6], data[7]); |
694 | pos = 8; | 694 | pos = 8; |
695 | for (i = 0; i < uniquestrings; i++) | 695 | for (i = 0; i < uniquestrings; i++) |
696 | { | 696 | { |
697 | richruns=0; fareastsize=0; | 697 | richruns=0; fareastsize=0; |
698 | chars = Integer2Byte(data[pos], data[pos+1]); | 698 | chars = Integer2Byte(data[pos], data[pos+1]); |
699 | pos += 2; | 699 | pos += 2; |
700 | options = data[pos]; | 700 | options = data[pos]; |
701 | pos++; | 701 | pos++; |
702 | fareaststring = ((options & 0x04) != 0); | 702 | fareaststring = ((options & 0x04) != 0); |
703 | richstring = ((options & 0x08) != 0); | 703 | richstring = ((options & 0x08) != 0); |
704 | if(richstring) | 704 | if(richstring) |
705 | { | 705 | { |
706 | richruns= Integer2Byte(data[pos],data[pos+1]); | 706 | richruns= Integer2Byte(data[pos],data[pos+1]); |
707 | pos+=2; | 707 | pos+=2; |
708 | }; | 708 | }; |
709 | if(fareaststring) | 709 | if(fareaststring) |
710 | { | 710 | { |
711 | fareastsize=Integer4Byte(data[pos], data[pos+1], data[pos+2], data[pos+3]); | 711 | fareastsize=Integer4Byte(data[pos], data[pos+1], data[pos+2], data[pos+3]); |
712 | pos+=4; | 712 | pos+=4; |
713 | }; | 713 | }; |
714 | 714 | ||
715 | if ((options & 0x01) == 0) //8 bit chars | 715 | if ((options & 0x01) == 0) //8 bit chars |
716 | { | 716 | { |
717 | /* ascii */ | 717 | /* ascii */ |
718 | str = GetASCII(bytes,pos,chars); | 718 | str = GetASCII(bytes,pos,chars); |
719 | pos=pos+chars; | 719 | pos=pos+chars; |
720 | if(str[0]=='=') str[0]=' '; | 720 | if(str[0]=='=') str[0]=' '; |
721 | }else //16 bit chars | 721 | }else //16 bit chars |
722 | { | 722 | { |
723 | /* unicode */ | 723 | /* unicode */ |
724 | str = GetUnicode(bytes,pos,chars); | 724 | str = GetUnicode(bytes,pos,chars); |
725 | pos=pos+chars*2; | 725 | pos=pos+chars*2; |
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.cpp b/noncore/apps/tinykate/libkate/document/katedocument.cpp index 6dc4fd2..a70f3aa 100644 --- a/noncore/apps/tinykate/libkate/document/katedocument.cpp +++ b/noncore/apps/tinykate/libkate/document/katedocument.cpp | |||
@@ -1838,830 +1838,830 @@ QString KateDocument::markedText(int flags) { | |||
1838 | s[len] = '\n'; | 1838 | s[len] = '\n'; |
1839 | len++; | 1839 | len++; |
1840 | } | 1840 | } |
1841 | // s[len] = '\0'; // the final \0 is not counted in length() | 1841 | // s[len] = '\0'; // the final \0 is not counted in length() |
1842 | return s; | 1842 | return s; |
1843 | } | 1843 | } |
1844 | } | 1844 | } |
1845 | 1845 | ||
1846 | void KateDocument::delMarkedText(VConfig &c/*, bool undo*/) { | 1846 | void KateDocument::delMarkedText(VConfig &c/*, bool undo*/) { |
1847 | int end = 0; | 1847 | int end = 0; |
1848 | 1848 | ||
1849 | if (selectEnd < selectStart) return; | 1849 | if (selectEnd < selectStart) return; |
1850 | 1850 | ||
1851 | // the caller may have already started an undo record for the current action | 1851 | // the caller may have already started an undo record for the current action |
1852 | // if (undo) | 1852 | // if (undo) |
1853 | 1853 | ||
1854 | //auto deletion of the marked text occurs not very often and can therefore | 1854 | //auto deletion of the marked text occurs not very often and can therefore |
1855 | // be recorded separately | 1855 | // be recorded separately |
1856 | recordStart(c, KateActionGroup::ugDelBlock); | 1856 | recordStart(c, KateActionGroup::ugDelBlock); |
1857 | 1857 | ||
1858 | for (c.cursor.y = selectEnd; c.cursor.y >= selectStart; c.cursor.y--) { | 1858 | for (c.cursor.y = selectEnd; c.cursor.y >= selectStart; c.cursor.y--) { |
1859 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 1859 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
1860 | 1860 | ||
1861 | c.cursor.x = textLine->length(); | 1861 | c.cursor.x = textLine->length(); |
1862 | do { | 1862 | do { |
1863 | end = textLine->findRevUnselected(c.cursor.x); | 1863 | end = textLine->findRevUnselected(c.cursor.x); |
1864 | if (end == 0) break; | 1864 | if (end == 0) break; |
1865 | c.cursor.x = textLine->findRevSelected(end); | 1865 | c.cursor.x = textLine->findRevSelected(end); |
1866 | recordDelete(c.cursor, end - c.cursor.x); | 1866 | recordDelete(c.cursor, end - c.cursor.x); |
1867 | } while (true); | 1867 | } while (true); |
1868 | end = c.cursor.x; | 1868 | end = c.cursor.x; |
1869 | c.cursor.x = textLine->length(); | 1869 | c.cursor.x = textLine->length(); |
1870 | if (textLine->isSelected()) recordAction(KateAction::delLine,c.cursor); | 1870 | if (textLine->isSelected()) recordAction(KateAction::delLine,c.cursor); |
1871 | } | 1871 | } |
1872 | c.cursor.y++; | 1872 | c.cursor.y++; |
1873 | /*if (end < c.cursor.x)*/ c.cursor.x = end; | 1873 | /*if (end < c.cursor.x)*/ c.cursor.x = end; |
1874 | 1874 | ||
1875 | selectEnd = -1; | 1875 | selectEnd = -1; |
1876 | select.x = -1; | 1876 | select.x = -1; |
1877 | 1877 | ||
1878 | /*if (undo)*/ recordEnd(c); | 1878 | /*if (undo)*/ recordEnd(c); |
1879 | } | 1879 | } |
1880 | 1880 | ||
1881 | void KateDocument::tagLineRange(int line, int x1, int x2) { | 1881 | void KateDocument::tagLineRange(int line, int x1, int x2) { |
1882 | int z; | 1882 | int z; |
1883 | 1883 | ||
1884 | for (z = 0; z < (int) views.count(); z++) { | 1884 | for (z = 0; z < (int) views.count(); z++) { |
1885 | views.at(z)->tagLines(line, line, x1, x2); | 1885 | views.at(z)->tagLines(line, line, x1, x2); |
1886 | } | 1886 | } |
1887 | } | 1887 | } |
1888 | 1888 | ||
1889 | void KateDocument::tagLines(int start, int end) { | 1889 | void KateDocument::tagLines(int start, int end) { |
1890 | int z; | 1890 | int z; |
1891 | 1891 | ||
1892 | for (z = 0; z < (int) views.count(); z++) { | 1892 | for (z = 0; z < (int) views.count(); z++) { |
1893 | views.at(z)->tagLines(start, end, 0, 0xffffff); | 1893 | views.at(z)->tagLines(start, end, 0, 0xffffff); |
1894 | } | 1894 | } |
1895 | } | 1895 | } |
1896 | 1896 | ||
1897 | void KateDocument::tagAll() { | 1897 | void KateDocument::tagAll() { |
1898 | int z; | 1898 | int z; |
1899 | 1899 | ||
1900 | for (z = 0; z < (int) views.count(); z++) { | 1900 | for (z = 0; z < (int) views.count(); z++) { |
1901 | views.at(z)->tagAll(); | 1901 | views.at(z)->tagAll(); |
1902 | } | 1902 | } |
1903 | } | 1903 | } |
1904 | 1904 | ||
1905 | void KateDocument::updateLines(int startLine, int endLine, int flags, int cursorY) { | 1905 | void KateDocument::updateLines(int startLine, int endLine, int flags, int cursorY) { |
1906 | TextLine::Ptr textLine; | 1906 | TextLine::Ptr textLine; |
1907 | int line, last_line; | 1907 | int line, last_line; |
1908 | int ctxNum, endCtx; | 1908 | int ctxNum, endCtx; |
1909 | // kdDebug(13020)<<"******************KateDocument::updateLines Checkpoint 1"<<endl; | 1909 | // kdDebug(13020)<<"******************KateDocument::updateLines Checkpoint 1"<<endl; |
1910 | if (buffer->line(startLine)==0) {kdDebug(13020)<<"********************No buffer for line " << startLine << " found**************"<<endl; return;}; | 1910 | if (buffer->line(startLine)==0) {kdDebug(13020)<<"********************No buffer for line " << startLine << " found**************"<<endl; return;}; |
1911 | // kdDebug(13020)<<"KateDocument::updateLines Checkpoint 2"<<endl; | 1911 | // kdDebug(13020)<<"KateDocument::updateLines Checkpoint 2"<<endl; |
1912 | last_line = lastLine(); | 1912 | last_line = lastLine(); |
1913 | // if (endLine >= last_line) endLine = last_line; | 1913 | // if (endLine >= last_line) endLine = last_line; |
1914 | 1914 | ||
1915 | line = startLine; | 1915 | line = startLine; |
1916 | ctxNum = 0; | 1916 | ctxNum = 0; |
1917 | if (line > 0) ctxNum = getTextLine(line - 1)->getContext(); | 1917 | if (line > 0) ctxNum = getTextLine(line - 1)->getContext(); |
1918 | do { | 1918 | do { |
1919 | // kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl; | 1919 | // kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl; |
1920 | textLine = getTextLine(line); | 1920 | textLine = getTextLine(line); |
1921 | if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl; | 1921 | if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl; |
1922 | if (line <= endLine && line != cursorY) { | 1922 | if (line <= endLine && line != cursorY) { |
1923 | if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces(); | 1923 | if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces(); |
1924 | updateMaxLength(textLine); | 1924 | updateMaxLength(textLine); |
1925 | } | 1925 | } |
1926 | endCtx = textLine->getContext(); | 1926 | endCtx = textLine->getContext(); |
1927 | // odebug << "DOHIGHLIGHT" << oendl; | 1927 | // odebug << "DOHIGHLIGHT" << oendl; |
1928 | 1928 | ||
1929 | ctxNum = m_highlight->doHighlight(ctxNum,textLine); | 1929 | ctxNum = m_highlight->doHighlight(ctxNum,textLine); |
1930 | textLine->setContext(ctxNum); | 1930 | textLine->setContext(ctxNum); |
1931 | line++; | 1931 | line++; |
1932 | } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum)); | 1932 | } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum)); |
1933 | // kdDebug(13020)<<"updateLines :: while loop left"<<endl; | 1933 | // kdDebug(13020)<<"updateLines :: while loop left"<<endl; |
1934 | tagLines(startLine, line - 1); | 1934 | tagLines(startLine, line - 1); |
1935 | } | 1935 | } |
1936 | 1936 | ||
1937 | 1937 | ||
1938 | void KateDocument::updateMaxLength(TextLine::Ptr &textLine) { | 1938 | void KateDocument::updateMaxLength(TextLine::Ptr &textLine) { |
1939 | int len; | 1939 | int len; |
1940 | 1940 | ||
1941 | len = textWidth(textLine,textLine->length()); | 1941 | len = textWidth(textLine,textLine->length()); |
1942 | 1942 | ||
1943 | if (len > maxLength) { | 1943 | if (len > maxLength) { |
1944 | longestLine = textLine; | 1944 | longestLine = textLine; |
1945 | maxLength = len; | 1945 | maxLength = len; |
1946 | newDocGeometry = true; | 1946 | newDocGeometry = true; |
1947 | } else { | 1947 | } else { |
1948 | if (!longestLine || (textLine == longestLine && len <= maxLength*3/4)) { | 1948 | if (!longestLine || (textLine == longestLine && len <= maxLength*3/4)) { |
1949 | maxLength = -1; | 1949 | maxLength = -1; |
1950 | for (int i = 0; i < numLines();i++) { | 1950 | for (int i = 0; i < numLines();i++) { |
1951 | textLine = getTextLine(i); | 1951 | textLine = getTextLine(i); |
1952 | len = textWidth(textLine,textLine->length()); | 1952 | len = textWidth(textLine,textLine->length()); |
1953 | if (len > maxLength) { | 1953 | if (len > maxLength) { |
1954 | maxLength = len; | 1954 | maxLength = len; |
1955 | longestLine = textLine; | 1955 | longestLine = textLine; |
1956 | } | 1956 | } |
1957 | } | 1957 | } |
1958 | newDocGeometry = true; | 1958 | newDocGeometry = true; |
1959 | } | 1959 | } |
1960 | } | 1960 | } |
1961 | } | 1961 | } |
1962 | 1962 | ||
1963 | void KateDocument::slotBufferChanged() { | 1963 | void KateDocument::slotBufferChanged() { |
1964 | newDocGeometry = true; | 1964 | newDocGeometry = true; |
1965 | //updateLines();//JW | 1965 | //updateLines();//JW |
1966 | updateViews(); | 1966 | updateViews(); |
1967 | } | 1967 | } |
1968 | 1968 | ||
1969 | void KateDocument::slotBufferHighlight(long start,long stop) { | 1969 | void KateDocument::slotBufferHighlight(long start,long stop) { |
1970 | kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl; | 1970 | kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl; |
1971 | updateLines(start,stop); | 1971 | updateLines(start,stop); |
1972 | // buffer->startLoadTimer(); | 1972 | // buffer->startLoadTimer(); |
1973 | } | 1973 | } |
1974 | 1974 | ||
1975 | void KateDocument::updateViews(KateView *exclude) { | 1975 | void KateDocument::updateViews(KateView *exclude) { |
1976 | KateView *view; | 1976 | KateView *view; |
1977 | int flags; | 1977 | int flags; |
1978 | bool markState = hasMarkedText(); | 1978 | bool markState = hasMarkedText(); |
1979 | 1979 | ||
1980 | flags = (newDocGeometry) ? KateView::ufDocGeometry : 0; | 1980 | flags = (newDocGeometry) ? KateView::ufDocGeometry : 0; |
1981 | for (view = views.first(); view != 0L; view = views.next() ) { | 1981 | for (view = views.first(); view != 0L; view = views.next() ) { |
1982 | if (view != exclude) view->updateView(flags); | 1982 | if (view != exclude) view->updateView(flags); |
1983 | 1983 | ||
1984 | // notify every view about the changed mark state.... | 1984 | // notify every view about the changed mark state.... |
1985 | if (oldMarkState != markState) emit view->newMarkStatus(); | 1985 | if (oldMarkState != markState) emit view->newMarkStatus(); |
1986 | } | 1986 | } |
1987 | oldMarkState = markState; | 1987 | oldMarkState = markState; |
1988 | newDocGeometry = false; | 1988 | newDocGeometry = false; |
1989 | } | 1989 | } |
1990 | 1990 | ||
1991 | QColor &KateDocument::cursorCol(int x, int y) { | 1991 | QColor &KateDocument::cursorCol(int x, int y) { |
1992 | int attr; | 1992 | int attr; |
1993 | Attribute *a; | 1993 | Attribute *a; |
1994 | 1994 | ||
1995 | TextLine::Ptr textLine = getTextLine(y); | 1995 | TextLine::Ptr textLine = getTextLine(y); |
1996 | attr = textLine->getRawAttr(x); | 1996 | attr = textLine->getRawAttr(x); |
1997 | a = &m_attribs[attr & taAttrMask]; | 1997 | a = &m_attribs[attr & taAttrMask]; |
1998 | if (attr & taSelected) return a->selCol; else return a->col; | 1998 | if (attr & taSelected) return a->selCol; else return a->col; |
1999 | } | 1999 | } |
2000 | 2000 | ||
2001 | void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs) | 2001 | void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs) |
2002 | { | 2002 | { |
2003 | paintTextLine (paint, line, 0, xStart, xEnd, showTabs); | 2003 | paintTextLine (paint, line, 0, xStart, xEnd, showTabs); |
2004 | } | 2004 | } |
2005 | 2005 | ||
2006 | void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs) | 2006 | void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs) |
2007 | { | 2007 | { |
2008 | TextLine::Ptr textLine; | 2008 | TextLine::Ptr textLine; |
2009 | int len; | 2009 | int len; |
2010 | const QChar *s; | 2010 | const QChar *s; |
2011 | int z, x; | 2011 | int z, x; |
2012 | QChar ch; | 2012 | QChar ch; |
2013 | Attribute *a = 0L; | 2013 | Attribute *a = 0L; |
2014 | int attr, nextAttr; | 2014 | int attr, nextAttr; |
2015 | int xs; | 2015 | int xs; |
2016 | int xc, zc; | 2016 | int xc, zc; |
2017 | 2017 | ||
2018 | if (line > lastLine()) { | 2018 | if (line > lastLine()) { |
2019 | paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]); | 2019 | paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]); |
2020 | return; | 2020 | return; |
2021 | } | 2021 | } |
2022 | 2022 | ||
2023 | textLine = getTextLine(line); | 2023 | textLine = getTextLine(line); |
2024 | len = textLine->length(); | 2024 | len = textLine->length(); |
2025 | s = textLine->getText(); | 2025 | s = textLine->getText(); |
2026 | 2026 | ||
2027 | // skip to first visible character | 2027 | // skip to first visible character |
2028 | x = 0; | 2028 | x = 0; |
2029 | z = 0; | 2029 | z = 0; |
2030 | do { | 2030 | do { |
2031 | xc = x; | 2031 | xc = x; |
2032 | zc = z; | 2032 | zc = z; |
2033 | if (z == len) break; | 2033 | if (z == len) break; |
2034 | ch = s[z];//textLine->getChar(z); | 2034 | ch = s[z];//textLine->getChar(z); |
2035 | if (ch == '\t') { | 2035 | if (ch == '\t') { |
2036 | x += m_tabWidth - (x % m_tabWidth); | 2036 | x += m_tabWidth - (x % m_tabWidth); |
2037 | } else { | 2037 | } else { |
2038 | a = &m_attribs[textLine->getAttr(z)]; | 2038 | a = &m_attribs[textLine->getAttr(z)]; |
2039 | 2039 | ||
2040 | if (a->bold && a->italic) | 2040 | if (a->bold && a->italic) |
2041 | x += myFontMetricsBI.width(ch); | 2041 | x += myFontMetricsBI.width(ch); |
2042 | else if (a->bold) | 2042 | else if (a->bold) |
2043 | x += myFontMetricsBold.width(ch); | 2043 | x += myFontMetricsBold.width(ch); |
2044 | else if (a->italic) | 2044 | else if (a->italic) |
2045 | x += myFontMetricsItalic.width(ch); | 2045 | x += myFontMetricsItalic.width(ch); |
2046 | else | 2046 | else |
2047 | x += myFontMetrics.width(ch); | 2047 | x += myFontMetrics.width(ch); |
2048 | } | 2048 | } |
2049 | z++; | 2049 | z++; |
2050 | } while (x <= xStart); | 2050 | } while (x <= xStart); |
2051 | 2051 | ||
2052 | // draw background | 2052 | // draw background |
2053 | xs = xStart; | 2053 | xs = xStart; |
2054 | attr = textLine->getRawAttr(zc); | 2054 | attr = textLine->getRawAttr(zc); |
2055 | while (x < xEnd) | 2055 | while (x < xEnd) |
2056 | { | 2056 | { |
2057 | nextAttr = textLine->getRawAttr(z); | 2057 | nextAttr = textLine->getRawAttr(z); |
2058 | if ((nextAttr ^ attr) & taSelected) | 2058 | if ((nextAttr ^ attr) & taSelected) |
2059 | { | 2059 | { |
2060 | if (attr & taSelected) | 2060 | if (attr & taSelected) |
2061 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]); | 2061 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]); |
2062 | else | 2062 | else |
2063 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]); | 2063 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]); |
2064 | 2064 | ||
2065 | xs = x; | 2065 | xs = x; |
2066 | attr = nextAttr; | 2066 | attr = nextAttr; |
2067 | } | 2067 | } |
2068 | 2068 | ||
2069 | if (z == len) break; | 2069 | if (z == len) break; |
2070 | 2070 | ||
2071 | ch = s[z];//textLine->getChar(z); | 2071 | ch = s[z];//textLine->getChar(z); |
2072 | 2072 | ||
2073 | if (ch == '\t') | 2073 | if (ch == '\t') |
2074 | x += m_tabWidth - (x % m_tabWidth); | 2074 | x += m_tabWidth - (x % m_tabWidth); |
2075 | else | 2075 | else |
2076 | { | 2076 | { |
2077 | a = &m_attribs[textLine->getAttr(z)]; | 2077 | a = &m_attribs[textLine->getAttr(z)]; |
2078 | 2078 | ||
2079 | if (a->bold && a->italic) | 2079 | if (a->bold && a->italic) |
2080 | x += myFontMetricsBI.width(ch); | 2080 | x += myFontMetricsBI.width(ch); |
2081 | else if (a->bold) | 2081 | else if (a->bold) |
2082 | x += myFontMetricsBold.width(ch); | 2082 | x += myFontMetricsBold.width(ch); |
2083 | else if (a->italic) | 2083 | else if (a->italic) |
2084 | x += myFontMetricsItalic.width(ch); | 2084 | x += myFontMetricsItalic.width(ch); |
2085 | else | 2085 | else |
2086 | x += myFontMetrics.width(ch); | 2086 | x += myFontMetrics.width(ch); |
2087 | } | 2087 | } |
2088 | z++; | 2088 | z++; |
2089 | } | 2089 | } |
2090 | 2090 | ||
2091 | if (attr & taSelected) | 2091 | if (attr & taSelected) |
2092 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]); | 2092 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]); |
2093 | else | 2093 | else |
2094 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]); | 2094 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]); |
2095 | 2095 | ||
2096 | len = z; //reduce length to visible length | 2096 | len = z; //reduce length to visible length |
2097 | 2097 | ||
2098 | // draw text | 2098 | // draw text |
2099 | x = xc; | 2099 | x = xc; |
2100 | z = zc; | 2100 | z = zc; |
2101 | y += fontAscent;// -1; | 2101 | y += fontAscent;// -1; |
2102 | attr = -1; | 2102 | attr = -1; |
2103 | while (z < len) { | 2103 | while (z < len) { |
2104 | ch = s[z];//textLine->getChar(z); | 2104 | ch = s[z];//textLine->getChar(z); |
2105 | if (ch == '\t') { | 2105 | if (ch == '\t') { |
2106 | if (z > zc) { | 2106 | if (z > zc) { |
2107 | //this should cause no copy at all | 2107 | //this should cause no copy at all |
2108 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2108 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2109 | QString s = str.string(); | 2109 | QString s = str.string(); |
2110 | paint.drawText(x - xStart, y, s); | 2110 | paint.drawText(x - xStart, y, s); |
2111 | 2111 | ||
2112 | if (a->bold && a->italic) | 2112 | if (a->bold && a->italic) |
2113 | x += myFontMetricsBI.width(s); | 2113 | x += myFontMetricsBI.width(s); |
2114 | else if (a->bold) | 2114 | else if (a->bold) |
2115 | x += myFontMetricsBold.width(s); | 2115 | x += myFontMetricsBold.width(s); |
2116 | else if (a->italic) | 2116 | else if (a->italic) |
2117 | x += myFontMetricsItalic.width(s); | 2117 | x += myFontMetricsItalic.width(s); |
2118 | else | 2118 | else |
2119 | x += myFontMetrics.width(s); | 2119 | x += myFontMetrics.width(s); |
2120 | } | 2120 | } |
2121 | zc = z +1; | 2121 | zc = z +1; |
2122 | 2122 | ||
2123 | if (showTabs) { | 2123 | if (showTabs) { |
2124 | nextAttr = textLine->getRawAttr(z); | 2124 | nextAttr = textLine->getRawAttr(z); |
2125 | if (nextAttr != attr) { | 2125 | if (nextAttr != attr) { |
2126 | attr = nextAttr; | 2126 | attr = nextAttr; |
2127 | a = &m_attribs[attr & taAttrMask]; | 2127 | a = &m_attribs[attr & taAttrMask]; |
2128 | 2128 | ||
2129 | if (attr & taSelected) paint.setPen(a->selCol); | 2129 | if (attr & taSelected) paint.setPen(a->selCol); |
2130 | else paint.setPen(a->col); | 2130 | else paint.setPen(a->col); |
2131 | 2131 | ||
2132 | if (a->bold && a->italic) | 2132 | if (a->bold && a->italic) |
2133 | paint.setFont(myFontBI); | 2133 | paint.setFont(myFontBI); |
2134 | else if (a->bold) | 2134 | else if (a->bold) |
2135 | paint.setFont(myFontBold); | 2135 | paint.setFont(myFontBold); |
2136 | else if (a->italic) | 2136 | else if (a->italic) |
2137 | paint.setFont(myFontItalic); | 2137 | paint.setFont(myFontItalic); |
2138 | else | 2138 | else |
2139 | paint.setFont(myFont); | 2139 | paint.setFont(myFont); |
2140 | } | 2140 | } |
2141 | 2141 | ||
2142 | // paint.drawLine(x - xStart, y -2, x - xStart, y); | 2142 | // paint.drawLine(x - xStart, y -2, x - xStart, y); |
2143 | // paint.drawLine(x - xStart, y, x - xStart + 2, y); | 2143 | // paint.drawLine(x - xStart, y, x - xStart + 2, y); |
2144 | paint.drawPoint(x - xStart, y); | 2144 | paint.drawPoint(x - xStart, y); |
2145 | paint.drawPoint(x - xStart +1, y); | 2145 | paint.drawPoint(x - xStart +1, y); |
2146 | paint.drawPoint(x - xStart, y -1); | 2146 | paint.drawPoint(x - xStart, y -1); |
2147 | } | 2147 | } |
2148 | x += m_tabWidth - (x % m_tabWidth); | 2148 | x += m_tabWidth - (x % m_tabWidth); |
2149 | } else { | 2149 | } else { |
2150 | nextAttr = textLine->getRawAttr(z); | 2150 | nextAttr = textLine->getRawAttr(z); |
2151 | if (nextAttr != attr) { | 2151 | if (nextAttr != attr) { |
2152 | if (z > zc) { | 2152 | if (z > zc) { |
2153 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2153 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2154 | QString s = str.string(); | 2154 | QString s = str.string(); |
2155 | paint.drawText(x - xStart, y, s); | 2155 | paint.drawText(x - xStart, y, s); |
2156 | 2156 | ||
2157 | if (a->bold && a->italic) | 2157 | if (a->bold && a->italic) |
2158 | x += myFontMetricsBI.width(s); | 2158 | x += myFontMetricsBI.width(s); |
2159 | else if (a->bold) | 2159 | else if (a->bold) |
2160 | x += myFontMetricsBold.width(s); | 2160 | x += myFontMetricsBold.width(s); |
2161 | else if (a->italic) | 2161 | else if (a->italic) |
2162 | x += myFontMetricsItalic.width(s); | 2162 | x += myFontMetricsItalic.width(s); |
2163 | else | 2163 | else |
2164 | x += myFontMetrics.width(s); | 2164 | x += myFontMetrics.width(s); |
2165 | zc = z; | 2165 | zc = z; |
2166 | } | 2166 | } |
2167 | attr = nextAttr; | 2167 | attr = nextAttr; |
2168 | a = &m_attribs[attr & taAttrMask]; | 2168 | a = &m_attribs[attr & taAttrMask]; |
2169 | 2169 | ||
2170 | if (attr & taSelected) paint.setPen(a->selCol); | 2170 | if (attr & taSelected) paint.setPen(a->selCol); |
2171 | else paint.setPen(a->col); | 2171 | else paint.setPen(a->col); |
2172 | 2172 | ||
2173 | if (a->bold && a->italic) | 2173 | if (a->bold && a->italic) |
2174 | paint.setFont(myFontBI); | 2174 | paint.setFont(myFontBI); |
2175 | else if (a->bold) | 2175 | else if (a->bold) |
2176 | paint.setFont(myFontBold); | 2176 | paint.setFont(myFontBold); |
2177 | else if (a->italic) | 2177 | else if (a->italic) |
2178 | paint.setFont(myFontItalic); | 2178 | paint.setFont(myFontItalic); |
2179 | else | 2179 | else |
2180 | paint.setFont(myFont); | 2180 | paint.setFont(myFont); |
2181 | } | 2181 | } |
2182 | } | 2182 | } |
2183 | z++; | 2183 | z++; |
2184 | } | 2184 | } |
2185 | if (z > zc) { | 2185 | if (z > zc) { |
2186 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2186 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2187 | paint.drawText(x - xStart, y, str.string()); | 2187 | paint.drawText(x - xStart, y, str.string()); |
2188 | } | 2188 | } |
2189 | } | 2189 | } |
2190 | 2190 | ||
2191 | // Applies the search context, and returns whether a match was found. If one is, | 2191 | // Applies the search context, and returns whether a match was found. If one is, |
2192 | // the length of the string matched is also returned. | 2192 | // the length of the string matched is also returned. |
2193 | bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { | 2193 | bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { |
2194 | int line, col; | 2194 | int line, col; |
2195 | int searchEnd; | 2195 | int searchEnd; |
2196 | int bufLen, tlen; | 2196 | int bufLen, tlen; |
2197 | QChar *t; | 2197 | QChar *t; |
2198 | TextLine::Ptr textLine; | 2198 | TextLine::Ptr textLine; |
2199 | int pos, newPos; | 2199 | int pos, newPos; |
2200 | 2200 | ||
2201 | if (searchFor.isEmpty()) return false; | 2201 | if (searchFor.isEmpty()) return false; |
2202 | 2202 | ||
2203 | bufLen = 0; | 2203 | bufLen = 0; |
2204 | t = 0L; | 2204 | t = 0L; |
2205 | 2205 | ||
2206 | line = sc.cursor.y; | 2206 | line = sc.cursor.y; |
2207 | col = sc.cursor.x; | 2207 | col = sc.cursor.x; |
2208 | if (!(sc.flags & KateView::sfBackward)) { | 2208 | if (!(sc.flags & KateView::sfBackward)) { |
2209 | //forward search | 2209 | //forward search |
2210 | if (sc.flags & KateView::sfSelected) { | 2210 | if (sc.flags & KateView::sfSelected) { |
2211 | if (line < selectStart) { | 2211 | if (line < selectStart) { |
2212 | line = selectStart; | 2212 | line = selectStart; |
2213 | col = 0; | 2213 | col = 0; |
2214 | } | 2214 | } |
2215 | searchEnd = selectEnd; | 2215 | searchEnd = selectEnd; |
2216 | } else searchEnd = lastLine(); | 2216 | } else searchEnd = lastLine(); |
2217 | 2217 | ||
2218 | while (line <= searchEnd) { | 2218 | while (line <= searchEnd) { |
2219 | textLine = getTextLine(line); | 2219 | textLine = getTextLine(line); |
2220 | tlen = textLine->length(); | 2220 | tlen = textLine->length(); |
2221 | if (tlen > bufLen) { | 2221 | if (tlen > bufLen) { |
2222 | delete t; | 2222 | delete [] t; |
2223 | bufLen = (tlen + 255) & (~255); | 2223 | bufLen = (tlen + 255) & (~255); |
2224 | t = new QChar[bufLen]; | 2224 | t = new QChar[bufLen]; |
2225 | } | 2225 | } |
2226 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); | 2226 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); |
2227 | if (sc.flags & KateView::sfSelected) { | 2227 | if (sc.flags & KateView::sfSelected) { |
2228 | pos = 0; | 2228 | pos = 0; |
2229 | do { | 2229 | do { |
2230 | pos = textLine->findSelected(pos); | 2230 | pos = textLine->findSelected(pos); |
2231 | newPos = textLine->findUnselected(pos); | 2231 | newPos = textLine->findUnselected(pos); |
2232 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); | 2232 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); |
2233 | pos = newPos; | 2233 | pos = newPos; |
2234 | } while (pos < tlen); | 2234 | } while (pos < tlen); |
2235 | } | 2235 | } |
2236 | 2236 | ||
2237 | QString text(t, tlen); | 2237 | QString text(t, tlen); |
2238 | if (sc.flags & KateView::sfWholeWords) { | 2238 | if (sc.flags & KateView::sfWholeWords) { |
2239 | // Until the end of the line... | 2239 | // Until the end of the line... |
2240 | while (col < tlen) { | 2240 | while (col < tlen) { |
2241 | // ...find the next match. | 2241 | // ...find the next match. |
2242 | col = sc.search(text, col); | 2242 | col = sc.search(text, col); |
2243 | if (col != -1) { | 2243 | if (col != -1) { |
2244 | // Is the match delimited correctly? | 2244 | // Is the match delimited correctly? |
2245 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && | 2245 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && |
2246 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { | 2246 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { |
2247 | goto found; | 2247 | goto found; |
2248 | } | 2248 | } |
2249 | else { | 2249 | else { |
2250 | // Start again from the next character. | 2250 | // Start again from the next character. |
2251 | col++; | 2251 | col++; |
2252 | } | 2252 | } |
2253 | } | 2253 | } |
2254 | else { | 2254 | else { |
2255 | // No match. | 2255 | // No match. |
2256 | break; | 2256 | break; |
2257 | } | 2257 | } |
2258 | } | 2258 | } |
2259 | } | 2259 | } |
2260 | else { | 2260 | else { |
2261 | // Non-whole-word search. | 2261 | // Non-whole-word search. |
2262 | col = sc.search(text, col); | 2262 | col = sc.search(text, col); |
2263 | if (col != -1) | 2263 | if (col != -1) |
2264 | goto found; | 2264 | goto found; |
2265 | } | 2265 | } |
2266 | col = 0; | 2266 | col = 0; |
2267 | line++; | 2267 | line++; |
2268 | } | 2268 | } |
2269 | } else { | 2269 | } else { |
2270 | // backward search | 2270 | // backward search |
2271 | if (sc.flags & KateView::sfSelected) { | 2271 | if (sc.flags & KateView::sfSelected) { |
2272 | if (line > selectEnd) { | 2272 | if (line > selectEnd) { |
2273 | line = selectEnd; | 2273 | line = selectEnd; |
2274 | col = -1; | 2274 | col = -1; |
2275 | } | 2275 | } |
2276 | searchEnd = selectStart; | 2276 | searchEnd = selectStart; |
2277 | } else searchEnd = 0; | 2277 | } else searchEnd = 0; |
2278 | 2278 | ||
2279 | while (line >= searchEnd) { | 2279 | while (line >= searchEnd) { |
2280 | textLine = getTextLine(line); | 2280 | textLine = getTextLine(line); |
2281 | tlen = textLine->length(); | 2281 | tlen = textLine->length(); |
2282 | if (tlen > bufLen) { | 2282 | if (tlen > bufLen) { |
2283 | delete t; | 2283 | delete [] t; |
2284 | bufLen = (tlen + 255) & (~255); | 2284 | bufLen = (tlen + 255) & (~255); |
2285 | t = new QChar[bufLen]; | 2285 | t = new QChar[bufLen]; |
2286 | } | 2286 | } |
2287 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); | 2287 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); |
2288 | if (sc.flags & KateView::sfSelected) { | 2288 | if (sc.flags & KateView::sfSelected) { |
2289 | pos = 0; | 2289 | pos = 0; |
2290 | do { | 2290 | do { |
2291 | pos = textLine->findSelected(pos); | 2291 | pos = textLine->findSelected(pos); |
2292 | newPos = textLine->findUnselected(pos); | 2292 | newPos = textLine->findUnselected(pos); |
2293 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); | 2293 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); |
2294 | pos = newPos; | 2294 | pos = newPos; |
2295 | } while (pos < tlen); | 2295 | } while (pos < tlen); |
2296 | } | 2296 | } |
2297 | 2297 | ||
2298 | if (col < 0 || col > tlen) col = tlen; | 2298 | if (col < 0 || col > tlen) col = tlen; |
2299 | 2299 | ||
2300 | QString text(t, tlen); | 2300 | QString text(t, tlen); |
2301 | if (sc.flags & KateView::sfWholeWords) { | 2301 | if (sc.flags & KateView::sfWholeWords) { |
2302 | // Until the beginning of the line... | 2302 | // Until the beginning of the line... |
2303 | while (col >= 0) { | 2303 | while (col >= 0) { |
2304 | // ...find the next match. | 2304 | // ...find the next match. |
2305 | col = sc.search(text, col); | 2305 | col = sc.search(text, col); |
2306 | if (col != -1) { | 2306 | if (col != -1) { |
2307 | // Is the match delimited correctly? | 2307 | // Is the match delimited correctly? |
2308 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && | 2308 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && |
2309 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { | 2309 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { |
2310 | goto found; | 2310 | goto found; |
2311 | } | 2311 | } |
2312 | else { | 2312 | else { |
2313 | // Start again from the previous character. | 2313 | // Start again from the previous character. |
2314 | col--; | 2314 | col--; |
2315 | } | 2315 | } |
2316 | } | 2316 | } |
2317 | else { | 2317 | else { |
2318 | // No match. | 2318 | // No match. |
2319 | break; | 2319 | break; |
2320 | } | 2320 | } |
2321 | } | 2321 | } |
2322 | } | 2322 | } |
2323 | else { | 2323 | else { |
2324 | // Non-whole-word search. | 2324 | // Non-whole-word search. |
2325 | col = sc.search(text, col); | 2325 | col = sc.search(text, col); |
2326 | if (col != -1) | 2326 | if (col != -1) |
2327 | goto found; | 2327 | goto found; |
2328 | } | 2328 | } |
2329 | col = -1; | 2329 | col = -1; |
2330 | line--; | 2330 | line--; |
2331 | } | 2331 | } |
2332 | } | 2332 | } |
2333 | sc.flags |= KateView::sfWrapped; | 2333 | sc.flags |= KateView::sfWrapped; |
2334 | return false; | 2334 | return false; |
2335 | found: | 2335 | found: |
2336 | if (sc.flags & KateView::sfWrapped) { | 2336 | if (sc.flags & KateView::sfWrapped) { |
2337 | if ((line > sc.startCursor.y || (line == sc.startCursor.y && col >= sc.startCursor.x)) | 2337 | if ((line > sc.startCursor.y || (line == sc.startCursor.y && col >= sc.startCursor.x)) |
2338 | ^ ((sc.flags & KateView::sfBackward) != 0)) return false; | 2338 | ^ ((sc.flags & KateView::sfBackward) != 0)) return false; |
2339 | } | 2339 | } |
2340 | sc.cursor.x = col; | 2340 | sc.cursor.x = col; |
2341 | sc.cursor.y = line; | 2341 | sc.cursor.y = line; |
2342 | return true; | 2342 | return true; |
2343 | } | 2343 | } |
2344 | 2344 | ||
2345 | void KateDocument::tagLine(int line) { | 2345 | void KateDocument::tagLine(int line) { |
2346 | 2346 | ||
2347 | if (tagStart > line) tagStart = line; | 2347 | if (tagStart > line) tagStart = line; |
2348 | if (tagEnd < line) tagEnd = line; | 2348 | if (tagEnd < line) tagEnd = line; |
2349 | } | 2349 | } |
2350 | 2350 | ||
2351 | void KateDocument::insLine(int line) { | 2351 | void KateDocument::insLine(int line) { |
2352 | KateView *view; | 2352 | KateView *view; |
2353 | 2353 | ||
2354 | if (selectStart >= line) selectStart++; | 2354 | if (selectStart >= line) selectStart++; |
2355 | if (selectEnd >= line) selectEnd++; | 2355 | if (selectEnd >= line) selectEnd++; |
2356 | if (tagStart >= line) tagStart++; | 2356 | if (tagStart >= line) tagStart++; |
2357 | if (tagEnd >= line) tagEnd++; | 2357 | if (tagEnd >= line) tagEnd++; |
2358 | 2358 | ||
2359 | newDocGeometry = true; | 2359 | newDocGeometry = true; |
2360 | for (view = views.first(); view != 0L; view = views.next() ) { | 2360 | for (view = views.first(); view != 0L; view = views.next() ) { |
2361 | view->insLine(line); | 2361 | view->insLine(line); |
2362 | } | 2362 | } |
2363 | } | 2363 | } |
2364 | 2364 | ||
2365 | void KateDocument::delLine(int line) { | 2365 | void KateDocument::delLine(int line) { |
2366 | KateView *view; | 2366 | KateView *view; |
2367 | 2367 | ||
2368 | if (selectStart >= line && selectStart > 0) selectStart--; | 2368 | if (selectStart >= line && selectStart > 0) selectStart--; |
2369 | if (selectEnd >= line) selectEnd--; | 2369 | if (selectEnd >= line) selectEnd--; |
2370 | if (tagStart >= line && tagStart > 0) tagStart--; | 2370 | if (tagStart >= line && tagStart > 0) tagStart--; |
2371 | if (tagEnd >= line) tagEnd--; | 2371 | if (tagEnd >= line) tagEnd--; |
2372 | 2372 | ||
2373 | newDocGeometry = true; | 2373 | newDocGeometry = true; |
2374 | for (view = views.first(); view != 0L; view = views.next() ) { | 2374 | for (view = views.first(); view != 0L; view = views.next() ) { |
2375 | view->delLine(line); | 2375 | view->delLine(line); |
2376 | } | 2376 | } |
2377 | } | 2377 | } |
2378 | 2378 | ||
2379 | void KateDocument::optimizeSelection() { | 2379 | void KateDocument::optimizeSelection() { |
2380 | TextLine::Ptr textLine; | 2380 | TextLine::Ptr textLine; |
2381 | 2381 | ||
2382 | while (selectStart <= selectEnd) { | 2382 | while (selectStart <= selectEnd) { |
2383 | textLine = getTextLine(selectStart); | 2383 | textLine = getTextLine(selectStart); |
2384 | if (textLine->isSelected() || textLine->numSelected() > 0) break; | 2384 | if (textLine->isSelected() || textLine->numSelected() > 0) break; |
2385 | selectStart++; | 2385 | selectStart++; |
2386 | } | 2386 | } |
2387 | while (selectEnd >= selectStart) { | 2387 | while (selectEnd >= selectStart) { |
2388 | textLine = getTextLine(selectEnd); | 2388 | textLine = getTextLine(selectEnd); |
2389 | if (textLine->isSelected() || textLine->numSelected() > 0) break; | 2389 | if (textLine->isSelected() || textLine->numSelected() > 0) break; |
2390 | selectEnd--; | 2390 | selectEnd--; |
2391 | } | 2391 | } |
2392 | if (selectStart > selectEnd) { | 2392 | if (selectStart > selectEnd) { |
2393 | selectStart = 0xffffff; | 2393 | selectStart = 0xffffff; |
2394 | selectEnd = 0; | 2394 | selectEnd = 0; |
2395 | } | 2395 | } |
2396 | } | 2396 | } |
2397 | 2397 | ||
2398 | void KateDocument::doAction(KateAction *a) { | 2398 | void KateDocument::doAction(KateAction *a) { |
2399 | 2399 | ||
2400 | switch (a->action) { | 2400 | switch (a->action) { |
2401 | case KateAction::replace: | 2401 | case KateAction::replace: |
2402 | doReplace(a); | 2402 | doReplace(a); |
2403 | break; | 2403 | break; |
2404 | case KateAction::wordWrap: | 2404 | case KateAction::wordWrap: |
2405 | doWordWrap(a); | 2405 | doWordWrap(a); |
2406 | break; | 2406 | break; |
2407 | case KateAction::wordUnWrap: | 2407 | case KateAction::wordUnWrap: |
2408 | doWordUnWrap(a); | 2408 | doWordUnWrap(a); |
2409 | break; | 2409 | break; |
2410 | case KateAction::newLine: | 2410 | case KateAction::newLine: |
2411 | doNewLine(a); | 2411 | doNewLine(a); |
2412 | break; | 2412 | break; |
2413 | case KateAction::delLine: | 2413 | case KateAction::delLine: |
2414 | doDelLine(a); | 2414 | doDelLine(a); |
2415 | break; | 2415 | break; |
2416 | case KateAction::insLine: | 2416 | case KateAction::insLine: |
2417 | doInsLine(a); | 2417 | doInsLine(a); |
2418 | break; | 2418 | break; |
2419 | case KateAction::killLine: | 2419 | case KateAction::killLine: |
2420 | doKillLine(a); | 2420 | doKillLine(a); |
2421 | break; | 2421 | break; |
2422 | /* case KateAction::doubleLine: | 2422 | /* case KateAction::doubleLine: |
2423 | break; | 2423 | break; |
2424 | case KateAction::removeLine: | 2424 | case KateAction::removeLine: |
2425 | break;*/ | 2425 | break;*/ |
2426 | } | 2426 | } |
2427 | } | 2427 | } |
2428 | 2428 | ||
2429 | void KateDocument::doReplace(KateAction *a) { | 2429 | void KateDocument::doReplace(KateAction *a) { |
2430 | TextLine::Ptr textLine; | 2430 | TextLine::Ptr textLine; |
2431 | int l; | 2431 | int l; |
2432 | 2432 | ||
2433 | //exchange current text with stored text in KateAction *a | 2433 | //exchange current text with stored text in KateAction *a |
2434 | 2434 | ||
2435 | textLine = getTextLine(a->cursor.y); | 2435 | textLine = getTextLine(a->cursor.y); |
2436 | l = textLine->length() - a->cursor.x; | 2436 | l = textLine->length() - a->cursor.x; |
2437 | if (l > a->len) l = a->len; | 2437 | if (l > a->len) l = a->len; |
2438 | 2438 | ||
2439 | QString oldText(&textLine->getText()[a->cursor.x], (l < 0) ? 0 : l); | 2439 | QString oldText(&textLine->getText()[a->cursor.x], (l < 0) ? 0 : l); |
2440 | textLine->replace(a->cursor.x, a->len, a->text.unicode(), a->text.length()); | 2440 | textLine->replace(a->cursor.x, a->len, a->text.unicode(), a->text.length()); |
2441 | 2441 | ||
2442 | a->len = a->text.length(); | 2442 | a->len = a->text.length(); |
2443 | a->text = oldText; | 2443 | a->text = oldText; |
2444 | 2444 | ||
2445 | buffer->changeLine(a->cursor.y); | 2445 | buffer->changeLine(a->cursor.y); |
2446 | 2446 | ||
2447 | tagLine(a->cursor.y); | 2447 | tagLine(a->cursor.y); |
2448 | } | 2448 | } |
2449 | 2449 | ||
2450 | void KateDocument::doWordWrap(KateAction *a) { | 2450 | void KateDocument::doWordWrap(KateAction *a) { |
2451 | TextLine::Ptr textLine; | 2451 | TextLine::Ptr textLine; |
2452 | 2452 | ||
2453 | textLine = getTextLine(a->cursor.y - 1); | 2453 | textLine = getTextLine(a->cursor.y - 1); |
2454 | a->len = textLine->length() - a->cursor.x; | 2454 | a->len = textLine->length() - a->cursor.x; |
2455 | textLine->wrap(getTextLine(a->cursor.y),a->len); | 2455 | textLine->wrap(getTextLine(a->cursor.y),a->len); |
2456 | 2456 | ||
2457 | buffer->changeLine(a->cursor.y - 1); | 2457 | buffer->changeLine(a->cursor.y - 1); |
2458 | buffer->changeLine(a->cursor.y); | 2458 | buffer->changeLine(a->cursor.y); |
2459 | 2459 | ||
2460 | tagLine(a->cursor.y - 1); | 2460 | tagLine(a->cursor.y - 1); |
2461 | tagLine(a->cursor.y); | 2461 | tagLine(a->cursor.y); |
2462 | if (selectEnd == a->cursor.y - 1) selectEnd++; | 2462 | if (selectEnd == a->cursor.y - 1) selectEnd++; |
2463 | 2463 | ||
2464 | a->action = KateAction::wordUnWrap; | 2464 | a->action = KateAction::wordUnWrap; |
2465 | } | 2465 | } |
2466 | 2466 | ||
2467 | void KateDocument::doWordUnWrap(KateAction *a) { | 2467 | void KateDocument::doWordUnWrap(KateAction *a) { |
2468 | TextLine::Ptr textLine; | 2468 | TextLine::Ptr textLine; |
2469 | 2469 | ||
2470 | textLine = getTextLine(a->cursor.y - 1); | 2470 | textLine = getTextLine(a->cursor.y - 1); |
2471 | // textLine->setLength(a->len); | 2471 | // textLine->setLength(a->len); |
2472 | textLine->unWrap(a->len, getTextLine(a->cursor.y),a->cursor.x); | 2472 | textLine->unWrap(a->len, getTextLine(a->cursor.y),a->cursor.x); |
2473 | 2473 | ||
2474 | buffer->changeLine(a->cursor.y - 1); | 2474 | buffer->changeLine(a->cursor.y - 1); |
2475 | buffer->changeLine(a->cursor.y); | 2475 | buffer->changeLine(a->cursor.y); |
2476 | 2476 | ||
2477 | tagLine(a->cursor.y - 1); | 2477 | tagLine(a->cursor.y - 1); |
2478 | tagLine(a->cursor.y); | 2478 | tagLine(a->cursor.y); |
2479 | 2479 | ||
2480 | a->action = KateAction::wordWrap; | 2480 | a->action = KateAction::wordWrap; |
2481 | } | 2481 | } |
2482 | 2482 | ||
2483 | void KateDocument::doNewLine(KateAction *a) { | 2483 | void KateDocument::doNewLine(KateAction *a) { |
2484 | TextLine::Ptr textLine, newLine; | 2484 | TextLine::Ptr textLine, newLine; |
2485 | 2485 | ||
2486 | textLine = getTextLine(a->cursor.y); | 2486 | textLine = getTextLine(a->cursor.y); |
2487 | newLine = new TextLine(textLine->getRawAttr(), textLine->getContext()); | 2487 | newLine = new TextLine(textLine->getRawAttr(), textLine->getContext()); |
2488 | textLine->wrap(newLine,a->cursor.x); | 2488 | textLine->wrap(newLine,a->cursor.x); |
2489 | 2489 | ||
2490 | buffer->insertLine(a->cursor.y + 1, newLine); | 2490 | buffer->insertLine(a->cursor.y + 1, newLine); |
2491 | buffer->changeLine(a->cursor.y); | 2491 | buffer->changeLine(a->cursor.y); |
2492 | 2492 | ||
2493 | insLine(a->cursor.y + 1); | 2493 | insLine(a->cursor.y + 1); |
2494 | tagLine(a->cursor.y); | 2494 | tagLine(a->cursor.y); |
2495 | tagLine(a->cursor.y + 1); | 2495 | tagLine(a->cursor.y + 1); |
2496 | if (selectEnd == a->cursor.y) selectEnd++;//addSelection(a->cursor.y + 1); | 2496 | if (selectEnd == a->cursor.y) selectEnd++;//addSelection(a->cursor.y + 1); |
2497 | 2497 | ||
2498 | a->action = KateAction::delLine; | 2498 | a->action = KateAction::delLine; |
2499 | } | 2499 | } |
2500 | 2500 | ||
2501 | void KateDocument::doDelLine(KateAction *a) { | 2501 | void KateDocument::doDelLine(KateAction *a) { |
2502 | TextLine::Ptr textLine, nextLine; | 2502 | TextLine::Ptr textLine, nextLine; |
2503 | 2503 | ||
2504 | textLine = getTextLine(a->cursor.y); | 2504 | textLine = getTextLine(a->cursor.y); |
2505 | nextLine = getTextLine(a->cursor.y+1); | 2505 | nextLine = getTextLine(a->cursor.y+1); |
2506 | // textLine->setLength(a->cursor.x); | 2506 | // textLine->setLength(a->cursor.x); |
2507 | textLine->unWrap(a->cursor.x, nextLine,nextLine->length()); | 2507 | textLine->unWrap(a->cursor.x, nextLine,nextLine->length()); |
2508 | textLine->setContext(nextLine->getContext()); | 2508 | textLine->setContext(nextLine->getContext()); |
2509 | if (longestLine == nextLine) longestLine = 0L; | 2509 | if (longestLine == nextLine) longestLine = 0L; |
2510 | 2510 | ||
2511 | buffer->changeLine(a->cursor.y); | 2511 | buffer->changeLine(a->cursor.y); |
2512 | buffer->removeLine(a->cursor.y+1); | 2512 | buffer->removeLine(a->cursor.y+1); |
2513 | 2513 | ||
2514 | tagLine(a->cursor.y); | 2514 | tagLine(a->cursor.y); |
2515 | delLine(a->cursor.y + 1); | 2515 | delLine(a->cursor.y + 1); |
2516 | 2516 | ||
2517 | a->action = KateAction::newLine; | 2517 | a->action = KateAction::newLine; |
2518 | } | 2518 | } |
2519 | 2519 | ||
2520 | void KateDocument::doInsLine(KateAction *a) { | 2520 | void KateDocument::doInsLine(KateAction *a) { |
2521 | 2521 | ||
2522 | buffer->insertLine(a->cursor.y, new TextLine()); | 2522 | buffer->insertLine(a->cursor.y, new TextLine()); |
2523 | 2523 | ||
2524 | insLine(a->cursor.y); | 2524 | insLine(a->cursor.y); |
2525 | 2525 | ||
2526 | a->action = KateAction::killLine; | 2526 | a->action = KateAction::killLine; |
2527 | } | 2527 | } |
2528 | 2528 | ||
2529 | void KateDocument::doKillLine(KateAction *a) { | 2529 | void KateDocument::doKillLine(KateAction *a) { |
2530 | TextLine::Ptr textLine = getTextLine(a->cursor.y); | 2530 | TextLine::Ptr textLine = getTextLine(a->cursor.y); |
2531 | if (longestLine == textLine) longestLine = 0L; | 2531 | if (longestLine == textLine) longestLine = 0L; |
2532 | 2532 | ||
2533 | buffer->removeLine(a->cursor.y); | 2533 | buffer->removeLine(a->cursor.y); |
2534 | 2534 | ||
2535 | delLine(a->cursor.y); | 2535 | delLine(a->cursor.y); |
2536 | tagLine(a->cursor.y); | 2536 | tagLine(a->cursor.y); |
2537 | 2537 | ||
2538 | a->action = KateAction::insLine; | 2538 | a->action = KateAction::insLine; |
2539 | } | 2539 | } |
2540 | 2540 | ||
2541 | void KateDocument::newUndo() { | 2541 | void KateDocument::newUndo() { |
2542 | KTextEditor::View *view; | 2542 | KTextEditor::View *view; |
2543 | int state; | 2543 | int state; |
2544 | 2544 | ||
2545 | state = 0; | 2545 | state = 0; |
2546 | if (currentUndo > 0) state |= 1; | 2546 | if (currentUndo > 0) state |= 1; |
2547 | if (currentUndo < (int) undoList.count()) state |= 2; | 2547 | if (currentUndo < (int) undoList.count()) state |= 2; |
2548 | undoState = state; | 2548 | undoState = state; |
2549 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { | 2549 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { |
2550 | emit static_cast<KateView *>( view )->newUndo(); | 2550 | emit static_cast<KateView *>( view )->newUndo(); |
2551 | } | 2551 | } |
2552 | } | 2552 | } |
2553 | 2553 | ||
2554 | void KateDocument::recordStart(VConfig &c, int newUndoType) { | 2554 | void KateDocument::recordStart(VConfig &c, int newUndoType) { |
2555 | recordStart(c.view, c.cursor, c.flags, newUndoType); | 2555 | recordStart(c.view, c.cursor, c.flags, newUndoType); |
2556 | } | 2556 | } |
2557 | 2557 | ||
2558 | void KateDocument::recordStart(KateView *, PointStruc &cursor, int flags, | 2558 | void KateDocument::recordStart(KateView *, PointStruc &cursor, int flags, |
2559 | int newUndoType, bool keepModal, bool mergeUndo) { | 2559 | int newUndoType, bool keepModal, bool mergeUndo) { |
2560 | 2560 | ||
2561 | KateActionGroup *g; | 2561 | KateActionGroup *g; |
2562 | 2562 | ||
2563 | // if (newUndoType == KateActionGroup::ugNone) { | 2563 | // if (newUndoType == KateActionGroup::ugNone) { |
2564 | // only a bug would cause this | 2564 | // only a bug would cause this |
2565 | //why should someone do this? we can't prevent all programming errors :) (jochen whilhelmy) | 2565 | //why should someone do this? we can't prevent all programming errors :) (jochen whilhelmy) |
2566 | // debug("KateDocument::recordStart() called with no undo group type!"); | 2566 | // debug("KateDocument::recordStart() called with no undo group type!"); |
2567 | // return; | 2567 | // return; |
2568 | // } | 2568 | // } |
2569 | 2569 | ||
2570 | if (!keepModal) setPseudoModal(0L); | 2570 | if (!keepModal) setPseudoModal(0L); |
2571 | 2571 | ||
2572 | //i optimized the group undo stuff a bit (jochen wilhelmy) | 2572 | //i optimized the group undo stuff a bit (jochen wilhelmy) |
2573 | // recordReset() is not needed any more | 2573 | // recordReset() is not needed any more |
2574 | g = undoList.getLast(); | 2574 | g = undoList.getLast(); |
2575 | if (g != 0L && ((undoCount < 1024 && flags & KateView::cfGroupUndo | 2575 | if (g != 0L && ((undoCount < 1024 && flags & KateView::cfGroupUndo |
2576 | && g->end.x == cursor.x && g->end.y == cursor.y) || mergeUndo)) { | 2576 | && g->end.x == cursor.x && g->end.y == cursor.y) || mergeUndo)) { |
2577 | 2577 | ||
2578 | //undo grouping : same actions are put into one undo step | 2578 | //undo grouping : same actions are put into one undo step |
2579 | //precondition : new action starts where old stops or mergeUndo flag | 2579 | //precondition : new action starts where old stops or mergeUndo flag |
2580 | if (g->undoType == newUndoType | 2580 | if (g->undoType == newUndoType |
2581 | || (g->undoType == KateActionGroup::ugInsChar | 2581 | || (g->undoType == KateActionGroup::ugInsChar |
2582 | && newUndoType == KateActionGroup::ugInsLine) | 2582 | && newUndoType == KateActionGroup::ugInsLine) |
2583 | || (g->undoType == KateActionGroup::ugDelChar | 2583 | || (g->undoType == KateActionGroup::ugDelChar |
2584 | && newUndoType == KateActionGroup::ugDelLine)) { | 2584 | && newUndoType == KateActionGroup::ugDelLine)) { |
2585 | 2585 | ||
2586 | undoCount++; | 2586 | undoCount++; |
2587 | if (g->undoType != newUndoType) undoCount = 0xffffff; | 2587 | if (g->undoType != newUndoType) undoCount = 0xffffff; |
2588 | return; | 2588 | return; |
2589 | } | 2589 | } |
2590 | } | 2590 | } |
2591 | undoCount = 0; | 2591 | undoCount = 0; |
2592 | /* | 2592 | /* |
2593 | if (undoView != view) { | 2593 | if (undoView != view) { |
2594 | // always kill the current undo group if the editing view changes | 2594 | // always kill the current undo group if the editing view changes |
2595 | recordReset(); | 2595 | recordReset(); |
2596 | undoType = newUndoType; | 2596 | undoType = newUndoType; |
2597 | } else if (newUndoType == undoType) { | 2597 | } else if (newUndoType == undoType) { |
2598 | printf("bla!!!\n"); | 2598 | printf("bla!!!\n"); |
2599 | // same as current type, keep using it | 2599 | // same as current type, keep using it |
2600 | return; | 2600 | return; |
2601 | } else if ( (undoType == KateActionGroup::ugInsChar && newUndoType == KateActionGroup::ugInsLine) || | 2601 | } else if ( (undoType == KateActionGroup::ugInsChar && newUndoType == KateActionGroup::ugInsLine) || |
2602 | (undoType == KateActionGroup::ugDelChar && newUndoType == KateActionGroup::ugDelLine) ) { | 2602 | (undoType == KateActionGroup::ugDelChar && newUndoType == KateActionGroup::ugDelLine) ) { |
2603 | // some type combinations can run together... | 2603 | // some type combinations can run together... |
2604 | undoType += 1000; | 2604 | undoType += 1000; |
2605 | return; | 2605 | return; |
2606 | } else { | 2606 | } else { |
2607 | recordReset(); | 2607 | recordReset(); |
2608 | undoType = newUndoType; | 2608 | undoType = newUndoType; |
2609 | } | 2609 | } |
2610 | 2610 | ||
2611 | undoView = view; | 2611 | undoView = view; |
2612 | */ | 2612 | */ |
2613 | while ((int) undoList.count() > currentUndo) undoList.removeLast(); | 2613 | while ((int) undoList.count() > currentUndo) undoList.removeLast(); |
2614 | while ((int) undoList.count() > undoSteps) { | 2614 | while ((int) undoList.count() > undoSteps) { |
2615 | undoList.removeFirst(); | 2615 | undoList.removeFirst(); |
2616 | currentUndo--; | 2616 | currentUndo--; |
2617 | } | 2617 | } |
2618 | 2618 | ||
2619 | g = new KateActionGroup(cursor, newUndoType); | 2619 | g = new KateActionGroup(cursor, newUndoType); |
2620 | undoList.append(g); | 2620 | undoList.append(g); |
2621 | // currentUndo++; | 2621 | // currentUndo++; |
2622 | 2622 | ||
2623 | tagEnd = 0; | 2623 | tagEnd = 0; |
2624 | tagStart = 0xffffff; | 2624 | tagStart = 0xffffff; |
2625 | } | 2625 | } |
2626 | 2626 | ||
2627 | void KateDocument::recordAction(KateAction::Action action, PointStruc &cursor) { | 2627 | void KateDocument::recordAction(KateAction::Action action, PointStruc &cursor) { |
2628 | KateAction *a; | 2628 | KateAction *a; |
2629 | 2629 | ||
2630 | a = new KateAction(action, cursor); | 2630 | a = new KateAction(action, cursor); |
2631 | doAction(a); | 2631 | doAction(a); |
2632 | undoList.getLast()->insertAction(a); | 2632 | undoList.getLast()->insertAction(a); |
2633 | } | 2633 | } |
2634 | 2634 | ||
2635 | void KateDocument::recordInsert(VConfig &c, const QString &text) { | 2635 | void KateDocument::recordInsert(VConfig &c, const QString &text) { |
2636 | recordReplace(c, 0, text); | 2636 | recordReplace(c, 0, text); |
2637 | } | 2637 | } |
2638 | 2638 | ||
2639 | void KateDocument::recordReplace(VConfig &c, int len, const QString &text) { | 2639 | void KateDocument::recordReplace(VConfig &c, int len, const QString &text) { |
2640 | if (c.cursor.x > 0 && !(c.flags & KateView::cfSpaceIndent)) { | 2640 | if (c.cursor.x > 0 && !(c.flags & KateView::cfSpaceIndent)) { |
2641 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 2641 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
2642 | if (textLine->length() == 0) { | 2642 | if (textLine->length() == 0) { |
2643 | QString s = tabString(c.cursor.x, tabChars); | 2643 | QString s = tabString(c.cursor.x, tabChars); |
2644 | int len = s.length(); | 2644 | int len = s.length(); |
2645 | s += text; | 2645 | s += text; |
2646 | c.cursor.x = 0; | 2646 | c.cursor.x = 0; |
2647 | recordReplace(c.cursor, len, s); | 2647 | recordReplace(c.cursor, len, s); |
2648 | c.cursor.x = len; | 2648 | c.cursor.x = len; |
2649 | return; | 2649 | return; |
2650 | } | 2650 | } |
2651 | } | 2651 | } |
2652 | recordReplace(c.cursor, len, text); | 2652 | recordReplace(c.cursor, len, text); |
2653 | } | 2653 | } |
2654 | 2654 | ||
2655 | void KateDocument::recordInsert(PointStruc &cursor, const QString &text) { | 2655 | void KateDocument::recordInsert(PointStruc &cursor, const QString &text) { |
2656 | recordReplace(cursor, 0, text); | 2656 | recordReplace(cursor, 0, text); |
2657 | } | 2657 | } |
2658 | 2658 | ||
2659 | void KateDocument::recordDelete(PointStruc &cursor, int len) { | 2659 | void KateDocument::recordDelete(PointStruc &cursor, int len) { |
2660 | recordReplace(cursor, len, QString::null); | 2660 | recordReplace(cursor, len, QString::null); |
2661 | } | 2661 | } |
2662 | 2662 | ||
2663 | void KateDocument::recordReplace(PointStruc &cursor, int len, const QString &text) { | 2663 | void KateDocument::recordReplace(PointStruc &cursor, int len, const QString &text) { |
2664 | KateAction *a; | 2664 | KateAction *a; |
2665 | TextLine::Ptr textLine; | 2665 | TextLine::Ptr textLine; |
2666 | int l; | 2666 | int l; |
2667 | 2667 | ||
diff --git a/noncore/comm/keypebble/krfbdecoder.cpp b/noncore/comm/keypebble/krfbdecoder.cpp index 837fcc5..27ae101 100644 --- a/noncore/comm/keypebble/krfbdecoder.cpp +++ b/noncore/comm/keypebble/krfbdecoder.cpp | |||
@@ -1,831 +1,831 @@ | |||
1 | #include "krfbconnection.h" | 1 | #include "krfbconnection.h" |
2 | #include "krfbserverinfo.h" | 2 | #include "krfbserverinfo.h" |
3 | #include "krfbdecoder.h" | 3 | #include "krfbdecoder.h" |
4 | #include "krfbbuffer.h" | 4 | #include "krfbbuffer.h" |
5 | 5 | ||
6 | /* OPIE */ | 6 | /* OPIE */ |
7 | #include <opie2/odebug.h> | 7 | #include <opie2/odebug.h> |
8 | using namespace Opie::Core; | 8 | using namespace Opie::Core; |
9 | 9 | ||
10 | /* QT */ | 10 | /* QT */ |
11 | #include <qpixmap.h> | 11 | #include <qpixmap.h> |
12 | 12 | ||
13 | /* STD */ | 13 | /* STD */ |
14 | #include <assert.h> | 14 | #include <assert.h> |
15 | 15 | ||
16 | // | 16 | // |
17 | // Endian stuff | 17 | // Endian stuff |
18 | // | 18 | // |
19 | //#ifndef OPIE_NO_DEBUG | 19 | //#ifndef OPIE_NO_DEBUG |
20 | const int endianTest = 1; | 20 | const int endianTest = 1; |
21 | //#endif | 21 | //#endif |
22 | 22 | ||
23 | #define Swap16IfLE(s) \ | 23 | #define Swap16IfLE(s) \ |
24 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) | 24 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) |
25 | 25 | ||
26 | #define Swap32IfLE(l) \ | 26 | #define Swap32IfLE(l) \ |
27 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ | 27 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ |
28 | (((l) & 0x00ff0000) >> 8) | \ | 28 | (((l) & 0x00ff0000) >> 8) | \ |
29 | (((l) & 0x0000ff00) << 8) | \ | 29 | (((l) & 0x0000ff00) << 8) | \ |
30 | (((l) & 0x000000ff) << 24)) : (l)) | 30 | (((l) & 0x000000ff) << 24)) : (l)) |
31 | 31 | ||
32 | // | 32 | // |
33 | // The lengths of the messages we need to wait for | 33 | // The lengths of the messages we need to wait for |
34 | // | 34 | // |
35 | const int ServerInitLength = 24; | 35 | const int ServerInitLength = 24; |
36 | const int UpdateHeaderLength = 4; | 36 | const int UpdateHeaderLength = 4; |
37 | const int RectHeaderLength = 12; | 37 | const int RectHeaderLength = 12; |
38 | const int RectChunkSize = 4; | 38 | const int RectChunkSize = 4; |
39 | const int CopyRectPosLength = 4; | 39 | const int CopyRectPosLength = 4; |
40 | const int ServerCutLenLength = 7; | 40 | const int ServerCutLenLength = 7; |
41 | 41 | ||
42 | // | 42 | // |
43 | // Client -> Server Message Identifiers | 43 | // Client -> Server Message Identifiers |
44 | // | 44 | // |
45 | static CARD8 SetPixelFormatId = 0; | 45 | static CARD8 SetPixelFormatId = 0; |
46 | //static CARD8 FixColourMapEntriesId = 1; // Not used | 46 | //static CARD8 FixColourMapEntriesId = 1; // Not used |
47 | static CARD8 SetEncodingsId = 2; | 47 | static CARD8 SetEncodingsId = 2; |
48 | static CARD8 UpdateRequestId = 3; | 48 | static CARD8 UpdateRequestId = 3; |
49 | static CARD8 KeyEventId = 4; | 49 | static CARD8 KeyEventId = 4; |
50 | static CARD8 PointerEventId = 5; | 50 | static CARD8 PointerEventId = 5; |
51 | static CARD8 ClientCutTextId = 6; | 51 | static CARD8 ClientCutTextId = 6; |
52 | 52 | ||
53 | // | 53 | // |
54 | // Server -> Client Message Identifiers | 54 | // Server -> Client Message Identifiers |
55 | // | 55 | // |
56 | static CARD8 UpdateId = 0; | 56 | static CARD8 UpdateId = 0; |
57 | static CARD8 BellId = 2; | 57 | static CARD8 BellId = 2; |
58 | static CARD8 ServerCutId = 3; | 58 | static CARD8 ServerCutId = 3; |
59 | 59 | ||
60 | // | 60 | // |
61 | // Encoding identifiers | 61 | // Encoding identifiers |
62 | // | 62 | // |
63 | static CARD32 RawEncoding = Swap32IfLE( 0 ); | 63 | static CARD32 RawEncoding = Swap32IfLE( 0 ); |
64 | static CARD32 CopyRectEncoding = Swap32IfLE(1 ); | 64 | static CARD32 CopyRectEncoding = Swap32IfLE(1 ); |
65 | static CARD32 RreEncoding = Swap32IfLE( 2 ); | 65 | static CARD32 RreEncoding = Swap32IfLE( 2 ); |
66 | static CARD32 CorreEncoding = Swap32IfLE( 4 ); | 66 | static CARD32 CorreEncoding = Swap32IfLE( 4 ); |
67 | static CARD32 HexTileEncoding = Swap32IfLE( 5 ); | 67 | static CARD32 HexTileEncoding = Swap32IfLE( 5 ); |
68 | 68 | ||
69 | static struct { | 69 | static struct { |
70 | int keysym; | 70 | int keysym; |
71 | int keycode; | 71 | int keycode; |
72 | } keyMap[] = { | 72 | } keyMap[] = { |
73 | { 0xff08, Qt::Key_Backspace }, | 73 | { 0xff08, Qt::Key_Backspace }, |
74 | { 0xff09, Qt::Key_Tab }, | 74 | { 0xff09, Qt::Key_Tab }, |
75 | { 0xff0d, Qt::Key_Return }, | 75 | { 0xff0d, Qt::Key_Return }, |
76 | { 0xff1b, Qt::Key_Escape }, | 76 | { 0xff1b, Qt::Key_Escape }, |
77 | { 0xff63, Qt::Key_Insert }, | 77 | { 0xff63, Qt::Key_Insert }, |
78 | { 0xffff, Qt::Key_Delete }, | 78 | { 0xffff, Qt::Key_Delete }, |
79 | { 0xff50, Qt::Key_Home }, | 79 | { 0xff50, Qt::Key_Home }, |
80 | { 0xff57, Qt::Key_End }, | 80 | { 0xff57, Qt::Key_End }, |
81 | { 0xff55, Qt::Key_Prior }, | 81 | { 0xff55, Qt::Key_Prior }, |
82 | { 0xff56, Qt::Key_Next }, | 82 | { 0xff56, Qt::Key_Next }, |
83 | { 0xff51, Qt::Key_Left }, | 83 | { 0xff51, Qt::Key_Left }, |
84 | { 0xff52, Qt::Key_Up }, | 84 | { 0xff52, Qt::Key_Up }, |
85 | { 0xff53, Qt::Key_Right }, | 85 | { 0xff53, Qt::Key_Right }, |
86 | { 0xff54, Qt::Key_Down }, | 86 | { 0xff54, Qt::Key_Down }, |
87 | { 0xffbe, Qt::Key_F1 }, | 87 | { 0xffbe, Qt::Key_F1 }, |
88 | { 0xffbf, Qt::Key_F2 }, | 88 | { 0xffbf, Qt::Key_F2 }, |
89 | { 0xffc0, Qt::Key_F3 }, | 89 | { 0xffc0, Qt::Key_F3 }, |
90 | { 0xffc1, Qt::Key_F4 }, | 90 | { 0xffc1, Qt::Key_F4 }, |
91 | { 0xffc2, Qt::Key_F5 }, | 91 | { 0xffc2, Qt::Key_F5 }, |
92 | { 0xffc3, Qt::Key_F6 }, | 92 | { 0xffc3, Qt::Key_F6 }, |
93 | { 0xffc4, Qt::Key_F7 }, | 93 | { 0xffc4, Qt::Key_F7 }, |
94 | { 0xffc5, Qt::Key_F8 }, | 94 | { 0xffc5, Qt::Key_F8 }, |
95 | { 0xffc6, Qt::Key_F9 }, | 95 | { 0xffc6, Qt::Key_F9 }, |
96 | { 0xffc7, Qt::Key_F10 }, | 96 | { 0xffc7, Qt::Key_F10 }, |
97 | { 0xffc8, Qt::Key_F11 }, | 97 | { 0xffc8, Qt::Key_F11 }, |
98 | { 0xffc9, Qt::Key_F12 }, | 98 | { 0xffc9, Qt::Key_F12 }, |
99 | { 0xffe1, Qt::Key_Shift }, | 99 | { 0xffe1, Qt::Key_Shift }, |
100 | { 0xffe2, Qt::Key_Shift }, | 100 | { 0xffe2, Qt::Key_Shift }, |
101 | { 0xffe3, Qt::Key_Control }, | 101 | { 0xffe3, Qt::Key_Control }, |
102 | { 0xffe4, Qt::Key_Control }, | 102 | { 0xffe4, Qt::Key_Control }, |
103 | { 0xffe7, Qt::Key_Meta }, | 103 | { 0xffe7, Qt::Key_Meta }, |
104 | { 0xffe8, Qt::Key_Meta }, | 104 | { 0xffe8, Qt::Key_Meta }, |
105 | { 0xffe9, Qt::Key_Alt }, | 105 | { 0xffe9, Qt::Key_Alt }, |
106 | { 0xffea, Qt::Key_Alt }, | 106 | { 0xffea, Qt::Key_Alt }, |
107 | { 0, 0 } | 107 | { 0, 0 } |
108 | }; | 108 | }; |
109 | 109 | ||
110 | 110 | ||
111 | KRFBDecoder::KRFBDecoder( KRFBConnection *con ) | 111 | KRFBDecoder::KRFBDecoder( KRFBConnection *con ) |
112 | : QObject( con, "RFB Decoder" ) | 112 | : QObject( con, "RFB Decoder" ) |
113 | { | 113 | { |
114 | assert( con ); | 114 | assert( con ); |
115 | assert( con->state() == KRFBConnection::Connected ); | 115 | assert( con->state() == KRFBConnection::Connected ); |
116 | 116 | ||
117 | this->con = con; | 117 | this->con = con; |
118 | this->buf = 0; | 118 | this->buf = 0; |
119 | this->info = 0; | 119 | this->info = 0; |
120 | this->format = 0; | 120 | this->format = 0; |
121 | this->buttonMask = 0; | 121 | this->buttonMask = 0; |
122 | currentState = Idle; | 122 | currentState = Idle; |
123 | } | 123 | } |
124 | 124 | ||
125 | KRFBDecoder::~KRFBDecoder() | 125 | KRFBDecoder::~KRFBDecoder() |
126 | { | 126 | { |
127 | if ( info ) | 127 | if ( info ) |
128 | delete info; | 128 | delete info; |
129 | if ( format ) | 129 | if ( format ) |
130 | delete format; | 130 | delete format; |
131 | } | 131 | } |
132 | 132 | ||
133 | void KRFBDecoder::start() | 133 | void KRFBDecoder::start() |
134 | { | 134 | { |
135 | sendClientInit(); | 135 | sendClientInit(); |
136 | } | 136 | } |
137 | 137 | ||
138 | void KRFBDecoder::sendClientInit() | 138 | void KRFBDecoder::sendClientInit() |
139 | { | 139 | { |
140 | con->write( &( con->options()->shared ), 1 ); | 140 | con->write( &( con->options()->shared ), 1 ); |
141 | 141 | ||
142 | // Wait for server init | 142 | // Wait for server init |
143 | owarn << "Waiting for server init" << oendl; | 143 | owarn << "Waiting for server init" << oendl; |
144 | 144 | ||
145 | static QString statusMsg = tr( "Waiting for server initialization..." ); | 145 | static QString statusMsg = tr( "Waiting for server initialization..." ); |
146 | emit status( statusMsg ); | 146 | emit status( statusMsg ); |
147 | 147 | ||
148 | currentState = AwaitingServerInit; | 148 | currentState = AwaitingServerInit; |
149 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); | 149 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); |
150 | con->waitForData( ServerInitLength ); | 150 | con->waitForData( ServerInitLength ); |
151 | } | 151 | } |
152 | 152 | ||
153 | void KRFBDecoder::gotServerInit() | 153 | void KRFBDecoder::gotServerInit() |
154 | { | 154 | { |
155 | owarn << "Got server init" << oendl; | 155 | owarn << "Got server init" << oendl; |
156 | disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); | 156 | disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); |
157 | 157 | ||
158 | if ( info ) | 158 | if ( info ) |
159 | delete info; | 159 | delete info; |
160 | info = new KRFBServerInfo; | 160 | info = new KRFBServerInfo; |
161 | CHECK_PTR( info ); | 161 | CHECK_PTR( info ); |
162 | 162 | ||
163 | con->read( &(info->width), 2 ); | 163 | con->read( &(info->width), 2 ); |
164 | info->width = Swap16IfLE( info->width ); | 164 | info->width = Swap16IfLE( info->width ); |
165 | con->read( &info->height, 2 ); | 165 | con->read( &info->height, 2 ); |
166 | info->height = Swap16IfLE( info->height ); | 166 | info->height = Swap16IfLE( info->height ); |
167 | 167 | ||
168 | con->read( &(info->bpp), 1 ); | 168 | con->read( &(info->bpp), 1 ); |
169 | con->read( &(info->depth), 1 ); | 169 | con->read( &(info->depth), 1 ); |
170 | con->read( &(info->bigEndian), 1 ); | 170 | con->read( &(info->bigEndian), 1 ); |
171 | con->read( &(info->trueColor), 1 ); | 171 | con->read( &(info->trueColor), 1 ); |
172 | 172 | ||
173 | con->read( &(info->redMax), 2 ); | 173 | con->read( &(info->redMax), 2 ); |
174 | info->redMax = Swap16IfLE( info->redMax ); | 174 | info->redMax = Swap16IfLE( info->redMax ); |
175 | con->read( &(info->greenMax), 2 ); | 175 | con->read( &(info->greenMax), 2 ); |
176 | info->greenMax = Swap16IfLE( info->greenMax ); | 176 | info->greenMax = Swap16IfLE( info->greenMax ); |
177 | con->read( &(info->blueMax), 2 ); | 177 | con->read( &(info->blueMax), 2 ); |
178 | info->blueMax = Swap16IfLE( info->blueMax ); | 178 | info->blueMax = Swap16IfLE( info->blueMax ); |
179 | 179 | ||
180 | con->read( &(info->redShift), 1 ); | 180 | con->read( &(info->redShift), 1 ); |
181 | con->read( &(info->greenShift), 1 ); | 181 | con->read( &(info->greenShift), 1 ); |
182 | con->read( &(info->blueShift), 1 ); | 182 | con->read( &(info->blueShift), 1 ); |
183 | 183 | ||
184 | con->read( info->padding, 3 ); | 184 | con->read( info->padding, 3 ); |
185 | 185 | ||
186 | con->read( &(info->nameLength), 4 ); | 186 | con->read( &(info->nameLength), 4 ); |
187 | info->nameLength = Swap32IfLE( info->nameLength ); | 187 | info->nameLength = Swap32IfLE( info->nameLength ); |
188 | 188 | ||
189 | owarn << "Width = " << info->width << ", Height = " << info->height << "" << oendl; | 189 | owarn << "Width = " << info->width << ", Height = " << info->height << "" << oendl; |
190 | owarn << "Bpp = " << info->bpp << ", Depth = " << info->depth << ", Big = " << info->bigEndian | 190 | owarn << "Bpp = " << info->bpp << ", Depth = " << info->depth << ", Big = " << info->bigEndian |
191 | << ", True = " << info->trueColor << oendl; | 191 | << ", True = " << info->trueColor << oendl; |
192 | owarn << "RedMax = " << info->redMax << ", GreenMax = " << info->greenMax << ", BlueMax = " << info->blueMax << oendl; | 192 | owarn << "RedMax = " << info->redMax << ", GreenMax = " << info->greenMax << ", BlueMax = " << info->blueMax << oendl; |
193 | owarn << "RedShift = " << info->redShift << ", GreenShift = " << info->greenShift | 193 | owarn << "RedShift = " << info->redShift << ", GreenShift = " << info->greenShift |
194 | << ", BlueShift = " << info-> blueShift << oendl; | 194 | << ", BlueShift = " << info-> blueShift << oendl; |
195 | 195 | ||
196 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); | 196 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); |
197 | 197 | ||
198 | // Wait for desktop name | 198 | // Wait for desktop name |
199 | owarn << "Waiting for desktop name" << oendl; | 199 | owarn << "Waiting for desktop name" << oendl; |
200 | 200 | ||
201 | static QString statusMsg = tr( "Waiting for desktop name..." ); | 201 | static QString statusMsg = tr( "Waiting for desktop name..." ); |
202 | emit status( statusMsg ); | 202 | emit status( statusMsg ); |
203 | 203 | ||
204 | currentState = AwaitingDesktopName; | 204 | currentState = AwaitingDesktopName; |
205 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); | 205 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); |
206 | con->waitForData( info->nameLength ); | 206 | con->waitForData( info->nameLength ); |
207 | } | 207 | } |
208 | 208 | ||
209 | void KRFBDecoder::gotDesktopName() | 209 | void KRFBDecoder::gotDesktopName() |
210 | { | 210 | { |
211 | assert( info ); | 211 | assert( info ); |
212 | assert( currentState == AwaitingDesktopName ); | 212 | assert( currentState == AwaitingDesktopName ); |
213 | 213 | ||
214 | owarn << "Got desktop name" << oendl; | 214 | owarn << "Got desktop name" << oendl; |
215 | 215 | ||
216 | disconnect( con, SIGNAL( gotEnoughData() ), | 216 | disconnect( con, SIGNAL( gotEnoughData() ), |
217 | this, SLOT( gotDesktopName() ) ); | 217 | this, SLOT( gotDesktopName() ) ); |
218 | 218 | ||
219 | char *buf = new char[ info->nameLength + 1 ]; | 219 | char *buf = new char[ info->nameLength + 1 ]; |
220 | CHECK_PTR( buf ); | 220 | CHECK_PTR( buf ); |
221 | 221 | ||
222 | con->read( buf, info->nameLength ); | 222 | con->read( buf, info->nameLength ); |
223 | buf[ info->nameLength ] = '\0'; | 223 | buf[ info->nameLength ] = '\0'; |
224 | info->name = buf; | 224 | info->name = buf; |
225 | 225 | ||
226 | owarn << "Desktop: " << info->name.latin1() << "" << oendl; | 226 | owarn << "Desktop: " << info->name.latin1() << "" << oendl; |
227 | 227 | ||
228 | delete buf; | 228 | delete [] buf; |
229 | 229 | ||
230 | // Get the format we'll really use and tell the server | 230 | // Get the format we'll really use and tell the server |
231 | decidePixelFormat(); | 231 | decidePixelFormat(); |
232 | sendPixelFormat(); | 232 | sendPixelFormat(); |
233 | sendAllowedEncodings(); | 233 | sendAllowedEncodings(); |
234 | currentState = Idle; | 234 | currentState = Idle; |
235 | 235 | ||
236 | QString msg; | 236 | QString msg; |
237 | msg = tr( "Connected to %1" ); | 237 | msg = tr( "Connected to %1" ); |
238 | msg = msg.arg( info->name ); | 238 | msg = msg.arg( info->name ); |
239 | emit status( msg ); | 239 | emit status( msg ); |
240 | 240 | ||
241 | sendUpdateRequest( false ); | 241 | sendUpdateRequest( false ); |
242 | } | 242 | } |
243 | 243 | ||
244 | void KRFBDecoder::decidePixelFormat() | 244 | void KRFBDecoder::decidePixelFormat() |
245 | { | 245 | { |
246 | assert( info ); | 246 | assert( info ); |
247 | 247 | ||
248 | if ( format ) | 248 | if ( format ) |
249 | delete format; | 249 | delete format; |
250 | format = new KRFBPixelFormat; | 250 | format = new KRFBPixelFormat; |
251 | CHECK_PTR( format ); | 251 | CHECK_PTR( format ); |
252 | 252 | ||
253 | // What depth do we want? | 253 | // What depth do we want? |
254 | // | 254 | // |
255 | // We'll use the minimum of the remote and local depths, UNLESS an | 255 | // We'll use the minimum of the remote and local depths, UNLESS an |
256 | // eight bit session has been specifically requested by the user. | 256 | // eight bit session has been specifically requested by the user. |
257 | int screenDepth = QPixmap::defaultDepth(); | 257 | int screenDepth = QPixmap::defaultDepth(); |
258 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; | 258 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; |
259 | int chosenDepth; | 259 | int chosenDepth; |
260 | 260 | ||
261 | if ( con->options()->colors256 ) | 261 | if ( con->options()->colors256 ) |
262 | chosenDepth = 8; | 262 | chosenDepth = 8; |
263 | else | 263 | else |
264 | chosenDepth = bestDepth; | 264 | chosenDepth = bestDepth; |
265 | 265 | ||
266 | owarn << "Screen depth=" << screenDepth << ", server depth=" << info->depth | 266 | owarn << "Screen depth=" << screenDepth << ", server depth=" << info->depth |
267 | << ", best depth=" << bestDepth << "eight bit " << con->options()->colors256 | 267 | << ", best depth=" << bestDepth << "eight bit " << con->options()->colors256 |
268 | << ", chosenDepth=" << chosenDepth << oendl; | 268 | << ", chosenDepth=" << chosenDepth << oendl; |
269 | 269 | ||
270 | format->depth = chosenDepth; | 270 | format->depth = chosenDepth; |
271 | 271 | ||
272 | // If we're using the servers native depth | 272 | // If we're using the servers native depth |
273 | if ( chosenDepth == info->depth ) { | 273 | if ( chosenDepth == info->depth ) { |
274 | // Use the servers native format | 274 | // Use the servers native format |
275 | format->bpp = info->bpp; | 275 | format->bpp = info->bpp; |
276 | // format->bigEndian = info->bigEndian; | 276 | // format->bigEndian = info->bigEndian; |
277 | format->bigEndian = true; | 277 | format->bigEndian = true; |
278 | format->trueColor = info->trueColor; | 278 | format->trueColor = info->trueColor; |
279 | format->redMax = info->redMax; | 279 | format->redMax = info->redMax; |
280 | format->greenMax = info->greenMax; | 280 | format->greenMax = info->greenMax; |
281 | format->blueMax = info->blueMax; | 281 | format->blueMax = info->blueMax; |
282 | format->redShift = info->redShift; | 282 | format->redShift = info->redShift; |
283 | format->greenShift = info->greenShift; | 283 | format->greenShift = info->greenShift; |
284 | format->blueShift = info->blueShift; | 284 | format->blueShift = info->blueShift; |
285 | } | 285 | } |
286 | else { | 286 | else { |
287 | if ( chosenDepth == 8 ) { | 287 | if ( chosenDepth == 8 ) { |
288 | format->bpp = 8; | 288 | format->bpp = 8; |
289 | format->bigEndian = true; | 289 | format->bigEndian = true; |
290 | format->trueColor = true; | 290 | format->trueColor = true; |
291 | format->redMax = 7; | 291 | format->redMax = 7; |
292 | format->greenMax = 7; | 292 | format->greenMax = 7; |
293 | format->blueMax = 3; | 293 | format->blueMax = 3; |
294 | format->redShift = 0; | 294 | format->redShift = 0; |
295 | format->greenShift = 3; | 295 | format->greenShift = 3; |
296 | format->blueShift = 6; | 296 | format->blueShift = 6; |
297 | } | 297 | } |
298 | } | 298 | } |
299 | 299 | ||
300 | format->redMax = Swap16IfLE( format->redMax ); | 300 | format->redMax = Swap16IfLE( format->redMax ); |
301 | format->greenMax = Swap16IfLE( format->greenMax ); | 301 | format->greenMax = Swap16IfLE( format->greenMax ); |
302 | format->blueMax = Swap16IfLE( format->blueMax ); | 302 | format->blueMax = Swap16IfLE( format->blueMax ); |
303 | } | 303 | } |
304 | 304 | ||
305 | void KRFBDecoder::sendPixelFormat() | 305 | void KRFBDecoder::sendPixelFormat() |
306 | { | 306 | { |
307 | static char padding[3]; | 307 | static char padding[3]; |
308 | con->write( &SetPixelFormatId, 1 ); | 308 | con->write( &SetPixelFormatId, 1 ); |
309 | con->write( padding, 3 ); | 309 | con->write( padding, 3 ); |
310 | 310 | ||
311 | con->write( &(format->bpp), 1 ); | 311 | con->write( &(format->bpp), 1 ); |
312 | con->write( &(format->depth), 1 ); | 312 | con->write( &(format->depth), 1 ); |
313 | con->write( &(format->bigEndian), 1 ); | 313 | con->write( &(format->bigEndian), 1 ); |
314 | con->write( &(format->trueColor), 1 ); | 314 | con->write( &(format->trueColor), 1 ); |
315 | 315 | ||
316 | con->write( &(format->redMax), 2 ); | 316 | con->write( &(format->redMax), 2 ); |
317 | con->write( &(format->greenMax), 2 ); | 317 | con->write( &(format->greenMax), 2 ); |
318 | con->write( &(format->blueMax), 2 ); | 318 | con->write( &(format->blueMax), 2 ); |
319 | 319 | ||
320 | con->write( &(format->redShift), 1 ); | 320 | con->write( &(format->redShift), 1 ); |
321 | con->write( &(format->greenShift), 1 ); | 321 | con->write( &(format->greenShift), 1 ); |
322 | con->write( &(format->blueShift), 1 ); | 322 | con->write( &(format->blueShift), 1 ); |
323 | con->write( format->padding, 3 ); // Padding | 323 | con->write( format->padding, 3 ); // Padding |
324 | } | 324 | } |
325 | 325 | ||
326 | void KRFBDecoder::sendAllowedEncodings() | 326 | void KRFBDecoder::sendAllowedEncodings() |
327 | { | 327 | { |
328 | static CARD8 padding[1]; | 328 | static CARD8 padding[1]; |
329 | con->write( &SetEncodingsId, 1 ); | 329 | con->write( &SetEncodingsId, 1 ); |
330 | con->write( padding, 1 ); | 330 | con->write( padding, 1 ); |
331 | 331 | ||
332 | CARD16 noEncodings = con->options()->encodings(); | 332 | CARD16 noEncodings = con->options()->encodings(); |
333 | noEncodings = Swap16IfLE( noEncodings ); | 333 | noEncodings = Swap16IfLE( noEncodings ); |
334 | con->write( &noEncodings, 2 ); | 334 | con->write( &noEncodings, 2 ); |
335 | 335 | ||
336 | if ( con->options()->corre ) | 336 | if ( con->options()->corre ) |
337 | con->write( &CorreEncoding, 4 ); | 337 | con->write( &CorreEncoding, 4 ); |
338 | if ( con->options()->hexTile ) | 338 | if ( con->options()->hexTile ) |
339 | con->write( &HexTileEncoding, 4 ); | 339 | con->write( &HexTileEncoding, 4 ); |
340 | if ( con->options()->rre ) | 340 | if ( con->options()->rre ) |
341 | con->write( &RreEncoding, 4 ); | 341 | con->write( &RreEncoding, 4 ); |
342 | if ( con->options()->copyrect ) | 342 | if ( con->options()->copyrect ) |
343 | con->write( &CopyRectEncoding, 4 ); | 343 | con->write( &CopyRectEncoding, 4 ); |
344 | // We always support this | 344 | // We always support this |
345 | con->write( &RawEncoding, 4 ); | 345 | con->write( &RawEncoding, 4 ); |
346 | } | 346 | } |
347 | 347 | ||
348 | void KRFBDecoder::sendUpdateRequest( bool incremental ) | 348 | void KRFBDecoder::sendUpdateRequest( bool incremental ) |
349 | { | 349 | { |
350 | if ( currentState != Idle ) | 350 | if ( currentState != Idle ) |
351 | return; | 351 | return; |
352 | 352 | ||
353 | con->write( &UpdateRequestId, 1 ); | 353 | con->write( &UpdateRequestId, 1 ); |
354 | con->write( &incremental, 1 ); | 354 | con->write( &incremental, 1 ); |
355 | 355 | ||
356 | static CARD16 x = 0, y = 0; | 356 | static CARD16 x = 0, y = 0; |
357 | static CARD16 w = Swap16IfLE( info->width ); | 357 | static CARD16 w = Swap16IfLE( info->width ); |
358 | static CARD16 h = Swap16IfLE( info->height ); | 358 | static CARD16 h = Swap16IfLE( info->height ); |
359 | 359 | ||
360 | con->write( &x, 2 ); | 360 | con->write( &x, 2 ); |
361 | con->write( &y, 2 ); | 361 | con->write( &y, 2 ); |
362 | con->write( &w, 2 ); | 362 | con->write( &w, 2 ); |
363 | con->write( &h, 2 ); | 363 | con->write( &h, 2 ); |
364 | 364 | ||
365 | // Now wait for the update | 365 | // Now wait for the update |
366 | currentState = AwaitingUpdate; | 366 | currentState = AwaitingUpdate; |
367 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 367 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
368 | con->waitForData( UpdateHeaderLength ); | 368 | con->waitForData( UpdateHeaderLength ); |
369 | } | 369 | } |
370 | 370 | ||
371 | void KRFBDecoder::gotUpdateHeader() | 371 | void KRFBDecoder::gotUpdateHeader() |
372 | { | 372 | { |
373 | assert( currentState == AwaitingUpdate ); | 373 | assert( currentState == AwaitingUpdate ); |
374 | 374 | ||
375 | // owarn << "Got update header" << oendl; | 375 | // owarn << "Got update header" << oendl; |
376 | 376 | ||
377 | disconnect( con, SIGNAL( gotEnoughData() ), | 377 | disconnect( con, SIGNAL( gotEnoughData() ), |
378 | this, SLOT( gotUpdateHeader() ) ); | 378 | this, SLOT( gotUpdateHeader() ) ); |
379 | 379 | ||
380 | CARD8 msgType; | 380 | CARD8 msgType; |
381 | con->read( &msgType, 1 ); | 381 | con->read( &msgType, 1 ); |
382 | 382 | ||
383 | if ( msgType != UpdateId ) { | 383 | if ( msgType != UpdateId ) { |
384 | // We might have a bell or server cut | 384 | // We might have a bell or server cut |
385 | if ( msgType == ServerCutId ) { | 385 | if ( msgType == ServerCutId ) { |
386 | oldState = currentState; | 386 | oldState = currentState; |
387 | gotServerCut(); | 387 | gotServerCut(); |
388 | } | 388 | } |
389 | else if ( msgType == BellId ) { | 389 | else if ( msgType == BellId ) { |
390 | oldState = currentState; | 390 | oldState = currentState; |
391 | gotBell(); | 391 | gotBell(); |
392 | } | 392 | } |
393 | else { | 393 | else { |
394 | int msg = msgType; | 394 | int msg = msgType; |
395 | QString protocolError = tr( "Protocol Error: Message Id %1 was " | 395 | QString protocolError = tr( "Protocol Error: Message Id %1 was " |
396 | "found when expecting an update " | 396 | "found when expecting an update " |
397 | "message." ).arg( msg ); | 397 | "message." ).arg( msg ); |
398 | currentState = Error; | 398 | currentState = Error; |
399 | emit error( protocolError ); | 399 | emit error( protocolError ); |
400 | } | 400 | } |
401 | return; | 401 | return; |
402 | } | 402 | } |
403 | 403 | ||
404 | CARD8 padding; | 404 | CARD8 padding; |
405 | con->read( &padding, 1 ); | 405 | con->read( &padding, 1 ); |
406 | 406 | ||
407 | con->read( &noRects, 2 ); | 407 | con->read( &noRects, 2 ); |
408 | noRects = Swap16IfLE( noRects ); | 408 | noRects = Swap16IfLE( noRects ); |
409 | 409 | ||
410 | // owarn << "Expecting " << noRects << " rects" << oendl; | 410 | // owarn << "Expecting " << noRects << " rects" << oendl; |
411 | 411 | ||
412 | // Now wait for the data | 412 | // Now wait for the data |
413 | currentState = AwaitingRectHeader; | 413 | currentState = AwaitingRectHeader; |
414 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 414 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
415 | con->waitForData( RectHeaderLength ); | 415 | con->waitForData( RectHeaderLength ); |
416 | } | 416 | } |
417 | 417 | ||
418 | void KRFBDecoder::gotRectHeader() | 418 | void KRFBDecoder::gotRectHeader() |
419 | { | 419 | { |
420 | assert( currentState == AwaitingRectHeader ); | 420 | assert( currentState == AwaitingRectHeader ); |
421 | 421 | ||
422 | // owarn << "Got rect header" << oendl; | 422 | // owarn << "Got rect header" << oendl; |
423 | 423 | ||
424 | disconnect( con, SIGNAL( gotEnoughData() ), | 424 | disconnect( con, SIGNAL( gotEnoughData() ), |
425 | this, SLOT( gotRectHeader() ) ); | 425 | this, SLOT( gotRectHeader() ) ); |
426 | 426 | ||
427 | con->read( &x, 2 ); | 427 | con->read( &x, 2 ); |
428 | x = Swap16IfLE( x ); | 428 | x = Swap16IfLE( x ); |
429 | con->read( &y, 2 ); | 429 | con->read( &y, 2 ); |
430 | y = Swap16IfLE( y ); | 430 | y = Swap16IfLE( y ); |
431 | 431 | ||
432 | con->read( &w, 2 ); | 432 | con->read( &w, 2 ); |
433 | w = Swap16IfLE( w ); | 433 | w = Swap16IfLE( w ); |
434 | con->read( &h, 2 ); | 434 | con->read( &h, 2 ); |
435 | h = Swap16IfLE( h ); | 435 | h = Swap16IfLE( h ); |
436 | 436 | ||
437 | con->read( &encoding, 4 ); | 437 | con->read( &encoding, 4 ); |
438 | 438 | ||
439 | // CARD32 encodingLocal = Swap32IfLE( encoding ); | 439 | // CARD32 encodingLocal = Swap32IfLE( encoding ); |
440 | // owarn << "Rect: x=" << x << ", y= " << y << ", w=" << w << ", h=" << h | 440 | // owarn << "Rect: x=" << x << ", y= " << y << ", w=" << w << ", h=" << h |
441 | // << ", encoding= " << encodingLocal << oendl; | 441 | // << ", encoding= " << encodingLocal << oendl; |
442 | 442 | ||
443 | // | 443 | // |
444 | // Each encoding needs to be handled differently. Some require | 444 | // Each encoding needs to be handled differently. Some require |
445 | // waiting for more data, but others like a copyrect do not. | 445 | // waiting for more data, but others like a copyrect do not. |
446 | // Our constants have already been byte swapped, so we use | 446 | // Our constants have already been byte swapped, so we use |
447 | // the remote value as is. | 447 | // the remote value as is. |
448 | // | 448 | // |
449 | if ( encoding == RawEncoding ) { | 449 | if ( encoding == RawEncoding ) { |
450 | // owarn << "Raw encoding" << oendl; | 450 | // owarn << "Raw encoding" << oendl; |
451 | handleRawRect(); | 451 | handleRawRect(); |
452 | } | 452 | } |
453 | else if ( encoding == CopyRectEncoding ) { | 453 | else if ( encoding == CopyRectEncoding ) { |
454 | // owarn << "CopyRect encoding" << oendl; | 454 | // owarn << "CopyRect encoding" << oendl; |
455 | handleCopyRect(); | 455 | handleCopyRect(); |
456 | } | 456 | } |
457 | else if ( encoding == RreEncoding ) { | 457 | else if ( encoding == RreEncoding ) { |
458 | owarn << "RRE encoding" << oendl; | 458 | owarn << "RRE encoding" << oendl; |
459 | handleRRERect(); | 459 | handleRRERect(); |
460 | } | 460 | } |
461 | else if ( encoding == CorreEncoding ) { | 461 | else if ( encoding == CorreEncoding ) { |
462 | owarn << "CoRRE encoding" << oendl; | 462 | owarn << "CoRRE encoding" << oendl; |
463 | handleCoRRERect(); | 463 | handleCoRRERect(); |
464 | } | 464 | } |
465 | else if ( encoding == HexTileEncoding ) { | 465 | else if ( encoding == HexTileEncoding ) { |
466 | owarn << "HexTile encoding" << oendl; | 466 | owarn << "HexTile encoding" << oendl; |
467 | handleHexTileRect(); | 467 | handleHexTileRect(); |
468 | } | 468 | } |
469 | else { | 469 | else { |
470 | int msg = Swap32IfLE( encoding ); | 470 | int msg = Swap32IfLE( encoding ); |
471 | QString protocolError = tr( "Protocol Error: An unknown encoding was " | 471 | QString protocolError = tr( "Protocol Error: An unknown encoding was " |
472 | "used by the server %1" ).arg( msg ); | 472 | "used by the server %1" ).arg( msg ); |
473 | currentState = Error; | 473 | currentState = Error; |
474 | owarn << "Unknown encoding, " << msg << "" << oendl; | 474 | owarn << "Unknown encoding, " << msg << "" << oendl; |
475 | emit error( protocolError ); | 475 | emit error( protocolError ); |
476 | return; | 476 | return; |
477 | } | 477 | } |
478 | } | 478 | } |
479 | 479 | ||
480 | // | 480 | // |
481 | // Raw Encoding | 481 | // Raw Encoding |
482 | // | 482 | // |
483 | 483 | ||
484 | void KRFBDecoder::handleRawRect() | 484 | void KRFBDecoder::handleRawRect() |
485 | { | 485 | { |
486 | // We need something a bit cleverer here to handle large | 486 | // We need something a bit cleverer here to handle large |
487 | // rectanges nicely. The chunking should be based on the | 487 | // rectanges nicely. The chunking should be based on the |
488 | // overall size (but has to be in complete lines). | 488 | // overall size (but has to be in complete lines). |
489 | 489 | ||
490 | // owarn << "Handling a raw rect chunk" << oendl; | 490 | // owarn << "Handling a raw rect chunk" << oendl; |
491 | 491 | ||
492 | // CARD32 lineCount = w * format->bpp / 8; | 492 | // CARD32 lineCount = w * format->bpp / 8; |
493 | 493 | ||
494 | if ( h > RectChunkSize ) { | 494 | if ( h > RectChunkSize ) { |
495 | // if ( con->sock->size() / lineCount ) { | 495 | // if ( con->sock->size() / lineCount ) { |
496 | // getRawRectChunk( con->sock->size() / lineCount ); | 496 | // getRawRectChunk( con->sock->size() / lineCount ); |
497 | // } | 497 | // } |
498 | // else { | 498 | // else { |
499 | getRawRectChunk( RectChunkSize ); | 499 | getRawRectChunk( RectChunkSize ); |
500 | // } | 500 | // } |
501 | } | 501 | } |
502 | else { | 502 | else { |
503 | getRawRectChunk( h ); | 503 | getRawRectChunk( h ); |
504 | } | 504 | } |
505 | } | 505 | } |
506 | 506 | ||
507 | void KRFBDecoder::getRawRectChunk( int lines ) | 507 | void KRFBDecoder::getRawRectChunk( int lines ) |
508 | { | 508 | { |
509 | this->lines = lines; | 509 | this->lines = lines; |
510 | CARD32 count = lines * w * format->bpp / 8; | 510 | CARD32 count = lines * w * format->bpp / 8; |
511 | 511 | ||
512 | // Wait for server init | 512 | // Wait for server init |
513 | // owarn << "Waiting for raw rect chunk, " << count << "" << oendl; | 513 | // owarn << "Waiting for raw rect chunk, " << count << "" << oendl; |
514 | 514 | ||
515 | currentState = AwaitingRawRectChunk; | 515 | currentState = AwaitingRawRectChunk; |
516 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); | 516 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); |
517 | con->waitForData( count ); | 517 | con->waitForData( count ); |
518 | } | 518 | } |
519 | 519 | ||
520 | void KRFBDecoder::gotRawRectChunk() | 520 | void KRFBDecoder::gotRawRectChunk() |
521 | { | 521 | { |
522 | assert( currentState == AwaitingRawRectChunk ); | 522 | assert( currentState == AwaitingRawRectChunk ); |
523 | 523 | ||
524 | disconnect( con, SIGNAL( gotEnoughData() ), | 524 | disconnect( con, SIGNAL( gotEnoughData() ), |
525 | this, SLOT( gotRawRectChunk() ) ); | 525 | this, SLOT( gotRawRectChunk() ) ); |
526 | 526 | ||
527 | // owarn << "Got raw rect chunk" << oendl; | 527 | // owarn << "Got raw rect chunk" << oendl; |
528 | 528 | ||
529 | // | 529 | // |
530 | // Read the rect data and copy it to the buffer. | 530 | // Read the rect data and copy it to the buffer. |
531 | // | 531 | // |
532 | 532 | ||
533 | // TODO: Replace this! | 533 | // TODO: Replace this! |
534 | int count = lines * w * format->bpp / 8; | 534 | int count = lines * w * format->bpp / 8; |
535 | char *hack = new char[ count ]; | 535 | char *hack = new char[ count ]; |
536 | con->read( hack, count ); | 536 | con->read( hack, count ); |
537 | buf->drawRawRectChunk( hack, x, y, w, lines ); | 537 | buf->drawRawRectChunk( hack, x, y, w, lines ); |
538 | delete hack; | 538 | delete [] hack; |
539 | // /TODO: | 539 | // /TODO: |
540 | 540 | ||
541 | h = h - lines; | 541 | h = h - lines; |
542 | y = y + lines; | 542 | y = y + lines; |
543 | 543 | ||
544 | if ( h > 0 ) { | 544 | if ( h > 0 ) { |
545 | handleRawRect(); | 545 | handleRawRect(); |
546 | } | 546 | } |
547 | else { | 547 | else { |
548 | noRects--; | 548 | noRects--; |
549 | 549 | ||
550 | // owarn << "There are " << noRects << " rects left" << oendl; | 550 | // owarn << "There are " << noRects << " rects left" << oendl; |
551 | 551 | ||
552 | if ( noRects ) { | 552 | if ( noRects ) { |
553 | currentState = AwaitingRectHeader; | 553 | currentState = AwaitingRectHeader; |
554 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 554 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
555 | con->waitForData( RectHeaderLength ); | 555 | con->waitForData( RectHeaderLength ); |
556 | } | 556 | } |
557 | else { | 557 | else { |
558 | // we are now ready for the next update - no need to wait for the timer | 558 | // we are now ready for the next update - no need to wait for the timer |
559 | currentState = Idle; | 559 | currentState = Idle; |
560 | sendUpdateRequest (1); | 560 | sendUpdateRequest (1); |
561 | } | 561 | } |
562 | } | 562 | } |
563 | } | 563 | } |
564 | 564 | ||
565 | // | 565 | // |
566 | // Copy Rectangle Encoding | 566 | // Copy Rectangle Encoding |
567 | // | 567 | // |
568 | 568 | ||
569 | void KRFBDecoder::handleCopyRect() | 569 | void KRFBDecoder::handleCopyRect() |
570 | { | 570 | { |
571 | currentState = AwaitingCopyRectPos; | 571 | currentState = AwaitingCopyRectPos; |
572 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) ); | 572 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) ); |
573 | con->waitForData( CopyRectPosLength ); | 573 | con->waitForData( CopyRectPosLength ); |
574 | } | 574 | } |
575 | 575 | ||
576 | void KRFBDecoder::gotCopyRectPos() | 576 | void KRFBDecoder::gotCopyRectPos() |
577 | { | 577 | { |
578 | disconnect( con, SIGNAL( gotEnoughData() ), | 578 | disconnect( con, SIGNAL( gotEnoughData() ), |
579 | this, SLOT( gotCopyRectPos() ) ); | 579 | this, SLOT( gotCopyRectPos() ) ); |
580 | 580 | ||
581 | CARD16 srcX; | 581 | CARD16 srcX; |
582 | CARD16 srcY; | 582 | CARD16 srcY; |
583 | 583 | ||
584 | con->read( &srcX, 2 ); | 584 | con->read( &srcX, 2 ); |
585 | con->read( &srcY, 2 ); | 585 | con->read( &srcY, 2 ); |
586 | 586 | ||
587 | srcX = Swap16IfLE( srcX ); | 587 | srcX = Swap16IfLE( srcX ); |
588 | srcY = Swap16IfLE( srcY ); | 588 | srcY = Swap16IfLE( srcY ); |
589 | 589 | ||
590 | buf->copyRect( srcX, srcY, x, y, w, h ); | 590 | buf->copyRect( srcX, srcY, x, y, w, h ); |
591 | 591 | ||
592 | noRects--; | 592 | noRects--; |
593 | 593 | ||
594 | // owarn << "There are " << noRects << " rects left" << oendl; | 594 | // owarn << "There are " << noRects << " rects left" << oendl; |
595 | 595 | ||
596 | if ( noRects ) { | 596 | if ( noRects ) { |
597 | currentState = AwaitingRectHeader; | 597 | currentState = AwaitingRectHeader; |
598 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 598 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
599 | con->waitForData( RectHeaderLength ); | 599 | con->waitForData( RectHeaderLength ); |
600 | } | 600 | } |
601 | else | 601 | else |
602 | currentState = Idle; | 602 | currentState = Idle; |
603 | } | 603 | } |
604 | 604 | ||
605 | void KRFBDecoder::handleRRERect() | 605 | void KRFBDecoder::handleRRERect() |
606 | { | 606 | { |
607 | owarn << "RRE not implemented" << oendl; | 607 | owarn << "RRE not implemented" << oendl; |
608 | } | 608 | } |
609 | 609 | ||
610 | void KRFBDecoder::handleCoRRERect() | 610 | void KRFBDecoder::handleCoRRERect() |
611 | { | 611 | { |
612 | owarn << "CoRRE not implemented" << oendl; | 612 | owarn << "CoRRE not implemented" << oendl; |
613 | } | 613 | } |
614 | 614 | ||
615 | void KRFBDecoder::handleHexTileRect() | 615 | void KRFBDecoder::handleHexTileRect() |
616 | { | 616 | { |
617 | owarn << "HexTile not implemented" << oendl; | 617 | owarn << "HexTile not implemented" << oendl; |
618 | } | 618 | } |
619 | 619 | ||
620 | void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) | 620 | void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) |
621 | { | 621 | { |
622 | // Deal with the buttons | 622 | // Deal with the buttons |
623 | if ( e->type() != QEvent::MouseMove ) { | 623 | if ( e->type() != QEvent::MouseMove ) { |
624 | buttonMask = 0; | 624 | buttonMask = 0; |
625 | if ( e->type() == QEvent::MouseButtonPress ) { | 625 | if ( e->type() == QEvent::MouseButtonPress ) { |
626 | if ( e->button() & LeftButton ) | 626 | if ( e->button() & LeftButton ) |
627 | buttonMask |= 0x01; | 627 | buttonMask |= 0x01; |
628 | if ( e->button() & MidButton ) | 628 | if ( e->button() & MidButton ) |
629 | buttonMask |= 0x04; | 629 | buttonMask |= 0x04; |
630 | if ( e->button() & RightButton ) | 630 | if ( e->button() & RightButton ) |
631 | buttonMask |= 0x02; | 631 | buttonMask |= 0x02; |
632 | } | 632 | } |
633 | else if ( e->type() == QEvent::MouseButtonRelease ) { | 633 | else if ( e->type() == QEvent::MouseButtonRelease ) { |
634 | if ( e->button() & LeftButton ) | 634 | if ( e->button() & LeftButton ) |
635 | buttonMask &= 0x06; | 635 | buttonMask &= 0x06; |
636 | if ( e->button() & MidButton ) | 636 | if ( e->button() & MidButton ) |
637 | buttonMask |= 0x03; | 637 | buttonMask |= 0x03; |
638 | if ( e->button() & RightButton ) | 638 | if ( e->button() & RightButton ) |
639 | buttonMask |= 0x05; | 639 | buttonMask |= 0x05; |
640 | } | 640 | } |
641 | } | 641 | } |
642 | 642 | ||
643 | // HACK: Scaling | 643 | // HACK: Scaling |
644 | CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); | 644 | CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); |
645 | CARD16 y = Swap16IfLE( e->y() * con->options()->scaleFactor ); | 645 | CARD16 y = Swap16IfLE( e->y() * con->options()->scaleFactor ); |
646 | 646 | ||
647 | con->write( &PointerEventId, 1 ); | 647 | con->write( &PointerEventId, 1 ); |
648 | con->write( &buttonMask, 1 ); | 648 | con->write( &buttonMask, 1 ); |
649 | con->write( &x, 2 ); | 649 | con->write( &x, 2 ); |
650 | con->write( &y, 2 ); | 650 | con->write( &y, 2 ); |
651 | } | 651 | } |
652 | 652 | ||
653 | 653 | ||
654 | void KRFBDecoder::sendCutEvent( const QString &unicode ) | 654 | void KRFBDecoder::sendCutEvent( const QString &unicode ) |
655 | { | 655 | { |
656 | // | 656 | // |
657 | // Warning: There is a bug in the RFB protocol because there is no way to find | 657 | // Warning: There is a bug in the RFB protocol because there is no way to find |
658 | // out the codepage in use on the remote machine. This could be fixed by requiring | 658 | // out the codepage in use on the remote machine. This could be fixed by requiring |
659 | // the remote server to use utf8 etc. but for now we have to assume they're the | 659 | // the remote server to use utf8 etc. but for now we have to assume they're the |
660 | // same. I've reported this problem to the ORL guys, but they apparantly have no | 660 | // same. I've reported this problem to the ORL guys, but they apparantly have no |
661 | // immediate plans to fix the issue. :-( (rich) | 661 | // immediate plans to fix the issue. :-( (rich) |
662 | // | 662 | // |
663 | 663 | ||
664 | CARD8 padding[3]; | 664 | CARD8 padding[3]; |
665 | QCString text = unicode.local8Bit(); | 665 | QCString text = unicode.local8Bit(); |
666 | CARD32 length = text.length(); | 666 | CARD32 length = text.length(); |
667 | length = Swap32IfLE( length ); | 667 | length = Swap32IfLE( length ); |
668 | 668 | ||
669 | con->write( &ClientCutTextId, 1 ); | 669 | con->write( &ClientCutTextId, 1 ); |
670 | con->write( &padding, 3 ); | 670 | con->write( &padding, 3 ); |
671 | con->write( &length, 4 ); | 671 | con->write( &length, 4 ); |
672 | con->write( text.data(), length ); | 672 | con->write( text.data(), length ); |
673 | } | 673 | } |
674 | 674 | ||
675 | void KRFBDecoder::gotServerCut() | 675 | void KRFBDecoder::gotServerCut() |
676 | { | 676 | { |
677 | owarn << "Got server cut" << oendl; | 677 | owarn << "Got server cut" << oendl; |
678 | 678 | ||
679 | currentState = AwaitingServerCutLength; | 679 | currentState = AwaitingServerCutLength; |
680 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); | 680 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); |
681 | con->waitForData( ServerCutLenLength ); | 681 | con->waitForData( ServerCutLenLength ); |
682 | } | 682 | } |
683 | 683 | ||
684 | void KRFBDecoder::gotServerCutLength() | 684 | void KRFBDecoder::gotServerCutLength() |
685 | { | 685 | { |
686 | assert( currentState = AwaitingServerCutLength ); | 686 | assert( currentState = AwaitingServerCutLength ); |
687 | disconnect( con, SIGNAL( gotEnoughData() ), | 687 | disconnect( con, SIGNAL( gotEnoughData() ), |
688 | this, SLOT( gotServerCutLength() ) ); | 688 | this, SLOT( gotServerCutLength() ) ); |
689 | 689 | ||
690 | CARD8 padding[3]; | 690 | CARD8 padding[3]; |
691 | con->read( padding, 3 ); | 691 | con->read( padding, 3 ); |
692 | 692 | ||
693 | con->read( &serverCutTextLen, 4 ); | 693 | con->read( &serverCutTextLen, 4 ); |
694 | serverCutTextLen = Swap32IfLE( serverCutTextLen ); | 694 | serverCutTextLen = Swap32IfLE( serverCutTextLen ); |
695 | 695 | ||
696 | currentState = AwaitingServerCutText; | 696 | currentState = AwaitingServerCutText; |
697 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); | 697 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); |
698 | con->waitForData( serverCutTextLen ); | 698 | con->waitForData( serverCutTextLen ); |
699 | } | 699 | } |
700 | 700 | ||
701 | void KRFBDecoder::gotServerCutText() | 701 | void KRFBDecoder::gotServerCutText() |
702 | { | 702 | { |
703 | assert( currentState = AwaitingServerCutText ); | 703 | assert( currentState = AwaitingServerCutText ); |
704 | 704 | ||
705 | disconnect( con, SIGNAL( gotEnoughData() ), | 705 | disconnect( con, SIGNAL( gotEnoughData() ), |
706 | this, SLOT( gotServerCutText() ) ); | 706 | this, SLOT( gotServerCutText() ) ); |
707 | 707 | ||
708 | 708 | ||
709 | // | 709 | // |
710 | // Warning: There is a bug in the RFB protocol because there is no way to find | 710 | // Warning: There is a bug in the RFB protocol because there is no way to find |
711 | // out the codepage in use on the remote machine. This could be fixed by requiring | 711 | // out the codepage in use on the remote machine. This could be fixed by requiring |
712 | // the remote server to use utf8 etc. but for now we have to assume they're the | 712 | // the remote server to use utf8 etc. but for now we have to assume they're the |
713 | // same. I've reported this problem to the ORL guys, but they apparantly have no | 713 | // same. I've reported this problem to the ORL guys, but they apparantly have no |
714 | // immediate plans to fix the issue. :-( (rich) | 714 | // immediate plans to fix the issue. :-( (rich) |
715 | // | 715 | // |
716 | 716 | ||
717 | char *cutbuf = new char[ serverCutTextLen + 1 ]; | 717 | char *cutbuf = new char[ serverCutTextLen + 1 ]; |
718 | CHECK_PTR( cutbuf ); | 718 | CHECK_PTR( cutbuf ); |
719 | 719 | ||
720 | con->read( cutbuf, serverCutTextLen ); | 720 | con->read( cutbuf, serverCutTextLen ); |
721 | cutbuf[ serverCutTextLen ] = '\0'; | 721 | cutbuf[ serverCutTextLen ] = '\0'; |
722 | 722 | ||
723 | /* For some reason QApplication::clipboard()->setText() segfaults when called | 723 | /* For some reason QApplication::clipboard()->setText() segfaults when called |
724 | * from within keypebble's mass of signals and slots | 724 | * from within keypebble's mass of signals and slots |
725 | owarn << "Server cut: " << cutbuf << "" << oendl; | 725 | owarn << "Server cut: " << cutbuf << "" << oendl; |
726 | 726 | ||
727 | QString cutText( cutbuf ); // DANGER!! | 727 | QString cutText( cutbuf ); // DANGER!! |
728 | qApp->clipboard()->setText( cutText ); | 728 | qApp->clipboard()->setText( cutText ); |
729 | */ | 729 | */ |
730 | 730 | ||
731 | delete cutbuf; | 731 | delete [] cutbuf; |
732 | // Now wait for the update (again) | 732 | // Now wait for the update (again) |
733 | if ( oldState == AwaitingUpdate ) { | 733 | if ( oldState == AwaitingUpdate ) { |
734 | currentState = AwaitingUpdate; | 734 | currentState = AwaitingUpdate; |
735 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 735 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
736 | con->waitForData( UpdateHeaderLength ); | 736 | con->waitForData( UpdateHeaderLength ); |
737 | } | 737 | } |
738 | else if ( oldState == Idle ) { | 738 | else if ( oldState == Idle ) { |
739 | currentState = Idle; | 739 | currentState = Idle; |
740 | } | 740 | } |
741 | else { | 741 | else { |
742 | owarn << "Async handled in weird state" << oendl; | 742 | owarn << "Async handled in weird state" << oendl; |
743 | currentState = oldState; | 743 | currentState = oldState; |
744 | }; | 744 | }; |
745 | } | 745 | } |
746 | 746 | ||
747 | void KRFBDecoder::gotBell() | 747 | void KRFBDecoder::gotBell() |
748 | { | 748 | { |
749 | owarn << "Got server bell" << oendl; | 749 | owarn << "Got server bell" << oendl; |
750 | buf->soundBell(); | 750 | buf->soundBell(); |
751 | 751 | ||
752 | // Now wait for the update (again) | 752 | // Now wait for the update (again) |
753 | if ( oldState == AwaitingUpdate ) { | 753 | if ( oldState == AwaitingUpdate ) { |
754 | currentState = AwaitingUpdate; | 754 | currentState = AwaitingUpdate; |
755 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 755 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
756 | con->waitForData( UpdateHeaderLength ); | 756 | con->waitForData( UpdateHeaderLength ); |
757 | } | 757 | } |
758 | else if ( oldState == Idle ) { | 758 | else if ( oldState == Idle ) { |
759 | currentState = Idle; | 759 | currentState = Idle; |
760 | } | 760 | } |
761 | else { | 761 | else { |
762 | owarn << "Async handled in weird state" << oendl; | 762 | owarn << "Async handled in weird state" << oendl; |
763 | currentState = oldState; | 763 | currentState = oldState; |
764 | }; | 764 | }; |
765 | } | 765 | } |
766 | 766 | ||
767 | void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) | 767 | void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) |
768 | { | 768 | { |
769 | int key; | 769 | int key; |
770 | key = toKeySym( event ); | 770 | key = toKeySym( event ); |
771 | if ( key ) { | 771 | if ( key ) { |
772 | key = Swap32IfLE( key ); | 772 | key = Swap32IfLE( key ); |
773 | 773 | ||
774 | CARD8 mask = true; | 774 | CARD8 mask = true; |
775 | 775 | ||
776 | CARD16 padding = 0; | 776 | CARD16 padding = 0; |
777 | con->write( &KeyEventId, 1 ); | 777 | con->write( &KeyEventId, 1 ); |
778 | con->write( &mask, 1 ); | 778 | con->write( &mask, 1 ); |
779 | con->write( &padding, 2 ); | 779 | con->write( &padding, 2 ); |
780 | con->write( &key, 4 ); | 780 | con->write( &key, 4 ); |
781 | } | 781 | } |
782 | } | 782 | } |
783 | 783 | ||
784 | void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) | 784 | void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) |
785 | { | 785 | { |
786 | int key; | 786 | int key; |
787 | key = toKeySym( event ); | 787 | key = toKeySym( event ); |
788 | if ( key ) { | 788 | if ( key ) { |
789 | key = Swap32IfLE( key ); | 789 | key = Swap32IfLE( key ); |
790 | 790 | ||
791 | CARD8 mask = false; | 791 | CARD8 mask = false; |
792 | 792 | ||
793 | CARD16 padding = 0; | 793 | CARD16 padding = 0; |
794 | con->write( &KeyEventId, 1 ); | 794 | con->write( &KeyEventId, 1 ); |
795 | con->write( &mask, 1 ); | 795 | con->write( &mask, 1 ); |
796 | con->write( &padding, 2 ); | 796 | con->write( &padding, 2 ); |
797 | con->write( &key, 4 ); | 797 | con->write( &key, 4 ); |
798 | } | 798 | } |
799 | } | 799 | } |
800 | 800 | ||
801 | 801 | ||
802 | 802 | ||
803 | 803 | ||
804 | // | 804 | // |
805 | // The RFB protocol spec says 'For most ordinary keys, the 'keysym' | 805 | // The RFB protocol spec says 'For most ordinary keys, the 'keysym' |
806 | // is the same as the corresponding ASCII value.', but doesn't | 806 | // is the same as the corresponding ASCII value.', but doesn't |
807 | // elaborate what the most ordinary keys are. The spec also lists | 807 | // elaborate what the most ordinary keys are. The spec also lists |
808 | // a set (possibly subset, it's unspecified) of mappings for | 808 | // a set (possibly subset, it's unspecified) of mappings for |
809 | // "other common keys" (backspace, tab, return, escape, etc). | 809 | // "other common keys" (backspace, tab, return, escape, etc). |
810 | // | 810 | // |
811 | int KRFBDecoder::toKeySym( QKeyEvent *k ) | 811 | int KRFBDecoder::toKeySym( QKeyEvent *k ) |
812 | { | 812 | { |
813 | 813 | ||
814 | // | 814 | // |
815 | // Try and map these "other common keys" first. | 815 | // Try and map these "other common keys" first. |
816 | // | 816 | // |
817 | if ((k->key() >= Qt::Key_Escape) && (k->key() <= Qt::Key_F12)) { | 817 | if ((k->key() >= Qt::Key_Escape) && (k->key() <= Qt::Key_F12)) { |
818 | for(int i = 0; keyMap[i].keycode != 0; i++) { | 818 | for(int i = 0; keyMap[i].keycode != 0; i++) { |
819 | if (k->key() == keyMap[i].keycode) { | 819 | if (k->key() == keyMap[i].keycode) { |
820 | return keyMap[i].keysym; | 820 | return keyMap[i].keysym; |
821 | } | 821 | } |
822 | } | 822 | } |
823 | } | 823 | } |
824 | 824 | ||
825 | // | 825 | // |
826 | // If these keys aren't matched, return the ascii code and let the | 826 | // If these keys aren't matched, return the ascii code and let the |
827 | // server figure it out. We don't return k->key(), as the data in | 827 | // server figure it out. We don't return k->key(), as the data in |
828 | // key differs between input methods, and we don't want special cases. | 828 | // key differs between input methods, and we don't want special cases. |
829 | // | 829 | // |
830 | return k->ascii(); | 830 | return k->ascii(); |
831 | } | 831 | } |
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp index a6c92a0..516dc93 100644 --- a/noncore/games/sfcave/sfcave.cpp +++ b/noncore/games/sfcave/sfcave.cpp | |||
@@ -617,595 +617,595 @@ void SFCave :: addGate() | |||
617 | blocks[i].setRect( x1, y1, blockWidth, b1Height ); | 617 | blocks[i].setRect( x1, y1, blockWidth, b1Height ); |
618 | blocks[i+1].setRect( x2, y2, blockWidth, b2Height ); | 618 | blocks[i+1].setRect( x2, y2, blockWidth, b2Height ); |
619 | 619 | ||
620 | break; | 620 | break; |
621 | } | 621 | } |
622 | } | 622 | } |
623 | } | 623 | } |
624 | 624 | ||
625 | void SFCave :: setPoint( int point ) | 625 | void SFCave :: setPoint( int point ) |
626 | { | 626 | { |
627 | if ( nextInt(100) >= 80 ) | 627 | if ( nextInt(100) >= 80 ) |
628 | dir *= -1; | 628 | dir *= -1; |
629 | 629 | ||
630 | mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) ); | 630 | mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) ); |
631 | if ( mapTop[point] < 0 ) | 631 | if ( mapTop[point] < 0 ) |
632 | { | 632 | { |
633 | mapTop[point] = 0; | 633 | mapTop[point] = 0; |
634 | dir *= -1; | 634 | dir *= -1; |
635 | } | 635 | } |
636 | else if ( mapTop[point] >= maxHeight ) | 636 | else if ( mapTop[point] >= maxHeight ) |
637 | { | 637 | { |
638 | mapTop[point] = maxHeight; | 638 | mapTop[point] = maxHeight; |
639 | dir *= -1; | 639 | dir *= -1; |
640 | } | 640 | } |
641 | 641 | ||
642 | // mapBottom[point] = sHeight - (maxHeight - mapBottom[point]); | 642 | // mapBottom[point] = sHeight - (maxHeight - mapBottom[point]); |
643 | mapBottom[point] = sHeight - (maxHeight - mapTop[point]); | 643 | mapBottom[point] = sHeight - (maxHeight - mapTop[point]); |
644 | } | 644 | } |
645 | 645 | ||
646 | void SFCave :: drawBoss() | 646 | void SFCave :: drawBoss() |
647 | { | 647 | { |
648 | offscreen->fill( Qt::black ); | 648 | offscreen->fill( Qt::black ); |
649 | 649 | ||
650 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); | 650 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); |
651 | } | 651 | } |
652 | 652 | ||
653 | void SFCave :: draw() | 653 | void SFCave :: draw() |
654 | { | 654 | { |
655 | //printf( "Paint\n" ); | 655 | //printf( "Paint\n" ); |
656 | offscreen->fill( Qt::black ); | 656 | offscreen->fill( Qt::black ); |
657 | 657 | ||
658 | QPainter p( offscreen ); | 658 | QPainter p( offscreen ); |
659 | QFontMetrics fm = p.fontMetrics(); | 659 | QFontMetrics fm = p.fontMetrics(); |
660 | p.setPen( Qt::white ); | 660 | p.setPen( Qt::white ); |
661 | 661 | ||
662 | for ( int i = 0 ; i < MAPSIZE -3; ++i ) | 662 | for ( int i = 0 ; i < MAPSIZE -3; ++i ) |
663 | { | 663 | { |
664 | // Only display top landscape if not running FLY_GAME | 664 | // Only display top landscape if not running FLY_GAME |
665 | if ( CURRENT_GAME_TYPE != FLY_GAME ) | 665 | if ( CURRENT_GAME_TYPE != FLY_GAME ) |
666 | p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] ); | 666 | p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] ); |
667 | 667 | ||
668 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] ); | 668 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] ); |
669 | 669 | ||
670 | if ( CURRENT_GAME_TYPE == FLY_GAME && showScoreZones ) | 670 | if ( CURRENT_GAME_TYPE == FLY_GAME && showScoreZones ) |
671 | { | 671 | { |
672 | p.setPen( Qt::blue ); | 672 | p.setPen( Qt::blue ); |
673 | for ( int j = 1 ; j < 10 && FLYSCORES( j, 0 ) != -1 ; ++j ) | 673 | for ( int j = 1 ; j < 10 && FLYSCORES( j, 0 ) != -1 ; ++j ) |
674 | { | 674 | { |
675 | if ( FLYSCORES( j, 2 ) < 0 ) | 675 | if ( FLYSCORES( j, 2 ) < 0 ) |
676 | p.setPen( Qt::red ); | 676 | p.setPen( Qt::red ); |
677 | 677 | ||
678 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-FLYSCORES( j, 0 ), ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-FLYSCORES( j, 0 ) ); | 678 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-FLYSCORES( j, 0 ), ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-FLYSCORES( j, 0 ) ); |
679 | } | 679 | } |
680 | 680 | ||
681 | p.setPen( Qt::white ); | 681 | p.setPen( Qt::white ); |
682 | } | 682 | } |
683 | } | 683 | } |
684 | 684 | ||
685 | // Uncomment this to show user segment (usful for checking collision boundary with landscape | 685 | // Uncomment this to show user segment (usful for checking collision boundary with landscape |
686 | // p.setPen( Qt::red ); | 686 | // p.setPen( Qt::red ); |
687 | // p.drawLine( (11*segSize) - (offset*speed), 0, ((11)*segSize)-(offset*speed), sHeight ); | 687 | // p.drawLine( (11*segSize) - (offset*speed), 0, ((11)*segSize)-(offset*speed), sHeight ); |
688 | // p.setPen( Qt::white ); | 688 | // p.setPen( Qt::white ); |
689 | 689 | ||
690 | // Draw user | 690 | // Draw user |
691 | p.drawRect( user ); | 691 | p.drawRect( user ); |
692 | 692 | ||
693 | // Draw trails | 693 | // Draw trails |
694 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) | 694 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) |
695 | if ( trail[i].x() >= 0 ) | 695 | if ( trail[i].x() >= 0 ) |
696 | { | 696 | { |
697 | if ( showEyeCandy ) | 697 | if ( showEyeCandy ) |
698 | p.setPen( Qt::white.light((int)(100.0-3*(user.x()/100.0)* (user.x()-trail[i].x())) ) ); | 698 | p.setPen( Qt::white.light((int)(100.0-3*(user.x()/100.0)* (user.x()-trail[i].x())) ) ); |
699 | p.drawRect( trail[i].x(), trail[i].y(), 2, 2 ); | 699 | p.drawRect( trail[i].x(), trail[i].y(), 2, 2 ); |
700 | } | 700 | } |
701 | 701 | ||
702 | p.setPen( Qt::white ); | 702 | p.setPen( Qt::white ); |
703 | // Draw blocks | 703 | // Draw blocks |
704 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) | 704 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) |
705 | if ( blocks[i].y() != -1 ) | 705 | if ( blocks[i].y() != -1 ) |
706 | { | 706 | { |
707 | p.fillRect( blocks[i], Qt::black ); | 707 | p.fillRect( blocks[i], Qt::black ); |
708 | p.drawRect( blocks[i] ); | 708 | p.drawRect( blocks[i] ); |
709 | } | 709 | } |
710 | 710 | ||
711 | // draw score | 711 | // draw score |
712 | QString s; | 712 | QString s; |
713 | s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType][currentGameDifficulty] ); | 713 | s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType][currentGameDifficulty] ); |
714 | p.drawText( 5, 10, s ); | 714 | p.drawText( 5, 10, s ); |
715 | 715 | ||
716 | 716 | ||
717 | if ( state == STATE_CRASHING || state == STATE_CRASHED ) | 717 | if ( state == STATE_CRASHING || state == STATE_CRASHED ) |
718 | { | 718 | { |
719 | // add next crash line | 719 | // add next crash line |
720 | 720 | ||
721 | if ( crashLineLength != -1 ) | 721 | if ( crashLineLength != -1 ) |
722 | { | 722 | { |
723 | for ( int i = 0 ; i < 36 ; ++i ) | 723 | for ( int i = 0 ; i < 36 ; ++i ) |
724 | { | 724 | { |
725 | int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) ); | 725 | int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) ); |
726 | int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y ); | 726 | int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y ); |
727 | } | 727 | } |
728 | } | 728 | } |
729 | 729 | ||
730 | if ( state == STATE_CRASHING && crashLineLength >= 15 ) //|| crashLineLength == -1) ) | 730 | if ( state == STATE_CRASHING && crashLineLength >= 15 ) //|| crashLineLength == -1) ) |
731 | state = STATE_CRASHED; | 731 | state = STATE_CRASHED; |
732 | 732 | ||
733 | if ( state == STATE_CRASHED ) | 733 | if ( state == STATE_CRASHED ) |
734 | { | 734 | { |
735 | QString text = "Press up or down to start"; | 735 | QString text = "Press up or down to start"; |
736 | p.drawText( (sWidth/2) - (fm.width( text )/2), 120, text ); | 736 | p.drawText( (sWidth/2) - (fm.width( text )/2), 120, text ); |
737 | 737 | ||
738 | text = "Press OK for menu"; | 738 | text = "Press OK for menu"; |
739 | p.drawText( (sWidth/2) - (fm.width( text )/2), 135, text ); | 739 | p.drawText( (sWidth/2) - (fm.width( text )/2), 135, text ); |
740 | /* | 740 | /* |
741 | text = "Press r to replay"; | 741 | text = "Press r to replay"; |
742 | p.drawText( (sWidth/2) - (fm.width( text )/2), 150, text ); | 742 | p.drawText( (sWidth/2) - (fm.width( text )/2), 150, text ); |
743 | 743 | ||
744 | text = "Press s to save the replay"; | 744 | text = "Press s to save the replay"; |
745 | p.drawText( (sWidth/2) - (fm.width( text )/2), 165, text ); | 745 | p.drawText( (sWidth/2) - (fm.width( text )/2), 165, text ); |
746 | 746 | ||
747 | text = "Press r to load a saved replay"; | 747 | text = "Press r to load a saved replay"; |
748 | p.drawText( (sWidth/2) - (fm.width( text )/2), 180, text ); | 748 | p.drawText( (sWidth/2) - (fm.width( text )/2), 180, text ); |
749 | */ | 749 | */ |
750 | } | 750 | } |
751 | else | 751 | else |
752 | crashLineLength ++; | 752 | crashLineLength ++; |
753 | } | 753 | } |
754 | 754 | ||
755 | p.end(); | 755 | p.end(); |
756 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); | 756 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); |
757 | //printf( "endpaint\n" ); | 757 | //printf( "endpaint\n" ); |
758 | } | 758 | } |
759 | 759 | ||
760 | void SFCave :: handleKeys() | 760 | void SFCave :: handleKeys() |
761 | { | 761 | { |
762 | // Find enpty trail and move others | 762 | // Find enpty trail and move others |
763 | bool done = false; | 763 | bool done = false; |
764 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) | 764 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) |
765 | { | 765 | { |
766 | if ( trail[i].x() < 0 ) | 766 | if ( trail[i].x() < 0 ) |
767 | { | 767 | { |
768 | if ( !done ) | 768 | if ( !done ) |
769 | { | 769 | { |
770 | trail[i].setX( user.x() - 5 ); | 770 | trail[i].setX( user.x() - 5 ); |
771 | trail[i].setY( user.y() ); | 771 | trail[i].setY( user.y() ); |
772 | done = true; | 772 | done = true; |
773 | } | 773 | } |
774 | } | 774 | } |
775 | else | 775 | else |
776 | { | 776 | { |
777 | trail[i].setX( trail[i].x() - (2) ); | 777 | trail[i].setX( trail[i].x() - (2) ); |
778 | } | 778 | } |
779 | } | 779 | } |
780 | 780 | ||
781 | if ( speed <= 3 ) | 781 | if ( speed <= 3 ) |
782 | { | 782 | { |
783 | if ( press ) | 783 | if ( press ) |
784 | thrust -= thrustUp; | 784 | thrust -= thrustUp; |
785 | else | 785 | else |
786 | thrust += noThrust; | 786 | thrust += noThrust; |
787 | 787 | ||
788 | if ( thrust > maxDownThrust ) | 788 | if ( thrust > maxDownThrust ) |
789 | thrust = maxDownThrust; | 789 | thrust = maxDownThrust; |
790 | else if ( thrust < maxUpThrust ) | 790 | else if ( thrust < maxUpThrust ) |
791 | thrust = maxUpThrust; | 791 | thrust = maxUpThrust; |
792 | } | 792 | } |
793 | else | 793 | else |
794 | { | 794 | { |
795 | if ( press ) | 795 | if ( press ) |
796 | thrust -= 0.5; | 796 | thrust -= 0.5; |
797 | else | 797 | else |
798 | thrust += 0.8; | 798 | thrust += 0.8; |
799 | 799 | ||
800 | if ( thrust > 5.0 ) | 800 | if ( thrust > 5.0 ) |
801 | thrust = 5.0; | 801 | thrust = 5.0; |
802 | else if ( thrust < -3.5 ) | 802 | else if ( thrust < -3.5 ) |
803 | thrust = -3.5; | 803 | thrust = -3.5; |
804 | } | 804 | } |
805 | user.moveBy( 0, (int)thrust ); | 805 | user.moveBy( 0, (int)thrust ); |
806 | } | 806 | } |
807 | 807 | ||
808 | void SFCave :: keyPressEvent( QKeyEvent *e ) | 808 | void SFCave :: keyPressEvent( QKeyEvent *e ) |
809 | { | 809 | { |
810 | if ( state == STATE_MENU ) | 810 | if ( state == STATE_MENU ) |
811 | handleMenuKeys( e ); | 811 | handleMenuKeys( e ); |
812 | else | 812 | else |
813 | { | 813 | { |
814 | switch( e->key() ) | 814 | switch( e->key() ) |
815 | { | 815 | { |
816 | case Qt::Key_Up: | 816 | case Qt::Key_Up: |
817 | case Qt::Key_F9: | 817 | case Qt::Key_F9: |
818 | case Qt::Key_Space: | 818 | case Qt::Key_Space: |
819 | if ( state == STATE_RUNNING ) | 819 | if ( state == STATE_RUNNING ) |
820 | { | 820 | { |
821 | if ( !replay && !press ) | 821 | if ( !replay && !press ) |
822 | { | 822 | { |
823 | press = true; | 823 | press = true; |
824 | replayList.append( new int( nrFrames ) ); | 824 | replayList.append( new int( nrFrames ) ); |
825 | } | 825 | } |
826 | } | 826 | } |
827 | else if ( state == STATE_CRASHED ) | 827 | else if ( state == STATE_CRASHED ) |
828 | { | 828 | { |
829 | if ( e->key() == Key_Up ) | 829 | if ( e->key() == Key_Up ) |
830 | state = STATE_NEWGAME; | 830 | state = STATE_NEWGAME; |
831 | } | 831 | } |
832 | 832 | ||
833 | break; | 833 | break; |
834 | case Qt::Key_M: | 834 | case Qt::Key_M: |
835 | case Qt::Key_Return: | 835 | case Qt::Key_Return: |
836 | case Qt::Key_Enter: | 836 | case Qt::Key_Enter: |
837 | if ( state == STATE_CRASHED ) | 837 | if ( state == STATE_CRASHED ) |
838 | { | 838 | { |
839 | state = STATE_MENU; | 839 | state = STATE_MENU; |
840 | currentMenuNr = 0; | 840 | currentMenuNr = 0; |
841 | currentMenuOption[currentMenuNr] = 0; | 841 | currentMenuOption[currentMenuNr] = 0; |
842 | } | 842 | } |
843 | break; | 843 | break; |
844 | 844 | ||
845 | case Qt::Key_Z: | 845 | case Qt::Key_Z: |
846 | showScoreZones = !showScoreZones; | 846 | showScoreZones = !showScoreZones; |
847 | break; | 847 | break; |
848 | 848 | ||
849 | default: | 849 | default: |
850 | e->ignore(); | 850 | e->ignore(); |
851 | break; | 851 | break; |
852 | } | 852 | } |
853 | } | 853 | } |
854 | } | 854 | } |
855 | 855 | ||
856 | void SFCave :: keyReleaseEvent( QKeyEvent *e ) | 856 | void SFCave :: keyReleaseEvent( QKeyEvent *e ) |
857 | { | 857 | { |
858 | if ( state == STATE_MENU ) | 858 | if ( state == STATE_MENU ) |
859 | { | 859 | { |
860 | } | 860 | } |
861 | else | 861 | else |
862 | { | 862 | { |
863 | switch( e->key() ) | 863 | switch( e->key() ) |
864 | { | 864 | { |
865 | case Qt::Key_F9: | 865 | case Qt::Key_F9: |
866 | case Qt::Key_Space: | 866 | case Qt::Key_Space: |
867 | case Qt::Key_Up: | 867 | case Qt::Key_Up: |
868 | if ( state == STATE_RUNNING ) | 868 | if ( state == STATE_RUNNING ) |
869 | { | 869 | { |
870 | if ( !replay && press ) | 870 | if ( !replay && press ) |
871 | { | 871 | { |
872 | press = false; | 872 | press = false; |
873 | replayList.append( new int( nrFrames ) ); | 873 | replayList.append( new int( nrFrames ) ); |
874 | } | 874 | } |
875 | } | 875 | } |
876 | break; | 876 | break; |
877 | 877 | ||
878 | case Qt::Key_E: | 878 | case Qt::Key_E: |
879 | showEyeCandy = !showEyeCandy; | 879 | showEyeCandy = !showEyeCandy; |
880 | break; | 880 | break; |
881 | 881 | ||
882 | case Qt::Key_R: | 882 | case Qt::Key_R: |
883 | if ( state == STATE_CRASHED ) | 883 | if ( state == STATE_CRASHED ) |
884 | state = STATE_REPLAY; | 884 | state = STATE_REPLAY; |
885 | break; | 885 | break; |
886 | 886 | ||
887 | case Qt::Key_Down: | 887 | case Qt::Key_Down: |
888 | if ( state == STATE_CRASHED ) | 888 | if ( state == STATE_CRASHED ) |
889 | state = STATE_NEWGAME; | 889 | state = STATE_NEWGAME; |
890 | break; | 890 | break; |
891 | 891 | ||
892 | case Qt::Key_S: | 892 | case Qt::Key_S: |
893 | if ( state == STATE_CRASHED ) | 893 | if ( state == STATE_CRASHED ) |
894 | saveReplay(); | 894 | saveReplay(); |
895 | break; | 895 | break; |
896 | 896 | ||
897 | case Qt::Key_L: | 897 | case Qt::Key_L: |
898 | if ( state == STATE_CRASHED ) | 898 | if ( state == STATE_CRASHED ) |
899 | loadReplay(); | 899 | loadReplay(); |
900 | break; | 900 | break; |
901 | default: | 901 | default: |
902 | e->ignore(); | 902 | e->ignore(); |
903 | break; | 903 | break; |
904 | } | 904 | } |
905 | } | 905 | } |
906 | 906 | ||
907 | } | 907 | } |
908 | 908 | ||
909 | 909 | ||
910 | void SFCave :: saveScore() | 910 | void SFCave :: saveScore() |
911 | { | 911 | { |
912 | #ifdef QWS | 912 | #ifdef QWS |
913 | Config cfg( "sfcave" ); | 913 | Config cfg( "sfcave" ); |
914 | cfg.setGroup( "settings" ); | 914 | cfg.setGroup( "settings" ); |
915 | QString key = "highScore_"; | 915 | QString key = "highScore_"; |
916 | 916 | ||
917 | cfg.writeEntry( key + gameTypes[currentGameType] + "_" + dificultyOption[currentGameDifficulty], highestScore[currentGameType][currentGameDifficulty] ); | 917 | cfg.writeEntry( key + gameTypes[currentGameType] + "_" + dificultyOption[currentGameDifficulty], highestScore[currentGameType][currentGameDifficulty] ); |
918 | key += CURRENT_GAME_TYPE; | 918 | key += CURRENT_GAME_TYPE; |
919 | cfg.writeEntry( key, highestScore[currentGameType] ); | 919 | cfg.writeEntry( key, highestScore[currentGameType] ); |
920 | #endif | 920 | #endif |
921 | } | 921 | } |
922 | 922 | ||
923 | void SFCave :: saveReplay() | 923 | void SFCave :: saveReplay() |
924 | { | 924 | { |
925 | FILE *out; | 925 | FILE *out; |
926 | out = fopen( QFile::encodeName(replayFile).data(), "w" ); | 926 | out = fopen( QFile::encodeName(replayFile).data(), "w" ); |
927 | if ( !out ) | 927 | if ( !out ) |
928 | { | 928 | { |
929 | printf( "Couldn't write to %s\n", QFile::encodeName(replayFile).data() ); | 929 | printf( "Couldn't write to %s\n", QFile::encodeName(replayFile).data() ); |
930 | return; | 930 | return; |
931 | } | 931 | } |
932 | 932 | ||
933 | // Build up string of values | 933 | // Build up string of values |
934 | // Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>....... | 934 | // Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>....... |
935 | QString val; | 935 | QString val; |
936 | val.sprintf( "%d %d %d ", currentSeed, currentGameType, currentGameDifficulty ); | 936 | val.sprintf( "%d %d %d ", currentSeed, currentGameType, currentGameDifficulty ); |
937 | 937 | ||
938 | QListIterator<int> it( replayList ); | 938 | QListIterator<int> it( replayList ); |
939 | while( it.current() ) | 939 | while( it.current() ) |
940 | { | 940 | { |
941 | QString tmp; | 941 | QString tmp; |
942 | tmp.sprintf( "%d ", (*it.current()) ); | 942 | tmp.sprintf( "%d ", (*it.current()) ); |
943 | val += tmp; | 943 | val += tmp; |
944 | 944 | ||
945 | ++it; | 945 | ++it; |
946 | } | 946 | } |
947 | val += "\n"; | 947 | val += "\n"; |
948 | 948 | ||
949 | QString line; | 949 | QString line; |
950 | line.sprintf( "%d\n", val.length() ); | 950 | line.sprintf( "%d\n", val.length() ); |
951 | fwrite( (const char *)line, 1, line.length(), out ); | 951 | fwrite( (const char *)line, 1, line.length(), out ); |
952 | 952 | ||
953 | fwrite( (const char *)val, 1, val.length(), out ); | 953 | fwrite( (const char *)val, 1, val.length(), out ); |
954 | 954 | ||
955 | fclose( out ); | 955 | fclose( out ); |
956 | 956 | ||
957 | printf( "Replay saved to %s\n", QFile::encodeName(replayFile).data() ); | 957 | printf( "Replay saved to %s\n", QFile::encodeName(replayFile).data() ); |
958 | 958 | ||
959 | } | 959 | } |
960 | 960 | ||
961 | void SFCave :: loadReplay() | 961 | void SFCave :: loadReplay() |
962 | { | 962 | { |
963 | FILE *in = fopen( QFile::encodeName(replayFile).data() , "r" ); | 963 | FILE *in = fopen( QFile::encodeName(replayFile).data() , "r" ); |
964 | 964 | ||
965 | if ( in == 0 ) | 965 | if ( in == 0 ) |
966 | { | 966 | { |
967 | printf( "Couldn't load replay file!\n" ); | 967 | printf( "Couldn't load replay file!\n" ); |
968 | return; | 968 | return; |
969 | } | 969 | } |
970 | 970 | ||
971 | // Read next line - contains the size of the options | 971 | // Read next line - contains the size of the options |
972 | char line[10+1]; | 972 | char line[10+1]; |
973 | fgets( line, 10, in ); | 973 | fgets( line, 10, in ); |
974 | 974 | ||
975 | int length = -1; | 975 | int length = -1; |
976 | sscanf( line, "%d", &length ); | 976 | sscanf( line, "%d", &length ); |
977 | char *data = new char[length+1]; | 977 | char *data = new char[length+1]; |
978 | 978 | ||
979 | fread( data, 1, length, in ); | 979 | fread( data, 1, length, in ); |
980 | // printf( "data - %s", data ); | 980 | // printf( "data - %s", data ); |
981 | 981 | ||
982 | QString sep = " "; | 982 | QString sep = " "; |
983 | QStringList list = QStringList::split( sep, QString( data ) ); | 983 | QStringList list = QStringList::split( sep, QString( data ) ); |
984 | 984 | ||
985 | // print it out | 985 | // print it out |
986 | QStringList::Iterator it = list.begin(); | 986 | QStringList::Iterator it = list.begin(); |
987 | currentSeed = (*it).toInt(); | 987 | currentSeed = (*it).toInt(); |
988 | ++it; | 988 | ++it; |
989 | currentGameType = (*it).toInt(); | 989 | currentGameType = (*it).toInt(); |
990 | ++it; | 990 | ++it; |
991 | currentGameDifficulty = (*it).toInt(); | 991 | currentGameDifficulty = (*it).toInt(); |
992 | ++it; | 992 | ++it; |
993 | 993 | ||
994 | replayList.clear(); | 994 | replayList.clear(); |
995 | for ( ; it != list.end(); ++it ) | 995 | for ( ; it != list.end(); ++it ) |
996 | { | 996 | { |
997 | int v = (*it).toInt(); | 997 | int v = (*it).toInt(); |
998 | replayList.append( new int( v ) ); | 998 | replayList.append( new int( v ) ); |
999 | } | 999 | } |
1000 | 1000 | ||
1001 | delete data; | 1001 | delete [] data; |
1002 | 1002 | ||
1003 | fclose( in ); | 1003 | fclose( in ); |
1004 | 1004 | ||
1005 | printf( "Replay loaded from %s\n", QFile::encodeName(replayFile).data() ); | 1005 | printf( "Replay loaded from %s\n", QFile::encodeName(replayFile).data() ); |
1006 | } | 1006 | } |
1007 | 1007 | ||
1008 | 1008 | ||
1009 | //--------------- MENU CODE --------------------- | 1009 | //--------------- MENU CODE --------------------- |
1010 | void SFCave :: handleMenuKeys( QKeyEvent *e ) | 1010 | void SFCave :: handleMenuKeys( QKeyEvent *e ) |
1011 | { | 1011 | { |
1012 | switch( e->key() ) | 1012 | switch( e->key() ) |
1013 | { | 1013 | { |
1014 | case Qt::Key_Down: | 1014 | case Qt::Key_Down: |
1015 | currentMenuOption[currentMenuNr] ++; | 1015 | currentMenuOption[currentMenuNr] ++; |
1016 | if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" ) | 1016 | if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" ) |
1017 | currentMenuOption[currentMenuNr] = 0; | 1017 | currentMenuOption[currentMenuNr] = 0; |
1018 | break; | 1018 | break; |
1019 | case Qt::Key_Up: | 1019 | case Qt::Key_Up: |
1020 | currentMenuOption[currentMenuNr] --; | 1020 | currentMenuOption[currentMenuNr] --; |
1021 | if ( currentMenuOption[currentMenuNr] < 0 ) | 1021 | if ( currentMenuOption[currentMenuNr] < 0 ) |
1022 | currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1; | 1022 | currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1; |
1023 | break; | 1023 | break; |
1024 | 1024 | ||
1025 | case Qt::Key_Left: | 1025 | case Qt::Key_Left: |
1026 | if ( currentMenuNr == MENU_OPTIONS_MENU ) | 1026 | if ( currentMenuNr == MENU_OPTIONS_MENU ) |
1027 | { | 1027 | { |
1028 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) | 1028 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) |
1029 | { | 1029 | { |
1030 | currentGameType --; | 1030 | currentGameType --; |
1031 | if ( currentGameType < 0 ) | 1031 | if ( currentGameType < 0 ) |
1032 | currentGameType = NR_GAME_TYPES - 1; | 1032 | currentGameType = NR_GAME_TYPES - 1; |
1033 | } | 1033 | } |
1034 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) | 1034 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) |
1035 | { | 1035 | { |
1036 | currentGameDifficulty --; | 1036 | currentGameDifficulty --; |
1037 | if ( currentGameDifficulty < 0 ) | 1037 | if ( currentGameDifficulty < 0 ) |
1038 | currentGameDifficulty = NR_GAME_DIFFICULTIES - 1; | 1038 | currentGameDifficulty = NR_GAME_DIFFICULTIES - 1; |
1039 | } | 1039 | } |
1040 | } | 1040 | } |
1041 | break; | 1041 | break; |
1042 | 1042 | ||
1043 | case Qt::Key_Right: | 1043 | case Qt::Key_Right: |
1044 | if ( currentMenuNr == MENU_OPTIONS_MENU ) | 1044 | if ( currentMenuNr == MENU_OPTIONS_MENU ) |
1045 | { | 1045 | { |
1046 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) | 1046 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) |
1047 | { | 1047 | { |
1048 | currentGameType ++; | 1048 | currentGameType ++; |
1049 | if ( currentGameType == NR_GAME_TYPES ) | 1049 | if ( currentGameType == NR_GAME_TYPES ) |
1050 | currentGameType = 0; | 1050 | currentGameType = 0; |
1051 | } | 1051 | } |
1052 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) | 1052 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) |
1053 | { | 1053 | { |
1054 | currentGameDifficulty ++; | 1054 | currentGameDifficulty ++; |
1055 | if ( currentGameDifficulty == NR_GAME_DIFFICULTIES ) | 1055 | if ( currentGameDifficulty == NR_GAME_DIFFICULTIES ) |
1056 | currentGameDifficulty = 0; | 1056 | currentGameDifficulty = 0; |
1057 | } | 1057 | } |
1058 | } | 1058 | } |
1059 | break; | 1059 | break; |
1060 | 1060 | ||
1061 | case Qt::Key_Space: | 1061 | case Qt::Key_Space: |
1062 | case Qt::Key_Return: | 1062 | case Qt::Key_Return: |
1063 | case Qt::Key_Enter: | 1063 | case Qt::Key_Enter: |
1064 | dealWithMenuSelection(); | 1064 | dealWithMenuSelection(); |
1065 | break; | 1065 | break; |
1066 | } | 1066 | } |
1067 | } | 1067 | } |
1068 | 1068 | ||
1069 | void SFCave :: displayMenu() | 1069 | void SFCave :: displayMenu() |
1070 | { | 1070 | { |
1071 | offscreen->fill( Qt::black ); | 1071 | offscreen->fill( Qt::black ); |
1072 | 1072 | ||
1073 | QPainter p( offscreen ); | 1073 | QPainter p( offscreen ); |
1074 | p.setPen( Qt::white ); | 1074 | p.setPen( Qt::white ); |
1075 | 1075 | ||
1076 | QFont f( "Helvetica", 16 ); | 1076 | QFont f( "Helvetica", 16 ); |
1077 | p.setFont( f ); | 1077 | p.setFont( f ); |
1078 | 1078 | ||
1079 | QFontMetrics fm = p.fontMetrics(); | 1079 | QFontMetrics fm = p.fontMetrics(); |
1080 | 1080 | ||
1081 | QString text = "SFCave"; | 1081 | QString text = "SFCave"; |
1082 | p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text ); | 1082 | p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text ); |
1083 | 1083 | ||
1084 | text = "Written by Andy Qua"; | 1084 | text = "Written by Andy Qua"; |
1085 | p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text ); | 1085 | p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text ); |
1086 | 1086 | ||
1087 | // Draw options | 1087 | // Draw options |
1088 | int pos = 140; | 1088 | int pos = 140; |
1089 | for ( int i = 0 ; menuOptions[currentMenuNr][i] != "" ; ++i, pos += 25 ) | 1089 | for ( int i = 0 ; menuOptions[currentMenuNr][i] != "" ; ++i, pos += 25 ) |
1090 | { | 1090 | { |
1091 | if ( currentMenuOption[currentMenuNr] == i ) | 1091 | if ( currentMenuOption[currentMenuNr] == i ) |
1092 | p.setPen( Qt::yellow ); | 1092 | p.setPen( Qt::yellow ); |
1093 | else | 1093 | else |
1094 | p.setPen( Qt::white ); | 1094 | p.setPen( Qt::white ); |
1095 | 1095 | ||
1096 | QString text; | 1096 | QString text; |
1097 | if ( menuOptions[currentMenuNr][i].find( "%s" ) != -1 ) | 1097 | if ( menuOptions[currentMenuNr][i].find( "%s" ) != -1 ) |
1098 | { | 1098 | { |
1099 | QString val; | 1099 | QString val; |
1100 | if ( i == MENU_GAME_TYPE ) | 1100 | if ( i == MENU_GAME_TYPE ) |
1101 | val = gameTypes[currentGameType]; | 1101 | val = gameTypes[currentGameType]; |
1102 | else | 1102 | else |
1103 | val = dificultyOption[currentGameDifficulty]; | 1103 | val = dificultyOption[currentGameDifficulty]; |
1104 | 1104 | ||
1105 | text.sprintf( (const char *)menuOptions[currentMenuNr][i], (const char *)val ); | 1105 | text.sprintf( (const char *)menuOptions[currentMenuNr][i], (const char *)val ); |
1106 | } | 1106 | } |
1107 | else | 1107 | else |
1108 | text = menuOptions[currentMenuNr][i]; | 1108 | text = menuOptions[currentMenuNr][i]; |
1109 | 1109 | ||
1110 | p.drawText( (sWidth/2) - (fm.width( text )/2), pos, text ); | 1110 | p.drawText( (sWidth/2) - (fm.width( text )/2), pos, text ); |
1111 | } | 1111 | } |
1112 | 1112 | ||
1113 | p.end(); | 1113 | p.end(); |
1114 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); | 1114 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); |
1115 | } | 1115 | } |
1116 | 1116 | ||
1117 | void SFCave :: dealWithMenuSelection() | 1117 | void SFCave :: dealWithMenuSelection() |
1118 | { | 1118 | { |
1119 | switch( currentMenuNr ) | 1119 | switch( currentMenuNr ) |
1120 | { | 1120 | { |
1121 | case MENU_MAIN_MENU: | 1121 | case MENU_MAIN_MENU: |
1122 | { | 1122 | { |
1123 | switch( currentMenuOption[currentMenuNr] ) | 1123 | switch( currentMenuOption[currentMenuNr] ) |
1124 | { | 1124 | { |
1125 | case MENU_START_GAME: | 1125 | case MENU_START_GAME: |
1126 | state = STATE_NEWGAME; | 1126 | state = STATE_NEWGAME; |
1127 | break; | 1127 | break; |
1128 | 1128 | ||
1129 | case MENU_REPLAY: | 1129 | case MENU_REPLAY: |
1130 | currentMenuNr = MENU_REPLAY_MENU; | 1130 | currentMenuNr = MENU_REPLAY_MENU; |
1131 | currentMenuOption[currentMenuNr] = 0; | 1131 | currentMenuOption[currentMenuNr] = 0; |
1132 | break; | 1132 | break; |
1133 | 1133 | ||
1134 | case MENU_OPTIONS: | 1134 | case MENU_OPTIONS: |
1135 | currentMenuNr = MENU_OPTIONS_MENU; | 1135 | currentMenuNr = MENU_OPTIONS_MENU; |
1136 | currentMenuOption[currentMenuNr] = 0; | 1136 | currentMenuOption[currentMenuNr] = 0; |
1137 | break; | 1137 | break; |
1138 | 1138 | ||
1139 | case MENU_HELP: | 1139 | case MENU_HELP: |
1140 | { | 1140 | { |
1141 | // Display Help Menu | 1141 | // Display Help Menu |
1142 | HelpWindow *win = new HelpWindow( ); | 1142 | HelpWindow *win = new HelpWindow( ); |
1143 | QPEApplication::showWidget( win ); | 1143 | QPEApplication::showWidget( win ); |
1144 | break; | 1144 | break; |
1145 | } | 1145 | } |
1146 | 1146 | ||
1147 | case MENU_QUIT: | 1147 | case MENU_QUIT: |
1148 | QApplication::exit(); | 1148 | QApplication::exit(); |
1149 | break; | 1149 | break; |
1150 | } | 1150 | } |
1151 | 1151 | ||
1152 | break; | 1152 | break; |
1153 | } | 1153 | } |
1154 | 1154 | ||
1155 | case MENU_OPTIONS_MENU: | 1155 | case MENU_OPTIONS_MENU: |
1156 | { | 1156 | { |
1157 | switch( currentMenuOption[currentMenuNr] ) | 1157 | switch( currentMenuOption[currentMenuNr] ) |
1158 | { | 1158 | { |
1159 | case MENU_GAME_TYPE: | 1159 | case MENU_GAME_TYPE: |
1160 | break; | 1160 | break; |
1161 | 1161 | ||
1162 | case MENU_GAME_DIFFICULTY: | 1162 | case MENU_GAME_DIFFICULTY: |
1163 | break; | 1163 | break; |
1164 | 1164 | ||
1165 | case MENU_CLEAR_HIGHSCORES: | 1165 | case MENU_CLEAR_HIGHSCORES: |
1166 | for ( int i = 0 ; i < 3 ; ++i ) | 1166 | for ( int i = 0 ; i < 3 ; ++i ) |
1167 | highestScore[currentGameType][i] = 0; | 1167 | highestScore[currentGameType][i] = 0; |
1168 | break; | 1168 | break; |
1169 | 1169 | ||
1170 | case MENU_BACK: | 1170 | case MENU_BACK: |
1171 | currentMenuNr = MENU_MAIN_MENU; | 1171 | currentMenuNr = MENU_MAIN_MENU; |
1172 | 1172 | ||
1173 | #ifdef QWS | 1173 | #ifdef QWS |
1174 | Config cfg( "sfcave" ); | 1174 | Config cfg( "sfcave" ); |
1175 | cfg.setGroup( "settings" ); | 1175 | cfg.setGroup( "settings" ); |
1176 | cfg.writeEntry( "difficulty", currentGameDifficulty ); | 1176 | cfg.writeEntry( "difficulty", currentGameDifficulty ); |
1177 | cfg.writeEntry( "gameType", currentGameType ); | 1177 | cfg.writeEntry( "gameType", currentGameType ); |
1178 | #endif | 1178 | #endif |
1179 | break; | 1179 | break; |
1180 | } | 1180 | } |
1181 | 1181 | ||
1182 | break; | 1182 | break; |
1183 | } | 1183 | } |
1184 | 1184 | ||
1185 | case MENU_REPLAY_MENU: | 1185 | case MENU_REPLAY_MENU: |
1186 | { | 1186 | { |
1187 | switch( currentMenuOption[currentMenuNr] ) | 1187 | switch( currentMenuOption[currentMenuNr] ) |
1188 | { | 1188 | { |
1189 | case MENU_REPLAY_START: | 1189 | case MENU_REPLAY_START: |
1190 | if ( currentSeed != 0 ) | 1190 | if ( currentSeed != 0 ) |
1191 | state = STATE_REPLAY; | 1191 | state = STATE_REPLAY; |
1192 | // Display No Replay | 1192 | // Display No Replay |
1193 | break; | 1193 | break; |
1194 | 1194 | ||
1195 | case MENU_REPLAY_LOAD: | 1195 | case MENU_REPLAY_LOAD: |
1196 | loadReplay(); | 1196 | loadReplay(); |
1197 | break; | 1197 | break; |
1198 | 1198 | ||
1199 | case MENU_REPLAY_SAVE: | 1199 | case MENU_REPLAY_SAVE: |
1200 | saveReplay(); | 1200 | saveReplay(); |
1201 | break; | 1201 | break; |
1202 | 1202 | ||
1203 | case MENU_REPLAY_BACK: | 1203 | case MENU_REPLAY_BACK: |
1204 | currentMenuNr = MENU_MAIN_MENU; | 1204 | currentMenuNr = MENU_MAIN_MENU; |
1205 | break; | 1205 | break; |
1206 | 1206 | ||
1207 | } | 1207 | } |
1208 | } | 1208 | } |
1209 | } | 1209 | } |
1210 | } | 1210 | } |
1211 | 1211 | ||
diff --git a/noncore/settings/aqpkg/settingsimpl.cpp b/noncore/settings/aqpkg/settingsimpl.cpp index 7ffa1d6..0886e69 100644 --- a/noncore/settings/aqpkg/settingsimpl.cpp +++ b/noncore/settings/aqpkg/settingsimpl.cpp | |||
@@ -1,490 +1,490 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | 3 | ||
4 | =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk> | 4 | =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk> |
5 | .=l. Dan Williams <drw@handhelds.org> | 5 | .=l. Dan Williams <drw@handhelds.org> |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This file is free software; you can | 7 | _;:, .> :=|. This file is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This file is distributed in the hope that | 14 | .i_,=:_. -<s. This file is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
19 | ..}^=.= = ; Public License for more details. | 19 | ..}^=.= = ; Public License for more details. |
20 | ++= -. .` .: | 20 | ++= -. .` .: |
21 | : = ...= . :.=- You should have received a copy of the GNU | 21 | : = ...= . :.=- You should have received a copy of the GNU |
22 | -. .:....=;==+<; General Public License along with this file; | 22 | -. .:....=;==+<; General Public License along with this file; |
23 | -_. . . )=. = see the file COPYING. If not, write to the | 23 | -_. . . )=. = see the file COPYING. If not, write to the |
24 | -- :-=` Free Software Foundation, Inc., | 24 | -- :-=` Free Software Foundation, Inc., |
25 | 59 Temple Place - Suite 330, | 25 | 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | 27 | ||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "settingsimpl.h" | 30 | #include "settingsimpl.h" |
31 | #include "global.h" | 31 | #include "global.h" |
32 | 32 | ||
33 | /* OPIE */ | 33 | /* OPIE */ |
34 | #include <opie2/otabwidget.h> | 34 | #include <opie2/otabwidget.h> |
35 | #include <opie2/oresource.h> | 35 | #include <opie2/oresource.h> |
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
37 | #include <qpe/qpeapplication.h> | 37 | #include <qpe/qpeapplication.h> |
38 | 38 | ||
39 | /* QT */ | 39 | /* QT */ |
40 | #include <qcheckbox.h> | 40 | #include <qcheckbox.h> |
41 | #include <qgroupbox.h> | 41 | #include <qgroupbox.h> |
42 | #include <qlabel.h> | 42 | #include <qlabel.h> |
43 | #include <qlayout.h> | 43 | #include <qlayout.h> |
44 | #include <qlineedit.h> | 44 | #include <qlineedit.h> |
45 | #include <qlistbox.h> | 45 | #include <qlistbox.h> |
46 | #include <qpushbutton.h> | 46 | #include <qpushbutton.h> |
47 | 47 | ||
48 | using namespace Opie::Ui; | 48 | using namespace Opie::Ui; |
49 | using namespace Opie::Ui; | 49 | using namespace Opie::Ui; |
50 | SettingsImpl :: SettingsImpl( DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl ) | 50 | SettingsImpl :: SettingsImpl( DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl ) |
51 | : QDialog( parent, name, modal, fl ) | 51 | : QDialog( parent, name, modal, fl ) |
52 | { | 52 | { |
53 | setCaption( tr( "Configuration" ) ); | 53 | setCaption( tr( "Configuration" ) ); |
54 | 54 | ||
55 | // Setup layout to make everything pretty | 55 | // Setup layout to make everything pretty |
56 | QVBoxLayout *layout = new QVBoxLayout( this ); | 56 | QVBoxLayout *layout = new QVBoxLayout( this ); |
57 | layout->setMargin( 2 ); | 57 | layout->setMargin( 2 ); |
58 | layout->setSpacing( 4 ); | 58 | layout->setSpacing( 4 ); |
59 | 59 | ||
60 | // Setup tabs for all info | 60 | // Setup tabs for all info |
61 | OTabWidget *tabwidget = new OTabWidget( this ); | 61 | OTabWidget *tabwidget = new OTabWidget( this ); |
62 | layout->addWidget( tabwidget ); | 62 | layout->addWidget( tabwidget ); |
63 | 63 | ||
64 | tabwidget->addTab( initServerTab(), "aqpkg/servertab", tr( "Servers" ) ); | 64 | tabwidget->addTab( initServerTab(), "aqpkg/servertab", tr( "Servers" ) ); |
65 | tabwidget->addTab( initDestinationTab(), "aqpkg/desttab", tr( "Destinations" ) ); | 65 | tabwidget->addTab( initDestinationTab(), "aqpkg/desttab", tr( "Destinations" ) ); |
66 | tabwidget->addTab( initProxyTab(), "aqpkg/proxytab", tr( "Proxies" ) ); | 66 | tabwidget->addTab( initProxyTab(), "aqpkg/proxytab", tr( "Proxies" ) ); |
67 | tabwidget->setCurrentTab( tr( "Servers" ) ); | 67 | tabwidget->setCurrentTab( tr( "Servers" ) ); |
68 | 68 | ||
69 | dataMgr = dataManager; | 69 | dataMgr = dataManager; |
70 | setupData(); | 70 | setupData(); |
71 | changed = false; | 71 | changed = false; |
72 | newserver = false; | 72 | newserver = false; |
73 | newdestination = false; | 73 | newdestination = false; |
74 | } | 74 | } |
75 | 75 | ||
76 | SettingsImpl :: ~SettingsImpl() | 76 | SettingsImpl :: ~SettingsImpl() |
77 | { | 77 | { |
78 | } | 78 | } |
79 | 79 | ||
80 | bool SettingsImpl :: showDlg() | 80 | bool SettingsImpl :: showDlg() |
81 | { | 81 | { |
82 | QPEApplication::execDialog( this ); | 82 | QPEApplication::execDialog( this ); |
83 | if ( changed ) | 83 | if ( changed ) |
84 | dataMgr->writeOutIpkgConf(); | 84 | dataMgr->writeOutIpkgConf(); |
85 | 85 | ||
86 | return changed; | 86 | return changed; |
87 | } | 87 | } |
88 | 88 | ||
89 | QWidget *SettingsImpl :: initServerTab() | 89 | QWidget *SettingsImpl :: initServerTab() |
90 | { | 90 | { |
91 | QWidget *control = new QWidget( this ); | 91 | QWidget *control = new QWidget( this ); |
92 | 92 | ||
93 | QVBoxLayout *vb = new QVBoxLayout( control ); | 93 | QVBoxLayout *vb = new QVBoxLayout( control ); |
94 | 94 | ||
95 | QScrollView *sv = new QScrollView( control ); | 95 | QScrollView *sv = new QScrollView( control ); |
96 | vb->addWidget( sv, 0, 0 ); | 96 | vb->addWidget( sv, 0, 0 ); |
97 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 97 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
98 | sv->setFrameStyle( QFrame::NoFrame ); | 98 | sv->setFrameStyle( QFrame::NoFrame ); |
99 | 99 | ||
100 | QWidget *container = new QWidget( sv->viewport() ); | 100 | QWidget *container = new QWidget( sv->viewport() ); |
101 | sv->addChild( container ); | 101 | sv->addChild( container ); |
102 | 102 | ||
103 | QGridLayout *layout = new QGridLayout( container ); | 103 | QGridLayout *layout = new QGridLayout( container ); |
104 | layout->setSpacing( 2 ); | 104 | layout->setSpacing( 2 ); |
105 | layout->setMargin( 4 ); | 105 | layout->setMargin( 4 ); |
106 | 106 | ||
107 | servers = new QListBox( container ); | 107 | servers = new QListBox( container ); |
108 | servers->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); | 108 | servers->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); |
109 | connect( servers, SIGNAL( highlighted(int) ), this, SLOT( editServer(int) ) ); | 109 | connect( servers, SIGNAL( highlighted(int) ), this, SLOT( editServer(int) ) ); |
110 | layout->addMultiCellWidget( servers, 0, 0, 0, 1 ); | 110 | layout->addMultiCellWidget( servers, 0, 0, 0, 1 ); |
111 | 111 | ||
112 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), | 112 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), |
113 | tr( "New" ), container ); | 113 | tr( "New" ), container ); |
114 | connect( btn, SIGNAL( clicked() ), this, SLOT( newServer() ) ); | 114 | connect( btn, SIGNAL( clicked() ), this, SLOT( newServer() ) ); |
115 | layout->addWidget( btn, 1, 0 ); | 115 | layout->addWidget( btn, 1, 0 ); |
116 | 116 | ||
117 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), container ); | 117 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), container ); |
118 | connect( btn, SIGNAL( clicked() ), this, SLOT( removeServer() ) ); | 118 | connect( btn, SIGNAL( clicked() ), this, SLOT( removeServer() ) ); |
119 | layout->addWidget( btn, 1, 1 ); | 119 | layout->addWidget( btn, 1, 1 ); |
120 | 120 | ||
121 | QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Server" ), container ); | 121 | QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Server" ), container ); |
122 | grpbox->layout()->setSpacing( 2 ); | 122 | grpbox->layout()->setSpacing( 2 ); |
123 | grpbox->layout()->setMargin( 4 ); | 123 | grpbox->layout()->setMargin( 4 ); |
124 | layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 ); | 124 | layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 ); |
125 | 125 | ||
126 | QGridLayout *grplayout = new QGridLayout( grpbox->layout() ); | 126 | QGridLayout *grplayout = new QGridLayout( grpbox->layout() ); |
127 | 127 | ||
128 | QLabel *label = new QLabel( tr( "Name:" ), grpbox ); | 128 | QLabel *label = new QLabel( tr( "Name:" ), grpbox ); |
129 | grplayout->addWidget( label, 0, 0 ); | 129 | grplayout->addWidget( label, 0, 0 ); |
130 | servername = new QLineEdit( grpbox ); | 130 | servername = new QLineEdit( grpbox ); |
131 | grplayout->addWidget( servername, 0, 1 ); | 131 | grplayout->addWidget( servername, 0, 1 ); |
132 | 132 | ||
133 | label = new QLabel( tr( "Address:" ), grpbox ); | 133 | label = new QLabel( tr( "Address:" ), grpbox ); |
134 | grplayout->addWidget( label, 1, 0 ); | 134 | grplayout->addWidget( label, 1, 0 ); |
135 | serverurl = new QLineEdit( grpbox ); | 135 | serverurl = new QLineEdit( grpbox ); |
136 | grplayout->addWidget( serverurl, 1, 1 ); | 136 | grplayout->addWidget( serverurl, 1, 1 ); |
137 | 137 | ||
138 | active = new QCheckBox( tr( "Active Server" ), grpbox ); | 138 | active = new QCheckBox( tr( "Active Server" ), grpbox ); |
139 | grplayout->addMultiCellWidget( active, 2, 2, 0, 1 ); | 139 | grplayout->addMultiCellWidget( active, 2, 2, 0, 1 ); |
140 | 140 | ||
141 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), grpbox ); | 141 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), grpbox ); |
142 | connect( btn, SIGNAL( clicked() ), this, SLOT( changeServerDetails() ) ); | 142 | connect( btn, SIGNAL( clicked() ), this, SLOT( changeServerDetails() ) ); |
143 | grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 ); | 143 | grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 ); |
144 | 144 | ||
145 | return control; | 145 | return control; |
146 | } | 146 | } |
147 | 147 | ||
148 | QWidget *SettingsImpl :: initDestinationTab() | 148 | QWidget *SettingsImpl :: initDestinationTab() |
149 | { | 149 | { |
150 | QWidget *control = new QWidget( this ); | 150 | QWidget *control = new QWidget( this ); |
151 | 151 | ||
152 | QVBoxLayout *vb = new QVBoxLayout( control ); | 152 | QVBoxLayout *vb = new QVBoxLayout( control ); |
153 | 153 | ||
154 | QScrollView *sv = new QScrollView( control ); | 154 | QScrollView *sv = new QScrollView( control ); |
155 | vb->addWidget( sv, 0, 0 ); | 155 | vb->addWidget( sv, 0, 0 ); |
156 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 156 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
157 | sv->setFrameStyle( QFrame::NoFrame ); | 157 | sv->setFrameStyle( QFrame::NoFrame ); |
158 | 158 | ||
159 | QWidget *container = new QWidget( sv->viewport() ); | 159 | QWidget *container = new QWidget( sv->viewport() ); |
160 | sv->addChild( container ); | 160 | sv->addChild( container ); |
161 | 161 | ||
162 | QGridLayout *layout = new QGridLayout( container ); | 162 | QGridLayout *layout = new QGridLayout( container ); |
163 | layout->setSpacing( 2 ); | 163 | layout->setSpacing( 2 ); |
164 | layout->setMargin( 4 ); | 164 | layout->setMargin( 4 ); |
165 | 165 | ||
166 | destinations = new QListBox( container ); | 166 | destinations = new QListBox( container ); |
167 | destinations->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); | 167 | destinations->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); |
168 | connect( destinations, SIGNAL( highlighted(int) ), this, SLOT( editDestination(int) ) ); | 168 | connect( destinations, SIGNAL( highlighted(int) ), this, SLOT( editDestination(int) ) ); |
169 | layout->addMultiCellWidget( destinations, 0, 0, 0, 1 ); | 169 | layout->addMultiCellWidget( destinations, 0, 0, 0, 1 ); |
170 | 170 | ||
171 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), tr( "New" ), container ); | 171 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), tr( "New" ), container ); |
172 | connect( btn, SIGNAL( clicked() ), this, SLOT( newDestination() ) ); | 172 | connect( btn, SIGNAL( clicked() ), this, SLOT( newDestination() ) ); |
173 | layout->addWidget( btn, 1, 0 ); | 173 | layout->addWidget( btn, 1, 0 ); |
174 | 174 | ||
175 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), container ); | 175 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), container ); |
176 | connect( btn, SIGNAL( clicked() ), this, SLOT( removeDestination() ) ); | 176 | connect( btn, SIGNAL( clicked() ), this, SLOT( removeDestination() ) ); |
177 | layout->addWidget( btn, 1, 1 ); | 177 | layout->addWidget( btn, 1, 1 ); |
178 | 178 | ||
179 | QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Destination" ), container ); | 179 | QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Destination" ), container ); |
180 | grpbox->layout()->setSpacing( 2 ); | 180 | grpbox->layout()->setSpacing( 2 ); |
181 | grpbox->layout()->setMargin( 4 ); | 181 | grpbox->layout()->setMargin( 4 ); |
182 | layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 ); | 182 | layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 ); |
183 | 183 | ||
184 | QGridLayout *grplayout = new QGridLayout( grpbox->layout() ); | 184 | QGridLayout *grplayout = new QGridLayout( grpbox->layout() ); |
185 | 185 | ||
186 | QLabel *label = new QLabel( tr( "Name:" ), grpbox ); | 186 | QLabel *label = new QLabel( tr( "Name:" ), grpbox ); |
187 | grplayout->addWidget( label, 0, 0 ); | 187 | grplayout->addWidget( label, 0, 0 ); |
188 | destinationname = new QLineEdit( grpbox ); | 188 | destinationname = new QLineEdit( grpbox ); |
189 | grplayout->addWidget( destinationname, 0, 1 ); | 189 | grplayout->addWidget( destinationname, 0, 1 ); |
190 | 190 | ||
191 | label = new QLabel( tr( "Location:" ), grpbox ); | 191 | label = new QLabel( tr( "Location:" ), grpbox ); |
192 | grplayout->addWidget( label, 1, 0 ); | 192 | grplayout->addWidget( label, 1, 0 ); |
193 | destinationurl = new QLineEdit( grpbox ); | 193 | destinationurl = new QLineEdit( grpbox ); |
194 | grplayout->addWidget( destinationurl, 1, 1 ); | 194 | grplayout->addWidget( destinationurl, 1, 1 ); |
195 | 195 | ||
196 | linkToRoot = new QCheckBox( tr( "Link to root" ), grpbox ); | 196 | linkToRoot = new QCheckBox( tr( "Link to root" ), grpbox ); |
197 | grplayout->addMultiCellWidget( linkToRoot, 2, 2, 0, 1 ); | 197 | grplayout->addMultiCellWidget( linkToRoot, 2, 2, 0, 1 ); |
198 | 198 | ||
199 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), grpbox ); | 199 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), grpbox ); |
200 | connect( btn, SIGNAL( clicked() ), this, SLOT( changeDestinationDetails() ) ); | 200 | connect( btn, SIGNAL( clicked() ), this, SLOT( changeDestinationDetails() ) ); |
201 | grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 ); | 201 | grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 ); |
202 | 202 | ||
203 | return control; | 203 | return control; |
204 | } | 204 | } |
205 | 205 | ||
206 | QWidget *SettingsImpl :: initProxyTab() | 206 | QWidget *SettingsImpl :: initProxyTab() |
207 | { | 207 | { |
208 | QWidget *control = new QWidget( this ); | 208 | QWidget *control = new QWidget( this ); |
209 | 209 | ||
210 | QVBoxLayout *vb = new QVBoxLayout( control ); | 210 | QVBoxLayout *vb = new QVBoxLayout( control ); |
211 | 211 | ||
212 | QScrollView *sv = new QScrollView( control ); | 212 | QScrollView *sv = new QScrollView( control ); |
213 | vb->addWidget( sv, 0, 0 ); | 213 | vb->addWidget( sv, 0, 0 ); |
214 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 214 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
215 | sv->setFrameStyle( QFrame::NoFrame ); | 215 | sv->setFrameStyle( QFrame::NoFrame ); |
216 | 216 | ||
217 | QWidget *container = new QWidget( sv->viewport() ); | 217 | QWidget *container = new QWidget( sv->viewport() ); |
218 | sv->addChild( container ); | 218 | sv->addChild( container ); |
219 | 219 | ||
220 | QGridLayout *layout = new QGridLayout( container ); | 220 | QGridLayout *layout = new QGridLayout( container ); |
221 | layout->setSpacing( 2 ); | 221 | layout->setSpacing( 2 ); |
222 | layout->setMargin( 4 ); | 222 | layout->setMargin( 4 ); |
223 | 223 | ||
224 | QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "HTTP Proxy" ), container ); | 224 | QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "HTTP Proxy" ), container ); |
225 | grpbox->layout()->setSpacing( 2 ); | 225 | grpbox->layout()->setSpacing( 2 ); |
226 | grpbox->layout()->setMargin( 4 ); | 226 | grpbox->layout()->setMargin( 4 ); |
227 | layout->addMultiCellWidget( grpbox, 0, 0, 0, 1 ); | 227 | layout->addMultiCellWidget( grpbox, 0, 0, 0, 1 ); |
228 | QVBoxLayout *grplayout = new QVBoxLayout( grpbox->layout() ); | 228 | QVBoxLayout *grplayout = new QVBoxLayout( grpbox->layout() ); |
229 | txtHttpProxy = new QLineEdit( grpbox ); | 229 | txtHttpProxy = new QLineEdit( grpbox ); |
230 | grplayout->addWidget( txtHttpProxy ); | 230 | grplayout->addWidget( txtHttpProxy ); |
231 | chkHttpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox ); | 231 | chkHttpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox ); |
232 | grplayout->addWidget( chkHttpProxyEnabled ); | 232 | grplayout->addWidget( chkHttpProxyEnabled ); |
233 | 233 | ||
234 | grpbox = new QGroupBox( 0, Qt::Vertical, tr( "FTP Proxy" ), container ); | 234 | grpbox = new QGroupBox( 0, Qt::Vertical, tr( "FTP Proxy" ), container ); |
235 | grpbox->layout()->setSpacing( 2 ); | 235 | grpbox->layout()->setSpacing( 2 ); |
236 | grpbox->layout()->setMargin( 4 ); | 236 | grpbox->layout()->setMargin( 4 ); |
237 | layout->addMultiCellWidget( grpbox, 1, 1, 0, 1 ); | 237 | layout->addMultiCellWidget( grpbox, 1, 1, 0, 1 ); |
238 | grplayout = new QVBoxLayout( grpbox->layout() ); | 238 | grplayout = new QVBoxLayout( grpbox->layout() ); |
239 | txtFtpProxy = new QLineEdit( grpbox ); | 239 | txtFtpProxy = new QLineEdit( grpbox ); |
240 | grplayout->addWidget( txtFtpProxy ); | 240 | grplayout->addWidget( txtFtpProxy ); |
241 | chkFtpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox ); | 241 | chkFtpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox ); |
242 | grplayout->addWidget( chkFtpProxyEnabled ); | 242 | grplayout->addWidget( chkFtpProxyEnabled ); |
243 | 243 | ||
244 | QLabel *label = new QLabel( tr( "Username:" ), container ); | 244 | QLabel *label = new QLabel( tr( "Username:" ), container ); |
245 | layout->addWidget( label, 2, 0 ); | 245 | layout->addWidget( label, 2, 0 ); |
246 | txtUsername = new QLineEdit( container ); | 246 | txtUsername = new QLineEdit( container ); |
247 | layout->addWidget( txtUsername, 2, 1 ); | 247 | layout->addWidget( txtUsername, 2, 1 ); |
248 | 248 | ||
249 | label = new QLabel( tr( "Password:" ), container ); | 249 | label = new QLabel( tr( "Password:" ), container ); |
250 | layout->addWidget( label, 3, 0 ); | 250 | layout->addWidget( label, 3, 0 ); |
251 | txtPassword = new QLineEdit( container ); | 251 | txtPassword = new QLineEdit( container ); |
252 | layout->addWidget( txtPassword, 3, 1 ); | 252 | layout->addWidget( txtPassword, 3, 1 ); |
253 | 253 | ||
254 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), container ); | 254 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), container ); |
255 | connect( btn, SIGNAL( clicked() ), this, SLOT( proxyApplyChanges() ) ); | 255 | connect( btn, SIGNAL( clicked() ), this, SLOT( proxyApplyChanges() ) ); |
256 | layout->addMultiCellWidget( btn, 4, 4, 0, 1 ); | 256 | layout->addMultiCellWidget( btn, 4, 4, 0, 1 ); |
257 | 257 | ||
258 | return control; | 258 | return control; |
259 | } | 259 | } |
260 | 260 | ||
261 | void SettingsImpl :: setupData() | 261 | void SettingsImpl :: setupData() |
262 | { | 262 | { |
263 | // add servers | 263 | // add servers |
264 | QString serverName; | 264 | QString serverName; |
265 | QListIterator<Server> it( dataMgr->getServerList() ); | 265 | QListIterator<Server> it( dataMgr->getServerList() ); |
266 | for ( ; it.current(); ++it ) | 266 | for ( ; it.current(); ++it ) |
267 | { | 267 | { |
268 | serverName = it.current()->getServerName(); | 268 | serverName = it.current()->getServerName(); |
269 | if ( serverName == LOCAL_SERVER || serverName == LOCAL_IPKGS ) | 269 | if ( serverName == LOCAL_SERVER || serverName == LOCAL_IPKGS ) |
270 | continue; | 270 | continue; |
271 | 271 | ||
272 | servers->insertItem( serverName ); | 272 | servers->insertItem( serverName ); |
273 | } | 273 | } |
274 | 274 | ||
275 | 275 | ||
276 | // add destinations | 276 | // add destinations |
277 | QListIterator<Destination> it2( dataMgr->getDestinationList() ); | 277 | QListIterator<Destination> it2( dataMgr->getDestinationList() ); |
278 | for ( ; it2.current(); ++it2 ) | 278 | for ( ; it2.current(); ++it2 ) |
279 | destinations->insertItem( it2.current()->getDestinationName() ); | 279 | destinations->insertItem( it2.current()->getDestinationName() ); |
280 | 280 | ||
281 | // setup proxy tab | 281 | // setup proxy tab |
282 | txtHttpProxy->setText( dataMgr->getHttpProxy() ); | 282 | txtHttpProxy->setText( dataMgr->getHttpProxy() ); |
283 | txtFtpProxy->setText( dataMgr->getFtpProxy() ); | 283 | txtFtpProxy->setText( dataMgr->getFtpProxy() ); |
284 | txtUsername->setText( dataMgr->getProxyUsername() ); | 284 | txtUsername->setText( dataMgr->getProxyUsername() ); |
285 | txtPassword->setText( dataMgr->getProxyPassword() ); | 285 | txtPassword->setText( dataMgr->getProxyPassword() ); |
286 | chkHttpProxyEnabled->setChecked( dataMgr->getHttpProxyEnabled() ); | 286 | chkHttpProxyEnabled->setChecked( dataMgr->getHttpProxyEnabled() ); |
287 | chkFtpProxyEnabled->setChecked( dataMgr->getFtpProxyEnabled() ); | 287 | chkFtpProxyEnabled->setChecked( dataMgr->getFtpProxyEnabled() ); |
288 | } | 288 | } |
289 | 289 | ||
290 | //------------------ Servers tab ---------------------- | 290 | //------------------ Servers tab ---------------------- |
291 | 291 | ||
292 | void SettingsImpl :: editServer( int sel ) | 292 | void SettingsImpl :: editServer( int sel ) |
293 | { | 293 | { |
294 | currentSelectedServer = sel; | 294 | currentSelectedServer = sel; |
295 | Server *s = dataMgr->getServer( servers->currentText() ); | 295 | Server *s = dataMgr->getServer( servers->currentText() ); |
296 | if ( s ) | 296 | if ( s ) |
297 | { | 297 | { |
298 | serverName = s->getServerName(); | 298 | serverName = s->getServerName(); |
299 | servername->setText( s->getServerName() ); | 299 | servername->setText( s->getServerName() ); |
300 | serverurl->setText( s->getServerUrl() ); | 300 | serverurl->setText( s->getServerUrl() ); |
301 | active->setChecked( s->isServerActive() ); | 301 | active->setChecked( s->isServerActive() ); |
302 | } | 302 | } |
303 | else | 303 | else |
304 | { | 304 | { |
305 | serverName = ""; | 305 | serverName = ""; |
306 | servername->setText( "" ); | 306 | servername->setText( "" ); |
307 | serverurl->setText( "" ); | 307 | serverurl->setText( "" ); |
308 | active->setChecked( false ); | 308 | active->setChecked( false ); |
309 | } | 309 | } |
310 | } | 310 | } |
311 | 311 | ||
312 | void SettingsImpl :: newServer() | 312 | void SettingsImpl :: newServer() |
313 | { | 313 | { |
314 | newserver = true; | 314 | newserver = true; |
315 | servername->setText( "" ); | 315 | servername->setText( "" ); |
316 | serverurl->setText( "" ); | 316 | serverurl->setText( "" ); |
317 | servername->setFocus(); | 317 | servername->setFocus(); |
318 | active->setChecked( true ); | 318 | active->setChecked( true ); |
319 | } | 319 | } |
320 | 320 | ||
321 | void SettingsImpl :: removeServer() | 321 | void SettingsImpl :: removeServer() |
322 | { | 322 | { |
323 | changed = true; | 323 | changed = true; |
324 | Server *s = dataMgr->getServer( servers->currentText() ); | 324 | Server *s = dataMgr->getServer( servers->currentText() ); |
325 | if ( s ) | 325 | if ( s ) |
326 | { | 326 | { |
327 | dataMgr->getServerList().removeRef( s ); | 327 | dataMgr->getServerList().removeRef( s ); |
328 | servers->removeItem( currentSelectedServer ); | 328 | servers->removeItem( currentSelectedServer ); |
329 | } | 329 | } |
330 | } | 330 | } |
331 | 331 | ||
332 | void SettingsImpl :: changeServerDetails() | 332 | void SettingsImpl :: changeServerDetails() |
333 | { | 333 | { |
334 | changed = true; | 334 | changed = true; |
335 | 335 | ||
336 | QString newName = servername->text(); | 336 | QString newName = servername->text(); |
337 | 337 | ||
338 | // Convert any spaces to underscores | 338 | // Convert any spaces to underscores |
339 | char *tmpStr = new char[newName.length() + 1]; | 339 | char *tmpStr = new char[newName.length() + 1]; |
340 | for ( unsigned int i = 0 ; i < newName.length() ; ++i ) | 340 | for ( unsigned int i = 0 ; i < newName.length() ; ++i ) |
341 | { | 341 | { |
342 | if ( newName[i] == ' ' ) | 342 | if ( newName[i] == ' ' ) |
343 | tmpStr[i] = '_'; | 343 | tmpStr[i] = '_'; |
344 | else | 344 | else |
345 | tmpStr[i] = newName[i].latin1(); | 345 | tmpStr[i] = newName[i].latin1(); |
346 | } | 346 | } |
347 | tmpStr[newName.length()] = '\0'; | 347 | tmpStr[newName.length()] = '\0'; |
348 | 348 | ||
349 | newName = tmpStr; | 349 | newName = tmpStr; |
350 | delete tmpStr; | 350 | delete [] tmpStr; |
351 | 351 | ||
352 | if ( !newserver ) | 352 | if ( !newserver ) |
353 | { | 353 | { |
354 | Server *s = dataMgr->getServer( servers->currentText() ); | 354 | Server *s = dataMgr->getServer( servers->currentText() ); |
355 | if ( s ) | 355 | if ( s ) |
356 | { | 356 | { |
357 | // Update url | 357 | // Update url |
358 | s->setServerUrl( serverurl->text() ); | 358 | s->setServerUrl( serverurl->text() ); |
359 | s->setActive( active->isChecked() ); | 359 | s->setActive( active->isChecked() ); |
360 | 360 | ||
361 | // Check if server name has changed, if it has then we need to replace the key in the map | 361 | // Check if server name has changed, if it has then we need to replace the key in the map |
362 | if ( serverName != newName ) | 362 | if ( serverName != newName ) |
363 | { | 363 | { |
364 | // Update server name | 364 | // Update server name |
365 | s->setServerName( newName ); | 365 | s->setServerName( newName ); |
366 | } | 366 | } |
367 | 367 | ||
368 | // Update list box | 368 | // Update list box |
369 | servers->changeItem( newName, currentSelectedServer ); | 369 | servers->changeItem( newName, currentSelectedServer ); |
370 | } | 370 | } |
371 | } | 371 | } |
372 | else | 372 | else |
373 | { | 373 | { |
374 | Server s( newName, serverurl->text() ); | 374 | Server s( newName, serverurl->text() ); |
375 | dataMgr->getServerList().append( new Server( newName, serverurl->text() ) ); | 375 | dataMgr->getServerList().append( new Server( newName, serverurl->text() ) ); |
376 | dataMgr->getServerList().last()->setActive( active->isChecked() ); | 376 | dataMgr->getServerList().last()->setActive( active->isChecked() ); |
377 | servers->insertItem( newName ); | 377 | servers->insertItem( newName ); |
378 | servers->setCurrentItem( servers->count() ); | 378 | servers->setCurrentItem( servers->count() ); |
379 | newserver = false; | 379 | newserver = false; |
380 | } | 380 | } |
381 | } | 381 | } |
382 | 382 | ||
383 | //------------------ Destinations tab ---------------------- | 383 | //------------------ Destinations tab ---------------------- |
384 | 384 | ||
385 | void SettingsImpl :: editDestination( int sel ) | 385 | void SettingsImpl :: editDestination( int sel ) |
386 | { | 386 | { |
387 | currentSelectedDestination = sel; | 387 | currentSelectedDestination = sel; |
388 | Destination *d = dataMgr->getDestination( destinations->currentText() ); | 388 | Destination *d = dataMgr->getDestination( destinations->currentText() ); |
389 | if ( d ) | 389 | if ( d ) |
390 | { | 390 | { |
391 | destinationName = d->getDestinationName(); | 391 | destinationName = d->getDestinationName(); |
392 | destinationname->setText( d->getDestinationName() ); | 392 | destinationname->setText( d->getDestinationName() ); |
393 | destinationurl->setText( d->getDestinationPath() ); | 393 | destinationurl->setText( d->getDestinationPath() ); |
394 | linkToRoot->setChecked( d->linkToRoot() ); | 394 | linkToRoot->setChecked( d->linkToRoot() ); |
395 | } | 395 | } |
396 | else | 396 | else |
397 | { | 397 | { |
398 | destinationName = ""; | 398 | destinationName = ""; |
399 | destinationname->setText( "" ); | 399 | destinationname->setText( "" ); |
400 | destinationurl->setText( "" ); | 400 | destinationurl->setText( "" ); |
401 | linkToRoot->setChecked( false ); | 401 | linkToRoot->setChecked( false ); |
402 | } | 402 | } |
403 | } | 403 | } |
404 | 404 | ||
405 | void SettingsImpl :: newDestination() | 405 | void SettingsImpl :: newDestination() |
406 | { | 406 | { |
407 | newdestination = true; | 407 | newdestination = true; |
408 | destinationname->setText( "" ); | 408 | destinationname->setText( "" ); |
409 | destinationurl->setText( "" ); | 409 | destinationurl->setText( "" ); |
410 | destinationname->setFocus(); | 410 | destinationname->setFocus(); |
411 | linkToRoot->setChecked( true ); | 411 | linkToRoot->setChecked( true ); |
412 | } | 412 | } |
413 | 413 | ||
414 | void SettingsImpl :: removeDestination() | 414 | void SettingsImpl :: removeDestination() |
415 | { | 415 | { |
416 | changed = true; | 416 | changed = true; |
417 | Destination *d = dataMgr->getDestination( destinations->currentText() ); | 417 | Destination *d = dataMgr->getDestination( destinations->currentText() ); |
418 | if ( d ) | 418 | if ( d ) |
419 | { | 419 | { |
420 | dataMgr->getDestinationList().removeRef( d ); | 420 | dataMgr->getDestinationList().removeRef( d ); |
421 | destinations->removeItem( currentSelectedDestination ); | 421 | destinations->removeItem( currentSelectedDestination ); |
422 | } | 422 | } |
423 | } | 423 | } |
424 | 424 | ||
425 | void SettingsImpl :: changeDestinationDetails() | 425 | void SettingsImpl :: changeDestinationDetails() |
426 | { | 426 | { |
427 | changed = true; | 427 | changed = true; |
428 | 428 | ||
429 | #ifdef QWS | 429 | #ifdef QWS |
430 | Config cfg( "aqpkg" ); | 430 | Config cfg( "aqpkg" ); |
431 | cfg.setGroup( "destinations" ); | 431 | cfg.setGroup( "destinations" ); |
432 | #endif | 432 | #endif |
433 | 433 | ||
434 | QString newName = destinationname->text(); | 434 | QString newName = destinationname->text(); |
435 | if ( !newdestination ) | 435 | if ( !newdestination ) |
436 | { | 436 | { |
437 | Destination *d = dataMgr->getDestination( destinations->currentText() ); | 437 | Destination *d = dataMgr->getDestination( destinations->currentText() ); |
438 | if ( d ) | 438 | if ( d ) |
439 | { | 439 | { |
440 | // Update url | 440 | // Update url |
441 | d->setDestinationPath( destinationurl->text() ); | 441 | d->setDestinationPath( destinationurl->text() ); |
442 | d->linkToRoot( linkToRoot->isChecked() ); | 442 | d->linkToRoot( linkToRoot->isChecked() ); |
443 | 443 | ||
444 | // Check if server name has changed, if it has then we need to replace the key in the map | 444 | // Check if server name has changed, if it has then we need to replace the key in the map |
445 | if ( destinationName != newName ) | 445 | if ( destinationName != newName ) |
446 | { | 446 | { |
447 | // Update server name | 447 | // Update server name |
448 | d->setDestinationName( newName ); | 448 | d->setDestinationName( newName ); |
449 | 449 | ||
450 | // Update list box | 450 | // Update list box |
451 | destinations->changeItem( newName, currentSelectedDestination ); | 451 | destinations->changeItem( newName, currentSelectedDestination ); |
452 | } | 452 | } |
453 | 453 | ||
454 | #ifdef QWS | 454 | #ifdef QWS |
455 | QString key = newName; | 455 | QString key = newName; |
456 | key += "_linkToRoot"; | 456 | key += "_linkToRoot"; |
457 | int val = d->linkToRoot(); | 457 | int val = d->linkToRoot(); |
458 | cfg.writeEntry( key, val ); | 458 | cfg.writeEntry( key, val ); |
459 | #endif | 459 | #endif |
460 | 460 | ||
461 | } | 461 | } |
462 | } | 462 | } |
463 | else | 463 | else |
464 | { | 464 | { |
465 | dataMgr->getDestinationList().append( new Destination( newName, destinationurl->text() ) ); | 465 | dataMgr->getDestinationList().append( new Destination( newName, destinationurl->text() ) ); |
466 | destinations->insertItem( newName ); | 466 | destinations->insertItem( newName ); |
467 | destinations->setCurrentItem( destinations->count() ); | 467 | destinations->setCurrentItem( destinations->count() ); |
468 | newdestination = false; | 468 | newdestination = false; |
469 | 469 | ||
470 | #ifdef QWS | 470 | #ifdef QWS |
471 | QString key = newName; | 471 | QString key = newName; |
472 | key += "_linkToRoot"; | 472 | key += "_linkToRoot"; |
473 | cfg.writeEntry( key, true ); | 473 | cfg.writeEntry( key, true ); |
474 | #endif | 474 | #endif |
475 | 475 | ||
476 | } | 476 | } |
477 | } | 477 | } |
478 | 478 | ||
479 | //------------------ Proxy tab ---------------------- | 479 | //------------------ Proxy tab ---------------------- |
480 | void SettingsImpl :: proxyApplyChanges() | 480 | void SettingsImpl :: proxyApplyChanges() |
481 | { | 481 | { |
482 | changed = true; | 482 | changed = true; |
483 | dataMgr->setHttpProxy( txtHttpProxy->text() ); | 483 | dataMgr->setHttpProxy( txtHttpProxy->text() ); |
484 | dataMgr->setFtpProxy( txtFtpProxy->text() ); | 484 | dataMgr->setFtpProxy( txtFtpProxy->text() ); |
485 | dataMgr->setProxyUsername( txtUsername->text() ); | 485 | dataMgr->setProxyUsername( txtUsername->text() ); |
486 | dataMgr->setProxyPassword( txtPassword->text() ); | 486 | dataMgr->setProxyPassword( txtPassword->text() ); |
487 | 487 | ||
488 | dataMgr->setHttpProxyEnabled( chkHttpProxyEnabled->isChecked() ); | 488 | dataMgr->setHttpProxyEnabled( chkHttpProxyEnabled->isChecked() ); |
489 | dataMgr->setFtpProxyEnabled( chkFtpProxyEnabled->isChecked() ); | 489 | dataMgr->setFtpProxyEnabled( chkFtpProxyEnabled->isChecked() ); |
490 | } | 490 | } |
diff --git a/noncore/settings/aqpkg/version.cpp b/noncore/settings/aqpkg/version.cpp index 59e6f3f..ce2de7b 100644 --- a/noncore/settings/aqpkg/version.cpp +++ b/noncore/settings/aqpkg/version.cpp | |||
@@ -1,219 +1,219 @@ | |||
1 | /* | 1 | /* |
2 | * libdpkg - Debian packaging suite library routines | 2 | * libdpkg - Debian packaging suite library routines |
3 | * vercmp.c - comparison of version numbers | 3 | * vercmp.c - comparison of version numbers |
4 | * | 4 | * |
5 | * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk> | 5 | * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk> |
6 | * | 6 | * |
7 | * This is free software; you can redistribute it and/or modify | 7 | * This is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as | 8 | * it under the terms of the GNU General Public License as |
9 | * published by the Free Software Foundation; either version 2, | 9 | * published by the Free Software Foundation; either version 2, |
10 | * or (at your option) any later version. | 10 | * or (at your option) any later version. |
11 | * | 11 | * |
12 | * This is distributed in the hope that it will be useful, but | 12 | * This is distributed in the hope that it will be useful, but |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. | 15 | * GNU General Public License for more details. |
16 | * | 16 | * |
17 | * You should have received a copy of the GNU General Public | 17 | * You should have received a copy of the GNU General Public |
18 | * License along with dpkg; if not, write to the Free Software | 18 | * License along with dpkg; if not, write to the Free Software |
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | */ | 20 | */ |
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <ctype.h> | 23 | #include <ctype.h> |
24 | #include <string.h> | 24 | #include <string.h> |
25 | 25 | ||
26 | #include <qobject.h> | 26 | #include <qobject.h> |
27 | 27 | ||
28 | //# define _(Text) Text | 28 | //# define _(Text) Text |
29 | 29 | ||
30 | class versionrevision | 30 | class versionrevision |
31 | { | 31 | { |
32 | public: | 32 | public: |
33 | versionrevision() | 33 | versionrevision() |
34 | { | 34 | { |
35 | version = 0; | 35 | version = 0; |
36 | } | 36 | } |
37 | 37 | ||
38 | ~versionrevision() | 38 | ~versionrevision() |
39 | { | 39 | { |
40 | if ( version ) | 40 | if ( version ) |
41 | delete version; | 41 | delete [] version; |
42 | } | 42 | } |
43 | 43 | ||
44 | void setVersion( const char *str ) | 44 | void setVersion( const char *str ) |
45 | { | 45 | { |
46 | version = new char[(strlen(str)+1)]; | 46 | version = new char[(strlen(str)+1)]; |
47 | strcpy( version, str ); | 47 | strcpy( version, str ); |
48 | } | 48 | } |
49 | 49 | ||
50 | unsigned long epoch; | 50 | unsigned long epoch; |
51 | char *version; | 51 | char *version; |
52 | const char *revision; | 52 | const char *revision; |
53 | const char *familiar_revision; | 53 | const char *familiar_revision; |
54 | }; | 54 | }; |
55 | 55 | ||
56 | static int verrevcmp(const char *val, const char *ref) | 56 | static int verrevcmp(const char *val, const char *ref) |
57 | { | 57 | { |
58 | int vc, rc; | 58 | int vc, rc; |
59 | long vl, rl; | 59 | long vl, rl; |
60 | const char *vp, *rp; | 60 | const char *vp, *rp; |
61 | 61 | ||
62 | if (!val) val= ""; | 62 | if (!val) val= ""; |
63 | if (!ref) ref= ""; | 63 | if (!ref) ref= ""; |
64 | for (;;) { | 64 | for (;;) { |
65 | vp= val; while (*vp && !isdigit(*vp)) vp++; | 65 | vp= val; while (*vp && !isdigit(*vp)) vp++; |
66 | rp= ref; while (*rp && !isdigit(*rp)) rp++; | 66 | rp= ref; while (*rp && !isdigit(*rp)) rp++; |
67 | for (;;) { | 67 | for (;;) { |
68 | vc= val == vp ? 0 : *val++; | 68 | vc= val == vp ? 0 : *val++; |
69 | rc= ref == rp ? 0 : *ref++; | 69 | rc= ref == rp ? 0 : *ref++; |
70 | if (!rc && !vc) break; | 70 | if (!rc && !vc) break; |
71 | if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */ | 71 | if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */ |
72 | if (rc && !isalpha(rc)) rc += 256; | 72 | if (rc && !isalpha(rc)) rc += 256; |
73 | if (vc != rc) return vc - rc; | 73 | if (vc != rc) return vc - rc; |
74 | } | 74 | } |
75 | val= vp; | 75 | val= vp; |
76 | ref= rp; | 76 | ref= rp; |
77 | vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10); | 77 | vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10); |
78 | rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10); | 78 | rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10); |
79 | if (vl != rl) return vl - rl; | 79 | if (vl != rl) return vl - rl; |
80 | if (!*val && !*ref) return 0; | 80 | if (!*val && !*ref) return 0; |
81 | if (!*val) return -1; | 81 | if (!*val) return -1; |
82 | if (!*ref) return +1; | 82 | if (!*ref) return +1; |
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | int versioncompare(const struct versionrevision *version, | 86 | int versioncompare(const struct versionrevision *version, |
87 | const struct versionrevision *refversion) | 87 | const struct versionrevision *refversion) |
88 | { | 88 | { |
89 | int r; | 89 | int r; |
90 | 90 | ||
91 | if (version->epoch > refversion->epoch) return 1; | 91 | if (version->epoch > refversion->epoch) return 1; |
92 | if (version->epoch < refversion->epoch) return -1; | 92 | if (version->epoch < refversion->epoch) return -1; |
93 | r= verrevcmp(version->version,refversion->version); if (r) return r; | 93 | r= verrevcmp(version->version,refversion->version); if (r) return r; |
94 | r= verrevcmp(version->revision,refversion->revision); if (r) return r; | 94 | r= verrevcmp(version->revision,refversion->revision); if (r) return r; |
95 | return verrevcmp(version->familiar_revision,refversion->familiar_revision); | 95 | return verrevcmp(version->familiar_revision,refversion->familiar_revision); |
96 | } | 96 | } |
97 | 97 | ||
98 | int versionsatisfied3(const struct versionrevision *it, | 98 | int versionsatisfied3(const struct versionrevision *it, |
99 | const struct versionrevision *ref, | 99 | const struct versionrevision *ref, |
100 | const char *op) | 100 | const char *op) |
101 | { | 101 | { |
102 | int r; | 102 | int r; |
103 | r= versioncompare(it,ref); | 103 | r= versioncompare(it,ref); |
104 | if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) | 104 | if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) |
105 | return r <= 0; | 105 | return r <= 0; |
106 | if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) | 106 | if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) |
107 | return r >= 0; | 107 | return r >= 0; |
108 | if (strcmp(op, "<<") == 0) | 108 | if (strcmp(op, "<<") == 0) |
109 | return r < 0; | 109 | return r < 0; |
110 | if (strcmp(op, ">>") == 0) | 110 | if (strcmp(op, ">>") == 0) |
111 | return r > 0; | 111 | return r > 0; |
112 | if (strcmp(op, "=") == 0) | 112 | if (strcmp(op, "=") == 0) |
113 | return r == 0; | 113 | return r == 0; |
114 | // fprintf(stderr, "unknown operator: %s", op); | 114 | // fprintf(stderr, "unknown operator: %s", op); |
115 | 115 | ||
116 | exit(1); | 116 | exit(1); |
117 | } | 117 | } |
118 | 118 | ||
119 | const char *parseversion(struct versionrevision *rversion, const char *string) | 119 | const char *parseversion(struct versionrevision *rversion, const char *string) |
120 | { | 120 | { |
121 | char *hyphen, *colon, *eepochcolon; | 121 | char *hyphen, *colon, *eepochcolon; |
122 | unsigned long epoch; | 122 | unsigned long epoch; |
123 | 123 | ||
124 | if ( !*string ) | 124 | if ( !*string ) |
125 | return QObject::tr( "Version string is empty." ); | 125 | return QObject::tr( "Version string is empty." ); |
126 | 126 | ||
127 | colon= strchr(string,':'); | 127 | colon= strchr(string,':'); |
128 | if (colon) { | 128 | if (colon) { |
129 | epoch= strtoul(string,&eepochcolon,10); | 129 | epoch= strtoul(string,&eepochcolon,10); |
130 | if ( colon != eepochcolon ) | 130 | if ( colon != eepochcolon ) |
131 | return QObject::tr( "Epoch in version is not number." ); | 131 | return QObject::tr( "Epoch in version is not number." ); |
132 | if ( !*++colon ) | 132 | if ( !*++colon ) |
133 | return QObject::tr( "Nothing after colon in version number." ); | 133 | return QObject::tr( "Nothing after colon in version number." ); |
134 | string= colon; | 134 | string= colon; |
135 | rversion->epoch= epoch; | 135 | rversion->epoch= epoch; |
136 | } else { | 136 | } else { |
137 | rversion->epoch= 0; | 137 | rversion->epoch= 0; |
138 | } | 138 | } |
139 | 139 | ||
140 | rversion->revision = ""; | 140 | rversion->revision = ""; |
141 | rversion->familiar_revision = ""; | 141 | rversion->familiar_revision = ""; |
142 | 142 | ||
143 | rversion->setVersion( string ); | 143 | rversion->setVersion( string ); |
144 | hyphen= strrchr(rversion->version,'-'); | 144 | hyphen= strrchr(rversion->version,'-'); |
145 | if (hyphen) { | 145 | if (hyphen) { |
146 | *hyphen++= 0; | 146 | *hyphen++= 0; |
147 | if (strncmp("fam", hyphen, 3) == 0) { | 147 | if (strncmp("fam", hyphen, 3) == 0) { |
148 | rversion->familiar_revision=hyphen+3; | 148 | rversion->familiar_revision=hyphen+3; |
149 | hyphen= strrchr(rversion->version,'-'); | 149 | hyphen= strrchr(rversion->version,'-'); |
150 | if (hyphen) { | 150 | if (hyphen) { |
151 | *hyphen++= 0; | 151 | *hyphen++= 0; |
152 | rversion->revision = hyphen; | 152 | rversion->revision = hyphen; |
153 | } | 153 | } |
154 | } else { | 154 | } else { |
155 | rversion->revision = hyphen; | 155 | rversion->revision = hyphen; |
156 | } | 156 | } |
157 | } | 157 | } |
158 | /* | 158 | /* |
159 | fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n", | 159 | fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n", |
160 | rversion->epoch, | 160 | rversion->epoch, |
161 | rversion->version, | 161 | rversion->version, |
162 | rversion->revision, | 162 | rversion->revision, |
163 | rversion->familiar_revision); | 163 | rversion->familiar_revision); |
164 | */ | 164 | */ |
165 | return 0; | 165 | return 0; |
166 | } | 166 | } |
167 | 167 | ||
168 | int compareVersions( const char *v1, const char *v2 ) | 168 | int compareVersions( const char *v1, const char *v2 ) |
169 | { | 169 | { |
170 | const char *err; | 170 | const char *err; |
171 | versionrevision ver, ref; | 171 | versionrevision ver, ref; |
172 | 172 | ||
173 | err = parseversion(&ref, v1); | 173 | err = parseversion(&ref, v1); |
174 | if (err) { | 174 | if (err) { |
175 | // fprintf(stderr, "Invalid version `%s': %s\n", v2, err); | 175 | // fprintf(stderr, "Invalid version `%s': %s\n", v2, err); |
176 | return -2; | 176 | return -2; |
177 | } | 177 | } |
178 | 178 | ||
179 | err = parseversion(&ver, v2); | 179 | err = parseversion(&ver, v2); |
180 | if (err) { | 180 | if (err) { |
181 | // fprintf(stderr, "Invalid version `%s': %s\n", v1, err); | 181 | // fprintf(stderr, "Invalid version `%s': %s\n", v1, err); |
182 | return -2; | 182 | return -2; |
183 | } | 183 | } |
184 | 184 | ||
185 | if ( versionsatisfied3( &ver, &ref, "=" ) ) | 185 | if ( versionsatisfied3( &ver, &ref, "=" ) ) |
186 | return 0; | 186 | return 0; |
187 | else if ( versionsatisfied3( &ver, &ref, "<" ) ) | 187 | else if ( versionsatisfied3( &ver, &ref, "<" ) ) |
188 | return -1; | 188 | return -1; |
189 | else | 189 | else |
190 | return 1; | 190 | return 1; |
191 | } | 191 | } |
192 | 192 | ||
193 | /* | 193 | /* |
194 | int main(int argc, char *argv[]) | 194 | int main(int argc, char *argv[]) |
195 | { | 195 | { |
196 | const char *err; | 196 | const char *err; |
197 | versionrevision ver, ref; | 197 | versionrevision ver, ref; |
198 | 198 | ||
199 | if (argc < 4) { | 199 | if (argc < 4) { |
200 | fprintf(stderr, "usage: %s: version op refversion\n", argv[0]); | 200 | fprintf(stderr, "usage: %s: version op refversion\n", argv[0]); |
201 | return 2; | 201 | return 2; |
202 | } | 202 | } |
203 | 203 | ||
204 | err = parseversion(&ver, argv[1]); | 204 | err = parseversion(&ver, argv[1]); |
205 | if (err) { | 205 | if (err) { |
206 | fprintf(stderr, "Invalid version `%s': %s\n", argv[1], err); | 206 | fprintf(stderr, "Invalid version `%s': %s\n", argv[1], err); |
207 | return 2; | 207 | return 2; |
208 | } | 208 | } |
209 | 209 | ||
210 | err = parseversion(&ref, argv[3]); | 210 | err = parseversion(&ref, argv[3]); |
211 | if (err) { | 211 | if (err) { |
212 | fprintf(stderr, "Invalid version `%s': %s\n", argv[3], err); | 212 | fprintf(stderr, "Invalid version `%s': %s\n", argv[3], err); |
213 | return 2; | 213 | return 2; |
214 | } | 214 | } |
215 | 215 | ||
216 | printf( "Result: %d\n", versionsatisfied3(&ver, &ref, argv[2]) ); | 216 | printf( "Result: %d\n", versionsatisfied3(&ver, &ref, argv[2]) ); |
217 | } | 217 | } |
218 | 218 | ||
219 | */ | 219 | */ |