mainwindow.py 25.8 KB
Newer Older
Erdem Ersoy's avatar
Erdem Ersoy committed
1 2
#!/usr/bin/env python3
#
3
# Pardus Flatpak GUI main window module
Erdem Ersoy's avatar
Erdem Ersoy committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# Copyright (C) 2020 Erdem Ersoy
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

19
from pardusflatpakgui.infowindow import InfoWindow
Erdem Ersoy's avatar
Erdem Ersoy committed
20
from pardusflatpakgui.installwindow import InstallWindow
21 22
from pardusflatpakgui.uninstallwindow import UninstallWindow
from pardusflatpakgui.updateallwindow import UpdateAllWindow
23
from pardusflatpakgui.version import Version
Erdem Ersoy's avatar
Erdem Ersoy committed
24 25 26 27

import gettext
import locale
import gi
28

Erdem Ersoy's avatar
Erdem Ersoy committed
29 30 31 32 33 34 35
gi.require_version('Gtk', '3.0')
gi.require_version('GLib', '2.0')
gi.require_version('Flatpak', '1.0')
gi.require_version('Gio', '2.0')
from gi.repository import Gtk, GLib, Flatpak, Gio

locale.setlocale(locale.LC_ALL, "")
Erdem Ersoy's avatar
Erdem Ersoy committed
36
gettext.bindtextdomain("pardus-flatpak-gui", "/usr/share/locale/")
37
gettext.textdomain("pardus-flatpak-gui")
Erdem Ersoy's avatar
Erdem Ersoy committed
38
_ = gettext.gettext
Erdem Ersoy's avatar
Erdem Ersoy committed
39
gettext.install("pardus-flatpak-gui", "/usr/share/locale/")
Erdem Ersoy's avatar
Erdem Ersoy committed
40 41 42 43 44 45 46


class MainWindow(object):
    def __init__(self, application):
        self.Application = application

        try:
Erdem Ersoy's avatar
Erdem Ersoy committed
47
            main_gui_file = "/usr/share/pardus/pardus-flatpak-gui/ui/mainwindow.glade"
48 49
            main_builder = Gtk.Builder.new_from_file(main_gui_file)
            main_builder.connect_signals(self)
Erdem Ersoy's avatar
Erdem Ersoy committed
50
        except GLib.GError:
51
            print(_("Error reading GUI file: ") + main_gui_file)
Erdem Ersoy's avatar
Erdem Ersoy committed
52 53 54
            raise

        try:
Erdem Ersoy's avatar
Erdem Ersoy committed
55
            about_gui_file = "/usr/share/pardus/pardus-flatpak-gui/ui/aboutdialog.glade"
56 57
            about_builder = Gtk.Builder.new_from_file(about_gui_file)
            about_builder.connect_signals(self)
Erdem Ersoy's avatar
Erdem Ersoy committed
58
        except GLib.GError:
59
            print(_("Error reading About dialog GUI file: ") + about_gui_file)
Erdem Ersoy's avatar
Erdem Ersoy committed
60 61 62
            raise

        try:
Erdem Ersoy's avatar
Erdem Ersoy committed
63
            messages_gui_file = "/usr/share/pardus/pardus-flatpak-gui/ui/messagedialogs.glade"
64 65
            messages_builder = Gtk.Builder.new_from_file(messages_gui_file)
            messages_builder.connect_signals(self)
Erdem Ersoy's avatar
Erdem Ersoy committed
66 67
        except GLib.GError:
            print(_("Error reading message dialogs GUI file: ") +
68
                  messages_gui_file)
Erdem Ersoy's avatar
Erdem Ersoy committed
69 70
            raise

71 72 73 74 75 76
        self.FlatpakInstallation = Flatpak.Installation.new_system()
        self.InstalledRefsList = self.FlatpakInstallation.list_installed_refs()
        self.FlatHubRefsList = self.FlatpakInstallation.list_remote_refs_sync(
            "flathub", Gio.Cancellable.new())
        self.NonInstalledRefsList = []

