|
67 | 67 |
|
68 | 68 | is_windows = sys.platform.startswith('win') |
69 | 69 |
|
| 70 | +HOUR = 60 * 60 |
| 71 | +SLIDER_SCALING_EXPONENT = 3.199 |
| 72 | +DAY = 24 * HOUR |
| 73 | +HOURS_48 = 48 |
| 74 | +MONTH = 28 * DAY |
| 75 | + |
70 | 76 |
|
71 | 77 | # TODO: rewrite |
72 | 78 | def powQueueSize(): |
@@ -834,11 +840,11 @@ def __init__(self, parent=None): |
834 | 840 |
|
835 | 841 | # Put the TTL slider in the correct spot |
836 | 842 | TTL = config.getint('bitmessagesettings', 'ttl') |
837 | | - if TTL < 3600: # an hour |
838 | | - TTL = 3600 |
839 | | - elif TTL > 28*24*60*60: # 28 days |
840 | | - TTL = 28*24*60*60 |
841 | | - self.ui.horizontalSliderTTL.setSliderPosition((TTL - 3600) ** (1/3.199)) |
| 843 | + if TTL < HOUR: |
| 844 | + TTL = HOUR |
| 845 | + elif TTL > MONTH: |
| 846 | + TTL = MONTH |
| 847 | + self.ui.horizontalSliderTTL.setSliderPosition((TTL - HOUR) ** (1 / SLIDER_SCALING_EXPONENT)) |
842 | 848 | self.updateHumanFriendlyTTLDescription(TTL) |
843 | 849 |
|
844 | 850 | QtCore.QObject.connect(self.ui.horizontalSliderTTL, QtCore.SIGNAL( |
@@ -891,34 +897,32 @@ def updateStartOnLogon(self): |
891 | 897 | except (NameError, TypeError): |
892 | 898 | self.desktop = False |
893 | 899 |
|
894 | | - def updateTTL(self, sliderPosition): |
895 | | - TTL = int(sliderPosition ** 3.199 + 3600) |
896 | | - self.updateHumanFriendlyTTLDescription(TTL) |
897 | | - config.set('bitmessagesettings', 'ttl', str(TTL)) |
| 900 | + def updateTTL(self, slider_position): |
| 901 | + ttl = int(slider_position ** SLIDER_SCALING_EXPONENT + HOUR) |
| 902 | + self.updateHumanFriendlyTTLDescription(ttl) |
| 903 | + config.set('bitmessagesettings', 'ttl', str(ttl)) |
898 | 904 | config.save() |
899 | 905 |
|
900 | | - def updateHumanFriendlyTTLDescription(self, TTL): |
901 | | - numberOfHours = int(round(TTL / (60*60))) |
| 906 | + def updateHumanFriendlyTTLDescription(self, ttl): |
902 | 907 | font = QtGui.QFont() |
903 | 908 | stylesheet = "" |
904 | 909 |
|
905 | | - if numberOfHours < 48: |
| 910 | + if ttl < (2 * DAY): |
906 | 911 | self.ui.labelHumanFriendlyTTLDescription.setText( |
907 | | - _translate("MainWindow", "%n hour(s)", None, QtCore.QCoreApplication.CodecForTr, numberOfHours) + |
| 912 | + _translate("MainWindow", "%n hour(s)", None, QtCore.QCoreApplication.CodecForTr, int(round(ttl / HOUR))) + |
908 | 913 | ", " + |
909 | 914 | _translate("MainWindow", "not recommended for chans", None, QtCore.QCoreApplication.CodecForTr) |
910 | 915 | ) |
911 | 916 | stylesheet = "QLabel { color : red; }" |
912 | 917 | font.setBold(True) |
913 | 918 | else: |
914 | | - numberOfDays = int(round(TTL / (24*60*60))) |
915 | 919 | self.ui.labelHumanFriendlyTTLDescription.setText( |
916 | 920 | _translate( |
917 | 921 | "MainWindow", |
918 | 922 | "%n day(s)", |
919 | 923 | None, |
920 | 924 | QtCore.QCoreApplication.CodecForTr, |
921 | | - numberOfDays)) |
| 925 | + int(round(ttl / DAY)))) |
922 | 926 | font.setBold(False) |
923 | 927 | self.ui.labelHumanFriendlyTTLDescription.setStyleSheet(stylesheet) |
924 | 928 | self.ui.labelHumanFriendlyTTLDescription.setFont(font) |
|
0 commit comments