]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Merge remote-tracking branch 'upstream/master' into work/zakharafoniam/useful-groups
authorZakhar Afonin <zakharafoniam@gmail.com>
Sat, 28 Sep 2024 08:17:27 +0000 (11:17 +0300)
committerZakhar Afonin <zakharafoniam@gmail.com>
Sat, 28 Sep 2024 08:17:27 +0000 (11:17 +0300)
1  2 
src/dolphincontextmenu.cpp
src/dolphinmainwindow.cpp
src/dolphinui.rc
src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kfileitemmodel.h
src/kitemviews/kfileitemmodelrolesupdater.cpp
src/settings/contextmenu/contextmenusettingspage.cpp
src/settings/dolphinsettingsdialog.cpp
src/views/dolphinview.cpp
src/views/dolphinview.h
src/views/viewproperties.cpp

Simple merge
Simple merge
Simple merge
index 5b7b781a8fbdc6d8631b63771b9724f92db7e014,3e4a8c663c1def71aa5aa086562fb3776d0a42be..a6f90b9f5adcf4ad0158ffe43c92b293eb456720
@@@ -2540,76 -2366,50 +2540,91 @@@ KFileItemModel::ItemGroupInfo KFileItem
          }
      }
  
 -    return groups;
 +    if (withString) {
 +        char const *groupNames[] = {"Folders", "Small", "Medium", "Big"};
 +        groupInfo.text = i18nc("@title:group Size", groupNames[groupInfo.comparable]);
 +    }
 +    return groupInfo;
  }
  
 -QList<QPair<int, QVariant>> KFileItemModel::timeRoleGroups(const std::function<QDateTime(const ItemData *)> &fileTimeCb) const
 +KFileItemModel::ItemGroupInfo
 +KFileItemModel::timeRoleGroup(const std::function<QDateTime(const ItemData *)> &fileTimeCb, const ItemData *itemData, bool withString) const
  {
 -    Q_ASSERT(!m_itemData.isEmpty());
 -
 -    const int maxIndex = count() - 1;
 -    QList<QPair<int, QVariant>> groups;
 +    static bool oldWithString;
 +    static ItemGroupInfo oldGroupInfo;
 +    static QDate oldFileDate;
 +    ItemGroupInfo groupInfo;
  
      const QDate currentDate = QDate::currentDate();
-     const QDateTime fileTime = fileTimeCb(itemData);
-     const QDate fileDate = fileTime.date();
-     const int daysDistance = fileDate.daysTo(currentDate);
+     QDate previousFileDate;
+     QString groupValue;
+     for (int i = 0; i <= maxIndex; ++i) {
+         if (isChildItem(i)) {
+             continue;
+         }
+         const QLocale locale;
+         const QDateTime fileTime = fileTimeCb(m_itemData.at(i));
+         const QDate fileDate = fileTime.date();
+         if (fileDate == previousFileDate) {
+             // The current item is in the same group as the previous item
+             continue;
+         }
+         previousFileDate = fileDate;
+         const int daysDistance = fileDate.daysTo(currentDate);
  
 -        QString newGroupValue;
 +    if (fileDate == oldFileDate && withString == oldWithString) {
 +        return oldGroupInfo;
 +    }
 +    // Simplified grouping algorithm, preserving dates
 +    // but not taking "pretty printing" into account
 +    if (currentDate.year() == fileDate.year() && currentDate.month() == fileDate.month()) {
 +        if (daysDistance < 7) {
 +            groupInfo.comparable = daysDistance; // Today, Yesterday and week days
 +        } else if (daysDistance < 14) {
 +            groupInfo.comparable = 10; // One Week Ago
 +        } else if (daysDistance < 21) {
 +            groupInfo.comparable = 20; // Two Weeks Ago
 +        } else if (daysDistance < 28) {
 +            groupInfo.comparable = 30; // Three Weeks Ago
 +        } else {
 +            groupInfo.comparable = 40; // Earlier This Month
 +        }
 +    } else {
 +        const QDate lastMonthDate = currentDate.addMonths(-1);
 +        if (lastMonthDate.year() == fileDate.year() && lastMonthDate.month() == fileDate.month()) {
 +            if (daysDistance < 7) {
 +                groupInfo.comparable = daysDistance; // Today, Yesterday and week days (Month, Year)
 +            } else if (daysDistance < 14) {
 +                groupInfo.comparable = 11; // One Week Ago (Month, Year)
 +            } else if (daysDistance < 21) {
 +                groupInfo.comparable = 21; // Two Weeks Ago (Month, Year)
 +            } else if (daysDistance < 28) {
 +                groupInfo.comparable = 31; // Three Weeks Ago (Month, Year)
 +            } else {
 +                groupInfo.comparable = 41; // Earlier on Month, Year
 +            }
 +        } else {
 +            // The trick will fail for dates past April, 178956967 or before 1 AD.
 +            groupInfo.comparable = 2147483647 - (fileDate.year() * 12 + fileDate.month() - 1); // Month, Year; newer < older
 +        }
 +    }
 +    if (withString) {
          if (currentDate.year() == fileDate.year() && currentDate.month() == fileDate.month()) {
              switch (daysDistance / 7) {
              case 0:
                  switch (daysDistance) {
                  case 0:
 -                    newGroupValue = i18nc("@title:group Date", "Today");
 +                    groupInfo.text = i18nc("@title:group Date", "Today");
                      break;
                  case 1:
 -                    newGroupValue = i18nc("@title:group Date", "Yesterday");
 +                    groupInfo.text = i18nc("@title:group Date", "Yesterday");
                      break;
                  default:
-                     groupInfo.text = fileTime.toString(i18nc("@title:group Date: The week day name: dddd", "dddd"));
-                     groupInfo.text = i18nc(
+                     newGroupValue = locale.toString(fileTime, i18nc("@title:group Date: The week day name: dddd", "dddd"));
+                     newGroupValue = i18nc(
                          "Can be used to script translation of \"dddd\""
                          "with context @title:group Date",
                          "%1",
                          qCWarning(DolphinDebug).nospace()
                              << "A wrong translation was found: " << translatedFormat << ". Please file a bug report at bugs.kde.org";
                          const QString untranslatedFormat = format.toString({QLatin1String("en_US")});
-                         groupInfo.text = fileTime.toString(untranslatedFormat);
+                         newGroupValue = locale.toString(fileTime, untranslatedFormat);
                      }
 -                } else if (daysDistance <= 7 * 3) {
 +                } else if (daysDistance < 7 * 3) {
                      const KLocalizedString format = ki18nc(
                          "@title:group Date: "
                          "MMMM is full month name in current locale, and yyyy is "
                          qCWarning(DolphinDebug).nospace()
                              << "A wrong translation was found: " << translatedFormat << ". Please file a bug report at bugs.kde.org";
                          const QString untranslatedFormat = format.toString({QLatin1String("en_US")});
-                         groupInfo.text = fileTime.toString(untranslatedFormat);
+                         newGroupValue = locale.toString(fileTime, untranslatedFormat);
                      }
 -                } else if (daysDistance <= 7 * 4) {
 +                } else if (daysDistance < 7 * 4) {
                      const KLocalizedString format = ki18nc(
                          "@title:group Date: "
                          "MMMM is full month name in current locale, and yyyy is "
Simple merge
Simple merge
Simple merge
Simple merge