77 78 79 80
        for item in self.FlatHubRefsList:
            self.NonInstalledRefsList.append(item)
            for item_2 in self.InstalledRefsList:
                if item.get_name() == item_2.get_name() and \
81
                        item.get_arch() == item_2.get_arch() and \
82 83 84 85 86
                        item.get_branch() == item_2.get_branch():
                    if len(self.NonInstalledRefsList) != 0:
                        self.NonInstalledRefsList.pop(len(self.NonInstalledRefsList) - 1)
                    else:
                        self.NonInstalledRefsList = []
87 88

        self.AllRefsList = self.InstalledRefsList + self.NonInstalledRefsList
Erdem Ersoy's avatar
Erdem Ersoy committed
89

90 91 92 93
        self.ListStoreMain = main_builder.get_object("ListStoreMain")

        self.MessageDialogError = messages_builder.get_object("MessageDialogError")

94 95 96 97 98
        # Debug print()'s:
        # print("self.FlatHubRefsList:", len(self.FlatHubRefsList))
        # print("self.InstalledRefsList:", len(self.InstalledRefsList))
        # print("self.NonInstalledRefsList:", len(self.NonInstalledRefsList))
        # print("self.AllRefsList:", len(self.AllRefsList))
99 100

        for item in self.AllRefsList:
101
            if item.get_kind() == Flatpak.RefKind.APP and \
102
                    item.get_arch() == Flatpak.get_default_arch():
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
                if isinstance(item, Flatpak.RemoteRef):
                    item_is_installed = False
                elif isinstance(item, Flatpak.InstalledRef):
                    item_is_installed = True
                else:
                    item_is_installed = None

                real_name = item.get_name()
                arch = item.get_arch()
                branch = item.get_branch()
                installed_size = item.get_installed_size()
                installed_size_mib = installed_size / 1048576
                installed_size_mib_str = f"{installed_size_mib:.2f}" + " MiB"

                if not item_is_installed:
                    if item in self.FlatHubRefsList:
                        remote_name = "flathub"
                    else:
                        remote_name = ""
                    download_size = item.get_download_size()
                    download_size_mib = download_size / 1048576
                    download_size_mib_str = f"{download_size_mib:.2f}" + " MiB"
                    name = ""
                elif item_is_installed:
                    remote_name = item.get_origin()
                    download_size_mib_str = ""
                    name = item.get_appdata_name()
                else:
131 132 133 134
                    remote_name = ""
                    download_size_mib_str = ""
                    name = ""

135 136 137
                    self.MessageDialogError.set_markup(
                        _("<big><b>Invalid Flatpak Reference Error</b></big>"))
                    self.MessageDialogError.format_secondary_text(
138
                        _("Invalid Flatpak reference is: ") + "app/" + real_name + "/" + arch + "/" + branch)
139 140
                    self.MessageDialogError.run()
                    self.MessageDialogError.hide()
141 142 143 144 145 146 147 148 149

                if item_is_installed is not None:
                    self.ListStoreMain.append([real_name,
                                               arch,
                                               branch,
                                               remote_name,
                                               installed_size_mib_str,
                                               download_size_mib_str,
                                               name])
150 151 152 153
            else:
                continue

        self.HeaderBarMain = main_builder.get_object("HeaderBarMain")
154 155
        self.HeaderBarMain.set_title(_("Pardus Flatpak GUI"))
        self.HeaderBarMain.set_subtitle(_("Manage Flatpak softwares via GUI on Pardus"))
Erdem Ersoy's avatar
Erdem Ersoy committed
156

157
        self.RunMenuItem = main_builder.get_object("RunMenuItem")
Erdem Ersoy's avatar
Erdem Ersoy committed
158 159
        self.RunMenuItem.set_label(_("_Run"))

160
        self.InfoMenuItem = main_builder.get_object("InfoMenuItem")
Erdem Ersoy's avatar
Erdem Ersoy committed
161 162
        self.InfoMenuItem.set_label(_("_Info"))

163
        self.UninstallMenuItem = main_builder.get_object("UninstallMenuItem")
Erdem Ersoy's avatar
Erdem Ersoy committed
164 165
        self.UninstallMenuItem.set_label(_("_Uninstall"))

