Mercurial > projects > qtd
comparison demos/browser/downloadmanager.d @ 80:85c59c4e5f19
remove QLatin1String and other fixes
author | mandel |
---|---|
date | Sun, 24 May 2009 15:25:41 +0000 |
parents | 0654fc9bac95 |
children | 5c8c9c5d9ee1 |
comparison
equal
deleted
inserted
replaced
79:957f549cfc65 | 80:85c59c4e5f19 |
---|---|
211 private: | 211 private: |
212 | 212 |
213 void getFileName() | 213 void getFileName() |
214 { | 214 { |
215 auto settings = new QSettings; | 215 auto settings = new QSettings; |
216 settings.beginGroup(QLatin1String("downloadmanager")); | 216 settings.beginGroup("downloadmanager"); |
217 string defaultLocation = QDesktopServices.storageLocation(QDesktopServices.DesktopLocation); | 217 string defaultLocation = QDesktopServices.storageLocation(QDesktopServices.DesktopLocation); |
218 string downloadDirectory = settings.value(QLatin1String("downloadDirectory"), defaultLocation).toString(); | 218 string downloadDirectory = settings.value("downloadDirectory", defaultLocation).toString(); |
219 if (!downloadDirectory.isEmpty()) | 219 if (!downloadDirectory.isEmpty()) |
220 downloadDirectory += QLatin1Char('/'); | 220 downloadDirectory ~= QLatin1Char('/'); |
221 | 221 |
222 string defaultFileName = saveFileName(downloadDirectory); | 222 string defaultFileName = saveFileName(downloadDirectory); |
223 string fileName = defaultFileName; | 223 string fileName = defaultFileName; |
224 if (m_requestFileName) { | 224 if (m_requestFileName) { |
225 fileName = QFileDialog.getSaveFileName(this, tr("Save File"), defaultFileName); | 225 fileName = QFileDialog.getSaveFileName(this, tr("Save File"), defaultFileName); |
317 unit = tr("kB"); | 317 unit = tr("kB"); |
318 } else { | 318 } else { |
319 size /= 1024*1024; | 319 size /= 1024*1024; |
320 unit = tr("MB"); | 320 unit = tr("MB"); |
321 } | 321 } |
322 return Format(QLatin1String("{} {}"), size, unit); | 322 return Format("{} {}", size, unit); |
323 } | 323 } |
324 | 324 |
325 string saveFileName(string directory) | 325 string saveFileName(string directory) |
326 { | 326 { |
327 // Move this function into QNetworkReply to also get file name sent from the server | 327 // Move this function into QNetworkReply to also get file name sent from the server |
329 auto info = new QFileInfo(path); | 329 auto info = new QFileInfo(path); |
330 string baseName = info.completeBaseName(); | 330 string baseName = info.completeBaseName(); |
331 string endName = info.suffix(); | 331 string endName = info.suffix(); |
332 | 332 |
333 if (baseName.isEmpty()) { | 333 if (baseName.isEmpty()) { |
334 baseName = QLatin1String("unnamed_download"); | 334 baseName = "unnamed_download"; |
335 qDebug() << "DownloadManager:: downloading unknown file:" << m_url; | 335 qDebug() << "DownloadManager:: downloading unknown file:" << m_url; |
336 } | 336 } |
337 string name = directory ~ baseName ~ QLatin1Char('.') ~ endName; | 337 string name = directory ~ baseName ~ QLatin1Char('.') ~ endName; |
338 if (QFile.exists(name)) { | 338 if (QFile.exists(name)) { |
339 // already exists, don't overwrite | 339 // already exists, don't overwrite |
464 private: | 464 private: |
465 | 465 |
466 void save() | 466 void save() |
467 { | 467 { |
468 QSettings settings; | 468 QSettings settings; |
469 settings.beginGroup(QLatin1String("downloadmanager")); | 469 settings.beginGroup("downloadmanager"); |
470 QMetaEnum removePolicyEnum = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("RemovePolicy")); | 470 QMetaEnum removePolicyEnum = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("RemovePolicy")); |
471 settings.setValue(QLatin1String("removeDownloadsPolicy"), QLatin1String(removePolicyEnum.valueToKey(m_removePolicy))); | 471 settings.setValue("removeDownloadsPolicy", removePolicyEnum.valueToKey(m_removePolicy)); |
472 settings.setValue(QLatin1String("size"), size()); | 472 settings.setValue("size", size()); |
473 if (m_removePolicy == Exit) | 473 if (m_removePolicy == Exit) |
474 return; | 474 return; |
475 | 475 |
476 for (int i = 0; i < m_downloads.length; ++i) { | 476 for (int i = 0; i < m_downloads.length; ++i) { |
477 string key = Format(QLatin1String("download_{}_"), i); | 477 string key = Format("download_{}_", i); |
478 settings.setValue(key ~ QLatin1String("url"), m_downloads[i].m_url); | 478 settings.setValue(key ~ "url", m_downloads[i].m_url); |
479 settings.setValue(key ~ QLatin1String("location"), (new QFileInfo(m_downloads[i].m_output)).filePath()); | 479 settings.setValue(key ~ "location", (new QFileInfo(m_downloads[i].m_output)).filePath()); |
480 settings.setValue(key ~ QLatin1String("done"), m_downloads[i].downloadedSuccessfully()); | 480 settings.setValue(key ~ "done", m_downloads[i].downloadedSuccessfully()); |
481 } | 481 } |
482 int i = m_downloads.length; | 482 int i = m_downloads.length; |
483 string key = Format(QLatin1String("download_{}_"), i); | 483 string key = Format("download_{}_", i); |
484 while (settings.contains(key ~ QLatin1String("url"))) { | 484 while (settings.contains(key ~ "url")) { |
485 settings.remove(key ~ QLatin1String("url")); | 485 settings.remove(key ~ "url"); |
486 settings.remove(key ~ QLatin1String("location")); | 486 settings.remove(key ~ "location"); |
487 settings.remove(key ~ QLatin1String("done")); | 487 settings.remove(key ~ "done"); |
488 key = Format(QLatin1String("download_{}_"), ++i); | 488 key = Format("download_{}_", ++i); |
489 } | 489 } |
490 } | 490 } |
491 | 491 |
492 void updateRow() | 492 void updateRow() |
493 { | 493 { |
543 } | 543 } |
544 | 544 |
545 void load() | 545 void load() |
546 { | 546 { |
547 QSettings settings; | 547 QSettings settings; |
548 settings.beginGroup(QLatin1String("downloadmanager")); | 548 settings.beginGroup("downloadmanager"); |
549 QSize size = settings.value(QLatin1String("size")).toSize(); | 549 QSize size = settings.value("size").toSize(); |
550 if (size.isValid()) | 550 if (size.isValid()) |
551 resize(size); | 551 resize(size); |
552 QByteArray value = settings.value(QLatin1String("removeDownloadsPolicy"), QLatin1String("Never")).toByteArray(); | 552 QByteArray value = settings.value("removeDownloadsPolicy", "Never").toByteArray(); |
553 QMetaEnum removePolicyEnum = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("RemovePolicy")); | 553 QMetaEnum removePolicyEnum = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("RemovePolicy")); |
554 m_removePolicy = removePolicyEnum.keyToValue(value) == -1 ? Never : | 554 m_removePolicy = removePolicyEnum.keyToValue(value) == -1 ? Never : |
555 cast(RemovePolicy) removePolicyEnum.keyToValue(value); | 555 cast(RemovePolicy) removePolicyEnum.keyToValue(value); |
556 | 556 |
557 int i = 0; | 557 int i = 0; |
558 string key = Format(QLatin1String("download_{}_"), i); | 558 string key = Format("download_{}_", i); |
559 while (settings.contains(key + QLatin1String("url"))) { | 559 while (settings.contains(key ~ "url")) { |
560 QUrl url = settings.value(key + QLatin1String("url")).toUrl(); | 560 QUrl url = settings.value(key ~ "url").toUrl(); |
561 string fileName = settings.value(key + QLatin1String("location")).toString(); | 561 string fileName = settings.value(key ~ "location").toString(); |
562 bool done = settings.value(key + QLatin1String("done"), true).toBool(); | 562 bool done = settings.value(key ~ "done", true).toBool(); |
563 if (!url.isEmpty() && !fileName.isEmpty()) { | 563 if (!url.isEmpty() && !fileName.isEmpty()) { |
564 DownloadItem item = new DownloadItem(0, this); | 564 DownloadItem item = new DownloadItem(0, this); |
565 item.m_output.setFileName(fileName); | 565 item.m_output.setFileName(fileName); |
566 item.fileNameLabel.setText((new QFileInfo(item.m_output.fileName())).fileName()); | 566 item.fileNameLabel.setText((new QFileInfo(item.m_output.fileName())).fileName()); |
567 item.m_url = url; | 567 item.m_url = url; |
570 item.tryAgainButton.setVisible(!done); | 570 item.tryAgainButton.setVisible(!done); |
571 item.tryAgainButton.setEnabled(!done); | 571 item.tryAgainButton.setEnabled(!done); |
572 item.progressBar.setVisible(!done); | 572 item.progressBar.setVisible(!done); |
573 addItem(item); | 573 addItem(item); |
574 } | 574 } |
575 key = Format(QLatin1String("download_{}_"), ++i); | 575 key = Format("download_{}_", ++i); |
576 } | 576 } |
577 cleanupButton.setEnabled(m_downloads.length - activeDownloads() > 0); | 577 cleanupButton.setEnabled(m_downloads.length - activeDownloads() > 0); |
578 } | 578 } |
579 | 579 |
580 AutoSaver m_autoSaver; | 580 AutoSaver m_autoSaver; |