[go: up one dir, main page]

File: tobrowser.cpp

package info (click to toggle)
tora 1.3.16-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 11,604 kB
  • ctags: 10,426
  • sloc: cpp: 100,338; sh: 5,034; perl: 1,482; makefile: 566; xml: 69
file content (2772 lines) | stat: -rw-r--r-- 97,117 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
/*****
 *
 * TOra - An Oracle Toolkit for DBA's and developers
 * Copyright (C) 2003-2005 Quest Software, Inc
 * Portions Copyright (C) 2005 Other Contributors
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation;  only version 2 of
 * the License is valid for this program.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 *      As a special exception, you have permission to link this program
 *      with the Oracle Client libraries and distribute executables, as long
 *      as you follow the requirements of the GNU GPL in regard to all of the
 *      software in the executable aside from Oracle client libraries.
 *
 *      Specifically you are not permitted to link this program with the
 *      Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
 *      And you are not permitted to distribute binaries compiled against
 *      these libraries without written consent from Quest Software, Inc.
 *      Observe that this does not disallow linking to the Qt Free Edition.
 *
 *      You may link this product with any GPL'd Qt library such as Qt/Free
 *
 * All trademarks belong to their respective owners.
 *
 *****/

#include "utils.h"

#include "tobrowser.h"
#include "tobrowsertable.h"
#include "tobrowserconstraint.h"
#include "tobrowserfilterui.h"
#include "tobrowserindex.h"
#include "tochangeconnection.h"
#include "toconf.h"
#include "toconnection.h"
#include "toextract.h"
#include "tohelp.h"
#include "tomain.h"
#include "toresultcols.h"
#include "toresultcombo.h"
#include "toresultconstraint.h"
#include "toresultcontent.h"
#include "toresultdepend.h"
#include "toresultextract.h"
#include "toresultfield.h"
#include "toresultindexes.h"
#include "toresultitem.h"
#include "toresultlong.h"
#include "toresultreferences.h"
#include "toresultstorage.h"
#include "toresultview.h"
#include "tosql.h"
#include "totabwidget.h"
#include "totool.h"

#ifdef TOEXTENDED_MYSQL
#  include "tomysqluser.h"
#endif

#ifdef TO_KDE
#  include <kmenubar.h>
#endif

#include <qbuttongroup.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qheader.h>
#include <qinputdialog.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qmenubar.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qprogressdialog.h>
#include <qregexp.h>
#include <qsplitter.h>
#include <qtabwidget.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <qtooltip.h>
#include <qvaluelist.h>
#include <qworkspace.h>

#include "tobrowser.moc"
#include "tobrowserfilterui.moc"

#include "icons/addindex.xpm"
#include "icons/addtable.xpm"
#include "icons/filter.xpm"
#include "icons/function.xpm"
#include "icons/index.xpm"
#include "icons/modconstraint.xpm"
#include "icons/modindex.xpm"
#include "icons/modtable.xpm"
#include "icons/nofilter.xpm"
#include "icons/refresh.xpm"
#include "icons/schema.xpm"
#include "icons/sequence.xpm"
#include "icons/synonym.xpm"
#include "icons/table.xpm"
#include "icons/tobrowser.xpm"
#include "icons/view.xpm"
#include "icons/trash.xpm"
#ifndef TO_NO_ORACLE
#include "icons/offline.xpm"
#include "icons/online.xpm"
#endif
#ifdef TOEXTENDED_MYSQL
#include "icons/new.xpm"
#endif

#define TO_DEBUGOUT(x) fprintf(stderr,(const char *)x);

#define CONF_FILTER_IGNORE_CASE "FilterIgnoreCase"
#define CONF_FILTER_INVERT  	"FilterInvert"
#define CONF_FILTER_TYPE  	"FilterType"
#define CONF_FILTER_TABLESPACE_TYPE  	"FilterTablespaceType"
#define CONF_FILTER_TEXT  	"FilterText"


const char **toBrowserTool::pictureXPM(void)
{
  return tobrowser_xpm;
}

toBrowserTool::toBrowserTool()
  : toTool(20,"Schema Browser")
{ }

const char *toBrowserTool::menuItem()
{
  return "Schema Browser";
}

QWidget *toBrowserTool::toolWindow(QWidget *parent,toConnection &connection)
{
  return new toBrowser(parent,connection);
}

bool toBrowserTool::canHandle(toConnection &conn)
{
  return toIsOracle(conn)||toIsMySQL(conn)||toIsPostgreSQL(conn) || toIsSapDB(conn);
}

void toBrowserTool::customSetup(int)
{
  QPopupMenu *createMenu=new QPopupMenu(toMainWidget());
  createMenu->insertItem(QPixmap((const char **)modtable_xpm),tr("&Table"),
			 this,SLOT(addTable()));
  createMenu->insertItem(QPixmap((const char **)modindex_xpm),tr("&Index"),
			 this,SLOT(addIndex()));
  createMenu->insertItem(QPixmap((const char **)modconstraint_xpm),tr("&Constraint"),
			 this,SLOT(addConstraint()));
  toMainWidget()->menuBar()->insertItem(tr("&Create"),createMenu,-1,toToolMenuIndex());
}

void toBrowserTool::addTable(void)
{
  try {
    toConnection &conn=toMainWidget()->currentConnection();
    toBrowserTable::newTable(conn,
			     toIsMySQL(conn)?conn.database():conn.user(),
			     toMainWidget());
  } TOCATCH
}

void toBrowserTool::addIndex(void)
{
  try {
    toConnection &conn=toMainWidget()->currentConnection();
    toBrowserIndex::modifyIndex(conn,
				toIsMySQL(conn)?conn.database():conn.user(),
				QString::null,
				toMainWidget());
  } TOCATCH
}

void toBrowserTool::addConstraint(void)
{
  try {
    toConnection &conn=toMainWidget()->currentConnection();
    toBrowserConstraint::modifyConstraint(conn,
					  toIsMySQL(conn)?conn.database():conn.user(),
					  QString::null,
					  toMainWidget());
  } TOCATCH
}

static toBrowserTool BrowserTool;

static toSQL SQLListTablespaces("toBrowser:ListTablespaces",
				"SELECT Tablespace_Name FROM sys.DBA_TABLESPACES\n"
				" ORDER BY Tablespace_Name",
				"List the available tablespaces in a database.");

class toBrowserFilter : public toResultFilter {
  int Type;
  bool IgnoreCase;
  bool Invert;
  QString Text;
  int TablespaceType;
  std::list<QString> Tablespaces;
  QRegExp Match;
  bool OnlyOwnSchema;