166
        self.InstallMenuItem = main_builder.get_object("InstallMenuItem")
Erdem Ersoy's avatar
Erdem Ersoy committed
167 168
        self.InstallMenuItem.set_label(_("I_nstall"))

169
        self.ActionsMenu = main_builder.get_object("ActionsMenu")
Erdem Ersoy's avatar
Erdem Ersoy committed
170

171
        self.UpdateAllMenuItem = main_builder.get_object("UpdateAllMenuItem")
172
        self.UpdateAllMenuItem.set_label(_("_Update All"))
Erdem Ersoy's avatar
Erdem Ersoy committed
173

174
        self.AboutMenuItem = main_builder.get_object("AboutMenuItem")
Erdem Ersoy's avatar
Erdem Ersoy committed
175 176
        self.AboutMenuItem.set_label(_("_About"))

177 178
        self.TreeViewColumnRealName = main_builder.get_object(
            "TreeViewColumnRealName")
Erdem Ersoy's avatar
Erdem Ersoy committed
179 180
        self.TreeViewColumnRealName.set_title(_("Real Name"))

181
        self.TreeViewColumnArch = main_builder.get_object("TreeViewColumnArch")
Erdem Ersoy's avatar
Erdem Ersoy committed
182 183
        self.TreeViewColumnArch.set_title(_("Arch"))

184
        self.TreeViewColumnBranch = main_builder.get_object("TreeViewColumnBranch")
185
        self.TreeViewColumnBranch.set_title(_("Branch"))
Erdem Ersoy's avatar
Erdem Ersoy committed
186

187 188
        self.TreeViewColumnRemoteName = main_builder.get_object(
            "TreeViewColumnRemoteName")
Erdem Ersoy's avatar
Erdem Ersoy committed
189 190
        self.TreeViewColumnRemoteName.set_title(_("Remote Name"))

191 192
        self.TreeViewColumnInstalledSize = main_builder.get_object(
            "TreeViewColumnInstalledSize")
Erdem Ersoy's avatar
Erdem Ersoy committed
193 194
        self.TreeViewColumnInstalledSize.set_title(_("Installed Size"))

195 196
        self.TreeViewColumnDownloadSize = main_builder.get_object(
            "TreeViewColumnDownloadSize")
Erdem Ersoy's avatar
Erdem Ersoy committed
197 198
        self.TreeViewColumnDownloadSize.set_title(_("Download Size"))

199
        self.TreeViewColumnName = main_builder.get_object("TreeViewColumnName")
Erdem Ersoy's avatar
Erdem Ersoy committed
200 201
        self.TreeViewColumnName.set_title(_("Name"))

202
        self.TreeViewMain = main_builder.get_object("TreeViewMain")
Erdem Ersoy's avatar
Erdem Ersoy committed
203

204 205
        self.SearchEntryMain = main_builder.get_object("SearchEntryMain")
        self.SearchEntryMain.set_placeholder_text(_("Click here for search"))
Erdem Ersoy's avatar
Erdem Ersoy committed
206

207
        self.SearchFilter = main_builder.get_object("SearchFilter")
208
        self.SearchFilter.set_visible_func(self.search_filter_function)
Erdem Ersoy's avatar
Erdem Ersoy committed
209

210 211 212 213 214 215 216 217 218
        self.SortModel = main_builder.get_object("SortModel")
        self.SortModel.set_sort_func(0, self.sorting_compare_function, (self.TreeViewColumnRealName, 0))
        self.SortModel.set_sort_func(1, self.sorting_compare_function, (self.TreeViewColumnArch, 1))
        self.SortModel.set_sort_func(2, self.sorting_compare_function, (self.TreeViewColumnBranch, 2))
        self.SortModel.set_sort_func(3, self.sorting_compare_function, (self.TreeViewColumnRemoteName, 3))
        self.SortModel.set_sort_func(4, self.sorting_float_compare_function, (self.TreeViewColumnInstalledSize, 4))
        self.SortModel.set_sort_func(5, self.sorting_float_compare_function, (self.TreeViewColumnDownloadSize, 5))
        self.SortModel.set_sort_func(6, self.sorting_compare_function, (self.TreeViewColumnName, 6))

