Exemplo n.º 1
0
    def __init__(self, name):
        Gtk.ApplicationWindow.__init__(self, title=name)
        self.api = Api()
        self.show_installed_only = False
        self.search_string = ""
        self.offline = False

        # Set library
        self.library = Library(self, self.api)
        self.window_library.add(self.library)

        # Set the icon
        icon = GdkPixbuf.Pixbuf.new_from_file(LOGO_IMAGE_PATH)
        self.set_default_icon_list([icon])

        # Show the window
        self.show_all()

        # Create the thumbnails directory
        if not os.path.exists(THUMBNAIL_DIR):
            os.makedirs(THUMBNAIL_DIR)

        # Interact with the API
        self.__authenticate()
        self.HeaderBar.set_subtitle(self.api.get_user_info())
        self.sync_library()
Exemplo n.º 2
0
 def test3_add_games_from_api(self):
     self_games = []
     for game in SELF_GAMES:
         self_games.append(Game(
             name=game,
             game_id=int(SELF_GAMES[game]),
         ))
     self_games.append(Game(name="Game without ID", game_id=0))
     api_games = []
     for game in API_GAMES:
         api_games.append(Game(
             name=game,
             game_id=int(API_GAMES[game]),
         ))
     api_gmae_with_id = Game(name="Game without ID", game_id=1234567890)
     api_games.append(api_gmae_with_id)
     api_mock = MagicMock()
     api_mock.get_library.return_value = api_games
     test_library = Library(MagicMock(), api_mock)
     test_library.games = self_games
     test_library._Library__add_games_from_api()
     exp = True
     obs = api_gmae_with_id in test_library.games
     self.assertEqual(exp, obs)
     exp = len(api_games)
     obs = len(test_library.games)
     self.assertEqual(exp, obs)
Exemplo n.º 3
0
    def __init__(self, name="Minigalaxy"):
        Gtk.ApplicationWindow.__init__(self, title=name)
        self.api = Api()
        self.search_string = ""
        self.offline = False

        # Set library
        self.library = Library(self, self.api)
        self.window_library.add(self.library)
        self.header_installed.set_active(Config.get("installed_filter"))

        # Set the icon
        icon = GdkPixbuf.Pixbuf.new_from_file(LOGO_IMAGE_PATH)
        self.set_default_icon_list([icon])

        # Show the window
        if Config.get("keep_window_maximized"):
            self.maximize()
        self.show_all()

        # Create the thumbnails directory
        if not os.path.exists(THUMBNAIL_DIR):
            os.makedirs(THUMBNAIL_DIR, mode=0o755)

        # Interact with the API
        self.__authenticate()
        self.HeaderBar.set_subtitle(self.api.get_user_info())
        self.sync_library()
Exemplo n.º 4
0
 def test2_add_games_from_api(self):
     self_games = []
     for game in SELF_GAMES:
         self_games.append(Game(
             name=game,
             game_id=int(SELF_GAMES[game]),
         ))
     api_games = []
     for game in API_GAMES:
         api_games.append(Game(
             name=game,
             game_id=int(API_GAMES[game]),
         ))
     err_msg = ""
     api_mock = MagicMock()
     api_mock.get_library.return_value = api_games, err_msg
     test_library = Library(MagicMock(), api_mock)
     test_library.games = self_games
     test_library._Library__add_games_from_api()
     exp = True
     obs = Game(
         name="Stellaris (English)",
         game_id=1508702879,
     ) in test_library.games
     self.assertEqual(exp, obs)
Exemplo n.º 5
0
    def __init__(self, name="Minigalaxy"):
        current_locale = Config.get("locale")
        default_locale = locale.getdefaultlocale()[0]
        if current_locale == '':
            locale.setlocale(locale.LC_ALL, (default_locale, 'UTF-8'))
        else:
            try:
                locale.setlocale(locale.LC_ALL, (current_locale, 'UTF-8'))
            except NameError:
                locale.setlocale(locale.LC_ALL, (default_locale, 'UTF-8'))
        Gtk.ApplicationWindow.__init__(self, title=name)

        self.api = Api()
        self.search_string = ""
        self.offline = False

        # Set library
        self.library = Library(self, self.api)
        self.window_library.add(self.library)
        self.header_installed.set_active(Config.get("installed_filter"))

        # Set the icon
        icon = GdkPixbuf.Pixbuf.new_from_file(LOGO_IMAGE_PATH)
        self.set_default_icon_list([icon])

        # Set theme
        settings = Gtk.Settings.get_default()
        if Config.get("use_dark_theme") is True:
            settings.set_property("gtk-application-prefer-dark-theme", True)
        else:
            settings.set_property("gtk-application-prefer-dark-theme", False)

        # Show the window
        if Config.get("keep_window_maximized"):
            self.maximize()
        self.show_all()

        self.make_directories()

        # Interact with the API
        self.offline = not self.api.can_connect()
        if not self.offline:
            try:
                self.__authenticate()
                self.HeaderBar.set_subtitle(self.api.get_user_info())
            except Exception as e:
                print(
                    "Starting in offline mode, after receiving exception: {}".
                    format(e))
                self.offline = True
        self.sync_library()
