summaryrefslogtreecommitdiff
path: root/noncore/settings/tabmanager/tabmanager.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/tabmanager/tabmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/tabmanager/tabmanager.cpp247
1 files changed, 149 insertions, 98 deletions
diff --git a/noncore/settings/tabmanager/tabmanager.cpp b/noncore/settings/tabmanager/tabmanager.cpp
index 13aae81..5f0899c 100644
--- a/noncore/settings/tabmanager/tabmanager.cpp
+++ b/noncore/settings/tabmanager/tabmanager.cpp
@@ -2,2 +2,3 @@
#include "app.h"
+#include "wait.h"
#include "tabapplnk.h"
@@ -5,3 +6,2 @@
#include <qpe/applnk.h>
-#include <qpe/qpeapplication.h>
#include <qdir.h>
@@ -11,2 +11,3 @@
#include <qheader.h>
+#include <qcombobox.h>
#include <qlineedit.h>
@@ -16,4 +17,7 @@
#include <qpe/qcopenvelope_qws.h>
+#include <qpe/qpeapplication.h>
+#include <qpe/resource.h>
-#define HOME_APP_DIR QPEApplication::qpeDir()+"/apps" // <-- made this a little more flexible
+
+#define HOME_APP_DIR QPEApplication::qpeDir()+"/apps"
#define HOME_APP_INSTALL_DIR "/usr/lib/ipkg/info"
@@ -28,3 +32,3 @@
*/
-TabManager::TabManager( QWidget* parent, const char* name):TabManagerBase(parent, name), changed(false){
+TabManager::TabManager( QWidget* parent, const char* name):TabManagerBase(parent, name), changed(false), application(NULL){
rescanFolder(HOME_APP_DIR);
@@ -32,7 +36,5 @@ TabManager::TabManager( QWidget* parent, const char* name):TabManagerBase(parent
// Connect the signals and slots
- connect(tabList, SIGNAL(doubleClicked(QListViewItem *)),
- this, SLOT(editItem(QListViewItem*)));
+ connect(tabList, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(editItem(QListViewItem*)));
(tabList->header())->hide();
- connect(tabList, SIGNAL(moveItem(QListViewItem *, QListViewItem *)),
- this, SLOT(moveApplication(QListViewItem *, QListViewItem *)));
+ connect(tabList, SIGNAL(moveItem(QListViewItem *, QListViewItem *)), this, SLOT(moveApplication(QListViewItem *, QListViewItem *)));
}
@@ -45,6 +47,7 @@ TabManager::~TabManager(){
if(changed){
- //QMessageBox::critical(this, tr("Message"), tr("Please restart Qtopia to see all new changes."),tr("Ok") );
- //filename = fn;
+ // Prompt.
+ //int answer = QMessageBox::warning(this, "Message", "Should your desktop be","Yes", "Cancel", 0, 1 );
+ //if (answer)
+ // return;
QCopEnvelope e("QPE/System", "linkChanged(QString)");
- //e << description << filename << mimetype;
QString link; //we'll just send an empty string
@@ -63,3 +66,3 @@ void TabManager::rescanFolder(QString directory, QListViewItem* parent){
//qDebug(QString("rescanFolder: ") + directory.latin1());
-
+
QDir d;
@@ -78,8 +81,8 @@ void TabManager::rescanFolder(QString directory, QListViewItem* parent){
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);
+ 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);
}
@@ -88,7 +91,7 @@ void TabManager::rescanFolder(QString directory, QListViewItem* parent){
// 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){
+ AppLnk app(directory + "/" + fi->fileName());
+ if(parent){
parent->setPixmap(0,app.pixmap());
@@ -98,6 +101,6 @@ void TabManager::rescanFolder(QString directory, QListViewItem* parent){
else{
- // Add any desktop files found.
+ // Add any desktop files found.
QListViewItem* newItem;
- if(directory != HOME_APP_DIR){
- if(!parent)
+ if(directory != HOME_APP_DIR){
+ if(!parent)
newItem = new QListViewItem(tabList, fi->fileName());
@@ -109,5 +112,5 @@ void TabManager::rescanFolder(QString directory, QListViewItem* parent){
newItem->setText(0, app.name());
- itemList.insert(newItem, directory + "/" + fi->fileName());
- }
- }
+ itemList.insert(newItem, directory + "/" + fi->fileName());
+ }
+ }
}
@@ -128,3 +131,3 @@ void TabManager::newFolder(){
system((QString("echo Name=" NEW_FOLDER " | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1());
-
+
QString homeLocation = QString(HOME_APP_DIR) + "/" + NEW_FOLDER + "/.directory";
@@ -132,3 +135,3 @@ void TabManager::newFolder(){
itemList.insert(newItem, homeLocation );
-
+
// We have changed something.
@@ -147,4 +150,4 @@ void TabManager::newApplication(){
return;
-
- QString parentDir = itemList[item].mid(0,itemList[item].length()-11);
+
+ QString parentDir = itemList[item].mid(0,itemList[item].length()-11);
QString homeLocation = parentDir + "/" NEW_APPLICATION APPLICATION_EXTENSION;
@@ -154,5 +157,5 @@ void TabManager::newApplication(){
QString folderName = parentDir.mid(slash+1, parentDir.length());
-
+
system((QString("echo Type=") + folderName + " | cat >> " + homeLocation).latin1());
-
+
// Insert into the tree
@@ -160,3 +163,3 @@ void TabManager::newApplication(){
itemList.insert(newItem, homeLocation );
-
+
// We have changed something.
@@ -171,3 +174,3 @@ void TabManager::newApplication(){
* Remove from installer if need too.
- */
+ */
void TabManager::removeItem(){
@@ -178,13 +181,11 @@ void TabManager::removeItem(){
if(item->childCount() > 0){
- QMessageBox::critical(this, tr("Message"), tr("Can't remove with applications\nstill in the group."),
- tr("Ok") );
- return;
+ 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 );
+ 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 removeSuccessfull = true;
@@ -194,3 +195,3 @@ void TabManager::removeItem(){
removeSuccessfull = false;
-
+
// Remove directory
@@ -204,16 +205,14 @@ void TabManager::removeItem(){
removeSuccessfull = true;
-
}
-
- // If removing failed.
+
+ // If removing failed.
if(!removeSuccessfull){
qDebug((QString("removeItem: ") + location).latin1());
- QMessageBox::critical(this, tr("Message"), tr("Can't remove."),
- tr("Ok") );
+ 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.
@@ -223,3 +222,3 @@ void TabManager::removeItem(){
delete item;
-
+
// We have changed something.
@@ -238,5 +237,5 @@ void TabManager::editCurrentItem(){
* Edit the item that is passed in.
- * Show application dialog and if anything changed
+ * Show application dialog and if anything changed
* @param item the item to edit.
- */
+ */
void TabManager::editItem( QListViewItem * item){
@@ -244,3 +243,3 @@ void TabManager::editItem( QListViewItem * item){
return;
-
+
TabAppLnk app(itemList[item]);
@@ -248,19 +247,73 @@ void TabManager::editItem( QListViewItem * item){
qDebug(QString("editItem: Not a valid applnk file: ") + itemList[item].latin1());
- return;
+ 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);
+
+ const QFileInfoList *list = d.entryInfoList();
+ QFileInfoListIterator it( *list ); // create list iterator
+ QFileInfo *fi; // pointer for traversing
+
+ while ( (fi=it.current()) ) { // for each file...
+ QString fileName = fi->fileName();
+ if(fileName.right(4) == ".png"){
+ fileName = fileName.mid(0,fileName.length()-4);
+ QPixmap imageOfFile(Resource::loadPixmap(fileName));
+ QImage foo = imageOfFile.convertToImage();
+ foo = foo.smoothScale(16,16);
+ imageOfFile.convertFromImage(foo);
+ application->iconLineEdit->insertItem(imageOfFile,fileName);
+ }
+ //qDebug(fi->fileName().latin1());
+ ++it;
+ }
+ waitDialog.hide();
}
-
- AppEdit application(this, tr("Application edit"), true);
- application.nameLineEdit->setText(app.name());
- application.iconLineEdit->setText(app.pixmapString());
- application.execLineEdit->setText(app.exec());
- application.commentLineEdit->setText(app.comment());
-
+ int pixmap = -1;
+ QString pixmapText = app.pixmapString();
+ QComboBox *f = application->iconLineEdit;
+ for(int i = 0; i < application->iconLineEdit->count(); i++){
+ if(f->text(i) == pixmapText){
+ pixmap = i;
+ break;
+ }
+ }
+ if(pixmap != -1)
+ application->iconLineEdit->setCurrentItem(pixmap);
+ else{
+ QPixmap imageOfFile(Resource::loadPixmap(pixmapText));
+ QImage foo = imageOfFile.convertToImage();
+ foo = foo.smoothScale(16,16);
+ imageOfFile.convertFromImage(foo);
+ application->iconLineEdit->insertItem(imageOfFile,pixmapText,0);
+ application->iconLineEdit->setCurrentItem(0);
+ }
+
+ application->nameLineEdit->setText(app.name());
+ application->execLineEdit->setText(app.exec());
+ application->commentLineEdit->setText(app.comment());
+
if(item->parent() == NULL){
- application.execLineEdit->setEnabled(false);
- application.TextLabel3->setEnabled(false);
- application.setCaption(tr("Tab"));
+ application->execLineEdit->setEnabled(false);
+ application->TextLabel3->setEnabled(false);
+ application->setCaption(tr("Tab"));
}
-
+ else{
+ application->execLineEdit->setEnabled(true);
+ application->TextLabel3->setEnabled(true);
+ application->setCaption(tr("Application"));
+ }
+
// Only do somthing if they hit OK
- if(application.exec() == 0)
+ application->showMaximized();
+ if(application->exec() == 0)
return;
@@ -268,6 +321,6 @@ void TabManager::editItem( QListViewItem * item){
// If nothing has changed exit (hmmm why did they hit ok?)
- if(app.name() == application.nameLineEdit->text() &&
- app.pixmapString() == application.iconLineEdit->text() &&
- app.comment() == application.commentLineEdit->text() &&
- app.exec() == application.execLineEdit->text())
+ if(app.name() == application->nameLineEdit->text() &&
+ app.pixmapString() == application->iconLineEdit->currentText() &&
+ app.comment() == application->commentLineEdit->text() &&
+ app.exec() == application->execLineEdit->text())
return;
@@ -276,12 +329,11 @@ void TabManager::editItem( QListViewItem * item){
QString oldName = app.name();
- app.setName(application.nameLineEdit->text());
- app.setIcon(application.iconLineEdit->text());
- app.setComment(application.commentLineEdit->text());
- app.setExec(application.execLineEdit->text());
+ app.setName(application->nameLineEdit->text());
+ app.setIcon(application->iconLineEdit->currentText());
+ app.setComment(application->commentLineEdit->text());
+ app.setExec(application->execLineEdit->text());
if(!app.writeLink()){
- QMessageBox::critical(this, tr("Message"), tr("Can't save."),
- tr("Ok") );
+ QMessageBox::critical(this, tr("Message"), "Can't save.", tr("Ok") );
return;
}
-
+
// Update the gui icon and name
@@ -289,6 +341,6 @@ void TabManager::editItem( QListViewItem * item){
item->setPixmap(0,app.pixmap());
-
+
// We have changed something.
changed = true;
-
+
// If we were dealing with a new folder or new application change
@@ -318,3 +370,3 @@ void TabManager::editItem( QListViewItem * item){
}
-
+
/**
@@ -324,3 +376,3 @@ void TabManager::editItem( QListViewItem * item){
* @pearam newGroup the new parent of this application
- */
+ */
void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
@@ -328,3 +380,3 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
if(!item || !item->parent() || newGroup->parent())
- return;
+ return;
if(item->parent() == newGroup)
@@ -332,3 +384,3 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
- // Get the new folder, new file name,
+ // Get the new folder, new file name,
QString newFolder = itemList[newGroup];
@@ -337,3 +389,3 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
QString folderName = newFolder.mid(slash+1, newFolder.length());
-
+
QString desktopFile = itemList[item];
@@ -346,5 +398,4 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
if(!r.rename(itemList[item], newFolder)){
- QMessageBox::critical(this, tr("Message"), tr("Can't move application."),
- tr("Ok") );
- return;
+ QMessageBox::critical(this, tr("Message"), "Can't move application.", tr("Ok") );
+ return;
}
@@ -352,3 +403,3 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
//qDebug((QString("moveApplication: ") + newFolder).latin1());
-
+
// Move in the gui
@@ -357,3 +408,3 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
newGroup->setOpen(true);
-
+
// Move file in the installer
@@ -363,5 +414,5 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
else
- qDebug("moveApplication: No installed app found for dekstop file");
-
- // Move application type
+ qDebug("moveApplication: No installed app found for dekstop file");
+
+ // Move application type
AppLnk app(newFolder);
@@ -369,3 +420,3 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
app.writeLink();
-
+
// Move in our internal list
@@ -373,3 +424,3 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
itemList.insert(item, newFolder);
-
+
// We have changed something.
@@ -385,5 +436,5 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
* @return true if successfull, false if file not found.
- */
+ */
bool TabManager::findInstalledApplication(QString desktopFile, QString &installedAppFile){
-
+
QDir d;
@@ -421,3 +472,3 @@ bool TabManager::findInstalledApplication(QString desktopFile, QString &installe
* @param installedAppFile application installed list
- * @param desktopFile old .desktop file
+ * @param desktopFile old .desktop file
* @param newLocation new .desktop file
@@ -430,3 +481,3 @@ void TabManager::swapInstalledLocation( QString installedAppFile, QString deskto
}
-
+
QTextStream stream( &file ); // use a text stream