summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-08-04 23:16:00 (UTC)
committer llornkcor <llornkcor>2002-08-04 23:16:00 (UTC)
commit400870188f123415355589ce4fb533614ecdf2ac (patch) (unidiff)
tree6dc7b0f747c3c48de6b730154c1167186226ec4a
parent57bd412cf973805fbe69ecfa8f168ad2e28311a9 (diff)
downloadopie-400870188f123415355589ce4fb533614ecdf2ac.zip
opie-400870188f123415355589ce4fb533614ecdf2ac.tar.gz
opie-400870188f123415355589ce4fb533614ecdf2ac.tar.bz2
fix several severe file handling bugs
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/advancedfm/advancedfm.cpp362
1 files changed, 188 insertions, 174 deletions
diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp
index 818a281..b169a79 100644
--- a/noncore/apps/advancedfm/advancedfm.cpp
+++ b/noncore/apps/advancedfm/advancedfm.cpp
@@ -1000,21 +1000,23 @@ QStringList AdvancedFm::getPath() {
1000 if (TabWidget->currentPageIndex() == 0) { 1000 if (TabWidget->currentPageIndex() == 0) {
1001 QList<QListViewItem> * getSelectedItems( QListView * Local_View ); 1001 QList<QListViewItem> * getSelectedItems( QListView * Local_View );
1002 QListViewItemIterator it( Local_View ); 1002 QListViewItemIterator it( Local_View );
1003 for ( ; it.current(); ++it ) { 1003 for ( ; it.current(); ++it ) {
1004 if ( it.current()->isSelected() ) { 1004 if ( it.current()->isSelected() ) {
1005 strList << it.current()->text(0); 1005 strList << it.current()->text(0);
1006 qDebug(it.current()->text(0));
1006 } 1007 }
1007 } 1008 }
1008 return strList; 1009 return strList;
1009 } else { 1010 } else {
1010 QList<QListViewItem> * getSelectedItems( QListView * Remote_View ); 1011 QList<QListViewItem> * getSelectedItems( QListView * Remote_View );
1011 QListViewItemIterator it( Remote_View ); 1012 QListViewItemIterator it( Remote_View );
1012 for ( ; it.current(); ++it ) { 1013 for ( ; it.current(); ++it ) {
1013 if ( it.current()->isSelected() ) { 1014 if ( it.current()->isSelected() ) {
1014 strList << it.current()->text(0); 1015 strList << it.current()->text(0);
1016 qDebug(it.current()->text(0));
1015 } 1017 }
1016 } 1018 }
1017 return strList; 1019 return strList;
1018 } 1020 }
1019 return ""; 1021 return "";
1020} 1022}
@@ -1096,20 +1098,25 @@ void AdvancedFm::upDir()
1096 update(); 1098 update();
1097 } 1099 }
1098} 1100}
1099 1101
1100void AdvancedFm::copy() 1102void AdvancedFm::copy()
1101{ 1103{
1104 qApp->processEvents();
1102 QStringList curFileList = getPath(); 1105 QStringList curFileList = getPath();
1103 if( curFileList.count() > 0) { 1106 if( curFileList.count() > 0) {
1104 QString curFile; 1107 QString curFile;
1105 if (TabWidget->currentPageIndex() == 0) { 1108 if (TabWidget->currentPageIndex() == 0) {
1106 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 1109 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
1107 1110
1108 QString destFile = currentRemoteDir.canonicalPath()+"/"+(*it); 1111 QString destFile = currentRemoteDir.canonicalPath()+"/"+(*it);
1112 qDebug("Destination file is "+destFile);
1113
1109 curFile = currentDir.canonicalPath()+"/"+(*it); 1114 curFile = currentDir.canonicalPath()+"/"+(*it);
1115 qDebug("CurrentFile file is " + curFile);
1116
1110 QFile f(destFile); 1117 QFile f(destFile);
1111 if( f.exists()) { 1118 if( f.exists()) {
1112 switch ( QMessageBox::warning(this,tr("Delete"), 1119 switch ( QMessageBox::warning(this,tr("Delete"),
1113 destFile+tr(" already exists\nDo you really want to delete it?"), 1120 destFile+tr(" already exists\nDo you really want to delete it?"),
1114 tr("Yes"),tr("No"),0,0,1) ) { 1121 tr("Yes"),tr("No"),0,0,1) ) {
1115 case 0: 1122 case 0:
@@ -1129,13 +1136,15 @@ void AdvancedFm::copy()
1129 TabWidget->setCurrentPage(1); 1136 TabWidget->setCurrentPage(1);
1130 1137
1131 } else { 1138 } else {
1132 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 1139 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
1133 1140
1134 QString destFile = currentDir.canonicalPath()+"/"+(*it); 1141 QString destFile = currentDir.canonicalPath()+"/"+(*it);
1142 qDebug("Destination file is "+destFile);
1135 curFile = currentRemoteDir.canonicalPath()+"/"+(*it); 1143 curFile = currentRemoteDir.canonicalPath()+"/"+(*it);
1144 qDebug("CurrentFile file is " + curFile);
1136 1145
1137 QFile f(destFile); 1146 QFile f(destFile);
1138 if( f.exists()) { 1147 if( f.exists()) {
1139 switch ( QMessageBox::warning(this,tr("Delete"), 1148 switch ( QMessageBox::warning(this,tr("Delete"),
1140 destFile+tr(" already exists\nDo you really want to delete it?"), 1149 destFile+tr(" already exists\nDo you really want to delete it?"),
1141 tr("Yes"),tr("No"),0,0,1) ) { 1150 tr("Yes"),tr("No"),0,0,1) ) {
@@ -1153,258 +1162,263 @@ void AdvancedFm::copy()
1153 qWarning("nothin doing"); 1162 qWarning("nothin doing");
1154 } 1163 }
1155 } 1164 }
1156 populateLocalView(); 1165 populateLocalView();
1157 TabWidget->setCurrentPage(0); 1166 TabWidget->setCurrentPage(0);
1158 } 1167 }
1168
1159 } 1169 }
1160} 1170}
1161 1171
1162void AdvancedFm::copyAs() 1172void AdvancedFm::copyAs() {
1163{ 1173 qApp->processEvents();
1174
1164 QStringList curFileList = getPath(); 1175 QStringList curFileList = getPath();
1165 if( curFileList.count() > 0) { 1176 QString curFile;
1166 QString curFile; 1177 InputDialog *fileDlg;
1167 InputDialog *fileDlg; 1178 if (TabWidget->currentPageIndex() == 0) {
1168 fileDlg = new InputDialog(this,tr("Copy As"),TRUE, 0); 1179 qDebug("tab 1");
1180 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
1181 QString destFile;
1182 curFile = currentDir.canonicalPath()+"/"+(*it);
1183 fileDlg = new InputDialog( this,tr("Copy "+curFile+" As"), TRUE, 0);
1169 1184
1170 if (TabWidget->currentPageIndex() == 0) { 1185 fileDlg->setInputText((const QString &) destFile );
1171 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 1186 fileDlg->exec();
1172 QString destFile; 1187
1173 curFile = currentDir.canonicalPath()+"/"+(*it); 1188 if( fileDlg->result() == 1 ) {
1174 fileDlg->setInputText((const QString &) destFile ); 1189 QString filename = fileDlg->LineEdit1->text();
1175 fileDlg->exec(); 1190 destFile = currentRemoteDir.canonicalPath()+"/"+filename;
1176 if( fileDlg->result() == 1 ) { 1191
1177 QString filename = fileDlg->LineEdit1->text(); 1192 QFile f(destFile);
1178 destFile = currentRemoteDir.canonicalPath()+"/"+(*it); 1193 if( f.exists()) {
1179 1194 switch (QMessageBox::warning(this,tr("Delete"),
1180 QFile f(destFile); 1195 destFile+tr(" already exists\nDo you really want to delete it?"),
1181 if( f.exists()) { 1196 tr("Yes"),tr("No"),0,0,1) ) {
1182 switch (QMessageBox::warning(this,tr("Delete"), 1197 case 0:
1183 destFile+tr(" already exists\nDo you really want to delete it?"), 1198 f.remove();
1184 tr("Yes"),tr("No"),0,0,1) ) { 1199 break;
1185 case 0: 1200 case 1:
1186 f.remove(); 1201 return;
1187 break; 1202 break;
1188 case 1: 1203 };
1189 return; 1204 }
1190 break; 1205 if(!copyFile(destFile, curFile) ) {
1191 }; 1206 QMessageBox::message("AdvancedFm",tr("Could not copy\n")+curFile +tr("to\n")+destFile);
1192 } 1207 qWarning("nothin doing");
1193 if(!copyFile(destFile, curFile) ) {
1194 QMessageBox::message("AdvancedFm",tr("Could not copy\n")+curFile +tr("to\n")+destFile);
1195 qWarning("nothin doing");
1196 }
1197 } 1208 }
1198 } 1209 }
1199 populateRemoteView(); 1210 delete fileDlg;
1200 TabWidget->setCurrentPage(1);
1201 } else {
1202 if (TabWidget->currentPageIndex() == 0) {
1203 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
1204 1211
1205 curFile = currentDir.canonicalPath()+"/"+(*it); 1212 }
1206 QString destFile; 1213 populateRemoteView();
1207 fileDlg->setInputText((const QString &) destFile); 1214 TabWidget->setCurrentPage(1);
1208 fileDlg->exec(); 1215
1209 if( fileDlg->result() == 1 ) { 1216 } else {
1210 QString filename = fileDlg->LineEdit1->text(); 1217 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
1211 destFile = currentDir.canonicalPath()+"/"+(*it); 1218
1212 1219 curFile = currentRemoteDir.canonicalPath()+"/"+(*it);
1213 QFile f(destFile); 1220 fileDlg = new InputDialog( this,tr("Copy "+curFile+" As"), TRUE, 0);
1214 if( f.exists()) { 1221
1215 switch ( QMessageBox::warning(this,tr("Delete"), 1222 QString destFile;
1216 destFile+tr(" already exists\nDo you really want to delete it?"), 1223 fileDlg->setInputText((const QString &) destFile);
1217 tr("Yes"),tr("No"),0,0,1) ) { 1224 fileDlg->exec();
1218 case 0: 1225
1219 f.remove(); 1226 if( fileDlg->result() == 1 ) {
1220 break; 1227 QString filename = fileDlg->LineEdit1->text();
1221 case 1: 1228 destFile = currentDir.canonicalPath()+"/"+filename;
1222 return; 1229
1223 break; 1230 QFile f( destFile);
1224 }; 1231 if( f.exists()) {
1225 } 1232 switch ( QMessageBox::warning(this,tr("Delete"),
1226 if(!copyFile(destFile, curFile) ) { 1233 destFile+tr(" already exists\nDo you really want to delete it?"),
1227 QMessageBox::message("AdvancedFm",tr("Could not copy\n")+curFile +tr("to\n")+destFile); 1234 tr("Yes"),tr("No"),0,0,1) ) {
1228 qWarning("nothin doing"); 1235 case 0:
1229 } 1236 f.remove();
1230 1237 break;
1231 } 1238 case 1:
1239 return;
1240 break;
1241 };
1232 } 1242 }
1233 populateLocalView(); 1243 if(!copyFile(destFile, curFile) ) {
1234 TabWidget->setCurrentPage(0); 1244 QMessageBox::message("AdvancedFm",tr("Could not copy\n")+curFile +tr("to\n")+destFile);
1245 qWarning("nothin doing");
1246 }
1247
1235 } 1248 }
1249 delete fileDlg;
1250
1236 } 1251 }
1252 populateLocalView();
1253 TabWidget->setCurrentPage(0);
1237 } 1254 }
1238
1239} 1255}
1240 1256
1241void AdvancedFm::copySameDir() { 1257void AdvancedFm::copySameDir() {
1258 qApp->processEvents();
1242 QStringList curFileList = getPath(); 1259 QStringList curFileList = getPath();
1243 if( curFileList.count() > 0) { 1260 QString curFile;
1244 QString curFile; 1261 InputDialog *fileDlg;
1245 InputDialog *fileDlg;
1246 1262
1247 if (TabWidget->currentPageIndex() == 0) { 1263 if (TabWidget->currentPageIndex() == 0) {
1248 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 1264
1249 QString destFile; 1265 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
1250 curFile = currentDir.canonicalPath()+"/"+(*it); 1266
1251 fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0); 1267 QString destFile;
1252 fileDlg->setInputText((const QString &) destFile ); 1268 curFile = currentDir.canonicalPath()+"/"+(*it);
1253 fileDlg->exec(); 1269
1254 if( fileDlg->result() == 1 ) { 1270 fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0);
1255 QString filename = fileDlg->LineEdit1->text(); 1271 fileDlg->setInputText((const QString &) destFile );
1256 destFile = currentDir.canonicalPath()+"/"+filename; 1272 fileDlg->exec();
1257 1273
1258 QFile f(destFile); 1274 if( fileDlg->result() == 1 ) {
1259 if( f.exists()) { 1275
1260 switch (QMessageBox::warning(this,tr("Delete"), 1276 QString filename = fileDlg->LineEdit1->text();
1261 destFile+tr(" already exists\nDo you really want to delete it?"), 1277 destFile = currentDir.canonicalPath()+"/"+filename;
1262 tr("Yes"),tr("No"),0,0,1) ) { 1278
1263 case 0: 1279 QFile f(destFile);
1264 qDebug(""); 1280 if( f.exists()) {
1265 f.remove(); 1281 switch (QMessageBox::warning(this,tr("Delete"),
1266 break; 1282 destFile+tr(" already exists\nDo you really want to delete it?"),
1267 case 1: 1283 tr("Yes"),tr("No"),0,0,1) ) {
1268 return; 1284 case 0:
1269 break; 1285 qDebug("");
1270 }; 1286 f.remove();
1271 } 1287 break;
1272 if(!copyFile(destFile, curFile) ) { 1288 case 1:
1273 QMessageBox::message("AdvancedFm",tr("Could not copy\n")+curFile +tr("to\n")+destFile); 1289 return;
1274 qWarning("nothin doing"); 1290 break;
1275 } 1291 };
1276
1277 qDebug("copy "+curFile+" as "+destFile);
1278 } 1292 }
1279 delete fileDlg; 1293 if(!copyFile(destFile, curFile) ) {
1294 QMessageBox::message("AdvancedFm",tr("Could not copy\n")+curFile +tr("to\n")+destFile);
1295 qWarning("nothin doing");
1296 }
1297
1298 qDebug("copy "+curFile+" as "+destFile);
1280 } 1299 }
1281 populateRemoteView(); 1300 delete fileDlg;
1282 TabWidget->setCurrentPage(1); 1301 }
1283 } else { 1302 populateLocalView();
1284 if (TabWidget->currentPageIndex() == 0) {
1285 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
1286 1303
1287 curFile = currentRemoteDir.canonicalPath()+"/"+(*it); 1304 } else {
1288 fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0); 1305 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
1289 QString destFile; 1306
1290 fileDlg->setInputText((const QString &) destFile); 1307 curFile = currentRemoteDir.canonicalPath()+"/"+(*it);
1291 fileDlg->exec(); 1308
1292 if( fileDlg->result() == 1 ) { 1309 fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0);
1293 QString filename = fileDlg->LineEdit1->text(); 1310 QString destFile;
1294 destFile = currentDir.canonicalPath()+"/"+filename; 1311 fileDlg->setInputText((const QString &) destFile);
1295 1312 fileDlg->exec();
1296 QFile f(destFile); 1313 if( fileDlg->result() == 1 ) {
1297 if( f.exists()) { 1314 QString filename = fileDlg->LineEdit1->text();
1298 switch ( QMessageBox::warning(this,tr("Delete"), 1315
1299 destFile+tr(" already exists\nDo you really want to delete it?"), 1316 destFile = currentRemoteDir.canonicalPath()+"/"+filename;
1300 tr("Yes"),tr("No"),0,0,1) ) { 1317
1301 case 0: 1318 QFile f(destFile);
1302 f.remove(); 1319 if( f.exists()) {
1303 break; 1320 switch ( QMessageBox::warning(this,tr("Delete"),
1304 case 1: 1321 destFile+tr(" already exists\nDo you really want to delete it?"),
1305 return; 1322 tr("Yes"),tr("No"),0,0,1) ) {
1306 break; 1323 case 0:
1307 }; 1324 f.remove();
1308 } 1325 break;
1309 if(!copyFile(destFile, curFile) ) { 1326 case 1:
1310 QMessageBox::message("AdvancedFm",tr("Could not copy\n")+curFile +tr("to\n")+destFile); 1327 return;
1311 qWarning("nothin doing"); 1328 break;
1312 } 1329 };
1313 qDebug("copy "+curFile+" as "+destFile);
1314 }
1315 delete fileDlg;
1316 } 1330 }
1317 populateLocalView(); 1331 if(!copyFile(destFile, curFile) ) {
1318 TabWidget->setCurrentPage(0); 1332 QMessageBox::message("AdvancedFm",tr("Could not copy\n")+curFile +tr("to\n")+destFile);
1333 qWarning("nothin doing");
1334 }
1335 qDebug("copy "+curFile+" as "+destFile);
1319 } 1336 }
1337 delete fileDlg;
1320 } 1338 }
1339 populateRemoteView();
1321 } 1340 }
1322
1323} 1341}
1324 1342
1325void AdvancedFm::move() { 1343void AdvancedFm::move() {
1344 qApp->processEvents();
1326 1345
1327 QStringList curFileList = getPath(); 1346 QStringList curFileList = getPath();
1328 if( curFileList.count() > 0) { 1347 if( curFileList.count() > 0) {
1329 QString curFile; 1348 QString curFile;
1330 // qDebug(curFile);
1331 QString destFile; 1349 QString destFile;
1332 1350
1333 if (TabWidget->currentPageIndex() == 0) { 1351 if (TabWidget->currentPageIndex() == 0) {
1352
1334 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 1353 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
1354
1335 QString destFile = currentRemoteDir.canonicalPath(); 1355 QString destFile = currentRemoteDir.canonicalPath();
1356
1336 if(destFile.right(1).find("/",0,TRUE) == -1) 1357 if(destFile.right(1).find("/",0,TRUE) == -1)
1337 destFile+="/"; 1358 destFile+="/";
1338 destFile +=(*it); 1359 destFile +=(*it);
1339 curFile = currentDir.canonicalPath(); 1360 curFile = currentDir.canonicalPath();
1361
1340 qDebug("Destination file is "+destFile); 1362 qDebug("Destination file is "+destFile);
1363
1341 if(curFile.right(1).find("/",0,TRUE) == -1) 1364 if(curFile.right(1).find("/",0,TRUE) == -1)
1342 curFile +="/"; 1365 curFile +="/";
1366
1343 curFile+=(*it); 1367 curFile+=(*it);
1368 qDebug("CurrentFile file is " + curFile);
1344 1369
1345 QFile f(destFile); 1370 QFile f( curFile);
1346 if( f.exists()) { 1371 if( f.exists()) {
1347 switch (QMessageBox::warning(this,tr("Delete"),
1348 destFile+tr(" already exists\nDo you really want to delete it?"),
1349 tr("Yes"),tr("No"),0,0,1) ) {
1350 case 0:
1351 f.remove();
1352 break;
1353 case 1:
1354 return;
1355 break;
1356 };
1357 if(!copyFile( destFile, curFile) ) { 1372 if(!copyFile( destFile, curFile) ) {
1358 QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile); 1373 QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile);
1359 return; 1374 return;
1360 } 1375 } else
1361 QFile::remove(curFile); 1376 QFile::remove(curFile);
1362 } 1377 }
1363 } 1378 }
1379
1364 TabWidget->setCurrentPage(1); 1380 TabWidget->setCurrentPage(1);
1365 } else { 1381
1382 } else { //view 2
1383
1366 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 1384 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
1367 QString destFile = currentRemoteDir.canonicalPath(); 1385
1386 QString destFile = currentDir.canonicalPath();
1387
1368 if(destFile.right(1).find("/",0,TRUE) == -1) 1388 if(destFile.right(1).find("/",0,TRUE) == -1)
1369 destFile+="/"; 1389 destFile+="/";
1390
1370 destFile +=(*it); 1391 destFile +=(*it);
1392
1371 qDebug("Destination file is "+destFile); 1393 qDebug("Destination file is "+destFile);
1372 curFile = currentDir.canonicalPath(); 1394
1395 curFile = currentRemoteDir.canonicalPath();
1396
1373 if(curFile.right(1).find("/",0,TRUE) == -1) 1397 if(curFile.right(1).find("/",0,TRUE) == -1)
1374 curFile +="/"; 1398 curFile +="/";
1375 curFile+=(*it); 1399 curFile+=(*it);
1400 qDebug("CurrentFile file is " + curFile);
1376 1401
1377 QFile f(destFile); 1402 QFile f( curFile);
1378 if( f.exists()) { 1403 if( f.exists()) {
1379 switch (QMessageBox::warning(this,tr("Delete"), 1404 if(!copyFile( destFile, curFile) ) {
1380 destFile+tr(" already exists\nDo you really want to delete it?"), 1405 QMessageBox::message(tr("Note"),tr("Could not move\n") + curFile);
1381 tr("Yes"),tr("No"),0,0,1) ) {
1382 case 0:
1383 f.remove();
1384 break;
1385 case 1:
1386 return;
1387 break;
1388 };
1389 if(!copyFile(destFile, curFile) ) {
1390 QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile);
1391 return; 1406 return;
1392 } 1407 } else
1408 QFile::remove( curFile);
1393 } 1409 }
1394 QFile::remove(curFile);
1395 TabWidget->setCurrentPage(0); 1410 TabWidget->setCurrentPage(0);
1396 } 1411 }
1397 } 1412 }
1398 populateRemoteView(); 1413 populateRemoteView();
1399 populateLocalView(); 1414 populateLocalView();
1400 } 1415 }
1401} 1416}
1402 1417
1403bool AdvancedFm::copyFile( const QString & dest, const QString & src ) 1418bool AdvancedFm::copyFile( const QString & dest, const QString & src ) {
1404{
1405 char bf[ 50000 ]; 1419 char bf[ 50000 ];
1406 int bytesRead; 1420 int bytesRead;
1407 bool success = TRUE; 1421 bool success = TRUE;
1408 struct stat status; 1422 struct stat status;
1409 1423
1410 QFile s( src ); 1424 QFile s( src );