Exemplo n.º 6
0
 def test1_add_games_from_api(self):
     self_games = []
     for game in SELF_GAMES:
         self_games.append(Game(name=game, game_id=int(SELF_GAMES[game]),))
     api_games = []
     for game in API_GAMES:
         api_games.append(Game(name=game, game_id=int(API_GAMES[game]),))
     api_mock = MagicMock()
     api_mock.get_library.return_value = api_games
     test_library = Library(MagicMock(), api_mock)
     test_library.games = self_games
     test_library._Library__add_games_from_api()
     exp = len(API_GAMES)
     obs = len(test_library.games)
     self.assertEqual(exp, obs)
Exemplo n.º 7
0
 def test6_add_games_from_api(self):
     self_games = [
         Game(name="Torchlight 2",
              game_id=0,
              install_dir="/home/user/GoG Games/Torchlight II")
     ]
     api_games = [Game(name="Torchlight II", game_id=1958228073)]
     err_msg = ""
     api_mock = MagicMock()
     api_mock.get_library.return_value = api_games, err_msg
     test_library = Library(MagicMock(), api_mock)
     test_library.games = self_games
     test_library._Library__add_games_from_api()
     exp = 1
     obs = len(test_library.games)
     self.assertEqual(exp, obs)
Exemplo n.º 8
0
 def test4_add_games_from_api(self):
     self_games = []
     for game in SELF_GAMES:
         self_games.append(Game(name=game, game_id=int(SELF_GAMES[game]),))
     api_games = []
     url_nr = 1
     for game in API_GAMES:
         api_games.append(Game(name=game, game_id=int(API_GAMES[game]), url="http://test_url{}".format(str(url_nr))))
         url_nr += 1
     api_mock = MagicMock()
     api_mock.get_library.return_value = api_games
     test_library = Library(MagicMock(), api_mock)
     test_library.games = self_games
     test_library._Library__add_games_from_api()
     exp = "http://test_url1"
     obs = test_library.games[0].url
     self.assertEqual(exp, obs)
Exemplo n.º 9
0
    def __init__(self, name="Minigalaxy"):
        current_locale = Config.get("locale")
        default_locale = locale.getdefaultlocale()[0]
        if current_locale == '':
            locale.setlocale(locale.LC_ALL, (default_locale, 'UTF-8'))
        else:
            try:
                locale.setlocale(locale.LC_ALL, (current_locale, 'UTF-8'))
            except NameError:
                locale.setlocale(locale.LC_ALL, (default_locale, 'UTF-8'))
        Gtk.ApplicationWindow.__init__(self, title=name)

        self.api = Api()
        self.search_string = ""
        self.offline = False

        # Set library
        self.library = Library(self, self.api)
        self.window_library.add(self.library)
        self.header_installed.set_active(Config.get("installed_filter"))

        # Set the icon
        icon = GdkPixbuf.Pixbuf.new_from_file(LOGO_IMAGE_PATH)
        self.set_default_icon_list([icon])

        # Set theme
        settings = Gtk.Settings.get_default()
        if Config.get("use_dark_theme") is True:
            settings.set_property("gtk-application-prefer-dark-theme", True)
        else:
            settings.set_property("gtk-application-prefer-dark-theme", False)

        # Show the window
        if Config.get("keep_window_maximized"):
            self.maximize()
        self.show_all()

        # Create the thumbnails directory
        if not os.path.exists(THUMBNAIL_DIR):
            os.makedirs(THUMBNAIL_DIR, mode=0o755)

        # Interact with the API
        self.__authenticate()
        self.HeaderBar.set_subtitle(self.api.get_user_info())
        self.sync_library()
