-rw-r--r-- | noncore/settings/tabmanager/tabmanager.cpp | 122 | ||||
-rw-r--r-- | noncore/settings/tabmanager/tabmanager.pro | 2 |
2 files changed, 63 insertions, 61 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,508 +1,510 @@ | |||
1 | #include "tabmanager.h" | 1 | #include "tabmanager.h" |
2 | #include "app.h" | 2 | #include "app.h" |
3 | #include "wait.h" | 3 | #include "wait.h" |
4 | #include "tabapplnk.h" | 4 | #include "tabapplnk.h" |
5 | 5 | ||
6 | #include <opie2/odebug.h> | ||
7 | |||
6 | #include <qpe/applnk.h> | 8 | #include <qpe/applnk.h> |
7 | #include <qdir.h> | 9 | #include <qdir.h> |
8 | #include <qfile.h> | 10 | #include <qfile.h> |
9 | #include <qtextstream.h> | 11 | #include <qtextstream.h> |
10 | #include <qlistview.h> | 12 | #include <qlistview.h> |
11 | #include <qheader.h> | 13 | #include <qheader.h> |
12 | #include <qcombobox.h> | 14 | #include <qcombobox.h> |
13 | #include <qlineedit.h> | 15 | #include <qlineedit.h> |
14 | #include <qlabel.h> | 16 | #include <qlabel.h> |
15 | #include <qmessagebox.h> | 17 | #include <qmessagebox.h> |
16 | #include <stdlib.h> | 18 | #include <stdlib.h> |
17 | #include <qpe/qcopenvelope_qws.h> | 19 | #include <qpe/qcopenvelope_qws.h> |
18 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
19 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
20 | 22 | ||
21 | 23 | ||
22 | #define HOME_APP_DIR QPEApplication::qpeDir()+"/apps" | 24 | #define HOME_APP_DIR QPEApplication::qpeDir()+"/apps" |
23 | #define HOME_APP_INSTALL_DIR "/usr/lib/ipkg/info" | 25 | #define HOME_APP_INSTALL_DIR "/usr/lib/ipkg/info" |
24 | #define NEW_FOLDER "EmptyTab" | 26 | #define NEW_FOLDER "EmptyTab" |
25 | #define NEW_APPLICATION "NewApp" | 27 | #define NEW_APPLICATION "NewApp" |
26 | #define APPLICATION_EXTENSION ".desktop" | 28 | #define APPLICATION_EXTENSION ".desktop" |
27 | #define APPLICATION_EXTENSION_LENGTH 8 | 29 | #define APPLICATION_EXTENSION_LENGTH 8 |
28 | 30 | ||
29 | /** | 31 | /** |
30 | * Constructor. Sets up signals. Performs initial scan of applications | 32 | * Constructor. Sets up signals. Performs initial scan of applications |
31 | * and tabs | 33 | * and tabs |
32 | */ | 34 | */ |
33 | TabManager::TabManager( QWidget* parent, const char* name):TabManagerBase(parent, name), changed(false), application(NULL){ | 35 | TabManager::TabManager( QWidget* parent, const char* name):TabManagerBase(parent, name), changed(false), application(NULL){ |
34 | rescanFolder(HOME_APP_DIR); | 36 | rescanFolder(HOME_APP_DIR); |
35 | 37 | ||
36 | // Connect the signals and slots | 38 | // Connect the signals and slots |
37 | connect(tabList, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(editItem(QListViewItem*))); | 39 | connect(tabList, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(editItem(QListViewItem*))); |
38 | (tabList->header())->hide(); | 40 | (tabList->header())->hide(); |
39 | connect(tabList, SIGNAL(moveItem(QListViewItem*,QListViewItem*)), this, SLOT(moveApplication(QListViewItem*,QListViewItem*))); | 41 | connect(tabList, SIGNAL(moveItem(QListViewItem*,QListViewItem*)), this, SLOT(moveApplication(QListViewItem*,QListViewItem*))); |
40 | } | 42 | } |
41 | 43 | ||
42 | /** | 44 | /** |
43 | * If anything in the tab's have been changed then update the system or alert | 45 | * If anything in the tab's have been changed then update the system or alert |
44 | * the user. | 46 | * the user. |
45 | */ | 47 | */ |
46 | TabManager::~TabManager(){ | 48 | TabManager::~TabManager(){ |
47 | if(changed){ | 49 | if(changed){ |
48 | // Prompt. | 50 | // Prompt. |
49 | //int answer = QMessageBox::warning(this, "Message", "Should your desktop be","Yes", "Cancel", 0, 1 ); | 51 | //int answer = QMessageBox::warning(this, "Message", "Should your desktop be","Yes", "Cancel", 0, 1 ); |
50 | //if (answer) | 52 | //if (answer) |
51 | // return; | 53 | // return; |
52 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 54 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
53 | QString link; //we'll just send an empty string | 55 | QString link; //we'll just send an empty string |
54 | e << link; | 56 | e << link; |
55 | } | 57 | } |
56 | } | 58 | } |
57 | 59 | ||
58 | /** | 60 | /** |
59 | * Scans root directory for any tabs or applications. Will recursivly go down, | 61 | * Scans root directory for any tabs or applications. Will recursivly go down, |
60 | * but will not follow symlinks. | 62 | * but will not follow symlinks. |
61 | * @param directory - the directory to look in. | 63 | * @param directory - the directory to look in. |
62 | * @param parent - the parent to place any new tabs or apps into. If parent is | 64 | * @param parent - the parent to place any new tabs or apps into. If parent is |
63 | * NULL then the item is a tab and should be placed as a child of the window. | 65 | * NULL then the item is a tab and should be placed as a child of the window. |
64 | */ | 66 | */ |
65 | void TabManager::rescanFolder(QString directory, QListViewItem* parent){ | 67 | void TabManager::rescanFolder(QString directory, QListViewItem* parent){ |
66 | //odebug << QString("rescanFolder: ") + directory.latin1() << oendl; | 68 | //odebug << QString("rescanFolder: ") + directory.latin1() << oendl; |
67 | 69 | ||
68 | QDir d; | 70 | QDir d; |
69 | d.setPath(directory); | 71 | d.setPath(directory); |
70 | // Show hidden files for .directories | 72 | // Show hidden files for .directories |
71 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); | 73 | d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); |
72 | 74 | ||
73 | const QFileInfoList *list = d.entryInfoList(); | 75 | const QFileInfoList *list = d.entryInfoList(); |
74 | QFileInfoListIterator it( *list ); // create list iterator | 76 | QFileInfoListIterator it( *list ); // create list iterator |
75 | QFileInfo *fi; // pointer for traversing | 77 | QFileInfo *fi; // pointer for traversing |
76 | 78 | ||
77 | while ( (fi=it.current()) ) { // for each file... | 79 | while ( (fi=it.current()) ) { // for each file... |
78 | // If it is a dir and not .. or . then add it as a tab and go down. | 80 | // If it is a dir and not .. or . then add it as a tab and go down. |
79 | if(fi->isDir()){ | 81 | if(fi->isDir()){ |
80 | if(fi->fileName() != ".." && fi->fileName() != ".") { | 82 | if(fi->fileName() != ".." && fi->fileName() != ".") { |
81 | QListViewItem* newItem; | 83 | QListViewItem* newItem; |
82 | if(!parent) | 84 | if(!parent) |
83 | newItem = new QListViewItem(tabList, fi->fileName()); | 85 | newItem = new QListViewItem(tabList, fi->fileName()); |
84 | else | 86 | else |
85 | newItem = new QListViewItem(parent, fi->fileName()); | 87 | newItem = new QListViewItem(parent, fi->fileName()); |
86 | itemList.insert(newItem, directory + "/" + fi->fileName() + "/.directory" ); | 88 | itemList.insert(newItem, directory + "/" + fi->fileName() + "/.directory" ); |
87 | rescanFolder(directory + "/" + fi->fileName(), newItem); | 89 | rescanFolder(directory + "/" + fi->fileName(), newItem); |
88 | } | 90 | } |
89 | } | 91 | } |
90 | else{ | 92 | else{ |
91 | // it is a file, if not a .directory add to parent. | 93 | // it is a file, if not a .directory add to parent. |
92 | 94 | ||
93 | // Change parents name and icon to reflect icon. | 95 | // Change parents name and icon to reflect icon. |
94 | if(fi->fileName() == ".directory"){ | 96 | if(fi->fileName() == ".directory"){ |
95 | AppLnk app(directory + "/" + fi->fileName()); | 97 | AppLnk app(directory + "/" + fi->fileName()); |
96 | if(parent){ | 98 | if(parent){ |
97 | parent->setPixmap(0,app.pixmap()); | 99 | parent->setPixmap(0,app.pixmap()); |
98 | parent->setText(0, app.name()); | 100 | parent->setText(0, app.name()); |
99 | } | 101 | } |
100 | } | 102 | } |
101 | else{ | 103 | else{ |
102 | // Add any desktop files found. | 104 | // Add any desktop files found. |
103 | QListViewItem* newItem; | 105 | QListViewItem* newItem; |
104 | if(directory != HOME_APP_DIR){ | 106 | if(directory != HOME_APP_DIR){ |
105 | if(!parent) | 107 | if(!parent) |
106 | newItem = new QListViewItem(tabList, fi->fileName()); | 108 | newItem = new QListViewItem(tabList, fi->fileName()); |
107 | else | 109 | else |
108 | newItem = new QListViewItem(parent, fi->fileName()); | 110 | newItem = new QListViewItem(parent, fi->fileName()); |
109 | if(fi->fileName().right(APPLICATION_EXTENSION_LENGTH) == APPLICATION_EXTENSION){ | 111 | if(fi->fileName().right(APPLICATION_EXTENSION_LENGTH) == APPLICATION_EXTENSION){ |
110 | AppLnk app(directory + "/" + fi->fileName()); | 112 | AppLnk app(directory + "/" + fi->fileName()); |
111 | newItem->setPixmap(0,app.pixmap()); | 113 | newItem->setPixmap(0,app.pixmap()); |
112 | newItem->setText(0, app.name()); | 114 | newItem->setText(0, app.name()); |
113 | itemList.insert(newItem, directory + "/" + fi->fileName()); | 115 | itemList.insert(newItem, directory + "/" + fi->fileName()); |
114 | } | 116 | } |
115 | } | 117 | } |
116 | } | 118 | } |
117 | } | 119 | } |
118 | ++it; // goto next list element | 120 | ++it; // goto next list element |
119 | } | 121 | } |
120 | } | 122 | } |
121 | 123 | ||
122 | /** | 124 | /** |
123 | * Create a new blank Tab. | 125 | * Create a new blank Tab. |
124 | * Create a physical folder with .directory file | 126 | * Create a physical folder with .directory file |
125 | * Create a item on the list | 127 | * Create a item on the list |
126 | */ | 128 | */ |
127 | void TabManager::newFolder(){ | 129 | void TabManager::newFolder(){ |
128 | QDir r; | 130 | QDir r; |
129 | r.mkdir(QString(HOME_APP_DIR) + "/" + NEW_FOLDER); | 131 | r.mkdir(QString(HOME_APP_DIR) + "/" + NEW_FOLDER); |
130 | system((QString("echo [Desktop Entry] | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); | 132 | system((QString("echo [Desktop Entry] | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); |
131 | system((QString("echo Name=" NEW_FOLDER " | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); | 133 | system((QString("echo Name=" NEW_FOLDER " | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); |
132 | 134 | ||
133 | QString homeLocation = QString(HOME_APP_DIR) + "/" + NEW_FOLDER + "/.directory"; | 135 | QString homeLocation = QString(HOME_APP_DIR) + "/" + NEW_FOLDER + "/.directory"; |
134 | QListViewItem *newItem = new QListViewItem(tabList, NEW_FOLDER); | 136 | QListViewItem *newItem = new QListViewItem(tabList, NEW_FOLDER); |
135 | itemList.insert(newItem, homeLocation ); | 137 | itemList.insert(newItem, homeLocation ); |
136 | 138 | ||
137 | // We have changed something. | 139 | // We have changed something. |
138 | changed = true; | 140 | changed = true; |
139 | } | 141 | } |
140 | 142 | ||
141 | /** | 143 | /** |
142 | * Create a new blank application | 144 | * Create a new blank application |
143 | * Make sure a tab is selected | 145 | * Make sure a tab is selected |
144 | * create physical file | 146 | * create physical file |
145 | * fill file with default information (entry, name, type). | 147 | * fill file with default information (entry, name, type). |
146 | */ | 148 | */ |
147 | void TabManager::newApplication(){ | 149 | void TabManager::newApplication(){ |
148 | QListViewItem *item = tabList->currentItem(); | 150 | QListViewItem *item = tabList->currentItem(); |
149 | if(!item || item->parent()) | 151 | if(!item || item->parent()) |
150 | return; | 152 | return; |
151 | 153 | ||
152 | QString parentDir = itemList[item].mid(0,itemList[item].length()-11); | 154 | QString parentDir = itemList[item].mid(0,itemList[item].length()-11); |
153 | QString homeLocation = parentDir + "/" NEW_APPLICATION APPLICATION_EXTENSION; | 155 | QString homeLocation = parentDir + "/" NEW_APPLICATION APPLICATION_EXTENSION; |
154 | system((QString("echo [Desktop Entry] | cat >> ") + homeLocation).latin1()); | 156 | system((QString("echo [Desktop Entry] | cat >> ") + homeLocation).latin1()); |
155 | system((QString("echo Name=" NEW_APPLICATION " | cat >> ") + homeLocation).latin1()); | 157 | system((QString("echo Name=" NEW_APPLICATION " | cat >> ") + homeLocation).latin1()); |
156 | int slash = parentDir.findRev('/', -1); | 158 | int slash = parentDir.findRev('/', -1); |
157 | QString folderName = parentDir.mid(slash+1, parentDir.length()); | 159 | QString folderName = parentDir.mid(slash+1, parentDir.length()); |
158 | 160 | ||
159 | system((QString("echo Type=") + folderName + " | cat >> " + homeLocation).latin1()); | 161 | system((QString("echo Type=") + folderName + " | cat >> " + homeLocation).latin1()); |
160 | 162 | ||
161 | // Insert into the tree | 163 | // Insert into the tree |
162 | QListViewItem *newItem = new QListViewItem(item, NEW_APPLICATION); | 164 | QListViewItem *newItem = new QListViewItem(item, NEW_APPLICATION); |
163 | itemList.insert(newItem, homeLocation ); | 165 | itemList.insert(newItem, homeLocation ); |
164 | 166 | ||
165 | // We have changed something. | 167 | // We have changed something. |
166 | changed = true; | 168 | changed = true; |
167 | } | 169 | } |
168 | 170 | ||
169 | /** | 171 | /** |
170 | * Remove the item. | 172 | * Remove the item. |
171 | * Check if we can | 173 | * Check if we can |
172 | * Prompt user | 174 | * Prompt user |
173 | * Delete physical file (Dir, remove .dir, then dir. File, remove file) | 175 | * Delete physical file (Dir, remove .dir, then dir. File, remove file) |
174 | * Remove from installer if need too. | 176 | * Remove from installer if need too. |
175 | */ | 177 | */ |
176 | void TabManager::removeItem(){ | 178 | void TabManager::removeItem(){ |
177 | // Make sure we can delete | 179 | // Make sure we can delete |
178 | QListViewItem *item = tabList->currentItem(); | 180 | QListViewItem *item = tabList->currentItem(); |
179 | if(!item) | 181 | if(!item) |
180 | return; | 182 | return; |
181 | if(item->childCount() > 0){ | 183 | if(item->childCount() > 0){ |
182 | QMessageBox::critical(this, tr("Message"), tr("Can't remove with applications\nstill in the group."), tr("Ok") ); | 184 | QMessageBox::critical(this, tr("Message"), tr("Can't remove with applications\nstill in the group."), tr("Ok") ); |
183 | return; | 185 | return; |
184 | } | 186 | } |
185 | 187 | ||
186 | // Prompt. | 188 | // Prompt. |
187 | int answer = QMessageBox::warning(this, tr("Message"), tr("Are you sure you want to delete?"), tr("Yes"), tr("Cancel"), 0, 1 ); | 189 | int answer = QMessageBox::warning(this, tr("Message"), tr("Are you sure you want to delete?"), tr("Yes"), tr("Cancel"), 0, 1 ); |
188 | if (answer) | 190 | if (answer) |
189 | return; | 191 | return; |
190 | 192 | ||
191 | bool removeSuccessful = true; | 193 | bool removeSuccessful = true; |
192 | QString location = itemList[item]; | 194 | QString location = itemList[item]; |
193 | // Remove file (.directory in a Directory case) | 195 | // Remove file (.directory in a Directory case) |
194 | if(!QFile::remove(location)) | 196 | if(!QFile::remove(location)) |
195 | removeSuccessful = false; | 197 | removeSuccessful = false; |
196 | 198 | ||
197 | // Remove directory | 199 | // Remove directory |
198 | if(item->parent() == NULL){ | 200 | if(item->parent() == NULL){ |
199 | // Remove .directory file string | 201 | // Remove .directory file string |
200 | location = location.mid(0,location.length()-10); | 202 | location = location.mid(0,location.length()-10); |
201 | QDir dir; | 203 | QDir dir; |
202 | if(!dir.rmdir(location)) | 204 | if(!dir.rmdir(location)) |
203 | removeSuccessful = false; | 205 | removeSuccessful = false; |
204 | else | 206 | else |
205 | removeSuccessful = true; | 207 | removeSuccessful = true; |
206 | } | 208 | } |
207 | 209 | ||
208 | // If removing failed. | 210 | // If removing failed. |
209 | if(!removeSuccessful){ | 211 | if(!removeSuccessful){ |
210 | odebug << (QString("removeItem: ") + location).latin1() << oendl; | 212 | odebug << (QString("removeItem: ") + location).latin1() << oendl; |
211 | QMessageBox::critical(this, tr("Message"), tr("Can't remove."), tr("Ok") ); | 213 | QMessageBox::critical(this, tr("Message"), tr("Can't remove."), tr("Ok") ); |
212 | return; | 214 | return; |
213 | } | 215 | } |
214 | 216 | ||
215 | // Remove from the installer so it wont fail. | 217 | // Remove from the installer so it wont fail. |
216 | // Don't need to do this sense the current install uses rm -f so no error | 218 | // Don't need to do this sense the current install uses rm -f so no error |
217 | 219 | ||
218 | // Remove from the gui list. | 220 | // Remove from the gui list. |
219 | itemList.remove(item); | 221 | itemList.remove(item); |
220 | if(item->parent()) | 222 | if(item->parent()) |
221 | item->parent()->takeItem(item); | 223 | item->parent()->takeItem(item); |
222 | delete item; | 224 | delete item; |
223 | 225 | ||
224 | // We have changed something. | 226 | // We have changed something. |
225 | changed = true; | 227 | changed = true; |
226 | } | 228 | } |
227 | 229 | ||
228 | /** | 230 | /** |
229 | * Helper function. Edits the current item. | 231 | * Helper function. Edits the current item. |
230 | * calls editItem with the currently selected item. | 232 | * calls editItem with the currently selected item. |
231 | */ | 233 | */ |
232 | void TabManager::editCurrentItem(){ | 234 | void TabManager::editCurrentItem(){ |
233 | editItem(tabList->currentItem()); | 235 | editItem(tabList->currentItem()); |
234 | } | 236 | } |
235 | 237 | ||
236 | /** | 238 | /** |
237 | * Edit the item that is passed in. | 239 | * Edit the item that is passed in. |
238 | * Show application dialog and if anything changed | 240 | * Show application dialog and if anything changed |
239 | * @param item the item to edit. | 241 | * @param item the item to edit. |
240 | */ | 242 | */ |
241 | void TabManager::editItem( QListViewItem * item){ | 243 | void TabManager::editItem( QListViewItem * item){ |
242 | if(!item) | 244 | if(!item) |
243 | return; | 245 | return; |
244 | 246 | ||
245 | TabAppLnk app(itemList[item]); | 247 | TabAppLnk app(itemList[item]); |
246 | if(!app.isValid()){ | 248 | if(!app.isValid()){ |
247 | odebug << QString("editItem: Not a valid applnk file: ") + itemList[item].latin1() << oendl; | 249 | odebug << QString("editItem: Not a valid applnk file: ") + itemList[item].latin1() << oendl; |
248 | return; | 250 | return; |
249 | } | 251 | } |
250 | 252 | ||
251 | // Fill with all of the icons | 253 | // Fill with all of the icons |
252 | if(!application){ | 254 | if(!application){ |
253 | Wait waitDialog(this, "Wait dialog"); | 255 | Wait waitDialog(this, "Wait dialog"); |
254 | waitDialog.waitLabel->setText(tr("Gathering icons...")); | 256 | waitDialog.waitLabel->setText(tr("Gathering icons...")); |
255 | waitDialog.show(); | 257 | waitDialog.show(); |
256 | qApp->processEvents(); | 258 | qApp->processEvents(); |
257 | application = new AppEdit(this, "Application edit", true); | 259 | application = new AppEdit(this, "Application edit", true); |
258 | 260 | ||
259 | QDir d(QPEApplication::qpeDir() + "/pics/"); | 261 | QDir d(QPEApplication::qpeDir() + "/pics/"); |
260 | d.setFilter( QDir::Files); | 262 | d.setFilter( QDir::Files); |
261 | 263 | ||
262 | const QFileInfoList *list = d.entryInfoList(); | 264 | const QFileInfoList *list = d.entryInfoList(); |
263 | QFileInfoListIterator it( *list ); // create list iterator | 265 | QFileInfoListIterator it( *list ); // create list iterator |
264 | QFileInfo *fi; // pointer for traversing | 266 | QFileInfo *fi; // pointer for traversing |
265 | 267 | ||
266 | while ( (fi=it.current()) ) { // for each file... | 268 | while ( (fi=it.current()) ) { // for each file... |
267 | QString fileName = fi->fileName(); | 269 | QString fileName = fi->fileName(); |
268 | if(fileName.right(4) == ".png"){ | 270 | if(fileName.right(4) == ".png"){ |
269 | fileName = fileName.mid(0,fileName.length()-4); | 271 | fileName = fileName.mid(0,fileName.length()-4); |
270 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); | 272 | QPixmap imageOfFile(Resource::loadPixmap(fileName)); |
271 | QImage foo = imageOfFile.convertToImage(); | 273 | QImage foo = imageOfFile.convertToImage(); |
272 | foo = foo.smoothScale(16,16); | 274 | foo = foo.smoothScale(16,16); |
273 | imageOfFile.convertFromImage(foo); | 275 | imageOfFile.convertFromImage(foo); |
274 | application->iconLineEdit->insertItem(imageOfFile,fileName); | 276 | application->iconLineEdit->insertItem(imageOfFile,fileName); |
275 | } | 277 | } |
276 | //odebug << fi->fileName().latin1() << oendl; | 278 | //odebug << fi->fileName().latin1() << oendl; |
277 | ++it; | 279 | ++it; |
278 | } | 280 | } |
279 | waitDialog.hide(); | 281 | waitDialog.hide(); |
280 | } | 282 | } |
281 | int pixmap = -1; | 283 | int pixmap = -1; |
282 | QString pixmapText = app.pixmapString(); | 284 | QString pixmapText = app.pixmapString(); |
283 | QComboBox *f = application->iconLineEdit; | 285 | QComboBox *f = application->iconLineEdit; |
284 | for(int i = 0; i < application->iconLineEdit->count(); i++){ | 286 | for(int i = 0; i < application->iconLineEdit->count(); i++){ |
285 | if(f->text(i) == pixmapText){ | 287 | if(f->text(i) == pixmapText){ |
286 | pixmap = i; | 288 | pixmap = i; |
287 | break; | 289 | break; |
288 | } | 290 | } |
289 | } | 291 | } |
290 | if(pixmap != -1) | 292 | if(pixmap != -1) |
291 | application->iconLineEdit->setCurrentItem(pixmap); | 293 | application->iconLineEdit->setCurrentItem(pixmap); |
292 | else if(pixmapText.isEmpty()){ | 294 | else if(pixmapText.isEmpty()){ |
293 | application->iconLineEdit->setCurrentItem(0); | 295 | application->iconLineEdit->setCurrentItem(0); |
294 | } | 296 | } |
295 | else{ | 297 | else{ |
296 | QPixmap imageOfFile(Resource::loadPixmap(pixmapText)); | 298 | QPixmap imageOfFile(Resource::loadPixmap(pixmapText)); |
297 | QImage foo = imageOfFile.convertToImage(); | 299 | QImage foo = imageOfFile.convertToImage(); |
298 | foo = foo.smoothScale(16,16); | 300 | foo = foo.smoothScale(16,16); |
299 | imageOfFile.convertFromImage(foo); | 301 | imageOfFile.convertFromImage(foo); |
300 | application->iconLineEdit->insertItem(imageOfFile,pixmapText,0); | 302 | application->iconLineEdit->insertItem(imageOfFile,pixmapText,0); |
301 | application->iconLineEdit->setCurrentItem(0); | 303 | application->iconLineEdit->setCurrentItem(0); |
302 | } | 304 | } |
303 | 305 | ||
304 | application->nameLineEdit->setText(app.name()); | 306 | application->nameLineEdit->setText(app.name()); |
305 | application->execLineEdit->setText(app.exec()); | 307 | application->execLineEdit->setText(app.exec()); |
306 | application->commentLineEdit->setText(app.comment()); | 308 | application->commentLineEdit->setText(app.comment()); |
307 | 309 | ||
308 | if(item->parent() == NULL){ | 310 | if(item->parent() == NULL){ |
309 | application->execLineEdit->setEnabled(false); | 311 | application->execLineEdit->setEnabled(false); |
310 | application->TextLabel3->setEnabled(false); | 312 | application->TextLabel3->setEnabled(false); |
311 | application->setCaption(tr("Tab")); | 313 | application->setCaption(tr("Tab")); |
312 | } | 314 | } |
313 | else{ | 315 | else{ |
314 | application->execLineEdit->setEnabled(true); | 316 | application->execLineEdit->setEnabled(true); |
315 | application->TextLabel3->setEnabled(true); | 317 | application->TextLabel3->setEnabled(true); |
316 | application->setCaption(tr("Application")); | 318 | application->setCaption(tr("Application")); |
317 | } | 319 | } |
318 | 320 | ||
319 | // Only do somthing if they hit OK | 321 | // Only do somthing if they hit OK |
320 | application->showMaximized(); | 322 | application->showMaximized(); |
321 | if(application->exec() == 0) | 323 | if(application->exec() == 0) |
322 | return; | 324 | return; |
323 | 325 | ||
324 | // If nothing has changed exit (hmmm why did they hit ok?) | 326 | // If nothing has changed exit (hmmm why did they hit ok?) |
325 | if(app.name() == application->nameLineEdit->text() && | 327 | if(app.name() == application->nameLineEdit->text() && |
326 | app.pixmapString() == application->iconLineEdit->currentText() && | 328 | app.pixmapString() == application->iconLineEdit->currentText() && |
327 | app.comment() == application->commentLineEdit->text() && | 329 | app.comment() == application->commentLineEdit->text() && |
328 | app.exec() == application->execLineEdit->text()) | 330 | app.exec() == application->execLineEdit->text()) |
329 | return; | 331 | return; |
330 | 332 | ||
331 | // Change the applnk file | 333 | // Change the applnk file |
332 | QString oldName = app.name(); | 334 | QString oldName = app.name(); |
333 | app.setName(application->nameLineEdit->text()); | 335 | app.setName(application->nameLineEdit->text()); |
334 | app.setIcon(application->iconLineEdit->currentText()); | 336 | app.setIcon(application->iconLineEdit->currentText()); |
335 | app.setComment(application->commentLineEdit->text()); | 337 | app.setComment(application->commentLineEdit->text()); |
336 | app.setExec(application->execLineEdit->text()); | 338 | app.setExec(application->execLineEdit->text()); |
337 | if(!app.writeLink()){ | 339 | if(!app.writeLink()){ |
338 | QMessageBox::critical(this, tr("Message"), "Can't save.", tr("Ok") ); | 340 | QMessageBox::critical(this, tr("Message"), "Can't save.", tr("Ok") ); |
339 | return; | 341 | return; |
340 | } | 342 | } |
341 | 343 | ||
342 | // Update the gui icon and name | 344 | // Update the gui icon and name |
343 | item->setText(0,app.name()); | 345 | item->setText(0,app.name()); |
344 | item->setPixmap(0,app.pixmap()); | 346 | item->setPixmap(0,app.pixmap()); |
345 | 347 | ||
346 | // We have changed something. | 348 | // We have changed something. |
347 | changed = true; | 349 | changed = true; |
348 | 350 | ||
349 | // If we were dealing with a new folder or new application change | 351 | // If we were dealing with a new folder or new application change |
350 | // the file names. Also change the item location in itemList | 352 | // the file names. Also change the item location in itemList |
351 | if(oldName == NEW_FOLDER){ | 353 | if(oldName == NEW_FOLDER){ |
352 | QDir r; | 354 | QDir r; |
353 | QString oldName = itemList[item]; | 355 | QString oldName = itemList[item]; |
354 | oldName = oldName.mid(0,oldName.length()-11); | 356 | oldName = oldName.mid(0,oldName.length()-11); |
355 | QString newName = oldName.mid(0,oldName.length()-9); | 357 | QString newName = oldName.mid(0,oldName.length()-9); |
356 | newName = newName + "/" + app.name(); | 358 | newName = newName + "/" + app.name(); |
357 | r.rename(oldName, newName); | 359 | r.rename(oldName, newName); |
358 | itemList.remove(item); | 360 | itemList.remove(item); |
359 | itemList.insert(item, newName + "/.directory" ); | 361 | itemList.insert(item, newName + "/.directory" ); |
360 | } | 362 | } |
361 | else if(oldName == NEW_APPLICATION){ | 363 | else if(oldName == NEW_APPLICATION){ |
362 | if(!item->parent()) | 364 | if(!item->parent()) |
363 | return; | 365 | return; |
364 | QString parentDir = itemList[item->parent()]; | 366 | QString parentDir = itemList[item->parent()]; |
365 | QDir r; | 367 | QDir r; |
366 | QString oldName = itemList[item]; | 368 | QString oldName = itemList[item]; |
367 | QString newName = oldName.mid(0, parentDir.length()-10); | 369 | QString newName = oldName.mid(0, parentDir.length()-10); |
368 | newName = newName + app.name() + APPLICATION_EXTENSION; | 370 | newName = newName + app.name() + APPLICATION_EXTENSION; |
369 | r.rename(oldName, newName); | 371 | r.rename(oldName, newName); |
370 | itemList.remove(item); | 372 | itemList.remove(item); |
371 | itemList.insert(item, newName); | 373 | itemList.insert(item, newName); |
372 | } | 374 | } |
373 | } | 375 | } |
374 | 376 | ||
375 | /** | 377 | /** |
376 | * Move an application from one directory to another. | 378 | * Move an application from one directory to another. |
377 | * Move in the gui, move in the applnk file, move in the installer. | 379 | * Move in the gui, move in the applnk file, move in the installer. |
378 | * @param item the application to move | 380 | * @param item the application to move |
379 | * @pearam newGroup the new parent of this application | 381 | * @pearam newGroup the new parent of this application |
380 | */ | 382 | */ |
381 | void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){ | 383 | void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){ |
382 | // Can we even move it? | 384 | // Can we even move it? |
383 | if(!item || !item->parent() || newGroup->parent()) | 385 | if(!item || !item->parent() || newGroup->parent()) |
384 | return; | 386 | return; |
385 | if(item->parent() == newGroup) | 387 | if(item->parent() == newGroup) |
386 | return; | 388 | return; |
387 | 389 | ||
388 | // Get the new folder, new file name, | 390 | // Get the new folder, new file name, |
389 | QString newFolder = itemList[newGroup]; | 391 | QString newFolder = itemList[newGroup]; |
390 | newFolder = newFolder.mid(0,newFolder.length()-11); | 392 | newFolder = newFolder.mid(0,newFolder.length()-11); |
391 | int slash = newFolder.findRev('/', -1); | 393 | int slash = newFolder.findRev('/', -1); |
392 | QString folderName = newFolder.mid(slash+1, newFolder.length()); | 394 | QString folderName = newFolder.mid(slash+1, newFolder.length()); |
393 | 395 | ||
394 | QString desktopFile = itemList[item]; | 396 | QString desktopFile = itemList[item]; |
395 | slash = desktopFile.findRev('/', -1); | 397 | slash = desktopFile.findRev('/', -1); |
396 | desktopFile = desktopFile.mid(slash, desktopFile.length()); | 398 | desktopFile = desktopFile.mid(slash, desktopFile.length()); |
397 | newFolder = newFolder + desktopFile; | 399 | newFolder = newFolder + desktopFile; |
398 | 400 | ||
399 | // Move file | 401 | // Move file |
400 | QDir r; | 402 | QDir r; |
401 | if(!r.rename(itemList[item], newFolder)){ | 403 | if(!r.rename(itemList[item], newFolder)){ |
402 | QMessageBox::critical(this, tr("Message"), "Can't move application.", tr("Ok") ); | 404 | QMessageBox::critical(this, tr("Message"), "Can't move application.", tr("Ok") ); |
403 | return; | 405 | return; |
404 | } | 406 | } |
405 | //odebug << (QString("moveApplication: ") + itemList[item]).latin1() << oendl; | 407 | //odebug << (QString("moveApplication: ") + itemList[item]).latin1() << oendl; |
406 | //odebug << (QString("moveApplication: ") + newFolder).latin1() << oendl; | 408 | //odebug << (QString("moveApplication: ") + newFolder).latin1() << oendl; |
407 | 409 | ||
408 | // Move in the gui | 410 | // Move in the gui |
409 | item->parent()->takeItem(item); | 411 | item->parent()->takeItem(item); |
410 | newGroup->insertItem(item); | 412 | newGroup->insertItem(item); |
411 | newGroup->setOpen(true); | 413 | newGroup->setOpen(true); |
412 | 414 | ||
413 | // Move file in the installer | 415 | // Move file in the installer |
414 | QString installedAppFile; | 416 | QString installedAppFile; |
415 | if(findInstalledApplication(desktopFile, installedAppFile)) | 417 | if(findInstalledApplication(desktopFile, installedAppFile)) |
416 | swapInstalledLocation(installedAppFile, desktopFile, newFolder); | 418 | swapInstalledLocation(installedAppFile, desktopFile, newFolder); |
417 | else | 419 | else |
418 | odebug << "moveApplication: No installed app found for dekstop file" << oendl; | 420 | odebug << "moveApplication: No installed app found for dekstop file" << oendl; |
419 | 421 | ||
420 | // Move application type | 422 | // Move application type |
421 | AppLnk app(newFolder); | 423 | AppLnk app(newFolder); |
422 | app.setType(folderName); | 424 | app.setType(folderName); |
423 | app.writeLink(); | 425 | app.writeLink(); |
424 | 426 | ||
425 | // Move in our internal list | 427 | // Move in our internal list |
426 | itemList.remove(item); | 428 | itemList.remove(item); |
427 | itemList.insert(item, newFolder); | 429 | itemList.insert(item, newFolder); |
428 | 430 | ||
429 | // We have changed something. | 431 | // We have changed something. |
430 | changed = true; | 432 | changed = true; |
431 | } | 433 | } |
432 | 434 | ||
433 | /** | 435 | /** |
434 | * File the installed application that has this desktop file. | 436 | * File the installed application that has this desktop file. |
435 | * Go through each file in HOME_APP_INSTALL_DIR and see if it contains desktop | 437 | * Go through each file in HOME_APP_INSTALL_DIR and see if it contains desktop |
436 | * file | 438 | * file |
437 | * @param desktopFile - the .desktop file to search for [foo.desktop] | 439 | * @param desktopFile - the .desktop file to search for [foo.desktop] |
438 | * @param installedAppFile - location of the app install list | 440 | * @param installedAppFile - location of the app install list |
439 | * @return true if successful, false if file not found. | 441 | * @return true if successful, false if file not found. |
440 | */ | 442 | */ |
441 | bool TabManager::findInstalledApplication(QString desktopFile, QString &installedAppFile){ | 443 | bool TabManager::findInstalledApplication(QString desktopFile, QString &installedAppFile){ |
442 | 444 | ||
443 | QDir d; | 445 | QDir d; |
444 | d.setPath(HOME_APP_INSTALL_DIR); | 446 | d.setPath(HOME_APP_INSTALL_DIR); |
445 | d.setFilter( QDir::Files ); | 447 | d.setFilter( QDir::Files ); |
446 | 448 | ||
447 | const QFileInfoList *list = d.entryInfoList(); | 449 | const QFileInfoList *list = d.entryInfoList(); |
448 | QFileInfoListIterator it( *list ); // create list iterator | 450 | QFileInfoListIterator it( *list ); // create list iterator |
449 | QFileInfo *fi; // pointer for traversing | 451 | QFileInfo *fi; // pointer for traversing |
450 | 452 | ||
451 | while ( (fi=it.current()) ) { // for each file... | 453 | while ( (fi=it.current()) ) { // for each file... |
452 | QFile file(QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName()); | 454 | QFile file(QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName()); |
453 | if ( file.open(IO_ReadOnly) ) { // file opened successfully | 455 | if ( file.open(IO_ReadOnly) ) { // file opened successfully |
454 | QTextStream stream( &file ); // use a text stream | 456 | QTextStream stream( &file ); // use a text stream |
455 | QString line; | 457 | QString line; |
456 | while ( !stream.eof() ) { // until end of file... | 458 | while ( !stream.eof() ) { // until end of file... |
457 | line = stream.readLine(); // line of text excluding '\n' | 459 | line = stream.readLine(); // line of text excluding '\n' |
458 | if(line.contains(desktopFile)){ | 460 | if(line.contains(desktopFile)){ |
459 | installedAppFile = QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName(); | 461 | installedAppFile = QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName(); |
460 | file.close(); | 462 | file.close(); |
461 | return true; | 463 | return true; |
462 | } | 464 | } |
463 | } | 465 | } |
464 | file.close(); | 466 | file.close(); |
465 | } | 467 | } |
466 | else | 468 | else |
467 | odebug << (QString("findInstalledApplication: Can't open file") + HOME_APP_INSTALL_DIR + "/" + fi->fileName()).latin1() << oendl; | 469 | odebug << (QString("findInstalledApplication: Can't open file") + HOME_APP_INSTALL_DIR + "/" + fi->fileName()).latin1() << oendl; |
468 | ++it; // goto next list element | 470 | ++it; // goto next list element |
469 | } | 471 | } |
470 | return false; | 472 | return false; |
471 | } | 473 | } |
472 | 474 | ||
473 | /** | 475 | /** |
474 | * Open a file and replace a file containing the old desktop file with the new. | 476 | * Open a file and replace a file containing the old desktop file with the new. |
475 | * @param installedAppFile application installed list | 477 | * @param installedAppFile application installed list |
476 | * @param desktopFile old .desktop file | 478 | * @param desktopFile old .desktop file |
477 | * @param newLocation new .desktop file | 479 | * @param newLocation new .desktop file |
478 | */ | 480 | */ |
479 | void TabManager::swapInstalledLocation( QString installedAppFile, QString desktopFile, QString newLocation ){ | 481 | void TabManager::swapInstalledLocation( QString installedAppFile, QString desktopFile, QString newLocation ){ |
480 | QFile file(installedAppFile); | 482 | QFile file(installedAppFile); |
481 | if ( !file.open(IO_ReadOnly) ){ | 483 | if ( !file.open(IO_ReadOnly) ){ |
482 | odebug << QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1() << oendl; | 484 | odebug << QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1() << oendl; |
483 | return; | 485 | return; |
484 | } | 486 | } |
485 | 487 | ||
486 | QTextStream stream( &file ); // use a text stream | 488 | QTextStream stream( &file ); // use a text stream |
487 | QString allLines; | 489 | QString allLines; |
488 | while ( !stream.eof() ) { // until end of file... | 490 | while ( !stream.eof() ) { // until end of file... |
489 | QString line = stream.readLine(); // line of text excluding '\n' | 491 | QString line = stream.readLine(); // line of text excluding '\n' |
490 | if(line.contains(desktopFile)) | 492 | if(line.contains(desktopFile)) |
491 | allLines += newLocation; | 493 | allLines += newLocation; |
492 | else | 494 | else |
493 | allLines += line; | 495 | allLines += line; |
494 | allLines += '\n'; | 496 | allLines += '\n'; |
495 | } | 497 | } |
496 | file.close(); | 498 | file.close(); |
497 | 499 | ||
498 | if ( !file.open(IO_ReadWrite) ){ | 500 | if ( !file.open(IO_ReadWrite) ){ |
499 | odebug << QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1() << oendl; | 501 | odebug << QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1() << oendl; |
500 | return; | 502 | return; |
501 | } | 503 | } |
502 | QTextStream streamOut( &file ); | 504 | QTextStream streamOut( &file ); |
503 | streamOut << allLines; | 505 | streamOut << allLines; |
504 | file.close(); | 506 | file.close(); |
505 | } | 507 | } |
506 | 508 | ||
507 | // tabmanager.cpp | 509 | // tabmanager.cpp |
508 | 510 | ||
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 @@ | |||
1 | TEMPLATE= app | 1 | TEMPLATE= app |
2 | CONFIG = qt warn_on | 2 | CONFIG = qt warn_on |
3 | HEADERS = tabmanager.h tabmainwindow.h tablistview.h tabmanagerbase.h tabapplnk.h | 3 | HEADERS = tabmanager.h tabmainwindow.h tablistview.h tabmanagerbase.h tabapplnk.h |
4 | SOURCES = main.cpp tabmanager.cpp tabmanagerbase.cpp | 4 | SOURCES = main.cpp tabmanager.cpp tabmanagerbase.cpp |
5 | INCLUDEPATH+= $(OPIEDIR)/include | 5 | INCLUDEPATH+= $(OPIEDIR)/include |
6 | DEPENDPATH+= $(OPIEDIR)/include | 6 | DEPENDPATH+= $(OPIEDIR)/include |
7 | LIBS += -lqpe | 7 | LIBS += -lqpe -lopiecore2 |
8 | INTERFACES= app.ui wait.ui | 8 | INTERFACES= app.ui wait.ui |
9 | TARGET = tabmanager | 9 | TARGET = tabmanager |
10 | DESTDIR = $(OPIEDIR)/bin | 10 | DESTDIR = $(OPIEDIR)/bin |
11 | 11 | ||
12 | include ( $(OPIEDIR)/include.pro ) | 12 | include ( $(OPIEDIR)/include.pro ) |