# Path: kano_profile/apps.py
# def get_app_list():
#     if not os.path.exists(apps_dir):
#         return []
#     else:
#         return [p for p in os.listdir(apps_dir)
#                 if os.path.isdir(os.path.join(apps_dir, p))]
# 
# def get_app_data_dir(app_name):
#     data_str = 'data'
#     app_data_dir = os.path.join(get_app_dir(app_name), data_str)
#     return app_data_dir
# 
# def launch_project(app, filename, data_dir, background=False):
#     # This is necessary to support the new official names
#     # TODO: once the apps have been renamed this will not be necessary
#     name_translation = {
#         'make-art': 'kano-draw',
#         'terminal-quest': 'linux-story'
#     }
# 
#     app_tr = name_translation.get(app, app)
# 
#     logger.info("launch_project: {} {} {}".format(app_tr, filename, data_dir))
# 
#     app_profiles = read_json(app_profiles_file)
# 
#     # XML file with complete pathname
#     fullpath = os.path.join(data_dir, filename)
# 
#     # Prepare the command line to open the app with the new project
#     try:
#         cmd = (app_profiles[app_tr]['cmd']
#                .format(fullpath=fullpath, filename=filename))
#     except KeyError as exc:
#         logger.warn(
#             "Can't find app '{}' in the app profiles - [{}]"
#             .format(app_tr, exc)
#         )
#         raise ValueError(_("App '{}' not available").format(app_tr))
# 
#     # Try to load the project if the app is already running, via a signal.
#     _, _, rc = run_cmd('/usr/bin/kano-signal launch-share {}'.format(fullpath))
#     if rc:
#         # Likely the app is not running and the signal could not be sent, so start it now
#         logger.warn("Error sending launch signal, starting the app now, rc={}".format(rc))
#         if background:
#             # TODO: After migrating to launching apps via systemd, shares for make-snake
#             # stopped launching from KW. Created a special case here to avoid
#             # fixing the make-snake cmd through systemd temporarily. FIX THIS.
#             if app == 'make-snake':
#                 run_bg(cmd)
#             else:
#                 run_cmd('systemd-run --user {cmd}'.format(cmd=cmd))
#         else:
#             _, _, rc = run_print_output_error(cmd)
#             return rc
#     else:
#         logger.info("Sent signal to app: {} to open : {}".format(app_tr, fullpath))
# 
#     return 0
# 
# Path: kano_profile/paths.py
# TRACKER_UUIDS_PATH = os.path.join(kanoprofile_dir, 'tracker', 'uuids')
# PAUSED_SESSIONS_FILE = os.path.join(kanoprofile_dir, '.paused_sessions')
# 
# Path: kano_profile_gui/paths.py



import os
import kano.gtk3.cursor as cursor
import kano_profile_gui.components.icons as icons
from gi.repository import Gtk
from kano.utils import get_home, read_json
from kano_profile.apps import get_app_list, get_app_data_dir, launch_project
from kano_profile.paths import app_profiles_file
from kano.logging import logger
from kano.gtk3.scrolled_window import ScrolledWindow
from .paths import image_dir
from kdesk.hourglass import hourglass_start, hourglass_end
        self.button_padding.add(self.button)

        # shorten project name to 20 characters long
        display_name = project['display_name']
        if len(display_name) > 20:
            display_name = display_name[:20] + u'\N{HORIZONTAL ELLIPSIS}'

        self.title = Gtk.Label(display_name)
        self.title.get_style_context().add_class('project_item_title')
        self.title.set_alignment(xalign=0, yalign=1)

        self.label_container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
        self.label_container.pack_start(self.title, False, False, 0)

        self.label_align = Gtk.Alignment(xalign=0, yalign=0.5, xscale=1, yscale=0)
        self.label_align.add(self.label_container)
        self.label_align.set_padding(0, 0, 10, 0)

        self.image = Gtk.Image()
        self.image.set_from_file(project['icon'])

        self.container = Gtk.Box()
        self.container.pack_start(self.image, False, False, 0)
        self.container.pack_start(self.label_align, False, False, 0)
        self.container.pack_end(self.button_padding, False, False, 0)

        self.background.add(self.container)

    def load(self, _button, app, filename, data_dir):
        hourglass_start(app)

