summaryrefslogtreecommitdiff
path: root/noncore/settings/tabmanager/tabmanager.cpp
Unidiff
Diffstat (limited to 'noncore/settings/tabmanager/tabmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/tabmanager/tabmanager.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/noncore/settings/tabmanager/tabmanager.cpp b/noncore/settings/tabmanager/tabmanager.cpp
index 15aeaf5..4274203 100644
--- a/noncore/settings/tabmanager/tabmanager.cpp
+++ b/noncore/settings/tabmanager/tabmanager.cpp
@@ -42,49 +42,49 @@ TabManager::TabManager( QWidget* parent, const char* name):TabManagerBase(parent
42/** 42/**
43 * If anything in the tab's have been changed then update the system or alert 43 * If anything in the tab's have been changed then update the system or alert
44 * the user. 44 * the user.
45 */ 45 */
46TabManager::~TabManager(){ 46TabManager::~TabManager(){
47 if(changed){ 47 if(changed){
48 // Prompt. 48 // Prompt.
49 //int answer = QMessageBox::warning(this, "Message", "Should your desktop be","Yes", "Cancel", 0, 1 ); 49 //int answer = QMessageBox::warning(this, "Message", "Should your desktop be","Yes", "Cancel", 0, 1 );
50 //if (answer) 50 //if (answer)
51 // return; 51 // return;
52 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 52 QCopEnvelope e("QPE/System", "linkChanged(QString)");
53 QString link; //we'll just send an empty string 53 QString link; //we'll just send an empty string
54 e << link; 54 e << link;
55 } 55 }
56} 56}
57 57
58/** 58/**
59 * Scans root directory for any tabs or applications. Will recursivly go down, 59 * Scans root directory for any tabs or applications. Will recursivly go down,
60 * but will not follow symlinks. 60 * but will not follow symlinks.
61 * @param directory - the directory to look in. 61 * @param directory - the directory to look in.
62 * @param parent - the parent to place any new tabs or apps into. If parent is 62 * @param parent - the parent to place any new tabs or apps into. If parent is
63 * NULL then the item is a tab and should be placed as a child of the window. 63 * NULL then the item is a tab and should be placed as a child of the window.
64 */ 64 */
65void TabManager::rescanFolder(QString directory, QListViewItem* parent){ 65void TabManager::rescanFolder(QString directory, QListViewItem* parent){
66 //qDebug(QString("rescanFolder: ") + directory.latin1()); 66 //odebug << QString("rescanFolder: ") + directory.latin1() << oendl;
67 67
68 QDir d; 68 QDir d;
69 d.setPath(directory); 69 d.setPath(directory);
70 // Show hidden files for .directories 70 // Show hidden files for .directories
71 d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); 71 d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs);
72 72
73 const QFileInfoList *list = d.entryInfoList(); 73 const QFileInfoList *list = d.entryInfoList();
74 QFileInfoListIterator it( *list ); // create list iterator 74 QFileInfoListIterator it( *list ); // create list iterator
75 QFileInfo *fi; // pointer for traversing 75 QFileInfo *fi; // pointer for traversing
76 76
77 while ( (fi=it.current()) ) { // for each file... 77 while ( (fi=it.current()) ) { // for each file...
78 // If it is a dir and not .. or . then add it as a tab and go down. 78 // If it is a dir and not .. or . then add it as a tab and go down.
79 if(fi->isDir()){ 79 if(fi->isDir()){
80 if(fi->fileName() != ".." && fi->fileName() != ".") { 80 if(fi->fileName() != ".." && fi->fileName() != ".") {
81 QListViewItem* newItem; 81 QListViewItem* newItem;
82 if(!parent) 82 if(!parent)
83 newItem = new QListViewItem(tabList, fi->fileName()); 83 newItem = new QListViewItem(tabList, fi->fileName());
84 else 84 else
85 newItem = new QListViewItem(parent, fi->fileName()); 85 newItem = new QListViewItem(parent, fi->fileName());
86 itemList.insert(newItem, directory + "/" + fi->fileName() + "/.directory" ); 86 itemList.insert(newItem, directory + "/" + fi->fileName() + "/.directory" );
87 rescanFolder(directory + "/" + fi->fileName(), newItem); 87 rescanFolder(directory + "/" + fi->fileName(), newItem);
88 } 88 }
89 } 89 }
90 else{ 90 else{
@@ -186,115 +186,115 @@ void TabManager::removeItem(){
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 removeSuccessful = true; 191 bool removeSuccessful = 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 removeSuccessful = false; 195 removeSuccessful = 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 removeSuccessful = false; 203 removeSuccessful = false;
204 else 204 else
205 removeSuccessful = true; 205 removeSuccessful = true;
206 } 206 }
207 207
208 // If removing failed. 208 // If removing failed.
209 if(!removeSuccessful){ 209 if(!removeSuccessful){
210 qDebug((QString("removeItem: ") + location).latin1()); 210 odebug << (QString("removeItem: ") + location).latin1() << oendl;
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 odebug << QString("editItem: Not a valid applnk file: ") + itemList[item].latin1() << oendl;
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 //odebug << fi->fileName().latin1() << oendl;
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()){ 292 else if(pixmapText.isEmpty()){
293 application->iconLineEdit->setCurrentItem(0); 293 application->iconLineEdit->setCurrentItem(0);
294 } 294 }
295 else{ 295 else{
296 QPixmap imageOfFile(Resource::loadPixmap(pixmapText)); 296 QPixmap imageOfFile(Resource::loadPixmap(pixmapText));
297 QImage foo = imageOfFile.convertToImage(); 297 QImage foo = imageOfFile.convertToImage();
298 foo = foo.smoothScale(16,16); 298 foo = foo.smoothScale(16,16);
299 imageOfFile.convertFromImage(foo); 299 imageOfFile.convertFromImage(foo);
300 application->iconLineEdit->insertItem(imageOfFile,pixmapText,0); 300 application->iconLineEdit->insertItem(imageOfFile,pixmapText,0);
@@ -381,128 +381,128 @@ void TabManager::editItem( QListViewItem * item){
381void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){ 381void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
382 // Can we even move it? 382 // Can we even move it?
383 if(!item || !item->parent() || newGroup->parent()) 383 if(!item || !item->parent() || newGroup->parent())
384 return; 384 return;
385 if(item->parent() == newGroup) 385 if(item->parent() == newGroup)
386 return; 386 return;
387 387
388 // Get the new folder, new file name, 388 // Get the new folder, new file name,
389 QString newFolder = itemList[newGroup]; 389 QString newFolder = itemList[newGroup];
390 newFolder = newFolder.mid(0,newFolder.length()-11); 390 newFolder = newFolder.mid(0,newFolder.length()-11);
391 int slash = newFolder.findRev('/', -1); 391 int slash = newFolder.findRev('/', -1);
392 QString folderName = newFolder.mid(slash+1, newFolder.length()); 392 QString folderName = newFolder.mid(slash+1, newFolder.length());
393 393
394 QString desktopFile = itemList[item]; 394 QString desktopFile = itemList[item];
395 slash = desktopFile.findRev('/', -1); 395 slash = desktopFile.findRev('/', -1);
396 desktopFile = desktopFile.mid(slash, desktopFile.length()); 396 desktopFile = desktopFile.mid(slash, desktopFile.length());
397 newFolder = newFolder + desktopFile; 397 newFolder = newFolder + desktopFile;
398 398
399 // Move file 399 // Move file
400 QDir r; 400 QDir r;
401 if(!r.rename(itemList[item], newFolder)){ 401 if(!r.rename(itemList[item], newFolder)){
402 QMessageBox::critical(this, tr("Message"), "Can't move application.", tr("Ok") ); 402 QMessageBox::critical(this, tr("Message"), "Can't move application.", tr("Ok") );
403 return; 403 return;
404 } 404 }
405 //qDebug((QString("moveApplication: ") + itemList[item]).latin1()); 405 //odebug << (QString("moveApplication: ") + itemList[item]).latin1() << oendl;
406 //qDebug((QString("moveApplication: ") + newFolder).latin1()); 406 //odebug << (QString("moveApplication: ") + newFolder).latin1() << oendl;
407 407
408 // Move in the gui 408 // Move in the gui
409 item->parent()->takeItem(item); 409 item->parent()->takeItem(item);
410 newGroup->insertItem(item); 410 newGroup->insertItem(item);
411 newGroup->setOpen(true); 411 newGroup->setOpen(true);
412 412
413 // Move file in the installer 413 // Move file in the installer
414 QString installedAppFile; 414 QString installedAppFile;
415 if(findInstalledApplication(desktopFile, installedAppFile)) 415 if(findInstalledApplication(desktopFile, installedAppFile))
416 swapInstalledLocation(installedAppFile, desktopFile, newFolder); 416 swapInstalledLocation(installedAppFile, desktopFile, newFolder);
417 else 417 else
418 qDebug("moveApplication: No installed app found for dekstop file"); 418 odebug << "moveApplication: No installed app found for dekstop file" << oendl;
419 419
420 // Move application type 420 // Move application type
421 AppLnk app(newFolder); 421 AppLnk app(newFolder);
422 app.setType(folderName); 422 app.setType(folderName);
423 app.writeLink(); 423 app.writeLink();
424 424
425 // Move in our internal list 425 // Move in our internal list
426 itemList.remove(item); 426 itemList.remove(item);
427 itemList.insert(item, newFolder); 427 itemList.insert(item, newFolder);
428 428
429 // We have changed something. 429 // We have changed something.
430 changed = true; 430 changed = true;
431} 431}
432 432
433/** 433/**
434 * File the installed application that has this desktop file. 434 * File the installed application that has this desktop file.
435 * 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
436 * file 436 * file
437 * @param desktopFile - the .desktop file to search for [foo.desktop] 437 * @param desktopFile - the .desktop file to search for [foo.desktop]
438 * @param installedAppFile - location of the app install list 438 * @param installedAppFile - location of the app install list
439 * @return true if successful, false if file not found. 439 * @return true if successful, false if file not found.
440 */ 440 */
441bool TabManager::findInstalledApplication(QString desktopFile, QString &installedAppFile){ 441bool TabManager::findInstalledApplication(QString desktopFile, QString &installedAppFile){
442 442
443 QDir d; 443 QDir d;
444 d.setPath(HOME_APP_INSTALL_DIR); 444 d.setPath(HOME_APP_INSTALL_DIR);
445 d.setFilter( QDir::Files ); 445 d.setFilter( QDir::Files );
446 446
447 const QFileInfoList *list = d.entryInfoList(); 447 const QFileInfoList *list = d.entryInfoList();
448 QFileInfoListIterator it( *list ); // create list iterator 448 QFileInfoListIterator it( *list ); // create list iterator
449 QFileInfo *fi; // pointer for traversing 449 QFileInfo *fi; // pointer for traversing
450 450
451 while ( (fi=it.current()) ) { // for each file... 451 while ( (fi=it.current()) ) { // for each file...
452 QFile file(QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName()); 452 QFile file(QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName());
453 if ( file.open(IO_ReadOnly) ) { // file opened successfully 453 if ( file.open(IO_ReadOnly) ) { // file opened successfully
454 QTextStream stream( &file ); // use a text stream 454 QTextStream stream( &file ); // use a text stream
455 QString line; 455 QString line;
456 while ( !stream.eof() ) { // until end of file... 456 while ( !stream.eof() ) { // until end of file...
457 line = stream.readLine(); // line of text excluding '\n' 457 line = stream.readLine(); // line of text excluding '\n'
458 if(line.contains(desktopFile)){ 458 if(line.contains(desktopFile)){
459 installedAppFile = QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName(); 459 installedAppFile = QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName();
460 file.close(); 460 file.close();
461 return true; 461 return true;
462 } 462 }
463 } 463 }
464 file.close(); 464 file.close();
465 } 465 }
466 else 466 else
467 qDebug((QString("findInstalledApplication: Can't open file") + HOME_APP_INSTALL_DIR + "/" + fi->fileName()).latin1()); 467 odebug << (QString("findInstalledApplication: Can't open file") + HOME_APP_INSTALL_DIR + "/" + fi->fileName()).latin1() << oendl;
468 ++it; // goto next list element 468 ++it; // goto next list element
469 } 469 }
470 return false; 470 return false;
471} 471}
472 472
473/** 473/**
474 * 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.
475 * @param installedAppFile application installed list 475 * @param installedAppFile application installed list
476 * @param desktopFile old .desktop file 476 * @param desktopFile old .desktop file
477 * @param newLocation new .desktop file 477 * @param newLocation new .desktop file
478 */ 478 */
479void TabManager::swapInstalledLocation( QString installedAppFile, QString desktopFile, QString newLocation ){ 479void TabManager::swapInstalledLocation( QString installedAppFile, QString desktopFile, QString newLocation ){
480 QFile file(installedAppFile); 480 QFile file(installedAppFile);
481 if ( !file.open(IO_ReadOnly) ){ 481 if ( !file.open(IO_ReadOnly) ){
482 qDebug(QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1()); 482 odebug << QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1() << oendl;
483 return; 483 return;
484 } 484 }
485 485
486 QTextStream stream( &file ); // use a text stream 486 QTextStream stream( &file ); // use a text stream
487 QString allLines; 487 QString allLines;
488 while ( !stream.eof() ) { // until end of file... 488 while ( !stream.eof() ) { // until end of file...
489 QString line = stream.readLine(); // line of text excluding '\n' 489 QString line = stream.readLine(); // line of text excluding '\n'
490 if(line.contains(desktopFile)) 490 if(line.contains(desktopFile))
491 allLines += newLocation; 491 allLines += newLocation;
492 else 492 else
493 allLines += line; 493 allLines += line;
494 allLines += '\n'; 494 allLines += '\n';
495 } 495 }
496 file.close(); 496 file.close();
497 497
498 if ( !file.open(IO_ReadWrite) ){ 498 if ( !file.open(IO_ReadWrite) ){
499 qDebug(QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1()); 499 odebug << QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1() << oendl;
500 return; 500 return;
501 } 501 }
502 QTextStream streamOut( &file ); 502 QTextStream streamOut( &file );
503 streamOut << allLines; 503 streamOut << allLines;
504 file.close(); 504 file.close();
505} 505}
506 506
507// tabmanager.cpp 507// tabmanager.cpp
508 508