  std::map<QString,bool> RemoveDuplicates;
public:
  toBrowserFilter(int type,bool cas,bool invert,
		  const QString &str,int tablespace,
		  const std::list<QString> &tablespaces,
		  bool 
    : Type(type),IgnoreCase(cas),Invert(invert),Text(cas?str.upper():str),
      TablespaceType(tablespace),Tablespaces(tablespaces),OnlyOwnSchema(onlyOwnSchema)
  {
    if (!str.isEmpty()) {
      Match.setPattern(str);
      Match.setCaseSensitive(cas);
    }
    storeFilterSettings();
  }
  
  toBrowserFilter(bool empty=true)
    : Type(0),IgnoreCase(true),Invert(false),TablespaceType(0)
  {
    if (!empty)
      readFilterSettings();
    else
      BrowserTool.setConfig(CONF_FILTER_TYPE,"0");  // No filter type
  }
  
  virtual void storeFilterSettings(void) 
  {
    BrowserTool.setConfig(CONF_FILTER_IGNORE_CASE,IgnoreCase?"Yes":"No");
    BrowserTool.setConfig(CONF_FILTER_INVERT,Invert?"Yes":"No");
    BrowserTool.setConfig(CONF_FILTER_TYPE,QString("%1").arg(Type));
    BrowserTool.setConfig(CONF_FILTER_TABLESPACE_TYPE,QString("%1").arg(TablespaceType));
    BrowserTool.setConfig(CONF_FILTER_TEXT,Text);
    toTool::saveConfig();
  }

  virtual void readFilterSettings(void) 
  {
    QString t;
    Text = BrowserTool.config(CONF_FILTER_TEXT, "");
    
    if (BrowserTool.config(CONF_FILTER_IGNORE_CASE,"No") == "Yes") 
      IgnoreCase=true;
    else
      IgnoreCase=false;
    
    if (BrowserTool.config(CONF_FILTER_INVERT,"No") == "Yes") 
      Invert=true;
    else
      Invert=false;
    
    Type=QString(BrowserTool.config(CONF_FILTER_TYPE,"0")).toInt();
    TablespaceType=QString(BrowserTool.config(CONF_FILTER_TABLESPACE_TYPE,"0")).toInt();
  }
  virtual void exportData(std::map<QCString,QString> &data,const QCString &prefix)
  {
    data[prefix+":Type"]=QString::number(Type);
    if (IgnoreCase)
      data[prefix+":Ignore"]="Yes";
    if (Invert)
      data[prefix+":Invert"]="Yes";
    data[prefix+":SpaceType"]=QString::number(TablespaceType);
    data[prefix+":Text"]=Text;
    int id=1;
    for(std::list<QString>::iterator i=Tablespaces.begin();i!=Tablespaces.end();i++,id++)
      data[prefix+":Space:"+QString::number(id).latin1()]=*i;
    if (OnlyOwnSchema)
      data[prefix+":OwnlyOwnSchema"]="Yes";
  }
  virtual void importData(std::map<QCString,QString> &data,const QCString &prefix)
  {
    Type=data[prefix+":Type"].toInt();
    
    TablespaceType=data[prefix+":SpaceType"].toInt();
    IgnoreCase=!data[prefix+":Ignore"].isEmpty();
    Invert=!data[prefix+":Invert"].isEmpty();
    Text=data[prefix+":Text"];
    if (!Text.isEmpty()) {
      Match.setPattern(Text);
      Match.setCaseSensitive(IgnoreCase);
    }
    int id=1;
    std::map<QCString,QString>::iterator i;
    Tablespaces.clear();
    while((i=data.find(prefix+":Space:"+QString::number(id).latin1()))!=data.end()) {
      Tablespaces.insert(Tablespaces.end(),(*i).second);
      i++;
      id++;
    }
  }
  bool onlyOwnSchema(void)
  { return OnlyOwnSchema; }
  virtual QString wildCard(void)
  {
    switch(Type) {
    default:
      return QString::fromLatin1("%");
    case 1:
      return Text.upper()+QString::fromLatin1("%");
    case 2:
      return QString::fromLatin1("%")+Text.upper();
    case 3:
      return QString::fromLatin1("%")+Text.upper()+QString::fromLatin1("%");
    }
  }
  virtual void startingQuery()
  { RemoveDuplicates.clear(); }
  virtual bool check(const QListViewItem *item)
  {
    QString key=item->text(0)+"."+item->text(1);
    if (RemoveDuplicates.find(key)!=RemoveDuplicates.end())
      return false;
    else
      RemoveDuplicates[key]=true;
    
    QString str=item->text(0);
    QString tablespace=item->text(3);
    if (!tablespace.isEmpty()) {
      switch(TablespaceType) {
      default:
	break;
      case 1:
	{
	  bool ok=false;
	  for(std::list<QString>::iterator i=Tablespaces.begin();i!=Tablespaces.end();i++) {
	    if (*i==tablespace) {
	      ok=true;
	      break;
	    }
	  }
	  if (!ok)
	    return false;
	}
	break;
      case 2:
	for(std::list<QString>::iterator i=Tablespaces.begin();i!=Tablespaces.end();i++)
	  if (*i==tablespace)
	    return false;
	break;
      }
    }
    switch(Type) {
    default:
      return true;
    case 1:
      if (IgnoreCase) {
	if (str.upper().startsWith(Text))
	  return !Invert;
      } else if (str.startsWith(Text))
	return !Invert;
      break;
    case 2:
      if (IgnoreCase) {
	if (str.right(Text.length()).upper()==Text)
	  return !Invert;
      } else if (str.right(Text.length())==Text)
	return !Invert;
      break;
    case 3:
      if (str.contains(Text,!IgnoreCase))
	return !Invert;
      break;
    case 4:
      {
	QStringList lst=QStringList::split(QRegExp(QString::fromLatin1("\\s*,\\s*")),Text);
	for(unsigned int i=0;i<lst.count();i++)
	  if (IgnoreCase) {
	    if (str.upper()==lst[i])
	      return !Invert;
	  } else if (str==lst[i])
	    return !Invert;
      }
      break;
    case 5:
      if (Match.match(str)>=0)
	return !Invert;
      break;
    }
    return Invert;
  }
  virtual toResultFilter *clone(void)
  { return new toBrowserFilter(*this); }
  friend class toBrowserFilterSetup;
};

class toBrowserFilterSetup : public toBrowserFilterUI {
public:
  void setup(bool temp)
  {
    toHelp::connectDialog(this);
    if (!temp) {
      OnlyOwnSchema->hide();
      Tablespaces->setNumberColumn(false);
      Tablespaces->setReadableColumns(true);
      try {
	toConnection &conn=toCurrentConnection(this);
	toQuery query(conn,toSQL::string(SQLListTablespaces,conn));
	Tablespaces->query(SQLListTablespaces);
      } catch(...) {
      }
      Tablespaces->setSelectionMode(QListView::Multi);
    } else {
      TablespaceType->hide();
    }
  }
  toBrowserFilterSetup(bool temp,QWidget *parent)
    : toBrowserFilterUI(parent,"Filter Setting",true)
  {
    setup(temp);
  }
  toBrowserFilterSetup(bool temp,toBrowserFilter &cur,QWidget *parent)
    : toBrowserFilterUI(parent,"Filter Setting",true)
  {
    setup(temp);

    Buttons->setButton(cur.Type);
    if (!TablespaceType->isHidden()) {
      TablespaceType->setButton(cur.TablespaceType);
      for(std::list<QString>::iterator i=cur.Tablespaces.begin();i!=cur.Tablespaces.end();i++) {
	for (QListViewItem *item=Tablespaces->firstChild();item;item=item->nextSibling())
	  if (item->text(0)==*i) {
	    item->setSelected(true);
	    break;
	  }
      }
    }
    String->setText(cur.Text);
    Invert->setChecked(cur.Invert);
    IgnoreCase->setChecked(cur.IgnoreCase);
    OnlyOwnSchema->setChecked(cur.OnlyOwnSchema);
  }
  toBrowserFilter *getSetting(void)
  {
    std::list<QString> tablespaces;
    for (QListViewItem *item=Tablespaces->firstChild();item;item=item->nextSibling())
      if (item->isSelected())
	tablespaces.insert(tablespaces.end(),item->text(0));
    return new toBrowserFilter(Buttons->id(Buttons->selected()),
			       IgnoreCase->isChecked(),
			       Invert->isChecked(),
			       String->text(),
			       TablespaceType->id(TablespaceType->selected()),
			       tablespaces,
			       OnlyOwnSchema->isChecked());
  }
};

toBrowseButton::toBrowseButton(const QIconSet &iconSet,
			       const QString &textLabel,
			       const QString & grouptext,
			       QObject * receiver,
			       const char * slot,
			       QToolBar * parent,
			       const char * name)
  : QToolButton(iconSet,textLabel,grouptext,receiver,slot,parent,name)
{
  try {
    connect(toCurrentTool(this),SIGNAL(connectionChange()),this,SLOT(connectionChanged()));
  } TOCATCH
  connectionChanged();
}

void toBrowseButton::connectionChanged()
{
  try {
    setEnabled(toExtract::canHandle(toCurrentConnection(this)));
  } TOCATCH
}

#define FIRST_WIDTH 180

#define TAB_TABLES		"Tables"
#define TAB_TABLE_COLUMNS	"TablesColumns"
#define TAB_TABLE_CONS		"TablesConstraint"
#define TAB_TABLE_DEPEND	"TablesDepend"
#define TAB_TABLE_INDEXES	"TablesIndexes"
#define TAB_TABLE_DATA		"TablesData"
#define TAB_TABLE_GRANTS	"TablesGrants"
#define TAB_TABLE_TRIGGERS	"TablesTriggers"
#define TAB_TABLE_INFO		"TablesInfo"
#define TAB_TABLE_PARTITION	"TablesPartition"
#define TAB_TABLE_STATISTIC	"TablesStatistic"
#define TAB_TABLE_EXTENT	"TablesExtent"
#define TAB_TABLE_EXTRACT	"TablesExtract"

#define TAB_VIEWS		"Views"
#define TAB_VIEW_COLUMNS	"ViewColumns"
#define TAB_VIEW_SQL		"ViewSQL"
#define TAB_VIEW_DATA		"ViewData"
#define TAB_VIEW_GRANTS		"ViewGrants"
#define TAB_VIEW_DEPEND		"ViewDepend"
#define TAB_VIEW_EXTRACT	"ViewExtract"

#define TAB_SEQUENCES		"Sequences"
#define TAB_SEQUENCES_GRANTS	"SequencesGrants"
#define TAB_SEQUENCES_INFO	"SequencesInfo"
#define TAB_SEQUENCES_EXTRACT	"SequencesExtract"

#define TAB_INDEX		"Index"
#define TAB_INDEX_COLS		"IndexCols"
#define TAB_INDEX_INFO		"IndexInfo"
#define TAB_INDEX_EXTENT	"IndexesExtent"
#define TAB_INDEX_EXTRACT	"IndexExtract"
#define TAB_INDEX_STATISTIC	"IndexStatistic"

#define TAB_SYNONYM		"Synonym"
#define TAB_SYNONYM_GRANTS	"SynonymGrants"
#define TAB_SYNONYM_INFO	"SynonymInfo"
#define TAB_SYNONYM_EXTRACT	"SynonymExtract"

#define TAB_PLSQL		"PLSQL"
#define TAB_PLSQL_SOURCE	"PLSQLSource"
#define TAB_PLSQL_BODY		"PLSQLBody"
#define TAB_PLSQL_GRANTS	"PLSQLGrants"
#define TAB_PLSQL_DEPEND	"PLSQLDepend"
#define TAB_PLSQL_EXTRACT	"PLSQLExtract"

#define TAB_TRIGGER		"Trigger"
#define TAB_TRIGGER_INFO	"TriggerInfo"
#define TAB_TRIGGER_SOURCE	"TriggerSource"
#define TAB_TRIGGER_GRANTS	"TriggerGrants"
#define TAB_TRIGGER_COLS	"TriggerCols"
#define TAB_TRIGGER_DEPEND	"TriggerDepend"
#define TAB_TRIGGER_EXTRACT	"TriggerExtract"

#define TAB_DBLINK		"DBLink"
#define TAB_DBLINK_INFO		"DBLinkInfo"
#define TAB_DBLINK_SYNONYMS	"DBLinkSynonyms"

#define TAB_ACCESS		"Access"
#define TAB_ACCESS_CONTENT	"AccessContent"
#define TAB_ACCESS_USER		"AccessUser"
#define TAB_ACCESS_OBJECTS	"AccessObjects"

static toSQL SQLListTablesMysql("toBrowser:ListTables",
				"SHOW TABLES FROM :f1<noquote>",
				"List the available tables in a schema.",
				"3.0",
				"MySQL");
static toSQL SQLListTables("toBrowser:ListTables",
			   "SELECT Table_Name,NULL \" Ignore\",NULL \" Ignore2\",Tablespace_name \" Ignore2\"\n"
			   "  FROM SYS.ALL_ALL_TABLES WHERE OWNER = :f1<char[101]> AND IOT_Name IS NULL\n"
			   "   AND UPPER(TABLE_NAME) LIKE :f2<char[101]>\n"
			   " ORDER BY Table_Name",
			   "",
			   "8.0");
static toSQL SQLListTables7("toBrowser:ListTables",
			    "SELECT Table_Name,NULL \" Ignore\",NULL \" Ignore2\",Tablespace_name \" Ignore2\"\n"
			    "  FROM SYS.ALL_TABLES WHERE OWNER = :f1<char[101]>\n"
			    "   AND UPPER(TABLE_NAME) LIKE :f2<char[101]>\n"
			    " ORDER BY Table_Name",
			    "",
			    "7.3");
static toSQL SQLListTablesPgSQL("toBrowser:ListTables",
                                "SELECT c.relname AS \"Table Name\"\n"
                                "  FROM pg_class c LEFT OUTER JOIN pg_user u ON c.relowner=u.usesysid\n"
                                " WHERE (u.usename = :f1 OR u.usesysid IS NULL)\n"
                                "   AND c.relkind = 'r'"
                                " ORDER BY \"Table Name\"",
                                "",
                                "7.1",
                                "PostgreSQL");
static toSQL SQLListTablesSapDB("toBrowser:ListTables",
                            "SELECT tablename \"Table Name\"\n"
                            " FROM tables \n"
                            " WHERE tabletype = 'TABLE' and owner = upper(:f1<char[101]>) \n"
                            " ORDER by tablename",
                            "",
                            "",
                            "SapDB");
static toSQL SQLAnyGrantsSapDB("toBrowser:AnyGrants",
                            "SELECT privilege,grantee,grantor,is_grantable\n"
                            " FROM tableprivileges \n"
                            " WHERE owner = upper(:f1<char[101]>) and tablename = :f2<char[101]>\n"
                            " ORDER by privilege,grantee ",
                            "Display the grants on an object",
                            "",
                            "SapDB");
static toSQL SQLAnyGrants("toBrowser:AnyGrants",
			  "SELECT Privilege,Grantee,Grantor,Grantable FROM SYS.ALL_TAB_PRIVS\n"
			  " WHERE Table_Schema = :f1<char[101]> AND Table_Name = :f2<char[101]>\n"
			  " ORDER BY Privilege,Grantee",
			  "");
static toSQL SQLTableTriggerSapDB("toBrowser:TableTrigger",
                            "SELECT TriggerName,'UPDATE' \"Event\",''\"Column\",'ENABLED' \"Status\",''\"Description\"\n"
                            " FROM triggers \n"
                            " WHERE owner = upper(:f1<char[101]>) and tablename = :f2<char[101]>\n"
                            "  and update='YES'\n"
                            "UNION\n"
                            "SELECT TriggerName,'INSERT','','ENABLED',''\n"
                            " FROM triggers \n"
                            " WHERE owner = upper(:f1<char[101]>) and  tablename = :f2<char[101]>\n"
                            "  and insert='YES'\n"
                            "UNION\n"
                            "SELECT TriggerName,'DELETE','','ENABLED',''\n"
                            " FROM triggers \n"
                            " WHERE owner = upper(:f1<char[101]>) and  tablename = :f2<char[101]>\n"
                            "  and delete='YES'\n"
                            " ORDER by 1 ",
                            "Display the triggers operating on a table",
                            "",
                            "SapDB");
static toSQL SQLTableTrigger("toBrowser:TableTrigger",
			     "SELECT Trigger_Name,Triggering_Event,Column_Name,Status,Description \n"
			     "  FROM SYS.ALL_TRIGGERS\n"
			     " WHERE Table_Owner = :f1<char[101]> AND Table_Name = :f2<char[101]>",
			     "",
			     "8.1");
static toSQL SQLTableTrigger8("toBrowser:TableTrigger",
			      "SELECT Trigger_Name,Triggering_Event,Status,Description \n"
			      "  FROM SYS.ALL_TRIGGERS\n"
			      " WHERE Table_Owner = :f1<char[101]> AND Table_Name = :f2<char[101]>",
			      "",
			      "8.0");
static toSQL SQLTableInfoMysql("toBrowser:TableInformation",
			       "show table status from :own<noquote> like :tab",
			       "Display information about a table",
			       "3.0",
			       "MySQL");
static toSQL SQLTableInfo("toBrowser:TableInformation",
			  "SELECT *\n"
			  "  FROM SYS.ALL_TABLES\n"
			  " WHERE OWNER = :f1<char[101]> AND Table_Name = :f2<char[101]>",
			  "");
static toSQL SQLTableInfoPgSQL("toBrowser:TableInformation",
			       "SELECT c.*\n"
			       "  FROM pg_class c LEFT OUTER JOIN pg_user u ON c.relowner=u.usesysid\n"
			       " WHERE (u.usename = :f1 OR u.usesysid IS NULL)\n"
			       "   AND c.relkind = 'r'\n"
			       "   AND c.relname = :f2",
                               "",
                               "7.1",
                               "PostgreSQL");
static toSQL SQLTableInfoSapDB("toBrowser:TableInformation",
                            "SELECT TABLENAME,PRIVILEGES,CREATEDATE,CREATETIME,UPDSTATDATE,UPDSTATTIME,ALTERDATE,ALTERTIME,TABLEID \n"
                            " FROM tables \n"
                            " WHERE tabletype = 'TABLE' and owner = upper(:f1<char[101]>) and tablename = :f2<char[101]>",
                            "",
                            "",
                            "SapDB");
static toSQL SQLTableStatistic("toBrowser:TableStatstics",
                            "SELECT description \"Description\", value(char_value,numeric_value) \"Value\" \n"
                            " FROM tablestatistics \n"
                            " WHERE owner = upper(:f1<char[101]>) and tablename = :f2<char[101]>",
                            "Table Statistics",
                            "",
                            "SapDB");
static toSQL SQLTablePartition("toBrowser:TablePartitions",
			       "select    p.partition_name \"Partition\"\n"
			       "	, p.composite \"Composite\"\n"
			       "	, p.num_rows \"Partition rows\"\n"
			       "	, p.high_value \"High value\"\n"
			       "	, p.subpartition_count \"Subpartitions\"\n"
			       "	, p.partition_position \"Position\"\n"
			       "	, s.subpartition_name \"Subpartition\"\n"
			       "	, s.num_rows \"Subpartition rows\"\n"
			       "	, s.subpartition_position \"Subpartition position\"\n"
			       "  from all_tab_partitions p,\n"
			       "       all_tab_subpartitions s\n"
			       " where p.table_owner = s.table_owner(+)\n"
			       "   and p.table_name = s.table_name(+)\n"
			       "   and p.partition_name = s.partition_name(+)\n"
			       "   and p.table_owner like upper(:table_owner<char[101]>)\n"
			       "   and p.table_name like upper(:table_name<char[101]>)\n"
			       " order by p.partition_name\n"
			       "	, s.subpartition_name\n",
			       "Table partitions",
			       "8.1");

static toSQL SQLListViewPgSQL("toBrowser:ListView",
                         "SELECT c.relname as View_Name\n"
                         "  FROM pg_class c LEFT OUTER JOIN pg_user u ON c.relowner=u.usesysid\n"
                         " WHERE (u.usename = :f1 OR u.usesysid IS NULL)\n"
                         "   AND c.relkind = 'v'"
                         " ORDER BY View_Name",
                         "List the available views in a schema",
                         "7.1",
                         "PostgreSQL");
static toSQL SQLListView("toBrowser:ListView",
			 "SELECT View_Name FROM SYS.ALL_VIEWS WHERE OWNER = :f1<char[101]>\n"
			 "   AND UPPER(VIEW_NAME) LIKE :f2<char[101]>\n"
			 " ORDER BY View_Name",
			 "");
static toSQL SQLListViewSapDb("toBrowser:ListView",
                            "SELECT tablename \"View_Name\"\n"
                            " FROM tables \n"
                            " WHERE tabletype = 'VIEW' and owner = upper(:f1<char[101]>)\n"
                            " ORDER by tablename",
                            "",
                            "",
                            "SapDB");
static toSQL SQLViewSQLPgSQL("toBrowser:ViewSQL",	
			     "SELECT pg_get_viewdef(c.relname)\n"
			     "  FROM pg_class c LEFT OUTER JOIN pg_user u ON c.relowner=u.usesysid\n"
			     " WHERE (u.usename = :f1 OR u.usesysid IS NULL)\n"
			     "   AND c.relkind = 'v' AND c.relname = :f2",
			     "Display SQL of a specified view",
			     "7.1",
			     "PostgreSQL");
static toSQL SQLViewSQL("toBrowser:ViewSQL",	
			"SELECT Text SQL\n"
			"  FROM SYS.ALL_Views\n"
			" WHERE Owner = :f1<char[101]> AND View_Name = :f2<char[101]>",
			"");
static toSQL SQLViewSQLSapDb("toBrowser:ViewSQL",
                            "SELECT definition \"SQL\"\n"
                            " FROM viewdefs \n"
                            " WHERE  viewname = :f2<char[101]> and owner = upper(:f1<char[101]>)\n",
                            "",
                            "",
                            "SapDB");

static toSQL SQLListIndexMySQL("toBrowser:ListIndex",
			       "TOAD 1,3 SHOW INDEX FROM :f1<database>",
			       "List the available indexes in a schema",
			       "3.23",
			       "MySQL");
static toSQL SQLListIndex("toBrowser:ListIndex",
			  "SELECT Index_Name,NULL \" Ignore\",NULL \" Ignore2\",Tablespace_name \" Ignore2\"\n"
			  "  FROM SYS.ALL_INDEXES\n"
			  " WHERE OWNER = :f1<char[101]>\n"
			  "   AND UPPER(INDEX_NAME) LIKE :f2<char[101]>\n"
			  " ORDER BY Index_Name\n",
			  "");
static toSQL SQLListIndexPgSQL("toBrowser:ListIndex",
			       "SELECT c.relname AS \"Index Name\"\n"
                               "FROM pg_class c LEFT OUTER JOIN pg_user u ON c.relowner=u.usesysid\n"
                               "WHERE (u.usename = :f1 OR u.usesysid IS NULL)\n"
                               "  AND c.relkind = 'i'\n"
                               "ORDER BY \"Index Name\"",
			       "",
			       "7.1",
			       "PostgreSQL");
static toSQL SQLListIndexSapDb("toBrowser:ListIndex",
                            "SELECT IndexName \"Index Name\"\n"
                            " FROM indexes \n"
                            " WHERE  owner = upper(:f1<char[101]>)",
                            "",
                            "",
                            "SapDB");

static toSQL SQLIndexColsMySQL("toBrowser:IndexCols",
			       "SHOW INDEX FROM :f1<noquote>.:f2<noquote>",
			       "Display columns on which an index is built",
			       "3.23",
			       "MySQL");
static toSQL SQLIndexCols("toBrowser:IndexCols",
			  "SELECT a.Table_Name,a.Column_Name,a.Column_Length,a.Descend,b.Column_Expression \" \"\n"
			  "  FROM sys.All_Ind_Columns a,sys.All_Ind_Expressions b\n"
			  " WHERE a.Index_Owner = :f1<char[101]> AND a.Index_Name = :f2<char[101]>\n"
			  "   AND a.Index_Owner = b.Index_Owner(+) AND a.Index_Name = b.Index_Name(+)\n"
			  "   AND a.column_Position = b.Column_Position(+)\n"
			  " ORDER BY a.Column_Position",
			  "",
			  "8.1");
static toSQL SQLIndexCols8("toBrowser:IndexCols",
			   "SELECT Table_Name,Column_Name,Column_Length,Descend\n"
			   "  FROM SYS.ALL_IND_COLUMNS\n"
			   " WHERE Index_Owner = :f1<char[101]> AND Index_Name = :f2<char[101]>\n"
			   " ORDER BY Column_Position",
			   "",
			   "8.0");
static toSQL SQLIndexCols7("toBrowser:IndexCols",
			   "SELECT Table_Name,Column_Name,Column_Length\n"
			   "  FROM SYS.ALL_IND_COLUMNS\n"
			   " WHERE Index_Owner = :f1<char[101]> AND Index_Name = :f2<char[101]>\n"
			   " ORDER BY Column_Position",
			   "",
			   "7.3");
static toSQL SQLIndexColsPgSQL("toBrowser:IndexCols",
                               "SELECT a.attname,\n"
                               "       format_type(a.atttypid, a.atttypmod) as FORMAT,\n"
                               "       a.attnotnull,\n"
                               "       a.atthasdef\n"
                               "  FROM pg_class c LEFT OUTER JOIN pg_user u ON c.relowner=u.usesysid,\n"
                               "       pg_attribute a\n"
                               " WHERE (u.usename = :f1 OR u.usesysid IS NULL)\n"
                               "   AND a.attrelid = c.oid AND c.relname = :f2\n"
                               "   AND a.attnum > 0\n"
                               " ORDER BY a.attnum\n",
			       "",
			       "7.1",
                               "PostgreSQL");
static toSQL SQLIndexColsSapDb("toBrowser:IndexCols",
                            "SELECT tablename,columnname,len \"Length\",DataType,Sort \n"
                            " FROM indexcolumns \n"
                            " WHERE  owner = upper(:f1<char[101]>) and indexname = upper(:f2<char[101]>)\n"
                            " ORDER BY indexname,columnno",
                            "",
                            "",
                            "SapDB");

static toSQL SQLIndexInfoSapDb("toBrowser:IndexInformation",
                            "SELECT  INDEXNAME,TABLENAME, TYPE, CREATEDATE,CREATETIME,INDEX_USED, DISABLED \n"
                            " FROM indexes\n"
                            " WHERE  owner = upper(:f1<char[101]>) and indexname = :f2<char[101]>\n",
                            "Display information about an index",
                            "",
                            "SapDB");
static toSQL SQLIndexInfo("toBrowser:IndexInformation",
			  "SELECT * FROM SYS.ALL_INDEXES\n"
			  " WHERE Owner = :f1<char[101]> AND Index_Name = :f2<char[101]>",
			  "");
static toSQL SQLIndexStatistic("toBrowser:IndexStatstics",
                            "SELECT description \"Description\", value(char_value,numeric_value) \"Value\" \n"
                            " FROM indexstatistics \n"
                            " WHERE owner = upper(:f1<char[101]>) and indexname = :f2<char[101]>",
                            "Index Statistics",
                            "",
                            "SapDB");

static toSQL SQLListSequencePgSQL("toBrowser:ListSequence",
                                  "SELECT c.relname AS \"Sequence Name\"\n"
                                  "  FROM pg_class c LEFT OUTER JOIN pg_user u ON c.relowner=u.usesysid\n"
                                  " WHERE (u.usename = :f1 OR u.usesysid IS NULL)\n"
                                  "   AND c.relkind = 'S'\n"
                                  " ORDER BY \"Sequence Name\"",
			          "List the available sequences in a schema",
			          "7.1",
                                  "PostgreSQL");
static toSQL SQLListSequence("toBrowser:ListSequence",
			     "SELECT Sequence_Name FROM SYS.ALL_SEQUENCES\n"
			     " WHERE SEQUENCE_OWNER = :f1<char[101]>\n"
			     "   AND UPPER(SEQUENCE_NAME) LIKE :f2<char[101]>\n"
			     " ORDER BY Sequence_Name",
			     "");
static toSQL SQLSequenceInfoPgSQL("toBrowser:SequenceInformation",
                                  "SELECT *, substr(:f1,1) as \"Owner\" FROM :f2<noquote>",
			          "Display information about a sequence",
			          "7.1",
                                  "PostgreSQL");
static toSQL SQLSequenceInfo("toBrowser:SequenceInformation",
			     "SELECT * FROM SYS.ALL_SEQUENCES\n"
			     " WHERE Sequence_Owner = :f1<char[101]>\n"
			     "   AND Sequence_Name = :f2<char[101]>",
			     "");

static toSQL SQLListSynonym("toBrowser:ListSynonym",
			    "SELECT DECODE(Owner,'PUBLIC','',Owner||'.')||Synonym_Name \"Synonym Name\"\n"
			    "  FROM Sys.All_Synonyms\n"
			    " WHERE Table_Owner = :f1<char[101]>\n"
			    "    OR Owner = :f1<char[101]>\n"
			    "   AND UPPER(Synonym_Name) LIKE :f2<char[101]>\n"
			    " ORDER BY Synonym_Name",
			    "List the available synonyms in a schema");
static toSQL SQLSynonymInfo("toBrowser:SynonymInformation",
			    "SELECT * FROM Sys.All_Synonyms a\n"
			    " WHERE Owner = :f1<char[101]>\n"
			    "   AND Synonym_Name = :f2<char[101]>",
			    "Display information about a synonym");

static toSQL SQLListSQLPgSQL("toBrowser:ListCode",
			     "SELECT p.proname AS Object_Name,\n"
                             "  CASE WHEN p.prorettype = 0 THEN 'PROCEDURE'\n"
                             "       ELSE 'FUNCTION'\n"
                             "   END AS Object_Type\n"
                             "FROM pg_proc p LEFT OUTER JOIN pg_user u ON p.proowner=u.usesysid\n"
                             "WHERE (u.usename = :f1 OR u.usesysid IS NULL)\n"
                             "ORDER BY Object_Name",
			     "List the available Code objects in a schema",
			     "7.1",
                             "PostgreSQL");
static toSQL SQLListSQL("toBrowser:ListCode",
			"SELECT Object_Name,Object_Type,Status Type FROM SYS.ALL_OBJECTS\n"
			" WHERE OWNER = :f1<char[101]>\n"
			"   AND Object_Type IN ('FUNCTION','PACKAGE',\n"
			"                       'PROCEDURE','TYPE')\n"
			"   AND UPPER(OBJECT_NAME) LIKE :f2<char[101]>\n"
			" ORDER BY Object_Name",
			"");
static toSQL SQLListSQLShortPgSQL("toBrowser:ListCodeShort",
			     "SELECT p.proname AS Object_Name\n"
                             "FROM pg_proc p LEFT OUTER JOIN pg_user u ON p.proowner=u.usesysid\n"
                             "WHERE (u.usename = :f1 OR u.usesysid IS NULL)\n"
                             "ORDER BY Object_Name",
			     "List the available Code objects in a schema, one column version",
			     "7.1",
                             "PostgreSQL");
static toSQL SQLListSQLShort("toBrowser:ListCodeShort",
			     "SELECT Object_Name Type FROM SYS.ALL_OBJECTS\n"
		 	     " WHERE OWNER = :f1<char[101]>\n"
			     "   AND Object_Type IN ('FUNCTION','PACKAGE',\n"
			     "                       'PROCEDURE','TYPE')\n"
			     "   AND UPPER(OBJECT_NAME) LIKE :f2<char[101]>\n"
			     " ORDER BY Object_Name",
			     "");


static toSQL SQLSQLTemplate("toBrowser:CodeTemplate",
			    "SELECT Text FROM SYS.ALL_SOURCE\n"
			    " WHERE Owner = :f1<char[101]> AND Name = :f2<char[101]>\n"
			    "   AND Type IN ('PACKAGE','PROCEDURE','FUNCTION','PACKAGE','TYPE')",
			    "Declaration of object displayed in template window");
// PostgreSQL does not distinguish between Head and Body for Stored SQL
// package code will be returnd for both Head and Body
static toSQL SQLSQLHeadPgSQL("toBrowser:CodeHead",
			     "SELECT p.prosrc\n"
                             "FROM pg_proc p LEFT OUTER JOIN pg_user u ON p.proowner=u.usesysid\n"
                             "WHERE (u.usename = :f1 OR u.usesysid IS NULL)\n"
                             "  AND p.proname = :f2\n",
			     "Declaration of object",
			     "7.1",
                             "PostgreSQL");
static toSQL SQLSQLHead("toBrowser:CodeHead",
			"SELECT Text FROM SYS.ALL_SOURCE\n"
			" WHERE Owner = :f1<char[101]> AND Name = :f2<char[101]>\n"
			"   AND Type IN ('PACKAGE','TYPE')",
			"");

static toSQL SQLSQLBodyPgSQL("toBrowser:CodeBody",
			"SELECT p.prosrc\n"
                        "FROM pg_proc p LEFT OUTER JOIN pg_user u ON p.proowner=u.usesysid\n"
                        "WHERE (u.usename = :f1 OR u.usesysid IS NULL)\n"
                        "  AND p.proname = :f2\n",
			"Implementation of object",
			"7.1",
                        "PostgreSQL");
static toSQL SQLSQLBody("toBrowser:CodeBody",
			"SELECT Text FROM SYS.ALL_SOURCE\n"
			" WHERE Owner = :f1<char[101]> AND Name = :f2<char[101]>\n"
			"   AND Type IN ('PROCEDURE','FUNCTION','PACKAGE BODY','TYPE BODY')",
			"");


static toSQL SQLListTrigger("toBrowser:ListTrigger",
			    "SELECT Trigger_Name FROM SYS.ALL_TRIGGERS\n"
			    " WHERE OWNER = :f1<char[101]>\n"
			    "   AND UPPER(TRIGGER_NAME) LIKE :f2<char[101]>\n"
			    " ORDER BY Trigger_Name",
			    "List the available triggers in a schema");
static toSQL SQLTriggerInfo("toBrowser:TriggerInfo",
			    "SELECT Owner,Trigger_Name,\n"
			    "       Trigger_Type,Triggering_Event,\n"
			    "       Table_Owner,Base_Object_Type,Table_Name,Column_Name,\n"
			    "       Referencing_Names,When_Clause,Status,\n"
			    "       Description,Action_Type\n"
			    "  FROM SYS.ALL_TRIGGERS\n"
			    "WHERE Owner = :f1<char[101]> AND Trigger_Name = :f2<char[101]>",
			    "Display information about a trigger",
			    "8.1");
static toSQL SQLTriggerInfo8("toBrowser:TriggerInfo",
			     "SELECT Owner,Trigger_Name,\n"
			     "       Trigger_Type,Triggering_Event,\n"
			     "       Table_Owner,Table_Name,\n"
			     "       Referencing_Names,When_Clause,Status,\n"
			     "       Description\n"
			     "  FROM SYS.ALL_TRIGGERS\n"
			     "WHERE Owner = :f1<char[101]> AND Trigger_Name = :f2<char[101]>",
			     "",
			     "8.0");
static toSQL SQLTriggerBody("toBrowser:TriggerBody",
			    "SELECT Trigger_Body FROM SYS.ALL_TRIGGERS\n"
			    " WHERE Owner = :f1<char[101]> AND Trigger_Name = :f2<char[101]>",
			    "Implementation of trigger");
static toSQL SQLTriggerCols("toBrowser:TriggerCols",
			    "SELECT Column_Name,Column_List \"In Update\",Column_Usage Usage\n"
			    "  FROM SYS.ALL_TRIGGER_COLS\n"
			    " WHERE Trigger_Owner = :f1<char[101]> AND Trigger_Name = :f2<char[101]>",
			    "Columns used by trigger");
#if DBLINK
static toSQL SQLListDBLink("toBrowser:ListDBLink",
			   "SELECT Db_Link, Owner FROM SYS.ALL_DB_LINKS\n"
			   " WHERE (Owner = :f1<char[101]> or Owner='PUBLIC') and\n"
			   " UPPER(DB_Link) like :f2<char[101]>",
			   "List database links");
static toSQL SQLListDBLinkDBA("toBrowser:ListDBLinkDBA",
			      "SELECT Owner, Db_Link, Username, Host, Created\n"
			      " FROM SYS.DBA_DB_LINK\n",
			      "List database links as DBA");
static toSQL SQLDBLinkInfo("toBrowser:DBLinkInformation",
			    "SELECT * FROM Sys.all_db_links a\n"
			    " WHERE Owner = :f1<char[101]>\n"
			    "   AND DB_LINK = :f2<char[101]>",
			    "Display information about database link");
static toSQL SQLDBLinkSynonyms("toBrowser:DBLinkSynonyms",
			       "SELECT * FROM Sys.all_synonyms a\n"
			       " WHERE Owner = :f1<char[101]>\n"
			       "   AND DB_LINK = :f2<char[101]>",
			       "Display foreign synonyms");
#endif

static toSQL SQLMySQLAccess("toBrowser:MySQLAcess",
			    "SHOW TABLES FROM mysql",
			    "Show access tables for MySQL databases",
			    "3.23",
			    "MySQL");

static toSQL SQLMySQLUsers("toBrowser:MySQLUsers",
			   "SELECT concat(user,'@',host) Users FROM mysql.user",
			   "Show users for MySQL databases",
			   "3.23",
			   "MySQL");

static toSQL SQLTruncateTable("toBrowser:TruncateTable",
			      "TRUNCATE TABLE %1.%2",
			      "Truncate a table",
			      "",
			      "Any");

QString toBrowser::schema(void)
{
  try {
    QString ret=Schema->selected();
    if (ret==tr("No schemas"))
      return connection().database();
    return ret;
  } catch(...) {
    return QString::null;
  }
}

void toBrowser::setNewFilter(toBrowserFilter *filter)
{
  if (Filter) {
    delete Filter;
    Filter=NULL;
  }
  if (filter)
    Filter=filter;
  else
    Filter=new toBrowserFilter();
  disconnect(FilterButton,SIGNAL(toggled(bool)),this,SLOT(defineFilter()));
  FilterButton->setOn(filter);
  connect(FilterButton,SIGNAL(toggled(bool)),this,SLOT(defineFilter()));
  for(std::map<QCString,toResultView *>::iterator i=Map.begin();i!=Map.end();i++)
    (*i).second->setFilter(Filter->clone());
  refresh();
}

toBrowser::toBrowser(QWidget *parent,toConnection &connection)
  : toToolWidget(BrowserTool,"browser.html",parent,connection)
{
  Filter=new toBrowserFilter(false);

  QToolBar *toolbar=toAllocBar(this,tr("DB Browser"));

  new QToolButton(QPixmap((const char **)refresh_xpm),
		  tr("Update from DB"),
		  tr("Update from DB"),
		  this,SLOT(refresh(void)),
		  toolbar);
  toolbar->addSeparator();
  FilterButton=new QToolButton(toolbar);
  FilterButton->setToggleButton(true);
  FilterButton->setIconSet(QIconSet(QPixmap((const char **)filter_xpm)));
  QToolTip::add(FilterButton,tr("Define the object filter"));
  connect(FilterButton,SIGNAL(toggled(bool)),this,SLOT(defineFilter()));

  new QToolButton(QPixmap((const char **)nofilter_xpm),
		  tr("Remove any object filter"),
		  tr("Remove any object filter"),
		  this,SLOT(clearFilter(void)),
		  toolbar);
  Schema=new toResultCombo(toolbar,TO_KDE_TOOLBAR_WIDGET);
  connect(Schema,SIGNAL(activated(int)),
	  this,SLOT(changeSchema(int)));
  Schema->setSQL(toSQL::sql(toSQL::TOSQL_USERLIST));
  if (toIsMySQL(connection))
    Schema->setSelected(connection.database());
  else if (toIsOracle(connection)||toIsSapDB(connection))
    Schema->setSelected(connection.user().upper());
  else
    Schema->setSelected(connection.user());
  toolbar->setStretchableWidget(new QLabel(toolbar,TO_KDE_TOOLBAR_WIDGET));
  new toChangeConnection(toolbar,TO_KDE_TOOLBAR_WIDGET);
  
  TopTab=new toTabWidget(this);
  QSplitter *splitter=new QSplitter(Horizontal,TopTab,TAB_TABLES);
  TopTab->addTab(splitter,tr("T&ables"));
  CurrentTop=splitter;

  QVBox *box=new QVBox(splitter);

  toolbar=toAllocBar(box,tr("Database browser"));
  new toBrowseButton(QPixmap((const char **)addtable_xpm),
		     tr("Create new table"),
		     tr("Create new table"),
		     this,SLOT(addTable()),
		     toolbar);
  toolbar->addSeparator();
  new toBrowseButton(QPixmap((const char **)modtable_xpm),
		     tr("Modify table columns"),
		     tr("Modify table columns"),
		     this,SLOT(modifyTable()),
		     toolbar);
  new toBrowseButton(QPixmap((const char **)modconstraint_xpm),
		     tr("Modify constraints"),
		     tr("Modify constraints"),
		     this,SLOT(modifyConstraint()),
		     toolbar);
  new toBrowseButton(QPixmap((const char **)modindex_xpm),
		     tr("Modify indexes"),
		     tr("Modify indexes"),
		     this,SLOT(modifyIndex()),
		     toolbar);
  toolbar->addSeparator();
  new toBrowseButton(QPixmap((const char **)trash_xpm),
		     tr("Drop table"),
		     tr("Drop table"),
		     this,SLOT(dropTable()),
		     toolbar);
#ifndef TO_NO_ORACLE
  toolbar->addSeparator();
  new toBrowseButton(QPixmap((const char **)online_xpm),
		     tr("Enable constraint or trigger"),
		     tr("Enable constraint or trigger"),
		     this,SLOT(enableConstraints()),
		     toolbar);
  new toBrowseButton(QPixmap((const char **)offline_xpm),
		     tr("Disable constraint or trigger"),
		     tr("Disable constraint or trigger"),
		     this,SLOT(disableConstraints()),
		     toolbar);
#endif
  toolbar->setStretchableWidget(new QLabel(toolbar,TO_KDE_TOOLBAR_WIDGET));

  toResultView *resultView=new toResultLong(true,false,toQuery::Background,box);
  resultView->setReadAll(true);
  resultView->setSQL(SQLListTables);
  resultView->setResizeMode(QListView::AllColumns);
  setFocusProxy(resultView);
  box->resize(FIRST_WIDTH,resultView->height());
  splitter->setResizeMode(box,QSplitter::KeepSize);
  connect(resultView,SIGNAL(done()),this,SLOT(firstDone()));
  FirstTab=resultView;
  Map[TAB_TABLES]=resultView;
  resultView->setTabWidget(TopTab);
  connect(resultView,SIGNAL(selectionChanged()),
	  this,SLOT(changeItem()));
  connect(resultView,SIGNAL(displayMenu(QPopupMenu *)),this,SLOT(displayTableMenu(QPopupMenu *)));


  QTabWidget *curr=new toTabWidget(splitter);
  splitter->setResizeMode(curr,QSplitter::Stretch);

  toResultCols *resultCols=new toResultCols(curr,TAB_TABLE_COLUMNS);
  curr->addTab(resultCols,tr("&Columns"));
  SecondTab=resultCols;
  SecondMap[TAB_TABLES]=resultCols;
  SecondMap[TAB_TABLE_COLUMNS]=resultCols;

  resultView=new toResultIndexes(curr,TAB_TABLE_INDEXES);
  curr->addTab(resultView,tr("&Indexes"));
  SecondMap[TAB_TABLE_INDEXES]=resultView;

  toResultConstraint *resultConstraint=new toResultConstraint(curr,TAB_TABLE_CONS);
  curr->addTab(resultConstraint,tr("C&onstraints"));
  SecondMap[TAB_TABLE_CONS]=resultConstraint;

  toResultReferences *resultReferences=new toResultReferences(curr,TAB_TABLE_DEPEND);
  curr->addTab(resultReferences,tr("&References"));
  SecondMap[TAB_TABLE_DEPEND]=resultReferences;

  resultView=new toResultLong(true,false,toQuery::Background,curr,TAB_TABLE_GRANTS);
  resultView->setSQL(SQLAnyGrants);
  resultView->setReadAll(true);
  curr->addTab(resultView,tr("&Grants"));
  SecondMap[TAB_TABLE_GRANTS]=resultView;

  resultView=new toResultLong(true,false,toQuery::Background,curr,TAB_TABLE_TRIGGERS);
  resultView->setSQL(SQLTableTrigger);
  resultView->setReadAll(true);
  curr->addTab(resultView,tr("Triggers"));
  SecondMap[TAB_TABLE_TRIGGERS]=resultView;

  TableContent=new toResultContent(curr,TAB_TABLE_DATA);
  curr->addTab(TableContent,tr("&Data"));
  SecondMap[TAB_TABLE_DATA]=TableContent;

  toResultItem *resultInfo=new toResultItem(2,true,curr,TAB_TABLE_INFO);
  resultInfo->setSQL(SQLTableInfo);
  curr->addTab(resultInfo,tr("Information"));
  SecondMap[TAB_TABLE_INFO]=resultInfo;

  resultView=new toResultLong(true,false,toQuery::Background,curr,TAB_TABLE_STATISTIC);
  resultView->setSQL(SQLTableStatistic);
  resultView->setResizeMode(QListView::AllColumns);
  resultView->setReadAll(true);
  curr->addTab(resultView,tr("Statistic"));
  SecondMap[TAB_TABLE_STATISTIC]=resultView;

  resultView=new toResultLong(true,false,toQuery::Background,curr,TAB_TABLE_PARTITION);
  resultView->setSQL(SQLTablePartition);
  resultView->setReadAll(true);
  curr->addTab(resultView,tr("Partitions"));
  SecondMap[TAB_TABLE_PARTITION]=resultView;

  toResultExtent *resultExtent=new toResultExtent(curr,TAB_TABLE_EXTENT);
  curr->addTab(resultExtent,tr("Extents"));
  SecondMap[TAB_TABLE_EXTENT]=resultExtent;
  toResultExtract *resultExtract=new toResultExtract(true,this,TAB_TABLE_EXTRACT);
  curr->addTab(resultExtract,tr("Script"));
  SecondMap[TAB_TABLE_EXTRACT]=resultExtract;

  connect(curr,SIGNAL(currentChanged(QWidget *)),this,SLOT(changeSecondTab(QWidget *)));

  splitter=new QSplitter(Horizontal,TopTab,TAB_VIEWS);
  TopTab->addTab(splitter,tr("&Views"));
  resultView=new toResultLong(true,false,toQuery::Background,splitter);
  resultView->setReadAll(true);
  connect(resultView,SIGNAL(done()),this,SLOT(firstDone()));
  Map[TAB_VIEWS]=resultView;
  resultView->setTabWidget(TopTab);
  resultView->setSQL(SQLListView);
  resultView->resize(FIRST_WIDTH,resultView->height());
  resultView->setResizeMode(QListView::AllColumns);
  connect(resultView,SIGNAL(selectionChanged()),
	  this,SLOT(changeItem()));
  splitter->setResizeMode(resultView,QSplitter::KeepSize);
  curr=new toTabWidget(splitter);
  splitter->setResizeMode(curr,QSplitter::Stretch);
  resultCols=new toResultCols(curr,TAB_VIEW_COLUMNS);
  curr->addTab(resultCols,tr("&Columns"));
  SecondMap[TAB_VIEWS]=resultCols;
  SecondMap[TAB_VIEW_COLUMNS]=resultCols;

  toResultField *resultField=new toResultField(curr,TAB_VIEW_SQL);
  resultField->setSQL(SQLViewSQL);
  curr->addTab(resultField,tr("SQL"));
  SecondMap[TAB_VIEW_SQL]=resultField;

  ViewContent=new toResultContent(curr,TAB_VIEW_DATA);
  ViewContent->useNoReturning(true);
  curr->addTab(ViewContent,tr("&Data"));
  SecondMap[TAB_VIEW_DATA]=ViewContent;

  resultView=new toResultLong(true,false,toQuery::Background,curr,TAB_VIEW_GRANTS);
  resultView->setSQL(SQLAnyGrants);
  resultView->setReadAll(true);
  curr->addTab(resultView,tr("&Grants"));
  SecondMap[TAB_VIEW_GRANTS]=resultView;

  toResultDepend *resultDepend=new toResultDepend(curr,TAB_VIEW_DEPEND);
  curr->addTab(resultDepend,tr("De&pendencies"));
  SecondMap[TAB_VIEW_DEPEND]=resultDepend;

  resultExtract=new toResultExtract(true,this,TAB_VIEW_EXTRACT);
  curr->addTab(resultExtract,tr("Script"));
  SecondMap[TAB_VIEW_EXTRACT]=resultExtract;
  connect(curr,SIGNAL(currentChanged(QWidget *)),this,SLOT(changeSecondTab(QWidget *)));

  splitter=new QSplitter(Horizontal,TopTab,TAB_INDEX);

  TopTab->addTab(splitter,tr("Inde&xes"));

  box=new QVBox(splitter);
  toolbar=toAllocBar(box,tr("Database browser"));
  new toBrowseButton(QPixmap((const char **)addindex_xpm),
		     tr("Add indexes"),
		     tr("Add indexes"),
		     this,SLOT(addIndex()),
		     toolbar);
  toolbar->addSeparator();
  new toBrowseButton(QPixmap((const char **)modindex_xpm),
		     tr("Modify indexes"),
		     tr("Modify indexes"),
		     this,SLOT(modifyIndex()),
		     toolbar);
  toolbar->addSeparator();
  new toBrowseButton(QPixmap((const char **)trash_xpm),
		     tr("Drop index"),
		     tr("Drop index"),
		     this,SLOT(dropIndex()),
		     toolbar);
  toolbar->setStretchableWidget(new QLabel(toolbar,TO_KDE_TOOLBAR_WIDGET));

  resultView=new toResultLong(true,false,toQuery::Background,box);
  resultView->setReadAll(true);
  connect(resultView,SIGNAL(done()),this,SLOT(firstDone()));
  Map[TAB_INDEX]=resultView;
  resultView->setTabWidget(TopTab);
  resultView->setSQL(SQLListIndex);
  resultView->setResizeMode(QListView::AllColumns);
  connect(resultView,SIGNAL(selectionChanged()),
	  this,SLOT(changeItem()));
  connect(resultView,SIGNAL(displayMenu(QPopupMenu *)),this,SLOT(displayIndexMenu(QPopupMenu *))); 

  box->resize(FIRST_WIDTH,resultView->height());
  splitter->setResizeMode(box,QSplitter::KeepSize);
  curr=new toTabWidget(splitter);
  splitter->setResizeMode(curr,QSplitter::Stretch);

  resultView=new toResultLong(true,false,toQuery::Background,curr,TAB_INDEX_COLS);
  resultView->setSQL(SQLIndexCols);
  connect(resultView,SIGNAL(done()),this,SLOT(fixIndexCols()));
  curr->addTab(resultView,tr("&Columns"));
  SecondMap[TAB_INDEX]=resultView;
  SecondMap[TAB_INDEX_COLS]=resultView;

  toResultItem *resultIdxInfo=new toResultItem(2,true,curr,TAB_INDEX_INFO);
  resultIdxInfo->setSQL(SQLIndexInfo);
  curr->addTab(resultIdxInfo,tr("Info"));
  SecondMap[TAB_INDEX_INFO]=resultIdxInfo;

  resultView=new toResultLong(true,false,toQuery::Background,curr,TAB_INDEX_STATISTIC);
  resultView->setSQL(SQLIndexStatistic);
  resultView->setResizeMode(QListView::AllColumns);
  resultView->setReadAll(true);
  curr->addTab(resultView,tr("&Statistic"));
  SecondMap[TAB_INDEX_STATISTIC]=resultView;

  resultExtent=new toResultExtent(curr,TAB_INDEX_EXTENT);
  curr->addTab(resultExtent,tr("Extents"));
  SecondMap[TAB_INDEX_EXTENT]=resultExtent;

  resultExtract=new toResultExtract(true,this,TAB_INDEX_EXTRACT);
  curr->addTab(resultExtract,tr("Script"));
  SecondMap[TAB_INDEX_EXTRACT]=resultExtract;
  connect(curr,SIGNAL(currentChanged(QWidget *)),this,SLOT(changeSecondTab(QWidget *)));

  splitter=new QSplitter(Horizontal,TopTab,TAB_SEQUENCES);
  TopTab->addTab(splitter,tr("Se&quences"));
  resultView=new toResultLong(true,false,toQuery::Background,splitter);
  resultView->setReadAll(true);
  resultView->setSQL(SQLListSequence);
  connect(resultView,SIGNAL(done()),this,SLOT(firstDone()));
  Map[TAB_SEQUENCES]=resultView;
  resultView->setTabWidget(TopTab);
  resultView->setSQL(SQLListSequence);
  resultView->resize(FIRST_WIDTH,resultView->height());
  resultView->setResizeMode(QListView::AllColumns);
  connect(resultView,SIGNAL(selectionChanged()),
	  this,SLOT(changeItem()));
  splitter->setResizeMode(resultView,QSplitter::KeepSize);
  curr=new toTabWidget(splitter);
  splitter->setResizeMode(curr,QSplitter::Stretch);

  toResultItem *resultSequences=new toResultItem(2,true,curr,TAB_SEQUENCES_INFO);
  resultSequences->setSQL(SQLSequenceInfo);
  curr->addTab(resultSequences,tr("Info"));
  SecondMap[TAB_SEQUENCES]=resultSequences;
  SecondMap[TAB_SEQUENCES_INFO]=resultSequences;
  resultView=new toResultLong(true,false,toQuery::Background,curr,TAB_SEQUENCES_GRANTS);
  resultView->setSQL(SQLAnyGrants);
  resultView->setReadAll(true);
  curr->addTab(resultView,tr("&Grants"));
  SecondMap[TAB_SEQUENCES_GRANTS]=resultView;

  resultExtract=new toResultExtract(true,this,TAB_SEQUENCES_EXTRACT);
  curr->addTab(resultExtract,tr("Script"));
  SecondMap[TAB_SEQUENCES_EXTRACT]=resultExtract;

  connect(curr,SIGNAL(currentChanged(QWidget *)),this,SLOT(changeSecondTab(QWidget *)));

  splitter=new QSplitter(Horizontal,TopTab,TAB_SYNONYM);
  TopTab->addTab(splitter,tr("S&ynonyms"));
  resultView=new toResultLong(true,false,toQuery::Background,splitter);
  resultView->setReadAll(true);
  connect(resultView,SIGNAL(done()),this,SLOT(firstDone()));
  Map[TAB_SYNONYM]=resultView;
  resultView->setTabWidget(TopTab);
  resultView->setSQL(SQLListSynonym);
  resultView->resize(FIRST_WIDTH,resultView->height());
  resultView->setResizeMode(QListView::AllColumns);
  connect(resultView,SIGNAL(selectionChanged()),
	  this,SLOT(changeItem()));
  splitter->setResizeMode(resultView,QSplitter::KeepSize);
  curr=new toTabWidget(splitter);
  splitter->setResizeMode(curr,QSplitter::Stretch);

  toResultItem *resultSynonym=new toResultItem(2,true,curr,TAB_SYNONYM_INFO);
  resultSynonym->setSQL(SQLSynonymInfo);
  curr->addTab(resultSynonym,tr("Info"));
  SecondMap[TAB_SYNONYM]=resultSynonym;
  SecondMap[TAB_SYNONYM_INFO]=resultSynonym;

  resultView=new toResultLong(true,false,toQuery::Background,curr,TAB_SYNONYM_GRANTS);
  resultView->setSQL(SQLAnyGrants);
  resultView->setReadAll(true);
  curr->addTab(resultView,tr("&Grants"));
  SecondMap[TAB_SYNONYM_GRANTS]=resultView;

  resultExtract=new toResultExtract(true,this,TAB_SYNONYM_EXTRACT);
  curr->addTab(resultExtract,tr("Script"));
  SecondMap[TAB_SYNONYM_EXTRACT]=resultExtract;

  connect(curr,SIGNAL(currentChanged(QWidget *)),this,SLOT(changeSecondTab(QWidget *)));

  splitter=new QSplitter(Horizontal,TopTab,TAB_PLSQL);
  TopTab->addTab(splitter,tr("Cod&e"));
  resultView=new toResultLong(true,false,toQuery::Background,splitter);
  resultView->setReadAll(true);
  connect(resultView,SIGNAL(done()),this,SLOT(firstDone()));
  Map[TAB_PLSQL]=resultView;
  resultView->setTabWidget(TopTab);
  resultView->setSQL(SQLListSQL);
  resultView->resize(FIRST_WIDTH*2,resultView->height());
  resultView->setResizeMode(QListView::AllColumns);
  connect(resultView,SIGNAL(selectionChanged()),
	  this,SLOT(changeItem()));
  splitter->setResizeMode(resultView,QSplitter::KeepSize);
  curr=new toTabWidget(splitter);
  splitter->setResizeMode(curr,QSplitter::Stretch);

  resultField=new toResultField(curr,TAB_PLSQL_SOURCE);
  resultField->setSQL(SQLSQLHead);
  curr->addTab(resultField,tr("&Declaration"));
  SecondMap[TAB_PLSQL]=resultField;
  SecondMap[TAB_PLSQL_SOURCE]=resultField;

  resultField=new toResultField(curr,TAB_PLSQL_BODY);
  resultField->setSQL(SQLSQLBody);
  curr->addTab(resultField,tr("B&ody"));
  SecondMap[TAB_PLSQL_BODY]=resultField;

  resultView=new toResultLong(true,false,toQuery::Background,curr,TAB_PLSQL_GRANTS);
  resultView->setReadAll(true);
  resultView->setSQL(SQLAnyGrants);
  curr->addTab(resultView,tr("&Grants"));
  SecondMap[TAB_PLSQL_GRANTS]=resultView;
  resultDepend=new toResultDepend(curr,TAB_PLSQL_DEPEND);
  curr->addTab(resultDepend,tr("De&pendencies"));
  SecondMap[TAB_PLSQL_DEPEND]=resultDepend;

  resultExtract=new toResultExtract(true,this,TAB_PLSQL_EXTRACT);
  curr->addTab(resultExtract,tr("Script"));
  SecondMap[TAB_PLSQL_EXTRACT]=resultExtract;
  connect(curr,SIGNAL(currentChanged(QWidget *)),this,SLOT(changeSecondTab(QWidget *)));

  splitter=new QSplitter(Horizontal,TopTab,TAB_TRIGGER);
  TopTab->addTab(splitter,tr("Tri&ggers"));
  resultView=new toResultLong(true,false,toQuery::Background,splitter);
  resultView->setReadAll(true);
  connect(resultView,SIGNAL(done()),this,SLOT(firstDone()));
  Map[TAB_TRIGGER]=resultView;
  resultView->setTabWidget(TopTab);
  resultView->setSQL(SQLListTrigger);
  resultView->resize(FIRST_WIDTH,resultView->height());
  resultView->setResizeMode(QListView::AllColumns);
  connect(resultView,SIGNAL(selectionChanged()),
	  this,SLOT(changeItem()));
  splitter->setResizeMode(resultView,QSplitter::KeepSize);
  curr=new toTabWidget(splitter);
  splitter->setResizeMode(curr,QSplitter::Stretch);

  toResultItem *resultTrigger=new toResultItem(2,true,curr,TAB_TRIGGER_INFO);
  resultTrigger->setSQL(SQLTriggerInfo);
  curr->addTab(resultTrigger,tr("Info"));
  SecondMap[TAB_TRIGGER]=resultTrigger;
  SecondMap[TAB_TRIGGER_INFO]=resultTrigger; 

  resultField=new toResultField(curr,TAB_TRIGGER_SOURCE);
  resultField->setSQL(SQLTriggerBody);
  curr->addTab(resultField,tr("C&ode"));
  SecondMap[TAB_TRIGGER_SOURCE]=resultField;

  resultView=new toResultLong(true,false,toQuery::Background,curr,TAB_TRIGGER_COLS);
  resultView->setSQL(SQLTriggerCols);
  curr->addTab(resultView,tr("&Columns"));
  SecondMap[TAB_TRIGGER_COLS]=resultView;

  resultView=new toResultLong(true,false,toQuery::Background,curr,TAB_TRIGGER_GRANTS);
  resultView->setSQL(SQLAnyGrants);
  resultView->setReadAll(true);
  curr->addTab(resultView,tr("&Grants"));
  SecondMap[TAB_TRIGGER_GRANTS]=resultView;

  resultDepend=new toResultDepend(curr,TAB_TRIGGER_DEPEND);
  curr->addTab(resultDepend,tr("De&pendencies"));
  SecondMap[TAB_TRIGGER_DEPEND]=resultDepend;

  resultExtract=new toResultExtract(true,this,TAB_TRIGGER_EXTRACT);
  curr->addTab(resultExtract,tr("Script"));
  SecondMap[TAB_TRIGGER_EXTRACT]=resultExtract;

  connect(curr,SIGNAL(currentChanged(QWidget *)),this,SLOT(changeSecondTab(QWidget *)));

#ifdef DBLINK
  splitter=new QSplitter(Horizontal,TopTab,TAB_DBLINK);
  TopTab->addTab(splitter,tr("DBLinks"));
  box=new QVBox(splitter);
  toolbar=toAllocBar(box,tr("Database browser"));
  new toBrowseButton(QPixmap((const char **)modconstraint_xpm),
		     tr("Test DBLink"),
		     tr("Test DBLink"),
		     this,SLOT(testDBLink()),
		     toolbar);
  toolbar->addSeparator();
  toolbar->setStretchableWidget(new QLabel(toolbar,TO_KDE_TOOLBAR_WIDGET));
  
  resultView=new toResultLong(true,false,toQuery::Background,box);
  resultView->setReadAll(true);
  connect(resultView,SIGNAL(done()),this,SLOT(firstDone()));
  Map[TAB_DBLINK]=resultView;
  resultView->setTabWidget(TopTab);
  resultView->setSQL(SQLListDBLink);
  resultView->resize(FIRST_WIDTH,resultView->height());
  resultView->setResizeMode(QListView::AllColumns);
  connect(resultView,SIGNAL(selectionChanged()),
	  this,SLOT(changeItem()));
  connect(resultView,SIGNAL(displayMenu(QPopupMenu *)),this,SLOT(displayIndexMenu(QPopupMenu *)));
  box->resize(FIRST_WIDTH,resultView->height());
  splitter->setResizeMode(box,QSplitter::KeepSize);
  curr=new toTabWidget(splitter);
  splitter->setResizeMode(curr,QSplitter::Stretch);

  toResultItem *resultDBLink=new toResultItem(2,true,curr,TAB_DBLINK_INFO);
  resultDBLink->setSQL(SQLDBLinkInfo);
  curr->addTab(resultDBLink,tr("Info"));
  SecondMap[TAB_DBLINK]=resultDBLink;
  SecondMap[TAB_DBLINK_INFO]=resultDBLink;

  resultView=new toResultLong(true,false,toQuery::Background,curr,TAB_DBLINK_SYNONYMS);
  resultView->setSQL(SQLDBLinkSynonyms);
  curr->addTab(resultView,tr("&Synonyms"));
  SecondMap[TAB_DBLINK_SYNONYMS]=resultView;

  connect(curr,SIGNAL(currentChanged(QWidget *)),this,SLOT(changeSecondTab(QWidget *)));
#endif

  splitter=new QSplitter(Horizontal,TopTab,TAB_ACCESS);
  TopTab->addTab(splitter,tr("Access"));
#ifdef TOEXTENDED_MYSQL
  box=new QVBox(splitter);
  toolbar=toAllocBar(box,tr("Database browser"));
  new toBrowseButton(QPixmap((const char **)new_xpm),
		     tr("Add user"),
		     tr("Add user"),
		     this,SLOT(addUser()),
		     toolbar);
  new toBrowseButton(QPixmap((const char **)trash_xpm),
		     tr("Drop user"),
		     tr("Drop user"),
		     this,SLOT(dropUser()),
		     toolbar);
  toolbar->setStretchableWidget(new QLabel(toolbar,TO_KDE_TOOLBAR_WIDGET));
  resultView=new toResultLong(true,false,toQuery::Background,box);
#else
  resultView=new toResultLong(true,false,toQuery::Background,splitter);
#endif
  resultView->setReadAll(true);
  connect(resultView,SIGNAL(done()),this,SLOT(firstDone()));
  Map[TAB_ACCESS]=resultView;
  resultView->setTabWidget(TopTab);
  resultView->setResizeMode(QListView::AllColumns);
  resultView->resize(FIRST_WIDTH,resultView->height());
  connect(resultView,SIGNAL(selectionChanged()),
	  this,SLOT(changeItem()));
  curr=new toTabWidget(splitter);
  splitter->setResizeMode(curr,QSplitter::Stretch);

#ifdef TOEXTENDED_MYSQL
  splitter->setResizeMode(box,QSplitter::KeepSize);
  resultView->setSQL(SQLMySQLUsers);

  AccessContent=NULL;

  UserPanel=new toMySQLUser(curr,TAB_ACCESS_USER);
  curr->addTab(UserPanel,tr("&User"));
  SecondMap[TAB_ACCESS]=UserPanel;
  SecondMap[TAB_ACCESS_USER]=UserPanel;

  AccessPanel=new toMySQLUserAccess(curr,TAB_ACCESS_OBJECTS);
  curr->addTab(AccessPanel,tr("&Objects"));
  SecondMap[TAB_ACCESS_OBJECTS]=UserPanel;	// Yes, it should be this one, it will signal the TAB_ACCESS_OBJECTS to update.
  connect(AccessPanel,SIGNAL(hasChanged()),UserPanel,SLOT(hasChanged()));
  connect(UserPanel,SIGNAL(saveChanges(const QString &,const QString &)),AccessPanel,SLOT(saveChanges(const QString &,const QString &)));
  connect(UserPanel,SIGNAL(changeUser(const QString &)),AccessPanel,SLOT(changeUser(const QString &)));

  AccessContent=new toResultContent(curr,TAB_ACCESS_CONTENT);
  curr->addTab(AccessContent,tr("&Hosts"));
  SecondMap[TAB_ACCESS_CONTENT]=AccessContent; 
#else
  splitter->setResizeMode(resultView,QSplitter::KeepSize);
  resultView->setSQL(SQLMySQLAccess);

  AccessContent=new toResultContent(curr,TAB_ACCESS_CONTENT);
  curr->addTab(AccessContent,tr("&Data"));
  SecondMap[TAB_ACCESS]=AccessContent;
  SecondMap[TAB_ACCESS_CONTENT]=AccessContent; 
#endif
  connect(AccessContent,SIGNAL(changesSaved()),this,SLOT(flushPrivs()));

  connect(curr,SIGNAL(currentChanged(QWidget *)),this,SLOT(changeSecondTab(QWidget *)));
  
  ToolMenu=NULL;
  connect(toMainWidget()->workspace(),SIGNAL(windowActivated(QWidget *)),
	  this,SLOT(windowActivated(QWidget *)));

  refresh();

  connect(TopTab,SIGNAL(currentChanged(QWidget *)),this,SLOT(changeTab(QWidget *)));
  connect(this,SIGNAL(connectionChange()),this,SLOT(changeConnection()));
  Schema->setFocus();
  connect(&Poll,SIGNAL(timeout()),this,SLOT(changeSecond()));

  setNewFilter(NULL);
}

void toBrowser::windowActivated(QWidget *widget)
{
  if (widget==this) {
    if (!ToolMenu) {
      ToolMenu=new QPopupMenu(this);
      ToolMenu->insertItem(QPixmap((const char **)refresh_xpm),tr("&Refresh"),this,SLOT(refresh(void)),
			   toKeySequence(tr("F5", "Browser|Refresh")));
      ToolMenu->insertItem(tr("&Change Schema"),Schema,SLOT(setFocus(void)),
			   toKeySequence(tr("Alt+S", "Browser|Change Schema")));
      ToolMenu->insertItem(tr("Change &Object"),this,SLOT(focusObject(void)),
			   toKeySequence(tr("Alt+N", "Browser|Change object")));
      ToolMenu->insertSeparator();
      ToolMenu->insertItem(QPixmap((const char **)filter_xpm),tr("&Define filter..."),
			   this,SLOT(defineFilter(void)),
			   toKeySequence(tr("Ctrl+Shift+G", "Browser|Define filter")));
      ToolMenu->insertItem(QPixmap((const char **)nofilter_xpm),tr("&Clear filter"),this,SLOT(clearFilter(void)),
			   toKeySequence(tr("Ctrl+Shift+H", "Browser|Clear filter")));
      toMainWidget()->menuBar()->insertItem(tr("&Browser"),ToolMenu,-1,toToolMenuIndex());
    }
  } else {
    delete ToolMenu;
    ToolMenu=NULL;
  }
}

static toSQL SQLDropUser("toBrowser:DropUser",
			 "DELETE FROM mysql.user WHERE concat(user,'@',host) = :f1<char[255]>",
			 "Drop MYSQL user",
			 "3.23",
			 "MySQL");

void toBrowser::addUser()
{
#ifdef TOEXTENDED_MYSQL
  UserPanel->changeParams(QString::null,QString::null);
#endif
}

void toBrowser::dropUser()
{
#ifdef TOEXTENDED_MYSQL
  try {
    AccessPanel->dropCurrentAccess();
    connection().execute(SQLDropUser,selectedItem()->text(0));
    flushPrivs();
    refresh();
  } TOCATCH
#endif
}

void toBrowser::changeSchema(int)
{
  SecondText=QString::fromLatin1("");
  updateTabs();
}

toBrowser::~toBrowser()
{
  delete Filter;
}

void toBrowser::refresh(void)
{
  try {
    Schema->refresh();
    if (FirstTab) {
      toQList pars=FirstTab->params();
      if (pars.begin()==pars.end()) {
	updateTabs();
	return;
      }
      FirstTab->refresh();
    }
    if (SecondTab) {
      toQList pars=SecondTab->params();
      if (pars.begin()==pars.end()) {
	updateTabs();
	return;
      }
      SecondTab->refresh();
    }
  } TOCATCH
}

void toBrowser::focusObject(void)
{
  if (FirstTab)
    FirstTab->setFocus();
}

void toBrowser::changeConnection(void)
{
  FirstTab->clear();
  Schema->refresh();
  SecondText=QString::null;
  updateTabs();
}

void toBrowser::updateTabs(void)
{
  try {
    if (!Schema->selected().isEmpty()&&FirstTab)
      FirstTab->changeParams(schema(),Filter?Filter->wildCard():QString::fromLatin1("%"));
    firstDone(); // In case it is ignored cause it is already done.
    if (SecondTab&&!SecondText.isEmpty())
      changeSecond();
  } TOCATCH
}

void toBrowser::firstDone(void)
{
  if (!SecondText.isEmpty()&&FirstTab) {
    for (QListViewItem *item=FirstTab->firstChild();item;item=item->nextSibling()) {
      if (item->text(0)==SecondText) {
	FirstTab->setSelected(item,true);
	FirstTab->setCurrentItem(item);
	FirstTab->ensureItemVisible(item);
	break;
      }
    }
  } else {
    QListViewItem *item=selectedItem();
    if (item)
      SecondText=item->text(0);
  }
}

void toBrowser::changeItem()
{
  QListViewItem *item=selectedItem();
  if (item) {
    SecondText=item->text(0);
    if (SecondTab&&!SecondText.isEmpty())
      Poll.start(250,true);
  }
}

void toBrowser::changeSecond(void)
{
  QWidget *tab=TopTab->currentPage();
  QWidget *tab2=dynamic_cast<QWidget *>(SecondTab);
  if (tab&&!strcmp(tab->name(),TAB_SYNONYM)) {
    QString owner;
    QString name;
    int pos=SecondText.find(QString::fromLatin1("."));
    if (pos>=0) {
      owner=SecondText.mid(0,pos);
      name=SecondText.mid(pos+1);
    } else {
      owner=QString::fromLatin1("PUBLIC");
      name=SecondText;
    }
    SecondTab->changeParams(owner,name);
#ifdef TOEXTENDED_MYSQL
  } else if (tab&&!strcmp(tab->name(),TAB_ACCESS)&&!strcmp(tab2->name(),TAB_ACCESS_CONTENT)) {
    SecondTab->changeParams("mysql",
			    "host");
#else
  } else if (tab&&!strcmp(tab->name(),TAB_ACCESS)) {
    SecondTab->changeParams("mysql",
			    SecondText);
#endif
  } else if (tab&&!strcmp(tab->name(),TAB_INDEX)&&!strcmp(tab2->name(),TAB_INDEX_EXTRACT)) {
    QListViewItem *item=selectedItem();
    if (item)
      SecondTab->changeParams(schema(),item->text(0)+"."+item->text(1));
  } else
    SecondTab->changeParams(schema(),
			    SecondText);
}

void toBrowser::changeSecondTab(QWidget *tab)
{
  for (QWidget *t=tab->parentWidget();t!=TopTab->currentPage();t=t->parentWidget())
    if (!t)
      return;

  if (tab) {
    toResult *newtab=SecondMap[tab->name()];
    if (newtab==SecondTab)
      return;

    // The change second tab can get called for other tabs than the current one. Ignore those
    // calls.
    QWidget *t=dynamic_cast<QWidget *>(newtab);
    while(t&&t!=CurrentTop)
      t=t->parentWidget();
    if (!t)
      return;

    SecondTab=newtab;
    SecondMap[TopTab->currentPage()->name()]=SecondTab;
    if (SecondTab&&!SecondText.isEmpty())
      changeSecond();
  }
}

void toBrowser::changeTab(QWidget *tab)
{
  if (tab&&this==toMainWidget()->workspace()->activeWindow()) {
    toResultView *newtab=Map[tab->name()];
    if (newtab==FirstTab)
      return;
    CurrentTop=tab;
    setFocusProxy(newtab);
    FirstTab=newtab;
    SecondTab=SecondMap[tab->name()];
    SecondText="";
    
    if (FirstTab&&SecondTab)
      updateTabs();
  }
}

void toBrowser::clearFilter(void)
{
  setNewFilter(NULL);
}

void toBrowser::defineFilter(void)
{
  if (Filter) {
    toBrowserFilterSetup filt(false,*Filter,this);
    if (filt.exec())
      setNewFilter(filt.getSetting());
  } else {
    toBrowserFilterSetup filt(false,this);
    if (filt.exec())
      setNewFilter(filt.getSetting());
  }
}

bool toBrowser::canHandle(toConnection &conn)
{
  return toIsOracle(conn)||toIsMySQL(conn)||toIsSapDB(conn);
}

void toBrowser::modifyTable(void)
{
  toBrowserTable::editTable(connection(),
			    Schema->selected(),
			    SecondText,
			    this);
  refresh();
}

void toBrowser::addTable(void)
{
  toBrowserTable::newTable(connection(),
			   Schema->selected(),
			   this);
  refresh();
}

void toBrowser::modifyConstraint(void)
{
  toBrowserConstraint::modifyConstraint(connection(),
					Schema->selected(),
					SecondText,
					this);
  refresh();
}

void toBrowser::modifyIndex(void)
{
  QString index;
  QListViewItem *item=selectedItem();
  if (FirstTab->columns()>1&&item)
    index=item->text(1);

  if (item) {
    toBrowserIndex::modifyIndex(connection(),
				Schema->selected(),
				item->text(0),
				this,
				index);
  }
  refresh();
}

void toBrowser::addIndex(void)
{
  toBrowserIndex::addIndex(connection(),
			   Schema->selected(),
			   SecondText,
			   this);
  refresh();
}

void toBrowser::displayTableMenu(QPopupMenu *menu)
{
  menu->insertSeparator(0);
  menu->insertItem(QPixmap((const char **)trash_xpm),tr("Drop table"),this,SLOT(dropTable()),0,0,0);
  menu->insertItem(tr("Truncate table"),this,SLOT(truncateTable()),0,0,0);
  menu->insertSeparator(0);
  if (toIsMySQL(connection())) {
    menu->insertItem(tr("Check table"),this,SLOT(checkTable()),0,0,0);
    menu->insertItem(tr("Optimize table"),this,SLOT(optimizeTable()),0,0,0);
    menu->insertItem(tr("Analyze table"),this,SLOT(analyzeTable()),0,0,0);
    menu->insertItem(tr("Change type"),this,SLOT(changeType()),0,0,0);
    menu->insertSeparator(0);
  }
  menu->insertItem(QPixmap((const char **)modconstraint_xpm),tr("Modify constraints"),this,SLOT(modifyConstraint()),0,0,0);
  menu->insertItem(QPixmap((const char **)modindex_xpm),tr("Modify indexes"),this,SLOT(modifyIndex()),0,0,0);
  menu->insertItem(QPixmap((const char **)addtable_xpm),tr("Create table"),this,SLOT(addTable()),0,0,0);
  menu->insertSeparator(0);
  menu->insertItem(QPixmap((const char **)refresh_xpm),tr("Refresh"),this,SLOT(refresh()),0,0,0);
}

void toBrowser::displayIndexMenu(QPopupMenu *menu)
{
  menu->insertSeparator(0);
  menu->insertItem(QPixmap((const char **)trash_xpm),tr("Drop index"),this,SLOT(dropIndex()),0,0,0);
  menu->insertItem(QPixmap((const char **)modindex_xpm),tr("Modify index"),this,SLOT(modifyIndex()),0,0,0);
  menu->insertItem(QPixmap((const char **)addindex_xpm),tr("Create index"),this,SLOT(addIndex()),0,0,0);
  menu->insertSeparator(0);
  menu->insertItem(QPixmap((const char **)refresh_xpm),tr("Refresh"),this,SLOT(refresh()),0,0,0);
}

void toBrowser::dropSomething(const QString &type,const QString &what)
{
  if (what.isEmpty())
    return;
  if (TOMessageBox::warning(this,tr("Dropping %1?").arg(tr(type)),
			    tr("Are you sure you want to drop the %1 %2.%3,\n"
			       "this action can not be undone?").arg(tr(type)).arg(Schema->selected()).arg(what),
			    tr("&Yes"),tr("&Cancel"),QString::null,0)==0) {
    std::list<QString> ctx;
    toPush(ctx,Schema->selected());
    toPush(ctx,QString(type.upper()));
    QStringList parts=QStringList::split(".",what);
    if (parts.count()>1) {
      toPush(ctx,parts[1]);
      toPush(ctx,QString("ON"));
      toPush(ctx,parts[0]);
    } else {
      toPush(ctx,what);
    }

    std::list<QString> drop;
    toExtract::addDescription(drop,ctx);

    std::list<QString> empty;

    try {
      toExtract extractor(connection(),NULL);
      extractor.setIndexes(false);
      extractor.setConstraints(false);
      extractor.setPrompt(false);
      extractor.setHeading(false);
      QString sql=extractor.migrate(drop,empty);

      std::list<toSQLParse::statement> statements=toSQLParse::parse(sql,connection());
      QProgressDialog prog(tr("Performing %1 changes").arg(tr(type)),
			   tr("Executing %1 change script").arg(tr(type)),
			   statements.size(),
			   this,"progress",true);
      prog.setCaption(tr("Performing %1 changes").arg(tr(type)));
      for(std::list<toSQLParse::statement>::iterator i=statements.begin();i!=statements.end();i++) {
	QString sql=toSQLParse::indentStatement(*i,connection());
	int i=sql.length()-1;
	while(i>=0&&(sql.at(i)==';'||sql.at(i).isSpace()))
	  i--;
	if (i>=0)
	  connection().execute(sql.mid(0,i+1));
	qApp->processEvents();
	if (prog.wasCancelled())
	  throw tr("Cancelled ongoing %1 modification, %2 might be corrupt").arg(tr(type)).arg(tr(type));
      }
    } TOCATCH
  }
  refresh();
}

void toBrowser::dropTable(void)
{
  dropSomething("table",SecondText);
}

void toBrowser::truncateTable(void)
{
  bool force=false;
  for(QListViewItem *item=FirstTab->firstChild();item;item=item->nextSibling()) {
    if (item->isSelected()) {
      switch (force?0:TOMessageBox::warning(this,tr("Truncate table?"),
					    tr("Are you sure you want to truncate the table %2.%3,\n"
					       "this action can not be undone?").arg(Schema->selected()).arg(item->text(0)),
					    tr("&Yes"),tr("Yes to &all"),tr("&Cancel"),0)) {
      case 1:
	force=true;
	// Intentionally no break here.
      case 0:
	connection().execute(toSQL::string(SQLTruncateTable,connection()).
			     arg(connection().quote(Schema->selected())).
			     arg(connection().quote(item->text(0))));
	break;
      case 2:
	return;
      }
    }
  }
}

void toBrowser::flushPrivs(void)
{
  try {
    connection().execute("FLUSH PRIVILEGES");
  } TOCATCH
}

void toBrowser::checkTable(void)
{
  QString sql;

  for(QListViewItem *item=FirstTab->firstChild();item;item=item->nextSibling()) {
    if (item->isSelected()) {
      if (sql.isEmpty())
	sql="CHECK TABLE ";
      else
	sql+=", ";
      sql+=connection().quote(Schema->selected())+"."+connection().quote(item->text(0));
    }
  }

  if (!sql.isEmpty()) {
    toResultLong *result=new toResultLong(this,"Check result",WType_TopLevel|WDestructiveClose);
    result->query(sql);
    result->show();
  }

}

void toBrowser::optimizeTable(void)
{
  QString sql;

  for(QListViewItem *item=FirstTab->firstChild();item;item=item->nextSibling()) {
    if (item->isSelected()) {
      if (sql.isEmpty())
	sql="OPTIMIZE TABLE ";
      else
	sql+=", ";
      sql+=connection().quote(Schema->selected())+"."+connection().quote(item->text(0));
    }
  }

  if (!sql.isEmpty()) {
    toResultLong *result=new toResultLong(this,"Check result",WType_TopLevel|WDestructiveClose);
    result->query(sql);
    result->show();
  }
}

void toBrowser::changeType(void)
{
  bool ok;
  QString text=QInputDialog::getText("Change table type","Enter new table type",QLineEdit::Normal,
				     "MyISAM",&ok,this);
  if (ok&&!text.isEmpty()) {
    for(QListViewItem *item=FirstTab->firstChild();item;item=item->nextSibling()) {
      if (item->isSelected()) {
	QString sql="ALTER TABLE ";
	sql+=connection().quote(Schema->selected())+"."+connection().quote(item->text(0));
	sql+=" TYPE = "+text;
	try {
	  connection().execute(sql);
	} TOCATCH
      }
    }
  }
}

void toBrowser::analyzeTable(void)
{
  QString sql;

  for(QListViewItem *item=FirstTab->firstChild();item;item=item->nextSibling()) {
    if (item->isSelected()) {
      if (sql.isEmpty())
	sql="ANALYZE TABLE ";
      else
	sql+=", ";
      sql+=connection().quote(Schema->selected())+"."+connection().quote(item->text(0));
    }
  }

  if (!sql.isEmpty()) {
    toResultLong *result=new toResultLong(this,"Check result",WType_TopLevel|WDestructiveClose);
    result->query(sql);
    result->show();
  }
}

QListViewItem *toBrowser::selectedItem()
{
  QListViewItem *selected=NULL;
  for(QListViewItem *item=FirstTab->firstChild();item;item=item->nextSibling()) {
    if (item->isSelected()) {
      if (item==FirstTab->currentItem())
	return item;
      else if (!selected)
	selected=item;
    }
  }
  return selected;
}

void toBrowser::dropIndex(void)
{
  for(QListViewItem *item=FirstTab->firstChild();item;item=item->nextSibling()) {
    if (item->isSelected()) {
      QString index=item->text(1);
      if (index!="PRIMARY"&&!item->text(0).isEmpty())
	dropSomething("index",item->text(0)+"."+index);
      else
	dropSomething("index",item->text(0));
    }
  }
}

bool toBrowser::close(bool del)
{
#ifdef TOEXTENDED_MYSQL
  UserPanel->saveChanges();
#endif
  
  return toToolWidget::close(del);
}

void toBrowser::exportData(std::map<QCString,QString> &data,const QCString &prefix)
{
  data[prefix+":Schema"]=Schema->selected();
  data[prefix+":FirstTab"]=TopTab->currentPage()->name();
  data[prefix+":SecondText"]=SecondText;
  for(std::map<QCString,toResult *>::iterator i=SecondMap.begin();i!=SecondMap.end();i++) {
    if ((*i).second==SecondTab&&Map.find((*i).first)==Map.end()) {
      data[prefix+":SecondTab"]=(*i).first;
      break;
    }
  }
  ViewContent->exportData(data,prefix+":View");
  TableContent->exportData(data,prefix+":Table");
  if (AccessContent)
    AccessContent->exportData(data,prefix+":Hosts");
  toToolWidget::exportData(data,prefix);
  if (Filter)
    Filter->exportData(data,prefix+":Filter");
}

void toBrowser::importData(std::map<QCString,QString> &data,const QCString &prefix)
{
  disconnect(Schema,SIGNAL(activated(int)),
	     this,SLOT(changeSchema(int)));
  disconnect(TopTab,SIGNAL(currentChanged(QWidget *)),this,SLOT(changeTab(QWidget *)));

  ViewContent->importData(data,prefix+":View");
  TableContent->importData(data,prefix+":Table");
  if (AccessContent)
    AccessContent->importData(data,prefix+":Hosts");

  if (data.find(prefix+":Filter:Type")!=data.end()) {
    toBrowserFilter *filter=new toBrowserFilter;
    filter->importData(data,prefix+":Filter");
    setNewFilter(filter);
  } else
    setNewFilter(NULL);

  toToolWidget::importData(data,prefix);
  QString str=data[prefix+":Schema"];
  Schema->setSelected(str);
  for(int i=0;i<Schema->count();i++)
    if (Schema->text(i)==str)
      Schema->setCurrentItem(i);

  str=data[prefix+":FirstTab"];
  QWidget *chld=(QWidget *)child(str);
  if(chld&&str.length()) {
    SecondText=QString::null;
    TopTab->showPage(chld);

    toResultView *newtab=Map[chld->name()];
    if (newtab!=FirstTab&&newtab) {
      CurrentTop=chld;
      setFocusProxy(newtab);
      FirstTab=newtab;
    }

    str=data[prefix+":SecondTab"];
    chld=(QWidget *)child(str);
    if (chld&&str.length()) {
      QWidget *par=chld->parentWidget();
      while(par&&!par->inherits("QTabWidget"))
	par=par->parentWidget();
      if (par)
	((QTabWidget *)par)->showPage(chld);
      changeSecondTab(chld);
    }
    SecondText=data[prefix+":SecondText"];
  }

  connect(Schema,SIGNAL(activated(int)),
	  this,SLOT(changeSchema(int)));
  connect(TopTab,SIGNAL(currentChanged(QWidget *)),this,SLOT(changeTab(QWidget *)));
  refresh();
}

void toBrowser::fixIndexCols(void)
{
  if (toIsOracle(connection())) {
    toResultLong *tmp=dynamic_cast<toResultLong *>(SecondMap[TAB_INDEX_COLS]);
    if (tmp)
      for(QListViewItem *item=tmp->firstChild();item;item=item->nextSibling()) {
	if (!toUnnull(item->text(4)).isNull()) {
	  toResultViewItem *resItem=dynamic_cast<toResultViewItem *>(item);
	  if (resItem)
	    resItem->setText(1,resItem->allText(4));
	}
      }
  } else if (toIsMySQL(connection())) {
    toResultLong *second=dynamic_cast<toResultLong *>(SecondMap[TAB_INDEX_COLS]);
    if (FirstTab&&second) {
      QListViewItem *item=selectedItem();
      if (item) {
	QString index=item->text(1);
	for(QListViewItem *item=second->firstChild();item;) {
	  QListViewItem *t=item->nextSibling();
	  if (item->text(2)!=index) {
	    delete item;
	    second->clearParams(); // Make sure it is reexecuted even if same table.
	  }
	  item=t;
	}
      }
    }
  }
}

static toBrowseTemplate BrowseTemplate;

void toBrowseTemplate::removeDatabase(const QString &name)
{
  for(std::list<toTemplateItem *>::iterator i=Parents.begin();i!=Parents.end();i++) {
    for (QListViewItem *item=(*i)->firstChild();item;item=item->nextSibling())
      if (item->text(0)==name) {
	delete item;
	break;
      }
  }
}

void toBrowseTemplate::defineFilter(void)
{
  if (Filter) {
    toBrowserFilterSetup filt(true,*Filter,toMainWidget());
    if (filt.exec()) {
      delete Filter;
      Filter=filt.getSetting();
    }
  } else {
    toBrowserFilterSetup filt(true,toMainWidget());
    if (filt.exec())
      Filter=filt.getSetting();
  }
  if (Filter) {
    disconnect(FilterButton,SIGNAL(toggled(bool)),this,SLOT(defineFilter()));
    FilterButton->setOn(true);
    connect(FilterButton,SIGNAL(toggled(bool)),this,SLOT(defineFilter()));
  }
}

void toBrowseTemplate::clearFilter(void)
{
  delete Filter;
  Filter=new toBrowserFilter;
  disconnect(FilterButton,SIGNAL(toggled(bool)),this,SLOT(defineFilter()));
  FilterButton->setOn(false);
  connect(FilterButton,SIGNAL(toggled(bool)),this,SLOT(defineFilter()));
}

void toBrowseTemplate::removeItem(QListViewItem *item)
{
  for(std::list<toTemplateItem *>::iterator i=Parents.begin();i!=Parents.end();i++)
    if ((*i)==item) {
      Parents.erase(i);
      break;
    }
}

class toTemplateTableItem : public toTemplateItem {
  toConnection &Connection;
public:
  toTemplateTableItem(toConnection &conn,toTemplateItem *parent,
		       const QString &name)
    : toTemplateItem(parent,name),Connection(conn)
  {
  }
  virtual QWidget *selectedWidget(QWidget *par)
  {
    QString ptyp=parent()->parent()->text(0);
    QString object=parent()->text(0);
    QString typ=text(0);
    QString schema=parent()->parent()->parent()->text(0);
    if (ptyp=="Synonyms") {
      int pos=object.find(QString::fromLatin1("."));
      if (pos>=0) {
	schema=object.mid(0,pos);
	object=object.mid(pos+1);
      } else {
	schema=QString::fromLatin1("PUBLIC");
      }
    }

    if (schema==qApp->translate("toBrowser","No schemas"))
      schema=Connection.database();

    toResultView *res;

    toToolWidget *tool=new toToolWidget(BrowserTool,
					"",
					par,
					Connection);
    if (typ==qApp->translate("toBrowser","Data")) {
      toResultContent *cnt=new toResultContent(tool);
      cnt->changeParams(schema,object);
      return tool;
    } else if (typ==qApp->translate("toBrowser","Indexes")) {
      res=new toResultIndexes(tool);
    } else if (typ==qApp->translate("toBrowser","Extents")) {
      new toResultExtent(tool);
      return tool;
    } else if (typ==qApp->translate("toBrowser","Constraints")) {
      res=new toResultConstraint(tool);
    } else if (typ==qApp->translate("toBrowser","Triggers")) {
      res=new toResultLong(true,false,toQuery::Background,tool);
      res->setReadAll(true);
      res->setSQL(SQLTableTrigger);
    } else if (typ==qApp->translate("toBrowser","SQL")) {
      toResultField *sql=new toResultField(tool);
      sql->setSQL(SQLViewSQL);
      sql->changeParams(schema,object);
      return tool;
    } else if (typ==qApp->translate("toBrowser","Script")) {
      toResultExtract *ext=new toResultExtract(true,tool);
      ext->changeParams(schema,object);
      return tool;
    } else if (typ==qApp->translate("toBrowser","Information")) {
      toResultItem *inf=new toResultItem(2,true,tool);
      if (ptyp==qApp->translate("toBrowser","Tables")) {
	inf->setSQL(SQLTableInfo);
      } else if (ptyp==qApp->translate("toBrowser","Triggers")) {
	inf->setSQL(SQLTriggerInfo);
      } else if (ptyp==qApp->translate("toBrowser","Indexes")) {
	inf->setSQL(SQLIndexInfo);
      }
      inf->changeParams(schema,object);
      return tool;
    } else if (typ==qApp->translate("toBrowser","Columns")) {
      res=new toResultLong(true,false,toQuery::Background,tool);
      res->setSQL(SQLTriggerCols);
    } else if (typ==qApp->translate("toBrowser","References")) {
      res=new toResultReferences(tool);
    } else if (typ==qApp->translate("toBrowser","Grants")) {
      res=new toResultLong(true,false,toQuery::Background,tool);
      res->setSQL(SQLAnyGrants);
    } else if (typ==qApp->translate("toBrowser","Dependencies")) {
      res=new toResultDepend(tool);
    } else {
      delete tool;
      return NULL;
    }
    res->changeParams(schema,object);
    return tool;
  }
};

class toTemplateSchemaItem : public toTemplateItem {
  toConnection &Connection;
public:
  toTemplateSchemaItem(toConnection &conn,toTemplateItem *parent,
		       const QString &name)
    : toTemplateItem(parent,name),Connection(conn)
  {
    QString typ=parent->text(0);
    if (typ==qApp->translate("toBrowser","Tables")) {
      QPixmap image((const char **)table_xpm);
      setPixmap(0,image);
      new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Indexes"));
      if (toIsOracle(conn)) {
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Constraints"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","References"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Grants"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Triggers"));
      }
      new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Data"));
      new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Information"));
      if (toIsOracle(conn)) {
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Extents"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Script"));
      }
    } else if (typ==qApp->translate("toBrowser","Views")) {
      QPixmap image((const char **)view_xpm);
      setPixmap(0,image);
      if (toIsOracle(conn)) {
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","SQL"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Grants"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Data"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Dependencies"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Script"));
      }
    } else if (typ==qApp->translate("toBrowser","Sequences")) {
      QPixmap image((const char **)sequence_xpm);
      setPixmap(0,image);
      if (toIsOracle(conn)) {
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Grants"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Script"));
      }
    } else if (typ==qApp->translate("toBrowser","Code")) {
      QPixmap image((const char **)function_xpm);
      setPixmap(0,image);
      if (toIsOracle(conn)) {
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Grants"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Dependencies"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Script"));
      }
    } else if (typ==qApp->translate("toBrowser","Triggers")) {
      QPixmap image((const char **)function_xpm);
      setPixmap(0,image);
      if (toIsOracle(conn)) {
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Information"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Columns"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Grants"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Dependencies"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Script"));
      }
    } else if (typ==qApp->translate("toBrowser","Indexes")) {
      QPixmap image((const char **)index_xpm);
      setPixmap(0,image);
      if (toIsOracle(conn) || toIsSapDB(conn)) {
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Information"));
      }
      if (toIsOracle(conn)) {
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Information"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Extents"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Script"));
      }
    } else if (typ==qApp->translate("toBrowser","Synonyms")) {
      QPixmap image((const char **)synonym_xpm);
      setPixmap(0,image);
      if (toIsOracle(conn)) {
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Grants"));
	new toTemplateTableItem(conn,this,qApp->translate("toBrowser","Script"));
      }
    }
  }

  virtual QString allText(int col) const
  {
    QString txt=parent()->parent()->text(0);
    txt+=QString::fromLatin1(".");
    txt+=text(col);
    return txt;
  }

  virtual QWidget *selectedWidget(QWidget *par)
  {
    QString object=text(0);
    QString typ=parent()->text(0);
    QString schema=parent()->parent()->text(0);
    if (schema==qApp->translate("toBrowser","No schemas"))
      schema=Connection.database();

    toToolWidget *tool=new toToolWidget(BrowserTool,
					"",
					par,
					Connection);
    if (typ==qApp->translate("toBrowser","Code")||typ==qApp->translate("toBrowser","Triggers")) {
      toResultField *fld=new toResultField(tool);
      if(typ==qApp->translate("toBrowser","Code"))
	fld->setSQL(SQLSQLTemplate);
      else
	fld->setSQL(SQLTriggerBody);
      fld->changeParams(schema,object);
      return tool;
    } else if (typ==qApp->translate("toBrowser","Tables")||typ==qApp->translate("toBrowser","Views")) {
      toResultCols *cols=new toResultCols(tool);
      cols->changeParams(schema,object);
      return tool;
    } else if (typ==qApp->translate("toBrowser","Indexes")) {
      toResultView *resultView=new toResultLong(true,false,toQuery::Background,tool);
      resultView->setSQL(SQLIndexCols);
      resultView->changeParams(schema,object);
      return tool;
    } else if (typ==qApp->translate("toBrowser","Synonyms")||typ==qApp->translate("toBrowser","Sequences")) {
      toResultItem *resultItem=new toResultItem(2,true,tool);
      if (typ==qApp->translate("toBrowser","Synonyms")) {
	resultItem->setSQL(SQLSynonymInfo);
	int pos=object.find(QString::fromLatin1("."));
	if (pos>=0) {
	  schema=object.mid(0,pos);
	  object=object.mid(pos+1);
	} else {
	  schema=QString::fromLatin1("PUBLIC");
	}
      } else
	resultItem->setSQL(SQLSequenceInfo);
      resultItem->changeParams(schema,object);
      return tool;
    } else {
      delete tool;
      return NULL;
    }
  }
};

