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.cpp11
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
@@ -38,49 +38,49 @@
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 */
58TabManager::TabManager( QWidget* parent, const char* name):TabManagerBase(parent, name), changed(false){ 58TabManager::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 */
73TabManager::~TabManager(){ 73TabManager::~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.
@@ -184,78 +184,81 @@ void TabManager::newApplication(){
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 */
202void TabManager::removeItem(){ 202void 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 */
259void TabManager::editCurrentItem(){ 262void TabManager::editCurrentItem(){
260 editItem(tabList->currentItem()); 263 editItem(tabList->currentItem());
261} 264}
@@ -349,49 +352,49 @@ void TabManager::editItem( QListViewItem * item){
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 */
352void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){ 355void 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