219
        self.HeaderBarShowButton = main_builder.get_object("HeaderBarShowButton")
220 221
        self.HeaderBarShowButton.set_label(_("Show Installed Apps"))

222
        self.AboutDialog = about_builder.get_object("AboutDialog")
223
        self.AboutDialog.set_comments(_("Flatpak GUI for Pardus"))
Erdem Ersoy's avatar
Erdem Ersoy committed
224
        self.AboutDialog.set_copyright(_("Copyright (C) 2020 Erdem Ersoy"))
225
        self.AboutDialog.set_program_name(_("Pardus Flatpak GUI"))
226
        self.AboutDialog.set_version(Version.getVersion())
227
        self.AboutDialog.set_website_label(_("Pardus Flatpak GUI Web Site"))
Erdem Ersoy's avatar
Erdem Ersoy committed
228

229 230
        self.MainWindow = main_builder.get_object("MainWindow")
        self.MainWindow.set_application(application)
Erdem Ersoy's avatar
Erdem Ersoy committed
231 232
        self.MainWindow.show()

233
    def search_filter_function(self, model, iteration, data):
Erdem Ersoy's avatar
Erdem Ersoy committed
234 235 236 237
        search_entry_text = self.SearchEntryMain.get_text()
        real_name = model[iteration][0]
        name = model[iteration][6]

238
        # If a reference is installed
239
        if model[iteration][5] == "":
240
            is_installed = True
241 242
        else:
            is_installed = False
243 244

        if len(search_entry_text) == 0 and not self.HeaderBarShowButton.get_active():
Erdem Ersoy's avatar
Erdem Ersoy committed
245
            return True
246
        if len(search_entry_text) == 0 and self.HeaderBarShowButton.get_active():
247
            if UpdateAllWindow.at_updating:
248 249 250
                return True
            else:
                return is_installed
251
        elif (real_name.lower().count(search_entry_text.lower()) > 0 or name.lower().count(
252
                search_entry_text.lower()) > 0) and not self.HeaderBarShowButton.get_active():
Erdem Ersoy's avatar
Erdem Ersoy committed
253
            return True
254
        elif (real_name.lower().count(search_entry_text.lower()) > 0 or name.lower().count(
255
                search_entry_text.lower()) > 0) and self.HeaderBarShowButton.get_active():
256
            if UpdateAllWindow.at_updating:
257 258 259
                return True
            else:
                return is_installed
Erdem Ersoy's avatar
Erdem Ersoy committed
260 261 262
        else:
            return False

263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
    def sorting_compare_function(self, tree_model_filter, row1, row2, data):
        sorting_column, id_number = data
        value1 = tree_model_filter.get_value(row1, id_number)
        value2 = tree_model_filter.get_value(row2, id_number)

        if value1 == "" and value2 == "":
            return 0
        elif value1 == "" and value2 != "":
            return -1
        elif value1 != "" and value2 == "":
            return 1

        if value1 < value2:
            return -1
        elif value1 == value2:
            return 0
        else:
            return 1

    def sorting_float_compare_function(self, tree_model_filter, row1, row2, data):
        sorting_column, id_number = data
        value1 = tree_model_filter.get_value(row1, id_number)[:-4]
        value2 = tree_model_filter.get_value(row2, id_number)[:-4]

        if value1 == "" and value2 == "":
            return 0
        elif value1 == "" and value2 != "":
            return -1
        elif value1 != "" and value2 == "":
            return 1

        value1_float = float(value1)
        value2_float = float(value2)

        if value1_float < value2_float:
            return -1
        elif value1_float == value2_float:
            return 0
        else:
            return 1

304
    def on_delete_main_window(self, widget, event):
305
        widget.hide_on_delete()
Erdem Ersoy's avatar
Erdem Ersoy committed
306

307
    def on_columns_changed(self, tree_view):  # FIXME: Remove
308
        selection = tree_view.get_selection()
