summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/tabmanager/tabmanager.cpp122
-rw-r--r--noncore/settings/tabmanager/tabmanager.pro2
2 files changed, 63 insertions, 61 deletions
diff --git a/noncore/settings/tabmanager/tabmanager.cpp b/noncore/settings/tabmanager/tabmanager.cpp
index 4274203..3eae424 100644
--- a/noncore/settings/tabmanager/tabmanager.cpp
+++ b/noncore/settings/tabmanager/tabmanager.cpp
@@ -3,6 +3,8 @@
3#include "wait.h" 3#include "wait.h"
4#include "tabapplnk.h" 4#include "tabapplnk.h"
5 5
6#include <opie2/odebug.h>
7
6#include <qpe/applnk.h> 8#include <qpe/applnk.h>
7#include <qdir.h> 9#include <qdir.h>
8#include <qfile.h> 10#include <qfile.h>
@@ -63,8 +65,8 @@ TabManager::~TabManager(){
63 * NULL then the item is a tab and should be placed as a child of the window. 65 * NULL then the item is a tab and should be placed as a child of the window.
64 */ 66 */
65void TabManager::rescanFolder(QString directory, QListViewItem* parent){ 67void TabManager::rescanFolder(QString directory, QListViewItem* parent){
66 //odebug << QString("rescanFolder: ") + directory.latin1() << oendl; 68 //odebug << QString("rescanFolder: ") + directory.latin1() << oendl;
67 69
68 QDir d; 70 QDir d;
69 d.setPath(directory); 71 d.setPath(directory);
70 // Show hidden files for .directories 72 // Show hidden files for .directories
@@ -89,7 +91,7 @@ void TabManager::rescanFolder(QString directory, QListViewItem* parent){
89 } 91 }
90 else{ 92 else{
91 // it is a file, if not a .directory add to parent. 93 // it is a file, if not a .directory add to parent.
92 94
93 // Change parents name and icon to reflect icon. 95 // Change parents name and icon to reflect icon.
94 if(fi->fileName() == ".directory"){ 96 if(fi->fileName() == ".directory"){
95 AppLnk app(directory + "/" + fi->fileName()); 97 AppLnk app(directory + "/" + fi->fileName());
@@ -129,11 +131,11 @@ void TabManager::newFolder(){
129 r.mkdir(QString(HOME_APP_DIR) + "/" + NEW_FOLDER); 131 r.mkdir(QString(HOME_APP_DIR) + "/" + NEW_FOLDER);
130 system((QString("echo [Desktop Entry] | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); 132 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()); 133 system((QString("echo Name=" NEW_FOLDER " | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1());
132 134
133 QString homeLocation = QString(HOME_APP_DIR) + "/" + NEW_FOLDER + "/.directory"; 135 QString homeLocation = QString(HOME_APP_DIR) + "/" + NEW_FOLDER + "/.directory";
134 QListViewItem *newItem = new QListViewItem(tabList, NEW_FOLDER); 136 QListViewItem *newItem = new QListViewItem(tabList, NEW_FOLDER);
135 itemList.insert(newItem, homeLocation ); 137 itemList.insert(newItem, homeLocation );
136 138
137 // We have changed something. 139 // We have changed something.
138 changed = true; 140 changed = true;
139} 141}
@@ -148,20 +150,20 @@ void TabManager::newApplication(){
148 QListViewItem *item = tabList->currentItem(); 150 QListViewItem *item = tabList->currentItem();
149 if(!item || item->parent()) 151 if(!item || item->parent())
150 return; 152 return;
151 153
152 QString parentDir = itemList[item].mid(0,itemList[item].length()-11); 154 QString parentDir = itemList[item].mid(0,itemList[item].length()-11);
153 QString homeLocation = parentDir + "/" NEW_APPLICATION APPLICATION_EXTENSION; 155 QString homeLocation = parentDir + "/" NEW_APPLICATION APPLICATION_EXTENSION;
154 system((QString("echo [Desktop Entry] | cat >> ") + homeLocation).latin1()); 156 system((QString("echo [Desktop Entry] | cat >> ") + homeLocation).latin1());
155 system((QString("echo Name=" NEW_APPLICATION " | cat >> ") + homeLocation).latin1()); 157 system((QString("echo Name=" NEW_APPLICATION " | cat >> ") + homeLocation).latin1());
156 int slash = parentDir.findRev('/', -1); 158 int slash = parentDir.findRev('/', -1);
157 QString folderName = parentDir.mid(slash+1, parentDir.length()); 159 QString folderName = parentDir.mid(slash+1, parentDir.length());
158 160
159 system((QString("echo Type=") + folderName + " | cat >> " + homeLocation).latin1()); 161 system((QString("echo Type=") + folderName + " | cat >> " + homeLocation).latin1());
160 162
161 // Insert into the tree 163 // Insert into the tree
162 QListViewItem *newItem = new QListViewItem(item, NEW_APPLICATION); 164 QListViewItem *newItem = new QListViewItem(item, NEW_APPLICATION);
163 itemList.insert(newItem, homeLocation ); 165 itemList.insert(newItem, homeLocation );
164 166
165 // We have changed something. 167 // We have changed something.
166 changed = true; 168 changed = true;
167} 169}
@@ -172,7 +174,7 @@ void TabManager::newApplication(){
172 * Prompt user 174 * Prompt user
173 * Delete physical file (Dir, remove .dir, then dir. File, remove file) 175 * Delete physical file (Dir, remove .dir, then dir. File, remove file)
174 * Remove from installer if need too. 176 * Remove from installer if need too.
175 */ 177 */
176void TabManager::removeItem(){ 178void TabManager::removeItem(){
177 // Make sure we can delete 179 // Make sure we can delete
178 QListViewItem *item = tabList->currentItem(); 180 QListViewItem *item = tabList->currentItem();
@@ -180,20 +182,20 @@ void TabManager::removeItem(){
180 return; 182 return;
181 if(item->childCount() > 0){ 183 if(item->childCount() > 0){
182 QMessageBox::critical(this, tr("Message"), tr("Can't remove with applications\nstill in the group."), tr("Ok") ); 184 QMessageBox::critical(this, tr("Message"), tr("Can't remove with applications\nstill in the group."), tr("Ok") );
183 return; 185 return;
184 } 186 }
185 187
186 // Prompt. 188 // Prompt.
187 int answer = QMessageBox::warning(this, tr("Message"), tr("Are you sure you want to delete?"), tr("Yes"), tr("Cancel"), 0, 1 ); 189 int answer = QMessageBox::warning(this, tr("Message"), tr("Are you sure you want to delete?"), tr("Yes"), tr("Cancel"), 0, 1 );
188 if (answer) 190 if (answer)
189 return; 191 return;
190 192
191 bool removeSuccessful = true; 193 bool removeSuccessful = true;
192 QString location = itemList[item]; 194 QString location = itemList[item];
193 // Remove file (.directory in a Directory case) 195 // Remove file (.directory in a Directory case)
194 if(!QFile::remove(location)) 196 if(!QFile::remove(location))
195 removeSuccessful = false; 197 removeSuccessful = false;
196 198
197 // Remove directory 199 // Remove directory
198 if(item->parent() == NULL){ 200 if(item->parent() == NULL){
199 // Remove .directory file string 201 // Remove .directory file string
@@ -204,23 +206,23 @@ void TabManager::removeItem(){
204 else 206 else
205 removeSuccessful = true; 207 removeSuccessful = true;
206 } 208 }
207 209
208 // If removing failed. 210 // If removing failed.
209 if(!removeSuccessful){ 211 if(!removeSuccessful){
210 odebug << (QString("removeItem: ") + location).latin1() << oendl; 212 odebug << (QString("removeItem: ") + location).latin1() << oendl;
211 QMessageBox::critical(this, tr("Message"), tr("Can't remove."), tr("Ok") ); 213 QMessageBox::critical(this, tr("Message"), tr("Can't remove."), tr("Ok") );
212 return; 214 return;
213 } 215 }
214 216
215 // Remove from the installer so it wont fail. 217 // 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 218 // Don't need to do this sense the current install uses rm -f so no error
217 219
218 // Remove from the gui list. 220 // Remove from the gui list.
219 itemList.remove(item); 221 itemList.remove(item);
220 if(item->parent()) 222 if(item->parent())
221 item->parent()->takeItem(item); 223 item->parent()->takeItem(item);
222 delete item; 224 delete item;
223 225
224 // We have changed something. 226 // We have changed something.
225 changed = true; 227 changed = true;
226} 228}
@@ -235,19 +237,19 @@ void TabManager::editCurrentItem(){
235 237
236/** 238/**
237 * Edit the item that is passed in. 239 * Edit the item that is passed in.
238 * Show application dialog and if anything changed 240 * Show application dialog and if anything changed
239 * @param item the item to edit. 241 * @param item the item to edit.
240 */ 242 */
241void TabManager::editItem( QListViewItem * item){ 243void TabManager::editItem( QListViewItem * item){
242 if(!item) 244 if(!item)
243 return; 245 return;
244 246
245 TabAppLnk app(itemList[item]); 247 TabAppLnk app(itemList[item]);
246 if(!app.isValid()){ 248 if(!app.isValid()){
247 odebug << QString("editItem: Not a valid applnk file: ") + itemList[item].latin1() << oendl; 249 odebug << QString("editItem: Not a valid applnk file: ") + itemList[item].latin1() << oendl;
248 return; 250 return;
249 } 251 }
250 252
251 // Fill with all of the icons 253 // Fill with all of the icons
252 if(!application){ 254 if(!application){
253 Wait waitDialog(this, "Wait dialog"); 255 Wait waitDialog(this, "Wait dialog");
@@ -255,7 +257,7 @@ void TabManager::editItem( QListViewItem * item){
255 waitDialog.show(); 257 waitDialog.show();
256 qApp->processEvents(); 258 qApp->processEvents();
257 application = new AppEdit(this, "Application edit", true); 259 application = new AppEdit(this, "Application edit", true);
258 260
259 QDir d(QPEApplication::qpeDir() + "/pics/"); 261 QDir d(QPEApplication::qpeDir() + "/pics/");
260 d.setFilter( QDir::Files); 262 d.setFilter( QDir::Files);
261 263
@@ -271,9 +273,9 @@ void TabManager::editItem( QListViewItem * item){
271 QImage foo = imageOfFile.convertToImage(); 273 QImage foo = imageOfFile.convertToImage();
272 foo = foo.smoothScale(16,16); 274 foo = foo.smoothScale(16,16);
273 imageOfFile.convertFromImage(foo); 275 imageOfFile.convertFromImage(foo);
274 application->iconLineEdit->insertItem(imageOfFile,fileName); 276 application->iconLineEdit->insertItem(imageOfFile,fileName);
275 } 277 }
276 //odebug << fi->fileName().latin1() << oendl; 278 //odebug << fi->fileName().latin1() << oendl;
277 ++it; 279 ++it;
278 } 280 }
279 waitDialog.hide(); 281 waitDialog.hide();
@@ -297,14 +299,14 @@ void TabManager::editItem( QListViewItem * item){
297 QImage foo = imageOfFile.convertToImage(); 299 QImage foo = imageOfFile.convertToImage();
298 foo = foo.smoothScale(16,16); 300 foo = foo.smoothScale(16,16);
299 imageOfFile.convertFromImage(foo); 301 imageOfFile.convertFromImage(foo);
300 application->iconLineEdit->insertItem(imageOfFile,pixmapText,0); 302 application->iconLineEdit->insertItem(imageOfFile,pixmapText,0);
301 application->iconLineEdit->setCurrentItem(0); 303 application->iconLineEdit->setCurrentItem(0);
302 } 304 }
303 305
304 application->nameLineEdit->setText(app.name()); 306 application->nameLineEdit->setText(app.name());
305 application->execLineEdit->setText(app.exec()); 307 application->execLineEdit->setText(app.exec());
306 application->commentLineEdit->setText(app.comment()); 308 application->commentLineEdit->setText(app.comment());
307 309
308 if(item->parent() == NULL){ 310 if(item->parent() == NULL){
309 application->execLineEdit->setEnabled(false); 311 application->execLineEdit->setEnabled(false);
310 application->TextLabel3->setEnabled(false); 312 application->TextLabel3->setEnabled(false);
@@ -315,7 +317,7 @@ void TabManager::editItem( QListViewItem * item){
315 application->TextLabel3->setEnabled(true); 317 application->TextLabel3->setEnabled(true);
316 application->setCaption(tr("Application")); 318 application->setCaption(tr("Application"));
317 } 319 }
318 320
319 // Only do somthing if they hit OK 321 // Only do somthing if they hit OK
320 application->showMaximized(); 322 application->showMaximized();
321 if(application->exec() == 0) 323 if(application->exec() == 0)
@@ -338,14 +340,14 @@ void TabManager::editItem( QListViewItem * item){
338 QMessageBox::critical(this, tr("Message"), "Can't save.", tr("Ok") ); 340 QMessageBox::critical(this, tr("Message"), "Can't save.", tr("Ok") );
339 return; 341 return;
340 } 342 }
341 343
342 // Update the gui icon and name 344 // Update the gui icon and name
343 item->setText(0,app.name()); 345 item->setText(0,app.name());
344 item->setPixmap(0,app.pixmap()); 346 item->setPixmap(0,app.pixmap());
345 347
346 // We have changed something. 348 // We have changed something.
347 changed = true; 349 changed = true;
348 350
349 // If we were dealing with a new folder or new application change 351 // If we were dealing with a new folder or new application change
350 // the file names. Also change the item location in itemList 352 // the file names. Also change the item location in itemList
351 if(oldName == NEW_FOLDER){ 353 if(oldName == NEW_FOLDER){
@@ -371,26 +373,26 @@ void TabManager::editItem( QListViewItem * item){
371 itemList.insert(item, newName); 373 itemList.insert(item, newName);
372 } 374 }
373} 375}
374 376
375/** 377/**
376 * Move an application from one directory to another. 378 * Move an application from one directory to another.
377 * Move in the gui, move in the applnk file, move in the installer. 379 * Move in the gui, move in the applnk file, move in the installer.
378 * @param item the application to move 380 * @param item the application to move
379 * @pearam newGroup the new parent of this application 381 * @pearam newGroup the new parent of this application
380 */ 382 */
381void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){ 383void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
382 // Can we even move it? 384 // Can we even move it?
383 if(!item || !item->parent() || newGroup->parent()) 385 if(!item || !item->parent() || newGroup->parent())
384 return; 386 return;
385 if(item->parent() == newGroup) 387 if(item->parent() == newGroup)
386 return; 388 return;
387 389
388 // Get the new folder, new file name, 390 // Get the new folder, new file name,
389 QString newFolder = itemList[newGroup]; 391 QString newFolder = itemList[newGroup];
390 newFolder = newFolder.mid(0,newFolder.length()-11); 392 newFolder = newFolder.mid(0,newFolder.length()-11);
391 int slash = newFolder.findRev('/', -1); 393 int slash = newFolder.findRev('/', -1);
392 QString folderName = newFolder.mid(slash+1, newFolder.length()); 394 QString folderName = newFolder.mid(slash+1, newFolder.length());
393 395
394 QString desktopFile = itemList[item]; 396 QString desktopFile = itemList[item];
395 slash = desktopFile.findRev('/', -1); 397 slash = desktopFile.findRev('/', -1);
396 desktopFile = desktopFile.mid(slash, desktopFile.length()); 398 desktopFile = desktopFile.mid(slash, desktopFile.length());
@@ -400,32 +402,32 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
400 QDir r; 402 QDir r;
401 if(!r.rename(itemList[item], newFolder)){ 403 if(!r.rename(itemList[item], newFolder)){
402 QMessageBox::critical(this, tr("Message"), "Can't move application.", tr("Ok") ); 404 QMessageBox::critical(this, tr("Message"), "Can't move application.", tr("Ok") );
403 return; 405 return;
404 } 406 }
405 //odebug << (QString("moveApplication: ") + itemList[item]).latin1() << oendl; 407 //odebug << (QString("moveApplication: ") + itemList[item]).latin1() << oendl;
406 //odebug << (QString("moveApplication: ") + newFolder).latin1() << oendl; 408 //odebug << (QString("moveApplication: ") + newFolder).latin1() << oendl;
407 409
408 // Move in the gui 410 // Move in the gui
409 item->parent()->takeItem(item); 411 item->parent()->takeItem(item);
410 newGroup->insertItem(item); 412 newGroup->insertItem(item);
411 newGroup->setOpen(true); 413 newGroup->setOpen(true);
412 414
413 // Move file in the installer 415 // Move file in the installer
414 QString installedAppFile; 416 QString installedAppFile;
415 if(findInstalledApplication(desktopFile, installedAppFile)) 417 if(findInstalledApplication(desktopFile, installedAppFile))
416 swapInstalledLocation(installedAppFile, desktopFile, newFolder); 418 swapInstalledLocation(installedAppFile, desktopFile, newFolder);
417 else 419 else
418 odebug << "moveApplication: No installed app found for dekstop file" << oendl; 420 odebug << "moveApplication: No installed app found for dekstop file" << oendl;
419 421
420 // Move application type 422 // Move application type
421 AppLnk app(newFolder); 423 AppLnk app(newFolder);
422 app.setType(folderName); 424 app.setType(folderName);
423 app.writeLink(); 425 app.writeLink();
424 426
425 // Move in our internal list 427 // Move in our internal list
426 itemList.remove(item); 428 itemList.remove(item);
427 itemList.insert(item, newFolder); 429 itemList.insert(item, newFolder);
428 430
429 // We have changed something. 431 // We have changed something.
430 changed = true; 432 changed = true;
431} 433}
@@ -437,9 +439,9 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
437 * @param desktopFile - the .desktop file to search for [foo.desktop] 439 * @param desktopFile - the .desktop file to search for [foo.desktop]
438 * @param installedAppFile - location of the app install list 440 * @param installedAppFile - location of the app install list
439 * @return true if successful, false if file not found. 441 * @return true if successful, false if file not found.
440 */ 442 */
441bool TabManager::findInstalledApplication(QString desktopFile, QString &installedAppFile){ 443bool TabManager::findInstalledApplication(QString desktopFile, QString &installedAppFile){
442 444
443 QDir d; 445 QDir d;
444 d.setPath(HOME_APP_INSTALL_DIR); 446 d.setPath(HOME_APP_INSTALL_DIR);
445 d.setFilter( QDir::Files ); 447 d.setFilter( QDir::Files );
@@ -464,7 +466,7 @@ bool TabManager::findInstalledApplication(QString desktopFile, QString &installe
464 file.close(); 466 file.close();
465 } 467 }
466 else 468 else
467 odebug << (QString("findInstalledApplication: Can't open file") + HOME_APP_INSTALL_DIR + "/" + fi->fileName()).latin1() << oendl; 469 odebug << (QString("findInstalledApplication: Can't open file") + HOME_APP_INSTALL_DIR + "/" + fi->fileName()).latin1() << oendl;
468 ++it; // goto next list element 470 ++it; // goto next list element
469 } 471 }
470 return false; 472 return false;
@@ -473,16 +475,16 @@ bool TabManager::findInstalledApplication(QString desktopFile, QString &installe
473/** 475/**
474 * Open a file and replace a file containing the old desktop file with the new. 476 * Open a file and replace a file containing the old desktop file with the new.
475 * @param installedAppFile application installed list 477 * @param installedAppFile application installed list
476 * @param desktopFile old .desktop file 478 * @param desktopFile old .desktop file
477 * @param newLocation new .desktop file 479 * @param newLocation new .desktop file
478 */ 480 */
479void TabManager::swapInstalledLocation( QString installedAppFile, QString desktopFile, QString newLocation ){ 481void TabManager::swapInstalledLocation( QString installedAppFile, QString desktopFile, QString newLocation ){
480 QFile file(installedAppFile); 482 QFile file(installedAppFile);
481 if ( !file.open(IO_ReadOnly) ){ 483 if ( !file.open(IO_ReadOnly) ){
482 odebug << QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1() << oendl; 484 odebug << QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1() << oendl;
483 return; 485 return;
484 } 486 }
485 487
486 QTextStream stream( &file ); // use a text stream 488 QTextStream stream( &file ); // use a text stream
487 QString allLines; 489 QString allLines;
488 while ( !stream.eof() ) { // until end of file... 490 while ( !stream.eof() ) { // until end of file...
@@ -496,7 +498,7 @@ void TabManager::swapInstalledLocation( QString installedAppFile, QString deskto
496 file.close(); 498 file.close();
497 499
498 if ( !file.open(IO_ReadWrite) ){ 500 if ( !file.open(IO_ReadWrite) ){
499 odebug << QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1() << oendl; 501 odebug << QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1() << oendl;
500 return; 502 return;
501 } 503 }
502 QTextStream streamOut( &file ); 504 QTextStream streamOut( &file );
diff --git a/noncore/settings/tabmanager/tabmanager.pro b/noncore/settings/tabmanager/tabmanager.pro
index dbc81a3..d4aac43 100644
--- a/noncore/settings/tabmanager/tabmanager.pro
+++ b/noncore/settings/tabmanager/tabmanager.pro
@@ -4,7 +4,7 @@ HEADERS = tabmanager.h tabmainwindow.h tablistview.h tabmanagerbase.h tabapplnk
4 SOURCES = main.cpp tabmanager.cpp tabmanagerbase.cpp 4 SOURCES = main.cpp tabmanager.cpp tabmanagerbase.cpp
5 INCLUDEPATH+= $(OPIEDIR)/include 5 INCLUDEPATH+= $(OPIEDIR)/include
6 DEPENDPATH+= $(OPIEDIR)/include 6 DEPENDPATH+= $(OPIEDIR)/include
7 LIBS += -lqpe 7 LIBS += -lqpe -lopiecore2
8 INTERFACES= app.ui wait.ui 8 INTERFACES= app.ui wait.ui
9 TARGET = tabmanager 9 TARGET = tabmanager
10 DESTDIR = $(OPIEDIR)/bin 10 DESTDIR = $(OPIEDIR)/bin