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.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 @@
2#include "app.h" 2#include "app.h"
3#include "wait.h"
3#include "tabapplnk.h" 4#include "tabapplnk.h"
@@ -5,3 +6,2 @@
5#include <qpe/applnk.h> 6#include <qpe/applnk.h>
6#include <qpe/qpeapplication.h>
7#include <qdir.h> 7#include <qdir.h>
@@ -11,2 +11,3 @@
11#include <qheader.h> 11#include <qheader.h>
12#include <qcombobox.h>
12#include <qlineedit.h> 13#include <qlineedit.h>
@@ -16,4 +17,7 @@
16#include <qpe/qcopenvelope_qws.h> 17#include <qpe/qcopenvelope_qws.h>
18#include <qpe/qpeapplication.h>
19#include <qpe/resource.h>
17 20
18#define HOME_APP_DIR QPEApplication::qpeDir()+"/apps" // <-- made this a little more flexible 21
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"
@@ -28,3 +32,3 @@
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);
@@ -32,7 +36,5 @@ TabManager::TabManager( QWidget* parent, const char* name):TabManagerBase(parent
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}
@@ -45,6 +47,7 @@ TabManager::~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
@@ -63,3 +66,3 @@ void TabManager::rescanFolder(QString directory, QListViewItem* parent){
63 //qDebug(QString("rescanFolder: ") + directory.latin1()); 66 //qDebug(QString("rescanFolder: ") + directory.latin1());
64 67
65 QDir d; 68 QDir d;
@@ -78,8 +81,8 @@ void TabManager::rescanFolder(QString directory, QListViewItem* parent){
78 QListViewItem* newItem; 81 QListViewItem* newItem;
79 if(!parent) 82 if(!parent)
80 newItem = new QListViewItem(tabList, fi->fileName()); 83 newItem = new QListViewItem(tabList, fi->fileName());
81 else 84 else
82 newItem = new QListViewItem(parent, fi->fileName()); 85 newItem = new QListViewItem(parent, fi->fileName());
83 itemList.insert(newItem, directory + "/" + fi->fileName() + "/.directory" ); 86 itemList.insert(newItem, directory + "/" + fi->fileName() + "/.directory" );
84 rescanFolder(directory + "/" + fi->fileName(), newItem); 87 rescanFolder(directory + "/" + fi->fileName(), newItem);
85 } 88 }
@@ -88,7 +91,7 @@ void TabManager::rescanFolder(QString directory, QListViewItem* parent){
88 // it is a file, if not a .directory add to parent. 91 // it is a file, if not a .directory add to parent.
89 92
90 // Change parents name and icon to reflect icon. 93 // Change parents name and icon to reflect icon.
91 if(fi->fileName() == ".directory"){ 94 if(fi->fileName() == ".directory"){
92 AppLnk app(directory + "/" + fi->fileName()); 95 AppLnk app(directory + "/" + fi->fileName());
93 if(parent){ 96 if(parent){
94 parent->setPixmap(0,app.pixmap()); 97 parent->setPixmap(0,app.pixmap());
@@ -98,6 +101,6 @@ void TabManager::rescanFolder(QString directory, QListViewItem* parent){
98 else{ 101 else{
99 // Add any desktop files found. 102 // Add any desktop files found.
100 QListViewItem* newItem; 103 QListViewItem* newItem;
101 if(directory != HOME_APP_DIR){ 104 if(directory != HOME_APP_DIR){
102 if(!parent) 105 if(!parent)
103 newItem = new QListViewItem(tabList, fi->fileName()); 106 newItem = new QListViewItem(tabList, fi->fileName());
@@ -109,5 +112,5 @@ void TabManager::rescanFolder(QString directory, QListViewItem* parent){
109 newItem->setText(0, app.name()); 112 newItem->setText(0, app.name());
110 itemList.insert(newItem, directory + "/" + fi->fileName()); 113 itemList.insert(newItem, directory + "/" + fi->fileName());
111 } 114 }
112 } 115 }
113 } 116 }
@@ -128,3 +131,3 @@ void TabManager::newFolder(){
128 system((QString("echo Name=" NEW_FOLDER " | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); 131 system((QString("echo Name=" NEW_FOLDER " | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1());
129 132
130 QString homeLocation = QString(HOME_APP_DIR) + "/" + NEW_FOLDER + "/.directory"; 133 QString homeLocation = QString(HOME_APP_DIR) + "/" + NEW_FOLDER + "/.directory";
@@ -132,3 +135,3 @@ void TabManager::newFolder(){
132 itemList.insert(newItem, homeLocation ); 135 itemList.insert(newItem, homeLocation );
133 136
134 // We have changed something. 137 // We have changed something.
@@ -147,4 +150,4 @@ void TabManager::newApplication(){
147 return; 150 return;
148 151
149 QString parentDir = itemList[item].mid(0,itemList[item].length()-11); 152 QString parentDir = itemList[item].mid(0,itemList[item].length()-11);
150 QString homeLocation = parentDir + "/" NEW_APPLICATION APPLICATION_EXTENSION; 153 QString homeLocation = parentDir + "/" NEW_APPLICATION APPLICATION_EXTENSION;
@@ -154,5 +157,5 @@ void TabManager::newApplication(){
154 QString folderName = parentDir.mid(slash+1, parentDir.length()); 157 QString folderName = parentDir.mid(slash+1, parentDir.length());
155 158
156 system((QString("echo Type=") + folderName + " | cat >> " + homeLocation).latin1()); 159 system((QString("echo Type=") + folderName + " | cat >> " + homeLocation).latin1());
157 160
158 // Insert into the tree 161 // Insert into the tree
@@ -160,3 +163,3 @@ void TabManager::newApplication(){
160 itemList.insert(newItem, homeLocation ); 163 itemList.insert(newItem, homeLocation );
161 164
162 // We have changed something. 165 // We have changed something.
@@ -171,3 +174,3 @@ void TabManager::newApplication(){
171 * Remove from installer if need too. 174 * Remove from installer if need too.
172 */ 175 */
173void TabManager::removeItem(){ 176void TabManager::removeItem(){
@@ -178,13 +181,11 @@ void TabManager::removeItem(){
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") ); 183 return;
181 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;
@@ -194,3 +195,3 @@ void TabManager::removeItem(){
194 removeSuccessfull = false; 195 removeSuccessfull = false;
195 196
196 // Remove directory 197 // Remove directory
@@ -204,16 +205,14 @@ void TabManager::removeItem(){
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
219 // Remove from the gui list. 218 // Remove from the gui list.
@@ -223,3 +222,3 @@ void TabManager::removeItem(){
223 delete item; 222 delete item;
224 223
225 // We have changed something. 224 // We have changed something.
@@ -238,5 +237,5 @@ void TabManager::editCurrentItem(){
238 * Edit the item that is passed in. 237 * Edit the item that is passed in.
239 * Show application dialog and if anything changed 238 * Show application dialog and if anything changed
240 * @param item the item to edit. 239 * @param item the item to edit.
241 */ 240 */
242void TabManager::editItem( QListViewItem * item){ 241void TabManager::editItem( QListViewItem * item){
@@ -244,3 +243,3 @@ void TabManager::editItem( QListViewItem * item){
244 return; 243 return;
245 244
246 TabAppLnk app(itemList[item]); 245 TabAppLnk app(itemList[item]);
@@ -248,19 +247,73 @@ void TabManager::editItem( QListViewItem * item){
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;
249 }
250
251 // Fill with all of the icons
252 if(!application){
253 Wait waitDialog(this, "Wait dialog");
254 waitDialog.waitLabel->setText(tr("Gathering icons..."));
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();
250 } 280 }
251 281 int pixmap = -1;
252 AppEdit application(this, tr("Application edit"), true); 282 QString pixmapText = app.pixmapString();
253 application.nameLineEdit->setText(app.name()); 283 QComboBox *f = application->iconLineEdit;
254 application.iconLineEdit->setText(app.pixmapString()); 284 for(int i = 0; i < application->iconLineEdit->count(); i++){
255 application.execLineEdit->setText(app.exec()); 285 if(f->text(i) == pixmapText){
256 application.commentLineEdit->setText(app.comment()); 286 pixmap = i;
257 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());
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"));
262 } 309 }
263 310 else{
311 application->execLineEdit->setEnabled(true);
312 application->TextLabel3->setEnabled(true);
313 application->setCaption(tr("Application"));
314 }
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;
@@ -268,6 +321,6 @@ void TabManager::editItem( QListViewItem * item){
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;
@@ -276,12 +329,11 @@ void TabManager::editItem( QListViewItem * item){
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
@@ -289,6 +341,6 @@ void TabManager::editItem( QListViewItem * item){
289 item->setPixmap(0,app.pixmap()); 341 item->setPixmap(0,app.pixmap());
290 342
291 // We have changed something. 343 // We have changed something.
292 changed = true; 344 changed = true;
293 345
294 // If we were dealing with a new folder or new application change 346 // If we were dealing with a new folder or new application change
@@ -318,3 +370,3 @@ void TabManager::editItem( QListViewItem * item){
318} 370}
319 371
320/** 372/**
@@ -324,3 +376,3 @@ void TabManager::editItem( QListViewItem * item){
324 * @pearam newGroup the new parent of this application 376 * @pearam newGroup the new parent of this application
325 */ 377 */
326void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){ 378void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
@@ -328,3 +380,3 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
328 if(!item || !item->parent() || newGroup->parent()) 380 if(!item || !item->parent() || newGroup->parent())
329 return; 381 return;
330 if(item->parent() == newGroup) 382 if(item->parent() == newGroup)
@@ -332,3 +384,3 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
332 384
333 // Get the new folder, new file name, 385 // Get the new folder, new file name,
334 QString newFolder = itemList[newGroup]; 386 QString newFolder = itemList[newGroup];
@@ -337,3 +389,3 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
337 QString folderName = newFolder.mid(slash+1, newFolder.length()); 389 QString folderName = newFolder.mid(slash+1, newFolder.length());
338 390
339 QString desktopFile = itemList[item]; 391 QString desktopFile = itemList[item];
@@ -346,5 +398,4 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
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") ); 400 return;
349 return;
350 } 401 }
@@ -352,3 +403,3 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
352 //qDebug((QString("moveApplication: ") + newFolder).latin1()); 403 //qDebug((QString("moveApplication: ") + newFolder).latin1());
353 404
354 // Move in the gui 405 // Move in the gui
@@ -357,3 +408,3 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
357 newGroup->setOpen(true); 408 newGroup->setOpen(true);
358 409
359 // Move file in the installer 410 // Move file in the installer
@@ -363,5 +414,5 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
363 else 414 else
364 qDebug("moveApplication: No installed app found for dekstop file"); 415 qDebug("moveApplication: No installed app found for dekstop file");
365 416
366 // Move application type 417 // Move application type
367 AppLnk app(newFolder); 418 AppLnk app(newFolder);
@@ -369,3 +420,3 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
369 app.writeLink(); 420 app.writeLink();
370 421
371 // Move in our internal list 422 // Move in our internal list
@@ -373,3 +424,3 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
373 itemList.insert(item, newFolder); 424 itemList.insert(item, newFolder);
374 425
375 // We have changed something. 426 // We have changed something.
@@ -385,5 +436,5 @@ void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
385 * @return true if successfull, false if file not found. 436 * @return true if successfull, false if file not found.
386 */ 437 */
387bool TabManager::findInstalledApplication(QString desktopFile, QString &installedAppFile){ 438bool TabManager::findInstalledApplication(QString desktopFile, QString &installedAppFile){
388 439
389 QDir d; 440 QDir d;
@@ -421,3 +472,3 @@ bool TabManager::findInstalledApplication(QString desktopFile, QString &installe
421 * @param installedAppFile application installed list 472 * @param installedAppFile application installed list
422 * @param desktopFile old .desktop file 473 * @param desktopFile old .desktop file
423 * @param newLocation new .desktop file 474 * @param newLocation new .desktop file
@@ -430,3 +481,3 @@ void TabManager::swapInstalledLocation( QString installedAppFile, QString deskto
430 } 481 }
431 482
432 QTextStream stream( &file ); // use a text stream 483 QTextStream stream( &file ); // use a text stream