309 310
        tree_model, tree_iter = selection.get_selected()
        if tree_iter is None:
Erdem Ersoy's avatar
Erdem Ersoy committed
311 312 313
            return None

        # If the selected app is installed
314
        if tree_model.get_value(tree_iter, 5) == "":
Erdem Ersoy's avatar
Erdem Ersoy committed
315 316 317 318 319 320 321 322 323 324
            self.RunMenuItem.set_sensitive(True)
            self.UninstallMenuItem.set_sensitive(True)
            self.InstallMenuItem.set_sensitive(False)

        # If the selected app is not installed
        else:
            self.RunMenuItem.set_sensitive(False)
            self.UninstallMenuItem.set_sensitive(False)
            self.InstallMenuItem.set_sensitive(True)

325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
    def on_selection_changed(self, tree_selection):
        tree_model, tree_iter = tree_selection.get_selected()
        if tree_iter is None:
            return None

        # If the selected app is installed
        if tree_model.get_value(tree_iter, 5) == "":
            self.RunMenuItem.set_sensitive(True)
            self.UninstallMenuItem.set_sensitive(True)
            self.InstallMenuItem.set_sensitive(False)

        # If the selected app is not installed
        else:
            self.RunMenuItem.set_sensitive(False)
            self.UninstallMenuItem.set_sensitive(False)
            self.InstallMenuItem.set_sensitive(True)

342
    def on_search_changed(self, search_entry):
Erdem Ersoy's avatar
Erdem Ersoy committed
343 344
        self.SearchFilter.refilter()

345 346 347
    def on_resorted(self, tree_sortable):
        self.SearchFilter.refilter()

348
    def on_press_show_button(self, toggle_button):
349 350
        self.SearchFilter.refilter()

351
    def on_show_actions_menu(self, tree_view, path, column):
Erdem Ersoy's avatar
Erdem Ersoy committed
352 353
        self.ActionsMenu.popup_at_pointer(None)

354 355 356 357
    def on_run(self, menu_item):
        selection = self.TreeViewMain.get_selection()
        tree_model, tree_iter = selection.get_selected()
        if tree_iter is None:
Erdem Ersoy's avatar
Erdem Ersoy committed
358 359 360 361 362 363 364 365
            self.MessageDialogError.set_markup(
                _("<big><b>Selection Error</b></big>"))
            self.MessageDialogError.format_secondary_text(
                _("None of the applications are selected."))
            self.MessageDialogError.run()
            self.MessageDialogError.hide()
            return None

366 367 368
        real_name = tree_model.get_value(tree_iter, 0)
        arch = tree_model.get_value(tree_iter, 1)
        branch = tree_model.get_value(tree_iter, 2)
Erdem Ersoy's avatar
Erdem Ersoy committed
369

370 371
        ref = Flatpak.Ref.parse("app/" + real_name + "/" +
                                arch + "/" + branch)
Erdem Ersoy's avatar
Erdem Ersoy committed
372

373
        commit = ref.get_commit()
Erdem Ersoy's avatar
Erdem Ersoy committed
374

375 376 377 378 379 380 381 382
        try:
            success = self.FlatpakInstallation.launch(
                real_name,
                arch,
                branch,
                commit,
                Gio.Cancellable.new())
        except GLib.Error:
Erdem Ersoy's avatar
Erdem Ersoy committed
383 384 385 386 387 388
            self.MessageDialogError.set_markup(
                _("<big><b>Running Error</b></big>"))
            self.MessageDialogError.format_secondary_text(
                _("The selected application couldn't run."))
            self.MessageDialogError.run()
            self.MessageDialogError.hide()
389 390 391 392 393 394 395 396 397 398
        else:
            if success:
                pass
            else:
                self.MessageDialogError.set_markup(
                    _("<big><b>Running Error</b></big>"))
                self.MessageDialogError.format_secondary_text(
                    _("The selected application couldn't run."))
                self.MessageDialogError.run()
                self.MessageDialogError.hide()
Erdem Ersoy's avatar
Erdem Ersoy committed
399