class toTemplateSchemaList : public toTemplateSQL {
public:
  toTemplateSchemaList(toConnection &conn,toTemplateItem *parent,
		       const QString &name,const QString &sql)
    : toTemplateSQL(conn,parent,name,sql)
  { }
  virtual toTemplateItem *createChild(const QString &name)
  {
    try {
      toBrowserFilter *filter=BrowseTemplate.filter();
      toTemplateItem *item=new toTemplateSchemaItem(connection(),this,name);
      if (filter&&!filter->check(item)) {
	delete item;
	return NULL;
      }
      return item;
    } catch(...) {
      return NULL;
    }
  }
  virtual toQList parameters(void)
  {
    toQList ret;
    ret.insert(ret.end(),parent()->text(0));
    toBrowserFilter *filter=BrowseTemplate.filter();
    if (filter)
      ret.insert(ret.end(),filter->wildCard());
    else
      ret.insert(ret.end(),toQValue(QString::fromLatin1("%")));
    return ret;
  }
};

class toTemplateDBItem : public toTemplateSQL {
public:
  toTemplateDBItem(toConnection &conn,toTemplateItem *parent,
		   const QString &name)
    : toTemplateSQL(conn,parent,name,toSQL::string(toSQL::TOSQL_USERLIST,conn))
  {
  }
  virtual ~toTemplateDBItem()
  {
    toBrowseTemplate *prov=dynamic_cast<toBrowseTemplate *>(&provider());
    if (prov)
      prov->removeItem(this);
  }
  virtual toTemplateItem *createChild(const QString &name)
  {
    try {
      toTemplateItem *item=new toTemplateItem(this,name);
      QPixmap image((const char **)schema_xpm);
      item->setPixmap(0,image);
      QPixmap table((const char **)table_xpm);
      QPixmap view((const char **)view_xpm);
      QPixmap sequence((const char **)sequence_xpm);
      QPixmap function((const char **)function_xpm);
      QPixmap index((const char **)index_xpm);
      QPixmap synonym((const char **)synonym_xpm);

      toBrowserFilter *filter=BrowseTemplate.filter();
      if (filter&&filter->onlyOwnSchema()&&
	  name.upper()!=connection().user().upper()) {
	delete item;
	return NULL;
      }

      (new toTemplateSchemaList(connection(),
				item,
				qApp->translate("toBrowser","Tables"),
				toSQL::string(SQLListTables,connection())))->setPixmap(0,table);

      if (toIsOracle(connection()) || toIsSapDB(connection())) {
	(new toTemplateSchemaList(connection(),
				  item,
				  qApp->translate("toBrowser","Views"),
				  toSQL::string(SQLListView,connection())))->setPixmap(0,view);
	(new toTemplateSchemaList(connection(),
				  item,
				  qApp->translate("toBrowser","Indexes"),
				  toSQL::string(SQLListIndex,connection())))->setPixmap(0,index);
      }

      if (toIsOracle(connection())) {
	(new toTemplateSchemaList(connection(),
				  item,
				  qApp->translate("toBrowser","Sequences"),
				  toSQL::string(SQLListSequence,connection())))->setPixmap(0,sequence);
	(new toTemplateSchemaList(connection(),
				  item,
				  qApp->translate("toBrowser","Synonyms"),
				  toSQL::string(SQLListSynonym,connection())))->setPixmap(0,synonym);
	(new toTemplateSchemaList(connection(),
				  item,
				  qApp->translate("toBrowser","Code"),
				  toSQL::string(SQLListSQLShort,connection())))->setPixmap(0,function);
	(new toTemplateSchemaList(connection(),
				  item,
				  qApp->translate("toBrowser","Triggers"),
				  toSQL::string(SQLListTrigger,connection())))->setPixmap(0,function);
      }
      return item;
    } catch(...) {
      return NULL;
    }
  }
};

