Commit ff672460 authored by Harish Fulara's avatar Harish Fulara Committed by Alexandru Băluț

greeter: Display project's meta-info

parent 612e8e84
Pipeline #18583 failed with stage
in 8 minutes and 48 seconds
......@@ -83,8 +83,10 @@
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="recent_projects_label">
<property name="name">recent_projects_label</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Recent Projects</property>
</object>
<packing>
......@@ -93,6 +95,21 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="updated_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="margin_right">12</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">Updated</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
......@@ -109,7 +126,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">1</property>
</packing>
</child>
</object>
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkBox" id="project_info_vbox">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="project_name_label">
<property name="name">project_name_label</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="project_last_updated_label">
<property name="name">project_last_updated_label</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="margin_left">200</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="project_uri_label">
<property name="name">project_uri_label</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_right">200</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</interface>
......@@ -29,6 +29,8 @@ from gi.repository import Gtk
from pitivi.configure import get_ui_dir
from pitivi.dialogs.browseprojects import BrowseProjectsDialog
from pitivi.perspective import Perspective
from pitivi.utils.ui import beautify_last_updated_timestamp
from pitivi.utils.ui import beautify_project_path
from pitivi.utils.ui import fix_infobar
from pitivi.utils.ui import GREETER_PERSPECTIVE_CSS
......@@ -39,12 +41,22 @@ class ProjectInfoRow(Gtk.ListBoxRow):
"""Displays a project's info.
Attributes:
project: Project's meta-data.
recent_project_item (Gtk.RecentInfo): Recent project's meta-data.
"""
def __init__(self, project):
def __init__(self, recent_project_item):
Gtk.ListBoxRow.__init__(self)
self.uri = project.get_uri()
self.add(Gtk.Label(project.get_display_name(), xalign=0))
self.uri = recent_project_item.get_uri()
builder = Gtk.Builder()
builder.add_from_file(os.path.join(get_ui_dir(), "project_info.ui"))
self.add(builder.get_object("project_info_vbox"))
builder.get_object("project_name_label").set_text(
os.path.splitext(recent_project_item.get_display_name())[0])
builder.get_object("project_uri_label").set_text(
beautify_project_path(recent_project_item.get_uri_display()))
builder.get_object("project_last_updated_label").set_text(
beautify_last_updated_timestamp(recent_project_item.get_modified()))
# pylint: disable=too-many-instance-attributes
......
......@@ -20,6 +20,7 @@
"""UI constants and various functions and classes that help with UI drawing."""
import decimal
import os
import time
import urllib.error
import urllib.parse
import urllib.request
......@@ -47,7 +48,6 @@ from pitivi.utils.loggable import INFO
from pitivi.utils.misc import path_from_uri
from pitivi.utils.proxy import get_proxy_target
# Dimensions in pixels
EXPANDED_SIZE = 65
......@@ -72,6 +72,19 @@ URI_TARGET_ENTRY = Gtk.TargetEntry.new("text/uri-list", 0, 0)
EFFECT_TARGET_ENTRY = Gtk.TargetEntry.new("pitivi/effect", 0, 0)
def get_month_format_string():
"""Returns the appropriate format string for month name in time.strftime() function."""
# %OB produces the month name in nominative case.
month_format_string = "%OB"
if time.strftime(month_format_string) == "%OB":
# %B produces the month name in genitive case.
month_format_string = "%B"
return month_format_string
# TODO: Drop this when we depend on glibc 2.27+
MONTH_FORMAT_STRING = get_month_format_string()
def _get_settings(schema):
if schema not in Gio.Settings.list_schemas():
return None
......@@ -97,12 +110,11 @@ MONOSPACE_FONT = _get_font("monospace-font-name", "Monospace")
GREETER_PERSPECTIVE_CSS = """
#recent_projects_listbox {
font-weight: bold;
border: 1px solid alpha(@borders, 0.6);
}
#recent_projects_listbox row {
padding: 10px 200px 10px 10px;
padding: 12px 12px 12px 12px;
border-bottom: 1px solid alpha(@borders, 0.2);
}
......@@ -110,15 +122,26 @@ GREETER_PERSPECTIVE_CSS = """
border-bottom-width: 0px;
}
#project_name_label {
font-weight: bold;
}
#project_uri_label, #project_last_updated_label {
opacity: 0.55;
}
#recent_projects_labelbox {
color: @insensitive_fg_color;
font-weight: bold;
padding-bottom: 6px;
}
#recent_projects_labelbox > label:backdrop {
color: @unfocused_insensitive_color;
}
#recent_projects_label {
font-weight: bold;
}
"""
TIMELINE_CSS = """
......@@ -412,6 +435,14 @@ def info_name(info):
return GLib.markup_escape_text(filename)
def beautify_project_path(path):
"""Beautifies project path by shortening the home directory path (if present)."""
home_dir = os.path.expanduser("~")
if path.startswith(home_dir):
return path.replace(home_dir, "~")
return path
def beautify_stream(stream):
if type(stream) is DiscovererAudioInfo:
if stream.get_depth() == 0:
......@@ -548,6 +579,36 @@ def beautify_ETA(length_nanos):
return ", ".join(parts)
def beautify_last_updated_timestamp(last_updated_timestamp):
"""Returns a rough estimation of how long ago the timestamp is."""
delta_seconds = int(time.time()) - last_updated_timestamp
if delta_seconds < 60 * 45:
return _("Just now")
if delta_seconds < 60 * 90:
return _("An hour ago")
if delta_seconds < 60 * 60 * 24:
return _("Today")
if delta_seconds < 60 * 60 * 24 * 2:
return _("Yesterday")
if delta_seconds < 60 * 60 * 24 * 7:
return time.strftime("%A", time.localtime(last_updated_timestamp))
if delta_seconds < 60 * 60 * 24 * 365:
return time.strftime(MONTH_FORMAT_STRING, time.localtime(last_updated_timestamp))
if delta_seconds < 60 * 60 * 24 * 365 * 1.5:
return _("About a year ago")
years = max(2, delta_seconds / (60 * 60 * 24 * 365))
return ngettext("About %d year ago",
"About %d years ago", years) % years
# -------------------- Gtk widget helpers ----------------------------------- #
def clear_styles(widget):
......
......@@ -17,6 +17,7 @@
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
import time
from unittest import TestCase
from unittest.mock import Mock
......@@ -29,6 +30,7 @@ from pitivi.check import ClassicDependency
from pitivi.check import GstDependency
from pitivi.check import GtkDependency
from pitivi.utils.misc import fixate_caps_with_default_values
from pitivi.utils.ui import beautify_last_updated_timestamp
from pitivi.utils.ui import beautify_length
from pitivi.utils.ui import format_audiochannels
from pitivi.utils.ui import format_audiorate
......@@ -39,30 +41,54 @@ minute = second * 60
hour = minute * 60
class TestBeautifyLength(TestCase):
class TestBeautifyTime(TestCase):
"""Tests time beautifying utility methods."""
def test_beautify_seconds(self):
def __check_beautify_last_updated_timestamp(self, seconds, expected):
time.time = Mock()
time.time.return_value = seconds
self.assertEqual(beautify_last_updated_timestamp(0), expected)
def test_beautify_length(self):
"""Tests beautification of time duration."""
self.assertEqual(beautify_length(second), "1 second")
self.assertEqual(beautify_length(second * 2), "2 seconds")
def test_beautify_minutes(self):
self.assertEqual(beautify_length(minute), "1 minute")
self.assertEqual(beautify_length(minute * 2), "2 minutes")
def test_beautify_hours(self):
self.assertEqual(beautify_length(hour), "1 hour")
self.assertEqual(beautify_length(hour * 2), "2 hours")
def test_beautify_minutes_and_seconds(self):
self.assertEqual(beautify_length(minute + second),
"1 minute, 1 second")
self.assertEqual(beautify_length(minute + second), "1 minute, 1 second")
self.assertEqual(beautify_length(hour + minute + second), "1 hour, 1 minute")
self.assertEqual(beautify_length(Gst.CLOCK_TIME_NONE), "")
def test_beautify_hours_and_minutes(self):
self.assertEqual(beautify_length(hour + minute + second),
"1 hour, 1 minute")
def test_beautify_last_updated_timestamp(self):
"""Tests beautification of project's updation timestamp."""
self.__check_beautify_last_updated_timestamp(0, "Just now")
self.__check_beautify_last_updated_timestamp(60 * 45 - 1, "Just now")
def test_beautify_nothing(self):
self.assertEqual(beautify_length(Gst.CLOCK_TIME_NONE), "")
self.__check_beautify_last_updated_timestamp(60 * 45, "An hour ago")
self.__check_beautify_last_updated_timestamp(60 * 90 - 1, "An hour ago")
self.__check_beautify_last_updated_timestamp(60 * 90, "Today")
self.__check_beautify_last_updated_timestamp(60 * 60 * 24 - 1, "Today")
self.__check_beautify_last_updated_timestamp(60 * 60 * 24, "Yesterday")
self.__check_beautify_last_updated_timestamp(60 * 60 * 24 * 2 - 1, "Yesterday")
self.__check_beautify_last_updated_timestamp(60 * 60 * 24 * 2, "Thursday")
self.__check_beautify_last_updated_timestamp(60 * 60 * 24 * 7 - 1, "Thursday")
self.__check_beautify_last_updated_timestamp(60 * 60 * 24 * 7, "January")
self.__check_beautify_last_updated_timestamp(60 * 60 * 24 * 365 - 1, "January")
self.__check_beautify_last_updated_timestamp(60 * 60 * 24 * 365, "About a year ago")
self.__check_beautify_last_updated_timestamp(60 * 60 * 24 * 365 * 1.5 - 1, "About a year ago")
self.__check_beautify_last_updated_timestamp(60 * 60 * 24 * 365 * 1.5, "About 2 years ago")
self.__check_beautify_last_updated_timestamp(60 * 60 * 24 * 365 * 3, "About 3 years ago")
class TestFormatFramerateValue(TestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment