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