comparison demos/browser/history.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
242 242
243 void loadSettings() 243 void loadSettings()
244 { 244 {
245 // load settings 245 // load settings
246 QSettings settings; 246 QSettings settings;
247 settings.beginGroup(QLatin1String("history")); 247 settings.beginGroup("history");
248 m_historyLimit = settings.value(QLatin1String("historyLimit"), 30).toInt(); 248 m_historyLimit = settings.value("historyLimit", 30).toInt();
249 } 249 }
250 250
251 private: 251 private:
252 252
253 void save() 253 void save()
254 { 254 {
255 QSettings settings; 255 QSettings settings;
256 settings.beginGroup(QLatin1String("history")); 256 settings.beginGroup("history");
257 settings.setValue(QLatin1String("historyLimit"), m_historyLimit); 257 settings.setValue("historyLimit", m_historyLimit);
258 258
259 bool saveAll = m_lastSavedUrl.isEmpty(); 259 bool saveAll = m_lastSavedUrl.isEmpty();
260 int first = m_history.length - 1; 260 int first = m_history.length - 1;
261 if (!saveAll) { 261 if (!saveAll) {
262 // find the first one to save 262 // find the first one to save
271 if (first == m_history.length - 1) 271 if (first == m_history.length - 1)
272 saveAll = true; 272 saveAll = true;
273 273
274 string directory = QDesktopServices.storageLocation(QDesktopServices.DataLocation); 274 string directory = QDesktopServices.storageLocation(QDesktopServices.DataLocation);
275 if (directory.isEmpty()) 275 if (directory.isEmpty())
276 directory = QDir.homePath() + QLatin1String("/.") + QCoreApplication.applicationName(); 276 directory = QDir.homePath() ~ "/." ~ QCoreApplication.applicationName();
277 if (!QFile.exists(directory)) { 277 if (!QFile.exists(directory)) {
278 QDir dir; 278 QDir dir;
279 dir.mkpath(directory); 279 dir.mkpath(directory);
280 } 280 }
281 281
282 auto historyFile = new QFile(directory ~ QLatin1String("/history")); 282 auto historyFile = new QFile(directory ~ "/history");
283 // When saving everything use a temporary file to prevent possible data loss. 283 // When saving everything use a temporary file to prevent possible data loss.
284 auto tempFile = new QTemporaryFile; 284 auto tempFile = new QTemporaryFile;
285 tempFile.setAutoRemove(false); 285 tempFile.setAutoRemove(false);
286 bool open = false; 286 bool open = false;
287 if (saveAll) { 287 if (saveAll) {
362 362
363 void load() 363 void load()
364 { 364 {
365 loadSettings(); 365 loadSettings();
366 366
367 historyFile = new QFile(QDesktopServices.storageLocation(QDesktopServices.DataLocation) ~ QLatin1String("/history")); 367 historyFile = new QFile(QDesktopServices.storageLocation(QDesktopServices.DataLocation) ~ "/history");
368 if (!historyFile.exists()) 368 if (!historyFile.exists())
369 return; 369 return;
370 if (!historyFile.open(QFile.ReadOnly)) { 370 if (!historyFile.open(QFile.ReadOnly)) {
371 qWarning() << "Unable to open history file" << historyFile.fileName(); 371 qWarning() << "Unable to open history file" << historyFile.fileName();
372 return; 372 return;
1093 if (index.column() == 0) { 1093 if (index.column() == 0) {
1094 QModelIndex idx = sourceModel().index(offset, 0); 1094 QModelIndex idx = sourceModel().index(offset, 0);
1095 QDate date = idx.data(HistoryModel.DateRole).toDate(); 1095 QDate date = idx.data(HistoryModel.DateRole).toDate();
1096 if (date == QDate.currentDate()) 1096 if (date == QDate.currentDate())
1097 return tr("Earlier Today"); 1097 return tr("Earlier Today");
1098 return date.toString(QLatin1String("dddd, MMMM d, yyyy")); 1098 return date.toString("dddd, MMMM d, yyyy");
1099 } 1099 }
1100 if (index.column() == 1) { 1100 if (index.column() == 1) {
1101 return Format(tr("{} items"), rowCount(index.sibling(index.row(), 0))); 1101 return Format(tr("{} items"), rowCount(index.sibling(index.row(), 0)));
1102 } 1102 }
1103 } 1103 }
1104 } 1104 }
1105 if (role == Qt.DecorationRole && index.column() == 0 && !index.parent().isValid()) 1105 if (role == Qt.DecorationRole && index.column() == 0 && !index.parent().isValid())
1106 return QIcon(QLatin1String(":history.png")); 1106 return new QIcon(":history.png");
1107 if (role == HistoryModel.DateRole && index.column() == 0 && index.internalId() == 0) { 1107 if (role == HistoryModel.DateRole && index.column() == 0 && index.internalId() == 0) {
1108 int offset = sourceDateRow(index.row()); 1108 int offset = sourceDateRow(index.row());
1109 QModelIndex idx = sourceModel().index(offset, 0); 1109 QModelIndex idx = sourceModel().index(offset, 0);
1110 return idx.data(HistoryModel.DateRole); 1110 return idx.data(HistoryModel.DateRole);
1111 } 1111 }