400 401 402 403
    def on_info(self, menu_item):
        selection = self.TreeViewMain.get_selection()
        tree_model, tree_iter = selection.get_selected()
        if tree_iter is None:
Erdem Ersoy's avatar
Erdem Ersoy committed
404 405 406 407 408 409 410 411
            self.MessageDialogError.set_markup(
                _("<big><b>Selection Error</b></big>"))
            self.MessageDialogError.format_secondary_text(
                _("None of the applications are selected."))
            self.MessageDialogError.run()
            self.MessageDialogError.hide()
            return None

412
        self.InstalledRefsList = self.FlatpakInstallation.list_installed_refs()
Erdem Ersoy's avatar
Erdem Ersoy committed
413
        self.FlatHubRefsList = self.FlatpakInstallation.list_remote_refs_sync(
414
            "flathub", Gio.Cancellable.new())
415
        self.NonInstalledRefsList = []
Erdem Ersoy's avatar
Erdem Ersoy committed
416

417 418 419 420
        for item in self.FlatHubRefsList:
            self.NonInstalledRefsList.append(item)
            for item_2 in self.InstalledRefsList:
                if item.get_name() == item_2.get_name() and \
421 422 423 424 425 426
                        item.get_arch() == item_2.get_arch() and \
                        item.get_branch() == item_2.get_branch():
                    if len(self.NonInstalledRefsList) != 0:
                        self.NonInstalledRefsList.pop(len(self.NonInstalledRefsList) - 1)
                    else:
                        self.NonInstalledRefsList = []
Erdem Ersoy's avatar
Erdem Ersoy committed
427

428
        self.AllRefsList = self.InstalledRefsList + self.NonInstalledRefsList
Erdem Ersoy's avatar
Erdem Ersoy committed
429

430 431 432
        real_name = tree_model.get_value(tree_iter, 0)
        arch = tree_model.get_value(tree_iter, 1)
        branch = tree_model.get_value(tree_iter, 2)
Erdem Ersoy's avatar
Erdem Ersoy committed
433

434 435 436 437
        for item in self.AllRefsList:
            if item.get_name() == real_name:
                ref = item
                break
438

Erdem Ersoy's avatar
Erdem Ersoy committed
439
        if ref not in self.AllRefsList:
440 441 442 443 444 445 446
            self.MessageDialogError.set_markup(
                _("<big><b>Invalid Flatpak Reference Error</b></big>"))
            self.MessageDialogError.format_secondary_text(
                _("Invalid Flatpak reference is: ") + "app/" + real_name + "/" + arch + "/" + branch)
            self.MessageDialogError.run()
            self.MessageDialogError.hide()
            return None
Erdem Ersoy's avatar
Erdem Ersoy committed
447

448 449 450 451
        collection_id = ref.get_collection_id()
        if collection_id is None:
            collection_id = _("None")
        commit = ref.get_commit()
Erdem Ersoy's avatar
Erdem Ersoy committed
452

Erdem Ersoy's avatar
Erdem Ersoy committed
453
        if isinstance(ref, Flatpak.RemoteRef):
454
            is_installed = False
Erdem Ersoy's avatar
Erdem Ersoy committed
455
        elif isinstance(ref, Flatpak.InstalledRef):
456 457 458
            is_installed = True
        else:
            is_installed = None
Erdem Ersoy's avatar
Erdem Ersoy committed
459

460 461 462 463
        if is_installed:
            app_license = ref.get_appdata_license()
            if app_license is None:
                app_license = _("None")
Erdem Ersoy's avatar
Erdem Ersoy committed
464

465 466 467
            name = ref.get_appdata_name()
            if name is None:
                name = _("None")
Erdem Ersoy's avatar
Erdem Ersoy committed
468

469 470 471
            summary = ref.get_appdata_summary()
            if summary is None:
                summary = _("None")
Erdem Ersoy's avatar
Erdem Ersoy committed
472

473 474 475
            version = ref.get_appdata_version()
            if version is None:
                version = _("None")
Erdem Ersoy's avatar
Erdem Ersoy committed
476