Exemplo n.º 10
0
 def test5_add_games_from_api(self):
     self_games = []
     for game in SELF_GAMES:
         self_games.append(
             Game(
                 name="{}_diff".format(game),
                 game_id=int(SELF_GAMES[game]),
             ))
     api_games = []
     for game in API_GAMES:
         api_games.append(Game(name=game, game_id=int(API_GAMES[game])))
     err_msg = ""
     api_mock = MagicMock()
     api_mock.get_library.return_value = api_games, err_msg
     test_library = Library(MagicMock(), api_mock)
     test_library.games = self_games
     test_library._Library__add_games_from_api()
     exp = "Neverwinter Nights: Enhanced Edition"
     obs = test_library.games[0].name
     self.assertEqual(exp, obs)
Exemplo n.º 11
0
class Window(Gtk.ApplicationWindow):

    __gtype_name__ = "Window"

    HeaderBar = Gtk.Template.Child()
    header_sync = Gtk.Template.Child()
    header_installed = Gtk.Template.Child()
    header_search = Gtk.Template.Child()
    menu_about = Gtk.Template.Child()
    menu_preferences = Gtk.Template.Child()
    menu_logout = Gtk.Template.Child()
    window_library = Gtk.Template.Child()

    def __init__(self, name):
        Gtk.ApplicationWindow.__init__(self, title=name)
        self.api = Api()
        self.show_installed_only = False
        self.search_string = ""
        self.offline = False

        # Set library
        self.library = Library(self, self.api)
        self.window_library.add(self.library)

        # Set the icon
        icon = GdkPixbuf.Pixbuf.new_from_file(LOGO_IMAGE_PATH)
        self.set_default_icon_list([icon])

        # Show the window
        self.show_all()

        # Create the thumbnails directory
        if not os.path.exists(THUMBNAIL_DIR):
            os.makedirs(THUMBNAIL_DIR)

        # Interact with the API
        self.__authenticate()
        self.HeaderBar.set_subtitle(self.api.get_user_info())
        self.sync_library()

    @Gtk.Template.Callback("filter_library")
    def filter_library(self, switch, _=""):
        self.library.filter_library(switch)

    @Gtk.Template.Callback("on_menu_preferences_clicked")
    def show_preferences(self, button):
        preferences_window = Preferences(self)
        preferences_window.run()
        preferences_window.destroy()

    @Gtk.Template.Callback("on_menu_about_clicked")
    def show_about(self, button):
        about_window = About(self)
        about_window.run()
        about_window.destroy()

    @Gtk.Template.Callback("on_menu_logout_clicked")
    def logout(self, button):
        # Unset everything which is specific to this user
        self.HeaderBar.set_subtitle("")
        Config.unset("username")
        Config.unset("refresh_token")
        self.hide()

        # Show the login screen
        self.__authenticate()
        self.HeaderBar.set_subtitle(self.api.get_user_info())
        self.sync_library()

        self.show_all()

    @Gtk.Template.Callback("on_header_sync_clicked")
    def sync_library(self, _=""):
        if self.library.offline:
            self.__authenticate()
        self.library.update_library()

    def reset_library(self):
        self.library.reset()

    """
    The API remembers the authentication token and uses it
    The token is not valid for a long time
    """

    def __authenticate(self):
        url = None
        if Config.get("stay_logged_in"):
            token = Config.get("refresh_token")
        else:
            Config.unset("username")
            Config.unset("refresh_token")
            token = None

        # Make sure there is an internet connection
        if not self.api.can_connect():
            return

        authenticated = self.api.authenticate(refresh_token=token,
                                              login_code=url)

        while not authenticated:
            login_url = self.api.get_login_url()
            redirect_url = self.api.get_redirect_url()
            login = Login(login_url=login_url,
                          redirect_url=redirect_url,
                          parent=self)
            response = login.run()
            login.hide()
            if response == Gtk.ResponseType.DELETE_EVENT:
                Gtk.main_quit()
                exit(0)
            if response == Gtk.ResponseType.NONE:
                result = login.get_result()
                authenticated = self.api.authenticate(refresh_token=token,
                                                      login_code=result)

        Config.set("refresh_token", authenticated)
