Diffstat (limited to 'noncore/settings/aqpkg/settingsimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/aqpkg/settingsimpl.cpp | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/noncore/settings/aqpkg/settingsimpl.cpp b/noncore/settings/aqpkg/settingsimpl.cpp new file mode 100644 index 0000000..81e89ed --- a/dev/null +++ b/noncore/settings/aqpkg/settingsimpl.cpp | |||
@@ -0,0 +1,195 @@ | |||
1 | /*************************************************************************** | ||
2 | settingsimpl.cpp - description | ||
3 | ------------------- | ||
4 | begin : Thu Aug 29 2002 | ||
5 | copyright : (C) 2002 by Andy Qua | ||
6 | email : andy.qua@blueyonder.co.uk | ||
7 | ***************************************************************************/ | ||
8 | |||
9 | /*************************************************************************** | ||
10 | * * | ||
11 | * This program is free software; you can redistribute it and/or modify * | ||
12 | * it under the terms of the GNU General Public License as published by * | ||
13 | * the Free Software Foundation; either version 2 of the License, or * | ||
14 | * (at your option) any later version. * | ||
15 | * * | ||
16 | ***************************************************************************/ | ||
17 | |||
18 | #include <fstream> | ||
19 | using namespace std; | ||
20 | |||
21 | #include <qlistbox.h> | ||
22 | #include <qlineedit.h> | ||
23 | #include <qpushbutton.h> | ||
24 | #include <qtabwidget.h> | ||
25 | |||
26 | #include "settingsimpl.h" | ||
27 | |||
28 | #include "global.h" | ||
29 | |||
30 | SettingsImpl :: SettingsImpl( DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl ) | ||
31 | : SettingsBase( parent, name, modal, fl ) | ||
32 | { | ||
33 | dataMgr = dataManager; | ||
34 | |||
35 | setupData(); | ||
36 | changed = false; | ||
37 | newserver = false; | ||
38 | newdestination = false; | ||
39 | } | ||
40 | |||
41 | SettingsImpl :: ~SettingsImpl() | ||
42 | { | ||
43 | |||
44 | } | ||
45 | |||
46 | bool SettingsImpl :: showDlg( int i ) | ||
47 | { | ||
48 | TabWidget->setCurrentPage( i ); | ||
49 | showMaximized(); | ||
50 | exec(); | ||
51 | |||
52 | if ( changed ) | ||
53 | dataMgr->writeOutIpkgConf(); | ||
54 | |||
55 | return changed; | ||
56 | } | ||
57 | |||
58 | void SettingsImpl :: setupData() | ||
59 | { | ||
60 | // add servers | ||
61 | vector<Server>::iterator it; | ||
62 | for ( it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it ) | ||
63 | { | ||
64 | if ( it->getServerName() == LOCAL_SERVER || it->getServerName() == LOCAL_IPKGS ) | ||
65 | continue; | ||
66 | |||
67 | servers->insertItem( it->getServerName() ); | ||
68 | } | ||
69 | |||
70 | // add destinations | ||
71 | vector<Destination>::iterator it2; | ||
72 | for ( it2 = dataMgr->getDestinationList().begin() ; it2 != dataMgr->getDestinationList().end() ; ++it2 ) | ||
73 | destinations->insertItem( it2->getDestinationName() ); | ||
74 | |||
75 | } | ||
76 | |||
77 | //------------------ Servers tab ---------------------- | ||
78 | |||
79 | void SettingsImpl :: editServer( int sel ) | ||
80 | { | ||
81 | currentSelectedServer = sel; | ||
82 | Server *s = dataMgr->getServer( servers->currentText() ); | ||
83 | serverName = s->getServerName(); | ||
84 | servername->setText( s->getServerName() ); | ||
85 | serverurl->setText( s->getServerUrl() ); | ||
86 | } | ||
87 | |||
88 | void SettingsImpl :: newServer() | ||
89 | { | ||
90 | newserver = true; | ||
91 | servername->setText( "" ); | ||
92 | serverurl->setText( "" ); | ||
93 | servername->setFocus(); | ||
94 | } | ||
95 | |||
96 | void SettingsImpl :: removeServer() | ||
97 | { | ||
98 | changed = true; | ||
99 | Server *s = dataMgr->getServer( servers->currentText() ); | ||
100 | dataMgr->getServerList().erase( s ); | ||
101 | servers->removeItem( currentSelectedServer ); | ||
102 | } | ||
103 | |||
104 | void SettingsImpl :: changeServerDetails() | ||
105 | { | ||
106 | changed = true; | ||
107 | |||
108 | QString newName = servername->text(); | ||
109 | if ( !newserver ) | ||
110 | { | ||
111 | Server *s = dataMgr->getServer( serverName ); | ||
112 | |||
113 | // Update url | ||
114 | s->setServerUrl( serverurl->text() ); | ||
115 | |||
116 | // Check if server name has changed, if it has then we need to replace the key in the map | ||
117 | if ( serverName != newName ) | ||
118 | { | ||
119 | // Update server name | ||
120 | s->setServerName( newName ); | ||
121 | |||
122 | // See if this server is the active server | ||
123 | if ( dataMgr->getActiveServer() == serverName ) | ||
124 | dataMgr->setActiveServer( newName ); | ||
125 | |||
126 | // Update list box | ||
127 | servers->changeItem( newName, currentSelectedServer ); | ||
128 | } | ||
129 | } | ||
130 | else | ||
131 | { | ||
132 | dataMgr->getServerList().push_back( Server( newName, serverurl->text() ) ); | ||
133 | servers->insertItem( newName ); | ||
134 | servers->setCurrentItem( servers->count() ); | ||
135 | newserver = false; | ||
136 | } | ||
137 | } | ||
138 | |||
139 | //------------------ Destinations tab ---------------------- | ||
140 | |||
141 | void SettingsImpl :: editDestination( int sel ) | ||
142 | { | ||
143 | currentSelectedDestination = sel; | ||
144 | Destination *s = dataMgr->getDestination( destinations->currentText() ); | ||
145 | destinationName = s->getDestinationName(); | ||
146 | destinationname->setText( s->getDestinationName() ); | ||
147 | destinationurl->setText( s->getDestinationPath() ); | ||
148 | } | ||
149 | |||
150 | void SettingsImpl :: newDestination() | ||
151 | { | ||
152 | newdestination = true; | ||
153 | destinationname->setText( "" ); | ||
154 | destinationurl->setText( "" ); | ||
155 | destinationname->setFocus(); | ||
156 | } | ||
157 | |||
158 | void SettingsImpl :: removeDestination() | ||
159 | { | ||
160 | changed = true; | ||
161 | Destination *d = dataMgr->getDestination( destinations->currentText() ); | ||
162 | dataMgr->getDestinationList().erase( d ); | ||
163 | destinations->removeItem( currentSelectedDestination ); | ||
164 | } | ||
165 | |||
166 | void SettingsImpl :: changeDestinationDetails() | ||
167 | { | ||
168 | changed = true; | ||
169 | |||
170 | QString newName = destinationname->text(); | ||
171 | if ( !newdestination ) | ||
172 | { | ||
173 | Destination *d = dataMgr->getDestination( destinationName ); | ||
174 | |||
175 | // Update url | ||
176 | d->setDestinationPath( destinationurl->text() ); | ||
177 | |||
178 | // Check if server name has changed, if it has then we need to replace the key in the map | ||
179 | if ( destinationName != newName ) | ||
180 | { | ||
181 | // Update server name | ||
182 | d->setDestinationName( newName ); | ||
183 | |||
184 | // Update list box | ||
185 | destinations->changeItem( newName, currentSelectedDestination ); | ||
186 | } | ||
187 | } | ||
188 | else | ||
189 | { | ||
190 | dataMgr->getDestinationList().push_back( Destination( newName, destinationurl->text() ) ); | ||
191 | destinations->insertItem( newName ); | ||
192 | destinations->setCurrentItem( destinations->count() ); | ||
193 | newdestination = false; | ||
194 | } | ||
195 | } | ||