Changeset View
Changeset View
Standalone View
Standalone View
src/vcalformat.cpp
Show First 20 Lines • Show All 335 Lines • ▼ Show 20 Line(s) | 335 | if (anEvent->dtStart().time().hour() == 0 && | |||
---|---|---|---|---|---|
336 | anEvent->dtStart().time().minute() == 0 && | 336 | anEvent->dtStart().time().minute() == 0 && | ||
337 | anEvent->dtStart().time().second() == 0) { | 337 | anEvent->dtStart().time().second() == 0) { | ||
338 | anEvent->setAllDay(true); | 338 | anEvent->setAllDay(true); | ||
339 | } | 339 | } | ||
340 | } else { | 340 | } else { | ||
341 | anEvent->setDtStart(QDateTime()); | 341 | anEvent->setDtStart(QDateTime()); | ||
342 | } | 342 | } | ||
343 | 343 | | |||
344 | // repeat stuff | 344 | // recurrence stuff | ||
345 | if ((vo = isAPropertyOf(vtodo, VCRRuleProp)) != nullptr) { | 345 | if ((vo = isAPropertyOf(vtodo, VCRRuleProp)) != nullptr) { | ||
346 | uint recurrenceType = Recurrence::rNone; | ||||
347 | int recurrenceTypeAbbrLen = 0; | ||||
348 | | ||||
346 | QString tmpStr = (QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo)))); | 349 | QString tmpStr = (QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo)))); | ||
347 | deleteStr(s); | 350 | deleteStr(s); | ||
348 | tmpStr = tmpStr.simplified(); | 351 | tmpStr = tmpStr.simplified(); | ||
352 | const int tmpStrLen = tmpStr.length(); | ||||
353 | if (tmpStrLen > 0) { | ||||
349 | tmpStr = tmpStr.toUpper(); | 354 | tmpStr = tmpStr.toUpper(); | ||
350 | // first, read the type of the recurrence | 355 | // first, read the type of the recurrence | ||
351 | int typelen = 1; | 356 | recurrenceTypeAbbrLen = 1; | ||
352 | uint type = Recurrence::rNone; | 357 | if (tmpStr.at(0) == QLatin1String("D")) { | ||
353 | if (tmpStr.left(1) == QStringLiteral("D")) { | 358 | recurrenceType = Recurrence::rDaily; | ||
354 | type = Recurrence::rDaily; | 359 | } else if (tmpStr.at(0) == QLatin1String("W")) { | ||
355 | } else if (tmpStr.left(1) == QStringLiteral("W")) { | 360 | recurrenceType = Recurrence::rWeekly; | ||
356 | type = Recurrence::rWeekly; | 361 | } else if (tmpStrLen > 1) { | ||
357 | } else { | 362 | recurrenceTypeAbbrLen = 2; | ||
358 | typelen = 2; | 363 | if (tmpStr.leftRef(2) == QLatin1String("MP")) { | ||
dvratil: You could use `leftRef()` and compare with a `QLatin1String()` to reduce allocations, since you… | |||||
359 | if (tmpStr.left(2) == QStringLiteral("MP")) { | 364 | recurrenceType = Recurrence::rMonthlyPos; | ||
360 | type = Recurrence::rMonthlyPos; | 365 | } else if (tmpStr.leftRef(2) == QLatin1String("MD")) { | ||
ach: QLatin1String() suggestion not applied. | |||||
361 | } else if (tmpStr.left(2) == QStringLiteral("MD")) { | 366 | recurrenceType = Recurrence::rMonthlyDay; | ||
362 | type = Recurrence::rMonthlyDay; | 367 | } else if (tmpStr.leftRef(2) == QLatin1String("YM")) { | ||
363 | } else if (tmpStr.left(2) == QStringLiteral("YM")) { | 368 | recurrenceType = Recurrence::rYearlyMonth; | ||
364 | type = Recurrence::rYearlyMonth; | 369 | } else if (tmpStr.leftRef(2) == QLatin1String("YD")) { | ||
365 | } else if (tmpStr.left(2) == QStringLiteral("YD")) { | 370 | recurrenceType = Recurrence::rYearlyDay; | ||
366 | type = Recurrence::rYearlyDay; | 371 | } | ||
367 | } | 372 | } | ||
368 | } | 373 | } | ||
369 | 374 | | |||
370 | if (type != Recurrence::rNone) { | 375 | if (recurrenceType != Recurrence::rNone) { | ||
371 | | ||||
372 | // Immediately after the type is the frequency | 376 | // Immediately after the type is the frequency | ||
373 | int index = tmpStr.indexOf(QLatin1Char(' ')); | 377 | int index = tmpStr.indexOf(QLatin1Char(' ')); | ||
374 | int last = tmpStr.lastIndexOf(QLatin1Char(' ')) + 1; // find last entry | 378 | int last = tmpStr.lastIndexOf(QLatin1Char(' ')) + 1; // find last entry | ||
375 | int rFreq = tmpStr.midRef(typelen, (index - 1)).toInt(); | 379 | int rFreq = tmpStr.midRef(recurrenceTypeAbbrLen, (index - 1)).toInt(); | ||
376 | ++index; // advance to beginning of stuff after freq | 380 | ++index; // advance to beginning of stuff after freq | ||
377 | 381 | | |||
378 | // Read the type-specific settings | 382 | // Read the type-specific settings | ||
379 | switch (type) { | 383 | switch (recurrenceType) { | ||
380 | case Recurrence::rDaily: | 384 | case Recurrence::rDaily: | ||
381 | anEvent->recurrence()->setDaily(rFreq); | 385 | anEvent->recurrence()->setDaily(rFreq); | ||
382 | break; | 386 | break; | ||
383 | 387 | | |||
384 | case Recurrence::rWeekly: { | 388 | case Recurrence::rWeekly: { | ||
385 | QBitArray qba(7); | 389 | QBitArray qba(7); | ||
386 | QString dayStr; | 390 | QString dayStr; | ||
387 | if (index == last) { | 391 | if (index == last) { | ||
▲ Show 20 Lines • Show All 388 Lines • ▼ Show 20 Line(s) | 779 | if (!isAPropertyOf(vevent, VCDTstartProp)) { | |||
776 | anEvent->setDtStart(anEvent->dtEnd()); | 780 | anEvent->setDtStart(anEvent->dtEnd()); | ||
777 | } | 781 | } | ||
778 | if (! isAPropertyOf(vevent, VCDTendProp)) { | 782 | if (! isAPropertyOf(vevent, VCDTendProp)) { | ||
779 | anEvent->setDtEnd(anEvent->dtStart()); | 783 | anEvent->setDtEnd(anEvent->dtStart()); | ||
780 | } | 784 | } | ||
781 | 785 | | |||
782 | /////////////////////////////////////////////////////////////////////////// | 786 | /////////////////////////////////////////////////////////////////////////// | ||
783 | 787 | | |||
784 | // repeat stuff | 788 | // recurrence stuff | ||
This looks identical to the code above, should it be moved into its own function? (not necessarily in this review, but if you feel bored ;-)) dvratil: This looks identical to the code above, should it be moved into its own function? (not… | |||||
too much work at this time. huge amounts of code in the file really needs refactoring. I'll skip it. winterz: too much work at this time. huge amounts of code in the file really needs refactoring. I'll… | |||||
785 | if ((vo = isAPropertyOf(vevent, VCRRuleProp)) != nullptr) { | 789 | if ((vo = isAPropertyOf(vevent, VCRRuleProp)) != nullptr) { | ||
790 | uint recurrenceType = Recurrence::rNone; | ||||
791 | int recurrenceTypeAbbrLen = 0; | ||||
792 | | ||||
786 | QString tmpStr = (QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo)))); | 793 | QString tmpStr = (QString::fromUtf8(s = fakeCString(vObjectUStringZValue(vo)))); | ||
787 | deleteStr(s); | 794 | deleteStr(s); | ||
788 | tmpStr = tmpStr.simplified(); | 795 | tmpStr = tmpStr.simplified(); | ||
796 | const int tmpStrLen = tmpStr.length(); | ||||
797 | if (tmpStrLen > 0) { | ||||
789 | tmpStr = tmpStr.toUpper(); | 798 | tmpStr = tmpStr.toUpper(); | ||
790 | // first, read the type of the recurrence | 799 | // first, read the type of the recurrence | ||
791 | int typelen = 1; | 800 | recurrenceTypeAbbrLen = 1; | ||
792 | uint type = Recurrence::rNone; | 801 | if (tmpStr.at(0) == QLatin1String("D")) { | ||
793 | if (tmpStr.left(1) == QLatin1String("D")) { | 802 | recurrenceType = Recurrence::rDaily; | ||
794 | type = Recurrence::rDaily; | 803 | } else if (tmpStr.at(0) == QLatin1String("W")) { | ||
795 | } else if (tmpStr.left(1) == QLatin1String("W")) { | 804 | recurrenceType = Recurrence::rWeekly; | ||
796 | type = Recurrence::rWeekly; | 805 | } else if (tmpStrLen > 1){ | ||
797 | } else { | 806 | recurrenceTypeAbbrLen = 2; | ||
798 | typelen = 2; | 807 | if (tmpStr.leftRef(2) == QLatin1String("MP")) { | ||
dvratil: Same as above. | |||||
799 | if (tmpStr.left(2) == QLatin1String("MP")) { | 808 | recurrenceType = Recurrence::rMonthlyPos; | ||
800 | type = Recurrence::rMonthlyPos; | 809 | } else if (tmpStr.leftRef(2) == QLatin1String("MD")) { | ||
801 | } else if (tmpStr.left(2) == QLatin1String("MD")) { | 810 | recurrenceType = Recurrence::rMonthlyDay; | ||
802 | type = Recurrence::rMonthlyDay; | 811 | } else if (tmpStr.leftRef(2) == QLatin1String("YM")) { | ||
803 | } else if (tmpStr.left(2) == QLatin1String("YM")) { | 812 | recurrenceType = Recurrence::rYearlyMonth; | ||
804 | type = Recurrence::rYearlyMonth; | 813 | } else if (tmpStr.leftRef(2) == QLatin1String("YD")) { | ||
805 | } else if (tmpStr.left(2) == QLatin1String("YD")) { | 814 | recurrenceType = Recurrence::rYearlyDay; | ||
806 | type = Recurrence::rYearlyDay; | 815 | } | ||
807 | } | 816 | } | ||
808 | } | 817 | } | ||
809 | 818 | | |||
810 | if (type != Recurrence::rNone) { | 819 | if (recurrenceType != Recurrence::rNone) { | ||
811 | | ||||
812 | // Immediately after the type is the frequency | 820 | // Immediately after the type is the frequency | ||
813 | int index = tmpStr.indexOf(QLatin1Char(' ')); | 821 | int index = tmpStr.indexOf(QLatin1Char(' ')); | ||
814 | int last = tmpStr.lastIndexOf(QLatin1Char(' ')) + 1; // find last entry | 822 | int last = tmpStr.lastIndexOf(QLatin1Char(' ')) + 1; // find last entry | ||
815 | int rFreq = tmpStr.midRef(typelen, (index - 1)).toInt(); | 823 | int rFreq = tmpStr.midRef(recurrenceTypeAbbrLen, (index - 1)).toInt(); | ||
816 | ++index; // advance to beginning of stuff after freq | 824 | ++index; // advance to beginning of stuff after freq | ||
817 | 825 | | |||
818 | // Read the type-specific settings | 826 | // Read the type-specific settings | ||
819 | switch (type) { | 827 | switch (recurrenceType) { | ||
820 | case Recurrence::rDaily: | 828 | case Recurrence::rDaily: | ||
821 | anEvent->recurrence()->setDaily(rFreq); | 829 | anEvent->recurrence()->setDaily(rFreq); | ||
822 | break; | 830 | break; | ||
823 | 831 | | |||
824 | case Recurrence::rWeekly: { | 832 | case Recurrence::rWeekly: { | ||
825 | QBitArray qba(7); | 833 | QBitArray qba(7); | ||
826 | QString dayStr; | 834 | QString dayStr; | ||
827 | if (index == last) { | 835 | if (index == last) { | ||
▲ Show 20 Lines • Show All 902 Lines • Show Last 20 Lines |
You could use leftRef() and compare with a QLatin1String() to reduce allocations, since you are touching this code.