Diffstat (limited to 'noncore/unsupported/oipkg/pksettings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/oipkg/pksettings.cpp | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/noncore/unsupported/oipkg/pksettings.cpp b/noncore/unsupported/oipkg/pksettings.cpp index be01837..6c8dc2a 100644 --- a/noncore/unsupported/oipkg/pksettings.cpp +++ b/noncore/unsupported/oipkg/pksettings.cpp | |||
@@ -28,12 +28,13 @@ | |||
28 | #include <qtoolbutton.h> | 28 | #include <qtoolbutton.h> |
29 | #include <qtabwidget.h> | 29 | #include <qtabwidget.h> |
30 | 30 | ||
31 | #include <stdlib.h> | 31 | #include <stdlib.h> |
32 | #include <unistd.h> | 32 | #include <unistd.h> |
33 | #include "debug.h" | 33 | #include "debug.h" |
34 | //#include "utils.h" | ||
34 | 35 | ||
35 | PackageManagerSettings::PackageManagerSettings( QWidget* parent, const char* name, WFlags fl ) | 36 | PackageManagerSettings::PackageManagerSettings( QWidget* parent, const char* name, WFlags fl ) |
36 | : PackageManagerSettingsBase( parent, name, fl ) | 37 | : PackageManagerSettingsBase( parent, name, fl ) |
37 | { | 38 | { |
38 | connect( newserver, SIGNAL(clicked()), this, SLOT(newServer()) ); | 39 | connect( newserver, SIGNAL(clicked()), this, SLOT(newServer()) ); |
39 | connect( removeserver, SIGNAL(clicked()), this, SLOT(removeServer()) ); | 40 | connect( removeserver, SIGNAL(clicked()), this, SLOT(removeServer()) ); |
@@ -53,12 +54,13 @@ PackageManagerSettings::PackageManagerSettings( QWidget* parent, const char* na | |||
53 | serverurl->setEnabled(FALSE); | 54 | serverurl->setEnabled(FALSE); |
54 | serverurlDic.setAutoDelete(TRUE); | 55 | serverurlDic.setAutoDelete(TRUE); |
55 | destinationname->setEnabled(FALSE); | 56 | destinationname->setEnabled(FALSE); |
56 | destinationurl->setEnabled(FALSE); | 57 | destinationurl->setEnabled(FALSE); |
57 | destinationurlDic.setAutoDelete(TRUE); | 58 | destinationurlDic.setAutoDelete(TRUE); |
58 | readSettings(); | 59 | readSettings(); |
60 | activeLinkDestination->hide(); | ||
59 | } | 61 | } |
60 | 62 | ||
61 | PackageManagerSettings::~PackageManagerSettings() | 63 | PackageManagerSettings::~PackageManagerSettings() |
62 | { | 64 | { |
63 | } | 65 | } |
64 | 66 | ||
@@ -73,14 +75,16 @@ void PackageManagerSettings::newServer() | |||
73 | } else { | 75 | } else { |
74 | // allows one-level undo | 76 | // allows one-level undo |
75 | serverurlDic.insert(i,new QString(serverurl->text())); | 77 | serverurlDic.insert(i,new QString(serverurl->text())); |
76 | servers->insertItem(servername->text()); | 78 | servers->insertItem(servername->text()); |
77 | activeServers->insertItem(servername->text()); | 79 | activeServers->insertItem(servername->text()); |
78 | } | 80 | } |
81 | changed = true; | ||
79 | servers->setSelected(i,TRUE); | 82 | servers->setSelected(i,TRUE); |
80 | editServer(i); | 83 | editServer(i); |
84 | changed = true; | ||
81 | } | 85 | } |
82 | 86 | ||
83 | void PackageManagerSettings::newDestination() | 87 | void PackageManagerSettings::newDestination() |
84 | { | 88 | { |
85 | int i = destinations->count(); | 89 | int i = destinations->count(); |
86 | if ( destinationname->isEnabled() || destinationurl->text().isEmpty() ) { | 90 | if ( destinationname->isEnabled() || destinationurl->text().isEmpty() ) { |
@@ -94,12 +98,13 @@ void PackageManagerSettings::newDestination() | |||
94 | destinations->insertItem(destinationname->text()); | 98 | destinations->insertItem(destinationname->text()); |
95 | activeDestination->insertItem(destinationname->text()); | 99 | activeDestination->insertItem(destinationname->text()); |
96 | activeLinkDestination->insertItem(destinationname->text()); | 100 | activeLinkDestination->insertItem(destinationname->text()); |
97 | } | 101 | } |
98 | destinations->setSelected(i,TRUE); | 102 | destinations->setSelected(i,TRUE); |
99 | editDestination(i); | 103 | editDestination(i); |
104 | changed = true; | ||
100 | } | 105 | } |
101 | 106 | ||
102 | 107 | ||
103 | void PackageManagerSettings::editServer(int i) | 108 | void PackageManagerSettings::editServer(int i) |
104 | { | 109 | { |
105 | if ( servername->isEnabled() ) { | 110 | if ( servername->isEnabled() ) { |
@@ -114,12 +119,13 @@ void PackageManagerSettings::editServer(int i) | |||
114 | serverurl->setText( *serverurlDic[i] ); | 119 | serverurl->setText( *serverurlDic[i] ); |
115 | 120 | ||
116 | editedserver = i; | 121 | editedserver = i; |
117 | 122 | ||
118 | connect( servername, SIGNAL(textChanged(const QString&)), this, SLOT(serverNameChanged(const QString&)) ); | 123 | connect( servername, SIGNAL(textChanged(const QString&)), this, SLOT(serverNameChanged(const QString&)) ); |
119 | connect( serverurl, SIGNAL(textChanged(const QString&)), this, SLOT(serverUrlChanged(const QString&)) ); | 124 | connect( serverurl, SIGNAL(textChanged(const QString&)), this, SLOT(serverUrlChanged(const QString&)) ); |
125 | changed = true; | ||
120 | } | 126 | } |
121 | 127 | ||
122 | 128 | ||
123 | void PackageManagerSettings::editDestination(int i) | 129 | void PackageManagerSettings::editDestination(int i) |
124 | { | 130 | { |
125 | if ( destinationname->isEnabled() ) { | 131 | if ( destinationname->isEnabled() ) { |
@@ -134,12 +140,13 @@ void PackageManagerSettings::editDestination(int i) | |||
134 | destinationurl->setText( *destinationurlDic[i] ); | 140 | destinationurl->setText( *destinationurlDic[i] ); |
135 | 141 | ||
136 | editeddestination = i; | 142 | editeddestination = i; |
137 | 143 | ||
138 | connect( destinationname, SIGNAL(textChanged(const QString&)), this, SLOT(destNameChanged(const QString&)) ); | 144 | connect( destinationname, SIGNAL(textChanged(const QString&)), this, SLOT(destNameChanged(const QString&)) ); |
139 | connect( destinationurl, SIGNAL(textChanged(const QString&)), this, SLOT(destUrlChanged(const QString&)) ); | 145 | connect( destinationurl, SIGNAL(textChanged(const QString&)), this, SLOT(destUrlChanged(const QString&)) ); |
146 | changed = true; | ||
140 | } | 147 | } |
141 | 148 | ||
142 | void PackageManagerSettings::removeServer() | 149 | void PackageManagerSettings::removeServer() |
143 | { | 150 | { |
144 | disconnect( servername, SIGNAL(textChanged(const QString&)), this, SLOT(serverNameChanged(const QString&)) ); | 151 | disconnect( servername, SIGNAL(textChanged(const QString&)), this, SLOT(serverNameChanged(const QString&)) ); |
145 | disconnect( serverurl, SIGNAL(textChanged(const QString&)), this, SLOT(serverUrlChanged(const QString&)) ); | 152 | disconnect( serverurl, SIGNAL(textChanged(const QString&)), this, SLOT(serverUrlChanged(const QString&)) ); |
@@ -148,12 +155,13 @@ void PackageManagerSettings::removeServer() | |||
148 | disconnect( servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) ); | 155 | disconnect( servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) ); |
149 | servers->removeItem(editedserver); | 156 | servers->removeItem(editedserver); |
150 | activeServers->removeItem(editedserver); | 157 | activeServers->removeItem(editedserver); |
151 | connect( servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) ); | 158 | connect( servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) ); |
152 | servername->setEnabled(FALSE); | 159 | servername->setEnabled(FALSE); |
153 | serverurl->setEnabled(FALSE); | 160 | serverurl->setEnabled(FALSE); |
161 | changed = true; | ||
154 | } | 162 | } |
155 | 163 | ||
156 | void PackageManagerSettings::removeDestination() | 164 | void PackageManagerSettings::removeDestination() |
157 | { | 165 | { |
158 | disconnect( destinationname, SIGNAL(textChanged(const QString&)), this, SLOT(destNameChanged(const QString&)) ); | 166 | disconnect( destinationname, SIGNAL(textChanged(const QString&)), this, SLOT(destNameChanged(const QString&)) ); |
159 | disconnect( destinationurl, SIGNAL(textChanged(const QString&)), this, SLOT(destUrlChanged(const QString&)) ); | 167 | disconnect( destinationurl, SIGNAL(textChanged(const QString&)), this, SLOT(destUrlChanged(const QString&)) ); |
@@ -163,39 +171,45 @@ void PackageManagerSettings::removeDestination() | |||
163 | destinations->removeItem(editeddestination); | 171 | destinations->removeItem(editeddestination); |
164 | activeDestination->removeItem(editeddestination); | 172 | activeDestination->removeItem(editeddestination); |
165 | activeLinkDestination->removeItem(editeddestination); | 173 | activeLinkDestination->removeItem(editeddestination); |
166 | connect( destinations, SIGNAL(highlighted(int)), this, SLOT(editDestination(int)) ); | 174 | connect( destinations, SIGNAL(highlighted(int)), this, SLOT(editDestination(int)) ); |
167 | destinationname->setEnabled(FALSE); | 175 | destinationname->setEnabled(FALSE); |
168 | destinationurl->setEnabled(FALSE); | 176 | destinationurl->setEnabled(FALSE); |
177 | changed = true; | ||
169 | } | 178 | } |
170 | 179 | ||
171 | void PackageManagerSettings::serverNameChanged(const QString& t) | 180 | void PackageManagerSettings::serverNameChanged(const QString& t) |
172 | { | 181 | { |
173 | disconnect( servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) ); | 182 | disconnect( servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) ); |
174 | servers->changeItem( t, editedserver ); | 183 | servers->changeItem( t, editedserver ); |
175 | activeServers->changeItem( t, editedserver ); | 184 | activeServers->changeItem( t, editedserver ); |
185 | changed = true; | ||
176 | connect( servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) ); | 186 | connect( servers, SIGNAL(highlighted(int)), this, SLOT(editServer(int)) ); |
187 | changed = true; | ||
177 | } | 188 | } |
178 | 189 | ||
179 | void PackageManagerSettings::destNameChanged(const QString& t) | 190 | void PackageManagerSettings::destNameChanged(const QString& t) |
180 | { | 191 | { |
181 | disconnect( destinations, SIGNAL(highlighted(int)), this, SLOT(editDestination(int)) ); | 192 | disconnect( destinations, SIGNAL(highlighted(int)), this, SLOT(editDestination(int)) ); |
182 | destinations->changeItem( t, editeddestination ); | 193 | destinations->changeItem( t, editeddestination ); |
183 | activeDestination->changeItem( t, editeddestination ); | 194 | activeDestination->changeItem( t, editeddestination ); |
184 | activeLinkDestination->changeItem( t, editeddestination ); | 195 | activeLinkDestination->changeItem( t, editeddestination ); |
185 | connect( destinations, SIGNAL(highlighted(int)), this, SLOT(editDestination(int)) ); | 196 | connect( destinations, SIGNAL(highlighted(int)), this, SLOT(editDestination(int)) ); |
197 | changed = true; | ||
186 | } | 198 | } |
187 | 199 | ||
188 | void PackageManagerSettings::serverUrlChanged(const QString& t) | 200 | void PackageManagerSettings::serverUrlChanged(const QString& t) |
189 | { | 201 | { |
190 | serverurlDic.replace(editedserver, new QString(t)); | 202 | serverurlDic.replace(editedserver, new QString(t)); |
203 | changed = true; | ||
191 | } | 204 | } |
192 | 205 | ||
193 | void PackageManagerSettings::destUrlChanged(const QString& t) | 206 | void PackageManagerSettings::destUrlChanged(const QString& t) |
194 | { | 207 | { |
195 | destinationurlDic.replace(editeddestination, new QString(t)); | 208 | destinationurlDic.replace(editeddestination, new QString(t)); |
209 | changed = true; | ||
196 | } | 210 | } |
197 | 211 | ||
198 | void PackageManagerSettings::writeIpkgConfig(const QString& conffile) | 212 | void PackageManagerSettings::writeIpkgConfig(const QString& conffile) |
199 | { | 213 | { |
200 | QFile conf(conffile); | 214 | QFile conf(conffile); |
201 | if ( ! conf.open(IO_WriteOnly) ) return; | 215 | if ( ! conf.open(IO_WriteOnly) ) return; |
@@ -262,17 +276,17 @@ void PackageManagerSettings::newInstallationSetting() | |||
262 | 276 | ||
263 | void PackageManagerSettings::installationSettingChange(int cs) | 277 | void PackageManagerSettings::installationSettingChange(int cs) |
264 | { | 278 | { |
265 | writeCurrentInstallationSetting(); | 279 | writeCurrentInstallationSetting(); |
266 | currentSetting = cs; | 280 | currentSetting = cs; |
267 | readInstallationSetting( cs ); | 281 | readInstallationSetting( cs ); |
282 | changed = true; | ||
268 | } | 283 | } |
269 | 284 | ||
270 | void PackageManagerSettings::writeInstallationSettings() | 285 | void PackageManagerSettings::writeInstallationSettings() |
271 | { | 286 | { |
272 | if ( ! changed ) return ; | ||
273 | { | 287 | { |
274 | Config cfg( "oipkg", Config::User ); | 288 | Config cfg( "oipkg", Config::User ); |
275 | cfg.setGroup( "Settings" ); | 289 | cfg.setGroup( "Settings" ); |
276 | cfg.writeEntry( "count", installationSettingsCount ); | 290 | cfg.writeEntry( "count", installationSettingsCount ); |
277 | cfg.writeEntry( "current", currentSetting ); | 291 | cfg.writeEntry( "current", currentSetting ); |
278 | } | 292 | } |
@@ -282,31 +296,29 @@ void PackageManagerSettings::writeInstallationSettings() | |||
282 | 296 | ||
283 | void PackageManagerSettings::readInstallationSetting(int setting) | 297 | void PackageManagerSettings::readInstallationSetting(int setting) |
284 | { | 298 | { |
285 | if ( setting < 0 ) return; | 299 | if ( setting < 0 ) return; |
286 | Config cfg( "oipkg", Config::User ); | 300 | Config cfg( "oipkg", Config::User ); |
287 | cfg.setGroup( "Setting_" + QString::number( setting ) ); | 301 | cfg.setGroup( "Setting_" + QString::number( setting ) ); |
288 | CheckBoxLink->setChecked( cfg.readBoolEntry( "link", false ) ); | 302 | CheckBoxLink->setChecked( cfg.readBoolEntry( "link", true ) ); |
289 | QString dest = cfg.readEntry( "dest" ); | 303 | QString dest = cfg.readEntry( "dest" ); |
290 | QString linkdest = cfg.readEntry( "linkdest" ); | 304 | QString linkdest = cfg.readEntry( "linkdest" ); |
291 | pvDebug(3, "dest="+dest); | 305 | pvDebug(3, "dest="+dest); |
292 | pvDebug(3, "linkdest="+linkdest); | 306 | pvDebug(3, "linkdest="+linkdest); |
293 | |||
294 | for ( int i = 0; i < activeDestination->count(); i++) | 307 | for ( int i = 0; i < activeDestination->count(); i++) |
295 | { | 308 | { |
296 | if ( activeDestination->text( i ) == dest ) | 309 | if ( activeDestination->text( i ) == dest ) |
297 | activeDestination->setCurrentItem( i ); | 310 | activeDestination->setCurrentItem( i ); |
298 | if ( activeLinkDestination->text( i ) == linkdest ) | 311 | if ( activeLinkDestination->text( i ) == linkdest ) |
299 | activeLinkDestination->setCurrentItem( i ); | 312 | activeLinkDestination->setCurrentItem( i ); |
300 | } | 313 | } |
301 | } | 314 | } |
302 | 315 | ||
303 | void PackageManagerSettings::writeCurrentInstallationSetting() | 316 | void PackageManagerSettings::writeCurrentInstallationSetting() |
304 | { | 317 | { |
305 | Config cfg( "oipkg", Config::User ); | 318 | Config cfg( "oipkg", Config::User ); |
306 | changed = false; | ||
307 | cfg.setGroup( "Setting_" + QString::number(currentSetting) ); | 319 | cfg.setGroup( "Setting_" + QString::number(currentSetting) ); |
308 | cfg.writeEntry( "link", CheckBoxLink->isChecked() ); | 320 | cfg.writeEntry( "link", CheckBoxLink->isChecked() ); |
309 | cfg.writeEntry( "dest", getDestinationName() ); | 321 | cfg.writeEntry( "dest", getDestinationName() ); |
310 | cfg.writeEntry( "linkdest" , getLinkDestinationName() ); | 322 | cfg.writeEntry( "linkdest" , getLinkDestinationName() ); |
311 | QStringList sers = getActiveServers(); | 323 | QStringList sers = getActiveServers(); |
312 | int srvc = 0; | 324 | int srvc = 0; |
@@ -329,12 +341,13 @@ void PackageManagerSettings::installationSettingSetName(const QString &name) | |||
329 | } | 341 | } |
330 | 342 | ||
331 | 343 | ||
332 | bool PackageManagerSettings::readIpkgConfig(const QString& conffile) | 344 | bool PackageManagerSettings::readIpkgConfig(const QString& conffile) |
333 | { | 345 | { |
334 | QFile conf(conffile); | 346 | QFile conf(conffile); |
347 | changed = false; | ||
335 | if ( conf.open(IO_ReadOnly) ) { | 348 | if ( conf.open(IO_ReadOnly) ) { |
336 | QTextStream s(&conf); | 349 | QTextStream s(&conf); |
337 | servers->clear(); | 350 | servers->clear(); |
338 | activeServers->clear(); | 351 | activeServers->clear(); |
339 | activeDestination->clear(); | 352 | activeDestination->clear(); |
340 | activeLinkDestination->clear(); | 353 | activeLinkDestination->clear(); |
@@ -421,24 +434,24 @@ void PackageManagerSettings::readSettings() | |||
421 | readIpkgConfig("/etc/ipkg.conf"); | 434 | readIpkgConfig("/etc/ipkg.conf"); |
422 | readInstallationSettings(); | 435 | readInstallationSettings(); |
423 | } | 436 | } |
424 | 437 | ||
425 | void PackageManagerSettings::writeSettings() | 438 | void PackageManagerSettings::writeSettings() |
426 | { | 439 | { |
427 | writeIpkgConfig("/etc/ipkg.conf"); | 440 | if ( changed ) writeIpkgConfig("/etc/ipkg.conf"); |
428 | writeInstallationSettings(); | 441 | writeInstallationSettings(); |
429 | } | 442 | } |
430 | /** shows the setting dialog */ | 443 | /** shows the setting dialog */ |
431 | bool PackageManagerSettings::showDialog( int i ) | 444 | bool PackageManagerSettings::showDialog( int i ) |
432 | { | 445 | { |
433 | TabWidget->setCurrentPage( i ); | 446 | TabWidget->setCurrentPage( i ); |
434 | showMaximized(); | 447 | showMaximized(); |
435 | bool ret = exec(); | 448 | bool ret = exec(); |
436 | if ( ret ) writeSettings(); | 449 | if ( ret ) writeSettings(); |
437 | else readSettings(); | 450 | else readSettings(); |
438 | return ret; | 451 | return (changed && ret); |
439 | } | 452 | } |
440 | /** Returns the installation destination */ | 453 | /** Returns the installation destination */ |
441 | QString PackageManagerSettings::getDestinationName() | 454 | QString PackageManagerSettings::getDestinationName() |
442 | { | 455 | { |
443 | return activeDestination->currentText(); | 456 | return activeDestination->currentText(); |
444 | } | 457 | } |
@@ -466,12 +479,21 @@ QStringList PackageManagerSettings::getActiveServers() | |||
466 | { | 479 | { |
467 | if ( activeServers->isSelected(i) ) | 480 | if ( activeServers->isSelected(i) ) |
468 | sl += activeServers->text(i); | 481 | sl += activeServers->text(i); |
469 | } | 482 | } |
470 | return sl; | 483 | return sl; |
471 | } | 484 | } |
485 | QStringList PackageManagerSettings::getServers() | ||
486 | { | ||
487 | QStringList sl; | ||
488 | for (int i=0; i<(int)activeServers->count(); i++) | ||
489 | { | ||
490 | sl += activeServers->text(i); | ||
491 | } | ||
492 | return sl; | ||
493 | } | ||
472 | 494 | ||
473 | /** returns the destination listed in ipkg.conf */ | 495 | /** returns the destination listed in ipkg.conf */ |
474 | QStringList PackageManagerSettings::getDestinationUrls() | 496 | QStringList PackageManagerSettings::getDestinationUrls() |
475 | { | 497 | { |
476 | QStringList sl; | 498 | QStringList sl; |
477 | for (int i=0; i<(int)destinations->count(); i++) | 499 | for (int i=0; i<(int)destinations->count(); i++) |
@@ -503,9 +525,18 @@ QStringList PackageManagerSettings::getDestinationNames() | |||
503 | return sl; | 525 | return sl; |
504 | } | 526 | } |
505 | 527 | ||
506 | 528 | ||
507 | void PackageManagerSettings::linkEnabled( bool b ) | 529 | void PackageManagerSettings::linkEnabled( bool b ) |
508 | { | 530 | { |
509 | changed = true; | ||
510 | activeLinkDestination->setEnabled( b ); | 531 | activeLinkDestination->setEnabled( b ); |
511 | } | 532 | } |
533 | |||
534 | void PackageManagerSettings::activeServerChanged() | ||
535 | { | ||
536 | changed = true; | ||
537 | } | ||
538 | |||
539 | QComboBox* PackageManagerSettings::getDestCombo() | ||
540 | { | ||
541 | return new QComboBox(activeDestination); | ||
542 | } | ||