summaryrefslogtreecommitdiff
authorbenmeyer <benmeyer>2002-07-26 18:47:13 (UTC)
committer benmeyer <benmeyer>2002-07-26 18:47:13 (UTC)
commit1658b161a890ee69aafac084e04776759932dbce (patch) (unidiff)
treef4330f580496467a01eb6a487069fe235060a453
parent630a8f6e4ff5eddaee0089e383c42cc198c68ced (diff)
downloadopie-1658b161a890ee69aafac084e04776759932dbce.zip
opie-1658b161a890ee69aafac084e04776759932dbce.tar.gz
opie-1658b161a890ee69aafac084e04776759932dbce.tar.bz2
bug fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/tabmanager/tabmanager.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/noncore/settings/tabmanager/tabmanager.cpp b/noncore/settings/tabmanager/tabmanager.cpp
index 5f0899c..c9d7aed 100644
--- a/noncore/settings/tabmanager/tabmanager.cpp
+++ b/noncore/settings/tabmanager/tabmanager.cpp
@@ -100,384 +100,387 @@ void TabManager::rescanFolder(QString directory, QListViewItem* parent){
100 } 100 }
101 else{ 101 else{
102 // Add any desktop files found. 102 // Add any desktop files found.
103 QListViewItem* newItem; 103 QListViewItem* newItem;
104 if(directory != HOME_APP_DIR){ 104 if(directory != HOME_APP_DIR){
105 if(!parent) 105 if(!parent)
106 newItem = new QListViewItem(tabList, fi->fileName()); 106 newItem = new QListViewItem(tabList, fi->fileName());
107 else 107 else
108 newItem = new QListViewItem(parent, fi->fileName()); 108 newItem = new QListViewItem(parent, fi->fileName());
109 if(fi->fileName().right(APPLICATION_EXTENSION_LENGTH) == APPLICATION_EXTENSION){ 109 if(fi->fileName().right(APPLICATION_EXTENSION_LENGTH) == APPLICATION_EXTENSION){
110 AppLnk app(directory + "/" + fi->fileName()); 110 AppLnk app(directory + "/" + fi->fileName());
111 newItem->setPixmap(0,app.pixmap()); 111 newItem->setPixmap(0,app.pixmap());
112 newItem->setText(0, app.name()); 112 newItem->setText(0, app.name());
113 itemList.insert(newItem, directory + "/" + fi->fileName()); 113 itemList.insert(newItem, directory + "/" + fi->fileName());
114 } 114 }
115 } 115 }
116 } 116 }
117 } 117 }
118 ++it; // goto next list element 118 ++it; // goto next list element
119 } 119 }
120} 120}
121 121
122/** 122/**
123 * Create a new blank Tab. 123 * Create a new blank Tab.
124 * Create a physical folder with .directory file 124 * Create a physical folder with .directory file
125 * Create a item on the list 125 * Create a item on the list
126 */ 126 */
127void TabManager::newFolder(){ 127void TabManager::newFolder(){
128 QDir r; 128 QDir r;
129 r.mkdir(QString(HOME_APP_DIR) + "/" + NEW_FOLDER); 129 r.mkdir(QString(HOME_APP_DIR) + "/" + NEW_FOLDER);
130 system((QString("echo [Desktop Entry] | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); 130 system((QString("echo [Desktop Entry] | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1());
131 system((QString("echo Name=" NEW_FOLDER " | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); 131 system((QString("echo Name=" NEW_FOLDER " | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1());
132 132
133 QString homeLocation = QString(HOME_APP_DIR) + "/" + NEW_FOLDER + "/.directory"; 133 QString homeLocation = QString(HOME_APP_DIR) + "/" + NEW_FOLDER + "/.directory";
134 QListViewItem *newItem = new QListViewItem(tabList, NEW_FOLDER); 134 QListViewItem *newItem = new QListViewItem(tabList, NEW_FOLDER);
135 itemList.insert(newItem, homeLocation ); 135 itemList.insert(newItem, homeLocation );
136 136
137 // We have changed something. 137 // We have changed something.
138 changed = true; 138 changed = true;
139} 139}
140 140
141/** 141/**
142 * Create a new blank application 142 * Create a new blank application
143 * Make sure a tab is selected 143 * Make sure a tab is selected
144 * create physical file 144 * create physical file
145 * fill file with default information (entry, name, type). 145 * fill file with default information (entry, name, type).
146 */ 146 */
147void TabManager::newApplication(){ 147void TabManager::newApplication(){
148 QListViewItem *item = tabList->currentItem(); 148 QListViewItem *item = tabList->currentItem();
149 if(!item || item->parent()) 149 if(!item || item->parent())
150 return; 150 return;
151 151
152 QString parentDir = itemList[item].mid(0,itemList[item].length()-11); 152 QString parentDir = itemList[item].mid(0,itemList[item].length()-11);
153 QString homeLocation = parentDir + "/" NEW_APPLICATION APPLICATION_EXTENSION; 153 QString homeLocation = parentDir + "/" NEW_APPLICATION APPLICATION_EXTENSION;
154 system((QString("echo [Desktop Entry] | cat >> ") + homeLocation).latin1()); 154 system((QString("echo [Desktop Entry] | cat >> ") + homeLocation).latin1());
155 system((QString("echo Name=" NEW_APPLICATION " | cat >> ") + homeLocation).latin1()); 155 system((QString("echo Name=" NEW_APPLICATION " | cat >> ") + homeLocation).latin1());
156 int slash = parentDir.findRev('/', -1); 156 int slash = parentDir.findRev('/', -1);
157 QString folderName = parentDir.mid(slash+1, parentDir.length()); 157 QString folderName = parentDir.mid(slash+1, parentDir.length());
158 158
159 system((QString("echo Type=") + folderName + " | cat >> " + homeLocation).latin1()); 159 system((QString("echo Type=") + folderName + " | cat >> " + homeLocation).latin1());
160 160
161 // Insert into the tree 161 // Insert into the tree
162 QListViewItem *newItem = new QListViewItem(item, NEW_APPLICATION); 162 QListViewItem *newItem = new QListViewItem(item, NEW_APPLICATION);
163 itemList.insert(newItem, homeLocation ); 163 itemList.insert(newItem, homeLocation );
164 164
165 // We have changed something. 165 // We have changed something.
166 changed = true; 166 changed = true;
167} 167}
168 168
169/** 169/**
170 * Remove the item. 170 * Remove the item.
171 * Check if we can 171 * Check if we can
172 * Prompt user 172 * Prompt user
173 * Delete physical file (Dir, remove .dir, then dir. File, remove file) 173 * Delete physical file (Dir, remove .dir, then dir. File, remove file)
174 * Remove from installer if need too. 174 * Remove from installer if need too.
175 */ 175 */
176void TabManager::removeItem(){ 176void TabManager::removeItem(){
177 // Make sure we can delete 177 // Make sure we can delete
178 QListViewItem *item = tabList->currentItem(); 178 QListViewItem *item = tabList->currentItem();
179 if(!item) 179 if(!item)
180 return; 180 return;
181 if(item->childCount() > 0){ 181 if(item->childCount() > 0){
182 QMessageBox::critical(this, tr("Message"), tr("Can't remove with applications\nstill in the group."), tr("Ok") ); 182 QMessageBox::critical(this, tr("Message"), tr("Can't remove with applications\nstill in the group."), tr("Ok") );
183 return; 183 return;
184 } 184 }
185 185
186 // Prompt. 186 // Prompt.
187 int answer = QMessageBox::warning(this, tr("Message"), tr("Are you sure you want to delete?"), tr("Yes"), tr("Cancel"), 0, 1 ); 187 int answer = QMessageBox::warning(this, tr("Message"), tr("Are you sure you want to delete?"), tr("Yes"), tr("Cancel"), 0, 1 );
188 if (answer) 188 if (answer)
189 return; 189 return;
190 190
191 bool removeSuccessfull = true; 191 bool removeSuccessfull = true;
192 QString location = itemList[item]; 192 QString location = itemList[item];
193 // Remove file (.directory in a Directory case) 193 // Remove file (.directory in a Directory case)
194 if(!QFile::remove(location)) 194 if(!QFile::remove(location))
195 removeSuccessfull = false; 195 removeSuccessfull = false;
196 196
197 // Remove directory 197 // Remove directory
198 if(item->parent() == NULL){ 198 if(item->parent() == NULL){
199 // Remove .directory file string 199 // Remove .directory file string
200 location = location.mid(0,location.length()-10); 200 location = location.mid(0,location.length()-10);
201 QDir dir; 201 QDir dir;
202 if(!dir.rmdir(location)) 202 if(!dir.rmdir(location))
203 removeSuccessfull = false; 203 removeSuccessfull = false;
204 else 204 else
205 removeSuccessfull = true; 205 removeSuccessfull = true;
206 } 206 }
207 207
208 // If removing failed. 208 // If removing failed.
209 if(!removeSuccessfull){ 209 if(!removeSuccessfull){
210 qDebug((QString("removeItem: ") + location).latin1()); 210 qDebug((QString("removeItem: ") + location).latin1());
211 QMessageBox::critical(this, tr("Message"), tr("Can't remove."), tr("Ok") ); 211 QMessageBox::critical(this, tr("Message"), tr("Can't remove."), tr("Ok") );
212 return; 212 return;
213 } 213 }
214 214
215 // Remove from the installer so it wont fail. 215 // Remove from the installer so it wont fail.
216 // Don't need to do this sense the current install uses rm -f so no error 216 // Don't need to do this sense the current install uses rm -f so no error
217 217
218 // Remove from the gui list. 218 // Remove from the gui list.
219 itemList.remove(item); 219 itemList.remove(item);
220 if(item->parent()) 220 if(item->parent())
221 item->parent()->takeItem(item); 221 item->parent()->takeItem(item);
222 delete item; 222 delete item;
223 223
224 // We have changed something. 224 // We have changed something.
225 changed = true; 225 changed = true;
226} 226}
227 227
228/** 228/**
229 * Helper function. Edits the current item. 229 * Helper function. Edits the current item.
230 * calls editItem with the currently selected item. 230 * calls editItem with the currently selected item.
231 */ 231 */
232void TabManager::editCurrentItem(){ 232void TabManager::editCurrentItem(){
233 editItem(tabList->currentItem()); 233 editItem(tabList->currentItem());
234} 234}
235 235
236/** 236/**
237 * Edit the item that is passed in. 237 * Edit the item that is passed in.
238 * Show application dialog and if anything changed 238 * Show application dialog and if anything changed
239 * @param item the item to edit. 239 * @param item the item to edit.
240 */ 240 */
241void TabManager::editItem( QListViewItem * item){ 241void TabManager::editItem( QListViewItem * item){
242 if(!item) 242 if(!item)
243 return; 243 return;
244 244
245 TabAppLnk app(itemList[item]); 245 TabAppLnk app(itemList[item]);
246 if(!app.isValid()){ 246 if(!app.isValid()){
247 qDebug(QString("editItem: Not a valid applnk file: ") + itemList[item].latin1()); 247 qDebug(QString("editItem: Not a valid applnk file: ") + itemList[item].latin1());
248 return; 248 return;
249 } 249 }
250 250
251 // Fill with all of the icons 251 // Fill with all of the icons
252 if(!application){ 252 if(!application){
253 Wait waitDialog(this, "Wait dialog"); 253 Wait waitDialog(this, "Wait dialog");
254 waitDialog.waitLabel->setText(tr("Gathering icons...")); 254 waitDialog.waitLabel->setText(tr("Gathering icons..."));
255 waitDialog.show(); 255 waitDialog.show();
256 qApp->processEvents(); 256 qApp->processEvents();
257 application = new AppEdit(this, "Application edit", true); 257 application = new AppEdit(this, "Application edit", true);
258 258
259 QDir d(QPEApplication::qpeDir() + "/pics/"); 259 QDir d(QPEApplication::qpeDir() + "/pics/");
260 d.setFilter( QDir::Files); 260 d.setFilter( QDir::Files);
261 261
262 const QFileInfoList *list = d.entryInfoList(); 262 const QFileInfoList *list = d.entryInfoList();
263 QFileInfoListIterator it( *list ); // create list iterator 263 QFileInfoListIterator it( *list ); // create list iterator
264 QFileInfo *fi; // pointer for traversing 264 QFileInfo *fi; // pointer for traversing
265 265
266 while ( (fi=it.current()) ) { // for each file... 266 while ( (fi=it.current()) ) { // for each file...
267 QString fileName = fi->fileName(); 267 QString fileName = fi->fileName();
268 if(fileName.right(4) == ".png"){ 268 if(fileName.right(4) == ".png"){
269 fileName = fileName.mid(0,fileName.length()-4); 269 fileName = fileName.mid(0,fileName.length()-4);
270 QPixmap imageOfFile(Resource::loadPixmap(fileName)); 270 QPixmap imageOfFile(Resource::loadPixmap(fileName));
271 QImage foo = imageOfFile.convertToImage(); 271 QImage foo = imageOfFile.convertToImage();
272 foo = foo.smoothScale(16,16); 272 foo = foo.smoothScale(16,16);
273 imageOfFile.convertFromImage(foo); 273 imageOfFile.convertFromImage(foo);
274 application->iconLineEdit->insertItem(imageOfFile,fileName); 274 application->iconLineEdit->insertItem(imageOfFile,fileName);
275 } 275 }
276 //qDebug(fi->fileName().latin1()); 276 //qDebug(fi->fileName().latin1());
277 ++it; 277 ++it;
278 } 278 }
279 waitDialog.hide(); 279 waitDialog.hide();
280 } 280 }
281 int pixmap = -1; 281 int pixmap = -1;
282 QString pixmapText = app.pixmapString(); 282 QString pixmapText = app.pixmapString();
283 QComboBox *f = application->iconLineEdit; 283 QComboBox *f = application->iconLineEdit;
284 for(int i = 0; i < application->iconLineEdit->count(); i++){ 284 for(int i = 0; i < application->iconLineEdit->count(); i++){
285 if(f->text(i) == pixmapText){ 285 if(f->text(i) == pixmapText){
286 pixmap = i; 286 pixmap = i;
287 break; 287 break;
288 } 288 }
289 } 289 }
290 if(pixmap != -1) 290 if(pixmap != -1)
291 application->iconLineEdit->setCurrentItem(pixmap); 291 application->iconLineEdit->setCurrentItem(pixmap);
292 else if(pixmapText.isEmpty()){
293 application->iconLineEdit->setCurrentItem(0);
294 }
292 else{ 295 else{
293 QPixmap imageOfFile(Resource::loadPixmap(pixmapText)); 296 QPixmap imageOfFile(Resource::loadPixmap(pixmapText));
294 QImage foo = imageOfFile.convertToImage(); 297 QImage foo = imageOfFile.convertToImage();
295 foo = foo.smoothScale(16,16); 298 foo = foo.smoothScale(16,16);
296 imageOfFile.convertFromImage(foo); 299 imageOfFile.convertFromImage(foo);
297 application->iconLineEdit->insertItem(imageOfFile,pixmapText,0); 300 application->iconLineEdit->insertItem(imageOfFile,pixmapText,0);
298 application->iconLineEdit->setCurrentItem(0); 301 application->iconLineEdit->setCurrentItem(0);
299 } 302 }
300 303
301 application->nameLineEdit->setText(app.name()); 304 application->nameLineEdit->setText(app.name());
302 application->execLineEdit->setText(app.exec()); 305 application->execLineEdit->setText(app.exec());
303 application->commentLineEdit->setText(app.comment()); 306 application->commentLineEdit->setText(app.comment());
304 307
305 if(item->parent() == NULL){ 308 if(item->parent() == NULL){
306 application->execLineEdit->setEnabled(false); 309 application->execLineEdit->setEnabled(false);
307 application->TextLabel3->setEnabled(false); 310 application->TextLabel3->setEnabled(false);
308 application->setCaption(tr("Tab")); 311 application->setCaption(tr("Tab"));
309 } 312 }
310 else{ 313 else{
311 application->execLineEdit->setEnabled(true); 314 application->execLineEdit->setEnabled(true);
312 application->TextLabel3->setEnabled(true); 315 application->TextLabel3->setEnabled(true);
313 application->setCaption(tr("Application")); 316 application->setCaption(tr("Application"));
314 } 317 }
315 318
316 // Only do somthing if they hit OK 319 // Only do somthing if they hit OK
317 application->showMaximized(); 320 application->showMaximized();
318 if(application->exec() == 0) 321 if(application->exec() == 0)
319 return; 322 return;
320 323
321 // If nothing has changed exit (hmmm why did they hit ok?) 324 // If nothing has changed exit (hmmm why did they hit ok?)
322 if(app.name() == application->nameLineEdit->text() && 325 if(app.name() == application->nameLineEdit->text() &&
323 app.pixmapString() == application->iconLineEdit->currentText() && 326 app.pixmapString() == application->iconLineEdit->currentText() &&
324 app.comment() == application->commentLineEdit->text() && 327 app.comment() == application->commentLineEdit->text() &&
325 app.exec() == application->execLineEdit->text()) 328 app.exec() == application->execLineEdit->text())
326 return; 329 return;
327 330
328 // Change the applnk file 331 // Change the applnk file
329 QString oldName = app.name(); 332 QString oldName = app.name();
330 app.setName(application->nameLineEdit->text()); 333 app.setName(application->nameLineEdit->text());
331 app.setIcon(application->iconLineEdit->currentText()); 334 app.setIcon(application->iconLineEdit->currentText());
332 app.setComment(application->commentLineEdit->text()); 335 app.setComment(application->commentLineEdit->text());
333 app.setExec(application->execLineEdit->text()); 336 app.setExec(application->execLineEdit->text());
334 if(!app.writeLink()){ 337 if(!app.writeLink()){
335 QMessageBox::critical(this, tr("Message"), "Can't save.", tr("Ok") ); 338 QMessageBox::critical(this, tr("Message"), "Can't save.", tr("Ok") );
336 return; 339 return;
337 } 340 }
338 341
339 // Update the gui icon and name 342 // Update the gui icon and name
340 item->setText(0,app.name()); 343 item->setText(0,app.name());
341 item->setPixmap(0,app.pixmap()); 344 item->setPixmap(0,app.pixmap());
342 345
343 // We have changed something. 346 // We have changed something.
344 changed = true; 347 changed = true;
345 348
346 // If we were dealing with a new folder or new application change 349 // If we were dealing with a new folder or new application change
347 // the file names. Also change the item location in itemList 350 // the file names. Also change the item location in itemList
348 if(oldName == NEW_FOLDER){ 351 if(oldName == NEW_FOLDER){
349 QDir r; 352 QDir r;
350 QString oldName = itemList[item]; 353 QString oldName = itemList[item];
351 oldName = oldName.mid(0,oldName.length()-11); 354 oldName = oldName.mid(0,oldName.length()-11);
352 QString newName = oldName.mid(0,oldName.length()-9); 355 QString newName = oldName.mid(0,oldName.length()-9);
353 newName = newName + "/" + app.name(); 356 newName = newName + "/" + app.name();
354 r.rename(oldName, newName); 357 r.rename(oldName, newName);
355 itemList.remove(item); 358 itemList.remove(item);
356 itemList.insert(item, newName + "/.directory" ); 359 itemList.insert(item, newName + "/.directory" );
357 } 360 }
358 else if(oldName == NEW_APPLICATION){ 361 else if(oldName == NEW_APPLICATION){
359 if(!item->parent()) 362 if(!item->parent())
360 return; 363 return;
361 QString parentDir = itemList[item->parent()]; 364 QString parentDir = itemList[item->parent()];
362 QDir r; 365 QDir r;
363 QString oldName = itemList[item]; 366 QString oldName = itemList[item];
364 QString newName = oldName.mid(0, parentDir.length()-10); 367 QString newName = oldName.mid(0, parentDir.length()-10);
365 newName = newName + app.name() + APPLICATION_EXTENSION; 368 newName = newName + app.name() + APPLICATION_EXTENSION;
366 r.rename(oldName, newName); 369 r.rename(oldName, newName);
367 itemList.remove(item); 370 itemList.remove(item);
368 itemList.insert(item, newName); 371 itemList.insert(item, newName);
369 } 372 }
370} 373}
371 374
372/** 375/**
373 * Move an application from one directory to another. 376 * Move an application from one directory to another.
374 * Move in the gui, move in the applnk file, move in the installer. 377 * Move in the gui, move in the applnk file, move in the installer.
375 * @param item the application to move 378 * @param item the application to move
376 * @pearam newGroup the new parent of this application 379 * @pearam newGroup the new parent of this application
377 */ 380 */
378void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){ 381void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
379 // Can we even move it? 382 // Can we even move it?
380 if(!item || !item->parent() || newGroup->parent()) 383 if(!item || !item->parent() || newGroup->parent())
381 return; 384 return;
382 if(item->parent() == newGroup) 385 if(item->parent() == newGroup)
383 return; 386 return;
384 387
385 // Get the new folder, new file name, 388 // Get the new folder, new file name,
386 QString newFolder = itemList[newGroup]; 389 QString newFolder = itemList[newGroup];
387 newFolder = newFolder.mid(0,newFolder.length()-11); 390 newFolder = newFolder.mid(0,newFolder.length()-11);
388 int slash = newFolder.findRev('/', -1); 391 int slash = newFolder.findRev('/', -1);
389 QString folderName = newFolder.mid(slash+1, newFolder.length()); 392 QString folderName = newFolder.mid(slash+1, newFolder.length());
390 393
391 QString desktopFile = itemList[item]; 394 QString desktopFile = itemList[item];
392 slash = desktopFile.findRev('/', -1); 395 slash = desktopFile.findRev('/', -1);
393 desktopFile = desktopFile.mid(slash, desktopFile.length()); 396 desktopFile = desktopFile.mid(slash, desktopFile.length());
394 newFolder = newFolder + desktopFile; 397 newFolder = newFolder + desktopFile;
395 398
396 // Move file 399 // Move file
397 QDir r; 400 QDir r;
398 if(!r.rename(itemList[item], newFolder)){ 401 if(!r.rename(itemList[item], newFolder)){
399 QMessageBox::critical(this, tr("Message"), "Can't move application.", tr("Ok") ); 402 QMessageBox::critical(this, tr("Message"), "Can't move application.", tr("Ok") );
400 return; 403 return;
401 } 404 }
402 //qDebug((QString("moveApplication: ") + itemList[item]).latin1()); 405 //qDebug((QString("moveApplication: ") + itemList[item]).latin1());
403 //qDebug((QString("moveApplication: ") + newFolder).latin1()); 406 //qDebug((QString("moveApplication: ") + newFolder).latin1());
404 407
405 // Move in the gui 408 // Move in the gui
406 item->parent()->takeItem(item); 409 item->parent()->takeItem(item);
407 newGroup->insertItem(item); 410 newGroup->insertItem(item);
408 newGroup->setOpen(true); 411 newGroup->setOpen(true);
409 412
410 // Move file in the installer 413 // Move file in the installer
411 QString installedAppFile; 414 QString installedAppFile;
412 if(findInstalledApplication(desktopFile, installedAppFile)) 415 if(findInstalledApplication(desktopFile, installedAppFile))
413 swapInstalledLocation(installedAppFile, desktopFile, newFolder); 416 swapInstalledLocation(installedAppFile, desktopFile, newFolder);
414 else 417 else
415 qDebug("moveApplication: No installed app found for dekstop file"); 418 qDebug("moveApplication: No installed app found for dekstop file");
416 419
417 // Move application type 420 // Move application type
418 AppLnk app(newFolder); 421 AppLnk app(newFolder);
419 app.setType(folderName); 422 app.setType(folderName);
420 app.writeLink(); 423 app.writeLink();
421 424
422 // Move in our internal list 425 // Move in our internal list
423 itemList.remove(item); 426 itemList.remove(item);
424 itemList.insert(item, newFolder); 427 itemList.insert(item, newFolder);
425 428
426 // We have changed something. 429 // We have changed something.
427 changed = true; 430 changed = true;
428} 431}
429 432
430/** 433/**
431 * File the installed application that has this desktop file. 434 * File the installed application that has this desktop file.
432 * Go through each file in HOME_APP_INSTALL_DIR and see if it contains desktop 435 * Go through each file in HOME_APP_INSTALL_DIR and see if it contains desktop
433 * file 436 * file
434 * @param desktopFile - the .desktop file to search for [foo.desktop] 437 * @param desktopFile - the .desktop file to search for [foo.desktop]
435 * @param installedAppFile - location of the app install list 438 * @param installedAppFile - location of the app install list
436 * @return true if successfull, false if file not found. 439 * @return true if successfull, false if file not found.
437 */ 440 */
438bool TabManager::findInstalledApplication(QString desktopFile, QString &installedAppFile){ 441bool TabManager::findInstalledApplication(QString desktopFile, QString &installedAppFile){
439 442
440 QDir d; 443 QDir d;
441 d.setPath(HOME_APP_INSTALL_DIR); 444 d.setPath(HOME_APP_INSTALL_DIR);
442 d.setFilter( QDir::Files ); 445 d.setFilter( QDir::Files );
443 446
444 const QFileInfoList *list = d.entryInfoList(); 447 const QFileInfoList *list = d.entryInfoList();
445 QFileInfoListIterator it( *list ); // create list iterator 448 QFileInfoListIterator it( *list ); // create list iterator
446 QFileInfo *fi; // pointer for traversing 449 QFileInfo *fi; // pointer for traversing
447 450
448 while ( (fi=it.current()) ) { // for each file... 451 while ( (fi=it.current()) ) { // for each file...
449 QFile file(QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName()); 452 QFile file(QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName());
450 if ( file.open(IO_ReadOnly) ) { // file opened successfully 453 if ( file.open(IO_ReadOnly) ) { // file opened successfully
451 QTextStream stream( &file ); // use a text stream 454 QTextStream stream( &file ); // use a text stream
452 QString line; 455 QString line;
453 while ( !stream.eof() ) { // until end of file... 456 while ( !stream.eof() ) { // until end of file...
454 line = stream.readLine(); // line of text excluding '\n' 457 line = stream.readLine(); // line of text excluding '\n'
455 if(line.contains(desktopFile)){ 458 if(line.contains(desktopFile)){
456 installedAppFile = QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName(); 459 installedAppFile = QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName();
457 file.close(); 460 file.close();
458 return true; 461 return true;
459 } 462 }
460 } 463 }
461 file.close(); 464 file.close();
462 } 465 }
463 else 466 else
464 qDebug((QString("findInstalledApplication: Can't open file") + HOME_APP_INSTALL_DIR + "/" + fi->fileName()).latin1()); 467 qDebug((QString("findInstalledApplication: Can't open file") + HOME_APP_INSTALL_DIR + "/" + fi->fileName()).latin1());
465 ++it; // goto next list element 468 ++it; // goto next list element
466 } 469 }
467 return false; 470 return false;
468} 471}
469 472
470/** 473/**
471 * Open a file and replace a file containing the old desktop file with the new. 474 * Open a file and replace a file containing the old desktop file with the new.
472 * @param installedAppFile application installed list 475 * @param installedAppFile application installed list
473 * @param desktopFile old .desktop file 476 * @param desktopFile old .desktop file
474 * @param newLocation new .desktop file 477 * @param newLocation new .desktop file
475 */ 478 */
476void TabManager::swapInstalledLocation( QString installedAppFile, QString desktopFile, QString newLocation ){ 479void TabManager::swapInstalledLocation( QString installedAppFile, QString desktopFile, QString newLocation ){
477 QFile file(installedAppFile); 480 QFile file(installedAppFile);
478 if ( !file.open(IO_ReadOnly) ){ 481 if ( !file.open(IO_ReadOnly) ){
479 qDebug(QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1()); 482 qDebug(QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1());
480 return; 483 return;
481 } 484 }
482 485
483 QTextStream stream( &file ); // use a text stream 486 QTextStream stream( &file ); // use a text stream