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
|
/***************************************************************************
* settings.cpp
* -------------------
*
* begin : Tue Jan 29 2002
* copyright : (C) 2002 by Patrick Charbonnier
*
* email : pch@freeshell.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 <kapplication.h>
#include <kstandarddirs.h>
#include <kglobal.h>
#include <kconfig.h>
#include <klocale.h>
#include <kwin.h>
#include <kmessagebox.h>
#include <kglobalsettings.h>
#include <netwm_def.h>
#include <tqdir.h>
#include "kmainwidget.h"
#include "transferlist.h"
#include "droptarget.h"
#include "settings.h"
#include "common.h"
#include "version.h"
static const unsigned long DEFAULT_DOCK_STATE = (NET::SkipTaskbar | NET::StaysOnTop);
TQString ConnectionDevices[6] = {
"",
"eth",
"plip",
"slip",
"ppp",
"isdn"
};
void
Settings::load()
{
sDebug << "Loading settings" << endl;
KConfig *config = kapp->config();
// read system options
config->setGroup("System");
// read connection options
config->setGroup("Connection");
b_reconnectOnError = config->readBoolEntry("ReconnectOnError", DEF_ReconnectOnError);
reconnectTime = config->readNumEntry("ReconnectTime", DEF_ReconnectTime);
reconnectRetries = config->readNumEntry("ReconnectRetries", DEF_ReconnectRetries);
b_reconnectOnBroken = config->readBoolEntry("ReconnectOnBroken", DEF_ReconnectOnBroken);
timeoutData = config->readNumEntry("TimeoutData", DEF_TimeoutData);
timeoutDataNoResume = config->readNumEntry("TimeoutDataNoResume", DEF_TimeoutDataNoResume);
connectionType = config->readNumEntry("ConnectionType", DEF_ConnectionType);
linkNumber = config->readNumEntry("LinkNumber", DEF_LinkNumber);
b_offlineMode = config->readBoolEntry("OfflineMode", DEF_OfflineMode);
// read automation options
config->setGroup("Automation");
b_autoSave = config->readBoolEntry("AutoSave", DEF_AutoSave);
autoSaveInterval = config->readNumEntry("AutoSaveInterval", DEF_AutoSaveInterval);
b_autoDisconnect = config->readBoolEntry("AutoDisconnect", DEF_AutoDisconnect);
disconnectCommand = config->readPathEntry("DisconnectCommand", DEF_DisconnectCommand);
b_timedDisconnect = config->readBoolEntry("TimedDisconnect", DEF_TimedDisconnect);
disconnectTime.setHMS(config->readNumEntry("DisconnectTimeHour"), config->readNumEntry("DisconnectTimeMinute"), 0);
disconnectDate = TQDate::currentDate(); // doesn't make sense to save it
b_autoShutdown = config->readBoolEntry("AutoShutdown", DEF_AutoShutdown);
b_autoPaste = config->readBoolEntry("AutoPaste", DEF_AutoPaste);
// read limits options
config->setGroup("Limits");
maxSimultaneousConnections = config->readNumEntry("MaxSimConnections", DEF_MaxSimConnections);
minimumBandwidth = config->readNumEntry("MinimumBandwidth", DEF_MinimumBandwidth);
maximumBandwidth = config->readNumEntry("MaximumBandwidth", DEF_MaximumBandwidth);
// read advanced options
config->setGroup("Advanced");
b_addQueued = config->readBoolEntry("AddQueued", DEF_AddQueued);
b_showMain = config->readBoolEntry("ShowMain", DEF_ShowMain);
b_showIndividual = config->readBoolEntry("ShowIndividual", DEF_ShowIndividual);
b_iconifyIndividual = config->readBoolEntry("IconifyIndividual", DEF_IconifyIndividual);
b_advancedIndividual = config->readBoolEntry("AdvancedIndividual", DEF_AdvancedIndividual);
b_removeOnSuccess = config->readBoolEntry("RemoveOnSuccess", DEF_RemoveOnSuccess);
b_getSizes = config->readBoolEntry("GetSizes", DEF_GetSizes);
b_expertMode = config->readBoolEntry("ExpertMode", DEF_ExpertMode);
// read if the integration whith konqueror is enabled
KConfig *cfg = new KConfig("konquerorrc", false, false);
cfg->setGroup("HTML Settings");
TQString downloadManager=cfg->readPathEntry("DownloadManager");
b_KonquerorIntegration=(downloadManager==KGET_APP_NAME)?true:false;
// check if we already asked about konqueror integration
if(config->readBoolEntry("FirstRun",true))
{
config->writeEntry("FirstRun",false);
bool bAnswerYes = KMessageBox::questionYesNo(0L,i18n("This is the first time that you have run KGet.\nDo you want to use KGet as Download Manager for Konqueror?"), i18n("Konqueror Integration"), i18n("Enable"), i18n("Do Not Enable")) == KMessageBox::Yes;
if (bAnswerYes)
{
cfg->writePathEntry("DownloadManager", TQString(KGET_APP_NAME));
cfg->sync();
b_KonquerorIntegration=true;
}
}
delete cfg;
// read search options
config->setGroup("Search");
b_searchFastest = config->readBoolEntry("SearchFastest", DEF_SearchFastest);
searchItems = config->readNumEntry("SearchItems", DEF_SearchItems);
timeoutSearch = config->readNumEntry("TimeoutSearch", DEF_TimeoutSearch);
b_switchHosts = config->readBoolEntry("SwitchHosts", DEF_SwitchHosts);
// read directory options
config->setGroup("Directories");
b_useLastDir = config->readBoolEntry("UseLastDirectory", DEF_UseLastDir);
lastDirectory = config->readPathEntry("LastDirectory",
TQString("file:") + TQDir::currentDirPath() );
TQStringList strList;
strList = config->readPathListEntry("Items");
defaultDirList.clear();
TQStringList::Iterator it = strList.begin();
for (; it != strList.end(); ++it) {
DirItem item;
item.extRegexp = *it;
++it;
item.defaultDir = *it;
defaultDirList.append(item);
}
// read misc settings
config->setGroup("Misc");
TQFont font = KGlobalSettings::generalFont();
listViewFont = config->readFontEntry("Font", &font);
// read main window geometry settings
config->setGroup("MainGeometry");
const TQPoint point(-1,-1);
mainPosition = config->readPointEntry("Position", &point);
mainSize = config->readSizeEntry("Size");
mainState = config->readUnsignedLongNumEntry("State", 0);
// read drop target geometry settings
config->setGroup("DropGeometry");
dropPosition = config->readPointEntry("Position", &point);
dropState = config->readUnsignedLongNumEntry("State", DEFAULT_DOCK_STATE );
// flushing pending changes
config->sync();
}
void Settings::save()
{
sDebug << "Saving settings" << endl;
KConfig *config = kapp->config();
// write connection options
config->setGroup("Connection");
config->writeEntry("ReconnectOnError", b_reconnectOnError);
config->writeEntry("ReconnectTime", reconnectTime);
config->writeEntry("ReconnectRetries", reconnectRetries);
config->writeEntry("ReconnectOnBroken", b_reconnectOnBroken);
config->writeEntry("TimeoutData", timeoutData);
config->writeEntry("TimeoutDataNoResume", timeoutDataNoResume);
config->writeEntry("ConnectionType", connectionType);
config->writeEntry("LinkNumber", linkNumber);
config->writeEntry("OfflineMode", b_offlineMode);
// write automation options
config->setGroup("Automation");
config->writeEntry("AutoSave", b_autoSave);
config->writeEntry("AutoSaveInterval", autoSaveInterval);
config->writeEntry("AutoDisconnect", b_autoDisconnect);
config->writePathEntry("DisconnectCommand", disconnectCommand);
config->writeEntry("TimedDisconnect", b_timedDisconnect);
config->writeEntry("DisconnectTimeHour", disconnectTime.hour());
config->writeEntry("DisconnectTimeMinute", disconnectTime.minute());
config->writeEntry("AutoShutdown", b_autoShutdown);
config->writeEntry("AutoPaste", b_autoPaste);
// write limits options
config->setGroup("Limits");
config->writeEntry("MaxSimConnections", maxSimultaneousConnections);
config->writeEntry("MinimumBandwidth", minimumBandwidth);
config->writeEntry("MaximumBandwidth", maximumBandwidth);
// write advanced options
config->setGroup("Advanced");
config->writeEntry("ShowMain", b_showMain);
config->writeEntry("AddQueued", b_addQueued);
config->writeEntry("ShowIndividual", b_showIndividual);
config->writeEntry("IconifyIndividual", b_iconifyIndividual);
config->writeEntry("AdvancedIndividual", b_advancedIndividual);
config->writeEntry("RemoveOnSuccess", b_removeOnSuccess);
config->writeEntry("GetSizes", b_getSizes);
config->writeEntry("ExpertMode", b_expertMode);
config->writeEntry("KonquerorIntegration",b_KonquerorIntegration);
// write search options
config->setGroup("Search");
config->writeEntry("SearchFastest", b_searchFastest);
config->writeEntry("SearchItems", searchItems);
config->writeEntry("TimeoutSearch", timeoutSearch);
config->writeEntry("SwitchHosts", b_switchHosts);
// write directory options
config->setGroup("Directories");
config->writeEntry("UseLastDirectory", b_useLastDir);
config->writePathEntry("LastDirectory", lastDirectory );
DirList::Iterator it;
TQStringList lst;
for (it = defaultDirList.begin(); it != defaultDirList.end(); ++it) {
lst.append((*it).extRegexp);
lst.append((*it).defaultDir);
}
config->writePathEntry("Items", lst);
// write system options
config->setGroup("System");
config->writeEntry("UseAnimation", b_useAnimation);
// write misc options
config->setGroup("Misc");
config->writeEntry("Font", listViewFont);
// write main window geometry properties
config->setGroup("MainGeometry");
config->writeEntry("Position", kmain->pos());
config->writeEntry("Size", kmain->size());
config->writeEntry("State", KWin::windowInfo(kmain->winId()).state());
// write drop target geometry properties
config->setGroup("DropGeometry");
config->writeEntry("Position", kdrop->pos());
unsigned long state = KWin::windowInfo(kdrop->winId()).state();
// state will be 0L if droptarget is hidden. Sigh.
config->writeEntry("State", state ? state : DEFAULT_DOCK_STATE );
config->sync();
}
|