summaryrefslogtreecommitdiff
path: root/noncore/settings/tabmanager/tabmanager.cpp
Unidiff
Diffstat (limited to 'noncore/settings/tabmanager/tabmanager.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/tabmanager/tabmanager.cpp127
1 files changed, 89 insertions, 38 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
@@ -1,55 +1,58 @@
1#include "tabmanager.h" 1#include "tabmanager.h"
2#include "app.h" 2#include "app.h"
3#include "wait.h"
3#include "tabapplnk.h" 4#include "tabapplnk.h"
4 5
5#include <qpe/applnk.h> 6#include <qpe/applnk.h>
6#include <qpe/qpeapplication.h>
7#include <qdir.h> 7#include <qdir.h>
8#include <qfile.h> 8#include <qfile.h>
9#include <qtextstream.h> 9#include <qtextstream.h>
10#include <qlistview.h> 10#include <qlistview.h>
11#include <qheader.h> 11#include <qheader.h>
12#include <qcombobox.h>
12#include <qlineedit.h> 13#include <qlineedit.h>
13#include <qlabel.h> 14#include <qlabel.h>
14#include <qmessagebox.h> 15#include <qmessagebox.h>
15#include <stdlib.h> 16#include <stdlib.h>
16#include <qpe/qcopenvelope_qws.h> 17#include <qpe/qcopenvelope_qws.h>
18#include <qpe/qpeapplication.h>
19#include <qpe/resource.h>
20
17 21
18#define HOME_APP_DIR QPEApplication::qpeDir()+"/apps" // <-- made this a little more flexible 22#define HOME_APP_DIR QPEApplication::qpeDir()+"/apps"
19#define HOME_APP_INSTALL_DIR "/usr/lib/ipkg/info" 23#define HOME_APP_INSTALL_DIR "/usr/lib/ipkg/info"
20#define NEW_FOLDER "EmptyTab" 24#define NEW_FOLDER "EmptyTab"
21#define NEW_APPLICATION "NewApp" 25#define NEW_APPLICATION "NewApp"
22#define APPLICATION_EXTENSION ".desktop" 26#define APPLICATION_EXTENSION ".desktop"
23#define APPLICATION_EXTENSION_LENGTH 8 27#define APPLICATION_EXTENSION_LENGTH 8
24 28
25/** 29/**
26 * Constructor. Sets up signals. Performs initial scan of applications 30 * Constructor. Sets up signals. Performs initial scan of applications
27 * and tabs 31 * and tabs
28 */ 32 */
29TabManager::TabManager( QWidget* parent, const char* name):TabManagerBase(parent, name), changed(false){ 33TabManager::TabManager( QWidget* parent, const char* name):TabManagerBase(parent, name), changed(false), application(NULL){
30 rescanFolder(HOME_APP_DIR); 34 rescanFolder(HOME_APP_DIR);
31 35
32 // Connect the signals and slots 36 // Connect the signals and slots
33 connect(tabList, SIGNAL(doubleClicked(QListViewItem *)), 37 connect(tabList, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(editItem(QListViewItem*)));
34 this, SLOT(editItem(QListViewItem*)));
35 (tabList->header())->hide(); 38 (tabList->header())->hide();
36 connect(tabList, SIGNAL(moveItem(QListViewItem *, QListViewItem *)), 39 connect(tabList, SIGNAL(moveItem(QListViewItem *, QListViewItem *)), this, SLOT(moveApplication(QListViewItem *, QListViewItem *)));
37 this, SLOT(moveApplication(QListViewItem *, QListViewItem *)));
38} 40}
39 41
40/** 42/**
41 * If anything in the tab's have been changed then update the system or alert 43 * If anything in the tab's have been changed then update the system or alert
42 * the user. 44 * the user.
43 */ 45 */
44TabManager::~TabManager(){ 46TabManager::~TabManager(){
45 if(changed){ 47 if(changed){
46 //QMessageBox::critical(this, tr("Message"), tr("Please restart Qtopia to see all new changes."),tr("Ok") ); 48 // Prompt.
47 //filename = fn; 49 //int answer = QMessageBox::warning(this, "Message", "Should your desktop be","Yes", "Cancel", 0, 1 );
50 //if (answer)
51 // return;
48 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 52 QCopEnvelope e("QPE/System", "linkChanged(QString)");
49 //e << description << filename << mimetype;
50 QString link; //we'll just send an empty string 53 QString link; //we'll just send an empty string
51 e << link; 54 e << link;
52 } 55 }
53} 56}
54 57
55/** 58/**
@@ -173,20 +176,18 @@ void TabManager::newApplication(){
173void TabManager::removeItem(){ 176void TabManager::removeItem(){
174 // Make sure we can delete 177 // Make sure we can delete
175 QListViewItem *item = tabList->currentItem(); 178 QListViewItem *item = tabList->currentItem();
176 if(!item) 179 if(!item)
177 return; 180 return;
178 if(item->childCount() > 0){ 181 if(item->childCount() > 0){
179 QMessageBox::critical(this, tr("Message"), tr("Can't remove with applications\nstill in the group."), 182 QMessageBox::critical(this, tr("Message"), tr("Can't remove with applications\nstill in the group."), tr("Ok") );
180 tr("Ok") );
181 return; 183 return;
182 } 184 }
183 185
184 // Prompt. 186 // Prompt.
185 int answer = QMessageBox::warning(this, tr("Message"), tr("Are you sure you want to delete?"), 187 int answer = QMessageBox::warning(this, tr("Message"), tr("Are you sure you want to delete?"), tr("Yes"), tr("Cancel"), 0, 1 );
186 tr("Yes"), tr("Cancel"), 0, 1 );
187 if (answer) 188 if (answer)
188 return; 189 return;
189 190
190 bool removeSuccessfull = true; 191 bool removeSuccessfull = true;
191 QString location = itemList[item]; 192 QString location = itemList[item];
192 // Remove file (.directory in a Directory case) 193 // Remove file (.directory in a Directory case)
@@ -199,20 +200,18 @@ void TabManager::removeItem(){
199 location = location.mid(0,location.length()-10); 200 location = location.mid(0,location.length()-10);
200 QDir dir; 201 QDir dir;
201 if(!dir.rmdir(location)) 202 if(!dir.rmdir(location))
202 removeSuccessfull = false; 203 removeSuccessfull = false;
203 else 204 else
204 removeSuccessfull = true; 205 removeSuccessfull = true;
205
206 } 206 }
207 207
208 // If removing failed. 208 // If removing failed.
209 if(!removeSuccessfull){ 209 if(!removeSuccessfull){
210 qDebug((QString("removeItem: ") + location).latin1()); 210 qDebug((QString("removeItem: ") + location).latin1());
211 QMessageBox::critical(this, tr("Message"), tr("Can't remove."), 211 QMessageBox::critical(this, tr("Message"), tr("Can't remove."), tr("Ok") );
212 tr("Ok") );
213 return; 212 return;
214 } 213 }
215 214
216 // Remove from the installer so it wont fail. 215 // Remove from the installer so it wont fail.
217 // 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
218 217
@@ -246,44 +245,97 @@ void TabManager::editItem( QListViewItem * item){
246 TabAppLnk app(itemList[item]); 245 TabAppLnk app(itemList[item]);
247 if(!app.isValid()){ 246 if(!app.isValid()){
248 qDebug(QString("editItem: Not a valid applnk file: ") + itemList[item].latin1()); 247 qDebug(QString("editItem: Not a valid applnk file: ") + itemList[item].latin1());
249 return; 248 return;
250 } 249 }
251 250
252 AppEdit application(this, tr("Application edit"), true); 251 // Fill with all of the icons
253 application.nameLineEdit->setText(app.name()); 252 if(!application){
254 application.iconLineEdit->setText(app.pixmapString()); 253 Wait waitDialog(this, "Wait dialog");
255 application.execLineEdit->setText(app.exec()); 254 waitDialog.waitLabel->setText(tr("Gathering icons..."));
256 application.commentLineEdit->setText(app.comment()); 255 waitDialog.show();
256 qApp->processEvents();
257 application = new AppEdit(this, "Application edit", true);
258
259 QDir d(QPEApplication::qpeDir() + "/pics/");
260 d.setFilter( QDir::Files);
261
262 const QFileInfoList *list = d.entryInfoList();
263 QFileInfoListIterator it( *list ); // create list iterator
264 QFileInfo *fi; // pointer for traversing
265
266 while ( (fi=it.current()) ) { // for each file...
267 QString fileName = fi->fileName();
268 if(fileName.right(4) == ".png"){
269 fileName = fileName.mid(0,fileName.length()-4);
270 QPixmap imageOfFile(Resource::loadPixmap(fileName));
271 QImage foo = imageOfFile.convertToImage();
272 foo = foo.smoothScale(16,16);
273 imageOfFile.convertFromImage(foo);
274 application->iconLineEdit->insertItem(imageOfFile,fileName);
275 }
276 //qDebug(fi->fileName().latin1());
277 ++it;
278 }
279 waitDialog.hide();
280 }
281 int pixmap = -1;
282 QString pixmapText = app.pixmapString();
283 QComboBox *f = application->iconLineEdit;
284 for(int i = 0; i < application->iconLineEdit->count(); i++){
285 if(f->text(i) == pixmapText){
286 pixmap = i;
287 break;
288 }
289 }
290 if(pixmap != -1)
291 application->iconLineEdit->setCurrentItem(pixmap);
292 else{
293 QPixmap imageOfFile(Resource::loadPixmap(pixmapText));
294 QImage foo = imageOfFile.convertToImage();
295 foo = foo.smoothScale(16,16);
296 imageOfFile.convertFromImage(foo);
297 application->iconLineEdit->insertItem(imageOfFile,pixmapText,0);
298 application->iconLineEdit->setCurrentItem(0);
299 }
300
301 application->nameLineEdit->setText(app.name());
302 application->execLineEdit->setText(app.exec());
303 application->commentLineEdit->setText(app.comment());
257 304
258 if(item->parent() == NULL){ 305 if(item->parent() == NULL){
259 application.execLineEdit->setEnabled(false); 306 application->execLineEdit->setEnabled(false);
260 application.TextLabel3->setEnabled(false); 307 application->TextLabel3->setEnabled(false);
261 application.setCaption(tr("Tab")); 308 application->setCaption(tr("Tab"));
309 }
310 else{
311 application->execLineEdit->setEnabled(true);
312 application->TextLabel3->setEnabled(true);
313 application->setCaption(tr("Application"));
262 } 314 }
263 315
264 // Only do somthing if they hit OK 316 // Only do somthing if they hit OK
265 if(application.exec() == 0) 317 application->showMaximized();
318 if(application->exec() == 0)
266 return; 319 return;
267 320
268 // If nothing has changed exit (hmmm why did they hit ok?) 321 // If nothing has changed exit (hmmm why did they hit ok?)
269 if(app.name() == application.nameLineEdit->text() && 322 if(app.name() == application->nameLineEdit->text() &&
270 app.pixmapString() == application.iconLineEdit->text() && 323 app.pixmapString() == application->iconLineEdit->currentText() &&
271 app.comment() == application.commentLineEdit->text() && 324 app.comment() == application->commentLineEdit->text() &&
272 app.exec() == application.execLineEdit->text()) 325 app.exec() == application->execLineEdit->text())
273 return; 326 return;
274 327
275 // Change the applnk file 328 // Change the applnk file
276 QString oldName = app.name(); 329 QString oldName = app.name();
277 app.setName(application.nameLineEdit->text()); 330 app.setName(application->nameLineEdit->text());
278 app.setIcon(application.iconLineEdit->text()); 331 app.setIcon(application->iconLineEdit->currentText());
279 app.setComment(application.commentLineEdit->text()); 332 app.setComment(application->commentLineEdit->text());
280 app.setExec(application.execLineEdit->text()); 333 app.setExec(application->execLineEdit->text());
281 if(!app.writeLink()){ 334 if(!app.writeLink()){
282 QMessageBox::critical(this, tr("Message"), tr("Can't save."), 335 QMessageBox::critical(this, tr("Message"), "Can't save.", tr("Ok") );
283 tr("Ok") );
284 return; 336 return;
285 } 337 }
286 338
287 // Update the gui icon and name 339 // Update the gui icon and name
288 item->setText(0,app.name()); 340 item->setText(0,app.name());
289 item->setPixmap(0,app.pixmap()); 341 item->setPixmap(0,app.pixmap());
@@ -341,14 +393,13 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
341 desktopFile = desktopFile.mid(slash, desktopFile.length()); 393 desktopFile = desktopFile.mid(slash, desktopFile.length());
342 newFolder = newFolder + desktopFile; 394 newFolder = newFolder + desktopFile;
343 395
344 // Move file 396 // Move file
345 QDir r; 397 QDir r;
346 if(!r.rename(itemList[item], newFolder)){ 398 if(!r.rename(itemList[item], newFolder)){
347 QMessageBox::critical(this, tr("Message"), tr("Can't move application."), 399 QMessageBox::critical(this, tr("Message"), "Can't move application.", tr("Ok") );
348 tr("Ok") );
349 return; 400 return;
350 } 401 }
351 //qDebug((QString("moveApplication: ") + itemList[item]).latin1()); 402 //qDebug((QString("moveApplication: ") + itemList[item]).latin1());
352 //qDebug((QString("moveApplication: ") + newFolder).latin1()); 403 //qDebug((QString("moveApplication: ") + newFolder).latin1());
353 404
354 // Move in the gui 405 // Move in the gui