Exemplo n.º 12
0
class Window(Gtk.ApplicationWindow):
    __gtype_name__ = "Window"

    HeaderBar = Gtk.Template.Child()
    header_sync = Gtk.Template.Child()
    header_installed = Gtk.Template.Child()
    header_search = Gtk.Template.Child()
    menu_about = Gtk.Template.Child()
    menu_preferences = Gtk.Template.Child()
    menu_logout = Gtk.Template.Child()
    window_library = Gtk.Template.Child()

    def __init__(self, name="Minigalaxy"):
        Gtk.ApplicationWindow.__init__(self, title=name)
        self.api = Api()
        self.search_string = ""
        self.offline = False

        # Set library
        self.library = Library(self, self.api)
        self.window_library.add(self.library)
        self.header_installed.set_active(Config.get("installed_filter"))

        # Set the icon
        icon = GdkPixbuf.Pixbuf.new_from_file(LOGO_IMAGE_PATH)
        self.set_default_icon_list([icon])

        # Show the window
        if Config.get("keep_window_maximized"):
            self.maximize()
        self.show_all()

        # Create the thumbnails directory
        if not os.path.exists(THUMBNAIL_DIR):
            os.makedirs(THUMBNAIL_DIR, mode=0o755)

        # Interact with the API
        self.__authenticate()
        self.HeaderBar.set_subtitle(self.api.get_user_info())
        self.sync_library()

    @Gtk.Template.Callback("filter_library")
    def filter_library(self, switch, _=""):
        self.library.filter_library(switch)
        Config.set("installed_filter", switch.get_active())

    @Gtk.Template.Callback("on_menu_preferences_clicked")
    def show_preferences(self, button):
        preferences_window = Preferences(self)
        preferences_window.run()
        preferences_window.destroy()

    @Gtk.Template.Callback("on_menu_about_clicked")
    def show_about(self, button):
        about_window = About(self)
        about_window.run()
        about_window.destroy()

    @Gtk.Template.Callback("on_menu_logout_clicked")
    def logout(self, button):
        # Unset everything which is specific to this user
        self.HeaderBar.set_subtitle("")
        Config.unset("username")
        Config.unset("refresh_token")
        self.hide()

        # Show the login screen
        self.__authenticate()
        self.HeaderBar.set_subtitle(self.api.get_user_info())
        self.sync_library()

        self.show_all()

    @Gtk.Template.Callback("on_window_state_event")
    def on_window_state_event(self, widget, event):
        if event.new_window_state & Gdk.WindowState.MAXIMIZED:
            Config.set("keep_window_maximized", True)
        else:
            Config.set("keep_window_maximized", False)

    @Gtk.Template.Callback("on_header_sync_clicked")
    def sync_library(self, _=""):
        if self.library.offline:
            self.__authenticate()
        self.library.update_library()

    def reset_library(self):
        self.library.reset()

    def update_library(self):
        self.library.update_library()

    def show_error(self, text, secondary_text=""):
        dialog = Gtk.MessageDialog(
            parent=self,
            modal=True,
            destroy_with_parent=True,
            message_type=Gtk.MessageType.ERROR,
            buttons=Gtk.ButtonsType.OK,
            text=text
        )
        if secondary_text:
            dialog.format_secondary_text(secondary_text)
        dialog.run()
        dialog.destroy()

    def show_question(self, text, secondary_text=""):
        dialog = Gtk.MessageDialog(
            parent=self,
            flags=Gtk.DialogFlags.MODAL,
            message_type=Gtk.MessageType.WARNING,
            buttons=Gtk.ButtonsType.OK_CANCEL,
            message_format=text
        )
        if secondary_text:
            dialog.format_secondary_text(secondary_text)
        response = dialog.run()
        dialog.destroy()
        return response == Gtk.ResponseType.OK

    """
    The API remembers the authentication token and uses it
    The token is not valid for a long time
    """

    def __authenticate(self):
        url = None
        if Config.get("stay_logged_in"):
            token = Config.get("refresh_token")
        else:
            Config.unset("username")
            Config.unset("refresh_token")
            token = None

        # Make sure there is an internet connection
        if not self.api.can_connect():
            return

        authenticated = self.api.authenticate(refresh_token=token, login_code=url)

        while not authenticated:
            login_url = self.api.get_login_url()
            redirect_url = self.api.get_redirect_url()
            login = Login(login_url=login_url, redirect_url=redirect_url, parent=self)
            response = login.run()
            login.hide()
            if response == Gtk.ResponseType.DELETE_EVENT:
                Gtk.main_quit()
                exit(0)
            if response == Gtk.ResponseType.NONE:
                result = login.get_result()
                authenticated = self.api.authenticate(login_code=result)

        Config.set("refresh_token", authenticated)