477 478 479
            deploy_dir = ref.get_deploy_dir()
            if deploy_dir is None:
                deploy_dir = _("None")
Erdem Ersoy's avatar
Erdem Ersoy committed
480

481 482 483
            eol_reason = ref.get_eol()
            if eol_reason is None:
                eol_reason = _("None")
Erdem Ersoy's avatar
Erdem Ersoy committed
484

485 486 487
            eol_rebased = ref.get_eol_rebase()
            if eol_rebased is None:
                eol_rebased = _("None")
Erdem Ersoy's avatar
Erdem Ersoy committed
488

489 490 491
            installed_size = ref.get_installed_size()
            installed_size_mib = installed_size / 1048576
            installed_size_mib_as_string = f"{installed_size_mib:.2f}" + " MiB"
Erdem Ersoy's avatar
Erdem Ersoy committed
492

493 494 495
            is_current = ref.get_is_current()
            if is_current:
                is_current_str = _("Yes")
Erdem Ersoy's avatar
Erdem Ersoy committed
496
            else:
497
                is_current_str = _("No")
Erdem Ersoy's avatar
Erdem Ersoy committed
498

499 500 501
            latest_commit = ref.get_latest_commit()
            if latest_commit is None:
                latest_commit = _("None")
Erdem Ersoy's avatar
Erdem Ersoy committed
502

503 504 505
            origin = ref.get_origin()
            if origin is None:
                origin = _("None")
Erdem Ersoy's avatar
Erdem Ersoy committed
506

507 508 509
            sub_paths = ref.get_subpaths()
            if sub_paths is None or not sub_paths:
                sub_paths_str = _("None")
Erdem Ersoy's avatar
Erdem Ersoy committed
510
            else:
511 512 513 514 515 516
                sub_paths_str = ""
                for item in sub_paths:
                    sub_paths_str = sub_paths_str + item + ", "
                    sub_paths_str = sub_paths_str[:-2]

            info_str = _("Real Name: ") + real_name + "\n" + \
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
                       _("Arch: ") + arch + "\n" + \
                       _("Branch: ") + branch + "\n" + \
                       _("Collection ID: ") + collection_id + "\n" + \
                       _("Commit: ") + commit + "\n" + \
                       _("Is Installed: ") + _("Yes") + "\n" + \
                       _("License: ") + app_license + "\n" + \
                       _("Name: ") + name + "\n" + \
                       _("Summary: ") + summary + "\n" + \
                       _("Version: ") + version + "\n" + \
                       _("Deploy Dir: ") + deploy_dir + "\n" + \
                       _("EOL Reason: ") + eol_reason + "\n" + \
                       _("EOL Rebased: ") + eol_rebased + "\n" + \
                       _("Installed Size: ") + installed_size_mib_as_string + "\n" + \
                       _("Is Current: ") + is_current_str + "\n" + \
                       _("Latest Commit: ") + latest_commit + "\n" + \
                       _("Origin: ") + origin + "\n" + \
                       _("Subpaths: ") + sub_paths_str + "\n"
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556

        elif not is_installed:
            download_size = ref.get_download_size()
            download_size_mib = download_size / 1048576
            download_size_mib_str = f"{download_size_mib:.2f}" + " MiB"

            eol_reason = ref.get_eol()
            if eol_reason is None:
                eol_reason = _("None")

            eol_rebased = ref.get_eol_rebase()
            if eol_rebased is None:
                eol_rebased = _("None")

            installed_size = ref.get_installed_size()
            installed_size_mib = installed_size / 1048576
            installed_size_mib_as_string = f"{installed_size_mib:.2f}" + " MiB"

            remote = ref.get_remote_name()
            if remote is None:
                remote = _("None")

            info_str = _("Real Name: ") + real_name + "\n" + \
Erdem Ersoy's avatar
Erdem Ersoy committed
557 558 559 560 561 562 563 564 565 566
                _("Arch: ") + arch + "\n" + \
                _("Branch: ") + branch + "\n" + \
                _("Collection ID: ") + collection_id + "\n" + \
                _("Commit: ") + commit + "\n" + \
                _("Is Installed: ") + _("Yes") + "\n" + \
                _("Download Size: ") + download_size_mib_str + "\n" + \
                _("EOL Reason: ") + eol_reason + "\n" + \
                _("EOL Rebased: ") + eol_rebased + "\n" + \
                _("Installed Size: ") + installed_size_mib_as_string + "\n" + \
                _("Remote Name: ") + remote + "\n"
