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