-rw-r--r-- | noncore/settings/tabmanager/tabmanager.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/noncore/settings/tabmanager/tabmanager.cpp b/noncore/settings/tabmanager/tabmanager.cpp index af76251..f54c837 100644 --- a/noncore/settings/tabmanager/tabmanager.cpp +++ b/noncore/settings/tabmanager/tabmanager.cpp | |||
@@ -1,480 +1,483 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | =. This file is part of the OPIE Project | 3 | =. This file is part of the OPIE Project |
4 | .=l. Copyright (c) 2002 Benjamin Meyer <meyerb@sharpsec.com> | 4 | .=l. Copyright (c) 2002 Benjamin Meyer <meyerb@sharpsec.com> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This library is free software; you can | 6 | _;:, .> :=|. This library is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This library is distributed in the hope that | 13 | .i_,=:_. -<s. This library is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | 27 | ||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "tabmanager.h" | 30 | #include "tabmanager.h" |
31 | #include "app.h" | 31 | #include "app.h" |
32 | #include "tabapplnk.h" | 32 | #include "tabapplnk.h" |
33 | 33 | ||
34 | #include <qpe/applnk.h> | 34 | #include <qpe/applnk.h> |
35 | #include <qpe/qpeapplication.h> | 35 | #include <qpe/qpeapplication.h> |
36 | #include <qdir.h> | 36 | #include <qdir.h> |
37 | #include <qfile.h> | 37 | #include <qfile.h> |
38 | #include <qtextstream.h> | 38 | #include <qtextstream.h> |
39 | #include <qlistview.h> | 39 | #include <qlistview.h> |
40 | #include <qheader.h> | 40 | #include <qheader.h> |
41 | #include <qlineedit.h> | 41 | #include <qlineedit.h> |
42 | #include <qlabel.h> | 42 | #include <qlabel.h> |
43 | #include <qmessagebox.h> | 43 | #include <qmessagebox.h> |
44 | #include <stdlib.h> | 44 | #include <stdlib.h> |
45 | #include <qpe/qcopenvelope_qws.h> | 45 | #include <qpe/qcopenvelope_qws.h> |
46 | 46 | ||
47 | #define HOME_APP_DIR QPEApplication::qpeDir()+"/apps" // <-- made this a little more flexible | 47 | #define HOME_APP_DIR QPEApplication::qpeDir()+"/apps" // <-- made this a little more flexible |
48 | #define HOME_APP_INSTALL_DIR "/usr/lib/ipkg/info" | 48 | #define HOME_APP_INSTALL_DIR "/usr/lib/ipkg/info" |
49 | #define NEW_FOLDER "EmptyTab" | 49 | #define NEW_FOLDER "EmptyTab" |
50 | #define NEW_APPLICATION "NewApp" | 50 | #define NEW_APPLICATION "NewApp" |
51 | #define APPLICATION_EXTENSION ".desktop" | 51 | #define APPLICATION_EXTENSION ".desktop" |
52 | #define APPLICATION_EXTENSION_LENGTH 8 | 52 | #define APPLICATION_EXTENSION_LENGTH 8 |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Constructor. Sets up signals. Performs initial scan of applications | 55 | * Constructor. Sets up signals. Performs initial scan of applications |
56 | * and tabs | 56 | * and tabs |
57 | */ | 57 | */ |
58 | TabManager::TabManager( QWidget* parent, const char* name):TabManagerBase(parent, name), changed(false){ | 58 | TabManager::TabManager( QWidget* parent, const char* name):TabManagerBase(parent, name), changed(false){ |
59 | rescanFolder(HOME_APP_DIR); | 59 | rescanFolder(HOME_APP_DIR); |
60 | 60 | ||
61 | // Connect the signals and slots | 61 | // Connect the signals and slots |
62 | connect(tabList, SIGNAL(doubleClicked(QListViewItem *)), | 62 | connect(tabList, SIGNAL(doubleClicked(QListViewItem *)), |
63 | this, SLOT(editItem(QListViewItem*))); | 63 | this, SLOT(editItem(QListViewItem*))); |
64 | (tabList->header())->hide(); | 64 | (tabList->header())->hide(); |
65 | connect(tabList, SIGNAL(moveItem(QListViewItem *, QListViewItem *)), | 65 | connect(tabList, SIGNAL(moveItem(QListViewItem *, QListViewItem *)), |
66 | this, SLOT(moveApplication(QListViewItem *, QListViewItem *))); | 66 | this, SLOT(moveApplication(QListViewItem *, QListViewItem *))); |
67 | } | 67 | } |
68 | 68 | ||
69 | /** | 69 | /** |
70 | * If anything in the tab's have been changed then update the system or alert | 70 | * If anything in the tab's have been changed then update the system or alert |
71 | * the user. | 71 | * the user. |
72 | */ | 72 | */ |
73 | TabManager::~TabManager(){ | 73 | TabManager::~TabManager(){ |
74 | if(changed){ | 74 | if(changed){ |
75 | //QMessageBox::critical(this, tr("Message"), tr("Please restart Qtopia to see all new changes."),tr("Ok") ); | 75 | //QMessageBox::critical(this, tr("Message"), tr("Please restart Qtopia to see all new changes."),tr("Ok") ); |
76 | //filename = fn; | 76 | //filename = fn; |
77 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 77 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
78 | //e << description << filename << mimetype; | 78 | //e << description << filename << mimetype; |
79 | QString link; //we'll just send an empty string | 79 | QString link; //we'll just send an empty string |
80 | e << link; | 80 | e << link; |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | /** | 84 | /** |
85 | * Scans root directory for any tabs or applications. Will recursivly go down, | 85 | * Scans root directory for any tabs or applications. Will recursivly go down, |
86 | * but will not follow symlinks. | 86 | * but will not follow symlinks. |
87 | * @param directory - the directory to look in. | 87 | * @param directory - the directory to look in. |
88 | * @param parent - the parent to place any new tabs or apps into. If parent is | 88 | * @param parent - the parent to place any new tabs or apps into. If parent is |
89 | * NULL then the item is a tab and should be placed as a child of the window. | 89 | * NULL then the item is a tab and should be placed as a child of the window. |
90 | */ | 90 | */ |
91 | void TabManager::rescanFolder(QString directory, QListViewItem* parent){ | 91 | void TabManager::rescanFolder(QString directory, QListViewItem* parent){ |
92 | //qDebug(QString("rescanFolder: ") + directory.latin1()); | 92 | //qDebug(QString("rescanFolder: ") + directory.latin1()); |
93 | 93 | ||
94 | QDir d; | 94 | QDir d; |
95 | d.setPath(directory); | 95 | d.setPath(directory); |
96 | // Show hidden files for .directories | 96 | // Show hidden files for .directories |
97 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); | 97 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); |
98 | 98 | ||
99 | const QFileInfoList *list = d.entryInfoList(); | 99 | const QFileInfoList *list = d.entryInfoList(); |
100 | QFileInfoListIterator it( *list ); // create list iterator | 100 | QFileInfoListIterator it( *list ); // create list iterator |
101 | QFileInfo *fi; // pointer for traversing | 101 | QFileInfo *fi; // pointer for traversing |
102 | 102 | ||
103 | while ( (fi=it.current()) ) { // for each file... | 103 | while ( (fi=it.current()) ) { // for each file... |
104 | // If it is a dir and not .. or . then add it as a tab and go down. | 104 | // If it is a dir and not .. or . then add it as a tab and go down. |
105 | if(fi->isDir()){ | 105 | if(fi->isDir()){ |
106 | if(fi->fileName() != ".." && fi->fileName() != ".") { | 106 | if(fi->fileName() != ".." && fi->fileName() != ".") { |
107 | QListViewItem* newItem; | 107 | QListViewItem* newItem; |
108 | if(!parent) | 108 | if(!parent) |
109 | newItem = new QListViewItem(tabList, fi->fileName()); | 109 | newItem = new QListViewItem(tabList, fi->fileName()); |
110 | else | 110 | else |
111 | newItem = new QListViewItem(parent, fi->fileName()); | 111 | newItem = new QListViewItem(parent, fi->fileName()); |
112 | itemList.insert(newItem, directory + "/" + fi->fileName() + "/.directory" ); | 112 | itemList.insert(newItem, directory + "/" + fi->fileName() + "/.directory" ); |
113 | rescanFolder(directory + "/" + fi->fileName(), newItem); | 113 | rescanFolder(directory + "/" + fi->fileName(), newItem); |
114 | } | 114 | } |
115 | } | 115 | } |
116 | else{ | 116 | else{ |
117 | // it is a file, if not a .directory add to parent. | 117 | // it is a file, if not a .directory add to parent. |
118 | 118 | ||
119 | // Change parents name and icon to reflect icon. | 119 | // Change parents name and icon to reflect icon. |
120 | if(fi->fileName() == ".directory"){ | 120 | if(fi->fileName() == ".directory"){ |
121 | AppLnk app(directory + "/" + fi->fileName()); | 121 | AppLnk app(directory + "/" + fi->fileName()); |
122 | if(parent){ | 122 | if(parent){ |
123 | parent->setPixmap(0,app.pixmap()); | 123 | parent->setPixmap(0,app.pixmap()); |
124 | parent->setText(0, app.name()); | 124 | parent->setText(0, app.name()); |
125 | } | 125 | } |
126 | } | 126 | } |
127 | else{ | 127 | else{ |
128 | // Add any desktop files found. | 128 | // Add any desktop files found. |
129 | QListViewItem* newItem; | 129 | QListViewItem* newItem; |
130 | if(directory != HOME_APP_DIR){ | 130 | if(directory != HOME_APP_DIR){ |
131 | if(!parent) | 131 | if(!parent) |
132 | newItem = new QListViewItem(tabList, fi->fileName()); | 132 | newItem = new QListViewItem(tabList, fi->fileName()); |
133 | else | 133 | else |
134 | newItem = new QListViewItem(parent, fi->fileName()); | 134 | newItem = new QListViewItem(parent, fi->fileName()); |
135 | if(fi->fileName().right(APPLICATION_EXTENSION_LENGTH) == APPLICATION_EXTENSION){ | 135 | if(fi->fileName().right(APPLICATION_EXTENSION_LENGTH) == APPLICATION_EXTENSION){ |
136 | AppLnk app(directory + "/" + fi->fileName()); | 136 | AppLnk app(directory + "/" + fi->fileName()); |
137 | newItem->setPixmap(0,app.pixmap()); | 137 | newItem->setPixmap(0,app.pixmap()); |
138 | newItem->setText(0, app.name()); | 138 | newItem->setText(0, app.name()); |
139 | itemList.insert(newItem, directory + "/" + fi->fileName()); | 139 | itemList.insert(newItem, directory + "/" + fi->fileName()); |
140 | } | 140 | } |
141 | } | 141 | } |
142 | } | 142 | } |
143 | } | 143 | } |
144 | ++it; // goto next list element | 144 | ++it; // goto next list element |
145 | } | 145 | } |
146 | } | 146 | } |
147 | 147 | ||
148 | /** | 148 | /** |
149 | * Create a new blank Tab. | 149 | * Create a new blank Tab. |
150 | * Create a physical folder with .directory file | 150 | * Create a physical folder with .directory file |
151 | * Create a item on the list | 151 | * Create a item on the list |
152 | */ | 152 | */ |
153 | void TabManager::newFolder(){ | 153 | void TabManager::newFolder(){ |
154 | QDir r; | 154 | QDir r; |
155 | r.mkdir(QString(HOME_APP_DIR) + "/" + NEW_FOLDER); | 155 | r.mkdir(QString(HOME_APP_DIR) + "/" + NEW_FOLDER); |
156 | system((QString("echo [Desktop Entry] | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); | 156 | system((QString("echo [Desktop Entry] | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); |
157 | system((QString("echo Name=" NEW_FOLDER " | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); | 157 | system((QString("echo Name=" NEW_FOLDER " | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); |
158 | 158 | ||
159 | QString homeLocation = QString(HOME_APP_DIR) + "/" + NEW_FOLDER + "/.directory"; | 159 | QString homeLocation = QString(HOME_APP_DIR) + "/" + NEW_FOLDER + "/.directory"; |
160 | QListViewItem *newItem = new QListViewItem(tabList, NEW_FOLDER); | 160 | QListViewItem *newItem = new QListViewItem(tabList, NEW_FOLDER); |
161 | itemList.insert(newItem, homeLocation ); | 161 | itemList.insert(newItem, homeLocation ); |
162 | 162 | ||
163 | // We have changed something. | 163 | // We have changed something. |
164 | changed = true; | 164 | changed = true; |
165 | } | 165 | } |
166 | 166 | ||
167 | /** | 167 | /** |
168 | * Create a new blank application | 168 | * Create a new blank application |
169 | * Make sure a tab is selected | 169 | * Make sure a tab is selected |
170 | * create physical file | 170 | * create physical file |
171 | * fill file with default information (entry, name, type). | 171 | * fill file with default information (entry, name, type). |
172 | */ | 172 | */ |
173 | void TabManager::newApplication(){ | 173 | void TabManager::newApplication(){ |
174 | QListViewItem *item = tabList->currentItem(); | 174 | QListViewItem *item = tabList->currentItem(); |
175 | if(!item || item->parent()) | 175 | if(!item || item->parent()) |
176 | return; | 176 | return; |
177 | 177 | ||
178 | QString parentDir = itemList[item].mid(0,itemList[item].length()-11); | 178 | QString parentDir = itemList[item].mid(0,itemList[item].length()-11); |
179 | QString homeLocation = parentDir + "/" NEW_APPLICATION APPLICATION_EXTENSION; | 179 | QString homeLocation = parentDir + "/" NEW_APPLICATION APPLICATION_EXTENSION; |
180 | system((QString("echo [Desktop Entry] | cat >> ") + homeLocation).latin1()); | 180 | system((QString("echo [Desktop Entry] | cat >> ") + homeLocation).latin1()); |
181 | system((QString("echo Name=" NEW_APPLICATION " | cat >> ") + homeLocation).latin1()); | 181 | system((QString("echo Name=" NEW_APPLICATION " | cat >> ") + homeLocation).latin1()); |
182 | int slash = parentDir.findRev('/', -1); | 182 | int slash = parentDir.findRev('/', -1); |
183 | QString folderName = parentDir.mid(slash+1, parentDir.length()); | 183 | QString folderName = parentDir.mid(slash+1, parentDir.length()); |
184 | 184 | ||
185 | system((QString("echo Type=") + folderName + " | cat >> " + homeLocation).latin1()); | 185 | system((QString("echo Type=") + folderName + " | cat >> " + homeLocation).latin1()); |
186 | 186 | ||
187 | // Insert into the tree | 187 | // Insert into the tree |
188 | QListViewItem *newItem = new QListViewItem(item, NEW_APPLICATION); | 188 | QListViewItem *newItem = new QListViewItem(item, NEW_APPLICATION); |
189 | itemList.insert(newItem, homeLocation ); | 189 | itemList.insert(newItem, homeLocation ); |
190 | 190 | ||
191 | // We have changed something. | 191 | // We have changed something. |
192 | changed = true; | 192 | changed = true; |
193 | } | 193 | } |
194 | 194 | ||
195 | /** | 195 | /** |
196 | * Remove the item. | 196 | * Remove the item. |
197 | * Check if we can | 197 | * Check if we can |
198 | * Prompt user | 198 | * Prompt user |
199 | * Delete physical file (Dir, remove .dir, then dir. File, remove file) | 199 | * Delete physical file (Dir, remove .dir, then dir. File, remove file) |
200 | * Remove from installer if need too. | 200 | * Remove from installer if need too. |
201 | */ | 201 | */ |
202 | void TabManager::removeItem(){ | 202 | void TabManager::removeItem(){ |
203 | // Make sure we can delete | 203 | // Make sure we can delete |
204 | QListViewItem *item = tabList->currentItem(); | 204 | QListViewItem *item = tabList->currentItem(); |
205 | if(!item) | 205 | if(!item) |
206 | return; | 206 | return; |
207 | if(item->childCount() > 0){ | 207 | if(item->childCount() > 0){ |
208 | QMessageBox::critical(this, tr("Message"), tr("Can't remove with applications\nstill in the group."), | 208 | QMessageBox::critical(this, tr("Message"), tr("Can't remove with applications\nstill in the group."), |
209 | tr("Ok") ); | 209 | tr("Ok") ); |
210 | return; | 210 | return; |
211 | } | 211 | } |
212 | 212 | ||
213 | // Prompt. | 213 | // Prompt. |
214 | int answer = QMessageBox::warning(this, tr("Message"), tr("Are you sure you want to delete?"), | 214 | int answer = QMessageBox::warning(this, tr("Message"), tr("Are you sure you want to delete?"), |
215 | tr("Yes"), tr("Cancel"), 0, 1 ); | 215 | tr("Yes"), tr("Cancel"), 0, 1 ); |
216 | if (answer) | 216 | if (answer) |
217 | return; | 217 | return; |
218 | 218 | ||
219 | bool removeSuccessfull = true; | 219 | bool removeSuccessfull = true; |
220 | QString location = itemList[item]; | 220 | QString location = itemList[item]; |
221 | // Remove file (.directory in a Directory case) | 221 | // Remove file (.directory in a Directory case) |
222 | if(!QFile::remove(location)) | 222 | if(!QFile::remove(location)) |
223 | removeSuccessfull = false; | 223 | removeSuccessfull = false; |
224 | 224 | ||
225 | // Remove directory | 225 | // Remove directory |
226 | if(item->parent() == NULL){ | 226 | if(item->parent() == NULL){ |
227 | // Remove .directory file string | 227 | // Remove .directory file string |
228 | location = location.mid(0,location.length()-10); | 228 | location = location.mid(0,location.length()-10); |
229 | QDir dir; | 229 | QDir dir; |
230 | if(!dir.rmdir(location)) | 230 | if(!dir.rmdir(location)) |
231 | removeSuccessfull = false; | 231 | removeSuccessfull = false; |
232 | else | ||
233 | removeSuccessfull = true; | ||
234 | |||
232 | } | 235 | } |
233 | 236 | ||
234 | // If removing failed. | 237 | // If removing failed. |
235 | if(!removeSuccessfull){ | 238 | if(!removeSuccessfull){ |
236 | qDebug((QString("removeItem: ") + location).latin1()); | 239 | qDebug((QString("removeItem: ") + location).latin1()); |
237 | QMessageBox::critical(this, tr("Message"), tr("Can't remove."), | 240 | QMessageBox::critical(this, tr("Message"), tr("Can't remove."), |
238 | tr("Ok") ); | 241 | tr("Ok") ); |
239 | return; | 242 | return; |
240 | } | 243 | } |
241 | 244 | ||
242 | // Remove from the installer so it wont fail. | 245 | // Remove from the installer so it wont fail. |
243 | // Don't need to do this sense the current install uses rm -f so no error | 246 | // Don't need to do this sense the current install uses rm -f so no error |
244 | 247 | ||
245 | // Remove from the gui list. | 248 | // Remove from the gui list. |
246 | itemList.remove(item); | 249 | itemList.remove(item); |
247 | if(item->parent()) | 250 | if(item->parent()) |
248 | item->parent()->takeItem(item); | 251 | item->parent()->takeItem(item); |
249 | delete item; | 252 | delete item; |
250 | 253 | ||
251 | // We have changed something. | 254 | // We have changed something. |
252 | changed = true; | 255 | changed = true; |
253 | } | 256 | } |
254 | 257 | ||
255 | /** | 258 | /** |
256 | * Helper function. Edits the current item. | 259 | * Helper function. Edits the current item. |
257 | * calls editItem with the currently selected item. | 260 | * calls editItem with the currently selected item. |
258 | */ | 261 | */ |
259 | void TabManager::editCurrentItem(){ | 262 | void TabManager::editCurrentItem(){ |
260 | editItem(tabList->currentItem()); | 263 | editItem(tabList->currentItem()); |
261 | } | 264 | } |
262 | 265 | ||
263 | /** | 266 | /** |
264 | * Edit the item that is passed in. | 267 | * Edit the item that is passed in. |
265 | * Show application dialog and if anything changed | 268 | * Show application dialog and if anything changed |
266 | * @param item the item to edit. | 269 | * @param item the item to edit. |
267 | */ | 270 | */ |
268 | void TabManager::editItem( QListViewItem * item){ | 271 | void TabManager::editItem( QListViewItem * item){ |
269 | if(!item) | 272 | if(!item) |
270 | return; | 273 | return; |
271 | 274 | ||
272 | TabAppLnk app(itemList[item]); | 275 | TabAppLnk app(itemList[item]); |
273 | if(!app.isValid()){ | 276 | if(!app.isValid()){ |
274 | qDebug(QString("editItem: Not a valid applnk file: ") + itemList[item].latin1()); | 277 | qDebug(QString("editItem: Not a valid applnk file: ") + itemList[item].latin1()); |
275 | return; | 278 | return; |
276 | } | 279 | } |
277 | 280 | ||
278 | AppEdit application(this, tr("Application edit"), true); | 281 | AppEdit application(this, tr("Application edit"), true); |
279 | application.nameLineEdit->setText(app.name()); | 282 | application.nameLineEdit->setText(app.name()); |
280 | application.iconLineEdit->setText(app.pixmapString()); | 283 | application.iconLineEdit->setText(app.pixmapString()); |
281 | application.execLineEdit->setText(app.exec()); | 284 | application.execLineEdit->setText(app.exec()); |
282 | application.commentLineEdit->setText(app.comment()); | 285 | application.commentLineEdit->setText(app.comment()); |
283 | 286 | ||
284 | if(item->parent() == NULL){ | 287 | if(item->parent() == NULL){ |
285 | application.execLineEdit->setEnabled(false); | 288 | application.execLineEdit->setEnabled(false); |
286 | application.TextLabel3->setEnabled(false); | 289 | application.TextLabel3->setEnabled(false); |
287 | application.setCaption(tr("Tab")); | 290 | application.setCaption(tr("Tab")); |
288 | } | 291 | } |
289 | 292 | ||
290 | // Only do somthing if they hit OK | 293 | // Only do somthing if they hit OK |
291 | if(application.exec() == 0) | 294 | if(application.exec() == 0) |
292 | return; | 295 | return; |
293 | 296 | ||
294 | // If nothing has changed exit (hmmm why did they hit ok?) | 297 | // If nothing has changed exit (hmmm why did they hit ok?) |
295 | if(app.name() == application.nameLineEdit->text() && | 298 | if(app.name() == application.nameLineEdit->text() && |
296 | app.pixmapString() == application.iconLineEdit->text() && | 299 | app.pixmapString() == application.iconLineEdit->text() && |
297 | app.comment() == application.commentLineEdit->text() && | 300 | app.comment() == application.commentLineEdit->text() && |
298 | app.exec() == application.execLineEdit->text()) | 301 | app.exec() == application.execLineEdit->text()) |
299 | return; | 302 | return; |
300 | 303 | ||
301 | // Change the applnk file | 304 | // Change the applnk file |
302 | QString oldName = app.name(); | 305 | QString oldName = app.name(); |
303 | app.setName(application.nameLineEdit->text()); | 306 | app.setName(application.nameLineEdit->text()); |
304 | app.setIcon(application.iconLineEdit->text()); | 307 | app.setIcon(application.iconLineEdit->text()); |
305 | app.setComment(application.commentLineEdit->text()); | 308 | app.setComment(application.commentLineEdit->text()); |
306 | app.setExec(application.execLineEdit->text()); | 309 | app.setExec(application.execLineEdit->text()); |
307 | if(!app.writeLink()){ | 310 | if(!app.writeLink()){ |
308 | QMessageBox::critical(this, tr("Message"), tr("Can't save."), | 311 | QMessageBox::critical(this, tr("Message"), tr("Can't save."), |
309 | tr("Ok") ); | 312 | tr("Ok") ); |
310 | return; | 313 | return; |
311 | } | 314 | } |
312 | 315 | ||
313 | // Update the gui icon and name | 316 | // Update the gui icon and name |
314 | item->setText(0,app.name()); | 317 | item->setText(0,app.name()); |
315 | item->setPixmap(0,app.pixmap()); | 318 | item->setPixmap(0,app.pixmap()); |
316 | 319 | ||
317 | // We have changed something. | 320 | // We have changed something. |
318 | changed = true; | 321 | changed = true; |
319 | 322 | ||
320 | // If we were dealing with a new folder or new application change | 323 | // If we were dealing with a new folder or new application change |
321 | // the file names. Also change the item location in itemList | 324 | // the file names. Also change the item location in itemList |
322 | if(oldName == NEW_FOLDER){ | 325 | if(oldName == NEW_FOLDER){ |
323 | QDir r; | 326 | QDir r; |
324 | QString oldName = itemList[item]; | 327 | QString oldName = itemList[item]; |
325 | oldName = oldName.mid(0,oldName.length()-11); | 328 | oldName = oldName.mid(0,oldName.length()-11); |
326 | QString newName = oldName.mid(0,oldName.length()-9); | 329 | QString newName = oldName.mid(0,oldName.length()-9); |
327 | newName = newName + "/" + app.name(); | 330 | newName = newName + "/" + app.name(); |
328 | r.rename(oldName, newName); | 331 | r.rename(oldName, newName); |
329 | itemList.remove(item); | 332 | itemList.remove(item); |
330 | itemList.insert(item, newName + "/.directory" ); | 333 | itemList.insert(item, newName + "/.directory" ); |
331 | } | 334 | } |
332 | else if(oldName == NEW_APPLICATION){ | 335 | else if(oldName == NEW_APPLICATION){ |
333 | if(!item->parent()) | 336 | if(!item->parent()) |
334 | return; | 337 | return; |
335 | QString parentDir = itemList[item->parent()]; | 338 | QString parentDir = itemList[item->parent()]; |
336 | QDir r; | 339 | QDir r; |
337 | QString oldName = itemList[item]; | 340 | QString oldName = itemList[item]; |
338 | QString newName = oldName.mid(0, parentDir.length()-10); | 341 | QString newName = oldName.mid(0, parentDir.length()-10); |
339 | newName = newName + app.name() + APPLICATION_EXTENSION; | 342 | newName = newName + app.name() + APPLICATION_EXTENSION; |
340 | r.rename(oldName, newName); | 343 | r.rename(oldName, newName); |
341 | itemList.remove(item); | 344 | itemList.remove(item); |
342 | itemList.insert(item, newName); | 345 | itemList.insert(item, newName); |
343 | } | 346 | } |
344 | } | 347 | } |
345 | 348 | ||
346 | /** | 349 | /** |
347 | * Move an application from one directory to another. | 350 | * Move an application from one directory to another. |
348 | * Move in the gui, move in the applnk file, move in the installer. | 351 | * Move in the gui, move in the applnk file, move in the installer. |
349 | * @param item the application to move | 352 | * @param item the application to move |
350 | * @pearam newGroup the new parent of this application | 353 | * @pearam newGroup the new parent of this application |
351 | */ | 354 | */ |
352 | void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){ | 355 | void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){ |
353 | // Can we even move it? | 356 | // Can we even move it? |
354 | if(!item || !item->parent() || newGroup->parent()) | 357 | if(!item || !item->parent() || newGroup->parent()) |
355 | return; | 358 | return; |
356 | if(item->parent() == newGroup) | 359 | if(item->parent() == newGroup) |
357 | return; | 360 | return; |
358 | 361 | ||
359 | // Get the new folder, new file name, | 362 | // Get the new folder, new file name, |
360 | QString newFolder = itemList[newGroup]; | 363 | QString newFolder = itemList[newGroup]; |
361 | newFolder = newFolder.mid(0,newFolder.length()-11); | 364 | newFolder = newFolder.mid(0,newFolder.length()-11); |
362 | int slash = newFolder.findRev('/', -1); | 365 | int slash = newFolder.findRev('/', -1); |
363 | QString folderName = newFolder.mid(slash+1, newFolder.length()); | 366 | QString folderName = newFolder.mid(slash+1, newFolder.length()); |
364 | 367 | ||
365 | QString desktopFile = itemList[item]; | 368 | QString desktopFile = itemList[item]; |
366 | slash = desktopFile.findRev('/', -1); | 369 | slash = desktopFile.findRev('/', -1); |
367 | desktopFile = desktopFile.mid(slash, desktopFile.length()); | 370 | desktopFile = desktopFile.mid(slash, desktopFile.length()); |
368 | newFolder = newFolder + desktopFile; | 371 | newFolder = newFolder + desktopFile; |
369 | 372 | ||
370 | // Move file | 373 | // Move file |
371 | QDir r; | 374 | QDir r; |
372 | if(!r.rename(itemList[item], newFolder)){ | 375 | if(!r.rename(itemList[item], newFolder)){ |
373 | QMessageBox::critical(this, tr("Message"), tr("Can't move application."), | 376 | QMessageBox::critical(this, tr("Message"), tr("Can't move application."), |
374 | tr("Ok") ); | 377 | tr("Ok") ); |
375 | return; | 378 | return; |
376 | } | 379 | } |
377 | //qDebug((QString("moveApplication: ") + itemList[item]).latin1()); | 380 | //qDebug((QString("moveApplication: ") + itemList[item]).latin1()); |
378 | //qDebug((QString("moveApplication: ") + newFolder).latin1()); | 381 | //qDebug((QString("moveApplication: ") + newFolder).latin1()); |
379 | 382 | ||
380 | // Move in the gui | 383 | // Move in the gui |
381 | item->parent()->takeItem(item); | 384 | item->parent()->takeItem(item); |
382 | newGroup->insertItem(item); | 385 | newGroup->insertItem(item); |
383 | newGroup->setOpen(true); | 386 | newGroup->setOpen(true); |
384 | 387 | ||
385 | // Move file in the installer | 388 | // Move file in the installer |
386 | QString installedAppFile; | 389 | QString installedAppFile; |
387 | if(findInstalledApplication(desktopFile, installedAppFile)) | 390 | if(findInstalledApplication(desktopFile, installedAppFile)) |
388 | swapInstalledLocation(installedAppFile, desktopFile, newFolder); | 391 | swapInstalledLocation(installedAppFile, desktopFile, newFolder); |
389 | else | 392 | else |
390 | qDebug("moveApplication: No installed app found for dekstop file"); | 393 | qDebug("moveApplication: No installed app found for dekstop file"); |
391 | 394 | ||
392 | // Move application type | 395 | // Move application type |
393 | AppLnk app(newFolder); | 396 | AppLnk app(newFolder); |
394 | app.setType(folderName); | 397 | app.setType(folderName); |
395 | app.writeLink(); | 398 | app.writeLink(); |
396 | 399 | ||
397 | // Move in our internal list | 400 | // Move in our internal list |
398 | itemList.remove(item); | 401 | itemList.remove(item); |
399 | itemList.insert(item, newFolder); | 402 | itemList.insert(item, newFolder); |
400 | 403 | ||
401 | // We have changed something. | 404 | // We have changed something. |
402 | changed = true; | 405 | changed = true; |
403 | } | 406 | } |
404 | 407 | ||
405 | /** | 408 | /** |
406 | * File the installed application that has this desktop file. | 409 | * File the installed application that has this desktop file. |
407 | * Go through each file in HOME_APP_INSTALL_DIR and see if it contains desktop | 410 | * Go through each file in HOME_APP_INSTALL_DIR and see if it contains desktop |
408 | * file | 411 | * file |
409 | * @param desktopFile - the .desktop file to search for [foo.desktop] | 412 | * @param desktopFile - the .desktop file to search for [foo.desktop] |
410 | * @param installedAppFile - location of the app install list | 413 | * @param installedAppFile - location of the app install list |
411 | * @return true if successfull, false if file not found. | 414 | * @return true if successfull, false if file not found. |
412 | */ | 415 | */ |
413 | bool TabManager::findInstalledApplication(QString desktopFile, QString &installedAppFile){ | 416 | bool TabManager::findInstalledApplication(QString desktopFile, QString &installedAppFile){ |
414 | 417 | ||
415 | QDir d; | 418 | QDir d; |
416 | d.setPath(HOME_APP_INSTALL_DIR); | 419 | d.setPath(HOME_APP_INSTALL_DIR); |
417 | d.setFilter( QDir::Files ); | 420 | d.setFilter( QDir::Files ); |
418 | 421 | ||
419 | const QFileInfoList *list = d.entryInfoList(); | 422 | const QFileInfoList *list = d.entryInfoList(); |
420 | QFileInfoListIterator it( *list ); // create list iterator | 423 | QFileInfoListIterator it( *list ); // create list iterator |
421 | QFileInfo *fi; // pointer for traversing | 424 | QFileInfo *fi; // pointer for traversing |
422 | 425 | ||
423 | while ( (fi=it.current()) ) { // for each file... | 426 | while ( (fi=it.current()) ) { // for each file... |
424 | QFile file(QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName()); | 427 | QFile file(QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName()); |
425 | if ( file.open(IO_ReadOnly) ) { // file opened successfully | 428 | if ( file.open(IO_ReadOnly) ) { // file opened successfully |
426 | QTextStream stream( &file ); // use a text stream | 429 | QTextStream stream( &file ); // use a text stream |
427 | QString line; | 430 | QString line; |
428 | while ( !stream.eof() ) { // until end of file... | 431 | while ( !stream.eof() ) { // until end of file... |
429 | line = stream.readLine(); // line of text excluding '\n' | 432 | line = stream.readLine(); // line of text excluding '\n' |
430 | if(line.contains(desktopFile)){ | 433 | if(line.contains(desktopFile)){ |
431 | installedAppFile = QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName(); | 434 | installedAppFile = QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName(); |
432 | file.close(); | 435 | file.close(); |
433 | return true; | 436 | return true; |
434 | } | 437 | } |
435 | } | 438 | } |
436 | file.close(); | 439 | file.close(); |
437 | } | 440 | } |
438 | else | 441 | else |
439 | qDebug((QString("findInstalledApplication: Can't open file") + HOME_APP_INSTALL_DIR + "/" + fi->fileName()).latin1()); | 442 | qDebug((QString("findInstalledApplication: Can't open file") + HOME_APP_INSTALL_DIR + "/" + fi->fileName()).latin1()); |
440 | ++it; // goto next list element | 443 | ++it; // goto next list element |
441 | } | 444 | } |
442 | return false; | 445 | return false; |
443 | } | 446 | } |
444 | 447 | ||
445 | /** | 448 | /** |
446 | * Open a file and replace a file containing the old desktop file with the new. | 449 | * Open a file and replace a file containing the old desktop file with the new. |
447 | * @param installedAppFile application installed list | 450 | * @param installedAppFile application installed list |
448 | * @param desktopFile old .desktop file | 451 | * @param desktopFile old .desktop file |
449 | * @param newLocation new .desktop file | 452 | * @param newLocation new .desktop file |
450 | */ | 453 | */ |
451 | void TabManager::swapInstalledLocation( QString installedAppFile, QString desktopFile, QString newLocation ){ | 454 | void TabManager::swapInstalledLocation( QString installedAppFile, QString desktopFile, QString newLocation ){ |
452 | QFile file(installedAppFile); | 455 | QFile file(installedAppFile); |
453 | if ( !file.open(IO_ReadOnly) ){ | 456 | if ( !file.open(IO_ReadOnly) ){ |
454 | qDebug(QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1()); | 457 | qDebug(QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1()); |
455 | return; | 458 | return; |
456 | } | 459 | } |
457 | 460 | ||
458 | QTextStream stream( &file ); // use a text stream | 461 | QTextStream stream( &file ); // use a text stream |
459 | QString allLines; | 462 | QString allLines; |
460 | while ( !stream.eof() ) { // until end of file... | 463 | while ( !stream.eof() ) { // until end of file... |
461 | QString line = stream.readLine(); // line of text excluding '\n' | 464 | QString line = stream.readLine(); // line of text excluding '\n' |
462 | if(line.contains(desktopFile)) | 465 | if(line.contains(desktopFile)) |
463 | allLines += newLocation; | 466 | allLines += newLocation; |
464 | else | 467 | else |
465 | allLines += line; | 468 | allLines += line; |
466 | allLines += '\n'; | 469 | allLines += '\n'; |
467 | } | 470 | } |
468 | file.close(); | 471 | file.close(); |
469 | 472 | ||
470 | if ( !file.open(IO_ReadWrite) ){ | 473 | if ( !file.open(IO_ReadWrite) ){ |
471 | qDebug(QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1()); | 474 | qDebug(QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1()); |
472 | return; | 475 | return; |
473 | } | 476 | } |
474 | QTextStream streamOut( &file ); | 477 | QTextStream streamOut( &file ); |
475 | streamOut << allLines; | 478 | streamOut << allLines; |
476 | file.close(); | 479 | file.close(); |
477 | } | 480 | } |
478 | 481 | ||
479 | // tabmanager.cpp | 482 | // tabmanager.cpp |
480 | 483 | ||