567 568 569 570 571 572 573 574 575 576
        else:
            self.MessageDialogError.set_markup(
                _("<big><b>Invalid Flatpak Reference Error</b></big>"))
            self.MessageDialogError.format_secondary_text(
                _("Invalid Flatpak reference is: ") + "app/" + real_name + "/" + arch + "/" + branch)
            self.MessageDialogError.run()
            self.MessageDialogError.hide()
            return None

        InfoWindow(self.Application, info_str, ref)
Erdem Ersoy's avatar
Erdem Ersoy committed
577

578
    def on_uninstall(self, menu_item):
579 580 581 582 583 584
        if not self.HeaderBarShowButton.get_active():
            button_not_pressed_already = True
        elif self.HeaderBarShowButton.get_active():
            button_not_pressed_already = False
            self.HeaderBarShowButton.set_active(False)
            self.SearchFilter.refilter()
585

586 587 588
        selection = self.TreeViewMain.get_selection()
        tree_model, tree_iter = selection.get_selected()
        if tree_iter is None:
Erdem Ersoy's avatar
Erdem Ersoy committed
589 590 591 592 593 594 595 596
            self.MessageDialogError.set_markup(
                _("<big><b>Selection Error</b></big>"))
            self.MessageDialogError.format_secondary_text(
                _("None of the applications are selected."))
            self.MessageDialogError.run()
            self.MessageDialogError.hide()
            return None

597 598 599
        real_name = tree_model.get_value(tree_iter, 0)
        arch = tree_model.get_value(tree_iter, 1)
        branch = tree_model.get_value(tree_iter, 2)
Erdem Ersoy's avatar
Erdem Ersoy committed
600

601
        UninstallWindow(self.Application, self.FlatpakInstallation, real_name,
602 603
                        arch, branch, tree_model, tree_iter, selection, self.SearchFilter, self.HeaderBarShowButton,
                        button_not_pressed_already)
Erdem Ersoy's avatar
Erdem Ersoy committed
604

605 606 607 608
    def on_install(self, menu_item):
        selection = self.TreeViewMain.get_selection()
        tree_model, tree_iter = selection.get_selected()
        if tree_iter is None:
Erdem Ersoy's avatar
Erdem Ersoy committed
609 610 611 612 613 614 615 616
            self.MessageDialogError.set_markup(
                _("<big><b>Selection Error</b></big>"))
            self.MessageDialogError.format_secondary_text(
                _("None of the applications are selected."))
            self.MessageDialogError.run()
            self.MessageDialogError.hide()
            return None

617 618 619 620
        real_name = tree_model.get_value(tree_iter, 0)
        arch = tree_model.get_value(tree_iter, 1)
        branch = tree_model.get_value(tree_iter, 2)
        remote = tree_model.get_value(tree_iter, 3)
Erdem Ersoy's avatar
Erdem Ersoy committed
621

622
        InstallWindow(self.Application, self.FlatpakInstallation, real_name, arch, branch,
623
                      remote, tree_model, tree_iter, selection, self.SearchFilter)
Erdem Ersoy's avatar
Erdem Ersoy committed
624

625
    def on_update_all(self, menu_item):
626 627
        UpdateAllWindow.at_updating = True
        tree_model = self.TreeViewMain.get_model()
Erdem Ersoy's avatar
Erdem Ersoy committed
628
        UpdateAllWindow(self.Application, self.FlatpakInstallation,
629
                        tree_model, self.HeaderBarShowButton)
Erdem Ersoy's avatar
Erdem Ersoy committed
630

631
    def on_about(self, menu_item):
Erdem Ersoy's avatar
Erdem Ersoy committed
632 633
        self.AboutDialog.run()
        self.AboutDialog.hide()