class toBrowseTemplateItem : public toTemplateItem {
public:
  toBrowseTemplateItem(toTemplateProvider &prov,QListView *parent,const QString &name)
    : toTemplateItem(prov,parent,name)
  { }
  virtual ~toBrowseTemplateItem()
  {
    dynamic_cast<toBrowseTemplate &>(provider()).removeItem(this);
  }
};

void toBrowseTemplate::insertItems(QListView *parent,QToolBar *toolbar)
{
  if (!Registered) {
    connect(toMainWidget(),SIGNAL(addedConnection(const QString &)),
	    this,SLOT(addDatabase(const QString &)));
    connect(toMainWidget(),SIGNAL(removedConnection(const QString &)),
	    this,SLOT(removeDatabase(const QString &)));
  }
  toTemplateItem *dbitem=new toBrowseTemplateItem(*this,parent,qApp->translate("toBrowser","DB Browser"));
  std::list<QString> conn=toMainWidget()->connections();
  for (std::list<QString>::iterator i=conn.begin();i!=conn.end();i++) {
    toConnection &conn=toMainWidget()->connection(*i);
    new toTemplateDBItem(conn,dbitem,*i);
  }
  Parents.insert(Parents.end(),dbitem);

  FilterButton=new QToolButton(toolbar);
  FilterButton->setToggleButton(true);
  FilterButton->setIconSet(QIconSet(QPixmap((const char **)filter_xpm)));
  QToolTip::add(FilterButton,tr("Define the object filter for database browser"));
  connect(FilterButton,SIGNAL(toggled(bool)),this,SLOT(defineFilter()));

  new QToolButton(QPixmap((const char **)nofilter_xpm),
		  qApp->translate("toBrowser","Remove any object filter for database browser"),
		  qApp->translate("toBrowser","Remove any object filter for database browser"),
		  this,SLOT(clearFilter(void)),
		  toolbar);
}

