-rw-r--r-- | noncore/settings/tabmanager/tabmanager.cpp | 2 | ||||
-rw-r--r-- | noncore/settings/tabmanager/tabmanager.pro | 2 |
2 files changed, 3 insertions, 1 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 @@ -1,261 +1,263 @@ #include "tabmanager.h" #include "app.h" #include "wait.h" #include "tabapplnk.h" +#include <opie2/odebug.h> + #include <qpe/applnk.h> #include <qdir.h> #include <qfile.h> #include <qtextstream.h> #include <qlistview.h> #include <qheader.h> #include <qcombobox.h> #include <qlineedit.h> #include <qlabel.h> #include <qmessagebox.h> #include <stdlib.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> #define HOME_APP_DIR QPEApplication::qpeDir()+"/apps" #define HOME_APP_INSTALL_DIR "/usr/lib/ipkg/info" #define NEW_FOLDER "EmptyTab" #define NEW_APPLICATION "NewApp" #define APPLICATION_EXTENSION ".desktop" #define APPLICATION_EXTENSION_LENGTH 8 /** * Constructor. Sets up signals. Performs initial scan of applications * and tabs */ TabManager::TabManager( QWidget* parent, const char* name):TabManagerBase(parent, name), changed(false), application(NULL){ rescanFolder(HOME_APP_DIR); // Connect the signals and slots connect(tabList, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(editItem(QListViewItem*))); (tabList->header())->hide(); connect(tabList, SIGNAL(moveItem(QListViewItem*,QListViewItem*)), this, SLOT(moveApplication(QListViewItem*,QListViewItem*))); } /** * If anything in the tab's have been changed then update the system or alert * the user. */ TabManager::~TabManager(){ if(changed){ // Prompt. //int answer = QMessageBox::warning(this, "Message", "Should your desktop be","Yes", "Cancel", 0, 1 ); //if (answer) // return; QCopEnvelope e("QPE/System", "linkChanged(QString)"); QString link; //we'll just send an empty string e << link; } } /** * Scans root directory for any tabs or applications. Will recursivly go down, * but will not follow symlinks. * @param directory - the directory to look in. * @param parent - the parent to place any new tabs or apps into. If parent is * NULL then the item is a tab and should be placed as a child of the window. */ void TabManager::rescanFolder(QString directory, QListViewItem* parent){ //odebug << QString("rescanFolder: ") + directory.latin1() << oendl; QDir d; d.setPath(directory); // Show hidden files for .directories d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); const QFileInfoList *list = d.entryInfoList(); QFileInfoListIterator it( *list ); // create list iterator QFileInfo *fi; // pointer for traversing while ( (fi=it.current()) ) { // for each file... // If it is a dir and not .. or . then add it as a tab and go down. if(fi->isDir()){ if(fi->fileName() != ".." && fi->fileName() != ".") { QListViewItem* newItem; if(!parent) newItem = new QListViewItem(tabList, fi->fileName()); else newItem = new QListViewItem(parent, fi->fileName()); itemList.insert(newItem, directory + "/" + fi->fileName() + "/.directory" ); rescanFolder(directory + "/" + fi->fileName(), newItem); } } else{ // it is a file, if not a .directory add to parent. // Change parents name and icon to reflect icon. if(fi->fileName() == ".directory"){ AppLnk app(directory + "/" + fi->fileName()); if(parent){ parent->setPixmap(0,app.pixmap()); parent->setText(0, app.name()); } } else{ // Add any desktop files found. QListViewItem* newItem; if(directory != HOME_APP_DIR){ if(!parent) newItem = new QListViewItem(tabList, fi->fileName()); else newItem = new QListViewItem(parent, fi->fileName()); if(fi->fileName().right(APPLICATION_EXTENSION_LENGTH) == APPLICATION_EXTENSION){ AppLnk app(directory + "/" + fi->fileName()); newItem->setPixmap(0,app.pixmap()); newItem->setText(0, app.name()); itemList.insert(newItem, directory + "/" + fi->fileName()); } } } } ++it; // goto next list element } } /** * Create a new blank Tab. * Create a physical folder with .directory file * Create a item on the list */ void TabManager::newFolder(){ QDir r; r.mkdir(QString(HOME_APP_DIR) + "/" + NEW_FOLDER); system((QString("echo [Desktop Entry] | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); system((QString("echo Name=" NEW_FOLDER " | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); QString homeLocation = QString(HOME_APP_DIR) + "/" + NEW_FOLDER + "/.directory"; QListViewItem *newItem = new QListViewItem(tabList, NEW_FOLDER); itemList.insert(newItem, homeLocation ); // We have changed something. changed = true; } /** * Create a new blank application * Make sure a tab is selected * create physical file * fill file with default information (entry, name, type). */ void TabManager::newApplication(){ QListViewItem *item = tabList->currentItem(); if(!item || item->parent()) return; QString parentDir = itemList[item].mid(0,itemList[item].length()-11); QString homeLocation = parentDir + "/" NEW_APPLICATION APPLICATION_EXTENSION; system((QString("echo [Desktop Entry] | cat >> ") + homeLocation).latin1()); system((QString("echo Name=" NEW_APPLICATION " | cat >> ") + homeLocation).latin1()); int slash = parentDir.findRev('/', -1); QString folderName = parentDir.mid(slash+1, parentDir.length()); system((QString("echo Type=") + folderName + " | cat >> " + homeLocation).latin1()); // Insert into the tree QListViewItem *newItem = new QListViewItem(item, NEW_APPLICATION); itemList.insert(newItem, homeLocation ); // We have changed something. changed = true; } /** * Remove the item. * Check if we can * Prompt user * Delete physical file (Dir, remove .dir, then dir. File, remove file) * Remove from installer if need too. */ void TabManager::removeItem(){ // Make sure we can delete QListViewItem *item = tabList->currentItem(); if(!item) return; if(item->childCount() > 0){ QMessageBox::critical(this, tr("Message"), tr("Can't remove with applications\nstill in the group."), tr("Ok") ); return; } // Prompt. int answer = QMessageBox::warning(this, tr("Message"), tr("Are you sure you want to delete?"), tr("Yes"), tr("Cancel"), 0, 1 ); if (answer) return; bool removeSuccessful = true; QString location = itemList[item]; // Remove file (.directory in a Directory case) if(!QFile::remove(location)) removeSuccessful = false; // Remove directory if(item->parent() == NULL){ // Remove .directory file string location = location.mid(0,location.length()-10); QDir dir; if(!dir.rmdir(location)) removeSuccessful = false; else removeSuccessful = true; } // If removing failed. if(!removeSuccessful){ odebug << (QString("removeItem: ") + location).latin1() << oendl; QMessageBox::critical(this, tr("Message"), tr("Can't remove."), tr("Ok") ); return; } // Remove from the installer so it wont fail. // Don't need to do this sense the current install uses rm -f so no error // Remove from the gui list. itemList.remove(item); if(item->parent()) item->parent()->takeItem(item); delete item; // We have changed something. changed = true; } /** * Helper function. Edits the current item. * calls editItem with the currently selected item. */ void TabManager::editCurrentItem(){ editItem(tabList->currentItem()); } /** * Edit the item that is passed in. * Show application dialog and if anything changed * @param item the item to edit. */ void TabManager::editItem( QListViewItem * item){ if(!item) return; TabAppLnk app(itemList[item]); if(!app.isValid()){ odebug << QString("editItem: Not a valid applnk file: ") + itemList[item].latin1() << oendl; return; } // Fill with all of the icons if(!application){ Wait waitDialog(this, "Wait dialog"); waitDialog.waitLabel->setText(tr("Gathering icons...")); waitDialog.show(); qApp->processEvents(); application = new AppEdit(this, "Application edit", true); QDir d(QPEApplication::qpeDir() + "/pics/"); d.setFilter( QDir::Files); 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 @@ -1,12 +1,12 @@ TEMPLATE = app CONFIG = qt warn_on HEADERS = tabmanager.h tabmainwindow.h tablistview.h tabmanagerbase.h tabapplnk.h SOURCES = main.cpp tabmanager.cpp tabmanagerbase.cpp INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include -LIBS += -lqpe +LIBS += -lqpe -lopiecore2 INTERFACES = app.ui wait.ui TARGET = tabmanager DESTDIR = $(OPIEDIR)/bin include ( $(OPIEDIR)/include.pro ) |