author | tille <tille> | 2002-07-09 13:17:05 (UTC) |
---|---|---|
committer | tille <tille> | 2002-07-09 13:17:05 (UTC) |
commit | e99adc2029808f6276474c95e8587607a4bd8091 (patch) (unidiff) | |
tree | ff1d4fc802b9cb581cb01466777f564ca7390512 /noncore/unsupported/oipkg/settings.cpp | |
parent | 0faf1ec599a30432169486aea8a117cf9f1627b8 (diff) | |
download | opie-e99adc2029808f6276474c95e8587607a4bd8091.zip opie-e99adc2029808f6276474c95e8587607a4bd8091.tar.gz opie-e99adc2029808f6276474c95e8587607a4bd8091.tar.bz2 |
weg mit dem scheiss...
Diffstat (limited to 'noncore/unsupported/oipkg/settings.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/unsupported/oipkg/settings.cpp | 450 |
1 files changed, 0 insertions, 450 deletions
diff --git a/noncore/unsupported/oipkg/settings.cpp b/noncore/unsupported/oipkg/settings.cpp deleted file mode 100644 index 4bd60c0..0000000 --- a/noncore/unsupported/oipkg/settings.cpp +++ b/dev/null | |||
@@ -1,450 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
3 | * This program is free software; you can redistribute it and/or modify * | ||
4 | * it under the terms of the GNU General Public License as published by * | ||
5 | * the Free Software Foundation; either version 2 of the License, or * | ||
6 | * (at your option) any later version. * | ||
7 | * * | ||
8 | ***************************************************************************/ | ||
9 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> | ||
10 | #include "pksettings.h" | ||
11 | |||
12 | #include <qpe/config.h> | ||
13 | #include <qcombobox.h> | ||
14 | #include <qfile.h> | ||
15 | #include <qlineedit.h> | ||
16 | #include <qpushbutton.h> | ||
17 | #include <qlistbox.h> | ||
18 | #include <qcheckbox.h> | ||
19 | #include <qstring.h> | ||
20 | #include <qobject.h> | ||
21 | #include <qtextstream.h> | ||
22 | #include <qtabwidget.h> | ||
23 | |||
24 | |||
25 | PackageManagerSettings::PackageManagerSettings( QWidget* parent, const char* name, WFlags fl ) | ||
26 | : PackageManagerSettingsBase( parent, name, fl ) | ||
27 | { | ||
28 | connect( newserver, SIGNAL(clicked()), this, SLOT(newServer()) ); | ||
29 | connect( removeserver, SIGNAL(clicked()), this, SLOT(removeServer()) ); | ||
30 | connect( servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) ); | ||
31 | connect( newdestination, SIGNAL(clicked()), this, SLOT(newDestination()) ); | ||
32 | connect( removedestination, SIGNAL(clicked()), this, SLOT(removeDestination()) ); | ||
33 | connect( destinations, SIGNAL(highlighted(int)), this, SLOT(editDestination(int)) ); | ||
34 | // connect( CheckBoxLink, SIGNAL(toggled(bool)), | ||
35 | // activeLinkDestination, SLOT(setEnabled(bool)) ); | ||
36 | |||
37 | connect( settingName, SIGNAL(activated(int)), this, SLOT(installationSettingChange(int)) ); | ||
38 | connect( settingName, SIGNAL(textChanged(const QString &)), this, SLOT(installationSettingSetName(const QString &)) ); | ||
39 | connect( newsetting, SIGNAL(clicked()), this, SLOT(newInstallationSetting()) ); | ||
40 | connect( renamesetting, SIGNAL(clicked()), this, SLOT(renameInstallationSetting()) ); | ||
41 | connect( removesetting, SIGNAL(clicked()), this, SLOT(removeInstallationSetting()) ); | ||
42 | servername->setEnabled(FALSE); | ||
43 | serverurl->setEnabled(FALSE); | ||
44 | serverurlDic.setAutoDelete(TRUE); | ||
45 | destinationname->setEnabled(FALSE); | ||
46 | destinationurl->setEnabled(FALSE); | ||
47 | destinationurlDic.setAutoDelete(TRUE); | ||
48 | readSettings(); | ||
49 | } | ||
50 | |||
51 | PackageManagerSettings::~PackageManagerSettings() | ||
52 | { | ||
53 | } | ||
54 | |||
55 | |||
56 | void PackageManagerSettings::newServer() | ||
57 | { | ||
58 | int i = servers->count(); | ||
59 | if ( servername->isEnabled() || serverurl->text().isEmpty() ) { | ||
60 | serverurlDic.insert(i,new QString("http://")); | ||
61 | servers->insertItem(tr("New")); | ||
62 | activeServers->insertItem(tr("New")); | ||
63 | } else { | ||
64 | // allows one-level undo | ||
65 | serverurlDic.insert(i,new QString(serverurl->text())); | ||
66 | servers->insertItem(servername->text()); | ||
67 | activeServers->insertItem(servername->text()); | ||
68 | } | ||
69 | servers->setSelected(i,TRUE); | ||
70 | editServer(i); | ||
71 | } | ||
72 | |||
73 | void PackageManagerSettings::newDestination() | ||
74 | { | ||
75 | int i = destinations->count(); | ||
76 | if ( destinationname->isEnabled() || destinationurl->text().isEmpty() ) { | ||
77 | destinationurlDic.insert(i,new QString("/")); | ||
78 | destinations->insertItem(tr("New")); | ||
79 | activeDestination->insertItem(tr("New")); | ||
80 | activeLinkDestination->insertItem(tr("New")); | ||
81 | } else { | ||
82 | // allows one-level undo | ||
83 | destinationurlDic.insert(i,new QString(destinationurl->text())); | ||
84 | destinations->insertItem(destinationname->text()); | ||
85 | activeDestination->insertItem(destinationname->text()); | ||
86 | activeLinkDestination->insertItem(destinationname->text()); | ||
87 | } | ||
88 | destinations->setSelected(i,TRUE); | ||
89 | editDestination(i); | ||
90 | } | ||
91 | |||
92 | |||
93 | void PackageManagerSettings::editServer(int i) | ||
94 | { | ||
95 | if ( servername->isEnabled() ) { | ||
96 | disconnect( servername, SIGNAL(textChanged(const QString&)), this, SLOT(serverNameChanged(const QString&)) ); | ||
97 | disconnect( serverurl, SIGNAL(textChanged(const QString&)), this, SLOT(serverUrlChanged(const QString&)) ); | ||
98 | } else { | ||
99 | servername->setEnabled(TRUE); | ||
100 | serverurl->setEnabled(TRUE); | ||
101 | } | ||
102 | |||
103 | servername->setText( servers->text(i) ); | ||
104 | serverurl->setText( *serverurlDic[i] ); | ||
105 | |||
106 | editedserver = i; | ||
107 | |||
108 | connect( servername, SIGNAL(textChanged(const QString&)), this, SLOT(serverNameChanged(const QString&)) ); | ||
109 | connect( serverurl, SIGNAL(textChanged(const QString&)), this, SLOT(serverUrlChanged(const QString&)) ); | ||
110 | } | ||
111 | |||
112 | |||
113 | void PackageManagerSettings::editDestination(int i) | ||
114 | { | ||
115 | if ( destinationname->isEnabled() ) { | ||
116 | disconnect( destinationname, SIGNAL(textChanged(const QString&)), this, SLOT(destNameChanged(const QString&)) ); | ||
117 | disconnect( destinationurl, SIGNAL(textChanged(const QString&)), this, SLOT(destUrlChanged(const QString&)) ); | ||
118 | } else { | ||
119 | destinationname->setEnabled(TRUE); | ||
120 | destinationurl->setEnabled(TRUE); | ||
121 | } | ||
122 | |||
123 | destinationname->setText( destinations->text(i) ); | ||
124 | destinationurl->setText( *destinationurlDic[i] ); | ||
125 | |||
126 | editeddestination = i; | ||
127 | |||
128 | connect( destinationname, SIGNAL(textChanged(const QString&)), this, SLOT(destNameChanged(const QString&)) ); | ||
129 | connect( destinationurl, SIGNAL(textChanged(const QString&)), this, SLOT(destUrlChanged(const QString&)) ); | ||
130 | } | ||
131 | |||
132 | void PackageManagerSettings::removeServer() | ||
133 | { | ||
134 | disconnect( servername, SIGNAL(textChanged(const QString&)), this, SLOT(serverNameChanged(const QString&)) ); | ||
135 | disconnect( serverurl, SIGNAL(textChanged(const QString&)), this, SLOT(serverUrlChanged(const QString&)) ); | ||
136 | servername->setText(servers->text(editedserver)); | ||
137 | serverurl->setText(*serverurlDic[editedserver]); | ||
138 | disconnect( servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) ); | ||
139 | servers->removeItem(editedserver); | ||
140 | activeServers->removeItem(editedserver); | ||
141 | connect( servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) ); | ||
142 | servername->setEnabled(FALSE); | ||
143 | serverurl->setEnabled(FALSE); | ||
144 | } | ||
145 | |||
146 | void PackageManagerSettings::removeDestination() | ||
147 | { | ||
148 | disconnect( destinationname, SIGNAL(textChanged(const QString&)), this, SLOT(destNameChanged(const QString&)) ); | ||
149 | disconnect( destinationurl, SIGNAL(textChanged(const QString&)), this, SLOT(destUrlChanged(const QString&)) ); | ||
150 | destinationname->setText(destinations->text(editedserver)); | ||
151 | destinationurl->setText(*destinationurlDic[editedserver]); | ||
152 | disconnect( destinations, SIGNAL(highlighted(int)), this, SLOT(editDestination(int)) ); | ||
153 | destinations->removeItem(editeddestination); | ||
154 | activeDestination->removeItem(editeddestination); | ||
155 | activeLinkDestination->removeItem(editeddestination); | ||
156 | connect( destinations, SIGNAL(highlighted(int)), this, SLOT(editDestination(int)) ); | ||
157 | destinationname->setEnabled(FALSE); | ||
158 | destinationurl->setEnabled(FALSE); | ||
159 | } | ||
160 | |||
161 | void PackageManagerSettings::serverNameChanged(const QString& t) | ||
162 | { | ||
163 | disconnect( servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) ); | ||
164 | servers->changeItem( t, editedserver ); | ||
165 | activeServers->changeItem( t, editedserver ); | ||
166 | connect( servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) ); | ||
167 | } | ||
168 | |||
169 | void PackageManagerSettings::destNameChanged(const QString& t) | ||
170 | { | ||
171 | disconnect( destinations, SIGNAL(highlighted(int)), this, SLOT(editDestination(int)) ); | ||
172 | destinations->changeItem( t, editeddestination ); | ||
173 | activeDestination->changeItem( t, editeddestination ); | ||
174 | activeLinkDestination->changeItem( t, editeddestination ); | ||
175 | connect( destinations, SIGNAL(highlighted(int)), this, SLOT(editDestination(int)) ); | ||
176 | } | ||
177 | |||
178 | void PackageManagerSettings::serverUrlChanged(const QString& t) | ||
179 | { | ||
180 | serverurlDic.replace(editedserver, new QString(t)); | ||
181 | } | ||
182 | |||
183 | void PackageManagerSettings::destUrlChanged(const QString& t) | ||
184 | { | ||
185 | destinationurlDic.replace(editeddestination, new QString(t)); | ||
186 | } | ||
187 | |||
188 | void PackageManagerSettings::writeIpkgConfig(const QString& conffile) | ||
189 | { | ||
190 | QFile conf(conffile); | ||
191 | if ( ! conf.open(IO_WriteOnly) ) return; | ||
192 | QTextStream s(&conf); | ||
193 | s << "# "+tr("Written by Opie Package Manager")+"\n"; | ||
194 | for (int i=0; i<(int)activeServers->count(); i++) | ||
195 | { | ||
196 | QString url = serverurlDic[i] ? *serverurlDic[i] : QString("???"); | ||
197 | if ( !activeServers->isSelected(i) ) | ||
198 | s << "#"; | ||
199 | s << "src " << activeServers->text(i) << " " << url << "\n"; | ||
200 | } | ||
201 | for (int i=0; i<(int)destinations->count(); i++) | ||
202 | { | ||
203 | QString url = destinationurlDic[i] ? *destinationurlDic[i] : QString("???"); | ||
204 | s << "dest " << destinations->text(i) << " " << url << "\n"; | ||
205 | } | ||
206 | conf.close(); | ||
207 | } | ||
208 | |||
209 | |||
210 | void PackageManagerSettings::readInstallationSettings() | ||
211 | { | ||
212 | Config cfg( "oipkg", Config::User ); | ||
213 | cfg.setGroup( "Settings" ); | ||
214 | installationSettingsCount = cfg.readNumEntry( "count", -1 ); | ||
215 | currentSetting = cfg.readNumEntry( "current", 0 ); | ||
216 | |||
217 | for (int i = 0; i < installationSettingsCount; i++) | ||
218 | { | ||
219 | cfg.setGroup( "Setting_" + QString::number(i) ); | ||
220 | settingName->insertItem( cfg.readEntry( "name", "???" ), i ); | ||
221 | }; | ||
222 | readInstallationSetting( currentSetting ); | ||
223 | } | ||
224 | |||
225 | |||
226 | void PackageManagerSettings::removeInstallationSetting() | ||
227 | { | ||
228 | settingName->removeItem( settingName->currentItem() ); | ||
229 | Config cfg( "oipkg", Config::User ); | ||
230 | cfg.setGroup( "Setting_" + QString::number( installationSettingsCount ) ); | ||
231 | cfg.clearGroup(); | ||
232 | installationSettingsCount--; | ||
233 | settingName->setEditable( false ); | ||
234 | } | ||
235 | |||
236 | void PackageManagerSettings::newInstallationSetting() | ||
237 | { | ||
238 | installationSettingsCount++; | ||
239 | settingName->insertItem( "New", installationSettingsCount ); | ||
240 | settingName->setCurrentItem( installationSettingsCount ); | ||
241 | settingName->setEditable( true ); | ||
242 | } | ||
243 | |||
244 | void PackageManagerSettings::installationSettingChange(int cs) | ||
245 | { | ||
246 | writeCurrentInstallationSetting(); | ||
247 | currentSetting = cs; | ||
248 | readInstallationSetting( cs ); | ||
249 | } | ||
250 | |||
251 | void PackageManagerSettings::writeInstallationSettings() | ||
252 | { | ||
253 | { | ||
254 | Config cfg( "oipkg", Config::User ); | ||
255 | cfg.setGroup( "Settings" ); | ||
256 | cfg.writeEntry( "count", installationSettingsCount ); | ||
257 | cfg.writeEntry( "current", currentSetting ); | ||
258 | writeCurrentInstallationSetting(); | ||
259 | } | ||
260 | } | ||
261 | |||
262 | |||
263 | void PackageManagerSettings::readInstallationSetting(int setting) | ||
264 | { | ||
265 | if ( setting < 0 ) return; | ||
266 | Config cfg( "oipkg", Config::User ); | ||
267 | cfg.setGroup( "Setting_" + QString::number( setting ) ); | ||
268 | CheckBoxLink->setChecked( cfg.readBoolEntry( "link", false ) ); | ||
269 | QString dest = cfg.readEntry( "dest" ); | ||
270 | QString linkdest = cfg.readEntry( "linkdest" ); | ||
271 | |||
272 | for ( int i = 0; i < activeDestination->count(); i++) | ||
273 | { | ||
274 | QString name = cfg.readEntry( "name" ); | ||
275 | if ( activeDestination->text( i ) == name ) | ||
276 | activeDestination->setCurrentItem( i ); | ||
277 | if ( activeLinkDestination->text( i ) == name ) | ||
278 | activeLinkDestination->setCurrentItem( i ); | ||
279 | } | ||
280 | } | ||
281 | |||
282 | void PackageManagerSettings::writeCurrentInstallationSetting() | ||
283 | { | ||
284 | Config cfg( "oipkg", Config::User ); | ||
285 | cfg.setGroup( "Setting_" + QString::number(currentSetting) ); | ||
286 | cfg.writeEntry( "link", CheckBoxLink->isChecked() ); | ||
287 | cfg.writeEntry( "dest", getDestinationName() ); | ||
288 | cfg.writeEntry( "linkdest" , getLinkDestinationName() ); | ||
289 | QStringList sers = getActiveServers(); | ||
290 | int srvc = 0; | ||
291 | for ( QStringList::Iterator it = sers.begin(); it != sers.end(); ++it ) { | ||
292 | cfg.writeEntry( "server_" + QString::number(srvc++), *it ); | ||
293 | } | ||
294 | cfg.writeEntry( "server_count", srvc ); | ||
295 | } | ||
296 | |||
297 | void PackageManagerSettings::renameInstallationSetting() | ||
298 | { | ||
299 | settingName->setEditable( true ); | ||
300 | } | ||
301 | |||
302 | void PackageManagerSettings::installationSettingSetName(const QString &name) | ||
303 | { | ||
304 | settingName->changeItem( name, settingName->currentItem() ); | ||
305 | } | ||
306 | |||
307 | |||
308 | bool PackageManagerSettings::readIpkgConfig(const QString& conffile) | ||
309 | { | ||
310 | QFile conf(conffile); | ||
311 | if ( conf.open(IO_ReadOnly) ) { | ||
312 | QTextStream s(&conf); | ||
313 | servers->clear(); | ||
314 | activeServers->clear(); | ||
315 | activeDestination->clear(); | ||
316 | activeLinkDestination->clear(); | ||
317 | serverurlDic.clear(); | ||
318 | destinationurlDic.clear(); | ||
319 | ipkg_old=0; | ||
320 | int currentserver=0; | ||
321 | while ( !s.atEnd() ) { | ||
322 | QString l = s.readLine(); | ||
323 | QStringList token = QStringList::split(' ', l); | ||
324 | if ( token[0] == "src" || token[0] == "#src" ) { | ||
325 | currentserver=servers->count(); | ||
326 | serverurlDic.insert(servers->count(),new QString(token[2])); | ||
327 | int a = token[0] == "src" ? 1 : 0; | ||
328 | int i = servers->count(); | ||
329 | servers->insertItem(token[1]); | ||
330 | activeServers->insertItem( token[1] ); | ||
331 | activeServers->setSelected(i,a); | ||
332 | } else if ( token[0] == "dest" ) { | ||
333 | currentserver=destinations->count(); | ||
334 | destinationurlDic.insert(destinations->count(),new QString(token[2])); | ||
335 | destinations->insertItem(token[1]); | ||
336 | activeDestination->insertItem( token[1] ); | ||
337 | activeLinkDestination->insertItem( token[1] ); | ||
338 | |||
339 | } else if ( token[0] == "option" ) { | ||
340 | } else { | ||
341 | // Old style? | ||
342 | int eq = l.find('='); | ||
343 | if ( eq >= 0 ) { | ||
344 | QString v = l.mid(eq+1).stripWhiteSpace(); | ||
345 | if ( v[0] == '"' || v[0] == '\'' ) { | ||
346 | int cl=v.find(v[0],1); | ||
347 | if ( cl >= 0 ) | ||
348 | v = v.mid(1,cl-1); | ||
349 | } | ||
350 | if ( l.left(12) == "IPKG_SOURCE=" ) { | ||
351 | ipkg_old=1; | ||
352 | currentserver=servers->count(); | ||
353 | serverurlDic.insert(servers->count(),new QString(v)); | ||
354 | servers->insertItem(v); | ||
355 | } else if ( l.left(13) == "#IPKG_SOURCE=" ) { | ||
356 | serverurlDic.insert(servers->count(),new QString(v)); | ||
357 | servers->insertItem(v); | ||
358 | } else if ( l.left(10) == "IPKG_ROOT=" ) { | ||
359 | |||
360 | } | ||
361 | } | ||
362 | } | ||
363 | } | ||
364 | if ( ipkg_old ) { | ||
365 | servers->setSelectionMode(QListBox::Single); | ||
366 | servers->setSelected(currentserver,TRUE); | ||
367 | } | ||
368 | return TRUE; | ||
369 | } else { | ||
370 | return FALSE; | ||
371 | } | ||
372 | } | ||
373 | |||
374 | void PackageManagerSettings::readSettings() | ||
375 | { | ||
376 | readIpkgConfig("/etc/ipkg.conf"); | ||
377 | readInstallationSettings(); | ||
378 | } | ||
379 | |||
380 | void PackageManagerSettings::writeSettings() | ||
381 | { | ||
382 | writeIpkgConfig("/etc/ipkg.conf"); | ||
383 | writeInstallationSettings(); | ||
384 | } | ||
385 | |||
386 | bool PackageManagerSettings::showDialog( int i ) | ||
387 | { | ||
388 | TabWidget->setCurrentPage( i ); | ||
389 | showMaximized(); | ||
390 | bool ret = exec(); | ||
391 | if ( ret ) writeSettings(); | ||
392 | else readSettings(); | ||
393 | return ret; | ||
394 | } | ||
395 | |||
396 | QString PackageManagerSettings::getDestinationName() | ||
397 | { | ||
398 | return activeDestination->currentText(); | ||
399 | } | ||
400 | |||
401 | QString PackageManagerSettings::getLinkDestinationName() | ||
402 | { | ||
403 | return activeLinkDestination->currentText(); | ||
404 | } | ||
405 | |||
406 | /** Returns the URL of the active destination */ | ||
407 | QString PackageManagerSettings::getDestinationUrl() | ||
408 | { | ||
409 | int dnr = activeDestination->currentItem(); | ||
410 | return *destinationurlDic.find(dnr); | ||
411 | } | ||
412 | |||
413 | /** Should oipkg create links form install destination to link destination */ | ||
414 | bool PackageManagerSettings::createLinks() | ||
415 | { | ||
416 | return CheckBoxLink->isChecked(); | ||
417 | } | ||
418 | |||
419 | /** get the servers that are active */ | ||
420 | QStringList PackageManagerSettings::getActiveServers() | ||
421 | { | ||
422 | QStringList sl; | ||
423 | for (int i=0; i<(int)activeServers->count(); i++) | ||
424 | { | ||
425 | if ( activeServers->isSelected(i) ) | ||
426 | sl += activeServers->text(i); | ||
427 | } | ||
428 | return sl; | ||
429 | } | ||
430 | |||
431 | /** returns the destination listed in ipkg.conf */ | ||
432 | QStringList PackageManagerSettings::getDestinationUrls() | ||
433 | { | ||
434 | QStringList sl; | ||
435 | for (int i=0; i<(int)destinations->count(); i++) | ||
436 | { | ||
437 | sl += *destinationurlDic[i]; | ||
438 | } | ||
439 | return sl; | ||
440 | } | ||
441 | |||
442 | void PackageManagerSettings::linkEnabled( bool b ) | ||
443 | { | ||
444 | activeLinkDestination->setEnabled( b ); | ||
445 | } | ||
446 | |||
447 | void PackageManagerSettings::activeDestinationChange(int i) | ||
448 | { | ||
449 | activeLinkDestination->setCurrentItem( i ); | ||
450 | } \ No newline at end of file | ||