void toBrowseTemplate::addDatabase(const QString &name)
{
  try {
    for(std::list<toTemplateItem *>::iterator i=Parents.begin();i!=Parents.end();i++)
      new toTemplateDBItem(toMainWidget()->connection(name),*i,name);
  } TOCATCH
}

void toBrowseTemplate::importData(std::map<QCString,QString> &data,const QCString &prefix)
{
  if (data.find(prefix+":Filter:Type")!=data.end()) {
    Filter=new toBrowserFilter;
    Filter->importData(data,prefix+":Filter");
  }
}

void toBrowseTemplate::exportData(std::map<QCString,QString> &data,const QCString &prefix)
{
  if (Filter)
    Filter->exportData(data,prefix+":Filter");
}

void toBrowser::enableDisableConstraints(const QString &what)
{
  try {
    if (SecondTab) {
      toResultView *lst=dynamic_cast<toResultConstraint *>(SecondTab);
      toConnection &conn=connection();
      std::list<QString> migrate;
      if (lst) {
	for(QListViewItem *item=lst->firstChild();item;item=item->nextSibling()) {
	  if (item->isSelected()) {
	    toResultViewItem *res=dynamic_cast<toResultViewItem *>(item);
	    if (res) {
	      toPush(migrate,
		     conn.quote(schema())+":"+
		     "TABLE:"+
		     conn.quote(SecondText)+":"+
		     "CONSTRAINT:"+
		     conn.quote(res->allText(0))+":"+
		     "DEFINITION:"+
		     what);
	    }
	  }
	}
      } else {
	lst=dynamic_cast<toResultReferences *>(SecondTab);
	if (lst) {
	  for(QListViewItem *item=lst->firstChild();item;item=item->nextSibling()) {
	    if (item->isSelected()) {
	      toResultViewItem *res=dynamic_cast<toResultViewItem *>(item);
	      if (res) {
		toPush(migrate,
		       conn.quote(res->allText(0))+":"+
		       "TABLE:"+
		       conn.quote(res->allText(1))+":"+
		       "CONSTRAINT:"+
		       conn.quote(res->allText(2))+":"+
		       "DEFINITION:"+
		       what);
	      }
	    }
	  }
	} else {
	  lst=dynamic_cast<toResultView *>(SecondTab);
	  if (lst&&lst->sqlName()=="toBrowser:TableTrigger") {
	    // Need work
	  }
	}
      }
      if (migrate.begin()!=migrate.end()) {
	std::list<QString> drop;
	toExtract extract(conn,this);
	extract.setPrompt(false);
	extract.setHeading(false);
	QString sql=extract.migrate(drop,migrate);
	conn.execute("BEGIN\n"+sql+"\nEND;");
      }
    }
  } TOCATCH
}

void toBrowser::enableConstraints(void)
{
  enableDisableConstraints("ENABLE");
}

void toBrowser::disableConstraints(void)
{
  enableDisableConstraints("DISABLE");
}

void toBrowser::testDBLink(void)
{
  if(SecondText.isEmpty()) return;
  toQList resultset;
  try {
    resultset=toQuery::readQueryNull(toCurrentConnection(this),
				     "SELECT * FROM dual@"+SecondText);
  } TOCATCH;
//   } catch (...) {
//     TOMessageBox::information(this, "Database link", SecondText);
//   }
  if(!resultset.empty())
    TOMessageBox::information(this, "Database link", SecondText);
}