# Path: kano_profile/apps.py
# def get_app_list():
#     if not os.path.exists(apps_dir):
#         return []
#     else:
#         return [p for p in os.listdir(apps_dir)
#                 if os.path.isdir(os.path.join(apps_dir, p))]
# 
# def get_app_data_dir(app_name):
#     data_str = 'data'
#     app_data_dir = os.path.join(get_app_dir(app_name), data_str)
#     return app_data_dir
# 
# def launch_project(app, filename, data_dir, background=False):
#     # This is necessary to support the new official names
#     # TODO: once the apps have been renamed this will not be necessary
#     name_translation = {
#         'make-art': 'kano-draw',
#         'terminal-quest': 'linux-story'
#     }
# 
#     app_tr = name_translation.get(app, app)
# 
#     logger.info("launch_project: {} {} {}".format(app_tr, filename, data_dir))
# 
#     app_profiles = read_json(app_profiles_file)
# 
#     # XML file with complete pathname
#     fullpath = os.path.join(data_dir, filename)
# 
#     # Prepare the command line to open the app with the new project
#     try:
#         cmd = (app_profiles[app_tr]['cmd']
#                .format(fullpath=fullpath, filename=filename))
#     except KeyError as exc:
#         logger.warn(
#             "Can't find app '{}' in the app profiles - [{}]"
#             .format(app_tr, exc)
#         )
#         raise ValueError(_("App '{}' not available").format(app_tr))
# 
#     # Try to load the project if the app is already running, via a signal.
#     _, _, rc = run_cmd('/usr/bin/kano-signal launch-share {}'.format(fullpath))
#     if rc:
#         # Likely the app is not running and the signal could not be sent, so start it now
#         logger.warn("Error sending launch signal, starting the app now, rc={}".format(rc))
#         if background:
#             # TODO: After migrating to launching apps via systemd, shares for make-snake
#             # stopped launching from KW. Created a special case here to avoid
#             # fixing the make-snake cmd through systemd temporarily. FIX THIS.
#             if app == 'make-snake':
#                 run_bg(cmd)
#             else:
#                 run_cmd('systemd-run --user {cmd}'.format(cmd=cmd))
#         else:
#             _, _, rc = run_print_output_error(cmd)
#             return rc
#     else:
#         logger.info("Sent signal to app: {} to open : {}".format(app_tr, fullpath))
# 
#     return 0
# 
# Path: kano_profile/paths.py
# TRACKER_UUIDS_PATH = os.path.join(kanoprofile_dir, 'tracker', 'uuids')
# PAUSED_SESSIONS_FILE = os.path.join(kanoprofile_dir, '.paused_sessions')
# 
# Path: kano_profile_gui/paths.py



# Path: kano_profile_gui/projects.py
import os
import kano.gtk3.cursor as cursor
import kano_profile_gui.components.icons as icons
from gi.repository import Gtk
from kano.utils import get_home, read_json
from kano_profile.apps import get_app_list, get_app_data_dir, launch_project
from kano_profile.paths import app_profiles_file
from kano.logging import logger
from kano.gtk3.scrolled_window import ScrolledWindow
from .paths import image_dir
from kdesk.hourglass import hourglass_start, hourglass_end

        self.button_padding.add(self.button)

        # shorten project name to 20 characters long
        display_name = project['display_name']
        if len(display_name) > 20:
            display_name = display_name[:20] + u'\N{HORIZONTAL ELLIPSIS}'

        self.title = Gtk.Label(display_name)
        self.title.get_style_context().add_class('project_item_title')
        self.title.set_alignment(xalign=0, yalign=1)

        self.label_container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
        self.label_container.pack_start(self.title, False, False, 0)

        self.label_align = Gtk.Alignment(xalign=0, yalign=0.5, xscale=1, yscale=0)
        self.label_align.add(self.label_container)
        self.label_align.set_padding(0, 0, 10, 0)

        self.image = Gtk.Image()
        self.image.set_from_file(project['icon'])

        self.container = Gtk.Box()
        self.container.pack_start(self.image, False, False, 0)
        self.container.pack_start(self.label_align, False, False, 0)
        self.container.pack_end(self.button_padding, False, False, 0)

        self.background.add(self.container)

    def load(self, _button, app, filename, data_dir):
        hourglass_start(app)

        rc = launch_project(app, filename, data_dir)