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.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/noncore/settings/tabmanager/tabmanager.cpp b/noncore/settings/tabmanager/tabmanager.cpp
index c9d7aed..ff5957c 100644
--- a/noncore/settings/tabmanager/tabmanager.cpp
+++ b/noncore/settings/tabmanager/tabmanager.cpp
@@ -143,115 +143,115 @@ void TabManager::newFolder(){
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 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 removeSuccessfull = 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 removeSuccessfull = false; 203 removeSuccessful = false;
204 else 204 else
205 removeSuccessfull = true; 205 removeSuccessful = true;
206 } 206 }
207 207
208 // If removing failed. 208 // If removing failed.
209 if(!removeSuccessfull){ 209 if(!removeSuccessful){
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);
@@ -391,97 +391,97 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
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 //qDebug((QString("moveApplication: ") + itemList[item]).latin1());
406 //qDebug((QString("moveApplication: ") + newFolder).latin1()); 406 //qDebug((QString("moveApplication: ") + newFolder).latin1());
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 qDebug("moveApplication: No installed app found for dekstop file");
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 successfull, 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 qDebug((QString("findInstalledApplication: Can't open file") + HOME_APP_INSTALL_DIR + "/" + fi->fileName()).latin1());
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 qDebug(QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1());
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;