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
|
/***************************************************************************
* tdemainwidget.cpp
* -------------------
*
* begin : Tue Jan 29 2002
* copyright : (C) 2002 by Patrick Charbonnier
* : Based On Caitoo v.0.7.3 (c) 1998 - 2000, Matej Koss
* email : pch@freeshell.org
* Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org>
*
****************************************************************************/
/***************************************************************************
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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.
*
***************************************************************************/
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef __svr4__
#define map BULLSHIT // on Solaris it conflicts with STL ?
#include <net/if.h>
#undef map
#include <sys/sockio.h> // needed for SIOCGIFFLAGS
#else
#include <net/if.h>
#endif
#include <tqclipboard.h>
#include <tqregexp.h>
#include <tqdragobject.h>
#include <tqwhatsthis.h>
#include <tqtooltip.h>
#include <tqtimer.h>
#include <tqdropsite.h>
#include <tqpopupmenu.h>
#include <tqfileinfo.h>
#include <kinputdialog.h>
#include <kprotocolinfo.h>
#include <tdefiledialog.h>
#include <tdeapplication.h>
#include <kstandarddirs.h>
#include <kiconloader.h>
#include <kurl.h>
#include <kurldrag.h>
#include <tdelocale.h>
#include <tdeglobal.h>
#include <twin.h>
#include <tdemessagebox.h>
#include <kstdaction.h>
#include <khelpmenu.h>
#include <kedittoolbar.h>
#include <kstatusbar.h>
#include <tdeconfig.h>
#include <tdeio/netaccess.h>
#include <knotifyclient.h>
#include <knotifydialog.h>
#include <tdemenubar.h>
#include <tdeio/renamedlg.h>
#include "safedelete.h"
#include "settings.h"
#include "transfer.h"
#include "transferlist.h"
#include "tdemainwidget.h"
#include "tdefileio.h"
#include "dlgPreferences.h"
#include "logwindow.h"
#include "docking.h"
#include "droptarget.h"
#include <assert.h>
#include <tdeio/authinfo.h>
#include <tdeio/global.h>
#include <tqiconset.h>
#include "version.h"
#include "slave.h"
#include "slaveevent.h"
struct KURLPair
{
KURL dest;
KURL src;
};
TDEMainWidget *tdemain = 0L;
#define LOAD_ICON(X) TDEGlobal::iconLoader()->loadIcon(X, TDEIcon::MainToolbar)
DropTarget *kdrop = 0L;
Settings ksettings; // this object contains all settings
static int sockets_open();
// socket constants
int ipx_sock = -1; /* IPX socket */
int ax25_sock = -1; /* AX.25 socket */
int inet_sock = -1; /* INET socket */
int ddp_sock = -1; /* Appletalk DDP socket */
TDEMainWidget::TDEMainWidget(bool bStartDocked)
: KGetIface( "KGet-Interface" ),
TDEMainWindow(0, "kget mainwindow",0),
prefDlg( 0 ), kdock( 0 )
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
{
TDEConfig cfg( "tdeioslaverc", false, false);
cfg.setGroup(TQString());
cfg.writeEntry("AutoResume", true);
cfg.sync();
}
b_connected = TRUE;
b_viewLogWindow = FALSE;
b_viewPreferences = FALSE;
myTransferList = 0L;
tdemain = this;
// Set log time, needed for the name of log file
TQDate date = TQDateTime::currentDateTime().date();
TQTime time = TQDateTime::currentDateTime().time();
TQString tmp;
tmp.sprintf("log%d:%d:%d-%d:%d:%d", date.day(), date.month(), date.year(), time.hour(), time.minute(), time.second());
logFileName = locateLocal("appdata", "logs/");
logFileName += tmp;
lastClipboard = TQApplication::clipboard()->text( TQClipboard::Clipboard ).stripWhiteSpace();
// Load all settings from TDEConfig
ksettings.load();
// Setup log window
logWindow = new LogWindow();
m_showDropTarget = false;
setCaption(KGETVERSION);
setupGUI();
setupWhatsThis();
log(i18n("Welcome to KGet"));
setCentralWidget(myTransferList);
connect(kapp, TQ_SIGNAL(saveYourself()), TQ_SLOT(slotSaveYourself()));
// Enable dropping
setAcceptDrops(true);
// Setup connection timer
connectionTimer = new TQTimer(this);
connect(connectionTimer, TQ_SIGNAL(timeout()), TQ_SLOT(slotCheckConnection()));
// setup socket for checking connection
if ((_sock = sockets_open()) < 0) {
log(i18n("Could not create valid socket"), false);
} else {
connectionTimer->start(5000); // 5 second interval for checking connection
}
checkOnline();
ksettings.b_offline=( !b_connected || ksettings.b_offlineMode );
// Setup animation timer
animTimer = new TQTimer(this);
animCounter = 0;
connect(animTimer, TQ_SIGNAL(timeout()), TQ_SLOT(slotAnimTimeout()));
if (ksettings.b_useAnimation) {
animTimer->start(400);
} else {
animTimer->start(1000);
}
// Setup transfer timer for scheduled downloads and checkQueue()
transferTimer = new TQTimer(this);
connect(transferTimer, TQ_SIGNAL(timeout()), TQ_SLOT(slotTransferTimeout()));
transferTimer->start(10000); // 10 secs time interval
// Setup autosave timer
autosaveTimer = new TQTimer(this);
connect(autosaveTimer, TQ_SIGNAL(timeout()), TQ_SLOT(slotAutosaveTimeout()));
setAutoSave();
// Setup clipboard timer
clipboardTimer = new TQTimer(this);
connect(clipboardTimer, TQ_SIGNAL(timeout()), TQ_SLOT(slotCheckClipboard()));
if (ksettings.b_autoPaste) {
clipboardTimer->start(1000);
}
readTransfers();
// Setup special windows
kdrop = new DropTarget(this);
kdock = new DockWidget(this);
connect(kdock, TQ_SIGNAL(quitSelected()), TQ_SLOT(slotQuit()));
// Set geometry
if (ksettings.mainPosition.x() != -1) {
resize(ksettings.mainSize);
move(ksettings.mainPosition);
KWin::setState(winId(), ksettings.mainState);
} else {
resize(650, 180);
}
// update actions
m_paUseAnimation->setChecked(ksettings.b_useAnimation);
m_paExpertMode->setChecked(ksettings.b_expertMode);
m_paUseLastDir->setChecked(ksettings.b_useLastDir);
if (ksettings.connectionType != PERMANENT) {
m_paAutoDisconnect->setChecked(ksettings.b_autoDisconnect);
}
setAutoDisconnect();
m_paAutoShutdown->setChecked(ksettings.b_autoShutdown);
m_paOfflineMode->setChecked(ksettings.b_offline);
if (!ksettings.b_offlineMode)
m_paOfflineMode->setIconSet(LOAD_ICON("tool_offline_mode_on"));
if (ksettings.b_offline) {
setCaption(i18n("Offline"), false);
log(i18n("Starting offline"));
} else
setCaption(TQString(), false);
m_paAutoPaste->setChecked(ksettings.b_autoPaste);
m_paShowLog->setChecked(b_viewLogWindow);
if (!bStartDocked && ksettings.b_showMain)
show();
kdock->show();
KNotifyClient::startDaemon();
setStandardToolBarMenuEnabled(true);
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
TDEMainWidget::~TDEMainWidget()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
delete prefDlg;
delete kdrop;
writeTransfers();
writeLog();
#ifdef _DEBUG
sDebugOut << endl;
#endif
delete logWindow;
}
void TDEMainWidget::log(const TQString & message, bool statusbar)
{
#ifdef _DEBUG
sDebugIn <<" message= "<< message << endl;
#endif
logWindow->logGeneral(message);
if (statusbar) {
statusBar()->message(message, 1000);
}
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotSaveYourself()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
writeTransfers();
ksettings.save();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::setupGUI()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
// setup transfer list
myTransferList = new TransferList(this, "transferList");
myTransferList->setSorting(-1);
setListFont();
TDEActionCollection *coll = actionCollection();
connect(myTransferList, TQ_SIGNAL(selectionChanged()), this, TQ_SLOT(slotUpdateActions()));
connect(myTransferList, TQ_SIGNAL(transferSelected(Transfer *)), this, TQ_SLOT(slotOpenIndividual()));
connect(myTransferList, TQ_SIGNAL(popupMenu(Transfer *)), this, TQ_SLOT(slotPopupMenu(Transfer *)));
// file actions
m_paOpenTransfer = KStdAction::open(this, TQ_SLOT(slotOpenTransfer()), coll, "open_transfer");
m_paPasteTransfer = KStdAction::paste(this, TQ_SLOT(slotPasteTransfer()), coll, "paste_transfer");
m_paExportTransfers = new TDEAction(i18n("&Export Transfer List..."), 0, this, TQ_SLOT(slotExportTransfers()), coll, "export_transfers");
m_paImportTransfers = new TDEAction(i18n("&Import Transfer List..."), 0, this, TQ_SLOT(slotImportTransfers()), coll, "import_transfers");
m_paImportText = new TDEAction(i18n("Import Text &File..."), 0, this, TQ_SLOT(slotImportTextFile()), coll, "import_text");
m_paQuit = KStdAction::quit(this, TQ_SLOT(slotQuit()), coll, "quit");
// transfer actions
m_paCopy = new TDEAction(i18n("&Copy URL to Clipboard"), 0, this, TQ_SLOT(slotCopyToClipboard()), coll, "copy_url");
m_paIndividual = new TDEAction(i18n("&Open Individual Window"), 0, this, TQ_SLOT(slotOpenIndividual()), coll, "open_individual");
m_paMoveToBegin = new TDEAction(i18n("Move to &Beginning"), 0, this, TQ_SLOT(slotMoveToBegin()), coll, "move_begin");
m_paMoveToEnd = new TDEAction(i18n("Move to &End"), 0, this, TQ_SLOT(slotMoveToEnd()), coll, "move_end");
#ifdef _DEBUG
sDebug << "Loading pics" << endl;
#endif
m_paResume = new TDEAction(i18n("&Resume"),"tool_resume", 0, this, TQ_SLOT(slotResumeCurrent()), coll, "resume");
m_paPause = new TDEAction(i18n("&Pause"),"tool_pause", 0, this, TQ_SLOT(slotPauseCurrent()), coll, "pause");
m_paDelete = new TDEAction(i18n("&Delete"),"edit-delete", TQt::Key_Delete, this, TQ_SLOT(slotDeleteCurrent()), coll, "delete");
m_paRestart = new TDEAction(i18n("Re&start"),"tool_restart", 0, this, TQ_SLOT(slotRestartCurrent()), coll, "restart");
m_paQueue = new TDERadioAction(i18n("&Queue"),"tool_queue", 0, this, TQ_SLOT(slotQueueCurrent()), coll, "queue");
m_paTimer = new TDERadioAction(i18n("&Timer"),"tool_timer", 0, this, TQ_SLOT(slotTimerCurrent()), coll, "timer");
m_paDelay = new TDERadioAction(i18n("De&lay"),"tool_delay", 0, this, TQ_SLOT(slotDelayCurrent()), coll, "delay");
m_paQueue->setExclusiveGroup("TransferMode");
m_paTimer->setExclusiveGroup("TransferMode");
m_paDelay->setExclusiveGroup("TransferMode");
// options actions
m_paUseAnimation = new TDEToggleAction(i18n("Use &Animation"), 0, this, TQ_SLOT(slotToggleAnimation()), coll, "toggle_animation");
m_paExpertMode = new TDEToggleAction(i18n("&Expert Mode"),"tool_expert", 0, this, TQ_SLOT(slotToggleExpertMode()), coll, "expert_mode");
m_paUseLastDir = new TDEToggleAction(i18n("&Use-Last-Folder Mode"),"tool_uselastdir", 0, this, TQ_SLOT(slotToggleUseLastDir()), coll, "use_last_dir");
m_paAutoDisconnect = new TDEToggleAction(i18n("Auto-&Disconnect Mode"),"tool_disconnect", 0, this, TQ_SLOT(slotToggleAutoDisconnect()), coll, "auto_disconnect");
m_paAutoShutdown = new TDEToggleAction(i18n("Auto-S&hutdown Mode"), "tool_shutdown", 0, this, TQ_SLOT(slotToggleAutoShutdown()), coll, "auto_shutdown");
m_paOfflineMode = new TDEToggleAction(i18n("&Offline Mode"),"tool_offline_mode_off", 0, this, TQ_SLOT(slotToggleOfflineMode()), coll, "offline_mode");
m_paAutoPaste = new TDEToggleAction(i18n("Auto-Pas&te Mode"),"tool_clipboard", 0, this, TQ_SLOT(slotToggleAutoPaste()), coll, "auto_paste");
m_paPreferences = KStdAction::preferences(this, TQ_SLOT(slotPreferences()), coll);
KStdAction::keyBindings(guiFactory(), TQ_SLOT(configureShortcuts()), coll);
KStdAction::configureToolbars(this, TQ_SLOT(slotConfigureToolbars()), coll);
KStdAction::configureNotifications(this, TQ_SLOT(slotConfigureNotifications()), coll);
m_menubarAction = KStdAction::showMenubar(this, TQ_SLOT(slotShowMenubar()), coll, "settings_showmenubar" );
m_menubarAction->setChecked( !menuBar()->isHidden() );
// view actions
createStandardStatusBarAction();
m_paShowLog = new TDEToggleAction(i18n("Show &Log Window"),"tool_logwindow", 0, this, TQ_SLOT(slotToggleLogWindow()), coll, "toggle_log");
m_paShowLog->setCheckedState(i18n("Hide &Log Window"));
m_paDropTarget = new TDEAction(i18n("Show Drop &Target"),"tool_drop_target", 0, this, TQ_SLOT(slotToggleDropTarget()), coll, "drop_target");
m_paKonquerorIntegration = new TDEAction(i18n("Enable &KGet as Konqueror Download Manager"), "konqueror", 0, this, TQ_SLOT(slotKonquerorIntegration()), coll, "konqueror_integration");
if (ksettings.b_KonquerorIntegration) {
m_paKonquerorIntegration->setText(i18n("Disable &KGet as Konqueror Download Manager"));
}
menuHelp = new KHelpMenu(this, TDEGlobal::instance()->aboutData());
KStdAction::whatsThis(menuHelp, TQ_SLOT(contextHelpActivated()), coll, "whats_this");
createGUI("kgetui.rc");
// setup statusbar
statusBar()->insertFixedItem(i18n(" Transfers: %1 ").arg(99), ID_TOTAL_TRANSFERS);
statusBar()->insertFixedItem(i18n(" Files: %1 ").arg(555), ID_TOTAL_FILES);
statusBar()->insertFixedItem(i18n(" Size: %1 KB ").arg("134.56"), ID_TOTAL_SIZE);
statusBar()->insertFixedItem(i18n(" Time: %1 ").arg(TDEIO::convertSeconds(0)), ID_TOTAL_TIME);
statusBar()->insertFixedItem(i18n(" %1 KB/s ").arg("123.34"), ID_TOTAL_SPEED);
setAutoSaveSettings( "MainWindow", false /*Settings takes care of size & pos & state */ );
slotUpdateActions();
updateStatusBar();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::setupWhatsThis()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
TQString tmp;
tmp = i18n("<b>Resume</b> button starts selected transfers\n" "and sets their mode to <i>queued</i>.");
m_paResume->setWhatsThis(tmp);
tmp = i18n("<b>Pause</b> button stops selected transfers\n" "and sets their mode to <i>delayed</i>.");
m_paPause->setWhatsThis(tmp);
tmp = i18n("<b>Delete</b> button removes selected transfers\n" "from the list.");
m_paDelete->setWhatsThis(tmp);
tmp = i18n("<b>Restart</b> button is a convenience button\n" "that simply does Pause and Resume.");
m_paRestart->setWhatsThis(tmp);
tmp = i18n("<b>Queued</b> button sets the mode of selected\n" "transfers to <i>queued</i>.\n" "\n" "It is a radio button -- you can choose between\n" "three modes.");
m_paQueue->setWhatsThis(tmp);
tmp = i18n("<b>Scheduled</b> button sets the mode of selected\n" "transfers to <i>scheduled</i>.\n" "\n" "It is a radio button -- you can choose between\n" "three modes.");
m_paTimer->setWhatsThis(tmp);
tmp = i18n("<b>Delayed</b> button sets the mode of selected\n" "transfers to <i>delayed</i>." "This also causes the selected transfers to stop.\n" "\n" "It is a radio button -- you can choose between\n" "three modes.");
m_paDelay->setWhatsThis(tmp);
tmp = i18n("<b>Preferences</b> button opens a preferences dialog\n" "where you can set various options.\n" "\n" "Some of these options can be more easily set using the toolbar.");
m_paPreferences->setWhatsThis(tmp);
tmp = i18n("<b>Log window</b> button opens a log window.\n" "The log window records all program events that occur\n" "while KGet is running.");
m_paShowLog->setWhatsThis(tmp);
tmp = i18n("<b>Paste transfer</b> button adds a URL from\n" "the clipboard as a new transfer.\n" "\n" "This way you can easily copy&paste URLs between\n" "applications.");
m_paPasteTransfer->setWhatsThis(tmp);
tmp = i18n("<b>Expert mode</b> button toggles the expert mode\n" "on and off.\n" "\n" "Expert mode is recommended for experienced users.\n" "When set, you will not be \"bothered\" by confirmation\n" "messages.\n" "<b>Important!</b>\n" "Turn it on if you are using auto-disconnect or\n" "auto-shutdown features and you want KGet to disconnect \n" "or shut down without asking.");
m_paExpertMode->setWhatsThis(tmp);
tmp = i18n("<b>Use last folder</b> button toggles the\n" "use-last-folder feature on and off.\n" "\n" "When set, KGet will ignore the folder settings\n" "and put all new added transfers into the folder\n" "where the last transfer was put.");
m_paUseLastDir->setWhatsThis(tmp);
tmp = i18n("<b>Auto disconnect</b> button toggles the auto-disconnect\n" "mode on and off.\n" "\n" "When set, KGet will disconnect automatically\n" "after all queued transfers are finished.\n" "\n" "<b>Important!</b>\n" "Also turn on the expert mode when you want KGet\n" "to disconnect without asking.");
m_paAutoDisconnect->setWhatsThis(tmp);
tmp = i18n("<b>Auto shutdown</b> button toggles the auto-shutdown\n" "mode on and off.\n" "\n" "When set, KGet will quit automatically\n" "after all queued transfers are finished.\n" "<b>Important!</b>\n" "Also turn on the expert mode when you want KGet\n" "to quit without asking.");
m_paAutoShutdown->setWhatsThis(tmp);
tmp = i18n("<b>Offline mode</b> button toggles the offline mode\n" "on and off.\n" "\n" "When set, KGet will act as if it was not connected\n" "to the Internet.\n" "\n" "You can browse offline, while still being able to add\n" "new transfers as queued.");
m_paOfflineMode->setWhatsThis(tmp);
tmp = i18n("<b>Auto paste</b> button toggles the auto-paste mode\n" "on and off.\n" "\n" "When set, KGet will periodically scan the clipboard\n" "for URLs and paste them automatically.");
m_paAutoPaste->setWhatsThis(tmp);
tmp = i18n("<b>Drop target</b> button toggles the window style\n" "between a normal window and a drop target.\n" "\n" "When set, the main window will be hidden and\n" "instead a small shaped window will appear.\n" "\n" "You can show/hide a normal window with a simple click\n" "on a shaped window.");
m_paDropTarget->setWhatsThis(tmp);
/*
tmp = i18n("<b>Dock widget</b> button toggles the window style\n" "between a normal window and a docked widget.\n" "\n" "When set, the main window will be hidden and\n" "instead a docked widget will appear on the panel.\n" "\n" "You can show/hide a normal window by simply clicking\n" "on a docked widget.");
m_paDockWindow->setWhatsThis(tmp);
tmp = i18n("<b>Normal window</b> button sets\n" "\n" "the window style to normal window");
m_paNormal->setWhatsThis(tmp);
*/
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotConfigureToolbars()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
saveMainWindowSettings( TDEGlobal::config(), "MainWindow" );
KEditToolbar edit(factory());
connect(&edit, TQ_SIGNAL( newToolbarConfig() ), this, TQ_SLOT( slotNewToolbarConfig() ));
edit.exec();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotNewToolbarConfig()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
createGUI("kgetui.rc");
applyMainWindowSettings( TDEGlobal::config(), "MainWindow" );
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotImportTextFile()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
TQString tmpFile;
TQString list;
int i, j;
KURL filename = KFileDialog::getOpenURL(ksettings.lastDirectory);
if (!filename.isValid())
return;
if (TDEIO::NetAccess::download(filename, tmpFile, this)) {
list = kFileToString(tmpFile);
TDEIO::NetAccess::removeTempFile(tmpFile);
} else
list = kFileToString(filename.path()); // file not accessible -> give error message
i = 0;
while ((j = list.find('\n', i)) != -1) {
TQString newtransfer = list.mid(i, j - i);
addTransfer(newtransfer);
i = j + 1;
}
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotImportTransfers()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
readTransfers(true);
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::readTransfers(bool ask_for_name)
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
KURL url;
if (ask_for_name)
url = KFileDialog::getOpenURL(ksettings.lastDirectory, i18n("*.kgt|*.kgt\n*|All Files"));
else
url.setPath( locateLocal("appdata", "transfers.kgt") );
readTransfersEx(url);
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::readTransfersEx(const KURL & file)
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
if (!file.isValid()) {
#ifdef _DEBUG
sDebugOut<< " string empty" << endl;
#endif
return;
}
#ifdef _DEBUG
sDebug << "Read from file: " << file << endl;
#endif
myTransferList->readTransfers(file);
checkQueue();
slotTransferTimeout();
myTransferList->clearSelection();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotExportTransfers()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
writeTransfers(true);
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::writeTransfers(bool ask_for_name)
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
TQString str;
TQString txt;
if (ask_for_name)
txt = KFileDialog::getSaveFileName(ksettings.lastDirectory, i18n("*.kgt|*.kgt\n*|All Files"));
else
txt = locateLocal("appdata", "transfers.kgt");
if (txt.isEmpty())
{
#ifdef _DEBUG
sDebugOut<< " because Destination File name isEmpty"<< endl;
#endif
return;
}
if (!txt.endsWith(".kgt"))
txt += ".kgt";
#ifdef _DEBUG
sDebug << "Writing transfers " << txt << endl;
#endif
myTransferList->writeTransfers(txt);
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::writeLog()
{
#ifdef _DEBUG
sDebugIn << "Writing log to file : " << logFileName.ascii() << endl;
#endif
kCStringToFile(logWindow->getText().local8Bit(), logFileName, false, false);
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotQuit()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
Transfer *item;
TransferIterator it(myTransferList);
log(i18n("Quitting..."));
for (; it.current(); ++it) {
item = it.current();
if (item->getStatus() == Transfer::ST_RUNNING && !ksettings.b_expertMode) {
if (KMessageBox::warningContinueCancel(this, i18n("Some transfers are still running.\nAre you sure you want to quit KGet?"), i18n("Warning"), KStdGuiItem::quit()) != KMessageBox::Continue) {
#ifdef _DEBUG
sDebugOut << endl;
#endif
return;
}
break;
}
}
ksettings.save();
#ifdef _DEBUG
sDebugOut << endl;
#endif
kapp->quit();
}
void TDEMainWidget::slotResumeCurrent()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
TransferIterator it(myTransferList);
for (; it.current(); ++it)
if (it.current()->isSelected())
it.current()->slotResume();
slotUpdateActions();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotPauseCurrent()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
TransferIterator it(myTransferList);
m_paPause->setEnabled(false);
m_paRestart->setEnabled(false);
update();
for (; it.current(); ++it)
if (it.current()->isSelected())
it.current()->slotRequestPause();
slotUpdateActions();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotRestartCurrent()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
TransferIterator it(myTransferList);
for (; it.current(); ++it)
if (it.current()->isSelected())
it.current()->slotRequestRestart();
slotUpdateActions();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotDeleteCurrent()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
m_paDelete->setEnabled(false);
m_paPause->setEnabled(false);
update();
TransferIterator it(myTransferList);
TQValueList<TQGuardedPtr<Transfer> > selectedItems;
TQStringList itemNames;
while (it.current()) {
if (it.current()->isSelected()) {
selectedItems.append( TQGuardedPtr<Transfer>( it.current() ));
itemNames.append( it.current()->getSrc().prettyURL() );
}
++it;
}
if (!ksettings.b_expertMode)
{
if ( selectedItems.count() > 1 )
{
if (KMessageBox::warningContinueCancelList(this, i18n("Are you sure you want to delete these transfers?"),
itemNames, i18n("Question"),
KStdGuiItem::del(),
TQString("multiple_delete_transfer"))
!= KMessageBox::Continue)
return; // keep 'em
}
else
{
if (KMessageBox::warningContinueCancel(this, i18n("Are you sure you want to delete this transfer?"),
i18n("Question"), KStdGuiItem::del(),
TQString("delete_transfer"))
!= KMessageBox::Continue)
return;
}
}
// If we reach this, we want to delete all selected transfers
// Some of them might have finished in the meantime tho. Good that
// we used a TQGuardedPtr :)
int transferFinishedMeanwhile = 0;
TQValueListConstIterator<TQGuardedPtr<Transfer> > lit = selectedItems.begin();;
while ( lit != selectedItems.end() )
{
if ( *lit )
(*lit)->slotRequestRemove();
else
++transferFinishedMeanwhile;
++lit;
}
checkQueue(); // needed !
if ( !ksettings.b_expertMode && transferFinishedMeanwhile > 0 )
KMessageBox::information(this, i18n("The transfer you wanted to delete completed before it could be deleted.",
"%n transfers you wanted to delete completed before they could be deleted.",
transferFinishedMeanwhile ),
TQString(), "completedBeforeDeletion" );
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::stopAll()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
log(i18n("Stopping all jobs"), false);
TransferIterator it(myTransferList);
Transfer::TransferStatus Status;
for (; it.current(); ++it) {
Status = it.current()->getStatus();
if (Status == Transfer::ST_TRYING || Status == Transfer::ST_RUNNING)
it.current()->slotStop();
}
slotUpdateActions();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotQueueCurrent()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
TransferIterator it(myTransferList);
for (; it.current(); ++it) {
if (it.current()->isSelected()) {
it.current()->slotQueue();
}
}
// myTransferList->clearSelection();
slotUpdateActions();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotTimerCurrent()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
TransferIterator it(myTransferList);
for (; it.current(); ++it)
if (it.current()->isSelected())
it.current()->slotRequestSchedule();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotDelayCurrent()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
TransferIterator it(myTransferList);
for (; it.current(); ++it)
if (it.current()->isSelected())
it.current()->slotRequestDelay();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotOpenTransfer()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
TQString newtransfer;
bool ok = false;
#ifdef _DEBUG
// newtransfer = "ftp://localhost/home/pch/test.gz";
// newtransfer = "http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.18.tar.gz";
newtransfer = "ftp://darkmoon/pub/test.gz";
#endif
while (!ok) {
newtransfer = KInputDialog::getText(i18n("Open Transfer"), i18n("Open transfer:"), newtransfer, &ok, this);
// user presses cancel
if (!ok) {
return;
}
KURL url = KURL::fromPathOrURL(newtransfer);
if (!url.isValid()) {
KMessageBox::error(this, i18n("Malformed URL:\n%1").arg(newtransfer), i18n("Error"));
ok = false;
}
}
addTransfer(newtransfer);
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotCheckClipboard()
{
#ifdef _DEBUG
//sDebugIn << endl;
#endif
TQString clipData = TQApplication::clipboard()->text( TQClipboard::Clipboard ).stripWhiteSpace();
if (clipData != lastClipboard) {
sDebug << "New clipboard event" << endl;
lastClipboard = clipData;
if ( lastClipboard.isEmpty() )
return;
KURL url = KURL::fromPathOrURL( lastClipboard );
if (url.isValid() && !url.isLocalFile())
slotPasteTransfer();
}
#ifdef _DEBUG
//sDebugOut << endl;
#endif
}
void TDEMainWidget::slotPasteTransfer()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
TQString newtransfer;
newtransfer = TQApplication::clipboard()->text();
newtransfer = newtransfer.stripWhiteSpace();
if (!ksettings.b_expertMode) {
bool ok = false;
newtransfer = KInputDialog::getText(i18n("Open Transfer"), i18n("Open transfer:"), newtransfer, &ok, this);
if (!ok) {
// cancelled
#ifdef _DEBUG
sDebugOut << endl;
#endif
return;
}
}
if (!newtransfer.isEmpty())
addTransfer(newtransfer);
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
// destFile must be a filename, not a directory! And it will be deleted, if
// it exists already, without further notice.
void TDEMainWidget::addTransferEx(const KURL& url, const KURL& destFile)
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
if ( !sanityChecksSuccessful( url ) )
return;
KURL destURL = destFile;
// Malformed destination url means one of two things.
// 1) The URL is empty.
// 2) The URL is only a filename, like a default (suggested) filename.
if ( !destURL.isValid() )
{
// Setup destination
TQString destDir = getSaveDirectoryFor( url.fileName() );
bool b_expertMode = ksettings.b_expertMode;
bool bDestisMalformed = true;
while (bDestisMalformed)
{
if (!b_expertMode) {
// open the filedialog for confirmation
KFileDialog dlg( destDir, TQString(),
0L, "save_as", true);
dlg.setCaption(i18n("Save As"));
dlg.setOperationMode(KFileDialog::Saving);
// Use the destination name if not empty...
if (destURL.isEmpty())
dlg.setSelection(url.fileName());
else
dlg.setSelection(destURL.url());
if ( dlg.exec() == TQDialog::Rejected )
{
#ifdef _DEBUG
sDebugOut << endl;
#endif
return;
}
else
{
destURL = dlg.selectedURL();
ksettings.lastDirectory = destURL.directory();
}
}
else {
// in expert mode don't open the filedialog
// if destURL is not empty, it's the suggested filename
destURL = KURL::fromPathOrURL( destDir + "/" +
( destURL.isEmpty() ?
url.fileName() : destURL.url() ));
}
//check if destination already exists
if(TDEIO::NetAccess::exists(destURL, false, this))
{
if (KMessageBox::warningYesNo(this,i18n("Destination file \n%1\nalready exists.\nDo you want to overwrite it?").arg( destURL.prettyURL()), TQString(), i18n("Overwrite"), i18n("Do Not Overwrite") )
== KMessageBox::Yes)
{
bDestisMalformed=false;
SafeDelete::deleteFile( destURL );
}
else
{
b_expertMode=false;
ksettings.lastDirectory = destURL.directory();
}
}
else
bDestisMalformed=false;
}
}
else // destURL was given, check whether the file exists already
{
// simply delete it, the calling process should have asked if you
// really want to delete (at least tdehtml does)
if(TDEIO::NetAccess::exists(destURL, false, this))
SafeDelete::deleteFile( destURL );
}
// create a new transfer item
Transfer *item = myTransferList->addTransfer(url, destURL);
KNotifyClient::event(kdock->winId(), "added", i18n("<i>%1</i> has been added.").arg(url.prettyURL()));
item->updateAll(); // update the remaining fields
if (ksettings.b_showIndividual)
item->showIndividual();
myTransferList->clearSelection();
checkQueue();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::addTransfers( const KURL::List& src, const TQString& destDir )
{
TQValueList<KURLPair> urls_orig;
for ( KURL::List::ConstIterator it = src.begin(); it != src.end(); ++it )
{
KURLPair url;
url.src = *it;
if ( url.src.fileName().endsWith( ".kgt" ) )
readTransfersEx(url.src);
else
urls_orig.append( url );
}
if ( urls_orig.isEmpty() )
return;
if ( urls_orig.count() == 1 ) // just one file -> ask for filename
{
KURL destFile;
if ( !destDir.isEmpty() )
{
// create a proper destination file from destDir
KURL destURL = KURL::fromPathOrURL( destDir );
TQString fileName = urls_orig.first().src.fileName();
// in case the fileName is empty, we simply ask for a filename in
// addTransferEx. Do NOT attempt to use an empty filename, that
// would be a directory (and we don't want to overwrite that!)
if ( !fileName.isEmpty() )
{
destURL.adjustPath( +1 );
destURL.setFileName( fileName );
if(TDEIO::NetAccess::exists(destURL, false, this))
{
if (KMessageBox::warningYesNo(this,i18n("Destination file \n%1\nalready exists.\nDo you want to overwrite it?").arg( destURL.prettyURL()), TQString(), i18n("Overwrite"), i18n("Do Not Overwrite") )
== KMessageBox::Yes)
{
SafeDelete::deleteFile( destURL );
destFile = destURL;
}
}
else
{
destFile = destURL;
}
}
}
addTransferEx( urls_orig.first().src, destFile );
return;
}
// multiple files -> ask for directory, not for every single filename
bool dir_accepted = false;
TQValueList<KURLPair>::Iterator it;
TQValueList<KURLPair> urls;
KURL::List urlsToDelete;
while ( !dir_accepted )
{
urlsToDelete.clear();
urls = urls_orig; // copy the list here, urls might be changed, yet when we return here (Cancel),
// we want to start again with the original list
dir_accepted = true; //Set to false later when Cancel is pressed
KURL dest;
if ( destDir.isEmpty() || !TQFileInfo( destDir ).isDir() )
{
if ( !destDir.isEmpty() )
dest.setPath( destDir );
else
dest.setPath( getSaveDirectoryFor( src.first().fileName() ) );
// ask in any case, when destDir is empty
if ( destDir.isEmpty() || !TQFileInfo( dest.path() ).isDir() )
{
TQString dir = KFileDialog::getExistingDirectory( dest.path() );
if ( dir.isEmpty() ) // aborted
return;
dest.setPath( dir );
ksettings.lastDirectory = dir;
}
}
// dest is now finally the real destination directory for all the files
dest.adjustPath(+1);
// create new transfer items
bool skip_all = false;
bool overwrite_all = false;
it = urls.begin();
TDEIO::RenameDlg_Result result;
while ( it != urls.end() )
{
if ( !sanityChecksSuccessful( (*it).src ) )
{
it = urls.erase( it );
continue; // shouldn't we notify the user??
}
(*it).dest = dest;
TQString fileName = (*it).src.fileName();
if ( fileName.isEmpty() ) // simply use the full url as filename
fileName = KURL::encode_string_no_slash( (*it).src.prettyURL() );
(*it).dest.setFileName( fileName );
if( TDEIO::NetAccess::exists((*it).dest, false, this))
{
TQString newdest;
if (skip_all)
result = TDEIO::R_SKIP;
else if( overwrite_all )
result = TDEIO::R_OVERWRITE;
else
{
TQFileInfo finfo( (*it).dest.path() );
TQString caption = i18n( "File Already exists" ) + " - KGet";
result = TDEIO::open_RenameDlg( caption, (*it).src.url(), (*it).dest.url(), TDEIO::RenameDlg_Mode(TDEIO::M_OVERWRITE|TDEIO::M_SKIP|TDEIO::M_MULTI), newdest, (TDEIO::filesize_t) -1, (TDEIO::filesize_t)finfo.size(), (time_t) -1, (time_t) -1, (time_t) -1, finfo.lastModified().toTime_t());
}
switch (result)
{
case TDEIO::R_RENAME:
(*it).dest = KURL::fromPathOrURL( newdest );
break;
case TDEIO::R_OVERWRITE_ALL:
overwrite_all = true; //fall through
case TDEIO::R_OVERWRITE:
urlsToDelete.append( (*it).dest );
break;
case TDEIO::R_AUTO_SKIP:
skip_all = true;
case TDEIO::R_SKIP: //fall through
it = urls.erase( it );
continue;
break;
default: // Cancel, ask again for directory
dir_accepted = false;
}
if ( !dir_accepted )
break;
} // if(TDEIO::NetAccess::exists
++it;
} // while ( it != urls.end() )
} // while ( !dir_accepted )
KURL::List::Iterator it_1 = urlsToDelete.begin();
for ( ; it_1 != urlsToDelete.end(); ++it_1 )
{
SafeDelete::deleteFile( *it_1 );
}
int numdl = 0;
it = urls.begin();
for ( ; it != urls.end(); ++it )
{
Transfer *item = myTransferList->addTransfer((*it).src, (*it).dest);
item->updateAll(); // update the remaining fields
numdl++;
}
KNotifyClient::event(kdock->winId(), "added", i18n("1 download has been added.", "%n downloads have been added.", numdl));
myTransferList->clearSelection();
checkQueue();
}
void TDEMainWidget::addTransfer(const TQString& src)
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
if ( src.isEmpty() )
return;
addTransferEx( KURL::fromPathOrURL( src ) );
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::checkQueue()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
uint numRun = 0;
int status;
Transfer *item;
TransferIterator it(myTransferList);
if (!ksettings.b_offline) {
// count running transfers
for (; it.current(); ++it) {
status = it.current()->getStatus();
if (status == Transfer::ST_RUNNING || status == Transfer::ST_TRYING)
numRun++;
}
sDebug << "Found " << numRun << " Running Jobs" << endl;
it.reset();
bool isRunning;
bool isQuequed;
for (; it.current() && numRun < ksettings.maxSimultaneousConnections; ++it) {
item = it.current();
isRunning = (item->getStatus() == Transfer::ST_RUNNING) || ((item->getStatus() == Transfer::ST_TRYING));
isQuequed = (item->getMode() == Transfer::MD_QUEUED || item->getMode() == Transfer::MD_NEW);
if (!isRunning && isQuequed && !ksettings.b_offline)
{
log(i18n("Starting another queued job."));
item->slotResume();
numRun++;
}
}
slotUpdateActions();
updateStatusBar();
// } else {//TODO this has to be solved different
// log(i18n("Cannot continue offline status"));
}
it.reset();
for (; it.current(); ++it)
{
item = it.current();
if (item->getMode() == Transfer::MD_NEW && item->getStatus() == Transfer::ST_STOPPED)
{
item->checkCache();
}
}
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotAnimTimeout()
{
#ifdef _DEBUG
//sDebugIn << endl;
#endif
animCounter++;
if (animCounter == myTransferList->getPhasesNum()) {
//updateStatusBar();
animCounter = 0;
}
// update status of all items of transferList
myTransferList->updateStatus(animCounter);
//if (this->isVisible()) {
updateStatusBar();
//}
#ifdef _DEBUG
//sDebugOut << endl;
#endif
}
void TDEMainWidget::slotTransferTimeout()
{
#ifdef _DEBUG
//sDebugIn << endl;
#endif
Transfer *item;
TransferIterator it(myTransferList);
bool flag = false;
for (; it.current(); ++it) {
item = it.current();
if (item->getMode() == Transfer::MD_SCHEDULED && item->getStartTime() <= TQDateTime::currentDateTime()) {
item->setMode(Transfer::MD_QUEUED);
flag = true;
}
}
if (flag) {
checkQueue();
}
if (ksettings.b_autoDisconnect && ksettings.b_timedDisconnect && ksettings.disconnectTime <= TQTime::currentTime() && ksettings.disconnectDate == TQDate::currentDate()) {
onlineDisconnect();
}
#ifdef _DEBUG
//sDebugOut << endl;
#endif
}
void TDEMainWidget::slotAutosaveTimeout()
{
#ifdef _DEBUG
//sDebugIn << endl;
#endif
writeTransfers();
#ifdef _DEBUG
//sDebugOut << endl;
#endif
}
void TDEMainWidget::slotStatusChanged(Transfer * item, int _operation)
{
#ifdef _DEBUG
//sDebugIn << endl;
#endif
switch (_operation) {
case Transfer::OP_FINISHED:
{
TQString srcurl = item->getSrc().prettyURL();
if (ksettings.b_removeOnSuccess && !item->keepDialogOpen() )
{
delete item;
item = 0L;
}
else
item->setMode(Transfer::MD_NONE);
if (!myTransferList->areTransfersQueuedOrScheduled()) {
// no items or only delayed and finished items in the TransferList
if (ksettings.b_autoDisconnect)
onlineDisconnect();
if (ksettings.b_autoShutdown) {
slotQuit();
return;
}
KNotifyClient::event(kdock->winId(), "finishedall", i18n("All the downloads are finished."));
}
else
{
KNotifyClient::event(kdock->winId(), "finished", i18n("<i>%1</i> successfully downloaded.").arg(srcurl));
}
if ( item )
item->slotUpdateActions();
break;
}
case Transfer::OP_RESUMED:
slotUpdateActions();
item->slotUpdateActions();
// play(ksettings.audioStarted);
break;
case Transfer::OP_PAUSED:
break;
case Transfer::OP_REMOVED:
delete item;
return; // checkQueue() will be called only once after all deletions
case Transfer::OP_ABORTED:
break;
case Transfer::OP_DELAYED:
case Transfer::OP_QUEUED:
slotUpdateActions();
item->slotUpdateActions();
break;
case Transfer::OP_SCHEDULED:
slotUpdateActions();
item->slotUpdateActions();
slotTransferTimeout(); // this will check schedule times
return; // checkQueue() is called from slotTransferTimeout()
}
checkQueue();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::dragEnterEvent(TQDragEnterEvent * event)
{
#ifdef _DEBUG
//sDebugIn << endl;
#endif
event->accept(KURLDrag::canDecode(event) || TQTextDrag::canDecode(event));
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::dropEvent(TQDropEvent * event)
{
#ifdef _DEBUG
//sDebugIn << endl;
#endif
KURL::List list;
TQString str;
if (KURLDrag::decode(event, list)) {
addTransfers(list);
} else if (TQTextDrag::decode(event, str)) {
addTransfer(str);
}
sDebugOut << endl;
}
void TDEMainWidget::slotCopyToClipboard()
{
#ifdef _DEBUG
//sDebugIn << endl;
#endif
Transfer *item = (Transfer *) myTransferList->currentItem();
if (item) {
TQString url = item->getSrc().url();
TQClipboard *cb = TQApplication::clipboard();
cb->setText( url, TQClipboard::Selection );
cb->setText( url, TQClipboard::Clipboard);
myTransferList->clearSelection();
}
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotMoveToBegin()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
myTransferList->moveToBegin((Transfer *) myTransferList->currentItem());
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotMoveToEnd()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
myTransferList->moveToEnd((Transfer *) myTransferList->currentItem());
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotOpenIndividual()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
Transfer *item = (Transfer *) myTransferList->currentItem();
if (item)
item->showIndividual();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
bool TDEMainWidget::queryClose()
{
if( kapp->sessionSaving())
return true;
hide();
return false;
}
void TDEMainWidget::setAutoSave()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
autosaveTimer->stop();
if (ksettings.b_autoSave) {
autosaveTimer->start(ksettings.autoSaveInterval * 60000);
}
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::setAutoDisconnect()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
// disable action when we are connected permanently
m_paAutoDisconnect->setEnabled(ksettings.connectionType != PERMANENT);
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotPreferences()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
if ( !prefDlg )
prefDlg = new DlgPreferences(this);
prefDlg->show();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotConfigureNotifications()
{
KNotifyDialog::configure(this);
}
void TDEMainWidget::slotToggleLogWindow()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
b_viewLogWindow = !b_viewLogWindow;
if (b_viewLogWindow)
logWindow->show();
else
logWindow->hide();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotToggleAnimation()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
ksettings.b_useAnimation = !ksettings.b_useAnimation;
if (!ksettings.b_useAnimation && animTimer->isActive()) {
animTimer->stop();
animTimer->start(1000);
animCounter = 0;
} else {
animTimer->stop();
animTimer->start(400);
}
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotToggleOfflineMode()
{
#ifdef _DEBUG
sDebugIn "ksettings.b_offlineMode = " << ksettings.b_offlineMode << endl;
#endif
ksettings.b_offlineMode = !ksettings.b_offlineMode;
ksettings.b_offline=(ksettings.b_offlineMode || !b_connected);
if (ksettings.b_offline) {
log(i18n("Offline mode on."));
stopAll();
setCaption(i18n("Offline"), false);
m_paOfflineMode->setIconSet(LOAD_ICON("tool_offline_mode_off"));
} else {
log(i18n("Offline mode off."));
setCaption(TQString(), false);
m_paOfflineMode->setIconSet(LOAD_ICON("tool_offline_mode_on"));
}
m_paOfflineMode->setChecked(ksettings.b_offline);
slotUpdateActions();
checkQueue();
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotToggleExpertMode()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
ksettings.b_expertMode = !ksettings.b_expertMode;
if (ksettings.b_expertMode) {
log(i18n("Expert mode on."));
} else {
log(i18n("Expert mode off."));
}
m_paExpertMode->setChecked(ksettings.b_expertMode);
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotToggleUseLastDir()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
ksettings.b_useLastDir = !ksettings.b_useLastDir;
if (ksettings.b_useLastDir) {
log(i18n("Use last folder on."));
} else {
log(i18n("Use last folder off."));
}
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotToggleAutoDisconnect()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
ksettings.b_autoDisconnect = !ksettings.b_autoDisconnect;
if (ksettings.b_autoDisconnect) {
log(i18n("Auto disconnect on."));
} else {
log(i18n("Auto disconnect off."));
}
m_paAutoDisconnect->setChecked(ksettings.b_autoDisconnect);
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotToggleAutoShutdown()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
ksettings.b_autoShutdown = !ksettings.b_autoShutdown;
if (ksettings.b_autoShutdown) {
log(i18n("Auto shutdown on."));
} else {
log(i18n("Auto shutdown off."));
}
m_paAutoShutdown->setChecked(ksettings.b_autoShutdown);
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotToggleAutoPaste()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
ksettings.b_autoPaste = !ksettings.b_autoPaste;
if (ksettings.b_autoPaste) {
log(i18n("Auto paste on."));
clipboardTimer->start(1000);
} else {
log(i18n("Auto paste off."));
clipboardTimer->stop();
}
m_paAutoPaste->setChecked(ksettings.b_autoPaste);
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotToggleDropTarget()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
m_showDropTarget = !m_showDropTarget;
if (m_showDropTarget) {
kdrop->show();
kdrop->updateStickyState();
m_paDropTarget->setText(i18n("Hide Drop &Target"));
}
else {
kdrop->hide();
m_paDropTarget->setText(i18n("Show Drop &Target"));
}
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotKonquerorIntegration()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
bool bIsKonquiEnable=!ksettings.b_KonquerorIntegration;
ksettings.b_KonquerorIntegration=!ksettings.b_KonquerorIntegration;
TDEConfig cfg("konquerorrc", false, false);
cfg.setGroup("HTML Settings");
cfg.writePathEntry("DownloadManager",TQString((bIsKonquiEnable)?"kget":""));
cfg.sync();
if (bIsKonquiEnable)
{
m_paKonquerorIntegration->setText(i18n("Disable &KGet as Konqueror Download Manager"));
}
else
{
m_paKonquerorIntegration->setText(i18n("Enable &KGet as Konqueror Download Manager"));
}
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotPopupMenu(Transfer * item)
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
// select current item
myTransferList->setCurrentItem(item);
// set action properties
slotUpdateActions();
// popup transfer menu at the position
TQWidget *menu = guiFactory()->container("transfer",this);
((TQPopupMenu *) menu)->popup(TQCursor::pos());
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::setListFont()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
myTransferList->setFont(ksettings.listViewFont);
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotUpdateActions()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
// disable all signals
m_paQueue->blockSignals(true);
m_paTimer->blockSignals(true);
m_paDelay->blockSignals(true);
// at first turn off all buttons like when nothing is selected
m_paQueue->setChecked(false);
m_paTimer->setChecked(false);
m_paDelay->setChecked(false);
m_paQueue->setEnabled(false);
m_paTimer->setEnabled(false);
m_paDelay->setEnabled(false);
m_paDelete->setEnabled(false);
m_paResume->setEnabled(false);
m_paPause->setEnabled(false);
m_paRestart->setEnabled(false);
m_paCopy->setEnabled(false);
m_paIndividual->setEnabled(false);
m_paMoveToBegin->setEnabled(false);
m_paMoveToEnd->setEnabled(false);
Transfer *item;
Transfer *first_item = 0L;
TransferIterator it(myTransferList);
int index = 0;
int totals_items = 0;
int sel_items = 0;
for (; it.current(); ++it, ++totals_items) {
// update action on visibles windows
if (it.current()->isVisible())
it.current()->slotUpdateActions();
if (it.current()->isSelected()) {
item = it.current();
sel_items = totals_items;
index++; // counting number of selected items
if (index == 1) {
first_item = item; // store first selected item
if (totals_items > 0)
m_paMoveToBegin->setEnabled(true);
m_paMoveToEnd->setEnabled(true);
} else {
m_paMoveToBegin->setEnabled(false);
m_paMoveToEnd->setEnabled(false);
}
// enable PAUSE, RESUME and RESTART only when we are online and not in offline mode
#ifdef _DEBUG
sDebug << "-->ONLINE= " << ksettings.b_offline << endl;
#endif
if (item == first_item && !ksettings.b_offline) {
switch (item->getStatus()) {
case Transfer::ST_TRYING:
case Transfer::ST_RUNNING:
m_paResume->setEnabled(false);
m_paPause->setEnabled(true);
m_paRestart->setEnabled(true);
break;
case Transfer::ST_STOPPED:
m_paResume->setEnabled(true);
m_paPause->setEnabled(false);
m_paRestart->setEnabled(false);
#ifdef _DEBUG
sDebug << "STATUS IS stopped" << item->getStatus() << endl;
#endif
break;
case Transfer::ST_FINISHED:
m_paResume->setEnabled(false);
m_paPause->setEnabled(false);
m_paRestart->setEnabled(false);
break;
} //end switch
} else if (item->getStatus() != first_item->getStatus()) {
// disable all when all selected items don't have the same status
m_paResume->setEnabled(false);
m_paPause->setEnabled(false);
m_paRestart->setEnabled(false);
}
if (item == first_item) {
m_paDelete->setEnabled(true);
m_paCopy->setEnabled(true);
m_paIndividual->setEnabled(true);
if (item->getStatus() != Transfer::ST_FINISHED) {
m_paQueue->setEnabled(true);
m_paTimer->setEnabled(true);
m_paDelay->setEnabled(true);
switch (item->getMode()) {
case Transfer::MD_QUEUED:
#ifdef _DEBUG
sDebug << "....................THE MODE IS MD_QUEUED " << item->getMode() << endl;
#endif
m_paQueue->setChecked(true);
break;
case Transfer::MD_SCHEDULED:
#ifdef _DEBUG
sDebug << "....................THE MODE IS MD_SCHEDULED " << item->getMode() << endl;
#endif
m_paTimer->setChecked(true);
break;
case Transfer::MD_DELAYED:
#ifdef _DEBUG
sDebug << "....................THE MODE IS MD_DELAYED " << item->getMode() << endl;
#endif
m_paDelay->setChecked(true);
break;
}
}
} else if (item->getMode() != first_item->getMode()) {
// unset all when all selected items don't have the same mode
m_paQueue->setChecked(false);
m_paTimer->setChecked(false);
m_paDelay->setChecked(false);
m_paMoveToBegin->setEnabled(false);
m_paMoveToEnd->setEnabled(false);
m_paQueue->setEnabled(false);
m_paTimer->setEnabled(false);
m_paDelay->setEnabled(false);
}
} // when item is selected
} // loop
if (sel_items == totals_items - 1)
m_paMoveToEnd->setEnabled(false);
// enable all signals
m_paQueue->blockSignals(false);
m_paTimer->blockSignals(false);
m_paDelay->blockSignals(false);
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::updateStatusBar()
{
#ifdef _DEBUG
//sDebugIn << endl;
#endif
Transfer *item;
TQString tmpstr;
int totalFiles = 0;
TDEIO::filesize_t totalSize = 0;
int totalSpeed = 0;
unsigned int remTime = 0;
TransferIterator it(myTransferList);
for (; it.current(); ++it) {
item = it.current();
if (item->getTotalSize() != 0) {
totalSize += (item->getTotalSize() - item->getProcessedSize());
}
totalFiles++;
totalSpeed += item->getSpeed();
if (item->getRemainingTime() > remTime) {
remTime = item->getRemainingTime();
}
}
statusBar()->changeItem(i18n(" Transfers: %1 ").arg(myTransferList->childCount()), ID_TOTAL_TRANSFERS);
statusBar()->changeItem(i18n(" Files: %1 ").arg(totalFiles), ID_TOTAL_FILES);
statusBar()->changeItem(i18n(" Size: %1 ").arg(TDEIO::convertSize(totalSize)), ID_TOTAL_SIZE);
statusBar()->changeItem(i18n(" Time: %1 ").arg(TDEIO::convertSeconds(remTime)), ID_TOTAL_TIME);
statusBar()->changeItem(i18n(" %1/s ").arg(TDEIO::convertSize(totalSpeed)), ID_TOTAL_SPEED);
//update size for each statusbar field
statusBar()->setItemFixed(ID_TOTAL_TRANSFERS, -1);
statusBar()->setItemFixed(ID_TOTAL_FILES, -1);
statusBar()->setItemFixed(ID_TOTAL_SIZE, -1);
statusBar()->setItemFixed(ID_TOTAL_TIME, -1);
statusBar()->setItemFixed(ID_TOTAL_SPEED, -1);
if (kdock) {
tmpstr = i18n("<b>Transfers:</b> %1 ").arg(myTransferList->childCount()) +
i18n("<br /><b>Files:</b> %1 ").arg(totalFiles) +
i18n("<br /><b>Size:</b> %1 ").arg(TDEIO::convertSize(totalSize)) +
i18n("<br /><b>Time:</b> %1 ").arg(TDEIO::convertSeconds(remTime)) +
i18n("<br /><b>Speed:</b> %1/s").arg(TDEIO::convertSize(totalSpeed));
kdock->updateToolTip( tmpstr );
//trayicon changes if download is in progress
if (totalSpeed == 0)
{
kdock->changeIcon( "kget_dock" );
}
else
{
kdock->changeIcon( "kget_dock_download" );
}
}
#ifdef _DEBUG
//sDebugOut << endl;
#endif
}
void TDEMainWidget::onlineDisconnect()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
if (!b_connected) {
return;
}
if (!ksettings.b_expertMode) {
if (KMessageBox::questionYesNo(this, i18n("Do you really want to disconnect?"),
i18n("Question"),
i18n("Disconnect"), i18n("Stay Connected"),
"kget_AutoOnlineDisconnect")
!= KMessageBox::Yes) {
return;
}
}
log(i18n("Disconnecting..."));
if (system(TQFile::encodeName(ksettings.disconnectCommand)) < 0) {
// Error!
}
#ifdef _DEBUG
sDebugOut << endl;
#endif
}
void TDEMainWidget::slotCheckConnection()
{
#ifdef _DEBUG
//sDebugIn << endl;
#endif
bool old = b_connected;
checkOnline();
if (b_connected != old) {
if (b_connected) {
log(i18n("We are online."));
setCaption(TQString(), false);
ksettings.b_offline=ksettings.b_offlineMode;
checkQueue();
} else {
log(i18n("We are offline."));
setCaption(i18n("Offline"), false);
ksettings.b_offline=true;
stopAll();
}
}
#ifdef _DEBUG
//sDebugOut << endl;
#endif
}
void TDEMainWidget::checkOnline()
{
#ifdef _DEBUG
//sDebugIn << endl;
#endif
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifreq));
// setup the device name according to the type of connection and link number
snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s%d", ConnectionDevices[ksettings.connectionType].ascii(), ksettings.linkNumber);
bool flag = false;
if (ksettings.connectionType != PERMANENT) {
// get the flags for particular device
if (ioctl(_sock, SIOCGIFFLAGS, &ifr) < 0) {
flag = true;
b_connected = false;
} else if (ifr.ifr_flags == 0) {
#ifdef _DEBUG
sDebug << "Can't get flags from interface " << ifr.ifr_name << endl;
#endif
b_connected = false;
} else if (ifr.ifr_flags & IFF_UP) { // if (ifr.ifr_flags & IFF_RUNNING)
b_connected = true;
} else {
b_connected = false;
}
} else {
b_connected = true; // PERMANENT connection
}
m_paOfflineMode->setEnabled(b_connected);
if (flag) {
#ifdef _DEBUG
sDebug << "Unknown interface " << ifr.ifr_name << endl;
#endif
}
#ifdef _DEBUG
//sDebugOut << endl;
#endif
}
// Helper method for opening device socket
static int sockets_open()
{
#ifdef _DEBUG
sDebugIn << endl;
#endif
inet_sock = socket(AF_INET, SOCK_DGRAM, 0);
#ifdef AF_IPX
ipx_sock = socket(AF_IPX, SOCK_DGRAM, 0);
#else
ipx_sock = -1;
#endif
#ifdef AF_AX25
ax25_sock = socket(AF_AX25, SOCK_DGRAM, 0);
#else
ax25_sock = -1;
#endif
ddp_sock = socket(AF_APPLETALK, SOCK_DGRAM, 0);
/*
* Now pick any (exisiting) useful socket family for generic queries
*/
sDebug << "<<<<Leaving -> sockets_open () " << endl;
if (inet_sock != -1)
return inet_sock;
if (ipx_sock != -1)
return ipx_sock;
if (ax25_sock != -1)
return ax25_sock;
/*
* If this is -1 we have no known network layers and its time to jump.
*/
#ifdef _DEBUG
sDebugOut << endl;
#endif
return ddp_sock;
}
/** No descriptions */
void TDEMainWidget::customEvent(TQCustomEvent * _e)
{
#ifdef _DEBUG
//sDebugIn << endl;
#endif
SlaveEvent *e = (SlaveEvent *) _e;
unsigned int result = e->getEvent();
switch (result) {
// running cases..
case Slave::SLV_PROGRESS_SIZE:
e->getItem()->slotProcessedSize(e->getData());
break;
case Slave::SLV_PROGRESS_SPEED:
e->getItem()->slotSpeed(e->getData());
break;
case Slave::SLV_RESUMED:
e->getItem()->slotExecResume();
break;
// stopping cases
case Slave::SLV_FINISHED:
e->getItem()->slotFinished();
break;
case Slave::SLV_PAUSED:
e->getItem()->slotExecPause();
break;
case Slave::SLV_SCHEDULED:
e->getItem()->slotExecSchedule();
break;
case Slave::SLV_DELAYED:
e->getItem()->slotExecDelay();
break;
case Slave::SLV_CONNECTED:
e->getItem()->slotExecConnected();
break;
case Slave::SLV_CAN_RESUME:
e->getItem()->slotCanResume((bool) e->getData());
break;
case Slave::SLV_TOTAL_SIZE:
e->getItem()->slotTotalSize(e->getData());
break;
case Slave::SLV_ERROR:
e->getItem()->slotExecError();
break;
case Slave::SLV_BROKEN:
e->getItem()->slotExecBroken();
break;
case Slave::SLV_REMOVED:
e->getItem()->slotExecRemove();
break;
case Slave::SLV_INFO:
e->getItem()->logMessage(e->getMsg());
break;
case Slave::SLV_NOTINCACHE:
e->getItem()->NotInCache();
break;
default:
#ifdef _DEBUG
sDebug << "Unknown Result..die" << result << endl;
#endif
assert(0);
}
#ifdef _DEBUG
//sDebugOut << endl;
#endif
}
TQString TDEMainWidget::getSaveDirectoryFor( const TQString& filename ) const
{
// first set destination directory to current directory ( which is also last used )
TQString destDir = ksettings.lastDirectory;
if (!ksettings.b_useLastDir) {
// check wildcards for default directory
DirList::Iterator it;
for (it = ksettings.defaultDirList.begin(); it != ksettings.defaultDirList.end(); ++it) {
TQRegExp rexp((*it).extRegexp);
rexp.setWildcard(true);
if ((rexp.search( filename )) != -1) {
destDir = (*it).defaultDir;
break;
}
}
}
return destDir;
}
bool TDEMainWidget::sanityChecksSuccessful( const KURL& url )
{
if (!url.isValid() || !KProtocolInfo::supportsReading( url ) )
{
if (!ksettings.b_expertMode)
KMessageBox::error(this, i18n("Malformed URL:\n%1").arg(url.prettyURL()), i18n("Error"));
return false;
}
// if we find this URL in the list
Transfer *transfer = myTransferList->find( url );
if ( transfer )
{
if ( transfer->getStatus() != Transfer::ST_FINISHED )
{
if ( !ksettings.b_expertMode )
{
KMessageBox::error(this, i18n("Already saving URL\n%1").arg(url.prettyURL()), i18n("Error"));
}
transfer->showIndividual();
return false;
}
else // transfer is finished, ask if we want to download again
{
if ( ksettings.b_expertMode ||
(KMessageBox::questionYesNo(this, i18n("Already saved URL\n%1\nDownload again?").arg(url.prettyURL()),i18n("Question"),i18n("Download Again"),KStdGuiItem::cancel() )
== KMessageBox::Yes) )
{
transfer->slotRequestRemove();
checkQueue();
return true;
}
}
return false;
}
// why restrict this to ftp and http? (pfeiffer)
// // don't download file URL's TODO : uncomment?
// if (url.protocol() == "http" && url.protocol() != "ftp") {
// KMessageBox::error(this, i18n("File protocol not accepted!\n%1").arg(url.prettyURL()), i18n("Error"));
// #ifdef _DEBUG
// sDebugOut << endl;
// #endif
// return false;
// }
return true;
}
bool TDEMainWidget::isDropTargetVisible() const
{
return m_showDropTarget;
}
void TDEMainWidget::setDropTargetVisible( bool setVisible )
{
if ( setVisible != isDropTargetVisible() )
{
m_paDropTarget->activate();
}
}
void TDEMainWidget::setOfflineMode( bool offline )
{
if ( ksettings.b_offlineMode != offline )
slotToggleOfflineMode();
}
bool TDEMainWidget::isOfflineMode() const
{
return ksettings.b_offlineMode;
}
void TDEMainWidget::activateDropTarget()
{
setDropTargetVisible( true );
}
void TDEMainWidget::slotShowMenubar()
{
if(m_menubarAction->isChecked())
menuBar()->show();
else
menuBar()->hide();
}
#include "tdemainwidget.moc"
|